@ai-sdk/google-vertex 5.0.98 → 5.0.99
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 +13 -0
- package/dist/anthropic/edge/index.d.ts +84 -80
- package/dist/anthropic/edge/index.d.ts.map +1 -0
- package/dist/anthropic/edge/index.js +232 -272
- package/dist/anthropic/edge/index.js.map +1 -1
- package/dist/anthropic/index.d.ts +69 -66
- package/dist/anthropic/index.d.ts.map +1 -0
- package/dist/anthropic/index.js +166 -177
- package/dist/anthropic/index.js.map +1 -1
- package/dist/edge/index.d.ts +206 -194
- package/dist/edge/index.d.ts.map +1 -0
- package/dist/edge/index.js +1408 -1846
- package/dist/edge/index.js.map +1 -1
- package/dist/index.d.ts +265 -252
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1349 -1761
- package/dist/index.js.map +1 -1
- package/dist/maas/edge/index.d.ts +62 -59
- package/dist/maas/edge/index.d.ts.map +1 -0
- package/dist/maas/edge/index.js +166 -196
- package/dist/maas/edge/index.js.map +1 -1
- package/dist/maas/index.d.ts +47 -45
- package/dist/maas/index.d.ts.map +1 -0
- package/dist/maas/index.js +101 -102
- package/dist/maas/index.js.map +1 -1
- package/dist/xai/edge/index.d.ts +77 -73
- package/dist/xai/edge/index.d.ts.map +1 -0
- package/dist/xai/edge/index.js +203 -235
- package/dist/xai/edge/index.js.map +1 -1
- package/dist/xai/index.d.ts +62 -59
- package/dist/xai/index.d.ts.map +1 -0
- package/dist/xai/index.js +138 -141
- package/dist/xai/index.js.map +1 -1
- package/docs/16-google-vertex.mdx +3 -3
- package/package.json +11 -11
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { anthropicTools } from
|
|
5
|
-
|
|
1
|
+
import { FetchFunction, Resolvable } from "@ai-sdk/provider-utils";
|
|
2
|
+
import { GoogleAuthOptions } from "google-auth-library";
|
|
3
|
+
import { LanguageModelV4, ProviderV4 } from "@ai-sdk/provider";
|
|
4
|
+
import { anthropicTools } from "@ai-sdk/anthropic/internal";
|
|
5
|
+
//#region src/anthropic/google-vertex-anthropic-options.d.ts
|
|
6
6
|
type GoogleVertexAnthropicModelId = 'claude-sonnet-5' | 'claude-sonnet-5-5' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-opus-5' | 'claude-opus-5-5' | 'claude-opus-4-8' | 'claude-opus-4-7' | 'claude-opus-4-6' | 'claude-sonnet-4-6' | 'claude-opus-4-5@20251101' | 'claude-sonnet-4-5@20250929' | 'claude-opus-4-1@20250805' | 'claude-opus-4@20250514' | 'claude-sonnet-4@20250514' | 'claude-3-7-sonnet@20250219' | 'claude-3-5-sonnet-v2@20241022' | 'claude-3-5-haiku@20241022' | 'claude-3-5-sonnet@20240620' | 'claude-3-haiku@20240307' | 'claude-3-sonnet@20240229' | 'claude-3-opus@20240229' | (string & {});
|
|
7
|
-
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/anthropic/google-vertex-anthropic-provider.d.ts
|
|
8
9
|
type GoogleVertexAnthropicTools = Pick<typeof anthropicTools, 'bash_20241022' | 'bash_20250124' | 'textEditor_20241022' | 'textEditor_20250124' | 'textEditor_20250429' | 'textEditor_20250728' | 'computer_20241022' | 'webSearch_20250305' | 'toolSearchRegex_20251119' | 'toolSearchBm25_20251119'>;
|
|
9
10
|
/**
|
|
10
11
|
* Tools supported by Google Vertex Anthropic.
|
|
@@ -12,71 +13,73 @@ type GoogleVertexAnthropicTools = Pick<typeof anthropicTools, 'bash_20241022' |
|
|
|
12
13
|
*/
|
|
13
14
|
declare const googleVertexAnthropicTools: GoogleVertexAnthropicTools;
|
|
14
15
|
interface GoogleVertexAnthropicProvider extends ProviderV4 {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Creates a model for text generation.
|
|
18
|
+
*/
|
|
19
|
+
(modelId: GoogleVertexAnthropicModelId): LanguageModelV4;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a model for text generation.
|
|
22
|
+
*/
|
|
23
|
+
languageModel(modelId: GoogleVertexAnthropicModelId): LanguageModelV4;
|
|
24
|
+
/**
|
|
25
|
+
* Anthropic tools supported by Google Vertex.
|
|
26
|
+
* Note: Only a subset of Anthropic tools are available on Vertex.
|
|
27
|
+
* Supported tools: bash_20241022, bash_20250124, textEditor_20241022,
|
|
28
|
+
* textEditor_20250124, textEditor_20250429, textEditor_20250728,
|
|
29
|
+
* computer_20241022, webSearch_20250305, toolSearchRegex_20251119,
|
|
30
|
+
* toolSearchBm25_20251119
|
|
31
|
+
*/
|
|
32
|
+
tools: typeof googleVertexAnthropicTools;
|
|
33
|
+
/**
|
|
34
|
+
* @deprecated Use `embeddingModel` instead.
|
|
35
|
+
*/
|
|
36
|
+
textEmbeddingModel(modelId: string): never;
|
|
36
37
|
}
|
|
37
38
|
interface GoogleVertexAnthropicProviderSettings$1 {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Google Cloud project ID. Defaults to the value of the `GOOGLE_VERTEX_PROJECT` environment variable.
|
|
41
|
+
*/
|
|
42
|
+
project?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Google Cloud region. Defaults to the value of the `GOOGLE_VERTEX_LOCATION` environment variable.
|
|
45
|
+
*/
|
|
46
|
+
location?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
49
|
+
* The default prefix is `https://api.anthropic.com/v1`.
|
|
50
|
+
*/
|
|
51
|
+
baseURL?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Custom headers to include in the requests.
|
|
54
|
+
*/
|
|
55
|
+
headers?: Resolvable<Record<string, string | undefined>>;
|
|
56
|
+
/**
|
|
57
|
+
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
58
|
+
* or to provide a custom fetch implementation for e.g. testing.
|
|
59
|
+
*/
|
|
60
|
+
fetch?: FetchFunction;
|
|
60
61
|
}
|
|
61
|
-
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/anthropic/google-vertex-anthropic-provider-node.d.ts
|
|
62
64
|
interface GoogleVertexAnthropicProviderSettings extends GoogleVertexAnthropicProviderSettings$1 {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Optional. The Authentication options provided by google-auth-library.
|
|
67
|
+
* Complete list of authentication options is documented in the
|
|
68
|
+
* GoogleAuthOptions interface:
|
|
69
|
+
* https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts.
|
|
70
|
+
*/
|
|
71
|
+
googleAuthOptions?: GoogleAuthOptions;
|
|
72
|
+
/**
|
|
73
|
+
* Optional. Override the Bearer token generator. Defaults to OAuth exchange
|
|
74
|
+
* via `google-auth-library` with `googleAuthOptions`.
|
|
75
|
+
*/
|
|
76
|
+
generateAuthToken?: () => Promise<string | null>;
|
|
75
77
|
}
|
|
76
|
-
declare function createGoogleVertexAnthropic(options?: GoogleVertexAnthropicProviderSettings): GoogleVertexAnthropicProvider;
|
|
78
|
+
export declare function createGoogleVertexAnthropic(options?: GoogleVertexAnthropicProviderSettings): GoogleVertexAnthropicProvider;
|
|
77
79
|
/**
|
|
78
80
|
* Default Google Vertex Anthropic provider instance.
|
|
79
81
|
*/
|
|
80
|
-
declare const googleVertexAnthropic: GoogleVertexAnthropicProvider;
|
|
81
|
-
|
|
82
|
-
export { type GoogleVertexAnthropicProvider, type GoogleVertexAnthropicProviderSettings, createGoogleVertexAnthropic
|
|
82
|
+
export declare const googleVertexAnthropic: GoogleVertexAnthropicProvider;
|
|
83
|
+
//#endregion
|
|
84
|
+
export { type GoogleVertexAnthropicProvider, type GoogleVertexAnthropicProviderSettings, createGoogleVertexAnthropic as createVertexAnthropic, googleVertexAnthropic as vertexAnthropic };
|
|
85
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["GoogleVertexAnthropicProviderSettings","GoogleVertexAnthropicProviderSettingsOriginal"],"sources":["../../src/anthropic/google-vertex-anthropic-options.ts","../../src/anthropic/google-vertex-anthropic-provider.ts","../../src/anthropic/google-vertex-anthropic-provider-node.ts"],"mappings":";;;;;KACY;;;KCgBP,6BAA6B,YACzB;;;;;cAiBI,4BAA4B;UAkFxB,sCAAsC;;;;GAIpD,SAAS,+BAA+B;;;;EAKzC,cAAc,SAAS,+BAA+B;;;;;;;;;EAUtD,cAAc;;;;EAKd,mBAAmB;;UAGJA;;;;EAIf;;;;EAKA;;;;;EAMA;;;;EAKA,UAAU,WAAW;;;;;EAMrB,QAAQ;;;;UChKO,8CAA8CC;;;;;;;EAO7D,oBAAoB;;;;;EAKpB,0BAA0B;;wBAGZ,4BACd,UAAS,wCACR;;;;qBAiBU,uBAAqB"}
|
package/dist/anthropic/index.js
CHANGED
|
@@ -1,185 +1,174 @@
|
|
|
1
|
-
|
|
2
|
-
import { resolve } from "@ai-sdk/provider-utils";
|
|
3
|
-
|
|
4
|
-
// src/google-vertex-auth-google-auth-library.ts
|
|
1
|
+
import { loadOptionalSetting, resolve, withoutTrailingSlash } from "@ai-sdk/provider-utils";
|
|
5
2
|
import { GoogleAuth } from "google-auth-library";
|
|
3
|
+
import { NoSuchModelError } from "@ai-sdk/provider";
|
|
4
|
+
import { AnthropicLanguageModel, anthropicTools } from "@ai-sdk/anthropic/internal";
|
|
5
|
+
//#region src/google-vertex-auth-google-auth-library.ts
|
|
6
6
|
function createAuthTokenGenerator(options) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return token?.token ?? null;
|
|
15
|
-
};
|
|
7
|
+
const auth = new GoogleAuth({
|
|
8
|
+
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
|
|
9
|
+
...options
|
|
10
|
+
});
|
|
11
|
+
return async function generateAuthToken() {
|
|
12
|
+
return (await (await auth.getClient()).getAccessToken())?.token ?? null;
|
|
13
|
+
};
|
|
16
14
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
* The tool search tool enables Claude to work with hundreds or thousands of tools
|
|
96
|
-
* by dynamically discovering and loading them on-demand.
|
|
97
|
-
*
|
|
98
|
-
* Use `providerOptions: { anthropic: { deferLoading: true } }` on other tools
|
|
99
|
-
* to mark them for deferred loading.
|
|
100
|
-
*/
|
|
101
|
-
toolSearchBm25_20251119: anthropicTools.toolSearchBm25_20251119
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/anthropic/google-vertex-anthropic-provider.ts
|
|
17
|
+
/**
|
|
18
|
+
* Tools supported by Google Vertex Anthropic.
|
|
19
|
+
* This is a subset of the full Anthropic tools - only these are recognized by the Vertex API.
|
|
20
|
+
*/
|
|
21
|
+
const googleVertexAnthropicTools = {
|
|
22
|
+
/**
|
|
23
|
+
* The bash tool enables Claude to execute shell commands in a persistent bash session,
|
|
24
|
+
* allowing system operations, script execution, and command-line automation.
|
|
25
|
+
*
|
|
26
|
+
* Image results are supported.
|
|
27
|
+
*/
|
|
28
|
+
bash_20241022: anthropicTools.bash_20241022,
|
|
29
|
+
/**
|
|
30
|
+
* The bash tool enables Claude to execute shell commands in a persistent bash session,
|
|
31
|
+
* allowing system operations, script execution, and command-line automation.
|
|
32
|
+
*
|
|
33
|
+
* Image results are supported.
|
|
34
|
+
*/
|
|
35
|
+
bash_20250124: anthropicTools.bash_20250124,
|
|
36
|
+
/**
|
|
37
|
+
* Claude can use an Anthropic-defined text editor tool to view and modify text files,
|
|
38
|
+
* helping you debug, fix, and improve your code or other text documents.
|
|
39
|
+
*
|
|
40
|
+
* Supported models: Claude Sonnet 3.5
|
|
41
|
+
*/
|
|
42
|
+
textEditor_20241022: anthropicTools.textEditor_20241022,
|
|
43
|
+
/**
|
|
44
|
+
* Claude can use an Anthropic-defined text editor tool to view and modify text files,
|
|
45
|
+
* helping you debug, fix, and improve your code or other text documents.
|
|
46
|
+
*
|
|
47
|
+
* Supported models: Claude Sonnet 3.7
|
|
48
|
+
*/
|
|
49
|
+
textEditor_20250124: anthropicTools.textEditor_20250124,
|
|
50
|
+
/**
|
|
51
|
+
* Claude can use an Anthropic-defined text editor tool to view and modify text files.
|
|
52
|
+
* Note: This version does not support the "undo_edit" command.
|
|
53
|
+
* @deprecated Use textEditor_20250728 instead
|
|
54
|
+
*/
|
|
55
|
+
textEditor_20250429: anthropicTools.textEditor_20250429,
|
|
56
|
+
/**
|
|
57
|
+
* Claude can use an Anthropic-defined text editor tool to view and modify text files.
|
|
58
|
+
* Note: This version does not support the "undo_edit" command and adds optional max_characters parameter.
|
|
59
|
+
* Supported models: Claude Sonnet 4, Opus 4, and Opus 4.1
|
|
60
|
+
*/
|
|
61
|
+
textEditor_20250728: anthropicTools.textEditor_20250728,
|
|
62
|
+
/**
|
|
63
|
+
* Claude can interact with computer environments through the computer use tool, which
|
|
64
|
+
* provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.
|
|
65
|
+
*
|
|
66
|
+
* Image results are supported.
|
|
67
|
+
*/
|
|
68
|
+
computer_20241022: anthropicTools.computer_20241022,
|
|
69
|
+
/**
|
|
70
|
+
* Creates a web search tool that gives Claude direct access to real-time web content.
|
|
71
|
+
*/
|
|
72
|
+
webSearch_20250305: anthropicTools.webSearch_20250305,
|
|
73
|
+
/**
|
|
74
|
+
* Creates a tool search tool that uses regex patterns to find tools.
|
|
75
|
+
*
|
|
76
|
+
* The tool search tool enables Claude to work with hundreds or thousands of tools
|
|
77
|
+
* by dynamically discovering and loading them on-demand.
|
|
78
|
+
*
|
|
79
|
+
* Use `providerOptions: { anthropic: { deferLoading: true } }` on other tools
|
|
80
|
+
* to mark them for deferred loading.
|
|
81
|
+
*/
|
|
82
|
+
toolSearchRegex_20251119: anthropicTools.toolSearchRegex_20251119,
|
|
83
|
+
/**
|
|
84
|
+
* Creates a tool search tool that uses BM25 (natural language) to find tools.
|
|
85
|
+
*
|
|
86
|
+
* The tool search tool enables Claude to work with hundreds or thousands of tools
|
|
87
|
+
* by dynamically discovering and loading them on-demand.
|
|
88
|
+
*
|
|
89
|
+
* Use `providerOptions: { anthropic: { deferLoading: true } }` on other tools
|
|
90
|
+
* to mark them for deferred loading.
|
|
91
|
+
*/
|
|
92
|
+
toolSearchBm25_20251119: anthropicTools.toolSearchBm25_20251119
|
|
102
93
|
};
|
|
94
|
+
/**
|
|
95
|
+
* Create a Google Vertex Anthropic provider instance.
|
|
96
|
+
*/
|
|
97
|
+
function createGoogleVertexAnthropic$1(options = {}) {
|
|
98
|
+
const getBaseURL = () => {
|
|
99
|
+
const location = loadOptionalSetting({
|
|
100
|
+
settingValue: options.location,
|
|
101
|
+
environmentVariableName: "GOOGLE_VERTEX_LOCATION"
|
|
102
|
+
});
|
|
103
|
+
const project = loadOptionalSetting({
|
|
104
|
+
settingValue: options.project,
|
|
105
|
+
environmentVariableName: "GOOGLE_VERTEX_PROJECT"
|
|
106
|
+
});
|
|
107
|
+
const getHost = () => {
|
|
108
|
+
if (location === "global") return "aiplatform.googleapis.com";
|
|
109
|
+
else if (location === "eu" || location === "us") return `aiplatform.${location}.rep.googleapis.com`;
|
|
110
|
+
else return `${location}-aiplatform.googleapis.com`;
|
|
111
|
+
};
|
|
112
|
+
return withoutTrailingSlash(options.baseURL) ?? `https://${getHost()}/v1/projects/${project}/locations/${location}/publishers/anthropic/models`;
|
|
113
|
+
};
|
|
114
|
+
const createChatModel = (modelId) => new AnthropicLanguageModel(modelId, {
|
|
115
|
+
provider: "googleVertex.anthropic.messages",
|
|
116
|
+
baseURL: getBaseURL(),
|
|
117
|
+
headers: options.headers ?? {},
|
|
118
|
+
fetch: options.fetch,
|
|
119
|
+
buildRequestUrl: (baseURL, isStreaming) => `${baseURL}/${modelId}:${isStreaming ? "streamRawPredict" : "rawPredict"}`,
|
|
120
|
+
transformRequestBody: (args) => {
|
|
121
|
+
const { model: _model, ...rest } = args;
|
|
122
|
+
return {
|
|
123
|
+
...rest,
|
|
124
|
+
anthropic_version: "vertex-2023-10-16"
|
|
125
|
+
};
|
|
126
|
+
},
|
|
127
|
+
supportedUrls: () => ({}),
|
|
128
|
+
supportsNativeStructuredOutput: false,
|
|
129
|
+
supportsStrictTools: false
|
|
130
|
+
});
|
|
131
|
+
const provider = function(modelId) {
|
|
132
|
+
if (new.target) throw new Error("The Anthropic model function cannot be called with the new keyword.");
|
|
133
|
+
return createChatModel(modelId);
|
|
134
|
+
};
|
|
135
|
+
provider.specificationVersion = "v4";
|
|
136
|
+
provider.languageModel = createChatModel;
|
|
137
|
+
provider.chat = createChatModel;
|
|
138
|
+
provider.messages = createChatModel;
|
|
139
|
+
provider.embeddingModel = (modelId) => {
|
|
140
|
+
throw new NoSuchModelError({
|
|
141
|
+
modelId,
|
|
142
|
+
modelType: "embeddingModel"
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
provider.textEmbeddingModel = provider.embeddingModel;
|
|
146
|
+
provider.imageModel = (modelId) => {
|
|
147
|
+
throw new NoSuchModelError({
|
|
148
|
+
modelId,
|
|
149
|
+
modelType: "imageModel"
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
provider.tools = googleVertexAnthropicTools;
|
|
153
|
+
return provider;
|
|
154
|
+
}
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/anthropic/google-vertex-anthropic-provider-node.ts
|
|
103
157
|
function createGoogleVertexAnthropic(options = {}) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
});
|
|
113
|
-
const getHost = () => {
|
|
114
|
-
if (location === "global") {
|
|
115
|
-
return "aiplatform.googleapis.com";
|
|
116
|
-
} else if (location === "eu" || location === "us") {
|
|
117
|
-
return `aiplatform.${location}.rep.googleapis.com`;
|
|
118
|
-
} else {
|
|
119
|
-
return `${location}-aiplatform.googleapis.com`;
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
return withoutTrailingSlash(options.baseURL) ?? `https://${getHost()}/v1/projects/${project}/locations/${location}/publishers/anthropic/models`;
|
|
123
|
-
};
|
|
124
|
-
const createChatModel = (modelId) => new AnthropicLanguageModel(modelId, {
|
|
125
|
-
provider: "googleVertex.anthropic.messages",
|
|
126
|
-
baseURL: getBaseURL(),
|
|
127
|
-
headers: options.headers ?? {},
|
|
128
|
-
fetch: options.fetch,
|
|
129
|
-
buildRequestUrl: (baseURL, isStreaming) => `${baseURL}/${modelId}:${isStreaming ? "streamRawPredict" : "rawPredict"}`,
|
|
130
|
-
transformRequestBody: (args) => {
|
|
131
|
-
const { model: _model, ...rest } = args;
|
|
132
|
-
return {
|
|
133
|
-
...rest,
|
|
134
|
-
anthropic_version: "vertex-2023-10-16"
|
|
135
|
-
};
|
|
136
|
-
},
|
|
137
|
-
// Google Vertex Anthropic doesn't support URL sources, force download and base64 conversion
|
|
138
|
-
supportedUrls: () => ({}),
|
|
139
|
-
// force the use of JSON tool fallback for structured outputs since beta header isn't supported
|
|
140
|
-
supportsNativeStructuredOutput: false,
|
|
141
|
-
// Vertex Anthropic doesn't support strict mode on tool definitions.
|
|
142
|
-
supportsStrictTools: false
|
|
143
|
-
});
|
|
144
|
-
const provider = function(modelId) {
|
|
145
|
-
if (new.target) {
|
|
146
|
-
throw new Error(
|
|
147
|
-
"The Anthropic model function cannot be called with the new keyword."
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
return createChatModel(modelId);
|
|
151
|
-
};
|
|
152
|
-
provider.specificationVersion = "v4";
|
|
153
|
-
provider.languageModel = createChatModel;
|
|
154
|
-
provider.chat = createChatModel;
|
|
155
|
-
provider.messages = createChatModel;
|
|
156
|
-
provider.embeddingModel = (modelId) => {
|
|
157
|
-
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
158
|
-
};
|
|
159
|
-
provider.textEmbeddingModel = provider.embeddingModel;
|
|
160
|
-
provider.imageModel = (modelId) => {
|
|
161
|
-
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
162
|
-
};
|
|
163
|
-
provider.tools = googleVertexAnthropicTools;
|
|
164
|
-
return provider;
|
|
158
|
+
const generateAuthToken = options.generateAuthToken ?? createAuthTokenGenerator(options.googleAuthOptions);
|
|
159
|
+
return createGoogleVertexAnthropic$1({
|
|
160
|
+
...options,
|
|
161
|
+
headers: async () => ({
|
|
162
|
+
Authorization: `Bearer ${await generateAuthToken()}`,
|
|
163
|
+
...await resolve(options.headers)
|
|
164
|
+
})
|
|
165
|
+
});
|
|
165
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Default Google Vertex Anthropic provider instance.
|
|
169
|
+
*/
|
|
170
|
+
const googleVertexAnthropic = createGoogleVertexAnthropic();
|
|
171
|
+
//#endregion
|
|
172
|
+
export { createGoogleVertexAnthropic, createGoogleVertexAnthropic as createVertexAnthropic, googleVertexAnthropic, googleVertexAnthropic as vertexAnthropic };
|
|
166
173
|
|
|
167
|
-
// src/anthropic/google-vertex-anthropic-provider-node.ts
|
|
168
|
-
function createGoogleVertexAnthropic2(options = {}) {
|
|
169
|
-
const generateAuthToken = options.generateAuthToken ?? createAuthTokenGenerator(options.googleAuthOptions);
|
|
170
|
-
return createGoogleVertexAnthropic({
|
|
171
|
-
...options,
|
|
172
|
-
headers: async () => ({
|
|
173
|
-
Authorization: `Bearer ${await generateAuthToken()}`,
|
|
174
|
-
...await resolve(options.headers)
|
|
175
|
-
})
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
var googleVertexAnthropic = createGoogleVertexAnthropic2();
|
|
179
|
-
export {
|
|
180
|
-
createGoogleVertexAnthropic2 as createGoogleVertexAnthropic,
|
|
181
|
-
createGoogleVertexAnthropic2 as createVertexAnthropic,
|
|
182
|
-
googleVertexAnthropic,
|
|
183
|
-
googleVertexAnthropic as vertexAnthropic
|
|
184
|
-
};
|
|
185
174
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/anthropic/google-vertex-anthropic-provider-node.ts","../../src/google-vertex-auth-google-auth-library.ts","../../src/anthropic/google-vertex-anthropic-provider.ts"],"sourcesContent":["import { resolve } from '@ai-sdk/provider-utils';\nimport type { GoogleAuthOptions } from 'google-auth-library';\nimport { createAuthTokenGenerator } from '../google-vertex-auth-google-auth-library';\nimport {\n createGoogleVertexAnthropic as createVertexAnthropicOriginal,\n type GoogleVertexAnthropicProvider,\n type GoogleVertexAnthropicProviderSettings as GoogleVertexAnthropicProviderSettingsOriginal,\n} from './google-vertex-anthropic-provider';\nexport type { GoogleVertexAnthropicProvider };\n\nexport interface GoogleVertexAnthropicProviderSettings extends GoogleVertexAnthropicProviderSettingsOriginal {\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 * Optional. Override the Bearer token generator. Defaults to OAuth exchange\n * via `google-auth-library` with `googleAuthOptions`.\n */\n generateAuthToken?: () => Promise<string | null>;\n}\n\nexport function createGoogleVertexAnthropic(\n options: GoogleVertexAnthropicProviderSettings = {},\n): GoogleVertexAnthropicProvider {\n const generateAuthToken =\n options.generateAuthToken ??\n createAuthTokenGenerator(options.googleAuthOptions);\n\n return createVertexAnthropicOriginal({\n ...options,\n headers: async () => ({\n Authorization: `Bearer ${await generateAuthToken()}`,\n ...(await resolve(options.headers)),\n }),\n });\n}\n\n/**\n * Default Google Vertex Anthropic provider instance.\n */\nexport const googleVertexAnthropic = createGoogleVertexAnthropic();\n","import { GoogleAuth, type GoogleAuthOptions } from 'google-auth-library';\n\nexport function createAuthTokenGenerator(options?: GoogleAuthOptions) {\n const auth = new GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n ...options,\n });\n\n return async function generateAuthToken() {\n const client = await auth.getClient();\n const token = await client.getAccessToken();\n return token?.token ?? null;\n };\n}\n","import {\n NoSuchModelError,\n type LanguageModelV4,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n loadOptionalSetting,\n withoutTrailingSlash,\n type FetchFunction,\n type Resolvable,\n} from '@ai-sdk/provider-utils';\nimport {\n anthropicTools,\n AnthropicLanguageModel,\n} from '@ai-sdk/anthropic/internal';\nimport type { GoogleVertexAnthropicModelId } from './google-vertex-anthropic-options';\n\ntype GoogleVertexAnthropicTools = Pick<\n typeof anthropicTools,\n | 'bash_20241022'\n | 'bash_20250124'\n | 'textEditor_20241022'\n | 'textEditor_20250124'\n | 'textEditor_20250429'\n | 'textEditor_20250728'\n | 'computer_20241022'\n | 'webSearch_20250305'\n | 'toolSearchRegex_20251119'\n | 'toolSearchBm25_20251119'\n>;\n\n/**\n * Tools supported by Google Vertex Anthropic.\n * This is a subset of the full Anthropic tools - only these are recognized by the Vertex API.\n */\nexport const googleVertexAnthropicTools: GoogleVertexAnthropicTools = {\n /**\n * The bash tool enables Claude to execute shell commands in a persistent bash session,\n * allowing system operations, script execution, and command-line automation.\n *\n * Image results are supported.\n */\n bash_20241022: anthropicTools.bash_20241022,\n\n /**\n * The bash tool enables Claude to execute shell commands in a persistent bash session,\n * allowing system operations, script execution, and command-line automation.\n *\n * Image results are supported.\n */\n bash_20250124: anthropicTools.bash_20250124,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files,\n * helping you debug, fix, and improve your code or other text documents.\n *\n * Supported models: Claude Sonnet 3.5\n */\n textEditor_20241022: anthropicTools.textEditor_20241022,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files,\n * helping you debug, fix, and improve your code or other text documents.\n *\n * Supported models: Claude Sonnet 3.7\n */\n textEditor_20250124: anthropicTools.textEditor_20250124,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files.\n * Note: This version does not support the \"undo_edit\" command.\n * @deprecated Use textEditor_20250728 instead\n */\n textEditor_20250429: anthropicTools.textEditor_20250429,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files.\n * Note: This version does not support the \"undo_edit\" command and adds optional max_characters parameter.\n * Supported models: Claude Sonnet 4, Opus 4, and Opus 4.1\n */\n textEditor_20250728: anthropicTools.textEditor_20250728,\n\n /**\n * Claude can interact with computer environments through the computer use tool, which\n * provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.\n *\n * Image results are supported.\n */\n computer_20241022: anthropicTools.computer_20241022,\n\n /**\n * Creates a web search tool that gives Claude direct access to real-time web content.\n */\n webSearch_20250305: anthropicTools.webSearch_20250305,\n\n /**\n * Creates a tool search tool that uses regex patterns to find tools.\n *\n * The tool search tool enables Claude to work with hundreds or thousands of tools\n * by dynamically discovering and loading them on-demand.\n *\n * Use `providerOptions: { anthropic: { deferLoading: true } }` on other tools\n * to mark them for deferred loading.\n */\n toolSearchRegex_20251119: anthropicTools.toolSearchRegex_20251119,\n\n /**\n * Creates a tool search tool that uses BM25 (natural language) to find tools.\n *\n * The tool search tool enables Claude to work with hundreds or thousands of tools\n * by dynamically discovering and loading them on-demand.\n *\n * Use `providerOptions: { anthropic: { deferLoading: true } }` on other tools\n * to mark them for deferred loading.\n */\n toolSearchBm25_20251119: anthropicTools.toolSearchBm25_20251119,\n};\nexport interface GoogleVertexAnthropicProvider extends ProviderV4 {\n /**\n * Creates a model for text generation.\n */\n (modelId: GoogleVertexAnthropicModelId): LanguageModelV4;\n\n /**\n * Creates a model for text generation.\n */\n languageModel(modelId: GoogleVertexAnthropicModelId): LanguageModelV4;\n\n /**\n * Anthropic tools supported by Google Vertex.\n * Note: Only a subset of Anthropic tools are available on Vertex.\n * Supported tools: bash_20241022, bash_20250124, textEditor_20241022,\n * textEditor_20250124, textEditor_20250429, textEditor_20250728,\n * computer_20241022, webSearch_20250305, toolSearchRegex_20251119,\n * toolSearchBm25_20251119\n */\n tools: typeof googleVertexAnthropicTools;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nexport interface GoogleVertexAnthropicProviderSettings {\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 region. Defaults to the value of the `GOOGLE_VERTEX_LOCATION` environment variable.\n */\n location?: string;\n\n /**\n * Use a different URL prefix for API calls, e.g. to use proxy servers.\n * The default prefix is `https://api.anthropic.com/v1`.\n */\n baseURL?: string;\n\n /**\n * Custom headers to include in the requests.\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 Anthropic provider instance.\n */\nexport function createGoogleVertexAnthropic(\n options: GoogleVertexAnthropicProviderSettings = {},\n): GoogleVertexAnthropicProvider {\n const getBaseURL = () => {\n const location = loadOptionalSetting({\n settingValue: options.location,\n environmentVariableName: 'GOOGLE_VERTEX_LOCATION',\n });\n const project = loadOptionalSetting({\n settingValue: options.project,\n environmentVariableName: 'GOOGLE_VERTEX_PROJECT',\n });\n\n const getHost = () => {\n if (location === 'global') {\n return 'aiplatform.googleapis.com';\n } else if (location === 'eu' || location === 'us') {\n return `aiplatform.${location}.rep.googleapis.com`;\n } else {\n return `${location}-aiplatform.googleapis.com`;\n }\n };\n\n return (\n withoutTrailingSlash(options.baseURL) ??\n `https://${getHost()}/v1/projects/${project}/locations/${location}/publishers/anthropic/models`\n );\n };\n\n const createChatModel = (modelId: GoogleVertexAnthropicModelId) =>\n new AnthropicLanguageModel(modelId, {\n provider: 'googleVertex.anthropic.messages',\n baseURL: getBaseURL(),\n headers: options.headers ?? {},\n fetch: options.fetch,\n\n buildRequestUrl: (baseURL, isStreaming) =>\n `${baseURL}/${modelId}:${\n isStreaming ? 'streamRawPredict' : 'rawPredict'\n }`,\n transformRequestBody: args => {\n // Remove model from args and add anthropic version\n const { model: _model, ...rest } = args;\n return {\n ...rest,\n anthropic_version: 'vertex-2023-10-16',\n };\n },\n // Google Vertex Anthropic doesn't support URL sources, force download and base64 conversion\n supportedUrls: () => ({}),\n // force the use of JSON tool fallback for structured outputs since beta header isn't supported\n supportsNativeStructuredOutput: false,\n // Vertex Anthropic doesn't support strict mode on tool definitions.\n supportsStrictTools: false,\n });\n\n const provider = function (modelId: GoogleVertexAnthropicModelId) {\n if (new.target) {\n throw new Error(\n 'The Anthropic model function cannot be called with the new keyword.',\n );\n }\n\n return createChatModel(modelId);\n };\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.messages = createChatModel;\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n provider.tools = googleVertexAnthropicTools;\n\n return provider;\n}\n"],"mappings":";AAAA,SAAS,eAAe;;;ACAxB,SAAS,kBAA0C;AAE5C,SAAS,yBAAyB,SAA6B;AACpE,QAAM,OAAO,IAAI,WAAW;AAAA,IAC1B,QAAQ,CAAC,gDAAgD;AAAA,IACzD,GAAG;AAAA,EACL,CAAC;AAED,SAAO,eAAe,oBAAoB;AACxC,UAAM,SAAS,MAAM,KAAK,UAAU;AACpC,UAAM,QAAQ,MAAM,OAAO,eAAe;AAC1C,WAAO,OAAO,SAAS;AAAA,EACzB;AACF;;;ACbA;AAAA,EACE;AAAA,OAGK;AACP;AAAA,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;AAAA,MAClD,GAAI,MAAM,QAAQ,QAAQ,OAAO;AAAA,IACnC;AAAA,EACF,CAAC;AACH;AAKO,IAAM,wBAAwBA,6BAA4B;","names":["createGoogleVertexAnthropic"]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["createGoogleVertexAnthropic","createVertexAnthropicOriginal"],"sources":["../../src/google-vertex-auth-google-auth-library.ts","../../src/anthropic/google-vertex-anthropic-provider.ts","../../src/anthropic/google-vertex-anthropic-provider-node.ts"],"sourcesContent":["import { GoogleAuth, type GoogleAuthOptions } from 'google-auth-library';\n\nexport function createAuthTokenGenerator(options?: GoogleAuthOptions) {\n const auth = new GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n ...options,\n });\n\n return async function generateAuthToken() {\n const client = await auth.getClient();\n const token = await client.getAccessToken();\n return token?.token ?? null;\n };\n}\n","import {\n NoSuchModelError,\n type LanguageModelV4,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n loadOptionalSetting,\n withoutTrailingSlash,\n type FetchFunction,\n type Resolvable,\n} from '@ai-sdk/provider-utils';\nimport {\n anthropicTools,\n AnthropicLanguageModel,\n} from '@ai-sdk/anthropic/internal';\nimport type { GoogleVertexAnthropicModelId } from './google-vertex-anthropic-options';\n\ntype GoogleVertexAnthropicTools = Pick<\n typeof anthropicTools,\n | 'bash_20241022'\n | 'bash_20250124'\n | 'textEditor_20241022'\n | 'textEditor_20250124'\n | 'textEditor_20250429'\n | 'textEditor_20250728'\n | 'computer_20241022'\n | 'webSearch_20250305'\n | 'toolSearchRegex_20251119'\n | 'toolSearchBm25_20251119'\n>;\n\n/**\n * Tools supported by Google Vertex Anthropic.\n * This is a subset of the full Anthropic tools - only these are recognized by the Vertex API.\n */\nexport const googleVertexAnthropicTools: GoogleVertexAnthropicTools = {\n /**\n * The bash tool enables Claude to execute shell commands in a persistent bash session,\n * allowing system operations, script execution, and command-line automation.\n *\n * Image results are supported.\n */\n bash_20241022: anthropicTools.bash_20241022,\n\n /**\n * The bash tool enables Claude to execute shell commands in a persistent bash session,\n * allowing system operations, script execution, and command-line automation.\n *\n * Image results are supported.\n */\n bash_20250124: anthropicTools.bash_20250124,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files,\n * helping you debug, fix, and improve your code or other text documents.\n *\n * Supported models: Claude Sonnet 3.5\n */\n textEditor_20241022: anthropicTools.textEditor_20241022,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files,\n * helping you debug, fix, and improve your code or other text documents.\n *\n * Supported models: Claude Sonnet 3.7\n */\n textEditor_20250124: anthropicTools.textEditor_20250124,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files.\n * Note: This version does not support the \"undo_edit\" command.\n * @deprecated Use textEditor_20250728 instead\n */\n textEditor_20250429: anthropicTools.textEditor_20250429,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files.\n * Note: This version does not support the \"undo_edit\" command and adds optional max_characters parameter.\n * Supported models: Claude Sonnet 4, Opus 4, and Opus 4.1\n */\n textEditor_20250728: anthropicTools.textEditor_20250728,\n\n /**\n * Claude can interact with computer environments through the computer use tool, which\n * provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.\n *\n * Image results are supported.\n */\n computer_20241022: anthropicTools.computer_20241022,\n\n /**\n * Creates a web search tool that gives Claude direct access to real-time web content.\n */\n webSearch_20250305: anthropicTools.webSearch_20250305,\n\n /**\n * Creates a tool search tool that uses regex patterns to find tools.\n *\n * The tool search tool enables Claude to work with hundreds or thousands of tools\n * by dynamically discovering and loading them on-demand.\n *\n * Use `providerOptions: { anthropic: { deferLoading: true } }` on other tools\n * to mark them for deferred loading.\n */\n toolSearchRegex_20251119: anthropicTools.toolSearchRegex_20251119,\n\n /**\n * Creates a tool search tool that uses BM25 (natural language) to find tools.\n *\n * The tool search tool enables Claude to work with hundreds or thousands of tools\n * by dynamically discovering and loading them on-demand.\n *\n * Use `providerOptions: { anthropic: { deferLoading: true } }` on other tools\n * to mark them for deferred loading.\n */\n toolSearchBm25_20251119: anthropicTools.toolSearchBm25_20251119,\n};\nexport interface GoogleVertexAnthropicProvider extends ProviderV4 {\n /**\n * Creates a model for text generation.\n */\n (modelId: GoogleVertexAnthropicModelId): LanguageModelV4;\n\n /**\n * Creates a model for text generation.\n */\n languageModel(modelId: GoogleVertexAnthropicModelId): LanguageModelV4;\n\n /**\n * Anthropic tools supported by Google Vertex.\n * Note: Only a subset of Anthropic tools are available on Vertex.\n * Supported tools: bash_20241022, bash_20250124, textEditor_20241022,\n * textEditor_20250124, textEditor_20250429, textEditor_20250728,\n * computer_20241022, webSearch_20250305, toolSearchRegex_20251119,\n * toolSearchBm25_20251119\n */\n tools: typeof googleVertexAnthropicTools;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nexport interface GoogleVertexAnthropicProviderSettings {\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 region. Defaults to the value of the `GOOGLE_VERTEX_LOCATION` environment variable.\n */\n location?: string;\n\n /**\n * Use a different URL prefix for API calls, e.g. to use proxy servers.\n * The default prefix is `https://api.anthropic.com/v1`.\n */\n baseURL?: string;\n\n /**\n * Custom headers to include in the requests.\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 Anthropic provider instance.\n */\nexport function createGoogleVertexAnthropic(\n options: GoogleVertexAnthropicProviderSettings = {},\n): GoogleVertexAnthropicProvider {\n const getBaseURL = () => {\n const location = loadOptionalSetting({\n settingValue: options.location,\n environmentVariableName: 'GOOGLE_VERTEX_LOCATION',\n });\n const project = loadOptionalSetting({\n settingValue: options.project,\n environmentVariableName: 'GOOGLE_VERTEX_PROJECT',\n });\n\n const getHost = () => {\n if (location === 'global') {\n return 'aiplatform.googleapis.com';\n } else if (location === 'eu' || location === 'us') {\n return `aiplatform.${location}.rep.googleapis.com`;\n } else {\n return `${location}-aiplatform.googleapis.com`;\n }\n };\n\n return (\n withoutTrailingSlash(options.baseURL) ??\n `https://${getHost()}/v1/projects/${project}/locations/${location}/publishers/anthropic/models`\n );\n };\n\n const createChatModel = (modelId: GoogleVertexAnthropicModelId) =>\n new AnthropicLanguageModel(modelId, {\n provider: 'googleVertex.anthropic.messages',\n baseURL: getBaseURL(),\n headers: options.headers ?? {},\n fetch: options.fetch,\n\n buildRequestUrl: (baseURL, isStreaming) =>\n `${baseURL}/${modelId}:${\n isStreaming ? 'streamRawPredict' : 'rawPredict'\n }`,\n transformRequestBody: args => {\n // Remove model from args and add anthropic version\n const { model: _model, ...rest } = args;\n return {\n ...rest,\n anthropic_version: 'vertex-2023-10-16',\n };\n },\n // Google Vertex Anthropic doesn't support URL sources, force download and base64 conversion\n supportedUrls: () => ({}),\n // force the use of JSON tool fallback for structured outputs since beta header isn't supported\n supportsNativeStructuredOutput: false,\n // Vertex Anthropic doesn't support strict mode on tool definitions.\n supportsStrictTools: false,\n });\n\n const provider = function (modelId: GoogleVertexAnthropicModelId) {\n if (new.target) {\n throw new Error(\n 'The Anthropic model function cannot be called with the new keyword.',\n );\n }\n\n return createChatModel(modelId);\n };\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.messages = createChatModel;\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n provider.tools = googleVertexAnthropicTools;\n\n return provider;\n}\n","import { resolve } from '@ai-sdk/provider-utils';\nimport type { GoogleAuthOptions } from 'google-auth-library';\nimport { createAuthTokenGenerator } from '../google-vertex-auth-google-auth-library';\nimport {\n createGoogleVertexAnthropic as createVertexAnthropicOriginal,\n type GoogleVertexAnthropicProvider,\n type GoogleVertexAnthropicProviderSettings as GoogleVertexAnthropicProviderSettingsOriginal,\n} from './google-vertex-anthropic-provider';\nexport type { GoogleVertexAnthropicProvider };\n\nexport interface GoogleVertexAnthropicProviderSettings extends GoogleVertexAnthropicProviderSettingsOriginal {\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 * Optional. Override the Bearer token generator. Defaults to OAuth exchange\n * via `google-auth-library` with `googleAuthOptions`.\n */\n generateAuthToken?: () => Promise<string | null>;\n}\n\nexport function createGoogleVertexAnthropic(\n options: GoogleVertexAnthropicProviderSettings = {},\n): GoogleVertexAnthropicProvider {\n const generateAuthToken =\n options.generateAuthToken ??\n createAuthTokenGenerator(options.googleAuthOptions);\n\n return createVertexAnthropicOriginal({\n ...options,\n headers: async () => ({\n Authorization: `Bearer ${await generateAuthToken()}`,\n ...(await resolve(options.headers)),\n }),\n });\n}\n\n/**\n * Default Google Vertex Anthropic provider instance.\n */\nexport const googleVertexAnthropic = createGoogleVertexAnthropic();\n"],"mappings":";;;;;AAEA,SAAgB,yBAAyB,SAA6B;CACpE,MAAM,OAAO,IAAI,WAAW;EAC1B,QAAQ,CAAC,gDAAgD;EACzD,GAAG;CACL,CAAC;CAED,OAAO,eAAe,oBAAoB;EAGxC,QAAO,OADa,MADC,KAAK,UAAU,EAAA,CACT,eAAe,EAAA,EAC5B,SAAS;CACzB;AACF;;;;;;;ACsBA,MAAa,6BAAyD;;;;;;;CAOpE,eAAe,eAAe;;;;;;;CAQ9B,eAAe,eAAe;;;;;;;CAQ9B,qBAAqB,eAAe;;;;;;;CAQpC,qBAAqB,eAAe;;;;;;CAOpC,qBAAqB,eAAe;;;;;;CAOpC,qBAAqB,eAAe;;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