mapigate 0.5.123 → 0.5.130

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +1 -1
  2. package/dist/core/adapters/anthropic/requestOpenAiToAnthropic.js +42 -5
  3. package/dist/core/adapters/anthropicAdapter.js +2 -2
  4. package/dist/core/adapters/helpers/toolCallRescue.js +6 -1
  5. package/dist/core/capabilities/constants.js +12 -0
  6. package/dist/core/capabilities/modelDictionary.js +1 -0
  7. package/dist/core/capabilities/patterns.js +25 -13
  8. package/dist/core/scanner/modelScanner.js +10 -5
  9. package/dist/mitm/handlers/kiro/config.js +1 -0
  10. package/dist/mitm/manager.js +1 -1
  11. package/dist/mitm/portConflict.js +38 -19
  12. package/dist/providers/catalog/xiaomi-tokenplan/provider.js +44 -11
  13. package/dist/providers/core/base/anthropicProvider.js +1 -1
  14. package/dist/providers/runtime/antigravity/executor.js +24 -6
  15. package/dist/providers/runtime/bedrock/provider.js +1 -1
  16. package/dist/providers/runtime/gemini-cli/provider.js +6 -1
  17. package/dist/providers/runtime/mimo/provider.js +43 -10
  18. package/dist/server/proxy/singleModelExecutor.js +7 -1
  19. package/dist/shared/utils/extractText.js +31 -0
  20. package/dist/web/assets/{CliToolsTab-D-0zU55K.js → CliToolsTab-Ck8EuOcF.js} +1 -1
  21. package/dist/web/assets/{CombosTab-V_ldcQni.js → CombosTab-CLPru5aK.js} +1 -1
  22. package/dist/web/assets/{ConfirmModal-B7vVauYn.js → ConfirmModal-1KqBoeRh.js} +1 -1
  23. package/dist/web/assets/{ConsoleLogTab-Byt7Fr4V.js → ConsoleLogTab-DC2FAcl1.js} +1 -1
  24. package/dist/web/assets/{EditAccountModal-p6rlIU5X.js → EditAccountModal-1EbG3eyM.js} +1 -1
  25. package/dist/web/assets/{EndpointTab-BHYn9Syj.js → EndpointTab-C-gwVRmb.js} +1 -1
  26. package/dist/web/assets/{MitmTab-sRzVrlgW.js → MitmTab-C2kTKbAV.js} +4 -4
  27. package/dist/web/assets/ModelAutocompleteInput-K8-vMnIb.js +1 -0
  28. package/dist/web/assets/{ProviderDetailPage-DgClsBMU.js → ProviderDetailPage-BSqwg2fW.js} +1 -1
  29. package/dist/web/assets/{ProvidersTab-CPMTBmXq.js → ProvidersTab-w9OOjPmA.js} +1 -1
  30. package/dist/web/assets/{QuotaTab-NaCPxtWq.js → QuotaTab-C43xP8JP.js} +1 -1
  31. package/dist/web/assets/{SettingsTab-BUKXj5iT.js → SettingsTab-BMs0BtId.js} +1 -1
  32. package/dist/web/assets/{UsageTab-BDTnu1v_.js → UsageTab-C5MbpcRp.js} +1 -1
  33. package/dist/web/assets/{index-BdD7LHGu.js → index-DVeDwPjn.js} +2 -2
  34. package/dist/web/assets/{metadataRegistry-7DDoxaR3.js → metadataRegistry-BMKXREeE.js} +1 -1
  35. package/dist/web/assets/{providersData-Br5RocnM.js → providersData-D7kilpPx.js} +1 -1
  36. package/dist/web/index.html +1 -1
  37. package/package.json +1 -1
  38. package/dist/web/assets/ModelAutocompleteInput-ClwXyzE7.js +0 -1
@@ -224,7 +224,13 @@ export async function executeSingleModel(options) {
224
224
  res.once("close", onClientClose);
225
225
  }
226
226
  const upstreamTimeoutMs = Number(process.env.MAPIGATE_UPSTREAM_TIMEOUT_MS) || 180_000;
227
- const timeoutSignal = AbortSignal.timeout(upstreamTimeoutMs);
227
+ const isStreaming = upstreamBody?.stream !== false && !isPanel;
228
+ // Streaming generations with large contexts (e.g. 100k+ tokens) can take many minutes.
229
+ // Use a generous ceiling (30 minutes) for streaming so active token streams aren't aborted mid-sentence at 180s.
230
+ const effectiveTimeoutMs = isStreaming
231
+ ? Math.max(upstreamTimeoutMs, 1_800_000)
232
+ : upstreamTimeoutMs;
233
+ const timeoutSignal = AbortSignal.timeout(effectiveTimeoutMs);
228
234
  const combinedSignal = AbortSignal.any
229
235
  ? AbortSignal.any([abortController.signal, timeoutSignal])
230
236
  : abortController.signal;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Extracts plain text from OpenAI / Responses / Anthropic message content
