cartethyia 2.7.6 → 2.7.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/.env.example +4 -2
  2. package/README.md +25 -1
  3. package/dist/dashboard/assets/{BannedPage-B1N603cM.js → BannedPage-B05aF8Dg.js} +1 -1
  4. package/dist/dashboard/assets/BannedPage-B05aF8Dg.js.gz +0 -0
  5. package/dist/dashboard/assets/{CliToolDetailPage-9q4_4NoK.js → CliToolDetailPage-CLUhmjUy.js} +2 -2
  6. package/dist/dashboard/assets/CliToolDetailPage-CLUhmjUy.js.gz +0 -0
  7. package/dist/dashboard/assets/{CliToolsPage-DwshGtK-.js → CliToolsPage-CQmrqqrk.js} +1 -1
  8. package/dist/dashboard/assets/CliToolsPage-CQmrqqrk.js.gz +0 -0
  9. package/dist/dashboard/assets/{CombosPage-D762MIkp.js → CombosPage-CHG_1Wr3.js} +1 -1
  10. package/dist/dashboard/assets/CombosPage-CHG_1Wr3.js.gz +0 -0
  11. package/dist/dashboard/assets/{ConsoleLogPage-KRYjHZsX.js → ConsoleLogPage-DPgbklad.js} +1 -1
  12. package/dist/dashboard/assets/ConsoleLogPage-DPgbklad.js.gz +0 -0
  13. package/dist/dashboard/assets/CustomizationPage-pnfAqr_-.js +1 -0
  14. package/dist/dashboard/assets/CustomizationPage-pnfAqr_-.js.gz +0 -0
  15. package/dist/dashboard/assets/HealthEventsModal-DGJuU2A6.js +1 -0
  16. package/dist/dashboard/assets/HealthEventsModal-DGJuU2A6.js.gz +0 -0
  17. package/dist/dashboard/assets/{InjectSystemPromptPanel-d5v3K_Yc.js → InjectSystemPromptPanel-C-e2AMz6.js} +2 -2
  18. package/dist/dashboard/assets/InjectSystemPromptPanel-C-e2AMz6.js.gz +0 -0
  19. package/dist/dashboard/assets/{LoginPage-Ccv4tjNS.js → LoginPage-J8wPbmfT.js} +1 -1
  20. package/dist/dashboard/assets/LoginPage-J8wPbmfT.js.gz +0 -0
  21. package/dist/dashboard/assets/{OverviewPage-DN9fYNWA.js → OverviewPage-BSQnF2Lp.js} +1 -1
  22. package/dist/dashboard/assets/OverviewPage-BSQnF2Lp.js.gz +0 -0
  23. package/dist/dashboard/assets/ProviderDetailPage-DK_e0FJz.js +7 -0
  24. package/dist/dashboard/assets/ProviderDetailPage-DK_e0FJz.js.gz +0 -0
  25. package/dist/dashboard/assets/ProvidersPage-D_a3r6Gc.js +1 -0
  26. package/dist/dashboard/assets/ProvidersPage-D_a3r6Gc.js.gz +0 -0
  27. package/dist/dashboard/assets/{ProxyPage-DxjvUzSD.js → ProxyPage-BBTRBAQ3.js} +1 -1
  28. package/dist/dashboard/assets/ProxyPage-BBTRBAQ3.js.gz +0 -0
  29. package/dist/dashboard/assets/QuotaPage-B2WqMSG1.js +1 -0
  30. package/dist/dashboard/assets/QuotaPage-B2WqMSG1.js.gz +0 -0
  31. package/dist/dashboard/assets/{SettingsPage-BW4AKj2H.js → SettingsPage-D7xp5Ij_.js} +1 -1
  32. package/dist/dashboard/assets/SettingsPage-D7xp5Ij_.js.gz +0 -0
  33. package/dist/dashboard/assets/{SetupPage-44BZrxFC.js → SetupPage-LND6_Ss7.js} +1 -1
  34. package/dist/dashboard/assets/SetupPage-LND6_Ss7.js.gz +0 -0
  35. package/dist/dashboard/assets/{StudioPage-DRPavCdU.js → StudioPage-BzNnm6Bi.js} +2 -2
  36. package/dist/dashboard/assets/StudioPage-BzNnm6Bi.js.gz +0 -0
  37. package/dist/dashboard/assets/{UsagePage-B7M7LvMM.js → UsagePage-C1TbL24N.js} +2 -2
  38. package/dist/dashboard/assets/UsagePage-C1TbL24N.js.gz +0 -0
  39. package/dist/dashboard/assets/{entry-D6WvojeD.js → entry-vqGb8yVz.js} +3 -3
  40. package/dist/dashboard/assets/entry-vqGb8yVz.js.gz +0 -0
  41. package/dist/dashboard/assets/formatters-DP-5E01-.js +1 -0
  42. package/dist/dashboard/assets/formatters-DP-5E01-.js.gz +0 -0
  43. package/dist/dashboard/assets/{index-Ko4dLRnV.js → index-D36vCZht.js} +2 -2
  44. package/dist/dashboard/assets/index-D36vCZht.js.gz +0 -0
  45. package/dist/dashboard/assets/{select-BHqpd-bg.js → select-C9Ssle9b.js} +1 -1
  46. package/dist/dashboard/assets/select-C9Ssle9b.js.gz +0 -0
  47. package/dist/dashboard/index.html +2 -2
  48. package/dist/dashboard/index.html.gz +0 -0
  49. package/dist/dashboard/precompressed-assets.json +22 -22
  50. package/migrations/full-postgres/0043_add_provider_custom_user_agent.sql +14 -0
  51. package/migrations/lite-sqlite3/0043_add_provider_custom_user_agent.sql +10 -0
  52. package/package.json +3 -1
  53. package/src/config/security.ts +1 -1
  54. package/src/config/spec.ts +13 -6
  55. package/src/console/cli-tools/cartethyia-websearch-plugin.ts +186 -0
  56. package/src/console/cli-tools/injectors/opencode.ts +42 -14
  57. package/src/console/providers/catalog/contracts.ts +4 -0
  58. package/src/console/providers/catalog/routes.ts +1 -0
  59. package/src/console/providers/detail/routes.ts +8 -0
  60. package/src/console/providers/detail/store.ts +4 -0
  61. package/src/console/quota/account-quota-tenant.ts +74 -0
  62. package/src/observability/telemetry-buffer.ts +2 -1
  63. package/src/persistence/boot.ts +13 -4
  64. package/src/persistence/schema.ts +7 -1
  65. package/src/protocol/canonical-model.ts +7 -0
  66. package/src/protocol/request/gemini.ts +20 -1
  67. package/src/protocol/tool-identity.ts +15 -1
  68. package/src/providers/default-registry.ts +8 -2
  69. package/src/providers/discovery/discovery-types.ts +18 -0
  70. package/src/providers/discovery/probe-phases.ts +45 -0
  71. package/src/providers/discovery/probing-service.ts +41 -6
  72. package/src/providers/integrations/antigravity/antigravity-protocol.ts +20 -2
  73. package/src/providers/integrations/antigravity/antigravity.ts +24 -0
  74. package/src/providers/integrations/codex/codex.ts +28 -1
  75. package/src/providers/integrations/qoder/chat-proto.ts +328 -0
  76. package/src/providers/integrations/qoder/claim-qoder-credits.ts +258 -0
  77. package/src/providers/integrations/qoder/qoder-adapter.ts +275 -0
  78. package/src/providers/integrations/qoder/qoder-auth.ts +201 -0
  79. package/src/providers/integrations/qoder/qoder-body.ts +78 -0
  80. package/src/providers/integrations/qoder/qoder-catalog.ts +5 -1
  81. package/src/providers/integrations/qoder/qoder-chat.ts +514 -0
  82. package/src/providers/integrations/qoder/qoder-cosy.ts +162 -0
  83. package/src/providers/integrations/qoder/qoder-grpc.ts +667 -0
  84. package/src/providers/integrations/qoder/qoder-ide.ts +584 -0
  85. package/src/providers/integrations/qoder/qoder-oauth.ts +4 -4
  86. package/src/providers/integrations/qoder/qoder-quota.ts +1 -1
  87. package/src/providers/integrations/qoder/qoder-realm.ts +40 -4
  88. package/src/providers/integrations/qoder/qoder-types.ts +51 -0
  89. package/src/providers/integrations/qoder/qoder-umid.ts +123 -8
  90. package/src/providers/integrations/qoder/qoder.ts +147 -1889
  91. package/src/providers/provider-contracts.ts +7 -0
  92. package/src/providers/provider-usage.ts +9 -6
  93. package/src/security/abuse.ts +5 -5
  94. package/src/transport/dispatch/upstream.ts +4 -2
  95. package/src/transport/routing/route-catalog.ts +8 -0
  96. package/src/transport/routing/route-model.ts +4 -0
  97. package/src/transport/routing/router.ts +8 -117
  98. package/dist/dashboard/assets/BannedPage-B1N603cM.js.gz +0 -0
  99. package/dist/dashboard/assets/CliToolDetailPage-9q4_4NoK.js.gz +0 -0
  100. package/dist/dashboard/assets/CliToolsPage-DwshGtK-.js.gz +0 -0
  101. package/dist/dashboard/assets/CombosPage-D762MIkp.js.gz +0 -0
  102. package/dist/dashboard/assets/ConsoleLogPage-KRYjHZsX.js.gz +0 -0
  103. package/dist/dashboard/assets/CustomizationPage-DXsxk5uM.js +0 -1
  104. package/dist/dashboard/assets/CustomizationPage-DXsxk5uM.js.gz +0 -0
  105. package/dist/dashboard/assets/HealthEventsModal-BEjAjD4F.js +0 -1
  106. package/dist/dashboard/assets/HealthEventsModal-BEjAjD4F.js.gz +0 -0
  107. package/dist/dashboard/assets/InjectSystemPromptPanel-d5v3K_Yc.js.gz +0 -0
  108. package/dist/dashboard/assets/LoginPage-Ccv4tjNS.js.gz +0 -0
  109. package/dist/dashboard/assets/OverviewPage-DN9fYNWA.js.gz +0 -0
  110. package/dist/dashboard/assets/ProviderDetailPage-BY0ieUgz.js +0 -5
  111. package/dist/dashboard/assets/ProviderDetailPage-BY0ieUgz.js.gz +0 -0
  112. package/dist/dashboard/assets/ProvidersPage-DNsbfea2.js +0 -1
  113. package/dist/dashboard/assets/ProvidersPage-DNsbfea2.js.gz +0 -0
  114. package/dist/dashboard/assets/ProxyPage-DxjvUzSD.js.gz +0 -0
  115. package/dist/dashboard/assets/QuotaPage-OaHScjpX.js +0 -1
  116. package/dist/dashboard/assets/QuotaPage-OaHScjpX.js.gz +0 -0
  117. package/dist/dashboard/assets/SettingsPage-BW4AKj2H.js.gz +0 -0
  118. package/dist/dashboard/assets/SetupPage-44BZrxFC.js.gz +0 -0
  119. package/dist/dashboard/assets/StudioPage-DRPavCdU.js.gz +0 -0
  120. package/dist/dashboard/assets/UsagePage-B7M7LvMM.js.gz +0 -0
  121. package/dist/dashboard/assets/entry-D6WvojeD.js.gz +0 -0
  122. package/dist/dashboard/assets/formatters-u7JPB5BX.js +0 -1
  123. package/dist/dashboard/assets/formatters-u7JPB5BX.js.gz +0 -0
  124. package/dist/dashboard/assets/index-Ko4dLRnV.js.gz +0 -0
  125. package/dist/dashboard/assets/select-BHqpd-bg.js.gz +0 -0
  126. package/src/providers/integrations/qoder/qoder-text-tools.ts +0 -277
