cartethyia 2.4.5 → 2.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (303) hide show
  1. package/.env.example +4 -1
  2. package/README.md +18 -0
  3. package/dist/dashboard/assets/AccountCooldown-ChpdzxRH.js.gz +0 -0
  4. package/dist/dashboard/assets/{BannedPage-DUrXpp-X.js → BannedPage-QhvbJB9o.js} +1 -1
  5. package/dist/dashboard/assets/BannedPage-QhvbJB9o.js.gz +0 -0
  6. package/dist/dashboard/assets/{CliToolDetailPage-BzGevuql.js → CliToolDetailPage-Bcy150Jo.js} +1 -1
  7. package/dist/dashboard/assets/CliToolDetailPage-Bcy150Jo.js.gz +0 -0
  8. package/dist/dashboard/assets/{CliToolsPage-BaRM_7We.js → CliToolsPage-DyNXefph.js} +1 -1
  9. package/dist/dashboard/assets/CliToolsPage-DyNXefph.js.gz +0 -0
  10. package/dist/dashboard/assets/CombosPage-Cak0ljnO.js +1 -0
  11. package/dist/dashboard/assets/CombosPage-Cak0ljnO.js.gz +0 -0
  12. package/dist/dashboard/assets/ConsoleLogPage-CATpAEOz.js +1 -0
  13. package/dist/dashboard/assets/ConsoleLogPage-CATpAEOz.js.gz +0 -0
  14. package/dist/dashboard/assets/{CustomizationPage-DqUGcoH0.js → CustomizationPage-D6jEU7nL.js} +1 -1
  15. package/dist/dashboard/assets/CustomizationPage-D6jEU7nL.js.gz +0 -0
  16. package/dist/dashboard/assets/HealthEventsModal-CZkpn0a7.js +1 -0
  17. package/dist/dashboard/assets/HealthEventsModal-CZkpn0a7.js.gz +0 -0
  18. package/dist/dashboard/assets/{LoginPage-DbhTGfhb.js → LoginPage-BJlMVN4U.js} +1 -1
  19. package/dist/dashboard/assets/LoginPage-BJlMVN4U.js.gz +0 -0
  20. package/dist/dashboard/assets/ModelPicker-Br3CXEau.js +1 -0
  21. package/dist/dashboard/assets/ModelPicker-Br3CXEau.js.gz +0 -0
  22. package/dist/dashboard/assets/{OverviewPage-C3NIzsDx.js → OverviewPage-CQxXbo2g.js} +1 -1
  23. package/dist/dashboard/assets/OverviewPage-CQxXbo2g.js.gz +0 -0
  24. package/dist/dashboard/assets/ProviderDetailPage--0RBNh99.js +3 -0
  25. package/dist/dashboard/assets/ProviderDetailPage--0RBNh99.js.gz +0 -0
  26. package/dist/dashboard/assets/ProviderIcon-paOCq8I0.js.gz +0 -0
  27. package/dist/dashboard/assets/ProvidersPage-1M-C3mbu.js +1 -0
  28. package/dist/dashboard/assets/ProvidersPage-1M-C3mbu.js.gz +0 -0
  29. package/dist/dashboard/assets/ProxyPage-CXiumA53.js +7 -0
  30. package/dist/dashboard/assets/ProxyPage-CXiumA53.js.gz +0 -0
  31. package/dist/dashboard/assets/QuotaPage-BGDIfIYP.js +1 -0
  32. package/dist/dashboard/assets/QuotaPage-BGDIfIYP.js.gz +0 -0
  33. package/dist/dashboard/assets/{SettingsPage-YxRml8AT.js → SettingsPage-BHW4Zt06.js} +1 -1
  34. package/dist/dashboard/assets/SettingsPage-BHW4Zt06.js.gz +0 -0
  35. package/dist/dashboard/assets/SetupPage-VOYC_lIa.js +1 -0
  36. package/dist/dashboard/assets/SetupPage-VOYC_lIa.js.gz +0 -0
  37. package/dist/dashboard/assets/SortableList-DpOTnGuH.js +1 -0
  38. package/dist/dashboard/assets/SortableList-DpOTnGuH.js.gz +0 -0
  39. package/dist/dashboard/assets/StudioPage-BNIDLiU6.js +31 -0
  40. package/dist/dashboard/assets/StudioPage-BNIDLiU6.js.gz +0 -0
  41. package/dist/dashboard/assets/ToolIcon-K1ckcDKg.js.gz +0 -0
  42. package/dist/dashboard/assets/{UsagePage-Djes-Epy.js → UsagePage-BAFaSDQV.js} +14 -14
  43. package/dist/dashboard/assets/UsagePage-BAFaSDQV.js.gz +0 -0
  44. package/dist/dashboard/assets/api-keys-BETfaMYZ.js +1 -0
  45. package/dist/dashboard/assets/api-keys-BETfaMYZ.js.gz +0 -0
  46. package/dist/dashboard/assets/app-BLCvGdzb.css +2 -0
  47. package/dist/dashboard/assets/app-BLCvGdzb.css.gz +0 -0
  48. package/dist/dashboard/assets/{app-BDJWMThu.js → app-Cjq7nrwu.js} +3 -3
  49. package/dist/dashboard/assets/app-Cjq7nrwu.js.gz +0 -0
  50. package/dist/dashboard/assets/arrow-left-CpBxkoxI.js.gz +0 -0
  51. package/dist/dashboard/assets/arrow-right-Dl5yKnp8.js.gz +0 -0
  52. package/dist/dashboard/assets/{assert-Bwh6DJTK.js → assert-7J6_LVD3.js} +1 -1
  53. package/dist/dashboard/assets/assert-7J6_LVD3.js.gz +0 -0
  54. package/dist/dashboard/assets/backup-file-gdKIlg8U.js.gz +0 -0
  55. package/dist/dashboard/assets/{badge-BwmwEOgA.js → badge-BTyGk_DL.js} +1 -1
  56. package/dist/dashboard/assets/badge-BTyGk_DL.js.gz +0 -0
  57. package/dist/dashboard/assets/{banner-BKBfKTqn.js → banner-bujTWYM4.js} +1 -1
  58. package/dist/dashboard/assets/banner-bujTWYM4.js.gz +0 -0
  59. package/dist/dashboard/assets/brain-Cwed_72z.js.gz +0 -0
  60. package/dist/dashboard/assets/{card-BTdbRFFg.js → card-B0Bnx5CA.js} +1 -1
  61. package/dist/dashboard/assets/card-B0Bnx5CA.js.gz +0 -0
  62. package/dist/dashboard/assets/check-D69FzdvC.js.gz +0 -0
  63. package/dist/dashboard/assets/chevron-right-BXIy5l3h.js.gz +0 -0
  64. package/dist/dashboard/assets/circle-alert-CntYHV5v.js.gz +0 -0
  65. package/dist/dashboard/assets/circle-check-BU3v_mFW.js.gz +0 -0
  66. package/dist/dashboard/assets/cli-tools-DE2ug812.js +1 -0
  67. package/dist/dashboard/assets/cli-tools-DE2ug812.js.gz +0 -0
  68. package/dist/dashboard/assets/clipboard-button-R_rArH8S.js +1 -0
  69. package/dist/dashboard/assets/clipboard-button-R_rArH8S.js.gz +0 -0
  70. package/dist/dashboard/assets/cog-CdWhsajs.js.gz +0 -0
  71. package/dist/dashboard/assets/copy-ngmQ9zcZ.js.gz +0 -0
  72. package/dist/dashboard/assets/{dialog-iocKA3jr.js → dialog-BWIP_EvW.js} +1 -1
  73. package/dist/dashboard/assets/dialog-BWIP_EvW.js.gz +0 -0
  74. package/dist/dashboard/assets/dialog-actions-B1axpEg7.js.gz +0 -0
  75. package/dist/dashboard/assets/download-A0SW9OCW.js.gz +0 -0
  76. package/dist/dashboard/assets/download-dRFo5_Wu.js.gz +0 -0
  77. package/dist/dashboard/assets/{drawer-CDKOTZdY.js → drawer-BKcgVugF.js} +1 -1
  78. package/dist/dashboard/assets/drawer-BKcgVugF.js.gz +0 -0
  79. package/dist/dashboard/assets/entry-7dpgvpJ3.js +4 -0
  80. package/dist/dashboard/assets/entry-7dpgvpJ3.js.gz +0 -0
  81. package/dist/dashboard/assets/entry-CcWkGR4a.js +1 -0
  82. package/dist/dashboard/assets/entry-CcWkGR4a.js.gz +0 -0
  83. package/dist/dashboard/assets/entry-kTiTFrvh.js +1 -0
  84. package/dist/dashboard/assets/entry-kTiTFrvh.js.gz +0 -0
  85. package/dist/dashboard/assets/eye-C_hawfH4.js.gz +0 -0
  86. package/dist/dashboard/assets/eye-off-Bk5g2luF.js.gz +0 -0
  87. package/dist/dashboard/assets/fingerprint-pattern-BWuHtbW4.js.gz +0 -0
  88. package/dist/dashboard/assets/gauge-BbIMy7MB.js.gz +0 -0
  89. package/dist/dashboard/assets/github-badge-Booc5mNe.js +1 -0
  90. package/dist/dashboard/assets/github-badge-Booc5mNe.js.gz +0 -0
  91. package/dist/dashboard/assets/image-BPaouViG.js.gz +0 -0
  92. package/dist/dashboard/assets/{index-C4hXfAMs.js → index-D70pChfn.js} +2 -2
  93. package/dist/dashboard/assets/index-D70pChfn.js.gz +0 -0
  94. package/dist/dashboard/assets/{inline-DCejSLlA.js → inline-D1TCqM2D.js} +1 -1
  95. package/dist/dashboard/assets/inline-D1TCqM2D.js.gz +0 -0
  96. package/dist/dashboard/assets/{input-Bn4_kNav.js → input-B9oyU93y.js} +1 -1
  97. package/dist/dashboard/assets/input-B9oyU93y.js.gz +0 -0
  98. package/dist/dashboard/assets/jsx-runtime-CXUMngI_.js.gz +0 -0
  99. package/dist/dashboard/assets/key-round-UkavsGxp.js.gz +0 -0
  100. package/dist/dashboard/assets/layers-2-glBbjl.js.gz +0 -0
  101. package/dist/dashboard/assets/{layout-Bv-NxqZ5.js → layout-BArzXirQ.js} +1 -1
  102. package/dist/dashboard/assets/layout-BArzXirQ.js.gz +0 -0
  103. package/dist/dashboard/assets/{list-row-BLA0sldD.js → list-row-BVZzaoHF.js} +1 -1
  104. package/dist/dashboard/assets/list-row-BVZzaoHF.js.gz +0 -0
  105. package/dist/dashboard/assets/{live-YlifPYox.js → live-EmuIayqp.js} +1 -1
  106. package/dist/dashboard/assets/live-EmuIayqp.js.gz +0 -0
  107. package/dist/dashboard/assets/log-in-BmRjy60c.js.gz +0 -0
  108. package/dist/dashboard/assets/message-circle-CCxGwRvv.js.gz +0 -0
  109. package/dist/dashboard/assets/{model-bans-CVvHZ-qz.js → model-bans-CSPQ9xB0.js} +1 -1
  110. package/dist/dashboard/assets/model-bans-CSPQ9xB0.js.gz +0 -0
  111. package/dist/dashboard/assets/mutation-BkoLM5Ba.js +1 -0
  112. package/dist/dashboard/assets/mutation-BkoLM5Ba.js.gz +0 -0
  113. package/dist/dashboard/assets/numbers-CFL4_Dqc.js.gz +0 -0
  114. package/dist/dashboard/assets/pencil-768ysRAr.js.gz +0 -0
  115. package/dist/dashboard/assets/plus-DIdX_g-x.js.gz +0 -0
  116. package/dist/dashboard/assets/power-off-Yjw9GMJh.js +1 -0
  117. package/dist/dashboard/assets/power-off-Yjw9GMJh.js.gz +0 -0
  118. package/dist/dashboard/assets/privacy-mode-GM8bej85.js +1 -0
  119. package/dist/dashboard/assets/privacy-mode-GM8bej85.js.gz +0 -0
  120. package/dist/dashboard/assets/providers/agentrouter.svg.gz +0 -0
  121. package/dist/dashboard/assets/providers/aihubmix.svg.gz +0 -0
  122. package/dist/dashboard/assets/providers/alibaba-coding-plan.svg.gz +0 -0
  123. package/dist/dashboard/assets/providers/alibaba.svg.gz +0 -0
  124. package/dist/dashboard/assets/providers/antigravity.svg.gz +0 -0
  125. package/dist/dashboard/assets/providers/bai.svg.gz +0 -0
  126. package/dist/dashboard/assets/providers/blackbox.svg.gz +0 -0
  127. package/dist/dashboard/assets/providers/claude-code.svg.gz +0 -0
  128. package/dist/dashboard/assets/providers/exa.svg.gz +0 -0
  129. package/dist/dashboard/assets/providers/gmi-cloud.svg.gz +0 -0
  130. package/dist/dashboard/assets/providers/inferhub.svg.gz +0 -0
  131. package/dist/dashboard/assets/providers/muse.svg.gz +0 -0
  132. package/dist/dashboard/assets/providers/nous-research.svg.gz +0 -0
  133. package/dist/dashboard/assets/providers/openai-light.svg.gz +0 -0
  134. package/dist/dashboard/assets/providers/parallel.svg.gz +0 -0
  135. package/dist/dashboard/assets/providers/tokenharbor.svg.gz +0 -0
  136. package/dist/dashboard/assets/providers/zai-coding-plan.svg.gz +0 -0
  137. package/dist/dashboard/assets/{query-keys-ROf-g1Wi.js → query-keys-D7wX2vM5.js} +1 -1
  138. package/dist/dashboard/assets/query-keys-D7wX2vM5.js.gz +0 -0
  139. package/dist/dashboard/assets/quota-DZGyp0N5.js.gz +0 -0
  140. package/dist/dashboard/assets/refresh-cw-BqJFk4sU.js.gz +0 -0
  141. package/dist/dashboard/assets/rotate-ccw-CufcqITi.js.gz +0 -0
  142. package/dist/dashboard/assets/route-CNSNj9Zm.js.gz +0 -0
  143. package/dist/dashboard/assets/{routing-jntw9-Ui.js → routing-BExgxxBU.js} +1 -1
  144. package/dist/dashboard/assets/routing-BExgxxBU.js.gz +0 -0
  145. package/dist/dashboard/assets/scaling-nWE4Cx8f.js.gz +0 -0
  146. package/dist/dashboard/assets/search-JOKus9rb.js.gz +0 -0
  147. package/dist/dashboard/assets/{select-CGUuTQmj.js → select-C9mMoEpJ.js} +1 -1
  148. package/dist/dashboard/assets/select-C9mMoEpJ.js.gz +0 -0
  149. package/dist/dashboard/assets/settings-C4_Gn_wq.js +1 -0
  150. package/dist/dashboard/assets/settings-C4_Gn_wq.js.gz +0 -0
  151. package/dist/dashboard/assets/shield-check-DVS0Foqh.js.gz +0 -0
  152. package/dist/dashboard/assets/sliders-horizontal-ClG7dBeJ.js.gz +0 -0
  153. package/dist/dashboard/assets/sparkles-BRaRUxAU.js.gz +0 -0
  154. package/dist/dashboard/assets/{stack-C1kTcOmP.js → stack-Ca5HxI5i.js} +1 -1
  155. package/dist/dashboard/assets/stack-Ca5HxI5i.js.gz +0 -0
  156. package/dist/dashboard/assets/{state-DHKdg-pm.js → state-CzUPfLXo.js} +1 -1
  157. package/dist/dashboard/assets/state-CzUPfLXo.js.gz +0 -0
  158. package/dist/dashboard/assets/stream-retry-5QnVuSSo.js.gz +0 -0
  159. package/dist/dashboard/assets/{switch-DIDeAiz9.js → switch-DOUIky_i.js} +1 -1
  160. package/dist/dashboard/assets/switch-DOUIky_i.js.gz +0 -0
  161. package/dist/dashboard/assets/terminal-Bd4ee8TA.js +1 -0
  162. package/dist/dashboard/assets/terminal-Bd4ee8TA.js.gz +0 -0
  163. package/dist/dashboard/assets/toast-C76WrMhc.js +2 -0
  164. package/dist/dashboard/assets/toast-C76WrMhc.js.gz +0 -0
  165. package/dist/dashboard/assets/tokens-DDxMbSRL.js.gz +0 -0
  166. package/dist/dashboard/assets/trash-Cppn5c3R.js.gz +0 -0
  167. package/dist/dashboard/assets/use-clipboard-B0Sy03fE.js.gz +0 -0
  168. package/dist/dashboard/assets/use-presence-BSZEBx7U.js.gz +0 -0
  169. package/dist/dashboard/assets/use-reduced-motion-C4B0R6Sz.js.gz +0 -0
  170. package/dist/dashboard/assets/use-timeout-BwcBBRrT.js.gz +0 -0
  171. package/dist/dashboard/assets/{useMutation-DVmwOKU-.js → useMutation-D87FZwH0.js} +1 -1
  172. package/dist/dashboard/assets/useMutation-D87FZwH0.js.gz +0 -0
  173. package/dist/dashboard/assets/wrench-B6E1oEuY.js.gz +0 -0
  174. package/dist/dashboard/index.html +1 -1
  175. package/dist/dashboard/index.html.gz +0 -0
  176. package/dist/dashboard/precompressed-assets.json +123 -0
  177. package/migrations/full-postgres/0013_add_providers_tenant_id_index.sql +22 -0
  178. package/migrations/full-postgres/0014_add_provider_accounts_tenant_id_index.sql +21 -0
  179. package/migrations/lite-sqlite3/0000_baseline.sql +4 -2
  180. package/migrations/lite-sqlite3/0013_add_providers_tenant_id_index.sql +4 -0
  181. package/migrations/lite-sqlite3/0014_add_provider_accounts_tenant_id_index.sql +4 -0
  182. package/package.json +25 -30
  183. package/scripts/cli/{carte-launcher.cjs → bin/carte.cjs} +8 -8
  184. package/scripts/cli/{cli-launcher.cjs → bin/cartethyia.cjs} +167 -134
  185. package/scripts/cli/command/admin.ts +65 -0
  186. package/scripts/cli/command/console-menu.ts +227 -0
  187. package/scripts/cli/{doctor.ts → command/doctor.ts} +257 -258
  188. package/scripts/cli/{setup.ts → command/setup.ts} +8 -12
  189. package/scripts/cli/command/start.ts +13 -0
  190. package/scripts/cli/command/tray.ts +165 -0
  191. package/scripts/cli/command/update.ts +23 -0
  192. package/scripts/cli/{runtime-state.ts → gateway/drain-token.ts} +78 -78
  193. package/scripts/cli/gateway/spawn.ts +101 -0
  194. package/scripts/cli/gateway/stop.ts +51 -0
  195. package/scripts/cli/main.ts +94 -0
  196. package/scripts/cli/support/bun.ts +27 -0
  197. package/scripts/cli/support/env.ts +99 -0
  198. package/scripts/cli/support/platform.ts +64 -0
  199. package/scripts/cli/support/services.ts +88 -0
  200. package/scripts/cli/support/startup-signal.ts +23 -0
  201. package/scripts/cli/{version.ts → support/version.ts} +1 -1
  202. package/scripts/cli/tray/hidden-window.vbs +28 -0
  203. package/scripts/cli/{tray.ts → tray/index.ts} +3 -3
  204. package/scripts/cli/{tray.ps1 → tray/windows.ps1} +107 -98
  205. package/scripts/cli/ui/background.ts +49 -0
  206. package/src/boot/app.ts +3 -1
  207. package/src/boot/dependencies.ts +36 -13
  208. package/src/config/providers.ts +27 -1
  209. package/src/config/spec.ts +11 -0
  210. package/src/console/backup/routes.ts +8 -0
  211. package/src/console/cli-tools/contracts.ts +6 -6
  212. package/src/console/console-router.ts +5 -3
  213. package/src/console/dashboard-assets.ts +81 -11
  214. package/src/console/observability/contracts.ts +54 -22
  215. package/src/console/observability/routes.ts +31 -6
  216. package/src/console/observability/store.ts +68 -28
  217. package/src/console/providers/catalog/public-model-store.ts +91 -60
  218. package/src/console/providers/catalog/store.ts +5 -1
  219. package/src/console/quota/account-quota-tenant.ts +9 -6
  220. package/src/console/response-compression.ts +69 -2
  221. package/src/console/routing/pools/probe-verdict.ts +72 -0
  222. package/src/console/share/share-router.ts +7 -4
  223. package/src/console/share/share-stats.ts +12 -5
  224. package/src/console/shared/read-through-cache.ts +133 -7
  225. package/src/console/updates/repository-updates.ts +39 -34
  226. package/src/network/outbound-fetch.ts +113 -25
  227. package/src/network/tls/bun-client-hello.ts +112 -0
  228. package/src/observability/event-log.ts +29 -8
  229. package/src/observability/metrics.ts +40 -13
  230. package/src/observability/runtime-metrics.ts +7 -0
  231. package/src/persistence/schema.ts +40 -2
  232. package/src/protocol/response/codex.ts +9 -75
  233. package/src/protocol/tool-identity.ts +43 -9
  234. package/src/providers/authentication/jwt-validator.ts +130 -187
  235. package/src/providers/authentication/oauth-flow-store.ts +16 -9
  236. package/src/providers/default-registry.ts +4 -0
  237. package/src/providers/discovery/catalog/catalog-format.ts +20 -0
  238. package/src/providers/discovery/models-dev-catalog.ts +39 -22
  239. package/src/providers/discovery/probe-wire.ts +29 -5
  240. package/src/providers/integrations/buddy/buddy-catalog-shared.ts +3 -2
  241. package/src/providers/integrations/buddy/buddy-cli-headers.ts +88 -0
  242. package/src/providers/integrations/buddy/buddy-conversation-headers.ts +4 -0
  243. package/src/providers/integrations/buddy/buddy-discovery-shared.ts +33 -1
  244. package/src/providers/integrations/buddy/buddy-identity.ts +46 -0
  245. package/src/providers/integrations/buddy/buddy-oauth-shared.ts +37 -1
  246. package/src/providers/integrations/buddy/buddy-usage-store.ts +40 -5
  247. package/src/providers/integrations/buddy/codebuddy/provider.ts +2 -2
  248. package/src/providers/integrations/buddy/codebuddy/shared.ts +106 -73
  249. package/src/providers/integrations/buddy/workbuddy/cn-provider.ts +5 -2
  250. package/src/providers/integrations/buddy/workbuddy/quota.ts +172 -159
  251. package/src/providers/integrations/buddy/workbuddy/shared.ts +200 -171
  252. package/src/providers/integrations/codex/codex.ts +5 -8
  253. package/src/providers/integrations/factory/factory-oauth.ts +7 -11
  254. package/src/providers/integrations/opencode/opencode-go-quota.ts +130 -0
  255. package/src/providers/integrations/opencode/provider.ts +42 -3
  256. package/src/providers/integrations/qoder/qoder-oauth.ts +3 -9
  257. package/src/providers/integrations/shared/install-id.ts +29 -2
  258. package/src/providers/operations/client-versions.ts +11 -1
  259. package/src/providers/operations/model-catalog-cache.ts +18 -3
  260. package/src/providers/operations/provider-catalog-service.ts +76 -0
  261. package/src/transport/dispatch/attempt-finalize.ts +7 -1
  262. package/src/transport/dispatch/attempt-loop.ts +9 -7
  263. package/src/transport/dispatch/empty-stream.ts +17 -26
  264. package/src/transport/failure-policy.ts +20 -0
  265. package/src/transport/routing/route-catalog.ts +42 -3
  266. package/src/transport/surface/chat/encode.ts +18 -31
  267. package/src/transport/surface/messages/stream.ts +3 -2
  268. package/src/transport/translation/tool-repair.ts +37 -16
  269. package/src/workers/account-identity-sweep.ts +14 -12
  270. package/src/workers/daily-checkin.ts +62 -0
  271. package/src/workers/quota-refresh-sweep.ts +27 -2
  272. package/dist/dashboard/assets/CombosPage-B7ETkfVH.js +0 -1
  273. package/dist/dashboard/assets/ConsoleLogPage-AisQzCI1.js +0 -1
  274. package/dist/dashboard/assets/HealthEventsModal-BNflDm_f.js +0 -1
  275. package/dist/dashboard/assets/ModelPicker-CAiPR5Vd.js +0 -1
  276. package/dist/dashboard/assets/ProviderDetailPage-BK8i5B5X.js +0 -3
  277. package/dist/dashboard/assets/ProvidersPage-CvCVgm1e.js +0 -1
  278. package/dist/dashboard/assets/ProxyPage-DjabkuzP.js +0 -7
  279. package/dist/dashboard/assets/QuotaPage-Dxe0B0iu.js +0 -1
  280. package/dist/dashboard/assets/SetupPage-BaD4P_jW.js +0 -1
  281. package/dist/dashboard/assets/SortableList-Bol1ASmI.js +0 -1
  282. package/dist/dashboard/assets/StudioPage-CLP4le3U.js +0 -31
  283. package/dist/dashboard/assets/api-keys-CjIGQhe7.js +0 -1
  284. package/dist/dashboard/assets/app-Cjgo4-Lf.css +0 -2
  285. package/dist/dashboard/assets/cli-tools-DccaOfhX.js +0 -1
  286. package/dist/dashboard/assets/clipboard-button-DQmMikNQ.js +0 -1
  287. package/dist/dashboard/assets/entry-Cpi0rph1.js +0 -4
  288. package/dist/dashboard/assets/entry-Dm3PpDCO.js +0 -1
  289. package/dist/dashboard/assets/entry-keNDZ_Wz.js +0 -1
  290. package/dist/dashboard/assets/github-badge-BuAJr8oU.js +0 -1
  291. package/dist/dashboard/assets/mutation-BIizFZav.js +0 -1
  292. package/dist/dashboard/assets/privacy-mode-CQjbZ3xk.js +0 -1
  293. package/dist/dashboard/assets/settings-BAS6QbmJ.js +0 -1
  294. package/dist/dashboard/assets/terminal-C9mZ4Ugm.js +0 -1
  295. package/dist/dashboard/assets/toast-DKAdP2mo.js +0 -2
  296. package/scripts/cli/cli.ts +0 -771
  297. package/scripts/operations/probe-egress.ts +0 -335
  298. package/scripts/operations/restart.ts +0 -120
  299. package/scripts/shared/env.ts +0 -269
  300. /package/{tray-assets → scripts/cli/tray/assets}/cartethyia.ico +0 -0
  301. /package/{tray-assets → scripts/cli/tray/assets}/cartethyia.png +0 -0
  302. /package/scripts/cli/{menu.ts → ui/prompt.ts} +0 -0
  303. /package/scripts/cli/{wordmark.ts → ui/wordmark.ts} +0 -0
