fix(llms): use configured fetch for Vertex ADC refreshes (#12981) (#12991)

This commit is contained in:
Ara
2026-08-06 19:07:06 +02:00
committed by GitHub
parent 81cce3d70e
commit 574b8eb45e
2 changed files with 67 additions and 9 deletions
+45 -4
View File
@@ -51,9 +51,14 @@ describe("createVertexProviderModule", () => {
project: "test-project",
location: "global",
apiKey: undefined,
googleAuthOptions: {
googleAuthOptions: expect.objectContaining({
projectId: "test-project",
},
clientOptions: {
transporterOptions: {
fetchImplementation: globalThis.fetch,
},
},
}),
fetch: expect.any(Function),
}),
);
@@ -77,9 +82,9 @@ describe("createVertexProviderModule", () => {
expect.objectContaining({
project: "nested-project",
location: "europe-west4",
googleAuthOptions: {
googleAuthOptions: expect.objectContaining({
projectId: "nested-project",
},
}),
}),
);
});
@@ -116,10 +121,46 @@ describe("createVertexProviderModule", () => {
expect.objectContaining({
project: "test-project",
location: "us-east5",
googleAuthOptions: expect.objectContaining({
projectId: "test-project",
clientOptions: {
transporterOptions: {
fetchImplementation: globalThis.fetch,
},
},
}),
}),
);
expect(createVertexMock).not.toHaveBeenCalled();
});
it("passes a configured fetch to Vertex requests and the ADC refresh transport", async () => {
const customFetch = vi.fn() as unknown as typeof fetch;
await createVertexProviderModule(
config({
fetch: customFetch,
options: {
project: "test-project",
location: "global",
},
}),
context("claude-sonnet-4-5@20250929"),
);
expect(createVertexAnthropicMock).toHaveBeenCalledWith(
expect.objectContaining({
fetch: customFetch,
googleAuthOptions: expect.objectContaining({
clientOptions: {
transporterOptions: {
fetchImplementation: customFetch,
},
},
}),
}),
);
});
});
function config(
+22 -5
View File
@@ -8,6 +8,25 @@ import { ensureFetch, resolveApiKey } from "../http";
import { isClaudeModelId } from "../model-facts";
import type { ProviderFactoryResult } from "./types";
type VertexProviderSettings = NonNullable<Parameters<typeof createVertex>[0]>;
type VertexGoogleAuthOptions = NonNullable<
VertexProviderSettings["googleAuthOptions"]
>;
function createGoogleAuthOptions(
projectId: string | undefined,
fetchImplementation: typeof fetch,
): VertexGoogleAuthOptions {
return {
...(projectId ? { projectId } : {}),
clientOptions: {
transporterOptions: {
fetchImplementation,
},
},
};
}
function readStringOption(
options: Record<string, unknown> | undefined,
key: string,
@@ -49,11 +68,13 @@ export async function createVertexProviderModule(
"us-central1";
const googleAuthProjectId = project || undefined;
const fetch = ensureFetch(config.fetch);
const googleAuthOptions = createGoogleAuthOptions(googleAuthProjectId, fetch);
if (isClaudeModelId(context.model.id)) {
const provider = createVertexAnthropic({
project,
location,
googleAuthOptions,
baseURL: config.baseUrl,
headers: config.headers,
fetch,
@@ -65,11 +86,7 @@ export async function createVertexProviderModule(
project,
location,
apiKey: googleAuthProjectId ? undefined : await resolveApiKey(config),
googleAuthOptions: googleAuthProjectId
? {
projectId: googleAuthProjectId,
}
: undefined,
googleAuthOptions: googleAuthProjectId ? googleAuthOptions : undefined,
baseURL: config.baseUrl,
headers: config.headers,
fetch,