@ai-sdk/google-vertex 5.0.99 → 5.0.100
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 +15 -0
- package/dist/anthropic/edge/index.d.ts.map +1 -1
- package/dist/anthropic/edge/index.js +10 -4
- package/dist/anthropic/edge/index.js.map +1 -1
- package/dist/anthropic/index.d.ts.map +1 -1
- package/dist/anthropic/index.js +9 -3
- package/dist/anthropic/index.js.map +1 -1
- package/dist/edge/index.d.ts.map +1 -1
- package/dist/edge/index.js +32 -12
- package/dist/edge/index.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -12
- package/dist/index.js.map +1 -1
- package/dist/maas/edge/index.d.ts.map +1 -1
- package/dist/maas/edge/index.js +15 -7
- package/dist/maas/edge/index.js.map +1 -1
- package/dist/maas/index.d.ts.map +1 -1
- package/dist/maas/index.js +14 -6
- package/dist/maas/index.js.map +1 -1
- package/dist/xai/edge/index.js +1 -1
- package/package.json +6 -6
- package/src/anthropic/google-vertex-anthropic-provider.ts +14 -4
- package/src/gemini-transcription/google-vertex-gemini-transcription-model.ts +5 -1
- package/src/google-vertex-provider-base.ts +28 -15
- package/src/google-vertex-transcription-model-options.ts +2 -1
- package/src/google-vertex-transcription-model.ts +13 -1
- package/src/maas/google-vertex-maas-provider.ts +18 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @ai-sdk/google-vertex
|
|
2
2
|
|
|
3
|
+
## 5.0.100
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8c65988: feat(ai): add telemetry to speech generation and transcription, including
|
|
8
|
+
provider usage propagation and experimental streaming lifecycle callbacks
|
|
9
|
+
- 527a163: fix: validate hostname parts using `isValidHostnamePart`
|
|
10
|
+
- Updated dependencies [8c65988]
|
|
11
|
+
- Updated dependencies [527a163]
|
|
12
|
+
- @ai-sdk/provider@4.0.21
|
|
13
|
+
- @ai-sdk/provider-utils@5.0.53
|
|
14
|
+
- @ai-sdk/google@4.0.87
|
|
15
|
+
- @ai-sdk/anthropic@4.0.70
|
|
16
|
+
- @ai-sdk/openai-compatible@3.0.61
|
|
17
|
+
|
|
3
18
|
## 5.0.99
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["GoogleVertexAnthropicProviderSettings","GoogleVertexAnthropicProviderSettingsOriginal"],"sources":["../../../src/edge/google-vertex-auth-edge.ts","../../../src/anthropic/google-vertex-anthropic-options.ts","../../../src/anthropic/google-vertex-anthropic-provider.ts","../../../src/anthropic/edge/google-vertex-anthropic-provider-edge.ts"],"mappings":";;;;UAQiB;;;;;EAKf;;;;;EAMA;;;;;EAMA;;;;KCxBU;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["GoogleVertexAnthropicProviderSettings","GoogleVertexAnthropicProviderSettingsOriginal"],"sources":["../../../src/edge/google-vertex-auth-edge.ts","../../../src/anthropic/google-vertex-anthropic-options.ts","../../../src/anthropic/google-vertex-anthropic-provider.ts","../../../src/anthropic/edge/google-vertex-anthropic-provider-edge.ts"],"mappings":";;;;UAQiB;;;;;EAKf;;;;;EAMA;;;;;EAMA;;;;KCxBU;;;KCkBP,6BAA6B,YACzB;;;;;cAiBI,4BAA4B;UAkFxB,sCAAsC;;;;GAIpD,SAAS,+BAA+B;;;;EAKzC,cAAc,SAAS,+BAA+B;;;;;;;;;EAUtD,cAAc;;;;EAKd,mBAAmB;;UAGJA;;;;EAIf;;;;EAKA;;;;;EAMA;;;;EAKA,UAAU,WAAW;;;;;EAMrB,QAAQ;;;;UChKO,8CAA8CC;;;;;;EAM7D,oBAAoB;;;;;EAKpB,0BAA0B;;wBAGZ,4BACd,UAAS,wCACR;;;;qBAgBU,uBAAqB"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { getRuntimeEnvironmentUserAgent, loadOptionalSetting, loadSetting, resolve, withUserAgentSuffix, withoutTrailingSlash } from "@ai-sdk/provider-utils";
|
|
2
|
-
import { NoSuchModelError } from "@ai-sdk/provider";
|
|
1
|
+
import { getRuntimeEnvironmentUserAgent, isValidHostnamePart, loadOptionalSetting, loadSetting, resolve, withUserAgentSuffix, withoutTrailingSlash } from "@ai-sdk/provider-utils";
|
|
2
|
+
import { InvalidArgumentError, NoSuchModelError } from "@ai-sdk/provider";
|
|
3
3
|
import { AnthropicLanguageModel, anthropicTools } from "@ai-sdk/anthropic/internal";
|
|
4
4
|
//#region src/version.ts
|
|
5
|
-
const VERSION = "5.0.
|
|
5
|
+
const VERSION = "5.0.100";
|
|
6
6
|
//#endregion
|
|
7
7
|
//#region src/edge/google-vertex-auth-edge.ts
|
|
8
8
|
const loadCredentials = async () => {
|
|
@@ -165,10 +165,16 @@ const googleVertexAnthropicTools = {
|
|
|
165
165
|
*/
|
|
166
166
|
function createGoogleVertexAnthropic$1(options = {}) {
|
|
167
167
|
const getBaseURL = () => {
|
|
168
|
+
const baseURL = withoutTrailingSlash(options.baseURL);
|
|
169
|
+
if (baseURL != null) return baseURL;
|
|
168
170
|
const location = loadOptionalSetting({
|
|
169
171
|
settingValue: options.location,
|
|
170
172
|
environmentVariableName: "GOOGLE_VERTEX_LOCATION"
|
|
171
173
|
});
|
|
174
|
+
if (location != null && !isValidHostnamePart(location)) throw new InvalidArgumentError({
|
|
175
|
+
argument: "location",
|
|
176
|
+
message: "Invalid Google Vertex location. Expected a single DNS label (letters, digits, and hyphens). Use `baseURL` for custom endpoints."
|
|
177
|
+
});
|
|
172
178
|
const project = loadOptionalSetting({
|
|
173
179
|
settingValue: options.project,
|
|
174
180
|
environmentVariableName: "GOOGLE_VERTEX_PROJECT"
|
|
@@ -178,7 +184,7 @@ function createGoogleVertexAnthropic$1(options = {}) {
|
|
|
178
184
|
else if (location === "eu" || location === "us") return `aiplatform.${location}.rep.googleapis.com`;
|
|
179
185
|
else return `${location}-aiplatform.googleapis.com`;
|
|
180
186
|
};
|
|
181
|
-
return
|
|
187
|
+
return `https://${getHost()}/v1/projects/${project}/locations/${location}/publishers/anthropic/models`;
|
|
182
188
|
};
|
|
183
189
|
const createChatModel = (modelId) => new AnthropicLanguageModel(modelId, {
|
|
184
190
|
provider: "googleVertex.anthropic.messages",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["createGoogleVertexAnthropic","generateAuthToken","defaultGenerateAuthToken","createVertexAnthropicOriginal"],"sources":["../../../src/version.ts","../../../src/edge/google-vertex-auth-edge.ts","../../../src/anthropic/google-vertex-anthropic-provider.ts","../../../src/anthropic/edge/google-vertex-anthropic-provider-edge.ts"],"sourcesContent":["// 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 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 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}\n","import {\n NoSuchModelError,\n type LanguageModelV4,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n loadOptionalSetting,\n withoutTrailingSlash,\n type FetchFunction,\n type Resolvable,\n} from '@ai-sdk/provider-utils';\nimport {\n anthropicTools,\n AnthropicLanguageModel,\n} from '@ai-sdk/anthropic/internal';\nimport type { GoogleVertexAnthropicModelId } from './google-vertex-anthropic-options';\n\ntype GoogleVertexAnthropicTools = Pick<\n typeof anthropicTools,\n | 'bash_20241022'\n | 'bash_20250124'\n | 'textEditor_20241022'\n | 'textEditor_20250124'\n | 'textEditor_20250429'\n | 'textEditor_20250728'\n | 'computer_20241022'\n | 'webSearch_20250305'\n | 'toolSearchRegex_20251119'\n | 'toolSearchBm25_20251119'\n>;\n\n/**\n * Tools supported by Google Vertex Anthropic.\n * This is a subset of the full Anthropic tools - only these are recognized by the Vertex API.\n */\nexport const googleVertexAnthropicTools: GoogleVertexAnthropicTools = {\n /**\n * The bash tool enables Claude to execute shell commands in a persistent bash session,\n * allowing system operations, script execution, and command-line automation.\n *\n * Image results are supported.\n */\n bash_20241022: anthropicTools.bash_20241022,\n\n /**\n * The bash tool enables Claude to execute shell commands in a persistent bash session,\n * allowing system operations, script execution, and command-line automation.\n *\n * Image results are supported.\n */\n bash_20250124: anthropicTools.bash_20250124,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files,\n * helping you debug, fix, and improve your code or other text documents.\n *\n * Supported models: Claude Sonnet 3.5\n */\n textEditor_20241022: anthropicTools.textEditor_20241022,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files,\n * helping you debug, fix, and improve your code or other text documents.\n *\n * Supported models: Claude Sonnet 3.7\n */\n textEditor_20250124: anthropicTools.textEditor_20250124,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files.\n * Note: This version does not support the \"undo_edit\" command.\n * @deprecated Use textEditor_20250728 instead\n */\n textEditor_20250429: anthropicTools.textEditor_20250429,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files.\n * Note: This version does not support the \"undo_edit\" command and adds optional max_characters parameter.\n * Supported models: Claude Sonnet 4, Opus 4, and Opus 4.1\n */\n textEditor_20250728: anthropicTools.textEditor_20250728,\n\n /**\n * Claude can interact with computer environments through the computer use tool, which\n * provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.\n *\n * Image results are supported.\n */\n computer_20241022: anthropicTools.computer_20241022,\n\n /**\n * Creates a web search tool that gives Claude direct access to real-time web content.\n */\n webSearch_20250305: anthropicTools.webSearch_20250305,\n\n /**\n * Creates a tool search tool that uses regex patterns to find tools.\n *\n * The tool search tool enables Claude to work with hundreds or thousands of tools\n * by dynamically discovering and loading them on-demand.\n *\n * Use `providerOptions: { anthropic: { deferLoading: true } }` on other tools\n * to mark them for deferred loading.\n */\n toolSearchRegex_20251119: anthropicTools.toolSearchRegex_20251119,\n\n /**\n * Creates a tool search tool that uses BM25 (natural language) to find tools.\n *\n * The tool search tool enables Claude to work with hundreds or thousands of tools\n * by dynamically discovering and loading them on-demand.\n *\n * Use `providerOptions: { anthropic: { deferLoading: true } }` on other tools\n * to mark them for deferred loading.\n */\n toolSearchBm25_20251119: anthropicTools.toolSearchBm25_20251119,\n};\nexport interface GoogleVertexAnthropicProvider extends ProviderV4 {\n /**\n * Creates a model for text generation.\n */\n (modelId: GoogleVertexAnthropicModelId): LanguageModelV4;\n\n /**\n * Creates a model for text generation.\n */\n languageModel(modelId: GoogleVertexAnthropicModelId): LanguageModelV4;\n\n /**\n * Anthropic tools supported by Google Vertex.\n * Note: Only a subset of Anthropic tools are available on Vertex.\n * Supported tools: bash_20241022, bash_20250124, textEditor_20241022,\n * textEditor_20250124, textEditor_20250429, textEditor_20250728,\n * computer_20241022, webSearch_20250305, toolSearchRegex_20251119,\n * toolSearchBm25_20251119\n */\n tools: typeof googleVertexAnthropicTools;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nexport interface GoogleVertexAnthropicProviderSettings {\n /**\n * Google Cloud project ID. Defaults to the value of the `GOOGLE_VERTEX_PROJECT` environment variable.\n */\n project?: string;\n\n /**\n * Google Cloud region. Defaults to the value of the `GOOGLE_VERTEX_LOCATION` environment variable.\n */\n location?: string;\n\n /**\n * Use a different URL prefix for API calls, e.g. to use proxy servers.\n * The default prefix is `https://api.anthropic.com/v1`.\n */\n baseURL?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Resolvable<Record<string, string | undefined>>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\n/**\n * Create a Google Vertex Anthropic provider instance.\n */\nexport function createGoogleVertexAnthropic(\n options: GoogleVertexAnthropicProviderSettings = {},\n): GoogleVertexAnthropicProvider {\n const getBaseURL = () => {\n const location = loadOptionalSetting({\n settingValue: options.location,\n environmentVariableName: 'GOOGLE_VERTEX_LOCATION',\n });\n const project = loadOptionalSetting({\n settingValue: options.project,\n environmentVariableName: 'GOOGLE_VERTEX_PROJECT',\n });\n\n const getHost = () => {\n if (location === 'global') {\n return 'aiplatform.googleapis.com';\n } else if (location === 'eu' || location === 'us') {\n return `aiplatform.${location}.rep.googleapis.com`;\n } else {\n return `${location}-aiplatform.googleapis.com`;\n }\n };\n\n return (\n withoutTrailingSlash(options.baseURL) ??\n `https://${getHost()}/v1/projects/${project}/locations/${location}/publishers/anthropic/models`\n );\n };\n\n const createChatModel = (modelId: GoogleVertexAnthropicModelId) =>\n new AnthropicLanguageModel(modelId, {\n provider: 'googleVertex.anthropic.messages',\n baseURL: getBaseURL(),\n headers: options.headers ?? {},\n fetch: options.fetch,\n\n buildRequestUrl: (baseURL, isStreaming) =>\n `${baseURL}/${modelId}:${\n isStreaming ? 'streamRawPredict' : 'rawPredict'\n }`,\n transformRequestBody: args => {\n // Remove model from args and add anthropic version\n const { model: _model, ...rest } = args;\n return {\n ...rest,\n anthropic_version: 'vertex-2023-10-16',\n };\n },\n // Google Vertex Anthropic doesn't support URL sources, force download and base64 conversion\n supportedUrls: () => ({}),\n // force the use of JSON tool fallback for structured outputs since beta header isn't supported\n supportsNativeStructuredOutput: false,\n // Vertex Anthropic doesn't support strict mode on tool definitions.\n supportsStrictTools: false,\n });\n\n const provider = function (modelId: GoogleVertexAnthropicModelId) {\n if (new.target) {\n throw new Error(\n 'The Anthropic model function cannot be called with the new keyword.',\n );\n }\n\n return createChatModel(modelId);\n };\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.messages = createChatModel;\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n provider.tools = googleVertexAnthropicTools;\n\n return provider;\n}\n","import { resolve } from '@ai-sdk/provider-utils';\nimport {\n generateAuthToken as defaultGenerateAuthToken,\n type GoogleCredentials,\n} from '../../edge/google-vertex-auth-edge';\nimport {\n createGoogleVertexAnthropic as createVertexAnthropicOriginal,\n type GoogleVertexAnthropicProvider,\n type GoogleVertexAnthropicProviderSettings as GoogleVertexAnthropicProviderSettingsOriginal,\n} from '../google-vertex-anthropic-provider';\nexport type { GoogleVertexAnthropicProvider };\n\nexport interface GoogleVertexAnthropicProviderSettings extends GoogleVertexAnthropicProviderSettingsOriginal {\n /**\n * Optional. The 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 * Optional. Override the Bearer token generator. Defaults to OAuth exchange\n * with `googleCredentials`.\n */\n generateAuthToken?: () => Promise<string>;\n}\n\nexport function createGoogleVertexAnthropic(\n options: GoogleVertexAnthropicProviderSettings = {},\n): GoogleVertexAnthropicProvider {\n const generateAuthToken =\n options.generateAuthToken ??\n (() => defaultGenerateAuthToken(options.googleCredentials));\n return createVertexAnthropicOriginal({\n ...options,\n headers: async () => ({\n Authorization: `Bearer ${await generateAuthToken()}`,\n ...(await resolve(options.headers)),\n }),\n });\n}\n\n/**\n * Default Google Vertex AI Anthropic provider instance.\n */\nexport const googleVertexAnthropic = createGoogleVertexAnthropic();\n"],"mappings":";;;;AAEA,MAAa,UAAA;;;AC0Bb,MAAM,kBAAkB,YAAwC;CAC9D,IAAI;EACF,OAAO;GACL,aAAa,YAAY;IACvB,cAAc,KAAA;IACd,aAAa;IACb,yBAAyB;IACzB,aAAa;GACf,CAAC;GACD,YAAY,YAAY;IACtB,cAAc,KAAA;IACd,aAAa;IACb,yBAAyB;IACzB,aAAa;GACf,CAAC;GACD,cAAc,oBAAoB;IAChC,cAAc,KAAA;IACd,yBAAyB;GAC3B,CAAC;EACH;CACF,SAAS,OAAY;EACnB,MAAM,IAAI,MAAM,sCAAsC,MAAM,SAAS;CACvE;AACF;AAGA,MAAM,aAAa,QAAgB;CACjC,OAAO,KAAK,GAAG,CAAC,CAAC,QAAQ,OAAO,GAAG,CAAC,CAAC,QAAQ,OAAO,GAAG,CAAC,CAA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kBAAkB,SAAS,gBACzB,GAAG,QAAQ,GAAG,QAAQ,GACpB,cAAc,qBAAqB;EAEvC,uBAAsB,SAAQ;GAE5B,MAAM,EAAE,OAAO,QAAQ,GAAG,SAAS;GACnC,OAAO;IACL,GAAG;IACH,mBAAmB;GACrB;EACF;EAEA,sBAAsB,CAAC;EAEvB,gCAAgC;EAEhC,qBAAqB;CACvB,CAAC;CAEH,MAAM,WAAW,SAAU,SAAuC;EAChE,IAAI,YACF,MAAM,IAAI,MACR,qEACF;EAGF,OAAO,gBAAgB,OAAO;CAChC;CAEA,SAAS,uBAAuB;CAChC,SAAS,gBAAgB;CACzB,SAAS,OAAO;CAChB,SAAS,WAAW;CAEpB,SAAS,kBAAkB,YAAoB;EAC7C,MAAM,IAAI,iBAAiB;GAAE;GAAS,WAAW;EAAiB,CAAC;CACrE;CACA,SAAS,qBAAqB,SAAS;CACvC,SAAS,cAAc,YAAoB;EACzC,MAAM,IAAI,iBAAiB;GAAE;GAAS,WAAW;EAAa,CAAC;CACjE;CAEA,SAAS,QAAQ;CAEjB,OAAO;AACT;;;ACxOA,SAAgB,4BACd,UAAiD,CAAC,GACnB;CAC/B,MAAMC,sBACJ,QAAQ,4BACDC,kBAAyB,QAAQ,iBAAiB;CAC3D,OAAOC,8BAA8B;EACnC,GAAG;EACH,SAAS,aAAa;GACpB,eAAe,UAAU,MAAMF,oBAAkB;GACjD,GAAI,MAAM,QAAQ,QAAQ,OAAO;EACnC;CACF,CAAC;AACH;;;;AAKA,MAAa,wBAAwB,4BAA4B"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["createGoogleVertexAnthropic","generateAuthToken","defaultGenerateAuthToken","createVertexAnthropicOriginal"],"sources":["../../../src/version.ts","../../../src/edge/google-vertex-auth-edge.ts","../../../src/anthropic/google-vertex-anthropic-provider.ts","../../../src/anthropic/edge/google-vertex-anthropic-provider-edge.ts"],"sourcesContent":["// 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 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 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}\n","import {\n InvalidArgumentError,\n NoSuchModelError,\n type LanguageModelV4,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n isValidHostnamePart,\n loadOptionalSetting,\n withoutTrailingSlash,\n type FetchFunction,\n type Resolvable,\n} from '@ai-sdk/provider-utils';\nimport {\n anthropicTools,\n AnthropicLanguageModel,\n} from '@ai-sdk/anthropic/internal';\nimport type { GoogleVertexAnthropicModelId } from './google-vertex-anthropic-options';\n\ntype GoogleVertexAnthropicTools = Pick<\n typeof anthropicTools,\n | 'bash_20241022'\n | 'bash_20250124'\n | 'textEditor_20241022'\n | 'textEditor_20250124'\n | 'textEditor_20250429'\n | 'textEditor_20250728'\n | 'computer_20241022'\n | 'webSearch_20250305'\n | 'toolSearchRegex_20251119'\n | 'toolSearchBm25_20251119'\n>;\n\n/**\n * Tools supported by Google Vertex Anthropic.\n * This is a subset of the full Anthropic tools - only these are recognized by the Vertex API.\n */\nexport const googleVertexAnthropicTools: GoogleVertexAnthropicTools = {\n /**\n * The bash tool enables Claude to execute shell commands in a persistent bash session,\n * allowing system operations, script execution, and command-line automation.\n *\n * Image results are supported.\n */\n bash_20241022: anthropicTools.bash_20241022,\n\n /**\n * The bash tool enables Claude to execute shell commands in a persistent bash session,\n * allowing system operations, script execution, and command-line automation.\n *\n * Image results are supported.\n */\n bash_20250124: anthropicTools.bash_20250124,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files,\n * helping you debug, fix, and improve your code or other text documents.\n *\n * Supported models: Claude Sonnet 3.5\n */\n textEditor_20241022: anthropicTools.textEditor_20241022,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files,\n * helping you debug, fix, and improve your code or other text documents.\n *\n * Supported models: Claude Sonnet 3.7\n */\n textEditor_20250124: anthropicTools.textEditor_20250124,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files.\n * Note: This version does not support the \"undo_edit\" command.\n * @deprecated Use textEditor_20250728 instead\n */\n textEditor_20250429: anthropicTools.textEditor_20250429,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files.\n * Note: This version does not support the \"undo_edit\" command and adds optional max_characters parameter.\n * Supported models: Claude Sonnet 4, Opus 4, and Opus 4.1\n */\n textEditor_20250728: anthropicTools.textEditor_20250728,\n\n /**\n * Claude can interact with computer environments through the computer use tool, which\n * provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.\n *\n * Image results are supported.\n */\n computer_20241022: anthropicTools.computer_20241022,\n\n /**\n * Creates a web search tool that gives Claude direct access to real-time web content.\n */\n webSearch_20250305: anthropicTools.webSearch_20250305,\n\n /**\n * Creates a tool search tool that uses regex patterns to find tools.\n *\n * The tool search tool enables Claude to work with hundreds or thousands of tools\n * by dynamically discovering and loading them on-demand.\n *\n * Use `providerOptions: { anthropic: { deferLoading: true } }` on other tools\n * to mark them for deferred loading.\n */\n toolSearchRegex_20251119: anthropicTools.toolSearchRegex_20251119,\n\n /**\n * Creates a tool search tool that uses BM25 (natural language) to find tools.\n *\n * The tool search tool enables Claude to work with hundreds or thousands of tools\n * by dynamically discovering and loading them on-demand.\n *\n * Use `providerOptions: { anthropic: { deferLoading: true } }` on other tools\n * to mark them for deferred loading.\n */\n toolSearchBm25_20251119: anthropicTools.toolSearchBm25_20251119,\n};\nexport interface GoogleVertexAnthropicProvider extends ProviderV4 {\n /**\n * Creates a model for text generation.\n */\n (modelId: GoogleVertexAnthropicModelId): LanguageModelV4;\n\n /**\n * Creates a model for text generation.\n */\n languageModel(modelId: GoogleVertexAnthropicModelId): LanguageModelV4;\n\n /**\n * Anthropic tools supported by Google Vertex.\n * Note: Only a subset of Anthropic tools are available on Vertex.\n * Supported tools: bash_20241022, bash_20250124, textEditor_20241022,\n * textEditor_20250124, textEditor_20250429, textEditor_20250728,\n * computer_20241022, webSearch_20250305, toolSearchRegex_20251119,\n * toolSearchBm25_20251119\n */\n tools: typeof googleVertexAnthropicTools;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nexport interface GoogleVertexAnthropicProviderSettings {\n /**\n * Google Cloud project ID. Defaults to the value of the `GOOGLE_VERTEX_PROJECT` environment variable.\n */\n project?: string;\n\n /**\n * Google Cloud region. Defaults to the value of the `GOOGLE_VERTEX_LOCATION` environment variable.\n */\n location?: string;\n\n /**\n * Use a different URL prefix for API calls, e.g. to use proxy servers.\n * The default prefix is `https://api.anthropic.com/v1`.\n */\n baseURL?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Resolvable<Record<string, string | undefined>>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\n/**\n * Create a Google Vertex Anthropic provider instance.\n */\nexport function createGoogleVertexAnthropic(\n options: GoogleVertexAnthropicProviderSettings = {},\n): GoogleVertexAnthropicProvider {\n const getBaseURL = () => {\n const baseURL = withoutTrailingSlash(options.baseURL);\n if (baseURL != null) {\n return baseURL;\n }\n const location = loadOptionalSetting({\n settingValue: options.location,\n environmentVariableName: 'GOOGLE_VERTEX_LOCATION',\n });\n if (location != null && !isValidHostnamePart(location)) {\n throw new InvalidArgumentError({\n argument: 'location',\n message:\n 'Invalid Google Vertex location. Expected a single DNS label (letters, digits, and hyphens). Use `baseURL` for custom endpoints.',\n });\n }\n const project = loadOptionalSetting({\n settingValue: options.project,\n environmentVariableName: 'GOOGLE_VERTEX_PROJECT',\n });\n\n const getHost = () => {\n if (location === 'global') {\n return 'aiplatform.googleapis.com';\n } else if (location === 'eu' || location === 'us') {\n return `aiplatform.${location}.rep.googleapis.com`;\n } else {\n return `${location}-aiplatform.googleapis.com`;\n }\n };\n\n return `https://${getHost()}/v1/projects/${project}/locations/${location}/publishers/anthropic/models`;\n };\n\n const createChatModel = (modelId: GoogleVertexAnthropicModelId) =>\n new AnthropicLanguageModel(modelId, {\n provider: 'googleVertex.anthropic.messages',\n baseURL: getBaseURL(),\n headers: options.headers ?? {},\n fetch: options.fetch,\n\n buildRequestUrl: (baseURL, isStreaming) =>\n `${baseURL}/${modelId}:${\n isStreaming ? 'streamRawPredict' : 'rawPredict'\n }`,\n transformRequestBody: args => {\n // Remove model from args and add anthropic version\n const { model: _model, ...rest } = args;\n return {\n ...rest,\n anthropic_version: 'vertex-2023-10-16',\n };\n },\n // Google Vertex Anthropic doesn't support URL sources, force download and base64 conversion\n supportedUrls: () => ({}),\n // force the use of JSON tool fallback for structured outputs since beta header isn't supported\n supportsNativeStructuredOutput: false,\n // Vertex Anthropic doesn't support strict mode on tool definitions.\n supportsStrictTools: false,\n });\n\n const provider = function (modelId: GoogleVertexAnthropicModelId) {\n if (new.target) {\n throw new Error(\n 'The Anthropic model function cannot be called with the new keyword.',\n );\n }\n\n return createChatModel(modelId);\n };\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.messages = createChatModel;\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n provider.tools = googleVertexAnthropicTools;\n\n return provider;\n}\n","import { resolve } from '@ai-sdk/provider-utils';\nimport {\n generateAuthToken as defaultGenerateAuthToken,\n type GoogleCredentials,\n} from '../../edge/google-vertex-auth-edge';\nimport {\n createGoogleVertexAnthropic as createVertexAnthropicOriginal,\n type GoogleVertexAnthropicProvider,\n type GoogleVertexAnthropicProviderSettings as GoogleVertexAnthropicProviderSettingsOriginal,\n} from '../google-vertex-anthropic-provider';\nexport type { GoogleVertexAnthropicProvider };\n\nexport interface GoogleVertexAnthropicProviderSettings extends GoogleVertexAnthropicProviderSettingsOriginal {\n /**\n * Optional. The 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 * Optional. Override the Bearer token generator. Defaults to OAuth exchange\n * with `googleCredentials`.\n */\n generateAuthToken?: () => Promise<string>;\n}\n\nexport function createGoogleVertexAnthropic(\n options: GoogleVertexAnthropicProviderSettings = {},\n): GoogleVertexAnthropicProvider {\n const generateAuthToken =\n options.generateAuthToken ??\n (() => defaultGenerateAuthToken(options.googleCredentials));\n return createVertexAnthropicOriginal({\n ...options,\n headers: async () => ({\n Authorization: `Bearer ${await generateAuthToken()}`,\n ...(await resolve(options.headers)),\n }),\n });\n}\n\n/**\n * Default Google Vertex AI Anthropic provider instance.\n */\nexport const googleVertexAnthropic = createGoogleVertexAnthropic();\n"],"mappings":";;;;AAEA,MAAa,UAAA;;;AC0Bb,MAAM,kBAAkB,YAAwC;CAC9D,IAAI;EACF,OAAO;GACL,aAAa,YAAY;IACvB,cAAc,KAAA;IACd,aAAa;IACb,yBAAyB;IACzB,aAAa;GACf,CAAC;GACD,YAAY,YAAY;IACtB,cAAc,KAAA;IACd,aAAa;IACb,yBAAyB;IACzB,aAAa;GACf,CAAC;GACD,cAAc,oBAAoB;IAChC,cAAc,KAAA;IACd,yBAAyB;GAC3B,CAAC;EACH;CACF,SAAS,OAAY;EACnB,MAAM,IAAI,MAAM,sCAAsC,MAAM,SAAS;CACvE;AACF;AAGA,MAAM,aAAa,QAAgB;CACjC,OAAO,KAAK,GAAG,CAAC,CAAC,QAAQ,OAAO,GAAG,CAAC,CAAC,QAAQ,OAAO,GAAG,CAAC,CAAC,QAAQ,MAAM,EAAE;AAC3E;AACA,MAAM,mBAAmB,OAAO,WAAmB;CAKjD,MAAM,cAAc,OACjB,QAAQ,+BAAW,EAAE,CAAC,CACtB,QAAQ,6BAAW,EAAE,CAAC,CACtB,QAAQ,OAAO,EAAE;CAGpB,MAAM,eAAe,KAAK,WAAW;CAGrC,MAAM,aAAa,IAAI,WAAW,aAAa,MAAM;CACrD,KAAK,IAAI,IAAI,GAAG,IAAI,aAAa,QAAQ,KACvC,WAAW,KAAK,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mBAAmB;GACrB;EACF;EAEA,sBAAsB,CAAC;EAEvB,gCAAgC;EAEhC,qBAAqB;CACvB,CAAC;CAEH,MAAM,WAAW,SAAU,SAAuC;EAChE,IAAI,YACF,MAAM,IAAI,MACR,qEACF;EAGF,OAAO,gBAAgB,OAAO;CAChC;CAEA,SAAS,uBAAuB;CAChC,SAAS,gBAAgB;CACzB,SAAS,OAAO;CAChB,SAAS,WAAW;CAEpB,SAAS,kBAAkB,YAAoB;EAC7C,MAAM,IAAI,iBAAiB;GAAE;GAAS,WAAW;EAAiB,CAAC;CACrE;CACA,SAAS,qBAAqB,SAAS;CACvC,SAAS,cAAc,YAAoB;EACzC,MAAM,IAAI,iBAAiB;GAAE;GAAS,WAAW;EAAa,CAAC;CACjE;CAEA,SAAS,QAAQ;CAEjB,OAAO;AACT;;;AClPA,SAAgB,4BACd,UAAiD,CAAC,GACnB;CAC/B,MAAMC,sBACJ,QAAQ,4BACDC,kBAAyB,QAAQ,iBAAiB;CAC3D,OAAOC,8BAA8B;EACnC,GAAG;EACH,SAAS,aAAa;GACpB,eAAe,UAAU,MAAMF,oBAAkB;GACjD,GAAI,MAAM,QAAQ,QAAQ,OAAO;EACnC;CACF,CAAC;AACH;;;;AAKA,MAAa,wBAAwB,4BAA4B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["GoogleVertexAnthropicProviderSettings","GoogleVertexAnthropicProviderSettingsOriginal"],"sources":["../../src/anthropic/google-vertex-anthropic-options.ts","../../src/anthropic/google-vertex-anthropic-provider.ts","../../src/anthropic/google-vertex-anthropic-provider-node.ts"],"mappings":";;;;;KACY;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["GoogleVertexAnthropicProviderSettings","GoogleVertexAnthropicProviderSettingsOriginal"],"sources":["../../src/anthropic/google-vertex-anthropic-options.ts","../../src/anthropic/google-vertex-anthropic-provider.ts","../../src/anthropic/google-vertex-anthropic-provider-node.ts"],"mappings":";;;;;KACY;;;KCkBP,6BAA6B,YACzB;;;;;cAiBI,4BAA4B;UAkFxB,sCAAsC;;;;GAIpD,SAAS,+BAA+B;;;;EAKzC,cAAc,SAAS,+BAA+B;;;;;;;;;EAUtD,cAAc;;;;EAKd,mBAAmB;;UAGJA;;;;EAIf;;;;EAKA;;;;;EAMA;;;;EAKA,UAAU,WAAW;;;;;EAMrB,QAAQ;;;;UClKO,8CAA8CC;;;;;;;EAO7D,oBAAoB;;;;;EAKpB,0BAA0B;;wBAGZ,4BACd,UAAS,wCACR;;;;qBAiBU,uBAAqB"}
|
package/dist/anthropic/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { loadOptionalSetting, resolve, withoutTrailingSlash } from "@ai-sdk/provider-utils";
|
|
1
|
+
import { isValidHostnamePart, loadOptionalSetting, resolve, withoutTrailingSlash } from "@ai-sdk/provider-utils";
|
|
2
2
|
import { GoogleAuth } from "google-auth-library";
|
|
3
|
-
import { NoSuchModelError } from "@ai-sdk/provider";
|
|
3
|
+
import { InvalidArgumentError, NoSuchModelError } from "@ai-sdk/provider";
|
|
4
4
|
import { AnthropicLanguageModel, anthropicTools } from "@ai-sdk/anthropic/internal";
|
|
5
5
|
//#region src/google-vertex-auth-google-auth-library.ts
|
|
6
6
|
function createAuthTokenGenerator(options) {
|
|
@@ -96,10 +96,16 @@ const googleVertexAnthropicTools = {
|
|
|
96
96
|
*/
|
|
97
97
|
function createGoogleVertexAnthropic$1(options = {}) {
|
|
98
98
|
const getBaseURL = () => {
|
|
99
|
+
const baseURL = withoutTrailingSlash(options.baseURL);
|
|
100
|
+
if (baseURL != null) return baseURL;
|
|
99
101
|
const location = loadOptionalSetting({
|
|
100
102
|
settingValue: options.location,
|
|
101
103
|
environmentVariableName: "GOOGLE_VERTEX_LOCATION"
|
|
102
104
|
});
|
|
105
|
+
if (location != null && !isValidHostnamePart(location)) throw new InvalidArgumentError({
|
|
106
|
+
argument: "location",
|
|
107
|
+
message: "Invalid Google Vertex location. Expected a single DNS label (letters, digits, and hyphens). Use `baseURL` for custom endpoints."
|
|
108
|
+
});
|
|
103
109
|
const project = loadOptionalSetting({
|
|
104
110
|
settingValue: options.project,
|
|
105
111
|
environmentVariableName: "GOOGLE_VERTEX_PROJECT"
|
|
@@ -109,7 +115,7 @@ function createGoogleVertexAnthropic$1(options = {}) {
|
|
|
109
115
|
else if (location === "eu" || location === "us") return `aiplatform.${location}.rep.googleapis.com`;
|
|
110
116
|
else return `${location}-aiplatform.googleapis.com`;
|
|
111
117
|
};
|
|
112
|
-
return
|
|
118
|
+
return `https://${getHost()}/v1/projects/${project}/locations/${location}/publishers/anthropic/models`;
|
|
113
119
|
};
|
|
114
120
|
const createChatModel = (modelId) => new AnthropicLanguageModel(modelId, {
|
|
115
121
|
provider: "googleVertex.anthropic.messages",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["createGoogleVertexAnthropic","createVertexAnthropicOriginal"],"sources":["../../src/google-vertex-auth-google-auth-library.ts","../../src/anthropic/google-vertex-anthropic-provider.ts","../../src/anthropic/google-vertex-anthropic-provider-node.ts"],"sourcesContent":["import { GoogleAuth, type GoogleAuthOptions } from 'google-auth-library';\n\nexport function createAuthTokenGenerator(options?: GoogleAuthOptions) {\n const auth = new GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n ...options,\n });\n\n return async function generateAuthToken() {\n const client = await auth.getClient();\n const token = await client.getAccessToken();\n return token?.token ?? null;\n };\n}\n","import {\n NoSuchModelError,\n type LanguageModelV4,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n loadOptionalSetting,\n withoutTrailingSlash,\n type FetchFunction,\n type Resolvable,\n} from '@ai-sdk/provider-utils';\nimport {\n anthropicTools,\n AnthropicLanguageModel,\n} from '@ai-sdk/anthropic/internal';\nimport type { GoogleVertexAnthropicModelId } from './google-vertex-anthropic-options';\n\ntype GoogleVertexAnthropicTools = Pick<\n typeof anthropicTools,\n | 'bash_20241022'\n | 'bash_20250124'\n | 'textEditor_20241022'\n | 'textEditor_20250124'\n | 'textEditor_20250429'\n | 'textEditor_20250728'\n | 'computer_20241022'\n | 'webSearch_20250305'\n | 'toolSearchRegex_20251119'\n | 'toolSearchBm25_20251119'\n>;\n\n/**\n * Tools supported by Google Vertex Anthropic.\n * This is a subset of the full Anthropic tools - only these are recognized by the Vertex API.\n */\nexport const googleVertexAnthropicTools: GoogleVertexAnthropicTools = {\n /**\n * The bash tool enables Claude to execute shell commands in a persistent bash session,\n * allowing system operations, script execution, and command-line automation.\n *\n * Image results are supported.\n */\n bash_20241022: anthropicTools.bash_20241022,\n\n /**\n * The bash tool enables Claude to execute shell commands in a persistent bash session,\n * allowing system operations, script execution, and command-line automation.\n *\n * Image results are supported.\n */\n bash_20250124: anthropicTools.bash_20250124,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files,\n * helping you debug, fix, and improve your code or other text documents.\n *\n * Supported models: Claude Sonnet 3.5\n */\n textEditor_20241022: anthropicTools.textEditor_20241022,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files,\n * helping you debug, fix, and improve your code or other text documents.\n *\n * Supported models: Claude Sonnet 3.7\n */\n textEditor_20250124: anthropicTools.textEditor_20250124,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files.\n * Note: This version does not support the \"undo_edit\" command.\n * @deprecated Use textEditor_20250728 instead\n */\n textEditor_20250429: anthropicTools.textEditor_20250429,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files.\n * Note: This version does not support the \"undo_edit\" command and adds optional max_characters parameter.\n * Supported models: Claude Sonnet 4, Opus 4, and Opus 4.1\n */\n textEditor_20250728: anthropicTools.textEditor_20250728,\n\n /**\n * Claude can interact with computer environments through the computer use tool, which\n * provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.\n *\n * Image results are supported.\n */\n computer_20241022: anthropicTools.computer_20241022,\n\n /**\n * Creates a web search tool that gives Claude direct access to real-time web content.\n */\n webSearch_20250305: anthropicTools.webSearch_20250305,\n\n /**\n * Creates a tool search tool that uses regex patterns to find tools.\n *\n * The tool search tool enables Claude to work with hundreds or thousands of tools\n * by dynamically discovering and loading them on-demand.\n *\n * Use `providerOptions: { anthropic: { deferLoading: true } }` on other tools\n * to mark them for deferred loading.\n */\n toolSearchRegex_20251119: anthropicTools.toolSearchRegex_20251119,\n\n /**\n * Creates a tool search tool that uses BM25 (natural language) to find tools.\n *\n * The tool search tool enables Claude to work with hundreds or thousands of tools\n * by dynamically discovering and loading them on-demand.\n *\n * Use `providerOptions: { anthropic: { deferLoading: true } }` on other tools\n * to mark them for deferred loading.\n */\n toolSearchBm25_20251119: anthropicTools.toolSearchBm25_20251119,\n};\nexport interface GoogleVertexAnthropicProvider extends ProviderV4 {\n /**\n * Creates a model for text generation.\n */\n (modelId: GoogleVertexAnthropicModelId): LanguageModelV4;\n\n /**\n * Creates a model for text generation.\n */\n languageModel(modelId: GoogleVertexAnthropicModelId): LanguageModelV4;\n\n /**\n * Anthropic tools supported by Google Vertex.\n * Note: Only a subset of Anthropic tools are available on Vertex.\n * Supported tools: bash_20241022, bash_20250124, textEditor_20241022,\n * textEditor_20250124, textEditor_20250429, textEditor_20250728,\n * computer_20241022, webSearch_20250305, toolSearchRegex_20251119,\n * toolSearchBm25_20251119\n */\n tools: typeof googleVertexAnthropicTools;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nexport interface GoogleVertexAnthropicProviderSettings {\n /**\n * Google Cloud project ID. Defaults to the value of the `GOOGLE_VERTEX_PROJECT` environment variable.\n */\n project?: string;\n\n /**\n * Google Cloud region. Defaults to the value of the `GOOGLE_VERTEX_LOCATION` environment variable.\n */\n location?: string;\n\n /**\n * Use a different URL prefix for API calls, e.g. to use proxy servers.\n * The default prefix is `https://api.anthropic.com/v1`.\n */\n baseURL?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Resolvable<Record<string, string | undefined>>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\n/**\n * Create a Google Vertex Anthropic provider instance.\n */\nexport function createGoogleVertexAnthropic(\n options: GoogleVertexAnthropicProviderSettings = {},\n): GoogleVertexAnthropicProvider {\n const getBaseURL = () => {\n const location = loadOptionalSetting({\n settingValue: options.location,\n environmentVariableName: 'GOOGLE_VERTEX_LOCATION',\n });\n const project = loadOptionalSetting({\n settingValue: options.project,\n environmentVariableName: 'GOOGLE_VERTEX_PROJECT',\n });\n\n const getHost = () => {\n if (location === 'global') {\n return 'aiplatform.googleapis.com';\n } else if (location === 'eu' || location === 'us') {\n return `aiplatform.${location}.rep.googleapis.com`;\n } else {\n return `${location}-aiplatform.googleapis.com`;\n }\n };\n\n return (\n withoutTrailingSlash(options.baseURL) ??\n `https://${getHost()}/v1/projects/${project}/locations/${location}/publishers/anthropic/models`\n );\n };\n\n const createChatModel = (modelId: GoogleVertexAnthropicModelId) =>\n new AnthropicLanguageModel(modelId, {\n provider: 'googleVertex.anthropic.messages',\n baseURL: getBaseURL(),\n headers: options.headers ?? {},\n fetch: options.fetch,\n\n buildRequestUrl: (baseURL, isStreaming) =>\n `${baseURL}/${modelId}:${\n isStreaming ? 'streamRawPredict' : 'rawPredict'\n }`,\n transformRequestBody: args => {\n // Remove model from args and add anthropic version\n const { model: _model, ...rest } = args;\n return {\n ...rest,\n anthropic_version: 'vertex-2023-10-16',\n };\n },\n // Google Vertex Anthropic doesn't support URL sources, force download and base64 conversion\n supportedUrls: () => ({}),\n // force the use of JSON tool fallback for structured outputs since beta header isn't supported\n supportsNativeStructuredOutput: false,\n // Vertex Anthropic doesn't support strict mode on tool definitions.\n supportsStrictTools: false,\n });\n\n const provider = function (modelId: GoogleVertexAnthropicModelId) {\n if (new.target) {\n throw new Error(\n 'The Anthropic model function cannot be called with the new keyword.',\n );\n }\n\n return createChatModel(modelId);\n };\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.messages = createChatModel;\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n provider.tools = googleVertexAnthropicTools;\n\n return provider;\n}\n","import { resolve } from '@ai-sdk/provider-utils';\nimport type { GoogleAuthOptions } from 'google-auth-library';\nimport { createAuthTokenGenerator } from '../google-vertex-auth-google-auth-library';\nimport {\n createGoogleVertexAnthropic as createVertexAnthropicOriginal,\n type GoogleVertexAnthropicProvider,\n type GoogleVertexAnthropicProviderSettings as GoogleVertexAnthropicProviderSettingsOriginal,\n} from './google-vertex-anthropic-provider';\nexport type { GoogleVertexAnthropicProvider };\n\nexport interface GoogleVertexAnthropicProviderSettings extends GoogleVertexAnthropicProviderSettingsOriginal {\n /**\n * Optional. The Authentication options provided by google-auth-library.\n * Complete list of authentication options is documented in the\n * GoogleAuthOptions interface:\n * https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts.\n */\n googleAuthOptions?: GoogleAuthOptions;\n /**\n * Optional. Override the Bearer token generator. Defaults to OAuth exchange\n * via `google-auth-library` with `googleAuthOptions`.\n */\n generateAuthToken?: () => Promise<string | null>;\n}\n\nexport function createGoogleVertexAnthropic(\n options: GoogleVertexAnthropicProviderSettings = {},\n): GoogleVertexAnthropicProvider {\n const generateAuthToken =\n options.generateAuthToken ??\n createAuthTokenGenerator(options.googleAuthOptions);\n\n return createVertexAnthropicOriginal({\n ...options,\n headers: async () => ({\n Authorization: `Bearer ${await generateAuthToken()}`,\n ...(await resolve(options.headers)),\n }),\n });\n}\n\n/**\n * Default Google Vertex Anthropic provider instance.\n */\nexport const googleVertexAnthropic = createGoogleVertexAnthropic();\n"],"mappings":";;;;;AAEA,SAAgB,yBAAyB,SAA6B;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IACL,GAAG;IACH,mBAAmB;GACrB;EACF;EAEA,sBAAsB,CAAC;EAEvB,gCAAgC;EAEhC,qBAAqB;CACvB,CAAC;CAEH,MAAM,WAAW,SAAU,SAAuC;EAChE,IAAI,YACF,MAAM,IAAI,MACR,qEACF;EAGF,OAAO,gBAAgB,OAAO;CAChC;CAEA,SAAS,uBAAuB;CAChC,SAAS,gBAAgB;CACzB,SAAS,OAAO;CAChB,SAAS,WAAW;CAEpB,SAAS,kBAAkB,YAAoB;EAC7C,MAAM,IAAI,iBAAiB;GAAE;GAAS,WAAW;EAAiB,CAAC;CACrE;CACA,SAAS,qBAAqB,SAAS;CACvC,SAAS,cAAc,YAAoB;EACzC,MAAM,IAAI,iBAAiB;GAAE;GAAS,WAAW;EAAa,CAAC;CACjE;CAEA,SAAS,QAAQ;CAEjB,OAAO;AACT;;;ACzOA,SAAgB,4BACd,UAAiD,CAAC,GACnB;CAC/B,MAAM,oBACJ,QAAQ,qBACR,yBAAyB,QAAQ,iBAAiB;CAEpD,OAAOC,8BAA8B;EACnC,GAAG;EACH,SAAS,aAAa;GACpB,eAAe,UAAU,MAAM,kBAAkB;GACjD,GAAI,MAAM,QAAQ,QAAQ,OAAO;EACnC;CACF,CAAC;AACH;;;;AAKA,MAAa,wBAAwB,4BAA4B"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["createGoogleVertexAnthropic","createVertexAnthropicOriginal"],"sources":["../../src/google-vertex-auth-google-auth-library.ts","../../src/anthropic/google-vertex-anthropic-provider.ts","../../src/anthropic/google-vertex-anthropic-provider-node.ts"],"sourcesContent":["import { GoogleAuth, type GoogleAuthOptions } from 'google-auth-library';\n\nexport function createAuthTokenGenerator(options?: GoogleAuthOptions) {\n const auth = new GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n ...options,\n });\n\n return async function generateAuthToken() {\n const client = await auth.getClient();\n const token = await client.getAccessToken();\n return token?.token ?? null;\n };\n}\n","import {\n InvalidArgumentError,\n NoSuchModelError,\n type LanguageModelV4,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n isValidHostnamePart,\n loadOptionalSetting,\n withoutTrailingSlash,\n type FetchFunction,\n type Resolvable,\n} from '@ai-sdk/provider-utils';\nimport {\n anthropicTools,\n AnthropicLanguageModel,\n} from '@ai-sdk/anthropic/internal';\nimport type { GoogleVertexAnthropicModelId } from './google-vertex-anthropic-options';\n\ntype GoogleVertexAnthropicTools = Pick<\n typeof anthropicTools,\n | 'bash_20241022'\n | 'bash_20250124'\n | 'textEditor_20241022'\n | 'textEditor_20250124'\n | 'textEditor_20250429'\n | 'textEditor_20250728'\n | 'computer_20241022'\n | 'webSearch_20250305'\n | 'toolSearchRegex_20251119'\n | 'toolSearchBm25_20251119'\n>;\n\n/**\n * Tools supported by Google Vertex Anthropic.\n * This is a subset of the full Anthropic tools - only these are recognized by the Vertex API.\n */\nexport const googleVertexAnthropicTools: GoogleVertexAnthropicTools = {\n /**\n * The bash tool enables Claude to execute shell commands in a persistent bash session,\n * allowing system operations, script execution, and command-line automation.\n *\n * Image results are supported.\n */\n bash_20241022: anthropicTools.bash_20241022,\n\n /**\n * The bash tool enables Claude to execute shell commands in a persistent bash session,\n * allowing system operations, script execution, and command-line automation.\n *\n * Image results are supported.\n */\n bash_20250124: anthropicTools.bash_20250124,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files,\n * helping you debug, fix, and improve your code or other text documents.\n *\n * Supported models: Claude Sonnet 3.5\n */\n textEditor_20241022: anthropicTools.textEditor_20241022,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files,\n * helping you debug, fix, and improve your code or other text documents.\n *\n * Supported models: Claude Sonnet 3.7\n */\n textEditor_20250124: anthropicTools.textEditor_20250124,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files.\n * Note: This version does not support the \"undo_edit\" command.\n * @deprecated Use textEditor_20250728 instead\n */\n textEditor_20250429: anthropicTools.textEditor_20250429,\n\n /**\n * Claude can use an Anthropic-defined text editor tool to view and modify text files.\n * Note: This version does not support the \"undo_edit\" command and adds optional max_characters parameter.\n * Supported models: Claude Sonnet 4, Opus 4, and Opus 4.1\n */\n textEditor_20250728: anthropicTools.textEditor_20250728,\n\n /**\n * Claude can interact with computer environments through the computer use tool, which\n * provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.\n *\n * Image results are supported.\n */\n computer_20241022: anthropicTools.computer_20241022,\n\n /**\n * Creates a web search tool that gives Claude direct access to real-time web content.\n */\n webSearch_20250305: anthropicTools.webSearch_20250305,\n\n /**\n * Creates a tool search tool that uses regex patterns to find tools.\n *\n * The tool search tool enables Claude to work with hundreds or thousands of tools\n * by dynamically discovering and loading them on-demand.\n *\n * Use `providerOptions: { anthropic: { deferLoading: true } }` on other tools\n * to mark them for deferred loading.\n */\n toolSearchRegex_20251119: anthropicTools.toolSearchRegex_20251119,\n\n /**\n * Creates a tool search tool that uses BM25 (natural language) to find tools.\n *\n * The tool search tool enables Claude to work with hundreds or thousands of tools\n * by dynamically discovering and loading them on-demand.\n *\n * Use `providerOptions: { anthropic: { deferLoading: true } }` on other tools\n * to mark them for deferred loading.\n */\n toolSearchBm25_20251119: anthropicTools.toolSearchBm25_20251119,\n};\nexport interface GoogleVertexAnthropicProvider extends ProviderV4 {\n /**\n * Creates a model for text generation.\n */\n (modelId: GoogleVertexAnthropicModelId): LanguageModelV4;\n\n /**\n * Creates a model for text generation.\n */\n languageModel(modelId: GoogleVertexAnthropicModelId): LanguageModelV4;\n\n /**\n * Anthropic tools supported by Google Vertex.\n * Note: Only a subset of Anthropic tools are available on Vertex.\n * Supported tools: bash_20241022, bash_20250124, textEditor_20241022,\n * textEditor_20250124, textEditor_20250429, textEditor_20250728,\n * computer_20241022, webSearch_20250305, toolSearchRegex_20251119,\n * toolSearchBm25_20251119\n */\n tools: typeof googleVertexAnthropicTools;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nexport interface GoogleVertexAnthropicProviderSettings {\n /**\n * Google Cloud project ID. Defaults to the value of the `GOOGLE_VERTEX_PROJECT` environment variable.\n */\n project?: string;\n\n /**\n * Google Cloud region. Defaults to the value of the `GOOGLE_VERTEX_LOCATION` environment variable.\n */\n location?: string;\n\n /**\n * Use a different URL prefix for API calls, e.g. to use proxy servers.\n * The default prefix is `https://api.anthropic.com/v1`.\n */\n baseURL?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Resolvable<Record<string, string | undefined>>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\n/**\n * Create a Google Vertex Anthropic provider instance.\n */\nexport function createGoogleVertexAnthropic(\n options: GoogleVertexAnthropicProviderSettings = {},\n): GoogleVertexAnthropicProvider {\n const getBaseURL = () => {\n const baseURL = withoutTrailingSlash(options.baseURL);\n if (baseURL != null) {\n return baseURL;\n }\n const location = loadOptionalSetting({\n settingValue: options.location,\n environmentVariableName: 'GOOGLE_VERTEX_LOCATION',\n });\n if (location != null && !isValidHostnamePart(location)) {\n throw new InvalidArgumentError({\n argument: 'location',\n message:\n 'Invalid Google Vertex location. Expected a single DNS label (letters, digits, and hyphens). Use `baseURL` for custom endpoints.',\n });\n }\n const project = loadOptionalSetting({\n settingValue: options.project,\n environmentVariableName: 'GOOGLE_VERTEX_PROJECT',\n });\n\n const getHost = () => {\n if (location === 'global') {\n return 'aiplatform.googleapis.com';\n } else if (location === 'eu' || location === 'us') {\n return `aiplatform.${location}.rep.googleapis.com`;\n } else {\n return `${location}-aiplatform.googleapis.com`;\n }\n };\n\n return `https://${getHost()}/v1/projects/${project}/locations/${location}/publishers/anthropic/models`;\n };\n\n const createChatModel = (modelId: GoogleVertexAnthropicModelId) =>\n new AnthropicLanguageModel(modelId, {\n provider: 'googleVertex.anthropic.messages',\n baseURL: getBaseURL(),\n headers: options.headers ?? {},\n fetch: options.fetch,\n\n buildRequestUrl: (baseURL, isStreaming) =>\n `${baseURL}/${modelId}:${\n isStreaming ? 'streamRawPredict' : 'rawPredict'\n }`,\n transformRequestBody: args => {\n // Remove model from args and add anthropic version\n const { model: _model, ...rest } = args;\n return {\n ...rest,\n anthropic_version: 'vertex-2023-10-16',\n };\n },\n // Google Vertex Anthropic doesn't support URL sources, force download and base64 conversion\n supportedUrls: () => ({}),\n // force the use of JSON tool fallback for structured outputs since beta header isn't supported\n supportsNativeStructuredOutput: false,\n // Vertex Anthropic doesn't support strict mode on tool definitions.\n supportsStrictTools: false,\n });\n\n const provider = function (modelId: GoogleVertexAnthropicModelId) {\n if (new.target) {\n throw new Error(\n 'The Anthropic model function cannot be called with the new keyword.',\n );\n }\n\n return createChatModel(modelId);\n };\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.messages = createChatModel;\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n provider.tools = googleVertexAnthropicTools;\n\n return provider;\n}\n","import { resolve } from '@ai-sdk/provider-utils';\nimport type { GoogleAuthOptions } from 'google-auth-library';\nimport { createAuthTokenGenerator } from '../google-vertex-auth-google-auth-library';\nimport {\n createGoogleVertexAnthropic as createVertexAnthropicOriginal,\n type GoogleVertexAnthropicProvider,\n type GoogleVertexAnthropicProviderSettings as GoogleVertexAnthropicProviderSettingsOriginal,\n} from './google-vertex-anthropic-provider';\nexport type { GoogleVertexAnthropicProvider };\n\nexport interface GoogleVertexAnthropicProviderSettings extends GoogleVertexAnthropicProviderSettingsOriginal {\n /**\n * Optional. The Authentication options provided by google-auth-library.\n * Complete list of authentication options is documented in the\n * GoogleAuthOptions interface:\n * https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts.\n */\n googleAuthOptions?: GoogleAuthOptions;\n /**\n * Optional. Override the Bearer token generator. Defaults to OAuth exchange\n * via `google-auth-library` with `googleAuthOptions`.\n */\n generateAuthToken?: () => Promise<string | null>;\n}\n\nexport function createGoogleVertexAnthropic(\n options: GoogleVertexAnthropicProviderSettings = {},\n): GoogleVertexAnthropicProvider {\n const generateAuthToken =\n options.generateAuthToken ??\n createAuthTokenGenerator(options.googleAuthOptions);\n\n return createVertexAnthropicOriginal({\n ...options,\n headers: async () => ({\n Authorization: `Bearer ${await generateAuthToken()}`,\n ...(await resolve(options.headers)),\n }),\n });\n}\n\n/**\n * Default Google Vertex Anthropic provider instance.\n */\nexport const googleVertexAnthropic = createGoogleVertexAnthropic();\n"],"mappings":";;;;;AAEA,SAAgB,yBAAyB,SAA6B;CACpE,MAAM,OAAO,IAAI,WAAW;EAC1B,QAAQ,CAAC,gDAAgD;EACzD,GAAG;CACL,CAAC;CAED,OAAO,eAAe,oBAAoB;EAGxC,QAAO,OADa,MADC,KAAK,UAAU,EAAA,CACT,eAAe,EAAA,EAC5B,SAAS;CACzB;AACF;;;;;;;ACwBA,MAAa,6BAAyD;;;;;;;CAOpE,eAAe,eAAe;;;;;;;CAQ9B,eAAe,eAAe;;;;;;;CAQ9B,qBAAqB,eAAe;;;;;;;CAQpC,qBAAqB,eAAe;;;;;;CAOpC,qBAAqB,eAAe;;;;;;CAOpC,qBAAqB,eAAe;;;;;;;CAQpC,mBAAmB,eAAe;;;;CAKlC,oBAAoB,eAAe;;;;;;;;;;CAWnC,0BAA0B,eAAe;;;;;;;;;;CAWzC,yBAAyB,eAAe;AAC1C;;;;AA4DA,SAAgBA,8BACd,UAAiD,CAAC,GACnB;CAC/B,MAAM,mBAAmB;EACvB,MAAM,UAAU,qBAAqB,QAAQ,OAAO;EACpD,IAAI,WAAW,MACb,OAAO;EAET,MAAM,WAAW,oBAAoB;GACnC,cAAc,QAAQ;GACtB,yBAAyB;EAC3B,CAAC;EACD,IAAI,YAAY,QAAQ,CAAC,oBAAoB,QAA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,iBAAiB;CAEpD,OAAOC,8BAA8B;EACnC,GAAG;EACH,SAAS,aAAa;GACpB,eAAe,UAAU,MAAM,kBAAkB;GACjD,GAAI,MAAM,QAAQ,QAAQ,OAAO;EACnC;CACF,CAAC;AACH;;;;AAKA,MAAa,wBAAwB,4BAA4B"}
|
package/dist/edge/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["GoogleVertexProviderSettings","GoogleVertexProviderSettingsOriginal"],"sources":["../../src/google-vertex-embedding-model-options.ts","../../src/google-vertex-config.ts","../../src/google-vertex-embedding-model.ts","../../src/google-vertex-image-settings.ts","../../src/google-vertex-options.ts","../../src/google-vertex-tools.ts","../../src/google-vertex-transcription-model-options.ts","../../src/google-vertex-video-settings.ts","../../src/google-vertex-speech-model-options.ts","../../src/google-vertex-provider-base.ts","../../src/edge/google-vertex-auth-edge.ts","../../src/edge/google-vertex-provider-edge.ts"],"mappings":";;;;;;KAGY;;;UCDK;EACf;EACA;EACA,UAAU,WAAW;EACrB,QAAQ;;;;cCgBG,sCAAsC;WACxC;WACA,SAAS;WACT;mBAEQ;UAET,oBAAoB,OAAO;;;;UAO3B,sBAAsB;IAC5B;IACA,QAAQ;MACT;MAIG;MAMA;EAKF,YAAA,SAAS,8BACT,QAAQ;EAMJ,UACJ,QACA,SACA,aACA,mBACC,WAAW,kCAAkC,QAC9C,QAAQ,WAAW;;;;KCnEX;;;KCGA;;;cCDC;;;;MAS0qlB,YAAC;MAAsD,cAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KCPnulB;;;KCJA;;;KCMA;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["GoogleVertexProviderSettings","GoogleVertexProviderSettingsOriginal"],"sources":["../../src/google-vertex-embedding-model-options.ts","../../src/google-vertex-config.ts","../../src/google-vertex-embedding-model.ts","../../src/google-vertex-image-settings.ts","../../src/google-vertex-options.ts","../../src/google-vertex-tools.ts","../../src/google-vertex-transcription-model-options.ts","../../src/google-vertex-video-settings.ts","../../src/google-vertex-speech-model-options.ts","../../src/google-vertex-provider-base.ts","../../src/edge/google-vertex-auth-edge.ts","../../src/edge/google-vertex-provider-edge.ts"],"mappings":";;;;;;KAGY;;;UCDK;EACf;EACA;EACA,UAAU,WAAW;EACrB,QAAQ;;;;cCgBG,sCAAsC;WACxC;WACA,SAAS;WACT;mBAEQ;UAET,oBAAoB,OAAO;;;;UAO3B,sBAAsB;IAC5B;IACA,QAAQ;MACT;MAIG;MAMA;EAKF,YAAA,SAAS,8BACT,QAAQ;EAMJ,UACJ,QACA,SACA,aACA,mBACC,WAAW,kCAAkC,QAC9C,QAAQ,WAAW;;;;KCnEX;;;KCGA;;;cCDC;;;;MAS0qlB,YAAC;MAAsD,cAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KCPnulB;;;KCJA;;;KCMA;;;UCqEK,6BAA6B;;;;GAI3C,SAAS,sBAAsB;EAEhC,gBAAgB,SAAS,wBAAwB;;;;;;;EAQjD,aACE,gBACI;IACE,OAAO;;IACP;MACL;;;;EAKH,MAAM,SAAS,2BAA2B;;;;EAK1C,WAAW,SAAS,2BAA2B;EAE/C,cAAc;;;;EAKd,mBACE,SAAS,+BACR;;;;EAKH,MAAM,SAAS,2BAA2B;;;;EAK1C,WAAW,SAAS,2BAA2B;;;;EAK/C,OAAO,SAAS,4BAA4B;;;;EAK5C,YAAY,SAAS,4BAA4B;;;;EAKjD,cACE,SAAS,mCACR;;;;EAKH,mBACE,SAAS,mCACR;;UAGYA;;;;;;EAMf;;;;EAKA;;;;EAKA;;;;;;;;EASA,UAAU,WAAW;;;;;EAMrB,QAAQ;EAGR;;;;EAKA;;;;;;EAOA,YAAY;;;;;EAMZ;;;;IAIE;;;;;UCtMa;;;;;EAKf;;;;;EAMA;;;;;EAMA;;;;UCbe,qCAAqCC;;;;;;EAMpD,oBAAoB;;wBAGN,mBACd,UAAS,+BACR;;;;qBAwBU,cAAY"}
|
package/dist/edge/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, connectToWebSocket, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createJsonErrorResponseHandler, createJsonResponseHandler, generateId, getRuntimeEnvironmentUserAgent, lazySchema, loadOptionalSetting, loadSetting, normalizeHeaders, parseProviderOptions, postJsonToApi, resolve, safeParseJSON, serializeModelOptions, waitForWebSocketBufferDrain, withUserAgentSuffix, withoutTrailingSlash, zodSchema } from "@ai-sdk/provider-utils";
|
|
1
|
+
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, connectToWebSocket, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createJsonErrorResponseHandler, createJsonResponseHandler, generateId, getRuntimeEnvironmentUserAgent, isValidHostnamePart, lazySchema, loadOptionalSetting, loadSetting, normalizeHeaders, parseProviderOptions, postJsonToApi, resolve, safeParseJSON, serializeModelOptions, waitForWebSocketBufferDrain, withUserAgentSuffix, withoutTrailingSlash, zodSchema } from "@ai-sdk/provider-utils";
|
|
2
2
|
import { GoogleInteractionsLanguageModel, GoogleLanguageModel, GoogleSpeechModel, googleTools } from "@ai-sdk/google/internal";
|
|
3
3
|
import { AISDKError, InvalidArgumentError, TooManyEmbeddingValuesForCallError } from "@ai-sdk/provider";
|
|
4
4
|
import { z } from "zod/v4";
|
|
5
5
|
//#region src/version.ts
|
|
6
|
-
const VERSION = "5.0.
|
|
6
|
+
const VERSION = "5.0.100";
|
|
7
7
|
//#endregion
|
|
8
8
|
//#region src/google-vertex-error.ts
|
|
9
9
|
const googleVertexErrorDataSchema = z.object({ error: z.object({
|
|
@@ -419,7 +419,8 @@ const googleVertexTranscriptionProviderOptionsSchema = z.object({
|
|
|
419
419
|
enableWordTimeOffsets: z.boolean().optional(),
|
|
420
420
|
/**
|
|
421
421
|
* The Cloud Speech-to-Text region for the request (e.g. `'us'`, `'eu'`,
|
|
422
|
-
* `'us-central1'`). Defaults to the provider `location`.
|
|
422
|
+
* `'us-central1'`). Defaults to the provider `location`. Must be a single
|
|
423
|
+
* DNS label (letters, digits, and hyphens).
|
|
423
424
|
*
|
|
424
425
|
* Note: Speech-to-Text regions differ from Vertex AI regions. Chirp is only
|
|
425
426
|
* available in specific Speech-to-Text regions and is not available in the
|
|
@@ -478,6 +479,10 @@ var GoogleVertexTranscriptionModel = class GoogleVertexTranscriptionModel {
|
|
|
478
479
|
if (googleOptions != null) break;
|
|
479
480
|
}
|
|
480
481
|
const region = googleOptions?.region ?? this.config.location;
|
|
482
|
+
if (!isValidHostnamePart(region)) throw new InvalidArgumentError({
|
|
483
|
+
argument: googleOptions?.region != null ? "region" : "location",
|
|
484
|
+
message: "Invalid Google Cloud Speech-to-Text region. Expected a single DNS label (letters, digits, and hyphens)."
|
|
485
|
+
});
|
|
481
486
|
const languageCodes = googleOptions?.languageCodes ?? ["auto"];
|
|
482
487
|
const content = typeof options.audio === "string" ? options.audio : convertUint8ArrayToBase64(options.audio);
|
|
483
488
|
const requestBody = {
|
|
@@ -695,7 +700,10 @@ var GoogleVertexGeminiTranscriptionModel = class GoogleVertexGeminiTranscription
|
|
|
695
700
|
headers: responseHeaders,
|
|
696
701
|
body: rawResponse
|
|
697
702
|
},
|
|
698
|
-
...response.usageMetadata != null ? {
|
|
703
|
+
...response.usageMetadata != null ? {
|
|
704
|
+
usage: response.usageMetadata,
|
|
705
|
+
providerMetadata: { google: { usageMetadata: response.usageMetadata } }
|
|
706
|
+
} : {}
|
|
699
707
|
};
|
|
700
708
|
}
|
|
701
709
|
async doStream(options) {
|
|
@@ -807,7 +815,10 @@ function createVertexLiveTranscriptionStream({ webSocket, url, headers, setup, i
|
|
|
807
815
|
segments: [],
|
|
808
816
|
language,
|
|
809
817
|
durationInSeconds: void 0,
|
|
810
|
-
...usageMetadata != null ? {
|
|
818
|
+
...usageMetadata != null ? {
|
|
819
|
+
usage: usageMetadata,
|
|
820
|
+
providerMetadata: { google: { usageMetadata } }
|
|
821
|
+
} : {}
|
|
811
822
|
});
|
|
812
823
|
controller.close();
|
|
813
824
|
cleanup(1e3);
|
|
@@ -1256,14 +1267,23 @@ function createGoogleVertex$1(options = {}) {
|
|
|
1256
1267
|
environmentVariableName: "GOOGLE_VERTEX_PROJECT",
|
|
1257
1268
|
description: "Google Vertex project"
|
|
1258
1269
|
});
|
|
1259
|
-
const loadGoogleVertexLocation = () =>
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1270
|
+
const loadGoogleVertexLocation = () => {
|
|
1271
|
+
const location = loadSetting({
|
|
1272
|
+
settingValue: options.location,
|
|
1273
|
+
settingName: "location",
|
|
1274
|
+
environmentVariableName: "GOOGLE_VERTEX_LOCATION",
|
|
1275
|
+
description: "Google Vertex location"
|
|
1276
|
+
});
|
|
1277
|
+
if (!isValidHostnamePart(location)) throw new InvalidArgumentError({
|
|
1278
|
+
argument: "location",
|
|
1279
|
+
message: "Invalid Google Vertex location. Expected a single DNS label (letters, digits, and hyphens). Use `baseURL` for custom endpoints."
|
|
1280
|
+
});
|
|
1281
|
+
return location;
|
|
1282
|
+
};
|
|
1265
1283
|
const loadBaseURL = ({ endpoint = false } = {}) => {
|
|
1266
1284
|
if (apiKey) return withoutTrailingSlash(options.baseURL) ?? EXPRESS_MODE_BASE_URL;
|
|
1285
|
+
const baseURL = withoutTrailingSlash(options.baseURL);
|
|
1286
|
+
if (baseURL != null) return baseURL;
|
|
1267
1287
|
const region = loadGoogleVertexLocation();
|
|
1268
1288
|
const project = loadGoogleVertexProject();
|
|
1269
1289
|
const getHost = () => {
|
|
@@ -1271,7 +1291,7 @@ function createGoogleVertex$1(options = {}) {
|
|
|
1271
1291
|
else if (region === "eu" || region === "us") return `aiplatform.${region}.rep.googleapis.com`;
|
|
1272
1292
|
else return `${region}-aiplatform.googleapis.com`;
|
|
1273
1293
|
};
|
|
1274
|
-
return
|
|
1294
|
+
return `https://${getHost()}/v1beta1/projects/${project}/locations/${region}${endpoint ? "" : "/publishers/google"}`;
|
|
1275
1295
|
};
|
|
1276
1296
|
const createConfig = (name, { endpoint = false } = {}) => {
|
|
1277
1297
|
const getHeaders = async () => {
|