mapigate 0.5.133 → 0.5.141

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 (101) hide show
  1. package/README.md +1 -1
  2. package/dist/cli/commands/logs.js +0 -1
  3. package/dist/core/adapters/anthropic/requestAnthropicToOpenAi.js +59 -11
  4. package/dist/core/adapters/anthropic/requestOpenAiToAnthropic.js +1 -1
  5. package/dist/core/adapters/anthropicAdapter.js +2 -2
  6. package/dist/core/adapters/helpers/toolCallRescue.js +1 -1
  7. package/dist/core/adapters/responsesAdapter.js +11 -0
  8. package/dist/core/capabilities/modelDictionary.js +1 -0
  9. package/dist/core/scanner/modelScanner.js +2 -1
  10. package/dist/core/scanner/payloadExtractor.js +1 -1
  11. package/dist/core/scanner/urlResolver.js +16 -0
  12. package/dist/core/tokenSaver/methods/rtk/autodetect.js +1 -1
  13. package/dist/core/tokenSaver/methods/rtk/filters/gitLog.js +1 -1
  14. package/dist/core/usage/pricing.js +98 -42
  15. package/dist/core/usage/tokenExtractor.js +59 -0
  16. package/dist/mitm/handlers/antigravity/config.js +22 -0
  17. package/dist/mitm/handlers/antigravity/modelInjector.js +2 -2
  18. package/dist/providers/catalog/commandcode/converter.js +215 -0
  19. package/dist/providers/catalog/commandcode/executor.js +305 -0
  20. package/dist/providers/catalog/commandcode/headers.js +76 -0
  21. package/dist/providers/catalog/commandcode/metadata.js +4 -1
  22. package/dist/providers/catalog/commandcode/ndjson.js +161 -0
  23. package/dist/providers/catalog/commandcode/provider.js +18 -35
  24. package/dist/providers/catalog/commandcode/routes.js +75 -0
  25. package/dist/providers/catalog/iflow/provider.js +1 -1
  26. package/dist/providers/catalog/iteracompute/metadata.js +154 -13
  27. package/dist/providers/catalog/iteracompute/provider.js +111 -0
  28. package/dist/providers/catalog/opencode-go/metadata.js +4 -2
  29. package/dist/providers/catalog/opencode-go/models.js +1 -0
  30. package/dist/providers/catalog/opencode-go/provider.js +114 -0
  31. package/dist/providers/catalog/opencode-go/quota.js +106 -0
  32. package/dist/providers/catalog/opencode-go/responses.js +301 -0
  33. package/dist/providers/catalog/opencode-go/responsesPayload.js +228 -0
  34. package/dist/providers/catalog/openrouter/metadata.js +1 -0
  35. package/dist/providers/catalog/sensenova/metadata.js +35 -0
  36. package/dist/providers/core/base/baseProvider.js +8 -3
  37. package/dist/providers/core/base/openAiProvider.js +3 -1
  38. package/dist/providers/generated/routesRegistry.generated.js +2 -0
  39. package/dist/providers/runtime/antigravity/executor.js +2 -2
  40. package/dist/providers/runtime/antigravity/metadata.js +2 -2
  41. package/dist/providers/runtime/antigravity/models.js +9 -0
  42. package/dist/providers/runtime/antigravity/provider.js +2 -2
  43. package/dist/providers/runtime/antigravity/routes.js +2 -2
  44. package/dist/providers/runtime/antigravity/schema.js +20 -2
  45. package/dist/providers/runtime/antigravity/types.js +10 -2
  46. package/dist/providers/runtime/codebuddy/provider.js +21 -6
  47. package/dist/providers/runtime/gemini/provider.js +77 -0
  48. package/dist/providers/runtime/gemini-cli/provider.js +2 -2
  49. package/dist/providers/runtime/github/routes.js +1 -1
  50. package/dist/providers/runtime/grok/provider.js +1 -1
  51. package/dist/providers/runtime/kiro/executor.js +7 -4
  52. package/dist/providers/runtime/kiro/models.js +11 -0
  53. package/dist/providers/runtime/kiro/provider.js +8 -8
  54. package/dist/providers/runtime/minimax/routes.js +0 -1
  55. package/dist/providers/runtime/opencode/tools.js +39 -17
  56. package/dist/providers/runtime/windsurf/routes.js +0 -2
  57. package/dist/providers/runtime/xkiro/quota.js +4 -1
  58. package/dist/server/proxy/executorHelpers.js +1 -1
  59. package/dist/server/proxy/index.js +1 -1
  60. package/dist/server/proxy/pipeline.js +12 -6
  61. package/dist/server/proxy/proxyDispatcher.js +136 -17
  62. package/dist/server/proxy/responseHandlers.js +2 -18
  63. package/dist/server/proxy/singleModelExecutor.js +15 -3
  64. package/dist/server/proxy/streaming/sseStreamer.js +3 -10
  65. package/dist/server/routes/apiMitm.js +1 -1
  66. package/dist/server/routes/apiModels.js +17 -12
  67. package/dist/server/utils/consoleLogBuffer.js +3 -3
  68. package/dist/shared/constants/index.js +2 -2
  69. package/dist/shared/logger.js +2 -2
  70. package/dist/shared/utils/dnsResolver.js +69 -27
  71. package/dist/storage/repositories/logRepo.js +3 -23
  72. package/dist/storage/repositories/requestDetailsRepo.js +1 -1
  73. package/dist/storage/repositories/usageRepo.js +136 -74
  74. package/dist/web/assets/{CliToolsTab-D4DkK7Rn.js → CliToolsTab-rKSWLJC3.js} +1 -1
  75. package/dist/web/assets/CombosTab-D1_cfssh.js +1 -0
  76. package/dist/web/assets/{ConfirmModal-CuQ7ARxt.js → ConfirmModal-OWeauwYv.js} +1 -1
  77. package/dist/web/assets/{ConsoleLogTab-B2sfhYZW.js → ConsoleLogTab-rZe8zCb_.js} +1 -1
  78. package/dist/web/assets/{EditAccountModal-BusNJLvX.js → EditAccountModal-CAg-yIOn.js} +1 -1
  79. package/dist/web/assets/{EndpointTab-DQCezUA9.js → EndpointTab-B-Jb4wAG.js} +1 -1
  80. package/dist/web/assets/{MitmTab-DxEuD0DW.js → MitmTab-5dKeNi4T.js} +5 -5
  81. package/dist/web/assets/{ModelAutocompleteInput-CgJ2FlEf.js → ModelAutocompleteInput-CoinzdsW.js} +1 -1
  82. package/dist/web/assets/ProviderDetailPage-D-fodBhz.js +6 -0
  83. package/dist/web/assets/ProvidersTab-yzmb4w0D.js +1 -0
  84. package/dist/web/assets/{QuotaTab-CvXGyICr.js → QuotaTab-BXevQzen.js} +1 -1
  85. package/dist/web/assets/{SettingsTab-D7YF7rTP.js → SettingsTab-LkByv4Sg.js} +1 -1
  86. package/dist/web/assets/UsageTab-Hr8XPZD4.js +1 -0
  87. package/dist/web/assets/index-CKuvklEr.js +2 -0
  88. package/dist/web/assets/{index-BisuNW2y.css → index-HnsyZg0I.css} +1 -1
  89. package/dist/web/assets/metadataRegistry-NuDSSkP9.js +1 -0
  90. package/dist/web/assets/providers/openrouter/icon.png +0 -0
  91. package/dist/web/assets/providersData-DS1-ETBi.js +1 -0
  92. package/dist/web/index.html +2 -2
  93. package/package.json +9 -1
  94. package/dist/web/assets/CombosTab-X1C_OmzI.js +0 -1
  95. package/dist/web/assets/ProviderDetailPage-DMA1DVSN.js +0 -6
  96. package/dist/web/assets/ProvidersTab-pZoM69s4.js +0 -1
  97. package/dist/web/assets/UsageTab-B0YCftIJ.js +0 -1
  98. package/dist/web/assets/index-DTRst7wN.js +0 -2
  99. package/dist/web/assets/metadataRegistry-BPZSXiBy.js +0 -1
  100. package/dist/web/assets/providers/openrouter/openrouter.png +0 -0
  101. package/dist/web/assets/providersData-Bsv7o5VV.js +0 -1
