From 3bf168615a9db0bbbddc3a7112caae5cc21bff14 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Sun, 28 Dec 2025 11:17:08 +0100 Subject: [PATCH] Use dynamic import for http module in OAuth files Prevents browser bundles from failing on import. The http module is only loaded when login functions are actually called. --- packages/ai/src/utils/oauth/google-antigravity.ts | 9 +++++++-- packages/ai/src/utils/oauth/google-gemini-cli.ts | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/ai/src/utils/oauth/google-antigravity.ts b/packages/ai/src/utils/oauth/google-antigravity.ts index 20ad3e17..16f45c51 100644 --- a/packages/ai/src/utils/oauth/google-antigravity.ts +++ b/packages/ai/src/utils/oauth/google-antigravity.ts @@ -6,7 +6,7 @@ * It is only intended for CLI use, not browser environments. */ -import { createServer, type Server } from "http"; +import type { Server } from "http"; import { generatePKCE } from "./pkce.js"; import type { OAuthCredentials } from "./types.js"; @@ -36,7 +36,12 @@ const DEFAULT_PROJECT_ID = "rising-fact-p41fc"; /** * Start a local HTTP server to receive the OAuth callback */ -function startCallbackServer(): Promise<{ server: Server; getCode: () => Promise<{ code: string; state: string }> }> { +async function startCallbackServer(): Promise<{ + server: Server; + getCode: () => Promise<{ code: string; state: string }>; +}> { + const { createServer } = await import("http"); + return new Promise((resolve, reject) => { let codeResolve: (value: { code: string; state: string }) => void; let codeReject: (error: Error) => void; diff --git a/packages/ai/src/utils/oauth/google-gemini-cli.ts b/packages/ai/src/utils/oauth/google-gemini-cli.ts index 68a80492..d3585d15 100644 --- a/packages/ai/src/utils/oauth/google-gemini-cli.ts +++ b/packages/ai/src/utils/oauth/google-gemini-cli.ts @@ -6,7 +6,7 @@ * It is only intended for CLI use, not browser environments. */ -import { createServer, type Server } from "http"; +import type { Server } from "http"; import { generatePKCE } from "./pkce.js"; import type { OAuthCredentials } from "./types.js"; @@ -28,7 +28,12 @@ const CODE_ASSIST_ENDPOINT = "https://cloudcode-pa.googleapis.com"; /** * Start a local HTTP server to receive the OAuth callback */ -function startCallbackServer(): Promise<{ server: Server; getCode: () => Promise<{ code: string; state: string }> }> { +async function startCallbackServer(): Promise<{ + server: Server; + getCode: () => Promise<{ code: string; state: string }>; +}> { + const { createServer } = await import("http"); + return new Promise((resolve, reject) => { let codeResolve: (value: { code: string; state: string }) => void; let codeReject: (error: Error) => void;