mapigate 0.5.153 → 0.5.155

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/README.md +1 -1
  2. package/dist/cli/client/apiClient.js +1 -1
  3. package/dist/cli/commands/doctor.js +3 -3
  4. package/dist/cli/commands/start.js +1 -1
  5. package/dist/cli/daemon/portHelper.js +1 -1
  6. package/dist/cli/tools/definitions/codex/configurator.js +3 -3
  7. package/dist/cli/tools/definitions/droid/definition.js +2 -2
  8. package/dist/cli/tools/helpers.js +2 -2
  9. package/dist/cli/tray/tray.js +1 -1
  10. package/dist/cli/tray/tray.ps1 +25 -3
  11. package/dist/cli/tui/settingsMenu.js +5 -5
  12. package/dist/core/adapters/helpers/toolCallRescue.js +1 -1
  13. package/dist/core/adapters/responsesAdapter.js +2 -2
  14. package/dist/core/resilience/cooldownManager.js +1 -1
  15. package/dist/core/resilience/index.js +1 -1
  16. package/dist/core/router/loadBalancer.js +1 -1
  17. package/dist/core/scanner/modelScanner.js +1 -1
  18. package/dist/core/scanner/urlResolver.js +1 -1
  19. package/dist/core/tokenSaver/methods/rtk/autodetect.js +4 -4
  20. package/dist/core/tokenSaver/methods/rtk/filters/buildOutput.js +8 -7
  21. package/dist/core/tokenSaver/methods/rtk/method.js +1 -1
  22. package/dist/core/usage/quotaService.js +1 -1
  23. package/dist/core/usage/tokenHelper.js +1 -1
  24. package/dist/mitm/cert/install.js +1 -1
  25. package/dist/mitm/cert/rootCA.js +1 -1
  26. package/dist/mitm/dns/dnsConfig.js +10 -9
  27. package/dist/mitm/handlers/antigravity/config.js +2 -2
  28. package/dist/mitm/handlers/base.js +2 -2
  29. package/dist/mitm/handlers/copilot/config.js +2 -2
  30. package/dist/mitm/handlers/copilot/handler.js +1 -1
  31. package/dist/mitm/handlers/kiro/config.js +2 -2
  32. package/dist/mitm/server.js +2 -2
  33. package/dist/mitm/toolsHelper.js +2 -2
  34. package/dist/providers/catalog/kilocode/routes.js +1 -1
  35. package/dist/providers/composite/combo/fusionStrategy.js +1 -1
  36. package/dist/providers/composite/combo/provider.js +1 -1
  37. package/dist/providers/core/base/anthropicProvider.js +1 -1
  38. package/dist/providers/core/base/customExecutionHelper.js +1 -0
  39. package/dist/providers/core/base/tokenExtractor.js +1 -1
  40. package/dist/providers/core/registry.js +1 -1
  41. package/dist/providers/runtime/antigravity/executor.js +7 -7
  42. package/dist/providers/runtime/antigravity/provider.js +1 -1
  43. package/dist/providers/runtime/antigravity/thoughtSignatureStore.js +1 -1
  44. package/dist/providers/runtime/bedrock/provider.js +1 -1
  45. package/dist/providers/runtime/cline/provider.js +1 -1
  46. package/dist/providers/runtime/codex/provider.js +1 -1
  47. package/dist/providers/runtime/gemini/provider.js +1 -1
  48. package/dist/providers/runtime/gemini-cli/provider.js +1 -1
  49. package/dist/providers/runtime/kimi/routes.js +1 -1
  50. package/dist/providers/runtime/kiro/auth.js +1 -1
  51. package/dist/providers/runtime/kiro/createResponse.js +1 -1
  52. package/dist/providers/runtime/kiro/createResponseConverter.js +2 -2
  53. package/dist/providers/runtime/kiro/deviceFlow.js +1 -1
  54. package/dist/providers/runtime/kiro/executor.js +6 -6
  55. package/dist/providers/runtime/kiro/externalIdp.js +1 -1
  56. package/dist/providers/runtime/minimax/provider.js +1 -1
  57. package/dist/providers/runtime/opencode/provider.js +1 -1
  58. package/dist/providers/runtime/trae/provider.js +13 -13
  59. package/dist/providers/runtime/windsurf/provider.js +11 -11
  60. package/dist/providers/runtime/zed/provider.js +13 -13
  61. package/dist/server/auth/masterAuth.js +1 -1
  62. package/dist/server/index.js +4 -4
  63. package/dist/server/lifecycle.js +1 -1
  64. package/dist/server/proxy/countTokens.js +1 -1
  65. package/dist/server/proxy/index.js +1 -1
  66. package/dist/server/proxy/pipeline.js +5 -5
  67. package/dist/server/proxy/proxyDispatcher.js +1 -1
  68. package/dist/server/proxy/responseHandlers.js +1 -1
  69. package/dist/server/proxy/singleModelExecutor.js +5 -5
  70. package/dist/server/proxy/streaming/bedrockStreamer.js +9 -9
  71. package/dist/server/proxy/streaming/sseStreamer.js +16 -16
  72. package/dist/server/routes/apiAuth.js +1 -1
  73. package/dist/server/routes/apiCliTools.js +1 -1
  74. package/dist/server/routes/apiCombos.js +1 -1
  75. package/dist/server/routes/apiMitm.js +1 -1
  76. package/dist/server/routes/apiModels.js +1 -1
  77. package/dist/server/routes/apiOAuth.js +1 -1
  78. package/dist/server/routes/apiProviders.js +1 -1
  79. package/dist/server/routes/apiQuota.js +1 -1
  80. package/dist/server/routes/apiServer.js +1 -1
  81. package/dist/server/routes/mitmRouterTargetHelper.js +1 -1
  82. package/dist/server/utils/consoleLogBuffer.js +1 -1
  83. package/dist/shared/constants/index.js +1 -1
  84. package/dist/shared/utils/dnsResolver.js +1 -1
  85. package/dist/shared/utils/security.js +1 -1
  86. package/dist/shared/utils/versionChecker.js +1 -1
  87. package/dist/storage/backupService.js +1 -1
  88. package/dist/storage/database.js +3 -2
  89. package/dist/storage/repositories/comboRepo.js +11 -9
  90. package/dist/storage/repositories/logRepo.js +5 -8
  91. package/dist/storage/repositories/mitmRepo.js +5 -5
  92. package/dist/storage/repositories/modelRepo.js +9 -7
  93. package/dist/storage/repositories/providerRepo.js +5 -5
  94. package/dist/storage/repositories/requestDetailsRepo.js +5 -5
  95. package/dist/storage/repositories/settingsRepo.js +2 -2
  96. package/dist/storage/repositories/toolMappingRepo.js +4 -4
  97. package/dist/web/assets/CallbackPage-sTRnWJ-d.js +1 -0
  98. package/dist/web/assets/{CliToolsTab-D_MUwimj.js → CliToolsTab-CJ1qK1mc.js} +2 -2
  99. package/dist/web/assets/{CombosTab-EWUYC3TU.js → CombosTab-C__IN7Vh.js} +1 -1
  100. package/dist/web/assets/{ConfirmModal-CMfDss7P.js → ConfirmModal-S6NP0OqD.js} +1 -1
  101. package/dist/web/assets/{ConsoleLogTab-BSMXSYrR.js → ConsoleLogTab-BW7FAr8M.js} +1 -1
  102. package/dist/web/assets/{EditAccountModal-OrvqLLBP.js → EditAccountModal-BOJ3dX8Q.js} +1 -1
  103. package/dist/web/assets/{EndpointTab-BwtzqXUN.js → EndpointTab-DpvqvtLI.js} +1 -1
  104. package/dist/web/assets/{MitmTab-C7g7GUXW.js → MitmTab-BkYhPR9f.js} +6 -6
  105. package/dist/web/assets/ProviderDetailPage-D7ptkJW2.js +6 -0
  106. package/dist/web/assets/{ProvidersTab-CwJo_EUX.js → ProvidersTab-C0UAYPzg.js} +1 -1
  107. package/dist/web/assets/{QuotaTab-PFvP6yAb.js → QuotaTab-CK7pgfKr.js} +1 -1
  108. package/dist/web/assets/{SettingsTab-DwAbjIW3.js → SettingsTab-DpK_sfw0.js} +1 -1
  109. package/dist/web/assets/{UsageTab-85tTb2_C.js → UsageTab-dv87ggGC.js} +1 -1
  110. package/dist/web/assets/index-D3Xjro_O.js +2 -0
  111. package/dist/web/index.html +1 -1
  112. package/package.json +1 -1
  113. package/dist/web/assets/CallbackPage-DBsxnmPi.js +0 -1
  114. package/dist/web/assets/ProviderDetailPage-BIfOQupC.js +0 -6
  115. package/dist/web/assets/index-CWkEEbms.js +0 -2
