mapigate 0.5.153 → 0.5.155

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 (115) hide show
  1. package/README.md +1 -1
  2. package/dist/cli/client/apiClient.js +1 -1
  3. package/dist/cli/commands/doctor.js +3 -3
  4. package/dist/cli/commands/start.js +1 -1
  5. package/dist/cli/daemon/portHelper.js +1 -1
  6. package/dist/cli/tools/definitions/codex/configurator.js +3 -3
  7. package/dist/cli/tools/definitions/droid/definition.js +2 -2
  8. package/dist/cli/tools/helpers.js +2 -2
  9. package/dist/cli/tray/tray.js +1 -1
  10. package/dist/cli/tray/tray.ps1 +25 -3
  11. package/dist/cli/tui/settingsMenu.js +5 -5
  12. package/dist/core/adapters/helpers/toolCallRescue.js +1 -1
  13. package/dist/core/adapters/responsesAdapter.js +2 -2
  14. package/dist/core/resilience/cooldownManager.js +1 -1
  15. package/dist/core/resilience/index.js +1 -1
  16. package/dist/core/router/loadBalancer.js +1 -1
  17. package/dist/core/scanner/modelScanner.js +1 -1
  18. package/dist/core/scanner/urlResolver.js +1 -1
  19. package/dist/core/tokenSaver/methods/rtk/autodetect.js +4 -4
  20. package/dist/core/tokenSaver/methods/rtk/filters/buildOutput.js +8 -7
  21. package/dist/core/tokenSaver/methods/rtk/method.js +1 -1
  22. package/dist/core/usage/quotaService.js +1 -1
  23. package/dist/core/usage/tokenHelper.js +1 -1
  24. package/dist/mitm/cert/install.js +1 -1
  25. package/dist/mitm/cert/rootCA.js +1 -1
  26. package/dist/mitm/dns/dnsConfig.js +10 -9
  27. package/dist/mitm/handlers/antigravity/config.js +2 -2
  28. package/dist/mitm/handlers/base.js +2 -2
  29. package/dist/mitm/handlers/copilot/config.js +2 -2
  30. package/dist/mitm/handlers/copilot/handler.js +1 -1
  31. package/dist/mitm/handlers/kiro/config.js +2 -2
  32. package/dist/mitm/server.js +2 -2
  33. package/dist/mitm/toolsHelper.js +2 -2
  34. package/dist/providers/catalog/kilocode/routes.js +1 -1
  35. package/dist/providers/composite/combo/fusionStrategy.js +1 -1
  36. package/dist/providers/composite/combo/provider.js +1 -1
  37. package/dist/providers/core/base/anthropicProvider.js +1 -1
  38. package/dist/providers/core/base/customExecutionHelper.js +1 -0
  39. package/dist/providers/core/base/tokenExtractor.js +1 -1
  40. package/dist/providers/core/registry.js +1 -1
  41. package/dist/providers/runtime/antigravity/executor.js +7 -7
  42. package/dist/providers/runtime/antigravity/provider.js +1 -1
  43. package/dist/providers/runtime/antigravity/thoughtSignatureStore.js +1 -1
  44. package/dist/providers/runtime/bedrock/provider.js +1 -1
  45. package/dist/providers/runtime/cline/provider.js +1 -1
  46. package/dist/providers/runtime/codex/provider.js +1 -1
  47. package/dist/providers/runtime/gemini/provider.js +1 -1
  48. package/dist/providers/runtime/gemini-cli/provider.js +1 -1
  49. package/dist/providers/runtime/kimi/routes.js +1 -1
  50. package/dist/providers/runtime/kiro/auth.js +1 -1
  51. package/dist/providers/runtime/kiro/createResponse.js +1 -1
  52. package/dist/providers/runtime/kiro/createResponseConverter.js +2 -2
  53. package/dist/providers/runtime/kiro/deviceFlow.js +1 -1
  54. package/dist/providers/runtime/kiro/executor.js +6 -6
  55. package/dist/providers/runtime/kiro/externalIdp.js +1 -1
  56. package/dist/providers/runtime/minimax/provider.js +1 -1
  57. package/dist/providers/runtime/opencode/provider.js +1 -1
  58. package/dist/providers/runtime/trae/provider.js +13 -13
  59. package/dist/providers/runtime/windsurf/provider.js +11 -11
  60. package/dist/providers/runtime/zed/provider.js +13 -13
  61. package/dist/server/auth/masterAuth.js +1 -1
  62. package/dist/server/index.js +4 -4
  63. package/dist/server/lifecycle.js +1 -1
  64. package/dist/server/proxy/countTokens.js +1 -1
  65. package/dist/server/proxy/index.js +1 -1
  66. package/dist/server/proxy/pipeline.js +5 -5
  67. package/dist/server/proxy/proxyDispatcher.js +1 -1
  68. package/dist/server/proxy/responseHandlers.js +1 -1
  69. package/dist/server/proxy/singleModelExecutor.js +5 -5
  70. package/dist/server/proxy/streaming/bedrockStreamer.js +9 -9
  71. package/dist/server/proxy/streaming/sseStreamer.js +16 -16
  72. package/dist/server/routes/apiAuth.js +1 -1
  73. package/dist/server/routes/apiCliTools.js +1 -1
  74. package/dist/server/routes/apiCombos.js +1 -1
  75. package/dist/server/routes/apiMitm.js +1 -1
  76. package/dist/server/routes/apiModels.js +1 -1
  77. package/dist/server/routes/apiOAuth.js +1 -1
  78. package/dist/server/routes/apiProviders.js +1 -1
  79. package/dist/server/routes/apiQuota.js +1 -1
  80. package/dist/server/routes/apiServer.js +1 -1
  81. package/dist/server/routes/mitmRouterTargetHelper.js +1 -1
  82. package/dist/server/utils/consoleLogBuffer.js +1 -1
  83. package/dist/shared/constants/index.js +1 -1
  84. package/dist/shared/utils/dnsResolver.js +1 -1
  85. package/dist/shared/utils/security.js +1 -1
  86. package/dist/shared/utils/versionChecker.js +1 -1
  87. package/dist/storage/backupService.js +1 -1
  88. package/dist/storage/database.js +3 -2
  89. package/dist/storage/repositories/comboRepo.js +11 -9
  90. package/dist/storage/repositories/logRepo.js +5 -8
  91. package/dist/storage/repositories/mitmRepo.js +5 -5
  92. package/dist/storage/repositories/modelRepo.js +9 -7
  93. package/dist/storage/repositories/providerRepo.js +5 -5
  94. package/dist/storage/repositories/requestDetailsRepo.js +5 -5
  95. package/dist/storage/repositories/settingsRepo.js +2 -2
  96. package/dist/storage/repositories/toolMappingRepo.js +4 -4
  97. package/dist/web/assets/CallbackPage-sTRnWJ-d.js +1 -0
  98. package/dist/web/assets/{CliToolsTab-D_MUwimj.js → CliToolsTab-CJ1qK1mc.js} +2 -2
  99. package/dist/web/assets/{CombosTab-EWUYC3TU.js → CombosTab-C__IN7Vh.js} +1 -1
  100. package/dist/web/assets/{ConfirmModal-CMfDss7P.js → ConfirmModal-S6NP0OqD.js} +1 -1
  101. package/dist/web/assets/{ConsoleLogTab-BSMXSYrR.js → ConsoleLogTab-BW7FAr8M.js} +1 -1
  102. package/dist/web/assets/{EditAccountModal-OrvqLLBP.js → EditAccountModal-BOJ3dX8Q.js} +1 -1
  103. package/dist/web/assets/{EndpointTab-BwtzqXUN.js → EndpointTab-DpvqvtLI.js} +1 -1
  104. package/dist/web/assets/{MitmTab-C7g7GUXW.js → MitmTab-BkYhPR9f.js} +6 -6
  105. package/dist/web/assets/ProviderDetailPage-D7ptkJW2.js +6 -0
  106. package/dist/web/assets/{ProvidersTab-CwJo_EUX.js → ProvidersTab-C0UAYPzg.js} +1 -1
  107. package/dist/web/assets/{QuotaTab-PFvP6yAb.js → QuotaTab-CK7pgfKr.js} +1 -1
  108. package/dist/web/assets/{SettingsTab-DwAbjIW3.js → SettingsTab-DpK_sfw0.js} +1 -1
  109. package/dist/web/assets/{UsageTab-85tTb2_C.js → UsageTab-dv87ggGC.js} +1 -1
  110. package/dist/web/assets/index-D3Xjro_O.js +2 -0
  111. package/dist/web/index.html +1 -1
  112. package/package.json +1 -1
  113. package/dist/web/assets/CallbackPage-DBsxnmPi.js +0 -1
  114. package/dist/web/assets/ProviderDetailPage-BIfOQupC.js +0 -6
  115. package/dist/web/assets/index-CWkEEbms.js +0 -2
