fix(ai): forward google vertex base url

closes #3619
This commit is contained in:
Mario Zechner
2026-04-24 00:05:43 +02:00
parent 95f4921250
commit 65a6472bdd
3 changed files with 124 additions and 18 deletions

View File

@@ -32,6 +32,9 @@ vi.mock("@google/genai", () => {
return {
GoogleGenAI,
ResourceScope: {
COLLECTION: "COLLECTION",
},
ThinkingLevel: {
THINKING_LEVEL_UNSPECIFIED: "THINKING_LEVEL_UNSPECIFIED",
MINIMAL: "MINIMAL",
@@ -44,7 +47,7 @@ vi.mock("@google/genai", () => {
import { getModel } from "../src/models.js";
import { streamGoogleVertex } from "../src/providers/google-vertex.js";
import type { Context } from "../src/types.js";
import type { Context, Model } from "../src/types.js";
const model = getModel("google-vertex", "gemini-3-flash-preview");
const context: Context = {
@@ -141,4 +144,80 @@ describe("google-vertex api key resolution", () => {
expect(googleGenAiMock.constructorCalls[0]).not.toHaveProperty("project");
expect(googleGenAiMock.constructorCalls[0]).not.toHaveProperty("location");
});
it("does not forward generated Vertex base URL placeholders", async () => {
const stream = streamGoogleVertex(model, context, {
project: "test-project",
location: "us-central1",
});
await stream.result();
expect(googleGenAiMock.constructorCalls).toHaveLength(1);
expect(googleGenAiMock.constructorCalls[0]?.httpOptions).toBeUndefined();
});
it("forwards custom baseUrl to the ADC client", async () => {
const customModel: Model<"google-vertex"> = { ...model, baseUrl: "https://proxy.example.com" };
const stream = streamGoogleVertex(customModel, context, {
project: "test-project",
location: "us-central1",
});
await stream.result();
expect(googleGenAiMock.constructorCalls).toHaveLength(1);
expect(googleGenAiMock.constructorCalls[0]).toMatchObject({
vertexai: true,
project: "test-project",
location: "us-central1",
apiVersion: "v1",
httpOptions: {
baseUrl: "https://proxy.example.com",
baseUrlResourceScope: "COLLECTION",
},
});
});
it("forwards custom baseUrl to the API key client", async () => {
const customModel: Model<"google-vertex"> = { ...model, baseUrl: "https://proxy.example.com" };
const stream = streamGoogleVertex(customModel, context, {
apiKey: "AIzaSyExampleRealisticLookingApiKey123456",
});
await stream.result();
expect(googleGenAiMock.constructorCalls).toHaveLength(1);
expect(googleGenAiMock.constructorCalls[0]).toMatchObject({
vertexai: true,
apiKey: "AIzaSyExampleRealisticLookingApiKey123456",
apiVersion: "v1",
httpOptions: {
baseUrl: "https://proxy.example.com",
baseUrlResourceScope: "COLLECTION",
},
});
});
it("does not append apiVersion when custom baseUrl already includes one", async () => {
const customModel: Model<"google-vertex"> = {
...model,
baseUrl: "https://proxy.example.com/v1/projects/test-project/locations/global",
};
const stream = streamGoogleVertex(customModel, context, {
project: "test-project",
location: "us-central1",
});
await stream.result();
expect(googleGenAiMock.constructorCalls).toHaveLength(1);
expect(googleGenAiMock.constructorCalls[0]).toMatchObject({
httpOptions: {
baseUrl: "https://proxy.example.com/v1/projects/test-project/locations/global",
baseUrlResourceScope: "COLLECTION",
apiVersion: "",
},
});
});
});