@ai-sdk/google-vertex 3.0.121 → 3.0.122
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 +6 -0
- package/README.md +63 -1
- package/dist/anthropic/edge/index.js +1 -1
- package/dist/anthropic/edge/index.mjs +1 -1
- package/dist/edge/index.js +1 -1
- package/dist/edge/index.mjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/maas/edge/index.d.mts +76 -0
- package/dist/maas/edge/index.d.ts +76 -0
- package/dist/maas/edge/index.js +214 -0
- package/dist/maas/edge/index.js.map +1 -0
- package/dist/maas/edge/index.mjs +195 -0
- package/dist/maas/edge/index.mjs.map +1 -0
- package/dist/maas/index.d.mts +60 -0
- package/dist/maas/index.d.ts +60 -0
- package/dist/maas/index.js +124 -0
- package/dist/maas/index.js.map +1 -0
- package/dist/maas/index.mjs +100 -0
- package/dist/maas/index.mjs.map +1 -0
- package/maas/edge.d.ts +1 -0
- package/maas/index.d.ts +1 -0
- package/package.json +18 -5
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The **[Google Vertex provider](https://ai-sdk.dev/providers/ai-sdk-providers/google-vertex)** for the [AI SDK](https://ai-sdk.dev/docs) contains language model support for the [Google Vertex AI](https://cloud.google.com/vertex-ai) APIs.
|
|
4
4
|
|
|
5
|
-
This library includes a Google Vertex Anthropic provider
|
|
5
|
+
This library includes a Google Vertex Anthropic provider and a Google Vertex MaaS provider. These providers closely follow the core Google Vertex library's usage patterns. See more in the [Google Vertex Anthropic Provider](#google-vertex-anthropic-provider) and [Google Vertex MaaS Provider](#google-vertex-maas-provider) sections below.
|
|
6
6
|
|
|
7
7
|
## Setup
|
|
8
8
|
|
|
@@ -216,6 +216,68 @@ const { text } = await generateText({
|
|
|
216
216
|
});
|
|
217
217
|
```
|
|
218
218
|
|
|
219
|
+
## Google Vertex MaaS Provider
|
|
220
|
+
|
|
221
|
+
The Google Vertex MaaS (Model as a Service) provider offers access to partner and open models hosted on Vertex AI through an OpenAI-compatible Chat Completions API. It is available for both Node.js and Edge runtimes.
|
|
222
|
+
|
|
223
|
+
### Node.js Runtime
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
import { vertexMaas } from '@ai-sdk/google-vertex/maas';
|
|
227
|
+
import { generateText } from 'ai';
|
|
228
|
+
|
|
229
|
+
const { text } = await generateText({
|
|
230
|
+
model: vertexMaas('deepseek-ai/deepseek-v3.2-maas'),
|
|
231
|
+
prompt: 'Write a vegetarian lasagna recipe.',
|
|
232
|
+
});
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Edge Runtime
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
import { vertexMaas } from '@ai-sdk/google-vertex/maas/edge';
|
|
239
|
+
import { generateText } from 'ai';
|
|
240
|
+
|
|
241
|
+
const { text } = await generateText({
|
|
242
|
+
model: vertexMaas('deepseek-ai/deepseek-v3.2-maas'),
|
|
243
|
+
prompt: 'Write a vegetarian lasagna recipe.',
|
|
244
|
+
});
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Google Vertex MaaS Provider Custom Configuration
|
|
248
|
+
|
|
249
|
+
```ts
|
|
250
|
+
import { createVertexMaas } from '@ai-sdk/google-vertex/maas';
|
|
251
|
+
import { generateText } from 'ai';
|
|
252
|
+
|
|
253
|
+
const customProvider = createVertexMaas({
|
|
254
|
+
project: 'your-project-id',
|
|
255
|
+
location: 'us-east5',
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
const { text } = await generateText({
|
|
259
|
+
model: customProvider('deepseek-ai/deepseek-v3.2-maas'),
|
|
260
|
+
prompt: 'Write a vegetarian lasagna recipe.',
|
|
261
|
+
});
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
And for the Edge runtime:
|
|
265
|
+
|
|
266
|
+
```ts
|
|
267
|
+
import { createVertexMaas } from '@ai-sdk/google-vertex/maas/edge';
|
|
268
|
+
import { generateText } from 'ai';
|
|
269
|
+
|
|
270
|
+
const customProvider = createVertexMaas({
|
|
271
|
+
project: 'your-project-id',
|
|
272
|
+
location: 'us-east5',
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
const { text } = await generateText({
|
|
276
|
+
model: customProvider('deepseek-ai/deepseek-v3.2-maas'),
|
|
277
|
+
prompt: 'Write a vegetarian lasagna recipe.',
|
|
278
|
+
});
|
|
279
|
+
```
|
|
280
|
+
|
|
219
281
|
## Documentation
|
|
220
282
|
|
|
221
283
|
Please check out the **[Google Vertex provider](https://ai-sdk.dev/providers/ai-sdk-providers/google-vertex)** for more information.
|
|
@@ -32,7 +32,7 @@ var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
|
32
32
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
33
33
|
|
|
34
34
|
// src/version.ts
|
|
35
|
-
var VERSION = true ? "3.0.
|
|
35
|
+
var VERSION = true ? "3.0.122" : "0.0.0-test";
|
|
36
36
|
|
|
37
37
|
// src/edge/google-vertex-auth-edge.ts
|
|
38
38
|
var loadCredentials = async () => {
|
package/dist/edge/index.js
CHANGED
|
@@ -33,7 +33,7 @@ var import_internal2 = require("@ai-sdk/google/internal");
|
|
|
33
33
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
34
34
|
|
|
35
35
|
// src/version.ts
|
|
36
|
-
var VERSION = true ? "3.0.
|
|
36
|
+
var VERSION = true ? "3.0.122" : "0.0.0-test";
|
|
37
37
|
|
|
38
38
|
// src/google-vertex-embedding-model.ts
|
|
39
39
|
var import_provider = require("@ai-sdk/provider");
|
package/dist/edge/index.mjs
CHANGED
package/dist/index.js
CHANGED
|
@@ -55,7 +55,7 @@ var import_internal2 = require("@ai-sdk/google/internal");
|
|
|
55
55
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
56
56
|
|
|
57
57
|
// src/version.ts
|
|
58
|
-
var VERSION = true ? "3.0.
|
|
58
|
+
var VERSION = true ? "3.0.122" : "0.0.0-test";
|
|
59
59
|
|
|
60
60
|
// src/google-vertex-embedding-model.ts
|
|
61
61
|
var import_provider = require("@ai-sdk/provider");
|
package/dist/index.mjs
CHANGED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { OpenAICompatibleProvider } from '@ai-sdk/openai-compatible';
|
|
2
|
+
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
+
|
|
4
|
+
interface GoogleCredentials {
|
|
5
|
+
/**
|
|
6
|
+
* The client email for the Google Cloud service account. Defaults to the
|
|
7
|
+
* value of the `GOOGLE_CLIENT_EMAIL` environment variable.
|
|
8
|
+
*/
|
|
9
|
+
clientEmail: string;
|
|
10
|
+
/**
|
|
11
|
+
* The private key for the Google Cloud service account. Defaults to the
|
|
12
|
+
* value of the `GOOGLE_PRIVATE_KEY` environment variable.
|
|
13
|
+
*/
|
|
14
|
+
privateKey: string;
|
|
15
|
+
/**
|
|
16
|
+
* Optional. The private key ID for the Google Cloud service account. Defaults
|
|
17
|
+
* to the value of the `GOOGLE_PRIVATE_KEY_ID` environment variable.
|
|
18
|
+
*/
|
|
19
|
+
privateKeyId?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type GoogleVertexMaasModelId = 'deepseek-ai/deepseek-r1-0528-maas' | 'deepseek-ai/deepseek-v3.1-maas' | 'deepseek-ai/deepseek-v3.2-maas' | 'openai/gpt-oss-120b-maas' | 'openai/gpt-oss-20b-maas' | 'meta/llama-4-maverick-17b-128e-instruct-maas' | 'meta/llama-4-scout-17b-16e-instruct-maas' | 'minimax/minimax-m2-maas' | 'qwen/qwen3-coder-480b-a35b-instruct-maas' | 'qwen/qwen3-next-80b-a3b-instruct-maas' | 'qwen/qwen3-next-80b-a3b-thinking-maas' | 'moonshotai/kimi-k2-thinking-maas' | (string & {});
|
|
23
|
+
|
|
24
|
+
interface GoogleVertexMaasProvider extends OpenAICompatibleProvider<GoogleVertexMaasModelId, string, string, string> {
|
|
25
|
+
}
|
|
26
|
+
interface GoogleVertexMaasProviderSettings$1 {
|
|
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;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface GoogleVertexMaasProviderSettings extends GoogleVertexMaasProviderSettings$1 {
|
|
56
|
+
/**
|
|
57
|
+
* Optional. The Google credentials for the Google Cloud service account. If
|
|
58
|
+
* not provided, the Google Vertex provider will use environment variables to
|
|
59
|
+
* load the credentials.
|
|
60
|
+
*/
|
|
61
|
+
googleCredentials?: GoogleCredentials;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create a Google Vertex AI MaaS (Model as a Service) provider instance for Edge runtimes.
|
|
65
|
+
* Uses the OpenAI-compatible Chat Completions API for partner and open models.
|
|
66
|
+
* Automatically handles Google Cloud authentication.
|
|
67
|
+
*
|
|
68
|
+
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models
|
|
69
|
+
*/
|
|
70
|
+
declare function createVertexMaas(options?: GoogleVertexMaasProviderSettings): GoogleVertexMaasProvider;
|
|
71
|
+
/**
|
|
72
|
+
* Default Google Vertex AI MaaS provider instance for Edge runtimes.
|
|
73
|
+
*/
|
|
74
|
+
declare const vertexMaas: GoogleVertexMaasProvider;
|
|
75
|
+
|
|
76
|
+
export { type GoogleVertexMaasModelId, type GoogleVertexMaasProvider, type GoogleVertexMaasProviderSettings, createVertexMaas, vertexMaas };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { OpenAICompatibleProvider } from '@ai-sdk/openai-compatible';
|
|
2
|
+
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
+
|
|
4
|
+
interface GoogleCredentials {
|
|
5
|
+
/**
|
|
6
|
+
* The client email for the Google Cloud service account. Defaults to the
|
|
7
|
+
* value of the `GOOGLE_CLIENT_EMAIL` environment variable.
|
|
8
|
+
*/
|
|
9
|
+
clientEmail: string;
|
|
10
|
+
/**
|
|
11
|
+
* The private key for the Google Cloud service account. Defaults to the
|
|
12
|
+
* value of the `GOOGLE_PRIVATE_KEY` environment variable.
|
|
13
|
+
*/
|
|
14
|
+
privateKey: string;
|
|
15
|
+
/**
|
|
16
|
+
* Optional. The private key ID for the Google Cloud service account. Defaults
|
|
17
|
+
* to the value of the `GOOGLE_PRIVATE_KEY_ID` environment variable.
|
|
18
|
+
*/
|
|
19
|
+
privateKeyId?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type GoogleVertexMaasModelId = 'deepseek-ai/deepseek-r1-0528-maas' | 'deepseek-ai/deepseek-v3.1-maas' | 'deepseek-ai/deepseek-v3.2-maas' | 'openai/gpt-oss-120b-maas' | 'openai/gpt-oss-20b-maas' | 'meta/llama-4-maverick-17b-128e-instruct-maas' | 'meta/llama-4-scout-17b-16e-instruct-maas' | 'minimax/minimax-m2-maas' | 'qwen/qwen3-coder-480b-a35b-instruct-maas' | 'qwen/qwen3-next-80b-a3b-instruct-maas' | 'qwen/qwen3-next-80b-a3b-thinking-maas' | 'moonshotai/kimi-k2-thinking-maas' | (string & {});
|
|
23
|
+
|
|
24
|
+
interface GoogleVertexMaasProvider extends OpenAICompatibleProvider<GoogleVertexMaasModelId, string, string, string> {
|
|
25
|
+
}
|
|
26
|
+
interface GoogleVertexMaasProviderSettings$1 {
|
|
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;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface GoogleVertexMaasProviderSettings extends GoogleVertexMaasProviderSettings$1 {
|
|
56
|
+
/**
|
|
57
|
+
* Optional. The Google credentials for the Google Cloud service account. If
|
|
58
|
+
* not provided, the Google Vertex provider will use environment variables to
|
|
59
|
+
* load the credentials.
|
|
60
|
+
*/
|
|
61
|
+
googleCredentials?: GoogleCredentials;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create a Google Vertex AI MaaS (Model as a Service) provider instance for Edge runtimes.
|
|
65
|
+
* Uses the OpenAI-compatible Chat Completions API for partner and open models.
|
|
66
|
+
* Automatically handles Google Cloud authentication.
|
|
67
|
+
*
|
|
68
|
+
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models
|
|
69
|
+
*/
|
|
70
|
+
declare function createVertexMaas(options?: GoogleVertexMaasProviderSettings): GoogleVertexMaasProvider;
|
|
71
|
+
/**
|
|
72
|
+
* Default Google Vertex AI MaaS provider instance for Edge runtimes.
|
|
73
|
+
*/
|
|
74
|
+
declare const vertexMaas: GoogleVertexMaasProvider;
|
|
75
|
+
|
|
76
|
+
export { type GoogleVertexMaasModelId, type GoogleVertexMaasProvider, type GoogleVertexMaasProviderSettings, createVertexMaas, vertexMaas };
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/maas/edge/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
createVertexMaas: () => createVertexMaas2,
|
|
24
|
+
vertexMaas: () => vertexMaas
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/maas/edge/google-vertex-maas-provider-edge.ts
|
|
29
|
+
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
30
|
+
|
|
31
|
+
// src/edge/google-vertex-auth-edge.ts
|
|
32
|
+
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
33
|
+
|
|
34
|
+
// src/version.ts
|
|
35
|
+
var VERSION = true ? "3.0.122" : "0.0.0-test";
|
|
36
|
+
|
|
37
|
+
// src/edge/google-vertex-auth-edge.ts
|
|
38
|
+
var loadCredentials = async () => {
|
|
39
|
+
try {
|
|
40
|
+
return {
|
|
41
|
+
clientEmail: (0, import_provider_utils.loadSetting)({
|
|
42
|
+
settingValue: void 0,
|
|
43
|
+
settingName: "clientEmail",
|
|
44
|
+
environmentVariableName: "GOOGLE_CLIENT_EMAIL",
|
|
45
|
+
description: "Google client email"
|
|
46
|
+
}),
|
|
47
|
+
privateKey: (0, import_provider_utils.loadSetting)({
|
|
48
|
+
settingValue: void 0,
|
|
49
|
+
settingName: "privateKey",
|
|
50
|
+
environmentVariableName: "GOOGLE_PRIVATE_KEY",
|
|
51
|
+
description: "Google private key"
|
|
52
|
+
}),
|
|
53
|
+
privateKeyId: (0, import_provider_utils.loadOptionalSetting)({
|
|
54
|
+
settingValue: void 0,
|
|
55
|
+
environmentVariableName: "GOOGLE_PRIVATE_KEY_ID"
|
|
56
|
+
})
|
|
57
|
+
};
|
|
58
|
+
} catch (error) {
|
|
59
|
+
throw new Error(`Failed to load Google credentials: ${error.message}`);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var base64url = (str) => {
|
|
63
|
+
return btoa(str).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
64
|
+
};
|
|
65
|
+
var importPrivateKey = async (pemKey) => {
|
|
66
|
+
const pemHeader = "-----BEGIN PRIVATE KEY-----";
|
|
67
|
+
const pemFooter = "-----END PRIVATE KEY-----";
|
|
68
|
+
const pemContents = pemKey.replace(pemHeader, "").replace(pemFooter, "").replace(/\s/g, "");
|
|
69
|
+
const binaryString = atob(pemContents);
|
|
70
|
+
const binaryData = new Uint8Array(binaryString.length);
|
|
71
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
72
|
+
binaryData[i] = binaryString.charCodeAt(i);
|
|
73
|
+
}
|
|
74
|
+
return await crypto.subtle.importKey(
|
|
75
|
+
"pkcs8",
|
|
76
|
+
binaryData,
|
|
77
|
+
{ name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" },
|
|
78
|
+
true,
|
|
79
|
+
["sign"]
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
var buildJwt = async (credentials) => {
|
|
83
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
84
|
+
const header = {
|
|
85
|
+
alg: "RS256",
|
|
86
|
+
typ: "JWT"
|
|
87
|
+
};
|
|
88
|
+
if (credentials.privateKeyId) {
|
|
89
|
+
header.kid = credentials.privateKeyId;
|
|
90
|
+
}
|
|
91
|
+
const payload = {
|
|
92
|
+
iss: credentials.clientEmail,
|
|
93
|
+
scope: "https://www.googleapis.com/auth/cloud-platform",
|
|
94
|
+
aud: "https://oauth2.googleapis.com/token",
|
|
95
|
+
exp: now + 3600,
|
|
96
|
+
iat: now
|
|
97
|
+
};
|
|
98
|
+
const privateKey = await importPrivateKey(credentials.privateKey);
|
|
99
|
+
const signingInput = `${base64url(JSON.stringify(header))}.${base64url(
|
|
100
|
+
JSON.stringify(payload)
|
|
101
|
+
)}`;
|
|
102
|
+
const encoder = new TextEncoder();
|
|
103
|
+
const data = encoder.encode(signingInput);
|
|
104
|
+
const signature = await crypto.subtle.sign(
|
|
105
|
+
"RSASSA-PKCS1-v1_5",
|
|
106
|
+
privateKey,
|
|
107
|
+
data
|
|
108
|
+
);
|
|
109
|
+
const signatureBase64 = base64url(
|
|
110
|
+
String.fromCharCode(...new Uint8Array(signature))
|
|
111
|
+
);
|
|
112
|
+
return `${base64url(JSON.stringify(header))}.${base64url(
|
|
113
|
+
JSON.stringify(payload)
|
|
114
|
+
)}.${signatureBase64}`;
|
|
115
|
+
};
|
|
116
|
+
async function generateAuthToken(credentials) {
|
|
117
|
+
try {
|
|
118
|
+
const creds = credentials || await loadCredentials();
|
|
119
|
+
const jwt = await buildJwt(creds);
|
|
120
|
+
const response = await fetch("https://oauth2.googleapis.com/token", {
|
|
121
|
+
method: "POST",
|
|
122
|
+
headers: (0, import_provider_utils.withUserAgentSuffix)(
|
|
123
|
+
{ "Content-Type": "application/x-www-form-urlencoded" },
|
|
124
|
+
`ai-sdk/google-vertex/${VERSION}`,
|
|
125
|
+
(0, import_provider_utils.getRuntimeEnvironmentUserAgent)()
|
|
126
|
+
),
|
|
127
|
+
body: new URLSearchParams({
|
|
128
|
+
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
|
|
129
|
+
assertion: jwt
|
|
130
|
+
})
|
|
131
|
+
});
|
|
132
|
+
if (!response.ok) {
|
|
133
|
+
throw new Error(`Token request failed: ${response.statusText}`);
|
|
134
|
+
}
|
|
135
|
+
const data = await response.json();
|
|
136
|
+
return data.access_token;
|
|
137
|
+
} catch (error) {
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/maas/google-vertex-maas-provider.ts
|
|
143
|
+
var import_openai_compatible = require("@ai-sdk/openai-compatible");
|
|
144
|
+
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
145
|
+
function createVertexMaas(options = {}) {
|
|
146
|
+
const loadLocation = () => (0, import_provider_utils2.loadOptionalSetting)({
|
|
147
|
+
settingValue: options.location,
|
|
148
|
+
environmentVariableName: "GOOGLE_VERTEX_LOCATION"
|
|
149
|
+
});
|
|
150
|
+
const loadProject = () => (0, import_provider_utils2.loadSetting)({
|
|
151
|
+
settingValue: options.project,
|
|
152
|
+
settingName: "project",
|
|
153
|
+
environmentVariableName: "GOOGLE_VERTEX_PROJECT",
|
|
154
|
+
description: "Google Vertex project"
|
|
155
|
+
});
|
|
156
|
+
const constructBaseURL = () => {
|
|
157
|
+
var _a;
|
|
158
|
+
const projectId = loadProject();
|
|
159
|
+
const location = (_a = loadLocation()) != null ? _a : "global";
|
|
160
|
+
return `https://aiplatform.googleapis.com/v1/projects/${projectId}/locations/${location}/endpoints/openapi`;
|
|
161
|
+
};
|
|
162
|
+
const loadBaseURL = () => {
|
|
163
|
+
var _a;
|
|
164
|
+
return (0, import_provider_utils2.withoutTrailingSlash)((_a = options.baseURL) != null ? _a : "") || constructBaseURL();
|
|
165
|
+
};
|
|
166
|
+
let cachedProvider;
|
|
167
|
+
const getProvider = () => cachedProvider != null ? cachedProvider : cachedProvider = (0, import_openai_compatible.createOpenAICompatible)({
|
|
168
|
+
name: "vertex.maas",
|
|
169
|
+
baseURL: loadBaseURL(),
|
|
170
|
+
fetch: options.fetch
|
|
171
|
+
});
|
|
172
|
+
const provider = (modelId) => getProvider()(modelId);
|
|
173
|
+
provider.specificationVersion = "v2";
|
|
174
|
+
provider.languageModel = (modelId) => getProvider().languageModel(modelId);
|
|
175
|
+
provider.chatModel = (modelId) => getProvider().chatModel(modelId);
|
|
176
|
+
provider.completionModel = (modelId) => getProvider().completionModel(modelId);
|
|
177
|
+
provider.textEmbeddingModel = (modelId) => getProvider().textEmbeddingModel(modelId);
|
|
178
|
+
provider.imageModel = (modelId) => getProvider().imageModel(modelId);
|
|
179
|
+
return provider;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// src/maas/edge/google-vertex-maas-provider-edge.ts
|
|
183
|
+
function createVertexMaas2(options = {}) {
|
|
184
|
+
const customFetch = async (url, init) => {
|
|
185
|
+
var _a;
|
|
186
|
+
const token = await generateAuthToken(options.googleCredentials);
|
|
187
|
+
const resolvedHeaders = await (0, import_provider_utils3.resolve)(options.headers);
|
|
188
|
+
const authHeaders = {
|
|
189
|
+
...resolvedHeaders,
|
|
190
|
+
Authorization: `Bearer ${token}`
|
|
191
|
+
};
|
|
192
|
+
const fetchInit = {
|
|
193
|
+
...init,
|
|
194
|
+
headers: {
|
|
195
|
+
...init == null ? void 0 : init.headers,
|
|
196
|
+
...authHeaders
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
return ((_a = options.fetch) != null ? _a : fetch)(url, fetchInit);
|
|
200
|
+
};
|
|
201
|
+
return createVertexMaas({
|
|
202
|
+
...options,
|
|
203
|
+
fetch: customFetch,
|
|
204
|
+
headers: void 0
|
|
205
|
+
// Don't pass headers, we handle them in fetch
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
var vertexMaas = createVertexMaas2();
|
|
209
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
210
|
+
0 && (module.exports = {
|
|
211
|
+
createVertexMaas,
|
|
212
|
+
vertexMaas
|
|
213
|
+
});
|
|
214
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/maas/edge/index.ts","../../../src/maas/edge/google-vertex-maas-provider-edge.ts","../../../src/edge/google-vertex-auth-edge.ts","../../../src/version.ts","../../../src/maas/google-vertex-maas-provider.ts"],"sourcesContent":["export {\n createVertexMaas,\n vertexMaas,\n} from './google-vertex-maas-provider-edge';\nexport type {\n GoogleVertexMaasProvider,\n GoogleVertexMaasProviderSettings,\n} from './google-vertex-maas-provider-edge';\nexport type { GoogleVertexMaasModelId } from '../google-vertex-maas-options';\n","import { FetchFunction, resolve } from '@ai-sdk/provider-utils';\nimport {\n generateAuthToken,\n GoogleCredentials,\n} from '../../edge/google-vertex-auth-edge';\nimport {\n createVertexMaas as createVertexMaasOriginal,\n GoogleVertexMaasProvider,\n GoogleVertexMaasProviderSettings as GoogleVertexMaasProviderSettingsOriginal,\n} from '../google-vertex-maas-provider';\n\nexport type { GoogleVertexMaasProvider };\n\nexport interface GoogleVertexMaasProviderSettings extends GoogleVertexMaasProviderSettingsOriginal {\n /**\n * Optional. The Google credentials for the Google Cloud service account. If\n * not provided, the Google Vertex provider will use environment variables to\n * load the credentials.\n */\n googleCredentials?: GoogleCredentials;\n}\n\n/**\n * Create a Google Vertex AI MaaS (Model as a Service) provider instance for Edge runtimes.\n * Uses the OpenAI-compatible Chat Completions API for partner and open models.\n * Automatically handles Google Cloud authentication.\n *\n * @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models\n */\nexport function createVertexMaas(\n options: GoogleVertexMaasProviderSettings = {},\n): GoogleVertexMaasProvider {\n // Create a custom fetch wrapper that adds auth headers\n const customFetch: FetchFunction = async (url, init) => {\n const token = await generateAuthToken(options.googleCredentials);\n const resolvedHeaders = await resolve(options.headers);\n const authHeaders = {\n ...resolvedHeaders,\n Authorization: `Bearer ${token}`,\n };\n\n // Merge auth headers with existing headers from init\n const fetchInit = {\n ...init,\n headers: {\n ...init?.headers,\n ...authHeaders,\n },\n };\n\n // Call the original fetch or user's custom fetch\n return (options.fetch ?? fetch)(url, fetchInit);\n };\n\n return createVertexMaasOriginal({\n ...options,\n fetch: customFetch,\n headers: undefined, // Don't pass headers, we handle them in fetch\n });\n}\n\n/**\n * Default Google Vertex AI MaaS provider instance for Edge runtimes.\n */\nexport const vertexMaas = createVertexMaas();\n","import {\n loadOptionalSetting,\n loadSetting,\n withUserAgentSuffix,\n getRuntimeEnvironmentUserAgent,\n} from '@ai-sdk/provider-utils';\nimport { VERSION } from '../version';\n\nexport interface GoogleCredentials {\n /**\n * The client email for the Google Cloud service account. Defaults to the\n * value of the `GOOGLE_CLIENT_EMAIL` environment variable.\n */\n clientEmail: string;\n\n /**\n * The private key for the Google Cloud service account. Defaults to the\n * value of the `GOOGLE_PRIVATE_KEY` environment variable.\n */\n privateKey: string;\n\n /**\n * Optional. The private key ID for the Google Cloud service account. Defaults\n * to the value of the `GOOGLE_PRIVATE_KEY_ID` environment variable.\n */\n privateKeyId?: string;\n}\n\nconst loadCredentials = async (): Promise<GoogleCredentials> => {\n try {\n return {\n clientEmail: loadSetting({\n settingValue: undefined,\n settingName: 'clientEmail',\n environmentVariableName: 'GOOGLE_CLIENT_EMAIL',\n description: 'Google client email',\n }),\n privateKey: loadSetting({\n settingValue: undefined,\n settingName: 'privateKey',\n environmentVariableName: 'GOOGLE_PRIVATE_KEY',\n description: 'Google private key',\n }),\n privateKeyId: loadOptionalSetting({\n settingValue: undefined,\n environmentVariableName: 'GOOGLE_PRIVATE_KEY_ID',\n }),\n };\n } catch (error: any) {\n throw new Error(`Failed to load Google credentials: ${error.message}`);\n }\n};\n\n// Convert a string to base64url\nconst base64url = (str: string) => {\n return btoa(str).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=/g, '');\n};\nconst importPrivateKey = async (pemKey: string) => {\n const pemHeader = '-----BEGIN PRIVATE KEY-----';\n const pemFooter = '-----END PRIVATE KEY-----';\n\n // Remove header, footer, and any whitespace/newlines\n const pemContents = pemKey\n .replace(pemHeader, '')\n .replace(pemFooter, '')\n .replace(/\\s/g, '');\n\n // Decode base64 to binary\n const binaryString = atob(pemContents);\n\n // Convert binary string to Uint8Array\n const binaryData = new Uint8Array(binaryString.length);\n for (let i = 0; i < binaryString.length; i++) {\n binaryData[i] = binaryString.charCodeAt(i);\n }\n\n return await crypto.subtle.importKey(\n 'pkcs8',\n binaryData,\n { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-256' },\n true,\n ['sign'],\n );\n};\n\nconst buildJwt = async (credentials: GoogleCredentials) => {\n const now = Math.floor(Date.now() / 1000);\n\n // Only include kid in header if privateKeyId is provided\n const header: { alg: string; typ: string; kid?: string } = {\n alg: 'RS256',\n typ: 'JWT',\n };\n\n if (credentials.privateKeyId) {\n header.kid = credentials.privateKeyId;\n }\n\n const payload = {\n iss: credentials.clientEmail,\n scope: 'https://www.googleapis.com/auth/cloud-platform',\n aud: 'https://oauth2.googleapis.com/token',\n exp: now + 3600,\n iat: now,\n };\n\n const privateKey = await importPrivateKey(credentials.privateKey);\n\n const signingInput = `${base64url(JSON.stringify(header))}.${base64url(\n JSON.stringify(payload),\n )}`;\n const encoder = new TextEncoder();\n const data = encoder.encode(signingInput);\n\n const signature = await crypto.subtle.sign(\n 'RSASSA-PKCS1-v1_5',\n privateKey,\n data,\n );\n\n const signatureBase64 = base64url(\n String.fromCharCode(...new Uint8Array(signature)),\n );\n\n return `${base64url(JSON.stringify(header))}.${base64url(\n JSON.stringify(payload),\n )}.${signatureBase64}`;\n};\n\n/**\n * Generate an authentication token for Google Vertex AI in a manner compatible\n * with the Edge runtime.\n */\nexport async function generateAuthToken(credentials?: GoogleCredentials) {\n try {\n const creds = credentials || (await loadCredentials());\n const jwt = await buildJwt(creds);\n\n const response = await fetch('https://oauth2.googleapis.com/token', {\n method: 'POST',\n headers: withUserAgentSuffix(\n { 'Content-Type': 'application/x-www-form-urlencoded' },\n `ai-sdk/google-vertex/${VERSION}`,\n getRuntimeEnvironmentUserAgent(),\n ),\n body: new URLSearchParams({\n grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',\n assertion: jwt,\n }),\n });\n\n if (!response.ok) {\n throw new Error(`Token request failed: ${response.statusText}`);\n }\n\n const data = await response.json();\n return data.access_token;\n } catch (error) {\n throw error;\n }\n}\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n","import { createOpenAICompatible } from '@ai-sdk/openai-compatible';\nimport type { OpenAICompatibleProvider } from '@ai-sdk/openai-compatible';\nimport {\n FetchFunction,\n loadOptionalSetting,\n loadSetting,\n Resolvable,\n withoutTrailingSlash,\n} from '@ai-sdk/provider-utils';\nimport type { GoogleVertexMaasModelId } from './google-vertex-maas-options';\n\nexport interface GoogleVertexMaasProvider extends OpenAICompatibleProvider<\n GoogleVertexMaasModelId,\n string,\n string,\n string\n> {}\n\nexport interface GoogleVertexMaasProviderSettings {\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\n/**\n * Create a Google Vertex AI MaaS (Model as a Service) provider instance.\n * Uses the OpenAI-compatible Chat Completions API for partner and open models.\n *\n * @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models\n */\nexport function createVertexMaas(\n options: GoogleVertexMaasProviderSettings = {},\n): GoogleVertexMaasProvider {\n // Lazy-load settings to support loading from environment variables at runtime\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 // Construct base URL: https://aiplatform.googleapis.com/v1/projects/{project}/locations/{location}/endpoints/openapi\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: GoogleVertexMaasProvider | undefined;\n const getProvider = () =>\n (cachedProvider ??= createOpenAICompatible({\n name: 'vertex.maas',\n baseURL: loadBaseURL(),\n fetch: options.fetch,\n }));\n\n const provider = (modelId: GoogleVertexMaasModelId) => getProvider()(modelId);\n\n provider.specificationVersion = 'v2' as const;\n provider.languageModel = (modelId: GoogleVertexMaasModelId) =>\n getProvider().languageModel(modelId);\n provider.chatModel = (modelId: GoogleVertexMaasModelId) =>\n getProvider().chatModel(modelId);\n provider.completionModel = (modelId: string) =>\n getProvider().completionModel(modelId);\n provider.textEmbeddingModel = (modelId: string) =>\n getProvider().textEmbeddingModel(modelId);\n provider.imageModel = (modelId: string) => getProvider().imageModel(modelId);\n\n return provider as GoogleVertexMaasProvider;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAAA;AAAA,EAAA;AAAA;AAAA;;;ACAA,IAAAC,yBAAuC;;;ACAvC,4BAKO;;;ACHA,IAAM,UACX,OACI,YACA;;;ADuBN,IAAM,kBAAkB,YAAwC;AAC9D,MAAI;AACF,WAAO;AAAA,MACL,iBAAa,mCAAY;AAAA,QACvB,cAAc;AAAA,QACd,aAAa;AAAA,QACb,yBAAyB;AAAA,QACzB,aAAa;AAAA,MACf,CAAC;AAAA,MACD,gBAAY,mCAAY;AAAA,QACtB,cAAc;AAAA,QACd,aAAa;AAAA,QACb,yBAAyB;AAAA,QACzB,aAAa;AAAA,MACf,CAAC;AAAA,MACD,kBAAc,2CAAoB;AAAA,QAChC,cAAc;AAAA,QACd,yBAAyB;AAAA,MAC3B,CAAC;AAAA,IACH;AAAA,EACF,SAAS,OAAY;AACnB,UAAM,IAAI,MAAM,sCAAsC,MAAM,OAAO,EAAE;AAAA,EACvE;AACF;AAGA,IAAM,YAAY,CAAC,QAAgB;AACjC,SAAO,KAAK,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,MAAM,EAA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R,YAAmB,EAAE,KAAK,iBAAiB;AAAA;AAElE,MAAI;AACJ,QAAM,cAAc,MACjB,+DAAmB,iDAAuB;AAAA,IACzC,MAAM;AAAA,IACN,SAAS,YAAY;AAAA,IACrB,OAAO,QAAQ;AAAA,EACjB,CAAC;AAEH,QAAM,WAAW,CAAC,YAAqC,YAAY,EAAE,OAAO;AAE5E,WAAS,uBAAuB;AAChC,WAAS,gBAAgB,CAAC,YACxB,YAAY,EAAE,cAAc,OAAO;AACrC,WAAS,YAAY,CAAC,YACpB,YAAY,EAAE,UAAU,OAAO;AACjC,WAAS,kBAAkB,CAAC,YAC1B,YAAY,EAAE,gBAAgB,OAAO;AACvC,WAAS,qBAAqB,CAAC,YAC7B,YAAY,EAAE,mBAAmB,OAAO;AAC1C,WAAS,aAAa,CAAC,YAAoB,YAAY,EAAE,WAAW,OAAO;AAE3E,SAAO;AACT;;;AH/EO,SAASC,kBACd,UAA4C,CAAC,GACnB;AAE1B,QAAM,cAA6B,OAAO,KAAK,SAAS;AAjC1D;AAkCI,UAAM,QAAQ,MAAM,kBAAkB,QAAQ,iBAAiB;AAC/D,UAAM,kBAAkB,UAAM,gCAAQ,QAAQ,OAAO;AACrD,UAAM,cAAc;AAAA,MAClB,GAAG;AAAA,MACH,eAAe,UAAU,KAAK;AAAA,IAChC;AAGA,UAAM,YAAY;AAAA,MAChB,GAAG;AAAA,MACH,SAAS;AAAA,QACP,GAAG,6BAAM;AAAA,QACT,GAAG;AAAA,MACL;AAAA,IACF;AAGA,aAAQ,aAAQ,UAAR,YAAiB,OAAO,KAAK,SAAS;AAAA,EAChD;AAEA,SAAO,iBAAyB;AAAA,IAC9B,GAAG;AAAA,IACH,OAAO;AAAA,IACP,SAAS;AAAA;AAAA,EACX,CAAC;AACH;AAKO,IAAM,aAAaA,kBAAiB;","names":["createVertexMaas","import_provider_utils","import_provider_utils","createVertexMaas"]}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// src/maas/edge/google-vertex-maas-provider-edge.ts
|
|
2
|
+
import { resolve } from "@ai-sdk/provider-utils";
|
|
3
|
+
|
|
4
|
+
// src/edge/google-vertex-auth-edge.ts
|
|
5
|
+
import {
|
|
6
|
+
loadOptionalSetting,
|
|
7
|
+
loadSetting,
|
|
8
|
+
withUserAgentSuffix,
|
|
9
|
+
getRuntimeEnvironmentUserAgent
|
|
10
|
+
} from "@ai-sdk/provider-utils";
|
|
11
|
+
|
|
12
|
+
// src/version.ts
|
|
13
|
+
var VERSION = true ? "3.0.122" : "0.0.0-test";
|
|
14
|
+
|
|
15
|
+
// src/edge/google-vertex-auth-edge.ts
|
|
16
|
+
var loadCredentials = async () => {
|
|
17
|
+
try {
|
|
18
|
+
return {
|
|
19
|
+
clientEmail: loadSetting({
|
|
20
|
+
settingValue: void 0,
|
|
21
|
+
settingName: "clientEmail",
|
|
22
|
+
environmentVariableName: "GOOGLE_CLIENT_EMAIL",
|
|
23
|
+
description: "Google client email"
|
|
24
|
+
}),
|
|
25
|
+
privateKey: loadSetting({
|
|
26
|
+
settingValue: void 0,
|
|
27
|
+
settingName: "privateKey",
|
|
28
|
+
environmentVariableName: "GOOGLE_PRIVATE_KEY",
|
|
29
|
+
description: "Google private key"
|
|
30
|
+
}),
|
|
31
|
+
privateKeyId: loadOptionalSetting({
|
|
32
|
+
settingValue: void 0,
|
|
33
|
+
environmentVariableName: "GOOGLE_PRIVATE_KEY_ID"
|
|
34
|
+
})
|
|
35
|
+
};
|
|
36
|
+
} catch (error) {
|
|
37
|
+
throw new Error(`Failed to load Google credentials: ${error.message}`);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var base64url = (str) => {
|
|
41
|
+
return btoa(str).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
42
|
+
};
|
|
43
|
+
var importPrivateKey = async (pemKey) => {
|
|
44
|
+
const pemHeader = "-----BEGIN PRIVATE KEY-----";
|
|
45
|
+
const pemFooter = "-----END PRIVATE KEY-----";
|
|
46
|
+
const pemContents = pemKey.replace(pemHeader, "").replace(pemFooter, "").replace(/\s/g, "");
|
|
47
|
+
const binaryString = atob(pemContents);
|
|
48
|
+
const binaryData = new Uint8Array(binaryString.length);
|
|
49
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
50
|
+
binaryData[i] = binaryString.charCodeAt(i);
|
|
51
|
+
}
|
|
52
|
+
return await crypto.subtle.importKey(
|
|
53
|
+
"pkcs8",
|
|
54
|
+
binaryData,
|
|
55
|
+
{ name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" },
|
|
56
|
+
true,
|
|
57
|
+
["sign"]
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
var buildJwt = async (credentials) => {
|
|
61
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
62
|
+
const header = {
|
|
63
|
+
alg: "RS256",
|
|
64
|
+
typ: "JWT"
|
|
65
|
+
};
|
|
66
|
+
if (credentials.privateKeyId) {
|
|
67
|
+
header.kid = credentials.privateKeyId;
|
|
68
|
+
}
|
|
69
|
+
const payload = {
|
|
70
|
+
iss: credentials.clientEmail,
|
|
71
|
+
scope: "https://www.googleapis.com/auth/cloud-platform",
|
|
72
|
+
aud: "https://oauth2.googleapis.com/token",
|
|
73
|
+
exp: now + 3600,
|
|
74
|
+
iat: now
|
|
75
|
+
};
|
|
76
|
+
const privateKey = await importPrivateKey(credentials.privateKey);
|
|
77
|
+
const signingInput = `${base64url(JSON.stringify(header))}.${base64url(
|
|
78
|
+
JSON.stringify(payload)
|
|
79
|
+
)}`;
|
|
80
|
+
const encoder = new TextEncoder();
|
|
81
|
+
const data = encoder.encode(signingInput);
|
|
82
|
+
const signature = await crypto.subtle.sign(
|
|
83
|
+
"RSASSA-PKCS1-v1_5",
|
|
84
|
+
privateKey,
|
|
85
|
+
data
|
|
86
|
+
);
|
|
87
|
+
const signatureBase64 = base64url(
|
|
88
|
+
String.fromCharCode(...new Uint8Array(signature))
|
|
89
|
+
);
|
|
90
|
+
return `${base64url(JSON.stringify(header))}.${base64url(
|
|
91
|
+
JSON.stringify(payload)
|
|
92
|
+
)}.${signatureBase64}`;
|
|
93
|
+
};
|
|
94
|
+
async function generateAuthToken(credentials) {
|
|
95
|
+
try {
|
|
96
|
+
const creds = credentials || await loadCredentials();
|
|
97
|
+
const jwt = await buildJwt(creds);
|
|
98
|
+
const response = await fetch("https://oauth2.googleapis.com/token", {
|
|
99
|
+
method: "POST",
|
|
100
|
+
headers: withUserAgentSuffix(
|
|
101
|
+
{ "Content-Type": "application/x-www-form-urlencoded" },
|
|
102
|
+
`ai-sdk/google-vertex/${VERSION}`,
|
|
103
|
+
getRuntimeEnvironmentUserAgent()
|
|
104
|
+
),
|
|
105
|
+
body: new URLSearchParams({
|
|
106
|
+
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
|
|
107
|
+
assertion: jwt
|
|
108
|
+
})
|
|
109
|
+
});
|
|
110
|
+
if (!response.ok) {
|
|
111
|
+
throw new Error(`Token request failed: ${response.statusText}`);
|
|
112
|
+
}
|
|
113
|
+
const data = await response.json();
|
|
114
|
+
return data.access_token;
|
|
115
|
+
} catch (error) {
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// src/maas/google-vertex-maas-provider.ts
|
|
121
|
+
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
122
|
+
import {
|
|
123
|
+
loadOptionalSetting as loadOptionalSetting2,
|
|
124
|
+
loadSetting as loadSetting2,
|
|
125
|
+
withoutTrailingSlash
|
|
126
|
+
} from "@ai-sdk/provider-utils";
|
|
127
|
+
function createVertexMaas(options = {}) {
|
|
128
|
+
const loadLocation = () => loadOptionalSetting2({
|
|
129
|
+
settingValue: options.location,
|
|
130
|
+
environmentVariableName: "GOOGLE_VERTEX_LOCATION"
|
|
131
|
+
});
|
|
132
|
+
const loadProject = () => loadSetting2({
|
|
133
|
+
settingValue: options.project,
|
|
134
|
+
settingName: "project",
|
|
135
|
+
environmentVariableName: "GOOGLE_VERTEX_PROJECT",
|
|
136
|
+
description: "Google Vertex project"
|
|
137
|
+
});
|
|
138
|
+
const constructBaseURL = () => {
|
|
139
|
+
var _a;
|
|
140
|
+
const projectId = loadProject();
|
|
141
|
+
const location = (_a = loadLocation()) != null ? _a : "global";
|
|
142
|
+
return `https://aiplatform.googleapis.com/v1/projects/${projectId}/locations/${location}/endpoints/openapi`;
|
|
143
|
+
};
|
|
144
|
+
const loadBaseURL = () => {
|
|
145
|
+
var _a;
|
|
146
|
+
return withoutTrailingSlash((_a = options.baseURL) != null ? _a : "") || constructBaseURL();
|
|
147
|
+
};
|
|
148
|
+
let cachedProvider;
|
|
149
|
+
const getProvider = () => cachedProvider != null ? cachedProvider : cachedProvider = createOpenAICompatible({
|
|
150
|
+
name: "vertex.maas",
|
|
151
|
+
baseURL: loadBaseURL(),
|
|
152
|
+
fetch: options.fetch
|
|
153
|
+
});
|
|
154
|
+
const provider = (modelId) => getProvider()(modelId);
|
|
155
|
+
provider.specificationVersion = "v2";
|
|
156
|
+
provider.languageModel = (modelId) => getProvider().languageModel(modelId);
|
|
157
|
+
provider.chatModel = (modelId) => getProvider().chatModel(modelId);
|
|
158
|
+
provider.completionModel = (modelId) => getProvider().completionModel(modelId);
|
|
159
|
+
provider.textEmbeddingModel = (modelId) => getProvider().textEmbeddingModel(modelId);
|
|
160
|
+
provider.imageModel = (modelId) => getProvider().imageModel(modelId);
|
|
161
|
+
return provider;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// src/maas/edge/google-vertex-maas-provider-edge.ts
|
|
165
|
+
function createVertexMaas2(options = {}) {
|
|
166
|
+
const customFetch = async (url, init) => {
|
|
167
|
+
var _a;
|
|
168
|
+
const token = await generateAuthToken(options.googleCredentials);
|
|
169
|
+
const resolvedHeaders = await resolve(options.headers);
|
|
170
|
+
const authHeaders = {
|
|
171
|
+
...resolvedHeaders,
|
|
172
|
+
Authorization: `Bearer ${token}`
|
|
173
|
+
};
|
|
174
|
+
const fetchInit = {
|
|
175
|
+
...init,
|
|
176
|
+
headers: {
|
|
177
|
+
...init == null ? void 0 : init.headers,
|
|
178
|
+
...authHeaders
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
return ((_a = options.fetch) != null ? _a : fetch)(url, fetchInit);
|
|
182
|
+
};
|
|
183
|
+
return createVertexMaas({
|
|
184
|
+
...options,
|
|
185
|
+
fetch: customFetch,
|
|
186
|
+
headers: void 0
|
|
187
|
+
// Don't pass headers, we handle them in fetch
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
var vertexMaas = createVertexMaas2();
|
|
191
|
+
export {
|
|
192
|
+
createVertexMaas2 as createVertexMaas,
|
|
193
|
+
vertexMaas
|
|
194
|
+
};
|
|
195
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/maas/edge/google-vertex-maas-provider-edge.ts","../../../src/edge/google-vertex-auth-edge.ts","../../../src/version.ts","../../../src/maas/google-vertex-maas-provider.ts"],"sourcesContent":["import { FetchFunction, resolve } from '@ai-sdk/provider-utils';\nimport {\n generateAuthToken,\n GoogleCredentials,\n} from '../../edge/google-vertex-auth-edge';\nimport {\n createVertexMaas as createVertexMaasOriginal,\n GoogleVertexMaasProvider,\n GoogleVertexMaasProviderSettings as GoogleVertexMaasProviderSettingsOriginal,\n} from '../google-vertex-maas-provider';\n\nexport type { GoogleVertexMaasProvider };\n\nexport interface GoogleVertexMaasProviderSettings extends GoogleVertexMaasProviderSettingsOriginal {\n /**\n * Optional. The Google credentials for the Google Cloud service account. If\n * not provided, the Google Vertex provider will use environment variables to\n * load the credentials.\n */\n googleCredentials?: GoogleCredentials;\n}\n\n/**\n * Create a Google Vertex AI MaaS (Model as a Service) provider instance for Edge runtimes.\n * Uses the OpenAI-compatible Chat Completions API for partner and open models.\n * Automatically handles Google Cloud authentication.\n *\n * @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models\n */\nexport function createVertexMaas(\n options: GoogleVertexMaasProviderSettings = {},\n): GoogleVertexMaasProvider {\n // Create a custom fetch wrapper that adds auth headers\n const customFetch: FetchFunction = async (url, init) => {\n const token = await generateAuthToken(options.googleCredentials);\n const resolvedHeaders = await resolve(options.headers);\n const authHeaders = {\n ...resolvedHeaders,\n Authorization: `Bearer ${token}`,\n };\n\n // Merge auth headers with existing headers from init\n const fetchInit = {\n ...init,\n headers: {\n ...init?.headers,\n ...authHeaders,\n },\n };\n\n // Call the original fetch or user's custom fetch\n return (options.fetch ?? fetch)(url, fetchInit);\n };\n\n return createVertexMaasOriginal({\n ...options,\n fetch: customFetch,\n headers: undefined, // Don't pass headers, we handle them in fetch\n });\n}\n\n/**\n * Default Google Vertex AI MaaS provider instance for Edge runtimes.\n */\nexport const vertexMaas = createVertexMaas();\n","import {\n loadOptionalSetting,\n loadSetting,\n withUserAgentSuffix,\n getRuntimeEnvironmentUserAgent,\n} from '@ai-sdk/provider-utils';\nimport { VERSION } from '../version';\n\nexport interface GoogleCredentials {\n /**\n * The client email for the Google Cloud service account. Defaults to the\n * value of the `GOOGLE_CLIENT_EMAIL` environment variable.\n */\n clientEmail: string;\n\n /**\n * The private key for the Google Cloud service account. Defaults to the\n * value of the `GOOGLE_PRIVATE_KEY` environment variable.\n */\n privateKey: string;\n\n /**\n * Optional. The private key ID for the Google Cloud service account. Defaults\n * to the value of the `GOOGLE_PRIVATE_KEY_ID` environment variable.\n */\n privateKeyId?: string;\n}\n\nconst loadCredentials = async (): Promise<GoogleCredentials> => {\n try {\n return {\n clientEmail: loadSetting({\n settingValue: undefined,\n settingName: 'clientEmail',\n environmentVariableName: 'GOOGLE_CLIENT_EMAIL',\n description: 'Google client email',\n }),\n privateKey: loadSetting({\n settingValue: undefined,\n settingName: 'privateKey',\n environmentVariableName: 'GOOGLE_PRIVATE_KEY',\n description: 'Google private key',\n }),\n privateKeyId: loadOptionalSetting({\n settingValue: undefined,\n environmentVariableName: 'GOOGLE_PRIVATE_KEY_ID',\n }),\n };\n } catch (error: any) {\n throw new Error(`Failed to load Google credentials: ${error.message}`);\n }\n};\n\n// Convert a string to base64url\nconst base64url = (str: string) => {\n return btoa(str).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=/g, '');\n};\nconst importPrivateKey = async (pemKey: string) => {\n const pemHeader = '-----BEGIN PRIVATE KEY-----';\n const pemFooter = '-----END PRIVATE KEY-----';\n\n // Remove header, footer, and any whitespace/newlines\n const pemContents = pemKey\n .replace(pemHeader, '')\n .replace(pemFooter, '')\n .replace(/\\s/g, '');\n\n // Decode base64 to binary\n const binaryString = atob(pemContents);\n\n // Convert binary string to Uint8Array\n const binaryData = new Uint8Array(binaryString.length);\n for (let i = 0; i < binaryString.length; i++) {\n binaryData[i] = binaryString.charCodeAt(i);\n }\n\n return await crypto.subtle.importKey(\n 'pkcs8',\n binaryData,\n { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-256' },\n true,\n ['sign'],\n );\n};\n\nconst buildJwt = async (credentials: GoogleCredentials) => {\n const now = Math.floor(Date.now() / 1000);\n\n // Only include kid in header if privateKeyId is provided\n const header: { alg: string; typ: string; kid?: string } = {\n alg: 'RS256',\n typ: 'JWT',\n };\n\n if (credentials.privateKeyId) {\n header.kid = credentials.privateKeyId;\n }\n\n const payload = {\n iss: credentials.clientEmail,\n scope: 'https://www.googleapis.com/auth/cloud-platform',\n aud: 'https://oauth2.googleapis.com/token',\n exp: now + 3600,\n iat: now,\n };\n\n const privateKey = await importPrivateKey(credentials.privateKey);\n\n const signingInput = `${base64url(JSON.stringify(header))}.${base64url(\n JSON.stringify(payload),\n )}`;\n const encoder = new TextEncoder();\n const data = encoder.encode(signingInput);\n\n const signature = await crypto.subtle.sign(\n 'RSASSA-PKCS1-v1_5',\n privateKey,\n data,\n );\n\n const signatureBase64 = base64url(\n String.fromCharCode(...new Uint8Array(signature)),\n );\n\n return `${base64url(JSON.stringify(header))}.${base64url(\n JSON.stringify(payload),\n )}.${signatureBase64}`;\n};\n\n/**\n * Generate an authentication token for Google Vertex AI in a manner compatible\n * with the Edge runtime.\n */\nexport async function generateAuthToken(credentials?: GoogleCredentials) {\n try {\n const creds = credentials || (await loadCredentials());\n const jwt = await buildJwt(creds);\n\n const response = await fetch('https://oauth2.googleapis.com/token', {\n method: 'POST',\n headers: withUserAgentSuffix(\n { 'Content-Type': 'application/x-www-form-urlencoded' },\n `ai-sdk/google-vertex/${VERSION}`,\n getRuntimeEnvironmentUserAgent(),\n ),\n body: new URLSearchParams({\n grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',\n assertion: jwt,\n }),\n });\n\n if (!response.ok) {\n throw new Error(`Token request failed: ${response.statusText}`);\n }\n\n const data = await response.json();\n return data.access_token;\n } catch (error) {\n throw error;\n }\n}\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n","import { createOpenAICompatible } from '@ai-sdk/openai-compatible';\nimport type { OpenAICompatibleProvider } from '@ai-sdk/openai-compatible';\nimport {\n FetchFunction,\n loadOptionalSetting,\n loadSetting,\n Resolvable,\n withoutTrailingSlash,\n} from '@ai-sdk/provider-utils';\nimport type { GoogleVertexMaasModelId } from './google-vertex-maas-options';\n\nexport interface GoogleVertexMaasProvider extends OpenAICompatibleProvider<\n GoogleVertexMaasModelId,\n string,\n string,\n string\n> {}\n\nexport interface GoogleVertexMaasProviderSettings {\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\n/**\n * Create a Google Vertex AI MaaS (Model as a Service) provider instance.\n * Uses the OpenAI-compatible Chat Completions API for partner and open models.\n *\n * @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models\n */\nexport function createVertexMaas(\n options: GoogleVertexMaasProviderSettings = {},\n): GoogleVertexMaasProvider {\n // Lazy-load settings to support loading from environment variables at runtime\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 // Construct base URL: https://aiplatform.googleapis.com/v1/projects/{project}/locations/{location}/endpoints/openapi\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: GoogleVertexMaasProvider | undefined;\n const getProvider = () =>\n (cachedProvider ??= createOpenAICompatible({\n name: 'vertex.maas',\n baseURL: loadBaseURL(),\n fetch: options.fetch,\n }));\n\n const provider = (modelId: GoogleVertexMaasModelId) => getProvider()(modelId);\n\n provider.specificationVersion = 'v2' as const;\n provider.languageModel = (modelId: GoogleVertexMaasModelId) =>\n getProvider().languageModel(modelId);\n provider.chatModel = (modelId: GoogleVertexMaasModelId) =>\n getProvider().chatModel(modelId);\n provider.completionModel = (modelId: string) =>\n getProvider().completionModel(modelId);\n provider.textEmbeddingModel = (modelId: string) =>\n getProvider().textEmbeddingModel(modelId);\n provider.imageModel = (model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AAO;AACvC,WAAS,qBAAqB,CAAC,YAC7B,YAAY,EAAE,mBAAmB,OAAO;AAC1C,WAAS,aAAa,CAAC,YAAoB,YAAY,EAAE,WAAW,OAAO;AAE3E,SAAO;AACT;;;AH/EO,SAASC,kBACd,UAA4C,CAAC,GACnB;AAE1B,QAAM,cAA6B,OAAO,KAAK,SAAS;AAjC1D;AAkCI,UAAM,QAAQ,MAAM,kBAAkB,QAAQ,iBAAiB;AAC/D,UAAM,kBAAkB,MAAM,QAAQ,QAAQ,OAAO;AACrD,UAAM,cAAc;AAAA,MAClB,GAAG;AAAA,MACH,eAAe,UAAU,KAAK;AAAA,IAChC;AAGA,UAAM,YAAY;AAAA,MAChB,GAAG;AAAA,MACH,SAAS;AAAA,QACP,GAAG,6BAAM;AAAA,QACT,GAAG;AAAA,MACL;AAAA,IACF;AAGA,aAAQ,aAAQ,UAAR,YAAiB,OAAO,KAAK,SAAS;AAAA,EAChD;AAEA,SAAO,iBAAyB;AAAA,IAC9B,GAAG;AAAA,IACH,OAAO;AAAA,IACP,SAAS;AAAA;AAAA,EACX,CAAC;AACH;AAKO,IAAM,aAAaA,kBAAiB;","names":["loadOptionalSetting","loadSetting","createVertexMaas"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { GoogleAuthOptions } from 'google-auth-library';
|
|
2
|
+
import { OpenAICompatibleProvider } from '@ai-sdk/openai-compatible';
|
|
3
|
+
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
|
+
|
|
5
|
+
type GoogleVertexMaasModelId = 'deepseek-ai/deepseek-r1-0528-maas' | 'deepseek-ai/deepseek-v3.1-maas' | 'deepseek-ai/deepseek-v3.2-maas' | 'openai/gpt-oss-120b-maas' | 'openai/gpt-oss-20b-maas' | 'meta/llama-4-maverick-17b-128e-instruct-maas' | 'meta/llama-4-scout-17b-16e-instruct-maas' | 'minimax/minimax-m2-maas' | 'qwen/qwen3-coder-480b-a35b-instruct-maas' | 'qwen/qwen3-next-80b-a3b-instruct-maas' | 'qwen/qwen3-next-80b-a3b-thinking-maas' | 'moonshotai/kimi-k2-thinking-maas' | (string & {});
|
|
6
|
+
|
|
7
|
+
interface GoogleVertexMaasProvider extends OpenAICompatibleProvider<GoogleVertexMaasModelId, string, string, string> {
|
|
8
|
+
}
|
|
9
|
+
interface GoogleVertexMaasProviderSettings$1 {
|
|
10
|
+
/**
|
|
11
|
+
* Google Cloud project ID. Defaults to the value of the `GOOGLE_VERTEX_PROJECT` environment variable.
|
|
12
|
+
*/
|
|
13
|
+
project?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Google Cloud location/region. Defaults to the value of the `GOOGLE_VERTEX_LOCATION` environment variable.
|
|
16
|
+
* Use 'global' for the global endpoint.
|
|
17
|
+
*/
|
|
18
|
+
location?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Base URL for the API calls. If not provided, will be constructed from project and location.
|
|
21
|
+
*/
|
|
22
|
+
baseURL?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Headers to use for requests. Can be:
|
|
25
|
+
* - A headers object
|
|
26
|
+
* - A Promise that resolves to a headers object
|
|
27
|
+
* - A function that returns a headers object
|
|
28
|
+
* - A function that returns a Promise of a headers object
|
|
29
|
+
*/
|
|
30
|
+
headers?: Resolvable<Record<string, string | undefined>>;
|
|
31
|
+
/**
|
|
32
|
+
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
33
|
+
* or to provide a custom fetch implementation for e.g. testing.
|
|
34
|
+
*/
|
|
35
|
+
fetch?: FetchFunction;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface GoogleVertexMaasProviderSettings extends GoogleVertexMaasProviderSettings$1 {
|
|
39
|
+
/**
|
|
40
|
+
* Optional. The Authentication options provided by google-auth-library.
|
|
41
|
+
* Complete list of authentication options is documented in the
|
|
42
|
+
* GoogleAuthOptions interface:
|
|
43
|
+
* https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts.
|
|
44
|
+
*/
|
|
45
|
+
googleAuthOptions?: GoogleAuthOptions;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Create a Google Vertex AI MaaS (Model as a Service) provider instance for Node.js.
|
|
49
|
+
* Uses the OpenAI-compatible Chat Completions API for partner and open models.
|
|
50
|
+
* Automatically handles Google Cloud authentication.
|
|
51
|
+
*
|
|
52
|
+
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models
|
|
53
|
+
*/
|
|
54
|
+
declare function createVertexMaas(options?: GoogleVertexMaasProviderSettings): GoogleVertexMaasProvider;
|
|
55
|
+
/**
|
|
56
|
+
* Default Google Vertex AI MaaS provider instance for Node.js.
|
|
57
|
+
*/
|
|
58
|
+
declare const vertexMaas: GoogleVertexMaasProvider;
|
|
59
|
+
|
|
60
|
+
export { type GoogleVertexMaasModelId, type GoogleVertexMaasProvider, type GoogleVertexMaasProviderSettings, createVertexMaas, vertexMaas };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { GoogleAuthOptions } from 'google-auth-library';
|
|
2
|
+
import { OpenAICompatibleProvider } from '@ai-sdk/openai-compatible';
|
|
3
|
+
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
|
+
|
|
5
|
+
type GoogleVertexMaasModelId = 'deepseek-ai/deepseek-r1-0528-maas' | 'deepseek-ai/deepseek-v3.1-maas' | 'deepseek-ai/deepseek-v3.2-maas' | 'openai/gpt-oss-120b-maas' | 'openai/gpt-oss-20b-maas' | 'meta/llama-4-maverick-17b-128e-instruct-maas' | 'meta/llama-4-scout-17b-16e-instruct-maas' | 'minimax/minimax-m2-maas' | 'qwen/qwen3-coder-480b-a35b-instruct-maas' | 'qwen/qwen3-next-80b-a3b-instruct-maas' | 'qwen/qwen3-next-80b-a3b-thinking-maas' | 'moonshotai/kimi-k2-thinking-maas' | (string & {});
|
|
6
|
+
|
|
7
|
+
interface GoogleVertexMaasProvider extends OpenAICompatibleProvider<GoogleVertexMaasModelId, string, string, string> {
|
|
8
|
+
}
|
|
9
|
+
interface GoogleVertexMaasProviderSettings$1 {
|
|
10
|
+
/**
|
|
11
|
+
* Google Cloud project ID. Defaults to the value of the `GOOGLE_VERTEX_PROJECT` environment variable.
|
|
12
|
+
*/
|
|
13
|
+
project?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Google Cloud location/region. Defaults to the value of the `GOOGLE_VERTEX_LOCATION` environment variable.
|
|
16
|
+
* Use 'global' for the global endpoint.
|
|
17
|
+
*/
|
|
18
|
+
location?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Base URL for the API calls. If not provided, will be constructed from project and location.
|
|
21
|
+
*/
|
|
22
|
+
baseURL?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Headers to use for requests. Can be:
|
|
25
|
+
* - A headers object
|
|
26
|
+
* - A Promise that resolves to a headers object
|
|
27
|
+
* - A function that returns a headers object
|
|
28
|
+
* - A function that returns a Promise of a headers object
|
|
29
|
+
*/
|
|
30
|
+
headers?: Resolvable<Record<string, string | undefined>>;
|
|
31
|
+
/**
|
|
32
|
+
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
33
|
+
* or to provide a custom fetch implementation for e.g. testing.
|
|
34
|
+
*/
|
|
35
|
+
fetch?: FetchFunction;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface GoogleVertexMaasProviderSettings extends GoogleVertexMaasProviderSettings$1 {
|
|
39
|
+
/**
|
|
40
|
+
* Optional. The Authentication options provided by google-auth-library.
|
|
41
|
+
* Complete list of authentication options is documented in the
|
|
42
|
+
* GoogleAuthOptions interface:
|
|
43
|
+
* https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts.
|
|
44
|
+
*/
|
|
45
|
+
googleAuthOptions?: GoogleAuthOptions;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Create a Google Vertex AI MaaS (Model as a Service) provider instance for Node.js.
|
|
49
|
+
* Uses the OpenAI-compatible Chat Completions API for partner and open models.
|
|
50
|
+
* Automatically handles Google Cloud authentication.
|
|
51
|
+
*
|
|
52
|
+
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models
|
|
53
|
+
*/
|
|
54
|
+
declare function createVertexMaas(options?: GoogleVertexMaasProviderSettings): GoogleVertexMaasProvider;
|
|
55
|
+
/**
|
|
56
|
+
* Default Google Vertex AI MaaS provider instance for Node.js.
|
|
57
|
+
*/
|
|
58
|
+
declare const vertexMaas: GoogleVertexMaasProvider;
|
|
59
|
+
|
|
60
|
+
export { type GoogleVertexMaasModelId, type GoogleVertexMaasProvider, type GoogleVertexMaasProviderSettings, createVertexMaas, vertexMaas };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/maas/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
createVertexMaas: () => createVertexMaas2,
|
|
24
|
+
vertexMaas: () => vertexMaas
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/maas/google-vertex-maas-provider-node.ts
|
|
29
|
+
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
30
|
+
|
|
31
|
+
// src/google-vertex-auth-google-auth-library.ts
|
|
32
|
+
var import_google_auth_library = require("google-auth-library");
|
|
33
|
+
var authInstance = null;
|
|
34
|
+
var authOptions = null;
|
|
35
|
+
function getAuth(options) {
|
|
36
|
+
if (!authInstance || options !== authOptions) {
|
|
37
|
+
authInstance = new import_google_auth_library.GoogleAuth({
|
|
38
|
+
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
|
|
39
|
+
...options
|
|
40
|
+
});
|
|
41
|
+
authOptions = options;
|
|
42
|
+
}
|
|
43
|
+
return authInstance;
|
|
44
|
+
}
|
|
45
|
+
async function generateAuthToken(options) {
|
|
46
|
+
const auth = getAuth(options || {});
|
|
47
|
+
const client = await auth.getClient();
|
|
48
|
+
const token = await client.getAccessToken();
|
|
49
|
+
return (token == null ? void 0 : token.token) || null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/maas/google-vertex-maas-provider.ts
|
|
53
|
+
var import_openai_compatible = require("@ai-sdk/openai-compatible");
|
|
54
|
+
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
55
|
+
function createVertexMaas(options = {}) {
|
|
56
|
+
const loadLocation = () => (0, import_provider_utils.loadOptionalSetting)({
|
|
57
|
+
settingValue: options.location,
|
|
58
|
+
environmentVariableName: "GOOGLE_VERTEX_LOCATION"
|
|
59
|
+
});
|
|
60
|
+
const loadProject = () => (0, import_provider_utils.loadSetting)({
|
|
61
|
+
settingValue: options.project,
|
|
62
|
+
settingName: "project",
|
|
63
|
+
environmentVariableName: "GOOGLE_VERTEX_PROJECT",
|
|
64
|
+
description: "Google Vertex project"
|
|
65
|
+
});
|
|
66
|
+
const constructBaseURL = () => {
|
|
67
|
+
var _a;
|
|
68
|
+
const projectId = loadProject();
|
|
69
|
+
const location = (_a = loadLocation()) != null ? _a : "global";
|
|
70
|
+
return `https://aiplatform.googleapis.com/v1/projects/${projectId}/locations/${location}/endpoints/openapi`;
|
|
71
|
+
};
|
|
72
|
+
const loadBaseURL = () => {
|
|
73
|
+
var _a;
|
|
74
|
+
return (0, import_provider_utils.withoutTrailingSlash)((_a = options.baseURL) != null ? _a : "") || constructBaseURL();
|
|
75
|
+
};
|
|
76
|
+
let cachedProvider;
|
|
77
|
+
const getProvider = () => cachedProvider != null ? cachedProvider : cachedProvider = (0, import_openai_compatible.createOpenAICompatible)({
|
|
78
|
+
name: "vertex.maas",
|
|
79
|
+
baseURL: loadBaseURL(),
|
|
80
|
+
fetch: options.fetch
|
|
81
|
+
});
|
|
82
|
+
const provider = (modelId) => getProvider()(modelId);
|
|
83
|
+
provider.specificationVersion = "v2";
|
|
84
|
+
provider.languageModel = (modelId) => getProvider().languageModel(modelId);
|
|
85
|
+
provider.chatModel = (modelId) => getProvider().chatModel(modelId);
|
|
86
|
+
provider.completionModel = (modelId) => getProvider().completionModel(modelId);
|
|
87
|
+
provider.textEmbeddingModel = (modelId) => getProvider().textEmbeddingModel(modelId);
|
|
88
|
+
provider.imageModel = (modelId) => getProvider().imageModel(modelId);
|
|
89
|
+
return provider;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/maas/google-vertex-maas-provider-node.ts
|
|
93
|
+
function createVertexMaas2(options = {}) {
|
|
94
|
+
const customFetch = async (url, init) => {
|
|
95
|
+
var _a;
|
|
96
|
+
const token = await generateAuthToken(options.googleAuthOptions);
|
|
97
|
+
const resolvedHeaders = await (0, import_provider_utils2.resolve)(options.headers);
|
|
98
|
+
const authHeaders = {
|
|
99
|
+
...resolvedHeaders,
|
|
100
|
+
Authorization: `Bearer ${token}`
|
|
101
|
+
};
|
|
102
|
+
const fetchInit = {
|
|
103
|
+
...init,
|
|
104
|
+
headers: {
|
|
105
|
+
...init == null ? void 0 : init.headers,
|
|
106
|
+
...authHeaders
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
return ((_a = options.fetch) != null ? _a : fetch)(url, fetchInit);
|
|
110
|
+
};
|
|
111
|
+
return createVertexMaas({
|
|
112
|
+
...options,
|
|
113
|
+
fetch: customFetch,
|
|
114
|
+
headers: void 0
|
|
115
|
+
// Don't pass headers, we handle them in fetch
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
var vertexMaas = createVertexMaas2();
|
|
119
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
120
|
+
0 && (module.exports = {
|
|
121
|
+
createVertexMaas,
|
|
122
|
+
vertexMaas
|
|
123
|
+
});
|
|
124
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/maas/index.ts","../../src/maas/google-vertex-maas-provider-node.ts","../../src/google-vertex-auth-google-auth-library.ts","../../src/maas/google-vertex-maas-provider.ts"],"sourcesContent":["export {\n createVertexMaas,\n vertexMaas,\n} from './google-vertex-maas-provider-node';\nexport type {\n GoogleVertexMaasProvider,\n GoogleVertexMaasProviderSettings,\n} from './google-vertex-maas-provider-node';\nexport type { GoogleVertexMaasModelId } from './google-vertex-maas-options';\n","import { FetchFunction, resolve } from '@ai-sdk/provider-utils';\nimport { GoogleAuthOptions } from 'google-auth-library';\nimport { generateAuthToken } from '../google-vertex-auth-google-auth-library';\nimport {\n createVertexMaas as createVertexMaasOriginal,\n GoogleVertexMaasProvider,\n GoogleVertexMaasProviderSettings as GoogleVertexMaasProviderSettingsOriginal,\n} from './google-vertex-maas-provider';\n\nexport type { GoogleVertexMaasProvider };\n\nexport interface GoogleVertexMaasProviderSettings extends GoogleVertexMaasProviderSettingsOriginal {\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 MaaS (Model as a Service) provider instance for Node.js.\n * Uses the OpenAI-compatible Chat Completions API for partner and open models.\n * Automatically handles Google Cloud authentication.\n *\n * @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models\n */\nexport function createVertexMaas(\n options: GoogleVertexMaasProviderSettings = {},\n): GoogleVertexMaasProvider {\n // Create a custom fetch wrapper that adds auth headers\n const customFetch: FetchFunction = async (url, init) => {\n const token = await generateAuthToken(options.googleAuthOptions);\n const resolvedHeaders = await resolve(options.headers);\n const authHeaders = {\n ...resolvedHeaders,\n Authorization: `Bearer ${token}`,\n };\n\n // Merge auth headers with existing headers from init\n const fetchInit = {\n ...init,\n headers: {\n ...init?.headers,\n ...authHeaders,\n },\n };\n\n // Call the original fetch or user's custom fetch\n return (options.fetch ?? fetch)(url, fetchInit);\n };\n\n return createVertexMaasOriginal({\n ...options,\n fetch: customFetch,\n headers: undefined, // Don't pass headers, we handle them in fetch\n });\n}\n\n/**\n * Default Google Vertex AI MaaS provider instance for Node.js.\n */\nexport const vertexMaas = createVertexMaas();\n","import { GoogleAuth, GoogleAuthOptions } from 'google-auth-library';\n\nlet authInstance: GoogleAuth | null = null;\nlet authOptions: GoogleAuthOptions | null = null;\n\nfunction getAuth(options: GoogleAuthOptions) {\n if (!authInstance || options !== authOptions) {\n authInstance = new GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n ...options,\n });\n authOptions = options;\n }\n return authInstance;\n}\n\nexport async function generateAuthToken(options?: GoogleAuthOptions) {\n const auth = getAuth(options || {});\n const client = await auth.getClient();\n const token = await client.getAccessToken();\n return token?.token || null;\n}\n\n// For testing purposes only\nexport function _resetAuthInstance() {\n authInstance = null;\n}\n","import { createOpenAICompatible } from '@ai-sdk/openai-compatible';\nimport type { OpenAICompatibleProvider } from '@ai-sdk/openai-compatible';\nimport {\n FetchFunction,\n loadOptionalSetting,\n loadSetting,\n Resolvable,\n withoutTrailingSlash,\n} from '@ai-sdk/provider-utils';\nimport type { GoogleVertexMaasModelId } from './google-vertex-maas-options';\n\nexport interface GoogleVertexMaasProvider extends OpenAICompatibleProvider<\n GoogleVertexMaasModelId,\n string,\n string,\n string\n> {}\n\nexport interface GoogleVertexMaasProviderSettings {\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\n/**\n * Create a Google Vertex AI MaaS (Model as a Service) provider instance.\n * Uses the OpenAI-compatible Chat Completions API for partner and open models.\n *\n * @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models\n */\nexport function createVertexMaas(\n options: GoogleVertexMaasProviderSettings = {},\n): GoogleVertexMaasProvider {\n // Lazy-load settings to support loading from environment variables at runtime\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 // Construct base URL: https://aiplatform.googleapis.com/v1/projects/{project}/locations/{location}/endpoints/openapi\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: GoogleVertexMaasProvider | undefined;\n const getProvider = () =>\n (cachedProvider ??= createOpenAICompatible({\n name: 'vertex.maas',\n baseURL: loadBaseURL(),\n fetch: options.fetch,\n }));\n\n const provider = (modelId: GoogleVertexMaasModelId) => getProvider()(modelId);\n\n provider.specificationVersion = 'v2' as const;\n provider.languageModel = (modelId: GoogleVertexMaasModelId) =>\n getProvider().languageModel(modelId);\n provider.chatModel = (modelId: GoogleVertexMaasModelId) =>\n getProvider().chatModel(modelId);\n provider.completionModel = (modelId: string) =>\n getProvider().completionModel(modelId);\n provider.textEmbeddingModel = (modelId: string) =>\n getProvider().textEmbeddingModel(modelId);\n provider.imageModel = (modelId: string) => getProvider().imageModel(modelId);\n\n return provider as GoogleVertexMaasProvider;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAAA;AAAA,EAAA;AAAA;AAAA;;;ACAA,IAAAC,yBAAuC;;;ACAvC,iCAA8C;AAE9C,IAAI,eAAkC;AACtC,IAAI,cAAwC;AAE5C,SAAS,QAAQ,SAA4B;AAC3C,MAAI,CAAC,gBAAgB,YAAY,aAAa;AAC5C,mBAAe,IAAI,sCAAW;AAAA,MAC5B,QAAQ,CAAC,gDAAgD;AAAA,MACzD,GAAG;AAAA,IACL,CAAC;AACD,kBAAc;AAAA,EAChB;AACA,SAAO;AACT;AAEA,eAAsB,kBAAkB,SAA6B;AACnE,QAAM,OAAO,QAAQ,WAAW,CAAC,CAAC;AAClC,QAAM,SAAS,MAAM,KAAK,UAAU;AACpC,QAAM,QAAQ,MAAM,OAAO,eAAe;AAC1C,UAAO,+BAAO,UAAS;AACzB;;;ACrBA,+BAAuC;AAEvC,4BAMO;AAiDA,SAAS,iBACd,UAA4C,CAAC,GACnB;AAE1B,QAAM,eAAe,UACnB,2CAAoB;AAAA,IAClB,cAAc,QAAQ;AAAA,IACtB,yBAAyB;AAAA,EAC3B,CAAC;AAEH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QACT,GAAG;AAAA,MACL;AAAA,IACF;AAGA,aAAQ,aAAQ,UAAR,YAAiB,OAAO,KAAK,SAAS;AAAA,EAChD;AAEA,SAAO,iBAAyB;AAAA,IAC9B,GAAG;AAAA,IACH,OAAO;AAAA,IACP,SAAS;AAAA;AAAA,EACX,CAAC;AACH;AAKO,IAAM,aAAaA,kBAAiB;","names":["createVertexMaas","import_provider_utils","createVertexMaas"]}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// src/maas/google-vertex-maas-provider-node.ts
|
|
2
|
+
import { resolve } from "@ai-sdk/provider-utils";
|
|
3
|
+
|
|
4
|
+
// src/google-vertex-auth-google-auth-library.ts
|
|
5
|
+
import { GoogleAuth } from "google-auth-library";
|
|
6
|
+
var authInstance = null;
|
|
7
|
+
var authOptions = null;
|
|
8
|
+
function getAuth(options) {
|
|
9
|
+
if (!authInstance || options !== authOptions) {
|
|
10
|
+
authInstance = new GoogleAuth({
|
|
11
|
+
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
|
|
12
|
+
...options
|
|
13
|
+
});
|
|
14
|
+
authOptions = options;
|
|
15
|
+
}
|
|
16
|
+
return authInstance;
|
|
17
|
+
}
|
|
18
|
+
async function generateAuthToken(options) {
|
|
19
|
+
const auth = getAuth(options || {});
|
|
20
|
+
const client = await auth.getClient();
|
|
21
|
+
const token = await client.getAccessToken();
|
|
22
|
+
return (token == null ? void 0 : token.token) || null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// src/maas/google-vertex-maas-provider.ts
|
|
26
|
+
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
27
|
+
import {
|
|
28
|
+
loadOptionalSetting,
|
|
29
|
+
loadSetting,
|
|
30
|
+
withoutTrailingSlash
|
|
31
|
+
} from "@ai-sdk/provider-utils";
|
|
32
|
+
function createVertexMaas(options = {}) {
|
|
33
|
+
const loadLocation = () => loadOptionalSetting({
|
|
34
|
+
settingValue: options.location,
|
|
35
|
+
environmentVariableName: "GOOGLE_VERTEX_LOCATION"
|
|
36
|
+
});
|
|
37
|
+
const loadProject = () => loadSetting({
|
|
38
|
+
settingValue: options.project,
|
|
39
|
+
settingName: "project",
|
|
40
|
+
environmentVariableName: "GOOGLE_VERTEX_PROJECT",
|
|
41
|
+
description: "Google Vertex project"
|
|
42
|
+
});
|
|
43
|
+
const constructBaseURL = () => {
|
|
44
|
+
var _a;
|
|
45
|
+
const projectId = loadProject();
|
|
46
|
+
const location = (_a = loadLocation()) != null ? _a : "global";
|
|
47
|
+
return `https://aiplatform.googleapis.com/v1/projects/${projectId}/locations/${location}/endpoints/openapi`;
|
|
48
|
+
};
|
|
49
|
+
const loadBaseURL = () => {
|
|
50
|
+
var _a;
|
|
51
|
+
return withoutTrailingSlash((_a = options.baseURL) != null ? _a : "") || constructBaseURL();
|
|
52
|
+
};
|
|
53
|
+
let cachedProvider;
|
|
54
|
+
const getProvider = () => cachedProvider != null ? cachedProvider : cachedProvider = createOpenAICompatible({
|
|
55
|
+
name: "vertex.maas",
|
|
56
|
+
baseURL: loadBaseURL(),
|
|
57
|
+
fetch: options.fetch
|
|
58
|
+
});
|
|
59
|
+
const provider = (modelId) => getProvider()(modelId);
|
|
60
|
+
provider.specificationVersion = "v2";
|
|
61
|
+
provider.languageModel = (modelId) => getProvider().languageModel(modelId);
|
|
62
|
+
provider.chatModel = (modelId) => getProvider().chatModel(modelId);
|
|
63
|
+
provider.completionModel = (modelId) => getProvider().completionModel(modelId);
|
|
64
|
+
provider.textEmbeddingModel = (modelId) => getProvider().textEmbeddingModel(modelId);
|
|
65
|
+
provider.imageModel = (modelId) => getProvider().imageModel(modelId);
|
|
66
|
+
return provider;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// src/maas/google-vertex-maas-provider-node.ts
|
|
70
|
+
function createVertexMaas2(options = {}) {
|
|
71
|
+
const customFetch = async (url, init) => {
|
|
72
|
+
var _a;
|
|
73
|
+
const token = await generateAuthToken(options.googleAuthOptions);
|
|
74
|
+
const resolvedHeaders = await resolve(options.headers);
|
|
75
|
+
const authHeaders = {
|
|
76
|
+
...resolvedHeaders,
|
|
77
|
+
Authorization: `Bearer ${token}`
|
|
78
|
+
};
|
|
79
|
+
const fetchInit = {
|
|
80
|
+
...init,
|
|
81
|
+
headers: {
|
|
82
|
+
...init == null ? void 0 : init.headers,
|
|
83
|
+
...authHeaders
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
return ((_a = options.fetch) != null ? _a : fetch)(url, fetchInit);
|
|
87
|
+
};
|
|
88
|
+
return createVertexMaas({
|
|
89
|
+
...options,
|
|
90
|
+
fetch: customFetch,
|
|
91
|
+
headers: void 0
|
|
92
|
+
// Don't pass headers, we handle them in fetch
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
var vertexMaas = createVertexMaas2();
|
|
96
|
+
export {
|
|
97
|
+
createVertexMaas2 as createVertexMaas,
|
|
98
|
+
vertexMaas
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/maas/google-vertex-maas-provider-node.ts","../../src/google-vertex-auth-google-auth-library.ts","../../src/maas/google-vertex-maas-provider.ts"],"sourcesContent":["import { FetchFunction, resolve } from '@ai-sdk/provider-utils';\nimport { GoogleAuthOptions } from 'google-auth-library';\nimport { generateAuthToken } from '../google-vertex-auth-google-auth-library';\nimport {\n createVertexMaas as createVertexMaasOriginal,\n GoogleVertexMaasProvider,\n GoogleVertexMaasProviderSettings as GoogleVertexMaasProviderSettingsOriginal,\n} from './google-vertex-maas-provider';\n\nexport type { GoogleVertexMaasProvider };\n\nexport interface GoogleVertexMaasProviderSettings extends GoogleVertexMaasProviderSettingsOriginal {\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 MaaS (Model as a Service) provider instance for Node.js.\n * Uses the OpenAI-compatible Chat Completions API for partner and open models.\n * Automatically handles Google Cloud authentication.\n *\n * @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models\n */\nexport function createVertexMaas(\n options: GoogleVertexMaasProviderSettings = {},\n): GoogleVertexMaasProvider {\n // Create a custom fetch wrapper that adds auth headers\n const customFetch: FetchFunction = async (url, init) => {\n const token = await generateAuthToken(options.googleAuthOptions);\n const resolvedHeaders = await resolve(options.headers);\n const authHeaders = {\n ...resolvedHeaders,\n Authorization: `Bearer ${token}`,\n };\n\n // Merge auth headers with existing headers from init\n const fetchInit = {\n ...init,\n headers: {\n ...init?.headers,\n ...authHeaders,\n },\n };\n\n // Call the original fetch or user's custom fetch\n return (options.fetch ?? fetch)(url, fetchInit);\n };\n\n return createVertexMaasOriginal({\n ...options,\n fetch: customFetch,\n headers: undefined, // Don't pass headers, we handle them in fetch\n });\n}\n\n/**\n * Default Google Vertex AI MaaS provider instance for Node.js.\n */\nexport const vertexMaas = createVertexMaas();\n","import { GoogleAuth, GoogleAuthOptions } from 'google-auth-library';\n\nlet authInstance: GoogleAuth | null = null;\nlet authOptions: GoogleAuthOptions | null = null;\n\nfunction getAuth(options: GoogleAuthOptions) {\n if (!authInstance || options !== authOptions) {\n authInstance = new GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n ...options,\n });\n authOptions = options;\n }\n return authInstance;\n}\n\nexport async function generateAuthToken(options?: GoogleAuthOptions) {\n const auth = getAuth(options || {});\n const client = await auth.getClient();\n const token = await client.getAccessToken();\n return token?.token || null;\n}\n\n// For testing purposes only\nexport function _resetAuthInstance() {\n authInstance = null;\n}\n","import { createOpenAICompatible } from '@ai-sdk/openai-compatible';\nimport type { OpenAICompatibleProvider } from '@ai-sdk/openai-compatible';\nimport {\n FetchFunction,\n loadOptionalSetting,\n loadSetting,\n Resolvable,\n withoutTrailingSlash,\n} from '@ai-sdk/provider-utils';\nimport type { GoogleVertexMaasModelId } from './google-vertex-maas-options';\n\nexport interface GoogleVertexMaasProvider extends OpenAICompatibleProvider<\n GoogleVertexMaasModelId,\n string,\n string,\n string\n> {}\n\nexport interface GoogleVertexMaasProviderSettings {\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\n/**\n * Create a Google Vertex AI MaaS (Model as a Service) provider instance.\n * Uses the OpenAI-compatible Chat Completions API for partner and open models.\n *\n * @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models\n */\nexport function createVertexMaas(\n options: GoogleVertexMaasProviderSettings = {},\n): GoogleVertexMaasProvider {\n // Lazy-load settings to support loading from environment variables at runtime\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 // Construct base URL: https://aiplatform.googleapis.com/v1/projects/{project}/locations/{location}/endpoints/openapi\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: GoogleVertexMaasProvider | undefined;\n const getProvider = () =>\n (cachedProvider ??= createOpenAICompatible({\n name: 'vertex.maas',\n baseURL: loadBaseURL(),\n fetch: options.fetch,\n }));\n\n const provider = (modelId: GoogleVertexMaasModelId) => getProvider()(modelId);\n\n provider.specificationVersion = 'v2' as const;\n provider.languageModel = (modelId: GoogleVertexMaasModelId) =>\n getProvider().languageModel(modelId);\n provider.chatModel = (modelId: GoogleVertexMaasModelId) =>\n getProvider().chatModel(modelId);\n provider.completionModel = (modelId: string) =>\n getProvider().completionModel(modelId);\n provider.textEmbeddingModel = (modelId: string) =>\n getProvider().textEmbeddingModel(modelId);\n provider.imageModel = (modelId: string) => getProvider().imageModel(modelId);\n\n return provider as GoogleVertexMaasProvider;\n}\n"],"mappings":";AAAA,SAAwB,eAAe;;;ACAvC,SAAS,kBAAqC;AAE9C,IAAI,eAAkC;AACtC,IAAI,cAAwC;AAE5C,SAAS,QAAQ,SAA4B;AAC3C,MAAI,CAAC,gBAAgB,YAAY,aAAa;AAC5C,mBAAe,IAAI,WAAW;AAAA,MAC5B,QAAQ,CAAC,gDAAgD;AAAA,MACzD,GAAG;AAAA,IACL,CAAC;AACD,kBAAc;AAAA,EAChB;AACA,SAAO;AACT;AAEA,eAAsB,kBAAkB,SAA6B;AACnE,QAAM,OAAO,QAAQ,WAAW,CAAC,CAAC;AAClC,QAAM,SAAS,MAAM,KAAK,UAAU;AACpC,QAAM,QAAQ,MAAM,OAAO,eAAe;AAC1C,UAAO,+BAAO,UAAS;AACzB;;;ACrBA,SAAS,8BAA8B;AAEvC;AAAA,EAEE;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AAiDA,SAAS,iBACd,UAA4C,CAAC,GACnB;AAE1B,QAAM,eAAe,MACnB,oBAAoB;AAAA,IAClB,cAAc,QAAQ;AAAA,IACtB,yBAAyB;AAAA,EAC3B,CAAC;AAEH,QAAM,c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AAAA,MACL;AAAA,IACF;AAGA,aAAQ,aAAQ,UAAR,YAAiB,OAAO,KAAK,SAAS;AAAA,EAChD;AAEA,SAAO,iBAAyB;AAAA,IAC9B,GAAG;AAAA,IACH,OAAO;AAAA,IACP,SAAS;AAAA;AAAA,EACX,CAAC;AACH;AAKO,IAAM,aAAaA,kBAAiB;","names":["createVertexMaas"]}
|
package/maas/edge.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/maas/edge/index';
|
package/maas/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/maas/index';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/google-vertex",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.122",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
"CHANGELOG.md",
|
|
12
12
|
"edge.d.ts",
|
|
13
13
|
"anthropic/edge.d.ts",
|
|
14
|
-
"anthropic/index.d.ts"
|
|
14
|
+
"anthropic/index.d.ts",
|
|
15
|
+
"maas/edge.d.ts",
|
|
16
|
+
"maas/index.d.ts"
|
|
15
17
|
],
|
|
16
18
|
"exports": {
|
|
17
19
|
"./package.json": "./package.json",
|
|
@@ -34,14 +36,25 @@
|
|
|
34
36
|
"types": "./dist/anthropic/edge/index.d.ts",
|
|
35
37
|
"import": "./dist/anthropic/edge/index.mjs",
|
|
36
38
|
"require": "./dist/anthropic/edge/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./maas": {
|
|
41
|
+
"types": "./dist/maas/index.d.ts",
|
|
42
|
+
"import": "./dist/maas/index.mjs",
|
|
43
|
+
"require": "./dist/maas/index.js"
|
|
44
|
+
},
|
|
45
|
+
"./maas/edge": {
|
|
46
|
+
"types": "./dist/maas/edge/index.d.ts",
|
|
47
|
+
"import": "./dist/maas/edge/index.mjs",
|
|
48
|
+
"require": "./dist/maas/edge/index.js"
|
|
37
49
|
}
|
|
38
50
|
},
|
|
39
51
|
"dependencies": {
|
|
40
52
|
"google-auth-library": "^10.5.0",
|
|
41
|
-
"@ai-sdk/
|
|
42
|
-
"@ai-sdk/
|
|
53
|
+
"@ai-sdk/anthropic": "2.0.71",
|
|
54
|
+
"@ai-sdk/openai-compatible": "1.0.34",
|
|
43
55
|
"@ai-sdk/provider": "2.0.1",
|
|
44
|
-
"@ai-sdk/
|
|
56
|
+
"@ai-sdk/google": "2.0.64",
|
|
57
|
+
"@ai-sdk/provider-utils": "3.0.22"
|
|
45
58
|
},
|
|
46
59
|
"devDependencies": {
|
|
47
60
|
"@types/node": "20.17.24",
|