@ai-sdk/google-vertex 5.0.0-beta.3 → 5.0.0-beta.30
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 +226 -8
- package/README.md +65 -1
- package/dist/anthropic/edge/index.d.mts +60 -15
- package/dist/anthropic/edge/index.d.ts +60 -15
- package/dist/anthropic/edge/index.js +29 -7
- package/dist/anthropic/edge/index.js.map +1 -1
- package/dist/anthropic/edge/index.mjs +26 -4
- package/dist/anthropic/edge/index.mjs.map +1 -1
- package/dist/anthropic/index.d.mts +60 -15
- package/dist/anthropic/index.d.ts +60 -15
- package/dist/anthropic/index.js +28 -6
- package/dist/anthropic/index.js.map +1 -1
- package/dist/anthropic/index.mjs +25 -3
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/edge/index.d.mts +19 -19
- package/dist/edge/index.d.ts +19 -19
- package/dist/edge/index.js +8 -8
- package/dist/edge/index.js.map +1 -1
- package/dist/edge/index.mjs +5 -5
- package/dist/edge/index.mjs.map +1 -1
- package/dist/index.d.mts +19 -19
- package/dist/index.d.ts +19 -19
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/index.mjs.map +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 +215 -0
- package/dist/maas/edge/index.js.map +1 -0
- package/dist/maas/edge/index.mjs +196 -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 +125 -0
- package/dist/maas/index.js.map +1 -0
- package/dist/maas/index.mjs +101 -0
- package/dist/maas/index.mjs.map +1 -0
- package/docs/16-google-vertex.mdx +164 -6
- package/maas/edge.d.ts +1 -0
- package/maas/index.d.ts +1 -0
- package/package.json +19 -8
- package/src/anthropic/edge/google-vertex-anthropic-provider-edge.ts +1 -2
- package/src/anthropic/google-vertex-anthropic-provider-node.ts +1 -2
- package/src/anthropic/google-vertex-anthropic-provider.ts +32 -7
- package/src/edge/google-vertex-provider-edge.ts +1 -2
- package/src/google-vertex-embedding-model.ts +5 -5
- package/src/google-vertex-embedding-options.ts +2 -0
- package/src/google-vertex-image-model.ts +17 -17
- package/src/google-vertex-provider-node.ts +1 -2
- package/src/google-vertex-provider.ts +12 -12
- package/src/google-vertex-video-model.ts +7 -7
- package/src/maas/edge/google-vertex-maas-provider-edge.ts +65 -0
- package/src/maas/edge/index.ts +9 -0
- package/src/maas/google-vertex-maas-options.ts +15 -0
- package/src/maas/google-vertex-maas-provider-node.ts +64 -0
- package/src/maas/google-vertex-maas-provider.ts +111 -0
- package/src/maas/index.ts +9 -0
|
@@ -0,0 +1,125 @@
|
|
|
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 = "v4";
|
|
84
|
+
provider.languageModel = (modelId) => getProvider().languageModel(modelId);
|
|
85
|
+
provider.chatModel = (modelId) => getProvider().chatModel(modelId);
|
|
86
|
+
provider.completionModel = (modelId) => getProvider().completionModel(modelId);
|
|
87
|
+
provider.embeddingModel = (modelId) => getProvider().embeddingModel(modelId);
|
|
88
|
+
provider.textEmbeddingModel = (modelId) => getProvider().textEmbeddingModel(modelId);
|
|
89
|
+
provider.imageModel = (modelId) => getProvider().imageModel(modelId);
|
|
90
|
+
return provider;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/maas/google-vertex-maas-provider-node.ts
|
|
94
|
+
function createVertexMaas2(options = {}) {
|
|
95
|
+
const customFetch = async (url, init) => {
|
|
96
|
+
var _a;
|
|
97
|
+
const token = await generateAuthToken(options.googleAuthOptions);
|
|
98
|
+
const resolvedHeaders = await (0, import_provider_utils2.resolve)(options.headers);
|
|
99
|
+
const authHeaders = {
|
|
100
|
+
...resolvedHeaders,
|
|
101
|
+
Authorization: `Bearer ${token}`
|
|
102
|
+
};
|
|
103
|
+
const fetchInit = {
|
|
104
|
+
...init,
|
|
105
|
+
headers: {
|
|
106
|
+
...init == null ? void 0 : init.headers,
|
|
107
|
+
...authHeaders
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
return ((_a = options.fetch) != null ? _a : fetch)(url, fetchInit);
|
|
111
|
+
};
|
|
112
|
+
return createVertexMaas({
|
|
113
|
+
...options,
|
|
114
|
+
fetch: customFetch,
|
|
115
|
+
headers: void 0
|
|
116
|
+
// Don't pass headers, we handle them in fetch
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
var vertexMaas = createVertexMaas2();
|
|
120
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
121
|
+
0 && (module.exports = {
|
|
122
|
+
createVertexMaas,
|
|
123
|
+
vertexMaas
|
|
124
|
+
});
|
|
125
|
+
//# 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 = 'v4' 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.embeddingModel = (modelId: string) =>\n getProvider().embeddingModel(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,QAAM,cAAc,UAClB,mCAAY;AAAA,IACV,cAAc,QAAQ;AAAA,IACtB,aAAa;AAAA,IACb,yBAAyB;AAAA,IACzB,aAAa;AAAA,EACf,CAAC;AAGH,QAAM,mBAAmB,MAAM;AA5EjC;AA6EI,UAAM,YAAY,YAAY;AAC9B,UAAM,YAAW,kBAAa,MAAb,YAAkB;AAEnC,WAAO,iDAAiD,SAAS,cAAc,QAAQ;AAAA,EACzF;AAEA,QAAM,cAAc,MAAG;AAnFzB;AAoFI,4DAAqB,aAAQ,YAAR,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,iBAAiB,CAAC,YACzB,YAAY,EAAE,eAAe,OAAO;AACtC,WAAS,qBAAqB,CAAC,YAC7B,YAAY,EAAE,mBAAmB,OAAO;AAC1C,WAAS,aAAa,CAAC,YAAoB,YAAY,EAAE,WAAW,OAAO;AAE3E,SAAO;AACT;;;AFlFO,SAASC,kBACd,UAA4C,CAAC,GACnB;AAE1B,QAAM,cAA6B,OAAO,KAAK,SAAS;AAhC1D;AAiCI,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","createVertexMaas"]}
|
|
@@ -0,0 +1,101 @@
|
|
|
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 = "v4";
|
|
61
|
+
provider.languageModel = (modelId) => getProvider().languageModel(modelId);
|
|
62
|
+
provider.chatModel = (modelId) => getProvider().chatModel(modelId);
|
|
63
|
+
provider.completionModel = (modelId) => getProvider().completionModel(modelId);
|
|
64
|
+
provider.embeddingModel = (modelId) => getProvider().embeddingModel(modelId);
|
|
65
|
+
provider.textEmbeddingModel = (modelId) => getProvider().textEmbeddingModel(modelId);
|
|
66
|
+
provider.imageModel = (modelId) => getProvider().imageModel(modelId);
|
|
67
|
+
return provider;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/maas/google-vertex-maas-provider-node.ts
|
|
71
|
+
function createVertexMaas2(options = {}) {
|
|
72
|
+
const customFetch = async (url, init) => {
|
|
73
|
+
var _a;
|
|
74
|
+
const token = await generateAuthToken(options.googleAuthOptions);
|
|
75
|
+
const resolvedHeaders = await resolve(options.headers);
|
|
76
|
+
const authHeaders = {
|
|
77
|
+
...resolvedHeaders,
|
|
78
|
+
Authorization: `Bearer ${token}`
|
|
79
|
+
};
|
|
80
|
+
const fetchInit = {
|
|
81
|
+
...init,
|
|
82
|
+
headers: {
|
|
83
|
+
...init == null ? void 0 : init.headers,
|
|
84
|
+
...authHeaders
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
return ((_a = options.fetch) != null ? _a : fetch)(url, fetchInit);
|
|
88
|
+
};
|
|
89
|
+
return createVertexMaas({
|
|
90
|
+
...options,
|
|
91
|
+
fetch: customFetch,
|
|
92
|
+
headers: void 0
|
|
93
|
+
// Don't pass headers, we handle them in fetch
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
var vertexMaas = createVertexMaas2();
|
|
97
|
+
export {
|
|
98
|
+
createVertexMaas2 as createVertexMaas,
|
|
99
|
+
vertexMaas
|
|
100
|
+
};
|
|
101
|
+
//# 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 = 'v4' 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.embeddingModel = (modelId: string) =>\n getProvider().embeddingModel(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,cAAc,MAClB,YAAY;AAAA,IACV,cAAc,QAAQ;AAAA,IACtB,aAAa;AAAA,IACb,yBAAyB;AAAA,IACzB,aAAa;AAAA,EACf,CAAC;AAGH,QAAM,mBAAmB,MAAM;AA5EjC;AA6EI,UAAM,YAAY,YAAY;AAC9B,UAAM,YAAW,kBAAa,MAAb,YAAkB;AAEnC,WAAO,iDAAiD,SAAS,cAAc,QAAQ;AAAA,EACzF;AAEA,QAAM,cAAc,MAAG;AAnFzB;AAoFI,iCAAqB,aAAQ,YAAR,YAAmB,EAAE,KAAK,iBAAiB;AAAA;AAElE,MAAI;AACJ,QAAM,cAAc,MACjB,2DAAmB,uBAAuB;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,iBAAiB,CAAC,YACzB,YAAY,EAAE,eAAe,OAAO;AACtC,WAAS,qBAAqB,CAAC,YAC7B,YAAY,EAAE,mBAAmB,OAAO;AAC1C,WAAS,aAAa,CAAC,YAAoB,YAAY,EAAE,WAAW,OAAO;AAE3E,SAAO;AACT;;;AFlFO,SAASA,kBACd,UAA4C,CAAC,GACnB;AAE1B,QAAM,cAA6B,OAAO,KAAK,SAAS;AAhC1D;AAiCI,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":["createVertexMaas"]}
|
|
@@ -5,14 +5,15 @@ description: Learn how to use the Google Vertex AI provider.
|
|
|
5
5
|
|
|
6
6
|
# Google Vertex Provider
|
|
7
7
|
|
|
8
|
-
The Google Vertex provider for the [AI SDK](/docs) contains language model support for the [Google Vertex AI](https://cloud.google.com/vertex-ai) APIs. This includes support for [Google's Gemini models](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models)
|
|
8
|
+
The Google Vertex provider for the [AI SDK](/docs) contains language model support for the [Google Vertex AI](https://cloud.google.com/vertex-ai) APIs. This includes support for [Google's Gemini models](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models), [Anthropic's Claude partner models](https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude), and [MaaS (Model as a Service) open models](https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models).
|
|
9
9
|
|
|
10
10
|
<Note>
|
|
11
11
|
The Google Vertex provider is compatible with both Node.js and Edge runtimes.
|
|
12
12
|
The Edge runtime is supported through the `@ai-sdk/google-vertex/edge`
|
|
13
13
|
sub-module. More details can be found in the [Google Vertex Edge
|
|
14
|
-
Runtime](#google-vertex-edge-runtime)
|
|
15
|
-
Runtime](#google-vertex-anthropic-edge-runtime)
|
|
14
|
+
Runtime](#google-vertex-edge-runtime), [Google Vertex Anthropic Edge
|
|
15
|
+
Runtime](#google-vertex-anthropic-edge-runtime), and [Google Vertex MaaS Edge
|
|
16
|
+
Runtime](#google-vertex-maas-edge-runtime) sections below.
|
|
16
17
|
</Note>
|
|
17
18
|
|
|
18
19
|
## Setup
|
|
@@ -829,9 +830,10 @@ The following optional provider options are available for Google Vertex AI embed
|
|
|
829
830
|
|
|
830
831
|
#### Model Capabilities
|
|
831
832
|
|
|
832
|
-
| Model
|
|
833
|
-
|
|
|
834
|
-
| `text-embedding-005`
|
|
833
|
+
| Model | Max Values Per Call | Parallel Calls | Multimodal |
|
|
834
|
+
| ---------------------------- | ------------------- | ------------------- | ------------------- |
|
|
835
|
+
| `text-embedding-005` | 2048 | <Check size={18} /> | <Cross size={18} /> |
|
|
836
|
+
| `gemini-embedding-2-preview` | 2048 | <Check size={18} /> | <Check size={18} /> |
|
|
835
837
|
|
|
836
838
|
<Note>
|
|
837
839
|
The table above lists popular models. You can also pass any available provider
|
|
@@ -1428,6 +1430,12 @@ The following optional provider options are available for Anthropic models:
|
|
|
1428
1430
|
|
|
1429
1431
|
Optional. See [Reasoning section](#reasoning) for more details.
|
|
1430
1432
|
|
|
1433
|
+
- `metadata` _object_
|
|
1434
|
+
|
|
1435
|
+
Optional. Metadata to include with the request. See the [Anthropic API documentation](https://platform.claude.com/docs/en/api/messages/create) for details.
|
|
1436
|
+
|
|
1437
|
+
- `userId` _string_ - An external identifier for the end-user.
|
|
1438
|
+
|
|
1431
1439
|
### Reasoning
|
|
1432
1440
|
|
|
1433
1441
|
Anthropic has reasoning support for the `claude-3-7-sonnet@20250219` model.
|
|
@@ -1547,6 +1555,12 @@ Google Vertex Anthropic supports a subset of Anthropic's built-in tools. The fol
|
|
|
1547
1555
|
`@ai-sdk/anthropic` provider if you need access to all Anthropic tools.
|
|
1548
1556
|
</Note>
|
|
1549
1557
|
|
|
1558
|
+
<Note>
|
|
1559
|
+
Google Vertex Anthropic does not support strict mode on tool definitions.
|
|
1560
|
+
Setting `strict: true` on a tool will be ignored and a warning will be
|
|
1561
|
+
emitted.
|
|
1562
|
+
</Note>
|
|
1563
|
+
|
|
1550
1564
|
For more background on Anthropic tools, see [Anthropic's documentation](https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview).
|
|
1551
1565
|
|
|
1552
1566
|
#### Bash Tool
|
|
@@ -1703,3 +1717,147 @@ See also [Anthropic Model Comparison](https://docs.anthropic.com/en/docs/about-c
|
|
|
1703
1717
|
The table above lists popular models. You can also pass any available provider
|
|
1704
1718
|
model ID as a string if needed.
|
|
1705
1719
|
</Note>
|
|
1720
|
+
|
|
1721
|
+
## Google Vertex MaaS Provider Usage
|
|
1722
|
+
|
|
1723
|
+
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. This includes models from DeepSeek, Qwen, Meta, MiniMax, Moonshot, and OpenAI.
|
|
1724
|
+
|
|
1725
|
+
For more information, see the [Vertex AI MaaS documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models).
|
|
1726
|
+
|
|
1727
|
+
### Provider Instance
|
|
1728
|
+
|
|
1729
|
+
You can import the default provider instance `vertexMaas` from `@ai-sdk/google-vertex/maas`:
|
|
1730
|
+
|
|
1731
|
+
```typescript
|
|
1732
|
+
import { vertexMaas } from '@ai-sdk/google-vertex/maas';
|
|
1733
|
+
```
|
|
1734
|
+
|
|
1735
|
+
If you need a customized setup, you can import `createVertexMaas` from `@ai-sdk/google-vertex/maas` and create a provider instance with your settings:
|
|
1736
|
+
|
|
1737
|
+
```typescript
|
|
1738
|
+
import { createVertexMaas } from '@ai-sdk/google-vertex/maas';
|
|
1739
|
+
|
|
1740
|
+
const vertexMaas = createVertexMaas({
|
|
1741
|
+
project: 'my-project', // optional
|
|
1742
|
+
location: 'us-east5', // optional, defaults to 'global'
|
|
1743
|
+
});
|
|
1744
|
+
```
|
|
1745
|
+
|
|
1746
|
+
#### Node.js Runtime
|
|
1747
|
+
|
|
1748
|
+
For Node.js environments, the Google Vertex MaaS provider supports all standard Google Cloud authentication options through the `google-auth-library`:
|
|
1749
|
+
|
|
1750
|
+
```typescript
|
|
1751
|
+
import { createVertexMaas } from '@ai-sdk/google-vertex/maas';
|
|
1752
|
+
|
|
1753
|
+
const vertexMaas = createVertexMaas({
|
|
1754
|
+
googleAuthOptions: {
|
|
1755
|
+
credentials: {
|
|
1756
|
+
client_email: 'my-email',
|
|
1757
|
+
private_key: 'my-private-key',
|
|
1758
|
+
},
|
|
1759
|
+
},
|
|
1760
|
+
});
|
|
1761
|
+
```
|
|
1762
|
+
|
|
1763
|
+
##### Optional Provider Settings
|
|
1764
|
+
|
|
1765
|
+
- **project** _string_
|
|
1766
|
+
|
|
1767
|
+
The Google Cloud project ID. Defaults to the `GOOGLE_VERTEX_PROJECT` environment variable.
|
|
1768
|
+
|
|
1769
|
+
- **location** _string_
|
|
1770
|
+
|
|
1771
|
+
The Google Cloud location, e.g. `us-east5` or `global`. Defaults to the `GOOGLE_VERTEX_LOCATION` environment variable. If not set, defaults to `global`.
|
|
1772
|
+
|
|
1773
|
+
- **googleAuthOptions** _object_
|
|
1774
|
+
|
|
1775
|
+
Optional. The Authentication options used by the [Google Auth Library](https://github.com/googleapis/google-auth-library-nodejs/).
|
|
1776
|
+
|
|
1777
|
+
- **headers** _Resolvable<Record<string, string | undefined>>_
|
|
1778
|
+
|
|
1779
|
+
Headers to include in requests.
|
|
1780
|
+
|
|
1781
|
+
- **fetch** _(input: RequestInfo, init?: RequestInit) => Promise<Response>_
|
|
1782
|
+
|
|
1783
|
+
Custom [fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch) implementation.
|
|
1784
|
+
|
|
1785
|
+
<a id="google-vertex-maas-edge-runtime"></a>
|
|
1786
|
+
|
|
1787
|
+
#### Edge Runtime
|
|
1788
|
+
|
|
1789
|
+
For Edge runtimes, import from `@ai-sdk/google-vertex/maas/edge`:
|
|
1790
|
+
|
|
1791
|
+
```typescript
|
|
1792
|
+
import { vertexMaas } from '@ai-sdk/google-vertex/maas/edge';
|
|
1793
|
+
```
|
|
1794
|
+
|
|
1795
|
+
```typescript
|
|
1796
|
+
import { createVertexMaas } from '@ai-sdk/google-vertex/maas/edge';
|
|
1797
|
+
|
|
1798
|
+
const vertexMaas = createVertexMaas({
|
|
1799
|
+
project: 'my-project',
|
|
1800
|
+
location: 'us-east5',
|
|
1801
|
+
});
|
|
1802
|
+
```
|
|
1803
|
+
|
|
1804
|
+
For Edge runtime authentication, set these environment variables:
|
|
1805
|
+
|
|
1806
|
+
- `GOOGLE_CLIENT_EMAIL`
|
|
1807
|
+
- `GOOGLE_PRIVATE_KEY`
|
|
1808
|
+
- `GOOGLE_PRIVATE_KEY_ID` (optional)
|
|
1809
|
+
|
|
1810
|
+
### Language Models
|
|
1811
|
+
|
|
1812
|
+
You can create models using the provider instance. The first argument is the model ID:
|
|
1813
|
+
|
|
1814
|
+
```ts
|
|
1815
|
+
import { vertexMaas } from '@ai-sdk/google-vertex/maas';
|
|
1816
|
+
import { generateText } from 'ai';
|
|
1817
|
+
|
|
1818
|
+
const { text } = await generateText({
|
|
1819
|
+
model: vertexMaas('deepseek-ai/deepseek-v3.2-maas'),
|
|
1820
|
+
prompt: 'Invent a new holiday and describe its traditions.',
|
|
1821
|
+
});
|
|
1822
|
+
```
|
|
1823
|
+
|
|
1824
|
+
Streaming is also supported:
|
|
1825
|
+
|
|
1826
|
+
```ts
|
|
1827
|
+
import { vertexMaas } from '@ai-sdk/google-vertex/maas';
|
|
1828
|
+
import { streamText } from 'ai';
|
|
1829
|
+
|
|
1830
|
+
const result = streamText({
|
|
1831
|
+
model: vertexMaas('deepseek-ai/deepseek-v3.2-maas'),
|
|
1832
|
+
prompt: 'Invent a new holiday and describe its traditions.',
|
|
1833
|
+
});
|
|
1834
|
+
|
|
1835
|
+
for await (const textPart of result.textStream) {
|
|
1836
|
+
process.stdout.write(textPart);
|
|
1837
|
+
}
|
|
1838
|
+
```
|
|
1839
|
+
|
|
1840
|
+
### Available Models
|
|
1841
|
+
|
|
1842
|
+
The following models are available through the MaaS provider. You can also pass any valid model ID as a string.
|
|
1843
|
+
|
|
1844
|
+
| Model ID | Provider |
|
|
1845
|
+
| ---------------------------------------------- | -------- |
|
|
1846
|
+
| `deepseek-ai/deepseek-r1-0528-maas` | DeepSeek |
|
|
1847
|
+
| `deepseek-ai/deepseek-v3.1-maas` | DeepSeek |
|
|
1848
|
+
| `deepseek-ai/deepseek-v3.2-maas` | DeepSeek |
|
|
1849
|
+
| `openai/gpt-oss-120b-maas` | OpenAI |
|
|
1850
|
+
| `openai/gpt-oss-20b-maas` | OpenAI |
|
|
1851
|
+
| `meta/llama-4-maverick-17b-128e-instruct-maas` | Meta |
|
|
1852
|
+
| `meta/llama-4-scout-17b-16e-instruct-maas` | Meta |
|
|
1853
|
+
| `minimax/minimax-m2-maas` | MiniMax |
|
|
1854
|
+
| `qwen/qwen3-coder-480b-a35b-instruct-maas` | Qwen |
|
|
1855
|
+
| `qwen/qwen3-next-80b-a3b-instruct-maas` | Qwen |
|
|
1856
|
+
| `qwen/qwen3-next-80b-a3b-thinking-maas` | Qwen |
|
|
1857
|
+
| `moonshotai/kimi-k2-thinking-maas` | Moonshot |
|
|
1858
|
+
|
|
1859
|
+
<Note>
|
|
1860
|
+
Model availability depends on your Google Cloud project and region. Check the
|
|
1861
|
+
[Vertex AI Model Garden](https://console.cloud.google.com/vertex-ai/model-garden)
|
|
1862
|
+
for the latest available models.
|
|
1863
|
+
</Note>
|
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": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.30",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
"README.md",
|
|
19
19
|
"edge.d.ts",
|
|
20
20
|
"anthropic/edge.d.ts",
|
|
21
|
-
"anthropic/index.d.ts"
|
|
21
|
+
"anthropic/index.d.ts",
|
|
22
|
+
"maas/edge.d.ts",
|
|
23
|
+
"maas/index.d.ts"
|
|
22
24
|
],
|
|
23
25
|
"directories": {
|
|
24
26
|
"doc": "./docs"
|
|
@@ -44,14 +46,25 @@
|
|
|
44
46
|
"types": "./dist/anthropic/edge/index.d.ts",
|
|
45
47
|
"import": "./dist/anthropic/edge/index.mjs",
|
|
46
48
|
"require": "./dist/anthropic/edge/index.js"
|
|
49
|
+
},
|
|
50
|
+
"./maas": {
|
|
51
|
+
"types": "./dist/maas/index.d.ts",
|
|
52
|
+
"import": "./dist/maas/index.mjs",
|
|
53
|
+
"require": "./dist/maas/index.js"
|
|
54
|
+
},
|
|
55
|
+
"./maas/edge": {
|
|
56
|
+
"types": "./dist/maas/edge/index.d.ts",
|
|
57
|
+
"import": "./dist/maas/edge/index.mjs",
|
|
58
|
+
"require": "./dist/maas/edge/index.js"
|
|
47
59
|
}
|
|
48
60
|
},
|
|
49
61
|
"dependencies": {
|
|
50
62
|
"google-auth-library": "^10.5.0",
|
|
51
|
-
"@ai-sdk/anthropic": "4.0.0-beta.
|
|
52
|
-
"@ai-sdk/google": "4.0.0-beta.
|
|
53
|
-
"@ai-sdk/
|
|
54
|
-
"@ai-sdk/provider
|
|
63
|
+
"@ai-sdk/anthropic": "4.0.0-beta.16",
|
|
64
|
+
"@ai-sdk/google": "4.0.0-beta.22",
|
|
65
|
+
"@ai-sdk/openai-compatible": "3.0.0-beta.13",
|
|
66
|
+
"@ai-sdk/provider": "4.0.0-beta.5",
|
|
67
|
+
"@ai-sdk/provider-utils": "5.0.0-beta.9"
|
|
55
68
|
},
|
|
56
69
|
"devDependencies": {
|
|
57
70
|
"@types/node": "20.17.24",
|
|
@@ -85,9 +98,7 @@
|
|
|
85
98
|
"build": "pnpm clean && tsup --tsconfig tsconfig.build.json",
|
|
86
99
|
"build:watch": "pnpm clean && tsup --watch",
|
|
87
100
|
"clean": "del-cli dist docs *.tsbuildinfo",
|
|
88
|
-
"lint": "eslint \"./**/*.ts*\"",
|
|
89
101
|
"type-check": "tsc --build",
|
|
90
|
-
"prettier-check": "prettier --check \"./**/*.ts*\"",
|
|
91
102
|
"test": "pnpm test:node && pnpm test:edge",
|
|
92
103
|
"test:update": "pnpm test:node -u",
|
|
93
104
|
"test:watch": "vitest --config vitest.node.config.js",
|
|
@@ -11,8 +11,7 @@ import {
|
|
|
11
11
|
|
|
12
12
|
export type { GoogleVertexAnthropicProvider };
|
|
13
13
|
|
|
14
|
-
export interface GoogleVertexAnthropicProviderSettings
|
|
15
|
-
extends GoogleVertexAnthropicProviderSettingsOriginal {
|
|
14
|
+
export interface GoogleVertexAnthropicProviderSettings extends GoogleVertexAnthropicProviderSettingsOriginal {
|
|
16
15
|
/**
|
|
17
16
|
* Optional. The Google credentials for the Google Cloud service account. If
|
|
18
17
|
* not provided, the Google Vertex provider will use environment variables to
|
|
@@ -9,8 +9,7 @@ import {
|
|
|
9
9
|
|
|
10
10
|
export type { GoogleVertexAnthropicProvider };
|
|
11
11
|
|
|
12
|
-
export interface GoogleVertexAnthropicProviderSettings
|
|
13
|
-
extends GoogleVertexAnthropicProviderSettingsOriginal {
|
|
12
|
+
export interface GoogleVertexAnthropicProviderSettings extends GoogleVertexAnthropicProviderSettingsOriginal {
|
|
14
13
|
/**
|
|
15
14
|
* Optional. The Authentication options provided by google-auth-library.
|
|
16
15
|
* Complete list of authentication options is documented in the
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
LanguageModelV4,
|
|
3
3
|
NoSuchModelError,
|
|
4
|
-
|
|
4
|
+
ProviderV4,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import {
|
|
7
7
|
FetchFunction,
|
|
@@ -78,24 +78,47 @@ export const vertexAnthropicTools = {
|
|
|
78
78
|
* Creates a web search tool that gives Claude direct access to real-time web content.
|
|
79
79
|
*/
|
|
80
80
|
webSearch_20250305: anthropicTools.webSearch_20250305,
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Creates a tool search tool that uses regex patterns to find tools.
|
|
84
|
+
*
|
|
85
|
+
* The tool search tool enables Claude to work with hundreds or thousands of tools
|
|
86
|
+
* by dynamically discovering and loading them on-demand.
|
|
87
|
+
*
|
|
88
|
+
* Use `providerOptions: { anthropic: { deferLoading: true } }` on other tools
|
|
89
|
+
* to mark them for deferred loading.
|
|
90
|
+
*/
|
|
91
|
+
toolSearchRegex_20251119: anthropicTools.toolSearchRegex_20251119,
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Creates a tool search tool that uses BM25 (natural language) to find tools.
|
|
95
|
+
*
|
|
96
|
+
* The tool search tool enables Claude to work with hundreds or thousands of tools
|
|
97
|
+
* by dynamically discovering and loading them on-demand.
|
|
98
|
+
*
|
|
99
|
+
* Use `providerOptions: { anthropic: { deferLoading: true } }` on other tools
|
|
100
|
+
* to mark them for deferred loading.
|
|
101
|
+
*/
|
|
102
|
+
toolSearchBm25_20251119: anthropicTools.toolSearchBm25_20251119,
|
|
81
103
|
};
|
|
82
|
-
export interface GoogleVertexAnthropicProvider extends
|
|
104
|
+
export interface GoogleVertexAnthropicProvider extends ProviderV4 {
|
|
83
105
|
/**
|
|
84
106
|
* Creates a model for text generation.
|
|
85
107
|
*/
|
|
86
|
-
(modelId: GoogleVertexAnthropicMessagesModelId):
|
|
108
|
+
(modelId: GoogleVertexAnthropicMessagesModelId): LanguageModelV4;
|
|
87
109
|
|
|
88
110
|
/**
|
|
89
111
|
* Creates a model for text generation.
|
|
90
112
|
*/
|
|
91
|
-
languageModel(modelId: GoogleVertexAnthropicMessagesModelId):
|
|
113
|
+
languageModel(modelId: GoogleVertexAnthropicMessagesModelId): LanguageModelV4;
|
|
92
114
|
|
|
93
115
|
/**
|
|
94
116
|
* Anthropic tools supported by Google Vertex.
|
|
95
117
|
* Note: Only a subset of Anthropic tools are available on Vertex.
|
|
96
118
|
* Supported tools: bash_20241022, bash_20250124, textEditor_20241022,
|
|
97
119
|
* textEditor_20250124, textEditor_20250429, textEditor_20250728,
|
|
98
|
-
* computer_20241022, webSearch_20250305
|
|
120
|
+
* computer_20241022, webSearch_20250305, toolSearchRegex_20251119,
|
|
121
|
+
* toolSearchBm25_20251119
|
|
99
122
|
*/
|
|
100
123
|
tools: typeof vertexAnthropicTools;
|
|
101
124
|
|
|
@@ -179,6 +202,8 @@ export function createVertexAnthropic(
|
|
|
179
202
|
supportedUrls: () => ({}),
|
|
180
203
|
// force the use of JSON tool fallback for structured outputs since beta header isn't supported
|
|
181
204
|
supportsNativeStructuredOutput: false,
|
|
205
|
+
// Vertex Anthropic doesn't support strict mode on tool definitions.
|
|
206
|
+
supportsStrictTools: false,
|
|
182
207
|
});
|
|
183
208
|
|
|
184
209
|
const provider = function (modelId: GoogleVertexAnthropicMessagesModelId) {
|
|
@@ -191,7 +216,7 @@ export function createVertexAnthropic(
|
|
|
191
216
|
return createChatModel(modelId);
|
|
192
217
|
};
|
|
193
218
|
|
|
194
|
-
provider.specificationVersion = '
|
|
219
|
+
provider.specificationVersion = 'v4' as const;
|
|
195
220
|
provider.languageModel = createChatModel;
|
|
196
221
|
provider.chat = createChatModel;
|
|
197
222
|
provider.messages = createChatModel;
|
|
@@ -11,8 +11,7 @@ import {
|
|
|
11
11
|
|
|
12
12
|
export type { GoogleVertexProvider };
|
|
13
13
|
|
|
14
|
-
export interface GoogleVertexProviderSettings
|
|
15
|
-
extends GoogleVertexProviderSettingsOriginal {
|
|
14
|
+
export interface GoogleVertexProviderSettings extends GoogleVertexProviderSettingsOriginal {
|
|
16
15
|
/**
|
|
17
16
|
* Optional. The Google credentials for the Google Cloud service account. If
|
|
18
17
|
* not provided, the Google Vertex provider will use environment variables to
|