@ai-sdk/google-vertex 5.0.0-beta.10 → 5.0.0-beta.108
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 +930 -8
- package/README.md +65 -2
- package/dist/anthropic/edge/index.d.ts +18 -151
- package/dist/anthropic/edge/index.js +88 -70
- package/dist/anthropic/edge/index.js.map +1 -1
- package/dist/anthropic/index.d.ts +18 -151
- package/dist/anthropic/index.js +88 -81
- package/dist/anthropic/index.js.map +1 -1
- package/dist/edge/index.d.ts +58 -29
- package/dist/edge/index.js +581 -278
- package/dist/edge/index.js.map +1 -1
- package/dist/index.d.ts +70 -32
- package/dist/index.js +590 -296
- package/dist/index.js.map +1 -1
- package/dist/maas/edge/index.d.ts +76 -0
- package/dist/maas/edge/index.js +209 -0
- package/dist/maas/edge/index.js.map +1 -0
- package/dist/maas/index.d.ts +60 -0
- package/dist/maas/index.js +109 -0
- package/dist/maas/index.js.map +1 -0
- package/dist/xai/edge/index.d.ts +92 -0
- package/dist/xai/edge/index.js +259 -0
- package/dist/xai/edge/index.js.map +1 -0
- package/dist/xai/index.d.ts +76 -0
- package/dist/xai/index.js +159 -0
- package/dist/xai/index.js.map +1 -0
- package/docs/16-google-vertex.mdx +640 -102
- package/maas/edge.d.ts +1 -0
- package/maas/index.d.ts +1 -0
- package/package.json +49 -24
- package/src/anthropic/edge/google-vertex-anthropic-provider-edge.ts +17 -13
- package/src/anthropic/edge/index.ts +6 -2
- package/src/anthropic/{google-vertex-anthropic-messages-options.ts → google-vertex-anthropic-options.ts} +4 -1
- package/src/anthropic/google-vertex-anthropic-provider-node.ts +18 -13
- package/src/anthropic/google-vertex-anthropic-provider.ts +68 -19
- package/src/anthropic/index.ts +6 -2
- package/src/edge/google-vertex-provider-edge.ts +10 -12
- package/src/edge/index.ts +8 -1
- package/src/google-vertex-auth-google-auth-library.ts +13 -26
- package/src/google-vertex-config.ts +2 -2
- package/src/{google-vertex-embedding-options.ts → google-vertex-embedding-model-options.ts} +1 -0
- package/src/google-vertex-embedding-model.ts +35 -10
- package/src/google-vertex-image-model-options.ts +74 -0
- package/src/google-vertex-image-model.ts +106 -133
- package/src/google-vertex-options.ts +1 -1
- package/src/google-vertex-provider-base.ts +311 -0
- package/src/google-vertex-provider.ts +43 -233
- package/src/google-vertex-speech-model-options.ts +11 -0
- package/src/google-vertex-transcription-model-options.ts +46 -0
- package/src/google-vertex-transcription-model.ts +231 -0
- package/src/google-vertex-video-model-options.ts +49 -0
- package/src/google-vertex-video-model.ts +39 -75
- package/src/index.ts +20 -5
- package/src/maas/edge/google-vertex-maas-provider-edge.ts +64 -0
- package/src/maas/edge/index.ts +13 -0
- package/src/maas/google-vertex-maas-options.ts +15 -0
- package/src/maas/google-vertex-maas-provider-node.ts +65 -0
- package/src/maas/google-vertex-maas-provider.ts +122 -0
- package/src/maas/index.ts +13 -0
- package/src/xai/edge/google-vertex-xai-provider-edge.ts +61 -0
- package/src/xai/edge/index.ts +9 -0
- package/src/xai/google-vertex-xai-options.ts +7 -0
- package/src/xai/google-vertex-xai-provider-node.ts +62 -0
- package/src/xai/google-vertex-xai-provider.ts +212 -0
- package/src/xai/index.ts +9 -0
- package/xai/edge.d.ts +1 -0
- package/xai/index.d.ts +1 -0
- package/dist/anthropic/edge/index.d.mts +0 -231
- package/dist/anthropic/edge/index.mjs +0 -259
- package/dist/anthropic/edge/index.mjs.map +0 -1
- package/dist/anthropic/index.d.mts +0 -215
- package/dist/anthropic/index.mjs +0 -164
- package/dist/anthropic/index.mjs.map +0 -1
- package/dist/edge/index.d.mts +0 -160
- package/dist/edge/index.mjs +0 -1049
- package/dist/edge/index.mjs.map +0 -1
- package/dist/index.d.mts +0 -219
- package/dist/index.mjs +0 -960
- package/dist/index.mjs.map +0 -1
- package/src/google-vertex-provider-node.ts +0 -49
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,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/google-vertex",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.108",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"license": "Apache-2.0",
|
|
5
6
|
"sideEffects": false,
|
|
6
7
|
"main": "./dist/index.js",
|
|
7
|
-
"module": "./dist/index.mjs",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist/**/*",
|
|
@@ -18,7 +18,11 @@
|
|
|
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",
|
|
24
|
+
"xai/edge.d.ts",
|
|
25
|
+
"xai/index.d.ts"
|
|
22
26
|
],
|
|
23
27
|
"directories": {
|
|
24
28
|
"doc": "./docs"
|
|
@@ -27,53 +31,76 @@
|
|
|
27
31
|
"./package.json": "./package.json",
|
|
28
32
|
".": {
|
|
29
33
|
"types": "./dist/index.d.ts",
|
|
30
|
-
"import": "./dist/index.
|
|
31
|
-
"
|
|
34
|
+
"import": "./dist/index.js",
|
|
35
|
+
"default": "./dist/index.js"
|
|
32
36
|
},
|
|
33
37
|
"./edge": {
|
|
34
38
|
"types": "./dist/edge/index.d.ts",
|
|
35
|
-
"import": "./dist/edge/index.
|
|
36
|
-
"
|
|
39
|
+
"import": "./dist/edge/index.js",
|
|
40
|
+
"default": "./dist/edge/index.js"
|
|
37
41
|
},
|
|
38
42
|
"./anthropic": {
|
|
39
43
|
"types": "./dist/anthropic/index.d.ts",
|
|
40
|
-
"import": "./dist/anthropic/index.
|
|
41
|
-
"
|
|
44
|
+
"import": "./dist/anthropic/index.js",
|
|
45
|
+
"default": "./dist/anthropic/index.js"
|
|
42
46
|
},
|
|
43
47
|
"./anthropic/edge": {
|
|
44
48
|
"types": "./dist/anthropic/edge/index.d.ts",
|
|
45
|
-
"import": "./dist/anthropic/edge/index.
|
|
46
|
-
"
|
|
49
|
+
"import": "./dist/anthropic/edge/index.js",
|
|
50
|
+
"default": "./dist/anthropic/edge/index.js"
|
|
51
|
+
},
|
|
52
|
+
"./maas": {
|
|
53
|
+
"types": "./dist/maas/index.d.ts",
|
|
54
|
+
"import": "./dist/maas/index.js",
|
|
55
|
+
"default": "./dist/maas/index.js"
|
|
56
|
+
},
|
|
57
|
+
"./maas/edge": {
|
|
58
|
+
"types": "./dist/maas/edge/index.d.ts",
|
|
59
|
+
"import": "./dist/maas/edge/index.js",
|
|
60
|
+
"default": "./dist/maas/edge/index.js"
|
|
61
|
+
},
|
|
62
|
+
"./xai": {
|
|
63
|
+
"types": "./dist/xai/index.d.ts",
|
|
64
|
+
"import": "./dist/xai/index.js",
|
|
65
|
+
"default": "./dist/xai/index.js"
|
|
66
|
+
},
|
|
67
|
+
"./xai/edge": {
|
|
68
|
+
"types": "./dist/xai/edge/index.d.ts",
|
|
69
|
+
"import": "./dist/xai/edge/index.js",
|
|
70
|
+
"default": "./dist/xai/edge/index.js"
|
|
47
71
|
}
|
|
48
72
|
},
|
|
49
73
|
"dependencies": {
|
|
50
|
-
"google-auth-library": "^10.
|
|
51
|
-
"@ai-sdk/anthropic": "4.0.0-beta.
|
|
52
|
-
"@ai-sdk/
|
|
53
|
-
"@ai-sdk/
|
|
54
|
-
"@ai-sdk/provider
|
|
74
|
+
"google-auth-library": "^10.6.2",
|
|
75
|
+
"@ai-sdk/anthropic": "4.0.0-beta.67",
|
|
76
|
+
"@ai-sdk/google": "4.0.0-beta.82",
|
|
77
|
+
"@ai-sdk/openai-compatible": "3.0.0-beta.57",
|
|
78
|
+
"@ai-sdk/provider": "4.0.0-beta.19",
|
|
79
|
+
"@ai-sdk/provider-utils": "5.0.0-beta.49"
|
|
55
80
|
},
|
|
56
81
|
"devDependencies": {
|
|
57
|
-
"@types/node": "
|
|
58
|
-
"tsup": "^8",
|
|
82
|
+
"@types/node": "22.19.19",
|
|
83
|
+
"tsup": "^8.5.1",
|
|
59
84
|
"typescript": "5.8.3",
|
|
60
85
|
"zod": "3.25.76",
|
|
61
|
-
"@ai-sdk/test-server": "2.0.0-beta.
|
|
86
|
+
"@ai-sdk/test-server": "2.0.0-beta.7",
|
|
62
87
|
"@vercel/ai-tsconfig": "0.0.0"
|
|
63
88
|
},
|
|
64
89
|
"peerDependencies": {
|
|
65
90
|
"zod": "^3.25.76 || ^4.1.8"
|
|
66
91
|
},
|
|
67
92
|
"engines": {
|
|
68
|
-
"node": ">=
|
|
93
|
+
"node": ">=22"
|
|
69
94
|
},
|
|
70
95
|
"publishConfig": {
|
|
71
|
-
"access": "public"
|
|
96
|
+
"access": "public",
|
|
97
|
+
"provenance": true
|
|
72
98
|
},
|
|
73
99
|
"homepage": "https://ai-sdk.dev/docs",
|
|
74
100
|
"repository": {
|
|
75
101
|
"type": "git",
|
|
76
|
-
"url": "
|
|
102
|
+
"url": "https://github.com/vercel/ai",
|
|
103
|
+
"directory": "packages/google-vertex"
|
|
77
104
|
},
|
|
78
105
|
"bugs": {
|
|
79
106
|
"url": "https://github.com/vercel/ai/issues"
|
|
@@ -85,9 +112,7 @@
|
|
|
85
112
|
"build": "pnpm clean && tsup --tsconfig tsconfig.build.json",
|
|
86
113
|
"build:watch": "pnpm clean && tsup --watch",
|
|
87
114
|
"clean": "del-cli dist docs *.tsbuildinfo",
|
|
88
|
-
"lint": "eslint \"./**/*.ts*\"",
|
|
89
115
|
"type-check": "tsc --build",
|
|
90
|
-
"prettier-check": "prettier --check \"./**/*.ts*\"",
|
|
91
116
|
"test": "pnpm test:node && pnpm test:edge",
|
|
92
117
|
"test:update": "pnpm test:node -u",
|
|
93
118
|
"test:watch": "vitest --config vitest.node.config.js",
|
|
@@ -1,35 +1,39 @@
|
|
|
1
1
|
import { resolve } from '@ai-sdk/provider-utils';
|
|
2
2
|
import {
|
|
3
|
-
generateAuthToken,
|
|
4
|
-
GoogleCredentials,
|
|
3
|
+
generateAuthToken as defaultGenerateAuthToken,
|
|
4
|
+
type GoogleCredentials,
|
|
5
5
|
} from '../../edge/google-vertex-auth-edge';
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
GoogleVertexAnthropicProvider,
|
|
9
|
-
GoogleVertexAnthropicProviderSettings as GoogleVertexAnthropicProviderSettingsOriginal,
|
|
7
|
+
createGoogleVertexAnthropic as createVertexAnthropicOriginal,
|
|
8
|
+
type GoogleVertexAnthropicProvider,
|
|
9
|
+
type GoogleVertexAnthropicProviderSettings as GoogleVertexAnthropicProviderSettingsOriginal,
|
|
10
10
|
} from '../google-vertex-anthropic-provider';
|
|
11
|
-
|
|
12
11
|
export type { GoogleVertexAnthropicProvider };
|
|
13
12
|
|
|
14
|
-
export interface GoogleVertexAnthropicProviderSettings
|
|
15
|
-
extends GoogleVertexAnthropicProviderSettingsOriginal {
|
|
13
|
+
export interface GoogleVertexAnthropicProviderSettings extends GoogleVertexAnthropicProviderSettingsOriginal {
|
|
16
14
|
/**
|
|
17
15
|
* Optional. The Google credentials for the Google Cloud service account. If
|
|
18
16
|
* not provided, the Google Vertex provider will use environment variables to
|
|
19
17
|
* load the credentials.
|
|
20
18
|
*/
|
|
21
19
|
googleCredentials?: GoogleCredentials;
|
|
20
|
+
/**
|
|
21
|
+
* Optional. Override the Bearer token generator. Defaults to OAuth exchange
|
|
22
|
+
* with `googleCredentials`.
|
|
23
|
+
*/
|
|
24
|
+
generateAuthToken?: () => Promise<string>;
|
|
22
25
|
}
|
|
23
26
|
|
|
24
|
-
export function
|
|
27
|
+
export function createGoogleVertexAnthropic(
|
|
25
28
|
options: GoogleVertexAnthropicProviderSettings = {},
|
|
26
29
|
): GoogleVertexAnthropicProvider {
|
|
30
|
+
const generateAuthToken =
|
|
31
|
+
options.generateAuthToken ??
|
|
32
|
+
(() => defaultGenerateAuthToken(options.googleCredentials));
|
|
27
33
|
return createVertexAnthropicOriginal({
|
|
28
34
|
...options,
|
|
29
35
|
headers: async () => ({
|
|
30
|
-
Authorization: `Bearer ${await generateAuthToken(
|
|
31
|
-
options.googleCredentials,
|
|
32
|
-
)}`,
|
|
36
|
+
Authorization: `Bearer ${await generateAuthToken()}`,
|
|
33
37
|
...(await resolve(options.headers)),
|
|
34
38
|
}),
|
|
35
39
|
});
|
|
@@ -38,4 +42,4 @@ export function createVertexAnthropic(
|
|
|
38
42
|
/**
|
|
39
43
|
* Default Google Vertex AI Anthropic provider instance.
|
|
40
44
|
*/
|
|
41
|
-
export const
|
|
45
|
+
export const googleVertexAnthropic = createGoogleVertexAnthropic();
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
createGoogleVertexAnthropic,
|
|
3
|
+
/** @deprecated Use `createGoogleVertexAnthropic` instead. */
|
|
4
|
+
createGoogleVertexAnthropic as createVertexAnthropic,
|
|
5
|
+
googleVertexAnthropic,
|
|
6
|
+
/** @deprecated Use `googleVertexAnthropic` instead. */
|
|
7
|
+
googleVertexAnthropic as vertexAnthropic,
|
|
4
8
|
} from './google-vertex-anthropic-provider-edge';
|
|
5
9
|
export type {
|
|
6
10
|
GoogleVertexAnthropicProviderSettings,
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
// https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/claude
|
|
2
|
-
export type
|
|
2
|
+
export type GoogleVertexAnthropicModelId =
|
|
3
|
+
| 'claude-fable-5'
|
|
4
|
+
| 'claude-opus-4-8'
|
|
5
|
+
| 'claude-opus-4-7'
|
|
3
6
|
| 'claude-opus-4-6'
|
|
4
7
|
| 'claude-sonnet-4-6'
|
|
5
8
|
| 'claude-opus-4-5@20251101'
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { resolve } from '@ai-sdk/provider-utils';
|
|
2
|
-
import { GoogleAuthOptions } from 'google-auth-library';
|
|
3
|
-
import {
|
|
2
|
+
import type { GoogleAuthOptions } from 'google-auth-library';
|
|
3
|
+
import { createAuthTokenGenerator } from '../google-vertex-auth-google-auth-library';
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
GoogleVertexAnthropicProvider,
|
|
7
|
-
GoogleVertexAnthropicProviderSettings as GoogleVertexAnthropicProviderSettingsOriginal,
|
|
5
|
+
createGoogleVertexAnthropic as createVertexAnthropicOriginal,
|
|
6
|
+
type GoogleVertexAnthropicProvider,
|
|
7
|
+
type GoogleVertexAnthropicProviderSettings as GoogleVertexAnthropicProviderSettingsOriginal,
|
|
8
8
|
} from './google-vertex-anthropic-provider';
|
|
9
|
-
|
|
10
9
|
export type { GoogleVertexAnthropicProvider };
|
|
11
10
|
|
|
12
|
-
export interface GoogleVertexAnthropicProviderSettings
|
|
13
|
-
extends GoogleVertexAnthropicProviderSettingsOriginal {
|
|
11
|
+
export interface GoogleVertexAnthropicProviderSettings extends GoogleVertexAnthropicProviderSettingsOriginal {
|
|
14
12
|
/**
|
|
15
13
|
* Optional. The Authentication options provided by google-auth-library.
|
|
16
14
|
* Complete list of authentication options is documented in the
|
|
@@ -18,17 +16,24 @@ export interface GoogleVertexAnthropicProviderSettings
|
|
|
18
16
|
* https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts.
|
|
19
17
|
*/
|
|
20
18
|
googleAuthOptions?: GoogleAuthOptions;
|
|
19
|
+
/**
|
|
20
|
+
* Optional. Override the Bearer token generator. Defaults to OAuth exchange
|
|
21
|
+
* via `google-auth-library` with `googleAuthOptions`.
|
|
22
|
+
*/
|
|
23
|
+
generateAuthToken?: () => Promise<string | null>;
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
export function
|
|
26
|
+
export function createGoogleVertexAnthropic(
|
|
24
27
|
options: GoogleVertexAnthropicProviderSettings = {},
|
|
25
28
|
): GoogleVertexAnthropicProvider {
|
|
29
|
+
const generateAuthToken =
|
|
30
|
+
options.generateAuthToken ??
|
|
31
|
+
createAuthTokenGenerator(options.googleAuthOptions);
|
|
32
|
+
|
|
26
33
|
return createVertexAnthropicOriginal({
|
|
27
34
|
...options,
|
|
28
35
|
headers: async () => ({
|
|
29
|
-
Authorization: `Bearer ${await generateAuthToken(
|
|
30
|
-
options.googleAuthOptions,
|
|
31
|
-
)}`,
|
|
36
|
+
Authorization: `Bearer ${await generateAuthToken()}`,
|
|
32
37
|
...(await resolve(options.headers)),
|
|
33
38
|
}),
|
|
34
39
|
});
|
|
@@ -37,4 +42,4 @@ export function createVertexAnthropic(
|
|
|
37
42
|
/**
|
|
38
43
|
* Default Google Vertex Anthropic provider instance.
|
|
39
44
|
*/
|
|
40
|
-
export const
|
|
45
|
+
export const googleVertexAnthropic = createGoogleVertexAnthropic();
|
|
@@ -1,25 +1,39 @@
|
|
|
1
1
|
import {
|
|
2
|
-
LanguageModelV4,
|
|
3
2
|
NoSuchModelError,
|
|
4
|
-
|
|
3
|
+
type LanguageModelV4,
|
|
4
|
+
type ProviderV4,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import {
|
|
7
|
-
FetchFunction,
|
|
8
|
-
Resolvable,
|
|
9
7
|
loadOptionalSetting,
|
|
10
8
|
withoutTrailingSlash,
|
|
9
|
+
type FetchFunction,
|
|
10
|
+
type Resolvable,
|
|
11
11
|
} from '@ai-sdk/provider-utils';
|
|
12
12
|
import {
|
|
13
13
|
anthropicTools,
|
|
14
|
-
|
|
14
|
+
AnthropicLanguageModel,
|
|
15
15
|
} from '@ai-sdk/anthropic/internal';
|
|
16
|
-
import {
|
|
16
|
+
import type { GoogleVertexAnthropicModelId } from './google-vertex-anthropic-options';
|
|
17
|
+
|
|
18
|
+
type GoogleVertexAnthropicTools = Pick<
|
|
19
|
+
typeof anthropicTools,
|
|
20
|
+
| 'bash_20241022'
|
|
21
|
+
| 'bash_20250124'
|
|
22
|
+
| 'textEditor_20241022'
|
|
23
|
+
| 'textEditor_20250124'
|
|
24
|
+
| 'textEditor_20250429'
|
|
25
|
+
| 'textEditor_20250728'
|
|
26
|
+
| 'computer_20241022'
|
|
27
|
+
| 'webSearch_20250305'
|
|
28
|
+
| 'toolSearchRegex_20251119'
|
|
29
|
+
| 'toolSearchBm25_20251119'
|
|
30
|
+
>;
|
|
17
31
|
|
|
18
32
|
/**
|
|
19
33
|
* Tools supported by Google Vertex Anthropic.
|
|
20
34
|
* This is a subset of the full Anthropic tools - only these are recognized by the Vertex API.
|
|
21
35
|
*/
|
|
22
|
-
export const
|
|
36
|
+
export const googleVertexAnthropicTools: GoogleVertexAnthropicTools = {
|
|
23
37
|
/**
|
|
24
38
|
* The bash tool enables Claude to execute shell commands in a persistent bash session,
|
|
25
39
|
* allowing system operations, script execution, and command-line automation.
|
|
@@ -78,26 +92,49 @@ export const vertexAnthropicTools = {
|
|
|
78
92
|
* Creates a web search tool that gives Claude direct access to real-time web content.
|
|
79
93
|
*/
|
|
80
94
|
webSearch_20250305: anthropicTools.webSearch_20250305,
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Creates a tool search tool that uses regex patterns to find tools.
|
|
98
|
+
*
|
|
99
|
+
* The tool search tool enables Claude to work with hundreds or thousands of tools
|
|
100
|
+
* by dynamically discovering and loading them on-demand.
|
|
101
|
+
*
|
|
102
|
+
* Use `providerOptions: { anthropic: { deferLoading: true } }` on other tools
|
|
103
|
+
* to mark them for deferred loading.
|
|
104
|
+
*/
|
|
105
|
+
toolSearchRegex_20251119: anthropicTools.toolSearchRegex_20251119,
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Creates a tool search tool that uses BM25 (natural language) to find tools.
|
|
109
|
+
*
|
|
110
|
+
* The tool search tool enables Claude to work with hundreds or thousands of tools
|
|
111
|
+
* by dynamically discovering and loading them on-demand.
|
|
112
|
+
*
|
|
113
|
+
* Use `providerOptions: { anthropic: { deferLoading: true } }` on other tools
|
|
114
|
+
* to mark them for deferred loading.
|
|
115
|
+
*/
|
|
116
|
+
toolSearchBm25_20251119: anthropicTools.toolSearchBm25_20251119,
|
|
81
117
|
};
|
|
82
118
|
export interface GoogleVertexAnthropicProvider extends ProviderV4 {
|
|
83
119
|
/**
|
|
84
120
|
* Creates a model for text generation.
|
|
85
121
|
*/
|
|
86
|
-
(modelId:
|
|
122
|
+
(modelId: GoogleVertexAnthropicModelId): LanguageModelV4;
|
|
87
123
|
|
|
88
124
|
/**
|
|
89
125
|
* Creates a model for text generation.
|
|
90
126
|
*/
|
|
91
|
-
languageModel(modelId:
|
|
127
|
+
languageModel(modelId: GoogleVertexAnthropicModelId): LanguageModelV4;
|
|
92
128
|
|
|
93
129
|
/**
|
|
94
130
|
* Anthropic tools supported by Google Vertex.
|
|
95
131
|
* Note: Only a subset of Anthropic tools are available on Vertex.
|
|
96
132
|
* Supported tools: bash_20241022, bash_20250124, textEditor_20241022,
|
|
97
133
|
* textEditor_20250124, textEditor_20250429, textEditor_20250728,
|
|
98
|
-
* computer_20241022, webSearch_20250305
|
|
134
|
+
* computer_20241022, webSearch_20250305, toolSearchRegex_20251119,
|
|
135
|
+
* toolSearchBm25_20251119
|
|
99
136
|
*/
|
|
100
|
-
tools: typeof
|
|
137
|
+
tools: typeof googleVertexAnthropicTools;
|
|
101
138
|
|
|
102
139
|
/**
|
|
103
140
|
* @deprecated Use `embeddingModel` instead.
|
|
@@ -137,7 +174,7 @@ export interface GoogleVertexAnthropicProviderSettings {
|
|
|
137
174
|
/**
|
|
138
175
|
* Create a Google Vertex Anthropic provider instance.
|
|
139
176
|
*/
|
|
140
|
-
export function
|
|
177
|
+
export function createGoogleVertexAnthropic(
|
|
141
178
|
options: GoogleVertexAnthropicProviderSettings = {},
|
|
142
179
|
): GoogleVertexAnthropicProvider {
|
|
143
180
|
const getBaseURL = () => {
|
|
@@ -150,15 +187,25 @@ export function createVertexAnthropic(
|
|
|
150
187
|
environmentVariableName: 'GOOGLE_VERTEX_PROJECT',
|
|
151
188
|
});
|
|
152
189
|
|
|
190
|
+
const getHost = () => {
|
|
191
|
+
if (location === 'global') {
|
|
192
|
+
return 'aiplatform.googleapis.com';
|
|
193
|
+
} else if (location === 'eu' || location === 'us') {
|
|
194
|
+
return `aiplatform.${location}.rep.googleapis.com`;
|
|
195
|
+
} else {
|
|
196
|
+
return `${location}-aiplatform.googleapis.com`;
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
153
200
|
return (
|
|
154
201
|
withoutTrailingSlash(options.baseURL) ??
|
|
155
|
-
`https://${
|
|
202
|
+
`https://${getHost()}/v1/projects/${project}/locations/${location}/publishers/anthropic/models`
|
|
156
203
|
);
|
|
157
204
|
};
|
|
158
205
|
|
|
159
|
-
const createChatModel = (modelId:
|
|
160
|
-
new
|
|
161
|
-
provider: '
|
|
206
|
+
const createChatModel = (modelId: GoogleVertexAnthropicModelId) =>
|
|
207
|
+
new AnthropicLanguageModel(modelId, {
|
|
208
|
+
provider: 'googleVertex.anthropic.messages',
|
|
162
209
|
baseURL: getBaseURL(),
|
|
163
210
|
headers: options.headers ?? {},
|
|
164
211
|
fetch: options.fetch,
|
|
@@ -169,7 +216,7 @@ export function createVertexAnthropic(
|
|
|
169
216
|
}`,
|
|
170
217
|
transformRequestBody: args => {
|
|
171
218
|
// Remove model from args and add anthropic version
|
|
172
|
-
const { model, ...rest } = args;
|
|
219
|
+
const { model: _model, ...rest } = args;
|
|
173
220
|
return {
|
|
174
221
|
...rest,
|
|
175
222
|
anthropic_version: 'vertex-2023-10-16',
|
|
@@ -179,9 +226,11 @@ export function createVertexAnthropic(
|
|
|
179
226
|
supportedUrls: () => ({}),
|
|
180
227
|
// force the use of JSON tool fallback for structured outputs since beta header isn't supported
|
|
181
228
|
supportsNativeStructuredOutput: false,
|
|
229
|
+
// Vertex Anthropic doesn't support strict mode on tool definitions.
|
|
230
|
+
supportsStrictTools: false,
|
|
182
231
|
});
|
|
183
232
|
|
|
184
|
-
const provider = function (modelId:
|
|
233
|
+
const provider = function (modelId: GoogleVertexAnthropicModelId) {
|
|
185
234
|
if (new.target) {
|
|
186
235
|
throw new Error(
|
|
187
236
|
'The Anthropic model function cannot be called with the new keyword.',
|
|
@@ -204,7 +253,7 @@ export function createVertexAnthropic(
|
|
|
204
253
|
throw new NoSuchModelError({ modelId, modelType: 'imageModel' });
|
|
205
254
|
};
|
|
206
255
|
|
|
207
|
-
provider.tools =
|
|
256
|
+
provider.tools = googleVertexAnthropicTools;
|
|
208
257
|
|
|
209
258
|
return provider;
|
|
210
259
|
}
|
package/src/anthropic/index.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
googleVertexAnthropic,
|
|
3
|
+
/** @deprecated Use `googleVertexAnthropic` instead. */
|
|
4
|
+
googleVertexAnthropic as vertexAnthropic,
|
|
5
|
+
createGoogleVertexAnthropic,
|
|
6
|
+
/** @deprecated Use `createGoogleVertexAnthropic` instead. */
|
|
7
|
+
createGoogleVertexAnthropic as createVertexAnthropic,
|
|
4
8
|
} from './google-vertex-anthropic-provider-node';
|
|
5
9
|
export type {
|
|
6
10
|
GoogleVertexAnthropicProvider,
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { loadOptionalSetting, resolve } from '@ai-sdk/provider-utils';
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
GoogleVertexProvider,
|
|
5
|
-
GoogleVertexProviderSettings as GoogleVertexProviderSettingsOriginal,
|
|
6
|
-
} from '../google-vertex-provider';
|
|
3
|
+
createGoogleVertex as createGoogleVertexOriginal,
|
|
4
|
+
type GoogleVertexProvider,
|
|
5
|
+
type GoogleVertexProviderSettings as GoogleVertexProviderSettingsOriginal,
|
|
6
|
+
} from '../google-vertex-provider-base';
|
|
7
7
|
import {
|
|
8
8
|
generateAuthToken,
|
|
9
|
-
GoogleCredentials,
|
|
9
|
+
type GoogleCredentials,
|
|
10
10
|
} from './google-vertex-auth-edge';
|
|
11
|
-
|
|
12
11
|
export type { GoogleVertexProvider };
|
|
13
12
|
|
|
14
|
-
export interface GoogleVertexProviderSettings
|
|
15
|
-
extends GoogleVertexProviderSettingsOriginal {
|
|
13
|
+
export interface GoogleVertexProviderSettings extends GoogleVertexProviderSettingsOriginal {
|
|
16
14
|
/**
|
|
17
15
|
* Optional. The Google credentials for the Google Cloud service account. If
|
|
18
16
|
* not provided, the Google Vertex provider will use environment variables to
|
|
@@ -21,7 +19,7 @@ export interface GoogleVertexProviderSettings
|
|
|
21
19
|
googleCredentials?: GoogleCredentials;
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
export function
|
|
22
|
+
export function createGoogleVertex(
|
|
25
23
|
options: GoogleVertexProviderSettings = {},
|
|
26
24
|
): GoogleVertexProvider {
|
|
27
25
|
const apiKey = loadOptionalSetting({
|
|
@@ -30,10 +28,10 @@ export function createVertex(
|
|
|
30
28
|
});
|
|
31
29
|
|
|
32
30
|
if (apiKey) {
|
|
33
|
-
return
|
|
31
|
+
return createGoogleVertexOriginal(options);
|
|
34
32
|
}
|
|
35
33
|
|
|
36
|
-
return
|
|
34
|
+
return createGoogleVertexOriginal({
|
|
37
35
|
...options,
|
|
38
36
|
headers: async () => ({
|
|
39
37
|
Authorization: `Bearer ${await generateAuthToken(
|
|
@@ -47,4 +45,4 @@ export function createVertex(
|
|
|
47
45
|
/**
|
|
48
46
|
* Default Google Vertex AI provider instance.
|
|
49
47
|
*/
|
|
50
|
-
export const
|
|
48
|
+
export const googleVertex = createGoogleVertex();
|
package/src/edge/index.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {
|
|
2
|
+
createGoogleVertex,
|
|
3
|
+
/** @deprecated Use `createGoogleVertex` instead. */
|
|
4
|
+
createGoogleVertex as createVertex,
|
|
5
|
+
googleVertex,
|
|
6
|
+
/** @deprecated Use `googleVertex` instead. */
|
|
7
|
+
googleVertex as vertex,
|
|
8
|
+
} from './google-vertex-provider-edge';
|
|
2
9
|
export type {
|
|
3
10
|
GoogleVertexProviderSettings,
|
|
4
11
|
GoogleVertexProvider,
|
|
@@ -1,27 +1,14 @@
|
|
|
1
|
-
import { GoogleAuth, GoogleAuthOptions } from 'google-auth-library';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
return authInstance;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export async function generateAuthToken(options?: GoogleAuthOptions) {
|
|
18
|
-
const auth = getAuth(options || {});
|
|
19
|
-
const client = await auth.getClient();
|
|
20
|
-
const token = await client.getAccessToken();
|
|
21
|
-
return token?.token || null;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// For testing purposes only
|
|
25
|
-
export function _resetAuthInstance() {
|
|
26
|
-
authInstance = null;
|
|
1
|
+
import { GoogleAuth, type GoogleAuthOptions } from 'google-auth-library';
|
|
2
|
+
|
|
3
|
+
export function createAuthTokenGenerator(options?: GoogleAuthOptions) {
|
|
4
|
+
const auth = new GoogleAuth({
|
|
5
|
+
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
|
|
6
|
+
...options,
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
return async function generateAuthToken() {
|
|
10
|
+
const client = await auth.getClient();
|
|
11
|
+
const token = await client.getAccessToken();
|
|
12
|
+
return token?.token ?? null;
|
|
13
|
+
};
|
|
27
14
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { FetchFunction, Resolvable } from '@ai-sdk/provider-utils';
|
|
1
|
+
import type { FetchFunction, Resolvable } from '@ai-sdk/provider-utils';
|
|
2
2
|
|
|
3
3
|
export interface GoogleVertexConfig {
|
|
4
4
|
provider: string;
|
|
5
5
|
baseURL: string;
|
|
6
|
-
headers
|
|
6
|
+
headers?: Resolvable<Record<string, string | undefined>>;
|
|
7
7
|
fetch?: FetchFunction;
|
|
8
8
|
}
|