mapigate 0.5.130 → 0.5.136

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 (56) hide show
  1. package/README.md +1 -1
  2. package/dist/core/adapters/anthropic/requestAnthropicToOpenAi.js +59 -11
  3. package/dist/core/adapters/anthropicAdapter.js +2 -2
  4. package/dist/providers/catalog/commandcode/converter.js +215 -0
  5. package/dist/providers/catalog/commandcode/executor.js +305 -0
  6. package/dist/providers/catalog/commandcode/headers.js +76 -0
  7. package/dist/providers/catalog/commandcode/metadata.js +4 -1
  8. package/dist/providers/catalog/commandcode/ndjson.js +161 -0
  9. package/dist/providers/catalog/commandcode/provider.js +18 -35
  10. package/dist/providers/catalog/commandcode/routes.js +75 -0
  11. package/dist/providers/catalog/opencode-go/metadata.js +4 -2
  12. package/dist/providers/catalog/opencode-go/models.js +1 -0
  13. package/dist/providers/catalog/opencode-go/provider.js +114 -0
  14. package/dist/providers/catalog/opencode-go/quota.js +106 -0
  15. package/dist/providers/catalog/opencode-go/responses.js +301 -0
  16. package/dist/providers/catalog/opencode-go/responsesPayload.js +228 -0
  17. package/dist/providers/catalog/sensenova/metadata.js +35 -0
  18. package/dist/providers/core/base/baseProvider.js +3 -0
  19. package/dist/providers/core/base/openAiProvider.js +3 -1
  20. package/dist/providers/generated/routesRegistry.generated.js +2 -0
  21. package/dist/providers/runtime/antigravity/schema.js +19 -1
  22. package/dist/providers/runtime/codebuddy/provider.js +21 -6
  23. package/dist/providers/runtime/kiro/converter.js +2 -1
  24. package/dist/providers/runtime/kiro/executor.js +15 -9
  25. package/dist/providers/runtime/kiro/metadata.js +3 -3
  26. package/dist/providers/runtime/kiro/models.js +11 -0
  27. package/dist/providers/runtime/kiro/provider.js +12 -8
  28. package/dist/providers/runtime/kiro/quota.js +4 -4
  29. package/dist/providers/runtime/opencode/tools.js +38 -16
  30. package/dist/server/proxy/proxyDispatcher.js +136 -17
  31. package/dist/server/proxy/singleModelExecutor.js +14 -2
  32. package/dist/server/routes/apiModels.js +15 -6
  33. package/dist/shared/utils/dnsResolver.js +69 -27
  34. package/dist/web/assets/{CliToolsTab-Ck8EuOcF.js → CliToolsTab-CkzwuwaC.js} +1 -1
  35. package/dist/web/assets/CombosTab-C5RzRwwr.js +1 -0
  36. package/dist/web/assets/{ConfirmModal-1KqBoeRh.js → ConfirmModal-DGvcf0gB.js} +1 -1
  37. package/dist/web/assets/{ConsoleLogTab-DC2FAcl1.js → ConsoleLogTab-84Ens8T5.js} +1 -1
  38. package/dist/web/assets/{EditAccountModal-1EbG3eyM.js → EditAccountModal-D-_omvev.js} +1 -1
  39. package/dist/web/assets/{EndpointTab-C-gwVRmb.js → EndpointTab-7nBfEdYE.js} +1 -1
  40. package/dist/web/assets/{MitmTab-C2kTKbAV.js → MitmTab-CqS6mXHZ.js} +1 -1
  41. package/dist/web/assets/{ModelAutocompleteInput-K8-vMnIb.js → ModelAutocompleteInput-B9syrV1O.js} +1 -1
  42. package/dist/web/assets/ProviderDetailPage-DGZceQ2d.js +6 -0
  43. package/dist/web/assets/{ProvidersTab-w9OOjPmA.js → ProvidersTab-CiYbqRou.js} +1 -1
  44. package/dist/web/assets/{QuotaTab-C43xP8JP.js → QuotaTab-DFr0DWAU.js} +1 -1
  45. package/dist/web/assets/{SettingsTab-BMs0BtId.js → SettingsTab-4c0ksNJa.js} +1 -1
  46. package/dist/web/assets/{UsageTab-C5MbpcRp.js → UsageTab-BQcPmvtQ.js} +1 -1
  47. package/dist/web/assets/{index-DVeDwPjn.js → index-C4NTQZ40.js} +2 -2
  48. package/dist/web/assets/{index-BisuNW2y.css → index-HnsyZg0I.css} +1 -1
  49. package/dist/web/assets/metadataRegistry-B91sal4r.js +1 -0
  50. package/dist/web/assets/providersData-DkVCRBsJ.js +1 -0
  51. package/dist/web/index.html +2 -2
  52. package/package.json +1 -1
  53. package/dist/web/assets/CombosTab-CLPru5aK.js +0 -1
  54. package/dist/web/assets/ProviderDetailPage-BSqwg2fW.js +0 -6
  55. package/dist/web/assets/metadataRegistry-BMKXREeE.js +0 -1
  56. package/dist/web/assets/providersData-D7kilpPx.js +0 -1
@@ -0,0 +1 @@
1
+ import{P as n}from"./metadataRegistry-B91sal4r.js";const s=Object.values(n).filter(e=>e.id!=="combo"&&e.category!=="composite");function a(e){var t;if(!e||e.category==="webCookie"||e.authType==="cookie")return!1;const o=((t=e.id)==null?void 0:t.toLowerCase())||"";return!!(o==="antigravity"||o==="github"||o==="cursor"||o==="kiro"||o==="amazon-q"||o==="codex"||o==="grok-cli"||o==="supergrok"||o==="minimax-code"||o==="codebuddy"||o==="qoder"||o==="cline"||e.oauth!=null||e.category==="oauth"||e.authType==="oauth"||Array.isArray(e.authModes)&&e.authModes.includes("oauth"))}function r(e){var t;if(!e)return!1;const o=((t=e.id)==null?void 0:t.toLowerCase())||"";return o==="opencode"||o==="oc"||o==="ollama-local"||o==="lm-studio"||o==="jan"||e.requiresApiKey===!1||e.authType==="none"||e.noAuth===!0}function i(e){return e?e.category==="freeTier"||e.category==="free"||r(e):!1}const u=s,l=s.filter(e=>i(e)).map(e=>({id:e.id,name:e.name,image:e.image||`/assets/providers/${e.id}/icon.png`,color:e.color||"#10B981",iconBg:e.iconBg,category:"freeTier",defaultConnected:0,baseUrl:e.baseUrl,defaultBaseUrl:e.defaultBaseUrl||e.baseUrl,format:e.format,defaultHeaders:e.defaultHeaders,models:e.models.map(o=>o.id),thinkingMode:e.thinkingMode,authType:e.authType,requiresApiKey:e.requiresApiKey,isLocal:e.isLocal,noAuth:e.noAuth,supportsAutoImport:e.supportsAutoImport,autoImportHint:e.autoImportHint})),c=s.filter(e=>!i(e)&&a(e)).map(e=>({id:e.id,name:e.name,image:e.image||`/assets/providers/${e.id}/icon.png`,color:e.color||"#4285F4",iconBg:e.iconBg,category:"oauth",defaultConnected:0,baseUrl:e.baseUrl,defaultBaseUrl:e.defaultBaseUrl||e.baseUrl,format:e.format,defaultHeaders:e.defaultHeaders,models:e.models.map(o=>o.id),thinkingMode:e.thinkingMode,authType:e.authType,requiresApiKey:e.requiresApiKey,isLocal:e.isLocal,noAuth:e.noAuth,supportsAutoImport:e.supportsAutoImport,autoImportHint:e.autoImportHint})),m=s.filter(e=>!i(e)&&!a(e)).map(e=>({id:e.id,name:e.name,image:e.image||`/assets/providers/${e.id}/icon.png`,color:e.color||"#6366F1",iconBg:e.iconBg,category:"apikey",defaultConnected:0,baseUrl:e.baseUrl,defaultBaseUrl:e.defaultBaseUrl||e.baseUrl,format:e.format,defaultHeaders:e.defaultHeaders,models:e.models.map(o=>o.id),thinkingMode:e.thinkingMode,authType:e.authType,requiresApiKey:e.requiresApiKey,isLocal:e.isLocal,noAuth:e.noAuth,supportsAutoImport:e.supportsAutoImport,autoImportHint:e.autoImportHint})),g=[{id:"claude",name:"Claude Code",image:"/assets/providers/claude/icon.png",status:"Not configured"},{id:"openclaw",name:"Open Claw",image:"/assets/tools/openclaw/icon.png",status:"Not installed"},{id:"codex",name:"OpenAI Codex CLI / App",image:"/assets/providers/codex/icon.png",status:"Not configured"},{id:"copilot",name:"GitHub Copilot",image:"/assets/providers/github/icon.png",iconBg:"#FFFFFF",status:"Guide"},{id:"opencode",name:"OpenCode",image:"/assets/providers/opencode/icon.png",status:"Not configured"},{id:"cowork",name:"Claude Cowork",image:"/assets/providers/claude/icon.png",status:"Not configured"},{id:"hermes",name:"Hermes Agent",image:"/assets/tools/hermes/icon.png",status:"Not installed"},{id:"droid",name:"Factory Droid",image:"/assets/tools/droid/icon.png",status:"Not installed"},{id:"cursor",name:"Cursor",image:"/assets/providers/cursor/icon.png",iconBg:"#FFFFFF",status:"Guide"},{id:"cline",name:"Cline",image:"/assets/providers/cline/icon.png",status:"Not configured"},{id:"kilo",name:"Kilo Code",image:"/assets/providers/kilocode/icon.png",status:"Guide"},{id:"roo",name:"Roo",image:"/assets/tools/roo/icon.png",status:"Guide"},{id:"continue",name:"Continue",image:"/assets/tools/continue/icon.png",status:"Guide"},{id:"amp",name:"Amp CLI",image:"/assets/tools/amp/icon.png",status:"Guide"},{id:"qwen",name:"Qwen Code",image:"/assets/providers/qwen/icon.png",status:"Guide"},{id:"deepseek-tui",name:"DeepSeek TUI",image:"/assets/tools/deepseek-tui/icon.png",status:"Not installed"},{id:"jcode",name:"Jcode",image:"/assets/tools/jcode/icon.png",status:"Not installed"},{id:"grok-build",name:"Grok Build",image:"/assets/tools/grok-build/icon.png",status:"Not installed"},{id:"devin",name:"Devin CLI",image:"/assets/providers/devin/icon.png",status:"Guide"},{id:"opendesign",name:"OpenDesign",image:"/assets/tools/opendesign/icon.png",status:"Guide"},{id:"pi",name:"Pi (pi-coding-agent)",image:"/assets/tools/pi/icon.svg",status:"Not installed"},{id:"omp",name:"Oh My Pi",image:"/assets/tools/omp/icon.png",status:"Not installed"},{id:"crush",name:"Crush",image:"/assets/tools/crush/icon.png",status:"Not installed"},{id:"forge",name:"ForgeCode",image:"/assets/tools/forge/icon.png",status:"Not installed"},{id:"smelt",name:"Smelt",image:"/assets/tools/smelt/icon.svg",status:"Not installed"},{id:"codewhale",name:"CodeWhale",image:"/assets/tools/codewhale/icon.svg",status:"Not installed"}];export{m as A,u as C,l as F,c as O,g as a,a as i};
@@ -8,10 +8,10 @@
8
8
  <link rel="apple-touch-icon" href="/apple-touch-icon.png" />
9
9
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
10
10
  <title>Mapigate - AI Model API Gateway & Token Optimizer</title>
11
- <script type="module" crossorigin src="/assets/index-DVeDwPjn.js"></script>
11
+ <script type="module" crossorigin src="/assets/index-C4NTQZ40.js"></script>
12
12
  <link rel="modulepreload" crossorigin href="/assets/vendor-BcOI2aZ9.js">
13
13
  <link rel="modulepreload" crossorigin href="/assets/lucide-Cc35htxl.js">
14
- <link rel="stylesheet" crossorigin href="/assets/index-BisuNW2y.css">
14
+ <link rel="stylesheet" crossorigin href="/assets/index-HnsyZg0I.css">
15
15
  </head>
16
16
  <body class="bg-zinc-950 text-zinc-100 min-h-screen antialiased">
17
17
  <div id="root"></div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mapigate",
3
- "version": "0.5.130",
3
+ "version": "0.5.136",
4
4
  "description": "AI Model API Gateway & Token Optimizer for coding tools",
5
5
  "author": "Giao Ho",
6
6
  "main": "dist/server/index.js",
