@ai-sdk/google-vertex 5.0.0-beta.5 → 5.0.0-beta.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +430 -8
- package/README.md +65 -1
- package/dist/anthropic/edge/index.d.ts +61 -16
- package/dist/anthropic/edge/index.js +67 -60
- package/dist/anthropic/edge/index.js.map +1 -1
- package/dist/anthropic/index.d.ts +61 -16
- package/dist/anthropic/index.js +57 -55
- package/dist/anthropic/index.js.map +1 -1
- package/dist/edge/index.d.ts +31 -22
- package/dist/edge/index.js +217 -176
- package/dist/edge/index.js.map +1 -1
- package/dist/index.d.ts +31 -22
- package/dist/index.js +208 -173
- package/dist/index.js.map +1 -1
- package/dist/maas/edge/index.d.ts +76 -0
- package/dist/maas/edge/index.js +196 -0
- package/dist/maas/edge/index.js.map +1 -0
- package/dist/maas/index.d.ts +60 -0
- package/dist/maas/index.js +101 -0
- package/dist/maas/index.js.map +1 -0
- package/docs/16-google-vertex.mdx +226 -6
- package/maas/edge.d.ts +1 -0
- package/maas/index.d.ts +1 -0
- package/package.json +29 -18
- package/src/anthropic/edge/google-vertex-anthropic-provider-edge.ts +1 -2
- package/src/anthropic/google-vertex-anthropic-messages-options.ts +1 -0
- package/src/anthropic/google-vertex-anthropic-provider-node.ts +1 -2
- package/src/anthropic/google-vertex-anthropic-provider.ts +33 -8
- package/src/edge/google-vertex-provider-edge.ts +1 -2
- package/src/google-vertex-config.ts +1 -1
- package/src/google-vertex-embedding-model.ts +23 -6
- package/src/google-vertex-embedding-options.ts +2 -0
- package/src/google-vertex-image-model.ts +38 -18
- package/src/google-vertex-options.ts +0 -1
- package/src/google-vertex-provider-node.ts +1 -2
- package/src/google-vertex-provider.ts +12 -12
- package/src/google-vertex-video-model.ts +7 -7
- package/src/maas/edge/google-vertex-maas-provider-edge.ts +65 -0
- package/src/maas/edge/index.ts +9 -0
- package/src/maas/google-vertex-maas-options.ts +15 -0
- package/src/maas/google-vertex-maas-provider-node.ts +64 -0
- package/src/maas/google-vertex-maas-provider.ts +111 -0
- package/src/maas/index.ts +9 -0
- package/dist/anthropic/edge/index.d.mts +0 -231
- package/dist/anthropic/edge/index.mjs +0 -259
- package/dist/anthropic/edge/index.mjs.map +0 -1
- package/dist/anthropic/index.d.mts +0 -215
- package/dist/anthropic/index.mjs +0 -164
- package/dist/anthropic/index.mjs.map +0 -1
- package/dist/edge/index.d.mts +0 -160
- package/dist/edge/index.mjs +0 -1049
- package/dist/edge/index.mjs.map +0 -1
- package/dist/index.d.mts +0 -219
- package/dist/index.mjs +0 -960
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,41 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
VERSION: () => VERSION,
|
|
24
|
-
createVertex: () => createVertex2,
|
|
25
|
-
vertex: () => vertex
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(src_exports);
|
|
28
|
-
|
|
29
1
|
// src/google-vertex-provider-node.ts
|
|
30
|
-
|
|
2
|
+
import { loadOptionalSetting as loadOptionalSetting2, resolve as resolve5 } from "@ai-sdk/provider-utils";
|
|
31
3
|
|
|
32
4
|
// src/google-vertex-auth-google-auth-library.ts
|
|
33
|
-
|
|
5
|
+
import { GoogleAuth } from "google-auth-library";
|
|
34
6
|
var authInstance = null;
|
|
35
7
|
var authOptions = null;
|
|
36
8
|
function getAuth(options) {
|
|
37
9
|
if (!authInstance || options !== authOptions) {
|
|
38
|
-
authInstance = new
|
|
10
|
+
authInstance = new GoogleAuth({
|
|
39
11
|
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
|
|
40
12
|
...options
|
|
41
13
|
});
|
|
@@ -51,28 +23,47 @@ async function generateAuthToken(options) {
|
|
|
51
23
|
}
|
|
52
24
|
|
|
53
25
|
// src/google-vertex-provider.ts
|
|
54
|
-
|
|
55
|
-
|
|
26
|
+
import { GoogleGenerativeAILanguageModel as GoogleGenerativeAILanguageModel2 } from "@ai-sdk/google/internal";
|
|
27
|
+
import {
|
|
28
|
+
generateId,
|
|
29
|
+
loadOptionalSetting,
|
|
30
|
+
loadSetting,
|
|
31
|
+
normalizeHeaders,
|
|
32
|
+
resolve as resolve4,
|
|
33
|
+
withoutTrailingSlash,
|
|
34
|
+
withUserAgentSuffix
|
|
35
|
+
} from "@ai-sdk/provider-utils";
|
|
56
36
|
|
|
57
37
|
// src/version.ts
|
|
58
|
-
var VERSION = true ? "5.0.0-beta.
|
|
38
|
+
var VERSION = true ? "5.0.0-beta.52" : "0.0.0-test";
|
|
59
39
|
|
|
60
40
|
// src/google-vertex-embedding-model.ts
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
41
|
+
import {
|
|
42
|
+
TooManyEmbeddingValuesForCallError
|
|
43
|
+
} from "@ai-sdk/provider";
|
|
44
|
+
import {
|
|
45
|
+
combineHeaders,
|
|
46
|
+
createJsonResponseHandler,
|
|
47
|
+
postJsonToApi,
|
|
48
|
+
resolve,
|
|
49
|
+
parseProviderOptions,
|
|
50
|
+
serializeModelOptions,
|
|
51
|
+
WORKFLOW_SERIALIZE,
|
|
52
|
+
WORKFLOW_DESERIALIZE
|
|
53
|
+
} from "@ai-sdk/provider-utils";
|
|
54
|
+
import { z as z3 } from "zod/v4";
|
|
64
55
|
|
|
65
56
|
// src/google-vertex-error.ts
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
var googleVertexErrorDataSchema =
|
|
69
|
-
error:
|
|
70
|
-
code:
|
|
71
|
-
message:
|
|
72
|
-
status:
|
|
57
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
58
|
+
import { z } from "zod/v4";
|
|
59
|
+
var googleVertexErrorDataSchema = z.object({
|
|
60
|
+
error: z.object({
|
|
61
|
+
code: z.number().nullable(),
|
|
62
|
+
message: z.string(),
|
|
63
|
+
status: z.string()
|
|
73
64
|
})
|
|
74
65
|
});
|
|
75
|
-
var googleVertexFailedResponseHandler =
|
|
66
|
+
var googleVertexFailedResponseHandler = createJsonErrorResponseHandler(
|
|
76
67
|
{
|
|
77
68
|
errorSchema: googleVertexErrorDataSchema,
|
|
78
69
|
errorToMessage: (data) => data.error.message
|
|
@@ -80,13 +71,13 @@ var googleVertexFailedResponseHandler = (0, import_provider_utils.createJsonErro
|
|
|
80
71
|
);
|
|
81
72
|
|
|
82
73
|
// src/google-vertex-embedding-options.ts
|
|
83
|
-
|
|
84
|
-
var googleVertexEmbeddingModelOptions =
|
|
74
|
+
import { z as z2 } from "zod/v4";
|
|
75
|
+
var googleVertexEmbeddingModelOptions = z2.object({
|
|
85
76
|
/**
|
|
86
77
|
* Optional. Optional reduced dimension for the output embedding.
|
|
87
78
|
* If set, excessive values in the output embedding are truncated from the end.
|
|
88
79
|
*/
|
|
89
|
-
outputDimensionality:
|
|
80
|
+
outputDimensionality: z2.number().optional(),
|
|
90
81
|
/**
|
|
91
82
|
* Optional. Specifies the task type for generating embeddings.
|
|
92
83
|
* Supported task types:
|
|
@@ -99,7 +90,7 @@ var googleVertexEmbeddingModelOptions = import_v42.z.object({
|
|
|
99
90
|
* - FACT_VERIFICATION: Optimized for verifying factual information.
|
|
100
91
|
* - CODE_RETRIEVAL_QUERY: Optimized for retrieving code blocks based on natural language queries.
|
|
101
92
|
*/
|
|
102
|
-
taskType:
|
|
93
|
+
taskType: z2.enum([
|
|
103
94
|
"SEMANTIC_SIMILARITY",
|
|
104
95
|
"CLASSIFICATION",
|
|
105
96
|
"CLUSTERING",
|
|
@@ -114,23 +105,32 @@ var googleVertexEmbeddingModelOptions = import_v42.z.object({
|
|
|
114
105
|
* Only valid when task_type is set to 'RETRIEVAL_DOCUMENT'.
|
|
115
106
|
* Helps the model produce better embeddings by providing additional context.
|
|
116
107
|
*/
|
|
117
|
-
title:
|
|
108
|
+
title: z2.string().optional(),
|
|
118
109
|
/**
|
|
119
110
|
* Optional. When set to true, input text will be truncated. When set to false,
|
|
120
111
|
* an error is returned if the input text is longer than the maximum length supported by the model. Defaults to true.
|
|
121
112
|
*/
|
|
122
|
-
autoTruncate:
|
|
113
|
+
autoTruncate: z2.boolean().optional()
|
|
123
114
|
});
|
|
124
115
|
|
|
125
116
|
// src/google-vertex-embedding-model.ts
|
|
126
|
-
var GoogleVertexEmbeddingModel = class {
|
|
117
|
+
var GoogleVertexEmbeddingModel = class _GoogleVertexEmbeddingModel {
|
|
127
118
|
constructor(modelId, config) {
|
|
128
|
-
this.specificationVersion = "
|
|
119
|
+
this.specificationVersion = "v4";
|
|
129
120
|
this.maxEmbeddingsPerCall = 2048;
|
|
130
121
|
this.supportsParallelCalls = true;
|
|
131
122
|
this.modelId = modelId;
|
|
132
123
|
this.config = config;
|
|
133
124
|
}
|
|
125
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
126
|
+
return serializeModelOptions({
|
|
127
|
+
modelId: model.modelId,
|
|
128
|
+
config: model.config
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
132
|
+
return new _GoogleVertexEmbeddingModel(options.modelId, options.config);
|
|
133
|
+
}
|
|
134
134
|
get provider() {
|
|
135
135
|
return this.config.provider;
|
|
136
136
|
}
|
|
@@ -140,13 +140,13 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
140
140
|
abortSignal,
|
|
141
141
|
providerOptions
|
|
142
142
|
}) {
|
|
143
|
-
let googleOptions = await
|
|
143
|
+
let googleOptions = await parseProviderOptions({
|
|
144
144
|
provider: "vertex",
|
|
145
145
|
providerOptions,
|
|
146
146
|
schema: googleVertexEmbeddingModelOptions
|
|
147
147
|
});
|
|
148
148
|
if (googleOptions == null) {
|
|
149
|
-
googleOptions = await
|
|
149
|
+
googleOptions = await parseProviderOptions({
|
|
150
150
|
provider: "google",
|
|
151
151
|
providerOptions,
|
|
152
152
|
schema: googleVertexEmbeddingModelOptions
|
|
@@ -154,15 +154,15 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
154
154
|
}
|
|
155
155
|
googleOptions = googleOptions != null ? googleOptions : {};
|
|
156
156
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
157
|
-
throw new
|
|
157
|
+
throw new TooManyEmbeddingValuesForCallError({
|
|
158
158
|
provider: this.provider,
|
|
159
159
|
modelId: this.modelId,
|
|
160
160
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
161
161
|
values
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
|
-
const mergedHeaders =
|
|
165
|
-
await
|
|
164
|
+
const mergedHeaders = combineHeaders(
|
|
165
|
+
this.config.headers ? await resolve(this.config.headers) : void 0,
|
|
166
166
|
headers
|
|
167
167
|
);
|
|
168
168
|
const url = `${this.config.baseURL}/models/${this.modelId}:predict`;
|
|
@@ -170,7 +170,7 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
170
170
|
responseHeaders,
|
|
171
171
|
value: response,
|
|
172
172
|
rawValue
|
|
173
|
-
} = await
|
|
173
|
+
} = await postJsonToApi({
|
|
174
174
|
url,
|
|
175
175
|
headers: mergedHeaders,
|
|
176
176
|
body: {
|
|
@@ -185,7 +185,7 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
185
185
|
}
|
|
186
186
|
},
|
|
187
187
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
188
|
-
successfulResponseHandler:
|
|
188
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
189
189
|
googleVertexTextEmbeddingResponseSchema
|
|
190
190
|
),
|
|
191
191
|
abortSignal,
|
|
@@ -206,13 +206,13 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
206
206
|
};
|
|
207
207
|
}
|
|
208
208
|
};
|
|
209
|
-
var googleVertexTextEmbeddingResponseSchema =
|
|
210
|
-
predictions:
|
|
211
|
-
|
|
212
|
-
embeddings:
|
|
213
|
-
values:
|
|
214
|
-
statistics:
|
|
215
|
-
token_count:
|
|
209
|
+
var googleVertexTextEmbeddingResponseSchema = z3.object({
|
|
210
|
+
predictions: z3.array(
|
|
211
|
+
z3.object({
|
|
212
|
+
embeddings: z3.object({
|
|
213
|
+
values: z3.array(z3.number()),
|
|
214
|
+
statistics: z3.object({
|
|
215
|
+
token_count: z3.number()
|
|
216
216
|
})
|
|
217
217
|
})
|
|
218
218
|
})
|
|
@@ -220,14 +220,35 @@ var googleVertexTextEmbeddingResponseSchema = import_v43.z.object({
|
|
|
220
220
|
});
|
|
221
221
|
|
|
222
222
|
// src/google-vertex-image-model.ts
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
223
|
+
import { GoogleGenerativeAILanguageModel } from "@ai-sdk/google/internal";
|
|
224
|
+
import {
|
|
225
|
+
combineHeaders as combineHeaders2,
|
|
226
|
+
convertToBase64,
|
|
227
|
+
convertUint8ArrayToBase64,
|
|
228
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
229
|
+
generateId as defaultGenerateId,
|
|
230
|
+
parseProviderOptions as parseProviderOptions2,
|
|
231
|
+
postJsonToApi as postJsonToApi2,
|
|
232
|
+
resolve as resolve2,
|
|
233
|
+
serializeModelOptions as serializeModelOptions2,
|
|
234
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
|
|
235
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
|
|
236
|
+
} from "@ai-sdk/provider-utils";
|
|
237
|
+
import { z as z4 } from "zod/v4";
|
|
238
|
+
var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
227
239
|
constructor(modelId, config) {
|
|
228
240
|
this.modelId = modelId;
|
|
229
241
|
this.config = config;
|
|
230
|
-
this.specificationVersion = "
|
|
242
|
+
this.specificationVersion = "v4";
|
|
243
|
+
}
|
|
244
|
+
static [WORKFLOW_SERIALIZE2](model) {
|
|
245
|
+
return serializeModelOptions2({
|
|
246
|
+
modelId: model.modelId,
|
|
247
|
+
config: model.config
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
static [WORKFLOW_DESERIALIZE2](options) {
|
|
251
|
+
return new _GoogleVertexImageModel(options.modelId, options.config);
|
|
231
252
|
}
|
|
232
253
|
get maxImagesPerCall() {
|
|
233
254
|
if (isGeminiModel(this.modelId)) {
|
|
@@ -265,7 +286,7 @@ var GoogleVertexImageModel = class {
|
|
|
265
286
|
details: "This model does not support the `size` option. Use `aspectRatio` instead."
|
|
266
287
|
});
|
|
267
288
|
}
|
|
268
|
-
const vertexImageOptions = await (
|
|
289
|
+
const vertexImageOptions = await parseProviderOptions2({
|
|
269
290
|
provider: "vertex",
|
|
270
291
|
providerOptions,
|
|
271
292
|
schema: googleVertexImageModelOptionsSchema
|
|
@@ -327,12 +348,15 @@ var GoogleVertexImageModel = class {
|
|
|
327
348
|
};
|
|
328
349
|
}
|
|
329
350
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
330
|
-
const { value: response, responseHeaders } = await (
|
|
351
|
+
const { value: response, responseHeaders } = await postJsonToApi2({
|
|
331
352
|
url: `${this.config.baseURL}/models/${this.modelId}:predict`,
|
|
332
|
-
headers: (
|
|
353
|
+
headers: combineHeaders2(
|
|
354
|
+
this.config.headers ? await resolve2(this.config.headers) : void 0,
|
|
355
|
+
headers
|
|
356
|
+
),
|
|
333
357
|
body,
|
|
334
358
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
335
|
-
successfulResponseHandler: (
|
|
359
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
336
360
|
vertexImageResponseSchema
|
|
337
361
|
),
|
|
338
362
|
abortSignal,
|
|
@@ -416,12 +440,12 @@ var GoogleVertexImageModel = class {
|
|
|
416
440
|
const languageModelPrompt = [
|
|
417
441
|
{ role: "user", content: userContent }
|
|
418
442
|
];
|
|
419
|
-
const languageModel = new
|
|
443
|
+
const languageModel = new GoogleGenerativeAILanguageModel(this.modelId, {
|
|
420
444
|
provider: this.config.provider,
|
|
421
445
|
baseURL: this.config.baseURL,
|
|
422
446
|
headers: (_a = this.config.headers) != null ? _a : {},
|
|
423
447
|
fetch: this.config.fetch,
|
|
424
|
-
generateId: (_b = this.config.generateId) != null ? _b :
|
|
448
|
+
generateId: (_b = this.config.generateId) != null ? _b : defaultGenerateId,
|
|
425
449
|
supportedUrls: () => ({
|
|
426
450
|
"*": [/^https?:\/\/.*$/, /^gs:\/\/.*$/]
|
|
427
451
|
})
|
|
@@ -445,7 +469,7 @@ var GoogleVertexImageModel = class {
|
|
|
445
469
|
const images = [];
|
|
446
470
|
for (const part of result.content) {
|
|
447
471
|
if (part.type === "file" && part.mediaType.startsWith("image/")) {
|
|
448
|
-
images.push(
|
|
472
|
+
images.push(convertToBase64(part.data));
|
|
449
473
|
}
|
|
450
474
|
}
|
|
451
475
|
return {
|
|
@@ -472,41 +496,41 @@ var GoogleVertexImageModel = class {
|
|
|
472
496
|
function isGeminiModel(modelId) {
|
|
473
497
|
return modelId.startsWith("gemini-");
|
|
474
498
|
}
|
|
475
|
-
var vertexImageResponseSchema =
|
|
476
|
-
predictions:
|
|
477
|
-
|
|
478
|
-
bytesBase64Encoded:
|
|
479
|
-
mimeType:
|
|
480
|
-
prompt:
|
|
499
|
+
var vertexImageResponseSchema = z4.object({
|
|
500
|
+
predictions: z4.array(
|
|
501
|
+
z4.object({
|
|
502
|
+
bytesBase64Encoded: z4.string(),
|
|
503
|
+
mimeType: z4.string(),
|
|
504
|
+
prompt: z4.string().nullish()
|
|
481
505
|
})
|
|
482
506
|
).nullish()
|
|
483
507
|
});
|
|
484
|
-
var googleVertexImageModelOptionsSchema =
|
|
485
|
-
negativePrompt:
|
|
486
|
-
personGeneration:
|
|
487
|
-
safetySetting:
|
|
508
|
+
var googleVertexImageModelOptionsSchema = z4.object({
|
|
509
|
+
negativePrompt: z4.string().nullish(),
|
|
510
|
+
personGeneration: z4.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
511
|
+
safetySetting: z4.enum([
|
|
488
512
|
"block_low_and_above",
|
|
489
513
|
"block_medium_and_above",
|
|
490
514
|
"block_only_high",
|
|
491
515
|
"block_none"
|
|
492
516
|
]).nullish(),
|
|
493
|
-
addWatermark:
|
|
494
|
-
storageUri:
|
|
495
|
-
sampleImageSize:
|
|
517
|
+
addWatermark: z4.boolean().nullish(),
|
|
518
|
+
storageUri: z4.string().nullish(),
|
|
519
|
+
sampleImageSize: z4.enum(["1K", "2K"]).nullish(),
|
|
496
520
|
/**
|
|
497
521
|
* Configuration for image editing operations
|
|
498
522
|
*/
|
|
499
|
-
edit:
|
|
523
|
+
edit: z4.object({
|
|
500
524
|
/**
|
|
501
525
|
* An integer that represents the number of sampling steps.
|
|
502
526
|
* A higher value offers better image quality, a lower value offers better latency.
|
|
503
527
|
* Try 35 steps to start. If the quality doesn't meet your requirements,
|
|
504
528
|
* increase the value towards an upper limit of 75.
|
|
505
529
|
*/
|
|
506
|
-
baseSteps:
|
|
530
|
+
baseSteps: z4.number().nullish(),
|
|
507
531
|
// Edit mode options
|
|
508
532
|
// https://cloud.google.com/vertex-ai/generative-ai/docs/image/edit-insert-objects
|
|
509
|
-
mode:
|
|
533
|
+
mode: z4.enum([
|
|
510
534
|
"EDIT_MODE_INPAINT_INSERTION",
|
|
511
535
|
"EDIT_MODE_INPAINT_REMOVAL",
|
|
512
536
|
"EDIT_MODE_OUTPAINT",
|
|
@@ -522,7 +546,7 @@ var googleVertexImageModelOptionsSchema = import_v44.z.object({
|
|
|
522
546
|
* - `MASK_MODE_CLOTHING_AREA` - Masks from segmenting the clothing area with open-vocab segmentation.
|
|
523
547
|
* - `MASK_MODE_PARSED_PERSON` - Masks from segmenting the person body and clothing using the person-parsing model.
|
|
524
548
|
*/
|
|
525
|
-
maskMode:
|
|
549
|
+
maskMode: z4.enum([
|
|
526
550
|
"MASK_MODE_DEFAULT",
|
|
527
551
|
"MASK_MODE_USER_PROVIDED",
|
|
528
552
|
"MASK_MODE_DETECTION_BOX",
|
|
@@ -534,7 +558,7 @@ var googleVertexImageModelOptionsSchema = import_v44.z.object({
|
|
|
534
558
|
* percentage of the image width to grow the mask by. Using dilation helps
|
|
535
559
|
* compensate for imprecise masks. We recommend a value of 0.01.
|
|
536
560
|
*/
|
|
537
|
-
maskDilation:
|
|
561
|
+
maskDilation: z4.number().nullish()
|
|
538
562
|
}).nullish()
|
|
539
563
|
});
|
|
540
564
|
function getBase64Data(file) {
|
|
@@ -546,30 +570,42 @@ function getBase64Data(file) {
|
|
|
546
570
|
if (typeof file.data === "string") {
|
|
547
571
|
return file.data;
|
|
548
572
|
}
|
|
549
|
-
return
|
|
573
|
+
return convertUint8ArrayToBase64(file.data);
|
|
550
574
|
}
|
|
551
575
|
|
|
552
576
|
// src/google-vertex-tools.ts
|
|
553
|
-
|
|
577
|
+
import { googleTools } from "@ai-sdk/google/internal";
|
|
554
578
|
var googleVertexTools = {
|
|
555
|
-
googleSearch:
|
|
556
|
-
enterpriseWebSearch:
|
|
557
|
-
googleMaps:
|
|
558
|
-
urlContext:
|
|
559
|
-
fileSearch:
|
|
560
|
-
codeExecution:
|
|
561
|
-
vertexRagStore:
|
|
579
|
+
googleSearch: googleTools.googleSearch,
|
|
580
|
+
enterpriseWebSearch: googleTools.enterpriseWebSearch,
|
|
581
|
+
googleMaps: googleTools.googleMaps,
|
|
582
|
+
urlContext: googleTools.urlContext,
|
|
583
|
+
fileSearch: googleTools.fileSearch,
|
|
584
|
+
codeExecution: googleTools.codeExecution,
|
|
585
|
+
vertexRagStore: googleTools.vertexRagStore
|
|
562
586
|
};
|
|
563
587
|
|
|
564
588
|
// src/google-vertex-video-model.ts
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
589
|
+
import {
|
|
590
|
+
AISDKError
|
|
591
|
+
} from "@ai-sdk/provider";
|
|
592
|
+
import {
|
|
593
|
+
combineHeaders as combineHeaders3,
|
|
594
|
+
convertUint8ArrayToBase64 as convertUint8ArrayToBase642,
|
|
595
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
596
|
+
delay,
|
|
597
|
+
lazySchema,
|
|
598
|
+
parseProviderOptions as parseProviderOptions3,
|
|
599
|
+
postJsonToApi as postJsonToApi3,
|
|
600
|
+
resolve as resolve3,
|
|
601
|
+
zodSchema
|
|
602
|
+
} from "@ai-sdk/provider-utils";
|
|
603
|
+
import { z as z5 } from "zod/v4";
|
|
568
604
|
var GoogleVertexVideoModel = class {
|
|
569
605
|
constructor(modelId, config) {
|
|
570
606
|
this.modelId = modelId;
|
|
571
607
|
this.config = config;
|
|
572
|
-
this.specificationVersion = "
|
|
608
|
+
this.specificationVersion = "v4";
|
|
573
609
|
}
|
|
574
610
|
get provider() {
|
|
575
611
|
return this.config.provider;
|
|
@@ -581,7 +617,7 @@ var GoogleVertexVideoModel = class {
|
|
|
581
617
|
var _a, _b, _c, _d, _e, _f;
|
|
582
618
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
583
619
|
const warnings = [];
|
|
584
|
-
const vertexOptions = await (
|
|
620
|
+
const vertexOptions = await parseProviderOptions3({
|
|
585
621
|
provider: "vertex",
|
|
586
622
|
providerOptions: options.providerOptions,
|
|
587
623
|
schema: googleVertexVideoModelOptionsSchema
|
|
@@ -599,7 +635,7 @@ var GoogleVertexVideoModel = class {
|
|
|
599
635
|
details: "Vertex AI video models require base64-encoded images or GCS URIs. URL will be ignored."
|
|
600
636
|
});
|
|
601
637
|
} else {
|
|
602
|
-
const base64Data = typeof options.image.data === "string" ? options.image.data : (
|
|
638
|
+
const base64Data = typeof options.image.data === "string" ? options.image.data : convertUint8ArrayToBase642(options.image.data);
|
|
603
639
|
instance.image = {
|
|
604
640
|
bytesBase64Encoded: base64Data,
|
|
605
641
|
mimeType: options.image.mediaType
|
|
@@ -657,17 +693,17 @@ var GoogleVertexVideoModel = class {
|
|
|
657
693
|
}
|
|
658
694
|
}
|
|
659
695
|
}
|
|
660
|
-
const { value: operation } = await (
|
|
696
|
+
const { value: operation } = await postJsonToApi3({
|
|
661
697
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
662
|
-
headers: (
|
|
663
|
-
await (
|
|
698
|
+
headers: combineHeaders3(
|
|
699
|
+
await resolve3(this.config.headers),
|
|
664
700
|
options.headers
|
|
665
701
|
),
|
|
666
702
|
body: {
|
|
667
703
|
instances,
|
|
668
704
|
parameters
|
|
669
705
|
},
|
|
670
|
-
successfulResponseHandler: (
|
|
706
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
671
707
|
vertexOperationSchema
|
|
672
708
|
),
|
|
673
709
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
@@ -676,7 +712,7 @@ var GoogleVertexVideoModel = class {
|
|
|
676
712
|
});
|
|
677
713
|
const operationName = operation.name;
|
|
678
714
|
if (!operationName) {
|
|
679
|
-
throw new
|
|
715
|
+
throw new AISDKError({
|
|
680
716
|
name: "VERTEX_VIDEO_GENERATION_ERROR",
|
|
681
717
|
message: "No operation name returned from API"
|
|
682
718
|
});
|
|
@@ -688,28 +724,28 @@ var GoogleVertexVideoModel = class {
|
|
|
688
724
|
let responseHeaders;
|
|
689
725
|
while (!finalOperation.done) {
|
|
690
726
|
if (Date.now() - startTime > pollTimeoutMs) {
|
|
691
|
-
throw new
|
|
727
|
+
throw new AISDKError({
|
|
692
728
|
name: "VERTEX_VIDEO_GENERATION_TIMEOUT",
|
|
693
729
|
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
694
730
|
});
|
|
695
731
|
}
|
|
696
|
-
await
|
|
732
|
+
await delay(pollIntervalMs);
|
|
697
733
|
if ((_f = options.abortSignal) == null ? void 0 : _f.aborted) {
|
|
698
|
-
throw new
|
|
734
|
+
throw new AISDKError({
|
|
699
735
|
name: "VERTEX_VIDEO_GENERATION_ABORTED",
|
|
700
736
|
message: "Video generation request was aborted"
|
|
701
737
|
});
|
|
702
738
|
}
|
|
703
|
-
const { value: statusOperation, responseHeaders: pollHeaders } = await (
|
|
739
|
+
const { value: statusOperation, responseHeaders: pollHeaders } = await postJsonToApi3({
|
|
704
740
|
url: `${this.config.baseURL}/models/${this.modelId}:fetchPredictOperation`,
|
|
705
|
-
headers: (
|
|
706
|
-
await (
|
|
741
|
+
headers: combineHeaders3(
|
|
742
|
+
await resolve3(this.config.headers),
|
|
707
743
|
options.headers
|
|
708
744
|
),
|
|
709
745
|
body: {
|
|
710
746
|
operationName
|
|
711
747
|
},
|
|
712
|
-
successfulResponseHandler: (
|
|
748
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
713
749
|
vertexOperationSchema
|
|
714
750
|
),
|
|
715
751
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
@@ -720,14 +756,14 @@ var GoogleVertexVideoModel = class {
|
|
|
720
756
|
responseHeaders = pollHeaders;
|
|
721
757
|
}
|
|
722
758
|
if (finalOperation.error) {
|
|
723
|
-
throw new
|
|
759
|
+
throw new AISDKError({
|
|
724
760
|
name: "VERTEX_VIDEO_GENERATION_FAILED",
|
|
725
761
|
message: `Video generation failed: ${finalOperation.error.message}`
|
|
726
762
|
});
|
|
727
763
|
}
|
|
728
764
|
const response = finalOperation.response;
|
|
729
765
|
if (!(response == null ? void 0 : response.videos) || response.videos.length === 0) {
|
|
730
|
-
throw new
|
|
766
|
+
throw new AISDKError({
|
|
731
767
|
name: "VERTEX_VIDEO_GENERATION_ERROR",
|
|
732
768
|
message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
|
|
733
769
|
});
|
|
@@ -757,7 +793,7 @@ var GoogleVertexVideoModel = class {
|
|
|
757
793
|
}
|
|
758
794
|
}
|
|
759
795
|
if (videos.length === 0) {
|
|
760
|
-
throw new
|
|
796
|
+
throw new AISDKError({
|
|
761
797
|
name: "VERTEX_VIDEO_GENERATION_ERROR",
|
|
762
798
|
message: "No valid videos in response"
|
|
763
799
|
});
|
|
@@ -778,38 +814,38 @@ var GoogleVertexVideoModel = class {
|
|
|
778
814
|
};
|
|
779
815
|
}
|
|
780
816
|
};
|
|
781
|
-
var vertexOperationSchema =
|
|
782
|
-
name:
|
|
783
|
-
done:
|
|
784
|
-
error:
|
|
785
|
-
code:
|
|
786
|
-
message:
|
|
787
|
-
status:
|
|
817
|
+
var vertexOperationSchema = z5.object({
|
|
818
|
+
name: z5.string().nullish(),
|
|
819
|
+
done: z5.boolean().nullish(),
|
|
820
|
+
error: z5.object({
|
|
821
|
+
code: z5.number().nullish(),
|
|
822
|
+
message: z5.string(),
|
|
823
|
+
status: z5.string().nullish()
|
|
788
824
|
}).nullish(),
|
|
789
|
-
response:
|
|
790
|
-
videos:
|
|
791
|
-
|
|
792
|
-
bytesBase64Encoded:
|
|
793
|
-
gcsUri:
|
|
794
|
-
mimeType:
|
|
825
|
+
response: z5.object({
|
|
826
|
+
videos: z5.array(
|
|
827
|
+
z5.object({
|
|
828
|
+
bytesBase64Encoded: z5.string().nullish(),
|
|
829
|
+
gcsUri: z5.string().nullish(),
|
|
830
|
+
mimeType: z5.string().nullish()
|
|
795
831
|
})
|
|
796
832
|
).nullish(),
|
|
797
|
-
raiMediaFilteredCount:
|
|
833
|
+
raiMediaFilteredCount: z5.number().nullish()
|
|
798
834
|
}).nullish()
|
|
799
835
|
});
|
|
800
|
-
var googleVertexVideoModelOptionsSchema =
|
|
801
|
-
() =>
|
|
802
|
-
|
|
803
|
-
pollIntervalMs:
|
|
804
|
-
pollTimeoutMs:
|
|
805
|
-
personGeneration:
|
|
806
|
-
negativePrompt:
|
|
807
|
-
generateAudio:
|
|
808
|
-
gcsOutputDirectory:
|
|
809
|
-
referenceImages:
|
|
810
|
-
|
|
811
|
-
bytesBase64Encoded:
|
|
812
|
-
gcsUri:
|
|
836
|
+
var googleVertexVideoModelOptionsSchema = lazySchema(
|
|
837
|
+
() => zodSchema(
|
|
838
|
+
z5.object({
|
|
839
|
+
pollIntervalMs: z5.number().positive().nullish(),
|
|
840
|
+
pollTimeoutMs: z5.number().positive().nullish(),
|
|
841
|
+
personGeneration: z5.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
842
|
+
negativePrompt: z5.string().nullish(),
|
|
843
|
+
generateAudio: z5.boolean().nullish(),
|
|
844
|
+
gcsOutputDirectory: z5.string().nullish(),
|
|
845
|
+
referenceImages: z5.array(
|
|
846
|
+
z5.object({
|
|
847
|
+
bytesBase64Encoded: z5.string().nullish(),
|
|
848
|
+
gcsUri: z5.string().nullish()
|
|
813
849
|
})
|
|
814
850
|
).nullish()
|
|
815
851
|
}).passthrough()
|
|
@@ -823,7 +859,7 @@ function createExpressModeFetch(apiKey, customFetch) {
|
|
|
823
859
|
const modifiedInit = {
|
|
824
860
|
...init,
|
|
825
861
|
headers: {
|
|
826
|
-
...(init == null ? void 0 : init.headers) ?
|
|
862
|
+
...(init == null ? void 0 : init.headers) ? normalizeHeaders(init.headers) : {},
|
|
827
863
|
"x-goog-api-key": apiKey
|
|
828
864
|
}
|
|
829
865
|
};
|
|
@@ -831,17 +867,17 @@ function createExpressModeFetch(apiKey, customFetch) {
|
|
|
831
867
|
};
|
|
832
868
|
}
|
|
833
869
|
function createVertex(options = {}) {
|
|
834
|
-
const apiKey =
|
|
870
|
+
const apiKey = loadOptionalSetting({
|
|
835
871
|
settingValue: options.apiKey,
|
|
836
872
|
environmentVariableName: "GOOGLE_VERTEX_API_KEY"
|
|
837
873
|
});
|
|
838
|
-
const loadVertexProject = () =>
|
|
874
|
+
const loadVertexProject = () => loadSetting({
|
|
839
875
|
settingValue: options.project,
|
|
840
876
|
settingName: "project",
|
|
841
877
|
environmentVariableName: "GOOGLE_VERTEX_PROJECT",
|
|
842
878
|
description: "Google Vertex project"
|
|
843
879
|
});
|
|
844
|
-
const loadVertexLocation = () =>
|
|
880
|
+
const loadVertexLocation = () => loadSetting({
|
|
845
881
|
settingValue: options.location,
|
|
846
882
|
settingName: "location",
|
|
847
883
|
environmentVariableName: "GOOGLE_VERTEX_LOCATION",
|
|
@@ -850,18 +886,18 @@ function createVertex(options = {}) {
|
|
|
850
886
|
const loadBaseURL = () => {
|
|
851
887
|
var _a, _b;
|
|
852
888
|
if (apiKey) {
|
|
853
|
-
return (_a =
|
|
889
|
+
return (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : EXPRESS_MODE_BASE_URL;
|
|
854
890
|
}
|
|
855
891
|
const region = loadVertexLocation();
|
|
856
892
|
const project = loadVertexProject();
|
|
857
893
|
const baseHost = `${region === "global" ? "" : region + "-"}aiplatform.googleapis.com`;
|
|
858
|
-
return (_b =
|
|
894
|
+
return (_b = withoutTrailingSlash(options.baseURL)) != null ? _b : `https://${baseHost}/v1beta1/projects/${project}/locations/${region}/publishers/google`;
|
|
859
895
|
};
|
|
860
896
|
const createConfig = (name) => {
|
|
861
897
|
const getHeaders = async () => {
|
|
862
898
|
var _a;
|
|
863
|
-
const originalHeaders = await (
|
|
864
|
-
return
|
|
899
|
+
const originalHeaders = await resolve4((_a = options.headers) != null ? _a : {});
|
|
900
|
+
return withUserAgentSuffix(
|
|
865
901
|
originalHeaders,
|
|
866
902
|
`ai-sdk/google-vertex/${VERSION}`
|
|
867
903
|
);
|
|
@@ -875,9 +911,9 @@ function createVertex(options = {}) {
|
|
|
875
911
|
};
|
|
876
912
|
const createChatModel = (modelId) => {
|
|
877
913
|
var _a;
|
|
878
|
-
return new
|
|
914
|
+
return new GoogleGenerativeAILanguageModel2(modelId, {
|
|
879
915
|
...createConfig("chat"),
|
|
880
|
-
generateId: (_a = options.generateId) != null ? _a :
|
|
916
|
+
generateId: (_a = options.generateId) != null ? _a : generateId,
|
|
881
917
|
supportedUrls: () => ({
|
|
882
918
|
"*": [
|
|
883
919
|
// HTTP URLs:
|
|
@@ -893,14 +929,14 @@ function createVertex(options = {}) {
|
|
|
893
929
|
var _a;
|
|
894
930
|
return new GoogleVertexImageModel(modelId, {
|
|
895
931
|
...createConfig("image"),
|
|
896
|
-
generateId: (_a = options.generateId) != null ? _a :
|
|
932
|
+
generateId: (_a = options.generateId) != null ? _a : generateId
|
|
897
933
|
});
|
|
898
934
|
};
|
|
899
935
|
const createVideoModel = (modelId) => {
|
|
900
936
|
var _a;
|
|
901
937
|
return new GoogleVertexVideoModel(modelId, {
|
|
902
938
|
...createConfig("video"),
|
|
903
|
-
generateId: (_a = options.generateId) != null ? _a :
|
|
939
|
+
generateId: (_a = options.generateId) != null ? _a : generateId
|
|
904
940
|
});
|
|
905
941
|
};
|
|
906
942
|
const provider = function(modelId) {
|
|
@@ -911,7 +947,7 @@ function createVertex(options = {}) {
|
|
|
911
947
|
}
|
|
912
948
|
return createChatModel(modelId);
|
|
913
949
|
};
|
|
914
|
-
provider.specificationVersion = "
|
|
950
|
+
provider.specificationVersion = "v4";
|
|
915
951
|
provider.languageModel = createChatModel;
|
|
916
952
|
provider.embeddingModel = createEmbeddingModel;
|
|
917
953
|
provider.textEmbeddingModel = createEmbeddingModel;
|
|
@@ -925,7 +961,7 @@ function createVertex(options = {}) {
|
|
|
925
961
|
|
|
926
962
|
// src/google-vertex-provider-node.ts
|
|
927
963
|
function createVertex2(options = {}) {
|
|
928
|
-
const apiKey = (
|
|
964
|
+
const apiKey = loadOptionalSetting2({
|
|
929
965
|
settingValue: options.apiKey,
|
|
930
966
|
environmentVariableName: "GOOGLE_VERTEX_API_KEY"
|
|
931
967
|
});
|
|
@@ -938,15 +974,14 @@ function createVertex2(options = {}) {
|
|
|
938
974
|
Authorization: `Bearer ${await generateAuthToken(
|
|
939
975
|
options.googleAuthOptions
|
|
940
976
|
)}`,
|
|
941
|
-
...await (
|
|
977
|
+
...await resolve5(options.headers)
|
|
942
978
|
})
|
|
943
979
|
});
|
|
944
980
|
}
|
|
945
981
|
var vertex = createVertex2();
|
|
946
|
-
|
|
947
|
-
0 && (module.exports = {
|
|
982
|
+
export {
|
|
948
983
|
VERSION,
|
|
949
|
-
createVertex,
|
|
984
|
+
createVertex2 as createVertex,
|
|
950
985
|
vertex
|
|
951
|
-
}
|
|
986
|
+
};
|
|
952
987
|
//# sourceMappingURL=index.js.map
|