mirror of
https://github.com/cline/cline.git
synced 2026-08-28 19:48:08 +08:00
This commit is contained in:
+45
-4
@@ -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
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user