From b8d410fd51559d05df71e5d43971acb1242e1d2b Mon Sep 17 00:00:00 2001 From: Brad Huffman Date: Sun, 5 Jul 2026 12:15:06 -0500 Subject: [PATCH] fix: pass Vertex project explicitly and drop setup-time validation call Addresses the review on PR #36 (Gemini / Vertex support). - Pass the GCP project to ChatGoogle explicitly via googleAuthOptions.projectId in the gemini-enterprise branch of createModel(), instead of relying on ambient process.env resolution. - Import ChatGoogle from @langchain/google/node, whose params expose googleAuthOptions (the default @langchain/google entrypoint types authOptions as never and is API-key oriented). Same package, no new dependency; the /node client still supports the gai/apiKey path. - Remove the setup-time credential validation in credentials.tsx that mutated process.env.GOOGLE_CLOUD_PROJECT and issued a live testModel.invoke(["ping"]) network call during onboarding. It was the source of the flagged process.env mutation and added a round-trip, cost, and potential hang no other provider performs. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/agent/index.ts | 6 +++++- src/credentials.tsx | 32 -------------------------------- 2 files changed, 5 insertions(+), 33 deletions(-) diff --git a/src/agent/index.ts b/src/agent/index.ts index e63c31bd..cf46e040 100644 --- a/src/agent/index.ts +++ b/src/agent/index.ts @@ -5,7 +5,7 @@ import { ChatAnthropic } from "@langchain/anthropic"; import { SqliteSaver } from "@langchain/langgraph-checkpoint-sqlite"; import { ChatOpenAI } from "@langchain/openai"; import { ChatOpenRouter } from "@langchain/openrouter"; -import { ChatGoogle } from "@langchain/google"; +import { ChatGoogle } from "@langchain/google/node"; import { createDeepAgent, LocalShellBackend } from "deepagents"; import { loadOpenWikiEnv, openWikiEnvDir } from "../env.js"; import { createSystemPrompt, createUserPrompt } from "./prompt.js"; @@ -23,6 +23,7 @@ import { getProviderApiKeyEnvKey, getProviderConfig, getProviderLabel, + GOOGLE_CLOUD_PROJECT_ENV_KEY, isValidModelId, normalizeModelId, OPENAI_API_KEY_ENV_KEY, @@ -388,10 +389,13 @@ async function createModel(provider: OpenWikiProvider, modelId: string) { } if (provider === "gemini-enterprise") { + const projectId = process.env[GOOGLE_CLOUD_PROJECT_ENV_KEY]; + return new ChatGoogle({ model: modelId, platformType: "gcp", location: process.env.GOOGLE_CLOUD_LOCATION ?? "us-central1", + ...(projectId ? { googleAuthOptions: { projectId } } : {}), }); } diff --git a/src/credentials.tsx b/src/credentials.tsx index 92e825f2..5184f04d 100644 --- a/src/credentials.tsx +++ b/src/credentials.tsx @@ -298,38 +298,6 @@ export function InitSetup({ setIsSaving(true); try { - // Active credential validation - if (nextProvider === "gemini" || nextProvider === "gemini-enterprise") { - const testModelId = nextModelId ?? getDefaultModelId(nextProvider); - const resolvedValue = - nextApiKey ?? process.env[getProviderApiKeyEnvKey(nextProvider)]; - - let testModel; - if (nextProvider === "gemini") { - const { ChatGoogle } = await import("@langchain/google"); - testModel = new ChatGoogle({ - apiKey: resolvedValue, - model: testModelId, - platformType: "gai", - }); - } else { - const { ChatGoogle } = await import("@langchain/google"); - if (resolvedValue) { - process.env.GOOGLE_CLOUD_PROJECT = resolvedValue; - } - testModel = new ChatGoogle({ - model: testModelId, - platformType: "gcp", - location: process.env.GOOGLE_CLOUD_LOCATION ?? "us-central1", - }); - } - - // Execute a lightweight validation call - await testModel.invoke([{ role: "user", content: "ping" }], { - timeout: 5000, - }); - } - const updates: Record = {}; const providerEnvChanged = process.env[OPENWIKI_PROVIDER_ENV_KEY] !== nextProvider;