@ai-sdk/google-vertex 5.0.0-beta.5 → 5.0.0-beta.52
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 +430 -8
- package/README.md +65 -1
- package/dist/anthropic/edge/index.d.ts +61 -16
- package/dist/anthropic/edge/index.js +67 -60
- package/dist/anthropic/edge/index.js.map +1 -1
- package/dist/anthropic/index.d.ts +61 -16
- package/dist/anthropic/index.js +57 -55
- package/dist/anthropic/index.js.map +1 -1
- package/dist/edge/index.d.ts +31 -22
- package/dist/edge/index.js +217 -176
- package/dist/edge/index.js.map +1 -1
- package/dist/index.d.ts +31 -22
- package/dist/index.js +208 -173
- package/dist/index.js.map +1 -1
- package/dist/maas/edge/index.d.ts +76 -0
- package/dist/maas/edge/index.js +196 -0
- package/dist/maas/edge/index.js.map +1 -0
- package/dist/maas/index.d.ts +60 -0
- package/dist/maas/index.js +101 -0
- package/dist/maas/index.js.map +1 -0
- package/docs/16-google-vertex.mdx +226 -6
- package/maas/edge.d.ts +1 -0
- package/maas/index.d.ts +1 -0
- package/package.json +29 -18
- package/src/anthropic/edge/google-vertex-anthropic-provider-edge.ts +1 -2
- package/src/anthropic/google-vertex-anthropic-messages-options.ts +1 -0
- package/src/anthropic/google-vertex-anthropic-provider-node.ts +1 -2
- package/src/anthropic/google-vertex-anthropic-provider.ts +33 -8
- package/src/edge/google-vertex-provider-edge.ts +1 -2
- package/src/google-vertex-config.ts +1 -1
- package/src/google-vertex-embedding-model.ts +23 -6
- package/src/google-vertex-embedding-options.ts +2 -0
- package/src/google-vertex-image-model.ts +38 -18
- package/src/google-vertex-options.ts +0 -1
- 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
- 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
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
|
|
2
|
+
import type { OpenAICompatibleProvider } from '@ai-sdk/openai-compatible';
|
|
3
|
+
import {
|
|
4
|
+
FetchFunction,
|
|
5
|
+
loadOptionalSetting,
|
|
6
|
+
loadSetting,
|
|
7
|
+
Resolvable,
|
|
8
|
+
withoutTrailingSlash,
|
|
9
|
+
} from '@ai-sdk/provider-utils';
|
|
10
|
+
import type { GoogleVertexMaasModelId } from './google-vertex-maas-options';
|
|
11
|
+
|
|
12
|
+
export interface GoogleVertexMaasProvider extends OpenAICompatibleProvider<
|
|
13
|
+
GoogleVertexMaasModelId,
|
|
14
|
+
string,
|
|
15
|
+
string,
|
|
16
|
+
string
|
|
17
|
+
> {}
|
|
18
|
+
|
|
19
|
+
export interface GoogleVertexMaasProviderSettings {
|
|
20
|
+
/**
|
|
21
|
+
* Google Cloud project ID. Defaults to the value of the `GOOGLE_VERTEX_PROJECT` environment variable.
|
|
22
|
+
*/
|
|
23
|
+
project?: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Google Cloud location/region. Defaults to the value of the `GOOGLE_VERTEX_LOCATION` environment variable.
|
|
27
|
+
* Use 'global' for the global endpoint.
|
|
28
|
+
*/
|
|
29
|
+
location?: string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Base URL for the API calls. If not provided, will be constructed from project and location.
|
|
33
|
+
*/
|
|
34
|
+
baseURL?: string;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Headers to use for requests. Can be:
|
|
38
|
+
* - A headers object
|
|
39
|
+
* - A Promise that resolves to a headers object
|
|
40
|
+
* - A function that returns a headers object
|
|
41
|
+
* - A function that returns a Promise of a headers object
|
|
42
|
+
*/
|
|
43
|
+
headers?: Resolvable<Record<string, string | undefined>>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
47
|
+
* or to provide a custom fetch implementation for e.g. testing.
|
|
48
|
+
*/
|
|
49
|
+
fetch?: FetchFunction;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Create a Google Vertex AI MaaS (Model as a Service) provider instance.
|
|
54
|
+
* Uses the OpenAI-compatible Chat Completions API for partner and open models.
|
|
55
|
+
*
|
|
56
|
+
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models
|
|
57
|
+
*/
|
|
58
|
+
export function createVertexMaas(
|
|
59
|
+
options: GoogleVertexMaasProviderSettings = {},
|
|
60
|
+
): GoogleVertexMaasProvider {
|
|
61
|
+
// Lazy-load settings to support loading from environment variables at runtime
|
|
62
|
+
const loadLocation = () =>
|
|
63
|
+
loadOptionalSetting({
|
|
64
|
+
settingValue: options.location,
|
|
65
|
+
environmentVariableName: 'GOOGLE_VERTEX_LOCATION',
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const loadProject = () =>
|
|
69
|
+
loadSetting({
|
|
70
|
+
settingValue: options.project,
|
|
71
|
+
settingName: 'project',
|
|
72
|
+
environmentVariableName: 'GOOGLE_VERTEX_PROJECT',
|
|
73
|
+
description: 'Google Vertex project',
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Construct base URL: https://aiplatform.googleapis.com/v1/projects/{project}/locations/{location}/endpoints/openapi
|
|
77
|
+
const constructBaseURL = () => {
|
|
78
|
+
const projectId = loadProject();
|
|
79
|
+
const location = loadLocation() ?? 'global';
|
|
80
|
+
|
|
81
|
+
return `https://aiplatform.googleapis.com/v1/projects/${projectId}/locations/${location}/endpoints/openapi`;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const loadBaseURL = () =>
|
|
85
|
+
withoutTrailingSlash(options.baseURL ?? '') || constructBaseURL();
|
|
86
|
+
|
|
87
|
+
let cachedProvider: GoogleVertexMaasProvider | undefined;
|
|
88
|
+
const getProvider = () =>
|
|
89
|
+
(cachedProvider ??= createOpenAICompatible({
|
|
90
|
+
name: 'vertex.maas',
|
|
91
|
+
baseURL: loadBaseURL(),
|
|
92
|
+
fetch: options.fetch,
|
|
93
|
+
}));
|
|
94
|
+
|
|
95
|
+
const provider = (modelId: GoogleVertexMaasModelId) => getProvider()(modelId);
|
|
96
|
+
|
|
97
|
+
provider.specificationVersion = 'v4' as const;
|
|
98
|
+
provider.languageModel = (modelId: GoogleVertexMaasModelId) =>
|
|
99
|
+
getProvider().languageModel(modelId);
|
|
100
|
+
provider.chatModel = (modelId: GoogleVertexMaasModelId) =>
|
|
101
|
+
getProvider().chatModel(modelId);
|
|
102
|
+
provider.completionModel = (modelId: string) =>
|
|
103
|
+
getProvider().completionModel(modelId);
|
|
104
|
+
provider.embeddingModel = (modelId: string) =>
|
|
105
|
+
getProvider().embeddingModel(modelId);
|
|
106
|
+
provider.textEmbeddingModel = (modelId: string) =>
|
|
107
|
+
getProvider().textEmbeddingModel(modelId);
|
|
108
|
+
provider.imageModel = (modelId: string) => getProvider().imageModel(modelId);
|
|
109
|
+
|
|
110
|
+
return provider as GoogleVertexMaasProvider;
|
|
111
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export {
|
|
2
|
+
createVertexMaas,
|
|
3
|
+
vertexMaas,
|
|
4
|
+
} from './google-vertex-maas-provider-node';
|
|
5
|
+
export type {
|
|
6
|
+
GoogleVertexMaasProvider,
|
|
7
|
+
GoogleVertexMaasProviderSettings,
|
|
8
|
+
} from './google-vertex-maas-provider-node';
|
|
9
|
+
export type { GoogleVertexMaasModelId } from './google-vertex-maas-options';
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
2
|
-
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
-
import { ProviderV3, LanguageModelV3 } from '@ai-sdk/provider';
|
|
4
|
-
|
|
5
|
-
interface GoogleCredentials {
|
|
6
|
-
/**
|
|
7
|
-
* The client email for the Google Cloud service account. Defaults to the
|
|
8
|
-
* value of the `GOOGLE_CLIENT_EMAIL` environment variable.
|
|
9
|
-
*/
|
|
10
|
-
clientEmail: string;
|
|
11
|
-
/**
|
|
12
|
-
* The private key for the Google Cloud service account. Defaults to the
|
|
13
|
-
* value of the `GOOGLE_PRIVATE_KEY` environment variable.
|
|
14
|
-
*/
|
|
15
|
-
privateKey: string;
|
|
16
|
-
/**
|
|
17
|
-
* Optional. The private key ID for the Google Cloud service account. Defaults
|
|
18
|
-
* to the value of the `GOOGLE_PRIVATE_KEY_ID` environment variable.
|
|
19
|
-
*/
|
|
20
|
-
privateKeyId?: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type GoogleVertexAnthropicMessagesModelId = '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 & {});
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Tools supported by Google Vertex Anthropic.
|
|
27
|
-
* This is a subset of the full Anthropic tools - only these are recognized by the Vertex API.
|
|
28
|
-
*/
|
|
29
|
-
declare const vertexAnthropicTools: {
|
|
30
|
-
/**
|
|
31
|
-
* The bash tool enables Claude to execute shell commands in a persistent bash session,
|
|
32
|
-
* allowing system operations, script execution, and command-line automation.
|
|
33
|
-
*
|
|
34
|
-
* Image results are supported.
|
|
35
|
-
*/
|
|
36
|
-
bash_20241022: _ai_sdk_provider_utils.ProviderToolFactory<{
|
|
37
|
-
command: string;
|
|
38
|
-
restart?: boolean;
|
|
39
|
-
}, {}>;
|
|
40
|
-
/**
|
|
41
|
-
* The bash tool enables Claude to execute shell commands in a persistent bash session,
|
|
42
|
-
* allowing system operations, script execution, and command-line automation.
|
|
43
|
-
*
|
|
44
|
-
* Image results are supported.
|
|
45
|
-
*/
|
|
46
|
-
bash_20250124: _ai_sdk_provider_utils.ProviderToolFactory<{
|
|
47
|
-
command: string;
|
|
48
|
-
restart?: boolean;
|
|
49
|
-
}, {}>;
|
|
50
|
-
/**
|
|
51
|
-
* Claude can use an Anthropic-defined text editor tool to view and modify text files,
|
|
52
|
-
* helping you debug, fix, and improve your code or other text documents.
|
|
53
|
-
*
|
|
54
|
-
* Supported models: Claude Sonnet 3.5
|
|
55
|
-
*/
|
|
56
|
-
textEditor_20241022: _ai_sdk_provider_utils.ProviderToolFactory<{
|
|
57
|
-
command: "view" | "create" | "str_replace" | "insert" | "undo_edit";
|
|
58
|
-
path: string;
|
|
59
|
-
file_text?: string;
|
|
60
|
-
insert_line?: number;
|
|
61
|
-
new_str?: string;
|
|
62
|
-
insert_text?: string;
|
|
63
|
-
old_str?: string;
|
|
64
|
-
view_range?: number[];
|
|
65
|
-
}, {}>;
|
|
66
|
-
/**
|
|
67
|
-
* Claude can use an Anthropic-defined text editor tool to view and modify text files,
|
|
68
|
-
* helping you debug, fix, and improve your code or other text documents.
|
|
69
|
-
*
|
|
70
|
-
* Supported models: Claude Sonnet 3.7
|
|
71
|
-
*/
|
|
72
|
-
textEditor_20250124: _ai_sdk_provider_utils.ProviderToolFactory<{
|
|
73
|
-
command: "view" | "create" | "str_replace" | "insert" | "undo_edit";
|
|
74
|
-
path: string;
|
|
75
|
-
file_text?: string;
|
|
76
|
-
insert_line?: number;
|
|
77
|
-
new_str?: string;
|
|
78
|
-
insert_text?: string;
|
|
79
|
-
old_str?: string;
|
|
80
|
-
view_range?: number[];
|
|
81
|
-
}, {}>;
|
|
82
|
-
/**
|
|
83
|
-
* Claude can use an Anthropic-defined text editor tool to view and modify text files.
|
|
84
|
-
* Note: This version does not support the "undo_edit" command.
|
|
85
|
-
* @deprecated Use textEditor_20250728 instead
|
|
86
|
-
*/
|
|
87
|
-
textEditor_20250429: _ai_sdk_provider_utils.ProviderToolFactory<{
|
|
88
|
-
command: "view" | "create" | "str_replace" | "insert";
|
|
89
|
-
path: string;
|
|
90
|
-
file_text?: string;
|
|
91
|
-
insert_line?: number;
|
|
92
|
-
new_str?: string;
|
|
93
|
-
insert_text?: string;
|
|
94
|
-
old_str?: string;
|
|
95
|
-
view_range?: number[];
|
|
96
|
-
}, {}>;
|
|
97
|
-
/**
|
|
98
|
-
* Claude can use an Anthropic-defined text editor tool to view and modify text files.
|
|
99
|
-
* Note: This version does not support the "undo_edit" command and adds optional max_characters parameter.
|
|
100
|
-
* Supported models: Claude Sonnet 4, Opus 4, and Opus 4.1
|
|
101
|
-
*/
|
|
102
|
-
textEditor_20250728: (args?: Parameters<_ai_sdk_provider_utils.ProviderToolFactory<{
|
|
103
|
-
command: "view" | "create" | "str_replace" | "insert";
|
|
104
|
-
path: string;
|
|
105
|
-
file_text?: string;
|
|
106
|
-
insert_line?: number;
|
|
107
|
-
new_str?: string;
|
|
108
|
-
insert_text?: string;
|
|
109
|
-
old_str?: string;
|
|
110
|
-
view_range?: number[];
|
|
111
|
-
}, {
|
|
112
|
-
maxCharacters?: number;
|
|
113
|
-
}>>[0]) => _ai_sdk_provider_utils.Tool<{
|
|
114
|
-
command: "view" | "create" | "str_replace" | "insert";
|
|
115
|
-
path: string;
|
|
116
|
-
file_text?: string;
|
|
117
|
-
insert_line?: number;
|
|
118
|
-
new_str?: string;
|
|
119
|
-
insert_text?: string;
|
|
120
|
-
old_str?: string;
|
|
121
|
-
view_range?: number[];
|
|
122
|
-
}, unknown>;
|
|
123
|
-
/**
|
|
124
|
-
* Claude can interact with computer environments through the computer use tool, which
|
|
125
|
-
* provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.
|
|
126
|
-
*
|
|
127
|
-
* Image results are supported.
|
|
128
|
-
*/
|
|
129
|
-
computer_20241022: _ai_sdk_provider_utils.ProviderToolFactory<{
|
|
130
|
-
action: "key" | "type" | "mouse_move" | "left_click" | "left_click_drag" | "right_click" | "middle_click" | "double_click" | "screenshot" | "cursor_position";
|
|
131
|
-
coordinate?: number[];
|
|
132
|
-
text?: string;
|
|
133
|
-
}, {
|
|
134
|
-
displayWidthPx: number;
|
|
135
|
-
displayHeightPx: number;
|
|
136
|
-
displayNumber?: number;
|
|
137
|
-
}>;
|
|
138
|
-
/**
|
|
139
|
-
* Creates a web search tool that gives Claude direct access to real-time web content.
|
|
140
|
-
*/
|
|
141
|
-
webSearch_20250305: (args?: Parameters<_ai_sdk_provider_utils.ProviderToolFactoryWithOutputSchema<{
|
|
142
|
-
query: string;
|
|
143
|
-
}, {
|
|
144
|
-
type: "web_search_result";
|
|
145
|
-
url: string;
|
|
146
|
-
title: string | null;
|
|
147
|
-
pageAge: string | null;
|
|
148
|
-
encryptedContent: string;
|
|
149
|
-
}[], {
|
|
150
|
-
maxUses?: number;
|
|
151
|
-
allowedDomains?: string[];
|
|
152
|
-
blockedDomains?: string[];
|
|
153
|
-
userLocation?: {
|
|
154
|
-
type: "approximate";
|
|
155
|
-
city?: string;
|
|
156
|
-
region?: string;
|
|
157
|
-
country?: string;
|
|
158
|
-
timezone?: string;
|
|
159
|
-
};
|
|
160
|
-
}>>[0]) => _ai_sdk_provider_utils.Tool<{
|
|
161
|
-
query: string;
|
|
162
|
-
}, {
|
|
163
|
-
type: "web_search_result";
|
|
164
|
-
url: string;
|
|
165
|
-
title: string | null;
|
|
166
|
-
pageAge: string | null;
|
|
167
|
-
encryptedContent: string;
|
|
168
|
-
}[]>;
|
|
169
|
-
};
|
|
170
|
-
interface GoogleVertexAnthropicProvider extends ProviderV3 {
|
|
171
|
-
/**
|
|
172
|
-
* Creates a model for text generation.
|
|
173
|
-
*/
|
|
174
|
-
(modelId: GoogleVertexAnthropicMessagesModelId): LanguageModelV3;
|
|
175
|
-
/**
|
|
176
|
-
* Creates a model for text generation.
|
|
177
|
-
*/
|
|
178
|
-
languageModel(modelId: GoogleVertexAnthropicMessagesModelId): LanguageModelV3;
|
|
179
|
-
/**
|
|
180
|
-
* Anthropic tools supported by Google Vertex.
|
|
181
|
-
* Note: Only a subset of Anthropic tools are available on Vertex.
|
|
182
|
-
* Supported tools: bash_20241022, bash_20250124, textEditor_20241022,
|
|
183
|
-
* textEditor_20250124, textEditor_20250429, textEditor_20250728,
|
|
184
|
-
* computer_20241022, webSearch_20250305
|
|
185
|
-
*/
|
|
186
|
-
tools: typeof vertexAnthropicTools;
|
|
187
|
-
/**
|
|
188
|
-
* @deprecated Use `embeddingModel` instead.
|
|
189
|
-
*/
|
|
190
|
-
textEmbeddingModel(modelId: string): never;
|
|
191
|
-
}
|
|
192
|
-
interface GoogleVertexAnthropicProviderSettings$1 {
|
|
193
|
-
/**
|
|
194
|
-
* Google Cloud project ID. Defaults to the value of the `GOOGLE_VERTEX_PROJECT` environment variable.
|
|
195
|
-
*/
|
|
196
|
-
project?: string;
|
|
197
|
-
/**
|
|
198
|
-
* Google Cloud region. Defaults to the value of the `GOOGLE_VERTEX_LOCATION` environment variable.
|
|
199
|
-
*/
|
|
200
|
-
location?: string;
|
|
201
|
-
/**
|
|
202
|
-
* Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
203
|
-
* The default prefix is `https://api.anthropic.com/v1`.
|
|
204
|
-
*/
|
|
205
|
-
baseURL?: string;
|
|
206
|
-
/**
|
|
207
|
-
* Custom headers to include in the requests.
|
|
208
|
-
*/
|
|
209
|
-
headers?: Resolvable<Record<string, string | undefined>>;
|
|
210
|
-
/**
|
|
211
|
-
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
212
|
-
* or to provide a custom fetch implementation for e.g. testing.
|
|
213
|
-
*/
|
|
214
|
-
fetch?: FetchFunction;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
interface GoogleVertexAnthropicProviderSettings extends GoogleVertexAnthropicProviderSettings$1 {
|
|
218
|
-
/**
|
|
219
|
-
* Optional. The Google credentials for the Google Cloud service account. If
|
|
220
|
-
* not provided, the Google Vertex provider will use environment variables to
|
|
221
|
-
* load the credentials.
|
|
222
|
-
*/
|
|
223
|
-
googleCredentials?: GoogleCredentials;
|
|
224
|
-
}
|
|
225
|
-
declare function createVertexAnthropic(options?: GoogleVertexAnthropicProviderSettings): GoogleVertexAnthropicProvider;
|
|
226
|
-
/**
|
|
227
|
-
* Default Google Vertex AI Anthropic provider instance.
|
|
228
|
-
*/
|
|
229
|
-
declare const vertexAnthropic: GoogleVertexAnthropicProvider;
|
|
230
|
-
|
|
231
|
-
export { type GoogleVertexAnthropicProvider, type GoogleVertexAnthropicProviderSettings, createVertexAnthropic, vertexAnthropic };
|
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
// src/anthropic/edge/google-vertex-anthropic-provider-edge.ts
|
|
2
|
-
import { resolve } from "@ai-sdk/provider-utils";
|
|
3
|
-
|
|
4
|
-
// src/edge/google-vertex-auth-edge.ts
|
|
5
|
-
import {
|
|
6
|
-
loadOptionalSetting,
|
|
7
|
-
loadSetting,
|
|
8
|
-
withUserAgentSuffix,
|
|
9
|
-
getRuntimeEnvironmentUserAgent
|
|
10
|
-
} from "@ai-sdk/provider-utils";
|
|
11
|
-
|
|
12
|
-
// src/version.ts
|
|
13
|
-
var VERSION = true ? "5.0.0-beta.5" : "0.0.0-test";
|
|
14
|
-
|
|
15
|
-
// src/edge/google-vertex-auth-edge.ts
|
|
16
|
-
var loadCredentials = async () => {
|
|
17
|
-
try {
|
|
18
|
-
return {
|
|
19
|
-
clientEmail: loadSetting({
|
|
20
|
-
settingValue: void 0,
|
|
21
|
-
settingName: "clientEmail",
|
|
22
|
-
environmentVariableName: "GOOGLE_CLIENT_EMAIL",
|
|
23
|
-
description: "Google client email"
|
|
24
|
-
}),
|
|
25
|
-
privateKey: loadSetting({
|
|
26
|
-
settingValue: void 0,
|
|
27
|
-
settingName: "privateKey",
|
|
28
|
-
environmentVariableName: "GOOGLE_PRIVATE_KEY",
|
|
29
|
-
description: "Google private key"
|
|
30
|
-
}),
|
|
31
|
-
privateKeyId: loadOptionalSetting({
|
|
32
|
-
settingValue: void 0,
|
|
33
|
-
environmentVariableName: "GOOGLE_PRIVATE_KEY_ID"
|
|
34
|
-
})
|
|
35
|
-
};
|
|
36
|
-
} catch (error) {
|
|
37
|
-
throw new Error(`Failed to load Google credentials: ${error.message}`);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
var base64url = (str) => {
|
|
41
|
-
return btoa(str).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
42
|
-
};
|
|
43
|
-
var importPrivateKey = async (pemKey) => {
|
|
44
|
-
const pemHeader = "-----BEGIN PRIVATE KEY-----";
|
|
45
|
-
const pemFooter = "-----END PRIVATE KEY-----";
|
|
46
|
-
const pemContents = pemKey.replace(pemHeader, "").replace(pemFooter, "").replace(/\s/g, "");
|
|
47
|
-
const binaryString = atob(pemContents);
|
|
48
|
-
const binaryData = new Uint8Array(binaryString.length);
|
|
49
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
50
|
-
binaryData[i] = binaryString.charCodeAt(i);
|
|
51
|
-
}
|
|
52
|
-
return await crypto.subtle.importKey(
|
|
53
|
-
"pkcs8",
|
|
54
|
-
binaryData,
|
|
55
|
-
{ name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" },
|
|
56
|
-
true,
|
|
57
|
-
["sign"]
|
|
58
|
-
);
|
|
59
|
-
};
|
|
60
|
-
var buildJwt = async (credentials) => {
|
|
61
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
62
|
-
const header = {
|
|
63
|
-
alg: "RS256",
|
|
64
|
-
typ: "JWT"
|
|
65
|
-
};
|
|
66
|
-
if (credentials.privateKeyId) {
|
|
67
|
-
header.kid = credentials.privateKeyId;
|
|
68
|
-
}
|
|
69
|
-
const payload = {
|
|
70
|
-
iss: credentials.clientEmail,
|
|
71
|
-
scope: "https://www.googleapis.com/auth/cloud-platform",
|
|
72
|
-
aud: "https://oauth2.googleapis.com/token",
|
|
73
|
-
exp: now + 3600,
|
|
74
|
-
iat: now
|
|
75
|
-
};
|
|
76
|
-
const privateKey = await importPrivateKey(credentials.privateKey);
|
|
77
|
-
const signingInput = `${base64url(JSON.stringify(header))}.${base64url(
|
|
78
|
-
JSON.stringify(payload)
|
|
79
|
-
)}`;
|
|
80
|
-
const encoder = new TextEncoder();
|
|
81
|
-
const data = encoder.encode(signingInput);
|
|
82
|
-
const signature = await crypto.subtle.sign(
|
|
83
|
-
"RSASSA-PKCS1-v1_5",
|
|
84
|
-
privateKey,
|
|
85
|
-
data
|
|
86
|
-
);
|
|
87
|
-
const signatureBase64 = base64url(
|
|
88
|
-
String.fromCharCode(...new Uint8Array(signature))
|
|
89
|
-
);
|
|
90
|
-
return `${base64url(JSON.stringify(header))}.${base64url(
|
|
91
|
-
JSON.stringify(payload)
|
|
92
|
-
)}.${signatureBase64}`;
|
|
93
|
-
};
|
|
94
|
-
async function generateAuthToken(credentials) {
|
|
95
|
-
try {
|
|
96
|
-
const creds = credentials || await loadCredentials();
|
|
97
|
-
const jwt = await buildJwt(creds);
|
|
98
|
-
const response = await fetch("https://oauth2.googleapis.com/token", {
|
|
99
|
-
method: "POST",
|
|
100
|
-
headers: withUserAgentSuffix(
|
|
101
|
-
{ "Content-Type": "application/x-www-form-urlencoded" },
|
|
102
|
-
`ai-sdk/google-vertex/${VERSION}`,
|
|
103
|
-
getRuntimeEnvironmentUserAgent()
|
|
104
|
-
),
|
|
105
|
-
body: new URLSearchParams({
|
|
106
|
-
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
|
|
107
|
-
assertion: jwt
|
|
108
|
-
})
|
|
109
|
-
});
|
|
110
|
-
if (!response.ok) {
|
|
111
|
-
throw new Error(`Token request failed: ${response.statusText}`);
|
|
112
|
-
}
|
|
113
|
-
const data = await response.json();
|
|
114
|
-
return data.access_token;
|
|
115
|
-
} catch (error) {
|
|
116
|
-
throw error;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// src/anthropic/google-vertex-anthropic-provider.ts
|
|
121
|
-
import {
|
|
122
|
-
NoSuchModelError
|
|
123
|
-
} from "@ai-sdk/provider";
|
|
124
|
-
import {
|
|
125
|
-
loadOptionalSetting as loadOptionalSetting2,
|
|
126
|
-
withoutTrailingSlash
|
|
127
|
-
} from "@ai-sdk/provider-utils";
|
|
128
|
-
import {
|
|
129
|
-
anthropicTools,
|
|
130
|
-
AnthropicMessagesLanguageModel
|
|
131
|
-
} from "@ai-sdk/anthropic/internal";
|
|
132
|
-
var vertexAnthropicTools = {
|
|
133
|
-
/**
|
|
134
|
-
* The bash tool enables Claude to execute shell commands in a persistent bash session,
|
|
135
|
-
* allowing system operations, script execution, and command-line automation.
|
|
136
|
-
*
|
|
137
|
-
* Image results are supported.
|
|
138
|
-
*/
|
|
139
|
-
bash_20241022: anthropicTools.bash_20241022,
|
|
140
|
-
/**
|
|
141
|
-
* The bash tool enables Claude to execute shell commands in a persistent bash session,
|
|
142
|
-
* allowing system operations, script execution, and command-line automation.
|
|
143
|
-
*
|
|
144
|
-
* Image results are supported.
|
|
145
|
-
*/
|
|
146
|
-
bash_20250124: anthropicTools.bash_20250124,
|
|
147
|
-
/**
|
|
148
|
-
* Claude can use an Anthropic-defined text editor tool to view and modify text files,
|
|
149
|
-
* helping you debug, fix, and improve your code or other text documents.
|
|
150
|
-
*
|
|
151
|
-
* Supported models: Claude Sonnet 3.5
|
|
152
|
-
*/
|
|
153
|
-
textEditor_20241022: anthropicTools.textEditor_20241022,
|
|
154
|
-
/**
|
|
155
|
-
* Claude can use an Anthropic-defined text editor tool to view and modify text files,
|
|
156
|
-
* helping you debug, fix, and improve your code or other text documents.
|
|
157
|
-
*
|
|
158
|
-
* Supported models: Claude Sonnet 3.7
|
|
159
|
-
*/
|
|
160
|
-
textEditor_20250124: anthropicTools.textEditor_20250124,
|
|
161
|
-
/**
|
|
162
|
-
* Claude can use an Anthropic-defined text editor tool to view and modify text files.
|
|
163
|
-
* Note: This version does not support the "undo_edit" command.
|
|
164
|
-
* @deprecated Use textEditor_20250728 instead
|
|
165
|
-
*/
|
|
166
|
-
textEditor_20250429: anthropicTools.textEditor_20250429,
|
|
167
|
-
/**
|
|
168
|
-
* Claude can use an Anthropic-defined text editor tool to view and modify text files.
|
|
169
|
-
* Note: This version does not support the "undo_edit" command and adds optional max_characters parameter.
|
|
170
|
-
* Supported models: Claude Sonnet 4, Opus 4, and Opus 4.1
|
|
171
|
-
*/
|
|
172
|
-
textEditor_20250728: anthropicTools.textEditor_20250728,
|
|
173
|
-
/**
|
|
174
|
-
* Claude can interact with computer environments through the computer use tool, which
|
|
175
|
-
* provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.
|
|
176
|
-
*
|
|
177
|
-
* Image results are supported.
|
|
178
|
-
*/
|
|
179
|
-
computer_20241022: anthropicTools.computer_20241022,
|
|
180
|
-
/**
|
|
181
|
-
* Creates a web search tool that gives Claude direct access to real-time web content.
|
|
182
|
-
*/
|
|
183
|
-
webSearch_20250305: anthropicTools.webSearch_20250305
|
|
184
|
-
};
|
|
185
|
-
function createVertexAnthropic(options = {}) {
|
|
186
|
-
const getBaseURL = () => {
|
|
187
|
-
var _a;
|
|
188
|
-
const location = loadOptionalSetting2({
|
|
189
|
-
settingValue: options.location,
|
|
190
|
-
environmentVariableName: "GOOGLE_VERTEX_LOCATION"
|
|
191
|
-
});
|
|
192
|
-
const project = loadOptionalSetting2({
|
|
193
|
-
settingValue: options.project,
|
|
194
|
-
environmentVariableName: "GOOGLE_VERTEX_PROJECT"
|
|
195
|
-
});
|
|
196
|
-
return (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : `https://${location === "global" ? "" : location + "-"}aiplatform.googleapis.com/v1/projects/${project}/locations/${location}/publishers/anthropic/models`;
|
|
197
|
-
};
|
|
198
|
-
const createChatModel = (modelId) => {
|
|
199
|
-
var _a;
|
|
200
|
-
return new AnthropicMessagesLanguageModel(modelId, {
|
|
201
|
-
provider: "vertex.anthropic.messages",
|
|
202
|
-
baseURL: getBaseURL(),
|
|
203
|
-
headers: (_a = options.headers) != null ? _a : {},
|
|
204
|
-
fetch: options.fetch,
|
|
205
|
-
buildRequestUrl: (baseURL, isStreaming) => `${baseURL}/${modelId}:${isStreaming ? "streamRawPredict" : "rawPredict"}`,
|
|
206
|
-
transformRequestBody: (args) => {
|
|
207
|
-
const { model, ...rest } = args;
|
|
208
|
-
return {
|
|
209
|
-
...rest,
|
|
210
|
-
anthropic_version: "vertex-2023-10-16"
|
|
211
|
-
};
|
|
212
|
-
},
|
|
213
|
-
// Google Vertex Anthropic doesn't support URL sources, force download and base64 conversion
|
|
214
|
-
supportedUrls: () => ({}),
|
|
215
|
-
// force the use of JSON tool fallback for structured outputs since beta header isn't supported
|
|
216
|
-
supportsNativeStructuredOutput: false
|
|
217
|
-
});
|
|
218
|
-
};
|
|
219
|
-
const provider = function(modelId) {
|
|
220
|
-
if (new.target) {
|
|
221
|
-
throw new Error(
|
|
222
|
-
"The Anthropic model function cannot be called with the new keyword."
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
return createChatModel(modelId);
|
|
226
|
-
};
|
|
227
|
-
provider.specificationVersion = "v3";
|
|
228
|
-
provider.languageModel = createChatModel;
|
|
229
|
-
provider.chat = createChatModel;
|
|
230
|
-
provider.messages = createChatModel;
|
|
231
|
-
provider.embeddingModel = (modelId) => {
|
|
232
|
-
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
233
|
-
};
|
|
234
|
-
provider.textEmbeddingModel = provider.embeddingModel;
|
|
235
|
-
provider.imageModel = (modelId) => {
|
|
236
|
-
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
237
|
-
};
|
|
238
|
-
provider.tools = vertexAnthropicTools;
|
|
239
|
-
return provider;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// src/anthropic/edge/google-vertex-anthropic-provider-edge.ts
|
|
243
|
-
function createVertexAnthropic2(options = {}) {
|
|
244
|
-
return createVertexAnthropic({
|
|
245
|
-
...options,
|
|
246
|
-
headers: async () => ({
|
|
247
|
-
Authorization: `Bearer ${await generateAuthToken(
|
|
248
|
-
options.googleCredentials
|
|
249
|
-
)}`,
|
|
250
|
-
...await resolve(options.headers)
|
|
251
|
-
})
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
var vertexAnthropic = createVertexAnthropic2();
|
|
255
|
-
export {
|
|
256
|
-
createVertexAnthropic2 as createVertexAnthropic,
|
|
257
|
-
vertexAnthropic
|
|
258
|
-
};
|
|
259
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/anthropic/edge/google-vertex-anthropic-provider-edge.ts","../../../src/edge/google-vertex-auth-edge.ts","../../../src/version.ts","../../../src/anthropic/google-vertex-anthropic-provider.ts"],"sourcesContent":["import { resolve } from '@ai-sdk/provider-utils';\nimport {\n generateAuthToken,\n GoogleCredentials,\n} from '../../edge/google-vertex-auth-edge';\nimport {\n createVertexAnthropic as createVertexAnthropicOriginal,\n GoogleVertexAnthropicProvider,\n GoogleVertexAnthropicProviderSettings as GoogleVertexAnthropicProviderSettingsOriginal,\n} from '../google-vertex-anthropic-provider';\n\nexport type { GoogleVertexAnthropicProvider };\n\nexport interface GoogleVertexAnthropicProviderSettings\n extends GoogleVertexAnthropicProviderSettingsOriginal {\n /**\n * Optional. The Google credentials for the Google Cloud service account. If\n * not provided, the Google Vertex provider will use environment variables to\n * load the credentials.\n */\n googleCredentials?: GoogleCredentials;\n}\n\nexport function createVertexAnthropic(\n options: GoogleVertexAnthropicProviderSettings = {},\n): GoogleVertexAnthropicProvider {\n return createVertexAnthropicOriginal({\n ...options,\n headers: async () => ({\n Authorization: `Bearer ${await generateAuthToken(\n options.googleCredentials,\n )}`,\n ...(await resolve(options.headers)),\n }),\n });\n}\n\n/**\n * Default Google Vertex AI Anthropic provider instance.\n */\nexport const vertexAnthropic = createVertexAnthropic();\n","import {\n loadOptionalSetting,\n loadSetting,\n withUserAgentSuffix,\n getRuntimeEnvironmentUserAgent,\n} from '@ai-sdk/provider-utils';\nimport { VERSION } from '../version';\n\nexport interface GoogleCredentials {\n /**\n * The client email for the Google Cloud service account. Defaults to the\n * value of the `GOOGLE_CLIENT_EMAIL` environment variable.\n */\n clientEmail: string;\n\n /**\n * The private key for the Google Cloud service account. Defaults to the\n * value of the `GOOGLE_PRIVATE_KEY` environment variable.\n */\n privateKey: string;\n\n /**\n * Optional. The private key ID for the Google Cloud service account. Defaults\n * to the value of the `GOOGLE_PRIVATE_KEY_ID` environment variable.\n */\n privateKeyId?: string;\n}\n\nconst loadCredentials = async (): Promise<GoogleCredentials> => {\n try {\n return {\n clientEmail: loadSetting({\n settingValue: undefined,\n settingName: 'clientEmail',\n environmentVariableName: 'GOOGLE_CLIENT_EMAIL',\n description: 'Google client email',\n }),\n privateKey: loadSetting({\n settingValue: undefined,\n settingName: 'privateKey',\n environmentVariableName: 'GOOGLE_PRIVATE_KEY',\n description: 'Google private key',\n }),\n privateKeyId: loadOptionalSetting({\n settingValue: undefined,\n environmentVariableName: 'GOOGLE_PRIVATE_KEY_ID',\n }),\n };\n } catch (error: any) {\n throw new Error(`Failed to load Google credentials: ${error.message}`);\n }\n};\n\n// Convert a string to base64url\nconst base64url = (str: string) => {\n return btoa(str).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=/g, '');\n};\nconst importPrivateKey = async (pemKey: string) => {\n const pemHeader = '-----BEGIN PRIVATE KEY-----';\n const pemFooter = '-----END PRIVATE KEY-----';\n\n // Remove header, footer, and any whitespace/newlines\n const pemContents = pemKey\n .replace(pemHeader, '')\n .replace(pemFooter, '')\n .replace(/\\s/g, '');\n\n // Decode base64 to binary\n const binaryString = atob(pemContents);\n\n // Convert binary string to Uint8Array\n const binaryData = new Uint8Array(binaryString.length);\n for (let i = 0; i < binaryString.length; i++) {\n binaryData[i] = binaryString.charCodeAt(i);\n }\n\n return await crypto.subtle.importKey(\n 'pkcs8',\n binaryData,\n { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-256' },\n true,\n ['sign'],\n );\n};\n\nconst buildJwt = async (credentials: GoogleCredentials) => {\n const now = Math.floor(Date.now() / 1000);\n\n // Only include kid in header if privateKeyId is provided\n const header: { alg: string; typ: string; kid?: string } = {\n alg: 'RS256',\n typ: 'JWT',\n };\n\n if (credentials.privateKeyId) {\n header.kid = credentials.privateKeyId;\n }\n\n const payload = {\n iss: credentials.clientEmail,\n scope: 'https://www.googleapis.com/auth/cloud-platform',\n aud: 'https://oauth2.googleapis.com/token',\n exp: now + 3600,\n iat: now,\n };\n\n const privateKey = await importPrivateKey(credentials.privateKey);\n\n const signingInput = `${base64url(JSON.stringify(header))}.${base64url(\n JSON.stringify(payload),\n )}`;\n const encoder = new TextEncoder();\n const data = encoder.encode(signingInput);\n\n const signature = await crypto.subtle.sign(\n 'RSASSA-PKCS1-v1_5',\n privateKey,\n data,\n );\n\n const signatureBase64 = base64url(\n String.fromCharCode(...new Uint8Array(signature)),\n );\n\n return `${base64url(JSON.stringify(header))}.${base64url(\n JSON.stringify(payload),\n )}.${signatureBase64}`;\n};\n\n/**\n * Generate an authentication token for Google Vertex AI in a manner compatible\n * with the Edge runtime.\n */\nexport async function generateAuthToken(credentials?: GoogleCredentials) {\n try {\n const creds = credentials || (await loadCredentials());\n const jwt = await buildJwt(creds);\n\n const response = await fetch('https://oauth2.googleapis.com/token', {\n method: 'POST',\n headers: withUserAgentSuffix(\n { 'Content-Type': 'application/x-www-form-urlencoded' },\n `ai-sdk/google-vertex/${VERSION}`,\n getRuntimeEnvironmentUserAgent(),\n ),\n body: new URLSearchParams({\n grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',\n assertion: jwt,\n }),\n });\n\n if (!response.ok) {\n throw new Error(`Token request failed: ${response.statusText}`);\n }\n\n const data = await response.json();\n return data.access_token;\n } catch (error) {\n throw error;\n }\n}\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n","import {\n LanguageModelV3,\n NoSuchModelError,\n ProviderV3,\n} from '@ai-sdk/provider';\nimport {\n FetchFunction,\n Resolvable,\n loadOptionalSetting,\n withoutTrailingSlash,\n} from '@ai-sdk/provider-utils';\nimport {\n anthropicTools,\n AnthropicMessagesLanguageModel,\n} from '@ai-sdk/anthropic/internal';\nimport { GoogleVertexAnthropicMessagesModelId } from './google-vertex-anthropic-messages-options';\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 vertexAnthropicTools = {\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};\nexport interface GoogleVertexAnthropicProvider extends ProviderV3 {\n /**\n * Creates a model for text generation.\n */\n (modelId: GoogleVertexAnthropicMessagesModelId): LanguageModelV3;\n\n /**\n * Creates a model for text generation.\n */\n languageModel(modelId: GoogleVertexAnthropicMessagesModelId): LanguageModelV3;\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\n */\n tools: typeof vertexAnthropicTools;\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 createVertexAnthropic(\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 return (\n withoutTrailingSlash(options.baseURL) ??\n `https://${location === 'global' ? '' : location + '-'}aiplatform.googleapis.com/v1/projects/${project}/locations/${location}/publishers/anthropic/models`\n );\n };\n\n const createChatModel = (modelId: GoogleVertexAnthropicMessagesModelId) =>\n new AnthropicMessagesLanguageModel(modelId, {\n provider: 'vertex.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, ...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 });\n\n const provider = function (modelId: GoogleVertexAnthropicMessagesModelId) {\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 = 'v3' 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 = vertexAnthropicTools;\n\n return provider;\n}\n"],"mappings":";AAAA,SAAS,eAAe;;;ACAxB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACHA,IAAM,UACX,OACI,iBACA;;;ADuBN,IAAM,kBAAkB,YAAwC;AAC9D,MAAI;AACF,WAAO;AAAA,MACL,aAAa,YAAY;AAAA,QACvB,cAAc;AAAA,QACd,aAAa;AAAA,QACb,yBAAyB;AAAA,QACzB,aAAa;AAAA,MACf,CAAC;AAAA,MACD,YAAY,YAAY;AAAA,QACtB,cAAc;AAAA,QACd,aAAa;AAAA,QACb,yBAAyB;AAAA,QACzB,aAAa;AAAA,MACf,CAAC;AAAA,MACD,cAAc,oBAAoB;AAAA,QAChC,cAAc;AAAA,QACd,yBAAyB;AAAA,MAC3B,CAAC;AAAA,IACH;AAAA,EACF,SAAS,OAAY;AACnB,UAAM,IAAI,MAAM,sCAAsC,MAAM,OAAO,EAAE;AAAA,EACvE;AACF;AAGA,IAAM,YAAY,CAAC,QAAgB;AACjC,SAAO,KAAK,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,MAAM,EAAE;AAC3E;AACA,IAAM,mBAAmB,OAAO,WAAmB;AACjD,QAAM,YAAY;AAClB,QAAM,YAAY;AAGlB,QAAM,cAAc,OACjB,QAAQ,WAAW,EAAE,EACrB,QAAQ,WAAW,EAAE,EACrB,QAAQ,OAAO,EAAE;AAGpB,QAAM,eAAe,KAAK,WAAW;AAGrC,QAAM,aAAa,IAAI,WAAW,aAAa,MAAM;AACrD,WAAS,IAAI,GAAG,IAAI,aA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