3
+ * (handles string or array of text / input_text / output_text blocks).
4
+ */
5
+ export function extractPlainTextContent(content) {
6
+ if (typeof content === "string")
7
+ return content;
8
+ if (Array.isArray(content)) {
9
+ const parts = [];
10
+ for (const item of content) {
11
+ if (typeof item === "string") {
12
+ parts.push(item);
13
+ }
14
+ else if (item && typeof item === "object") {
15
+ const block = item;
16
+ if ((block.type === "text" ||
17
+ block.type === "input_text" ||
18
+ block.type === "output_text" ||
19
+ block.type === undefined) &&
20
+ typeof block.text === "string") {
21
+ parts.push(block.text);
22
+ }
23
+ }
24
+ }
25
+ return parts.join("\n");
26
+ }
27
+ if (content != null && typeof content === "object" && typeof content.text === "string") {
28
+ return content.text;
29
+ }
30
+ return "";
31
+ }
@@ -1,4 +1,4 @@
1
- import{r as n,j as e}from"./vendor-BcOI2aZ9.js";import{b as s,c as f,D as Y,d as se,u as be,P as fe}from"./index-BdD7LHGu.js";import{a as ye}from"./providersData-Br5RocnM.js";import{T as X}from"./ToolIcon-Cp4gSgFt.js";import{M as ee}from"./ModelAutocompleteInput-ClwXyzE7.js";import{r as ve,s as Ne}from"./lucide-Cc35htxl.js";import"./metadataRegistry-7DDoxaR3.js";const Ae={id:"amp",name:"Amp CLI",image:"/assets/tools/amp/icon.png",color:"#F97316",description:"Sourcegraph Amp coding assistant CLI",configType:"env",binary:"amp",baseUrlPath:"/v1",defaultModels:["claude-sonnet-4-6","claude-3-7-sonnet","claude-3-5-sonnet","claude-opus-5","claude-fable-5.1","gpt-5.6","gpt-6-astra","glm-5.3-flash","gpt-4o"],envVars:{baseUrl:"OPENAI_BASE_URL",apiKey:"OPENAI_API_KEY"},powershellTemplate:`$env:OPENAI_BASE_URL = "${s}"
1
+ import{r as n,j as e}from"./vendor-BcOI2aZ9.js";import{b as s,c as f,D as Y,d as se,u as be,P as fe}from"./index-DVeDwPjn.js";import{a as ye}from"./providersData-D7kilpPx.js";import{T as X}from"./ToolIcon-Cp4gSgFt.js";import{M as ee}from"./ModelAutocompleteInput-K8-vMnIb.js";import{r as ve,s as Ne}from"./lucide-Cc35htxl.js";import"./metadataRegistry-BMKXREeE.js";const Ae={id:"amp",name:"Amp CLI",image:"/assets/tools/amp/icon.png",color:"#F97316",description:"Sourcegraph Amp coding assistant CLI",configType:"env",binary:"amp",baseUrlPath:"/v1",defaultModels:["claude-sonnet-4-6","claude-3-7-sonnet","claude-3-5-sonnet","claude-opus-5","claude-fable-5.1","gpt-5.6","gpt-6-astra","glm-5.3-flash","gpt-4o"],envVars:{baseUrl:"OPENAI_BASE_URL",apiKey:"OPENAI_API_KEY"},powershellTemplate:`$env:OPENAI_BASE_URL = "${s}"
2
2
  $env:OPENAI_API_KEY = "mapigate-local"
3
3
  amp`,bashTemplate:`export OPENAI_BASE_URL="${s}"
4
4
  export OPENAI_API_KEY="mapigate-local"
@@ -1 +1 @@
1
- import{r as o,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-BdD7LHGu.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-ClwXyzE7.js";import{T as qe}from"./ToolIcon-Cp4gSgFt.js";import{S as ne}from"./Select-BNRH8LIG.js";import{P as me}from"./metadataRegistry-7DDoxaR3.js";import{C as Ge}from"./ConfirmModal-B7vVauYn.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:f,onRemove:x,onMoveUp:q,onMoveDown:u,isFirst:B,isLast:L})=>{const{attributes:S,listeners:M,setNodeRef:h,transform:v,transition:D,isDragging:N}=Ce({id:c}),P={transform:ke.Transform.toString(v),transition:D,zIndex:N?50:void 0,opacity:N?.6:1};return e.jsxs("div",{ref:h,style:P,className:`flex items-center justify-between gap-2 px-3 py-2 rounded-xl border bg-[#0A0D14] transition-all ${N?"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",...S,...M,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:f+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:B,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:L,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:x,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:f,title:x="Select & Reorder Models",initialSelectedModels:q=[],onConfirm:u,multiSelect:B=!0,filterModality:L=null,onSelect:S,onDeselect:M,selectedModel:h,activeProviders:v=[],modelAliases:D={},kindFilter:N=null,capFilter:P=null,addedModelValues:k,closeOnSelect:V=!1,excludeModelIds:T,allowCombos:E=!0})=>{const[p,b]=o.useState([]),[w,_]=o.useState(""),[y,G]=o.useState("all"),[I,F]=o.useState(P||L||"all"),[Q,J]=o.useState(""),[U,X]=o.useState([]),[W,se]=o.useState([]),[R,r]=o.useState(!0),a=o.useRef(null),l=he(ce(we,{activationConstraint:{distance:4}}),ce(Ne,{coordinateGetter:je}));o.useEffect(()=>{if(c){b([...k||q||[]]),_(""),G("all"),F(P||L||"all"),J("");const s=setTimeout(()=>{var n;(n=a.current)==null||n.focus()},50);return()=>clearTimeout(s)}},[c,q,k,L,P]),o.useEffect(()=>{if(!c)return;let t=!1;return fetch("/api/combos").then(s=>s.ok?s.json():[]).then(s=>{if(!t){const n=Array.isArray(s)?s:s.combos||[];X(n)}}).catch(()=>{t||X([])}),()=>{t=!0}},[c]),o.useEffect(()=>{if(!c)return;let t=!1;const s=()=>{Oe().then(d=>{if(!t){se(d);const m=d.some(z=>z.hasConnectedAccount);r(m)}}).catch(()=>{})};s();const n=ze(()=>{t||s()});return()=>{t=!0,n()}},[c]);const i=o.useMemo(()=>{const t=new Set;for(const s of W)s.hasConnectedAccount&&t.add(s.providerId);return t},[W]),j=o.useMemo(()=>i.size>0,[i]),A=o.useMemo(()=>{var d,m,z,ie;const t=[],s=new Set,n=new Set;for(const g of W){if(g.isCombo||s.has(g.value))continue;s.add(g.value),n.add(g.providerId);const C=de(g.providerId,g.id);t.push({id:g.id,value:g.value,name:g.name||g.id,providerId:g.providerId,providerName:g.providerName||g.providerId,caps:{...C,vision:!!(((d=g.caps)==null?void 0:d.vision)??C.vision),reasoning:!!(((m=g.caps)==null?void 0:m.reasoning)??C.reasoning),audioInput:!!(((z=g.caps)==null?void 0:z.audio)??C.audioInput),audioOutput:!!(((ie=g.caps)==null?void 0:ie.audio)??C.audioOutput)},contextLength:g.contextLength||C.contextWindow,kind:"llm",isCustom:!1})}for(const[g,C]of Object.entries(me)){if(!C||!C.models)continue;const H=C.alias||C.id||g;if(!(n.has(g)||n.has(H)||C.aliases&&C.aliases.some($=>n.has($))))for(const $ of C.models){const te=$.id.includes("/")?$.id:`${H}/${$.id}`;if(s.has(te))continue;s.add(te);const re=de(g,$.id);t.push({id:$.id,value:te,name:$.name||$.id,providerId:g,providerName:C.name||g,caps:re,contextLength:$.contextLength,kind:$.kind||"llm",isCustom:!1})}}for(const[g,C]of Object.entries(D))if(!s.has(C)){s.add(C);const H=C.indexOf("/"),$=H===-1?"custom":C.slice(0,H),te=H===-1?C:C.slice(H+1),re=me[$],Fe=de($,te);t.push({id:te,value:C,name:g,providerId:$,providerName:(re==null?void 0:re.name)||$,caps:Fe,isCustom:!0})}return t},[W,D]),O=o.useMemo(()=>new Set((T||[]).map(t=>t.toLowerCase())),[T]),ae=o.useMemo(()=>{const t=new Map;E!==!1&&U.length>0&&t.set("combo","Combos");for(const s of A)R&&j&&!i.has(s.providerId)||t.has(s.providerId)||t.set(s.providerId,s.providerName);return Array.from(t.entries()).map(([s,n])=>({id:s,name:n}))},[A,R,j,i,E,U]),Y=o.useMemo(()=>{if(E===!1)return[];if(I!=="all"||N)return[];const t=w.trim().toLowerCase(),s=U.filter(n=>!O.has(n.id.toLowerCase())&&!O.has(n.name.toLowerCase())&&!O.has(`combo/${n.name}`.toLowerCase()));return t?s.filter(n=>n.name.toLowerCase().includes(t)||n.strategy&&n.strategy.toLowerCase().includes(t)||n.models.some(d=>d.toLowerCase().includes(t))):s},[U,w,I,N,E,O]),Z=o.useMemo(()=>y==="combo"?[]:A.filter(t=>{if(O.has(t.id.toLowerCase())||O.has(t.value.toLowerCase())||R&&j&&!i.has(t.providerId)||N&&t.kind&&t.kind!==N||y!=="all"&&t.providerId!==y||I==="vision"&&!t.caps.vision||I==="pdf"&&!t.caps.pdf||I==="audio"&&!t.caps.audioInput&&!t.caps.audio||I==="thinking"&&!t.caps.reasoning&&!t.caps.thinking&&!t.caps.thinkingFormat)return!1;if(w.trim()){const s=w.toLowerCase().trim(),n=t.name.toLowerCase().includes(s),d=t.value.toLowerCase().includes(s),m=t.providerName.toLowerCase().includes(s);if(!n&&!d&&!m)return!1}return!0}),[A,y,I,N,w,R,j,i,O]),[Me,ee]=o.useState(new Set),K=o.useMemo(()=>{const t=new Map;for(const s of Z){const n=s.providerId;let d=t.get(n);if(!d){const m=me[n];d={providerId:n,providerName:s.providerName||(m==null?void 0:m.name)||n,color:m==null?void 0:m.color,iconBg:m==null?void 0:m.iconBg,image:m==null?void 0:m.image,models:[],selectedCount:0},t.set(n,d)}d.models.push(s),(p.includes(s.value)||h===s.value)&&d.selectedCount++}return Array.from(t.values()).sort((s,n)=>{if(s.selectedCount>0&&n.selectedCount===0)return-1;if(n.selectedCount>0&&s.selectedCount===0)return 1;const d=i.has(s.providerId)?1:0,m=i.has(n.providerId)?1:0;return d!==m?m-d:s.providerName.localeCompare(n.providerName)})},[Z,p,h,i]);o.useEffect(()=>{w.trim()?ee(new Set(K.map(t=>t.providerId))):y!=="all"&&ee(new Set([y]))},[w,y,K]),o.useEffect(()=>{c&&!w.trim()&&y==="all"&&K.length>0&&ee(t=>{if(t.size>0)return t;const s=new Set,n=K.filter(d=>d.selectedCount>0);return n.length>0?n.forEach(d=>s.add(d.providerId)):K[0]&&s.add(K[0].providerId),s})},[c,K,w,y]);const Be=t=>{ee(s=>{const n=new Set(s);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 s=t.value;p.includes(s)?(M&&M(t),b(d=>d.filter(m=>m!==s))):(S&&S(t),b(B?d=>[...d,s]:[s])),V&&f()},xe=t=>{const s=t.name,n=p.includes(s),d=pe(t.models),m={id:t.name,value:t.name,name:t.name,providerId:"combo",providerName:"Combos",caps:d||de(null,t.name)};n?(M&&M(m),b(z=>z.filter(ie=>ie!==s))):(S&&S(m),b(B?z=>[...z,s]:[s])),V&&f()},Re=t=>{b(n=>n.filter(d=>d!==t));const s=A.find(n=>n.value===t);s&&M&&M(s)},$e=t=>{if(t===0)return;const s=[...p],n=s[t-1];s[t-1]=s[t],s[t]=n,b(s)},Pe=t=>{if(t===p.length-1)return;const s=[...p],n=s[t+1];s[t+1]=s[t],s[t]=n,b(s)},Le=t=>{const{active:s,over:n}=t;n&&s.id!==n.id&&b(d=>{const m=d.indexOf(String(s.id)),z=d.indexOf(String(n.id));return m!==-1&&z!==-1?ve(d,m,z):d})},Te=t=>{t.preventDefault();const s=Q.trim();s&&(p.includes(s)||b(B?n=>[...n,s]:[s]),J(""))},_e=()=>{u&&u(p),f()};return e.jsx(Se,{isOpen:c,onClose:f,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:x}),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:f,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:a,type:"text",placeholder:"Search models by name, provider, or ID...",value:w,onChange:t=>_(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"}),w&&e.jsx("button",{type:"button",onClick:()=>_(""),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:y,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]"}),E!==!1&&U.length>0&&e.jsxs("button",{type:"button",onClick:()=>G(y==="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 ${y==="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:()=>r(!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",j&&e.jsx("span",{className:"text-[9.5px] px-1 rounded bg-emerald-500/30 text-emerald-300 font-mono",children:i.size})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("button",{type:"button",onClick:()=>F("all"),className:`px-2 py-1 rounded-lg text-[11px] font-medium border transition-colors cursor-pointer ${I==="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:()=>F("vision"),className:`px-2 py-1 rounded-lg text-[11px] font-medium border transition-colors cursor-pointer flex items-center gap-1 ${I==="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:()=>F("audio"),className:`px-2 py-1 rounded-lg text-[11px] font-medium border transition-colors cursor-pointer flex items-center gap-1 ${I==="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:()=>F("thinking"),className:`px-2 py-1 rounded-lg text-[11px] font-medium border transition-colors cursor-pointer flex items-center gap-1 ${I==="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"]})]})]}),y!=="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 s=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 ${s?"bg-cyan-600 text-white border-cyan-500":"bg-[#0A0D14] text-slate-300 border-[#1E293B] hover:border-cyan-500/40 hover:text-white"}`,children:[s&&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)})})]}),y==="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 s=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 ${s?"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:d=>{d.stopPropagation(),xe(t)},className:`size-7 rounded-lg flex items-center justify-center shrink-0 border transition-colors ${s?"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:s?"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&&!j?"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:()=>r(!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 s=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 ${s?"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 ${s?"rotate-180 text-blue-400":""}`,children:"expand_more"})]}),s&&e.jsx("div",{className:"p-2 space-y-1.5 bg-[#080B12]/60",children:t.models.map(n=>{const d=p.includes(n.value)||h===n.value,m=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 ${d?"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}),m&&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:m})]}),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:z=>{z.stopPropagation(),ue(n)},className:`size-7 rounded-lg flex items-center justify-center shrink-0 border transition-colors ${d?"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:d?"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:()=>b([]),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:l,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,s)=>e.jsx(Ve,{id:t,index:s,onRemove:()=>Re(t),onMoveUp:()=>$e(s),onMoveDown:()=>Pe(s),isFirst:s===0,isLast:s===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: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:"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:f,index:x,onEdit:q,onRemove:u,onMoveUp:B,onMoveDown:L,isFirst:S,isLast:M,excludeValues:h})=>{const[v,D]=o.useState(!1),[N,P]=o.useState(f);o.useEffect(()=>{P(f)},[f]);const k=()=>{const y=N.trim();y&&y!==f?q(y):P(f),D(!1)},{attributes:V,listeners:T,setNodeRef:E,transform:p,transition:b,isDragging:w}=Ce({id:c}),_={transform:ke.Transform.toString(p),transition:b,zIndex:w?50:void 0,opacity:w?.6:1};return e.jsxs("div",{ref:E,style:_,className:`group flex items-center justify-between gap-2.5 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",...V,...T,className:"cursor-grab active:cursor-grabbing text-slate-500 hover:text-slate-300 p-0.5 rounded touch-none shrink-0",title:"Drag to reorder priority",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"drag_indicator"})}),e.jsx("span",{className:"size-5 rounded-md bg-[#141B2D] border border-[#1E293B] text-[10px] font-mono text-blue-400 font-bold flex items-center justify-center shrink-0",children:x+1}),v?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:N,onChange:y=>P(y),onEnter:k,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:k,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:()=>{P(f),D(!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:()=>D(!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"})]}),!v&&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:B,disabled:S,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:L,disabled:M,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:f,combo:x,title:q,onSave:u})=>{const[B,L]=o.useState(""),[S,M]=o.useState("round-robin"),[h,v]=o.useState([]),[D,N]=o.useState(""),[P,k]=o.useState(""),[V,T]=o.useState(""),[E,p]=o.useState(!1),[b,w]=o.useState(!1),_=!!x,y=he(ce(we,{activationConstraint:{distance:4}}),ce(Ne,{coordinateGetter:je}));o.useEffect(()=>{c&&(x?(L(x.name),M(x.strategy||"round-robin"),v(Array.isArray(x.models)?[...x.models]:[])):(L(""),M("round-robin"),v([])),N(""),k(""),T(""),w(!1))},[c,x]);const G=a=>{const l=a.trim();return l?Qe.test(l)?(N(""),!0):(N("Name can only contain letters, numbers, -, _ and ."),!1):(N("Combo name is required."),!1)},I=a=>{const l=a.target.value;L(l),l.trim()?G(l):N("")},F=o.useMemo(()=>{const a=[];x!=null&&x.id&&a.push(x.id),x!=null&&x.name&&(a.push(x.name),a.push(`combo/${x.name}`));const l=B.trim();return l&&(a.push(l),a.push(`combo/${l}`)),a},[x,B]),Q=a=>{const l=a.trim().toLowerCase(),i=l.startsWith("combo/")?l.slice(6):l;return F.some(j=>{const A=j.toLowerCase(),O=A.startsWith("combo/")?A.slice(6):A;return l===A||i===O})},J=(a,l)=>{const i=l.trim();if(Q(i)){k("A combo cannot bundle itself (circular reference).");return}const j=[...h];j[a]=i,v(j),k("")},U=a=>{v(h.filter((l,i)=>i!==a))},X=a=>{if(a===0)return;const l=[...h],i=l[a-1];l[a-1]=l[a],l[a]=i,v(l)},W=a=>{if(a===h.length-1)return;const l=[...h],i=l[a+1];l[a+1]=l[a],l[a]=i,v(l)},se=a=>{const{active:l,over:i}=a;i&&l.id!==i.id&&v(j=>{const A=j.map((Y,Z)=>`${Y}-${Z}`),O=A.indexOf(String(l.id)),ae=A.indexOf(String(i.id));return O!==-1&&ae!==-1?ve(j,O,ae):j})},R=a=>{const l=V.trim();if(l){if(Q(l)){k("A combo cannot bundle itself (circular reference).");return}h.includes(l)||(v([...h,l]),k("")),T("")}},r=async a=>{if(a.preventDefault(),!!G(B)){if(h.length===0){k("At least one model must be added to the combo.");return}if(h.some(Q)){k("A combo cannot bundle itself (circular reference).");return}try{w(!0),await u({id:x==null?void 0:x.id,name:B.trim(),models:h,strategy:S,isActive:x?x.isActive:!0}),le(),f()}catch(l){N((l==null?void 0:l.message)||"Failed to save combo.")}finally{w(!1)}}};return e.jsxs(e.Fragment,{children:[e.jsx(Se,{isOpen:c,onClose:f,maxWidthClass:"w-full max-w-2xl",children:e.jsxs("form",{onSubmit:r,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:_?"edit_note":"add_circle"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-bold text-white",children:q||(_?`Edit Combo: ${x==null?void 0:x.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:f,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:B,onChange:I,className:`w-full bg-[#0A0D14] border rounded-xl px-3.5 py-2 text-xs font-mono text-white placeholder-slate-500 focus:outline-none transition-colors ${D?"border-rose-500/80 focus:border-rose-500":"border-[#1E293B] focus:border-blue-500"}`}),D?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"}),D]}):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:S,onChange:a=>M(a),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:[S==="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."]}),S==="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."]}),S==="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."]}),S==="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."]}),S==="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:y,collisionDetection:fe,onDragEnd:se,children:e.jsx(ge,{items:h.map((a,l)=>`${a}-${l}`),strategy:ye,children:e.jsx("div",{className:"space-y-1.5",children:h.map((a,l)=>e.jsx(Ue,{id:`${a}-${l}`,model:a,index:l,onEdit:i=>J(l,i),onRemove:()=>U(l),onMoveUp:()=>X(l),onMoveDown:()=>W(l),isFirst:l===0,isLast:l===h.length-1,excludeValues:F},`${a}-${l}`))})})})}),P&&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"}),P]}),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:T,onEnter:()=>R(),excludeValues:F,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:f,disabled:b,className:"px-4 py-2 rounded-xl text-xs font-medium text-slate-400 hover:text-white bg-[#141B2D] border border-[#1E293B] hover:border-slate-700 transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:b,className:"px-5 py-2 rounded-xl text-xs font-semibold text-white bg-blue-600 hover:bg-blue-500 shadow-md shadow-blue-600/20 disabled:opacity-50 transition-all flex items-center gap-1.5 cursor-pointer",children:b?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[15px] animate-spin",children:"progress_activity"}),"Saving..."]}):e.jsx("span",{children:_?"Update Combo":"Save Combo"})})]})]})}),E&&e.jsx(Ae,{isOpen:E,onClose:()=>p(!1),addedModelValues:h,initialSelectedModels:h,excludeModelIds:F,allowCombos:!1,onSelect:a=>{h.includes(a.value)||(v(l=>[...l,a.value]),k(""))},onDeselect:a=>{v(l=>l.filter(i=>i!==a.value))},onConfirm:a=>{v(a),a.length>0&&k("")},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,f]=o.useState([]),[x,q]=o.useState(!0),[u,B]=o.useState(Je),[L,S]=o.useState(!1),[M,h]=o.useState(null),[v,D]=o.useState(""),N=o.useMemo(()=>{const r=v.trim().toLowerCase();return r?c.filter(a=>!!(a.name.toLowerCase().includes(r)||a.strategy.toLowerCase().includes(r)||a.models&&a.models.some(l=>l.toLowerCase().includes(r)))):c},[c,v]),[P,k]=o.useState(!1),[V,T]=o.useState(null),[E,p]=o.useState(null),[b,w]=o.useState(null),_=o.useCallback(async()=>{try{q(!0);const r=await fetch("/api/combos");if(r.ok){const a=await r.json();Array.isArray(a)&&f(a)}}catch(r){console.error("Failed to load combos:",r)}finally{q(!1)}},[]),y=o.useCallback(async()=>{try{const r=await fetch("/api/settings/capacity-adapter");if(r.ok){const a=await r.json();a&&typeof a=="object"&&B({vision:a.vision||{enabled:!1,roundRobin:!1,models:[]},audioInput:a.audioInput||{enabled:!1,roundRobin:!1,models:[]},pdf:a.pdf,videoInput:a.videoInput})}}catch(r){console.error("Failed to load capacity adapter settings:",r)}},[]);o.useEffect(()=>{_(),y()},[_,y]);const G=async r=>{B(r);try{S(!0),await fetch("/api/settings/capacity-adapter",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})}catch(a){console.error("Failed to save capacity adapter settings:",a)}finally{S(!1)}},I=r=>{const a=u[r];G({...u,[r]:{...a,enabled:!a.enabled}})},F=(r,a)=>{const l=u[r];G({...u,[r]:{...l,roundRobin:a}})},Q=(r,a)=>{const l=u[r];G({...u,[r]:{...l,models:l.models.filter(i=>i!==a)}})},J=r=>{if(!E)return;const a=u[E];G({...u,[E]:{...a,models:r}}),p(null)},U=async r=>{if(r.id){const a=await fetch(`/api/combos/${r.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r.name,models:r.models,strategy:r.strategy,isActive:r.isActive})});if(!a.ok){const l=await a.json();throw new Error(l.error||"Failed to update combo")}}else{const a=await fetch("/api/combos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r.name,models:r.models,strategy:r.strategy})});if(!a.ok){const l=await a.json();throw new Error(l.error||"Failed to create combo")}}await _(),le(),k(!1),T(null)},X=async r=>{try{const a=await fetch(`/api/combos/${r.id}/toggle`,{method:"POST"});if(a.ok){const l=await a.json();f(i=>i.map(j=>j.id===r.id?l:j)),le()}}catch(a){console.error("Error toggling combo status:",a)}},W=async(r,a)=>{try{const l=await fetch(`/api/combos/${r.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({strategy:a})});if(l.ok){const i=await l.json();f(j=>j.map(A=>A.id===r.id?i:A)),le()}}catch(l){console.error("Error updating strategy:",l)}},se=r=>{w({title:"Delete Combo",message:`Are you sure you want to delete combo "${r.name}"? This action cannot be undone.`,confirmText:"Delete Combo",variant:"danger",onConfirm:async()=>{try{(await fetch(`/api/combos/${r.id}`,{method:"DELETE"})).ok&&(f(l=>l.filter(i=>i.id!==r.id)),le())}catch(a){console.error("Error deleting combo:",a)}finally{w(null)}}})},R=(r,a)=>{navigator.clipboard.writeText(r),h(a),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:()=>{T(null),k(!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 (",v?`${N.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:v,onChange:r=>D(r.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"}),v&&e.jsx("button",{type:"button",onClick:()=>D(""),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"})]})]}),x?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."})]}):N.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 “",v,"”"]}),e.jsx("button",{onClick:()=>D(""),className:"text-xs text-blue-400 hover:underline cursor-pointer",children:"Clear filter"})]}):e.jsx("div",{className:"w-full space-y-2.5",children:N.map((r,a)=>{const l=pe(r.models),i=r.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 ${i?"bg-[#0F1420]/80 border-[#1E293B] hover:border-slate-700":"bg-[#0A0D14]/50 border-[#1E293B]/50 opacity-60"}`,style:{animationDelay:`${a*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 ${r.strategy==="fallback"?"bg-blue-500/10 text-blue-400 border-blue-500/20":r.strategy==="round-robin"?"bg-cyan-500/10 text-cyan-400 border-cyan-500/20":r.strategy==="fusion"?"bg-indigo-500/10 text-indigo-400 border-indigo-500/20":r.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:r.strategy==="fallback"?"low_priority":r.strategy==="round-robin"?"sync":r.strategy==="fusion"?"call_split":r.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:r.name}),l&&e.jsx(oe,{caps:l,size:"xs"}),!i&&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:r.models.map((j,A)=>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:A+1}),e.jsx("span",{children:j})]},A))})]})]}),e.jsxs("div",{className:"flex items-center gap-2.5 shrink-0",children:[e.jsx(ne,{value:r.strategy,onChange:j=>W(r,j),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:i?"Disable combo":"Enable combo",children:[e.jsx("input",{type:"checkbox",checked:i,onChange:()=>X(r),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:M===r.id?"Copied to clipboard!":"Copy combo identifier",onClick:()=>R(r.name,r.id),className:`p-1.5 rounded-lg transition-colors cursor-pointer ${M===r.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:M===r.id?"check":"content_copy"})}),e.jsx("button",{type:"button",title:"Edit combo",onClick:()=>{T(r),k(!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(r),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"})})]})]})]},r.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."})]}),L&&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:()=>I("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:r=>F("vision",r==="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(r=>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:r}),e.jsx("button",{type:"button",onClick:()=>Q("vision",r),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"})})]},r))})]})]}),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:()=>I("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:r=>F("audioInput",r==="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(r=>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:r}),e.jsx("button",{type:"button",onClick:()=>Q("audioInput",r),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"})})]},r))})]})]})]})]}),e.jsx(We,{isOpen:P,onClose:()=>{k(!1),T(null)},combo:V,onSave:U}),E&&e.jsx(Ae,{isOpen:E!==null,onClose:()=>p(null),title:`Configure ${E==="vision"?"Vision":"Audio"} Adapter Model Pool`,initialSelectedModels:u[E].models,onConfirm:J,filterModality:E==="vision"?"vision":"audio",multiSelect:!0}),b&&e.jsx(Ge,{isOpen:b!==null,title:b.title,message:b.message,confirmText:b.confirmText||"Confirm",variant:b.variant||"primary",onConfirm:b.onConfirm,onCancel:()=>w(null)})]})};export{lt as CombosTab};
1
+ import{r as o,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-DVeDwPjn.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-K8-vMnIb.js";import{T as qe}from"./ToolIcon-Cp4gSgFt.js";import{S as ne}from"./Select-BNRH8LIG.js";import{P as me}from"./metadataRegistry-BMKXREeE.js";import{C as Ge}from"./ConfirmModal-1KqBoeRh.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:f,onRemove:x,onMoveUp:q,onMoveDown:u,isFirst:B,isLast:L})=>{const{attributes:S,listeners:M,setNodeRef:h,transform:v,transition:D,isDragging:N}=Ce({id:c}),P={transform:ke.Transform.toString(v),transition:D,zIndex:N?50:void 0,opacity:N?.6:1};return e.jsxs("div",{ref:h,style:P,className:`flex items-center justify-between gap-2 px-3 py-2 rounded-xl border bg-[#0A0D14] transition-all ${N?"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",...S,...M,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:f+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:B,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:L,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:x,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:f,title:x="Select & Reorder Models",initialSelectedModels:q=[],onConfirm:u,multiSelect:B=!0,filterModality:L=null,onSelect:S,onDeselect:M,selectedModel:h,activeProviders:v=[],modelAliases:D={},kindFilter:N=null,capFilter:P=null,addedModelValues:k,closeOnSelect:V=!1,excludeModelIds:T,allowCombos:E=!0})=>{const[p,b]=o.useState([]),[w,_]=o.useState(""),[y,G]=o.useState("all"),[I,F]=o.useState(P||L||"all"),[Q,J]=o.useState(""),[U,X]=o.useState([]),[W,se]=o.useState([]),[R,r]=o.useState(!0),a=o.useRef(null),l=he(ce(we,{activationConstraint:{distance:4}}),ce(Ne,{coordinateGetter:je}));o.useEffect(()=>{if(c){b([...k||q||[]]),_(""),G("all"),F(P||L||"all"),J("");const s=setTimeout(()=>{var n;(n=a.current)==null||n.focus()},50);return()=>clearTimeout(s)}},[c,q,k,L,P]),o.useEffect(()=>{if(!c)return;let t=!1;return fetch("/api/combos").then(s=>s.ok?s.json():[]).then(s=>{if(!t){const n=Array.isArray(s)?s:s.combos||[];X(n)}}).catch(()=>{t||X([])}),()=>{t=!0}},[c]),o.useEffect(()=>{if(!c)return;let t=!1;const s=()=>{Oe().then(d=>{if(!t){se(d);const m=d.some(z=>z.hasConnectedAccount);r(m)}}).catch(()=>{})};s();const n=ze(()=>{t||s()});return()=>{t=!0,n()}},[c]);const i=o.useMemo(()=>{const t=new Set;for(const s of W)s.hasConnectedAccount&&t.add(s.providerId);return t},[W]),j=o.useMemo(()=>i.size>0,[i]),A=o.useMemo(()=>{var d,m,z,ie;const t=[],s=new Set,n=new Set;for(const g of W){if(g.isCombo||s.has(g.value))continue;s.add(g.value),n.add(g.providerId);const C=de(g.providerId,g.id);t.push({id:g.id,value:g.value,name:g.name||g.id,providerId:g.providerId,providerName:g.providerName||g.providerId,caps:{...C,vision:!!(((d=g.caps)==null?void 0:d.vision)??C.vision),reasoning:!!(((m=g.caps)==null?void 0:m.reasoning)??C.reasoning),audioInput:!!(((z=g.caps)==null?void 0:z.audio)??C.audioInput),audioOutput:!!(((ie=g.caps)==null?void 0:ie.audio)??C.audioOutput)},contextLength:g.contextLength||C.contextWindow,kind:"llm",isCustom:!1})}for(const[g,C]of Object.entries(me)){if(!C||!C.models)continue;const H=C.alias||C.id||g;if(!(n.has(g)||n.has(H)||C.aliases&&C.aliases.some($=>n.has($))))for(const $ of C.models){const te=$.id.includes("/")?$.id:`${H}/${$.id}`;if(s.has(te))continue;s.add(te);const re=de(g,$.id);t.push({id:$.id,value:te,name:$.name||$.id,providerId:g,providerName:C.name||g,caps:re,contextLength:$.contextLength,kind:$.kind||"llm",isCustom:!1})}}for(const[g,C]of Object.entries(D))if(!s.has(C)){s.add(C);const H=C.indexOf("/"),$=H===-1?"custom":C.slice(0,H),te=H===-1?C:C.slice(H+1),re=me[$],Fe=de($,te);t.push({id:te,value:C,name:g,providerId:$,providerName:(re==null?void 0:re.name)||$,caps:Fe,isCustom:!0})}return t},[W,D]),O=o.useMemo(()=>new Set((T||[]).map(t=>t.toLowerCase())),[T]),ae=o.useMemo(()=>{const t=new Map;E!==!1&&U.length>0&&t.set("combo","Combos");for(const s of A)R&&j&&!i.has(s.providerId)||t.has(s.providerId)||t.set(s.providerId,s.providerName);return Array.from(t.entries()).map(([s,n])=>({id:s,name:n}))},[A,R,j,i,E,U]),Y=o.useMemo(()=>{if(E===!1)return[];if(I!=="all"||N)return[];const t=w.trim().toLowerCase(),s=U.filter(n=>!O.has(n.id.toLowerCase())&&!O.has(n.name.toLowerCase())&&!O.has(`combo/${n.name}`.toLowerCase()));return t?s.filter(n=>n.name.toLowerCase().includes(t)||n.strategy&&n.strategy.toLowerCase().includes(t)||n.models.some(d=>d.toLowerCase().includes(t))):s},[U,w,I,N,E,O]),Z=o.useMemo(()=>y==="combo"?[]:A.filter(t=>{if(O.has(t.id.toLowerCase())||O.has(t.value.toLowerCase())||R&&j&&!i.has(t.providerId)||N&&t.kind&&t.kind!==N||y!=="all"&&t.providerId!==y||I==="vision"&&!t.caps.vision||I==="pdf"&&!t.caps.pdf||I==="audio"&&!t.caps.audioInput&&!t.caps.audio||I==="thinking"&&!t.caps.reasoning&&!t.caps.thinking&&!t.caps.thinkingFormat)return!1;if(w.trim()){const s=w.toLowerCase().trim(),n=t.name.toLowerCase().includes(s),d=t.value.toLowerCase().includes(s),m=t.providerName.toLowerCase().includes(s);if(!n&&!d&&!m)return!1}return!0}),[A,y,I,N,w,R,j,i,O]),[Me,ee]=o.useState(new Set),K=o.useMemo(()=>{const t=new Map;for(const s of Z){const n=s.providerId;let d=t.get(n);if(!d){const m=me[n];d={providerId:n,providerName:s.providerName||(m==null?void 0:m.name)||n,color:m==null?void 0:m.color,iconBg:m==null?void 0:m.iconBg,image:m==null?void 0:m.image,models:[],selectedCount:0},t.set(n,d)}d.models.push(s),(p.includes(s.value)||h===s.value)&&d.selectedCount++}return Array.from(t.values()).sort((s,n)=>{if(s.selectedCount>0&&n.selectedCount===0)return-1;if(n.selectedCount>0&&s.selectedCount===0)return 1;const d=i.has(s.providerId)?1:0,m=i.has(n.providerId)?1:0;return d!==m?m-d:s.providerName.localeCompare(n.providerName)})},[Z,p,h,i]);o.useEffect(()=>{w.trim()?ee(new Set(K.map(t=>t.providerId))):y!=="all"&&ee(new Set([y]))},[w,y,K]),o.useEffect(()=>{c&&!w.trim()&&y==="all"&&K.length>0&&ee(t=>{if(t.size>0)return t;const s=new Set,n=K.filter(d=>d.selectedCount>0);return n.length>0?n.forEach(d=>s.add(d.providerId)):K[0]&&s.add(K[0].providerId),s})},[c,K,w,y]);const Be=t=>{ee(s=>{const n=new Set(s);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 s=t.value;p.includes(s)?(M&&M(t),b(d=>d.filter(m=>m!==s))):(S&&S(t),b(B?d=>[...d,s]:[s])),V&&f()},xe=t=>{const s=t.name,n=p.includes(s),d=pe(t.models),m={id:t.name,value:t.name,name:t.name,providerId:"combo",providerName:"Combos",caps:d||de(null,t.name)};n?(M&&M(m),b(z=>z.filter(ie=>ie!==s))):(S&&S(m),b(B?z=>[...z,s]:[s])),V&&f()},Re=t=>{b(n=>n.filter(d=>d!==t));const s=A.find(n=>n.value===t);s&&M&&M(s)},$e=t=>{if(t===0)return;const s=[...p],n=s[t-1];s[t-1]=s[t],s[t]=n,b(s)},Pe=t=>{if(t===p.length-1)return;const s=[...p],n=s[t+1];s[t+1]=s[t],s[t]=n,b(s)},Le=t=>{const{active:s,over:n}=t;n&&s.id!==n.id&&b(d=>{const m=d.indexOf(String(s.id)),z=d.indexOf(String(n.id));return m!==-1&&z!==-1?ve(d,m,z):d})},Te=t=>{t.preventDefault();const s=Q.trim();s&&(p.includes(s)||b(B?n=>[...n,s]:[s]),J(""))},_e=()=>{u&&u(p),f()};return e.jsx(Se,{isOpen:c,onClose:f,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:x}),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:f,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:a,type:"text",placeholder:"Search models by name, provider, or ID...",value:w,onChange:t=>_(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"}),w&&e.jsx("button",{type:"button",onClick:()=>_(""),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:y,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]"}),E!==!1&&U.length>0&&e.jsxs("button",{type:"button",onClick:()=>G(y==="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 ${y==="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:()=>r(!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",j&&e.jsx("span",{className:"text-[9.5px] px-1 rounded bg-emerald-500/30 text-emerald-300 font-mono",children:i.size})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("button",{type:"button",onClick:()=>F("all"),className:`px-2 py-1 rounded-lg text-[11px] font-medium border transition-colors cursor-pointer ${I==="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:()=>F("vision"),className:`px-2 py-1 rounded-lg text-[11px] font-medium border transition-colors cursor-pointer flex items-center gap-1 ${I==="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:()=>F("audio"),className:`px-2 py-1 rounded-lg text-[11px] font-medium border transition-colors cursor-pointer flex items-center gap-1 ${I==="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:()=>F("thinking"),className:`px-2 py-1 rounded-lg text-[11px] font-medium border transition-colors cursor-pointer flex items-center gap-1 ${I==="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"]})]})]}),y!=="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 s=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 ${s?"bg-cyan-600 text-white border-cyan-500":"bg-[#0A0D14] text-slate-300 border-[#1E293B] hover:border-cyan-500/40 hover:text-white"}`,children:[s&&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)})})]}),y==="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 s=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 ${s?"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:d=>{d.stopPropagation(),xe(t)},className:`size-7 rounded-lg flex items-center justify-center shrink-0 border transition-colors ${s?"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:s?"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&&!j?"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:()=>r(!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 s=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 ${s?"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 ${s?"rotate-180 text-blue-400":""}`,children:"expand_more"})]}),s&&e.jsx("div",{className:"p-2 space-y-1.5 bg-[#080B12]/60",children:t.models.map(n=>{const d=p.includes(n.value)||h===n.value,m=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 ${d?"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}),m&&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:m})]}),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:z=>{z.stopPropagation(),ue(n)},className:`size-7 rounded-lg flex items-center justify-center shrink-0 border transition-colors ${d?"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:d?"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:()=>b([]),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:l,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,s)=>e.jsx(Ve,{id:t,index:s,onRemove:()=>Re(t),onMoveUp:()=>$e(s),onMoveDown:()=>Pe(s),isFirst:s===0,isLast:s===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: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:"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:f,index:x,onEdit:q,onRemove:u,onMoveUp:B,onMoveDown:L,isFirst:S,isLast:M,excludeValues:h})=>{const[v,D]=o.useState(!1),[N,P]=o.useState(f);o.useEffect(()=>{P(f)},[f]);const k=()=>{const y=N.trim();y&&y!==f?q(y):P(f),D(!1)},{attributes:V,listeners:T,setNodeRef:E,transform:p,transition:b,isDragging:w}=Ce({id:c}),_={transform:ke.Transform.toString(p),transition:b,zIndex:w?50:void 0,opacity:w?.6:1};return e.jsxs("div",{ref:E,style:_,className:`group flex items-center justify-between gap-2.5 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",...V,...T,className:"cursor-grab active:cursor-grabbing text-slate-500 hover:text-slate-300 p-0.5 rounded touch-none shrink-0",title:"Drag to reorder priority",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"drag_indicator"})}),e.jsx("span",{className:"size-5 rounded-md bg-[#141B2D] border border-[#1E293B] text-[10px] font-mono text-blue-400 font-bold flex items-center justify-center shrink-0",children:x+1}),v?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:N,onChange:y=>P(y),onEnter:k,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:k,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:()=>{P(f),D(!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:()=>D(!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"})]}),!v&&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:B,disabled:S,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:L,disabled:M,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:f,combo:x,title:q,onSave:u})=>{const[B,L]=o.useState(""),[S,M]=o.useState("round-robin"),[h,v]=o.useState([]),[D,N]=o.useState(""),[P,k]=o.useState(""),[V,T]=o.useState(""),[E,p]=o.useState(!1),[b,w]=o.useState(!1),_=!!x,y=he(ce(we,{activationConstraint:{distance:4}}),ce(Ne,{coordinateGetter:je}));o.useEffect(()=>{c&&(x?(L(x.name),M(x.strategy||"round-robin"),v(Array.isArray(x.models)?[...x.models]:[])):(L(""),M("round-robin"),v([])),N(""),k(""),T(""),w(!1))},[c,x]);const G=a=>{const l=a.trim();return l?Qe.test(l)?(N(""),!0):(N("Name can only contain letters, numbers, -, _ and ."),!1):(N("Combo name is required."),!1)},I=a=>{const l=a.target.value;L(l),l.trim()?G(l):N("")},F=o.useMemo(()=>{const a=[];x!=null&&x.id&&a.push(x.id),x!=null&&x.name&&(a.push(x.name),a.push(`combo/${x.name}`));const l=B.trim();return l&&(a.push(l),a.push(`combo/${l}`)),a},[x,B]),Q=a=>{const l=a.trim().toLowerCase(),i=l.startsWith("combo/")?l.slice(6):l;return F.some(j=>{const A=j.toLowerCase(),O=A.startsWith("combo/")?A.slice(6):A;return l===A||i===O})},J=(a,l)=>{const i=l.trim();if(Q(i)){k("A combo cannot bundle itself (circular reference).");return}const j=[...h];j[a]=i,v(j),k("")},U=a=>{v(h.filter((l,i)=>i!==a))},X=a=>{if(a===0)return;const l=[...h],i=l[a-1];l[a-1]=l[a],l[a]=i,v(l)},W=a=>{if(a===h.length-1)return;const l=[...h],i=l[a+1];l[a+1]=l[a],l[a]=i,v(l)},se=a=>{const{active:l,over:i}=a;i&&l.id!==i.id&&v(j=>{const A=j.map((Y,Z)=>`${Y}-${Z}`),O=A.indexOf(String(l.id)),ae=A.indexOf(String(i.id));return O!==-1&&ae!==-1?ve(j,O,ae):j})},R=a=>{const l=V.trim();if(l){if(Q(l)){k("A combo cannot bundle itself (circular reference).");return}h.includes(l)||(v([...h,l]),k("")),T("")}},r=async a=>{if(a.preventDefault(),!!G(B)){if(h.length===0){k("At least one model must be added to the combo.");return}if(h.some(Q)){k("A combo cannot bundle itself (circular reference).");return}try{w(!0),await u({id:x==null?void 0:x.id,name:B.trim(),models:h,strategy:S,isActive:x?x.isActive:!0}),le(),f()}catch(l){N((l==null?void 0:l.message)||"Failed to save combo.")}finally{w(!1)}}};return e.jsxs(e.Fragment,{children:[e.jsx(Se,{isOpen:c,onClose:f,maxWidthClass:"w-full max-w-2xl",children:e.jsxs("form",{onSubmit:r,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:_?"edit_note":"add_circle"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-bold text-white",children:q||(_?`Edit Combo: ${x==null?void 0:x.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:f,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:B,onChange:I,className:`w-full bg-[#0A0D14] border rounded-xl px-3.5 py-2 text-xs font-mono text-white placeholder-slate-500 focus:outline-none transition-colors ${D?"border-rose-500/80 focus:border-rose-500":"border-[#1E293B] focus:border-blue-500"}`}),D?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"}),D]}):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:S,onChange:a=>M(a),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:[S==="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."]}),S==="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."]}),S==="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."]}),S==="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."]}),S==="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:y,collisionDetection:fe,onDragEnd:se,children:e.jsx(ge,{items:h.map((a,l)=>`${a}-${l}`),strategy:ye,children:e.jsx("div",{className:"space-y-1.5",children:h.map((a,l)=>e.jsx(Ue,{id:`${a}-${l}`,model:a,index:l,onEdit:i=>J(l,i),onRemove:()=>U(l),onMoveUp:()=>X(l),onMoveDown:()=>W(l),isFirst:l===0,isLast:l===h.length-1,excludeValues:F},`${a}-${l}`))})})})}),P&&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"}),P]}),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:T,onEnter:()=>R(),excludeValues:F,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:f,disabled:b,className:"px-4 py-2 rounded-xl text-xs font-medium text-slate-400 hover:text-white bg-[#141B2D] border border-[#1E293B] hover:border-slate-700 transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:b,className:"px-5 py-2 rounded-xl text-xs font-semibold text-white bg-blue-600 hover:bg-blue-500 shadow-md shadow-blue-600/20 disabled:opacity-50 transition-all flex items-center gap-1.5 cursor-pointer",children:b?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[15px] animate-spin",children:"progress_activity"}),"Saving..."]}):e.jsx("span",{children:_?"Update Combo":"Save Combo"})})]})]})}),E&&e.jsx(Ae,{isOpen:E,onClose:()=>p(!1),addedModelValues:h,initialSelectedModels:h,excludeModelIds:F,allowCombos:!1,onSelect:a=>{h.includes(a.value)||(v(l=>[...l,a.value]),k(""))},onDeselect:a=>{v(l=>l.filter(i=>i!==a.value))},onConfirm:a=>{v(a),a.length>0&&k("")},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,f]=o.useState([]),[x,q]=o.useState(!0),[u,B]=o.useState(Je),[L,S]=o.useState(!1),[M,h]=o.useState(null),[v,D]=o.useState(""),N=o.useMemo(()=>{const r=v.trim().toLowerCase();return r?c.filter(a=>!!(a.name.toLowerCase().includes(r)||a.strategy.toLowerCase().includes(r)||a.models&&a.models.some(l=>l.toLowerCase().includes(r)))):c},[c,v]),[P,k]=o.useState(!1),[V,T]=o.useState(null),[E,p]=o.useState(null),[b,w]=o.useState(null),_=o.useCallback(async()=>{try{q(!0);const r=await fetch("/api/combos");if(r.ok){const a=await r.json();Array.isArray(a)&&f(a)}}catch(r){console.error("Failed to load combos:",r)}finally{q(!1)}},[]),y=o.useCallback(async()=>{try{const r=await fetch("/api/settings/capacity-adapter");if(r.ok){const a=await r.json();a&&typeof a=="object"&&B({vision:a.vision||{enabled:!1,roundRobin:!1,models:[]},audioInput:a.audioInput||{enabled:!1,roundRobin:!1,models:[]},pdf:a.pdf,videoInput:a.videoInput})}}catch(r){console.error("Failed to load capacity adapter settings:",r)}},[]);o.useEffect(()=>{_(),y()},[_,y]);const G=async r=>{B(r);try{S(!0),await fetch("/api/settings/capacity-adapter",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})}catch(a){console.error("Failed to save capacity adapter settings:",a)}finally{S(!1)}},I=r=>{const a=u[r];G({...u,[r]:{...a,enabled:!a.enabled}})},F=(r,a)=>{const l=u[r];G({...u,[r]:{...l,roundRobin:a}})},Q=(r,a)=>{const l=u[r];G({...u,[r]:{...l,models:l.models.filter(i=>i!==a)}})},J=r=>{if(!E)return;const a=u[E];G({...u,[E]:{...a,models:r}}),p(null)},U=async r=>{if(r.id){const a=await fetch(`/api/combos/${r.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r.name,models:r.models,strategy:r.strategy,isActive:r.isActive})});if(!a.ok){const l=await a.json();throw new Error(l.error||"Failed to update combo")}}else{const a=await fetch("/api/combos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r.name,models:r.models,strategy:r.strategy})});if(!a.ok){const l=await a.json();throw new Error(l.error||"Failed to create combo")}}await _(),le(),k(!1),T(null)},X=async r=>{try{const a=await fetch(`/api/combos/${r.id}/toggle`,{method:"POST"});if(a.ok){const l=await a.json();f(i=>i.map(j=>j.id===r.id?l:j)),le()}}catch(a){console.error("Error toggling combo status:",a)}},W=async(r,a)=>{try{const l=await fetch(`/api/combos/${r.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({strategy:a})});if(l.ok){const i=await l.json();f(j=>j.map(A=>A.id===r.id?i:A)),le()}}catch(l){console.error("Error updating strategy:",l)}},se=r=>{w({title:"Delete Combo",message:`Are you sure you want to delete combo "${r.name}"? This action cannot be undone.`,confirmText:"Delete Combo",variant:"danger",onConfirm:async()=>{try{(await fetch(`/api/combos/${r.id}`,{method:"DELETE"})).ok&&(f(l=>l.filter(i=>i.id!==r.id)),le())}catch(a){console.error("Error deleting combo:",a)}finally{w(null)}}})},R=(r,a)=>{navigator.clipboard.writeText(r),h(a),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:()=>{T(null),k(!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 (",v?`${N.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:v,onChange:r=>D(r.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"}),v&&e.jsx("button",{type:"button",onClick:()=>D(""),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"})]})]}),x?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."})]}):N.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 “",v,"”"]}),e.jsx("button",{onClick:()=>D(""),className:"text-xs text-blue-400 hover:underline cursor-pointer",children:"Clear filter"})]}):e.jsx("div",{className:"w-full space-y-2.5",children:N.map((r,a)=>{const l=pe(r.models),i=r.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 ${i?"bg-[#0F1420]/80 border-[#1E293B] hover:border-slate-700":"bg-[#0A0D14]/50 border-[#1E293B]/50 opacity-60"}`,style:{animationDelay:`${a*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 ${r.strategy==="fallback"?"bg-blue-500/10 text-blue-400 border-blue-500/20":r.strategy==="round-robin"?"bg-cyan-500/10 text-cyan-400 border-cyan-500/20":r.strategy==="fusion"?"bg-indigo-500/10 text-indigo-400 border-indigo-500/20":r.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:r.strategy==="fallback"?"low_priority":r.strategy==="round-robin"?"sync":r.strategy==="fusion"?"call_split":r.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:r.name}),l&&e.jsx(oe,{caps:l,size:"xs"}),!i&&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:r.models.map((j,A)=>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:A+1}),e.jsx("span",{children:j})]},A))})]})]}),e.jsxs("div",{className:"flex items-center gap-2.5 shrink-0",children:[e.jsx(ne,{value:r.strategy,onChange:j=>W(r,j),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:i?"Disable combo":"Enable combo",children:[e.jsx("input",{type:"checkbox",checked:i,onChange:()=>X(r),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:M===r.id?"Copied to clipboard!":"Copy combo identifier",onClick:()=>R(r.name,r.id),className:`p-1.5 rounded-lg transition-colors cursor-pointer ${M===r.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:M===r.id?"check":"content_copy"})}),e.jsx("button",{type:"button",title:"Edit combo",onClick:()=>{T(r),k(!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(r),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"})})]})]})]},r.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."})]}),L&&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:()=>I("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:r=>F("vision",r==="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(r=>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:r}),e.jsx("button",{type:"button",onClick:()=>Q("vision",r),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"})})]},r))})]})]}),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:()=>I("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:r=>F("audioInput",r==="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(r=>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:r}),e.jsx("button",{type:"button",onClick:()=>Q("audioInput",r),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"})})]},r))})]})]})]})]}),e.jsx(We,{isOpen:P,onClose:()=>{k(!1),T(null)},combo:V,onSave:U}),E&&e.jsx(Ae,{isOpen:E!==null,onClose:()=>p(null),title:`Configure ${E==="vision"?"Vision":"Audio"} Adapter Model Pool`,initialSelectedModels:u[E].models,onConfirm:J,filterModality:E==="vision"?"vision":"audio",multiSelect:!0}),b&&e.jsx(Ge,{isOpen:b!==null,title:b.title,message:b.message,confirmText:b.confirmText||"Confirm",variant:b.variant||"primary",onConfirm:b.onConfirm,onCancel:()=>w(null)})]})};export{lt as CombosTab};
@@ -1 +1 @@
1
- import{j as e}from"./vendor-BcOI2aZ9.js";import{P as m}from"./index-BdD7LHGu.js";const h=({isOpen:r,title:s,message:o,confirmText:a="Confirm",cancelText:n="Cancel",confirmVariant:l="primary",variant:i,onConfirm:d,onCancel:t})=>{const x=i||l,c=()=>{switch(x){case"danger":return"bg-red-600 hover:bg-red-500 text-white";case"emerald":return"bg-emerald-600 hover:bg-emerald-500 text-white";default:return"bg-blue-600 hover:bg-blue-500 text-white"}};return e.jsx(m,{isOpen:r,onClose:t,maxWidthClass:"max-w-md",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-base font-semibold text-slate-100",children:s}),e.jsx("p",{className:"text-sm text-slate-300 leading-relaxed",children:o}),e.jsxs("div",{className:"flex items-center justify-end gap-3 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{type:"button",onClick:t,className:"px-4 py-2 text-xs font-medium text-slate-400 hover:text-white bg-[#141B2D] border border-[#1E293B] rounded-xl transition-colors cursor-pointer",children:n}),e.jsx("button",{type:"button",onClick:d,className:`px-4 py-2 text-xs font-medium rounded-xl transition-colors cursor-pointer ${c()}`,children:a})]})]})})};export{h as C};
1
+ import{j as e}from"./vendor-BcOI2aZ9.js";import{P as m}from"./index-DVeDwPjn.js";const h=({isOpen:r,title:s,message:o,confirmText:a="Confirm",cancelText:n="Cancel",confirmVariant:l="primary",variant:i,onConfirm:d,onCancel:t})=>{const x=i||l,c=()=>{switch(x){case"danger":return"bg-red-600 hover:bg-red-500 text-white";case"emerald":return"bg-emerald-600 hover:bg-emerald-500 text-white";default:return"bg-blue-600 hover:bg-blue-500 text-white"}};return e.jsx(m,{isOpen:r,onClose:t,maxWidthClass:"max-w-md",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-base font-semibold text-slate-100",children:s}),e.jsx("p",{className:"text-sm text-slate-300 leading-relaxed",children:o}),e.jsxs("div",{className:"flex items-center justify-end gap-3 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{type:"button",onClick:t,className:"px-4 py-2 text-xs font-medium text-slate-400 hover:text-white bg-[#141B2D] border border-[#1E293B] rounded-xl transition-colors cursor-pointer",children:n}),e.jsx("button",{type:"button",onClick:d,className:`px-4 py-2 text-xs font-medium rounded-xl transition-colors cursor-pointer ${c()}`,children:a})]})]})})};export{h as C};