@@ -1,6 +0,0 @@
1
- import{r as s,j as e}from"./vendor-BcOI2aZ9.js";import{i as et}from"./providersData-Bsv7o5VV.js";import{g as st}from"./metadataRegistry-BPZSXiBy.js";import{u as yt,D as vt,P as De}from"./index-DTRst7wN.js";import{S as Le}from"./Select-BNRH8LIG.js";import{T as Me}from"./ToolIcon-Cp4gSgFt.js";import{i as we}from"./ModelAutocompleteInput-CgJ2FlEf.js";import{C as tt,E as Nt}from"./EditAccountModal-BusNJLvX.js";import{C as wt}from"./ConfirmModal-CuQ7ARxt.js";import"./lucide-Cc35htxl.js";const kt=({isOpen:l,providerId:n,providerName:t,onSuccess:h,onClose:g})=>{const f=s.useRef(h);f.current=h;const c=s.useRef(g);c.current=g;const K=yt(C=>C.info),b=(K==null?void 0:K.port)||vt,W=s.useRef(b);W.current=b;const y=st(n),k=(y==null?void 0:y.regions)||[],[N,R]=s.useState((y==null?void 0:y.defaultRegion)||(k.length>0?k[0].id:"")),S=s.useRef(N);S.current=N;const[A,H]=s.useState(""),[z,I]=s.useState(`http://localhost:${b}/callback`),[E,M]=s.useState(""),[B,D]=s.useState("loading"),[te,Y]=s.useState(null),[ee,j]=s.useState(!1),[U,Q]=s.useState(!1),[J,L]=s.useState(!1),[ae,ue]=s.useState(!1),[G,le]=s.useState(null),ge=s.useRef(null),me=s.useRef(!1),be=s.useRef(void 0),V=s.useRef(void 0),X=s.useRef(0),F=s.useRef(null),P=s.useCallback(()=>{F.current&&(clearTimeout(F.current),clearInterval(F.current),F.current=null)},[]),r=s.useCallback(async C=>{if(!me.current){me.current=!0,P(),D("processing"),Y(null);try{const ne=await fetch(`/api/oauth/${n}/exchange`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:C,redirectUri:z,codeVerifier:be.current,state:V.current,region:S.current||void 0})}),$=await ne.json().catch(()=>({}));if(!ne.ok||$.error)throw new Error($.error||"Token exchange failed");D("success");try{localStorage.removeItem("oauth_pending_flow"),localStorage.removeItem("oauth_callback")}catch{}setTimeout(()=>{f.current(),c.current()},1200)}catch(ne){me.current=!1,D("error"),Y(ne.message||"Failed to exchange authorization token")}}},[n,z,P]),d=s.useCallback(async C=>{const ne=++X.current,$=()=>ne!==X.current;me.current=!1,P(),D("loading"),Y(null),M(""),ue(!1),le(null),L(!1),be.current=void 0,V.current=void 0;const ce=C!==void 0?C:S.current,m=ce?`&region=${encodeURIComponent(ce)}`:"",x=ce?`?region=${encodeURIComponent(ce)}`:"",v=window.location.port==="5173"?`http://localhost:${W.current}/callback`:`${window.location.origin}/callback`;I(v);try{const he=await fetch(`/api/oauth/${n}/authorize?redirect_uri=${encodeURIComponent(v)}${m}`),O=await he.json().catch(()=>({}));if($())return;if(!he.ok||O.error)throw new Error(O.error||`Authorization error (HTTP ${he.status})`);if(O.flowType==="device_code"||!O.authUrl&&O.flowType){ue(!0),D("waiting");const Z=await fetch(`/api/oauth/${n}/device-code${x}`),q=await Z.json().catch(()=>({}));if($())return;if(!Z.ok||!q.device_code)throw new Error(q.error||"Failed to initiate device code flow");le(q);const ke=q.verification_uri_complete||q.verification_uri;if(ke)try{window.open(ke,"_blank","noopener,noreferrer")}catch{}let fe=Number(q.interval)||5,de=!0;const Ce=Ae=>{$()||(F.current&&clearTimeout(F.current),F.current=setTimeout(async()=>{if(!(!de||$()))try{const oe=await(await fetch(`/api/oauth/${n}/poll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:q.device_code,codeVerifier:q.codeVerifier,region:ce||void 0,extraData:{...q||{},_zcodePollToken:q._zcodePollToken,_minimaxPollByUser:q._minimaxPollByUser,codeVerifier:q.codeVerifier,user_code:q.user_code,region:ce||void 0}})})).json();if($())return;if(oe.ok&&oe.success){de=!1,P(),D("success"),setTimeout(()=>{f.current(),c.current()},1200);return}if(oe.error==="slow_down"){fe=Math.min(fe+5,30),Ce(fe);return}if(oe.error==="authorization_pending"){Ce(fe);return}if(oe.error){de=!1,P(),D("error"),Y(oe.error_description||oe.error);return}Ce(fe)}catch{de&&Ce(fe)}},Ae*1e3))};Ce(fe);return}if(O.authUrl){H(O.authUrl),O.redirectUri&&I(O.redirectUri),O.codeVerifier&&(be.current=O.codeVerifier),O.state&&(V.current=O.state),D("waiting");try{localStorage.setItem("oauth_pending_flow",JSON.stringify({providerId:n,redirectUri:O.redirectUri||v,state:O.state,codeVerifier:O.codeVerifier,timestamp:Date.now()}))}catch{}try{const Z=window.open(O.authUrl,"oauth_popup","width=600,height=700");Z&&!Z.closed?ge.current=Z:L(!0)}catch{L(!0)}return}throw new Error("No authorization URL returned from provider")}catch(he){if($())return;if(n==="antigravity"&&DEFAULT_ANTIGRAVITY_AUTH_URL){H(DEFAULT_ANTIGRAVITY_AUTH_URL),D("waiting");try{const O=window.open(DEFAULT_ANTIGRAVITY_AUTH_URL,"oauth_popup","width=600,height=700");O?ge.current=O:L(!0)}catch{L(!0)}}else D("error"),Y(he.message||"Failed to initialize authorization endpoint")}},[n,P]);if(s.useEffect(()=>{if(!l){P(),D("loading"),Y(null),ue(!1),le(null);return}return d(),()=>{X.current++,P()}},[l,n,d,P]),s.useEffect(()=>{if(!l)return;const C=x=>{if(!x)return;if(x.done){me.current=!0,P(),D("success");try{localStorage.removeItem("oauth_pending_flow"),localStorage.removeItem("oauth_callback")}catch{}setTimeout(()=>{f.current(),c.current()},1200);return}if(x.error){D("error"),Y(x.errorDescription||x.error);return}const v=x.code||x.token||(x.userId&&x.token?x.fullUrl||`${window.location.origin}/?user_id=${x.userId}&access_token=${x.token}`:null);v&&r(v)},ne=x=>{var v;((v=x.data)==null?void 0:v.type)==="oauth_callback"&&C(x.data.data)};window.addEventListener("message",ne);let $=null;try{$=new BroadcastChannel("oauth_callback"),$.onmessage=x=>C(x.data)}catch{}const ce=x=>{if(x.key==="oauth_callback"&&x.newValue)try{const v=JSON.parse(x.newValue);C(v),localStorage.removeItem("oauth_callback")}catch{}};window.addEventListener("storage",ce);const m=setInterval(()=>{try{const x=localStorage.getItem("oauth_callback");if(x){const v=JSON.parse(x);v&&(!v.timestamp||Date.now()-v.timestamp<6e4)&&C(v),localStorage.removeItem("oauth_callback")}}catch{}},500);return()=>{clearInterval(m),window.removeEventListener("message",ne),window.removeEventListener("storage",ce),$&&$.close()}},[l,r]),!l)return null;const w=()=>{A&&(navigator.clipboard.writeText(A),j(!0),setTimeout(()=>j(!1),2e3))},pe=C=>{C&&(navigator.clipboard.writeText(C),Q(!0),setTimeout(()=>Q(!1),2e3))},se=()=>{if(A){L(!1);try{const C=window.open(A,"oauth_popup","width=600,height=700");C&&(ge.current=C)}catch{}}},ye=()=>{E.trim()&&r(E.trim())};return e.jsx(De,{isOpen:l,onClose:g,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:g,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"})})]}),k.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:N})]}),e.jsx(Le,{value:N,onChange:C=>{R(C),S.current=C,d(C)},options:k.map(C=>({value:C.id,label:C.label}))})]}),B==="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,"..."]})]}),B==="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:ae?"Waiting for device authorization in browser...":J?"Authorization link ready. Click button below to open login window.":"Popup window opened. Complete authorization in browser..."})]}),B==="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..."})]}),B==="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..."})]}),B==="error"&&te&&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:te})]})]}),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"]})]}),ae&&G?e.jsxs("div",{className:"space-y-4 pt-1",children:[e.jsxs("div",{className:"p-3.5 rounded-xl border border-blue-500/20 bg-blue-500/5 space-y-2",children:[e.jsx("label",{className:"text-xs font-semibold text-slate-200 block",children:"Your One-Time Device Code:"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"flex-1 bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-sm font-mono text-white tracking-widest font-bold text-center select-all",children:G.user_code}),e.jsxs("button",{type:"button",onClick:()=>pe(G.user_code),className:"flex items-center gap-1 px-3 py-2 rounded-xl border border-[#1E293B] bg-[#0A0D14] text-xs font-medium text-slate-300 hover:text-white transition-colors cursor-pointer shrink-0",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${U?"text-emerald-400":""}`,children:U?"check":"content_copy"}),U?"Copied":"Copy Code"]})]})]}),e.jsxs("button",{type:"button",onClick:()=>{const C=G.verification_uri_complete||G.verification_uri;C&&window.open(C,"_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:C=>M(C.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:se,disabled:!A||B==="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"})]}),J&&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"}),A&&e.jsx("button",{type:"button",onClick:()=>window.open(A,"_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:A||(B==="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:w,disabled:!A,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] ${ee?"text-emerald-400":""}`,children:ee?"check":"content_copy"}),ee?"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:C=>M(C.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:g,className:"px-4 py-2 rounded-xl text-xs font-medium text-slate-400 hover:text-white transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"button",onClick:ye,disabled:!E.trim()||B==="processing",className:"rt-btn rt-btn--primary disabled:opacity-50 disabled:cursor-not-allowed",children:B==="processing"?"Exchanging...":"Connect"})]})]})})};function Ct(l,n={}){const{isCloudflareAi:t=!1}=n,h=l.trim();if(!t&&/^LLM\|/i.test(h))return{baseName:"LLM",apiKey:h};const g=l.split("|");if(t&&g.length>=3){const c=g[0].trim(),K=g.slice(1,-1).join("|").trim(),b=g[g.length-1].trim();return{baseName:c||"Key",apiKey:K,providerSpecificData:{accountId:b}}}if(g.length>=2){const c=g[0].trim(),K=g.slice(1).join("|").trim();return{baseName:c||"Key",apiKey:K}}return{baseName:"Key",apiKey:g[0].trim()}}function At(l,n=[],t={}){const h=Array.isArray(n)?n:[],g=new Set(h.map(c=>typeof c=="string"?c.toLowerCase():"")),f=[];for(const c of l){const K=typeof c=="string"?c.trim():"";if(!K)continue;const b=Ct(K,t);if(!b||!b.apiKey)continue;const W=b.baseName;let y=1,k;for(;k=`${W} ${y}`,!!g.has(k.toLowerCase());)y+=1;g.add(k.toLowerCase());const N={name:k,apiKey:b.apiKey};b.providerSpecificData&&(N.providerSpecificData=b.providerSpecificData),f.push(N)}return f}const St=({isOpen:l,provider:n,existingNames:t=[],onClose:h,onSuccess:g,onOpenOAuth:f})=>{const c=n.id.toLowerCase(),K=c==="opencode"||c==="oc"||!!n.noAuth||n.requiresApiKey===!1||n.authType==="none",b=c==="ollama-local"||c.includes("ollama"),W=!!n.isLocal||c==="lm-studio"||c==="jan",y=K||b||W||n.requiresApiKey===!1,k=c==="azure"||c.includes("azure"),N=c==="cloudflare-ai"||c==="cloudflare",R=c==="bedrock"||c.includes("bedrock"),S=c==="grok-web"||c==="iflow",A=c==="xiaomi-tokenplan",H=c==="alicode"||c==="alibaba",z=s.useMemo(()=>A?[{id:"sgp",label:"Singapore (新加坡)"},{id:"cn",label:"China (中国大陆)"},{id:"ams",label:"Amsterdam (阿姆斯特丹)"}]:n.regions||[],[A,n.regions]),[I,E]=s.useState(n.defaultRegion||(z.length>0?z[0].id:"sgp")),[M,B]=s.useState("single"),[D,te]=s.useState(""),[Y,ee]=s.useState(""),[j,U]=s.useState(""),[Q,J]=s.useState("http://127.0.0.1:11434"),[L,ae]=s.useState(n.defaultBaseUrl||(c==="lm-studio"?"http://localhost:1234/v1":c==="jan"?"http://localhost:1337/v1":"http://localhost:8000/v1")),[ue,G]=s.useState(""),[le,ge]=s.useState("gpt-4"),[me,be]=s.useState("2024-10-01-preview"),[V,X]=s.useState(""),[F,P]=s.useState(""),[r,d]=s.useState(""),[w,pe]=s.useState("profile"),[se,ye]=s.useState(""),[C,ne]=s.useState("us-east-1"),[$,ce]=s.useState(""),[m,x]=s.useState(""),[v,he]=s.useState(""),[O,Z]=s.useState(null),[q,ke]=s.useState(!1),[fe,de]=s.useState(null),[Ce,Ae]=s.useState(null),[Te,oe]=s.useState(!1),[Be,Se]=s.useState(null),ve=s.useCallback(()=>{B("single"),te(""),ee(""),U(""),J("http://127.0.0.1:11434"),ae(n.defaultBaseUrl||(c==="lm-studio"?"http://localhost:1234/v1":c==="jan"?"http://localhost:1337/v1":"http://localhost:8000/v1")),G(""),ge("gpt-4"),be("2024-10-01-preview"),X(""),P(""),d(""),pe("profile"),ye(""),ne("us-east-1"),ce(""),x(""),E(n.defaultRegion||(z.length>0?z[0].id:"sgp")),he(""),Z(null),ke(!1),de(null),Ae(null),oe(!1),Se(null)},[n.defaultBaseUrl,n.defaultRegion,z,c]);s.useEffect(()=>{l&&ve()},[l,ve]);const Pe=()=>{ve(),h()},re=()=>S?c==="grok-web"?"sso=xxxx... or raw cookie":"eyJhbGciOi...":y?"Optional / Not required":A?"tp-...":c.startsWith("deepseek")?"sk-...":c.startsWith("xai")?"xai-...":c.startsWith("groq")?"gsk_...":c.startsWith("anthropic")?"sk-ant-...":c.startsWith("gemini")?"AIzaSy...":"sk-...",Ee=()=>{if(b)return{baseUrl:Q.trim()||"http://127.0.0.1:11434"};if(W)return{baseUrl:L.trim()};if(k)return{azureEndpoint:ue.trim(),deployment:le.trim(),apiVersion:me.trim(),organization:V.trim()||void 0};if(N)return{accountId:F.trim()};if(R)return w==="profile"?{profile:se.trim(),region:C.trim()||"us-east-1"}:{accessKeyId:$.trim(),region:C.trim()||"us-east-1",sessionToken:m.trim()||void 0};if(A||z.length>0){const u={region:I};return H&&r.trim()&&(u.baseUrl=r.trim()),u}},_e=()=>y?!0:R&&w==="profile"?!!se.trim():R&&w==="static"?!!(j.trim()&&$.trim()):k?!!(j.trim()&&ue.trim()&&le.trim()):N?!!(j.trim()&&F.trim()):A?!!(j.trim()&&I):!!j.trim(),Re=async()=>{ke(!0),de(null),Ae(null);try{const u=Ee(),ie=await(await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:n.id,apiKey:j.trim(),providerSpecificData:u})})).json();ie.valid?de("valid"):(de("invalid"),Ae(ie.error||"Validation check failed"))}catch(u){de("invalid"),Ae(u.message||"Connection check error")}finally{ke(!1)}},Fe=async()=>{if(!_e())return;oe(!0),Se(null);const u=K?c==="opencode"||c==="oc"?"OpenCode Free":`${n.name} (Public)`:b?"Ollama Local":W?`${n.name} Local`:R&&w==="profile"?`Bedrock (${se})`:A?`Xiaomi MiMo (${I.toUpperCase()})`:`${n.name} Account`,Ne=D.trim()||u,ie=Ee()||{};Y.trim()&&(ie.tag=Y.trim().toLowerCase());try{const xe=await fetch(`/api/providers/${n.id}/accounts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:Ne,apiKey:j.trim()||(c==="opencode"||c==="oc"?"public":""),providerSpecificData:Object.keys(ie).length>0?ie:void 0})});if(!xe.ok){const Oe=await xe.json().catch(()=>({}));throw new Error(Oe.error||`Server returned ${xe.status}`)}we(),ve(),g(),h()}catch(xe){Se(xe.message||"Failed to save account")}finally{oe(!1)}},Ue=async()=>{if(!v.trim())return;oe(!0),Z(null),Se(null);const u=v.split(`
2
- `),Ne=At(u,t,{isCloudflareAi:N});if(Ne.length===0){Se("No valid keys found in input"),oe(!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 Oe=await ie.json().catch(()=>({}));throw new Error(Oe.error||`Bulk addition failed (${ie.status})`)}const xe=await ie.json();we(),Z({success:xe.count||Ne.length,failed:0}),setTimeout(()=>{ve(),g(),h()},700)}catch(ie){Se(ie.message||"Failed to add bulk keys")}finally{oe(!1)}};return e.jsx(De,{isOpen:l,onClose:Pe,maxWidthClass:"max-w-xl",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Me,{src:n.image,name:n.name,color:n.color,iconBg:n.iconBg,size:"md",fallback:e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[20px]",children:"vpn_key"})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-bold text-white",children:["Add ",n.name," Connection"]}),e.jsx("p",{className:"text-xs text-slate-400",children:S?"Paste session cookie credentials":R?"Configure AWS SSO profile or static keys":k?"Configure Azure OpenAI deployment & endpoint":b?"Connect local self-hosted model service":W?`Connect local ${n.name} model server`:y?"No API key required for this provider":A?"Select cluster region & paste Token Plan API key":"API key is hardware-encrypted (AES-256-GCM)"})]})]}),e.jsx("button",{onClick:Pe,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"})]}),!R&&!b&&!y&&e.jsxs("div",{className:"flex bg-[#0A0D14] p-1 rounded-xl border border-[#1E293B] text-xs",children:[e.jsx("button",{onClick:()=>{B("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:()=>{B("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"&&!R&&!b&&!y?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:N?`name|apiToken|accountId
3
- or just apiToken`:`name|apiKey
4
- or just apiKey (auto-numbered)`})]}),e.jsx("textarea",{value:v,onChange:u=>he(u.target.value),placeholder:N?`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"}),O&&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 ",O.success," connection(s)."]}),Be&&e.jsx("p",{className:"text-xs text-rose-400",children:Be}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{onClick:Ue,disabled:Te||!v.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:Te?"Adding...":"Add All Keys"}),e.jsx("button",{onClick:Pe,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:D,onChange:u=>te(u.target.value),placeholder:b?"Ollama Local":W?`${n.name} Local`:K?"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:Y,onChange:u=>ee(u.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(u=>e.jsx("button",{type:"button",tabIndex:-1,onClick:Ne=>{Ne.preventDefault(),ee(u)},className:`pointer-events-auto text-[10px] px-1.5 py-0.5 rounded font-mono transition-colors ${Y===u?"bg-blue-600 text-white font-semibold":"bg-[#1E293B] text-slate-400 hover:text-slate-200"}`,children:u},u))})]})]})]}),y&&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."]})]}),(A||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(Le,{value:I,onChange:u=>E(u),options:z.map(u=>({value:u.id,label:u.label.includes(u.id)?u.label:`${u.label} (${u.id})`})),className:"w-full",triggerClassName:"bg-[#0F1420] font-mono text-xs py-2"}),A&&e.jsx("p",{className:"text-[11px] text-slate-400 mt-1",children:"Token Plan keys are cluster-specific — select the region matching your subscription."}),H&&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:r,onChange:u=>d(u.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:Q,onChange:u=>J(u.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:Re,disabled:q,className:"rt-btn rt-btn--secondary shrink-0",children:q?"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."]})]})}),W&&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:L,onChange:u=>ae(u.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:Re,disabled:q,className:"rt-btn rt-btn--secondary shrink-0",children:q?"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."]})]})}),k&&e.jsxs("div",{className:"space-y-3 p-3.5 bg-[#0A0D14] border border-[#1E293B] rounded-xl",children:[e.jsx("span",{className:"font-semibold text-blue-400 block",children:"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:ue,onChange:u=>G(u.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:le,onChange:u=>ge(u.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:me,onChange:u=>be(u.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:V,onChange:u=>X(u.target.value),placeholder:"org-id",className:"w-full bg-[#0F1420] border border-[#1E293B] rounded-xl px-3 py-1.5 text-white font-mono"})]})]})]}),N&&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:F,onChange:u=>P(u.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"})]})]})]}),R&&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 ${w==="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 ${w==="static"?"bg-blue-600 text-white":"text-slate-400 hover:text-white"}`,children:"Static Keys (AKIA...)"})]}),w==="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:se,onChange:u=>ye(u.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:C,onChange:u=>ne(u.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 ",se||"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:$,onChange:u=>ce(u.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:C,onChange:u=>ne(u.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:m,onChange:u=>x(u.target.value),placeholder:"FwoGZXIvYXdz...",className:"w-full bg-[#0F1420] border border-[#1E293B] rounded-xl px-3 py-1.5 text-white font-mono"})]})]})]}),!b&&!(R&&w==="profile")&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:S?"Cookie Value":R?"Secret Access Key":N?"Cloudflare API Token":A?"Token Plan Key (tp-...)":y?"API Key (Optional)":"API Key"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:S?"text":"password",value:j,onChange:u=>U(u.target.value),placeholder:re(),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:Re,disabled:q||!_e(),className:"rt-btn rt-btn--secondary shrink-0",children:q?"Checking...":"Check"})]})]}),fe&&e.jsxs("div",{className:`p-2.5 rounded-xl border flex items-center gap-2 ${fe==="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:fe==="valid"?"check_circle":"error"}),e.jsx("span",{children:fe==="valid"?"Credentials verified successfully!":Ce||"Invalid credentials."})]}),Be&&e.jsx("p",{className:"text-xs text-rose-400",children:Be}),e.jsxs("div",{className:"flex gap-2 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{type:"button",onClick:Fe,disabled:Te||!_e(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:Te?"Saving Connection...":"Save Connection"}),e.jsx("button",{type:"button",onClick:Pe,className:"rt-btn rt-btn--secondary",children:"Cancel"})]})]})]})})},Et=({isOpen:l,onClose:n,onSuccess:t})=>{const[h,g]=s.useState("device"),[f,c]=s.useState(null),[K,b]=s.useState(!1),[W,y]=s.useState(!1),[k,N]=s.useState("idle"),[R,S]=s.useState(null),[A,H]=s.useState(""),[z,I]=s.useState(""),[E,M]=s.useState(!1),B=s.useRef(null),D=()=>{B.current&&(clearTimeout(B.current),clearInterval(B.current),B.current=null)};s.useEffect(()=>{if(!l){D(),c(null),N("idle"),H(""),I(""),S(null);return}return H(""),I(""),S(null),h==="device"&&te(),()=>{D()}},[l,h]);const te=async()=>{D(),b(!0),S(null),N("idle");try{const j=await fetch("/api/oauth/github/device-code",{method:"POST"});if(!j.ok){const ae=await j.text();throw new Error(ae||"Failed to initiate GitHub device flow")}const U=await j.json();c(U),N("polling");let Q=Math.max(U.interval||5,5),J=!0;const L=ae=>{B.current&&clearTimeout(B.current),B.current=setTimeout(async()=>{if(J)try{const G=await(await fetch("/api/oauth/github/poll",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:U.device_code})})).json();if(G.ok){J=!1,N("success"),setTimeout(()=>{t(),n()},1200);return}if(G.error==="slow_down"){Q=Math.min(Q+5,30),L(Q);return}if(G.error==="authorization_pending"){L(Q);return}J=!1,N("error"),S(G.error_description||G.error)}catch{J&&L(Q)}},ae*1e3)};L(Q)}catch(j){N("error"),S(j.message||"Failed to request device code")}finally{b(!1)}},Y=j=>{navigator.clipboard.writeText(j),y(!0),setTimeout(()=>y(!1),2e3)},ee=async()=>{if(A.trim()){M(!0),S(null);try{const j=await fetch("/api/oauth/github/token",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:A.trim(),name:z.trim()||void 0})});if(!j.ok){const U=await j.json().catch(()=>({}));throw new Error(U.error||"Failed to save GitHub token")}t(),n()}catch(j){S(j.message||"Could not save token")}finally{M(!1)}}};return l?e.jsx(De,{isOpen:l,onClose:n,maxWidthClass:"max-w-lg",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Me,{src:"/assets/providers/github/icon.png",name:"GitHub Copilot",color:"#333333",iconBg:"#FFFFFF",size:"md"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-white",children:"Connect GitHub Copilot"}),e.jsx("p",{className:"text-xs text-slate-400",children:"Authorize via official GitHub Device Flow"})]})]}),e.jsx("button",{onClick:n,className:"text-slate-400 hover:text-white p-1 rounded-lg hover:bg-white/10",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),e.jsxs("div",{className:"flex bg-[#0A0D14] p-1 rounded-xl border border-[#1E293B] text-xs",children:[e.jsx("button",{onClick:()=>g("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:()=>g("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:[K?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:()=>Y(f.user_code),className:"rt-btn rt-btn--secondary py-1 text-xs",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:W?"check":"content_copy"}),W?"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"})]})]}),k==="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..."})]}),k==="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,R&&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:R})]})]}):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:j=>I(j.target.value),placeholder:"Copilot Work Account",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"GitHub Access Token or Copilot Token"}),e.jsx("input",{type:"password",value:A,onChange:j=>H(j.target.value),placeholder:"ghu_... or ghp_...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500 font-mono"}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-1.5",children:"Paste your GitHub token from VS Code extension or personal token. Mapigate encrypts it locally."})]}),R&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:R}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{onClick:ee,disabled:E||!A.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},Dt=({isOpen:l,onClose:n,onSuccess:t})=>{const[h,g]=s.useState(""),[f,c]=s.useState(""),[K,b]=s.useState(""),[W,y]=s.useState(!1),[k,N]=s.useState(!1),[R,S]=s.useState(null),[A,H]=s.useState(!1);s.useEffect(()=>{if(!l){g(""),c(""),b(""),N(!1),S(null);return}b(""),S(null),z()},[l]);const z=async()=>{y(!0),N(!1),S(null);try{const M=await(await fetch("/api/oauth/cursor/auto-import")).json();M.found?(g(M.accessToken||""),c(M.machineId||""),N(!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{y(!1)}},I=async()=>{if(h.trim()){H(!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:K.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{H(!1)}}};return l?e.jsx(De,{isOpen:l,onClose:n,maxWidthClass:"max-w-lg",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Me,{src:"/assets/providers/cursor/icon.png",name:"Cursor",color:"#00D4AA",iconBg:"#FFFFFF",size:"md"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-white",children:"Connect Cursor IDE"}),e.jsx("p",{className:"text-xs text-slate-400",children:"Import session token from local Cursor database"})]})]}),e.jsx("button",{onClick:n,className:"text-slate-400 hover:text-white p-1 rounded-lg hover:bg-white/10",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),W?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:[k&&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:K,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=>g(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=>c(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"})]}),R&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:R}),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:I,disabled:A||!h.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:A?"Saving...":"Save Connection"})]})]})]})}):null},Tt=({isOpen:l,onClose:n,onSuccess:t})=>{const[h,g]=s.useState("builder-id"),[f,c]=s.useState(null),[K,b]=s.useState(!1),[W,y]=s.useState(!1),k=s.useRef(null),[N,R]=s.useState(""),[S,A]=s.useState("us-east-1"),[H,z]=s.useState(""),[I,E]=s.useState(""),[M,B]=s.useState(""),[D,te]=s.useState(!1),[Y,ee]=s.useState(!1),[j,U]=s.useState(null),[Q,J]=s.useState(""),[L,ae]=s.useState(""),[ue,G]=s.useState("us-east-1"),[le,ge]=s.useState(""),[me,be]=s.useState("us-east-1"),[V,X]=s.useState(""),[F,P]=s.useState(!1),[r,d]=s.useState(null),w=s.useCallback(()=>{k.current&&clearInterval(k.current),c(null),b(!1),y(!1),R(""),A("us-east-1"),z(""),E(""),B(""),te(!1),ee(!1),U(null),J(""),ae(""),G("us-east-1"),ge(""),be("us-east-1"),X(""),P(!1),d(null)},[]);s.useEffect(()=>{if(!l){w();return}w(),h==="import"&&ye()},[l,h,w]),s.useEffect(()=>()=>{k.current&&clearInterval(k.current)},[]);const pe=m=>{navigator.clipboard.writeText(m),y(!0),setTimeout(()=>y(!1),2e3)},se=async m=>{P(!0),d(null),c(null);try{const x=await fetch("/api/oauth/kiro/device-code",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...m,name:m.name||V.trim()||void 0})});if(!x.ok){const O=await x.json().catch(()=>({}));throw new Error(O.error||"Failed to start AWS device authorization")}const v=await x.json();c(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);k.current&&clearInterval(k.current),k.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?(k.current&&clearInterval(k.current),b(!1),t(),n()):Z.error&&!Z.pending&&(k.current&&clearInterval(k.current),b(!1),d(Z.error))}catch{}},he)}catch(x){d(x.message||"Failed to start device flow")}finally{P(!1)}},ye=async()=>{te(!0),ee(!1),d(null);try{const x=await(await fetch("/api/oauth/kiro/auto-import")).json();x.found&&(x.refreshToken||x.accessToken)?(x.refreshToken&&E(x.refreshToken),x.accessToken&&B(x.accessToken),ee(!0),x.clientId&&x.clientSecret&&U({clientId:x.clientId,clientSecret:x.clientSecret,region:x.region||"us-east-1",authMethod:x.authMethod||"idc",profileArn:x.profileArn})):d(x.error||"Could not auto-detect token from ~/.aws/sso/cache")}catch(m){d(m.message||"Failed to scan AWS SSO cache")}finally{te(!1)}},C=async()=>{const m=I.trim(),x=M.trim();if(!m&&!x){d("Please provide a refresh token or access token");return}P(!0),d(null);try{const v=await fetch("/api/oauth/kiro/import",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:m||void 0,accessToken:x||void 0,name:V.trim()||void 0,...j||{}})});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{P(!1)}},ne=async()=>{const m=N.trim();if(!m){d("Please enter your Access Token (aoa... or JWT)");return}P(!0),d(null);try{const x=await fetch("/api/oauth/kiro/access-token",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({accessToken:m,name:V.trim()||(m.startsWith("aoa")?"Kiro Education Token (aoa)":void 0),region:S.trim()||"us-east-1",profileArn:H.trim()||void 0})});if(!x.ok){const v=await x.json().catch(()=>({}));throw new Error(v.error||"Failed to save Access Token")}t(),n()}catch(x){d(x.message||"Failed to save Access Token")}finally{P(!1)}},$=async()=>{const m=Q.trim();if(!m){d("Please paste the External IDP / CLIProxy auth JSON");return}P(!0),d(null);try{const x=await fetch("/api/oauth/kiro/import-cli-proxy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({json:m,name:V.trim()||void 0})});if(!x.ok){const v=await x.json().catch(()=>({}));throw new Error(v.error||"Failed to import External IDP JSON")}t(),n()}catch(x){d(x.message||"Import failed")}finally{P(!1)}},ce=async()=>{if(le.trim()){P(!0),d(null);try{const m=await fetch("/api/oauth/kiro/api-key",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:le.trim(),region:me.trim()||"us-east-1",name:V.trim()||void 0})});if(!m.ok){const x=await m.json().catch(()=>({}));throw new Error(x.error||"Failed to save Kiro API key")}t(),n()}catch(m){d(m.message||"Could not save API key")}finally{P(!1)}}};return l?e.jsx(De,{isOpen:l,onClose:n,maxWidthClass:"max-w-lg",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Me,{src:"/assets/providers/kiro/icon.png",name:"Kiro",color:"#FF9900",size:"md"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-white",children:"Connect Kiro IDE"}),e.jsx("p",{className:"text-xs text-slate-400",children:"Builder ID, Access Token, Import, External IDP, IDC, API Key"})]})]}),e.jsx("button",{onClick:n,className:"text-slate-400 hover:text-white p-1 rounded-lg hover:bg-white/10",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),e.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 bg-[#0A0D14] p-1 rounded-xl border border-[#1E293B] text-[11px] gap-1",children:[e.jsx("button",{onClick:()=>{g("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:()=>{g("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:()=>{g("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:()=>{g("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:()=>{g("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:()=>{g("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:W?"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"})]}),K&&e.jsxs("div",{className:"flex items-center justify-center gap-2 text-slate-400 text-[11px]",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] animate-spin text-blue-400",children:"progress_activity"}),e.jsx("span",{children:"Waiting for approval in AWS portal..."})]})]}),e.jsx("div",{className:"flex gap-2 pt-2",children:e.jsx("button",{type:"button",onClick:()=>{c(null),b(!1)},className:"w-full rt-btn rt-btn--secondary",children:"Restart Flow"})})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"p-2.5 rounded-xl bg-orange-500/10 border border-orange-500/20 text-orange-300 text-[11px] leading-relaxed",children:e.jsxs("p",{children:["Recommended for personal accounts. Click ",e.jsx("strong",{children:"Start Builder ID Login"})," to authorize via browser device code."]})}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Account Label"}),e.jsx("input",{type:"text",value:V,onChange:m=>X(m.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"})]}),r&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:r}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>se({authMethod:"builder-id",startUrl:"https://view.awsapps.com/start",name:V.trim()||void 0}),disabled:F,className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:F?"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:V,onChange:m=>X(m.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:N,onChange:m=>R(m.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:m=>A(m.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:H,onChange:m=>z(m.target.value),placeholder:"arn:aws:codewhisperer...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white font-mono"})]})]}),r&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:r}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:ne,disabled:F||!N.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:F?"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:[D?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:[Y&&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:V,onChange:m=>X(m.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:I,onChange:m=>E(m.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:m=>B(m.target.value),placeholder:"aoaAAAAAG...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white font-mono"})]})]}),r&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:r}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsxs("button",{type:"button",onClick:ye,className:"rt-btn rt-btn--secondary",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"refresh"}),"Re-detect"]}),e.jsx("button",{type:"button",onClick:C,disabled:F||!I.trim()&&!M.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:F?"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:V,onChange:m=>X(m.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:Q,onChange:m=>J(m.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]"})]}),r&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:r}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:$,disabled:F||!Q.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:F?"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:W?"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"})]}),K&&e.jsxs("div",{className:"flex items-center justify-center gap-2 text-slate-400 text-[11px]",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] animate-spin text-blue-400",children:"progress_activity"}),e.jsx("span",{children:"Waiting for approval from Identity Center..."})]})]}),e.jsx("div",{className:"flex gap-2 pt-2",children:e.jsx("button",{type:"button",onClick:()=>{c(null),b(!1)},className:"w-full rt-btn rt-btn--secondary",children:"Restart Flow"})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Account Label"}),e.jsx("input",{type:"text",value:V,onChange:m=>X(m.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:L,onChange:m=>ae(m.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:ue,onChange:m=>G(m.target.value),placeholder:"us-east-1",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white font-mono"})]}),r&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:r}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>{if(!L.trim()){d("Please enter your IDC start URL");return}se({authMethod:"idc",startUrl:L.trim(),region:ue.trim()||"us-east-1",name:V.trim()||void 0})},disabled:F||!L.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:F?"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:V,onChange:m=>X(m.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:le,onChange:m=>ge(m.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:me,onChange:m=>be(m.target.value),placeholder:"us-east-1",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white font-mono"})]}),r&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:r}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:ce,disabled:F||!le.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:F?"Saving...":"Save Connection"}),e.jsx("button",{type:"button",onClick:n,className:"rt-btn rt-btn--secondary",children:"Cancel"})]})]})]})}):null};async function Bt(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 Pt=({isOpen:l,provider:n,existingModels:t,onAddAccount:h,onClose:g,onApplyModels:f})=>{var F,P;const[c,K]=s.useState(!1),[b,W]=s.useState([]),[y,k]=s.useState(new Set),[N,R]=s.useState(null),[S,A]=s.useState([]),[H,z]=s.useState([]),[I,E]=s.useState(!1),[M,B]=s.useState(null),[D,te]=s.useState(""),Y=n.modelsUrl||n.baseUrl||"",[ee,j]=s.useState(!1),[U,Q]=s.useState(Y),J=s.useCallback(async r=>{K(!0),B(null),E(!1);try{const d=await Bt({providerId:n.id,baseUrl:(r!==void 0?r:U).trim()||void 0});if(d.success){if(W(d.models),R(d.endpointUrl||null),A(d.scannedAccounts||[]),z(d.failedAccounts||[]),E(!1),k(new Set(d.models.map(w=>w.id))),d.models.length>0){const w=d.models.map(se=>se.id);w.some(se=>!t.includes(se))&&f(w,"merge")}}else W([]),R(null),A([]),z(d.failedAccounts||[]),d.noAccountsConfigured&&E(!0),B(d.error||"Failed to scan models from upstream provider.")}catch(d){const w=d instanceof Error?d.message:String(d);B(w)}finally{K(!1)}},[n.id,U]);s.useEffect(()=>{if(l){const r=n.modelsUrl||n.baseUrl||"";Q(r),te(""),j(!1),A([]),z([]),E(!1),J(r||void 0)}else W([]),k(new Set),B(null),R(null),A([]),z([]),E(!1)},[l,n.id,n.baseUrl,n.modelsUrl,J]);const L=s.useMemo(()=>{let r=b;if(D.trim()){const d=D.toLowerCase();r=b.filter(w=>w.id.toLowerCase().includes(d)||w.name&&w.name.toLowerCase().includes(d)||w.description&&w.description.toLowerCase().includes(d))}return[...r].sort((d,w)=>(d.name||d.id).localeCompare(w.name||w.id,void 0,{sensitivity:"base"}))},[b,D]),ae=r=>{const d=new Set(y);d.has(r)?d.delete(r):d.add(r),k(d)},ue=()=>{k(new Set(L.map(r=>r.id)))},G=()=>{k(new Set)},le=L.length>0&&L.every(r=>y.has(r.id)),ge=L.some(r=>y.has(r.id)),me=r=>{r?ue():G()},be=r=>{const d=b.filter(w=>y.has(w.id)).map(w=>w.id);f(d,r),g()},V=s.useMemo(()=>b.filter(r=>!t.includes(r.id)).length,[b,t]),X=s.useMemo(()=>b.filter(r=>t.includes(r.id)).length,[b,t]);return e.jsx(De,{isOpen:l,onClose:g,maxWidthClass:"max-w-2xl",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Me,{src:n.image,name:n.name,color:n.color,iconBg:n.iconBg,size:"md",fallback:e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[20px]",children:"radar"})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:["Scan Models from Provider API",e.jsx("span",{className:"text-[10px] font-mono px-2 py-0.5 rounded bg-blue-500/10 text-blue-400 border border-blue-500/20",children:n.name})]}),e.jsx("p",{className:"text-xs text-slate-400 mt-0.5",children:"Automatically probe and import live available models using your configured accounts."})]})]}),e.jsxs("button",{onClick:()=>J(),disabled:c,className:"rt-btn rt-btn--secondary text-xs flex items-center gap-1.5",title:"Rescan",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${c?"animate-spin":""}`,children:"sync"}),c?"Scanning...":"Rescan"]})]}),(S.length>0||H.length>0||N)&&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(r=>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:r.name},r.id))]}),H.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:H.length===1?(P=(F=H[0])==null?void 0:F.error)!=null&&P.toLowerCase().includes("auth")?"1 account failed to authenticate:":"1 account failed to scan:":H.every(r=>{var d;return(d=r.error)==null?void 0:d.toLowerCase().includes("auth")})?`${H.length} accounts failed to authenticate:`:`${H.length} accounts failed to scan:`}),H.map(r=>e.jsx("span",{title:r.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:r.name},r.id))]}),N&&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:N})]})]}),I&&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:()=>{g(),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&&!I&&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:()=>j(!ee),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:ee?"expand_less":"expand_more"})]}),ee&&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:U,onChange:r=>Q(r.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:()=>J(),disabled:c,className:"rt-btn rt-btn--primary text-xs",children:"Apply & Scan"})})]})]}),c&&e.jsxs("div",{className:"py-12 flex flex-col items-center justify-center gap-3 text-center",children:[e.jsx("div",{className:"relative size-12 flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-3xl text-blue-400 animate-spin",children:"sync"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-white",children:"Probing provider endpoints..."}),e.jsx("p",{className:"text-[11px] text-slate-500 font-mono mt-0.5",children:"Querying /v1/models with configured credentials"})]})]}),!c&&b.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2.5",children:[e.jsx("div",{className:"flex items-center gap-2 flex-1 min-w-[200px]",children:e.jsxs("div",{className:"relative w-full",children:[e.jsx("span",{className:"material-symbols-outlined absolute left-2.5 top-1/2 -translate-y-1/2 text-[16px] text-slate-500",children:"search"}),e.jsx("input",{type:"text",placeholder:"Search discovered models...",value:D,onChange:r=>te(r.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"}),D&&e.jsx("button",{type:"button",onClick:()=>te(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-slate-500 hover:text-white transition-colors cursor-pointer flex items-center justify-center",title:"Clear search",children:e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"close"})})]})}),e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[e.jsx(tt,{size:"sm",checked:le,indeterminate:ge&&!le,onChange:me,label:e.jsx("span",{className:"text-xs font-medium text-slate-300",children:"Select All"})}),e.jsx("button",{type:"button",onClick:G,className:"px-2.5 py-1 rounded-md bg-white/5 hover:bg-white/10 text-slate-400 hover:text-slate-200 text-[11px] transition-colors cursor-pointer",children:"Deselect All"})]})]}),e.jsxs("div",{className:"flex items-center justify-between text-[11px] text-slate-400 px-1 font-mono",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{children:["Discovered: ",e.jsx("strong",{className:"text-white",children:b.length})]}),e.jsx("span",{children:"•"}),e.jsxs("span",{className:"text-emerald-400",children:[V," new"]}),e.jsx("span",{children:"•"}),e.jsxs("span",{className:"text-slate-500",children:[X," existing"]})]}),e.jsx("div",{children:e.jsxs("span",{children:["Selected: ",e.jsx("strong",{className:"text-blue-400",children:y.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:L.length===0?e.jsxs("div",{className:"py-6 text-center text-xs text-slate-500",children:['No models match "',D,'"']}):L.map(r=>{var pe,se;const d=y.has(r.id),w=t.includes(r.id);return e.jsxs("div",{onClick:()=>ae(r.id),className:`flex items-center justify-between p-2 rounded-lg border text-xs cursor-pointer transition-colors ${d?"bg-blue-500/10 border-blue-500/40 text-white":"bg-[#0D1322] border-[#1E293B] hover:border-slate-700 text-slate-300"}`,children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx(tt,{size:"sm",checked:d,onChange:()=>ae(r.id),onClick:ye=>ye.stopPropagation()}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"font-mono font-medium truncate block",children:r.id}),r.name&&r.name!==r.id&&e.jsx("span",{className:"text-[10px] text-slate-500 truncate block",children:r.name})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[((pe=r.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"}),((se=r.capabilities)==null?void 0:se.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"}),w?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"})]})]},r.id)})})]}),!c&&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:g,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:y.size===0,onClick:()=>be("replace"),className:"rt-btn rt-btn--secondary text-xs disabled:opacity-40",title:"Replace current provider models list with selected models",children:["Replace Existing (",y.size,")"]}),e.jsxs("button",{type:"button",disabled:y.size===0,onClick:()=>be("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 (",y.size,")"]})]})]})]})})},Ht=({provider:l,onBack:n})=>{var Ge,qe,Ye,Qe,Xe,Ze;const t=st(l.id),[h,g]=s.useState([]),[f,c]=s.useState([]),K=s.useMemo(()=>[...f].sort((a,o)=>a.localeCompare(o,void 0,{sensitivity:"base"})),[f]),[b,W]=s.useState((t==null?void 0:t.models)||[]),[y,k]=s.useState(null),[N,R]=s.useState("1"),[S,A]=s.useState((t==null?void 0:t.thinkingMode)||"auto"),[H,z]=s.useState((t==null?void 0:t.thinkingOptions)||["auto","none","low","medium","high"]),[I,E]=s.useState(l.format||(t==null?void 0:t.format)||"openai"),[M,B]=s.useState([]),[D,te]=s.useState((t==null?void 0:t.baseUrl)||l.baseUrl||""),[Y,ee]=s.useState(""),[j,U]=s.useState([]),[Q,J]=s.useState(!1),[L,ae]=s.useState(!1),[ue,G]=s.useState(!1),[le,ge]=s.useState(!1),[me,be]=s.useState(!1),[V,X]=s.useState(!1),[F,P]=s.useState(!1),[r,d]=s.useState(""),[w,pe]=s.useState(null),[se,ye]=s.useState(null),[C,ne]=s.useState({}),[$,ce]=s.useState(!1),[m,x]=s.useState(!1),[v,he]=s.useState(null),[O,Z]=s.useState(""),[q,ke]=s.useState(""),[fe,de]=s.useState(null),[Ce,Ae]=s.useState(null),[Te,oe]=s.useState(!1),[Be,Se]=s.useState(!1),[ve,Pe]=s.useState(null),[re,Ee]=s.useState(null),[_e,Re]=s.useState(""),Fe=l.category==="custom"||!t,Ue=(t==null?void 0:t.authType)==="cookie"||(t==null?void 0:t.category)==="webCookie"||l.category==="webCookie",u=!Ue&&(et(t)||et(l)),Ne=!Ue&&(Array.isArray(t==null?void 0:t.authModes)?t.authModes.includes("apikey"):!!((t==null?void 0:t.category)==="apikey"||(Ge=t==null?void 0:t.notice)!=null&&Ge.apiKeyUrl||l.category==="apikey"&&!["antigravity","cursor","github","kiro"].includes(l.id))),ie=()=>{if(l.id==="github"){G(!0);return}if(l.id==="cursor"){ge(!0);return}if(l.id==="kiro"){be(!0);return}ae(!0)},xe=s.useCallback(()=>{const a=(t==null?void 0:t.defaultHeaders)||{},o=Object.entries(a).map(([i,T])=>({key:i,value:String(T)})),p=((t==null?void 0:t.models)||[]).map(i=>i.id);fetch(`/api/providers/${l.id}`).then(i=>i.json()).then(i=>{i.format&&E(i.format),Array.isArray(i.supportedFormats)&&i.supportedFormats.length>0?B(i.supportedFormats.map(_=>typeof _=="string"?{value:_,label:_.toUpperCase()}:_)):Array.isArray(t==null?void 0:t.supportedFormats)&&t.supportedFormats.length>0?B(t.supportedFormats.map(_=>typeof _=="string"?{value:_,label:_.toUpperCase()}:_)):B([]),i.baseUrl&&te(i.baseUrl),i.proxyUrl&&ee(i.proxyUrl),i.thinkingMode&&A(i.thinkingMode),Array.isArray(i.thinkingOptions)&&i.thinkingOptions.length>0&&z(i.thinkingOptions),i.strategy!==void 0&&k(i.strategy||null),i.stickyLimit!=null&&R(String(i.stickyLimit));const T=i.userCustomHeaders!==void 0?i.userCustomHeaders:i.customHeaders||{};T&&Object.keys(T).length>0?U(Object.entries(T).map(([_,je])=>({key:_,value:String(je)}))):U([]),Array.isArray(i.catalogModels)&&i.catalogModels.length>0&&W(i.catalogModels),Array.isArray(i.models)&&i.models.length>0?c(i.models):c(p),i.accounts&&i.accounts.length>0?g(i.accounts.map((_,je)=>{var $e;return{id:_.id,name:_.name,tag:_.tag||(($e=_.providerSpecificData)==null?void 0:$e.tag),supportedModelsCount:_.supportedModelsCount,isActive:_.isActive,order:_.sortOrder??je,providerSpecificData:_.providerSpecificData}})):g([]),we()}).catch(()=>{U(o),c(p),g([])})},[l.id,l.name,t]);s.useEffect(()=>{xe()},[xe]);const Oe=async(a,o)=>{try{await fetch(`/api/providers/${l.id}/strategy`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({strategy:a||null,stickyLimit:a==="round-robin"?Number(o)||1:null})})}catch(p){console.warn("Failed to save provider strategy:",p)}},at=async a=>{const o=h.map(p=>p.id===a?{...p,isActive:!p.isActive}:p);g(o);try{await fetch(`/api/providers/${l.id}/accounts/${a}/toggle`,{method:"PUT"}),we()}catch{}},Ke=(a,o)=>{if(o==="up"&&a===0||o==="down"&&a===h.length-1)return;const p=o==="up"?a-1:a+1,i=[...h],T=i[a];i[a]=i[p],i[p]=T;const _=i.map((je,$e)=>({...je,order:$e}));g(_),fetch(`/api/providers/${l.id}/accounts/reorder`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({accountIds:_.map(je=>je.id)})}).then(je=>{je.ok||console.error("Failed to reorder accounts:",je.status),we()}).catch(je=>{console.error("Failed to reorder accounts:",je)})},lt=a=>{g(h.filter(o=>o.id!==a)),fetch(`/api/providers/${l.id}/accounts/${a}`,{method:"DELETE"}).then(()=>we()).catch(()=>{})},nt=a=>{Pe({id:a.id,providerId:l.id,name:a.name,isActive:a.isActive,providerSpecificData:a.providerSpecificData})},ot=async a=>{if(!ve)return;const o=await fetch(`/api/providers/${l.id}/accounts/${ve.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!o.ok){const p=await o.json().catch(()=>({}));throw new Error(p.error||"Failed to update account.")}xe(),we()},ze=async(a,o)=>{o!==void 0&&pe(o),ye(a.id);try{const i=await(await fetch(`/api/providers/${l.id}/accounts/${a.id}/test`,{method:"POST"})).json();ne(T=>({...T,[a.id]:{success:!!i.success,message:i.message||(i.success?"Connection verified":"Connection failed"),latencyMs:i.latencyMs}}))}catch(p){ne(i=>({...i,[a.id]:{success:!1,message:p.message||"Failed to reach gateway"}}))}finally{o!==void 0&&pe(null),ye(null)}},rt=async()=>{if(!(m||h.length===0)){x(!0);try{for(let a=0;a<h.length;a++){const o=h[a];await ze(o,a)}}finally{pe(null),x(!1)}}},He=async()=>{ce(!0),he(null);try{const o=await(await fetch(`/api/providers/${l.id}/test`,{method:"POST"})).json();he({success:!!o.success,message:o.message||(o.success?"Connection successful!":"Connection failed."),latencyMs:o.latencyMs})}catch(a){he({success:!1,message:`Error testing connection: ${a.message}`})}finally{ce(!1)}},it=()=>{O.trim()&&(U([...j,{key:O.trim(),value:q.trim()}]),Z(""),ke(""))},We=a=>{U(j.filter((o,p)=>p!==a))},Ie=(a,o,p)=>{const i=[...j];i[a]={key:o,value:p},U(i)},ct=()=>{U([]),de("Reset custom headers. Using system defaults."),setTimeout(()=>de(null),3e3)},dt=(a,o)=>{j.findIndex(i=>i.key.trim().toLowerCase()===a.toLowerCase())>=0||U([...j,{key:a,value:o}])},xt=a=>{U(j.filter(o=>o.key.trim().toLowerCase()!==a.toLowerCase()))},ut=a=>{const o=j.filter(p=>p.key.trim().toLowerCase()!==a.toLowerCase());U([...o,{key:a,value:""}])},mt=a=>{U(j.filter(o=>o.key.trim().toLowerCase()!==a.toLowerCase()))},pt=()=>{if(!r.trim())return;const a=r.trim();f.includes(a)||c([...f,a]),d(""),X(!1)},ht=a=>{c(f.filter(o=>o!==a))},bt=async(a,o)=>{let p;if(o==="replace")p=a;else{const T=new Set(f),_=a.filter(je=>!T.has(je));p=[...f,..._]}c(p);const i={};j.forEach(T=>{T.key.trim()&&(i[T.key.trim()]=T.value.trim())});try{await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:l.id,name:l.name,baseUrl:D||l.baseUrl||(t==null?void 0:t.baseUrl)||"https://api.openai.com",format:I||l.format||(t==null?void 0:t.format)||"openai",customHeaders:i,proxyUrl:Y.trim()||void 0,thinkingMode:S,strategy:y,stickyLimit:y==="round-robin"?Number(N)||1:null,models:p})}),de(`Saved ${p.length} models for ${l.name}.`),we(),xe(),setTimeout(()=>de(null),3e3)}catch{}},ft=a=>{navigator.clipboard.writeText(a),Ae(a),setTimeout(()=>{Ae(o=>o===a?null:o)},2e3)},Je=async()=>{const a={};j.forEach(o=>{o.key.trim()&&(a[o.key.trim()]=o.value.trim())});try{await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:l.id,name:l.name,baseUrl:D||l.baseUrl||(t==null?void 0:t.baseUrl)||"https://api.openai.com",format:I||l.format||(t==null?void 0:t.format)||"openai",customHeaders:a,proxyUrl:Y.trim()||void 0,thinkingMode:S,strategy:y,stickyLimit:y==="round-robin"?Number(N)||1:null,models:f})}),de("Configuration saved successfully."),we(),setTimeout(()=>de(null),3e3)}catch{}},gt=async()=>{Se(!0);try{(await fetch(`/api/providers/${l.id}`,{method:"DELETE"})).ok&&(we(),n())}catch{}finally{Se(!1),oe(!1)}},Ve=((qe=t==null?void 0:t.notice)==null?void 0:qe.apiKeyUrl)||((Ye=t==null?void 0:t.notice)==null?void 0:Ye.signupUrl)||(t==null?void 0:t.website),jt=(Qe=t==null?void 0:t.notice)!=null&&Qe.apiKeyUrl?"Get API Key":"Sign up / Learn more";return e.jsxs("div",{className:"space-y-6 w-full px-2 sm:px-4 pb-16 animate-rt-fade-in",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{type:"button",onClick:a=>{a.preventDefault(),a.stopPropagation(),n()},className:"flex items-center gap-1.5 text-xs font-semibold text-slate-400 hover:text-blue-400 transition-colors cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"arrow_back"}),"Back to Providers"]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3.5",children:[e.jsx(Me,{src:l.image,name:l.name,color:(t==null?void 0:t.color)||l.color,iconBg:(t==null?void 0:t.iconBg)||l.iconBg,size:"lg"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2.5 flex-wrap",children:[e.jsx("h2",{className:"text-xl font-bold text-white tracking-tight",children:l.name}),e.jsx("span",{className:"text-[11px] font-mono px-2 py-0.5 rounded bg-[#1E293B] text-slate-300",children:(t==null?void 0:t.format)||l.format||"openai"}),Ve&&e.jsxs("a",{href:Ve,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-blue-400 hover:text-blue-300 hover:underline inline-flex items-center gap-1 font-medium transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"open_in_new"}),jt]})]}),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:He,disabled:$,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] ${$?"animate-spin text-blue-400":""}`,children:$?"sync":"speed"}),$?"Testing...":"Test Connection"]}),e.jsxs("button",{onClick:Je,className:"rt-btn rt-btn--primary",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"save"}),"Save Provider Settings"]})]})]})]}),v&&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 ${v.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:v.success?"check_circle":"error"}),e.jsx("span",{className:"truncate",children:v.message})]}),v.latencyMs&&e.jsxs("span",{className:"shrink-0 font-bold opacity-80",children:[v.latencyMs,"ms"]})]}),(t==null?void 0:t.deprecated)&&e.jsxs("div",{className:"flex items-start gap-2.5 px-4 py-3 rounded-xl bg-amber-500/10 border border-amber-500/30 text-xs text-amber-300 leading-relaxed animate-rt-scale-in",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] text-amber-400 mt-0.5 shrink-0",children:"warning"}),e.jsx("p",{children:t.deprecationNotice||"This provider uses an undocumented or risk-prone connection session. Use at your own risk."})]}),((Xe=t==null?void 0:t.notice)==null?void 0:Xe.text)&&!(t!=null&&t.deprecated)&&e.jsxs("div",{className:"flex flex-col gap-2 rounded-xl border border-blue-500/30 bg-blue-500/10 px-4 py-3 sm:flex-row sm:items-center text-xs animate-rt-scale-in",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] text-blue-400 shrink-0",children:"info"}),e.jsx("p",{className:"min-w-0 flex-1 text-blue-300 leading-relaxed",children:t.notice.text}),t.notice.apiKeyUrl&&e.jsx("a",{href:t.notice.apiKeyUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex justify-center rounded bg-blue-500 px-2.5 py-1 text-xs font-medium text-white transition-colors hover:bg-blue-600 shrink-0",children:"Get API Key →"})]}),(l.id==="opencode"||(t==null?void 0:t.noAuth)||(t==null?void 0:t.requiresApiKey)===!1||(t==null?void 0:t.authType)==="none"||(t==null?void 0:t.isLocal))&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-3 px-4 py-3.5 rounded-xl bg-emerald-500/10 border border-emerald-500/30 text-xs text-emerald-300 animate-rt-scale-in",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-emerald-400 shrink-0",children:"check_circle"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-white",children:t!=null&&t.isLocal?"Local Provider (No Paid Key Required)":"No Authentication Required (100% Free)"}),e.jsx("p",{className:"text-slate-400 mt-0.5",children:t!=null&&t.isLocal?`${l.name} runs directly on your local device without external API tokens.`:`${l.name} is ready to use immediately without an account or API key.`})]})]}),e.jsxs("button",{onClick:He,disabled:$,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] ${$?"animate-spin":""}`,children:$?"sync":"speed"}),$?"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:rt,disabled:m||w!==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] ${m||w!==null?"animate-spin text-blue-400":""}`,children:"sync"}),m?"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(Le,{value:y||"",onChange:a=>{const o=a||null;k(o);const p=o==="round-robin"?N||"1":N;o==="round-robin"&&!N&&R("1"),Oe(o,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"}),y==="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:N,onChange:a=>{const o=a.target.value;R(o),Oe("round-robin",o)},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:u?"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:u?`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,o)=>{const p=C[a.id],i=w===o||se===a.id;return e.jsxs("div",{className:"flex flex-col gap-2 p-3 rounded-xl bg-[#0A0D14] border border-[#1E293B] hover:border-blue-500/30 transition-all text-xs",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsxs("div",{className:"flex flex-col text-slate-500",children:[e.jsx("button",{onClick:()=>Ke(o,"up"),disabled:o===0,className:"hover:text-white disabled:opacity-30 leading-none cursor-pointer",children:"▲"}),e.jsx("button",{onClick:()=>Ke(o,"down"),disabled:o===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:u?"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:()=>{Ee({accountId:a.id,accountName:a.name,models:[],scanned:!0,loading:!0}),Re(""),fetch(`/api/providers/${l.id}/accounts/${a.id}/models`).then(T=>T.json()).then(T=>{Ee(_=>_&&_.accountId===a.id?{..._,models:T.models||[],scanned:!!T.scanned,loading:!1}:_)}).catch(()=>{Ee(T=>T&&T.accountId===a.id?{...T,loading:!1}:T)})},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"," • #",o+1]}),i&&e.jsx("span",{className:"text-[10px] text-blue-400 animate-pulse font-mono",children:"Testing upstream..."}),p&&!i&&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:()=>ze(a,o),disabled:w!==null||i,className:"p-1 text-slate-500 hover:text-blue-400 transition-colors cursor-pointer disabled:opacity-40",children:e.jsx("span",{className:`material-symbols-outlined text-[16px] ${i?"animate-spin text-blue-400":""}`,children:i?"sync":"speed"})}),e.jsx("button",{title:"Edit account",onClick:()=>nt(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:()=>lt(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:()=>at(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)})}),u&&Ne?e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsxs("button",{onClick:ie,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:()=>J(!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:()=>{u||["github","cursor","kiro","antigravity"].includes(l.id)?ie():J(!0)},className:"rt-btn rt-btn--primary",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:u||l.id==="github"||l.id==="cursor"||l.id==="kiro"?"lock":Ue?"cookie":"add"}),u||l.id==="github"||l.id==="cursor"||l.id==="kiro"?`Connect ${l.name}`:Ue?"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:ct,className:"rt-btn rt-btn--secondary text-xs",title:"Reset custom headers and use system defaults",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"restart_alt"}),"Reset"]}),e.jsxs("button",{onClick:Je,className:"rt-btn rt-btn--primary text-xs",title:"Save headers",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"save"}),"Save"]})]})]}),fe&&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"}),fe]}),(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,o])=>{const p=j.find(_=>_.key.trim().toLowerCase()===a.toLowerCase()),i=p!==void 0&&p.value==="",T=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:i?"text-slate-600 line-through":"text-blue-400 font-semibold",children:a}),e.jsx("span",{className:"text-slate-600",children:":"}),e.jsx("span",{className:i||T?"text-slate-500 line-through truncate":"text-slate-300 truncate",children:o}),T&&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:i?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-rose-500/10 text-rose-400 border border-rose-500/20 font-sans font-semibold",children:"Disabled / Omitted"}),e.jsxs("button",{type:"button",onClick:()=>mt(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"]})]}):T?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:()=>xt(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:()=>dt(a,o),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:()=>ut(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:[j.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:j.map((a,o)=>{const p=!!(t!=null&&t.defaultHeaders&&Object.keys(t.defaultHeaders).some(T=>T.toLowerCase()===a.key.trim().toLowerCase())),i=a.value==="";return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"w-1/3 relative",children:[e.jsx("input",{type:"text",value:a.key,onChange:T=>Ie(o,T.target.value,a.value),className:`w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs font-mono focus:outline-none focus:border-blue-500 ${i?"text-slate-500 line-through":"text-blue-400"}`,placeholder:"Header Key"}),p&&e.jsx("span",{className:`absolute right-2 top-2 text-[10px] font-sans pointer-events-none font-semibold ${i?"text-rose-400":"text-amber-400"}`,children:i?"Disabled":"Override"})]}),i?e.jsxs("div",{className:"flex-1 bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-rose-400/80 italic font-mono flex items-center justify-between",children:[e.jsx("span",{children:"(Disabled — this header will be omitted from outgoing requests)"}),e.jsx("button",{type:"button",onClick:()=>We(o),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:T=>Ie(o,a.key,T.target.value),className:"flex-1 bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-slate-200 font-mono focus:outline-none focus:border-blue-500",placeholder:"Header Value"}),e.jsx("button",{onClick:()=>We(o),className:"p-2 text-slate-500 hover:text-red-400 transition-colors cursor-pointer rounded-lg hover:bg-red-500/10",title:i?"Re-enable header":p?"Remove override (reverts to default)":"Delete header",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:i||p?"undo":"delete"})})]},o)})}),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:O,onChange:a=>Z(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:q,onChange:a=>ke(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:it,className:"rt-btn rt-btn--secondary text-xs shrink-0",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"add"}),"+ add header"]})]})]}),M.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(Le,{value:I,onChange:E,options:M,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!==D&&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:D,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:Y,onChange:a=>ee(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(Le,{value:S,onChange:A,options:H.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:()=>P(!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:()=>X(!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:K.map(a=>{const o=b.find(i=>i.id===a),p=Ce===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}),o&&o.name&&o.name!==a&&e.jsx("span",{className:"text-[10px] text-slate-500 truncate block",children:o.name})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:()=>ft(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:()=>ht(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)})})]}),Fe&&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:()=>oe(!0),disabled:Be,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"}),Be?"Deleting...":"Delete Provider"]})]})}),Q&&e.jsx(St,{isOpen:Q,provider:{id:l.id,name:l.name,image:l.image,color:(t==null?void 0:t.color)||l.color,iconBg:(t==null?void 0:t.iconBg)||l.iconBg,format:(t==null?void 0:t.format)||l.format,website:t==null?void 0:t.website,apiKeyUrl:(Ze=t==null?void 0:t.notice)==null?void 0:Ze.apiKeyUrl,regions:t==null?void 0:t.regions,defaultRegion:t==null?void 0:t.defaultRegion,requiresApiKey:t==null?void 0:t.requiresApiKey,authType:t==null?void 0:t.authType,isLocal:t==null?void 0:t.isLocal,defaultBaseUrl:(t==null?void 0:t.defaultBaseUrl)||(t==null?void 0:t.baseUrl),noAuth:t==null?void 0:t.noAuth},existingNames:h.map(a=>a.name),onClose:()=>J(!1),onSuccess:xe,onOpenOAuth:u?()=>{J(!1),ie()}:void 0}),ue&&e.jsx(Et,{isOpen:ue,onClose:()=>G(!1),onSuccess:xe}),le&&e.jsx(Dt,{isOpen:le,onClose:()=>ge(!1),onSuccess:xe}),me&&e.jsx(Tt,{isOpen:me,onClose:()=>be(!1),onSuccess:xe}),L&&e.jsx(kt,{isOpen:L,providerId:l.id,providerName:l.name,onSuccess:xe,onClose:()=>ae(!1)}),e.jsx(De,{isOpen:V,onClose:()=>X(!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:r,onChange:a=>d(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:()=>X(!1),className:"px-4 py-2 text-xs text-slate-400 cursor-pointer",children:"Cancel"}),e.jsx("button",{onClick:pt,className:"rt-btn rt-btn--primary",children:"Add Model"})]})]})}),e.jsx(Pt,{isOpen:F,provider:{id:l.id,name:l.name,baseUrl:D||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:()=>{P(!1),u||["github","cursor","kiro","antigravity"].includes(l.id)?ie():J(!0)},onClose:()=>P(!1),onApplyModels:bt}),e.jsx(Nt,{isOpen:!!ve,account:ve,onClose:()=>Pe(null),onSave:ot}),e.jsx(De,{isOpen:!!re,onClose:()=>Ee(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:re==null?void 0:re.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:[(re==null?void 0:re.models.length)||0," models"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"material-symbols-outlined absolute left-2.5 top-1/2 -translate-y-1/2 text-slate-500 text-[16px]",children:"search"}),e.jsx("input",{type:"text",value:_e,onChange:a=>Re(a.target.value),placeholder:"Search supported models...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl pl-8 pr-3 py-1.5 text-xs text-white font-mono focus:outline-none focus:border-blue-500"})]}),e.jsx("div",{className:"max-h-60 overflow-y-auto space-y-1 pr-1 font-mono text-xs",children:re!=null&&re.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..."]}):(re==null?void 0:re.models.length)===0?e.jsx("div",{className:"py-8 text-center text-slate-500",children:"No specific models registered for this account yet."}):[...(re==null?void 0:re.models)||[]].filter(a=>!_e||a.toLowerCase().includes(_e.toLowerCase())).sort((a,o)=>a.localeCompare(o,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:()=>Ee(null),className:"rt-btn rt-btn--secondary text-xs",children:"Close"})})]})}),Fe&&e.jsx(wt,{isOpen:Te,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:gt,onCancel:()=>oe(!1)})]})};export{Ht as ProviderDetailPage};
@@ -1 +0,0 @@
1
- import{r as l,j as e}from"./vendor-BcOI2aZ9.js";import{P as ae}from"./index-DTRst7wN.js";import{C as ne}from"./ConfirmModal-CuQ7ARxt.js";import{i as Q}from"./ModelAutocompleteInput-CgJ2FlEf.js";import{g as X}from"./metadataRegistry-BPZSXiBy.js";import{T as Z}from"./ToolIcon-Cp4gSgFt.js";import{C as ie,O as ee,F as te,A as se}from"./providersData-Bsv7o5VV.js";import"./lucide-Cc35htxl.js";const ce=({isOpen:N,existingProviderIds:z,onClose:o,onImportSuccess:g})=>{const[u,w]=l.useState([]),[_,y]=l.useState(!1),[h,j]=l.useState(""),[p,q]=l.useState("all"),[C,b]=l.useState(null),[I,k]=l.useState(""),[d,T]=l.useState(""),[v,P]=l.useState("Default Account"),[D,O]=l.useState(!1),[f,A]=l.useState(null);l.useEffect(()=>{N&&(y(!0),fetch("/api/providers/community-catalog").then(a=>a.json()).then(a=>{a&&Array.isArray(a.catalog)&&w(a.catalog)}).catch(a=>{console.error("Failed to load community catalog:",a)}).finally(()=>{y(!1)}))},[N]);const W=l.useMemo(()=>{const a=new Set;for(const n of u)n.category&&a.add(n.category);return["all",...Array.from(a).sort()]},[u]),B=l.useMemo(()=>{const a=h.toLowerCase().trim();return u.filter(n=>{var S;return p!=="all"&&n.category!==p?!1:a?n.name.toLowerCase().includes(a)||n.id.toLowerCase().includes(a)||n.baseUrl.toLowerCase().includes(a)||((S=n.models)==null?void 0:S.some(U=>U.id.toLowerCase().includes(a))):!0})},[u,h,p]),L=a=>{b(a),k(a.baseUrl||"https://api.openai.com"),T(""),P("Default Account"),A(null)},$=async()=>{if(C){O(!0),A(null);try{const a=await fetch("/api/providers/community-catalog/import",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:C.id,customBaseUrl:I.trim(),apiKey:d.trim()||void 0,accountName:v.trim()||"Default Account"})}),n=await a.json();if(!a.ok||!n.success)throw new Error(n.error||"Failed to import provider");g(C.id),b(null)}catch(a){A(a.message||"Import failed")}finally{O(!1)}}};return N?e.jsx(ae,{isOpen:N,onClose:o,maxWidthClass:"w-full max-w-4xl",children:e.jsxs("div",{className:"relative w-full max-w-4xl bg-[#0B0F19] border border-[#1E293B] rounded-2xl shadow-2xl overflow-hidden flex flex-col max-h-[88vh]",children:[e.jsxs("div",{className:"p-6 border-b border-[#1E293B] bg-[#0F1420]/70 flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-blue-500/10 border border-blue-500/20 flex items-center justify-center text-blue-400",children:e.jsx("span",{className:"material-symbols-outlined text-[22px]",children:"explore"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-base font-bold text-white",children:"Community Providers Catalog"}),e.jsxs("span",{className:"px-2 py-0.5 rounded-full bg-blue-500/10 border border-blue-500/20 text-blue-400 text-[11px] font-mono",children:[u.length," Available"]})]}),e.jsx("p",{className:"text-xs text-slate-400 mt-0.5",children:"Browse on-demand multi-gateways, token resellers, and community inference proxies. Import directly into active providers."})]})]}),e.jsx("button",{onClick:o,className:"p-1.5 rounded-lg text-slate-400 hover:text-white hover:bg-white/5 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"close"})})]}),e.jsxs("div",{className:"p-4 border-b border-[#1E293B] bg-[#0A0D14]/80 flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-[240px]",children:[e.jsx("span",{className:"material-symbols-outlined absolute left-3 top-2.5 text-slate-500 text-[18px]",children:"search"}),e.jsx("input",{type:"text",value:h,onChange:a=>j(a.target.value),placeholder:"Search community provider by name, ID, endpoint...",className:"w-full pl-9 pr-3 py-2 text-xs bg-[#0F1420] border border-[#1E293B] rounded-xl text-white placeholder-slate-500 focus:outline-none focus:border-blue-500/60 transition-colors"}),h&&e.jsx("button",{onClick:()=>j(""),className:"absolute right-3 top-2.5 text-slate-500 hover:text-white text-xs",children:"✕"})]}),e.jsx("div",{className:"flex items-center gap-1.5 overflow-x-auto pb-1 max-w-full",children:W.map(a=>e.jsx("button",{onClick:()=>q(a),className:`px-2.5 py-1 rounded-lg text-[11px] font-medium capitalize transition-colors cursor-pointer ${p===a?"bg-blue-600 text-white shadow-xs":"bg-[#0F1420] text-slate-400 border border-[#1E293B] hover:text-white"}`,children:a},a))})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4 space-y-2.5 min-h-[300px]",children:_?e.jsxs("div",{className:"py-20 flex flex-col items-center justify-center text-slate-500 text-xs gap-3",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-[28px] text-blue-400",children:"sync"}),e.jsx("span",{children:"Loading community catalog..."})]}):B.length===0?e.jsxs("div",{className:"py-16 text-center text-slate-500 text-xs flex flex-col items-center justify-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[32px] text-slate-600",children:"search_off"}),e.jsx("span",{children:"No community providers match your filter query."})]}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:B.map(a=>{const n=z.includes(a.id);return e.jsxs("div",{className:"p-3.5 rounded-xl bg-[#0F1420]/80 border border-[#1E293B] hover:border-slate-700 transition-all flex flex-col justify-between gap-3 group",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-semibold text-xs text-white",children:a.name}),e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] bg-[#1E293B] text-slate-400 font-mono",children:a.id})]}),e.jsx("div",{className:"text-[11px] text-slate-500 font-mono truncate max-w-[280px] mt-1",title:a.baseUrl||"Custom Base URL required",children:a.baseUrl||e.jsx("span",{className:"italic text-amber-500/80",children:"Requires custom URL"})})]}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-mono uppercase font-semibold ${a.format==="claude"?"bg-amber-500/10 text-amber-400 border border-amber-500/20":"bg-emerald-500/10 text-emerald-400 border border-emerald-500/20"}`,children:a.format})})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-3 text-[11px] text-slate-400",children:[a.models&&a.models.length>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px] text-slate-500",children:"memory"}),a.models.length," preset models"]}),a.website&&e.jsxs("a",{href:a.website,target:"_blank",rel:"noreferrer",className:"flex items-center gap-1 text-blue-400/80 hover:text-blue-300 transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"open_in_new"}),"Docs"]})]})]}),e.jsxs("div",{className:"pt-2 border-t border-[#1E293B]/60 flex items-center justify-between",children:[e.jsx("span",{className:"text-[10px] text-slate-500 capitalize",children:a.category}),n?e.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-emerald-400 font-medium px-2 py-0.5 rounded bg-emerald-500/10 border border-emerald-500/20",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"check_circle"}),"Active"]}):e.jsxs("button",{onClick:()=>L(a),className:"flex items-center gap-1 px-3 py-1 rounded-lg bg-blue-600 hover:bg-blue-500 text-white text-[11px] font-semibold transition-colors cursor-pointer shadow-xs",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"download"}),"Import"]})]})]},a.id)})})}),e.jsxs("div",{className:"p-3 border-t border-[#1E293B] bg-[#0A0D14] flex items-center justify-between text-xs text-slate-500",children:[e.jsxs("span",{children:["Showing ",B.length," of ",u.length," community providers"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] text-blue-400",children:"info"}),"Imported providers are saved locally in SQLite and support load balancing."]})]}),C&&e.jsx("div",{className:"absolute inset-0 bg-black/75 backdrop-blur-xs flex items-center justify-center p-4 z-50 animate-rt-fade-in",children:e.jsxs("div",{className:"w-full max-w-md bg-[#0F1420] border border-[#1E293B] rounded-2xl p-5 shadow-2xl space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-[#1E293B] pb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[18px]",children:"add_task"}),e.jsxs("h3",{className:"text-sm font-bold text-white",children:["Import ",C.name]})]}),e.jsx("button",{onClick:()=>b(null),className:"text-slate-400 hover:text-white text-xs cursor-pointer",children:"✕"})]}),f&&e.jsxs("div",{className:"p-2.5 rounded-lg bg-red-500/10 border border-red-500/20 text-red-400 text-xs flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"error"}),e.jsx("span",{children:f})]}),e.jsxs("div",{className:"space-y-3 text-xs",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-semibold mb-1",children:"Base URL"}),e.jsx("input",{type:"text",value:I,onChange:a=>k(a.target.value),placeholder:"https://api.example.com/v1",className:"w-full px-3 py-2 bg-[#0A0D14] border border-[#1E293B] rounded-xl text-white placeholder-slate-600 focus:outline-none focus:border-blue-500/60"}),e.jsx("p",{className:"text-[11px] text-slate-500 mt-1",children:"API endpoint prefix where request completions will be routed."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-semibold mb-1",children:"Account Name"}),e.jsx("input",{type:"text",value:v,onChange:a=>P(a.target.value),placeholder:"Default Account",className:"w-full px-3 py-2 bg-[#0A0D14] border border-[#1E293B] rounded-xl text-white placeholder-slate-600 focus:outline-none focus:border-blue-500/60"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-semibold mb-1",children:"API Key (Optional)"}),e.jsx("input",{type:"password",value:d,onChange:a=>T(a.target.value),placeholder:"sk-...",className:"w-full px-3 py-2 bg-[#0A0D14] border border-[#1E293B] rounded-xl text-white placeholder-slate-600 focus:outline-none focus:border-blue-500/60"}),e.jsx("p",{className:"text-[11px] text-slate-500 mt-1",children:"Encrypted with AES-256-GCM hardware vault. You can also configure it later."})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{onClick:()=>b(null),disabled:D,className:"px-3.5 py-1.5 rounded-xl border border-[#1E293B] text-slate-400 hover:text-white text-xs font-semibold cursor-pointer",children:"Cancel"}),e.jsx("button",{onClick:$,disabled:D||!I.trim(),className:"px-4 py-1.5 rounded-xl bg-blue-600 hover:bg-blue-500 disabled:opacity-50 text-white text-xs font-semibold flex items-center gap-1.5 cursor-pointer shadow-xs",children:D?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-[14px]",children:"sync"}),"Importing..."]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"check"}),"Save & Activate"]})})]})]})})]})}):null},ge=({searchQuery:N,onSelectProvider:z})=>{const[o,g]=l.useState(null),[u,w]=l.useState(""),[_,y]=l.useState("Default Account"),[h,j]=l.useState(""),[p,q]=l.useState([]),[C,b]=l.useState(new Set),[I,k]=l.useState({}),[d,T]=l.useState(null),[v,P]=l.useState("all"),[D,O]=l.useState(!1),[f,A]=l.useState(null),[W,B]=l.useState(!1),[L,$]=l.useState(!1),[a,n]=l.useState(null),S=async()=>{try{const t=await fetch("/api/providers");if(t.ok){const s=await t.json(),r=Array.isArray(s)?s.filter(x=>x.id!=="combo"&&x.category!=="composite"):[];q(r)}}catch{}};l.useEffect(()=>{S()},[]);const U=t=>{const s=t.baseUrl||t.defaultBaseUrl||"";return s.startsWith("devin://")||s.startsWith("auggie://")||s.startsWith("zcode://")||s.includes("://")&&s.endsWith("/stdio")},F=t=>U(t)?!1:!!t.noAuth||t.requiresApiKey===!1||t.authType==="none"||t.id==="opencode"||t.id==="oc"||t.id==="ollama-local"||t.id==="lm-studio"||t.id==="jan",G=t=>{const s=p.find(x=>x.id===t),r=X(t);return r&&U(r)?(s==null?void 0:s.accountsCount)??0:t==="opencode"||t==="oc"||s!=null&&s.noAuth||r!=null&&r.noAuth||(r==null?void 0:r.requiresApiKey)===!1||(r==null?void 0:r.authType)==="none"?Math.max(1,(s==null?void 0:s.accountsCount)??0):(s==null?void 0:s.accountsCount)??0},M=t=>{const s=!N||t.name.toLowerCase().includes(N.toLowerCase()),r=G(t.id);return v==="connected"?s&&(r>0||F(t)):v==="not_connected"?s&&r===0&&!F(t):s},re=async()=>{if(o){$(!0),n(null);try{let t=p.find(s=>s.id===o.id);if(!t||h.trim()&&h.trim()!==t.baseUrl){const s={id:o.id,name:(t==null?void 0:t.name)||o.name,baseUrl:h.trim()||o.baseUrl||(t==null?void 0:t.baseUrl)||"https://api.openai.com",format:(t==null?void 0:t.format)||o.format||"openai"};t&&(s.models=t.models,s.customHeaders=t.customHeaders,s.proxyUrl=t.proxyUrl,s.thinkingMode=t.thinkingMode,s.strategy=t.strategy,s.stickyLimit=t.stickyLimit);const r=await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!r.ok){const x=await r.json().catch(()=>({}));throw new Error(x.error||`Failed to save provider (${r.status})`)}}if(u.trim()||F(o)){const s=await fetch(`/api/providers/${o.id}/accounts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:_||`${o.name} Connection`,apiKey:u.trim()||(o.id==="opencode"||o.id==="oc"?"public":"")})});if(!s.ok){const r=await s.json().catch(()=>({}));throw new Error(r.error||`Failed to add account (${s.status})`)}}await S(),Q(),w(""),y("Default Account"),j(""),n(null),g(null)}catch(t){console.error(t),n(t.message||"Failed to save connection.")}finally{$(!1)}}},H=async t=>{b(s=>new Set(s).add(t));try{const r=await(await fetch(`/api/providers/${t}/test`,{method:"POST"})).json();k(x=>({...x,[t]:{success:!!r.success,msg:r.message||(r.success?"Connected successfully":"Connection failed"),latencyMs:r.latencyMs}}))}catch(s){k(r=>({...r,[t]:{success:!1,msg:s.message||"Failed to reach gateway"}}))}finally{b(s=>{const r=new Set(s);return r.delete(t),r})}},J=async(t,s)=>{const r=t.filter(c=>G(c.id)>0||F(c));if(r.length===0){alert(`No configured or ready accounts found in ${s}.`);return}T(s);const x=r.map(c=>c.id);b(c=>{const m=new Set(c);return x.forEach(i=>m.add(i)),m});try{const c=await fetch("/api/providers/test-bulk",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerIds:x})});if(c.ok){const m=await c.json();m.results&&k(i=>{const E={...i};for(const[oe,K]of Object.entries(m.results))E[oe]={success:!!K.success,msg:K.message||(K.success?"Connected successfully":"Connection failed"),latencyMs:K.latencyMs};return E})}else for(const m of r)await H(m.id)}catch{for(const c of r)await H(c.id)}finally{b(c=>{const m=new Set(c);return x.forEach(i=>m.delete(i)),m}),T(null)}},le=async()=>{if(f){B(!0);try{(await fetch(`/api/providers/${f.id}`,{method:"DELETE"})).ok&&(await S(),Q())}catch{}finally{B(!1),A(null)}}},Y=new Set(ie.map(t=>t.id)),V=p.filter(t=>!Y.has(t.id)).map(t=>{const s=X(t.id);return{id:t.id,name:t.name,image:(s==null?void 0:s.image)||(t.format==="anthropic"?"/assets/providers/anthropic/icon.png":"/assets/providers/openai/icon.png"),color:(s==null?void 0:s.color)||(t.format==="anthropic"?"#D97706":"#10A37F"),iconBg:(s==null?void 0:s.iconBg)||"#ffffff",category:"custom",format:t.format||"openai",baseUrl:t.baseUrl,models:t.models,thinkingMode:t.thinkingMode}}),R=(t,s=!1)=>{const r=t.category==="custom"||!Y.has(t.id),x=!!s&&r,c=G(t.id),m=C.has(t.id),i=I[t.id];return e.jsxs("div",{onClick:()=>z(t),className:"rt-card stagger-item group flex flex-col justify-between cursor-pointer relative overflow-hidden min-w-[300px] hover:border-blue-500/30 transition-all",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(Z,{src:t.image,name:t.name,color:t.color,iconBg:t.iconBg,size:"md",className:"group-hover:border-blue-500/40 transition-colors shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"text-xs font-bold text-slate-100 truncate group-hover:text-blue-400 transition-colors",children:t.name}),e.jsxs("div",{className:"mt-1 flex items-center gap-1.5 flex-wrap",children:[U(t)?e.jsx("span",{className:"rt-badge rt-badge--muted text-[10px]",children:"CLI Bridge"}):F(t)?e.jsxs("span",{className:"rt-badge rt-badge--success",children:[e.jsx("span",{className:"size-1.5 rounded-full bg-emerald-400"}),t.isLocal?"Ready (Local)":"Ready (Free)"]}):c>0?e.jsxs("span",{className:"rt-badge rt-badge--success",children:[e.jsx("span",{className:"size-1.5 rounded-full bg-emerald-400 animate-pulse"}),c," Connected"]}):e.jsx("span",{className:"rt-badge rt-badge--muted",children:"No connections"}),i&&e.jsx("span",{className:`rt-badge text-[10px] ${i.success?"bg-emerald-500/10 text-emerald-400 border border-emerald-500/20":"bg-red-500/10 text-red-400 border border-red-500/20"}`,title:i.msg,children:i.success?`● ${i.latencyMs?`${i.latencyMs}ms`:"Active"}`:"● Error"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:E=>{E.stopPropagation(),H(t.id)},disabled:m,title:"Test Connection",className:"p-2 rounded-lg bg-white/5 hover:bg-blue-500/20 text-slate-400 hover:text-blue-400 transition-colors cursor-pointer",children:e.jsx("span",{className:`material-symbols-outlined text-[16px] ${m?"animate-spin text-blue-400":""}`,children:m?"sync":"speed"})}),x&&e.jsx("button",{onClick:E=>{E.stopPropagation(),A(t)},title:"Delete Provider",className:"p-2 rounded-lg bg-white/5 hover:bg-red-500/20 text-slate-400 hover:text-red-400 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"delete"})})]})]}),i&&e.jsx("div",{className:`w-full py-1 px-3 text-[10px] font-mono border-t truncate ${i.success?"bg-emerald-500/10 text-emerald-400 border-emerald-500/20":"bg-red-500/10 text-red-400 border-red-500/20"}`,title:i.msg,children:i.success?`✓ ${i.msg}`:`✗ ${i.msg}`})]},t.id)};return e.jsxs("div",{className:"space-y-8 w-full px-2 sm:px-4 pb-16 animate-rt-fade-in",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4 p-4 rounded-2xl bg-[#0F1420]/70 border border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[e.jsx("span",{className:"font-semibold text-slate-300",children:"Filter Status:"}),e.jsxs("div",{className:"flex items-center bg-[#0A0D14] p-1 rounded-xl border border-[#1E293B]",children:[e.jsx("button",{onClick:()=>P("all"),className:`px-3 py-1 rounded-lg transition-colors font-medium ${v==="all"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"All Providers"}),e.jsx("button",{onClick:()=>P("connected"),className:`px-3 py-1 rounded-lg transition-colors font-medium ${v==="connected"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Connected Only"}),e.jsx("button",{onClick:()=>P("not_connected"),className:`px-3 py-1 rounded-lg transition-colors font-medium ${v==="not_connected"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Unconfigured"})]})]}),e.jsxs("div",{className:"text-xs text-slate-400 font-mono flex items-center gap-2",children:[e.jsx("span",{children:"Active Accounts:"}),e.jsx("span",{className:"px-2 py-0.5 rounded-md bg-blue-500/10 text-blue-400 border border-blue-500/20 font-bold",children:p.reduce((t,s)=>t+(s.accountsCount||0),0)})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[18px]",children:"add_circle"}),"Custom Providers (OpenAI & Anthropic Compatible)"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>{w(""),y("Default Account"),j("https://api.anthropic.com"),g({id:`custom-anthropic-${Date.now().toString().slice(-4)}`,name:"Custom Anthropic",image:"/assets/providers/anthropic/icon.png",category:"custom",format:"anthropic",baseUrl:"https://api.anthropic.com"})},className:"rt-btn rt-btn--primary",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"add"}),"Add Anthropic Compatible"]}),e.jsxs("button",{onClick:()=>{w(""),y("Default Account"),j("https://api.openai.com"),g({id:`custom-openai-${Date.now().toString().slice(-4)}`,name:"Custom OpenAI",image:"/assets/providers/openai/icon.png",category:"custom",format:"openai",baseUrl:"https://api.openai.com"})},className:"rt-btn rt-btn--secondary",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"add"}),"Add OpenAI Compatible"]}),e.jsxs("button",{onClick:()=>O(!0),className:"rt-btn rt-btn--secondary hover:border-blue-500/50",title:"Browse 124 community-curated routers & gateways",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[16px]",children:"explore"}),"Community Catalog"]})]})]}),V.filter(M).length>0?e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(290px,1fr))] gap-3",children:V.filter(M).map(t=>R(t,!0))}):e.jsxs("div",{className:"border border-dashed border-[#1E293B] bg-[#0E1320]/60 rounded-2xl p-5 text-center text-xs text-slate-400 flex items-center justify-center gap-2 hover:border-blue-500/30 transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[18px]",children:"cloud_sync"}),e.jsx("span",{children:V.length>0?"No custom providers match the current filter.":"Use the buttons above to register self-hosted vLLM, Ollama, LM Studio, or local API proxies."})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[18px]",children:"verified"}),"OAuth & Managed IDE Providers"]}),e.jsxs("button",{onClick:()=>J(ee,"OAuth Providers"),disabled:d==="OAuth Providers",className:"flex items-center gap-1.5 text-xs text-slate-400 hover:text-blue-400 px-3 py-1.5 rounded-lg hover:bg-white/5 transition-colors cursor-pointer font-medium disabled:opacity-50",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${d==="OAuth Providers"?"animate-spin text-blue-400":""}`,children:d==="OAuth Providers"?"sync":"play_arrow"}),d==="OAuth Providers"?"Testing...":"Test All"]})]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(290px,1fr))] gap-3",children:ee.filter(M).map(t=>R(t,!1))})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-emerald-400 text-[18px]",children:"redeem"}),"Free Tier & Community Gateways"]}),e.jsxs("button",{onClick:()=>J(te,"Free Tier Providers"),disabled:d==="Free Tier Providers",className:"flex items-center gap-1.5 text-xs text-slate-400 hover:text-blue-400 px-3 py-1.5 rounded-lg hover:bg-white/5 transition-colors cursor-pointer font-medium disabled:opacity-50",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${d==="Free Tier Providers"?"animate-spin text-emerald-400":""}`,children:d==="Free Tier Providers"?"sync":"play_arrow"}),d==="Free Tier Providers"?"Testing...":"Test All"]})]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(290px,1fr))] gap-3",children:te.filter(M).map(t=>R(t,!1))})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[18px]",children:"key"}),"Direct API Key Providers"]}),e.jsxs("button",{onClick:()=>J(se,"API Key Providers"),disabled:d==="API Key Providers",className:"flex items-center gap-1.5 text-xs text-slate-400 hover:text-blue-400 px-3 py-1.5 rounded-lg hover:bg-white/5 transition-colors cursor-pointer font-medium disabled:opacity-50",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${d==="API Key Providers"?"animate-spin text-blue-400":""}`,children:d==="API Key Providers"?"sync":"play_arrow"}),d==="API Key Providers"?"Testing...":"Test All"]})]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(290px,1fr))] gap-3",children:se.filter(M).map(t=>R(t,!1))})]}),e.jsx(ae,{isOpen:!!o,onClose:()=>{g(null),w(""),y("Default Account"),j(""),n(null)},maxWidthClass:"max-w-md",children:o&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Z,{src:o.image,name:o.name,color:o.color,iconBg:o.iconBg,size:"sm"}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:o.name}),e.jsxs("span",{className:"text-[11px] text-blue-400 font-mono",children:[o.format||"openai"," protocol"]})]})]}),e.jsx("button",{onClick:()=>g(null),className:"text-slate-400 hover:text-white p-1 rounded-lg hover:bg-white/10",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"close"})})]}),a&&e.jsxs("div",{className:"p-3 rounded-xl bg-red-500/10 border border-red-500/20 text-xs text-red-400 flex items-start gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-red-400 shrink-0 mt-0.5",children:"error"}),e.jsx("span",{children:a})]}),e.jsxs("div",{className:"space-y-3 pt-1",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-300 mb-1",children:"Account Label / Nickname"}),e.jsx("input",{type:"text",value:_,onChange:t=>y(t.target.value),placeholder:"e.g. Work Pro Key 1",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500/30"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-300 mb-1",children:"Base URL Override"}),e.jsx("input",{type:"text",value:h,onChange:t=>j(t.target.value),placeholder:o.format==="anthropic"?"https://api.anthropic.com":o.baseUrl||"https://api.openai.com",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white font-mono focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500/30"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-300 mb-1",children:"API Key / Secret Token (AES-256-GCM Hardware Encrypted)"}),e.jsx("input",{type:"password",value:u,onChange:t=>w(t.target.value),placeholder:"sk-...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white font-mono focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500/30"})]}),e.jsxs("div",{className:"bg-[#0A0D14] p-3 rounded-xl border border-[#1E293B] text-[11px] text-slate-400 flex items-start gap-2.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-emerald-400 shrink-0 mt-0.5",children:"enhanced_encryption"}),e.jsx("span",{className:"leading-relaxed",children:"Keys are securely locked with your PC's machine ID salt. No cloud upload, no telemetry."})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{onClick:()=>g(null),disabled:L,className:"px-4 py-2 text-xs text-slate-400 hover:text-white transition-colors cursor-pointer disabled:opacity-50",children:"Cancel"}),e.jsx("button",{onClick:re,disabled:L,className:"rt-btn rt-btn--primary disabled:opacity-50",children:L?"Saving...":"Save & Connect"})]})]})}),e.jsx(ce,{isOpen:D,existingProviderIds:p.map(t=>t.id),onClose:()=>O(!1),onImportSuccess:async()=>{await S(),Q()}}),e.jsx(ne,{isOpen:!!f,title:"Delete Provider",message:`Are you sure you want to delete "${f==null?void 0:f.name}"? This will permanently remove the provider configuration and all associated accounts/credentials.`,confirmText:W?"Deleting...":"Delete",variant:"danger",onConfirm:le,onCancel:()=>A(null)})]})};export{ge as ProvidersTab};