fix(ai): treat gcp vertex marker as ADC auth (#3221)
This commit is contained in:
@@ -45,6 +45,7 @@ export interface GoogleVertexOptions extends StreamOptions {
|
||||
}
|
||||
|
||||
const API_VERSION = "v1";
|
||||
const GCP_VERTEX_CREDENTIALS_MARKER = "gcp-vertex-credentials";
|
||||
|
||||
const THINKING_LEVEL_MAP: Record<GoogleThinkingLevel, ThinkingLevel> = {
|
||||
THINKING_LEVEL_UNSPECIFIED: ThinkingLevel.THINKING_LEVEL_UNSPECIFIED,
|
||||
@@ -370,7 +371,7 @@ function createClientWithApiKey(
|
||||
|
||||
function resolveApiKey(options?: GoogleVertexOptions): string | undefined {
|
||||
const apiKey = options?.apiKey?.trim() || process.env.GOOGLE_CLOUD_API_KEY?.trim();
|
||||
if (!apiKey || isPlaceholderApiKey(apiKey)) {
|
||||
if (!apiKey || apiKey === GCP_VERTEX_CREDENTIALS_MARKER || isPlaceholderApiKey(apiKey)) {
|
||||
return undefined;
|
||||
}
|
||||
return apiKey;
|
||||
|
||||
@@ -86,6 +86,25 @@ describe("google-vertex api key resolution", () => {
|
||||
expect(googleGenAiMock.constructorCalls[0]).not.toHaveProperty("apiKey");
|
||||
});
|
||||
|
||||
it("falls back to ADC when options.apiKey is the gcp-vertex-credentials marker", async () => {
|
||||
const stream = streamGoogleVertex(model, context, {
|
||||
apiKey: "gcp-vertex-credentials",
|
||||
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",
|
||||
});
|
||||
expect(googleGenAiMock.constructorCalls[0]).not.toHaveProperty("apiKey");
|
||||
});
|
||||
|
||||
it("falls back to ADC when GOOGLE_CLOUD_API_KEY is a placeholder marker", async () => {
|
||||
process.env.GOOGLE_CLOUD_API_KEY = "<authenticated>";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user