cartethyia 2.6.5 → 2.6.6
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/dist/dashboard/assets/{BannedPage-B7OjIxCp.js → BannedPage-1v5rzKMl.js} +1 -1
- package/dist/dashboard/assets/BannedPage-1v5rzKMl.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolDetailPage-Bt-6y24w.js → CliToolDetailPage-chMg74ct.js} +1 -1
- package/dist/dashboard/assets/CliToolDetailPage-chMg74ct.js.gz +0 -0
- package/dist/dashboard/assets/{CliToolsPage-C6LunsuE.js → CliToolsPage-CKG-Vxrt.js} +1 -1
- package/dist/dashboard/assets/CliToolsPage-CKG-Vxrt.js.gz +0 -0
- package/dist/dashboard/assets/{CombosPage-CgyfN2Yy.js → CombosPage-JYmVKzIx.js} +1 -1
- package/dist/dashboard/assets/CombosPage-JYmVKzIx.js.gz +0 -0
- package/dist/dashboard/assets/{ConsoleLogPage-BHWU7y6j.js → ConsoleLogPage-CPflWDry.js} +1 -1
- package/dist/dashboard/assets/ConsoleLogPage-CPflWDry.js.gz +0 -0
- package/dist/dashboard/assets/{CustomizationPage-xIjU736m.js → CustomizationPage-B0EYUE47.js} +1 -1
- package/dist/dashboard/assets/CustomizationPage-B0EYUE47.js.gz +0 -0
- package/dist/dashboard/assets/{HealthEventsModal-DeT1zkYG.js → HealthEventsModal-F1c4lkNG.js} +1 -1
- package/dist/dashboard/assets/HealthEventsModal-F1c4lkNG.js.gz +0 -0
- package/dist/dashboard/assets/{LoginPage-ChVqIAam.js → LoginPage-BYTpzcoU.js} +1 -1
- package/dist/dashboard/assets/LoginPage-BYTpzcoU.js.gz +0 -0
- package/dist/dashboard/assets/{OverviewPage-BD4GkRtS.js → OverviewPage-DIYZRAcb.js} +1 -1
- package/dist/dashboard/assets/OverviewPage-DIYZRAcb.js.gz +0 -0
- package/dist/dashboard/assets/{ProviderDetailPage-BJXwqpKj.js → ProviderDetailPage-CM4MNy45.js} +1 -1
- package/dist/dashboard/assets/ProviderDetailPage-CM4MNy45.js.gz +0 -0
- package/dist/dashboard/assets/{ProvidersPage-Ck64riM5.js → ProvidersPage-Bsoqg2HG.js} +1 -1
- package/dist/dashboard/assets/ProvidersPage-Bsoqg2HG.js.gz +0 -0
- package/dist/dashboard/assets/{ProxyPage-Br_Leqq0.js → ProxyPage-8G3doV7j.js} +1 -1
- package/dist/dashboard/assets/ProxyPage-8G3doV7j.js.gz +0 -0
- package/dist/dashboard/assets/{QuotaPage-D2gyhfa8.js → QuotaPage-CVIQq6JG.js} +1 -1
- package/dist/dashboard/assets/QuotaPage-CVIQq6JG.js.gz +0 -0
- package/dist/dashboard/assets/{SettingsPage-1dbYb8cM.js → SettingsPage-BgXvRN2Q.js} +1 -1
- package/dist/dashboard/assets/SettingsPage-BgXvRN2Q.js.gz +0 -0
- package/dist/dashboard/assets/{SetupPage-DUTFy9wH.js → SetupPage-BCx07-bj.js} +1 -1
- package/dist/dashboard/assets/SetupPage-BCx07-bj.js.gz +0 -0
- package/dist/dashboard/assets/{SortableList-BZEhfDpZ.js → SortableList-MhkB6msu.js} +1 -1
- package/dist/dashboard/assets/SortableList-MhkB6msu.js.gz +0 -0
- package/dist/dashboard/assets/{StudioPage-GBDtsJjh.js → StudioPage-CTqK6Nsj.js} +1 -1
- package/dist/dashboard/assets/StudioPage-CTqK6Nsj.js.gz +0 -0
- package/dist/dashboard/assets/{UsagePage-CxidMvxq.js → UsagePage-Do65OWbr.js} +1 -1
- package/dist/dashboard/assets/UsagePage-Do65OWbr.js.gz +0 -0
- package/dist/dashboard/assets/{entry-BrksMru8.js → entry-CBHzQ6Qh.js} +3 -3
- package/dist/dashboard/assets/entry-CBHzQ6Qh.js.gz +0 -0
- package/dist/dashboard/assets/{index-DU61iviS.js → index-Ck4uwuYb.js} +2 -2
- package/dist/dashboard/assets/index-Ck4uwuYb.js.gz +0 -0
- package/dist/dashboard/assets/{select-Ciq_KFQ1.js → select-BrrUDUPc.js} +1 -1
- package/dist/dashboard/assets/select-BrrUDUPc.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 +21 -21
- package/package.json +1 -1
- package/scripts/cli/tray.ts +34 -10
- package/src/transport/dispatch/streaming/finalize.ts +64 -2
- package/dist/dashboard/assets/BannedPage-B7OjIxCp.js.gz +0 -0
- package/dist/dashboard/assets/CliToolDetailPage-Bt-6y24w.js.gz +0 -0
- package/dist/dashboard/assets/CliToolsPage-C6LunsuE.js.gz +0 -0
- package/dist/dashboard/assets/CombosPage-CgyfN2Yy.js.gz +0 -0
- package/dist/dashboard/assets/ConsoleLogPage-BHWU7y6j.js.gz +0 -0
- package/dist/dashboard/assets/CustomizationPage-xIjU736m.js.gz +0 -0
- package/dist/dashboard/assets/HealthEventsModal-DeT1zkYG.js.gz +0 -0
- package/dist/dashboard/assets/LoginPage-ChVqIAam.js.gz +0 -0
- package/dist/dashboard/assets/OverviewPage-BD4GkRtS.js.gz +0 -0
- package/dist/dashboard/assets/ProviderDetailPage-BJXwqpKj.js.gz +0 -0
- package/dist/dashboard/assets/ProvidersPage-Ck64riM5.js.gz +0 -0
- package/dist/dashboard/assets/ProxyPage-Br_Leqq0.js.gz +0 -0
- package/dist/dashboard/assets/QuotaPage-D2gyhfa8.js.gz +0 -0
- package/dist/dashboard/assets/SettingsPage-1dbYb8cM.js.gz +0 -0
- package/dist/dashboard/assets/SetupPage-DUTFy9wH.js.gz +0 -0
- package/dist/dashboard/assets/SortableList-BZEhfDpZ.js.gz +0 -0
- package/dist/dashboard/assets/StudioPage-GBDtsJjh.js.gz +0 -0
- package/dist/dashboard/assets/UsagePage-CxidMvxq.js.gz +0 -0
- package/dist/dashboard/assets/entry-BrksMru8.js.gz +0 -0
- package/dist/dashboard/assets/index-DU61iviS.js.gz +0 -0
- package/dist/dashboard/assets/select-Ciq_KFQ1.js.gz +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{n as i}from"./terminal-0_IjPWTk.js";import{a,i as o,n as s,r as c}from"./model-bans-BmYTmbAk.js";import{n as l,r as u,t as d}from"./concurrency-BDF0ok7y.js";import{C as f,E as p,O as m,T as h,c as g,s as _,v,x as y}from"./numbers-Dulqgys5.js";import{t as ee}from"./chevron-right-BXIy5l3h.js";import{t as b}from"./SortableList-BZEhfDpZ.js";import{t as x}from"./database-Dz9N3zGd.js";import{t as S}from"./eye-off-Bk5g2luF.js";import{t as C}from"./eye-C_hawfH4.js";import{t as te}from"./gauge-BbIMy7MB.js";import{n as w,r as T,t as E}from"./state-DhZBfWgx.js";import{t as D}from"./key-round-UkavsGxp.js";import{n as ne,r as re,t as O}from"./clipboard-button-e-Mlk0FH.js";import{t as k}from"./dialog-Iec_ywbD.js";import{t as A}from"./pencil-768ysRAr.js";import{t as j}from"./plus-DIdX_g-x.js";import{t as M}from"./power-off-Yjw9GMJh.js";import{t as ie}from"./refresh-cw-BqJFk4sU.js";import{t as N}from"./route-CNSNj9Zm.js";import{t as ae}from"./search-JOKus9rb.js";import{t as oe}from"./shield-check-DVS0Foqh.js";import{n as P,r as se,t as F}from"./settings--3hxSyry.js";import{t as ce}from"./trash-Cppn5c3R.js";import{C as le,T as ue,b as de,x as fe}from"./assert-DU6qrMA_.js";import{l as I,o as pe,t as L}from"./query-keys-UETqfytp.js";import{t as me}from"./useMutation-EDFRkn1i.js";import{it as he,j as ge,lt as _e,ot as ve,z as ye}from"./entry-BrksMru8.js";import{n as R,r as z,t as B}from"./card-BOPBuBzD.js";import{t as V}from"./use-clipboard-B0Sy03fE.js";import{n as be}from"./download-dRFo5_Wu.js";import{c as H,d as U}from"./tokens-COzario9.js";import{t as W}from"./badge-Bkz_-RrM.js";import{n as G,t as xe}from"./input-WlyHWeG2.js";import{t as Se}from"./select-Ciq_KFQ1.js";import{t as Ce}from"./ModelPicker-CA1kLs45.js";import{t as K}from"./switch-yD7D99Lg.js";import{t as q}from"./stack-B1w5BM0u.js";import{n as J}from"./inline-DToMICwl.js";import{a as we,c as Y,d as Te,f as Ee,i as X,l as Z,n as De,o as Oe,r as ke,s as Ae,t as je,u as Me}from"./api-keys-C23S9sgp.js";import{a as Ne,i as Pe,n as Fe,r as Ie}from"./cli-tools-BaFUuFFF.js";import{t as Le}from"./layout-DaJ5baJr.js";import{s as Re}from"./quota-DZGyp0N5.js";var ze=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`}]]),Be=e(`radio-tower`,[[`path`,{d:`M4.9 16.1C1 12.2 1 5.8 4.9 1.9`,key:`s0qx1y`}],[`path`,{d:`M7.8 4.7a6.14 6.14 0 0 0-.8 7.5`,key:`1idnkw`}],[`circle`,{cx:`12`,cy:`9`,r:`2`,key:`1092wv`}],[`path`,{d:`M16.2 4.8c2 2 2.26 5.11.8 7.47`,key:`ojru2q`}],[`path`,{d:`M19.1 1.9a9.96 9.96 0 0 1 0 14.1`,key:`rhi7fg`}],[`path`,{d:`M9.5 18h5`,key:`mfy3pd`}],[`path`,{d:`m8 22 4-11 4 11`,key:`25yftu`}]]),Ve=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`}]]),He=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`}]]),Ue=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`}]]),We=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`}]]),Ge=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`}]]),Ke=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`}]]),qe=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`}]]),Je=e(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]),Ye=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`}]]),Xe=[`routing:invoke`,`routing:cli_mapping`,`search:invoke`,`dashboard:read`,`dashboard:write`,`providers:read`,`providers:write`,`models:read`,`models:write`],Ze=[`image/png`,`image/jpeg`,`image/webp`,`image/gif`],Q=t(n(),1),$=r(),Qe={"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.`},$e={"routing:invoke":N,"routing:cli_mapping":N,"search:invoke":ae,"dashboard:read":C,"dashboard:write":A,"providers:read":he,"providers:write":ze,"models:read":u,"models:write":x},et={k:1e3,m:1e6,b:1e9,t:0xe8d4a51000},tt=[{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 nt(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]?et[n[2]]??1:1;return Math.round(r*i)}function rt(e){if(e==null)return``;let t=tt.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 it(e){let t=Number(e.trim());return Number.isFinite(t)&&t>0?Math.round(t):void 0}function at(e){let t=it(e);return e.trim()===``?null:t}function ot({label:e,value:t,onChange:n,disabled:r}){let i=nt(t),a=tt.find(e=>e.amount===i)?.label;return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(G,{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-2 mt-2`,role:`group`,"aria-label":`${e} presets`,children:tt.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-0.5 px-3 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 st({tool:e,keyId:t,busy:n,scopeGranted:r,onScopeChange:i}){let a=Pe(e.id,t),o=Ie(),s=Fe(),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-4 py-1.5 px-4 rounded-inset`,style:{minHeight:`38px`,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)(N,{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)(K,{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:()=>_.success(`Saved remote routing for ${e.name}.`),onError:e=>_.error(I(e,`Could not save remote routing.`))})}}),(0,$.jsx)(g,{variant:`secondary`,size:`sm`,disabled:n||d||!c&&u===0,onClick:()=>s.mutate({toolId:e.id,keyId:t},{onSuccess:()=>_.success(`Cleared remote routes for ${e.name}.`),onError:e=>_.error(I(e,`Could not reset remote routes.`))}),children:s.isPending?`Resetting…`:`Reset`})]})]})}function ct({keyId:e,busy:t,scopeGranted:n,onScopeChange:r,persistScope:i}){let a=(Ne().data??[]).filter(e=>e.mappingSupported);return(0,$.jsxs)(`section`,{"aria-labelledby":`remote-routing-heading`,className:`flex flex-col gap-3`,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)(N,{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.`})]}),e.length===0?(0,$.jsx)(`p`,{className:`text-badge text-text-tertiary m-0`,children:`Save the key first to configure per-tool remote routing mappings.`}):a.length===0?(0,$.jsx)(`p`,{className:`text-badge text-text-tertiary m-0`,children:`No CLI tools with mapping support are currently registered.`}):(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:a.map(a=>(0,$.jsx)(st,{tool:a,keyId:e,busy:t,scopeGranted:n,onScopeChange:e=>{r(e),i(e)}},a.id))})]})}function lt(e,t,n){let r=e===`personal`?t.trim():``;return{keyMode:e,keyPrefix:n.trim()||void 0,...r?{key:r}:{}}}function ut(e,t){return e===`personal`?t??null:null}function dt(e){let t=e?.scopes;return e?.isDefault?t&&t.length>0?[...t]:[...Xe]:t&&t.length>0?[...t]:[`routing:invoke`,`search:invoke`]}function ft({mode:e,record:t,busy:n,onDone:r,onClose:i,actionsRef:o}){let[s,c]=(0,Q.useState)(t?.label??``),[d,f]=(0,Q.useState)(t?.keyPrefix??``),[p,m]=(0,Q.useState)(``),[h,v]=(0,Q.useState)(t?.requestsPerMinute?.toString()??``),[y,ee]=(0,Q.useState)(rt(t?.dailyTokenLimit??null)),[b,x]=(0,Q.useState)(rt(t?.monthlyTokenLimit??null)),[S,C]=(0,Q.useState)(rt(t?.lifetimeTokenBudget??null)),[w,T]=(0,Q.useState)(t?.lifetimeTokenBudget==null?`recurring`:`one-time`),[E,re]=(0,Q.useState)(t?.maxConcurrentRequests?.toString()??``),[O,k]=(0,Q.useState)(()=>dt(t)),[A,j]=(0,Q.useState)(t?.modelAccessMode??`whitelist`),[M,ie]=(0,Q.useState)(()=>{let e=t?.modelList;return e?[...e]:[]}),[ae,P]=(0,Q.useState)(!1),[F,ce]=(0,Q.useState)(()=>{let e=t?.clientRouterDenylist;return e?[...new Set(e.map(fe).filter(e=>e!==void 0))]:[]}),[le,ue]=(0,Q.useState)(()=>t?.notesTitle??``),[pe,L]=(0,Q.useState)(()=>t?.notesSubtitle??``),[me,he]=(0,Q.useState)(()=>t?.notesBody??``),[ge,ye]=(0,Q.useState)(t?.sharePopupEnabled??!0),[R,z]=(0,Q.useState)(null),[B,V]=(0,Q.useState)(!1),[be,H]=(0,Q.useState)(null),U=t?.sharePopupImageMime!==void 0,W=R??(U&&!B&&t!==null?`/console/api/api-keys/${t.id}/share-popup-image`:null);(0,Q.useEffect)(()=>{U||R!==null||B||fetch(`/donation/qris-risun-marke.png`).then(e=>e.ok?e.blob():Promise.reject(e.status)).then(e=>{let{promise:t,resolve:n,reject:r}=Promise.withResolvers(),i=new FileReader;return i.onload=()=>n(i.result),i.onerror=r,i.readAsDataURL(e),t}).then(e=>z(e)).catch(()=>{})},[]);let[Se,q]=(0,Q.useState)(t?.sharePopupTitle??`Support via QRIS`),[J,we]=(0,Q.useState)(t?.sharePopupBody??`Scan the QR code above with any QRIS-compatible banking or e-wallet app to support this gateway's upkeep. Every contribution helps keep the service running — thank you! 🙏`),[Y,Te]=(0,Q.useState)(t?.keyMode??`personal`),X=w===`one-time`,Z=e===`edit`,De=Ee(),Oe=e=>k(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),ke=()=>{r({label:s.trim(),...lt(Y,p,d),scopes:O,modelAccessMode:A,modelList:M,clientRouterDenylist:F,requestsPerMinute:at(h),maxConcurrentRequests:at(E),dailyTokenLimit:X?null:nt(y)??null,monthlyTokenLimit:X?null:nt(b)??null,lifetimeTokenBudget:X?nt(S)??null:null,notesTitle:le.trim(),notesSubtitle:pe.trim(),notesBody:me.trim(),sharePopupEnabled:ge,...R===null?B?{sharePopupImage:null}:{}:{sharePopupImage:R},sharePopupTitle:Se.trim(),sharePopupBody:J.trim()})};return(0,Q.useEffect)(()=>{o?.((0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:i,disabled:n,children:`Cancel`}),(0,$.jsx)(g,{variant:`primary`,size:`sm`,disabled:n||e===`create`&&!s.trim(),onClick:ke,children:n?`Saving…`:e===`create`?`Create API key`:`Save changes`})]}))}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 min-w-0 pb-2`,children:[(0,$.jsxs)(`section`,{className:`flex flex-col gap-3 min-w-0 p-4 border border-inner-border rounded-card bg-surface-2 col-span-full`,children:[(0,$.jsxs)(`h3`,{className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(D,{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:()=>Te(e),title:Z?`Credential mode cannot change after creation`:void 0,className:`rounded-inset py-1.5 px-5`,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)(Je,{size:14,"aria-hidden":`true`}):(0,$.jsx)(Ye,{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:`grid grid-cols-2 gap-3 min-w-0 max-medium:grid-cols-1`,children:[e===`create`&&(0,$.jsxs)(`section`,{className:`flex flex-col gap-3 min-w-0 p-4 border border-inner-border rounded-card bg-surface-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(l,{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)(G,{label:`Name`,value:s,onChange:e=>c(e.target.value),placeholder:`ci-key…`,disabled:n,autoFocus:!0}),(0,$.jsx)(G,{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)(G,{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-3 min-w-0 p-4 border border-inner-border rounded-card bg-surface-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`text-caption font-bold text-text-primary`,children:[(0,$.jsx)(l,{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)(G,{label:`Name`,value:s,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-3 min-w-0 p-4 border border-inner-border rounded-card bg-surface-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`text-caption font-bold text-text-primary`,children:[(0,$.jsx)(ne,{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)(G,{label:`Title`,value:le,onChange:e=>ue(e.target.value),placeholder:`e.g. Bansos Token`,disabled:n}),(0,$.jsx)(G,{label:`Subtitle`,value:pe,onChange:e=>L(e.target.value),placeholder:`e.g. Come and save your tokens`,disabled:n}),(0,$.jsx)(`div`,{className:`col-span-full`,children:(0,$.jsx)(G,{label:`Body`,value:me,onChange:e=>he(e.target.value),placeholder:`Free-form notes for the recipient`,disabled:n})})]})]}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-3 min-w-0 p-4 border border-inner-border rounded-card bg-surface-2 col-span-full`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`text-caption font-bold text-text-primary`,children:[(0,$.jsx)(te,{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)(G,{label:`Requests per minute`,type:`number`,min:`0`,value:h,onChange:e=>v(e.target.value),placeholder:`Unlimited…`,disabled:n}),(0,$.jsx)(G,{label:`Max concurrent requests`,type:`number`,min:`0`,value:E,onChange:e=>re(e.target.value),placeholder:`Unlimited…`,disabled:n})]}),(0,$.jsx)(`p`,{className:`text-micro leading-normal text-text-tertiary`,children:E===``?`No concurrency limit, so the tenant allowance does nothing.`:`Limit ${E} concurrent. Refusals name this number; the allowance above it is tenant-wide and set in Settings.`}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 rounded-panel border border-inner-border px-4 py-3 bg-surface-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`text-caption font-bold text-text-primary`,children:[(0,$.jsx)(te,{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:()=>T(`recurring`),disabled:n,className:`py-1.5 px-4 rounded-chip font-semibold border-0 cursor-pointer`,style:{fontSize:`10px`,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)(Ve,{size:13,"aria-hidden":`true`}),`Recurring`]})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>T(`one-time`),disabled:n,className:`py-1.5 px-4 rounded-chip font-semibold border-0 cursor-pointer`,style:{fontSize:`10px`,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)(ze,{size:13,"aria-hidden":`true`}),`One-time`]})})]})]}),X?(0,$.jsx)(ot,{label:`One-time token limit`,value:S,onChange:C,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)(ot,{label:`Daily token limit`,value:y,onChange:ee,disabled:n}),(0,$.jsx)(ot,{label:`Monthly token limit`,value:b,onChange:x,disabled:n})]})]})]}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-3 min-w-0 p-4 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-caption font-bold text-text-primary`,children:[(0,$.jsx)(We,{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)(K,{checked:ge,onChange:e=>ye(e),disabled:n,label:`Enable popup`})]}),ge?(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:[W?(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:W,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)(xe,{id:`share-popup-image`,accept:Ze.join(`,`),"aria-label":`Popup image`,disabled:n,onChange:e=>{let t=e.target.files?.[0];if(e.target.value=``,!t)return;if(H(null),t.size>2097152){z(null),H(`Image must be 2 MB or smaller.`);return}let n=new FileReader;n.onload=()=>{z(String(n.result)),V(!1)},n.onerror=()=>H(`Could not read that file.`),n.readAsDataURL(t)}}),W?(0,$.jsx)(g,{variant:`secondary`,size:`sm`,type:`button`,disabled:n,className:`h-14 px-5 text-badge self-start`,onClick:()=>{z(null),V(!0),H(null)},children:`Remove image`}):null,be?(0,$.jsx)(`p`,{className:`form-error`,children:be}):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)(G,{label:`Popup title`,value:Se,onChange:e=>q(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:J,onChange:e=>we(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-3 p-4 [&::-webkit-details-marker]:hidden`,children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 items-start gap-3`,children:[(0,$.jsx)(`span`,{className:`grid size-8 shrink-0 place-items-center rounded-inset bg-accent-soft text-accent`,children:(0,$.jsx)(se,{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:[O.length,`/`,Xe.length,` grants`,(0,$.jsx)(_e,{size:14,className:`transition-transform group-open:rotate-180`,"aria-hidden":`true`})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 border-t border-inner-border p-4`,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)(oe,{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:`grid grid-cols-access gap-5 min-w-0 max-medium:grid-cols-1`,children:[(0,$.jsxs)(`section`,{"aria-labelledby":`model-access-heading`,className:`flex flex-col gap-3 min-w-0 rounded-card border border-inner-border bg-surface-1 p-4`,children:[(0,$.jsxs)(`h4`,{id:`model-access-heading`,className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(u,{size:15,className:`text-accent`,"aria-hidden":`true`}),`Model access`]}),(0,$.jsx)(`div`,{role:`group`,"aria-label":`Model access mode`,className:`flex gap-2`,children:[`whitelist`,`blacklist`].map(e=>(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":A===e,disabled:n,onClick:()=>j(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 px-3 text-badge font-semibold`,style:{borderRadius:`7px`,border:`1px solid ${A===e?`var(--accent)`:`var(--inner-border)`}`,background:A===e?`var(--accent-soft)`:`var(--surface-2)`,color:A===e?`var(--accent)`:`var(--text-secondary)`,cursor:n?`not-allowed`:`pointer`,opacity:n?.6:1},children:[e===`whitelist`?`Whitelist`:`Blacklist`,e===`whitelist`?(0,$.jsx)(oe,{size:13,className:`ml-1.5 inline`,"aria-hidden":`true`}):(0,$.jsx)(Ke,{size:13,className:`ml-1.5 inline`,"aria-hidden":`true`})]},e))}),(0,$.jsx)(`p`,{className:`text-badge text-text-tertiary m-0`,children:A===`whitelist`?`Only these models may be called. Empty = all allowed.`:`These models are refused. Everything else is allowed.`}),(0,$.jsx)(`div`,{className:`flex gap-1.5 flex-wrap min-h-6`,children:M.length===0?(0,$.jsx)(`span`,{className:`text-badge text-text-tertiary`,children:A===`whitelist`?`All models allowed`:`No models blocked`}):M.map(e=>(0,$.jsxs)(`span`,{className:`font-mono tabular-nums inline-flex items-center gap-1.5 text-badge bg-accent-soft text-accent py-1 px-3 rounded-chip border border-accent`,children:[e,(0,$.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e} from the model list`,onClick:()=>ie(t=>t.filter(t=>t!==e)),disabled:n,className:`bg-transparent border-0 cursor-pointer p-0 flex`,children:`×`})]},e))}),(0,$.jsx)(g,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>P(!0),disabled:n,children:`Browse models`}),(0,$.jsx)(Ce,{open:ae,onClose:()=>P(!1),selected:M,onToggle:e=>ie(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),title:A===`whitelist`?`Select allowed models`:`Select blocked models`,multi:!0})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 min-w-0`,children:[(0,$.jsxs)(`section`,{"aria-labelledby":`routing-blocking-heading`,className:`flex flex-col gap-0 min-w-0 rounded-card border border-inner-border bg-surface-1 overflow-hidden`,children:[(0,$.jsxs)(`div`,{className:`px-4 pt-4 pb-3 border-b border-inner-border`,children:[(0,$.jsxs)(`h4`,{id:`routing-blocking-heading`,className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(N,{size:15,className:`text-accent`,"aria-hidden":`true`}),`Routing & Client Blocking`]}),(0,$.jsx)(`p`,{className:`mt-1 mb-0 text-badge text-text-tertiary`,children:`Control which gateway routes this key can call and which client apps are blocked before routing.`})]}),(0,$.jsxs)(`div`,{className:`flex flex-col divide-y divide-inner-border`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 px-4 py-3`,children:[(0,$.jsx)(`p`,{className:`text-badge font-semibold text-text-secondary m-0`,children:`Gateway routing`}),Xe.filter(e=>e===`routing:invoke`).map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 py-1.5 px-4 rounded-inset`,style:{minHeight:`38px`,border:`1px solid var(--inner-border)`,background:O.includes(e)?`var(--accent-soft)`:`var(--surface-2)`},children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(N,{size:14,className:`mt-0.5 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-0.5 mb-0 text-badge text-text-tertiary`,children:Qe[e]})]})]}),(0,$.jsx)(K,{checked:O.includes(e),onChange:()=>Oe(e),disabled:n,"aria-label":`Grant ${e}`})]},e))]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 px-4 py-3`,children:[(0,$.jsx)(`p`,{className:`text-badge font-semibold text-text-secondary m-0`,children:`Blocked client apps`}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:de.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 py-1.5 px-4 rounded-inset`,style:{minHeight:`38px`,border:`1px solid var(--inner-border)`,background:F.includes(e.id)?`var(--accent-soft)`:`var(--surface-2)`},children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,$.jsx)(a,{size:14,className:`shrink-0 text-orange`,"aria-hidden":`true`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`text-caption font-semibold text-text-primary`,children:[`Block `,e.label,` Client`]}),(0,$.jsx)(`p`,{className:`mt-0.5 mb-0 text-badge text-text-tertiary`,children:e.id===`9router`?`9router, Omniroute, and Baazar Probes`:`Fingerprint-based detection — best-effort; unrecognised clients are never matched`})]})]}),(0,$.jsx)(K,{checked:F.includes(e.id),onChange:t=>ce(n=>t?[...n,e.id]:n.filter(t=>t!==e.id)),disabled:n,"aria-label":`Block ${e.label} client`})]},e.id))})]})]}),(0,$.jsx)(`div`,{className:`px-4 py-3`,children:(0,$.jsx)(ct,{keyId:e===`edit`&&t?t.id:``,busy:n,scopeGranted:O.includes(`routing:cli_mapping`),onScopeChange:e=>{e!==O.includes(`routing:cli_mapping`)&&Oe(`routing:cli_mapping`)},persistScope:n=>{if(e!==`edit`||!t)return;let r=n?[...new Set([...O,`routing:cli_mapping`])]:O.filter(e=>e!==`routing:cli_mapping`);De.mutate({keyId:t.id,request:{scopes:r}},{onError:e=>_.error(I(e,`Could not update the key's routing scope.`))})}})})]}),(0,$.jsxs)(`section`,{"aria-labelledby":`dashboard-scopes-heading`,className:`flex flex-col gap-0 min-w-0 rounded-card border border-inner-border bg-surface-1 overflow-hidden`,children:[(0,$.jsxs)(`div`,{className:`px-4 pt-4 pb-3 border-b border-inner-border`,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)(ve,{size:15,className:`text-accent`,"aria-hidden":`true`}),`Dashboard / Resources`]}),(0,$.jsx)(`p`,{className:`mt-1 mb-0 text-badge text-text-tertiary`,children:`Grants read or write access to console data — providers, models, configuration, and usage stats. No routing is implied by these scopes.`})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2 p-4`,children:Xe.filter(e=>!e.startsWith(`routing:`)).map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 py-1.5 px-4 rounded-inset`,style:{minHeight:`38px`,border:`1px solid var(--inner-border)`,background:O.includes(e)?`var(--accent-soft)`:`var(--surface-2)`},children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3 min-w-0`,children:[(()=>{let t=$e[e];return(0,$.jsx)(t,{size:14,className:`mt-0.5 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-0.5 mb-0 text-badge text-text-tertiary`,children:Qe[e]})]})]}),(0,$.jsx)(K,{checked:O.includes(e),onChange:()=>Oe(e),disabled:n,"aria-label":`Grant ${e}`})]},e))})]})]})]})]})]})]})}function pt({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)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(h,{size:13}),onClick:()=>{e!==null&&(be(`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`),_.success(`Key saved to your downloads.`))},children:`Save this key`})]})]})})}function mt(e,t){if(t)return`Permanent — lift manually`;let n=new Date(e);if(!Number.isFinite(n.getTime()))return`—`;let r=e-Date.now(),i=n.toLocaleString();if(r<=0)return`${i} (lapsed)`;let a=Math.ceil(r/6e4);if(a<60)return`${i} (in ${a}m)`;let o=Math.floor(a/60);return o<24?`${i} (in ${o}h)`:`${i} (in ${Math.floor(o/24)}d)`}function ht({onClose:e}){let t=s(!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 caller is banned after repeated invalid-model requests. A ban is scoped to the API key that made them, so other keys used from the same address keep working — unless an operator banned the address outright.`,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)(T,{compact:!0,label:`Loading banned users…`}):t.isError?(0,$.jsx)(w,{compact:!0,message:I(t.error,`Could not load banned users.`),onRetry:()=>void t.refetch()}):a.length===0?(0,$.jsx)(E,{compact:!0,title:`No banned users`,message:`No client address is currently banned for model abuse.`,icon:(0,$.jsx)(Ge,{size:20})}):(0,$.jsx)(`div`,{className:`rounded-inset border border-inner-border`,children:(0,$.jsx)(Le,{maxHeight:480,scrollRegion:!0,headers:[`Client IP`,`API key`,`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:`font-mono tabular-nums text-badge text-text-secondary whitespace-nowrap`,children:e.apiKeyId?`${e.apiKeyId.slice(0,8)}…`:`—`}),(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:e.apiKeyId?`This key only`:`All keys from this IP`}),(0,$.jsx)(`td`,{className:`text-badge text-text-secondary whitespace-nowrap`,children:mt(e.expiresAt,e.permanent===!0)}),(0,$.jsx)(`td`,{className:`text-right whitespace-nowrap`,children:(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(qe,{size:13}),disabled:n.isPending,onClick:()=>i(e),children:`Unban`})})]},e.identity))})})]}),(0,$.jsx)(J,{justify:`flex-end`,gap:`0px`,children:(0,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:e,children:`Close`})})]})}),(0,$.jsx)(ye,{open:r!==null,onClose:()=>i(null),onConfirm:async()=>{r&&(await n.mutateAsync(r.identity),_.success(`Unbanned ${r.ip}.`),i(null))},title:`Lift this ban?`,message:r?`Lift the ban on ${r.ip}${r.apiKeyId?` for this API key`:``}? The caller can reach the gateway again immediately.`:`Lift this ban?`,confirmLabel:`Unban`,danger:!0})]})}var gt=e=>(e??0).toLocaleString(),_t=e=>e?new Date(e).toLocaleString():`—`;function vt({keyId:e}){let t=we(),[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)(g,{variant:`secondary`,size:`sm`,icon:i?(0,$.jsx)(S,{size:13}):(0,$.jsx)(C,{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=>_.error(I(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 yt({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`:gt(t)})]})}function bt(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 xt({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?`${H(e)} · Unlimited`:`${H(e)} / ${H(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?`${H(e)} tokens consumed, no lifetime budget set`:`${H(e)} of ${H(t)} tokens consumed`,children:(0,$.jsx)(`div`,{className:i?`h-full rounded bg-status-danger`:`h-full rounded bg-status-success`,style:{width:`${r}%`}})})]})}var St=6;function Ct(e){return e.filter(e=>e.revokedAt===null).length}function wt(e){return e.reduce((e,t)=>e+t.allTime.totalTokens,0)}function Tt({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:H(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=Re(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:[H(e),` / `,H(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`:`${H(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":`${H(e)} of ${H(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 Et({parentId:e,childId:t}){let n=Me(e,t);if(n.isPending)return(0,$.jsx)(T,{label:`Loading activity…`,compact:!0});if(n.isError)return(0,$.jsx)(w,{compact:!0,message:I(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:gt(e.todayRequests)}),(0,$.jsx)(`td`,{children:gt(e.todayErrors)}),(0,$.jsx)(`td`,{children:H(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:H(e.totalTokens)}),(0,$.jsx)(`td`,{children:_t(e.startedAt)})]},e.requestId))})]})}):(0,$.jsx)(`p`,{className:`py-3 text-caption text-text-tertiary`,children:`No recent requests.`})]})]}):null}function Dt({parent:e,onSecretRevealed:t}){let[n,r]=(0,Q.useState)(null),[i,o]=(0,Q.useState)(`active`),[s,c]=(0,Q.useState)(null),l=ue(),u=Y(),f=ke(),p=Ae(),m=Z(e.id),h=e.keyMode!==`share`,v=Te(h?null:e.id),y=v.data??[],b=i===`active`?y.filter(e=>e.revokedAt===null):y.filter(e=>e.revokedAt!==null),x=y.filter(e=>e.revokedAt===null&&e.allTime.totalTokens===0);(0,Q.useEffect)(()=>{r(null)},[e.id]);let S=async(t,n)=>{let r=(await d(t,St,t=>p.mutateAsync({parentKeyId:e.id,childKeyId:t.id,deferInvalidation:!0}))).filter(e=>e.status===`fulfilled`).length;await l.invalidateQueries({queryKey:L.apiKeys.sharedKeys(e.id)}),await l.invalidateQueries({queryKey:L.apiKeys.all}),await v.refetch();let i=t.length-r;i>0?_.error(`Revoked ${r} of ${t.length} ${n}; ${i} failed.`):_.success(`Revoked ${r} ${n}.`)},C=u.isPending||f.isPending,[te,D]=(0,Q.useState)(!1),ne=async()=>{if(h){let n=await f.mutateAsync({keyId:e.id});t?.(n.secret);return}await u.mutateAsync({keyId:e.id,regenerate:!0}),_.success(`Link regenerated; the previous URL no longer works.`)},k=()=>{u.mutate({keyId:e.id},{onError:e=>_.error(I(e,`Could not create link.`))})},A=m.data?.url??null,j=bt(h);return(0,$.jsxs)(`div`,{className:`grid min-w-0 gap-6`,children:[(0,$.jsx)(`section`,{"aria-label":`Link`,children:m.isPending?(0,$.jsx)(T,{label:`Loading link…`,compact:!0}):m.isError?(0,$.jsx)(w,{compact:!0,message:I(m.error,`Could not load the link.`),onRetry:()=>void m.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)(re,{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)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(He,{size:13}),loading:C,disabled:C,onClick:()=>D(!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)(re,{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)(g,{variant:`primary`,size:`sm`,loading:C,disabled:C,onClick:k,children:`Create link`})]})}),h?(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)(vt,{keyId:e.id})]}):null,h?(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:H(e.tokensConsumed)})]}),(0,$.jsx)(yt,{label:`Requests / min`,value:e.requestsPerMinute}),(0,$.jsx)(yt,{label:`Daily tokens`,value:e.dailyTokenLimit}),(0,$.jsx)(yt,{label:`Monthly tokens`,value:e.monthlyTokenLimit}),(0,$.jsx)(xt,{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)(Tt,{consumed:wt(y),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: `,Ct(y)]}),(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:()=>o(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))}),s===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:s===`all`?`Revoke ${b.length}?`:`Revoke ${x.length} unused?`}),(0,$.jsx)(g,{variant:`danger`,size:`sm`,loading:p.isPending,onClick:()=>{let e=s===`all`?b:x,t=s===`all`?`recipients`:`unused recipients`;c(null),S(e,t)},children:`Confirm`}),(0,$.jsx)(g,{variant:`ghost`,size:`sm`,onClick:()=>c(null),children:`Cancel`})]}),(0,$.jsx)(g,{variant:`ghost`,size:`sm`,disabled:x.length===0||p.isPending,title:x.length===0?`No active recipient has spent zero tokens`:`Revoke ${x.length} recipient${x.length===1?``:`s`} that never spent a token`,onClick:()=>c(`unused`),icon:(0,$.jsx)(a,{size:13}),children:`Revoke no-usage`}),(0,$.jsx)(g,{variant:`ghost`,size:`sm`,disabled:b.length===0||p.isPending,title:b.length===0?`Nothing to revoke in this view`:`Revoke all ${b.length} listed recipient${b.length===1?``:`s`}`,onClick:()=>c(`all`),icon:(0,$.jsx)(a,{size:13}),children:`Revoke all`}),(0,$.jsx)(g,{variant:`ghost`,size:`sm`,onClick:()=>void v.refetch(),icon:(0,$.jsx)(ie,{size:13,className:v.isFetching?`animate-spin`:void 0}),children:`Refresh`})]}),v.isPending&&!v.data?(0,$.jsx)(T,{label:`Loading recipients…`,compact:!0}):v.isError?(0,$.jsx)(w,{compact:!0,message:I(v.error,`Could not load recipients.`),onRetry:()=>void v.refetch()}):b.length===0?(0,$.jsx)(E,{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:b.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)(_e,{size:14}):(0,$.jsx)(ee,{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:H(t.today.totalTokens)}),(0,$.jsx)(`td`,{children:H(t.allTime.totalTokens)}),(0,$.jsx)(`td`,{children:_t(t.lastUsedAt)}),(0,$.jsx)(`td`,{className:`text-right whitespace-nowrap`,children:(0,$.jsx)(g,{variant:`danger`,size:`sm`,disabled:p.isPending||!!t.revokedAt,onClick:()=>p.mutate({parentKeyId:e.id,childKeyId:t.id},{onError:e=>_.error(I(e,`Could not revoke key.`))}),children:`Revoke`})})]}),i?(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:7,className:`p-0`,children:(0,$.jsx)(Et,{parentId:e.id,childId:t.id})})}):null]},t.id)})})]})})]})]}),(0,$.jsx)(ye,{open:te,onClose:()=>D(!1),onConfirm:ne,title:j.title,message:j.message,confirmLabel:j.confirmLabel,danger:!0})]})}function Ot({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)(Dt,{parent:e,onSecretRevealed:n})})}function kt(){let e=je(),t=ge(),n=De(),r=Ee(),i=Oe(),a=ke(),o=we(),s=X(),{copy:c}=V(),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(null),[v,y]=(0,Q.useState)(null),[ee,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(null),[te,ne]=(0,Q.useState)(!1),[re,O]=(0,Q.useState)(null),[M,ie]=(0,Q.useState)(null),N=e.data??[],ae=t.data?.isPlatformAdmin??!1,oe=e=>{x(null),C(e)},P=async e=>{try{let{secret:t}=await o.mutateAsync({keyId:e.id});await c(t)?_.success(`API key copied`):_.error(`Clipboard unavailable on this origin`)}catch(e){_.error(I(e,`Could not reveal API key.`))}},se=bt(!0);return(0,$.jsxs)(B,{children:[(0,$.jsx)(z,{title:`API Credentials`,subtitle:`Manage tenant API keys, model access, budgets, and sharing.`,icon:(0,$.jsx)(D,{size:16}),action:(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[ae?(0,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:()=>ne(!0),icon:(0,$.jsx)(Ge,{size:13}),children:`Banned Users`}):null,(0,$.jsx)(g,{variant:`primary`,size:`sm`,onClick:()=>{x(null),u(!0)},icon:(0,$.jsx)(j,{size:13}),children:`Create Key`})]})}),(0,$.jsx)(R,{children:e.isPending&&!e.data?(0,$.jsx)(T,{label:`Loading API keys…`}):e.isError&&!e.data?(0,$.jsx)(w,{message:I(e.error,`Could not load credentials.`),onRetry:()=>void e.refetch()}):N.length===0?(0,$.jsx)(E,{title:`No API keys issued`,message:`Generate a secret key to authenticate your SDK or CLI client against the gateway.`,icon:(0,$.jsx)(D,{size:20})}):(0,$.jsx)(`div`,{className:`scroll-region max-h-280 pr-1`,children:(0,$.jsx)(b,{items:N,label:`API credentials`,disabled:s.isPending,onReorder:e=>s.mutate(e,{onError:e=>_.error(I(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)(W,{tone:e.revokedAt?`err`:e.enabled?`ok`:`warn`,children:e.revokedAt?`revoked`:e.enabled?`enabled`:`disabled`}),(0,$.jsx)(W,{tone:e.keyMode===`share`?`accent`:`default`,children:e.keyMode===`share`?`share template`:`personal`}),e.isDefault?(0,$.jsx)(W,{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`}),H(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`}),U(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`}),U(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`}),U(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`}),U(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`}),U(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)(K,{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:()=>_.success(`${e.label||`API credential`} ${t?`enabled`:`disabled`}`),onError:e=>_.error(I(e,`Could not update credential state.`))})}),(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(A,{size:13}),onClick:()=>{x(null),f(e)},children:`Edit`}),!e.revokedAt&&e.keyMode!==`share`?(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(p,{size:13}),onClick:()=>void P(e),disabled:o.isPending,children:`Copy`}):null,!e.revokedAt&&(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(We,{size:13}),onClick:()=>oe(e),children:e.keyMode===`share`?`Recipients`:`Share`}),!e.revokedAt&&e.keyMode!==`share`&&(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(He,{size:13}),onClick:()=>{x(null),y(e)},disabled:a.isPending,children:`Rotate`}),!e.revokedAt&&!e.isDefault&&(0,$.jsx)(g,{variant:`danger`,size:`sm`,icon:(0,$.jsx)(ce,{size:13}),onClick:()=>h(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:re,children:(0,$.jsx)(ft,{mode:`create`,record:null,busy:n.isPending,onClose:()=>u(!1),actionsRef:O,onDone:e=>{n.mutate(e,{onSuccess:t=>{u(!1),x(ut(e.keyMode,t.secret)),_.success(`API key created`)},onError:e=>_.error(I(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:M,children:(0,$.jsx)(ft,{mode:`edit`,record:d,busy:r.isPending,onClose:()=>f(null),actionsRef:ie,onDone:e=>{d&&r.mutate({keyId:d.id,request:e},{onSuccess:t=>{f(null),x(ut(e.keyMode,t.secret)),_.success(`API key updated`)},onError:e=>_.error(I(e,`Could not update API key.`))})}})}),S?(0,$.jsx)(Ot,{parent:S,onClose:()=>C(null),onSecretRevealed:e=>{C(null),x(e)}}):null,(0,$.jsx)(ye,{open:v!==null,onClose:()=>y(null),onConfirm:async()=>{if(!v)return;let e=await a.mutateAsync({keyId:v.id});x(e.secret),_.success(`Rotated ${v.label||v.id}.`),y(null)},title:se.title,message:se.message,confirmLabel:se.confirmLabel,danger:!0}),(0,$.jsx)(ye,{open:m!==null,onClose:()=>h(null),onConfirm:async()=>{m&&(await i.mutateAsync(m.id),_.success(`Revoked ${m.label||m.id}.`),h(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}),te?(0,$.jsx)(ht,{onClose:()=>ne(!1)}):null,(0,$.jsx)(pt,{secret:ee,onClose:()=>x(null)})]})}function At(){let e=F(),t=P(),n=e.data;if(e.isPending)return(0,$.jsx)(T,{label:`Loading compression settings…`});if(e.isError||!n)return(0,$.jsx)(w,{message:I(e.error,`Failed to load compression settings`),onRetry:()=>void e.refetch()});let r=n.rtkPruneEnabled,a=n.ponyTailEnabled;return(0,$.jsxs)(B,{children:[(0,$.jsx)(z,{title:`Compression`,subtitle:`Shrink requests before they reach the provider`,icon:(0,$.jsx)(o,{size:16})}),(0,$.jsx)(R,{children:(0,$.jsxs)(q,{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)(Ue,{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)(J,{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)(J,{gap:`8px`,className:`shrink-0 items-center ml-auto`,children:[(0,$.jsx)(Se,{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=>_.error(I(e,`Could not update RTK strength.`))}),options:[{value:`lite`,label:`Lite`},{value:`full`,label:`Full`},{value:`ultra`,label:`Ultra`}]}),(0,$.jsx)(K,{id:`compression-rtk`,"aria-label":`Enable RTK prune`,checked:r,onChange:e=>t.mutate({rtkPruneEnabled:e},{onError:e=>_.error(I(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)(i,{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)(J,{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)(J,{gap:`8px`,className:`shrink-0 items-center ml-auto`,children:[(0,$.jsx)(Se,{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=>_.error(I(e,`Could not update PonyTail strength.`))}),options:[{value:`lite`,label:`Lite`},{value:`full`,label:`Full`},{value:`ultra`,label:`Ultra`}]}),(0,$.jsx)(K,{id:`compression-ponytail`,"aria-label":`Enable PonyTail`,checked:a,onChange:e=>t.mutate({ponyTailEnabled:e},{onError:e=>_.error(I(e,`Could not update PonyTail.`))})})]})]}),r||a?(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)(v,{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 jt(){return le({queryKey:L.remoteSupport.status,queryFn:()=>pe(`/remote-support/status`)})}function Mt(){let e=ue();return me({mutationFn:e=>pe(`/remote-support/start`,{method:`POST`,body:JSON.stringify({tool:e})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:L.remoteSupport.status})}})}function Nt(){let e=ue();return me({mutationFn:e=>pe(`/remote-support/stop`,{method:`POST`,body:JSON.stringify(e===void 0?{}:{tool:e})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:L.remoteSupport.status})}})}var Pt={cloudflared:`cloudflared`,tailscale:`Tailscale`},Ft={cloudflared:`Publish a temporary public URL without opening a port.`,tailscale:`Give a helper a private address on your own tailnet.`};function It({tool:e}){return e===`cloudflared`?(0,$.jsxs)(`svg`,{viewBox:`0 0 24 24`,className:`size-8 shrink-0`,"aria-hidden":`true`,fill:`currentColor`,children:[(0,$.jsx)(`path`,{d:`M16.5 18.4a4.6 4.6 0 0 1-3.2-1.3l-6-5.9a2.4 2.4 0 0 0-3.3 0 2.3 2.3 0 0 0 0 3.3l5.4 5.3a.9.9 0 0 1-1.3 1.3L2.7 15.8a4.1 4.1 0 0 1 0-5.8 4.2 4.2 0 0 1 5.8 0l6 5.9a2.4 2.4 0 0 0 3.3 0 2.3 2.3 0 0 0 0-3.3l-4.2-4.1a.9.9 0 0 1 1.3-1.3l4.2 4.1a4.1 4.1 0 0 1 0 5.8 4.2 4.2 0 0 1-2.6 1.3Z`}),(0,$.jsx)(`path`,{d:`M7.6 18.4a4.5 4.5 0 0 1-3-1.1 5.4 5.4 0 0 1-1.5-3.5 6 6 0 0 1 .4-2 .9.9 0 0 1 1.7.6 4.2 4.2 0 0 0-.3 1.4 3.6 3.6 0 0 0 1 2.3 2.7 2.7 0 0 0 1.8.7.9.9 0 0 1 0 1.8Z`})]}):(0,$.jsxs)(`svg`,{viewBox:`0 0 24 24`,className:`size-8 shrink-0`,"aria-hidden":`true`,fill:`currentColor`,children:[(0,$.jsx)(`path`,{d:`M12 3.2a4.4 4.4 0 0 0-4.4 4.4v2.2H4.6a2.2 2.2 0 0 0 0 4.4h3v2.2a4.4 4.4 0 0 0 8.8 0v-2.2h1.1a3.3 3.3 0 0 0 0-6.6h-1.1V7.6A4.4 4.4 0 0 0 12 3.2Zm0 2.2a2.2 2.2 0 0 1 2.2 2.2v6.6a2.2 2.2 0 0 1-4.4 0V7.6A2.2 2.2 0 0 1 12 5.4Z`}),(0,$.jsx)(`path`,{d:`M6.6 11h4.2v2.2H6.6zM13.2 11h4.2v2.2h-4.2z`})]})}function Lt({tool:e}){let t=jt(),n=Mt(),r=Nt(),{copied:i,copy:a}=V(2e3),o=t.data?.active===e,s=n.isPending||r.isPending,c=o?t.data?.url??null:null,[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(o);(0,Q.useEffect)(()=>{!n.isPending&&!r.isPending&&f(o)},[o,n.isPending,r.isPending]);let h=async t=>{f(t);try{let i=t?await n.mutateAsync(e):await r.mutateAsync(e);if(i.blocker!==null&&i.message!==null){u(i.message),_.error(i.message),f(!t);return}u(null),_.success(t?`${Pt[e]} started`:`${Pt[e]} stopped`)}catch{_.error(`Could not ${t?`start`:`stop`} ${Pt[e]}`),f(!t)}},v=async()=>{if(c!==null){if(await a(c)){_.success(`Remote URL copied`,c);return}_.error(`Clipboard unavailable on this origin`)}};return(0,$.jsxs)(`div`,{className:`rounded-control border border-inner-border bg-surface-2 p-5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,$.jsx)(It,{tool:e}),(0,$.jsx)(`h3`,{className:`text-caption font-semibold`,children:Pt[e]})]}),(0,$.jsx)(K,{checked:d,disabled:s,onChange:e=>void h(e),"aria-label":`Toggle ${Pt[e]} remote support`})]}),n.isPending?(0,$.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-badge text-text-secondary`,children:[(0,$.jsx)(y,{size:14,className:`animate-spin`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`animate-pulse`,children:`Waiting for address…`})]}),(0,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:()=>void h(!1),children:`Cancel`})]}):c===null?l===null?(0,$.jsx)(`p`,{className:`mt-2 text-badge leading-normal text-text-tertiary`,children:Ft[e]}):(0,$.jsxs)(`div`,{className:`mt-2 rounded-control border border-warning/30 bg-warning/10 p-3 text-badge leading-normal text-text-secondary`,children:[(0,$.jsx)(`p`,{className:`font-medium text-warning`,children:`Setup needed`}),(0,$.jsx)(`p`,{className:`mt-1 whitespace-pre-wrap break-words`,children:l}),(()=>{let e=l.match(/https:\/\/login\.tailscale\.com\/f\/serve\?[^\s]+/);return e?(0,$.jsx)(`a`,{href:e[0],target:`_blank`,rel:`noreferrer`,className:`mt-2 inline-block font-medium text-accent underline`,children:`Enable Tailscale Serve →`}):null})()]}):(0,$.jsxs)(`div`,{className:`mt-3 flex items-center gap-3`,children:[(0,$.jsx)(`code`,{className:`min-w-0 flex-1 truncate font-mono text-badge text-text-primary`,title:c,children:c}),(0,$.jsxs)(g,{variant:`secondary`,size:`sm`,onClick:()=>void v(),children:[i?(0,$.jsx)(m,{size:14}):(0,$.jsx)(p,{size:14}),i?`Copied`:`Copy`]})]})]})}function Rt(){let{copied:e,copy:t}=V(2e3),n=`${window.location.origin}/v1`,r=async()=>{if(await t(n)){_.success(`Gateway endpoint copied`,n);return}_.error(`Clipboard unavailable on this origin`)};return(0,$.jsxs)(B,{children:[(0,$.jsx)(z,{title:`Gateway Endpoint`,subtitle:`Universal OpenAI & Anthropic Wire API Endpoint Compatible`,icon:(0,$.jsx)(f,{size:16})}),(0,$.jsx)(R,{children:(0,$.jsxs)(q,{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)(g,{variant:`secondary`,size:`sm`,icon:e?(0,$.jsx)(m,{size:13}):(0,$.jsx)(p,{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 zt(){let e=F(),t=P(),n=e.data?.invokeDisabled===!0,r=e=>{t.mutate({invokeDisabled:!e},{onSuccess:()=>_.success(e?`Invoke enabled — routing has resumed.`:`Invoke disabled — every request now returns 503 and nothing upstream is dialed.`),onError:e=>_.error(e instanceof Error?e.message:`Could not save the setting`)})};return(0,$.jsxs)(B,{children:[(0,$.jsx)(z,{title:`Invoke Switch`,subtitle:`Stop every request without deleting anything`,icon:(0,$.jsx)(M,{size:16})}),(0,$.jsx)(R,{children:(0,$.jsxs)(q,{gap:`10px`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsxs)(`p`,{className:`min-w-0 text-caption leading-normal text-text-secondary`,children:[`Off refuses every `,(0,$.jsx)(`code`,{className:`font-mono`,children:`/v1/*`}),` request with 503. Nothing is dispatched upstream, and no account, key, or model is changed — the dashboard stays reachable so you can turn it back on.`]}),(0,$.jsx)(K,{checked:!n,disabled:e.isLoading||t.isPending,onChange:e=>r(e),"aria-label":`Toggle invoke for every request`})]}),n?(0,$.jsxs)(`p`,{className:`flex items-start gap-2 text-caption leading-normal text-warning`,children:[(0,$.jsx)(v,{size:14,className:`mt-0.5 shrink-0`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:`Invoke is off. Every API request is being refused, and any client pointed at this gateway will keep failing until you switch it back on.`})]}):null]})})]})}function Bt(){let e=jt();return(0,$.jsxs)(B,{children:[(0,$.jsx)(z,{title:`Remote Support`,subtitle:`Reach this gateway from outside the local network`,icon:(0,$.jsx)(Be,{size:16})}),(0,$.jsx)(R,{children:(0,$.jsxs)(q,{gap:`10px`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 max-medium:grid-cols-1`,children:[(0,$.jsx)(Lt,{tool:`cloudflared`}),(0,$.jsx)(Lt,{tool:`tailscale`})]}),e.data?.blocker!==null&&e.data?.message!==null?(0,$.jsx)(`p`,{className:`text-badge leading-normal text-red-primary`,children:e.data?.message}):null,(0,$.jsxs)(`p`,{className:`text-caption leading-normal text-text-secondary`,children:[`Either way the gateway still sees the tunnel's address as the client, so set`,` `,(0,$.jsx)(`code`,{className:`font-mono`,children:`TRUSTED_PROXY_CIDRS`}),` to the edge that forwards to it — otherwise every remote caller is recorded as the loopback address.`]}),(0,$.jsx)(`p`,{className:`text-badge leading-normal text-text-tertiary`,children:`cloudflared and Tailscale are not installed by Cartethyia — install either one yourself first. The tunnel is launched detached from this process, so it survives a gateway restart.`})]})})]})}function Vt(){return(0,$.jsxs)(q,{gap:`16px`,children:[(0,$.jsx)(Rt,{}),(0,$.jsx)(zt,{}),(0,$.jsx)(Bt,{}),(0,$.jsx)(At,{}),(0,$.jsx)(kt,{})]})}export{Vt as default};
|
|
1
|
+
import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{n as i}from"./terminal-0_IjPWTk.js";import{a,i as o,n as s,r as c}from"./model-bans-BmYTmbAk.js";import{n as l,r as u,t as d}from"./concurrency-BDF0ok7y.js";import{C as f,E as p,O as m,T as h,c as g,s as _,v,x as y}from"./numbers-Dulqgys5.js";import{t as ee}from"./chevron-right-BXIy5l3h.js";import{t as b}from"./SortableList-MhkB6msu.js";import{t as x}from"./database-Dz9N3zGd.js";import{t as S}from"./eye-off-Bk5g2luF.js";import{t as C}from"./eye-C_hawfH4.js";import{t as te}from"./gauge-BbIMy7MB.js";import{n as w,r as T,t as E}from"./state-DhZBfWgx.js";import{t as D}from"./key-round-UkavsGxp.js";import{n as ne,r as re,t as O}from"./clipboard-button-e-Mlk0FH.js";import{t as k}from"./dialog-Iec_ywbD.js";import{t as A}from"./pencil-768ysRAr.js";import{t as j}from"./plus-DIdX_g-x.js";import{t as M}from"./power-off-Yjw9GMJh.js";import{t as ie}from"./refresh-cw-BqJFk4sU.js";import{t as N}from"./route-CNSNj9Zm.js";import{t as ae}from"./search-JOKus9rb.js";import{t as oe}from"./shield-check-DVS0Foqh.js";import{n as P,r as se,t as F}from"./settings--3hxSyry.js";import{t as ce}from"./trash-Cppn5c3R.js";import{C as le,T as ue,b as de,x as fe}from"./assert-DU6qrMA_.js";import{l as I,o as pe,t as L}from"./query-keys-UETqfytp.js";import{t as me}from"./useMutation-EDFRkn1i.js";import{it as he,j as ge,lt as _e,ot as ve,z as ye}from"./entry-CBHzQ6Qh.js";import{n as R,r as z,t as B}from"./card-BOPBuBzD.js";import{t as V}from"./use-clipboard-B0Sy03fE.js";import{n as be}from"./download-dRFo5_Wu.js";import{c as H,d as U}from"./tokens-COzario9.js";import{t as W}from"./badge-Bkz_-RrM.js";import{n as G,t as xe}from"./input-WlyHWeG2.js";import{t as Se}from"./select-BrrUDUPc.js";import{t as Ce}from"./ModelPicker-CA1kLs45.js";import{t as K}from"./switch-yD7D99Lg.js";import{t as q}from"./stack-B1w5BM0u.js";import{n as J}from"./inline-DToMICwl.js";import{a as we,c as Y,d as Te,f as Ee,i as X,l as Z,n as De,o as Oe,r as ke,s as Ae,t as je,u as Me}from"./api-keys-C23S9sgp.js";import{a as Ne,i as Pe,n as Fe,r as Ie}from"./cli-tools-BaFUuFFF.js";import{t as Le}from"./layout-DaJ5baJr.js";import{s as Re}from"./quota-DZGyp0N5.js";var ze=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`}]]),Be=e(`radio-tower`,[[`path`,{d:`M4.9 16.1C1 12.2 1 5.8 4.9 1.9`,key:`s0qx1y`}],[`path`,{d:`M7.8 4.7a6.14 6.14 0 0 0-.8 7.5`,key:`1idnkw`}],[`circle`,{cx:`12`,cy:`9`,r:`2`,key:`1092wv`}],[`path`,{d:`M16.2 4.8c2 2 2.26 5.11.8 7.47`,key:`ojru2q`}],[`path`,{d:`M19.1 1.9a9.96 9.96 0 0 1 0 14.1`,key:`rhi7fg`}],[`path`,{d:`M9.5 18h5`,key:`mfy3pd`}],[`path`,{d:`m8 22 4-11 4 11`,key:`25yftu`}]]),Ve=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`}]]),He=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`}]]),Ue=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`}]]),We=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`}]]),Ge=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`}]]),Ke=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`}]]),qe=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`}]]),Je=e(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]),Ye=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`}]]),Xe=[`routing:invoke`,`routing:cli_mapping`,`search:invoke`,`dashboard:read`,`dashboard:write`,`providers:read`,`providers:write`,`models:read`,`models:write`],Ze=[`image/png`,`image/jpeg`,`image/webp`,`image/gif`],Q=t(n(),1),$=r(),Qe={"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.`},$e={"routing:invoke":N,"routing:cli_mapping":N,"search:invoke":ae,"dashboard:read":C,"dashboard:write":A,"providers:read":he,"providers:write":ze,"models:read":u,"models:write":x},et={k:1e3,m:1e6,b:1e9,t:0xe8d4a51000},tt=[{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 nt(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]?et[n[2]]??1:1;return Math.round(r*i)}function rt(e){if(e==null)return``;let t=tt.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 it(e){let t=Number(e.trim());return Number.isFinite(t)&&t>0?Math.round(t):void 0}function at(e){let t=it(e);return e.trim()===``?null:t}function ot({label:e,value:t,onChange:n,disabled:r}){let i=nt(t),a=tt.find(e=>e.amount===i)?.label;return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(G,{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-2 mt-2`,role:`group`,"aria-label":`${e} presets`,children:tt.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-0.5 px-3 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 st({tool:e,keyId:t,busy:n,scopeGranted:r,onScopeChange:i}){let a=Pe(e.id,t),o=Ie(),s=Fe(),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-4 py-1.5 px-4 rounded-inset`,style:{minHeight:`38px`,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)(N,{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)(K,{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:()=>_.success(`Saved remote routing for ${e.name}.`),onError:e=>_.error(I(e,`Could not save remote routing.`))})}}),(0,$.jsx)(g,{variant:`secondary`,size:`sm`,disabled:n||d||!c&&u===0,onClick:()=>s.mutate({toolId:e.id,keyId:t},{onSuccess:()=>_.success(`Cleared remote routes for ${e.name}.`),onError:e=>_.error(I(e,`Could not reset remote routes.`))}),children:s.isPending?`Resetting…`:`Reset`})]})]})}function ct({keyId:e,busy:t,scopeGranted:n,onScopeChange:r,persistScope:i}){let a=(Ne().data??[]).filter(e=>e.mappingSupported);return(0,$.jsxs)(`section`,{"aria-labelledby":`remote-routing-heading`,className:`flex flex-col gap-3`,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)(N,{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.`})]}),e.length===0?(0,$.jsx)(`p`,{className:`text-badge text-text-tertiary m-0`,children:`Save the key first to configure per-tool remote routing mappings.`}):a.length===0?(0,$.jsx)(`p`,{className:`text-badge text-text-tertiary m-0`,children:`No CLI tools with mapping support are currently registered.`}):(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:a.map(a=>(0,$.jsx)(st,{tool:a,keyId:e,busy:t,scopeGranted:n,onScopeChange:e=>{r(e),i(e)}},a.id))})]})}function lt(e,t,n){let r=e===`personal`?t.trim():``;return{keyMode:e,keyPrefix:n.trim()||void 0,...r?{key:r}:{}}}function ut(e,t){return e===`personal`?t??null:null}function dt(e){let t=e?.scopes;return e?.isDefault?t&&t.length>0?[...t]:[...Xe]:t&&t.length>0?[...t]:[`routing:invoke`,`search:invoke`]}function ft({mode:e,record:t,busy:n,onDone:r,onClose:i,actionsRef:o}){let[s,c]=(0,Q.useState)(t?.label??``),[d,f]=(0,Q.useState)(t?.keyPrefix??``),[p,m]=(0,Q.useState)(``),[h,v]=(0,Q.useState)(t?.requestsPerMinute?.toString()??``),[y,ee]=(0,Q.useState)(rt(t?.dailyTokenLimit??null)),[b,x]=(0,Q.useState)(rt(t?.monthlyTokenLimit??null)),[S,C]=(0,Q.useState)(rt(t?.lifetimeTokenBudget??null)),[w,T]=(0,Q.useState)(t?.lifetimeTokenBudget==null?`recurring`:`one-time`),[E,re]=(0,Q.useState)(t?.maxConcurrentRequests?.toString()??``),[O,k]=(0,Q.useState)(()=>dt(t)),[A,j]=(0,Q.useState)(t?.modelAccessMode??`whitelist`),[M,ie]=(0,Q.useState)(()=>{let e=t?.modelList;return e?[...e]:[]}),[ae,P]=(0,Q.useState)(!1),[F,ce]=(0,Q.useState)(()=>{let e=t?.clientRouterDenylist;return e?[...new Set(e.map(fe).filter(e=>e!==void 0))]:[]}),[le,ue]=(0,Q.useState)(()=>t?.notesTitle??``),[pe,L]=(0,Q.useState)(()=>t?.notesSubtitle??``),[me,he]=(0,Q.useState)(()=>t?.notesBody??``),[ge,ye]=(0,Q.useState)(t?.sharePopupEnabled??!0),[R,z]=(0,Q.useState)(null),[B,V]=(0,Q.useState)(!1),[be,H]=(0,Q.useState)(null),U=t?.sharePopupImageMime!==void 0,W=R??(U&&!B&&t!==null?`/console/api/api-keys/${t.id}/share-popup-image`:null);(0,Q.useEffect)(()=>{U||R!==null||B||fetch(`/donation/qris-risun-marke.png`).then(e=>e.ok?e.blob():Promise.reject(e.status)).then(e=>{let{promise:t,resolve:n,reject:r}=Promise.withResolvers(),i=new FileReader;return i.onload=()=>n(i.result),i.onerror=r,i.readAsDataURL(e),t}).then(e=>z(e)).catch(()=>{})},[]);let[Se,q]=(0,Q.useState)(t?.sharePopupTitle??`Support via QRIS`),[J,we]=(0,Q.useState)(t?.sharePopupBody??`Scan the QR code above with any QRIS-compatible banking or e-wallet app to support this gateway's upkeep. Every contribution helps keep the service running — thank you! 🙏`),[Y,Te]=(0,Q.useState)(t?.keyMode??`personal`),X=w===`one-time`,Z=e===`edit`,De=Ee(),Oe=e=>k(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),ke=()=>{r({label:s.trim(),...lt(Y,p,d),scopes:O,modelAccessMode:A,modelList:M,clientRouterDenylist:F,requestsPerMinute:at(h),maxConcurrentRequests:at(E),dailyTokenLimit:X?null:nt(y)??null,monthlyTokenLimit:X?null:nt(b)??null,lifetimeTokenBudget:X?nt(S)??null:null,notesTitle:le.trim(),notesSubtitle:pe.trim(),notesBody:me.trim(),sharePopupEnabled:ge,...R===null?B?{sharePopupImage:null}:{}:{sharePopupImage:R},sharePopupTitle:Se.trim(),sharePopupBody:J.trim()})};return(0,Q.useEffect)(()=>{o?.((0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:i,disabled:n,children:`Cancel`}),(0,$.jsx)(g,{variant:`primary`,size:`sm`,disabled:n||e===`create`&&!s.trim(),onClick:ke,children:n?`Saving…`:e===`create`?`Create API key`:`Save changes`})]}))}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 min-w-0 pb-2`,children:[(0,$.jsxs)(`section`,{className:`flex flex-col gap-3 min-w-0 p-4 border border-inner-border rounded-card bg-surface-2 col-span-full`,children:[(0,$.jsxs)(`h3`,{className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(D,{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:()=>Te(e),title:Z?`Credential mode cannot change after creation`:void 0,className:`rounded-inset py-1.5 px-5`,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)(Je,{size:14,"aria-hidden":`true`}):(0,$.jsx)(Ye,{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:`grid grid-cols-2 gap-3 min-w-0 max-medium:grid-cols-1`,children:[e===`create`&&(0,$.jsxs)(`section`,{className:`flex flex-col gap-3 min-w-0 p-4 border border-inner-border rounded-card bg-surface-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(l,{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)(G,{label:`Name`,value:s,onChange:e=>c(e.target.value),placeholder:`ci-key…`,disabled:n,autoFocus:!0}),(0,$.jsx)(G,{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)(G,{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-3 min-w-0 p-4 border border-inner-border rounded-card bg-surface-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`text-caption font-bold text-text-primary`,children:[(0,$.jsx)(l,{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)(G,{label:`Name`,value:s,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-3 min-w-0 p-4 border border-inner-border rounded-card bg-surface-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`text-caption font-bold text-text-primary`,children:[(0,$.jsx)(ne,{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)(G,{label:`Title`,value:le,onChange:e=>ue(e.target.value),placeholder:`e.g. Bansos Token`,disabled:n}),(0,$.jsx)(G,{label:`Subtitle`,value:pe,onChange:e=>L(e.target.value),placeholder:`e.g. Come and save your tokens`,disabled:n}),(0,$.jsx)(`div`,{className:`col-span-full`,children:(0,$.jsx)(G,{label:`Body`,value:me,onChange:e=>he(e.target.value),placeholder:`Free-form notes for the recipient`,disabled:n})})]})]}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-3 min-w-0 p-4 border border-inner-border rounded-card bg-surface-2 col-span-full`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`text-caption font-bold text-text-primary`,children:[(0,$.jsx)(te,{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)(G,{label:`Requests per minute`,type:`number`,min:`0`,value:h,onChange:e=>v(e.target.value),placeholder:`Unlimited…`,disabled:n}),(0,$.jsx)(G,{label:`Max concurrent requests`,type:`number`,min:`0`,value:E,onChange:e=>re(e.target.value),placeholder:`Unlimited…`,disabled:n})]}),(0,$.jsx)(`p`,{className:`text-micro leading-normal text-text-tertiary`,children:E===``?`No concurrency limit, so the tenant allowance does nothing.`:`Limit ${E} concurrent. Refusals name this number; the allowance above it is tenant-wide and set in Settings.`}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 rounded-panel border border-inner-border px-4 py-3 bg-surface-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`text-caption font-bold text-text-primary`,children:[(0,$.jsx)(te,{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:()=>T(`recurring`),disabled:n,className:`py-1.5 px-4 rounded-chip font-semibold border-0 cursor-pointer`,style:{fontSize:`10px`,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)(Ve,{size:13,"aria-hidden":`true`}),`Recurring`]})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>T(`one-time`),disabled:n,className:`py-1.5 px-4 rounded-chip font-semibold border-0 cursor-pointer`,style:{fontSize:`10px`,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)(ze,{size:13,"aria-hidden":`true`}),`One-time`]})})]})]}),X?(0,$.jsx)(ot,{label:`One-time token limit`,value:S,onChange:C,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)(ot,{label:`Daily token limit`,value:y,onChange:ee,disabled:n}),(0,$.jsx)(ot,{label:`Monthly token limit`,value:b,onChange:x,disabled:n})]})]})]}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-3 min-w-0 p-4 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-caption font-bold text-text-primary`,children:[(0,$.jsx)(We,{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)(K,{checked:ge,onChange:e=>ye(e),disabled:n,label:`Enable popup`})]}),ge?(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:[W?(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:W,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)(xe,{id:`share-popup-image`,accept:Ze.join(`,`),"aria-label":`Popup image`,disabled:n,onChange:e=>{let t=e.target.files?.[0];if(e.target.value=``,!t)return;if(H(null),t.size>2097152){z(null),H(`Image must be 2 MB or smaller.`);return}let n=new FileReader;n.onload=()=>{z(String(n.result)),V(!1)},n.onerror=()=>H(`Could not read that file.`),n.readAsDataURL(t)}}),W?(0,$.jsx)(g,{variant:`secondary`,size:`sm`,type:`button`,disabled:n,className:`h-14 px-5 text-badge self-start`,onClick:()=>{z(null),V(!0),H(null)},children:`Remove image`}):null,be?(0,$.jsx)(`p`,{className:`form-error`,children:be}):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)(G,{label:`Popup title`,value:Se,onChange:e=>q(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:J,onChange:e=>we(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-3 p-4 [&::-webkit-details-marker]:hidden`,children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 items-start gap-3`,children:[(0,$.jsx)(`span`,{className:`grid size-8 shrink-0 place-items-center rounded-inset bg-accent-soft text-accent`,children:(0,$.jsx)(se,{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:[O.length,`/`,Xe.length,` grants`,(0,$.jsx)(_e,{size:14,className:`transition-transform group-open:rotate-180`,"aria-hidden":`true`})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 border-t border-inner-border p-4`,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)(oe,{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:`grid grid-cols-access gap-5 min-w-0 max-medium:grid-cols-1`,children:[(0,$.jsxs)(`section`,{"aria-labelledby":`model-access-heading`,className:`flex flex-col gap-3 min-w-0 rounded-card border border-inner-border bg-surface-1 p-4`,children:[(0,$.jsxs)(`h4`,{id:`model-access-heading`,className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(u,{size:15,className:`text-accent`,"aria-hidden":`true`}),`Model access`]}),(0,$.jsx)(`div`,{role:`group`,"aria-label":`Model access mode`,className:`flex gap-2`,children:[`whitelist`,`blacklist`].map(e=>(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":A===e,disabled:n,onClick:()=>j(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 px-3 text-badge font-semibold`,style:{borderRadius:`7px`,border:`1px solid ${A===e?`var(--accent)`:`var(--inner-border)`}`,background:A===e?`var(--accent-soft)`:`var(--surface-2)`,color:A===e?`var(--accent)`:`var(--text-secondary)`,cursor:n?`not-allowed`:`pointer`,opacity:n?.6:1},children:[e===`whitelist`?`Whitelist`:`Blacklist`,e===`whitelist`?(0,$.jsx)(oe,{size:13,className:`ml-1.5 inline`,"aria-hidden":`true`}):(0,$.jsx)(Ke,{size:13,className:`ml-1.5 inline`,"aria-hidden":`true`})]},e))}),(0,$.jsx)(`p`,{className:`text-badge text-text-tertiary m-0`,children:A===`whitelist`?`Only these models may be called. Empty = all allowed.`:`These models are refused. Everything else is allowed.`}),(0,$.jsx)(`div`,{className:`flex gap-1.5 flex-wrap min-h-6`,children:M.length===0?(0,$.jsx)(`span`,{className:`text-badge text-text-tertiary`,children:A===`whitelist`?`All models allowed`:`No models blocked`}):M.map(e=>(0,$.jsxs)(`span`,{className:`font-mono tabular-nums inline-flex items-center gap-1.5 text-badge bg-accent-soft text-accent py-1 px-3 rounded-chip border border-accent`,children:[e,(0,$.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e} from the model list`,onClick:()=>ie(t=>t.filter(t=>t!==e)),disabled:n,className:`bg-transparent border-0 cursor-pointer p-0 flex`,children:`×`})]},e))}),(0,$.jsx)(g,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>P(!0),disabled:n,children:`Browse models`}),(0,$.jsx)(Ce,{open:ae,onClose:()=>P(!1),selected:M,onToggle:e=>ie(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),title:A===`whitelist`?`Select allowed models`:`Select blocked models`,multi:!0})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 min-w-0`,children:[(0,$.jsxs)(`section`,{"aria-labelledby":`routing-blocking-heading`,className:`flex flex-col gap-0 min-w-0 rounded-card border border-inner-border bg-surface-1 overflow-hidden`,children:[(0,$.jsxs)(`div`,{className:`px-4 pt-4 pb-3 border-b border-inner-border`,children:[(0,$.jsxs)(`h4`,{id:`routing-blocking-heading`,className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(N,{size:15,className:`text-accent`,"aria-hidden":`true`}),`Routing & Client Blocking`]}),(0,$.jsx)(`p`,{className:`mt-1 mb-0 text-badge text-text-tertiary`,children:`Control which gateway routes this key can call and which client apps are blocked before routing.`})]}),(0,$.jsxs)(`div`,{className:`flex flex-col divide-y divide-inner-border`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 px-4 py-3`,children:[(0,$.jsx)(`p`,{className:`text-badge font-semibold text-text-secondary m-0`,children:`Gateway routing`}),Xe.filter(e=>e===`routing:invoke`).map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 py-1.5 px-4 rounded-inset`,style:{minHeight:`38px`,border:`1px solid var(--inner-border)`,background:O.includes(e)?`var(--accent-soft)`:`var(--surface-2)`},children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(N,{size:14,className:`mt-0.5 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-0.5 mb-0 text-badge text-text-tertiary`,children:Qe[e]})]})]}),(0,$.jsx)(K,{checked:O.includes(e),onChange:()=>Oe(e),disabled:n,"aria-label":`Grant ${e}`})]},e))]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 px-4 py-3`,children:[(0,$.jsx)(`p`,{className:`text-badge font-semibold text-text-secondary m-0`,children:`Blocked client apps`}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:de.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 py-1.5 px-4 rounded-inset`,style:{minHeight:`38px`,border:`1px solid var(--inner-border)`,background:F.includes(e.id)?`var(--accent-soft)`:`var(--surface-2)`},children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,$.jsx)(a,{size:14,className:`shrink-0 text-orange`,"aria-hidden":`true`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`text-caption font-semibold text-text-primary`,children:[`Block `,e.label,` Client`]}),(0,$.jsx)(`p`,{className:`mt-0.5 mb-0 text-badge text-text-tertiary`,children:e.id===`9router`?`9router, Omniroute, and Baazar Probes`:`Fingerprint-based detection — best-effort; unrecognised clients are never matched`})]})]}),(0,$.jsx)(K,{checked:F.includes(e.id),onChange:t=>ce(n=>t?[...n,e.id]:n.filter(t=>t!==e.id)),disabled:n,"aria-label":`Block ${e.label} client`})]},e.id))})]})]}),(0,$.jsx)(`div`,{className:`px-4 py-3`,children:(0,$.jsx)(ct,{keyId:e===`edit`&&t?t.id:``,busy:n,scopeGranted:O.includes(`routing:cli_mapping`),onScopeChange:e=>{e!==O.includes(`routing:cli_mapping`)&&Oe(`routing:cli_mapping`)},persistScope:n=>{if(e!==`edit`||!t)return;let r=n?[...new Set([...O,`routing:cli_mapping`])]:O.filter(e=>e!==`routing:cli_mapping`);De.mutate({keyId:t.id,request:{scopes:r}},{onError:e=>_.error(I(e,`Could not update the key's routing scope.`))})}})})]}),(0,$.jsxs)(`section`,{"aria-labelledby":`dashboard-scopes-heading`,className:`flex flex-col gap-0 min-w-0 rounded-card border border-inner-border bg-surface-1 overflow-hidden`,children:[(0,$.jsxs)(`div`,{className:`px-4 pt-4 pb-3 border-b border-inner-border`,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)(ve,{size:15,className:`text-accent`,"aria-hidden":`true`}),`Dashboard / Resources`]}),(0,$.jsx)(`p`,{className:`mt-1 mb-0 text-badge text-text-tertiary`,children:`Grants read or write access to console data — providers, models, configuration, and usage stats. No routing is implied by these scopes.`})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2 p-4`,children:Xe.filter(e=>!e.startsWith(`routing:`)).map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4 py-1.5 px-4 rounded-inset`,style:{minHeight:`38px`,border:`1px solid var(--inner-border)`,background:O.includes(e)?`var(--accent-soft)`:`var(--surface-2)`},children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3 min-w-0`,children:[(()=>{let t=$e[e];return(0,$.jsx)(t,{size:14,className:`mt-0.5 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-0.5 mb-0 text-badge text-text-tertiary`,children:Qe[e]})]})]}),(0,$.jsx)(K,{checked:O.includes(e),onChange:()=>Oe(e),disabled:n,"aria-label":`Grant ${e}`})]},e))})]})]})]})]})]})]})}function pt({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)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(h,{size:13}),onClick:()=>{e!==null&&(be(`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`),_.success(`Key saved to your downloads.`))},children:`Save this key`})]})]})})}function mt(e,t){if(t)return`Permanent — lift manually`;let n=new Date(e);if(!Number.isFinite(n.getTime()))return`—`;let r=e-Date.now(),i=n.toLocaleString();if(r<=0)return`${i} (lapsed)`;let a=Math.ceil(r/6e4);if(a<60)return`${i} (in ${a}m)`;let o=Math.floor(a/60);return o<24?`${i} (in ${o}h)`:`${i} (in ${Math.floor(o/24)}d)`}function ht({onClose:e}){let t=s(!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 caller is banned after repeated invalid-model requests. A ban is scoped to the API key that made them, so other keys used from the same address keep working — unless an operator banned the address outright.`,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)(T,{compact:!0,label:`Loading banned users…`}):t.isError?(0,$.jsx)(w,{compact:!0,message:I(t.error,`Could not load banned users.`),onRetry:()=>void t.refetch()}):a.length===0?(0,$.jsx)(E,{compact:!0,title:`No banned users`,message:`No client address is currently banned for model abuse.`,icon:(0,$.jsx)(Ge,{size:20})}):(0,$.jsx)(`div`,{className:`rounded-inset border border-inner-border`,children:(0,$.jsx)(Le,{maxHeight:480,scrollRegion:!0,headers:[`Client IP`,`API key`,`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:`font-mono tabular-nums text-badge text-text-secondary whitespace-nowrap`,children:e.apiKeyId?`${e.apiKeyId.slice(0,8)}…`:`—`}),(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:e.apiKeyId?`This key only`:`All keys from this IP`}),(0,$.jsx)(`td`,{className:`text-badge text-text-secondary whitespace-nowrap`,children:mt(e.expiresAt,e.permanent===!0)}),(0,$.jsx)(`td`,{className:`text-right whitespace-nowrap`,children:(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(qe,{size:13}),disabled:n.isPending,onClick:()=>i(e),children:`Unban`})})]},e.identity))})})]}),(0,$.jsx)(J,{justify:`flex-end`,gap:`0px`,children:(0,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:e,children:`Close`})})]})}),(0,$.jsx)(ye,{open:r!==null,onClose:()=>i(null),onConfirm:async()=>{r&&(await n.mutateAsync(r.identity),_.success(`Unbanned ${r.ip}.`),i(null))},title:`Lift this ban?`,message:r?`Lift the ban on ${r.ip}${r.apiKeyId?` for this API key`:``}? The caller can reach the gateway again immediately.`:`Lift this ban?`,confirmLabel:`Unban`,danger:!0})]})}var gt=e=>(e??0).toLocaleString(),_t=e=>e?new Date(e).toLocaleString():`—`;function vt({keyId:e}){let t=we(),[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)(g,{variant:`secondary`,size:`sm`,icon:i?(0,$.jsx)(S,{size:13}):(0,$.jsx)(C,{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=>_.error(I(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 yt({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`:gt(t)})]})}function bt(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 xt({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?`${H(e)} · Unlimited`:`${H(e)} / ${H(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?`${H(e)} tokens consumed, no lifetime budget set`:`${H(e)} of ${H(t)} tokens consumed`,children:(0,$.jsx)(`div`,{className:i?`h-full rounded bg-status-danger`:`h-full rounded bg-status-success`,style:{width:`${r}%`}})})]})}var St=6;function Ct(e){return e.filter(e=>e.revokedAt===null).length}function wt(e){return e.reduce((e,t)=>e+t.allTime.totalTokens,0)}function Tt({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:H(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=Re(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:[H(e),` / `,H(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`:`${H(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":`${H(e)} of ${H(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 Et({parentId:e,childId:t}){let n=Me(e,t);if(n.isPending)return(0,$.jsx)(T,{label:`Loading activity…`,compact:!0});if(n.isError)return(0,$.jsx)(w,{compact:!0,message:I(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:gt(e.todayRequests)}),(0,$.jsx)(`td`,{children:gt(e.todayErrors)}),(0,$.jsx)(`td`,{children:H(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:H(e.totalTokens)}),(0,$.jsx)(`td`,{children:_t(e.startedAt)})]},e.requestId))})]})}):(0,$.jsx)(`p`,{className:`py-3 text-caption text-text-tertiary`,children:`No recent requests.`})]})]}):null}function Dt({parent:e,onSecretRevealed:t}){let[n,r]=(0,Q.useState)(null),[i,o]=(0,Q.useState)(`active`),[s,c]=(0,Q.useState)(null),l=ue(),u=Y(),f=ke(),p=Ae(),m=Z(e.id),h=e.keyMode!==`share`,v=Te(h?null:e.id),y=v.data??[],b=i===`active`?y.filter(e=>e.revokedAt===null):y.filter(e=>e.revokedAt!==null),x=y.filter(e=>e.revokedAt===null&&e.allTime.totalTokens===0);(0,Q.useEffect)(()=>{r(null)},[e.id]);let S=async(t,n)=>{let r=(await d(t,St,t=>p.mutateAsync({parentKeyId:e.id,childKeyId:t.id,deferInvalidation:!0}))).filter(e=>e.status===`fulfilled`).length;await l.invalidateQueries({queryKey:L.apiKeys.sharedKeys(e.id)}),await l.invalidateQueries({queryKey:L.apiKeys.all}),await v.refetch();let i=t.length-r;i>0?_.error(`Revoked ${r} of ${t.length} ${n}; ${i} failed.`):_.success(`Revoked ${r} ${n}.`)},C=u.isPending||f.isPending,[te,D]=(0,Q.useState)(!1),ne=async()=>{if(h){let n=await f.mutateAsync({keyId:e.id});t?.(n.secret);return}await u.mutateAsync({keyId:e.id,regenerate:!0}),_.success(`Link regenerated; the previous URL no longer works.`)},k=()=>{u.mutate({keyId:e.id},{onError:e=>_.error(I(e,`Could not create link.`))})},A=m.data?.url??null,j=bt(h);return(0,$.jsxs)(`div`,{className:`grid min-w-0 gap-6`,children:[(0,$.jsx)(`section`,{"aria-label":`Link`,children:m.isPending?(0,$.jsx)(T,{label:`Loading link…`,compact:!0}):m.isError?(0,$.jsx)(w,{compact:!0,message:I(m.error,`Could not load the link.`),onRetry:()=>void m.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)(re,{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)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(He,{size:13}),loading:C,disabled:C,onClick:()=>D(!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)(re,{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)(g,{variant:`primary`,size:`sm`,loading:C,disabled:C,onClick:k,children:`Create link`})]})}),h?(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)(vt,{keyId:e.id})]}):null,h?(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:H(e.tokensConsumed)})]}),(0,$.jsx)(yt,{label:`Requests / min`,value:e.requestsPerMinute}),(0,$.jsx)(yt,{label:`Daily tokens`,value:e.dailyTokenLimit}),(0,$.jsx)(yt,{label:`Monthly tokens`,value:e.monthlyTokenLimit}),(0,$.jsx)(xt,{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)(Tt,{consumed:wt(y),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: `,Ct(y)]}),(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:()=>o(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))}),s===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:s===`all`?`Revoke ${b.length}?`:`Revoke ${x.length} unused?`}),(0,$.jsx)(g,{variant:`danger`,size:`sm`,loading:p.isPending,onClick:()=>{let e=s===`all`?b:x,t=s===`all`?`recipients`:`unused recipients`;c(null),S(e,t)},children:`Confirm`}),(0,$.jsx)(g,{variant:`ghost`,size:`sm`,onClick:()=>c(null),children:`Cancel`})]}),(0,$.jsx)(g,{variant:`ghost`,size:`sm`,disabled:x.length===0||p.isPending,title:x.length===0?`No active recipient has spent zero tokens`:`Revoke ${x.length} recipient${x.length===1?``:`s`} that never spent a token`,onClick:()=>c(`unused`),icon:(0,$.jsx)(a,{size:13}),children:`Revoke no-usage`}),(0,$.jsx)(g,{variant:`ghost`,size:`sm`,disabled:b.length===0||p.isPending,title:b.length===0?`Nothing to revoke in this view`:`Revoke all ${b.length} listed recipient${b.length===1?``:`s`}`,onClick:()=>c(`all`),icon:(0,$.jsx)(a,{size:13}),children:`Revoke all`}),(0,$.jsx)(g,{variant:`ghost`,size:`sm`,onClick:()=>void v.refetch(),icon:(0,$.jsx)(ie,{size:13,className:v.isFetching?`animate-spin`:void 0}),children:`Refresh`})]}),v.isPending&&!v.data?(0,$.jsx)(T,{label:`Loading recipients…`,compact:!0}):v.isError?(0,$.jsx)(w,{compact:!0,message:I(v.error,`Could not load recipients.`),onRetry:()=>void v.refetch()}):b.length===0?(0,$.jsx)(E,{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:b.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)(_e,{size:14}):(0,$.jsx)(ee,{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:H(t.today.totalTokens)}),(0,$.jsx)(`td`,{children:H(t.allTime.totalTokens)}),(0,$.jsx)(`td`,{children:_t(t.lastUsedAt)}),(0,$.jsx)(`td`,{className:`text-right whitespace-nowrap`,children:(0,$.jsx)(g,{variant:`danger`,size:`sm`,disabled:p.isPending||!!t.revokedAt,onClick:()=>p.mutate({parentKeyId:e.id,childKeyId:t.id},{onError:e=>_.error(I(e,`Could not revoke key.`))}),children:`Revoke`})})]}),i?(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:7,className:`p-0`,children:(0,$.jsx)(Et,{parentId:e.id,childId:t.id})})}):null]},t.id)})})]})})]})]}),(0,$.jsx)(ye,{open:te,onClose:()=>D(!1),onConfirm:ne,title:j.title,message:j.message,confirmLabel:j.confirmLabel,danger:!0})]})}function Ot({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)(Dt,{parent:e,onSecretRevealed:n})})}function kt(){let e=je(),t=ge(),n=De(),r=Ee(),i=Oe(),a=ke(),o=we(),s=X(),{copy:c}=V(),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(null),[v,y]=(0,Q.useState)(null),[ee,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(null),[te,ne]=(0,Q.useState)(!1),[re,O]=(0,Q.useState)(null),[M,ie]=(0,Q.useState)(null),N=e.data??[],ae=t.data?.isPlatformAdmin??!1,oe=e=>{x(null),C(e)},P=async e=>{try{let{secret:t}=await o.mutateAsync({keyId:e.id});await c(t)?_.success(`API key copied`):_.error(`Clipboard unavailable on this origin`)}catch(e){_.error(I(e,`Could not reveal API key.`))}},se=bt(!0);return(0,$.jsxs)(B,{children:[(0,$.jsx)(z,{title:`API Credentials`,subtitle:`Manage tenant API keys, model access, budgets, and sharing.`,icon:(0,$.jsx)(D,{size:16}),action:(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[ae?(0,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:()=>ne(!0),icon:(0,$.jsx)(Ge,{size:13}),children:`Banned Users`}):null,(0,$.jsx)(g,{variant:`primary`,size:`sm`,onClick:()=>{x(null),u(!0)},icon:(0,$.jsx)(j,{size:13}),children:`Create Key`})]})}),(0,$.jsx)(R,{children:e.isPending&&!e.data?(0,$.jsx)(T,{label:`Loading API keys…`}):e.isError&&!e.data?(0,$.jsx)(w,{message:I(e.error,`Could not load credentials.`),onRetry:()=>void e.refetch()}):N.length===0?(0,$.jsx)(E,{title:`No API keys issued`,message:`Generate a secret key to authenticate your SDK or CLI client against the gateway.`,icon:(0,$.jsx)(D,{size:20})}):(0,$.jsx)(`div`,{className:`scroll-region max-h-280 pr-1`,children:(0,$.jsx)(b,{items:N,label:`API credentials`,disabled:s.isPending,onReorder:e=>s.mutate(e,{onError:e=>_.error(I(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)(W,{tone:e.revokedAt?`err`:e.enabled?`ok`:`warn`,children:e.revokedAt?`revoked`:e.enabled?`enabled`:`disabled`}),(0,$.jsx)(W,{tone:e.keyMode===`share`?`accent`:`default`,children:e.keyMode===`share`?`share template`:`personal`}),e.isDefault?(0,$.jsx)(W,{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`}),H(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`}),U(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`}),U(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`}),U(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`}),U(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`}),U(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)(K,{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:()=>_.success(`${e.label||`API credential`} ${t?`enabled`:`disabled`}`),onError:e=>_.error(I(e,`Could not update credential state.`))})}),(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(A,{size:13}),onClick:()=>{x(null),f(e)},children:`Edit`}),!e.revokedAt&&e.keyMode!==`share`?(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(p,{size:13}),onClick:()=>void P(e),disabled:o.isPending,children:`Copy`}):null,!e.revokedAt&&(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(We,{size:13}),onClick:()=>oe(e),children:e.keyMode===`share`?`Recipients`:`Share`}),!e.revokedAt&&e.keyMode!==`share`&&(0,$.jsx)(g,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(He,{size:13}),onClick:()=>{x(null),y(e)},disabled:a.isPending,children:`Rotate`}),!e.revokedAt&&!e.isDefault&&(0,$.jsx)(g,{variant:`danger`,size:`sm`,icon:(0,$.jsx)(ce,{size:13}),onClick:()=>h(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:re,children:(0,$.jsx)(ft,{mode:`create`,record:null,busy:n.isPending,onClose:()=>u(!1),actionsRef:O,onDone:e=>{n.mutate(e,{onSuccess:t=>{u(!1),x(ut(e.keyMode,t.secret)),_.success(`API key created`)},onError:e=>_.error(I(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:M,children:(0,$.jsx)(ft,{mode:`edit`,record:d,busy:r.isPending,onClose:()=>f(null),actionsRef:ie,onDone:e=>{d&&r.mutate({keyId:d.id,request:e},{onSuccess:t=>{f(null),x(ut(e.keyMode,t.secret)),_.success(`API key updated`)},onError:e=>_.error(I(e,`Could not update API key.`))})}})}),S?(0,$.jsx)(Ot,{parent:S,onClose:()=>C(null),onSecretRevealed:e=>{C(null),x(e)}}):null,(0,$.jsx)(ye,{open:v!==null,onClose:()=>y(null),onConfirm:async()=>{if(!v)return;let e=await a.mutateAsync({keyId:v.id});x(e.secret),_.success(`Rotated ${v.label||v.id}.`),y(null)},title:se.title,message:se.message,confirmLabel:se.confirmLabel,danger:!0}),(0,$.jsx)(ye,{open:m!==null,onClose:()=>h(null),onConfirm:async()=>{m&&(await i.mutateAsync(m.id),_.success(`Revoked ${m.label||m.id}.`),h(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}),te?(0,$.jsx)(ht,{onClose:()=>ne(!1)}):null,(0,$.jsx)(pt,{secret:ee,onClose:()=>x(null)})]})}function At(){let e=F(),t=P(),n=e.data;if(e.isPending)return(0,$.jsx)(T,{label:`Loading compression settings…`});if(e.isError||!n)return(0,$.jsx)(w,{message:I(e.error,`Failed to load compression settings`),onRetry:()=>void e.refetch()});let r=n.rtkPruneEnabled,a=n.ponyTailEnabled;return(0,$.jsxs)(B,{children:[(0,$.jsx)(z,{title:`Compression`,subtitle:`Shrink requests before they reach the provider`,icon:(0,$.jsx)(o,{size:16})}),(0,$.jsx)(R,{children:(0,$.jsxs)(q,{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)(Ue,{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)(J,{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)(J,{gap:`8px`,className:`shrink-0 items-center ml-auto`,children:[(0,$.jsx)(Se,{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=>_.error(I(e,`Could not update RTK strength.`))}),options:[{value:`lite`,label:`Lite`},{value:`full`,label:`Full`},{value:`ultra`,label:`Ultra`}]}),(0,$.jsx)(K,{id:`compression-rtk`,"aria-label":`Enable RTK prune`,checked:r,onChange:e=>t.mutate({rtkPruneEnabled:e},{onError:e=>_.error(I(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)(i,{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)(J,{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)(J,{gap:`8px`,className:`shrink-0 items-center ml-auto`,children:[(0,$.jsx)(Se,{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=>_.error(I(e,`Could not update PonyTail strength.`))}),options:[{value:`lite`,label:`Lite`},{value:`full`,label:`Full`},{value:`ultra`,label:`Ultra`}]}),(0,$.jsx)(K,{id:`compression-ponytail`,"aria-label":`Enable PonyTail`,checked:a,onChange:e=>t.mutate({ponyTailEnabled:e},{onError:e=>_.error(I(e,`Could not update PonyTail.`))})})]})]}),r||a?(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)(v,{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 jt(){return le({queryKey:L.remoteSupport.status,queryFn:()=>pe(`/remote-support/status`)})}function Mt(){let e=ue();return me({mutationFn:e=>pe(`/remote-support/start`,{method:`POST`,body:JSON.stringify({tool:e})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:L.remoteSupport.status})}})}function Nt(){let e=ue();return me({mutationFn:e=>pe(`/remote-support/stop`,{method:`POST`,body:JSON.stringify(e===void 0?{}:{tool:e})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:L.remoteSupport.status})}})}var Pt={cloudflared:`cloudflared`,tailscale:`Tailscale`},Ft={cloudflared:`Publish a temporary public URL without opening a port.`,tailscale:`Give a helper a private address on your own tailnet.`};function It({tool:e}){return e===`cloudflared`?(0,$.jsxs)(`svg`,{viewBox:`0 0 24 24`,className:`size-8 shrink-0`,"aria-hidden":`true`,fill:`currentColor`,children:[(0,$.jsx)(`path`,{d:`M16.5 18.4a4.6 4.6 0 0 1-3.2-1.3l-6-5.9a2.4 2.4 0 0 0-3.3 0 2.3 2.3 0 0 0 0 3.3l5.4 5.3a.9.9 0 0 1-1.3 1.3L2.7 15.8a4.1 4.1 0 0 1 0-5.8 4.2 4.2 0 0 1 5.8 0l6 5.9a2.4 2.4 0 0 0 3.3 0 2.3 2.3 0 0 0 0-3.3l-4.2-4.1a.9.9 0 0 1 1.3-1.3l4.2 4.1a4.1 4.1 0 0 1 0 5.8 4.2 4.2 0 0 1-2.6 1.3Z`}),(0,$.jsx)(`path`,{d:`M7.6 18.4a4.5 4.5 0 0 1-3-1.1 5.4 5.4 0 0 1-1.5-3.5 6 6 0 0 1 .4-2 .9.9 0 0 1 1.7.6 4.2 4.2 0 0 0-.3 1.4 3.6 3.6 0 0 0 1 2.3 2.7 2.7 0 0 0 1.8.7.9.9 0 0 1 0 1.8Z`})]}):(0,$.jsxs)(`svg`,{viewBox:`0 0 24 24`,className:`size-8 shrink-0`,"aria-hidden":`true`,fill:`currentColor`,children:[(0,$.jsx)(`path`,{d:`M12 3.2a4.4 4.4 0 0 0-4.4 4.4v2.2H4.6a2.2 2.2 0 0 0 0 4.4h3v2.2a4.4 4.4 0 0 0 8.8 0v-2.2h1.1a3.3 3.3 0 0 0 0-6.6h-1.1V7.6A4.4 4.4 0 0 0 12 3.2Zm0 2.2a2.2 2.2 0 0 1 2.2 2.2v6.6a2.2 2.2 0 0 1-4.4 0V7.6A2.2 2.2 0 0 1 12 5.4Z`}),(0,$.jsx)(`path`,{d:`M6.6 11h4.2v2.2H6.6zM13.2 11h4.2v2.2h-4.2z`})]})}function Lt({tool:e}){let t=jt(),n=Mt(),r=Nt(),{copied:i,copy:a}=V(2e3),o=t.data?.active===e,s=n.isPending||r.isPending,c=o?t.data?.url??null:null,[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(o);(0,Q.useEffect)(()=>{!n.isPending&&!r.isPending&&f(o)},[o,n.isPending,r.isPending]);let h=async t=>{f(t);try{let i=t?await n.mutateAsync(e):await r.mutateAsync(e);if(i.blocker!==null&&i.message!==null){u(i.message),_.error(i.message),f(!t);return}u(null),_.success(t?`${Pt[e]} started`:`${Pt[e]} stopped`)}catch{_.error(`Could not ${t?`start`:`stop`} ${Pt[e]}`),f(!t)}},v=async()=>{if(c!==null){if(await a(c)){_.success(`Remote URL copied`,c);return}_.error(`Clipboard unavailable on this origin`)}};return(0,$.jsxs)(`div`,{className:`rounded-control border border-inner-border bg-surface-2 p-5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,$.jsx)(It,{tool:e}),(0,$.jsx)(`h3`,{className:`text-caption font-semibold`,children:Pt[e]})]}),(0,$.jsx)(K,{checked:d,disabled:s,onChange:e=>void h(e),"aria-label":`Toggle ${Pt[e]} remote support`})]}),n.isPending?(0,$.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-badge text-text-secondary`,children:[(0,$.jsx)(y,{size:14,className:`animate-spin`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`animate-pulse`,children:`Waiting for address…`})]}),(0,$.jsx)(g,{variant:`secondary`,size:`sm`,onClick:()=>void h(!1),children:`Cancel`})]}):c===null?l===null?(0,$.jsx)(`p`,{className:`mt-2 text-badge leading-normal text-text-tertiary`,children:Ft[e]}):(0,$.jsxs)(`div`,{className:`mt-2 rounded-control border border-warning/30 bg-warning/10 p-3 text-badge leading-normal text-text-secondary`,children:[(0,$.jsx)(`p`,{className:`font-medium text-warning`,children:`Setup needed`}),(0,$.jsx)(`p`,{className:`mt-1 whitespace-pre-wrap break-words`,children:l}),(()=>{let e=l.match(/https:\/\/login\.tailscale\.com\/f\/serve\?[^\s]+/);return e?(0,$.jsx)(`a`,{href:e[0],target:`_blank`,rel:`noreferrer`,className:`mt-2 inline-block font-medium text-accent underline`,children:`Enable Tailscale Serve →`}):null})()]}):(0,$.jsxs)(`div`,{className:`mt-3 flex items-center gap-3`,children:[(0,$.jsx)(`code`,{className:`min-w-0 flex-1 truncate font-mono text-badge text-text-primary`,title:c,children:c}),(0,$.jsxs)(g,{variant:`secondary`,size:`sm`,onClick:()=>void v(),children:[i?(0,$.jsx)(m,{size:14}):(0,$.jsx)(p,{size:14}),i?`Copied`:`Copy`]})]})]})}function Rt(){let{copied:e,copy:t}=V(2e3),n=`${window.location.origin}/v1`,r=async()=>{if(await t(n)){_.success(`Gateway endpoint copied`,n);return}_.error(`Clipboard unavailable on this origin`)};return(0,$.jsxs)(B,{children:[(0,$.jsx)(z,{title:`Gateway Endpoint`,subtitle:`Universal OpenAI & Anthropic Wire API Endpoint Compatible`,icon:(0,$.jsx)(f,{size:16})}),(0,$.jsx)(R,{children:(0,$.jsxs)(q,{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)(g,{variant:`secondary`,size:`sm`,icon:e?(0,$.jsx)(m,{size:13}):(0,$.jsx)(p,{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 zt(){let e=F(),t=P(),n=e.data?.invokeDisabled===!0,r=e=>{t.mutate({invokeDisabled:!e},{onSuccess:()=>_.success(e?`Invoke enabled — routing has resumed.`:`Invoke disabled — every request now returns 503 and nothing upstream is dialed.`),onError:e=>_.error(e instanceof Error?e.message:`Could not save the setting`)})};return(0,$.jsxs)(B,{children:[(0,$.jsx)(z,{title:`Invoke Switch`,subtitle:`Stop every request without deleting anything`,icon:(0,$.jsx)(M,{size:16})}),(0,$.jsx)(R,{children:(0,$.jsxs)(q,{gap:`10px`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsxs)(`p`,{className:`min-w-0 text-caption leading-normal text-text-secondary`,children:[`Off refuses every `,(0,$.jsx)(`code`,{className:`font-mono`,children:`/v1/*`}),` request with 503. Nothing is dispatched upstream, and no account, key, or model is changed — the dashboard stays reachable so you can turn it back on.`]}),(0,$.jsx)(K,{checked:!n,disabled:e.isLoading||t.isPending,onChange:e=>r(e),"aria-label":`Toggle invoke for every request`})]}),n?(0,$.jsxs)(`p`,{className:`flex items-start gap-2 text-caption leading-normal text-warning`,children:[(0,$.jsx)(v,{size:14,className:`mt-0.5 shrink-0`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:`Invoke is off. Every API request is being refused, and any client pointed at this gateway will keep failing until you switch it back on.`})]}):null]})})]})}function Bt(){let e=jt();return(0,$.jsxs)(B,{children:[(0,$.jsx)(z,{title:`Remote Support`,subtitle:`Reach this gateway from outside the local network`,icon:(0,$.jsx)(Be,{size:16})}),(0,$.jsx)(R,{children:(0,$.jsxs)(q,{gap:`10px`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 max-medium:grid-cols-1`,children:[(0,$.jsx)(Lt,{tool:`cloudflared`}),(0,$.jsx)(Lt,{tool:`tailscale`})]}),e.data?.blocker!==null&&e.data?.message!==null?(0,$.jsx)(`p`,{className:`text-badge leading-normal text-red-primary`,children:e.data?.message}):null,(0,$.jsxs)(`p`,{className:`text-caption leading-normal text-text-secondary`,children:[`Either way the gateway still sees the tunnel's address as the client, so set`,` `,(0,$.jsx)(`code`,{className:`font-mono`,children:`TRUSTED_PROXY_CIDRS`}),` to the edge that forwards to it — otherwise every remote caller is recorded as the loopback address.`]}),(0,$.jsx)(`p`,{className:`text-badge leading-normal text-text-tertiary`,children:`cloudflared and Tailscale are not installed by Cartethyia — install either one yourself first. The tunnel is launched detached from this process, so it survives a gateway restart.`})]})})]})}function Vt(){return(0,$.jsxs)(q,{gap:`16px`,children:[(0,$.jsx)(Rt,{}),(0,$.jsx)(zt,{}),(0,$.jsx)(Bt,{}),(0,$.jsx)(At,{}),(0,$.jsx)(kt,{})]})}export{Vt as default};
|
|
Binary file
|