Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/server/gemini-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
}));
Expand All @@ -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?.(); }
Expand Down
5 changes: 3 additions & 2 deletions structure/data-planes/gemini-native.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions tests/server/gemini-native.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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! },
Expand Down