cartethyia 2.5.1 → 2.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +5 -1
- package/dist/dashboard/assets/{AccountCooldown-ChpdzxRH.js → AccountCooldown-Bjo92Qat.js} +1 -1
- package/dist/dashboard/assets/AccountCooldown-Bjo92Qat.js.gz +0 -0
- package/dist/dashboard/assets/{BannedPage-ChqnTRpZ.js → BannedPage-MsQaeQTs.js} +1 -1
- package/dist/dashboard/assets/BannedPage-MsQaeQTs.js.gz +0 -0
- package/dist/dashboard/assets/CliToolDetailPage-BO9nKg9w.js +1 -0
- package/dist/dashboard/assets/CliToolDetailPage-BO9nKg9w.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolsPage-BXUaRCQQ.js → CliToolsPage-DfWHTJ7v.js} +1 -1
- package/dist/dashboard/assets/CliToolsPage-DfWHTJ7v.js.gz +0 -0
- package/dist/dashboard/assets/CombosPage-BrCBQDAc.js +1 -0
- package/dist/dashboard/assets/CombosPage-BrCBQDAc.js.gz +0 -0
- package/dist/dashboard/assets/ConsoleLogPage-C6Uh33er.js +1 -0
- package/dist/dashboard/assets/ConsoleLogPage-C6Uh33er.js.gz +0 -0
- package/dist/dashboard/assets/CustomizationPage-8aS9hyJu.js +1 -0
- package/dist/dashboard/assets/CustomizationPage-8aS9hyJu.js.gz +0 -0
- package/dist/dashboard/assets/HealthEventsModal-qomXThxX.js +1 -0
- package/dist/dashboard/assets/HealthEventsModal-qomXThxX.js.gz +0 -0
- package/dist/dashboard/assets/LoginPage-C8hKyXBe.js +1 -0
- package/dist/dashboard/assets/LoginPage-C8hKyXBe.js.gz +0 -0
- package/dist/dashboard/assets/ModelPicker-CWkTUtpX.js +1 -0
- package/dist/dashboard/assets/ModelPicker-CWkTUtpX.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-C-ExCy1V.js +1 -0
- package/dist/dashboard/assets/OverviewPage-C-ExCy1V.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-tr811uaF.js +3 -0
- package/dist/dashboard/assets/ProviderDetailPage-tr811uaF.js.gz +0 -0
- package/dist/dashboard/assets/ProvidersPage-BS9IEpvv.js +1 -0
- package/dist/dashboard/assets/ProvidersPage-BS9IEpvv.js.gz +0 -0
- package/dist/dashboard/assets/ProxyPage-Rn_qXScb.js +7 -0
- package/dist/dashboard/assets/ProxyPage-Rn_qXScb.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-BihkgQSq.js +1 -0
- package/dist/dashboard/assets/QuotaPage-BihkgQSq.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-DhiEjm6T.js +1 -0
- package/dist/dashboard/assets/SettingsPage-DhiEjm6T.js.gz +0 -0
- package/dist/dashboard/assets/SetupPage-CXjUlfqr.js +1 -0
- package/dist/dashboard/assets/SetupPage-CXjUlfqr.js.gz +0 -0
- package/dist/dashboard/assets/SortableList-C-_oD3F2.js +1 -0
- package/dist/dashboard/assets/SortableList-C-_oD3F2.js.gz +0 -0
- package/dist/dashboard/assets/{StudioPage-DqK5E26W.js → StudioPage-u9IxmYOI.js} +3 -3
- package/dist/dashboard/assets/StudioPage-u9IxmYOI.js.gz +0 -0
- package/dist/dashboard/assets/UsagePage-BEVLVrwP.js +56 -0
- package/dist/dashboard/assets/UsagePage-BEVLVrwP.js.gz +0 -0
- package/dist/dashboard/assets/{api-keys-BmDbsior.js → api-keys-uNywYlfv.js} +1 -1
- package/dist/dashboard/assets/api-keys-uNywYlfv.js.gz +0 -0
- package/dist/dashboard/assets/{app-C-Y4oZT0.js → app-CafWtVXA.js} +1 -1
- package/dist/dashboard/assets/{app-C-Y4oZT0.js.gz → app-CafWtVXA.js.gz} +0 -0
- package/dist/dashboard/assets/app-DxivpfYG.css +2 -0
- package/dist/dashboard/assets/app-DxivpfYG.css.gz +0 -0
- package/dist/dashboard/assets/{assert-BHfaei-X.js → assert-NHwYq95t.js} +1 -1
- package/dist/dashboard/assets/{assert-BHfaei-X.js.gz → assert-NHwYq95t.js.gz} +0 -0
- package/dist/dashboard/assets/badge-6uzDDvqs.js +1 -0
- package/dist/dashboard/assets/badge-6uzDDvqs.js.gz +0 -0
- package/dist/dashboard/assets/banner-4_WNg2WZ.js +1 -0
- package/dist/dashboard/assets/banner-4_WNg2WZ.js.gz +0 -0
- package/dist/dashboard/assets/card--AtFedAq.js +1 -0
- package/dist/dashboard/assets/card--AtFedAq.js.gz +0 -0
- package/dist/dashboard/assets/{cli-tools-B0wBq-RL.js → cli-tools-B3e7dx3N.js} +1 -1
- package/dist/dashboard/assets/cli-tools-B3e7dx3N.js.gz +0 -0
- package/dist/dashboard/assets/clipboard-button-NreUx6c8.js +1 -0
- package/dist/dashboard/assets/clipboard-button-NreUx6c8.js.gz +0 -0
- package/dist/dashboard/assets/dialog-BtpsJU98.js +1 -0
- package/dist/dashboard/assets/dialog-BtpsJU98.js.gz +0 -0
- package/dist/dashboard/assets/drawer-WwwtzihF.js +1 -0
- package/dist/dashboard/assets/drawer-WwwtzihF.js.gz +0 -0
- package/dist/dashboard/assets/entry-Dj9AR0gY.js +4 -0
- package/dist/dashboard/assets/entry-Dj9AR0gY.js.gz +0 -0
- package/dist/dashboard/assets/entry-TJIye_jT.js +1 -0
- package/dist/dashboard/assets/entry-TJIye_jT.js.gz +0 -0
- package/dist/dashboard/assets/{entry-D4O2229X.js → entry-jy9_4-Ke.js} +1 -1
- package/dist/dashboard/assets/entry-jy9_4-Ke.js.gz +0 -0
- package/dist/dashboard/assets/github-badge-D_eM3IgG.js +1 -0
- package/dist/dashboard/assets/github-badge-D_eM3IgG.js.gz +0 -0
- package/dist/dashboard/assets/{index-CcD1eSJ6.js → index-DCBtROoK.js} +2 -2
- package/dist/dashboard/assets/index-DCBtROoK.js.gz +0 -0
- package/dist/dashboard/assets/inline-BcNGF8Gr.js +1 -0
- package/dist/dashboard/assets/inline-BcNGF8Gr.js.gz +0 -0
- package/dist/dashboard/assets/input-BG41et9G.js +1 -0
- package/dist/dashboard/assets/input-BG41et9G.js.gz +0 -0
- package/dist/dashboard/assets/layout-C8mer_Ak.js +1 -0
- package/dist/dashboard/assets/layout-C8mer_Ak.js.gz +0 -0
- package/dist/dashboard/assets/list-row-Gh_W4OR_.js +1 -0
- package/dist/dashboard/assets/list-row-Gh_W4OR_.js.gz +0 -0
- package/dist/dashboard/assets/{live-yfEJFF9T.js → live-BJGYRBnR.js} +1 -1
- package/dist/dashboard/assets/live-BJGYRBnR.js.gz +0 -0
- package/dist/dashboard/assets/{model-bans-CT-TxSNX.js → model-bans-DeVLDA7I.js} +1 -1
- package/dist/dashboard/assets/model-bans-DeVLDA7I.js.gz +0 -0
- package/dist/dashboard/assets/numbers-Bs4LOOuf.js +2 -0
- package/dist/dashboard/assets/numbers-Bs4LOOuf.js.gz +0 -0
- package/dist/dashboard/assets/{routing-Cs6jl49L.js → routing-CcusqXA7.js} +1 -1
- package/dist/dashboard/assets/routing-CcusqXA7.js.gz +0 -0
- package/dist/dashboard/assets/select-DsX5QT8K.js +41 -0
- package/dist/dashboard/assets/select-DsX5QT8K.js.gz +0 -0
- package/dist/dashboard/assets/{settings-CfcTcOyU.js → settings-mpmXTgUa.js} +1 -1
- package/dist/dashboard/assets/settings-mpmXTgUa.js.gz +0 -0
- package/dist/dashboard/assets/stack-DwLmjUFK.js +1 -0
- package/dist/dashboard/assets/stack-DwLmjUFK.js.gz +0 -0
- package/dist/dashboard/assets/state-DYdQmdAl.js +1 -0
- package/dist/dashboard/assets/state-DYdQmdAl.js.gz +0 -0
- package/dist/dashboard/assets/switch-CidSfbG7.js +1 -0
- package/dist/dashboard/assets/switch-CidSfbG7.js.gz +0 -0
- package/dist/dashboard/assets/{useMutation-BQKMcJ1H.js → useMutation-w4u4CVue.js} +1 -1
- package/dist/dashboard/assets/useMutation-w4u4CVue.js.gz +0 -0
- package/dist/dashboard/index.html +1 -1
- package/dist/dashboard/index.html.gz +0 -0
- package/dist/dashboard/precompressed-assets.json +51 -54
- package/package.json +1 -1
- package/src/boot/app.ts +3 -2
- package/src/console/observability/contracts.ts +11 -1
- package/src/console/observability/store.ts +9 -6
- package/src/providers/discovery/openrouter-free-roster.ts +3 -11
- package/src/providers/discovery/probe-phases.ts +42 -5
- package/src/providers/discovery/probing-service.ts +25 -2
- package/src/providers/integrations/claude/claude.ts +3 -1
- package/src/providers/integrations/cloudflareai/cloudflareai-models.ts +3 -1
- package/src/providers/integrations/inferhub.ts +3 -1
- package/src/providers/integrations/kilo/kilo.ts +0 -1
- package/src/providers/integrations/kiro/kiro-catalog.ts +8 -2
- package/src/providers/integrations/openrouter/provider.ts +5 -15
- package/src/security/api-key-auth.ts +23 -0
- package/src/transport/guards/auth-guard.ts +2 -3
- package/dist/dashboard/assets/AccountCooldown-ChpdzxRH.js.gz +0 -0
- package/dist/dashboard/assets/BannedPage-ChqnTRpZ.js.gz +0 -0
- package/dist/dashboard/assets/CliToolDetailPage-Bb9CNuoh.js +0 -1
- package/dist/dashboard/assets/CliToolDetailPage-Bb9CNuoh.js.gz +0 -0
- package/dist/dashboard/assets/CliToolsPage-BXUaRCQQ.js.gz +0 -0
- package/dist/dashboard/assets/CombosPage-CisNZOUt.js +0 -1
- package/dist/dashboard/assets/CombosPage-CisNZOUt.js.gz +0 -0
- package/dist/dashboard/assets/ConsoleLogPage-BOpI_LOH.js +0 -1
- package/dist/dashboard/assets/ConsoleLogPage-BOpI_LOH.js.gz +0 -0
- package/dist/dashboard/assets/CustomizationPage-DAkdvJ4k.js +0 -1
- package/dist/dashboard/assets/CustomizationPage-DAkdvJ4k.js.gz +0 -0
- package/dist/dashboard/assets/HealthEventsModal-DeT-VXHd.js +0 -1
- package/dist/dashboard/assets/HealthEventsModal-DeT-VXHd.js.gz +0 -0
- package/dist/dashboard/assets/LoginPage-CytxSeGP.js +0 -1
- package/dist/dashboard/assets/LoginPage-CytxSeGP.js.gz +0 -0
- package/dist/dashboard/assets/ModelPicker-oQ-SDXp8.js +0 -1
- package/dist/dashboard/assets/ModelPicker-oQ-SDXp8.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-CU7S1wJs.js +0 -1
- package/dist/dashboard/assets/OverviewPage-CU7S1wJs.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-DLm2baot.js +0 -3
- package/dist/dashboard/assets/ProviderDetailPage-DLm2baot.js.gz +0 -0
- package/dist/dashboard/assets/ProvidersPage-DOXfuzfL.js +0 -1
- package/dist/dashboard/assets/ProvidersPage-DOXfuzfL.js.gz +0 -0
- package/dist/dashboard/assets/ProxyPage-wvk0ciQN.js +0 -7
- package/dist/dashboard/assets/ProxyPage-wvk0ciQN.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-Cn_fcUHE.js +0 -1
- package/dist/dashboard/assets/QuotaPage-Cn_fcUHE.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-8-eVadhc.js +0 -1
- package/dist/dashboard/assets/SettingsPage-8-eVadhc.js.gz +0 -0
- package/dist/dashboard/assets/SetupPage-uEIXPyGO.js +0 -1
- package/dist/dashboard/assets/SetupPage-uEIXPyGO.js.gz +0 -0
- package/dist/dashboard/assets/SortableList-DCY0TPTZ.js +0 -1
- package/dist/dashboard/assets/SortableList-DCY0TPTZ.js.gz +0 -0
- package/dist/dashboard/assets/StudioPage-DqK5E26W.js.gz +0 -0
- package/dist/dashboard/assets/UsagePage-38JfiZ0H.js +0 -56
- package/dist/dashboard/assets/UsagePage-38JfiZ0H.js.gz +0 -0
- package/dist/dashboard/assets/api-keys-BmDbsior.js.gz +0 -0
- package/dist/dashboard/assets/app-BbpSarVV.css +0 -2
- package/dist/dashboard/assets/app-BbpSarVV.css.gz +0 -0
- package/dist/dashboard/assets/badge-DpXT4Ixt.js +0 -1
- package/dist/dashboard/assets/badge-DpXT4Ixt.js.gz +0 -0
- package/dist/dashboard/assets/banner-CSAAWLJv.js +0 -1
- package/dist/dashboard/assets/banner-CSAAWLJv.js.gz +0 -0
- package/dist/dashboard/assets/card-DEhRXXw4.js +0 -1
- package/dist/dashboard/assets/card-DEhRXXw4.js.gz +0 -0
- package/dist/dashboard/assets/check-D69FzdvC.js +0 -1
- package/dist/dashboard/assets/check-D69FzdvC.js.gz +0 -0
- package/dist/dashboard/assets/cli-tools-B0wBq-RL.js.gz +0 -0
- package/dist/dashboard/assets/clipboard-button-DOo6EU8O.js +0 -1
- package/dist/dashboard/assets/clipboard-button-DOo6EU8O.js.gz +0 -0
- package/dist/dashboard/assets/copy-ngmQ9zcZ.js +0 -1
- package/dist/dashboard/assets/copy-ngmQ9zcZ.js.gz +0 -0
- package/dist/dashboard/assets/dialog-BvQeBMfP.js +0 -1
- package/dist/dashboard/assets/dialog-BvQeBMfP.js.gz +0 -0
- package/dist/dashboard/assets/drawer-CMwPXwQB.js +0 -1
- package/dist/dashboard/assets/drawer-CMwPXwQB.js.gz +0 -0
- package/dist/dashboard/assets/entry--yj84zk3.js +0 -4
- package/dist/dashboard/assets/entry--yj84zk3.js.gz +0 -0
- package/dist/dashboard/assets/entry-D4O2229X.js.gz +0 -0
- package/dist/dashboard/assets/entry-DKvr5Q9K.js +0 -1
- package/dist/dashboard/assets/entry-DKvr5Q9K.js.gz +0 -0
- package/dist/dashboard/assets/github-badge-zliLvBwr.js +0 -1
- package/dist/dashboard/assets/github-badge-zliLvBwr.js.gz +0 -0
- package/dist/dashboard/assets/index-CcD1eSJ6.js.gz +0 -0
- package/dist/dashboard/assets/inline-D1IlZZ8H.js +0 -1
- package/dist/dashboard/assets/inline-D1IlZZ8H.js.gz +0 -0
- package/dist/dashboard/assets/input-BpVZdrbc.js +0 -1
- package/dist/dashboard/assets/input-BpVZdrbc.js.gz +0 -0
- package/dist/dashboard/assets/layout-BioLW7gN.js +0 -1
- package/dist/dashboard/assets/layout-BioLW7gN.js.gz +0 -0
- package/dist/dashboard/assets/list-row-CwVcGAIc.js +0 -1
- package/dist/dashboard/assets/list-row-CwVcGAIc.js.gz +0 -0
- package/dist/dashboard/assets/live-yfEJFF9T.js.gz +0 -0
- package/dist/dashboard/assets/model-bans-CT-TxSNX.js.gz +0 -0
- package/dist/dashboard/assets/numbers-CFL4_Dqc.js +0 -1
- package/dist/dashboard/assets/numbers-CFL4_Dqc.js.gz +0 -0
- package/dist/dashboard/assets/routing-Cs6jl49L.js.gz +0 -0
- package/dist/dashboard/assets/select-XPJ-dIw3.js +0 -41
- package/dist/dashboard/assets/select-XPJ-dIw3.js.gz +0 -0
- package/dist/dashboard/assets/settings-CfcTcOyU.js.gz +0 -0
- package/dist/dashboard/assets/stack-C9_uUjaA.js +0 -1
- package/dist/dashboard/assets/stack-C9_uUjaA.js.gz +0 -0
- package/dist/dashboard/assets/state-DA0B95UQ.js +0 -1
- package/dist/dashboard/assets/state-DA0B95UQ.js.gz +0 -0
- package/dist/dashboard/assets/switch-Cittxy-x.js +0 -1
- package/dist/dashboard/assets/switch-Cittxy-x.js.gz +0 -0
- package/dist/dashboard/assets/toast-CNt_jzO4.js +0 -2
- package/dist/dashboard/assets/toast-CNt_jzO4.js.gz +0 -0
- package/dist/dashboard/assets/useMutation-BQKMcJ1H.js.gz +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{t as i}from"./arrow-right-Dl5yKnp8.js";import{t as a}from"./SortableList-DCY0TPTZ.js";import{a as o,p as ee,r as s,t as c}from"./toast-CNt_jzO4.js";import{t as l}from"./copy-ngmQ9zcZ.js";import{n as u,r as te,t as ne}from"./state-DA0B95UQ.js";import{t as d}from"./layers-2-glBbjl.js";import{t as f}from"./dialog-BvQeBMfP.js";import{t as p}from"./pencil-768ysRAr.js";import{t as m}from"./plus-DIdX_g-x.js";import{t as h}from"./route-CNSNj9Zm.js";import{t as g}from"./search-JOKus9rb.js";import{t as re}from"./trash-Cppn5c3R.js";import{l as _}from"./query-keys-D7wX2vM5.js";import{t as v}from"./dialog-actions-B1axpEg7.js";import{n as y,r as b,t as ie}from"./card-DEhRXXw4.js";import{t as ae}from"./use-clipboard-B0Sy03fE.js";import{n as x}from"./input-BpVZdrbc.js";import{t as S}from"./select-XPJ-dIw3.js";import{t as C}from"./ModelPicker-oQ-SDXp8.js";import{t as w}from"./stack-C9_uUjaA.js";import{n as T,t as E}from"./inline-D1IlZZ8H.js";import{t as D}from"./list-row-CwVcGAIc.js";import{a as O,d as k,f as A,i as j,n as M,o as N,p as P,r as F,s as I,t as oe,u as L}from"./routing-Cs6jl49L.js";import{t as R}from"./use-timeout-BwcBBRrT.js";var z=e(`copy-plus`,[[`line`,{x1:`15`,x2:`15`,y1:`12`,y2:`18`,key:`1p7wdc`}],[`line`,{x1:`12`,x2:`18`,y1:`15`,y2:`15`,key:`1nscbv`}],[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),B=t(n(),1),V=r(),H={plain:`code-chip-plain`,muted:`code-chip-muted text-text-secondary bg-surface-muted border border-inner-border px-4 py-1 rounded-chip`,accent:`code-chip-accent text-accent bg-accent-soft px-4 py-1.5 rounded-chip font-bold`};function U({value:e,tone:t=`muted`,action:n,className:r=``,children:i,...a}){return(0,V.jsxs)(`span`,{className:o(`code-chip inline-flex items-center gap-3 min-w-0 max-w-full font-mono text-caption tabular-nums`,H[t],r),...a,children:[(0,V.jsx)(`code`,{className:`code-chip-value min-w-0 overflow-hidden text-ellipsis whitespace-nowrap`,title:a.title??e,children:e}),n?(0,V.jsx)(`span`,{className:`code-chip-action inline-flex shrink-0`,children:n}):null,i]})}var W=[{value:`fallback`,label:`Fallback (try in order)`},{value:`round_robin`,label:`Round Robin (rotate)`}],G=()=>`m${Date.now().toString(36)}${Math.random().toString(36).slice(2,8)}`;function K(){let e=N(),t=M(),n=A(),r=j(),o=L(),[ee,d]=(0,B.useState)(!1),[S,O]=(0,B.useState)(null),[k,P]=(0,B.useState)(``),[F,I]=(0,B.useState)(``),[oe,z]=(0,B.useState)(!1),[H,W]=(0,B.useState)(null),[G,K]=(0,B.useState)(null),{copy:q}=ae(),J=R(),Y=(0,B.useMemo)(()=>e.data??[],[e.data]),X=()=>{O(null),P(``),I(``),d(!0)},Z=e=>{O(e),P(e.alias),I(e.targetModel),d(!0)},Q=e=>{e.preventDefault(),k.trim()&&F.trim()&&(S?n.mutate({id:S.id,request:{alias:k.trim(),targetModel:F.trim()}},{onSuccess:()=>{d(!1),O(null),c.success(`Alias updated`)},onError:e=>c.error(_(e,`Could not save the alias.`))}):t.mutate({alias:k.trim(),targetModel:F.trim()},{onSuccess:()=>{d(!1),P(``),I(``),c.success(`Alias created`)},onError:e=>c.error(_(e,`Could not create the alias.`))}))},se=(e,t)=>{q(e).then(e=>{if(!e){c.error(`Copy failed`);return}K(t),J(()=>K(null),1500)})};return(0,V.jsxs)(ie,{children:[(0,V.jsx)(b,{title:`Model Aliases`,subtitle:`Map readable names to real models (e.g. claude-mythos-5 → claude-opus-5)`,icon:(0,V.jsx)(h,{size:16}),action:(0,V.jsx)(E,{children:(0,V.jsx)(s,{variant:`primary`,size:`sm`,icon:(0,V.jsx)(m,{size:13}),onClick:X,children:`New Alias`})})}),(0,V.jsx)(y,{children:e.isPending?(0,V.jsx)(te,{label:`Loading aliases...`}):e.isError?(0,V.jsx)(u,{message:`Failed to load aliases`,onRetry:()=>e.refetch()}):Y.length===0?(0,V.jsx)(ne,{title:`No aliases defined`,message:`Create an alias to route short or friendly names to real provider model IDs.`}):(0,V.jsx)(a,{items:Y,label:`Model aliases`,gap:`8px`,disabled:o.isPending,onReorder:e=>o.mutate(e,{onError:e=>c.error(_(e,`Could not save the new order.`))}),renderItem:e=>(0,V.jsx)(D,{className:`items-start flex-col sm:flex-row`,actions:(0,V.jsxs)(T,{gap:`4px`,className:`w-full justify-start sm:w-auto sm:justify-end`,children:[(0,V.jsx)(s,{variant:`ghost`,size:`sm`,icon:(0,V.jsx)(l,{size:13}),onClick:()=>se(e.alias,e.id),title:G===e.id?`Copied!`:`Copy alias`}),(0,V.jsx)(s,{variant:`ghost`,size:`sm`,icon:(0,V.jsx)(p,{size:13}),onClick:()=>Z(e),title:`Edit target model`}),(0,V.jsx)(s,{variant:`ghost`,size:`sm`,icon:(0,V.jsx)(re,{size:13}),onClick:()=>W(e),title:`Delete alias`,className:`text-red`})]}),children:(0,V.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap min-w-0`,children:[(0,V.jsx)(U,{value:e.alias,tone:`accent`}),(0,V.jsx)(i,{size:13,className:`text-text-tertiary shrink-0`}),(0,V.jsx)(U,{value:e.targetModel,tone:`plain`})]})})})}),(0,V.jsx)(f,{open:ee,onClose:()=>d(!1),title:S?`Edit Model Alias`:`New Model Alias`,footer:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(s,{variant:`secondary`,type:`button`,onClick:()=>d(!1),children:`Cancel`}),(0,V.jsx)(s,{variant:`primary`,type:`submit`,form:`alias-form`,disabled:t.isPending||n.isPending||!k.trim()||!F.trim(),children:S?`Save Changes`:`Create Alias`})]}),children:(0,V.jsxs)(`form`,{id:`alias-form`,onSubmit:Q,className:`flex flex-col gap-6`,children:[(0,V.jsx)(x,{label:`Alias name`,id:`alias-name-input`,value:k,onChange:e=>P(e.target.value),placeholder:`e.g. fast, sonnet, smart`,required:!0}),(0,V.jsxs)(T,{gap:`8px`,align:`flex-end`,children:[(0,V.jsx)(`div`,{className:`flex-1`,children:(0,V.jsx)(x,{label:`Target model`,id:`target-model-input`,value:F,onChange:e=>I(e.target.value),placeholder:`e.g. codex/gpt-5.5, claude/claude-sonnet-5`,required:!0})}),(0,V.jsx)(s,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>z(!0),icon:(0,V.jsx)(g,{size:13}),children:`Browse`})]}),(0,V.jsx)(C,{open:oe,onClose:()=>z(!1),selected:F?[F]:[],onToggle:()=>{},onSelectOne:e=>I(e),title:`Select target model`,multi:!1})]})}),(0,V.jsx)(f,{open:!!H,onClose:()=>W(null),title:`Delete Model Alias`,children:(0,V.jsxs)(w,{gap:`12px`,children:[(0,V.jsxs)(`p`,{className:`text-body text-text-secondary`,children:[`Are you sure you want to delete alias `,(0,V.jsx)(`strong`,{children:H?.alias}),`? Clients requesting this name will need their full model path.`]}),(0,V.jsxs)(v,{children:[(0,V.jsx)(s,{variant:`secondary`,onClick:()=>W(null),children:`Cancel`}),(0,V.jsx)(s,{variant:`danger`,onClick:()=>{H&&r.mutate(H.id,{onSuccess:()=>W(null)})},disabled:r.isPending,children:r.isPending?`Deleting...`:`Delete Alias`})]})]})})]})}function q(){let e=I(),t=F(),n=oe(),r=P(),i=O(),o=k(),[h,A]=(0,B.useState)(!1),[j,M]=(0,B.useState)(null),[N,L]=(0,B.useState)(``),[H,K]=(0,B.useState)([]),[q,J]=(0,B.useState)(`fallback`),[Y,X]=(0,B.useState)(!1),[Z,Q]=(0,B.useState)(null),[se,ce]=(0,B.useState)(null),{copy:le}=ae(),ue=R(),$=(0,B.useMemo)(()=>H.map(e=>e.value),[H]),de=e=>{$.includes(e)?K(H.filter(t=>t.value!==e)):K([...H,{id:G(),value:e.trim()}])},fe=e.data??[],pe=()=>{M(null),L(``),K([]),J(`fallback`),A(!0)},me=e=>{M(e),L(e.name),K(e.members.map(e=>({id:G(),value:e}))),A(!0)},he=e=>{n.mutate(e.id,{onSuccess:e=>{let t=e.skippedMembers;t.length>0?c.success(`Combo cloned`,`${e.combo.name} — skipped unresolvable member${t.length>1?`s`:``}: ${t.join(`, `)}`):c.success(`Combo cloned`,e.combo.name)},onError:e=>c.error(_(e,`Could not clone the combo.`))})},ge=e=>{e.preventDefault(),N.trim()&&$.length!==0&&(j?r.mutate({id:j.id,request:{name:N.trim(),members:$,strategy:q}},{onSuccess:()=>{A(!1),M(null),c.success(`Combo saved`)},onError:e=>c.error(_(e,`Could not save the combo.`))}):t.mutate({name:N.trim(),members:$,strategy:q},{onSuccess:()=>{A(!1),L(``),K([]),c.success(`Combo created`)},onError:e=>c.error(_(e,`Could not create the combo.`))}))},_e=(e,t)=>{r.mutate({id:e.id,request:{strategy:t}},{onSuccess:()=>c.success(`Combo strategy updated`),onError:e=>c.error(_(e,`Could not update the combo strategy.`))})},ve=(e,t)=>{le(e).then(e=>{if(!e){c.error(`Copy failed`);return}ce(t),ue(()=>ce(null),1500)})};return(0,V.jsxs)(ie,{children:[(0,V.jsx)(b,{title:`Combos`,subtitle:`Combine multiple models with fallback or round-robin rotation`,icon:(0,V.jsx)(d,{size:16}),action:(0,V.jsx)(E,{children:(0,V.jsx)(s,{variant:`primary`,size:`sm`,icon:(0,V.jsx)(m,{size:13}),onClick:pe,children:`New Combo`})})}),(0,V.jsx)(y,{children:e.isPending?(0,V.jsx)(te,{label:`Loading combos...`}):e.isError?(0,V.jsx)(u,{message:`Failed to load combos`,onRetry:()=>e.refetch()}):fe.length===0?(0,V.jsx)(ne,{title:`No combos defined`,message:`Create a model combo to distribute requests across multiple models.`}):(0,V.jsx)(a,{items:fe,label:`Model combos`,disabled:o.isPending,onReorder:e=>o.mutate(e,{onError:e=>c.error(_(e,`Could not save the new order.`))}),renderItem:e=>(0,V.jsxs)(D,{className:`items-start flex-col sm:flex-row`,actions:(0,V.jsxs)(T,{gap:`8px`,className:`w-full justify-between sm:w-auto sm:justify-start`,children:[(0,V.jsx)(S,{value:e.strategy,onValueChange:t=>_e(e,t),options:W}),(0,V.jsxs)(T,{gap:`4px`,className:`flex-wrap`,children:[(0,V.jsx)(s,{variant:`ghost`,size:`sm`,icon:(0,V.jsx)(l,{size:13}),onClick:()=>ve(e.name,e.id),title:se===e.id?`Copied!`:`Copy combo name`}),(0,V.jsx)(s,{variant:`ghost`,size:`sm`,icon:(0,V.jsx)(z,{size:13}),onClick:()=>he(e),disabled:n.isPending,title:`Clone combo (same members and strategy)`}),(0,V.jsx)(s,{variant:`ghost`,size:`sm`,icon:(0,V.jsx)(p,{size:13}),onClick:()=>me(e),title:`Edit combo`}),(0,V.jsx)(s,{variant:`ghost`,size:`sm`,icon:(0,V.jsx)(re,{size:13}),onClick:()=>Q(e),title:`Delete combo`,className:`text-red`})]})]}),children:[(0,V.jsx)(`div`,{className:`flex items-center justify-between gap-6 flex-wrap`,children:(0,V.jsx)(`strong`,{className:`text-body`,children:e.name})}),(0,V.jsx)(T,{gap:`6px`,className:`w-full flex-wrap`,children:e.members.map(e=>(0,V.jsx)(U,{value:e},e))})]})})}),(0,V.jsx)(f,{open:h,onClose:()=>A(!1),title:j?`Edit Model Combo`:`New Model Combo`,footer:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(s,{variant:`secondary`,type:`button`,onClick:()=>A(!1),children:`Cancel`}),(0,V.jsx)(s,{variant:`primary`,type:`submit`,form:`combo-form`,disabled:t.isPending||r.isPending||!N.trim()||$.length===0,children:j?`Save Changes`:`Create Combo`})]}),children:(0,V.jsxs)(`form`,{id:`combo-form`,onSubmit:ge,className:`flex flex-col gap-6`,children:[(0,V.jsx)(x,{label:`Combo name`,id:`combo-name-input`,value:N,onChange:e=>L(e.target.value),placeholder:`e.g. smart-combo, fast-pool`,required:!0}),(0,V.jsx)(S,{label:`Strategy`,id:`combo-strategy-select`,value:q,onValueChange:e=>J(e),options:W}),(0,V.jsxs)(w,{gap:`6px`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,V.jsx)(`label`,{className:`text-caption font-semibold text-text-secondary`,children:`Member models — use arrows or drag to reorder`}),(0,V.jsx)(s,{variant:`secondary`,size:`sm`,type:`button`,icon:(0,V.jsx)(g,{size:12}),onClick:()=>X(!0),children:`Browse models`})]}),(0,V.jsx)(`div`,{role:`list`,"aria-label":`Combo members`,"data-testid":`combo-members-list`,className:`flex min-h-22 flex-col gap-2 rounded-control border border-dashed border-inner-border ${H.length===0?`p-0`:`p-3`}`,children:H.length===0?(0,V.jsx)(`button`,{type:`button`,onClick:()=>X(!0),className:`flex-1 cursor-pointer font-inherit text-caption text-text-tertiary`,children:`Pick models to add`}):(0,V.jsx)(a,{items:H,label:`Combo members`,gap:`4px`,onReorder:e=>{let t=new Map(H.map(e=>[e.id,e]));K(e.map(e=>t.get(e)).filter(Boolean))},renderItem:e=>(0,V.jsx)(D,{density:`compact`,actions:(0,V.jsx)(`button`,{type:`button`,onClick:()=>de(e.value),"aria-label":`Remove ${e.value}`,className:`flex shrink-0 cursor-pointer text-text-tertiary`,children:(0,V.jsx)(ee,{size:12})}),children:(0,V.jsx)(U,{value:e.value,tone:`accent`})})})})]}),(0,V.jsx)(C,{open:Y,onClose:()=>X(!1),selected:$,onToggle:de,title:`Select combo members`,multi:!0})]})}),(0,V.jsx)(f,{open:!!Z,onClose:()=>Q(null),title:`Delete Model Combo`,children:(0,V.jsxs)(w,{gap:`12px`,children:[(0,V.jsxs)(`p`,{className:`text-body text-text-secondary`,children:[`Are you sure you want to delete combo `,(0,V.jsx)(`strong`,{children:Z?.name}),`? Any aliases pointing to it will fail to resolve.`]}),(0,V.jsxs)(v,{children:[(0,V.jsx)(s,{variant:`secondary`,onClick:()=>Q(null),children:`Cancel`}),(0,V.jsx)(s,{variant:`danger`,onClick:()=>{Z&&i.mutate(Z.id,{onSuccess:()=>Q(null)})},disabled:i.isPending,children:i.isPending?`Deleting...`:`Delete Combo`})]})]})})]})}function J(){return(0,V.jsxs)(w,{gap:`16px`,children:[(0,V.jsx)(q,{}),(0,V.jsx)(K,{})]})}export{J as default};
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e,r as t,t as n}from"./jsx-runtime-CXUMngI_.js";import{r,t as i}from"./toast-CNt_jzO4.js";import{n as a,r as o,t as s}from"./state-DA0B95UQ.js";import{t as c}from"./refresh-cw-BqJFk4sU.js";import{t as l}from"./search-JOKus9rb.js";import{t as u}from"./shield-check-DVS0Foqh.js";import{t as d}from"./trash-Cppn5c3R.js";import{l as f,o as p,u as m}from"./query-keys-D7wX2vM5.js";import{A as h,L as g,k as _,rt as v}from"./entry--yj84zk3.js";import{n as y,r as b,t as x}from"./card-DEhRXXw4.js";import{r as S}from"./numbers-CFL4_Dqc.js";import{t as C}from"./stream-retry-5QnVuSSo.js";import{t as w}from"./badge-DpXT4Ixt.js";import{n as T}from"./input-BpVZdrbc.js";import{t as E}from"./layout-BioLW7gN.js";var D=e(t(),1),O=500,k=1500;function A(e){return m(e)&&typeof e.ts==`string`&&(e.level===`debug`||e.level===`info`||e.level===`warn`||e.level===`error`)&&typeof e.msg==`string`}function j(e){return!m(e)||!Array.isArray(e.lines)?[]:e.lines.filter(A)}function M(){let[e,t]=(0,D.useState)([]),[n,r]=(0,D.useState)(new Set),[i,a]=(0,D.useState)(`idle`),o=(0,D.useRef)(0),s=(0,D.useRef)(0),c=(0,D.useRef)(new Set),l=e=>({...e,id:`l${s.current+=1}`});return(0,D.useEffect)(()=>{let e=!1,n,i=o.current+=1,s=(e,t)=>{let n=window.setTimeout(()=>{c.current.delete(n),e()},t);c.current.add(n)},u=e=>{let n=l(e);r(e=>{let t=new Set(e);return t.add(n.id),t}),s(()=>{r(e=>{if(!e.has(n.id))return e;let t=new Set(e);return t.delete(n.id),t})},k),t(e=>{let t=[...e,n];return t.length>O?t.slice(t.length-O):t})},d=()=>{n=new EventSource(`/console/api/logs/stream`),n.addEventListener(`init`,n=>{if(!e)try{let e=JSON.parse(n.data);m(e)&&(t(j(e).slice(-500).map(l)),r(new Set)),a(`live`)}catch{}}),n.addEventListener(`line`,t=>{if(!e)try{let e=JSON.parse(t.data);A(e)&&(u(e),a(`live`))}catch{}}),n.addEventListener(`clear`,()=>{e||(t([]),r(new Set))}),n.onerror=()=>{n?.close(),!e&&(a(`reconnecting`),s(()=>{!e&&i===o.current&&f()},C))}},f=async()=>{try{let n=await p(`/logs?limit=200`);if(e||i!==o.current)return;t(j(n).slice(-500).map(l)),r(new Set),d()}catch{}};return f(),()=>{e=!0;for(let e of c.current)window.clearTimeout(e);c.current.clear(),n?.close()}},[]),{lines:e,newLineIds:n,status:i,clear:(0,D.useCallback)(async()=>{await p(`/logs`,{method:`DELETE`}),t([]),r(new Set)},[])}}var N={"api_key.created":`API key created`,"api_key.updated":`API key updated`,"api_key.revoked":`API key revoked`,"api_key.regenerated":`API key regenerated`,"api_key.shared":`API key shared`,"api_key.share_regenerated":`API key share link regenerated`,"api_key.share_revoked":`API key unshared`,"provider.created":`Provider created`,"provider.updated":`Provider updated`,"provider.deleted":`Provider deleted`,"provider.global.updated":`Global provider updated`,"provider.global.deleted":`Global provider deleted`,"provider.routing.updated":`Provider routing updated`,"provider.models.registered":`Provider models registered`,"provider.models.bulk_deleted":`Provider models bulk-deleted`,"provider.model.deleted":`Provider model deleted`,"provider.model.enabled":`Provider model enabled`,"provider.model.disabled":`Provider model disabled`,"provider_account.created":`Provider account connected`,"provider_account.updated":`Provider account updated`,"provider_account.recovered":`Provider account recovered`,"provider_account.revoked":`Provider account revoked`,"provider_account.circuit_force_closed":`Provider account circuit force-closed`,"provider_account.deleted":`Provider account deleted`,"provider_account.exported":`Provider accounts exported (plaintext)`,"provider_account.global.updated":`Global provider account updated`,"provider_account.global.refreshed":`Global provider account refreshed`,"provider_account.global.deleted":`Global provider account deleted`,"model_alias.created":`Model alias created`,"model_alias.updated":`Model alias updated`,"model_alias.deleted":`Model alias deleted`,"model_combo.created":`Model combo created`,"model_combo.updated":`Model combo updated`,"model_combo.cloned":`Model combo cloned`,"model_combo.deleted":`Model combo deleted`,"network_pool.created":`Network pool created`,"network_pool.updated":`Network pool updated`,"network_pool.deleted":`Network pool deleted`,"network_pool.recovered":`Network pool recovered`,"network_pool.strategy_updated":`Network pool strategy updated`,"network_pool.relay_deployed":`Network pool relay deployed`,"filter_rule.created":`Filter rule created`,"filter_rule.updated":`Filter rule updated`,"filter_rule.deleted":`Filter rule deleted`,"filter_rule.reordered":`Filter rules reordered`,"filter_rule.master_toggle":`Filter master switch toggled`,"settings.runtime.updated":`Runtime settings updated`,"cli_tool.mappings_saved":`CLI tool mappings saved`,"cli_tool.mappings_reset":`CLI tool mappings reset`,"cli_tool.applied":`CLI tool applied`,"console.password_changed":`Console password changed`,"console_logs.cleared":`Console logs cleared`,"security.ip_banned":`IP banned`,"backup.reset":`Backup reset`,"backup.delete_all":`Delete all configuration`},P={api:`API`,ip:`IP`,cli:`CLI`,oauth:`OAuth`};function F(e){return e.split(`.`).map(e=>e.split(/[_-]+/).filter(Boolean).map(e=>P[e.toLowerCase()]??e.charAt(0).toUpperCase()+e.slice(1)).join(` `)).join(` · `)}function I(e){return N[e]??F(e)}var L=n(),R=50,z=[{id:`all`,label:`All`},{id:`debug`,label:`Debug`},{id:`info`,label:`Info`},{id:`warn`,label:`Warn`},{id:`error`,label:`Error`}],B={debug:`var(--text-tertiary)`,info:`var(--accent)`,warn:`var(--orange)`,error:`var(--red)`},V={debug:`DBG`,info:`INF`,warn:`WRN`,error:`ERR`};function H(e){return e>=500?`err`:e>=400?`warn`:`ok`}function U(e,t,n){let r=n.trim().toLowerCase();return e.filter(e=>t!==`all`&&e.level!==t?!1:!r||`${e.msg} ${e.endpoint??``} ${e.model??``} ${e.routedModel??``} ${e.providerId??``} ${e.errorCode??``} ${e.userAgent??``} ${e.clientIp??``} ${e.accountLabel??``}`.toLowerCase().includes(r))}function W(){let[e,t]=(0,D.useState)(`logs`),n=h().data?.isPlatformAdmin??!1,i=e===`audit`&&!n?`logs`:e,a=(0,L.jsxs)(`div`,{className:`flex gap-4`,children:[(0,L.jsx)(r,{variant:i===`logs`?`primary`:`secondary`,size:`sm`,onClick:()=>t(`logs`),icon:(0,L.jsx)(v,{size:13}),"aria-pressed":i===`logs`,children:`Console Log`}),n?(0,L.jsx)(r,{variant:i===`audit`?`primary`:`secondary`,size:`sm`,onClick:()=>t(`audit`),icon:(0,L.jsx)(u,{size:13}),"aria-pressed":i===`audit`,children:`Admin Audit`}):null]});return(0,L.jsx)(`div`,{className:`flex flex-col flex-1 min-h-0`,children:i===`logs`?(0,L.jsx)(Q,{tabAction:a}):(0,L.jsx)($,{tabAction:a})})}function G(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleTimeString([],{hour12:!1})}function K(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function q(e){let t=e.details;if(!t)return null;let n=typeof t.inputTokens==`number`?t.inputTokens:void 0,r=typeof t.outputTokens==`number`?t.outputTokens:void 0,i=typeof t.cachedInputTokens==`number`?t.cachedInputTokens:void 0,a=typeof t.reasoningTokens==`number`?t.reasoningTokens:void 0;if(n===void 0&&r===void 0&&i===void 0&&a===void 0)return null;let o=[];return n!==void 0&&o.push(`${K(n)} in`),r!==void 0&&o.push(`${K(r)} out`),i!==void 0&&o.push(`${K(i)} cached`),a!==void 0&&a>0&&o.push(`${K(a)} reason`),o.join(` / `)}function J(e){let t=e.model,n=e.routedModel,r=e.providerId,i=n??t;if(!i&&!r)return null;let a=r&&i?`${r}/${i}`:i??r??``;return n&&t&&n!==t?`${a} ← ${t}`:a}var Y=(0,D.memo)(function({line:e,isNew:t}){let n=e.event!==void 0,r=e.level;return(0,L.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-4 px-8 py-1.5 font-mono text-caption leading-normal max-medium:gap-3 max-medium:px-5 max-medium:text-badge${r===`warn`?` bg-orange-soft`:r===`error`?` bg-red-soft`:``}${t?` bg-surface-muted`:``} hover:bg-surface-hover`,"data-log-tone":r,children:[(0,L.jsx)(`span`,{className:`max-medium:flex-none flex-none tabular-nums text-text-tertiary`,children:G(e.ts)}),(0,L.jsx)(`span`,{className:`flex-none w-13 text-left text-micro font-bold tracking-label`,style:{color:B[e.level]},title:e.level.toUpperCase(),children:V[e.level]}),n?(0,L.jsx)(X,{line:e}):(0,L.jsx)(`span`,{className:`min-w-0 flex-1 whitespace-pre-wrap wrap-anywhere break-words text-text-secondary`,children:e.msg})]})});function X({line:e}){let t=J(e),n=q(e),r=Z(e);return(0,L.jsxs)(`span`,{className:`min-w-0 flex-1 whitespace-pre-wrap wrap-anywhere`,children:[(0,L.jsxs)(`span`,{className:`font-bold tracking-label ${r.tone}`,"data-log-field":`badge`,children:[`[`,r.label,`]`]}),` `,(0,L.jsx)(`span`,{className:`text-text-tertiary`,children:e.method??`POST`}),` `,(0,L.jsx)(`span`,{className:`text-text-primary`,children:e.endpoint??``}),e.status===void 0?null:(0,L.jsxs)(L.Fragment,{children:[` `,(0,L.jsx)(`span`,{className:`tabular-nums ${H(e.status)===`ok`?`text-text-tertiary`:H(e.status)===`warn`?`text-orange font-semibold`:`text-red font-semibold`}`,children:e.status})]}),e.durationMs===void 0?null:(0,L.jsxs)(L.Fragment,{children:[` `,(0,L.jsx)(`span`,{className:`tabular-nums text-text-secondary`,children:S(e.durationMs)})]}),t?(0,L.jsxs)(L.Fragment,{children:[` `,(0,L.jsx)(`span`,{className:`text-status-info`,"data-log-field":`route`,children:t})]}):null,e.accountLabel?(0,L.jsxs)(L.Fragment,{children:[` `,(0,L.jsx)(`span`,{className:`text-purple`,"data-log-field":`account`,title:e.accountId??void 0,children:e.accountLabel})]}):null,e.clientIp?(0,L.jsxs)(L.Fragment,{children:[` `,(0,L.jsx)(`span`,{className:`tabular-nums text-text-secondary`,"data-log-field":`ip`,children:e.clientIp})]}):null,n?(0,L.jsxs)(L.Fragment,{children:[` `,(0,L.jsx)(`span`,{className:`tabular-nums text-orange`,"data-log-field":`tokens`,children:n})]}):null,e.errorCode?(0,L.jsxs)(L.Fragment,{children:[` `,(0,L.jsxs)(`span`,{className:`text-red`,title:e.msg,children:[e.msg,` (`,e.errorCode,`)`]})]}):null,e.requestId?(0,L.jsxs)(L.Fragment,{children:[` `,(0,L.jsx)(`span`,{className:`text-micro text-text-tertiary`,"data-log-field":`id`,children:e.requestId.slice(0,8)})]}):null]})}function Z(e){return e.event===`request_start`||e.status===void 0?{label:`REQUEST`,tone:`text-text-tertiary`}:e.event===`request_error`||e.status>=400?{label:`FAILED`,tone:`text-red`}:{label:`SUCCESS`,tone:`text-status-info`}}function Q({tabAction:e}){let{lines:t,newLineIds:n,clear:r}=M(),[a,o]=(0,D.useState)(`all`),[c,u]=(0,D.useState)(``),[f,p]=(0,D.useState)(!1),[m,h]=(0,D.useState)(null),_=c.trim().toLowerCase(),S=(0,D.useMemo)(()=>U(t,a,_).slice().reverse(),[t,a,_]),C=(0,D.useMemo)(()=>{let e=new Map([[`all`,t.length]]);for(let n of t)e.set(n.level,(e.get(n.level)??0)+1);return e},[t]);return(0,L.jsxs)(x,{className:`flex-1 min-h-0 flex flex-col`,children:[(0,L.jsx)(b,{title:`Console Log`,subtitle:`${S.length} of ${t.length} lines`,icon:(0,L.jsx)(v,{size:16}),action:e}),(0,L.jsxs)(y,{className:`flex flex-row items-center justify-between gap-8 flex-none min-h-0 px-7 py-4 border-b border-inner-border max-medium:flex-col max-medium:items-start max-medium:gap-4`,children:[(0,L.jsx)(`div`,{className:`inline-flex items-center gap-1.5 flex-none max-medium:w-full max-medium:overflow-x-auto`,role:`group`,"aria-label":`Log level`,children:z.map(e=>{let t=C.get(e.id)??0;return(0,L.jsxs)(`button`,{className:`inline-flex items-center appearance-none border-0 rounded-tiny px-5 py-3.5 bg-transparent font-sans text-badge font-semibold leading-none cursor-pointer ${a===e.id?`bg-surface-muted text-text-primary`:`text-text-tertiary hover:bg-surface-muted hover:text-text-primary`}`,type:`button`,onClick:()=>o(e.id),"aria-pressed":a===e.id,children:[(0,L.jsx)(`span`,{children:e.label}),(0,L.jsx)(`span`,{className:`ml-2.5 text-inherit opacity-65 tabular-nums`,children:t})]},e.id)})}),(0,L.jsxs)(`div`,{className:`flex items-center gap-4 ml-auto max-medium:w-full max-medium:ml-0 max-medium:min-w-0`,children:[(0,L.jsxs)(`div`,{className:`relative w-140 min-w-0 max-w-full max-medium:flex-auto max-medium:w-auto`,children:[(0,L.jsx)(l,{size:13,"aria-hidden":`true`,className:`absolute left-5 top-1/2 -translate-y-1/2 text-text-tertiary pointer-events-none`}),(0,L.jsx)(T,{"aria-label":`Search console logs`,value:c,onChange:e=>u(e.target.value),placeholder:`Search logs...`,className:`pl-15 w-full min-w-0`})]}),(0,L.jsx)(`button`,{className:`inline-grid place-items-center w-16 h-16 border border-border-subtle rounded-control bg-transparent text-text-secondary cursor-pointer hover:border-red hover:text-red hover:bg-red-soft`,type:`button`,onClick:()=>p(!0),"aria-label":`Clear console logs`,title:`Clear logs`,children:(0,L.jsx)(d,{size:15,"aria-hidden":`true`})})]})]}),(0,L.jsxs)(y,{className:`p-0 flex-1 min-h-0 flex flex-col`,children:[(0,L.jsx)(`div`,{className:`scroll-region flex-1 min-h-0 flex flex-col p-0 bg-code-surface text-text-primary`,children:S.length===0?(0,L.jsx)(s,{title:t.length===0?`No log lines yet`:_?`No lines match your search`:`No lines match this level`,message:t.length===0?`Server log output will stream here as the gateway runs.`:`Adjust the search or pick another level to widen the view.`,icon:(0,L.jsx)(v,{size:20})}):S.map(e=>(0,L.jsx)(Y,{line:e,isNew:n.has(e.id)},e.id))}),(0,L.jsx)(`div`,{className:`flex items-center justify-between gap-5 shrink-0 px-8 py-4 border-t border-inner-border bg-surface-2 text-micro text-text-tertiary`,"aria-live":`polite`,children:(0,L.jsxs)(`span`,{className:`min-w-0 overflow-hidden text-ellipsis whitespace-nowrap`,children:[S.length,` of `,t.length,` lines`,a===`all`?``:` · ${a}`,_?` · search: "${c.trim()}"`:``]})})]}),(0,L.jsx)(g,{open:f,onClose:()=>p(!1),onConfirm:async()=>{h(null);try{await r(),p(!1),i.success(`Console logs cleared`)}catch{h(`Failed to clear server logs.`)}},title:`Clear console logs`,message:`Clear the in-memory server log tail? New lines keep streaming afterwards.`,confirmLabel:`Clear`,danger:!0}),m?(0,L.jsx)(`span`,{className:`text-badge text-red pt-0 px-8 pb-4`,children:m}):null]})}function $({tabAction:e}){let[t,n]=(0,D.useState)(``),[i,l]=(0,D.useState)(``),[d,p]=(0,D.useState)(``),[m,h]=(0,D.useState)(``),[g,v]=(0,D.useState)(void 0),[S,C]=(0,D.useState)([]);(0,D.useEffect)(()=>{let e=setTimeout(()=>p(t),300);return()=>clearTimeout(e)},[t]),(0,D.useEffect)(()=>{let e=setTimeout(()=>h(i),300);return()=>clearTimeout(e)},[i]);let w=_({limit:R,...d?{action:d}:{},...m?{actor:m}:{},...g?{cursor:g}:{}}),O=w.data,k=O?.entries??[],A=O?.nextCursor,j=()=>{A&&(C(e=>[...e,g??``]),v(A))},M=()=>{C(e=>{let t=e[e.length-1];return v(t||void 0),e.slice(0,-1)})},N=()=>{v(void 0),C([])};return(0,L.jsxs)(x,{className:`flex-1 min-h-0 flex flex-col`,children:[(0,L.jsx)(b,{title:`Admin Audit Trail`,subtitle:`Every privileged console mutation, retained on its own lifecycle`,icon:(0,L.jsx)(u,{size:16}),action:(0,L.jsxs)(`div`,{className:`flex gap-4 items-center`,children:[e,(0,L.jsx)(r,{variant:`secondary`,size:`sm`,onClick:()=>void w.refetch(),disabled:w.isFetching,icon:(0,L.jsx)(c,{size:13,className:w.isFetching?`animate-spin`:``}),children:`Refresh`})]})}),(0,L.jsxs)(y,{className:`flex flex-row items-center justify-between gap-6 flex-none min-h-0 px-8 py-5 border-b border-inner-border items-end`,children:[(0,L.jsx)(T,{label:`Action`,placeholder:`e.g. provider updated`,value:t,onChange:e=>{n(e.target.value),N()}}),(0,L.jsx)(T,{label:`Actor`,placeholder:`e.g. alice or a user id`,value:i,onChange:e=>{l(e.target.value),N()}}),(0,L.jsxs)(`div`,{className:`ml-auto flex gap-4`,children:[(0,L.jsx)(r,{size:`sm`,variant:`secondary`,onClick:M,disabled:S.length===0,children:`← Newer`}),(0,L.jsx)(r,{size:`sm`,variant:`secondary`,onClick:j,disabled:!A,children:`Older →`})]})]}),(0,L.jsx)(y,{className:`p-0 flex-1 min-h-0 flex flex-col`,children:(0,L.jsx)(`div`,{className:`flex-1 min-h-0 flex flex-col overflow-y-auto p-0 bg-transparent text-inherit`,children:w.isPending&&k.length===0?(0,L.jsx)(o,{label:`Loading audit trail…`}):w.isError&&k.length===0?(0,L.jsx)(a,{message:f(w.error,`Unable to load audit trail.`),onRetry:()=>void w.refetch()}):k.length===0?(0,L.jsx)(s,{title:`No audit entries yet`,message:`Privileged mutations (provider changes, key rotations, backups, bans) will appear here.`,icon:(0,L.jsx)(u,{size:20})}):(0,L.jsx)(E,{headers:[`Timestamp`,`Actor`,`Action`,`Target`,`Detail`],children:k.map(e=>(0,L.jsx)(ee,{entry:e},e.id))})})})]})}function ee({entry:e}){return(0,L.jsxs)(`tr`,{children:[(0,L.jsx)(`td`,{className:`text-badge text-text-tertiary whitespace-nowrap`,children:new Date(e.createdAt).toLocaleString()}),(0,L.jsxs)(`td`,{className:`max-w-100`,children:[(0,L.jsx)(`div`,{className:`text-caption font-semibold`,children:e.actorName??e.actor}),e.actorName?(0,L.jsx)(`div`,{title:e.actor,className:`truncate font-mono tabular-nums text-micro text-text-tertiary`,children:e.actor}):null]}),(0,L.jsx)(`td`,{children:(0,L.jsx)(w,{tone:e.action.includes(`delete`)||e.action.includes(`revoked`)?`err`:`ok`,title:e.action,children:I(e.action)})}),(0,L.jsx)(`td`,{title:e.target,className:`truncate font-mono tabular-nums text-badge max-w-110`,children:e.target}),(0,L.jsx)(`td`,{className:`font-mono tabular-nums text-badge max-w-160 overflow-hidden truncate`,children:e.detail?JSON.stringify(e.detail):`—`})]})}export{W as default,U as filterLogLines,H as statusTone};
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{f as i,r as a}from"./toast-CNt_jzO4.js";import{t as o}from"./image-BPaouViG.js";import{t as s}from"./layers-2-glBbjl.js";import{t as c}from"./rotate-ccw-CufcqITi.js";import{B as l,G as u,J as d,K as f,R as p,U as m,V as h,W as g,Y as _,q as v,z as y}from"./entry--yj84zk3.js";import{n as b,r as x,t as S}from"./card-DEhRXXw4.js";import{t as C}from"./switch-Cittxy-x.js";import{t as w}from"./stack-C9_uUjaA.js";import{t as T}from"./inline-D1IlZZ8H.js";var E=e(`frame`,[[`line`,{x1:`22`,x2:`2`,y1:`6`,y2:`6`,key:`15w7dq`}],[`line`,{x1:`22`,x2:`2`,y1:`18`,y2:`18`,key:`1ip48p`}],[`line`,{x1:`6`,x2:`6`,y1:`2`,y2:`22`,key:`a2lnyx`}],[`line`,{x1:`18`,x2:`18`,y1:`2`,y2:`22`,key:`8vb6jd`}]]),D=e(`panel-top`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M3 9h18`,key:`1pudct`}]]),O=e(`rectangle-horizontal`,[[`rect`,{width:`20`,height:`12`,x:`2`,y:`6`,rx:`2`,key:`9lu3g6`}]]),k=t(n(),1),A=r(),j={cards:{label:`Cards`,description:`The card body on every page`,icon:(0,A.jsx)(O,{size:15})},chrome:{label:`Sidebar & topbar`,description:`The shell around the page`,icon:(0,A.jsx)(D,{size:15})}};function M(e){return e<1048576?`${Math.max(1,Math.round(e/1024))} KB`:`${(e/1048576).toFixed(1)} MB`}function N(){let[e,t]=h(),[n,r]=(0,k.useState)(!1),[g,v]=(0,k.useState)(null),C=async n=>{let a=n.target.files?.[0];if(n.target.value=``,!a)return;let o=f(a);if(!o){i.error(`Choose an image or a video.`);return}if(a.size>4294967296){i.error(`File too big. 4 GB is the limit.`);return}let s=a.size>m;r(!0);try{let n=o===`image`?await d(a):a;await _(n,o),v(n.size),t({backgroundSet:!0,backgroundEnabled:!0,backgroundRevision:e.backgroundRevision+1}),i.success(o===`video`?`Video background saved in this browser.`:`Background saved in this browser.`),s&&i.warning(`File too big. Your web performance and experience may be degraded.`)}catch{i.error(`Could not store that file. The browser may be out of space.`)}finally{r(!1)}},D=async()=>{r(!0);try{await u(),v(null),t({backgroundSet:!1,backgroundEnabled:!1})}catch{i.error(`Could not remove the background.`)}finally{r(!1)}};return(0,A.jsxs)(w,{gap:`16px`,children:[(0,A.jsxs)(S,{children:[(0,A.jsx)(x,{title:`Background`,subtitle:`Stored in this browser only. It never leaves the machine.`,icon:(0,A.jsx)(o,{size:16}),action:(0,A.jsx)(T,{children:(0,A.jsx)(a,{variant:`ghost`,size:`sm`,icon:(0,A.jsx)(c,{size:13}),onClick:()=>{l({backgroundOpacity:y.backgroundOpacity,backgroundScale:y.backgroundScale,backgroundX:y.backgroundX,backgroundY:y.backgroundY,backgroundBlur:y.backgroundBlur,backgroundEnabled:e.backgroundSet}),i.success(`Background reset to defaults.`)},children:`Reset`})})}),(0,A.jsx)(b,{children:(0,A.jsxs)(w,{gap:`14px`,children:[(0,A.jsx)(P,{settings:e,onBytes:v,bytes:g}),(0,A.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,A.jsxs)(`label`,{className:`btn btn-primary inline-flex items-center justify-center gap-3.5 rounded-control font-semibold text-caption px-7 py-2 cursor-pointer bg-accent text-accent-foreground`,children:[n?`Working…`:e.backgroundSet?`Replace`:`Upload image or video`,(0,A.jsx)(`input`,{type:`file`,accept:`image/*,video/*`,className:`sr-only`,onChange:e=>void C(e),disabled:n})]}),e.backgroundSet?(0,A.jsx)(a,{variant:`danger`,size:`sm`,onClick:()=>void D(),disabled:n,children:`Remove`}):null,(0,A.jsx)(`span`,{className:`text-badge text-text-tertiary`,children:`Images are resized to 2560px. Videos play on desktop and show their first frame on mobile.`})]}),(0,A.jsx)(F,{settings:e,setSettings:t})]})})]}),(0,A.jsxs)(S,{children:[(0,A.jsx)(x,{title:`Blur`,subtitle:`Each surface keeps its own style. Dialogs are never blurred, so they stay readable.`,icon:(0,A.jsx)(s,{size:16}),action:(0,A.jsx)(T,{children:(0,A.jsx)(a,{variant:`ghost`,size:`sm`,icon:(0,A.jsx)(c,{size:13}),onClick:()=>{l({blurCardsAmount:y.blurCardsAmount,blurChromeAmount:y.blurChromeAmount,blurCardsEnabled:y.blurCardsEnabled,blurChromeEnabled:y.blurChromeEnabled,blurCardsDepth:y.blurCardsDepth,blurChromeDepth:y.blurChromeDepth}),i.success(`Blur reset to defaults.`)},children:`Reset`})})}),(0,A.jsx)(b,{children:(0,A.jsx)(`div`,{className:`grid gap-10 lg:grid-cols-2`,children:p.map(n=>{let r=n===`chrome`;return(0,A.jsx)(L,{target:n,enabled:r?e.blurChromeEnabled:e.blurCardsEnabled,onToggle:()=>t(r?{blurChromeEnabled:!e.blurChromeEnabled}:{blurCardsEnabled:!e.blurCardsEnabled}),clarity:r?e.blurChromeAmount:e.blurCardsAmount,onClarity:e=>t(r?{blurChromeAmount:e}:{blurCardsAmount:e}),depth:r?e.blurChromeDepth:e.blurCardsDepth,onDepth:e=>t(r?{blurChromeDepth:e}:{blurCardsDepth:e})},n)})})})]}),(0,A.jsxs)(S,{children:[(0,A.jsx)(x,{title:`Empty panels`,subtitle:`A dashed frame around a page that has nothing to show yet.`,icon:(0,A.jsx)(E,{size:16})}),(0,A.jsx)(b,{children:(0,A.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":e.emptyOutline,onClick:()=>t({emptyOutline:!e.emptyOutline}),className:`flex w-full items-center justify-between gap-6 rounded-card border border-inner-border bg-surface-2 px-7 py-6 text-left`,children:[(0,A.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[(0,A.jsx)(`span`,{className:`text-caption font-semibold text-text-primary`,children:`Dashed border`}),(0,A.jsx)(`span`,{className:`text-badge text-text-tertiary`,children:`Off leaves the empty state sitting on the card.`})]}),(0,A.jsx)(`span`,{"aria-hidden":`true`,className:e.emptyOutline?`h-10 w-18 shrink-0 rounded-pill bg-accent p-1`:`h-10 w-18 shrink-0 rounded-pill bg-surface-active p-1`,children:(0,A.jsx)(`span`,{className:e.emptyOutline?`block size-8 translate-x-8 rounded-full bg-accent-foreground transition-transform`:`block size-8 rounded-full bg-text-secondary transition-transform`})})]})})]})]})}function P({settings:e,bytes:t,onBytes:n}){let[r,i]=(0,k.useState)(null),[a,o]=(0,k.useState)(null);if((0,k.useEffect)(()=>{if(!e.backgroundSet){i(g),o(`image`);return}let t=!0,r=null;return v().then(e=>{if(e){if(!t){URL.revokeObjectURL(e.url);return}r=e.url,i(e.url),o(e.kind),n(e.blob.size)}}).catch(()=>{}),()=>{t=!1,r&&URL.revokeObjectURL(r)}},[e.backgroundSet,n]),!r)return(0,A.jsx)(`div`,{className:`flex h-60 items-center justify-center rounded-card border border-dashed border-inner-border bg-surface-2 text-caption text-text-tertiary`,children:`No background yet. The console uses its plain surface.`});let s={objectFit:`cover`,objectPosition:`${50+e.backgroundX/2}% ${50+e.backgroundY/2}%`,transform:`scale(${e.backgroundScale/100})`,opacity:e.backgroundOpacity/100};return(0,A.jsxs)(`div`,{className:`relative h-75 overflow-hidden rounded-card border border-inner-border bg-surface-2`,children:[a===`video`?(0,A.jsx)(`video`,{src:r,muted:!0,playsInline:!0,preload:`metadata`,className:`size-full`,style:s}):(0,A.jsx)(`img`,{src:r,alt:``,className:`size-full`,style:s}),(0,A.jsxs)(`span`,{className:`absolute bottom-4 left-5 rounded-control bg-surface-1 px-4 py-1 text-micro text-text-secondary`,children:[a===`video`?`Video`:`Image`,t===null?``:` · ${M(t)}`,e.backgroundEnabled?``:` · hidden`]})]})}function F({settings:e,setSettings:t}){return(0,A.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,A.jsxs)(`label`,{className:`flex min-h-18 items-center justify-between gap-6 text-body font-semibold text-text-primary`,children:[(0,A.jsx)(`span`,{children:`Show background`}),(0,A.jsx)(C,{checked:e.backgroundEnabled,onChange:e=>t({backgroundEnabled:e}),"aria-label":`Show background`})]}),(0,A.jsxs)(`div`,{className:`grid gap-7 sm:grid-cols-2`,children:[(0,A.jsx)(I,{label:`Visibility`,value:e.backgroundOpacity,defaultValue:y.backgroundOpacity,min:0,max:100,unit:`%`,onChange:e=>t({backgroundOpacity:e})}),(0,A.jsx)(I,{label:`Blur`,value:e.backgroundBlur,defaultValue:y.backgroundBlur,min:0,max:100,unit:`%`,onChange:e=>t({backgroundBlur:e})}),(0,A.jsx)(I,{label:`Zoom`,value:e.backgroundScale,defaultValue:y.backgroundScale,min:100,max:180,unit:`%`,onChange:e=>t({backgroundScale:e})}),(0,A.jsx)(I,{label:`Shift horizontal`,value:e.backgroundX,defaultValue:y.backgroundX,min:-100,max:100,onChange:e=>t({backgroundX:e})}),(0,A.jsx)(I,{label:`Shift vertical`,value:e.backgroundY,defaultValue:y.backgroundY,min:-100,max:100,onChange:e=>t({backgroundY:e})})]})]})}function I({label:e,value:t,defaultValue:n,min:r,max:i,unit:a,onChange:o}){return(0,A.jsxs)(`label`,{className:`flex flex-col gap-2 text-caption text-text-secondary`,children:[(0,A.jsxs)(`span`,{className:`flex items-center justify-between`,children:[e,(0,A.jsxs)(`span`,{className:`flex items-center gap-3`,children:[(0,A.jsxs)(`span`,{className:`font-mono tabular-nums text-badge text-text-tertiary`,children:[t,a??``]}),(0,A.jsx)(`button`,{type:`button`,onClick:()=>o(n),disabled:t===n,"aria-label":`Reset ${e}`,title:`Reset ${e} to ${n}${a??``}`,className:`flex size-9 items-center justify-center rounded-control text-text-tertiary hover:bg-hover hover:text-text-primary disabled:pointer-events-none disabled:opacity-30`,children:(0,A.jsx)(c,{size:11})})]})]}),(0,A.jsx)(`input`,{type:`range`,min:r,max:i,value:t,onChange:e=>o(Number(e.target.value)),"aria-label":e,className:`blur-slider w-full h-11 m-0 border-0 rounded-pill cursor-pointer`,style:{"--fill":`${(t-r)/(i-r)*100}%`}})]})}function L({target:e,enabled:t,onToggle:n,clarity:r,onClarity:i,depth:a,onDepth:o}){let s=j[e]??j.cards;return(0,A.jsxs)(`div`,{className:`flex flex-col gap-8 rounded-card border border-inner-border bg-surface-2 p-8`,children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-5`,children:[(0,A.jsx)(`span`,{className:`flex size-16 shrink-0 items-center justify-center rounded-control bg-surface-1 text-text-secondary`,children:s.icon}),(0,A.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,A.jsx)(`span`,{className:`text-body font-semibold text-text-primary`,children:s.label}),(0,A.jsx)(`span`,{className:`text-micro text-text-tertiary`,children:s.description})]}),(0,A.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":t,"aria-label":`Toggle ${s.label} blur`,onClick:n,className:t?`h-10 w-18 shrink-0 rounded-pill bg-accent p-1`:`h-10 w-18 shrink-0 rounded-pill bg-surface-active p-1`,children:(0,A.jsx)(`span`,{className:t?`block size-8 translate-x-8 rounded-full bg-accent-foreground`:`block size-8 rounded-full bg-text-secondary`})})]}),(0,A.jsxs)(`div`,{className:t?`flex flex-col gap-6`:`flex flex-col gap-6 opacity-40`,children:[(0,A.jsxs)(`label`,{className:`flex flex-col gap-3 text-caption text-text-secondary`,children:[(0,A.jsxs)(`span`,{className:`flex items-center justify-between`,children:[`Clarity`,(0,A.jsxs)(`span`,{className:`font-mono text-badge tabular-nums text-text-tertiary`,children:[r,`%`]})]}),(0,A.jsx)(`input`,{type:`range`,min:0,max:100,value:r,disabled:!t,onChange:e=>i(Number(e.target.value)),"aria-label":`${s.label} clarity. How see-through the surface is.`,className:`blur-slider w-full h-11 m-0 border-0 rounded-pill cursor-pointer`,style:{"--fill":`${r}%`}}),(0,A.jsxs)(`span`,{className:`flex justify-between text-badge text-text-tertiary`,children:[(0,A.jsx)(`span`,{children:`See-through`}),(0,A.jsx)(`span`,{children:`Solid`})]})]}),(0,A.jsxs)(`label`,{className:`flex flex-col gap-3 text-caption text-text-secondary`,children:[(0,A.jsxs)(`span`,{className:`flex items-center justify-between`,children:[`Blur`,(0,A.jsxs)(`span`,{className:`font-mono text-badge tabular-nums text-text-tertiary`,children:[a,`%`]})]}),(0,A.jsx)(`input`,{type:`range`,min:0,max:100,value:a,disabled:!t,onChange:e=>o(Number(e.target.value)),"aria-label":`${s.label} blur. How blurred whatever is behind it looks.`,className:`blur-slider w-full h-11 m-0 border-0 rounded-pill cursor-pointer`,style:{"--fill":`${a}%`}}),(0,A.jsxs)(`span`,{className:`flex justify-between text-badge text-text-tertiary`,children:[(0,A.jsx)(`span`,{children:`Sharp`}),(0,A.jsx)(`span`,{children:`Blurred`})]})]})]})]})}export{N as default};
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e,r as t,t as n}from"./jsx-runtime-CXUMngI_.js";import{r}from"./terminal-Bd4ee8TA.js";import{r as i,t as a}from"./toast-CNt_jzO4.js";import{n as o,r as s,t as c}from"./state-DA0B95UQ.js";import{t as l}from"./dialog-BvQeBMfP.js";import{t as u}from"./rotate-ccw-CufcqITi.js";import{C as d,T as f,v as p}from"./assert-BHfaei-X.js";import{o as m,t as h}from"./query-keys-D7wX2vM5.js";import{t as g}from"./useMutation-BQKMcJ1H.js";import{L as _,O as v,n as y,v as b}from"./entry--yj84zk3.js";import{t as x}from"./badge-DpXT4Ixt.js";import{n as S}from"./inline-D1IlZZ8H.js";import{t as C}from"./layout-BioLW7gN.js";async function w(e){return m(`/quota/overview`,e?{signal:e}:void 0)}function T(){return d({queryKey:h.quota.all,queryFn:e=>w(p(e)),staleTime:1/0,refetchInterval:!1,refetchIntervalInBackground:!1,refetchOnMount:!1,refetchOnWindowFocus:!1,placeholderData:e=>e})}function E(e){let t=f(),n=h.quota.account(e);return g({mutationFn:async()=>m(`/accounts/${encodeURIComponent(e)}/quota/refresh`,{method:`POST`}),onSuccess:async()=>{await Promise.all([t.invalidateQueries({queryKey:n,exact:!0}),t.invalidateQueries({queryKey:h.quota.all}),t.invalidateQueries({queryKey:h.providers.all})])}})}var D=100;function O(){let e=f();return g({mutationFn:async e=>{let t=[];for(let n=0;n<e.length;n+=D)t.push(e.slice(n,n+D));let n=await Promise.all(t.map(e=>m(`/quota/refresh`,{method:`POST`,body:JSON.stringify({accountIds:e})}))),r=n.flatMap(e=>e.failures);return{ok:r.length===0,queued:n.reduce((e,t)=>e+t.queued,0),succeeded:n.reduce((e,t)=>e+t.succeeded,0),failed:n.reduce((e,t)=>e+t.failed,0),failures:r}},onSuccess:async(t,n)=>{let r=new Set(t.failures.map(e=>e.accountId)),i=n.filter(e=>!r.has(e));await Promise.all([...i.map(t=>e.invalidateQueries({queryKey:h.quota.account(t),exact:!0})),e.invalidateQueries({queryKey:h.quota.all})])}})}function k(){let e=f();return g({mutationFn:({id:e,active:t})=>m(`/accounts/${encodeURIComponent(e)}`,{method:`PATCH`,body:JSON.stringify({active:t})}),onSuccess:async()=>{await Promise.all([e.invalidateQueries({queryKey:h.quota.all}),e.invalidateQueries({queryKey:h.providers.all})])}})}function A(){let e=f();return g({mutationFn:async({ids:e,active:t})=>{e.length!==0&&await m(`/accounts/batch`,{method:`PATCH`,body:JSON.stringify({ids:e,active:t})})},onSuccess:async()=>{await Promise.all([e.invalidateQueries({queryKey:h.quota.all}),e.invalidateQueries({queryKey:h.providers.all})])}})}function j(){let e=f();return g({mutationFn:async e=>{await m(`/accounts/${encodeURIComponent(e)}`,{method:`DELETE`})},onSuccess:async(t,n)=>{e.removeQueries({queryKey:h.quota.account(n),exact:!0}),await Promise.all([e.invalidateQueries({queryKey:h.quota.all}),e.invalidateQueries({queryKey:h.providers.all})])}})}var M=new Set([`workbuddy`,`workbuddycn`,`cb`,`cbcn`]);function N(e){return M.has(e.trim().toLowerCase())}function P(e){let t=f();return g({mutationFn:async()=>{if(e.length===0)throw Error(`Select a provider first`);return m(`/quota/daily-growth`,{method:`POST`,body:JSON.stringify({providerId:e})})},onSuccess:async()=>{await Promise.all([t.invalidateQueries({queryKey:h.quota.all}),t.invalidateQueries({queryKey:h.providers.all})])}})}function F(e){let t=f();return g({mutationFn:async()=>{let t=await m(`/accounts/${encodeURIComponent(e)}/activity-report`,{method:`POST`}),n=t.message??`Activity reported`,r=await m(`/accounts/${encodeURIComponent(e)}/checkin`,{method:`POST`}),i=r.message??`Daily check-in done`;return{ok:t.ok,message:t.ok?`Report success · Check-in ${i}`:`Report failed: ${n} · Check-in ${i}`,checkin:r,report:t}},onSuccess:async()=>{await Promise.all([t.invalidateQueries({queryKey:h.quota.all}),t.invalidateQueries({queryKey:h.providers.all})])}})}var I=new Set([`codex`,`claude`,`anthropic`]);function L(e){return I.has(e.trim().toLowerCase())}function R(e,t){return d({queryKey:h.quota.resets(e),queryFn:({signal:t})=>m(`/accounts/${encodeURIComponent(e)}/resets`,t?{signal:t}:void 0),enabled:t,staleTime:3e4})}function z(e){let t=f();return g({mutationFn:async t=>m(`/accounts/${encodeURIComponent(e)}/reset`,{method:`POST`,body:JSON.stringify(t??{})}),onSettled:async()=>{await Promise.all([t.invalidateQueries({queryKey:h.quota.all}),t.invalidateQueries({queryKey:h.providers.all})])}})}var B=e(t(),1),V=n();function H(e){return e===`cooldown`}function U(e){return e===`active`?`ok`:e===`disabled`?`disabled`:`warn`}function W(e,t){return e?{title:`Enable static-token mode?`,message:`${t} will be used exactly as issued and will not be refreshed. Re-enable refresh before this token expires.`,confirmLabel:`Enable static mode`}:{title:`Re-enable credential refresh?`,message:`${t} will return to the OAuth refresh sweep. Use this only when a refresh token is available.`,confirmLabel:`Re-enable refresh`}}function G({summary:e,onClose:t}){let{providerId:n,accountId:d,title:f,status:p,errorCategory:m,errorMessage:h}=e,g=y(n,d),w=b(),T=g.data??[],E=v(),D=e.credentialKind===`oauth`||e.credentialMode===`jwt`||e.staticToken===!0,[O,k]=(0,B.useState)(e.staticToken===!0),[A,j]=(0,B.useState)(null);return(0,B.useEffect)(()=>k(e.staticToken===!0),[e.staticToken]),(0,V.jsx)(l,{open:!0,onClose:t,title:`Health & Error Log — ${f}`,size:`lg`,children:(0,V.jsxs)(`div`,{className:`flex flex-col gap-7 min-w-0`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-5 rounded-control border border-inner-border bg-surface-2 py-5 px-7`,children:[(0,V.jsxs)(`div`,{className:`min-w-0`,children:[(0,V.jsxs)(S,{gap:`8px`,className:`flex-wrap`,children:[(0,V.jsx)(`span`,{className:`text-body font-semibold`,children:`Account status:`}),(0,V.jsx)(x,{tone:U(p),dot:!0,children:p.toUpperCase()}),m?(0,V.jsx)(x,{tone:`warn`,title:h??void 0,children:m}):null]}),h?(0,V.jsx)(`p`,{className:`text-badge text-red mt-2 wrap-anywhere`,children:h}):null]}),H(p)?(0,V.jsx)(i,{size:`sm`,variant:`secondary`,icon:(0,V.jsx)(u,{size:12,className:w.isPending?`animate-spin`:``}),disabled:w.isPending,onClick:()=>w.mutate({providerId:n,accountId:d},{onSuccess:()=>void g.refetch()}),children:w.isPending?`Recovering...`:`Recover Now`}):null]}),D?(0,V.jsxs)(`div`,{className:`flex items-center justify-between gap-6 rounded-control border border-inner-border bg-surface-2 py-5 px-7`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:`text-caption font-semibold`,children:`Credential management`}),(0,V.jsx)(`div`,{className:`text-badge text-text-tertiary`,children:O?`Static mode: no refresh request will be sent.`:`OAuth refresh is enabled for this account.`})]}),(0,V.jsx)(i,{size:`sm`,variant:O?`primary`:`secondary`,disabled:E.isPending,onClick:()=>j(!O),children:O?`Static · no refresh`:`Enable static mode`})]}):null,(0,V.jsxs)(`div`,{className:`min-w-0`,children:[(0,V.jsxs)(`h4`,{className:`text-caption font-semibold text-text-secondary mb-4`,children:[`Transition Events & Audit (`,T.length,`)`]}),g.isPending?(0,V.jsx)(s,{label:`Loading health events...`}):g.isError?(0,V.jsx)(o,{message:`Failed to load health events`,onRetry:()=>void g.refetch()}):T.length===0?(0,V.jsx)(c,{title:`No health events recorded`,message:e.emptyMessage,icon:(0,V.jsx)(r,{size:20})}):(0,V.jsx)(`div`,{className:`rounded-inset border border-inner-border`,children:(0,V.jsx)(C,{maxHeight:480,scrollRegion:!0,headers:[`Timestamp`,`From → To`,`Model`,`Category`,`Reason / Details`],children:T.map(e=>(0,V.jsxs)(`tr`,{children:[(0,V.jsx)(`td`,{className:`text-badge text-text-tertiary whitespace-nowrap`,children:new Date(e.createdAt).toLocaleString()}),(0,V.jsxs)(`td`,{className:`whitespace-nowrap`,children:[(0,V.jsxs)(`span`,{className:`text-badge text-text-secondary`,children:[e.fromStatus??`new`,` →`,` `]}),(0,V.jsx)(x,{tone:U(e.toStatus),children:e.toStatus})]}),(0,V.jsx)(`td`,{className:`font-mono tabular-nums text-badge text-text-secondary wrap-anywhere`,children:e.modelId??`—`}),(0,V.jsx)(`td`,{className:`font-mono tabular-nums text-badge text-text-secondary`,children:e.errorCategory??`—`}),(0,V.jsx)(`td`,{className:`text-badge text-text-primary min-w-110 max-w-260 wrap-anywhere`,children:e.reason??`—`})]},e.id))})})]}),(0,V.jsx)(_,{open:A!==null,onClose:()=>j(null),onConfirm:()=>{let e=A===!0;E.mutate({providerId:n,accountId:d,request:{staticToken:e}},{onSuccess:()=>{k(e),j(null),a.success(e?`Static mode enabled`:`Credential refresh re-enabled`,f),g.refetch()},onError:e=>a.error(`Credential update failed`,e instanceof Error?e.message:`Unable to update credential mode`)})},title:W(A===!0,f).title,message:W(A===!0,f).message,confirmLabel:W(A===!0,f).confirmLabel,cancelLabel:`Cancel`}),(0,V.jsx)(S,{justify:`flex-end`,gap:`0px`,children:(0,V.jsx)(i,{variant:`secondary`,size:`sm`,onClick:t,children:`Close`})})]})})}export{j as a,O as c,F as d,P as f,R as i,A as l,N as n,T as o,k as p,L as r,E as s,G as t,z as u};
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e,r as t,t as n}from"./jsx-runtime-CXUMngI_.js";import{r}from"./toast-CNt_jzO4.js";import{t as i}from"./log-in-BmRjy60c.js";import{o as a,t as o}from"./query-keys-D7wX2vM5.js";import{$ as s,I as c,Z as l}from"./entry--yj84zk3.js";import{n as u}from"./input-BpVZdrbc.js";var d=e(t(),1),f=n();function p(e){return e?.startsWith(`/`)&&!e.startsWith(`//`)?e:`/`}function m(){let e=l(),[t]=s(),[n,m]=(0,d.useState)(``),[h,g]=(0,d.useState)(``),[_,v]=(0,d.useState)(null),[y,b]=(0,d.useState)(!1),[x,S]=(0,d.useState)(!0);return(0,d.useEffect)(()=>{let t=!0;return a(`/auth/first-boot`).then(n=>{if(t){if(n.requires_setup){e(`/setup`,{replace:!0});return}S(!1)}}).catch(()=>{t&&S(!1)}),()=>{t=!1}},[e]),x?(0,f.jsx)(`main`,{className:`auth-viewport`,children:(0,f.jsx)(`div`,{className:`card-solid auth-window`,children:(0,f.jsxs)(`div`,{className:`auth-header`,children:[(0,f.jsx)(`div`,{className:`auth-logo`,"aria-hidden":`true`}),(0,f.jsx)(`h1`,{className:`auth-title`,children:`Cartethyia Console`}),(0,f.jsx)(`p`,{className:`auth-desc`,children:`Checking console setup...`})]})})}):(0,f.jsx)(`main`,{className:`auth-viewport`,children:(0,f.jsxs)(`div`,{className:`card-solid auth-window`,children:[(0,f.jsxs)(`div`,{className:`auth-header`,children:[(0,f.jsx)(`div`,{className:`auth-logo`,"aria-hidden":`true`}),(0,f.jsx)(`h1`,{className:`auth-title`,children:`Cartethyia Console`}),(0,f.jsx)(`p`,{className:`auth-desc`,children:`Sign in to manage AI Gateway routing and providers`})]}),(0,f.jsxs)(`form`,{onSubmit:async r=>{r.preventDefault(),b(!0),v(null);try{let r=await a(`/auth/login`,{method:`POST`,body:JSON.stringify({username:n.trim(),password:h})});if(r.status!==`success`){if(r.requires_setup){e(`/setup`,{replace:!0});return}g(``),v(r.message??`Authentication failed. Please check your credentials.`);return}c.removeQueries({queryKey:o.session.current}),e(r.requires_setup?`/setup`:p(t.get(`returnTo`)),{replace:!0})}catch(e){if(e&&typeof e==`object`&&`message`in e){let t=e.message;if(typeof t==`string`){g(``),v(t);return}}v(`An unexpected network error occurred.`)}finally{b(!1)}},className:`flex flex-col gap-7`,children:[(0,f.jsx)(u,{label:`Username`,id:`login-username`,value:n,onChange:e=>m(e.target.value),required:!0,autoComplete:`username`,placeholder:`admin`}),(0,f.jsx)(u,{label:`Password`,id:`login-password`,type:`password`,value:h,onChange:e=>g(e.target.value),required:!0,autoComplete:`current-password`}),_?(0,f.jsx)(`div`,{className:`py-5 px-7 rounded-control bg-red-soft text-red text-caption font-medium`,role:`alert`,children:_}):null,(0,f.jsx)(r,{variant:`primary`,type:`submit`,disabled:y,className:`w-full mt-3 h-20`,icon:(0,f.jsx)(i,{size:15}),children:y?`Authenticating…`:`Sign In`})]})]})})}export{m as default};
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e,r as t,t as n}from"./jsx-runtime-CXUMngI_.js";import{t as r}from"./check-D69FzdvC.js";import{p as i,r as a}from"./toast-CNt_jzO4.js";import{t as o}from"./dialog-BvQeBMfP.js";import{t as s}from"./route-CNSNj9Zm.js";import{t as c}from"./search-JOKus9rb.js";import{C as l,v as u}from"./assert-BHfaei-X.js";import{o as d,t as f}from"./query-keys-D7wX2vM5.js";import{s as p}from"./tokens-DDxMbSRL.js";import{t as m}from"./badge-DpXT4Ixt.js";import{t as h}from"./ProviderIcon-CmfzxpVM.js";var g=e(t(),1),_=n();function v(e){let t=l({queryKey:f.providers.flatAll,queryFn:e=>d(`/providers/models/flat`,{signal:u(e)}),enabled:e,staleTime:0});return{items:t.data??[],isLoading:t.isPending,isError:t.isError,refetch:()=>void t.refetch()}}function y(e){return e==null?`?`:e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}k`:String(e)}function b(e){let t=e.toLowerCase();return t===`responses`?`Responses`:t===`messages`?`Messages`:`Chat`}function x(e){let t=e.toLowerCase();return t===`responses`?`var(--purple)`:t===`messages`?`var(--orange)`:`var(--teal)`}function S(e){return e===`systemone`?`System One decision model — not a chat model. Call it at POST /v1/systemone with {state, questions}; it answers {answers}. It cannot run in a chat playground.`:e===`websearch`?`Web-search model — not a chat model. Call it at POST /v1/search with {query, max_results}; it answers a normalized list of hits. It cannot run in a chat playground.`:`This model is served by a native '${e}' route, not the chat wire.`}function C({open:e,onClose:t,selected:n,onToggle:l,onSelectOne:u,size:d=`lg`,title:f=`Select model`,multi:C=!0,filter:w}){let[T,E]=(0,g.useState)(``),{items:D,isLoading:O,isError:k,refetch:A}=v(e),j=(0,g.useMemo)(()=>{let e=T.trim().toLowerCase();return D.filter(t=>w&&!w(t)?!1:!e||t.qualified.toLowerCase().includes(e)||t.modelId.toLowerCase().includes(e)||t.providerId.toLowerCase().includes(e))},[D,T,w]),M=(0,g.useMemo)(()=>{let e=new Map;for(let t of j){let n=t.kind===`model`?t.providerId:t.kind===`alias`?`Aliases`:`Combos`,r=e.get(n)??[];r.push(t),e.set(n,r)}let t=(e,t)=>{let n=t[0]?.kind;return n===`alias`?0:n===`combo`?1:2};return Array.from(e.entries()).sort(([e,n],[r,i])=>{let a=t(e,n),o=t(r,i);return a===o?e.localeCompare(r):a-o})},[j]),N=e=>n.includes(e),P=e=>{u&&!C?(u(e),t()):l(e)};return(0,_.jsx)(o,{open:e,onClose:t,title:f,size:d,footer:(0,_.jsx)(a,{variant:`secondary`,onClick:t,children:`Done`}),children:(0,_.jsxs)(`div`,{className:`flex max-w-full flex-col gap-6`,children:[(0,_.jsxs)(`div`,{className:`relative`,children:[(0,_.jsx)(c,{size:14,className:`absolute left-5 top-1/2 -translate-y-1/2 text-text-tertiary`}),(0,_.jsx)(`input`,{value:T,onChange:e=>E(e.target.value),placeholder:`Search models or providers (e.g. gpt-5.4, codex)`,className:`w-full max-w-full rounded-inset border border-inner-border bg-surface-2 py-4 pr-5 pl-16 text-caption text-text-primary`})]}),C&&n.length>0&&(0,_.jsx)(`div`,{className:`flex flex-wrap gap-3 rounded-inset border border-inner-border bg-surface-2 p-4`,children:n.map(e=>(0,_.jsxs)(`span`,{className:`font-mono tabular-nums inline-flex items-center gap-2 text-badge bg-accent-soft text-accent py-1 px-3 rounded-chip border border-accent max-w-full overflow-hidden break-all`,children:[(0,_.jsx)(`span`,{className:`overflow-hidden truncate whitespace-nowrap`,children:e}),(0,_.jsx)(`button`,{type:`button`,onClick:()=>l(e),className:`bg-transparent border-none cursor-pointer p-0 flex shrink-0`,children:(0,_.jsx)(i,{size:12})})]},e))}),(0,_.jsx)(`div`,{className:`flex min-h-160 max-h-210 flex-1 flex-col gap-8 overflow-x-hidden overflow-y-auto rounded-control border border-inner-border bg-surface-1 p-6`,children:O?(0,_.jsx)(`div`,{className:`p-16 text-center text-caption text-text-tertiary`,children:`Loading catalog…`}):k?(0,_.jsxs)(`div`,{className:`p-16 text-center text-caption`,children:[(0,_.jsx)(`p`,{className:`text-text-tertiary`,children:`Failed to load catalog.`}),(0,_.jsx)(`button`,{type:`button`,onClick:A,className:`mt-4`,children:`Retry`})]}):M.length===0?(0,_.jsx)(`div`,{className:`p-16 text-center text-caption text-text-tertiary`,children:`No models found.`}):M.map(([e,t])=>{let n=t[0]?.kind===`model`;return(0,_.jsxs)(`div`,{className:`flex flex-col gap-4 min-w-0`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-3 text-badge font-bold tracking-[0.05em] text-text-secondary uppercase`,children:[n?(0,_.jsx)(h,{name:e,icon:e,size:16}):(0,_.jsx)(s,{size:14}),e,(0,_.jsx)(m,{tone:`default`,children:t.length})]}),(0,_.jsx)(`div`,{className:`grid min-w-0 grid-cols-2 gap-4 max-small:gap-2`,children:t.map(e=>{let t=N(e.qualified);return(0,_.jsxs)(`button`,{type:`button`,onClick:()=>P(e.qualified),className:`relative flex w-full min-w-0 cursor-pointer flex-col gap-2 overflow-hidden rounded-control px-6 py-5 text-left max-small:px-3 max-small:py-4 ${t?`border border-accent bg-accent-soft`:`border border-inner-border bg-surface-2`}`,children:[t&&(0,_.jsx)(r,{size:12,className:`absolute top-4 right-4 text-accent`}),(0,_.jsxs)(`span`,{title:e.qualified,className:`font-mono tabular-nums w-full whitespace-normal break-all text-badge font-semibold ${t?`pr-8 text-accent`:`text-text-primary`}`,children:[e.modelId,e.kind===`model`&&e.entry.serviceKind!==`llm`&&(0,_.jsx)(`span`,{title:S(e.entry.serviceKind),className:`ml-3 inline-block cursor-help rounded-tiny border border-orange px-2.5 align-middle font-bold tracking-[0.04em] text-micro text-orange uppercase`,children:e.entry.serviceKind})]}),(0,_.jsx)(`span`,{title:e.qualified,className:`font-mono tabular-nums w-full truncate text-micro text-text-tertiary`,children:e.kind===`alias`||e.kind===`combo`?(0,_.jsx)(`span`,{title:e.providerLabel,children:e.providerLabel}):(0,_.jsxs)(_.Fragment,{children:[e.entry.contextLimit?`${y(e.entry.contextLimit)} ctx`:(0,_.jsx)(`span`,{title:p,className:`cursor-help`,children:`n/a ctx`}),` · `,e.entry.outputLimit?`${y(e.entry.outputLimit)} out`:(0,_.jsx)(`span`,{title:p,className:`cursor-help`,children:`n/a out`}),` · `,(0,_.jsx)(`span`,{style:{color:x(e.entry.wireFamily),fontWeight:700},children:b(e.entry.wireFamily)})]})})]},e.qualified)})})]},e)})})]})})}export{v as n,C as t};
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{a as i,i as a,n as o,o as s,r as c}from"./model-bans-CT-TxSNX.js";import{n as l,t as u}from"./fingerprint-pattern-BWuHtbW4.js";import{t as d}from"./check-D69FzdvC.js";import{t as f}from"./chevron-right-BXIy5l3h.js";import{t as p}from"./SortableList-DCY0TPTZ.js";import{_ as m,r as h,t as g}from"./toast-CNt_jzO4.js";import{t as _}from"./copy-ngmQ9zcZ.js";import{t as v}from"./download-A0SW9OCW.js";import{t as y}from"./eye-off-Bk5g2luF.js";import{t as b}from"./eye-C_hawfH4.js";import{t as x}from"./gauge-BbIMy7MB.js";import{a as S,n as C,r as w,t as T}from"./state-DA0B95UQ.js";import{t as ee}from"./key-round-UkavsGxp.js";import{n as E,r as D,t as O}from"./clipboard-button-DOo6EU8O.js";import{t as k}from"./dialog-BvQeBMfP.js";import{t as te}from"./pencil-768ysRAr.js";import{t as A}from"./plus-DIdX_g-x.js";import{t as j}from"./refresh-cw-BqJFk4sU.js";import{t as M}from"./route-CNSNj9Zm.js";import{t as N}from"./search-JOKus9rb.js";import{t as ne}from"./shield-check-DVS0Foqh.js";import{n as re,r as ie,t as P}from"./settings-CfcTcOyU.js";import{t as ae}from"./sparkles-BRaRUxAU.js";import{t as oe}from"./trash-Cppn5c3R.js";import{b as se,x as ce}from"./assert-BHfaei-X.js";import{l as F}from"./query-keys-D7wX2vM5.js";import{A as le,L as I,at as ue,it as de,nt as fe}from"./entry--yj84zk3.js";import{n as L,r as R,t as z}from"./card-DEhRXXw4.js";import{t as pe}from"./use-clipboard-B0Sy03fE.js";import{n as me}from"./download-dRFo5_Wu.js";import{c as B,d as V}from"./tokens-DDxMbSRL.js";import{t as H}from"./badge-DpXT4Ixt.js";import{n as U,t as he}from"./input-BpVZdrbc.js";import{t as W}from"./select-XPJ-dIw3.js";import{t as ge}from"./ModelPicker-oQ-SDXp8.js";import{t as G}from"./switch-Cittxy-x.js";import{t as K}from"./stack-C9_uUjaA.js";import{n as q}from"./inline-D1IlZZ8H.js";import{a as _e,c as ve,d as J,f as ye,i as be,l as xe,n as Se,o as Ce,r as we,s as Te,t as Y,u as Ee}from"./api-keys-BmDbsior.js";import{a as X,i as Z,n as De,r as Oe}from"./cli-tools-B0wBq-RL.js";import{t as ke}from"./layout-BioLW7gN.js";import{s as Ae}from"./quota-DZGyp0N5.js";var je=e(`lock-keyhole`,[[`circle`,{cx:`12`,cy:`16`,r:`1`,key:`1au0dj`}],[`rect`,{x:`3`,y:`10`,width:`18`,height:`12`,rx:`2`,key:`6s8ecr`}],[`path`,{d:`M7 10V7a5 5 0 0 1 10 0v3`,key:`1pqi11`}]]),Me=e(`repeat-2`,[[`path`,{d:`m2 9 3-3 3 3`,key:`1ltn5i`}],[`path`,{d:`M13 18H7a2 2 0 0 1-2-2V6`,key:`1r6tfw`}],[`path`,{d:`m22 15-3 3-3-3`,key:`4rnwn2`}],[`path`,{d:`M11 6h6a2 2 0 0 1 2 2v10`,key:`2f72bc`}]]),Ne=e(`rotate-cw`,[[`path`,{d:`M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8`,key:`1p45f6`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}]]),Pe=e(`scissors`,[[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M8.12 8.12 12 12`,key:`1alkpv`}],[`path`,{d:`M20 4 8.12 15.88`,key:`xgtan2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M14.8 14.8 20 20`,key:`ptml3r`}]]),Fe=e(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]),Ie=e(`shield-off`,[[`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`}]]),Le=e(`shield-x`,[[`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:`m14.5 9.5-5 5`,key:`17q4r4`}],[`path`,{d:`m9.5 9.5 5 5`,key:`18nt4w`}]]),Re=e(`undo-2`,[[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`,key:`f3b9sd`}]]),ze=e(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]),Be=e(`users-round`,[[`path`,{d:`M18 21a8 8 0 0 0-16 0`,key:`3ypg7q`}],[`circle`,{cx:`10`,cy:`8`,r:`5`,key:`o932ke`}],[`path`,{d:`M22 20c0-3.37-2-6.5-4-8a5 5 0 0 0-.45-8.3`,key:`10s06x`}]]),Ve=[`routing:invoke`,`routing:cli_mapping`,`search:invoke`,`dashboard:read`,`dashboard:write`,`providers:read`,`providers:write`,`models:read`,`models:write`],He=[`image/png`,`image/jpeg`,`image/webp`,`image/gif`],Q=t(n(),1),$=r(),Ue={"routing:invoke":`Call /v1/* gateway routes within this tenant.`,"routing:cli_mapping":`Resolve persisted CLI source→target model mappings.`,"search:invoke":`Call POST /v1/search with exa.`,"dashboard:read":`Read this tenant's configuration and usage.`,"dashboard:write":`Modify this tenant's configuration.`,"providers:read":`Read provider rows, including accounts.`,"providers:write":`Add, modify, or delete provider rows and their credentials.`,"models:read":`Read catalog model rows.`,"models:write":`Add, modify, or delete catalog model rows.`},We={"routing:invoke":M,"routing:cli_mapping":M,"search:invoke":N,"dashboard:read":b,"dashboard:write":te,"providers:read":fe,"providers:write":je,"models:read":l,"models:write":i},Ge={k:1e3,m:1e6,b:1e9,t:0xe8d4a51000},Ke=[{label:`1M`,amount:1e6,description:`1 million`},{label:`100M`,amount:1e8,description:`100 million`},{label:`1B`,amount:1e9,description:`1 billion`},{label:`1T`,amount:0xe8d4a51000,description:`1 trillion`}];function qe(e){let t=e.trim().toLowerCase();if(!t)return;let n=t.match(/^([\d.]+)\s*([kmbt])?$/);if(!n)return;let r=Number(n[1]);if(!Number.isFinite(r)||r<=0)return;let i=n[2]?Ge[n[2]]??1:1;return Math.round(r*i)}function Je(e){if(e==null)return``;let t=Ke.find(t=>t.amount===e);return t?t.label:e>=1e9?`${(e/1e9).toFixed(1).replace(/\.0$/,``)}B`:e>=1e6?`${(e/1e6).toFixed(1).replace(/\.0$/,``)}M`:e>=1e3?`${(e/1e3).toFixed(1).replace(/\.0$/,``)}K`:String(e)}function Ye(e){let t=Number(e.trim());return Number.isFinite(t)&&t>0?Math.round(t):void 0}function Xe(e){let t=Ye(e);return e.trim()===``?null:t}function Ze({label:e,value:t,onChange:n,disabled:r}){let i=qe(t),a=Ke.find(e=>e.amount===i)?.label;return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(U,{label:e,value:t,onChange:e=>n(e.target.value),placeholder:`e.g. 1M, 500K`,disabled:r}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-3 mt-3`,role:`group`,"aria-label":`${e} presets`,children:Ke.map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":a===e.label,"aria-label":`${e.label}, ${e.description} tokens`,onClick:()=>n(e.label),disabled:r,className:`py-1 px-4 rounded-chip text-micro font-semibold`,style:{cursor:r?`not-allowed`:`pointer`,border:`1px solid ${a===e.label?`var(--accent)`:`var(--inner-border)`}`,background:a===e.label?`var(--accent-soft)`:`transparent`,color:a===e.label?`var(--accent)`:`var(--text-tertiary)`},children:e.label},e.label))})]})}function Qe({tool:e,keyId:t,busy:n,scopeGranted:r,onScopeChange:i}){let a=Z(e.id,t),o=Oe(),s=De(),c=a.data?.enabled??!1,l=r&&c,u=a.data?.mappings.length??0,d=o.isPending||s.isPending;return(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-6 py-2 px-5 rounded-inset`,style:{minHeight:`44px`,border:`1px solid var(--inner-border)`,background:l?`var(--accent-soft)`:`var(--surface-1)`},children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,$.jsx)(M,{size:16,className:`mt-1 shrink-0 text-accent`,"aria-hidden":`true`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-caption font-semibold text-text-primary`,children:e.name}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:l?`Remote routing on — ${u} route${u===1?``:`s`} active, routing:cli_mapping granted.`:`Remote routing off — this key's requests go straight to the provider.`})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,$.jsx)(G,{checked:l,disabled:n||d||a.isLoading,"aria-label":`Enable remote routing for ${e.name}`,onChange:n=>{n!==r&&i(n),o.mutate({toolId:e.id,keyId:t,input:{enabled:n,mappings:a.data?.mappings??[]}},{onSuccess:()=>g.success(`Saved remote routing for ${e.name}.`),onError:e=>g.error(F(e,`Could not save remote routing.`))})}}),(0,$.jsx)(h,{variant:`secondary`,size:`sm`,disabled:n||d||!c&&u===0,onClick:()=>s.mutate({toolId:e.id,keyId:t},{onSuccess:()=>g.success(`Cleared remote routes for ${e.name}.`),onError:e=>g.error(F(e,`Could not reset remote routes.`))}),children:s.isPending?`Resetting…`:`Reset`})]})]})}function $e({keyId:e,busy:t,scopeGranted:n,onScopeChange:r,persistScope:i}){let a=(X().data??[]).filter(e=>e.mappingSupported);return e.length===0||a.length===0?null:(0,$.jsxs)(`section`,{"aria-labelledby":`remote-routing-heading`,className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h4`,{id:`remote-routing-heading`,className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(M,{size:15,className:`text-accent`,"aria-hidden":`true`}),`Remote routing`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Route this key's CLI model calls through persisted mappings and grant routing:cli_mapping. Applies immediately — no save needed.`})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:a.map(a=>(0,$.jsx)(Qe,{tool:a,keyId:e,busy:t,scopeGranted:n,onScopeChange:e=>{r(e),i(e)}},a.id))})]})}function et(e,t,n){let r=e===`personal`?t.trim():``;return{keyMode:e,keyPrefix:n.trim()||void 0,...r?{key:r}:{}}}function tt(e,t){return e===`personal`?t??null:null}function nt(e){if(e?.isDefault)return[...Ve];let t=e?.scopes;return t&&t.length>0?[...t]:[`routing:invoke`,`search:invoke`]}function rt({mode:e,record:t,busy:n,onDone:r,onClose:i,actionsRef:a}){let[o,c]=(0,Q.useState)(t?.label??``),[d,f]=(0,Q.useState)(t?.keyPrefix??``),[p,m]=(0,Q.useState)(``),[_,v]=(0,Q.useState)(t?.requestsPerMinute?.toString()??``),[y,b]=(0,Q.useState)(Je(t?.dailyTokenLimit??null)),[S,C]=(0,Q.useState)(Je(t?.monthlyTokenLimit??null)),[w,T]=(0,Q.useState)(Je(t?.lifetimeTokenBudget??null)),[D,O]=(0,Q.useState)(t?.lifetimeTokenBudget==null?`recurring`:`one-time`),[k,te]=(0,Q.useState)(t?.maxConcurrentRequests?.toString()??``),[A,j]=(0,Q.useState)(()=>nt(t)),[N,re]=(0,Q.useState)(t?.modelAccessMode??`whitelist`),[P,ae]=(0,Q.useState)(()=>{let e=t?.modelList;return e?[...e]:[]}),[oe,le]=(0,Q.useState)(!1),[I,fe]=(0,Q.useState)(()=>{let e=t?.clientRouterDenylist;return e?[...new Set(e.map(ce).filter(e=>e!==void 0))]:[]}),[L,R]=(0,Q.useState)(()=>t?.notesTitle??``),[z,pe]=(0,Q.useState)(()=>t?.notesSubtitle??``),[me,B]=(0,Q.useState)(()=>t?.notesBody??``),[V,H]=(0,Q.useState)(t?.sharePopupEnabled??!1),[W,K]=(0,Q.useState)(null),[q,_e]=(0,Q.useState)(!1),[ve,J]=(0,Q.useState)(null),be=t?.sharePopupImageMime!==void 0,xe=W??(be&&!q&&t!==null?`/console/api/api-keys/${t.id}/share-popup-image`:null),[Se,Ce]=(0,Q.useState)(t?.sharePopupTitle??``),[we,Te]=(0,Q.useState)(t?.sharePopupBody??``),[Y,Ee]=(0,Q.useState)(t?.keyMode??`personal`),X=D===`one-time`,Z=e===`edit`,De=ye(),Oe=e=>j(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),ke=()=>{r({label:o.trim(),...et(Y,p,d),scopes:A,modelAccessMode:N,modelList:P,clientRouterDenylist:I,requestsPerMinute:Xe(_),maxConcurrentRequests:Xe(k),dailyTokenLimit:X?null:qe(y)??null,monthlyTokenLimit:X?null:qe(S)??null,lifetimeTokenBudget:X?qe(w)??null:null,notesTitle:L.trim(),notesSubtitle:z.trim(),notesBody:me.trim(),sharePopupEnabled:V,...W===null?q?{sharePopupImage:null}:{}:{sharePopupImage:W},sharePopupTitle:Se.trim(),sharePopupBody:we.trim()})};return(0,Q.useEffect)(()=>{a?.((0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(h,{variant:`secondary`,size:`sm`,onClick:i,disabled:n,children:`Cancel`}),(0,$.jsx)(h,{variant:`primary`,size:`sm`,disabled:n||e===`create`&&!o.trim(),onClick:ke,children:n?`Saving…`:e===`create`?`Create API key`:`Save changes`})]}))}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-6 min-w-0 pb-2`,children:[(0,$.jsxs)(`section`,{className:`flex flex-col gap-4 min-w-0 p-6 border border-inner-border rounded-card bg-surface-2 col-span-full`,children:[(0,$.jsxs)(`h3`,{className:`inline-flex items-center gap-2 text-body font-bold text-text-primary`,children:[(0,$.jsx)(ee,{size:16,className:`text-accent`,"aria-hidden":`true`}),`Credential mode`]}),(0,$.jsx)(`div`,{role:`group`,"aria-label":`Credential mode`,className:`flex gap-4`,children:[`personal`,`share`].map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":Y===e,disabled:n||Z,onClick:()=>Ee(e),title:Z?`Credential mode cannot change after creation`:void 0,className:`rounded-inset py-2 px-6`,style:{border:`1px solid var(--inner-border)`,color:Y===e?`var(--accent)`:`var(--text-secondary)`,background:Y===e?`var(--accent-soft)`:`var(--surface-2)`,cursor:Z?`not-allowed`:`pointer`,opacity:Z&&Y!==e?.5:1},children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[e===`personal`?(0,$.jsx)(ze,{size:14,"aria-hidden":`true`}):(0,$.jsx)(Be,{size:14,"aria-hidden":`true`}),e===`personal`?`Personal`:`Share template`]})},e))}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:Y===`share`?`A share template does not authenticate requests. Recipients generate their own child key from its public enrollment page.`:`A personal key authenticates requests directly; its secret is shown once when created or rotated.`})]}),(0,$.jsxs)(`div`,{className:`columns-2 gap-6 min-w-0 max-medium:columns-1`,children:[e===`create`&&(0,$.jsxs)(`section`,{className:`flex flex-col gap-4 min-w-0 p-6 border border-inner-border rounded-card bg-surface-2 break-inside-avoid mb-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`inline-flex items-center gap-2 text-body font-bold text-text-primary`,children:[(0,$.jsx)(u,{size:16,className:`text-accent`,"aria-hidden":`true`}),`Identity`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Give this credential a recognizable name.`})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 items-start min-w-0 max-medium:grid-cols-1`,children:[(0,$.jsx)(U,{label:`Name`,value:o,onChange:e=>c(e.target.value),placeholder:`ci-key…`,disabled:n,autoFocus:!0}),(0,$.jsx)(U,{label:`Key prefix`,value:d,onChange:e=>f(e.target.value),placeholder:`pn-carte- (default)…`,disabled:n||p.trim().length>0})]}),Y===`personal`&&(0,$.jsx)(U,{label:`Custom API key value (optional)`,value:p,onChange:e=>m(e.target.value),placeholder:`Leave blank to generate…`,disabled:n})]}),e===`edit`&&(0,$.jsxs)(`section`,{className:`flex flex-col gap-4 min-w-0 p-6 border border-inner-border rounded-card bg-surface-2 break-inside-avoid mb-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`text-body font-bold text-text-primary`,children:[(0,$.jsx)(u,{size:16,className:`mr-2 inline text-accent`,"aria-hidden":`true`}),`Identity`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:t?.isDefault?`The default key's name is fixed. Limits, access, and everything else can still change.`:`Update the label for this credential.`})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-2 gap-4 items-start min-w-0 max-medium:grid-cols-1`,children:(0,$.jsx)(U,{label:`Name`,value:o,onChange:e=>c(e.target.value),placeholder:`ci-key…`,disabled:n||t?.isDefault===!0,title:t?.isDefault?`The default gateway key keeps its name`:void 0,autoFocus:!0})})]}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-4 min-w-0 p-6 border border-inner-border rounded-card bg-surface-2 break-inside-avoid mb-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`text-body font-bold text-text-primary`,children:[(0,$.jsx)(E,{size:16,className:`mr-2 inline text-accent`,"aria-hidden":`true`}),`Share notes`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Optional copy shown on the public share page.`})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 items-start min-w-0 max-medium:grid-cols-1`,children:[(0,$.jsx)(U,{label:`Title`,value:L,onChange:e=>R(e.target.value),placeholder:`e.g. Bansos Token`,disabled:n}),(0,$.jsx)(U,{label:`Subtitle`,value:z,onChange:e=>pe(e.target.value),placeholder:`e.g. Come and save your tokens`,disabled:n}),(0,$.jsx)(U,{label:`Body`,value:me,onChange:e=>B(e.target.value),placeholder:`Free-form notes for the recipient`,disabled:n})]})]}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-4 min-w-0 p-6 border border-inner-border rounded-card bg-surface-2 break-inside-avoid mb-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`text-body font-bold text-text-primary`,children:[(0,$.jsx)(x,{size:16,className:`mr-2 inline text-accent`,"aria-hidden":`true`}),`Limits`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Keep this credential predictable under load.`})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 items-start min-w-0 max-medium:grid-cols-1`,children:[(0,$.jsx)(U,{label:`Requests per minute`,type:`number`,min:`0`,value:_,onChange:e=>v(e.target.value),placeholder:`Unlimited…`,disabled:n}),(0,$.jsx)(U,{label:`Max concurrent requests`,type:`number`,min:`0`,value:k,onChange:e=>te(e.target.value),placeholder:`Unlimited…`,disabled:n})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-6 rounded-panel border border-inner-border px-6 py-5 bg-surface-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`text-caption font-bold text-text-primary`,children:[(0,$.jsx)(x,{size:14,className:`mr-2 inline text-accent`,"aria-hidden":`true`}),`Token budget`]}),(0,$.jsx)(`p`,{className:`mt-1 text-text-tertiary text-micro`,children:X?`One-time cap; it does not reset.`:`Daily and monthly limits reset automatically.`})]}),(0,$.jsxs)(`div`,{className:`flex gap-2 rounded-inset border border-inner-border bg-surface-1 p-1`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>O(`recurring`),disabled:n,className:`py-2 px-5 rounded-chip font-semibold border-0 cursor-pointer`,style:{fontSize:`10.5px`,background:X?`transparent`:`var(--accent-soft)`,color:X?`var(--text-tertiary)`:`var(--accent)`},children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(Me,{size:13,"aria-hidden":`true`}),`Recurring`]})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>O(`one-time`),disabled:n,className:`py-2 px-5 rounded-chip font-semibold border-0 cursor-pointer`,style:{fontSize:`10.5px`,background:X?`var(--accent-soft)`:`transparent`,color:X?`var(--accent)`:`var(--text-tertiary)`},children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(je,{size:13,"aria-hidden":`true`}),`One-time`]})})]})]}),X?(0,$.jsx)(Ze,{label:`One-time token limit`,value:w,onChange:T,disabled:n}):(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 items-start min-w-0 max-medium:grid-cols-1`,children:[(0,$.jsx)(Ze,{label:`Daily token limit`,value:y,onChange:b,disabled:n}),(0,$.jsx)(Ze,{label:`Monthly token limit`,value:S,onChange:C,disabled:n})]})]})]}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-4 min-w-0 p-6 border border-inner-border rounded-card bg-surface-2 col-span-full`,"aria-labelledby":`share-popup-heading`,children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{id:`share-popup-heading`,className:`text-body font-bold text-text-primary`,children:[(0,$.jsx)(Fe,{size:16,className:`mr-2 inline text-accent`,"aria-hidden":`true`}),`Share page popup`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Optional card visitors open from the Base URL card on your share page.`})]}),(0,$.jsx)(G,{checked:V,onChange:e=>H(e),disabled:n,label:`Enable popup`})]}),V?(0,$.jsxs)(`div`,{className:`flex gap-7 items-start mt-2 min-w-0 max-medium:flex-col max-medium:items-stretch`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 min-w-0 w-100 shrink-0 max-medium:w-auto`,children:[xe?(0,$.jsx)(`img`,{className:`block w-full h-66 object-cover border border-inner-border rounded-control bg-surface-1 max-medium:h-80`,src:xe,alt:`Popup image preview`}):(0,$.jsx)(`div`,{className:`flex items-center justify-center w-full h-66 object-cover border border-dashed border-inner-border rounded-control bg-surface-1 text-text-tertiary text-badge max-medium:h-80`,"aria-hidden":`true`,children:(0,$.jsx)(`span`,{children:`No image`})}),(0,$.jsx)(he,{id:`share-popup-image`,accept:He.join(`,`),"aria-label":`Popup image`,disabled:n,onChange:e=>{let t=e.target.files?.[0];if(e.target.value=``,!t)return;if(J(null),t.size>2097152){K(null),J(`Image must be 2 MB or smaller.`);return}let n=new FileReader;n.onload=()=>{K(String(n.result)),_e(!1)},n.onerror=()=>J(`Could not read that file.`),n.readAsDataURL(t)}}),xe?(0,$.jsx)(h,{variant:`secondary`,size:`sm`,type:`button`,disabled:n,className:`h-14 px-5 text-badge self-start`,onClick:()=>{K(null),_e(!0),J(null)},children:`Remove image`}):null,ve?(0,$.jsx)(`p`,{className:`form-error`,children:ve}):null,(0,$.jsx)(`p`,{className:`m-0 text-text-tertiary text-badge leading-normal`,children:`PNG, JPEG, WebP, or GIF up to 2 MB.`})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 min-w-0 flex-1 [&_.form-group]:gap-2`,children:[(0,$.jsx)(U,{label:`Popup title`,value:Se,onChange:e=>Ce(e.target.value),maxLength:120,placeholder:`Support this gateway`,disabled:n}),(0,$.jsxs)(`div`,{className:`form-group`,children:[(0,$.jsx)(`label`,{className:`form-label`,htmlFor:`share-popup-copy`,children:`Message`}),(0,$.jsx)(`textarea`,{className:`form-textarea`,id:`share-popup-copy`,value:we,onChange:e=>Te(e.target.value),maxLength:1200,rows:3,placeholder:`If this service helps you, consider supporting its upkeep…`,disabled:n})]})]})]}):null]}),(0,$.jsxs)(`details`,{className:`group min-w-0 col-span-full rounded-card border border-inner-border bg-surface-2`,children:[(0,$.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-4 p-6 [&::-webkit-details-marker]:hidden`,children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 items-start gap-3`,children:[(0,$.jsx)(`span`,{className:`grid size-10 shrink-0 place-items-center rounded-inset bg-accent-soft text-accent`,children:(0,$.jsx)(ie,{size:18,"aria-hidden":`true`})}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block text-body font-bold text-text-primary`,children:`Access`}),(0,$.jsx)(`span`,{className:`mt-1 block text-badge text-text-tertiary`,children:t?.isDefault?`Default gateway key · all tenant permissions, including gateway routing and remote debugging.`:`Choose model, router, and dashboard permissions for this key.`})]})]}),(0,$.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-2 rounded-control border border-inner-border bg-surface-1 px-3 py-2 text-micro font-semibold text-text-secondary`,children:[A.length,`/`,Ve.length,` grants`,(0,$.jsx)(ue,{size:14,className:`transition-transform group-open:rotate-180`,"aria-hidden":`true`})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-5 border-t border-inner-border p-6`,children:[t?.isDefault?(0,$.jsxs)(`div`,{className:`flex items-start gap-3 rounded-control border border-accent/30 bg-accent-soft p-4 text-badge text-text-secondary`,children:[(0,$.jsx)(ne,{size:16,className:`mt-0.5 shrink-0 text-accent`,"aria-hidden":`true`}),(0,$.jsxs)(`p`,{className:`m-0`,children:[`This default API key is provisioned with every tenant permission, including `,(0,$.jsx)(`code`,{children:`routing:invoke`}),` and`,` `,(0,$.jsx)(`code`,{children:`routing:cli_mapping`}),`. Those grant gateway access and authorization to use remote CLI mappings; each client's mapping toggle below still controls whether those routes are active. You can remove individual grants here.`]})]}):null,(0,$.jsxs)(`div`,{className:`columns-2 gap-6 min-w-0 max-medium:columns-1`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`label`,{className:`inline-flex items-center gap-2 text-badge font-semibold text-text-secondary block mb-3`,children:[(0,$.jsx)(l,{size:14,className:`text-accent`,"aria-hidden":`true`}),`Model access`]}),(0,$.jsx)(`div`,{role:`group`,"aria-label":`Model access mode`,className:`flex gap-3 mb-4`,children:[`whitelist`,`blacklist`].map(e=>(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":N===e,disabled:n,onClick:()=>re(e),title:e===`whitelist`?`Only the listed models may be used. An empty list allows every model.`:`The listed models are refused. Everything else is allowed.`,className:`flex-1 py-2.5 px-4 text-badge font-semibold`,style:{borderRadius:`7px`,border:`1px solid ${N===e?`var(--accent)`:`var(--inner-border)`}`,background:N===e?`var(--accent-soft)`:`var(--surface-2)`,color:N===e?`var(--accent)`:`var(--text-secondary)`,cursor:n?`not-allowed`:`pointer`,opacity:n?.6:1},children:[e===`whitelist`?`Whitelist`:`Blacklist`,e===`whitelist`?(0,$.jsx)(ne,{size:13,className:`ml-2 inline`,"aria-hidden":`true`}):(0,$.jsx)(Le,{size:13,className:`ml-2 inline`,"aria-hidden":`true`})]},e))}),(0,$.jsx)(`label`,{className:`text-badge font-semibold text-text-secondary block mb-3`,children:N===`whitelist`?`Allowed models`:`Blocked models`}),(0,$.jsx)(`div`,{className:`flex gap-3 flex-wrap mb-4`,children:P.length===0?(0,$.jsx)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:N===`whitelist`?`All models allowed`:`No models blocked`}):P.map(e=>(0,$.jsxs)(`span`,{className:`font-mono tabular-nums inline-flex items-center gap-2 text-badge bg-accent-soft text-accent py-1 px-4 rounded-chip border border-accent`,children:[e,(0,$.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e} from the model list`,onClick:()=>ae(t=>t.filter(t=>t!==e)),disabled:n,className:`bg-transparent border-0 cursor-pointer p-0 flex`,children:`×`})]},e))}),(0,$.jsx)(h,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>le(!0),disabled:n,children:`Browse models`}),(0,$.jsx)(ge,{open:oe,onClose:()=>le(!1),selected:P,onToggle:e=>ae(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),title:N===`whitelist`?`Select allowed models`:`Select blocked models`,multi:!0})]}),(0,$.jsxs)(`section`,{"aria-labelledby":`blocked-routers-heading`,className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h4`,{id:`blocked-routers-heading`,className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(s,{size:15,className:`text-accent`,"aria-hidden":`true`}),`Blocked client routers`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Matching fingerprints are rejected with 403 before routing. Detection is best-effort; clients without a fingerprint are not matched. This may also block bazaar probe links that share the same fingerprint.`})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:se.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-6 py-2 px-5 rounded-inset`,style:{minHeight:`44px`,border:`1px solid var(--inner-border)`,background:I.includes(e.id)?`var(--accent-soft)`:`var(--surface-1)`},children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,$.jsx)(s,{size:15,className:`mt-1 shrink-0 text-orange`,"aria-hidden":`true`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`text-caption text-text-primary`,children:[`Block `,e.label,` Client`]}),(0,$.jsxs)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Reject requests fingerprinted as `,e.label,`.`]})]})]}),(0,$.jsx)(G,{checked:I.includes(e.id),onChange:t=>fe(n=>t?[...n,e.id]:n.filter(t=>t!==e.id)),disabled:n,"aria-label":`Block ${e.label} client`})]},e.id))})]}),(0,$.jsxs)(`section`,{"aria-labelledby":`routing-scopes-heading`,className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`h4`,{id:`routing-scopes-heading`,className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(M,{size:15,className:`text-accent`,"aria-hidden":`true`}),`Routing`]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:Ve.filter(e=>e===`routing:invoke`).map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-6 py-2 px-5 rounded-inset`,style:{minHeight:`44px`,border:`1px solid var(--inner-border)`,background:A.includes(e)?`var(--accent-soft)`:`var(--surface-1)`},children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(M,{size:16,className:`mt-1 shrink-0 text-accent`,"aria-hidden":`true`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-caption font-semibold text-text-primary`,children:e}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:Ue[e]})]})]}),(0,$.jsx)(G,{checked:A.includes(e),onChange:()=>Oe(e),disabled:n,"aria-label":`Grant ${e}`})]},e))})]}),(0,$.jsx)($e,{keyId:e===`edit`&&t?t.id:``,busy:n,scopeGranted:A.includes(`routing:cli_mapping`),onScopeChange:e=>{e!==A.includes(`routing:cli_mapping`)&&Oe(`routing:cli_mapping`)},persistScope:n=>{if(e!==`edit`||!t)return;let r=n?[...new Set([...A,`routing:cli_mapping`])]:A.filter(e=>e!==`routing:cli_mapping`);De.mutate({keyId:t.id,request:{scopes:r}},{onError:e=>g.error(F(e,`Could not update the key's routing scope.`))})}}),(0,$.jsxs)(`section`,{"aria-labelledby":`dashboard-scopes-heading`,className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`h4`,{id:`dashboard-scopes-heading`,className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(de,{size:15,className:`text-accent`,"aria-hidden":`true`}),`Dashboard / Resources`]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:Ve.filter(e=>!e.startsWith(`routing:`)).map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-6 py-2 px-5 rounded-inset`,style:{minHeight:`44px`,border:`1px solid var(--inner-border)`,background:A.includes(e)?`var(--accent-soft)`:`var(--surface-1)`},children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(()=>{let t=We[e];return(0,$.jsx)(t,{size:16,className:`mt-1 shrink-0 text-accent`,"aria-hidden":`true`})})(),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-caption font-semibold text-text-primary`,children:e}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:Ue[e]})]})]}),(0,$.jsx)(G,{checked:A.includes(e),onChange:()=>Oe(e),disabled:n,"aria-label":`Grant ${e}`})]},e))})]})]})]})]})]})}function it({secret:e,onClose:t}){return(0,$.jsx)(k,{open:e!==null,onClose:t,title:`New API key`,description:`Copy it now, or reveal it again later from the key's Share button.`,size:`md`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,$.jsx)(`p`,{className:`text-body text-text-secondary m-0 leading-normal`,children:`A personal key stays recoverable. Open the key's Share button and choose Reveal to see it again and copy it. Rotating the key replaces this secret, and any client still using it starts getting 401s.`}),(0,$.jsx)(`code`,{className:`block rounded-inset border border-inner-border bg-surface-1 py-5 px-6 text-caption text-text-primary break-all`,children:e}),(0,$.jsxs)(`div`,{className:`flex gap-4 flex-wrap`,children:[(0,$.jsx)(O,{value:e??``,size:`sm`,variant:`primary`,label:`Copy key`,copiedLabel:`Copied`}),(0,$.jsx)(h,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(v,{size:13}),onClick:()=>{e!==null&&(me(`cartethyia-api-key.txt`,`Cartethyia API key\n\n${e}\n\nKeep this secret. Reveal it again from the key's Share button.\n`,`text/plain;charset=utf-8`),g.success(`Key saved to your downloads.`))},children:`Save this key`})]})]})})}function at(e){let t=new Date(e);if(!Number.isFinite(t.getTime()))return`—`;let n=e-Date.now(),r=t.toLocaleString();if(n<=0)return`${r} (lapsed)`;let i=Math.ceil(n/6e4);if(i<60)return`${r} (in ${i}m)`;let a=Math.floor(i/60);return a<24?`${r} (in ${a}h)`:`${r} (in ${Math.floor(a/24)}d)`}function ot({onClose:e}){let t=o(!0),n=c(),[r,i]=(0,Q.useState)(null),a=t.data??[];return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(k,{open:!0,onClose:e,title:`Banned Users`,description:`A client address is banned after repeated invalid-model requests. The ban applies to every API key used from that address, not just one credential.`,size:`lg`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-7 min-w-0`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`h4`,{className:`text-caption font-semibold text-text-secondary mb-4`,children:[`Active bans (`,a.length,`)`]}),t.isPending?(0,$.jsx)(w,{label:`Loading banned users…`}):t.isError?(0,$.jsx)(C,{message:F(t.error,`Could not load banned users.`),onRetry:()=>void t.refetch()}):a.length===0?(0,$.jsx)(T,{title:`No banned users`,message:`No client address is currently banned for model abuse.`,icon:(0,$.jsx)(Ie,{size:20})}):(0,$.jsx)(`div`,{className:`rounded-inset border border-inner-border`,children:(0,$.jsx)(ke,{maxHeight:480,scrollRegion:!0,headers:[`Client IP`,`Reason`,`Applies to`,`Lapses`,``],children:a.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`font-mono tabular-nums text-badge text-text-primary whitespace-nowrap`,children:e.ip}),(0,$.jsx)(`td`,{className:`text-badge text-text-secondary`,children:e.reason===`repeated_invalid_model_requests`?`Repeated invalid-model requests`:e.reason}),(0,$.jsx)(`td`,{className:`text-badge text-text-secondary whitespace-nowrap`,children:`All API keys from this IP`}),(0,$.jsx)(`td`,{className:`text-badge text-text-secondary whitespace-nowrap`,children:at(e.expiresAt)}),(0,$.jsx)(`td`,{className:`text-right whitespace-nowrap`,children:(0,$.jsx)(h,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(Re,{size:13}),disabled:n.isPending,onClick:()=>i(e),children:`Unban`})})]},e.ip))})})]}),(0,$.jsx)(q,{justify:`flex-end`,gap:`0px`,children:(0,$.jsx)(h,{variant:`secondary`,size:`sm`,onClick:e,children:`Close`})})]})}),(0,$.jsx)(I,{open:r!==null,onClose:()=>i(null),onConfirm:async()=>{r&&(await n.mutateAsync(r.ip),g.success(`Unbanned ${r.ip}.`),i(null))},title:`Lift this ban?`,message:r?`Lift the ban on ${r.ip}? The address can reach the gateway again immediately.`:`Lift this ban?`,confirmLabel:`Unban`,danger:!0})]})}var st=e=>(e??0).toLocaleString(),ct=e=>e?new Date(e).toLocaleString():`—`;function lt({keyId:e}){let t=_e(),[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(!1);return(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-4 rounded-control border border-inner-border bg-surface-2 px-5 py-4 text-text-tertiary`,children:[(0,$.jsx)(`code`,{title:i&&n?n:void 0,className:`min-w-0 flex-auto overflow-hidden font-mono text-caption text-text-primary text-ellipsis whitespace-nowrap`,children:i&&n?n:`••••••••••••••••`}),(0,$.jsx)(h,{variant:`secondary`,size:`sm`,icon:i?(0,$.jsx)(y,{size:13}):(0,$.jsx)(b,{size:13}),loading:t.isPending,disabled:t.isPending,onClick:()=>{if(n!==null){a(e=>!e);return}t.mutate({keyId:e},{onSuccess:e=>{r(e.secret),a(!0)},onError:e=>g.error(F(e,`Could not reveal the key.`))})},children:i?`Hide`:`Reveal`}),i&&n?(0,$.jsx)(O,{value:n,size:`sm`,variant:`secondary`,label:`Copy`,copiedLabel:`Copied`}):null]})}function ut({label:e,value:t}){return(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 basis-60 rounded-control border border-inner-border bg-surface-2 px-5 py-3`,children:[(0,$.jsx)(`dt`,{className:`text-badge font-normal tracking-label text-text-tertiary uppercase`,children:e}),(0,$.jsx)(`dd`,{className:`mt-1 text-caption font-normal text-text-primary tabular-nums`,children:t==null?`Unlimited`:st(t)})]})}function dt(e){return e?{title:`Regenerate this key?`,message:`This rotates the key credential. Any client still using the current secret starts getting 401s immediately, and the old secret cannot be recovered. The handoff link is re-pointed to reveal the new key.`,confirmLabel:`Regenerate key`}:{title:`Regenerate this link?`,message:`This replaces the link URL; the current URL stops resolving immediately. Recipients keep the keys they already generated and keep working — but no one can enroll through the old link again.`,confirmLabel:`Regenerate link`}}function ft({consumed:e,budget:t}){let n=t==null||t<=0,r=n?100:Math.min(100,e/t*100),i=!n&&e>=t;return(0,$.jsxs)(`div`,{className:`grid flex-auto basis-full gap-2.5 rounded-control border border-inner-border bg-surface-2 px-5 py-3.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 text-badge tracking-label text-text-tertiary uppercase`,children:[(0,$.jsx)(`span`,{children:`Lifetime budget`}),(0,$.jsx)(`span`,{className:`text-caption font-normal text-text-primary tabular-nums normal-case tracking-normal`,children:n?`${B(e)} · Unlimited`:`${B(e)} / ${B(t)}`})]}),(0,$.jsx)(`div`,{className:`h-3 overflow-hidden rounded bg-inner-border`,role:`progressbar`,"aria-label":`Lifetime token budget consumed`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(r),"aria-valuetext":n?`${B(e)} tokens consumed, no lifetime budget set`:`${B(e)} of ${B(t)} tokens consumed`,children:(0,$.jsx)(`div`,{className:i?`h-full rounded bg-status-danger`:`h-full rounded bg-status-success`,style:{width:`${r}%`}})})]})}function pt(e){return e.filter(e=>e.revokedAt===null).length}function mt(e){return e.reduce((e,t)=>e+t.allTime.totalTokens,0)}function ht({consumed:e,budget:t}){if(t==null)return(0,$.jsx)(`div`,{className:`grid flex-auto basis-full gap-2.5 rounded-control border border-inner-border bg-surface-2 px-5 py-3.5`,children:(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 text-badge tracking-label text-text-tertiary uppercase`,children:[(0,$.jsx)(`span`,{children:`Total quota used`}),(0,$.jsx)(`span`,{className:`text-caption font-normal text-text-primary tabular-nums normal-case tracking-normal`,children:B(e)})]})});let n=t>0?Math.min(100,e/t*100):0,r=t>0?Math.max(0,100-e/t*100):100,i=Math.max(0,t-e),a=Ae(e>=t?0:r),o=e>=t;return(0,$.jsxs)(`div`,{className:`grid flex-auto basis-full gap-2.5 rounded-control border border-inner-border bg-surface-2 px-5 py-3.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 text-badge tracking-label text-text-tertiary uppercase`,children:[(0,$.jsx)(`span`,{children:`Total quota`}),(0,$.jsxs)(`span`,{className:`text-caption font-normal text-text-primary tabular-nums normal-case tracking-normal`,children:[B(e),` / `,B(t)]}),(0,$.jsx)(`span`,{className:`border rounded-chip px-4 py-0.5 text-caption font-bold whitespace-nowrap tabular-nums`,style:{color:a.text,borderColor:a.text},children:o?`Exhausted`:`${B(i)} left`})]}),(0,$.jsx)(`div`,{className:`h-3 overflow-hidden rounded bg-inner-border`,role:`progressbar`,"aria-label":`Total quota consumed`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(n),"aria-valuetext":`${B(e)} of ${B(t)} tokens consumed`,children:(0,$.jsx)(`div`,{className:o?`h-full rounded bg-status-danger`:`h-full rounded`,style:{width:`${n}%`,background:o?void 0:a.bar}})})]})}function gt({parentId:e,childId:t}){let n=Ee(e,t);if(n.isPending)return(0,$.jsx)(w,{label:`Loading activity…`,compact:!0});if(n.isError)return(0,$.jsx)(C,{compact:!0,message:F(n.error,`Could not load activity.`),onRetry:()=>void n.refetch()});let r=n.data;return r?(0,$.jsxs)(`div`,{className:`grid min-w-0 gap-6 border-t border-inner-border bg-surface-1 px-6 py-5`,children:[(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h4`,{className:`mb-3 text-caption font-bold text-text-primary`,children:`Top models`}),r.models.length?(0,$.jsx)(`div`,{className:`data-table-container`,children:(0,$.jsxs)(`table`,{className:`data-table text-caption`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`col`,children:`Model`}),(0,$.jsx)(`th`,{scope:`col`,children:`Today`}),(0,$.jsx)(`th`,{scope:`col`,children:`Errors`}),(0,$.jsx)(`th`,{scope:`col`,children:`Tokens`})]})}),(0,$.jsx)(`tbody`,{children:r.models.map((e,t)=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:e.modelId}),(0,$.jsx)(`td`,{children:st(e.todayRequests)}),(0,$.jsx)(`td`,{children:st(e.todayErrors)}),(0,$.jsx)(`td`,{children:B(e.todayTokens)})]},`${e.providerId??``}-${e.modelId}-${t}`))})]})}):(0,$.jsx)(`p`,{className:`py-3 text-caption text-text-tertiary`,children:`No model activity yet.`})]}),(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h4`,{className:`mb-3 text-caption font-bold text-text-primary`,children:`Recent requests`}),r.requests.length?(0,$.jsx)(`div`,{className:`data-table-container`,children:(0,$.jsxs)(`table`,{className:`data-table text-caption`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`col`,children:`Model`}),(0,$.jsx)(`th`,{scope:`col`,children:`Status`}),(0,$.jsx)(`th`,{scope:`col`,children:`Tokens`}),(0,$.jsx)(`th`,{scope:`col`,children:`Time`})]})}),(0,$.jsx)(`tbody`,{children:r.requests.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsxs)(`td`,{children:[e.providerId??`Provider`,`/`,e.modelId??`Model`]}),(0,$.jsxs)(`td`,{children:[e.status,e.httpStatus?` · ${e.httpStatus}`:``]}),(0,$.jsx)(`td`,{children:B(e.totalTokens)}),(0,$.jsx)(`td`,{children:ct(e.startedAt)})]},e.requestId))})]})}):(0,$.jsx)(`p`,{className:`py-3 text-caption text-text-tertiary`,children:`No recent requests.`})]})]}):null}function _t({parent:e,onSecretRevealed:t}){let[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(`active`),[o,c]=(0,Q.useState)(null),l=ve(),u=we(),d=Te(),p=xe(e.id),m=e.keyMode!==`share`,_=J(m?null:e.id),v=_.data??[],y=i===`active`?v.filter(e=>e.revokedAt===null):v.filter(e=>e.revokedAt!==null),b=v.filter(e=>e.revokedAt===null&&e.allTime.totalTokens===0);(0,Q.useEffect)(()=>{r(null)},[e.id]);let x=async(t,n)=>{let r=0;for(let n of t)try{await d.mutateAsync({parentKeyId:e.id,childKeyId:n.id}),r+=1}catch{}await _.refetch();let i=t.length-r;i>0?g.error(`Revoked ${r} of ${t.length} ${n}; ${i} failed.`):g.success(`Revoked ${r} ${n}.`)},S=l.isPending||u.isPending,[ee,E]=(0,Q.useState)(!1),k=async()=>{if(m){let n=await u.mutateAsync({keyId:e.id});t?.(n.secret);return}await l.mutateAsync({keyId:e.id,regenerate:!0}),g.success(`Link regenerated; the previous URL no longer works.`)},te=()=>{l.mutate({keyId:e.id},{onError:e=>g.error(F(e,`Could not create link.`))})},A=p.data?.url??null,M=dt(m);return(0,$.jsxs)(`div`,{className:`grid min-w-0 gap-6`,children:[(0,$.jsx)(`section`,{"aria-label":`Link`,children:p.isPending?(0,$.jsx)(w,{label:`Loading link…`,compact:!0}):p.isError?(0,$.jsx)(C,{compact:!0,message:F(p.error,`Could not load the link.`),onRetry:()=>void p.refetch()}):A?(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-4 rounded-control border border-inner-border bg-surface-2 px-5 py-4 text-text-tertiary`,children:[(0,$.jsx)(D,{size:14,"aria-hidden":`true`,className:`shrink-0`}),(0,$.jsx)(`code`,{title:A,className:`min-w-0 flex-auto overflow-hidden font-mono text-caption text-text-primary text-ellipsis whitespace-nowrap`,children:A}),(0,$.jsx)(O,{value:A,size:`sm`,variant:`secondary`,label:`Copy`,copiedLabel:`Copied`}),(0,$.jsx)(h,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(Ne,{size:13}),loading:S,disabled:S,onClick:()=>E(!0),children:`Regenerate`})]}):(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-4 rounded-control border border-inner-border bg-surface-2 px-5 py-4 text-text-tertiary`,children:[(0,$.jsx)(D,{size:14,"aria-hidden":`true`,className:`shrink-0`}),(0,$.jsx)(`span`,{className:`flex-auto text-caption text-text-tertiary`,children:`No link yet.`}),(0,$.jsx)(h,{variant:`primary`,size:`sm`,loading:S,disabled:S,onClick:te,children:`Create link`})]})}),m?(0,$.jsxs)(`section`,{"aria-label":`API key`,className:`grid gap-3`,children:[(0,$.jsx)(`div`,{className:`flex items-center justify-between gap-4`,children:(0,$.jsx)(`strong`,{className:`text-caption`,children:`API key`})}),(0,$.jsx)(lt,{keyId:e.id})]}):null,m?(0,$.jsxs)(`section`,{"aria-label":`Usage`,className:`grid gap-3`,children:[(0,$.jsx)(`div`,{className:`flex items-center justify-between gap-4`,children:(0,$.jsx)(`strong`,{className:`text-caption`,children:`Usage`})}),(0,$.jsxs)(`dl`,{className:`m-0 flex flex-wrap gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 basis-60 rounded-control border border-inner-border bg-surface-2 px-5 py-3`,children:[(0,$.jsx)(`dt`,{className:`text-badge font-normal tracking-label text-text-tertiary uppercase`,children:`Lifetime tokens`}),(0,$.jsx)(`dd`,{className:`mt-1 text-caption font-normal text-text-primary tabular-nums`,children:B(e.tokensConsumed)})]}),(0,$.jsx)(ut,{label:`Requests / min`,value:e.requestsPerMinute}),(0,$.jsx)(ut,{label:`Daily tokens`,value:e.dailyTokenLimit}),(0,$.jsx)(ut,{label:`Monthly tokens`,value:e.monthlyTokenLimit}),(0,$.jsx)(ft,{consumed:e.tokensConsumed,budget:e.lifetimeTokenBudget})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`section`,{"aria-label":`Total quota`,className:`grid gap-3`,children:[(0,$.jsx)(`div`,{className:`flex items-center justify-between gap-4`,children:(0,$.jsx)(`strong`,{className:`text-caption`,children:`Total quota`})}),(0,$.jsx)(ht,{consumed:mt(v),budget:e.lifetimeTokenBudget})]}),(0,$.jsxs)(`section`,{"aria-label":`Recipients`,className:`grid gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsx)(`strong`,{className:`text-caption`,children:`Recipients`}),(0,$.jsxs)(`span`,{className:`mr-2 ml-auto text-caption text-text-tertiary tabular-nums`,children:[`Active users: `,pt(v)]}),(0,$.jsx)(`div`,{className:`inline-flex items-center gap-1 rounded-chip border border-inner-border p-0.5`,role:`group`,"aria-label":`Filter recipients by status`,children:[`active`,`revoked`].map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":i===e,onClick:()=>a(e),className:`rounded-chip border-0 px-3 py-1 text-badge font-semibold capitalize cursor-pointer ${i===e?`bg-surface-1 text-text-primary`:`bg-transparent text-text-secondary hover:text-text-primary`}`,children:e},e))}),o===null?null:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2 rounded-chip border border-danger-border bg-surface-2 px-3 py-1`,children:[(0,$.jsx)(`span`,{className:`text-badge text-text-secondary`,children:o===`all`?`Revoke ${y.length}?`:`Revoke ${b.length} unused?`}),(0,$.jsx)(h,{variant:`danger`,size:`sm`,loading:d.isPending,onClick:()=>{let e=o===`all`?y:b,t=o===`all`?`recipients`:`unused recipients`;c(null),x(e,t)},children:`Confirm`}),(0,$.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>c(null),children:`Cancel`})]}),(0,$.jsx)(h,{variant:`ghost`,size:`sm`,disabled:b.length===0||d.isPending,title:b.length===0?`No active recipient has spent zero tokens`:`Revoke ${b.length} recipient${b.length===1?``:`s`} that never spent a token`,onClick:()=>c(`unused`),icon:(0,$.jsx)(s,{size:13}),children:`Revoke no-usage`}),(0,$.jsx)(h,{variant:`ghost`,size:`sm`,disabled:y.length===0||d.isPending,title:y.length===0?`Nothing to revoke in this view`:`Revoke all ${y.length} listed recipient${y.length===1?``:`s`}`,onClick:()=>c(`all`),icon:(0,$.jsx)(s,{size:13}),children:`Revoke all`}),(0,$.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>void _.refetch(),icon:(0,$.jsx)(j,{size:13,className:_.isFetching?`animate-spin`:void 0}),children:`Refresh`})]}),_.isPending&&!_.data?(0,$.jsx)(w,{label:`Loading recipients…`,compact:!0}):_.isError?(0,$.jsx)(C,{compact:!0,message:F(_.error,`Could not load recipients.`),onRetry:()=>void _.refetch()}):y.length===0?(0,$.jsx)(T,{compact:!0,title:i===`revoked`?`No revoked recipients`:`No active recipients`,message:i===`revoked`?`Revoked keys appear here once a recipient's key is revoked.`:`Keys generated through this link appear here with their masked client IP and token usage.`}):(0,$.jsx)(`div`,{className:`data-table-container max-h-[46vh]`,children:(0,$.jsxs)(`table`,{className:`data-table text-caption`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`col`,className:`w-12`,"aria-label":`Expand`}),(0,$.jsx)(`th`,{scope:`col`,children:`Key`}),(0,$.jsx)(`th`,{scope:`col`,children:`Status`}),(0,$.jsx)(`th`,{scope:`col`,children:`Today`}),(0,$.jsx)(`th`,{scope:`col`,children:`Lifetime`}),(0,$.jsx)(`th`,{scope:`col`,children:`Last activity`}),(0,$.jsx)(`th`,{scope:`col`,className:`text-right whitespace-nowrap`,children:`Actions`})]})}),(0,$.jsx)(`tbody`,{children:y.map(t=>{let i=n===t.id;return(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsx)(`button`,{type:`button`,className:`grid h-11 w-11 place-items-center rounded-chip border-0 bg-transparent p-0 text-text-secondary hover:bg-hover hover:text-text-primary`,"aria-expanded":i,"aria-label":i?`Collapse recipient`:`Expand recipient`,onClick:()=>r(i?null:t.id),children:i?(0,$.jsx)(ue,{size:14}):(0,$.jsx)(f,{size:14})})}),(0,$.jsxs)(`td`,{children:[(0,$.jsxs)(`code`,{children:[t.label||t.keyPrefix||`key`,`…`]}),(0,$.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary wrap-anywhere`,children:t.issuedClientIp??`IP hidden`})]}),(0,$.jsx)(`td`,{children:t.revokedAt?`revoked`:`active`}),(0,$.jsx)(`td`,{children:B(t.today.totalTokens)}),(0,$.jsx)(`td`,{children:B(t.allTime.totalTokens)}),(0,$.jsx)(`td`,{children:ct(t.lastUsedAt)}),(0,$.jsx)(`td`,{className:`text-right whitespace-nowrap`,children:(0,$.jsx)(h,{variant:`danger`,size:`sm`,disabled:d.isPending||!!t.revokedAt,onClick:()=>d.mutate({parentKeyId:e.id,childKeyId:t.id},{onError:e=>g.error(F(e,`Could not revoke key.`))}),children:`Revoke`})})]}),i?(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:7,className:`p-0`,children:(0,$.jsx)(gt,{parentId:e.id,childId:t.id})})}):null]},t.id)})})]})})]})]}),(0,$.jsx)(I,{open:ee,onClose:()=>E(!1),onConfirm:k,title:M.title,message:M.message,confirmLabel:M.confirmLabel,danger:!0})]})}function vt({parent:e,onClose:t,onSecretRevealed:n}){let r=e.keyMode!==`share`;return(0,$.jsx)(k,{open:!0,onClose:t,title:`Sharing — ${e.label||`API key`}`,description:r?`One stable handoff link for this key. Regenerating rotates the key itself.`:`One stable enrollment link. Regenerating replaces the URL; recipients keep the keys they already generated.`,size:`lg`,children:(0,$.jsx)(_t,{parent:e,onSecretRevealed:n})})}function yt(){let e=Y(),t=le(),n=Se(),r=ye(),i=Ce(),a=we(),o=_e(),s=be(),{copy:c}=pe(),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(null),[m,v]=(0,Q.useState)(null),[y,b]=(0,Q.useState)(null),[x,S]=(0,Q.useState)(null),[E,D]=(0,Q.useState)(null),[O,j]=(0,Q.useState)(!1),[M,N]=(0,Q.useState)(null),[ne,re]=(0,Q.useState)(null),ie=e.data??[],P=t.data?.isPlatformAdmin??!1,ae=e=>{S(null),D(e)},se=async e=>{try{let{secret:t}=await o.mutateAsync({keyId:e.id});await c(t)?g.success(`API key copied`):g.error(`Clipboard unavailable on this origin`)}catch(e){g.error(F(e,`Could not reveal API key.`))}},ce=dt(!0);return(0,$.jsxs)(z,{children:[(0,$.jsx)(R,{title:`API Credentials`,subtitle:`Manage tenant API keys, model access, budgets, and sharing.`,icon:(0,$.jsx)(ee,{size:16}),action:(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[P?(0,$.jsx)(h,{variant:`secondary`,size:`sm`,onClick:()=>j(!0),icon:(0,$.jsx)(Ie,{size:13}),children:`Banned Users`}):null,(0,$.jsx)(h,{variant:`primary`,size:`sm`,onClick:()=>{S(null),u(!0)},icon:(0,$.jsx)(A,{size:13}),children:`Create Key`})]})}),(0,$.jsx)(L,{children:e.isPending&&!e.data?(0,$.jsx)(w,{label:`Loading API keys…`}):e.isError&&!e.data?(0,$.jsx)(C,{message:F(e.error,`Could not load credentials.`),onRetry:()=>void e.refetch()}):ie.length===0?(0,$.jsx)(T,{title:`No API keys issued`,message:`Generate a secret key to authenticate your SDK or CLI client against the gateway.`,icon:(0,$.jsx)(ee,{size:20})}):(0,$.jsx)(`div`,{className:`scroll-region max-h-280 pr-1`,children:(0,$.jsx)(p,{items:ie,label:`API credentials`,disabled:s.isPending,onReorder:e=>s.mutate(e,{onError:e=>g.error(F(e,`Could not save the new order.`))}),renderItem:e=>(0,$.jsxs)(`div`,{className:`api-key-card flex items-start justify-between gap-6 px-6 py-4 rounded-chip border border-inner-border bg-surface-2 max-medium:flex-col max-medium:items-stretch max-medium:gap-4 max-medium:p-5 [&>div:last-child]:flex-wrap`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,$.jsx)(`strong`,{className:`text-body`,children:e.label||`Unnamed credential`}),(0,$.jsx)(H,{tone:e.revokedAt?`err`:e.enabled?`ok`:`warn`,children:e.revokedAt?`revoked`:e.enabled?`enabled`:`disabled`}),(0,$.jsx)(H,{tone:e.keyMode===`share`?`accent`:`default`,children:e.keyMode===`share`?`share template`:`personal`}),e.isDefault?(0,$.jsx)(H,{tone:`warn`,title:`Required by the gateway. Rotate it; it cannot be deleted.`,children:`default · rotate only`}):null]}),(0,$.jsxs)(`div`,{className:`api-key-facts flex items-center flex-wrap gap-2 mt-3 min-w-0 max-medium:grid max-medium:grid-cols-3 max-medium:gap-2 max-medium:mt-0`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap max-medium:justify-between`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Created`}),new Date(e.createdAt).toLocaleDateString()]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap max-medium:justify-between`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:e.keyMode===`share`?`Total usage`:`Usage`}),B(e.tokensConsumed)]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap max-medium:justify-between`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`RPM`}),V(e.requestsPerMinute)]})]}),(0,$.jsxs)(`div`,{className:`api-key-facts flex items-center flex-wrap gap-2 mt-3 min-w-0 max-medium:grid max-medium:grid-cols-3 max-medium:gap-2 max-medium:mt-0`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap max-medium:justify-between`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Daily`}),V(e.dailyTokenLimit)]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap max-medium:justify-between`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Monthly`}),V(e.monthlyTokenLimit)]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap max-medium:justify-between`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`One-time`}),V(e.lifetimeTokenBudget)]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap max-medium:justify-between`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Concurrent`}),V(e.maxConcurrentRequests)]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap max-medium:justify-between`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:e.modelAccessMode===`blacklist`?`Blocked`:`Models`}),e.modelAccessMode===`blacklist`?e.modelList?.length??0:e.modelList?.length?e.modelList.length:`All`]})]})]}),(0,$.jsxs)(`div`,{className:`flex gap-3 shrink-0 flex-wrap`,children:[e.revokedAt?null:(0,$.jsx)(G,{checked:e.enabled,disabled:r.isPending,id:`api-key-enabled-${e.id}`,label:``,"aria-label":`${e.enabled?`Disable`:`Enable`} ${e.label||`API credential`}`,onChange:t=>r.mutate({keyId:e.id,request:{enabled:t}},{onSuccess:()=>g.success(`${e.label||`API credential`} ${t?`enabled`:`disabled`}`),onError:e=>g.error(F(e,`Could not update credential state.`))})}),(0,$.jsx)(h,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(te,{size:13}),onClick:()=>{S(null),f(e)},children:`Edit`}),!e.revokedAt&&e.keyMode!==`share`?(0,$.jsx)(h,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(_,{size:13}),onClick:()=>void se(e),disabled:o.isPending,children:`Copy`}):null,!e.revokedAt&&(0,$.jsx)(h,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(Fe,{size:13}),onClick:()=>ae(e),children:e.keyMode===`share`?`Recipients`:`Share`}),!e.revokedAt&&e.keyMode!==`share`&&(0,$.jsx)(h,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(Ne,{size:13}),onClick:()=>{S(null),b(e)},disabled:a.isPending,children:`Rotate`}),!e.revokedAt&&!e.isDefault&&(0,$.jsx)(h,{variant:`danger`,size:`sm`,icon:(0,$.jsx)(oe,{size:13}),onClick:()=>v(e),disabled:i.isPending,children:`Revoke`})]})]})})})}),(0,$.jsx)(k,{open:l,onClose:()=>u(!1),title:`Create API Key`,description:`Create a tenant-scoped credential. Choose model access, permissions, limits, and optional blocked client routers.`,size:`lg`,footer:M,children:(0,$.jsx)(rt,{mode:`create`,record:null,busy:n.isPending,onClose:()=>u(!1),actionsRef:N,onDone:e=>{n.mutate(e,{onSuccess:t=>{u(!1),S(tt(e.keyMode,t.secret)),g.success(`API key created`)},onError:e=>g.error(F(e,`Could not create API key.`))})}})}),(0,$.jsx)(k,{open:d!==null,onClose:()=>f(null),title:`Edit API Key`,description:`Update the key's model access, permissions, limits, share notes, and optional public popup.`,size:`lg`,footer:ne,children:(0,$.jsx)(rt,{mode:`edit`,record:d,busy:r.isPending,onClose:()=>f(null),actionsRef:re,onDone:e=>{d&&r.mutate({keyId:d.id,request:e},{onSuccess:t=>{f(null),S(tt(e.keyMode,t.secret)),g.success(`API key updated`)},onError:e=>g.error(F(e,`Could not update API key.`))})}})}),E?(0,$.jsx)(vt,{parent:E,onClose:()=>D(null),onSecretRevealed:e=>{D(null),S(e)}}):null,(0,$.jsx)(I,{open:y!==null,onClose:()=>b(null),onConfirm:async()=>{if(!y)return;let e=await a.mutateAsync({keyId:y.id});S(e.secret),g.success(`Rotated ${y.label||y.id}.`),b(null)},title:ce.title,message:ce.message,confirmLabel:ce.confirmLabel,danger:!0}),(0,$.jsx)(I,{open:m!==null,onClose:()=>v(null),onConfirm:async()=>{m&&(await i.mutateAsync(m.id),g.success(`Revoked ${m.label||m.id}.`),v(null))},title:`Revoke API key?`,message:m?`Revoke ${m.label||m.id}? Clients using it will be rejected.${m.keyMode===`share`?` All child keys and enrollment links will also be revoked.`:``}`:`Revoke this API key?`,confirmLabel:`Revoke`,danger:!0}),O?(0,$.jsx)(ot,{onClose:()=>j(!1)}):null,(0,$.jsx)(it,{secret:x,onClose:()=>S(null)})]})}function bt(){let e=P(),t=re(),n=e.data;if(e.isPending)return(0,$.jsx)(w,{label:`Loading compression settings…`});if(e.isError||!n)return(0,$.jsx)(C,{message:F(e.error,`Failed to load compression settings`),onRetry:()=>void e.refetch()});let r=n.rtkPruneEnabled,i=n.ponyTailEnabled;return(0,$.jsxs)(z,{children:[(0,$.jsx)(R,{title:`Compression`,subtitle:`Shrink requests before they reach the provider`,icon:(0,$.jsx)(a,{size:16})}),(0,$.jsx)(L,{children:(0,$.jsxs)(K,{gap:`14px`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-x-8 gap-y-5`,children:[(0,$.jsxs)(`div`,{className:`flex gap-5 min-w-0 flex-auto`,children:[(0,$.jsx)(Pe,{size:16,className:`shrink-0 mt-1 text-text-secondary`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`label`,{htmlFor:`compression-rtk`,children:(0,$.jsx)(q,{gap:`6px`,className:`text-body font-semibold`,children:`Prune tool output (RTK)`})}),(0,$.jsx)(`div`,{className:`text-badge text-text-tertiary wrap-anywhere max-w-full`,children:`Compact bulky tool results (diffs, grep dumps, listings) in the message history so a long conversation stops re-sending megabytes of raw output. Higher strength compresses more aggressively.`})]})]}),(0,$.jsxs)(q,{gap:`8px`,className:`shrink-0 items-center ml-auto`,children:[(0,$.jsx)(W,{id:`compression-rtk-level`,"aria-label":`RTK strength`,value:n.rtkPruneLevel,onValueChange:e=>t.mutate({rtkPruneLevel:e===`lite`||e===`full`||e===`ultra`?e:`full`},{onError:e=>g.error(F(e,`Could not update RTK strength.`))}),options:[{value:`lite`,label:`Lite`},{value:`full`,label:`Full`},{value:`ultra`,label:`Ultra`}]}),(0,$.jsx)(G,{id:`compression-rtk`,"aria-label":`Enable RTK prune`,checked:r,onChange:e=>t.mutate({rtkPruneEnabled:e},{onError:e=>g.error(F(e,`Could not update RTK prune.`))})})]})]}),(0,$.jsxs)(`div`,{className:`flex items-start gap-x-8 gap-y-5`,children:[(0,$.jsxs)(`div`,{className:`flex gap-5 min-w-0 flex-auto`,children:[(0,$.jsx)(ae,{size:16,className:`shrink-0 mt-1 text-text-secondary`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`label`,{htmlFor:`compression-ponytail`,children:(0,$.jsx)(q,{gap:`6px`,className:`text-body font-semibold`,children:`PonyTail (system directive)`})}),(0,$.jsx)(`div`,{className:`text-badge text-text-tertiary wrap-anywhere max-w-full`,children:`Appends a minimal-code directive to the system content, biasing the model toward the smallest working change. Higher strength pushes harder toward deletion over addition.`})]})]}),(0,$.jsxs)(q,{gap:`8px`,className:`shrink-0 items-center ml-auto`,children:[(0,$.jsx)(W,{id:`compression-ponytail-level`,"aria-label":`PonyTail strength`,value:n.ponyTailLevel,onValueChange:e=>t.mutate({ponyTailLevel:e===`lite`||e===`full`||e===`ultra`?e:`full`},{onError:e=>g.error(F(e,`Could not update PonyTail strength.`))}),options:[{value:`lite`,label:`Lite`},{value:`full`,label:`Full`},{value:`ultra`,label:`Ultra`}]}),(0,$.jsx)(G,{id:`compression-ponytail`,"aria-label":`Enable PonyTail`,checked:i,onChange:e=>t.mutate({ponyTailEnabled:e},{onError:e=>g.error(F(e,`Could not update PonyTail.`))})})]})]}),r||i?(0,$.jsxs)(`p`,{role:`note`,className:`flex gap-4 items-start m-0 py-4 px-5 rounded-inset border border-orange bg-orange-soft text-text-secondary text-badge`,children:[(0,$.jsx)(S,{size:14,className:`shrink-0 mt-0.5 text-orange`}),(0,$.jsx)(`span`,{children:`Your AI may produce degraded quality while compression is active: it sees a shortened history and a minimal-code directive, so fewer tokens but a chance of missing detail. Turn it off if answers get worse.`})]}):null]})})]})}function xt(){let{copied:e,copy:t}=pe(2e3),n=`${window.location.origin}/v1`,r=async()=>{if(await t(n)){g.success(`Gateway endpoint copied`,n);return}g.error(`Clipboard unavailable on this origin`)};return(0,$.jsxs)(z,{children:[(0,$.jsx)(R,{title:`Gateway Endpoint`,subtitle:`Universal OpenAI & Anthropic Wire API Endpoint Compatible`,icon:(0,$.jsx)(m,{size:16})}),(0,$.jsx)(L,{children:(0,$.jsxs)(K,{gap:`10px`,children:[(0,$.jsxs)(`div`,{className:`nested-panel flex items-center gap-4 rounded-control border border-inner-border bg-code-surface px-7 py-5 font-mono text-body font-semibold tabular-nums`,children:[(0,$.jsx)(`code`,{className:`min-w-0 flex-1 truncate`,title:n,children:n}),(0,$.jsx)(h,{variant:`secondary`,size:`sm`,icon:e?(0,$.jsx)(d,{size:13}):(0,$.jsx)(_,{size:13}),"aria-label":`Copy endpoint`,title:`Copy endpoint`,onClick:()=>void r(),className:`shrink-0`,children:e?`Copied`:`Copy`})]}),(0,$.jsxs)(`p`,{className:`text-caption leading-normal text-text-secondary`,children:[`Point any SDK, CLI, or agent (e.g. OpenCode, Pi, OMP, Kilo, Cline, Droid and more clients) to this same-origin base URL.`,(0,$.jsxs)(`span`,{className:`mt-1 block text-text-tertiary`,children:[`You may not put `,(0,$.jsx)(`code`,{className:`font-mono`,children:`/v1`}),` on Claude Code — the CLI appends it itself.`]})]})]})})]})}function St(){return(0,$.jsxs)(K,{gap:`16px`,children:[(0,$.jsx)(xt,{}),(0,$.jsx)(bt,{}),(0,$.jsx)(yt,{})]})}export{St as default};
|
|
Binary file
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{r as i}from"./terminal-Bd4ee8TA.js";import{t as a}from"./arrow-left-CpBxkoxI.js";import{n as o,t as s}from"./brain-Cwed_72z.js";import{n as c,t as l}from"./fingerprint-pattern-BWuHtbW4.js";import{t as u}from"./check-D69FzdvC.js";import{t as d}from"./circle-alert-CntYHV5v.js";import{t as f}from"./circle-check-BU3v_mFW.js";import{_ as p,a as m,g as h,i as g,p as _,r as v,t as y,v as b}from"./toast-CNt_jzO4.js";import{t as x}from"./cog-CdWhsajs.js";import{t as S}from"./copy-ngmQ9zcZ.js";import{t as C}from"./download-A0SW9OCW.js";import{t as w}from"./eye-off-Bk5g2luF.js";import{t as T}from"./eye-C_hawfH4.js";import{t as E}from"./gauge-BbIMy7MB.js";import{t as D}from"./image-BPaouViG.js";import{a as O,n as k,r as A,t as j}from"./state-DA0B95UQ.js";import{t as M}from"./key-round-UkavsGxp.js";import{t as N}from"./layers-2-glBbjl.js";import{n as ee,t as P}from"./dialog-BvQeBMfP.js";import{t as te}from"./pencil-768ysRAr.js";import{t as ne}from"./plus-DIdX_g-x.js";import{t as re}from"./power-off-Yjw9GMJh.js";import{t as ie}from"./refresh-cw-BqJFk4sU.js";import{t as F}from"./rotate-ccw-CufcqITi.js";import{t as ae}from"./search-JOKus9rb.js";import{t as oe}from"./trash-Cppn5c3R.js";import{t as se}from"./wrench-B6E1oEuY.js";import{T as ce}from"./assert-BHfaei-X.js";import{o as le,t as I}from"./query-keys-D7wX2vM5.js";import{$ as ue,C as de,D as fe,E as pe,L as me,O as he,Q as ge,S as _e,T as ve,Z as ye,a as be,at as xe,b as L,c as Se,d as Ce,f as we,g as Te,h as Ee,l as De,m as Oe,o as ke,p as Ae,r as je,t as R,u as Me,v as Ne,x as Pe,y as Fe}from"./entry--yj84zk3.js";import{n as z,r as Ie,t as B}from"./card-DEhRXXw4.js";import{n as Le}from"./download-dRFo5_Wu.js";import{f as Re,i as V,l as ze,n as H,r as Be,s as Ve}from"./tokens-DDxMbSRL.js";import{a as U}from"./numbers-CFL4_Dqc.js";import{t as W}from"./badge-DpXT4Ixt.js";import{n as G}from"./input-BpVZdrbc.js";import{t as K}from"./select-XPJ-dIw3.js";import{t as He}from"./ProviderIcon-CmfzxpVM.js";import{t as q}from"./switch-Cittxy-x.js";import{t as J}from"./stack-C9_uUjaA.js";import{n as Y,t as Ue}from"./inline-D1IlZZ8H.js";import{i as We}from"./quota-DZGyp0N5.js";import{t as Ge}from"./list-row-CwVcGAIc.js";import{c as Ke,l as X,m as qe}from"./routing-Cs6jl49L.js";import{o as Je,s as Ye,t as Xe}from"./HealthEventsModal-DeT-VXHd.js";import{r as Ze}from"./privacy-mode-GM8bej85.js";import{n as Qe,t as $e}from"./AccountCooldown-ChpdzxRH.js";import{t as et}from"./use-timeout-BwcBBRrT.js";import{t as tt}from"./banner-CSAAWLJv.js";var nt=e(`cable`,[[`path`,{d:`M17 19a1 1 0 0 1-1-1v-2a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v2a1 1 0 0 1-1 1z`,key:`trhst0`}],[`path`,{d:`M17 21v-2`,key:`ds4u3f`}],[`path`,{d:`M19 14V6.5a1 1 0 0 0-7 0v11a1 1 0 0 1-7 0V10`,key:`1mo9zo`}],[`path`,{d:`M21 21v-2`,key:`eo0ou`}],[`path`,{d:`M3 5V3`,key:`1k5hjh`}],[`path`,{d:`M4 10a2 2 0 0 1-2-2V6a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2a2 2 0 0 1-2 2z`,key:`1dd30t`}],[`path`,{d:`M7 5V3`,key:`1t1388`}]]),rt=e(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),it=e(`info`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]),at=e(`lock-open`,[[`rect`,{width:`18`,height:`11`,x:`3`,y:`11`,rx:`2`,ry:`2`,key:`1w4ew1`}],[`path`,{d:`M7 11V7a5 5 0 0 1 9.9-1`,key:`1mm8w8`}]]),ot=e(`package-x`,[[`path`,{d:`M12 22V12`,key:`d0xqtd`}],[`path`,{d:`m16.5 14.5 5 5`,key:`ozpm51`}],[`path`,{d:`m16.5 19.5 5-5`,key:`syf6b9`}],[`path`,{d:`M21 10.5V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.729l7 4a2 2 0 0 0 2 .001l.13-.074`,key:`isw6gs`}],[`path`,{d:`M3.29 7 12 12l8.71-5`,key:`19ckod`}],[`path`,{d:`m7.5 4.27 8.997 5.148`,key:`9yrvtv`}]]),st=e(`repeat`,[[`path`,{d:`m17 2 4 4-4 4`,key:`nntrym`}],[`path`,{d:`M3 11v-1a4 4 0 0 1 4-4h14`,key:`84bu3i`}],[`path`,{d:`m7 22-4-4 4-4`,key:`1wqhfi`}],[`path`,{d:`M21 13v1a4 4 0 0 1-4 4H3`,key:`1rx37r`}]]),ct=e(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),lt=e(`video`,[[`path`,{d:`m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5`,key:`ftymec`}],[`rect`,{x:`2`,y:`6`,width:`14`,height:`12`,rx:`2`,key:`158x01`}]]),ut=e(`waypoints`,[[`path`,{d:`m10.586 5.414-5.172 5.172`,key:`4mc350`}],[`path`,{d:`m18.586 13.414-5.172 5.172`,key:`8c96vv`}],[`path`,{d:`M6 12h12`,key:`8npq4p`}],[`circle`,{cx:`12`,cy:`20`,r:`2`,key:`144qzu`}],[`circle`,{cx:`12`,cy:`4`,r:`2`,key:`muu5ef`}],[`circle`,{cx:`20`,cy:`12`,r:`2`,key:`1xzzfp`}],[`circle`,{cx:`4`,cy:`12`,r:`2`,key:`1hvhnz`}]]),dt=[`auto`,`minimal`,`low`,`medium`,`high`,`xhigh`,`max`];function ft(e,t){return t===null?e:`${e}(${t})`}var Z=t(n(),1),Q=r();function pt({to:e,label:t}){let n=ye();return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{window.history.length>1?n(-1):n(e)},className:`inline-flex items-center gap-3 text-accent text-caption bg-transparent border-0 p-0 cursor-pointer`,children:[(0,Q.jsx)(a,{size:14,"aria-hidden":`true`}),t]})}function mt({title:e,description:t,icon:n,badges:r,actions:i,back:a}){return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[a?(0,Q.jsx)(pt,{...a}):null,(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-6 flex-wrap`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-5 min-w-0`,children:[n?(0,Q.jsx)(`div`,{className:`card-header-icon`,children:n}):null,(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,Q.jsx)(`h1`,{className:`text-lead font-bold`,children:e}),r]}),t?(0,Q.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:t}):null]})]}),i?(0,Q.jsx)(`div`,{className:m(`flex items-center gap-4 flex-wrap min-w-0 max-w-full`),children:i}):null]})]})}function ht(e){return e.isBuiltIn&&e.requiresAccount&&e.oauthFlows===void 0&&!e.hasAdapterUserAgent}function gt(e,t=600){let n=(0,Z.useRef)(void 0);return(0,Z.useEffect)(()=>()=>clearTimeout(n.current),[]),r=>{clearTimeout(n.current),n.current=setTimeout(()=>e(r),t)}}var _t={fallback:`Failover`,roundRobin:`Round robin`},vt=new Set([`inferhub`,`cline`]);function yt(e,t){let n=X(e),r=qe(),[i,a]=(0,Z.useState)(`fallback`),[o,s]=(0,Z.useState)(1),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(`percent`),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(``);(0,Z.useEffect)(()=>{n.data&&(a(n.data.strategy),s(n.data.rotateCount),l(n.data.maxInflight),d(n.data.maxInflightPerProxy??null),p(n.data.usageFloor),h(n.data.usageFloorUnit),_(n.data.skipProxy),y(n.data.userAgent))},[n.data]);let b=i=>{r.mutate({providerId:e,request:{enabled:!0,strategy:i.strategy,rotateCount:i.rotateCount,maxInflight:i.maxInflight,maxInflightPerProxy:i.maxInflightPerProxy,usageFloor:i.usageFloor,usageFloorUnit:i.usageFloorUnit,skipProxy:i.skipProxy,...t?{userAgent:i.userAgent}:{}}},{onError:()=>{n.data&&(a(n.data.strategy),s(n.data.rotateCount),l(n.data.maxInflight),d(n.data.maxInflightPerProxy??null),p(n.data.usageFloor),h(n.data.usageFloorUnit),_(n.data.skipProxy),y(n.data.userAgent))}})},x=gt(e=>b({strategy:i,rotateCount:o,maxInflight:e,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),S=gt(e=>b({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:e,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),C=gt(e=>b({strategy:i,rotateCount:e,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),w=gt(e=>b({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:e}));return{strategy:i,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,setUsageFloor:(e,t)=>{p(e),h(t),b({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:e,usageFloorUnit:t,skipProxy:g,userAgent:v})},skipProxy:g,userAgent:v,isLoading:n.isPending,isError:n.isError,isSaving:r.isPending,saveFailed:r.isError,refetch:()=>n.refetch(),setMaxInflight:e=>{l(e),x(e)},setMaxInflightPerProxy:e=>{d(e),S(e)},setUserAgent:e=>{y(e),w(e)},setSkipProxy:e=>{_(e),b({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:e,userAgent:v})},roundRobinEnabled:i===`round_robin`,setRoundRobinEnabled:e=>{let t=e?`round_robin`:`fallback`;a(t),b({strategy:t,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})},rotateCount:o,setRotateCount:e=>{s(e),C(e)}}}var bt=50,xt=100;function St(e,t,n){return[{value:``,label:`None`},{value:`Cartethyia/${e}`,label:`Cartethyia ${e}`},{value:`codex_cli_rs/${t}`,label:`Codex`},{value:`claude-cli/${n} (external, cli)`,label:`Claude Code`}]}function Ct({children:e,action:t}){return(0,Q.jsx)(Ge,{actions:t,children:e})}function wt({providerId:e,clientVersion:t,routeIdentityVersions:n,userAgentEditable:r}){let i=yt(e,r),[a,o]=(0,Z.useState)(!1),s=vt.has(e),c=St(R,n.codex,n.claude),u=c.some(e=>e.value===i.userAgent)?c:[...c,{value:i.userAgent,label:`Custom`}];if(i.isLoading)return(0,Q.jsx)(A,{label:`Loading routing...`});if(i.isError)return(0,Q.jsx)(k,{message:`Failed to load routing`,onRetry:i.refetch});let d=i.roundRobinEnabled?`${_t.roundRobin} · ${i.rotateCount} account${i.rotateCount===1?``:`s`} per rotation`:_t.fallback,f=i.isSaving?`Saving...`:i.saveFailed?`Save failed — reverted to last saved value`:`Active: ${d}`,p=i.maxInflight===null,m=p?51:Math.min(51,Math.max(1,i.maxInflight)),h=p?`∞`:String(i.maxInflight),g=i.maxInflightPerProxy===null,_=g?51:Math.min(51,Math.max(1,i.maxInflightPerProxy)),b=g?`∞`:String(i.maxInflightPerProxy),x=i.skipProxy,S=e=>{i.setRotateCount(Math.min(1e3,Math.max(1,i.rotateCount+e)))},C=e=>{if(e===i.userAgent)return;i.setUserAgent(e);let t=u.find(t=>t.value===e)?.label??e;y.success(`Client identity updated`,t)},w=t?`${t.client} ${t.version}`:`Provider default`;return(0,Q.jsxs)(B,{children:[(0,Q.jsx)(Ie,{title:`Routing Strategy`,subtitle:f,icon:(0,Q.jsx)(N,{size:16})}),(0,Q.jsx)(z,{children:(0,Q.jsxs)(`div`,{className:`grid gap-5 w-full min-w-0`,children:[(0,Q.jsx)(Ct,{action:(0,Q.jsxs)(Q.Fragment,{children:[i.roundRobinEnabled?(0,Q.jsxs)(`div`,{role:`group`,"aria-label":`Accounts per rotation`,className:`inline-flex items-center gap-1 rounded-control border border-inner-border bg-surface-1 p-1`,children:[(0,Q.jsx)(`span`,{className:`px-2 text-badge text-text-secondary`,children:`Accounts/rotation`}),(0,Q.jsx)(v,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Decrease accounts per rotation`,disabled:i.rotateCount<=1,icon:(0,Q.jsx)(ee,{size:14}),onClick:()=>S(-1)}),(0,Q.jsx)(`output`,{className:`min-w-8 text-center text-body font-semibold tabular-nums`,"aria-live":`polite`,children:i.rotateCount}),(0,Q.jsx)(v,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Increase accounts per rotation`,disabled:i.rotateCount>=1e3,icon:(0,Q.jsx)(ne,{size:14}),onClick:()=>S(1)})]}):null,(0,Q.jsx)(q,{checked:i.roundRobinEnabled,onChange:i.setRoundRobinEnabled,id:`routing-round-robin`})]}),children:(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`label`,{htmlFor:`routing-round-robin`,children:(0,Q.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(st,{size:15,"aria-hidden":`true`,className:`shrink-0 ${i.roundRobinEnabled?`text-accent`:`text-text-tertiary`}`}),`Round robin`]})}),(0,Q.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Off uses priority order with failover. On rotates requests across this provider's accounts.`})]})}),(0,Q.jsx)(Ct,{action:(0,Q.jsx)(q,{checked:i.skipProxy,onChange:i.setSkipProxy,id:`routing-skip-proxy`}),children:(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`label`,{htmlFor:`routing-skip-proxy`,children:(0,Q.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(nt,{size:15,"aria-hidden":`true`,className:`shrink-0 ${i.skipProxy?`text-accent`:`text-text-tertiary`}`}),`Always direct`]})}),(0,Q.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Bypass automatic proxy-pool routing for this provider and always dial direct`})]})}),(0,Q.jsxs)(`div`,{className:`routing-controls-grid grid gap-5 min-w-0 w-full`,children:[(0,Q.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0`,children:[(0,Q.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold mb-3`,children:[(0,Q.jsx)(l,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Client identity`]}),r?(0,Q.jsx)(K,{id:`routing-user-agent-preset`,"aria-label":`Client identity`,value:i.userAgent,options:u,onValueChange:C}):(0,Q.jsx)(K,{id:`routing-user-agent-fixed`,"aria-label":`Client identity`,disabled:!0,value:w,options:[{value:w,label:w}]}),(0,Q.jsx)(`div`,{className:`text-badge text-text-tertiary mt-2`,children:r?`None sends the request as-is — whatever the runtime or egress sets, with no identity stamped by the gateway. A chosen value overrides it.`:`Set by the provider. It cannot be changed.`})]}),(0,Q.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0`,children:[(0,Q.jsx)(`label`,{htmlFor:`routing-max-inflight`,className:`form-label`,children:(0,Q.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(E,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Max inflight / account`]})}),(0,Q.jsxs)(`div`,{className:`text-badge text-text-tertiary mb-3`,children:[`Shared provider ceiling. One step past `,bt,` is unlimited.`]}),(0,Q.jsxs)(Y,{gap:`10px`,className:`mt-3`,children:[(0,Q.jsx)(`input`,{id:`routing-max-inflight`,type:`range`,className:`routing-slider flex-1 min-w-0`,"data-unlimited":p?`true`:void 0,min:1,max:51,step:1,value:m,"aria-valuetext":p?`Unlimited`:String(i.maxInflight),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&i.setMaxInflight(t>bt?null:Math.round(t))},style:{"--slider-pct":`${m/51*100}%`}}),(0,Q.jsx)(`input`,{type:`text`,inputMode:`numeric`,"aria-label":`Max inflight per account`,value:h,onChange:e=>{let t=e.target.value.trim();if(t===``||t===`∞`){i.setMaxInflight(null);return}let n=Number(t);Number.isFinite(n)&&n>=1&&i.setMaxInflight(Math.min(xt,Math.round(n)))},className:`form-input w-26 shrink-0 px-2 py-3 text-center text-body ${p?`text-status-success`:``}`})]})]})]}),(0,Q.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0${x?` opacity-60`:``}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,Q.jsxs)(`label`,{htmlFor:`routing-max-inflight-per-proxy`,className:`min-w-0`,children:[(0,Q.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(ut,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Max inflight / proxy`]}),(0,Q.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Each proxy pool carries at most this many concurrent requests for this provider. Other providers on the same pool are unaffected.`})]}),(0,Q.jsx)(v,{variant:`ghost`,size:`sm`,className:`shrink-0`,"aria-label":`How per-proxy limits work`,onClick:()=>o(!0),children:`How it works`})]}),(0,Q.jsxs)(Y,{gap:`10px`,className:`mt-3`,children:[(0,Q.jsx)(`input`,{id:`routing-max-inflight-per-proxy`,type:`range`,className:`routing-slider flex-1 min-w-0`,"data-unlimited":g?`true`:void 0,min:1,max:51,step:1,disabled:x,value:_,"aria-valuetext":g?`Unlimited`:String(i.maxInflightPerProxy),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&i.setMaxInflightPerProxy(t>bt?null:Math.round(t))},style:{"--slider-pct":`${_/51*100}%`}}),(0,Q.jsx)(`input`,{type:`text`,inputMode:`numeric`,"aria-label":`Max inflight per proxy`,disabled:x,value:b,onChange:e=>{let t=e.target.value.trim();if(t===``||t===`∞`){i.setMaxInflightPerProxy(null);return}let n=Number(t);Number.isFinite(n)&&n>=1&&i.setMaxInflightPerProxy(Math.min(xt,Math.round(n)))},className:`form-input w-26 shrink-0 px-2 py-3 text-center text-body ${g?`text-status-success`:``}`})]}),(0,Q.jsx)(`div`,{className:`mt-2 text-badge text-text-tertiary`,children:x?`Always direct is on, so this provider never dials a pool. The limit is kept for when a pool is used again.`:`One step past ${bt} is unlimited.`})]}),(0,Q.jsx)(P,{open:a,onClose:()=>o(!1),title:`How concurrency limits stack`,size:`md`,children:(0,Q.jsxs)(`div`,{className:`grid gap-4 text-body`,children:[(0,Q.jsx)(`p`,{className:`text-text-secondary`,children:`Three limits apply at once. Each one bounds a different thing; none replaces another.`}),(0,Q.jsxs)(`dl`,{className:`grid gap-3`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Max inflight / account`}),(0,Q.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`One account of this provider, across every proxy. Set here, above.`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Max inflight / proxy`}),(0,Q.jsxs)(`dd`,{className:`text-badge text-text-tertiary`,children:[`One proxy pool's concurrent requests `,(0,Q.jsx)(`em`,{children:`for this provider`}),`. The same number applies to every pool; each pool counts separately. This is the field above.`]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Pool capacity`}),(0,Q.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`Everything through one pool, all providers combined. Set on the proxy itself, on the Proxies page.`})]})]}),(0,Q.jsxs)(`p`,{className:`text-badge text-text-tertiary`,children:[`A request must clear all three. When a pool is full for this provider, the request moves to another pool that still has room; it only fails with`,` `,(0,Q.jsx)(`code`,{children:`429`}),` when every pool is full.`]}),(0,Q.jsx)(`p`,{className:`text-badge text-text-tertiary`,children:`Unlimited means no counter is kept for this provider, so the limit costs nothing until you set one.`})]})}),s&&(0,Q.jsxs)(Y,{gap:`6px`,align:`flex-start`,className:`mt-1 text-badge text-text-tertiary`,children:[(0,Q.jsx)(it,{size:12,className:`shrink-0 mt-0.5`}),(0,Q.jsx)(`span`,{children:`This provider doesn't reliably work through a plain HTTP/S proxy — use a SOCKS5 or proxy pool instead if you need to route it.`})]})]})})]})}function Tt({providerId:e}){let t=yt(e,!1),n=Je(),r=Ke(e),i=(0,Z.useMemo)(()=>Dt(n.data?.accounts??[],e),[n.data,e]),a=(0,Z.useRef)(null),o=(0,Z.useMemo)(()=>[...r.data?.values()??[]].reduce((e,t)=>e+t,0),[r.data]);(0,Z.useEffect)(()=>{if(a.current===null){a.current=o;return}a.current!==o&&(a.current=o,n.refetch())},[o,n]);let[s,c]=(0,Z.useState)(`40`),[l,u]=(0,Z.useState)(`percent`),d=t.usageFloor!==null;(0,Z.useEffect)(()=>{t.usageFloor!==null&&c(String(t.usageFloor)),u(t.usageFloorUnit)},[t.usageFloor,t.usageFloorUnit]);let f=Number(s),p=Number.isInteger(f)&&f>=0&&f<=1e6,m=i===null||i.remaining<=0?`text-status-danger`:i.percent<=10?`text-status-warning`:`text-status-success`,h=(e,n)=>{(e===null||p)&&t.setUsageFloor(e,n)};return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`section`,{className:`usage-floor-panel flex flex-col gap-4 px-5 py-4 border border-inner-border rounded-narrow bg-surface-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 text-body font-semibold text-text-primary`,children:[(0,Q.jsx)(E,{size:14}),(0,Q.jsx)(`span`,{children:`Usage floor`}),(0,Q.jsx)(`span`,{className:`badge border border-warning-line bg-surface-2 text-micro tracking-label text-status-warning`,children:`BETA`})]}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-badge leading-normal text-text-tertiary`,children:`Per account. Skip an account once its remaining allowance reaches this, and send the request to the next one.`})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[i!==null&&(0,Q.jsxs)(`div`,{className:`flex min-h-24 min-w-0 flex-[1_1_20rem] flex-col justify-center gap-2 py-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-micro font-semibold tracking-label uppercase text-text-tertiary`,children:[(0,Q.jsx)(`span`,{children:`Pooled credits`}),(0,Q.jsx)(`span`,{className:`text-text-primary`,children:i.accounts}),(0,Q.jsx)(`span`,{children:i.accounts===1?`active account`:`active accounts`})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1 text-caption font-semibold tabular-nums text-text-primary`,title:`Combined allowance across active accounts; the usage floor is evaluated per account`,children:[(0,Q.jsx)(`strong`,{className:`font-bold ${m}`,children:Ot(i.remaining)}),(0,Q.jsx)(`span`,{className:`font-medium text-text-secondary`,children:`credits available`}),(0,Q.jsxs)(`span`,{className:`font-medium opacity-75`,children:[`of `,Ot(i.total)]}),(0,Q.jsxs)(`span`,{className:`font-bold ${m}`,children:[i.percent,`%`]})]}),(0,Q.jsx)(`p`,{className:`text-micro leading-normal text-text-tertiary`,children:t.usageFloor===null?`Floor off · exhausted quota windows are still skipped`:`Floor ${Ot(t.usageFloor)} ${t.usageFloorUnit===`credit`?`credits`:`%`} per account`})]}),i===null&&(0,Q.jsxs)(`p`,{className:`flex min-h-24 min-w-0 flex-[1_1_20rem] flex-col justify-center gap-2 py-2 text-badge leading-normal text-text-tertiary`,children:[(0,Q.jsx)(`span`,{children:`No combined credit balance is available. Separate quota windows are not added together, and exhausted windows are still skipped.`}),(0,Q.jsx)(`span`,{className:`text-micro`,children:t.usageFloor===null?`Floor off · exhausted quota windows are still skipped`:`Floor ${Ot(t.usageFloor)} ${t.usageFloorUnit===`credit`?`credits`:`%`} per account`})]}),(0,Q.jsxs)(`div`,{className:`ml-auto flex max-w-full shrink-0 flex-col items-end justify-center gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-x-3 gap-y-2`,children:[(0,Q.jsx)(`span`,{className:`text-micro font-semibold tracking-label uppercase text-text-tertiary`,children:`Floor threshold`}),(0,Q.jsxs)(`label`,{className:`flex h-12 max-w-full items-center overflow-hidden rounded-tiny border border-inner-border bg-surface-1 focus-within:border-text-tertiary`,children:[(0,Q.jsx)(`input`,{type:`number`,min:0,max:1e6,value:d?s:``,placeholder:`40`,disabled:!d,"aria-label":`Usage floor amount`,className:`h-full w-24 border-0 bg-transparent px-3 text-right font-mono text-body font-semibold tabular-nums text-text-primary disabled:text-text-tertiary`,onChange:e=>c(e.target.value),onBlur:()=>{d&&h(f,l)}}),(0,Q.jsxs)(`select`,{value:l,disabled:!d,"aria-label":`Usage floor unit`,className:`h-full border-0 border-l border-inner-border bg-hover px-3 text-body font-semibold text-text-secondary disabled:cursor-default disabled:opacity-60`,onChange:e=>{let t=e.target.value===`credit`?`credit`:`percent`;u(t),d&&h(f,t)},children:[(0,Q.jsx)(`option`,{value:`percent`,children:`%`}),(0,Q.jsx)(`option`,{value:`credit`,children:`credits`})]})]}),(0,Q.jsx)(q,{checked:d,label:`Enabled`,"aria-label":`Usage floor`,className:`usage-floor-switch`,onChange:e=>h(e?p?f:40:null,l)})]}),t.saveFailed?(0,Q.jsx)(`p`,{role:`alert`,className:`text-right text-micro leading-normal text-status-danger`,children:`Usage floor save failed. The last saved setting has been restored.`}):null]})]})]}),(0,Q.jsx)(Et,{providerId:e})]})}function Et({providerId:e}){let{enabled:t,setEnabled:n}=Ze(e);return(0,Q.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-6 px-6 py-5 border border-inner-border rounded-control bg-surface-2`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-auto basis-110`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 text-body font-semibold text-text-primary`,children:[(0,Q.jsx)(w,{size:14}),(0,Q.jsx)(`span`,{children:`Mysterious accounts`})]}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-badge leading-normal text-text-tertiary`,children:`Hide this provider's emails and usernames. Stored in this browser only.`})]}),(0,Q.jsx)(`div`,{className:`flex items-center gap-4 shrink-0`,children:(0,Q.jsx)(q,{checked:t,"aria-label":`Mysterious accounts`,onChange:n})})]})}function Dt(e,t){let n=0,r=0,i=0,a=!1;for(let o of e)if(o.provider===t&&o.active&&(i+=1,o.quota!==null))for(let e of o.quota.windows){if(e.accounting!==`pooled`)continue;let t=typeof e.limit==`number`&&Number.isFinite(e.limit)?e.limit:null;if(t===null)continue;let i=typeof e.remaining==`number`&&Number.isFinite(e.remaining)?e.remaining:typeof e.used==`number`&&Number.isFinite(e.used)?t-e.used:null;i!==null&&(n+=Math.min(t,Math.max(0,i)),r+=t,a=!0)}return i>0&&a?{accounts:i,remaining:n,total:r,percent:r>0?Math.round(n/r*100):0}:null}function Ot(e){return e.toLocaleString(void 0,{maximumFractionDigits:1})}function kt({provider:e}){let t=e.credentialUrl,n=e.credentialHint,r=e.operatorNotice;if(!t&&!n&&!r)return null;let i=e.oauthFlows?.browser===!0||e.oauthFlows?.device===!0,a=n??(i?`This provider authorizes through its own login flow; there is no key to paste.`:e.requiresAccount?`Create a credential on the provider site, then add it as an account below.`:`This provider needs no credential.`);return(0,Q.jsx)(B,{density:`compact`,children:(0,Q.jsx)(z,{children:(0,Q.jsxs)(Y,{gap:`12px`,className:`items-center flex-wrap`,children:[(0,Q.jsxs)(`span`,{className:`min-w-110 flex-1 text-caption text-text-secondary`,children:[a,r?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`br`,{}),r]}):null]}),t?(0,Q.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,title:t,className:g({size:`sm`,className:`shrink-0 no-underline`}),children:[(0,Q.jsx)(`span`,{className:`btn-icon-wrapper`,"aria-hidden":`true`,children:(0,Q.jsx)(rt,{size:13})}),i?`Sign in`:`Get API Key`]}):null]})})})}function At({provider:e}){let t=fe(),[n,r]=(0,Z.useState)(!1),[i,a]=(0,Z.useState)(e.baseUrl??``);(0,Z.useEffect)(()=>{a(e.baseUrl??``)},[e.providerId,e.baseUrl]);let o=(e.baseUrl??``).replace(/\/+$/,``),s=i.trim().replace(/\/+$/,``),c=s!==o,l=s.length>0&&c&&!t.isPending;return(0,Q.jsxs)(B,{children:[(0,Q.jsx)(Ie,{title:`Custom Provider Endpoint`,subtitle:`Upstream base URL`,icon:(0,Q.jsx)(p,{size:16})}),(0,Q.jsx)(z,{children:(0,Q.jsxs)(J,{gap:`12px`,children:[n?(0,Q.jsx)(G,{label:`Base URL`,id:`custom-provider-base-url`,type:`url`,value:i,onChange:e=>a(e.target.value),placeholder:`https://api.example.com/v1`,autoFocus:!0}):(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`div`,{className:`text-micro font-semibold uppercase tracking-label text-text-tertiary`,children:`Base URL`}),(0,Q.jsx)(`code`,{className:`mt-1 block min-w-0 break-all font-mono text-caption text-text-primary`,children:e.baseUrl??`Not configured`})]}),(0,Q.jsxs)(Y,{gap:`8px`,className:`w-full flex-wrap`,justify:`end`,children:[n?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(v,{size:`sm`,variant:`primary`,icon:(0,Q.jsx)(ct,{size:13}),disabled:!l,loading:t.isPending,onClick:()=>{l&&t.mutate({providerId:e.providerId,request:{baseUrl:s}},{onSuccess:()=>r(!1)})},children:`Save endpoint`}),(0,Q.jsx)(v,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(_,{size:13}),disabled:t.isPending,onClick:()=>{a(e.baseUrl??``),r(!1)},children:`Cancel`})]}):(0,Q.jsx)(v,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(te,{size:13}),onClick:()=>r(!0),children:`Edit endpoint`}),e.requiresAccount?(0,Q.jsx)(v,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(M,{size:13}),onClick:()=>{let e=document.getElementById(`provider-accounts`);e?.scrollIntoView({behavior:`smooth`,block:`start`}),e?.focus({preventScroll:!0})},children:`Manage API keys`}):null]})]})})]})}var jt={quota_fetch_failed:`Quota unreachable`,quota_exhausted:`Quota exhausted`,policy_blocked:`Policy blocked`,rate_limit_transient:`Rate limited`,missing_credential:`No credential`},Mt=new Set([`quota_fetch_failed`]);function Nt(e){return e===void 0||e.length===0?!1:!Mt.has(e)}function Pt(e){return e===`oauth`?`Re-login required`:`Replace API key`}function Ft(e,t){return e===`auth_invalidated`?Pt(t):jt[e]??e}async function It(e,t,n){let r=Array(e.length),i=Math.max(1,Math.min(t,e.length)),a=0;return await Promise.all(Array.from({length:i},async()=>{for(;;){let t=a;if(t>=e.length)return;a+=1;try{r[t]={status:`fulfilled`,value:await n(e[t],t)}}catch(e){r[t]={status:`rejected`,reason:e}}}})),r}var Lt=[`access`,`accessToken`,`access_token`,`sessionToken`,`session_token`,`token`,`apiKey`,`api_key`,`key`,`credential`,`pat`,`secret`],Rt=[`refresh`,`refreshToken`,`refresh_token`],zt=[`credentialKind`,`providerId`,`accessToken`],Bt=[`accounts`,`items`,`connections`],Vt=[`email`,`name`,`accountId`,`account_id`,`id`,`login`,`username`];function $(e){if(typeof e==`object`&&e&&!Array.isArray(e))return Object.fromEntries(Object.entries(e))}function Ht(e){let t=e.data;if(typeof t==`string`)try{return $(JSON.parse(t))}catch{return}return $(t)}function Ut(e){for(let t of Lt){let n=e[t];if(typeof n==`string`&&n.trim().length>0)return{value:n.trim(),extracted:!0,source:t}}let t=Ht(e);if(t)for(let e of Lt){let n=t[e];if(typeof n==`string`&&n.trim().length>0)return{value:n.trim(),extracted:!0,source:`data.${e}`}}}function Wt(e){for(let t of Vt){let n=e[t];if(typeof n==`string`&&n.trim().length>0)return n.trim()}let t=Ht(e);if(t)for(let e of Vt){let n=t[e];if(typeof n==`string`&&n.trim().length>0)return n.trim()}}function Gt(e){let t=(e,t)=>t.some(t=>typeof e[t]==`string`||typeof e[t]==`number`),n=e=>t(e,Rt);if(n(e))return!0;let r=Ht(e);return r?n(r):!1}function Kt(e){let t=e.trim().split(`.`);if(t.length===3)try{let e=t[1].replaceAll(`-`,`+`).replaceAll(`_`,`/`),n=e.padEnd(e.length+(4-e.length%4)%4,`=`);return $(JSON.parse(atob(n)))}catch{return}}function qt(e){let t=Kt(e)?.exp;if(typeof t!=`number`||!Number.isFinite(t))return;let n=new Date(t*1e3);return Number.isFinite(n.getTime())?n.toISOString():void 0}function Jt(e){let t={},n=0;for(let r of e.split(/\r?\n/)){let e=/^\s*([A-Za-z_][\w-]*)\s*:\s*(.*)$/.exec(r),i=e?.[1],a=e?.[2];i!==void 0&&a!==void 0&&(t[i]=a.trim(),n+=1)}return n>0?t:void 0}function Yt(e){if(e.startsWith(`{`)||e.startsWith(`[`))try{return JSON.parse(e)}catch{return}}function Xt(e){let t=e.trim(),n=$(Yt(t))??Jt(t);return n&&Gt(n)?`oauth`:Kt((n?Ut(n)?.value:void 0)??t)===void 0?`api_key`:`jwt`}function Zt(e){return e.length!==0&&!!(e.some(e=>Array.isArray(e.cookies)&&(typeof e.domain==`string`||typeof e.originalUrl==`string`))||e.every(e=>typeof e.name==`string`&&typeof e.value==`string`&&(e.domain!==void 0||e.path!==void 0||e.expirationDate!==void 0)))}function Qt(e,t){let n,r=!1,i=(e,t)=>{let i=e.toLowerCase();(i===`userid`||i===`uid`||i===`accountid`||i===`cuserid`)&&(n||=t.replace(/^"|"$/g,``).trim()),(i.includes(`token`)||i.includes(`ph`)||i.includes(`auth`)||i.includes(`session`))&&(r=!0)};for(let e of t)if(Array.isArray(e.cookies)){for(let t of e.cookies)if(t&&typeof t==`object`){let e=t;typeof e.name==`string`&&typeof e.value==`string`&&i(e.name,e.value)}}else typeof e.name==`string`&&typeof e.value==`string`&&i(e.name,e.value);return{value:e,kind:r?`oauth`:`api_key`,...n?{identity:n}:{}}}function $t(e){let t=e.credentialKind;if(typeof t==`string`&&typeof e.accessToken==`string`&&zt.every(t=>t in e)){let n=typeof e.label==`string`&&e.label.trim().length>0?e.label.trim():void 0,r=e.accessToken,i=t===`oauth`&&Gt(e);return{value:i?JSON.stringify(e):r,kind:i?`oauth`:`api_key`,...n?{identity:n}:{}}}let n=Ut(e),r=Gt(e)?`oauth`:Xt(n?.value??JSON.stringify(e)),i=r===`oauth`?JSON.stringify(e):n?.value??JSON.stringify(e),a=Wt(e);return a?{value:i,kind:r,identity:a}:{value:i,kind:r}}function en(e){for(let t of Bt){let n=e[t];if(!Array.isArray(n))continue;let r=n.map(e=>$(e)).filter(e=>e!==void 0);if(r.length>0)return r}}function tn(e){let t=e.trim();if(!t)return[];let n=Yt(t);if(Array.isArray(n)){let e=n.map(e=>$(e)).filter(e=>e!==void 0);if(e.length>0)return Zt(e)?[Qt(t,e)]:e.map($t)}else{let e=$(n);if(e){let t=en(e);return t?t.map($t):[$t(e)]}}let r=t.split(/\r?\n/).map(e=>e.trim()).filter(e=>e.length>0);if(r.length===0)return[];if(r.length===1){let e=Jt(r[0]);return e?[$t(e)]:nn(r[0])}let i=Jt(t);return i&&(Ut(i)||Object.keys(i).length===r.length)?[$t(i)]:r.flatMap(nn)}function nn(e){let t=$(Yt(e));if(t){let e=en(t);return e?e.map($t):[$t(t)]}return[{value:e,kind:Xt(e)}]}function rn(e,t,n){let r=new Set(n),i=1;return e.map(e=>{let n=e.identity;if(!n){for(;r.has(`${t}-${i}`);)i+=1;n=`${t}-${i}`,i+=1}let a=n,o=2;for(;r.has(a);)a=`${n} (${o++})`;return r.add(a),a})}function an(e){return e===`active`?0:e===`cooldown`?2:3}function on(e){if(e===void 0)return;let t=new Date(e).getTime();if(Number.isFinite(t))return t<=Date.now()?`Expired ${new Date(e).toLocaleDateString()}`:We(e,!1)}function sn({cooldowns:e,reason:t}){if(!e)return null;let n=We(e.until),r=`Soonest: ${e.modelId} — ${n}`;return(0,Q.jsxs)(W,{tone:`warn`,dot:!0,title:t?`${t} — ${r}`:r,children:[e.count,` model`,e.count===1?``:`s`,` cooling · `,n]})}function cn(e){if(e.credentialKind===`oauth`)return`OAuth`;if(e.credentialMode===`jwt`)return`JWT`}function ln(e){return e.credentialKind===`oauth`?`blue`:`ok`}function un({account:e}){let t=e.cooldownUntil?new Date(e.cooldownUntil).getTime():NaN,n=Number.isFinite(t)&&t>Date.now(),r=$e(e);if(e.status===`disabled`){let t=cn(e),n=e.lastErrorCategory===`auth_invalidated`;return(0,Q.jsxs)(Y,{gap:`4px`,children:[(0,Q.jsxs)(W,{tone:`disabled`,dot:!0,title:e.lastError,children:[`Disabled`,t?` - ${t}`:``]}),n?(0,Q.jsx)(W,{tone:`warn`,title:e.lastError,children:Pt(e.credentialKind)}):Nt(e.lastErrorCategory)&&!(e.lastErrorCategory===`quota_exhausted`&&r)?(0,Q.jsx)(W,{tone:`warn`,title:e.lastError??e.lastErrorCategory,children:Ft(e.lastErrorCategory,e.credentialKind)}):null,(0,Q.jsx)(sn,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]})}return e.status===`active`?(0,Q.jsxs)(Y,{gap:`4px`,children:[(0,Q.jsxs)(W,{tone:ln(e),dot:!0,children:[`Active`,cn(e)?` - ${cn(e)}`:``]}),Nt(e.lastErrorCategory)&&!(e.lastErrorCategory===`quota_exhausted`&&r)?(0,Q.jsx)(W,{tone:`warn`,title:e.lastError??e.lastErrorCategory,children:Ft(e.lastErrorCategory,e.credentialKind)}):null,(0,Q.jsx)(sn,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]}):e.status===`cooldown`||n?(0,Q.jsxs)(Y,{gap:`4px`,children:[(0,Q.jsxs)(W,{tone:`warn`,dot:!0,children:[`Cooldown`,cn(e)?` - ${cn(e)}`:``,` `,e.cooldownUntil?`(${We(e.cooldownUntil)})`:``]}),Nt(e.lastErrorCategory)&&!(e.lastErrorCategory===`quota_exhausted`&&r)?(0,Q.jsx)(W,{tone:`warn`,title:e.lastError??e.lastErrorCategory,children:Ft(e.lastErrorCategory,e.credentialKind)}):null,(0,Q.jsx)(sn,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]}):(0,Q.jsx)(W,{tone:`disabled`,children:`Disabled`})}function dn({windows:e}){if(e===void 0||e.length===0)return null;let t=0,n=0,r=!1,i=null;for(let a of e){if(a.accounting!==`pooled`){typeof a.remainingPercent==`number`&&Number.isFinite(a.remainingPercent)&&(i=i===null?a.remainingPercent:Math.min(i,a.remainingPercent));continue}let e=typeof a.limit==`number`&&Number.isFinite(a.limit)?a.limit:null,o=typeof a.remaining==`number`&&Number.isFinite(a.remaining)?a.remaining:e!==null&&typeof a.used==`number`&&Number.isFinite(a.used)?e-a.used:null;o!==null&&e!==null&&(t+=Math.max(0,o),n+=e,r=!0)}let a=null;return r?a=`${fn(t)} of ${fn(n)}`:i!==null&&(a=`${Math.round(i)}% left`),a===null?null:(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,"data-tone":r&&t<=0||(i??100)<=10?`warn`:void 0,title:r?`${fn(t)} credits available of ${fn(n)}`:`Lowest remaining percent across this account's quota windows`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Quota`}),a]})}function fn(e){return e.toLocaleString(void 0,{maximumFractionDigits:1})}function pn({providerId:e,account:t,onClose:n}){let r=he(),[i,a]=(0,Z.useState)(``),o=t.label||t.id.slice(0,8),s=r.isPending,c=i.trim().length>0&&!s,l=async()=>{try{a(await navigator.clipboard.readText())}catch{y.error(`Clipboard access denied`)}};return(0,Q.jsx)(P,{open:!0,onClose:n,title:`Replace API key — ${o}`,width:560,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(v,{variant:`secondary`,size:`sm`,onClick:n,disabled:s,children:`Cancel`}),(0,Q.jsx)(v,{size:`sm`,variant:`primary`,disabled:!c,onClick:()=>{let a=i.trim();a&&r.mutate({providerId:e,accountId:t.id,request:{secret:a}},{onSuccess:()=>{y.success(`API key replaced`,o),n()},onError:e=>{let t=e instanceof Error?e.message:`Unable to update account`;y.error(`Failed to replace key`,t)}})},children:s?`Saving…`:`Replace key`})]}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(`p`,{className:`m-0 text-caption text-text-secondary`,children:`Paste the new key for this account. The old key stops working immediately; the account keeps its label, history, and routing.`}),(0,Q.jsxs)(J,{gap:`6px`,className:`min-w-0`,children:[(0,Q.jsx)(`label`,{className:`text-caption font-semibold text-text-secondary`,children:`New API key`}),(0,Q.jsx)(`textarea`,{value:i,onChange:e=>a(e.target.value),placeholder:`Paste the replacement key…`,rows:4,spellCheck:!1,autoFocus:!0,className:`font-mono tabular-nums w-full min-w-0 min-h-65 rounded-control border border-inner-border bg-input-bg px-6 py-5 text-caption text-text-primary resize-y box-border`}),(0,Q.jsx)(Y,{gap:`8px`,className:`justify-end`,children:(0,Q.jsx)(v,{variant:`secondary`,size:`sm`,onClick:()=>void l(),children:`Paste`})})]})]})})}function mn({providerId:e,account:t,inflight:n,quota:r,selected:a,onToggleSelect:o,onDelete:s}){let c=he(),l=Ne(),u=Ye(t.id),d=t.status===`disabled`,f=t.cooldownUntil?new Date(t.cooldownUntil).getTime():NaN,p=Number.isFinite(f)&&f>Date.now(),m=t.status===`cooldown`||p,[g,_]=(0,Z.useState)(!1),[x,S]=(0,Z.useState)(!1),[,C]=(0,Z.useState)(0),[w,T]=(0,Z.useState)(!1),[E,D]=(0,Z.useState)(``),O=Ze(e),k=(t.label?.match(/[^\s@]+@[^\s@]+/)?.[0]??t.label)||t.id.slice(0,8),A=O.enabled?`Mysterious accounts`:k,j=on(t.tokenExpiresAt),N=Qe(t),ee=Math.max(p&&t.cooldownUntil?f:0,N??0);(0,Z.useEffect)(()=>{if(ee<=Date.now())return;let e=setInterval(()=>C(e=>e+1),1e3);return()=>clearInterval(e)},[ee]);let P=()=>{let n=E.trim();T(!1),n&&n!==(t.label??``)&&c.mutate({providerId:e,accountId:t.id,request:{label:n}},{onSuccess:()=>y.success(`Account renamed`,n),onError:e=>y.error(`Rename failed`,e.message??`Unable to rename account`)})};return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`account-row account-row-grid grid items-center gap-5 px-5 py-4 border rounded-control bg-surface-2 ${a?`border-accent`:`border-inner-border`} hover:bg-hover`,role:`listitem`,"data-selected":a?`true`:void 0,style:{opacity:d?.62:1},children:[(0,Q.jsx)(`div`,{className:`flex items-center`,children:(0,Q.jsx)(`input`,{type:`checkbox`,checked:a,onChange:e=>o(t.id,e.target.checked),"aria-label":`Select ${A}`,className:`cursor-pointer`})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex flex-col gap-1.5`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-3 min-w-0`,children:w?(0,Q.jsx)(G,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&P(),e.key===`Escape`&&T(!1)},onBlur:P,autoFocus:!0,"aria-label":`Account label`,className:`text-body max-w-120`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`text-body font-semibold text-text-primary min-w-0 overflow-hidden text-ellipsis whitespace-nowrap`,title:t.label||t.id,children:A}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 grid place-items-center w-10 h-10 p-0 border-0 bg-transparent text-text-tertiary cursor-pointer rounded-tiny hover:bg-inner-border hover:text-text-primary`,title:`Rename account`,"aria-label":`Rename ${A}`,onClick:()=>{D(t.label??``),T(!0)},children:(0,Q.jsx)(te,{size:11})})]})}),(0,Q.jsxs)(`div`,{className:`flex items-center flex-nowrap gap-2 min-w-0 overflow-hidden`,children:[(0,Q.jsx)(un,{account:t}),j?(0,Q.jsx)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:j,children:j}):null]}),(0,Q.jsxs)(`div`,{className:`flex items-center flex-wrap gap-2 min-w-0`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Today: ${t.usageToday.totalTokens.toLocaleString()} tokens, ${t.usageToday.requests.toLocaleString()} requests`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Today`}),t.usageToday.totalTokens.toLocaleString(),` tok · `,t.usageToday.requests.toLocaleString(),` req`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Lifetime totals are backfilled from telemetry still retained when tracking starts; new totals survive telemetry cleanup.`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`All time`}),t.usageAllTime.totalTokens.toLocaleString(),` tok · `,t.usageAllTime.requests.toLocaleString(),` req`]}),(0,Q.jsx)(dn,{windows:r}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Concurrency comes from this provider’s Routing Strategy; accounts no longer carry manual ceilings.`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`In flight`}),n?.toLocaleString()??`—`]})]})]}),(0,Q.jsxs)(`div`,{className:`account-row-actions flex items-center justify-end gap-3 flex-wrap`,children:[(0,Q.jsx)(v,{size:`icon`,variant:`secondary`,icon:(0,Q.jsx)(i,{size:12}),label:`Health`,"aria-label":`Health for ${A}`,onClick:()=>_(!0),title:`View Health & Error History`}),(0,Q.jsx)(v,{size:`icon`,variant:`secondary`,icon:u.isPending?(0,Q.jsx)(h,{size:12,className:`animate-spin`}):(0,Q.jsx)(b,{size:12}),label:u.isPending?`Testing…`:`Test`,"aria-label":`Test ${A}`,disabled:u.isPending,onClick:()=>{u.mutate(void 0,{onSuccess:e=>{e?.ok?y.success(`Account test passed`,A):y.error(`Account test failed`,e?.message??`Provider reported an error`)},onError:e=>y.error(`Account test failed`,e.message??`Unable to test account`)})},title:`Refresh quota and health for this account`}),(0,Q.jsx)(v,{size:`icon`,variant:`secondary`,icon:(0,Q.jsx)(M,{size:12}),label:`Edit key`,"aria-label":`Replace API key for ${A}`,onClick:()=>S(!0),title:`Replace API key`}),(0,Q.jsx)(v,{size:`icon`,variant:`secondary`,icon:d?(0,Q.jsx)(at,{size:12}):(0,Q.jsx)(re,{size:12}),label:d?`Enable`:`Disable`,"aria-label":d?`Enable ${A}`:`Disable ${A}`,disabled:c.isPending,onClick:()=>{let n=d;c.mutate({providerId:e,accountId:t.id,request:{status:n?`active`:`disabled`}},{onSuccess:()=>y.success(n?`Account enabled`:`Account disabled`,A),onError:e=>y.error(`Update failed`,e.message??`Unable to update account`)})},title:d?`Enable account`:`Disable account`}),m?(0,Q.jsx)(v,{size:`icon`,variant:`secondary`,icon:(0,Q.jsx)(F,{size:12,className:l.isPending?`animate-spin`:``}),label:l.isPending?`Recovering…`:`Recover`,"aria-label":`Recover ${A}`,disabled:l.isPending,onClick:()=>l.mutate({providerId:e,accountId:t.id}),title:`Clear cooldown / restore active status`}):null,(0,Q.jsx)(v,{size:`icon`,variant:`danger`,icon:(0,Q.jsx)(oe,{size:12}),label:`Delete`,"aria-label":`Delete ${A}`,onClick:()=>s(t),title:`Delete account`})]})]}),g&&(0,Q.jsx)(Xe,{summary:{providerId:e,accountId:t.id,title:t.label||t.id.slice(0,8),status:t.status,errorCategory:t.lastErrorCategory??void 0,errorMessage:t.lastError??void 0,emptyMessage:`Status transitions, rate limits, and auto-recoveries will appear here.`,staticToken:t.staticToken===!0,credentialKind:t.credentialKind,credentialMode:t.credentialMode},onClose:()=>_(!1)}),x&&(0,Q.jsx)(pn,{providerId:e,account:t,onClose:()=>S(!1)})]})}var hn=[{value:`added-asc`,label:`Added · oldest`},{value:`added-desc`,label:`Added · newest`},{value:`label-asc`,label:`Name · A–Z`},{value:`label-desc`,label:`Name · Z–A`},{value:`status-asc`,label:`Status · active first`},{value:`status-desc`,label:`Status · disabled first`},{value:`lastCheck-desc`,label:`Last check · newest`},{value:`lastCheck-asc`,label:`Last check · oldest`}];function gn(e,t,n){let r=(e,t)=>(e.label||e.id).localeCompare(t.label||t.id)||e.createdAt.localeCompare(t.createdAt)||e.id.localeCompare(t.id);if(n===`added`)return e.sortIndex-t.sortIndex||e.createdAt.localeCompare(t.createdAt)||e.id.localeCompare(t.id);if(n===`label`)return r(e,t);if(n===`status`){let n=an(e.status)-an(t.status);return n===0?r(e,t):n}let i=new Date(e.lastSuccessAt??e.createdAt).getTime();return new Date(t.lastSuccessAt??t.createdAt).getTime()-i||r(e,t)}function _n({providerId:e,accounts:t,onDelete:n,showGrokProbe:r=!1,grokProbePending:i=!1,onGrokProbe:a}){let o=ce(),s=he(),c=Ne(),l=De(),u=Ke(e).data??new Map,d=Je(),f=(0,Z.useMemo)(()=>{let t=new Map;for(let n of d.data?.accounts??[])n.provider===e&&n.quota&&t.set(n.id,n.quota.windows);return t},[d.data,e]),[p,m]=(0,Z.useState)(``),[h,g]=(0,Z.useState)(new Set),[_,x]=(0,Z.useState)(`added-asc`),[S,w]=(0,Z.useState)(!1),[T,E]=(0,Z.useState)(null),[D,O]=(0,Z.useState)(!1),[k,A]=(0,Z.useState)(!1),j=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{if(!k)return;let e=e=>{j.current&&!j.current.contains(e.target)&&A(!1)},t=e=>{e.key===`Escape`&&A(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[k]);let M=p.trim().toLowerCase(),N=(0,Z.useMemo)(()=>M?t.filter(e=>{let t=`${e.label??``} ${e.id} ${e.credentialKind} ${e.status}`.toLowerCase();return M.split(/\s+/).every(e=>t.includes(e))}):t,[t,M]),ee=(0,Z.useMemo)(()=>{let e=_.slice(0,_.lastIndexOf(`-`)),t=_.endsWith(`-desc`)?-1:1,n=[...N];return n.sort((n,r)=>t*gn(n,r,e)),n},[N,_]),P=(0,Z.useMemo)(()=>t.filter(e=>h.has(e.id)),[t,h]),te=N.length>0&&N.every(e=>h.has(e.id)),ne=P.some(e=>e.status===`disabled`),ie=P.some(e=>e.status!==`disabled`),se=P.length===0,ue=(e,t)=>{g(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},de=()=>{g(e=>{let t=new Set(e);if(te)for(let e of N)t.delete(e.id);else for(let e of N)t.add(e.id);return t})},fe=async(e,t)=>{if(P.length===0)return;w(!0);let n=await Promise.allSettled(P.map(e=>t(e))),r=n.filter(e=>e.status===`rejected`).length,i=n.length-r;w(!1),r===0?y.success(`${e} complete`,`${i} account${i===1?``:`s`}`):y.error(`${e} partially failed`,`${i} succeeded, ${r} failed`)},pe=()=>fe(`Recover`,t=>c.mutateAsync({providerId:e,accountId:t.id})),ge=async()=>{t.length!==0&&(w(!0),E({done:0,total:t.length}),await It(t,3,async(e,n)=>{let r=await le(`/accounts/${encodeURIComponent(e.id)}/quota/refresh`,{method:`POST`});return E({done:n+1,total:t.length}),r}),await Promise.all([o.invalidateQueries({queryKey:I.quota.all}),o.invalidateQueries({queryKey:I.providers.all})]),w(!1),E(null),y.success(`Test complete`,`${t.length} account${t.length===1?``:`s`} tested`))},_e=t=>fe(t?`Enable`:`Disable`,n=>s.mutateAsync({providerId:e,accountId:n.id,request:{status:t?`active`:`disabled`}})),ve=async()=>{if(P.length!==0){w(!0);try{let t=await l.mutateAsync({providerId:e,accountIds:P.map(e=>e.id)}),n=new Date().toISOString().replace(/[:.]/g,`-`);Le(`${e}-accounts-${n}.json`,JSON.stringify(t,null,2),`application/json`),y.success(`Accounts exported`,`${t.accounts.length} account${t.accounts.length===1?``:`s`} — contains plaintext credentials`)}catch(e){y.error(`Export failed`,e.message??`Unable to export accounts`)}finally{w(!1)}}};return(0,Q.jsxs)(J,{gap:`8px`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2 p-3 border border-inner-border rounded-control bg-surface-2`,children:[(0,Q.jsxs)(`label`,{className:`relative min-w-20 flex-[1_1_10rem]`,children:[(0,Q.jsx)(ae,{size:13,"aria-hidden":`true`,className:`pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-text-tertiary`}),(0,Q.jsx)(G,{id:`accounts-search`,value:p,onChange:e=>m(e.target.value),placeholder:`Search accounts...`,"aria-label":`Search accounts`,className:`pl-9`})]}),(0,Q.jsx)(v,{size:`sm`,variant:`primary`,icon:(0,Q.jsx)(b,{size:12}),disabled:S||t.length===0,onClick:ge,"aria-label":T===null?`Test all accounts`:`Testing accounts, ${T.done} of ${T.total} tested`,title:`Test every account, regardless of selection or filters`,children:T===null?`Test all`:`Tested ${T.done}/${T.total}`}),(0,Q.jsxs)(`div`,{ref:j,className:`relative`,children:[(0,Q.jsxs)(v,{size:`sm`,variant:`secondary`,disabled:S||se,"aria-expanded":k,"aria-haspopup":`menu`,"aria-label":se?`Select accounts to enable bulk actions`:`Bulk actions for ${P.length} selected accounts`,onClick:()=>A(e=>!e),children:[`Actions`,se?``:` (${P.length})`,(0,Q.jsx)(xe,{size:12,"aria-hidden":`true`,className:`transition-transform ${k?`rotate-180`:``}`})]}),k&&!se?(0,Q.jsxs)(`div`,{role:`menu`,"aria-label":`Selected account actions`,className:`absolute left-0 top-full z-50 mt-1 flex w-64 popover-max flex-col gap-1 rounded-control border border-inner-border bg-popover-bg p-2 shadow-popout sm:left-auto sm:right-0`,children:[(0,Q.jsx)(v,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,icon:(0,Q.jsx)(F,{size:12}),disabled:S,onClick:()=>{A(!1),pe()},children:`Recover`}),ne?(0,Q.jsx)(v,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,icon:(0,Q.jsx)(at,{size:12}),disabled:S,onClick:()=>{A(!1),_e(!0)},children:`Enable`}):null,ie?(0,Q.jsx)(v,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,icon:(0,Q.jsx)(re,{size:12}),disabled:S,onClick:()=>{A(!1),_e(!1)},children:`Disable`}):null,(0,Q.jsx)(v,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,icon:(0,Q.jsx)(C,{size:12}),disabled:S,onClick:()=>{A(!1),ve()},children:`Export JSON`}),(0,Q.jsx)(v,{role:`menuitem`,size:`sm`,variant:`danger`,className:`w-full justify-start`,icon:(0,Q.jsx)(oe,{size:12}),disabled:S,onClick:()=>{A(!1),O(!0)},children:`Delete`}),(0,Q.jsx)(v,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,disabled:S,onClick:()=>{g(new Set),A(!1)},children:`Clear selection`})]}):null]}),(0,Q.jsx)(`label`,{className:`inline-flex h-15 shrink-0 items-center gap-2 text-caption font-semibold text-text-secondary [&_.radix-select-trigger]:font-semibold [&_.radix-select-trigger]:bg-hover [&_.radix-select-trigger]:text-text-primary`,children:(0,Q.jsx)(K,{size:`sm`,value:_,onValueChange:e=>x(e),options:hn,"aria-label":`Sort accounts by`})}),(0,Q.jsxs)(`label`,{className:`inline-flex h-15 shrink-0 items-center gap-2 text-caption font-semibold text-text-secondary`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:te,onChange:de,"aria-label":`Select accounts`}),(0,Q.jsx)(`span`,{children:`Select`})]}),r?(0,Q.jsx)(v,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(b,{size:12,className:i?`animate-spin`:``}),disabled:i||t.length===0,onClick:a,title:`Probe every Grok account with the live 407 streaming request`,children:i?`Testing…`:`Test 407`}):null]}),(0,Q.jsx)(`div`,{className:`account-list flex flex-col gap-3 max-h-230 overflow-y-auto pr-1 [container-type:inline-size] [container-name:account-list]`,role:`list`,"aria-label":`Provider accounts`,children:ee.map(t=>(0,Q.jsx)(mn,{providerId:e,account:t,inflight:u.get(t.id)??t.inflight,quota:f.get(t.id),selected:h.has(t.id),onToggleSelect:ue,onDelete:n},t.id))}),(0,Q.jsx)(`div`,{className:`flex items-center justify-between text-badge text-text-tertiary`,children:(0,Q.jsxs)(`span`,{children:[`Showing `,N.length,` account`,N.length===1?``:`s`,M?` (filtered from ${t.length})`:``]})}),(0,Q.jsx)(me,{open:D,onClose:()=>{S||O(!1)},onConfirm:async()=>{await fe(`Delete`,async e=>{let t=e.tenantId===null?`/global/accounts/${encodeURIComponent(e.id)}`:`/accounts/${encodeURIComponent(e.id)}`;await le(t,{method:`DELETE`}),o.removeQueries({queryKey:I.quota.account(e.id),exact:!0})}),g(new Set),O(!1),await Promise.all([o.invalidateQueries({queryKey:I.providers.accounts(e)}),o.invalidateQueries({queryKey:I.providers.all}),o.invalidateQueries({queryKey:I.quota.all})])},title:`Delete ${P.length} account${P.length===1?``:`s`}?`,message:`This permanently removes the selected accounts and their credentials. This cannot be undone.`,confirmLabel:`Delete`,danger:!0})]})}var vn=2097152,yn=vn/1048576;function bn({providerId:e,accounts:t,onClose:n}){let r=be(),i=ke(),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(!1),[d,f]=(0,Z.useState)(`auto`),p=tn(s),m=p.length>1,h=p.length===1?p[0]:void 0,_=d===`auto`?h?.kind:d,b=h&&_===`jwt`?qt(h.value):void 0,x=t.map(e=>e.label),S=m?rn(p,e,x):[],C=e=>{let t=d===`auto`?e.kind===`jwt`?`jwt`:`auto`:d;return{credentialKind:t===`auto`&&e.kind===`oauth`?`oauth`:`api_key`,credentialMode:t,secret:e.value}},w=r.isPending||l,T=async()=>{try{let e=await navigator.clipboard.readText();c(e);let t=tn(e);if(t.length>1)y.success(`Pasted from clipboard`,`Detected ${t.length} credentials`);else{let e=t[0]?.kind??`api_key`,n=e===`oauth`?`OAuth export`:e===`jwt`?`Static JWT`:`API key`;y.success(`Pasted from clipboard`,`Detected: ${n}`)}}catch{y.error(`Clipboard access denied`)}},E=e=>{if(e.size>vn){y.error(`File too large`,`Credential files must be ${yn} MB or smaller.`);return}let t=new FileReader;t.onload=()=>{let n=typeof t.result==`string`?t.result:``;c(n);let r=tn(n);if(r.length===0){y.error(`Nothing to import`,`That file held no credential the gateway recognises.`);return}y.success(`Imported ${e.name}`,r.length>1?`Detected ${r.length} credentials`:r[0]?.kind===`oauth`?`Detected: OAuth export`:`Detected: API key`)},t.onerror=()=>y.error(`Could not read that file`),t.readAsText(e)},D=async()=>{if(p.length!==0){if(p.length===1){let t=p[0];r.mutate({providerId:e,request:{label:(a.trim()||t.identity)??void 0,...C(t)}},{onSuccess:()=>{y.success(`Account connected`,`New ${t.kind===`oauth`?`OAuth`:t.kind===`jwt`?`Static JWT`:`API key`} account registered successfully`),n()},onError:e=>y.error(`Failed to add account`,e.message??`Invalid credentials`)});return}u(!0);try{let t=await i.mutateAsync({providerId:e,accounts:p.map((e,t)=>({label:S[t],...C(e)}))}),r=t.results.filter(e=>!e.ok),a=t.created;if(a>0&&y.success(`${a} account${a===1?``:`s`} added`,r.length>0?`${r.length} skipped`:void 0),r.length>0){let e=r.slice(0,5).map(e=>`${S[e.index]??e.index}: ${e.error??`rejected`}`).join(`
|
|
2
|
-
`);y.error(`${r.length} account${r.length===1?``:`s`} skipped`,e+(r.length>5?`\n…and ${r.length-5} more`:``))}a>0&&n()}finally{u(!1)}}};return(0,Q.jsx)(P,{open:!0,onClose:n,title:`Add Account (API key / JSON)`,width:560,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(v,{variant:`secondary`,size:`sm`,onClick:n,disabled:w,children:`Cancel`}),(0,Q.jsx)(v,{size:`sm`,variant:`primary`,disabled:w||p.length===0,onClick:()=>void D(),children:w?`Connecting...`:m?`Add ${p.length} Accounts`:`Add Account`})]}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[!m&&(0,Q.jsx)(G,{label:`Account label (optional)`,value:a,onChange:e=>o(e.target.value),placeholder:h?.identity??`${e} account`}),(0,Q.jsx)(K,{label:`Credential type`,id:`credential-mode`,value:d,onValueChange:e=>f(e===`jwt`||e===`api_key`?e:`auto`),options:[{value:`auto`,label:`Auto — detect JWT, OAuth, or API key`},{value:`jwt`,label:`JWT — static, no refresh`},{value:`api_key`,label:`API key — do not decode as JWT`}]}),(0,Q.jsxs)(J,{gap:`6px`,className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Q.jsx)(`label`,{className:`text-caption font-semibold text-text-secondary`,children:`API key, OAuth token, or exported JSON — one or many`}),m?(0,Q.jsxs)(W,{tone:`accent`,children:[`Detected: `,p.length,` accounts`]}):h?(0,Q.jsxs)(W,{tone:_===`oauth`||_===`jwt`?`accent`:`default`,children:[`Detected:`,` `,_===`oauth`?`OAuth`:_===`jwt`?`Static JWT`:`API key`,h.identity?` · ${h.identity}`:``]}):null,h&&_===`jwt`?(0,Q.jsxs)(`p`,{className:`text-micro text-text-tertiary`,children:[`Static JWT · no refresh token`,b?` · expires ${new Date(b).toLocaleString()}`:` · no expiry claim`]}):null]}),(0,Q.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),placeholder:`Paste one credential, or many — one per line, a JSON array, or newline-delimited OAuth exports. Kind and account naming are detected automatically…`,rows:6,spellCheck:!1,className:`font-mono tabular-nums w-full min-w-0 min-h-65 rounded-control border border-inner-border bg-input-bg px-6 py-5 text-caption text-text-primary resize-y box-border`}),(0,Q.jsxs)(Y,{gap:`8px`,className:`justify-end`,children:[(0,Q.jsx)(v,{variant:`secondary`,size:`sm`,onClick:()=>void T(),children:`Paste`}),(0,Q.jsxs)(`label`,{className:g({size:`sm`,className:`cursor-pointer`}),children:[(0,Q.jsx)(`input`,{type:`file`,accept:`.json,.txt,.jsonl,.ndjson,application/json,text/plain`,"aria-label":`Import credentials from a file`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&E(t)}}),`Import file`]})]})]}),m&&(0,Q.jsx)(`div`,{className:`flex flex-col gap-2 max-h-75 overflow-y-auto rounded-control border border-inner-border bg-surface-2 px-4 py-5`,children:p.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4 text-badge`,children:[(0,Q.jsx)(`span`,{className:`truncate min-w-0`,children:S[t]}),(0,Q.jsx)(W,{tone:e.kind===`oauth`?`accent`:`default`,children:e.kind===`oauth`?`OAuth`:`API key`})]},t))})]})})}function xn(e){let t=e.trim(),n=e=>{try{return new URL(e).searchParams}catch{return}},r=n(t)??new URLSearchParams(t.startsWith(`?`)?t.slice(1):t),i=r.get(`code`);if(i)return{code:i};let a=r.get(`error_description`)??r.get(`error`);return a?{error:`The provider refused the login: ${a}`}:r.has(`authCodeInfo`)||r.has(`refreshToken`)||r.has(`refresh_token`)?{code:r.toString()}:n(t)!==void 0||t.startsWith(`?`)?{error:`That redirect URL carries no authorization code — copy the full URL from the address bar.`}:{code:t}}function Sn({providerId:e,authorizeUrl:t,state:n,popup:r,onClose:i}){let[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(``),l=je(),d=et(),f=ce(),p=Oe(e),m=(0,Z.useRef)(null),g=(0,Z.useRef)(!1);(0,Z.useEffect)(()=>{let t=setInterval(()=>{f.invalidateQueries({queryKey:I.providers.accounts(e)})},1500);return()=>clearInterval(t)},[f,e]),(0,Z.useEffect)(()=>{let e=p.data?.map(e=>e.id)??null;if(e!==null){if(m.current===null){m.current=new Set(e);return}g.current||e.find(e=>!m.current.has(e))!==void 0&&(g.current=!0,r.close(),y.success(`Account connected`,`OAuth login completed successfully`),i(!0))}},[p.data,r,i]);let _=()=>{r.close(),i(!1)},[b,x]=(0,Z.useState)(!1),C=()=>{x(!0),f.invalidateQueries({queryKey:I.providers.accounts(e)}).finally(()=>x(!1))},w=async()=>{try{let e=await navigator.clipboard.readText();if(!e.trim()){y.error(`Clipboard is empty`);return}c(e),y.success(`Pasted redirect URL`)}catch{y.error(`Clipboard unavailable on this origin`)}};return(0,Q.jsx)(P,{open:!0,onClose:_,title:`Connect via OAuth`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(v,{variant:`secondary`,size:`sm`,onClick:_,disabled:l.isPending,children:`Cancel`}),(0,Q.jsx)(v,{variant:`secondary`,size:`sm`,onClick:C,disabled:l.isPending||b,title:`You already approved in the popup — check now instead of waiting`,children:b?`Checking…`:`Complete`}),(0,Q.jsx)(v,{variant:`primary`,size:`sm`,disabled:l.isPending||s.trim().length===0,onClick:()=>{let t=xn(s);if(`error`in t){y.error(`OAuth callback failed`,t.error);return}l.mutate({providerId:e,code:t.code,state:n},{onSuccess:()=>{r.close(),y.success(`Account connected`,`OAuth login completed successfully`),i(!0)},onError:e=>y.error(`OAuth callback failed`,e.message??`Invalid or expired authorization code`)})},children:l.isPending?`Connecting…`:`Connect`})]}),children:(0,Q.jsxs)(J,{gap:`14px`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3.5 py-2.5 rounded-card border border-inner-border bg-surface-2`,children:[(0,Q.jsx)(h,{size:16,className:`animate-spin text-accent shrink-0`}),(0,Q.jsx)(`span`,{className:`text-body font-semibold`,children:`Waiting for popup authorization…`})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:`Step 1: Open this URL in your browser`}),(0,Q.jsxs)(Y,{gap:`8px`,children:[(0,Q.jsx)(`a`,{className:`min-w-0 flex-1 font-mono text-badge text-accent overflow-hidden text-ellipsis whitespace-nowrap px-2.5 py-2 rounded-control bg-input-bg border border-inner-border`,href:t,target:`_blank`,rel:`noreferrer`,title:t,children:t}),(0,Q.jsx)(v,{variant:`secondary`,size:`sm`,icon:a?(0,Q.jsx)(u,{size:12}):(0,Q.jsx)(S,{size:12}),onClick:()=>{navigator.clipboard?.writeText(t),o(!0),d(()=>o(!1),1500)},className:`shrink-0`,children:a?`Copied`:`Copy`})]}),(0,Q.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:`A popup should open automatically. If it was blocked, open the URL above manually.`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 text-micro font-bold uppercase tracking-label text-text-tertiary`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`flex-1 h-px bg-inner-border`}),(0,Q.jsx)(`span`,{children:`Or complete manually`}),(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`flex-1 h-px bg-inner-border`})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:`Step 2: Paste the redirect URL here`}),(0,Q.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:`If the redirect lands on an unreachable address, copy that page's full URL from your browser and paste it below — this works from any machine, not just localhost.`}),(0,Q.jsxs)(Y,{gap:`8px`,align:`flex-start`,children:[(0,Q.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),placeholder:`http://127.0.0.1:59653/callback?code=…&state=… (or just the code)`,rows:2,spellCheck:!1,className:`w-full min-h-16 resize-y rounded-control border border-inner-border bg-input-bg px-2.5 py-2 font-mono text-badge text-text-primary box-border focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-1 flex-1`}),(0,Q.jsx)(v,{variant:`secondary`,size:`sm`,onClick:()=>void w(),className:`shrink-0`,children:`Paste`})]})]})]})})}function Cn(e){try{return new URL(e).host}catch{return e}}function wn({providerId:e,parameters:t,onClose:n}){let r=_e(),i=Ce(),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(!1),[l,d]=(0,Z.useState)(!1),f=et();(0,Z.useEffect)(()=>{let i=!1;return r.mutate({providerId:e,...t===void 0||Object.keys(t).length===0?{}:{parameters:t}},{onSuccess:e=>{i||o(e)},onError:e=>{i||(y.error(`Failed to start device login`,e.message??`Unable to start device authorization`),n())}}),()=>{i=!0}},[]);let p=(0,Z.useRef)(null),[m,g]=(0,Z.useState)(!1);return(0,Z.useEffect)(()=>{if(!a)return;let e=window.open(a.verificationUri,`cartethyia-device`,`popup,width=720,height=820`);return e?p.current=e:g(!0),()=>{let e=p.current;p.current=null,e&&!e.closed&&e.close()}},[a]),(0,Z.useEffect)(()=>{if(!a)return;let t=Date.now(),r=Math.max(1,a.expiresInSeconds)*1e3,o=!1,s=Math.max(1,a.intervalSeconds)*1e3,c=!1,l=0,u=()=>window.clearTimeout(l),d=e=>{u(),l=window.setTimeout(f,e)},f=()=>{if(!c){if(Date.now()-t>r){u(),y.error(`Device login expired`,`Please try again.`),n();return}o||(o=!0,i.mutate({providerId:e,deviceAuthId:a.deviceAuthId},{onSuccess:e=>{if(o=!1,!c){if(e.status===`complete`){u();let e=p.current;e&&!e.closed&&e.close(),y.success(`OAuth account connected`,`Device authorization complete`),n()}else e.status===`failed`?(u(),y.error(`Device login failed`,e.reason),n()):e.status===`slow_down`?(s=(e.retryAfterSeconds===void 0?s+5e3:Math.max(1,e.retryAfterSeconds)*1e3)+1e3,d(s)):(e.status===`pending`&&e.retryAfterSeconds!==void 0&&(s=Math.max(1,e.retryAfterSeconds)*1e3+1e3),d(s))}},onError:()=>{o=!1,c||d(s)}}))}};return d(s+1e3),()=>{c=!0,u()}},[a]),(0,Q.jsx)(P,{open:!0,onClose:n,title:`Login with OAuth (device code)`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(v,{variant:`secondary`,size:`sm`,onClick:n,children:`Cancel`}),null]}),children:(0,Q.jsx)(J,{gap:`14px`,children:a?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3.5 py-2.5 rounded-card border border-inner-border bg-surface-2`,children:[(0,Q.jsx)(h,{size:16,className:`animate-spin text-accent shrink-0`}),(0,Q.jsx)(`span`,{className:`text-body font-semibold`,children:`Waiting for authorization…`})]}),a.userCode?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:`Step 1: Enter this code`}),(0,Q.jsxs)(`div`,{className:`rounded-card border border-inner-border bg-surface-2 p-3.5 flex flex-col gap-1.5 items-center text-center`,children:[(0,Q.jsx)(`div`,{className:`text-micro font-bold uppercase tracking-label text-text-tertiary`,children:`Device code`}),(0,Q.jsx)(`div`,{className:`font-mono text-display font-bold tracking-code text-text-primary`,children:a.userCode}),(0,Q.jsx)(v,{variant:`secondary`,size:`sm`,icon:l?(0,Q.jsx)(u,{size:12}):(0,Q.jsx)(S,{size:12}),onClick:()=>{navigator.clipboard?.writeText(a.userCode),d(!0),f(()=>d(!1),1500)},children:l?`Copied`:`Copy code`})]})]}):null,(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:a.userCode?`Step 2: Open the verification page`:`Open the verification page to authorize`}),(0,Q.jsxs)(Y,{gap:`8px`,children:[(0,Q.jsx)(`a`,{className:`min-w-0 flex-1 font-mono text-badge text-accent overflow-hidden text-ellipsis whitespace-nowrap px-2.5 py-2 rounded-control bg-input-bg border border-inner-border`,href:a.verificationUri,target:`_blank`,rel:`noreferrer`,title:a.verificationUri,children:Cn(a.verificationUri)}),(0,Q.jsx)(v,{variant:`primary`,size:`sm`,icon:(0,Q.jsx)(rt,{size:12}),onClick:()=>window.open(a.verificationUri,`_blank`,`noopener`),className:`shrink-0`,children:`Open`}),(0,Q.jsx)(v,{variant:`secondary`,size:`sm`,icon:s?(0,Q.jsx)(u,{size:12}):(0,Q.jsx)(S,{size:12}),onClick:()=>{navigator.clipboard?.writeText(a.verificationUri),c(!0),f(()=>c(!1),1500)},className:`shrink-0`,children:s?`Copied`:`Copy`})]}),(0,Q.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:m?`The popup was blocked — open the page with Open above, finish signing in there, then press Check now.`:`The page opened in a popup. Finish signing in there — this dialog closes automatically once the account connects, or press Check now.`})]})]}):(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3.5 py-2.5 rounded-card border border-inner-border bg-surface-2`,children:[(0,Q.jsx)(h,{size:16,className:`animate-spin text-accent shrink-0`}),(0,Q.jsx)(`span`,{className:`text-body font-semibold`,children:`Starting device authorization…`})]})})})}function Tn(e){let t={};for(let n of e)t[n.key]=n.defaultValue??``;return t}function En(e,t){return e.filter(e=>e.required===!0&&(t[e.key]??``).trim().length===0).map(e=>e.key)}function Dn({fields:e,values:t,onChange:n,idPrefix:r}){return e.length===0?null:(0,Q.jsx)(J,{gap:`10px`,children:e.map(e=>{let i=`${r}-${e.key}`,a=t[e.key]??``;return e.options&&e.options.length>0?(0,Q.jsx)(K,{id:i,label:e.label,value:a,onValueChange:t=>n(e.key,t),options:e.options.map(e=>({value:e.value,label:e.label}))},e.key):(0,Q.jsx)(G,{id:i,label:e.label,value:a,placeholder:e.placeholder??``,type:e.secret===!0?`password`:`text`,autoComplete:`off`,onChange:t=>n(e.key,t.target.value)},e.key)})})}function On({providerId:e,providerName:t,fields:n,onClose:r}){let i=Me(),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(()=>Tn(n)),d=(0,Z.useMemo)(()=>En(n,l),[n,l]);return(0,Q.jsx)(P,{open:!0,onClose:r,title:`Import a ${t} credential`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(v,{variant:`secondary`,size:`sm`,onClick:r,disabled:i.isPending,children:`Cancel`}),(0,Q.jsx)(v,{variant:`primary`,size:`sm`,onClick:()=>{if(a.trim().length===0){y.error(`Credential required`,`Paste the token, key or exported JSON to import.`);return}if(d.length>0){y.error(`Missing required fields`,`Fill in: ${d.join(`, `)}`);return}i.mutate({providerId:e,credential:a.trim(),...Object.keys(l).length>0?{fields:l}:{},...s.trim().length>0?{accountLabel:s.trim()}:{}},{onSuccess:()=>{y.success(`Account imported`,`The credential was validated and saved`),r()},onError:e=>y.error(`Import failed`,e.message??`The provider rejected this credential`)})},disabled:i.isPending,icon:i.isPending?(0,Q.jsx)(h,{size:13,className:`animate-spin`}):void 0,children:i.isPending?`Validating…`:`Import`})]}),children:(0,Q.jsxs)(J,{gap:`12px`,children:[(0,Q.jsxs)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:[`The credential is checked against `,t,` before it is saved, so one that no longer works is reported here instead of being stored.`]}),(0,Q.jsx)(Dn,{fields:n,values:l,idPrefix:`import`,onChange:(e,t)=>u(n=>({...n,[e]:t}))}),(0,Q.jsx)(G,{id:`import-account-label`,label:`Account label`,hint:`optional`,value:s,placeholder:e,onChange:e=>c(e.target.value)}),(0,Q.jsx)(G,{id:`import-credential`,label:`Credential`,value:a,placeholder:`Paste the token, key, or exported JSON`,type:`password`,autoComplete:`off`,onChange:e=>o(e.target.value)})]})})}function kn(e,t,n){let r=n?.trim()??``,i=r.indexOf(` — `),a=i>0?r.slice(0,i):``,o=i>0?r.slice(i+3):r;return{title:`${e}/${t} probe failed${a.length>0?` via ${a}`:``}`,detail:o.length>0?o:`Unknown error`}}function An(e,t,n){let{title:r,detail:i}=kn(e,t,n);return[r,i]}function jn(e){return e===`builtin`?`Built-in model`:e===`auto_free`?`Free tier, discovered from the provider`:e===`discovered`?`Fetched from provider`:`Added manually`}function Mn(e){return e===`auto_free`?`Free tier`:e===`discovered`?`Fetched`:`Manual`}var Nn=[{key:`builtin`,label:`Built-in models`,hint:`Compiled catalog — can be disabled, not deleted`,matches:e=>e===null||e===`builtin`},{key:`auto_free`,label:`Free models (auto)`,hint:`Discovered from the provider's free tier`,matches:e=>e===`auto_free`},{key:`manual`,label:`Manually added`,hint:`Added by hand from the Add Model dialog`,matches:e=>e===`manual`},{key:`fetched`,label:`Fetched from provider`,hint:`Listed by the provider's /v1/models`,matches:e=>e!==null&&e!==`builtin`&&e!==`auto_free`&&e!==`manual`}],Pn={key:`disabled`,label:`Disabled models`,hint:`Turned off — not routable until re-enabled`};function Fn(){return dt.map(e=>({value:e,label:e===`auto`?`Thinking: auto`:e.charAt(0).toUpperCase()+e.slice(1)}))}function In({value:e,onChange:t,disabled:n,id:r=`probe-thinking-effort`}){return(0,Q.jsx)(`div`,{title:`Reasoning effort every test in this section sends. Auto leaves the model's own reasoning default in place.`,className:`min-w-74 shrink-0`,children:(0,Q.jsx)(K,{id:r,"aria-label":`Thinking effort`,value:e,disabled:n,onValueChange:e=>t(e),options:Fn()})})}function Ln({providerId:e,provider:t,onClose:n}){let r=Ae(),i=Fe(),[a,o]=(0,Z.useState)(``),s=t?.supportedWireFamilies,c=t?.wireFamilyDefault!==void 0&&(s===void 0||s.includes(t.wireFamilyDefault))?t.wireFamilyDefault:s?.[0],l=(0,Z.useMemo)(()=>{let e=[`chat`,`responses`,`messages`],t=(s??[]).filter(t=>e.includes(t));return[...t,...e.filter(e=>!t.includes(e))]},[s]),[u,d]=(0,Z.useState)(c??`chat`),[f,p]=(0,Z.useState)(`auto`),[m,g]=(0,Z.useState)(`idle`),[_,x]=(0,Z.useState)(``),[S,C]=(0,Z.useState)(Vn),w=a.trim(),T=w.toLowerCase().startsWith(`${e.toLowerCase()}/`)&&w.length>e.length+1?w.slice(e.length+1):w,E=T!==w,D=()=>{T&&(g(`testing`),x(``),r.mutate({providerId:e,request:{modelId:T,wireFamily:u,reasoningEffort:f,serviceKind:`llm`}},{onSuccess:e=>{e.ok?g(`passed`):(g(`failed`),x(e.error??`Model probe failed`))},onError:e=>{g(`failed`),x(e.message??`Model probe failed`)}}))};return(0,Q.jsx)(P,{open:!0,onClose:n,title:`Add Custom Model`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(v,{variant:`secondary`,size:`sm`,onClick:n,disabled:i.isPending,children:`Cancel`}),(0,Q.jsx)(v,{variant:`primary`,size:`sm`,disabled:i.isPending||T.length===0,onClick:()=>{if(!T)return;let t=Re(S.contextLimit),r=Re(S.outputLimit);if(t===null||r===null){y.error(`Invalid limits`,`Use a token count such as 512k, 200000, or 1.5m.`);return}i.mutate({providerId:e,modelIds:[T],wireFamily:u,metadata:{contextLimit:t??null,outputLimit:r??null,passthrough:S.passthrough,image:S.passthrough?!0:S.image,reasoning:S.passthrough?!0:S.reasoning,toolCall:S.passthrough?!0:S.toolCall}},{onSuccess:()=>{y.success(`Custom model added`,`Sent to ${e}/${T}`),n()},onError:e=>y.error(`Failed to add model`,e.message??`Unable to register model`)})},children:i.isPending?`Adding...`:`Add Model`})]}),children:(0,Q.jsxs)(J,{gap:`10px`,children:[(0,Q.jsxs)(Y,{gap:`8px`,align:`flex-end`,children:[(0,Q.jsx)(G,{label:`Model ID`,autoFocus:!0,placeholder:`e.g. gpt-4o, free-model-id`,value:a,onChange:e=>{o(e.target.value),g(`idle`),x(``)},onKeyDown:e=>{e.key===`Enter`&&T.length>0&&D()},className:`flex-1`}),(0,Q.jsx)(v,{variant:`secondary`,size:`sm`,icon:m===`testing`?(0,Q.jsx)(h,{size:13,className:`animate-spin`}):(0,Q.jsx)(b,{size:13}),disabled:r.isPending||T.length===0,onClick:D,className:`shrink-0`,children:m===`testing`?`Testing...`:`Test`})]}),E&&(0,Q.jsxs)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Using `,(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:T}),` (provider prefix removed).`]}),(0,Q.jsx)(K,{label:`Wire family`,id:`add-model-wire-family`,value:u,onValueChange:e=>{d(e),g(`idle`),x(``)},options:l.map(e=>({value:e,label:qn(e)}))}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Thinking`}),(0,Q.jsx)(In,{id:`add-model-thinking-effort`,value:f,onChange:e=>{p(e),g(`idle`),x(``)},disabled:r.isPending}),(0,Q.jsx)(`div`,{className:`text-badge text-text-tertiary mt-2`,children:`Sent with the test. Auto leaves the model's own reasoning default in place.`})]}),(0,Q.jsx)(Hn,{draft:S,onChange:C,idPrefix:`add-model`,disabled:i.isPending}),s!==void 0&&!s.includes(u)&&(0,Q.jsxs)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:[`This provider does not declare the`,` `,(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:qn(u)}),` wire. The request is sent as chosen; the upstream decides whether it answers.`]}),m===`passed`&&(0,Q.jsx)(tt,{tone:`success`,live:`status`,children:`Model test passed — ready to add.`}),m===`failed`&&(0,Q.jsx)(tt,{tone:`danger`,live:`alert`,children:_||`Model test failed.`})]})})}function Rn(){return{contextLimit:``,outputLimit:``,passthrough:!1,image:!0,reasoning:!0,toolCall:!0}}var zn=String(Be),Bn=String(V);function Vn(){return{...Rn(),contextLimit:zn,outputLimit:Bn}}function Hn({draft:e,onChange:t,idPrefix:n,disabled:r=!1}){let i=e.passthrough;return(0,Q.jsxs)(J,{gap:`10px`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Limits`}),(0,Q.jsxs)(Y,{gap:`8px`,children:[(0,Q.jsx)(G,{label:`Context`,id:`${n}-context`,placeholder:zn,value:e.contextLimit,disabled:r,onChange:n=>t({...e,contextLimit:n.target.value}),className:`flex-1`}),(0,Q.jsx)(G,{label:`Output`,id:`${n}-output`,placeholder:Bn,value:e.outputLimit,disabled:r,onChange:n=>t({...e,outputLimit:n.target.value}),className:`flex-1`})]}),(0,Q.jsxs)(`label`,{className:`inline-flex items-center gap-2 mt-2 text-badge text-text-secondary cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,id:`${n}-fallback-limits`,checked:e.contextLimit===zn&&e.outputLimit===Bn,disabled:r,onChange:n=>t(n.target.checked?{...e,contextLimit:zn,outputLimit:Bn}:{...e,contextLimit:``,outputLimit:``})}),`Use fallback — `,ze(Be),` ctx ·`,` `,ze(V),` out`]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Capabilities`}),(0,Q.jsx)(J,{gap:`6px`,children:[[`image`,`Can image`,e.image],[`reasoning`,`Reasoning`,e.reasoning],[`toolCall`,`Tools`,e.toolCall]].map(([a,o,s])=>(0,Q.jsxs)(`label`,{className:`inline-flex items-center gap-2 text-badge text-text-secondary`,style:i?{opacity:.5}:void 0,children:[(0,Q.jsx)(`input`,{type:`checkbox`,id:`${n}-${a}`,checked:i?!0:s,disabled:r||i,onChange:n=>t({...e,[a]:n.target.checked})}),o]},a))}),(0,Q.jsxs)(`label`,{className:`inline-flex items-center gap-2 mt-2 text-badge text-text-secondary cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,id:`${n}-passthrough`,checked:e.passthrough,disabled:r,onChange:n=>t({...e,passthrough:n.target.checked})}),`Passthrough — accept every capability`]}),i?(0,Q.jsx)(`div`,{className:`text-badge text-text-tertiary mt-2`,children:`Passthrough grants all of the above, so they are locked on. Uncheck it to restore your own choices.`}):null]})]})}function Un({providerId:e,model:t,onClose:n}){let r=pe(),[i,a]=(0,Z.useState)(()=>({contextLimit:t.contextLimit?String(t.contextLimit):``,outputLimit:t.outputLimit?String(t.outputLimit):``,passthrough:!1,image:t.vision===!0,reasoning:t.reasoning===!0,toolCall:t.toolCall===!0}));return(0,Q.jsx)(P,{open:!0,onClose:n,title:`Edit Model`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(v,{variant:`secondary`,size:`sm`,onClick:n,disabled:r.isPending,children:`Cancel`}),(0,Q.jsx)(v,{variant:`primary`,size:`sm`,disabled:r.isPending,onClick:()=>{let a=Re(i.contextLimit),o=Re(i.outputLimit);if(a===null||o===null){y.error(`Invalid limits`,`Use a token count such as 512k, 200000, or 1.5m.`);return}r.mutate({providerId:e,modelId:t.modelId,route:t.route??``,metadata:{contextLimit:a??null,outputLimit:o??null,passthrough:i.passthrough,image:i.passthrough?!0:i.image,reasoning:i.passthrough?!0:i.reasoning,toolCall:i.passthrough?!0:i.toolCall}},{onSuccess:()=>n(),onError:e=>y.error(`Failed to update model`,e.message??`Unable to update model`)})},children:r.isPending?`Saving...`:`Save`})]}),children:(0,Q.jsxs)(J,{gap:`10px`,children:[(0,Q.jsxs)(`div`,{className:`text-badge text-text-tertiary`,children:[`Editing `,(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:t.modelId})]}),(0,Q.jsx)(Hn,{draft:i,onChange:a,idPrefix:`edit-model`,disabled:r.isPending})]})})}function Wn({providerId:e,model:t,serviceKind:n,searchCapable:r,thinkingEffort:i,onDeleteRequest:a,onEditRequest:c,deletePending:l}){let m=Ae(),g=L(),[_,C]=(0,Z.useState)(!1),[w,E]=(0,Z.useState)(null),D=et(),k=n===`llm`?ft(t.modelId,i===`auto`?null:i):t.modelId,A=`${e}/${k}`,j=n===`websearch`?`Searching…`:`Thinking…`,M=()=>{m.mutate({providerId:e,request:{modelId:t.modelId,route:t.route,...n===`llm`?{reasoningEffort:i}:{},serviceKind:n}},{onSuccess:t=>{if(E({ok:t.ok,latencyMs:t.latencyMs}),!t.ok){let{title:n,detail:r}=kn(e,k,t.error);y.error(n,r);return}let n=t.sample?.trim()??``,r=t.reportedModel?.trim()??``;y.successRich(`${k} · END ${U(t.latencyMs)}`,(0,Q.jsxs)(`span`,{className:`grid gap-2 min-w-0`,children:[r?(0,Q.jsxs)(Y,{gap:`6px`,align:`center`,className:`min-w-0`,children:[(0,Q.jsx)(x,{size:12,"aria-hidden":`true`,className:`shrink-0 text-text-tertiary`}),(0,Q.jsx)(`span`,{className:`truncate font-mono text-badge text-text-secondary`,title:r,children:r})]}):null,(0,Q.jsx)(`span`,{children:n||`No sample text in the response.`})]}),[r,n].filter(Boolean).join(`
|
|
3
|
-
`)||`No sample text in the response.`)},onError:t=>{E({ok:!1,latencyMs:0}),y.error(...An(e,k,t.message))}})},N=()=>{let n=!t.enabled;g.mutate({providerId:e,request:{modelId:t.modelId,route:t.route,enabled:n}},{onSuccess:()=>y.success(n?`Model enabled`:`Model disabled`,t.modelId),onError:e=>y.error(`Failed to update model`,e.message??`Unable to update model`)})};return(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(`div`,{className:`model-card box-border flex w-full min-w-0 flex-1-auto flex-col gap-5 rounded-panel border border-inner-border p-6 ${t.enabled?`bg-surface-2`:`bg-surface-1 opacity-72`}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-4 min-w-0`,children:[(0,Q.jsx)(`span`,{className:`inline-flex items-center justify-center w-13 h-13 rounded-inset bg-teal-soft text-teal shrink-0`,children:(0,Q.jsx)(o,{size:14})}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-col gap-1`,children:[(0,Q.jsx)(`div`,{title:A,className:`font-mono tabular-nums min-w-0 truncate text-caption font-semibold leading-[1.35]`,children:k}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 text-micro text-text-tertiary`,children:[(0,Q.jsx)(`span`,{title:`${t.wireFamily} · ${t.route??e}`,className:`shrink-0 rounded-tiny px-3.5 py-0.5 text-micro font-bold`,style:{...Kn(t.wireFamily)},children:qn(t.wireFamily)}),t.source!==null&&t.source!==`builtin`?(0,Q.jsx)(`span`,{title:jn(t.source),className:`shrink-0 rounded-pill border border-teal-soft px-3 py-0.5 text-micro font-bold tracking-[0.04em] text-teal`,children:Mn(t.source)}):null,t.proOnly===!0?(0,Q.jsx)(`span`,{title:`Refused on a free plan. Nothing in the provider's model directory predicts it, so this comes from a real dispatch: the upstream answers that the model is not allowed for a free user type.`,className:`shrink-0 rounded-tiny border border-orange bg-orange-soft px-3.5 py-0.5 text-micro font-bold uppercase tracking-[0.04em] text-orange`,children:`Pro`}):null,t.freeTier===!0&&t.source!==`auto_free`?(0,Q.jsx)(`span`,{title:`Free on this provider's plan. Taken from the provider's own model directory, not a hardcoded list, so it tracks plan changes.`,className:`shrink-0 rounded-pill border border-teal-soft px-3 py-0.5 text-micro font-bold text-teal`,children:`Free tier`}):null,t.enabled?null:(0,Q.jsx)(`span`,{className:`shrink-0 rounded-pill bg-red-soft px-3 py-0.5 text-micro font-bold tracking-[0.04em] text-red`,children:`Off`})]})]}),(0,Q.jsx)(v,{variant:`ghost`,size:`sm`,icon:_?(0,Q.jsx)(u,{size:12}):(0,Q.jsx)(S,{size:12}),"aria-label":`Copy ${A}`,title:`Copy ${A}`,onClick:()=>{navigator.clipboard?.writeText(A),C(!0),D(()=>C(!1),1500)},className:`shrink-0 p-2 opacity-70`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 text-badge text-text-secondary`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex gap-2.5`,children:[t.reasoning?(0,Q.jsx)(`span`,{title:`Reasoning`,"aria-label":`Reasoning`,className:`inline-flex text-purple`,children:(0,Q.jsx)(s,{size:12})}):null,t.vision?(0,Q.jsx)(`span`,{title:`Vision`,"aria-label":`Vision`,className:`inline-flex text-status-info`,children:(0,Q.jsx)(T,{size:12})}):null,t.toolCall?(0,Q.jsx)(`span`,{title:`Tool calling`,"aria-label":`Tool calling`,className:`inline-flex text-orange`,children:(0,Q.jsx)(se,{size:12})}):null,r?(0,Q.jsx)(`span`,{title:`Web search`,"aria-label":`Web search`,className:`inline-flex text-teal`,children:(0,Q.jsx)(p,{size:12})}):null]}),(0,Q.jsxs)(`span`,{className:`whitespace-nowrap`,children:[t.limitsEstimated?(0,Q.jsx)(`span`,{title:H,"aria-label":`Limits are a fallback estimate`,className:`estimate-dot inline-flex items-center justify-center rounded-full border border-inner-border bg-surface-2 text-orange cursor-help mr-1 align-middle`,children:(0,Q.jsx)(d,{size:9,"aria-hidden":`true`})}):null,t.contextLimit?`${ze(t.contextLimit)} ctx`:(0,Q.jsx)(`span`,{title:Ve,className:`cursor-help`,children:`n/a ctx`}),t.outputLimit?` · ${ze(t.outputLimit)} out`:(0,Q.jsx)(`span`,{title:Ve,className:`cursor-help`,children:` · n/a out`})]}),c?(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 grid place-items-center w-6 h-6 p-0 border-0 bg-transparent text-text-tertiary cursor-pointer rounded-tiny hover:bg-inner-border hover:text-text-primary`,title:`Edit limits and capabilities`,"aria-label":`Edit ${t.modelId} limits and capabilities`,onClick:()=>c(t),children:(0,Q.jsx)(te,{size:11})}):null]}),(0,Q.jsxs)(`div`,{className:`flex gap-3 items-center flex-wrap`,children:[(0,Q.jsx)(v,{variant:`secondary`,size:`sm`,disabled:m.isPending,onClick:M,"aria-label":`Test ${k}`,title:m.isPending?`Probing ${k}…`:w?.ok?`Last probe OK in ${U(w.latencyMs)} — click to re-test`:w?`Last probe failed — click to retry`:`Test ${k}`,className:`flex-1 justify-center`,icon:m.isPending?(0,Q.jsx)(h,{size:12,className:`animate-spin`}):w?w.ok?(0,Q.jsx)(`span`,{className:`inline-flex text-green`,children:(0,Q.jsx)(f,{size:12})}):(0,Q.jsx)(`span`,{className:`inline-flex text-red`,children:(0,Q.jsx)(O,{size:12})}):(0,Q.jsx)(b,{size:12}),children:m.isPending?j:w?.ok?U(w.latencyMs):w?`Fail`:`Test`}),(0,Q.jsx)(v,{variant:`ghost`,size:`sm`,disabled:g.isPending,onClick:N,icon:t.enabled?(0,Q.jsx)(re,{size:12}):(0,Q.jsx)(at,{size:12}),"aria-label":t.enabled?`Disable ${t.modelId}`:`Enable ${t.modelId}`,title:t.enabled?`Disable model`:`Enable model`,className:`flex-1 justify-center ${t.enabled?`text-red`:`text-green`}`,children:t.enabled?`Disable`:`Enable`}),t.source===`builtin`?null:(0,Q.jsx)(v,{variant:`ghost`,size:`sm`,disabled:l,onClick:()=>a(t),icon:(0,Q.jsx)(oe,{size:12}),"aria-label":`Delete ${t.modelId}`,title:`Delete model`,className:`model-card-delete shrink-0 px-4 py-3 text-text-tertiary`})]})]})})}var Gn=(0,Z.memo)(Wn);function Kn(e){return e===`responses`?{color:`var(--purple)`,background:`var(--purple-soft)`}:e===`messages`?{color:`var(--orange)`,background:`color-mix(in srgb, var(--orange) 14%, transparent)`}:{color:`var(--teal)`,background:`var(--teal-soft)`}}function qn(e){let t=e.toLowerCase();return t===`responses`?`Responses`:t===`messages`?`Messages`:`Chat`}function Jn({providerId:e,models:t,thinkingEffort:n,serviceKind:r=`llm`,searchCapable:i=!1}){let a=Se(),[o,s]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(null),u=e=>e.enabled!==!1,d=Nn.map(e=>({...e,rows:t.filter(t=>u(t)&&e.matches(t.source))})).filter(e=>e.rows.length>0),f=t.filter(e=>!u(e)),p=t=>(0,Q.jsx)(Gn,{providerId:e,model:t,serviceKind:r,searchCapable:i,thinkingEffort:n,deletePending:a.isPending,onDeleteRequest:s,onEditRequest:t.source===`builtin`?void 0:l},`${t.modelId}::${t.route}`);return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(J,{gap:`16px`,children:[d.map(e=>(0,Q.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-4 min-w-0`,children:[(0,Q.jsx)(`span`,{className:`text-caption font-bold text-text-secondary`,children:e.label}),(0,Q.jsx)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:e.rows.length}),(0,Q.jsxs)(`span`,{title:e.hint,className:`text-micro text-text-tertiary overflow-hidden truncate`,children:[`· `,e.hint]})]}),(0,Q.jsx)(`div`,{className:`provider-grid grid gap-4 items-stretch`,children:e.rows.map(p)})]},e.key)),f.length===0?null:(0,Q.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-4 min-w-0`,children:[(0,Q.jsx)(`span`,{className:`text-caption font-bold text-text-secondary`,children:Pn.label}),(0,Q.jsx)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:f.length}),(0,Q.jsxs)(`span`,{title:Pn.hint,className:`text-micro text-text-tertiary overflow-hidden truncate`,children:[`· `,Pn.hint]})]}),(0,Q.jsx)(`div`,{className:`provider-grid grid gap-4 items-stretch`,children:f.map(p)})]})]}),(0,Q.jsx)(me,{open:o!==null,onClose:()=>{a.isPending||s(null)},onConfirm:async()=>{o!==null&&(await a.mutateAsync({providerId:e,request:{modelId:o.modelId,route:o.route}}),y.success(`Model deleted`,`${e}/${o.modelId}`),s(null))},title:`Delete model?`,message:`Delete ${e}/${o?.modelId??``} from the provider catalog?`,confirmLabel:`Delete`,danger:!0}),c===null?null:(0,Q.jsx)(Un,{providerId:e,model:c,onClose:()=>l(null)})]})}function Yn(e){return e===`llm`?`LLM`:e===`websearch`?`Search`:e===`imageGeneration`?`Image`:e===`videoGeneration`?`Video`:e}function Xn(e){let t=e.serviceKinds;return Array.isArray(t)&&t.length>0?t:[`llm`]}function Zn(){let{providerId:e}=ge(),[t]=ue(),n=e??``,r=t.get(`service`),[i,a]=(0,Z.useState)(r===`websearch`||r===`imageGeneration`||r===`videoGeneration`?r:`llm`),o=Ee(n),s=Te(n),l=Oe(n),u=de(),d=de({silent:!0}),[f,m]=(0,Z.useState)(!1),h=we(),g=ve(),_=Pe(),b=ce(),[x,S]=(0,Z.useState)(!1),[w,T]=(0,Z.useState)(!1),E=Ae(),[O,N]=(0,Z.useState)(``),[ee,te]=(0,Z.useState)(``),[F,ae]=(0,Z.useState)(null),se=e=>`cartethyia:provider:${e}:thinking-effort`,fe=e=>{if(typeof window>`u`||!window.localStorage)return`auto`;let t=window.localStorage.getItem(se(e));if(t===null)return`auto`;let n=t.trim().toLowerCase();return dt.includes(n)?n:`auto`},[pe,he]=(0,Z.useState)(()=>fe(n));(0,Z.useEffect)(()=>{if(!n)return;let e=fe(n);e!==pe&&he(e)},[n]),(0,Z.useEffect)(()=>{typeof window>`u`||!window.localStorage||!n||window.localStorage.setItem(se(n),pe)},[n,pe]);let[_e,ye]=(0,Z.useState)(!1),[be,xe]=(0,Z.useState)(!1),[L,Se]=(0,Z.useState)(null),[Ce,De]=(0,Z.useState)({}),[ke,je]=(0,Z.useState)({}),[R,Me]=(0,Z.useState)(null),[Ne,Fe]=(0,Z.useState)(!1),[Le,Re]=(0,Z.useState)(null),V=(0,Z.useRef)(null),ze=(0,Z.useRef)(null);(0,Z.useEffect)(()=>()=>{let e=V.current;V.current=null,e&&!e.closed&&e.close()},[]);let H=o.data,Be=n===`opencode`||n===`cline`,Ve=H===void 0?[`llm`]:Xn(H),U=[];for(let e of Ve)(e===`llm`||e===`websearch`||e===`imageGeneration`||e===`videoGeneration`)&&U.push(e);(0,Z.useEffect)(()=>{if(H===void 0)return;let e=r===`websearch`||r===`imageGeneration`||r===`videoGeneration`||r===`llm`?r:void 0,t=U[0];if(e!==void 0&&U.includes(e)){i!==e&&a(e);return}!U.includes(i)&&t!==void 0&&a(t)},[H,r,i,U.join(`|`)]),(0,Z.useEffect)(()=>{Be&&H!==void 0&&H.supportsModelDiscovery!==!1&&ze.current!==n&&(ze.current=n,d.mutate(n))},[Be,d,n,H?.supportsModelDiscovery]);let W=l.data??[],G=s.data??[],K=(()=>{let e=new Map;for(let t of G){let n=`${t.serviceKind??`llm`}:${t.modelId}`,r=e.get(n);if(!r)e.set(n,t);else{let i=r.contextLimit??0;(t.contextLimit??0)>i&&e.set(n,t)}}return[...e.values()].sort((e,t)=>e.modelId.localeCompare(t.modelId))})(),q=K.filter(e=>e.serviceKind===`llm`||e.serviceKind===void 0),We=K.filter(e=>e.serviceKind===`websearch`),Ge=K.filter(e=>e.serviceKind===`imageGeneration`),Ke=K.filter(e=>e.serviceKind===`videoGeneration`),X=U.includes(i)?i:U[0],qe=ee||We[0]?.modelId||``,Je=()=>{let e=O.trim();qe&&e&&(ae(null),E.mutate({providerId:n,request:{modelId:qe,serviceKind:`websearch`,prompt:e}},{onSuccess:e=>ae({ok:e.ok,latencyMs:e.latencyMs,...e.searchResults?{results:e.searchResults,count:e.searchResults.length}:{},...e.error?{error:e.error}:{}}),onError:e=>ae({ok:!1,error:e instanceof Error?e.message:`Search test failed`})}))};if(o.isPending)return(0,Q.jsx)(A,{label:`Loading provider...`});if(o.isError)return(0,Q.jsx)(k,{title:`Unable to load providers`,message:`The provider details could not be read, so this page cannot resolve its endpoint settings.`,onRetry:()=>void o.refetch(),retrying:o.isFetching,action:(0,Q.jsx)(pt,{to:`/providers`,label:`Back to providers`})});if(!H)return(0,Q.jsx)(j,{icon:(0,Q.jsx)(ot,{size:20}),title:`Provider not found`,message:`No provider named “${n}”. It may have been removed, or the link is stale.`,action:(0,Q.jsx)(pt,{to:`/providers`,label:`Back to providers`})});let Ye=W.filter(e=>e.status===`active`).length,Xe=e=>{let t=e===`browser`?H?.oauthFlows?.browserLoginFields??[]:H?.oauthFlows?.deviceLoginFields??[];if(t.length===0){e===`browser`?Qe():ye(!0);return}De(Tn(t)),Se(e)},Ze=()=>{if(L===null)return;let e=En(L===`browser`?H?.oauthFlows?.browserLoginFields??[]:H?.oauthFlows?.deviceLoginFields??[],Ce);if(e.length>0){y.error(`Missing required fields`,`Fill in: ${e.join(`, `)}`);return}let t=L;Se(null),t===`browser`?Qe(Ce):(je(Ce),ye(!0))},Qe=e=>{let t=window.open(`about:blank`,`cartethyia-oauth`,`popup,width=720,height=820`);t&&(t.opener=null,V.current=t),_.mutate({providerId:n,...e===void 0?{}:{parameters:e}},{onSuccess:({authorizeUrl:e,state:n})=>{let r=null;if(t&&!t.closed?(t.location.href=e,r=t):(r=window.open(e,`cartethyia-oauth`,`popup,width=720,height=820`),r&&(r.opener=null,V.current=r)),!r){y.error(`Popup blocked`,`Allow popups to complete OAuth login.`);return}Re({authorizeUrl:e,state:n,popup:r})},onError:e=>{t&&!t.closed&&t.close(),V.current===t&&(V.current=null),y.error(`Failed to start OAuth`,e.message??`Unable to start authorization`)}})};return(0,Q.jsxs)(J,{gap:`16px`,children:[(0,Q.jsx)(mt,{title:`${H.label||H.displayName}${X?` (${Yn(X)})`:``}`,description:`${H.providerId}/${H.baseUrl?` · ${H.baseUrl}`:``}`,icon:(0,Q.jsx)(He,{icon:H.providerId,name:H.label||H.displayName,size:28}),back:{to:`/providers`,label:`Back to Providers`},actions:(0,Q.jsx)(Y,{gap:`8px`,className:`flex-wrap w-full max-w-full min-w-0`,children:H.isBuiltIn?(0,Q.jsx)(v,{variant:H.enabled?`danger`:`secondary`,icon:H.enabled?(0,Q.jsx)(re,{size:13}):(0,Q.jsx)(at,{size:13}),loading:g.isPending,onClick:()=>g.mutate({providerId:n,enabled:!H.enabled},{onSuccess:e=>y.success(e.enabled?`Provider enabled`:`Provider disabled`,H.label||H.displayName),onError:e=>y.error(`Provider update failed`,e.message??`Unable to change provider availability`)}),title:H.enabled?`Disable provider globally`:`Enable provider globally`,children:H.enabled?`Disable`:`Enable`}):null})}),(0,Q.jsx)(kt,{provider:H}),H.isBuiltIn?null:(0,Q.jsx)(At,{provider:H}),X===`llm`?(0,Q.jsx)(wt,{providerId:n,clientVersion:H.clientVersion,routeIdentityVersions:H.routeIdentityVersions,userAgentEditable:ht(H)}):null,(0,Q.jsx)(`div`,{id:`provider-accounts`,tabIndex:-1,children:H.requiresAccount===!1?(0,Q.jsxs)(B,{children:[(0,Q.jsx)(Ie,{title:`Accounts`,icon:(0,Q.jsx)(nt,{size:16})}),(0,Q.jsx)(z,{children:(0,Q.jsx)(`p`,{className:`text-caption text-text-secondary`,children:`This provider is a public, unauthenticated route — no account or credential is needed. Routing already works without any setup here.`})})]}):(0,Q.jsxs)(B,{children:[(0,Q.jsx)(Ie,{title:`Accounts`,subtitle:`${W.length} total · ${Ye} active · ${W.length-Ye} disabled`,icon:(0,Q.jsx)(nt,{size:16}),action:(0,Q.jsxs)(Ue,{children:[H.oauthFlows?.browser&&(0,Q.jsx)(v,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(rt,{size:13}),disabled:_.isPending,onClick:()=>Xe(`browser`),title:`Browser OAuth login — opens the provider authorize page in a popup`,children:_.isPending?`Starting...`:`Login with browser`}),H.oauthFlows?.device&&(0,Q.jsx)(v,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(M,{size:13}),onClick:()=>Xe(`device`),title:`Device-code login — enter the shown code on the provider site`,children:`Login with device code`}),H.oauthFlows?.import&&(0,Q.jsx)(v,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(C,{size:13}),onClick:()=>xe(!0),title:H.oauthFlows.browser||H.oauthFlows.device||H.oauthFlows.refreshable?`Import a credential you already hold — a refresh token, an exported auth blob, or an API key`:`Add and validate an API key`,children:H.oauthFlows.browser||H.oauthFlows.device||H.oauthFlows.refreshable?`Import credential`:`Add API key`}),(0,Q.jsx)(v,{variant:`primary`,size:`sm`,icon:(0,Q.jsx)(ne,{size:13}),onClick:()=>S(!0),children:`Add Account`})]})}),(0,Q.jsxs)(z,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(Tt,{providerId:n}),l.isPending?(0,Q.jsx)(A,{label:`Loading accounts...`}):l.isError?(0,Q.jsx)(k,{message:`Failed to load accounts`,onRetry:()=>l.refetch()}):W.length===0?(0,Q.jsx)(j,{title:`No accounts connected`,message:`Add an API key or OAuth credential to route requests to this provider.`}):(0,Q.jsx)(_n,{providerId:n,accounts:W,onDelete:e=>Me(e),showGrokProbe:X===`llm`&&n===`grok`,grokProbePending:h.isPending,onGrokProbe:()=>{h.mutate({providerId:n,request:{modelId:`grok-4.6`,prompt:`reply my message with exact number 407`,stream:!0,serviceKind:`llm`}},{onSuccess:e=>{let t=e.results.filter(e=>e.ok).length,n=e.results.filter(e=>e.statusCode===202).length,r=e.results.length-t-n;y.success(`Grok account probe complete`,`${t} passed · ${n} returned 202 and were parked in cooldown · ${r} other failures`)},onError:e=>y.error(`Grok account probe failed`,e.message??`Unable to probe Grok accounts`)})}})]})]})}),X===`llm`?(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(B,{children:[(0,Q.jsx)(Ie,{title:`Models`,subtitle:`${q.length} model${q.length===1?``:`s`} registered`,icon:(0,Q.jsx)(c,{size:16}),action:(0,Q.jsxs)(Y,{gap:`6px`,className:`flex-wrap items-center`,children:[(0,Q.jsx)(In,{id:`models-section-thinking-effort`,value:pe,onChange:he}),(0,Q.jsx)(v,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(ie,{size:13,className:u.isPending||d.isPending?`animate-spin`:``}),disabled:u.isPending||d.isPending,onClick:()=>u.mutate(n),children:u.isPending||d.isPending?`Fetching...`:`Fetch models`}),(0,Q.jsx)(v,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(oe,{size:13,className:f?`animate-spin`:``}),disabled:u.isPending||d.isPending||f||q.filter(e=>e.source!==`builtin`&&e.source!==null).length===0,onClick:async()=>{let e=q.filter(e=>e.source!==`builtin`&&e.source!==null);if(e.length!==0&&confirm(`Delete ${e.length} fetched/manual model(s) for ${n}?`)){m(!0);try{let t=await le(`/providers/${encodeURIComponent(n)}/models/bulk`,{method:`DELETE`,body:JSON.stringify({items:e.map(e=>({modelId:e.modelId,route:e.route}))})});await Promise.all([b.invalidateQueries({queryKey:I.providers.models(n)}),b.invalidateQueries({queryKey:I.providers.all})]);let r=t.failures.length;y.success(`Fetched models deleted`,r>0?`${t.deleted}/${t.total} removed, ${r} failed`:`${t.deleted}/${t.total} removed`)}catch(e){y.error(`Failed to delete fetched models`,e.message??`Unable to delete models`)}finally{m(!1)}}},children:f?`Deleting…`:`Delete fetched`}),(0,Q.jsx)(v,{variant:`primary`,size:`sm`,icon:(0,Q.jsx)(ne,{size:13}),onClick:()=>T(!0),children:`Add Model`})]})}),(0,Q.jsx)(z,{className:`flex flex-col gap-8`,children:s.isPending?(0,Q.jsx)(A,{label:`Loading models...`}):s.isError?(0,Q.jsx)(k,{message:`Failed to load models`,onRetry:()=>s.refetch()}):q.length===0?(0,Q.jsx)(j,{title:`No LLM models found`,message:`No LLM models published by this provider yet. Sync or add a custom model above.`}):(0,Q.jsx)(Jn,{providerId:n,models:q,serviceKind:`llm`,thinkingEffort:pe,searchCapable:H?.supportsWebSearch===!0})})]})}):X===`websearch`?(0,Q.jsxs)(B,{children:[(0,Q.jsx)(Ie,{title:`Web Search`,subtitle:`Run a real search request through the selected provider.`,icon:(0,Q.jsx)(p,{size:16})}),(0,Q.jsx)(z,{className:`flex flex-col gap-6`,children:s.isPending?(0,Q.jsx)(A,{label:`Loading search models...`}):s.isError?(0,Q.jsx)(k,{message:`Failed to load search models`,onRetry:()=>s.refetch()}):We.length===0?(0,Q.jsx)(j,{title:`No Search models found`,message:`This provider advertises Search, but no websearch model is registered yet.`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`label`,{className:`flex flex-col gap-2.5 text-badge text-text-secondary`,children:[`Search model`,(0,Q.jsx)(`select`,{value:qe,onChange:e=>{te(e.target.value),ae(null)},className:`w-full min-h-17 rounded-inset border border-inner-border bg-surface-1 text-text-primary px-4.5 py-0`,children:We.map(e=>(0,Q.jsx)(`option`,{value:e.modelId,children:e.modelId},`${e.modelId}:${e.route}`))})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-2.5 text-badge text-text-secondary`,children:[`Query`,(0,Q.jsx)(`input`,{value:O,onChange:e=>N(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Je())},placeholder:`What is the latest news about AI?`,className:`w-full min-h-17 rounded-inset border border-inner-border bg-surface-1 text-text-primary px-4.5 py-0`})]}),(0,Q.jsxs)(Y,{gap:`8px`,className:`items-center flex-wrap`,children:[(0,Q.jsx)(v,{variant:`primary`,size:`sm`,disabled:E.isPending||O.trim().length===0,loading:E.isPending,onClick:Je,children:`Test search`}),F?(0,Q.jsx)(`span`,{className:`text-badge`,style:{color:F.ok?`var(--green)`:`var(--red)`},children:F.ok?`Search ok · ${F.latencyMs}ms · ${F.count??0} result(s)`:F.error??`Search failed.`}):null]}),F&&F.results&&F.results.length>0?(0,Q.jsx)(`div`,{className:`flex max-h-110 flex-col gap-4 overflow-y-auto rounded-inset border border-inner-border bg-surface-1 p-4`,children:F.results.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,className:`text-caption text-text-primary font-semibold`,children:e.title||e.url}),(0,Q.jsx)(`span`,{className:`text-badge text-text-tertiary break-all`,children:e.url}),e.snippet?(0,Q.jsx)(`span`,{className:`text-badge text-text-secondary`,children:e.snippet}):null]},`${e.url}:${t}`))}):null]})})]}):X===`imageGeneration`||X===`videoGeneration`?(0,Q.jsxs)(B,{children:[(0,Q.jsx)(Ie,{title:Yn(X),subtitle:X===`imageGeneration`?`Models that return an image rather than text.`:`Models that return a video. Wired and routable; not yet verified against a live account.`,icon:X===`imageGeneration`?(0,Q.jsx)(D,{size:16}):(0,Q.jsx)(lt,{size:16})}),(0,Q.jsx)(z,{className:`flex flex-col gap-6`,children:s.isPending?(0,Q.jsx)(A,{label:`Loading ${Yn(X).toLowerCase()} models...`}):s.isError?(0,Q.jsx)(k,{message:`Failed to load ${Yn(X).toLowerCase()} models`,onRetry:()=>s.refetch()}):(X===`imageGeneration`?Ge:Ke).length===0?(0,Q.jsx)(j,{title:`No ${Yn(X)} models found`,message:`This provider advertises ${Yn(X)}, but no ${X} model is registered yet.`}):(0,Q.jsx)(Jn,{providerId:n,models:X===`imageGeneration`?Ge:Ke,serviceKind:`llm`,searchCapable:!1,thinkingEffort:`auto`})})]}):(0,Q.jsx)(B,{children:(0,Q.jsx)(z,{children:(0,Q.jsx)(j,{title:`Service not available`,message:`This provider advertises ${Ve.map(Yn).join(`, `)}, but the dashboard has no controls for the selected service yet.`})})}),x&&(0,Q.jsx)(bn,{providerId:n,accounts:W,onClose:()=>S(!1)}),X===`llm`&&w?(0,Q.jsx)(Ln,{providerId:n,provider:H,onClose:()=>T(!1)}):null,(0,Q.jsx)(me,{open:R!==null,onClose:()=>{Ne||Me(null)},onConfirm:async()=>{if(R){Fe(!0);try{let e=R.tenantId===null?`/global/accounts/${encodeURIComponent(R.id)}`:`/accounts/${encodeURIComponent(R.id)}`;await le(e,{method:`DELETE`}),b.removeQueries({queryKey:I.quota.account(R.id),exact:!0}),await Promise.all([b.invalidateQueries({queryKey:I.providers.accounts(n)}),b.invalidateQueries({queryKey:I.providers.healthEvents(n,R.id)}),b.invalidateQueries({queryKey:I.providers.all}),b.invalidateQueries({queryKey:I.quota.all})]),y.success(`Account deleted`,R.label||R.id.slice(0,8)),Me(null)}catch(e){throw y.error(`Failed to delete account`,e.message??`Unable to delete account`),e}finally{Fe(!1)}}},title:`Delete account?`,message:`Delete "${R?.label||R?.id.slice(0,8)}"? This cannot be undone.`,confirmLabel:`Delete`,danger:!0}),_e&&(0,Q.jsx)(wn,{providerId:n,parameters:ke,onClose:()=>{ye(!1),je({})}}),L!==null&&(0,Q.jsx)(P,{open:!0,onClose:()=>Se(null),title:L===`browser`?`Sign in with`:`Device sign-in details`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(v,{variant:`secondary`,size:`sm`,onClick:()=>Se(null),children:`Cancel`}),(0,Q.jsx)(v,{variant:`primary`,size:`sm`,onClick:Ze,children:`Continue`})]}),children:(0,Q.jsxs)(J,{gap:`12px`,children:[(0,Q.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:L===`browser`?`Choose how ${H.label||H.displayName} should identify you, then continue to its sign-in page.`:`These decide which organization the device code is issued for.`}),(0,Q.jsx)(Dn,{fields:L===`browser`?H?.oauthFlows?.browserLoginFields??[]:H?.oauthFlows?.deviceLoginFields??[],values:Ce,idPrefix:`flow-${L}`,onChange:(e,t)=>De(n=>({...n,[e]:t}))})]})}),be&&H?.oauthFlows?.import===!0&&(0,Q.jsx)(On,{providerId:n,providerName:H.label||H.displayName,fields:H.oauthFlows.importFields,onClose:()=>xe(!1)}),Le&&(0,Q.jsx)(Sn,{providerId:n,authorizeUrl:Le.authorizeUrl,state:Le.state,popup:Le.popup,onClose:e=>{V.current=null,Re(null),e&&b.invalidateQueries({queryKey:I.providers.accounts(n)})}})]})}export{Zn as default};
|
|
Binary file
|