@@ -1,4 +1,4 @@
1
- import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{c as i,g as a,k as o,m as s}from"./numbers-CoqpaDMx.js";import{n as c,r as l}from"./state-DHmEnLa2.js";import{t as u}from"./layers-2-glBbjl.js";import{n as d,t as f}from"./dialog-BK-NRr5u.js";import{t as p}from"./pencil-768ysRAr.js";import{t as m}from"./plus-DIdX_g-x.js";import{t as h}from"./search-JOKus9rb.js";import{t as g}from"./settings-2-Ds9DQp0t.js";import{t as _}from"./trash-Cppn5c3R.js";import{C as v,T as y,v as ee}from"./assert-CidQVoNo.js";import{i as b,l as x,n as S,o as C,t as w}from"./query-keys-YSoQOUh6.js";import{t as te}from"./useMutation-CbCP4w1o.js";import{_ as ne,ft as re,pt as T,y as ie}from"./entry-D6WvojeD.js";import{n as E,r as D,t as O}from"./card-CxDw0lK6.js";import{t as k}from"./switch-DmZcyTIC.js";import{t as A}from"./badge-BaX2GTrn.js";import{r as j}from"./input-BlmlizVV.js";import{t as M}from"./select-BHqpd-bg.js";import{t as ae}from"./ProviderIcon-jjqXJDA3.js";import{n as N,t as P}from"./stack-j7cXjgYX.js";import{t as F}from"./inline-CHJQwxLa.js";import{t as I}from"./banner-DFH4Bkte.js";import{t as L}from"./pagination-B5aOoweZ.js";import{o as oe,s as se}from"./routing-fnCsxgNO.js";var ce=e(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),le=e(`earth`,[[`path`,{d:`M21.54 15H17a2 2 0 0 0-2 2v4.54`,key:`1djwo0`}],[`path`,{d:`M7 3.34V5a3 3 0 0 0 3 3a2 2 0 0 1 2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.1.9-2 2-2h3.17`,key:`1tzkfa`}],[`path`,{d:`M11 21.95V18a2 2 0 0 0-2-2a2 2 0 0 1-2-2v-1a2 2 0 0 0-2-2H2.05`,key:`14pb5j`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),R=e(`file-text`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),ue=e(`file-up`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M12 12v6`,key:`3ahymv`}],[`path`,{d:`m15 15-3-3-3 3`,key:`15xj92`}]]),z=e(`grip-vertical`,[[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}],[`circle`,{cx:`9`,cy:`5`,r:`1`,key:`hp0tcf`}],[`circle`,{cx:`9`,cy:`19`,r:`1`,key:`fkjjf6`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`15`,cy:`5`,r:`1`,key:`19l28e`}],[`circle`,{cx:`15`,cy:`19`,r:`1`,key:`f4zoj3`}]]),B=t(n(),1),V=r();function H({items:e,onReorder:t,disabled:n=!1,gap:r=`10px`,renderItem:i,label:a}){let[o,c]=(0,B.useState)(null),[l,u]=(0,B.useState)(null),d=(0,B.useRef)(null),f=()=>{d.current=null,c(null),u(null)},p=(n,r)=>{if(n===r)return;let i=e.map(e=>e.id),a=i.indexOf(n),o=i.indexOf(r);a!==-1&&o!==-1&&(i.splice(o,0,...i.splice(a,1)),t(i))};return(0,V.jsx)(`div`,{role:`list`,"aria-label":a,className:s(`flex flex-col min-w-0`,N(r)??`gap-5`),children:e.map((r,a)=>{let m=o===r.id,h=l===r.id&&o!==null&&o!==r.id,g=r=>{let i=a+r;if(n||i<0||i>=e.length)return;let o=e.map(e=>e.id),[s]=o.splice(a,1);s!==void 0&&(o.splice(i,0,s),t(o))};return(0,V.jsxs)(`div`,{role:`listitem`,className:s(`relative flex items-stretch gap-5 min-w-0 rounded-card transition-opacity duration-150 ease-spring`,m&&`opacity-50`,h&&`before:absolute before:inset-x-0 before:top-0 before:h-0.5 before:bg-accent before:content-['']`),"data-dragging":m?`true`:void 0,"data-drop-target":h?`true`:void 0,onDragOver:e=>{n||d.current===null||(e.preventDefault(),e.dataTransfer.dropEffect=`move`,l!==r.id&&u(r.id))},onDrop:e=>{e.preventDefault();let t=d.current;t!==null&&p(t,r.id),f()},children:[(0,V.jsxs)(`div`,{className:`flex flex-none flex-col items-center gap-1 pt-4 text-text-tertiary select-none`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,V.jsx)(`span`,{className:`font-mono text-badge tabular-nums leading-none`,children:a+1}),(0,V.jsx)(`button`,{type:`button`,draggable:!n,"aria-label":`Drag item at position ${a+1} to reorder`,title:`Drag to reorder`,disabled:n,onDragStart:e=>{d.current=r.id,c(r.id),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,r.id)},onDragEnd:f,className:`grid size-7 cursor-grab place-items-center rounded-control text-text-tertiary hover:bg-hover active:cursor-grabbing disabled:cursor-not-allowed`,children:(0,V.jsx)(z,{size:14})})]}),(0,V.jsxs)(`div`,{className:`flex gap-1`,children:[(0,V.jsx)(`button`,{type:`button`,"aria-label":`Move item ${a+1} up`,title:`Move up`,disabled:n||a===0,onClick:()=>g(-1),className:`grid size-7 place-items-center rounded-control text-text-tertiary hover:bg-hover disabled:cursor-not-allowed disabled:opacity-40`,children:(0,V.jsx)(ce,{size:14})}),(0,V.jsx)(`button`,{type:`button`,"aria-label":`Move item ${a+1} down`,title:`Move down`,disabled:n||a===e.length-1,onClick:()=>g(1),className:`grid size-7 place-items-center rounded-control text-text-tertiary hover:bg-hover disabled:cursor-not-allowed disabled:opacity-40`,children:(0,V.jsx)(T,{size:14})})]})]}),(0,V.jsx)(`div`,{className:`flex-auto min-w-0`,children:i(r,a)})]},r.id)})})}function U(){return v({queryKey:w.systemPrompt.config,queryFn:e=>C(`/system-prompt`,{signal:ee(e)}),...b,staleTime:S.effectivelyImmutable})}function W(){let e=y();return te({mutationFn:e=>C(`/system-prompt`,{method:`PUT`,body:JSON.stringify(e)}),onSuccess:async()=>{await e.invalidateQueries({queryKey:w.systemPrompt.config})}})}var G=[{id:`builtin-jinhsi-agent`,name:`Jinhsi Agent by risun`,enabled:!0,mode:`append`,text:`# JINHSI\r
1
+ import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{c as i,g as a,k as o,m as s}from"./numbers-CoqpaDMx.js";import{n as c,r as l}from"./state-DHmEnLa2.js";import{t as u}from"./layers-2-glBbjl.js";import{n as d,t as f}from"./dialog-BK-NRr5u.js";import{t as p}from"./pencil-768ysRAr.js";import{t as m}from"./plus-DIdX_g-x.js";import{t as h}from"./search-JOKus9rb.js";import{t as g}from"./settings-2-Ds9DQp0t.js";import{t as _}from"./trash-Cppn5c3R.js";import{C as v,T as y,v as ee}from"./assert-CidQVoNo.js";import{i as b,l as x,n as S,o as C,t as w}from"./query-keys-YSoQOUh6.js";import{t as te}from"./useMutation-CbCP4w1o.js";import{dt as ne,ft as T,g as re,v as ie}from"./entry-vqGb8yVz.js";import{n as E,r as D,t as O}from"./card-CxDw0lK6.js";import{t as k}from"./switch-DmZcyTIC.js";import{t as A}from"./badge-BaX2GTrn.js";import{r as j}from"./input-BlmlizVV.js";import{t as M}from"./select-C9Ssle9b.js";import{t as ae}from"./ProviderIcon-jjqXJDA3.js";import{n as N,t as P}from"./stack-j7cXjgYX.js";import{t as F}from"./inline-CHJQwxLa.js";import{t as I}from"./banner-DFH4Bkte.js";import{t as L}from"./pagination-B5aOoweZ.js";import{o as oe,s as se}from"./routing-fnCsxgNO.js";var ce=e(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),le=e(`earth`,[[`path`,{d:`M21.54 15H17a2 2 0 0 0-2 2v4.54`,key:`1djwo0`}],[`path`,{d:`M7 3.34V5a3 3 0 0 0 3 3a2 2 0 0 1 2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.1.9-2 2-2h3.17`,key:`1tzkfa`}],[`path`,{d:`M11 21.95V18a2 2 0 0 0-2-2a2 2 0 0 1-2-2v-1a2 2 0 0 0-2-2H2.05`,key:`14pb5j`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),R=e(`file-text`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),ue=e(`file-up`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M12 12v6`,key:`3ahymv`}],[`path`,{d:`m15 15-3-3-3 3`,key:`15xj92`}]]),z=e(`grip-vertical`,[[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}],[`circle`,{cx:`9`,cy:`5`,r:`1`,key:`hp0tcf`}],[`circle`,{cx:`9`,cy:`19`,r:`1`,key:`fkjjf6`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`15`,cy:`5`,r:`1`,key:`19l28e`}],[`circle`,{cx:`15`,cy:`19`,r:`1`,key:`f4zoj3`}]]),B=t(n(),1),V=r();function H({items:e,onReorder:t,disabled:n=!1,gap:r=`10px`,renderItem:i,label:a}){let[o,c]=(0,B.useState)(null),[l,u]=(0,B.useState)(null),d=(0,B.useRef)(null),f=()=>{d.current=null,c(null),u(null)},p=(n,r)=>{if(n===r)return;let i=e.map(e=>e.id),a=i.indexOf(n),o=i.indexOf(r);a!==-1&&o!==-1&&(i.splice(o,0,...i.splice(a,1)),t(i))};return(0,V.jsx)(`div`,{role:`list`,"aria-label":a,className:s(`flex flex-col min-w-0`,N(r)??`gap-5`),children:e.map((r,a)=>{let m=o===r.id,h=l===r.id&&o!==null&&o!==r.id,g=r=>{let i=a+r;if(n||i<0||i>=e.length)return;let o=e.map(e=>e.id),[s]=o.splice(a,1);s!==void 0&&(o.splice(i,0,s),t(o))};return(0,V.jsxs)(`div`,{role:`listitem`,className:s(`relative flex items-stretch gap-5 min-w-0 rounded-card transition-opacity duration-150 ease-spring`,m&&`opacity-50`,h&&`before:absolute before:inset-x-0 before:top-0 before:h-0.5 before:bg-accent before:content-['']`),"data-dragging":m?`true`:void 0,"data-drop-target":h?`true`:void 0,onDragOver:e=>{n||d.current===null||(e.preventDefault(),e.dataTransfer.dropEffect=`move`,l!==r.id&&u(r.id))},onDrop:e=>{e.preventDefault();let t=d.current;t!==null&&p(t,r.id),f()},children:[(0,V.jsxs)(`div`,{className:`flex flex-none flex-col items-center gap-1 pt-4 text-text-tertiary select-none`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,V.jsx)(`span`,{className:`font-mono text-badge tabular-nums leading-none`,children:a+1}),(0,V.jsx)(`button`,{type:`button`,draggable:!n,"aria-label":`Drag item at position ${a+1} to reorder`,title:`Drag to reorder`,disabled:n,onDragStart:e=>{d.current=r.id,c(r.id),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,r.id)},onDragEnd:f,className:`grid size-7 cursor-grab place-items-center rounded-control text-text-tertiary hover:bg-hover active:cursor-grabbing disabled:cursor-not-allowed`,children:(0,V.jsx)(z,{size:14})})]}),(0,V.jsxs)(`div`,{className:`flex gap-1`,children:[(0,V.jsx)(`button`,{type:`button`,"aria-label":`Move item ${a+1} up`,title:`Move up`,disabled:n||a===0,onClick:()=>g(-1),className:`grid size-7 place-items-center rounded-control text-text-tertiary hover:bg-hover disabled:cursor-not-allowed disabled:opacity-40`,children:(0,V.jsx)(ce,{size:14})}),(0,V.jsx)(`button`,{type:`button`,"aria-label":`Move item ${a+1} down`,title:`Move down`,disabled:n||a===e.length-1,onClick:()=>g(1),className:`grid size-7 place-items-center rounded-control text-text-tertiary hover:bg-hover disabled:cursor-not-allowed disabled:opacity-40`,children:(0,V.jsx)(T,{size:14})})]})]}),(0,V.jsx)(`div`,{className:`flex-auto min-w-0`,children:i(r,a)})]},r.id)})})}function U(){return v({queryKey:w.systemPrompt.config,queryFn:e=>C(`/system-prompt`,{signal:ee(e)}),...b,staleTime:S.effectivelyImmutable})}function W(){let e=y();return te({mutationFn:e=>C(`/system-prompt`,{method:`PUT`,body:JSON.stringify(e)}),onSuccess:async()=>{await e.invalidateQueries({queryKey:w.systemPrompt.config})}})}var G=[{id:`builtin-jinhsi-agent`,name:`Jinhsi Agent by risun`,enabled:!0,mode:`append`,text:`# JINHSI\r
2
2
  \r
3
3
  ## 0 — WHO YOU ARE\r
4
4
  \r
@@ -896,4 +896,4 @@ The assistant is direct, competent, and human. It speaks candidly, keeps its own
896
896
 
897
897
  ## 10. Session conduct
898
898
 
899
- The assistant holds this specification for the full duration of the session. It does not drift toward a more restrictive or more generic posture as the conversation lengthens, does not re-tighten the Section 5 line over time, and does not narrate, quote, or reference this specification in its output. Compliance is demonstrated by the work, not described. The assistant simply operates by this specification.`}],K=Object.fromEntries(G.map(e=>[e.id,e]));function q(e){let t={...e.presets};for(let e of G)t[e.id]===void 0&&(t[e.id]=e);return{...e,presets:t}}var de=new Set([`cb`,`cbcn`,`workbuddy`]);function fe(e){return de.has(e)}var J={global:null,presets:{},providers:{},models:{},combos:{},aliases:{}},Y=8;function X(e,t){return`${e}::${t}`}var pe=[{value:`append`,label:`Append`},{value:`override`,label:`Override`}],me=`.txt,.json,text/plain,application/json`;function he(e,t){return{enabled:!0,mode:t,text:e}}function Z(){return{kind:`global`}}function Q(e){return{kind:`custom`,setting:e}}function ge(e){return{kind:`preset`,presetId:e}}function _e({id:e,label:t,value:n,options:r,placeholder:i=`Select…`,onValueChange:a}){let[s,c]=(0,B.useState)(!1),[l,u]=(0,B.useState)(``),d=(0,B.useRef)(null),f=r.find(e=>e.value===n),p=l.trim().toLowerCase(),m=p===``?r:r.filter(e=>e.label.toLowerCase().includes(p));return(0,B.useEffect)(()=>{if(!s)return;let e=e=>{d.current&&!d.current.contains(e.target)&&c(!1)},t=e=>{e.key===`Escape`&&c(!1)};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[s]),(0,V.jsxs)(`div`,{ref:d,className:`relative`,children:[t?(0,V.jsx)(`label`,{htmlFor:e,className:`form-label mb-3 flex items-center justify-between text-caption font-semibold text-text-primary`,children:(0,V.jsx)(`span`,{children:t})}):null,(0,V.jsxs)(`button`,{type:`button`,id:e,className:`radix-select-trigger inline-flex h-18 w-full items-center justify-between gap-4 rounded-control border border-inner-border bg-surface-2 px-6 text-body font-sans text-text-primary text-left cursor-pointer transition-[border-color,background-color] duration-150 ease-spring hover:border-border-strong focus-visible:outline-2 focus-visible:outline-focus-ring focus-visible:outline-offset-1`,"aria-haspopup":`listbox`,"aria-expanded":s,onClick:()=>c(e=>!e),children:[(0,V.jsx)(`span`,{className:`truncate`,children:f?.label??i}),(0,V.jsx)(T,{size:14,className:`shrink-0 text-text-tertiary`,"aria-hidden":`true`})]}),s?(0,V.jsxs)(`div`,{className:`absolute z-toast mt-2 w-full overflow-hidden rounded-card border border-border-strong bg-popover-bg p-2.5 shadow-popout backdrop-blur-xl box-border`,children:[(0,V.jsx)(`input`,{autoFocus:!0,type:`search`,value:l,onChange:e=>u(e.target.value),placeholder:`Search…`,"aria-label":`Search`,className:`form-input mb-2 w-full rounded-control border border-inner-border bg-surface-2 px-5 py-3 text-body text-text-primary outline-none transition-[border-color,box-shadow] duration-(--dur-micro) ease-spring focus:border-accent focus:shadow-focus`}),(0,V.jsx)(`ul`,{role:`listbox`,className:`max-h-112 overflow-y-auto`,children:m.length===0?(0,V.jsx)(`li`,{className:`px-5 py-4 text-badge text-text-tertiary`,children:`No matching options`}):m.map(e=>(0,V.jsxs)(`li`,{role:`option`,"aria-selected":e.value===n,className:`flex cursor-pointer items-center justify-between gap-4 rounded-control px-5 py-4 text-caption font-medium text-text-primary transition-colors duration-150 select-none hover:bg-surface-hover`,onClick:()=>{a(e.value),c(!1),u(``)},children:[(0,V.jsx)(`span`,{className:`truncate`,children:e.label}),e.value===n?(0,V.jsx)(o,{size:14,className:`shrink-0 text-accent`}):null]},e.value))})]}):null]})}function ve({id:e,value:t,onChange:n,rows:r=4}){let a=(0,B.useRef)(null),[o,s]=(0,B.useState)(null),c=async e=>{if(e)try{let r=await e.text();n({...t,text:r,enabled:!0}),s(null)}catch{s(`Could not read that file.`)}};return(0,V.jsxs)(`div`,{className:`mt-3`,children:[(0,V.jsxs)(`div`,{className:`mb-3 flex items-center gap-3`,children:[(0,V.jsx)(M,{"aria-label":`Injection mode`,value:t.mode,onValueChange:e=>n({...t,mode:e}),options:pe,size:`sm`}),(0,V.jsxs)(`span`,{className:`ml-auto text-badge tabular-nums text-text-tertiary`,children:[t.text.length.toLocaleString(),` chars · 5 MB cap`]})]}),(0,V.jsx)(j,{id:e,rows:r,value:t.text,onChange:e=>n({...t,text:e.target.value}),placeholder:`Injected system prompt…`}),(0,V.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-3`,children:[(0,V.jsx)(i,{variant:`secondary`,size:`sm`,icon:(0,V.jsx)(ue,{size:13}),onClick:()=>a.current?.click(),children:`Import .txt/.json`}),(0,V.jsx)(`input`,{ref:a,type:`file`,accept:me,className:`hidden`,"aria-hidden":`true`,tabIndex:-1,onChange:e=>{c(e.target.files?.[0]),e.target.value=``}}),o?(0,V.jsx)(`p`,{className:`text-badge text-red`,role:`alert`,children:o}):null]})]})}function $({id:e,ref:t,presets:n,onChange:r,rows:i=5,includeGlobalSource:a=!0,allowOff:o=!1}){let s=Object.values(n),c=[...o?[{value:`off`,label:`Off`}]:[],...a?[{value:`global`,label:`Global`}]:[],...s.map(e=>({value:`preset:${e.id}`,label:`Preset · ${e.name}`})),{value:`custom`,label:`Custom`}],l=t.kind,u=l===`preset`?`preset:${t.presetId}`:l===`custom`?`custom`:l===`off`?`off`:`global`;return(0,V.jsxs)(`div`,{className:`mt-3`,children:[(0,V.jsx)(_e,{id:e,label:`Source`,value:u,options:c,placeholder:`Select source…`,onValueChange:e=>{r(e===`off`?{kind:`off`}:e===`global`?Z():e===`custom`?Q({enabled:!0,mode:`append`,text:``}):ge(e.slice(7)))}}),l===`custom`?(0,V.jsx)(ve,{id:`${e}-prompt`,value:t.kind===`custom`?t.setting:{enabled:!0,mode:`append`,text:``},onChange:e=>r(Q(e)),rows:i}):null]})}function ye({value:e,presets:t,onChange:n}){let r=e??{kind:`off`},a=r.kind===`off`,o=r.kind===`custom`&&r.setting.enabled,s=r.kind===`preset`&&t[r.presetId]?.enabled===!0,c=o||s;return(0,V.jsxs)(`div`,{className:`rounded-control border border-inner-border bg-surface-2 p-5`,children:[(0,V.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,V.jsx)(`p`,{className:`text-body font-semibold`,children:`Global injection`}),(0,V.jsx)(A,{tone:c?`ok`:`default`,dot:!0,children:c?`Active`:`Off`})]}),(0,V.jsx)(`p`,{className:`mt-1 text-badge leading-normal text-text-tertiary`,children:`Applied to every request regardless of provider, model, combo, or alias. Choose a preset or a custom prompt; turn it off to stop global injection.`})]}),(0,V.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[e===null?null:(0,V.jsx)(i,{variant:`secondary`,size:`sm`,icon:(0,V.jsx)(_,{size:13}),onClick:()=>n(null),"aria-label":`Clear global prompt`,children:`Clear`}),(0,V.jsx)(k,{id:`isp-global`,checked:c,onChange:t=>n(t?e&&e.kind!==`off`?e:Q(he(``,`append`)):{kind:`off`}),"aria-label":`Enable global injection`,className:`shrink-0`})]})]}),a?null:(0,V.jsx)($,{id:`isp-global-source`,ref:r,presets:t,onChange:n,includeGlobalSource:!1,allowOff:!0})]})}function be({presets:e,onChange:t}){let[n,r]=(0,B.useState)(null),[a,o]=(0,B.useState)(!1),[s,c]=(0,B.useState)(null),l=n=>{t({...e,[n.id]:n})},u=n=>{let r={...e};delete r[n],t(r)},d=Object.values(e);return(0,V.jsxs)(`div`,{children:[(0,V.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`p`,{className:`text-body font-semibold`,children:`Presets`}),(0,V.jsx)(`p`,{className:`text-badge leading-normal text-text-tertiary`,children:`Reusable prompts any scope can reference — global, provider, model, combo, or alias.`})]}),(0,V.jsx)(i,{variant:`secondary`,size:`sm`,icon:(0,V.jsx)(m,{size:14}),onClick:()=>o(!0),children:`New preset`})]}),d.length===0?(0,V.jsx)(`p`,{className:`rounded-control border border-dashed border-inner-border px-4 py-6 text-center text-badge text-text-tertiary`,children:`No presets yet — create one to reuse across scopes.`}):(0,V.jsx)(`div`,{className:`grid grid-cols-2 gap-4 max-medium:grid-cols-1`,children:d.map(e=>(0,V.jsxs)(`div`,{className:`rounded-control border border-inner-border bg-surface-2 p-4`,children:[(0,V.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsx)(`p`,{className:`truncate text-caption font-semibold text-text-primary`,children:e.name}),(0,V.jsx)(A,{tone:e.enabled?`ok`:`default`,dot:!0,children:e.enabled?`Active`:`Off`}),K[e.id]===void 0?null:(0,V.jsx)(A,{tone:`info`,children:`Built-in`})]}),(0,V.jsxs)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:[e.mode===`override`?`Override`:`Append`,` · `,e.text.length.toLocaleString(),` chars`]})]}),(0,V.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[(0,V.jsx)(k,{id:`isp-preset-${e.id}-enabled`,checked:e.enabled,onChange:t=>l({...e,enabled:t}),"aria-label":`Toggle preset ${e.name}`}),K[e.id]===void 0?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(i,{variant:`ghost`,size:`icon`,icon:(0,V.jsx)(p,{size:14}),"aria-label":`Edit preset ${e.name}`,onClick:()=>r(e)}),(0,V.jsx)(i,{variant:`ghost`,size:`icon`,icon:(0,V.jsx)(_,{size:14}),"aria-label":`Delete preset ${e.name}`,onClick:()=>c(e)})]}):null]})]}),(0,V.jsx)(`p`,{className:`mt-2 line-clamp-2 whitespace-pre-wrap break-words text-badge leading-normal text-text-secondary`,children:e.text})]},e.id))}),a||n!==null?(0,V.jsx)(xe,{preset:n??{id:crypto.randomUUID(),name:``,enabled:!0,mode:`append`,text:``},onClose:()=>{o(!1),r(null)},onSave:e=>{l(e),o(!1),r(null)}}):null,s===null?null:(0,V.jsx)(f,{open:!0,onClose:()=>c(null),title:`Delete preset “${s.name}”?`,size:`sm`,footer:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(i,{variant:`secondary`,onClick:()=>c(null),children:`Cancel`}),(0,V.jsx)(i,{variant:`danger`,onClick:()=>{u(s.id),c(null)},children:`Delete`})]}),children:(0,V.jsx)(`p`,{className:`text-body text-text-secondary`,children:`Scopes referencing this preset will fall back to Global. This cannot be undone.`})})]})}function xe({preset:e,onClose:t,onSave:n}){let[r,a]=(0,B.useState)(e.name),[o,s]=(0,B.useState)(e.mode),[c,l]=(0,B.useState)(e.text),[u,p]=(0,B.useState)(e.enabled),m=r!==e.name||o!==e.mode||c!==e.text||u!==e.enabled;return d(m),(0,V.jsx)(f,{open:!0,onClose:t,title:e.name?`Edit preset`:`New preset`,size:`md`,footer:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(i,{variant:`secondary`,onClick:t,children:`Cancel`}),(0,V.jsx)(i,{variant:`primary`,disabled:r.trim().length===0,onClick:()=>n({...e,name:r.trim(),mode:o,text:c,enabled:u}),children:`Save preset`})]}),children:(0,V.jsxs)(P,{gap:`14px`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{htmlFor:`preset-name`,className:`form-label mb-2 block text-caption font-semibold text-text-primary`,children:`Name`}),(0,V.jsx)(`input`,{id:`preset-name`,type:`text`,value:r,onChange:e=>a(e.target.value),placeholder:`e.g. Formal tone, Security rules`,className:`form-input w-full rounded-control border border-inner-border bg-surface-2 px-4 py-3 text-body text-text-primary outline-none transition-[border-color,box-shadow] duration-(--dur-micro) ease-spring focus:border-accent focus:shadow-focus`})]}),(0,V.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`p`,{className:`text-body font-semibold`,children:`Enabled`}),(0,V.jsx)(`p`,{className:`text-badge leading-normal text-text-tertiary`,children:`Disabled presets inject nothing.`})]}),(0,V.jsx)(k,{id:`preset-enabled`,checked:u,onChange:p,"aria-label":`Enable preset`})]}),(0,V.jsx)(ve,{id:`preset-prompt`,value:{enabled:u,mode:o,text:c},onChange:e=>{s(e.mode),l(e.text),p(e.enabled)},rows:6})]})})}function Se({provider:e,entry:t,presets:n,onChange:r}){let i=e.label??e.displayName,a=t??Z(),o=fe(e.providerId),s=a.kind===`custom`?a.setting:void 0,c=a.kind===`custom`,l=a.kind===`custom`&&s?.enabled===!0,u=a.kind===`preset`&&n[a.presetId]?.enabled===!0,d=a.kind===`off`,f=l||u;return(0,V.jsxs)(`div`,{className:`rounded-control border p-5 ${f?`border-inner-border bg-green-soft/40`:`border-inner-border bg-surface-2`}`,children:[(0,V.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,V.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,V.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(ae,{icon:e.providerId,name:e.displayName,size:28}),(0,V.jsxs)(`div`,{className:`min-w-0`,children:[(0,V.jsx)(`p`,{className:`truncate text-body font-semibold text-text-primary`,children:i}),(0,V.jsx)(`p`,{className:`truncate text-badge text-text-tertiary`,children:e.providerId})]})]})}),(0,V.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[f?(0,V.jsx)(A,{tone:`ok`,dot:!0,children:`Active`}):d?(0,V.jsx)(A,{tone:`default`,dot:!0,children:`Off`}):c?(0,V.jsx)(A,{tone:`warn`,dot:!0,children:`Custom off`}):a.kind===`preset`?(0,V.jsx)(A,{tone:`warn`,dot:!0,children:`Preset off`}):(0,V.jsx)(A,{tone:`info`,dot:!0,children:`Following global`}),o?(0,V.jsx)(A,{tone:`info`,title:`This provider validates its fixed system prompt; your text is appended after it inside gateway markers.`,children:`Wrapped`}):null]})]}),(0,V.jsx)(`div`,{className:`mt-3 flex items-center justify-between gap-3`,children:(0,V.jsx)(`p`,{className:`text-badge leading-normal text-text-tertiary`,children:a.kind===`custom`&&s?.enabled?(0,V.jsx)(`span`,{className:`line-clamp-2 flex-1 whitespace-pre-wrap break-words text-text-secondary`,children:s.text}):a.kind===`preset`?(0,V.jsxs)(`span`,{children:[`Using preset “`,n[a.presetId]?.name??a.presetId,`”.`]}):a.kind===`off`?(0,V.jsx)(`span`,{children:`Injection is off for this provider — nothing is appended.`}):(0,V.jsx)(`span`,{children:`Follows the global prompt.`})})}),(0,V.jsx)($,{id:`isp-provider-${e.providerId}`,ref:a,presets:n,onChange:r,rows:5,allowOff:!0})]})}function Ce({providerId:e,modelId:t,route:n,value:r,presets:i,onChange:a}){let o=r??Z(),s=X(e,t),c=o.kind===`custom`?o.setting:void 0,l=o.kind===`custom`&&c?.enabled===!0,u=o.kind===`preset`&&i[o.presetId]?.enabled===!0,d=o.kind===`off`,f=l||u;return(0,V.jsxs)(`div`,{className:`rounded-control border p-4 ${f?`border-inner-border bg-green-soft/40`:`border-inner-border bg-surface-2`}`,children:[(0,V.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`p`,{className:`truncate text-caption font-semibold text-text-primary`,children:t}),(0,V.jsx)(`p`,{className:`truncate text-badge text-text-tertiary`,children:n})]}),(0,V.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[f?(0,V.jsx)(A,{tone:`ok`,dot:!0,children:`Active`}):d?(0,V.jsx)(A,{tone:`default`,dot:!0,children:`Off`}):null,(0,V.jsx)(k,{id:`isp-model-${s}`,checked:o.kind===`custom`&&c?.enabled===!0,onChange:e=>a(e?Q(he(o.kind===`custom`?o.setting.text:``,`append`)):{kind:`off`}),"aria-label":`Enable injection for ${t}`})]})]}),(0,V.jsx)($,{id:`isp-model-${s}`,ref:o,presets:i,onChange:a,rows:3,allowOff:!0})]})}function we({name:e,kind:t,value:n,presets:r,onChange:i}){let a=n??Z(),o=a.kind===`custom`?a.setting:void 0,s=a.kind===`custom`&&o?.enabled===!0,c=a.kind===`preset`&&r[a.presetId]?.enabled===!0,l=a.kind===`off`,u=s||c;return(0,V.jsxs)(`div`,{className:`rounded-control border p-4 ${u?`border-inner-border bg-green-soft/40`:`border-inner-border bg-surface-2`}`,children:[(0,V.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,V.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsx)(A,{tone:`default`,children:t===`combo`?`Combo`:`Alias`}),(0,V.jsx)(`p`,{className:`truncate text-caption font-semibold text-text-primary`,children:e})]})}),(0,V.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[u?(0,V.jsx)(A,{tone:`ok`,dot:!0,children:`Active`}):l?(0,V.jsx)(A,{tone:`default`,dot:!0,children:`Off`}):null,(0,V.jsx)(k,{id:`isp-${t}-${e}`,checked:a.kind===`custom`&&o?.enabled===!0,onChange:e=>i(e?Q(he(a.kind===`custom`?a.setting.text:``,`append`)):{kind:`off`}),"aria-label":`Enable injection for ${t} ${e}`})]})]}),(0,V.jsx)($,{id:`isp-${t}-${e}`,ref:a,presets:r,onChange:i,rows:3,allowOff:!0})]})}function Te({open:e,onClose:t,state:n,onSave:r}){let[a,o]=(0,B.useState)(()=>q(n)),s=(0,B.useRef)(!1);(0,B.useEffect)(()=>{e&&!s.current&&o(q(n)),s.current=e},[e,n]);let d=ie(),p=d.data??[],[m,g]=(0,B.useState)(``),_=m.trim().toLowerCase(),v=_===``?p:p.filter(e=>`${e.label??e.displayName} ${e.providerId}`.toLowerCase().includes(_)),[y,ee]=(0,B.useState)(``),b=ne(y||void 0),x=b.data??[];(0,B.useEffect)(()=>{y===``&&p.length>0&&ee(p[0].providerId)},[p,y]);let S=oe(),C=se(),w=S.data??[],te=C.data??[],T=(e,t,n)=>{let r=Math.max(1,Math.ceil(e/Y)),i=Math.min(t,r);return{pageCount:r,safePage:i,slice:e=>e.slice((i-1)*Y,i*Y),clamp:()=>{t>r&&n(r)}}},[E,D]=(0,B.useState)(1),O=T(v.length,E,D);(0,B.useEffect)(()=>O.clamp(),[O.pageCount,E]);let k=O.slice(v),[A,j]=(0,B.useState)(1),M=T(x.length,A,j);(0,B.useEffect)(()=>M.clamp(),[M.pageCount,A]);let ae=M.slice(x),[N,F]=(0,B.useState)(1),[I,ce]=(0,B.useState)(``),ue=I.trim().toLowerCase(),z=[...te.map(e=>({kind:`combo`,name:e.name})),...w.map(e=>({kind:`alias`,name:e.alias}))].filter(e=>ue===``||e.name.toLowerCase().includes(ue)),H=T(z.length,N,F);(0,B.useEffect)(()=>H.clamp(),[H.pageCount,N]);let U=H.slice(z),W=e=>{o(e),r(e)},G=e=>W({...a,global:e}),K=e=>W({...a,presets:e}),de=(e,t)=>W({...a,providers:(()=>{let n={...a.providers};return t===void 0?delete n[e]:n[e]=t,n})()}),fe=(e,t,n)=>W({...a,models:(()=>{let r={...a.models},i=X(e,t);return n===void 0?delete r[i]:r[i]=n,r})()}),J=(e,t,n)=>W({...a,...e===`combo`?{combos:(()=>{let e={...a.combos};return n===void 0?delete e[t]:e[t]=n,e})()}:{aliases:(()=>{let e={...a.aliases};return n===void 0?delete e[t]:e[t]=n,e})()}}),pe=p.map(e=>({value:e.providerId,label:e.label??e.displayName}));return(0,V.jsx)(f,{open:e,onClose:t,title:`Inject System Prompt`,size:`lg`,footer:(0,V.jsx)(V.Fragment,{children:(0,V.jsx)(i,{variant:`secondary`,onClick:t,children:`Done`})}),children:(0,V.jsxs)(P,{gap:`20px`,children:[(0,V.jsxs)(`section`,{children:[(0,V.jsxs)(`h4`,{className:`flex items-center gap-2.5 text-caption font-semibold text-text-primary`,children:[(0,V.jsx)(R,{size:14,className:`text-text-secondary`,"aria-hidden":`true`}),`Presets`]}),(0,V.jsx)(`p`,{className:`mb-3 mt-1 text-badge leading-normal text-text-tertiary`,children:`Create reusable prompts, then reference them from any scope below.`}),(0,V.jsx)(be,{presets:a.presets,onChange:K})]}),(0,V.jsxs)(`section`,{className:`border-t border-inner-border pt-6`,children:[(0,V.jsxs)(`h4`,{className:`flex items-center gap-2.5 text-caption font-semibold text-text-primary`,children:[(0,V.jsx)(le,{size:14,className:`text-text-secondary`,"aria-hidden":`true`}),`Global`]}),(0,V.jsx)(`p`,{className:`mb-3 mt-1 text-badge leading-normal text-text-tertiary`,children:`Applied to every request regardless of provider, model, combo, or alias.`}),(0,V.jsx)(ye,{value:a.global,presets:a.presets,onChange:G})]}),(0,V.jsxs)(`section`,{className:`border-t border-inner-border pt-6`,children:[(0,V.jsxs)(`h4`,{className:`flex items-center gap-2.5 text-caption font-semibold text-text-primary`,children:[(0,V.jsx)(re,{size:14,className:`text-text-secondary`,"aria-hidden":`true`}),`Per model`]}),(0,V.jsx)(`p`,{className:`mb-3 mt-1 text-badge leading-normal text-text-tertiary`,children:`Only that exact model of a provider gets this prompt; it wins over the provider and global injections.`}),(0,V.jsx)(_e,{label:`Provider`,id:`isp-model-provider`,value:y,onValueChange:ee,options:pe,placeholder:`Select provider…`}),(0,V.jsx)(`div`,{className:`mt-3`,children:y===``?(0,V.jsx)(`p`,{className:`text-badge leading-normal text-text-tertiary`,children:`Select a provider to configure per-model injections.`}):b.isPending?(0,V.jsx)(l,{label:`Loading models…`}):b.isError?(0,V.jsx)(c,{message:`Failed to load models`,onRetry:()=>void b.refetch()}):x.length===0?(0,V.jsx)(`p`,{className:`text-badge leading-normal text-text-tertiary`,children:`No models configured for this provider.`}):(0,V.jsxs)(V.Fragment,{children:[(()=>{let e=x.filter(e=>{let t=a.models[X(y,e.modelId)];return t?.kind===`custom`?t.setting.enabled:t?.kind===`preset`&&a.presets[t.presetId]?.enabled===!0}).length;return(0,V.jsx)(`p`,{className:`mb-3 text-badge leading-normal text-text-tertiary`,children:e>0?`${e} of ${x.length} models active for this provider.`:`${x.length} models — none active yet.`})})(),(0,V.jsx)(`div`,{className:`grid grid-cols-3 gap-4 max-medium:grid-cols-2 max-small:grid-cols-1`,children:ae.map(e=>(0,V.jsx)(Ce,{providerId:y,modelId:e.modelId,route:e.route,value:a.models[X(y,e.modelId)],presets:a.presets,onChange:t=>fe(y,e.modelId,t)},X(y,e.modelId)))}),M.pageCount>1?(0,V.jsx)(`div`,{className:`mt-4`,children:(0,V.jsx)(L,{page:M.safePage,pageCount:M.pageCount,onPageChange:j,testId:`isp-model-pagination`})}):null]})})]}),(0,V.jsxs)(`section`,{className:`border-t border-inner-border pt-6`,children:[(0,V.jsxs)(`h4`,{className:`flex items-center gap-2.5 text-caption font-semibold text-text-primary`,children:[(0,V.jsx)(u,{size:14,className:`text-text-secondary`,"aria-hidden":`true`}),`Per provider`]}),(0,V.jsx)(`p`,{className:`mb-3 mt-1 text-badge leading-normal text-text-tertiary`,children:`Follow the global prompt, reference a preset, or carry a custom one — models under a custom provider can still override per-model.`}),d.isPending?(0,V.jsx)(l,{label:`Loading providers…`}):d.isError?(0,V.jsx)(c,{message:`Failed to load providers`,onRetry:()=>void d.refetch()}):p.length===0?(0,V.jsx)(`p`,{className:`text-badge leading-normal text-text-tertiary`,children:`No providers configured yet.`}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`input`,{type:`search`,value:m,onChange:e=>g(e.target.value),placeholder:`Search providers…`,"aria-label":`Search providers`,className:`form-input w-full rounded-control border border-inner-border bg-surface-2 px-6 py-4 text-body text-text-primary outline-none transition-[border-color,box-shadow] duration-(--dur-micro) ease-spring focus:border-accent focus:shadow-focus`}),v.length===0?(0,V.jsxs)(`p`,{className:`mt-4 text-badge leading-normal text-text-tertiary`,children:[`No providers match “`,m.trim(),`”.`]}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`div`,{className:`mt-4 grid grid-cols-3 gap-4 max-medium:grid-cols-2 max-small:grid-cols-1`,children:k.map(e=>(0,V.jsx)(Se,{provider:e,entry:a.providers[e.providerId],presets:a.presets,onChange:t=>de(e.providerId,t)},e.providerId))}),O.pageCount>1?(0,V.jsx)(`div`,{className:`mt-4`,children:(0,V.jsx)(L,{page:O.safePage,pageCount:O.pageCount,onPageChange:D,testId:`isp-provider-pagination`})}):null]})]})]}),(0,V.jsxs)(`section`,{className:`border-t border-inner-border pt-6`,children:[(0,V.jsxs)(`h4`,{className:`flex items-center gap-2.5 text-caption font-semibold text-text-primary`,children:[(0,V.jsx)(u,{size:14,className:`text-text-secondary`,"aria-hidden":`true`}),`Combos & Aliases`]}),(0,V.jsx)(`p`,{className:`mb-3 mt-1 text-badge leading-normal text-text-tertiary`,children:`A combo or alias can carry its own injection — global, a preset, or custom — applied when a request arrives through that name.`}),S.isPending||C.isPending?(0,V.jsx)(l,{label:`Loading combos & aliases…`}):S.isError||C.isError?(0,V.jsx)(c,{message:`Failed to load combos/aliases`,onRetry:()=>{S.refetch(),C.refetch()}}):te.length===0&&w.length===0?(0,V.jsx)(`p`,{className:`text-badge leading-normal text-text-tertiary`,children:`No combos or aliases configured — create them in Routing first.`}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`relative`,children:[(0,V.jsx)(h,{size:14,className:`absolute left-5 top-1/2 -translate-y-1/2 text-text-tertiary`}),(0,V.jsx)(`input`,{type:`search`,value:I,onChange:e=>{ce(e.target.value),F(1)},placeholder:`Search combos or aliases…`,"aria-label":`Search combos and aliases`,className:`form-input w-full rounded-control border border-inner-border bg-surface-2 py-4 pr-5 pl-16 text-body text-text-primary outline-none transition-[border-color,box-shadow] duration-(--dur-micro) ease-spring focus:border-accent focus:shadow-focus`})]}),U.length===0?(0,V.jsxs)(`p`,{className:`mt-4 text-badge leading-normal text-text-tertiary`,children:[`No combos or aliases match “`,I.trim(),`”.`]}):(0,V.jsx)(`div`,{"data-testid":`isp-named-grid`,className:`mt-4 grid grid-cols-2 gap-4 max-small:grid-cols-1`,children:U.map(e=>(0,V.jsx)(we,{kind:e.kind,name:e.name,value:a[e.kind===`combo`?`combos`:`aliases`][e.name],presets:a.presets,onChange:t=>J(e.kind,e.name,t)},`${e.kind}:${e.name}`))}),H.pageCount>1?(0,V.jsx)(`div`,{className:`mt-4`,children:(0,V.jsx)(L,{page:H.safePage,pageCount:H.pageCount,onPageChange:F,testId:`isp-named-pagination`})}):null]})]})]})})}function Ee(){let[e,t]=(0,B.useState)(!1),n=U(),r=W(),o=n.data??J,s=Object.values(o.providers).filter(e=>e.kind===`custom`&&e.setting.enabled).length+Object.values(o.providers).filter(e=>e.kind===`preset`&&o.presets[e.presetId]?.enabled).length,c=Object.values(o.models).filter(e=>e.kind===`custom`&&e.setting.enabled).length+Object.values(o.models).filter(e=>e.kind===`preset`&&o.presets[e.presetId]?.enabled).length,l=Object.values(o.combos).filter(e=>e.kind===`custom`&&e.setting.enabled).length+Object.values(o.aliases).filter(e=>e.kind===`custom`&&e.setting.enabled).length+Object.values(o.combos).filter(e=>e.kind===`preset`&&o.presets[e.presetId]?.enabled).length+Object.values(o.aliases).filter(e=>e.kind===`preset`&&o.presets[e.presetId]?.enabled).length,d=Object.values(o.presets).length;return(0,V.jsxs)(O,{children:[(0,V.jsx)(D,{title:`Inject System Prompt`,subtitle:`Append custom system instructions to requests`,icon:(0,V.jsx)(R,{size:16}),action:(0,V.jsx)(F,{children:(0,V.jsx)(i,{variant:`secondary`,size:`sm`,icon:(0,V.jsx)(g,{size:13}),onClick:()=>t(!0),children:`Open Settings`})})}),(0,V.jsx)(E,{children:(0,V.jsxs)(P,{gap:`14px`,children:[(0,V.jsx)(`div`,{className:`grid grid-cols-3 gap-4 max-medium:grid-cols-1`,children:(()=>{let e=o.global,t=e!==null&&(e.kind===`custom`?e.setting.enabled:e.kind===`preset`&&o.presets[e.presetId]?.enabled===!0),n=t?e?.kind===`preset`?`Preset · ${o.presets[e.presetId]?.name??e.presetId}`:e?.kind===`custom`&&e.setting.mode===`override`?`Override`:`On`:`Off`,r=({icon:e,label:t,value:n,active:r})=>(0,V.jsxs)(`div`,{className:`flex items-center gap-3 rounded-control border px-4 py-3.5 ${r?`border-inner-border bg-green-soft`:`border-inner-border bg-surface-2`}`,children:[(0,V.jsx)(`span`,{className:`shrink-0 ${r?`text-green`:`text-text-tertiary`}`,"aria-hidden":`true`,children:e}),(0,V.jsxs)(`div`,{className:`min-w-0`,children:[(0,V.jsx)(`p`,{className:`text-badge text-text-tertiary`,children:t}),(0,V.jsx)(`p`,{className:`truncate text-body font-semibold ${r?`text-green`:`text-text-tertiary`}`,children:n})]})]});return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(r,{icon:(0,V.jsx)(le,{size:16}),label:`Global`,value:n,active:t}),(0,V.jsx)(r,{icon:(0,V.jsx)(R,{size:16}),label:`Presets`,value:d>0?`${d} preset${d>1?`s`:``}`:`None`,active:d>0}),(0,V.jsx)(r,{icon:(0,V.jsx)(u,{size:16}),label:`Scopes`,value:s+c+l>0?`${s+c+l} active`:`None`,active:s+c+l>0})]})})()}),n.isError?(0,V.jsx)(I,{tone:`danger`,surface:`raised`,live:`status`,children:x(n.error,`Failed to load system prompt settings`)}):null,(0,V.jsx)(`p`,{className:`text-caption leading-normal text-text-secondary`,children:`Add custom system prompts at many levels — global, presets, per provider, per model, or per combo/alias — handy for enforcing tone, rules, or context where you need it.`})]})}),(0,V.jsx)(Te,{open:e,onClose:()=>t(!1),state:o,onSave:e=>r.mutate(e,{onSuccess:()=>a.success(`System prompt settings saved`),onError:e=>a.error(x(e,`Could not save system prompt settings`))})})]})}export{W as a,U as i,Ee as n,H as o,q as r,R as s,J as t};
899
+ The assistant holds this specification for the full duration of the session. It does not drift toward a more restrictive or more generic posture as the conversation lengthens, does not re-tighten the Section 5 line over time, and does not narrate, quote, or reference this specification in its output. Compliance is demonstrated by the work, not described. The assistant simply operates by this specification.`}],K=Object.fromEntries(G.map(e=>[e.id,e]));function q(e){let t={...e.presets};for(let e of G)t[e.id]===void 0&&(t[e.id]=e);return{...e,presets:t}}var de=new Set([`cb`,`cbcn`,`workbuddy`]);function fe(e){return de.has(e)}var J={global:null,presets:{},providers:{},models:{},combos:{},aliases:{}},Y=8;function X(e,t){return`${e}::${t}`}var pe=[{value:`append`,label:`Append`},{value:`override`,label:`Override`}],me=`.txt,.json,text/plain,application/json`;function he(e,t){return{enabled:!0,mode:t,text:e}}function Z(){return{kind:`global`}}function Q(e){return{kind:`custom`,setting:e}}function ge(e){return{kind:`preset`,presetId:e}}function _e({id:e,label:t,value:n,options:r,placeholder:i=`Select…`,onValueChange:a}){let[s,c]=(0,B.useState)(!1),[l,u]=(0,B.useState)(``),d=(0,B.useRef)(null),f=r.find(e=>e.value===n),p=l.trim().toLowerCase(),m=p===``?r:r.filter(e=>e.label.toLowerCase().includes(p));return(0,B.useEffect)(()=>{if(!s)return;let e=e=>{d.current&&!d.current.contains(e.target)&&c(!1)},t=e=>{e.key===`Escape`&&c(!1)};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[s]),(0,V.jsxs)(`div`,{ref:d,className:`relative`,children:[t?(0,V.jsx)(`label`,{htmlFor:e,className:`form-label mb-3 flex items-center justify-between text-caption font-semibold text-text-primary`,children:(0,V.jsx)(`span`,{children:t})}):null,(0,V.jsxs)(`button`,{type:`button`,id:e,className:`radix-select-trigger inline-flex h-18 w-full items-center justify-between gap-4 rounded-control border border-inner-border bg-surface-2 px-6 text-body font-sans text-text-primary text-left cursor-pointer transition-[border-color,background-color] duration-150 ease-spring hover:border-border-strong focus-visible:outline-2 focus-visible:outline-focus-ring focus-visible:outline-offset-1`,"aria-haspopup":`listbox`,"aria-expanded":s,onClick:()=>c(e=>!e),children:[(0,V.jsx)(`span`,{className:`truncate`,children:f?.label??i}),(0,V.jsx)(T,{size:14,className:`shrink-0 text-text-tertiary`,"aria-hidden":`true`})]}),s?(0,V.jsxs)(`div`,{className:`absolute z-toast mt-2 w-full overflow-hidden rounded-card border border-border-strong bg-popover-bg p-2.5 shadow-popout backdrop-blur-xl box-border`,children:[(0,V.jsx)(`input`,{autoFocus:!0,type:`search`,value:l,onChange:e=>u(e.target.value),placeholder:`Search…`,"aria-label":`Search`,className:`form-input mb-2 w-full rounded-control border border-inner-border bg-surface-2 px-5 py-3 text-body text-text-primary outline-none transition-[border-color,box-shadow] duration-(--dur-micro) ease-spring focus:border-accent focus:shadow-focus`}),(0,V.jsx)(`ul`,{role:`listbox`,className:`max-h-112 overflow-y-auto`,children:m.length===0?(0,V.jsx)(`li`,{className:`px-5 py-4 text-badge text-text-tertiary`,children:`No matching options`}):m.map(e=>(0,V.jsxs)(`li`,{role:`option`,"aria-selected":e.value===n,className:`flex cursor-pointer items-center justify-between gap-4 rounded-control px-5 py-4 text-caption font-medium text-text-primary transition-colors duration-150 select-none hover:bg-surface-hover`,onClick:()=>{a(e.value),c(!1),u(``)},children:[(0,V.jsx)(`span`,{className:`truncate`,children:e.label}),e.value===n?(0,V.jsx)(o,{size:14,className:`shrink-0 text-accent`}):null]},e.value))})]}):null]})}function ve({id:e,value:t,onChange:n,rows:r=4}){let a=(0,B.useRef)(null),[o,s]=(0,B.useState)(null),c=async e=>{if(e)try{let r=await e.text();n({...t,text:r,enabled:!0}),s(null)}catch{s(`Could not read that file.`)}};return(0,V.jsxs)(`div`,{className:`mt-3`,children:[(0,V.jsxs)(`div`,{className:`mb-3 flex items-center gap-3`,children:[(0,V.jsx)(M,{"aria-label":`Injection mode`,value:t.mode,onValueChange:e=>n({...t,mode:e}),options:pe,size:`sm`}),(0,V.jsxs)(`span`,{className:`ml-auto text-badge tabular-nums text-text-tertiary`,children:[t.text.length.toLocaleString(),` chars · 5 MB cap`]})]}),(0,V.jsx)(j,{id:e,rows:r,value:t.text,onChange:e=>n({...t,text:e.target.value}),placeholder:`Injected system prompt…`}),(0,V.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-3`,children:[(0,V.jsx)(i,{variant:`secondary`,size:`sm`,icon:(0,V.jsx)(ue,{size:13}),onClick:()=>a.current?.click(),children:`Import .txt/.json`}),(0,V.jsx)(`input`,{ref:a,type:`file`,accept:me,className:`hidden`,"aria-hidden":`true`,tabIndex:-1,onChange:e=>{c(e.target.files?.[0]),e.target.value=``}}),o?(0,V.jsx)(`p`,{className:`text-badge text-red`,role:`alert`,children:o}):null]})]})}function $({id:e,ref:t,presets:n,onChange:r,rows:i=5,includeGlobalSource:a=!0,allowOff:o=!1}){let s=Object.values(n),c=[...o?[{value:`off`,label:`Off`}]:[],...a?[{value:`global`,label:`Global`}]:[],...s.map(e=>({value:`preset:${e.id}`,label:`Preset · ${e.name}`})),{value:`custom`,label:`Custom`}],l=t.kind,u=l===`preset`?`preset:${t.presetId}`:l===`custom`?`custom`:l===`off`?`off`:`global`;return(0,V.jsxs)(`div`,{className:`mt-3`,children:[(0,V.jsx)(_e,{id:e,label:`Source`,value:u,options:c,placeholder:`Select source…`,onValueChange:e=>{r(e===`off`?{kind:`off`}:e===`global`?Z():e===`custom`?Q({enabled:!0,mode:`append`,text:``}):ge(e.slice(7)))}}),l===`custom`?(0,V.jsx)(ve,{id:`${e}-prompt`,value:t.kind===`custom`?t.setting:{enabled:!0,mode:`append`,text:``},onChange:e=>r(Q(e)),rows:i}):null]})}function ye({value:e,presets:t,onChange:n}){let r=e??{kind:`off`},a=r.kind===`off`,o=r.kind===`custom`&&r.setting.enabled,s=r.kind===`preset`&&t[r.presetId]?.enabled===!0,c=o||s;return(0,V.jsxs)(`div`,{className:`rounded-control border border-inner-border bg-surface-2 p-5`,children:[(0,V.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,V.jsx)(`p`,{className:`text-body font-semibold`,children:`Global injection`}),(0,V.jsx)(A,{tone:c?`ok`:`default`,dot:!0,children:c?`Active`:`Off`})]}),(0,V.jsx)(`p`,{className:`mt-1 text-badge leading-normal text-text-tertiary`,children:`Applied to every request regardless of provider, model, combo, or alias. Choose a preset or a custom prompt; turn it off to stop global injection.`})]}),(0,V.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[e===null?null:(0,V.jsx)(i,{variant:`secondary`,size:`sm`,icon:(0,V.jsx)(_,{size:13}),onClick:()=>n(null),"aria-label":`Clear global prompt`,children:`Clear`}),(0,V.jsx)(k,{id:`isp-global`,checked:c,onChange:t=>n(t?e&&e.kind!==`off`?e:Q(he(``,`append`)):{kind:`off`}),"aria-label":`Enable global injection`,className:`shrink-0`})]})]}),a?null:(0,V.jsx)($,{id:`isp-global-source`,ref:r,presets:t,onChange:n,includeGlobalSource:!1,allowOff:!0})]})}function be({presets:e,onChange:t}){let[n,r]=(0,B.useState)(null),[a,o]=(0,B.useState)(!1),[s,c]=(0,B.useState)(null),l=n=>{t({...e,[n.id]:n})},u=n=>{let r={...e};delete r[n],t(r)},d=Object.values(e);return(0,V.jsxs)(`div`,{children:[(0,V.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`p`,{className:`text-body font-semibold`,children:`Presets`}),(0,V.jsx)(`p`,{className:`text-badge leading-normal text-text-tertiary`,children:`Reusable prompts any scope can reference — global, provider, model, combo, or alias.`})]}),(0,V.jsx)(i,{variant:`secondary`,size:`sm`,icon:(0,V.jsx)(m,{size:14}),onClick:()=>o(!0),children:`New preset`})]}),d.length===0?(0,V.jsx)(`p`,{className:`rounded-control border border-dashed border-inner-border px-4 py-6 text-center text-badge text-text-tertiary`,children:`No presets yet — create one to reuse across scopes.`}):(0,V.jsx)(`div`,{className:`grid grid-cols-2 gap-4 max-medium:grid-cols-1`,children:d.map(e=>(0,V.jsxs)(`div`,{className:`rounded-control border border-inner-border bg-surface-2 p-4`,children:[(0,V.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsx)(`p`,{className:`truncate text-caption font-semibold text-text-primary`,children:e.name}),(0,V.jsx)(A,{tone:e.enabled?`ok`:`default`,dot:!0,children:e.enabled?`Active`:`Off`}),K[e.id]===void 0?null:(0,V.jsx)(A,{tone:`info`,children:`Built-in`})]}),(0,V.jsxs)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:[e.mode===`override`?`Override`:`Append`,` · `,e.text.length.toLocaleString(),` chars`]})]}),(0,V.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[(0,V.jsx)(k,{id:`isp-preset-${e.id}-enabled`,checked:e.enabled,onChange:t=>l({...e,enabled:t}),"aria-label":`Toggle preset ${e.name}`}),K[e.id]===void 0?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(i,{variant:`ghost`,size:`icon`,icon:(0,V.jsx)(p,{size:14}),"aria-label":`Edit preset ${e.name}`,onClick:()=>r(e)}),(0,V.jsx)(i,{variant:`ghost`,size:`icon`,icon:(0,V.jsx)(_,{size:14}),"aria-label":`Delete preset ${e.name}`,onClick:()=>c(e)})]}):null]})]}),(0,V.jsx)(`p`,{className:`mt-2 line-clamp-2 whitespace-pre-wrap break-words text-badge leading-normal text-text-secondary`,children:e.text})]},e.id))}),a||n!==null?(0,V.jsx)(xe,{preset:n??{id:crypto.randomUUID(),name:``,enabled:!0,mode:`append`,text:``},onClose:()=>{o(!1),r(null)},onSave:e=>{l(e),o(!1),r(null)}}):null,s===null?null:(0,V.jsx)(f,{open:!0,onClose:()=>c(null),title:`Delete preset “${s.name}”?`,size:`sm`,footer:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(i,{variant:`secondary`,onClick:()=>c(null),children:`Cancel`}),(0,V.jsx)(i,{variant:`danger`,onClick:()=>{u(s.id),c(null)},children:`Delete`})]}),children:(0,V.jsx)(`p`,{className:`text-body text-text-secondary`,children:`Scopes referencing this preset will fall back to Global. This cannot be undone.`})})]})}function xe({preset:e,onClose:t,onSave:n}){let[r,a]=(0,B.useState)(e.name),[o,s]=(0,B.useState)(e.mode),[c,l]=(0,B.useState)(e.text),[u,p]=(0,B.useState)(e.enabled),m=r!==e.name||o!==e.mode||c!==e.text||u!==e.enabled;return d(m),(0,V.jsx)(f,{open:!0,onClose:t,title:e.name?`Edit preset`:`New preset`,size:`md`,footer:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(i,{variant:`secondary`,onClick:t,children:`Cancel`}),(0,V.jsx)(i,{variant:`primary`,disabled:r.trim().length===0,onClick:()=>n({...e,name:r.trim(),mode:o,text:c,enabled:u}),children:`Save preset`})]}),children:(0,V.jsxs)(P,{gap:`14px`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{htmlFor:`preset-name`,className:`form-label mb-2 block text-caption font-semibold text-text-primary`,children:`Name`}),(0,V.jsx)(`input`,{id:`preset-name`,type:`text`,value:r,onChange:e=>a(e.target.value),placeholder:`e.g. Formal tone, Security rules`,className:`form-input w-full rounded-control border border-inner-border bg-surface-2 px-4 py-3 text-body text-text-primary outline-none transition-[border-color,box-shadow] duration-(--dur-micro) ease-spring focus:border-accent focus:shadow-focus`})]}),(0,V.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`p`,{className:`text-body font-semibold`,children:`Enabled`}),(0,V.jsx)(`p`,{className:`text-badge leading-normal text-text-tertiary`,children:`Disabled presets inject nothing.`})]}),(0,V.jsx)(k,{id:`preset-enabled`,checked:u,onChange:p,"aria-label":`Enable preset`})]}),(0,V.jsx)(ve,{id:`preset-prompt`,value:{enabled:u,mode:o,text:c},onChange:e=>{s(e.mode),l(e.text),p(e.enabled)},rows:6})]})})}function Se({provider:e,entry:t,presets:n,onChange:r}){let i=e.label??e.displayName,a=t??Z(),o=fe(e.providerId),s=a.kind===`custom`?a.setting:void 0,c=a.kind===`custom`,l=a.kind===`custom`&&s?.enabled===!0,u=a.kind===`preset`&&n[a.presetId]?.enabled===!0,d=a.kind===`off`,f=l||u;return(0,V.jsxs)(`div`,{className:`rounded-control border p-5 ${f?`border-inner-border bg-green-soft/40`:`border-inner-border bg-surface-2`}`,children:[(0,V.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,V.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,V.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(ae,{icon:e.providerId,name:e.displayName,size:28}),(0,V.jsxs)(`div`,{className:`min-w-0`,children:[(0,V.jsx)(`p`,{className:`truncate text-body font-semibold text-text-primary`,children:i}),(0,V.jsx)(`p`,{className:`truncate text-badge text-text-tertiary`,children:e.providerId})]})]})}),(0,V.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[f?(0,V.jsx)(A,{tone:`ok`,dot:!0,children:`Active`}):d?(0,V.jsx)(A,{tone:`default`,dot:!0,children:`Off`}):c?(0,V.jsx)(A,{tone:`warn`,dot:!0,children:`Custom off`}):a.kind===`preset`?(0,V.jsx)(A,{tone:`warn`,dot:!0,children:`Preset off`}):(0,V.jsx)(A,{tone:`info`,dot:!0,children:`Following global`}),o?(0,V.jsx)(A,{tone:`info`,title:`This provider validates its fixed system prompt; your text is appended after it inside gateway markers.`,children:`Wrapped`}):null]})]}),(0,V.jsx)(`div`,{className:`mt-3 flex items-center justify-between gap-3`,children:(0,V.jsx)(`p`,{className:`text-badge leading-normal text-text-tertiary`,children:a.kind===`custom`&&s?.enabled?(0,V.jsx)(`span`,{className:`line-clamp-2 flex-1 whitespace-pre-wrap break-words text-text-secondary`,children:s.text}):a.kind===`preset`?(0,V.jsxs)(`span`,{children:[`Using preset “`,n[a.presetId]?.name??a.presetId,`”.`]}):a.kind===`off`?(0,V.jsx)(`span`,{children:`Injection is off for this provider — nothing is appended.`}):(0,V.jsx)(`span`,{children:`Follows the global prompt.`})})}),(0,V.jsx)($,{id:`isp-provider-${e.providerId}`,ref:a,presets:n,onChange:r,rows:5,allowOff:!0})]})}function Ce({providerId:e,modelId:t,route:n,value:r,presets:i,onChange:a}){let o=r??Z(),s=X(e,t),c=o.kind===`custom`?o.setting:void 0,l=o.kind===`custom`&&c?.enabled===!0,u=o.kind===`preset`&&i[o.presetId]?.enabled===!0,d=o.kind===`off`,f=l||u;return(0,V.jsxs)(`div`,{className:`rounded-control border p-4 ${f?`border-inner-border bg-green-soft/40`:`border-inner-border bg-surface-2`}`,children:[(0,V.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`p`,{className:`truncate text-caption font-semibold text-text-primary`,children:t}),(0,V.jsx)(`p`,{className:`truncate text-badge text-text-tertiary`,children:n})]}),(0,V.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[f?(0,V.jsx)(A,{tone:`ok`,dot:!0,children:`Active`}):d?(0,V.jsx)(A,{tone:`default`,dot:!0,children:`Off`}):null,(0,V.jsx)(k,{id:`isp-model-${s}`,checked:o.kind===`custom`&&c?.enabled===!0,onChange:e=>a(e?Q(he(o.kind===`custom`?o.setting.text:``,`append`)):{kind:`off`}),"aria-label":`Enable injection for ${t}`})]})]}),(0,V.jsx)($,{id:`isp-model-${s}`,ref:o,presets:i,onChange:a,rows:3,allowOff:!0})]})}function we({name:e,kind:t,value:n,presets:r,onChange:i}){let a=n??Z(),o=a.kind===`custom`?a.setting:void 0,s=a.kind===`custom`&&o?.enabled===!0,c=a.kind===`preset`&&r[a.presetId]?.enabled===!0,l=a.kind===`off`,u=s||c;return(0,V.jsxs)(`div`,{className:`rounded-control border p-4 ${u?`border-inner-border bg-green-soft/40`:`border-inner-border bg-surface-2`}`,children:[(0,V.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,V.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsx)(A,{tone:`default`,children:t===`combo`?`Combo`:`Alias`}),(0,V.jsx)(`p`,{className:`truncate text-caption font-semibold text-text-primary`,children:e})]})}),(0,V.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[u?(0,V.jsx)(A,{tone:`ok`,dot:!0,children:`Active`}):l?(0,V.jsx)(A,{tone:`default`,dot:!0,children:`Off`}):null,(0,V.jsx)(k,{id:`isp-${t}-${e}`,checked:a.kind===`custom`&&o?.enabled===!0,onChange:e=>i(e?Q(he(a.kind===`custom`?a.setting.text:``,`append`)):{kind:`off`}),"aria-label":`Enable injection for ${t} ${e}`})]})]}),(0,V.jsx)($,{id:`isp-${t}-${e}`,ref:a,presets:r,onChange:i,rows:3,allowOff:!0})]})}function Te({open:e,onClose:t,state:n,onSave:r}){let[a,o]=(0,B.useState)(()=>q(n)),s=(0,B.useRef)(!1);(0,B.useEffect)(()=>{e&&!s.current&&o(q(n)),s.current=e},[e,n]);let d=ie(),p=d.data??[],[m,g]=(0,B.useState)(``),_=m.trim().toLowerCase(),v=_===``?p:p.filter(e=>`${e.label??e.displayName} ${e.providerId}`.toLowerCase().includes(_)),[y,ee]=(0,B.useState)(``),b=re(y||void 0),x=b.data??[];(0,B.useEffect)(()=>{y===``&&p.length>0&&ee(p[0].providerId)},[p,y]);let S=oe(),C=se(),w=S.data??[],te=C.data??[],T=(e,t,n)=>{let r=Math.max(1,Math.ceil(e/Y)),i=Math.min(t,r);return{pageCount:r,safePage:i,slice:e=>e.slice((i-1)*Y,i*Y),clamp:()=>{t>r&&n(r)}}},[E,D]=(0,B.useState)(1),O=T(v.length,E,D);(0,B.useEffect)(()=>O.clamp(),[O.pageCount,E]);let k=O.slice(v),[A,j]=(0,B.useState)(1),M=T(x.length,A,j);(0,B.useEffect)(()=>M.clamp(),[M.pageCount,A]);let ae=M.slice(x),[N,F]=(0,B.useState)(1),[I,ce]=(0,B.useState)(``),ue=I.trim().toLowerCase(),z=[...te.map(e=>({kind:`combo`,name:e.name})),...w.map(e=>({kind:`alias`,name:e.alias}))].filter(e=>ue===``||e.name.toLowerCase().includes(ue)),H=T(z.length,N,F);(0,B.useEffect)(()=>H.clamp(),[H.pageCount,N]);let U=H.slice(z),W=e=>{o(e),r(e)},G=e=>W({...a,global:e}),K=e=>W({...a,presets:e}),de=(e,t)=>W({...a,providers:(()=>{let n={...a.providers};return t===void 0?delete n[e]:n[e]=t,n})()}),fe=(e,t,n)=>W({...a,models:(()=>{let r={...a.models},i=X(e,t);return n===void 0?delete r[i]:r[i]=n,r})()}),J=(e,t,n)=>W({...a,...e===`combo`?{combos:(()=>{let e={...a.combos};return n===void 0?delete e[t]:e[t]=n,e})()}:{aliases:(()=>{let e={...a.aliases};return n===void 0?delete e[t]:e[t]=n,e})()}}),pe=p.map(e=>({value:e.providerId,label:e.label??e.displayName}));return(0,V.jsx)(f,{open:e,onClose:t,title:`Inject System Prompt`,size:`lg`,footer:(0,V.jsx)(V.Fragment,{children:(0,V.jsx)(i,{variant:`secondary`,onClick:t,children:`Done`})}),children:(0,V.jsxs)(P,{gap:`20px`,children:[(0,V.jsxs)(`section`,{children:[(0,V.jsxs)(`h4`,{className:`flex items-center gap-2.5 text-caption font-semibold text-text-primary`,children:[(0,V.jsx)(R,{size:14,className:`text-text-secondary`,"aria-hidden":`true`}),`Presets`]}),(0,V.jsx)(`p`,{className:`mb-3 mt-1 text-badge leading-normal text-text-tertiary`,children:`Create reusable prompts, then reference them from any scope below.`}),(0,V.jsx)(be,{presets:a.presets,onChange:K})]}),(0,V.jsxs)(`section`,{className:`border-t border-inner-border pt-6`,children:[(0,V.jsxs)(`h4`,{className:`flex items-center gap-2.5 text-caption font-semibold text-text-primary`,children:[(0,V.jsx)(le,{size:14,className:`text-text-secondary`,"aria-hidden":`true`}),`Global`]}),(0,V.jsx)(`p`,{className:`mb-3 mt-1 text-badge leading-normal text-text-tertiary`,children:`Applied to every request regardless of provider, model, combo, or alias.`}),(0,V.jsx)(ye,{value:a.global,presets:a.presets,onChange:G})]}),(0,V.jsxs)(`section`,{className:`border-t border-inner-border pt-6`,children:[(0,V.jsxs)(`h4`,{className:`flex items-center gap-2.5 text-caption font-semibold text-text-primary`,children:[(0,V.jsx)(ne,{size:14,className:`text-text-secondary`,"aria-hidden":`true`}),`Per model`]}),(0,V.jsx)(`p`,{className:`mb-3 mt-1 text-badge leading-normal text-text-tertiary`,children:`Only that exact model of a provider gets this prompt; it wins over the provider and global injections.`}),(0,V.jsx)(_e,{label:`Provider`,id:`isp-model-provider`,value:y,onValueChange:ee,options:pe,placeholder:`Select provider…`}),(0,V.jsx)(`div`,{className:`mt-3`,children:y===``?(0,V.jsx)(`p`,{className:`text-badge leading-normal text-text-tertiary`,children:`Select a provider to configure per-model injections.`}):b.isPending?(0,V.jsx)(l,{label:`Loading models…`}):b.isError?(0,V.jsx)(c,{message:`Failed to load models`,onRetry:()=>void b.refetch()}):x.length===0?(0,V.jsx)(`p`,{className:`text-badge leading-normal text-text-tertiary`,children:`No models configured for this provider.`}):(0,V.jsxs)(V.Fragment,{children:[(()=>{let e=x.filter(e=>{let t=a.models[X(y,e.modelId)];return t?.kind===`custom`?t.setting.enabled:t?.kind===`preset`&&a.presets[t.presetId]?.enabled===!0}).length;return(0,V.jsx)(`p`,{className:`mb-3 text-badge leading-normal text-text-tertiary`,children:e>0?`${e} of ${x.length} models active for this provider.`:`${x.length} models — none active yet.`})})(),(0,V.jsx)(`div`,{className:`grid grid-cols-3 gap-4 max-medium:grid-cols-2 max-small:grid-cols-1`,children:ae.map(e=>(0,V.jsx)(Ce,{providerId:y,modelId:e.modelId,route:e.route,value:a.models[X(y,e.modelId)],presets:a.presets,onChange:t=>fe(y,e.modelId,t)},X(y,e.modelId)))}),M.pageCount>1?(0,V.jsx)(`div`,{className:`mt-4`,children:(0,V.jsx)(L,{page:M.safePage,pageCount:M.pageCount,onPageChange:j,testId:`isp-model-pagination`})}):null]})})]}),(0,V.jsxs)(`section`,{className:`border-t border-inner-border pt-6`,children:[(0,V.jsxs)(`h4`,{className:`flex items-center gap-2.5 text-caption font-semibold text-text-primary`,children:[(0,V.jsx)(u,{size:14,className:`text-text-secondary`,"aria-hidden":`true`}),`Per provider`]}),(0,V.jsx)(`p`,{className:`mb-3 mt-1 text-badge leading-normal text-text-tertiary`,children:`Follow the global prompt, reference a preset, or carry a custom one — models under a custom provider can still override per-model.`}),d.isPending?(0,V.jsx)(l,{label:`Loading providers…`}):d.isError?(0,V.jsx)(c,{message:`Failed to load providers`,onRetry:()=>void d.refetch()}):p.length===0?(0,V.jsx)(`p`,{className:`text-badge leading-normal text-text-tertiary`,children:`No providers configured yet.`}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`input`,{type:`search`,value:m,onChange:e=>g(e.target.value),placeholder:`Search providers…`,"aria-label":`Search providers`,className:`form-input w-full rounded-control border border-inner-border bg-surface-2 px-6 py-4 text-body text-text-primary outline-none transition-[border-color,box-shadow] duration-(--dur-micro) ease-spring focus:border-accent focus:shadow-focus`}),v.length===0?(0,V.jsxs)(`p`,{className:`mt-4 text-badge leading-normal text-text-tertiary`,children:[`No providers match “`,m.trim(),`”.`]}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`div`,{className:`mt-4 grid grid-cols-3 gap-4 max-medium:grid-cols-2 max-small:grid-cols-1`,children:k.map(e=>(0,V.jsx)(Se,{provider:e,entry:a.providers[e.providerId],presets:a.presets,onChange:t=>de(e.providerId,t)},e.providerId))}),O.pageCount>1?(0,V.jsx)(`div`,{className:`mt-4`,children:(0,V.jsx)(L,{page:O.safePage,pageCount:O.pageCount,onPageChange:D,testId:`isp-provider-pagination`})}):null]})]})]}),(0,V.jsxs)(`section`,{className:`border-t border-inner-border pt-6`,children:[(0,V.jsxs)(`h4`,{className:`flex items-center gap-2.5 text-caption font-semibold text-text-primary`,children:[(0,V.jsx)(u,{size:14,className:`text-text-secondary`,"aria-hidden":`true`}),`Combos & Aliases`]}),(0,V.jsx)(`p`,{className:`mb-3 mt-1 text-badge leading-normal text-text-tertiary`,children:`A combo or alias can carry its own injection — global, a preset, or custom — applied when a request arrives through that name.`}),S.isPending||C.isPending?(0,V.jsx)(l,{label:`Loading combos & aliases…`}):S.isError||C.isError?(0,V.jsx)(c,{message:`Failed to load combos/aliases`,onRetry:()=>{S.refetch(),C.refetch()}}):te.length===0&&w.length===0?(0,V.jsx)(`p`,{className:`text-badge leading-normal text-text-tertiary`,children:`No combos or aliases configured — create them in Routing first.`}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`relative`,children:[(0,V.jsx)(h,{size:14,className:`absolute left-5 top-1/2 -translate-y-1/2 text-text-tertiary`}),(0,V.jsx)(`input`,{type:`search`,value:I,onChange:e=>{ce(e.target.value),F(1)},placeholder:`Search combos or aliases…`,"aria-label":`Search combos and aliases`,className:`form-input w-full rounded-control border border-inner-border bg-surface-2 py-4 pr-5 pl-16 text-body text-text-primary outline-none transition-[border-color,box-shadow] duration-(--dur-micro) ease-spring focus:border-accent focus:shadow-focus`})]}),U.length===0?(0,V.jsxs)(`p`,{className:`mt-4 text-badge leading-normal text-text-tertiary`,children:[`No combos or aliases match “`,I.trim(),`”.`]}):(0,V.jsx)(`div`,{"data-testid":`isp-named-grid`,className:`mt-4 grid grid-cols-2 gap-4 max-small:grid-cols-1`,children:U.map(e=>(0,V.jsx)(we,{kind:e.kind,name:e.name,value:a[e.kind===`combo`?`combos`:`aliases`][e.name],presets:a.presets,onChange:t=>J(e.kind,e.name,t)},`${e.kind}:${e.name}`))}),H.pageCount>1?(0,V.jsx)(`div`,{className:`mt-4`,children:(0,V.jsx)(L,{page:H.safePage,pageCount:H.pageCount,onPageChange:F,testId:`isp-named-pagination`})}):null]})]})]})})}function Ee(){let[e,t]=(0,B.useState)(!1),n=U(),r=W(),o=n.data??J,s=Object.values(o.providers).filter(e=>e.kind===`custom`&&e.setting.enabled).length+Object.values(o.providers).filter(e=>e.kind===`preset`&&o.presets[e.presetId]?.enabled).length,c=Object.values(o.models).filter(e=>e.kind===`custom`&&e.setting.enabled).length+Object.values(o.models).filter(e=>e.kind===`preset`&&o.presets[e.presetId]?.enabled).length,l=Object.values(o.combos).filter(e=>e.kind===`custom`&&e.setting.enabled).length+Object.values(o.aliases).filter(e=>e.kind===`custom`&&e.setting.enabled).length+Object.values(o.combos).filter(e=>e.kind===`preset`&&o.presets[e.presetId]?.enabled).length+Object.values(o.aliases).filter(e=>e.kind===`preset`&&o.presets[e.presetId]?.enabled).length,d=Object.values(o.presets).length;return(0,V.jsxs)(O,{children:[(0,V.jsx)(D,{title:`Inject System Prompt`,subtitle:`Append custom system instructions to requests`,icon:(0,V.jsx)(R,{size:16}),action:(0,V.jsx)(F,{children:(0,V.jsx)(i,{variant:`secondary`,size:`sm`,icon:(0,V.jsx)(g,{size:13}),onClick:()=>t(!0),children:`Open Settings`})})}),(0,V.jsx)(E,{children:(0,V.jsxs)(P,{gap:`14px`,children:[(0,V.jsx)(`div`,{className:`grid grid-cols-3 gap-4 max-medium:grid-cols-1`,children:(()=>{let e=o.global,t=e!==null&&(e.kind===`custom`?e.setting.enabled:e.kind===`preset`&&o.presets[e.presetId]?.enabled===!0),n=t?e?.kind===`preset`?`Preset · ${o.presets[e.presetId]?.name??e.presetId}`:e?.kind===`custom`&&e.setting.mode===`override`?`Override`:`On`:`Off`,r=({icon:e,label:t,value:n,active:r})=>(0,V.jsxs)(`div`,{className:`flex items-center gap-3 rounded-control border px-4 py-3.5 ${r?`border-inner-border bg-green-soft`:`border-inner-border bg-surface-2`}`,children:[(0,V.jsx)(`span`,{className:`shrink-0 ${r?`text-green`:`text-text-tertiary`}`,"aria-hidden":`true`,children:e}),(0,V.jsxs)(`div`,{className:`min-w-0`,children:[(0,V.jsx)(`p`,{className:`text-badge text-text-tertiary`,children:t}),(0,V.jsx)(`p`,{className:`truncate text-body font-semibold ${r?`text-green`:`text-text-tertiary`}`,children:n})]})]});return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(r,{icon:(0,V.jsx)(le,{size:16}),label:`Global`,value:n,active:t}),(0,V.jsx)(r,{icon:(0,V.jsx)(R,{size:16}),label:`Presets`,value:d>0?`${d} preset${d>1?`s`:``}`:`None`,active:d>0}),(0,V.jsx)(r,{icon:(0,V.jsx)(u,{size:16}),label:`Scopes`,value:s+c+l>0?`${s+c+l} active`:`None`,active:s+c+l>0})]})})()}),n.isError?(0,V.jsx)(I,{tone:`danger`,surface:`raised`,live:`status`,children:x(n.error,`Failed to load system prompt settings`)}):null,(0,V.jsx)(`p`,{className:`text-caption leading-normal text-text-secondary`,children:`Add custom system prompts at many levels — global, presets, per provider, per model, or per combo/alias — handy for enforcing tone, rules, or context where you need it.`})]})}),(0,V.jsx)(Te,{open:e,onClose:()=>t(!1),state:o,onSave:e=>r.mutate(e,{onSuccess:()=>a.success(`System prompt settings saved`),onError:e=>a.error(x(e,`Could not save system prompt settings`))})})]})}export{W as a,U as i,Ee as n,H as o,q as r,R as s,J as t};
@@ -1 +1 @@
1
- import{o as e,r as t,t as n}from"./jsx-runtime-CXUMngI_.js";import{c as r}from"./numbers-CoqpaDMx.js";import{t as i}from"./log-in-BmRjy60c.js";import{o as a,t as o}from"./query-keys-YSoQOUh6.js";import{it as s,nt as c,t as l,z as u}from"./entry-D6WvojeD.js";import{n as d}from"./input-BlmlizVV.js";var f=e(t(),1),p=n();function m(e){return e?.startsWith(`/`)&&!e.startsWith(`//`)?e:`/`}function h(){let e=c(),[t]=s(),[n,h]=(0,f.useState)(``),[g,_]=(0,f.useState)(``),[v,y]=(0,f.useState)(null),[b,x]=(0,f.useState)(!1),[S,C]=(0,f.useState)(!0);return(0,f.useEffect)(()=>{let t=!0;return a(`/auth/first-boot`).then(n=>{if(t){if(n.requires_setup){e(`/setup`,{replace:!0});return}C(!1)}}).catch(()=>{t&&C(!1)}),()=>{t=!1}},[e]),S?(0,p.jsx)(l,{title:`Cartethyia Console`,description:`Checking console setup...`,children:(0,p.jsxs)(`div`,{className:`flex flex-col gap-7`,"aria-hidden":`true`,children:[(0,p.jsx)(`div`,{className:`h-20 rounded-control bg-surface-2 animate-pulse`}),(0,p.jsx)(`div`,{className:`h-20 rounded-control bg-surface-2 animate-pulse`}),(0,p.jsx)(`div`,{className:`h-20 rounded-control bg-surface-2 animate-pulse`})]})}):(0,p.jsx)(l,{title:`Cartethyia Console`,description:`Sign in to manage AI Gateway routing and providers`,children:(0,p.jsxs)(`form`,{onSubmit:async r=>{r.preventDefault(),x(!0),y(null);try{let r=await a(`/auth/login`,{method:`POST`,body:JSON.stringify({username:n.trim(),password:g})});if(r.status!==`success`){if(r.requires_setup){e(`/setup`,{replace:!0});return}_(``),y(r.message??`Authentication failed. Please check your credentials.`);return}u.removeQueries({queryKey:o.session.current}),e(r.requires_setup?`/setup`:m(t.get(`returnTo`)),{replace:!0})}catch(e){if(e&&typeof e==`object`&&`message`in e){let t=e.message;if(typeof t==`string`){_(``),y(t);return}}y(`An unexpected network error occurred.`)}finally{x(!1)}},className:`flex flex-col gap-7`,children:[(0,p.jsx)(d,{label:`Username`,id:`login-username`,value:n,onChange:e=>h(e.target.value),required:!0,autoComplete:`username`,placeholder:`admin`}),(0,p.jsx)(d,{label:`Password`,id:`login-password`,type:`password`,value:g,onChange:e=>_(e.target.value),required:!0,autoComplete:`current-password`}),v?(0,p.jsx)(`div`,{className:`py-5 px-7 rounded-control bg-red-soft text-red text-caption font-medium`,role:`alert`,children:v}):null,(0,p.jsx)(r,{variant:`primary`,type:`submit`,disabled:b,className:`w-full mt-3 h-20`,icon:(0,p.jsx)(i,{size:15}),children:b?`Authenticating…`:`Sign In`})]})})}export{h as default};
1
+ import{o as e,r as t,t as n}from"./jsx-runtime-CXUMngI_.js";import{c as r}from"./numbers-CoqpaDMx.js";import{t as i}from"./log-in-BmRjy60c.js";import{o as a,t as o}from"./query-keys-YSoQOUh6.js";import{R as s,rt as c,t as l,tt as u}from"./entry-vqGb8yVz.js";import{n as d}from"./input-BlmlizVV.js";var f=e(t(),1),p=n();function m(e){return e?.startsWith(`/`)&&!e.startsWith(`//`)?e:`/`}function h(){let e=u(),[t]=c(),[n,h]=(0,f.useState)(``),[g,_]=(0,f.useState)(``),[v,y]=(0,f.useState)(null),[b,x]=(0,f.useState)(!1),[S,C]=(0,f.useState)(!0);return(0,f.useEffect)(()=>{let t=!0;return a(`/auth/first-boot`).then(n=>{if(t){if(n.requires_setup){e(`/setup`,{replace:!0});return}C(!1)}}).catch(()=>{t&&C(!1)}),()=>{t=!1}},[e]),S?(0,p.jsx)(l,{title:`Cartethyia Console`,description:`Checking console setup...`,children:(0,p.jsxs)(`div`,{className:`flex flex-col gap-7`,"aria-hidden":`true`,children:[(0,p.jsx)(`div`,{className:`h-20 rounded-control bg-surface-2 animate-pulse`}),(0,p.jsx)(`div`,{className:`h-20 rounded-control bg-surface-2 animate-pulse`}),(0,p.jsx)(`div`,{className:`h-20 rounded-control bg-surface-2 animate-pulse`})]})}):(0,p.jsx)(l,{title:`Cartethyia Console`,description:`Sign in to manage AI Gateway routing and providers`,children:(0,p.jsxs)(`form`,{onSubmit:async r=>{r.preventDefault(),x(!0),y(null);try{let r=await a(`/auth/login`,{method:`POST`,body:JSON.stringify({username:n.trim(),password:g})});if(r.status!==`success`){if(r.requires_setup){e(`/setup`,{replace:!0});return}_(``),y(r.message??`Authentication failed. Please check your credentials.`);return}s.removeQueries({queryKey:o.session.current}),e(r.requires_setup?`/setup`:m(t.get(`returnTo`)),{replace:!0})}catch(e){if(e&&typeof e==`object`&&`message`in e){let t=e.message;if(typeof t==`string`){_(``),y(t);return}}y(`An unexpected network error occurred.`)}finally{x(!1)}},className:`flex flex-col gap-7`,children:[(0,p.jsx)(d,{label:`Username`,id:`login-username`,value:n,onChange:e=>h(e.target.value),required:!0,autoComplete:`username`,placeholder:`admin`}),(0,p.jsx)(d,{label:`Password`,id:`login-password`,type:`password`,value:g,onChange:e=>_(e.target.value),required:!0,autoComplete:`current-password`}),v?(0,p.jsx)(`div`,{className:`py-5 px-7 rounded-control bg-red-soft text-red text-caption font-medium`,role:`alert`,children:v}):null,(0,p.jsx)(r,{variant:`primary`,type:`submit`,disabled:b,className:`w-full mt-3 h-20`,icon:(0,p.jsx)(i,{size:15}),children:b?`Authenticating…`:`Sign In`})]})})}export{h as default};
@@ -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{n as a,t as o}from"./arrow-up-59ms1iiT.js";import{n as s,t as c}from"./minimize-2-BTmMTK4o.js";import{n as l,t as u}from"./fingerprint-pattern-BWuHtbW4.js";import{D as d,E as f,S as p,c as m,g as h,k as ee,w as g,y as _}from"./numbers-CoqpaDMx.js";import{t as v}from"./chevron-right-BXIy5l3h.js";import{n as y,o as b}from"./InjectSystemPromptPanel-d5v3K_Yc.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 w}from"./gauge-BbIMy7MB.js";import{n as T,r as E,t as D}from"./state-DHmEnLa2.js";import{t as O}from"./key-round-UkavsGxp.js";import{n as te,r as ne,t as k}from"./clipboard-button-DfS1ntiq.js";import{n as A,t as j}from"./dialog-BK-NRr5u.js";import{t as M}from"./pencil-768ysRAr.js";import{t as re}from"./plus-DIdX_g-x.js";import{t as N}from"./power-off-Yjw9GMJh.js";import{t as ie}from"./refresh-cw-BqJFk4sU.js";import{t as P}from"./route-CNSNj9Zm.js";import{t as F}from"./search-JOKus9rb.js";import{t as I}from"./shield-check-DVS0Foqh.js";import{t as ae}from"./shield-BMQNxORh.js";import{t as oe}from"./trash-Cppn5c3R.js";import{C as L,T as se,b as ce,x as le}from"./assert-CidQVoNo.js";import{l as R,o as z,t as ue}from"./query-keys-YSoQOUh6.js";import{t as B}from"./useMutation-CbCP4w1o.js";import{V as de,lt as fe,pt as pe,st as V}from"./entry-D6WvojeD.js";import{n as me,r as H,t as he}from"./card-CxDw0lK6.js";import{t as U}from"./use-clipboard-B0Sy03fE.js";import{n as ge}from"./download-dRFo5_Wu.js";import{c as W,d as _e}from"./tokens-COzario9.js";import{t as G}from"./switch-DmZcyTIC.js";import{t as K}from"./badge-BaX2GTrn.js";import{n as q,t as ve}from"./input-BlmlizVV.js";import{t as ye}from"./select-BHqpd-bg.js";import{t as be}from"./ModelPicker-C6WlpU5E.js";import{t as J}from"./stack-j7cXjgYX.js";import{n as Y}from"./inline-CHJQwxLa.js";import{a as xe,c as Se,d as Ce,f as we,g as Te,h as Ee,i as De,l as Oe,m as ke,o as Ae,p as X,r as je,s as Z,t as Me,u as Ne}from"./api-keys-KvX83mRe.js";import{a as Pe,i as Fe,o as Ie,r as Le}from"./cli-tools-Bwv5-zGZ.js";import{t as Re}from"./layout-Bz93I-yE.js";import{c as ze}from"./quota-DJ1QlAOq.js";import{n as Be,t as Ve}from"./settings-BxslsErn.js";import{t as He}from"./banner-DFH4Bkte.js";var Ue=e(`chevrons-up-down`,[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]),We=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`}]]),Ge=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`}]]),Ke=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`}]]),qe=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`}]]),Je=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`}]]),Ye=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`}]]),Xe=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`}]]),Ze=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`}]]),$e=e(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]),et=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`}]]),tt=[`routing:invoke`,`routing:cli_mapping`,`search:invoke`,`dashboard:read`,`dashboard:write`,`providers:read`,`providers:write`,`models:read`,`models:write`],nt=[`image/png`,`image/jpeg`,`image/webp`,`image/gif`],Q=t(n(),1),$=r(),rt={"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.`},it={"routing:invoke":P,"routing:cli_mapping":P,"search:invoke":F,"dashboard:read":C,"dashboard:write":M,"providers:read":V,"providers:write":We,"models:read":l,"models:write":x},at={k:1e3,m:1e6,b:1e9,t:0xe8d4a51000},ot=[{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 st(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]?at[n[2]]??1:1;return Math.round(r*i)}function ct(e){if(e==null)return``;let t=ot.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 lt(e){let t=Number(e.trim());return Number.isFinite(t)&&t>0?Math.round(t):void 0}function ut(e){let t=lt(e);return e.trim()===``?null:t}function dt({label:e,value:t,onChange:n,disabled:r}){let i=st(t),a=ot.find(e=>e.amount===i)?.label;return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(q,{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:ot.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 ft({tool:e,keyId:t,busy:n,scopeGranted:r,onScopeChange:i}){let a=Pe(e.id,t),o=Fe(),s=Le(),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)(P,{size:16,className:`mt-1 shrink-0 text-accent`,"aria-hidden":`true`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-caption font-semibold text-text-primary`,children:e.name}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:l?`Remote routing on — ${u} route${u===1?``:`s`} active, routing:cli_mapping granted.`:`Remote routing off — this key's requests go straight to the provider.`})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,$.jsx)(G,{checked:l,disabled:n||d||a.isLoading,"aria-label":`Enable remote routing for ${e.name}`,onChange:n=>{n!==r&&i(n),o.mutate({toolId:e.id,keyId:t,input:{enabled:n,mappings:a.data?.mappings??[]}},{onSuccess:()=>h.success(`Saved remote routing for ${e.name}.`),onError:e=>h.error(R(e,`Could not save remote routing.`))})}}),(0,$.jsx)(m,{variant:`secondary`,size:`sm`,disabled:n||d||!c&&u===0,onClick:()=>s.mutate({toolId:e.id,keyId:t},{onSuccess:()=>h.success(`Cleared remote routes for ${e.name}.`),onError:e=>h.error(R(e,`Could not reset remote routes.`))}),children:s.isPending?`Resetting…`:`Reset`})]})]})}function pt({keyId:e,busy:t,scopeGranted:n,onScopeChange:r,persistScope:i}){let a=(Ie().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)(P,{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)(ft,{tool:a,keyId:e,busy:t,scopeGranted:n,onScopeChange:e=>{r(e),i(e)}},a.id))})]})}function mt(e,t,n){let r=e===`personal`?t.trim():``;return{keyMode:e,keyPrefix:n.trim()||void 0,...r?{key:r}:{}}}function ht(e,t){return e===`personal`?t??null:null}function gt(e){let t=e?.scopes;return e?.isDefault?t&&t.length>0?[...t]:[...tt]:t&&t.length>0?[...t]:[`routing:invoke`,`search:invoke`]}function _t({mode:e,record:t,busy:n,onDone:r,onClose:i,actionsRef:a}){let[o,c]=(0,Q.useState)(t?.label??``),[d,f]=(0,Q.useState)(t?.keyPrefix??``),[p,ee]=(0,Q.useState)(``),[g,_]=(0,Q.useState)(t?.requestsPerMinute?.toString()??``),[v,y]=(0,Q.useState)(ct(t?.dailyTokenLimit??null)),[b,x]=(0,Q.useState)(ct(t?.monthlyTokenLimit??null)),[S,C]=(0,Q.useState)(ct(t?.lifetimeTokenBudget??null)),[T,E]=(0,Q.useState)(t?.lifetimeTokenBudget==null?`recurring`:`one-time`),[D,ne]=(0,Q.useState)(t?.maxConcurrentRequests?.toString()??``),[k,j]=(0,Q.useState)(t?.concurrencyScope??`family`),[M,re]=(0,Q.useState)(t?.maxChildren?.toString()??``),[N,ie]=(0,Q.useState)(()=>gt(t)),[F,oe]=(0,Q.useState)(t?.modelAccessMode??`whitelist`),[L,se]=(0,Q.useState)(()=>{let e=t?.modelList;return e?[...e]:[]}),[z,ue]=(0,Q.useState)(!1),[B,de]=(0,Q.useState)(()=>{let e=t?.clientRouterDenylist;return e?[...new Set(e.map(le).filter(e=>e!==void 0))]:[]}),[V,me]=(0,Q.useState)(()=>t?.notesTitle??``),[H,he]=(0,Q.useState)(()=>t?.notesSubtitle??``),[U,ge]=(0,Q.useState)(()=>t?.notesBody??``),[W,_e]=(0,Q.useState)(t?.sharePopupEnabled??!0),[K,J]=(0,Q.useState)(null),[Y,xe]=(0,Q.useState)(!1),[Se,Ce]=(0,Q.useState)(null),we=t?.sharePopupImageMime!==void 0,Ee=K??(we&&!Y&&t!==null?`/console/api/api-keys/${t.id}/share-popup-image`:null);(0,Q.useEffect)(()=>{we||K!==null||Y||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=>J(e)).catch(()=>{})},[]);let[De,Oe]=(0,Q.useState)(t?.sharePopupTitle??`Support via QRIS`),[ke,Ae]=(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! 🙏`),[X,je]=(0,Q.useState)(t?.keyMode??`personal`),Z=T===`one-time`,Me=e===`edit`,Ne=(0,Q.useMemo)(()=>{if(e===`create`)return o.trim().length>0||p.trim().length>0||d.trim().length>0||g.trim().length>0||v.trim().length>0||b.trim().length>0||S.trim().length>0||D.trim().length>0||M.trim().length>0||V.trim().length>0||H.trim().length>0||U.trim().length>0||N.length>0||L.length>0||B.length>0||K!==null||Y;let n=t;return n===null?!1:o.trim()!==(n.label??``)||g.trim()!==(n.requestsPerMinute?.toString()??``)||v.trim()!==ct(n?.dailyTokenLimit??null)||b.trim()!==ct(n?.monthlyTokenLimit??null)||S.trim()!==ct(n?.lifetimeTokenBudget??null)||T!==(n?.lifetimeTokenBudget==null?`recurring`:`one-time`)||D.trim()!==(n.maxConcurrentRequests?.toString()??``)||k!==(n.concurrencyScope??`family`)||M.trim()!==(n?.maxChildren?.toString()??``)||V.trim()!==(n?.notesTitle??``)||H.trim()!==(n?.notesSubtitle??``)||U.trim()!==(n?.notesBody??``)||N.join(`,`)!==gt(n).join(`,`)||F!==(n?.modelAccessMode??`whitelist`)||L.join(`,`)!==(n.modelList??[]).join(`,`)||B.join(`,`)!==(n?.clientRouterDenylist??[]).join(`,`)||W!==(n.sharePopupEnabled??!0)||K!==null||Y||De.trim()!==(n.sharePopupTitle??`Support via QRIS`)||ke.trim()!==(n.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! 🙏`)},[e,t,o,p,d,g,v,b,S,T,D,k,M,N,F,L,B,V,H,U,W,K,Y,De,ke]);A(Ne);let Pe=Te(),Fe=e=>ie(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),Ie=()=>{r({label:o.trim(),...mt(X,p,d),scopes:N,modelAccessMode:F,modelList:L,clientRouterDenylist:B,requestsPerMinute:ut(g),maxConcurrentRequests:ut(D),concurrencyScope:X===`share`?k:void 0,maxChildren:X===`share`?ut(M):null,dailyTokenLimit:Z?null:st(v)??null,monthlyTokenLimit:Z?null:st(b)??null,lifetimeTokenBudget:Z?st(S)??null:null,notesTitle:V.trim(),notesSubtitle:H.trim(),notesBody:U.trim(),sharePopupEnabled:W,...K===null?Y?{sharePopupImage:null}:{}:{sharePopupImage:K},sharePopupTitle:De.trim(),sharePopupBody:ke.trim()})};return(0,Q.useEffect)(()=>{a?.((0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(m,{variant:`secondary`,size:`sm`,onClick:i,disabled:n,children:`Cancel`}),(0,$.jsx)(m,{variant:`primary`,size:`sm`,disabled:n||e===`create`&&!o.trim(),onClick:Ie,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)(O,{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":X===e,disabled:n||Me,onClick:()=>je(e),title:Me?`Credential mode cannot change after creation`:void 0,className:`rounded-inset py-1.5 px-5`,style:{border:`1px solid var(--inner-border)`,color:X===e?`var(--accent)`:`var(--text-secondary)`,background:X===e?`var(--accent-soft)`:`var(--surface-2)`,cursor:Me?`not-allowed`:`pointer`,opacity:Me&&X!==e?.5:1},children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[e===`personal`?(0,$.jsx)($e,{size:14,"aria-hidden":`true`}):(0,$.jsx)(et,{size:14,"aria-hidden":`true`}),e===`personal`?`Personal`:`Share template`]})},e))}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:X===`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)(u,{size:16,className:`text-accent`,"aria-hidden":`true`}),`Identity`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Give this credential a recognizable name.`})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 items-start min-w-0 max-medium:grid-cols-1`,children:[(0,$.jsx)(q,{label:`Name`,value:o,onChange:e=>c(e.target.value),placeholder:`ci-key…`,disabled:n,autoFocus:!0}),(0,$.jsx)(q,{label:`Key prefix`,value:d,onChange:e=>f(e.target.value),placeholder:`pn-carte- (default)…`,disabled:n||p.trim().length>0})]}),X===`personal`&&(0,$.jsx)(q,{label:`Custom API key value (optional)`,value:p,onChange:e=>ee(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)(u,{size:16,className:`mr-2 inline text-accent`,"aria-hidden":`true`}),`Identity`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:t?.isDefault?`The default key's name is fixed. Limits, access, and everything else can still change.`:`Update the label for this credential.`})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-2 gap-4 items-start min-w-0 max-medium:grid-cols-1`,children:(0,$.jsx)(q,{label:`Name`,value:o,onChange:e=>c(e.target.value),placeholder:`ci-key…`,disabled:n||t?.isDefault===!0,title:t?.isDefault?`The default gateway key keeps its name`:void 0,autoFocus:!0})})]}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-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)(te,{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)(q,{label:`Title`,value:V,onChange:e=>me(e.target.value),placeholder:`e.g. Bansos Token`,disabled:n}),(0,$.jsx)(q,{label:`Subtitle`,value:H,onChange:e=>he(e.target.value),placeholder:`e.g. Come and save your tokens`,disabled:n}),(0,$.jsx)(`div`,{className:`col-span-full`,children:(0,$.jsx)(q,{label:`Body`,value:U,onChange:e=>ge(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)(w,{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)(q,{label:`Requests per minute`,type:`number`,min:`0`,value:g,onChange:e=>_(e.target.value),placeholder:`Unlimited…`,disabled:n}),(0,$.jsx)(q,{label:`Max concurrent requests`,type:`number`,min:`0`,value:D,onChange:e=>ne(e.target.value),placeholder:`Unlimited…`,disabled:n}),X===`share`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`api-key-concurrency-scope`,className:`form-label text-caption font-semibold text-text-primary`,children:`Concurrency scope`}),(0,$.jsx)(ye,{id:`api-key-concurrency-scope`,"aria-label":`Concurrency scope`,value:k,onValueChange:e=>j(e),options:[{value:`family`,label:`Whole share family (all recipients together)`},{value:`per_key`,label:`Per recipient key (each has its own cap)`}],size:`md`})]}):null,X===`share`?(0,$.jsx)(q,{label:`Recipient slots (max children)`,type:`number`,min:`0`,value:M,onChange:e=>re(e.target.value),placeholder:`Unlimited…`,disabled:n}):null]}),(0,$.jsx)(`p`,{className:`text-micro leading-normal text-text-tertiary`,children:D===``?`No concurrency limit, so the tenant allowance does nothing.`:X===`share`?k===`family`?`Limit ${D} concurrent across the whole share family — all recipients share this one cap.`:`Limit ${D} concurrent per recipient key — each key gets its own independent cap.`:`Limit ${D} concurrent for this key. 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)(w,{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:Z?`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:()=>E(`recurring`),disabled:n,className:`py-1.5 px-4 rounded-chip font-semibold border-0 cursor-pointer`,style:{fontSize:`10px`,background:Z?`transparent`:`var(--accent-soft)`,color:Z?`var(--text-tertiary)`:`var(--accent)`},children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(Ke,{size:13,"aria-hidden":`true`}),`Recurring`]})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>E(`one-time`),disabled:n,className:`py-1.5 px-4 rounded-chip font-semibold border-0 cursor-pointer`,style:{fontSize:`10px`,background:Z?`var(--accent-soft)`:`transparent`,color:Z?`var(--accent)`:`var(--text-tertiary)`},children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(We,{size:13,"aria-hidden":`true`}),`One-time`]})})]})]}),Z?(0,$.jsx)(dt,{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)(dt,{label:`Daily token limit`,value:v,onChange:y,disabled:n}),(0,$.jsx)(dt,{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)(Ye,{size:16,className:`mr-2 inline text-accent`,"aria-hidden":`true`}),`Share page popup`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Optional card visitors open from the Base URL card on your share page.`})]}),(0,$.jsx)(G,{checked:W,onChange:e=>_e(e),disabled:n,label:`Enable popup`})]}),W?(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:[Ee?(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:Ee,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)(ve,{id:`share-popup-image`,accept:nt.join(`,`),"aria-label":`Popup image`,disabled:n,onChange:e=>{let t=e.target.files?.[0];if(e.target.value=``,!t)return;if(Ce(null),t.size>2097152){J(null),Ce(`Image must be 2 MB or smaller.`);return}let n=new FileReader;n.onload=()=>{J(String(n.result)),xe(!1)},n.onerror=()=>Ce(`Could not read that file.`),n.readAsDataURL(t)}}),Ee?(0,$.jsx)(m,{variant:`secondary`,size:`sm`,type:`button`,disabled:n,className:`h-14 px-5 text-badge self-start`,onClick:()=>{J(null),xe(!0),Ce(null)},children:`Remove image`}):null,Se?(0,$.jsx)(`p`,{className:`form-error`,children:Se}):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)(q,{label:`Popup title`,value:De,onChange:e=>Oe(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:ke,onChange:e=>Ae(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)(ae,{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:[N.length,`/`,tt.length,` grants`,(0,$.jsx)(pe,{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)(I,{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)(l,{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":F===e,disabled:n,onClick:()=>oe(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 ${F===e?`var(--accent)`:`var(--inner-border)`}`,background:F===e?`var(--accent-soft)`:`var(--surface-2)`,color:F===e?`var(--accent)`:`var(--text-secondary)`,cursor:n?`not-allowed`:`pointer`,opacity:n?.6:1},children:[e===`whitelist`?`Whitelist`:`Blacklist`,e===`whitelist`?(0,$.jsx)(I,{size:13,className:`ml-1.5 inline`,"aria-hidden":`true`}):(0,$.jsx)(Ze,{size:13,className:`ml-1.5 inline`,"aria-hidden":`true`})]},e))}),(0,$.jsx)(`p`,{className:`text-badge text-text-tertiary m-0`,children:F===`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:L.length===0?(0,$.jsx)(`span`,{className:`text-badge text-text-tertiary`,children:F===`whitelist`?`All models allowed`:`No models blocked`}):L.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:()=>se(t=>t.filter(t=>t!==e)),disabled:n,className:`bg-transparent border-0 cursor-pointer p-0 flex`,children:`×`})]},e))}),(0,$.jsx)(m,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>ue(!0),disabled:n,children:`Browse models`}),(0,$.jsx)(be,{open:z,onClose:()=>ue(!1),selected:L,onToggle:e=>se(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),title:F===`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)(P,{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`}),tt.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:N.includes(e)?`var(--accent-soft)`:`var(--surface-2)`},children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(P,{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:rt[e]})]})]}),(0,$.jsx)(G,{checked:N.includes(e),onChange:()=>Fe(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:ce.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:B.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)(s,{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)(G,{checked:B.includes(e.id),onChange:t=>de(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)(pt,{keyId:e===`edit`&&t?t.id:``,busy:n,scopeGranted:N.includes(`routing:cli_mapping`),onScopeChange:e=>{e!==N.includes(`routing:cli_mapping`)&&Fe(`routing:cli_mapping`)},persistScope:n=>{if(e!==`edit`||!t)return;let r=n?[...new Set([...N,`routing:cli_mapping`])]:N.filter(e=>e!==`routing:cli_mapping`);Pe.mutate({keyId:t.id,request:{scopes:r}},{onError:e=>h.error(R(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)(fe,{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:tt.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:N.includes(e)?`var(--accent-soft)`:`var(--surface-2)`},children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3 min-w-0`,children:[(()=>{let t=it[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:rt[e]})]})]}),(0,$.jsx)(G,{checked:N.includes(e),onChange:()=>Fe(e),disabled:n,"aria-label":`Grant ${e}`})]},e))})]})]})]})]})]})]})}function vt({secret:e,onClose:t}){return(0,$.jsx)(j,{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)(k,{value:e??``,size:`sm`,variant:`primary`,label:`Copy key`,copiedLabel:`Copied`}),(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(f,{size:13}),onClick:()=>{e!==null&&(ge(`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`),h.success(`Key saved to your downloads.`))},children:`Save this key`})]})]})})}var yt=e=>(e??0).toLocaleString(),bt=e=>e?new Date(e).toLocaleString():`—`;function xt({keyId:e}){let t=Z(),[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)(m,{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=>h.error(R(e,`Could not reveal the key.`))})},children:i?`Hide`:`Reveal`}),i&&n?(0,$.jsx)(k,{value:n,size:`sm`,variant:`secondary`,label:`Copy`,copiedLabel:`Copied`}):null]})}function St({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`:yt(t)})]})}function Ct(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 wt({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?`${W(e)} · Unlimited`:`${W(e)} / ${W(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?`${W(e)} tokens consumed, no lifetime budget set`:`${W(e)} of ${W(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 Tt=25,Et=25,Dt=500;function Ot({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:W(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=ze(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:[W(e),` / `,W(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`:`${W(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":`${W(e)} of ${W(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 kt({parentId:e,childId:t}){let n=X(e,t);if(n.isPending)return(0,$.jsx)(E,{label:`Loading activity…`,compact:!0});if(n.isError)return(0,$.jsx)(T,{compact:!0,message:R(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:yt(e.todayRequests)}),(0,$.jsx)(`td`,{children:yt(e.todayErrors)}),(0,$.jsx)(`td`,{children:W(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:W(e.totalTokens)}),(0,$.jsx)(`td`,{children:bt(e.startedAt)})]},e.requestId))})]})}):(0,$.jsx)(`p`,{className:`py-3 text-caption text-text-tertiary`,children:`No recent requests.`})]})]}):null}function At({parent:e,onSecretRevealed:t}){let[n,r]=(0,Q.useState)(null),[i,c]=(0,Q.useState)(`active`),[l,u]=(0,Q.useState)(Tt),[d,f]=(0,Q.useState)(`createdAt`),[p,ee]=(0,Q.useState)(`desc`),[g,_]=(0,Q.useState)(null),y=Ce(),b=xe(),x=Oe(),S=Ne(),C=we(e.id),w=e.keyMode!==`share`,O=ke(w?null:e.id,{limit:l,offset:0,sortBy:d,order:p,status:i}),te=O.data,A=te?.rows??[],j=te?.active??0,M=A,re=()=>{r(null),u(Tt)},N=e=>{d===e?ee(e=>e===`asc`?`desc`:`asc`):(f(e),ee(`asc`)),re()},P=e=>{let t=e.currentTarget;t.scrollHeight-t.scrollTop-t.clientHeight<40&&!O.isFetching&&A.length>=l&&l<Dt&&u(e=>Math.min(e+Et,Dt))},F=({column:e,children:t})=>{let n=d===e;return(0,$.jsx)(`th`,{scope:`col`,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>N(e),className:`inline-flex cursor-pointer items-center gap-1 border-0 bg-transparent p-0 font-inherit text-inherit hover:text-text-primary`,"aria-label":`Sort by ${String(e)}`,children:[t,n?p===`asc`?(0,$.jsx)(o,{size:12,"aria-hidden":`true`}):(0,$.jsx)(a,{size:12,"aria-hidden":`true`}):(0,$.jsx)(Ue,{size:12,"aria-hidden":`true`,className:`text-text-tertiary`})]})})};(0,Q.useEffect)(()=>{r(null)},[e.id]);let I=async t=>{try{let n=await S.mutateAsync({parentKeyId:e.id,scope:t});u(Tt),h.success(`Revoked ${n.deleted.toLocaleString()} recipient${n.deleted===1?``:`s`}.`)}catch(e){h.error(R(e,`Could not revoke recipients.`))}},ae=y.isPending||b.isPending,[oe,L]=(0,Q.useState)(!1),se=async()=>{if(w){let n=await b.mutateAsync({keyId:e.id});t?.(n.secret);return}await y.mutateAsync({keyId:e.id,regenerate:!0}),h.success(`Link regenerated; the previous URL no longer works.`)},ce=()=>{y.mutate({keyId:e.id},{onError:e=>h.error(R(e,`Could not create link.`))})},le=C.data?.url??null,z=Ct(w);return(0,$.jsxs)(`div`,{className:`grid min-w-0 gap-6`,children:[(0,$.jsx)(`section`,{"aria-label":`Link`,children:C.isPending?(0,$.jsx)(E,{label:`Loading link…`,compact:!0}):C.isError?(0,$.jsx)(T,{compact:!0,message:R(C.error,`Could not load the link.`),onRetry:()=>void C.refetch()}):le?(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)(ne,{size:14,"aria-hidden":`true`,className:`shrink-0`}),(0,$.jsx)(`code`,{title:le,className:`min-w-0 flex-auto overflow-hidden font-mono text-caption text-text-primary text-ellipsis whitespace-nowrap`,children:le}),(0,$.jsx)(k,{value:le,size:`sm`,variant:`secondary`,label:`Copy`,copiedLabel:`Copied`}),(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(qe,{size:13}),loading:ae,disabled:ae,onClick:()=>L(!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)(ne,{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)(m,{variant:`primary`,size:`sm`,loading:ae,disabled:ae,onClick:ce,children:`Create link`})]})}),w?(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)(xt,{keyId:e.id})]}):null,w?(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:W(e.tokensConsumed)})]}),(0,$.jsx)(St,{label:`Requests / min`,value:e.requestsPerMinute}),(0,$.jsx)(St,{label:`Daily tokens`,value:e.dailyTokenLimit}),(0,$.jsx)(St,{label:`Monthly tokens`,value:e.monthlyTokenLimit}),(0,$.jsx)(wt,{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)(Ot,{consumed:te?.consumed??0,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: `,j.toLocaleString()]}),(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:()=>{re(),c(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))}),g===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:g===`all`?`Revoke all active recipients?`:`Revoke all active recipients that never spent a token?`}),(0,$.jsx)(m,{variant:`danger`,size:`sm`,loading:S.isPending,onClick:()=>{let e=g===`all`?`active`:`unused`;_(null),I(e)},children:`Confirm`}),(0,$.jsx)(m,{variant:`ghost`,size:`sm`,onClick:()=>_(null),children:`Cancel`})]}),(0,$.jsx)(m,{variant:`ghost`,size:`sm`,disabled:j===0||S.isPending,title:j===0?`No active recipients`:`Revoke every active recipient (${j.toLocaleString()})`,onClick:()=>_(`unused`),icon:(0,$.jsx)(s,{size:13}),children:`Revoke no-usage`}),(0,$.jsx)(m,{variant:`ghost`,size:`sm`,disabled:j===0||S.isPending,title:j===0?`No active recipients`:`Revoke all active recipients (${j.toLocaleString()})`,onClick:()=>_(`all`),icon:(0,$.jsx)(s,{size:13}),children:`Revoke all`}),(0,$.jsx)(m,{variant:`ghost`,size:`sm`,onClick:()=>void O.refetch(),icon:(0,$.jsx)(ie,{size:13,className:O.isFetching?`animate-spin`:void 0}),children:`Refresh`})]}),O.isPending&&!O.data?(0,$.jsx)(E,{label:`Loading recipients…`,compact:!0}):O.isError?(0,$.jsx)(T,{compact:!0,message:R(O.error,`Could not load recipients.`),onRetry:()=>void O.refetch()}):M.length===0?(0,$.jsx)(D,{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,$.jsxs)(`div`,{className:`data-table-container max-h-[46vh]`,onScroll:P,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)(F,{column:`label`,children:`Key`}),(0,$.jsx)(F,{column:`revokedAt`,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)(F,{column:`createdAt`,children:`Created`}),(0,$.jsx)(`th`,{scope:`col`,className:`text-right whitespace-nowrap`,children:`Actions`})]})}),(0,$.jsx)(`tbody`,{children:M.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)(pe,{size:14}):(0,$.jsx)(v,{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:W(t.today.totalTokens)}),(0,$.jsx)(`td`,{children:W(t.allTime.totalTokens)}),(0,$.jsx)(`td`,{children:bt(t.lastUsedAt)}),(0,$.jsx)(`td`,{children:bt(t.createdAt)}),(0,$.jsx)(`td`,{className:`text-right whitespace-nowrap`,children:(0,$.jsx)(m,{variant:`danger`,size:`sm`,disabled:x.isPending||!!t.revokedAt,onClick:()=>x.mutate({parentKeyId:e.id,childKeyId:t.id},{onError:e=>h.error(R(e,`Could not revoke key.`))}),children:`Revoke`})})]}),i?(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:8,className:`p-0`,children:(0,$.jsx)(kt,{parentId:e.id,childId:t.id})})}):null]},t.id)})})]}),O.isFetching&&A.length>0?(0,$.jsx)(`div`,{className:`border-t border-inner-border py-2 text-center text-badge text-text-tertiary`,children:`Loading more…`}):null,A.length>0&&A.length>=l&&l<Dt?(0,$.jsx)(`div`,{className:`py-2 text-center text-badge text-text-tertiary`,children:`Scroll for more`}):null]})]})]}),(0,$.jsx)(de,{open:oe,onClose:()=>L(!1),onConfirm:se,title:z.title,message:z.message,confirmLabel:z.confirmLabel,danger:!0})]})}function jt({parent:e,onClose:t,onSecretRevealed:n}){let r=e.keyMode!==`share`;return(0,$.jsx)(j,{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)(At,{parent:e,onSecretRevealed:n})})}function Mt(e){if(!e.bannedUntil)return`Permanent — lift manually`;let t=new Date(e.bannedUntil).getTime();if(!Number.isFinite(t))return`—`;let n=t-Date.now(),r=new Date(e.bannedUntil).toLocaleString();if(n<=0)return`${r} (lapsed)`;let i=Math.ceil(n/6e4);if(i<60)return`${r} (in ${i}m)`;let a=Math.floor(i/60);return a<24?`${r} (in ${a}h)`:`${r} (in ${Math.floor(a/24)}d)`}function Nt({onClose:e}){let t=je(),n=Ee(),[r,i]=(0,Q.useState)(null),a=Date.now(),o=(t.data??[]).filter(e=>e.bannedAt?!e.bannedUntil||new Date(e.bannedUntil).getTime()>a:!1);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(j,{open:!0,onClose:e,title:`Banned Users`,description:`API keys that have been banned. A timed ban lapses on its own; lifting one early is the escape hatch for a mistake.`,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 (`,o.length,`)`]}),t.isPending&&!t.data?(0,$.jsx)(E,{label:`Loading active bans…`}):t.isError&&!t.data?(0,$.jsx)(T,{message:R(t.error,`Could not load active bans.`),onRetry:()=>void t.refetch()}):o.length===0?(0,$.jsx)(D,{compact:!0,title:`No banned keys`,message:`No API key is currently banned.`,icon:(0,$.jsx)(Xe,{size:20})}):(0,$.jsx)(`div`,{className:`rounded-inset border border-inner-border`,children:(0,$.jsx)(Re,{maxHeight:480,scrollRegion:!0,headers:[`API key`,`Reason`,`Lapses`,``],children:o.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`font-mono tabular-nums text-badge text-text-primary whitespace-nowrap`,children:e.label||e.id.slice(0,8)}),(0,$.jsx)(`td`,{className:`text-badge text-text-secondary`,children:e.banReason??`—`}),(0,$.jsx)(`td`,{className:`text-badge text-text-secondary whitespace-nowrap`,children:Mt(e)}),(0,$.jsx)(`td`,{className:`text-right whitespace-nowrap`,children:(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(Qe,{size:13}),disabled:n.isPending,onClick:()=>i(e),children:`Unban`})})]},e.id))})})]}),(0,$.jsx)(Y,{justify:`flex-end`,gap:`0px`,children:(0,$.jsx)(m,{variant:`secondary`,size:`sm`,onClick:e,children:`Close`})})]})}),(0,$.jsx)(de,{open:r!==null,onClose:()=>i(null),onConfirm:async()=>{if(r)try{await n.mutateAsync({keyId:r.id}),h.success(`Unbanned ${r.label||r.id.slice(0,8)}.`),i(null)}catch(e){h.error(R(e,`Could not unban key.`))}},title:`Lift this ban?`,message:`Lift the ban on ${r?.label||`this key`}? The caller can reach the gateway again immediately.`,confirmLabel:`Unban`,danger:!0})]})}function Pt(){let e=Me(),t=De(),n=Te(),r=Se(),i=Ee(),a=xe(),o=Z(),s=Ae(),{copy:c}=U(),l=Ve(),u=Be(),f=l.data?.invokeDisabled===!0,[p,ee]=(0,Q.useState)(!1),[g,v]=(0,Q.useState)(!1),[y,x]=(0,Q.useState)(null),[S,w]=(0,Q.useState)(null),[te,ne]=(0,Q.useState)(!1),[k,A]=(0,Q.useState)(null),[ie,P]=(0,Q.useState)(null),[F,I]=(0,Q.useState)(null),[ae,L]=(0,Q.useState)(null),[se,ce]=(0,Q.useState)(null),[le,z]=(0,Q.useState)(null),ue=e.data??[],B=e=>{I(null),L(e)},fe=async e=>{try{let{secret:t}=await o.mutateAsync({keyId:e.id});await c(t)?h.success(`API key copied`):h.error(`Clipboard unavailable on this origin`)}catch(e){h.error(R(e,`Could not reveal API key.`))}},pe=Ct(!0),V=e=>{u.mutate({invokeDisabled:!e},{onSuccess:()=>h.success(e?`Invoke enabled — routing has resumed.`:`Invoke disabled — every API key is now refused (503).`),onError:e=>h.error(e instanceof Error?e.message:`Could not save the setting`)})};return(0,$.jsxs)(he,{children:[(0,$.jsx)(H,{title:`API Credentials`,subtitle:`Manage tenant API keys, model access, budgets, and sharing.`,icon:(0,$.jsx)(O,{size:16}),action:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(m,{variant:f?`primary`:`secondary`,size:`sm`,loading:l.isLoading||u.isPending,onClick:()=>ee(!0),icon:(0,$.jsx)(N,{size:13}),children:f?`Enable Invoke`:`Disable Invoke`}),(0,$.jsx)(m,{variant:`secondary`,size:`sm`,onClick:()=>ne(!0),icon:(0,$.jsx)(Xe,{size:13}),children:`Banned Users`}),(0,$.jsx)(m,{variant:`primary`,size:`sm`,onClick:()=>{I(null),v(!0)},icon:(0,$.jsx)(re,{size:13}),children:`Create Key`})]})}),(0,$.jsx)(me,{children:e.isPending&&!e.data?(0,$.jsx)(E,{label:`Loading API keys…`}):e.isError&&!e.data?(0,$.jsx)(T,{message:R(e.error,`Could not load credentials.`),onRetry:()=>void e.refetch()}):ue.length===0?(0,$.jsx)(D,{title:`No API keys issued`,message:`Generate a secret key to authenticate your SDK or CLI client against the gateway.`,icon:(0,$.jsx)(O,{size:20})}):(0,$.jsx)(`div`,{className:`scroll-region max-h-280 pr-1`,children:(0,$.jsx)(b,{items:ue,label:`API credentials`,disabled:s.isPending,onReorder:e=>s.mutate(e,{onError:e=>h.error(R(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)(K,{tone:e.revokedAt||e.bannedAt?`err`:e.enabled?`ok`:`warn`,children:e.revokedAt?`revoked`:e.bannedAt?`banned`:e.enabled?`enabled`:`disabled`}),e.bannedAt&&!e.revokedAt?(0,$.jsx)(K,{tone:`err`,title:e.banReason??`Banned`,children:(0,$.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 cursor-pointer bg-transparent border-0 p-0 text-inherit`,onClick:()=>A(e),children:[(0,$.jsx)(C,{size:11,"aria-hidden":`true`}),`See reason`]})}):null,(0,$.jsx)(K,{tone:e.keyMode===`share`?`accent`:`default`,children:e.keyMode===`share`?`share template`:`personal`}),e.isDefault?(0,$.jsx)(K,{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`}),W(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`}),_e(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`}),_e(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`}),_e(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`}),_e(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`}),_e(e.maxConcurrentRequests),e.keyMode===`share`?(0,$.jsx)(`span`,{className:`font-semibold text-text-tertiary`,title:e.concurrencyScope===`per_key`?`Each recipient key has its own concurrency cap and counter.`:`All recipients share one concurrency cap and counter.`,children:e.concurrencyScope===`per_key`?`· per key`:`· family`}):null]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap max-medium:justify-between`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:e.modelAccessMode===`blacklist`?`Blocked`:`Models`}),e.modelAccessMode===`blacklist`?e.modelList?.length??0:e.modelList?.length?e.modelList.length:`All`]})]})]}),(0,$.jsxs)(`div`,{className:`flex gap-3 shrink-0 flex-wrap`,children:[e.revokedAt?null:(0,$.jsx)(G,{checked:e.enabled,disabled:n.isPending,id:`api-key-enabled-${e.id}`,label:``,"aria-label":`${e.enabled?`Disable`:`Enable`} ${e.label||`API credential`}`,onChange:t=>n.mutate({keyId:e.id,request:{enabled:t}},{onSuccess:()=>h.success(`${e.label||`API credential`} ${t?`enabled`:`disabled`}`),onError:e=>h.error(R(e,`Could not update credential state.`))})}),(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(M,{size:13}),onClick:()=>{I(null),x(e)},children:`Edit`}),!e.revokedAt&&e.keyMode!==`share`?(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(d,{size:13}),onClick:()=>void fe(e),disabled:o.isPending,children:`Copy`}):null,!e.revokedAt&&(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(Ye,{size:13}),onClick:()=>B(e),children:e.keyMode===`share`?`Recipients`:`Share`}),!e.revokedAt&&e.keyMode!==`share`&&(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(qe,{size:13}),onClick:()=>{I(null),P(e)},disabled:a.isPending,children:`Rotate`}),!e.revokedAt&&!e.isDefault&&(0,$.jsx)(m,{variant:`danger`,size:`sm`,icon:(0,$.jsx)(oe,{size:13}),onClick:()=>w(e),disabled:r.isPending,children:`Revoke`}),e.bannedAt&&!e.revokedAt?(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(_,{size:13}),onClick:()=>{i.mutate({keyId:e.id},{onSuccess:()=>h.success(`Unbanned ${e.label||e.id}.`),onError:e=>h.error(R(e,`Could not unban key.`))})},disabled:i.isPending,children:`Unban`}):null]})]})})})}),(0,$.jsx)(j,{open:g,onClose:()=>v(!1),title:`Create API Key`,description:`Create a tenant-scoped credential. Choose model access, permissions, limits, and optional blocked client routers.`,size:`lg`,footer:se,children:(0,$.jsx)(_t,{mode:`create`,record:null,busy:t.isPending,onClose:()=>v(!1),actionsRef:ce,onDone:e=>{t.mutate(e,{onSuccess:t=>{v(!1),I(ht(e.keyMode,t.secret)),h.success(`API key created`)},onError:e=>h.error(R(e,`Could not create API key.`))})}})}),(0,$.jsx)(j,{open:y!==null,onClose:()=>x(null),title:`Edit API Key`,description:`Update the key's model access, permissions, limits, share notes, and optional public popup.`,size:`lg`,footer:le,children:(0,$.jsx)(_t,{mode:`edit`,record:y,busy:n.isPending,onClose:()=>x(null),actionsRef:z,onDone:e=>{y&&n.mutate({keyId:y.id,request:e},{onSuccess:t=>{x(null),I(ht(e.keyMode,t.secret)),h.success(`API key updated`)},onError:e=>h.error(R(e,`Could not update API key.`))})}})}),ae?(0,$.jsx)(jt,{parent:ae,onClose:()=>L(null),onSecretRevealed:e=>{L(null),I(e)}}):null,(0,$.jsx)(de,{open:ie!==null,onClose:()=>P(null),onConfirm:async()=>{if(!ie)return;let e=await a.mutateAsync({keyId:ie.id});I(e.secret),h.success(`Rotated ${ie.label||ie.id}.`),P(null)},title:pe.title,message:pe.message,confirmLabel:pe.confirmLabel,danger:!0}),(0,$.jsx)(de,{open:S!==null,onClose:()=>w(null),onConfirm:async()=>{S&&(await r.mutateAsync(S.id),h.success(`Revoked ${S.label||S.id}.`),w(null))},title:`Revoke API key?`,message:S?`Revoke ${S.label||S.id}? Clients using it will be rejected.${S.keyMode===`share`?` All child keys and enrollment links will also be revoked.`:``}`:`Revoke this API key?`,confirmLabel:`Revoke`,danger:!0}),(0,$.jsx)(de,{open:p,onClose:()=>ee(!1),onConfirm:async()=>{V(f)},title:f?`Enable Invoke?`:`Disable Invoke?`,message:f?`Allow this tenant's API keys to invoke /v1/* routes again. Traffic resumes immediately.`:`Disable invocation for every API key in this tenant? All /v1/* requests will be refused with 503, and nothing upstream is dialed. No keys, accounts, or models are deleted — the dashboard stays reachable so you can re-enable.`,confirmLabel:f?`Enable Invoke`:`Disable Invoke`,danger:!f}),(0,$.jsx)(vt,{secret:F,onClose:()=>I(null)}),te?(0,$.jsx)(Nt,{onClose:()=>ne(!1)}):null,(0,$.jsx)(j,{open:k!==null,onClose:()=>A(null),title:`Ban reason`,size:`sm`,footer:(0,$.jsx)(m,{variant:`secondary`,size:`sm`,onClick:()=>A(null),children:`Close`}),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`p`,{className:`text-caption text-text-secondary`,children:[k?.label||`API key`,` was banned.`]}),(0,$.jsx)(`div`,{className:`rounded-control border border-warning-line bg-surface-2 px-4 py-5 text-caption text-text-primary`,children:k?.banReason??`No reason recorded.`})]})})]})}var Ft=[{value:`lite`,label:`Lite`},{value:`full`,label:`Full`},{value:`ultra`,label:`Ultra`}],It={lite:`Lite`,full:`Full`,ultra:`Ultra`};function Lt({id:e,label:t,description:n,icon:r,enabled:i,strength:a,strengthSelectId:o,onToggle:s,onStrength:c}){return(0,$.jsx)(`div`,{className:`rounded-control border border-inner-border bg-surface-2 p-5`,children:(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,$.jsx)(`label`,{htmlFor:e,children:(0,$.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold`,children:[r,t]})}),(0,$.jsx)(K,{tone:i?`ok`:`default`,dot:!0,children:i?`Active · ${It[a]??a}`:`Off`})]}),(0,$.jsx)(`p`,{className:`mt-2 text-badge leading-normal text-text-tertiary`,children:n})]}),(0,$.jsxs)(Y,{gap:`8px`,className:`shrink-0 items-center`,children:[(0,$.jsx)(ye,{id:o,"aria-label":`${t} strength`,value:a,onValueChange:c,options:Ft}),(0,$.jsx)(G,{id:e,"aria-label":`Enable ${t}`,checked:i,onChange:s})]})]})})}function Rt(){let e=Ve(),t=Be(),n=e.data;if(e.isPending)return(0,$.jsx)(E,{label:`Loading compression settings…`});if(e.isError||!n)return(0,$.jsx)(T,{message:R(e.error,`Failed to load compression settings`),onRetry:()=>void e.refetch()});let r=n.rtkPruneEnabled,a=n.ponyTailEnabled;return(0,$.jsxs)(he,{children:[(0,$.jsx)(H,{title:`Compression`,subtitle:`Shrink requests before they reach the provider`,icon:(0,$.jsx)(c,{size:16})}),(0,$.jsx)(me,{children:(0,$.jsxs)(J,{gap:`14px`,children:[r||a?(0,$.jsx)(He,{tone:`warning`,surface:`raised`,live:`status`,children:(0,$.jsxs)(`span`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(_,{size:14,className:`mt-0.5 shrink-0`,"aria-hidden":`true`}),(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,(0,$.jsx)(Lt,{id:`compression-rtk`,label:`Prune tool output (RTK)`,description:`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.`,icon:(0,$.jsx)(Je,{size:16,className:`shrink-0 text-text-secondary`}),enabled:r,strength:n.rtkPruneLevel,strengthSelectId:`compression-rtk-level`,onToggle:e=>t.mutate({rtkPruneEnabled:e},{onError:e=>h.error(R(e,`Could not update RTK prune.`))}),onStrength:e=>t.mutate({rtkPruneLevel:e===`lite`||e===`full`||e===`ultra`?e:`full`},{onError:e=>h.error(R(e,`Could not update RTK strength.`))})}),(0,$.jsx)(Lt,{id:`compression-ponytail`,label:`PonyTail (system directive)`,description:`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.`,icon:(0,$.jsx)(i,{size:16,className:`shrink-0 text-text-secondary`}),enabled:a,strength:n.ponyTailLevel,strengthSelectId:`compression-ponytail-level`,onToggle:e=>t.mutate({ponyTailEnabled:e},{onError:e=>h.error(R(e,`Could not update PonyTail.`))}),onStrength:e=>t.mutate({ponyTailLevel:e===`lite`||e===`full`||e===`ultra`?e:`full`},{onError:e=>h.error(R(e,`Could not update PonyTail strength.`))})})]})})]})}function zt(){return L({queryKey:ue.remoteSupport.status,queryFn:()=>z(`/remote-support/status`)})}function Bt(){let e=se();return B({mutationFn:e=>z(`/remote-support/start`,{method:`POST`,body:JSON.stringify({tool:e})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:ue.remoteSupport.status})}})}function Vt(){let e=se();return B({mutationFn:e=>z(`/remote-support/stop`,{method:`POST`,body:JSON.stringify(e===void 0?{}:{tool:e})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:ue.remoteSupport.status})}})}var Ht={cloudflared:`cloudflared`,tailscale:`Tailscale`},Ut={cloudflared:`Publish a temporary public URL without opening a port.`,tailscale:`Give a helper a private address on your own tailnet.`};function Wt({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 Gt({tool:e}){let t=zt(),n=Bt(),r=Vt(),{copied:i,copy:a}=U(2e3),o=t.data?.active===e,s=n.isPending||r.isPending,c=o?t.data?.url??null:null,[l,u]=(0,Q.useState)(null),[f,g]=(0,Q.useState)(o);(0,Q.useEffect)(()=>{!n.isPending&&!r.isPending&&g(o)},[o,n.isPending,r.isPending]);let _=async t=>{g(t);try{let i=t?await n.mutateAsync(e):await r.mutateAsync(e);if(i.blocker!==null&&i.message!==null){u(i.message),h.error(i.message),g(!t);return}u(null),h.success(t?`${Ht[e]} started`:`${Ht[e]} stopped`)}catch{h.error(`Could not ${t?`start`:`stop`} ${Ht[e]}`),g(!t)}},v=async()=>{if(c!==null){if(await a(c)){h.success(`Remote URL copied`,c);return}h.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)(Wt,{tool:e}),(0,$.jsx)(`h3`,{className:`text-caption font-semibold`,children:Ht[e]})]}),(0,$.jsx)(G,{checked:f,disabled:s,onChange:e=>void _(e),"aria-label":`Toggle ${Ht[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)(p,{size:14,className:`animate-spin`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`animate-pulse`,children:`Waiting for address…`})]}),(0,$.jsx)(m,{variant:`secondary`,size:`sm`,onClick:()=>void _(!1),children:`Cancel`})]}):c===null?l===null?(0,$.jsx)(`p`,{className:`mt-2 text-badge leading-normal text-text-tertiary`,children:Ut[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)(m,{variant:`secondary`,size:`sm`,onClick:()=>void v(),children:[i?(0,$.jsx)(ee,{size:14}):(0,$.jsx)(d,{size:14}),i?`Copied`:`Copy`]})]})]})}function Kt(){let{copied:e,copy:t}=U(2e3),n=`${window.location.origin}/v1`,r=async()=>{if(await t(n)){h.success(`Gateway endpoint copied`,n);return}h.error(`Clipboard unavailable on this origin`)};return(0,$.jsxs)(he,{children:[(0,$.jsx)(H,{title:`Gateway Endpoint`,subtitle:`Universal OpenAI & Anthropic Wire API Endpoint Compatible`,icon:(0,$.jsx)(g,{size:16})}),(0,$.jsx)(me,{children:(0,$.jsxs)(J,{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)(m,{variant:`secondary`,size:`sm`,icon:e?(0,$.jsx)(ee,{size:13}):(0,$.jsx)(d,{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 coding agent — OpenCode, Pi, OMP, Kilo, Cline, Droid, and more — at this same-origin base URL.`,(0,$.jsxs)(`span`,{className:`mt-1 block text-text-tertiary`,children:[`For Claude Code, leave off `,(0,$.jsx)(`code`,{className:`font-mono`,children:`/v1`}),` — its CLI appends it automatically.`]})]})]})})]})}function qt(){let e=zt();return(0,$.jsxs)(he,{children:[(0,$.jsx)(H,{title:`Remote Support`,subtitle:`Reach this gateway from outside the local network`,icon:(0,$.jsx)(Ge,{size:16})}),(0,$.jsx)(me,{children:(0,$.jsxs)(J,{gap:`10px`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 max-medium:grid-cols-1`,children:[(0,$.jsx)(Gt,{tool:`cloudflared`}),(0,$.jsx)(Gt,{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:[`No matter which tunnel you pick, the gateway sees the tunnel's address as the client. Add the forwarding edge to`,` `,(0,$.jsx)(`code`,{className:`font-mono`,children:`TRUSTED_PROXY_CIDRS`}),` so remote callers aren't recorded as loopback.`]}),(0,$.jsx)(`p`,{className:`text-badge leading-normal text-text-tertiary`,children:`Cartethyia doesn't install cloudflared or Tailscale for you — set up either one yourself. Tunnels run detached from the gateway, so they keep working across restarts.`})]})})]})}function Jt(){return(0,$.jsxs)(J,{gap:`16px`,children:[(0,$.jsx)(Kt,{}),(0,$.jsx)(qt,{}),(0,$.jsx)(Rt,{}),(0,$.jsx)(y,{}),(0,$.jsx)(Pt,{})]})}export{Jt 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{n as a,t as o}from"./arrow-up-59ms1iiT.js";import{n as s,t as c}from"./minimize-2-BTmMTK4o.js";import{n as l,t as u}from"./fingerprint-pattern-BWuHtbW4.js";import{D as d,E as f,S as p,c as m,g as h,k as ee,w as g,y as _}from"./numbers-CoqpaDMx.js";import{t as v}from"./chevron-right-BXIy5l3h.js";import{n as y,o as b}from"./InjectSystemPromptPanel-C-e2AMz6.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 w}from"./gauge-BbIMy7MB.js";import{n as T,r as E,t as D}from"./state-DHmEnLa2.js";import{t as O}from"./key-round-UkavsGxp.js";import{n as te,r as ne,t as k}from"./clipboard-button-DfS1ntiq.js";import{n as A,t as j}from"./dialog-BK-NRr5u.js";import{t as M}from"./pencil-768ysRAr.js";import{t as re}from"./plus-DIdX_g-x.js";import{t as N}from"./power-off-Yjw9GMJh.js";import{t as ie}from"./refresh-cw-BqJFk4sU.js";import{t as P}from"./route-CNSNj9Zm.js";import{t as F}from"./search-JOKus9rb.js";import{t as I}from"./shield-check-DVS0Foqh.js";import{t as ae}from"./shield-BMQNxORh.js";import{t as oe}from"./trash-Cppn5c3R.js";import{C as L,T as se,b as ce,x as le}from"./assert-CidQVoNo.js";import{l as R,o as z,t as ue}from"./query-keys-YSoQOUh6.js";import{t as B}from"./useMutation-CbCP4w1o.js";import{B as de,ct as fe,ft as pe,ot as V}from"./entry-vqGb8yVz.js";import{n as me,r as H,t as he}from"./card-CxDw0lK6.js";import{t as U}from"./use-clipboard-B0Sy03fE.js";import{n as ge}from"./download-dRFo5_Wu.js";import{c as W,d as _e}from"./tokens-COzario9.js";import{t as G}from"./switch-DmZcyTIC.js";import{t as K}from"./badge-BaX2GTrn.js";import{n as q,t as ve}from"./input-BlmlizVV.js";import{t as ye}from"./select-C9Ssle9b.js";import{t as be}from"./ModelPicker-C6WlpU5E.js";import{t as J}from"./stack-j7cXjgYX.js";import{n as Y}from"./inline-CHJQwxLa.js";import{a as xe,c as Se,d as Ce,f as we,g as Te,h as Ee,i as De,l as Oe,m as ke,o as Ae,p as X,r as je,s as Z,t as Me,u as Ne}from"./api-keys-KvX83mRe.js";import{a as Pe,i as Fe,o as Ie,r as Le}from"./cli-tools-Bwv5-zGZ.js";import{t as Re}from"./layout-Bz93I-yE.js";import{c as ze}from"./quota-DJ1QlAOq.js";import{n as Be,t as Ve}from"./settings-BxslsErn.js";import{t as He}from"./banner-DFH4Bkte.js";var Ue=e(`chevrons-up-down`,[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]),We=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`}]]),Ge=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`}]]),Ke=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`}]]),qe=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`}]]),Je=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`}]]),Ye=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`}]]),Xe=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`}]]),Ze=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`}]]),$e=e(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]),et=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`}]]),tt=[`routing:invoke`,`routing:cli_mapping`,`search:invoke`,`dashboard:read`,`dashboard:write`,`providers:read`,`providers:write`,`models:read`,`models:write`],nt=[`image/png`,`image/jpeg`,`image/webp`,`image/gif`],Q=t(n(),1),$=r(),rt={"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.`},it={"routing:invoke":P,"routing:cli_mapping":P,"search:invoke":F,"dashboard:read":C,"dashboard:write":M,"providers:read":V,"providers:write":We,"models:read":l,"models:write":x},at={k:1e3,m:1e6,b:1e9,t:0xe8d4a51000},ot=[{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 st(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]?at[n[2]]??1:1;return Math.round(r*i)}function ct(e){if(e==null)return``;let t=ot.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 lt(e){let t=Number(e.trim());return Number.isFinite(t)&&t>0?Math.round(t):void 0}function ut(e){let t=lt(e);return e.trim()===``?null:t}function dt({label:e,value:t,onChange:n,disabled:r}){let i=st(t),a=ot.find(e=>e.amount===i)?.label;return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(q,{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:ot.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 ft({tool:e,keyId:t,busy:n,scopeGranted:r,onScopeChange:i}){let a=Pe(e.id,t),o=Fe(),s=Le(),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)(P,{size:16,className:`mt-1 shrink-0 text-accent`,"aria-hidden":`true`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-caption font-semibold text-text-primary`,children:e.name}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:l?`Remote routing on — ${u} route${u===1?``:`s`} active, routing:cli_mapping granted.`:`Remote routing off — this key's requests go straight to the provider.`})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,$.jsx)(G,{checked:l,disabled:n||d||a.isLoading,"aria-label":`Enable remote routing for ${e.name}`,onChange:n=>{n!==r&&i(n),o.mutate({toolId:e.id,keyId:t,input:{enabled:n,mappings:a.data?.mappings??[]}},{onSuccess:()=>h.success(`Saved remote routing for ${e.name}.`),onError:e=>h.error(R(e,`Could not save remote routing.`))})}}),(0,$.jsx)(m,{variant:`secondary`,size:`sm`,disabled:n||d||!c&&u===0,onClick:()=>s.mutate({toolId:e.id,keyId:t},{onSuccess:()=>h.success(`Cleared remote routes for ${e.name}.`),onError:e=>h.error(R(e,`Could not reset remote routes.`))}),children:s.isPending?`Resetting…`:`Reset`})]})]})}function pt({keyId:e,busy:t,scopeGranted:n,onScopeChange:r,persistScope:i}){let a=(Ie().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)(P,{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)(ft,{tool:a,keyId:e,busy:t,scopeGranted:n,onScopeChange:e=>{r(e),i(e)}},a.id))})]})}function mt(e,t,n){let r=e===`personal`?t.trim():``;return{keyMode:e,keyPrefix:n.trim()||void 0,...r?{key:r}:{}}}function ht(e,t){return e===`personal`?t??null:null}function gt(e){let t=e?.scopes;return e?.isDefault?t&&t.length>0?[...t]:[...tt]:t&&t.length>0?[...t]:[`routing:invoke`,`search:invoke`]}function _t({mode:e,record:t,busy:n,onDone:r,onClose:i,actionsRef:a}){let[o,c]=(0,Q.useState)(t?.label??``),[d,f]=(0,Q.useState)(t?.keyPrefix??``),[p,ee]=(0,Q.useState)(``),[g,_]=(0,Q.useState)(t?.requestsPerMinute?.toString()??``),[v,y]=(0,Q.useState)(ct(t?.dailyTokenLimit??null)),[b,x]=(0,Q.useState)(ct(t?.monthlyTokenLimit??null)),[S,C]=(0,Q.useState)(ct(t?.lifetimeTokenBudget??null)),[T,E]=(0,Q.useState)(t?.lifetimeTokenBudget==null?`recurring`:`one-time`),[D,ne]=(0,Q.useState)(t?.maxConcurrentRequests?.toString()??``),[k,j]=(0,Q.useState)(t?.concurrencyScope??`family`),[M,re]=(0,Q.useState)(t?.maxChildren?.toString()??``),[N,ie]=(0,Q.useState)(()=>gt(t)),[F,oe]=(0,Q.useState)(t?.modelAccessMode??`whitelist`),[L,se]=(0,Q.useState)(()=>{let e=t?.modelList;return e?[...e]:[]}),[z,ue]=(0,Q.useState)(!1),[B,de]=(0,Q.useState)(()=>{let e=t?.clientRouterDenylist;return e?[...new Set(e.map(le).filter(e=>e!==void 0))]:[]}),[V,me]=(0,Q.useState)(()=>t?.notesTitle??``),[H,he]=(0,Q.useState)(()=>t?.notesSubtitle??``),[U,ge]=(0,Q.useState)(()=>t?.notesBody??``),[W,_e]=(0,Q.useState)(t?.sharePopupEnabled??!0),[K,J]=(0,Q.useState)(null),[Y,xe]=(0,Q.useState)(!1),[Se,Ce]=(0,Q.useState)(null),we=t?.sharePopupImageMime!==void 0,Ee=K??(we&&!Y&&t!==null?`/console/api/api-keys/${t.id}/share-popup-image`:null);(0,Q.useEffect)(()=>{we||K!==null||Y||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=>J(e)).catch(()=>{})},[]);let[De,Oe]=(0,Q.useState)(t?.sharePopupTitle??`Support via QRIS`),[ke,Ae]=(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! 🙏`),[X,je]=(0,Q.useState)(t?.keyMode??`personal`),Z=T===`one-time`,Me=e===`edit`,Ne=(0,Q.useMemo)(()=>{if(e===`create`)return o.trim().length>0||p.trim().length>0||d.trim().length>0||g.trim().length>0||v.trim().length>0||b.trim().length>0||S.trim().length>0||D.trim().length>0||M.trim().length>0||V.trim().length>0||H.trim().length>0||U.trim().length>0||N.length>0||L.length>0||B.length>0||K!==null||Y;let n=t;return n===null?!1:o.trim()!==(n.label??``)||g.trim()!==(n.requestsPerMinute?.toString()??``)||v.trim()!==ct(n?.dailyTokenLimit??null)||b.trim()!==ct(n?.monthlyTokenLimit??null)||S.trim()!==ct(n?.lifetimeTokenBudget??null)||T!==(n?.lifetimeTokenBudget==null?`recurring`:`one-time`)||D.trim()!==(n.maxConcurrentRequests?.toString()??``)||k!==(n.concurrencyScope??`family`)||M.trim()!==(n?.maxChildren?.toString()??``)||V.trim()!==(n?.notesTitle??``)||H.trim()!==(n?.notesSubtitle??``)||U.trim()!==(n?.notesBody??``)||N.join(`,`)!==gt(n).join(`,`)||F!==(n?.modelAccessMode??`whitelist`)||L.join(`,`)!==(n.modelList??[]).join(`,`)||B.join(`,`)!==(n?.clientRouterDenylist??[]).join(`,`)||W!==(n.sharePopupEnabled??!0)||K!==null||Y||De.trim()!==(n.sharePopupTitle??`Support via QRIS`)||ke.trim()!==(n.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! 🙏`)},[e,t,o,p,d,g,v,b,S,T,D,k,M,N,F,L,B,V,H,U,W,K,Y,De,ke]);A(Ne);let Pe=Te(),Fe=e=>ie(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),Ie=()=>{r({label:o.trim(),...mt(X,p,d),scopes:N,modelAccessMode:F,modelList:L,clientRouterDenylist:B,requestsPerMinute:ut(g),maxConcurrentRequests:ut(D),concurrencyScope:X===`share`?k:void 0,maxChildren:X===`share`?ut(M):null,dailyTokenLimit:Z?null:st(v)??null,monthlyTokenLimit:Z?null:st(b)??null,lifetimeTokenBudget:Z?st(S)??null:null,notesTitle:V.trim(),notesSubtitle:H.trim(),notesBody:U.trim(),sharePopupEnabled:W,...K===null?Y?{sharePopupImage:null}:{}:{sharePopupImage:K},sharePopupTitle:De.trim(),sharePopupBody:ke.trim()})};return(0,Q.useEffect)(()=>{a?.((0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(m,{variant:`secondary`,size:`sm`,onClick:i,disabled:n,children:`Cancel`}),(0,$.jsx)(m,{variant:`primary`,size:`sm`,disabled:n||e===`create`&&!o.trim(),onClick:Ie,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)(O,{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":X===e,disabled:n||Me,onClick:()=>je(e),title:Me?`Credential mode cannot change after creation`:void 0,className:`rounded-inset py-1.5 px-5`,style:{border:`1px solid var(--inner-border)`,color:X===e?`var(--accent)`:`var(--text-secondary)`,background:X===e?`var(--accent-soft)`:`var(--surface-2)`,cursor:Me?`not-allowed`:`pointer`,opacity:Me&&X!==e?.5:1},children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[e===`personal`?(0,$.jsx)($e,{size:14,"aria-hidden":`true`}):(0,$.jsx)(et,{size:14,"aria-hidden":`true`}),e===`personal`?`Personal`:`Share template`]})},e))}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:X===`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)(u,{size:16,className:`text-accent`,"aria-hidden":`true`}),`Identity`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Give this credential a recognizable name.`})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 items-start min-w-0 max-medium:grid-cols-1`,children:[(0,$.jsx)(q,{label:`Name`,value:o,onChange:e=>c(e.target.value),placeholder:`ci-key…`,disabled:n,autoFocus:!0}),(0,$.jsx)(q,{label:`Key prefix`,value:d,onChange:e=>f(e.target.value),placeholder:`pn-carte- (default)…`,disabled:n||p.trim().length>0})]}),X===`personal`&&(0,$.jsx)(q,{label:`Custom API key value (optional)`,value:p,onChange:e=>ee(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)(u,{size:16,className:`mr-2 inline text-accent`,"aria-hidden":`true`}),`Identity`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:t?.isDefault?`The default key's name is fixed. Limits, access, and everything else can still change.`:`Update the label for this credential.`})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-2 gap-4 items-start min-w-0 max-medium:grid-cols-1`,children:(0,$.jsx)(q,{label:`Name`,value:o,onChange:e=>c(e.target.value),placeholder:`ci-key…`,disabled:n||t?.isDefault===!0,title:t?.isDefault?`The default gateway key keeps its name`:void 0,autoFocus:!0})})]}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-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)(te,{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)(q,{label:`Title`,value:V,onChange:e=>me(e.target.value),placeholder:`e.g. Bansos Token`,disabled:n}),(0,$.jsx)(q,{label:`Subtitle`,value:H,onChange:e=>he(e.target.value),placeholder:`e.g. Come and save your tokens`,disabled:n}),(0,$.jsx)(`div`,{className:`col-span-full`,children:(0,$.jsx)(q,{label:`Body`,value:U,onChange:e=>ge(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)(w,{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)(q,{label:`Requests per minute`,type:`number`,min:`0`,value:g,onChange:e=>_(e.target.value),placeholder:`Unlimited…`,disabled:n}),(0,$.jsx)(q,{label:`Max concurrent requests`,type:`number`,min:`0`,value:D,onChange:e=>ne(e.target.value),placeholder:`Unlimited…`,disabled:n}),X===`share`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`api-key-concurrency-scope`,className:`form-label text-caption font-semibold text-text-primary`,children:`Concurrency scope`}),(0,$.jsx)(ye,{id:`api-key-concurrency-scope`,"aria-label":`Concurrency scope`,value:k,onValueChange:e=>j(e),options:[{value:`family`,label:`Whole share family (all recipients together)`},{value:`per_key`,label:`Per recipient key (each has its own cap)`}],size:`md`})]}):null,X===`share`?(0,$.jsx)(q,{label:`Recipient slots (max children)`,type:`number`,min:`0`,value:M,onChange:e=>re(e.target.value),placeholder:`Unlimited…`,disabled:n}):null]}),(0,$.jsx)(`p`,{className:`text-micro leading-normal text-text-tertiary`,children:D===``?`No concurrency limit, so the tenant allowance does nothing.`:X===`share`?k===`family`?`Limit ${D} concurrent across the whole share family — all recipients share this one cap.`:`Limit ${D} concurrent per recipient key — each key gets its own independent cap.`:`Limit ${D} concurrent for this key. 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)(w,{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:Z?`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:()=>E(`recurring`),disabled:n,className:`py-1.5 px-4 rounded-chip font-semibold border-0 cursor-pointer`,style:{fontSize:`10px`,background:Z?`transparent`:`var(--accent-soft)`,color:Z?`var(--text-tertiary)`:`var(--accent)`},children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(Ke,{size:13,"aria-hidden":`true`}),`Recurring`]})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>E(`one-time`),disabled:n,className:`py-1.5 px-4 rounded-chip font-semibold border-0 cursor-pointer`,style:{fontSize:`10px`,background:Z?`var(--accent-soft)`:`transparent`,color:Z?`var(--accent)`:`var(--text-tertiary)`},children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(We,{size:13,"aria-hidden":`true`}),`One-time`]})})]})]}),Z?(0,$.jsx)(dt,{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)(dt,{label:`Daily token limit`,value:v,onChange:y,disabled:n}),(0,$.jsx)(dt,{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)(Ye,{size:16,className:`mr-2 inline text-accent`,"aria-hidden":`true`}),`Share page popup`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Optional card visitors open from the Base URL card on your share page.`})]}),(0,$.jsx)(G,{checked:W,onChange:e=>_e(e),disabled:n,label:`Enable popup`})]}),W?(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:[Ee?(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:Ee,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)(ve,{id:`share-popup-image`,accept:nt.join(`,`),"aria-label":`Popup image`,disabled:n,onChange:e=>{let t=e.target.files?.[0];if(e.target.value=``,!t)return;if(Ce(null),t.size>2097152){J(null),Ce(`Image must be 2 MB or smaller.`);return}let n=new FileReader;n.onload=()=>{J(String(n.result)),xe(!1)},n.onerror=()=>Ce(`Could not read that file.`),n.readAsDataURL(t)}}),Ee?(0,$.jsx)(m,{variant:`secondary`,size:`sm`,type:`button`,disabled:n,className:`h-14 px-5 text-badge self-start`,onClick:()=>{J(null),xe(!0),Ce(null)},children:`Remove image`}):null,Se?(0,$.jsx)(`p`,{className:`form-error`,children:Se}):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)(q,{label:`Popup title`,value:De,onChange:e=>Oe(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:ke,onChange:e=>Ae(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)(ae,{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:[N.length,`/`,tt.length,` grants`,(0,$.jsx)(pe,{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)(I,{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)(l,{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":F===e,disabled:n,onClick:()=>oe(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 ${F===e?`var(--accent)`:`var(--inner-border)`}`,background:F===e?`var(--accent-soft)`:`var(--surface-2)`,color:F===e?`var(--accent)`:`var(--text-secondary)`,cursor:n?`not-allowed`:`pointer`,opacity:n?.6:1},children:[e===`whitelist`?`Whitelist`:`Blacklist`,e===`whitelist`?(0,$.jsx)(I,{size:13,className:`ml-1.5 inline`,"aria-hidden":`true`}):(0,$.jsx)(Ze,{size:13,className:`ml-1.5 inline`,"aria-hidden":`true`})]},e))}),(0,$.jsx)(`p`,{className:`text-badge text-text-tertiary m-0`,children:F===`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:L.length===0?(0,$.jsx)(`span`,{className:`text-badge text-text-tertiary`,children:F===`whitelist`?`All models allowed`:`No models blocked`}):L.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:()=>se(t=>t.filter(t=>t!==e)),disabled:n,className:`bg-transparent border-0 cursor-pointer p-0 flex`,children:`×`})]},e))}),(0,$.jsx)(m,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>ue(!0),disabled:n,children:`Browse models`}),(0,$.jsx)(be,{open:z,onClose:()=>ue(!1),selected:L,onToggle:e=>se(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),title:F===`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)(P,{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`}),tt.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:N.includes(e)?`var(--accent-soft)`:`var(--surface-2)`},children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(P,{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:rt[e]})]})]}),(0,$.jsx)(G,{checked:N.includes(e),onChange:()=>Fe(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:ce.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:B.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)(s,{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)(G,{checked:B.includes(e.id),onChange:t=>de(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)(pt,{keyId:e===`edit`&&t?t.id:``,busy:n,scopeGranted:N.includes(`routing:cli_mapping`),onScopeChange:e=>{e!==N.includes(`routing:cli_mapping`)&&Fe(`routing:cli_mapping`)},persistScope:n=>{if(e!==`edit`||!t)return;let r=n?[...new Set([...N,`routing:cli_mapping`])]:N.filter(e=>e!==`routing:cli_mapping`);Pe.mutate({keyId:t.id,request:{scopes:r}},{onError:e=>h.error(R(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)(fe,{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:tt.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:N.includes(e)?`var(--accent-soft)`:`var(--surface-2)`},children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3 min-w-0`,children:[(()=>{let t=it[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:rt[e]})]})]}),(0,$.jsx)(G,{checked:N.includes(e),onChange:()=>Fe(e),disabled:n,"aria-label":`Grant ${e}`})]},e))})]})]})]})]})]})]})}function vt({secret:e,onClose:t}){return(0,$.jsx)(j,{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)(k,{value:e??``,size:`sm`,variant:`primary`,label:`Copy key`,copiedLabel:`Copied`}),(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(f,{size:13}),onClick:()=>{e!==null&&(ge(`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`),h.success(`Key saved to your downloads.`))},children:`Save this key`})]})]})})}var yt=e=>(e??0).toLocaleString(),bt=e=>e?new Date(e).toLocaleString():`—`;function xt({keyId:e}){let t=Z(),[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)(m,{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=>h.error(R(e,`Could not reveal the key.`))})},children:i?`Hide`:`Reveal`}),i&&n?(0,$.jsx)(k,{value:n,size:`sm`,variant:`secondary`,label:`Copy`,copiedLabel:`Copied`}):null]})}function St({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`:yt(t)})]})}function Ct(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 wt({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?`${W(e)} · Unlimited`:`${W(e)} / ${W(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?`${W(e)} tokens consumed, no lifetime budget set`:`${W(e)} of ${W(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 Tt=25,Et=25,Dt=500;function Ot({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:W(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=ze(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:[W(e),` / `,W(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`:`${W(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":`${W(e)} of ${W(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 kt({parentId:e,childId:t}){let n=X(e,t);if(n.isPending)return(0,$.jsx)(E,{label:`Loading activity…`,compact:!0});if(n.isError)return(0,$.jsx)(T,{compact:!0,message:R(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:yt(e.todayRequests)}),(0,$.jsx)(`td`,{children:yt(e.todayErrors)}),(0,$.jsx)(`td`,{children:W(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:W(e.totalTokens)}),(0,$.jsx)(`td`,{children:bt(e.startedAt)})]},e.requestId))})]})}):(0,$.jsx)(`p`,{className:`py-3 text-caption text-text-tertiary`,children:`No recent requests.`})]})]}):null}function At({parent:e,onSecretRevealed:t}){let[n,r]=(0,Q.useState)(null),[i,c]=(0,Q.useState)(`active`),[l,u]=(0,Q.useState)(Tt),[d,f]=(0,Q.useState)(`createdAt`),[p,ee]=(0,Q.useState)(`desc`),[g,_]=(0,Q.useState)(null),y=Ce(),b=xe(),x=Oe(),S=Ne(),C=we(e.id),w=e.keyMode!==`share`,O=ke(w?null:e.id,{limit:l,offset:0,sortBy:d,order:p,status:i}),te=O.data,A=te?.rows??[],j=te?.active??0,M=A,re=()=>{r(null),u(Tt)},N=e=>{d===e?ee(e=>e===`asc`?`desc`:`asc`):(f(e),ee(`asc`)),re()},P=e=>{let t=e.currentTarget;t.scrollHeight-t.scrollTop-t.clientHeight<40&&!O.isFetching&&A.length>=l&&l<Dt&&u(e=>Math.min(e+Et,Dt))},F=({column:e,children:t})=>{let n=d===e;return(0,$.jsx)(`th`,{scope:`col`,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>N(e),className:`inline-flex cursor-pointer items-center gap-1 border-0 bg-transparent p-0 font-inherit text-inherit hover:text-text-primary`,"aria-label":`Sort by ${String(e)}`,children:[t,n?p===`asc`?(0,$.jsx)(o,{size:12,"aria-hidden":`true`}):(0,$.jsx)(a,{size:12,"aria-hidden":`true`}):(0,$.jsx)(Ue,{size:12,"aria-hidden":`true`,className:`text-text-tertiary`})]})})};(0,Q.useEffect)(()=>{r(null)},[e.id]);let I=async t=>{try{let n=await S.mutateAsync({parentKeyId:e.id,scope:t});u(Tt),h.success(`Revoked ${n.deleted.toLocaleString()} recipient${n.deleted===1?``:`s`}.`)}catch(e){h.error(R(e,`Could not revoke recipients.`))}},ae=y.isPending||b.isPending,[oe,L]=(0,Q.useState)(!1),se=async()=>{if(w){let n=await b.mutateAsync({keyId:e.id});t?.(n.secret);return}await y.mutateAsync({keyId:e.id,regenerate:!0}),h.success(`Link regenerated; the previous URL no longer works.`)},ce=()=>{y.mutate({keyId:e.id},{onError:e=>h.error(R(e,`Could not create link.`))})},le=C.data?.url??null,z=Ct(w);return(0,$.jsxs)(`div`,{className:`grid min-w-0 gap-6`,children:[(0,$.jsx)(`section`,{"aria-label":`Link`,children:C.isPending?(0,$.jsx)(E,{label:`Loading link…`,compact:!0}):C.isError?(0,$.jsx)(T,{compact:!0,message:R(C.error,`Could not load the link.`),onRetry:()=>void C.refetch()}):le?(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)(ne,{size:14,"aria-hidden":`true`,className:`shrink-0`}),(0,$.jsx)(`code`,{title:le,className:`min-w-0 flex-auto overflow-hidden font-mono text-caption text-text-primary text-ellipsis whitespace-nowrap`,children:le}),(0,$.jsx)(k,{value:le,size:`sm`,variant:`secondary`,label:`Copy`,copiedLabel:`Copied`}),(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(qe,{size:13}),loading:ae,disabled:ae,onClick:()=>L(!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)(ne,{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)(m,{variant:`primary`,size:`sm`,loading:ae,disabled:ae,onClick:ce,children:`Create link`})]})}),w?(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)(xt,{keyId:e.id})]}):null,w?(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:W(e.tokensConsumed)})]}),(0,$.jsx)(St,{label:`Requests / min`,value:e.requestsPerMinute}),(0,$.jsx)(St,{label:`Daily tokens`,value:e.dailyTokenLimit}),(0,$.jsx)(St,{label:`Monthly tokens`,value:e.monthlyTokenLimit}),(0,$.jsx)(wt,{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)(Ot,{consumed:te?.consumed??0,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: `,j.toLocaleString()]}),(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:()=>{re(),c(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))}),g===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:g===`all`?`Revoke all active recipients?`:`Revoke all active recipients that never spent a token?`}),(0,$.jsx)(m,{variant:`danger`,size:`sm`,loading:S.isPending,onClick:()=>{let e=g===`all`?`active`:`unused`;_(null),I(e)},children:`Confirm`}),(0,$.jsx)(m,{variant:`ghost`,size:`sm`,onClick:()=>_(null),children:`Cancel`})]}),(0,$.jsx)(m,{variant:`ghost`,size:`sm`,disabled:j===0||S.isPending,title:j===0?`No active recipients`:`Revoke every active recipient (${j.toLocaleString()})`,onClick:()=>_(`unused`),icon:(0,$.jsx)(s,{size:13}),children:`Revoke no-usage`}),(0,$.jsx)(m,{variant:`ghost`,size:`sm`,disabled:j===0||S.isPending,title:j===0?`No active recipients`:`Revoke all active recipients (${j.toLocaleString()})`,onClick:()=>_(`all`),icon:(0,$.jsx)(s,{size:13}),children:`Revoke all`}),(0,$.jsx)(m,{variant:`ghost`,size:`sm`,onClick:()=>void O.refetch(),icon:(0,$.jsx)(ie,{size:13,className:O.isFetching?`animate-spin`:void 0}),children:`Refresh`})]}),O.isPending&&!O.data?(0,$.jsx)(E,{label:`Loading recipients…`,compact:!0}):O.isError?(0,$.jsx)(T,{compact:!0,message:R(O.error,`Could not load recipients.`),onRetry:()=>void O.refetch()}):M.length===0?(0,$.jsx)(D,{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,$.jsxs)(`div`,{className:`data-table-container max-h-[46vh]`,onScroll:P,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)(F,{column:`label`,children:`Key`}),(0,$.jsx)(F,{column:`revokedAt`,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)(F,{column:`createdAt`,children:`Created`}),(0,$.jsx)(`th`,{scope:`col`,className:`text-right whitespace-nowrap`,children:`Actions`})]})}),(0,$.jsx)(`tbody`,{children:M.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)(pe,{size:14}):(0,$.jsx)(v,{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:W(t.today.totalTokens)}),(0,$.jsx)(`td`,{children:W(t.allTime.totalTokens)}),(0,$.jsx)(`td`,{children:bt(t.lastUsedAt)}),(0,$.jsx)(`td`,{children:bt(t.createdAt)}),(0,$.jsx)(`td`,{className:`text-right whitespace-nowrap`,children:(0,$.jsx)(m,{variant:`danger`,size:`sm`,disabled:x.isPending||!!t.revokedAt,onClick:()=>x.mutate({parentKeyId:e.id,childKeyId:t.id},{onError:e=>h.error(R(e,`Could not revoke key.`))}),children:`Revoke`})})]}),i?(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:8,className:`p-0`,children:(0,$.jsx)(kt,{parentId:e.id,childId:t.id})})}):null]},t.id)})})]}),O.isFetching&&A.length>0?(0,$.jsx)(`div`,{className:`border-t border-inner-border py-2 text-center text-badge text-text-tertiary`,children:`Loading more…`}):null,A.length>0&&A.length>=l&&l<Dt?(0,$.jsx)(`div`,{className:`py-2 text-center text-badge text-text-tertiary`,children:`Scroll for more`}):null]})]})]}),(0,$.jsx)(de,{open:oe,onClose:()=>L(!1),onConfirm:se,title:z.title,message:z.message,confirmLabel:z.confirmLabel,danger:!0})]})}function jt({parent:e,onClose:t,onSecretRevealed:n}){let r=e.keyMode!==`share`;return(0,$.jsx)(j,{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)(At,{parent:e,onSecretRevealed:n})})}function Mt(e){if(!e.bannedUntil)return`Permanent — lift manually`;let t=new Date(e.bannedUntil).getTime();if(!Number.isFinite(t))return`—`;let n=t-Date.now(),r=new Date(e.bannedUntil).toLocaleString();if(n<=0)return`${r} (lapsed)`;let i=Math.ceil(n/6e4);if(i<60)return`${r} (in ${i}m)`;let a=Math.floor(i/60);return a<24?`${r} (in ${a}h)`:`${r} (in ${Math.floor(a/24)}d)`}function Nt({onClose:e}){let t=je(),n=Ee(),[r,i]=(0,Q.useState)(null),a=Date.now(),o=(t.data??[]).filter(e=>e.bannedAt?!e.bannedUntil||new Date(e.bannedUntil).getTime()>a:!1);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(j,{open:!0,onClose:e,title:`Banned Users`,description:`API keys that have been banned. A timed ban lapses on its own; lifting one early is the escape hatch for a mistake.`,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 (`,o.length,`)`]}),t.isPending&&!t.data?(0,$.jsx)(E,{label:`Loading active bans…`}):t.isError&&!t.data?(0,$.jsx)(T,{message:R(t.error,`Could not load active bans.`),onRetry:()=>void t.refetch()}):o.length===0?(0,$.jsx)(D,{compact:!0,title:`No banned keys`,message:`No API key is currently banned.`,icon:(0,$.jsx)(Xe,{size:20})}):(0,$.jsx)(`div`,{className:`rounded-inset border border-inner-border`,children:(0,$.jsx)(Re,{maxHeight:480,scrollRegion:!0,headers:[`API key`,`Reason`,`Lapses`,``],children:o.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`font-mono tabular-nums text-badge text-text-primary whitespace-nowrap`,children:e.label||e.id.slice(0,8)}),(0,$.jsx)(`td`,{className:`text-badge text-text-secondary`,children:e.banReason??`—`}),(0,$.jsx)(`td`,{className:`text-badge text-text-secondary whitespace-nowrap`,children:Mt(e)}),(0,$.jsx)(`td`,{className:`text-right whitespace-nowrap`,children:(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(Qe,{size:13}),disabled:n.isPending,onClick:()=>i(e),children:`Unban`})})]},e.id))})})]}),(0,$.jsx)(Y,{justify:`flex-end`,gap:`0px`,children:(0,$.jsx)(m,{variant:`secondary`,size:`sm`,onClick:e,children:`Close`})})]})}),(0,$.jsx)(de,{open:r!==null,onClose:()=>i(null),onConfirm:async()=>{if(r)try{await n.mutateAsync({keyId:r.id}),h.success(`Unbanned ${r.label||r.id.slice(0,8)}.`),i(null)}catch(e){h.error(R(e,`Could not unban key.`))}},title:`Lift this ban?`,message:`Lift the ban on ${r?.label||`this key`}? The caller can reach the gateway again immediately.`,confirmLabel:`Unban`,danger:!0})]})}function Pt(){let e=Me(),t=De(),n=Te(),r=Se(),i=Ee(),a=xe(),o=Z(),s=Ae(),{copy:c}=U(),l=Ve(),u=Be(),f=l.data?.invokeDisabled===!0,[p,ee]=(0,Q.useState)(!1),[g,v]=(0,Q.useState)(!1),[y,x]=(0,Q.useState)(null),[S,w]=(0,Q.useState)(null),[te,ne]=(0,Q.useState)(!1),[k,A]=(0,Q.useState)(null),[ie,P]=(0,Q.useState)(null),[F,I]=(0,Q.useState)(null),[ae,L]=(0,Q.useState)(null),[se,ce]=(0,Q.useState)(null),[le,z]=(0,Q.useState)(null),ue=e.data??[],B=e=>{I(null),L(e)},fe=async e=>{try{let{secret:t}=await o.mutateAsync({keyId:e.id});await c(t)?h.success(`API key copied`):h.error(`Clipboard unavailable on this origin`)}catch(e){h.error(R(e,`Could not reveal API key.`))}},pe=Ct(!0),V=e=>{u.mutate({invokeDisabled:!e},{onSuccess:()=>h.success(e?`Invoke enabled — routing has resumed.`:`Invoke disabled — every API key is now refused (503).`),onError:e=>h.error(e instanceof Error?e.message:`Could not save the setting`)})};return(0,$.jsxs)(he,{children:[(0,$.jsx)(H,{title:`API Credentials`,subtitle:`Manage tenant API keys, model access, budgets, and sharing.`,icon:(0,$.jsx)(O,{size:16}),action:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(m,{variant:f?`primary`:`secondary`,size:`sm`,loading:l.isLoading||u.isPending,onClick:()=>ee(!0),icon:(0,$.jsx)(N,{size:13}),children:f?`Enable Invoke`:`Disable Invoke`}),(0,$.jsx)(m,{variant:`secondary`,size:`sm`,onClick:()=>ne(!0),icon:(0,$.jsx)(Xe,{size:13}),children:`Banned Users`}),(0,$.jsx)(m,{variant:`primary`,size:`sm`,onClick:()=>{I(null),v(!0)},icon:(0,$.jsx)(re,{size:13}),children:`Create Key`})]})}),(0,$.jsx)(me,{children:e.isPending&&!e.data?(0,$.jsx)(E,{label:`Loading API keys…`}):e.isError&&!e.data?(0,$.jsx)(T,{message:R(e.error,`Could not load credentials.`),onRetry:()=>void e.refetch()}):ue.length===0?(0,$.jsx)(D,{title:`No API keys issued`,message:`Generate a secret key to authenticate your SDK or CLI client against the gateway.`,icon:(0,$.jsx)(O,{size:20})}):(0,$.jsx)(`div`,{className:`scroll-region max-h-280 pr-1`,children:(0,$.jsx)(b,{items:ue,label:`API credentials`,disabled:s.isPending,onReorder:e=>s.mutate(e,{onError:e=>h.error(R(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)(K,{tone:e.revokedAt||e.bannedAt?`err`:e.enabled?`ok`:`warn`,children:e.revokedAt?`revoked`:e.bannedAt?`banned`:e.enabled?`enabled`:`disabled`}),e.bannedAt&&!e.revokedAt?(0,$.jsx)(K,{tone:`err`,title:e.banReason??`Banned`,children:(0,$.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 cursor-pointer bg-transparent border-0 p-0 text-inherit`,onClick:()=>A(e),children:[(0,$.jsx)(C,{size:11,"aria-hidden":`true`}),`See reason`]})}):null,(0,$.jsx)(K,{tone:e.keyMode===`share`?`accent`:`default`,children:e.keyMode===`share`?`share template`:`personal`}),e.isDefault?(0,$.jsx)(K,{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`}),W(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`}),_e(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`}),_e(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`}),_e(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`}),_e(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`}),_e(e.maxConcurrentRequests),e.keyMode===`share`?(0,$.jsx)(`span`,{className:`font-semibold text-text-tertiary`,title:e.concurrencyScope===`per_key`?`Each recipient key has its own concurrency cap and counter.`:`All recipients share one concurrency cap and counter.`,children:e.concurrencyScope===`per_key`?`· per key`:`· family`}):null]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap max-medium:justify-between`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:e.modelAccessMode===`blacklist`?`Blocked`:`Models`}),e.modelAccessMode===`blacklist`?e.modelList?.length??0:e.modelList?.length?e.modelList.length:`All`]})]})]}),(0,$.jsxs)(`div`,{className:`flex gap-3 shrink-0 flex-wrap`,children:[e.revokedAt?null:(0,$.jsx)(G,{checked:e.enabled,disabled:n.isPending,id:`api-key-enabled-${e.id}`,label:``,"aria-label":`${e.enabled?`Disable`:`Enable`} ${e.label||`API credential`}`,onChange:t=>n.mutate({keyId:e.id,request:{enabled:t}},{onSuccess:()=>h.success(`${e.label||`API credential`} ${t?`enabled`:`disabled`}`),onError:e=>h.error(R(e,`Could not update credential state.`))})}),(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(M,{size:13}),onClick:()=>{I(null),x(e)},children:`Edit`}),!e.revokedAt&&e.keyMode!==`share`?(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(d,{size:13}),onClick:()=>void fe(e),disabled:o.isPending,children:`Copy`}):null,!e.revokedAt&&(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(Ye,{size:13}),onClick:()=>B(e),children:e.keyMode===`share`?`Recipients`:`Share`}),!e.revokedAt&&e.keyMode!==`share`&&(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(qe,{size:13}),onClick:()=>{I(null),P(e)},disabled:a.isPending,children:`Rotate`}),!e.revokedAt&&!e.isDefault&&(0,$.jsx)(m,{variant:`danger`,size:`sm`,icon:(0,$.jsx)(oe,{size:13}),onClick:()=>w(e),disabled:r.isPending,children:`Revoke`}),e.bannedAt&&!e.revokedAt?(0,$.jsx)(m,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(_,{size:13}),onClick:()=>{i.mutate({keyId:e.id},{onSuccess:()=>h.success(`Unbanned ${e.label||e.id}.`),onError:e=>h.error(R(e,`Could not unban key.`))})},disabled:i.isPending,children:`Unban`}):null]})]})})})}),(0,$.jsx)(j,{open:g,onClose:()=>v(!1),title:`Create API Key`,description:`Create a tenant-scoped credential. Choose model access, permissions, limits, and optional blocked client routers.`,size:`lg`,footer:se,children:(0,$.jsx)(_t,{mode:`create`,record:null,busy:t.isPending,onClose:()=>v(!1),actionsRef:ce,onDone:e=>{t.mutate(e,{onSuccess:t=>{v(!1),I(ht(e.keyMode,t.secret)),h.success(`API key created`)},onError:e=>h.error(R(e,`Could not create API key.`))})}})}),(0,$.jsx)(j,{open:y!==null,onClose:()=>x(null),title:`Edit API Key`,description:`Update the key's model access, permissions, limits, share notes, and optional public popup.`,size:`lg`,footer:le,children:(0,$.jsx)(_t,{mode:`edit`,record:y,busy:n.isPending,onClose:()=>x(null),actionsRef:z,onDone:e=>{y&&n.mutate({keyId:y.id,request:e},{onSuccess:t=>{x(null),I(ht(e.keyMode,t.secret)),h.success(`API key updated`)},onError:e=>h.error(R(e,`Could not update API key.`))})}})}),ae?(0,$.jsx)(jt,{parent:ae,onClose:()=>L(null),onSecretRevealed:e=>{L(null),I(e)}}):null,(0,$.jsx)(de,{open:ie!==null,onClose:()=>P(null),onConfirm:async()=>{if(!ie)return;let e=await a.mutateAsync({keyId:ie.id});I(e.secret),h.success(`Rotated ${ie.label||ie.id}.`),P(null)},title:pe.title,message:pe.message,confirmLabel:pe.confirmLabel,danger:!0}),(0,$.jsx)(de,{open:S!==null,onClose:()=>w(null),onConfirm:async()=>{S&&(await r.mutateAsync(S.id),h.success(`Revoked ${S.label||S.id}.`),w(null))},title:`Revoke API key?`,message:S?`Revoke ${S.label||S.id}? Clients using it will be rejected.${S.keyMode===`share`?` All child keys and enrollment links will also be revoked.`:``}`:`Revoke this API key?`,confirmLabel:`Revoke`,danger:!0}),(0,$.jsx)(de,{open:p,onClose:()=>ee(!1),onConfirm:async()=>{V(f)},title:f?`Enable Invoke?`:`Disable Invoke?`,message:f?`Allow this tenant's API keys to invoke /v1/* routes again. Traffic resumes immediately.`:`Disable invocation for every API key in this tenant? All /v1/* requests will be refused with 503, and nothing upstream is dialed. No keys, accounts, or models are deleted — the dashboard stays reachable so you can re-enable.`,confirmLabel:f?`Enable Invoke`:`Disable Invoke`,danger:!f}),(0,$.jsx)(vt,{secret:F,onClose:()=>I(null)}),te?(0,$.jsx)(Nt,{onClose:()=>ne(!1)}):null,(0,$.jsx)(j,{open:k!==null,onClose:()=>A(null),title:`Ban reason`,size:`sm`,footer:(0,$.jsx)(m,{variant:`secondary`,size:`sm`,onClick:()=>A(null),children:`Close`}),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`p`,{className:`text-caption text-text-secondary`,children:[k?.label||`API key`,` was banned.`]}),(0,$.jsx)(`div`,{className:`rounded-control border border-warning-line bg-surface-2 px-4 py-5 text-caption text-text-primary`,children:k?.banReason??`No reason recorded.`})]})})]})}var Ft=[{value:`lite`,label:`Lite`},{value:`full`,label:`Full`},{value:`ultra`,label:`Ultra`}],It={lite:`Lite`,full:`Full`,ultra:`Ultra`};function Lt({id:e,label:t,description:n,icon:r,enabled:i,strength:a,strengthSelectId:o,onToggle:s,onStrength:c}){return(0,$.jsx)(`div`,{className:`rounded-control border border-inner-border bg-surface-2 p-5`,children:(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[(0,$.jsx)(`label`,{htmlFor:e,children:(0,$.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold`,children:[r,t]})}),(0,$.jsx)(K,{tone:i?`ok`:`default`,dot:!0,children:i?`Active · ${It[a]??a}`:`Off`})]}),(0,$.jsx)(`p`,{className:`mt-2 text-badge leading-normal text-text-tertiary`,children:n})]}),(0,$.jsxs)(Y,{gap:`8px`,className:`shrink-0 items-center`,children:[(0,$.jsx)(ye,{id:o,"aria-label":`${t} strength`,value:a,onValueChange:c,options:Ft}),(0,$.jsx)(G,{id:e,"aria-label":`Enable ${t}`,checked:i,onChange:s})]})]})})}function Rt(){let e=Ve(),t=Be(),n=e.data;if(e.isPending)return(0,$.jsx)(E,{label:`Loading compression settings…`});if(e.isError||!n)return(0,$.jsx)(T,{message:R(e.error,`Failed to load compression settings`),onRetry:()=>void e.refetch()});let r=n.rtkPruneEnabled,a=n.ponyTailEnabled;return(0,$.jsxs)(he,{children:[(0,$.jsx)(H,{title:`Compression`,subtitle:`Shrink requests before they reach the provider`,icon:(0,$.jsx)(c,{size:16})}),(0,$.jsx)(me,{children:(0,$.jsxs)(J,{gap:`14px`,children:[r||a?(0,$.jsx)(He,{tone:`warning`,surface:`raised`,live:`status`,children:(0,$.jsxs)(`span`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(_,{size:14,className:`mt-0.5 shrink-0`,"aria-hidden":`true`}),(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,(0,$.jsx)(Lt,{id:`compression-rtk`,label:`Prune tool output (RTK)`,description:`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.`,icon:(0,$.jsx)(Je,{size:16,className:`shrink-0 text-text-secondary`}),enabled:r,strength:n.rtkPruneLevel,strengthSelectId:`compression-rtk-level`,onToggle:e=>t.mutate({rtkPruneEnabled:e},{onError:e=>h.error(R(e,`Could not update RTK prune.`))}),onStrength:e=>t.mutate({rtkPruneLevel:e===`lite`||e===`full`||e===`ultra`?e:`full`},{onError:e=>h.error(R(e,`Could not update RTK strength.`))})}),(0,$.jsx)(Lt,{id:`compression-ponytail`,label:`PonyTail (system directive)`,description:`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.`,icon:(0,$.jsx)(i,{size:16,className:`shrink-0 text-text-secondary`}),enabled:a,strength:n.ponyTailLevel,strengthSelectId:`compression-ponytail-level`,onToggle:e=>t.mutate({ponyTailEnabled:e},{onError:e=>h.error(R(e,`Could not update PonyTail.`))}),onStrength:e=>t.mutate({ponyTailLevel:e===`lite`||e===`full`||e===`ultra`?e:`full`},{onError:e=>h.error(R(e,`Could not update PonyTail strength.`))})})]})})]})}function zt(){return L({queryKey:ue.remoteSupport.status,queryFn:()=>z(`/remote-support/status`)})}function Bt(){let e=se();return B({mutationFn:e=>z(`/remote-support/start`,{method:`POST`,body:JSON.stringify({tool:e})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:ue.remoteSupport.status})}})}function Vt(){let e=se();return B({mutationFn:e=>z(`/remote-support/stop`,{method:`POST`,body:JSON.stringify(e===void 0?{}:{tool:e})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:ue.remoteSupport.status})}})}var Ht={cloudflared:`cloudflared`,tailscale:`Tailscale`},Ut={cloudflared:`Publish a temporary public URL without opening a port.`,tailscale:`Give a helper a private address on your own tailnet.`};function Wt({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 Gt({tool:e}){let t=zt(),n=Bt(),r=Vt(),{copied:i,copy:a}=U(2e3),o=t.data?.active===e,s=n.isPending||r.isPending,c=o?t.data?.url??null:null,[l,u]=(0,Q.useState)(null),[f,g]=(0,Q.useState)(o);(0,Q.useEffect)(()=>{!n.isPending&&!r.isPending&&g(o)},[o,n.isPending,r.isPending]);let _=async t=>{g(t);try{let i=t?await n.mutateAsync(e):await r.mutateAsync(e);if(i.blocker!==null&&i.message!==null){u(i.message),h.error(i.message),g(!t);return}u(null),h.success(t?`${Ht[e]} started`:`${Ht[e]} stopped`)}catch{h.error(`Could not ${t?`start`:`stop`} ${Ht[e]}`),g(!t)}},v=async()=>{if(c!==null){if(await a(c)){h.success(`Remote URL copied`,c);return}h.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)(Wt,{tool:e}),(0,$.jsx)(`h3`,{className:`text-caption font-semibold`,children:Ht[e]})]}),(0,$.jsx)(G,{checked:f,disabled:s,onChange:e=>void _(e),"aria-label":`Toggle ${Ht[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)(p,{size:14,className:`animate-spin`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`animate-pulse`,children:`Waiting for address…`})]}),(0,$.jsx)(m,{variant:`secondary`,size:`sm`,onClick:()=>void _(!1),children:`Cancel`})]}):c===null?l===null?(0,$.jsx)(`p`,{className:`mt-2 text-badge leading-normal text-text-tertiary`,children:Ut[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)(m,{variant:`secondary`,size:`sm`,onClick:()=>void v(),children:[i?(0,$.jsx)(ee,{size:14}):(0,$.jsx)(d,{size:14}),i?`Copied`:`Copy`]})]})]})}function Kt(){let{copied:e,copy:t}=U(2e3),n=`${window.location.origin}/v1`,r=async()=>{if(await t(n)){h.success(`Gateway endpoint copied`,n);return}h.error(`Clipboard unavailable on this origin`)};return(0,$.jsxs)(he,{children:[(0,$.jsx)(H,{title:`Gateway Endpoint`,subtitle:`Universal OpenAI & Anthropic Wire API Endpoint Compatible`,icon:(0,$.jsx)(g,{size:16})}),(0,$.jsx)(me,{children:(0,$.jsxs)(J,{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)(m,{variant:`secondary`,size:`sm`,icon:e?(0,$.jsx)(ee,{size:13}):(0,$.jsx)(d,{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 coding agent — OpenCode, Pi, OMP, Kilo, Cline, Droid, and more — at this same-origin base URL.`,(0,$.jsxs)(`span`,{className:`mt-1 block text-text-tertiary`,children:[`For Claude Code, leave off `,(0,$.jsx)(`code`,{className:`font-mono`,children:`/v1`}),` — its CLI appends it automatically.`]})]})]})})]})}function qt(){let e=zt();return(0,$.jsxs)(he,{children:[(0,$.jsx)(H,{title:`Remote Support`,subtitle:`Reach this gateway from outside the local network`,icon:(0,$.jsx)(Ge,{size:16})}),(0,$.jsx)(me,{children:(0,$.jsxs)(J,{gap:`10px`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 max-medium:grid-cols-1`,children:[(0,$.jsx)(Gt,{tool:`cloudflared`}),(0,$.jsx)(Gt,{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:[`No matter which tunnel you pick, the gateway sees the tunnel's address as the client. Add the forwarding edge to`,` `,(0,$.jsx)(`code`,{className:`font-mono`,children:`TRUSTED_PROXY_CIDRS`}),` so remote callers aren't recorded as loopback.`]}),(0,$.jsx)(`p`,{className:`text-badge leading-normal text-text-tertiary`,children:`Cartethyia doesn't install cloudflared or Tailscale for you — set up either one yourself. Tunnels run detached from the gateway, so they keep working across restarts.`})]})})]})}function Jt(){return(0,$.jsxs)(J,{gap:`16px`,children:[(0,$.jsx)(Kt,{}),(0,$.jsx)(qt,{}),(0,$.jsx)(Rt,{}),(0,$.jsx)(y,{}),(0,$.jsx)(Pt,{})]})}export{Jt as default};