@@ -1 +0,0 @@
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,6 +0,0 @@
1
- import{r as s,j as e}from"./vendor-BcOI2aZ9.js";import{i as et}from"./providersData-D7kilpPx.js";import{g as st}from"./metadataRegistry-BMKXREeE.js";import{u as jt,D as yt,P as Te}from"./index-DVeDwPjn.js";import{S as Fe}from"./Select-BNRH8LIG.js";import{T as Me}from"./ToolIcon-Cp4gSgFt.js";import{i as Ce}from"./ModelAutocompleteInput-K8-vMnIb.js";import{C as tt,E as vt}from"./EditAccountModal-1EbG3eyM.js";import{C as Nt}from"./ConfirmModal-1KqBoeRh.js";import"./lucide-Cc35htxl.js";const wt=({isOpen:l,providerId:n,providerName:t,onSuccess:h,onClose:f})=>{const g=s.useRef(h);g.current=h;const c=s.useRef(f);c.current=f;const z=jt(N=>N.info),b=(z==null?void 0:z.port)||yt,M=s.useRef(b);M.current=b;const v=st(n),y=(v==null?void 0:v.regions)||[],[k,_]=s.useState((v==null?void 0:v.defaultRegion)||(y.length>0?y[0].id:"")),S=s.useRef(k);S.current=k;const[C,W]=s.useState(""),[F,V]=s.useState(`http://localhost:${b}/callback`),[A,L]=s.useState(""),[E,T]=s.useState("loading"),[le,Z]=s.useState(null),[R,j]=s.useState(!1),[X,I]=s.useState(!1),[ee,$]=s.useState(!1),[re,xe]=s.useState(!1),[G,ie]=s.useState(null),pe=s.useRef(null),ue=s.useRef(!1),he=s.useRef(void 0),H=s.useRef(void 0),ce=s.useRef(0),U=s.useRef(null),B=s.useCallback(()=>{U.current&&(clearTimeout(U.current),clearInterval(U.current),U.current=null)},[]),o=s.useCallback(async N=>{if(!ue.current){ue.current=!0,B(),T("processing"),Z(null);try{const J=await fetch(`/api/oauth/${n}/exchange`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:N,redirectUri:F,codeVerifier:he.current,state:H.current,region:S.current||void 0})}),q=await J.json().catch(()=>({}));if(!J.ok||q.error)throw new Error(q.error||"Token exchange failed");T("success");try{localStorage.removeItem("oauth_pending_flow"),localStorage.removeItem("oauth_callback")}catch{}setTimeout(()=>{g.current(),c.current()},1200)}catch(J){ue.current=!1,T("error"),Z(J.message||"Failed to exchange authorization token")}}},[n,F,B]),d=s.useCallback(async N=>{const J=++ce.current,q=()=>J!==ce.current;ue.current=!1,B(),T("loading"),Z(null),L(""),xe(!1),ie(null),$(!1),he.current=void 0,H.current=void 0;const ne=N!==void 0?N:S.current,u=ne?`&region=${encodeURIComponent(ne)}`:"",x=ne?`?region=${encodeURIComponent(ne)}`:"",w=window.location.port==="5173"?`http://localhost:${M.current}/callback`:`${window.location.origin}/callback`;V(w);try{const me=await fetch(`/api/oauth/${n}/authorize?redirect_uri=${encodeURIComponent(w)}${u}`),K=await me.json().catch(()=>({}));if(q())return;if(!me.ok||K.error)throw new Error(K.error||`Authorization error (HTTP ${me.status})`);if(K.flowType==="device_code"||!K.authUrl&&K.flowType){xe(!0),T("waiting");const te=await fetch(`/api/oauth/${n}/device-code${x}`),Y=await te.json().catch(()=>({}));if(q())return;if(!te.ok||!Y.device_code)throw new Error(Y.error||"Failed to initiate device code flow");ie(Y);const Ae=Y.verification_uri_complete||Y.verification_uri;if(Ae)try{window.open(Ae,"_blank","noopener,noreferrer")}catch{}let oe=Number(Y.interval)||5,je=!0;const we=Ee=>{q()||(U.current&&clearTimeout(U.current),U.current=setTimeout(async()=>{if(!(!je||q()))try{const de=await(await fetch(`/api/oauth/${n}/poll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:Y.device_code,codeVerifier:Y.codeVerifier,region:ne||void 0,extraData:{...Y||{},_zcodePollToken:Y._zcodePollToken,_minimaxPollByUser:Y._minimaxPollByUser,codeVerifier:Y.codeVerifier,user_code:Y.user_code,region:ne||void 0}})})).json();if(q())return;if(de.ok&&de.success){je=!1,B(),T("success"),setTimeout(()=>{g.current(),c.current()},1200);return}if(de.error==="slow_down"){oe=Math.min(oe+5,30),we(oe);return}if(de.error==="authorization_pending"){we(oe);return}if(de.error){je=!1,B(),T("error"),Z(de.error_description||de.error);return}we(oe)}catch{je&&we(oe)}},Ee*1e3))};we(oe);return}if(K.authUrl){W(K.authUrl),K.redirectUri&&V(K.redirectUri),K.codeVerifier&&(he.current=K.codeVerifier),K.state&&(H.current=K.state),T("waiting");try{localStorage.setItem("oauth_pending_flow",JSON.stringify({providerId:n,redirectUri:K.redirectUri||w,state:K.state,codeVerifier:K.codeVerifier,timestamp:Date.now()}))}catch{}try{const te=window.open(K.authUrl,"oauth_popup","width=600,height=700");te&&!te.closed?pe.current=te:$(!0)}catch{$(!0)}return}throw new Error("No authorization URL returned from provider")}catch(me){if(q())return;if(n==="antigravity"&&DEFAULT_ANTIGRAVITY_AUTH_URL){W(DEFAULT_ANTIGRAVITY_AUTH_URL),T("waiting");try{const K=window.open(DEFAULT_ANTIGRAVITY_AUTH_URL,"oauth_popup","width=600,height=700");K?pe.current=K:$(!0)}catch{$(!0)}}else T("error"),Z(me.message||"Failed to initialize authorization endpoint")}},[n,B]);if(s.useEffect(()=>{if(!l){B(),T("loading"),Z(null),xe(!1),ie(null);return}return d(),()=>{ce.current++,B()}},[l,n,d,B]),s.useEffect(()=>{if(!l)return;const N=x=>{if(!x)return;if(x.done){ue.current=!0,B(),T("success");try{localStorage.removeItem("oauth_pending_flow"),localStorage.removeItem("oauth_callback")}catch{}setTimeout(()=>{g.current(),c.current()},1200);return}if(x.error){T("error"),Z(x.errorDescription||x.error);return}const w=x.code||x.token||(x.userId&&x.token?x.fullUrl||`${window.location.origin}/?user_id=${x.userId}&access_token=${x.token}`:null);w&&o(w)},J=x=>{var w;((w=x.data)==null?void 0:w.type)==="oauth_callback"&&N(x.data.data)};window.addEventListener("message",J);let q=null;try{q=new BroadcastChannel("oauth_callback"),q.onmessage=x=>N(x.data)}catch{}const ne=x=>{if(x.key==="oauth_callback"&&x.newValue)try{const w=JSON.parse(x.newValue);N(w),localStorage.removeItem("oauth_callback")}catch{}};window.addEventListener("storage",ne);const u=setInterval(()=>{try{const x=localStorage.getItem("oauth_callback");if(x){const w=JSON.parse(x);w&&(!w.timestamp||Date.now()-w.timestamp<6e4)&&N(w),localStorage.removeItem("oauth_callback")}}catch{}},500);return()=>{clearInterval(u),window.removeEventListener("message",J),window.removeEventListener("storage",ne),q&&q.close()}},[l,o]),!l)return null;const O=()=>{C&&(navigator.clipboard.writeText(C),j(!0),setTimeout(()=>j(!1),2e3))},be=N=>{N&&(navigator.clipboard.writeText(N),I(!0),setTimeout(()=>I(!1),2e3))},ae=()=>{if(C){$(!1);try{const N=window.open(C,"oauth_popup","width=600,height=700");N&&(pe.current=N)}catch{}}},ye=()=>{A.trim()&&o(A.trim())};return e.jsx(Te,{isOpen:l,onClose:f,maxWidthClass:"max-w-lg",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-blue-400",children:"lock"}),e.jsxs("h3",{className:"text-base font-bold text-white tracking-tight",children:["Connect ",t]})]}),e.jsx("button",{type:"button",onClick:f,className:"text-slate-400 hover:text-white p-1 rounded-lg hover:bg-white/5 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),y.length>0&&e.jsxs("div",{className:"space-y-1.5 p-3 rounded-xl bg-[#0A0D14] border border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"block text-xs font-medium text-slate-300",children:"Server / Region:"}),e.jsx("span",{className:"text-[10px] text-slate-500 font-mono",children:k})]}),e.jsx(Fe,{value:k,onChange:N=>{_(N),S.current=N,d(N)},options:y.map(N=>({value:N.id,label:N.label}))})]}),E==="loading"&&e.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2.5 border border-blue-500/20 rounded-xl bg-blue-500/10 text-xs text-blue-300",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-blue-400 animate-spin",children:"progress_activity"}),e.jsxs("span",{children:["Initializing authorization for ",t,"..."]})]}),E==="waiting"&&e.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2.5 border border-blue-500/20 rounded-xl bg-blue-500/10 text-xs text-blue-300",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-blue-400 animate-spin",children:"progress_activity"}),e.jsx("span",{children:re?"Waiting for device authorization in browser...":ee?"Authorization link ready. Click button below to open login window.":"Popup window opened. Complete authorization in browser..."})]}),E==="processing"&&e.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2.5 border border-blue-500/20 rounded-xl bg-blue-500/10 text-xs text-blue-300",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-blue-400 animate-spin",children:"sync"}),e.jsx("span",{children:"Exchanging authorization code and saving credentials..."})]}),E==="success"&&e.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2.5 border border-emerald-500/30 rounded-xl bg-emerald-500/10 text-xs text-emerald-300",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-emerald-400 font-bold",children:"check_circle"}),e.jsx("span",{children:"Connected successfully! Refreshing connections..."})]}),E==="error"&&le&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-2.5 px-3.5 py-2.5 border border-red-500/30 rounded-xl bg-red-500/10 text-xs text-red-300",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-red-400 mt-0.5 shrink-0",children:"error"}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("p",{className:"font-semibold",children:"Connection Failed"}),e.jsx("p",{className:"text-red-200",children:le})]})]}),e.jsxs("button",{type:"button",onClick:()=>d(),className:"w-full flex items-center justify-center gap-1.5 py-2 px-3 rounded-xl bg-white/5 hover:bg-white/10 text-xs font-semibold text-slate-200 border border-[#1E293B] cursor-pointer transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"refresh"}),"Retry Authorization"]})]}),re&&G?e.jsxs("div",{className:"space-y-4 pt-1",children:[e.jsxs("div",{className:"p-3.5 rounded-xl border border-blue-500/20 bg-blue-500/5 space-y-2",children:[e.jsx("label",{className:"text-xs font-semibold text-slate-200 block",children:"Your One-Time Device Code:"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"flex-1 bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-sm font-mono text-white tracking-widest font-bold text-center select-all",children:G.user_code}),e.jsxs("button",{type:"button",onClick:()=>be(G.user_code),className:"flex items-center gap-1 px-3 py-2 rounded-xl border border-[#1E293B] bg-[#0A0D14] text-xs font-medium text-slate-300 hover:text-white transition-colors cursor-pointer shrink-0",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${X?"text-emerald-400":""}`,children:X?"check":"content_copy"}),X?"Copied":"Copy Code"]})]})]}),e.jsxs("button",{type:"button",onClick:()=>{const N=G.verification_uri_complete||G.verification_uri;N&&window.open(N,"_blank","noopener,noreferrer")},className:"rt-btn rt-btn--primary w-full flex items-center justify-center gap-2 py-2.5 cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"open_in_new"}),"Open Verification Page"]}),e.jsxs("div",{className:"flex items-center gap-3 my-2",children:[e.jsx("div",{className:"flex-1 h-px bg-[#1E293B]"}),e.jsx("span",{className:"text-[11px] font-bold text-slate-500 uppercase tracking-wider",children:"OR PASTE TOKEN MANUALLY"}),e.jsx("div",{className:"flex-1 h-px bg-[#1E293B]"})]}),e.jsx("div",{className:"space-y-1.5",children:e.jsx("input",{type:"text",value:A,onChange:N=>L(N.target.value),placeholder:"Paste token or authorization response...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs font-mono text-slate-200 focus:outline-none focus:border-blue-500"})})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("button",{type:"button",onClick:ae,disabled:!C||E==="loading",className:"rt-btn rt-btn--primary w-full flex items-center justify-center gap-2 py-2.5 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"open_in_new"}),e.jsx("span",{children:"Open Authorization Window"})]}),ee&&e.jsxs("p",{className:"text-[11px] text-amber-400 text-center flex items-center justify-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"info"}),"Browser blocked popup window. Click above to open the login window directly."]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"text-xs font-semibold text-slate-200",children:"Step 1: Authorization Link"}),C&&e.jsx("button",{type:"button",onClick:()=>window.open(C,"_blank"),className:"text-[11px] text-blue-400 hover:text-blue-300 underline cursor-pointer",children:"Open in new tab"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",readOnly:!0,value:C||(E==="loading"?"Initializing link...":"Generating authorization link..."),className:"flex-1 bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs font-mono text-slate-300 focus:outline-none focus:border-blue-500 select-all"}),e.jsxs("button",{type:"button",onClick:O,disabled:!C,className:"flex items-center gap-1 px-3 py-2 rounded-xl border border-[#1E293B] bg-[#0A0D14] text-xs font-medium text-slate-300 hover:text-white transition-colors cursor-pointer shrink-0 disabled:opacity-50",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${R?"text-emerald-400":""}`,children:R?"check":"content_copy"}),R?"Copied":"Copy Link"]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 my-2",children:[e.jsx("div",{className:"flex-1 h-px bg-[#1E293B]"}),e.jsx("span",{className:"text-[11px] font-bold text-slate-500 uppercase tracking-wider",children:"OR PASTE CALLBACK URL / CODE"}),e.jsx("div",{className:"flex-1 h-px bg-[#1E293B]"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold text-slate-200",children:"Step 2: Paste callback URL or authorization code here"}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"After logging in, copy the full URL from your browser address bar and paste it below."}),e.jsx("input",{type:"text",value:A,onChange:N=>L(N.target.value),placeholder:n==="codex"?"http://localhost:1455/auth/callback?code=... or code":`${window.location.origin}/callback?code=... or code`,className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs font-mono text-slate-200 focus:outline-none focus:border-blue-500"})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2.5 pt-3 border-t border-[#1E293B]",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 transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"button",onClick:ye,disabled:!A.trim()||E==="processing",className:"rt-btn rt-btn--primary disabled:opacity-50 disabled:cursor-not-allowed",children:E==="processing"?"Exchanging...":"Connect"})]})]})})};function kt(l,n={}){const{isCloudflareAi:t=!1}=n,h=l.trim();if(!t&&/^LLM\|/i.test(h))return{baseName:"LLM",apiKey:h};const f=l.split("|");if(t&&f.length>=3){const c=f[0].trim(),z=f.slice(1,-1).join("|").trim(),b=f[f.length-1].trim();return{baseName:c||"Key",apiKey:z,providerSpecificData:{accountId:b}}}if(f.length>=2){const c=f[0].trim(),z=f.slice(1).join("|").trim();return{baseName:c||"Key",apiKey:z}}return{baseName:"Key",apiKey:f[0].trim()}}function Ct(l,n=[],t={}){const h=Array.isArray(n)?n:[],f=new Set(h.map(c=>typeof c=="string"?c.toLowerCase():"")),g=[];for(const c of l){const z=typeof c=="string"?c.trim():"";if(!z)continue;const b=kt(z,t);if(!b||!b.apiKey)continue;const M=b.baseName;let v=1,y;for(;y=`${M} ${v}`,!!f.has(y.toLowerCase());)v+=1;f.add(y.toLowerCase());const k={name:y,apiKey:b.apiKey};b.providerSpecificData&&(k.providerSpecificData=b.providerSpecificData),g.push(k)}return g}const At=({isOpen:l,provider:n,existingNames:t=[],onClose:h,onSuccess:f,onOpenOAuth:g})=>{const c=n.id.toLowerCase(),z=c==="opencode"||c==="oc"||!!n.noAuth||n.requiresApiKey===!1||n.authType==="none",b=c==="ollama-local"||c.includes("ollama"),M=!!n.isLocal||c==="lm-studio"||c==="jan",v=z||b||M||n.requiresApiKey===!1,y=c==="azure"||c.includes("azure"),k=c==="cloudflare-ai"||c==="cloudflare",_=c==="bedrock"||c.includes("bedrock"),S=c==="grok-web"||c==="iflow",C=c==="xiaomi-tokenplan",W=c==="alicode"||c==="alibaba",F=s.useMemo(()=>C?[{id:"sgp",label:"Singapore (新加坡)"},{id:"cn",label:"China (中国大陆)"},{id:"ams",label:"Amsterdam (阿姆斯特丹)"}]:n.regions||[],[C,n.regions]),[V,A]=s.useState(n.defaultRegion||(F.length>0?F[0].id:"sgp")),[L,E]=s.useState("single"),[T,le]=s.useState(""),[Z,R]=s.useState(""),[j,X]=s.useState(""),[I,ee]=s.useState("http://127.0.0.1:11434"),[$,re]=s.useState(n.defaultBaseUrl||(c==="lm-studio"?"http://localhost:1234/v1":c==="jan"?"http://localhost:1337/v1":"http://localhost:8000/v1")),[xe,G]=s.useState(""),[ie,pe]=s.useState("gpt-4"),[ue,he]=s.useState("2024-10-01-preview"),[H,ce]=s.useState(""),[U,B]=s.useState(""),[o,d]=s.useState(""),[O,be]=s.useState("profile"),[ae,ye]=s.useState(""),[N,J]=s.useState("us-east-1"),[q,ne]=s.useState(""),[u,x]=s.useState(""),[w,me]=s.useState(""),[K,te]=s.useState(null),[Y,Ae]=s.useState(!1),[oe,je]=s.useState(null),[we,Ee]=s.useState(null),[Se,de]=s.useState(!1),[Be,ve]=s.useState(null),De=s.useCallback(()=>{E("single"),le(""),R(""),X(""),ee("http://127.0.0.1:11434"),re(n.defaultBaseUrl||(c==="lm-studio"?"http://localhost:1234/v1":c==="jan"?"http://localhost:1337/v1":"http://localhost:8000/v1")),G(""),pe("gpt-4"),he("2024-10-01-preview"),ce(""),B(""),d(""),be("profile"),ye(""),J("us-east-1"),ne(""),x(""),A(n.defaultRegion||(F.length>0?F[0].id:"sgp")),me(""),te(null),Ae(!1),je(null),Ee(null),de(!1),ve(null)},[n.defaultBaseUrl,n.defaultRegion,F,c]);s.useEffect(()=>{l&&De()},[l,De]);const se=()=>{De(),h()},Pe=()=>S?c==="grok-web"?"sso=xxxx... or raw cookie":"eyJhbGciOi...":v?"Optional / Not required":C?"tp-...":c.startsWith("deepseek")?"sk-...":c.startsWith("xai")?"xai-...":c.startsWith("groq")?"gsk_...":c.startsWith("anthropic")?"sk-ant-...":c.startsWith("gemini")?"AIzaSy...":"sk-...",_e=()=>{if(b)return{baseUrl:I.trim()||"http://127.0.0.1:11434"};if(M)return{baseUrl:$.trim()};if(y)return{azureEndpoint:xe.trim(),deployment:ie.trim(),apiVersion:ue.trim(),organization:H.trim()||void 0};if(k)return{accountId:U.trim()};if(_)return O==="profile"?{profile:ae.trim(),region:N.trim()||"us-east-1"}:{accessKeyId:q.trim(),region:N.trim()||"us-east-1",sessionToken:u.trim()||void 0};if(C||F.length>0){const p={region:V};return W&&o.trim()&&(p.baseUrl=o.trim()),p}},Re=()=>v?!0:_&&O==="profile"?!!ae.trim():_&&O==="static"?!!(j.trim()&&q.trim()):y?!!(j.trim()&&xe.trim()&&ie.trim()):k?!!(j.trim()&&U.trim()):C?!!(j.trim()&&V):!!j.trim(),Ue=async()=>{Ae(!0),je(null),Ee(null);try{const p=_e(),Q=await(await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:n.id,apiKey:j.trim(),providerSpecificData:p})})).json();Q.valid?je("valid"):(je("invalid"),Ee(Q.error||"Validation check failed"))}catch(p){je("invalid"),Ee(p.message||"Connection check error")}finally{Ae(!1)}},Oe=async()=>{if(!Re())return;de(!0),ve(null);const p=z?c==="opencode"||c==="oc"?"OpenCode Free":`${n.name} (Public)`:b?"Ollama Local":M?`${n.name} Local`:_&&O==="profile"?`Bedrock (${ae})`:C?`Xiaomi MiMo (${V.toUpperCase()})`:`${n.name} Account`,ge=T.trim()||p,Q=_e()||{};Z.trim()&&(Q.tag=Z.trim().toLowerCase());try{const ke=await fetch(`/api/providers/${n.id}/accounts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:ge,apiKey:j.trim()||(c==="opencode"||c==="oc"?"public":""),providerSpecificData:Object.keys(Q).length>0?Q:void 0})});if(!ke.ok){const Le=await ke.json().catch(()=>({}));throw new Error(Le.error||`Server returned ${ke.status}`)}Ce(),De(),f(),h()}catch(ke){ve(ke.message||"Failed to save account")}finally{de(!1)}},Ne=async()=>{if(!w.trim())return;de(!0),te(null),ve(null);const p=w.split(`
2
- `),ge=Ct(p,t,{isCloudflareAi:k});if(ge.length===0){ve("No valid keys found in input"),de(!1);return}try{const Q=await fetch(`/api/providers/${n.id}/accounts/bulk`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({accounts:ge})});if(!Q.ok){const Le=await Q.json().catch(()=>({}));throw new Error(Le.error||`Bulk addition failed (${Q.status})`)}const ke=await Q.json();Ce(),te({success:ke.count||ge.length,failed:0}),setTimeout(()=>{De(),f(),h()},700)}catch(Q){ve(Q.message||"Failed to add bulk keys")}finally{de(!1)}};return e.jsx(Te,{isOpen:l,onClose:se,maxWidthClass:"max-w-xl",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Me,{src:n.image,name:n.name,color:n.color,iconBg:n.iconBg,size:"md",fallback:e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[20px]",children:"vpn_key"})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-bold text-white",children:["Add ",n.name," Connection"]}),e.jsx("p",{className:"text-xs text-slate-400",children:S?"Paste session cookie credentials":_?"Configure AWS SSO profile or static keys":y?"Configure Azure OpenAI deployment & endpoint":b?"Connect local self-hosted model service":M?`Connect local ${n.name} model server`:v?"No API key required for this provider":C?"Select cluster region & paste Token Plan API key":"API key is hardware-encrypted (AES-256-GCM)"})]})]}),e.jsx("button",{onClick:se,className:"text-slate-400 hover:text-white p-1 rounded-lg hover:bg-white/10 cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),g&&e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-xl border border-blue-500/20 bg-blue-500/10 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2 text-blue-300",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] text-blue-400",children:"lock"}),e.jsx("span",{children:"This provider also supports OAuth authorization."})]}),e.jsx("button",{type:"button",onClick:g,className:"rt-btn rt-btn--primary text-xs py-1 px-3 cursor-pointer shrink-0",children:"Connect with OAuth"})]}),!_&&!b&&!v&&e.jsxs("div",{className:"flex bg-[#0A0D14] p-1 rounded-xl border border-[#1E293B] text-xs",children:[e.jsx("button",{onClick:()=>{E("single"),te(null)},className:`flex-1 py-1.5 rounded-lg font-medium transition-colors cursor-pointer ${L==="single"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Single Connection"}),e.jsx("button",{onClick:()=>{E("bulk"),te(null)},className:`flex-1 py-1.5 rounded-lg font-medium transition-colors cursor-pointer ${L==="bulk"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Bulk Add Keys"})]}),L==="bulk"&&!_&&!b&&!v?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"text-xs text-slate-400 space-y-1",children:[e.jsx("p",{children:"One key per line. Format:"}),e.jsx("code",{className:"block bg-[#0A0D14] p-2 rounded-lg border border-[#1E293B] font-mono text-[11px] text-blue-300",children:k?`name|apiToken|accountId
3
- or just apiToken`:`name|apiKey
4
- or just apiKey (auto-numbered)`})]}),e.jsx("textarea",{value:w,onChange:p=>me(p.target.value),placeholder:k?`Prod|cf_token_123|acc_xyz456
5
- Beta|cf_token_456|acc_xyz789`:`Primary|sk-...
6
- Backup|sk-...`,className:"w-full h-36 bg-[#0A0D14] border border-[#1E293B] rounded-xl p-3 text-xs font-mono text-slate-200 focus:outline-none focus:border-blue-500"}),K&&e.jsxs("div",{className:"text-xs text-emerald-400 flex items-center gap-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"check_circle"}),"Successfully added ",K.success," connection(s)."]}),Be&&e.jsx("p",{className:"text-xs text-rose-400",children:Be}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{onClick:Ne,disabled:Se||!w.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:Se?"Adding...":"Add All Keys"}),e.jsx("button",{onClick:se,className:"rt-btn rt-btn--secondary",children:"Cancel"})]})]}):e.jsxs("div",{className:"space-y-3.5 text-xs",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Connection Label"}),e.jsx("input",{type:"text",value:T,onChange:p=>le(p.target.value),placeholder:b?"Ollama Local":M?`${n.name} Local`:z?"OpenCode Free":"Primary Key (Production)",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("label",{className:"text-slate-300 font-medium flex items-center gap-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px] text-blue-400",children:"label"}),"Group Tag"]}),e.jsx("span",{className:"text-slate-500 text-[11px]",children:"Optional • For grouping in Combos"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"text",value:Z,onChange:p=>R(p.target.value.toLowerCase().replace(/[^a-z0-9_-]/g,"")),placeholder:"e.g. pro, plus, free, team",className:"w-full bg-[#0A0D14] border border-[#1E293B] text-slate-100 pl-3 pr-20 py-2 rounded-xl focus:outline-none focus:border-blue-500 transition-colors font-mono"}),e.jsx("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-1 pointer-events-none",children:["pro","plus","free"].map(p=>e.jsx("button",{type:"button",tabIndex:-1,onClick:ge=>{ge.preventDefault(),R(p)},className:`pointer-events-auto text-[10px] px-1.5 py-0.5 rounded font-mono transition-colors ${Z===p?"bg-blue-600 text-white font-semibold":"bg-[#1E293B] text-slate-400 hover:text-slate-200"}`,children:p},p))})]})]})]}),v&&e.jsxs("div",{className:"p-3 bg-emerald-500/10 border border-emerald-500/20 rounded-xl text-emerald-300 text-xs flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-emerald-400 text-[18px]",children:"verified"}),e.jsxs("span",{children:[n.name," does not require an API key. You can save immediately or customize the connection label."]})]}),(C||F.length>0)&&e.jsxs("div",{className:"space-y-1.5 p-3.5 bg-[#0A0D14] border border-[#1E293B] rounded-xl",children:[e.jsxs("label",{className:"block text-slate-300 font-medium mb-1",children:["Cluster Region ",e.jsx("span",{className:"text-red-400",children:"*"})]}),e.jsx(Fe,{value:V,onChange:p=>A(p),options:F.map(p=>({value:p.id,label:p.label.includes(p.id)?p.label:`${p.label} (${p.id})`})),className:"w-full",triggerClassName:"bg-[#0F1420] font-mono text-xs py-2"}),C&&e.jsx("p",{className:"text-[11px] text-slate-400 mt-1",children:"Token Plan keys are cluster-specific — select the region matching your subscription."}),W&&e.jsxs("div",{className:"pt-2 border-t border-[#1E293B]/70 mt-2 space-y-1",children:[e.jsxs("label",{className:"block text-slate-400 text-xs",children:["Dedicated Workspace Endpoint URL ",e.jsx("span",{className:"text-slate-500",children:"(Optional)"})]}),e.jsx("input",{type:"text",value:o,onChange:p=>d(p.target.value),placeholder:"e.g. https://ws-xxx.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",className:"w-full bg-[#0F1420] border border-[#1E293B] rounded-xl px-3 py-1.5 text-white font-mono text-xs focus:outline-none focus:border-blue-500"}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"Required if your API key was created inside an Alibaba Model Studio custom workspace."})]})]}),b&&e.jsx("div",{className:"space-y-3 p-3.5 bg-[#0A0D14] border border-[#1E293B] rounded-xl",children:e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Ollama Host URL"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:I,onChange:p=>ee(p.target.value),placeholder:"http://127.0.0.1:11434",className:"flex-1 bg-[#0F1420] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500 font-mono"}),e.jsx("button",{type:"button",onClick:Ue,disabled:Y,className:"rt-btn rt-btn--secondary shrink-0",children:Y?"Checking...":"Check"})]}),e.jsxs("p",{className:"text-[11px] text-slate-400 mt-1.5",children:["Default is ",e.jsx("code",{className:"text-blue-300 font-mono",children:"http://127.0.0.1:11434"}),". For remote Ollama instances, enter the full host URL."]})]})}),M&&e.jsx("div",{className:"space-y-3 p-3.5 bg-[#0A0D14] border border-[#1E293B] rounded-xl",children:e.jsxs("div",{children:[e.jsxs("label",{className:"block text-slate-300 font-medium mb-1",children:[n.name," Endpoint URL"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:$,onChange:p=>re(p.target.value),placeholder:n.defaultBaseUrl||"http://localhost:1234/v1",className:"flex-1 bg-[#0F1420] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500 font-mono"}),e.jsx("button",{type:"button",onClick:Ue,disabled:Y,className:"rt-btn rt-btn--secondary shrink-0",children:Y?"Checking...":"Check"})]}),e.jsxs("p",{className:"text-[11px] text-slate-400 mt-1.5",children:["Default is ",e.jsx("code",{className:"text-blue-300 font-mono",children:n.defaultBaseUrl||"http://localhost:1234/v1"}),". Ensure ",n.name," local server is started."]})]})}),y&&e.jsxs("div",{className:"space-y-3 p-3.5 bg-[#0A0D14] border border-[#1E293B] rounded-xl",children:[e.jsx("span",{className:"font-semibold text-blue-400 block",children:"Azure OpenAI Configuration"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"Azure Endpoint"}),e.jsx("input",{type:"text",value:xe,onChange:p=>G(p.target.value),placeholder:"https://my-resource.openai.azure.com",className:"w-full bg-[#0F1420] border border-[#1E293B] rounded-xl px-3 py-1.5 text-white font-mono"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"Deployment Name"}),e.jsx("input",{type:"text",value:ie,onChange:p=>pe(p.target.value),placeholder:"gpt-4",className:"w-full bg-[#0F1420] border border-[#1E293B] rounded-xl px-3 py-1.5 text-white font-mono"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"API Version"}),e.jsx("input",{type:"text",value:ue,onChange:p=>he(p.target.value),placeholder:"2024-10-01-preview",className:"w-full bg-[#0F1420] border border-[#1E293B] rounded-xl px-3 py-1.5 text-white font-mono"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"Organization (Optional)"}),e.jsx("input",{type:"text",value:H,onChange:p=>ce(p.target.value),placeholder:"org-id",className:"w-full bg-[#0F1420] border border-[#1E293B] rounded-xl px-3 py-1.5 text-white font-mono"})]})]})]}),k&&e.jsxs("div",{className:"space-y-3 p-3.5 bg-[#0A0D14] border border-[#1E293B] rounded-xl",children:[e.jsx("span",{className:"font-semibold text-blue-400 block",children:"Cloudflare Workers AI"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"Account ID"}),e.jsx("input",{type:"text",value:U,onChange:p=>B(p.target.value),placeholder:"abc123def456...",className:"w-full bg-[#0F1420] border border-[#1E293B] rounded-xl px-3 py-1.5 text-white font-mono"}),e.jsxs("p",{className:"text-[11px] text-slate-400 mt-1",children:["Find Account ID in the right sidebar of"," ",e.jsx("a",{href:"https://dash.cloudflare.com",target:"_blank",rel:"noreferrer",className:"text-blue-400 underline",children:"dash.cloudflare.com"})]})]})]}),_&&e.jsxs("div",{className:"space-y-3 p-3.5 bg-[#0A0D14] border border-[#1E293B] rounded-xl",children:[e.jsxs("div",{className:"flex bg-[#0F1420] p-1 rounded-xl border border-[#1E293B] text-[11px]",children:[e.jsx("button",{type:"button",onClick:()=>be("profile"),className:`flex-1 py-1 rounded-lg font-medium transition-colors cursor-pointer ${O==="profile"?"bg-blue-600 text-white":"text-slate-400 hover:text-white"}`,children:"AWS Profile (SSO — Recommended)"}),e.jsx("button",{type:"button",onClick:()=>be("static"),className:`flex-1 py-1 rounded-lg font-medium transition-colors cursor-pointer ${O==="static"?"bg-blue-600 text-white":"text-slate-400 hover:text-white"}`,children:"Static Keys (AKIA...)"})]}),O==="profile"?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"AWS Profile Name"}),e.jsx("input",{type:"text",value:ae,onChange:p=>ye(p.target.value),placeholder:"my-sso-profile",className:"w-full bg-[#0F1420] border border-[#1E293B] rounded-xl px-3 py-1.5 text-white font-mono"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"AWS Region"}),e.jsx("input",{type:"text",value:N,onChange:p=>J(p.target.value),placeholder:"us-east-1",className:"w-full bg-[#0F1420] border border-[#1E293B] rounded-xl px-3 py-1.5 text-white font-mono"})]})]}),e.jsxs("p",{className:"text-[11px] text-slate-400",children:["Configure a profile from ",e.jsx("code",{className:"text-blue-300 font-mono",children:"~/.aws/config"})," and run"," ",e.jsxs("code",{className:"text-blue-300 font-mono",children:["aws sso login --profile ",ae||"my-sso-profile"]}),"."]})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"Access Key ID"}),e.jsx("input",{type:"text",value:q,onChange:p=>ne(p.target.value),placeholder:"AKIA...",className:"w-full bg-[#0F1420] border border-[#1E293B] rounded-xl px-3 py-1.5 text-white font-mono"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"AWS Region"}),e.jsx("input",{type:"text",value:N,onChange:p=>J(p.target.value),placeholder:"us-east-1",className:"w-full bg-[#0F1420] border border-[#1E293B] rounded-xl px-3 py-1.5 text-white font-mono"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"Session Token (Optional)"}),e.jsx("input",{type:"password",value:u,onChange:p=>x(p.target.value),placeholder:"FwoGZXIvYXdz...",className:"w-full bg-[#0F1420] border border-[#1E293B] rounded-xl px-3 py-1.5 text-white font-mono"})]})]})]}),!b&&!(_&&O==="profile")&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:S?"Cookie Value":_?"Secret Access Key":k?"Cloudflare API Token":C?"Token Plan Key (tp-...)":v?"API Key (Optional)":"API Key"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:S?"text":"password",value:j,onChange:p=>X(p.target.value),placeholder:Pe(),className:"flex-1 bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500 font-mono"}),e.jsx("button",{type:"button",onClick:Ue,disabled:Y||!Re(),className:"rt-btn rt-btn--secondary shrink-0",children:Y?"Checking...":"Check"})]})]}),oe&&e.jsxs("div",{className:`p-2.5 rounded-xl border flex items-center gap-2 ${oe==="valid"?"bg-emerald-500/10 border-emerald-500/20 text-emerald-400":"bg-rose-500/10 border-rose-500/20 text-rose-400"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:oe==="valid"?"check_circle":"error"}),e.jsx("span",{children:oe==="valid"?"Credentials verified successfully!":we||"Invalid credentials."})]}),Be&&e.jsx("p",{className:"text-xs text-rose-400",children:Be}),e.jsxs("div",{className:"flex gap-2 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{type:"button",onClick:Oe,disabled:Se||!Re(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:Se?"Saving Connection...":"Save Connection"}),e.jsx("button",{type:"button",onClick:se,className:"rt-btn rt-btn--secondary",children:"Cancel"})]})]})]})})},St=({isOpen:l,onClose:n,onSuccess:t})=>{const[h,f]=s.useState("device"),[g,c]=s.useState(null),[z,b]=s.useState(!1),[M,v]=s.useState(!1),[y,k]=s.useState("idle"),[_,S]=s.useState(null),[C,W]=s.useState(""),[F,V]=s.useState(""),[A,L]=s.useState(!1),E=s.useRef(null),T=()=>{E.current&&(clearTimeout(E.current),clearInterval(E.current),E.current=null)};s.useEffect(()=>{if(!l){T(),c(null),k("idle"),W(""),V(""),S(null);return}return W(""),V(""),S(null),h==="device"&&le(),()=>{T()}},[l,h]);const le=async()=>{T(),b(!0),S(null),k("idle");try{const j=await fetch("/api/oauth/github/device-code",{method:"POST"});if(!j.ok){const re=await j.text();throw new Error(re||"Failed to initiate GitHub device flow")}const X=await j.json();c(X),k("polling");let I=Math.max(X.interval||5,5),ee=!0;const $=re=>{E.current&&clearTimeout(E.current),E.current=setTimeout(async()=>{if(ee)try{const G=await(await fetch("/api/oauth/github/poll",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:X.device_code})})).json();if(G.ok){ee=!1,k("success"),setTimeout(()=>{t(),n()},1200);return}if(G.error==="slow_down"){I=Math.min(I+5,30),$(I);return}if(G.error==="authorization_pending"){$(I);return}ee=!1,k("error"),S(G.error_description||G.error)}catch{ee&&$(I)}},re*1e3)};$(I)}catch(j){k("error"),S(j.message||"Failed to request device code")}finally{b(!1)}},Z=j=>{navigator.clipboard.writeText(j),v(!0),setTimeout(()=>v(!1),2e3)},R=async()=>{if(C.trim()){L(!0),S(null);try{const j=await fetch("/api/oauth/github/token",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:C.trim(),name:F.trim()||void 0})});if(!j.ok){const X=await j.json().catch(()=>({}));throw new Error(X.error||"Failed to save GitHub token")}t(),n()}catch(j){S(j.message||"Could not save token")}finally{L(!1)}}};return l?e.jsx(Te,{isOpen:l,onClose:n,maxWidthClass:"max-w-lg",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Me,{src:"/assets/providers/github/icon.png",name:"GitHub Copilot",color:"#333333",iconBg:"#FFFFFF",size:"md"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-white",children:"Connect GitHub Copilot"}),e.jsx("p",{className:"text-xs text-slate-400",children:"Authorize via official GitHub Device Flow"})]})]}),e.jsx("button",{onClick:n,className:"text-slate-400 hover:text-white p-1 rounded-lg hover:bg-white/10",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),e.jsxs("div",{className:"flex bg-[#0A0D14] p-1 rounded-xl border border-[#1E293B] text-xs",children:[e.jsx("button",{onClick:()=>f("device"),className:`flex-1 py-1.5 rounded-lg font-medium transition-colors ${h==="device"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"GitHub Device Code Flow"}),e.jsx("button",{onClick:()=>f("token"),className:`flex-1 py-1.5 rounded-lg font-medium transition-colors ${h==="token"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Paste Token Directly"})]}),h==="device"?e.jsxs("div",{className:"space-y-4 text-xs",children:[z?e.jsxs("div",{className:"py-8 text-center text-slate-400 space-y-2",children:[e.jsx("span",{className:"material-symbols-outlined text-3xl text-blue-400 animate-spin",children:"progress_activity"}),e.jsx("p",{children:"Requesting GitHub device code..."})]}):g?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"p-3 bg-[#0A0D14] border border-[#1E293B] rounded-xl space-y-2",children:[e.jsx("span",{className:"text-slate-400 uppercase text-[10px] font-bold block",children:"Step 1: Copy One-Time User Code"}),e.jsxs("div",{className:"flex items-center justify-between gap-3 bg-[#0F1420] p-3 rounded-lg border border-[#1E293B]",children:[e.jsx("span",{className:"text-xl font-mono font-bold text-white tracking-widest",children:g.user_code}),e.jsxs("button",{onClick:()=>Z(g.user_code),className:"rt-btn rt-btn--secondary py-1 text-xs",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:M?"check":"content_copy"}),M?"Copied":"Copy Code"]})]})]}),e.jsxs("div",{className:"p-3 bg-[#0A0D14] border border-[#1E293B] rounded-xl space-y-2",children:[e.jsx("span",{className:"text-slate-400 uppercase text-[10px] font-bold block",children:"Step 2: Authorize in Browser"}),e.jsx("p",{className:"text-slate-300",children:"Open GitHub activation page and enter the user code shown above:"}),e.jsxs("a",{href:g.verification_uri||"https://github.com/login/device",target:"_blank",rel:"noreferrer",className:"rt-btn rt-btn--primary w-full text-center inline-flex items-center justify-center gap-1.5",children:[e.jsx("span",{children:"Open https://github.com/login/device"}),e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"open_in_new"})]})]}),y==="polling"&&e.jsxs("div",{className:"flex items-center justify-center gap-2 text-slate-400 py-1 font-mono text-[11px]",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[16px] animate-spin",children:"sync"}),e.jsx("span",{children:"Waiting for authorization on github.com..."})]}),y==="success"&&e.jsxs("div",{className:"p-3 rounded-xl bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"check_circle"}),e.jsx("span",{children:"Authorized successfully! Connecting Copilot..."})]})]}):null,_&&e.jsxs("div",{className:"p-3 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400 flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"error"}),e.jsx("span",{children:_})]})]}):e.jsxs("div",{className:"space-y-3.5 text-xs",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Account Label"}),e.jsx("input",{type:"text",value:F,onChange:j=>V(j.target.value),placeholder:"Copilot Work Account",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"GitHub Access Token or Copilot Token"}),e.jsx("input",{type:"password",value:C,onChange:j=>W(j.target.value),placeholder:"ghu_... or ghp_...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500 font-mono"}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-1.5",children:"Paste your GitHub token from VS Code extension or personal token. Mapigate encrypts it locally."})]}),_&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:_}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{onClick:R,disabled:A||!C.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:A?"Connecting...":"Save Copilot Account"}),e.jsx("button",{onClick:n,className:"rt-btn rt-btn--secondary",children:"Cancel"})]})]})]})}):null},Et=({isOpen:l,onClose:n,onSuccess:t})=>{const[h,f]=s.useState(""),[g,c]=s.useState(""),[z,b]=s.useState(""),[M,v]=s.useState(!1),[y,k]=s.useState(!1),[_,S]=s.useState(null),[C,W]=s.useState(!1);s.useEffect(()=>{if(!l){f(""),c(""),b(""),k(!1),S(null);return}b(""),S(null),F()},[l]);const F=async()=>{v(!0),k(!1),S(null);try{const L=await(await fetch("/api/oauth/cursor/auto-import")).json();L.found?(f(L.accessToken||""),c(L.machineId||""),k(!0)):S(L.error||"Could not auto-detect token from local Cursor database")}catch(A){S(A.message||"Failed to auto-detect Cursor tokens")}finally{v(!1)}},V=async()=>{if(h.trim()){W(!0),S(null);try{const A=await fetch("/api/oauth/cursor/import",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({accessToken:h.trim(),machineId:g.trim()||void 0,name:z.trim()||void 0})});if(!A.ok){const L=await A.json().catch(()=>({}));throw new Error(L.error||"Failed to import Cursor connection")}t(),n()}catch(A){S(A.message||"Could not save Cursor account")}finally{W(!1)}}};return l?e.jsx(Te,{isOpen:l,onClose:n,maxWidthClass:"max-w-lg",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Me,{src:"/assets/providers/cursor/icon.png",name:"Cursor",color:"#00D4AA",iconBg:"#FFFFFF",size:"md"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-white",children:"Connect Cursor IDE"}),e.jsx("p",{className:"text-xs text-slate-400",children:"Import session token from local Cursor database"})]})]}),e.jsx("button",{onClick:n,className:"text-slate-400 hover:text-white p-1 rounded-lg hover:bg-white/10",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),M?e.jsxs("div",{className:"py-8 text-center text-slate-400 space-y-2 text-xs",children:[e.jsx("span",{className:"material-symbols-outlined text-3xl text-blue-400 animate-spin",children:"progress_activity"}),e.jsx("p",{className:"font-semibold text-white",children:"Scanning Cursor IDE state.vscdb..."}),e.jsx("p",{className:"text-slate-500",children:"Checking local Application Support / AppData"})]}):e.jsxs("div",{className:"space-y-3.5 text-xs",children:[y&&e.jsxs("div",{className:"p-3 rounded-xl bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"check_circle"}),e.jsx("span",{children:"Session token auto-detected from Cursor IDE successfully!"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Account Label"}),e.jsx("input",{type:"text",value:z,onChange:A=>b(A.target.value),placeholder:"Cursor Desktop Account",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Access Token"}),e.jsx("input",{type:"password",value:h,onChange:A=>f(A.target.value),placeholder:"Paste Cursor access token or auto-detect",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500 font-mono"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Machine ID"}),e.jsx("input",{type:"text",value:g,onChange:A=>c(A.target.value),placeholder:"desktop-cursor-client",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500 font-mono"})]}),_&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:_}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsxs("button",{onClick:F,type:"button",className:"rt-btn rt-btn--secondary",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"refresh"}),"Re-detect"]}),e.jsx("button",{onClick:V,disabled:C||!h.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:C?"Saving...":"Save Connection"})]})]})]})}):null},Dt=({isOpen:l,onClose:n,onSuccess:t})=>{const[h,f]=s.useState("builder-id"),[g,c]=s.useState(null),[z,b]=s.useState(!1),[M,v]=s.useState(!1),y=s.useRef(null),[k,_]=s.useState(""),[S,C]=s.useState("us-east-1"),[W,F]=s.useState(""),[V,A]=s.useState(""),[L,E]=s.useState(""),[T,le]=s.useState(!1),[Z,R]=s.useState(!1),[j,X]=s.useState(null),[I,ee]=s.useState(""),[$,re]=s.useState(""),[xe,G]=s.useState("us-east-1"),[ie,pe]=s.useState(""),[ue,he]=s.useState("us-east-1"),[H,ce]=s.useState(""),[U,B]=s.useState(!1),[o,d]=s.useState(null),O=s.useCallback(()=>{y.current&&clearInterval(y.current),c(null),b(!1),v(!1),_(""),C("us-east-1"),F(""),A(""),E(""),le(!1),R(!1),X(null),ee(""),re(""),G("us-east-1"),pe(""),he("us-east-1"),ce(""),B(!1),d(null)},[]);s.useEffect(()=>{if(!l){O();return}O(),h==="import"&&ye()},[l,h,O]),s.useEffect(()=>()=>{y.current&&clearInterval(y.current)},[]);const be=u=>{navigator.clipboard.writeText(u),v(!0),setTimeout(()=>v(!1),2e3)},ae=async u=>{B(!0),d(null),c(null);try{const x=await fetch("/api/oauth/kiro/device-code",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...u,name:u.name||H.trim()||void 0})});if(!x.ok){const K=await x.json().catch(()=>({}));throw new Error(K.error||"Failed to start AWS device authorization")}const w=await x.json();c(w),b(!0),w.verification_uri_complete&&window.open(w.verification_uri_complete,"_blank","noopener,noreferrer");const me=Math.max((w.interval||5)*1e3,3e3);y.current&&clearInterval(y.current),y.current=setInterval(async()=>{try{const te=await(await fetch("/api/oauth/kiro/device-poll",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({deviceCode:w.device_code,extraData:w.extraData})})).json();te.ok&&te.success?(y.current&&clearInterval(y.current),b(!1),t(),n()):te.error&&!te.pending&&(y.current&&clearInterval(y.current),b(!1),d(te.error))}catch{}},me)}catch(x){d(x.message||"Failed to start device flow")}finally{B(!1)}},ye=async()=>{le(!0),R(!1),d(null);try{const x=await(await fetch("/api/oauth/kiro/auto-import")).json();x.found&&(x.refreshToken||x.accessToken)?(x.refreshToken&&A(x.refreshToken),x.accessToken&&E(x.accessToken),R(!0),x.clientId&&x.clientSecret&&X({clientId:x.clientId,clientSecret:x.clientSecret,region:x.region||"us-east-1",authMethod:x.authMethod||"idc",profileArn:x.profileArn})):d(x.error||"Could not auto-detect token from ~/.aws/sso/cache")}catch(u){d(u.message||"Failed to scan AWS SSO cache")}finally{le(!1)}},N=async()=>{const u=V.trim(),x=L.trim();if(!u&&!x){d("Please provide a refresh token or access token");return}B(!0),d(null);try{const w=await fetch("/api/oauth/kiro/import",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:u||void 0,accessToken:x||void 0,name:H.trim()||void 0,...j||{}})});if(!w.ok){const me=await w.json().catch(()=>({}));throw new Error(me.error||"Failed to import Kiro credentials")}t(),n()}catch(w){d(w.message||"Import failed")}finally{B(!1)}},J=async()=>{const u=k.trim();if(!u){d("Please enter your Access Token (aoa... or JWT)");return}B(!0),d(null);try{const x=await fetch("/api/oauth/kiro/access-token",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({accessToken:u,name:H.trim()||(u.startsWith("aoa")?"Kiro Education Token (aoa)":void 0),region:S.trim()||"us-east-1",profileArn:W.trim()||void 0})});if(!x.ok){const w=await x.json().catch(()=>({}));throw new Error(w.error||"Failed to save Access Token")}t(),n()}catch(x){d(x.message||"Failed to save Access Token")}finally{B(!1)}},q=async()=>{const u=I.trim();if(!u){d("Please paste the External IDP / CLIProxy auth JSON");return}B(!0),d(null);try{const x=await fetch("/api/oauth/kiro/import-cli-proxy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({json:u,name:H.trim()||void 0})});if(!x.ok){const w=await x.json().catch(()=>({}));throw new Error(w.error||"Failed to import External IDP JSON")}t(),n()}catch(x){d(x.message||"Import failed")}finally{B(!1)}},ne=async()=>{if(ie.trim()){B(!0),d(null);try{const u=await fetch("/api/oauth/kiro/api-key",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:ie.trim(),region:ue.trim()||"us-east-1",name:H.trim()||void 0})});if(!u.ok){const x=await u.json().catch(()=>({}));throw new Error(x.error||"Failed to save Kiro API key")}t(),n()}catch(u){d(u.message||"Could not save API key")}finally{B(!1)}}};return l?e.jsx(Te,{isOpen:l,onClose:n,maxWidthClass:"max-w-lg",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Me,{src:"/assets/providers/kiro/icon.png",name:"Kiro",color:"#FF9900",size:"md"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-white",children:"Connect Kiro IDE"}),e.jsx("p",{className:"text-xs text-slate-400",children:"Builder ID, Access Token, Import, External IDP, IDC, API Key"})]})]}),e.jsx("button",{onClick:n,className:"text-slate-400 hover:text-white p-1 rounded-lg hover:bg-white/10",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),e.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 bg-[#0A0D14] p-1 rounded-xl border border-[#1E293B] text-[11px] gap-1",children:[e.jsx("button",{onClick:()=>{f("builder-id"),d(null)},className:`py-1.5 px-1 rounded-lg font-medium transition-colors text-center whitespace-nowrap ${h==="builder-id"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Builder ID"}),e.jsx("button",{onClick:()=>{f("token"),d(null)},className:`py-1.5 px-1 rounded-lg font-medium transition-colors text-center whitespace-nowrap ${h==="token"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Access Token"}),e.jsx("button",{onClick:()=>{f("import"),d(null)},className:`py-1.5 px-1 rounded-lg font-medium transition-colors text-center whitespace-nowrap ${h==="import"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Import Token"}),e.jsx("button",{onClick:()=>{f("cliproxy"),d(null)},className:`py-1.5 px-1 rounded-lg font-medium transition-colors text-center whitespace-nowrap ${h==="cliproxy"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"External IDP"}),e.jsx("button",{onClick:()=>{f("idc"),d(null)},className:`py-1.5 px-1 rounded-lg font-medium transition-colors text-center whitespace-nowrap ${h==="idc"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"AWS IDC"}),e.jsx("button",{onClick:()=>{f("apikey"),d(null)},className:`py-1.5 px-1 rounded-lg font-medium transition-colors text-center whitespace-nowrap ${h==="apikey"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"API Key"})]}),h==="builder-id"&&e.jsx("div",{className:"space-y-3.5 text-xs",children:g?e.jsxs("div",{className:"space-y-3.5",children:[e.jsxs("div",{className:"p-3 bg-[#0A0D14] border border-[#1E293B] rounded-xl text-center space-y-2",children:[e.jsx("p",{className:"text-slate-400 text-xs",children:"Enter this code on the AWS verification page:"}),e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx("span",{className:"text-xl font-mono font-bold text-white tracking-widest",children:g.user_code}),e.jsx("button",{type:"button",onClick:()=>be(g.user_code),className:"px-2.5 py-1 text-xs rounded-lg bg-blue-600/20 text-blue-400 hover:bg-blue-600/30 transition-colors cursor-pointer",children:M?"Copied!":"Copy"})]})]}),e.jsxs("div",{className:"text-center space-y-2 pt-1",children:[e.jsxs("a",{href:g.verification_uri_complete||g.verification_uri,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 text-blue-400 hover:underline text-xs",children:[e.jsx("span",{children:"Open AWS verification page"}),e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"open_in_new"})]}),z&&e.jsxs("div",{className:"flex items-center justify-center gap-2 text-slate-400 text-[11px]",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] animate-spin text-blue-400",children:"progress_activity"}),e.jsx("span",{children:"Waiting for approval in AWS portal..."})]})]}),e.jsx("div",{className:"flex gap-2 pt-2",children:e.jsx("button",{type:"button",onClick:()=>{c(null),b(!1)},className:"w-full rt-btn rt-btn--secondary",children:"Restart Flow"})})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"p-2.5 rounded-xl bg-orange-500/10 border border-orange-500/20 text-orange-300 text-[11px] leading-relaxed",children:e.jsxs("p",{children:["Recommended for personal accounts. Click ",e.jsx("strong",{children:"Start Builder ID Login"})," to authorize via browser device code."]})}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Account Label"}),e.jsx("input",{type:"text",value:H,onChange:u=>ce(u.target.value),placeholder:"Kiro AWS Builder ID",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500"})]}),o&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:o}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>ae({authMethod:"builder-id",startUrl:"https://view.awsapps.com/start",name:H.trim()||void 0}),disabled:U,className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:U?"Registering Client...":"Start Builder ID Login"}),e.jsx("button",{type:"button",onClick:n,className:"rt-btn rt-btn--secondary",children:"Cancel"})]})]})}),h==="token"&&e.jsxs("div",{className:"space-y-3.5 text-xs",children:[e.jsxs("div",{className:"p-2.5 rounded-xl bg-blue-500/10 border border-blue-500/20 text-blue-300 space-y-1 text-[11px]",children:[e.jsxs("div",{className:"flex items-center gap-1.5 font-semibold text-blue-200",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"school"}),e.jsx("span",{children:"Education / Student / Direct Token"})]}),e.jsxs("p",{children:["Paste the ",e.jsx("strong",{children:"AccessToken"})," (starts with ",e.jsx("code",{children:"aoa..."}),") or JWT token from DevTools (Cookies/Storage)."]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Account Label"}),e.jsx("input",{type:"text",value:H,onChange:u=>ce(u.target.value),placeholder:"Kiro Education (aoa)",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Access Token (aoaAAAAAG... or JWT)"}),e.jsx("textarea",{rows:3,value:k,onChange:u=>_(u.target.value),placeholder:"Paste AccessToken (aoa... or eyJr...)",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500 font-mono text-[11px]"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Region"}),e.jsx("input",{type:"text",value:S,onChange:u=>C(u.target.value),placeholder:"us-east-1",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white font-mono"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Profile ARN (Optional)"}),e.jsx("input",{type:"text",value:W,onChange:u=>F(u.target.value),placeholder:"arn:aws:codewhisperer...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white font-mono"})]})]}),o&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:o}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:J,disabled:U||!k.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:U?"Saving...":"Save Connection"}),e.jsx("button",{type:"button",onClick:n,className:"rt-btn rt-btn--secondary",children:"Cancel"})]})]}),h==="import"&&e.jsxs("div",{className:"space-y-3.5 text-xs",children:[T?e.jsxs("div",{className:"py-6 text-center text-slate-400 space-y-2",children:[e.jsx("span",{className:"material-symbols-outlined text-3xl text-blue-400 animate-spin",children:"progress_activity"}),e.jsx("p",{children:"Detecting token in ~/.aws/sso/cache..."})]}):e.jsxs(e.Fragment,{children:[Z&&e.jsxs("div",{className:"p-2.5 rounded-xl bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"check_circle"}),e.jsx("span",{children:"Kiro token auto-detected from ~/.aws/sso/cache!"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Account Label"}),e.jsx("input",{type:"text",value:H,onChange:u=>ce(u.target.value),placeholder:"Kiro Desktop Account",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Refresh Token (starts with aor...)"}),e.jsx("input",{type:"password",value:V,onChange:u=>A(u.target.value),placeholder:"aorAAAAAG...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500 font-mono"})]}),L&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Detected Access Token (aoa...)"}),e.jsx("input",{type:"password",value:L,onChange:u=>E(u.target.value),placeholder:"aoaAAAAAG...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white font-mono"})]})]}),o&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:o}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsxs("button",{type:"button",onClick:ye,className:"rt-btn rt-btn--secondary",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"refresh"}),"Re-detect"]}),e.jsx("button",{type:"button",onClick:N,disabled:U||!V.trim()&&!L.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:U?"Saving...":"Save Connection"})]})]}),h==="cliproxy"&&e.jsxs("div",{className:"space-y-3.5 text-xs",children:[e.jsx("div",{className:"p-2.5 rounded-xl bg-purple-500/10 border border-purple-500/20 text-purple-300 text-[11px]",children:e.jsxs("p",{children:["For Microsoft/Federated accounts generated via CLIProxyAPI or Kiro external login. Paste the JSON containing ",e.jsx("code",{children:"access_token"}),", ",e.jsx("code",{children:"refresh_token"}),", and ",e.jsx("code",{children:"token_endpoint"}),"."]})}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Account Label (Optional)"}),e.jsx("input",{type:"text",value:H,onChange:u=>ce(u.target.value),placeholder:"Kiro Microsoft Education",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"External IDP Auth JSON"}),e.jsx("textarea",{rows:4,value:I,onChange:u=>ee(u.target.value),placeholder:'{ "auth_method": "external_idp", "access_token": "...", "refresh_token": "...", "token_endpoint": "https://login.microsoftonline.com/..." }',className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500 font-mono text-[11px]"})]}),o&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:o}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:q,disabled:U||!I.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:U?"Importing...":"Import JSON"}),e.jsx("button",{type:"button",onClick:n,className:"rt-btn rt-btn--secondary",children:"Cancel"})]})]}),h==="idc"&&e.jsx("div",{className:"space-y-3.5 text-xs",children:g?e.jsxs("div",{className:"space-y-3.5",children:[e.jsxs("div",{className:"p-3 bg-[#0A0D14] border border-[#1E293B] rounded-xl text-center space-y-2",children:[e.jsx("p",{className:"text-slate-400 text-xs",children:"Enter this code on your organization's portal:"}),e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx("span",{className:"text-xl font-mono font-bold text-white tracking-widest",children:g.user_code}),e.jsx("button",{type:"button",onClick:()=>be(g.user_code),className:"px-2.5 py-1 text-xs rounded-lg bg-blue-600/20 text-blue-400 hover:bg-blue-600/30 transition-colors",children:M?"Copied!":"Copy"})]})]}),e.jsxs("div",{className:"text-center space-y-2 pt-1",children:[e.jsxs("a",{href:g.verification_uri_complete||g.verification_uri,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 text-blue-400 hover:underline text-xs",children:[e.jsx("span",{children:"Open IDC login page in browser"}),e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"open_in_new"})]}),z&&e.jsxs("div",{className:"flex items-center justify-center gap-2 text-slate-400 text-[11px]",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] animate-spin text-blue-400",children:"progress_activity"}),e.jsx("span",{children:"Waiting for approval from Identity Center..."})]})]}),e.jsx("div",{className:"flex gap-2 pt-2",children:e.jsx("button",{type:"button",onClick:()=>{c(null),b(!1)},className:"w-full rt-btn rt-btn--secondary",children:"Restart Flow"})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Account Label"}),e.jsx("input",{type:"text",value:H,onChange:u=>ce(u.target.value),placeholder:"Kiro Enterprise (IDC)",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-slate-300 font-medium mb-1",children:["IDC Start URL ",e.jsx("span",{className:"text-rose-400",children:"*"})]}),e.jsx("input",{type:"text",value:$,onChange:u=>re(u.target.value),placeholder:"https://your-org.awsapps.com/start",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white font-mono"}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-1",children:"Your organization's AWS IAM Identity Center URL."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"AWS Region"}),e.jsx("input",{type:"text",value:xe,onChange:u=>G(u.target.value),placeholder:"us-east-1",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white font-mono"})]}),o&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:o}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>{if(!$.trim()){d("Please enter your IDC start URL");return}ae({authMethod:"idc",startUrl:$.trim(),region:xe.trim()||"us-east-1",name:H.trim()||void 0})},disabled:U||!$.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:U?"Starting...":"Start IDC Login"}),e.jsx("button",{type:"button",onClick:n,className:"rt-btn rt-btn--secondary",children:"Cancel"})]})]})}),h==="apikey"&&e.jsxs("div",{className:"space-y-3.5 text-xs",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Account Label"}),e.jsx("input",{type:"text",value:H,onChange:u=>ce(u.target.value),placeholder:"Kiro Headless Key",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Kiro API Key"}),e.jsx("input",{type:"password",value:ie,onChange:u=>pe(u.target.value),placeholder:"Paste Kiro / CodeWhisperer key",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white font-mono"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Region"}),e.jsx("input",{type:"text",value:ue,onChange:u=>he(u.target.value),placeholder:"us-east-1",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white font-mono"})]}),o&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:o}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:ne,disabled:U||!ie.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:U?"Saving...":"Save Connection"}),e.jsx("button",{type:"button",onClick:n,className:"rt-btn rt-btn--secondary",children:"Cancel"})]})]})]})}):null};async function Tt(l){const n=l.providerId?`/api/providers/${encodeURIComponent(l.providerId)}/scan-models`:"/api/providers/scan-models";return await(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)})).json()}const Bt=({isOpen:l,provider:n,existingModels:t,onAddAccount:h,onClose:f,onApplyModels:g})=>{var U,B;const[c,z]=s.useState(!1),[b,M]=s.useState([]),[v,y]=s.useState(new Set),[k,_]=s.useState(null),[S,C]=s.useState([]),[W,F]=s.useState([]),[V,A]=s.useState(!1),[L,E]=s.useState(null),[T,le]=s.useState(""),Z=n.modelsUrl||n.baseUrl||"",[R,j]=s.useState(!1),[X,I]=s.useState(Z),ee=s.useCallback(async o=>{z(!0),E(null),A(!1);try{const d=await Tt({providerId:n.id,baseUrl:(o!==void 0?o:X).trim()||void 0});if(d.success){if(M(d.models),_(d.endpointUrl||null),C(d.scannedAccounts||[]),F(d.failedAccounts||[]),A(!1),y(new Set(d.models.map(O=>O.id))),d.models.length>0){const O=d.models.map(ae=>ae.id);O.some(ae=>!t.includes(ae))&&g(O,"merge")}}else M([]),_(null),C([]),F(d.failedAccounts||[]),d.noAccountsConfigured&&A(!0),E(d.error||"Failed to scan models from upstream provider.")}catch(d){const O=d instanceof Error?d.message:String(d);E(O)}finally{z(!1)}},[n.id,X]);s.useEffect(()=>{if(l){const o=n.modelsUrl||n.baseUrl||"";I(o),le(""),j(!1),C([]),F([]),A(!1),ee(o||void 0)}else M([]),y(new Set),E(null),_(null),C([]),F([]),A(!1)},[l,n.id,n.baseUrl,n.modelsUrl,ee]);const $=s.useMemo(()=>{if(!T.trim())return b;const o=T.toLowerCase();return b.filter(d=>d.id.toLowerCase().includes(o)||d.name&&d.name.toLowerCase().includes(o)||d.description&&d.description.toLowerCase().includes(o))},[b,T]),re=o=>{const d=new Set(v);d.has(o)?d.delete(o):d.add(o),y(d)},xe=()=>{y(new Set($.map(o=>o.id)))},G=()=>{y(new Set)},ie=$.length>0&&$.every(o=>v.has(o.id)),pe=$.some(o=>v.has(o.id)),ue=o=>{o?xe():G()},he=o=>{const d=b.filter(O=>v.has(O.id)).map(O=>O.id);g(d,o),f()},H=s.useMemo(()=>b.filter(o=>!t.includes(o.id)).length,[b,t]),ce=s.useMemo(()=>b.filter(o=>t.includes(o.id)).length,[b,t]);return e.jsx(Te,{isOpen:l,onClose:f,maxWidthClass:"max-w-2xl",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Me,{src:n.image,name:n.name,color:n.color,iconBg:n.iconBg,size:"md",fallback:e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[20px]",children:"radar"})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:["Scan Models from Provider API",e.jsx("span",{className:"text-[10px] font-mono px-2 py-0.5 rounded bg-blue-500/10 text-blue-400 border border-blue-500/20",children:n.name})]}),e.jsx("p",{className:"text-xs text-slate-400 mt-0.5",children:"Automatically probe and import live available models using your configured accounts."})]})]}),e.jsxs("button",{onClick:()=>ee(),disabled:c,className:"rt-btn rt-btn--secondary text-xs flex items-center gap-1.5",title:"Rescan",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${c?"animate-spin":""}`,children:"sync"}),c?"Scanning...":"Rescan"]})]}),(S.length>0||W.length>0||k)&&e.jsxs("div",{className:"flex flex-col gap-1.5 p-2.5 rounded-xl bg-[#0A0D14] border border-[#1E293B] text-[11px]",children:[S.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 text-slate-300",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[15px]",children:"badge"}),e.jsx("span",{className:"text-slate-400 font-medium",children:S.length===1?"Scanned account:":`Aggregated across ${S.length} accounts:`}),S.map(o=>e.jsx("span",{className:"px-2 py-0.5 rounded font-mono text-[10px] bg-blue-500/10 text-blue-400 border border-blue-500/20",children:o.name},o.id))]}),W.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 text-amber-300",children:[e.jsx("span",{className:"material-symbols-outlined text-amber-400 text-[15px]",children:"warning"}),e.jsx("span",{className:"text-amber-400/90 font-medium",children:W.length===1?(B=(U=W[0])==null?void 0:U.error)!=null&&B.toLowerCase().includes("auth")?"1 account failed to authenticate:":"1 account failed to scan:":W.every(o=>{var d;return(d=o.error)==null?void 0:d.toLowerCase().includes("auth")})?`${W.length} accounts failed to authenticate:`:`${W.length} accounts failed to scan:`}),W.map(o=>e.jsx("span",{title:o.error,className:"px-2 py-0.5 rounded font-mono text-[10px] bg-amber-500/10 text-amber-400 border border-amber-500/20",children:o.name},o.id))]}),k&&e.jsxs("div",{className:"flex items-center gap-1.5 font-mono text-slate-400 truncate",children:[e.jsx("span",{className:"material-symbols-outlined text-emerald-400 text-[14px]",children:"check_circle"}),e.jsx("span",{className:"text-slate-500",children:"Discovered endpoint:"}),e.jsx("span",{className:"text-emerald-400 truncate",children:k})]})]}),V&&e.jsxs("div",{className:"p-4 rounded-xl bg-amber-500/10 border border-amber-500/30 text-xs text-amber-300 space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-amber-400 shrink-0 mt-0.5",children:"key_off"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-semibold text-white",children:"No Accounts Configured"}),e.jsxs("p",{className:"text-[11px] text-amber-200/90 mt-1 leading-relaxed",children:["No active account or API key is configured for ",e.jsx("strong",{children:n.name}),". Model scanning automatically queries provider endpoints using your stored accounts. Please configure an account or API key in the provider settings first."]})]})]}),h&&e.jsx("div",{className:"flex justify-end pt-1",children:e.jsxs("button",{type:"button",onClick:()=>{f(),h()},className:"rt-btn rt-btn--primary text-xs flex items-center gap-1.5 bg-amber-600 hover:bg-amber-500 text-white border-none cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"add"}),"Add Account / API Key"]})})]}),L&&!V&&e.jsx("div",{className:"p-3.5 rounded-xl bg-red-500/10 border border-red-500/30 text-xs text-red-300 space-y-2",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] text-red-400 shrink-0 mt-0.5",children:"error"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-semibold",children:L}),e.jsx("p",{className:"text-[11px] text-red-400/80 mt-1",children:"Ensure the configured provider credentials are valid, or provide a custom endpoint URL below."})]})]})}),e.jsxs("div",{className:"rounded-xl border border-[#1E293B] bg-[#0A0D14]/60 overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>j(!R),className:"w-full flex items-center justify-between px-3.5 py-2 text-xs text-slate-400 hover:text-white transition-colors cursor-pointer",children:[e.jsxs("span",{className:"flex items-center gap-1.5 font-medium",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"tune"}),"Base URL & Endpoint Override"]}),e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:R?"expand_less":"expand_more"})]}),R&&e.jsxs("div",{className:"p-3.5 border-t border-[#1E293B] space-y-3 bg-[#080B12]",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[11px] font-semibold text-slate-400 mb-1",children:"Base URL or Models Endpoint"}),e.jsx("input",{type:"text",placeholder:"e.g. https://token-plan-sgp.xiaomimimo.com/v1/models or https://api.xkiro.com/v1",value:X,onChange:o=>I(o.target.value),className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-lg px-3 py-1.5 text-xs text-white font-mono focus:outline-none focus:border-blue-500"})]}),e.jsx("div",{className:"flex justify-end pt-1",children:e.jsx("button",{type:"button",onClick:()=>ee(),disabled:c,className:"rt-btn rt-btn--primary text-xs",children:"Apply & Scan"})})]})]}),c&&e.jsxs("div",{className:"py-12 flex flex-col items-center justify-center gap-3 text-center",children:[e.jsx("div",{className:"relative size-12 flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-3xl text-blue-400 animate-spin",children:"sync"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-white",children:"Probing provider endpoints..."}),e.jsx("p",{className:"text-[11px] text-slate-500 font-mono mt-0.5",children:"Querying /v1/models with configured credentials"})]})]}),!c&&b.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2.5",children:[e.jsx("div",{className:"flex items-center gap-2 flex-1 min-w-[200px]",children:e.jsxs("div",{className:"relative w-full",children:[e.jsx("span",{className:"material-symbols-outlined absolute left-2.5 top-1/2 -translate-y-1/2 text-[16px] text-slate-500",children:"search"}),e.jsx("input",{type:"text",placeholder:"Search discovered models...",value:T,onChange:o=>le(o.target.value),className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-lg pl-8 pr-8 py-1.5 text-xs text-white focus:outline-none focus:border-blue-500"}),T&&e.jsx("button",{type:"button",onClick:()=>le(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-slate-500 hover:text-white transition-colors cursor-pointer flex items-center justify-center",title:"Clear search",children:e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"close"})})]})}),e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[e.jsx(tt,{size:"sm",checked:ie,indeterminate:pe&&!ie,onChange:ue,label:e.jsx("span",{className:"text-xs font-medium text-slate-300",children:"Select All"})}),e.jsx("button",{type:"button",onClick:G,className:"px-2.5 py-1 rounded-md bg-white/5 hover:bg-white/10 text-slate-400 hover:text-slate-200 text-[11px] transition-colors cursor-pointer",children:"Deselect All"})]})]}),e.jsxs("div",{className:"flex items-center justify-between text-[11px] text-slate-400 px-1 font-mono",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{children:["Discovered: ",e.jsx("strong",{className:"text-white",children:b.length})]}),e.jsx("span",{children:"•"}),e.jsxs("span",{className:"text-emerald-400",children:[H," new"]}),e.jsx("span",{children:"•"}),e.jsxs("span",{className:"text-slate-500",children:[ce," existing"]})]}),e.jsx("div",{children:e.jsxs("span",{children:["Selected: ",e.jsx("strong",{className:"text-blue-400",children:v.size})]})})]}),e.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1.5 pr-1 border border-[#1E293B] rounded-xl p-2 bg-[#0A0D14]/80",children:$.length===0?e.jsxs("div",{className:"py-6 text-center text-xs text-slate-500",children:['No models match "',T,'"']}):$.map(o=>{var be,ae;const d=v.has(o.id),O=t.includes(o.id);return e.jsxs("div",{onClick:()=>re(o.id),className:`flex items-center justify-between p-2 rounded-lg border text-xs cursor-pointer transition-colors ${d?"bg-blue-500/10 border-blue-500/40 text-white":"bg-[#0D1322] border-[#1E293B] hover:border-slate-700 text-slate-300"}`,children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx(tt,{size:"sm",checked:d,onChange:()=>re(o.id),onClick:ye=>ye.stopPropagation()}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"font-mono font-medium truncate block",children:o.id}),o.name&&o.name!==o.id&&e.jsx("span",{className:"text-[10px] text-slate-500 truncate block",children:o.name})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[((be=o.capabilities)==null?void 0:be.reasoning)&&e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-mono bg-purple-500/20 text-purple-300 border border-purple-500/30",children:"reasoning"}),((ae=o.capabilities)==null?void 0:ae.vision)&&e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-mono bg-amber-500/20 text-amber-300 border border-amber-500/30",children:"vision"}),O?e.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-mono bg-slate-800 text-slate-400",children:"Configured"}):e.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-mono bg-emerald-500/20 text-emerald-300 border border-emerald-500/30 font-semibold",children:"NEW"})]})]},o.id)})})]}),!c&&b.length===0&&!L&&e.jsx("div",{className:"py-8 text-center text-xs text-slate-400",children:'Click "Rescan" or check provider account settings above to scan for models.'}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{type:"button",onClick:f,className:"px-4 py-2 text-xs text-slate-400 hover:text-white transition-colors cursor-pointer",children:"Cancel"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",disabled:v.size===0,onClick:()=>he("replace"),className:"rt-btn rt-btn--secondary text-xs disabled:opacity-40",title:"Replace current provider models list with selected models",children:["Replace Existing (",v.size,")"]}),e.jsxs("button",{type:"button",disabled:v.size===0,onClick:()=>he("merge"),className:"rt-btn rt-btn--primary text-xs disabled:opacity-40",title:"Append newly selected models without removing existing ones",children:["Merge with Existing (",v.size,")"]})]})]})]})})},zt=({provider:l,onBack:n})=>{var Ge,qe,Ye,Qe,Xe,Ze;const t=st(l.id),[h,f]=s.useState([]),[g,c]=s.useState([]),[z,b]=s.useState((t==null?void 0:t.models)||[]),[M,v]=s.useState(null),[y,k]=s.useState("1"),[_,S]=s.useState((t==null?void 0:t.thinkingMode)||"auto"),[C,W]=s.useState((t==null?void 0:t.thinkingOptions)||["auto","none","low","medium","high"]),[F,V]=s.useState(l.format||(t==null?void 0:t.format)||"openai"),[A,L]=s.useState([]),[E,T]=s.useState((t==null?void 0:t.baseUrl)||l.baseUrl||""),[le,Z]=s.useState(""),[R,j]=s.useState([]),[X,I]=s.useState(!1),[ee,$]=s.useState(!1),[re,xe]=s.useState(!1),[G,ie]=s.useState(!1),[pe,ue]=s.useState(!1),[he,H]=s.useState(!1),[ce,U]=s.useState(!1),[B,o]=s.useState(""),[d,O]=s.useState(null),[be,ae]=s.useState(null),[ye,N]=s.useState({}),[J,q]=s.useState(!1),[ne,u]=s.useState(!1),[x,w]=s.useState(null),[me,K]=s.useState(""),[te,Y]=s.useState(""),[Ae,oe]=s.useState(null),[je,we]=s.useState(null),[Ee,Se]=s.useState(!1),[de,Be]=s.useState(!1),[ve,De]=s.useState(null),[se,Pe]=s.useState(null),[_e,Re]=s.useState(""),Ue=l.category==="custom"||!t,Oe=(t==null?void 0:t.authType)==="cookie"||(t==null?void 0:t.category)==="webCookie"||l.category==="webCookie",Ne=!Oe&&(et(t)||et(l)),p=!Oe&&(Array.isArray(t==null?void 0:t.authModes)?t.authModes.includes("apikey"):!!((t==null?void 0:t.category)==="apikey"||(Ge=t==null?void 0:t.notice)!=null&&Ge.apiKeyUrl||l.category==="apikey"&&!["antigravity","cursor","github","kiro"].includes(l.id))),ge=()=>{if(l.id==="github"){xe(!0);return}if(l.id==="cursor"){ie(!0);return}if(l.id==="kiro"){ue(!0);return}$(!0)},Q=s.useCallback(()=>{const a=(t==null?void 0:t.defaultHeaders)||{},r=Object.entries(a).map(([i,D])=>({key:i,value:String(D)})),m=((t==null?void 0:t.models)||[]).map(i=>i.id);fetch(`/api/providers/${l.id}`).then(i=>i.json()).then(i=>{i.format&&V(i.format),Array.isArray(i.supportedFormats)&&i.supportedFormats.length>0?L(i.supportedFormats.map(P=>typeof P=="string"?{value:P,label:P.toUpperCase()}:P)):Array.isArray(t==null?void 0:t.supportedFormats)&&t.supportedFormats.length>0?L(t.supportedFormats.map(P=>typeof P=="string"?{value:P,label:P.toUpperCase()}:P)):L([]),i.baseUrl&&T(i.baseUrl),i.proxyUrl&&Z(i.proxyUrl),i.thinkingMode&&S(i.thinkingMode),Array.isArray(i.thinkingOptions)&&i.thinkingOptions.length>0&&W(i.thinkingOptions),i.strategy!==void 0&&v(i.strategy||null),i.stickyLimit!=null&&k(String(i.stickyLimit));const D=i.userCustomHeaders!==void 0?i.userCustomHeaders:i.customHeaders||{};D&&Object.keys(D).length>0?j(Object.entries(D).map(([P,fe])=>({key:P,value:String(fe)}))):j([]),Array.isArray(i.catalogModels)&&i.catalogModels.length>0&&b(i.catalogModels),Array.isArray(i.models)&&i.models.length>0?c(i.models):c(m),i.accounts&&i.accounts.length>0?f(i.accounts.map((P,fe)=>{var $e;return{id:P.id,name:P.name,tag:P.tag||(($e=P.providerSpecificData)==null?void 0:$e.tag),supportedModelsCount:P.supportedModelsCount,isActive:P.isActive,order:P.sortOrder??fe,providerSpecificData:P.providerSpecificData}})):f([]),Ce()}).catch(()=>{j(r),c(m),f([])})},[l.id,l.name,t]);s.useEffect(()=>{Q()},[Q]);const ke=async(a,r)=>{try{await fetch(`/api/providers/${l.id}/strategy`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({strategy:a||null,stickyLimit:a==="round-robin"?Number(r)||1:null})})}catch(m){console.warn("Failed to save provider strategy:",m)}},Le=async a=>{const r=h.map(m=>m.id===a?{...m,isActive:!m.isActive}:m);f(r);try{await fetch(`/api/providers/${l.id}/accounts/${a}/toggle`,{method:"PUT"}),Ce()}catch{}},Ke=(a,r)=>{if(r==="up"&&a===0||r==="down"&&a===h.length-1)return;const m=r==="up"?a-1:a+1,i=[...h],D=i[a];i[a]=i[m],i[m]=D;const P=i.map((fe,$e)=>({...fe,order:$e}));f(P),fetch(`/api/providers/${l.id}/accounts/reorder`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({accountIds:P.map(fe=>fe.id)})}).then(fe=>{fe.ok||console.error("Failed to reorder accounts:",fe.status),Ce()}).catch(fe=>{console.error("Failed to reorder accounts:",fe)})},at=a=>{f(h.filter(r=>r.id!==a)),fetch(`/api/providers/${l.id}/accounts/${a}`,{method:"DELETE"}).then(()=>Ce()).catch(()=>{})},lt=a=>{De({id:a.id,providerId:l.id,name:a.name,isActive:a.isActive,providerSpecificData:a.providerSpecificData})},nt=async a=>{if(!ve)return;const r=await fetch(`/api/providers/${l.id}/accounts/${ve.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!r.ok){const m=await r.json().catch(()=>({}));throw new Error(m.error||"Failed to update account.")}Q(),Ce()},ze=async(a,r)=>{r!==void 0&&O(r),ae(a.id);try{const i=await(await fetch(`/api/providers/${l.id}/accounts/${a.id}/test`,{method:"POST"})).json();N(D=>({...D,[a.id]:{success:!!i.success,message:i.message||(i.success?"Connection verified":"Connection failed"),latencyMs:i.latencyMs}}))}catch(m){N(i=>({...i,[a.id]:{success:!1,message:m.message||"Failed to reach gateway"}}))}finally{r!==void 0&&O(null),ae(null)}},ot=async()=>{if(!(ne||h.length===0)){u(!0);try{for(let a=0;a<h.length;a++){const r=h[a];await ze(r,a)}}finally{O(null),u(!1)}}},He=async()=>{q(!0),w(null);try{const r=await(await fetch(`/api/providers/${l.id}/test`,{method:"POST"})).json();w({success:!!r.success,message:r.message||(r.success?"Connection successful!":"Connection failed."),latencyMs:r.latencyMs})}catch(a){w({success:!1,message:`Error testing connection: ${a.message}`})}finally{q(!1)}},rt=()=>{me.trim()&&(j([...R,{key:me.trim(),value:te.trim()}]),K(""),Y(""))},We=a=>{j(R.filter((r,m)=>m!==a))},Ie=(a,r,m)=>{const i=[...R];i[a]={key:r,value:m},j(i)},it=()=>{j([]),oe("Reset custom headers. Using system defaults."),setTimeout(()=>oe(null),3e3)},ct=(a,r)=>{R.findIndex(i=>i.key.trim().toLowerCase()===a.toLowerCase())>=0||j([...R,{key:a,value:r}])},dt=a=>{j(R.filter(r=>r.key.trim().toLowerCase()!==a.toLowerCase()))},xt=a=>{const r=R.filter(m=>m.key.trim().toLowerCase()!==a.toLowerCase());j([...r,{key:a,value:""}])},ut=a=>{j(R.filter(r=>r.key.trim().toLowerCase()!==a.toLowerCase()))},mt=()=>{if(!B.trim())return;const a=B.trim();g.includes(a)||c([...g,a]),o(""),H(!1)},pt=a=>{c(g.filter(r=>r!==a))},ht=async(a,r)=>{let m;if(r==="replace")m=a;else{const D=new Set(g),P=a.filter(fe=>!D.has(fe));m=[...g,...P]}c(m);const i={};R.forEach(D=>{D.key.trim()&&(i[D.key.trim()]=D.value.trim())});try{await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:l.id,name:l.name,baseUrl:E||l.baseUrl||(t==null?void 0:t.baseUrl)||"https://api.openai.com",format:F||l.format||(t==null?void 0:t.format)||"openai",customHeaders:i,proxyUrl:le.trim()||void 0,thinkingMode:_,strategy:M,stickyLimit:M==="round-robin"?Number(y)||1:null,models:m})}),oe(`Saved ${m.length} models for ${l.name}.`),Ce(),Q(),setTimeout(()=>oe(null),3e3)}catch{}},bt=a=>{navigator.clipboard.writeText(a),we(a),setTimeout(()=>{we(r=>r===a?null:r)},2e3)},Je=async()=>{const a={};R.forEach(r=>{r.key.trim()&&(a[r.key.trim()]=r.value.trim())});try{await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:l.id,name:l.name,baseUrl:E||l.baseUrl||(t==null?void 0:t.baseUrl)||"https://api.openai.com",format:F||l.format||(t==null?void 0:t.format)||"openai",customHeaders:a,proxyUrl:le.trim()||void 0,thinkingMode:_,strategy:M,stickyLimit:M==="round-robin"?Number(y)||1:null,models:g})}),oe("Configuration saved successfully."),Ce(),setTimeout(()=>oe(null),3e3)}catch{}},ft=async()=>{Be(!0);try{(await fetch(`/api/providers/${l.id}`,{method:"DELETE"})).ok&&(Ce(),n())}catch{}finally{Be(!1),Se(!1)}},Ve=((qe=t==null?void 0:t.notice)==null?void 0:qe.apiKeyUrl)||((Ye=t==null?void 0:t.notice)==null?void 0:Ye.signupUrl)||(t==null?void 0:t.website),gt=(Qe=t==null?void 0:t.notice)!=null&&Qe.apiKeyUrl?"Get API Key":"Sign up / Learn more";return e.jsxs("div",{className:"space-y-6 w-full px-2 sm:px-4 pb-16 animate-rt-fade-in",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{type:"button",onClick:a=>{a.preventDefault(),a.stopPropagation(),n()},className:"flex items-center gap-1.5 text-xs font-semibold text-slate-400 hover:text-blue-400 transition-colors cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"arrow_back"}),"Back to Providers"]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3.5",children:[e.jsx(Me,{src:l.image,name:l.name,color:(t==null?void 0:t.color)||l.color,iconBg:(t==null?void 0:t.iconBg)||l.iconBg,size:"lg"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2.5 flex-wrap",children:[e.jsx("h2",{className:"text-xl font-bold text-white tracking-tight",children:l.name}),e.jsx("span",{className:"text-[11px] font-mono px-2 py-0.5 rounded bg-[#1E293B] text-slate-300",children:(t==null?void 0:t.format)||l.format||"openai"}),Ve&&e.jsxs("a",{href:Ve,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-blue-400 hover:text-blue-300 hover:underline inline-flex items-center gap-1 font-medium transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"open_in_new"}),gt]})]}),e.jsxs("span",{className:"text-xs text-slate-400 font-mono",children:[h.length," connection",h.length===1?"":"s"," • ",g.length," available models"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:He,disabled:J,className:"rt-btn rt-btn--secondary hover:border-blue-500/50",title:"Test connection with upstream provider",children:[e.jsx("span",{className:`material-symbols-outlined text-[16px] ${J?"animate-spin text-blue-400":""}`,children:J?"sync":"speed"}),J?"Testing...":"Test Connection"]}),e.jsxs("button",{onClick:Je,className:"rt-btn rt-btn--primary",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"save"}),"Save Provider Settings"]})]})]})]}),x&&e.jsxs("div",{className:`flex items-center justify-between gap-3 px-4 py-2.5 rounded-xl border text-xs font-mono animate-rt-scale-in ${x.success?"bg-emerald-500/10 text-emerald-300 border-emerald-500/30":"bg-red-500/10 text-red-300 border-red-500/30"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] shrink-0",children:x.success?"check_circle":"error"}),e.jsx("span",{className:"truncate",children:x.message})]}),x.latencyMs&&e.jsxs("span",{className:"shrink-0 font-bold opacity-80",children:[x.latencyMs,"ms"]})]}),(t==null?void 0:t.deprecated)&&e.jsxs("div",{className:"flex items-start gap-2.5 px-4 py-3 rounded-xl bg-amber-500/10 border border-amber-500/30 text-xs text-amber-300 leading-relaxed animate-rt-scale-in",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] text-amber-400 mt-0.5 shrink-0",children:"warning"}),e.jsx("p",{children:t.deprecationNotice||"This provider uses an undocumented or risk-prone connection session. Use at your own risk."})]}),((Xe=t==null?void 0:t.notice)==null?void 0:Xe.text)&&!(t!=null&&t.deprecated)&&e.jsxs("div",{className:"flex flex-col gap-2 rounded-xl border border-blue-500/30 bg-blue-500/10 px-4 py-3 sm:flex-row sm:items-center text-xs animate-rt-scale-in",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] text-blue-400 shrink-0",children:"info"}),e.jsx("p",{className:"min-w-0 flex-1 text-blue-300 leading-relaxed",children:t.notice.text}),t.notice.apiKeyUrl&&e.jsx("a",{href:t.notice.apiKeyUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex justify-center rounded bg-blue-500 px-2.5 py-1 text-xs font-medium text-white transition-colors hover:bg-blue-600 shrink-0",children:"Get API Key →"})]}),(l.id==="opencode"||(t==null?void 0:t.noAuth)||(t==null?void 0:t.requiresApiKey)===!1||(t==null?void 0:t.authType)==="none"||(t==null?void 0:t.isLocal))&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-3 px-4 py-3.5 rounded-xl bg-emerald-500/10 border border-emerald-500/30 text-xs text-emerald-300 animate-rt-scale-in",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-emerald-400 shrink-0",children:"check_circle"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-white",children:t!=null&&t.isLocal?"Local Provider (No Paid Key Required)":"No Authentication Required (100% Free)"}),e.jsx("p",{className:"text-slate-400 mt-0.5",children:t!=null&&t.isLocal?`${l.name} runs directly on your local device without external API tokens.`:`${l.name} is ready to use immediately without an account or API key.`})]})]}),e.jsxs("button",{onClick:He,disabled:J,className:"px-3 py-1.5 rounded-lg bg-emerald-500 hover:bg-emerald-600 text-white font-medium shrink-0 flex items-center gap-1.5 transition-colors cursor-pointer disabled:opacity-50",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${J?"animate-spin":""}`,children:J?"sync":"speed"}),J?"Testing...":"Test Connection"]})]}),e.jsxs("div",{className:"rt-card p-5 space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h3",{className:"text-sm font-bold text-white",children:"Connections & Priority Queue"}),e.jsxs("span",{className:"text-xs text-slate-500",children:["(",h.filter(a=>a.isActive).length," active)"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-xs",children:[e.jsxs("button",{onClick:ot,disabled:ne||d!==null||h.length===0,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-[#1E293B] bg-[#0A0D14] text-slate-300 hover:text-white transition-colors cursor-pointer disabled:opacity-40",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${ne||d!==null?"animate-spin text-blue-400":""}`,children:"sync"}),ne?"Testing...":"Test Connection One-by-One"]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 pl-2 border-l border-[#1E293B]",children:[e.jsx("span",{className:"text-xs text-slate-400 font-medium",children:"Strategy:"}),e.jsx(Fe,{value:M||"",onChange:a=>{const r=a||null;v(r);const m=r==="round-robin"?y||"1":y;r==="round-robin"&&!y&&k("1"),ke(r,m)},options:[{value:"",label:"Default (Global)"},{value:"fill-first",label:"Fill First"},{value:"sequential",label:"Sequential (Drain)"},{value:"round-robin",label:"Round Robin"},{value:"earliest-reset",label:"Earliest Reset"}],className:"w-40"}),M==="round-robin"&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs text-slate-400",children:"Sticky:"}),e.jsx("input",{type:"number",min:1,value:y,onChange:a=>{const r=a.target.value;k(r),ke("round-robin",r)},placeholder:"1",className:"w-14 px-2 py-1 text-xs border border-[#1E293B] rounded-lg bg-[#0A0D14] text-slate-200 focus:outline-none focus:border-blue-500 font-mono"})]})]})]})]}),h.length===0?e.jsxs("div",{className:"w-full py-10 px-4 text-center text-slate-400 flex flex-col items-center justify-center gap-2.5 bg-[#0A0D14] rounded-xl border border-dashed border-[#1E293B]",children:[e.jsx("span",{className:"material-symbols-outlined text-3xl text-slate-600",children:Ne?"vpn_key_off":"key_off"}),e.jsxs("p",{className:"text-sm font-semibold text-slate-300",children:["No accounts connected for ",l.name]}),e.jsx("p",{className:"text-xs text-slate-500 max-w-sm",children:Ne?`Connect your ${l.name} account via OAuth or add credentials to start routing.`:`Add an API key or credentials to start routing requests through ${l.name}.`})]}):e.jsx("div",{className:"space-y-2",children:h.map((a,r)=>{const m=ye[a.id],i=d===r||be===a.id;return e.jsxs("div",{className:"flex flex-col gap-2 p-3 rounded-xl bg-[#0A0D14] border border-[#1E293B] hover:border-blue-500/30 transition-all text-xs",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsxs("div",{className:"flex flex-col text-slate-500",children:[e.jsx("button",{onClick:()=>Ke(r,"up"),disabled:r===0,className:"hover:text-white disabled:opacity-30 leading-none cursor-pointer",children:"▲"}),e.jsx("button",{onClick:()=>Ke(r,"down"),disabled:r===h.length-1,className:"hover:text-white disabled:opacity-30 leading-none cursor-pointer",children:"▼"})]}),e.jsx("span",{className:"material-symbols-outlined text-[16px] text-slate-500",children:Ne?"lock":"key"}),e.jsx("span",{className:"font-mono text-slate-200 truncate font-medium",children:a.name}),a.tag?e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 text-[10px] font-mono rounded-md bg-blue-500/15 text-blue-300 border border-blue-500/30 font-semibold tracking-wide shadow-sm",children:[e.jsx("span",{className:"material-symbols-outlined text-[12px] text-blue-400",children:"label"}),a.tag]}):e.jsx("span",{className:"text-[10px] font-mono text-slate-600 border border-dashed border-[#1E293B] px-1.5 py-0.5 rounded",children:"no-tag"}),a.supportedModelsCount!=null?e.jsxs("button",{type:"button",onClick:()=>{Pe({accountId:a.id,accountName:a.name,models:[],scanned:!0,loading:!0}),Re(""),fetch(`/api/providers/${l.id}/accounts/${a.id}/models`).then(D=>D.json()).then(D=>{Pe(P=>P&&P.accountId===a.id?{...P,models:D.models||[],scanned:!!D.scanned,loading:!1}:P)}).catch(()=>{Pe(D=>D&&D.accountId===a.id?{...D,loading:!1}:D)})},className:`inline-flex items-center gap-1 px-2 py-0.5 text-[10px] font-mono rounded-md border font-medium cursor-pointer transition-all hover:scale-[1.02] active:scale-[0.98] ${a.supportedModelsCount>=(g.length||1)?"bg-emerald-500/10 text-emerald-400 border-emerald-500/20 hover:bg-emerald-500/20":"bg-amber-500/10 text-amber-300 border-amber-500/20 hover:bg-amber-500/20"}`,title:"Click to view verified models for this account",children:[e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:a.supportedModelsCount>=(g.length||1)?"check_circle":"tune"}),a.supportedModelsCount," / ",g.length," models"]}):e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 text-[10px] font-mono rounded-md bg-slate-800/80 text-slate-400 border border-slate-700/50",title:"Account has not been scanned yet. Will fail-open and auto-learn when called.",children:[e.jsx("span",{className:"material-symbols-outlined text-[12px] text-slate-500",children:"help_outline"}),"unscanned"]}),e.jsxs("span",{className:`rt-badge ${a.isActive?"rt-badge--success":"rt-badge--muted"}`,children:[a.isActive?"● active":"disabled"," • #",r+1]}),i&&e.jsx("span",{className:"text-[10px] text-blue-400 animate-pulse font-mono",children:"Testing upstream..."}),m&&!i&&e.jsx("span",{className:`rt-badge text-[10px] ${m.success?"bg-emerald-500/10 text-emerald-400 border border-emerald-500/20":"bg-red-500/10 text-red-400 border border-red-500/20"}`,title:m.message,children:m.success?`● ${m.latencyMs?`${m.latencyMs}ms`:"Active"}`:"● Failed"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{title:"Test this connection",onClick:()=>ze(a,r),disabled:d!==null||i,className:"p-1 text-slate-500 hover:text-blue-400 transition-colors cursor-pointer disabled:opacity-40",children:e.jsx("span",{className:`material-symbols-outlined text-[16px] ${i?"animate-spin text-blue-400":""}`,children:i?"sync":"speed"})}),e.jsx("button",{title:"Edit account",onClick:()=>lt(a),className:"p-1 text-slate-500 hover:text-blue-400 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"edit"})}),e.jsx("button",{title:"Delete account",onClick:()=>at(a.id),className:"p-1 text-slate-500 hover:text-red-400 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"delete"})}),e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer ml-1",children:[e.jsx("input",{type:"checkbox",checked:a.isActive,onChange:()=>Le(a.id),className:"sr-only peer"}),e.jsx("div",{className:"w-8 h-4.5 bg-[#1E293B] peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-3.5 after:w-3.5 after:transition-all peer-checked:bg-blue-600"})]})]})]}),m&&e.jsx("div",{className:`w-full py-1 px-2.5 text-[10px] font-mono rounded-lg border truncate ${m.success?"bg-emerald-500/10 text-emerald-400 border-emerald-500/20":"bg-red-500/10 text-red-400 border-red-500/20"}`,title:m.message,children:m.success?`✓ ${m.message}`:`✗ ${m.message}`})]},a.id)})}),Ne&&p?e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsxs("button",{onClick:ge,className:"rt-btn rt-btn--primary",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"lock"}),"Connect with OAuth"]}),e.jsxs("button",{onClick:()=>I(!0),className:"rt-btn rt-btn--secondary",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"key"}),"Add API Key"]})]}):e.jsxs("button",{onClick:()=>{Ne||["github","cursor","kiro","antigravity"].includes(l.id)?ge():I(!0)},className:"rt-btn rt-btn--primary",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:Ne||l.id==="github"||l.id==="cursor"||l.id==="kiro"?"lock":Oe?"cookie":"add"}),Ne||l.id==="github"||l.id==="cursor"||l.id==="kiro"?`Connect ${l.name}`:Oe?"Add Session Cookie":"Add Account"]})]}),e.jsxs("div",{className:"rt-card p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[20px]",children:"tune"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-white",children:"Upstream Request Headers"}),e.jsxs("p",{className:"text-xs text-slate-400 mt-0.5",children:["Headers forwarded to ",l.name,". System defaults are managed automatically and combined with your custom overrides."]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:it,className:"rt-btn rt-btn--secondary text-xs",title:"Reset custom headers and use system defaults",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"restart_alt"}),"Reset"]}),e.jsxs("button",{onClick:Je,className:"rt-btn rt-btn--primary text-xs",title:"Save headers",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"save"}),"Save"]})]})]}),Ae&&e.jsxs("div",{className:"text-[11px] text-emerald-400 font-mono flex items-center gap-1.5 animate-rt-scale-in",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"check_circle"}),Ae]}),(t==null?void 0:t.defaultHeaders)&&Object.keys(t.defaultHeaders).length>0&&e.jsxs("div",{className:"p-3.5 rounded-xl bg-[#0A0D14] border border-[#1E293B] space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-semibold text-slate-300",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-emerald-400",children:"verified"}),e.jsx("span",{children:"System Default Headers"}),e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-emerald-500/10 text-emerald-400 border border-emerald-500/20",children:"Auto-updated on release"})]}),e.jsx("span",{className:"text-[11px] text-slate-500 font-mono",children:"Managed by Mapigate"})]}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"These headers automatically update with new Mapigate releases. If upstream changes before an official update, click Customize to edit and override it immediately."}),e.jsx("div",{className:"space-y-1.5 pt-1",children:Object.entries(t.defaultHeaders).map(([a,r])=>{const m=R.find(P=>P.key.trim().toLowerCase()===a.toLowerCase()),i=m!==void 0&&m.value==="",D=m!==void 0&&m.value!=="";return e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 rounded-lg bg-[#0F141C] border border-[#1E293B]/60 text-xs font-mono",children:[e.jsxs("div",{className:"flex items-center gap-2 truncate pr-2",children:[e.jsx("span",{className:i?"text-slate-600 line-through":"text-blue-400 font-semibold",children:a}),e.jsx("span",{className:"text-slate-600",children:":"}),e.jsx("span",{className:i||D?"text-slate-500 line-through truncate":"text-slate-300 truncate",children:r}),D&&e.jsxs("span",{className:"text-amber-300 font-semibold truncate",children:["→ ",m==null?void 0:m.value]})]}),e.jsx("div",{className:"flex items-center gap-2 shrink-0",children:i?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-rose-500/10 text-rose-400 border border-rose-500/20 font-sans font-semibold",children:"Disabled / Omitted"}),e.jsxs("button",{type:"button",onClick:()=>ut(a),className:"flex items-center gap-1 text-[11px] text-emerald-400 hover:text-emerald-300 px-2 py-1 rounded bg-emerald-500/10 hover:bg-emerald-500/20 border border-emerald-500/20 transition-colors cursor-pointer",title:"Re-enable this default header",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"check_circle"}),"Enable"]})]}):D?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20 font-sans font-semibold",children:"Overridden"}),e.jsxs("button",{type:"button",onClick:()=>dt(a),className:"flex items-center gap-1 text-[11px] text-slate-400 hover:text-white px-2 py-1 rounded bg-[#1E293B] hover:bg-[#2A374A] transition-colors cursor-pointer",title:"Revert to system default value",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"undo"}),"Revert"]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>ct(a,r),className:"flex items-center gap-1 text-[11px] text-blue-400 hover:text-blue-300 px-2 py-1 rounded bg-blue-500/10 hover:bg-blue-500/20 border border-blue-500/20 transition-colors cursor-pointer",title:"Override or adjust this default header value",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"edit"}),"Customize"]}),e.jsxs("button",{type:"button",onClick:()=>xt(a),className:"flex items-center gap-1 text-[11px] text-slate-500 hover:text-rose-400 px-2 py-1 rounded hover:bg-rose-500/10 transition-colors cursor-pointer",title:"Disable/remove this default header from outgoing requests",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"block"}),"Disable"]})]})})]},a)})})]}),e.jsxs("div",{className:"pt-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-semibold text-slate-300 mb-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-blue-400",children:"tune"}),e.jsx("span",{children:"Custom Header Overrides & Additions"})]}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"Add custom headers or override/disable default headers. These values take precedence over system defaults."})]}),e.jsxs("div",{className:"space-y-2",children:[R.length===0?e.jsx("div",{className:"text-xs text-slate-500 italic p-3 rounded-xl bg-[#0A0D14] border border-[#1E293B]",children:'No custom header overrides configured. Outgoing requests will use the system default headers above. Click "Customize" on any default header or add a new header below.'}):e.jsx("div",{className:"space-y-2",children:R.map((a,r)=>{const m=!!(t!=null&&t.defaultHeaders&&Object.keys(t.defaultHeaders).some(D=>D.toLowerCase()===a.key.trim().toLowerCase())),i=a.value==="";return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"w-1/3 relative",children:[e.jsx("input",{type:"text",value:a.key,onChange:D=>Ie(r,D.target.value,a.value),className:`w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs font-mono focus:outline-none focus:border-blue-500 ${i?"text-slate-500 line-through":"text-blue-400"}`,placeholder:"Header Key"}),m&&e.jsx("span",{className:`absolute right-2 top-2 text-[10px] font-sans pointer-events-none font-semibold ${i?"text-rose-400":"text-amber-400"}`,children:i?"Disabled":"Override"})]}),i?e.jsxs("div",{className:"flex-1 bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-rose-400/80 italic font-mono flex items-center justify-between",children:[e.jsx("span",{children:"(Disabled — this header will be omitted from outgoing requests)"}),e.jsx("button",{type:"button",onClick:()=>We(r),className:"text-[11px] text-emerald-400 hover:text-emerald-300 font-sans not-italic hover:underline cursor-pointer",children:"Re-enable"})]}):e.jsx("input",{type:"text",value:a.value,onChange:D=>Ie(r,a.key,D.target.value),className:"flex-1 bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-slate-200 font-mono focus:outline-none focus:border-blue-500",placeholder:"Header Value"}),e.jsx("button",{onClick:()=>We(r),className:"p-2 text-slate-500 hover:text-red-400 transition-colors cursor-pointer rounded-lg hover:bg-red-500/10",title:i?"Re-enable header":m?"Remove override (reverts to default)":"Delete header",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:i||m?"undo":"delete"})})]},r)})}),e.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[e.jsx("input",{type:"text",placeholder:"Key (e.g. User-Agent or Anthropic-Beta)",value:me,onChange:a=>K(a.target.value),className:"w-1/3 bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white font-mono focus:outline-none focus:border-blue-500"}),e.jsx("input",{type:"text",placeholder:"Value",value:te,onChange:a=>Y(a.target.value),className:"flex-1 bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white font-mono focus:outline-none focus:border-blue-500"}),e.jsxs("button",{onClick:rt,className:"rt-btn rt-btn--secondary text-xs shrink-0",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"add"}),"+ add header"]})]})]}),A.length>0&&e.jsxs("div",{className:"pt-3 border-t border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{className:"block text-slate-400 font-semibold text-xs",children:"Target API Protocol Format"}),e.jsx("span",{className:"text-[11px] text-slate-500",children:"Select upstream API format"})]}),e.jsx(Fe,{value:F,onChange:V,options:A,className:"w-full",triggerClassName:"font-mono text-xs"})]}),e.jsxs("div",{className:"pt-3 border-t border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{className:"block text-slate-400 font-semibold text-xs",children:"Provider Base URL"}),(t==null?void 0:t.baseUrl)&&t.baseUrl!==E&&e.jsxs("button",{type:"button",onClick:()=>T(t.baseUrl||""),className:"text-[11px] text-blue-400 hover:text-blue-300 transition-colors cursor-pointer",title:"Reset to default Base URL",children:["Reset to default (",t.baseUrl,")"]})]}),e.jsx("input",{type:"text",placeholder:(t==null?void 0:t.baseUrl)||l.baseUrl||"https://api.openai.com",value:E,onChange:a=>T(a.target.value),className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white font-mono focus:outline-none focus:border-blue-500"})]}),e.jsxs("div",{className:"pt-3 border-t border-[#1E293B]",children:[e.jsx("label",{className:"block text-slate-400 font-semibold mb-1 text-xs",children:"Outbound HTTP / SOCKS5 Proxy (Optional)"}),e.jsx("input",{type:"text",placeholder:"http://127.0.0.1:7890 or socks5://127.0.0.1:1080",value:le,onChange:a=>Z(a.target.value),className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white font-mono focus:outline-none focus:border-blue-500"})]})]}),e.jsxs("div",{className:"rt-card p-5 space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h3",{className:"text-sm font-bold text-white",children:"Available Models"}),e.jsxs("span",{className:"text-xs text-slate-500 font-mono",children:["(",g.length," active)"]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-slate-400 ml-2",children:[e.jsx("span",{children:"Thinking / Reasoning:"}),e.jsx(Fe,{value:_,onChange:S,options:C.map(a=>({value:a,label:a.toUpperCase()})),className:"w-32",triggerClassName:"font-mono text-xs"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>U(!0),className:"rt-btn rt-btn--secondary text-xs flex items-center gap-1.5",title:"Scan models directly from provider API endpoint",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px] text-blue-400",children:"radar"}),"Scan Models from API"]}),e.jsxs("button",{onClick:()=>H(!0),className:"rt-btn rt-btn--secondary text-xs",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"add"}),"Add Custom Model"]})]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2.5",children:g.map(a=>{const r=z.find(i=>i.id===a),m=je===a;return e.jsxs("div",{className:"flex items-center justify-between p-2.5 rounded-xl bg-[#0A0D14] border border-[#1E293B] hover:border-blue-500/30 text-xs transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2 truncate",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-blue-400 shrink-0",children:"smart_toy"}),e.jsxs("div",{className:"truncate",children:[e.jsx("span",{className:"font-mono text-slate-200 truncate block",children:a}),r&&r.name&&r.name!==a&&e.jsx("span",{className:"text-[10px] text-slate-500 truncate block",children:r.name})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:()=>bt(a),title:m?"Copied!":"Copy model ID",className:"p-1 text-slate-500 hover:text-white cursor-pointer transition-colors",children:e.jsx("span",{className:`material-symbols-outlined text-[14px] ${m?"text-emerald-400 font-bold":""}`,children:m?"check":"content_copy"})}),e.jsx("button",{onClick:()=>pt(a),title:"Remove model",className:"p-1 text-slate-500 hover:text-red-400 cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]})]},a)})})]}),Ue&&e.jsx("div",{className:"rt-card p-5 space-y-3 border border-rose-500/20 bg-rose-500/5",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-bold text-rose-400 flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"warning"}),"Danger Zone"]}),e.jsx("p",{className:"text-xs text-slate-400 mt-1",children:"Permanently remove this custom provider configuration and all associated accounts/credentials."})]}),e.jsxs("button",{type:"button",onClick:()=>Se(!0),disabled:de,className:"rt-btn rt-btn--danger text-xs py-2 px-4 flex items-center gap-1.5 cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"delete"}),de?"Deleting...":"Delete Provider"]})]})}),X&&e.jsx(At,{isOpen:X,provider:{id:l.id,name:l.name,image:l.image,color:(t==null?void 0:t.color)||l.color,iconBg:(t==null?void 0:t.iconBg)||l.iconBg,format:(t==null?void 0:t.format)||l.format,website:t==null?void 0:t.website,apiKeyUrl:(Ze=t==null?void 0:t.notice)==null?void 0:Ze.apiKeyUrl,regions:t==null?void 0:t.regions,defaultRegion:t==null?void 0:t.defaultRegion,requiresApiKey:t==null?void 0:t.requiresApiKey,authType:t==null?void 0:t.authType,isLocal:t==null?void 0:t.isLocal,defaultBaseUrl:(t==null?void 0:t.defaultBaseUrl)||(t==null?void 0:t.baseUrl),noAuth:t==null?void 0:t.noAuth},existingNames:h.map(a=>a.name),onClose:()=>I(!1),onSuccess:Q,onOpenOAuth:Ne?()=>{I(!1),ge()}:void 0}),re&&e.jsx(St,{isOpen:re,onClose:()=>xe(!1),onSuccess:Q}),G&&e.jsx(Et,{isOpen:G,onClose:()=>ie(!1),onSuccess:Q}),pe&&e.jsx(Dt,{isOpen:pe,onClose:()=>ue(!1),onSuccess:Q}),ee&&e.jsx(wt,{isOpen:ee,providerId:l.id,providerName:l.name,onSuccess:Q,onClose:()=>$(!1)}),e.jsx(Te,{isOpen:he,onClose:()=>H(!1),maxWidthClass:"max-w-md",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Add Custom Model"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-300 mb-1",children:"Model Identifier"}),e.jsx("input",{type:"text",placeholder:"e.g. custom-gpt-oss or claude-3-7-sonnet",value:B,onChange:a=>o(a.target.value),className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white font-mono focus:outline-none focus:border-blue-500"})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2 border-t border-[#1E293B]",children:[e.jsx("button",{onClick:()=>H(!1),className:"px-4 py-2 text-xs text-slate-400 cursor-pointer",children:"Cancel"}),e.jsx("button",{onClick:mt,className:"rt-btn rt-btn--primary",children:"Add Model"})]})]})}),e.jsx(Bt,{isOpen:ce,provider:{id:l.id,name:l.name,baseUrl:E||l.baseUrl||(t==null?void 0:t.baseUrl),modelsUrl:l.modelsUrl||(t==null?void 0:t.modelsUrl),image:l.image,color:(t==null?void 0:t.color)||l.color,iconBg:(t==null?void 0:t.iconBg)||l.iconBg,format:l.format||(t==null?void 0:t.format)},existingModels:g,accountsCount:h.length,onAddAccount:()=>{U(!1),Ne||["github","cursor","kiro","antigravity"].includes(l.id)?ge():I(!0)},onClose:()=>U(!1),onApplyModels:ht}),e.jsx(vt,{isOpen:!!ve,account:ve,onClose:()=>De(null),onSave:nt}),e.jsx(Te,{isOpen:!!se,onClose:()=>Pe(null),maxWidthClass:"max-w-md",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-[#1E293B] pb-3",children:[e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[18px]",children:"verified"}),"Verified Account Models"]}),e.jsx("p",{className:"text-[11px] text-slate-400 font-mono mt-0.5 truncate max-w-xs",children:se==null?void 0:se.accountName})]}),e.jsxs("span",{className:"px-2 py-0.5 text-[11px] font-mono rounded bg-blue-500/10 text-blue-400 font-semibold border border-blue-500/20",children:[(se==null?void 0:se.models.length)||0," models"]})]}),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:_e,onChange:a=>Re(a.target.value),placeholder:"Search supported models...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl pl-8 pr-3 py-1.5 text-xs text-white font-mono focus:outline-none focus:border-blue-500"})]}),e.jsx("div",{className:"max-h-60 overflow-y-auto space-y-1 pr-1 font-mono text-xs",children:se!=null&&se.loading?e.jsxs("div",{className:"py-8 text-center text-slate-500 flex items-center justify-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-[16px]",children:"sync"}),"Loading account models..."]}):(se==null?void 0:se.models.length)===0?e.jsx("div",{className:"py-8 text-center text-slate-500",children:"No specific models registered for this account yet."}):se==null?void 0:se.models.filter(a=>!_e||a.toLowerCase().includes(_e.toLowerCase())).map(a=>e.jsxs("div",{className:"flex items-center justify-between p-2 rounded-lg bg-[#0A0D14] border border-[#1E293B] hover:border-blue-500/30 text-slate-200",children:[e.jsx("span",{className:"truncate",children:a}),e.jsx("span",{className:"text-[10px] text-emerald-400",children:"ready"})]},a))}),e.jsx("div",{className:"flex justify-end pt-2 border-t border-[#1E293B]",children:e.jsx("button",{onClick:()=>Pe(null),className:"rt-btn rt-btn--secondary text-xs",children:"Close"})})]})}),Ue&&e.jsx(Nt,{isOpen:Ee,title:"Delete Provider",message:`Are you sure you want to delete custom provider "${l.name}"? This will permanently remove the provider configuration and all associated accounts/credentials.`,confirmText:"Delete",variant:"danger",onConfirm:ft,onCancel:()=>Se(!1)})]})};export{zt as ProviderDetailPage};