@@ -1 +1 @@
1
- import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{a as i,i as a,n as o,o as s,r as c}from"./model-bans-CVvHZ-qz.js";import{n as l,t as u}from"./fingerprint-pattern-BWuHtbW4.js";import{t as d}from"./check-D69FzdvC.js";import{n as f,t as p}from"./select-CGUuTQmj.js";import{t as m}from"./chevron-right-BXIy5l3h.js";import{t as h}from"./SortableList-Bol1ASmI.js";import{h as g,n as _,t as v}from"./toast-DKAdP2mo.js";import{t as y}from"./copy-ngmQ9zcZ.js";import{t as b}from"./download-A0SW9OCW.js";import{t as x}from"./eye-off-Bk5g2luF.js";import{t as S}from"./eye-C_hawfH4.js";import{t as C}from"./gauge-BbIMy7MB.js";import{a as w,n as T,r as E,t as ee}from"./state-DHKdg-pm.js";import{t as te}from"./key-round-UkavsGxp.js";import{n as ne,r as D,t as O}from"./clipboard-button-DQmMikNQ.js";import{t as k}from"./dialog-iocKA3jr.js";import{t as A}from"./pencil-768ysRAr.js";import{t as re}from"./plus-DIdX_g-x.js";import{t as j}from"./refresh-cw-BqJFk4sU.js";import{t as M}from"./route-CNSNj9Zm.js";import{t as ie}from"./search-JOKus9rb.js";import{t as ae}from"./shield-check-DVS0Foqh.js";import{n as N,r as oe,t as se}from"./settings-BAS6QbmJ.js";import{t as P}from"./sparkles-BRaRUxAU.js";import{t as ce}from"./trash-Cppn5c3R.js";import{b as le,y as ue}from"./assert-Bwh6DJTK.js";import{c as F}from"./query-keys-ROf-g1Wi.js";import{F as I,O as de,et as fe,nt as pe}from"./entry-Cpi0rph1.js";import{n as L,r as R,t as z}from"./card-BTdbRFFg.js";import{t as B}from"./use-clipboard-B0Sy03fE.js";import{n as me}from"./download-dRFo5_Wu.js";import{c as V,d as H}from"./tokens-DDxMbSRL.js";import{t as U}from"./badge-BwmwEOgA.js";import{n as W,t as he}from"./input-Bn4_kNav.js";import{t as ge}from"./ModelPicker-CAiPR5Vd.js";import{t as G}from"./switch-DIDeAiz9.js";import{t as K}from"./stack-C1kTcOmP.js";import{n as q}from"./inline-DCejSLlA.js";import{a as _e,c as ve,d as J,f as ye,i as be,l as xe,n as Se,o as Ce,r as we,s as Te,t as Y,u as Ee}from"./api-keys-CjIGQhe7.js";import{a as X,i as Z,n as De,r as Oe}from"./cli-tools-DccaOfhX.js";import{t as ke}from"./layout-Bv-NxqZ5.js";import{s as Ae}from"./quota-DZGyp0N5.js";var je=e(`lock-keyhole`,[[`circle`,{cx:`12`,cy:`16`,r:`1`,key:`1au0dj`}],[`rect`,{x:`3`,y:`10`,width:`18`,height:`12`,rx:`2`,key:`6s8ecr`}],[`path`,{d:`M7 10V7a5 5 0 0 1 10 0v3`,key:`1pqi11`}]]),Me=e(`repeat-2`,[[`path`,{d:`m2 9 3-3 3 3`,key:`1ltn5i`}],[`path`,{d:`M13 18H7a2 2 0 0 1-2-2V6`,key:`1r6tfw`}],[`path`,{d:`m22 15-3 3-3-3`,key:`4rnwn2`}],[`path`,{d:`M11 6h6a2 2 0 0 1 2 2v10`,key:`2f72bc`}]]),Ne=e(`rotate-cw`,[[`path`,{d:`M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8`,key:`1p45f6`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}]]),Pe=e(`scissors`,[[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M8.12 8.12 12 12`,key:`1alkpv`}],[`path`,{d:`M20 4 8.12 15.88`,key:`xgtan2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M14.8 14.8 20 20`,key:`ptml3r`}]]),Fe=e(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]),Ie=e(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]),Le=e(`shield-x`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`m14.5 9.5-5 5`,key:`17q4r4`}],[`path`,{d:`m9.5 9.5 5 5`,key:`18nt4w`}]]),Re=e(`undo-2`,[[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`,key:`f3b9sd`}]]),ze=e(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]),Be=e(`users-round`,[[`path`,{d:`M18 21a8 8 0 0 0-16 0`,key:`3ypg7q`}],[`circle`,{cx:`10`,cy:`8`,r:`5`,key:`o932ke`}],[`path`,{d:`M22 20c0-3.37-2-6.5-4-8a5 5 0 0 0-.45-8.3`,key:`10s06x`}]]),Ve=[`routing:invoke`,`routing:cli_mapping`,`search:invoke`,`dashboard:read`,`dashboard:write`,`providers:read`,`providers:write`,`models:read`,`models:write`],He=[`image/png`,`image/jpeg`,`image/webp`,`image/gif`],Q=t(n(),1),$=r(),Ue={"routing:invoke":`Call /v1/* gateway routes within this tenant.`,"routing:cli_mapping":`Resolve persisted CLI source→target model mappings.`,"search:invoke":`Call POST /v1/search with exa.`,"dashboard:read":`Read this tenant's configuration and usage.`,"dashboard:write":`Modify this tenant's configuration.`,"providers:read":`Read provider rows, including accounts.`,"providers:write":`Add, modify, or delete provider rows and their credentials.`,"models:read":`Read catalog model rows.`,"models:write":`Add, modify, or delete catalog model rows.`},We={"routing:invoke":M,"routing:cli_mapping":M,"search:invoke":ie,"dashboard:read":S,"dashboard:write":A,"providers:read":fe,"providers:write":je,"models:read":l,"models:write":i},Ge={k:1e3,m:1e6,b:1e9,t:0xe8d4a51000},Ke=[{label:`1M`,amount:1e6,description:`1 million`},{label:`100M`,amount:1e8,description:`100 million`},{label:`1B`,amount:1e9,description:`1 billion`},{label:`1T`,amount:0xe8d4a51000,description:`1 trillion`}];function qe(e){let t=e.trim().toLowerCase();if(!t)return;let n=t.match(/^([\d.]+)\s*([kmbt])?$/);if(!n)return;let r=Number(n[1]);if(!Number.isFinite(r)||r<=0)return;let i=n[2]?Ge[n[2]]??1:1;return Math.round(r*i)}function Je(e){if(e==null)return``;let t=Ke.find(t=>t.amount===e);return t?t.label:e>=1e9?`${(e/1e9).toFixed(1).replace(/\.0$/,``)}B`:e>=1e6?`${(e/1e6).toFixed(1).replace(/\.0$/,``)}M`:e>=1e3?`${(e/1e3).toFixed(1).replace(/\.0$/,``)}K`:String(e)}function Ye(e){let t=Number(e.trim());return Number.isFinite(t)&&t>0?Math.round(t):void 0}function Xe(e){let t=Ye(e);return e.trim()===``?null:t}function Ze({label:e,value:t,onChange:n,disabled:r}){let i=qe(t),a=Ke.find(e=>e.amount===i)?.label;return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(W,{label:e,value:t,onChange:e=>n(e.target.value),placeholder:`e.g. 1M, 500K`,disabled:r}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-3 mt-3`,role:`group`,"aria-label":`${e} presets`,children:Ke.map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":a===e.label,"aria-label":`${e.label}, ${e.description} tokens`,onClick:()=>n(e.label),disabled:r,className:`py-1 px-4 rounded-chip text-micro font-semibold`,style:{cursor:r?`not-allowed`:`pointer`,border:`1px solid ${a===e.label?`var(--accent)`:`var(--inner-border)`}`,background:a===e.label?`var(--accent-soft)`:`transparent`,color:a===e.label?`var(--accent)`:`var(--text-tertiary)`},children:e.label},e.label))})]})}function Qe({tool:e,keyId:t,busy:n,scopeGranted:r,onScopeChange:i}){let a=Z(e.id,t),o=Oe(),s=De(),c=a.data?.enabled??!1,l=r&&c,u=a.data?.mappings.length??0,d=o.isPending||s.isPending;return(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-6 py-2 px-5 rounded-inset`,style:{minHeight:`44px`,border:`1px solid var(--inner-border)`,background:l?`var(--accent-soft)`:`var(--surface-1)`},children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,$.jsx)(M,{size:16,className:`mt-1 shrink-0 text-accent`,"aria-hidden":`true`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-caption font-semibold text-text-primary`,children:e.name}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:l?`Remote routing on — ${u} route${u===1?``:`s`} active, routing:cli_mapping granted.`:`Remote routing off — this key's requests go straight to the provider.`})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,$.jsx)(G,{checked:l,disabled:n||d||a.isLoading,"aria-label":`Enable remote routing for ${e.name}`,onChange:n=>{n!==r&&i(n),o.mutate({toolId:e.id,keyId:t,input:{enabled:n,mappings:a.data?.mappings??[]}},{onSuccess:()=>v.success(`Saved remote routing for ${e.name}.`),onError:e=>v.error(F(e,`Could not save remote routing.`))})}}),(0,$.jsx)(_,{variant:`secondary`,size:`sm`,disabled:n||d||!c&&u===0,onClick:()=>s.mutate({toolId:e.id,keyId:t},{onSuccess:()=>v.success(`Cleared remote routes for ${e.name}.`),onError:e=>v.error(F(e,`Could not reset remote routes.`))}),children:s.isPending?`Resetting…`:`Reset`})]})]})}function $e({keyId:e,busy:t,scopeGranted:n,onScopeChange:r,persistScope:i}){let a=(X().data??[]).filter(e=>e.mappingSupported);return e.length===0||a.length===0?null:(0,$.jsxs)(`section`,{"aria-labelledby":`remote-routing-heading`,className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h4`,{id:`remote-routing-heading`,className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(M,{size:15,className:`text-accent`,"aria-hidden":`true`}),`Remote routing`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Route this key's CLI model calls through persisted mappings and grant routing:cli_mapping. Applies immediately — no save needed.`})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:a.map(a=>(0,$.jsx)(Qe,{tool:a,keyId:e,busy:t,scopeGranted:n,onScopeChange:e=>{r(e),i(e)}},a.id))})]})}function et(e,t,n){let r=e===`personal`?t.trim():``;return{keyMode:e,keyPrefix:n.trim()||void 0,...r?{key:r}:{}}}function tt(e,t){return e===`personal`?t??null:null}function nt(e){if(e?.isDefault)return[...Ve];let t=e?.scopes;return t&&t.length>0?[...t]:[`routing:invoke`,`search:invoke`]}function rt({mode:e,record:t,busy:n,onDone:r,onClose:i,actionsRef:a}){let[o,c]=(0,Q.useState)(t?.label??``),[d,p]=(0,Q.useState)(t?.keyPrefix??``),[m,h]=(0,Q.useState)(``),[g,y]=(0,Q.useState)(t?.requestsPerMinute?.toString()??``),[b,x]=(0,Q.useState)(Je(t?.dailyTokenLimit??null)),[S,w]=(0,Q.useState)(Je(t?.monthlyTokenLimit??null)),[T,E]=(0,Q.useState)(Je(t?.lifetimeTokenBudget??null)),[ee,D]=(0,Q.useState)(t?.lifetimeTokenBudget==null?`recurring`:`one-time`),[O,k]=(0,Q.useState)(t?.maxConcurrentRequests?.toString()??``),[A,re]=(0,Q.useState)(()=>nt(t)),[j,ie]=(0,Q.useState)(t?.modelAccessMode??`whitelist`),[N,se]=(0,Q.useState)(()=>{let e=t?.modelList;return e?[...e]:[]}),[P,ce]=(0,Q.useState)(!1),[I,de]=(0,Q.useState)(()=>{let e=t?.clientRouterDenylist;return e?[...new Set(e.map(le).filter(e=>e!==void 0))]:[]}),[fe,L]=(0,Q.useState)(()=>t?.notesTitle??``),[R,z]=(0,Q.useState)(()=>t?.notesSubtitle??``),[B,me]=(0,Q.useState)(()=>t?.notesBody??``),[V,H]=(0,Q.useState)(t?.sharePopupEnabled??!1),[U,K]=(0,Q.useState)(null),[q,_e]=(0,Q.useState)(!1),[ve,J]=(0,Q.useState)(null),be=t?.sharePopupImageMime!==void 0,xe=U??(be&&!q&&t!==null?`/console/api/api-keys/${t.id}/share-popup-image`:null),[Se,Ce]=(0,Q.useState)(t?.sharePopupTitle??``),[we,Te]=(0,Q.useState)(t?.sharePopupBody??``),[Y,Ee]=(0,Q.useState)(t?.keyMode??`personal`),X=ee===`one-time`,Z=e===`edit`,De=ye(),Oe=e=>re(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),ke=()=>{r({label:o.trim(),...et(Y,m,d),scopes:A,modelAccessMode:j,modelList:N,clientRouterDenylist:I,requestsPerMinute:Xe(g),maxConcurrentRequests:Xe(O),dailyTokenLimit:X?null:qe(b)??null,monthlyTokenLimit:X?null:qe(S)??null,lifetimeTokenBudget:X?qe(T)??null:null,notesTitle:fe.trim(),notesSubtitle:R.trim(),notesBody:B.trim(),sharePopupEnabled:V,...U===null?q?{sharePopupImage:null}:{}:{sharePopupImage:U},sharePopupTitle:Se.trim(),sharePopupBody:we.trim()})};return(0,Q.useEffect)(()=>{a?.((0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(_,{variant:`secondary`,size:`sm`,onClick:i,disabled:n,children:`Cancel`}),(0,$.jsx)(_,{variant:`primary`,size:`sm`,disabled:n||e===`create`&&!o.trim(),onClick:ke,children:n?`Saving…`:e===`create`?`Create API key`:`Save changes`})]}))}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-6 min-w-0 pb-2`,children:[(0,$.jsxs)(`section`,{className:`flex flex-col gap-4 min-w-0 p-6 border border-inner-border rounded-card bg-surface-2 col-span-full`,children:[(0,$.jsxs)(`h3`,{className:`inline-flex items-center gap-2 text-body font-bold text-text-primary`,children:[(0,$.jsx)(te,{size:16,className:`text-accent`,"aria-hidden":`true`}),`Credential mode`]}),(0,$.jsx)(`div`,{role:`group`,"aria-label":`Credential mode`,className:`flex gap-4`,children:[`personal`,`share`].map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":Y===e,disabled:n||Z,onClick:()=>Ee(e),title:Z?`Credential mode cannot change after creation`:void 0,className:`rounded-inset py-2 px-6`,style:{border:`1px solid var(--inner-border)`,color:Y===e?`var(--accent)`:`var(--text-secondary)`,background:Y===e?`var(--accent-soft)`:`var(--surface-2)`,cursor:Z?`not-allowed`:`pointer`,opacity:Z&&Y!==e?.5:1},children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[e===`personal`?(0,$.jsx)(ze,{size:14,"aria-hidden":`true`}):(0,$.jsx)(Be,{size:14,"aria-hidden":`true`}),e===`personal`?`Personal`:`Share template`]})},e))}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:Y===`share`?`A share template does not authenticate requests. Recipients generate their own child key from its public enrollment page.`:`A personal key authenticates requests directly; its secret is shown once when created or rotated.`})]}),(0,$.jsxs)(`div`,{className:`columns-2 gap-6 min-w-0 max-medium:columns-1`,children:[e===`create`&&(0,$.jsxs)(`section`,{className:`flex flex-col gap-4 min-w-0 p-6 border border-inner-border rounded-card bg-surface-2 break-inside-avoid mb-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`inline-flex items-center gap-2 text-body font-bold text-text-primary`,children:[(0,$.jsx)(u,{size:16,className:`text-accent`,"aria-hidden":`true`}),`Identity`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Give this credential a recognizable name.`})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 items-start min-w-0 max-medium:grid-cols-1`,children:[(0,$.jsx)(W,{label:`Name`,value:o,onChange:e=>c(e.target.value),placeholder:`ci-key…`,disabled:n,autoFocus:!0}),(0,$.jsx)(W,{label:`Key prefix`,value:d,onChange:e=>p(e.target.value),placeholder:`carte_ (default)…`,disabled:n||m.trim().length>0})]}),Y===`personal`&&(0,$.jsx)(W,{label:`Custom API key value (optional)`,value:m,onChange:e=>h(e.target.value),placeholder:`Leave blank to generate…`,disabled:n})]}),e===`edit`&&(0,$.jsxs)(`section`,{className:`flex flex-col gap-4 min-w-0 p-6 border border-inner-border rounded-card bg-surface-2 break-inside-avoid mb-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`text-body font-bold text-text-primary`,children:[(0,$.jsx)(u,{size:16,className:`mr-2 inline text-accent`,"aria-hidden":`true`}),`Identity`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:t?.isDefault?`The default key's name is fixed. Limits, access, and everything else can still change.`:`Update the label for this credential.`})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-2 gap-4 items-start min-w-0 max-medium:grid-cols-1`,children:(0,$.jsx)(W,{label:`Name`,value:o,onChange:e=>c(e.target.value),placeholder:`ci-key…`,disabled:n||t?.isDefault===!0,title:t?.isDefault?`The default gateway key keeps its name`:void 0,autoFocus:!0})})]}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-4 min-w-0 p-6 border border-inner-border rounded-card bg-surface-2 break-inside-avoid mb-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`text-body font-bold text-text-primary`,children:[(0,$.jsx)(ne,{size:16,className:`mr-2 inline text-accent`,"aria-hidden":`true`}),`Share notes`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Optional copy shown on the public share page.`})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 items-start min-w-0 max-medium:grid-cols-1`,children:[(0,$.jsx)(W,{label:`Title`,value:fe,onChange:e=>L(e.target.value),placeholder:`e.g. Bansos Token`,disabled:n}),(0,$.jsx)(W,{label:`Subtitle`,value:R,onChange:e=>z(e.target.value),placeholder:`e.g. Come and save your tokens`,disabled:n}),(0,$.jsx)(W,{label:`Body`,value:B,onChange:e=>me(e.target.value),placeholder:`Free-form notes for the recipient`,disabled:n})]})]}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-4 min-w-0 p-6 border border-inner-border rounded-card bg-surface-2 break-inside-avoid mb-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`text-body font-bold text-text-primary`,children:[(0,$.jsx)(C,{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)(W,{label:`Requests per minute`,type:`number`,min:`0`,value:g,onChange:e=>y(e.target.value),placeholder:`Unlimited…`,disabled:n}),(0,$.jsx)(W,{label:`Max concurrent requests`,type:`number`,min:`0`,value:O,onChange:e=>k(e.target.value),placeholder:`Unlimited…`,disabled:n})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-6 rounded-panel border border-inner-border px-6 py-5 bg-surface-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`text-caption font-bold text-text-primary`,children:[(0,$.jsx)(C,{size:14,className:`mr-2 inline text-accent`,"aria-hidden":`true`}),`Token budget`]}),(0,$.jsx)(`p`,{className:`mt-1 text-text-tertiary text-micro`,children:X?`One-time cap; it does not reset.`:`Daily and monthly limits reset automatically.`})]}),(0,$.jsxs)(`div`,{className:`flex gap-2 rounded-inset border border-inner-border bg-surface-1 p-1`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>D(`recurring`),disabled:n,className:`py-2 px-5 rounded-chip font-semibold border-0 cursor-pointer`,style:{fontSize:`10.5px`,background:X?`transparent`:`var(--accent-soft)`,color:X?`var(--text-tertiary)`:`var(--accent)`},children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(Me,{size:13,"aria-hidden":`true`}),`Recurring`]})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>D(`one-time`),disabled:n,className:`py-2 px-5 rounded-chip font-semibold border-0 cursor-pointer`,style:{fontSize:`10.5px`,background:X?`var(--accent-soft)`:`transparent`,color:X?`var(--accent)`:`var(--text-tertiary)`},children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(je,{size:13,"aria-hidden":`true`}),`One-time`]})})]})]}),X?(0,$.jsx)(Ze,{label:`One-time token limit`,value:T,onChange:E,disabled:n}):(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 items-start min-w-0 max-medium:grid-cols-1`,children:[(0,$.jsx)(Ze,{label:`Daily token limit`,value:b,onChange:x,disabled:n}),(0,$.jsx)(Ze,{label:`Monthly token limit`,value:S,onChange:w,disabled:n})]})]})]}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-4 min-w-0 p-6 border border-inner-border rounded-card bg-surface-2 col-span-full`,"aria-labelledby":`share-popup-heading`,children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{id:`share-popup-heading`,className:`text-body font-bold text-text-primary`,children:[(0,$.jsx)(Fe,{size:16,className:`mr-2 inline text-accent`,"aria-hidden":`true`}),`Share page popup`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Optional card visitors open from the Base URL card on your share page.`})]}),(0,$.jsx)(G,{checked:V,onChange:e=>H(e),disabled:n,label:`Enable popup`})]}),V?(0,$.jsxs)(`div`,{className:`flex gap-7 items-start mt-2 min-w-0 max-medium:flex-col max-medium:items-stretch`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 min-w-0 w-100 shrink-0 max-medium:w-auto`,children:[xe?(0,$.jsx)(`img`,{className:`block w-full h-66 object-cover border border-inner-border rounded-control bg-surface-1 max-medium:h-80`,src:xe,alt:`Popup image preview`}):(0,$.jsx)(`div`,{className:`flex items-center justify-center w-full h-66 object-cover border border-dashed border-inner-border rounded-control bg-surface-1 text-text-tertiary text-badge max-medium:h-80`,"aria-hidden":`true`,children:(0,$.jsx)(`span`,{children:`No image`})}),(0,$.jsx)(he,{id:`share-popup-image`,accept:He.join(`,`),"aria-label":`Popup image`,disabled:n,onChange:e=>{let t=e.target.files?.[0];if(e.target.value=``,!t)return;if(J(null),t.size>2097152){K(null),J(`Image must be 2 MB or smaller.`);return}let n=new FileReader;n.onload=()=>{K(String(n.result)),_e(!1)},n.onerror=()=>J(`Could not read that file.`),n.readAsDataURL(t)}}),xe?(0,$.jsx)(_,{variant:`secondary`,size:`sm`,type:`button`,disabled:n,className:`h-14 px-5 text-badge self-start`,onClick:()=>{K(null),_e(!0),J(null)},children:`Remove image`}):null,ve?(0,$.jsx)(`p`,{className:`form-error`,children:ve}):null,(0,$.jsx)(`p`,{className:`m-0 text-text-tertiary text-badge leading-normal`,children:`PNG, JPEG, WebP, or GIF up to 2 MB.`})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 min-w-0 flex-1 [&_.form-group]:gap-2`,children:[(0,$.jsx)(W,{label:`Popup title`,value:Se,onChange:e=>Ce(e.target.value),maxLength:120,placeholder:`Support this gateway`,disabled:n}),(0,$.jsxs)(`div`,{className:`form-group`,children:[(0,$.jsx)(`label`,{className:`form-label`,htmlFor:`share-popup-copy`,children:`Message`}),(0,$.jsx)(`textarea`,{className:`form-textarea`,id:`share-popup-copy`,value:we,onChange:e=>Te(e.target.value),maxLength:1200,rows:3,placeholder:`If this service helps you, consider supporting its upkeep…`,disabled:n})]})]})]}):null]}),(0,$.jsxs)(`details`,{className:`group min-w-0 col-span-full rounded-card border border-inner-border bg-surface-2`,children:[(0,$.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-4 p-6 [&::-webkit-details-marker]:hidden`,children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 items-start gap-3`,children:[(0,$.jsx)(`span`,{className:`grid size-10 shrink-0 place-items-center rounded-inset bg-accent-soft text-accent`,children:(0,$.jsx)(oe,{size:18,"aria-hidden":`true`})}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block text-body font-bold text-text-primary`,children:`Access`}),(0,$.jsx)(`span`,{className:`mt-1 block text-badge text-text-tertiary`,children:t?.isDefault?`Default gateway key · all tenant permissions, including gateway routing and remote debugging.`:`Choose model, router, and dashboard permissions for this key.`})]})]}),(0,$.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-2 rounded-control border border-inner-border bg-surface-1 px-3 py-2 text-micro font-semibold text-text-secondary`,children:[A.length,`/`,Ve.length,` grants`,(0,$.jsx)(f,{size:14,className:`transition-transform group-open:rotate-180`,"aria-hidden":`true`})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-5 border-t border-inner-border p-6`,children:[t?.isDefault?(0,$.jsxs)(`div`,{className:`flex items-start gap-3 rounded-control border border-accent/30 bg-accent-soft p-4 text-badge text-text-secondary`,children:[(0,$.jsx)(ae,{size:16,className:`mt-0.5 shrink-0 text-accent`,"aria-hidden":`true`}),(0,$.jsxs)(`p`,{className:`m-0`,children:[`This default API key is provisioned with every tenant permission, including `,(0,$.jsx)(`code`,{children:`routing:invoke`}),` and`,` `,(0,$.jsx)(`code`,{children:`routing:cli_mapping`}),`. Those grant gateway access and authorization to use remote CLI mappings; each client's mapping toggle below still controls whether those routes are active. You can remove individual grants here.`]})]}):null,(0,$.jsxs)(`div`,{className:`columns-2 gap-6 min-w-0 max-medium:columns-1`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`label`,{className:`inline-flex items-center gap-2 text-badge font-semibold text-text-secondary block mb-3`,children:[(0,$.jsx)(l,{size:14,className:`text-accent`,"aria-hidden":`true`}),`Model access`]}),(0,$.jsx)(`div`,{role:`group`,"aria-label":`Model access mode`,className:`flex gap-3 mb-4`,children:[`whitelist`,`blacklist`].map(e=>(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":j===e,disabled:n,onClick:()=>ie(e),title:e===`whitelist`?`Only the listed models may be used. An empty list allows every model.`:`The listed models are refused. Everything else is allowed.`,className:`flex-1 py-2.5 px-4 text-badge font-semibold`,style:{borderRadius:`7px`,border:`1px solid ${j===e?`var(--accent)`:`var(--inner-border)`}`,background:j===e?`var(--accent-soft)`:`var(--surface-2)`,color:j===e?`var(--accent)`:`var(--text-secondary)`,cursor:n?`not-allowed`:`pointer`,opacity:n?.6:1},children:[e===`whitelist`?`Whitelist`:`Blacklist`,e===`whitelist`?(0,$.jsx)(ae,{size:13,className:`ml-2 inline`,"aria-hidden":`true`}):(0,$.jsx)(Le,{size:13,className:`ml-2 inline`,"aria-hidden":`true`})]},e))}),(0,$.jsx)(`label`,{className:`text-badge font-semibold text-text-secondary block mb-3`,children:j===`whitelist`?`Allowed models`:`Blocked models`}),(0,$.jsx)(`div`,{className:`flex gap-3 flex-wrap mb-4`,children:N.length===0?(0,$.jsx)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:j===`whitelist`?`All models allowed`:`No models blocked`}):N.map(e=>(0,$.jsxs)(`span`,{className:`font-mono tabular-nums inline-flex items-center gap-2 text-badge bg-accent-soft text-accent py-1 px-4 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)(_,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>ce(!0),disabled:n,children:`Browse models`}),(0,$.jsx)(ge,{open:P,onClose:()=>ce(!1),selected:N,onToggle:e=>se(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),title:j===`whitelist`?`Select allowed models`:`Select blocked models`,multi:!0})]}),(0,$.jsxs)(`section`,{"aria-labelledby":`blocked-routers-heading`,className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h4`,{id:`blocked-routers-heading`,className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(s,{size:15,className:`text-accent`,"aria-hidden":`true`}),`Blocked client routers`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Matching fingerprints are rejected with 403 before routing. Detection is best-effort; clients without a fingerprint are not matched. This may also block bazaar probe links that share the same fingerprint.`})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:ue.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-6 py-2 px-5 rounded-inset`,style:{minHeight:`44px`,border:`1px solid var(--inner-border)`,background:I.includes(e.id)?`var(--accent-soft)`:`var(--surface-1)`},children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,$.jsx)(s,{size:15,className:`mt-1 shrink-0 text-orange`,"aria-hidden":`true`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`text-caption text-text-primary`,children:[`Block `,e.label,` Client`]}),(0,$.jsxs)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Reject requests fingerprinted as `,e.label,`.`]})]})]}),(0,$.jsx)(G,{checked:I.includes(e.id),onChange:t=>de(n=>t?[...n,e.id]:n.filter(t=>t!==e.id)),disabled:n,"aria-label":`Block ${e.label} client`})]},e.id))})]}),(0,$.jsxs)(`section`,{"aria-labelledby":`routing-scopes-heading`,className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`h4`,{id:`routing-scopes-heading`,className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(M,{size:15,className:`text-accent`,"aria-hidden":`true`}),`Routing`]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:Ve.filter(e=>e===`routing:invoke`).map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-6 py-2 px-5 rounded-inset`,style:{minHeight:`44px`,border:`1px solid var(--inner-border)`,background:A.includes(e)?`var(--accent-soft)`:`var(--surface-1)`},children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(M,{size:16,className:`mt-1 shrink-0 text-accent`,"aria-hidden":`true`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-caption font-semibold text-text-primary`,children:e}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:Ue[e]})]})]}),(0,$.jsx)(G,{checked:A.includes(e),onChange:()=>Oe(e),disabled:n,"aria-label":`Grant ${e}`})]},e))})]}),(0,$.jsx)($e,{keyId:e===`edit`&&t?t.id:``,busy:n,scopeGranted:A.includes(`routing:cli_mapping`),onScopeChange:e=>{e!==A.includes(`routing:cli_mapping`)&&Oe(`routing:cli_mapping`)},persistScope:n=>{if(e!==`edit`||!t)return;let r=n?[...new Set([...A,`routing:cli_mapping`])]:A.filter(e=>e!==`routing:cli_mapping`);De.mutate({keyId:t.id,request:{scopes:r}},{onError:e=>v.error(F(e,`Could not update the key's routing scope.`))})}}),(0,$.jsxs)(`section`,{"aria-labelledby":`dashboard-scopes-heading`,className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`h4`,{id:`dashboard-scopes-heading`,className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(pe,{size:15,className:`text-accent`,"aria-hidden":`true`}),`Dashboard / Resources`]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:Ve.filter(e=>!e.startsWith(`routing:`)).map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-6 py-2 px-5 rounded-inset`,style:{minHeight:`44px`,border:`1px solid var(--inner-border)`,background:A.includes(e)?`var(--accent-soft)`:`var(--surface-1)`},children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(()=>{let t=We[e];return(0,$.jsx)(t,{size:16,className:`mt-1 shrink-0 text-accent`,"aria-hidden":`true`})})(),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-caption font-semibold text-text-primary`,children:e}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:Ue[e]})]})]}),(0,$.jsx)(G,{checked:A.includes(e),onChange:()=>Oe(e),disabled:n,"aria-label":`Grant ${e}`})]},e))})]})]})]})]})]})}function it({secret:e,onClose:t}){return(0,$.jsx)(k,{open:e!==null,onClose:t,title:`New API key`,description:`Copy it now, or reveal it again later from the key's Share button.`,size:`md`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,$.jsx)(`p`,{className:`text-body text-text-secondary m-0 leading-normal`,children:`A personal key stays recoverable. Open the key's Share button and choose Reveal to see it again and copy it. Rotating the key replaces this secret, and any client still using it starts getting 401s.`}),(0,$.jsx)(`code`,{className:`block rounded-inset border border-inner-border bg-surface-1 py-5 px-6 text-caption text-text-primary break-all`,children:e}),(0,$.jsxs)(`div`,{className:`flex gap-4 flex-wrap`,children:[(0,$.jsx)(O,{value:e??``,size:`sm`,variant:`primary`,label:`Copy key`,copiedLabel:`Copied`}),(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(b,{size:13}),onClick:()=>{e!==null&&(me(`cartethyia-api-key.txt`,`Cartethyia API key\n\n${e}\n\nKeep this secret. Reveal it again from the key's Share button.\n`,`text/plain;charset=utf-8`),v.success(`Key saved to your downloads.`))},children:`Save this key`})]})]})})}function at(e){let t=new Date(e);if(!Number.isFinite(t.getTime()))return`—`;let n=e-Date.now(),r=t.toLocaleString();if(n<=0)return`${r} (lapsed)`;let i=Math.ceil(n/6e4);if(i<60)return`${r} (in ${i}m)`;let a=Math.floor(i/60);return a<24?`${r} (in ${a}h)`:`${r} (in ${Math.floor(a/24)}d)`}function ot({onClose:e}){let t=o(!0),n=c(),[r,i]=(0,Q.useState)(null),a=t.data??[];return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(k,{open:!0,onClose:e,title:`Banned Users`,description:`A client address is banned after repeated invalid-model requests. The ban applies to every API key used from that address, not just one credential.`,size:`lg`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-7 min-w-0`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`h4`,{className:`text-caption font-semibold text-text-secondary mb-4`,children:[`Active bans (`,a.length,`)`]}),t.isPending?(0,$.jsx)(E,{label:`Loading banned users…`}):t.isError?(0,$.jsx)(T,{message:F(t.error,`Could not load banned users.`),onRetry:()=>void t.refetch()}):a.length===0?(0,$.jsx)(ee,{title:`No banned users`,message:`No client address is currently banned for model abuse.`,icon:(0,$.jsx)(Ie,{size:20})}):(0,$.jsx)(`div`,{className:`rounded-inset border border-inner-border`,children:(0,$.jsx)(ke,{maxHeight:480,scrollRegion:!0,headers:[`Client IP`,`Reason`,`Applies to`,`Lapses`,``],children:a.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`font-mono tabular-nums text-badge text-text-primary whitespace-nowrap`,children:e.ip}),(0,$.jsx)(`td`,{className:`text-badge text-text-secondary`,children:e.reason===`repeated_invalid_model_requests`?`Repeated invalid-model requests`:e.reason}),(0,$.jsx)(`td`,{className:`text-badge text-text-secondary whitespace-nowrap`,children:`All API keys from this IP`}),(0,$.jsx)(`td`,{className:`text-badge text-text-secondary whitespace-nowrap`,children:at(e.expiresAt)}),(0,$.jsx)(`td`,{className:`text-right whitespace-nowrap`,children:(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(Re,{size:13}),disabled:n.isPending,onClick:()=>i(e),children:`Unban`})})]},e.ip))})})]}),(0,$.jsx)(q,{justify:`flex-end`,gap:`0px`,children:(0,$.jsx)(_,{variant:`secondary`,size:`sm`,onClick:e,children:`Close`})})]})}),(0,$.jsx)(I,{open:r!==null,onClose:()=>i(null),onConfirm:async()=>{r&&(await n.mutateAsync(r.ip),v.success(`Unbanned ${r.ip}.`),i(null))},title:`Lift this ban?`,message:r?`Lift the ban on ${r.ip}? The address can reach the gateway again immediately.`:`Lift this ban?`,confirmLabel:`Unban`,danger:!0})]})}var st=e=>(e??0).toLocaleString(),ct=e=>e?new Date(e).toLocaleString():`—`;function lt({keyId:e}){let t=_e(),[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(!1);return(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-4 rounded-control border border-inner-border bg-surface-2 px-5 py-4 text-text-tertiary`,children:[(0,$.jsx)(`code`,{title:i&&n?n:void 0,className:`min-w-0 flex-auto overflow-hidden font-mono text-caption text-text-primary text-ellipsis whitespace-nowrap`,children:i&&n?n:`••••••••••••••••`}),(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:i?(0,$.jsx)(x,{size:13}):(0,$.jsx)(S,{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=>v.error(F(e,`Could not reveal the key.`))})},children:i?`Hide`:`Reveal`}),i&&n?(0,$.jsx)(O,{value:n,size:`sm`,variant:`secondary`,label:`Copy`,copiedLabel:`Copied`}):null]})}function ut({label:e,value:t}){return(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 basis-60 rounded-control border border-inner-border bg-surface-2 px-5 py-3`,children:[(0,$.jsx)(`dt`,{className:`text-badge font-normal tracking-label text-text-tertiary uppercase`,children:e}),(0,$.jsx)(`dd`,{className:`mt-1 text-caption font-normal text-text-primary tabular-nums`,children:t==null?`Unlimited`:st(t)})]})}function dt(e){return e?{title:`Regenerate this key?`,message:`This rotates the key credential. Any client still using the current secret starts getting 401s immediately, and the old secret cannot be recovered. The handoff link is re-pointed to reveal the new key.`,confirmLabel:`Regenerate key`}:{title:`Regenerate this link?`,message:`This replaces the link URL; the current URL stops resolving immediately. Recipients keep the keys they already generated and keep working — but no one can enroll through the old link again.`,confirmLabel:`Regenerate link`}}function ft({consumed:e,budget:t}){let n=t==null||t<=0,r=n?100:Math.min(100,e/t*100),i=!n&&e>=t;return(0,$.jsxs)(`div`,{className:`grid flex-auto basis-full gap-2.5 rounded-control border border-inner-border bg-surface-2 px-5 py-3.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 text-badge tracking-label text-text-tertiary uppercase`,children:[(0,$.jsx)(`span`,{children:`Lifetime budget`}),(0,$.jsx)(`span`,{className:`text-caption font-normal text-text-primary tabular-nums normal-case tracking-normal`,children:n?`${V(e)} · Unlimited`:`${V(e)} / ${V(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?`${V(e)} tokens consumed, no lifetime budget set`:`${V(e)} of ${V(t)} tokens consumed`,children:(0,$.jsx)(`div`,{className:i?`h-full rounded bg-status-danger`:`h-full rounded bg-status-success`,style:{width:`${r}%`}})})]})}function pt(e){return e.filter(e=>e.revokedAt===null).length}function mt(e){return e.reduce((e,t)=>e+t.allTime.totalTokens,0)}function ht({consumed:e,budget:t}){if(t==null)return(0,$.jsx)(`div`,{className:`grid flex-auto basis-full gap-2.5 rounded-control border border-inner-border bg-surface-2 px-5 py-3.5`,children:(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 text-badge tracking-label text-text-tertiary uppercase`,children:[(0,$.jsx)(`span`,{children:`Total quota used`}),(0,$.jsx)(`span`,{className:`text-caption font-normal text-text-primary tabular-nums normal-case tracking-normal`,children:V(e)})]})});let n=t>0?Math.min(100,e/t*100):0,r=t>0?Math.max(0,100-e/t*100):100,i=Math.max(0,t-e),a=Ae(e>=t?0:r),o=e>=t;return(0,$.jsxs)(`div`,{className:`grid flex-auto basis-full gap-2.5 rounded-control border border-inner-border bg-surface-2 px-5 py-3.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 text-badge tracking-label text-text-tertiary uppercase`,children:[(0,$.jsx)(`span`,{children:`Total quota`}),(0,$.jsxs)(`span`,{className:`text-caption font-normal text-text-primary tabular-nums normal-case tracking-normal`,children:[V(e),` / `,V(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`:`${V(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":`${V(e)} of ${V(t)} tokens consumed`,children:(0,$.jsx)(`div`,{className:o?`h-full rounded bg-status-danger`:`h-full rounded`,style:{width:`${n}%`,background:o?void 0:a.bar}})})]})}function gt({parentId:e,childId:t}){let n=Ee(e,t);if(n.isPending)return(0,$.jsx)(E,{label:`Loading activity…`,compact:!0});if(n.isError)return(0,$.jsx)(T,{compact:!0,message:F(n.error,`Could not load activity.`),onRetry:()=>void n.refetch()});let r=n.data;return r?(0,$.jsxs)(`div`,{className:`grid min-w-0 gap-6 border-t border-inner-border bg-surface-1 px-6 py-5`,children:[(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h4`,{className:`mb-3 text-caption font-bold text-text-primary`,children:`Top models`}),r.models.length?(0,$.jsx)(`div`,{className:`data-table-container`,children:(0,$.jsxs)(`table`,{className:`data-table text-caption`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`col`,children:`Model`}),(0,$.jsx)(`th`,{scope:`col`,children:`Today`}),(0,$.jsx)(`th`,{scope:`col`,children:`Errors`}),(0,$.jsx)(`th`,{scope:`col`,children:`Tokens`})]})}),(0,$.jsx)(`tbody`,{children:r.models.map((e,t)=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:e.modelId}),(0,$.jsx)(`td`,{children:st(e.todayRequests)}),(0,$.jsx)(`td`,{children:st(e.todayErrors)}),(0,$.jsx)(`td`,{children:V(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:V(e.totalTokens)}),(0,$.jsx)(`td`,{children:ct(e.startedAt)})]},e.requestId))})]})}):(0,$.jsx)(`p`,{className:`py-3 text-caption text-text-tertiary`,children:`No recent requests.`})]})]}):null}function _t({parent:e,onSecretRevealed:t}){let[n,r]=(0,Q.useState)(null),i=ve(),a=we(),o=Te(),s=xe(e.id),c=e.keyMode!==`share`,l=J(c?null:e.id),u=l.data??[];(0,Q.useEffect)(()=>{r(null)},[e.id]);let d=i.isPending||a.isPending,[p,h]=(0,Q.useState)(!1),g=async()=>{if(c){let n=await a.mutateAsync({keyId:e.id});t?.(n.secret);return}await i.mutateAsync({keyId:e.id,regenerate:!0}),v.success(`Link regenerated; the previous URL no longer works.`)},y=()=>{i.mutate({keyId:e.id},{onError:e=>v.error(F(e,`Could not create link.`))})},b=s.data?.url??null,x=dt(c);return(0,$.jsxs)(`div`,{className:`grid min-w-0 gap-6`,children:[(0,$.jsx)(`section`,{"aria-label":`Link`,children:s.isPending?(0,$.jsx)(E,{label:`Loading link…`,compact:!0}):s.isError?(0,$.jsx)(T,{compact:!0,message:F(s.error,`Could not load the link.`),onRetry:()=>void s.refetch()}):b?(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-4 rounded-control border border-inner-border bg-surface-2 px-5 py-4 text-text-tertiary`,children:[(0,$.jsx)(D,{size:14,"aria-hidden":`true`,className:`shrink-0`}),(0,$.jsx)(`code`,{title:b,className:`min-w-0 flex-auto overflow-hidden font-mono text-caption text-text-primary text-ellipsis whitespace-nowrap`,children:b}),(0,$.jsx)(O,{value:b,size:`sm`,variant:`secondary`,label:`Copy`,copiedLabel:`Copied`}),(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(Ne,{size:13}),loading:d,disabled:d,onClick:()=>h(!0),children:`Regenerate`})]}):(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-4 rounded-control border border-inner-border bg-surface-2 px-5 py-4 text-text-tertiary`,children:[(0,$.jsx)(D,{size:14,"aria-hidden":`true`,className:`shrink-0`}),(0,$.jsx)(`span`,{className:`flex-auto text-caption text-text-tertiary`,children:`No link yet.`}),(0,$.jsx)(_,{variant:`primary`,size:`sm`,loading:d,disabled:d,onClick:y,children:`Create link`})]})}),c?(0,$.jsxs)(`section`,{"aria-label":`API key`,className:`grid gap-3`,children:[(0,$.jsx)(`div`,{className:`flex items-center justify-between gap-4`,children:(0,$.jsx)(`strong`,{className:`text-caption`,children:`API key`})}),(0,$.jsx)(lt,{keyId:e.id})]}):null,c?(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:V(e.tokensConsumed)})]}),(0,$.jsx)(ut,{label:`Requests / min`,value:e.requestsPerMinute}),(0,$.jsx)(ut,{label:`Daily tokens`,value:e.dailyTokenLimit}),(0,$.jsx)(ut,{label:`Monthly tokens`,value:e.monthlyTokenLimit}),(0,$.jsx)(ft,{consumed:e.tokensConsumed,budget:e.lifetimeTokenBudget})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`section`,{"aria-label":`Total quota`,className:`grid gap-3`,children:[(0,$.jsx)(`div`,{className:`flex items-center justify-between gap-4`,children:(0,$.jsx)(`strong`,{className:`text-caption`,children:`Total quota`})}),(0,$.jsx)(ht,{consumed:mt(u),budget:e.lifetimeTokenBudget})]}),(0,$.jsxs)(`section`,{"aria-label":`Recipients`,className:`grid gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsx)(`strong`,{className:`text-caption`,children:`Recipients`}),(0,$.jsxs)(`span`,{className:`mr-2 ml-auto text-caption text-text-tertiary tabular-nums`,children:[`Active users: `,pt(u)]}),(0,$.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>void l.refetch(),icon:(0,$.jsx)(j,{size:13,className:l.isFetching?`animate-spin`:void 0}),children:`Refresh`})]}),l.isPending&&!l.data?(0,$.jsx)(E,{label:`Loading recipients…`,compact:!0}):l.isError?(0,$.jsx)(T,{compact:!0,message:F(l.error,`Could not load recipients.`),onRetry:()=>void l.refetch()}):u.length===0?(0,$.jsx)(ee,{compact:!0,title:`No recipients yet`,message:`Keys generated through this link appear here with their masked client IP and token usage.`}):(0,$.jsx)(`div`,{className:`data-table-container max-h-[46vh]`,children:(0,$.jsxs)(`table`,{className:`data-table text-caption`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`col`,className:`w-12`,"aria-label":`Expand`}),(0,$.jsx)(`th`,{scope:`col`,children:`Key`}),(0,$.jsx)(`th`,{scope:`col`,children:`Status`}),(0,$.jsx)(`th`,{scope:`col`,children:`Today`}),(0,$.jsx)(`th`,{scope:`col`,children:`Lifetime`}),(0,$.jsx)(`th`,{scope:`col`,children:`Last activity`}),(0,$.jsx)(`th`,{scope:`col`,className:`text-right whitespace-nowrap`,children:`Actions`})]})}),(0,$.jsx)(`tbody`,{children:u.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)(f,{size:14}):(0,$.jsx)(m,{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:V(t.today.totalTokens)}),(0,$.jsx)(`td`,{children:V(t.allTime.totalTokens)}),(0,$.jsx)(`td`,{children:ct(t.lastUsedAt)}),(0,$.jsx)(`td`,{className:`text-right whitespace-nowrap`,children:(0,$.jsx)(_,{variant:`danger`,size:`sm`,disabled:o.isPending||!!t.revokedAt,onClick:()=>o.mutate({parentKeyId:e.id,childKeyId:t.id},{onError:e=>v.error(F(e,`Could not revoke key.`))}),children:`Revoke`})})]}),i?(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:7,className:`p-0`,children:(0,$.jsx)(gt,{parentId:e.id,childId:t.id})})}):null]},t.id)})})]})})]})]}),(0,$.jsx)(I,{open:p,onClose:()=>h(!1),onConfirm:g,title:x.title,message:x.message,confirmLabel:x.confirmLabel,danger:!0})]})}function vt({parent:e,onClose:t,onSecretRevealed:n}){let r=e.keyMode!==`share`;return(0,$.jsx)(k,{open:!0,onClose:t,title:`Sharing — ${e.label||`API key`}`,description:r?`One stable handoff link for this key. Regenerating rotates the key itself.`:`One stable enrollment link. Regenerating replaces the URL; recipients keep the keys they already generated.`,size:`lg`,children:(0,$.jsx)(_t,{parent:e,onSecretRevealed:n})})}function yt(){let e=Y(),t=de(),n=Se(),r=ye(),i=Ce(),a=we(),o=_e(),s=be(),{copy:c}=B(),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)(null),[g,b]=(0,Q.useState)(null),[x,S]=(0,Q.useState)(null),[C,w]=(0,Q.useState)(null),[ne,D]=(0,Q.useState)(!1),[O,j]=(0,Q.useState)(null),[M,ie]=(0,Q.useState)(null),ae=e.data??[],N=t.data?.isPlatformAdmin??!1,oe=e=>{S(null),w(e)},se=async e=>{try{let{secret:t}=await o.mutateAsync({keyId:e.id});await c(t)?v.success(`API key copied`):v.error(`Clipboard unavailable on this origin`)}catch(e){v.error(F(e,`Could not reveal API key.`))}},P=dt(!0);return(0,$.jsxs)(z,{children:[(0,$.jsx)(R,{title:`API Credentials`,subtitle:`Manage tenant API keys, model access, budgets, and sharing.`,icon:(0,$.jsx)(te,{size:16}),action:(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[N?(0,$.jsx)(_,{variant:`secondary`,size:`sm`,onClick:()=>D(!0),icon:(0,$.jsx)(Ie,{size:13}),children:`Banned Users`}):null,(0,$.jsx)(_,{variant:`primary`,size:`sm`,onClick:()=>{S(null),u(!0)},icon:(0,$.jsx)(re,{size:13}),children:`Create Key`})]})}),(0,$.jsx)(L,{children:e.isPending&&!e.data?(0,$.jsx)(E,{label:`Loading API keys…`}):e.isError&&!e.data?(0,$.jsx)(T,{message:F(e.error,`Could not load credentials.`),onRetry:()=>void e.refetch()}):ae.length===0?(0,$.jsx)(ee,{title:`No API keys issued`,message:`Generate a secret key to authenticate your SDK or CLI client against the gateway.`,icon:(0,$.jsx)(te,{size:20})}):(0,$.jsx)(`div`,{className:`scroll-region max-h-280 pr-1`,children:(0,$.jsx)(h,{items:ae,label:`API credentials`,disabled:s.isPending,onReorder:e=>s.mutate(e,{onError:e=>v.error(F(e,`Could not save the new order.`))}),renderItem:e=>(0,$.jsxs)(`div`,{className:`api-key-card flex items-start justify-between gap-6 px-6 py-4 rounded-chip border border-inner-border bg-surface-2 max-medium:flex-col max-medium:items-stretch max-medium:gap-4 max-medium:p-5 [&>div:last-child]:flex-wrap`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,$.jsx)(`strong`,{className:`text-body`,children:e.label||`Unnamed credential`}),(0,$.jsx)(U,{tone:e.revokedAt?`err`:e.enabled?`ok`:`warn`,children:e.revokedAt?`revoked`:e.enabled?`enabled`:`disabled`}),(0,$.jsx)(U,{tone:e.keyMode===`share`?`accent`:`default`,children:e.keyMode===`share`?`share template`:`personal`}),e.isDefault?(0,$.jsx)(U,{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`}),V(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`}),H(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`}),H(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`}),H(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`}),H(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`}),H(e.maxConcurrentRequests)]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap max-medium:justify-between`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:e.modelAccessMode===`blacklist`?`Blocked`:`Models`}),e.modelAccessMode===`blacklist`?e.modelList?.length??0:e.modelList?.length?e.modelList.length:`All`]})]})]}),(0,$.jsxs)(`div`,{className:`flex gap-3 shrink-0 flex-wrap`,children:[e.revokedAt?null:(0,$.jsx)(G,{checked:e.enabled,disabled:r.isPending,id:`api-key-enabled-${e.id}`,label:``,"aria-label":`${e.enabled?`Disable`:`Enable`} ${e.label||`API credential`}`,onChange:t=>r.mutate({keyId:e.id,request:{enabled:t}},{onSuccess:()=>v.success(`${e.label||`API credential`} ${t?`enabled`:`disabled`}`),onError:e=>v.error(F(e,`Could not update credential state.`))})}),(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(A,{size:13}),onClick:()=>{S(null),f(e)},children:`Edit`}),!e.revokedAt&&e.keyMode!==`share`?(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(y,{size:13}),onClick:()=>void se(e),disabled:o.isPending,children:`Copy`}):null,!e.revokedAt&&(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(Fe,{size:13}),onClick:()=>oe(e),children:e.keyMode===`share`?`Recipients`:`Share`}),!e.revokedAt&&e.keyMode!==`share`&&(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(Ne,{size:13}),onClick:()=>{S(null),b(e)},disabled:a.isPending,children:`Rotate`}),!e.revokedAt&&!e.isDefault&&(0,$.jsx)(_,{variant:`danger`,size:`sm`,icon:(0,$.jsx)(ce,{size:13}),onClick:()=>m(e),disabled:i.isPending,children:`Revoke`})]})]})})})}),(0,$.jsx)(k,{open:l,onClose:()=>u(!1),title:`Create API Key`,description:`Create a tenant-scoped credential. Choose model access, permissions, limits, and optional blocked client routers.`,size:`lg`,footer:O,children:(0,$.jsx)(rt,{mode:`create`,record:null,busy:n.isPending,onClose:()=>u(!1),actionsRef:j,onDone:e=>{n.mutate(e,{onSuccess:t=>{u(!1),S(tt(e.keyMode,t.secret)),v.success(`API key created`)},onError:e=>v.error(F(e,`Could not create API key.`))})}})}),(0,$.jsx)(k,{open:d!==null,onClose:()=>f(null),title:`Edit API Key`,description:`Update the key's model access, permissions, limits, share notes, and optional public popup.`,size:`lg`,footer:M,children:(0,$.jsx)(rt,{mode:`edit`,record:d,busy:r.isPending,onClose:()=>f(null),actionsRef:ie,onDone:e=>{d&&r.mutate({keyId:d.id,request:e},{onSuccess:t=>{f(null),S(tt(e.keyMode,t.secret)),v.success(`API key updated`)},onError:e=>v.error(F(e,`Could not update API key.`))})}})}),C?(0,$.jsx)(vt,{parent:C,onClose:()=>w(null),onSecretRevealed:e=>{w(null),S(e)}}):null,(0,$.jsx)(I,{open:g!==null,onClose:()=>b(null),onConfirm:async()=>{if(!g)return;let e=await a.mutateAsync({keyId:g.id});S(e.secret),v.success(`Rotated ${g.label||g.id}.`),b(null)},title:P.title,message:P.message,confirmLabel:P.confirmLabel,danger:!0}),(0,$.jsx)(I,{open:p!==null,onClose:()=>m(null),onConfirm:async()=>{p&&(await i.mutateAsync(p.id),v.success(`Revoked ${p.label||p.id}.`),m(null))},title:`Revoke API key?`,message:p?`Revoke ${p.label||p.id}? Clients using it will be rejected.${p.keyMode===`share`?` All child keys and enrollment links will also be revoked.`:``}`:`Revoke this API key?`,confirmLabel:`Revoke`,danger:!0}),ne?(0,$.jsx)(ot,{onClose:()=>D(!1)}):null,(0,$.jsx)(it,{secret:x,onClose:()=>S(null)})]})}function bt(){let e=se(),t=N(),n=e.data;if(e.isPending)return(0,$.jsx)(E,{label:`Loading compression settings…`});if(e.isError||!n)return(0,$.jsx)(T,{message:F(e.error,`Failed to load compression settings`),onRetry:()=>void e.refetch()});let r=n.rtkPruneEnabled,i=n.ponyTailEnabled;return(0,$.jsxs)(z,{children:[(0,$.jsx)(R,{title:`Compression`,subtitle:`Shrink requests before they reach the provider`,icon:(0,$.jsx)(a,{size:16})}),(0,$.jsx)(L,{children:(0,$.jsxs)(K,{gap:`14px`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-x-8 gap-y-5`,children:[(0,$.jsxs)(`div`,{className:`flex gap-5 min-w-0 flex-auto`,children:[(0,$.jsx)(Pe,{size:16,className:`shrink-0 mt-1 text-text-secondary`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`label`,{htmlFor:`compression-rtk`,children:(0,$.jsx)(q,{gap:`6px`,className:`text-body font-semibold`,children:`Prune tool output (RTK)`})}),(0,$.jsx)(`div`,{className:`text-badge text-text-tertiary wrap-anywhere max-w-full`,children:`Compact bulky tool results (diffs, grep dumps, listings) in the message history so a long conversation stops re-sending megabytes of raw output. Higher strength compresses more aggressively.`})]})]}),(0,$.jsxs)(q,{gap:`8px`,className:`shrink-0 items-center ml-auto`,children:[(0,$.jsx)(p,{id:`compression-rtk-level`,"aria-label":`RTK strength`,value:n.rtkPruneLevel,onValueChange:e=>t.mutate({rtkPruneLevel:e===`lite`||e===`full`||e===`ultra`?e:`full`},{onError:e=>v.error(F(e,`Could not update RTK strength.`))}),options:[{value:`lite`,label:`Lite`},{value:`full`,label:`Full`},{value:`ultra`,label:`Ultra`}]}),(0,$.jsx)(G,{id:`compression-rtk`,"aria-label":`Enable RTK prune`,checked:r,onChange:e=>t.mutate({rtkPruneEnabled:e},{onError:e=>v.error(F(e,`Could not update RTK prune.`))})})]})]}),(0,$.jsxs)(`div`,{className:`flex items-start gap-x-8 gap-y-5`,children:[(0,$.jsxs)(`div`,{className:`flex gap-5 min-w-0 flex-auto`,children:[(0,$.jsx)(P,{size:16,className:`shrink-0 mt-1 text-text-secondary`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`label`,{htmlFor:`compression-ponytail`,children:(0,$.jsx)(q,{gap:`6px`,className:`text-body font-semibold`,children:`PonyTail (system directive)`})}),(0,$.jsx)(`div`,{className:`text-badge text-text-tertiary wrap-anywhere max-w-full`,children:`Appends a minimal-code directive to the system content, biasing the model toward the smallest working change. Higher strength pushes harder toward deletion over addition.`})]})]}),(0,$.jsxs)(q,{gap:`8px`,className:`shrink-0 items-center ml-auto`,children:[(0,$.jsx)(p,{id:`compression-ponytail-level`,"aria-label":`PonyTail strength`,value:n.ponyTailLevel,onValueChange:e=>t.mutate({ponyTailLevel:e===`lite`||e===`full`||e===`ultra`?e:`full`},{onError:e=>v.error(F(e,`Could not update PonyTail strength.`))}),options:[{value:`lite`,label:`Lite`},{value:`full`,label:`Full`},{value:`ultra`,label:`Ultra`}]}),(0,$.jsx)(G,{id:`compression-ponytail`,"aria-label":`Enable PonyTail`,checked:i,onChange:e=>t.mutate({ponyTailEnabled:e},{onError:e=>v.error(F(e,`Could not update PonyTail.`))})})]})]}),r||i?(0,$.jsxs)(`p`,{role:`note`,className:`flex gap-4 items-start m-0 py-4 px-5 rounded-inset border border-orange bg-orange-soft text-text-secondary text-badge`,children:[(0,$.jsx)(w,{size:14,className:`shrink-0 mt-0.5 text-orange`}),(0,$.jsx)(`span`,{children:`Your AI may produce degraded quality while compression is active: it sees a shortened history and a minimal-code directive, so fewer tokens but a chance of missing detail. Turn it off if answers get worse.`})]}):null]})})]})}function xt(){let{copied:e,copy:t}=B(2e3),n=`${window.location.origin}/v1`,r=async()=>{if(await t(n)){v.success(`Gateway endpoint copied`,n);return}v.error(`Clipboard unavailable on this origin`)};return(0,$.jsxs)(z,{children:[(0,$.jsx)(R,{title:`Gateway Endpoint`,subtitle:`Universal OpenAI & Anthropic Wire API Endpoint Compatible`,icon:(0,$.jsx)(g,{size:16})}),(0,$.jsx)(L,{children:(0,$.jsxs)(K,{gap:`10px`,children:[(0,$.jsxs)(`div`,{className:`nested-panel flex items-center gap-4 rounded-control border border-inner-border bg-code-surface px-7 py-5 font-mono text-body font-semibold tabular-nums`,children:[(0,$.jsx)(`code`,{className:`min-w-0 flex-1 truncate`,title:n,children:n}),(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:e?(0,$.jsx)(d,{size:13}):(0,$.jsx)(y,{size:13}),"aria-label":`Copy endpoint`,title:`Copy endpoint`,onClick:()=>void r(),className:`shrink-0`,children:e?`Copied`:`Copy`})]}),(0,$.jsxs)(`p`,{className:`text-caption leading-normal text-text-secondary`,children:[`Point any SDK, CLI, or agent (e.g. OpenCode, Pi, OMP, Kilo, Cline, Droid and more clients) to this same-origin base URL.`,(0,$.jsxs)(`span`,{className:`mt-1 block text-text-tertiary`,children:[`You may not put `,(0,$.jsx)(`code`,{className:`font-mono`,children:`/v1`}),` on Claude Code — the CLI appends it itself.`]})]})]})})]})}function St(){return(0,$.jsxs)(K,{gap:`16px`,children:[(0,$.jsx)(xt,{}),(0,$.jsx)(bt,{}),(0,$.jsx)(yt,{})]})}export{St as default};
1
+ import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{a as i,i as a,n as o,o as s,r as c}from"./model-bans-CSPQ9xB0.js";import{n as l,t as u}from"./fingerprint-pattern-BWuHtbW4.js";import{t as d}from"./check-D69FzdvC.js";import{n as f,t as p}from"./select-C9mMoEpJ.js";import{t as m}from"./chevron-right-BXIy5l3h.js";import{t as h}from"./SortableList-DpOTnGuH.js";import{_ as g,r as _,t as v}from"./toast-C76WrMhc.js";import{t as y}from"./copy-ngmQ9zcZ.js";import{t as b}from"./download-A0SW9OCW.js";import{t as x}from"./eye-off-Bk5g2luF.js";import{t as S}from"./eye-C_hawfH4.js";import{t as C}from"./gauge-BbIMy7MB.js";import{a as w,n as T,r as E,t as ee}from"./state-CzUPfLXo.js";import{t as te}from"./key-round-UkavsGxp.js";import{n as ne,r as D,t as O}from"./clipboard-button-R_rArH8S.js";import{t as k}from"./dialog-BWIP_EvW.js";import{t as A}from"./pencil-768ysRAr.js";import{t as re}from"./plus-DIdX_g-x.js";import{t as j}from"./refresh-cw-BqJFk4sU.js";import{t as M}from"./route-CNSNj9Zm.js";import{t as ie}from"./search-JOKus9rb.js";import{t as ae}from"./shield-check-DVS0Foqh.js";import{n as N,r as oe,t as se}from"./settings-C4_Gn_wq.js";import{t as P}from"./sparkles-BRaRUxAU.js";import{t as ce}from"./trash-Cppn5c3R.js";import{b as le,y as ue}from"./assert-7J6_LVD3.js";import{l as F}from"./query-keys-D7wX2vM5.js";import{F as I,O as de,et as fe,nt as pe}from"./entry-7dpgvpJ3.js";import{n as L,r as R,t as z}from"./card-B0Bnx5CA.js";import{t as B}from"./use-clipboard-B0Sy03fE.js";import{n as me}from"./download-dRFo5_Wu.js";import{c as V,d as H}from"./tokens-DDxMbSRL.js";import{t as U}from"./badge-BTyGk_DL.js";import{n as W,t as he}from"./input-B9oyU93y.js";import{t as ge}from"./ModelPicker-Br3CXEau.js";import{t as G}from"./switch-DOUIky_i.js";import{t as K}from"./stack-Ca5HxI5i.js";import{n as q}from"./inline-D1TCqM2D.js";import{a as _e,c as ve,d as J,f as ye,i as be,l as xe,n as Se,o as Ce,r as we,s as Te,t as Y,u as Ee}from"./api-keys-BETfaMYZ.js";import{a as X,i as Z,n as De,r as Oe}from"./cli-tools-DE2ug812.js";import{t as ke}from"./layout-BArzXirQ.js";import{s as Ae}from"./quota-DZGyp0N5.js";var je=e(`lock-keyhole`,[[`circle`,{cx:`12`,cy:`16`,r:`1`,key:`1au0dj`}],[`rect`,{x:`3`,y:`10`,width:`18`,height:`12`,rx:`2`,key:`6s8ecr`}],[`path`,{d:`M7 10V7a5 5 0 0 1 10 0v3`,key:`1pqi11`}]]),Me=e(`repeat-2`,[[`path`,{d:`m2 9 3-3 3 3`,key:`1ltn5i`}],[`path`,{d:`M13 18H7a2 2 0 0 1-2-2V6`,key:`1r6tfw`}],[`path`,{d:`m22 15-3 3-3-3`,key:`4rnwn2`}],[`path`,{d:`M11 6h6a2 2 0 0 1 2 2v10`,key:`2f72bc`}]]),Ne=e(`rotate-cw`,[[`path`,{d:`M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8`,key:`1p45f6`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}]]),Pe=e(`scissors`,[[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M8.12 8.12 12 12`,key:`1alkpv`}],[`path`,{d:`M20 4 8.12 15.88`,key:`xgtan2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M14.8 14.8 20 20`,key:`ptml3r`}]]),Fe=e(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]),Ie=e(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]),Le=e(`shield-x`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`m14.5 9.5-5 5`,key:`17q4r4`}],[`path`,{d:`m9.5 9.5 5 5`,key:`18nt4w`}]]),Re=e(`undo-2`,[[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`,key:`f3b9sd`}]]),ze=e(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]),Be=e(`users-round`,[[`path`,{d:`M18 21a8 8 0 0 0-16 0`,key:`3ypg7q`}],[`circle`,{cx:`10`,cy:`8`,r:`5`,key:`o932ke`}],[`path`,{d:`M22 20c0-3.37-2-6.5-4-8a5 5 0 0 0-.45-8.3`,key:`10s06x`}]]),Ve=[`routing:invoke`,`routing:cli_mapping`,`search:invoke`,`dashboard:read`,`dashboard:write`,`providers:read`,`providers:write`,`models:read`,`models:write`],He=[`image/png`,`image/jpeg`,`image/webp`,`image/gif`],Q=t(n(),1),$=r(),Ue={"routing:invoke":`Call /v1/* gateway routes within this tenant.`,"routing:cli_mapping":`Resolve persisted CLI source→target model mappings.`,"search:invoke":`Call POST /v1/search with exa.`,"dashboard:read":`Read this tenant's configuration and usage.`,"dashboard:write":`Modify this tenant's configuration.`,"providers:read":`Read provider rows, including accounts.`,"providers:write":`Add, modify, or delete provider rows and their credentials.`,"models:read":`Read catalog model rows.`,"models:write":`Add, modify, or delete catalog model rows.`},We={"routing:invoke":M,"routing:cli_mapping":M,"search:invoke":ie,"dashboard:read":S,"dashboard:write":A,"providers:read":fe,"providers:write":je,"models:read":l,"models:write":i},Ge={k:1e3,m:1e6,b:1e9,t:0xe8d4a51000},Ke=[{label:`1M`,amount:1e6,description:`1 million`},{label:`100M`,amount:1e8,description:`100 million`},{label:`1B`,amount:1e9,description:`1 billion`},{label:`1T`,amount:0xe8d4a51000,description:`1 trillion`}];function qe(e){let t=e.trim().toLowerCase();if(!t)return;let n=t.match(/^([\d.]+)\s*([kmbt])?$/);if(!n)return;let r=Number(n[1]);if(!Number.isFinite(r)||r<=0)return;let i=n[2]?Ge[n[2]]??1:1;return Math.round(r*i)}function Je(e){if(e==null)return``;let t=Ke.find(t=>t.amount===e);return t?t.label:e>=1e9?`${(e/1e9).toFixed(1).replace(/\.0$/,``)}B`:e>=1e6?`${(e/1e6).toFixed(1).replace(/\.0$/,``)}M`:e>=1e3?`${(e/1e3).toFixed(1).replace(/\.0$/,``)}K`:String(e)}function Ye(e){let t=Number(e.trim());return Number.isFinite(t)&&t>0?Math.round(t):void 0}function Xe(e){let t=Ye(e);return e.trim()===``?null:t}function Ze({label:e,value:t,onChange:n,disabled:r}){let i=qe(t),a=Ke.find(e=>e.amount===i)?.label;return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(W,{label:e,value:t,onChange:e=>n(e.target.value),placeholder:`e.g. 1M, 500K`,disabled:r}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-3 mt-3`,role:`group`,"aria-label":`${e} presets`,children:Ke.map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":a===e.label,"aria-label":`${e.label}, ${e.description} tokens`,onClick:()=>n(e.label),disabled:r,className:`py-1 px-4 rounded-chip text-micro font-semibold`,style:{cursor:r?`not-allowed`:`pointer`,border:`1px solid ${a===e.label?`var(--accent)`:`var(--inner-border)`}`,background:a===e.label?`var(--accent-soft)`:`transparent`,color:a===e.label?`var(--accent)`:`var(--text-tertiary)`},children:e.label},e.label))})]})}function Qe({tool:e,keyId:t,busy:n,scopeGranted:r,onScopeChange:i}){let a=Z(e.id,t),o=Oe(),s=De(),c=a.data?.enabled??!1,l=r&&c,u=a.data?.mappings.length??0,d=o.isPending||s.isPending;return(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-6 py-2 px-5 rounded-inset`,style:{minHeight:`44px`,border:`1px solid var(--inner-border)`,background:l?`var(--accent-soft)`:`var(--surface-1)`},children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,$.jsx)(M,{size:16,className:`mt-1 shrink-0 text-accent`,"aria-hidden":`true`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-caption font-semibold text-text-primary`,children:e.name}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:l?`Remote routing on — ${u} route${u===1?``:`s`} active, routing:cli_mapping granted.`:`Remote routing off — this key's requests go straight to the provider.`})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,$.jsx)(G,{checked:l,disabled:n||d||a.isLoading,"aria-label":`Enable remote routing for ${e.name}`,onChange:n=>{n!==r&&i(n),o.mutate({toolId:e.id,keyId:t,input:{enabled:n,mappings:a.data?.mappings??[]}},{onSuccess:()=>v.success(`Saved remote routing for ${e.name}.`),onError:e=>v.error(F(e,`Could not save remote routing.`))})}}),(0,$.jsx)(_,{variant:`secondary`,size:`sm`,disabled:n||d||!c&&u===0,onClick:()=>s.mutate({toolId:e.id,keyId:t},{onSuccess:()=>v.success(`Cleared remote routes for ${e.name}.`),onError:e=>v.error(F(e,`Could not reset remote routes.`))}),children:s.isPending?`Resetting…`:`Reset`})]})]})}function $e({keyId:e,busy:t,scopeGranted:n,onScopeChange:r,persistScope:i}){let a=(X().data??[]).filter(e=>e.mappingSupported);return e.length===0||a.length===0?null:(0,$.jsxs)(`section`,{"aria-labelledby":`remote-routing-heading`,className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h4`,{id:`remote-routing-heading`,className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(M,{size:15,className:`text-accent`,"aria-hidden":`true`}),`Remote routing`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Route this key's CLI model calls through persisted mappings and grant routing:cli_mapping. Applies immediately — no save needed.`})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:a.map(a=>(0,$.jsx)(Qe,{tool:a,keyId:e,busy:t,scopeGranted:n,onScopeChange:e=>{r(e),i(e)}},a.id))})]})}function et(e,t,n){let r=e===`personal`?t.trim():``;return{keyMode:e,keyPrefix:n.trim()||void 0,...r?{key:r}:{}}}function tt(e,t){return e===`personal`?t??null:null}function nt(e){if(e?.isDefault)return[...Ve];let t=e?.scopes;return t&&t.length>0?[...t]:[`routing:invoke`,`search:invoke`]}function rt({mode:e,record:t,busy:n,onDone:r,onClose:i,actionsRef:a}){let[o,c]=(0,Q.useState)(t?.label??``),[d,p]=(0,Q.useState)(t?.keyPrefix??``),[m,h]=(0,Q.useState)(``),[g,y]=(0,Q.useState)(t?.requestsPerMinute?.toString()??``),[b,x]=(0,Q.useState)(Je(t?.dailyTokenLimit??null)),[S,w]=(0,Q.useState)(Je(t?.monthlyTokenLimit??null)),[T,E]=(0,Q.useState)(Je(t?.lifetimeTokenBudget??null)),[ee,D]=(0,Q.useState)(t?.lifetimeTokenBudget==null?`recurring`:`one-time`),[O,k]=(0,Q.useState)(t?.maxConcurrentRequests?.toString()??``),[A,re]=(0,Q.useState)(()=>nt(t)),[j,ie]=(0,Q.useState)(t?.modelAccessMode??`whitelist`),[N,se]=(0,Q.useState)(()=>{let e=t?.modelList;return e?[...e]:[]}),[P,ce]=(0,Q.useState)(!1),[I,de]=(0,Q.useState)(()=>{let e=t?.clientRouterDenylist;return e?[...new Set(e.map(le).filter(e=>e!==void 0))]:[]}),[fe,L]=(0,Q.useState)(()=>t?.notesTitle??``),[R,z]=(0,Q.useState)(()=>t?.notesSubtitle??``),[B,me]=(0,Q.useState)(()=>t?.notesBody??``),[V,H]=(0,Q.useState)(t?.sharePopupEnabled??!1),[U,K]=(0,Q.useState)(null),[q,_e]=(0,Q.useState)(!1),[ve,J]=(0,Q.useState)(null),be=t?.sharePopupImageMime!==void 0,xe=U??(be&&!q&&t!==null?`/console/api/api-keys/${t.id}/share-popup-image`:null),[Se,Ce]=(0,Q.useState)(t?.sharePopupTitle??``),[we,Te]=(0,Q.useState)(t?.sharePopupBody??``),[Y,Ee]=(0,Q.useState)(t?.keyMode??`personal`),X=ee===`one-time`,Z=e===`edit`,De=ye(),Oe=e=>re(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),ke=()=>{r({label:o.trim(),...et(Y,m,d),scopes:A,modelAccessMode:j,modelList:N,clientRouterDenylist:I,requestsPerMinute:Xe(g),maxConcurrentRequests:Xe(O),dailyTokenLimit:X?null:qe(b)??null,monthlyTokenLimit:X?null:qe(S)??null,lifetimeTokenBudget:X?qe(T)??null:null,notesTitle:fe.trim(),notesSubtitle:R.trim(),notesBody:B.trim(),sharePopupEnabled:V,...U===null?q?{sharePopupImage:null}:{}:{sharePopupImage:U},sharePopupTitle:Se.trim(),sharePopupBody:we.trim()})};return(0,Q.useEffect)(()=>{a?.((0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(_,{variant:`secondary`,size:`sm`,onClick:i,disabled:n,children:`Cancel`}),(0,$.jsx)(_,{variant:`primary`,size:`sm`,disabled:n||e===`create`&&!o.trim(),onClick:ke,children:n?`Saving…`:e===`create`?`Create API key`:`Save changes`})]}))}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-6 min-w-0 pb-2`,children:[(0,$.jsxs)(`section`,{className:`flex flex-col gap-4 min-w-0 p-6 border border-inner-border rounded-card bg-surface-2 col-span-full`,children:[(0,$.jsxs)(`h3`,{className:`inline-flex items-center gap-2 text-body font-bold text-text-primary`,children:[(0,$.jsx)(te,{size:16,className:`text-accent`,"aria-hidden":`true`}),`Credential mode`]}),(0,$.jsx)(`div`,{role:`group`,"aria-label":`Credential mode`,className:`flex gap-4`,children:[`personal`,`share`].map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":Y===e,disabled:n||Z,onClick:()=>Ee(e),title:Z?`Credential mode cannot change after creation`:void 0,className:`rounded-inset py-2 px-6`,style:{border:`1px solid var(--inner-border)`,color:Y===e?`var(--accent)`:`var(--text-secondary)`,background:Y===e?`var(--accent-soft)`:`var(--surface-2)`,cursor:Z?`not-allowed`:`pointer`,opacity:Z&&Y!==e?.5:1},children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[e===`personal`?(0,$.jsx)(ze,{size:14,"aria-hidden":`true`}):(0,$.jsx)(Be,{size:14,"aria-hidden":`true`}),e===`personal`?`Personal`:`Share template`]})},e))}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:Y===`share`?`A share template does not authenticate requests. Recipients generate their own child key from its public enrollment page.`:`A personal key authenticates requests directly; its secret is shown once when created or rotated.`})]}),(0,$.jsxs)(`div`,{className:`columns-2 gap-6 min-w-0 max-medium:columns-1`,children:[e===`create`&&(0,$.jsxs)(`section`,{className:`flex flex-col gap-4 min-w-0 p-6 border border-inner-border rounded-card bg-surface-2 break-inside-avoid mb-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`inline-flex items-center gap-2 text-body font-bold text-text-primary`,children:[(0,$.jsx)(u,{size:16,className:`text-accent`,"aria-hidden":`true`}),`Identity`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Give this credential a recognizable name.`})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 items-start min-w-0 max-medium:grid-cols-1`,children:[(0,$.jsx)(W,{label:`Name`,value:o,onChange:e=>c(e.target.value),placeholder:`ci-key…`,disabled:n,autoFocus:!0}),(0,$.jsx)(W,{label:`Key prefix`,value:d,onChange:e=>p(e.target.value),placeholder:`carte_ (default)…`,disabled:n||m.trim().length>0})]}),Y===`personal`&&(0,$.jsx)(W,{label:`Custom API key value (optional)`,value:m,onChange:e=>h(e.target.value),placeholder:`Leave blank to generate…`,disabled:n})]}),e===`edit`&&(0,$.jsxs)(`section`,{className:`flex flex-col gap-4 min-w-0 p-6 border border-inner-border rounded-card bg-surface-2 break-inside-avoid mb-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`text-body font-bold text-text-primary`,children:[(0,$.jsx)(u,{size:16,className:`mr-2 inline text-accent`,"aria-hidden":`true`}),`Identity`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:t?.isDefault?`The default key's name is fixed. Limits, access, and everything else can still change.`:`Update the label for this credential.`})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-2 gap-4 items-start min-w-0 max-medium:grid-cols-1`,children:(0,$.jsx)(W,{label:`Name`,value:o,onChange:e=>c(e.target.value),placeholder:`ci-key…`,disabled:n||t?.isDefault===!0,title:t?.isDefault?`The default gateway key keeps its name`:void 0,autoFocus:!0})})]}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-4 min-w-0 p-6 border border-inner-border rounded-card bg-surface-2 break-inside-avoid mb-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`text-body font-bold text-text-primary`,children:[(0,$.jsx)(ne,{size:16,className:`mr-2 inline text-accent`,"aria-hidden":`true`}),`Share notes`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Optional copy shown on the public share page.`})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 items-start min-w-0 max-medium:grid-cols-1`,children:[(0,$.jsx)(W,{label:`Title`,value:fe,onChange:e=>L(e.target.value),placeholder:`e.g. Bansos Token`,disabled:n}),(0,$.jsx)(W,{label:`Subtitle`,value:R,onChange:e=>z(e.target.value),placeholder:`e.g. Come and save your tokens`,disabled:n}),(0,$.jsx)(W,{label:`Body`,value:B,onChange:e=>me(e.target.value),placeholder:`Free-form notes for the recipient`,disabled:n})]})]}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-4 min-w-0 p-6 border border-inner-border rounded-card bg-surface-2 break-inside-avoid mb-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{className:`text-body font-bold text-text-primary`,children:[(0,$.jsx)(C,{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)(W,{label:`Requests per minute`,type:`number`,min:`0`,value:g,onChange:e=>y(e.target.value),placeholder:`Unlimited…`,disabled:n}),(0,$.jsx)(W,{label:`Max concurrent requests`,type:`number`,min:`0`,value:O,onChange:e=>k(e.target.value),placeholder:`Unlimited…`,disabled:n})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-6 rounded-panel border border-inner-border px-6 py-5 bg-surface-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`text-caption font-bold text-text-primary`,children:[(0,$.jsx)(C,{size:14,className:`mr-2 inline text-accent`,"aria-hidden":`true`}),`Token budget`]}),(0,$.jsx)(`p`,{className:`mt-1 text-text-tertiary text-micro`,children:X?`One-time cap; it does not reset.`:`Daily and monthly limits reset automatically.`})]}),(0,$.jsxs)(`div`,{className:`flex gap-2 rounded-inset border border-inner-border bg-surface-1 p-1`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>D(`recurring`),disabled:n,className:`py-2 px-5 rounded-chip font-semibold border-0 cursor-pointer`,style:{fontSize:`10.5px`,background:X?`transparent`:`var(--accent-soft)`,color:X?`var(--text-tertiary)`:`var(--accent)`},children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(Me,{size:13,"aria-hidden":`true`}),`Recurring`]})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>D(`one-time`),disabled:n,className:`py-2 px-5 rounded-chip font-semibold border-0 cursor-pointer`,style:{fontSize:`10.5px`,background:X?`var(--accent-soft)`:`transparent`,color:X?`var(--accent)`:`var(--text-tertiary)`},children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(je,{size:13,"aria-hidden":`true`}),`One-time`]})})]})]}),X?(0,$.jsx)(Ze,{label:`One-time token limit`,value:T,onChange:E,disabled:n}):(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 items-start min-w-0 max-medium:grid-cols-1`,children:[(0,$.jsx)(Ze,{label:`Daily token limit`,value:b,onChange:x,disabled:n}),(0,$.jsx)(Ze,{label:`Monthly token limit`,value:S,onChange:w,disabled:n})]})]})]}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-4 min-w-0 p-6 border border-inner-border rounded-card bg-surface-2 col-span-full`,"aria-labelledby":`share-popup-heading`,children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h3`,{id:`share-popup-heading`,className:`text-body font-bold text-text-primary`,children:[(0,$.jsx)(Fe,{size:16,className:`mr-2 inline text-accent`,"aria-hidden":`true`}),`Share page popup`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Optional card visitors open from the Base URL card on your share page.`})]}),(0,$.jsx)(G,{checked:V,onChange:e=>H(e),disabled:n,label:`Enable popup`})]}),V?(0,$.jsxs)(`div`,{className:`flex gap-7 items-start mt-2 min-w-0 max-medium:flex-col max-medium:items-stretch`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 min-w-0 w-100 shrink-0 max-medium:w-auto`,children:[xe?(0,$.jsx)(`img`,{className:`block w-full h-66 object-cover border border-inner-border rounded-control bg-surface-1 max-medium:h-80`,src:xe,alt:`Popup image preview`}):(0,$.jsx)(`div`,{className:`flex items-center justify-center w-full h-66 object-cover border border-dashed border-inner-border rounded-control bg-surface-1 text-text-tertiary text-badge max-medium:h-80`,"aria-hidden":`true`,children:(0,$.jsx)(`span`,{children:`No image`})}),(0,$.jsx)(he,{id:`share-popup-image`,accept:He.join(`,`),"aria-label":`Popup image`,disabled:n,onChange:e=>{let t=e.target.files?.[0];if(e.target.value=``,!t)return;if(J(null),t.size>2097152){K(null),J(`Image must be 2 MB or smaller.`);return}let n=new FileReader;n.onload=()=>{K(String(n.result)),_e(!1)},n.onerror=()=>J(`Could not read that file.`),n.readAsDataURL(t)}}),xe?(0,$.jsx)(_,{variant:`secondary`,size:`sm`,type:`button`,disabled:n,className:`h-14 px-5 text-badge self-start`,onClick:()=>{K(null),_e(!0),J(null)},children:`Remove image`}):null,ve?(0,$.jsx)(`p`,{className:`form-error`,children:ve}):null,(0,$.jsx)(`p`,{className:`m-0 text-text-tertiary text-badge leading-normal`,children:`PNG, JPEG, WebP, or GIF up to 2 MB.`})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 min-w-0 flex-1 [&_.form-group]:gap-2`,children:[(0,$.jsx)(W,{label:`Popup title`,value:Se,onChange:e=>Ce(e.target.value),maxLength:120,placeholder:`Support this gateway`,disabled:n}),(0,$.jsxs)(`div`,{className:`form-group`,children:[(0,$.jsx)(`label`,{className:`form-label`,htmlFor:`share-popup-copy`,children:`Message`}),(0,$.jsx)(`textarea`,{className:`form-textarea`,id:`share-popup-copy`,value:we,onChange:e=>Te(e.target.value),maxLength:1200,rows:3,placeholder:`If this service helps you, consider supporting its upkeep…`,disabled:n})]})]})]}):null]}),(0,$.jsxs)(`details`,{className:`group min-w-0 col-span-full rounded-card border border-inner-border bg-surface-2`,children:[(0,$.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-4 p-6 [&::-webkit-details-marker]:hidden`,children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 items-start gap-3`,children:[(0,$.jsx)(`span`,{className:`grid size-10 shrink-0 place-items-center rounded-inset bg-accent-soft text-accent`,children:(0,$.jsx)(oe,{size:18,"aria-hidden":`true`})}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block text-body font-bold text-text-primary`,children:`Access`}),(0,$.jsx)(`span`,{className:`mt-1 block text-badge text-text-tertiary`,children:t?.isDefault?`Default gateway key · all tenant permissions, including gateway routing and remote debugging.`:`Choose model, router, and dashboard permissions for this key.`})]})]}),(0,$.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-2 rounded-control border border-inner-border bg-surface-1 px-3 py-2 text-micro font-semibold text-text-secondary`,children:[A.length,`/`,Ve.length,` grants`,(0,$.jsx)(f,{size:14,className:`transition-transform group-open:rotate-180`,"aria-hidden":`true`})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-5 border-t border-inner-border p-6`,children:[t?.isDefault?(0,$.jsxs)(`div`,{className:`flex items-start gap-3 rounded-control border border-accent/30 bg-accent-soft p-4 text-badge text-text-secondary`,children:[(0,$.jsx)(ae,{size:16,className:`mt-0.5 shrink-0 text-accent`,"aria-hidden":`true`}),(0,$.jsxs)(`p`,{className:`m-0`,children:[`This default API key is provisioned with every tenant permission, including `,(0,$.jsx)(`code`,{children:`routing:invoke`}),` and`,` `,(0,$.jsx)(`code`,{children:`routing:cli_mapping`}),`. Those grant gateway access and authorization to use remote CLI mappings; each client's mapping toggle below still controls whether those routes are active. You can remove individual grants here.`]})]}):null,(0,$.jsxs)(`div`,{className:`columns-2 gap-6 min-w-0 max-medium:columns-1`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`label`,{className:`inline-flex items-center gap-2 text-badge font-semibold text-text-secondary block mb-3`,children:[(0,$.jsx)(l,{size:14,className:`text-accent`,"aria-hidden":`true`}),`Model access`]}),(0,$.jsx)(`div`,{role:`group`,"aria-label":`Model access mode`,className:`flex gap-3 mb-4`,children:[`whitelist`,`blacklist`].map(e=>(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":j===e,disabled:n,onClick:()=>ie(e),title:e===`whitelist`?`Only the listed models may be used. An empty list allows every model.`:`The listed models are refused. Everything else is allowed.`,className:`flex-1 py-2.5 px-4 text-badge font-semibold`,style:{borderRadius:`7px`,border:`1px solid ${j===e?`var(--accent)`:`var(--inner-border)`}`,background:j===e?`var(--accent-soft)`:`var(--surface-2)`,color:j===e?`var(--accent)`:`var(--text-secondary)`,cursor:n?`not-allowed`:`pointer`,opacity:n?.6:1},children:[e===`whitelist`?`Whitelist`:`Blacklist`,e===`whitelist`?(0,$.jsx)(ae,{size:13,className:`ml-2 inline`,"aria-hidden":`true`}):(0,$.jsx)(Le,{size:13,className:`ml-2 inline`,"aria-hidden":`true`})]},e))}),(0,$.jsx)(`label`,{className:`text-badge font-semibold text-text-secondary block mb-3`,children:j===`whitelist`?`Allowed models`:`Blocked models`}),(0,$.jsx)(`div`,{className:`flex gap-3 flex-wrap mb-4`,children:N.length===0?(0,$.jsx)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:j===`whitelist`?`All models allowed`:`No models blocked`}):N.map(e=>(0,$.jsxs)(`span`,{className:`font-mono tabular-nums inline-flex items-center gap-2 text-badge bg-accent-soft text-accent py-1 px-4 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)(_,{variant:`secondary`,size:`sm`,type:`button`,onClick:()=>ce(!0),disabled:n,children:`Browse models`}),(0,$.jsx)(ge,{open:P,onClose:()=>ce(!1),selected:N,onToggle:e=>se(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),title:j===`whitelist`?`Select allowed models`:`Select blocked models`,multi:!0})]}),(0,$.jsxs)(`section`,{"aria-labelledby":`blocked-routers-heading`,className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h4`,{id:`blocked-routers-heading`,className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(s,{size:15,className:`text-accent`,"aria-hidden":`true`}),`Blocked client routers`]}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:`Matching fingerprints are rejected with 403 before routing. Detection is best-effort; clients without a fingerprint are not matched. This may also block bazaar probe links that share the same fingerprint.`})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:ue.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-6 py-2 px-5 rounded-inset`,style:{minHeight:`44px`,border:`1px solid var(--inner-border)`,background:I.includes(e.id)?`var(--accent-soft)`:`var(--surface-1)`},children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,$.jsx)(s,{size:15,className:`mt-1 shrink-0 text-orange`,"aria-hidden":`true`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`text-caption text-text-primary`,children:[`Block `,e.label,` Client`]}),(0,$.jsxs)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Reject requests fingerprinted as `,e.label,`.`]})]})]}),(0,$.jsx)(G,{checked:I.includes(e.id),onChange:t=>de(n=>t?[...n,e.id]:n.filter(t=>t!==e.id)),disabled:n,"aria-label":`Block ${e.label} client`})]},e.id))})]}),(0,$.jsxs)(`section`,{"aria-labelledby":`routing-scopes-heading`,className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`h4`,{id:`routing-scopes-heading`,className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(M,{size:15,className:`text-accent`,"aria-hidden":`true`}),`Routing`]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:Ve.filter(e=>e===`routing:invoke`).map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-6 py-2 px-5 rounded-inset`,style:{minHeight:`44px`,border:`1px solid var(--inner-border)`,background:A.includes(e)?`var(--accent-soft)`:`var(--surface-1)`},children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(M,{size:16,className:`mt-1 shrink-0 text-accent`,"aria-hidden":`true`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-caption font-semibold text-text-primary`,children:e}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:Ue[e]})]})]}),(0,$.jsx)(G,{checked:A.includes(e),onChange:()=>Oe(e),disabled:n,"aria-label":`Grant ${e}`})]},e))})]}),(0,$.jsx)($e,{keyId:e===`edit`&&t?t.id:``,busy:n,scopeGranted:A.includes(`routing:cli_mapping`),onScopeChange:e=>{e!==A.includes(`routing:cli_mapping`)&&Oe(`routing:cli_mapping`)},persistScope:n=>{if(e!==`edit`||!t)return;let r=n?[...new Set([...A,`routing:cli_mapping`])]:A.filter(e=>e!==`routing:cli_mapping`);De.mutate({keyId:t.id,request:{scopes:r}},{onError:e=>v.error(F(e,`Could not update the key's routing scope.`))})}}),(0,$.jsxs)(`section`,{"aria-labelledby":`dashboard-scopes-heading`,className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`h4`,{id:`dashboard-scopes-heading`,className:`inline-flex items-center gap-2 text-caption font-bold text-text-primary`,children:[(0,$.jsx)(pe,{size:15,className:`text-accent`,"aria-hidden":`true`}),`Dashboard / Resources`]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:Ve.filter(e=>!e.startsWith(`routing:`)).map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-6 py-2 px-5 rounded-inset`,style:{minHeight:`44px`,border:`1px solid var(--inner-border)`,background:A.includes(e)?`var(--accent-soft)`:`var(--surface-1)`},children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(()=>{let t=We[e];return(0,$.jsx)(t,{size:16,className:`mt-1 shrink-0 text-accent`,"aria-hidden":`true`})})(),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-caption font-semibold text-text-primary`,children:e}),(0,$.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:Ue[e]})]})]}),(0,$.jsx)(G,{checked:A.includes(e),onChange:()=>Oe(e),disabled:n,"aria-label":`Grant ${e}`})]},e))})]})]})]})]})]})}function it({secret:e,onClose:t}){return(0,$.jsx)(k,{open:e!==null,onClose:t,title:`New API key`,description:`Copy it now, or reveal it again later from the key's Share button.`,size:`md`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,$.jsx)(`p`,{className:`text-body text-text-secondary m-0 leading-normal`,children:`A personal key stays recoverable. Open the key's Share button and choose Reveal to see it again and copy it. Rotating the key replaces this secret, and any client still using it starts getting 401s.`}),(0,$.jsx)(`code`,{className:`block rounded-inset border border-inner-border bg-surface-1 py-5 px-6 text-caption text-text-primary break-all`,children:e}),(0,$.jsxs)(`div`,{className:`flex gap-4 flex-wrap`,children:[(0,$.jsx)(O,{value:e??``,size:`sm`,variant:`primary`,label:`Copy key`,copiedLabel:`Copied`}),(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(b,{size:13}),onClick:()=>{e!==null&&(me(`cartethyia-api-key.txt`,`Cartethyia API key\n\n${e}\n\nKeep this secret. Reveal it again from the key's Share button.\n`,`text/plain;charset=utf-8`),v.success(`Key saved to your downloads.`))},children:`Save this key`})]})]})})}function at(e){let t=new Date(e);if(!Number.isFinite(t.getTime()))return`—`;let n=e-Date.now(),r=t.toLocaleString();if(n<=0)return`${r} (lapsed)`;let i=Math.ceil(n/6e4);if(i<60)return`${r} (in ${i}m)`;let a=Math.floor(i/60);return a<24?`${r} (in ${a}h)`:`${r} (in ${Math.floor(a/24)}d)`}function ot({onClose:e}){let t=o(!0),n=c(),[r,i]=(0,Q.useState)(null),a=t.data??[];return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(k,{open:!0,onClose:e,title:`Banned Users`,description:`A client address is banned after repeated invalid-model requests. The ban applies to every API key used from that address, not just one credential.`,size:`lg`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-7 min-w-0`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`h4`,{className:`text-caption font-semibold text-text-secondary mb-4`,children:[`Active bans (`,a.length,`)`]}),t.isPending?(0,$.jsx)(E,{label:`Loading banned users…`}):t.isError?(0,$.jsx)(T,{message:F(t.error,`Could not load banned users.`),onRetry:()=>void t.refetch()}):a.length===0?(0,$.jsx)(ee,{title:`No banned users`,message:`No client address is currently banned for model abuse.`,icon:(0,$.jsx)(Ie,{size:20})}):(0,$.jsx)(`div`,{className:`rounded-inset border border-inner-border`,children:(0,$.jsx)(ke,{maxHeight:480,scrollRegion:!0,headers:[`Client IP`,`Reason`,`Applies to`,`Lapses`,``],children:a.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`font-mono tabular-nums text-badge text-text-primary whitespace-nowrap`,children:e.ip}),(0,$.jsx)(`td`,{className:`text-badge text-text-secondary`,children:e.reason===`repeated_invalid_model_requests`?`Repeated invalid-model requests`:e.reason}),(0,$.jsx)(`td`,{className:`text-badge text-text-secondary whitespace-nowrap`,children:`All API keys from this IP`}),(0,$.jsx)(`td`,{className:`text-badge text-text-secondary whitespace-nowrap`,children:at(e.expiresAt)}),(0,$.jsx)(`td`,{className:`text-right whitespace-nowrap`,children:(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(Re,{size:13}),disabled:n.isPending,onClick:()=>i(e),children:`Unban`})})]},e.ip))})})]}),(0,$.jsx)(q,{justify:`flex-end`,gap:`0px`,children:(0,$.jsx)(_,{variant:`secondary`,size:`sm`,onClick:e,children:`Close`})})]})}),(0,$.jsx)(I,{open:r!==null,onClose:()=>i(null),onConfirm:async()=>{r&&(await n.mutateAsync(r.ip),v.success(`Unbanned ${r.ip}.`),i(null))},title:`Lift this ban?`,message:r?`Lift the ban on ${r.ip}? The address can reach the gateway again immediately.`:`Lift this ban?`,confirmLabel:`Unban`,danger:!0})]})}var st=e=>(e??0).toLocaleString(),ct=e=>e?new Date(e).toLocaleString():`—`;function lt({keyId:e}){let t=_e(),[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(!1);return(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-4 rounded-control border border-inner-border bg-surface-2 px-5 py-4 text-text-tertiary`,children:[(0,$.jsx)(`code`,{title:i&&n?n:void 0,className:`min-w-0 flex-auto overflow-hidden font-mono text-caption text-text-primary text-ellipsis whitespace-nowrap`,children:i&&n?n:`••••••••••••••••`}),(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:i?(0,$.jsx)(x,{size:13}):(0,$.jsx)(S,{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=>v.error(F(e,`Could not reveal the key.`))})},children:i?`Hide`:`Reveal`}),i&&n?(0,$.jsx)(O,{value:n,size:`sm`,variant:`secondary`,label:`Copy`,copiedLabel:`Copied`}):null]})}function ut({label:e,value:t}){return(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 basis-60 rounded-control border border-inner-border bg-surface-2 px-5 py-3`,children:[(0,$.jsx)(`dt`,{className:`text-badge font-normal tracking-label text-text-tertiary uppercase`,children:e}),(0,$.jsx)(`dd`,{className:`mt-1 text-caption font-normal text-text-primary tabular-nums`,children:t==null?`Unlimited`:st(t)})]})}function dt(e){return e?{title:`Regenerate this key?`,message:`This rotates the key credential. Any client still using the current secret starts getting 401s immediately, and the old secret cannot be recovered. The handoff link is re-pointed to reveal the new key.`,confirmLabel:`Regenerate key`}:{title:`Regenerate this link?`,message:`This replaces the link URL; the current URL stops resolving immediately. Recipients keep the keys they already generated and keep working — but no one can enroll through the old link again.`,confirmLabel:`Regenerate link`}}function ft({consumed:e,budget:t}){let n=t==null||t<=0,r=n?100:Math.min(100,e/t*100),i=!n&&e>=t;return(0,$.jsxs)(`div`,{className:`grid flex-auto basis-full gap-2.5 rounded-control border border-inner-border bg-surface-2 px-5 py-3.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 text-badge tracking-label text-text-tertiary uppercase`,children:[(0,$.jsx)(`span`,{children:`Lifetime budget`}),(0,$.jsx)(`span`,{className:`text-caption font-normal text-text-primary tabular-nums normal-case tracking-normal`,children:n?`${V(e)} · Unlimited`:`${V(e)} / ${V(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?`${V(e)} tokens consumed, no lifetime budget set`:`${V(e)} of ${V(t)} tokens consumed`,children:(0,$.jsx)(`div`,{className:i?`h-full rounded bg-status-danger`:`h-full rounded bg-status-success`,style:{width:`${r}%`}})})]})}function pt(e){return e.filter(e=>e.revokedAt===null).length}function mt(e){return e.reduce((e,t)=>e+t.allTime.totalTokens,0)}function ht({consumed:e,budget:t}){if(t==null)return(0,$.jsx)(`div`,{className:`grid flex-auto basis-full gap-2.5 rounded-control border border-inner-border bg-surface-2 px-5 py-3.5`,children:(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 text-badge tracking-label text-text-tertiary uppercase`,children:[(0,$.jsx)(`span`,{children:`Total quota used`}),(0,$.jsx)(`span`,{className:`text-caption font-normal text-text-primary tabular-nums normal-case tracking-normal`,children:V(e)})]})});let n=t>0?Math.min(100,e/t*100):0,r=t>0?Math.max(0,100-e/t*100):100,i=Math.max(0,t-e),a=Ae(e>=t?0:r),o=e>=t;return(0,$.jsxs)(`div`,{className:`grid flex-auto basis-full gap-2.5 rounded-control border border-inner-border bg-surface-2 px-5 py-3.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 text-badge tracking-label text-text-tertiary uppercase`,children:[(0,$.jsx)(`span`,{children:`Total quota`}),(0,$.jsxs)(`span`,{className:`text-caption font-normal text-text-primary tabular-nums normal-case tracking-normal`,children:[V(e),` / `,V(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`:`${V(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":`${V(e)} of ${V(t)} tokens consumed`,children:(0,$.jsx)(`div`,{className:o?`h-full rounded bg-status-danger`:`h-full rounded`,style:{width:`${n}%`,background:o?void 0:a.bar}})})]})}function gt({parentId:e,childId:t}){let n=Ee(e,t);if(n.isPending)return(0,$.jsx)(E,{label:`Loading activity…`,compact:!0});if(n.isError)return(0,$.jsx)(T,{compact:!0,message:F(n.error,`Could not load activity.`),onRetry:()=>void n.refetch()});let r=n.data;return r?(0,$.jsxs)(`div`,{className:`grid min-w-0 gap-6 border-t border-inner-border bg-surface-1 px-6 py-5`,children:[(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h4`,{className:`mb-3 text-caption font-bold text-text-primary`,children:`Top models`}),r.models.length?(0,$.jsx)(`div`,{className:`data-table-container`,children:(0,$.jsxs)(`table`,{className:`data-table text-caption`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`col`,children:`Model`}),(0,$.jsx)(`th`,{scope:`col`,children:`Today`}),(0,$.jsx)(`th`,{scope:`col`,children:`Errors`}),(0,$.jsx)(`th`,{scope:`col`,children:`Tokens`})]})}),(0,$.jsx)(`tbody`,{children:r.models.map((e,t)=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:e.modelId}),(0,$.jsx)(`td`,{children:st(e.todayRequests)}),(0,$.jsx)(`td`,{children:st(e.todayErrors)}),(0,$.jsx)(`td`,{children:V(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:V(e.totalTokens)}),(0,$.jsx)(`td`,{children:ct(e.startedAt)})]},e.requestId))})]})}):(0,$.jsx)(`p`,{className:`py-3 text-caption text-text-tertiary`,children:`No recent requests.`})]})]}):null}function _t({parent:e,onSecretRevealed:t}){let[n,r]=(0,Q.useState)(null),i=ve(),a=we(),o=Te(),s=xe(e.id),c=e.keyMode!==`share`,l=J(c?null:e.id),u=l.data??[];(0,Q.useEffect)(()=>{r(null)},[e.id]);let d=i.isPending||a.isPending,[p,h]=(0,Q.useState)(!1),g=async()=>{if(c){let n=await a.mutateAsync({keyId:e.id});t?.(n.secret);return}await i.mutateAsync({keyId:e.id,regenerate:!0}),v.success(`Link regenerated; the previous URL no longer works.`)},y=()=>{i.mutate({keyId:e.id},{onError:e=>v.error(F(e,`Could not create link.`))})},b=s.data?.url??null,x=dt(c);return(0,$.jsxs)(`div`,{className:`grid min-w-0 gap-6`,children:[(0,$.jsx)(`section`,{"aria-label":`Link`,children:s.isPending?(0,$.jsx)(E,{label:`Loading link…`,compact:!0}):s.isError?(0,$.jsx)(T,{compact:!0,message:F(s.error,`Could not load the link.`),onRetry:()=>void s.refetch()}):b?(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-4 rounded-control border border-inner-border bg-surface-2 px-5 py-4 text-text-tertiary`,children:[(0,$.jsx)(D,{size:14,"aria-hidden":`true`,className:`shrink-0`}),(0,$.jsx)(`code`,{title:b,className:`min-w-0 flex-auto overflow-hidden font-mono text-caption text-text-primary text-ellipsis whitespace-nowrap`,children:b}),(0,$.jsx)(O,{value:b,size:`sm`,variant:`secondary`,label:`Copy`,copiedLabel:`Copied`}),(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(Ne,{size:13}),loading:d,disabled:d,onClick:()=>h(!0),children:`Regenerate`})]}):(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-4 rounded-control border border-inner-border bg-surface-2 px-5 py-4 text-text-tertiary`,children:[(0,$.jsx)(D,{size:14,"aria-hidden":`true`,className:`shrink-0`}),(0,$.jsx)(`span`,{className:`flex-auto text-caption text-text-tertiary`,children:`No link yet.`}),(0,$.jsx)(_,{variant:`primary`,size:`sm`,loading:d,disabled:d,onClick:y,children:`Create link`})]})}),c?(0,$.jsxs)(`section`,{"aria-label":`API key`,className:`grid gap-3`,children:[(0,$.jsx)(`div`,{className:`flex items-center justify-between gap-4`,children:(0,$.jsx)(`strong`,{className:`text-caption`,children:`API key`})}),(0,$.jsx)(lt,{keyId:e.id})]}):null,c?(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:V(e.tokensConsumed)})]}),(0,$.jsx)(ut,{label:`Requests / min`,value:e.requestsPerMinute}),(0,$.jsx)(ut,{label:`Daily tokens`,value:e.dailyTokenLimit}),(0,$.jsx)(ut,{label:`Monthly tokens`,value:e.monthlyTokenLimit}),(0,$.jsx)(ft,{consumed:e.tokensConsumed,budget:e.lifetimeTokenBudget})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`section`,{"aria-label":`Total quota`,className:`grid gap-3`,children:[(0,$.jsx)(`div`,{className:`flex items-center justify-between gap-4`,children:(0,$.jsx)(`strong`,{className:`text-caption`,children:`Total quota`})}),(0,$.jsx)(ht,{consumed:mt(u),budget:e.lifetimeTokenBudget})]}),(0,$.jsxs)(`section`,{"aria-label":`Recipients`,className:`grid gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsx)(`strong`,{className:`text-caption`,children:`Recipients`}),(0,$.jsxs)(`span`,{className:`mr-2 ml-auto text-caption text-text-tertiary tabular-nums`,children:[`Active users: `,pt(u)]}),(0,$.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>void l.refetch(),icon:(0,$.jsx)(j,{size:13,className:l.isFetching?`animate-spin`:void 0}),children:`Refresh`})]}),l.isPending&&!l.data?(0,$.jsx)(E,{label:`Loading recipients…`,compact:!0}):l.isError?(0,$.jsx)(T,{compact:!0,message:F(l.error,`Could not load recipients.`),onRetry:()=>void l.refetch()}):u.length===0?(0,$.jsx)(ee,{compact:!0,title:`No recipients yet`,message:`Keys generated through this link appear here with their masked client IP and token usage.`}):(0,$.jsx)(`div`,{className:`data-table-container max-h-[46vh]`,children:(0,$.jsxs)(`table`,{className:`data-table text-caption`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`col`,className:`w-12`,"aria-label":`Expand`}),(0,$.jsx)(`th`,{scope:`col`,children:`Key`}),(0,$.jsx)(`th`,{scope:`col`,children:`Status`}),(0,$.jsx)(`th`,{scope:`col`,children:`Today`}),(0,$.jsx)(`th`,{scope:`col`,children:`Lifetime`}),(0,$.jsx)(`th`,{scope:`col`,children:`Last activity`}),(0,$.jsx)(`th`,{scope:`col`,className:`text-right whitespace-nowrap`,children:`Actions`})]})}),(0,$.jsx)(`tbody`,{children:u.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)(f,{size:14}):(0,$.jsx)(m,{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:V(t.today.totalTokens)}),(0,$.jsx)(`td`,{children:V(t.allTime.totalTokens)}),(0,$.jsx)(`td`,{children:ct(t.lastUsedAt)}),(0,$.jsx)(`td`,{className:`text-right whitespace-nowrap`,children:(0,$.jsx)(_,{variant:`danger`,size:`sm`,disabled:o.isPending||!!t.revokedAt,onClick:()=>o.mutate({parentKeyId:e.id,childKeyId:t.id},{onError:e=>v.error(F(e,`Could not revoke key.`))}),children:`Revoke`})})]}),i?(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:7,className:`p-0`,children:(0,$.jsx)(gt,{parentId:e.id,childId:t.id})})}):null]},t.id)})})]})})]})]}),(0,$.jsx)(I,{open:p,onClose:()=>h(!1),onConfirm:g,title:x.title,message:x.message,confirmLabel:x.confirmLabel,danger:!0})]})}function vt({parent:e,onClose:t,onSecretRevealed:n}){let r=e.keyMode!==`share`;return(0,$.jsx)(k,{open:!0,onClose:t,title:`Sharing — ${e.label||`API key`}`,description:r?`One stable handoff link for this key. Regenerating rotates the key itself.`:`One stable enrollment link. Regenerating replaces the URL; recipients keep the keys they already generated.`,size:`lg`,children:(0,$.jsx)(_t,{parent:e,onSecretRevealed:n})})}function yt(){let e=Y(),t=de(),n=Se(),r=ye(),i=Ce(),a=we(),o=_e(),s=be(),{copy:c}=B(),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)(null),[g,b]=(0,Q.useState)(null),[x,S]=(0,Q.useState)(null),[C,w]=(0,Q.useState)(null),[ne,D]=(0,Q.useState)(!1),[O,j]=(0,Q.useState)(null),[M,ie]=(0,Q.useState)(null),ae=e.data??[],N=t.data?.isPlatformAdmin??!1,oe=e=>{S(null),w(e)},se=async e=>{try{let{secret:t}=await o.mutateAsync({keyId:e.id});await c(t)?v.success(`API key copied`):v.error(`Clipboard unavailable on this origin`)}catch(e){v.error(F(e,`Could not reveal API key.`))}},P=dt(!0);return(0,$.jsxs)(z,{children:[(0,$.jsx)(R,{title:`API Credentials`,subtitle:`Manage tenant API keys, model access, budgets, and sharing.`,icon:(0,$.jsx)(te,{size:16}),action:(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[N?(0,$.jsx)(_,{variant:`secondary`,size:`sm`,onClick:()=>D(!0),icon:(0,$.jsx)(Ie,{size:13}),children:`Banned Users`}):null,(0,$.jsx)(_,{variant:`primary`,size:`sm`,onClick:()=>{S(null),u(!0)},icon:(0,$.jsx)(re,{size:13}),children:`Create Key`})]})}),(0,$.jsx)(L,{children:e.isPending&&!e.data?(0,$.jsx)(E,{label:`Loading API keys…`}):e.isError&&!e.data?(0,$.jsx)(T,{message:F(e.error,`Could not load credentials.`),onRetry:()=>void e.refetch()}):ae.length===0?(0,$.jsx)(ee,{title:`No API keys issued`,message:`Generate a secret key to authenticate your SDK or CLI client against the gateway.`,icon:(0,$.jsx)(te,{size:20})}):(0,$.jsx)(`div`,{className:`scroll-region max-h-280 pr-1`,children:(0,$.jsx)(h,{items:ae,label:`API credentials`,disabled:s.isPending,onReorder:e=>s.mutate(e,{onError:e=>v.error(F(e,`Could not save the new order.`))}),renderItem:e=>(0,$.jsxs)(`div`,{className:`api-key-card flex items-start justify-between gap-6 px-6 py-4 rounded-chip border border-inner-border bg-surface-2 max-medium:flex-col max-medium:items-stretch max-medium:gap-4 max-medium:p-5 [&>div:last-child]:flex-wrap`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,$.jsx)(`strong`,{className:`text-body`,children:e.label||`Unnamed credential`}),(0,$.jsx)(U,{tone:e.revokedAt?`err`:e.enabled?`ok`:`warn`,children:e.revokedAt?`revoked`:e.enabled?`enabled`:`disabled`}),(0,$.jsx)(U,{tone:e.keyMode===`share`?`accent`:`default`,children:e.keyMode===`share`?`share template`:`personal`}),e.isDefault?(0,$.jsx)(U,{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`}),V(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`}),H(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`}),H(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`}),H(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`}),H(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`}),H(e.maxConcurrentRequests)]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap max-medium:justify-between`,children:[(0,$.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:e.modelAccessMode===`blacklist`?`Blocked`:`Models`}),e.modelAccessMode===`blacklist`?e.modelList?.length??0:e.modelList?.length?e.modelList.length:`All`]})]})]}),(0,$.jsxs)(`div`,{className:`flex gap-3 shrink-0 flex-wrap`,children:[e.revokedAt?null:(0,$.jsx)(G,{checked:e.enabled,disabled:r.isPending,id:`api-key-enabled-${e.id}`,label:``,"aria-label":`${e.enabled?`Disable`:`Enable`} ${e.label||`API credential`}`,onChange:t=>r.mutate({keyId:e.id,request:{enabled:t}},{onSuccess:()=>v.success(`${e.label||`API credential`} ${t?`enabled`:`disabled`}`),onError:e=>v.error(F(e,`Could not update credential state.`))})}),(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(A,{size:13}),onClick:()=>{S(null),f(e)},children:`Edit`}),!e.revokedAt&&e.keyMode!==`share`?(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(y,{size:13}),onClick:()=>void se(e),disabled:o.isPending,children:`Copy`}):null,!e.revokedAt&&(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(Fe,{size:13}),onClick:()=>oe(e),children:e.keyMode===`share`?`Recipients`:`Share`}),!e.revokedAt&&e.keyMode!==`share`&&(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:(0,$.jsx)(Ne,{size:13}),onClick:()=>{S(null),b(e)},disabled:a.isPending,children:`Rotate`}),!e.revokedAt&&!e.isDefault&&(0,$.jsx)(_,{variant:`danger`,size:`sm`,icon:(0,$.jsx)(ce,{size:13}),onClick:()=>m(e),disabled:i.isPending,children:`Revoke`})]})]})})})}),(0,$.jsx)(k,{open:l,onClose:()=>u(!1),title:`Create API Key`,description:`Create a tenant-scoped credential. Choose model access, permissions, limits, and optional blocked client routers.`,size:`lg`,footer:O,children:(0,$.jsx)(rt,{mode:`create`,record:null,busy:n.isPending,onClose:()=>u(!1),actionsRef:j,onDone:e=>{n.mutate(e,{onSuccess:t=>{u(!1),S(tt(e.keyMode,t.secret)),v.success(`API key created`)},onError:e=>v.error(F(e,`Could not create API key.`))})}})}),(0,$.jsx)(k,{open:d!==null,onClose:()=>f(null),title:`Edit API Key`,description:`Update the key's model access, permissions, limits, share notes, and optional public popup.`,size:`lg`,footer:M,children:(0,$.jsx)(rt,{mode:`edit`,record:d,busy:r.isPending,onClose:()=>f(null),actionsRef:ie,onDone:e=>{d&&r.mutate({keyId:d.id,request:e},{onSuccess:t=>{f(null),S(tt(e.keyMode,t.secret)),v.success(`API key updated`)},onError:e=>v.error(F(e,`Could not update API key.`))})}})}),C?(0,$.jsx)(vt,{parent:C,onClose:()=>w(null),onSecretRevealed:e=>{w(null),S(e)}}):null,(0,$.jsx)(I,{open:g!==null,onClose:()=>b(null),onConfirm:async()=>{if(!g)return;let e=await a.mutateAsync({keyId:g.id});S(e.secret),v.success(`Rotated ${g.label||g.id}.`),b(null)},title:P.title,message:P.message,confirmLabel:P.confirmLabel,danger:!0}),(0,$.jsx)(I,{open:p!==null,onClose:()=>m(null),onConfirm:async()=>{p&&(await i.mutateAsync(p.id),v.success(`Revoked ${p.label||p.id}.`),m(null))},title:`Revoke API key?`,message:p?`Revoke ${p.label||p.id}? Clients using it will be rejected.${p.keyMode===`share`?` All child keys and enrollment links will also be revoked.`:``}`:`Revoke this API key?`,confirmLabel:`Revoke`,danger:!0}),ne?(0,$.jsx)(ot,{onClose:()=>D(!1)}):null,(0,$.jsx)(it,{secret:x,onClose:()=>S(null)})]})}function bt(){let e=se(),t=N(),n=e.data;if(e.isPending)return(0,$.jsx)(E,{label:`Loading compression settings…`});if(e.isError||!n)return(0,$.jsx)(T,{message:F(e.error,`Failed to load compression settings`),onRetry:()=>void e.refetch()});let r=n.rtkPruneEnabled,i=n.ponyTailEnabled;return(0,$.jsxs)(z,{children:[(0,$.jsx)(R,{title:`Compression`,subtitle:`Shrink requests before they reach the provider`,icon:(0,$.jsx)(a,{size:16})}),(0,$.jsx)(L,{children:(0,$.jsxs)(K,{gap:`14px`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-x-8 gap-y-5`,children:[(0,$.jsxs)(`div`,{className:`flex gap-5 min-w-0 flex-auto`,children:[(0,$.jsx)(Pe,{size:16,className:`shrink-0 mt-1 text-text-secondary`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`label`,{htmlFor:`compression-rtk`,children:(0,$.jsx)(q,{gap:`6px`,className:`text-body font-semibold`,children:`Prune tool output (RTK)`})}),(0,$.jsx)(`div`,{className:`text-badge text-text-tertiary wrap-anywhere max-w-full`,children:`Compact bulky tool results (diffs, grep dumps, listings) in the message history so a long conversation stops re-sending megabytes of raw output. Higher strength compresses more aggressively.`})]})]}),(0,$.jsxs)(q,{gap:`8px`,className:`shrink-0 items-center ml-auto`,children:[(0,$.jsx)(p,{id:`compression-rtk-level`,"aria-label":`RTK strength`,value:n.rtkPruneLevel,onValueChange:e=>t.mutate({rtkPruneLevel:e===`lite`||e===`full`||e===`ultra`?e:`full`},{onError:e=>v.error(F(e,`Could not update RTK strength.`))}),options:[{value:`lite`,label:`Lite`},{value:`full`,label:`Full`},{value:`ultra`,label:`Ultra`}]}),(0,$.jsx)(G,{id:`compression-rtk`,"aria-label":`Enable RTK prune`,checked:r,onChange:e=>t.mutate({rtkPruneEnabled:e},{onError:e=>v.error(F(e,`Could not update RTK prune.`))})})]})]}),(0,$.jsxs)(`div`,{className:`flex items-start gap-x-8 gap-y-5`,children:[(0,$.jsxs)(`div`,{className:`flex gap-5 min-w-0 flex-auto`,children:[(0,$.jsx)(P,{size:16,className:`shrink-0 mt-1 text-text-secondary`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`label`,{htmlFor:`compression-ponytail`,children:(0,$.jsx)(q,{gap:`6px`,className:`text-body font-semibold`,children:`PonyTail (system directive)`})}),(0,$.jsx)(`div`,{className:`text-badge text-text-tertiary wrap-anywhere max-w-full`,children:`Appends a minimal-code directive to the system content, biasing the model toward the smallest working change. Higher strength pushes harder toward deletion over addition.`})]})]}),(0,$.jsxs)(q,{gap:`8px`,className:`shrink-0 items-center ml-auto`,children:[(0,$.jsx)(p,{id:`compression-ponytail-level`,"aria-label":`PonyTail strength`,value:n.ponyTailLevel,onValueChange:e=>t.mutate({ponyTailLevel:e===`lite`||e===`full`||e===`ultra`?e:`full`},{onError:e=>v.error(F(e,`Could not update PonyTail strength.`))}),options:[{value:`lite`,label:`Lite`},{value:`full`,label:`Full`},{value:`ultra`,label:`Ultra`}]}),(0,$.jsx)(G,{id:`compression-ponytail`,"aria-label":`Enable PonyTail`,checked:i,onChange:e=>t.mutate({ponyTailEnabled:e},{onError:e=>v.error(F(e,`Could not update PonyTail.`))})})]})]}),r||i?(0,$.jsxs)(`p`,{role:`note`,className:`flex gap-4 items-start m-0 py-4 px-5 rounded-inset border border-orange bg-orange-soft text-text-secondary text-badge`,children:[(0,$.jsx)(w,{size:14,className:`shrink-0 mt-0.5 text-orange`}),(0,$.jsx)(`span`,{children:`Your AI may produce degraded quality while compression is active: it sees a shortened history and a minimal-code directive, so fewer tokens but a chance of missing detail. Turn it off if answers get worse.`})]}):null]})})]})}function xt(){let{copied:e,copy:t}=B(2e3),n=`${window.location.origin}/v1`,r=async()=>{if(await t(n)){v.success(`Gateway endpoint copied`,n);return}v.error(`Clipboard unavailable on this origin`)};return(0,$.jsxs)(z,{children:[(0,$.jsx)(R,{title:`Gateway Endpoint`,subtitle:`Universal OpenAI & Anthropic Wire API Endpoint Compatible`,icon:(0,$.jsx)(g,{size:16})}),(0,$.jsx)(L,{children:(0,$.jsxs)(K,{gap:`10px`,children:[(0,$.jsxs)(`div`,{className:`nested-panel flex items-center gap-4 rounded-control border border-inner-border bg-code-surface px-7 py-5 font-mono text-body font-semibold tabular-nums`,children:[(0,$.jsx)(`code`,{className:`min-w-0 flex-1 truncate`,title:n,children:n}),(0,$.jsx)(_,{variant:`secondary`,size:`sm`,icon:e?(0,$.jsx)(d,{size:13}):(0,$.jsx)(y,{size:13}),"aria-label":`Copy endpoint`,title:`Copy endpoint`,onClick:()=>void r(),className:`shrink-0`,children:e?`Copied`:`Copy`})]}),(0,$.jsxs)(`p`,{className:`text-caption leading-normal text-text-secondary`,children:[`Point any SDK, CLI, or agent (e.g. OpenCode, Pi, OMP, Kilo, Cline, Droid and more clients) to this same-origin base URL.`,(0,$.jsxs)(`span`,{className:`mt-1 block text-text-tertiary`,children:[`You may not put `,(0,$.jsx)(`code`,{className:`font-mono`,children:`/v1`}),` on Claude Code — the CLI appends it itself.`]})]})]})})]})}function St(){return(0,$.jsxs)(K,{gap:`16px`,children:[(0,$.jsx)(xt,{}),(0,$.jsx)(bt,{}),(0,$.jsx)(yt,{})]})}export{St as default};
@@ -0,0 +1,3 @@
1
+ import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{r as i}from"./terminal-Bd4ee8TA.js";import{t as a}from"./arrow-left-CpBxkoxI.js";import{n as o,t as s}from"./brain-Cwed_72z.js";import{n as c,t as l}from"./fingerprint-pattern-BWuHtbW4.js";import{t as u}from"./check-D69FzdvC.js";import{n as d,t as f}from"./select-C9mMoEpJ.js";import{t as p}from"./circle-alert-CntYHV5v.js";import{t as m}from"./circle-check-BU3v_mFW.js";import{_ as h,a as g,g as _,i as v,r as y,t as b,v as x}from"./toast-C76WrMhc.js";import{t as S}from"./cog-CdWhsajs.js";import{t as C}from"./copy-ngmQ9zcZ.js";import{t as w}from"./download-A0SW9OCW.js";import{t as T}from"./eye-off-Bk5g2luF.js";import{t as E}from"./eye-C_hawfH4.js";import{t as D}from"./gauge-BbIMy7MB.js";import{t as O}from"./image-BPaouViG.js";import{a as k,n as A,r as j,t as M}from"./state-CzUPfLXo.js";import{t as N}from"./key-round-UkavsGxp.js";import{t as ee}from"./layers-2-glBbjl.js";import{n as P,t as F}from"./dialog-BWIP_EvW.js";import{t as I}from"./pencil-768ysRAr.js";import{t as te}from"./plus-DIdX_g-x.js";import{t as ne}from"./power-off-Yjw9GMJh.js";import{t as re}from"./refresh-cw-BqJFk4sU.js";import{t as ie}from"./rotate-ccw-CufcqITi.js";import{t as ae}from"./search-JOKus9rb.js";import{t as oe}from"./trash-Cppn5c3R.js";import{t as se}from"./wrench-B6E1oEuY.js";import{w as ce}from"./assert-7J6_LVD3.js";import{o as le,t as L}from"./query-keys-D7wX2vM5.js";import{E as R,F as ue,S as de,T as fe,X as pe,Y as me,Z as he,_ as ge,a as _e,b as ve,c as ye,d as z,f as be,g as xe,h as Se,l as Ce,m as we,o as Te,p as Ee,r as De,t as Oe,u as ke,v as B,w as Ae,x as je,y as Me}from"./entry-7dpgvpJ3.js";import{n as V,r as Ne,t as H}from"./card-B0Bnx5CA.js";import{n as Pe}from"./download-dRFo5_Wu.js";import{f as U,i as Fe,l as W,n as Ie,r as G,s as Le}from"./tokens-DDxMbSRL.js";import{a as Re}from"./numbers-CFL4_Dqc.js";import{t as K}from"./badge-BTyGk_DL.js";import{n as q}from"./input-B9oyU93y.js";import{t as ze}from"./ProviderIcon-paOCq8I0.js";import{t as Be}from"./switch-DOUIky_i.js";import{t as J}from"./stack-Ca5HxI5i.js";import{n as Y,t as Ve}from"./inline-D1TCqM2D.js";import{i as He}from"./quota-DZGyp0N5.js";import{t as Ue}from"./list-row-BVZzaoHF.js";import{c as We,l as Ge,m as Ke}from"./routing-BExgxxBU.js";import{o as X,s as qe,t as Je}from"./HealthEventsModal-CZkpn0a7.js";import{r as Ye}from"./privacy-mode-GM8bej85.js";import{n as Xe,t as Ze}from"./AccountCooldown-ChpdzxRH.js";import{t as Qe}from"./use-timeout-BwcBBRrT.js";import{t as $e}from"./banner-bujTWYM4.js";var et=e(`cable`,[[`path`,{d:`M17 19a1 1 0 0 1-1-1v-2a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v2a1 1 0 0 1-1 1z`,key:`trhst0`}],[`path`,{d:`M17 21v-2`,key:`ds4u3f`}],[`path`,{d:`M19 14V6.5a1 1 0 0 0-7 0v11a1 1 0 0 1-7 0V10`,key:`1mo9zo`}],[`path`,{d:`M21 21v-2`,key:`eo0ou`}],[`path`,{d:`M3 5V3`,key:`1k5hjh`}],[`path`,{d:`M4 10a2 2 0 0 1-2-2V6a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2a2 2 0 0 1-2 2z`,key:`1dd30t`}],[`path`,{d:`M7 5V3`,key:`1t1388`}]]),tt=e(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),nt=e(`info`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]),rt=e(`lock-open`,[[`rect`,{width:`18`,height:`11`,x:`3`,y:`11`,rx:`2`,ry:`2`,key:`1w4ew1`}],[`path`,{d:`M7 11V7a5 5 0 0 1 9.9-1`,key:`1mm8w8`}]]),it=e(`package-x`,[[`path`,{d:`M12 22V12`,key:`d0xqtd`}],[`path`,{d:`m16.5 14.5 5 5`,key:`ozpm51`}],[`path`,{d:`m16.5 19.5 5-5`,key:`syf6b9`}],[`path`,{d:`M21 10.5V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.729l7 4a2 2 0 0 0 2 .001l.13-.074`,key:`isw6gs`}],[`path`,{d:`M3.29 7 12 12l8.71-5`,key:`19ckod`}],[`path`,{d:`m7.5 4.27 8.997 5.148`,key:`9yrvtv`}]]),at=e(`repeat`,[[`path`,{d:`m17 2 4 4-4 4`,key:`nntrym`}],[`path`,{d:`M3 11v-1a4 4 0 0 1 4-4h14`,key:`84bu3i`}],[`path`,{d:`m7 22-4-4 4-4`,key:`1wqhfi`}],[`path`,{d:`M21 13v1a4 4 0 0 1-4 4H3`,key:`1rx37r`}]]),ot=e(`video`,[[`path`,{d:`m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5`,key:`ftymec`}],[`rect`,{x:`2`,y:`6`,width:`14`,height:`12`,rx:`2`,key:`158x01`}]]),st=e(`waypoints`,[[`path`,{d:`m10.586 5.414-5.172 5.172`,key:`4mc350`}],[`path`,{d:`m18.586 13.414-5.172 5.172`,key:`8c96vv`}],[`path`,{d:`M6 12h12`,key:`8npq4p`}],[`circle`,{cx:`12`,cy:`20`,r:`2`,key:`144qzu`}],[`circle`,{cx:`12`,cy:`4`,r:`2`,key:`muu5ef`}],[`circle`,{cx:`20`,cy:`12`,r:`2`,key:`1xzzfp`}],[`circle`,{cx:`4`,cy:`12`,r:`2`,key:`1hvhnz`}]]),ct=[`auto`,`minimal`,`low`,`medium`,`high`,`xhigh`,`max`];function lt(e,t){return t===null?e:`${e}(${t})`}var Z=t(n(),1),Q=r();function ut({to:e,label:t}){let n=me();return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{window.history.length>1?n(-1):n(e)},className:`inline-flex items-center gap-3 text-accent text-caption bg-transparent border-0 p-0 cursor-pointer`,children:[(0,Q.jsx)(a,{size:14,"aria-hidden":`true`}),t]})}function dt({title:e,description:t,icon:n,badges:r,actions:i,back:a}){return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[a?(0,Q.jsx)(ut,{...a}):null,(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-6 flex-wrap`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-5 min-w-0`,children:[n?(0,Q.jsx)(`div`,{className:`card-header-icon`,children:n}):null,(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,Q.jsx)(`h1`,{className:`text-lead font-bold`,children:e}),r]}),t?(0,Q.jsx)(`p`,{className:`mt-1 text-badge text-text-tertiary`,children:t}):null]})]}),i?(0,Q.jsx)(`div`,{className:g(`flex items-center gap-4 flex-wrap min-w-0 max-w-full`),children:i}):null]})]})}function ft(e){return e.isBuiltIn&&e.requiresAccount&&e.oauthFlows===void 0&&!e.hasAdapterUserAgent}function pt(e,t=600){let n=(0,Z.useRef)(void 0);return(0,Z.useEffect)(()=>()=>clearTimeout(n.current),[]),r=>{clearTimeout(n.current),n.current=setTimeout(()=>e(r),t)}}var mt={fallback:`Failover`,roundRobin:`Round robin`},ht=new Set([`inferhub`,`cline`]);function gt(e,t){let n=Ge(e),r=Ke(),[i,a]=(0,Z.useState)(`fallback`),[o,s]=(0,Z.useState)(1),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(`percent`),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(``);(0,Z.useEffect)(()=>{n.data&&(a(n.data.strategy),s(n.data.rotateCount),l(n.data.maxInflight),d(n.data.maxInflightPerProxy??null),p(n.data.usageFloor),h(n.data.usageFloorUnit),_(n.data.skipProxy),y(n.data.userAgent))},[n.data]);let b=i=>{r.mutate({providerId:e,request:{enabled:!0,strategy:i.strategy,rotateCount:i.rotateCount,maxInflight:i.maxInflight,maxInflightPerProxy:i.maxInflightPerProxy,usageFloor:i.usageFloor,usageFloorUnit:i.usageFloorUnit,skipProxy:i.skipProxy,...t?{userAgent:i.userAgent}:{}}},{onError:()=>{n.data&&(a(n.data.strategy),s(n.data.rotateCount),l(n.data.maxInflight),d(n.data.maxInflightPerProxy??null),p(n.data.usageFloor),h(n.data.usageFloorUnit),_(n.data.skipProxy),y(n.data.userAgent))}})},x=pt(e=>b({strategy:i,rotateCount:o,maxInflight:e,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),S=pt(e=>b({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:e,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),C=pt(e=>b({strategy:i,rotateCount:e,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})),w=pt(e=>b({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:e}));return{strategy:i,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,setUsageFloor:(e,t)=>{p(e),h(t),b({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:e,usageFloorUnit:t,skipProxy:g,userAgent:v})},skipProxy:g,userAgent:v,isLoading:n.isPending,isError:n.isError,isSaving:r.isPending,saveFailed:r.isError,refetch:()=>n.refetch(),setMaxInflight:e=>{l(e),x(e)},setMaxInflightPerProxy:e=>{d(e),S(e)},setUserAgent:e=>{y(e),w(e)},setSkipProxy:e=>{_(e),b({strategy:i,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:e,userAgent:v})},roundRobinEnabled:i===`round_robin`,setRoundRobinEnabled:e=>{let t=e?`round_robin`:`fallback`;a(t),b({strategy:t,rotateCount:o,maxInflight:c,maxInflightPerProxy:u,usageFloor:f,usageFloorUnit:m,skipProxy:g,userAgent:v})},rotateCount:o,setRotateCount:e=>{s(e),C(e)}}}var _t=50,vt=100;function yt(e,t,n){return[{value:``,label:`None`},{value:`Cartethyia/${e}`,label:`Cartethyia ${e}`},{value:`codex_cli_rs/${t}`,label:`Codex`},{value:`claude-cli/${n} (external, cli)`,label:`Claude Code`}]}function bt({children:e,action:t}){return(0,Q.jsx)(Ue,{actions:t,children:e})}function xt({providerId:e,clientVersion:t,routeIdentityVersions:n,userAgentEditable:r}){let i=gt(e,r),[a,o]=(0,Z.useState)(!1),s=ht.has(e),c=yt(Oe,n.codex,n.claude),u=c.some(e=>e.value===i.userAgent)?c:[...c,{value:i.userAgent,label:`Custom`}];if(i.isLoading)return(0,Q.jsx)(j,{label:`Loading routing...`});if(i.isError)return(0,Q.jsx)(A,{message:`Failed to load routing`,onRetry:i.refetch});let d=i.roundRobinEnabled?`${mt.roundRobin} · ${i.rotateCount} account${i.rotateCount===1?``:`s`} per rotation`:mt.fallback,p=i.isSaving?`Saving...`:i.saveFailed?`Save failed — reverted to last saved value`:`Active: ${d}`,m=i.maxInflight===null,h=m?51:Math.min(51,Math.max(1,i.maxInflight)),g=m?`∞`:String(i.maxInflight),_=i.maxInflightPerProxy===null,v=_?51:Math.min(51,Math.max(1,i.maxInflightPerProxy)),x=_?`∞`:String(i.maxInflightPerProxy),S=i.skipProxy,C=e=>{i.setRotateCount(Math.min(1e3,Math.max(1,i.rotateCount+e)))},w=e=>{if(e===i.userAgent)return;i.setUserAgent(e);let t=u.find(t=>t.value===e)?.label??e;b.success(`Client identity updated`,t)},T=t?`${t.client} ${t.version}`:`Provider default`;return(0,Q.jsxs)(H,{children:[(0,Q.jsx)(Ne,{title:`Routing Strategy`,subtitle:p,icon:(0,Q.jsx)(ee,{size:16})}),(0,Q.jsx)(V,{children:(0,Q.jsxs)(`div`,{className:`grid gap-5 w-full min-w-0`,children:[(0,Q.jsx)(bt,{action:(0,Q.jsxs)(Q.Fragment,{children:[i.roundRobinEnabled?(0,Q.jsxs)(`div`,{role:`group`,"aria-label":`Accounts per rotation`,className:`inline-flex items-center gap-1 rounded-control border border-inner-border bg-surface-1 p-1`,children:[(0,Q.jsx)(`span`,{className:`px-2 text-badge text-text-secondary`,children:`Accounts/rotation`}),(0,Q.jsx)(y,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Decrease accounts per rotation`,disabled:i.rotateCount<=1,icon:(0,Q.jsx)(P,{size:14}),onClick:()=>C(-1)}),(0,Q.jsx)(`output`,{className:`min-w-8 text-center text-body font-semibold tabular-nums`,"aria-live":`polite`,children:i.rotateCount}),(0,Q.jsx)(y,{variant:`ghost`,size:`icon`,className:`size-9 rounded-tiny`,"aria-label":`Increase accounts per rotation`,disabled:i.rotateCount>=1e3,icon:(0,Q.jsx)(te,{size:14}),onClick:()=>C(1)})]}):null,(0,Q.jsx)(Be,{checked:i.roundRobinEnabled,onChange:i.setRoundRobinEnabled,id:`routing-round-robin`})]}),children:(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`label`,{htmlFor:`routing-round-robin`,children:(0,Q.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(at,{size:15,"aria-hidden":`true`,className:`shrink-0 ${i.roundRobinEnabled?`text-accent`:`text-text-tertiary`}`}),`Round robin`]})}),(0,Q.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Off uses priority order with failover. On rotates requests across this provider's accounts.`})]})}),(0,Q.jsx)(bt,{action:(0,Q.jsx)(Be,{checked:i.skipProxy,onChange:i.setSkipProxy,id:`routing-skip-proxy`}),children:(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`label`,{htmlFor:`routing-skip-proxy`,children:(0,Q.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(et,{size:15,"aria-hidden":`true`,className:`shrink-0 ${i.skipProxy?`text-accent`:`text-text-tertiary`}`}),`Always direct`]})}),(0,Q.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Bypass automatic proxy-pool routing for this provider and always dial direct`})]})}),(0,Q.jsxs)(`div`,{className:`routing-controls-grid grid gap-5 min-w-0 w-full`,children:[(0,Q.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0`,children:[(0,Q.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold mb-3`,children:[(0,Q.jsx)(l,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Client identity`]}),r?(0,Q.jsx)(f,{id:`routing-user-agent-preset`,"aria-label":`Client identity`,value:i.userAgent,options:u,onValueChange:w}):(0,Q.jsx)(f,{id:`routing-user-agent-fixed`,"aria-label":`Client identity`,disabled:!0,value:T,options:[{value:T,label:T}]}),(0,Q.jsx)(`div`,{className:`text-badge text-text-tertiary mt-2`,children:r?`Sent when the provider has no identity of its own.`:`Set by the provider. It cannot be changed.`})]}),(0,Q.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0`,children:[(0,Q.jsx)(`label`,{htmlFor:`routing-max-inflight`,className:`form-label`,children:(0,Q.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(D,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Max inflight / account`]})}),(0,Q.jsxs)(`div`,{className:`text-badge text-text-tertiary mb-3`,children:[`Shared provider ceiling. One step past `,_t,` is unlimited.`]}),(0,Q.jsxs)(Y,{gap:`10px`,className:`mt-3`,children:[(0,Q.jsx)(`input`,{id:`routing-max-inflight`,type:`range`,className:`routing-slider flex-1 min-w-0`,"data-unlimited":m?`true`:void 0,min:1,max:51,step:1,value:h,"aria-valuetext":m?`Unlimited`:String(i.maxInflight),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&i.setMaxInflight(t>_t?null:Math.round(t))},style:{"--slider-pct":`${h/51*100}%`}}),(0,Q.jsx)(`input`,{type:`text`,inputMode:`numeric`,"aria-label":`Max inflight per account`,value:g,onChange:e=>{let t=e.target.value.trim();if(t===``||t===`∞`){i.setMaxInflight(null);return}let n=Number(t);Number.isFinite(n)&&n>=1&&i.setMaxInflight(Math.min(vt,Math.round(n)))},className:`form-input w-26 shrink-0 px-2 py-3 text-center text-body ${m?`text-status-success`:``}`})]})]})]}),(0,Q.jsxs)(`div`,{className:`px-6 py-5 rounded-control border border-inner-border bg-surface-2 min-w-0${S?` opacity-60`:``}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,Q.jsxs)(`label`,{htmlFor:`routing-max-inflight-per-proxy`,className:`min-w-0`,children:[(0,Q.jsxs)(Y,{gap:`6px`,className:`text-body font-semibold`,children:[(0,Q.jsx)(st,{size:15,"aria-hidden":`true`,className:`text-text-tertiary shrink-0`}),`Max inflight / proxy`]}),(0,Q.jsx)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:`Each proxy pool carries at most this many concurrent requests for this provider. Other providers on the same pool are unaffected.`})]}),(0,Q.jsx)(y,{variant:`ghost`,size:`sm`,className:`shrink-0`,"aria-label":`How per-proxy limits work`,onClick:()=>o(!0),children:`How it works`})]}),(0,Q.jsxs)(Y,{gap:`10px`,className:`mt-3`,children:[(0,Q.jsx)(`input`,{id:`routing-max-inflight-per-proxy`,type:`range`,className:`routing-slider flex-1 min-w-0`,"data-unlimited":_?`true`:void 0,min:1,max:51,step:1,disabled:S,value:v,"aria-valuetext":_?`Unlimited`:String(i.maxInflightPerProxy),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&i.setMaxInflightPerProxy(t>_t?null:Math.round(t))},style:{"--slider-pct":`${v/51*100}%`}}),(0,Q.jsx)(`input`,{type:`text`,inputMode:`numeric`,"aria-label":`Max inflight per proxy`,disabled:S,value:x,onChange:e=>{let t=e.target.value.trim();if(t===``||t===`∞`){i.setMaxInflightPerProxy(null);return}let n=Number(t);Number.isFinite(n)&&n>=1&&i.setMaxInflightPerProxy(Math.min(vt,Math.round(n)))},className:`form-input w-26 shrink-0 px-2 py-3 text-center text-body ${_?`text-status-success`:``}`})]}),(0,Q.jsx)(`div`,{className:`mt-2 text-badge text-text-tertiary`,children:S?`Always direct is on, so this provider never dials a pool. The limit is kept for when a pool is used again.`:`One step past ${_t} is unlimited.`})]}),(0,Q.jsx)(F,{open:a,onClose:()=>o(!1),title:`How concurrency limits stack`,size:`md`,children:(0,Q.jsxs)(`div`,{className:`grid gap-4 text-body`,children:[(0,Q.jsx)(`p`,{className:`text-text-secondary`,children:`Three limits apply at once. Each one bounds a different thing; none replaces another.`}),(0,Q.jsxs)(`dl`,{className:`grid gap-3`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Max inflight / account`}),(0,Q.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`One account of this provider, across every proxy. Set here, above.`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Max inflight / proxy`}),(0,Q.jsxs)(`dd`,{className:`text-badge text-text-tertiary`,children:[`One proxy pool's concurrent requests `,(0,Q.jsx)(`em`,{children:`for this provider`}),`. The same number applies to every pool; each pool counts separately. This is the field above.`]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`dt`,{className:`font-semibold`,children:`Pool capacity`}),(0,Q.jsx)(`dd`,{className:`text-badge text-text-tertiary`,children:`Everything through one pool, all providers combined. Set on the proxy itself, on the Proxies page.`})]})]}),(0,Q.jsxs)(`p`,{className:`text-badge text-text-tertiary`,children:[`A request must clear all three. When a pool is full for this provider, the request moves to another pool that still has room; it only fails with`,` `,(0,Q.jsx)(`code`,{children:`429`}),` when every pool is full.`]}),(0,Q.jsx)(`p`,{className:`text-badge text-text-tertiary`,children:`Unlimited means no counter is kept for this provider, so the limit costs nothing until you set one.`})]})}),s&&(0,Q.jsxs)(Y,{gap:`6px`,align:`flex-start`,className:`mt-1 text-badge text-text-tertiary`,children:[(0,Q.jsx)(nt,{size:12,className:`shrink-0 mt-0.5`}),(0,Q.jsx)(`span`,{children:`This provider doesn't reliably work through a plain HTTP/S proxy — use a SOCKS5 or proxy pool instead if you need to route it.`})]})]})})]})}function St({providerId:e}){let t=gt(e,!1),n=X(),r=We(e),i=(0,Z.useMemo)(()=>wt(n.data?.accounts??[],e),[n.data,e]),a=(0,Z.useRef)(null),o=(0,Z.useMemo)(()=>[...r.data?.values()??[]].reduce((e,t)=>e+t,0),[r.data]);(0,Z.useEffect)(()=>{if(a.current===null){a.current=o;return}a.current!==o&&(a.current=o,n.refetch())},[o,n]);let[s,c]=(0,Z.useState)(`40`),[l,u]=(0,Z.useState)(`percent`),d=t.usageFloor!==null;(0,Z.useEffect)(()=>{t.usageFloor!==null&&c(String(t.usageFloor)),u(t.usageFloorUnit)},[t.usageFloor,t.usageFloorUnit]);let f=Number(s),p=Number.isInteger(f)&&f>=0&&f<=1e6,m=i===null||i.remaining<=0?`text-status-danger`:i.percent<=10?`text-status-warning`:`text-status-success`,h=(e,n)=>{(e===null||p)&&t.setUsageFloor(e,n)};return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`section`,{className:`usage-floor-panel flex flex-col gap-4 px-5 py-4 border border-inner-border rounded-narrow bg-surface-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 text-body font-semibold text-text-primary`,children:[(0,Q.jsx)(D,{size:14}),(0,Q.jsx)(`span`,{children:`Usage floor`}),(0,Q.jsx)(`span`,{className:`badge border border-warning-line bg-surface-2 text-micro tracking-label text-status-warning`,children:`BETA`})]}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-badge leading-normal text-text-tertiary`,children:`Per account. Skip an account once its remaining allowance reaches this, and send the request to the next one.`})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[i!==null&&(0,Q.jsxs)(`div`,{className:`flex min-h-24 min-w-0 flex-[1_1_20rem] flex-col justify-center gap-2 py-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-micro font-semibold tracking-label uppercase text-text-tertiary`,children:[(0,Q.jsx)(`span`,{children:`Pooled credits`}),(0,Q.jsx)(`span`,{className:`text-text-primary`,children:i.accounts}),(0,Q.jsx)(`span`,{children:i.accounts===1?`active account`:`active accounts`})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1 text-caption font-semibold tabular-nums text-text-primary`,title:`Combined allowance across active accounts; the usage floor is evaluated per account`,children:[(0,Q.jsx)(`strong`,{className:`font-bold ${m}`,children:Tt(i.remaining)}),(0,Q.jsx)(`span`,{className:`font-medium text-text-secondary`,children:`credits available`}),(0,Q.jsxs)(`span`,{className:`font-medium opacity-75`,children:[`of `,Tt(i.total)]}),(0,Q.jsxs)(`span`,{className:`font-bold ${m}`,children:[i.percent,`%`]})]}),(0,Q.jsx)(`p`,{className:`text-micro leading-normal text-text-tertiary`,children:t.usageFloor===null?`Floor off · exhausted quota windows are still skipped`:`Floor ${Tt(t.usageFloor)} ${t.usageFloorUnit===`credit`?`credits`:`%`} per account`})]}),i===null&&(0,Q.jsxs)(`p`,{className:`flex min-h-24 min-w-0 flex-[1_1_20rem] flex-col justify-center gap-2 py-2 text-badge leading-normal text-text-tertiary`,children:[(0,Q.jsx)(`span`,{children:`No combined credit balance is available. Separate quota windows are not added together, and exhausted windows are still skipped.`}),(0,Q.jsx)(`span`,{className:`text-micro`,children:t.usageFloor===null?`Floor off · exhausted quota windows are still skipped`:`Floor ${Tt(t.usageFloor)} ${t.usageFloorUnit===`credit`?`credits`:`%`} per account`})]}),(0,Q.jsxs)(`div`,{className:`ml-auto flex max-w-full shrink-0 flex-col items-end justify-center gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-x-3 gap-y-2`,children:[(0,Q.jsx)(`span`,{className:`text-micro font-semibold tracking-label uppercase text-text-tertiary`,children:`Floor threshold`}),(0,Q.jsxs)(`label`,{className:`flex h-12 max-w-full items-center overflow-hidden rounded-tiny border border-inner-border bg-surface-1 focus-within:border-text-tertiary`,children:[(0,Q.jsx)(`input`,{type:`number`,min:0,max:1e6,value:d?s:``,placeholder:`40`,disabled:!d,"aria-label":`Usage floor amount`,className:`h-full w-24 border-0 bg-transparent px-3 text-right font-mono text-body font-semibold tabular-nums text-text-primary disabled:text-text-tertiary`,onChange:e=>c(e.target.value),onBlur:()=>{d&&h(f,l)}}),(0,Q.jsxs)(`select`,{value:l,disabled:!d,"aria-label":`Usage floor unit`,className:`h-full border-0 border-l border-inner-border bg-hover px-3 text-body font-semibold text-text-secondary disabled:cursor-default disabled:opacity-60`,onChange:e=>{let t=e.target.value===`credit`?`credit`:`percent`;u(t),d&&h(f,t)},children:[(0,Q.jsx)(`option`,{value:`percent`,children:`%`}),(0,Q.jsx)(`option`,{value:`credit`,children:`credits`})]})]}),(0,Q.jsx)(Be,{checked:d,label:`Enabled`,"aria-label":`Usage floor`,className:`usage-floor-switch`,onChange:e=>h(e?p?f:40:null,l)})]}),t.saveFailed?(0,Q.jsx)(`p`,{role:`alert`,className:`text-right text-micro leading-normal text-status-danger`,children:`Usage floor save failed. The last saved setting has been restored.`}):null]})]})]}),(0,Q.jsx)(Ct,{providerId:e})]})}function Ct({providerId:e}){let{enabled:t,setEnabled:n}=Ye(e);return(0,Q.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-6 px-6 py-5 border border-inner-border rounded-control bg-surface-2`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-auto basis-110`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 text-body font-semibold text-text-primary`,children:[(0,Q.jsx)(T,{size:14}),(0,Q.jsx)(`span`,{children:`Mysterious accounts`})]}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-badge leading-normal text-text-tertiary`,children:`Hide this provider's emails and usernames. Stored in this browser only.`})]}),(0,Q.jsx)(`div`,{className:`flex items-center gap-4 shrink-0`,children:(0,Q.jsx)(Be,{checked:t,"aria-label":`Mysterious accounts`,onChange:n})})]})}function wt(e,t){let n=0,r=0,i=0,a=!1;for(let o of e)if(o.provider===t&&o.active&&(i+=1,o.quota!==null))for(let e of o.quota.windows){if(e.accounting!==`pooled`)continue;let t=typeof e.limit==`number`&&Number.isFinite(e.limit)?e.limit:null;if(t===null)continue;let i=typeof e.remaining==`number`&&Number.isFinite(e.remaining)?e.remaining:typeof e.used==`number`&&Number.isFinite(e.used)?t-e.used:null;i!==null&&(n+=Math.min(t,Math.max(0,i)),r+=t,a=!0)}return i>0&&a?{accounts:i,remaining:n,total:r,percent:r>0?Math.round(n/r*100):0}:null}function Tt(e){return e.toLocaleString(void 0,{maximumFractionDigits:1})}function Et({provider:e}){let t=e.credentialUrl,n=e.credentialHint,r=e.operatorNotice;if(!t&&!n&&!r)return null;let i=e.oauthFlows?.browser===!0||e.oauthFlows?.device===!0,a=n??(i?`This provider authorizes through its own login flow; there is no key to paste.`:e.requiresAccount?`Create a credential on the provider site, then add it as an account below.`:`This provider needs no credential.`);return(0,Q.jsx)(H,{density:`compact`,children:(0,Q.jsx)(V,{children:(0,Q.jsxs)(Y,{gap:`12px`,className:`items-center flex-wrap`,children:[(0,Q.jsxs)(`span`,{className:`min-w-110 flex-1 text-caption text-text-secondary`,children:[a,r?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`br`,{}),r]}):null]}),t?(0,Q.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,title:t,className:v({size:`sm`,className:`shrink-0 no-underline`}),children:[(0,Q.jsx)(`span`,{className:`btn-icon-wrapper`,"aria-hidden":`true`,children:(0,Q.jsx)(tt,{size:13})}),i?`Sign in`:`Get API Key`]}):null]})})})}var Dt={quota_fetch_failed:`Quota unreachable`,quota_exhausted:`Quota exhausted`,policy_blocked:`Policy blocked`,rate_limit_transient:`Rate limited`,missing_credential:`No credential`},Ot=new Set([`quota_fetch_failed`]);function kt(e){return e===void 0||e.length===0?!1:!Ot.has(e)}function At(e){return e===`oauth`?`Re-login required`:`Replace API key`}function jt(e,t){return e===`auth_invalidated`?At(t):Dt[e]??e}async function Mt(e,t,n){let r=Array(e.length),i=Math.max(1,Math.min(t,e.length)),a=0;return await Promise.all(Array.from({length:i},async()=>{for(;;){let t=a;if(t>=e.length)return;a+=1;try{r[t]={status:`fulfilled`,value:await n(e[t],t)}}catch(e){r[t]={status:`rejected`,reason:e}}}})),r}var Nt=[`access`,`accessToken`,`access_token`,`sessionToken`,`session_token`,`token`,`apiKey`,`api_key`,`key`,`credential`,`pat`,`secret`],Pt=[`refresh`,`refreshToken`,`refresh_token`],Ft=[`credentialKind`,`providerId`,`accessToken`],It=[`accounts`,`items`,`connections`],Lt=[`email`,`name`,`accountId`,`account_id`,`id`,`login`,`username`];function $(e){if(typeof e==`object`&&e&&!Array.isArray(e))return Object.fromEntries(Object.entries(e))}function Rt(e){let t=e.data;if(typeof t==`string`)try{return $(JSON.parse(t))}catch{return}return $(t)}function zt(e){for(let t of Nt){let n=e[t];if(typeof n==`string`&&n.trim().length>0)return{value:n.trim(),extracted:!0,source:t}}let t=Rt(e);if(t)for(let e of Nt){let n=t[e];if(typeof n==`string`&&n.trim().length>0)return{value:n.trim(),extracted:!0,source:`data.${e}`}}}function Bt(e){for(let t of Lt){let n=e[t];if(typeof n==`string`&&n.trim().length>0)return n.trim()}let t=Rt(e);if(t)for(let e of Lt){let n=t[e];if(typeof n==`string`&&n.trim().length>0)return n.trim()}}function Vt(e){let t=e=>Pt.some(t=>typeof e[t]==`string`||typeof e[t]==`number`);if(t(e))return!0;let n=Rt(e);return n?t(n):!1}function Ht(e){let t=e.trim().split(`.`);if(t.length===3)try{let e=t[1].replaceAll(`-`,`+`).replaceAll(`_`,`/`),n=e.padEnd(e.length+(4-e.length%4)%4,`=`);return $(JSON.parse(atob(n)))}catch{return}}function Ut(e){let t=Ht(e)?.exp;if(typeof t!=`number`||!Number.isFinite(t))return;let n=new Date(t*1e3);return Number.isFinite(n.getTime())?n.toISOString():void 0}function Wt(e){let t={},n=0;for(let r of e.split(/\r?\n/)){let e=/^\s*([A-Za-z_][\w-]*)\s*:\s*(.*)$/.exec(r),i=e?.[1],a=e?.[2];i!==void 0&&a!==void 0&&(t[i]=a.trim(),n+=1)}return n>0?t:void 0}function Gt(e){if(e.startsWith(`{`)||e.startsWith(`[`))try{return JSON.parse(e)}catch{return}}function Kt(e){let t=e.trim(),n=$(Gt(t))??Wt(t);return n&&Vt(n)?`oauth`:Ht((n?zt(n)?.value:void 0)??t)===void 0?`api_key`:`jwt`}function qt(e){return e.length!==0&&!!(e.some(e=>Array.isArray(e.cookies)&&(typeof e.domain==`string`||typeof e.originalUrl==`string`))||e.every(e=>typeof e.name==`string`&&typeof e.value==`string`&&(e.domain!==void 0||e.path!==void 0||e.expirationDate!==void 0)))}function Jt(e,t){let n,r=!1,i=(e,t)=>{let i=e.toLowerCase();(i===`userid`||i===`uid`||i===`accountid`||i===`cuserid`)&&(n||=t.replace(/^"|"$/g,``).trim()),(i.includes(`token`)||i.includes(`ph`)||i.includes(`auth`)||i.includes(`session`))&&(r=!0)};for(let e of t)if(Array.isArray(e.cookies)){for(let t of e.cookies)if(t&&typeof t==`object`){let e=t;typeof e.name==`string`&&typeof e.value==`string`&&i(e.name,e.value)}}else typeof e.name==`string`&&typeof e.value==`string`&&i(e.name,e.value);return{value:e,kind:r?`oauth`:`api_key`,...n?{identity:n}:{}}}function Yt(e){let t=e.credentialKind;if(typeof t==`string`&&typeof e.accessToken==`string`&&Ft.every(t=>t in e)){let n=typeof e.label==`string`&&e.label.trim().length>0?e.label.trim():void 0,r=e.accessToken,i=t===`oauth`&&Vt(e);return{value:i?JSON.stringify(e):r,kind:i?`oauth`:`api_key`,...n?{identity:n}:{}}}let n=zt(e),r=Vt(e)?`oauth`:Kt(n?.value??JSON.stringify(e)),i=r===`oauth`?JSON.stringify(e):n?.value??JSON.stringify(e),a=Bt(e);return a?{value:i,kind:r,identity:a}:{value:i,kind:r}}function Xt(e){for(let t of It){let n=e[t];if(!Array.isArray(n))continue;let r=n.map(e=>$(e)).filter(e=>e!==void 0);if(r.length>0)return r}}function Zt(e){let t=e.trim();if(!t)return[];let n=Gt(t);if(Array.isArray(n)){let e=n.map(e=>$(e)).filter(e=>e!==void 0);if(e.length>0)return qt(e)?[Jt(t,e)]:e.map(Yt)}else{let e=$(n);if(e){let t=Xt(e);return t?t.map(Yt):[Yt(e)]}}let r=t.split(/\r?\n/).map(e=>e.trim()).filter(e=>e.length>0);if(r.length===0)return[];if(r.length===1)return Qt(r[0]);let i=Wt(t);return i&&(zt(i)||Object.keys(i).length===r.length)?[Yt(i)]:r.flatMap(Qt)}function Qt(e){let t=$(Gt(e));if(t){let e=Xt(t);return e?e.map(Yt):[Yt(t)]}return[{value:e,kind:Kt(e)}]}function $t(e,t,n){let r=new Set(n),i=1;return e.map(e=>{let n=e.identity;if(!n){for(;r.has(`${t}-${i}`);)i+=1;n=`${t}-${i}`,i+=1}let a=n,o=2;for(;r.has(a);)a=`${n} (${o++})`;return r.add(a),a})}function en(e){return e===`active`?0:e===`cooldown`?2:3}function tn(e){if(e===void 0)return;let t=new Date(e).getTime();if(Number.isFinite(t))return t<=Date.now()?`Expired ${new Date(e).toLocaleDateString()}`:He(e,!1)}function nn({cooldowns:e,reason:t}){if(!e)return null;let n=He(e.until),r=`Soonest: ${e.modelId} — ${n}`;return(0,Q.jsxs)(K,{tone:`warn`,dot:!0,title:t?`${t} — ${r}`:r,children:[e.count,` model`,e.count===1?``:`s`,` cooling · `,n]})}function rn(e){if(e.credentialKind===`oauth`)return`OAuth`;if(e.credentialMode===`jwt`)return`JWT`}function an(e){return e.credentialKind===`oauth`?`blue`:`ok`}function on({account:e}){let t=e.cooldownUntil?new Date(e.cooldownUntil).getTime():NaN,n=Number.isFinite(t)&&t>Date.now(),r=Ze(e);if(e.status===`disabled`){let t=rn(e),n=e.lastErrorCategory===`auth_invalidated`;return(0,Q.jsxs)(Y,{gap:`4px`,children:[(0,Q.jsxs)(K,{tone:`disabled`,dot:!0,title:e.lastError,children:[`Disabled`,t?` - ${t}`:``]}),n?(0,Q.jsx)(K,{tone:`warn`,title:e.lastError,children:At(e.credentialKind)}):kt(e.lastErrorCategory)&&!(e.lastErrorCategory===`quota_exhausted`&&r)?(0,Q.jsx)(K,{tone:`warn`,title:e.lastError??e.lastErrorCategory,children:jt(e.lastErrorCategory,e.credentialKind)}):null,(0,Q.jsx)(nn,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]})}return e.status===`active`?(0,Q.jsxs)(Y,{gap:`4px`,children:[(0,Q.jsxs)(K,{tone:an(e),dot:!0,children:[`Active`,rn(e)?` - ${rn(e)}`:``]}),kt(e.lastErrorCategory)&&!(e.lastErrorCategory===`quota_exhausted`&&r)?(0,Q.jsx)(K,{tone:`warn`,title:e.lastError??e.lastErrorCategory,children:jt(e.lastErrorCategory,e.credentialKind)}):null,(0,Q.jsx)(nn,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]}):e.status===`cooldown`||n?(0,Q.jsxs)(Y,{gap:`4px`,children:[(0,Q.jsxs)(K,{tone:`warn`,dot:!0,children:[`Cooldown`,rn(e)?` - ${rn(e)}`:``,` `,e.cooldownUntil?`(${He(e.cooldownUntil)})`:``]}),kt(e.lastErrorCategory)&&!(e.lastErrorCategory===`quota_exhausted`&&r)?(0,Q.jsx)(K,{tone:`warn`,title:e.lastError??e.lastErrorCategory,children:jt(e.lastErrorCategory,e.credentialKind)}):null,(0,Q.jsx)(nn,{cooldowns:r,reason:e.lastErrorCategory===`quota_exhausted`?e.lastError:void 0})]}):(0,Q.jsx)(K,{tone:`disabled`,children:`Disabled`})}function sn({windows:e}){if(e===void 0||e.length===0)return null;let t=0,n=0,r=!1,i=null;for(let a of e){if(a.accounting!==`pooled`){typeof a.remainingPercent==`number`&&Number.isFinite(a.remainingPercent)&&(i=i===null?a.remainingPercent:Math.min(i,a.remainingPercent));continue}let e=typeof a.limit==`number`&&Number.isFinite(a.limit)?a.limit:null,o=typeof a.remaining==`number`&&Number.isFinite(a.remaining)?a.remaining:e!==null&&typeof a.used==`number`&&Number.isFinite(a.used)?e-a.used:null;o!==null&&e!==null&&(t+=Math.max(0,o),n+=e,r=!0)}let a=null;return r?a=`${cn(t)} of ${cn(n)}`:i!==null&&(a=`${Math.round(i)}% left`),a===null?null:(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,"data-tone":r&&t<=0||(i??100)<=10?`warn`:void 0,title:r?`${cn(t)} credits available of ${cn(n)}`:`Lowest remaining percent across this account's quota windows`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Quota`}),a]})}function cn(e){return e.toLocaleString(void 0,{maximumFractionDigits:1})}function ln({providerId:e,account:t,onClose:n}){let r=R(),[i,a]=(0,Z.useState)(``),o=t.label||t.id.slice(0,8),s=r.isPending,c=i.trim().length>0&&!s,l=async()=>{try{a(await navigator.clipboard.readText())}catch{b.error(`Clipboard access denied`)}};return(0,Q.jsx)(F,{open:!0,onClose:n,title:`Replace API key — ${o}`,width:560,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,onClick:n,disabled:s,children:`Cancel`}),(0,Q.jsx)(y,{size:`sm`,variant:`primary`,disabled:!c,onClick:()=>{let a=i.trim();a&&r.mutate({providerId:e,accountId:t.id,request:{secret:a}},{onSuccess:()=>{b.success(`API key replaced`,o),n()},onError:e=>{let t=e instanceof Error?e.message:`Unable to update account`;b.error(`Failed to replace key`,t)}})},children:s?`Saving…`:`Replace key`})]}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(`p`,{className:`m-0 text-caption text-text-secondary`,children:`Paste the new key for this account. The old key stops working immediately; the account keeps its label, history, and routing.`}),(0,Q.jsxs)(J,{gap:`6px`,className:`min-w-0`,children:[(0,Q.jsx)(`label`,{className:`text-caption font-semibold text-text-secondary`,children:`New API key`}),(0,Q.jsx)(`textarea`,{value:i,onChange:e=>a(e.target.value),placeholder:`Paste the replacement key…`,rows:4,spellCheck:!1,autoFocus:!0,className:`font-mono tabular-nums w-full min-w-0 min-h-65 rounded-control border border-inner-border bg-input-bg px-6 py-5 text-caption text-text-primary resize-y box-border`}),(0,Q.jsx)(Y,{gap:`8px`,className:`justify-end`,children:(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,onClick:()=>void l(),children:`Paste`})})]})]})})}function un({providerId:e,account:t,inflight:n,quota:r,selected:a,onToggleSelect:o,onDelete:s}){let c=R(),l=ge(),u=qe(t.id),d=t.status===`disabled`,f=t.cooldownUntil?new Date(t.cooldownUntil).getTime():NaN,p=Number.isFinite(f)&&f>Date.now(),m=t.status===`cooldown`||p,[h,g]=(0,Z.useState)(!1),[v,S]=(0,Z.useState)(!1),[,C]=(0,Z.useState)(0),[w,T]=(0,Z.useState)(!1),[E,D]=(0,Z.useState)(``),O=Ye(e),k=(t.label?.match(/[^\s@]+@[^\s@]+/)?.[0]??t.label)||t.id.slice(0,8),A=O.enabled?`Mysterious accounts`:k,j=tn(t.tokenExpiresAt),M=Xe(t),ee=Math.max(p&&t.cooldownUntil?f:0,M??0);(0,Z.useEffect)(()=>{if(ee<=Date.now())return;let e=setInterval(()=>C(e=>e+1),1e3);return()=>clearInterval(e)},[ee]);let P=()=>{let n=E.trim();T(!1),n&&n!==(t.label??``)&&c.mutate({providerId:e,accountId:t.id,request:{label:n}},{onSuccess:()=>b.success(`Account renamed`,n),onError:e=>b.error(`Rename failed`,e.message??`Unable to rename account`)})};return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`account-row account-row-grid grid items-center gap-5 px-5 py-4 border rounded-control bg-surface-2 ${a?`border-accent`:`border-inner-border`} hover:bg-hover`,role:`listitem`,"data-selected":a?`true`:void 0,style:{opacity:d?.62:1},children:[(0,Q.jsx)(`div`,{className:`flex items-center`,children:(0,Q.jsx)(`input`,{type:`checkbox`,checked:a,onChange:e=>o(t.id,e.target.checked),"aria-label":`Select ${A}`,className:`cursor-pointer`})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex flex-col gap-1.5`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-3 min-w-0`,children:w?(0,Q.jsx)(q,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&P(),e.key===`Escape`&&T(!1)},onBlur:P,autoFocus:!0,"aria-label":`Account label`,className:`text-body max-w-120`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`text-body font-semibold text-text-primary min-w-0 overflow-hidden text-ellipsis whitespace-nowrap`,title:t.label||t.id,children:A}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 grid place-items-center w-10 h-10 p-0 border-0 bg-transparent text-text-tertiary cursor-pointer rounded-tiny hover:bg-inner-border hover:text-text-primary`,title:`Rename account`,"aria-label":`Rename ${A}`,onClick:()=>{D(t.label??``),T(!0)},children:(0,Q.jsx)(I,{size:11})})]})}),(0,Q.jsxs)(`div`,{className:`flex items-center flex-nowrap gap-2 min-w-0 overflow-hidden`,children:[(0,Q.jsx)(on,{account:t}),j?(0,Q.jsx)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:j,children:j}):null]}),(0,Q.jsxs)(`div`,{className:`flex items-center flex-wrap gap-2 min-w-0`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Today: ${t.usageToday.totalTokens.toLocaleString()} tokens, ${t.usageToday.requests.toLocaleString()} requests`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`Today`}),t.usageToday.totalTokens.toLocaleString(),` tok · `,t.usageToday.requests.toLocaleString(),` req`]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Lifetime totals are backfilled from telemetry still retained when tracking starts; new totals survive telemetry cleanup.`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`All time`}),t.usageAllTime.totalTokens.toLocaleString(),` tok · `,t.usageAllTime.requests.toLocaleString(),` req`]}),(0,Q.jsx)(sn,{windows:r}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2.5 max-w-full px-3.5 py-1 border border-inner-border rounded-chip bg-surface-1 text-text-secondary text-badge leading-normal whitespace-nowrap`,title:`Concurrency comes from this provider’s Routing Strategy; accounts no longer carry manual ceilings.`,children:[(0,Q.jsx)(`span`,{className:`text-text-tertiary text-micro font-semibold uppercase tracking-label`,children:`In flight`}),n?.toLocaleString()??`—`]})]})]}),(0,Q.jsxs)(`div`,{className:`account-row-actions flex items-center justify-end gap-3 flex-wrap`,children:[(0,Q.jsx)(y,{size:`icon`,variant:`secondary`,icon:(0,Q.jsx)(i,{size:12}),label:`Health`,"aria-label":`Health for ${A}`,onClick:()=>g(!0),title:`View Health & Error History`}),(0,Q.jsx)(y,{size:`icon`,variant:`secondary`,icon:u.isPending?(0,Q.jsx)(_,{size:12,className:`animate-spin`}):(0,Q.jsx)(x,{size:12}),label:u.isPending?`Testing…`:`Test`,"aria-label":`Test ${A}`,disabled:u.isPending,onClick:()=>{u.mutate(void 0,{onSuccess:e=>{e?.ok?b.success(`Account test passed`,A):b.error(`Account test failed`,e?.message??`Provider reported an error`)},onError:e=>b.error(`Account test failed`,e.message??`Unable to test account`)})},title:`Refresh quota and health for this account`}),(0,Q.jsx)(y,{size:`icon`,variant:`secondary`,icon:(0,Q.jsx)(N,{size:12}),label:`Edit key`,"aria-label":`Replace API key for ${A}`,onClick:()=>S(!0),title:`Replace API key`}),(0,Q.jsx)(y,{size:`icon`,variant:`secondary`,icon:d?(0,Q.jsx)(rt,{size:12}):(0,Q.jsx)(ne,{size:12}),label:d?`Enable`:`Disable`,"aria-label":d?`Enable ${A}`:`Disable ${A}`,disabled:c.isPending,onClick:()=>{let n=d;c.mutate({providerId:e,accountId:t.id,request:{status:n?`active`:`disabled`}},{onSuccess:()=>b.success(n?`Account enabled`:`Account disabled`,A),onError:e=>b.error(`Update failed`,e.message??`Unable to update account`)})},title:d?`Enable account`:`Disable account`}),m?(0,Q.jsx)(y,{size:`icon`,variant:`secondary`,icon:(0,Q.jsx)(ie,{size:12,className:l.isPending?`animate-spin`:``}),label:l.isPending?`Recovering…`:`Recover`,"aria-label":`Recover ${A}`,disabled:l.isPending,onClick:()=>l.mutate({providerId:e,accountId:t.id}),title:`Clear cooldown / restore active status`}):null,(0,Q.jsx)(y,{size:`icon`,variant:`danger`,icon:(0,Q.jsx)(oe,{size:12}),label:`Delete`,"aria-label":`Delete ${A}`,onClick:()=>s(t),title:`Delete account`})]})]}),h&&(0,Q.jsx)(Je,{summary:{providerId:e,accountId:t.id,title:t.label||t.id.slice(0,8),status:t.status,errorCategory:t.lastErrorCategory??void 0,errorMessage:t.lastError??void 0,emptyMessage:`Status transitions, rate limits, and auto-recoveries will appear here.`,staticToken:t.staticToken===!0,credentialKind:t.credentialKind,credentialMode:t.credentialMode},onClose:()=>g(!1)}),v&&(0,Q.jsx)(ln,{providerId:e,account:t,onClose:()=>S(!1)})]})}var dn=[{value:`added-asc`,label:`Added · oldest`},{value:`added-desc`,label:`Added · newest`},{value:`label-asc`,label:`Name · A–Z`},{value:`label-desc`,label:`Name · Z–A`},{value:`status-asc`,label:`Status · active first`},{value:`status-desc`,label:`Status · disabled first`},{value:`lastCheck-desc`,label:`Last check · newest`},{value:`lastCheck-asc`,label:`Last check · oldest`}];function fn(e,t,n){let r=(e,t)=>(e.label||e.id).localeCompare(t.label||t.id)||e.createdAt.localeCompare(t.createdAt)||e.id.localeCompare(t.id);if(n===`added`)return e.sortIndex-t.sortIndex||e.createdAt.localeCompare(t.createdAt)||e.id.localeCompare(t.id);if(n===`label`)return r(e,t);if(n===`status`){let n=en(e.status)-en(t.status);return n===0?r(e,t):n}let i=new Date(e.lastSuccessAt??e.createdAt).getTime();return new Date(t.lastSuccessAt??t.createdAt).getTime()-i||r(e,t)}function pn({providerId:e,accounts:t,onDelete:n,showGrokProbe:r=!1,grokProbePending:i=!1,onGrokProbe:a}){let o=ce(),s=R(),c=ge(),l=Ce(),u=We(e).data??new Map,p=X(),m=(0,Z.useMemo)(()=>{let t=new Map;for(let n of p.data?.accounts??[])n.provider===e&&n.quota&&t.set(n.id,n.quota.windows);return t},[p.data,e]),[h,g]=(0,Z.useState)(``),[_,v]=(0,Z.useState)(new Set),[S,C]=(0,Z.useState)(`added-asc`),[T,E]=(0,Z.useState)(!1),[D,O]=(0,Z.useState)(!1),[k,A]=(0,Z.useState)(!1),j=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{if(!k)return;let e=e=>{j.current&&!j.current.contains(e.target)&&A(!1)},t=e=>{e.key===`Escape`&&A(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[k]);let M=h.trim().toLowerCase(),N=(0,Z.useMemo)(()=>M?t.filter(e=>{let t=`${e.label??``} ${e.id} ${e.credentialKind} ${e.status}`.toLowerCase();return M.split(/\s+/).every(e=>t.includes(e))}):t,[t,M]),ee=(0,Z.useMemo)(()=>{let e=S.slice(0,S.lastIndexOf(`-`)),t=S.endsWith(`-desc`)?-1:1,n=[...N];return n.sort((n,r)=>t*fn(n,r,e)),n},[N,S]),P=(0,Z.useMemo)(()=>t.filter(e=>_.has(e.id)),[t,_]),F=N.length>0&&N.every(e=>_.has(e.id)),I=P.some(e=>e.status===`disabled`),te=P.some(e=>e.status!==`disabled`),re=P.length===0,se=(e,t)=>{v(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})},de=()=>{v(e=>{let t=new Set(e);if(F)for(let e of N)t.delete(e.id);else for(let e of N)t.add(e.id);return t})},fe=async(e,t)=>{if(P.length===0)return;E(!0);let n=await Promise.allSettled(P.map(e=>t(e))),r=n.filter(e=>e.status===`rejected`).length,i=n.length-r;E(!1),r===0?b.success(`${e} complete`,`${i} account${i===1?``:`s`}`):b.error(`${e} partially failed`,`${i} succeeded, ${r} failed`)},pe=()=>fe(`Recover`,t=>c.mutateAsync({providerId:e,accountId:t.id})),me=async()=>{if(t.length===0)return;E(!0);let e=await Mt(t,3,e=>le(`/accounts/${encodeURIComponent(e.id)}/quota/refresh`,{method:`POST`})),n=0,r=0;for(let t of e)t.status===`fulfilled`&&t.value?.ok?n+=1:r+=1;await Promise.all([o.invalidateQueries({queryKey:L.quota.all}),o.invalidateQueries({queryKey:L.providers.all})]),E(!1),r===0?b.success(`Test complete`,`${n} passed`):n===0?b.error(`Test failed`,`${r} account${r===1?``:`s`} failed`):b.error(`Test partially failed`,`${n} passed, ${r} failed`)},he=t=>fe(t?`Enable`:`Disable`,n=>s.mutateAsync({providerId:e,accountId:n.id,request:{status:t?`active`:`disabled`}})),_e=async()=>{if(P.length!==0){E(!0);try{let t=await l.mutateAsync({providerId:e,accountIds:P.map(e=>e.id)}),n=new Date().toISOString().replace(/[:.]/g,`-`);Pe(`${e}-accounts-${n}.json`,JSON.stringify(t,null,2),`application/json`),b.success(`Accounts exported`,`${t.accounts.length} account${t.accounts.length===1?``:`s`} — contains plaintext credentials`)}catch(e){b.error(`Export failed`,e.message??`Unable to export accounts`)}finally{E(!1)}}};return(0,Q.jsxs)(J,{gap:`8px`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2 p-3 border border-inner-border rounded-control bg-surface-2`,children:[(0,Q.jsxs)(`label`,{className:`relative min-w-20 flex-[1_1_10rem]`,children:[(0,Q.jsx)(ae,{size:13,"aria-hidden":`true`,className:`pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-text-tertiary`}),(0,Q.jsx)(q,{id:`accounts-search`,value:h,onChange:e=>g(e.target.value),placeholder:`Search accounts...`,"aria-label":`Search accounts`,className:`pl-9`})]}),(0,Q.jsx)(y,{size:`sm`,variant:`primary`,icon:(0,Q.jsx)(x,{size:12}),disabled:T||t.length===0,onClick:me,"aria-label":`Test all accounts`,title:`Test every account, regardless of selection or filters`,children:`Test all`}),(0,Q.jsxs)(`div`,{ref:j,className:`relative`,children:[(0,Q.jsxs)(y,{size:`sm`,variant:`secondary`,disabled:T||re,"aria-expanded":k,"aria-haspopup":`menu`,"aria-label":re?`Select accounts to enable bulk actions`:`Bulk actions for ${P.length} selected accounts`,onClick:()=>A(e=>!e),children:[`Actions`,re?``:` (${P.length})`,(0,Q.jsx)(d,{size:12,"aria-hidden":`true`,className:`transition-transform ${k?`rotate-180`:``}`})]}),k&&!re?(0,Q.jsxs)(`div`,{role:`menu`,"aria-label":`Selected account actions`,className:`absolute left-0 top-full z-50 mt-1 flex w-64 popover-max flex-col gap-1 rounded-control border border-inner-border bg-popover-bg p-2 shadow-popout sm:left-auto sm:right-0`,children:[(0,Q.jsx)(y,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,icon:(0,Q.jsx)(ie,{size:12}),disabled:T,onClick:()=>{A(!1),pe()},children:`Recover`}),I?(0,Q.jsx)(y,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,icon:(0,Q.jsx)(rt,{size:12}),disabled:T,onClick:()=>{A(!1),he(!0)},children:`Enable`}):null,te?(0,Q.jsx)(y,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,icon:(0,Q.jsx)(ne,{size:12}),disabled:T,onClick:()=>{A(!1),he(!1)},children:`Disable`}):null,(0,Q.jsx)(y,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,icon:(0,Q.jsx)(w,{size:12}),disabled:T,onClick:()=>{A(!1),_e()},children:`Export JSON`}),(0,Q.jsx)(y,{role:`menuitem`,size:`sm`,variant:`danger`,className:`w-full justify-start`,icon:(0,Q.jsx)(oe,{size:12}),disabled:T,onClick:()=>{A(!1),O(!0)},children:`Delete`}),(0,Q.jsx)(y,{role:`menuitem`,size:`sm`,variant:`ghost`,className:`w-full justify-start`,disabled:T,onClick:()=>{v(new Set),A(!1)},children:`Clear selection`})]}):null]}),(0,Q.jsx)(`label`,{className:`inline-flex h-15 shrink-0 items-center gap-2 text-caption font-semibold text-text-secondary [&_.radix-select-trigger]:font-semibold [&_.radix-select-trigger]:bg-hover [&_.radix-select-trigger]:text-text-primary`,children:(0,Q.jsx)(f,{size:`sm`,value:S,onValueChange:e=>C(e),options:dn,"aria-label":`Sort accounts by`})}),(0,Q.jsxs)(`label`,{className:`inline-flex h-15 shrink-0 items-center gap-2 text-caption font-semibold text-text-secondary`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:F,onChange:de,"aria-label":`Select accounts`}),(0,Q.jsx)(`span`,{children:`Select`})]}),r?(0,Q.jsx)(y,{size:`sm`,variant:`secondary`,icon:(0,Q.jsx)(x,{size:12,className:i?`animate-spin`:``}),disabled:i||t.length===0,onClick:a,title:`Probe every Grok account with the live 407 streaming request`,children:i?`Testing…`:`Test 407`}):null]}),(0,Q.jsx)(`div`,{className:`account-list flex flex-col gap-3 max-h-230 overflow-y-auto pr-1 [container-type:inline-size] [container-name:account-list]`,role:`list`,"aria-label":`Provider accounts`,children:ee.map(t=>(0,Q.jsx)(un,{providerId:e,account:t,inflight:u.get(t.id)??t.inflight,quota:m.get(t.id),selected:_.has(t.id),onToggleSelect:se,onDelete:n},t.id))}),(0,Q.jsx)(`div`,{className:`flex items-center justify-between text-badge text-text-tertiary`,children:(0,Q.jsxs)(`span`,{children:[`Showing `,N.length,` account`,N.length===1?``:`s`,M?` (filtered from ${t.length})`:``]})}),(0,Q.jsx)(ue,{open:D,onClose:()=>{T||O(!1)},onConfirm:async()=>{await fe(`Delete`,async e=>{let t=e.tenantId===null?`/global/accounts/${encodeURIComponent(e.id)}`:`/accounts/${encodeURIComponent(e.id)}`;await le(t,{method:`DELETE`}),o.removeQueries({queryKey:L.quota.account(e.id),exact:!0})}),v(new Set),O(!1),await Promise.all([o.invalidateQueries({queryKey:L.providers.accounts(e)}),o.invalidateQueries({queryKey:L.providers.all}),o.invalidateQueries({queryKey:L.quota.all})])},title:`Delete ${P.length} account${P.length===1?``:`s`}?`,message:`This permanently removes the selected accounts and their credentials. This cannot be undone.`,confirmLabel:`Delete`,danger:!0})]})}var mn=2097152,hn=mn/1048576;function gn({providerId:e,accounts:t,onClose:n}){let r=_e(),i=Te(),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(!1),[d,p]=(0,Z.useState)(`auto`),m=Zt(s),h=m.length>1,g=m.length===1?m[0]:void 0,_=d===`auto`?g?.kind:d,x=g&&_===`jwt`?Ut(g.value):void 0,S=t.map(e=>e.label),C=h?$t(m,e,S):[],w=e=>{let t=d===`auto`?e.kind===`jwt`?`jwt`:`auto`:d;return{credentialKind:t===`auto`&&e.kind===`oauth`?`oauth`:`api_key`,credentialMode:t,secret:e.value}},T=r.isPending||l,E=async()=>{try{let e=await navigator.clipboard.readText();c(e);let t=Zt(e);if(t.length>1)b.success(`Pasted from clipboard`,`Detected ${t.length} credentials`);else{let e=t[0]?.kind??`api_key`,n=e===`oauth`?`OAuth export`:e===`jwt`?`Static JWT`:`API key`;b.success(`Pasted from clipboard`,`Detected: ${n}`)}}catch{b.error(`Clipboard access denied`)}},D=e=>{if(e.size>mn){b.error(`File too large`,`Credential files must be ${hn} MB or smaller.`);return}let t=new FileReader;t.onload=()=>{let n=typeof t.result==`string`?t.result:``;c(n);let r=Zt(n);if(r.length===0){b.error(`Nothing to import`,`That file held no credential the gateway recognises.`);return}b.success(`Imported ${e.name}`,r.length>1?`Detected ${r.length} credentials`:r[0]?.kind===`oauth`?`Detected: OAuth export`:`Detected: API key`)},t.onerror=()=>b.error(`Could not read that file`),t.readAsText(e)},O=async()=>{if(m.length!==0){if(m.length===1){let t=m[0];r.mutate({providerId:e,request:{label:(a.trim()||t.identity)??void 0,...w(t)}},{onSuccess:()=>{b.success(`Account connected`,`New ${t.kind===`oauth`?`OAuth`:t.kind===`jwt`?`Static JWT`:`API key`} account registered successfully`),n()},onError:e=>b.error(`Failed to add account`,e.message??`Invalid credentials`)});return}u(!0);try{let t=await i.mutateAsync({providerId:e,accounts:m.map((e,t)=>({label:C[t],...w(e)}))}),r=t.results.filter(e=>!e.ok),a=t.created;if(a>0&&b.success(`${a} account${a===1?``:`s`} added`,r.length>0?`${r.length} skipped`:void 0),r.length>0){let e=r.slice(0,5).map(e=>`${C[e.index]??e.index}: ${e.error??`rejected`}`).join(`
2
+ `);b.error(`${r.length} account${r.length===1?``:`s`} skipped`,e+(r.length>5?`\n…and ${r.length-5} more`:``))}a>0&&n()}finally{u(!1)}}};return(0,Q.jsx)(F,{open:!0,onClose:n,title:`Add Account (API key / JSON)`,width:560,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,onClick:n,disabled:T,children:`Cancel`}),(0,Q.jsx)(y,{size:`sm`,variant:`primary`,disabled:T||m.length===0,onClick:()=>void O(),children:T?`Connecting...`:h?`Add ${m.length} Accounts`:`Add Account`})]}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[!h&&(0,Q.jsx)(q,{label:`Account label (optional)`,value:a,onChange:e=>o(e.target.value),placeholder:g?.identity??`${e} account`}),(0,Q.jsx)(f,{label:`Credential type`,id:`credential-mode`,value:d,onValueChange:e=>p(e===`jwt`||e===`api_key`?e:`auto`),options:[{value:`auto`,label:`Auto — detect JWT, OAuth, or API key`},{value:`jwt`,label:`JWT — static, no refresh`},{value:`api_key`,label:`API key — do not decode as JWT`}]}),(0,Q.jsxs)(J,{gap:`6px`,className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Q.jsx)(`label`,{className:`text-caption font-semibold text-text-secondary`,children:`API key, OAuth token, or exported JSON — one or many`}),h?(0,Q.jsxs)(K,{tone:`accent`,children:[`Detected: `,m.length,` accounts`]}):g?(0,Q.jsxs)(K,{tone:_===`oauth`||_===`jwt`?`accent`:`default`,children:[`Detected:`,` `,_===`oauth`?`OAuth`:_===`jwt`?`Static JWT`:`API key`,g.identity?` · ${g.identity}`:``]}):null,g&&_===`jwt`?(0,Q.jsxs)(`p`,{className:`text-micro text-text-tertiary`,children:[`Static JWT · no refresh token`,x?` · expires ${new Date(x).toLocaleString()}`:` · no expiry claim`]}):null]}),(0,Q.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),placeholder:`Paste one credential, or many — one per line, a JSON array, or newline-delimited OAuth exports. Kind and account naming are detected automatically…`,rows:6,spellCheck:!1,className:`font-mono tabular-nums w-full min-w-0 min-h-65 rounded-control border border-inner-border bg-input-bg px-6 py-5 text-caption text-text-primary resize-y box-border`}),(0,Q.jsxs)(Y,{gap:`8px`,className:`justify-end`,children:[(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,onClick:()=>void E(),children:`Paste`}),(0,Q.jsxs)(`label`,{className:v({size:`sm`,className:`cursor-pointer`}),children:[(0,Q.jsx)(`input`,{type:`file`,accept:`.json,.txt,.jsonl,.ndjson,application/json,text/plain`,"aria-label":`Import credentials from a file`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&D(t)}}),`Import file`]})]})]}),h&&(0,Q.jsx)(`div`,{className:`flex flex-col gap-2 max-h-75 overflow-y-auto rounded-control border border-inner-border bg-surface-2 px-4 py-5`,children:m.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4 text-badge`,children:[(0,Q.jsx)(`span`,{className:`truncate min-w-0`,children:C[t]}),(0,Q.jsx)(K,{tone:e.kind===`oauth`?`accent`:`default`,children:e.kind===`oauth`?`OAuth`:`API key`})]},t))})]})})}function _n(e){let t=e.trim(),n=e=>{try{return new URL(e).searchParams}catch{return}},r=n(t)??new URLSearchParams(t.startsWith(`?`)?t.slice(1):t),i=r.get(`code`);if(i)return{code:i};let a=r.get(`error_description`)??r.get(`error`);return a?{error:`The provider refused the login: ${a}`}:n(t)!==void 0||t.startsWith(`?`)?{error:`That redirect URL carries no authorization code — copy the full URL from the address bar.`}:{code:t}}function vn({providerId:e,authorizeUrl:t,state:n,popup:r,onClose:i}){let[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(``),l=De(),d=Qe(),f=ce(),p=we(e),m=(0,Z.useRef)(null),h=(0,Z.useRef)(!1);(0,Z.useEffect)(()=>{let t=setInterval(()=>{f.invalidateQueries({queryKey:L.providers.accounts(e)})},1500);return()=>clearInterval(t)},[f,e]),(0,Z.useEffect)(()=>{let e=p.data?.map(e=>e.id)??null;if(e!==null){if(m.current===null){m.current=new Set(e);return}h.current||e.find(e=>!m.current.has(e))!==void 0&&(h.current=!0,r.close(),b.success(`Account connected`,`OAuth login completed successfully`),i(!0))}},[p.data,r,i]);let g=()=>{r.close(),i(!1)},[v,x]=(0,Z.useState)(!1),S=()=>{x(!0),f.invalidateQueries({queryKey:L.providers.accounts(e)}).finally(()=>x(!1))},w=async()=>{try{let e=await navigator.clipboard.readText();if(!e.trim()){b.error(`Clipboard is empty`);return}c(e),b.success(`Pasted redirect URL`)}catch{b.error(`Clipboard unavailable on this origin`)}};return(0,Q.jsx)(F,{open:!0,onClose:g,title:`Connect via OAuth`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,onClick:g,disabled:l.isPending,children:`Cancel`}),(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,onClick:S,disabled:l.isPending||v,title:`You already approved in the popup — check now instead of waiting`,children:v?`Checking…`:`Complete`}),(0,Q.jsx)(y,{variant:`primary`,size:`sm`,disabled:l.isPending||s.trim().length===0,onClick:()=>{let t=_n(s);if(`error`in t){b.error(`OAuth callback failed`,t.error);return}l.mutate({providerId:e,code:t.code,state:n},{onSuccess:()=>{r.close(),b.success(`Account connected`,`OAuth login completed successfully`),i(!0)},onError:e=>b.error(`OAuth callback failed`,e.message??`Invalid or expired authorization code`)})},children:l.isPending?`Connecting…`:`Connect`})]}),children:(0,Q.jsxs)(J,{gap:`14px`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3.5 py-2.5 rounded-card border border-inner-border bg-surface-2`,children:[(0,Q.jsx)(_,{size:16,className:`animate-spin text-accent shrink-0`}),(0,Q.jsx)(`span`,{className:`text-body font-semibold`,children:`Waiting for popup authorization…`})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:`Step 1: Open this URL in your browser`}),(0,Q.jsxs)(Y,{gap:`8px`,children:[(0,Q.jsx)(`a`,{className:`min-w-0 flex-1 font-mono text-badge text-accent overflow-hidden text-ellipsis whitespace-nowrap px-2.5 py-2 rounded-control bg-input-bg border border-inner-border`,href:t,target:`_blank`,rel:`noreferrer`,title:t,children:t}),(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,icon:a?(0,Q.jsx)(u,{size:12}):(0,Q.jsx)(C,{size:12}),onClick:()=>{navigator.clipboard?.writeText(t),o(!0),d(()=>o(!1),1500)},className:`shrink-0`,children:a?`Copied`:`Copy`})]}),(0,Q.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:`A popup should open automatically. If it was blocked, open the URL above manually.`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 text-micro font-bold uppercase tracking-label text-text-tertiary`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`flex-1 h-px bg-inner-border`}),(0,Q.jsx)(`span`,{children:`Or complete manually`}),(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`flex-1 h-px bg-inner-border`})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:`Step 2: Paste the redirect URL here`}),(0,Q.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:`If the redirect lands on an unreachable address, copy that page's full URL from your browser and paste it below — this works from any machine, not just localhost.`}),(0,Q.jsxs)(Y,{gap:`8px`,align:`flex-start`,children:[(0,Q.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),placeholder:`http://127.0.0.1:59653/callback?code=…&state=… (or just the code)`,rows:2,spellCheck:!1,className:`w-full min-h-16 resize-y rounded-control border border-inner-border bg-input-bg px-2.5 py-2 font-mono text-badge text-text-primary box-border focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-1 flex-1`}),(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,onClick:()=>void w(),className:`shrink-0`,children:`Paste`})]})]})]})})}function yn(e){try{return new URL(e).host}catch{return e}}function bn({providerId:e,parameters:t,onClose:n}){let r=je(),i=z(),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(!1),[l,d]=(0,Z.useState)(!1),f=Qe();(0,Z.useEffect)(()=>{let i=!1;return r.mutate({providerId:e,...t===void 0||Object.keys(t).length===0?{}:{parameters:t}},{onSuccess:e=>{i||o(e)},onError:e=>{i||(b.error(`Failed to start device login`,e.message??`Unable to start device authorization`),n())}}),()=>{i=!0}},[]);let p=(0,Z.useRef)(null),[m,h]=(0,Z.useState)(!1);return(0,Z.useEffect)(()=>{if(!a)return;let e=window.open(a.verificationUri,`cartethyia-device`,`popup,width=720,height=820`);return e?p.current=e:h(!0),()=>{let e=p.current;p.current=null,e&&!e.closed&&e.close()}},[a]),(0,Z.useEffect)(()=>{if(!a)return;let t=Date.now(),r=Math.max(1,a.expiresInSeconds)*1e3,o=!1,s=Math.max(1,a.intervalSeconds)*1e3,c=!1,l=0,u=()=>window.clearTimeout(l),d=e=>{u(),l=window.setTimeout(f,e)},f=()=>{if(!c){if(Date.now()-t>r){u(),b.error(`Device login expired`,`Please try again.`),n();return}o||(o=!0,i.mutate({providerId:e,deviceAuthId:a.deviceAuthId},{onSuccess:e=>{if(o=!1,!c){if(e.status===`complete`){u();let e=p.current;e&&!e.closed&&e.close(),b.success(`OAuth account connected`,`Device authorization complete`),n()}else e.status===`failed`?(u(),b.error(`Device login failed`,e.reason),n()):e.status===`slow_down`?(s=(e.retryAfterSeconds===void 0?s+5e3:Math.max(1,e.retryAfterSeconds)*1e3)+1e3,d(s)):(e.status===`pending`&&e.retryAfterSeconds!==void 0&&(s=Math.max(1,e.retryAfterSeconds)*1e3+1e3),d(s))}},onError:()=>{o=!1,c||d(s)}}))}};return d(s+1e3),()=>{c=!0,u()}},[a]),(0,Q.jsx)(F,{open:!0,onClose:n,title:`Login with OAuth (device code)`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,onClick:n,children:`Cancel`}),null]}),children:(0,Q.jsx)(J,{gap:`14px`,children:a?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3.5 py-2.5 rounded-card border border-inner-border bg-surface-2`,children:[(0,Q.jsx)(_,{size:16,className:`animate-spin text-accent shrink-0`}),(0,Q.jsx)(`span`,{className:`text-body font-semibold`,children:`Waiting for authorization…`})]}),a.userCode?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:`Step 1: Enter this code`}),(0,Q.jsxs)(`div`,{className:`rounded-card border border-inner-border bg-surface-2 p-3.5 flex flex-col gap-1.5 items-center text-center`,children:[(0,Q.jsx)(`div`,{className:`text-micro font-bold uppercase tracking-label text-text-tertiary`,children:`Device code`}),(0,Q.jsx)(`div`,{className:`font-mono text-display font-bold tracking-code text-text-primary`,children:a.userCode}),(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,icon:l?(0,Q.jsx)(u,{size:12}):(0,Q.jsx)(C,{size:12}),onClick:()=>{navigator.clipboard?.writeText(a.userCode),d(!0),f(()=>d(!1),1500)},children:l?`Copied`:`Copy code`})]})]}):null,(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`div`,{className:`text-body font-semibold text-text-primary`,children:a.userCode?`Step 2: Open the verification page`:`Open the verification page to authorize`}),(0,Q.jsxs)(Y,{gap:`8px`,children:[(0,Q.jsx)(`a`,{className:`min-w-0 flex-1 font-mono text-badge text-accent overflow-hidden text-ellipsis whitespace-nowrap px-2.5 py-2 rounded-control bg-input-bg border border-inner-border`,href:a.verificationUri,target:`_blank`,rel:`noreferrer`,title:a.verificationUri,children:yn(a.verificationUri)}),(0,Q.jsx)(y,{variant:`primary`,size:`sm`,icon:(0,Q.jsx)(tt,{size:12}),onClick:()=>window.open(a.verificationUri,`_blank`,`noopener`),className:`shrink-0`,children:`Open`}),(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,icon:s?(0,Q.jsx)(u,{size:12}):(0,Q.jsx)(C,{size:12}),onClick:()=>{navigator.clipboard?.writeText(a.verificationUri),c(!0),f(()=>c(!1),1500)},className:`shrink-0`,children:s?`Copied`:`Copy`})]}),(0,Q.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:m?`The popup was blocked — open the page with Open above, finish signing in there, then press Check now.`:`The page opened in a popup. Finish signing in there — this dialog closes automatically once the account connects, or press Check now.`})]})]}):(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3.5 py-2.5 rounded-card border border-inner-border bg-surface-2`,children:[(0,Q.jsx)(_,{size:16,className:`animate-spin text-accent shrink-0`}),(0,Q.jsx)(`span`,{className:`text-body font-semibold`,children:`Starting device authorization…`})]})})})}function xn(e){let t={};for(let n of e)t[n.key]=n.defaultValue??``;return t}function Sn(e,t){return e.filter(e=>e.required===!0&&(t[e.key]??``).trim().length===0).map(e=>e.key)}function Cn({fields:e,values:t,onChange:n,idPrefix:r}){return e.length===0?null:(0,Q.jsx)(J,{gap:`10px`,children:e.map(e=>{let i=`${r}-${e.key}`,a=t[e.key]??``;return e.options&&e.options.length>0?(0,Q.jsx)(f,{id:i,label:e.label,value:a,onValueChange:t=>n(e.key,t),options:e.options.map(e=>({value:e.value,label:e.label}))},e.key):(0,Q.jsx)(q,{id:i,label:e.label,value:a,placeholder:e.placeholder??``,type:e.secret===!0?`password`:`text`,autoComplete:`off`,onChange:t=>n(e.key,t.target.value)},e.key)})})}function wn({providerId:e,providerName:t,fields:n,onClose:r}){let i=ke(),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(()=>xn(n)),d=(0,Z.useMemo)(()=>Sn(n,l),[n,l]);return(0,Q.jsx)(F,{open:!0,onClose:r,title:`Import a ${t} credential`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,onClick:r,disabled:i.isPending,children:`Cancel`}),(0,Q.jsx)(y,{variant:`primary`,size:`sm`,onClick:()=>{if(a.trim().length===0){b.error(`Credential required`,`Paste the token, key or exported JSON to import.`);return}if(d.length>0){b.error(`Missing required fields`,`Fill in: ${d.join(`, `)}`);return}i.mutate({providerId:e,credential:a.trim(),...Object.keys(l).length>0?{fields:l}:{},...s.trim().length>0?{accountLabel:s.trim()}:{}},{onSuccess:()=>{b.success(`Account imported`,`The credential was validated and saved`),r()},onError:e=>b.error(`Import failed`,e.message??`The provider rejected this credential`)})},disabled:i.isPending,icon:i.isPending?(0,Q.jsx)(_,{size:13,className:`animate-spin`}):void 0,children:i.isPending?`Validating…`:`Import`})]}),children:(0,Q.jsxs)(J,{gap:`12px`,children:[(0,Q.jsxs)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:[`The credential is checked against `,t,` before it is saved, so one that no longer works is reported here instead of being stored.`]}),(0,Q.jsx)(Cn,{fields:n,values:l,idPrefix:`import`,onChange:(e,t)=>u(n=>({...n,[e]:t}))}),(0,Q.jsx)(q,{id:`import-account-label`,label:`Account label`,hint:`optional`,value:s,placeholder:e,onChange:e=>c(e.target.value)}),(0,Q.jsx)(q,{id:`import-credential`,label:`Credential`,value:a,placeholder:`Paste the token, key, or exported JSON`,type:`password`,autoComplete:`off`,onChange:e=>o(e.target.value)})]})})}function Tn(e,t,n){let r=n?.trim()??``,i=r.indexOf(` — `),a=i>0?r.slice(0,i):``,o=i>0?r.slice(i+3):r;return{title:`${e}/${t} probe failed${a.length>0?` via ${a}`:``}`,detail:o.length>0?o:`Unknown error`}}function En(e,t,n){let{title:r,detail:i}=Tn(e,t,n);return[r,i]}function Dn(e){return e===`builtin`?`Built-in model`:e===`auto_free`?`Free tier, discovered from the provider`:e===`discovered`?`Fetched from provider`:`Added manually`}function On(e){return e===`auto_free`?`Free tier`:e===`discovered`?`Fetched`:`Manual`}var kn=[{key:`builtin`,label:`Built-in models`,hint:`Compiled catalog — can be disabled, not deleted`,matches:e=>e===null||e===`builtin`},{key:`auto_free`,label:`Free models (auto)`,hint:`Discovered from the provider's free tier`,matches:e=>e===`auto_free`},{key:`manual`,label:`Manually added`,hint:`Added by hand from the Add Model dialog`,matches:e=>e===`manual`},{key:`fetched`,label:`Fetched from provider`,hint:`Listed by the provider's /v1/models`,matches:e=>e!==null&&e!==`builtin`&&e!==`auto_free`&&e!==`manual`}],An={key:`disabled`,label:`Disabled models`,hint:`Turned off — not routable until re-enabled`};function jn(){return ct.map(e=>({value:e,label:e===`auto`?`Thinking: auto`:e.charAt(0).toUpperCase()+e.slice(1)}))}function Mn({value:e,onChange:t,disabled:n,id:r=`probe-thinking-effort`}){return(0,Q.jsx)(`div`,{title:`Reasoning effort every test in this section sends. Auto leaves the model's own reasoning default in place.`,className:`min-w-74 shrink-0`,children:(0,Q.jsx)(f,{id:r,"aria-label":`Thinking effort`,value:e,disabled:n,onValueChange:e=>t(e),options:jn()})})}function Nn({providerId:e,provider:t,onClose:n}){let r=Ee(),i=B(),[a,o]=(0,Z.useState)(``),s=t?.supportedWireFamilies,c=t?.wireFamilyDefault!==void 0&&(s===void 0||s.includes(t.wireFamilyDefault))?t.wireFamilyDefault:s?.[0],l=(0,Z.useMemo)(()=>{let e=[`chat`,`responses`,`messages`],t=(s??[]).filter(t=>e.includes(t));return[...t,...e.filter(e=>!t.includes(e))]},[s]),[u,d]=(0,Z.useState)(c??`chat`),[p,m]=(0,Z.useState)(`auto`),[h,g]=(0,Z.useState)(`idle`),[v,S]=(0,Z.useState)(``),[C,w]=(0,Z.useState)(Ln),T=a.trim(),E=T.toLowerCase().startsWith(`${e.toLowerCase()}/`)&&T.length>e.length+1?T.slice(e.length+1):T,D=E!==T,O=()=>{E&&(g(`testing`),S(``),r.mutate({providerId:e,request:{modelId:E,wireFamily:u,reasoningEffort:p,serviceKind:`llm`}},{onSuccess:e=>{e.ok?g(`passed`):(g(`failed`),S(e.error??`Model probe failed`))},onError:e=>{g(`failed`),S(e.message??`Model probe failed`)}}))};return(0,Q.jsx)(F,{open:!0,onClose:n,title:`Add Custom Model`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,onClick:n,disabled:i.isPending,children:`Cancel`}),(0,Q.jsx)(y,{variant:`primary`,size:`sm`,disabled:i.isPending||E.length===0,onClick:()=>{if(!E)return;let t=U(C.contextLimit),r=U(C.outputLimit);if(t===null||r===null){b.error(`Invalid limits`,`Use a token count such as 512k, 200000, or 1.5m.`);return}i.mutate({providerId:e,modelIds:[E],wireFamily:u,metadata:{contextLimit:t??null,outputLimit:r??null,passthrough:C.passthrough,image:C.passthrough?!0:C.image,reasoning:C.passthrough?!0:C.reasoning,toolCall:C.passthrough?!0:C.toolCall}},{onSuccess:()=>{b.success(`Custom model added`,`Sent to ${e}/${E}`),n()},onError:e=>b.error(`Failed to add model`,e.message??`Unable to register model`)})},children:i.isPending?`Adding...`:`Add Model`})]}),children:(0,Q.jsxs)(J,{gap:`10px`,children:[(0,Q.jsxs)(Y,{gap:`8px`,align:`flex-end`,children:[(0,Q.jsx)(q,{label:`Model ID`,autoFocus:!0,placeholder:`e.g. gpt-4o, free-model-id`,value:a,onChange:e=>{o(e.target.value),g(`idle`),S(``)},onKeyDown:e=>{e.key===`Enter`&&E.length>0&&O()},className:`flex-1`}),(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,icon:h===`testing`?(0,Q.jsx)(_,{size:13,className:`animate-spin`}):(0,Q.jsx)(x,{size:13}),disabled:r.isPending||E.length===0,onClick:O,className:`shrink-0`,children:h===`testing`?`Testing...`:`Test`})]}),D&&(0,Q.jsxs)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Using `,(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:E}),` (provider prefix removed).`]}),(0,Q.jsx)(f,{label:`Wire family`,id:`add-model-wire-family`,value:u,onValueChange:e=>{d(e),g(`idle`),S(``)},options:l.map(e=>({value:e,label:Un(e)}))}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Thinking`}),(0,Q.jsx)(Mn,{id:`add-model-thinking-effort`,value:p,onChange:e=>{m(e),g(`idle`),S(``)},disabled:r.isPending}),(0,Q.jsx)(`div`,{className:`text-badge text-text-tertiary mt-2`,children:`Sent with the test. Auto leaves the model's own reasoning default in place.`})]}),(0,Q.jsx)(Rn,{draft:C,onChange:w,idPrefix:`add-model`,disabled:i.isPending}),s!==void 0&&!s.includes(u)&&(0,Q.jsxs)(`div`,{className:`mt-1 text-badge text-text-tertiary`,children:[`This provider does not declare the`,` `,(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:Un(u)}),` wire. The request is sent as chosen; the upstream decides whether it answers.`]}),h===`passed`&&(0,Q.jsx)($e,{tone:`success`,live:`status`,children:`Model test passed — ready to add.`}),h===`failed`&&(0,Q.jsx)($e,{tone:`danger`,live:`alert`,children:v||`Model test failed.`})]})})}function Pn(){return{contextLimit:``,outputLimit:``,passthrough:!1,image:!0,reasoning:!0,toolCall:!0}}var Fn=String(G),In=String(Fe);function Ln(){return{...Pn(),contextLimit:Fn,outputLimit:In}}function Rn({draft:e,onChange:t,idPrefix:n,disabled:r=!1}){let i=e.passthrough;return(0,Q.jsxs)(J,{gap:`10px`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Limits`}),(0,Q.jsxs)(Y,{gap:`8px`,children:[(0,Q.jsx)(q,{label:`Context`,id:`${n}-context`,placeholder:Fn,value:e.contextLimit,disabled:r,onChange:n=>t({...e,contextLimit:n.target.value}),className:`flex-1`}),(0,Q.jsx)(q,{label:`Output`,id:`${n}-output`,placeholder:In,value:e.outputLimit,disabled:r,onChange:n=>t({...e,outputLimit:n.target.value}),className:`flex-1`})]}),(0,Q.jsxs)(`label`,{className:`inline-flex items-center gap-2 mt-2 text-badge text-text-secondary cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,id:`${n}-fallback-limits`,checked:e.contextLimit===Fn&&e.outputLimit===In,disabled:r,onChange:n=>t(n.target.checked?{...e,contextLimit:Fn,outputLimit:In}:{...e,contextLimit:``,outputLimit:``})}),`Use fallback — `,W(G),` ctx ·`,` `,W(Fe),` out`]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-badge font-semibold text-text-secondary mb-2`,children:`Capabilities`}),(0,Q.jsx)(J,{gap:`6px`,children:[[`image`,`Can image`,e.image],[`reasoning`,`Reasoning`,e.reasoning],[`toolCall`,`Tools`,e.toolCall]].map(([a,o,s])=>(0,Q.jsxs)(`label`,{className:`inline-flex items-center gap-2 text-badge text-text-secondary`,style:i?{opacity:.5}:void 0,children:[(0,Q.jsx)(`input`,{type:`checkbox`,id:`${n}-${a}`,checked:i?!0:s,disabled:r||i,onChange:n=>t({...e,[a]:n.target.checked})}),o]},a))}),(0,Q.jsxs)(`label`,{className:`inline-flex items-center gap-2 mt-2 text-badge text-text-secondary cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,id:`${n}-passthrough`,checked:e.passthrough,disabled:r,onChange:n=>t({...e,passthrough:n.target.checked})}),`Passthrough — accept every capability`]}),i?(0,Q.jsx)(`div`,{className:`text-badge text-text-tertiary mt-2`,children:`Passthrough grants all of the above, so they are locked on. Uncheck it to restore your own choices.`}):null]})]})}function zn({providerId:e,model:t,onClose:n}){let r=fe(),[i,a]=(0,Z.useState)(()=>({contextLimit:t.contextLimit?String(t.contextLimit):``,outputLimit:t.outputLimit?String(t.outputLimit):``,passthrough:!1,image:t.vision===!0,reasoning:t.reasoning===!0,toolCall:t.toolCall===!0}));return(0,Q.jsx)(F,{open:!0,onClose:n,title:`Edit Model`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,onClick:n,disabled:r.isPending,children:`Cancel`}),(0,Q.jsx)(y,{variant:`primary`,size:`sm`,disabled:r.isPending,onClick:()=>{let a=U(i.contextLimit),o=U(i.outputLimit);if(a===null||o===null){b.error(`Invalid limits`,`Use a token count such as 512k, 200000, or 1.5m.`);return}r.mutate({providerId:e,modelId:t.modelId,route:t.route??``,metadata:{contextLimit:a??null,outputLimit:o??null,passthrough:i.passthrough,image:i.passthrough?!0:i.image,reasoning:i.passthrough?!0:i.reasoning,toolCall:i.passthrough?!0:i.toolCall}},{onSuccess:()=>n(),onError:e=>b.error(`Failed to update model`,e.message??`Unable to update model`)})},children:r.isPending?`Saving...`:`Save`})]}),children:(0,Q.jsxs)(J,{gap:`10px`,children:[(0,Q.jsxs)(`div`,{className:`text-badge text-text-tertiary`,children:[`Editing `,(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:t.modelId})]}),(0,Q.jsx)(Rn,{draft:i,onChange:a,idPrefix:`edit-model`,disabled:r.isPending})]})})}function Bn({providerId:e,model:t,serviceKind:n,searchCapable:r,thinkingEffort:i,onDeleteRequest:a,onEditRequest:c,deletePending:l}){let d=Ee(),f=Me(),[g,v]=(0,Z.useState)(!1),[w,T]=(0,Z.useState)(null),D=Qe(),O=n===`llm`?lt(t.modelId,i===`auto`?null:i):t.modelId,A=`${e}/${O}`,j=n===`websearch`?`Searching…`:`Thinking…`,M=()=>{d.mutate({providerId:e,request:{modelId:t.modelId,route:t.route,...n===`llm`?{reasoningEffort:i}:{},serviceKind:n}},{onSuccess:t=>{if(T({ok:t.ok,latencyMs:t.latencyMs}),!t.ok){let{title:n,detail:r}=Tn(e,O,t.error);b.error(n,r);return}let n=t.sample?.trim()??``,r=t.reportedModel?.trim()??``;b.successRich(`${O} · END ${Re(t.latencyMs)}`,(0,Q.jsxs)(`span`,{className:`grid gap-2 min-w-0`,children:[r?(0,Q.jsxs)(Y,{gap:`6px`,align:`center`,className:`min-w-0`,children:[(0,Q.jsx)(S,{size:12,"aria-hidden":`true`,className:`shrink-0 text-text-tertiary`}),(0,Q.jsx)(`span`,{className:`truncate font-mono text-badge text-text-secondary`,title:r,children:r})]}):null,(0,Q.jsx)(`span`,{children:n||`No sample text in the response.`})]}),[r,n].filter(Boolean).join(`
3
+ `)||`No sample text in the response.`)},onError:t=>{T({ok:!1,latencyMs:0}),b.error(...En(e,O,t.message))}})},N=()=>{let n=!t.enabled;f.mutate({providerId:e,request:{modelId:t.modelId,route:t.route,enabled:n}},{onSuccess:()=>b.success(n?`Model enabled`:`Model disabled`,t.modelId),onError:e=>b.error(`Failed to update model`,e.message??`Unable to update model`)})};return(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(`div`,{className:`model-card box-border flex w-full min-w-0 flex-1-auto flex-col gap-5 rounded-panel border border-inner-border p-6 ${t.enabled?`bg-surface-2`:`bg-surface-1 opacity-72`}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-4 min-w-0`,children:[(0,Q.jsx)(`span`,{className:`inline-flex items-center justify-center w-13 h-13 rounded-inset bg-teal-soft text-teal shrink-0`,children:(0,Q.jsx)(o,{size:14})}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-col gap-1`,children:[(0,Q.jsx)(`div`,{title:A,className:`font-mono tabular-nums min-w-0 truncate text-caption font-semibold leading-[1.35]`,children:O}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 text-micro text-text-tertiary`,children:[(0,Q.jsx)(`span`,{title:`${t.wireFamily} · ${t.route??e}`,className:`shrink-0 rounded-pill px-3 py-0.5 text-micro font-bold tracking-[0.04em]`,style:{...Hn(t.wireFamily)},children:Un(t.wireFamily)}),t.source!==null&&t.source!==`builtin`?(0,Q.jsx)(`span`,{title:Dn(t.source),className:`shrink-0 rounded-pill border border-teal-soft px-3 py-0.5 text-micro font-bold tracking-[0.04em] text-teal`,children:On(t.source)}):null,t.enabled?null:(0,Q.jsx)(`span`,{className:`shrink-0 rounded-pill bg-red-soft px-3 py-0.5 text-micro font-bold tracking-[0.04em] text-red`,children:`Off`})]})]}),(0,Q.jsx)(y,{variant:`ghost`,size:`sm`,icon:g?(0,Q.jsx)(u,{size:12}):(0,Q.jsx)(C,{size:12}),"aria-label":`Copy ${A}`,title:`Copy ${A}`,onClick:()=>{navigator.clipboard?.writeText(A),v(!0),D(()=>v(!1),1500)},className:`shrink-0 p-2 opacity-70`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 text-badge text-text-secondary`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex gap-2.5`,children:[t.reasoning?(0,Q.jsx)(`span`,{title:`Reasoning`,"aria-label":`Reasoning`,className:`inline-flex text-purple`,children:(0,Q.jsx)(s,{size:12})}):null,t.vision?(0,Q.jsx)(`span`,{title:`Vision`,"aria-label":`Vision`,className:`inline-flex text-status-info`,children:(0,Q.jsx)(E,{size:12})}):null,t.toolCall?(0,Q.jsx)(`span`,{title:`Tool calling`,"aria-label":`Tool calling`,className:`inline-flex text-orange`,children:(0,Q.jsx)(se,{size:12})}):null,r?(0,Q.jsx)(`span`,{title:`Web search`,"aria-label":`Web search`,className:`inline-flex text-teal`,children:(0,Q.jsx)(h,{size:12})}):null]}),(0,Q.jsxs)(`span`,{className:`whitespace-nowrap`,children:[t.limitsEstimated?(0,Q.jsx)(`span`,{title:Ie,"aria-label":`Limits are a fallback estimate`,className:`estimate-dot inline-flex items-center justify-center rounded-full border border-inner-border bg-surface-2 text-orange cursor-help mr-1 align-middle`,children:(0,Q.jsx)(p,{size:9,"aria-hidden":`true`})}):null,t.contextLimit?`${W(t.contextLimit)} ctx`:(0,Q.jsx)(`span`,{title:Le,className:`cursor-help`,children:`n/a ctx`}),t.outputLimit?` · ${W(t.outputLimit)} out`:(0,Q.jsx)(`span`,{title:Le,className:`cursor-help`,children:` · n/a out`})]}),c?(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 grid place-items-center w-6 h-6 p-0 border-0 bg-transparent text-text-tertiary cursor-pointer rounded-tiny hover:bg-inner-border hover:text-text-primary`,title:`Edit limits and capabilities`,"aria-label":`Edit ${t.modelId} limits and capabilities`,onClick:()=>c(t),children:(0,Q.jsx)(I,{size:11})}):null]}),(0,Q.jsxs)(`div`,{className:`flex gap-3 items-center flex-wrap`,children:[(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,disabled:d.isPending,onClick:M,"aria-label":`Test ${O}`,title:d.isPending?`Probing ${O}…`:w?.ok?`Last probe OK in ${Re(w.latencyMs)} — click to re-test`:w?`Last probe failed — click to retry`:`Test ${O}`,className:`flex-1 justify-center`,icon:d.isPending?(0,Q.jsx)(_,{size:12,className:`animate-spin`}):w?w.ok?(0,Q.jsx)(`span`,{className:`inline-flex text-green`,children:(0,Q.jsx)(m,{size:12})}):(0,Q.jsx)(`span`,{className:`inline-flex text-red`,children:(0,Q.jsx)(k,{size:12})}):(0,Q.jsx)(x,{size:12}),children:d.isPending?j:w?.ok?Re(w.latencyMs):w?`Fail`:`Test`}),(0,Q.jsx)(y,{variant:`ghost`,size:`sm`,disabled:f.isPending,onClick:N,icon:t.enabled?(0,Q.jsx)(ne,{size:12}):(0,Q.jsx)(rt,{size:12}),"aria-label":t.enabled?`Disable ${t.modelId}`:`Enable ${t.modelId}`,title:t.enabled?`Disable model`:`Enable model`,className:`flex-1 justify-center ${t.enabled?`text-red`:`text-green`}`,children:t.enabled?`Disable`:`Enable`}),t.source===`builtin`?null:(0,Q.jsx)(y,{variant:`ghost`,size:`sm`,disabled:l,onClick:()=>a(t),icon:(0,Q.jsx)(oe,{size:12}),"aria-label":`Delete ${t.modelId}`,title:`Delete model`,className:`model-card-delete shrink-0 px-4 py-3 text-text-tertiary`})]})]})})}var Vn=(0,Z.memo)(Bn);function Hn(e){return e===`responses`?{color:`var(--purple)`,background:`var(--purple-soft)`}:e===`messages`?{color:`var(--orange)`,background:`color-mix(in srgb, var(--orange) 14%, transparent)`}:{color:`var(--teal)`,background:`var(--teal-soft)`}}function Un(e){let t=e.toLowerCase();return t===`responses`?`Responses`:t===`messages`?`Messages`:`Chat`}function Wn({providerId:e,models:t,thinkingEffort:n,serviceKind:r=`llm`,searchCapable:i=!1}){let a=ye(),[o,s]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(null),u=e=>e.enabled!==!1,d=kn.map(e=>({...e,rows:t.filter(t=>u(t)&&e.matches(t.source))})).filter(e=>e.rows.length>0),f=t.filter(e=>!u(e)),p=t=>(0,Q.jsx)(Vn,{providerId:e,model:t,serviceKind:r,searchCapable:i,thinkingEffort:n,deletePending:a.isPending,onDeleteRequest:s,onEditRequest:t.source===`builtin`?void 0:l},`${t.modelId}::${t.route}`);return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(J,{gap:`16px`,children:[d.map(e=>(0,Q.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-4 min-w-0`,children:[(0,Q.jsx)(`span`,{className:`text-caption font-bold text-text-secondary`,children:e.label}),(0,Q.jsx)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:e.rows.length}),(0,Q.jsxs)(`span`,{title:e.hint,className:`text-micro text-text-tertiary overflow-hidden truncate`,children:[`· `,e.hint]})]}),(0,Q.jsx)(`div`,{className:`provider-grid grid gap-4 items-stretch`,children:e.rows.map(p)})]},e.key)),f.length===0?null:(0,Q.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-4 min-w-0`,children:[(0,Q.jsx)(`span`,{className:`text-caption font-bold text-text-secondary`,children:An.label}),(0,Q.jsx)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:f.length}),(0,Q.jsxs)(`span`,{title:An.hint,className:`text-micro text-text-tertiary overflow-hidden truncate`,children:[`· `,An.hint]})]}),(0,Q.jsx)(`div`,{className:`provider-grid grid gap-4 items-stretch`,children:f.map(p)})]})]}),(0,Q.jsx)(ue,{open:o!==null,onClose:()=>{a.isPending||s(null)},onConfirm:async()=>{o!==null&&(await a.mutateAsync({providerId:e,request:{modelId:o.modelId,route:o.route}}),b.success(`Model deleted`,`${e}/${o.modelId}`),s(null))},title:`Delete model?`,message:`Delete ${e}/${o?.modelId??``} from the provider catalog?`,confirmLabel:`Delete`,danger:!0}),c===null?null:(0,Q.jsx)(zn,{providerId:e,model:c,onClose:()=>l(null)})]})}function Gn(e){return e===`llm`?`LLM`:e===`websearch`?`Search`:e===`imageGeneration`?`Image`:e===`videoGeneration`?`Video`:e}function Kn(e){let t=e.serviceKinds;return Array.isArray(t)&&t.length>0?t:[`llm`]}function qn(){let{providerId:e}=pe(),[t]=he(),n=e??``,r=t.get(`service`),[i,a]=(0,Z.useState)(r===`websearch`||r===`imageGeneration`||r===`videoGeneration`?r:`llm`),o=xe(),s=Se(n),l=we(n),u=de(),d=de({silent:!0}),[f,p]=(0,Z.useState)(!1),m=be(),g=Ae(),_=ve(),v=ce(),[x,S]=(0,Z.useState)(!1),[C,T]=(0,Z.useState)(!1),E=Ee(),[D,k]=(0,Z.useState)(``),[ee,P]=(0,Z.useState)(``),[I,ie]=(0,Z.useState)(null),ae=e=>`cartethyia:provider:${e}:thinking-effort`,se=e=>{if(typeof window>`u`||!window.localStorage)return`auto`;let t=window.localStorage.getItem(ae(e));if(t===null)return`auto`;let n=t.trim().toLowerCase();return ct.includes(n)?n:`auto`},[R,fe]=(0,Z.useState)(()=>se(n));(0,Z.useEffect)(()=>{if(!n)return;let e=se(n);e!==R&&fe(e)},[n]),(0,Z.useEffect)(()=>{typeof window>`u`||!window.localStorage||!n||window.localStorage.setItem(ae(n),R)},[n,R]);let[me,ge]=(0,Z.useState)(!1),[_e,ye]=(0,Z.useState)(!1),[z,Ce]=(0,Z.useState)(null),[Te,De]=(0,Z.useState)({}),[Oe,ke]=(0,Z.useState)({}),[B,je]=(0,Z.useState)(null),[Me,Pe]=(0,Z.useState)(!1),[U,Fe]=(0,Z.useState)(null),W=(0,Z.useRef)(null),Ie=(0,Z.useRef)(null);(0,Z.useEffect)(()=>()=>{let e=W.current;W.current=null,e&&!e.closed&&e.close()},[]);let G=(o.data??[]).find(e=>e.providerId===n),Le=n===`opencode`||n===`cline`,Re=G===void 0?[`llm`]:Kn(G),K=[];for(let e of Re)(e===`llm`||e===`websearch`||e===`imageGeneration`||e===`videoGeneration`)&&K.push(e);(0,Z.useEffect)(()=>{if(G===void 0)return;let e=r===`websearch`||r===`imageGeneration`||r===`videoGeneration`||r===`llm`?r:void 0,t=K[0];if(e!==void 0&&K.includes(e)){i!==e&&a(e);return}!K.includes(i)&&t!==void 0&&a(t)},[G,r,i,K.join(`|`)]),(0,Z.useEffect)(()=>{Le&&G!==void 0&&G.supportsModelDiscovery!==!1&&Ie.current!==n&&(Ie.current=n,d.mutate(n))},[Le,d,n,G?.supportsModelDiscovery]);let q=l.data??[],Be=s.data??[],He=(()=>{let e=new Map;for(let t of Be){let n=`${t.serviceKind??`llm`}:${t.modelId}`,r=e.get(n);if(!r)e.set(n,t);else{let i=r.contextLimit??0;(t.contextLimit??0)>i&&e.set(n,t)}}return[...e.values()].sort((e,t)=>e.modelId.localeCompare(t.modelId))})(),Ue=He.filter(e=>e.serviceKind===`llm`||e.serviceKind===void 0),We=He.filter(e=>e.serviceKind===`websearch`),Ge=He.filter(e=>e.serviceKind===`imageGeneration`),Ke=He.filter(e=>e.serviceKind===`videoGeneration`),X=K.includes(i)?i:K[0],qe=ee||We[0]?.modelId||``,Je=()=>{let e=D.trim();qe&&e&&(ie(null),E.mutate({providerId:n,request:{modelId:qe,serviceKind:`websearch`,prompt:e}},{onSuccess:e=>ie({ok:e.ok,latencyMs:e.latencyMs,...e.searchResults?{results:e.searchResults,count:e.searchResults.length}:{},...e.error?{error:e.error}:{}}),onError:e=>ie({ok:!1,error:e instanceof Error?e.message:`Search test failed`})}))};if(o.isPending)return(0,Q.jsx)(j,{label:`Loading provider...`});if(o.isError)return(0,Q.jsx)(A,{title:`Unable to load providers`,message:`The provider catalog could not be read, so this page cannot resolve its provider.`,onRetry:()=>void o.refetch(),retrying:o.isFetching,action:(0,Q.jsx)(ut,{to:`/providers`,label:`Back to providers`})});if(!G)return(0,Q.jsx)(M,{icon:(0,Q.jsx)(it,{size:20}),title:`Provider not found`,message:`No provider named “${n}”. It may have been removed, or the link is stale.`,action:(0,Q.jsx)(ut,{to:`/providers`,label:`Back to providers`})});let Ye=q.filter(e=>e.status===`active`).length,Xe=e=>{let t=e===`browser`?G?.oauthFlows?.browserLoginFields??[]:G?.oauthFlows?.deviceLoginFields??[];if(t.length===0){e===`browser`?Qe():ge(!0);return}De(xn(t)),Ce(e)},Ze=()=>{if(z===null)return;let e=Sn(z===`browser`?G?.oauthFlows?.browserLoginFields??[]:G?.oauthFlows?.deviceLoginFields??[],Te);if(e.length>0){b.error(`Missing required fields`,`Fill in: ${e.join(`, `)}`);return}let t=z;Ce(null),t===`browser`?Qe(Te):(ke(Te),ge(!0))},Qe=e=>{let t=window.open(`about:blank`,`cartethyia-oauth`,`popup,width=720,height=820`);t&&(t.opener=null,W.current=t),_.mutate({providerId:n,...e===void 0?{}:{parameters:e}},{onSuccess:({authorizeUrl:e,state:n})=>{let r=null;if(t&&!t.closed?(t.location.href=e,r=t):(r=window.open(e,`cartethyia-oauth`,`popup,width=720,height=820`),r&&(r.opener=null,W.current=r)),!r){b.error(`Popup blocked`,`Allow popups to complete OAuth login.`);return}Fe({authorizeUrl:e,state:n,popup:r})},onError:e=>{t&&!t.closed&&t.close(),W.current===t&&(W.current=null),b.error(`Failed to start OAuth`,e.message??`Unable to start authorization`)}})};return(0,Q.jsxs)(J,{gap:`16px`,children:[(0,Q.jsx)(dt,{title:`${G.label||G.displayName}${X?` (${Gn(X)})`:``}`,description:`${G.providerId}/${G.baseUrl?` · ${G.baseUrl}`:``}`,icon:(0,Q.jsx)(ze,{icon:G.providerId,name:G.label||G.displayName,size:28}),back:{to:`/providers`,label:`Back to Providers`},actions:(0,Q.jsx)(Y,{gap:`8px`,className:`flex-wrap w-full max-w-full min-w-0`,children:G.isBuiltIn?(0,Q.jsx)(y,{variant:G.enabled?`danger`:`secondary`,icon:G.enabled?(0,Q.jsx)(ne,{size:13}):(0,Q.jsx)(rt,{size:13}),loading:g.isPending,onClick:()=>g.mutate({providerId:n,enabled:!G.enabled},{onSuccess:e=>b.success(e.enabled?`Provider enabled`:`Provider disabled`,G.label||G.displayName),onError:e=>b.error(`Provider update failed`,e.message??`Unable to change provider availability`)}),title:G.enabled?`Disable provider globally`:`Enable provider globally`,children:G.enabled?`Disable`:`Enable`}):null})}),(0,Q.jsx)(Et,{provider:G}),X===`llm`?(0,Q.jsx)(xt,{providerId:n,clientVersion:G.clientVersion,routeIdentityVersions:G.routeIdentityVersions,userAgentEditable:ft(G)}):null,G.requiresAccount===!1?(0,Q.jsxs)(H,{children:[(0,Q.jsx)(Ne,{title:`Accounts`,icon:(0,Q.jsx)(et,{size:16})}),(0,Q.jsx)(V,{children:(0,Q.jsx)(`p`,{className:`text-caption text-text-secondary`,children:`This provider is a public, unauthenticated route — no account or credential is needed. Routing already works without any setup here.`})})]}):(0,Q.jsxs)(H,{children:[(0,Q.jsx)(Ne,{title:`Accounts`,subtitle:`${q.length} total · ${Ye} active · ${q.length-Ye} disabled`,icon:(0,Q.jsx)(et,{size:16}),action:(0,Q.jsxs)(Ve,{children:[G.oauthFlows?.browser&&(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(tt,{size:13}),disabled:_.isPending,onClick:()=>Xe(`browser`),title:`Browser OAuth login — opens the provider authorize page in a popup`,children:_.isPending?`Starting...`:`Login with browser`}),G.oauthFlows?.device&&(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(N,{size:13}),onClick:()=>Xe(`device`),title:`Device-code login — enter the shown code on the provider site`,children:`Login with device code`}),G.oauthFlows?.import&&(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(w,{size:13}),onClick:()=>ye(!0),title:G.oauthFlows.browser||G.oauthFlows.device?`Import a credential you already hold — a refresh token, an exported auth blob, or an API key`:`Add and validate an API key`,children:G.oauthFlows.browser||G.oauthFlows.device?`Import credential`:`Add API key`}),(0,Q.jsx)(y,{variant:`primary`,size:`sm`,icon:(0,Q.jsx)(te,{size:13}),onClick:()=>S(!0),children:`Add Account`})]})}),(0,Q.jsxs)(V,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(St,{providerId:n}),l.isPending?(0,Q.jsx)(j,{label:`Loading accounts...`}):l.isError?(0,Q.jsx)(A,{message:`Failed to load accounts`,onRetry:()=>l.refetch()}):q.length===0?(0,Q.jsx)(M,{title:`No accounts connected`,message:`Add an API key or OAuth credential to route requests to this provider.`}):(0,Q.jsx)(pn,{providerId:n,accounts:q,onDelete:e=>je(e),showGrokProbe:X===`llm`&&n===`grok`,grokProbePending:m.isPending,onGrokProbe:()=>{m.mutate({providerId:n,request:{modelId:`grok-4.6`,prompt:`reply my message with exact number 407`,stream:!0,serviceKind:`llm`}},{onSuccess:e=>{let t=e.results.filter(e=>e.ok).length,n=e.results.filter(e=>e.statusCode===202).length,r=e.results.length-t-n;b.success(`Grok account probe complete`,`${t} passed · ${n} returned 202 and were parked in cooldown · ${r} other failures`)},onError:e=>b.error(`Grok account probe failed`,e.message??`Unable to probe Grok accounts`)})}})]})]}),X===`llm`?(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(H,{children:[(0,Q.jsx)(Ne,{title:`Models`,subtitle:`${Ue.length} model${Ue.length===1?``:`s`} registered`,icon:(0,Q.jsx)(c,{size:16}),action:(0,Q.jsxs)(Y,{gap:`6px`,className:`flex-wrap items-center`,children:[(0,Q.jsx)(Mn,{id:`models-section-thinking-effort`,value:R,onChange:fe}),(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(re,{size:13,className:u.isPending||d.isPending?`animate-spin`:``}),disabled:u.isPending||d.isPending,onClick:()=>u.mutate(n),children:u.isPending||d.isPending?`Fetching...`:`Fetch models`}),(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,icon:(0,Q.jsx)(oe,{size:13,className:f?`animate-spin`:``}),disabled:u.isPending||d.isPending||f||Ue.filter(e=>e.source!==`builtin`&&e.source!==null).length===0,onClick:async()=>{let e=Ue.filter(e=>e.source!==`builtin`&&e.source!==null);if(e.length!==0&&confirm(`Delete ${e.length} fetched/manual model(s) for ${n}?`)){p(!0);try{let t=await le(`/providers/${encodeURIComponent(n)}/models/bulk`,{method:`DELETE`,body:JSON.stringify({items:e.map(e=>({modelId:e.modelId,route:e.route}))})});await Promise.all([v.invalidateQueries({queryKey:L.providers.models(n)}),v.invalidateQueries({queryKey:L.providers.all})]);let r=t.failures.length;b.success(`Fetched models deleted`,r>0?`${t.deleted}/${t.total} removed, ${r} failed`:`${t.deleted}/${t.total} removed`)}catch(e){b.error(`Failed to delete fetched models`,e.message??`Unable to delete models`)}finally{p(!1)}}},children:f?`Deleting…`:`Delete fetched`}),(0,Q.jsx)(y,{variant:`primary`,size:`sm`,icon:(0,Q.jsx)(te,{size:13}),onClick:()=>T(!0),children:`Add Model`})]})}),(0,Q.jsx)(V,{className:`flex flex-col gap-8`,children:s.isPending?(0,Q.jsx)(j,{label:`Loading models...`}):s.isError?(0,Q.jsx)(A,{message:`Failed to load models`,onRetry:()=>s.refetch()}):Ue.length===0?(0,Q.jsx)(M,{title:`No LLM models found`,message:`No LLM models published by this provider yet. Sync or add a custom model above.`}):(0,Q.jsx)(Wn,{providerId:n,models:Ue,serviceKind:`llm`,thinkingEffort:R,searchCapable:G?.supportsWebSearch===!0})})]})}):X===`websearch`?(0,Q.jsxs)(H,{children:[(0,Q.jsx)(Ne,{title:`Web Search`,subtitle:`Run a real search request through the selected provider.`,icon:(0,Q.jsx)(h,{size:16})}),(0,Q.jsx)(V,{className:`flex flex-col gap-6`,children:s.isPending?(0,Q.jsx)(j,{label:`Loading search models...`}):s.isError?(0,Q.jsx)(A,{message:`Failed to load search models`,onRetry:()=>s.refetch()}):We.length===0?(0,Q.jsx)(M,{title:`No Search models found`,message:`This provider advertises Search, but no websearch model is registered yet.`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`label`,{className:`flex flex-col gap-2.5 text-badge text-text-secondary`,children:[`Search model`,(0,Q.jsx)(`select`,{value:qe,onChange:e=>{P(e.target.value),ie(null)},className:`w-full min-h-17 rounded-inset border border-inner-border bg-surface-1 text-text-primary px-4.5 py-0`,children:We.map(e=>(0,Q.jsx)(`option`,{value:e.modelId,children:e.modelId},`${e.modelId}:${e.route}`))})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-2.5 text-badge text-text-secondary`,children:[`Query`,(0,Q.jsx)(`input`,{value:D,onChange:e=>k(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Je())},placeholder:`What is the latest news about AI?`,className:`w-full min-h-17 rounded-inset border border-inner-border bg-surface-1 text-text-primary px-4.5 py-0`})]}),(0,Q.jsxs)(Y,{gap:`8px`,className:`items-center flex-wrap`,children:[(0,Q.jsx)(y,{variant:`primary`,size:`sm`,disabled:E.isPending||D.trim().length===0,loading:E.isPending,onClick:Je,children:`Test search`}),I?(0,Q.jsx)(`span`,{className:`text-badge`,style:{color:I.ok?`var(--green)`:`var(--red)`},children:I.ok?`Search ok · ${I.latencyMs}ms · ${I.count??0} result(s)`:I.error??`Search failed.`}):null]}),I&&I.results&&I.results.length>0?(0,Q.jsx)(`div`,{className:`flex max-h-110 flex-col gap-4 overflow-y-auto rounded-inset border border-inner-border bg-surface-1 p-4`,children:I.results.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,className:`text-caption text-text-primary font-semibold`,children:e.title||e.url}),(0,Q.jsx)(`span`,{className:`text-badge text-text-tertiary break-all`,children:e.url}),e.snippet?(0,Q.jsx)(`span`,{className:`text-badge text-text-secondary`,children:e.snippet}):null]},`${e.url}:${t}`))}):null]})})]}):X===`imageGeneration`||X===`videoGeneration`?(0,Q.jsxs)(H,{children:[(0,Q.jsx)(Ne,{title:Gn(X),subtitle:X===`imageGeneration`?`Models that return an image rather than text.`:`Models that return a video. Wired and routable; not yet verified against a live account.`,icon:X===`imageGeneration`?(0,Q.jsx)(O,{size:16}):(0,Q.jsx)(ot,{size:16})}),(0,Q.jsx)(V,{className:`flex flex-col gap-6`,children:s.isPending?(0,Q.jsx)(j,{label:`Loading ${Gn(X).toLowerCase()} models...`}):s.isError?(0,Q.jsx)(A,{message:`Failed to load ${Gn(X).toLowerCase()} models`,onRetry:()=>s.refetch()}):(X===`imageGeneration`?Ge:Ke).length===0?(0,Q.jsx)(M,{title:`No ${Gn(X)} models found`,message:`This provider advertises ${Gn(X)}, but no ${X} model is registered yet.`}):(0,Q.jsx)(Wn,{providerId:n,models:X===`imageGeneration`?Ge:Ke,serviceKind:`llm`,searchCapable:!1,thinkingEffort:`auto`})})]}):(0,Q.jsx)(H,{children:(0,Q.jsx)(V,{children:(0,Q.jsx)(M,{title:`Service not available`,message:`This provider advertises ${Re.map(Gn).join(`, `)}, but the dashboard has no controls for the selected service yet.`})})}),x&&(0,Q.jsx)(gn,{providerId:n,accounts:q,onClose:()=>S(!1)}),X===`llm`&&C?(0,Q.jsx)(Nn,{providerId:n,provider:G,onClose:()=>T(!1)}):null,(0,Q.jsx)(ue,{open:B!==null,onClose:()=>{Me||je(null)},onConfirm:async()=>{if(B){Pe(!0);try{let e=B.tenantId===null?`/global/accounts/${encodeURIComponent(B.id)}`:`/accounts/${encodeURIComponent(B.id)}`;await le(e,{method:`DELETE`}),v.removeQueries({queryKey:L.quota.account(B.id),exact:!0}),await Promise.all([v.invalidateQueries({queryKey:L.providers.accounts(n)}),v.invalidateQueries({queryKey:L.providers.healthEvents(n,B.id)}),v.invalidateQueries({queryKey:L.providers.all}),v.invalidateQueries({queryKey:L.quota.all})]),b.success(`Account deleted`,B.label||B.id.slice(0,8)),je(null)}catch(e){throw b.error(`Failed to delete account`,e.message??`Unable to delete account`),e}finally{Pe(!1)}}},title:`Delete account?`,message:`Delete "${B?.label||B?.id.slice(0,8)}"? This cannot be undone.`,confirmLabel:`Delete`,danger:!0}),me&&(0,Q.jsx)(bn,{providerId:n,parameters:Oe,onClose:()=>{ge(!1),ke({})}}),z!==null&&(0,Q.jsx)(F,{open:!0,onClose:()=>Ce(null),title:z===`browser`?`Sign in with`:`Device sign-in details`,size:`sm`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(y,{variant:`secondary`,size:`sm`,onClick:()=>Ce(null),children:`Cancel`}),(0,Q.jsx)(y,{variant:`primary`,size:`sm`,onClick:Ze,children:`Continue`})]}),children:(0,Q.jsxs)(J,{gap:`12px`,children:[(0,Q.jsx)(`p`,{className:`text-badge leading-snug text-text-tertiary`,children:z===`browser`?`Choose how ${G.label||G.displayName} should identify you, then continue to its sign-in page.`:`These decide which organization the device code is issued for.`}),(0,Q.jsx)(Cn,{fields:z===`browser`?G?.oauthFlows?.browserLoginFields??[]:G?.oauthFlows?.deviceLoginFields??[],values:Te,idPrefix:`flow-${z}`,onChange:(e,t)=>De(n=>({...n,[e]:t}))})]})}),_e&&G?.oauthFlows?.import===!0&&(0,Q.jsx)(wn,{providerId:n,providerName:G.label||G.displayName,fields:G.oauthFlows.importFields,onClose:()=>ye(!1)}),U&&(0,Q.jsx)(vn,{providerId:n,authorizeUrl:U.authorizeUrl,state:U.state,popup:U.popup,onClose:e=>{W.current=null,Fe(null),e&&v.invalidateQueries({queryKey:L.providers.accounts(n)})}})]})}export{qn as default};