mapigate 0.5.168 → 0.5.174
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/core/adapters/responsesAdapter.js +2 -2
- package/dist/mitm/handlers/base.js +2 -2
- package/dist/providers/catalog/perplexity/index.js +1 -1
- package/dist/providers/catalog/perplexity/provider.js +1 -1
- package/dist/providers/core/base/customExecutionHelper.js +21 -1
- package/dist/providers/core/base/responsesExecution.js +37 -0
- package/dist/providers/core/base/responsesPayloadBuilder.js +5 -0
- package/dist/providers/runtime/antigravity/executor.js +8 -8
- package/dist/providers/runtime/antigravity/metadata.js +1 -1
- package/dist/providers/runtime/antigravity/provider.js +1 -1
- package/dist/providers/runtime/antigravity/quota.js +1 -1
- package/dist/providers/runtime/antigravity/routes.js +1 -1
- package/dist/providers/runtime/antigravity/types.js +1 -1
- package/dist/providers/runtime/antigravity/weekly.js +1 -1
- package/dist/providers/runtime/codex/index.js +1 -1
- package/dist/providers/runtime/codex/provider.js +1 -1
- package/dist/providers/runtime/codex/responses.js +1 -0
- package/dist/providers/runtime/codex/responsesPayload.js +1 -0
- package/dist/providers/runtime/gemini-cli/provider.js +1 -1
- package/dist/providers/runtime/gemini-cli/quota.js +1 -1
- package/dist/providers/runtime/gemini-cli/routes.js +1 -1
- package/dist/providers/runtime/grok-cli/grokWeb.js +5 -0
- package/dist/providers/runtime/grok-cli/provider.js +1 -1
- package/dist/providers/runtime/kiro/constants.js +1 -0
- package/dist/providers/runtime/kiro/executor.js +6 -6
- package/dist/providers/runtime/kiro/index.js +1 -1
- package/dist/providers/runtime/kiro/metadata.js +1 -1
- package/dist/providers/runtime/kiro/provider.js +1 -1
- package/dist/providers/runtime/kiro/quota.js +1 -1
- package/dist/providers/runtime/ollama/nativeChat.js +3 -0
- package/dist/providers/runtime/ollama/provider.js +1 -1
- package/dist/providers/runtime/opencode/provider.js +1 -1
- package/dist/web/assets/CallbackPage-B-htyyMG.js +1 -0
- package/dist/web/assets/{CliToolsTab-D4DtbZ7V.js → CliToolsTab-Q0vXiulu.js} +24 -24
- package/dist/web/assets/ComboDetailPage-hWEuQaOZ.js +1 -0
- package/dist/web/assets/CombosTab-nBWliTLU.js +1 -0
- package/dist/web/assets/{ConfirmModal-DCYNsbhd.js → ConfirmModal-CsfteGXH.js} +1 -1
- package/dist/web/assets/ConsoleLogTab-CW8OK2qW.js +6 -0
- package/dist/web/assets/EditAccountModal-CAxJfsFe.js +1 -0
- package/dist/web/assets/EndpointTab-BSOhVZQl.js +1 -0
- package/dist/web/assets/MitmTab-BjTPAKno.js +6 -0
- package/dist/web/assets/{ModelAutocompleteInput-Cdnm0qff.js → ModelAutocompleteInput-BH4gr6Dr.js} +1 -1
- package/dist/web/assets/ModelSelectModal-BP5Ha7Az.js +1 -0
- package/dist/web/assets/PortalDrawer-Bv31mboq.js +1 -0
- package/dist/web/assets/ProviderDetailPage-CeYToos_.js +6 -0
- package/dist/web/assets/{ProvidersTab-KfP8Lt0p.js → ProvidersTab-C4ZpyulK.js} +1 -1
- package/dist/web/assets/QuotaTab-Dh1eTSJx.js +1 -0
- package/dist/web/assets/SettingsTab-D0Bo21nq.js +1 -0
- package/dist/web/assets/{TokenSaverTab-B3Fbu_yc.js → TokenSaverTab-BYqUuEE1.js} +1 -1
- package/dist/web/assets/UsageTab-C5qvXO61.js +1 -0
- package/dist/web/assets/clipboard-CLQF8jeK.js +1 -0
- package/dist/web/assets/index-_goGZDSK.css +1 -0
- package/dist/web/assets/index-vFoRSZw0.js +10 -0
- package/dist/web/assets/metadataRegistry-4BIaQVmV.js +1 -0
- package/dist/web/assets/{providersData-BevGw_jX.js → providersData-C-7jZmPi.js} +1 -1
- package/dist/web/index.html +2 -2
- package/package.json +2 -2
- package/dist/web/assets/CallbackPage-sTRnWJ-d.js +0 -1
- package/dist/web/assets/ComboDetailPage-RbsO_iJo.js +0 -1
- package/dist/web/assets/CombosTab-DpKJ-Tdm.js +0 -1
- package/dist/web/assets/ConsoleLogTab-DfNJ54Az.js +0 -6
- package/dist/web/assets/EditAccountModal-DdreWxg7.js +0 -1
- package/dist/web/assets/EndpointTab-BYSh-fMY.js +0 -1
- package/dist/web/assets/MitmTab-DDSeULv5.js +0 -14
- package/dist/web/assets/ModelSelectModal-BsleTaNw.js +0 -1
- package/dist/web/assets/ProviderDetailPage-k1kl7EIO.js +0 -6
- package/dist/web/assets/QuotaTab-BA1BaQbz.js +0 -1
- package/dist/web/assets/SettingsTab-FET_sXur.js +0 -1
- package/dist/web/assets/UsageTab-C-Cs4o-K.js +0 -1
- package/dist/web/assets/index-Di7mCTbW.js +0 -2
- package/dist/web/assets/index-h7Meu4Tn.css +0 -1
- package/dist/web/assets/metadataRegistry-EMxpq0lK.js +0 -1
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{r as s,j as e}from"./vendor-BcOI2aZ9.js";import{i as lt}from"./providersData-BevGw_jX.js";import{g as ot}from"./metadataRegistry-EMxpq0lK.js";import{u as Nt,D as wt,P as Be}from"./index-Di7mCTbW.js";import{S as ze}from"./Select-BNRH8LIG.js";import{T as Le}from"./ToolIcon-BZE0Fv7L.js";import{i as Se}from"./ModelAutocompleteInput-Cdnm0qff.js";import{C as nt,E as kt}from"./EditAccountModal-DdreWxg7.js";import{C as Ct}from"./ConfirmModal-DCYNsbhd.js";import"./lucide-Cc35htxl.js";const St=({isOpen:l,providerId:n,providerName:t,onSuccess:h,onClose:j})=>{const f=s.useRef(h);f.current=h;const i=s.useRef(j);i.current=j;const H=Nt(S=>S.info),b=(H==null?void 0:H.port)||wt,V=s.useRef(b);V.current=b;const g=ot(n),w=(g==null?void 0:g.regions)||[],[v,O]=s.useState((g==null?void 0:g.defaultRegion)||(w.length>0?w[0].id:"")),A=s.useRef(v);A.current=v;const[k,I]=s.useState(""),[z,X]=s.useState(`http://localhost:${b}/callback`),[E,L]=s.useState(""),[B,P]=s.useState("loading"),[ae,q]=s.useState(null),[te,D]=s.useState(!1),[Q,R]=s.useState(!1),[$,W]=s.useState(!1),[se,ue]=s.useState(!1),[Y,ie]=s.useState(null),ye=s.useRef(null),me=s.useRef(!1),pe=s.useRef(void 0),J=s.useRef(void 0),ne=s.useRef(0),F=s.useRef(null),_=s.useCallback(()=>{F.current&&(clearTimeout(F.current),clearInterval(F.current),F.current=null)},[]),c=s.useCallback(async S=>{if(!me.current){me.current=!0,_(),P("processing"),q(null);try{const de=await fetch(`/api/oauth/${n}/exchange`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:S,redirectUri:z,codeVerifier:pe.current,state:J.current,region:A.current||void 0})}),le=await de.json().catch(()=>({}));if(!de.ok||le.error)throw new Error(le.error||"Token exchange failed");P("success");try{localStorage.removeItem("oauth_pending_flow"),localStorage.removeItem("oauth_callback")}catch{}setTimeout(()=>{f.current(),i.current()},1200)}catch(de){me.current=!1,P("error"),q(de.message||"Failed to exchange authorization token")}}},[n,z,_]),d=s.useCallback(async S=>{const de=++ne.current,le=()=>de!==ne.current;me.current=!1,_(),P("loading"),q(null),L(""),ue(!1),ie(null),W(!1),pe.current=void 0,J.current=void 0;const oe=S!==void 0?S:A.current,x=oe?`®ion=${encodeURIComponent(oe)}`:"",y=oe?`?region=${encodeURIComponent(oe)}`:"",p=window.location.port==="5173"?`http://localhost:${V.current}/callback`:`${window.location.origin}/callback`;X(p);try{const U=await fetch(`/api/oauth/${n}/authorize?redirect_uri=${encodeURIComponent(p)}${x}`),T=await U.json().catch(()=>({}));if(le())return;if(!U.ok||T.error)throw new Error(T.error||`Authorization error (HTTP ${U.status})`);if(T.flowType==="device_code"||!T.authUrl&&T.flowType){ue(!0),P("waiting");const G=await fetch(`/api/oauth/${n}/device-code${y}`),K=await G.json().catch(()=>({}));if(le())return;if(!G.ok||!K.device_code)throw new Error(K.error||"Failed to initiate device code flow");ie(K);const Ae=K.verification_uri_complete||K.verification_uri;if(Ae)try{window.open(Ae,"_blank","noopener,noreferrer")}catch{}let be=Number(K.interval)||5,fe=!0;const we=ge=>{le()||(F.current&&clearTimeout(F.current),F.current=setTimeout(async()=>{if(!(!fe||le()))try{const xe=await(await fetch(`/api/oauth/${n}/poll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:K.device_code,codeVerifier:K.codeVerifier,region:oe||void 0,extraData:{...K||{},_zcodePollToken:K._zcodePollToken,_minimaxPollByUser:K._minimaxPollByUser,codeVerifier:K.codeVerifier,user_code:K.user_code,region:oe||void 0}})})).json();if(le())return;if(xe.ok&&xe.success){fe=!1,_(),P("success"),setTimeout(()=>{f.current(),i.current()},1200);return}if(xe.error==="slow_down"){be=Math.min(be+5,30),we(be);return}if(xe.error==="authorization_pending"){we(be);return}if(xe.error){fe=!1,_(),P("error"),q(xe.error_description||xe.error);return}we(be)}catch{fe&&we(be)}},ge*1e3))};we(be);return}if(T.authUrl){I(T.authUrl),T.redirectUri&&X(T.redirectUri),T.codeVerifier&&(pe.current=T.codeVerifier),T.state&&(J.current=T.state),P("waiting");try{localStorage.setItem("oauth_pending_flow",JSON.stringify({providerId:n,redirectUri:T.redirectUri||p,state:T.state,codeVerifier:T.codeVerifier,timestamp:Date.now()}))}catch{}try{const G=window.open(T.authUrl,"oauth_popup","width=600,height=700");G&&!G.closed?ye.current=G:W(!0)}catch{W(!0)}return}throw new Error("No authorization URL returned from provider")}catch(U){if(le())return;P("error"),q(U.message||"Failed to initialize authorization endpoint")}},[n,_]);if(s.useEffect(()=>{if(!l){_(),P("loading"),q(null),ue(!1),ie(null);return}return d(),()=>{ne.current++,_()}},[l,n,d,_]),s.useEffect(()=>{if(!l)return;const S=p=>{if(!p)return;if(J.current&&p.state&&p.state!==J.current){P("error"),q("OAuth state mismatch. Please retry authorization.");return}if(p.done){me.current=!0,_(),P("success");try{localStorage.removeItem("oauth_pending_flow"),localStorage.removeItem("oauth_callback")}catch{}setTimeout(()=>{f.current(),i.current()},1200);return}if(p.error){P("error"),q(p.errorDescription||p.error);return}const U=p.code||p.token||(p.userId&&p.token?p.fullUrl||`${window.location.origin}/?user_id=${p.userId}&access_token=${p.token}`:null);U&&c(U)},de=p=>{if(!p)return!1;if(p===window.location.origin)return!0;try{const U=new URL(p),T=new URL(window.location.origin),G=K=>K==="localhost"||K==="127.0.0.1"||K==="[::1]"||K==="::1";return U.protocol===T.protocol&&U.port===T.port&&G(U.hostname.toLowerCase())&&G(T.hostname.toLowerCase())}catch{return!1}},le=p=>{var U;de(p.origin)&&((U=p.data)==null?void 0:U.type)==="oauth_callback"&&S(p.data.data)};window.addEventListener("message",le);let oe=null;try{oe=new BroadcastChannel("oauth_callback"),oe.onmessage=p=>S(p.data)}catch{}const x=p=>{if(p.key==="oauth_callback"&&p.newValue)try{const U=JSON.parse(p.newValue);S(U),localStorage.removeItem("oauth_callback")}catch{}};window.addEventListener("storage",x);const y=setInterval(()=>{try{const p=localStorage.getItem("oauth_callback");if(p){const U=JSON.parse(p);U&&(!U.timestamp||Date.now()-U.timestamp<6e4)&&S(U),localStorage.removeItem("oauth_callback")}}catch{}},500);return()=>{clearInterval(y),window.removeEventListener("message",le),window.removeEventListener("storage",x),oe&&oe.close()}},[l,c]),!l)return null;const C=()=>{k&&(navigator.clipboard.writeText(k),D(!0),setTimeout(()=>D(!1),2e3))},he=S=>{S&&(navigator.clipboard.writeText(S),R(!0),setTimeout(()=>R(!1),2e3))},Z=()=>{if(k){W(!1);try{const S=window.open(k,"oauth_popup","width=600,height=700");S&&(ye.current=S)}catch{}}},ve=()=>{E.trim()&&c(E.trim())};return e.jsx(Be,{isOpen:l,onClose:j,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-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-blue-400",children:"lock"}),e.jsxs("h3",{className:"text-base font-bold text-white tracking-tight",children:["Connect ",t]})]}),e.jsx("button",{type:"button",onClick:j,className:"text-slate-400 hover:text-white p-1 rounded-lg hover:bg-white/5 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),w.length>0&&e.jsxs("div",{className:"space-y-1.5 p-3 rounded-xl bg-[#0A0D14] border border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"block text-xs font-medium text-slate-300",children:"Server / Region:"}),e.jsx("span",{className:"text-[10px] text-slate-500 font-mono",children:v})]}),e.jsx(ze,{value:v,onChange:S=>{O(S),A.current=S,d(S)},options:w.map(S=>({value:S.id,label:S.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:se?"Waiting for device authorization in browser...":$?"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"&&ae&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-2.5 px-3.5 py-2.5 border border-red-500/30 rounded-xl bg-red-500/10 text-xs text-red-300",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-red-400 mt-0.5 shrink-0",children:"error"}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("p",{className:"font-semibold",children:"Connection Failed"}),e.jsx("p",{className:"text-red-200",children:ae})]})]}),e.jsxs("button",{type:"button",onClick:()=>d(),className:"w-full flex items-center justify-center gap-1.5 py-2 px-3 rounded-xl bg-white/5 hover:bg-white/10 text-xs font-semibold text-slate-200 border border-[#1E293B] cursor-pointer transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"refresh"}),"Retry Authorization"]})]}),se&&Y?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:Y.user_code}),e.jsxs("button",{type:"button",onClick:()=>he(Y.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] ${Q?"text-emerald-400":""}`,children:Q?"check":"content_copy"}),Q?"Copied":"Copy Code"]})]})]}),e.jsxs("button",{type:"button",onClick:()=>{const S=Y.verification_uri_complete||Y.verification_uri;S&&window.open(S,"_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:S=>L(S.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:Z,disabled:!k||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"})]}),$&&e.jsxs("p",{className:"text-[11px] text-amber-400 text-center flex items-center justify-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"info"}),"Browser blocked popup window. Click above to open the login window directly."]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"text-xs font-semibold text-slate-200",children:"Step 1: Authorization Link"}),k&&e.jsx("button",{type:"button",onClick:()=>window.open(k,"_blank"),className:"text-[11px] text-blue-400 hover:text-blue-300 underline cursor-pointer",children:"Open in new tab"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",readOnly:!0,value:k||(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:C,disabled:!k,className:"flex items-center gap-1 px-3 py-2 rounded-xl border border-[#1E293B] bg-[#0A0D14] text-xs font-medium text-slate-300 hover:text-white transition-colors cursor-pointer shrink-0 disabled:opacity-50",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${te?"text-emerald-400":""}`,children:te?"check":"content_copy"}),te?"Copied":"Copy Link"]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 my-2",children:[e.jsx("div",{className:"flex-1 h-px bg-[#1E293B]"}),e.jsx("span",{className:"text-[11px] font-bold text-slate-500 uppercase tracking-wider",children:"OR PASTE CALLBACK URL / CODE"}),e.jsx("div",{className:"flex-1 h-px bg-[#1E293B]"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold text-slate-200",children:"Step 2: Paste callback URL or authorization code here"}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"After logging in, copy the full URL from your browser address bar and paste it below."}),e.jsx("input",{type:"text",value:E,onChange:S=>L(S.target.value),placeholder:n==="codex"?"http://localhost:1455/auth/callback?code=... or code":`${window.location.origin}/callback?code=... or code`,className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs font-mono text-slate-200 focus:outline-none focus:border-blue-500"})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2.5 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{type:"button",onClick:j,className:"px-4 py-2 rounded-xl text-xs font-medium text-slate-400 hover:text-white transition-colors cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"button",onClick:ve,disabled:!E.trim()||B==="processing",className:"rt-btn rt-btn--primary disabled:opacity-50 disabled:cursor-not-allowed",children:B==="processing"?"Exchanging...":"Connect"})]})]})})};function At(l,n={}){const{isCloudflareAi:t=!1}=n,h=l.trim();if(!t&&/^LLM\|/i.test(h))return{baseName:"LLM",apiKey:h};const j=l.split("|");if(t&&j.length>=3){const i=j[0].trim(),H=j.slice(1,-1).join("|").trim(),b=j[j.length-1].trim();return{baseName:i||"Key",apiKey:H,providerSpecificData:{accountId:b}}}if(j.length>=2){const i=j[0].trim(),H=j.slice(1).join("|").trim();return{baseName:i||"Key",apiKey:H}}return{baseName:"Key",apiKey:j[0].trim()}}function Et(l,n=[],t={}){const h=Array.isArray(n)?n:[],j=new Set(h.map(i=>typeof i=="string"?i.toLowerCase():"")),f=[];for(const i of l){const H=typeof i=="string"?i.trim():"";if(!H)continue;const b=At(H,t);if(!b||!b.apiKey)continue;const V=b.baseName;let g=1,w;for(;w=`${V} ${g}`,!!j.has(w.toLowerCase());)g+=1;j.add(w.toLowerCase());const v={name:w,apiKey:b.apiKey};b.providerSpecificData&&(v.providerSpecificData=b.providerSpecificData),f.push(v)}return f}const Dt=({isOpen:l,provider:n,existingNames:t=[],onClose:h,onSuccess:j,onOpenOAuth:f})=>{const i=n.id.toLowerCase(),H=i==="opencode"||i==="oc"||!!n.noAuth||n.requiresApiKey===!1||n.authType==="none",b=i==="ollama-local"||i.includes("ollama"),V=!!n.isLocal||i==="lm-studio"||i==="jan",g=H||b||V||n.requiresApiKey===!1,w=i==="azure"||i.includes("azure"),v=i==="cloudflare-ai"||i==="cloudflare",O=i==="bedrock"||i.includes("bedrock"),A=i==="grok-web"||i==="iflow",k=i==="xiaomi-tokenplan",I=i==="alicode"||i==="alibaba",z=s.useMemo(()=>k?[{id:"sgp",label:"Singapore (新加坡)"},{id:"cn",label:"China (中国大陆)"},{id:"ams",label:"Amsterdam (阿姆斯特丹)"}]:n.regions||[],[k,n.regions]),[X,E]=s.useState(n.defaultRegion||(z.length>0?z[0].id:"sgp")),[L,B]=s.useState("single"),[P,ae]=s.useState(""),[q,te]=s.useState(""),[D,Q]=s.useState(""),[R,$]=s.useState("http://127.0.0.1:11434"),[W,se]=s.useState(n.defaultBaseUrl||(i==="lm-studio"?"http://localhost:1234/v1":i==="jan"?"http://localhost:1337/v1":"http://localhost:8000/v1")),[ue,Y]=s.useState(""),[ie,ye]=s.useState("gpt-4"),[me,pe]=s.useState("2024-10-01-preview"),[J,ne]=s.useState(""),[F,_]=s.useState(""),[c,d]=s.useState(""),[C,he]=s.useState("profile"),[Z,ve]=s.useState(""),[S,de]=s.useState("us-east-1"),[le,oe]=s.useState(""),[x,y]=s.useState(""),[p,U]=s.useState(""),[T,G]=s.useState(null),[K,Ae]=s.useState(!1),[be,fe]=s.useState(null),[we,ge]=s.useState(null),[Ee,xe]=s.useState(!1),[Oe,ke]=s.useState(null),[$e,Ue]=s.useState(!1),[Pe,Re]=s.useState(null),ee=s.useCallback(()=>{B("single"),ae(""),te(""),Q(""),$("http://127.0.0.1:11434"),se(n.defaultBaseUrl||(i==="lm-studio"?"http://localhost:1234/v1":i==="jan"?"http://localhost:1337/v1":"http://localhost:8000/v1")),Y(""),ye("gpt-4"),pe("2024-10-01-preview"),ne(""),_(""),d(""),he("profile"),ve(""),de("us-east-1"),oe(""),y(""),E(n.defaultRegion||(z.length>0?z[0].id:"sgp")),U(""),G(null),Ae(!1),fe(null),ge(null),xe(!1),ke(null),Ue(!1),Re(null)},[n.defaultBaseUrl,n.defaultRegion,z,i]);s.useEffect(()=>{l&&ee()},[l,ee]);const _e=async()=>{Ue(!0),Re(null);try{const re=await(await fetch(`/api/oauth/${encodeURIComponent(n.id)}/auto-import`)).json(),ce=re.apiKey||re.accessToken;re.found&&ce?(Q(ce),P.trim()||ae(re.userName||re.keyName||re.email||`${n.name} CLI`),fe(null),ge(null)):Re(re.error||`Could not find ${n.name} CLI credentials`)}catch{Re(`Failed to auto-import from ${n.name} CLI`)}finally{Ue(!1)}},De=()=>{ee(),h()},He=()=>A?i==="grok-web"?"sso=xxxx... or raw cookie":"eyJhbGciOi...":g?"Optional / Not required":k?"tp-...":i.startsWith("deepseek")?"sk-...":i.startsWith("xai")?"xai-...":i.startsWith("groq")?"gsk_...":i.startsWith("anthropic")?"sk-ant-...":i.startsWith("gemini")?"AIzaSy...":"sk-...",Fe=()=>{if(b)return{baseUrl:R.trim()||"http://127.0.0.1:11434"};if(V)return{baseUrl:W.trim()};if(w)return{azureEndpoint:ue.trim(),deployment:ie.trim(),apiVersion:me.trim(),organization:J.trim()||void 0};if(v)return{accountId:F.trim()};if(O)return C==="profile"?{profile:Z.trim(),region:S.trim()||"us-east-1"}:{accessKeyId:le.trim(),region:S.trim()||"us-east-1",sessionToken:x.trim()||void 0};if(k||z.length>0){const u={region:X};return I&&c.trim()&&(u.baseUrl=c.trim()),u}},Te=()=>g?!0:O&&C==="profile"?!!Z.trim():O&&C==="static"?!!(D.trim()&&le.trim()):w?!!(D.trim()&&ue.trim()&&ie.trim()):v?!!(D.trim()&&F.trim()):k?!!(D.trim()&&X):!!D.trim(),Ne=async()=>{Ae(!0),fe(null),ge(null);try{const u=Fe(),ce=await(await fetch("/api/providers/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:n.id,apiKey:D.trim(),providerSpecificData:u})})).json();ce.valid?fe("valid"):(fe("invalid"),ge(ce.error||"Validation check failed"))}catch(u){fe("invalid"),ge(u.message||"Connection check error")}finally{Ae(!1)}},We=async()=>{if(!Te())return;xe(!0),ke(null);const u=H?i==="opencode"||i==="oc"?"OpenCode Free":`${n.name} (Public)`:b?"Ollama Local":V?`${n.name} Local`:O&&C==="profile"?`Bedrock (${Z})`:k?`Xiaomi MiMo (${X.toUpperCase()})`:`${n.name} Account`,re=P.trim()||u,ce=Fe()||{};q.trim()&&(ce.tag=q.trim().toLowerCase());try{const Ce=await fetch(`/api/providers/${n.id}/accounts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:re,apiKey:D.trim()||(i==="opencode"||i==="oc"?"public":""),providerSpecificData:Object.keys(ce).length>0?ce:void 0})});if(!Ce.ok){const Ke=await Ce.json().catch(()=>({}));throw new Error(Ke.error||`Server returned ${Ce.status}`)}Se(),ee(),j(),h()}catch(Ce){ke(Ce.message||"Failed to save account")}finally{xe(!1)}},Me=async()=>{if(!p.trim())return;xe(!0),G(null),ke(null);const u=p.split(`
|
|
2
|
-
`),re=Et(u,t,{isCloudflareAi:v});if(re.length===0){ke("No valid keys found in input"),xe(!1);return}try{const ce=await fetch(`/api/providers/${n.id}/accounts/bulk`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({accounts:re})});if(!ce.ok){const Ke=await ce.json().catch(()=>({}));throw new Error(Ke.error||`Bulk addition failed (${ce.status})`)}const Ce=await ce.json();Se(),G({success:Ce.count||re.length,failed:0}),setTimeout(()=>{ee(),j(),h()},700)}catch(ce){ke(ce.message||"Failed to add bulk keys")}finally{xe(!1)}};return e.jsx(Be,{isOpen:l,onClose:De,maxWidthClass:"max-w-2xl",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Le,{src:n.image,name:n.name,color:n.color,iconBg:n.iconBg,size:"md",fallback:e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[20px]",children:"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:A?"Paste session cookie credentials":O?"Configure AWS SSO profile or static keys":w?"Configure Azure OpenAI deployment & endpoint":b?"Connect local self-hosted model service":V?`Connect local ${n.name} model server`:g?"No API key required for this provider":k?"Select cluster region & paste Token Plan API key":"API key is hardware-encrypted (AES-256-GCM)"})]})]}),e.jsx("button",{onClick:De,className:"text-slate-400 hover:text-white p-1 rounded-lg hover:bg-white/10 cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),f&&e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-xl border border-blue-500/20 bg-blue-500/10 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2 text-blue-300",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] text-blue-400",children:"lock"}),e.jsx("span",{children:"This provider also supports OAuth authorization."})]}),e.jsx("button",{type:"button",onClick:f,className:"rt-btn rt-btn--primary text-xs py-1 px-3 cursor-pointer shrink-0",children:"Connect with OAuth"})]}),!O&&!b&&!g&&e.jsxs("div",{className:"flex bg-[#0A0D14] p-1 rounded-xl border border-[#1E293B] text-xs",children:[e.jsx("button",{onClick:()=>{B("single"),G(null)},className:`flex-1 py-1.5 rounded-lg font-medium transition-colors cursor-pointer ${L==="single"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Single Connection"}),e.jsx("button",{onClick:()=>{B("bulk"),G(null)},className:`flex-1 py-1.5 rounded-lg font-medium transition-colors cursor-pointer ${L==="bulk"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Bulk Add Keys"})]}),L==="bulk"&&!O&&!b&&!g?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"text-xs text-slate-400 space-y-1",children:[e.jsx("p",{children:"One key per line. Format:"}),e.jsx("code",{className:"block bg-[#0A0D14] p-2 rounded-lg border border-[#1E293B] font-mono text-[11px] text-blue-300",children:v?`name|apiToken|accountId
|
|
3
|
-
or just apiToken`:`name|apiKey
|
|
4
|
-
or just apiKey (auto-numbered)`})]}),e.jsx("textarea",{value:p,onChange:u=>U(u.target.value),placeholder:v?`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"}),T&&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 ",T.success," connection(s)."]}),Oe&&e.jsx("p",{className:"text-xs text-rose-400",children:Oe}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{onClick:Me,disabled:Ee||!p.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:Ee?"Adding...":"Add All Keys"}),e.jsx("button",{onClick:De,className:"rt-btn rt-btn--secondary",children:"Cancel"})]})]}):e.jsxs("div",{className:"space-y-3.5 text-xs",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Connection Label"}),e.jsx("input",{type:"text",value:P,onChange:u=>ae(u.target.value),placeholder:b?"Ollama Local":V?`${n.name} Local`:H?"OpenCode Free":"Primary Key (Production)",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("label",{className:"text-slate-300 font-medium flex items-center gap-1.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px] text-blue-400",children:"label"}),"Group Tag"]}),e.jsx("span",{className:"text-slate-500 text-[11px]",children:"Optional • For grouping in Combos"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"text",value:q,onChange:u=>te(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:re=>{re.preventDefault(),te(u)},className:`pointer-events-auto text-[10px] px-1.5 py-0.5 rounded font-mono transition-colors ${q===u?"bg-blue-600 text-white font-semibold":"bg-[#1E293B] text-slate-400 hover:text-slate-200"}`,children:u},u))})]})]})]}),n.supportsAutoImport&&!g&&e.jsxs("div",{className:"flex items-center justify-between gap-3 p-3 rounded-xl bg-blue-500/10 border border-blue-500/20",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"text-xs font-medium text-blue-200",children:[n.name," CLI Auto-Import"]}),e.jsx("div",{className:"text-[11px] text-slate-400",children:n.autoImportHint||`Import local credentials for ${n.name}`}),Pe&&e.jsx("div",{className:"text-[11px] text-red-400 mt-1 whitespace-pre-line",children:Pe})]}),e.jsx("button",{type:"button",onClick:_e,disabled:$e||Ee,className:"rt-btn rt-btn--secondary text-xs py-1.5 px-3 cursor-pointer shrink-0 disabled:opacity-50",children:$e?"Importing...":"Import from CLI"})]}),g&&e.jsxs("div",{className:"p-3 bg-emerald-500/10 border border-emerald-500/20 rounded-xl text-emerald-300 text-xs flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-emerald-400 text-[18px]",children:"verified"}),e.jsxs("span",{children:[n.name," does not require an API key. You can save immediately or customize the connection label."]})]}),(k||z.length>0)&&e.jsxs("div",{className:"space-y-1.5 p-3.5 bg-[#0A0D14] border border-[#1E293B] rounded-xl",children:[e.jsxs("label",{className:"block text-slate-300 font-medium mb-1",children:["Cluster Region ",e.jsx("span",{className:"text-red-400",children:"*"})]}),e.jsx(ze,{value:X,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"}),k&&e.jsx("p",{className:"text-[11px] text-slate-400 mt-1",children:"Token Plan keys are cluster-specific — select the region matching your subscription."}),I&&e.jsxs("div",{className:"pt-2 border-t border-[#1E293B]/70 mt-2 space-y-1",children:[e.jsxs("label",{className:"block text-slate-400 text-xs",children:["Dedicated Workspace Endpoint URL ",e.jsx("span",{className:"text-slate-500",children:"(Optional)"})]}),e.jsx("input",{type:"text",value:c,onChange: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:R,onChange:u=>$(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:Ne,disabled:K,className:"rt-btn rt-btn--secondary shrink-0",children:K?"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."]})]})}),V&&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:W,onChange:u=>se(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:Ne,disabled:K,className:"rt-btn rt-btn--secondary shrink-0",children:K?"Checking...":"Check"})]}),e.jsxs("p",{className:"text-[11px] text-slate-400 mt-1.5",children:["Default is ",e.jsx("code",{className:"text-blue-300 font-mono",children:n.defaultBaseUrl||"http://localhost:1234/v1"}),". Ensure ",n.name," local server is started."]})]})}),w&&e.jsxs("div",{className:"space-y-3 p-3.5 bg-[#0A0D14] border border-[#1E293B] rounded-xl",children:[e.jsx("span",{className:"font-semibold text-blue-400 block",children:"Azure OpenAI Configuration"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"Azure Endpoint"}),e.jsx("input",{type:"text",value:ue,onChange:u=>Y(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:ie,onChange:u=>ye(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=>pe(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:J,onChange:u=>ne(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"})]})]})]}),v&&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=>_(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"})]})]})]}),O&&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:()=>he("profile"),className:`flex-1 py-1 rounded-lg font-medium transition-colors cursor-pointer ${C==="profile"?"bg-blue-600 text-white":"text-slate-400 hover:text-white"}`,children:"AWS Profile (SSO — Recommended)"}),e.jsx("button",{type:"button",onClick:()=>he("static"),className:`flex-1 py-1 rounded-lg font-medium transition-colors cursor-pointer ${C==="static"?"bg-blue-600 text-white":"text-slate-400 hover:text-white"}`,children:"Static Keys (AKIA...)"})]}),C==="profile"?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-400 mb-1",children:"AWS Profile Name"}),e.jsx("input",{type:"text",value:Z,onChange:u=>ve(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:S,onChange:u=>de(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 ",Z||"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:le,onChange:u=>oe(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:S,onChange:u=>de(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:x,onChange:u=>y(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&&!(O&&C==="profile")&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:A?"Cookie Value":O?"Secret Access Key":v?"Cloudflare API Token":k?"Token Plan Key (tp-...)":g?"API Key (Optional)":"API Key"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:A?"text":"password",value:D,onChange:u=>Q(u.target.value),placeholder:He(),className:"flex-1 bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500 font-mono"}),e.jsx("button",{type:"button",onClick:Ne,disabled:K||!Te(),className:"rt-btn rt-btn--secondary shrink-0",children:K?"Checking...":"Check"})]})]}),be&&e.jsxs("div",{className:`p-2.5 rounded-xl border flex items-center gap-2 ${be==="valid"?"bg-emerald-500/10 border-emerald-500/20 text-emerald-400":"bg-rose-500/10 border-rose-500/20 text-rose-400"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:be==="valid"?"check_circle":"error"}),e.jsx("span",{children:be==="valid"?"Credentials verified successfully!":we||"Invalid credentials."})]}),Oe&&e.jsx("p",{className:"text-xs text-rose-400",children:Oe}),e.jsxs("div",{className:"flex gap-2 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{type:"button",onClick:We,disabled:Ee||!Te(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:Ee?"Saving Connection...":"Save Connection"}),e.jsx("button",{type:"button",onClick:De,className:"rt-btn rt-btn--secondary",children:"Cancel"})]})]})]})})},Tt=({isOpen:l,onClose:n,onSuccess:t})=>{const[h,j]=s.useState("device"),[f,i]=s.useState(null),[H,b]=s.useState(!1),[V,g]=s.useState(!1),[w,v]=s.useState("idle"),[O,A]=s.useState(null),[k,I]=s.useState(""),[z,X]=s.useState(""),[E,L]=s.useState(!1),B=s.useRef(null),P=()=>{B.current&&(clearTimeout(B.current),clearInterval(B.current),B.current=null)};s.useEffect(()=>{if(!l){P(),i(null),v("idle"),I(""),X(""),A(null);return}return I(""),X(""),A(null),h==="device"&&ae(),()=>{P()}},[l,h]);const ae=async()=>{P(),b(!0),A(null),v("idle");try{const D=await fetch("/api/oauth/github/device-code",{method:"POST"});if(!D.ok){const se=await D.text();throw new Error(se||"Failed to initiate GitHub device flow")}const Q=await D.json();i(Q),v("polling");let R=Math.max(Q.interval||5,5),$=!0;const W=se=>{B.current&&clearTimeout(B.current),B.current=setTimeout(async()=>{if($)try{const Y=await(await fetch("/api/oauth/github/poll",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:Q.device_code})})).json();if(Y.ok){$=!1,v("success"),setTimeout(()=>{t(),n()},1200);return}if(Y.error==="slow_down"){R=Math.min(R+5,30),W(R);return}if(Y.error==="authorization_pending"){W(R);return}$=!1,v("error"),A(Y.error_description||Y.error)}catch{$&&W(R)}},se*1e3)};W(R)}catch(D){v("error"),A(D.message||"Failed to request device code")}finally{b(!1)}},q=D=>{navigator.clipboard.writeText(D),g(!0),setTimeout(()=>g(!1),2e3)},te=async()=>{if(k.trim()){L(!0),A(null);try{const D=await fetch("/api/oauth/github/token",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:k.trim(),name:z.trim()||void 0})});if(!D.ok){const Q=await D.json().catch(()=>({}));throw new Error(Q.error||"Failed to save GitHub token")}t(),n()}catch(D){A(D.message||"Could not save token")}finally{L(!1)}}};return l?e.jsx(Be,{isOpen:l,onClose:n,maxWidthClass:"max-w-xl",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Le,{src:"/assets/providers/github/icon.png",name:"GitHub Copilot",color:"#333333",iconBg:"#FFFFFF",size:"md"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-white",children:"Connect GitHub Copilot"}),e.jsx("p",{className:"text-xs text-slate-400",children:"Authorize via official GitHub Device Flow"})]})]}),e.jsx("button",{onClick:n,className:"text-slate-400 hover:text-white p-1 rounded-lg hover:bg-white/10",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),e.jsxs("div",{className:"flex bg-[#0A0D14] p-1 rounded-xl border border-[#1E293B] text-xs",children:[e.jsx("button",{onClick:()=>j("device"),className:`flex-1 py-1.5 rounded-lg font-medium transition-colors ${h==="device"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"GitHub Device Code Flow"}),e.jsx("button",{onClick:()=>j("token"),className:`flex-1 py-1.5 rounded-lg font-medium transition-colors ${h==="token"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Paste Token Directly"})]}),h==="device"?e.jsxs("div",{className:"space-y-4 text-xs",children:[H?e.jsxs("div",{className:"py-8 text-center text-slate-400 space-y-2",children:[e.jsx("span",{className:"material-symbols-outlined text-3xl text-blue-400 animate-spin",children:"progress_activity"}),e.jsx("p",{children:"Requesting GitHub device code..."})]}):f?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"p-3 bg-[#0A0D14] border border-[#1E293B] rounded-xl space-y-2",children:[e.jsx("span",{className:"text-slate-400 uppercase text-[10px] font-bold block",children:"Step 1: Copy One-Time User Code"}),e.jsxs("div",{className:"flex items-center justify-between gap-3 bg-[#0F1420] p-3 rounded-lg border border-[#1E293B]",children:[e.jsx("span",{className:"text-xl font-mono font-bold text-white tracking-widest",children:f.user_code}),e.jsxs("button",{onClick:()=>q(f.user_code),className:"rt-btn rt-btn--secondary py-1 text-xs",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:V?"check":"content_copy"}),V?"Copied":"Copy Code"]})]})]}),e.jsxs("div",{className:"p-3 bg-[#0A0D14] border border-[#1E293B] rounded-xl space-y-2",children:[e.jsx("span",{className:"text-slate-400 uppercase text-[10px] font-bold block",children:"Step 2: Authorize in Browser"}),e.jsx("p",{className:"text-slate-300",children:"Open GitHub activation page and enter the user code shown above:"}),e.jsxs("a",{href:f.verification_uri||"https://github.com/login/device",target:"_blank",rel:"noreferrer",className:"rt-btn rt-btn--primary w-full text-center inline-flex items-center justify-center gap-1.5",children:[e.jsx("span",{children:"Open https://github.com/login/device"}),e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"open_in_new"})]})]}),w==="polling"&&e.jsxs("div",{className:"flex items-center justify-center gap-2 text-slate-400 py-1 font-mono text-[11px]",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[16px] animate-spin",children:"sync"}),e.jsx("span",{children:"Waiting for authorization on github.com..."})]}),w==="success"&&e.jsxs("div",{className:"p-3 rounded-xl bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"check_circle"}),e.jsx("span",{children:"Authorized successfully! Connecting Copilot..."})]})]}):null,O&&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:O})]})]}):e.jsxs("div",{className:"space-y-3.5 text-xs",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Account Label"}),e.jsx("input",{type:"text",value:z,onChange:D=>X(D.target.value),placeholder:"Copilot Work Account",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"GitHub Access Token or Copilot Token"}),e.jsx("input",{type:"password",value:k,onChange:D=>I(D.target.value),placeholder:"ghu_... or ghp_...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500 font-mono"}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-1.5",children:"Paste your GitHub token from VS Code extension or personal token. Mapigate encrypts it locally."})]}),O&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:O}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{onClick:te,disabled:E||!k.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:E?"Connecting...":"Save Copilot Account"}),e.jsx("button",{onClick:n,className:"rt-btn rt-btn--secondary",children:"Cancel"})]})]})]})}):null},Bt=({isOpen:l,onClose:n,onSuccess:t})=>{const[h,j]=s.useState(""),[f,i]=s.useState(""),[H,b]=s.useState(""),[V,g]=s.useState(!1),[w,v]=s.useState(!1),[O,A]=s.useState(null),[k,I]=s.useState(!1);s.useEffect(()=>{if(!l){j(""),i(""),b(""),v(!1),A(null);return}b(""),A(null),z()},[l]);const z=async()=>{g(!0),v(!1),A(null);try{const L=await(await fetch("/api/oauth/cursor/auto-import")).json();L.found?(j(L.accessToken||""),i(L.machineId||""),v(!0)):A(L.error||"Could not auto-detect token from local Cursor database")}catch(E){A(E.message||"Failed to auto-detect Cursor tokens")}finally{g(!1)}},X=async()=>{if(h.trim()){I(!0),A(null);try{const E=await fetch("/api/oauth/cursor/import",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({accessToken:h.trim(),machineId:f.trim()||void 0,name:H.trim()||void 0})});if(!E.ok){const L=await E.json().catch(()=>({}));throw new Error(L.error||"Failed to import Cursor connection")}t(),n()}catch(E){A(E.message||"Could not save Cursor account")}finally{I(!1)}}};return l?e.jsx(Be,{isOpen:l,onClose:n,maxWidthClass:"max-w-xl",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Le,{src:"/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"})})]}),V?e.jsxs("div",{className:"py-8 text-center text-slate-400 space-y-2 text-xs",children:[e.jsx("span",{className:"material-symbols-outlined text-3xl text-blue-400 animate-spin",children:"progress_activity"}),e.jsx("p",{className:"font-semibold text-white",children:"Scanning Cursor IDE state.vscdb..."}),e.jsx("p",{className:"text-slate-500",children:"Checking local Application Support / AppData"})]}):e.jsxs("div",{className:"space-y-3.5 text-xs",children:[w&&e.jsxs("div",{className:"p-3 rounded-xl bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"check_circle"}),e.jsx("span",{children:"Session token auto-detected from Cursor IDE successfully!"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Account Label"}),e.jsx("input",{type:"text",value:H,onChange:E=>b(E.target.value),placeholder:"Cursor Desktop Account",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Access Token"}),e.jsx("input",{type:"password",value:h,onChange:E=>j(E.target.value),placeholder:"Paste Cursor access token or auto-detect",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500 font-mono"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Machine ID"}),e.jsx("input",{type:"text",value:f,onChange:E=>i(E.target.value),placeholder:"desktop-cursor-client",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500 font-mono"})]}),O&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:O}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsxs("button",{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:X,disabled:k||!h.trim(),className:"flex-1 rt-btn rt-btn--primary disabled:opacity-50",children:k?"Saving...":"Save Connection"})]})]})]})}):null},Pt=({isOpen:l,onClose:n,onSuccess:t})=>{const[h,j]=s.useState("builder-id"),[f,i]=s.useState(null),[H,b]=s.useState(!1),[V,g]=s.useState(!1),w=s.useRef(null),[v,O]=s.useState(""),[A,k]=s.useState("us-east-1"),[I,z]=s.useState(""),[X,E]=s.useState(""),[L,B]=s.useState(""),[P,ae]=s.useState(!1),[q,te]=s.useState(!1),[D,Q]=s.useState(null),[R,$]=s.useState(""),[W,se]=s.useState(""),[ue,Y]=s.useState("us-east-1"),[ie,ye]=s.useState(""),[me,pe]=s.useState("us-east-1"),[J,ne]=s.useState(""),[F,_]=s.useState(!1),[c,d]=s.useState(null),C=s.useCallback(()=>{w.current&&clearInterval(w.current),i(null),b(!1),g(!1),O(""),k("us-east-1"),z(""),E(""),B(""),ae(!1),te(!1),Q(null),$(""),se(""),Y("us-east-1"),ye(""),pe("us-east-1"),ne(""),_(!1),d(null)},[]);s.useEffect(()=>{if(!l){C();return}C(),h==="import"&&ve()},[l,h,C]),s.useEffect(()=>()=>{w.current&&clearInterval(w.current)},[]);const he=x=>{navigator.clipboard.writeText(x),g(!0),setTimeout(()=>g(!1),2e3)},Z=async x=>{_(!0),d(null),i(null);try{const y=await fetch("/api/oauth/kiro/device-code",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...x,name:x.name||J.trim()||void 0})});if(!y.ok){const T=await y.json().catch(()=>({}));throw new Error(T.error||"Failed to start AWS device authorization")}const p=await y.json();i(p),b(!0),p.verification_uri_complete&&window.open(p.verification_uri_complete,"_blank","noopener,noreferrer");const U=Math.max((p.interval||5)*1e3,3e3);w.current&&clearInterval(w.current),w.current=setInterval(async()=>{try{const G=await(await fetch("/api/oauth/kiro/device-poll",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({deviceCode:p.device_code,extraData:p.extraData})})).json();G.ok&&G.success?(w.current&&clearInterval(w.current),b(!1),t(),n()):G.error&&!G.pending&&(w.current&&clearInterval(w.current),b(!1),d(G.error))}catch{}},U)}catch(y){d(y.message||"Failed to start device flow")}finally{_(!1)}},ve=async()=>{ae(!0),te(!1),d(null);try{const y=await(await fetch("/api/oauth/kiro/auto-import")).json();y.found&&(y.refreshToken||y.accessToken)?(y.refreshToken&&E(y.refreshToken),y.accessToken&&B(y.accessToken),te(!0),y.clientId&&y.clientSecret&&Q({clientId:y.clientId,clientSecret:y.clientSecret,region:y.region||"us-east-1",authMethod:y.authMethod||"idc",profileArn:y.profileArn})):d(y.error||"Could not auto-detect token from ~/.aws/sso/cache")}catch(x){d(x.message||"Failed to scan AWS SSO cache")}finally{ae(!1)}},S=async()=>{const x=X.trim(),y=L.trim();if(!x&&!y){d("Please provide a refresh token or access token");return}_(!0),d(null);try{const p=await fetch("/api/oauth/kiro/import",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:x||void 0,accessToken:y||void 0,name:J.trim()||void 0,...D||{}})});if(!p.ok){const U=await p.json().catch(()=>({}));throw new Error(U.error||"Failed to import Kiro credentials")}t(),n()}catch(p){d(p.message||"Import failed")}finally{_(!1)}},de=async()=>{const x=v.trim();if(!x){d("Please enter your Access Token (aoa... or JWT)");return}_(!0),d(null);try{const y=await fetch("/api/oauth/kiro/access-token",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({accessToken:x,name:J.trim()||(x.startsWith("aoa")?"Kiro Education Token (aoa)":void 0),region:A.trim()||"us-east-1",profileArn:I.trim()||void 0})});if(!y.ok){const p=await y.json().catch(()=>({}));throw new Error(p.error||"Failed to save Access Token")}t(),n()}catch(y){d(y.message||"Failed to save Access Token")}finally{_(!1)}},le=async()=>{const x=R.trim();if(!x){d("Please paste the External IDP / CLIProxy auth JSON");return}_(!0),d(null);try{const y=await fetch("/api/oauth/kiro/import-cli-proxy",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({json:x,name:J.trim()||void 0})});if(!y.ok){const p=await y.json().catch(()=>({}));throw new Error(p.error||"Failed to import External IDP JSON")}t(),n()}catch(y){d(y.message||"Import failed")}finally{_(!1)}},oe=async()=>{if(ie.trim()){_(!0),d(null);try{const x=await fetch("/api/oauth/kiro/api-key",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:ie.trim(),region:me.trim()||"us-east-1",name:J.trim()||void 0})});if(!x.ok){const y=await x.json().catch(()=>({}));throw new Error(y.error||"Failed to save Kiro API key")}t(),n()}catch(x){d(x.message||"Could not save API key")}finally{_(!1)}}};return l?e.jsx(Be,{isOpen:l,onClose:n,maxWidthClass:"max-w-xl",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Le,{src:"/assets/providers/kiro/icon.png",name:"Kiro",color:"#FF9900",size:"md"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-white",children:"Connect Kiro IDE"}),e.jsx("p",{className:"text-xs text-slate-400",children:"Builder ID, Access Token, Import, External IDP, IDC, API Key"})]})]}),e.jsx("button",{onClick:n,className:"text-slate-400 hover:text-white p-1 rounded-lg hover:bg-white/10",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),e.jsxs("div",{className:"grid grid-cols-3 sm:grid-cols-6 bg-[#0A0D14] p-1 rounded-xl border border-[#1E293B] text-[11px] gap-1",children:[e.jsx("button",{onClick:()=>{j("builder-id"),d(null)},className:`py-1.5 px-1 rounded-lg font-medium transition-colors text-center whitespace-nowrap ${h==="builder-id"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Builder ID"}),e.jsx("button",{onClick:()=>{j("token"),d(null)},className:`py-1.5 px-1 rounded-lg font-medium transition-colors text-center whitespace-nowrap ${h==="token"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Access Token"}),e.jsx("button",{onClick:()=>{j("import"),d(null)},className:`py-1.5 px-1 rounded-lg font-medium transition-colors text-center whitespace-nowrap ${h==="import"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"Import Token"}),e.jsx("button",{onClick:()=>{j("cliproxy"),d(null)},className:`py-1.5 px-1 rounded-lg font-medium transition-colors text-center whitespace-nowrap ${h==="cliproxy"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"External IDP"}),e.jsx("button",{onClick:()=>{j("idc"),d(null)},className:`py-1.5 px-1 rounded-lg font-medium transition-colors text-center whitespace-nowrap ${h==="idc"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"AWS IDC"}),e.jsx("button",{onClick:()=>{j("apikey"),d(null)},className:`py-1.5 px-1 rounded-lg font-medium transition-colors text-center whitespace-nowrap ${h==="apikey"?"bg-blue-600 text-white shadow-xs":"text-slate-400 hover:text-white"}`,children:"API Key"})]}),h==="builder-id"&&e.jsx("div",{className:"space-y-3.5 text-xs",children:f?e.jsxs("div",{className:"space-y-3.5",children:[e.jsxs("div",{className:"p-3 bg-[#0A0D14] border border-[#1E293B] rounded-xl text-center space-y-2",children:[e.jsx("p",{className:"text-slate-400 text-xs",children:"Enter this code on the AWS verification page:"}),e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx("span",{className:"text-xl font-mono font-bold text-white tracking-widest",children:f.user_code}),e.jsx("button",{type:"button",onClick:()=>he(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:V?"Copied!":"Copy"})]})]}),e.jsxs("div",{className:"text-center space-y-2 pt-1",children:[e.jsxs("a",{href:f.verification_uri_complete||f.verification_uri,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 text-blue-400 hover:underline text-xs",children:[e.jsx("span",{children:"Open AWS verification page"}),e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"open_in_new"})]}),H&&e.jsxs("div",{className:"flex items-center justify-center gap-2 text-slate-400 text-[11px]",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] animate-spin text-blue-400",children:"progress_activity"}),e.jsx("span",{children:"Waiting for approval in AWS portal..."})]})]}),e.jsx("div",{className:"flex gap-2 pt-2",children:e.jsx("button",{type:"button",onClick:()=>{i(null),b(!1)},className:"w-full rt-btn rt-btn--secondary",children:"Restart Flow"})})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"p-2.5 rounded-xl bg-orange-500/10 border border-orange-500/20 text-orange-300 text-[11px] leading-relaxed",children:e.jsxs("p",{children:["Recommended for personal accounts. Click ",e.jsx("strong",{children:"Start Builder ID Login"})," to authorize via browser device code."]})}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Account Label"}),e.jsx("input",{type:"text",value:J,onChange:x=>ne(x.target.value),placeholder:"Kiro AWS Builder ID",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500"})]}),c&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:c}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>Z({authMethod:"builder-id",startUrl:"https://view.awsapps.com/start",name:J.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:J,onChange:x=>ne(x.target.value),placeholder:"Kiro Education (aoa)",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Access Token (aoaAAAAAG... or JWT)"}),e.jsx("textarea",{rows:3,value:v,onChange:x=>O(x.target.value),placeholder:"Paste AccessToken (aoa... or eyJr...)",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500 font-mono text-[11px]"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Region"}),e.jsx("input",{type:"text",value:A,onChange:x=>k(x.target.value),placeholder:"us-east-1",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white font-mono"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Profile ARN (Optional)"}),e.jsx("input",{type:"text",value:I,onChange:x=>z(x.target.value),placeholder:"arn:aws:codewhisperer...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white font-mono"})]})]}),c&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:c}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:de,disabled:F||!v.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:[P?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:[q&&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:J,onChange:x=>ne(x.target.value),placeholder:"Kiro Desktop Account",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Refresh Token (starts with aor...)"}),e.jsx("input",{type:"password",value:X,onChange:x=>E(x.target.value),placeholder:"aorAAAAAG...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500 font-mono"})]}),L&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Detected Access Token (aoa...)"}),e.jsx("input",{type:"password",value:L,onChange:x=>B(x.target.value),placeholder:"aoaAAAAAG...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white font-mono"})]})]}),c&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:c}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsxs("button",{type:"button",onClick:ve,className:"rt-btn rt-btn--secondary",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"refresh"}),"Re-detect"]}),e.jsx("button",{type:"button",onClick:S,disabled:F||!X.trim()&&!L.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:J,onChange:x=>ne(x.target.value),placeholder:"Kiro Microsoft Education",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"External IDP Auth JSON"}),e.jsx("textarea",{rows:4,value:R,onChange:x=>$(x.target.value),placeholder:'{ "auth_method": "external_idp", "access_token": "...", "refresh_token": "...", "token_endpoint": "https://login.microsoftonline.com/..." }',className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500 font-mono text-[11px]"})]}),c&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:c}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:le,disabled:F||!R.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:()=>he(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:V?"Copied!":"Copy"})]})]}),e.jsxs("div",{className:"text-center space-y-2 pt-1",children:[e.jsxs("a",{href:f.verification_uri_complete||f.verification_uri,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 text-blue-400 hover:underline text-xs",children:[e.jsx("span",{children:"Open IDC login page in browser"}),e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"open_in_new"})]}),H&&e.jsxs("div",{className:"flex items-center justify-center gap-2 text-slate-400 text-[11px]",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] animate-spin text-blue-400",children:"progress_activity"}),e.jsx("span",{children:"Waiting for approval from Identity Center..."})]})]}),e.jsx("div",{className:"flex gap-2 pt-2",children:e.jsx("button",{type:"button",onClick:()=>{i(null),b(!1)},className:"w-full rt-btn rt-btn--secondary",children:"Restart Flow"})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Account Label"}),e.jsx("input",{type:"text",value:J,onChange:x=>ne(x.target.value),placeholder:"Kiro Enterprise (IDC)",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white focus:outline-none focus:border-blue-500"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-slate-300 font-medium mb-1",children:["IDC Start URL ",e.jsx("span",{className:"text-rose-400",children:"*"})]}),e.jsx("input",{type:"text",value:W,onChange:x=>se(x.target.value),placeholder:"https://your-org.awsapps.com/start",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white font-mono"}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-1",children:"Your organization's AWS IAM Identity Center URL."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"AWS Region"}),e.jsx("input",{type:"text",value:ue,onChange:x=>Y(x.target.value),placeholder:"us-east-1",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white font-mono"})]}),c&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:c}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>{if(!W.trim()){d("Please enter your IDC start URL");return}Z({authMethod:"idc",startUrl:W.trim(),region:ue.trim()||"us-east-1",name:J.trim()||void 0})},disabled:F||!W.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:J,onChange:x=>ne(x.target.value),placeholder:"Kiro Headless Key",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Kiro API Key"}),e.jsx("input",{type:"password",value:ie,onChange:x=>ye(x.target.value),placeholder:"Paste Kiro / CodeWhisperer key",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white font-mono"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-slate-300 font-medium mb-1",children:"Region"}),e.jsx("input",{type:"text",value:me,onChange:x=>pe(x.target.value),placeholder:"us-east-1",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-white font-mono"})]}),c&&e.jsx("div",{className:"p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400",children:c}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:oe,disabled:F||!ie.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 Rt(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 _t=({isOpen:l,provider:n,existingModels:t,onAddAccount:h,onClose:j,onApplyModels:f})=>{var F,_;const[i,H]=s.useState(!1),[b,V]=s.useState([]),[g,w]=s.useState(new Set),[v,O]=s.useState(null),[A,k]=s.useState([]),[I,z]=s.useState([]),[X,E]=s.useState(!1),[L,B]=s.useState(null),[P,ae]=s.useState(""),q=n.modelsUrl||n.baseUrl||"",[te,D]=s.useState(!1),[Q,R]=s.useState(q),$=s.useCallback(async c=>{H(!0),B(null),E(!1);try{const d=await Rt({providerId:n.id,baseUrl:(c!==void 0?c:Q).trim()||void 0});if(d.success){if(V(d.models),O(d.endpointUrl||null),k(d.scannedAccounts||[]),z(d.failedAccounts||[]),E(!1),w(new Set(d.models.map(C=>C.id))),d.models.length>0){const C=d.models.map(Z=>Z.id);C.some(Z=>!t.includes(Z))&&f(C,"merge")}}else V([]),O(null),k([]),z(d.failedAccounts||[]),d.noAccountsConfigured&&E(!0),B(d.error||"Failed to scan models from upstream provider.")}catch(d){const C=d instanceof Error?d.message:String(d);B(C)}finally{H(!1)}},[n.id,Q]);s.useEffect(()=>{if(l){const c=n.modelsUrl||n.baseUrl||"";R(c),ae(""),D(!1),k([]),z([]),E(!1),$(c||void 0)}else V([]),w(new Set),B(null),O(null),k([]),z([]),E(!1)},[l,n.id,n.baseUrl,n.modelsUrl,$]);const W=s.useMemo(()=>{let c=b;if(P.trim()){const d=P.toLowerCase();c=b.filter(C=>C.id.toLowerCase().includes(d)||C.name&&C.name.toLowerCase().includes(d)||C.description&&C.description.toLowerCase().includes(d))}return[...c].sort((d,C)=>(d.name||d.id).localeCompare(C.name||C.id,void 0,{sensitivity:"base"}))},[b,P]),se=c=>{const d=new Set(g);d.has(c)?d.delete(c):d.add(c),w(d)},ue=()=>{w(new Set(W.map(c=>c.id)))},Y=()=>{w(new Set)},ie=W.length>0&&W.every(c=>g.has(c.id)),ye=W.some(c=>g.has(c.id)),me=c=>{c?ue():Y()},pe=c=>{const d=b.filter(C=>g.has(C.id)).map(C=>C.id);f(d,c),j()},J=s.useMemo(()=>b.filter(c=>!t.includes(c.id)).length,[b,t]),ne=s.useMemo(()=>b.filter(c=>t.includes(c.id)).length,[b,t]);return e.jsx(Be,{isOpen:l,onClose:j,maxWidthClass:"max-w-2xl",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Le,{src:n.image,name:n.name,color:n.color,iconBg:n.iconBg,size:"md",fallback:e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[20px]",children:"radar"})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-bold text-white flex items-center gap-2",children:["Scan Models from Provider API",e.jsx("span",{className:"text-[10px] font-mono px-2 py-0.5 rounded bg-blue-500/10 text-blue-400 border border-blue-500/20",children:n.name})]}),e.jsx("p",{className:"text-xs text-slate-400 mt-0.5",children:"Automatically probe and import live available models using your configured accounts."})]})]}),e.jsxs("button",{onClick:()=>$(),disabled:i,className:"rt-btn rt-btn--secondary text-xs flex items-center gap-1.5",title:"Rescan",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${i?"animate-spin":""}`,children:"sync"}),i?"Scanning...":"Rescan"]})]}),(A.length>0||I.length>0||v)&&e.jsxs("div",{className:"flex flex-col gap-1.5 p-2.5 rounded-xl bg-[#0A0D14] border border-[#1E293B] text-[11px]",children:[A.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:A.length===1?"Scanned account:":`Aggregated across ${A.length} accounts:`}),A.map(c=>e.jsx("span",{className:"px-2 py-0.5 rounded font-mono text-[10px] bg-blue-500/10 text-blue-400 border border-blue-500/20",children:c.name},c.id))]}),I.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:I.length===1?(_=(F=I[0])==null?void 0:F.error)!=null&&_.toLowerCase().includes("auth")?"1 account failed to authenticate:":"1 account failed to scan:":I.every(c=>{var d;return(d=c.error)==null?void 0:d.toLowerCase().includes("auth")})?`${I.length} accounts failed to authenticate:`:`${I.length} accounts failed to scan:`}),I.map(c=>e.jsx("span",{title:c.error,className:"px-2 py-0.5 rounded font-mono text-[10px] bg-amber-500/10 text-amber-400 border border-amber-500/20",children:c.name},c.id))]}),v&&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:v})]})]}),X&&e.jsxs("div",{className:"p-4 rounded-xl bg-amber-500/10 border border-amber-500/30 text-xs text-amber-300 space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-amber-400 shrink-0 mt-0.5",children:"key_off"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-semibold text-white",children:"No Accounts Configured"}),e.jsxs("p",{className:"text-[11px] text-amber-200/90 mt-1 leading-relaxed",children:["No active account or API key is configured for ",e.jsx("strong",{children:n.name}),". Model scanning automatically queries provider endpoints using your stored accounts. Please configure an account or API key in the provider settings first."]})]})]}),h&&e.jsx("div",{className:"flex justify-end pt-1",children:e.jsxs("button",{type:"button",onClick:()=>{j(),h()},className:"rt-btn rt-btn--primary text-xs flex items-center gap-1.5 bg-amber-600 hover:bg-amber-500 text-white border-none cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"add"}),"Add Account / API Key"]})})]}),L&&!X&&e.jsx("div",{className:"p-3.5 rounded-xl bg-red-500/10 border border-red-500/30 text-xs text-red-300 space-y-2",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] text-red-400 shrink-0 mt-0.5",children:"error"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-semibold",children:L}),e.jsx("p",{className:"text-[11px] text-red-400/80 mt-1",children:"Ensure the configured provider credentials are valid, or provide a custom endpoint URL below."})]})]})}),e.jsxs("div",{className:"rounded-xl border border-[#1E293B] bg-[#0A0D14]/60 overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>D(!te),className:"w-full flex items-center justify-between px-3.5 py-2 text-xs text-slate-400 hover:text-white transition-colors cursor-pointer",children:[e.jsxs("span",{className:"flex items-center gap-1.5 font-medium",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"tune"}),"Base URL & Endpoint Override"]}),e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:te?"expand_less":"expand_more"})]}),te&&e.jsxs("div",{className:"p-3.5 border-t border-[#1E293B] space-y-3 bg-[#080B12]",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[11px] font-semibold text-slate-400 mb-1",children:"Base URL or Models Endpoint"}),e.jsx("input",{type:"text",placeholder:"e.g. https://token-plan-sgp.xiaomimimo.com/v1/models or https://api.xkiro.com/v1",value:Q,onChange:c=>R(c.target.value),className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-lg px-3 py-1.5 text-xs text-white font-mono focus:outline-none focus:border-blue-500"})]}),e.jsx("div",{className:"flex justify-end pt-1",children:e.jsx("button",{type:"button",onClick:()=>$(),disabled:i,className:"rt-btn rt-btn--primary text-xs",children:"Apply & Scan"})})]})]}),i&&e.jsxs("div",{className:"py-12 flex flex-col items-center justify-center gap-3 text-center",children:[e.jsx("div",{className:"relative size-12 flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-3xl text-blue-400 animate-spin",children:"sync"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-white",children:"Probing provider endpoints..."}),e.jsx("p",{className:"text-[11px] text-slate-500 font-mono mt-0.5",children:"Querying /v1/models with configured credentials"})]})]}),!i&&b.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2.5",children:[e.jsx("div",{className:"flex items-center gap-2 flex-1 min-w-[200px]",children:e.jsxs("div",{className:"relative w-full",children:[e.jsx("span",{className:"material-symbols-outlined absolute left-2.5 top-1/2 -translate-y-1/2 text-[16px] text-slate-500",children:"search"}),e.jsx("input",{type:"text",placeholder:"Search discovered models...",value:P,onChange:c=>ae(c.target.value),className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-lg pl-8 pr-8 py-1.5 text-xs text-white focus:outline-none focus:border-blue-500"}),P&&e.jsx("button",{type:"button",onClick:()=>ae(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-slate-500 hover:text-white transition-colors cursor-pointer flex items-center justify-center",title:"Clear search",children:e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"close"})})]})}),e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[e.jsx(nt,{size:"sm",checked:ie,indeterminate:ye&&!ie,onChange:me,label:e.jsx("span",{className:"text-xs font-medium text-slate-300",children:"Select All"})}),e.jsx("button",{type:"button",onClick:Y,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:[J," new"]}),e.jsx("span",{children:"•"}),e.jsxs("span",{className:"text-slate-500",children:[ne," existing"]})]}),e.jsx("div",{children:e.jsxs("span",{children:["Selected: ",e.jsx("strong",{className:"text-blue-400",children:g.size})]})})]}),e.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1.5 pr-1 border border-[#1E293B] rounded-xl p-2 bg-[#0A0D14]/80",children:W.length===0?e.jsxs("div",{className:"py-6 text-center text-xs text-slate-500",children:['No models match "',P,'"']}):W.map(c=>{var he,Z;const d=g.has(c.id),C=t.includes(c.id);return e.jsxs("div",{onClick:()=>se(c.id),className:`flex items-center justify-between p-2 rounded-lg border text-xs cursor-pointer transition-colors ${d?"bg-blue-500/10 border-blue-500/40 text-white":"bg-[#0D1322] border-[#1E293B] hover:border-slate-700 text-slate-300"}`,children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx(nt,{size:"sm",checked:d,onChange:()=>se(c.id),onClick:ve=>ve.stopPropagation()}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"font-mono font-medium truncate block",children:c.id}),c.name&&c.name!==c.id&&e.jsx("span",{className:"text-[10px] text-slate-500 truncate block",children:c.name})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[((he=c.capabilities)==null?void 0:he.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"}),((Z=c.capabilities)==null?void 0:Z.vision)&&e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-mono bg-amber-500/20 text-amber-300 border border-amber-500/30",children:"vision"}),C?e.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-mono bg-slate-800 text-slate-400",children:"Configured"}):e.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-mono bg-emerald-500/20 text-emerald-300 border border-emerald-500/30 font-semibold",children:"NEW"})]})]},c.id)})})]}),!i&&b.length===0&&!L&&e.jsx("div",{className:"py-8 text-center text-xs text-slate-400",children:'Click "Rescan" or check provider account settings above to scan for models.'}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 pt-3 border-t border-[#1E293B]",children:[e.jsx("button",{type:"button",onClick:j,className:"px-4 py-2 text-xs text-slate-400 hover:text-white transition-colors cursor-pointer",children:"Cancel"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",disabled:g.size===0,onClick:()=>pe("replace"),className:"rt-btn rt-btn--secondary text-xs disabled:opacity-40",title:"Replace current provider models list with selected models",children:["Replace Existing (",g.size,")"]}),e.jsxs("button",{type:"button",disabled:g.size===0,onClick:()=>pe("merge"),className:"rt-btn rt-btn--primary text-xs disabled:opacity-40",title:"Append newly selected models without removing existing ones",children:["Merge with Existing (",g.size,")"]})]})]})]})})},Wt=({provider:l,onBack:n})=>{var Xe,Ze,et,tt,st,at;const t=ot(l.id),[h,j]=s.useState([]),[f,i]=s.useState([]),H=s.useMemo(()=>[...f].sort((a,r)=>a.localeCompare(r,void 0,{sensitivity:"base"})),[f]),[b,V]=s.useState((t==null?void 0:t.models)||[]),[g,w]=s.useState(null),[v,O]=s.useState("1"),[A,k]=s.useState(!1),[I,z]=s.useState((t==null?void 0:t.thinkingMode)||"auto"),[X,E]=s.useState((t==null?void 0:t.thinkingOptions)||["auto","none","low","medium","high"]),[L,B]=s.useState(l.format||(t==null?void 0:t.format)||"openai"),[P,ae]=s.useState([]),[q,te]=s.useState((t==null?void 0:t.baseUrl)||l.baseUrl||""),[D,Q]=s.useState(""),[R,$]=s.useState([]),[W,se]=s.useState(!1),[ue,Y]=s.useState(!1),[ie,ye]=s.useState(!1),[me,pe]=s.useState(!1),[J,ne]=s.useState(!1),[F,_]=s.useState(!1),[c,d]=s.useState(!1),[C,he]=s.useState(""),[Z,ve]=s.useState(null),[S,de]=s.useState(null),[le,oe]=s.useState({}),[x,y]=s.useState(!1),[p,U]=s.useState(!1),[T,G]=s.useState(null),[K,Ae]=s.useState(""),[be,fe]=s.useState(""),[we,ge]=s.useState(null),[Ee,xe]=s.useState(null),[Oe,ke]=s.useState(!1),[$e,Ue]=s.useState(!1),[Pe,Re]=s.useState(null),[ee,_e]=s.useState(null),[De,He]=s.useState(""),Fe=l.category==="custom"||!t,Te=(t==null?void 0:t.authType)==="cookie"||(t==null?void 0:t.category)==="webCookie"||l.category==="webCookie",Ne=!Te&&(lt(t)||lt(l)),We=!Te&&(Array.isArray(t==null?void 0:t.authModes)?t.authModes.includes("apikey"):!!((t==null?void 0:t.category)==="apikey"||(Xe=t==null?void 0:t.notice)!=null&&Xe.apiKeyUrl||l.category==="apikey"&&!["antigravity","cursor","github","kiro"].includes(l.id))),Me=()=>{if(l.id==="github"){ye(!0);return}if(l.id==="cursor"){pe(!0);return}if(l.id==="kiro"){ne(!0);return}Y(!0)},u=s.useCallback(()=>{k(!1);const a=(t==null?void 0:t.defaultHeaders)||{},r=Object.entries(a).map(([o,N])=>({key:o,value:String(N)})),m=((t==null?void 0:t.models)||[]).map(o=>o.id);fetch(`/api/providers/${l.id}`).then(o=>{if(!o.ok)throw new Error(`HTTP ${o.status}`);return o.json()}).then(o=>{o.format&&B(o.format),Array.isArray(o.supportedFormats)&&o.supportedFormats.length>0?ae(o.supportedFormats.map(M=>typeof M=="string"?{value:M,label:M.toUpperCase()}:M)):Array.isArray(t==null?void 0:t.supportedFormats)&&t.supportedFormats.length>0?ae(t.supportedFormats.map(M=>typeof M=="string"?{value:M,label:M.toUpperCase()}:M)):ae([]),o.baseUrl&&te(o.baseUrl),o.proxyUrl&&Q(o.proxyUrl),o.thinkingMode&&z(o.thinkingMode),Array.isArray(o.thinkingOptions)&&o.thinkingOptions.length>0&&E(o.thinkingOptions),o.strategy!==void 0&&w(o.strategy||null),o.stickyLimit!=null&&O(String(o.stickyLimit)),k(!0);const N=o.userCustomHeaders!==void 0?o.userCustomHeaders:o.customHeaders||{};N&&Object.keys(N).length>0?$(Object.entries(N).map(([M,je])=>({key:M,value:String(je)}))):$([]),Array.isArray(o.catalogModels)&&o.catalogModels.length>0&&V(o.catalogModels),Array.isArray(o.models)&&o.models.length>0?i(o.models):i(m),o.accounts&&o.accounts.length>0?j(o.accounts.map((M,je)=>{var Ie;return{id:M.id,name:M.name,tag:M.tag||((Ie=M.providerSpecificData)==null?void 0:Ie.tag),supportedModelsCount:M.supportedModelsCount,isActive:M.isActive,order:M.sortOrder??je,providerSpecificData:M.providerSpecificData}})):j([]),Se()}).catch(()=>{$(r),i(m),j([])})},[l.id,l.name,t]);s.useEffect(()=>{u()},[u]);const re=async(a,r,m,o)=>{try{const N=await fetch(`/api/providers/${l.id}/strategy`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({strategy:a||null,stickyLimit:a==="round-robin"?Number(r)||1:null})});if(!N.ok)throw new Error(`HTTP ${N.status}`);k(!0)}catch(N){console.warn("Failed to save provider strategy:",N),w(m),O(o)}},ce=async a=>{const r=h.map(m=>m.id===a?{...m,isActive:!m.isActive}:m);j(r);try{await fetch(`/api/providers/${l.id}/accounts/${a}/toggle`,{method:"PUT"}),Se()}catch{}},Ce=(a,r)=>{if(r==="up"&&a===0||r==="down"&&a===h.length-1)return;const m=r==="up"?a-1:a+1,o=[...h],N=o[a];o[a]=o[m],o[m]=N;const M=o.map((je,Ie)=>({...je,order:Ie}));j(M),fetch(`/api/providers/${l.id}/accounts/reorder`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({accountIds:M.map(je=>je.id)})}).then(je=>{je.ok||console.error("Failed to reorder accounts:",je.status),Se()}).catch(je=>{console.error("Failed to reorder accounts:",je)})},Ke=a=>{j(h.filter(r=>r.id!==a)),fetch(`/api/providers/${l.id}/accounts/${a}`,{method:"DELETE"}).then(()=>Se()).catch(()=>{})},rt=a=>{Re({id:a.id,providerId:l.id,name:a.name,isActive:a.isActive,providerSpecificData:a.providerSpecificData})},it=async a=>{if(!Pe)return;const r=await fetch(`/api/providers/${l.id}/accounts/${Pe.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!r.ok){const m=await r.json().catch(()=>({}));throw new Error(m.error||"Failed to update account.")}u(),Se()},Je=async(a,r)=>{r!==void 0&&ve(r),de(a.id);try{const o=await(await fetch(`/api/providers/${l.id}/accounts/${a.id}/test`,{method:"POST"})).json();oe(N=>({...N,[a.id]:{success:!!o.success,message:o.message||(o.success?"Connection verified":"Connection failed"),latencyMs:o.latencyMs}}))}catch(m){oe(o=>({...o,[a.id]:{success:!1,message:m.message||"Failed to reach gateway"}}))}finally{r!==void 0&&ve(null),de(null)}},ct=async()=>{if(!(p||h.length===0)){U(!0);try{for(let a=0;a<h.length;a++){const r=h[a];await Je(r,a)}}finally{ve(null),U(!1)}}},Ve=async()=>{y(!0),G(null);try{const r=await(await fetch(`/api/providers/${l.id}/test`,{method:"POST"})).json();G({success:!!r.success,message:r.message||(r.success?"Connection successful!":"Connection failed."),latencyMs:r.latencyMs})}catch(a){G({success:!1,message:`Error testing connection: ${a.message}`})}finally{y(!1)}},dt=()=>{K.trim()&&($([...R,{key:K.trim(),value:be.trim()}]),Ae(""),fe(""))},qe=a=>{$(R.filter((r,m)=>m!==a))},Ge=(a,r,m)=>{const o=[...R];o[a]={key:r,value:m},$(o)},xt=()=>{$([]),ge("Reset custom headers. Using system defaults."),setTimeout(()=>ge(null),3e3)},ut=(a,r)=>{R.findIndex(o=>o.key.trim().toLowerCase()===a.toLowerCase())>=0||$([...R,{key:a,value:r}])},mt=a=>{$(R.filter(r=>r.key.trim().toLowerCase()!==a.toLowerCase()))},pt=a=>{const r=R.filter(m=>m.key.trim().toLowerCase()!==a.toLowerCase());$([...r,{key:a,value:""}])},ht=a=>{$(R.filter(r=>r.key.trim().toLowerCase()!==a.toLowerCase()))},bt=()=>{if(!C.trim())return;const a=C.trim();f.includes(a)||i([...f,a]),he(""),_(!1)},ft=a=>{i(f.filter(r=>r!==a))},gt=async(a,r)=>{let m;if(r==="replace")m=a;else{const N=new Set(f),M=a.filter(je=>!N.has(je));m=[...f,...M]}i(m);const o={};R.forEach(N=>{N.key.trim()&&(o[N.key.trim()]=N.value.trim())});try{await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:l.id,name:l.name,baseUrl:q||l.baseUrl||(t==null?void 0:t.baseUrl)||"https://api.openai.com",format:L||l.format||(t==null?void 0:t.format)||"openai",customHeaders:o,proxyUrl:D.trim()||void 0,thinkingMode:I,...A?{strategy:g,stickyLimit:g==="round-robin"?Number(v)||1:null}:{},models:m})}),ge(`Saved ${m.length} models for ${l.name}.`),Se(),u(),setTimeout(()=>ge(null),3e3)}catch{}},jt=a=>{navigator.clipboard.writeText(a),xe(a),setTimeout(()=>{xe(r=>r===a?null:r)},2e3)},Qe=async()=>{const a={};R.forEach(r=>{r.key.trim()&&(a[r.key.trim()]=r.value.trim())});try{await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:l.id,name:l.name,baseUrl:q||l.baseUrl||(t==null?void 0:t.baseUrl)||"https://api.openai.com",format:L||l.format||(t==null?void 0:t.format)||"openai",customHeaders:a,proxyUrl:D.trim()||void 0,thinkingMode:I,...A?{strategy:g,stickyLimit:g==="round-robin"?Number(v)||1:null}:{},models:f})}),ge("Configuration saved successfully."),Se(),setTimeout(()=>ge(null),3e3)}catch{}},yt=async()=>{Ue(!0);try{(await fetch(`/api/providers/${l.id}`,{method:"DELETE"})).ok&&(Se(),n())}catch{}finally{Ue(!1),ke(!1)}},Ye=((Ze=t==null?void 0:t.notice)==null?void 0:Ze.apiKeyUrl)||((et=t==null?void 0:t.notice)==null?void 0:et.signupUrl)||(t==null?void 0:t.website),vt=(tt=t==null?void 0:t.notice)!=null&&tt.apiKeyUrl?"Get API Key":"Sign up / Learn more";return e.jsxs("div",{className:"space-y-6 w-full px-2 sm:px-4 pb-16 animate-rt-fade-in",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{type:"button",onClick:a=>{a.preventDefault(),a.stopPropagation(),n()},className:"flex items-center gap-1.5 text-xs font-semibold text-slate-400 hover:text-blue-400 transition-colors cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"arrow_back"}),"Back to Providers"]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3.5",children:[e.jsx(Le,{src:l.image,name:l.name,color:(t==null?void 0:t.color)||l.color,iconBg:(t==null?void 0:t.iconBg)||l.iconBg,size:"lg"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2.5 flex-wrap",children:[e.jsx("h2",{className:"text-xl font-bold text-white tracking-tight",children:l.name}),e.jsx("span",{className:"text-[11px] font-mono px-2 py-0.5 rounded bg-[#1E293B] text-slate-300",children:(t==null?void 0:t.format)||l.format||"openai"}),Ye&&e.jsxs("a",{href:Ye,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-blue-400 hover:text-blue-300 hover:underline inline-flex items-center gap-1 font-medium transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"open_in_new"}),vt]})]}),e.jsxs("span",{className:"text-xs text-slate-400 font-mono",children:[h.length," connection",h.length===1?"":"s"," • ",f.length," available models"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:Ve,disabled:x,className:"rt-btn rt-btn--secondary hover:border-blue-500/50",title:"Test connection with upstream provider",children:[e.jsx("span",{className:`material-symbols-outlined text-[16px] ${x?"animate-spin text-blue-400":""}`,children:x?"sync":"speed"}),x?"Testing...":"Test Connection"]}),e.jsxs("button",{onClick:Qe,className:"rt-btn rt-btn--primary",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"save"}),"Save Provider Settings"]})]})]})]}),T&&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 ${T.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:T.success?"check_circle":"error"}),e.jsx("span",{className:"truncate",children:T.message})]}),T.latencyMs&&e.jsxs("span",{className:"shrink-0 font-bold opacity-80",children:[T.latencyMs,"ms"]})]}),(t==null?void 0:t.deprecated)&&e.jsxs("div",{className:"flex items-start gap-2.5 px-4 py-3 rounded-xl bg-amber-500/10 border border-amber-500/30 text-xs text-amber-300 leading-relaxed animate-rt-scale-in",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] text-amber-400 mt-0.5 shrink-0",children:"warning"}),e.jsx("p",{children:t.deprecationNotice||"This provider uses an undocumented or risk-prone connection session. Use at your own risk."})]}),((st=t==null?void 0:t.notice)==null?void 0:st.text)&&!(t!=null&&t.deprecated)&&e.jsxs("div",{className:"flex flex-col gap-2 rounded-xl border border-blue-500/30 bg-blue-500/10 px-4 py-3 sm:flex-row sm:items-center text-xs animate-rt-scale-in",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] text-blue-400 shrink-0",children:"info"}),e.jsx("p",{className:"min-w-0 flex-1 text-blue-300 leading-relaxed",children:t.notice.text}),t.notice.apiKeyUrl&&e.jsx("a",{href:t.notice.apiKeyUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex justify-center rounded bg-blue-500 px-2.5 py-1 text-xs font-medium text-white transition-colors hover:bg-blue-600 shrink-0",children:"Get API Key →"})]}),(l.id==="opencode"||(t==null?void 0:t.noAuth)||(t==null?void 0:t.requiresApiKey)===!1||(t==null?void 0:t.authType)==="none"||(t==null?void 0:t.isLocal))&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-3 px-4 py-3.5 rounded-xl bg-emerald-500/10 border border-emerald-500/30 text-xs text-emerald-300 animate-rt-scale-in",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"material-symbols-outlined text-[20px] text-emerald-400 shrink-0",children:"check_circle"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-white",children:t!=null&&t.isLocal?"Local Provider (No Paid Key Required)":"No Authentication Required (100% Free)"}),e.jsx("p",{className:"text-slate-400 mt-0.5",children:t!=null&&t.isLocal?`${l.name} runs directly on your local device without external API tokens.`:`${l.name} is ready to use immediately without an account or API key.`})]})]}),e.jsxs("button",{onClick:Ve,disabled:x,className:"px-3 py-1.5 rounded-lg bg-emerald-500 hover:bg-emerald-600 text-white font-medium shrink-0 flex items-center gap-1.5 transition-colors cursor-pointer disabled:opacity-50",children:[e.jsx("span",{className:`material-symbols-outlined text-[15px] ${x?"animate-spin":""}`,children:x?"sync":"speed"}),x?"Testing...":"Test Connection"]})]}),e.jsxs("div",{className:"rt-card p-5 space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h3",{className:"text-sm font-bold text-white",children:"Connections & Priority Queue"}),e.jsxs("span",{className:"text-xs text-slate-500",children:["(",h.filter(a=>a.isActive).length," active)"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-xs",children:[e.jsxs("button",{onClick:ct,disabled:p||Z!==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] ${p||Z!==null?"animate-spin text-blue-400":""}`,children:"sync"}),p?"Testing...":"Test Connection One-by-One"]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 pl-2 border-l border-[#1E293B]",children:[e.jsx("span",{className:"text-xs text-slate-400 font-medium",children:"Strategy:"}),e.jsx(ze,{value:g||"",onChange:a=>{const r=g,m=v,o=a||null;w(o);const N=o==="round-robin"?v||"1":v;o==="round-robin"&&!v&&O("1"),re(o,N,r,m)},options:[{value:"",label:"Default (Global)"},{value:"fill-first",label:"Fill First"},{value:"sequential",label:"Sequential (Drain)"},{value:"round-robin",label:"Round Robin"},{value:"earliest-reset",label:"Earliest Reset"}],className:"w-40"}),g==="round-robin"&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs text-slate-400",children:"Sticky:"}),e.jsx("input",{type:"number",min:1,value:v,onChange:a=>{const r=v,m=a.target.value;O(m),re("round-robin",m,g,r)},placeholder:"1",className:"w-14 px-2 py-1 text-xs border border-[#1E293B] rounded-lg bg-[#0A0D14] text-slate-200 focus:outline-none focus:border-blue-500 font-mono"})]})]})]})]}),h.length===0?e.jsxs("div",{className:"w-full py-10 px-4 text-center text-slate-400 flex flex-col items-center justify-center gap-2.5 bg-[#0A0D14] rounded-xl border border-dashed border-[#1E293B]",children:[e.jsx("span",{className:"material-symbols-outlined text-3xl text-slate-600",children:Ne?"vpn_key_off":"key_off"}),e.jsxs("p",{className:"text-sm font-semibold text-slate-300",children:["No accounts connected for ",l.name]}),e.jsx("p",{className:"text-xs text-slate-500 max-w-sm",children:Ne?`Connect your ${l.name} account via OAuth or add credentials to start routing.`:`Add an API key or credentials to start routing requests through ${l.name}.`})]}):e.jsx("div",{className:"space-y-2",children:h.map((a,r)=>{const m=le[a.id],o=Z===r||S===a.id;return e.jsxs("div",{className:"flex flex-col gap-2 p-3 rounded-xl bg-[#0A0D14] border border-[#1E293B] hover:border-blue-500/30 transition-all text-xs",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsxs("div",{className:"flex flex-col text-slate-500",children:[e.jsx("button",{onClick:()=>Ce(r,"up"),disabled:r===0,className:"hover:text-white disabled:opacity-30 leading-none cursor-pointer",children:"▲"}),e.jsx("button",{onClick:()=>Ce(r,"down"),disabled:r===h.length-1,className:"hover:text-white disabled:opacity-30 leading-none cursor-pointer",children:"▼"})]}),e.jsx("span",{className:"material-symbols-outlined text-[16px] text-slate-500",children:Ne?"lock":"key"}),e.jsx("span",{className:"font-mono text-slate-200 truncate font-medium",children:a.name}),a.tag?e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 text-[10px] font-mono rounded-md bg-blue-500/15 text-blue-300 border border-blue-500/30 font-semibold tracking-wide shadow-sm",children:[e.jsx("span",{className:"material-symbols-outlined text-[12px] text-blue-400",children:"label"}),a.tag]}):e.jsx("span",{className:"text-[10px] font-mono text-slate-600 border border-dashed border-[#1E293B] px-1.5 py-0.5 rounded",children:"no-tag"}),a.supportedModelsCount!=null?e.jsxs("button",{type:"button",onClick:()=>{_e({accountId:a.id,accountName:a.name,models:[],scanned:!0,loading:!0}),He(""),fetch(`/api/providers/${l.id}/accounts/${a.id}/models`).then(N=>N.json()).then(N=>{_e(M=>M&&M.accountId===a.id?{...M,models:N.models||[],scanned:!!N.scanned,loading:!1}:M)}).catch(()=>{_e(N=>N&&N.accountId===a.id?{...N,loading:!1}:N)})},className:`inline-flex items-center gap-1 px-2 py-0.5 text-[10px] font-mono rounded-md border font-medium cursor-pointer transition-all hover:scale-[1.02] active:scale-[0.98] ${a.supportedModelsCount>=(f.length||1)?"bg-emerald-500/10 text-emerald-400 border-emerald-500/20 hover:bg-emerald-500/20":"bg-amber-500/10 text-amber-300 border-amber-500/20 hover:bg-amber-500/20"}`,title:"Click to view verified models for this account",children:[e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:a.supportedModelsCount>=(f.length||1)?"check_circle":"tune"}),a.supportedModelsCount," / ",f.length," models"]}):e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 text-[10px] font-mono rounded-md bg-slate-800/80 text-slate-400 border border-slate-700/50",title:"Account has not been scanned yet. Will fail-open and auto-learn when called.",children:[e.jsx("span",{className:"material-symbols-outlined text-[12px] text-slate-500",children:"help_outline"}),"unscanned"]}),e.jsxs("span",{className:`rt-badge ${a.isActive?"rt-badge--success":"rt-badge--muted"}`,children:[a.isActive?"● active":"disabled"," • #",r+1]}),o&&e.jsx("span",{className:"text-[10px] text-blue-400 animate-pulse font-mono",children:"Testing upstream..."}),m&&!o&&e.jsx("span",{className:`rt-badge text-[10px] ${m.success?"bg-emerald-500/10 text-emerald-400 border border-emerald-500/20":"bg-red-500/10 text-red-400 border border-red-500/20"}`,title:m.message,children:m.success?`● ${m.latencyMs?`${m.latencyMs}ms`:"Active"}`:"● Failed"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{title:"Test this connection",onClick:()=>Je(a,r),disabled:Z!==null||o,className:"p-1 text-slate-500 hover:text-blue-400 transition-colors cursor-pointer disabled:opacity-40",children:e.jsx("span",{className:`material-symbols-outlined text-[16px] ${o?"animate-spin text-blue-400":""}`,children:o?"sync":"speed"})}),e.jsx("button",{title:"Edit account",onClick:()=>rt(a),className:"p-1 text-slate-500 hover:text-blue-400 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"edit"})}),e.jsx("button",{title:"Delete account",onClick:()=>Ke(a.id),className:"p-1 text-slate-500 hover:text-red-400 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"delete"})}),e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer ml-1",children:[e.jsx("input",{type:"checkbox",checked:a.isActive,onChange:()=>ce(a.id),className:"sr-only peer"}),e.jsx("div",{className:"w-8 h-4.5 bg-[#1E293B] peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-3.5 after:w-3.5 after:transition-all peer-checked:bg-blue-600"})]})]})]}),m&&e.jsx("div",{className:`w-full py-1 px-2.5 text-[10px] font-mono rounded-lg border truncate ${m.success?"bg-emerald-500/10 text-emerald-400 border-emerald-500/20":"bg-red-500/10 text-red-400 border-red-500/20"}`,title:m.message,children:m.success?`✓ ${m.message}`:`✗ ${m.message}`})]},a.id)})}),Ne&&We?e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsxs("button",{onClick:Me,className:"rt-btn rt-btn--primary",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"lock"}),"Connect with OAuth"]}),e.jsxs("button",{onClick:()=>se(!0),className:"rt-btn rt-btn--secondary",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"key"}),"Add API Key"]})]}):e.jsxs("button",{onClick:()=>{Ne||["github","cursor","kiro","antigravity"].includes(l.id)?Me():se(!0)},className:"rt-btn rt-btn--primary",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:Ne||l.id==="github"||l.id==="cursor"||l.id==="kiro"?"lock":Te?"cookie":"add"}),Ne||l.id==="github"||l.id==="cursor"||l.id==="kiro"?`Connect ${l.name}`:Te?"Add Session Cookie":"Add Account"]})]}),e.jsxs("div",{className:"rt-card p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[20px]",children:"tune"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-white",children:"Upstream Request Headers"}),e.jsxs("p",{className:"text-xs text-slate-400 mt-0.5",children:["Headers forwarded to ",l.name,". System defaults are managed automatically and combined with your custom overrides."]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:xt,className:"rt-btn rt-btn--secondary text-xs",title:"Reset custom headers and use system defaults",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"restart_alt"}),"Reset"]}),e.jsxs("button",{onClick:Qe,className:"rt-btn rt-btn--primary text-xs",title:"Save headers",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"save"}),"Save"]})]})]}),we&&e.jsxs("div",{className:"text-[11px] text-emerald-400 font-mono flex items-center gap-1.5 animate-rt-scale-in",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"check_circle"}),we]}),(t==null?void 0:t.defaultHeaders)&&Object.keys(t.defaultHeaders).length>0&&e.jsxs("div",{className:"p-3.5 rounded-xl bg-[#0A0D14] border border-[#1E293B] space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-semibold text-slate-300",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-emerald-400",children:"verified"}),e.jsx("span",{children:"System Default Headers"}),e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-emerald-500/10 text-emerald-400 border border-emerald-500/20",children:"Auto-updated on release"})]}),e.jsx("span",{className:"text-[11px] text-slate-500 font-mono",children:"Managed by Mapigate"})]}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"These headers automatically update with new Mapigate releases. If upstream changes before an official update, click Customize to edit and override it immediately."}),e.jsx("div",{className:"space-y-1.5 pt-1",children:Object.entries(t.defaultHeaders).map(([a,r])=>{const m=R.find(M=>M.key.trim().toLowerCase()===a.toLowerCase()),o=m!==void 0&&m.value==="",N=m!==void 0&&m.value!=="";return e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 rounded-lg bg-[#0F141C] border border-[#1E293B]/60 text-xs font-mono",children:[e.jsxs("div",{className:"flex items-center gap-2 truncate pr-2",children:[e.jsx("span",{className:o?"text-slate-600 line-through":"text-blue-400 font-semibold",children:a}),e.jsx("span",{className:"text-slate-600",children:":"}),e.jsx("span",{className:o||N?"text-slate-500 line-through truncate":"text-slate-300 truncate",children:r}),N&&e.jsxs("span",{className:"text-amber-300 font-semibold truncate",children:["→ ",m==null?void 0:m.value]})]}),e.jsx("div",{className:"flex items-center gap-2 shrink-0",children:o?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-rose-500/10 text-rose-400 border border-rose-500/20 font-sans font-semibold",children:"Disabled / Omitted"}),e.jsxs("button",{type:"button",onClick:()=>ht(a),className:"flex items-center gap-1 text-[11px] text-emerald-400 hover:text-emerald-300 px-2 py-1 rounded bg-emerald-500/10 hover:bg-emerald-500/20 border border-emerald-500/20 transition-colors cursor-pointer",title:"Re-enable this default header",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"check_circle"}),"Enable"]})]}):N?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20 font-sans font-semibold",children:"Overridden"}),e.jsxs("button",{type:"button",onClick:()=>mt(a),className:"flex items-center gap-1 text-[11px] text-slate-400 hover:text-white px-2 py-1 rounded bg-[#1E293B] hover:bg-[#2A374A] transition-colors cursor-pointer",title:"Revert to system default value",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"undo"}),"Revert"]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>ut(a,r),className:"flex items-center gap-1 text-[11px] text-blue-400 hover:text-blue-300 px-2 py-1 rounded bg-blue-500/10 hover:bg-blue-500/20 border border-blue-500/20 transition-colors cursor-pointer",title:"Override or adjust this default header value",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"edit"}),"Customize"]}),e.jsxs("button",{type:"button",onClick:()=>pt(a),className:"flex items-center gap-1 text-[11px] text-slate-500 hover:text-rose-400 px-2 py-1 rounded hover:bg-rose-500/10 transition-colors cursor-pointer",title:"Disable/remove this default header from outgoing requests",children:[e.jsx("span",{className:"material-symbols-outlined text-[13px]",children:"block"}),"Disable"]})]})})]},a)})})]}),e.jsxs("div",{className:"pt-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-semibold text-slate-300 mb-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-blue-400",children:"tune"}),e.jsx("span",{children:"Custom Header Overrides & Additions"})]}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"Add custom headers or override/disable default headers. These values take precedence over system defaults."})]}),e.jsxs("div",{className:"space-y-2",children:[R.length===0?e.jsx("div",{className:"text-xs text-slate-500 italic p-3 rounded-xl bg-[#0A0D14] border border-[#1E293B]",children:'No custom header overrides configured. Outgoing requests will use the system default headers above. Click "Customize" on any default header or add a new header below.'}):e.jsx("div",{className:"space-y-2",children:R.map((a,r)=>{const m=!!(t!=null&&t.defaultHeaders&&Object.keys(t.defaultHeaders).some(N=>N.toLowerCase()===a.key.trim().toLowerCase())),o=a.value==="";return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"w-1/3 relative",children:[e.jsx("input",{type:"text",value:a.key,onChange:N=>Ge(r,N.target.value,a.value),className:`w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs font-mono focus:outline-none focus:border-blue-500 ${o?"text-slate-500 line-through":"text-blue-400"}`,placeholder:"Header Key"}),m&&e.jsx("span",{className:`absolute right-2 top-2 text-[10px] font-sans pointer-events-none font-semibold ${o?"text-rose-400":"text-amber-400"}`,children:o?"Disabled":"Override"})]}),o?e.jsxs("div",{className:"flex-1 bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-rose-400/80 italic font-mono flex items-center justify-between",children:[e.jsx("span",{children:"(Disabled — this header will be omitted from outgoing requests)"}),e.jsx("button",{type:"button",onClick:()=>qe(r),className:"text-[11px] text-emerald-400 hover:text-emerald-300 font-sans not-italic hover:underline cursor-pointer",children:"Re-enable"})]}):e.jsx("input",{type:"text",value:a.value,onChange:N=>Ge(r,a.key,N.target.value),className:"flex-1 bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-slate-200 font-mono focus:outline-none focus:border-blue-500",placeholder:"Header Value"}),e.jsx("button",{onClick:()=>qe(r),className:"p-2 text-slate-500 hover:text-red-400 transition-colors cursor-pointer rounded-lg hover:bg-red-500/10",title:o?"Re-enable header":m?"Remove override (reverts to default)":"Delete header",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:o||m?"undo":"delete"})})]},r)})}),e.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[e.jsx("input",{type:"text",placeholder:"Key (e.g. User-Agent or Anthropic-Beta)",value:K,onChange:a=>Ae(a.target.value),className:"w-1/3 bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white font-mono focus:outline-none focus:border-blue-500"}),e.jsx("input",{type:"text",placeholder:"Value",value:be,onChange:a=>fe(a.target.value),className:"flex-1 bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white font-mono focus:outline-none focus:border-blue-500"}),e.jsxs("button",{onClick:dt,className:"rt-btn rt-btn--secondary text-xs shrink-0",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"add"}),"Add Header"]})]})]}),P.length>0&&e.jsxs("div",{className:"pt-3 border-t border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{className:"block text-slate-400 font-semibold text-xs",children:"Target API Protocol Format"}),e.jsx("span",{className:"text-[11px] text-slate-500",children:"Select upstream API format"})]}),e.jsx(ze,{value:L,onChange:B,options:P,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!==q&&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:q,onChange:a=>te(a.target.value),className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white font-mono focus:outline-none focus:border-blue-500"})]}),e.jsxs("div",{className:"pt-3 border-t border-[#1E293B]",children:[e.jsx("label",{className:"block text-slate-400 font-semibold mb-1 text-xs",children:"Outbound HTTP / SOCKS5 Proxy (Optional)"}),e.jsx("input",{type:"text",placeholder:"http://127.0.0.1:7890 or socks5://127.0.0.1:1080",value:D,onChange:a=>Q(a.target.value),className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white font-mono focus:outline-none focus:border-blue-500"})]})]}),e.jsxs("div",{className:"rt-card p-5 space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 pb-3 border-b border-[#1E293B]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h3",{className:"text-sm font-bold text-white",children:"Available Models"}),e.jsxs("span",{className:"text-xs text-slate-500 font-mono",children:["(",f.length," active)"]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-slate-400 ml-2",children:[e.jsx("span",{children:"Thinking / Reasoning:"}),e.jsx(ze,{value:I,onChange:z,options:X.map(a=>({value:a,label:a.toUpperCase()})),className:"w-32",triggerClassName:"font-mono text-xs"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>d(!0),className:"rt-btn rt-btn--secondary text-xs flex items-center gap-1.5",title:"Scan models directly from provider API endpoint",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px] text-blue-400",children:"radar"}),"Scan Models from API"]}),e.jsxs("button",{onClick:()=>_(!0),className:"rt-btn rt-btn--secondary text-xs",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"add"}),"Add Custom Model"]})]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2.5",children:H.map(a=>{const r=b.find(o=>o.id===a),m=Ee===a;return e.jsxs("div",{className:"flex items-center justify-between p-2.5 rounded-xl bg-[#0A0D14] border border-[#1E293B] hover:border-blue-500/30 text-xs transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2 truncate",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px] text-blue-400 shrink-0",children:"smart_toy"}),e.jsxs("div",{className:"truncate",children:[e.jsx("span",{className:"font-mono text-slate-200 truncate block",children:a}),r&&r.name&&r.name!==a&&e.jsx("span",{className:"text-[10px] text-slate-500 truncate block",children:r.name})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:()=>jt(a),title:m?"Copied!":"Copy model ID",className:"p-1 text-slate-500 hover:text-white cursor-pointer transition-colors",children:e.jsx("span",{className:`material-symbols-outlined text-[14px] ${m?"text-emerald-400 font-bold":""}`,children:m?"check":"content_copy"})}),e.jsx("button",{onClick:()=>ft(a),title:"Remove model",className:"p-1 text-slate-500 hover:text-red-400 cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]})]},a)})})]}),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:()=>ke(!0),disabled:$e,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"}),$e?"Deleting...":"Delete Provider"]})]})}),W&&e.jsx(Dt,{isOpen:W,provider:{id:l.id,name:l.name,image:l.image,color:(t==null?void 0:t.color)||l.color,iconBg:(t==null?void 0:t.iconBg)||l.iconBg,format:(t==null?void 0:t.format)||l.format,website:t==null?void 0:t.website,apiKeyUrl:(at=t==null?void 0:t.notice)==null?void 0:at.apiKeyUrl,regions:t==null?void 0:t.regions,defaultRegion:t==null?void 0:t.defaultRegion,requiresApiKey:t==null?void 0:t.requiresApiKey,authType:t==null?void 0:t.authType,isLocal:t==null?void 0:t.isLocal,defaultBaseUrl:(t==null?void 0:t.defaultBaseUrl)||(t==null?void 0:t.baseUrl),noAuth:t==null?void 0:t.noAuth,supportsAutoImport:t==null?void 0:t.supportsAutoImport,autoImportHint:t==null?void 0:t.autoImportHint},existingNames:h.map(a=>a.name),onClose:()=>se(!1),onSuccess:u,onOpenOAuth:Ne?()=>{se(!1),Me()}:void 0}),ie&&e.jsx(Tt,{isOpen:ie,onClose:()=>ye(!1),onSuccess:u}),me&&e.jsx(Bt,{isOpen:me,onClose:()=>pe(!1),onSuccess:u}),J&&e.jsx(Pt,{isOpen:J,onClose:()=>ne(!1),onSuccess:u}),ue&&e.jsx(St,{isOpen:ue,providerId:l.id,providerName:l.name,onSuccess:u,onClose:()=>Y(!1)}),e.jsx(Be,{isOpen:F,onClose:()=>_(!1),maxWidthClass:"max-w-lg",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Add Custom Model"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-300 mb-1",children:"Model Identifier"}),e.jsx("input",{type:"text",placeholder:"e.g. custom-gpt-oss or claude-3-7-sonnet",value:C,onChange:a=>he(a.target.value),className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white font-mono focus:outline-none focus:border-blue-500"})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2 border-t border-[#1E293B]",children:[e.jsx("button",{onClick:()=>_(!1),className:"px-4 py-2 text-xs text-slate-400 cursor-pointer",children:"Cancel"}),e.jsx("button",{onClick:bt,className:"rt-btn rt-btn--primary",children:"Add Model"})]})]})}),e.jsx(_t,{isOpen:c,provider:{id:l.id,name:l.name,baseUrl:q||l.baseUrl||(t==null?void 0:t.baseUrl),modelsUrl:l.modelsUrl||(t==null?void 0:t.modelsUrl),image:l.image,color:(t==null?void 0:t.color)||l.color,iconBg:(t==null?void 0:t.iconBg)||l.iconBg,format:l.format||(t==null?void 0:t.format)},existingModels:f,accountsCount:h.length,onAddAccount:()=>{d(!1),Ne||["github","cursor","kiro","antigravity"].includes(l.id)?Me():se(!0)},onClose:()=>d(!1),onApplyModels:gt}),e.jsx(kt,{isOpen:!!Pe,account:Pe,onClose:()=>Re(null),onSave:it}),e.jsx(Be,{isOpen:!!ee,onClose:()=>_e(null),maxWidthClass:"max-w-2xl",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-[#1E293B] pb-3",children:[e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-bold text-white flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[18px]",children:"verified"}),"Verified Account Models"]}),e.jsx("p",{className:"text-[11px] text-slate-400 font-mono mt-0.5 truncate max-w-xs",children:ee==null?void 0:ee.accountName})]}),e.jsxs("span",{className:"px-2 py-0.5 text-[11px] font-mono rounded bg-blue-500/10 text-blue-400 font-semibold border border-blue-500/20",children:[(ee==null?void 0:ee.models.length)||0," models"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"material-symbols-outlined absolute left-2.5 top-1/2 -translate-y-1/2 text-slate-500 text-[16px]",children:"search"}),e.jsx("input",{type:"text",value:De,onChange:a=>He(a.target.value),placeholder:"Search supported models...",className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl pl-8 pr-3 py-1.5 text-xs text-white font-mono focus:outline-none focus:border-blue-500"})]}),e.jsx("div",{className:"max-h-60 overflow-y-auto space-y-1 pr-1 font-mono text-xs",children:ee!=null&&ee.loading?e.jsxs("div",{className:"py-8 text-center text-slate-500 flex items-center justify-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-[16px]",children:"sync"}),"Loading account models..."]}):(ee==null?void 0:ee.models.length)===0?e.jsx("div",{className:"py-8 text-center text-slate-500",children:"No specific models registered for this account yet."}):[...(ee==null?void 0:ee.models)||[]].filter(a=>!De||a.toLowerCase().includes(De.toLowerCase())).sort((a,r)=>a.localeCompare(r,void 0,{sensitivity:"base"})).map(a=>e.jsxs("div",{className:"flex items-center justify-between p-2 rounded-lg bg-[#0A0D14] border border-[#1E293B] hover:border-blue-500/30 text-slate-200",children:[e.jsx("span",{className:"truncate",children:a}),e.jsx("span",{className:"text-[10px] text-emerald-400",children:"ready"})]},a))}),e.jsx("div",{className:"flex justify-end pt-2 border-t border-[#1E293B]",children:e.jsx("button",{onClick:()=>_e(null),className:"rt-btn rt-btn--secondary text-xs",children:"Close"})})]})}),Fe&&e.jsx(Ct,{isOpen:Oe,title:"Delete Provider",message:`Are you sure you want to delete custom provider "${l.name}"? This will permanently remove the provider configuration and all associated accounts/credentials.`,confirmText:"Delete",variant:"danger",onConfirm:yt,onCancel:()=>ke(!1)})]})};export{Wt as ProviderDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e,r as h}from"./vendor-BcOI2aZ9.js";import{g as D}from"./metadataRegistry-EMxpq0lK.js";import{T as V}from"./ToolIcon-BZE0Fv7L.js";import{S as F}from"./Select-BNRH8LIG.js";import{C as Y,E as K}from"./EditAccountModal-DdreWxg7.js";import{C as X}from"./ConfirmModal-DCYNsbhd.js";import"./index-Di7mCTbW.js";import"./lucide-Cc35htxl.js";const Z={antigravity:["Gemini (5h)","Gemini (Weekly)","Claude & GPT (5h)","Claude & GPT (Weekly)","Gemini 4 Argon (Weekly)"],github:["Chat","Completions","Premium Interactions"],copilot:["Chat","Completions","Premium Interactions"],claude:["5-Hour Window","5h Session","Session","7-Day Window","Weekly"],codex:["Session","Weekly","Credits","Balance"],openai:["Session","Weekly","Credits","Balance"],gemini:["Requests (RPM)","Requests (Daily)","Tokens (TPM)","Tokens (Daily)"],"gemini-cli":["Gemini (5h)","Gemini (Weekly)","Requests (RPM)","Requests (Daily)","Tokens (TPM)","Tokens (Daily)"],grok:["Session","Weekly","Requests","Tokens","Balance"],"grok-cli":["Session","Weekly","Requests","Tokens","Balance"],kiro:["Session","Weekly","Monthly","Credits"],deepseek:["Balance","Total Grants","Topped-up Balance"],minimax:["Coding Tokens","Standard Tokens","Balance"],"minimax-cn":["Coding Tokens","Standard Tokens","Balance"],glm:["Session","Weekly","Balance"],"glm-cn":["Session","Weekly","Balance"],qoder:["Daily","Weekly","Monthly","Balance"],"qoder-cn":["Daily","Weekly","Monthly","Balance"],xkiro:["Session (5h)","Weekly (7d)","Free Tokens (Daily)","Wallet Balance"],"xiaomi-tokenplan":["Monthly Tokens","Weekly Quota"],xmtp:["Monthly Tokens","Weekly Quota"],"xiaomi-mimo":["Monthly Tokens","Weekly Quota"],mimo:["Monthly Tokens","Weekly Quota"],trae:["Dollar Usage","Autocomplete","Fast Requests"]},ee=new Proxy(Z,{get(s,o){if(typeof o!="string")return;const m=o.toLowerCase(),u=D(m);return u!=null&&u.quotaOrder?u.quotaOrder:s[m]},has(s,o){if(typeof o!="string")return!1;const m=o.toLowerCase(),u=D(m);return!!(u!=null&&u.quotaOrder)||m in s}});function te(s,o){if(!o||o.length<=1)return o?[...o]:[];const m=(s||"").toLowerCase(),u=D(m),l=(u==null?void 0:u.quotaOrder)||ee[m]||[];return[...o].sort((g,v)=>{const f=b=>{const i=(b||"").trim().toLowerCase(),d=l.findIndex(y=>{const x=y.toLowerCase();return i===x||i.startsWith(x)||x.startsWith(i)||i.includes(x)});return d===-1?9999:d},j=f(g.label),p=f(v.label);return j!==p?j-p:(g.label||"").localeCompare(v.label||"")})}function re(s,o,m,u){const l=m.toLowerCase(),g=(u==null?void 0:u.toLowerCase())==="kiro",v=l.includes("token"),f=l.includes("credit")||g&&!l.includes("request"),j=l.includes("$")||l.includes("dollar")||l.includes("usd"),p=l.includes("cny")||l.includes("rmb")||l.includes("¥");if(j){const i=d=>`$${d.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})}`;return o>0?`${i(s)} / ${i(o)}`:i(s)}if(p){const i=d=>`¥${d.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})}`;return o>0?`${i(s)} / ${i(o)}`:i(s)}if(v){if(o>=1e9){const i=`${(o/1e9).toFixed(1)}B`;return`${s>=1e9?`${(s/1e9).toFixed(2)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s.toLocaleString()} / ${i} tokens`}if(o>=1e6){const i=`${(o/1e6).toFixed(0)}M`;return`${s>=1e6?`${(s/1e6).toFixed(2)}M`:s.toLocaleString()} / ${i} tokens`}return o>0?`${s.toLocaleString()} / ${o.toLocaleString()} tokens`:`${s.toLocaleString()} tokens`}if(f){const i=o===1?"credit":"credits";return o>0?`${s.toLocaleString()} / ${o.toLocaleString()} ${i}`:`${s.toLocaleString()} ${i}`}if(l.includes("point")||l.includes("pts")){const i=o===1?"pt":"pts";return o>0?`${s.toLocaleString()} / ${o.toLocaleString()} ${i}`:`${s.toLocaleString()} ${i}`}return l.includes("autocomplete")||l.includes("completion")?o>0?`${s.toLocaleString()} / ${o.toLocaleString()}`:`${s.toLocaleString()}`:o===100&&!l.includes("req")?`${s}% used`:l.includes("req")||l.includes("call")||l.includes("interaction")||l.includes("turn")||l.includes("prompt")||l.includes("session")||l.includes("window")||l.includes("chat")?o>0?`${s.toLocaleString()} / ${o.toLocaleString()} reqs`:`${s.toLocaleString()} reqs`:o>0?`${s.toLocaleString()} / ${o.toLocaleString()}`:`${s.toLocaleString()}`}const se=({label:s,used:o,total:m,percentage:u,resetInText:l="-",unlimited:g=!1,recurring:v=!0,providerId:f})=>{const p=(i=>i>=50?{text:"text-emerald-400",bg:"bg-emerald-500",bgTrack:"bg-emerald-500/15",emoji:"🟢"}:i>0?{text:"text-amber-400",bg:"bg-amber-500",bgTrack:"bg-amber-500/15",emoji:"🟡"}:{text:"text-red-400",bg:"bg-red-500",bgTrack:"bg-red-500/15",emoji:"🔴"})(u),b=v?"Reset":"Expires";return e.jsxs("div",{className:"space-y-1.5 py-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"font-medium text-slate-200 truncate pr-2",title:s,children:s}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx("span",{className:"text-[10px]",children:p.emoji}),e.jsx("span",{className:`font-semibold ${p.text}`,children:g?"100%":`${u}%`})]})]}),!g&&e.jsx("div",{className:`h-2 rounded-full overflow-hidden ${p.bgTrack} w-full`,children:e.jsx("div",{className:`h-full transition-all duration-300 rounded-full ${p.bg}`,style:{width:`${Math.min(100,Math.max(0,u))}%`}})}),e.jsxs("div",{className:"flex items-center justify-between text-[11px] text-slate-400",children:[e.jsx("span",{children:g?"Unlimited":re(o,m,s,f)}),l&&l!=="-"&&e.jsxs("div",{className:"flex items-center gap-1 font-mono text-[10px] text-slate-400",children:[e.jsx("span",{children:"•"}),e.jsxs("span",{children:[b," in ",l]})]})]})]})},ae={antigravity:"#4285F4",gemini:"#1A73E8","gemini-cli":"#1A73E8",claude:"#D97757",codex:"#10A37F",openai:"#10A37F",github:"#24292F",copilot:"#24292F",kiro:"#FF9900",deepseek:"#4D6BFE",grok:"#E11D48","grok-cli":"#E11D48",minimax:"#7C3AED","minimax-cn":"#7C3AED",qoder:"#EC4899","qoder-cn":"#EC4899",glm:"#0055FF","glm-cn":"#0055FF"},P=({account:s,loading:o=!1,onRefresh:m,onEdit:u,onToggle:l})=>{const[g,v]=h.useState(!1),f=D(s.providerId),j=(f==null?void 0:f.color)||ae[s.providerId.toLowerCase()]||"#3B82F6",p=async()=>{if(!(g||o)){v(!0);try{await m(s.accountId)}finally{v(!1)}}},b=o||g,i=h.useMemo(()=>{var x;let d=s.quotas||[];const y=(x=s.providerId)==null?void 0:x.toLowerCase();if(y==="antigravity"||y==="gemini-cli"){const L=["gemini (5h)","gemini (weekly)","claude & gpt (5h)","claude & gpt (weekly)","gemini 4 argon (weekly)"],k=d.filter(C=>L.some(I=>(C.label||"").toLowerCase().trim()===I));k.length>0&&(d=k)}return te(s.providerId,d)},[s.providerId,s.quotas]);return e.jsxs("div",{className:`flex flex-col justify-between bg-[#0F1420]/80 border border-[#1E293B] hover:border-slate-700/80 rounded-2xl p-4 sm:p-5 transition-all duration-200 shadow-lg min-w-[400px] ${s.isActive?"":"opacity-60 bg-[#0B0E17]/60"}`,children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 pb-3 border-b border-[#1E293B]/70",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(V,{src:(f==null?void 0:f.image)||`/assets/providers/${s.providerId}/icon.png`,name:s.providerId,color:j,iconBg:f==null?void 0:f.iconBg,size:"md"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"font-semibold text-slate-100 text-xs sm:text-sm capitalize truncate",children:s.providerId}),s.plan&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-md font-medium bg-blue-500/10 text-blue-400 border border-blue-500/20",children:s.plan})]}),e.jsx("div",{className:"text-[11px] text-slate-400 truncate max-w-[170px]",title:s.accountName,children:s.accountName})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:p,disabled:b,title:"Refresh Quota",className:"p-1.5 rounded-lg text-slate-400 hover:text-white hover:bg-[#1E293B]/70 transition-colors disabled:opacity-50 cursor-pointer",children:e.jsx("span",{className:`material-symbols-outlined text-[18px] ${b?"animate-spin text-blue-400":""}`,children:"refresh"})}),e.jsx("button",{onClick:()=>u(s),title:"Edit Account",className:"p-1.5 rounded-lg text-slate-400 hover:text-white hover:bg-[#1E293B]/70 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"edit"})}),e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer ml-1",title:"Toggle active status",children:[e.jsx("input",{type:"checkbox",checked:s.isActive,onChange:d=>l(s.accountId,d.target.checked),className:"sr-only peer"}),e.jsx("div",{className:"w-8 h-4.5 bg-slate-700 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-3.5 after:w-3.5 after:transition-all peer-checked:bg-blue-600"})]})]})]}),b&&i.length===0?e.jsxs("div",{className:"space-y-3 py-2",children:[e.jsx("div",{className:"h-4 bg-slate-800/60 rounded animate-pulse w-3/4"}),e.jsx("div",{className:"h-2 bg-slate-800/60 rounded-full animate-pulse w-full"}),e.jsx("div",{className:"h-4 bg-slate-800/60 rounded animate-pulse w-2/3"}),e.jsx("div",{className:"h-2 bg-slate-800/60 rounded-full animate-pulse w-full"})]}):i.length>0?e.jsx("div",{className:"space-y-2.5",children:i.map((d,y)=>e.jsx(se,{label:d.label,used:d.used,total:d.total,percentage:d.remainingPercentage,resetInText:d.resetInText,unlimited:d.unlimited,recurring:d.recurring,providerId:s.providerId},`${d.label}-${y}`))}):e.jsx("div",{className:"py-4 text-center text-xs text-slate-400 bg-[#0A0D14]/50 rounded-xl border border-[#1E293B]/50 px-3",children:s.error?e.jsx("span",{className:"text-red-400/90",children:s.error}):s.message||"No quota data available."})]}),e.jsxs("div",{className:"pt-3 mt-2 border-t border-[#1E293B]/50 flex items-center justify-between text-[10px] text-slate-500 font-mono",children:[e.jsx("span",{children:s.isActive?e.jsx("span",{className:"text-emerald-400 font-medium",children:"Active"}):e.jsx("span",{className:"text-slate-400",children:"Inactive"})}),s.lastFetchedAt&&e.jsxs("span",{children:["Updated ",new Date(s.lastFetchedAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]})]})},ne=({providers:s,selectedProvider:o,onSelectProvider:m,statusFilter:u,onSelectStatusFilter:l,sortMode:g,onSelectSortMode:v,autoRefresh:f,onToggleAutoRefresh:j,countdownSeconds:p,isRefreshingAll:b,onRefreshAll:i,onTurnOffEmpty:d,onTurnOnAvailable:y})=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 text-xs p-4 rounded-2xl bg-[#0F1420]/80 border border-[#1E293B] shadow-lg w-full",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[e.jsx(F,{value:o,onChange:m,options:[{value:"all",label:"All providers"},...s.map(x=>({value:x,label:x.toUpperCase()}))],className:"min-w-[140px]"}),e.jsx(F,{value:u,onChange:x=>l(x),options:[{value:"all",label:"All accounts"},{value:"active",label:"Active only"},{value:"inactive",label:"Turned off"}],className:"min-w-[130px]"}),e.jsx(F,{value:g,onChange:x=>v(x),options:[{value:"fixed",label:"Fixed order (Providers)"},{value:"expiring-first",label:"Expiring first"},{value:"quota-asc",label:"% Quota: low to high"},{value:"quota-desc",label:"% Quota: high to low"}],className:"min-w-[175px]"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[e.jsxs("button",{onClick:d,title:"Turn off all accounts with depleted (0%) quota",className:"flex items-center gap-1.5 px-3 py-1.5 rounded-xl border border-red-500/20 bg-red-500/10 text-red-400 hover:bg-red-500/20 transition-colors cursor-pointer font-medium active:scale-95",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"block"}),"Turn off Empty"]}),e.jsxs("button",{onClick:y,title:"Turn on accounts with available (>0%) quota",className:"flex items-center gap-1.5 px-3 py-1.5 rounded-xl border border-emerald-500/20 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20 transition-colors cursor-pointer font-medium active:scale-95",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"check_circle"}),"Turn on Available"]}),e.jsxs("div",{className:"flex items-center gap-2 bg-[#0A0D14] border border-[#1E293B] px-3 py-1.5 rounded-xl select-none",children:[e.jsx(Y,{size:"sm",checked:f,onChange:x=>j(x),label:"Autorefresh"}),f&&e.jsxs("span",{className:"font-mono text-[10px] text-blue-400 font-semibold bg-blue-500/10 px-1.5 py-0.5 rounded border border-blue-500/20",children:[p,"s"]})]}),e.jsx("button",{onClick:i,disabled:b,title:"Refresh all quotas",className:"p-1.5 rounded-xl border border-[#1E293B] bg-[#0A0D14] text-slate-400 hover:text-white hover:border-slate-600 transition-colors cursor-pointer disabled:opacity-50",children:e.jsx("span",{className:`material-symbols-outlined text-[17px] ${b?"animate-spin text-blue-400":""}`,children:"refresh"})})]})]}),R=60,W="mapigate_cached_quota_accounts",_="mapigate_quota_sort_mode",pe=({searchQuery:s=""})=>{const[o,m]=h.useState(()=>{try{const a=localStorage.getItem(W);if(a){const r=JSON.parse(a);if(Array.isArray(r)&&r.length>0)return r}}catch{}return[]}),[u,l]=h.useState(()=>o.length===0),[g,v]=h.useState(!1),[f,j]=h.useState("all"),[p,b]=h.useState("all"),[i,d]=h.useState(()=>{try{const a=localStorage.getItem(_);if(a==="fixed"||a==="expiring-first"||a==="quota-asc"||a==="quota-desc")return a}catch{}return"fixed"}),[y,x]=h.useState(!0),[L,k]=h.useState(R),[C,I]=h.useState(null),[S,$]=h.useState(null),T=h.useCallback(async(a=!1)=>{try{a&&v(!0);const t=await fetch(a?"/api/quota?force=true":"/api/quota");if(!t.ok)throw new Error(`HTTP error ${t.status}`);const n=await t.json();m(n);try{localStorage.setItem(W,JSON.stringify(n))}catch{}}catch(r){console.error("[QuotaTab] Failed to fetch quotas:",r)}finally{l(!1),v(!1)}},[]);h.useEffect(()=>{T(!1).then(()=>{T(!0)})},[T]),h.useEffect(()=>{if(!y)return;const a=setInterval(()=>{document.hidden||k(r=>r<=1?(T(!1),R):r-1)},1e3);return()=>clearInterval(a)},[y,T]);const Q=async()=>{v(!0),k(R),await T(!0)},B=async a=>{try{const r=await fetch(`/api/quota/${a}`);if(!r.ok)throw new Error(`HTTP error ${r.status}`);const t=await r.json();m(n=>n.map(c=>c.accountId===a?{...c,...t,sortOrder:c.sortOrder??t.sortOrder,createdAt:c.createdAt??t.createdAt}:c))}catch(r){console.error(`[QuotaTab] Failed to refresh account ${a}:`,r)}},M=async(a,r)=>{m(t=>t.map(n=>n.accountId===a?{...n,isActive:r}:n));try{(await fetch(`/api/quota/accounts/${a}/toggle`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({isActive:r})})).ok||m(n=>n.map(c=>c.accountId===a?{...c,isActive:!r}:c))}catch{m(t=>t.map(n=>n.accountId===a?{...n,isActive:!r}:n))}},G=async a=>{if(!C)return;const r=await fetch(`/api/quota/accounts/${C.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!r.ok){const n=await r.json().catch(()=>({}));throw new Error(n.error||"Failed to update account.")}const{account:t}=await r.json();t?m(n=>n.map(c=>c.accountId===C.id?t:c)):await T(!0)},U=()=>{const a=o.filter(r=>r.isActive&&r.quotas.length>0&&r.quotas.some(t=>!t.unlimited&&t.remainingPercentage===0));if(a.length===0){alert("No active accounts with depleted (0%) quota found.");return}$({isOpen:!0,title:"Turn off Depleted Accounts",message:`Are you sure you want to turn off ${a.length} account(s) with 0% quota? This will prevent upstream 429 rate limit errors.`,variant:"danger",confirmText:`Turn off (${a.length})`,onConfirm:async()=>{const r=a.map(t=>t.accountId);m(t=>t.map(n=>r.includes(n.accountId)?{...n,isActive:!1}:n)),$(null);try{await fetch("/api/quota/toggle-batch",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({accountIds:r,isActive:!1})})}catch(t){console.error("[QuotaTab] Failed to turn off depleted accounts:",t)}}})},z=()=>{const a=o.filter(r=>!r.isActive&&r.quotas.length>0&&r.quotas.every(t=>t.unlimited||t.remainingPercentage>0));if(a.length===0){alert("No inactive accounts with available (>0%) quota found.");return}$({isOpen:!0,title:"Turn on Available Accounts",message:`Activate ${a.length} account(s) that have recovered capacity?`,variant:"emerald",confirmText:`Turn on (${a.length})`,onConfirm:async()=>{const r=a.map(t=>t.accountId);m(t=>t.map(n=>r.includes(n.accountId)?{...n,isActive:!0}:n)),$(null);try{await fetch("/api/quota/toggle-batch",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({accountIds:r,isActive:!0})})}catch(t){console.error("[QuotaTab] Failed to turn on available accounts:",t)}}})},H=h.useMemo(()=>{const a=new Set;return o.forEach(r=>{r.providerId&&a.add(r.providerId.toLowerCase())}),Array.from(a).sort()},[o]),O=h.useMemo(()=>{let a=[...o];if(f!=="all"&&(a=a.filter(r=>r.providerId.toLowerCase()===f.toLowerCase())),p==="active"?a=a.filter(r=>r.isActive):p==="inactive"&&(a=a.filter(r=>!r.isActive)),s.trim()){const r=s.toLowerCase().trim();a=a.filter(t=>t.accountName.toLowerCase().includes(r)||t.providerId.toLowerCase().includes(r)||t.accountId.toLowerCase().includes(r))}if(i==="fixed")a.sort((r,t)=>{const n=r.providerId.localeCompare(t.providerId);if(n!==0)return n;const c=(r.sortOrder??0)-(t.sortOrder??0);if(c!==0)return c;if(r.createdAt&&t.createdAt&&r.createdAt!==t.createdAt)return r.createdAt-t.createdAt;const N=r.accountName.localeCompare(t.accountName);return N!==0?N:r.accountId.localeCompare(t.accountId)});else if(i==="expiring-first"){const r=t=>{const n=t.quotas.map(c=>c.resetAt).filter(c=>typeof c=="number"&&c>0);return n.length>0?Math.min(...n):Number.POSITIVE_INFINITY};a.sort((t,n)=>{const c=r(t)-r(n);if(c!==0)return c;const N=t.providerId.localeCompare(n.providerId);if(N!==0)return N;const w=(t.sortOrder??0)-(n.sortOrder??0);if(w!==0)return w;if(t.createdAt&&n.createdAt&&t.createdAt!==n.createdAt)return t.createdAt-n.createdAt;const A=t.accountName.localeCompare(n.accountName);return A!==0?A:t.accountId.localeCompare(n.accountId)})}else if(i==="quota-asc"){const r=t=>t.quotas.length===0?Number.POSITIVE_INFINITY:Math.min(...t.quotas.map(n=>n.remainingPercentage));a.sort((t,n)=>{const c=r(t)-r(n);if(c!==0)return c;const N=t.providerId.localeCompare(n.providerId);if(N!==0)return N;const w=(t.sortOrder??0)-(n.sortOrder??0);if(w!==0)return w;if(t.createdAt&&n.createdAt&&t.createdAt!==n.createdAt)return t.createdAt-n.createdAt;const A=t.accountName.localeCompare(n.accountName);return A!==0?A:t.accountId.localeCompare(n.accountId)})}else if(i==="quota-desc"){const r=t=>t.quotas.length===0?Number.NEGATIVE_INFINITY:Math.max(...t.quotas.map(n=>n.remainingPercentage));a.sort((t,n)=>{const c=r(n)-r(t);if(c!==0)return c;const N=t.providerId.localeCompare(n.providerId);if(N!==0)return N;const w=(t.sortOrder??0)-(n.sortOrder??0);if(w!==0)return w;if(t.createdAt&&n.createdAt&&t.createdAt!==n.createdAt)return t.createdAt-n.createdAt;const A=t.accountName.localeCompare(n.accountName);return A!==0?A:t.accountId.localeCompare(n.accountId)})}return a},[o,f,p,i,s]),{accountsWithData:E,accountsWithoutData:q}=h.useMemo(()=>{const a=[],r=[];for(const t of O)Array.isArray(t.quotas)&&t.quotas.length>0||t.error?a.push(t):r.push(t);return{accountsWithData:a,accountsWithoutData:r}},[O]),J=a=>{d(a);try{localStorage.setItem(_,a)}catch{}};return e.jsxs("div",{className:"space-y-6 w-full px-2 sm:px-4 pb-16 animate-rt-fade-in",children:[e.jsx(ne,{providers:H,selectedProvider:f,onSelectProvider:j,statusFilter:p,onSelectStatusFilter:b,sortMode:i,onSelectSortMode:J,autoRefresh:y,onToggleAutoRefresh:x,countdownSeconds:L,isRefreshingAll:g,onRefreshAll:Q,onTurnOffEmpty:U,onTurnOnAvailable:z}),u?e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(400px,1fr))] gap-4 w-full",children:[...Array(6)].map((a,r)=>e.jsxs("div",{className:"bg-[#0F1420]/80 border border-[#1E293B] rounded-2xl p-5 space-y-4 animate-pulse shadow-lg",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 bg-slate-800 rounded-xl"}),e.jsxs("div",{className:"space-y-2 flex-1",children:[e.jsx("div",{className:"h-4 bg-slate-800 rounded w-1/2"}),e.jsx("div",{className:"h-3 bg-slate-800 rounded w-3/4"})]})]}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx("div",{className:"h-3 bg-slate-800 rounded w-full"}),e.jsx("div",{className:"h-2 bg-slate-800 rounded-full w-full"}),e.jsx("div",{className:"h-3 bg-slate-800 rounded w-5/6"}),e.jsx("div",{className:"h-2 bg-slate-800 rounded-full w-full"})]})]},r))}):O.length===0?e.jsxs("div",{className:"p-12 text-center rounded-2xl bg-[#0F1420]/50 border border-[#1E293B] text-slate-400 space-y-3",children:[e.jsx("span",{className:"material-symbols-outlined text-[36px] text-slate-500",children:"account_balance_wallet"}),e.jsx("div",{className:"text-sm font-medium text-slate-300",children:"No matching accounts found"}),e.jsx("p",{className:"text-xs text-slate-500 max-w-sm mx-auto",children:o.length===0?"Connect provider accounts in the Providers tab to track real-time quota.":"Try adjusting your provider, status, or search filters above."})]}):e.jsxs("div",{className:"space-y-8 w-full",children:[E.length>0&&e.jsxs("div",{className:"space-y-3",children:[q.length>0&&e.jsxs("div",{className:"flex items-center gap-2 text-xs font-semibold text-slate-300",children:[e.jsx("span",{className:"size-2 rounded-full bg-emerald-400"}),e.jsxs("span",{children:["Accounts With Quota (",E.length,")"]})]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(400px,1fr))] gap-4 w-full",children:E.map(a=>e.jsx(P,{account:a,onRefresh:B,onEdit:r=>I({id:r.accountId,providerId:r.providerId,name:r.accountName,isActive:r.isActive,providerSpecificData:r.providerSpecificData}),onToggle:M},a.accountId))})]}),q.length>0&&e.jsxs("div",{className:`space-y-3 ${E.length>0?"pt-6 border-t border-[#1E293B]/70":""}`,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 pb-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs font-semibold text-slate-400",children:[e.jsx("span",{className:"size-2 rounded-full bg-slate-500"}),e.jsxs("span",{children:["Accounts Without Quota Data (",q.length,")"]})]}),e.jsx("span",{className:"text-[11px] text-slate-500 font-mono",children:"No active quota or unsupported metrics"})]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(400px,1fr))] gap-4 w-full",children:q.map(a=>e.jsx(P,{account:a,onRefresh:B,onEdit:r=>I({id:r.accountId,providerId:r.providerId,name:r.accountName,isActive:r.isActive,providerSpecificData:r.providerSpecificData}),onToggle:M},a.accountId))})]})]}),e.jsx(K,{isOpen:!!C,account:C,onClose:()=>I(null),onSave:G}),S&&e.jsx(X,{isOpen:S.isOpen,title:S.title,message:S.message,variant:S.variant,confirmText:S.confirmText,onConfirm:S.onConfirm,onCancel:()=>$(null)})]})};export{pe as QuotaTab};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as t,j as e}from"./vendor-BcOI2aZ9.js";import{f as q,P as _,A as F,D as z,R as L}from"./index-Di7mCTbW.js";import{G as U}from"./lucide-Cc35htxl.js";const G=({mode:a,onClose:j,onSuccess:r})=>{const[u,v]=t.useState(""),[d,A]=t.useState(""),[k,m]=t.useState(""),[y,D]=t.useState(!1),[b,x]=t.useState(!1),[h,p]=t.useState(!1),[g,i]=t.useState(null),l=q(c=>c.checkAuth);if(!a)return null;const f=()=>{v(""),A(""),m(""),D(!1),x(!1),i(null),p(!1)},S=()=>{h||(f(),j())},M=async c=>{if(c.preventDefault(),i(null),a==="setup"||a==="change"){if(!d||d.length<4){i("New password must be at least 4 characters long");return}if(d!==k){i("Passwords do not match");return}}if((a==="change"||a==="remove")&&!u){i("Current password is required");return}p(!0);try{if(a==="setup"){const o=await F.setup(d);if(!o.success){i(o.error||"Failed to setup master password"),p(!1);return}}else if(a==="change"){const o=await F.changePassword(u,d);if(!o.success){i(o.error||"Failed to change master password"),p(!1);return}}else if(a==="remove"){const o=await F.removePassword(u);if(!o.success){i(o.error||"Failed to remove master password"),p(!1);return}}await l(),f(),j(),r==null||r()}catch(o){i(o.message||"An unexpected error occurred"),p(!1)}};return e.jsx(_,{isOpen:!!a,onClose:S,maxWidthClass:"max-w-md",children:e.jsxs("form",{onSubmit:M,className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`size-10 rounded-xl flex items-center justify-center shrink-0 border ${a==="remove"?"bg-rose-500/10 border-rose-500/30 text-rose-400":"bg-blue-500/10 border-blue-500/30 text-blue-400"}`,children:e.jsx("span",{className:"material-symbols-outlined text-[22px]",children:a==="remove"?"lock_open":a==="change"?"key":"lock"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:a==="setup"?"Set Master Password":a==="change"?"Change Master Password":"Remove Master Password"}),e.jsx("p",{className:"text-xs text-slate-400",children:a==="setup"?"Protect Mapigate dashboard and management APIs":a==="change"?"Update your existing dashboard password":"Disable authentication requirement"})]})]}),a==="remove"?e.jsxs("div",{className:"p-3 rounded-xl bg-rose-500/10 border border-rose-500/20 text-xs text-rose-300 leading-relaxed space-y-1",children:[e.jsx("p",{className:"font-semibold",children:"Warning: Disabling Master Password"}),e.jsx("p",{className:"text-[11px] text-rose-200/80",children:"Anyone with access to this machine or network will be able to view and manage your AI providers, API keys, and configurations without logging in."})]}):e.jsx("div",{className:"p-3 rounded-xl bg-[#0A0D14] border border-[#1E293B] text-xs text-slate-300 leading-relaxed space-y-1",children:e.jsxs("p",{className:"text-slate-400 text-[11px]",children:["AI coding assistant proxy routes (",e.jsx("code",{className:"text-blue-400 font-mono",children:"/v1/*"}),") remain completely untouched and unauthenticated. Only web dashboard management is protected."]})}),e.jsxs("div",{className:"space-y-3 pt-1",children:[(a==="change"||a==="remove")&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[11px] font-semibold text-slate-300",children:"Current Master Password"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:y?"text":"password",value:u,onChange:c=>{v(c.target.value),g&&i(null)},placeholder:"Enter current password...",required:!0,className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white placeholder-slate-500 focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500/30 transition-all font-mono"}),e.jsx("button",{type:"button",onClick:()=>D(!y),tabIndex:-1,className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-500 hover:text-slate-300 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:y?"visibility_off":"visibility"})})]})]}),(a==="setup"||a==="change")&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[11px] font-semibold text-slate-300",children:a==="setup"?"Master Password":"New Master Password"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:b?"text":"password",value:d,onChange:c=>{A(c.target.value),g&&i(null)},placeholder:"At least 4 characters...",required:!0,minLength:4,className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white placeholder-slate-500 focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500/30 transition-all font-mono"}),e.jsx("button",{type:"button",onClick:()=>x(!b),tabIndex:-1,className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-500 hover:text-slate-300 transition-colors cursor-pointer",children:e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:b?"visibility_off":"visibility"})})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"text-[11px] font-semibold text-slate-300",children:["Confirm ",a==="setup"?"Password":"New Password"]}),e.jsx("input",{type:b?"text":"password",value:k,onChange:c=>{m(c.target.value),g&&i(null)},placeholder:"Re-enter password...",required:!0,className:"w-full bg-[#0A0D14] border border-[#1E293B] rounded-xl px-3 py-2 text-xs text-white placeholder-slate-500 focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500/30 transition-all font-mono"})]})]})]}),g&&e.jsxs("div",{className:"p-2.5 rounded-lg bg-rose-500/10 border border-rose-500/30 text-xs text-rose-300 flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[15px] shrink-0 text-rose-400",children:"error"}),e.jsx("span",{children:g})]}),e.jsxs("div",{className:"flex items-center justify-end gap-3 pt-2",children:[e.jsx("button",{type:"button",onClick:S,disabled:h,className:"rt-btn rt-btn--secondary text-xs py-2 px-4 cursor-pointer",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:h,className:`text-xs py-2 px-4 flex items-center gap-1.5 cursor-pointer font-semibold rounded-xl ${a==="remove"?"rt-btn rt-btn--danger":"rt-btn rt-btn--primary"}`,children:h?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[15px] animate-spin",children:"progress_activity"}),"Processing..."]}):a==="setup"?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"lock"}),"Set Password"]}):a==="change"?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"check"}),"Save Changes"]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[15px]",children:"lock_open"}),"Remove Protection"]})})]})]})})},$=()=>{const[a,j]=t.useState(!1),[r,u]=t.useState(!1),[v,d]=t.useState(!1),[A,k]=t.useState(""),[m,y]=t.useState(!1),[D,b]=t.useState(null),[x,h]=t.useState(null),[p,g]=t.useState(""),[i,l]=t.useState("merge"),[f,S]=t.useState(!1),[M,c]=t.useState(null),[o,R]=t.useState(null),B=t.useRef(null),I=async()=>{y(!0),b(null);try{const n=await fetch("/api/settings/backup/export",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({includeCredentials:v,password:A.trim()||void 0})});if(!n.ok){const T=await n.json().catch(()=>({}));throw new Error(T.error||"Failed to generate backup")}const N=await n.json(),w=`mapigate-backup-${new Date().toISOString().split("T")[0]}.json`,s=new Blob([JSON.stringify(N,null,2)],{type:"application/json"}),E=URL.createObjectURL(s),P=document.createElement("a");P.href=E,P.download=w,document.body.appendChild(P),P.click(),document.body.removeChild(P),URL.revokeObjectURL(E),j(!1),k("")}catch(n){b(n.message||"Export failed")}finally{y(!1)}},O=async()=>{if(x){S(!0),c(null),R(null);try{const n=await x.text();let N;try{N=JSON.parse(n)}catch{throw new Error("Selected file is not valid JSON.")}const C=await fetch("/api/settings/backup/import",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({backup:N,password:p.trim()||void 0,mode:i})}),w=await C.json();if(!C.ok)throw new Error(w.error||"Failed to restore backup");R(`Restored ${w.restored.providersCount} providers, ${w.restored.accountsCount} accounts, ${w.restored.combosCount} combos, and ${w.restored.mappingsCount} model mappings!`),h(null),g(""),setTimeout(()=>{u(!1),R(null),window.location.reload()},2e3)}catch(n){c(n.message||"Import failed")}finally{S(!1)}}};return e.jsxs("div",{className:"rt-card p-6 space-y-4 border border-[#1E293B]",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("div",{className:"size-9 rounded-xl bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"settings_backup_restore"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-white",children:"Configuration Backup & Migration"}),e.jsx("p",{className:"text-xs text-slate-400",children:"Export providers, combos, and model mappings to JSON or migrate to another machine"})]})]}),e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsxs("button",{type:"button",onClick:()=>{b(null),j(!0)},className:"rt-btn rt-btn--secondary text-xs py-2 px-4 flex items-center gap-2 cursor-pointer font-semibold",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"file_download"}),"Export Backup"]}),e.jsxs("button",{type:"button",onClick:()=>{c(null),R(null),u(!0)},className:"rt-btn rt-btn--primary text-xs py-2 px-4 flex items-center gap-2 cursor-pointer font-semibold",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"file_upload"}),"Import Backup"]})]})]}),e.jsx("p",{className:"text-xs text-slate-400 leading-relaxed",children:"Backups include all your custom providers, multi-model combos, global model aliases, per-tool mappings, and engine preferences. If credentials are included, they are safely encrypted with your password using AES-256-GCM."}),e.jsx(_,{isOpen:a,onClose:()=>!m&&j(!1),maxWidthClass:"max-w-xl",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 rounded-xl bg-emerald-500/15 border border-emerald-500/30 text-emerald-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[24px]",children:"file_download"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Export Configuration Backup"}),e.jsx("p",{className:"text-xs text-slate-400",children:"Generate a portable JSON backup file"})]})]}),e.jsxs("div",{className:"space-y-3 pt-1",children:[e.jsxs("label",{className:"flex items-start gap-2.5 cursor-pointer bg-[#0A0D14] p-3 rounded-xl border border-[#1E293B]",children:[e.jsx("input",{type:"checkbox",checked:v,onChange:n=>d(n.target.checked),className:"mt-0.5 rounded border-slate-700 text-blue-600 focus:ring-0 cursor-pointer"}),e.jsxs("div",{className:"text-xs space-y-0.5",children:[e.jsx("span",{className:"font-semibold text-white block",children:"Include API Keys & Secrets"}),e.jsx("span",{className:"text-slate-400 text-[11px] block",children:"If unchecked, a zero-secrets template will be exported (safe for public sharing or team presets)."})]})]}),v&&e.jsxs("div",{className:"space-y-1.5 animate-rt-fade-in",children:[e.jsx("label",{className:"text-xs font-semibold text-slate-300 block",children:"Encryption Password (Recommended)"}),e.jsx("input",{type:"password",value:A,onChange:n=>k(n.target.value),placeholder:"Enter a password to encrypt credentials",className:"rt-input w-full text-xs py-2 px-3"}),e.jsx("span",{className:"text-[11px] text-slate-500 block",children:"If set, API keys will be encrypted via AES-256-GCM and will require this password when importing."})]}),D&&e.jsx("div",{className:"p-3 rounded-lg bg-rose-500/10 border border-rose-500/30 text-xs text-rose-300",children:D})]}),e.jsxs("div",{className:"flex items-center justify-end gap-3 pt-2",children:[e.jsx("button",{onClick:()=>j(!1),disabled:m,className:"rt-btn rt-btn--secondary text-xs py-2 px-4",children:"Cancel"}),e.jsx("button",{onClick:I,disabled:m,className:"rt-btn rt-btn--primary text-xs py-2 px-4 flex items-center gap-1.5",children:m?"Generating...":"Download JSON"})]})]})}),e.jsx(_,{isOpen:r,onClose:()=>!f&&u(!1),maxWidthClass:"max-w-xl",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 rounded-xl bg-blue-500/15 border border-blue-500/30 text-blue-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[24px]",children:"file_upload"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Import Configuration Backup"}),e.jsx("p",{className:"text-xs text-slate-400",children:"Restore or migrate settings from a JSON file"})]})]}),e.jsxs("div",{className:"space-y-3 pt-1",children:[e.jsxs("div",{onClick:()=>{var n;return(n=B.current)==null?void 0:n.click()},className:"border-2 border-dashed border-[#1E293B] hover:border-blue-500/50 p-4 rounded-xl text-center cursor-pointer bg-[#0A0D14] space-y-1 transition-colors",children:[e.jsx("input",{ref:B,type:"file",accept:".json",className:"hidden",onChange:n=>{var C;const N=(C=n.target.files)==null?void 0:C[0];N&&h(N)}}),e.jsx("span",{className:"material-symbols-outlined text-[28px] text-blue-400",children:"upload_file"}),e.jsx("p",{className:"text-xs font-semibold text-white",children:x?x.name:"Click to select backup .json file"}),e.jsx("p",{className:"text-[11px] text-slate-500",children:x?`${(x.size/1024).toFixed(1)} KB`:"Supports any Mapigate backup export"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold text-slate-300 block",children:"Decryption Password (If Encrypted)"}),e.jsx("input",{type:"password",value:p,onChange:n=>g(n.target.value),placeholder:"Enter password if backup was encrypted",className:"rt-input w-full text-xs py-2 px-3"})]}),e.jsxs("div",{className:"flex items-center justify-between bg-[#0A0D14] p-3 rounded-xl border border-[#1E293B] text-xs",children:[e.jsx("span",{className:"text-slate-400",children:"Import Mode"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("label",{className:"flex items-center gap-1.5 cursor-pointer text-slate-300",children:[e.jsx("input",{type:"radio",name:"importMode",value:"merge",checked:i==="merge",onChange:()=>l("merge"),className:"text-blue-600 focus:ring-0"}),"Merge"]}),e.jsxs("label",{className:"flex items-center gap-1.5 cursor-pointer text-slate-300",children:[e.jsx("input",{type:"radio",name:"importMode",value:"overwrite",checked:i==="overwrite",onChange:()=>l("overwrite"),className:"text-blue-600 focus:ring-0"}),"Overwrite"]})]})]}),M&&e.jsx("div",{className:"p-3 rounded-lg bg-rose-500/10 border border-rose-500/30 text-xs text-rose-300",children:M}),o&&e.jsxs("div",{className:"p-3 rounded-lg bg-emerald-500/10 border border-emerald-500/30 text-xs text-emerald-300 flex items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"check_circle"}),e.jsx("span",{children:o})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-3 pt-2",children:[e.jsx("button",{onClick:()=>u(!1),disabled:f,className:"rt-btn rt-btn--secondary text-xs py-2 px-4",children:"Cancel"}),e.jsx("button",{onClick:O,disabled:f||!x,className:"rt-btn rt-btn--primary text-xs py-2 px-4 flex items-center gap-1.5",children:f?"Restoring...":"Restore Configuration"})]})]})})]})},V=({onRestartClick:a,onUpgradeClick:j})=>{const[r,u]=t.useState(null),[v,d]=t.useState(!1),[A,k]=t.useState(!1),[m,y]=t.useState(!1),[D,b]=t.useState(!1),[x,h]=t.useState(null),p=q(s=>s.isPasswordSet),[g,i]=t.useState(null),[l,f]=t.useState(null),[S,M]=t.useState(!1),[c,o]=t.useState(10),[R,B]=t.useState(!1),[I,O]=t.useState(!1),n=a||(()=>k(!0));t.useEffect(()=>{fetch("/api/settings/system-info").then(s=>s.json()).then(s=>{s&&(s.dbPath||s.dataDir)&&u(s)}).catch(()=>{}),fetch("/api/settings/autostart").then(s=>s.json()).then(s=>{s&&typeof s.enabled=="boolean"&&f(s)}).catch(()=>{}),fetch("/api/settings/logging").then(s=>s.json()).then(s=>{s&&typeof s.logRetentionDays=="number"&&o(s.logRetentionDays)}).catch(()=>{})},[]);const N=async()=>{if(!l||S)return;const s=!l.enabled;M(!0);try{const E=await fetch("/api/settings/autostart",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:s})});if(E.ok){const P=await E.json();f(T=>T?{...T,enabled:P.enabled}:P)}}catch{}finally{M(!1)}},C=async s=>{o(s),B(!0),O(!1);try{(await fetch("/api/settings/logging",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({logRetentionDays:s})})).ok&&(O(!0),setTimeout(()=>O(!1),2e3))}catch{}finally{B(!1)}},w=async()=>{y(!0),h(null);try{const s=await fetch("/api/server/shutdown",{method:"POST",headers:{"Content-Type":"application/json"}});if(s.ok)b(!0),d(!1);else{const E=await s.json().catch(()=>({}));h(E.error||"Failed to initiate server shutdown."),y(!1)}}catch{b(!0),d(!1)}};return D?e.jsx("div",{className:"w-full px-2 sm:px-4 py-8 animate-rt-fade-in",children:e.jsxs("div",{className:"max-w-xl mx-auto rt-card p-8 text-center space-y-4 border border-rose-500/20 bg-[#0F1420]",children:[e.jsx("div",{className:"size-14 mx-auto rounded-2xl bg-rose-500/10 border border-rose-500/30 text-rose-400 flex items-center justify-center",children:e.jsx("span",{className:"material-symbols-outlined text-[32px]",children:"power_off"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{className:"text-lg font-bold text-white",children:"Mapigate Gateway Server Stopped"}),e.jsx("p",{className:"text-xs text-slate-400",children:"The local server has shut down and will no longer accept proxy requests."})]}),e.jsxs("div",{className:"bg-[#0A0D14] p-3 rounded-xl border border-[#1E293B] text-xs font-mono text-slate-300",children:["To restart, run in terminal: ",e.jsx("code",{className:"text-blue-400",children:"mpg"})," or ",e.jsx("code",{className:"text-blue-400",children:"mapigate start"})]}),e.jsx("p",{className:"text-[11px] text-slate-500",children:"You may now safely close this browser tab."})]})}):e.jsxs("div",{className:"w-full px-2 sm:px-4 space-y-6 animate-rt-fade-in pb-16",children:[e.jsxs("div",{className:"rt-card p-6 space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3 pb-3 border-b border-[#1E293B]",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-400 text-[22px]",children:"tune"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-white",children:"System & Storage Preferences"}),e.jsx("p",{className:"text-xs text-slate-400",children:"Local SQLite database and hardware encryption status"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 text-xs",children:[e.jsxs("div",{className:"bg-[#0A0D14] p-4 rounded-xl border border-[#1E293B] space-y-1",children:[e.jsx("span",{className:"text-slate-500 uppercase text-[10px] font-bold",children:"App Version & Gateway"}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("p",{className:"text-white font-mono font-semibold",children:["Mapigate v",(r==null?void 0:r.version)||"0.3.3"]}),(r==null?void 0:r.hasUpdate)&&r.latestVersion&&e.jsxs("button",{type:"button",onClick:j,className:"inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-md bg-amber-500/15 text-amber-300 border border-amber-500/35 font-mono font-semibold hover:bg-amber-500/25 transition-all cursor-pointer",title:`Upgrade to v${r.latestVersion}`,children:[e.jsxs("span",{children:["v",r.latestVersion]}),e.jsx("span",{className:"text-[9px] text-amber-400",children:"↑ Upgrade"})]})]}),e.jsxs("p",{className:"text-blue-400 font-mono text-[11px]",children:["Active on port ",(r==null?void 0:r.port)||z]})]}),e.jsxs("div",{className:"bg-[#0A0D14] p-4 rounded-xl border border-[#1E293B] space-y-1",children:[e.jsx("span",{className:"text-slate-500 uppercase text-[10px] font-bold",children:"Storage Engine"}),e.jsx("p",{className:"text-white font-mono font-semibold",children:"SQLite WAL (node:sqlite)"}),e.jsx("p",{className:"text-slate-400 text-[11px]",children:"Concurrent read/write without locks"})]}),e.jsxs("div",{className:"bg-[#0A0D14] p-4 rounded-xl border border-[#1E293B] space-y-1",children:[e.jsx("span",{className:"text-slate-500 uppercase text-[10px] font-bold",children:"Credential Vault"}),e.jsx("p",{className:"text-emerald-400 font-mono font-semibold",children:"AES-256-GCM Hardware-salted"}),e.jsx("p",{className:"text-slate-400 text-[11px]",children:"Tied to this machine ID"})]}),e.jsxs("div",{className:"bg-[#0A0D14] p-4 rounded-xl border border-[#1E293B] space-y-1 flex flex-col justify-between",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-500 uppercase text-[10px] font-bold",children:"Open Source"}),e.jsx("p",{className:"text-white font-mono font-semibold",children:"GitHub Repository"})]}),e.jsxs("a",{href:"https://github.com/joutvhu/mapigate",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 text-blue-400 hover:text-blue-300 text-[11px] font-medium hover:underline pt-1",children:[e.jsx(U,{className:"size-3.5"}),e.jsx("span",{children:"joutvhu/mapigate"}),e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"open_in_new"})]})]})]}),e.jsxs("div",{className:"bg-[#0A0D14] p-4 rounded-xl border border-[#1E293B] text-xs font-mono text-slate-300 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-slate-500 uppercase text-[10px] font-bold block font-sans",children:"Local Data Directory:"}),(r==null?void 0:r.isDevelopmentMode)&&e.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded bg-amber-500/10 border border-amber-500/30 text-amber-400 font-sans font-medium",children:"Development Mode (.mapigate local)"})]}),e.jsx("code",{className:"text-blue-400 block bg-[#0F1420] p-2.5 rounded-lg border border-[#1E293B] break-all select-all",children:(r==null?void 0:r.dbPath)||(r==null?void 0:r.dataDir)||"~/.mapigate/mapigate.sqlite"})]})]}),e.jsxs("div",{className:"rt-card p-6 space-y-4 border border-[#1E293B]",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("div",{className:"size-9 rounded-xl bg-purple-500/10 border border-purple-500/20 text-purple-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"rocket_launch"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-white",children:"System Startup (Autostart on Boot)"}),e.jsx("p",{className:"text-xs text-slate-400",children:"Launch Mapigate gateway automatically in the background on computer boot"})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{type:"button",onClick:N,disabled:S||!l,className:`relative inline-flex h-6 w-11 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none ${l!=null&&l.enabled?"bg-blue-600":"bg-slate-700"}`,title:l!=null&&l.enabled?"Click to disable autostart":"Click to enable autostart",children:e.jsx("span",{className:`pointer-events-none inline-block size-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out ${l!=null&&l.enabled?"translate-x-5":"translate-x-0"}`})}),e.jsx("span",{className:`text-xs font-semibold ${l!=null&&l.enabled?"text-emerald-400":"text-slate-400"}`,children:l!=null&&l.enabled?"Enabled":"Disabled"})]})]}),e.jsxs("div",{className:"space-y-2 text-xs text-slate-400 leading-relaxed",children:[e.jsx("p",{children:"When enabled, Mapigate will automatically start as a silent background daemon with system tray icon whenever you log in to this computer. Coding assistants (Claude Code, Cursor, Cline, Copilot) can access AI endpoints without having to manually start the gateway."}),(l==null?void 0:l.targetPath)&&e.jsxs("div",{className:"bg-[#0A0D14] p-3 rounded-xl border border-[#1E293B] text-slate-300 font-mono text-[11px] flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"text-slate-500 uppercase text-[10px] font-bold font-sans shrink-0",children:["Startup Target (",l.platform,"):"]}),e.jsx("code",{className:"text-blue-400 truncate select-all",children:l.targetPath})]})]})]}),e.jsxs("div",{className:"rt-card p-6 space-y-4 border border-blue-500/20",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("div",{className:"size-9 rounded-xl bg-blue-500/10 border border-blue-500/20 text-blue-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"lock"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-white",children:"Master Password Protection"}),e.jsx("p",{className:"text-xs text-slate-400",children:"Lock the Web Dashboard and guard management REST APIs"})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:p?e.jsxs("span",{className:"px-2.5 py-1 rounded-full text-[11px] font-semibold bg-emerald-500/10 text-emerald-400 border border-emerald-500/20 flex items-center gap-1.5",children:[e.jsx("span",{className:"size-1.5 rounded-full bg-emerald-400 animate-pulse"}),"Protected"]}):e.jsx("span",{className:"px-2.5 py-1 rounded-full text-[11px] font-semibold bg-slate-500/10 text-slate-400 border border-slate-500/20 flex items-center gap-1.5",children:"Disabled (No Auth Required)"})})]}),e.jsx("p",{className:"text-xs text-slate-400 leading-relaxed",children:p?"Master Password protection is active. Accessing the Mapigate dashboard requires entering your password. AI coding assistant proxy endpoints (/v1/*) remain 100% unauthenticated and fast.":"By default, Mapigate requires no login. Set a master password if you want to protect your dashboard settings, provider credentials, and management APIs from unauthorized access."}),e.jsx("div",{className:"flex flex-wrap items-center gap-3 pt-1",children:p?e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>i("change"),className:"rt-btn rt-btn--secondary text-xs py-2 px-4 flex items-center gap-2 cursor-pointer font-semibold",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"key"}),"Change Password"]}),e.jsxs("button",{type:"button",onClick:()=>i("remove"),className:"rt-btn rt-btn--danger text-xs py-2 px-4 flex items-center gap-2 cursor-pointer font-semibold",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"lock_open"}),"Remove Password"]})]}):e.jsxs("button",{type:"button",onClick:()=>i("setup"),className:"rt-btn rt-btn--primary text-xs py-2 px-4 flex items-center gap-2 cursor-pointer font-semibold",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"lock"}),"Set Master Password"]})})]}),e.jsx($,{}),e.jsxs("div",{className:"rt-card p-6 space-y-4 border border-[#1E293B]",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("div",{className:"size-9 rounded-xl bg-amber-500/10 border border-amber-500/20 text-amber-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"database"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-white",children:"Usage & Request Log Retention"}),e.jsx("p",{className:"text-xs text-slate-400",children:"Configure how long detailed request payloads and debug logs are kept"})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:I&&e.jsxs("span",{className:"text-[11px] font-semibold text-emerald-400 animate-rt-fade-in flex items-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"check_circle"}),"Saved"]})})]}),e.jsxs("div",{className:"space-y-3 text-xs text-slate-400 leading-relaxed",children:[e.jsx("p",{children:"Mapigate stores data in 3 tiers to maximize performance and prevent SQLite database bloat:"}),e.jsxs("ul",{className:"list-disc pl-5 space-y-1 text-slate-400 text-[11px]",children:[e.jsxs("li",{children:[e.jsx("strong",{className:"text-white",children:"Tier 1 (Detailed Request Payloads):"})," Kept according to the retention window below for debugging and inspection."]}),e.jsxs("li",{children:[e.jsx("strong",{className:"text-white",children:"Tier 2 (Daily Usage Analytics):"})," Compact daily rollups by model, provider, account, and API key kept for 365+ days."]}),e.jsxs("li",{children:[e.jsx("strong",{className:"text-white",children:"Tier 3 (All-Time Totals):"})," Total tokens saved, aggregate request counts, and cost metrics kept permanently."]})]}),e.jsxs("div",{className:"pt-2",children:[e.jsx("label",{className:"text-slate-300 font-semibold block text-xs mb-2",children:"Detailed Request Log Retention Period:"}),e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:[{label:"7 Days",value:7},{label:"10 Days (Default)",value:10},{label:"30 Days",value:30},{label:"90 Days",value:90},{label:"Keep All (No Auto-Prune)",value:0}].map(s=>e.jsx("button",{type:"button",disabled:R,onClick:()=>C(s.value),className:`px-3 py-1.5 rounded-lg text-xs font-semibold transition-all cursor-pointer ${c===s.value?"bg-blue-600 text-white shadow-xs border border-blue-500":"bg-[#0A0D14] border border-[#1E293B] text-slate-400 hover:text-white hover:bg-slate-800"}`,children:s.label},s.value))})]})]})]}),e.jsxs("div",{className:"rt-card p-6 space-y-4 border border-[#1E293B]",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("div",{className:"size-9 rounded-xl bg-blue-500/10 border border-blue-500/20 text-blue-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"power_settings_new"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold text-white",children:"Gateway Server Control"}),e.jsx("p",{className:"text-xs text-slate-400",children:"Manage running server lifecycle, hot restart, and daemon"})]})]}),e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsxs("button",{type:"button",onClick:n,className:"rt-btn rt-btn--primary text-xs py-2 px-4 flex items-center gap-2 font-semibold cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"restart_alt"}),"Restart Gateway"]}),e.jsxs("button",{type:"button",onClick:()=>d(!0),className:"rt-btn rt-btn--danger text-xs py-2 px-4 flex items-center gap-2 cursor-pointer",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"power_settings_new"}),"Shutdown Server"]})]})]}),e.jsxs("p",{className:"text-xs text-slate-400 leading-relaxed",children:["Restarting the gateway applies any newly installed updates, re-initializes provider modules, and clears active sockets without needing to run terminal commands. Shutting down the server stops all active proxy routing, terminates the background process, and releases port ",(r==null?void 0:r.port)||z,"."]}),x&&e.jsx("div",{className:"p-3 rounded-lg bg-rose-500/10 border border-rose-500/30 text-xs text-rose-300",children:x})]}),e.jsx(_,{isOpen:v,onClose:()=>!m&&d(!1),maxWidthClass:"max-w-md",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-10 rounded-xl bg-rose-500/15 border border-rose-500/30 text-rose-400 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"material-symbols-outlined text-[24px]",children:"warning"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Shutdown Mapigate Gateway?"}),e.jsx("p",{className:"text-xs text-slate-400",children:"This will terminate the server process."})]})]}),e.jsxs("div",{className:"p-3.5 rounded-xl bg-[#0A0D14] border border-[#1E293B] text-xs text-slate-300 space-y-2 leading-relaxed",children:[e.jsx("p",{children:"Are you sure you want to shut down the server? Active connections from coding assistants (Claude Code, Cursor, Kiro, etc.) will be disconnected immediately."}),e.jsxs("p",{className:"text-slate-400 text-[11px]",children:["To restart later, run ",e.jsx("span",{className:"text-blue-400 font-mono",children:"mapigate"})," in your terminal."]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-3 pt-2",children:[e.jsx("button",{onClick:()=>d(!1),disabled:m,className:"rt-btn rt-btn--secondary text-xs py-2 px-4",children:"Cancel"}),e.jsx("button",{onClick:w,disabled:m,className:"rt-btn rt-btn--danger text-xs py-2 px-4 flex items-center gap-1.5",children:m?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"animate-spin text-[14px]",children:"⠋"}),"Shutting Down..."]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"power_settings_new"}),"Confirm Shutdown"]})})]})]})}),e.jsx(G,{mode:g,onClose:()=>i(null)}),!a&&e.jsx(L,{isOpen:A,onClose:()=>k(!1)})]})};export{V as SettingsTab};
|