mapigate 0.5.136 → 0.5.146
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 +8 -8
- package/dist/cli/commands/logs.js +0 -1
- package/dist/core/adapters/anthropic/requestOpenAiToAnthropic.js +1 -1
- package/dist/core/adapters/helpers/toolCallRescue.js +1 -1
- package/dist/core/adapters/responsesAdapter.js +11 -0
- package/dist/core/capabilities/index.js +5 -4
- package/dist/core/capabilities/modelDictionary.js +1 -0
- package/dist/core/scanner/modelScanner.js +2 -1
- package/dist/core/scanner/payloadExtractor.js +1 -1
- package/dist/core/scanner/urlResolver.js +16 -0
- package/dist/core/tokenSaver/methods/rtk/autodetect.js +1 -1
- package/dist/core/tokenSaver/methods/rtk/filters/gitLog.js +1 -1
- package/dist/core/usage/pricing.js +98 -42
- package/dist/core/usage/tokenExtractor.js +59 -0
- package/dist/mitm/handlers/antigravity/config.js +22 -0
- package/dist/mitm/handlers/antigravity/modelInjector.js +2 -2
- package/dist/providers/catalog/coarena/index.js +3 -0
- package/dist/providers/catalog/coarena/metadata.js +104 -0
- package/dist/providers/catalog/coarena/provider.js +91 -0
- package/dist/providers/catalog/coarena/quota.js +119 -0
- package/dist/providers/catalog/iflow/provider.js +1 -1
- package/dist/providers/catalog/iteracompute/metadata.js +154 -13
- package/dist/providers/catalog/iteracompute/provider.js +111 -0
- package/dist/providers/catalog/opencode-go/responsesPayload.js +1 -1
- package/dist/providers/catalog/openrouter/metadata.js +1 -0
- package/dist/providers/core/base/baseProvider.js +5 -3
- package/dist/providers/generated/chunks/chunk1.js +2 -2
- package/dist/providers/generated/chunks/chunk2.js +2 -2
- package/dist/providers/generated/chunks/chunk3.js +2 -2
- package/dist/providers/generated/chunks/chunk4.js +2 -0
- package/dist/providers/generated/runtime/chunk1.js +2 -2
- package/dist/providers/generated/runtime/chunk2.js +2 -2
- package/dist/providers/generated/runtime/chunk3.js +2 -2
- package/dist/providers/generated/runtime/chunk4.js +2 -0
- package/dist/providers/runtime/antigravity/executor.js +2 -2
- package/dist/providers/runtime/antigravity/metadata.js +2 -2
- package/dist/providers/runtime/antigravity/models.js +9 -0
- package/dist/providers/runtime/antigravity/provider.js +2 -2
- package/dist/providers/runtime/antigravity/routes.js +2 -2
- package/dist/providers/runtime/antigravity/schema.js +1 -1
- package/dist/providers/runtime/antigravity/types.js +10 -2
- package/dist/providers/runtime/gemini/provider.js +77 -0
- package/dist/providers/runtime/gemini-cli/provider.js +2 -2
- package/dist/providers/runtime/github/routes.js +1 -1
- package/dist/providers/runtime/grok/provider.js +1 -1
- package/dist/providers/runtime/kiro/provider.js +1 -1
- package/dist/providers/runtime/minimax/routes.js +0 -1
- package/dist/providers/runtime/opencode/tools.js +1 -1
- package/dist/providers/runtime/trae/index.js +1 -0
- package/dist/providers/runtime/trae/metadata.js +1 -0
- package/dist/providers/runtime/trae/provider.js +7 -0
- package/dist/providers/runtime/trae/quota.js +99 -0
- package/dist/providers/runtime/windsurf/routes.js +0 -2
- package/dist/providers/runtime/xkiro/quota.js +4 -1
- package/dist/providers/runtime/zed/metadata.js +1 -1
- package/dist/providers/runtime/zed/models.js +68 -8
- package/dist/providers/runtime/zed/provider.js +60 -15
- package/dist/providers/runtime/zed/quota.js +69 -12
- package/dist/providers/runtime/zed/routes.js +7 -0
- package/dist/server/proxy/executorHelpers.js +1 -1
- package/dist/server/proxy/index.js +1 -1
- package/dist/server/proxy/pipeline.js +12 -6
- package/dist/server/proxy/responseHandlers.js +2 -18
- package/dist/server/proxy/singleModelExecutor.js +1 -1
- package/dist/server/proxy/streaming/sseStreamer.js +3 -10
- package/dist/server/routes/apiMitm.js +1 -1
- package/dist/server/routes/apiModels.js +17 -12
- package/dist/server/utils/consoleLogBuffer.js +3 -3
- package/dist/shared/constants/index.js +2 -2
- package/dist/shared/constants/quotaOrder.js +5 -0
- package/dist/shared/logger.js +2 -2
- package/dist/storage/repositories/logRepo.js +3 -23
- package/dist/storage/repositories/requestDetailsRepo.js +1 -1
- package/dist/storage/repositories/usageRepo.js +136 -74
- package/dist/web/assets/{CliToolsTab-CkzwuwaC.js → CliToolsTab-BYO-wJ7y.js} +1 -1
- package/dist/web/assets/CombosTab-CujUAbYQ.js +1 -0
- package/dist/web/assets/{ConfirmModal-DGvcf0gB.js → ConfirmModal-BS3mAUd5.js} +1 -1
- package/dist/web/assets/{ConsoleLogTab-84Ens8T5.js → ConsoleLogTab-CSgZxPGW.js} +1 -1
- package/dist/web/assets/{EditAccountModal-D-_omvev.js → EditAccountModal-BhPOk3Ya.js} +1 -1
- package/dist/web/assets/{EndpointTab-7nBfEdYE.js → EndpointTab-BRVjAng2.js} +1 -1
- package/dist/web/assets/{MitmTab-CqS6mXHZ.js → MitmTab-ZOoWyRnb.js} +5 -5
- package/dist/web/assets/{ModelAutocompleteInput-B9syrV1O.js → ModelAutocompleteInput-DJkxW2yD.js} +1 -1
- package/dist/web/assets/{ProviderDetailPage-DGZceQ2d.js → ProviderDetailPage-CnWjM-0J.js} +2 -2
- package/dist/web/assets/ProvidersTab-BFdg0gXr.js +1 -0
- package/dist/web/assets/QuotaTab-DXg3adeS.js +1 -0
- package/dist/web/assets/{SettingsTab-4c0ksNJa.js → SettingsTab-DoYGKtDn.js} +1 -1
- package/dist/web/assets/UsageTab-O6OK0i38.js +1 -0
- package/dist/web/assets/index-5TzViNxR.js +2 -0
- package/dist/web/assets/metadataRegistry-W75_wn57.js +1 -0
- package/dist/web/assets/providers/coarena/icon.png +0 -0
- package/dist/web/assets/providers/coarena/icon.svg +3 -0
- package/dist/web/assets/providers/openrouter/icon.png +0 -0
- package/dist/web/assets/{providersData-DkVCRBsJ.js → providersData-BI_7MaUL.js} +1 -1
- package/dist/web/index.html +1 -1
- package/package.json +9 -1
- package/dist/web/assets/CombosTab-C5RzRwwr.js +0 -1
- package/dist/web/assets/ProvidersTab-CiYbqRou.js +0 -1
- package/dist/web/assets/QuotaTab-DFr0DWAU.js +0 -1
- package/dist/web/assets/UsageTab-BQcPmvtQ.js +0 -1
- package/dist/web/assets/index-C4NTQZ40.js +0 -2
- package/dist/web/assets/metadataRegistry-B91sal4r.js +0 -1
- package/dist/web/assets/providers/openrouter/openrouter.png +0 -0
|
Binary file
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path d="M29.355 11.8A14 14 0 1 0 29.355 20.2L24.521 20.2A9.5 9.5 0 1 1 24.521 11.8ZM14.8 9.2h2.4a1.4 1.4 0 0 1 1.4 1.4v2.4a1.4 1.4 0 0 1-1.4 1.4h-2.4a1.4 1.4 0 0 1-1.4-1.4v-2.4a1.4 1.4 0 0 1 1.4-1.4ZM14.8 17.6h2.4a1.4 1.4 0 0 1 1.4 1.4v2.4a1.4 1.4 0 0 1-1.4 1.4h-2.4a1.4 1.4 0 0 1-1.4-1.4v-2.4a1.4 1.4 0 0 1 1.4-1.4Z" fill="#18181B"/>
|
|
3
|
+
</svg>
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{P as n}from"./metadataRegistry-
|
|
1
|
+
import{P as n}from"./metadataRegistry-W75_wn57.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,7 +8,7 @@
|
|
|
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-5TzViNxR.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
14
|
<link rel="stylesheet" crossorigin href="/assets/index-HnsyZg0I.css">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mapigate",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.146",
|
|
4
4
|
"description": "AI Model API Gateway & Token Optimizer for coding tools",
|
|
5
5
|
"author": "Giao Ho",
|
|
6
6
|
"main": "dist/server/index.js",
|
|
@@ -33,6 +33,8 @@
|
|
|
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
35
|
"typecheck": "tsc --noEmit",
|
|
36
|
+
"lint": "eslint .",
|
|
37
|
+
"lint:fix": "eslint . --fix",
|
|
36
38
|
"bump": "npm version patch --no-git-tag-version && npm install",
|
|
37
39
|
"bump:patch": "npm version patch --no-git-tag-version && npm install",
|
|
38
40
|
"bump:minor": "npm version minor --no-git-tag-version && npm install",
|
|
@@ -63,6 +65,7 @@
|
|
|
63
65
|
"better-sqlite3": "^13.0.3"
|
|
64
66
|
},
|
|
65
67
|
"devDependencies": {
|
|
68
|
+
"@eslint/js": "^10.0.1",
|
|
66
69
|
"@tailwindcss/vite": "^4.3.3",
|
|
67
70
|
"@types/cors": "^2.8.17",
|
|
68
71
|
"@types/express": "^5.0.0",
|
|
@@ -73,6 +76,10 @@
|
|
|
73
76
|
"@vitejs/plugin-react": "^4.3.4",
|
|
74
77
|
"concurrently": "^9.1.2",
|
|
75
78
|
"cross-env": "^7.0.3",
|
|
79
|
+
"eslint": "^10.14.0",
|
|
80
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
81
|
+
"eslint-plugin-react-refresh": "^0.5.7",
|
|
82
|
+
"globals": "^17.14.0",
|
|
76
83
|
"lucide-react": "^0.475.0",
|
|
77
84
|
"react": "^19.0.0",
|
|
78
85
|
"react-dom": "^19.0.0",
|
|
@@ -81,6 +88,7 @@
|
|
|
81
88
|
"tailwindcss": "^4.3.3",
|
|
82
89
|
"tsx": "^4.19.3",
|
|
83
90
|
"typescript": "^5.7.3",
|
|
91
|
+
"typescript-eslint": "^8.72.2",
|
|
84
92
|
"vite": "^6.1.0",
|
|
85
93
|
"zustand": "^5.0.3"
|
|
86
94
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as i,j as e}from"./vendor-BcOI2aZ9.js";import{u as he,a as ce,D as be,c as fe,S as ge,v as ye,b as ve,s as je,K as Ne,P as we,d as Ce,C as ke}from"./dnd-kit-DecqzwfZ.js";import{P as Se}from"./index-C4NTQZ40.js";import{o as ze,g as de,a as pe,C as oe,b as Oe,M as Ee,i as le}from"./ModelAutocompleteInput-B9syrV1O.js";import{T as qe}from"./ToolIcon-Cp4gSgFt.js";import{S as ne}from"./Select-BNRH8LIG.js";import{P as me}from"./metadataRegistry-B91sal4r.js";import{C as Ge}from"./ConfirmModal-DGvcf0gB.js";import"./lucide-Cc35htxl.js";function Ke(c){return!c||c<=0?null:c>=1e6?`${(c/1e6).toFixed(c%1e6===0?0:1)}M ctx`:c>=1e3?`${Math.round(c/1e3)}K ctx`:`${c} ctx`}const Ve=({id:c,index:g,onRemove:m,onMoveUp:q,onMoveDown:u,isFirst:D,isLast:T})=>{const{attributes:E,listeners:B,setNodeRef:h,transform:j,transition:I,isDragging:w}=Ce({id:c}),L={transform:ke.Transform.toString(j),transition:I,zIndex:w?50:void 0,opacity:w?.6:1};return e.jsxs("div",{ref:h,style:L,className:`flex items-center justify-between gap-2 px-3 py-2 rounded-xl border bg-[#0A0D14] transition-all ${w?"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",...E,...B,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:g+1}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"font-mono text-xs text-white truncate block",title:c,children:c}),e.jsx(oe,{model:c,size:"xs",className:"mt-1"})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{type:"button",onClick:q,disabled:D,className:"p-1 text-slate-400 hover:text-white disabled:opacity-20 disabled:hover:text-slate-400 cursor-pointer",title:"Move up",children:e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"arrow_upward"})}),e.jsx("button",{type:"button",onClick:u,disabled:T,className:"p-1 text-slate-400 hover:text-white disabled:opacity-20 disabled:hover:text-slate-400 cursor-pointer",title:"Move down",children:e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"arrow_downward"})}),e.jsx("button",{type:"button",onClick:m,className:"p-1 text-slate-400 hover:text-rose-400 cursor-pointer",title:"Remove",children:e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"close"})})]})]})},Ae=({isOpen:c,onClose:g,title:m="Select & Reorder Models",initialSelectedModels:q=[],onConfirm:u,multiSelect:D=!0,filterModality:T=null,onSelect:E,onDeselect:B,selectedModel:h,activeProviders:j=[],modelAliases:I={},kindFilter:w=null,capFilter:L=null,addedModelValues:S,closeOnSelect:V=!1,excludeModelIds:_,allowCombos:A=!0})=>{const[p,f]=i.useState([]),[C,F]=i.useState(""),[v,G]=i.useState("all"),[P,z]=i.useState(L||T||"all"),[Q,J]=i.useState(""),[U,X]=i.useState([]),[W,se]=i.useState([]),[R,a]=i.useState(!0),s=i.useRef(null),r=he(ce(we,{activationConstraint:{distance:4}}),ce(Ne,{coordinateGetter:je}));i.useEffect(()=>{if(c){f([...S||q||[]]),F(""),G("all"),z(L||T||"all"),J("");const l=setTimeout(()=>{var n;(n=s.current)==null||n.focus()},50);return()=>clearTimeout(l)}},[c,q,S,T,L]),i.useEffect(()=>{if(!c)return;let t=!1;return fetch("/api/combos").then(l=>l.ok?l.json():[]).then(l=>{if(!t){const n=Array.isArray(l)?l:l.combos||[];X(n)}}).catch(()=>{t||X([])}),()=>{t=!0}},[c]),i.useEffect(()=>{if(!c)return;let t=!1;const l=()=>{Oe().then(o=>{if(!t){se(o);const x=o.some(b=>b.hasConnectedAccount);a(x)}}).catch(()=>{})};l();const n=ze(()=>{t||l()});return()=>{t=!0,n()}},[c]);const d=i.useMemo(()=>{const t=new Set;for(const l of W)l.hasConnectedAccount&&t.add(l.providerId);return t},[W]),N=i.useMemo(()=>d.size>0,[d]),M=i.useMemo(()=>{var o,x,b,ie;const t=[],l=new Set,n=new Set;for(const y of W){if(y.isCombo||l.has(y.value))continue;l.add(y.value),n.add(y.providerId);const k=de(y.providerId,y.id);t.push({id:y.id,value:y.value,name:y.name||y.id,providerId:y.providerId,providerName:y.providerName||y.providerId,caps:{...k,vision:!!(((o=y.caps)==null?void 0:o.vision)??k.vision),reasoning:!!(((x=y.caps)==null?void 0:x.reasoning)??k.reasoning),audioInput:!!(((b=y.caps)==null?void 0:b.audio)??k.audioInput),audioOutput:!!(((ie=y.caps)==null?void 0:ie.audio)??k.audioOutput)},contextLength:y.contextLength||k.contextWindow,kind:"llm",isCustom:!1})}for(const[y,k]of Object.entries(me)){if(!k||!k.models)continue;const H=k.alias||k.id||y;if(!(n.has(y)||n.has(H)||k.aliases&&k.aliases.some($=>n.has($))))for(const $ of k.models){const te=$.id.includes("/")?$.id:`${H}/${$.id}`;if(l.has(te))continue;l.add(te);const re=de(y,$.id);t.push({id:$.id,value:te,name:$.name||$.id,providerId:y,providerName:k.name||y,caps:re,contextLength:$.contextLength,kind:$.kind||"llm",isCustom:!1})}}for(const[y,k]of Object.entries(I))if(!l.has(k)){l.add(k);const H=k.indexOf("/"),$=H===-1?"custom":k.slice(0,H),te=H===-1?k:k.slice(H+1),re=me[$],Fe=de($,te);t.push({id:te,value:k,name:y,providerId:$,providerName:(re==null?void 0:re.name)||$,caps:Fe,isCustom:!0})}return t},[W,I]),O=i.useMemo(()=>new Set((_||[]).map(t=>t.toLowerCase())),[_]),ae=i.useMemo(()=>{const t=new Map,l=A!==!1&&U.length>0;for(const o of M)R&&N&&!d.has(o.providerId)||t.has(o.providerId)||t.set(o.providerId,o.providerName);const n=Array.from(t.entries()).map(([o,x])=>({id:o,name:x})).sort((o,x)=>o.name.localeCompare(x.name,void 0,{sensitivity:"base"}));return l?[{id:"combo",name:"Combos"},...n]:n},[M,R,N,d,A,U]),Y=i.useMemo(()=>{if(A===!1)return[];if(P!=="all"||w)return[];const t=C.trim().toLowerCase(),n=[...U.filter(o=>!O.has(o.id.toLowerCase())&&!O.has(o.name.toLowerCase())&&!O.has(`combo/${o.name}`.toLowerCase()))].sort((o,x)=>o.name.localeCompare(x.name,void 0,{sensitivity:"base"}));return t?n.filter(o=>o.name.toLowerCase().includes(t)||o.strategy&&o.strategy.toLowerCase().includes(t)||o.models.some(x=>x.toLowerCase().includes(t))):n},[U,C,P,w,A,O]),Z=i.useMemo(()=>v==="combo"?[]:M.filter(t=>{if(O.has(t.id.toLowerCase())||O.has(t.value.toLowerCase())||R&&N&&!d.has(t.providerId)||w&&t.kind&&t.kind!==w||v!=="all"&&t.providerId!==v||P==="vision"&&!t.caps.vision||P==="pdf"&&!t.caps.pdf||P==="audio"&&!t.caps.audioInput&&!t.caps.audio||P==="thinking"&&!t.caps.reasoning&&!t.caps.thinking&&!t.caps.thinkingFormat)return!1;if(C.trim()){const l=C.toLowerCase().trim(),n=t.name.toLowerCase().includes(l),o=t.value.toLowerCase().includes(l),x=t.providerName.toLowerCase().includes(l);if(!n&&!o&&!x)return!1}return!0}),[M,v,P,w,C,R,N,d,O]),[Me,ee]=i.useState(new Set),K=i.useMemo(()=>{const t=new Map;for(const n of Z){const o=n.providerId;let x=t.get(o);if(!x){const b=me[o];x={providerId:o,providerName:n.providerName||(b==null?void 0:b.name)||o,color:b==null?void 0:b.color,iconBg:b==null?void 0:b.iconBg,image:b==null?void 0:b.image,models:[],selectedCount:0},t.set(o,x)}x.models.push(n),(p.includes(n.value)||h===n.value)&&x.selectedCount++}return Array.from(t.values()).map(n=>({...n,models:[...n.models].sort((o,x)=>(o.name||o.id).localeCompare(x.name||x.id,void 0,{sensitivity:"base"}))})).sort((n,o)=>{if(n.selectedCount>0&&o.selectedCount===0)return-1;if(o.selectedCount>0&&n.selectedCount===0)return 1;const x=d.has(n.providerId)?1:0,b=d.has(o.providerId)?1:0;return x!==b?b-x:n.providerName.localeCompare(o.providerName,void 0,{sensitivity:"base"})})},[Z,p,h,d]);i.useEffect(()=>{C.trim()?ee(new Set(K.map(t=>t.providerId))):v!=="all"&&ee(new Set([v]))},[C,v,K]),i.useEffect(()=>{c&&!C.trim()&&v==="all"&&K.length>0&&ee(t=>{if(t.size>0)return t;const l=new Set,n=K.filter(o=>o.selectedCount>0);return n.length>0?n.forEach(o=>l.add(o.providerId)):K[0]&&l.add(K[0].providerId),l})},[c,K,C,v]);const Be=t=>{ee(l=>{const n=new Set(l);return n.has(t)?n.delete(t):n.add(t),n})},De=()=>{ee(new Set(K.map(t=>t.providerId)))},Ie=()=>{ee(new Set)},ue=t=>{const l=t.value;p.includes(l)?(B&&B(t),f(o=>o.filter(x=>x!==l))):(E&&E(t),f(D?o=>[...o,l]:[l])),V&&g()},xe=t=>{const l=t.name,n=p.includes(l),o=pe(t.models),x={id:t.name,value:t.name,name:t.name,providerId:"combo",providerName:"Combos",caps:o||de(null,t.name)};n?(B&&B(x),f(b=>b.filter(ie=>ie!==l))):(E&&E(x),f(D?b=>[...b,l]:[l])),V&&g()},Pe=t=>{f(n=>n.filter(o=>o!==t));const l=M.find(n=>n.value===t);l&&B&&B(l)},Re=t=>{if(t===0)return;const l=[...p],n=l[t-1];l[t-1]=l[t],l[t]=n,f(l)},$e=t=>{if(t===p.length-1)return;const l=[...p],n=l[t+1];l[t+1]=l[t],l[t]=n,f(l)},Le=t=>{const{active:l,over:n}=t;n&&l.id!==n.id&&f(o=>{const x=o.indexOf(String(l.id)),b=o.indexOf(String(n.id));return x!==-1&&b!==-1?ve(o,x,b):o})},Te=t=>{t.preventDefault();const l=Q.trim();l&&(p.includes(l)||f(D?n=>[...n,l]:[l]),J(""))},_e=()=>{u&&u(p),g()};return e.jsx(Se,{isOpen:c,onClose:g,maxWidthClass:"w-full max-w-[72rem]",children:e.jsxs("div",{className:"flex flex-col h-[85vh] max-h-[780px] -m-2 sm:-m-4",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 sm:p-5 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:"tune"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm sm:text-base font-bold text-white",children:m}),e.jsx("p",{className:"text-xs text-slate-400",children:"Pick models and drag & drop in the right panel to set priority order"})]})]}),e.jsx("button",{type:"button",onClick:g,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:"grid grid-cols-1 lg:grid-cols-12 flex-1 min-h-0 overflow-hidden divide-y lg:divide-y-0 lg:divide-x divide-[#1E293B]",children:[e.jsxs("div",{className:"lg:col-span-7 flex flex-col min-h-0 p-4 space-y-3.5 overflow-hidden",children:[e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"material-symbols-outlined absolute left-3 top-1/2 -translate-y-1/2 text-[18px] text-slate-500",children:"search"}),e.jsx("input",{ref:s,type:"text",placeholder:"Search models by name, provider, or ID...",value:C,onChange:t=>F(t.target.value),className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl pl-9 pr-8 py-2 text-xs text-white placeholder-slate-500 focus:outline-none focus:border-blue-500 font-mono"}),C&&e.jsx("button",{type:"button",onClick:()=>F(""),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-500 hover:text-white cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"close"})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(ne,{value:v,onChange:G,options:[{value:"all",label:`All Providers (${ae.length})`},...ae.map(t=>({value:t.id,label:t.name}))],className:"shrink-0 min-w-[150px]"}),A!==!1&&U.length>0&&e.jsxs("button",{type:"button",onClick:()=>G(v==="combo"?"all":"combo"),className:`px-2.5 py-1 rounded-lg text-[11px] font-medium border transition-colors cursor-pointer flex items-center gap-1.5 ${v==="combo"?"bg-cyan-500/20 text-cyan-300 border-cyan-500/40":"bg-[#0A0D14] text-slate-400 border-[#1E293B] hover:text-cyan-300"}`,title:"Filter by Smart Combos",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"layers"}),"Combos",e.jsx("span",{className:"text-[9.5px] px-1 rounded bg-cyan-500/30 text-cyan-300 font-mono",children:U.length})]}),e.jsxs("button",{type:"button",onClick:()=>a(!R),className:`px-2.5 py-1 rounded-lg text-[11px] font-medium border transition-colors cursor-pointer flex items-center gap-1.5 ${R?"bg-emerald-500/20 text-emerald-300 border-emerald-500/40":"bg-[#0A0D14] text-slate-400 border-[#1E293B] hover:text-white"}`,title:R?"Showing only models from connected accounts. Click to show all models.":"Showing all catalog models. Click to filter by connected accounts.",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:R?"check_circle":"tune"}),"Connected Only",N&&e.jsx("span",{className:"text-[9.5px] px-1 rounded bg-emerald-500/30 text-emerald-300 font-mono",children:d.size})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("button",{type:"button",onClick:()=>z("all"),className:`px-2 py-1 rounded-lg text-[11px] font-medium border transition-colors cursor-pointer ${P==="all"?"bg-blue-600 text-white border-blue-500":"bg-[#0A0D14] text-slate-400 border-[#1E293B] hover:text-white"}`,children:"All"}),e.jsxs("button",{type:"button",onClick:()=>z("vision"),className:`px-2 py-1 rounded-lg text-[11px] font-medium border transition-colors cursor-pointer flex items-center gap-1 ${P==="vision"?"bg-cyan-500/20 text-cyan-300 border-cyan-500/40":"bg-[#0A0D14] text-slate-400 border-[#1E293B] hover:text-cyan-300"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"visibility"}),"Vision"]}),e.jsxs("button",{type:"button",onClick:()=>z("audio"),className:`px-2 py-1 rounded-lg text-[11px] font-medium border transition-colors cursor-pointer flex items-center gap-1 ${P==="audio"?"bg-purple-500/20 text-purple-300 border-purple-500/40":"bg-[#0A0D14] text-slate-400 border-[#1E293B] hover:text-purple-300"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"graphic_eq"}),"Audio"]}),e.jsxs("button",{type:"button",onClick:()=>z("thinking"),className:`px-2 py-1 rounded-lg text-[11px] font-medium border transition-colors cursor-pointer flex items-center gap-1 ${P==="thinking"?"bg-emerald-500/20 text-emerald-300 border-emerald-500/40":"bg-[#0A0D14] text-slate-400 border-[#1E293B] hover:text-emerald-300"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"psychology"}),"Reasoning"]})]})]}),v!=="combo"&&Y.length>0&&e.jsxs("div",{className:"p-2.5 rounded-xl border border-cyan-500/20 bg-cyan-950/20 space-y-1.5 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-cyan-400 font-semibold",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"layers"}),e.jsxs("span",{children:["Smart Combos (",Y.length,")"]})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Y.map(t=>{const l=p.includes(t.name);return e.jsxs("button",{type:"button",onClick:()=>xe(t),className:`inline-flex items-center gap-1 px-2 py-1 rounded-lg text-xs font-mono font-medium border transition-colors cursor-pointer ${l?"bg-cyan-600 text-white border-cyan-500":"bg-[#0A0D14] text-slate-300 border-[#1E293B] hover:border-cyan-500/40 hover:text-white"}`,children:[l&&e.jsx("span",{className:"material-symbols-outlined text-[12px] text-cyan-200",children:"check"}),e.jsx("span",{children:t.name}),e.jsxs("span",{className:"text-[10px] opacity-60",children:["(",t.models.length,")"]})]},t.id)})})]}),v==="combo"?e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto pr-1",children:Y.length===0?e.jsxs("div",{className:"py-10 text-center text-slate-500 text-xs space-y-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[26px] text-slate-600 block mx-auto",children:"layers_clear"}),e.jsx("p",{className:"max-w-xs mx-auto",children:"No combos found matching your search or filters."})]}):e.jsx("div",{className:"space-y-2",children:Y.map(t=>{const l=p.includes(t.name),n=pe(t.models);return e.jsxs("div",{onClick:()=>xe(t),className:`flex items-center justify-between p-3 rounded-xl border transition-colors cursor-pointer ${l?"bg-cyan-950/30 border-cyan-500/50 text-white":"bg-[#0A0D14]/70 border-[#1E293B] hover:border-slate-700 text-slate-300"}`,children:[e.jsxs("div",{className:"min-w-0 pr-2 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"px-1.5 py-0.2 rounded bg-cyan-500/20 border border-cyan-500/40 font-mono text-[9.5px] text-cyan-300 font-semibold tracking-wide",children:"COMBO"}),e.jsx("span",{className:"text-xs font-semibold text-white truncate",children:t.name}),t.strategy&&e.jsx("span",{className:`px-1.5 py-0.2 rounded font-sans text-[9px] font-medium border ${t.strategy==="round-robin"?"bg-cyan-950/40 text-cyan-300 border-cyan-500/30":t.strategy==="fusion"?"bg-purple-950/40 text-purple-300 border-purple-500/30":t.strategy==="lkgp"?"bg-emerald-950/40 text-emerald-300 border-emerald-500/30":t.strategy==="p2c"?"bg-indigo-950/40 text-indigo-300 border-indigo-500/30":"bg-amber-950/40 text-amber-300 border-amber-500/30"}`,children:t.strategy==="round-robin"?"Round Robin":t.strategy==="fusion"?"Fusion":t.strategy==="lkgp"?"LKGP":t.strategy==="p2c"?"P2C":"Fallback"})]}),e.jsxs("div",{className:"font-mono text-[11px] text-slate-400 truncate",children:[e.jsxs("span",{className:"text-cyan-400 font-semibold",children:[t.models.length," model",t.models.length>1?"s":"",":"]})," ",e.jsx("span",{className:"text-slate-300",children:t.models.join(", ")})]}),n&&e.jsx("div",{className:"pt-0.5",children:e.jsx(oe,{caps:n,size:"xs"})})]}),e.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),xe(t)},className:`size-7 rounded-lg flex items-center justify-center shrink-0 border transition-colors ${l?"bg-cyan-600 border-cyan-500 text-white":"bg-[#141B2D] border-[#1E293B] text-slate-400 hover:text-white hover:border-slate-600"}`,children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:l?"check":"add"})})]},t.id)})})}):Z.length===0?e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto pr-1",children:e.jsxs("div",{className:"py-10 text-center text-slate-500 text-xs space-y-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[26px] text-slate-600 block mx-auto",children:"search_off"}),e.jsx("p",{className:"max-w-xs mx-auto",children:R&&!N?"No accounts connected yet. All models are currently hidden by 'Connected Only'.":R?"No models found from connected accounts matching your search/filters.":"No models matched your filter. Try clearing filters or enter a custom model below."}),R&&e.jsx("button",{type:"button",onClick:()=>a(!1),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 cursor-pointer transition-colors",children:"Show All Registry Models"})]})}):e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs text-slate-400 px-1 shrink-0",children:[e.jsxs("span",{className:"font-medium text-slate-300",children:[K.length," provider",K.length>1?"s":""," • ",Z.length," models"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:De,className:"text-[11px] text-blue-400 hover:text-blue-300 font-medium cursor-pointer hover:underline",children:"Expand All"}),e.jsx("span",{className:"text-slate-600",children:"•"}),e.jsx("button",{type:"button",onClick:Ie,className:"text-[11px] text-slate-400 hover:text-slate-300 font-medium cursor-pointer hover:underline",children:"Collapse All"})]})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto space-y-2 pr-1",children:K.map(t=>{const l=Me.has(t.providerId);return e.jsxs("div",{className:"rounded-xl border border-[#1E293B] bg-[#0A0D14]/70 overflow-hidden transition-colors",children:[e.jsxs("div",{onClick:()=>Be(t.providerId),className:`flex items-center justify-between p-2.5 cursor-pointer select-none transition-colors ${l?"bg-[#141B2D]/80 hover:bg-[#141B2D] border-b border-[#1E293B]":"hover:bg-white/[0.03]"}`,children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx(qe,{src:t.image,name:t.providerName,color:t.color,iconBg:t.iconBg,size:"sm"}),e.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-bold text-white truncate",children:t.providerName}),e.jsxs("span",{className:"text-[10px] font-mono px-1.5 py-0.2 rounded bg-slate-800/80 text-slate-400 border border-slate-700/60 shrink-0",children:[t.models.length," model",t.models.length>1?"s":""]}),t.selectedCount>0&&e.jsxs("span",{className:"text-[10px] font-mono px-1.5 py-0.2 rounded bg-blue-500/20 text-blue-300 border border-blue-500/40 font-semibold shrink-0",children:[t.selectedCount," selected"]})]})]}),e.jsx("span",{className:`material-symbols-outlined text-[18px] text-slate-400 transition-transform duration-200 shrink-0 ${l?"rotate-180 text-blue-400":""}`,children:"expand_more"})]}),l&&e.jsx("div",{className:"p-2 space-y-1.5 bg-[#080B12]/60",children:t.models.map(n=>{const o=p.includes(n.value)||h===n.value,x=Ke(n.contextLength);return e.jsxs("div",{onClick:()=>ue(n),className:`flex items-center justify-between p-2.5 rounded-xl border transition-colors cursor-pointer ${o?"bg-blue-600/10 border-blue-500/40 text-white":"bg-[#0A0D14] border-[#1E293B] hover:border-slate-700 text-slate-300"}`,children:[e.jsxs("div",{className:"min-w-0 pr-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-white truncate",children:n.name}),x&&e.jsx("span",{className:"text-[9.5px] font-mono px-1 py-0.2 rounded bg-slate-800 text-slate-400 border border-slate-700/60 leading-tight",children:x})]}),e.jsx("div",{className:"font-mono text-[11px] text-slate-400 truncate mt-0.5",children:n.value}),e.jsx("div",{className:"mt-1",children:e.jsx(oe,{caps:n.caps,size:"xs"})})]}),e.jsx("button",{type:"button",onClick:b=>{b.stopPropagation(),ue(n)},className:`size-7 rounded-lg flex items-center justify-center shrink-0 border transition-colors ${o?"bg-blue-600 border-blue-500 text-white":"bg-[#141B2D] border-[#1E293B] text-slate-400 hover:text-white hover:border-slate-600"}`,children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:o?"check":"add"})})]},n.value)})})]},t.providerId)})})]}),e.jsxs("form",{onSubmit:Te,className:"flex gap-2 pt-1 border-t border-[#1E293B]",children:[e.jsx("input",{type:"text",placeholder:"Or enter custom model ID (e.g. provider/model)...",value:Q,onChange:t=>J(t.target.value),className:"flex-1 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:"submit",disabled:!Q.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",children:"Add Custom"})]})]}),e.jsxs("div",{className:"lg:col-span-5 flex flex-col min-h-0 p-4 space-y-3 bg-[#0A0D14]/40",children:[e.jsxs("div",{className:"flex items-center justify-between pb-2 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[18px]",children:"format_list_numbered"}),e.jsxs("span",{className:"text-xs font-bold text-white",children:["Selected Models (",p.length,")"]})]}),p.length>0&&e.jsx("button",{type:"button",onClick:()=>f([]),className:"text-[11px] text-slate-500 hover:text-rose-400 transition-colors cursor-pointer",children:"Clear all"})]}),e.jsx("p",{className:"text-[11px] text-slate-400 leading-normal",children:"Order determines execution priority (1 = primary, 2+ = backup fallbacks). Drag handles to reorder."}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto space-y-2 pr-1",children:p.length===0?e.jsx("div",{className:"py-16 text-center text-slate-500 text-xs border border-dashed border-[#1E293B] rounded-2xl p-4",children:"No models selected yet. Click any model on the left to add it to this priority list."}):e.jsx(be,{sensors:r,collisionDetection:fe,onDragEnd:Le,children:e.jsx(ge,{items:p,strategy:ye,children:e.jsx("div",{className:"space-y-1.5",children:p.map((t,l)=>e.jsx(Ve,{id:t,index:l,onRemove:()=>Pe(t),onMoveUp:()=>Re(l),onMoveDown:()=>$e(l),isFirst:l===0,isLast:l===p.length-1},t))})})})})]})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 sm:p-5 border-t border-[#1E293B] bg-[#0A0D14]/60",children:[e.jsx("div",{className:"text-xs text-slate-400",children:p.length===0?e.jsx("span",{children:"No models selected"}):e.jsxs("span",{children:[e.jsx("strong",{className:"text-white font-mono",children:p.length})," model",p.length>1?"s":""," in priority order"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:g,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:"button",onClick:_e,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 transition-all cursor-pointer",children:u?"Confirm Selection":"Done"})]})]})]})})},Qe=/^[a-zA-Z0-9_.-]+$/,Ue=({id:c,model:g,index:m,onEdit:q,onRemove:u,onMoveUp:D,onMoveDown:T,isFirst:E,isLast:B,excludeValues:h})=>{const[j,I]=i.useState(!1),[w,L]=i.useState(g);i.useEffect(()=>{L(g)},[g]);const S=()=>{const v=w.trim();v&&v!==g?q(v):L(g),I(!1)},{attributes:V,listeners:_,setNodeRef:A,transform:p,transition:f,isDragging:C}=Ce({id:c}),F={transform:ke.Transform.toString(p),transition:f,zIndex:C?50:void 0,opacity:C?.6:1};return e.jsxs("div",{ref:A,style:F,className:`group flex items-center justify-between gap-2.5 px-3 py-2 rounded-xl border bg-[#0A0D14] transition-all ${C?"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",...V,..._,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:m+1}),j?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(Ee,{autoFocus:!0,value:w,onChange:v=>L(v),onEnter:S,placeholder:"e.g. anthropic/claude-3-7-sonnet",excludeValues:h,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:S,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:()=>{L(g),I(!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:()=>I(!0),title:"Click to edit model ID inline",children:[e.jsx("span",{className:"truncate",title:c,children:c}),e.jsx("span",{className:"material-symbols-outlined text-[13px] text-slate-500 opacity-0 group-hover:opacity-100 transition-opacity",children:"edit"})]}),!j&&e.jsx(oe,{model:c,size:"xs"})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{type:"button",onClick:D,disabled:E,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:T,disabled:B,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:u,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"})})]})]})},We=({isOpen:c,onClose:g,combo:m,title:q,onSave:u})=>{const[D,T]=i.useState(""),[E,B]=i.useState("round-robin"),[h,j]=i.useState([]),[I,w]=i.useState(""),[L,S]=i.useState(""),[V,_]=i.useState(""),[A,p]=i.useState(!1),[f,C]=i.useState(!1),F=!!m,v=he(ce(we,{activationConstraint:{distance:4}}),ce(Ne,{coordinateGetter:je}));i.useEffect(()=>{c&&(m?(T(m.name),B(m.strategy||"round-robin"),j(Array.isArray(m.models)?[...m.models]:[])):(T(""),B("round-robin"),j([])),w(""),S(""),_(""),C(!1))},[c,m]);const G=s=>{const r=s.trim();return r?Qe.test(r)?(w(""),!0):(w("Name can only contain letters, numbers, -, _ and ."),!1):(w("Combo name is required."),!1)},P=s=>{const r=s.target.value;T(r),r.trim()?G(r):w("")},z=i.useMemo(()=>{const s=[];m!=null&&m.id&&s.push(m.id),m!=null&&m.name&&(s.push(m.name),s.push(`combo/${m.name}`));const r=D.trim();return r&&(s.push(r),s.push(`combo/${r}`)),s},[m,D]),Q=s=>{const r=s.trim().toLowerCase(),d=r.startsWith("combo/")?r.slice(6):r;return z.some(N=>{const M=N.toLowerCase(),O=M.startsWith("combo/")?M.slice(6):M;return r===M||d===O})},J=(s,r)=>{const d=r.trim();if(Q(d)){S("A combo cannot bundle itself (circular reference).");return}const N=[...h];N[s]=d,j(N),S("")},U=s=>{j(h.filter((r,d)=>d!==s))},X=s=>{if(s===0)return;const r=[...h],d=r[s-1];r[s-1]=r[s],r[s]=d,j(r)},W=s=>{if(s===h.length-1)return;const r=[...h],d=r[s+1];r[s+1]=r[s],r[s]=d,j(r)},se=s=>{const{active:r,over:d}=s;d&&r.id!==d.id&&j(N=>{const M=N.map((Y,Z)=>`${Y}-${Z}`),O=M.indexOf(String(r.id)),ae=M.indexOf(String(d.id));return O!==-1&&ae!==-1?ve(N,O,ae):N})},R=s=>{const r=V.trim();if(r){if(Q(r)){S("A combo cannot bundle itself (circular reference).");return}h.includes(r)||(j([...h,r]),S("")),_("")}},a=async s=>{if(s.preventDefault(),!!G(D)){if(h.length===0){S("At least one model must be added to the combo.");return}if(h.some(Q)){S("A combo cannot bundle itself (circular reference).");return}try{C(!0),await u({id:m==null?void 0:m.id,name:D.trim(),models:h,strategy:E,isActive:m?m.isActive:!0}),le(),g()}catch(r){w((r==null?void 0:r.message)||"Failed to save combo.")}finally{C(!1)}}};return e.jsxs(e.Fragment,{children:[e.jsx(Se,{isOpen:c,onClose:g,maxWidthClass:"w-full max-w-2xl",children:e.jsxs("form",{onSubmit:a,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:F?"edit_note":"add_circle"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-bold text-white",children:q||(F?`Edit Combo: ${m==null?void 0:m.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:g,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:D,onChange:P,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 ${I?"border-rose-500/80 focus:border-rose-500":"border-[#1E293B] focus:border-blue-500"}`}),I?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"}),I]}):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(ne,{value:E,onChange:s=>B(s),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:[E==="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."]}),E==="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."]}),E==="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."]}),E==="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."]}),E==="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 (",h.length,") ",e.jsx("span",{className:"text-rose-400",children:"*"})]}),e.jsxs("button",{type:"button",onClick:()=>p(!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:h.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(be,{sensors:v,collisionDetection:fe,onDragEnd:se,children:e.jsx(ge,{items:h.map((s,r)=>`${s}-${r}`),strategy:ye,children:e.jsx("div",{className:"space-y-1.5",children:h.map((s,r)=>e.jsx(Ue,{id:`${s}-${r}`,model:s,index:r,onEdit:d=>J(r,d),onRemove:()=>U(r),onMoveUp:()=>X(r),onMoveDown:()=>W(r),isFirst:r===0,isLast:r===h.length-1,excludeValues:z},`${s}-${r}`))})})})}),L&&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"}),L]}),e.jsxs("div",{className:"flex gap-2 pt-1 items-start",children:[e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx(Ee,{placeholder:"Or search/type model ID (e.g. anthropic/claude-3-7-sonnet)...",value:V,onChange:_,onEnter:()=>R(),excludeValues:z,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:()=>R(),disabled:!V.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:g,disabled:f,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:f,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:f?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[15px] animate-spin",children:"progress_activity"}),"Saving..."]}):e.jsx("span",{children:F?"Update Combo":"Save Combo"})})]})]})}),A&&e.jsx(Ae,{isOpen:A,onClose:()=>p(!1),addedModelValues:h,initialSelectedModels:h,excludeModelIds:z,allowCombos:!1,onSelect:s=>{h.includes(s.value)||(j(r=>[...r,s.value]),S(""))},onDeselect:s=>{j(r=>r.filter(d=>d!==s.value))},onConfirm:s=>{j(s),s.length>0&&S("")},title:"Add Model to Combo",multiSelect:!0,closeOnSelect:!1})]})},Je={vision:{enabled:!1,roundRobin:!1,models:[]},audioInput:{enabled:!1,roundRobin:!1,models:[]}},lt=()=>{const[c,g]=i.useState([]),[m,q]=i.useState(!0),[u,D]=i.useState(Je),[T,E]=i.useState(!1),[B,h]=i.useState(null),[j,I]=i.useState(""),w=i.useMemo(()=>{const a=j.trim().toLowerCase(),s=[...c].sort((r,d)=>r.name.localeCompare(d.name,void 0,{sensitivity:"base"}));return a?s.filter(r=>!!(r.name.toLowerCase().includes(a)||r.strategy.toLowerCase().includes(a)||r.models&&r.models.some(d=>d.toLowerCase().includes(a)))):s},[c,j]),[L,S]=i.useState(!1),[V,_]=i.useState(null),[A,p]=i.useState(null),[f,C]=i.useState(null),F=i.useCallback(async()=>{try{q(!0);const a=await fetch("/api/combos");if(a.ok){const s=await a.json();Array.isArray(s)&&g(s)}}catch(a){console.error("Failed to load combos:",a)}finally{q(!1)}},[]),v=i.useCallback(async()=>{try{const a=await fetch("/api/settings/capacity-adapter");if(a.ok){const s=await a.json();s&&typeof s=="object"&&D({vision:s.vision||{enabled:!1,roundRobin:!1,models:[]},audioInput:s.audioInput||{enabled:!1,roundRobin:!1,models:[]},pdf:s.pdf,videoInput:s.videoInput})}}catch(a){console.error("Failed to load capacity adapter settings:",a)}},[]);i.useEffect(()=>{F(),v()},[F,v]);const G=async a=>{D(a);try{E(!0),await fetch("/api/settings/capacity-adapter",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)})}catch(s){console.error("Failed to save capacity adapter settings:",s)}finally{E(!1)}},P=a=>{const s=u[a];G({...u,[a]:{...s,enabled:!s.enabled}})},z=(a,s)=>{const r=u[a];G({...u,[a]:{...r,roundRobin:s}})},Q=(a,s)=>{const r=u[a];G({...u,[a]:{...r,models:r.models.filter(d=>d!==s)}})},J=a=>{if(!A)return;const s=u[A];G({...u,[A]:{...s,models:a}}),p(null)},U=async a=>{if(a.id){const s=await fetch(`/api/combos/${a.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:a.name,models:a.models,strategy:a.strategy,isActive:a.isActive})});if(!s.ok){const r=await s.json();throw new Error(r.error||"Failed to update combo")}}else{const s=await fetch("/api/combos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:a.name,models:a.models,strategy:a.strategy})});if(!s.ok){const r=await s.json();throw new Error(r.error||"Failed to create combo")}}await F(),le(),S(!1),_(null)},X=async a=>{try{const s=await fetch(`/api/combos/${a.id}/toggle`,{method:"POST"});if(s.ok){const r=await s.json();g(d=>d.map(N=>N.id===a.id?r:N)),le()}}catch(s){console.error("Error toggling combo status:",s)}},W=async(a,s)=>{try{const r=await fetch(`/api/combos/${a.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({strategy:s})});if(r.ok){const d=await r.json();g(N=>N.map(M=>M.id===a.id?d:M)),le()}}catch(r){console.error("Error updating strategy:",r)}},se=a=>{C({title:"Delete Combo",message:`Are you sure you want to delete combo "${a.name}"? This action cannot be undone.`,confirmText:"Delete Combo",variant:"danger",onConfirm:async()=>{try{(await fetch(`/api/combos/${a.id}`,{method:"DELETE"})).ok&&(g(r=>r.filter(d=>d.id!==a.id)),le())}catch(s){console.error("Error deleting combo:",s)}finally{C(null)}}})},R=(a,s)=>{navigator.clipboard.writeText(a),h(s),setTimeout(()=>h(null),2e3)};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-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("button",{type:"button",onClick:()=>{_(null),S(!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?`${w.length} of ${c.length}`:c.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:a=>I(a.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:()=>I(""),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"})]})]}),m?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..."})]}):c.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."})]}):w.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:()=>I(""),className:"text-xs text-blue-400 hover:underline cursor-pointer",children:"Clear filter"})]}):e.jsx("div",{className:"w-full space-y-2.5",children:w.map((a,s)=>{const r=pe(a.models),d=a.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 ${d?"bg-[#0F1420]/80 border-[#1E293B] hover:border-slate-700":"bg-[#0A0D14]/50 border-[#1E293B]/50 opacity-60"}`,style:{animationDelay:`${s*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 ${a.strategy==="fallback"?"bg-blue-500/10 text-blue-400 border-blue-500/20":a.strategy==="round-robin"?"bg-cyan-500/10 text-cyan-400 border-cyan-500/20":a.strategy==="fusion"?"bg-indigo-500/10 text-indigo-400 border-indigo-500/20":a.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:a.strategy==="fallback"?"low_priority":a.strategy==="round-robin"?"sync":a.strategy==="fusion"?"call_split":a.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("span",{className:"text-xs font-bold text-white font-mono",children:a.name}),r&&e.jsx(oe,{caps:r,size:"xs"}),!d&&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.jsx("div",{className:"flex flex-wrap items-center gap-1.5 mt-1.5",children:a.models.map((N,M)=>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:M+1}),e.jsx("span",{children:N})]},M))})]})]}),e.jsxs("div",{className:"flex items-center gap-2.5 shrink-0",children:[e.jsx(ne,{value:a.strategy,onChange:N=>W(a,N),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:d?"Disable combo":"Enable combo",children:[e.jsx("input",{type:"checkbox",checked:d,onChange:()=>X(a),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:B===a.id?"Copied to clipboard!":"Copy combo identifier",onClick:()=>R(a.name,a.id),className:`p-1.5 rounded-lg transition-colors cursor-pointer ${B===a.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:B===a.id?"check":"content_copy"})}),e.jsx("button",{type:"button",title:"Edit combo",onClick:()=>{_(a),S(!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:()=>se(a),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"})})]})]})]},a.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."})]}),T&&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:u.vision.enabled,onChange:()=>P("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(ne,{value:u.vision.roundRobin?"round-robin":"fallback",onChange:a=>z("vision",a==="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 (",u.vision.models.length,")"]}),e.jsxs("button",{type:"button",onClick:()=>p("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:u.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."}):u.vision.models.map(a=>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:a}),e.jsx("button",{type:"button",onClick:()=>Q("vision",a),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"})})]},a))})]})]}),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:u.audioInput.enabled,onChange:()=>P("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(ne,{value:u.audioInput.roundRobin?"round-robin":"fallback",onChange:a=>z("audioInput",a==="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 (",u.audioInput.models.length,")"]}),e.jsxs("button",{type:"button",onClick:()=>p("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:u.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."}):u.audioInput.models.map(a=>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:a}),e.jsx("button",{type:"button",onClick:()=>Q("audioInput",a),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"})})]},a))})]})]})]})]}),e.jsx(We,{isOpen:L,onClose:()=>{S(!1),_(null)},combo:V,onSave:U}),A&&e.jsx(Ae,{isOpen:A!==null,onClose:()=>p(null),title:`Configure ${A==="vision"?"Vision":"Audio"} Adapter Model Pool`,initialSelectedModels:u[A].models,onConfirm:J,filterModality:A==="vision"?"vision":"audio",multiSelect:!0}),f&&e.jsx(Ge,{isOpen:f!==null,title:f.title,message:f.message,confirmText:f.confirmText||"Confirm",variant:f.variant||"primary",onConfirm:f.onConfirm,onCancel:()=>C(null)})]})};export{lt as CombosTab};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as l,j as e}from"./vendor-BcOI2aZ9.js";import{P as ae}from"./index-C4NTQZ40.js";import{C as ne}from"./ConfirmModal-DGvcf0gB.js";import{i as Q}from"./ModelAutocompleteInput-B9syrV1O.js";import{g as X}from"./metadataRegistry-B91sal4r.js";import{T as Z}from"./ToolIcon-Cp4gSgFt.js";import{C as ie,O as ee,F as te,A as se}from"./providersData-DkVCRBsJ.js";import"./lucide-Cc35htxl.js";const ce=({isOpen:N,existingProviderIds:z,onClose:o,onImportSuccess:g})=>{const[u,w]=l.useState([]),[_,y]=l.useState(!1),[h,j]=l.useState(""),[p,q]=l.useState("all"),[C,b]=l.useState(null),[I,k]=l.useState(""),[d,T]=l.useState(""),[v,P]=l.useState("Default Account"),[D,O]=l.useState(!1),[f,A]=l.useState(null);l.useEffect(()=>{N&&(y(!0),fetch("/api/providers/community-catalog").then(a=>a.json()).then(a=>{a&&Array.isArray(a.catalog)&&w(a.catalog)}).catch(a=>{console.error("Failed to load community catalog:",a)}).finally(()=>{y(!1)}))},[N]);const W=l.useMemo(()=>{const a=new Set;for(const n of u)n.category&&a.add(n.category);return["all",...Array.from(a).sort()]},[u]),B=l.useMemo(()=>{const a=h.toLowerCase().trim();return u.filter(n=>{var S;return p!=="all"&&n.category!==p?!1:a?n.name.toLowerCase().includes(a)||n.id.toLowerCase().includes(a)||n.baseUrl.toLowerCase().includes(a)||((S=n.models)==null?void 0:S.some(U=>U.id.toLowerCase().includes(a))):!0})},[u,h,p]),L=a=>{b(a),k(a.baseUrl||"https://api.openai.com"),T(""),P("Default Account"),A(null)},$=async()=>{if(C){O(!0),A(null);try{const a=await fetch("/api/providers/community-catalog/import",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:C.id,customBaseUrl:I.trim(),apiKey:d.trim()||void 0,accountName:v.trim()||"Default Account"})}),n=await a.json();if(!a.ok||!n.success)throw new Error(n.error||"Failed to import provider");g(C.id),b(null)}catch(a){A(a.message||"Import failed")}finally{O(!1)}}};return N?e.jsx(ae,{isOpen:N,onClose:o,maxWidthClass:"w-full max-w-4xl",children:e.jsxs("div",{className:"relative w-full max-w-4xl bg-[#0B0F19] border border-[#1E293B] rounded-2xl shadow-2xl overflow-hidden flex flex-col max-h-[88vh]",children:[e.jsxs("div",{className:"p-6 border-b border-[#1E293B] bg-[#0F1420]/70 flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-blue-500/10 border border-blue-500/20 flex items-center justify-center text-blue-400",children:e.jsx("span",{className:"material-symbols-outlined text-[22px]",children:"explore"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-base font-bold text-white",children:"Community Providers Catalog"}),e.jsxs("span",{className:"px-2 py-0.5 rounded-full bg-blue-500/10 border border-blue-500/20 text-blue-400 text-[11px] font-mono",children:[u.length," Available"]})]}),e.jsx("p",{className:"text-xs text-slate-400 mt-0.5",children:"Browse on-demand multi-gateways, token resellers, and community inference proxies. Import directly into active providers."})]})]}),e.jsx("button",{onClick:o,className:"p-1.5 rounded-lg text-slate-400 hover:text-white hover:bg-white/5 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"close"})})]}),e.jsxs("div",{className:"p-4 border-b border-[#1E293B] bg-[#0A0D14]/80 flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-[240px]",children:[e.jsx("span",{className:"material-symbols-outlined absolute left-3 top-2.5 text-slate-500 text-[18px]",children:"search"}),e.jsx("input",{type:"text",value:h,onChange:a=>j(a.target.value),placeholder:"Search community provider by name, ID, endpoint...",className:"w-full pl-9 pr-3 py-2 text-xs bg-[#0F1420] border border-[#1E293B] rounded-xl text-white placeholder-slate-500 focus:outline-none focus:border-blue-500/60 transition-colors"}),h&&e.jsx("button",{onClick:()=>j(""),className:"absolute right-3 top-2.5 text-slate-500 hover:text-white text-xs",children:"✕"})]}),e.jsx("div",{className:"flex items-center gap-1.5 overflow-x-auto pb-1 max-w-full",children:W.map(a=>e.jsx("button",{onClick:()=>q(a),className:`px-2.5 py-1 rounded-lg text-[11px] font-medium capitalize transition-colors cursor-pointer ${p===a?"bg-blue-600 text-white shadow-xs":"bg-[#0F1420] text-slate-400 border border-[#1E293B] hover:text-white"}`,children:a},a))})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4 space-y-2.5 min-h-[300px]",children:_?e.jsxs("div",{className:"py-20 flex flex-col items-center justify-center text-slate-500 text-xs gap-3",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-[28px] text-blue-400",children:"sync"}),e.jsx("span",{children:"Loading community catalog..."})]}):B.length===0?e.jsxs("div",{className:"py-16 text-center text-slate-500 text-xs flex flex-col items-center justify-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[32px] text-slate-600",children:"search_off"}),e.jsx("span",{children:"No community providers match your filter query."})]}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:B.map(a=>{const n=z.includes(a.id);return e.jsxs("div",{className:"p-3.5 rounded-xl bg-[#0F1420]/80 border border-[#1E293B] hover:border-slate-700 transition-all flex flex-col justify-between gap-3 group",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-semibold text-xs text-white",children:a.name}),e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] bg-[#1E293B] text-slate-400 font-mono",children:a.id})]}),e.jsx("div",{className:"text-[11px] text-slate-500 font-mono truncate max-w-[280px] mt-1",title:a.baseUrl||"Custom Base URL required",children:a.baseUrl||e.jsx("span",{className:"italic text-amber-500/80",children:"Requires custom URL"})})]}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-mono uppercase font-semibold ${a.format==="claude"?"bg-amber-500/10 text-amber-400 border border-amber-500/20":"bg-emerald-500/10 text-emerald-400 border border-emerald-500/20"}`,children:a.format})})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-3 text-[11px] text-slate-400",children:[a.models&&a.models.length>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px] text-slate-500",children:"memory"}),a.models.length," preset models"]}),a.website&&e.jsxs("a",{href:a.website,target:"_blank",rel:"noreferrer",className:"flex items-center gap-1 text-blue-400/80 hover:text-blue-300 transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"open_in_new"}),"Docs"]})]})]}),e.jsxs("div",{className:"pt-2 border-t border-[#1E293B]/60 flex items-center justify-between",children:[e.jsx("span",{className:"text-[10px] text-slate-500 capitalize",children:a.category}),n?e.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-emerald-400 font-medium px-2 py-0.5 rounded bg-emerald-500/10 border border-emerald-500/20",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"check_circle"}),"Active"]}):e.jsxs("button",{onClick:()=>L(a),className:"flex items-center gap-1 px-3 py-1 rounded-lg bg-blue-600 hover:bg-blue-500 text-white text-[11px] font-semibold transition-colors cursor-pointer shadow-xs",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"download"}),"Import"]})]})]},a.id)})})}),e.jsxs("div",{className:"p-3 border-t border-[#1E293B] bg-[#0A0D14] flex items-center justify-between text-xs text-slate-500",children:[e.jsxs("span",{children:["Showing ",B.length," of ",u.length," community providers"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] text-blue-400",children:"info"}),"Imported providers are saved locally in SQLite and support load balancing."]})]}),C&&e.jsx("div",{className:"absolute inset-0 bg-black/75 backdrop-blur-xs flex items-center justify-center p-4 z-50 animate-rt-fade-in",children:e.jsxs("div",{className:"w-full max-w-md bg-[#0F1420] border border-[#1E293B] rounded-2xl p-5 shadow-2xl space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-[#1E293B] pb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[18px]",children:"add_task"}),e.jsxs("h3",{className:"text-sm font-bold text-white",children:["Import ",C.name]})]}),e.jsx("button",{onClick:()=>b(null),className:"text-slate-400 hover:text-white text-xs cursor-pointer",children:"✕"})]}),f&&e.jsxs("div",{className:"p-2.5 rounded-lg bg-red-500/10 border border-red-500/20 text-red-400 text-xs flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"error"}),e.jsx("span",{children:f})]}),e.jsxs("div",{className:"space-y-3 text-xs",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-semibold mb-1",children:"Base URL"}),e.jsx("input",{type:"text",value:I,onChange:a=>k(a.target.value),placeholder:"https://api.example.com/v1",className:"w-full px-3 py-2 bg-[#0A0D14] border border-[#1E293B] rounded-xl text-white placeholder-slate-600 focus:outline-none focus:border-blue-500/60"}),e.jsx("p",{className:"text-[11px] text-slate-500 mt-1",children:"API endpoint prefix where request completions will be routed."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-semibold mb-1",children:"Account Name"}),e.jsx("input",{type:"text",value:v,onChange:a=>P(a.target.value),placeholder:"Default Account",className:"w-full px-3 py-2 bg-[#0A0D14] border border-[#1E293B] rounded-xl text-white placeholder-slate-600 focus:outline-none focus:border-blue-500/60"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-semibold mb-1",children:"API Key (Optional)"}),e.jsx("input",{type:"password",value:d,onChange:a=>T(a.target.value),placeholder:"sk-...",className:"w-full px-3 py-2 bg-[#0A0D14] border border-[#1E293B] rounded-xl text-white placeholder-slate-600 focus:outline-none focus:border-blue-500/60"}),e.jsx("p",{className:"text-[11px] text-slate-500 mt-1",children:"Encrypted with AES-256-GCM hardware vault. You can also configure it later."})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{onClick:()=>b(null),disabled:D,className:"px-3.5 py-1.5 rounded-xl border border-[#1E293B] text-slate-400 hover:text-white text-xs font-semibold cursor-pointer",children:"Cancel"}),e.jsx("button",{onClick:$,disabled:D||!I.trim(),className:"px-4 py-1.5 rounded-xl bg-blue-600 hover:bg-blue-500 disabled:opacity-50 text-white text-xs font-semibold flex items-center gap-1.5 cursor-pointer shadow-xs",children:D?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-[14px]",children:"sync"}),"Importing..."]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"check"}),"Save & Activate"]})})]})]})})]})}):null},ge=({searchQuery:N,onSelectProvider:z})=>{const[o,g]=l.useState(null),[u,w]=l.useState(""),[_,y]=l.useState("Default Account"),[h,j]=l.useState(""),[p,q]=l.useState([]),[C,b]=l.useState(new Set),[I,k]=l.useState({}),[d,T]=l.useState(null),[v,P]=l.useState("all"),[D,O]=l.useState(!1),[f,A]=l.useState(null),[W,B]=l.useState(!1),[L,$]=l.useState(!1),[a,n]=l.useState(null),S=async()=>{try{const t=await fetch("/api/providers");if(t.ok){const s=await t.json(),r=Array.isArray(s)?s.filter(x=>x.id!=="combo"&&x.category!=="composite"):[];q(r)}}catch{}};l.useEffect(()=>{S()},[]);const U=t=>{const s=t.baseUrl||t.defaultBaseUrl||"";return s.startsWith("devin://")||s.startsWith("auggie://")||s.startsWith("zcode://")||s.includes("://")&&s.endsWith("/stdio")},F=t=>U(t)?!1:!!t.noAuth||t.requiresApiKey===!1||t.authType==="none"||t.id==="opencode"||t.id==="oc"||t.id==="ollama-local"||t.id==="lm-studio"||t.id==="jan",G=t=>{const s=p.find(x=>x.id===t),r=X(t);return r&&U(r)?(s==null?void 0:s.accountsCount)??0:t==="opencode"||t==="oc"||s!=null&&s.noAuth||r!=null&&r.noAuth||(r==null?void 0:r.requiresApiKey)===!1||(r==null?void 0:r.authType)==="none"?Math.max(1,(s==null?void 0:s.accountsCount)??0):(s==null?void 0:s.accountsCount)??0},M=t=>{const s=!N||t.name.toLowerCase().includes(N.toLowerCase()),r=G(t.id);return v==="connected"?s&&(r>0||F(t)):v==="not_connected"?s&&r===0&&!F(t):s},re=async()=>{if(o){$(!0),n(null);try{let t=p.find(s=>s.id===o.id);if(!t||h.trim()&&h.trim()!==t.baseUrl){const s={id:o.id,name:(t==null?void 0:t.name)||o.name,baseUrl:h.trim()||o.baseUrl||(t==null?void 0:t.baseUrl)||"https://api.openai.com",format:(t==null?void 0:t.format)||o.format||"openai"};t&&(s.models=t.models,s.customHeaders=t.customHeaders,s.proxyUrl=t.proxyUrl,s.thinkingMode=t.thinkingMode,s.strategy=t.strategy,s.stickyLimit=t.stickyLimit);const r=await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!r.ok){const x=await r.json().catch(()=>({}));throw new Error(x.error||`Failed to save provider (${r.status})`)}}if(u.trim()||F(o)){const s=await fetch(`/api/providers/${o.id}/accounts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:_||`${o.name} Connection`,apiKey:u.trim()||(o.id==="opencode"||o.id==="oc"?"public":"")})});if(!s.ok){const r=await s.json().catch(()=>({}));throw new Error(r.error||`Failed to add account (${s.status})`)}}await S(),Q(),w(""),y("Default Account"),j(""),n(null),g(null)}catch(t){console.error(t),n(t.message||"Failed to save connection.")}finally{$(!1)}}},H=async t=>{b(s=>new Set(s).add(t));try{const r=await(await fetch(`/api/providers/${t}/test`,{method:"POST"})).json();k(x=>({...x,[t]:{success:!!r.success,msg:r.message||(r.success?"Connected successfully":"Connection failed"),latencyMs:r.latencyMs}}))}catch(s){k(r=>({...r,[t]:{success:!1,msg:s.message||"Failed to reach gateway"}}))}finally{b(s=>{const r=new Set(s);return r.delete(t),r})}},J=async(t,s)=>{const r=t.filter(c=>G(c.id)>0||F(c));if(r.length===0){alert(`No configured or ready accounts found in ${s}.`);return}T(s);const x=r.map(c=>c.id);b(c=>{const m=new Set(c);return x.forEach(i=>m.add(i)),m});try{const c=await fetch("/api/providers/test-bulk",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerIds:x})});if(c.ok){const m=await c.json();m.results&&k(i=>{const E={...i};for(const[oe,K]of Object.entries(m.results))E[oe]={success:!!K.success,msg:K.message||(K.success?"Connected successfully":"Connection failed"),latencyMs:K.latencyMs};return E})}else for(const m of r)await H(m.id)}catch{for(const c of r)await H(c.id)}finally{b(c=>{const m=new Set(c);return x.forEach(i=>m.delete(i)),m}),T(null)}},le=async()=>{if(f){B(!0);try{(await fetch(`/api/providers/${f.id}`,{method:"DELETE"})).ok&&(await S(),Q())}catch{}finally{B(!1),A(null)}}},Y=new Set(ie.map(t=>t.id)),V=p.filter(t=>!Y.has(t.id)).map(t=>{const s=X(t.id);return{id:t.id,name:t.name,image:(s==null?void 0:s.image)||(t.format==="anthropic"?"/assets/providers/anthropic/icon.png":"/assets/providers/openai/icon.png"),color:(s==null?void 0:s.color)||(t.format==="anthropic"?"#D97706":"#10A37F"),iconBg:(s==null?void 0:s.iconBg)||"#ffffff",category:"custom",format:t.format||"openai",baseUrl:t.baseUrl,models:t.models,thinkingMode:t.thinkingMode}}),R=(t,s=!1)=>{const r=t.category==="custom"||!Y.has(t.id),x=!!s&&r,c=G(t.id),m=C.has(t.id),i=I[t.id];return e.jsxs("div",{onClick:()=>z(t),className:"rt-card stagger-item group flex flex-col justify-between cursor-pointer relative overflow-hidden min-w-[300px] hover:border-blue-500/30 transition-all",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(Z,{src:t.image,name:t.name,color:t.color,iconBg:t.iconBg,size:"md",className:"group-hover:border-blue-500/40 transition-colors shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"text-xs font-bold text-slate-100 truncate group-hover:text-blue-400 transition-colors",children:t.name}),e.jsxs("div",{className:"mt-1 flex items-center gap-1.5 flex-wrap",children:[U(t)?e.jsx("span",{className:"rt-badge rt-badge--muted text-[10px]",children:"CLI Bridge"}):F(t)?e.jsxs("span",{className:"rt-badge rt-badge--success",children:[e.jsx("span",{className:"size-1.5 rounded-full bg-emerald-400"}),t.isLocal?"Ready (Local)":"Ready (Free)"]}):c>0?e.jsxs("span",{className:"rt-badge rt-badge--success",children:[e.jsx("span",{className:"size-1.5 rounded-full bg-emerald-400 animate-pulse"}),c," Connected"]}):e.jsx("span",{className:"rt-badge rt-badge--muted",children:"No connections"}),i&&e.jsx("span",{className:`rt-badge text-[10px] ${i.success?"bg-emerald-500/10 text-emerald-400 border border-emerald-500/20":"bg-red-500/10 text-red-400 border border-red-500/20"}`,title:i.msg,children:i.success?`● ${i.latencyMs?`${i.latencyMs}ms`:"Active"}`:"● Error"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:E=>{E.stopPropagation(),H(t.id)},disabled:m,title:"Test Connection",className:"p-2 rounded-lg bg-white/5 hover:bg-blue-500/20 text-slate-400 hover:text-blue-400 transition-colors cursor-pointer",children:e.jsx("span",{className:`material-symbols-outlined text-[16px] ${m?"animate-spin text-blue-400":""}`,children:m?"sync":"speed"})}),x&&e.jsx("button",{onClick:E=>{E.stopPropagation(),A(t)},title:"Delete Provider",className:"p-2 rounded-lg bg-white/5 hover:bg-red-500/20 text-slate-400 hover:text-red-400 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"delete"})})]})]}),i&&e.jsx("div",{className:`w-full py-1 px-3 text-[10px] font-mono border-t truncate ${i.success?"bg-emerald-500/10 text-emerald-400 border-emerald-500/20":"bg-red-500/10 text-red-400 border-red-500/20"}`,title:i.msg,children:i.success?`✓ ${i.msg}`:`✗ ${i.msg}`})]},t.id)};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:"flex flex-wrap items-center justify-between gap-4 p-4 rounded-2xl bg-[#0F1420]/70 border border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[e.jsx("span",{className:"font-semibold text-slate-300",children:"Filter Status:"}),e.jsxs("div",{className:"flex items-center bg-[#0A0D14] p-1 rounded-xl border border-[#1E293B]",children:[e.jsx("button",{onClick:()=>P("all"),className:`px-3 py-1 rounded-lg transition-colors font-medium ${v==="all"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"All Providers"}),e.jsx("button",{onClick:()=>P("connected"),className:`px-3 py-1 rounded-lg transition-colors font-medium ${v==="connected"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Connected Only"}),e.jsx("button",{onClick:()=>P("not_connected"),className:`px-3 py-1 rounded-lg transition-colors font-medium ${v==="not_connected"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Unconfigured"})]})]}),e.jsxs("div",{className:"text-xs text-slate-400 font-mono flex items-center gap-2",children:[e.jsx("span",{children:"Active Accounts:"}),e.jsx("span",{className:"px-2 py-0.5 rounded-md bg-blue-500/10 text-blue-400 border border-blue-500/20 font-bold",children:p.reduce((t,s)=>t+(s.accountsCount||0),0)})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",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-blue-400 text-[18px]",children:"add_circle"}),"Custom Providers (OpenAI & Anthropic Compatible)"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>{w(""),y("Default Account"),j("https://api.anthropic.com"),g({id:`custom-anthropic-${Date.now().toString().slice(-4)}`,name:"Custom Anthropic",image:"/assets/providers/anthropic/icon.png",category:"custom",format:"anthropic",baseUrl:"https://api.anthropic.com"})},className:"rt-btn rt-btn--primary",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"add"}),"Add Anthropic Compatible"]}),e.jsxs("button",{onClick:()=>{w(""),y("Default Account"),j("https://api.openai.com"),g({id:`custom-openai-${Date.now().toString().slice(-4)}`,name:"Custom OpenAI",image:"/assets/providers/openai/icon.png",category:"custom",format:"openai",baseUrl:"https://api.openai.com"})},className:"rt-btn rt-btn--secondary",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"add"}),"Add OpenAI Compatible"]}),e.jsxs("button",{onClick:()=>O(!0),className:"rt-btn rt-btn--secondary hover:border-blue-500/50",title:"Browse 124 community-curated routers & gateways",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[16px]",children:"explore"}),"Community Catalog"]})]})]}),V.filter(M).length>0?e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(290px,1fr))] gap-3",children:V.filter(M).map(t=>R(t,!0))}):e.jsxs("div",{className:"border border-dashed border-[#1E293B] bg-[#0E1320]/60 rounded-2xl p-5 text-center text-xs text-slate-400 flex items-center justify-center gap-2 hover:border-blue-500/30 transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[18px]",children:"cloud_sync"}),e.jsx("span",{children:V.length>0?"No custom providers match the current filter.":"Use the buttons above to register self-hosted vLLM, Ollama, LM Studio, or local API proxies."})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",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-blue-400 text-[18px]",children:"verified"}),"OAuth & Managed IDE Providers"]}),e.jsxs("button",{onClick:()=>J(ee,"OAuth Providers"),disabled:d==="OAuth Providers",className:"flex items-center gap-1.5 text-xs text-slate-400 hover:text-blue-400 px-3 py-1.5 rounded-lg hover:bg-white/5 transition-colors cursor-pointer font-medium disabled:opacity-50",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${d==="OAuth Providers"?"animate-spin text-blue-400":""}`,children:d==="OAuth Providers"?"sync":"play_arrow"}),d==="OAuth Providers"?"Testing...":"Test All"]})]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(290px,1fr))] gap-3",children:ee.filter(M).map(t=>R(t,!1))})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",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-emerald-400 text-[18px]",children:"redeem"}),"Free Tier & Community Gateways"]}),e.jsxs("button",{onClick:()=>J(te,"Free Tier Providers"),disabled:d==="Free Tier Providers",className:"flex items-center gap-1.5 text-xs text-slate-400 hover:text-blue-400 px-3 py-1.5 rounded-lg hover:bg-white/5 transition-colors cursor-pointer font-medium disabled:opacity-50",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${d==="Free Tier Providers"?"animate-spin text-emerald-400":""}`,children:d==="Free Tier Providers"?"sync":"play_arrow"}),d==="Free Tier Providers"?"Testing...":"Test All"]})]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(290px,1fr))] gap-3",children:te.filter(M).map(t=>R(t,!1))})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",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-blue-400 text-[18px]",children:"key"}),"Direct API Key Providers"]}),e.jsxs("button",{onClick:()=>J(se,"API Key Providers"),disabled:d==="API Key Providers",className:"flex items-center gap-1.5 text-xs text-slate-400 hover:text-blue-400 px-3 py-1.5 rounded-lg hover:bg-white/5 transition-colors cursor-pointer font-medium disabled:opacity-50",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${d==="API Key Providers"?"animate-spin text-blue-400":""}`,children:d==="API Key Providers"?"sync":"play_arrow"}),d==="API Key Providers"?"Testing...":"Test All"]})]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(290px,1fr))] gap-3",children:se.filter(M).map(t=>R(t,!1))})]}),e.jsx(ae,{isOpen:!!o,onClose:()=>{g(null),w(""),y("Default Account"),j(""),n(null)},maxWidthClass:"max-w-md",children:o&&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("div",{className:"flex items-center gap-3",children:[e.jsx(Z,{src:o.image,name:o.name,color:o.color,iconBg:o.iconBg,size:"sm"}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:o.name}),e.jsxs("span",{className:"text-[11px] text-blue-400 font-mono",children:[o.format||"openai"," protocol"]})]})]}),e.jsx("button",{onClick:()=>g(null),className:"text-slate-400 hover:text-white p-1 rounded-lg hover:bg-white/10",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"close"})})]}),a&&e.jsxs("div",{className:"p-3 rounded-xl bg-red-500/10 border border-red-500/20 text-xs text-red-400 flex items-start gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-red-400 shrink-0 mt-0.5",children:"error"}),e.jsx("span",{children:a})]}),e.jsxs("div",{className:"space-y-3 pt-1",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-300 mb-1",children:"Account Label / Nickname"}),e.jsx("input",{type:"text",value:_,onChange:t=>y(t.target.value),placeholder:"e.g. Work Pro Key 1",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500/30"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-300 mb-1",children:"Base URL Override"}),e.jsx("input",{type:"text",value:h,onChange:t=>j(t.target.value),placeholder:o.format==="anthropic"?"https://api.anthropic.com":o.baseUrl||"https://api.openai.com",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white font-mono focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500/30"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-300 mb-1",children:"API Key / Secret Token (AES-256-GCM Hardware Encrypted)"}),e.jsx("input",{type:"password",value:u,onChange:t=>w(t.target.value),placeholder:"sk-...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white font-mono focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500/30"})]}),e.jsxs("div",{className:"bg-[#0A0D14] p-3 rounded-xl border border-[#1E293B] text-[11px] text-slate-400 flex items-start gap-2.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-emerald-400 shrink-0 mt-0.5",children:"enhanced_encryption"}),e.jsx("span",{className:"leading-relaxed",children:"Keys are securely locked with your PC's machine ID salt. No cloud upload, no telemetry."})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{onClick:()=>g(null),disabled:L,className:"px-4 py-2 text-xs text-slate-400 hover:text-white transition-colors cursor-pointer disabled:opacity-50",children:"Cancel"}),e.jsx("button",{onClick:re,disabled:L,className:"rt-btn rt-btn--primary disabled:opacity-50",children:L?"Saving...":"Save & Connect"})]})]})}),e.jsx(ce,{isOpen:D,existingProviderIds:p.map(t=>t.id),onClose:()=>O(!1),onImportSuccess:async()=>{await S(),Q()}}),e.jsx(ne,{isOpen:!!f,title:"Delete Provider",message:`Are you sure you want to delete "${f==null?void 0:f.name}"? This will permanently remove the provider configuration and all associated accounts/credentials.`,confirmText:W?"Deleting...":"Delete",variant:"danger",onConfirm:le,onCancel:()=>A(null)})]})};export{ge as ProvidersTab};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e,r as x}from"./vendor-BcOI2aZ9.js";import{g as D}from"./metadataRegistry-B91sal4r.js";import{T as V}from"./ToolIcon-Cp4gSgFt.js";import{S as F}from"./Select-BNRH8LIG.js";import{C as Y,E as K}from"./EditAccountModal-D-_omvev.js";import{C as X}from"./ConfirmModal-DGvcf0gB.js";import"./index-C4NTQZ40.js";import"./lucide-Cc35htxl.js";const Z={antigravity:["Gemini (5h)","Gemini (Weekly)","Claude & GPT (5h)","Claude & GPT (Weekly)","Gemini 4 Argon (Weekly)"],github:["Chat","Completions","Premium Interactions"],copilot:["Chat","Completions","Premium Interactions"],claude:["5-Hour Window","5h Session","Session","7-Day Window","Weekly"],codex:["Session","Weekly","Credits","Balance"],openai:["Session","Weekly","Credits","Balance"],gemini:["Requests (RPM)","Requests (Daily)","Tokens (TPM)","Tokens (Daily)"],"gemini-cli":["Gemini (5h)","Gemini (Weekly)","Requests (RPM)","Requests (Daily)","Tokens (TPM)","Tokens (Daily)"],grok:["Session","Weekly","Requests","Tokens","Balance"],"grok-cli":["Session","Weekly","Requests","Tokens","Balance"],kiro:["Session","Weekly","Monthly","Credits"],deepseek:["Balance","Total Grants","Topped-up Balance"],minimax:["Coding Tokens","Standard Tokens","Balance"],"minimax-cn":["Coding Tokens","Standard Tokens","Balance"],glm:["Session","Weekly","Balance"],"glm-cn":["Session","Weekly","Balance"],qoder:["Daily","Weekly","Monthly","Balance"],"qoder-cn":["Daily","Weekly","Monthly","Balance"],xkiro:["Session (5h)","Weekly (7d)","Free Tokens (Daily)","Wallet Balance"],"xiaomi-tokenplan":["Monthly Tokens","Weekly Quota"],xmtp:["Monthly Tokens","Weekly Quota"],"xiaomi-mimo":["Monthly Tokens","Weekly Quota"],mimo:["Monthly Tokens","Weekly Quota"]},ee=new Proxy(Z,{get(o,n){if(typeof n!="string")return;const c=n.toLowerCase(),l=D(c);return l!=null&&l.quotaOrder?l.quotaOrder:o[c]},has(o,n){if(typeof n!="string")return!1;const c=n.toLowerCase(),l=D(c);return!!(l!=null&&l.quotaOrder)||c in o}});function te(o,n){if(!n||n.length<=1)return n?[...n]:[];const c=(o||"").toLowerCase(),l=D(c),h=(l==null?void 0:l.quotaOrder)||ee[c]||[];return[...n].sort((v,b)=>{const d=y=>{const m=(y||"").trim().toLowerCase(),u=h.findIndex(j=>{const p=j.toLowerCase();return m===p||m.startsWith(p)||p.startsWith(m)||m.includes(p)});return u===-1?9999:u},g=d(v.label),f=d(b.label);return g!==f?g-f:(v.label||"").localeCompare(b.label||"")})}function re(o,n,c,l){const h=c.toLowerCase(),v=(l==null?void 0:l.toLowerCase())==="kiro",b=h.includes("token"),d=h.includes("credit")||v&&!h.includes("request");if(b){if(n>=1e9){const g=`${(n/1e9).toFixed(1)}B`;return`${o>=1e9?`${(o/1e9).toFixed(2)}B`:o>=1e6?`${(o/1e6).toFixed(1)}M`:o.toLocaleString()} / ${g} tokens`}if(n>=1e6){const g=`${(n/1e6).toFixed(0)}M`;return`${o>=1e6?`${(o/1e6).toFixed(2)}M`:o.toLocaleString()} / ${g} tokens`}return n>0?`${o.toLocaleString()} / ${n.toLocaleString()} tokens`:`${o.toLocaleString()} tokens`}if(d){const g=n===1?"credit":"credits";return n>0?`${o.toLocaleString()} / ${n.toLocaleString()} ${g}`:`${o.toLocaleString()} ${g}`}return n===100&&!h.includes("req")?`${o}% used`:n>0?`${o.toLocaleString()} / ${n.toLocaleString()} reqs`:`${o.toLocaleString()} reqs`}const se=({label:o,used:n,total:c,percentage:l,resetInText:h="-",unlimited:v=!1,recurring:b=!0,providerId:d})=>{const f=(m=>m>=50?{text:"text-emerald-400",bg:"bg-emerald-500",bgTrack:"bg-emerald-500/15",emoji:"🟢"}:m>0?{text:"text-amber-400",bg:"bg-amber-500",bgTrack:"bg-amber-500/15",emoji:"🟡"}:{text:"text-red-400",bg:"bg-red-500",bgTrack:"bg-red-500/15",emoji:"🔴"})(l),y=b?"Reset":"Expires";return e.jsxs("div",{className:"space-y-1.5 py-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"font-medium text-slate-200 truncate pr-2",title:o,children:o}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx("span",{className:"text-[10px]",children:f.emoji}),e.jsx("span",{className:`font-semibold ${f.text}`,children:v?"100%":`${l}%`})]})]}),!v&&e.jsx("div",{className:`h-2 rounded-full overflow-hidden ${f.bgTrack} w-full`,children:e.jsx("div",{className:`h-full transition-all duration-300 rounded-full ${f.bg}`,style:{width:`${Math.min(100,Math.max(0,l))}%`}})}),e.jsxs("div",{className:"flex items-center justify-between text-[11px] text-slate-400",children:[e.jsx("span",{children:v?"Unlimited":re(n,c,o,d)}),h&&h!=="-"&&e.jsxs("div",{className:"flex items-center gap-1 font-mono text-[10px] text-slate-400",children:[e.jsx("span",{children:"•"}),e.jsxs("span",{children:[y," in ",h]})]})]})]})},ae={antigravity:"#4285F4",gemini:"#1A73E8","gemini-cli":"#1A73E8",claude:"#D97757",codex:"#10A37F",openai:"#10A37F",github:"#24292F",copilot:"#24292F",kiro:"#FF9900",deepseek:"#4D6BFE",grok:"#E11D48","grok-cli":"#E11D48",minimax:"#7C3AED","minimax-cn":"#7C3AED",qoder:"#EC4899","qoder-cn":"#EC4899",glm:"#0055FF","glm-cn":"#0055FF"},P=({account:o,loading:n=!1,onRefresh:c,onEdit:l,onToggle:h})=>{const[v,b]=x.useState(!1),d=D(o.providerId),g=(d==null?void 0:d.color)||ae[o.providerId.toLowerCase()]||"#3B82F6",f=async()=>{if(!(v||n)){b(!0);try{await c(o.accountId)}finally{b(!1)}}},y=n||v,m=x.useMemo(()=>{var p;let u=o.quotas||[];const j=(p=o.providerId)==null?void 0:p.toLowerCase();if(j==="antigravity"||j==="gemini-cli"){const $=["gemini (5h)","gemini (weekly)","claude & gpt (5h)","claude & gpt (weekly)","gemini 4 argon (weekly)"],S=u.filter(C=>$.some(I=>(C.label||"").toLowerCase().trim()===I));S.length>0&&(u=S)}return te(o.providerId,u)},[o.providerId,o.quotas]);return e.jsxs("div",{className:`flex flex-col justify-between bg-[#0F1420]/80 border border-[#1E293B] hover:border-slate-700/80 rounded-2xl p-4 sm:p-5 transition-all duration-200 shadow-lg min-w-[400px] ${o.isActive?"":"opacity-60 bg-[#0B0E17]/60"}`,children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 pb-3 border-b border-[#1E293B]/70",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(V,{src:(d==null?void 0:d.image)||`/assets/providers/${o.providerId}/icon.png`,name:o.providerId,color:g,iconBg:d==null?void 0:d.iconBg,size:"md"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"font-semibold text-slate-100 text-xs sm:text-sm capitalize truncate",children:o.providerId}),o.plan&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-md font-medium bg-blue-500/10 text-blue-400 border border-blue-500/20",children:o.plan})]}),e.jsx("div",{className:"text-[11px] text-slate-400 truncate max-w-[170px]",title:o.accountName,children:o.accountName})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:f,disabled:y,title:"Refresh Quota",className:"p-1.5 rounded-lg text-slate-400 hover:text-white hover:bg-[#1E293B]/70 transition-colors disabled:opacity-50 cursor-pointer",children:e.jsx("span",{className:`material-symbols-outlined text-[18px] ${y?"animate-spin text-blue-400":""}`,children:"refresh"})}),e.jsx("button",{onClick:()=>l(o),title:"Edit Account",className:"p-1.5 rounded-lg text-slate-400 hover:text-white hover:bg-[#1E293B]/70 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"edit"})}),e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer ml-1",title:"Toggle active status",children:[e.jsx("input",{type:"checkbox",checked:o.isActive,onChange:u=>h(o.accountId,u.target.checked),className:"sr-only peer"}),e.jsx("div",{className:"w-8 h-4.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-3.5 after:w-3.5 after:transition-all peer-checked:bg-blue-600"})]})]})]}),y&&m.length===0?e.jsxs("div",{className:"space-y-3 py-2",children:[e.jsx("div",{className:"h-4 bg-slate-800/60 rounded animate-pulse w-3/4"}),e.jsx("div",{className:"h-2 bg-slate-800/60 rounded-full animate-pulse w-full"}),e.jsx("div",{className:"h-4 bg-slate-800/60 rounded animate-pulse w-2/3"}),e.jsx("div",{className:"h-2 bg-slate-800/60 rounded-full animate-pulse w-full"})]}):m.length>0?e.jsx("div",{className:"space-y-2.5",children:m.map((u,j)=>e.jsx(se,{label:u.label,used:u.used,total:u.total,percentage:u.remainingPercentage,resetInText:u.resetInText,unlimited:u.unlimited,recurring:u.recurring,providerId:o.providerId},`${u.label}-${j}`))}):e.jsx("div",{className:"py-4 text-center text-xs text-slate-400 bg-[#0A0D14]/50 rounded-xl border border-[#1E293B]/50 px-3",children:o.error?e.jsx("span",{className:"text-red-400/90",children:o.error}):o.message||"No quota data available."})]}),e.jsxs("div",{className:"pt-3 mt-2 border-t border-[#1E293B]/50 flex items-center justify-between text-[10px] text-slate-500 font-mono",children:[e.jsx("span",{children:o.isActive?e.jsx("span",{className:"text-emerald-400 font-medium",children:"Active"}):e.jsx("span",{className:"text-slate-400",children:"Inactive"})}),o.lastFetchedAt&&e.jsxs("span",{children:["Updated ",new Date(o.lastFetchedAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]})]})},oe=({providers:o,selectedProvider:n,onSelectProvider:c,statusFilter:l,onSelectStatusFilter:h,sortMode:v,onSelectSortMode:b,autoRefresh:d,onToggleAutoRefresh:g,countdownSeconds:f,isRefreshingAll:y,onRefreshAll:m,onTurnOffEmpty:u,onTurnOnAvailable:j})=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 text-xs p-4 rounded-2xl bg-[#0F1420]/80 border border-[#1E293B] shadow-lg w-full",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[e.jsx(F,{value:n,onChange:c,options:[{value:"all",label:"All providers"},...o.map(p=>({value:p,label:p.toUpperCase()}))],className:"min-w-[140px]"}),e.jsx(F,{value:l,onChange:p=>h(p),options:[{value:"all",label:"All accounts"},{value:"active",label:"Active only"},{value:"inactive",label:"Turned off"}],className:"min-w-[130px]"}),e.jsx(F,{value:v,onChange:p=>b(p),options:[{value:"fixed",label:"Fixed order (Providers)"},{value:"expiring-first",label:"Expiring first"},{value:"quota-asc",label:"% Quota: low to high"},{value:"quota-desc",label:"% Quota: high to low"}],className:"min-w-[175px]"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[e.jsxs("button",{onClick:u,title:"Turn off all accounts with depleted (0%) quota",className:"flex items-center gap-1.5 px-3 py-1.5 rounded-xl border border-red-500/20 bg-red-500/10 text-red-400 hover:bg-red-500/20 transition-colors cursor-pointer font-medium active:scale-95",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"block"}),"Turn off Empty"]}),e.jsxs("button",{onClick:j,title:"Turn on accounts with available (>0%) quota",className:"flex items-center gap-1.5 px-3 py-1.5 rounded-xl border border-emerald-500/20 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20 transition-colors cursor-pointer font-medium active:scale-95",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"check_circle"}),"Turn on Available"]}),e.jsxs("div",{className:"flex items-center gap-2 bg-[#0A0D14] border border-[#1E293B] px-3 py-1.5 rounded-xl select-none",children:[e.jsx(Y,{size:"sm",checked:d,onChange:p=>g(p),label:"Autorefresh"}),d&&e.jsxs("span",{className:"font-mono text-[10px] text-blue-400 font-semibold bg-blue-500/10 px-1.5 py-0.5 rounded border border-blue-500/20",children:[f,"s"]})]}),e.jsx("button",{onClick:m,disabled:y,title:"Refresh all quotas",className:"p-1.5 rounded-xl border border-[#1E293B] bg-[#0A0D14] text-slate-400 hover:text-white hover:border-slate-600 transition-colors cursor-pointer disabled:opacity-50",children:e.jsx("span",{className:`material-symbols-outlined text-[17px] ${y?"animate-spin text-blue-400":""}`,children:"refresh"})})]})]}),B=60,W="mapigate_cached_quota_accounts",_="mapigate_quota_sort_mode",pe=({searchQuery:o=""})=>{const[n,c]=x.useState(()=>{try{const s=localStorage.getItem(W);if(s){const t=JSON.parse(s);if(Array.isArray(t)&&t.length>0)return t}}catch{}return[]}),[l,h]=x.useState(()=>n.length===0),[v,b]=x.useState(!1),[d,g]=x.useState("all"),[f,y]=x.useState("all"),[m,u]=x.useState(()=>{try{const s=localStorage.getItem(_);if(s==="fixed"||s==="expiring-first"||s==="quota-asc"||s==="quota-desc")return s}catch{}return"fixed"}),[j,p]=x.useState(!0),[$,S]=x.useState(B),[C,I]=x.useState(null),[T,E]=x.useState(null),k=x.useCallback(async(s=!1)=>{try{s&&b(!0);const r=await fetch(s?"/api/quota?force=true":"/api/quota");if(!r.ok)throw new Error(`HTTP error ${r.status}`);const a=await r.json();c(a);try{localStorage.setItem(W,JSON.stringify(a))}catch{}}catch(t){console.error("[QuotaTab] Failed to fetch quotas:",t)}finally{h(!1),b(!1)}},[]);x.useEffect(()=>{k(!1).then(()=>{k(!0)})},[k]),x.useEffect(()=>{if(!j)return;const s=setInterval(()=>{document.hidden||S(t=>t<=1?(k(!1),B):t-1)},1e3);return()=>clearInterval(s)},[j,k]);const Q=async()=>{b(!0),S(B),await k(!0)},R=async s=>{try{const t=await fetch(`/api/quota/${s}`);if(!t.ok)throw new Error(`HTTP error ${t.status}`);const r=await t.json();c(a=>a.map(i=>i.accountId===s?{...i,...r,sortOrder:i.sortOrder??r.sortOrder,createdAt:i.createdAt??r.createdAt}:i))}catch(t){console.error(`[QuotaTab] Failed to refresh account ${s}:`,t)}},M=async(s,t)=>{c(r=>r.map(a=>a.accountId===s?{...a,isActive:t}:a));try{(await fetch(`/api/quota/accounts/${s}/toggle`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:t})})).ok||c(a=>a.map(i=>i.accountId===s?{...i,isActive:!t}:i))}catch{c(a=>a.map(i=>i.accountId===s?{...i,isActive:!t}:i))}},G=async s=>{if(!C)return;const t=await fetch(`/api/quota/accounts/${C.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!t.ok){const a=await t.json().catch(()=>({}));throw new Error(a.error||"Failed to update account.")}const{account:r}=await t.json();r?c(a=>a.map(i=>i.accountId===C.id?r:i)):await k(!0)},U=()=>{const s=n.filter(t=>t.isActive&&t.quotas.length>0&&t.quotas.some(r=>!r.unlimited&&r.remainingPercentage===0));if(s.length===0){alert("No active accounts with depleted (0%) quota found.");return}E({isOpen:!0,title:"Turn off Depleted Accounts",message:`Are you sure you want to turn off ${s.length} account(s) with 0% quota? This will prevent upstream 429 rate limit errors.`,variant:"danger",confirmText:`Turn off (${s.length})`,onConfirm:async()=>{const t=s.map(r=>r.accountId);c(r=>r.map(a=>t.includes(a.accountId)?{...a,isActive:!1}:a)),E(null);try{await fetch("/api/quota/toggle-batch",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({accountIds:t,isActive:!1})})}catch(r){console.error("[QuotaTab] Failed to turn off depleted accounts:",r)}}})},z=()=>{const s=n.filter(t=>!t.isActive&&t.quotas.length>0&&t.quotas.every(r=>r.unlimited||r.remainingPercentage>0));if(s.length===0){alert("No inactive accounts with available (>0%) quota found.");return}E({isOpen:!0,title:"Turn on Available Accounts",message:`Activate ${s.length} account(s) that have recovered capacity?`,variant:"emerald",confirmText:`Turn on (${s.length})`,onConfirm:async()=>{const t=s.map(r=>r.accountId);c(r=>r.map(a=>t.includes(a.accountId)?{...a,isActive:!0}:a)),E(null);try{await fetch("/api/quota/toggle-batch",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({accountIds:t,isActive:!0})})}catch(r){console.error("[QuotaTab] Failed to turn on available accounts:",r)}}})},H=x.useMemo(()=>{const s=new Set;return n.forEach(t=>{t.providerId&&s.add(t.providerId.toLowerCase())}),Array.from(s).sort()},[n]),L=x.useMemo(()=>{let s=[...n];if(d!=="all"&&(s=s.filter(t=>t.providerId.toLowerCase()===d.toLowerCase())),f==="active"?s=s.filter(t=>t.isActive):f==="inactive"&&(s=s.filter(t=>!t.isActive)),o.trim()){const t=o.toLowerCase().trim();s=s.filter(r=>r.accountName.toLowerCase().includes(t)||r.providerId.toLowerCase().includes(t)||r.accountId.toLowerCase().includes(t))}if(m==="fixed")s.sort((t,r)=>{const a=t.providerId.localeCompare(r.providerId);if(a!==0)return a;const i=(t.sortOrder??0)-(r.sortOrder??0);if(i!==0)return i;if(t.createdAt&&r.createdAt&&t.createdAt!==r.createdAt)return t.createdAt-r.createdAt;const N=t.accountName.localeCompare(r.accountName);return N!==0?N:t.accountId.localeCompare(r.accountId)});else if(m==="expiring-first"){const t=r=>{const a=r.quotas.map(i=>i.resetAt).filter(i=>typeof i=="number"&&i>0);return a.length>0?Math.min(...a):Number.POSITIVE_INFINITY};s.sort((r,a)=>{const i=t(r)-t(a);if(i!==0)return i;const N=r.providerId.localeCompare(a.providerId);if(N!==0)return N;const A=(r.sortOrder??0)-(a.sortOrder??0);if(A!==0)return A;if(r.createdAt&&a.createdAt&&r.createdAt!==a.createdAt)return r.createdAt-a.createdAt;const w=r.accountName.localeCompare(a.accountName);return w!==0?w:r.accountId.localeCompare(a.accountId)})}else if(m==="quota-asc"){const t=r=>r.quotas.length===0?Number.POSITIVE_INFINITY:Math.min(...r.quotas.map(a=>a.remainingPercentage));s.sort((r,a)=>{const i=t(r)-t(a);if(i!==0)return i;const N=r.providerId.localeCompare(a.providerId);if(N!==0)return N;const A=(r.sortOrder??0)-(a.sortOrder??0);if(A!==0)return A;if(r.createdAt&&a.createdAt&&r.createdAt!==a.createdAt)return r.createdAt-a.createdAt;const w=r.accountName.localeCompare(a.accountName);return w!==0?w:r.accountId.localeCompare(a.accountId)})}else if(m==="quota-desc"){const t=r=>r.quotas.length===0?Number.NEGATIVE_INFINITY:Math.max(...r.quotas.map(a=>a.remainingPercentage));s.sort((r,a)=>{const i=t(a)-t(r);if(i!==0)return i;const N=r.providerId.localeCompare(a.providerId);if(N!==0)return N;const A=(r.sortOrder??0)-(a.sortOrder??0);if(A!==0)return A;if(r.createdAt&&a.createdAt&&r.createdAt!==a.createdAt)return r.createdAt-a.createdAt;const w=r.accountName.localeCompare(a.accountName);return w!==0?w:r.accountId.localeCompare(a.accountId)})}return s},[n,d,f,m,o]),{accountsWithData:q,accountsWithoutData:O}=x.useMemo(()=>{const s=[],t=[];for(const r of L)Array.isArray(r.quotas)&&r.quotas.length>0||r.error?s.push(r):t.push(r);return{accountsWithData:s,accountsWithoutData:t}},[L]),J=s=>{u(s);try{localStorage.setItem(_,s)}catch{}};return e.jsxs("div",{className:"space-y-6 w-full px-2 sm:px-4 pb-16 animate-rt-fade-in",children:[e.jsx(oe,{providers:H,selectedProvider:d,onSelectProvider:g,statusFilter:f,onSelectStatusFilter:y,sortMode:m,onSelectSortMode:J,autoRefresh:j,onToggleAutoRefresh:p,countdownSeconds:$,isRefreshingAll:v,onRefreshAll:Q,onTurnOffEmpty:U,onTurnOnAvailable:z}),l?e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(400px,1fr))] gap-4 w-full",children:[...Array(6)].map((s,t)=>e.jsxs("div",{className:"bg-[#0F1420]/80 border border-[#1E293B] rounded-2xl p-5 space-y-4 animate-pulse shadow-lg",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 bg-slate-800 rounded-xl"}),e.jsxs("div",{className:"space-y-2 flex-1",children:[e.jsx("div",{className:"h-4 bg-slate-800 rounded w-1/2"}),e.jsx("div",{className:"h-3 bg-slate-800 rounded w-3/4"})]})]}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx("div",{className:"h-3 bg-slate-800 rounded w-full"}),e.jsx("div",{className:"h-2 bg-slate-800 rounded-full w-full"}),e.jsx("div",{className:"h-3 bg-slate-800 rounded w-5/6"}),e.jsx("div",{className:"h-2 bg-slate-800 rounded-full w-full"})]})]},t))}):L.length===0?e.jsxs("div",{className:"p-12 text-center rounded-2xl bg-[#0F1420]/50 border border-[#1E293B] text-slate-400 space-y-3",children:[e.jsx("span",{className:"material-symbols-outlined text-[36px] text-slate-500",children:"account_balance_wallet"}),e.jsx("div",{className:"text-sm font-medium text-slate-300",children:"No matching accounts found"}),e.jsx("p",{className:"text-xs text-slate-500 max-w-sm mx-auto",children:n.length===0?"Connect provider accounts in the Providers tab to track real-time quota.":"Try adjusting your provider, status, or search filters above."})]}):e.jsxs("div",{className:"space-y-8 w-full",children:[q.length>0&&e.jsxs("div",{className:"space-y-3",children:[O.length>0&&e.jsxs("div",{className:"flex items-center gap-2 text-xs font-semibold text-slate-300",children:[e.jsx("span",{className:"size-2 rounded-full bg-emerald-400"}),e.jsxs("span",{children:["Accounts With Quota (",q.length,")"]})]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(400px,1fr))] gap-4 w-full",children:q.map(s=>e.jsx(P,{account:s,onRefresh:R,onEdit:t=>I({id:t.accountId,providerId:t.providerId,name:t.accountName,isActive:t.isActive,providerSpecificData:t.providerSpecificData}),onToggle:M},s.accountId))})]}),O.length>0&&e.jsxs("div",{className:`space-y-3 ${q.length>0?"pt-6 border-t border-[#1E293B]/70":""}`,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 pb-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs font-semibold text-slate-400",children:[e.jsx("span",{className:"size-2 rounded-full bg-slate-500"}),e.jsxs("span",{children:["Accounts Without Quota Data (",O.length,")"]})]}),e.jsx("span",{className:"text-[11px] text-slate-500 font-mono",children:"No active quota or unsupported metrics"})]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(400px,1fr))] gap-4 w-full",children:O.map(s=>e.jsx(P,{account:s,onRefresh:R,onEdit:t=>I({id:t.accountId,providerId:t.providerId,name:t.accountName,isActive:t.isActive,providerSpecificData:t.providerSpecificData}),onToggle:M},s.accountId))})]})]}),e.jsx(K,{isOpen:!!C,account:C,onClose:()=>I(null),onSave:G}),T&&e.jsx(X,{isOpen:T.isOpen,title:T.title,message:T.message,variant:T.variant,confirmText:T.confirmText,onConfirm:T.onConfirm,onCancel:()=>E(null)})]})};export{pe as QuotaTab};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e,r as i,a as ie}from"./vendor-BcOI2aZ9.js";import{Z as ce,A as de,D as xe,a as me,S as Q,b as pe,N as Z,c as he,d as ue,R as be,C as ee,e as te,T as fe,L as je,f as J,g as V,X as se,h as ge,i as ve,j as Ne,k as ae,l as we,F as ye,m as le,n as ke,o as Ce,p as Se,q as Te}from"./lucide-Cc35htxl.js";import{T as W}from"./ToolIcon-Cp4gSgFt.js";import{g as X}from"./metadataRegistry-B91sal4r.js";import{R as Ee,A as Le,C as Re,X as qe,Y as Be,T as $e,a as Me}from"./recharts-X4_nm3od.js";import{a as Fe,A as De}from"./index-C4NTQZ40.js";import{S as Y}from"./Select-BNRH8LIG.js";const Ae=({stats:t,loading:m})=>{const d=r=>(r||0).toLocaleString("en-US"),h=r=>`$${(r||0).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}`,c=(t==null?void 0:t.totalRequests)??0,p=(t==null?void 0:t.totalPromptTokens)??0,o=(t==null?void 0:t.totalCachedTokens)??0,x=(t==null?void 0:t.totalCompletionTokens)??0,j=(t==null?void 0:t.totalCost)??0,s=(t==null?void 0:t.totalTokensSaved)??0;return e.jsxs("div",{className:"w-full grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-3 sm:gap-4",children:[e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 flex flex-col justify-between hover:border-blue-500/30 transition-all shadow-xs",children:[e.jsxs("div",{className:"flex items-center justify-between text-slate-400 mb-2",children:[e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider",children:"Total Requests"}),e.jsx(ce,{className:"w-4 h-4 text-blue-400"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xl sm:text-2xl font-black text-white truncate",title:d(c),children:m?"...":d(c)}),e.jsx("span",{className:"text-[10px] text-slate-500 mt-0.5 block",children:"API Invocations"})]})]}),e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 flex flex-col justify-between hover:border-blue-500/30 transition-all shadow-xs",children:[e.jsxs("div",{className:"flex items-center justify-between text-blue-400 mb-2",children:[e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider",children:"Input Tokens"}),e.jsx(de,{className:"w-4 h-4 text-blue-400"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xl sm:text-2xl font-black text-blue-400 truncate",title:d(p),children:m?"...":d(p)}),e.jsx("span",{className:"text-[10px] text-slate-500 mt-0.5 block",children:"Prompt & context"})]})]}),e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 flex flex-col justify-between hover:border-cyan-500/30 transition-all shadow-xs",children:[e.jsxs("div",{className:"flex items-center justify-between text-cyan-400 mb-2",children:[e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider",children:"Cached Tokens"}),e.jsx(xe,{className:"w-4 h-4 text-cyan-400"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xl sm:text-2xl font-black text-cyan-400 truncate",title:d(o),children:m?"...":d(o)}),e.jsx("span",{className:"text-[10px] text-slate-500 mt-0.5 block",children:"Prompt cache hits"})]})]}),e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 flex flex-col justify-between hover:border-emerald-500/30 transition-all shadow-xs",children:[e.jsxs("div",{className:"flex items-center justify-between text-emerald-400 mb-2",children:[e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider",children:"Output Tokens"}),e.jsx(me,{className:"w-4 h-4 text-emerald-400"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xl sm:text-2xl font-black text-emerald-400 truncate",title:d(x),children:m?"...":d(x)}),e.jsx("span",{className:"text-[10px] text-slate-500 mt-0.5 block",children:"Generated output"})]})]}),e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 flex flex-col justify-between hover:border-purple-500/30 transition-all shadow-xs",children:[e.jsxs("div",{className:"flex items-center justify-between text-purple-400 mb-2",children:[e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider",children:"Tokens Saved"}),e.jsx(Q,{className:"w-4 h-4 text-purple-400"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xl sm:text-2xl font-black text-purple-400 truncate",title:d(s),children:m?"...":d(s)}),e.jsx("span",{className:"text-[10px] text-slate-500 mt-0.5 block",children:"Token Saver optimized"})]})]}),e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 flex flex-col justify-between hover:border-amber-500/30 transition-all shadow-xs",children:[e.jsxs("div",{className:"flex items-center justify-between text-amber-400 mb-2",children:[e.jsx("span",{className:"text-[11px] font-bold uppercase tracking-wider",children:"Est. Cost"}),e.jsx(pe,{className:"w-4 h-4 text-amber-400"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xl sm:text-2xl font-black text-amber-400 truncate",title:h(j),children:m?"...":`~${h(j)}`}),e.jsx("span",{className:"text-[10px] text-slate-500 mt-0.5 block",title:"Estimated, not actual billing",children:"Estimated, not actual"})]})]})]})},Pe={"github-copilot":"github",copilot:"github","devin-cli":"devin","devin-desktop":"devin","devin-cli-agentic":"devin",dvd:"devin"};function H(t){if(!t)return{id:"unknown",name:"Unknown",color:"#64748B"};const m=t.toLowerCase().trim(),d=Pe[m]||m,h=X(d)||X(m);return h?{id:h.id,name:h.name,color:h.color||"#64748B",image:h.image,iconBg:h.iconBg}:{id:t,name:t.charAt(0).toUpperCase()+t.slice(1),color:"#64748B"}}const Oe=5,Ue=({providers:t=[],activeRequests:m=[]})=>{const[d,h]=i.useState(null),[c,p]=i.useState(1),[o,x]=i.useState({x:0,y:0}),[j,s]=i.useState(!1),r=i.useRef({x:0,y:0}),S=i.useRef({x:0,y:0}),N=i.useRef(!1),L=i.useRef(null),O=i.useCallback(()=>{p(1),x({x:0,y:0})},[]),F=i.useCallback(()=>{p(a=>Math.min(2.5,+(a+.2).toFixed(2)))},[]),D=i.useCallback(()=>{p(a=>Math.max(.4,+(a-.2).toFixed(2)))},[]);i.useEffect(()=>{const a=L.current;if(!a)return;const v=u=>{if(!u.ctrlKey&&!u.metaKey)return;u.preventDefault();const f=u.deltaY<0?1.1:.9;p(w=>{const B=+(w*f).toFixed(2);return Math.min(2.5,Math.max(.4,B))})};return a.addEventListener("wheel",v,{passive:!1}),()=>{a.removeEventListener("wheel",v)}},[]);const T=i.useCallback(a=>{a.button===0&&(s(!0),N.current=!1,r.current={x:a.clientX,y:a.clientY},S.current={...o})},[o]);i.useEffect(()=>{const a=u=>{if(!j)return;const f=u.clientX-r.current.x,w=u.clientY-r.current.y;(Math.abs(f)>3||Math.abs(w)>3)&&(N.current=!0),x({x:S.current.x+f,y:S.current.y+w})},v=()=>{s(!1)};return j&&(window.addEventListener("mousemove",a),window.addEventListener("mouseup",v)),()=>{window.removeEventListener("mousemove",a),window.removeEventListener("mouseup",v)}},[j]);const k=i.useMemo(()=>{const a=new Set;for(const v of m)if(v.provider){const u=v.provider.toLowerCase();a.add(u);const f=H(u);a.add(f.id.toLowerCase())}return a},[m]),{displayProviders:C,totalCount:E}=i.useMemo(()=>{const a=[...t];for(const f of m)f.provider&&a.push(f.provider);const u=Array.from(new Set(a)).filter(f=>{if(!f)return!1;const w=f.toLowerCase().trim();return w!=="unknown"&&w!=="null"&&w!=="undefined"}).sort((f,w)=>{const B=k.has(f.toLowerCase()),$=k.has(w.toLowerCase());return B&&!$?-1:!B&&$?1:f.localeCompare(w)});return{displayProviders:u.slice(0,10),totalCount:u.length}},[t,m,k]),y=400,n=220,g=i.useMemo(()=>{const a=C.length;if(a===0)return{items:[]};const v=Math.min(300,160+a*15),u=Math.min(150,90+a*8);return{items:C.map((w,B)=>{const $=H(w),R=k.has(w.toLowerCase())||k.has($.id.toLowerCase()),M=(d==null?void 0:d.toLowerCase())===w.toLowerCase()||(d==null?void 0:d.toLowerCase())===$.id.toLowerCase(),A=-Math.PI/2+2*Math.PI*B/a,q=y+v*Math.cos(A),P=n+u*Math.sin(A),re=Math.abs(q-y)<20,U=P<n?-1:1,oe=q<y?-1:1;let I,_,K,z;if(re)I=y,_=n+U*Math.min(u*.5,50),K=q,z=P-U*Math.min(u*.5,50);else{const G=Math.abs(Math.sin(A))>.35;I=G?y:y+(q-y)*.5,_=G?n+U*Math.min(u*.7,75):n,K=q-oe*Math.min(v*.45,60),z=P}const ne=`M ${y} ${n} C ${I.toFixed(1)} ${_.toFixed(1)}, ${K.toFixed(1)} ${z.toFixed(1)}, ${q.toFixed(1)} ${P.toFixed(1)}`;return{id:w,meta:$,isActive:R,isFocused:M,px:q,py:P,pathData:ne}})}},[C,k,d]),l=m.length,b=l>0;return e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 sm:p-5 flex flex-col shadow-xs w-full",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{className:"w-4 h-4 text-cyan-400"}),e.jsx("h3",{className:"text-sm sm:text-base font-bold text-white",children:"Active Routing Topology"}),e.jsx("span",{className:"text-xs text-slate-500",children:E>10?`(Top 10 of ${E} Mesh)`:"(Real-time Mesh)"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[e.jsxs("div",{className:"flex items-center bg-[#070A11] border border-[#1E293B] rounded-lg p-0.5 mr-1",title:"Ctrl + Scroll or use buttons to Zoom",children:[e.jsx("button",{type:"button",onClick:F,className:"p-1 hover:text-white text-slate-400 hover:bg-slate-800 rounded transition-colors cursor-pointer",title:"Zoom In","aria-label":"Zoom In",children:e.jsx(he,{className:"w-3.5 h-3.5"})}),e.jsxs("span",{className:"px-1.5 text-[10px] font-mono text-slate-400 select-none min-w-[34px] text-center",children:[Math.round(c*100),"%"]}),e.jsx("button",{type:"button",onClick:D,className:"p-1 hover:text-white text-slate-400 hover:bg-slate-800 rounded transition-colors cursor-pointer",title:"Zoom Out","aria-label":"Zoom Out",children:e.jsx(ue,{className:"w-3.5 h-3.5"})}),(c!==1||o.x!==0||o.y!==0)&&e.jsx("button",{type:"button",onClick:O,className:"p-1 hover:text-cyan-400 text-slate-400 hover:bg-slate-800 rounded transition-colors cursor-pointer ml-0.5 border-l border-[#1E293B]",title:"Reset View","aria-label":"Reset View",children:e.jsx(be,{className:"w-3.5 h-3.5"})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-slate-400",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-slate-600"}),e.jsx("span",{children:"Idle"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-cyan-400 font-semibold",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-cyan-400 animate-ping"}),e.jsx("span",{children:"Active Stream"})]})]})]}),e.jsx("div",{ref:L,onMouseDown:T,className:`relative h-72 sm:h-80 w-full rounded-lg overflow-hidden bg-[#070A11] border border-[#162032] flex items-center justify-center select-none ${j?"cursor-grabbing":"cursor-grab"}`,children:C.length===0?e.jsxs("div",{className:"text-center p-6 text-slate-500 text-xs sm:text-sm",children:[e.jsx(Z,{className:"w-8 h-8 text-slate-600 mx-auto mb-2 opacity-60"}),e.jsx("p",{children:"No upstream provider traffic recorded yet"})]}):e.jsxs("div",{className:"relative w-full h-full will-change-transform",style:{transform:`translate(${o.x}px, ${o.y}px) scale(${c})`,transformOrigin:"center center",transition:j?"none":"transform 0.15s ease-out"},children:[e.jsxs("svg",{className:"absolute inset-0 w-full h-full pointer-events-none",viewBox:"0 0 800 440",preserveAspectRatio:"xMidYMid meet",children:[e.jsx("defs",{children:e.jsxs("filter",{id:"plasma-glow",x:"-30%",y:"-30%",width:"160%",height:"160%",children:[e.jsx("feGaussianBlur",{stdDeviation:"3.5",result:"blur"}),e.jsx("feComposite",{in:"SourceGraphic",in2:"blur",operator:"over"})]})}),g.items.map(a=>a.isActive?e.jsxs("g",{children:[e.jsx("path",{d:a.pathData,fill:"none",stroke:"#22d3ee",strokeWidth:"6",strokeOpacity:"0.25",strokeLinecap:"round",filter:"url(#plasma-glow)"}),e.jsx("path",{d:a.pathData,fill:"none",stroke:"#38bdf8",strokeWidth:"2.5",strokeOpacity:"0.85",strokeLinecap:"round"}),e.jsx("path",{d:a.pathData,fill:"none",stroke:"#ffffff",strokeWidth:"1.2",strokeLinecap:"round"}),Array.from({length:Oe},(v,u)=>e.jsx("circle",{r:u%2===0?3.5:2,fill:u%2===0?"#22d3ee":"#ffffff",opacity:"0.9",children:e.jsx("animateMotion",{dur:`${.8+u*.15}s`,repeatCount:"indefinite",path:a.pathData,begin:`${u*.12}s`})},`orb-${a.id}-${u}`))]},`edge-active-${a.id}`):e.jsx("path",{d:a.pathData,fill:"none",stroke:"#1E293B",strokeWidth:"1.5",strokeDasharray:"4 5",strokeLinecap:"round"},`edge-${a.id}`))]}),e.jsx("div",{className:"absolute inset-0 pointer-events-none",children:e.jsxs("svg",{className:"w-full h-full",viewBox:"0 0 800 440",preserveAspectRatio:"xMidYMid meet",children:[e.jsx("foreignObject",{x:y-80,y:n-26,width:"160",height:"54",className:"overflow-visible pointer-events-auto",children:e.jsxs("div",{className:`flex items-center justify-center gap-2.5 px-3.5 py-2.5 rounded-2xl border-2 transition-all duration-300 select-none ${b?"border-cyan-400 bg-gradient-to-br from-blue-900/80 via-cyan-900/50 to-blue-950 shadow-[0_0_24px_rgba(34,211,238,0.5)]":"border-blue-500/40 bg-[#0A0E18] shadow-lg"}`,children:[e.jsx(W,{src:"/favicon.svg",name:"Mapigate",color:"#38BDF8",size:"sm",fallback:e.jsx("span",{className:"material-symbols-outlined text-[18px] text-cyan-400",children:"graph_5"}),className:b?"shadow-[0_0_14px_rgba(34,211,238,0.7)] border-cyan-400":""}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-black tracking-wide text-white",children:"MAPIGATE"}),e.jsx("div",{className:"text-[9px] text-slate-400 font-mono",children:"Gateway"})]}),l>0&&e.jsx("span",{className:"ml-1 px-1.5 py-0.5 rounded-full bg-cyan-400 text-black text-[10px] font-black animate-pulse",children:l})]})}),g.items.map(a=>e.jsx("foreignObject",{x:a.px-75,y:a.py-22,width:"150",height:"44",className:"overflow-visible pointer-events-auto",children:e.jsxs("div",{onClick:v=>{v.stopPropagation(),!N.current&&h(u=>u===a.id?null:a.id)},className:`flex items-center gap-2 px-2.5 py-1.5 rounded-xl border-2 transition-all duration-300 cursor-pointer select-none bg-[#0B0F19] ${a.isActive?"shadow-[0_0_18px_rgba(56,189,248,0.4)]":a.isFocused?"border-blue-500/70 bg-[#0F1626]":"border-[#1E293B] hover:border-slate-500"}`,style:{borderColor:a.isActive?a.meta.color:a.isFocused?"#3B82F6":void 0},children:[e.jsx(W,{src:a.meta.image,name:a.meta.name,color:a.meta.color,iconBg:a.meta.iconBg,size:"sm"}),e.jsxs("div",{className:"min-w-0 flex-1 truncate",children:[e.jsx("span",{className:"text-xs font-bold block truncate",style:{color:a.isActive?a.meta.color:a.isFocused?"#93C5FD":"#E2E8F0"},title:a.meta.name,children:a.meta.name}),e.jsx("span",{className:"text-[9px] text-slate-500 font-mono block",children:"Upstream"})]}),a.isActive&&e.jsxs("span",{className:"relative flex h-2 w-2 ml-auto shrink-0",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full opacity-75",style:{backgroundColor:a.meta.color}}),e.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2",style:{backgroundColor:a.meta.color}})]})]})},`node-${a.id}`))]})})]})})]})},Ie=({data:t,period:m,loading:d})=>{const[h,c]=i.useState("tokens"),p=s=>h==="cost"?`$${s>=10?s.toFixed(0):s.toFixed(2)}`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(0)}k`:String(s),x={tokens:{stroke:"#38BDF8",fill:"#0284C7",label:"Total Tokens"},requests:{stroke:"#A855F7",fill:"#7E22CE",label:"Requests"},cost:{stroke:"#F59E0B",fill:"#B45309",label:"Estimated Cost ($)"}}[h],j=t.reduce((s,r)=>s+(r[h]||0),0);return e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 sm:p-5 flex flex-col shadow-xs w-full",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-4",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm sm:text-base font-bold text-white flex items-center gap-2",children:["Usage Trend",e.jsxs("span",{className:"text-xs font-normal text-slate-500",children:["(",m.toUpperCase(),")"]})]}),e.jsxs("span",{className:"text-xs text-slate-400 mt-0.5 block",children:["Aggregated ",x.label.toLowerCase(),":"," ",e.jsx("span",{className:"font-semibold text-slate-200",children:h==="cost"?`$${j.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}`:j.toLocaleString("en-US")})]})]}),e.jsx("div",{className:"bg-[#151C2C] p-0.5 rounded-lg border border-[#243048] flex items-center text-xs",children:["tokens","requests","cost"].map(s=>e.jsx("button",{onClick:()=>c(s),className:`px-3 py-1.5 rounded-md font-semibold capitalize transition-all ${h===s?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:s},s))})]}),e.jsx("div",{className:"h-64 sm:h-72 w-full",children:d?e.jsx("div",{className:"h-full w-full flex items-center justify-center text-slate-500 text-sm",children:"Loading metrics..."}):t.length===0?e.jsx("div",{className:"h-full w-full flex items-center justify-center text-slate-500 text-sm",children:"No request activity recorded for this period."}):e.jsx(Ee,{width:"100%",height:"100%",children:e.jsxs(Le,{data:t,margin:{top:10,right:10,left:-10,bottom:0},children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:`gradient-${h}`,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:x.stroke,stopOpacity:.35}),e.jsx("stop",{offset:"95%",stopColor:x.stroke,stopOpacity:0})]})}),e.jsx(Re,{strokeDasharray:"3 3",stroke:"#1E293B",vertical:!1}),e.jsx(qe,{dataKey:"label",stroke:"#64748B",fontSize:11,tickLine:!1,axisLine:{stroke:"#1E293B"}}),e.jsx(Be,{stroke:"#64748B",fontSize:11,tickFormatter:p,tickLine:!1,axisLine:{stroke:"#1E293B"},width:45}),e.jsx($e,{content:({active:s,payload:r,label:S})=>{if(s&&r&&r.length){const N=r[0].payload;return e.jsxs("div",{className:"bg-[#0B0F19]/95 backdrop-blur-md border border-[#2A374F] rounded-lg p-3 text-xs shadow-xl min-w-[160px]",children:[e.jsx("p",{className:"font-bold text-slate-200 mb-1.5 border-b border-slate-800 pb-1",children:N.time||S}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex justify-between items-center text-cyan-400",children:[e.jsx("span",{children:"Tokens:"}),e.jsx("span",{className:"font-mono font-semibold",children:N.tokens.toLocaleString()})]}),e.jsxs("div",{className:"flex justify-between items-center text-purple-400",children:[e.jsx("span",{children:"Requests:"}),e.jsx("span",{className:"font-mono font-semibold",children:N.requests.toLocaleString()})]}),e.jsxs("div",{className:"flex justify-between items-center text-amber-400",children:[e.jsx("span",{children:"Cost:"}),e.jsxs("span",{className:"font-mono font-semibold",children:["$",N.cost.toLocaleString("en-US",{minimumFractionDigits:4,maximumFractionDigits:4})]})]})]})]})}return null}}),e.jsx(Me,{type:"monotone",dataKey:h,stroke:x.stroke,strokeWidth:2.5,fillOpacity:1,fill:`url(#gradient-${h})`,dot:!1,activeDot:{r:5,fill:x.stroke,stroke:"#0E1320",strokeWidth:2}})]})})})]})},_e=({byModel:t})=>{const[m,d]=i.useState("tokens"),c=Object.entries(t||{}).map(([o,x])=>{const j=(x.promptTokens||0)+(x.completionTokens||0);return{key:o,name:x.rawModel||o,provider:x.provider||"default",requests:x.requests||0,totalTokens:j,promptTokens:x.promptTokens||0,completionTokens:x.completionTokens||0,cost:x.cost||0}}).sort((o,x)=>m==="tokens"?x.totalTokens-o.totalTokens:x.requests-o.requests).slice(0,5),p=c.length>0?m==="tokens"?c[0].totalTokens:c[0].requests:1;return e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 sm:p-5 flex flex-col justify-between shadow-xs w-full h-full",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h3",{className:"text-sm sm:text-base font-bold text-white flex items-center gap-2",children:[e.jsx(ee,{className:"w-4 h-4 text-blue-400"}),"Top Models"]}),e.jsxs("div",{className:"bg-[#151C2C] p-0.5 rounded-lg border border-[#243048] flex items-center text-xs",children:[e.jsx("button",{onClick:()=>d("tokens"),className:`px-2.5 py-1 rounded-md font-semibold transition-all ${m==="tokens"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Tokens"}),e.jsx("button",{onClick:()=>d("requests"),className:`px-2.5 py-1 rounded-md font-semibold transition-all ${m==="requests"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Requests"})]})]}),c.length===0?e.jsx("div",{className:"py-12 text-center text-slate-500 text-xs",children:"No model usage recorded yet."}):e.jsx("div",{className:"space-y-3.5",children:c.map((o,x)=>{const j=m==="tokens"?o.totalTokens:o.requests,s=p>0?Math.round(j/p*100):0;return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2 truncate max-w-[70%]",children:[e.jsx("span",{className:"w-4.5 h-4.5 rounded-sm bg-slate-800 text-slate-300 font-bold text-[10px] flex items-center justify-center shrink-0",children:x+1}),e.jsx("span",{className:"font-semibold text-slate-200 truncate",title:o.name,children:o.name}),e.jsx("span",{className:"px-1.5 py-0.2 rounded text-[10px] bg-slate-800/80 text-slate-400 border border-slate-700/50 shrink-0",children:o.provider})]}),e.jsxs("div",{className:"text-right shrink-0",children:[e.jsx("span",{className:"font-mono font-bold text-slate-200",children:m==="tokens"?o.totalTokens.toLocaleString():o.requests.toLocaleString()}),e.jsx("span",{className:"text-[10px] text-slate-500 ml-1",children:m==="tokens"?"tok":"req"})]})]}),e.jsx("div",{className:"w-full bg-[#151D2F] h-2 rounded-full overflow-hidden",children:e.jsx("div",{className:"bg-gradient-to-r from-blue-500 to-cyan-400 h-full rounded-full transition-all duration-500",style:{width:`${Math.max(4,s)}%`}})})]},o.key)})})]})},Ke=({byProvider:t})=>{const m=Object.entries(t||{}).map(([p,o])=>{const x=(o.promptTokens||0)+(o.completionTokens||0);return{id:p,requests:o.requests||0,totalTokens:x,cost:o.cost||0}}),d=m.reduce((p,o)=>p+o.requests,0)||1,h=m.sort((p,o)=>o.requests-p.requests),c={antigravity:"#3B82F6",claude:"#F97316",anthropic:"#F97316",openai:"#10B981",github:"#6366F1",gemini:"#38BDF8",deepseek:"#8B5CF6",default:"#64748B"};return e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 sm:p-5 flex flex-col justify-between shadow-xs w-full h-full",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h3",{className:"text-sm sm:text-base font-bold text-white flex items-center gap-2",children:[e.jsx(te,{className:"w-4 h-4 text-cyan-400"}),"By Provider"]}),e.jsxs("span",{className:"text-xs text-slate-400",children:[h.length," ",h.length===1?"provider":"providers"," active"]})]}),h.length===0?e.jsx("div",{className:"py-12 text-center text-slate-500 text-xs",children:"No provider activity recorded yet."}):e.jsx("div",{className:"space-y-3.5",children:h.map(p=>{const o=Math.round(p.requests/d*100),x=c[p.id.toLowerCase()]||c.default;return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2 truncate",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full shrink-0",style:{backgroundColor:x}}),e.jsx("span",{className:"font-semibold text-slate-200 uppercase tracking-wide truncate",children:p.id})]}),e.jsxs("div",{className:"flex items-center gap-3 text-right shrink-0",children:[e.jsxs("span",{className:"font-mono text-slate-400",children:[p.requests.toLocaleString()," reqs (",o,"%)"]}),e.jsxs("span",{className:"font-mono text-xs font-semibold text-slate-200",children:["$",p.cost.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})]})]})]}),e.jsx("div",{className:"w-full bg-[#151D2F] h-2 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${Math.max(4,o)}%`,backgroundColor:x}})})]},p.id)})})]})},ze=({byProvider:t,byModel:m,byAccount:d,byApiKey:h})=>{const[c,p]=i.useState("model");let o=[];c==="provider"?o=Object.entries(t||{}).map(([s,r])=>({id:s,name:s.toUpperCase(),sublabel:"Provider Gateway",requests:r.requests||0,promptTokens:r.promptTokens||0,cachedTokens:r.cachedTokens||0,completionTokens:r.completionTokens||0,cost:r.cost||0})):c==="model"?o=Object.entries(m||{}).map(([s,r])=>({id:s,name:r.rawModel||s,sublabel:r.provider?`Provider: ${r.provider}`:void 0,requests:r.requests||0,promptTokens:r.promptTokens||0,cachedTokens:r.cachedTokens||0,completionTokens:r.completionTokens||0,cost:r.cost||0,lastUsed:r.lastUsed})):c==="account"?o=Object.entries(d||{}).map(([s,r])=>({id:s,name:r.accountName||r.accountId||s,sublabel:r.rawModel?`${r.rawModel} (${r.provider||"default"})`:void 0,requests:r.requests||0,promptTokens:r.promptTokens||0,cachedTokens:r.cachedTokens||0,completionTokens:r.completionTokens||0,cost:r.cost||0,lastUsed:r.lastUsed})):o=Object.entries(h||{}).map(([s,r])=>({id:s,name:r.apiKeyName||(s==="no_key"?"Direct / No Key":s),sublabel:s==="no_key"?"Unauthenticated / Local Ping":`Key ID: ${s}`,requests:r.requests||0,promptTokens:r.promptTokens||0,cachedTokens:r.cachedTokens||0,completionTokens:r.completionTokens||0,cost:r.cost||0,lastUsed:r.lastUsed})),o=o.filter(s=>s.promptTokens+s.completionTokens>0),o.sort((s,r)=>r.requests-s.requests);const x=s=>(s||0).toLocaleString("en-US"),j=s=>`$${(s||0).toLocaleString("en-US",{minimumFractionDigits:4,maximumFractionDigits:4})}`;return e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 sm:p-5 flex flex-col shadow-xs w-full",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(fe,{className:"w-4 h-4 text-blue-400"}),e.jsx("h3",{className:"text-sm sm:text-base font-bold text-white",children:"Usage Breakdown"}),e.jsxs("span",{className:"text-xs text-slate-500",children:["(",o.length," records)"]})]}),e.jsxs("div",{className:"bg-[#151C2C] p-0.5 rounded-lg border border-[#243048] flex items-center text-xs",children:[e.jsxs("span",{className:"px-2 text-slate-500 flex items-center gap-1",children:[e.jsx(je,{className:"w-3 h-3"})," Group:"]}),["model","provider","account","apiKey"].map(s=>e.jsx("button",{onClick:()=>p(s),className:`px-3 py-1.5 rounded-md font-semibold capitalize transition-all ${c===s?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:s==="apiKey"?"API Key":s},s))]})]}),o.length===0?e.jsx("div",{className:"py-12 text-center text-slate-500 text-sm",children:"No usage records found for this period."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left text-xs border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-slate-800 text-slate-400 uppercase text-[10px] tracking-wider",children:[e.jsx("th",{className:"py-2.5 px-3",children:"Name"}),e.jsx("th",{className:"py-2.5 px-3 text-right",children:"Requests"}),e.jsx("th",{className:"py-2.5 px-3 text-right text-blue-400",children:"Input Tokens"}),e.jsx("th",{className:"py-2.5 px-3 text-right text-cyan-400",children:"Cached"}),e.jsx("th",{className:"py-2.5 px-3 text-right text-emerald-400",children:"Output Tokens"}),e.jsx("th",{className:"py-2.5 px-3 text-right text-amber-400",children:"Est. Cost"}),e.jsx("th",{className:"py-2.5 px-3 text-right",children:"Last Used"})]})}),e.jsx("tbody",{className:"divide-y divide-slate-800/60",children:o.map(s=>e.jsxs("tr",{className:"hover:bg-slate-800/25 transition-colors",children:[e.jsxs("td",{className:"py-2.5 px-3",children:[e.jsx("div",{className:"font-semibold text-slate-200",children:s.name}),s.sublabel&&e.jsx("div",{className:"text-[10px] text-slate-500 mt-0.5",children:s.sublabel})]}),e.jsx("td",{className:"py-2.5 px-3 text-right font-mono font-medium text-slate-300",children:x(s.requests)}),e.jsx("td",{className:"py-2.5 px-3 text-right font-mono text-blue-400/90",children:x(s.promptTokens)}),e.jsx("td",{className:"py-2.5 px-3 text-right font-mono text-cyan-400/90",children:x(s.cachedTokens)}),e.jsx("td",{className:"py-2.5 px-3 text-right font-mono text-emerald-400/90",children:x(s.completionTokens)}),e.jsx("td",{className:"py-2.5 px-3 text-right font-mono font-semibold text-amber-400/90",children:j(s.cost)}),e.jsx("td",{className:"py-2.5 px-3 text-right font-mono text-slate-400 text-[11px]",children:s.lastUsed?new Date(s.lastUsed).toLocaleDateString():"-"})]},s.id))})]})})]})},Ye=({detail:t,isOpen:m,onClose:d})=>{var T,k,C,E,y,n,g,l,b,a,v,u,f,w,B,$;const[h,c]=i.useState(!1),[p,o]=i.useState(null),[x,j]=i.useState(!1),[s,r]=i.useState("client"),{backdropProps:S}=Fe(d,!m);if(i.useEffect(()=>{if(!m)return;const R=A=>{A.key==="Escape"&&d()};document.addEventListener("keydown",R);const M=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",R),document.body.style.overflow=M}},[m,d]),!m||!t||typeof document>"u")return null;const N=(R,M)=>{navigator.clipboard.writeText(R),M==="id"?(c(!0),setTimeout(()=>c(!1),2e3)):(o(M),setTimeout(()=>o(null),2e3))},L=Number(t.status),O=L>=200&&L<300||t.status==="success"||t.status==="ok",F=L===429||t.status==="rate_limited",D=()=>F?e.jsx("span",{className:"px-2.5 py-1 rounded-md text-xs font-bold bg-amber-500/20 text-amber-400 border border-amber-500/30",children:"429 Rate Limit"}):O?e.jsx("span",{className:"px-2.5 py-1 rounded-md text-xs font-bold bg-emerald-500/20 text-emerald-400 border border-emerald-500/30",children:t.status==="success"||t.status==="ok"?"200 OK":`${t.status} OK`}):e.jsx("span",{className:"px-2.5 py-1 rounded-md text-xs font-bold bg-red-500/20 text-red-400 border border-red-500/30",children:t.status||"500 Error"});return ie.createPortal(e.jsx("div",{className:"fixed inset-0 z-[9999] flex justify-end bg-black/70 backdrop-blur-xs animate-rt-fade-in",...S,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:R=>R.stopPropagation(),children:[e.jsxs("div",{className:"p-4 sm:p-5 border-b border-[#1E293B] flex items-center justify-between bg-[#0A0E18]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[D(),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-sm sm:text-base font-bold text-white flex items-center gap-2",children:[e.jsx("span",{children:t.model||"Unknown Model"}),t.provider&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-slate-800 text-slate-300 font-mono",children:t.provider})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-slate-400 mt-0.5",children:[e.jsx("span",{className:"font-mono text-[11px] truncate max-w-[200px]",title:t.id,children:t.id}),e.jsx("button",{onClick:()=>N(t.id,"id"),className:"p-1 hover:text-white transition-colors",title:"Copy Request ID",children:h?e.jsx(J,{className:"w-3.5 h-3.5 text-emerald-400"}):e.jsx(V,{className:"w-3.5 h-3.5"})})]})]})]}),e.jsx("button",{onClick:d,className:"p-2 rounded-lg bg-slate-800/60 hover:bg-slate-700 text-slate-400 hover:text-white transition-colors",children:e.jsx(se,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6 space-y-5 text-xs",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3 bg-[#111726] border border-[#1E293B] rounded-xl p-3.5",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"text-slate-500 uppercase tracking-wider text-[10px] block font-semibold flex items-center gap-1",children:[e.jsx(ge,{className:"w-3 h-3"})," Latency"]}),e.jsx("span",{className:"font-mono text-sm font-bold text-slate-200 mt-1 block",children:((T=t.latency)==null?void 0:T.totalMs)!=null?`${t.latency.totalMs} ms`:"-"}),((k=t.latency)==null?void 0:k.ttftMs)!=null&&e.jsxs("span",{className:"text-[10px] text-slate-500 font-mono",children:["TTFT: ",t.latency.ttftMs,"ms"]})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-slate-500 uppercase tracking-wider text-[10px] block font-semibold flex items-center gap-1",children:[e.jsx(te,{className:"w-3 h-3"})," Account"]}),e.jsx("span",{className:"font-mono text-xs font-semibold text-slate-200 mt-1 block truncate",children:t.accountName||t.connectionId||"Default"}),e.jsx("span",{className:"text-[10px] text-slate-500 font-mono",children:t.provider||"-"})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-slate-500 uppercase tracking-wider text-[10px] block font-semibold flex items-center gap-1",children:[e.jsx(ve,{className:"w-3 h-3"})," Client Tool"]}),e.jsx("span",{className:"font-mono text-xs font-semibold text-slate-200 mt-1 block truncate",title:t.clientTool,children:t.clientTool||"unknown"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500 uppercase tracking-wider text-[10px] block font-semibold",children:"Cost Est."}),e.jsxs("span",{className:"font-mono text-sm font-bold text-amber-400 mt-1 block",children:["$",t.cost!=null?t.cost.toLocaleString("en-US",{minimumFractionDigits:4,maximumFractionDigits:4}):"0.0000"]})]})]}),e.jsxs("div",{className:"bg-[#111726] border border-[#1E293B] rounded-xl p-4",children:[e.jsxs("h4",{className:"text-xs font-bold uppercase tracking-wider text-slate-400 mb-3 flex items-center gap-1.5",children:[e.jsx(ee,{className:"w-3.5 h-3.5 text-blue-400"})," Token Breakdown"]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3 text-center",children:[e.jsxs("div",{className:"bg-[#0B0F19] p-2.5 rounded-lg border border-slate-800",children:[e.jsx("span",{className:"text-[10px] text-slate-400 block uppercase font-semibold",children:"Input"}),e.jsx("span",{className:"font-mono text-base font-bold text-blue-400 mt-1 block",children:(((C=t.tokens)==null?void 0:C.promptTokens)||0).toLocaleString()})]}),e.jsxs("div",{className:"bg-[#0B0F19] p-2.5 rounded-lg border border-slate-800",children:[e.jsx("span",{className:"text-[10px] text-slate-400 block uppercase font-semibold",children:"Cached"}),e.jsx("span",{className:"font-mono text-base font-bold text-cyan-400 mt-1 block",children:(((E=t.tokens)==null?void 0:E.cachedTokens)||0).toLocaleString()})]}),e.jsxs("div",{className:"bg-[#0B0F19] p-2.5 rounded-lg border border-slate-800",children:[e.jsx("span",{className:"text-[10px] text-slate-400 block uppercase font-semibold",children:"Output"}),e.jsx("span",{className:"font-mono text-base font-bold text-emerald-400 mt-1 block",children:(((y=t.tokens)==null?void 0:y.completionTokens)||0).toLocaleString()})]}),e.jsxs("div",{className:"bg-[#0B0F19] p-2.5 rounded-lg border border-slate-800",children:[e.jsx("span",{className:"text-[10px] text-slate-400 block uppercase font-semibold",children:"Tokens Saved"}),e.jsx("span",{className:"font-mono text-base font-bold text-purple-400 mt-1 block",children:(((n=t.tokens)==null?void 0:n.tokensSavedByRtk)||0).toLocaleString()})]})]})]}),e.jsxs("div",{className:"bg-[#111726] border border-[#1E293B] rounded-xl overflow-hidden",children:[e.jsxs("button",{onClick:()=>j(!x),className:"w-full p-3.5 flex items-center justify-between text-left hover:bg-slate-800/40 transition-colors",children:[e.jsxs("span",{className:"font-bold text-xs text-slate-300 flex items-center gap-2",children:[e.jsx(Q,{className:"w-4 h-4 text-emerald-400"}),"HTTP Headers (Sanitized)"]}),x?e.jsx(Ne,{className:"w-4 h-4 text-slate-400"}):e.jsx(ae,{className:"w-4 h-4 text-slate-400"})]}),x&&e.jsxs("div",{className:"p-3.5 border-t border-[#1E293B] space-y-3 bg-[#0B0F19]",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-wider block mb-1",children:"Client Inbound Headers:"}),e.jsx("pre",{className:"font-mono text-[11px] p-2.5 rounded bg-[#070A11] border border-slate-800/80 overflow-x-auto text-slate-300",children:JSON.stringify(((g=t.request)==null?void 0:g.headers)||{},null,2)})]}),((l=t.providerRequest)==null?void 0:l.headers)&&e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-wider block mb-1",children:"Provider Outbound Headers:"}),e.jsx("pre",{className:"font-mono text-[11px] p-2.5 rounded bg-[#070A11] border border-slate-800/80 overflow-x-auto text-slate-300",children:JSON.stringify(t.providerRequest.headers,null,2)})]}),(((b=t.response)==null?void 0:b.headers)||((a=t.providerResponse)==null?void 0:a.headers))&&e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-wider block mb-1",children:"Response Headers:"}),e.jsx("pre",{className:"font-mono text-[11px] p-2.5 rounded bg-[#070A11] border border-slate-800/80 overflow-x-auto text-slate-300",children:JSON.stringify(((v=t.response)==null?void 0:v.headers)||((u=t.providerResponse)==null?void 0:u.headers),null,2)})]})]})]}),e.jsxs("div",{className:"bg-[#111726] border border-[#1E293B] rounded-xl p-4 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-[#0B0F19] p-1 rounded-lg border border-slate-800",children:[e.jsx("button",{onClick:()=>r("client"),className:`px-3 py-1 rounded text-xs font-semibold transition-all ${s==="client"?"bg-blue-600 text-white":"text-slate-400 hover:text-white"}`,children:"Client Request"}),e.jsx("button",{onClick:()=>r("providerReq"),className:`px-3 py-1 rounded text-xs font-semibold transition-all ${s==="providerReq"?"bg-blue-600 text-white":"text-slate-400 hover:text-white"}`,children:"Provider Request"}),e.jsx("button",{onClick:()=>r("response"),className:`px-3 py-1 rounded text-xs font-semibold transition-all ${s==="response"?"bg-blue-600 text-white":"text-slate-400 hover:text-white"}`,children:"Response Output"})]}),e.jsx("button",{onClick:()=>{var M,A,q,P;const R=s==="client"?(M=t.request)==null?void 0:M.body:s==="providerReq"?(A=t.providerRequest)==null?void 0:A.body:((q=t.response)==null?void 0:q.body)||((P=t.providerResponse)==null?void 0:P.body);N(JSON.stringify(R,null,2),s)},className:"px-2.5 py-1 rounded-md bg-slate-800 hover:bg-slate-700 text-slate-300 hover:text-white flex items-center gap-1.5 transition-colors text-xs",children:p===s?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"w-3.5 h-3.5 text-emerald-400"}),e.jsx("span",{children:"Copied"})]}):e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Copy JSON"})]})})]}),e.jsx("div",{className:"relative rounded-lg bg-[#070A11] border border-slate-800/80 p-3 max-h-96 overflow-y-auto",children:e.jsx("pre",{className:"font-mono text-[11px] text-slate-300 whitespace-pre-wrap leading-relaxed",children:JSON.stringify(s==="client"?((f=t.request)==null?void 0:f.body)||{message:"No request body captured"}:s==="providerReq"?((w=t.providerRequest)==null?void 0:w.body)||{message:"Same as client or pass-through"}:((B=t.response)==null?void 0:B.body)||(($=t.providerResponse)==null?void 0:$.body)||{message:"Stream completed successfully"},null,2)})})]})]})]})}),document.body)},Ge=()=>{const[t,m]=i.useState(null),[d,h]=i.useState(!1),[c,p]=i.useState(1),[o,x]=i.useState(20),[j,s]=i.useState(""),[r,S]=i.useState("all"),[N,L]=i.useState("all"),[O,F]=i.useState([]),[D,T]=i.useState(null),[k,C]=i.useState(!1),E=i.useCallback(async()=>{try{const l=await fetch("/api/usage/providers");if(l.ok){const b=await l.json();Array.isArray(b)&&F(b)}}catch{}},[]),y=i.useCallback(async()=>{h(!0);try{const l=new URLSearchParams;l.set("page",String(c)),l.set("pageSize",String(o)),r!=="all"&&l.set("provider",r),N!=="all"&&l.set("status",N),j.trim()&&l.set("search",j.trim());const b=await fetch(`/api/usage/request-details?${l.toString()}`);if(b.ok){const a=await b.json();m(a)}}catch(l){console.error("Failed to fetch request details:",l)}finally{h(!1)}},[c,o,r,N,j]);i.useEffect(()=>{E()},[E]),i.useEffect(()=>{y()},[y]);const n=async l=>{try{const b=await fetch(`/api/usage/request-details/${l.id}`);if(b.ok){const a=await b.json();T(a)}else T(l)}catch{T(l)}C(!0)},g=l=>{const b=String(l||"");return b==="200"||b==="success"||b==="ok"?e.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-bold bg-emerald-500/20 text-emerald-400 border border-emerald-500/30",children:"200 OK"}):b==="429"||b==="rate_limited"?e.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-bold bg-amber-500/20 text-amber-400 border border-amber-500/30",children:"429"}):e.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-bold bg-red-500/20 text-red-400 border border-red-500/30",children:b||"500"})};return e.jsxs("div",{className:"w-full space-y-4",children:[e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl p-3.5 flex flex-wrap items-center justify-between gap-3 shadow-xs",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5 flex-1 min-w-[280px]",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px] max-w-md",children:[e.jsx(we,{className:"w-4 h-4 text-slate-500 absolute left-3 top-1/2 -translate-y-1/2"}),e.jsx("input",{type:"text",placeholder:"Search by model, ID, provider, tool...",value:j,onChange:l=>{s(l.target.value),p(1)},className:"w-full pl-9 pr-8 py-1.5 rounded-lg bg-[#070A11] border border-slate-800 text-xs text-slate-200 placeholder-slate-500 focus:outline-hidden focus:border-blue-500"}),j&&e.jsx("button",{type:"button",onClick:()=>{s(""),p(1)},className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-400 hover:text-white transition-colors cursor-pointer flex items-center justify-center",title:"Clear search",children:e.jsx(se,{className:"w-3.5 h-3.5"})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[e.jsx(ye,{className:"w-3.5 h-3.5 text-slate-500"}),e.jsx(Y,{value:r,onChange:l=>{S(l),p(1)},options:[{value:"all",label:"All Providers"},...O.map(l=>({value:l,label:l.toUpperCase()}))],className:"min-w-[140px]"})]}),e.jsx("div",{className:"flex items-center text-xs",children:e.jsx(Y,{value:N,onChange:l=>{L(l),p(1)},options:[{value:"all",label:"All Statuses"},{value:"200",label:"200 OK"},{value:"429",label:"429 Rate Limit"},{value:"500",label:"500 Error"}],className:"min-w-[130px]"})})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:()=>y(),disabled:d,className:"p-1.5 rounded-lg bg-[#151D2F] border border-slate-700/60 text-slate-300 hover:text-white hover:bg-slate-800 transition-colors",title:"Refresh logs",children:e.jsx(le,{className:`w-4 h-4 ${d?"animate-spin text-blue-400":""}`})}),e.jsx("span",{className:"text-xs text-slate-400 font-mono",children:t!=null&&t.pagination?`${t.pagination.totalItems} records`:""})]})]}),e.jsxs("div",{className:"bg-[#0E1320] border border-[#1E293B] rounded-xl overflow-hidden shadow-xs",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left text-xs border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-slate-800 text-slate-400 uppercase text-[10px] tracking-wider bg-[#0A0E18]",children:[e.jsx("th",{className:"py-3 px-3.5",children:"Status"}),e.jsx("th",{className:"py-3 px-3.5",children:"Time"}),e.jsx("th",{className:"py-3 px-3.5",children:"Model"}),e.jsx("th",{className:"py-3 px-3.5",children:"Provider"}),e.jsx("th",{className:"py-3 px-3.5",children:"Tool / Client"}),e.jsx("th",{className:"py-3 px-3.5 text-right text-blue-400",children:"In Tok"}),e.jsx("th",{className:"py-3 px-3.5 text-right text-emerald-400",children:"Out Tok"}),e.jsx("th",{className:"py-3 px-3.5 text-right",children:"Latency"}),e.jsx("th",{className:"py-3 px-3.5 text-right text-amber-400",children:"Cost"})]})}),e.jsx("tbody",{className:"divide-y divide-slate-800/60",children:d&&(!(t!=null&&t.details)||t.details.length===0)?e.jsx("tr",{children:e.jsx("td",{colSpan:9,className:"py-12 text-center text-slate-500",children:"Loading request records..."})}):!(t!=null&&t.details)||t.details.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:9,className:"py-12 text-center text-slate-500",children:"No matching request logs found."})}):t.details.map(l=>{var b,a,v;return e.jsxs("tr",{onClick:()=>n(l),className:"hover:bg-blue-600/10 cursor-pointer transition-colors group",children:[e.jsx("td",{className:"py-2.5 px-3.5",children:g(l.status)}),e.jsx("td",{className:"py-2.5 px-3.5 font-mono text-[11px] text-slate-400 whitespace-nowrap",children:new Date(l.timestamp).toLocaleTimeString()}),e.jsx("td",{className:"py-2.5 px-3.5 font-semibold text-slate-200 group-hover:text-blue-400 transition-colors truncate max-w-[180px]",children:l.model||"unknown"}),e.jsx("td",{className:"py-2.5 px-3.5",children:e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] bg-slate-800 text-slate-300 font-mono",children:l.provider||"-"})}),e.jsx("td",{className:"py-2.5 px-3.5 font-mono text-slate-400 truncate max-w-[140px]",title:l.clientTool,children:l.clientTool||"-"}),e.jsx("td",{className:"py-2.5 px-3.5 text-right font-mono text-blue-400/90",children:(((b=l.tokens)==null?void 0:b.promptTokens)||0).toLocaleString()}),e.jsx("td",{className:"py-2.5 px-3.5 text-right font-mono text-emerald-400/90",children:(((a=l.tokens)==null?void 0:a.completionTokens)||0).toLocaleString()}),e.jsx("td",{className:"py-2.5 px-3.5 text-right font-mono text-slate-300",children:((v=l.latency)==null?void 0:v.totalMs)!=null?`${l.latency.totalMs}ms`:"-"}),e.jsxs("td",{className:"py-2.5 px-3.5 text-right font-mono font-semibold text-amber-400/90",children:["$",l.cost!=null?l.cost.toLocaleString("en-US",{minimumFractionDigits:4,maximumFractionDigits:4}):"0.0000"]})]},l.id)})})]})}),(t==null?void 0:t.pagination)&&t.pagination.totalPages>1&&e.jsxs("div",{className:"p-3 border-t border-slate-800 bg-[#0A0E18] flex items-center justify-between text-xs text-slate-400",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:"Rows per page:"}),e.jsx(Y,{value:String(o),onChange:l=>{x(Number(l)),p(1)},options:[{value:"10",label:"10"},{value:"20",label:"20"},{value:"50",label:"50"}],className:"w-20"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{children:["Page ",e.jsx("span",{className:"font-bold text-slate-200",children:t.pagination.page})," of"," ",e.jsx("span",{className:"font-bold text-slate-200",children:t.pagination.totalPages})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{disabled:!t.pagination.hasPrev,onClick:()=>p(l=>Math.max(1,l-1)),className:"p-1.5 rounded bg-slate-800 hover:bg-slate-700 text-slate-300 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:e.jsx(ke,{className:"w-4 h-4"})}),e.jsx("button",{disabled:!t.pagination.hasNext,onClick:()=>p(l=>l+1),className:"p-1.5 rounded bg-slate-800 hover:bg-slate-700 text-slate-300 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:e.jsx(ae,{className:"w-4 h-4"})})]})]})]})]}),e.jsx(Ye,{detail:D,isOpen:k,onClose:()=>C(!1)})]})},et=()=>{const[t,m]=i.useState("overview"),[d,h]=i.useState("7d"),[c,p]=i.useState(null),[o,x]=i.useState([]),[j,s]=i.useState([]),[r,S]=i.useState([]),[N,L]=i.useState(!0),[O,F]=i.useState(!0),[D,T]=i.useState(!1),k=i.useRef(null),C=i.useCallback(async n=>{try{L(!0);const g=await fetch(`/api/usage/stats?period=${n}`);if(g.ok){const l=await g.json();p(l),l.activeRequests&&s(l.activeRequests),l.recentRequests&&S(l.recentRequests)}}catch(g){console.error("Failed to fetch stats:",g)}finally{L(!1)}},[]),E=i.useCallback(async n=>{try{F(!0);const g=await fetch(`/api/usage/chart?period=${n}`);if(g.ok){const l=await g.json();x(l)}}catch(g){console.error("Failed to fetch chart data:",g)}finally{F(!1)}},[]);i.useEffect(()=>{C(d),E(d)},[d,C,E]),i.useEffect(()=>{let n=null,g=null;const l=()=>{try{const b=De.getToken(),a=`/api/usage/stream?period=${encodeURIComponent(d)}`,v=b?`${a}&token=${encodeURIComponent(b)}`:a;n=new EventSource(v),k.current=n,n.onopen=()=>{T(!0)},n.addEventListener("stats",u=>{try{const f=JSON.parse(u.data);p(f),f.activeRequests&&s(f.activeRequests),f.recentRequests&&S(f.recentRequests)}catch{}}),n.addEventListener("pending",u=>{try{const f=JSON.parse(u.data);f.activeRequests&&s(f.activeRequests)}catch{}}),n.onerror=()=>{T(!1),n==null||n.close(),k.current=null,g=setTimeout(l,5e3)}}catch{T(!1)}};return l(),()=>{g&&clearTimeout(g),n&&n.close(),k.current=null}},[d]);const y=Object.keys((c==null?void 0:c.byProvider)||{});return e.jsxs("div",{className:"w-full min-w-0 space-y-6 px-2 sm:px-4 lg:px-6 pb-20 animate-rt-fade-in",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 bg-[#0B0F19] border border-[#1E293B] rounded-2xl p-2 sm:p-2.5 shadow-sm",children:[e.jsxs("div",{className:"bg-[#151C2C] p-1 rounded-xl border border-[#243048] flex items-center",children:[e.jsxs("button",{onClick:()=>m("overview"),className:`px-3.5 py-1.5 rounded-lg text-xs font-bold flex items-center gap-2 transition-all ${t==="overview"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:[e.jsx(Ce,{className:"w-3.5 h-3.5"}),"Overview"]}),e.jsxs("button",{onClick:()=>m("details"),className:`px-3.5 py-1.5 rounded-lg text-xs font-bold flex items-center gap-2 transition-all ${t==="details"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:[e.jsx(Se,{className:"w-3.5 h-3.5"}),"Details (Inspector)"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[e.jsxs("div",{className:"hidden sm:flex items-center gap-1.5 px-2.5 py-1 rounded-lg bg-[#151C2C] border border-slate-800 text-[11px] text-slate-400",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${D?"bg-emerald-400 shadow-[0_0_8px_#34d399]":"bg-amber-400"}`}),e.jsx("span",{className:"font-mono text-[10px]",children:D?"LIVE TELEMETRY":"POLLING"})]}),t==="overview"&&e.jsx("div",{className:"bg-[#151C2C] p-1 rounded-xl border border-[#243048] flex items-center text-xs",children:["today","24h","7d","30d","60d","90d","all"].map(n=>e.jsx("button",{onClick:()=>h(n),className:`px-2.5 sm:px-3 py-1 rounded-lg uppercase font-semibold transition-all ${d===n?"bg-blue-600/30 text-blue-400 border border-blue-500/40 shadow-xs":"text-slate-400 hover:text-white"}`,children:n},n))}),e.jsx("button",{onClick:()=>{C(d),E(d)},className:"p-2 rounded-xl bg-[#151C2C] border border-[#243048] text-slate-300 hover:text-white hover:bg-slate-800 transition-colors",title:"Refresh statistics",children:e.jsx(le,{className:`w-3.5 h-3.5 ${N?"animate-spin text-blue-400":""}`})})]})]}),t==="overview"&&e.jsxs("div",{className:"space-y-6 w-full",children:[e.jsx(Ae,{stats:c,loading:N}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-5 w-full",children:[e.jsx("div",{className:"lg:col-span-7 w-full flex",children:e.jsx(Ue,{providers:y,activeRequests:j})}),e.jsxs("div",{className:"lg:col-span-5 w-full bg-[#0E1320] border border-[#1E293B] rounded-xl p-4 sm:p-5 flex flex-col justify-between shadow-xs",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B] shrink-0",children:[e.jsxs("span",{className:"text-sm font-bold text-slate-200 uppercase tracking-wider flex items-center gap-2",children:[e.jsx(Te,{className:"w-4 h-4 text-blue-400"}),"Recent Requests"]}),e.jsxs("span",{className:"text-[10px] text-cyan-400 font-mono bg-cyan-500/10 border border-cyan-500/20 px-2 py-0.5 rounded-full flex items-center gap-1",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-cyan-400 animate-pulse"}),"Live Stream"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto mt-2 min-h-[220px] max-h-[300px] pr-1",children:r.length===0?e.jsx("div",{className:"py-16 text-center text-slate-500 text-xs",children:"No recent proxy requests yet. Call /v1/messages or /v1/chat/completions to see live logs."}):e.jsxs("table",{className:"w-full text-left text-xs font-mono border-collapse table-fixed",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-slate-500 text-[10px] uppercase border-b border-[#1E293B]",children:[e.jsx("th",{className:"pb-2 font-semibold pr-2",children:"Model / Provider"}),e.jsx("th",{className:"pb-2 font-semibold text-right px-2 w-[125px]",children:"In / Out"}),e.jsx("th",{className:"pb-2 font-semibold text-right pl-2 pr-2 w-[95px]",children:"When"})]})}),e.jsx("tbody",{className:"divide-y divide-[#1E293B]/50",children:r.slice(0,15).map((n,g)=>{const l=n.status==="success"||n.status==="ok",b=n.requestedModel&&n.requestedModel!==n.model?`${n.model} (via ${n.requestedModel}) · ${n.provider||"unknown"}`:`${n.model} · ${n.provider||"unknown"}`;return e.jsxs("tr",{className:"hover:bg-slate-800/30 transition-colors",children:[e.jsx("td",{className:"py-2 pr-2 overflow-hidden",title:b,children:e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${l?"bg-emerald-400":"bg-red-400"}`}),e.jsx("span",{className:"text-slate-200 text-xs truncate font-medium",children:n.model}),n.provider&&e.jsx("span",{className:"text-[9px] text-slate-400 font-mono uppercase px-1 py-0.5 rounded bg-slate-800 border border-slate-700/50 shrink-0",children:n.provider})]})}),e.jsxs("td",{className:"py-2 text-right whitespace-nowrap px-2 text-[11px] w-[125px]",children:[e.jsxs("span",{className:"text-blue-400",children:[n.promptTokens.toLocaleString(),"↑"]})," ",e.jsxs("span",{className:"text-emerald-400",children:[n.completionTokens.toLocaleString(),"↓"]})]}),e.jsx("td",{className:"py-2 text-right text-[10px] text-slate-400 whitespace-nowrap pl-2 pr-2 w-[95px]",children:typeof n.timestamp=="number"?new Date(n.timestamp).toLocaleTimeString():new Date(String(n.timestamp)).toLocaleTimeString()})]},n.id||g)})})]})})]})]}),e.jsx(Ie,{data:o,period:d,loading:O}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-5 w-full",children:[e.jsx(_e,{byModel:(c==null?void 0:c.byModel)||{}}),e.jsx(Ke,{byProvider:(c==null?void 0:c.byProvider)||{}})]}),e.jsx(ze,{byProvider:(c==null?void 0:c.byProvider)||{},byModel:(c==null?void 0:c.byModel)||{},byAccount:(c==null?void 0:c.byAccount)||{},byApiKey:(c==null?void 0:c.byApiKey)||{}})]}),t==="details"&&e.jsx(Ge,{})]})};export{et as UsageTab};
|