@ai-sdk/google-vertex 3.0.0-beta.2 → 3.0.0-beta.20
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 +165 -0
- package/dist/anthropic/edge/index.js +1 -1
- package/dist/anthropic/edge/index.js.map +1 -1
- package/dist/anthropic/edge/index.mjs +1 -1
- package/dist/anthropic/edge/index.mjs.map +1 -1
- package/dist/anthropic/index.js +1 -1
- package/dist/anthropic/index.js.map +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/edge/index.d.mts +1 -1
- package/dist/edge/index.d.ts +1 -1
- package/dist/edge/index.js +32 -31
- package/dist/edge/index.js.map +1 -1
- package/dist/edge/index.mjs +6 -5
- package/dist/edge/index.mjs.map +1 -1
- package/dist/index.d.mts +14 -17
- package/dist/index.d.ts +14 -17
- package/dist/index.js +32 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,170 @@
|
|
1
1
|
# @ai-sdk/google-vertex
|
2
2
|
|
3
|
+
## 3.0.0-beta.20
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- Updated dependencies [78e7fa9]
|
8
|
+
- Updated dependencies [0f05690]
|
9
|
+
- Updated dependencies [f418dd7]
|
10
|
+
- Updated dependencies [27deb4d]
|
11
|
+
- @ai-sdk/google@2.0.0-beta.18
|
12
|
+
- @ai-sdk/anthropic@2.0.0-beta.12
|
13
|
+
- @ai-sdk/provider@2.0.0-beta.2
|
14
|
+
- @ai-sdk/provider-utils@3.0.0-beta.9
|
15
|
+
|
16
|
+
## 3.0.0-beta.19
|
17
|
+
|
18
|
+
### Patch Changes
|
19
|
+
|
20
|
+
- Updated dependencies [eb173f1]
|
21
|
+
- Updated dependencies [dd5fd43]
|
22
|
+
- @ai-sdk/anthropic@2.0.0-beta.11
|
23
|
+
- @ai-sdk/google@2.0.0-beta.17
|
24
|
+
- @ai-sdk/provider-utils@3.0.0-beta.8
|
25
|
+
|
26
|
+
## 3.0.0-beta.18
|
27
|
+
|
28
|
+
### Patch Changes
|
29
|
+
|
30
|
+
- Updated dependencies [e7fcc86]
|
31
|
+
- Updated dependencies [269683f]
|
32
|
+
- @ai-sdk/provider-utils@3.0.0-beta.7
|
33
|
+
- @ai-sdk/anthropic@2.0.0-beta.10
|
34
|
+
- @ai-sdk/google@2.0.0-beta.16
|
35
|
+
|
36
|
+
## 3.0.0-beta.17
|
37
|
+
|
38
|
+
### Patch Changes
|
39
|
+
|
40
|
+
- Updated dependencies [4f26d59]
|
41
|
+
- Updated dependencies [ac34802]
|
42
|
+
- Updated dependencies [a753b3a]
|
43
|
+
- @ai-sdk/anthropic@2.0.0-beta.9
|
44
|
+
- @ai-sdk/provider-utils@3.0.0-beta.6
|
45
|
+
- @ai-sdk/google@2.0.0-beta.15
|
46
|
+
|
47
|
+
## 3.0.0-beta.16
|
48
|
+
|
49
|
+
### Patch Changes
|
50
|
+
|
51
|
+
- Updated dependencies [75f03b1]
|
52
|
+
- @ai-sdk/google@2.0.0-beta.14
|
53
|
+
|
54
|
+
## 3.0.0-beta.15
|
55
|
+
|
56
|
+
### Patch Changes
|
57
|
+
|
58
|
+
- Updated dependencies [57edfcb]
|
59
|
+
- Updated dependencies [383cbfa]
|
60
|
+
- @ai-sdk/provider-utils@3.0.0-beta.5
|
61
|
+
- @ai-sdk/anthropic@2.0.0-beta.8
|
62
|
+
- @ai-sdk/google@2.0.0-beta.13
|
63
|
+
|
64
|
+
## 3.0.0-beta.14
|
65
|
+
|
66
|
+
### Patch Changes
|
67
|
+
|
68
|
+
- 205077b: fix: improve Zod compatibility
|
69
|
+
- Updated dependencies [205077b]
|
70
|
+
- @ai-sdk/provider-utils@3.0.0-beta.4
|
71
|
+
- @ai-sdk/anthropic@2.0.0-beta.7
|
72
|
+
- @ai-sdk/google@2.0.0-beta.12
|
73
|
+
|
74
|
+
## 3.0.0-beta.13
|
75
|
+
|
76
|
+
### Patch Changes
|
77
|
+
|
78
|
+
- Updated dependencies [6a16dcf]
|
79
|
+
- @ai-sdk/google@2.0.0-beta.11
|
80
|
+
|
81
|
+
## 3.0.0-beta.12
|
82
|
+
|
83
|
+
### Minor Changes
|
84
|
+
|
85
|
+
- 6ca44f2: Fixed global region for vertex provider
|
86
|
+
|
87
|
+
### Patch Changes
|
88
|
+
|
89
|
+
- Updated dependencies [05d2819]
|
90
|
+
- Updated dependencies [7badba2]
|
91
|
+
- @ai-sdk/provider-utils@3.0.0-beta.3
|
92
|
+
- @ai-sdk/google@2.0.0-beta.10
|
93
|
+
- @ai-sdk/anthropic@2.0.0-beta.6
|
94
|
+
|
95
|
+
## 3.0.0-beta.11
|
96
|
+
|
97
|
+
### Patch Changes
|
98
|
+
|
99
|
+
- Updated dependencies [8af9e03]
|
100
|
+
- @ai-sdk/google@2.0.0-beta.9
|
101
|
+
|
102
|
+
## 3.0.0-beta.10
|
103
|
+
|
104
|
+
### Patch Changes
|
105
|
+
|
106
|
+
- Updated dependencies [b9ddcdd]
|
107
|
+
- @ai-sdk/anthropic@2.0.0-beta.5
|
108
|
+
|
109
|
+
## 3.0.0-beta.9
|
110
|
+
|
111
|
+
### Patch Changes
|
112
|
+
|
113
|
+
- Updated dependencies [2e06f14]
|
114
|
+
- @ai-sdk/google@2.0.0-beta.8
|
115
|
+
|
116
|
+
## 3.0.0-beta.8
|
117
|
+
|
118
|
+
### Patch Changes
|
119
|
+
|
120
|
+
- Updated dependencies [19a4336]
|
121
|
+
- @ai-sdk/google@2.0.0-beta.7
|
122
|
+
|
123
|
+
## 3.0.0-beta.7
|
124
|
+
|
125
|
+
### Patch Changes
|
126
|
+
|
127
|
+
- Updated dependencies [fdff8a4]
|
128
|
+
- Updated dependencies [84577c8]
|
129
|
+
- @ai-sdk/anthropic@2.0.0-beta.4
|
130
|
+
|
131
|
+
## 3.0.0-beta.6
|
132
|
+
|
133
|
+
### Patch Changes
|
134
|
+
|
135
|
+
- Updated dependencies [878bf45]
|
136
|
+
- @ai-sdk/google@2.0.0-beta.6
|
137
|
+
|
138
|
+
## 3.0.0-beta.5
|
139
|
+
|
140
|
+
### Patch Changes
|
141
|
+
|
142
|
+
- Updated dependencies [42fcd32]
|
143
|
+
- @ai-sdk/google@2.0.0-beta.5
|
144
|
+
|
145
|
+
## 3.0.0-beta.4
|
146
|
+
|
147
|
+
### Patch Changes
|
148
|
+
|
149
|
+
- Updated dependencies [c68931f]
|
150
|
+
- Updated dependencies [8e6b69d]
|
151
|
+
- @ai-sdk/google@2.0.0-beta.4
|
152
|
+
|
153
|
+
## 3.0.0-beta.3
|
154
|
+
|
155
|
+
### Patch Changes
|
156
|
+
|
157
|
+
- d1a034f: feature: using Zod 4 for internal stuff
|
158
|
+
- Updated dependencies [0571b98]
|
159
|
+
- Updated dependencies [a85c85f]
|
160
|
+
- Updated dependencies [cb787ac]
|
161
|
+
- Updated dependencies [39a4fab]
|
162
|
+
- Updated dependencies [d1a034f]
|
163
|
+
- Updated dependencies [0b678b2]
|
164
|
+
- @ai-sdk/provider-utils@3.0.0-beta.2
|
165
|
+
- @ai-sdk/anthropic@2.0.0-beta.3
|
166
|
+
- @ai-sdk/google@2.0.0-beta.3
|
167
|
+
|
3
168
|
## 3.0.0-beta.2
|
4
169
|
|
5
170
|
### Patch Changes
|
@@ -144,7 +144,7 @@ function createVertexAnthropic(options = {}) {
|
|
144
144
|
settingValue: options.project,
|
145
145
|
environmentVariableName: "GOOGLE_VERTEX_PROJECT"
|
146
146
|
});
|
147
|
-
const baseURL = (_a = (0, import_provider_utils2.withoutTrailingSlash)(options.baseURL)) != null ? _a : `https://${location}
|
147
|
+
const baseURL = (_a = (0, import_provider_utils2.withoutTrailingSlash)(options.baseURL)) != null ? _a : `https://${location === "global" ? "" : location + "-"}aiplatform.googleapis.com/v1/projects/${project}/locations/${location}/publishers/anthropic/models`;
|
148
148
|
const createChatModel = (modelId) => {
|
149
149
|
var _a2;
|
150
150
|
return new import_internal.AnthropicMessagesLanguageModel(modelId, {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/anthropic/edge/index.ts","../../../src/anthropic/edge/google-vertex-anthropic-provider-edge.ts","../../../src/edge/google-vertex-auth-edge.ts","../../../src/anthropic/google-vertex-anthropic-provider.ts"],"sourcesContent":["export {\n createVertexAnthropic,\n vertexAnthropic,\n} from './google-vertex-anthropic-provider-edge';\nexport type {\n GoogleVertexAnthropicProviderSettings,\n GoogleVertexAnthropicProvider,\n} from './google-vertex-anthropic-provider-edge';\n","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 { loadOptionalSetting, loadSetting } from '@ai-sdk/provider-utils';\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: { 'Content-Type': 'application/x-www-form-urlencoded' },\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","import {\n LanguageModelV2,\n NoSuchModelError,\n ProviderV2,\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';\nexport interface GoogleVertexAnthropicProvider extends ProviderV2 {\n /**\nCreates a model for text generation.\n*/\n (modelId: GoogleVertexAnthropicMessagesModelId): LanguageModelV2;\n\n /**\nCreates a model for text generation.\n*/\n languageModel(modelId: GoogleVertexAnthropicMessagesModelId): LanguageModelV2;\n\n /**\nAnthropic-specific computer use tool.\n */\n tools: typeof anthropicTools;\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 /**\nUse a different URL prefix for API calls, e.g. to use proxy servers.\nThe default prefix is `https://api.anthropic.com/v1`.\n */\n baseURL?: string;\n\n /**\nCustom headers to include in the requests.\n */\n headers?: Resolvable<Record<string, string | undefined>>;\n\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\n/**\nCreate a Google Vertex Anthropic provider instance.\n */\nexport function createVertexAnthropic(\n options: GoogleVertexAnthropicProviderSettings = {},\n): GoogleVertexAnthropicProvider {\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 const baseURL =\n withoutTrailingSlash(options.baseURL) ??\n `https://${location}-aiplatform.googleapis.com/v1/projects/${project}/locations/${location}/publishers/anthropic/models`;\n\n const createChatModel = (modelId: GoogleVertexAnthropicMessagesModelId) =>\n new AnthropicMessagesLanguageModel(modelId, {\n provider: 'vertex.anthropic.messages',\n baseURL,\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 });\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.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.messages = createChatModel;\n\n provider.textEmbeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'textEmbeddingModel' });\n };\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n provider.tools = anthropicTools;\n\n return provider;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,+BAAAA;AAAA,EAAA;AAAA;AAAA;;;ACAA,IAAAC,yBAAwB;;;ACAxB,4BAAiD;AAsBjD,IAAM,kBAAkB,YAAwC;AAC9D,MAAI;AACF,WAAO;AAAA,MACL,iBAAa,mCAAY;AAAA,QACvB,cAAc;AAAA,QACd,aAAa;AAAA,QACb,yBAAyB;AAAA,QACzB,aAAa;AAAA,MACf,CAAC;AAAA,MACD,gBAAY,mCAAY;AAAA,QACtB,cAAc;AAAA,QACd,aAAa;AAAA,QACb,yBAAyB;AAAA,QACzB,aAAa;AAAA,MACf,CAAC;AAAA,MACD,kBAAc,2CAAoB;AAAA,QAChC,cAAc;AAAA,QACd,yBAAyB;AAAA,MAC3B,CAAC;AAAA,IACH;AAAA,EACF,SAAS,OAAY;AACnB,UAAM,IAAI,MAAM,sCAAsC,MAAM,OAAO,EAAE;AAAA,EACvE;AACF;AAGA,IAAM,YAAY,CAAC,QAAgB;AACjC,SAAO,KAAK,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,MAAM,EAAE;AAC3E;AACA,IAAM,mBAAmB,OAAO,WAAmB;AACjD,QAAM,YAAY;AAClB,QA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AA,MACF,sBAAsB,UAAQ;AAE5B,cAAM,EAAE,OAAO,GAAG,KAAK,IAAI;AAC3B,eAAO;AAAA,UACL,GAAG;AAAA,UACH,mBAAmB;AAAA,QACrB;AAAA,MACF;AAAA;AAAA,MAEA,eAAe,OAAO,CAAC;AAAA,IACzB,CAAC;AAAA;AAEH,QAAM,WAAW,SAAU,SAA+C;AACxE,QAAI,YAAY;AACd,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,WAAO,gBAAgB,OAAO;AAAA,EAChC;AAEA,WAAS,gBAAgB;AACzB,WAAS,OAAO;AAChB,WAAS,WAAW;AAEpB,WAAS,qBAAqB,CAAC,YAAoB;AACjD,UAAM,IAAI,iCAAiB,EAAE,SAAS,WAAW,qBAAqB,CAAC;AAAA,EACzE;AACA,WAAS,aAAa,CAAC,YAAoB;AACzC,UAAM,IAAI,iCAAiB,EAAE,SAAS,WAAW,aAAa,CAAC;AAAA,EACjE;AAEA,WAAS,QAAQ;AAEjB,SAAO;AACT;;;AFxGO,SAASC,uBACd,UAAiD,CAAC,GACnB;AAC/B,SAAO,sBAA8B;AAAA,IACnC,GAAG;AAAA,IACH,SAAS,aAAa;AAAA,MACpB,eAAe,UAAU,MAAM;AAAA,QAC7B,QAAQ;AAAA,MACV,CAAC;AAAA,MACD,GAAI,UAAM,gCAAQ,QAAQ,OAAO;AAAA,IACnC;AAAA,EACF,CAAC;AACH;AAKO,IAAM,kBAAkBA,uBAAsB;","names":["createVertexAnthropic","import_provider_utils","import_provider_utils","_a","baseURL","createVertexAnthropic"]}
|
1
|
+
{"version":3,"sources":["../../../src/anthropic/edge/index.ts","../../../src/anthropic/edge/google-vertex-anthropic-provider-edge.ts","../../../src/edge/google-vertex-auth-edge.ts","../../../src/anthropic/google-vertex-anthropic-provider.ts"],"sourcesContent":["export {\n createVertexAnthropic,\n vertexAnthropic,\n} from './google-vertex-anthropic-provider-edge';\nexport type {\n GoogleVertexAnthropicProviderSettings,\n GoogleVertexAnthropicProvider,\n} from './google-vertex-anthropic-provider-edge';\n","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 { loadOptionalSetting, loadSetting } from '@ai-sdk/provider-utils';\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: { 'Content-Type': 'application/x-www-form-urlencoded' },\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","import {\n LanguageModelV2,\n NoSuchModelError,\n ProviderV2,\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';\nexport interface GoogleVertexAnthropicProvider extends ProviderV2 {\n /**\nCreates a model for text generation.\n*/\n (modelId: GoogleVertexAnthropicMessagesModelId): LanguageModelV2;\n\n /**\nCreates a model for text generation.\n*/\n languageModel(modelId: GoogleVertexAnthropicMessagesModelId): LanguageModelV2;\n\n /**\nAnthropic-specific computer use tool.\n */\n tools: typeof anthropicTools;\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 /**\nUse a different URL prefix for API calls, e.g. to use proxy servers.\nThe default prefix is `https://api.anthropic.com/v1`.\n */\n baseURL?: string;\n\n /**\nCustom headers to include in the requests.\n */\n headers?: Resolvable<Record<string, string | undefined>>;\n\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\n/**\nCreate a Google Vertex Anthropic provider instance.\n */\nexport function createVertexAnthropic(\n options: GoogleVertexAnthropicProviderSettings = {},\n): GoogleVertexAnthropicProvider {\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 baseURL =\n withoutTrailingSlash(options.baseURL) ??\n `https://${location === 'global' ? '' : location + '-'}aiplatform.googleapis.com/v1/projects/${project}/locations/${location}/publishers/anthropic/models`;\n\n const createChatModel = (modelId: GoogleVertexAnthropicMessagesModelId) =>\n new AnthropicMessagesLanguageModel(modelId, {\n provider: 'vertex.anthropic.messages',\n baseURL,\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 });\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.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.messages = createChatModel;\n\n provider.textEmbeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'textEmbeddingModel' });\n };\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n provider.tools = anthropicTools;\n\n return provider;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,+BAAAA;AAAA,EAAA;AAAA;AAAA;;;ACAA,IAAAC,yBAAwB;;;ACAxB,4BAAiD;AAsBjD,IAAM,kBAAkB,YAAwC;AAC9D,MAAI;AACF,WAAO;AAAA,MACL,iBAAa,mCAAY;AAAA,QACvB,cAAc;AAAA,QACd,aAAa;AAAA,QACb,yBAAyB;AAAA,QACzB,aAAa;AAAA,MACf,CAAC;AAAA,MACD,gBAAY,mCAAY;AAAA,QACtB,cAAc;AAAA,QACd,aAAa;AAAA,QACb,yBAAyB;AAAA,QACzB,aAAa;AAAA,MACf,CAAC;AAAA,MACD,kBAAc,2CAAoB;AAAA,QAChC,cAAc;AAAA,QACd,yBAAyB;AAAA,MAC3B,CAAC;AAAA,IACH;AAAA,EACF,SAAS,OAAY;AACnB,UAAM,IAAI,MAAM,sCAAsC,MAAM,OAAO,EAAE;AAAA,EACvE;AACF;AAGA,IAAM,YAAY,CAAC,QAAgB;AACjC,SAAO,KAAK,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,MAAM,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,aAAa,QAAQ,KAAK;AAC5C,eAAW,CAAC,IAAI,aAAa,WAAW,CAAC;AAAA,EAC3C;AAEA,SAAO,MAAM,OAAO,OAAO;AAAA,IACzB;AAAA,IACA;AAA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OAAO;AAAA,EAChC;AAEA,WAAS,gBAAgB;AACzB,WAAS,OAAO;AAChB,WAAS,WAAW;AAEpB,WAAS,qBAAqB,CAAC,YAAoB;AACjD,UAAM,IAAI,iCAAiB,EAAE,SAAS,WAAW,qBAAqB,CAAC;AAAA,EACzE;AACA,WAAS,aAAa,CAAC,YAAoB;AACzC,UAAM,IAAI,iCAAiB,EAAE,SAAS,WAAW,aAAa,CAAC;AAAA,EACjE;AAEA,WAAS,QAAQ;AAEjB,SAAO;AACT;;;AFzGO,SAASC,uBACd,UAAiD,CAAC,GACnB;AAC/B,SAAO,sBAA8B;AAAA,IACnC,GAAG;AAAA,IACH,SAAS,aAAa;AAAA,MACpB,eAAe,UAAU,MAAM;AAAA,QAC7B,QAAQ;AAAA,MACV,CAAC;AAAA,MACD,GAAI,UAAM,gCAAQ,QAAQ,OAAO;AAAA,IACnC;AAAA,EACF,CAAC;AACH;AAKO,IAAM,kBAAkBA,uBAAsB;","names":["createVertexAnthropic","import_provider_utils","import_provider_utils","_a","baseURL","createVertexAnthropic"]}
|
@@ -125,7 +125,7 @@ function createVertexAnthropic(options = {}) {
|
|
125
125
|
settingValue: options.project,
|
126
126
|
environmentVariableName: "GOOGLE_VERTEX_PROJECT"
|
127
127
|
});
|
128
|
-
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : `https://${location}
|
128
|
+
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : `https://${location === "global" ? "" : location + "-"}aiplatform.googleapis.com/v1/projects/${project}/locations/${location}/publishers/anthropic/models`;
|
129
129
|
const createChatModel = (modelId) => {
|
130
130
|
var _a2;
|
131
131
|
return new AnthropicMessagesLanguageModel(modelId, {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/anthropic/edge/google-vertex-anthropic-provider-edge.ts","../../../src/edge/google-vertex-auth-edge.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 { loadOptionalSetting, loadSetting } from '@ai-sdk/provider-utils';\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: { 'Content-Type': 'application/x-www-form-urlencoded' },\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","import {\n LanguageModelV2,\n NoSuchModelError,\n ProviderV2,\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';\nexport interface GoogleVertexAnthropicProvider extends ProviderV2 {\n /**\nCreates a model for text generation.\n*/\n (modelId: GoogleVertexAnthropicMessagesModelId): LanguageModelV2;\n\n /**\nCreates a model for text generation.\n*/\n languageModel(modelId: GoogleVertexAnthropicMessagesModelId): LanguageModelV2;\n\n /**\nAnthropic-specific computer use tool.\n */\n tools: typeof anthropicTools;\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 /**\nUse a different URL prefix for API calls, e.g. to use proxy servers.\nThe default prefix is `https://api.anthropic.com/v1`.\n */\n baseURL?: string;\n\n /**\nCustom headers to include in the requests.\n */\n headers?: Resolvable<Record<string, string | undefined>>;\n\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\n/**\nCreate a Google Vertex Anthropic provider instance.\n */\nexport function createVertexAnthropic(\n options: GoogleVertexAnthropicProviderSettings = {},\n): GoogleVertexAnthropicProvider {\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 const baseURL =\n withoutTrailingSlash(options.baseURL) ??\n `https://${location}-aiplatform.googleapis.com/v1/projects/${project}/locations/${location}/publishers/anthropic/models`;\n\n const createChatModel = (modelId: GoogleVertexAnthropicMessagesModelId) =>\n new AnthropicMessagesLanguageModel(modelId, {\n provider: 'vertex.anthropic.messages',\n baseURL,\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 });\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.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.messages = createChatModel;\n\n provider.textEmbeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'textEmbeddingModel' });\n };\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n provider.tools = anthropicTools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oB;AACjD,UAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,qBAAqB,CAAC;AAAA,EACzE;AACA,WAAS,aAAa,CAAC,YAAoB;AACzC,UAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,aAAa,CAAC;AAAA,EACjE;AAEA,WAAS,QAAQ;AAEjB,SAAO;AACT;;;AFxGO,SAASC,uBACd,UAAiD,CAAC,GACnB;AAC/B,SAAO,sBAA8B;AAAA,IACnC,GAAG;AAAA,IACH,SAAS,aAAa;AAAA,MACpB,eAAe,UAAU,MAAM;AAAA,QAC7B,QAAQ;AAAA,MACV,CAAC;AAAA,MACD,GAAI,MAAM,QAAQ,QAAQ,OAAO;AAAA,IACnC;AAAA,EACF,CAAC;AACH;AAKO,IAAM,kBAAkBA,uBAAsB;","names":["loadOptionalSetting","_a","baseURL","createVertexAnthropic"]}
|
1
|
+
{"version":3,"sources":["../../../src/anthropic/edge/google-vertex-anthropic-provider-edge.ts","../../../src/edge/google-vertex-auth-edge.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 { loadOptionalSetting, loadSetting } from '@ai-sdk/provider-utils';\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: { 'Content-Type': 'application/x-www-form-urlencoded' },\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","import {\n LanguageModelV2,\n NoSuchModelError,\n ProviderV2,\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';\nexport interface GoogleVertexAnthropicProvider extends ProviderV2 {\n /**\nCreates a model for text generation.\n*/\n (modelId: GoogleVertexAnthropicMessagesModelId): LanguageModelV2;\n\n /**\nCreates a model for text generation.\n*/\n languageModel(modelId: GoogleVertexAnthropicMessagesModelId): LanguageModelV2;\n\n /**\nAnthropic-specific computer use tool.\n */\n tools: typeof anthropicTools;\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 /**\nUse a different URL prefix for API calls, e.g. to use proxy servers.\nThe default prefix is `https://api.anthropic.com/v1`.\n */\n baseURL?: string;\n\n /**\nCustom headers to include in the requests.\n */\n headers?: Resolvable<Record<string, string | undefined>>;\n\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\n/**\nCreate a Google Vertex Anthropic provider instance.\n */\nexport function createVertexAnthropic(\n options: GoogleVertexAnthropicProviderSettings = {},\n): GoogleVertexAnthropicProvider {\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 baseURL =\n withoutTrailingSlash(options.baseURL) ??\n `https://${location === 'global' ? '' : location + '-'}aiplatform.googleapis.com/v1/projects/${project}/locations/${location}/publishers/anthropic/models`;\n\n const createChatModel = (modelId: GoogleVertexAnthropicMessagesModelId) =>\n new AnthropicMessagesLanguageModel(modelId, {\n provider: 'vertex.anthropic.messages',\n baseURL,\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 });\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.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.messages = createChatModel;\n\n provider.textEmbeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'textEmbeddingModel' });\n };\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n provider.tools = anthropicTools;\n\n return provider;\n}\n"],"mappings":";AAAA,SAAS,eAAe;;;ACAxB,SAAS,qBAAqB,mBAAmB;AAsBjD,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;AA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Setting","_a","baseURL","createVertexAnthropic"]}
|
package/dist/anthropic/index.js
CHANGED
@@ -63,7 +63,7 @@ function createVertexAnthropic(options = {}) {
|
|
63
63
|
settingValue: options.project,
|
64
64
|
environmentVariableName: "GOOGLE_VERTEX_PROJECT"
|
65
65
|
});
|
66
|
-
const baseURL = (_a = (0, import_provider_utils.withoutTrailingSlash)(options.baseURL)) != null ? _a : `https://${location}
|
66
|
+
const baseURL = (_a = (0, import_provider_utils.withoutTrailingSlash)(options.baseURL)) != null ? _a : `https://${location === "global" ? "" : location + "-"}aiplatform.googleapis.com/v1/projects/${project}/locations/${location}/publishers/anthropic/models`;
|
67
67
|
const createChatModel = (modelId) => {
|
68
68
|
var _a2;
|
69
69
|
return new import_internal.AnthropicMessagesLanguageModel(modelId, {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/anthropic/index.ts","../../src/anthropic/google-vertex-anthropic-provider-node.ts","../../src/google-vertex-auth-google-auth-library.ts","../../src/anthropic/google-vertex-anthropic-provider.ts"],"sourcesContent":["export {\n vertexAnthropic,\n createVertexAnthropic,\n} from './google-vertex-anthropic-provider-node';\nexport type {\n GoogleVertexAnthropicProvider,\n GoogleVertexAnthropicProviderSettings,\n} from './google-vertex-anthropic-provider-node';\n","import { resolve } from '@ai-sdk/provider-utils';\nimport { GoogleAuthOptions } from 'google-auth-library';\nimport { generateAuthToken } from '../google-vertex-auth-google-auth-library';\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 Authentication options provided by google-auth-library.\nComplete list of authentication options is documented in the\nGoogleAuthOptions interface:\nhttps://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts.\n */\n googleAuthOptions?: GoogleAuthOptions;\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.googleAuthOptions,\n )}`,\n ...(await resolve(options.headers)),\n }),\n });\n}\n\n/**\nDefault Google Vertex Anthropic provider instance.\n */\nexport const vertexAnthropic = createVertexAnthropic();\n","import { GoogleAuth, GoogleAuthOptions } from 'google-auth-library';\n\nlet authInstance: GoogleAuth | null = null;\nlet authOptions: GoogleAuthOptions | null = null;\n\nfunction getAuth(options: GoogleAuthOptions) {\n if (!authInstance || options !== authOptions) {\n authInstance = new GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n ...options,\n });\n authOptions = options;\n }\n return authInstance;\n}\n\nexport async function generateAuthToken(options?: GoogleAuthOptions) {\n const auth = getAuth(options || {});\n const client = await auth.getClient();\n const token = await client.getAccessToken();\n return token?.token || null;\n}\n\n// For testing purposes only\nexport function _resetAuthInstance() {\n authInstance = null;\n}\n","import {\n LanguageModelV2,\n NoSuchModelError,\n ProviderV2,\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';\nexport interface GoogleVertexAnthropicProvider extends ProviderV2 {\n /**\nCreates a model for text generation.\n*/\n (modelId: GoogleVertexAnthropicMessagesModelId): LanguageModelV2;\n\n /**\nCreates a model for text generation.\n*/\n languageModel(modelId: GoogleVertexAnthropicMessagesModelId): LanguageModelV2;\n\n /**\nAnthropic-specific computer use tool.\n */\n tools: typeof anthropicTools;\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 /**\nUse a different URL prefix for API calls, e.g. to use proxy servers.\nThe default prefix is `https://api.anthropic.com/v1`.\n */\n baseURL?: string;\n\n /**\nCustom headers to include in the requests.\n */\n headers?: Resolvable<Record<string, string | undefined>>;\n\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\n/**\nCreate a Google Vertex Anthropic provider instance.\n */\nexport function createVertexAnthropic(\n options: GoogleVertexAnthropicProviderSettings = {},\n): GoogleVertexAnthropicProvider {\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 const baseURL =\n withoutTrailingSlash(options.baseURL) ??\n `https://${location}
|
1
|
+
{"version":3,"sources":["../../src/anthropic/index.ts","../../src/anthropic/google-vertex-anthropic-provider-node.ts","../../src/google-vertex-auth-google-auth-library.ts","../../src/anthropic/google-vertex-anthropic-provider.ts"],"sourcesContent":["export {\n vertexAnthropic,\n createVertexAnthropic,\n} from './google-vertex-anthropic-provider-node';\nexport type {\n GoogleVertexAnthropicProvider,\n GoogleVertexAnthropicProviderSettings,\n} from './google-vertex-anthropic-provider-node';\n","import { resolve } from '@ai-sdk/provider-utils';\nimport { GoogleAuthOptions } from 'google-auth-library';\nimport { generateAuthToken } from '../google-vertex-auth-google-auth-library';\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 Authentication options provided by google-auth-library.\nComplete list of authentication options is documented in the\nGoogleAuthOptions interface:\nhttps://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts.\n */\n googleAuthOptions?: GoogleAuthOptions;\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.googleAuthOptions,\n )}`,\n ...(await resolve(options.headers)),\n }),\n });\n}\n\n/**\nDefault Google Vertex Anthropic provider instance.\n */\nexport const vertexAnthropic = createVertexAnthropic();\n","import { GoogleAuth, GoogleAuthOptions } from 'google-auth-library';\n\nlet authInstance: GoogleAuth | null = null;\nlet authOptions: GoogleAuthOptions | null = null;\n\nfunction getAuth(options: GoogleAuthOptions) {\n if (!authInstance || options !== authOptions) {\n authInstance = new GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n ...options,\n });\n authOptions = options;\n }\n return authInstance;\n}\n\nexport async function generateAuthToken(options?: GoogleAuthOptions) {\n const auth = getAuth(options || {});\n const client = await auth.getClient();\n const token = await client.getAccessToken();\n return token?.token || null;\n}\n\n// For testing purposes only\nexport function _resetAuthInstance() {\n authInstance = null;\n}\n","import {\n LanguageModelV2,\n NoSuchModelError,\n ProviderV2,\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';\nexport interface GoogleVertexAnthropicProvider extends ProviderV2 {\n /**\nCreates a model for text generation.\n*/\n (modelId: GoogleVertexAnthropicMessagesModelId): LanguageModelV2;\n\n /**\nCreates a model for text generation.\n*/\n languageModel(modelId: GoogleVertexAnthropicMessagesModelId): LanguageModelV2;\n\n /**\nAnthropic-specific computer use tool.\n */\n tools: typeof anthropicTools;\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 /**\nUse a different URL prefix for API calls, e.g. to use proxy servers.\nThe default prefix is `https://api.anthropic.com/v1`.\n */\n baseURL?: string;\n\n /**\nCustom headers to include in the requests.\n */\n headers?: Resolvable<Record<string, string | undefined>>;\n\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\n/**\nCreate a Google Vertex Anthropic provider instance.\n */\nexport function createVertexAnthropic(\n options: GoogleVertexAnthropicProviderSettings = {},\n): GoogleVertexAnthropicProvider {\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 baseURL =\n withoutTrailingSlash(options.baseURL) ??\n `https://${location === 'global' ? '' : location + '-'}aiplatform.googleapis.com/v1/projects/${project}/locations/${location}/publishers/anthropic/models`;\n\n const createChatModel = (modelId: GoogleVertexAnthropicMessagesModelId) =>\n new AnthropicMessagesLanguageModel(modelId, {\n provider: 'vertex.anthropic.messages',\n baseURL,\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 });\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.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.messages = createChatModel;\n\n provider.textEmbeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'textEmbeddingModel' });\n };\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n provider.tools = anthropicTools;\n\n return provider;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,+BAAAA;AAAA,EAAA;AAAA;AAAA;;;ACAA,IAAAC,yBAAwB;;;ACAxB,iCAA8C;AAE9C,IAAI,eAAkC;AACtC,IAAI,cAAwC;AAE5C,SAAS,QAAQ,SAA4B;AAC3C,MAAI,CAAC,gBAAgB,YAAY,aAAa;AAC5C,mBAAe,IAAI,sCAAW;AAAA,MAC5B,QAAQ,CAAC,gDAAgD;AAAA,MACzD,GAAG;AAAA,IACL,CAAC;AACD,kBAAc;AAAA,EAChB;AACA,SAAO;AACT;AAEA,eAAsB,kBAAkB,SAA6B;AACnE,QAAM,OAAO,QAAQ,WAAW,CAAC,CAAC;AAClC,QAAM,SAAS,MAAM,KAAK,UAAU;AACpC,QAAM,QAAQ,MAAM,OAAO,eAAe;AAC1C,UAAO,+BAAO,UAAS;AACzB;;;ACrBA,sBAIO;AACP,4BAKO;AACP,sBAGO;AAmDA,SAAS,sBACd,UAAiD,CAAC,GACnB;AAnEjC;AAoEE,QAAM,eAAW,2CAAoB;AAAA,IACnC,cAAc,QAAQ;AAAA,IACtB,yBAAyB;AAAA,EAC3B,CAAC;AACD,QAAM,cAAU,2CAAoB;AAAA,IAClC,cAAc,QAAQ;AAAA,IACtB,yBAAyB;AAAA,EAC3B,CA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CAAQ,QAAQ,OAAO;AAAA,IACnC;AAAA,EACF,CAAC;AACH;AAKO,IAAM,kBAAkBA,uBAAsB;","names":["createVertexAnthropic","import_provider_utils","_a","baseURL","createVertexAnthropic"]}
|
package/dist/anthropic/index.mjs
CHANGED
@@ -44,7 +44,7 @@ function createVertexAnthropic(options = {}) {
|
|
44
44
|
settingValue: options.project,
|
45
45
|
environmentVariableName: "GOOGLE_VERTEX_PROJECT"
|
46
46
|
});
|
47
|
-
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : `https://${location}
|
47
|
+
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : `https://${location === "global" ? "" : location + "-"}aiplatform.googleapis.com/v1/projects/${project}/locations/${location}/publishers/anthropic/models`;
|
48
48
|
const createChatModel = (modelId) => {
|
49
49
|
var _a2;
|
50
50
|
return new AnthropicMessagesLanguageModel(modelId, {
|
@@ -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 { GoogleAuthOptions } from 'google-auth-library';\nimport { generateAuthToken } from '../google-vertex-auth-google-auth-library';\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 Authentication options provided by google-auth-library.\nComplete list of authentication options is documented in the\nGoogleAuthOptions interface:\nhttps://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts.\n */\n googleAuthOptions?: GoogleAuthOptions;\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.googleAuthOptions,\n )}`,\n ...(await resolve(options.headers)),\n }),\n });\n}\n\n/**\nDefault Google Vertex Anthropic provider instance.\n */\nexport const vertexAnthropic = createVertexAnthropic();\n","import { GoogleAuth, GoogleAuthOptions } from 'google-auth-library';\n\nlet authInstance: GoogleAuth | null = null;\nlet authOptions: GoogleAuthOptions | null = null;\n\nfunction getAuth(options: GoogleAuthOptions) {\n if (!authInstance || options !== authOptions) {\n authInstance = new GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n ...options,\n });\n authOptions = options;\n }\n return authInstance;\n}\n\nexport async function generateAuthToken(options?: GoogleAuthOptions) {\n const auth = getAuth(options || {});\n const client = await auth.getClient();\n const token = await client.getAccessToken();\n return token?.token || null;\n}\n\n// For testing purposes only\nexport function _resetAuthInstance() {\n authInstance = null;\n}\n","import {\n LanguageModelV2,\n NoSuchModelError,\n ProviderV2,\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';\nexport interface GoogleVertexAnthropicProvider extends ProviderV2 {\n /**\nCreates a model for text generation.\n*/\n (modelId: GoogleVertexAnthropicMessagesModelId): LanguageModelV2;\n\n /**\nCreates a model for text generation.\n*/\n languageModel(modelId: GoogleVertexAnthropicMessagesModelId): LanguageModelV2;\n\n /**\nAnthropic-specific computer use tool.\n */\n tools: typeof anthropicTools;\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 /**\nUse a different URL prefix for API calls, e.g. to use proxy servers.\nThe default prefix is `https://api.anthropic.com/v1`.\n */\n baseURL?: string;\n\n /**\nCustom headers to include in the requests.\n */\n headers?: Resolvable<Record<string, string | undefined>>;\n\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\n/**\nCreate a Google Vertex Anthropic provider instance.\n */\nexport function createVertexAnthropic(\n options: GoogleVertexAnthropicProviderSettings = {},\n): GoogleVertexAnthropicProvider {\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 const baseURL =\n withoutTrailingSlash(options.baseURL) ??\n `https://${location}
|
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 { GoogleAuthOptions } from 'google-auth-library';\nimport { generateAuthToken } from '../google-vertex-auth-google-auth-library';\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 Authentication options provided by google-auth-library.\nComplete list of authentication options is documented in the\nGoogleAuthOptions interface:\nhttps://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts.\n */\n googleAuthOptions?: GoogleAuthOptions;\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.googleAuthOptions,\n )}`,\n ...(await resolve(options.headers)),\n }),\n });\n}\n\n/**\nDefault Google Vertex Anthropic provider instance.\n */\nexport const vertexAnthropic = createVertexAnthropic();\n","import { GoogleAuth, GoogleAuthOptions } from 'google-auth-library';\n\nlet authInstance: GoogleAuth | null = null;\nlet authOptions: GoogleAuthOptions | null = null;\n\nfunction getAuth(options: GoogleAuthOptions) {\n if (!authInstance || options !== authOptions) {\n authInstance = new GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n ...options,\n });\n authOptions = options;\n }\n return authInstance;\n}\n\nexport async function generateAuthToken(options?: GoogleAuthOptions) {\n const auth = getAuth(options || {});\n const client = await auth.getClient();\n const token = await client.getAccessToken();\n return token?.token || null;\n}\n\n// For testing purposes only\nexport function _resetAuthInstance() {\n authInstance = null;\n}\n","import {\n LanguageModelV2,\n NoSuchModelError,\n ProviderV2,\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';\nexport interface GoogleVertexAnthropicProvider extends ProviderV2 {\n /**\nCreates a model for text generation.\n*/\n (modelId: GoogleVertexAnthropicMessagesModelId): LanguageModelV2;\n\n /**\nCreates a model for text generation.\n*/\n languageModel(modelId: GoogleVertexAnthropicMessagesModelId): LanguageModelV2;\n\n /**\nAnthropic-specific computer use tool.\n */\n tools: typeof anthropicTools;\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 /**\nUse a different URL prefix for API calls, e.g. to use proxy servers.\nThe default prefix is `https://api.anthropic.com/v1`.\n */\n baseURL?: string;\n\n /**\nCustom headers to include in the requests.\n */\n headers?: Resolvable<Record<string, string | undefined>>;\n\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\n/**\nCreate a Google Vertex Anthropic provider instance.\n */\nexport function createVertexAnthropic(\n options: GoogleVertexAnthropicProviderSettings = {},\n): GoogleVertexAnthropicProvider {\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 baseURL =\n withoutTrailingSlash(options.baseURL) ??\n `https://${location === 'global' ? '' : location + '-'}aiplatform.googleapis.com/v1/projects/${project}/locations/${location}/publishers/anthropic/models`;\n\n const createChatModel = (modelId: GoogleVertexAnthropicMessagesModelId) =>\n new AnthropicMessagesLanguageModel(modelId, {\n provider: 'vertex.anthropic.messages',\n baseURL,\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 });\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.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.messages = createChatModel;\n\n provider.textEmbeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'textEmbeddingModel' });\n };\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n provider.tools = anthropicTools;\n\n return provider;\n}\n"],"mappings":";AAAA,SAAS,eAAe;;;ACAxB,SAAS,kBAAqC;AAE9C,IAAI,eAAkC;AACtC,IAAI,cAAwC;AAE5C,SAAS,QAAQ,SAA4B;AAC3C,MAAI,CAAC,gBAAgB,YAAY,aAAa;AAC5C,mBAAe,IAAI,WAAW;AAAA,MAC5B,QAAQ,CAAC,gDAAgD;AAAA,MACzD,GAAG;AAAA,IACL,CAAC;AACD,kBAAc;AAAA,EAChB;AACA,SAAO;AACT;AAEA,eAAsB,kBAAkB,SAA6B;AACnE,QAAM,OAAO,QAAQ,WAAW,CAAC,CAAC;AAClC,QAAM,SAAS,MAAM,KAAK,UAAU;AACpC,QAAM,QAAQ,MAAM,OAAO,eAAe;AAC1C,UAAO,+BAAO,UAAS;AACzB;;;ACrBA;AAAA,EAEE;AAAA,OAEK;AACP;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAmDA,SAAS,sBACd,UAAiD,CAAC,GACnB;AAnEjC;AAoEE,QAAM,WAAW,oBAAoB;AAAA,IACnC,cAAc,QAAQ;AAAA,IACtB,yBAAyB;AAAA,EAC3B,CAAC;AACD,QAAM,UAAU,oBAAoB;AAAA,IAClC,cAAc,QAAQ;AAAA,IACtB,yBAAyB;AAAA,EAC3B,CAAC;AAED,QAAM,WACJ,0BAAqB,QAAQ,OAAO,MAApC,YACA,WAAW,aAAa,WAAW,KAAK,WAAW,GAAG,yCAAyC,OAAO,cAAc,QAAQ;AAE9H,QAAM,kBAAkB,CAAC,YAA+C;AAjF1E,QAAAA;AAkFI,eAAI,+BAA+B,SAAS;AAAA,MAC1C,UAAU;AAAA,MACV;AAAA,MACA,UAASA,MAAA,QAAQ,YAAR,OAAAA,MAAmB,CAAC;AAAA,MAC7B,OAAO,QAAQ;AAAA,MAEf,iBAAiB,CAACC,UAAS,gBACzB,GAAGA,QAAO,IAAI,OAAO,IACnB,cAAc,qBAAqB,YACrC;AAAA,MACF,sBAAsB,UAAQ;AAE5B,cAAM,EAAE,OAAO,GAAG,KAAK,IAAI;AAC3B,eAAO;AAAA,UACL,GAAG;AAAA,UACH,mBAAmB;AAAA,QACrB;AAAA,MACF;AAAA;AAAA,MAEA,eAAe,OAAO,CAAC;AAAA,IACzB,CAAC;AAAA;AAEH,QAAM,WAAW,SAAU,SAA+C;AACxE,QAAI,YAAY;AACd,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,WAAO,gBAAgB,OAAO;AAAA,EAChC;AAEA,WAAS,gBAAgB;AACzB,WAAS,OAAO;AAChB,WAAS,WAAW;AAEpB,WAAS,qBAAqB,CAAC,YAAoB;AACjD,UAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,qBAAqB,CAAC;AAAA,EACzE;AACA,WAAS,aAAa,CAAC,YAAoB;AACzC,UAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,aAAa,CAAC;AAAA,EACjE;AAEA,WAAS,QAAQ;AAEjB,SAAO;AACT;;;AF1GO,SAASC,uBACd,UAAiD,CAAC,GACnB;AAC/B,SAAO,sBAA8B;AAAA,IACnC,GAAG;AAAA,IACH,SAAS,aAAa;AAAA,MACpB,eAAe,UAAU,MAAM;AAAA,QAC7B,QAAQ;AAAA,MACV,CAAC;AAAA,MACD,GAAI,MAAM,QAAQ,QAAQ,OAAO;AAAA,IACnC;AAAA,EACF,CAAC;AACH;AAKO,IAAM,kBAAkBA,uBAAsB;","names":["_a","baseURL","createVertexAnthropic"]}
|
package/dist/edge/index.d.mts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { ProviderV2, LanguageModelV2, ImageModelV2 } from '@ai-sdk/provider';
|
2
2
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
3
3
|
|
4
|
-
type GoogleVertexImageModelId = 'imagen-3.0-generate-001' | 'imagen-3.0-generate-002' | 'imagen-3.0-fast-generate-001' | (string & {});
|
4
|
+
type GoogleVertexImageModelId = 'imagen-3.0-generate-001' | 'imagen-3.0-generate-002' | 'imagen-3.0-fast-generate-001' | 'imagen-4.0-generate-preview-06-06' | 'imagen-4.0-fast-generate-preview-06-06' | 'imagen-4.0-ultra-generate-preview-06-06' | (string & {});
|
5
5
|
|
6
6
|
type GoogleVertexModelId = 'gemini-2.0-flash-001' | 'gemini-1.5-flash' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-pro' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-1.0-pro-001' | 'gemini-1.0-pro-vision-001' | 'gemini-1.0-pro' | 'gemini-1.0-pro-001' | 'gemini-1.0-pro-002' | 'gemini-2.0-flash-lite-preview-02-05' | 'gemini-2.0-pro-exp-02-05' | 'gemini-2.0-flash-exp' | (string & {});
|
7
7
|
|
package/dist/edge/index.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { ProviderV2, LanguageModelV2, ImageModelV2 } from '@ai-sdk/provider';
|
2
2
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
3
3
|
|
4
|
-
type GoogleVertexImageModelId = 'imagen-3.0-generate-001' | 'imagen-3.0-generate-002' | 'imagen-3.0-fast-generate-001' | (string & {});
|
4
|
+
type GoogleVertexImageModelId = 'imagen-3.0-generate-001' | 'imagen-3.0-generate-002' | 'imagen-3.0-fast-generate-001' | 'imagen-4.0-generate-preview-06-06' | 'imagen-4.0-fast-generate-preview-06-06' | 'imagen-4.0-ultra-generate-preview-06-06' | (string & {});
|
5
5
|
|
6
6
|
type GoogleVertexModelId = 'gemini-2.0-flash-001' | 'gemini-1.5-flash' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-pro' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-1.0-pro-001' | 'gemini-1.0-pro-vision-001' | 'gemini-1.0-pro' | 'gemini-1.0-pro-001' | 'gemini-1.0-pro-002' | 'gemini-2.0-flash-lite-preview-02-05' | 'gemini-2.0-pro-exp-02-05' | 'gemini-2.0-flash-exp' | (string & {});
|
7
7
|
|
package/dist/edge/index.js
CHANGED
@@ -35,16 +35,16 @@ var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
35
35
|
// src/google-vertex-embedding-model.ts
|
36
36
|
var import_provider = require("@ai-sdk/provider");
|
37
37
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
38
|
-
var
|
38
|
+
var import_v43 = require("zod/v4");
|
39
39
|
|
40
40
|
// src/google-vertex-error.ts
|
41
41
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
42
|
-
var
|
43
|
-
var googleVertexErrorDataSchema =
|
44
|
-
error:
|
45
|
-
code:
|
46
|
-
message:
|
47
|
-
status:
|
42
|
+
var import_v4 = require("zod/v4");
|
43
|
+
var googleVertexErrorDataSchema = import_v4.z.object({
|
44
|
+
error: import_v4.z.object({
|
45
|
+
code: import_v4.z.number().nullable(),
|
46
|
+
message: import_v4.z.string(),
|
47
|
+
status: import_v4.z.string()
|
48
48
|
})
|
49
49
|
});
|
50
50
|
var googleVertexFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)(
|
@@ -55,13 +55,13 @@ var googleVertexFailedResponseHandler = (0, import_provider_utils.createJsonErro
|
|
55
55
|
);
|
56
56
|
|
57
57
|
// src/google-vertex-embedding-options.ts
|
58
|
-
var
|
59
|
-
var googleVertexEmbeddingProviderOptions =
|
58
|
+
var import_v42 = require("zod/v4");
|
59
|
+
var googleVertexEmbeddingProviderOptions = import_v42.z.object({
|
60
60
|
/**
|
61
61
|
* Optional. Optional reduced dimension for the output embedding.
|
62
62
|
* If set, excessive values in the output embedding are truncated from the end.
|
63
63
|
*/
|
64
|
-
outputDimensionality:
|
64
|
+
outputDimensionality: import_v42.z.number().optional()
|
65
65
|
});
|
66
66
|
|
67
67
|
// src/google-vertex-embedding-model.ts
|
@@ -135,13 +135,13 @@ var GoogleVertexEmbeddingModel = class {
|
|
135
135
|
};
|
136
136
|
}
|
137
137
|
};
|
138
|
-
var googleVertexTextEmbeddingResponseSchema =
|
139
|
-
predictions:
|
140
|
-
|
141
|
-
embeddings:
|
142
|
-
values:
|
143
|
-
statistics:
|
144
|
-
token_count:
|
138
|
+
var googleVertexTextEmbeddingResponseSchema = import_v43.z.object({
|
139
|
+
predictions: import_v43.z.array(
|
140
|
+
import_v43.z.object({
|
141
|
+
embeddings: import_v43.z.object({
|
142
|
+
values: import_v43.z.array(import_v43.z.number()),
|
143
|
+
statistics: import_v43.z.object({
|
144
|
+
token_count: import_v43.z.number()
|
145
145
|
})
|
146
146
|
})
|
147
147
|
})
|
@@ -150,7 +150,7 @@ var googleVertexTextEmbeddingResponseSchema = import_zod3.z.object({
|
|
150
150
|
|
151
151
|
// src/google-vertex-image-model.ts
|
152
152
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
153
|
-
var
|
153
|
+
var import_v44 = require("zod/v4");
|
154
154
|
var GoogleVertexImageModel = class {
|
155
155
|
constructor(modelId, config) {
|
156
156
|
this.modelId = modelId;
|
@@ -233,26 +233,26 @@ var GoogleVertexImageModel = class {
|
|
233
233
|
};
|
234
234
|
}
|
235
235
|
};
|
236
|
-
var vertexImageResponseSchema =
|
237
|
-
predictions:
|
238
|
-
|
239
|
-
bytesBase64Encoded:
|
240
|
-
mimeType:
|
241
|
-
prompt:
|
236
|
+
var vertexImageResponseSchema = import_v44.z.object({
|
237
|
+
predictions: import_v44.z.array(
|
238
|
+
import_v44.z.object({
|
239
|
+
bytesBase64Encoded: import_v44.z.string(),
|
240
|
+
mimeType: import_v44.z.string(),
|
241
|
+
prompt: import_v44.z.string()
|
242
242
|
})
|
243
243
|
).nullish()
|
244
244
|
});
|
245
|
-
var vertexImageProviderOptionsSchema =
|
246
|
-
negativePrompt:
|
247
|
-
personGeneration:
|
248
|
-
safetySetting:
|
245
|
+
var vertexImageProviderOptionsSchema = import_v44.z.object({
|
246
|
+
negativePrompt: import_v44.z.string().nullish(),
|
247
|
+
personGeneration: import_v44.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
248
|
+
safetySetting: import_v44.z.enum([
|
249
249
|
"block_low_and_above",
|
250
250
|
"block_medium_and_above",
|
251
251
|
"block_only_high",
|
252
252
|
"block_none"
|
253
253
|
]).nullish(),
|
254
|
-
addWatermark:
|
255
|
-
storageUri:
|
254
|
+
addWatermark: import_v44.z.boolean().nullish(),
|
255
|
+
storageUri: import_v44.z.string().nullish()
|
256
256
|
});
|
257
257
|
|
258
258
|
// src/google-vertex-provider.ts
|
@@ -273,7 +273,8 @@ function createVertex(options = {}) {
|
|
273
273
|
var _a;
|
274
274
|
const region = loadVertexLocation();
|
275
275
|
const project = loadVertexProject();
|
276
|
-
|
276
|
+
const baseHost = `${region === "global" ? "" : region + "-"}aiplatform.googleapis.com`;
|
277
|
+
return (_a = (0, import_provider_utils4.withoutTrailingSlash)(options.baseURL)) != null ? _a : `https://${baseHost}/v1/projects/${project}/locations/${region}/publishers/google`;
|
277
278
|
};
|
278
279
|
const createConfig = (name) => {
|
279
280
|
var _a;
|