@@ -1,6 +0,0 @@
1
- import{r as s,j as e}from"./vendor-BcOI2aZ9.js";import{i as lt}from"./providersData-Y57rBt5o.js";import{g as ot}from"./metadataRegistry-FuJXbCt4.js";import{u as Nt,D as wt,P as Be}from"./index-CWkEEbms.js";import{S as ze}from"./Select-BNRH8LIG.js";import{T as Le}from"./ToolIcon-Cp4gSgFt.js";import{i as Ae}from"./ModelAutocompleteInput-DEb_clZC.js";import{C as nt,E as kt}from"./EditAccountModal-OrvqLLBP.js";import{C as Ct}from"./ConfirmModal-CMfDss7P.js";import"./lucide-Cc35htxl.js";const At=({isOpen:l,providerId:n,providerName:t,onSuccess:h,onClose:j})=>{const f=s.useRef(h);f.current=h;const i=s.useRef(j);i.current=j;const H=Nt(A=>A.info),b=(H==null?void 0:H.port)||wt,I=s.useRef(b);I.current=b;const g=ot(n),w=(g==null?void 0:g.regions)||[],[y,U]=s.useState((g==null?void 0:g.defaultRegion)||(w.length>0?w[0].id:"")),S=s.useRef(y);S.current=y;const[k,K]=s.useState(""),[z,Y]=s.useState(`http://localhost:${b}/callback`),[E,M]=s.useState(""),[T,B]=s.useState("loading"),[ae,J]=s.useState(null),[te,D]=s.useState(!1),[G,P]=s.useState(!1),[L,F]=s.useState(!1),[se,xe]=s.useState(!1),[q,oe]=s.useState(null),fe=s.useRef(null),ue=s.useRef(!1),me=s.useRef(void 0),W=s.useRef(void 0),le=s.useRef(0),$=s.useRef(null),_=s.useCallback(()=>{$.current&&(clearTimeout($.current),clearInterval($.current),$.current=null)},[]),c=s.useCallback(async A=>{if(!ue.current){ue.current=!0,_(),B("processing"),J(null);try{const re=await fetch(`/api/oauth/${n}/exchange`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:A,redirectUri:z,codeVerifier:me.current,state:W.current,region:S.current||void 0})}),X=await re.json().catch(()=>({}));if(!re.ok||X.error)throw new Error(X.error||"Token exchange failed");B("success");try{localStorage.removeItem("oauth_pending_flow"),localStorage.removeItem("oauth_callback")}catch{}setTimeout(()=>{f.current(),i.current()},1200)}catch(re){ue.current=!1,B("error"),J(re.message||"Failed to exchange authorization token")}}},[n,z,_]),d=s.useCallback(async A=>{const re=++le.current,X=()=>re!==le.current;ue.current=!1,_(),B("loading"),J(null),M(""),xe(!1),oe(null),F(!1),me.current=void 0,W.current=void 0;const ce=A!==void 0?A:S.current,x=ce?`&region=${encodeURIComponent(ce)}`:"",u=ce?`?region=${encodeURIComponent(ce)}`:"",v=window.location.port==="5173"?`http://localhost:${I.current}/callback`:`${window.location.origin}/callback`;Y(v);try{const he=await fetch(`/api/oauth/${n}/authorize?redirect_uri=${encodeURIComponent(v)}${x}`),R=await he.json().catch(()=>({}));if(X())return;if(!he.ok||R.error)throw new Error(R.error||`Authorization error (HTTP ${he.status})`);if(R.flowType==="device_code"||!R.authUrl&&R.flowType){xe(!0),B("waiting");const Z=await fetch(`/api/oauth/${n}/device-code${u}`),V=await Z.json().catch(()=>({}));if(X())return;if(!Z.ok||!V.device_code)throw new Error(V.error||"Failed to initiate device code flow");oe(V);const Se=V.verification_uri_complete||V.verification_uri;if(Se)try{window.open(Se,"_blank","noopener,noreferrer")}catch{}let be=Number(V.interval)||5,ge=!0;const we=je=>{X()||($.current&&clearTimeout($.current),$.current=setTimeout(async()=>{if(!(!ge||X()))try{const de=await(await fetch(`/api/oauth/${n}/poll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:V.device_code,codeVerifier:V.codeVerifier,region:ce||void 0,extraData:{...V||{},_zcodePollToken:V._zcodePollToken,_minimaxPollByUser:V._minimaxPollByUser,codeVerifier:V.codeVerifier,user_code:V.user_code,region:ce||void 0}})})).json();if(X())return;if(de.ok&&de.success){ge=!1,_(),B("success"),setTimeout(()=>{f.current(),i.current()},1200);return}if(de.error==="slow_down"){be=Math.min(be+5,30),we(be);return}if(de.error==="authorization_pending"){we(be);return}if(de.error){ge=!1,_(),B("error"),J(de.error_description||de.error);return}we(be)}catch{ge&&we(be)}},je*1e3))};we(be);return}if(R.authUrl){K(R.authUrl),R.redirectUri&&Y(R.redirectUri),R.codeVerifier&&(me.current=R.codeVerifier),R.state&&(W.current=R.state),B("waiting");try{localStorage.setItem("oauth_pending_flow",JSON.stringify({providerId:n,redirectUri:R.redirectUri||v,state:R.state,codeVerifier:R.codeVerifier,timestamp:Date.now()}))}catch{}try{const Z=window.open(R.authUrl,"oauth_popup","width=600,height=700");Z&&!Z.closed?fe.current=Z:F(!0)}catch{F(!0)}return}throw new Error("No authorization URL returned from provider")}catch(he){if(X())return;if(n==="antigravity"&&DEFAULT_ANTIGRAVITY_AUTH_URL){K(DEFAULT_ANTIGRAVITY_AUTH_URL),B("waiting");try{const R=window.open(DEFAULT_ANTIGRAVITY_AUTH_URL,"oauth_popup","width=600,height=700");R?fe.current=R:F(!0)}catch{F(!0)}}else B("error"),J(he.message||"Failed to initialize authorization endpoint")}},[n,_]);if(s.useEffect(()=>{if(!l){_(),B("loading"),J(null),xe(!1),oe(null);return}return d(),()=>{le.current++,_()}},[l,n,d,_]),s.useEffect(()=>{if(!l)return;const A=u=>{if(!u)return;if(u.done){ue.current=!0,_(),B("success");try{localStorage.removeItem("oauth_pending_flow"),localStorage.removeItem("oauth_callback")}catch{}setTimeout(()=>{f.current(),i.current()},1200);return}if(u.error){B("error"),J(u.errorDescription||u.error);return}const v=u.code||u.token||(u.userId&&u.token?u.fullUrl||`${window.location.origin}/?user_id=${u.userId}&access_token=${u.token}`:null);v&&c(v)},re=u=>{var v;((v=u.data)==null?void 0:v.type)==="oauth_callback"&&A(u.data.data)};window.addEventListener("message",re);let X=null;try{X=new BroadcastChannel("oauth_callback"),X.onmessage=u=>A(u.data)}catch{}const ce=u=>{if(u.key==="oauth_callback"&&u.newValue)try{const v=JSON.parse(u.newValue);A(v),localStorage.removeItem("oauth_callback")}catch{}};window.addEventListener("storage",ce);const x=setInterval(()=>{try{const u=localStorage.getItem("oauth_callback");if(u){const v=JSON.parse(u);v&&(!v.timestamp||Date.now()-v.timestamp<6e4)&&A(v),localStorage.removeItem("oauth_callback")}}catch{}},500);return()=>{clearInterval(x),window.removeEventListener("message",re),window.removeEventListener("storage",ce),X&&X.close()}},[l,c]),!l)return null;const C=()=>{k&&(navigator.clipboard.writeText(k),D(!0),setTimeout(()=>D(!1),2e3))},pe=A=>{A&&(navigator.clipboard.writeText(A),P(!0),setTimeout(()=>P(!1),2e3))},Q=()=>{if(k){F(!1);try{const A=window.open(k,"oauth_popup","width=600,height=700");A&&(fe.current=A)}catch{}}},ve=()=>{E.trim()&&c(E.trim())};return e.jsx(Be,{isOpen:l,onClose:j,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:j,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"})})]}),w.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:y})]}),e.jsx(ze,{value:y,onChange:A=>{U(A),S.current=A,d(A)},options:w.map(A=>({value:A.id,label:A.label}))})]}),T==="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,"..."]})]}),T==="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:se?"Waiting for device authorization in browser...":L?"Authorization link ready. Click button below to open login window.":"Popup window opened. Complete authorization in browser..."})]}),T==="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..."})]}),T==="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..."})]}),T==="error"&&ae&&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:ae})]})]}),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"]})]}),se&&q?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:q.user_code}),e.jsxs("button",{type:"button",onClick:()=>pe(q.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] ${G?"text-emerald-400":""}`,children:G?"check":"content_copy"}),G?"Copied":"Copy Code"]})]})]}),e.jsxs("button",{type:"button",onClick:()=>{const A=q.verification_uri_complete||q.verification_uri;A&&window.open(A,"_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:E,onChange:A=>M(A.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:Q,disabled:!k||T==="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"})]}),L&&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"}),k&&e.jsx("button",{type:"button",onClick:()=>window.open(k,"_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:k||(T==="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:C,disabled:!k,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] ${te?"text-emerald-400":""}`,children:te?"check":"content_copy"}),te?"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:E,onChange:A=>M(A.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:j,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:ve,disabled:!E.trim()||T==="processing",className:"rt-btn rt-btn--primary disabled:opacity-50 disabled:cursor-not-allowed",children:T==="processing"?"Exchanging...":"Connect"})]})]})})};function St(l,n={}){const{isCloudflareAi:t=!1}=n,h=l.trim();if(!t&&/^LLM\|/i.test(h))return{baseName:"LLM",apiKey:h};const j=l.split("|");if(t&&j.length>=3){const i=j[0].trim(),H=j.slice(1,-1).join("|").trim(),b=j[j.length-1].trim();return{baseName:i||"Key",apiKey:H,providerSpecificData:{accountId:b}}}if(j.length>=2){const i=j[0].trim(),H=j.slice(1).join("|").trim();return{baseName:i||"Key",apiKey:H}}return{baseName:"Key",apiKey:j[0].trim()}}function Et(l,n=[],t={}){const h=Array.isArray(n)?n:[],j=new Set(h.map(i=>typeof i=="string"?i.toLowerCase():"")),f=[];for(const i of l){const H=typeof i=="string"?i.trim():"";if(!H)continue;const b=St(H,t);if(!b||!b.apiKey)continue;const I=b.baseName;let g=1,w;for(;w=`${I} ${g}`,!!j.has(w.toLowerCase());)g+=1;j.add(w.toLowerCase());const y={name:w,apiKey:b.apiKey};b.providerSpecificData&&(y.providerSpecificData=b.providerSpecificData),f.push(y)}return f}const Dt=({isOpen:l,provider:n,existingNames:t=[],onClose:h,onSuccess:j,onOpenOAuth:f})=>{const i=n.id.toLowerCase(),H=i==="opencode"||i==="oc"||!!n.noAuth||n.requiresApiKey===!1||n.authType==="none",b=i==="ollama-local"||i.includes("ollama"),I=!!n.isLocal||i==="lm-studio"||i==="jan",g=H||b||I||n.requiresApiKey===!1,w=i==="azure"||i.includes("azure"),y=i==="cloudflare-ai"||i==="cloudflare",U=i==="bedrock"||i.includes("bedrock"),S=i==="grok-web"||i==="iflow",k=i==="xiaomi-tokenplan",K=i==="alicode"||i==="alibaba",z=s.useMemo(()=>k?[{id:"sgp",label:"Singapore (新加坡)"},{id:"cn",label:"China (中国大陆)"},{id:"ams",label:"Amsterdam (阿姆斯特丹)"}]:n.regions||[],[k,n.regions]),[Y,E]=s.useState(n.defaultRegion||(z.length>0?z[0].id:"sgp")),[M,T]=s.useState("single"),[B,ae]=s.useState(""),[J,te]=s.useState(""),[D,G]=s.useState(""),[P,L]=s.useState("http://127.0.0.1:11434"),[F,se]=s.useState(n.defaultBaseUrl||(i==="lm-studio"?"http://localhost:1234/v1":i==="jan"?"http://localhost:1337/v1":"http://localhost:8000/v1")),[xe,q]=s.useState(""),[oe,fe]=s.useState("gpt-4"),[ue,me]=s.useState("2024-10-01-preview"),[W,le]=s.useState(""),[$,_]=s.useState(""),[c,d]=s.useState(""),[C,pe]=s.useState("profile"),[Q,ve]=s.useState(""),[A,re]=s.useState("us-east-1"),[X,ce]=s.useState(""),[x,u]=s.useState(""),[v,he]=s.useState(""),[R,Z]=s.useState(null),[V,Se]=s.useState(!1),[be,ge]=s.useState(null),[we,je]=s.useState(null),[Ee,de]=s.useState(!1),[Ue,ke]=s.useState(null),[Fe,Oe]=s.useState(!1),[Pe,_e]=s.useState(null),ee=s.useCallback(()=>{T("single"),ae(""),te(""),G(""),L("http://127.0.0.1:11434"),se(n.defaultBaseUrl||(i==="lm-studio"?"http://localhost:1234/v1":i==="jan"?"http://localhost:1337/v1":"http://localhost:8000/v1")),q(""),fe("gpt-4"),me("2024-10-01-preview"),le(""),_(""),d(""),pe("profile"),ve(""),re("us-east-1"),ce(""),u(""),E(n.defaultRegion||(z.length>0?z[0].id:"sgp")),he(""),Z(null),Se(!1),ge(null),je(null),de(!1),ke(null),Oe(!1),_e(null)},[n.defaultBaseUrl,n.defaultRegion,z,i]);s.useEffect(()=>{l&&ee()},[l,ee]);const Re=async()=>{Oe(!0),_e(null);try{const ne=await(await fetch(`/api/oauth/${encodeURIComponent(n.id)}/auto-import`)).json(),ie=ne.apiKey||ne.accessToken;ne.found&&ie?(G(ie),B.trim()||ae(ne.userName||ne.keyName||ne.email||`${n.name} CLI`),ge(null),je(null)):_e(ne.error||`Could not find ${n.name} CLI credentials`)}catch{_e(`Failed to auto-import from ${n.name} CLI`)}finally{Oe(!1)}},De=()=>{ee(),h()},He=()=>S?i==="grok-web"?"sso=xxxx... or raw cookie":"eyJhbGciOi...":g?"Optional / Not required":k?"tp-...":i.startsWith("deepseek")?"sk-...":i.startsWith("xai")?"xai-...":i.startsWith("groq")?"gsk_...":i.startsWith("anthropic")?"sk-ant-...":i.startsWith("gemini")?"AIzaSy...":"sk-...",$e=()=>{if(b)return{baseUrl:P.trim()||"http://127.0.0.1:11434"};if(I)return{baseUrl:F.trim()};if(w)return{azureEndpoint:xe.trim(),deployment:oe.trim(),apiVersion:ue.trim(),organization:W.trim()||void 0};if(y)return{accountId:$.trim()};if(U)return C==="profile"?{profile:Q.trim(),region:A.trim()||"us-east-1"}:{accessKeyId:X.trim(),region:A.trim()||"us-east-1",sessionToken:x.trim()||void 0};if(k||z.length>0){const m={region:Y};return K&&c.trim()&&(m.baseUrl=c.trim()),m}},Te=()=>g?!0:U&&C==="profile"?!!Q.trim():U&&C==="static"?!!(D.trim()&&X.trim()):w?!!(D.trim()&&xe.trim()&&oe.trim()):y?!!(D.trim()&&$.trim()):k?!!(D.trim()&&Y):!!D.trim(),Ne=async()=>{Se(!0),ge(null),je(null);try{const m=$e(),ie=await(await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:n.id,apiKey:D.trim(),providerSpecificData:m})})).json();ie.valid?ge("valid"):(ge("invalid"),je(ie.error||"Validation check failed"))}catch(m){ge("invalid"),je(m.message||"Connection check error")}finally{Se(!1)}},We=async()=>{if(!Te())return;de(!0),ke(null);const m=H?i==="opencode"||i==="oc"?"OpenCode Free":`${n.name} (Public)`:b?"Ollama Local":I?`${n.name} Local`:U&&C==="profile"?`Bedrock (${Q})`:k?`Xiaomi MiMo (${Y.toUpperCase()})`:`${n.name} Account`,ne=B.trim()||m,ie=$e()||{};J.trim()&&(ie.tag=J.trim().toLowerCase());try{const Ce=await fetch(`/api/providers/${n.id}/accounts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:ne,apiKey:D.trim()||(i==="opencode"||i==="oc"?"public":""),providerSpecificData:Object.keys(ie).length>0?ie:void 0})});if(!Ce.ok){const Ke=await Ce.json().catch(()=>({}));throw new Error(Ke.error||`Server returned ${Ce.status}`)}Ae(),ee(),j(),h()}catch(Ce){ke(Ce.message||"Failed to save account")}finally{de(!1)}},Me=async()=>{if(!v.trim())return;de(!0),Z(null),ke(null);const m=v.split(`
2
- `),ne=Et(m,t,{isCloudflareAi:y});if(ne.length===0){ke("No valid keys found in input"),de(!1);return}try{const ie=await fetch(`/api/providers/${n.id}/accounts/bulk`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({accounts:ne})});if(!ie.ok){const Ke=await ie.json().catch(()=>({}));throw new Error(Ke.error||`Bulk addition failed (${ie.status})`)}const Ce=await ie.json();Ae(),Z({success:Ce.count||ne.length,failed:0}),setTimeout(()=>{ee(),j(),h()},700)}catch(ie){ke(ie.message||"Failed to add bulk keys")}finally{de(!1)}};return e.jsx(Be,{isOpen:l,onClose:De,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(Le,{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":U?"Configure AWS SSO profile or static keys":w?"Configure Azure OpenAI deployment & endpoint":b?"Connect local self-hosted model service":I?`Connect local ${n.name} model server`:g?"No API key required for this provider":k?"Select cluster region & paste Token Plan API key":"API key is hardware-encrypted (AES-256-GCM)"})]})]}),e.jsx("button",{onClick:De,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"})})]}),f&&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:f,className:"rt-btn rt-btn--primary text-xs py-1 px-3 cursor-pointer shrink-0",children:"Connect with OAuth"})]}),!U&&!b&&!g&&e.jsxs("div",{className:"flex bg-[#0A0D14] p-1 rounded-xl border border-[#1E293B] text-xs",children:[e.jsx("button",{onClick:()=>{T("single"),Z(null)},className:`flex-1 py-1.5 rounded-lg font-medium transition-colors cursor-pointer ${M==="single"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Single Connection"}),e.jsx("button",{onClick:()=>{T("bulk"),Z(null)},className:`flex-1 py-1.5 rounded-lg font-medium transition-colors cursor-pointer ${M==="bulk"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Bulk Add Keys"})]}),M==="bulk"&&!U&&!b&&!g?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:y?`name|apiToken|accountId
3
- or just apiToken`:`name|apiKey
4
- or just apiKey (auto-numbered)`})]}),e.jsx("textarea",{value:v,onChange:m=>he(m.target.value),placeholder:y?`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"}),R&&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 ",R.success," connection(s)."]}),Ue&&e.jsx("p",{className:"text-xs text-rose-400",children:Ue}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{onClick:Me,disabled:Ee||!v.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:Ee?"Adding...":"Add All Keys"}),e.jsx("button",{onClick:De,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:B,onChange:m=>ae(m.target.value),placeholder:b?"Ollama Local":I?`${n.name} Local`:H?"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:J,onChange:m=>te(m.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(m=>e.jsx("button",{type:"button",tabIndex:-1,onClick:ne=>{ne.preventDefault(),te(m)},className:`pointer-events-auto text-[10px] px-1.5 py-0.5 rounded font-mono transition-colors ${J===m?"bg-blue-600 text-white font-semibold":"bg-[#1E293B] text-slate-400 hover:text-slate-200"}`,children:m},m))})]})]})]}),n.supportsAutoImport&&!g&&e.jsxs("div",{className:"flex items-center justify-between gap-3 p-3 rounded-xl bg-blue-500/10 border border-blue-500/20",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"text-xs font-medium text-blue-200",children:[n.name," CLI Auto-Import"]}),e.jsx("div",{className:"text-[11px] text-slate-400",children:n.autoImportHint||`Import local credentials for ${n.name}`}),Pe&&e.jsx("div",{className:"text-[11px] text-red-400 mt-1 whitespace-pre-line",children:Pe})]}),e.jsx("button",{type:"button",onClick:Re,disabled:Fe||Ee,className:"rt-btn rt-btn--secondary text-xs py-1.5 px-3 cursor-pointer shrink-0 disabled:opacity-50",children:Fe?"Importing...":"Import from CLI"})]}),g&&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."]})]}),(k||z.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(ze,{value:Y,onChange:m=>E(m),options:z.map(m=>({value:m.id,label:m.label.includes(m.id)?m.label:`${m.label} (${m.id})`})),className:"w-full",triggerClassName:"bg-[#0F1420] font-mono text-xs py-2"}),k&&e.jsx("p",{className:"text-[11px] text-slate-400 mt-1",children:"Token Plan keys are cluster-specific — select the region matching your subscription."}),K&&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:c,onChange:m=>d(m.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:P,onChange:m=>L(m.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:Ne,disabled:V,className:"rt-btn rt-btn--secondary shrink-0",children:V?"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."]})]})}),I&&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:F,onChange:m=>se(m.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:Ne,disabled:V,className:"rt-btn rt-btn--secondary shrink-0",children:V?"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."]})]})}),w&&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:m=>q(m.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:oe,onChange:m=>fe(m.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:m=>me(m.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:W,onChange:m=>le(m.target.value),placeholder:"org-id",className:"w-full bg-[#0F1420] border border-[#1E293B] rounded-xl px-3 py-1.5 text-white font-mono"})]})]})]}),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:"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:$,onChange:m=>_(m.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"})]})]})]}),U&&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:()=>pe("profile"),className:`flex-1 py-1 rounded-lg font-medium transition-colors cursor-pointer ${C==="profile"?"bg-blue-600 text-white":"text-slate-400 hover:text-white"}`,children:"AWS Profile (SSO — Recommended)"}),e.jsx("button",{type:"button",onClick:()=>pe("static"),className:`flex-1 py-1 rounded-lg font-medium transition-colors cursor-pointer ${C==="static"?"bg-blue-600 text-white":"text-slate-400 hover:text-white"}`,children:"Static Keys (AKIA...)"})]}),C==="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:Q,onChange:m=>ve(m.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:A,onChange:m=>re(m.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 ",Q||"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:X,onChange:m=>ce(m.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:A,onChange:m=>re(m.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:x,onChange:m=>u(m.target.value),placeholder:"FwoGZXIvYXdz...",className:"w-full bg-[#0F1420] border border-[#1E293B] rounded-xl px-3 py-1.5 text-white font-mono"})]})]})]}),!b&&!(U&&C==="profile")&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:S?"Cookie Value":U?"Secret Access Key":y?"Cloudflare API Token":k?"Token Plan Key (tp-...)":g?"API Key (Optional)":"API Key"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:S?"text":"password",value:D,onChange:m=>G(m.target.value),placeholder:He(),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:Ne,disabled:V||!Te(),className:"rt-btn rt-btn--secondary shrink-0",children:V?"Checking...":"Check"})]})]}),be&&e.jsxs("div",{className:`p-2.5 rounded-xl border flex items-center gap-2 ${be==="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:be==="valid"?"check_circle":"error"}),e.jsx("span",{children:be==="valid"?"Credentials verified successfully!":we||"Invalid credentials."})]}),Ue&&e.jsx("p",{className:"text-xs text-rose-400",children:Ue}),e.jsxs("div",{className:"flex gap-2 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{type:"button",onClick:We,disabled:Ee||!Te(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:Ee?"Saving Connection...":"Save Connection"}),e.jsx("button",{type:"button",onClick:De,className:"rt-btn rt-btn--secondary",children:"Cancel"})]})]})]})})},Tt=({isOpen:l,onClose:n,onSuccess:t})=>{const[h,j]=s.useState("device"),[f,i]=s.useState(null),[H,b]=s.useState(!1),[I,g]=s.useState(!1),[w,y]=s.useState("idle"),[U,S]=s.useState(null),[k,K]=s.useState(""),[z,Y]=s.useState(""),[E,M]=s.useState(!1),T=s.useRef(null),B=()=>{T.current&&(clearTimeout(T.current),clearInterval(T.current),T.current=null)};s.useEffect(()=>{if(!l){B(),i(null),y("idle"),K(""),Y(""),S(null);return}return K(""),Y(""),S(null),h==="device"&&ae(),()=>{B()}},[l,h]);const ae=async()=>{B(),b(!0),S(null),y("idle");try{const D=await fetch("/api/oauth/github/device-code",{method:"POST"});if(!D.ok){const se=await D.text();throw new Error(se||"Failed to initiate GitHub device flow")}const G=await D.json();i(G),y("polling");let P=Math.max(G.interval||5,5),L=!0;const F=se=>{T.current&&clearTimeout(T.current),T.current=setTimeout(async()=>{if(L)try{const q=await(await fetch("/api/oauth/github/poll",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:G.device_code})})).json();if(q.ok){L=!1,y("success"),setTimeout(()=>{t(),n()},1200);return}if(q.error==="slow_down"){P=Math.min(P+5,30),F(P);return}if(q.error==="authorization_pending"){F(P);return}L=!1,y("error"),S(q.error_description||q.error)}catch{L&&F(P)}},se*1e3)};F(P)}catch(D){y("error"),S(D.message||"Failed to request device code")}finally{b(!1)}},J=D=>{navigator.clipboard.writeText(D),g(!0),setTimeout(()=>g(!1),2e3)},te=async()=>{if(k.trim()){M(!0),S(null);try{const D=await fetch("/api/oauth/github/token",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:k.trim(),name:z.trim()||void 0})});if(!D.ok){const G=await D.json().catch(()=>({}));throw new Error(G.error||"Failed to save GitHub token")}t(),n()}catch(D){S(D.message||"Could not save token")}finally{M(!1)}}};return l?e.jsx(Be,{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(Le,{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:()=>j("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:()=>j("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:[H?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..."})]}):f?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:f.user_code}),e.jsxs("button",{onClick:()=>J(f.user_code),className:"rt-btn rt-btn--secondary py-1 text-xs",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:I?"check":"content_copy"}),I?"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:f.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"})]})]}),w==="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..."})]}),w==="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,U&&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:U})]})]}):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:z,onChange:D=>Y(D.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:k,onChange:D=>K(D.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."})]}),U&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:U}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{onClick:te,disabled:E||!k.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:E?"Connecting...":"Save Copilot Account"}),e.jsx("button",{onClick:n,className:"rt-btn rt-btn--secondary",children:"Cancel"})]})]})]})}):null},Bt=({isOpen:l,onClose:n,onSuccess:t})=>{const[h,j]=s.useState(""),[f,i]=s.useState(""),[H,b]=s.useState(""),[I,g]=s.useState(!1),[w,y]=s.useState(!1),[U,S]=s.useState(null),[k,K]=s.useState(!1);s.useEffect(()=>{if(!l){j(""),i(""),b(""),y(!1),S(null);return}b(""),S(null),z()},[l]);const z=async()=>{g(!0),y(!1),S(null);try{const M=await(await fetch("/api/oauth/cursor/auto-import")).json();M.found?(j(M.accessToken||""),i(M.machineId||""),y(!0)):S(M.error||"Could not auto-detect token from local Cursor database")}catch(E){S(E.message||"Failed to auto-detect Cursor tokens")}finally{g(!1)}},Y=async()=>{if(h.trim()){K(!0),S(null);try{const E=await fetch("/api/oauth/cursor/import",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({accessToken:h.trim(),machineId:f.trim()||void 0,name:H.trim()||void 0})});if(!E.ok){const M=await E.json().catch(()=>({}));throw new Error(M.error||"Failed to import Cursor connection")}t(),n()}catch(E){S(E.message||"Could not save Cursor account")}finally{K(!1)}}};return l?e.jsx(Be,{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(Le,{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"})})]}),I?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:[w&&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:H,onChange:E=>b(E.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:E=>j(E.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:f,onChange:E=>i(E.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"})]}),U&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:U}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsxs("button",{onClick:z,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:Y,disabled:k||!h.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:k?"Saving...":"Save Connection"})]})]})]})}):null},Pt=({isOpen:l,onClose:n,onSuccess:t})=>{const[h,j]=s.useState("builder-id"),[f,i]=s.useState(null),[H,b]=s.useState(!1),[I,g]=s.useState(!1),w=s.useRef(null),[y,U]=s.useState(""),[S,k]=s.useState("us-east-1"),[K,z]=s.useState(""),[Y,E]=s.useState(""),[M,T]=s.useState(""),[B,ae]=s.useState(!1),[J,te]=s.useState(!1),[D,G]=s.useState(null),[P,L]=s.useState(""),[F,se]=s.useState(""),[xe,q]=s.useState("us-east-1"),[oe,fe]=s.useState(""),[ue,me]=s.useState("us-east-1"),[W,le]=s.useState(""),[$,_]=s.useState(!1),[c,d]=s.useState(null),C=s.useCallback(()=>{w.current&&clearInterval(w.current),i(null),b(!1),g(!1),U(""),k("us-east-1"),z(""),E(""),T(""),ae(!1),te(!1),G(null),L(""),se(""),q("us-east-1"),fe(""),me("us-east-1"),le(""),_(!1),d(null)},[]);s.useEffect(()=>{if(!l){C();return}C(),h==="import"&&ve()},[l,h,C]),s.useEffect(()=>()=>{w.current&&clearInterval(w.current)},[]);const pe=x=>{navigator.clipboard.writeText(x),g(!0),setTimeout(()=>g(!1),2e3)},Q=async x=>{_(!0),d(null),i(null);try{const u=await fetch("/api/oauth/kiro/device-code",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...x,name:x.name||W.trim()||void 0})});if(!u.ok){const R=await u.json().catch(()=>({}));throw new Error(R.error||"Failed to start AWS device authorization")}const v=await u.json();i(v),b(!0),v.verification_uri_complete&&window.open(v.verification_uri_complete,"_blank","noopener,noreferrer");const he=Math.max((v.interval||5)*1e3,3e3);w.current&&clearInterval(w.current),w.current=setInterval(async()=>{try{const Z=await(await fetch("/api/oauth/kiro/device-poll",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({deviceCode:v.device_code,extraData:v.extraData})})).json();Z.ok&&Z.success?(w.current&&clearInterval(w.current),b(!1),t(),n()):Z.error&&!Z.pending&&(w.current&&clearInterval(w.current),b(!1),d(Z.error))}catch{}},he)}catch(u){d(u.message||"Failed to start device flow")}finally{_(!1)}},ve=async()=>{ae(!0),te(!1),d(null);try{const u=await(await fetch("/api/oauth/kiro/auto-import")).json();u.found&&(u.refreshToken||u.accessToken)?(u.refreshToken&&E(u.refreshToken),u.accessToken&&T(u.accessToken),te(!0),u.clientId&&u.clientSecret&&G({clientId:u.clientId,clientSecret:u.clientSecret,region:u.region||"us-east-1",authMethod:u.authMethod||"idc",profileArn:u.profileArn})):d(u.error||"Could not auto-detect token from ~/.aws/sso/cache")}catch(x){d(x.message||"Failed to scan AWS SSO cache")}finally{ae(!1)}},A=async()=>{const x=Y.trim(),u=M.trim();if(!x&&!u){d("Please provide a refresh token or access token");return}_(!0),d(null);try{const v=await fetch("/api/oauth/kiro/import",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:x||void 0,accessToken:u||void 0,name:W.trim()||void 0,...D||{}})});if(!v.ok){const he=await v.json().catch(()=>({}));throw new Error(he.error||"Failed to import Kiro credentials")}t(),n()}catch(v){d(v.message||"Import failed")}finally{_(!1)}},re=async()=>{const x=y.trim();if(!x){d("Please enter your Access Token (aoa... or JWT)");return}_(!0),d(null);try{const u=await fetch("/api/oauth/kiro/access-token",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({accessToken:x,name:W.trim()||(x.startsWith("aoa")?"Kiro Education Token (aoa)":void 0),region:S.trim()||"us-east-1",profileArn:K.trim()||void 0})});if(!u.ok){const v=await u.json().catch(()=>({}));throw new Error(v.error||"Failed to save Access Token")}t(),n()}catch(u){d(u.message||"Failed to save Access Token")}finally{_(!1)}},X=async()=>{const x=P.trim();if(!x){d("Please paste the External IDP / CLIProxy auth JSON");return}_(!0),d(null);try{const u=await fetch("/api/oauth/kiro/import-cli-proxy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({json:x,name:W.trim()||void 0})});if(!u.ok){const v=await u.json().catch(()=>({}));throw new Error(v.error||"Failed to import External IDP JSON")}t(),n()}catch(u){d(u.message||"Import failed")}finally{_(!1)}},ce=async()=>{if(oe.trim()){_(!0),d(null);try{const x=await fetch("/api/oauth/kiro/api-key",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:oe.trim(),region:ue.trim()||"us-east-1",name:W.trim()||void 0})});if(!x.ok){const u=await x.json().catch(()=>({}));throw new Error(u.error||"Failed to save Kiro API key")}t(),n()}catch(x){d(x.message||"Could not save API key")}finally{_(!1)}}};return l?e.jsx(Be,{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(Le,{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:()=>{j("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:()=>{j("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:()=>{j("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:()=>{j("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:()=>{j("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:()=>{j("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:f?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:f.user_code}),e.jsx("button",{type:"button",onClick:()=>pe(f.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:I?"Copied!":"Copy"})]})]}),e.jsxs("div",{className:"text-center space-y-2 pt-1",children:[e.jsxs("a",{href:f.verification_uri_complete||f.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"})]}),H&&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:()=>{i(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:W,onChange:x=>le(x.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"})]}),c&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:c}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>Q({authMethod:"builder-id",startUrl:"https://view.awsapps.com/start",name:W.trim()||void 0}),disabled:$,className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:$?"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:W,onChange:x=>le(x.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:y,onChange:x=>U(x.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:x=>k(x.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:K,onChange:x=>z(x.target.value),placeholder:"arn:aws:codewhisperer...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white font-mono"})]})]}),c&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:c}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:re,disabled:$||!y.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:$?"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:[B?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:[J&&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:W,onChange:x=>le(x.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:Y,onChange:x=>E(x.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"})]}),M&&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:M,onChange:x=>T(x.target.value),placeholder:"aoaAAAAAG...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white font-mono"})]})]}),c&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:c}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsxs("button",{type:"button",onClick:ve,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:A,disabled:$||!Y.trim()&&!M.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:$?"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:W,onChange:x=>le(x.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:P,onChange:x=>L(x.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]"})]}),c&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:c}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:X,disabled:$||!P.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:$?"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:f?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:f.user_code}),e.jsx("button",{type:"button",onClick:()=>pe(f.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:I?"Copied!":"Copy"})]})]}),e.jsxs("div",{className:"text-center space-y-2 pt-1",children:[e.jsxs("a",{href:f.verification_uri_complete||f.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"})]}),H&&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:()=>{i(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:W,onChange:x=>le(x.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:F,onChange:x=>se(x.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:x=>q(x.target.value),placeholder:"us-east-1",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white font-mono"})]}),c&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:c}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>{if(!F.trim()){d("Please enter your IDC start URL");return}Q({authMethod:"idc",startUrl:F.trim(),region:xe.trim()||"us-east-1",name:W.trim()||void 0})},disabled:$||!F.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:$?"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:W,onChange:x=>le(x.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:oe,onChange:x=>fe(x.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:x=>me(x.target.value),placeholder:"us-east-1",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white font-mono"})]}),c&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:c}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:ce,disabled:$||!oe.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:$?"Saving...":"Save Connection"}),e.jsx("button",{type:"button",onClick:n,className:"rt-btn rt-btn--secondary",children:"Cancel"})]})]})]})}):null};async function _t(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 Rt=({isOpen:l,provider:n,existingModels:t,onAddAccount:h,onClose:j,onApplyModels:f})=>{var $,_;const[i,H]=s.useState(!1),[b,I]=s.useState([]),[g,w]=s.useState(new Set),[y,U]=s.useState(null),[S,k]=s.useState([]),[K,z]=s.useState([]),[Y,E]=s.useState(!1),[M,T]=s.useState(null),[B,ae]=s.useState(""),J=n.modelsUrl||n.baseUrl||"",[te,D]=s.useState(!1),[G,P]=s.useState(J),L=s.useCallback(async c=>{H(!0),T(null),E(!1);try{const d=await _t({providerId:n.id,baseUrl:(c!==void 0?c:G).trim()||void 0});if(d.success){if(I(d.models),U(d.endpointUrl||null),k(d.scannedAccounts||[]),z(d.failedAccounts||[]),E(!1),w(new Set(d.models.map(C=>C.id))),d.models.length>0){const C=d.models.map(Q=>Q.id);C.some(Q=>!t.includes(Q))&&f(C,"merge")}}else I([]),U(null),k([]),z(d.failedAccounts||[]),d.noAccountsConfigured&&E(!0),T(d.error||"Failed to scan models from upstream provider.")}catch(d){const C=d instanceof Error?d.message:String(d);T(C)}finally{H(!1)}},[n.id,G]);s.useEffect(()=>{if(l){const c=n.modelsUrl||n.baseUrl||"";P(c),ae(""),D(!1),k([]),z([]),E(!1),L(c||void 0)}else I([]),w(new Set),T(null),U(null),k([]),z([]),E(!1)},[l,n.id,n.baseUrl,n.modelsUrl,L]);const F=s.useMemo(()=>{let c=b;if(B.trim()){const d=B.toLowerCase();c=b.filter(C=>C.id.toLowerCase().includes(d)||C.name&&C.name.toLowerCase().includes(d)||C.description&&C.description.toLowerCase().includes(d))}return[...c].sort((d,C)=>(d.name||d.id).localeCompare(C.name||C.id,void 0,{sensitivity:"base"}))},[b,B]),se=c=>{const d=new Set(g);d.has(c)?d.delete(c):d.add(c),w(d)},xe=()=>{w(new Set(F.map(c=>c.id)))},q=()=>{w(new Set)},oe=F.length>0&&F.every(c=>g.has(c.id)),fe=F.some(c=>g.has(c.id)),ue=c=>{c?xe():q()},me=c=>{const d=b.filter(C=>g.has(C.id)).map(C=>C.id);f(d,c),j()},W=s.useMemo(()=>b.filter(c=>!t.includes(c.id)).length,[b,t]),le=s.useMemo(()=>b.filter(c=>t.includes(c.id)).length,[b,t]);return e.jsx(Be,{isOpen:l,onClose:j,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(Le,{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:()=>L(),disabled:i,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] ${i?"animate-spin":""}`,children:"sync"}),i?"Scanning...":"Rescan"]})]}),(S.length>0||K.length>0||y)&&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(c=>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:c.name},c.id))]}),K.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:K.length===1?(_=($=K[0])==null?void 0:$.error)!=null&&_.toLowerCase().includes("auth")?"1 account failed to authenticate:":"1 account failed to scan:":K.every(c=>{var d;return(d=c.error)==null?void 0:d.toLowerCase().includes("auth")})?`${K.length} accounts failed to authenticate:`:`${K.length} accounts failed to scan:`}),K.map(c=>e.jsx("span",{title:c.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:c.name},c.id))]}),y&&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:y})]})]}),Y&&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:()=>{j(),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"]})})]}),M&&!Y&&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:M}),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:()=>D(!te),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:te?"expand_less":"expand_more"})]}),te&&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:G,onChange:c=>P(c.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:()=>L(),disabled:i,className:"rt-btn rt-btn--primary text-xs",children:"Apply & Scan"})})]})]}),i&&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"})]})]}),!i&&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:B,onChange:c=>ae(c.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"}),B&&e.jsx("button",{type:"button",onClick:()=>ae(""),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(nt,{size:"sm",checked:oe,indeterminate:fe&&!oe,onChange:ue,label:e.jsx("span",{className:"text-xs font-medium text-slate-300",children:"Select All"})}),e.jsx("button",{type:"button",onClick:q,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:[W," new"]}),e.jsx("span",{children:"•"}),e.jsxs("span",{className:"text-slate-500",children:[le," existing"]})]}),e.jsx("div",{children:e.jsxs("span",{children:["Selected: ",e.jsx("strong",{className:"text-blue-400",children:g.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:F.length===0?e.jsxs("div",{className:"py-6 text-center text-xs text-slate-500",children:['No models match "',B,'"']}):F.map(c=>{var pe,Q;const d=g.has(c.id),C=t.includes(c.id);return e.jsxs("div",{onClick:()=>se(c.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(nt,{size:"sm",checked:d,onChange:()=>se(c.id),onClick:ve=>ve.stopPropagation()}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"font-mono font-medium truncate block",children:c.id}),c.name&&c.name!==c.id&&e.jsx("span",{className:"text-[10px] text-slate-500 truncate block",children:c.name})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[((pe=c.capabilities)==null?void 0:pe.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"}),((Q=c.capabilities)==null?void 0:Q.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"}),C?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"})]})]},c.id)})})]}),!i&&b.length===0&&!M&&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:j,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:g.size===0,onClick:()=>me("replace"),className:"rt-btn rt-btn--secondary text-xs disabled:opacity-40",title:"Replace current provider models list with selected models",children:["Replace Existing (",g.size,")"]}),e.jsxs("button",{type:"button",disabled:g.size===0,onClick:()=>me("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 (",g.size,")"]})]})]})]})})},Wt=({provider:l,onBack:n})=>{var Xe,Ze,et,tt,st,at;const t=ot(l.id),[h,j]=s.useState([]),[f,i]=s.useState([]),H=s.useMemo(()=>[...f].sort((a,r)=>a.localeCompare(r,void 0,{sensitivity:"base"})),[f]),[b,I]=s.useState((t==null?void 0:t.models)||[]),[g,w]=s.useState(null),[y,U]=s.useState("1"),[S,k]=s.useState(!1),[K,z]=s.useState((t==null?void 0:t.thinkingMode)||"auto"),[Y,E]=s.useState((t==null?void 0:t.thinkingOptions)||["auto","none","low","medium","high"]),[M,T]=s.useState(l.format||(t==null?void 0:t.format)||"openai"),[B,ae]=s.useState([]),[J,te]=s.useState((t==null?void 0:t.baseUrl)||l.baseUrl||""),[D,G]=s.useState(""),[P,L]=s.useState([]),[F,se]=s.useState(!1),[xe,q]=s.useState(!1),[oe,fe]=s.useState(!1),[ue,me]=s.useState(!1),[W,le]=s.useState(!1),[$,_]=s.useState(!1),[c,d]=s.useState(!1),[C,pe]=s.useState(""),[Q,ve]=s.useState(null),[A,re]=s.useState(null),[X,ce]=s.useState({}),[x,u]=s.useState(!1),[v,he]=s.useState(!1),[R,Z]=s.useState(null),[V,Se]=s.useState(""),[be,ge]=s.useState(""),[we,je]=s.useState(null),[Ee,de]=s.useState(null),[Ue,ke]=s.useState(!1),[Fe,Oe]=s.useState(!1),[Pe,_e]=s.useState(null),[ee,Re]=s.useState(null),[De,He]=s.useState(""),$e=l.category==="custom"||!t,Te=(t==null?void 0:t.authType)==="cookie"||(t==null?void 0:t.category)==="webCookie"||l.category==="webCookie",Ne=!Te&&(lt(t)||lt(l)),We=!Te&&(Array.isArray(t==null?void 0:t.authModes)?t.authModes.includes("apikey"):!!((t==null?void 0:t.category)==="apikey"||(Xe=t==null?void 0:t.notice)!=null&&Xe.apiKeyUrl||l.category==="apikey"&&!["antigravity","cursor","github","kiro"].includes(l.id))),Me=()=>{if(l.id==="github"){fe(!0);return}if(l.id==="cursor"){me(!0);return}if(l.id==="kiro"){le(!0);return}q(!0)},m=s.useCallback(()=>{k(!1);const a=(t==null?void 0:t.defaultHeaders)||{},r=Object.entries(a).map(([o,N])=>({key:o,value:String(N)})),p=((t==null?void 0:t.models)||[]).map(o=>o.id);fetch(`/api/providers/${l.id}`).then(o=>{if(!o.ok)throw new Error(`HTTP ${o.status}`);return o.json()}).then(o=>{o.format&&T(o.format),Array.isArray(o.supportedFormats)&&o.supportedFormats.length>0?ae(o.supportedFormats.map(O=>typeof O=="string"?{value:O,label:O.toUpperCase()}:O)):Array.isArray(t==null?void 0:t.supportedFormats)&&t.supportedFormats.length>0?ae(t.supportedFormats.map(O=>typeof O=="string"?{value:O,label:O.toUpperCase()}:O)):ae([]),o.baseUrl&&te(o.baseUrl),o.proxyUrl&&G(o.proxyUrl),o.thinkingMode&&z(o.thinkingMode),Array.isArray(o.thinkingOptions)&&o.thinkingOptions.length>0&&E(o.thinkingOptions),o.strategy!==void 0&&w(o.strategy||null),o.stickyLimit!=null&&U(String(o.stickyLimit)),k(!0);const N=o.userCustomHeaders!==void 0?o.userCustomHeaders:o.customHeaders||{};N&&Object.keys(N).length>0?L(Object.entries(N).map(([O,ye])=>({key:O,value:String(ye)}))):L([]),Array.isArray(o.catalogModels)&&o.catalogModels.length>0&&I(o.catalogModels),Array.isArray(o.models)&&o.models.length>0?i(o.models):i(p),o.accounts&&o.accounts.length>0?j(o.accounts.map((O,ye)=>{var Ie;return{id:O.id,name:O.name,tag:O.tag||((Ie=O.providerSpecificData)==null?void 0:Ie.tag),supportedModelsCount:O.supportedModelsCount,isActive:O.isActive,order:O.sortOrder??ye,providerSpecificData:O.providerSpecificData}})):j([]),Ae()}).catch(()=>{L(r),i(p),j([])})},[l.id,l.name,t]);s.useEffect(()=>{m()},[m]);const ne=async(a,r,p,o)=>{try{const N=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})});if(!N.ok)throw new Error(`HTTP ${N.status}`);k(!0)}catch(N){console.warn("Failed to save provider strategy:",N),w(p),U(o)}},ie=async a=>{const r=h.map(p=>p.id===a?{...p,isActive:!p.isActive}:p);j(r);try{await fetch(`/api/providers/${l.id}/accounts/${a}/toggle`,{method:"PUT"}),Ae()}catch{}},Ce=(a,r)=>{if(r==="up"&&a===0||r==="down"&&a===h.length-1)return;const p=r==="up"?a-1:a+1,o=[...h],N=o[a];o[a]=o[p],o[p]=N;const O=o.map((ye,Ie)=>({...ye,order:Ie}));j(O),fetch(`/api/providers/${l.id}/accounts/reorder`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({accountIds:O.map(ye=>ye.id)})}).then(ye=>{ye.ok||console.error("Failed to reorder accounts:",ye.status),Ae()}).catch(ye=>{console.error("Failed to reorder accounts:",ye)})},Ke=a=>{j(h.filter(r=>r.id!==a)),fetch(`/api/providers/${l.id}/accounts/${a}`,{method:"DELETE"}).then(()=>Ae()).catch(()=>{})},rt=a=>{_e({id:a.id,providerId:l.id,name:a.name,isActive:a.isActive,providerSpecificData:a.providerSpecificData})},it=async a=>{if(!Pe)return;const r=await fetch(`/api/providers/${l.id}/accounts/${Pe.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!r.ok){const p=await r.json().catch(()=>({}));throw new Error(p.error||"Failed to update account.")}m(),Ae()},Je=async(a,r)=>{r!==void 0&&ve(r),re(a.id);try{const o=await(await fetch(`/api/providers/${l.id}/accounts/${a.id}/test`,{method:"POST"})).json();ce(N=>({...N,[a.id]:{success:!!o.success,message:o.message||(o.success?"Connection verified":"Connection failed"),latencyMs:o.latencyMs}}))}catch(p){ce(o=>({...o,[a.id]:{success:!1,message:p.message||"Failed to reach gateway"}}))}finally{r!==void 0&&ve(null),re(null)}},ct=async()=>{if(!(v||h.length===0)){he(!0);try{for(let a=0;a<h.length;a++){const r=h[a];await Je(r,a)}}finally{ve(null),he(!1)}}},Ve=async()=>{u(!0),Z(null);try{const r=await(await fetch(`/api/providers/${l.id}/test`,{method:"POST"})).json();Z({success:!!r.success,message:r.message||(r.success?"Connection successful!":"Connection failed."),latencyMs:r.latencyMs})}catch(a){Z({success:!1,message:`Error testing connection: ${a.message}`})}finally{u(!1)}},dt=()=>{V.trim()&&(L([...P,{key:V.trim(),value:be.trim()}]),Se(""),ge(""))},Ge=a=>{L(P.filter((r,p)=>p!==a))},qe=(a,r,p)=>{const o=[...P];o[a]={key:r,value:p},L(o)},xt=()=>{L([]),je("Reset custom headers. Using system defaults."),setTimeout(()=>je(null),3e3)},ut=(a,r)=>{P.findIndex(o=>o.key.trim().toLowerCase()===a.toLowerCase())>=0||L([...P,{key:a,value:r}])},mt=a=>{L(P.filter(r=>r.key.trim().toLowerCase()!==a.toLowerCase()))},pt=a=>{const r=P.filter(p=>p.key.trim().toLowerCase()!==a.toLowerCase());L([...r,{key:a,value:""}])},ht=a=>{L(P.filter(r=>r.key.trim().toLowerCase()!==a.toLowerCase()))},bt=()=>{if(!C.trim())return;const a=C.trim();f.includes(a)||i([...f,a]),pe(""),_(!1)},ft=a=>{i(f.filter(r=>r!==a))},gt=async(a,r)=>{let p;if(r==="replace")p=a;else{const N=new Set(f),O=a.filter(ye=>!N.has(ye));p=[...f,...O]}i(p);const o={};P.forEach(N=>{N.key.trim()&&(o[N.key.trim()]=N.value.trim())});try{await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:l.id,name:l.name,baseUrl:J||l.baseUrl||(t==null?void 0:t.baseUrl)||"https://api.openai.com",format:M||l.format||(t==null?void 0:t.format)||"openai",customHeaders:o,proxyUrl:D.trim()||void 0,thinkingMode:K,...S?{strategy:g,stickyLimit:g==="round-robin"?Number(y)||1:null}:{},models:p})}),je(`Saved ${p.length} models for ${l.name}.`),Ae(),m(),setTimeout(()=>je(null),3e3)}catch{}},jt=a=>{navigator.clipboard.writeText(a),de(a),setTimeout(()=>{de(r=>r===a?null:r)},2e3)},Ye=async()=>{const a={};P.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:J||l.baseUrl||(t==null?void 0:t.baseUrl)||"https://api.openai.com",format:M||l.format||(t==null?void 0:t.format)||"openai",customHeaders:a,proxyUrl:D.trim()||void 0,thinkingMode:K,...S?{strategy:g,stickyLimit:g==="round-robin"?Number(y)||1:null}:{},models:f})}),je("Configuration saved successfully."),Ae(),setTimeout(()=>je(null),3e3)}catch{}},yt=async()=>{Oe(!0);try{(await fetch(`/api/providers/${l.id}`,{method:"DELETE"})).ok&&(Ae(),n())}catch{}finally{Oe(!1),ke(!1)}},Qe=((Ze=t==null?void 0:t.notice)==null?void 0:Ze.apiKeyUrl)||((et=t==null?void 0:t.notice)==null?void 0:et.signupUrl)||(t==null?void 0:t.website),vt=(tt=t==null?void 0:t.notice)!=null&&tt.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(Le,{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"}),Qe&&e.jsxs("a",{href:Qe,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"}),vt]})]}),e.jsxs("span",{className:"text-xs text-slate-400 font-mono",children:[h.length," connection",h.length===1?"":"s"," • ",f.length," available models"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:Ve,disabled:x,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] ${x?"animate-spin text-blue-400":""}`,children:x?"sync":"speed"}),x?"Testing...":"Test Connection"]}),e.jsxs("button",{onClick:Ye,className:"rt-btn rt-btn--primary",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"save"}),"Save Provider Settings"]})]})]})]}),R&&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 ${R.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:R.success?"check_circle":"error"}),e.jsx("span",{className:"truncate",children:R.message})]}),R.latencyMs&&e.jsxs("span",{className:"shrink-0 font-bold opacity-80",children:[R.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."})]}),((st=t==null?void 0:t.notice)==null?void 0:st.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:Ve,disabled:x,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] ${x?"animate-spin":""}`,children:x?"sync":"speed"}),x?"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:ct,disabled:v||Q!==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] ${v||Q!==null?"animate-spin text-blue-400":""}`,children:"sync"}),v?"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(ze,{value:g||"",onChange:a=>{const r=g,p=y,o=a||null;w(o);const N=o==="round-robin"?y||"1":y;o==="round-robin"&&!y&&U("1"),ne(o,N,r,p)},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"}),g==="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=y,p=a.target.value;U(p),ne("round-robin",p,g,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 p=X[a.id],o=Q===r||A===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:()=>Ce(r,"up"),disabled:r===0,className:"hover:text-white disabled:opacity-30 leading-none cursor-pointer",children:"▲"}),e.jsx("button",{onClick:()=>Ce(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:()=>{Re({accountId:a.id,accountName:a.name,models:[],scanned:!0,loading:!0}),He(""),fetch(`/api/providers/${l.id}/accounts/${a.id}/models`).then(N=>N.json()).then(N=>{Re(O=>O&&O.accountId===a.id?{...O,models:N.models||[],scanned:!!N.scanned,loading:!1}:O)}).catch(()=>{Re(N=>N&&N.accountId===a.id?{...N,loading:!1}:N)})},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>=(f.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>=(f.length||1)?"check_circle":"tune"}),a.supportedModelsCount," / ",f.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]}),o&&e.jsx("span",{className:"text-[10px] text-blue-400 animate-pulse font-mono",children:"Testing upstream..."}),p&&!o&&e.jsx("span",{className:`rt-badge text-[10px] ${p.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:p.message,children:p.success?`● ${p.latencyMs?`${p.latencyMs}ms`:"Active"}`:"● Failed"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{title:"Test this connection",onClick:()=>Je(a,r),disabled:Q!==null||o,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] ${o?"animate-spin text-blue-400":""}`,children:o?"sync":"speed"})}),e.jsx("button",{title:"Edit account",onClick:()=>rt(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:()=>Ke(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:()=>ie(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"})]})]})]}),p&&e.jsx("div",{className:`w-full py-1 px-2.5 text-[10px] font-mono rounded-lg border truncate ${p.success?"bg-emerald-500/10 text-emerald-400 border-emerald-500/20":"bg-red-500/10 text-red-400 border-red-500/20"}`,title:p.message,children:p.success?`✓ ${p.message}`:`✗ ${p.message}`})]},a.id)})}),Ne&&We?e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsxs("button",{onClick:Me,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:()=>se(!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)?Me():se(!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":Te?"cookie":"add"}),Ne||l.id==="github"||l.id==="cursor"||l.id==="kiro"?`Connect ${l.name}`:Te?"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:xt,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:Ye,className:"rt-btn rt-btn--primary text-xs",title:"Save headers",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"save"}),"Save"]})]})]}),we&&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"}),we]}),(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 p=P.find(O=>O.key.trim().toLowerCase()===a.toLowerCase()),o=p!==void 0&&p.value==="",N=p!==void 0&&p.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:o?"text-slate-600 line-through":"text-blue-400 font-semibold",children:a}),e.jsx("span",{className:"text-slate-600",children:":"}),e.jsx("span",{className:o||N?"text-slate-500 line-through truncate":"text-slate-300 truncate",children:r}),N&&e.jsxs("span",{className:"text-amber-300 font-semibold truncate",children:["→ ",p==null?void 0:p.value]})]}),e.jsx("div",{className:"flex items-center gap-2 shrink-0",children:o?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:()=>ht(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"]})]}):N?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:()=>mt(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:()=>ut(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:()=>pt(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:[P.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:P.map((a,r)=>{const p=!!(t!=null&&t.defaultHeaders&&Object.keys(t.defaultHeaders).some(N=>N.toLowerCase()===a.key.trim().toLowerCase())),o=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:N=>qe(r,N.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 ${o?"text-slate-500 line-through":"text-blue-400"}`,placeholder:"Header Key"}),p&&e.jsx("span",{className:`absolute right-2 top-2 text-[10px] font-sans pointer-events-none font-semibold ${o?"text-rose-400":"text-amber-400"}`,children:o?"Disabled":"Override"})]}),o?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:()=>Ge(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:N=>qe(r,a.key,N.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:()=>Ge(r),className:"p-2 text-slate-500 hover:text-red-400 transition-colors cursor-pointer rounded-lg hover:bg-red-500/10",title:o?"Re-enable header":p?"Remove override (reverts to default)":"Delete header",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:o||p?"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:V,onChange:a=>Se(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:be,onChange:a=>ge(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:dt,className:"rt-btn rt-btn--secondary text-xs shrink-0",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"add"}),"Add Header"]})]})]}),B.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(ze,{value:M,onChange:T,options:B,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!==J&&e.jsxs("button",{type:"button",onClick:()=>te(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:J,onChange:a=>te(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:D,onChange:a=>G(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:["(",f.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(ze,{value:K,onChange:z,options:Y.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:()=>d(!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:()=>_(!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:H.map(a=>{const r=b.find(o=>o.id===a),p=Ee===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:()=>jt(a),title:p?"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] ${p?"text-emerald-400 font-bold":""}`,children:p?"check":"content_copy"})}),e.jsx("button",{onClick:()=>ft(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)})})]}),$e&&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:()=>ke(!0),disabled:Fe,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"}),Fe?"Deleting...":"Delete Provider"]})]})}),F&&e.jsx(Dt,{isOpen:F,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:(at=t==null?void 0:t.notice)==null?void 0:at.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,supportsAutoImport:t==null?void 0:t.supportsAutoImport,autoImportHint:t==null?void 0:t.autoImportHint},existingNames:h.map(a=>a.name),onClose:()=>se(!1),onSuccess:m,onOpenOAuth:Ne?()=>{se(!1),Me()}:void 0}),oe&&e.jsx(Tt,{isOpen:oe,onClose:()=>fe(!1),onSuccess:m}),ue&&e.jsx(Bt,{isOpen:ue,onClose:()=>me(!1),onSuccess:m}),W&&e.jsx(Pt,{isOpen:W,onClose:()=>le(!1),onSuccess:m}),xe&&e.jsx(At,{isOpen:xe,providerId:l.id,providerName:l.name,onSuccess:m,onClose:()=>q(!1)}),e.jsx(Be,{isOpen:$,onClose:()=>_(!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:C,onChange:a=>pe(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:()=>_(!1),className:"px-4 py-2 text-xs text-slate-400 cursor-pointer",children:"Cancel"}),e.jsx("button",{onClick:bt,className:"rt-btn rt-btn--primary",children:"Add Model"})]})]})}),e.jsx(Rt,{isOpen:c,provider:{id:l.id,name:l.name,baseUrl:J||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:f,accountsCount:h.length,onAddAccount:()=>{d(!1),Ne||["github","cursor","kiro","antigravity"].includes(l.id)?Me():se(!0)},onClose:()=>d(!1),onApplyModels:gt}),e.jsx(kt,{isOpen:!!Pe,account:Pe,onClose:()=>_e(null),onSave:it}),e.jsx(Be,{isOpen:!!ee,onClose:()=>Re(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:ee==null?void 0:ee.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:[(ee==null?void 0:ee.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:De,onChange:a=>He(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:ee!=null&&ee.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..."]}):(ee==null?void 0:ee.models.length)===0?e.jsx("div",{className:"py-8 text-center text-slate-500",children:"No specific models registered for this account yet."}):[...(ee==null?void 0:ee.models)||[]].filter(a=>!De||a.toLowerCase().includes(De.toLowerCase())).sort((a,r)=>a.localeCompare(r,void 0,{sensitivity:"base"})).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:()=>Re(null),className:"rt-btn rt-btn--secondary text-xs",children:"Close"})})]})}),$e&&e.jsx(Ct,{isOpen:Ue,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:yt,onCancel:()=>ke(!1)})]})};export{Wt as ProviderDetailPage};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ProvidersTab-CwJo_EUX.js","assets/vendor-BcOI2aZ9.js","assets/ConfirmModal-CMfDss7P.js","assets/ModelAutocompleteInput-DEb_clZC.js","assets/metadataRegistry-FuJXbCt4.js","assets/ToolIcon-Cp4gSgFt.js","assets/providersData-Y57rBt5o.js","assets/lucide-Cc35htxl.js","assets/ProviderDetailPage-BIfOQupC.js","assets/Select-BNRH8LIG.js","assets/EditAccountModal-OrvqLLBP.js","assets/CombosTab-EWUYC3TU.js","assets/dnd-kit-DecqzwfZ.js","assets/UsageTab-85tTb2_C.js","assets/recharts-X4_nm3od.js","assets/QuotaTab-PFvP6yAb.js","assets/CliToolsTab-D_MUwimj.js","assets/MitmTab-C7g7GUXW.js","assets/EndpointTab-BwtzqXUN.js","assets/TokenSaverTab-B3Fbu_yc.js","assets/ConsoleLogTab-BSMXSYrR.js","assets/SettingsTab-DwAbjIW3.js","assets/CallbackPage-DBsxnmPi.js"])))=>i.map(i=>d[i]);
2
- import{d as A,j as e,r as m,a as J,e as Y,R as X}from"./vendor-BcOI2aZ9.js";import{G as H}from"./lucide-Cc35htxl.js";(function(){const r=document.createElement("link").relList;if(r&&r.supports&&r.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))t(n);new MutationObserver(n=>{for(const o of n)if(o.type==="childList")for(const l of o.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&t(l)}).observe(document,{childList:!0,subtree:!0});function s(n){const o={};return n.integrity&&(o.integrity=n.integrity),n.referrerPolicy&&(o.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?o.credentials="include":n.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function t(n){if(n.ep)return;n.ep=!0;const o=s(n);fetch(n.href,o)}})();const Z="modulepreload",ee=function(a){return"/"+a},z={},y=function(r,s,t){let n=Promise.resolve();if(s&&s.length>0){let l=function(i){return Promise.all(i.map(c=>Promise.resolve(c).then(p=>({status:"fulfilled",value:p}),p=>({status:"rejected",reason:p}))))};document.getElementsByTagName("link");const x=document.querySelector("meta[property=csp-nonce]"),d=(x==null?void 0:x.nonce)||(x==null?void 0:x.getAttribute("nonce"));n=l(s.map(i=>{if(i=ee(i),i in z)return;z[i]=!0;const c=i.endsWith(".css"),p=c?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${i}"]${p}`))return;const h=document.createElement("link");if(h.rel=c?"stylesheet":Z,c||(h.as="script"),h.crossOrigin="",h.href=i,d&&h.setAttribute("nonce",d),document.head.appendChild(h),c)return new Promise((u,b)=>{h.addEventListener("load",u),h.addEventListener("error",()=>b(new Error(`Unable to preload CSS for ${i}`)))})}))}function o(l){const x=new Event("vite:preloadError",{cancelable:!0});if(x.payload=l,window.dispatchEvent(x),!x.defaultPrevented)throw l}return n.then(l=>{for(const x of l||[])x.status==="rejected"&&o(x.reason);return r().catch(o)})},T=20128,R="127.0.0.1",te=`http://${R}:${T}`,Se=`${te}/v1`,_=A(a=>({info:null,loading:!1,fetchSystemInfo:async()=>{try{a({loading:!0});const r=await fetch("/api/settings/system-info");if(r.ok){const s=await r.json(),t=typeof window<"u"&&window.location.port?Number(window.location.port):void 0,n=s.port||(t&&t!==5173?t:T),o=s.host||(typeof window<"u"&&window.location.hostname?window.location.hostname:R),l={dataDir:s.dataDir||"",dbPath:s.dbPath||"",isDevelopmentMode:!!s.isDevelopmentMode,appName:s.appName||"Mapigate",version:s.version||"",port:n,host:o,configuredHost:s.configuredHost||o,configuredPort:s.configuredPort||n,isRestartRequired:!!s.isRestartRequired};return a({info:l,loading:!1}),(async()=>{try{const x=await fetch("/api/settings/version");if(x.ok){const d=await x.json();a(i=>i.info?{...i,info:{...i.info,latestVersion:d.latestVersion,hasUpdate:!!d.hasUpdate}}:i)}}catch{}})(),l}}catch{}return a({loading:!1}),null},checkForUpdate:async()=>{try{const r=await fetch("/api/settings/version?force=true");if(r.ok){const s=await r.json();a(t=>t.info?{...t,info:{...t.info,latestVersion:s.latestVersion,hasUpdate:!!s.hasUpdate}}:t)}}catch{}}})),se=({currentTab:a,onSelectTab:r,onUpgradeClick:s})=>{const t=_(d=>d.info),n=t==null?void 0:t.version,o=(t==null?void 0:t.port)||(typeof window<"u"&&window.location.port&&window.location.port!=="5173"?Number(window.location.port):T),l=(t==null?void 0:t.host)||(typeof window<"u"&&window.location.hostname?window.location.hostname:R),x=[{id:"endpoint",label:"Endpoint & Key",icon:"api"},{id:"providers",label:"Providers",icon:"dns"},{id:"combos",label:"Combo & Vision Adapter",icon:"layers"},{id:"usage",label:"Usage & Analytics",icon:"bar_chart"},{id:"quota",label:"Quota Tracker",icon:"data_usage"},{id:"tokensaver",label:"Token Saver",icon:"savings"},{id:"clitools",label:"Tools & Mappings",icon:"widgets"},{id:"mitm",label:"MITM Proxy",icon:"alt_route"}];return e.jsxs("aside",{className:"rt-sidebar",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"rt-sidebar__brand pt-5 pr-4 flex items-center gap-3",children:[e.jsx("div",{className:"rt-sidebar__brand-icon shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"graph_5"})}),e.jsxs("div",{className:"flex flex-col flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("h1",{className:"text-sm font-bold tracking-tight text-white leading-none truncate",children:"Mapigate"}),n&&(t!=null&&t.hasUpdate&&t.latestVersion?e.jsxs("button",{type:"button",onClick:()=>s==null?void 0:s(),className:"group relative inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-md bg-amber-500/15 text-amber-300 border border-amber-500/35 font-mono font-semibold shrink-0 select-none leading-none hover:bg-amber-500/25 transition-all cursor-pointer",title:`New version v${t.latestVersion} available! Click to upgrade`,children:[e.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-amber-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5 bg-amber-500"})]}),e.jsxs("span",{children:["v",n]}),e.jsx("span",{className:"text-[9px] text-amber-400 group-hover:translate-y-[-0.5px] transition-transform",children:"↑"})]}):e.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 rounded-md bg-blue-500/15 text-blue-300 border border-blue-500/30 font-mono font-semibold shrink-0 shadow-xs select-none leading-none",title:`Mapigate Version v${n}`,children:["v",n]}))]}),e.jsx("span",{className:"text-[11px] text-slate-400 leading-normal mt-1 truncate",children:"AI Model API Gateway"})]})]}),e.jsx("nav",{className:"px-3 pt-3 space-y-1",children:x.map(d=>{const i=a===d.id;return e.jsxs("button",{onClick:()=>r(d.id),className:`rt-sidebar__nav-item ${i?"rt-sidebar__nav-item--active":""}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:d.icon}),e.jsx("span",{children:d.label})]},d.id)})}),e.jsx("div",{className:"px-5 pt-6 pb-2",children:e.jsx("span",{className:"text-[10px] font-bold text-slate-500 tracking-wider uppercase",children:"SYSTEM PREFERENCES"})}),e.jsxs("nav",{className:"px-3 space-y-1",children:[e.jsxs("button",{onClick:()=>r("consolelog"),className:`rt-sidebar__nav-item ${a==="consolelog"?"rt-sidebar__nav-item--active":""}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"terminal"}),e.jsx("span",{children:"Console Log"})]}),e.jsxs("button",{onClick:()=>r("settings"),className:`rt-sidebar__nav-item ${a==="settings"?"rt-sidebar__nav-item--active":""}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"tune"}),e.jsx("span",{children:"Settings"})]})]})]}),e.jsxs("div",{className:"p-4 border-t border-[#1E293B] space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs text-slate-400 bg-[#111827] px-3.5 py-2.5 rounded-xl border border-[#1E293B] shadow-inner",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"rt-beacon size-2 bg-emerald-400"}),e.jsxs("span",{className:"font-semibold text-slate-200",children:["Port ",o]})]}),e.jsx("span",{className:"text-[10px] text-blue-300 font-mono bg-blue-500/10 px-1.5 py-0.5 rounded border border-blue-500/20",children:l})]}),e.jsxs("a",{href:"https://github.com/joutvhu/mapigate",target:"_blank",rel:"noreferrer",title:"Mapigate on GitHub (joutvhu/mapigate)",className:"flex items-center justify-center gap-2 w-full py-1.5 px-3 rounded-xl bg-[#111827]/60 hover:bg-white/5 border border-[#1E293B]/60 hover:border-[#1E293B] text-[11px] font-medium text-slate-400 hover:text-white transition-all cursor-pointer",children:[e.jsx(H,{className:"size-3.5 text-slate-400"}),e.jsx("span",{children:"GitHub · joutvhu/mapigate"})]})]})]})},E="mapigate_auth_token";let $=!1;const P=new Set;function ae(a){return P.add(a),()=>{P.delete(a)}}function q(){for(const a of P)try{a()}catch{}}class w{static getToken(){if(typeof window>"u")return null;try{return localStorage.getItem(E)}catch{return null}}static setToken(r){if(!(typeof window>"u"))try{localStorage.setItem(E,r)}catch{}}static removeToken(){if(!(typeof window>"u"))try{localStorage.removeItem(E)}catch{}}static async checkStatus(){try{const r=this.getToken(),s={};r&&(s.Authorization=`Bearer ${r}`);const t=await fetch("/api/auth/status",{headers:s});if(!t.ok)return{enabled:!1,authenticated:!0};const n=await t.json();return{enabled:!!n.enabled,authenticated:!!n.authenticated}}catch{return{enabled:!1,authenticated:!0}}}static async login(r){try{const s=await fetch("/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:r})}),t=await s.json();return s.ok&&t.success?(t.token&&this.setToken(t.token),{success:!0,token:t.token}):{success:!1,error:t.error||"Invalid master password"}}catch(s){return{success:!1,error:s.message||"Failed to authenticate"}}}static async logout(){try{await fetch("/api/auth/logout",{method:"POST"})}catch{}this.removeToken(),q()}static async setup(r){try{const s=await fetch("/api/auth/setup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:r})}),t=await s.json();return s.ok&&t.success?(t.token&&this.setToken(t.token),{success:!0,token:t.token}):{success:!1,error:t.error||"Failed to setup master password"}}catch(s){return{success:!1,error:s.message||"Failed to setup master password"}}}static async changePassword(r,s){try{const t=await fetch("/api/auth/change-password",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({currentPassword:r,newPassword:s})}),n=await t.json();return t.ok&&n.success?(n.token&&this.setToken(n.token),{success:!0,token:n.token}):{success:!1,error:n.error||"Failed to change master password"}}catch(t){return{success:!1,error:t.message||"Failed to change master password"}}}static async removePassword(r){try{const s=await fetch("/api/auth/remove-password",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({currentPassword:r})}),t=await s.json();return s.ok&&t.success?(this.removeToken(),{success:!0}):{success:!1,error:t.error||"Failed to remove master password"}}catch(s){return{success:!1,error:s.message||"Failed to remove master password"}}}}function re(){if(typeof window>"u"||$)return;$=!0;const a=window.fetch.bind(window);window.fetch=async(r,s)=>{let t="";typeof r=="string"?t=r:r instanceof URL?t=r.toString():r&&typeof r.url=="string"&&(t=r.url);const n=t.startsWith("/api/")||t.includes("/api/"),o=t.includes("/api/auth/status")||t.includes("/api/auth/login");let l=s;const x=w.getToken();if(n&&x){const i=new Headers((s==null?void 0:s.headers)||(r instanceof Request?r.headers:void 0));i.has("Authorization")||i.set("Authorization",`Bearer ${x}`),l={...s,headers:i}}const d=await a(r,l);if(n&&!o&&d.status===401)try{const c=await d.clone().json();c&&c.code==="AUTH_REQUIRED"&&q()}catch{}return d}}re();const j=A((a,r)=>({isChecking:!0,isPasswordSet:!1,isAuthenticated:!0,isLocked:!1,checkAuth:async()=>{a({isChecking:!0});try{const s=await w.checkStatus();if(!s.enabled){a({isChecking:!1,isPasswordSet:!1,isAuthenticated:!0,isLocked:!1});return}a({isChecking:!1,isPasswordSet:!0,isAuthenticated:s.authenticated,isLocked:!s.authenticated})}catch{a({isChecking:!1,isPasswordSet:!1,isAuthenticated:!0,isLocked:!1})}},login:async s=>{const t=await w.login(s);return t.success?(a({isAuthenticated:!0,isLocked:!1}),{success:!0}):{success:!1,error:t.error}},logout:async()=>{await w.logout();const s=r().isPasswordSet;a({isAuthenticated:!s,isLocked:s})},lock:()=>{r().isPasswordSet&&(w.removeToken(),a({isAuthenticated:!1,isLocked:!0}))},unlock:s=>{w.setToken(s),a({isAuthenticated:!0,isLocked:!1})}}));typeof window<"u"&&(ae(()=>{j.getState().lock()}),window.addEventListener("storage",a=>{(a.key===E||a.key===null)&&(w.getToken()?j.setState({isAuthenticated:!0,isLocked:!1}):j.getState().isPasswordSet&&j.setState({isAuthenticated:!1,isLocked:!0}))}));const F=A(a=>({status:null,loading:!1,fetchStatus:async()=>{try{a({loading:!0});const r=await fetch("/api/mitm/status");if(r.ok){const s=await r.json(),t=s.dnsStatus||{},n=Object.entries(t).filter(([l,x])=>!!x).map(([l])=>l),o={running:!!s.running,port:Number(s.port)||443,certExists:!!s.certExists,certTrusted:!!s.certTrusted,dnsStatus:t,orphanedDns:!!s.orphanedDns,activeDnsCount:n.length,activeDnsTools:n};return a({status:o,loading:!1}),o}}catch{}return a({loading:!1}),null}})),ne={antigravity:"Antigravity",kiro:"Kiro",copilot:"GitHub Copilot",cursor:"Cursor"};function V(a){return!a||a.length===0?"":a.map(r=>ne[r]||r.charAt(0).toUpperCase()+r.slice(1)).join(", ")}const G={endpoint:{title:"Endpoint & Key",subtitle:"Manage your local AI gateway endpoint and master keys",icon:"api"},providers:{title:"Providers",subtitle:"Manage your AI provider connections and encrypted API credentials",icon:"dns"},combos:{title:"Combos & Adapter",subtitle:"Group models under smart fallback and load-balancing combos",icon:"layers"},usage:{title:"Usage & Analytics",subtitle:"Real-time token metrics, savings analysis, and interactive routing topology",icon:"bar_chart"},quota:{title:"Quota Tracker",subtitle:"Track rate limits and multi-account sliding quota reset times",icon:"data_usage"},tokensaver:{title:"Token Saver",subtitle:"Lossless context optimization saving 20-40% input tokens",icon:"savings"},clitools:{title:"Tools & Mappings",subtitle:"One-click connection setups and universal model rewrite rules for AI assistants, IDEs & tools",icon:"widgets"},mitm:{title:"MITM Proxy",subtitle:"Intercept CLI & IDE tool traffic (Antigravity, Kiro, Copilot) via local Root CA",icon:"alt_route"},consolelog:{title:"Console Log",subtitle:"Live gateway server stdout, request streaming events, and system logs",icon:"terminal"},settings:{title:"Settings",subtitle:"Local SQLite database, hardware encryption vault, and system preferences",icon:"tune"}},oe=({currentTab:a,searchQuery:r,onSearchChange:s,detailProvider:t,onBackToProviders:n,onRestartClick:o,onSelectTab:l})=>{const x=G[a]||G.providers,d=j(v=>v.isPasswordSet),i=j(v=>v.lock),c=_(v=>v.info),p=_(v=>v.fetchSystemInfo);c==null||c.version;const h=F(v=>v.status),u=F(v=>v.fetchStatus);m.useEffect(()=>{u(),p();const v=setInterval(()=>{document.hidden||(u(),p())},1e4),U=()=>{u(),p()};return window.addEventListener("focus",U),()=>{clearInterval(v),window.removeEventListener("focus",U)}},[u,p]);const b=!!(h!=null&&h.running),g=(h==null?void 0:h.port)||443,f=(h==null?void 0:h.activeDnsCount)||0,M=(h==null?void 0:h.activeDnsTools)||[],W=!!(h!=null&&h.orphanedDns),S=(c==null?void 0:c.host)||"127.0.0.1",L=(c==null?void 0:c.configuredHost)||S,D=!!(c!=null&&c.isRestartRequired),C=S==="0.0.0.0";let I=C?`Network: LAN Active (0.0.0.0:${(c==null?void 0:c.port)||T}) • Accessible from local network • Click to configure Endpoint`:`Network: Local Only (127.0.0.1:${(c==null?void 0:c.port)||T}) • Isolated to this machine • Click to configure Endpoint`,B=C?"bg-emerald-500/10 text-emerald-400 border-emerald-500/20 hover:bg-emerald-500/20":"bg-blue-500/10 text-blue-400 border-blue-500/20 hover:bg-blue-500/20",O=C?"wifi":"shield";D&&(I=`⚠️ Restart Required: Configured for ${L==="0.0.0.0"?"LAN Active":"Local Only"} (${L}), but running on ${S}. Click Restart button to apply.`,B="bg-amber-500/15 text-amber-300 border-amber-500/30 hover:bg-amber-500/25 animate-pulse",O="restart_alt");let N="MITM Proxy: Stopped • Click to open settings",k="text-slate-500 hover:text-slate-300";return W?(N=`⚠️ MITM Warning: Server stopped but ${f} DNS redirect(s) still active (${V(M)})! Tools cannot connect. Click to fix.`,k="text-amber-400 hover:text-amber-300 animate-pulse"):b?f>0?(N=`MITM Proxy: Active on port ${g} • ${f} tool DNS active (${V(M)}) • Click to manage`,k="text-emerald-400 hover:text-emerald-300"):(N=`MITM Proxy: Running on port ${g} (Idle, 0 tool DNS active) • Click to configure`,k="text-blue-400 hover:text-blue-300"):(N="MITM Proxy: Stopped • Click to open settings",k="text-slate-500 hover:text-slate-300"),e.jsxs("header",{className:"rt-header",children:[e.jsxs("div",{className:"flex items-center gap-3.5 min-w-0",children:[e.jsx("div",{className:"rt-header__icon-box",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:x.icon})}),e.jsxs("div",{className:"flex flex-col min-w-0",children:[a==="providers"&&t?e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("button",{type:"button",onClick:n,className:"text-sm font-bold text-slate-400 hover:text-white flex items-center gap-1 cursor-pointer transition-colors",title:"Back to Providers",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"arrow_back"}),"Providers"]}),e.jsx("span",{className:"text-slate-600 text-xs",children:"/"}),e.jsx("h2",{className:"text-sm font-bold text-white tracking-tight leading-tight",children:t.name})]}):e.jsx("h2",{className:"text-sm font-bold text-white tracking-tight leading-tight",children:x.title}),e.jsx("p",{className:"text-[11px] text-slate-400 truncate leading-tight mt-0.5",children:a==="providers"&&t?`Configure credentials, upstream headers, and fallback strategy for ${t.name}`:x.subtitle})]})]}),e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsxs("div",{className:"relative w-64 h-8",children:[e.jsx("span",{className:"material-symbols-outlined absolute left-3 top-1/2 -translate-y-1/2 text-[15px] text-slate-500 pointer-events-none",children:"search"}),e.jsx("input",{type:"text",placeholder:"Search providers & models...",value:r,onChange:v=>s(v.target.value),className:"w-full h-8 bg-[#111827] border border-[#1E293B] rounded-lg pl-9 pr-8 text-xs text-white placeholder-slate-500 focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500/30 transition-all"}),r&&e.jsx("button",{type:"button",onClick:()=>s(""),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 w-5 h-5 rounded hover:bg-white/5",title:"Clear search",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>{D&&o?o():l==null||l("endpoint")},title:I,className:`w-8 h-8 rounded-lg border text-xs font-medium transition-all cursor-pointer shadow-xs inline-flex items-center justify-center ${B}`,children:e.jsx("span",{className:"material-symbols-outlined text-[17px]",children:O})}),e.jsx("button",{type:"button",onClick:()=>l==null?void 0:l("mitm"),title:N,className:`w-8 h-8 rounded-lg border border-[#1E293B] bg-[#111827] hover:bg-white/5 ${k} transition-colors cursor-pointer inline-flex items-center justify-center shadow-xs`,children:e.jsx("span",{className:"material-symbols-outlined text-[17px]",children:"alt_route"})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 border-l border-[#1E293B] pl-2.5",children:[o&&e.jsx("button",{type:"button",onClick:o,title:"Restart Mapigate Gateway (Hot Reload)",className:"w-8 h-8 rounded-lg border border-[#1E293B] bg-[#111827] hover:bg-white/5 hover:text-blue-400 text-slate-400 transition-colors cursor-pointer inline-flex items-center justify-center shadow-xs",children:e.jsx("span",{className:"material-symbols-outlined text-[17px]",children:"restart_alt"})}),d&&e.jsx("button",{type:"button",onClick:i,title:"Lock Dashboard (Master Password Protected)",className:"w-8 h-8 rounded-lg bg-amber-500/10 hover:bg-amber-500/20 text-amber-400 border border-amber-500/20 hover:border-amber-500/30 transition-all cursor-pointer inline-flex items-center justify-center shadow-xs",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"lock"})})]}),e.jsx("div",{className:"flex items-center border-l border-[#1E293B] pl-2.5",children:e.jsx("a",{href:"https://github.com/joutvhu/mapigate",target:"_blank",rel:"noreferrer",title:"Mapigate on GitHub (joutvhu/mapigate)",className:"hidden sm:inline-flex items-center justify-center w-8 h-8 rounded-lg bg-[#111827] hover:bg-white/5 text-slate-400 hover:text-white border border-[#1E293B] transition-all cursor-pointer shadow-xs",children:e.jsx(H,{className:"size-4"})})})]})]})},le=()=>{const[a,r]=m.useState(""),[s,t]=m.useState(!1),[n,o]=m.useState(!1),[l,x]=m.useState(null),d=m.useRef(null),i=j(p=>p.login);m.useEffect(()=>{var p;(p=d.current)==null||p.focus()},[]);const c=async p=>{var u;if(p.preventDefault(),!a.trim()||n)return;o(!0),x(null);const h=await i(a);h.success||(x(h.error||"Incorrect master password"),o(!1),(u=d.current)==null||u.select())};return e.jsxs("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-[#07090E] p-4 animate-rt-fade-in select-none",children:[e.jsxs("div",{className:"absolute inset-0 overflow-hidden pointer-events-none",children:[e.jsx("div",{className:"absolute -top-[25%] left-1/2 -translate-x-1/2 w-[650px] h-[450px] bg-gradient-to-b from-blue-600/15 via-indigo-600/10 to-transparent blur-[140px] rounded-full"}),e.jsx("div",{className:"absolute -bottom-[20%] left-1/2 -translate-x-1/2 w-[500px] h-[300px] bg-blue-500/5 blur-[120px] rounded-full"})]}),e.jsxs("div",{className:"w-full max-w-sm relative z-10 space-y-6",children:[e.jsxs("div",{className:"flex flex-col items-center justify-center text-center space-y-3",children:[e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"absolute -inset-1 bg-gradient-to-r from-blue-500 to-indigo-500 rounded-2xl blur-md opacity-40 group-hover:opacity-75 transition-opacity"}),e.jsx("div",{className:"relative size-12 rounded-2xl bg-gradient-to-br from-blue-500 to-indigo-600 text-white flex items-center justify-center shadow-lg shadow-blue-500/30 border border-blue-400/30",children:e.jsx("span",{className:"material-symbols-outlined text-[24px]",children:"graph_5"})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx("h1",{className:"text-xl font-bold tracking-tight text-white font-sans",children:"Mapigate"}),e.jsx("span",{className:"text-[10px] uppercase font-semibold px-1.5 py-0.5 rounded bg-blue-500/20 text-blue-400 border border-blue-500/30 font-mono",children:"AI"})]}),e.jsx("p",{className:"text-xs text-slate-400 mt-1 font-medium",children:"Ultra-lightweight Local AI Gateway"})]})]}),e.jsxs("div",{className:"bg-[#0D111A]/90 backdrop-blur-xl border border-slate-800/80 shadow-2xl shadow-black/60 rounded-2xl p-6 sm:p-7 text-center space-y-5 border-t-blue-500/50",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-slate-800/60",children:[e.jsxs("div",{className:"flex items-center gap-2 text-left",children:[e.jsx("div",{className:"size-8 rounded-lg bg-blue-500/10 border border-blue-500/20 text-blue-400 flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"lock"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xs font-semibold text-white tracking-tight",children:"Dashboard Locked"}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"Authentication required"})]})]}),e.jsx("span",{className:"text-[10px] font-mono px-2 py-0.5 rounded-full bg-slate-800/80 text-slate-300 border border-slate-700/50",children:"v1.0"})]}),e.jsxs("form",{onSubmit:c,className:"space-y-4",children:[e.jsxs("div",{className:"relative text-left",children:[e.jsx("span",{className:"material-symbols-outlined absolute left-3 top-1/2 -translate-y-1/2 text-[18px] text-slate-500",children:"key"}),e.jsx("input",{ref:d,type:s?"text":"password",placeholder:"Enter master password...",value:a,onChange:p=>{r(p.target.value),l&&x(null)},disabled:n,className:"w-full bg-[#07090E] border border-slate-800 rounded-xl pl-9 pr-10 py-2.5 text-xs text-white placeholder-slate-500 focus:outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 transition-all font-mono"}),e.jsx("button",{type:"button",onClick:()=>t(!s),tabIndex:-1,className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-500 hover:text-slate-300 transition-colors cursor-pointer","aria-label":s?"Hide password":"Show password",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:s?"visibility_off":"visibility"})})]}),l&&e.jsxs("div",{className:"p-2.5 rounded-lg bg-rose-500/10 border border-rose-500/30 text-xs text-rose-300 flex items-center gap-2 text-left animate-rt-scale-in",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] shrink-0 text-rose-400",children:"error"}),e.jsx("span",{className:"truncate",children:l})]}),e.jsx("button",{type:"submit",disabled:n||!a.trim(),className:"w-full rt-btn rt-btn--primary text-xs py-2.5 px-4 flex items-center justify-center gap-2 cursor-pointer font-semibold shadow-lg shadow-blue-500/20 disabled:opacity-50 disabled:cursor-not-allowed transition-all",children:n?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] animate-spin",children:"progress_activity"}),"Verifying..."]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"lock_open"}),"Unlock Dashboard"]})})]})]}),e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-slate-500 text-[11px]",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] text-blue-400",children:"verified_user"}),e.jsx("span",{children:"100% Local-First · Coding assistants proxy unaffected"})]})]})]})};function ie(a){let r={...a},s=!1,t=!1,n=0;const o=u=>{r={...u}},l=()=>{var b;if(r.disabled)return;const u=Date.now();u-n<250||(n=u,(b=r.onClose)==null||b.call(r))};return{updateOptions:o,handleMouseDown:u=>{r.disabled||(u.target===u.currentTarget&&(u.button===0||u.button===void 0)?s=!0:s=!1)},handleMouseUp:u=>{if(r.disabled){s=!1;return}s&&u.target===u.currentTarget&&(u.button===0||u.button===void 0)&&l(),s=!1},handleTouchStart:u=>{r.disabled||(u.target===u.currentTarget?t=!0:t=!1)},handleTouchEnd:u=>{if(r.disabled){t=!1;return}t&&u.target===u.currentTarget&&l(),t=!1},handleClick:u=>{r.disabled||u.detail===0&&u.target===u.currentTarget&&l()},reset:()=>{s=!1,t=!1},get isMouseDown(){return s},get isTouchStart(){return t}}}function ce(a,r=!1){const s=m.useRef(null);s.current?s.current.updateOptions({onClose:a,disabled:r}):s.current=ie({onClose:a,disabled:r}),m.useEffect(()=>{if(typeof window>"u")return;const n=()=>{var l;(l=s.current)==null||l.reset()},o=()=>{var l;(l=s.current)==null||l.reset()};return window.addEventListener("mouseup",n),window.addEventListener("touchend",o),()=>{window.removeEventListener("mouseup",n),window.removeEventListener("touchend",o)}},[]);const t=s.current;return{handleBackdropMouseDown:t.handleMouseDown,handleBackdropMouseUp:t.handleMouseUp,handleBackdropTouchStart:t.handleTouchStart,handleBackdropTouchEnd:t.handleTouchEnd,handleBackdropClick:t.handleClick,backdropProps:{onMouseDown:t.handleMouseDown,onMouseUp:t.handleMouseUp,onTouchStart:t.handleTouchStart,onTouchEnd:t.handleTouchEnd,onClick:t.handleClick}}}const K=({isOpen:a,onClose:r,children:s,maxWidthClass:t="max-w-xl",className:n="",overflowHidden:o=!1})=>{const{backdropProps:l}=ce(r);if(m.useEffect(()=>{if(!a)return;const d=c=>{c.key==="Escape"&&r()};document.addEventListener("keydown",d);const i=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",d),document.body.style.overflow=i}},[a,r]),!a||typeof document>"u")return null;const x=o?"overflow-hidden":n.includes("overflow-")?"":"overflow-visible";return J.createPortal(e.jsx("div",{role:"dialog","aria-modal":"true",className:"fixed inset-0 z-[9999] flex items-center justify-center p-4 bg-black/75 backdrop-blur-xs animate-rt-fade-in",...l,children:e.jsx("div",{className:`w-full ${t} bg-[#0F1420] border border-[#1E293B] rounded-2xl shadow-2xl p-6 animate-rt-scale-in text-slate-100 ${x} ${n}`,onClick:d=>d.stopPropagation(),children:s})}),document.body)},de=({isOpen:a,onClose:r})=>{const[s,t]=m.useState("confirm"),[n,o]=m.useState(null),[l,x]=m.useState(0),d=m.useRef(null),i=m.useRef(null);m.useEffect(()=>(a?(t("confirm"),o(null),x(0)):(d.current&&clearInterval(d.current),i.current&&clearInterval(i.current)),()=>{d.current&&clearInterval(d.current),i.current&&clearInterval(i.current)}),[a]);const c=()=>{const h=Date.now();let u=0;i.current=setInterval(()=>{x(Math.floor((Date.now()-h)/1e3))},500),setTimeout(()=>{d.current=setInterval(async()=>{u+=1;try{const b=await fetch("/health",{cache:"no-store",headers:{Accept:"application/json"}});if(b.ok){const g=await b.json().catch(()=>null);(g==null?void 0:g.status)==="ok"&&(d.current&&clearInterval(d.current),i.current&&clearInterval(i.current),t("success"),setTimeout(()=>{window.location.reload()},600))}}catch{}u>=50&&(d.current&&clearInterval(d.current),i.current&&clearInterval(i.current),t("timeout"))},500)},600)},p=async()=>{t("restarting"),o(null);try{const h=await fetch("/api/server/restart",{method:"POST",headers:{"Content-Type":"application/json"}});if(!h.ok){const u=await h.json().catch(()=>({}));o(u.error||"Failed to initiate server restart."),t("confirm");return}}catch{}c()};return e.jsx(K,{isOpen:a,onClose:()=>{(s==="confirm"||s==="timeout")&&r()},maxWidthClass:"max-w-md",children:e.jsxs("div",{className:"space-y-4",children:[s==="confirm"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 rounded-xl bg-blue-500/15 border border-blue-500/30 text-blue-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[24px]",children:"restart_alt"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Restart Mapigate Gateway?"}),e.jsx("p",{className:"text-xs text-slate-400",children:"Gracefully reload server and apply new version"})]})]}),e.jsxs("div",{className:"p-3.5 rounded-xl bg-[#0A0D14] border border-[#1E293B] text-xs text-slate-300 space-y-2 leading-relaxed",children:[e.jsx("p",{children:"Hot restarting the gateway reloads all provider modules, registries, and configuration. MITM proxy and tool DNS entries remain active across restart."}),e.jsxs("p",{className:"text-slate-400 text-[11px]",children:["If you recently installed an update (e.g. via ",e.jsx("code",{className:"text-blue-400",children:"npm install -g mapigate"})," or ",e.jsx("code",{className:"text-blue-400",children:"npm run local:publish"}),"), the new code will take effect immediately without needing to open a terminal or turn off DNS."]})]}),n&&e.jsx("div",{className:"p-3 rounded-lg bg-rose-500/10 border border-rose-500/30 text-xs text-rose-300",children:n}),e.jsxs("div",{className:"flex items-center justify-end gap-3 pt-2",children:[e.jsx("button",{type:"button",onClick:r,className:"rt-btn rt-btn--secondary text-xs py-2 px-4 cursor-pointer",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:p,className:"rt-btn rt-btn--primary text-xs py-2 px-4 flex items-center gap-1.5 cursor-pointer font-semibold",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"restart_alt"}),"Restart Gateway"]})]})]}),s==="restarting"&&e.jsxs("div",{className:"py-6 px-2 text-center space-y-4",children:[e.jsxs("div",{className:"relative size-14 mx-auto flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-blue-500/20 border-t-blue-500 animate-spin"}),e.jsx("span",{className:"material-symbols-outlined text-[28px] text-blue-400",children:"restart_alt"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Restarting Mapigate Gateway..."}),e.jsxs("p",{className:"text-xs text-slate-400",children:["Re-spawning daemon and binding port (",l,"s)"]})]}),e.jsx("p",{className:"text-[11px] text-slate-500",children:"Please wait. This page will refresh automatically once the new server responds."})]}),s==="success"&&e.jsxs("div",{className:"py-6 px-2 text-center space-y-4",children:[e.jsx("div",{className:"size-14 mx-auto rounded-full bg-emerald-500/15 border border-emerald-500/30 text-emerald-400 flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-[32px]",children:"check_circle"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Restart Succeeded!"}),e.jsx("p",{className:"text-xs text-emerald-400 font-medium",children:"Gateway is back online. Refreshing dashboard..."})]})]}),s==="timeout"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 rounded-xl bg-amber-500/15 border border-amber-500/30 text-amber-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[24px]",children:"schedule"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Restart Taking Longer Than Expected"}),e.jsx("p",{className:"text-xs text-slate-400",children:"The gateway server has not responded yet."})]})]}),e.jsxs("div",{className:"p-3.5 rounded-xl bg-[#0A0D14] border border-[#1E293B] text-xs text-slate-300 space-y-2",children:[e.jsx("p",{children:"If the server failed to restart automatically, you can start it manually in your terminal:"}),e.jsx("div",{className:"bg-[#111827] p-2.5 rounded-lg border border-[#1E293B] font-mono text-[11px] text-blue-400",children:"mpg start"})]}),e.jsxs("div",{className:"flex items-center justify-end gap-3 pt-2",children:[e.jsx("button",{type:"button",onClick:r,className:"rt-btn rt-btn--secondary text-xs py-2 px-4 cursor-pointer",children:"Close"}),e.jsxs("button",{type:"button",onClick:()=>window.location.reload(),className:"rt-btn rt-btn--primary 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:"refresh"}),"Refresh Page"]})]})]})]})})},ue=({isOpen:a,onClose:r,currentVersion:s,latestVersion:t})=>{const[n,o]=m.useState("confirm"),[l,x]=m.useState(null),[d,i]=m.useState(0),c=m.useRef(null),p=m.useRef(null);m.useEffect(()=>(a?(o("confirm"),x(null),i(0)):(c.current&&clearInterval(c.current),p.current&&clearInterval(p.current)),()=>{c.current&&clearInterval(c.current),p.current&&clearInterval(p.current)}),[a]);const h=()=>{let b=0;setTimeout(()=>{c.current=setInterval(async()=>{b+=1;try{const g=await fetch("/health",{cache:"no-store",headers:{Accept:"application/json"}});if(g.ok){const f=await g.json().catch(()=>null);(f==null?void 0:f.status)==="ok"&&(c.current&&clearInterval(c.current),p.current&&clearInterval(p.current),o("success"),setTimeout(()=>{window.location.reload()},800))}}catch{}b>=60&&(c.current&&clearInterval(c.current),p.current&&clearInterval(p.current),o("timeout"))},500)},800)},u=async()=>{o("upgrading"),x(null),i(0);const b=Date.now();p.current=setInterval(()=>{i(Math.floor((Date.now()-b)/1e3))},500);try{const g=await fetch("/api/server/upgrade",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:!1})}),f=await g.json().catch(()=>({}));if(!g.ok||!f.success){p.current&&clearInterval(p.current),x(f.error||"Failed to upgrade Mapigate."),o("error");return}o("restarting"),h()}catch(g){p.current&&clearInterval(p.current),x((g==null?void 0:g.message)||"Network error while requesting upgrade."),o("error")}};return e.jsx(K,{isOpen:a,onClose:()=>{(n==="confirm"||n==="error"||n==="timeout")&&r()},maxWidthClass:"max-w-md",children:e.jsxs("div",{className:"space-y-4",children:[n==="confirm"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 rounded-xl bg-amber-500/15 border border-amber-500/30 text-amber-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[24px]",children:"upgrade"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Upgrade Mapigate Gateway"}),e.jsx("p",{className:"text-xs text-slate-400",children:"Install the latest release from npm and reload"})]})]}),e.jsxs("div",{className:"p-3.5 rounded-xl bg-[#0A0D14] border border-[#1E293B] space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-slate-400",children:"Current Version:"}),e.jsxs("span",{className:"font-mono font-semibold text-slate-300",children:["v",s||"0.0.0"]})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-slate-400",children:"Target Version:"}),e.jsxs("span",{className:"font-mono font-semibold text-amber-400",children:["v",t||"latest"]})]}),e.jsxs("div",{className:"pt-2 border-t border-[#1E293B] text-[11px] text-slate-400 leading-relaxed",children:["Mapigate will run ",e.jsxs("code",{className:"text-amber-400 font-mono",children:["npm install -g mapigate@",t||"latest"]})," and hot-reload the gateway. All database settings, API keys, and active combos will be preserved."]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs("a",{href:"https://www.npmjs.com/package/mapigate",target:"_blank",rel:"noreferrer",className:"text-[11px] text-blue-400 hover:text-blue-300 hover:underline inline-flex items-center gap-1",children:[e.jsx("span",{children:"View on npm"}),e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"open_in_new"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:r,className:"rt-btn rt-btn--secondary text-xs py-2 px-3.5 cursor-pointer",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:u,className:"rt-btn rt-btn--primary text-xs py-2 px-4 flex items-center gap-1.5 cursor-pointer font-semibold bg-amber-600 hover:bg-amber-500 text-white border-amber-500/40",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"upgrade"}),"Upgrade to v",t]})]})]})]}),n==="upgrading"&&e.jsxs("div",{className:"py-6 px-2 text-center space-y-4",children:[e.jsxs("div",{className:"relative size-14 mx-auto flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-amber-500/20 border-t-amber-500 animate-spin"}),e.jsx("span",{className:"material-symbols-outlined text-[28px] text-amber-400",children:"download"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Upgrading Mapigate..."}),e.jsxs("p",{className:"text-xs text-slate-400 font-mono",children:["npm install -g mapigate@",t||"latest"," (",d,"s)"]})]}),e.jsx("p",{className:"text-[11px] text-slate-500",children:"Downloading and installing update. Please do not close this window."})]}),n==="restarting"&&e.jsxs("div",{className:"py-6 px-2 text-center space-y-4",children:[e.jsxs("div",{className:"relative size-14 mx-auto flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border-2 border-blue-500/20 border-t-blue-500 animate-spin"}),e.jsx("span",{className:"material-symbols-outlined text-[28px] text-blue-400",children:"restart_alt"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Restarting Gateway..."}),e.jsxs("p",{className:"text-xs text-slate-400",children:["Re-spawning daemon with v",t," (",d,"s)"]})]}),e.jsx("p",{className:"text-[11px] text-slate-500",children:"Gateway is reloading. This dashboard will refresh automatically once online."})]}),n==="success"&&e.jsxs("div",{className:"py-6 px-2 text-center space-y-4",children:[e.jsx("div",{className:"size-14 mx-auto rounded-full bg-emerald-500/15 border border-emerald-500/30 text-emerald-400 flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-[32px]",children:"check_circle"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Upgrade Succeeded!"}),e.jsxs("p",{className:"text-xs text-emerald-400 font-medium",children:["Mapigate v",t," is live. Refreshing dashboard..."]})]})]}),n==="error"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 rounded-xl bg-rose-500/15 border border-rose-500/30 text-rose-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[24px]",children:"error"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Upgrade Failed"}),e.jsx("p",{className:"text-xs text-slate-400",children:"An error occurred while updating"})]})]}),l&&e.jsx("div",{className:"p-3 rounded-lg bg-rose-500/10 border border-rose-500/30 text-xs text-rose-300 font-mono break-words leading-relaxed max-h-36 overflow-y-auto",children:l}),e.jsxs("div",{className:"p-3 rounded-xl bg-[#0A0D14] border border-[#1E293B] text-[11px] text-slate-400 space-y-1.5 leading-relaxed",children:[e.jsx("p",{className:"font-semibold text-slate-300",children:"You can upgrade manually from your terminal:"}),e.jsxs("div",{className:"p-2 rounded bg-black/50 font-mono text-slate-200 text-[10px] space-y-1 select-all",children:[e.jsx("div",{children:"npm install -g mapigate@latest"}),e.jsx("div",{children:"mpg restart"})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:r,className:"rt-btn rt-btn--secondary text-xs py-2 px-4 cursor-pointer",children:"Close"}),e.jsxs("button",{type:"button",onClick:u,className:"rt-btn rt-btn--primary text-xs py-2 px-4 flex items-center gap-1 cursor-pointer font-semibold",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"refresh"}),"Retry"]})]})]}),n==="timeout"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 rounded-xl bg-amber-500/15 border border-amber-500/30 text-amber-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[24px]",children:"schedule"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Server Still Starting"}),e.jsx("p",{className:"text-xs text-slate-400",children:"The gateway has not responded yet"})]})]}),e.jsxs("div",{className:"p-3.5 rounded-xl bg-[#0A0D14] border border-[#1E293B] text-xs text-slate-300 space-y-2 leading-relaxed",children:[e.jsx("p",{children:"The upgrade may have completed, but the server is taking longer than expected to bind to port."}),e.jsxs("p",{className:"text-slate-400 text-[11px]",children:["You can try refreshing the page or checking ",e.jsx("code",{className:"text-blue-400",children:"mpg status"})," in your terminal."]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:r,className:"rt-btn rt-btn--secondary text-xs py-2 px-4 cursor-pointer",children:"Close"}),e.jsxs("button",{type:"button",onClick:()=>window.location.reload(),className:"rt-btn rt-btn--primary text-xs py-2 px-4 flex items-center gap-1.5 cursor-pointer font-semibold",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"refresh"}),"Refresh Page"]})]})]})]})})},xe=m.lazy(()=>y(()=>import("./ProvidersTab-CwJo_EUX.js"),__vite__mapDeps([0,1,2,3,4,5,6,7])).then(a=>({default:a.ProvidersTab}))),me=m.lazy(()=>y(()=>import("./ProviderDetailPage-BIfOQupC.js"),__vite__mapDeps([8,1,6,4,9,5,3,10,2,7])).then(a=>({default:a.ProviderDetailPage}))),pe=m.lazy(()=>y(()=>import("./CombosTab-EWUYC3TU.js"),__vite__mapDeps([11,1,12,3,4,5,9,2,7])).then(a=>({default:a.CombosTab}))),he=m.lazy(()=>y(()=>import("./UsageTab-85tTb2_C.js"),__vite__mapDeps([13,1,7,5,4,14,9])).then(a=>({default:a.UsageTab}))),fe=m.lazy(()=>y(()=>import("./QuotaTab-PFvP6yAb.js"),__vite__mapDeps([15,1,4,5,9,10,2,7])).then(a=>({default:a.QuotaTab}))),be=m.lazy(()=>y(()=>import("./CliToolsTab-D_MUwimj.js"),__vite__mapDeps([16,1,6,4,5,3,7])).then(a=>({default:a.CliToolsTab}))),ge=m.lazy(()=>y(()=>import("./MitmTab-C7g7GUXW.js"),__vite__mapDeps([17,1,3,4,5,7])).then(a=>({default:a.MitmTab}))),ve=m.lazy(()=>y(()=>import("./EndpointTab-BwtzqXUN.js"),__vite__mapDeps([18,1,9,2,7])).then(a=>({default:a.EndpointTab}))),ye=m.lazy(()=>y(()=>import("./TokenSaverTab-B3Fbu_yc.js"),__vite__mapDeps([19,1])).then(a=>({default:a.TokenSaverTab}))),je=m.lazy(()=>y(()=>import("./ConsoleLogTab-BSMXSYrR.js"),__vite__mapDeps([20,1,9,7,5])).then(a=>({default:a.ConsoleLogTab}))),we=m.lazy(()=>y(()=>import("./SettingsTab-DwAbjIW3.js"),__vite__mapDeps([21,1,7])).then(a=>({default:a.SettingsTab}))),Ne=m.lazy(()=>y(()=>import("./CallbackPage-DBsxnmPi.js"),__vite__mapDeps([22,1])));function Q(){return e.jsx("div",{className:"flex items-center justify-center py-24 text-slate-500",children:e.jsx("div",{className:"size-6 rounded-full border-2 border-blue-500/20 border-t-blue-500 animate-spin"})})}function ke(){const a=typeof window<"u"?new URLSearchParams(window.location.search):null,r=!!(a&&(a.has("user_id")&&(a.has("access_token")||a.has("accessToken")||a.has("token"))||a.has("userId")&&(a.has("access_token")||a.has("accessToken")||a.has("token"))));return typeof window<"u"&&(window.location.pathname==="/callback"||window.location.pathname==="/auth/callback"||window.location.pathname==="/authorize"||window.location.pathname.startsWith("/callback")||r)?e.jsx(m.Suspense,{fallback:e.jsx(Q,{}),children:e.jsx(Ne,{})}):e.jsx(Te,{})}function Te(){const a=j(f=>f.isChecking),r=j(f=>f.isLocked),s=j(f=>f.checkAuth),t=_(f=>f.fetchSystemInfo);m.useEffect(()=>{s(),t()},[s,t]);const[n,o]=m.useState("providers"),[l,x]=m.useState(""),[d,i]=m.useState(null),[c,p]=m.useState(!1),[h,u]=m.useState(!1),b=_(f=>f.info),g=f=>{o(f),i(null)};return a?e.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-[#0A0D14] text-slate-400",children:e.jsx("div",{className:"size-8 rounded-full border-2 border-blue-500/20 border-t-blue-500 animate-spin"})}):r?e.jsx(le,{}):e.jsxs("div",{className:"rt-app",children:[e.jsx(se,{currentTab:n,onSelectTab:g,onUpgradeClick:()=>u(!0)}),e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 h-full overflow-hidden",children:[e.jsx(oe,{currentTab:n,searchQuery:l,onSearchChange:x,detailProvider:d,onBackToProviders:()=>i(null),onRestartClick:()=>p(!0),onSelectTab:g}),e.jsx("main",{className:"flex-1 overflow-y-auto px-4 sm:px-6 py-6 w-full",children:e.jsxs(m.Suspense,{fallback:e.jsx(Q,{}),children:[n==="endpoint"&&e.jsx(ve,{onRestartClick:()=>p(!0)}),n==="providers"&&(d?e.jsx(me,{provider:d,onBack:()=>i(null)}):e.jsx(xe,{searchQuery:l,onSelectProvider:f=>i(f)})),n==="combos"&&e.jsx(pe,{}),n==="usage"&&e.jsx(he,{}),n==="quota"&&e.jsx(fe,{searchQuery:l}),n==="tokensaver"&&e.jsx(ye,{}),n==="clitools"&&e.jsx(be,{}),n==="mitm"&&e.jsx(ge,{}),n==="consolelog"&&e.jsx(je,{}),n==="settings"&&e.jsx(we,{onRestartClick:()=>p(!0),onUpgradeClick:()=>u(!0)})]})})]}),e.jsx(de,{isOpen:c,onClose:()=>p(!1)}),e.jsx(ue,{isOpen:h,onClose:()=>u(!1),currentVersion:b==null?void 0:b.version,latestVersion:b==null?void 0:b.latestVersion})]})}Y.createRoot(document.getElementById("root")).render(e.jsx(X.StrictMode,{children:e.jsx(ke,{})}));export{w as A,T as D,K as P,de as R,ce as a,Se as b,te as c,R as d,F as e,j as f,_ as u};