module.exports=[951615,(e,t,r)=>{t.exports=e.x("node:buffer",()=>require("node:buffer"))},912714,(e,t,r)=>{t.exports=e.x("node:fs/promises",()=>require("node:fs/promises"))},812057,(e,t,r)=>{t.exports=e.x("node:util",()=>require("node:util"))},857764,(e,t,r)=>{t.exports=e.x("node:url",()=>require("node:url"))},574207,e=>{"use strict";var t=e.i(254799);function r(e=32){return t.default.randomBytes(e).toString("base64url")}function s(e){return t.default.createHash("sha256").update(e).digest("base64url")}function n(){return t.default.randomBytes(32).toString("base64url")}e.s(["generateCodeChallenge",0,s,"generateCodeVerifier",0,r,"generatePKCE",0,function(e=32){let t=r(e),o=s(t);return{codeVerifier:t,codeChallenge:o,state:n()}},"generateState",0,n])},472385,e=>{"use strict";let t="https://auth.x.ai",r="/oauth2/authorize",s="/oauth2/token",n="/.well-known/openid-configuration",o="/callback",a={clientId:"b1a00492-073a-47ea-816f-4c329264a828",issuer:t,authEndpointPath:r,tokenEndpointPath:s,discoveryPath:n,authorizeUrl:`${t}${r}`,tokenUrl:`${t}${s}`,discoveryUrl:`${t}${n}`,scope:"openid profile email offline_access grok-cli:access api:access",apiBaseUrl:"https://api.x.ai/v1",redirectUri:`http://127.0.0.1:56121${o}`,loopbackPort:56121,callbackPath:o,pkceVerifierBytes:96,refreshLeadSeconds:300,userAgent:"grok-cli/9router",codeChallengeMethod:"S256"};e.s(["XAI_CONFIG",0,a,"XAI_PKCE_VERIFIER_BYTES",0,96])},874533,(e,t,r)=>{t.exports=e.x("node:child_process",()=>require("node:child_process"))},660526,(e,t,r)=>{t.exports=e.x("node:os",()=>require("node:os"))},792509,(e,t,r)=>{t.exports=e.x("url",()=>require("url"))},921517,(e,t,r)=>{t.exports=e.x("http",()=>require("http"))},481474,e=>{"use strict";var t=e.i(921517),r=e.i(792509);let s=null,n=null,o=new Map;function a(e,t){let r=e?"Authentication Successful":"Authentication Failed";return`<!DOCTYPE html>
<html><head><meta charset="utf-8"><title>${r}</title>
<style>body{font-family:system-ui;display:flex;justify-content:center;align-items:center;height:100vh;margin:0;background:#f5f5f5}.c{text-align:center;padding:2rem;background:#fff;border-radius:8px;box-shadow:0 2px 10px rgba(0,0,0,.1)}.i{color:${e?"#22c55e":"#ef4444"};font-size:3rem}h1{margin:1rem 0}p{color:#666}</style>
</head><body><div class="c"><div class="i">${e?"&#10003;":"&#10007;"}</div><h1>${r}</h1><p>${t}</p><p>Closing in <span id="cd">3</span>s...</p>
<script>let n=3;const c=document.getElementById("cd");const t=setInterval(()=>{n--;c.textContent=n;if(n<=0){clearInterval(t);window.close();}},1000);</script>
</div></body></html>`}function i(){n&&(clearTimeout(n),n=null),s&&(s.close(),s=null)}let c=null,l=null,u=new Map;function d(){l&&(clearTimeout(l),l=null),c&&(c.close(),c=null)}e.s(["clearCodexSession",0,function(e){o.delete(e)},"clearXaiSession",0,function(e){u.delete(e)},"getCodexSessionStatus",0,function(e){return o.get(e)||null},"getXaiSessionStatus",0,function(e){return u.get(e)||null},"registerCodexSession",0,function({state:e,codeVerifier:t,redirectUri:r}){return!!e&&!!t&&!!r&&(o.set(e,{codeVerifier:t,redirectUri:r,status:"pending",createdAt:Date.now()}),!0)},"registerXaiSession",0,function({state:e,codeVerifier:t,redirectUri:r}){return!!e&&!!t&&!!r&&(u.set(e,{codeVerifier:t,redirectUri:r,status:"pending",createdAt:Date.now()}),!0)},"startCodexProxy",0,function(c){return new Promise(l=>{if(s)return void l({success:!0});let u=t.default.createServer(async(t,s)=>{let n=new r.URL(t.url,"http://localhost");if("/callback"!==n.pathname&&"/auth/callback"!==n.pathname){s.writeHead(404),s.end("Not found");return}let l=n.searchParams.get("code"),u=n.searchParams.get("state"),d=n.searchParams.get("error"),h=u?o.get(u):null;if(h){try{if(d)throw Error(n.searchParams.get("error_description")||d);if(!l)throw Error("No authorization code received");let{exchangeTokens:t}=await e.A(633998),{createProviderConnection:r}=await e.A(52307),o=await t("codex",l,h.redirectUri,h.codeVerifier,u),i=await r({provider:"codex",authType:"oauth",...o,expiresAt:o.expiresIn?new Date(Date.now()+1e3*o.expiresIn).toISOString():null,testStatus:"active"});h.status="done",h.connectionId=i.id,h.email=i.email,s.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),s.end(a(!0,"You can close this window."))}catch(e){h.status="error",h.error=e.message,s.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),s.end(a(!1,e.message))}finally{i()}return}let p=`http://localhost:${c}/callback${n.search}`;s.writeHead(302,{Location:p}),s.end(),i()});u.listen(1455,"127.0.0.1",()=>{s=u,n=setTimeout(()=>i(),3e5),l({success:!0})}),u.on("error",e=>{"EADDRINUSE"===e.code?l({success:!1,reason:"port_busy"}):l({success:!1,reason:e.message})})})},"startLocalServer",0,function(e,s=null){return new Promise((n,o)=>{let a=t.default.createServer((t,s)=>{let n=new r.URL(t.url,"http://localhost");if("/callback"===n.pathname||"/auth/callback"===n.pathname){let t=Object.fromEntries(n.searchParams);s.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),s.end(`<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Authentication Successful</title>
  <style>
    body { font-family: system-ui; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background: #f5f5f5; }
    .container { text-align: center; padding: 2rem; background: white; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
    .success { color: #22c55e; font-size: 3rem; }
    h1 { margin: 1rem 0; }
    p { color: #666; }
    #countdown { font-weight: bold; }
  </style>
</head>
<body>
  <div class="container">
    <div class="success">&#10003;</div>
    <h1>Authentication Successful</h1>
    <p id="message">Closing in <span id="countdown">3</span> seconds...</p>
  </div>
  <script>
    let count = 3;
    const countdown = document.getElementById("countdown");
    const message = document.getElementById("message");
    const timer = setInterval(() => {
      count--;
      countdown.textContent = count;
      if (count <= 0) {
        clearInterval(timer);
        window.close();
        setTimeout(() => {
          message.textContent = "Please close this tab manually.";
        }, 500);
      }
    }, 1000);
  </script>
</body>
</html>`),e(t)}else s.writeHead(404),s.end("Not found")});a.listen(s||0,"127.0.0.1",()=>{let{port:e}=a.address();n({server:a,port:e,close:()=>a.close()})}),a.on("error",e=>{"EADDRINUSE"===e.code&&s?o(Error(`Port ${s} is already in use. Please close other applications using this port.`)):o(e)})})},"startXaiProxy",0,function(s){return new Promise(n=>{if(c)return void n({success:!0});let o=t.default.createServer(async(t,n)=>{let o=new r.URL(t.url,"http://localhost");if("/callback"!==o.pathname&&"/auth/callback"!==o.pathname){n.writeHead(404),n.end("Not found");return}let i=o.searchParams.get("code"),c=o.searchParams.get("state"),l=o.searchParams.get("error"),h=c?u.get(c):null;if(h){try{if(l)throw Error(o.searchParams.get("error_description")||l);if(!i)throw Error("No authorization code received");let{exchangeTokens:t}=await e.A(633998),{createProviderConnection:r}=await e.A(52307),s=await t("xai",i,h.redirectUri,h.codeVerifier,c),u=await r({provider:"xai",authType:"oauth",...s,expiresAt:s.expiresIn?new Date(Date.now()+1e3*s.expiresIn).toISOString():null,testStatus:"active"});h.status="done",h.connectionId=u.id,h.email=u.email,n.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),n.end(a(!0,"You can close this window."))}catch(e){h.status="error",h.error=e.message,n.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),n.end(a(!1,e.message))}finally{d()}return}let p=`http://localhost:${s}/callback${o.search}`;n.writeHead(302,{Location:p}),n.end(),d()});o.listen(56121,"127.0.0.1",()=>{c=o,l=setTimeout(()=>d(),3e5),n({success:!0})}),o.on("error",e=>{"EADDRINUSE"===e.code?n({success:!1,reason:"port_busy"}):n({success:!1,reason:e.message})})})},"stopCodexProxy",0,i,"stopXaiProxy",0,d])},633998,e=>{e.v(t=>Promise.all(["server/chunks/[root-of-the-server]__0j4xhtp._.js","server/chunks/src_lib_oauth_providers_0~ug706.js","server/chunks/[root-of-the-server]__0g1r8m5._.js","server/chunks/open-sse_0nmde~9._.js","server/chunks/open-sse_0oh-v~-._.js","server/chunks/open-sse_06lq_.z._.js","server/chunks/open-sse_config_providerModels_0-p52r2.js"].map(t=>e.l(t))).then(()=>t(369585)))},52307,e=>{e.v(t=>Promise.all(["server/chunks/src_models_index_0w97_3~.js"].map(t=>e.l(t))).then(()=>t(756862)))}];

//# sourceMappingURL=%5Broot-of-the-server%5D__05pkv7q._.js.map