@ai-sdk/google-vertex 3.0.0-canary.0 → 3.0.0-canary.2
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 +20 -0
- package/anthropic/dist/index.d.mts +4 -4
- package/anthropic/dist/index.d.ts +4 -4
- package/anthropic/dist/index.js +3 -0
- package/anthropic/dist/index.js.map +1 -1
- package/anthropic/dist/index.mjs +3 -0
- package/anthropic/dist/index.mjs.map +1 -1
- package/anthropic/edge/dist/index.d.mts +4 -4
- package/anthropic/edge/dist/index.d.ts +4 -4
- package/anthropic/edge/dist/index.js +3 -0
- package/anthropic/edge/dist/index.js.map +1 -1
- package/anthropic/edge/dist/index.mjs +3 -0
- package/anthropic/edge/dist/index.mjs.map +1 -1
- package/dist/index.d.mts +31 -9
- package/dist/index.d.ts +31 -9
- package/dist/index.js +22 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +23 -5
- package/dist/index.mjs.map +1 -1
- package/edge/dist/index.d.mts +4 -4
- package/edge/dist/index.d.ts +4 -4
- package/edge/dist/index.js +22 -5
- package/edge/dist/index.js.map +1 -1
- package/edge/dist/index.mjs +23 -5
- package/edge/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
# @ai-sdk/google-vertex
|
2
2
|
|
3
|
+
## 3.0.0-canary.2
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- Updated dependencies [5cf30ea]
|
8
|
+
- @ai-sdk/google@2.0.0-canary.2
|
9
|
+
|
10
|
+
## 3.0.0-canary.1
|
11
|
+
|
12
|
+
### Patch Changes
|
13
|
+
|
14
|
+
- 779d916: feat: add provider option schemas for vertex imagegen and google genai
|
15
|
+
- Updated dependencies [060370c]
|
16
|
+
- Updated dependencies [0c0c0b3]
|
17
|
+
- Updated dependencies [779d916]
|
18
|
+
- Updated dependencies [63d791d]
|
19
|
+
- @ai-sdk/provider-utils@3.0.0-canary.1
|
20
|
+
- @ai-sdk/google@2.0.0-canary.1
|
21
|
+
- @ai-sdk/anthropic@2.0.0-canary.1
|
22
|
+
|
3
23
|
## 3.0.0-canary.0
|
4
24
|
|
5
25
|
### Major Changes
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { GoogleAuthOptions } from 'google-auth-library';
|
2
|
-
import {
|
2
|
+
import { ProviderV2, LanguageModelV2 } from '@ai-sdk/provider';
|
3
3
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
4
4
|
import { AnthropicMessagesSettings, anthropicTools } from '@ai-sdk/anthropic/internal';
|
5
5
|
|
@@ -7,15 +7,15 @@ type GoogleVertexAnthropicMessagesModelId = 'claude-3-7-sonnet@20250219' | 'clau
|
|
7
7
|
interface GoogleVertexAnthropicMessagesSettings extends AnthropicMessagesSettings {
|
8
8
|
}
|
9
9
|
|
10
|
-
interface GoogleVertexAnthropicProvider extends
|
10
|
+
interface GoogleVertexAnthropicProvider extends ProviderV2 {
|
11
11
|
/**
|
12
12
|
Creates a model for text generation.
|
13
13
|
*/
|
14
|
-
(modelId: GoogleVertexAnthropicMessagesModelId, settings?: GoogleVertexAnthropicMessagesSettings):
|
14
|
+
(modelId: GoogleVertexAnthropicMessagesModelId, settings?: GoogleVertexAnthropicMessagesSettings): LanguageModelV2;
|
15
15
|
/**
|
16
16
|
Creates a model for text generation.
|
17
17
|
*/
|
18
|
-
languageModel(modelId: GoogleVertexAnthropicMessagesModelId, settings?: GoogleVertexAnthropicMessagesSettings):
|
18
|
+
languageModel(modelId: GoogleVertexAnthropicMessagesModelId, settings?: GoogleVertexAnthropicMessagesSettings): LanguageModelV2;
|
19
19
|
/**
|
20
20
|
Anthropic-specific computer use tool.
|
21
21
|
*/
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { GoogleAuthOptions } from 'google-auth-library';
|
2
|
-
import {
|
2
|
+
import { ProviderV2, LanguageModelV2 } from '@ai-sdk/provider';
|
3
3
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
4
4
|
import { AnthropicMessagesSettings, anthropicTools } from '@ai-sdk/anthropic/internal';
|
5
5
|
|
@@ -7,15 +7,15 @@ type GoogleVertexAnthropicMessagesModelId = 'claude-3-7-sonnet@20250219' | 'clau
|
|
7
7
|
interface GoogleVertexAnthropicMessagesSettings extends AnthropicMessagesSettings {
|
8
8
|
}
|
9
9
|
|
10
|
-
interface GoogleVertexAnthropicProvider extends
|
10
|
+
interface GoogleVertexAnthropicProvider extends ProviderV2 {
|
11
11
|
/**
|
12
12
|
Creates a model for text generation.
|
13
13
|
*/
|
14
|
-
(modelId: GoogleVertexAnthropicMessagesModelId, settings?: GoogleVertexAnthropicMessagesSettings):
|
14
|
+
(modelId: GoogleVertexAnthropicMessagesModelId, settings?: GoogleVertexAnthropicMessagesSettings): LanguageModelV2;
|
15
15
|
/**
|
16
16
|
Creates a model for text generation.
|
17
17
|
*/
|
18
|
-
languageModel(modelId: GoogleVertexAnthropicMessagesModelId, settings?: GoogleVertexAnthropicMessagesSettings):
|
18
|
+
languageModel(modelId: GoogleVertexAnthropicMessagesModelId, settings?: GoogleVertexAnthropicMessagesSettings): LanguageModelV2;
|
19
19
|
/**
|
20
20
|
Anthropic-specific computer use tool.
|
21
21
|
*/
|
package/anthropic/dist/index.js
CHANGED
@@ -100,6 +100,9 @@ function createVertexAnthropic(options = {}) {
|
|
100
100
|
provider.textEmbeddingModel = (modelId) => {
|
101
101
|
throw new import_provider.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
|
102
102
|
};
|
103
|
+
provider.imageModel = (modelId) => {
|
104
|
+
throw new import_provider.NoSuchModelError({ modelId, modelType: "imageModel" });
|
105
|
+
};
|
103
106
|
provider.tools = import_internal.anthropicTools;
|
104
107
|
return provider;
|
105
108
|
}
|
@@ -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
|
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 AnthropicMessagesModelId,\n} from '@ai-sdk/anthropic/internal';\nimport {\n GoogleVertexAnthropicMessagesModelId,\n GoogleVertexAnthropicMessagesSettings,\n} from './google-vertex-anthropic-messages-settings';\nexport interface GoogleVertexAnthropicProvider extends ProviderV2 {\n /**\nCreates a model for text generation.\n*/\n (\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings?: GoogleVertexAnthropicMessagesSettings,\n ): LanguageModelV2;\n\n /**\nCreates a model for text generation.\n*/\n languageModel(\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings?: GoogleVertexAnthropicMessagesSettings,\n ): 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 = (\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings: GoogleVertexAnthropicMessagesSettings = {},\n ) =>\n new AnthropicMessagesLanguageModel(\n modelId as AnthropicMessagesModelId,\n settings,\n {\n provider: 'vertex.anthropic.messages',\n baseURL,\n headers: options.headers ?? {},\n fetch: options.fetch,\n supportsImageUrls: false,\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 },\n );\n\n const provider = function (\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings?: GoogleVertexAnthropicMessagesSettings,\n ) {\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, settings);\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: '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BACzB,GAAGA,QAAO,IAAI,OAAO,IACnB,cAAc,qBAAqB,YACrC;AAAA,QACF,sBAAsB,UAAQ;AAE5B,gBAAM,EAAE,OAAO,GAAG,KAAK,IAAI;AAC3B,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,mBAAmB;AAAA,UACrB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA;AAEF,QAAM,WAAW,SACf,SACA,UACA;AACA,QAAI,YAAY;AACd,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,WAAO,gBAAgB,SAAS,QAAQ;AAAA,EAC1C;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;;;AF3HO,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","_a","baseURL","createVertexAnthropic"]}
|
package/anthropic/dist/index.mjs
CHANGED
@@ -81,6 +81,9 @@ function createVertexAnthropic(options = {}) {
|
|
81
81
|
provider.textEmbeddingModel = (modelId) => {
|
82
82
|
throw new NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
|
83
83
|
};
|
84
|
+
provider.imageModel = (modelId) => {
|
85
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
86
|
+
};
|
84
87
|
provider.tools = anthropicTools;
|
85
88
|
return provider;
|
86
89
|
}
|
@@ -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
|
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 AnthropicMessagesModelId,\n} from '@ai-sdk/anthropic/internal';\nimport {\n GoogleVertexAnthropicMessagesModelId,\n GoogleVertexAnthropicMessagesSettings,\n} from './google-vertex-anthropic-messages-settings';\nexport interface GoogleVertexAnthropicProvider extends ProviderV2 {\n /**\nCreates a model for text generation.\n*/\n (\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings?: GoogleVertexAnthropicMessagesSettings,\n ): LanguageModelV2;\n\n /**\nCreates a model for text generation.\n*/\n languageModel(\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings?: GoogleVertexAnthropicMessagesSettings,\n ): 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 = (\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings: GoogleVertexAnthropicMessagesSettings = {},\n ) =>\n new AnthropicMessagesLanguageModel(\n modelId as AnthropicMessagesModelId,\n settings,\n {\n provider: 'vertex.anthropic.messages',\n baseURL,\n headers: options.headers ?? {},\n fetch: options.fetch,\n supportsImageUrls: false,\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 },\n );\n\n const provider = function (\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings?: GoogleVertexAnthropicMessagesSettings,\n ) {\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, settings);\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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,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,mBAAmB;AAAA,UACrB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA;AAEF,QAAM,WAAW,SACf,SACA,UACA;AACA,QAAI,YAAY;AACd,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,WAAO,gBAAgB,SAAS,QAAQ;AAAA,EAC1C;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;;;AF3HO,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"]}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { ProviderV2, LanguageModelV2 } from '@ai-sdk/provider';
|
2
2
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
3
3
|
import { AnthropicMessagesSettings, anthropicTools } from '@ai-sdk/anthropic/internal';
|
4
4
|
|
@@ -24,15 +24,15 @@ type GoogleVertexAnthropicMessagesModelId = 'claude-3-7-sonnet@20250219' | 'clau
|
|
24
24
|
interface GoogleVertexAnthropicMessagesSettings extends AnthropicMessagesSettings {
|
25
25
|
}
|
26
26
|
|
27
|
-
interface GoogleVertexAnthropicProvider extends
|
27
|
+
interface GoogleVertexAnthropicProvider extends ProviderV2 {
|
28
28
|
/**
|
29
29
|
Creates a model for text generation.
|
30
30
|
*/
|
31
|
-
(modelId: GoogleVertexAnthropicMessagesModelId, settings?: GoogleVertexAnthropicMessagesSettings):
|
31
|
+
(modelId: GoogleVertexAnthropicMessagesModelId, settings?: GoogleVertexAnthropicMessagesSettings): LanguageModelV2;
|
32
32
|
/**
|
33
33
|
Creates a model for text generation.
|
34
34
|
*/
|
35
|
-
languageModel(modelId: GoogleVertexAnthropicMessagesModelId, settings?: GoogleVertexAnthropicMessagesSettings):
|
35
|
+
languageModel(modelId: GoogleVertexAnthropicMessagesModelId, settings?: GoogleVertexAnthropicMessagesSettings): LanguageModelV2;
|
36
36
|
/**
|
37
37
|
Anthropic-specific computer use tool.
|
38
38
|
*/
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { ProviderV2, LanguageModelV2 } from '@ai-sdk/provider';
|
2
2
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
3
3
|
import { AnthropicMessagesSettings, anthropicTools } from '@ai-sdk/anthropic/internal';
|
4
4
|
|
@@ -24,15 +24,15 @@ type GoogleVertexAnthropicMessagesModelId = 'claude-3-7-sonnet@20250219' | 'clau
|
|
24
24
|
interface GoogleVertexAnthropicMessagesSettings extends AnthropicMessagesSettings {
|
25
25
|
}
|
26
26
|
|
27
|
-
interface GoogleVertexAnthropicProvider extends
|
27
|
+
interface GoogleVertexAnthropicProvider extends ProviderV2 {
|
28
28
|
/**
|
29
29
|
Creates a model for text generation.
|
30
30
|
*/
|
31
|
-
(modelId: GoogleVertexAnthropicMessagesModelId, settings?: GoogleVertexAnthropicMessagesSettings):
|
31
|
+
(modelId: GoogleVertexAnthropicMessagesModelId, settings?: GoogleVertexAnthropicMessagesSettings): LanguageModelV2;
|
32
32
|
/**
|
33
33
|
Creates a model for text generation.
|
34
34
|
*/
|
35
|
-
languageModel(modelId: GoogleVertexAnthropicMessagesModelId, settings?: GoogleVertexAnthropicMessagesSettings):
|
35
|
+
languageModel(modelId: GoogleVertexAnthropicMessagesModelId, settings?: GoogleVertexAnthropicMessagesSettings): LanguageModelV2;
|
36
36
|
/**
|
37
37
|
Anthropic-specific computer use tool.
|
38
38
|
*/
|
@@ -181,6 +181,9 @@ function createVertexAnthropic(options = {}) {
|
|
181
181
|
provider.textEmbeddingModel = (modelId) => {
|
182
182
|
throw new import_provider.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
|
183
183
|
};
|
184
|
+
provider.imageModel = (modelId) => {
|
185
|
+
throw new import_provider.NoSuchModelError({ modelId, modelType: "imageModel" });
|
186
|
+
};
|
184
187
|
provider.tools = import_internal.anthropicTools;
|
185
188
|
return provider;
|
186
189
|
}
|
@@ -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 LanguageModelV1,\n NoSuchModelError,\n ProviderV1,\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 AnthropicMessagesModelId,\n} from '@ai-sdk/anthropic/internal';\nimport {\n GoogleVertexAnthropicMessagesModelId,\n GoogleVertexAnthropicMessagesSettings,\n} from './google-vertex-anthropic-messages-settings';\nexport interface GoogleVertexAnthropicProvider extends ProviderV1 {\n /**\nCreates a model for text generation.\n*/\n (\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings?: GoogleVertexAnthropicMessagesSettings,\n ): LanguageModelV1;\n\n /**\nCreates a model for text generation.\n*/\n languageModel(\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings?: GoogleVertexAnthropicMessagesSettings,\n ): LanguageModelV1;\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 = (\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings: GoogleVertexAnthropicMessagesSettings = {},\n ) =>\n new AnthropicMessagesLanguageModel(\n modelId as AnthropicMessagesModelId,\n settings,\n {\n provider: 'vertex.anthropic.messages',\n baseURL,\n headers: options.headers ?? {},\n fetch: options.fetch,\n supportsImageUrls: false,\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 },\n );\n\n const provider = function (\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings?: GoogleVertexAnthropicMessagesSettings,\n ) {\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, settings);\n };\n\n provider.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.messages = createChatModel;\n provider.textEmbeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'textEmbeddingModel' });\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,Q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7B,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 AnthropicMessagesModelId,\n} from '@ai-sdk/anthropic/internal';\nimport {\n GoogleVertexAnthropicMessagesModelId,\n GoogleVertexAnthropicMessagesSettings,\n} from './google-vertex-anthropic-messages-settings';\nexport interface GoogleVertexAnthropicProvider extends ProviderV2 {\n /**\nCreates a model for text generation.\n*/\n (\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings?: GoogleVertexAnthropicMessagesSettings,\n ): LanguageModelV2;\n\n /**\nCreates a model for text generation.\n*/\n languageModel(\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings?: GoogleVertexAnthropicMessagesSettings,\n ): 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 = (\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings: GoogleVertexAnthropicMessagesSettings = {},\n ) =>\n new AnthropicMessagesLanguageModel(\n modelId as AnthropicMessagesModelId,\n settings,\n {\n provider: 'vertex.anthropic.messages',\n baseURL,\n headers: options.headers ?? {},\n fetch: options.fetch,\n supportsImageUrls: false,\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 },\n );\n\n const provider = function (\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings?: GoogleVertexAnthropicMessagesSettings,\n ) {\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, settings);\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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;","names":["createVertexAnthropic","import_provider_utils","import_provider_utils","_a","baseURL","createVertexAnthropic"]}
|
@@ -162,6 +162,9 @@ function createVertexAnthropic(options = {}) {
|
|
162
162
|
provider.textEmbeddingModel = (modelId) => {
|
163
163
|
throw new NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
|
164
164
|
};
|
165
|
+
provider.imageModel = (modelId) => {
|
166
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
167
|
+
};
|
165
168
|
provider.tools = anthropicTools;
|
166
169
|
return provider;
|
167
170
|
}
|
@@ -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 LanguageModelV1,\n NoSuchModelError,\n ProviderV1,\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 AnthropicMessagesModelId,\n} from '@ai-sdk/anthropic/internal';\nimport {\n GoogleVertexAnthropicMessagesModelId,\n GoogleVertexAnthropicMessagesSettings,\n} from './google-vertex-anthropic-messages-settings';\nexport interface GoogleVertexAnthropicProvider extends ProviderV1 {\n /**\nCreates a model for text generation.\n*/\n (\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings?: GoogleVertexAnthropicMessagesSettings,\n ): LanguageModelV1;\n\n /**\nCreates a model for text generation.\n*/\n languageModel(\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings?: GoogleVertexAnthropicMessagesSettings,\n ): LanguageModelV1;\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 = (\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings: GoogleVertexAnthropicMessagesSettings = {},\n ) =>\n new AnthropicMessagesLanguageModel(\n modelId as AnthropicMessagesModelId,\n settings,\n {\n provider: 'vertex.anthropic.messages',\n baseURL,\n headers: options.headers ?? {},\n fetch: options.fetch,\n supportsImageUrls: false,\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 },\n );\n\n const provider = function (\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings?: GoogleVertexAnthropicMessagesSettings,\n ) {\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, settings);\n };\n\n provider.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.messages = createChatModel;\n provider.textEmbeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'textEmbeddingModel' });\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;AAAA,EACvE;AACF;AAGA,IAAM,YAAY,CAAC,QAAgB;AACjC,SAA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FJ,QAAAC;AA8FI,eAAI;AAAA,MACF;AAAA,MACA;AAAA,MACA;AAAA,QACE,UAAU;AAAA,QACV;AAAA,QACA,UAASA,MAAA,QAAQ,YAAR,OAAAA,MAAmB,CAAC;AAAA,QAC7B,OAAO,QAAQ;AAAA,QACf,mBAAmB;AAAA,QACnB,iBAAiB,CAACC,UAAS,gBACzB,GAAGA,QAAO,IAAI,OAAO,IACnB,cAAc,qBAAqB,YACrC;AAAA,QACF,sBAAsB,UAAQ;AAE5B,gBAAM,EAAE,OAAO,GAAG,KAAK,IAAI;AAC3B,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,mBAAmB;AAAA,UACrB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA;AAEF,QAAM,WAAW,SACf,SACA,UACA;AACA,QAAI,YAAY;AACd,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,WAAO,gBAAgB,SAAS,QAAQ;AAAA,EAC1C;AAEA,WAAS,gBAAgB;AACzB,WAAS,OAAO;AAChB,WAAS,WAAW;AACpB,WAAS,qBAAqB,CAAC,YAAoB;AACjD,UAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,qBAAqB,CAAC;AAAA,EACzE;AAEA,WAAS,QAAQ;AAEjB,SAAO;AACT;;;AFtHO,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 AnthropicMessagesModelId,\n} from '@ai-sdk/anthropic/internal';\nimport {\n GoogleVertexAnthropicMessagesModelId,\n GoogleVertexAnthropicMessagesSettings,\n} from './google-vertex-anthropic-messages-settings';\nexport interface GoogleVertexAnthropicProvider extends ProviderV2 {\n /**\nCreates a model for text generation.\n*/\n (\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings?: GoogleVertexAnthropicMessagesSettings,\n ): LanguageModelV2;\n\n /**\nCreates a model for text generation.\n*/\n languageModel(\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings?: GoogleVertexAnthropicMessagesSettings,\n ): 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 = (\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings: GoogleVertexAnthropicMessagesSettings = {},\n ) =>\n new AnthropicMessagesLanguageModel(\n modelId as AnthropicMessagesModelId,\n settings,\n {\n provider: 'vertex.anthropic.messages',\n baseURL,\n headers: options.headers ?? {},\n fetch: options.fetch,\n supportsImageUrls: false,\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 },\n );\n\n const provider = function (\n modelId: GoogleVertexAnthropicMessagesModelId,\n settings?: GoogleVertexAnthropicMessagesSettings,\n ) {\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, settings);\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;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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AA,QACF;AAAA,MACF;AAAA,IACF;AAAA;AAEF,QAAM,WAAW,SACf,SACA,UACA;AACA,QAAI,YAAY;AACd,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,WAAO,gBAAgB,SAAS,QAAQ;AAAA,EAC1C;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;;;AF1HO,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"]}
|
package/dist/index.d.mts
CHANGED
@@ -1,12 +1,9 @@
|
|
1
|
+
import { z } from 'zod';
|
1
2
|
import { GoogleAuthOptions } from 'google-auth-library';
|
2
|
-
import {
|
3
|
+
import { ProviderV2, LanguageModelV2, ImageModelV1 } from '@ai-sdk/provider';
|
3
4
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
4
5
|
import { InternalGoogleGenerativeAISettings } from '@ai-sdk/google/internal';
|
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
|
-
interface GoogleVertexSettings extends InternalGoogleGenerativeAISettings {
|
8
|
-
}
|
9
|
-
|
10
7
|
type GoogleVertexImageModelId = 'imagen-3.0-generate-001' | 'imagen-3.0-fast-generate-001' | (string & {});
|
11
8
|
interface GoogleVertexImageSettings {
|
12
9
|
/**
|
@@ -15,12 +12,37 @@ interface GoogleVertexImageSettings {
|
|
15
12
|
maxImagesPerCall?: number;
|
16
13
|
}
|
17
14
|
|
18
|
-
|
15
|
+
declare const vertexImageProviderOptionsSchema: z.ZodObject<{
|
16
|
+
negativePrompt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
17
|
+
personGeneration: z.ZodOptional<z.ZodNullable<z.ZodEnum<["dont_allow", "allow_adult", "allow_all"]>>>;
|
18
|
+
safetySetting: z.ZodOptional<z.ZodNullable<z.ZodEnum<["block_low_and_above", "block_medium_and_above", "block_only_high", "block_none"]>>>;
|
19
|
+
addWatermark: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
20
|
+
storageUri: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
22
|
+
negativePrompt?: string | null | undefined;
|
23
|
+
personGeneration?: "dont_allow" | "allow_adult" | "allow_all" | null | undefined;
|
24
|
+
safetySetting?: "block_low_and_above" | "block_medium_and_above" | "block_only_high" | "block_none" | null | undefined;
|
25
|
+
addWatermark?: boolean | null | undefined;
|
26
|
+
storageUri?: string | null | undefined;
|
27
|
+
}, {
|
28
|
+
negativePrompt?: string | null | undefined;
|
29
|
+
personGeneration?: "dont_allow" | "allow_adult" | "allow_all" | null | undefined;
|
30
|
+
safetySetting?: "block_low_and_above" | "block_medium_and_above" | "block_only_high" | "block_none" | null | undefined;
|
31
|
+
addWatermark?: boolean | null | undefined;
|
32
|
+
storageUri?: string | null | undefined;
|
33
|
+
}>;
|
34
|
+
type GoogleVertexImageProviderOptions = z.infer<typeof vertexImageProviderOptionsSchema>;
|
35
|
+
|
36
|
+
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 & {});
|
37
|
+
interface GoogleVertexSettings extends InternalGoogleGenerativeAISettings {
|
38
|
+
}
|
39
|
+
|
40
|
+
interface GoogleVertexProvider extends ProviderV2 {
|
19
41
|
/**
|
20
42
|
Creates a model for text generation.
|
21
43
|
*/
|
22
|
-
(modelId: GoogleVertexModelId, settings?: GoogleVertexSettings):
|
23
|
-
languageModel: (modelId: GoogleVertexModelId, settings?: GoogleVertexSettings) =>
|
44
|
+
(modelId: GoogleVertexModelId, settings?: GoogleVertexSettings): LanguageModelV2;
|
45
|
+
languageModel: (modelId: GoogleVertexModelId, settings?: GoogleVertexSettings) => LanguageModelV2;
|
24
46
|
/**
|
25
47
|
* Creates a model for image generation.
|
26
48
|
*/
|
@@ -75,4 +97,4 @@ Default Google Vertex AI provider instance.
|
|
75
97
|
*/
|
76
98
|
declare const vertex: GoogleVertexProvider;
|
77
99
|
|
78
|
-
export { type GoogleVertexProvider, type GoogleVertexProviderSettings, createVertex, vertex };
|
100
|
+
export { type GoogleVertexImageProviderOptions, type GoogleVertexProvider, type GoogleVertexProviderSettings, createVertex, vertex };
|
package/dist/index.d.ts
CHANGED
@@ -1,12 +1,9 @@
|
|
1
|
+
import { z } from 'zod';
|
1
2
|
import { GoogleAuthOptions } from 'google-auth-library';
|
2
|
-
import {
|
3
|
+
import { ProviderV2, LanguageModelV2, ImageModelV1 } from '@ai-sdk/provider';
|
3
4
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
4
5
|
import { InternalGoogleGenerativeAISettings } from '@ai-sdk/google/internal';
|
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
|
-
interface GoogleVertexSettings extends InternalGoogleGenerativeAISettings {
|
8
|
-
}
|
9
|
-
|
10
7
|
type GoogleVertexImageModelId = 'imagen-3.0-generate-001' | 'imagen-3.0-fast-generate-001' | (string & {});
|
11
8
|
interface GoogleVertexImageSettings {
|
12
9
|
/**
|
@@ -15,12 +12,37 @@ interface GoogleVertexImageSettings {
|
|
15
12
|
maxImagesPerCall?: number;
|
16
13
|
}
|
17
14
|
|
18
|
-
|
15
|
+
declare const vertexImageProviderOptionsSchema: z.ZodObject<{
|
16
|
+
negativePrompt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
17
|
+
personGeneration: z.ZodOptional<z.ZodNullable<z.ZodEnum<["dont_allow", "allow_adult", "allow_all"]>>>;
|
18
|
+
safetySetting: z.ZodOptional<z.ZodNullable<z.ZodEnum<["block_low_and_above", "block_medium_and_above", "block_only_high", "block_none"]>>>;
|
19
|
+
addWatermark: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
20
|
+
storageUri: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
22
|
+
negativePrompt?: string | null | undefined;
|
23
|
+
personGeneration?: "dont_allow" | "allow_adult" | "allow_all" | null | undefined;
|
24
|
+
safetySetting?: "block_low_and_above" | "block_medium_and_above" | "block_only_high" | "block_none" | null | undefined;
|
25
|
+
addWatermark?: boolean | null | undefined;
|
26
|
+
storageUri?: string | null | undefined;
|
27
|
+
}, {
|
28
|
+
negativePrompt?: string | null | undefined;
|
29
|
+
personGeneration?: "dont_allow" | "allow_adult" | "allow_all" | null | undefined;
|
30
|
+
safetySetting?: "block_low_and_above" | "block_medium_and_above" | "block_only_high" | "block_none" | null | undefined;
|
31
|
+
addWatermark?: boolean | null | undefined;
|
32
|
+
storageUri?: string | null | undefined;
|
33
|
+
}>;
|
34
|
+
type GoogleVertexImageProviderOptions = z.infer<typeof vertexImageProviderOptionsSchema>;
|
35
|
+
|
36
|
+
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 & {});
|
37
|
+
interface GoogleVertexSettings extends InternalGoogleGenerativeAISettings {
|
38
|
+
}
|
39
|
+
|
40
|
+
interface GoogleVertexProvider extends ProviderV2 {
|
19
41
|
/**
|
20
42
|
Creates a model for text generation.
|
21
43
|
*/
|
22
|
-
(modelId: GoogleVertexModelId, settings?: GoogleVertexSettings):
|
23
|
-
languageModel: (modelId: GoogleVertexModelId, settings?: GoogleVertexSettings) =>
|
44
|
+
(modelId: GoogleVertexModelId, settings?: GoogleVertexSettings): LanguageModelV2;
|
45
|
+
languageModel: (modelId: GoogleVertexModelId, settings?: GoogleVertexSettings) => LanguageModelV2;
|
24
46
|
/**
|
25
47
|
* Creates a model for image generation.
|
26
48
|
*/
|
@@ -75,4 +97,4 @@ Default Google Vertex AI provider instance.
|
|
75
97
|
*/
|
76
98
|
declare const vertex: GoogleVertexProvider;
|
77
99
|
|
78
|
-
export { type GoogleVertexProvider, type GoogleVertexProviderSettings, createVertex, vertex };
|
100
|
+
export { type GoogleVertexImageProviderOptions, type GoogleVertexProvider, type GoogleVertexProviderSettings, createVertex, vertex };
|
package/dist/index.js
CHANGED
@@ -182,7 +182,7 @@ var GoogleVertexImageModel = class {
|
|
182
182
|
headers,
|
183
183
|
abortSignal
|
184
184
|
}) {
|
185
|
-
var _a, _b, _c, _d, _e
|
185
|
+
var _a, _b, _c, _d, _e;
|
186
186
|
const warnings = [];
|
187
187
|
if (size != null) {
|
188
188
|
warnings.push({
|
@@ -191,16 +191,21 @@ var GoogleVertexImageModel = class {
|
|
191
191
|
details: "This model does not support the `size` option. Use `aspectRatio` instead."
|
192
192
|
});
|
193
193
|
}
|
194
|
+
const vertexImageOptions = (0, import_provider_utils3.parseProviderOptions)({
|
195
|
+
provider: "vertex",
|
196
|
+
providerOptions,
|
197
|
+
schema: vertexImageProviderOptionsSchema
|
198
|
+
});
|
194
199
|
const body = {
|
195
200
|
instances: [{ prompt }],
|
196
201
|
parameters: {
|
197
202
|
sampleCount: n,
|
198
203
|
...aspectRatio != null ? { aspectRatio } : {},
|
199
204
|
...seed != null ? { seed } : {},
|
200
|
-
...
|
205
|
+
...vertexImageOptions != null ? vertexImageOptions : {}
|
201
206
|
}
|
202
207
|
};
|
203
|
-
const currentDate = (
|
208
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
204
209
|
const { value: response, responseHeaders } = await (0, import_provider_utils3.postJsonToApi)({
|
205
210
|
url: `${this.config.baseURL}/models/${this.modelId}:predict`,
|
206
211
|
headers: (0, import_provider_utils3.combineHeaders)(await (0, import_provider_utils3.resolve)(this.config.headers), headers),
|
@@ -213,9 +218,9 @@ var GoogleVertexImageModel = class {
|
|
213
218
|
fetch: this.config.fetch
|
214
219
|
});
|
215
220
|
return {
|
216
|
-
images: (
|
221
|
+
images: (_e = (_d = response.predictions) == null ? void 0 : _d.map(
|
217
222
|
(p) => p.bytesBase64Encoded
|
218
|
-
)) != null ?
|
223
|
+
)) != null ? _e : [],
|
219
224
|
warnings,
|
220
225
|
response: {
|
221
226
|
timestamp: currentDate,
|
@@ -228,6 +233,18 @@ var GoogleVertexImageModel = class {
|
|
228
233
|
var vertexImageResponseSchema = import_zod3.z.object({
|
229
234
|
predictions: import_zod3.z.array(import_zod3.z.object({ bytesBase64Encoded: import_zod3.z.string() })).nullish()
|
230
235
|
});
|
236
|
+
var vertexImageProviderOptionsSchema = import_zod3.z.object({
|
237
|
+
negativePrompt: import_zod3.z.string().nullish(),
|
238
|
+
personGeneration: import_zod3.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
239
|
+
safetySetting: import_zod3.z.enum([
|
240
|
+
"block_low_and_above",
|
241
|
+
"block_medium_and_above",
|
242
|
+
"block_only_high",
|
243
|
+
"block_none"
|
244
|
+
]).nullish(),
|
245
|
+
addWatermark: import_zod3.z.boolean().nullish(),
|
246
|
+
storageUri: import_zod3.z.string().nullish()
|
247
|
+
});
|
231
248
|
|
232
249
|
// src/google-vertex-supported-file-url.ts
|
233
250
|
function isSupportedFileUrl(url) {
|