diff --git a/src/server/gemini-native.ts b/src/server/gemini-native.ts index 8468c8a906b..20489ebc97f 100644 --- a/src/server/gemini-native.ts +++ b/src/server/gemini-native.ts @@ -26,6 +26,8 @@ import { noteCredentialAttemptSend, sealCredentialRefusal } from "./credential-r import { DEFAULT_STALL_TIMEOUT_SEC, resolveStallTimeoutMs } from "../stall-timeout"; import { isLocalUpstream } from "../lib/local-upstream"; import { assertProviderDestinationAllowed } from "../lib/destination-policy"; +import { providerEgressFetchInit, resolveProviderEgress } from "../lib/provider-egress"; +import { configuredOutboundFetch } from "../lib/proxy-env"; import { clientFacingModelLabel, type ClientFacingModelLabel } from "../lib/error-destination"; import { registerTurn, unregisterTurn, type ActiveTurnLease } from "./lifecycle"; import { containsGeminiCredential, geminiNativeReasoningFields, geminiSseTransform, readGeminiText, validateGeminiObject, GEMINI_NATIVE_MAX_BYTES, GEMINI_NATIVE_ERROR_CODE, unwrapGeminiResponse, wrapGeminiRequest } from "./gemini-native-wire"; @@ -193,6 +195,8 @@ export async function handleGeminiNative( } const body = wrapGeminiRequest(raw, model, access.projectId!); if (logCtx) stampOAuthAccountLabel(logCtx, GEMINI_NATIVE_PROVIDER, { authMode: "oauth" }, access.accountId); + const target = `${baseUrl.replace(/\/$/, "")}/v1internal:${method}`; + const egress = resolveProviderEgress({ providerName: GEMINI_NATIVE_PROVIDER, provider, url: target }); const report = physicalBudget && createPhysicalSendReporter(physicalBudget, () => ({ poolId: GEMINI_NATIVE_PROVIDER, identityId: logCtx?.accountLogLabel, })); @@ -212,11 +216,12 @@ export async function handleGeminiNative( Object.assign(logCtx.activeAttempt!, reasoning); } dispatched = true; - return await fetchWithAttemptDeadline(`${baseUrl.replace(/\/$/, "")}/v1internal:${method}`, { + return await fetchWithAttemptDeadline(target, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${access.accessToken}`, "User-Agent": antigravityUserAgentForWireModel(model) }, body, - }, config.connectTimeoutMs ?? 200_000, ac.signal, true, deps.fetch); + }, config.connectTimeoutMs ?? 200_000, ac.signal, true, + ((input, init) => configuredOutboundFetch(input, { ...init, ...providerEgressFetchInit(egress) }, deps.fetch)) as typeof globalThis.fetch); } finally { try { if (dispatched) report?.(1); } finally { report?.close?.(); } diff --git a/structure/data-planes/gemini-native.md b/structure/data-planes/gemini-native.md index d4ed04205a2..041999e4742 100644 --- a/structure/data-planes/gemini-native.md +++ b/structure/data-planes/gemini-native.md @@ -29,8 +29,9 @@ JSON input and the supplied output ceiling per candidate. A 401 replay needs fre An applicable ceiling that cannot admit the reservation returns a Gemini-shaped 429 with `workflow_spend_exhausted`. The final request log settles reported input and output usage, including reasoning. Sends without final usage retain unresolved spend at the reservation size. -The destination policy checks the base URL and redirects remain manual. Only proxy-constructed -headers and the bound OAuth credential go upstream. +The destination policy checks the base URL, redirects remain manual, and each physical send resolves +the provider's direct, `noProxy`, HTTP(S)-proxy or SOCKS route against the Antigravity destination. +Only proxy-constructed headers and the bound OAuth credential go upstream. `src/server/gemini-native-wire.ts` validates the JSON object and embeds the original request under the CCA `request` member. It extracts successful `response` members by source offsets diff --git a/tests/server/gemini-native.test.ts b/tests/server/gemini-native.test.ts index 717e23b39c6..9f6a2e7a948 100644 --- a/tests/server/gemini-native.test.ts +++ b/tests/server/gemini-native.test.ts @@ -64,6 +64,24 @@ test("native generation preserves source JSON, binds project and replaces ingres expect(getActiveTurnCount()).toBe(baseline); }); +test.each([ + ["direct", { proxy: "direct" }, false], + ["matching noProxy", { proxy: "http://provider-proxy.invalid:3128", noProxy: "daily-cloudcode-pa.googleapis.com" }, false], + ["provider proxy", { proxy: "http://provider-proxy.invalid:3128" }, "http://provider-proxy.invalid:3128/"], +] as const)("native generation honors %s provider egress", async (_name, egress, expectedProxy) => { + let seenProxy: unknown; + const cfg = { ...config, providers: { "google-antigravity": { ...config.providers["google-antigravity"], ...egress } } } as OcxConfig; + const response = await run(request(), { + access: async () => old, refresh: async () => { throw new Error("unexpected refresh"); }, + fetch: transport((_url, init) => { + seenProxy = (init as RequestInit & { proxy?: unknown }).proxy; + return new Response('{"response":{}}'); + }), + }, false, cfg); + expect(response.status).toBe(200); + expect(seenProxy).toBe(expectedProxy); +}); + const fixtureCredentials = [ { name: "access token", wire: old.accessToken }, { name: "project ID", wire: old.projectId! },