@@ -1,4 +1,4 @@
1
- import{r as c,j as e,a as fe}from"./vendor-BcOI2aZ9.js";import{S as V}from"./Select-BNRH8LIG.js";import{L as ee,i as se,t as ge,P as je,f as X,g as re,u as Ne,R as ve,l as ye,X as de,h as ie,Z as xe,k as we,W as le,C as pe,D as Ce,A as Ee,a as Te,v as ke,S as Se,e as Ae,w as Le,x as ze}from"./lucide-Cc35htxl.js";import{T as me}from"./ToolIcon-Cp4gSgFt.js";import{u as ue,D as be,d as he,a as Be,c as Re,A as Oe}from"./index-CWkEEbms.js";const Me=[{value:"trace",label:"TRACE (Max)",icon:e.jsx("span",{className:"size-2 rounded-full bg-purple-400 shadow-[0_0_6px_#c084fc]"})},{value:"debug",label:"DEBUG",icon:e.jsx("span",{className:"size-2 rounded-full bg-sky-400 shadow-[0_0_6px_#38bdf8]"})},{value:"info",label:"INFO (Default)",icon:e.jsx("span",{className:"size-2 rounded-full bg-emerald-400 shadow-[0_0_6px_#34d399]"})},{value:"warn",label:"WARN",icon:e.jsx("span",{className:"size-2 rounded-full bg-amber-400 shadow-[0_0_6px_#facc15]"})},{value:"error",label:"ERROR",icon:e.jsx("span",{className:"size-2 rounded-full bg-red-400 shadow-[0_0_6px_#f87171]"})}],$e=[{value:"errors_only",label:"Trace: Errors Only",icon:e.jsx("span",{className:"size-2 rounded-full bg-amber-400 shadow-[0_0_6px_#facc15]"})},{value:"all",label:"Trace: All Requests",icon:e.jsx("span",{className:"size-2 rounded-full bg-emerald-400 shadow-[0_0_6px_#34d399]"})},{value:"off",label:"Trace: Disabled (Off)",icon:e.jsx("span",{className:"size-2 rounded-full bg-slate-500"})}],Ie=({connected:t,totalCount:o,filteredCount:n,viewMode:s,onViewModeChange:w,categoryTab:f,onCategoryTabChange:u,searchQuery:b,onSearchQueryChange:p,clientToolFilter:C,onClientToolFilterChange:i,providerFilter:g,onProviderFilterChange:a,statusFilter:E,onStatusFilterChange:j,levelFilter:T,onLevelFilterChange:N,gatewayLogLevel:l,onGatewayLogLevelChange:k,observabilityMode:z,onObservabilityModeChange:S,autoScroll:L,onAutoScrollToggle:_,onCopy:B,copied:U,onClear:A,availableTools:J,availableProviders:q})=>{const D=c.useMemo(()=>[{value:"all",label:"Tool: All"},...J.map(m=>({value:m,label:`Tool: ${m}`}))],[J]),P=c.useMemo(()=>[{value:"all",label:"Provider: All"},...q.map(m=>({value:m,label:`Provider: ${m}`}))],[q]),F=c.useMemo(()=>[{value:"all",label:"Status: All"},{value:"200",label:"200 OK",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-emerald-400"})},{value:"429",label:"429 Rate Limit",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-amber-400"})},{value:"error",label:"5xx / Errors",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-red-400"})}],[]),G=c.useMemo(()=>[{value:"all",label:"Level: All"},{value:"trace",label:"Trace only",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-purple-400"})},{value:"debug",label:"Debug only",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-sky-400"})},{value:"info",label:"Info only",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-emerald-400"})},{value:"warn",label:"Warn only",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-amber-400"})},{value:"error",label:"Error only",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-red-400"})}],[]),R=C!=="all"||g!=="all"||E!=="all"||T!=="all"||b.trim()!=="",H=()=>{i("all"),a("all"),j("all"),N("all"),p("")};return e.jsxs("div",{className:"space-y-2.5 shrink-0",children:[e.jsxs("div",{className:"rt-card px-4 py-2.5 flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1 rounded-lg bg-[#0A0D14] border border-[#1E293B]",children:[e.jsx("span",{className:`size-2 rounded-full ${t?"bg-emerald-400 shadow-[0_0_8px_#34d399]":"bg-red-500 animate-pulse"}`}),e.jsx("span",{className:"text-xs font-semibold text-slate-300",children:t?"Live Stream":"Disconnected"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-lg bg-[#0A0D14] border border-[#1E293B] text-xs font-mono text-slate-400",children:[e.jsx("span",{className:"text-slate-200 font-semibold",children:n}),n!==o&&e.jsxs("span",{className:"text-slate-500",children:["/ ",o]}),e.jsx("span",{children:"logs"})]}),e.jsxs("div",{className:"flex items-center bg-[#0A0D14] p-0.5 rounded-lg border border-[#1E293B]",children:[e.jsxs("button",{type:"button",onClick:()=>w("structured"),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-semibold transition-colors cursor-pointer ${s==="structured"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-slate-200"}`,children:[e.jsx(ee,{className:"size-3.5"}),e.jsx("span",{children:"AI Transactions"})]}),e.jsxs("button",{type:"button",onClick:()=>w("raw"),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-semibold transition-colors cursor-pointer ${s==="raw"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-slate-200"}`,children:[e.jsx(se,{className:"size-3.5"}),e.jsx("span",{children:"Raw Terminal"})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[11px] font-semibold text-slate-400 shrink-0",children:"Log Level:"}),e.jsx(V,{value:l,onChange:k,options:Me,size:"sm",className:"min-w-[140px]",triggerClassName:"h-8 !py-1 !px-2.5 text-xs font-semibold rounded-lg bg-[#0A0D14] border-[#1E293B] hover:border-slate-700",menuClassName:"min-w-[145px] shadow-2xl border border-[#1E293B] bg-[#0A0D14]/95 backdrop-blur-xl"})]}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsx(V,{value:z,onChange:m=>S(m),options:$e,size:"sm",className:"min-w-[170px]",triggerClassName:"h-8 !py-1 !px-2.5 text-xs font-semibold rounded-lg bg-[#0A0D14] border-[#1E293B] hover:border-slate-700",menuClassName:"min-w-[180px] shadow-2xl border border-[#1E293B] bg-[#0A0D14]/95 backdrop-blur-xl"})})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("button",{type:"button",onClick:_,className:`px-2.5 py-1 rounded-lg text-xs font-semibold border flex items-center gap-1.5 transition-colors cursor-pointer ${L?"bg-blue-500/10 text-blue-400 border-blue-500/30 hover:bg-blue-500/20":"bg-slate-800/40 text-slate-400 border-slate-700/60 hover:text-slate-200"}`,title:L?"Pause auto-scrolling":"Enable auto-scrolling",children:[L?e.jsx(ge,{className:"size-3.5"}):e.jsx(je,{className:"size-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:L?"Auto-scroll ON":"Paused"})]}),e.jsxs("button",{type:"button",onClick:B,disabled:n===0,className:"px-2.5 py-1 rounded-lg text-xs font-semibold bg-[#0A0D14] border border-[#1E293B] text-slate-300 hover:text-white hover:border-slate-600 disabled:opacity-40 disabled:cursor-not-allowed flex items-center gap-1.5 transition-colors cursor-pointer",title:"Copy logs",children:[U?e.jsx(X,{className:"size-3.5 text-emerald-400"}):e.jsx(re,{className:"size-3.5"}),e.jsx("span",{children:U?"Copied!":"Copy"})]}),e.jsxs("button",{type:"button",onClick:A,disabled:o===0,className:"px-2.5 py-1 rounded-lg text-xs font-semibold bg-red-500/10 border border-red-500/20 text-red-400 hover:bg-red-500/20 hover:border-red-500/40 disabled:opacity-40 disabled:cursor-not-allowed flex items-center gap-1.5 transition-colors cursor-pointer",title:"Clear all logs",children:[e.jsx(Ne,{className:"size-3.5"}),e.jsx("span",{children:"Clear"})]})]})]}),e.jsxs("div",{className:"rt-card px-4 py-2.5 flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"flex items-center gap-1 overflow-x-auto pb-1 sm:pb-0",children:[{id:"all",label:"All Logs"},{id:"proxy",label:"AI Requests"},{id:"stream",label:"Stream & Tools"},{id:"errors",label:"Errors & Warns"},{id:"system",label:"System & MITM"}].map(m=>e.jsx("button",{type:"button",onClick:()=>u(m.id),className:`px-3 py-1.5 rounded-lg text-xs font-medium transition-all cursor-pointer whitespace-nowrap ${f===m.id?"bg-blue-600/15 text-blue-400 font-semibold border border-blue-500/30 shadow-xs":"text-slate-400 hover:text-slate-200 hover:bg-white/[0.04] border border-transparent"}`,children:m.label},m.id))}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap flex-1 justify-end min-w-[280px]",children:[e.jsx(V,{value:C,onChange:i,options:D,size:"sm",className:"min-w-[115px]",triggerClassName:`h-8 !py-1 !px-2.5 text-xs font-medium rounded-lg transition-colors ${C!=="all"?"border-blue-500/50 bg-blue-500/10 text-blue-300 font-semibold":"border-[#1E293B] bg-[#0A0D14] text-slate-300 hover:border-slate-700"}`,menuClassName:"min-w-[130px] shadow-2xl border border-[#1E293B] bg-[#0A0D14]/95 backdrop-blur-xl"}),e.jsx(V,{value:g,onChange:a,options:P,size:"sm",className:"min-w-[125px]",triggerClassName:`h-8 !py-1 !px-2.5 text-xs font-medium rounded-lg transition-colors ${g!=="all"?"border-blue-500/50 bg-blue-500/10 text-blue-300 font-semibold":"border-[#1E293B] bg-[#0A0D14] text-slate-300 hover:border-slate-700"}`,menuClassName:"min-w-[140px] shadow-2xl border border-[#1E293B] bg-[#0A0D14]/95 backdrop-blur-xl"}),e.jsx(V,{value:E,onChange:j,options:F,size:"sm",className:"min-w-[115px]",triggerClassName:`h-8 !py-1 !px-2.5 text-xs font-medium rounded-lg transition-colors ${E!=="all"?"border-blue-500/50 bg-blue-500/10 text-blue-300 font-semibold":"border-[#1E293B] bg-[#0A0D14] text-slate-300 hover:border-slate-700"}`,menuClassName:"min-w-[130px] shadow-2xl border border-[#1E293B] bg-[#0A0D14]/95 backdrop-blur-xl"}),e.jsx(V,{value:T,onChange:N,options:G,size:"sm",className:"min-w-[115px]",triggerClassName:`h-8 !py-1 !px-2.5 text-xs font-medium rounded-lg transition-colors ${T!=="all"?"border-blue-500/50 bg-blue-500/10 text-blue-300 font-semibold":"border-[#1E293B] bg-[#0A0D14] text-slate-300 hover:border-slate-700"}`,menuClassName:"right-0 left-auto min-w-[130px] shadow-2xl border border-[#1E293B] bg-[#0A0D14]/95 backdrop-blur-xl"}),R&&e.jsxs("button",{type:"button",onClick:H,className:"h-8 px-2 py-1 rounded-lg text-xs font-semibold text-slate-400 hover:text-white hover:bg-slate-800/50 border border-transparent hover:border-slate-700 flex items-center gap-1 transition-colors cursor-pointer",title:"Reset all filters to default",children:[e.jsx(ve,{className:"size-3"}),e.jsx("span",{className:"hidden xl:inline",children:"Reset"})]}),e.jsxs("div",{className:"relative w-44 sm:w-52",children:[e.jsx(ye,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 size-3.5 text-slate-500"}),e.jsx("input",{type:"text",placeholder:"Search in logs...",value:b,onChange:m=>p(m.target.value),className:"h-8 w-full bg-[#0A0D14] border border-[#1E293B] rounded-lg pl-8 pr-7 text-xs text-white placeholder-slate-500 font-mono focus:outline-hidden focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 transition-all"}),b&&e.jsx("button",{type:"button",onClick:()=>p(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-slate-400 hover:text-white cursor-pointer",children:e.jsx(de,{className:"size-3"})})]})]})]})]})};function _e(t){const o=new Date(t),n=s=>String(s).padStart(2,"0");return`${n(o.getHours())}:${n(o.getMinutes())}:${n(o.getSeconds())}`}const De=({entry:t,onClick:o,isSelected:n=!1})=>{const{gateway:s,level:w,category:f,message:u,reqTag:b,timestamp:p,error:C}=t,i=(s==null?void 0:s.statusCode)||(C==null?void 0:C.status),g=i&&i>=200&&i<300,a=i===429,E=w==="error"||i&&i>=400&&!a,j=()=>a?e.jsx("span",{className:"px-2 py-0.5 rounded text-[11px] font-bold bg-amber-500/15 text-amber-400 border border-amber-500/30",children:"429"}):E?e.jsx("span",{className:"px-2 py-0.5 rounded text-[11px] font-bold bg-red-500/15 text-red-400 border border-red-500/30",children:i||"ERR"}):g?e.jsxs("span",{className:"px-2 py-0.5 rounded text-[11px] font-bold bg-emerald-500/15 text-emerald-400 border border-emerald-500/30",children:[i," OK"]}):null,T=()=>{switch(f){case"proxy":return"bg-blue-500/10 text-blue-400 border-blue-500/30";case"router":return"bg-purple-500/10 text-purple-400 border-purple-500/30";case"rtk":return"bg-emerald-500/10 text-emerald-400 border-emerald-500/30";case"mitm":return"bg-cyan-500/10 text-cyan-400 border-cyan-500/30";case"scheduler":return"bg-slate-700/30 text-slate-400 border-slate-700/50";default:return"bg-slate-800/40 text-slate-400 border-slate-700/60"}};return e.jsxs("div",{onClick:o,className:`group px-3.5 py-2.5 rounded-xl border transition-all cursor-pointer select-text ${n?"bg-[#131B2E] border-blue-500 shadow-md ring-1 ring-blue-500/20":"bg-[#0A0E18] hover:bg-[#0E1524] border-[#1E293B] hover:border-slate-700"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap min-w-0",children:[e.jsx("span",{className:"text-[11px] font-mono text-slate-500 shrink-0",children:_e(p)}),b&&e.jsx("span",{className:"text-xs shrink-0 select-none",children:b}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-semibold uppercase tracking-wider border shrink-0 ${T()}`,children:f}),w==="trace"&&e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-mono font-bold bg-purple-500/15 text-purple-400 border border-purple-500/30",children:"TRACE"}),w==="debug"&&e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-mono font-bold bg-sky-500/15 text-sky-400 border border-sky-500/30",children:"DEBUG"}),j(),(s==null?void 0:s.clientTool)&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-0.5 rounded-md bg-[#05070B] border border-[#1E293B]",children:[e.jsx(me,{name:s.clientTool,size:"sm",className:"size-4"}),e.jsx("span",{className:"text-xs font-semibold text-slate-300",children:s.clientTool})]}),((s==null?void 0:s.actualModel)||(s==null?void 0:s.requestedModel))&&e.jsxs("div",{className:"flex items-center gap-1 text-xs font-mono text-slate-300 truncate",children:[s.providerId&&e.jsxs("span",{className:"text-slate-500",children:[s.providerId,"/"]}),e.jsx("span",{className:"font-medium text-blue-300",children:s.actualModel||s.requestedModel})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0 ml-auto",children:[(s==null?void 0:s.durationMs)!==void 0&&e.jsxs("div",{className:"flex items-center gap-1 px-2 py-0.5 rounded-md bg-slate-900 border border-slate-800 text-[11px] font-mono text-slate-400",children:[e.jsx(ie,{className:"size-3 text-slate-500"}),e.jsxs("span",{children:[s.durationMs,"ms"]}),s.ttftMs!==void 0&&s.ttftMs>0&&e.jsxs("span",{className:"text-slate-500",children:["· TTFT ",s.ttftMs,"ms"]})]}),(s==null?void 0:s.tokens)&&e.jsxs("div",{className:"hidden sm:flex items-center gap-1 text-[11px] font-mono",children:[e.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-blue-500/10 text-blue-400 border border-blue-500/20",children:["IN ",s.tokens.prompt.toLocaleString(),s.tokens.cached?` (↻${s.tokens.cached.toLocaleString()})`:""]}),e.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-emerald-500/10 text-emerald-400 border border-emerald-500/20",children:["OUT ",s.tokens.completion.toLocaleString()]}),s.tokens.savedByRtk?e.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20 flex items-center gap-0.5",children:[e.jsx(xe,{className:"size-2.5"}),e.jsxs("span",{children:["-",s.tokens.savedByRtk.toLocaleString()]})]}):null]}),(s==null?void 0:s.cost)!==void 0&&s.cost>0&&e.jsxs("span",{className:"hidden md:inline px-1.5 py-0.5 rounded bg-slate-800 border border-slate-700 text-[11px] font-mono text-slate-300 font-semibold",children:["$",s.cost<.01?s.cost.toFixed(4):s.cost.toFixed(3)]}),e.jsx(we,{className:"size-4 text-slate-600 group-hover:text-slate-400 transition-colors"})]})]}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-xs font-mono text-slate-400 truncate flex-1",children:u}),(s==null?void 0:s.tools)&&s.tools.length>0&&e.jsxs("div",{className:"flex items-center gap-1 shrink-0 overflow-hidden",children:[s.tools.slice(0,3).map((N,l)=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-mono bg-purple-500/15 text-purple-300 border border-purple-500/30",children:[e.jsx(le,{className:"size-2.5"}),e.jsx("span",{className:"truncate max-w-[120px]",children:N.name})]},l)),s.tools.length>3&&e.jsxs("span",{className:"text-[10px] text-slate-500 font-mono",children:["+",s.tools.length-3]})]})]})]})};function Pe(t){const o=t.toUpperCase();return o.includes("[ERROR]")||o.includes("ERROR:")||o.includes("EXCEPTION")||t.includes("Error:")||t.includes("ERR!")||t.toLowerCase().includes("failed")||t.includes("💥")||t.includes("❌")?"text-red-400":o.includes("[WARN]")||o.includes("WARN:")||o.includes("WARNING:")||t.includes("⚠️")?"text-amber-400":o.includes("[INFO]")||o.includes("INFO:")||t.includes("ℹ️")?"text-blue-400":o.includes("[LOG]")||t.includes("🚀")||t.includes("📡")||t.includes("▶")||t.includes("✔")||t.includes("Gateway running")||t.includes("📊")?"text-emerald-400":o.includes("[DEBUG]")||t.includes("🔍")?"text-purple-400":"text-slate-300"}const Fe=({logs:t,filterText:o,scrollRef:n})=>{const s=ue(u=>u.info),w=(s==null?void 0:s.port)||be,f=(s==null?void 0:s.host)||he;return e.jsxs("div",{className:"flex-1 flex flex-col rounded-xl border border-[#1E293B] bg-[#05070B] overflow-hidden shadow-2xl min-h-0",children:[e.jsxs("div",{className:"bg-[#0A0D14] px-4 py-2 border-b border-[#1E293B] flex items-center justify-between shrink-0 select-none",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"size-3 rounded-full bg-[#EF4444]/80 inline-block"}),e.jsx("span",{className:"size-3 rounded-full bg-[#F59E0B]/80 inline-block"}),e.jsx("span",{className:"size-3 rounded-full bg-[#10B981]/80 inline-block"}),e.jsx("span",{className:"ml-2 text-[11px] font-mono text-slate-400",children:"mapigate-gateway > stdout / stderr"})]}),e.jsx("div",{className:"text-[10px] font-mono text-slate-500",children:"UTF-8 · Local Gateway"})]}),e.jsx("div",{ref:n,className:"flex-1 p-4 font-mono text-xs overflow-y-auto space-y-0.5 select-text",children:t.length===0?e.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-slate-500 py-16 space-y-2 select-none",children:[e.jsx(se,{className:"size-8 text-slate-600"}),e.jsx("p",{className:"text-xs",children:o.trim()?`No logs match "${o}"`:"No console logs yet. Gateway logs will stream here in real time."}),e.jsxs("span",{className:"text-[10px] text-slate-600 font-mono",children:["Listening on http://",f,":",w,"/api/console-logs/stream"]})]}):t.map((u,b)=>{const p=Pe(u);return e.jsxs("div",{className:`py-0.5 px-1.5 rounded flex items-start gap-2.5 hover:bg-white/[0.03] transition-colors leading-relaxed ${p}`,children:[e.jsx("span",{className:"text-slate-600 select-none text-[10px] w-9 text-right shrink-0 pt-0.5 font-mono",children:b+1}),e.jsx("span",{className:"break-all whitespace-pre-wrap flex-1",children:u})]},b)})})]})},Ue=({tokens:t})=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h4",{className:"text-xs font-semibold text-slate-400 uppercase tracking-wider flex items-center gap-1.5",children:[e.jsx(pe,{className:"size-3.5 text-blue-400"})," Token Economics"]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2.5",children:[e.jsxs("div",{className:"p-3 rounded-lg bg-[#0A0E18] border border-[#1E293B]",children:[e.jsx("span",{className:"text-[11px] text-slate-400",children:"Prompt Tokens"}),e.jsx("p",{className:"text-sm font-bold font-mono text-blue-400",children:t.prompt.toLocaleString()})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-[#0A0E18] border border-[#1E293B]",children:[e.jsx("span",{className:"text-[11px] text-slate-400",children:"Cached Tokens (↻)"}),e.jsx("p",{className:"text-sm font-bold font-mono text-cyan-400",children:(t.cached||0).toLocaleString()})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-[#0A0E18] border border-[#1E293B]",children:[e.jsx("span",{className:"text-[11px] text-slate-400",children:"Output Tokens"}),e.jsx("p",{className:"text-sm font-bold font-mono text-emerald-400",children:t.completion.toLocaleString()})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-[#0A0E18] border border-[#1E293B]",children:[e.jsx("span",{className:"text-[11px] text-slate-400",children:"Tokens Saved"}),e.jsxs("p",{className:"text-sm font-bold font-mono text-amber-400 flex items-center gap-1",children:[e.jsx(xe,{className:"size-3"}),(t.savedByRtk||0).toLocaleString()]})]})]})]}),Je=({tools:t})=>!t||t.length===0?null:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h4",{className:"text-xs font-semibold text-slate-400 uppercase tracking-wider flex items-center gap-1.5",children:[e.jsx(le,{className:"size-3.5 text-purple-400"})," Tool Calls (",t.length,")"]}),e.jsx("div",{className:"space-y-2",children:t.map((o,n)=>e.jsxs("div",{className:"p-3 rounded-lg bg-[#0A0E18] border border-[#1E293B] flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"p-1 rounded bg-purple-500/20 text-purple-300",children:e.jsx(le,{className:"size-3.5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-bold text-white font-mono truncate",children:o.name}),e.jsx("p",{className:"text-[11px] text-slate-400 font-mono truncate",children:o.summary})]})]}),e.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-semibold bg-slate-800 text-slate-300 uppercase",children:o.type})]},n))})]}),qe=({detail:t,loading:o=!1})=>{var E,j,T,N,l,k,z,S,L;const[n,s]=c.useState("client"),[w,f]=c.useState(null),u=(_,B)=>{navigator.clipboard.writeText(_),f(B),setTimeout(()=>f(null),2e3)};if(o)return e.jsxs("div",{className:"p-6 rounded-xl bg-[#0A0E18] border border-[#1E293B] flex items-center justify-center gap-3 text-slate-400",children:[e.jsx("span",{className:"size-4 border-2 border-blue-400 border-t-transparent rounded-full animate-spin"}),e.jsx("span",{className:"text-xs font-mono",children:"Loading full payload observability trace..."})]});if(!t)return e.jsxs("div",{className:"p-5 rounded-xl bg-[#0A0E18] border border-[#1E293B] space-y-2 text-center select-none",children:[e.jsx(Ce,{className:"size-6 text-slate-500 mx-auto"}),e.jsx("p",{className:"text-xs font-semibold text-slate-300",children:"No payload trace snapshot found for this request"}),e.jsxs("p",{className:"text-[11px] text-slate-500 max-w-md mx-auto",children:["Observability trace is either set to ",e.jsx("strong",{className:"text-amber-400 font-mono",children:"Errors Only"})," (which bypasses successful 200 OK payloads) or ",e.jsx("strong",{className:"text-slate-400 font-mono",children:"Off"}),". Switch to ",e.jsx("strong",{className:"text-emerald-400 font-mono",children:"Trace: All"})," in the top toolbar to record all full payloads."]})]});const b=((E=t.request)==null?void 0:E.body)||{},p=((j=t.providerRequest)==null?void 0:j.body)||{},C=((T=t.response)==null?void 0:T.body)||((N=t.providerResponse)==null?void 0:N.body)||t.errorMessage||{},i=n==="client"?b:n==="providerReq"?p:C,g=n==="client"?(l=t.request)==null?void 0:l.headers:n==="providerReq"?(k=t.providerRequest)==null?void 0:k.headers:((z=t.response)==null?void 0:z.headers)||((S=t.providerResponse)==null?void 0:S.headers),a=JSON.stringify(i,null,2);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1 bg-[#05070B] p-1 rounded-lg border border-[#1E293B]",children:[e.jsxs("button",{type:"button",onClick:()=>s("client"),className:`flex items-center gap-1.5 px-3 py-1 rounded text-xs font-semibold transition-all cursor-pointer ${n==="client"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-slate-200"}`,children:[e.jsx(Ee,{className:"size-3.5"}),e.jsx("span",{children:"Client Inbound"})]}),e.jsxs("button",{type:"button",onClick:()=>s("providerReq"),className:`flex items-center gap-1.5 px-3 py-1 rounded text-xs font-semibold transition-all cursor-pointer ${n==="providerReq"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-slate-200"}`,children:[e.jsx(Te,{className:"size-3.5"}),e.jsx("span",{children:"Provider Transformed"})]}),e.jsxs("button",{type:"button",onClick:()=>s("response"),className:`flex items-center gap-1.5 px-3 py-1 rounded text-xs font-semibold transition-all cursor-pointer ${n==="response"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-slate-200"}`,children:[e.jsx(ke,{className:"size-3.5"}),e.jsx("span",{children:"Response & Output"})]})]}),e.jsx("button",{type:"button",onClick:()=>u(a,n),className:"px-2.5 py-1 rounded-md bg-[#0A0E18] border border-[#1E293B] text-slate-300 hover:text-white flex items-center gap-1.5 transition-colors text-xs cursor-pointer",children:w===n?e.jsxs(e.Fragment,{children:[e.jsx(X,{className:"size-3.5 text-emerald-400"}),e.jsx("span",{children:"Copied JSON"})]}):e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"size-3.5"}),e.jsx("span",{children:"Copy JSON"})]})})]}),n==="providerReq"&&((L=t.providerRequest)==null?void 0:L.url)&&e.jsxs("div",{className:"px-3 py-1.5 rounded-lg bg-[#05070B] border border-[#1E293B] text-[11px] font-mono text-slate-400 flex items-center gap-2",children:[e.jsx("span",{className:"text-slate-500 uppercase font-bold text-[10px]",children:"URL:"}),e.jsx("span",{className:"text-blue-300 truncate",children:t.providerRequest.url})]}),g&&Object.keys(g).length>0&&e.jsxs("details",{className:"rounded-lg bg-[#05070B] border border-[#1E293B] text-[11px] font-mono text-slate-400 overflow-hidden",children:[e.jsx("summary",{className:"px-3 py-1.5 cursor-pointer hover:text-slate-200 select-none flex items-center justify-between",children:e.jsxs("span",{className:"font-semibold text-slate-300",children:["Headers (",Object.keys(g).length,")"]})}),e.jsx("div",{className:"p-3 border-t border-[#1E293B] bg-black/40 max-h-36 overflow-y-auto",children:e.jsx("pre",{className:"text-[10px] text-slate-300 whitespace-pre-wrap",children:JSON.stringify(g,null,2)})})]}),e.jsx("div",{className:"rounded-xl bg-[#05070B] border border-[#1E293B] p-3 max-h-96 overflow-y-auto font-mono text-[11px] text-slate-200 leading-relaxed",children:a&&a!=="{}"?e.jsx("pre",{className:"whitespace-pre-wrap break-all select-text",children:a}):e.jsx("span",{className:"text-slate-500 italic",children:"No JSON payload body captured for this section."})})]})},Ge=({entry:t,isOpen:o,onClose:n})=>{var R,H,m,$,Y;const s=ue(v=>v.info),w=(s==null?void 0:s.port)||be,f=(s==null?void 0:s.host)||he,[u,b]=c.useState(!1),[p,C]=c.useState(!1),[i,g]=c.useState(!1),[a,E]=c.useState(null),[j,T]=c.useState(!1),{backdropProps:N}=Be(n,!o);if(c.useEffect(()=>{if(!o)return;const v=O=>{O.key==="Escape"&&n()};document.addEventListener("keydown",v);const y=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",v),document.body.style.overflow=y}},[o,n]),c.useEffect(()=>{if(!o||!t){E(null);return}const v=t.requestId||t.id;if(!v){E(null);return}let y=!0;return T(!0),fetch(`/api/usage/request-details/${encodeURIComponent(v)}`).then(O=>O.ok?O.json():null).then(O=>{y&&(E(O),T(!1))}).catch(()=>{y&&T(!1)}),()=>{y=!1}},[o,t]),!o||!t||typeof document>"u")return null;const{gateway:l,error:k,level:z,category:S,rawText:L,reqTag:_,id:B,requestId:U}=t,A=(l==null?void 0:l.statusCode)||(k==null?void 0:k.status)||(a==null?void 0:a.status),J=A===429,q=z==="error"||typeof A=="number"&&A>=400&&!J,D=typeof A=="number"&&A>=200&&A<300,P=S==="proxy"||!!l||!!a||!!t.requestId,F=(v,y)=>{navigator.clipboard.writeText(v),y==="id"?(b(!0),setTimeout(()=>b(!1),2e3)):y==="json"?(C(!0),setTimeout(()=>C(!1),2e3)):y==="curl"&&(g(!0),setTimeout(()=>g(!1),2e3))},G=()=>{var Z;const v=(l==null?void 0:l.route)||"/v1/messages",y=(l==null?void 0:l.actualModel)||(l==null?void 0:l.requestedModel)||(a==null?void 0:a.model)||"claude-3-7-sonnet",O=((Z=a==null?void 0:a.request)==null?void 0:Z.body)||{model:y,messages:[{role:"user",content:"Hello"}]},te=JSON.stringify(O,null,2).replace(/'/g,"'\\''");return`curl -X POST http://${f}:${w}${v} \\
1
+ import{r as c,j as e,a as fe}from"./vendor-BcOI2aZ9.js";import{S as V}from"./Select-BNRH8LIG.js";import{L as ee,i as se,t as ge,P as je,f as X,g as re,u as Ne,R as ve,l as ye,X as de,h as ie,Z as xe,k as we,W as le,C as pe,D as Ce,A as Ee,a as Te,v as ke,S as Se,e as Ae,w as Le,x as ze}from"./lucide-Cc35htxl.js";import{T as me}from"./ToolIcon-Cp4gSgFt.js";import{u as ue,D as be,d as he,a as Be,c as Re,A as Oe}from"./index-D3Xjro_O.js";const Me=[{value:"trace",label:"TRACE (Max)",icon:e.jsx("span",{className:"size-2 rounded-full bg-purple-400 shadow-[0_0_6px_#c084fc]"})},{value:"debug",label:"DEBUG",icon:e.jsx("span",{className:"size-2 rounded-full bg-sky-400 shadow-[0_0_6px_#38bdf8]"})},{value:"info",label:"INFO (Default)",icon:e.jsx("span",{className:"size-2 rounded-full bg-emerald-400 shadow-[0_0_6px_#34d399]"})},{value:"warn",label:"WARN",icon:e.jsx("span",{className:"size-2 rounded-full bg-amber-400 shadow-[0_0_6px_#facc15]"})},{value:"error",label:"ERROR",icon:e.jsx("span",{className:"size-2 rounded-full bg-red-400 shadow-[0_0_6px_#f87171]"})}],$e=[{value:"errors_only",label:"Trace: Errors Only",icon:e.jsx("span",{className:"size-2 rounded-full bg-amber-400 shadow-[0_0_6px_#facc15]"})},{value:"all",label:"Trace: All Requests",icon:e.jsx("span",{className:"size-2 rounded-full bg-emerald-400 shadow-[0_0_6px_#34d399]"})},{value:"off",label:"Trace: Disabled (Off)",icon:e.jsx("span",{className:"size-2 rounded-full bg-slate-500"})}],Ie=({connected:t,totalCount:o,filteredCount:n,viewMode:s,onViewModeChange:w,categoryTab:f,onCategoryTabChange:u,searchQuery:b,onSearchQueryChange:p,clientToolFilter:C,onClientToolFilterChange:i,providerFilter:g,onProviderFilterChange:a,statusFilter:E,onStatusFilterChange:j,levelFilter:T,onLevelFilterChange:N,gatewayLogLevel:l,onGatewayLogLevelChange:k,observabilityMode:z,onObservabilityModeChange:S,autoScroll:L,onAutoScrollToggle:_,onCopy:B,copied:U,onClear:A,availableTools:J,availableProviders:q})=>{const D=c.useMemo(()=>[{value:"all",label:"Tool: All"},...J.map(m=>({value:m,label:`Tool: ${m}`}))],[J]),P=c.useMemo(()=>[{value:"all",label:"Provider: All"},...q.map(m=>({value:m,label:`Provider: ${m}`}))],[q]),F=c.useMemo(()=>[{value:"all",label:"Status: All"},{value:"200",label:"200 OK",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-emerald-400"})},{value:"429",label:"429 Rate Limit",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-amber-400"})},{value:"error",label:"5xx / Errors",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-red-400"})}],[]),G=c.useMemo(()=>[{value:"all",label:"Level: All"},{value:"trace",label:"Trace only",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-purple-400"})},{value:"debug",label:"Debug only",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-sky-400"})},{value:"info",label:"Info only",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-emerald-400"})},{value:"warn",label:"Warn only",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-amber-400"})},{value:"error",label:"Error only",icon:e.jsx("span",{className:"size-1.5 rounded-full bg-red-400"})}],[]),R=C!=="all"||g!=="all"||E!=="all"||T!=="all"||b.trim()!=="",H=()=>{i("all"),a("all"),j("all"),N("all"),p("")};return e.jsxs("div",{className:"space-y-2.5 shrink-0",children:[e.jsxs("div",{className:"rt-card px-4 py-2.5 flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1 rounded-lg bg-[#0A0D14] border border-[#1E293B]",children:[e.jsx("span",{className:`size-2 rounded-full ${t?"bg-emerald-400 shadow-[0_0_8px_#34d399]":"bg-red-500 animate-pulse"}`}),e.jsx("span",{className:"text-xs font-semibold text-slate-300",children:t?"Live Stream":"Disconnected"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1 rounded-lg bg-[#0A0D14] border border-[#1E293B] text-xs font-mono text-slate-400",children:[e.jsx("span",{className:"text-slate-200 font-semibold",children:n}),n!==o&&e.jsxs("span",{className:"text-slate-500",children:["/ ",o]}),e.jsx("span",{children:"logs"})]}),e.jsxs("div",{className:"flex items-center bg-[#0A0D14] p-0.5 rounded-lg border border-[#1E293B]",children:[e.jsxs("button",{type:"button",onClick:()=>w("structured"),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-semibold transition-colors cursor-pointer ${s==="structured"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-slate-200"}`,children:[e.jsx(ee,{className:"size-3.5"}),e.jsx("span",{children:"AI Transactions"})]}),e.jsxs("button",{type:"button",onClick:()=>w("raw"),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-semibold transition-colors cursor-pointer ${s==="raw"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-slate-200"}`,children:[e.jsx(se,{className:"size-3.5"}),e.jsx("span",{children:"Raw Terminal"})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[11px] font-semibold text-slate-400 shrink-0",children:"Log Level:"}),e.jsx(V,{value:l,onChange:k,options:Me,size:"sm",className:"min-w-[140px]",triggerClassName:"h-8 !py-1 !px-2.5 text-xs font-semibold rounded-lg bg-[#0A0D14] border-[#1E293B] hover:border-slate-700",menuClassName:"min-w-[145px] shadow-2xl border border-[#1E293B] bg-[#0A0D14]/95 backdrop-blur-xl"})]}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsx(V,{value:z,onChange:m=>S(m),options:$e,size:"sm",className:"min-w-[170px]",triggerClassName:"h-8 !py-1 !px-2.5 text-xs font-semibold rounded-lg bg-[#0A0D14] border-[#1E293B] hover:border-slate-700",menuClassName:"min-w-[180px] shadow-2xl border border-[#1E293B] bg-[#0A0D14]/95 backdrop-blur-xl"})})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("button",{type:"button",onClick:_,className:`px-2.5 py-1 rounded-lg text-xs font-semibold border flex items-center gap-1.5 transition-colors cursor-pointer ${L?"bg-blue-500/10 text-blue-400 border-blue-500/30 hover:bg-blue-500/20":"bg-slate-800/40 text-slate-400 border-slate-700/60 hover:text-slate-200"}`,title:L?"Pause auto-scrolling":"Enable auto-scrolling",children:[L?e.jsx(ge,{className:"size-3.5"}):e.jsx(je,{className:"size-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:L?"Auto-scroll ON":"Paused"})]}),e.jsxs("button",{type:"button",onClick:B,disabled:n===0,className:"px-2.5 py-1 rounded-lg text-xs font-semibold bg-[#0A0D14] border border-[#1E293B] text-slate-300 hover:text-white hover:border-slate-600 disabled:opacity-40 disabled:cursor-not-allowed flex items-center gap-1.5 transition-colors cursor-pointer",title:"Copy logs",children:[U?e.jsx(X,{className:"size-3.5 text-emerald-400"}):e.jsx(re,{className:"size-3.5"}),e.jsx("span",{children:U?"Copied!":"Copy"})]}),e.jsxs("button",{type:"button",onClick:A,disabled:o===0,className:"px-2.5 py-1 rounded-lg text-xs font-semibold bg-red-500/10 border border-red-500/20 text-red-400 hover:bg-red-500/20 hover:border-red-500/40 disabled:opacity-40 disabled:cursor-not-allowed flex items-center gap-1.5 transition-colors cursor-pointer",title:"Clear all logs",children:[e.jsx(Ne,{className:"size-3.5"}),e.jsx("span",{children:"Clear"})]})]})]}),e.jsxs("div",{className:"rt-card px-4 py-2.5 flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"flex items-center gap-1 overflow-x-auto pb-1 sm:pb-0",children:[{id:"all",label:"All Logs"},{id:"proxy",label:"AI Requests"},{id:"stream",label:"Stream & Tools"},{id:"errors",label:"Errors & Warns"},{id:"system",label:"System & MITM"}].map(m=>e.jsx("button",{type:"button",onClick:()=>u(m.id),className:`px-3 py-1.5 rounded-lg text-xs font-medium transition-all cursor-pointer whitespace-nowrap ${f===m.id?"bg-blue-600/15 text-blue-400 font-semibold border border-blue-500/30 shadow-xs":"text-slate-400 hover:text-slate-200 hover:bg-white/[0.04] border border-transparent"}`,children:m.label},m.id))}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap flex-1 justify-end min-w-[280px]",children:[e.jsx(V,{value:C,onChange:i,options:D,size:"sm",className:"min-w-[115px]",triggerClassName:`h-8 !py-1 !px-2.5 text-xs font-medium rounded-lg transition-colors ${C!=="all"?"border-blue-500/50 bg-blue-500/10 text-blue-300 font-semibold":"border-[#1E293B] bg-[#0A0D14] text-slate-300 hover:border-slate-700"}`,menuClassName:"min-w-[130px] shadow-2xl border border-[#1E293B] bg-[#0A0D14]/95 backdrop-blur-xl"}),e.jsx(V,{value:g,onChange:a,options:P,size:"sm",className:"min-w-[125px]",triggerClassName:`h-8 !py-1 !px-2.5 text-xs font-medium rounded-lg transition-colors ${g!=="all"?"border-blue-500/50 bg-blue-500/10 text-blue-300 font-semibold":"border-[#1E293B] bg-[#0A0D14] text-slate-300 hover:border-slate-700"}`,menuClassName:"min-w-[140px] shadow-2xl border border-[#1E293B] bg-[#0A0D14]/95 backdrop-blur-xl"}),e.jsx(V,{value:E,onChange:j,options:F,size:"sm",className:"min-w-[115px]",triggerClassName:`h-8 !py-1 !px-2.5 text-xs font-medium rounded-lg transition-colors ${E!=="all"?"border-blue-500/50 bg-blue-500/10 text-blue-300 font-semibold":"border-[#1E293B] bg-[#0A0D14] text-slate-300 hover:border-slate-700"}`,menuClassName:"min-w-[130px] shadow-2xl border border-[#1E293B] bg-[#0A0D14]/95 backdrop-blur-xl"}),e.jsx(V,{value:T,onChange:N,options:G,size:"sm",className:"min-w-[115px]",triggerClassName:`h-8 !py-1 !px-2.5 text-xs font-medium rounded-lg transition-colors ${T!=="all"?"border-blue-500/50 bg-blue-500/10 text-blue-300 font-semibold":"border-[#1E293B] bg-[#0A0D14] text-slate-300 hover:border-slate-700"}`,menuClassName:"right-0 left-auto min-w-[130px] shadow-2xl border border-[#1E293B] bg-[#0A0D14]/95 backdrop-blur-xl"}),R&&e.jsxs("button",{type:"button",onClick:H,className:"h-8 px-2 py-1 rounded-lg text-xs font-semibold text-slate-400 hover:text-white hover:bg-slate-800/50 border border-transparent hover:border-slate-700 flex items-center gap-1 transition-colors cursor-pointer",title:"Reset all filters to default",children:[e.jsx(ve,{className:"size-3"}),e.jsx("span",{className:"hidden xl:inline",children:"Reset"})]}),e.jsxs("div",{className:"relative w-44 sm:w-52",children:[e.jsx(ye,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 size-3.5 text-slate-500"}),e.jsx("input",{type:"text",placeholder:"Search in logs...",value:b,onChange:m=>p(m.target.value),className:"h-8 w-full bg-[#0A0D14] border border-[#1E293B] rounded-lg pl-8 pr-7 text-xs text-white placeholder-slate-500 font-mono focus:outline-hidden focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 transition-all"}),b&&e.jsx("button",{type:"button",onClick:()=>p(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-slate-400 hover:text-white cursor-pointer",children:e.jsx(de,{className:"size-3"})})]})]})]})]})};function _e(t){const o=new Date(t),n=s=>String(s).padStart(2,"0");return`${n(o.getHours())}:${n(o.getMinutes())}:${n(o.getSeconds())}`}const De=({entry:t,onClick:o,isSelected:n=!1})=>{const{gateway:s,level:w,category:f,message:u,reqTag:b,timestamp:p,error:C}=t,i=(s==null?void 0:s.statusCode)||(C==null?void 0:C.status),g=i&&i>=200&&i<300,a=i===429,E=w==="error"||i&&i>=400&&!a,j=()=>a?e.jsx("span",{className:"px-2 py-0.5 rounded text-[11px] font-bold bg-amber-500/15 text-amber-400 border border-amber-500/30",children:"429"}):E?e.jsx("span",{className:"px-2 py-0.5 rounded text-[11px] font-bold bg-red-500/15 text-red-400 border border-red-500/30",children:i||"ERR"}):g?e.jsxs("span",{className:"px-2 py-0.5 rounded text-[11px] font-bold bg-emerald-500/15 text-emerald-400 border border-emerald-500/30",children:[i," OK"]}):null,T=()=>{switch(f){case"proxy":return"bg-blue-500/10 text-blue-400 border-blue-500/30";case"router":return"bg-purple-500/10 text-purple-400 border-purple-500/30";case"rtk":return"bg-emerald-500/10 text-emerald-400 border-emerald-500/30";case"mitm":return"bg-cyan-500/10 text-cyan-400 border-cyan-500/30";case"scheduler":return"bg-slate-700/30 text-slate-400 border-slate-700/50";default:return"bg-slate-800/40 text-slate-400 border-slate-700/60"}};return e.jsxs("div",{onClick:o,className:`group px-3.5 py-2.5 rounded-xl border transition-all cursor-pointer select-text ${n?"bg-[#131B2E] border-blue-500 shadow-md ring-1 ring-blue-500/20":"bg-[#0A0E18] hover:bg-[#0E1524] border-[#1E293B] hover:border-slate-700"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap min-w-0",children:[e.jsx("span",{className:"text-[11px] font-mono text-slate-500 shrink-0",children:_e(p)}),b&&e.jsx("span",{className:"text-xs shrink-0 select-none",children:b}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-semibold uppercase tracking-wider border shrink-0 ${T()}`,children:f}),w==="trace"&&e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-mono font-bold bg-purple-500/15 text-purple-400 border border-purple-500/30",children:"TRACE"}),w==="debug"&&e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-mono font-bold bg-sky-500/15 text-sky-400 border border-sky-500/30",children:"DEBUG"}),j(),(s==null?void 0:s.clientTool)&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-0.5 rounded-md bg-[#05070B] border border-[#1E293B]",children:[e.jsx(me,{name:s.clientTool,size:"sm",className:"size-4"}),e.jsx("span",{className:"text-xs font-semibold text-slate-300",children:s.clientTool})]}),((s==null?void 0:s.actualModel)||(s==null?void 0:s.requestedModel))&&e.jsxs("div",{className:"flex items-center gap-1 text-xs font-mono text-slate-300 truncate",children:[s.providerId&&e.jsxs("span",{className:"text-slate-500",children:[s.providerId,"/"]}),e.jsx("span",{className:"font-medium text-blue-300",children:s.actualModel||s.requestedModel})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0 ml-auto",children:[(s==null?void 0:s.durationMs)!==void 0&&e.jsxs("div",{className:"flex items-center gap-1 px-2 py-0.5 rounded-md bg-slate-900 border border-slate-800 text-[11px] font-mono text-slate-400",children:[e.jsx(ie,{className:"size-3 text-slate-500"}),e.jsxs("span",{children:[s.durationMs,"ms"]}),s.ttftMs!==void 0&&s.ttftMs>0&&e.jsxs("span",{className:"text-slate-500",children:["· TTFT ",s.ttftMs,"ms"]})]}),(s==null?void 0:s.tokens)&&e.jsxs("div",{className:"hidden sm:flex items-center gap-1 text-[11px] font-mono",children:[e.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-blue-500/10 text-blue-400 border border-blue-500/20",children:["IN ",s.tokens.prompt.toLocaleString(),s.tokens.cached?` (↻${s.tokens.cached.toLocaleString()})`:""]}),e.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-emerald-500/10 text-emerald-400 border border-emerald-500/20",children:["OUT ",s.tokens.completion.toLocaleString()]}),s.tokens.savedByRtk?e.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20 flex items-center gap-0.5",children:[e.jsx(xe,{className:"size-2.5"}),e.jsxs("span",{children:["-",s.tokens.savedByRtk.toLocaleString()]})]}):null]}),(s==null?void 0:s.cost)!==void 0&&s.cost>0&&e.jsxs("span",{className:"hidden md:inline px-1.5 py-0.5 rounded bg-slate-800 border border-slate-700 text-[11px] font-mono text-slate-300 font-semibold",children:["$",s.cost<.01?s.cost.toFixed(4):s.cost.toFixed(3)]}),e.jsx(we,{className:"size-4 text-slate-600 group-hover:text-slate-400 transition-colors"})]})]}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-xs font-mono text-slate-400 truncate flex-1",children:u}),(s==null?void 0:s.tools)&&s.tools.length>0&&e.jsxs("div",{className:"flex items-center gap-1 shrink-0 overflow-hidden",children:[s.tools.slice(0,3).map((N,l)=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-mono bg-purple-500/15 text-purple-300 border border-purple-500/30",children:[e.jsx(le,{className:"size-2.5"}),e.jsx("span",{className:"truncate max-w-[120px]",children:N.name})]},l)),s.tools.length>3&&e.jsxs("span",{className:"text-[10px] text-slate-500 font-mono",children:["+",s.tools.length-3]})]})]})]})};function Pe(t){const o=t.toUpperCase();return o.includes("[ERROR]")||o.includes("ERROR:")||o.includes("EXCEPTION")||t.includes("Error:")||t.includes("ERR!")||t.toLowerCase().includes("failed")||t.includes("💥")||t.includes("❌")?"text-red-400":o.includes("[WARN]")||o.includes("WARN:")||o.includes("WARNING:")||t.includes("⚠️")?"text-amber-400":o.includes("[INFO]")||o.includes("INFO:")||t.includes("ℹ️")?"text-blue-400":o.includes("[LOG]")||t.includes("🚀")||t.includes("📡")||t.includes("▶")||t.includes("✔")||t.includes("Gateway running")||t.includes("📊")?"text-emerald-400":o.includes("[DEBUG]")||t.includes("🔍")?"text-purple-400":"text-slate-300"}const Fe=({logs:t,filterText:o,scrollRef:n})=>{const s=ue(u=>u.info),w=(s==null?void 0:s.port)||be,f=(s==null?void 0:s.host)||he;return e.jsxs("div",{className:"flex-1 flex flex-col rounded-xl border border-[#1E293B] bg-[#05070B] overflow-hidden shadow-2xl min-h-0",children:[e.jsxs("div",{className:"bg-[#0A0D14] px-4 py-2 border-b border-[#1E293B] flex items-center justify-between shrink-0 select-none",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"size-3 rounded-full bg-[#EF4444]/80 inline-block"}),e.jsx("span",{className:"size-3 rounded-full bg-[#F59E0B]/80 inline-block"}),e.jsx("span",{className:"size-3 rounded-full bg-[#10B981]/80 inline-block"}),e.jsx("span",{className:"ml-2 text-[11px] font-mono text-slate-400",children:"mapigate-gateway > stdout / stderr"})]}),e.jsx("div",{className:"text-[10px] font-mono text-slate-500",children:"UTF-8 · Local Gateway"})]}),e.jsx("div",{ref:n,className:"flex-1 p-4 font-mono text-xs overflow-y-auto space-y-0.5 select-text",children:t.length===0?e.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-slate-500 py-16 space-y-2 select-none",children:[e.jsx(se,{className:"size-8 text-slate-600"}),e.jsx("p",{className:"text-xs",children:o.trim()?`No logs match "${o}"`:"No console logs yet. Gateway logs will stream here in real time."}),e.jsxs("span",{className:"text-[10px] text-slate-600 font-mono",children:["Listening on http://",f,":",w,"/api/console-logs/stream"]})]}):t.map((u,b)=>{const p=Pe(u);return e.jsxs("div",{className:`py-0.5 px-1.5 rounded flex items-start gap-2.5 hover:bg-white/[0.03] transition-colors leading-relaxed ${p}`,children:[e.jsx("span",{className:"text-slate-600 select-none text-[10px] w-9 text-right shrink-0 pt-0.5 font-mono",children:b+1}),e.jsx("span",{className:"break-all whitespace-pre-wrap flex-1",children:u})]},b)})})]})},Ue=({tokens:t})=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h4",{className:"text-xs font-semibold text-slate-400 uppercase tracking-wider flex items-center gap-1.5",children:[e.jsx(pe,{className:"size-3.5 text-blue-400"})," Token Economics"]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2.5",children:[e.jsxs("div",{className:"p-3 rounded-lg bg-[#0A0E18] border border-[#1E293B]",children:[e.jsx("span",{className:"text-[11px] text-slate-400",children:"Prompt Tokens"}),e.jsx("p",{className:"text-sm font-bold font-mono text-blue-400",children:t.prompt.toLocaleString()})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-[#0A0E18] border border-[#1E293B]",children:[e.jsx("span",{className:"text-[11px] text-slate-400",children:"Cached Tokens (↻)"}),e.jsx("p",{className:"text-sm font-bold font-mono text-cyan-400",children:(t.cached||0).toLocaleString()})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-[#0A0E18] border border-[#1E293B]",children:[e.jsx("span",{className:"text-[11px] text-slate-400",children:"Output Tokens"}),e.jsx("p",{className:"text-sm font-bold font-mono text-emerald-400",children:t.completion.toLocaleString()})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-[#0A0E18] border border-[#1E293B]",children:[e.jsx("span",{className:"text-[11px] text-slate-400",children:"Tokens Saved"}),e.jsxs("p",{className:"text-sm font-bold font-mono text-amber-400 flex items-center gap-1",children:[e.jsx(xe,{className:"size-3"}),(t.savedByRtk||0).toLocaleString()]})]})]})]}),Je=({tools:t})=>!t||t.length===0?null:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h4",{className:"text-xs font-semibold text-slate-400 uppercase tracking-wider flex items-center gap-1.5",children:[e.jsx(le,{className:"size-3.5 text-purple-400"})," Tool Calls (",t.length,")"]}),e.jsx("div",{className:"space-y-2",children:t.map((o,n)=>e.jsxs("div",{className:"p-3 rounded-lg bg-[#0A0E18] border border-[#1E293B] flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"p-1 rounded bg-purple-500/20 text-purple-300",children:e.jsx(le,{className:"size-3.5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-bold text-white font-mono truncate",children:o.name}),e.jsx("p",{className:"text-[11px] text-slate-400 font-mono truncate",children:o.summary})]})]}),e.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-semibold bg-slate-800 text-slate-300 uppercase",children:o.type})]},n))})]}),qe=({detail:t,loading:o=!1})=>{var E,j,T,N,l,k,z,S,L;const[n,s]=c.useState("client"),[w,f]=c.useState(null),u=(_,B)=>{navigator.clipboard.writeText(_),f(B),setTimeout(()=>f(null),2e3)};if(o)return e.jsxs("div",{className:"p-6 rounded-xl bg-[#0A0E18] border border-[#1E293B] flex items-center justify-center gap-3 text-slate-400",children:[e.jsx("span",{className:"size-4 border-2 border-blue-400 border-t-transparent rounded-full animate-spin"}),e.jsx("span",{className:"text-xs font-mono",children:"Loading full payload observability trace..."})]});if(!t)return e.jsxs("div",{className:"p-5 rounded-xl bg-[#0A0E18] border border-[#1E293B] space-y-2 text-center select-none",children:[e.jsx(Ce,{className:"size-6 text-slate-500 mx-auto"}),e.jsx("p",{className:"text-xs font-semibold text-slate-300",children:"No payload trace snapshot found for this request"}),e.jsxs("p",{className:"text-[11px] text-slate-500 max-w-md mx-auto",children:["Observability trace is either set to ",e.jsx("strong",{className:"text-amber-400 font-mono",children:"Errors Only"})," (which bypasses successful 200 OK payloads) or ",e.jsx("strong",{className:"text-slate-400 font-mono",children:"Off"}),". Switch to ",e.jsx("strong",{className:"text-emerald-400 font-mono",children:"Trace: All"})," in the top toolbar to record all full payloads."]})]});const b=((E=t.request)==null?void 0:E.body)||{},p=((j=t.providerRequest)==null?void 0:j.body)||{},C=((T=t.response)==null?void 0:T.body)||((N=t.providerResponse)==null?void 0:N.body)||t.errorMessage||{},i=n==="client"?b:n==="providerReq"?p:C,g=n==="client"?(l=t.request)==null?void 0:l.headers:n==="providerReq"?(k=t.providerRequest)==null?void 0:k.headers:((z=t.response)==null?void 0:z.headers)||((S=t.providerResponse)==null?void 0:S.headers),a=JSON.stringify(i,null,2);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1 bg-[#05070B] p-1 rounded-lg border border-[#1E293B]",children:[e.jsxs("button",{type:"button",onClick:()=>s("client"),className:`flex items-center gap-1.5 px-3 py-1 rounded text-xs font-semibold transition-all cursor-pointer ${n==="client"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-slate-200"}`,children:[e.jsx(Ee,{className:"size-3.5"}),e.jsx("span",{children:"Client Inbound"})]}),e.jsxs("button",{type:"button",onClick:()=>s("providerReq"),className:`flex items-center gap-1.5 px-3 py-1 rounded text-xs font-semibold transition-all cursor-pointer ${n==="providerReq"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-slate-200"}`,children:[e.jsx(Te,{className:"size-3.5"}),e.jsx("span",{children:"Provider Transformed"})]}),e.jsxs("button",{type:"button",onClick:()=>s("response"),className:`flex items-center gap-1.5 px-3 py-1 rounded text-xs font-semibold transition-all cursor-pointer ${n==="response"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-slate-200"}`,children:[e.jsx(ke,{className:"size-3.5"}),e.jsx("span",{children:"Response & Output"})]})]}),e.jsx("button",{type:"button",onClick:()=>u(a,n),className:"px-2.5 py-1 rounded-md bg-[#0A0E18] border border-[#1E293B] text-slate-300 hover:text-white flex items-center gap-1.5 transition-colors text-xs cursor-pointer",children:w===n?e.jsxs(e.Fragment,{children:[e.jsx(X,{className:"size-3.5 text-emerald-400"}),e.jsx("span",{children:"Copied JSON"})]}):e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"size-3.5"}),e.jsx("span",{children:"Copy JSON"})]})})]}),n==="providerReq"&&((L=t.providerRequest)==null?void 0:L.url)&&e.jsxs("div",{className:"px-3 py-1.5 rounded-lg bg-[#05070B] border border-[#1E293B] text-[11px] font-mono text-slate-400 flex items-center gap-2",children:[e.jsx("span",{className:"text-slate-500 uppercase font-bold text-[10px]",children:"URL:"}),e.jsx("span",{className:"text-blue-300 truncate",children:t.providerRequest.url})]}),g&&Object.keys(g).length>0&&e.jsxs("details",{className:"rounded-lg bg-[#05070B] border border-[#1E293B] text-[11px] font-mono text-slate-400 overflow-hidden",children:[e.jsx("summary",{className:"px-3 py-1.5 cursor-pointer hover:text-slate-200 select-none flex items-center justify-between",children:e.jsxs("span",{className:"font-semibold text-slate-300",children:["Headers (",Object.keys(g).length,")"]})}),e.jsx("div",{className:"p-3 border-t border-[#1E293B] bg-black/40 max-h-36 overflow-y-auto",children:e.jsx("pre",{className:"text-[10px] text-slate-300 whitespace-pre-wrap",children:JSON.stringify(g,null,2)})})]}),e.jsx("div",{className:"rounded-xl bg-[#05070B] border border-[#1E293B] p-3 max-h-96 overflow-y-auto font-mono text-[11px] text-slate-200 leading-relaxed",children:a&&a!=="{}"?e.jsx("pre",{className:"whitespace-pre-wrap break-all select-text",children:a}):e.jsx("span",{className:"text-slate-500 italic",children:"No JSON payload body captured for this section."})})]})},Ge=({entry:t,isOpen:o,onClose:n})=>{var R,H,m,$,Y;const s=ue(v=>v.info),w=(s==null?void 0:s.port)||be,f=(s==null?void 0:s.host)||he,[u,b]=c.useState(!1),[p,C]=c.useState(!1),[i,g]=c.useState(!1),[a,E]=c.useState(null),[j,T]=c.useState(!1),{backdropProps:N}=Be(n,!o);if(c.useEffect(()=>{if(!o)return;const v=O=>{O.key==="Escape"&&n()};document.addEventListener("keydown",v);const y=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",v),document.body.style.overflow=y}},[o,n]),c.useEffect(()=>{if(!o||!t){E(null);return}const v=t.requestId||t.id;if(!v){E(null);return}let y=!0;return T(!0),fetch(`/api/usage/request-details/${encodeURIComponent(v)}`).then(O=>O.ok?O.json():null).then(O=>{y&&(E(O),T(!1))}).catch(()=>{y&&T(!1)}),()=>{y=!1}},[o,t]),!o||!t||typeof document>"u")return null;const{gateway:l,error:k,level:z,category:S,rawText:L,reqTag:_,id:B,requestId:U}=t,A=(l==null?void 0:l.statusCode)||(k==null?void 0:k.status)||(a==null?void 0:a.status),J=A===429,q=z==="error"||typeof A=="number"&&A>=400&&!J,D=typeof A=="number"&&A>=200&&A<300,P=S==="proxy"||!!l||!!a||!!t.requestId,F=(v,y)=>{navigator.clipboard.writeText(v),y==="id"?(b(!0),setTimeout(()=>b(!1),2e3)):y==="json"?(C(!0),setTimeout(()=>C(!1),2e3)):y==="curl"&&(g(!0),setTimeout(()=>g(!1),2e3))},G=()=>{var Z;const v=(l==null?void 0:l.route)||"/v1/messages",y=(l==null?void 0:l.actualModel)||(l==null?void 0:l.requestedModel)||(a==null?void 0:a.model)||"claude-3-7-sonnet",O=((Z=a==null?void 0:a.request)==null?void 0:Z.body)||{model:y,messages:[{role:"user",content:"Hello"}]},te=JSON.stringify(O,null,2).replace(/'/g,"'\\''");return`curl -X POST http://${f}:${w}${v} \\
2
2
  -H "Content-Type: application/json" \\
3
3
  -H "Authorization: Bearer [REDACTED]" \\
4
4
  -d '${te}'`};return fe.createPortal(e.jsx("div",{className:"fixed inset-0 z-[9999] flex justify-end bg-black/70 backdrop-blur-xs animate-rt-fade-in",...N,children:e.jsxs("div",{className:"w-full max-w-2xl sm:max-w-3xl h-full bg-[#0D121F] border-l border-[#1E293B] shadow-2xl flex flex-col text-slate-100 overflow-hidden animate-rt-slide-in-right",onClick:v=>v.stopPropagation(),children:[e.jsxs("div",{className:"p-4 sm:p-5 border-b border-[#1E293B] flex items-center justify-between bg-[#0A0E18]",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[l!=null&&l.clientTool?e.jsx(me,{name:l.clientTool,size:"md"}):e.jsx("div",{className:"p-1.5 rounded-lg bg-blue-500/10 border border-blue-500/20 text-blue-400",children:e.jsx(ee,{className:"size-4"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-bold text-sm text-white",children:P?"AI Transaction Inspector":"System Event Diagnostics"}),_&&e.jsx("span",{children:_}),e.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-semibold uppercase bg-blue-500/10 text-blue-400 border border-blue-500/20",children:S})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("span",{className:"text-xs text-slate-400 font-mono",children:B||U||"N/A"}),e.jsx("button",{type:"button",onClick:()=>F(B||U||"","id"),className:"text-slate-500 hover:text-slate-300 transition-colors cursor-pointer",title:"Copy ID",children:u?e.jsx(X,{className:"size-3 text-emerald-400"}):e.jsx(re,{className:"size-3"})})]})]})]})}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("button",{type:"button",onClick:n,className:"p-1.5 rounded-lg text-slate-400 hover:text-white hover:bg-slate-800 transition-colors cursor-pointer",children:e.jsx(de,{className:"size-5"})})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6 space-y-6",children:[P?e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"p-3 rounded-xl bg-[#0A0E18] border border-[#1E293B]",children:[e.jsxs("span",{className:"text-xs text-slate-400 flex items-center gap-1.5",children:[e.jsx(Se,{className:"size-3.5 text-blue-400"})," Status"]}),e.jsx("p",{className:"mt-1 text-sm font-bold",children:J?e.jsx("span",{className:"text-amber-400",children:"429 Rate Limit"}):q?e.jsx("span",{className:"text-red-400",children:A||"Error"}):D?e.jsxs("span",{className:"text-emerald-400",children:[A," OK"]}):e.jsx("span",{className:"text-slate-300",children:z.toUpperCase()})})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-[#0A0E18] border border-[#1E293B]",children:[e.jsxs("span",{className:"text-xs text-slate-400 flex items-center gap-1.5",children:[e.jsx(ie,{className:"size-3.5 text-amber-400"})," Duration"]}),e.jsx("p",{className:"mt-1 text-sm font-bold text-slate-200 font-mono",children:(l==null?void 0:l.durationMs)!==void 0?`${l.durationMs}ms`:((R=a==null?void 0:a.latency)==null?void 0:R.totalMs)!==void 0?`${a.latency.totalMs}ms`:"-"}),(l==null?void 0:l.ttftMs)!==void 0&&l.ttftMs>0&&e.jsxs("span",{className:"text-[10px] text-slate-500 font-mono",children:["TTFT: ",l.ttftMs,"ms"]})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-[#0A0E18] border border-[#1E293B]",children:[e.jsxs("span",{className:"text-xs text-slate-400 flex items-center gap-1.5",children:[e.jsx(pe,{className:"size-3.5 text-purple-400"})," Model"]}),e.jsx("p",{className:"mt-1 text-xs font-bold text-slate-200 font-mono truncate",title:(l==null?void 0:l.actualModel)||(l==null?void 0:l.requestedModel)||(a==null?void 0:a.model),children:(l==null?void 0:l.actualModel)||(l==null?void 0:l.requestedModel)||(a==null?void 0:a.model)||"-"}),((l==null?void 0:l.providerId)||(a==null?void 0:a.provider))&&e.jsxs("span",{className:"text-[10px] text-slate-500 font-mono",children:["via ",(l==null?void 0:l.providerId)||(a==null?void 0:a.provider)]})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-[#0A0E18] border border-[#1E293B]",children:[e.jsxs("span",{className:"text-xs text-slate-400 flex items-center gap-1.5",children:[e.jsx(Ae,{className:"size-3.5 text-emerald-400"})," Cost"]}),e.jsx("p",{className:"mt-1 text-sm font-bold text-emerald-400 font-mono",children:(l==null?void 0:l.cost)!==void 0?`$${l.cost<.01?l.cost.toFixed(4):l.cost.toFixed(3)}`:(a==null?void 0:a.cost)!==void 0?`$${a.cost.toFixed(4)}`:"$0.00"})]})]}):e.jsxs("div",{className:"p-3.5 rounded-xl bg-[#0A0E18] border border-[#1E293B] flex items-center justify-between text-xs font-mono",children:[e.jsxs("span",{className:"text-slate-400",children:["Level: ",e.jsx("strong",{className:"text-white uppercase",children:z})]}),e.jsxs("span",{className:"text-slate-400",children:["Category: ",e.jsx("strong",{className:"text-blue-400 uppercase",children:S})]})]}),(l==null?void 0:l.tokens)&&e.jsx(Ue,{tokens:l.tokens}),(l==null?void 0:l.tools)&&l.tools.length>0&&e.jsx(Je,{tools:l.tools}),(t.error||(a==null?void 0:a.errorMessage))&&e.jsxs("div",{className:"p-4 rounded-xl bg-red-950/20 border border-red-500/30 space-y-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs font-bold text-red-400 flex items-center gap-1.5",children:[e.jsx(Le,{className:"size-4 text-red-400"})," Error Diagnostics"]}),(((H=t.error)==null?void 0:H.code)||((m=t.error)==null?void 0:m.status))&&e.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-mono font-bold bg-red-500/20 text-red-300 border border-red-500/40",children:t.error.code||`HTTP ${t.error.status}`})]}),e.jsx("div",{className:"text-xs font-mono text-red-200 bg-black/40 p-3 rounded-lg border border-red-500/20 whitespace-pre-wrap break-all leading-relaxed",children:(($=t.error)==null?void 0:$.message)||(a==null?void 0:a.errorMessage)||"Unknown error occurred"}),((Y=t.error)==null?void 0:Y.stack)&&e.jsxs("details",{className:"text-[11px] font-mono text-slate-400",children:[e.jsx("summary",{className:"cursor-pointer hover:text-slate-200 select-none",children:"View Stack Trace"}),e.jsx("pre",{className:"mt-2 p-2.5 rounded bg-black/60 text-[10px] text-slate-400 overflow-x-auto whitespace-pre-wrap leading-relaxed border border-slate-800",children:t.error.stack})]})]}),P&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h4",{className:"text-xs font-semibold text-slate-400 uppercase tracking-wider flex items-center gap-1.5",children:[e.jsx(ee,{className:"size-3.5 text-blue-400"})," Observability Payload Trace"]}),e.jsx(qe,{detail:a,loading:j})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h4",{className:"text-xs font-semibold text-slate-400 uppercase tracking-wider flex items-center gap-1.5",children:[e.jsx(se,{className:"size-3.5 text-slate-400"})," Log Output"]}),e.jsx("div",{className:"p-3 rounded-lg bg-[#05070B] border border-[#1E293B] font-mono text-xs text-slate-300 whitespace-pre-wrap break-all leading-relaxed",children:L})]})]}),e.jsxs("div",{className:"p-4 border-t border-[#1E293B] bg-[#0A0E18] flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[P&&e.jsxs("button",{type:"button",onClick:()=>F(G(),"curl"),className:"px-3 py-1.5 rounded-lg text-xs font-semibold bg-[#131B2E] border border-blue-500/30 text-blue-400 hover:bg-blue-500/20 flex items-center gap-1.5 transition-colors cursor-pointer",children:[i?e.jsx(X,{className:"size-3.5 text-emerald-400"}):e.jsx(se,{className:"size-3.5"}),e.jsx("span",{children:i?"Copied cURL!":"Copy cURL"})]}),e.jsxs("button",{type:"button",onClick:()=>F(JSON.stringify(a||t,null,2),"json"),className:"px-3 py-1.5 rounded-lg text-xs font-semibold bg-[#1E293B] text-slate-300 hover:text-white flex items-center gap-1.5 transition-colors cursor-pointer",children:[p?e.jsx(X,{className:"size-3.5 text-emerald-400"}):e.jsx(ze,{className:"size-3.5"}),e.jsx("span",{children:p?"Copied JSON!":"Copy JSON"})]})]}),e.jsx("button",{type:"button",onClick:n,className:"px-4 py-1.5 rounded-lg text-xs font-semibold bg-slate-800 text-slate-300 hover:text-white transition-colors cursor-pointer",children:"Close"})]})]})}),document.body)},Ze=()=>{const[t,o]=c.useState([]),[n,s]=c.useState([]),[w,f]=c.useState(!1),[u,b]=c.useState(!0),[p,C]=c.useState("structured"),[i,g]=c.useState("all"),[a,E]=c.useState(""),[j,T]=c.useState("all"),[N,l]=c.useState("all"),[k,z]=c.useState("all"),[S,L]=c.useState("all"),[_,B]=c.useState("info"),[U,A]=c.useState("errors_only"),[J,q]=c.useState(!1),[D,P]=c.useState(null),[F,G]=c.useState(!1),R=c.useRef(null);c.useEffect(()=>{let r=null,x=!0;return(()=>{try{const d=Oe.getToken(),M=d?`/api/console-logs/stream?token=${encodeURIComponent(d)}`:"/api/console-logs/stream";r=new EventSource(M),r.onopen=()=>{x&&f(!0)},r.onmessage=Q=>{if(x)try{const h=JSON.parse(Q.data);h.type==="init"?(Array.isArray(h.logs||h.lines)&&o(h.logs||h.lines),Array.isArray(h.structured)&&s(h.structured)):h.type==="lines"?(Array.isArray(h.lines)&&o(W=>[...W,...h.lines].slice(-500)),Array.isArray(h.structured)&&s(W=>[...W,...h.structured].slice(-500))):h.type==="clear"&&(o([]),s([]))}catch{}},r.onerror=()=>{x&&f(!1)}}catch{x&&f(!1)}})(),fetch("/api/console-logs").then(d=>d.json()).then(d=>{x&&d.success&&(Array.isArray(d.logs)&&d.logs.length>0&&o(M=>M.length===0?d.logs:M),Array.isArray(d.structuredLogs)&&d.structuredLogs.length>0&&s(M=>M.length===0?d.structuredLogs:M),d.level&&B(d.level))}).catch(()=>{}),fetch("/api/console-logs/level").then(d=>d.json()).then(d=>{x&&d.success&&d.level&&B(d.level)}).catch(()=>{}),fetch("/api/console-logs/observability").then(d=>d.json()).then(d=>{x&&d.success&&d.mode&&A(d.mode)}).catch(()=>{}),()=>{x=!1,r==null||r.close()}},[]),c.useEffect(()=>{u&&R.current&&(R.current.scrollTop=R.current.scrollHeight)},[t,n,u,p]);const H=c.useMemo(()=>{var x;const r=new Set;for(const I of n)(x=I.gateway)!=null&&x.clientTool&&r.add(I.gateway.clientTool);return Array.from(r).sort()},[n]),m=c.useMemo(()=>{var x;const r=new Set;for(const I of n)(x=I.gateway)!=null&&x.providerId&&r.add(I.gateway.providerId);return Array.from(r).sort()},[n]),$=c.useMemo(()=>n.filter(r=>{var x,I,d,M,Q,h,W,ae,oe,ne,ce;if(i==="proxy"&&r.category!=="proxy"||i==="stream"&&!(r.rawText.includes("Tool invoked:")||r.rawText.includes("streaming chunks")||(x=r.gateway)!=null&&x.tools&&r.gateway.tools.length>0)||i==="errors"&&!(r.level==="error"||r.level==="warn"||(I=r.gateway)!=null&&I.statusCode&&r.gateway.statusCode>=400)||i==="system"&&r.category==="proxy"||j!=="all"&&((d=r.gateway)==null?void 0:d.clientTool)!==j||N!=="all"&&((M=r.gateway)==null?void 0:M.providerId)!==N||k==="200"&&((Q=r.gateway)==null?void 0:Q.statusCode)!==200||k==="429"&&((h=r.gateway)==null?void 0:h.statusCode)!==429||k==="error"&&!(r.level==="error"||(W=r.gateway)!=null&&W.statusCode&&r.gateway.statusCode>=400&&r.gateway.statusCode!==429)||S!=="all"&&r.level!==S||S==="all"&&(r.level==="trace"||r.level==="debug")&&!((ae=r.gateway)!=null&&ae.statusCode)&&!((oe=r.gateway)!=null&&oe.actualModel)&&!r.error)return!1;if(a.trim()){const K=a.toLowerCase();if(!(r.rawText.toLowerCase().includes(K)||r.message.toLowerCase().includes(K)||r.requestId&&r.requestId.toLowerCase().includes(K)||((ne=r.gateway)==null?void 0:ne.actualModel)&&r.gateway.actualModel.toLowerCase().includes(K)||((ce=r.gateway)==null?void 0:ce.requestedModel)&&r.gateway.requestedModel.toLowerCase().includes(K)))return!1}return!0}),[n,i,j,N,k,S,a]),Y=async r=>{B(r);try{await fetch("/api/console-logs/level",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({level:r})})}catch{}},v=async r=>{A(r);try{await fetch("/api/console-logs/observability",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:r})})}catch{}},y=c.useMemo(()=>{if(n.length>0)return $.map(x=>x.rawText);if(!a.trim())return t;const r=a.toLowerCase();return t.filter(x=>x.toLowerCase().includes(r))},[n.length,$,t,a]),O=async()=>{try{o([]),s([]),await fetch("/api/console-logs",{method:"DELETE"})}catch{}},te=async()=>{const r=p==="raw"?y.join(`
@@ -1 +1 @@
1
- import{R as ue,r as o,j as e}from"./vendor-BcOI2aZ9.js";import{P as xe}from"./index-CWkEEbms.js";import{T as pe}from"./ToolIcon-Cp4gSgFt.js";import{S as me}from"./Select-BNRH8LIG.js";import{g as be}from"./metadataRegistry-FuJXbCt4.js";const ae={sm:{box:"size-4 rounded-[4px]",icon:"size-2.5",label:"text-xs",description:"text-[11px]",gap:"gap-2"},md:{box:"size-5 rounded-[5px]",icon:"size-3.5",label:"text-sm",description:"text-xs",gap:"gap-2.5"},lg:{box:"size-6 rounded-[6px]",icon:"size-4",label:"text-base",description:"text-sm",gap:"gap-3"}},re={primary:{active:"bg-blue-600 border-blue-500 text-white shadow-sm shadow-blue-500/25",focusRing:"peer-focus-visible:ring-blue-500/50",hoverBorder:"group-hover:border-blue-500/50 hover:border-blue-500/50"},emerald:{active:"bg-emerald-600 border-emerald-500 text-white shadow-sm shadow-emerald-500/25",focusRing:"peer-focus-visible:ring-emerald-500/50",hoverBorder:"group-hover:border-emerald-500/50 hover:border-emerald-500/50"},cyan:{active:"bg-cyan-600 border-cyan-500 text-white shadow-sm shadow-cyan-500/25",focusRing:"peer-focus-visible:ring-cyan-500/50",hoverBorder:"group-hover:border-cyan-500/50 hover:border-cyan-500/50"}},he=ue.forwardRef(({checked:B,defaultChecked:a,indeterminate:n=!1,onChange:g,size:v="md",variant:C="primary",label:u,description:x,disabled:i=!1,className:S="",checkboxClassName:b="",wrapperClassName:E="",onClick:I,...D},p)=>{const h=o.useRef(null),y=B!==void 0,[f,j]=o.useState(!!a),m=y?!!B:f;o.useEffect(()=>{h.current&&(h.current.indeterminate=!!n)},[n]);const z=c=>{h.current=c,typeof p=="function"?p(c):p&&(p.current=c)},$=c=>{i||(y||j(c.target.checked),g==null||g(c.target.checked,c))},d=ae[v]||ae.md,N=re[C]||re.primary,R=m||n,k=!!x;return e.jsxs("label",{className:`group inline-flex select-none transition-opacity ${k?"items-start":"items-center"} ${i?"cursor-not-allowed opacity-50":"cursor-pointer"} ${d.gap} ${E||S}`,onClick:I,children:[e.jsxs("div",{className:`relative inline-flex items-center justify-center shrink-0 ${k?"mt-0.5":""}`,children:[e.jsx("input",{ref:z,type:"checkbox",checked:m,disabled:i,onChange:$,"aria-checked":n?"mixed":m,className:"sr-only peer",...D}),e.jsxs("div",{className:`flex items-center justify-center border transition-all duration-150 ease-out peer-focus-visible:ring-2 peer-focus-visible:ring-offset-2 peer-focus-visible:ring-offset-[#0A0D14] ${d.box} ${R?N.active:`bg-[#0B0F17] border-[#1E293B] text-transparent ${i?"":"group-hover:border-slate-500 hover:border-slate-500"}`} ${N.focusRing} ${i?"":"active:scale-95"} ${b}`,children:[e.jsx("svg",{className:`transition-all duration-150 ease-out ${d.icon} ${m&&!n?"scale-100 opacity-100":"scale-50 opacity-0"}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),e.jsx("svg",{className:`transition-all duration-150 ease-out absolute ${d.icon} ${n?"scale-100 opacity-100":"scale-50 opacity-0"}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3.5,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})]})]}),(u||x)&&e.jsxs("div",{className:"flex flex-col leading-tight min-w-0 justify-center",children:[u&&e.jsx("span",{className:`font-medium text-slate-200 transition-colors ${i?"":"group-hover:text-white"} ${d.label}`,children:u}),x&&e.jsx("span",{className:`text-slate-400 mt-0.5 ${d.description}`,children:x})]})]})});he.displayName="Checkbox";const Ne=({isOpen:B,account:a,onClose:n,onSave:g})=>{const[v,C]=o.useState(""),[u,x]=o.useState(""),[i,S]=o.useState(""),[b,E]=o.useState(!1),[I,D]=o.useState(!0),[p,h]=o.useState(!1),[y,f]=o.useState(null),[j,m]=o.useState(""),[z,$]=o.useState(""),[d,N]=o.useState(""),[R,k]=o.useState("2024-10-01-preview"),[c,F]=o.useState(""),[_,q]=o.useState(""),[H,M]=o.useState("sgp"),[O,K]=o.useState("profile"),[V,G]=o.useState(""),[L,X]=o.useState("us-east-1"),[Y,Z]=o.useState(""),[J,Q]=o.useState(""),[T,P]=o.useState(""),r=((a==null?void 0:a.providerId)||"").toLowerCase(),s=be((a==null?void 0:a.providerId)||""),ne=r==="opencode"||r==="oc"||!!(s!=null&&s.noAuth)||(s==null?void 0:s.requiresApiKey)===!1||(s==null?void 0:s.authType)==="none",w=r==="ollama-local"||r.includes("ollama"),U=!!(s!=null&&s.isLocal)||r==="lm-studio"||r==="jan"||r==="local-device",ee=ne||w||U||(s==null?void 0:s.requiresApiKey)===!1,te=r==="azure"||r.includes("azure"),se=r==="cloudflare-ai"||r==="cloudflare",le=r==="bedrock"||r.includes("bedrock"),W=r==="xiaomi-tokenplan",oe=r==="alicode"||r==="alibaba",A=W?[{id:"sgp",label:"Singapore (新加坡)"},{id:"cn",label:"China (中国大陆)"},{id:"ams",label:"Amsterdam (阿姆斯特丹)"}]:(s==null?void 0:s.regions)||[];if(o.useEffect(()=>{var t;if(a){C(a.name||""),x(a.tag||((t=a.providerSpecificData)==null?void 0:t.tag)||""),S(""),E(!1),D(!!a.isActive),f(null);const l=a.providerSpecificData||{};m(l.baseUrl||(w?"http://127.0.0.1:11434":r==="lm-studio"?"http://localhost:1234/v1":r==="jan"?"http://localhost:1337/v1":"http://localhost:8000/v1")),$(l.azureEndpoint||""),N(l.deployment||"gpt-4"),k(l.apiVersion||"2024-10-01-preview"),F(l.organization||""),q(l.accountId||""),M(l.region||(A.length>0?A[0].id:"sgp")),P(l.baseUrl||"");const de=!!l.accessKeyId;K(de?"static":"profile"),G(l.profile||""),X(l.region||"us-east-1"),Z(l.accessKeyId||""),Q(l.sessionToken||"")}},[a]),!a)return null;const ie=()=>{const t=a.providerSpecificData||{};let l={};return w?l.baseUrl=j.trim()||"http://127.0.0.1:11434":U?l.baseUrl=j.trim():te?l={azureEndpoint:z.trim(),deployment:d.trim(),apiVersion:R.trim(),organization:c.trim()||void 0}:se?l={accountId:_.trim()}:le?O==="profile"?l={profile:V.trim(),region:L.trim()||"us-east-1"}:l={accessKeyId:Y.trim(),region:L.trim()||"us-east-1",sessionToken:J.trim()||void 0}:(W||A.length>0)&&(l.region=H,oe&&(T.trim()?l.baseUrl=T.trim():t.baseUrl&&delete t.baseUrl)),Object.keys(l).length>0?{...t,...l}:Object.keys(t).length>0?t:void 0},ce=async t=>{if(t.preventDefault(),!v.trim()){f("Account name is required.");return}h(!0),f(null);try{const l=ie()||{};u.trim()?l.tag=u.trim().toLowerCase():delete l.tag,await g({name:v.trim(),apiKey:i.trim()?i.trim():void 0,isActive:I,providerSpecificData:Object.keys(l).length>0?l:void 0}),n()}catch(l){f(l.message||"Failed to save account changes.")}finally{h(!1)}};return e.jsx(xe,{isOpen:B,onClose:n,maxWidthClass:"max-w-lg",children:e.jsxs("form",{onSubmit:ce,className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(pe,{src:(s==null?void 0:s.image)||`/assets/providers/${a.providerId}/icon.png`,name:(s==null?void 0:s.name)||a.providerId,color:(s==null?void 0:s.color)||"#3B82F6",iconBg:s==null?void 0:s.iconBg,size:"sm"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-100 flex items-center gap-1.5",children:"Edit Account"}),e.jsxs("div",{className:"text-[11px] text-slate-400 font-mono",children:[(s==null?void 0:s.name)||a.providerId.toUpperCase()," • ",a.id]})]})]}),e.jsx("button",{type:"button",onClick:n,className:"text-slate-400 hover:text-white transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),y&&e.jsxs("div",{className:"p-3 bg-red-500/10 border border-red-500/20 text-red-400 text-xs rounded-xl flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"error"}),e.jsx("span",{children:y})]}),e.jsxs("div",{className:"space-y-3.5 text-xs",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-slate-300 font-medium mb-1",children:["Account Name / Label ",e.jsx("span",{className:"text-red-400",children:"*"})]}),e.jsx("input",{type:"text",value:v,onChange:t=>C(t.target.value),placeholder:"e.g. Work Account or user@example.com",className:"w-full bg-[#0A0D14] border border-[#1E293B] text-slate-100 px-3 py-2 rounded-xl focus:outline-none focus:border-blue-500 transition-colors"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("label",{className:"text-slate-300 font-medium flex items-center gap-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px] text-blue-400",children:"label"}),"Group Tag"]}),e.jsx("span",{className:"text-slate-500 text-[11px]",children:"Optional • For grouping in Combos"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"text",value:u,onChange:t=>x(t.target.value.toLowerCase().replace(/[^a-z0-9_-]/g,"")),placeholder:"e.g. pro, plus, free, team",className:"w-full bg-[#0A0D14] border border-[#1E293B] text-slate-100 pl-3 pr-20 py-2 rounded-xl focus:outline-none focus:border-blue-500 transition-colors font-mono"}),e.jsx("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-1 pointer-events-none",children:["pro","plus","free"].map(t=>e.jsx("button",{type:"button",tabIndex:-1,onClick:l=>{l.preventDefault(),x(t)},className:`pointer-events-auto text-[10px] px-1.5 py-0.5 rounded font-mono transition-colors ${u===t?"bg-blue-600 text-white font-semibold":"bg-[#1E293B] text-slate-400 hover:text-slate-200"}`,children:t},t))})]})]})]}),ee&&e.jsxs("div",{className:"p-2.5 bg-emerald-500/10 border border-emerald-500/20 rounded-xl text-emerald-300 text-[11px] flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-emerald-400 text-[16px]",children:"verified"}),e.jsxs("span",{children:[(s==null?void 0:s.name)||a.providerId," does not require an API key by default. You can leave the key blank."]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{className:"block text-slate-300 font-medium",children:ee?"API Key / Auth Token (Optional)":"Update API Key / Secret Token"}),e.jsx("span",{className:"text-slate-500 text-[11px]",children:"Leave blank to keep existing key"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:b?"text":"password",value:i,onChange:t=>S(t.target.value),placeholder:"Enter new API key or token to overwrite...",className:"w-full bg-[#0A0D14] border border-[#1E293B] text-slate-100 pl-3 pr-9 py-2 rounded-xl focus:outline-none focus:border-blue-500 transition-colors font-mono"}),e.jsx("button",{type:"button",onClick:()=>E(!b),tabIndex:-1,className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-500 hover:text-slate-300 transition-colors cursor-pointer",title:b?"Hide token":"Show token",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:b?"visibility_off":"visibility"})})]})]}),(w||U)&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Local Host / Base URL"}),e.jsx("input",{type:"text",value:j,onChange:t=>m(t.target.value),placeholder:w?"http://127.0.0.1:11434":"http://localhost:1234/v1",className:"w-full bg-[#0A0D14] border border-[#1E293B] text-slate-100 px-3 py-2 rounded-xl focus:outline-none focus:border-blue-500 transition-colors font-mono"})]}),te&&e.jsxs("div",{className:"space-y-2.5 p-3 bg-[#0A0D14] border border-[#1E293B] rounded-xl",children:[e.jsxs("div",{className:"text-[11px] font-semibold text-slate-300 flex items-center gap-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[14px]",children:"cloud"}),"Azure OpenAI Deployment Parameters"]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"Endpoint URL"}),e.jsx("input",{type:"text",value:z,onChange:t=>$(t.target.value),placeholder:"https://my-resource.openai.azure.com",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"Deployment Name"}),e.jsx("input",{type:"text",value:d,onChange:t=>N(t.target.value),placeholder:"gpt-4",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"API Version"}),e.jsx("input",{type:"text",value:R,onChange:t=>k(t.target.value),placeholder:"2024-10-01-preview",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"Organization (Optional)"}),e.jsx("input",{type:"text",value:c,onChange:t=>F(t.target.value),placeholder:"org-...",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]})]}),se&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Cloudflare Account ID"}),e.jsx("input",{type:"text",value:_,onChange:t=>q(t.target.value),placeholder:"Cloudflare account ID (32 chars)",className:"w-full bg-[#0A0D14] border border-[#1E293B] text-slate-100 px-3 py-2 rounded-xl focus:outline-none focus:border-blue-500 transition-colors font-mono"})]}),le&&e.jsxs("div",{className:"space-y-2.5 p-3 bg-[#0A0D14] border border-[#1E293B] rounded-xl",children:[e.jsxs("div",{className:"flex bg-[#141B2D] p-1 rounded-lg border border-[#1E293B] text-xs",children:[e.jsx("button",{type:"button",onClick:()=>K("profile"),className:`flex-1 py-1 rounded-md font-medium transition-colors cursor-pointer ${O==="profile"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"AWS Profile"}),e.jsx("button",{type:"button",onClick:()=>K("static"),className:`flex-1 py-1 rounded-md font-medium transition-colors cursor-pointer ${O==="static"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Static IAM Keys"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"AWS Region"}),e.jsx("input",{type:"text",value:L,onChange:t=>X(t.target.value),placeholder:"us-east-1",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]}),O==="profile"?e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"AWS Profile Name"}),e.jsx("input",{type:"text",value:V,onChange:t=>G(t.target.value),placeholder:"default",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"Access Key ID"}),e.jsx("input",{type:"text",value:Y,onChange:t=>Z(t.target.value),placeholder:"AKIA...",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"Session Token (Optional)"}),e.jsx("input",{type:"password",value:J,onChange:t=>Q(t.target.value),placeholder:"Optional STS token...",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]})]})]}),(W||A.length>0)&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Cluster Region"}),e.jsx(me,{value:H,onChange:t=>M(t),options:A.map(t=>({value:t.id,label:t.label.includes(t.id)?t.label:`${t.label} (${t.id})`})),className:"w-full",triggerClassName:"bg-[#0A0D14] font-mono text-xs py-2"})]}),oe&&e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"block text-slate-400 text-xs",children:["Dedicated Workspace Endpoint URL ",e.jsx("span",{className:"text-slate-500",children:"(Optional)"})]}),e.jsx("input",{type:"text",value:T,onChange:t=>P(t.target.value),placeholder:"e.g. https://ws-xxx.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",className:"w-full bg-[#0A0D14] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono text-xs"}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"Required if your API key was created inside an Alibaba Model Studio custom workspace."})]})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 bg-[#141B2D] border border-[#1E293B] rounded-xl",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-slate-200",children:"Active Status"}),e.jsx("div",{className:"text-[11px] text-slate-400",children:"Inactive accounts are excluded from routing and quota polling."})]}),e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:I,onChange:t=>D(t.target.checked),className:"sr-only peer"}),e.jsx("div",{className:"w-9 h-5 bg-slate-700 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-blue-600"})]})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-3 pt-4 border-t border-[#1E293B]",children:[e.jsx("button",{type:"button",onClick:n,disabled:p,className:"px-4 py-2 text-xs font-medium text-slate-400 hover:text-white bg-[#141B2D] border border-[#1E293B] rounded-xl transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:p,className:"px-4 py-2 text-xs font-medium text-white bg-blue-600 hover:bg-blue-500 rounded-xl transition-colors cursor-pointer flex items-center gap-1.5 disabled:opacity-50",children:p?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[15px] animate-spin",children:"progress_activity"}),"Saving..."]}):"Save Changes"})]})]})})};export{he as C,Ne as E};
1
+ import{R as ue,r as o,j as e}from"./vendor-BcOI2aZ9.js";import{P as xe}from"./index-D3Xjro_O.js";import{T as pe}from"./ToolIcon-Cp4gSgFt.js";import{S as me}from"./Select-BNRH8LIG.js";import{g as be}from"./metadataRegistry-FuJXbCt4.js";const ae={sm:{box:"size-4 rounded-[4px]",icon:"size-2.5",label:"text-xs",description:"text-[11px]",gap:"gap-2"},md:{box:"size-5 rounded-[5px]",icon:"size-3.5",label:"text-sm",description:"text-xs",gap:"gap-2.5"},lg:{box:"size-6 rounded-[6px]",icon:"size-4",label:"text-base",description:"text-sm",gap:"gap-3"}},re={primary:{active:"bg-blue-600 border-blue-500 text-white shadow-sm shadow-blue-500/25",focusRing:"peer-focus-visible:ring-blue-500/50",hoverBorder:"group-hover:border-blue-500/50 hover:border-blue-500/50"},emerald:{active:"bg-emerald-600 border-emerald-500 text-white shadow-sm shadow-emerald-500/25",focusRing:"peer-focus-visible:ring-emerald-500/50",hoverBorder:"group-hover:border-emerald-500/50 hover:border-emerald-500/50"},cyan:{active:"bg-cyan-600 border-cyan-500 text-white shadow-sm shadow-cyan-500/25",focusRing:"peer-focus-visible:ring-cyan-500/50",hoverBorder:"group-hover:border-cyan-500/50 hover:border-cyan-500/50"}},he=ue.forwardRef(({checked:B,defaultChecked:a,indeterminate:n=!1,onChange:g,size:v="md",variant:C="primary",label:u,description:x,disabled:i=!1,className:S="",checkboxClassName:b="",wrapperClassName:E="",onClick:I,...D},p)=>{const h=o.useRef(null),y=B!==void 0,[f,j]=o.useState(!!a),m=y?!!B:f;o.useEffect(()=>{h.current&&(h.current.indeterminate=!!n)},[n]);const z=c=>{h.current=c,typeof p=="function"?p(c):p&&(p.current=c)},$=c=>{i||(y||j(c.target.checked),g==null||g(c.target.checked,c))},d=ae[v]||ae.md,N=re[C]||re.primary,R=m||n,k=!!x;return e.jsxs("label",{className:`group inline-flex select-none transition-opacity ${k?"items-start":"items-center"} ${i?"cursor-not-allowed opacity-50":"cursor-pointer"} ${d.gap} ${E||S}`,onClick:I,children:[e.jsxs("div",{className:`relative inline-flex items-center justify-center shrink-0 ${k?"mt-0.5":""}`,children:[e.jsx("input",{ref:z,type:"checkbox",checked:m,disabled:i,onChange:$,"aria-checked":n?"mixed":m,className:"sr-only peer",...D}),e.jsxs("div",{className:`flex items-center justify-center border transition-all duration-150 ease-out peer-focus-visible:ring-2 peer-focus-visible:ring-offset-2 peer-focus-visible:ring-offset-[#0A0D14] ${d.box} ${R?N.active:`bg-[#0B0F17] border-[#1E293B] text-transparent ${i?"":"group-hover:border-slate-500 hover:border-slate-500"}`} ${N.focusRing} ${i?"":"active:scale-95"} ${b}`,children:[e.jsx("svg",{className:`transition-all duration-150 ease-out ${d.icon} ${m&&!n?"scale-100 opacity-100":"scale-50 opacity-0"}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),e.jsx("svg",{className:`transition-all duration-150 ease-out absolute ${d.icon} ${n?"scale-100 opacity-100":"scale-50 opacity-0"}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3.5,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})]})]}),(u||x)&&e.jsxs("div",{className:"flex flex-col leading-tight min-w-0 justify-center",children:[u&&e.jsx("span",{className:`font-medium text-slate-200 transition-colors ${i?"":"group-hover:text-white"} ${d.label}`,children:u}),x&&e.jsx("span",{className:`text-slate-400 mt-0.5 ${d.description}`,children:x})]})]})});he.displayName="Checkbox";const Ne=({isOpen:B,account:a,onClose:n,onSave:g})=>{const[v,C]=o.useState(""),[u,x]=o.useState(""),[i,S]=o.useState(""),[b,E]=o.useState(!1),[I,D]=o.useState(!0),[p,h]=o.useState(!1),[y,f]=o.useState(null),[j,m]=o.useState(""),[z,$]=o.useState(""),[d,N]=o.useState(""),[R,k]=o.useState("2024-10-01-preview"),[c,F]=o.useState(""),[_,q]=o.useState(""),[H,M]=o.useState("sgp"),[O,K]=o.useState("profile"),[V,G]=o.useState(""),[L,X]=o.useState("us-east-1"),[Y,Z]=o.useState(""),[J,Q]=o.useState(""),[T,P]=o.useState(""),r=((a==null?void 0:a.providerId)||"").toLowerCase(),s=be((a==null?void 0:a.providerId)||""),ne=r==="opencode"||r==="oc"||!!(s!=null&&s.noAuth)||(s==null?void 0:s.requiresApiKey)===!1||(s==null?void 0:s.authType)==="none",w=r==="ollama-local"||r.includes("ollama"),U=!!(s!=null&&s.isLocal)||r==="lm-studio"||r==="jan"||r==="local-device",ee=ne||w||U||(s==null?void 0:s.requiresApiKey)===!1,te=r==="azure"||r.includes("azure"),se=r==="cloudflare-ai"||r==="cloudflare",le=r==="bedrock"||r.includes("bedrock"),W=r==="xiaomi-tokenplan",oe=r==="alicode"||r==="alibaba",A=W?[{id:"sgp",label:"Singapore (新加坡)"},{id:"cn",label:"China (中国大陆)"},{id:"ams",label:"Amsterdam (阿姆斯特丹)"}]:(s==null?void 0:s.regions)||[];if(o.useEffect(()=>{var t;if(a){C(a.name||""),x(a.tag||((t=a.providerSpecificData)==null?void 0:t.tag)||""),S(""),E(!1),D(!!a.isActive),f(null);const l=a.providerSpecificData||{};m(l.baseUrl||(w?"http://127.0.0.1:11434":r==="lm-studio"?"http://localhost:1234/v1":r==="jan"?"http://localhost:1337/v1":"http://localhost:8000/v1")),$(l.azureEndpoint||""),N(l.deployment||"gpt-4"),k(l.apiVersion||"2024-10-01-preview"),F(l.organization||""),q(l.accountId||""),M(l.region||(A.length>0?A[0].id:"sgp")),P(l.baseUrl||"");const de=!!l.accessKeyId;K(de?"static":"profile"),G(l.profile||""),X(l.region||"us-east-1"),Z(l.accessKeyId||""),Q(l.sessionToken||"")}},[a]),!a)return null;const ie=()=>{const t=a.providerSpecificData||{};let l={};return w?l.baseUrl=j.trim()||"http://127.0.0.1:11434":U?l.baseUrl=j.trim():te?l={azureEndpoint:z.trim(),deployment:d.trim(),apiVersion:R.trim(),organization:c.trim()||void 0}:se?l={accountId:_.trim()}:le?O==="profile"?l={profile:V.trim(),region:L.trim()||"us-east-1"}:l={accessKeyId:Y.trim(),region:L.trim()||"us-east-1",sessionToken:J.trim()||void 0}:(W||A.length>0)&&(l.region=H,oe&&(T.trim()?l.baseUrl=T.trim():t.baseUrl&&delete t.baseUrl)),Object.keys(l).length>0?{...t,...l}:Object.keys(t).length>0?t:void 0},ce=async t=>{if(t.preventDefault(),!v.trim()){f("Account name is required.");return}h(!0),f(null);try{const l=ie()||{};u.trim()?l.tag=u.trim().toLowerCase():delete l.tag,await g({name:v.trim(),apiKey:i.trim()?i.trim():void 0,isActive:I,providerSpecificData:Object.keys(l).length>0?l:void 0}),n()}catch(l){f(l.message||"Failed to save account changes.")}finally{h(!1)}};return e.jsx(xe,{isOpen:B,onClose:n,maxWidthClass:"max-w-lg",children:e.jsxs("form",{onSubmit:ce,className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(pe,{src:(s==null?void 0:s.image)||`/assets/providers/${a.providerId}/icon.png`,name:(s==null?void 0:s.name)||a.providerId,color:(s==null?void 0:s.color)||"#3B82F6",iconBg:s==null?void 0:s.iconBg,size:"sm"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-100 flex items-center gap-1.5",children:"Edit Account"}),e.jsxs("div",{className:"text-[11px] text-slate-400 font-mono",children:[(s==null?void 0:s.name)||a.providerId.toUpperCase()," • ",a.id]})]})]}),e.jsx("button",{type:"button",onClick:n,className:"text-slate-400 hover:text-white transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),y&&e.jsxs("div",{className:"p-3 bg-red-500/10 border border-red-500/20 text-red-400 text-xs rounded-xl flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"error"}),e.jsx("span",{children:y})]}),e.jsxs("div",{className:"space-y-3.5 text-xs",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-slate-300 font-medium mb-1",children:["Account Name / Label ",e.jsx("span",{className:"text-red-400",children:"*"})]}),e.jsx("input",{type:"text",value:v,onChange:t=>C(t.target.value),placeholder:"e.g. Work Account or user@example.com",className:"w-full bg-[#0A0D14] border border-[#1E293B] text-slate-100 px-3 py-2 rounded-xl focus:outline-none focus:border-blue-500 transition-colors"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("label",{className:"text-slate-300 font-medium flex items-center gap-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px] text-blue-400",children:"label"}),"Group Tag"]}),e.jsx("span",{className:"text-slate-500 text-[11px]",children:"Optional • For grouping in Combos"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"text",value:u,onChange:t=>x(t.target.value.toLowerCase().replace(/[^a-z0-9_-]/g,"")),placeholder:"e.g. pro, plus, free, team",className:"w-full bg-[#0A0D14] border border-[#1E293B] text-slate-100 pl-3 pr-20 py-2 rounded-xl focus:outline-none focus:border-blue-500 transition-colors font-mono"}),e.jsx("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-1 pointer-events-none",children:["pro","plus","free"].map(t=>e.jsx("button",{type:"button",tabIndex:-1,onClick:l=>{l.preventDefault(),x(t)},className:`pointer-events-auto text-[10px] px-1.5 py-0.5 rounded font-mono transition-colors ${u===t?"bg-blue-600 text-white font-semibold":"bg-[#1E293B] text-slate-400 hover:text-slate-200"}`,children:t},t))})]})]})]}),ee&&e.jsxs("div",{className:"p-2.5 bg-emerald-500/10 border border-emerald-500/20 rounded-xl text-emerald-300 text-[11px] flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-emerald-400 text-[16px]",children:"verified"}),e.jsxs("span",{children:[(s==null?void 0:s.name)||a.providerId," does not require an API key by default. You can leave the key blank."]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{className:"block text-slate-300 font-medium",children:ee?"API Key / Auth Token (Optional)":"Update API Key / Secret Token"}),e.jsx("span",{className:"text-slate-500 text-[11px]",children:"Leave blank to keep existing key"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:b?"text":"password",value:i,onChange:t=>S(t.target.value),placeholder:"Enter new API key or token to overwrite...",className:"w-full bg-[#0A0D14] border border-[#1E293B] text-slate-100 pl-3 pr-9 py-2 rounded-xl focus:outline-none focus:border-blue-500 transition-colors font-mono"}),e.jsx("button",{type:"button",onClick:()=>E(!b),tabIndex:-1,className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-500 hover:text-slate-300 transition-colors cursor-pointer",title:b?"Hide token":"Show token",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:b?"visibility_off":"visibility"})})]})]}),(w||U)&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Local Host / Base URL"}),e.jsx("input",{type:"text",value:j,onChange:t=>m(t.target.value),placeholder:w?"http://127.0.0.1:11434":"http://localhost:1234/v1",className:"w-full bg-[#0A0D14] border border-[#1E293B] text-slate-100 px-3 py-2 rounded-xl focus:outline-none focus:border-blue-500 transition-colors font-mono"})]}),te&&e.jsxs("div",{className:"space-y-2.5 p-3 bg-[#0A0D14] border border-[#1E293B] rounded-xl",children:[e.jsxs("div",{className:"text-[11px] font-semibold text-slate-300 flex items-center gap-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[14px]",children:"cloud"}),"Azure OpenAI Deployment Parameters"]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"Endpoint URL"}),e.jsx("input",{type:"text",value:z,onChange:t=>$(t.target.value),placeholder:"https://my-resource.openai.azure.com",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"Deployment Name"}),e.jsx("input",{type:"text",value:d,onChange:t=>N(t.target.value),placeholder:"gpt-4",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"API Version"}),e.jsx("input",{type:"text",value:R,onChange:t=>k(t.target.value),placeholder:"2024-10-01-preview",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"Organization (Optional)"}),e.jsx("input",{type:"text",value:c,onChange:t=>F(t.target.value),placeholder:"org-...",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]})]}),se&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Cloudflare Account ID"}),e.jsx("input",{type:"text",value:_,onChange:t=>q(t.target.value),placeholder:"Cloudflare account ID (32 chars)",className:"w-full bg-[#0A0D14] border border-[#1E293B] text-slate-100 px-3 py-2 rounded-xl focus:outline-none focus:border-blue-500 transition-colors font-mono"})]}),le&&e.jsxs("div",{className:"space-y-2.5 p-3 bg-[#0A0D14] border border-[#1E293B] rounded-xl",children:[e.jsxs("div",{className:"flex bg-[#141B2D] p-1 rounded-lg border border-[#1E293B] text-xs",children:[e.jsx("button",{type:"button",onClick:()=>K("profile"),className:`flex-1 py-1 rounded-md font-medium transition-colors cursor-pointer ${O==="profile"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"AWS Profile"}),e.jsx("button",{type:"button",onClick:()=>K("static"),className:`flex-1 py-1 rounded-md font-medium transition-colors cursor-pointer ${O==="static"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Static IAM Keys"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"AWS Region"}),e.jsx("input",{type:"text",value:L,onChange:t=>X(t.target.value),placeholder:"us-east-1",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]}),O==="profile"?e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"AWS Profile Name"}),e.jsx("input",{type:"text",value:V,onChange:t=>G(t.target.value),placeholder:"default",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"Access Key ID"}),e.jsx("input",{type:"text",value:Y,onChange:t=>Z(t.target.value),placeholder:"AKIA...",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"Session Token (Optional)"}),e.jsx("input",{type:"password",value:J,onChange:t=>Q(t.target.value),placeholder:"Optional STS token...",className:"w-full bg-[#141B2D] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono"})]})]})]}),(W||A.length>0)&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Cluster Region"}),e.jsx(me,{value:H,onChange:t=>M(t),options:A.map(t=>({value:t.id,label:t.label.includes(t.id)?t.label:`${t.label} (${t.id})`})),className:"w-full",triggerClassName:"bg-[#0A0D14] font-mono text-xs py-2"})]}),oe&&e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"block text-slate-400 text-xs",children:["Dedicated Workspace Endpoint URL ",e.jsx("span",{className:"text-slate-500",children:"(Optional)"})]}),e.jsx("input",{type:"text",value:T,onChange:t=>P(t.target.value),placeholder:"e.g. https://ws-xxx.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",className:"w-full bg-[#0A0D14] border border-[#1E293B] text-slate-100 px-3 py-1.5 rounded-lg focus:outline-none focus:border-blue-500 font-mono text-xs"}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"Required if your API key was created inside an Alibaba Model Studio custom workspace."})]})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 bg-[#141B2D] border border-[#1E293B] rounded-xl",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-slate-200",children:"Active Status"}),e.jsx("div",{className:"text-[11px] text-slate-400",children:"Inactive accounts are excluded from routing and quota polling."})]}),e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:I,onChange:t=>D(t.target.checked),className:"sr-only peer"}),e.jsx("div",{className:"w-9 h-5 bg-slate-700 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-blue-600"})]})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-3 pt-4 border-t border-[#1E293B]",children:[e.jsx("button",{type:"button",onClick:n,disabled:p,className:"px-4 py-2 text-xs font-medium text-slate-400 hover:text-white bg-[#141B2D] border border-[#1E293B] rounded-xl transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:p,className:"px-4 py-2 text-xs font-medium text-white bg-blue-600 hover:bg-blue-500 rounded-xl transition-colors cursor-pointer flex items-center gap-1.5 disabled:opacity-50",children:p?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[15px] animate-spin",children:"progress_activity"}),"Saving..."]}):"Save Changes"})]})]})})};export{he as C,Ne as E};
@@ -1 +1 @@
1
- import{r as l,j as e}from"./vendor-BcOI2aZ9.js";import{S as Ne}from"./Select-BNRH8LIG.js";import{C as we}from"./ConfirmModal-CMfDss7P.js";import{u as ee,D as m,d as te,P as ve}from"./index-CWkEEbms.js";import"./lucide-Cc35htxl.js";const u="10.*, 172.16-31.*, 192.168.*, 169.254.*, *.local",Ce={host:te,port:m,requireApiKey:!1,proxyUrl:"",customHeaders:{},allowedHosts:u},De=({onRestartClick:K})=>{const o=ee(t=>t.info),w=ee(t=>t.fetchSystemInfo),se=!!(o!=null&&o.isRestartRequired),[r,c]=l.useState(Ce),[ae,T]=l.useState(!0),[P,H]=l.useState(!1),[L,f]=l.useState(null),[R,I]=l.useState(null),[y,g]=l.useState([]),[v,j]=l.useState([]),[le,_]=l.useState(!0),[re,ne]=l.useState(new Set),[p,U]=l.useState(null),[oe,F]=l.useState(null),[q,h]=l.useState(!1),[G,O]=l.useState(""),[$,M]=l.useState(!1),[N,b]=l.useState(null),[x,C]=l.useState(null),[J,k]=l.useState(null),[A,V]=l.useState(!1),W=l.useCallback(async()=>{try{T(!0);const[t]=await Promise.all([fetch("/api/settings/endpoint"),w()]);if(t.ok){const s=await t.json();c({host:s.host||te,port:s.port||m,requireApiKey:!!s.requireApiKey,proxyUrl:s.proxyUrl||"",customHeaders:s.customHeaders||{},allowedHosts:s.allowedHosts||u});const a=Object.entries(s.customHeaders||{}).map(([i,n],d)=>({id:`header-${d}-${Date.now()}`,key:i,value:String(n)}));g(a)}}catch(t){console.error("Failed to load endpoint settings:",t)}finally{T(!1)}},[w]),z=l.useCallback(async()=>{try{_(!0);const t=await fetch("/api/settings/endpoint/keys");if(t.ok){const s=await t.json();Array.isArray(s)&&j(s)}}catch(t){console.error("Failed to load gateway API keys:",t)}finally{_(!1)}},[]);l.useEffect(()=>{W(),z()},[W,z]);const ie=async t=>{var a,i;t&&t.preventDefault(),H(!0),f(null),I(null);const s={};for(const n of y){const d=n.key.trim();d&&(s[d]=n.value.trim())}try{const n={host:r.host,port:Number(r.port)||m,requireApiKey:r.requireApiKey,proxyUrl:((a=r.proxyUrl)==null?void 0:a.trim())||"",customHeaders:s,allowedHosts:((i=r.allowedHosts)==null?void 0:i.trim())||u},d=await fetch("/api/settings/endpoint",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!d.ok){const je=await d.json();throw new Error(je.error||"Failed to update endpoint settings")}const ye=await d.json();c(ye);const D=await w(),ge=!!(D!=null&&D.isRestartRequired);f(ge?"Configuration saved! Server restart is required to rebind the network interface.":"Settings saved successfully!"),setTimeout(()=>f(null),5e3)}catch(n){I((n==null?void 0:n.message)||"Failed to save settings")}finally{H(!1)}},ce=async t=>{t.preventDefault();try{M(!0);const s=await fetch("/api/settings/endpoint/keys",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:G.trim()||void 0})});if(s.ok){const a=await s.json();j(i=>[a,...i]),b(a),O("")}else{const a=await s.json();alert(a.error||"Failed to create API key")}}catch(s){console.error("Error creating key:",s)}finally{M(!1)}},de=async t=>{try{const s=await fetch(`/api/settings/endpoint/keys/${t.id}/toggle`,{method:"PATCH"});if(s.ok){const a=await s.json();j(i=>i.map(n=>n.id===t.id?a:n))}}catch(s){console.error("Error toggling API key:",s)}},xe=async()=>{if(x)try{(await fetch(`/api/settings/endpoint/keys/${x.id}`,{method:"DELETE"})).ok&&j(s=>s.filter(a=>a.id!==x.id))}catch(t){console.error("Error deleting API key:",t)}finally{C(null)}},pe=t=>{ne(s=>{const a=new Set(s);return a.has(t)?a.delete(t):a.add(t),a})},S=(t,s)=>{navigator.clipboard.writeText(t),U(s),setTimeout(()=>U(null),2e3)},me=(t,s)=>{navigator.clipboard.writeText(t),F(s),setTimeout(()=>F(null),2e3)},ue=()=>{g([...y,{id:`header-${Date.now()}`,key:"",value:""}])},X=(t,s,a)=>{g(i=>i.map(n=>n.id===t?{...n,[s]:a}:n))},he=t=>{g(s=>s.filter(a=>a.id!==t))},Y=r.host==="0.0.0.0"?"127.0.0.1":r.host||"127.0.0.1",be=(o==null?void 0:o.port)||(typeof window<"u"&&window.location.port&&window.location.port!=="5173"?Number(window.location.port):m),E=r.port||be,Q=`http://${Y}:${E}/v1`,B=`http://${Y}:${E}`,fe=async()=>{V(!0),k(null);try{const s=await(await fetch("/health")).json();k(JSON.stringify(s,null,2))}catch{k(JSON.stringify({error:"Failed to connect to gateway"},null,2))}finally{V(!1)}},Z=t=>{if(t.length<=10)return"••••••••";const s=t.slice(0,6),a=t.slice(-4);return`${s}••••••••${a}`};return e.jsxs("div",{className:"space-y-8 w-full px-2 sm:px-4 pb-16 animate-rt-fade-in",children:[e.jsxs("div",{className:"w-full p-6 rounded-2xl bg-[#0F1420]/80 border border-[#1E293B] space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-blue-400",children:"api"}),"Local Gateway Endpoints"]}),e.jsx("p",{className:"text-xs text-slate-400 mt-1",children:"Universal endpoints accepting OpenAI Chat Completions and Anthropic Messages protocols"})]}),e.jsxs("div",{className:"space-y-3.5 text-xs font-mono",children:[e.jsxs("div",{className:"bg-[#0A0D14] p-4 rounded-xl border border-[#1E293B] flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500 block text-[10px] uppercase font-sans font-semibold",children:"OpenAI-Compatible Base URL (Cursor, Cline, OpenCode, Codex)"}),e.jsx("span",{className:"text-blue-400 font-bold text-sm",children:Q})]}),e.jsxs("button",{type:"button",onClick:()=>S(Q,"openai"),className:"px-3.5 py-1.5 rounded-xl bg-[#141B2D] border border-[#1E293B] hover:border-slate-600 text-xs font-semibold text-slate-300 hover:text-white flex items-center gap-1.5 transition-all cursor-pointer self-start sm:self-center font-sans",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:p==="openai"?"check":"content_copy"}),p==="openai"?"Copied":"Copy"]})]}),e.jsxs("div",{className:"bg-[#0A0D14] p-4 rounded-xl border border-[#1E293B] flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500 block text-[10px] uppercase font-sans font-semibold",children:"Anthropic Base URL (Claude Code CLI: ANTHROPIC_BASE_URL)"}),e.jsx("span",{className:"text-cyan-400 font-bold text-sm",children:B})]}),e.jsxs("button",{type:"button",onClick:()=>S(B,"anthropic"),className:"px-3.5 py-1.5 rounded-xl bg-[#141B2D] border border-[#1E293B] hover:border-slate-600 text-xs font-semibold text-slate-300 hover:text-white flex items-center gap-1.5 transition-all cursor-pointer self-start sm:self-center font-sans",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:p==="anthropic"?"check":"content_copy"}),p==="anthropic"?"Copied":"Copy"]})]})]}),e.jsxs("div",{className:"pt-2 border-t border-[#1E293B] space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-bold text-slate-200 block font-sans",children:"Test Gateway Connectivity:"}),e.jsxs("button",{type:"button",onClick:fe,disabled:A,className:"px-4 py-2 rounded-xl text-xs font-semibold text-white bg-blue-600 hover:bg-blue-500 shadow-md shadow-blue-600/20 disabled:opacity-50 transition-all flex items-center gap-1.5 cursor-pointer font-sans",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${A?"animate-spin":""}`,children:A?"sync":"play_arrow"}),"Execute Test Ping"]})]}),e.jsxs("div",{className:"bg-[#0A0D14] p-3 rounded-xl border border-[#1E293B] text-xs font-mono text-slate-300 overflow-x-auto",children:["curl ",B,"/health"]}),J&&e.jsx("pre",{className:"bg-[#080B10] p-4 rounded-xl border border-blue-500/30 text-emerald-400 text-xs font-mono overflow-x-auto animate-rt-scale-in",children:J})]})]}),e.jsxs("div",{className:"w-full p-6 rounded-2xl bg-[#0F1420]/80 border border-[#1E293B] space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-cyan-400",children:"tune"}),"Gateway & Connection Configuration"]}),e.jsx("p",{className:"text-xs text-slate-400 mt-1",children:"Configure server listening network interface, listening port, security enforcement, and global upstream proxy."})]}),L&&e.jsxs("span",{className:"px-3 py-1 rounded-lg bg-emerald-500/10 border border-emerald-500/30 text-emerald-400 text-xs font-medium flex items-center gap-1.5 animate-rt-fade-in self-start sm:self-center",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"check_circle"}),L]}),R&&e.jsxs("span",{className:"px-3 py-1 rounded-lg bg-rose-500/10 border border-rose-500/30 text-rose-400 text-xs font-medium flex items-center gap-1.5 self-start sm:self-center",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"error"}),R]})]}),se&&e.jsxs("div",{className:"p-4 rounded-xl bg-amber-500/10 border border-amber-500/30 flex flex-col sm:flex-row sm:items-center justify-between gap-3 animate-rt-fade-in",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-amber-400 shrink-0",children:"restart_alt"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-bold text-amber-300",children:"Restart Required to Apply Network Configuration"}),e.jsxs("p",{className:"text-[11px] text-amber-200/70 mt-0.5",children:["Listening host is configured as ",e.jsx("span",{className:"font-mono font-semibold text-white",children:o==null?void 0:o.configuredHost}),", but the gateway socket is still bound to ",e.jsx("span",{className:"font-mono font-semibold text-white",children:o==null?void 0:o.host}),"."]})]})]}),K&&e.jsxs("button",{type:"button",onClick:K,className:"px-3.5 py-1.5 rounded-lg bg-amber-500 hover:bg-amber-400 text-slate-950 font-semibold text-xs transition-colors flex items-center gap-1.5 shrink-0 self-start sm:self-center cursor-pointer shadow-sm",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"restart_alt"}),"Restart Gateway Now"]})]}),ae?e.jsxs("div",{className:"py-12 text-center text-slate-400 flex flex-col items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-2xl text-blue-400 animate-spin",children:"progress_activity"}),e.jsx("span",{className:"text-xs",children:"Loading configuration..."})]}):e.jsxs("form",{onSubmit:ie,className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-200 mb-1.5",children:"Listening Host Interface"}),e.jsx(Ne,{value:r.host,onChange:t=>c({...r,host:t}),options:[{value:"127.0.0.1",label:"127.0.0.1 — Localhost only (Recommended, Private)"},{value:"0.0.0.0",label:"0.0.0.0 — All Interfaces (LAN / Network Access)"},{value:"localhost",label:"localhost — Standard local loopback"}],className:"w-full"}),e.jsx("p",{className:"text-[11px] text-slate-500 mt-1",children:"Bind to 127.0.0.1 to isolate Mapigate to this machine, or 0.0.0.0 to expose on your local network."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-200 mb-1.5",children:"Gateway Port"}),e.jsx("input",{type:"number",min:1024,max:65535,value:r.port,onChange:t=>c({...r,port:parseInt(t.target.value,10)||m}),className:"w-full bg-[#0A0D14] border border-[#1E293B] focus:border-blue-500 rounded-xl px-3.5 py-2 text-xs font-mono text-white placeholder-slate-500 focus:outline-none transition-colors"}),e.jsxs("p",{className:"text-[11px] text-slate-500 mt-1",children:["Active server listening on port ",e.jsx("span",{className:"text-blue-400 font-mono font-semibold",children:E}),". Default port is ",m,". Change requires restarting Mapigate server."]})]})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-[#0A0D14] border border-[#1E293B] space-y-2.5",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("label",{className:"text-xs font-semibold text-slate-200 flex items-center gap-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-cyan-400",children:"lan"}),"Trusted LAN Host Patterns / IP Ranges"]}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"Host header patterns allowed when accessing Mapigate over LAN (comma-separated)."})]}),e.jsxs("button",{type:"button",onClick:()=>c({...r,allowedHosts:u}),className:"px-2.5 py-1 rounded-lg bg-[#141B2D] border border-[#1E293B] hover:border-slate-600 text-[11px] font-medium text-slate-300 hover:text-white flex items-center gap-1 transition-all cursor-pointer self-start sm:self-center shrink-0",title:"Reset to default private network ranges",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px] text-slate-400",children:"restart_alt"}),"Reset to Default"]})]}),e.jsx("input",{type:"text",placeholder:u,value:r.allowedHosts||"",onChange:t=>c({...r,allowedHosts:t.target.value}),className:"w-full bg-[#080B10] border border-[#1E293B] focus:border-blue-500 rounded-xl px-3.5 py-2 text-xs font-mono text-white placeholder-slate-500 focus:outline-none transition-colors"}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-1 text-[10.5px] text-slate-500",children:[e.jsxs("span",{children:["Default: ",e.jsx("code",{className:"text-slate-400 font-mono",children:u})]}),e.jsx("span",{children:"Supports wildcards (e.g. 192.168.*, 10.*, *.local)"})]})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-[#0A0D14] border border-[#1E293B] flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("span",{className:"text-xs font-bold text-white flex items-center gap-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-amber-400",children:"key"}),"Require API Key Authentication"]}),e.jsxs("p",{className:"text-[11px] text-slate-400",children:["When enabled, all incoming proxy requests to ",e.jsx("code",{className:"font-mono text-slate-300",children:"/v1/*"})," must supply an Authorization header matching an active Gateway Key below."]})]}),e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer shrink-0",children:[e.jsx("input",{type:"checkbox",checked:r.requireApiKey,onChange:t=>c({...r,requireApiKey:t.target.checked}),className:"sr-only peer"}),e.jsx("div",{className:"w-10 h-5.5 bg-[#1E293B] peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4.5 after:w-4.5 after:transition-all peer-checked:bg-blue-600"})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-semibold text-slate-200 mb-1.5 flex items-center gap-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-purple-400",children:"router"}),"Global Upstream Proxy URL (Optional)"]}),e.jsx("input",{type:"text",placeholder:"e.g. http://127.0.0.1:7890 or socks5://127.0.0.1:1080",value:r.proxyUrl||"",onChange:t=>c({...r,proxyUrl:t.target.value}),className:"w-full bg-[#0A0D14] border border-[#1E293B] focus:border-blue-500 rounded-xl px-3.5 py-2 text-xs font-mono text-white placeholder-slate-500 focus:outline-none transition-colors"}),e.jsx("p",{className:"text-[11px] text-slate-500 mt-1",children:"Egress proxy used for routing outgoing requests to upstream AI model providers. Leave blank for direct connection."})]}),e.jsxs("div",{className:"space-y-2.5 pt-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-200",children:"Custom Outbound Headers"}),e.jsx("p",{className:"text-[11px] text-slate-500",children:"Appended to all outgoing requests to upstream providers"})]}),e.jsxs("button",{type:"button",onClick:ue,className:"px-3 py-1 rounded-lg bg-blue-600/10 border border-blue-500/30 text-blue-400 hover:bg-blue-600/20 text-xs font-medium flex items-center gap-1 transition-colors cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"add"}),"Add Header"]})]}),y.length===0?e.jsx("div",{className:"p-3 text-center rounded-xl bg-[#0A0D14] border border-[#1E293B] text-slate-500 text-xs",children:"No custom headers configured. Click “Add Header” to add custom headers."}):e.jsx("div",{className:"space-y-2",children:y.map(t=>e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-xl bg-[#0A0D14] border border-[#1E293B]",children:[e.jsx("input",{type:"text",placeholder:"Header Name (e.g. X-Org-ID)",value:t.key,onChange:s=>X(t.id,"key",s.target.value),className:"flex-1 bg-transparent border-0 px-2 py-1 text-xs font-mono text-white placeholder-slate-600 focus:outline-none"}),e.jsx("span",{className:"text-slate-600 font-mono text-xs",children:":"}),e.jsx("input",{type:"text",placeholder:"Header Value",value:t.value,onChange:s=>X(t.id,"value",s.target.value),className:"flex-1 bg-transparent border-0 px-2 py-1 text-xs font-mono text-white placeholder-slate-600 focus:outline-none"}),e.jsx("button",{type:"button",onClick:()=>he(t.id),className:"p-1 text-slate-500 hover:text-rose-400 cursor-pointer transition-colors",title:"Remove header",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"close"})})]},t.id))})]}),e.jsx("div",{className:"flex items-center justify-end pt-3 border-t border-[#1E293B]",children:e.jsx("button",{type:"submit",disabled:P,className:"px-5 py-2 rounded-xl text-xs font-semibold text-white bg-blue-600 hover:bg-blue-500 shadow-md shadow-blue-600/20 disabled:opacity-50 transition-all flex items-center gap-1.5 cursor-pointer",children:P?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[15px] animate-spin",children:"progress_activity"}),"Saving Configuration..."]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"save"}),"Save Configuration"]})})})]})]}),e.jsxs("div",{className:"w-full p-6 rounded-2xl bg-[#0F1420]/80 border border-[#1E293B] space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-amber-400",children:"vpn_key"}),"Client Gateway API Keys (",v.length,")"]}),e.jsx("p",{className:"text-xs text-slate-400 mt-1",children:"Authentication tokens used by Claude Code CLI, Cursor, and Cline to access Mapigate gateway securely."})]}),e.jsxs("button",{type:"button",onClick:()=>{b(null),h(!0)},className:"px-4 py-2 rounded-xl bg-blue-600 hover:bg-blue-500 shadow-md shadow-blue-600/20 text-xs font-semibold text-white flex items-center gap-1.5 transition-all cursor-pointer self-start sm:self-center shrink-0",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"add"}),"Generate New Key"]})]}),le?e.jsxs("div",{className:"py-12 text-center text-slate-400 flex flex-col items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-2xl text-blue-400 animate-spin",children:"progress_activity"}),e.jsx("span",{className:"text-xs",children:"Loading API keys..."})]}):v.length===0?e.jsxs("div",{className:"py-12 text-center text-slate-400 flex flex-col items-center justify-center gap-2.5 bg-[#0A0D14] rounded-xl border border-[#1E293B]",children:[e.jsx("span",{className:"material-symbols-outlined text-3xl text-slate-600",children:"key_off"}),e.jsx("p",{className:"text-xs font-semibold text-slate-300",children:"No Gateway API Keys Generated"}),e.jsx("p",{className:"text-[11px] text-slate-500 max-w-sm",children:"Generate a client API key to authenticate requests from external developer tools when “Require API Key” is enabled."})]}):e.jsx("div",{className:"w-full overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left text-xs text-slate-300 border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-[#1E293B] text-[11px] text-slate-400 uppercase font-semibold",children:[e.jsx("th",{className:"py-3 px-3",children:"Name / Label"}),e.jsx("th",{className:"py-3 px-3",children:"API Token"}),e.jsx("th",{className:"py-3 px-3",children:"Created"}),e.jsx("th",{className:"py-3 px-3",children:"Last Used"}),e.jsx("th",{className:"py-3 px-3 text-center",children:"Status"}),e.jsx("th",{className:"py-3 px-3 text-right",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y divide-[#1E293B]/60",children:v.map(t=>{const s=re.has(t.id),a=oe===t.id;return e.jsxs("tr",{className:"hover:bg-[#141B2D]/40 transition-colors",children:[e.jsx("td",{className:"py-3.5 px-3 font-semibold text-white",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:t.name}),t.isSystem&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-blue-500/15 text-blue-400 border border-blue-500/30 font-medium",children:"System"})]})}),e.jsx("td",{className:"py-3.5 px-3",children:e.jsxs("div",{className:"flex items-center gap-2 font-mono text-xs",children:[e.jsx("span",{className:`px-2 py-0.5 rounded-lg border ${s?"bg-[#0A0D14] border-blue-500/30 text-blue-300 select-all":"bg-[#0A0D14] border-[#1E293B] text-slate-400 select-none"}`,children:s?t.key:Z(t.key)}),e.jsx("button",{type:"button",onClick:()=>pe(t.id),className:"p-1 text-slate-400 hover:text-white transition-colors cursor-pointer",title:s?"Hide token":"Reveal token",children:e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:s?"visibility_off":"visibility"})}),e.jsx("button",{type:"button",onClick:()=>me(t.key,t.id),className:"p-1 text-slate-400 hover:text-white transition-colors cursor-pointer",title:"Copy API key",children:e.jsx("span",{className:`material-symbols-outlined text-[15px] ${a?"text-emerald-400":""}`,children:a?"check":"content_copy"})})]})}),e.jsx("td",{className:"py-3.5 px-3 text-slate-400 text-[11px]",children:new Date(t.createdAt).toLocaleDateString()}),e.jsx("td",{className:"py-3.5 px-3 text-slate-400 text-[11px] font-mono",children:t.lastUsedAt?new Date(t.lastUsedAt).toLocaleString():"Never"}),e.jsx("td",{className:"py-3.5 px-3 text-center",children:e.jsxs("label",{className:`relative inline-flex items-center ${t.isSystem?"cursor-not-allowed opacity-60":"cursor-pointer"}`,children:[e.jsx("input",{type:"checkbox",checked:t.isActive,disabled:t.isSystem,onChange:()=>de(t),className:"sr-only peer"}),e.jsx("div",{className:"w-8 h-4.5 bg-[#1E293B] peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-3.5 after:w-3.5 after:transition-all peer-checked:bg-emerald-500"})]})}),e.jsx("td",{className:"py-3.5 px-3 text-right",children:t.isSystem?e.jsx("span",{className:"text-[11px] text-slate-500 italic pr-2",children:"Protected"}):e.jsx("button",{type:"button",onClick:()=>C(t),className:"p-1.5 text-slate-400 hover:text-rose-400 hover:bg-rose-500/10 rounded-lg transition-colors cursor-pointer",title:"Delete API key",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"delete"})})})]},t.id)})})]})})]}),q&&e.jsx(ve,{isOpen:q,onClose:()=>{h(!1),b(null)},maxWidthClass:"max-w-md",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] text-amber-400",children:"vpn_key"}),"Generate Gateway API Key"]}),e.jsx("button",{type:"button",onClick:()=>{h(!1),b(null)},className:"p-1 rounded text-slate-400 hover:text-white cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),N?e.jsxs("div",{className:"space-y-4 py-2 animate-rt-scale-in",children:[e.jsxs("div",{className:"p-3 rounded-xl bg-emerald-500/10 border border-emerald-500/30 text-emerald-400 text-xs flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"check_circle"}),e.jsxs("span",{children:["API Key “",N.name,"” generated successfully!"]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"text-[11px] font-semibold text-slate-400 block",children:"Your Gateway Secret Token:"}),e.jsxs("div",{className:"flex items-center gap-2 p-2.5 rounded-xl bg-[#0A0D14] border border-[#1E293B]",children:[e.jsx("span",{className:"font-mono text-xs text-white break-all flex-1 select-all",children:N.key}),e.jsxs("button",{type:"button",onClick:()=>S(N.key,"newlyCreated"),className:"px-2.5 py-1 rounded-lg bg-blue-600 hover:bg-blue-500 text-white text-xs font-semibold flex items-center gap-1 transition-all cursor-pointer shrink-0",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:p==="newlyCreated"?"check":"content_copy"}),p==="newlyCreated"?"Copied":"Copy"]})]})]}),e.jsx("div",{className:"flex justify-end pt-2",children:e.jsx("button",{type:"button",onClick:()=>{h(!1),b(null)},className:"px-4 py-1.5 rounded-xl bg-[#141B2D] border border-[#1E293B] text-xs font-semibold text-white hover:border-slate-600 cursor-pointer",children:"Done"})})]}):e.jsxs("form",{onSubmit:ce,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-200 mb-1",children:"Key Label / Client Name"}),e.jsx("input",{type:"text",placeholder:"e.g. Claude Code CLI, Cursor MacBook, Cline",value:G,onChange:t=>O(t.target.value),className:"w-full bg-[#0A0D14] border border-[#1E293B] focus:border-blue-500 rounded-xl px-3 py-2 text-xs text-white placeholder-slate-500 focus:outline-none",autoFocus:!0}),e.jsx("p",{className:"text-[11px] text-slate-500 mt-1",children:"A friendly label to identify which coding tool is using this key."})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{type:"button",onClick:()=>h(!1),className:"px-4 py-2 text-xs font-medium text-slate-400 hover:text-white bg-[#141B2D] border border-[#1E293B] rounded-xl transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:$,className:"px-4 py-2 rounded-xl text-xs font-semibold text-white bg-blue-600 hover:bg-blue-500 shadow-md shadow-blue-600/20 disabled:opacity-50 transition-all flex items-center gap-1.5 cursor-pointer",children:$?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] animate-spin",children:"progress_activity"}),"Generating..."]}):"Generate Key"})]})]})]})}),x&&e.jsx(we,{isOpen:x!==null,title:"Delete Gateway API Key",message:`Are you sure you want to permanently delete API key "${x.name}" (${Z(x.key)})? Any client tool configured with this key will no longer be authorized.`,confirmText:"Delete Key",variant:"danger",onConfirm:xe,onCancel:()=>C(null)})]})};export{De as EndpointTab};
1
+ import{r as l,j as e}from"./vendor-BcOI2aZ9.js";import{S as Ne}from"./Select-BNRH8LIG.js";import{C as we}from"./ConfirmModal-S6NP0OqD.js";import{u as ee,D as m,d as te,P as ve}from"./index-D3Xjro_O.js";import"./lucide-Cc35htxl.js";const u="10.*, 172.16-31.*, 192.168.*, 169.254.*, *.local",Ce={host:te,port:m,requireApiKey:!1,proxyUrl:"",customHeaders:{},allowedHosts:u},De=({onRestartClick:K})=>{const o=ee(t=>t.info),w=ee(t=>t.fetchSystemInfo),se=!!(o!=null&&o.isRestartRequired),[r,c]=l.useState(Ce),[ae,T]=l.useState(!0),[P,H]=l.useState(!1),[L,f]=l.useState(null),[R,I]=l.useState(null),[y,g]=l.useState([]),[v,j]=l.useState([]),[le,_]=l.useState(!0),[re,ne]=l.useState(new Set),[p,U]=l.useState(null),[oe,F]=l.useState(null),[q,h]=l.useState(!1),[G,O]=l.useState(""),[$,M]=l.useState(!1),[N,b]=l.useState(null),[x,C]=l.useState(null),[J,k]=l.useState(null),[A,V]=l.useState(!1),W=l.useCallback(async()=>{try{T(!0);const[t]=await Promise.all([fetch("/api/settings/endpoint"),w()]);if(t.ok){const s=await t.json();c({host:s.host||te,port:s.port||m,requireApiKey:!!s.requireApiKey,proxyUrl:s.proxyUrl||"",customHeaders:s.customHeaders||{},allowedHosts:s.allowedHosts||u});const a=Object.entries(s.customHeaders||{}).map(([i,n],d)=>({id:`header-${d}-${Date.now()}`,key:i,value:String(n)}));g(a)}}catch(t){console.error("Failed to load endpoint settings:",t)}finally{T(!1)}},[w]),z=l.useCallback(async()=>{try{_(!0);const t=await fetch("/api/settings/endpoint/keys");if(t.ok){const s=await t.json();Array.isArray(s)&&j(s)}}catch(t){console.error("Failed to load gateway API keys:",t)}finally{_(!1)}},[]);l.useEffect(()=>{W(),z()},[W,z]);const ie=async t=>{var a,i;t&&t.preventDefault(),H(!0),f(null),I(null);const s={};for(const n of y){const d=n.key.trim();d&&(s[d]=n.value.trim())}try{const n={host:r.host,port:Number(r.port)||m,requireApiKey:r.requireApiKey,proxyUrl:((a=r.proxyUrl)==null?void 0:a.trim())||"",customHeaders:s,allowedHosts:((i=r.allowedHosts)==null?void 0:i.trim())||u},d=await fetch("/api/settings/endpoint",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!d.ok){const je=await d.json();throw new Error(je.error||"Failed to update endpoint settings")}const ye=await d.json();c(ye);const D=await w(),ge=!!(D!=null&&D.isRestartRequired);f(ge?"Configuration saved! Server restart is required to rebind the network interface.":"Settings saved successfully!"),setTimeout(()=>f(null),5e3)}catch(n){I((n==null?void 0:n.message)||"Failed to save settings")}finally{H(!1)}},ce=async t=>{t.preventDefault();try{M(!0);const s=await fetch("/api/settings/endpoint/keys",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:G.trim()||void 0})});if(s.ok){const a=await s.json();j(i=>[a,...i]),b(a),O("")}else{const a=await s.json();alert(a.error||"Failed to create API key")}}catch(s){console.error("Error creating key:",s)}finally{M(!1)}},de=async t=>{try{const s=await fetch(`/api/settings/endpoint/keys/${t.id}/toggle`,{method:"PATCH"});if(s.ok){const a=await s.json();j(i=>i.map(n=>n.id===t.id?a:n))}}catch(s){console.error("Error toggling API key:",s)}},xe=async()=>{if(x)try{(await fetch(`/api/settings/endpoint/keys/${x.id}`,{method:"DELETE"})).ok&&j(s=>s.filter(a=>a.id!==x.id))}catch(t){console.error("Error deleting API key:",t)}finally{C(null)}},pe=t=>{ne(s=>{const a=new Set(s);return a.has(t)?a.delete(t):a.add(t),a})},S=(t,s)=>{navigator.clipboard.writeText(t),U(s),setTimeout(()=>U(null),2e3)},me=(t,s)=>{navigator.clipboard.writeText(t),F(s),setTimeout(()=>F(null),2e3)},ue=()=>{g([...y,{id:`header-${Date.now()}`,key:"",value:""}])},X=(t,s,a)=>{g(i=>i.map(n=>n.id===t?{...n,[s]:a}:n))},he=t=>{g(s=>s.filter(a=>a.id!==t))},Y=r.host==="0.0.0.0"?"127.0.0.1":r.host||"127.0.0.1",be=(o==null?void 0:o.port)||(typeof window<"u"&&window.location.port&&window.location.port!=="5173"?Number(window.location.port):m),E=r.port||be,Q=`http://${Y}:${E}/v1`,B=`http://${Y}:${E}`,fe=async()=>{V(!0),k(null);try{const s=await(await fetch("/health")).json();k(JSON.stringify(s,null,2))}catch{k(JSON.stringify({error:"Failed to connect to gateway"},null,2))}finally{V(!1)}},Z=t=>{if(t.length<=10)return"••••••••";const s=t.slice(0,6),a=t.slice(-4);return`${s}••••••••${a}`};return e.jsxs("div",{className:"space-y-8 w-full px-2 sm:px-4 pb-16 animate-rt-fade-in",children:[e.jsxs("div",{className:"w-full p-6 rounded-2xl bg-[#0F1420]/80 border border-[#1E293B] space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-blue-400",children:"api"}),"Local Gateway Endpoints"]}),e.jsx("p",{className:"text-xs text-slate-400 mt-1",children:"Universal endpoints accepting OpenAI Chat Completions and Anthropic Messages protocols"})]}),e.jsxs("div",{className:"space-y-3.5 text-xs font-mono",children:[e.jsxs("div",{className:"bg-[#0A0D14] p-4 rounded-xl border border-[#1E293B] flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500 block text-[10px] uppercase font-sans font-semibold",children:"OpenAI-Compatible Base URL (Cursor, Cline, OpenCode, Codex)"}),e.jsx("span",{className:"text-blue-400 font-bold text-sm",children:Q})]}),e.jsxs("button",{type:"button",onClick:()=>S(Q,"openai"),className:"px-3.5 py-1.5 rounded-xl bg-[#141B2D] border border-[#1E293B] hover:border-slate-600 text-xs font-semibold text-slate-300 hover:text-white flex items-center gap-1.5 transition-all cursor-pointer self-start sm:self-center font-sans",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:p==="openai"?"check":"content_copy"}),p==="openai"?"Copied":"Copy"]})]}),e.jsxs("div",{className:"bg-[#0A0D14] p-4 rounded-xl border border-[#1E293B] flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500 block text-[10px] uppercase font-sans font-semibold",children:"Anthropic Base URL (Claude Code CLI: ANTHROPIC_BASE_URL)"}),e.jsx("span",{className:"text-cyan-400 font-bold text-sm",children:B})]}),e.jsxs("button",{type:"button",onClick:()=>S(B,"anthropic"),className:"px-3.5 py-1.5 rounded-xl bg-[#141B2D] border border-[#1E293B] hover:border-slate-600 text-xs font-semibold text-slate-300 hover:text-white flex items-center gap-1.5 transition-all cursor-pointer self-start sm:self-center font-sans",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:p==="anthropic"?"check":"content_copy"}),p==="anthropic"?"Copied":"Copy"]})]})]}),e.jsxs("div",{className:"pt-2 border-t border-[#1E293B] space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-bold text-slate-200 block font-sans",children:"Test Gateway Connectivity:"}),e.jsxs("button",{type:"button",onClick:fe,disabled:A,className:"px-4 py-2 rounded-xl text-xs font-semibold text-white bg-blue-600 hover:bg-blue-500 shadow-md shadow-blue-600/20 disabled:opacity-50 transition-all flex items-center gap-1.5 cursor-pointer font-sans",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${A?"animate-spin":""}`,children:A?"sync":"play_arrow"}),"Execute Test Ping"]})]}),e.jsxs("div",{className:"bg-[#0A0D14] p-3 rounded-xl border border-[#1E293B] text-xs font-mono text-slate-300 overflow-x-auto",children:["curl ",B,"/health"]}),J&&e.jsx("pre",{className:"bg-[#080B10] p-4 rounded-xl border border-blue-500/30 text-emerald-400 text-xs font-mono overflow-x-auto animate-rt-scale-in",children:J})]})]}),e.jsxs("div",{className:"w-full p-6 rounded-2xl bg-[#0F1420]/80 border border-[#1E293B] space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-cyan-400",children:"tune"}),"Gateway & Connection Configuration"]}),e.jsx("p",{className:"text-xs text-slate-400 mt-1",children:"Configure server listening network interface, listening port, security enforcement, and global upstream proxy."})]}),L&&e.jsxs("span",{className:"px-3 py-1 rounded-lg bg-emerald-500/10 border border-emerald-500/30 text-emerald-400 text-xs font-medium flex items-center gap-1.5 animate-rt-fade-in self-start sm:self-center",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"check_circle"}),L]}),R&&e.jsxs("span",{className:"px-3 py-1 rounded-lg bg-rose-500/10 border border-rose-500/30 text-rose-400 text-xs font-medium flex items-center gap-1.5 self-start sm:self-center",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"error"}),R]})]}),se&&e.jsxs("div",{className:"p-4 rounded-xl bg-amber-500/10 border border-amber-500/30 flex flex-col sm:flex-row sm:items-center justify-between gap-3 animate-rt-fade-in",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-amber-400 shrink-0",children:"restart_alt"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-bold text-amber-300",children:"Restart Required to Apply Network Configuration"}),e.jsxs("p",{className:"text-[11px] text-amber-200/70 mt-0.5",children:["Listening host is configured as ",e.jsx("span",{className:"font-mono font-semibold text-white",children:o==null?void 0:o.configuredHost}),", but the gateway socket is still bound to ",e.jsx("span",{className:"font-mono font-semibold text-white",children:o==null?void 0:o.host}),"."]})]})]}),K&&e.jsxs("button",{type:"button",onClick:K,className:"px-3.5 py-1.5 rounded-lg bg-amber-500 hover:bg-amber-400 text-slate-950 font-semibold text-xs transition-colors flex items-center gap-1.5 shrink-0 self-start sm:self-center cursor-pointer shadow-sm",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"restart_alt"}),"Restart Gateway Now"]})]}),ae?e.jsxs("div",{className:"py-12 text-center text-slate-400 flex flex-col items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-2xl text-blue-400 animate-spin",children:"progress_activity"}),e.jsx("span",{className:"text-xs",children:"Loading configuration..."})]}):e.jsxs("form",{onSubmit:ie,className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-200 mb-1.5",children:"Listening Host Interface"}),e.jsx(Ne,{value:r.host,onChange:t=>c({...r,host:t}),options:[{value:"127.0.0.1",label:"127.0.0.1 — Localhost only (Recommended, Private)"},{value:"0.0.0.0",label:"0.0.0.0 — All Interfaces (LAN / Network Access)"},{value:"localhost",label:"localhost — Standard local loopback"}],className:"w-full"}),e.jsx("p",{className:"text-[11px] text-slate-500 mt-1",children:"Bind to 127.0.0.1 to isolate Mapigate to this machine, or 0.0.0.0 to expose on your local network."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-200 mb-1.5",children:"Gateway Port"}),e.jsx("input",{type:"number",min:1024,max:65535,value:r.port,onChange:t=>c({...r,port:parseInt(t.target.value,10)||m}),className:"w-full bg-[#0A0D14] border border-[#1E293B] focus:border-blue-500 rounded-xl px-3.5 py-2 text-xs font-mono text-white placeholder-slate-500 focus:outline-none transition-colors"}),e.jsxs("p",{className:"text-[11px] text-slate-500 mt-1",children:["Active server listening on port ",e.jsx("span",{className:"text-blue-400 font-mono font-semibold",children:E}),". Default port is ",m,". Change requires restarting Mapigate server."]})]})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-[#0A0D14] border border-[#1E293B] space-y-2.5",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("label",{className:"text-xs font-semibold text-slate-200 flex items-center gap-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-cyan-400",children:"lan"}),"Trusted LAN Host Patterns / IP Ranges"]}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"Host header patterns allowed when accessing Mapigate over LAN (comma-separated)."})]}),e.jsxs("button",{type:"button",onClick:()=>c({...r,allowedHosts:u}),className:"px-2.5 py-1 rounded-lg bg-[#141B2D] border border-[#1E293B] hover:border-slate-600 text-[11px] font-medium text-slate-300 hover:text-white flex items-center gap-1 transition-all cursor-pointer self-start sm:self-center shrink-0",title:"Reset to default private network ranges",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px] text-slate-400",children:"restart_alt"}),"Reset to Default"]})]}),e.jsx("input",{type:"text",placeholder:u,value:r.allowedHosts||"",onChange:t=>c({...r,allowedHosts:t.target.value}),className:"w-full bg-[#080B10] border border-[#1E293B] focus:border-blue-500 rounded-xl px-3.5 py-2 text-xs font-mono text-white placeholder-slate-500 focus:outline-none transition-colors"}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-1 text-[10.5px] text-slate-500",children:[e.jsxs("span",{children:["Default: ",e.jsx("code",{className:"text-slate-400 font-mono",children:u})]}),e.jsx("span",{children:"Supports wildcards (e.g. 192.168.*, 10.*, *.local)"})]})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-[#0A0D14] border border-[#1E293B] flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("span",{className:"text-xs font-bold text-white flex items-center gap-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-amber-400",children:"key"}),"Require API Key Authentication"]}),e.jsxs("p",{className:"text-[11px] text-slate-400",children:["When enabled, all incoming proxy requests to ",e.jsx("code",{className:"font-mono text-slate-300",children:"/v1/*"})," must supply an Authorization header matching an active Gateway Key below."]})]}),e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer shrink-0",children:[e.jsx("input",{type:"checkbox",checked:r.requireApiKey,onChange:t=>c({...r,requireApiKey:t.target.checked}),className:"sr-only peer"}),e.jsx("div",{className:"w-10 h-5.5 bg-[#1E293B] peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4.5 after:w-4.5 after:transition-all peer-checked:bg-blue-600"})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-semibold text-slate-200 mb-1.5 flex items-center gap-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-purple-400",children:"router"}),"Global Upstream Proxy URL (Optional)"]}),e.jsx("input",{type:"text",placeholder:"e.g. http://127.0.0.1:7890 or socks5://127.0.0.1:1080",value:r.proxyUrl||"",onChange:t=>c({...r,proxyUrl:t.target.value}),className:"w-full bg-[#0A0D14] border border-[#1E293B] focus:border-blue-500 rounded-xl px-3.5 py-2 text-xs font-mono text-white placeholder-slate-500 focus:outline-none transition-colors"}),e.jsx("p",{className:"text-[11px] text-slate-500 mt-1",children:"Egress proxy used for routing outgoing requests to upstream AI model providers. Leave blank for direct connection."})]}),e.jsxs("div",{className:"space-y-2.5 pt-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-200",children:"Custom Outbound Headers"}),e.jsx("p",{className:"text-[11px] text-slate-500",children:"Appended to all outgoing requests to upstream providers"})]}),e.jsxs("button",{type:"button",onClick:ue,className:"px-3 py-1 rounded-lg bg-blue-600/10 border border-blue-500/30 text-blue-400 hover:bg-blue-600/20 text-xs font-medium flex items-center gap-1 transition-colors cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"add"}),"Add Header"]})]}),y.length===0?e.jsx("div",{className:"p-3 text-center rounded-xl bg-[#0A0D14] border border-[#1E293B] text-slate-500 text-xs",children:"No custom headers configured. Click “Add Header” to add custom headers."}):e.jsx("div",{className:"space-y-2",children:y.map(t=>e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-xl bg-[#0A0D14] border border-[#1E293B]",children:[e.jsx("input",{type:"text",placeholder:"Header Name (e.g. X-Org-ID)",value:t.key,onChange:s=>X(t.id,"key",s.target.value),className:"flex-1 bg-transparent border-0 px-2 py-1 text-xs font-mono text-white placeholder-slate-600 focus:outline-none"}),e.jsx("span",{className:"text-slate-600 font-mono text-xs",children:":"}),e.jsx("input",{type:"text",placeholder:"Header Value",value:t.value,onChange:s=>X(t.id,"value",s.target.value),className:"flex-1 bg-transparent border-0 px-2 py-1 text-xs font-mono text-white placeholder-slate-600 focus:outline-none"}),e.jsx("button",{type:"button",onClick:()=>he(t.id),className:"p-1 text-slate-500 hover:text-rose-400 cursor-pointer transition-colors",title:"Remove header",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"close"})})]},t.id))})]}),e.jsx("div",{className:"flex items-center justify-end pt-3 border-t border-[#1E293B]",children:e.jsx("button",{type:"submit",disabled:P,className:"px-5 py-2 rounded-xl text-xs font-semibold text-white bg-blue-600 hover:bg-blue-500 shadow-md shadow-blue-600/20 disabled:opacity-50 transition-all flex items-center gap-1.5 cursor-pointer",children:P?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[15px] animate-spin",children:"progress_activity"}),"Saving Configuration..."]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"save"}),"Save Configuration"]})})})]})]}),e.jsxs("div",{className:"w-full p-6 rounded-2xl bg-[#0F1420]/80 border border-[#1E293B] space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-amber-400",children:"vpn_key"}),"Client Gateway API Keys (",v.length,")"]}),e.jsx("p",{className:"text-xs text-slate-400 mt-1",children:"Authentication tokens used by Claude Code CLI, Cursor, and Cline to access Mapigate gateway securely."})]}),e.jsxs("button",{type:"button",onClick:()=>{b(null),h(!0)},className:"px-4 py-2 rounded-xl bg-blue-600 hover:bg-blue-500 shadow-md shadow-blue-600/20 text-xs font-semibold text-white flex items-center gap-1.5 transition-all cursor-pointer self-start sm:self-center shrink-0",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"add"}),"Generate New Key"]})]}),le?e.jsxs("div",{className:"py-12 text-center text-slate-400 flex flex-col items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-2xl text-blue-400 animate-spin",children:"progress_activity"}),e.jsx("span",{className:"text-xs",children:"Loading API keys..."})]}):v.length===0?e.jsxs("div",{className:"py-12 text-center text-slate-400 flex flex-col items-center justify-center gap-2.5 bg-[#0A0D14] rounded-xl border border-[#1E293B]",children:[e.jsx("span",{className:"material-symbols-outlined text-3xl text-slate-600",children:"key_off"}),e.jsx("p",{className:"text-xs font-semibold text-slate-300",children:"No Gateway API Keys Generated"}),e.jsx("p",{className:"text-[11px] text-slate-500 max-w-sm",children:"Generate a client API key to authenticate requests from external developer tools when “Require API Key” is enabled."})]}):e.jsx("div",{className:"w-full overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left text-xs text-slate-300 border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-[#1E293B] text-[11px] text-slate-400 uppercase font-semibold",children:[e.jsx("th",{className:"py-3 px-3",children:"Name / Label"}),e.jsx("th",{className:"py-3 px-3",children:"API Token"}),e.jsx("th",{className:"py-3 px-3",children:"Created"}),e.jsx("th",{className:"py-3 px-3",children:"Last Used"}),e.jsx("th",{className:"py-3 px-3 text-center",children:"Status"}),e.jsx("th",{className:"py-3 px-3 text-right",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y divide-[#1E293B]/60",children:v.map(t=>{const s=re.has(t.id),a=oe===t.id;return e.jsxs("tr",{className:"hover:bg-[#141B2D]/40 transition-colors",children:[e.jsx("td",{className:"py-3.5 px-3 font-semibold text-white",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:t.name}),t.isSystem&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-blue-500/15 text-blue-400 border border-blue-500/30 font-medium",children:"System"})]})}),e.jsx("td",{className:"py-3.5 px-3",children:e.jsxs("div",{className:"flex items-center gap-2 font-mono text-xs",children:[e.jsx("span",{className:`px-2 py-0.5 rounded-lg border ${s?"bg-[#0A0D14] border-blue-500/30 text-blue-300 select-all":"bg-[#0A0D14] border-[#1E293B] text-slate-400 select-none"}`,children:s?t.key:Z(t.key)}),e.jsx("button",{type:"button",onClick:()=>pe(t.id),className:"p-1 text-slate-400 hover:text-white transition-colors cursor-pointer",title:s?"Hide token":"Reveal token",children:e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:s?"visibility_off":"visibility"})}),e.jsx("button",{type:"button",onClick:()=>me(t.key,t.id),className:"p-1 text-slate-400 hover:text-white transition-colors cursor-pointer",title:"Copy API key",children:e.jsx("span",{className:`material-symbols-outlined text-[15px] ${a?"text-emerald-400":""}`,children:a?"check":"content_copy"})})]})}),e.jsx("td",{className:"py-3.5 px-3 text-slate-400 text-[11px]",children:new Date(t.createdAt).toLocaleDateString()}),e.jsx("td",{className:"py-3.5 px-3 text-slate-400 text-[11px] font-mono",children:t.lastUsedAt?new Date(t.lastUsedAt).toLocaleString():"Never"}),e.jsx("td",{className:"py-3.5 px-3 text-center",children:e.jsxs("label",{className:`relative inline-flex items-center ${t.isSystem?"cursor-not-allowed opacity-60":"cursor-pointer"}`,children:[e.jsx("input",{type:"checkbox",checked:t.isActive,disabled:t.isSystem,onChange:()=>de(t),className:"sr-only peer"}),e.jsx("div",{className:"w-8 h-4.5 bg-[#1E293B] peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-3.5 after:w-3.5 after:transition-all peer-checked:bg-emerald-500"})]})}),e.jsx("td",{className:"py-3.5 px-3 text-right",children:t.isSystem?e.jsx("span",{className:"text-[11px] text-slate-500 italic pr-2",children:"Protected"}):e.jsx("button",{type:"button",onClick:()=>C(t),className:"p-1.5 text-slate-400 hover:text-rose-400 hover:bg-rose-500/10 rounded-lg transition-colors cursor-pointer",title:"Delete API key",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"delete"})})})]},t.id)})})]})})]}),q&&e.jsx(ve,{isOpen:q,onClose:()=>{h(!1),b(null)},maxWidthClass:"max-w-md",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] text-amber-400",children:"vpn_key"}),"Generate Gateway API Key"]}),e.jsx("button",{type:"button",onClick:()=>{h(!1),b(null)},className:"p-1 rounded text-slate-400 hover:text-white cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),N?e.jsxs("div",{className:"space-y-4 py-2 animate-rt-scale-in",children:[e.jsxs("div",{className:"p-3 rounded-xl bg-emerald-500/10 border border-emerald-500/30 text-emerald-400 text-xs flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"check_circle"}),e.jsxs("span",{children:["API Key “",N.name,"” generated successfully!"]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"text-[11px] font-semibold text-slate-400 block",children:"Your Gateway Secret Token:"}),e.jsxs("div",{className:"flex items-center gap-2 p-2.5 rounded-xl bg-[#0A0D14] border border-[#1E293B]",children:[e.jsx("span",{className:"font-mono text-xs text-white break-all flex-1 select-all",children:N.key}),e.jsxs("button",{type:"button",onClick:()=>S(N.key,"newlyCreated"),className:"px-2.5 py-1 rounded-lg bg-blue-600 hover:bg-blue-500 text-white text-xs font-semibold flex items-center gap-1 transition-all cursor-pointer shrink-0",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:p==="newlyCreated"?"check":"content_copy"}),p==="newlyCreated"?"Copied":"Copy"]})]})]}),e.jsx("div",{className:"flex justify-end pt-2",children:e.jsx("button",{type:"button",onClick:()=>{h(!1),b(null)},className:"px-4 py-1.5 rounded-xl bg-[#141B2D] border border-[#1E293B] text-xs font-semibold text-white hover:border-slate-600 cursor-pointer",children:"Done"})})]}):e.jsxs("form",{onSubmit:ce,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-200 mb-1",children:"Key Label / Client Name"}),e.jsx("input",{type:"text",placeholder:"e.g. Claude Code CLI, Cursor MacBook, Cline",value:G,onChange:t=>O(t.target.value),className:"w-full bg-[#0A0D14] border border-[#1E293B] focus:border-blue-500 rounded-xl px-3 py-2 text-xs text-white placeholder-slate-500 focus:outline-none",autoFocus:!0}),e.jsx("p",{className:"text-[11px] text-slate-500 mt-1",children:"A friendly label to identify which coding tool is using this key."})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{type:"button",onClick:()=>h(!1),className:"px-4 py-2 text-xs font-medium text-slate-400 hover:text-white bg-[#141B2D] border border-[#1E293B] rounded-xl transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:$,className:"px-4 py-2 rounded-xl text-xs font-semibold text-white bg-blue-600 hover:bg-blue-500 shadow-md shadow-blue-600/20 disabled:opacity-50 transition-all flex items-center gap-1.5 cursor-pointer",children:$?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] animate-spin",children:"progress_activity"}),"Generating..."]}):"Generate Key"})]})]})]})}),x&&e.jsx(we,{isOpen:x!==null,title:"Delete Gateway API Key",message:`Are you sure you want to permanently delete API key "${x.name}" (${Z(x.key)})? Any client tool configured with this key will no longer be authorized.`,confirmText:"Delete Key",variant:"danger",onConfirm:xe,onCancel:()=>C(null)})]})};export{De as EndpointTab};