mapigate 0.5.168 → 0.5.174
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/core/adapters/responsesAdapter.js +2 -2
- package/dist/mitm/handlers/base.js +2 -2
- package/dist/providers/catalog/perplexity/index.js +1 -1
- package/dist/providers/catalog/perplexity/provider.js +1 -1
- package/dist/providers/core/base/customExecutionHelper.js +21 -1
- package/dist/providers/core/base/responsesExecution.js +37 -0
- package/dist/providers/core/base/responsesPayloadBuilder.js +5 -0
- package/dist/providers/runtime/antigravity/executor.js +8 -8
- package/dist/providers/runtime/antigravity/metadata.js +1 -1
- package/dist/providers/runtime/antigravity/provider.js +1 -1
- package/dist/providers/runtime/antigravity/quota.js +1 -1
- package/dist/providers/runtime/antigravity/routes.js +1 -1
- package/dist/providers/runtime/antigravity/types.js +1 -1
- package/dist/providers/runtime/antigravity/weekly.js +1 -1
- package/dist/providers/runtime/codex/index.js +1 -1
- package/dist/providers/runtime/codex/provider.js +1 -1
- package/dist/providers/runtime/codex/responses.js +1 -0
- package/dist/providers/runtime/codex/responsesPayload.js +1 -0
- package/dist/providers/runtime/gemini-cli/provider.js +1 -1
- package/dist/providers/runtime/gemini-cli/quota.js +1 -1
- package/dist/providers/runtime/gemini-cli/routes.js +1 -1
- package/dist/providers/runtime/grok-cli/grokWeb.js +5 -0
- package/dist/providers/runtime/grok-cli/provider.js +1 -1
- package/dist/providers/runtime/kiro/constants.js +1 -0
- package/dist/providers/runtime/kiro/executor.js +6 -6
- package/dist/providers/runtime/kiro/index.js +1 -1
- package/dist/providers/runtime/kiro/metadata.js +1 -1
- package/dist/providers/runtime/kiro/provider.js +1 -1
- package/dist/providers/runtime/kiro/quota.js +1 -1
- package/dist/providers/runtime/ollama/nativeChat.js +3 -0
- package/dist/providers/runtime/ollama/provider.js +1 -1
- package/dist/providers/runtime/opencode/provider.js +1 -1
- package/dist/web/assets/CallbackPage-B-htyyMG.js +1 -0
- package/dist/web/assets/{CliToolsTab-D4DtbZ7V.js → CliToolsTab-Q0vXiulu.js} +24 -24
- package/dist/web/assets/ComboDetailPage-hWEuQaOZ.js +1 -0
- package/dist/web/assets/CombosTab-nBWliTLU.js +1 -0
- package/dist/web/assets/{ConfirmModal-DCYNsbhd.js → ConfirmModal-CsfteGXH.js} +1 -1
- package/dist/web/assets/ConsoleLogTab-CW8OK2qW.js +6 -0
- package/dist/web/assets/EditAccountModal-CAxJfsFe.js +1 -0
- package/dist/web/assets/EndpointTab-BSOhVZQl.js +1 -0
- package/dist/web/assets/MitmTab-BjTPAKno.js +6 -0
- package/dist/web/assets/{ModelAutocompleteInput-Cdnm0qff.js → ModelAutocompleteInput-BH4gr6Dr.js} +1 -1
- package/dist/web/assets/ModelSelectModal-BP5Ha7Az.js +1 -0
- package/dist/web/assets/PortalDrawer-Bv31mboq.js +1 -0
- package/dist/web/assets/ProviderDetailPage-CeYToos_.js +6 -0
- package/dist/web/assets/{ProvidersTab-KfP8Lt0p.js → ProvidersTab-C4ZpyulK.js} +1 -1
- package/dist/web/assets/QuotaTab-Dh1eTSJx.js +1 -0
- package/dist/web/assets/SettingsTab-D0Bo21nq.js +1 -0
- package/dist/web/assets/{TokenSaverTab-B3Fbu_yc.js → TokenSaverTab-BYqUuEE1.js} +1 -1
- package/dist/web/assets/UsageTab-C5qvXO61.js +1 -0
- package/dist/web/assets/clipboard-CLQF8jeK.js +1 -0
- package/dist/web/assets/index-_goGZDSK.css +1 -0
- package/dist/web/assets/index-vFoRSZw0.js +10 -0
- package/dist/web/assets/metadataRegistry-4BIaQVmV.js +1 -0
- package/dist/web/assets/{providersData-BevGw_jX.js → providersData-C-7jZmPi.js} +1 -1
- package/dist/web/index.html +2 -2
- package/package.json +2 -2
- package/dist/web/assets/CallbackPage-sTRnWJ-d.js +0 -1
- package/dist/web/assets/ComboDetailPage-RbsO_iJo.js +0 -1
- package/dist/web/assets/CombosTab-DpKJ-Tdm.js +0 -1
- package/dist/web/assets/ConsoleLogTab-DfNJ54Az.js +0 -6
- package/dist/web/assets/EditAccountModal-DdreWxg7.js +0 -1
- package/dist/web/assets/EndpointTab-BYSh-fMY.js +0 -1
- package/dist/web/assets/MitmTab-DDSeULv5.js +0 -14
- package/dist/web/assets/ModelSelectModal-BsleTaNw.js +0 -1
- package/dist/web/assets/ProviderDetailPage-k1kl7EIO.js +0 -6
- package/dist/web/assets/QuotaTab-BA1BaQbz.js +0 -1
- package/dist/web/assets/SettingsTab-FET_sXur.js +0 -1
- package/dist/web/assets/UsageTab-C-Cs4o-K.js +0 -1
- package/dist/web/assets/index-Di7mCTbW.js +0 -2
- package/dist/web/assets/index-h7Meu4Tn.css +0 -1
- package/dist/web/assets/metadataRegistry-EMxpq0lK.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{P as n}from"./metadataRegistry-
|
|
1
|
+
import{P as n}from"./metadataRegistry-4BIaQVmV.js";const s=Object.values(n).filter(e=>e.id!=="combo"&&e.category!=="composite");function a(e){var t;if(!e||e.category==="webCookie"||e.authType==="cookie")return!1;const o=((t=e.id)==null?void 0:t.toLowerCase())||"";return!!(o==="antigravity"||o==="github"||o==="cursor"||o==="kiro"||o==="amazon-q"||o==="codex"||o==="grok-cli"||o==="supergrok"||o==="minimax-code"||o==="codebuddy"||o==="qoder"||o==="cline"||e.oauth!=null||e.category==="oauth"||e.authType==="oauth"||Array.isArray(e.authModes)&&e.authModes.includes("oauth"))}function r(e){var t;if(!e)return!1;const o=((t=e.id)==null?void 0:t.toLowerCase())||"";return o==="opencode"||o==="oc"||o==="ollama-local"||o==="lm-studio"||o==="jan"||e.requiresApiKey===!1||e.authType==="none"||e.noAuth===!0}function i(e){return e?e.category==="freeTier"||e.category==="free"||r(e):!1}const u=s,l=s.filter(e=>i(e)).map(e=>({id:e.id,name:e.name,image:e.image||`/assets/providers/${e.id}/icon.png`,color:e.color||"#10B981",iconBg:e.iconBg,category:"freeTier",defaultConnected:0,baseUrl:e.baseUrl,defaultBaseUrl:e.defaultBaseUrl||e.baseUrl,format:e.format,defaultHeaders:e.defaultHeaders,models:e.models.map(o=>o.id),thinkingMode:e.thinkingMode,authType:e.authType,requiresApiKey:e.requiresApiKey,isLocal:e.isLocal,noAuth:e.noAuth,supportsAutoImport:e.supportsAutoImport,autoImportHint:e.autoImportHint})),c=s.filter(e=>!i(e)&&a(e)).map(e=>({id:e.id,name:e.name,image:e.image||`/assets/providers/${e.id}/icon.png`,color:e.color||"#4285F4",iconBg:e.iconBg,category:"oauth",defaultConnected:0,baseUrl:e.baseUrl,defaultBaseUrl:e.defaultBaseUrl||e.baseUrl,format:e.format,defaultHeaders:e.defaultHeaders,models:e.models.map(o=>o.id),thinkingMode:e.thinkingMode,authType:e.authType,requiresApiKey:e.requiresApiKey,isLocal:e.isLocal,noAuth:e.noAuth,supportsAutoImport:e.supportsAutoImport,autoImportHint:e.autoImportHint})),m=s.filter(e=>!i(e)&&!a(e)).map(e=>({id:e.id,name:e.name,image:e.image||`/assets/providers/${e.id}/icon.png`,color:e.color||"#6366F1",iconBg:e.iconBg,category:"apikey",defaultConnected:0,baseUrl:e.baseUrl,defaultBaseUrl:e.defaultBaseUrl||e.baseUrl,format:e.format,defaultHeaders:e.defaultHeaders,models:e.models.map(o=>o.id),thinkingMode:e.thinkingMode,authType:e.authType,requiresApiKey:e.requiresApiKey,isLocal:e.isLocal,noAuth:e.noAuth,supportsAutoImport:e.supportsAutoImport,autoImportHint:e.autoImportHint})),g=[{id:"claude",name:"Claude Code",image:"/assets/providers/claude/icon.png",status:"Not configured"},{id:"openclaw",name:"Open Claw",image:"/assets/tools/openclaw/icon.png",status:"Not installed"},{id:"codex",name:"OpenAI Codex CLI / App",image:"/assets/providers/codex/icon.png",status:"Not configured"},{id:"copilot",name:"GitHub Copilot",image:"/assets/providers/github/icon.png",iconBg:"#FFFFFF",status:"Guide"},{id:"opencode",name:"OpenCode",image:"/assets/providers/opencode/icon.png",status:"Not configured"},{id:"cowork",name:"Claude Cowork",image:"/assets/providers/claude/icon.png",status:"Not configured"},{id:"hermes",name:"Hermes Agent",image:"/assets/tools/hermes/icon.png",status:"Not installed"},{id:"droid",name:"Factory Droid",image:"/assets/tools/droid/icon.png",status:"Not installed"},{id:"cursor",name:"Cursor",image:"/assets/providers/cursor/icon.png",iconBg:"#FFFFFF",status:"Guide"},{id:"cline",name:"Cline",image:"/assets/providers/cline/icon.png",status:"Not configured"},{id:"kilo",name:"Kilo Code",image:"/assets/providers/kilocode/icon.png",status:"Guide"},{id:"roo",name:"Roo",image:"/assets/tools/roo/icon.png",status:"Guide"},{id:"continue",name:"Continue",image:"/assets/tools/continue/icon.png",status:"Guide"},{id:"amp",name:"Amp CLI",image:"/assets/tools/amp/icon.png",status:"Guide"},{id:"qwen",name:"Qwen Code",image:"/assets/providers/qwen/icon.png",status:"Guide"},{id:"deepseek-tui",name:"DeepSeek TUI",image:"/assets/tools/deepseek-tui/icon.png",status:"Not installed"},{id:"jcode",name:"Jcode",image:"/assets/tools/jcode/icon.png",status:"Not installed"},{id:"grok-build",name:"Grok Build",image:"/assets/tools/grok-build/icon.png",status:"Not installed"},{id:"devin",name:"Devin CLI",image:"/assets/providers/devin/icon.png",status:"Guide"},{id:"opendesign",name:"OpenDesign",image:"/assets/tools/opendesign/icon.png",status:"Guide"},{id:"pi",name:"Pi (pi-coding-agent)",image:"/assets/tools/pi/icon.svg",status:"Not installed"},{id:"omp",name:"Oh My Pi",image:"/assets/tools/omp/icon.png",status:"Not installed"},{id:"crush",name:"Crush",image:"/assets/tools/crush/icon.png",status:"Not installed"},{id:"forge",name:"ForgeCode",image:"/assets/tools/forge/icon.png",status:"Not installed"},{id:"smelt",name:"Smelt",image:"/assets/tools/smelt/icon.svg",status:"Not installed"},{id:"codewhale",name:"CodeWhale",image:"/assets/tools/codewhale/icon.svg",status:"Not installed"}];export{m as A,u as C,l as F,c as O,g as a,a as i};
|
package/dist/web/index.html
CHANGED
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
|
|
9
9
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
10
10
|
<title>Mapigate - AI Model API Gateway & Token Optimizer</title>
|
|
11
|
-
<script type="module" crossorigin src="/assets/index-
|
|
11
|
+
<script type="module" crossorigin src="/assets/index-vFoRSZw0.js"></script>
|
|
12
12
|
<link rel="modulepreload" crossorigin href="/assets/vendor-BcOI2aZ9.js">
|
|
13
13
|
<link rel="modulepreload" crossorigin href="/assets/lucide-Cc35htxl.js">
|
|
14
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
14
|
+
<link rel="stylesheet" crossorigin href="/assets/index-_goGZDSK.css">
|
|
15
15
|
</head>
|
|
16
16
|
<body class="bg-zinc-950 text-zinc-100 min-h-screen antialiased">
|
|
17
17
|
<div id="root"></div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mapigate",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.174",
|
|
4
4
|
"description": "AI Model API Gateway & Token Optimizer for coding tools",
|
|
5
5
|
"author": "Giao Ho",
|
|
6
6
|
"main": "dist/server/index.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"pretest": "npm run codegen",
|
|
33
33
|
"test": "node --import tsx/esm --import ./tests/setup.ts --test --test-concurrency=1 tests/**/*.test.ts",
|
|
34
34
|
"cli": "tsx src/cli/index.ts",
|
|
35
|
-
"typecheck": "tsc --noEmit",
|
|
35
|
+
"typecheck": "tsc --noEmit && tsc -p src/web/tsconfig.json --noEmit",
|
|
36
36
|
"lint": "eslint .",
|
|
37
37
|
"lint:fix": "eslint . --fix",
|
|
38
38
|
"bump": "npm version patch --no-git-tag-version && npm install",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r,j as e}from"./vendor-BcOI2aZ9.js";function $(){const[c,l]=r.useState("processing"),[j,y]=r.useState(null),[N,k]=r.useState(!1),h=r.useRef(!1);return r.useEffect(()=>{if(h.current)return;h.current=!0;const t=new URLSearchParams(window.location.search),v=t.get("code"),i=t.get("token")||t.get("access_token")||t.get("accessToken"),f=t.get("user_id")||t.get("userId"),b=t.get("refreshToken")||t.get("data")||t.get("RefreshToken"),C=t.get("userJwt"),w=t.get("state")||t.get("loginTraceID"),d=t.get("error"),p=t.get("error_description"),x=v||(f&&i||b||C?window.location.href:i),g={code:x,token:i,userId:f,refreshToken:b,state:w,error:d,errorDescription:p,fullUrl:window.location.href},m=o=>{if(window.opener){const s=new Set([window.location.origin]),a=window.location.hostname.toLowerCase();if(a==="localhost"||a==="127.0.0.1"||a==="[::1]"||a==="::1"){const n=window.location.port?`:${window.location.port}`:"",u=window.location.protocol;s.add(`${u}//localhost${n}`),s.add(`${u}//127.0.0.1${n}`),s.add(`${u}//[::1]${n}`)}for(const n of s)try{window.opener.postMessage({type:"oauth_callback",data:o},n)}catch{}}try{const s=new BroadcastChannel("oauth_callback");s.postMessage(o),s.close()}catch{}try{localStorage.setItem("oauth_callback",JSON.stringify({...o,timestamp:Date.now()}))}catch{}};if(d){l("error"),y(p||d),m(g);return}if(!x){l("manual");return}m(g),(async()=>{let o=null;try{const s=localStorage.getItem("oauth_pending_flow");s&&(o=JSON.parse(s))}catch{}if(o!=null&&o.providerId&&!window.opener)try{const s=await fetch(`/api/oauth/${o.providerId}/exchange`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:x,redirectUri:o.redirectUri||`${window.location.origin}/callback`,codeVerifier:o.codeVerifier,state:w||o.state})}),a=await s.json().catch(()=>({}));s.ok&&a.success&&(m({done:!0,account:a.account}),localStorage.removeItem("oauth_pending_flow"))}catch{}l("success"),setTimeout(()=>{try{window.close()}catch{}setTimeout(()=>{k(!0)},600)},800)})()},[]),e.jsx("div",{className:"min-h-screen bg-[#0A0D14] text-slate-100 flex items-center justify-center p-4 select-none",children:e.jsxs("div",{className:"w-full max-w-sm bg-[#0F1420] border border-[#1E293B] rounded-2xl p-6 text-center shadow-2xl",children:[c==="processing"&&e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-blue-500/10 flex items-center justify-center mb-4",children:e.jsx("span",{className:"material-symbols-outlined text-2xl text-blue-500 animate-spin",children:"progress_activity"})}),e.jsx("h1",{className:"text-base font-semibold text-slate-100 mb-1",children:"Connecting to Mapigate..."}),e.jsx("p",{className:"text-xs text-slate-400",children:"Verifying authorization and sending credentials to server."})]}),c==="success"&&e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-emerald-500/10 flex items-center justify-center mb-4",children:e.jsx("span",{className:"material-symbols-outlined text-2xl text-emerald-400",children:"check_circle"})}),e.jsx("h1",{className:"text-base font-semibold text-slate-100 mb-1",children:"Authorization Successful!"}),e.jsx("p",{className:"text-xs text-slate-400 mb-4",children:"Credentials received. This window will close automatically..."}),N&&e.jsx("button",{type:"button",onClick:()=>window.close(),className:"px-4 py-2 bg-blue-600 hover:bg-blue-500 text-white rounded-xl text-xs font-medium transition-colors",children:"Close Window"})]}),c==="error"&&e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-red-500/10 flex items-center justify-center mb-4",children:e.jsx("span",{className:"material-symbols-outlined text-2xl text-red-400",children:"error"})}),e.jsx("h1",{className:"text-base font-semibold text-slate-100 mb-1",children:"Authorization Failed"}),e.jsx("p",{className:"text-xs text-red-400 mb-4 break-words",children:j||"Unable to complete authentication."}),e.jsx("button",{type:"button",onClick:()=>window.close(),className:"px-4 py-2 bg-slate-800 hover:bg-slate-700 text-slate-200 rounded-xl text-xs font-medium transition-colors",children:"Close Window"})]}),c==="manual"&&e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-amber-500/10 flex items-center justify-center mb-4",children:e.jsx("span",{className:"material-symbols-outlined text-2xl text-amber-400",children:"info"})}),e.jsx("h1",{className:"text-base font-semibold text-slate-100 mb-1",children:"Copy Callback URL"}),e.jsx("p",{className:"text-xs text-slate-400 mb-4",children:"Please copy the URL from your address bar and paste it into the application."}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard.writeText(window.location.href)},className:"px-4 py-2 bg-blue-600 hover:bg-blue-500 text-white rounded-xl text-xs font-medium transition-colors",children:"Copy URL"})]})]})})}export{$ as CallbackPage,$ as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e,r as d}from"./vendor-BcOI2aZ9.js";import{C as B}from"./ConfirmModal-DCYNsbhd.js";import{M as Q}from"./ModelSelectModal-BsleTaNw.js";import{g as V,C as D,a as G,M as H,i as E}from"./ModelAutocompleteInput-Cdnm0qff.js";import{S as J}from"./Select-BNRH8LIG.js";import"./index-Di7mCTbW.js";import"./lucide-Cc35htxl.js";import"./dnd-kit-DecqzwfZ.js";import"./ToolIcon-BZE0Fv7L.js";import"./metadataRegistry-EMxpq0lK.js";const K=({model:i,index:a,total:r,onMoveToTop:p,onMoveUp:s,onMoveDown:u,onMoveToBottom:h,onRemove:b})=>{let n="",m=i;if(i.includes("/")){const j=i.indexOf("/");n=i.slice(0,j),m=i.slice(j+1)}const x=V(n||null,m),v=a===0,c=a===r-1;return e.jsxs("div",{className:"flex items-center justify-between gap-3 px-3.5 py-2.5 rounded-xl border border-[#1E293B] bg-[#0A0D14] hover:border-slate-700 hover:bg-[#0F1420] transition-colors group",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[e.jsx("span",{className:`size-6 rounded-lg text-[10px] font-mono font-bold flex items-center justify-center shrink-0 border ${a===0?"bg-blue-500/20 text-blue-300 border-blue-500/30":a===1?"bg-cyan-500/15 text-cyan-300 border-cyan-500/25":"bg-[#141B2D] text-slate-400 border-[#1E293B]"}`,title:`Priority #${a+1}`,children:a+1}),n&&e.jsx("span",{className:"px-2 py-0.5 rounded-md bg-[#161F30] border border-[#26354D] text-[11px] text-cyan-400 font-mono font-medium shrink-0 max-w-[140px] sm:max-w-none truncate",children:n}),e.jsx("span",{className:"text-xs text-white font-mono font-semibold truncate flex-1 min-w-0",children:m}),x&&e.jsx("div",{className:"shrink-0 hidden sm:block",children:e.jsx(D,{caps:x,size:"xs"})})]}),e.jsxs("div",{className:"flex items-center gap-1 text-slate-400 shrink-0",children:[e.jsx("button",{type:"button",disabled:v,onClick:()=>p(a),title:"Move to top priority (#1)",className:"p-1 rounded-md transition-colors hover:bg-white/10 hover:text-white disabled:opacity-20 disabled:pointer-events-none cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"vertical_align_top"})}),e.jsx("button",{type:"button",disabled:v,onClick:()=>s(a),title:"Move up",className:"p-1 rounded-md transition-colors hover:bg-white/10 hover:text-white disabled:opacity-20 disabled:pointer-events-none cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"arrow_upward"})}),e.jsx("button",{type:"button",disabled:c,onClick:()=>u(a),title:"Move down",className:"p-1 rounded-md transition-colors hover:bg-white/10 hover:text-white disabled:opacity-20 disabled:pointer-events-none cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"arrow_downward"})}),e.jsx("button",{type:"button",disabled:c,onClick:()=>h(a),title:"Move to lowest priority",className:"p-1 rounded-md transition-colors hover:bg-white/10 hover:text-white disabled:opacity-20 disabled:pointer-events-none cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"vertical_align_bottom"})}),e.jsx("div",{className:"h-4 w-px bg-[#1E293B] mx-0.5"}),e.jsx("button",{type:"button",onClick:()=>b(a),title:"Remove model from combo",className:"p-1 rounded-md transition-colors hover:bg-rose-500/20 hover:text-rose-400 text-slate-500 cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"close"})})]})]})},W=({combo:i,providersCount:a,saving:r,onBack:p,onUpdateStrategy:s,onToggleActive:u,onDeleteRequest:h})=>{const[b,n]=d.useState(!1),m=G(i.models),x=i.isActive!==!1,v=()=>{navigator.clipboard.writeText(i.name),n(!0),setTimeout(()=>n(!1),2e3)};return e.jsx("div",{className:"w-full p-5 rounded-2xl bg-[#0F1420]/80 border border-[#1E293B] space-y-4",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("button",{type:"button",onClick:p,className:"p-2 rounded-xl bg-[#0A0D14] border border-[#1E293B] text-slate-400 hover:text-white hover:border-slate-700 transition-colors cursor-pointer shrink-0",title:"Back to Combos",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"arrow_back"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-mono text-base font-bold text-white tracking-tight truncate",children:i.name}),m&&e.jsx(D,{caps:m,size:"xs"}),!x&&e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-slate-800 text-slate-400 text-[10px] uppercase font-bold",children:"Disabled"})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-slate-400 mt-1",children:[e.jsxs("span",{children:[e.jsx("strong",{className:"text-white",children:i.models.length})," models configured"]}),e.jsx("span",{children:"•"}),e.jsxs("span",{children:[e.jsx("strong",{className:"text-cyan-400",children:a})," providers"]}),r&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"•"}),e.jsxs("span",{className:"text-blue-400 font-mono text-[11px] flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[12px] animate-spin",children:"progress_activity"}),"Saving..."]})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("button",{type:"button",onClick:v,className:`px-3 py-1.5 rounded-xl border text-xs font-semibold flex items-center gap-1.5 transition-colors cursor-pointer ${b?"bg-emerald-500/10 text-emerald-400 border-emerald-500/20":"bg-[#0A0D14] text-slate-300 border-[#1E293B] hover:text-white hover:border-slate-700"}`,title:"Copy combo alias",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:b?"check":"content_copy"}),e.jsx("span",{children:b?"Copied":"Copy Alias"})]}),e.jsx(J,{value:i.strategy,onChange:c=>s(c),options:[{value:"fallback",label:"Fallback (in order)"},{value:"round-robin",label:"Round Robin"},{value:"fusion",label:"Fusion (parallel)"},{value:"lkgp",label:"LKGP (prompt cache)"},{value:"p2c",label:"P2C (two choices)"}],className:"min-w-[170px]"}),e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer ml-1",title:x?"Disable combo":"Enable combo",children:[e.jsx("input",{type:"checkbox",checked:x,onChange:u,className:"sr-only peer"}),e.jsx("div",{className:"w-9 h-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 after:w-4 after:transition-all peer-checked:bg-blue-600"})]}),e.jsx("button",{type:"button",onClick:h,className:"p-2 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400 hover:bg-rose-500/20 transition-colors cursor-pointer",title:"Delete Combo",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"delete"})})]})]})})},X=({totalModels:i,searchQuery:a,onSearchChange:r,providersList:p,providerFilter:s,onProviderFilterChange:u,onRemoveProviderRequest:h,onBrowseCatalog:b,newModelInput:n,onNewModelInputChange:m,onQuickAdd:x,existingModels:v})=>e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-[240px]",children:[e.jsxs("div",{className:"relative flex-1 max-w-sm",children:[e.jsx("span",{className:"material-symbols-outlined absolute left-3 top-1/2 -translate-y-1/2 text-[16px] text-slate-500",children:"search"}),e.jsx("input",{type:"text",placeholder:`Search among ${i} models...`,value:a,onChange:c=>r(c.target.value),className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl pl-9 pr-8 py-1.5 text-xs text-white placeholder-slate-500 focus:outline-none focus:border-blue-500/50"}),a&&e.jsx("button",{type:"button",onClick:()=>r(""),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-500 hover:text-white text-xs cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),p.length>1&&e.jsxs("select",{value:s,onChange:c=>u(c.target.value),className:"bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-1.5 text-xs text-slate-300 focus:outline-none focus:border-blue-500/50 cursor-pointer",children:[e.jsxs("option",{value:"all",children:["All Providers (",p.length,")"]}),p.map(c=>e.jsx("option",{value:c,children:c},c))]}),s!=="all"&&e.jsxs("button",{type:"button",onClick:()=>h(s),className:"px-2.5 py-1.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400 hover:bg-rose-500/20 text-xs font-semibold flex items-center gap-1 cursor-pointer",title:`Remove all models from ${s}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"delete_sweep"}),e.jsxs("span",{children:["Remove “",s,"”"]})]})]}),e.jsxs("button",{type:"button",onClick:b,className:"px-3.5 py-1.5 rounded-xl bg-blue-600 hover:bg-blue-500 text-xs font-semibold text-white flex items-center gap-1.5 shadow-lg shadow-blue-600/20 cursor-pointer shrink-0",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"add_circle"}),e.jsx("span",{children:"Browse Catalog"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-1 border-t border-[#1E293B]/60",children:[e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx(H,{value:n,onChange:m,onEnter:x,placeholder:"Quick add model (e.g. anthropic/claude-3-7-sonnet or devin/gpt-5-low)...",excludeValues:v,allowCombos:!1})}),e.jsx("button",{type:"button",disabled:!n.trim(),onClick:x,className:"px-4 py-2 rounded-xl bg-[#1E293B] hover:bg-blue-600 text-xs font-semibold text-white transition-colors disabled:opacity-40 disabled:pointer-events-none cursor-pointer shrink-0",children:"Add"})]})]}),ne=({combo:i,onBack:a,onComboUpdated:r,onComboDeleted:p})=>{const[s,u]=d.useState(i),[h,b]=d.useState(""),[n,m]=d.useState("all"),[x,v]=d.useState(""),[c,j]=d.useState(!1),[T,M]=d.useState(!1),[C,k]=d.useState(!1),[y,N]=d.useState(null),S=d.useMemo(()=>{const t=new Set;for(const l of s.models)if(l.includes("/")){const o=l.split("/")[0].replace(/\(.*?\)/,"").trim();o&&t.add(o)}return Array.from(t).sort()},[s.models]),f=d.useCallback(async t=>{const l=s,o={...s,...t};u(o),r==null||r(o);try{M(!0);const g=await fetch(`/api/combos/${s.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:o.name,models:o.models,strategy:o.strategy,isActive:o.isActive})});if(g.ok){const w=await g.json();u(w),r==null||r(w),E()}else{const w=await g.json().catch(()=>({}));console.error("Failed to update combo:",w.error||g.statusText),u(l),r==null||r(l)}}catch(g){console.error("Failed to update combo:",g),u(l),r==null||r(l)}finally{M(!1)}},[s,r]),R=t=>{if(t<=0)return;const o=[s.models[t],...s.models.slice(0,t),...s.models.slice(t+1)];f({models:o})},$=t=>{if(t<=0)return;const l=[...s.models],o=l[t];l[t]=l[t-1],l[t-1]=o,f({models:l})},_=t=>{if(t>=s.models.length-1)return;const l=[...s.models],o=l[t];l[t]=l[t+1],l[t+1]=o,f({models:l})},F=t=>{if(t>=s.models.length-1)return;const l=s.models[t],o=[...s.models.slice(0,t),...s.models.slice(t+1),l];f({models:o})},P=t=>{const l=s.models.filter((o,g)=>g!==t);f({models:l})},I=()=>{const t=x.trim();!t||new Set([s.name,`combo/${s.name}`,s.id]).has(t)||s.models.includes(t)||(f({models:[...s.models,t]}),v(""))},O=t=>{f({models:t}),j(!1)},L=d.useMemo(()=>{const t=[];return s!=null&&s.id&&t.push(s.id),s!=null&&s.name&&(t.push(s.name),t.push(`combo/${s.name}`)),t},[s]),q=t=>{const l=s.models.filter(o=>o.split("/")[0].replace(/\(.*?\)/,"").trim()!==t);f({models:l}),N(null),n===t&&m("all")},z=async()=>{try{(await fetch(`/api/combos/${s.id}`,{method:"DELETE"})).ok&&(E(),p==null||p(),a())}catch(t){console.error("Failed to delete combo:",t)}},A=d.useMemo(()=>{const t=h.trim().toLowerCase();return s.models.map((l,o)=>({model:l,originalIndex:o})).filter(({model:l})=>!(n!=="all"&&l.split("/")[0].replace(/\(.*?\)/,"").trim()!==n||t&&!l.toLowerCase().includes(t)))},[s.models,h,n]);return e.jsxs("div",{className:"space-y-6 w-full pb-16 animate-rt-fade-in",children:[e.jsx(W,{combo:s,providersCount:S.length,saving:T,onBack:a,onUpdateStrategy:t=>f({strategy:t}),onToggleActive:()=>f({isActive:s.isActive===!1}),onDeleteRequest:()=>k(!0)}),e.jsxs("div",{className:"w-full p-5 rounded-2xl bg-[#0F1420]/80 border border-[#1E293B] space-y-4",children:[e.jsx(X,{totalModels:s.models.length,searchQuery:h,onSearchChange:b,providersList:S,providerFilter:n,onProviderFilterChange:m,onRemoveProviderRequest:t=>N(t),onBrowseCatalog:()=>j(!0),newModelInput:x,onNewModelInputChange:v,onQuickAdd:I,existingModels:s.models}),e.jsx("div",{className:"space-y-2 pt-2",children:A.length===0?e.jsxs("div",{className:"py-12 text-center text-slate-500 bg-[#0A0D14]/60 rounded-xl border border-[#1E293B]",children:[e.jsx("span",{className:"material-symbols-outlined text-3xl mb-1 text-slate-600",children:"filter_list_off"}),e.jsx("p",{className:"text-xs",children:"No models match current filter"}),(h||n!=="all")&&e.jsx("button",{type:"button",onClick:()=>{b(""),m("all")},className:"mt-2 text-xs text-blue-400 hover:underline cursor-pointer",children:"Clear filters"})]}):A.map(({model:t,originalIndex:l})=>e.jsx(K,{model:t,index:l,total:s.models.length,onMoveToTop:R,onMoveUp:$,onMoveDown:_,onMoveToBottom:F,onRemove:P},`${t}-${l}`))})]}),C&&e.jsx(B,{isOpen:C,title:"Delete Combo",message:`Are you sure you want to delete combo "${s.name}"? This action cannot be undone.`,confirmText:"Delete Combo",variant:"danger",onClose:()=>k(!1),onConfirm:z}),y&&e.jsx(B,{isOpen:!!y,title:`Remove ${y} Models`,message:`Remove all models belonging to provider "${y}" from this combo?`,confirmText:"Remove Models",variant:"danger",onClose:()=>N(null),onConfirm:()=>q(y)}),c&&e.jsx(Q,{isOpen:c,onClose:()=>j(!1),title:`Manage Models in ${s.name}`,addedModelValues:s.models,initialSelectedModels:s.models,excludeModelIds:L,onConfirm:O,multiSelect:!0,allowCombos:!1})]})};export{ne as ComboDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as x,j as e}from"./vendor-BcOI2aZ9.js";import{u as ae,a as X,D as le,c as re,S as ne,v as oe,b as ie,s as ce,K as de,P as xe,d as me,C as ue}from"./dnd-kit-DecqzwfZ.js";import{P as Z}from"./index-Di7mCTbW.js";import{M as H,i as G,C as Y,a as pe}from"./ModelAutocompleteInput-Cdnm0qff.js";import{M as ee}from"./ModelSelectModal-BsleTaNw.js";import{S as Q}from"./Select-BNRH8LIG.js";import{T as be}from"./ToolIcon-BZE0Fv7L.js";import{P as he}from"./metadataRegistry-EMxpq0lK.js";import{C as fe}from"./ConfirmModal-DCYNsbhd.js";import"./lucide-Cc35htxl.js";const ge=/^[a-zA-Z0-9_.-]+$/,ye=({id:l,model:n,index:a,onEdit:k,onRemove:w,onMoveUp:i,onMoveDown:y,isFirst:p,isLast:C,excludeValues:s})=>{const[c,j]=x.useState(!1),[N,g]=x.useState(n);x.useEffect(()=>{g(n)},[n]);const h=B=>{const I=(typeof B=="string"?B:N).trim();I&&I!==n?k(I):g(n),j(!1)},{attributes:m,listeners:T,setNodeRef:L,transform:E,transition:b,isDragging:S}=me({id:l}),D={transform:ue.Transform.toString(E),transition:b,zIndex:S?50:void 0,opacity:S?.6:1};return e.jsxs("div",{ref:L,style:D,className:`group flex items-center justify-between gap-2.5 px-3 py-2 rounded-xl border bg-[#0A0D14] transition-all ${S?"border-blue-500 shadow-lg shadow-blue-500/10 bg-blue-950/40":"border-[#1E293B] hover:border-slate-700"}`,children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[e.jsx("button",{type:"button",...m,...T,className:"cursor-grab active:cursor-grabbing text-slate-500 hover:text-slate-300 p-0.5 rounded touch-none shrink-0",title:"Drag to reorder priority",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"drag_indicator"})}),e.jsx("span",{className:"size-5 rounded-md bg-[#141B2D] border border-[#1E293B] text-[10px] font-mono text-blue-400 font-bold flex items-center justify-center shrink-0",children:a+1}),c?e.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-1.5",children:[e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx(H,{autoFocus:!0,value:N,onChange:B=>g(B),onEnter:B=>h(B),placeholder:"e.g. anthropic/claude-3-7-sonnet",excludeValues:s,allowCombos:!1,className:"w-full rounded border border-blue-500/60 bg-[#141B2D] px-2 py-0.5 font-mono text-xs text-white outline-none focus:border-blue-400"})}),e.jsx("button",{type:"button",onClick:h,className:"p-1 text-emerald-400 hover:text-emerald-300 cursor-pointer",title:"Save changes",children:e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"check"})}),e.jsx("button",{type:"button",onClick:()=>{g(n),j(!1)},className:"p-1 text-slate-400 hover:text-white cursor-pointer",title:"Cancel",children:e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"close"})})]}):e.jsxs("div",{className:"min-w-0 flex-1 cursor-text truncate rounded px-1.5 py-0.5 font-mono text-xs text-white hover:bg-white/5 flex items-center gap-2",onClick:()=>j(!0),title:"Click to edit model ID inline",children:[e.jsx("span",{className:"truncate",title:n,children:n}),e.jsx("span",{className:"material-symbols-outlined text-[13px] text-slate-500 opacity-0 group-hover:opacity-100 transition-opacity",children:"edit"})]}),!c&&e.jsx(Y,{model:n,size:"xs"})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{type:"button",onClick:i,disabled:p,className:"p-1 text-slate-400 hover:text-white disabled:opacity-20 disabled:hover:text-slate-400 cursor-pointer transition-colors",title:"Move up",children:e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"arrow_upward"})}),e.jsx("button",{type:"button",onClick:y,disabled:C,className:"p-1 text-slate-400 hover:text-white disabled:opacity-20 disabled:hover:text-slate-400 cursor-pointer transition-colors",title:"Move down",children:e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"arrow_downward"})}),e.jsx("button",{type:"button",onClick:w,className:"p-1 text-slate-400 hover:text-rose-400 cursor-pointer transition-colors",title:"Remove model",children:e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"close"})})]})]})},je=({isOpen:l,onClose:n,combo:a,title:k,onSave:w})=>{const[i,y]=x.useState(""),[p,C]=x.useState("round-robin"),[s,c]=x.useState([]),[j,N]=x.useState(""),[g,h]=x.useState(""),[m,T]=x.useState(""),[L,E]=x.useState(!1),[b,S]=x.useState(!1),D=!!a,B=ae(X(xe,{activationConstraint:{distance:4}}),X(de,{coordinateGetter:ce}));x.useEffect(()=>{l&&(a?(y(a.name),C(a.strategy||"round-robin"),c(Array.isArray(a.models)?[...a.models]:[])):(y(""),C("round-robin"),c([])),N(""),h(""),T(""),S(!1))},[l,a]);const $=d=>{const r=d.trim();return r?ge.test(r)?(N(""),!0):(N("Name can only contain letters, numbers, -, _ and ."),!1):(N("Combo name is required."),!1)},I=d=>{const r=d.target.value;y(r),r.trim()?$(r):N("")},_=x.useMemo(()=>{const d=[];a!=null&&a.id&&d.push(a.id),a!=null&&a.name&&(d.push(a.name),d.push(`combo/${a.name}`));const r=i.trim();return r&&(d.push(r),d.push(`combo/${r}`)),d},[a,i]),R=d=>{const r=d.trim().toLowerCase(),t=r.startsWith("combo/")?r.slice(6):r;return _.some(o=>{const f=o.toLowerCase(),M=f.startsWith("combo/")?f.slice(6):f;return r===f||t===M})},q=(d,r)=>{const t=r.trim();if(R(t)){h("A combo cannot bundle itself (circular reference).");return}const o=[...s];o[d]=t,c(o),h("")},u=d=>{c(s.filter((r,t)=>t!==d))},v=d=>{if(d===0)return;const r=[...s],t=r[d-1];r[d-1]=r[d],r[d]=t,c(r)},A=d=>{if(d===s.length-1)return;const r=[...s],t=r[d+1];r[d+1]=r[d],r[d]=t,c(r)},z=d=>{const{active:r,over:t}=d;t&&r.id!==t.id&&c(o=>{const f=o.map((P,U)=>`${P}-${U}`),M=f.indexOf(String(r.id)),F=f.indexOf(String(t.id));return M!==-1&&F!==-1?ie(o,M,F):o})},V=(d,r)=>{const t=(typeof r=="string"?r:m).trim();if(t){if(R(t)){h("A combo cannot bundle itself (circular reference).");return}s.includes(t)||(c([...s,t]),h("")),T("")}},O=async d=>{if(d.preventDefault(),!!$(i)){if(s.length===0){h("At least one model must be added to the combo.");return}if(s.some(R)){h("A combo cannot bundle itself (circular reference).");return}try{S(!0),await w({id:a==null?void 0:a.id,name:i.trim(),models:s,strategy:p,isActive:a?a.isActive:!0}),G(),n()}catch(r){N((r==null?void 0:r.message)||"Failed to save combo.")}finally{S(!1)}}};return e.jsxs(e.Fragment,{children:[e.jsx(Z,{isOpen:l,onClose:n,maxWidthClass:"w-full max-w-3xl",children:e.jsxs("form",{onSubmit:O,className:"space-y-5 -m-2 sm:-m-4 p-5 sm:p-6",children:[e.jsxs("div",{className:"flex items-center justify-between pb-4 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-9 rounded-xl bg-blue-500/10 border border-blue-500/20 text-blue-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:D?"edit_note":"add_circle"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-bold text-white",children:k||(D?`Edit Combo: ${a==null?void 0:a.name}`:"Create Smart Model Combo")}),e.jsx("p",{className:"text-xs text-slate-400",children:"Configure an alias to rotate or fallback across multiple upstream models"})]})]}),e.jsx("button",{type:"button",onClick:n,className:"p-1.5 rounded-lg text-slate-400 hover:text-white hover:bg-white/10 cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"close"})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-semibold text-slate-200 mb-1.5",children:["Combo Name / Alias ",e.jsx("span",{className:"text-rose-400",children:"*"})]}),e.jsx("input",{type:"text",placeholder:"e.g. combo-fast-coding, claude-3-7-sonnet",value:i,onChange:I,className:`w-full bg-[#0A0D14] border rounded-xl px-3.5 py-2 text-xs font-mono text-white placeholder-slate-500 focus:outline-none transition-colors ${j?"border-rose-500/80 focus:border-rose-500":"border-[#1E293B] focus:border-blue-500"}`}),j?e.jsxs("p",{className:"text-[11px] text-rose-400 mt-1 flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"error"}),j]}):e.jsx("p",{className:"text-[11px] text-slate-500 mt-1",children:"Can contain letters, numbers, dashes, underscores, and dots."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-200 mb-1.5",children:"Routing Strategy"}),e.jsx(Q,{value:p,onChange:d=>C(d),options:[{value:"round-robin",label:"Round Robin — Rotate across accounts"},{value:"fallback",label:"Fallback — Sequential priority order"},{value:"fusion",label:"Fusion — Parallel query panel + judge synthesis"},{value:"lkgp",label:"LKGP — Last Known Good (maximize prompt cache warmth)"},{value:"p2c",label:"P2C — Power of Two Choices (dynamic EMA load balancing)"}],className:"w-full"}),e.jsxs("div",{className:"mt-2 p-2.5 rounded-xl bg-[#0A0D14] border border-[#1E293B] text-[11px] text-slate-400",children:[p==="round-robin"&&e.jsxs("span",{className:"text-cyan-300",children:[e.jsx("strong",{children:"Round Robin:"})," Spreads requests across member models in alternating turns to balance rate limits."]}),p==="fallback"&&e.jsxs("span",{className:"text-blue-300",children:[e.jsx("strong",{children:"Fallback:"})," Tries models sequentially; moves to backup on HTTP 429, 503, or quota errors."]}),p==="fusion"&&e.jsxs("span",{className:"text-indigo-300",children:[e.jsx("strong",{children:"Fusion:"})," Queries member models concurrently in parallel, then synthesizes the best answer with a judge."]}),p==="lkgp"&&e.jsxs("span",{className:"text-emerald-300",children:[e.jsx("strong",{children:"LKGP (Last Known Good):"})," Retains the model that succeeded on the last request to keep prompt caches warm; fails over on error."]}),p==="p2c"&&e.jsxs("span",{className:"text-amber-300",children:[e.jsx("strong",{children:"P2C (Power of Two Choices):"})," Samples 2 candidates at random and routes to the one with superior latency and error score via EMA."]})]})]}),e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("label",{className:"block text-xs font-semibold text-slate-200",children:["Member Models (",s.length,") ",e.jsx("span",{className:"text-rose-400",children:"*"})]}),e.jsxs("button",{type:"button",onClick:()=>E(!0),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.5 transition-colors cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"add"}),"Add Model"]})]}),e.jsx("div",{className:"border border-[#1E293B] rounded-2xl bg-[#0A0D14]/50 p-2.5 space-y-2 min-h-[140px] max-h-[260px] overflow-y-auto",children:s.length===0?e.jsx("div",{className:"py-8 text-center text-slate-500 text-xs",children:"No models in this combo yet. Click “Add Model” to pick from catalog or enter a model ID below."}):e.jsx(le,{sensors:B,collisionDetection:re,onDragEnd:z,children:e.jsx(ne,{items:s.map((d,r)=>`${d}-${r}`),strategy:oe,children:e.jsx("div",{className:"space-y-1.5",children:s.map((d,r)=>e.jsx(ye,{id:`${d}-${r}`,model:d,index:r,onEdit:t=>q(r,t),onRemove:()=>u(r),onMoveUp:()=>v(r),onMoveDown:()=>A(r),isFirst:r===0,isLast:r===s.length-1,excludeValues:_},`${d}-${r}`))})})})}),g&&e.jsxs("p",{className:"text-[11px] text-rose-400 flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"error"}),g]}),e.jsxs("div",{className:"flex gap-2 pt-1 items-start",children:[e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx(H,{placeholder:"Or search/type model ID (e.g. anthropic/claude-3-7-sonnet)...",value:m,onChange:T,onEnter:d=>V(void 0,d),excludeValues:_,allowCombos:!1,className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-1.5 text-xs text-white font-mono placeholder-slate-500 focus:outline-none focus:border-blue-500"})}),e.jsx("button",{type:"button",onClick:()=>V(),disabled:!m.trim(),className:"px-3 py-1.5 rounded-xl bg-[#141B2D] border border-[#1E293B] hover:border-blue-500/50 hover:bg-blue-600/10 text-xs text-slate-300 hover:text-white disabled:opacity-40 cursor-pointer whitespace-nowrap shrink-0",children:"Add"})]})]})]}),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:b,className:"px-4 py-2 rounded-xl text-xs font-medium text-slate-400 hover:text-white bg-[#141B2D] border border-[#1E293B] hover:border-slate-700 transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:b,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:b?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[15px] animate-spin",children:"progress_activity"}),"Saving..."]}):e.jsx("span",{children:D?"Update Combo":"Save Combo"})})]})]})}),L&&e.jsx(ee,{isOpen:L,onClose:()=>E(!1),addedModelValues:s,initialSelectedModels:s,excludeModelIds:_,allowCombos:!1,onConfirm:d=>{c(d),d.length>0&&h("")},title:"Add Model to Combo",multiSelect:!0,closeOnSelect:!1})]})},Ne=({provider:l,freeTier:n,freeModels:a,selectedModelValues:k,onToggleModel:w,onToggleAllProviderModels:i,connectionStatus:y,statusLabel:p,statusDetail:C,onTestConnection:s,isTesting:c,defaultExpanded:j=!1})=>{const[N,g]=x.useState(j),h=a.filter(b=>k.has(b.comboModelValue)).length,m=a.length>0&&h===a.length,T=h>0&&h<a.length,E=(b=>{switch(b){case"local":return{label:"Local Engine",bg:"bg-purple-500/10 text-purple-400 border-purple-500/20"};case"credits":return{label:"Free Credits",bg:"bg-emerald-500/10 text-emerald-400 border-emerald-500/20"};case"per-model":return{label:"Per-Model Limits",bg:"bg-blue-500/10 text-blue-400 border-blue-500/20"};case"requests":default:return{label:"Free Requests",bg:"bg-cyan-500/10 text-cyan-400 border-cyan-500/20"}}})(n.limitType);return e.jsxs("div",{className:"rounded-xl border border-[#1E293B] bg-[#0A0D14]/90 overflow-hidden transition-all duration-200 hover:border-slate-700",children:[e.jsxs("div",{className:"p-3.5 flex flex-wrap items-center justify-between gap-3 bg-[#0F1420]/60",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("input",{type:"checkbox",checked:m,ref:b=>{b&&(b.indeterminate=T)},onChange:b=>i(l.id,b.target.checked),title:m?"Deselect all models":"Select all free models",className:"size-4 rounded border-slate-700 bg-slate-800 text-blue-600 focus:ring-0 focus:ring-offset-0 cursor-pointer"}),e.jsx(be,{src:l.image,name:l.name,color:l.color,iconBg:l.iconBg,size:"sm"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-semibold text-xs text-white truncate",children:l.name}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-medium border ${E.bg}`,children:E.label})]}),n.note&&e.jsx("p",{className:"text-[11px] text-slate-400 truncate max-w-md",title:n.note,children:n.note})]})]}),e.jsxs("div",{className:"flex items-center gap-2.5 shrink-0 ml-auto",children:[e.jsxs("div",{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-[11px] font-medium border ${y==="connected"?"bg-emerald-500/10 text-emerald-400 border-emerald-500/20":y==="not_connected"?"bg-amber-500/10 text-amber-400 border-amber-500/20":"bg-rose-500/10 text-rose-400 border-rose-500/20"}`,title:C||p,children:[e.jsx("span",{className:"size-1.5 rounded-full animate-pulse bg-current"}),e.jsx("span",{children:p}),C&&e.jsxs("span",{className:"opacity-75 font-mono text-[10px]",children:["(",C,")"]})]}),e.jsxs("button",{type:"button",onClick:()=>s(l.id),disabled:c,title:"Test upstream connection",className:"px-2 py-1 rounded-lg bg-slate-800/80 hover:bg-slate-700 text-slate-300 text-[11px] font-medium flex items-center gap-1 transition-colors cursor-pointer disabled:opacity-50",children:[e.jsx("span",{className:`material-symbols-outlined text-[13px] ${c?"animate-spin text-blue-400":""}`,children:c?"refresh":"network_check"}),e.jsx("span",{children:c?"Testing":"Test"})]}),e.jsxs("button",{type:"button",onClick:()=>g(!N),className:"px-2 py-1 rounded-lg bg-slate-800/50 hover:bg-slate-800 text-slate-300 text-[11px] font-medium flex items-center gap-1.5 transition-colors cursor-pointer",children:[e.jsxs("span",{className:"text-slate-400",children:[h,"/",a.length]}),e.jsx("span",{className:"material-symbols-outlined text-[15px] transition-transform duration-200",children:N?"expand_less":"expand_more"})]})]})]}),N&&e.jsx("div",{className:"p-3 border-t border-[#1E293B] bg-[#0A0D14]/40 space-y-1.5 animate-rt-fade-in",children:a.length===0?e.jsx("div",{className:"py-3 text-center text-xs text-slate-500 italic",children:"No free models configured or discovered yet."}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-1.5 max-h-64 overflow-y-auto pr-1",children:a.map(b=>{const S=k.has(b.comboModelValue);return e.jsxs("label",{className:`flex items-start gap-2.5 p-2 rounded-lg border text-xs cursor-pointer transition-all ${S?"bg-blue-600/10 border-blue-500/30 text-white":"bg-[#0F1420]/50 border-[#1E293B]/70 text-slate-300 hover:bg-white/5"}`,children:[e.jsx("input",{type:"checkbox",checked:S,onChange:()=>w(b.comboModelValue),className:"size-3.5 mt-0.5 rounded border-slate-700 bg-slate-800 text-blue-600 focus:ring-0 focus:ring-offset-0 cursor-pointer shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"font-semibold text-slate-200 truncate",children:b.name}),b.contextLength&&e.jsxs("span",{className:"text-[10px] px-1 rounded bg-slate-800 text-slate-400",children:[Math.round(b.contextLength/1e3),"k ctx"]})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsx("span",{className:"font-mono text-[10px] text-slate-500 truncate",children:b.comboModelValue}),b.limit&&e.jsxs("span",{className:"text-[10px] text-cyan-400/90 truncate",children:["• ",b.limit]})]})]})]},b.comboModelValue)})})})]})},ve=({searchQuery:l,onSearchChange:n,onlyConnected:a,onToggleOnlyConnected:k,onSelectConnectedOnly:w,onDeselectAll:i,onTestAll:y,isTestingAll:p})=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2.5 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-[220px]",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("span",{className:"material-symbols-outlined absolute left-2.5 top-1/2 -translate-y-1/2 text-slate-500 text-[16px]",children:"search"}),e.jsx("input",{type:"text",value:l,onChange:C=>n(C.target.value),placeholder:"Search free providers or models...",className:"w-full pl-8 pr-3 py-1.5 bg-[#0A0D14] border border-[#1E293B] rounded-xl text-xs text-slate-200 placeholder-slate-500 focus:outline-none focus:border-blue-500"})]}),e.jsxs("button",{type:"button",onClick:k,className:`px-2.5 py-1.5 rounded-xl border text-xs font-medium flex items-center gap-1.5 transition-colors cursor-pointer shrink-0 ${a?"bg-emerald-500/15 border-emerald-500/30 text-emerald-400":"bg-[#0A0D14] border-[#1E293B] text-slate-400 hover:text-slate-200"}`,children:[e.jsx("span",{className:"size-1.5 rounded-full bg-current"}),"Connected Only"]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0 text-xs",children:[e.jsx("button",{type:"button",onClick:w,className:"px-2.5 py-1.5 rounded-xl bg-slate-800/60 hover:bg-slate-800 text-slate-300 font-medium transition-colors cursor-pointer",children:"Select Connected"}),e.jsx("button",{type:"button",onClick:i,className:"px-2.5 py-1.5 rounded-xl bg-slate-800/60 hover:bg-slate-800 text-slate-300 font-medium transition-colors cursor-pointer",children:"Deselect All"}),e.jsxs("button",{type:"button",onClick:y,disabled:p,className:"px-2.5 py-1.5 rounded-xl bg-blue-600/10 border border-blue-500/20 text-blue-400 hover:bg-blue-600/20 font-medium flex items-center gap-1 transition-colors cursor-pointer disabled:opacity-50",children:[e.jsx("span",{className:`material-symbols-outlined text-[14px] ${p?"animate-spin":""}`,children:p?"refresh":"network_check"}),"Test All"]})]})]}),we=({comboName:l,onComboNameChange:n,strategy:a,onStrategyChange:k})=>e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 p-4 rounded-xl bg-[#0A0D14] border border-[#1E293B] shrink-0",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-semibold text-slate-300 mb-1.5",children:["Combo Identifier ",e.jsx("span",{className:"text-rose-400",children:"*"})]}),e.jsx("input",{type:"text",value:l,onChange:w=>n(w.target.value),placeholder:"e.g. free-fallback",className:"w-full px-3 py-2 bg-[#0F1420] border border-[#1E293B] rounded-xl text-xs text-white placeholder-slate-500 focus:outline-none focus:border-blue-500 font-mono"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-300 mb-1.5",children:"Routing Strategy"}),e.jsx(Q,{value:a,onChange:w=>k(w),options:[{value:"fallback",label:"Fallback (try free models in order)"},{value:"round-robin",label:"Round Robin (distribute across free tiers)"},{value:"lkgp",label:"LKGP (Last Known Good Provider)"},{value:"fusion",label:"Fusion (parallel multi-model panel)"},{value:"p2c",label:"P2C (Power of Two Choices)"}],className:"w-full"})]})]});function Ce(l,n){if(!l||!n)return!1;if(l===n)return!0;const a=l.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,".");return new RegExp(`^${a}$`,"i").test(n)}function Se(l){return l?l.freeTier!=null||l.category==="freeTier"||l.category==="free"||l.isLocal===!0||l.requiresApiKey===!1||l.authType==="none"||l.noAuth===!0:!1}function ke(l,n){const a=l.freeTier,k=l.models||[],w=(n==null?void 0:n.models)||[],i=new Map;for(const s of k)!s||!s.id||i.set(s.id,{id:s.id,name:s.name||s.id,contextLength:s.contextLength});for(const s of w){const c=typeof s=="string"?s:s==null?void 0:s.id;c&&(i.has(c)||i.set(c,{id:c,name:typeof s=="string"?s:s.name||c,contextLength:typeof s=="object"?s.contextLength:void 0}))}const y=[],p=new Set,C=s=>s.startsWith(`${l.id}/`)?s:`${l.id}/${s}`;if(!a){for(const[s,c]of i.entries())p.has(s)||(p.add(s),y.push({id:s,comboModelValue:C(s),name:c.name,limit:l.isLocal?"Local inference":void 0,contextLength:c.contextLength}));return y}if(Array.isArray(a.models))for(const s of a.models){if(!s||!s.id)continue;const c=s.id;if(!p.has(c)){p.add(c);const j=i.get(c);y.push({id:c,comboModelValue:C(c),name:(j==null?void 0:j.name)||c,limit:s.limit||a.note,contextLength:j==null?void 0:j.contextLength})}}if(Array.isArray(a.match)&&a.match.length>0)for(const[s,c]of i.entries()){if(p.has(s))continue;a.match.some(N=>Ce(N,s))&&(p.add(s),y.push({id:s,comboModelValue:C(s),name:c.name,limit:a.note||"Free tier",contextLength:c.contextLength}))}if(a.scope==="all")for(const[s,c]of i.entries())p.has(s)||(p.add(s),y.push({id:s,comboModelValue:C(s),name:c.name,limit:a.note,contextLength:c.contextLength}));return y}function Me(l,n,a){if(a){if(a.success)return{status:"connected",label:"Connected",detail:a.latencyMs!=null?`${a.latencyMs}ms`:void 0};const y=a.error||a.message||"Connection failed",p=/quota|rate limit|exhausted|429/i.test(y);return{status:p?"exhausted":"error",label:p?"Quota Exhausted":"Connection Error",detail:y}}if(l.isLocal)return{status:"connected",label:"Local Engine",detail:"Runs on localhost"};if(l.noAuth||l.requiresApiKey===!1||l.authType==="none")return{status:"connected",label:"Ready (Zero Config)"};const w=((n==null?void 0:n.accounts)||[]).filter(y=>y.isActive!==!1),i=(n==null?void 0:n.accountsCount)??w.length;return i>0||w.length>0?w.length>0&&w.every(p=>(p.rateLimitHits??0)>=3)?{status:"exhausted",label:"Rate Limited",detail:"Cooldown active"}:{status:"connected",label:"Connected",detail:`${i} account${i>1?"s":""}`}:{status:"not_connected",label:"Not Connected",detail:"API key required"}}function Ae(l){const[n,a]=x.useState([]),[k,w]=x.useState(new Set),[i,y]=x.useState({}),[p,C]=x.useState(!1),s=x.useCallback(async()=>{try{const g=await fetch("/api/providers");if(g.ok){const h=await g.json();Array.isArray(h)&&a(h)}}catch(g){console.error("Failed to load providers:",g)}},[]);x.useEffect(()=>{l&&s()},[l,s]);const c=x.useMemo(()=>{const g=Object.values(he).filter(m=>m.id==="combo"||m.category==="composite"?!1:Se(m)),h=new Map(n.map(m=>[m.id,m]));return g.map(m=>{var D;const T=h.get(m.id),L=m.freeTier||{scope:"all",limitType:m.isLocal?"local":"requests",note:(D=m.notice)==null?void 0:D.text},E=ke(m,T),b=i[m.id],S=Me(m,T,b);return{provider:m,freeTier:L,freeModels:E,connectionStatus:S.status,statusLabel:S.label,statusDetail:S.detail}})},[n,i]),j=async g=>{w(h=>new Set(h).add(g));try{const m=await(await fetch(`/api/providers/${encodeURIComponent(g)}/test`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({timeoutMs:7e3})})).json();y(T=>({...T,[g]:{success:!!m.success,message:m.message,latencyMs:m.latencyMs,error:m.error}}))}catch(h){y(m=>({...m,[g]:{success:!1,error:h.message||"Test failed"}}))}finally{w(h=>{const m=new Set(h);return m.delete(g),m})}};return{freeProvidersList:c,testingIds:k,isTestingAll:p,testConnection:j,testAll:async g=>{C(!0),await Promise.allSettled(g.map(h=>j(h))),C(!1)}}}const Ee=/^[a-zA-Z0-9_.-]+$/,Te=({isOpen:l,onClose:n,onSave:a,existingComboNames:k=[]})=>{const[w,i]=x.useState("free-fallback"),[y,p]=x.useState("fallback"),[C,s]=x.useState(""),[c,j]=x.useState(!1),[N,g]=x.useState(new Set),[h,m]=x.useState(!1),[T,L]=x.useState(null),{freeProvidersList:E,testingIds:b,isTestingAll:S,testConnection:D,testAll:B}=Ae(l);x.useEffect(()=>{if(l){let u="free-fallback",v=2;for(;k.includes(u);)u=`free-fallback-${v++}`;i(u),L(null)}},[l,k]),x.useEffect(()=>{if(l&&N.size===0&&E.length>0){const u=new Set;for(const v of E)if(v.connectionStatus==="connected"&&v.freeModels.length>0)for(const A of v.freeModels.slice(0,3))u.add(A.comboModelValue);u.size>0&&g(u)}},[l,E]);const $=x.useMemo(()=>{const u=C.trim().toLowerCase();return E.filter(v=>c&&v.connectionStatus!=="connected"?!1:!u||v.provider.name.toLowerCase().includes(u)||v.provider.id.toLowerCase().includes(u)?!0:v.freeModels.some(A=>A.name.toLowerCase().includes(u)||A.id.toLowerCase().includes(u)))},[E,C,c]),I=u=>{g(v=>{const A=new Set(v);return A.has(u)?A.delete(u):A.add(u),A})},_=(u,v)=>{const A=E.find(z=>z.provider.id===u);A&&g(z=>{const V=new Set(z);for(const O of A.freeModels)v?V.add(O.comboModelValue):V.delete(O.comboModelValue);return V})},R=()=>{const u=new Set;for(const v of E)if(v.connectionStatus==="connected")for(const A of v.freeModels)u.add(A.comboModelValue);g(u)},q=async u=>{u.preventDefault();const v=w.trim();if(!v)return L("Combo name is required.");if(!Ee.test(v))return L("Name can only contain letters, numbers, -, _ and .");if(N.size===0)return L("Please select at least one free model for this combo.");try{m(!0),L(null),await a({name:v,models:Array.from(N),strategy:y}),n()}catch(A){L(A.message||"Failed to create free tier combo.")}finally{m(!1)}};return e.jsxs(Z,{isOpen:l,onClose:n,maxWidthClass:"max-w-5xl",className:"max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between pb-4 border-b border-[#1E293B] shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"size-9 rounded-xl bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"savings"})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-base font-bold text-white flex items-center gap-2",children:["Create Free Tier Combo",e.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-semibold bg-emerald-500/10 text-emerald-400 border border-emerald-500/20",children:"Auto-Fallback"})]}),e.jsx("p",{className:"text-xs text-slate-400",children:"Select verified free models across providers and bundle them into a resilient free combo."})]})]}),e.jsx("button",{type:"button",onClick:n,className:"p-1 rounded-lg text-slate-400 hover:text-white hover:bg-slate-800 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"close"})})]}),e.jsxs("form",{onSubmit:q,className:"flex-1 flex flex-col min-h-0 pt-4 space-y-4",children:[e.jsx(we,{comboName:w,onComboNameChange:u=>{i(u),T&&L(null)},strategy:y,onStrategyChange:p}),e.jsx(ve,{searchQuery:C,onSearchChange:s,onlyConnected:c,onToggleOnlyConnected:()=>j(!c),onSelectConnectedOnly:R,onDeselectAll:()=>g(new Set),onTestAll:()=>B($.map(u=>u.provider.id)),isTestingAll:S}),e.jsx("div",{className:"flex-1 overflow-y-auto pr-1 space-y-2.5 min-h-[220px]",children:$.length===0?e.jsx("div",{className:"py-12 text-center text-slate-500 text-xs",children:"No matching free providers found."}):$.map(u=>e.jsx(Ne,{provider:u.provider,freeTier:u.freeTier,freeModels:u.freeModels,selectedModelValues:N,onToggleModel:I,onToggleAllProviderModels:_,connectionStatus:u.connectionStatus,statusLabel:u.statusLabel,statusDetail:u.statusDetail,onTestConnection:D,isTesting:b.has(u.provider.id),defaultExpanded:u.freeModels.some(v=>N.has(v.comboModelValue))},u.provider.id))}),T&&e.jsxs("div",{className:"p-3 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400 text-xs flex items-center gap-2 shrink-0",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"error"}),e.jsx("span",{children:T})]}),e.jsxs("div",{className:"pt-3 border-t border-[#1E293B] flex items-center justify-between gap-3 shrink-0",children:[e.jsxs("div",{className:"text-xs text-slate-400",children:["Selected: ",e.jsx("span",{className:"font-semibold text-emerald-400",children:N.size})," free model",N.size!==1?"s":""]}),e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("button",{type:"button",onClick:n,className:"px-4 py-2 rounded-xl bg-slate-800 hover:bg-slate-700 text-xs font-semibold text-slate-300 transition-colors cursor-pointer",children:"Cancel"}),e.jsxs("button",{type:"submit",disabled:h||N.size===0,className:"px-4 py-2 rounded-xl bg-emerald-600 hover:bg-emerald-500 disabled:opacity-50 text-xs font-semibold text-white shadow-lg shadow-emerald-600/20 flex items-center gap-1.5 transition-all cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:h?"hourglass_empty":"check_circle"}),e.jsx("span",{children:"Create Free Tier Combo"})]})]})]})]})]})},Le={vision:{enabled:!1,roundRobin:!1,models:[]},audioInput:{enabled:!1,roundRobin:!1,models:[]}},qe=({onSelectCombo:l})=>{const[n,a]=x.useState([]),[k,w]=x.useState(!0),[i,y]=x.useState(Le),[p,C]=x.useState(!1),[s,c]=x.useState(null),[j,N]=x.useState(""),g=x.useMemo(()=>{const t=j.trim().toLowerCase(),o=[...n].sort((f,M)=>f.name.localeCompare(M.name,void 0,{sensitivity:"base"}));return t?o.filter(f=>!!(f.name.toLowerCase().includes(t)||f.strategy.toLowerCase().includes(t)||f.models&&f.models.some(M=>M.toLowerCase().includes(t)))):o},[n,j]),[h,m]=x.useState(!1),[T,L]=x.useState(!1),[E,b]=x.useState(null),[S,D]=x.useState(null),[B,$]=x.useState(null),I=x.useCallback(async()=>{try{w(!0);const t=await fetch("/api/combos");if(t.ok){const o=await t.json();Array.isArray(o)&&a(o)}}catch(t){console.error("Failed to load combos:",t)}finally{w(!1)}},[]),_=x.useCallback(async()=>{try{const t=await fetch("/api/settings/capacity-adapter");if(t.ok){const o=await t.json();o&&typeof o=="object"&&y({vision:o.vision||{enabled:!1,roundRobin:!1,models:[]},audioInput:o.audioInput||{enabled:!1,roundRobin:!1,models:[]},pdf:o.pdf,videoInput:o.videoInput})}}catch(t){console.error("Failed to load capacity adapter settings:",t)}},[]);x.useEffect(()=>{I(),_()},[I,_]);const R=async t=>{y(t);try{C(!0),await fetch("/api/settings/capacity-adapter",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}catch(o){console.error("Failed to save capacity adapter settings:",o)}finally{C(!1)}},q=t=>{const o=i[t];R({...i,[t]:{...o,enabled:!o.enabled}})},u=(t,o)=>{const f=i[t];R({...i,[t]:{...f,roundRobin:o}})},v=(t,o)=>{const f=i[t];R({...i,[t]:{...f,models:f.models.filter(M=>M!==o)}})},A=t=>{if(!S)return;const o=i[S];R({...i,[S]:{...o,models:t}}),D(null)},z=async t=>{if(t.id){const o=await fetch(`/api/combos/${t.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t.name,models:t.models,strategy:t.strategy,isActive:t.isActive})});if(!o.ok){const f=await o.json();throw new Error(f.error||"Failed to update combo")}}else{const o=await fetch("/api/combos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t.name,models:t.models,strategy:t.strategy})});if(!o.ok){const f=await o.json();throw new Error(f.error||"Failed to create combo")}}await I(),G(),m(!1),b(null)},V=async t=>{try{const o=await fetch(`/api/combos/${t.id}/toggle`,{method:"POST"});if(o.ok){const f=await o.json();a(M=>M.map(F=>F.id===t.id?f:F)),G()}}catch(o){console.error("Error toggling combo status:",o)}},O=async(t,o)=>{try{const f=await fetch(`/api/combos/${t.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({strategy:o})});if(f.ok){const M=await f.json();a(F=>F.map(P=>P.id===t.id?M:P)),G()}}catch(f){console.error("Error updating strategy:",f)}},d=t=>{$({title:"Delete Combo",message:`Are you sure you want to delete combo "${t.name}"? This action cannot be undone.`,confirmText:"Delete Combo",variant:"danger",onConfirm:async()=>{try{(await fetch(`/api/combos/${t.id}`,{method:"DELETE"})).ok&&(a(f=>f.filter(M=>M.id!==t.id)),G())}catch(o){console.error("Error deleting combo:",o)}finally{$(null)}}})},r=(t,o)=>{navigator.clipboard.writeText(t),c(o),setTimeout(()=>c(null),2e3)};return e.jsxs("div",{className:"space-y-8 w-full pb-16 animate-rt-fade-in",children:[e.jsxs("div",{className:"w-full p-5 rounded-2xl bg-[#0F1420]/80 border border-[#1E293B] space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[20px]",children:"hub"}),e.jsx("span",{className:"font-bold text-sm text-slate-100",children:"Smart Model Combos & Routing Strategies"})]}),e.jsxs("div",{className:"flex items-center gap-2.5 shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>L(!0),className:"px-4 py-2 rounded-xl bg-emerald-600 hover:bg-emerald-500 shadow-lg shadow-emerald-600/20 text-xs font-semibold text-white flex items-center gap-1.5 transition-all cursor-pointer shrink-0",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"savings"}),"Create Free Tier Combo"]}),e.jsxs("button",{type:"button",onClick:()=>{b(null),m(!0)},className:"px-4 py-2 rounded-xl bg-blue-600 hover:bg-blue-500 shadow-lg shadow-blue-600/20 text-xs font-semibold text-white flex items-center gap-1.5 transition-all cursor-pointer shrink-0",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"add_circle"}),"Create Combo"]})]})]}),e.jsx("p",{className:"text-xs text-slate-300 leading-relaxed",children:"Group multiple models and provider accounts under a single unified alias. Mapigate automatically manages fallbacks, load balances requests, or fuses multiple outputs together."}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 xl:grid-cols-5 gap-2.5 pt-1 text-[11px]",children:[e.jsxs("div",{className:"p-3 rounded-xl bg-[#0A0D14] border border-[#1E293B] space-y-1",children:[e.jsxs("span",{className:"text-blue-400 font-bold flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"low_priority"}),"Fallback Strategy"]}),e.jsx("p",{className:"text-slate-400",children:"Tries models in order; moves to backup on 429, 503, or quota limits."})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-[#0A0D14] border border-[#1E293B] space-y-1",children:[e.jsxs("span",{className:"text-cyan-400 font-bold flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"sync"}),"Round Robin Strategy"]}),e.jsx("p",{className:"text-slate-400",children:"Spreads requests sequentially across accounts to maximize throughput."})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-[#0A0D14] border border-[#1E293B] space-y-1",children:[e.jsxs("span",{className:"text-indigo-400 font-bold flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"call_split"}),"Fusion Strategy"]}),e.jsx("p",{className:"text-slate-400",children:"Queries models in parallel and synthesizes the best answer with a judge."})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-[#0A0D14] border border-[#1E293B] space-y-1",children:[e.jsxs("span",{className:"text-emerald-400 font-bold flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"verified"}),"LKGP Strategy"]}),e.jsx("p",{className:"text-slate-400",children:"Sticks to last known good model for prompt cache warmth; fails over on error."})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-[#0A0D14] border border-[#1E293B] space-y-1",children:[e.jsxs("span",{className:"text-amber-400 font-bold flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"balance"}),"P2C Strategy"]}),e.jsx("p",{className:"text-slate-400",children:"Samples 2 random models and picks the higher-scoring via EMA latency/error rate."})]})]})]}),e.jsxs("div",{className:"w-full space-y-3.5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 px-1 text-xs text-slate-400",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[18px]",children:"layers"}),e.jsxs("span",{className:"font-bold text-white text-sm",children:["Configured Combos (",j?`${g.length} of ${n.length}`:n.length,")"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"material-symbols-outlined absolute left-2.5 top-1/2 -translate-y-1/2 text-slate-500 text-[16px]",children:"search"}),e.jsx("input",{type:"text",value:j,onChange:t=>N(t.target.value),placeholder:"Filter combos by name or model...",className:"pl-8 pr-7 py-1 text-xs bg-[#0F1420] border border-[#1E293B] rounded-xl text-white placeholder-slate-500 focus:outline-none focus:border-blue-500/50 w-52 sm:w-64 transition-all"}),j&&e.jsx("button",{type:"button",onClick:()=>N(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-slate-500 hover:text-white text-xs",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),e.jsx("span",{className:"text-[11px] text-slate-500 hidden sm:inline",children:"Backed by SQLite"})]})]}),k?e.jsxs("div",{className:"w-full py-16 text-center text-slate-400 flex flex-col items-center justify-center gap-3 bg-[#0F1420]/40 rounded-2xl border border-[#1E293B]",children:[e.jsx("span",{className:"material-symbols-outlined text-3xl text-blue-400 animate-spin",children:"progress_activity"}),e.jsx("span",{className:"text-xs",children:"Loading combos from database..."})]}):n.length===0?e.jsxs("div",{className:"w-full py-16 text-center text-slate-400 flex flex-col items-center justify-center gap-3 bg-[#0F1420]/40 rounded-2xl border border-[#1E293B]",children:[e.jsx("span",{className:"material-symbols-outlined text-3xl text-slate-600",children:"layers_clear"}),e.jsx("p",{className:"text-sm font-semibold text-slate-300",children:"No combos configured in SQLite database yet"}),e.jsx("p",{className:"text-xs text-slate-500 max-w-md",children:"Click “Create Combo” to build your first multi-model cluster (e.g. combo/smart-coding). Tool-specific model aliases (sonnet, default...) are configured in the CLI Tools tab."})]}):g.length===0?e.jsxs("div",{className:"w-full py-12 text-center text-slate-400 flex flex-col items-center justify-center gap-2 bg-[#0F1420]/40 rounded-2xl border border-[#1E293B]",children:[e.jsx("span",{className:"material-symbols-outlined text-3xl text-slate-600",children:"search_off"}),e.jsxs("p",{className:"text-xs font-semibold text-slate-300",children:["No combos match “",j,"”"]}),e.jsx("button",{onClick:()=>N(""),className:"text-xs text-blue-400 hover:underline cursor-pointer",children:"Clear filter"})]}):e.jsx("div",{className:"w-full space-y-2.5",children:g.map((t,o)=>{const f=pe(t.models),M=t.isActive!==!1;return e.jsxs("div",{className:`w-full flex flex-wrap items-center justify-between gap-4 py-3.5 px-5 rounded-2xl border transition-all ${M?"bg-[#0F1420]/80 border-[#1E293B] hover:border-slate-700":"bg-[#0A0D14]/50 border-[#1E293B]/50 opacity-60"}`,style:{animationDelay:`${o*30}ms`},children:[e.jsxs("div",{className:"flex items-start sm:items-center gap-3.5 min-w-0 flex-1",children:[e.jsx("div",{className:`size-9 rounded-xl flex items-center justify-center shrink-0 border ${t.strategy==="fallback"?"bg-blue-500/10 text-blue-400 border-blue-500/20":t.strategy==="round-robin"?"bg-cyan-500/10 text-cyan-400 border-cyan-500/20":t.strategy==="fusion"?"bg-indigo-500/10 text-indigo-400 border-indigo-500/20":t.strategy==="lkgp"?"bg-emerald-500/10 text-emerald-400 border-emerald-500/20":"bg-amber-500/10 text-amber-400 border-amber-500/20"}`,children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:t.strategy==="fallback"?"low_priority":t.strategy==="round-robin"?"sync":t.strategy==="fusion"?"call_split":t.strategy==="lkgp"?"verified":"balance"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("button",{type:"button",onClick:()=>l?l(t):(b(t),m(!0)),className:"text-xs font-bold text-white font-mono hover:text-blue-400 cursor-pointer transition-colors text-left",title:"Open combo details & manage models",children:t.name}),f&&e.jsx(Y,{caps:f,size:"xs"}),(()=>{const F=new Set(t.models.map(P=>P.split("/")[0].replace(/\(.*?\)/,"").trim())).size;return e.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-[#161F30] border border-[#26354D] text-[10px] text-slate-400 font-medium",children:[t.models.length," ",t.models.length===1?"model":"models",F>0&&` · ${F} ${F===1?"provider":"providers"}`]})})(),!M&&e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-slate-800 text-slate-400 text-[10px] uppercase font-bold",children:"Disabled"})]}),(()=>{const P=j.trim().toLowerCase(),U=P?t.models.filter(K=>K.toLowerCase().includes(P)):[],W=P&&U.length>0?U.slice(0,4):t.models.slice(0,4),J=t.models.length-W.length;return e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-1.5",children:[W.map((K,te)=>{const se=t.models.indexOf(K);return e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-lg bg-[#0A0D14] border border-[#1E293B] text-[11px] text-slate-300 font-mono",children:[e.jsx("span",{className:"text-[10px] text-blue-400 font-bold",children:se+1}),e.jsx("span",{className:"truncate max-w-[220px] sm:max-w-none",children:K})]},te)}),J>0&&e.jsxs("button",{type:"button",onClick:K=>{K.stopPropagation(),l?l(t):(b(t),m(!0))},className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-lg bg-blue-500/10 hover:bg-blue-500/20 text-[11px] text-blue-400 font-semibold border border-blue-500/25 transition-colors cursor-pointer",title:`Click to view and manage all ${t.models.length} models`,children:[e.jsxs("span",{children:["+",J," more"]}),e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"arrow_forward"})]})]})})()]})]}),e.jsxs("div",{className:"flex items-center gap-2.5 shrink-0",children:[e.jsx(Q,{value:t.strategy,onChange:F=>O(t,F),options:[{value:"round-robin",label:"Round Robin (rotate)"},{value:"fallback",label:"Fallback (try in order)"},{value:"fusion",label:"Fusion (parallel panel)"},{value:"lkgp",label:"LKGP (Last Known Good)"},{value:"p2c",label:"P2C (Power of Two Choices)"}],className:"min-w-[180px]"}),e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",title:M?"Disable combo":"Enable combo",children:[e.jsx("input",{type:"checkbox",checked:M,onChange:()=>V(t),className:"sr-only peer"}),e.jsx("div",{className:"w-9 h-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 after:w-4 after:transition-all peer-checked:bg-blue-600"})]}),e.jsxs("div",{className:"flex items-center gap-1 text-slate-400 border-l border-[#1E293B] pl-2",children:[e.jsx("button",{type:"button",title:"Manage models & details",onClick:()=>{l?l(t):(b(t),m(!0))},className:"p-1.5 rounded-lg hover:bg-blue-500/10 hover:text-blue-400 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"tune"})}),e.jsx("button",{type:"button",title:s===t.id?"Copied to clipboard!":"Copy combo identifier",onClick:()=>r(t.name,t.id),className:`p-1.5 rounded-lg transition-colors cursor-pointer ${s===t.id?"bg-emerald-500/20 text-emerald-400":"hover:bg-white/10 hover:text-white"}`,children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:s===t.id?"check":"content_copy"})}),e.jsx("button",{type:"button",title:"Edit combo",onClick:()=>{b(t),m(!0)},className:"p-1.5 rounded-lg hover:bg-white/10 hover:text-white transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"edit"})}),e.jsx("button",{type:"button",title:"Delete combo",onClick:()=>d(t),className:"p-1.5 rounded-lg hover:bg-rose-500/10 hover:text-rose-400 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"delete"})})]})]})]},t.id)})})]}),e.jsxs("div",{className:"w-full space-y-4 pt-6 border-t border-[#1E293B]",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2",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-cyan-400 text-[20px]",children:"visibility"}),"Multimodal Capacity Adapter"]}),e.jsx("p",{className:"text-xs text-slate-400 mt-0.5",children:"When client coding tools send image or audio prompts to models lacking those modalities, Mapigate seamlessly elevates designated adapter models to priority #1."})]}),p&&e.jsxs("span",{className:"text-[11px] text-blue-400 flex items-center gap-1 font-mono",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] animate-spin",children:"progress_activity"}),"Syncing settings..."]})]}),e.jsxs("div",{className:"w-full grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"w-full p-5 rounded-2xl bg-[#0F1420]/80 border border-[#1E293B] flex flex-col justify-between gap-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-9 rounded-xl bg-cyan-500/10 border border-cyan-500/20 text-cyan-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"image"})}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-xs font-bold text-white flex items-center gap-2",children:["Vision Input Adapter",e.jsx("span",{className:"px-1.5 py-0.2 rounded text-[10px] bg-cyan-500/10 text-cyan-400 border border-cyan-500/20",children:"Images & Screenshots"})]}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"Auto-reroutes image payloads (png, jpg, webp, base64)"})]})]}),e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:i.vision.enabled,onChange:()=>q("vision"),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-cyan-600"})]})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs pt-1",children:[e.jsx("span",{className:"text-slate-400",children:"Adapter Pool Strategy:"}),e.jsx(Q,{value:i.vision.roundRobin?"round-robin":"fallback",onChange:t=>u("vision",t==="round-robin"),options:[{value:"fallback",label:"Fallback (try in order)"},{value:"round-robin",label:"Round Robin (rotate)"}],className:"min-w-[170px]"})]})]}),e.jsxs("div",{className:"space-y-2 pt-2 border-t border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center justify-between text-[11px]",children:[e.jsxs("span",{className:"text-slate-400 font-semibold",children:["Vision Model Pool (",i.vision.models.length,")"]}),e.jsxs("button",{type:"button",onClick:()=>D("vision"),className:"px-2.5 py-1 rounded-lg bg-cyan-600/10 border border-cyan-500/30 text-cyan-400 hover:bg-cyan-600/20 font-medium flex items-center gap-1 transition-colors cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"add"}),"Manage Models"]})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 min-h-[38px] p-2 rounded-xl bg-[#0A0D14] border border-[#1E293B]",children:i.vision.models.length===0?e.jsx("span",{className:"text-[11px] text-slate-500 italic",children:"No models in vision pool. Click Manage Models to add."}):i.vision.models.map(t=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-lg bg-[#141B2D] border border-cyan-500/20 text-[11px] text-cyan-300 font-mono",children:[e.jsx("span",{className:"size-1.5 rounded-full bg-cyan-400"}),e.jsx("span",{children:t}),e.jsx("button",{type:"button",onClick:()=>v("vision",t),className:"text-slate-500 hover:text-rose-400 cursor-pointer ml-0.5",title:"Remove model from pool",children:e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"close"})})]},t))})]})]}),e.jsxs("div",{className:"w-full p-5 rounded-2xl bg-[#0F1420]/80 border border-[#1E293B] flex flex-col justify-between gap-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-9 rounded-xl bg-purple-500/10 border border-purple-500/20 text-purple-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"graphic_eq"})}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-xs font-bold text-white flex items-center gap-2",children:["Audio Input Adapter",e.jsx("span",{className:"px-1.5 py-0.2 rounded text-[10px] bg-purple-500/10 text-purple-400 border border-purple-500/20",children:"Speech & Voice"})]}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"Auto-reroutes speech and audio inputs to audio-capable models"})]})]}),e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:i.audioInput.enabled,onChange:()=>q("audioInput"),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-purple-600"})]})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs pt-1",children:[e.jsx("span",{className:"text-slate-400",children:"Adapter Pool Strategy:"}),e.jsx(Q,{value:i.audioInput.roundRobin?"round-robin":"fallback",onChange:t=>u("audioInput",t==="round-robin"),options:[{value:"fallback",label:"Fallback (try in order)"},{value:"round-robin",label:"Round Robin (rotate)"}],className:"min-w-[170px]"})]})]}),e.jsxs("div",{className:"space-y-2 pt-2 border-t border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center justify-between text-[11px]",children:[e.jsxs("span",{className:"text-slate-400 font-semibold",children:["Audio Model Pool (",i.audioInput.models.length,")"]}),e.jsxs("button",{type:"button",onClick:()=>D("audioInput"),className:"px-2.5 py-1 rounded-lg bg-purple-600/10 border border-purple-500/30 text-purple-400 hover:bg-purple-600/20 font-medium flex items-center gap-1 transition-colors cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"add"}),"Manage Models"]})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 min-h-[38px] p-2 rounded-xl bg-[#0A0D14] border border-[#1E293B]",children:i.audioInput.models.length===0?e.jsx("span",{className:"text-[11px] text-slate-500 italic",children:"No models in audio pool. Click Manage Models to add."}):i.audioInput.models.map(t=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-lg bg-[#141B2D] border border-purple-500/20 text-[11px] text-purple-300 font-mono",children:[e.jsx("span",{className:"size-1.5 rounded-full bg-purple-400"}),e.jsx("span",{children:t}),e.jsx("button",{type:"button",onClick:()=>v("audioInput",t),className:"text-slate-500 hover:text-rose-400 cursor-pointer ml-0.5",title:"Remove model from pool",children:e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"close"})})]},t))})]})]})]})]}),e.jsx(je,{isOpen:h,onClose:()=>{m(!1),b(null)},combo:E,onSave:z}),e.jsx(Te,{isOpen:T,onClose:()=>L(!1),onSave:async t=>{await z({...t,isActive:!0})},existingComboNames:n.map(t=>t.name)}),S&&e.jsx(ee,{isOpen:S!==null,onClose:()=>D(null),title:`Configure ${S==="vision"?"Vision":"Audio"} Adapter Model Pool`,initialSelectedModels:i[S].models,onConfirm:A,filterModality:S==="vision"?"vision":"audio",multiSelect:!0}),B&&e.jsx(fe,{isOpen:B!==null,title:B.title,message:B.message,confirmText:B.confirmText||"Confirm",variant:B.variant||"primary",onConfirm:B.onConfirm,onCancel:()=>$(null)})]})};export{qe as CombosTab};
|
|
@@ -1,6 +0,0 @@
|
|
|
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-BZE0Fv7L.js";import{u as ue,D as be,d as he,a as Be,c as Re,A as Oe}from"./index-Di7mCTbW.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
|
-
-H "Content-Type: application/json" \\
|
|
3
|
-
-H "Authorization: Bearer [REDACTED]" \\
|
|
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(`
|
|
5
|
-
`):$.map(x=>x.rawText).join(`
|
|
6
|
-
`);if(r)try{await navigator.clipboard.writeText(r),q(!0),setTimeout(()=>q(!1),2e3)}catch{}},Z=r=>{P(r),G(!0)};return e.jsxs("div",{className:"w-full px-2 sm:px-4 space-y-3 animate-rt-fade-in flex flex-col h-[calc(100vh-140px)] min-h-[500px]",children:[e.jsx(Ie,{connected:w,totalCount:p==="raw"?t.length:n.length,filteredCount:p==="raw"?y.length:$.length,viewMode:p,onViewModeChange:C,categoryTab:i,onCategoryTabChange:g,searchQuery:a,onSearchQueryChange:E,clientToolFilter:j,onClientToolFilterChange:T,providerFilter:N,onProviderFilterChange:l,statusFilter:k,onStatusFilterChange:z,levelFilter:S,onLevelFilterChange:L,gatewayLogLevel:_,onGatewayLogLevelChange:Y,observabilityMode:U,onObservabilityModeChange:v,autoScroll:u,onAutoScrollToggle:()=>b(r=>!r),onCopy:te,copied:J,onClear:O,availableTools:H,availableProviders:m}),p==="raw"?e.jsx(Fe,{logs:y,filterText:a,scrollRef:R}):e.jsx("div",{ref:R,className:"flex-1 overflow-y-auto space-y-2 pr-1 select-text min-h-0",children:$.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 border border-[#1E293B] rounded-xl bg-[#05070B]",children:[e.jsx(ee,{className:"size-8 text-slate-600"}),e.jsx("p",{className:"text-xs",children:a.trim()||j!=="all"||N!=="all"?"No structured logs match the current filters.":"No structured logs yet. Proxy and system events will appear here."}),e.jsxs("span",{className:"text-[10px] text-slate-600 font-mono",children:["Listening on ",Re,"/api/console-logs/stream"]})]}):$.map(r=>e.jsx(De,{entry:r,onClick:()=>Z(r),isSelected:(D==null?void 0:D.id)===r.id&&F},r.id))}),e.jsx(Ge,{entry:D,isOpen:F,onClose:()=>G(!1)})]})};export{Ze as ConsoleLogTab};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{R as ue,r as o,j as e}from"./vendor-BcOI2aZ9.js";import{P as xe}from"./index-Di7mCTbW.js";import{T as pe}from"./ToolIcon-BZE0Fv7L.js";import{S as me}from"./Select-BNRH8LIG.js";import{g as be}from"./metadataRegistry-EMxpq0lK.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-xl",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 +0,0 @@
|
|
|
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-DCYNsbhd.js";import{u as ee,D as m,d as te,P as ve}from"./index-Di7mCTbW.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-xl",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};
|