@ai-sdk/google-vertex 5.0.98 → 5.0.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/dist/anthropic/edge/index.d.ts +84 -80
- package/dist/anthropic/edge/index.d.ts.map +1 -0
- package/dist/anthropic/edge/index.js +238 -272
- package/dist/anthropic/edge/index.js.map +1 -1
- package/dist/anthropic/index.d.ts +69 -66
- package/dist/anthropic/index.d.ts.map +1 -0
- package/dist/anthropic/index.js +172 -177
- package/dist/anthropic/index.js.map +1 -1
- package/dist/edge/index.d.ts +206 -194
- package/dist/edge/index.d.ts.map +1 -0
- package/dist/edge/index.js +1428 -1846
- package/dist/edge/index.js.map +1 -1
- package/dist/index.d.ts +265 -252
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1369 -1761
- package/dist/index.js.map +1 -1
- package/dist/maas/edge/index.d.ts +62 -59
- package/dist/maas/edge/index.d.ts.map +1 -0
- package/dist/maas/edge/index.js +174 -196
- package/dist/maas/edge/index.js.map +1 -1
- package/dist/maas/index.d.ts +47 -45
- package/dist/maas/index.d.ts.map +1 -0
- package/dist/maas/index.js +109 -102
- package/dist/maas/index.js.map +1 -1
- package/dist/xai/edge/index.d.ts +77 -73
- package/dist/xai/edge/index.d.ts.map +1 -0
- package/dist/xai/edge/index.js +203 -235
- package/dist/xai/edge/index.js.map +1 -1
- package/dist/xai/index.d.ts +62 -59
- package/dist/xai/index.d.ts.map +1 -0
- package/dist/xai/index.js +138 -141
- package/dist/xai/index.js.map +1 -1
- package/docs/16-google-vertex.mdx +3 -3
- package/package.json +11 -11
- package/src/anthropic/google-vertex-anthropic-provider.ts +14 -4
- package/src/gemini-transcription/google-vertex-gemini-transcription-model.ts +5 -1
- package/src/google-vertex-provider-base.ts +28 -15
- package/src/google-vertex-transcription-model-options.ts +2 -1
- package/src/google-vertex-transcription-model.ts +13 -1
- package/src/maas/google-vertex-maas-provider.ts +18 -6
package/dist/xai/index.d.ts
CHANGED
|
@@ -1,64 +1,66 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { FetchFunction, Resolvable } from "@ai-sdk/provider-utils";
|
|
2
|
+
import { GoogleAuthOptions } from "google-auth-library";
|
|
3
|
+
import { LanguageModelV4, ProviderV4 } from "@ai-sdk/provider";
|
|
4
|
+
//#region src/xai/google-vertex-xai-options.d.ts
|
|
5
5
|
type GoogleVertexXaiModelId = 'xai/grok-4.20-reasoning' | 'xai/grok-4.20-non-reasoning' | 'xai/grok-4.1-fast-reasoning' | 'xai/grok-4.1-fast-non-reasoning' | (string & {});
|
|
6
|
-
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/xai/google-vertex-xai-provider.d.ts
|
|
7
8
|
interface GoogleVertexXaiProvider extends ProviderV4 {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Creates a model for text generation.
|
|
11
|
+
*/
|
|
12
|
+
(modelId: GoogleVertexXaiModelId): LanguageModelV4;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a model for text generation.
|
|
15
|
+
*/
|
|
16
|
+
languageModel(modelId: GoogleVertexXaiModelId): LanguageModelV4;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a chat model for text generation.
|
|
19
|
+
*/
|
|
20
|
+
chatModel(modelId: GoogleVertexXaiModelId): LanguageModelV4;
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated Use `embeddingModel` instead.
|
|
23
|
+
*/
|
|
24
|
+
textEmbeddingModel(modelId: string): never;
|
|
24
25
|
}
|
|
25
26
|
interface GoogleVertexXaiProviderSettings$1 {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Google Cloud project ID. Defaults to the value of the `GOOGLE_VERTEX_PROJECT` environment variable.
|
|
29
|
+
*/
|
|
30
|
+
project?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Google Cloud location/region. Defaults to the value of the `GOOGLE_VERTEX_LOCATION` environment variable.
|
|
33
|
+
* Use 'global' for the global endpoint.
|
|
34
|
+
*/
|
|
35
|
+
location?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Base URL for the API calls. If not provided, will be constructed from project and location.
|
|
38
|
+
*/
|
|
39
|
+
baseURL?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Headers to use for requests. Can be:
|
|
42
|
+
* - A headers object
|
|
43
|
+
* - A Promise that resolves to a headers object
|
|
44
|
+
* - A function that returns a headers object
|
|
45
|
+
* - A function that returns a Promise of a headers object
|
|
46
|
+
*/
|
|
47
|
+
headers?: Resolvable<Record<string, string | undefined>>;
|
|
48
|
+
/**
|
|
49
|
+
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
50
|
+
* or to provide a custom fetch implementation for e.g. testing.
|
|
51
|
+
*/
|
|
52
|
+
fetch?: FetchFunction;
|
|
52
53
|
}
|
|
53
|
-
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/xai/google-vertex-xai-provider-node.d.ts
|
|
54
56
|
interface GoogleVertexXaiProviderSettings extends GoogleVertexXaiProviderSettings$1 {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Optional. The Authentication options provided by google-auth-library.
|
|
59
|
+
* Complete list of authentication options is documented in the
|
|
60
|
+
* GoogleAuthOptions interface:
|
|
61
|
+
* https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts.
|
|
62
|
+
*/
|
|
63
|
+
googleAuthOptions?: GoogleAuthOptions;
|
|
62
64
|
}
|
|
63
65
|
/**
|
|
64
66
|
* Create a Google Vertex AI xAI provider instance for Node.js.
|
|
@@ -67,10 +69,11 @@ interface GoogleVertexXaiProviderSettings extends GoogleVertexXaiProviderSetting
|
|
|
67
69
|
*
|
|
68
70
|
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/grok
|
|
69
71
|
*/
|
|
70
|
-
declare function createGoogleVertexXai(options?: GoogleVertexXaiProviderSettings): GoogleVertexXaiProvider;
|
|
72
|
+
export declare function createGoogleVertexXai(options?: GoogleVertexXaiProviderSettings): GoogleVertexXaiProvider;
|
|
71
73
|
/**
|
|
72
74
|
* Default Google Vertex AI xAI provider instance for Node.js.
|
|
73
75
|
*/
|
|
74
|
-
declare const googleVertexXai: GoogleVertexXaiProvider;
|
|
75
|
-
|
|
76
|
-
export {
|
|
76
|
+
export declare const googleVertexXai: GoogleVertexXaiProvider;
|
|
77
|
+
//#endregion
|
|
78
|
+
export type { GoogleVertexXaiModelId, GoogleVertexXaiProvider, GoogleVertexXaiProviderSettings };
|
|
79
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["GoogleVertexXaiProviderSettings","GoogleVertexXaiProviderSettingsOriginal"],"sources":["../../src/xai/google-vertex-xai-options.ts","../../src/xai/google-vertex-xai-provider.ts","../../src/xai/google-vertex-xai-provider-node.ts"],"mappings":";;;;KACY;;;UCkBK,gCAAgC;;;;GAI9C,SAAS,yBAAyB;;;;EAKnC,cAAc,SAAS,yBAAyB;;;;EAKhD,UAAU,SAAS,yBAAyB;;;;EAK5C,mBAAmB;;UAGJA;;;;EAIf;;;;;EAMA;;;;EAKA;;;;;;;;EASA,UAAU,WAAW;;;;;EAMrB,QAAQ;;;;UC7DO,wCAAwCC;;;;;;;EAOvD,oBAAoB;;;;;;;;;wBAUN,sBACd,UAAS,kCACR;;;;qBAgCU,iBAAe"}
|
package/dist/xai/index.js
CHANGED
|
@@ -1,152 +1,149 @@
|
|
|
1
|
-
|
|
2
|
-
import { resolve } from "@ai-sdk/provider-utils";
|
|
3
|
-
|
|
4
|
-
// src/google-vertex-auth-google-auth-library.ts
|
|
1
|
+
import { loadOptionalSetting, loadSetting, resolve, withoutTrailingSlash } from "@ai-sdk/provider-utils";
|
|
5
2
|
import { GoogleAuth } from "google-auth-library";
|
|
3
|
+
import { NoSuchModelError } from "@ai-sdk/provider";
|
|
4
|
+
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
5
|
+
//#region src/google-vertex-auth-google-auth-library.ts
|
|
6
6
|
function createAuthTokenGenerator(options) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return token?.token ?? null;
|
|
15
|
-
};
|
|
7
|
+
const auth = new GoogleAuth({
|
|
8
|
+
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
|
|
9
|
+
...options
|
|
10
|
+
});
|
|
11
|
+
return async function generateAuthToken() {
|
|
12
|
+
return (await (await auth.getClient()).getAccessToken())?.token ?? null;
|
|
13
|
+
};
|
|
16
14
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import {
|
|
20
|
-
NoSuchModelError
|
|
21
|
-
} from "@ai-sdk/provider";
|
|
22
|
-
import {
|
|
23
|
-
createOpenAICompatible
|
|
24
|
-
} from "@ai-sdk/openai-compatible";
|
|
25
|
-
import {
|
|
26
|
-
loadOptionalSetting,
|
|
27
|
-
loadSetting,
|
|
28
|
-
withoutTrailingSlash
|
|
29
|
-
} from "@ai-sdk/provider-utils";
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/xai/google-vertex-xai-provider.ts
|
|
30
17
|
function convertGoogleVertexXaiUsage(usage) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
raw: usage
|
|
64
|
-
};
|
|
18
|
+
if (usage == null) return {
|
|
19
|
+
inputTokens: {
|
|
20
|
+
total: void 0,
|
|
21
|
+
noCache: void 0,
|
|
22
|
+
cacheRead: void 0,
|
|
23
|
+
cacheWrite: void 0
|
|
24
|
+
},
|
|
25
|
+
outputTokens: {
|
|
26
|
+
total: void 0,
|
|
27
|
+
text: void 0,
|
|
28
|
+
reasoning: void 0
|
|
29
|
+
},
|
|
30
|
+
raw: void 0
|
|
31
|
+
};
|
|
32
|
+
const promptTokens = usage.prompt_tokens ?? 0;
|
|
33
|
+
const completionTokens = usage.completion_tokens ?? 0;
|
|
34
|
+
const cacheReadTokens = usage.prompt_tokens_details?.cached_tokens ?? 0;
|
|
35
|
+
const reasoningTokens = usage.completion_tokens_details?.reasoning_tokens ?? 0;
|
|
36
|
+
return {
|
|
37
|
+
inputTokens: {
|
|
38
|
+
total: promptTokens,
|
|
39
|
+
noCache: promptTokens - cacheReadTokens,
|
|
40
|
+
cacheRead: cacheReadTokens,
|
|
41
|
+
cacheWrite: void 0
|
|
42
|
+
},
|
|
43
|
+
outputTokens: {
|
|
44
|
+
total: completionTokens + reasoningTokens,
|
|
45
|
+
text: completionTokens,
|
|
46
|
+
reasoning: reasoningTokens
|
|
47
|
+
},
|
|
48
|
+
raw: usage
|
|
49
|
+
};
|
|
65
50
|
}
|
|
66
51
|
function transformGoogleVertexXaiRequestBody(args) {
|
|
67
|
-
|
|
68
|
-
|
|
52
|
+
const { reasoning_effort: _reasoningEffort, ...rest } = args;
|
|
53
|
+
return rest;
|
|
69
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Create a Google Vertex AI xAI provider instance.
|
|
57
|
+
* Uses the OpenAI-compatible Chat Completions API for Grok partner models.
|
|
58
|
+
*
|
|
59
|
+
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/grok
|
|
60
|
+
*/
|
|
61
|
+
function createGoogleVertexXai$1(options = {}) {
|
|
62
|
+
const loadLocation = () => loadOptionalSetting({
|
|
63
|
+
settingValue: options.location,
|
|
64
|
+
environmentVariableName: "GOOGLE_VERTEX_LOCATION"
|
|
65
|
+
});
|
|
66
|
+
const loadProject = () => loadSetting({
|
|
67
|
+
settingValue: options.project,
|
|
68
|
+
settingName: "project",
|
|
69
|
+
environmentVariableName: "GOOGLE_VERTEX_PROJECT",
|
|
70
|
+
description: "Google Vertex project"
|
|
71
|
+
});
|
|
72
|
+
const constructBaseURL = () => {
|
|
73
|
+
return `https://aiplatform.googleapis.com/v1/projects/${loadProject()}/locations/${loadLocation() ?? "global"}/endpoints/openapi`;
|
|
74
|
+
};
|
|
75
|
+
const loadBaseURL = () => withoutTrailingSlash(options.baseURL ?? "") || constructBaseURL();
|
|
76
|
+
let cachedProvider;
|
|
77
|
+
const getProvider = () => cachedProvider ??= createOpenAICompatible({
|
|
78
|
+
name: "googleVertex.xai",
|
|
79
|
+
baseURL: loadBaseURL(),
|
|
80
|
+
fetch: options.fetch,
|
|
81
|
+
includeUsage: true,
|
|
82
|
+
supportsStructuredOutputs: true,
|
|
83
|
+
supportedUrls: () => ({ "image/*": [/^https?:\/\/.*$/] }),
|
|
84
|
+
transformRequestBody: transformGoogleVertexXaiRequestBody,
|
|
85
|
+
convertUsage: convertGoogleVertexXaiUsage
|
|
86
|
+
});
|
|
87
|
+
const createChatModel = (modelId) => getProvider().languageModel(modelId);
|
|
88
|
+
const provider = function(modelId) {
|
|
89
|
+
if (new.target) throw new Error("The Google Vertex xAI model function cannot be called with the new keyword.");
|
|
90
|
+
return createChatModel(modelId);
|
|
91
|
+
};
|
|
92
|
+
provider.specificationVersion = "v4";
|
|
93
|
+
provider.languageModel = createChatModel;
|
|
94
|
+
provider.chatModel = (modelId) => getProvider().chatModel(modelId);
|
|
95
|
+
provider.embeddingModel = (modelId) => {
|
|
96
|
+
throw new NoSuchModelError({
|
|
97
|
+
modelId,
|
|
98
|
+
modelType: "embeddingModel"
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
provider.textEmbeddingModel = provider.embeddingModel;
|
|
102
|
+
provider.imageModel = (modelId) => {
|
|
103
|
+
throw new NoSuchModelError({
|
|
104
|
+
modelId,
|
|
105
|
+
modelType: "imageModel"
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
return provider;
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/xai/google-vertex-xai-provider-node.ts
|
|
112
|
+
/**
|
|
113
|
+
* Create a Google Vertex AI xAI provider instance for Node.js.
|
|
114
|
+
* Uses the OpenAI-compatible Chat Completions API for Grok partner models.
|
|
115
|
+
* Automatically handles Google Cloud authentication.
|
|
116
|
+
*
|
|
117
|
+
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/grok
|
|
118
|
+
*/
|
|
70
119
|
function createGoogleVertexXai(options = {}) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
includeUsage: true,
|
|
93
|
-
supportsStructuredOutputs: true,
|
|
94
|
-
supportedUrls: () => ({
|
|
95
|
-
"image/*": [/^https?:\/\/.*$/]
|
|
96
|
-
}),
|
|
97
|
-
transformRequestBody: transformGoogleVertexXaiRequestBody,
|
|
98
|
-
convertUsage: convertGoogleVertexXaiUsage
|
|
99
|
-
});
|
|
100
|
-
const createChatModel = (modelId) => getProvider().languageModel(modelId);
|
|
101
|
-
const provider = function(modelId) {
|
|
102
|
-
if (new.target) {
|
|
103
|
-
throw new Error(
|
|
104
|
-
"The Google Vertex xAI model function cannot be called with the new keyword."
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
return createChatModel(modelId);
|
|
108
|
-
};
|
|
109
|
-
provider.specificationVersion = "v4";
|
|
110
|
-
provider.languageModel = createChatModel;
|
|
111
|
-
provider.chatModel = (modelId) => getProvider().chatModel(modelId);
|
|
112
|
-
provider.embeddingModel = (modelId) => {
|
|
113
|
-
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
114
|
-
};
|
|
115
|
-
provider.textEmbeddingModel = provider.embeddingModel;
|
|
116
|
-
provider.imageModel = (modelId) => {
|
|
117
|
-
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
118
|
-
};
|
|
119
|
-
return provider;
|
|
120
|
+
const generateAuthToken = createAuthTokenGenerator(options.googleAuthOptions);
|
|
121
|
+
const customFetch = async (url, init) => {
|
|
122
|
+
const token = await generateAuthToken();
|
|
123
|
+
const authHeaders = {
|
|
124
|
+
...await resolve(options.headers),
|
|
125
|
+
Authorization: `Bearer ${token}`
|
|
126
|
+
};
|
|
127
|
+
const fetchInit = {
|
|
128
|
+
...init,
|
|
129
|
+
headers: {
|
|
130
|
+
...init?.headers,
|
|
131
|
+
...authHeaders
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
return (options.fetch ?? fetch)(url, fetchInit);
|
|
135
|
+
};
|
|
136
|
+
return createGoogleVertexXai$1({
|
|
137
|
+
...options,
|
|
138
|
+
fetch: customFetch,
|
|
139
|
+
headers: void 0
|
|
140
|
+
});
|
|
120
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Default Google Vertex AI xAI provider instance for Node.js.
|
|
144
|
+
*/
|
|
145
|
+
const googleVertexXai = createGoogleVertexXai();
|
|
146
|
+
//#endregion
|
|
147
|
+
export { createGoogleVertexXai, googleVertexXai };
|
|
121
148
|
|
|
122
|
-
// src/xai/google-vertex-xai-provider-node.ts
|
|
123
|
-
function createGoogleVertexXai2(options = {}) {
|
|
124
|
-
const generateAuthToken = createAuthTokenGenerator(options.googleAuthOptions);
|
|
125
|
-
const customFetch = async (url, init) => {
|
|
126
|
-
const token = await generateAuthToken();
|
|
127
|
-
const resolvedHeaders = await resolve(options.headers);
|
|
128
|
-
const authHeaders = {
|
|
129
|
-
...resolvedHeaders,
|
|
130
|
-
Authorization: `Bearer ${token}`
|
|
131
|
-
};
|
|
132
|
-
const fetchInit = {
|
|
133
|
-
...init,
|
|
134
|
-
headers: {
|
|
135
|
-
...init?.headers,
|
|
136
|
-
...authHeaders
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
return (options.fetch ?? fetch)(url, fetchInit);
|
|
140
|
-
};
|
|
141
|
-
return createGoogleVertexXai({
|
|
142
|
-
...options,
|
|
143
|
-
fetch: customFetch,
|
|
144
|
-
headers: void 0
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
var googleVertexXai = createGoogleVertexXai2();
|
|
148
|
-
export {
|
|
149
|
-
createGoogleVertexXai2 as createGoogleVertexXai,
|
|
150
|
-
googleVertexXai
|
|
151
|
-
};
|
|
152
149
|
//# sourceMappingURL=index.js.map
|
package/dist/xai/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/xai/google-vertex-xai-provider-node.ts","../../src/google-vertex-auth-google-auth-library.ts","../../src/xai/google-vertex-xai-provider.ts"],"sourcesContent":["import { resolve, type FetchFunction } from '@ai-sdk/provider-utils';\nimport type { GoogleAuthOptions } from 'google-auth-library';\nimport { createAuthTokenGenerator } from '../google-vertex-auth-google-auth-library';\nimport {\n createGoogleVertexXai as createGoogleVertexXaiOriginal,\n type GoogleVertexXaiProvider,\n type GoogleVertexXaiProviderSettings as GoogleVertexXaiProviderSettingsOriginal,\n} from './google-vertex-xai-provider';\nexport type { GoogleVertexXaiProvider };\n\nexport interface GoogleVertexXaiProviderSettings extends GoogleVertexXaiProviderSettingsOriginal {\n /**\n * Optional. The Authentication options provided by google-auth-library.\n * Complete list of authentication options is documented in the\n * GoogleAuthOptions interface:\n * https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts.\n */\n googleAuthOptions?: GoogleAuthOptions;\n}\n\n/**\n * Create a Google Vertex AI xAI provider instance for Node.js.\n * Uses the OpenAI-compatible Chat Completions API for Grok partner models.\n * Automatically handles Google Cloud authentication.\n *\n * @see https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/grok\n */\nexport function createGoogleVertexXai(\n options: GoogleVertexXaiProviderSettings = {},\n): GoogleVertexXaiProvider {\n const generateAuthToken = createAuthTokenGenerator(options.googleAuthOptions);\n\n const customFetch: FetchFunction = async (url, init) => {\n const token = await generateAuthToken();\n const resolvedHeaders = await resolve(options.headers);\n const authHeaders = {\n ...resolvedHeaders,\n Authorization: `Bearer ${token}`,\n };\n\n const fetchInit = {\n ...init,\n headers: {\n ...init?.headers,\n ...authHeaders,\n },\n };\n\n return (options.fetch ?? fetch)(url, fetchInit);\n };\n\n return createGoogleVertexXaiOriginal({\n ...options,\n fetch: customFetch,\n headers: undefined,\n });\n}\n\n/**\n * Default Google Vertex AI xAI provider instance for Node.js.\n */\nexport const googleVertexXai = createGoogleVertexXai();\n","import { GoogleAuth, type GoogleAuthOptions } from 'google-auth-library';\n\nexport function createAuthTokenGenerator(options?: GoogleAuthOptions) {\n const auth = new GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n ...options,\n });\n\n return async function generateAuthToken() {\n const client = await auth.getClient();\n const token = await client.getAccessToken();\n return token?.token ?? null;\n };\n}\n","import {\n NoSuchModelError,\n type LanguageModelV4,\n type LanguageModelV4Usage,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n createOpenAICompatible,\n type OpenAICompatibleProvider,\n} from '@ai-sdk/openai-compatible';\nimport {\n loadOptionalSetting,\n loadSetting,\n withoutTrailingSlash,\n type FetchFunction,\n type Resolvable,\n} from '@ai-sdk/provider-utils';\nimport type { GoogleVertexXaiModelId } from './google-vertex-xai-options';\n\nexport interface GoogleVertexXaiProvider extends ProviderV4 {\n /**\n * Creates a model for text generation.\n */\n (modelId: GoogleVertexXaiModelId): LanguageModelV4;\n\n /**\n * Creates a model for text generation.\n */\n languageModel(modelId: GoogleVertexXaiModelId): LanguageModelV4;\n\n /**\n * Creates a chat model for text generation.\n */\n chatModel(modelId: GoogleVertexXaiModelId): LanguageModelV4;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nexport interface GoogleVertexXaiProviderSettings {\n /**\n * Google Cloud project ID. Defaults to the value of the `GOOGLE_VERTEX_PROJECT` environment variable.\n */\n project?: string;\n\n /**\n * Google Cloud location/region. Defaults to the value of the `GOOGLE_VERTEX_LOCATION` environment variable.\n * Use 'global' for the global endpoint.\n */\n location?: string;\n\n /**\n * Base URL for the API calls. If not provided, will be constructed from project and location.\n */\n baseURL?: string;\n\n /**\n * Headers to use for requests. Can be:\n * - A headers object\n * - A Promise that resolves to a headers object\n * - A function that returns a headers object\n * - A function that returns a Promise of a headers object\n */\n headers?: Resolvable<Record<string, string | undefined>>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\ntype GoogleVertexXaiUsage =\n | {\n prompt_tokens?: number | null;\n completion_tokens?: number | null;\n prompt_tokens_details?: {\n cached_tokens?: number | null;\n } | null;\n completion_tokens_details?: {\n reasoning_tokens?: number | null;\n } | null;\n }\n | undefined\n | null;\n\nfunction convertGoogleVertexXaiUsage(\n usage: GoogleVertexXaiUsage,\n): LanguageModelV4Usage {\n if (usage == null) {\n return {\n inputTokens: {\n total: undefined,\n noCache: undefined,\n cacheRead: undefined,\n cacheWrite: undefined,\n },\n outputTokens: {\n total: undefined,\n text: undefined,\n reasoning: undefined,\n },\n raw: undefined,\n };\n }\n\n const promptTokens = usage.prompt_tokens ?? 0;\n const completionTokens = usage.completion_tokens ?? 0;\n const cacheReadTokens = usage.prompt_tokens_details?.cached_tokens ?? 0;\n const reasoningTokens =\n usage.completion_tokens_details?.reasoning_tokens ?? 0;\n\n return {\n inputTokens: {\n total: promptTokens,\n noCache: promptTokens - cacheReadTokens,\n cacheRead: cacheReadTokens,\n cacheWrite: undefined,\n },\n outputTokens: {\n total: completionTokens + reasoningTokens,\n text: completionTokens,\n reasoning: reasoningTokens,\n },\n raw: usage,\n };\n}\n\nfunction transformGoogleVertexXaiRequestBody(args: Record<string, any>) {\n const { reasoning_effort: _reasoningEffort, ...rest } = args;\n return rest;\n}\n\n/**\n * Create a Google Vertex AI xAI provider instance.\n * Uses the OpenAI-compatible Chat Completions API for Grok partner models.\n *\n * @see https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/grok\n */\nexport function createGoogleVertexXai(\n options: GoogleVertexXaiProviderSettings = {},\n): GoogleVertexXaiProvider {\n const loadLocation = () =>\n loadOptionalSetting({\n settingValue: options.location,\n environmentVariableName: 'GOOGLE_VERTEX_LOCATION',\n });\n\n const loadProject = () =>\n loadSetting({\n settingValue: options.project,\n settingName: 'project',\n environmentVariableName: 'GOOGLE_VERTEX_PROJECT',\n description: 'Google Vertex project',\n });\n\n const constructBaseURL = () => {\n const projectId = loadProject();\n const location = loadLocation() ?? 'global';\n\n return `https://aiplatform.googleapis.com/v1/projects/${projectId}/locations/${location}/endpoints/openapi`;\n };\n\n const loadBaseURL = () =>\n withoutTrailingSlash(options.baseURL ?? '') || constructBaseURL();\n\n let cachedProvider:\n | OpenAICompatibleProvider<GoogleVertexXaiModelId, string, string, string>\n | undefined;\n const getProvider = () =>\n (cachedProvider ??= createOpenAICompatible({\n name: 'googleVertex.xai',\n baseURL: loadBaseURL(),\n fetch: options.fetch,\n includeUsage: true,\n supportsStructuredOutputs: true,\n supportedUrls: () => ({\n 'image/*': [/^https?:\\/\\/.*$/],\n }),\n transformRequestBody: transformGoogleVertexXaiRequestBody,\n convertUsage: convertGoogleVertexXaiUsage,\n }));\n\n const createChatModel = (modelId: GoogleVertexXaiModelId) =>\n getProvider().languageModel(modelId);\n\n const provider = function (modelId: GoogleVertexXaiModelId) {\n if (new.target) {\n throw new Error(\n 'The Google Vertex xAI model function cannot be called with the new keyword.',\n );\n }\n\n return createChatModel(modelId);\n };\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = createChatModel;\n provider.chatModel = (modelId: GoogleVertexXaiModelId) =>\n getProvider().chatModel(modelId);\n provider.embeddingModel = (modelId: string): never => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string): never => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n return provider;\n}\n"],"mappings":";AAAA,SAAS,eAAmC;;;ACA5C,SAAS,kBAA0C;AAE5C,SAAS,yBAAyB,SAA6B;AACpE,QAAM,OAAO,IAAI,WAAW;AAAA,IAC1B,QAAQ,CAAC,gDAAgD;AAAA,IACzD,GAAG;AAAA,EACL,CAAC;AAED,SAAO,eAAe,oBAAoB;AACxC,UAAM,SAAS,MAAM,KAAK,UAAU;AACpC,UAAM,QAAQ,MAAM,OAAO,eAAe;AAC1C,WAAO,OAAO,SAAS;AAAA,EACzB;AACF;;;ACbA;AAAA,EACE;AAAA,OAI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A,QACP,GAAG,MAAM;AAAA,QACT,GAAG;AAAA,MACL;AAAA,IACF;AAEA,YAAQ,QAAQ,SAAS,OAAO,KAAK,SAAS;AAAA,EAChD;AAEA,SAAO,sBAA8B;AAAA,IACnC,GAAG;AAAA,IACH,OAAO;AAAA,IACP,SAAS;AAAA,EACX,CAAC;AACH;AAKO,IAAM,kBAAkBA,uBAAsB;","names":["createGoogleVertexXai"]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["createGoogleVertexXai","createGoogleVertexXaiOriginal"],"sources":["../../src/google-vertex-auth-google-auth-library.ts","../../src/xai/google-vertex-xai-provider.ts","../../src/xai/google-vertex-xai-provider-node.ts"],"sourcesContent":["import { GoogleAuth, type GoogleAuthOptions } from 'google-auth-library';\n\nexport function createAuthTokenGenerator(options?: GoogleAuthOptions) {\n const auth = new GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n ...options,\n });\n\n return async function generateAuthToken() {\n const client = await auth.getClient();\n const token = await client.getAccessToken();\n return token?.token ?? null;\n };\n}\n","import {\n NoSuchModelError,\n type LanguageModelV4,\n type LanguageModelV4Usage,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n createOpenAICompatible,\n type OpenAICompatibleProvider,\n} from '@ai-sdk/openai-compatible';\nimport {\n loadOptionalSetting,\n loadSetting,\n withoutTrailingSlash,\n type FetchFunction,\n type Resolvable,\n} from '@ai-sdk/provider-utils';\nimport type { GoogleVertexXaiModelId } from './google-vertex-xai-options';\n\nexport interface GoogleVertexXaiProvider extends ProviderV4 {\n /**\n * Creates a model for text generation.\n */\n (modelId: GoogleVertexXaiModelId): LanguageModelV4;\n\n /**\n * Creates a model for text generation.\n */\n languageModel(modelId: GoogleVertexXaiModelId): LanguageModelV4;\n\n /**\n * Creates a chat model for text generation.\n */\n chatModel(modelId: GoogleVertexXaiModelId): LanguageModelV4;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nexport interface GoogleVertexXaiProviderSettings {\n /**\n * Google Cloud project ID. Defaults to the value of the `GOOGLE_VERTEX_PROJECT` environment variable.\n */\n project?: string;\n\n /**\n * Google Cloud location/region. Defaults to the value of the `GOOGLE_VERTEX_LOCATION` environment variable.\n * Use 'global' for the global endpoint.\n */\n location?: string;\n\n /**\n * Base URL for the API calls. If not provided, will be constructed from project and location.\n */\n baseURL?: string;\n\n /**\n * Headers to use for requests. Can be:\n * - A headers object\n * - A Promise that resolves to a headers object\n * - A function that returns a headers object\n * - A function that returns a Promise of a headers object\n */\n headers?: Resolvable<Record<string, string | undefined>>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\ntype GoogleVertexXaiUsage =\n | {\n prompt_tokens?: number | null;\n completion_tokens?: number | null;\n prompt_tokens_details?: {\n cached_tokens?: number | null;\n } | null;\n completion_tokens_details?: {\n reasoning_tokens?: number | null;\n } | null;\n }\n | undefined\n | null;\n\nfunction convertGoogleVertexXaiUsage(\n usage: GoogleVertexXaiUsage,\n): LanguageModelV4Usage {\n if (usage == null) {\n return {\n inputTokens: {\n total: undefined,\n noCache: undefined,\n cacheRead: undefined,\n cacheWrite: undefined,\n },\n outputTokens: {\n total: undefined,\n text: undefined,\n reasoning: undefined,\n },\n raw: undefined,\n };\n }\n\n const promptTokens = usage.prompt_tokens ?? 0;\n const completionTokens = usage.completion_tokens ?? 0;\n const cacheReadTokens = usage.prompt_tokens_details?.cached_tokens ?? 0;\n const reasoningTokens =\n usage.completion_tokens_details?.reasoning_tokens ?? 0;\n\n return {\n inputTokens: {\n total: promptTokens,\n noCache: promptTokens - cacheReadTokens,\n cacheRead: cacheReadTokens,\n cacheWrite: undefined,\n },\n outputTokens: {\n total: completionTokens + reasoningTokens,\n text: completionTokens,\n reasoning: reasoningTokens,\n },\n raw: usage,\n };\n}\n\nfunction transformGoogleVertexXaiRequestBody(args: Record<string, any>) {\n const { reasoning_effort: _reasoningEffort, ...rest } = args;\n return rest;\n}\n\n/**\n * Create a Google Vertex AI xAI provider instance.\n * Uses the OpenAI-compatible Chat Completions API for Grok partner models.\n *\n * @see https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/grok\n */\nexport function createGoogleVertexXai(\n options: GoogleVertexXaiProviderSettings = {},\n): GoogleVertexXaiProvider {\n const loadLocation = () =>\n loadOptionalSetting({\n settingValue: options.location,\n environmentVariableName: 'GOOGLE_VERTEX_LOCATION',\n });\n\n const loadProject = () =>\n loadSetting({\n settingValue: options.project,\n settingName: 'project',\n environmentVariableName: 'GOOGLE_VERTEX_PROJECT',\n description: 'Google Vertex project',\n });\n\n const constructBaseURL = () => {\n const projectId = loadProject();\n const location = loadLocation() ?? 'global';\n\n return `https://aiplatform.googleapis.com/v1/projects/${projectId}/locations/${location}/endpoints/openapi`;\n };\n\n const loadBaseURL = () =>\n withoutTrailingSlash(options.baseURL ?? '') || constructBaseURL();\n\n let cachedProvider:\n | OpenAICompatibleProvider<GoogleVertexXaiModelId, string, string, string>\n | undefined;\n const getProvider = () =>\n (cachedProvider ??= createOpenAICompatible({\n name: 'googleVertex.xai',\n baseURL: loadBaseURL(),\n fetch: options.fetch,\n includeUsage: true,\n supportsStructuredOutputs: true,\n supportedUrls: () => ({\n 'image/*': [/^https?:\\/\\/.*$/],\n }),\n transformRequestBody: transformGoogleVertexXaiRequestBody,\n convertUsage: convertGoogleVertexXaiUsage,\n }));\n\n const createChatModel = (modelId: GoogleVertexXaiModelId) =>\n getProvider().languageModel(modelId);\n\n const provider = function (modelId: GoogleVertexXaiModelId) {\n if (new.target) {\n throw new Error(\n 'The Google Vertex xAI model function cannot be called with the new keyword.',\n );\n }\n\n return createChatModel(modelId);\n };\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = createChatModel;\n provider.chatModel = (modelId: GoogleVertexXaiModelId) =>\n getProvider().chatModel(modelId);\n provider.embeddingModel = (modelId: string): never => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string): never => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n return provider;\n}\n","import { resolve, type FetchFunction } from '@ai-sdk/provider-utils';\nimport type { GoogleAuthOptions } from 'google-auth-library';\nimport { createAuthTokenGenerator } from '../google-vertex-auth-google-auth-library';\nimport {\n createGoogleVertexXai as createGoogleVertexXaiOriginal,\n type GoogleVertexXaiProvider,\n type GoogleVertexXaiProviderSettings as GoogleVertexXaiProviderSettingsOriginal,\n} from './google-vertex-xai-provider';\nexport type { GoogleVertexXaiProvider };\n\nexport interface GoogleVertexXaiProviderSettings extends GoogleVertexXaiProviderSettingsOriginal {\n /**\n * Optional. The Authentication options provided by google-auth-library.\n * Complete list of authentication options is documented in the\n * GoogleAuthOptions interface:\n * https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts.\n */\n googleAuthOptions?: GoogleAuthOptions;\n}\n\n/**\n * Create a Google Vertex AI xAI provider instance for Node.js.\n * Uses the OpenAI-compatible Chat Completions API for Grok partner models.\n * Automatically handles Google Cloud authentication.\n *\n * @see https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/grok\n */\nexport function createGoogleVertexXai(\n options: GoogleVertexXaiProviderSettings = {},\n): GoogleVertexXaiProvider {\n const generateAuthToken = createAuthTokenGenerator(options.googleAuthOptions);\n\n const customFetch: FetchFunction = async (url, init) => {\n const token = await generateAuthToken();\n const resolvedHeaders = await resolve(options.headers);\n const authHeaders = {\n ...resolvedHeaders,\n Authorization: `Bearer ${token}`,\n };\n\n const fetchInit = {\n ...init,\n headers: {\n ...init?.headers,\n ...authHeaders,\n },\n };\n\n return (options.fetch ?? fetch)(url, fetchInit);\n };\n\n return createGoogleVertexXaiOriginal({\n ...options,\n fetch: customFetch,\n headers: undefined,\n });\n}\n\n/**\n * Default Google Vertex AI xAI provider instance for Node.js.\n */\nexport const googleVertexXai = createGoog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call` and `tool-result` parts for the executed c
|
|
|
488
488
|
|
|
489
489
|
#### URL Context
|
|
490
490
|
|
|
491
|
-
URL Context allows Gemini models to retrieve and analyze content from URLs. Supported models: Gemini 2.
|
|
491
|
+
URL Context allows Gemini models to retrieve and analyze content from URLs. Supported models: Gemini 2.0 and newer.
|
|
492
492
|
|
|
493
493
|
```ts
|
|
494
494
|
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
@@ -503,7 +503,7 @@ const result = await generateText({
|
|
|
503
503
|
|
|
504
504
|
#### Google Search
|
|
505
505
|
|
|
506
|
-
Google Search enables Gemini models to access real-time web information. Supported models: Gemini 2.
|
|
506
|
+
Google Search enables Gemini models to access real-time web information. Supported models: Gemini 2.0 and newer.
|
|
507
507
|
|
|
508
508
|
```ts
|
|
509
509
|
import { googleVertex } from '@ai-sdk/google-vertex';
|
|
@@ -535,7 +535,7 @@ const result = await generateText({
|
|
|
535
535
|
|
|
536
536
|
#### Google Maps
|
|
537
537
|
|
|
538
|
-
Google Maps grounding enables Gemini models to access Google Maps data for location-aware responses. Supported models: Gemini 2.
|
|
538
|
+
Google Maps grounding enables Gemini models to access Google Maps data for location-aware responses. Supported models: Gemini 2.0 and newer.
|
|
539
539
|
|
|
540
540
|
```ts
|
|
541
541
|
import { googleVertex } from '@ai-sdk/google-vertex';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/google-vertex",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.100",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -71,18 +71,18 @@
|
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@ai-sdk/anthropic": "4.0.
|
|
75
|
-
"@ai-sdk/google": "4.0.
|
|
76
|
-
"@ai-sdk/openai-compatible": "3.0.
|
|
77
|
-
"@ai-sdk/provider": "4.0.
|
|
78
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
74
|
+
"@ai-sdk/anthropic": "4.0.70",
|
|
75
|
+
"@ai-sdk/google": "4.0.87",
|
|
76
|
+
"@ai-sdk/openai-compatible": "3.0.61",
|
|
77
|
+
"@ai-sdk/provider": "4.0.21",
|
|
78
|
+
"@ai-sdk/provider-utils": "5.0.53",
|
|
79
79
|
"google-auth-library": "^10.6.2"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
|
-
"@ai-sdk/test-server": "2.0.
|
|
82
|
+
"@ai-sdk/test-server": "2.0.3",
|
|
83
83
|
"@types/node": "22.19.19",
|
|
84
84
|
"@vercel/ai-tsconfig": "0.0.0",
|
|
85
|
-
"
|
|
85
|
+
"tsdown": "^0.23.0",
|
|
86
86
|
"typescript": "5.8.3",
|
|
87
87
|
"zod": "3.25.76"
|
|
88
88
|
},
|
|
@@ -109,9 +109,9 @@
|
|
|
109
109
|
"ai"
|
|
110
110
|
],
|
|
111
111
|
"scripts": {
|
|
112
|
-
"build": "pnpm clean &&
|
|
113
|
-
"build:watch": "pnpm clean &&
|
|
114
|
-
"clean": "del-cli
|
|
112
|
+
"build": "pnpm clean && tsdown",
|
|
113
|
+
"build:watch": "pnpm clean && tsdown --watch",
|
|
114
|
+
"clean": "del-cli docs *.tsbuildinfo",
|
|
115
115
|
"type-check": "tsc --build",
|
|
116
116
|
"test": "pnpm test:node && pnpm test:edge",
|
|
117
117
|
"test:update": "pnpm test:node -u",
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
+
InvalidArgumentError,
|
|
2
3
|
NoSuchModelError,
|
|
3
4
|
type LanguageModelV4,
|
|
4
5
|
type ProviderV4,
|
|
5
6
|
} from '@ai-sdk/provider';
|
|
6
7
|
import {
|
|
8
|
+
isValidHostnamePart,
|
|
7
9
|
loadOptionalSetting,
|
|
8
10
|
withoutTrailingSlash,
|
|
9
11
|
type FetchFunction,
|
|
@@ -178,10 +180,21 @@ export function createGoogleVertexAnthropic(
|
|
|
178
180
|
options: GoogleVertexAnthropicProviderSettings = {},
|
|
179
181
|
): GoogleVertexAnthropicProvider {
|
|
180
182
|
const getBaseURL = () => {
|
|
183
|
+
const baseURL = withoutTrailingSlash(options.baseURL);
|
|
184
|
+
if (baseURL != null) {
|
|
185
|
+
return baseURL;
|
|
186
|
+
}
|
|
181
187
|
const location = loadOptionalSetting({
|
|
182
188
|
settingValue: options.location,
|
|
183
189
|
environmentVariableName: 'GOOGLE_VERTEX_LOCATION',
|
|
184
190
|
});
|
|
191
|
+
if (location != null && !isValidHostnamePart(location)) {
|
|
192
|
+
throw new InvalidArgumentError({
|
|
193
|
+
argument: 'location',
|
|
194
|
+
message:
|
|
195
|
+
'Invalid Google Vertex location. Expected a single DNS label (letters, digits, and hyphens). Use `baseURL` for custom endpoints.',
|
|
196
|
+
});
|
|
197
|
+
}
|
|
185
198
|
const project = loadOptionalSetting({
|
|
186
199
|
settingValue: options.project,
|
|
187
200
|
environmentVariableName: 'GOOGLE_VERTEX_PROJECT',
|
|
@@ -197,10 +210,7 @@ export function createGoogleVertexAnthropic(
|
|
|
197
210
|
}
|
|
198
211
|
};
|
|
199
212
|
|
|
200
|
-
return (
|
|
201
|
-
withoutTrailingSlash(options.baseURL) ??
|
|
202
|
-
`https://${getHost()}/v1/projects/${project}/locations/${location}/publishers/anthropic/models`
|
|
203
|
-
);
|
|
213
|
+
return `https://${getHost()}/v1/projects/${project}/locations/${location}/publishers/anthropic/models`;
|
|
204
214
|
};
|
|
205
215
|
|
|
206
216
|
const createChatModel = (modelId: GoogleVertexAnthropicModelId) =>
|
|
@@ -248,6 +248,7 @@ export class GoogleVertexGeminiTranscriptionModel implements TranscriptionModelV
|
|
|
248
248
|
},
|
|
249
249
|
...(response.usageMetadata != null
|
|
250
250
|
? {
|
|
251
|
+
usage: response.usageMetadata as JSONObject,
|
|
251
252
|
providerMetadata: {
|
|
252
253
|
google: { usageMetadata: response.usageMetadata as JSONObject },
|
|
253
254
|
},
|
|
@@ -446,7 +447,10 @@ function createVertexLiveTranscriptionStream({
|
|
|
446
447
|
language,
|
|
447
448
|
durationInSeconds: undefined,
|
|
448
449
|
...(usageMetadata != null
|
|
449
|
-
? {
|
|
450
|
+
? {
|
|
451
|
+
usage: usageMetadata,
|
|
452
|
+
providerMetadata: { google: { usageMetadata } },
|
|
453
|
+
}
|
|
450
454
|
: {}),
|
|
451
455
|
});
|
|
452
456
|
controller.close();
|