@ai-sdk/google-vertex 5.0.0-beta.6 → 5.0.0-beta.60
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 +516 -8
- package/README.md +65 -2
- package/dist/anthropic/edge/index.d.ts +69 -24
- package/dist/anthropic/edge/index.js +67 -60
- package/dist/anthropic/edge/index.js.map +1 -1
- package/dist/anthropic/index.d.ts +69 -24
- package/dist/anthropic/index.js +57 -55
- package/dist/anthropic/index.js.map +1 -1
- package/dist/edge/index.d.ts +35 -26
- package/dist/edge/index.js +217 -176
- package/dist/edge/index.js.map +1 -1
- package/dist/index.d.ts +35 -26
- 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 +236 -14
- package/maas/edge.d.ts +1 -0
- package/maas/index.d.ts +1 -0
- package/package.json +33 -20
- package/src/anthropic/edge/google-vertex-anthropic-provider-edge.ts +1 -2
- package/src/anthropic/{google-vertex-anthropic-messages-options.ts → google-vertex-anthropic-options.ts} +2 -1
- package/src/anthropic/google-vertex-anthropic-provider-node.ts +1 -2
- package/src/anthropic/google-vertex-anthropic-provider.ts +38 -13
- 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 +40 -20
- package/src/google-vertex-options.ts +0 -1
- package/src/google-vertex-provider-node.ts +1 -2
- package/src/google-vertex-provider.ts +14 -14
- 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/edge/index.js
CHANGED
|
@@ -1,56 +1,48 @@
|
|
|
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/edge/index.ts
|
|
21
|
-
var edge_exports = {};
|
|
22
|
-
__export(edge_exports, {
|
|
23
|
-
createVertex: () => createVertex2,
|
|
24
|
-
vertex: () => vertex
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(edge_exports);
|
|
27
|
-
|
|
28
1
|
// src/edge/google-vertex-provider-edge.ts
|
|
29
|
-
|
|
2
|
+
import { loadOptionalSetting as loadOptionalSetting3, resolve as resolve5 } from "@ai-sdk/provider-utils";
|
|
30
3
|
|
|
31
4
|
// src/google-vertex-provider.ts
|
|
32
|
-
|
|
33
|
-
|
|
5
|
+
import { GoogleLanguageModel as GoogleLanguageModel2 } from "@ai-sdk/google/internal";
|
|
6
|
+
import {
|
|
7
|
+
generateId,
|
|
8
|
+
loadOptionalSetting,
|
|
9
|
+
loadSetting,
|
|
10
|
+
normalizeHeaders,
|
|
11
|
+
resolve as resolve4,
|
|
12
|
+
withoutTrailingSlash,
|
|
13
|
+
withUserAgentSuffix
|
|
14
|
+
} from "@ai-sdk/provider-utils";
|
|
34
15
|
|
|
35
16
|
// src/version.ts
|
|
36
|
-
var VERSION = true ? "5.0.0-beta.
|
|
17
|
+
var VERSION = true ? "5.0.0-beta.60" : "0.0.0-test";
|
|
37
18
|
|
|
38
19
|
// src/google-vertex-embedding-model.ts
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
20
|
+
import {
|
|
21
|
+
TooManyEmbeddingValuesForCallError
|
|
22
|
+
} from "@ai-sdk/provider";
|
|
23
|
+
import {
|
|
24
|
+
combineHeaders,
|
|
25
|
+
createJsonResponseHandler,
|
|
26
|
+
postJsonToApi,
|
|
27
|
+
resolve,
|
|
28
|
+
parseProviderOptions,
|
|
29
|
+
serializeModelOptions,
|
|
30
|
+
WORKFLOW_SERIALIZE,
|
|
31
|
+
WORKFLOW_DESERIALIZE
|
|
32
|
+
} from "@ai-sdk/provider-utils";
|
|
33
|
+
import { z as z3 } from "zod/v4";
|
|
42
34
|
|
|
43
35
|
// src/google-vertex-error.ts
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var googleVertexErrorDataSchema =
|
|
47
|
-
error:
|
|
48
|
-
code:
|
|
49
|
-
message:
|
|
50
|
-
status:
|
|
36
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
37
|
+
import { z } from "zod/v4";
|
|
38
|
+
var googleVertexErrorDataSchema = z.object({
|
|
39
|
+
error: z.object({
|
|
40
|
+
code: z.number().nullable(),
|
|
41
|
+
message: z.string(),
|
|
42
|
+
status: z.string()
|
|
51
43
|
})
|
|
52
44
|
});
|
|
53
|
-
var googleVertexFailedResponseHandler =
|
|
45
|
+
var googleVertexFailedResponseHandler = createJsonErrorResponseHandler(
|
|
54
46
|
{
|
|
55
47
|
errorSchema: googleVertexErrorDataSchema,
|
|
56
48
|
errorToMessage: (data) => data.error.message
|
|
@@ -58,13 +50,13 @@ var googleVertexFailedResponseHandler = (0, import_provider_utils.createJsonErro
|
|
|
58
50
|
);
|
|
59
51
|
|
|
60
52
|
// src/google-vertex-embedding-options.ts
|
|
61
|
-
|
|
62
|
-
var googleVertexEmbeddingModelOptions =
|
|
53
|
+
import { z as z2 } from "zod/v4";
|
|
54
|
+
var googleVertexEmbeddingModelOptions = z2.object({
|
|
63
55
|
/**
|
|
64
56
|
* Optional. Optional reduced dimension for the output embedding.
|
|
65
57
|
* If set, excessive values in the output embedding are truncated from the end.
|
|
66
58
|
*/
|
|
67
|
-
outputDimensionality:
|
|
59
|
+
outputDimensionality: z2.number().optional(),
|
|
68
60
|
/**
|
|
69
61
|
* Optional. Specifies the task type for generating embeddings.
|
|
70
62
|
* Supported task types:
|
|
@@ -77,7 +69,7 @@ var googleVertexEmbeddingModelOptions = import_v42.z.object({
|
|
|
77
69
|
* - FACT_VERIFICATION: Optimized for verifying factual information.
|
|
78
70
|
* - CODE_RETRIEVAL_QUERY: Optimized for retrieving code blocks based on natural language queries.
|
|
79
71
|
*/
|
|
80
|
-
taskType:
|
|
72
|
+
taskType: z2.enum([
|
|
81
73
|
"SEMANTIC_SIMILARITY",
|
|
82
74
|
"CLASSIFICATION",
|
|
83
75
|
"CLUSTERING",
|
|
@@ -92,23 +84,32 @@ var googleVertexEmbeddingModelOptions = import_v42.z.object({
|
|
|
92
84
|
* Only valid when task_type is set to 'RETRIEVAL_DOCUMENT'.
|
|
93
85
|
* Helps the model produce better embeddings by providing additional context.
|
|
94
86
|
*/
|
|
95
|
-
title:
|
|
87
|
+
title: z2.string().optional(),
|
|
96
88
|
/**
|
|
97
89
|
* Optional. When set to true, input text will be truncated. When set to false,
|
|
98
90
|
* an error is returned if the input text is longer than the maximum length supported by the model. Defaults to true.
|
|
99
91
|
*/
|
|
100
|
-
autoTruncate:
|
|
92
|
+
autoTruncate: z2.boolean().optional()
|
|
101
93
|
});
|
|
102
94
|
|
|
103
95
|
// src/google-vertex-embedding-model.ts
|
|
104
|
-
var GoogleVertexEmbeddingModel = class {
|
|
96
|
+
var GoogleVertexEmbeddingModel = class _GoogleVertexEmbeddingModel {
|
|
105
97
|
constructor(modelId, config) {
|
|
106
|
-
this.specificationVersion = "
|
|
98
|
+
this.specificationVersion = "v4";
|
|
107
99
|
this.maxEmbeddingsPerCall = 2048;
|
|
108
100
|
this.supportsParallelCalls = true;
|
|
109
101
|
this.modelId = modelId;
|
|
110
102
|
this.config = config;
|
|
111
103
|
}
|
|
104
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
105
|
+
return serializeModelOptions({
|
|
106
|
+
modelId: model.modelId,
|
|
107
|
+
config: model.config
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
111
|
+
return new _GoogleVertexEmbeddingModel(options.modelId, options.config);
|
|
112
|
+
}
|
|
112
113
|
get provider() {
|
|
113
114
|
return this.config.provider;
|
|
114
115
|
}
|
|
@@ -118,13 +119,13 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
118
119
|
abortSignal,
|
|
119
120
|
providerOptions
|
|
120
121
|
}) {
|
|
121
|
-
let googleOptions = await
|
|
122
|
+
let googleOptions = await parseProviderOptions({
|
|
122
123
|
provider: "vertex",
|
|
123
124
|
providerOptions,
|
|
124
125
|
schema: googleVertexEmbeddingModelOptions
|
|
125
126
|
});
|
|
126
127
|
if (googleOptions == null) {
|
|
127
|
-
googleOptions = await
|
|
128
|
+
googleOptions = await parseProviderOptions({
|
|
128
129
|
provider: "google",
|
|
129
130
|
providerOptions,
|
|
130
131
|
schema: googleVertexEmbeddingModelOptions
|
|
@@ -132,15 +133,15 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
132
133
|
}
|
|
133
134
|
googleOptions = googleOptions != null ? googleOptions : {};
|
|
134
135
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
135
|
-
throw new
|
|
136
|
+
throw new TooManyEmbeddingValuesForCallError({
|
|
136
137
|
provider: this.provider,
|
|
137
138
|
modelId: this.modelId,
|
|
138
139
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
139
140
|
values
|
|
140
141
|
});
|
|
141
142
|
}
|
|
142
|
-
const mergedHeaders =
|
|
143
|
-
await
|
|
143
|
+
const mergedHeaders = combineHeaders(
|
|
144
|
+
this.config.headers ? await resolve(this.config.headers) : void 0,
|
|
144
145
|
headers
|
|
145
146
|
);
|
|
146
147
|
const url = `${this.config.baseURL}/models/${this.modelId}:predict`;
|
|
@@ -148,7 +149,7 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
148
149
|
responseHeaders,
|
|
149
150
|
value: response,
|
|
150
151
|
rawValue
|
|
151
|
-
} = await
|
|
152
|
+
} = await postJsonToApi({
|
|
152
153
|
url,
|
|
153
154
|
headers: mergedHeaders,
|
|
154
155
|
body: {
|
|
@@ -163,7 +164,7 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
163
164
|
}
|
|
164
165
|
},
|
|
165
166
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
166
|
-
successfulResponseHandler:
|
|
167
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
167
168
|
googleVertexTextEmbeddingResponseSchema
|
|
168
169
|
),
|
|
169
170
|
abortSignal,
|
|
@@ -184,13 +185,13 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
184
185
|
};
|
|
185
186
|
}
|
|
186
187
|
};
|
|
187
|
-
var googleVertexTextEmbeddingResponseSchema =
|
|
188
|
-
predictions:
|
|
189
|
-
|
|
190
|
-
embeddings:
|
|
191
|
-
values:
|
|
192
|
-
statistics:
|
|
193
|
-
token_count:
|
|
188
|
+
var googleVertexTextEmbeddingResponseSchema = z3.object({
|
|
189
|
+
predictions: z3.array(
|
|
190
|
+
z3.object({
|
|
191
|
+
embeddings: z3.object({
|
|
192
|
+
values: z3.array(z3.number()),
|
|
193
|
+
statistics: z3.object({
|
|
194
|
+
token_count: z3.number()
|
|
194
195
|
})
|
|
195
196
|
})
|
|
196
197
|
})
|
|
@@ -198,14 +199,35 @@ var googleVertexTextEmbeddingResponseSchema = import_v43.z.object({
|
|
|
198
199
|
});
|
|
199
200
|
|
|
200
201
|
// src/google-vertex-image-model.ts
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
202
|
+
import { GoogleLanguageModel } from "@ai-sdk/google/internal";
|
|
203
|
+
import {
|
|
204
|
+
combineHeaders as combineHeaders2,
|
|
205
|
+
convertToBase64,
|
|
206
|
+
convertUint8ArrayToBase64,
|
|
207
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
208
|
+
generateId as defaultGenerateId,
|
|
209
|
+
parseProviderOptions as parseProviderOptions2,
|
|
210
|
+
postJsonToApi as postJsonToApi2,
|
|
211
|
+
resolve as resolve2,
|
|
212
|
+
serializeModelOptions as serializeModelOptions2,
|
|
213
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
|
|
214
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
|
|
215
|
+
} from "@ai-sdk/provider-utils";
|
|
216
|
+
import { z as z4 } from "zod/v4";
|
|
217
|
+
var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
205
218
|
constructor(modelId, config) {
|
|
206
219
|
this.modelId = modelId;
|
|
207
220
|
this.config = config;
|
|
208
|
-
this.specificationVersion = "
|
|
221
|
+
this.specificationVersion = "v4";
|
|
222
|
+
}
|
|
223
|
+
static [WORKFLOW_SERIALIZE2](model) {
|
|
224
|
+
return serializeModelOptions2({
|
|
225
|
+
modelId: model.modelId,
|
|
226
|
+
config: model.config
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
static [WORKFLOW_DESERIALIZE2](options) {
|
|
230
|
+
return new _GoogleVertexImageModel(options.modelId, options.config);
|
|
209
231
|
}
|
|
210
232
|
get maxImagesPerCall() {
|
|
211
233
|
if (isGeminiModel(this.modelId)) {
|
|
@@ -243,7 +265,7 @@ var GoogleVertexImageModel = class {
|
|
|
243
265
|
details: "This model does not support the `size` option. Use `aspectRatio` instead."
|
|
244
266
|
});
|
|
245
267
|
}
|
|
246
|
-
const vertexImageOptions = await (
|
|
268
|
+
const vertexImageOptions = await parseProviderOptions2({
|
|
247
269
|
provider: "vertex",
|
|
248
270
|
providerOptions,
|
|
249
271
|
schema: googleVertexImageModelOptionsSchema
|
|
@@ -305,12 +327,15 @@ var GoogleVertexImageModel = class {
|
|
|
305
327
|
};
|
|
306
328
|
}
|
|
307
329
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
308
|
-
const { value: response, responseHeaders } = await (
|
|
330
|
+
const { value: response, responseHeaders } = await postJsonToApi2({
|
|
309
331
|
url: `${this.config.baseURL}/models/${this.modelId}:predict`,
|
|
310
|
-
headers: (
|
|
332
|
+
headers: combineHeaders2(
|
|
333
|
+
this.config.headers ? await resolve2(this.config.headers) : void 0,
|
|
334
|
+
headers
|
|
335
|
+
),
|
|
311
336
|
body,
|
|
312
337
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
313
|
-
successfulResponseHandler: (
|
|
338
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
314
339
|
vertexImageResponseSchema
|
|
315
340
|
),
|
|
316
341
|
abortSignal,
|
|
@@ -394,12 +419,12 @@ var GoogleVertexImageModel = class {
|
|
|
394
419
|
const languageModelPrompt = [
|
|
395
420
|
{ role: "user", content: userContent }
|
|
396
421
|
];
|
|
397
|
-
const languageModel = new
|
|
422
|
+
const languageModel = new GoogleLanguageModel(this.modelId, {
|
|
398
423
|
provider: this.config.provider,
|
|
399
424
|
baseURL: this.config.baseURL,
|
|
400
425
|
headers: (_a = this.config.headers) != null ? _a : {},
|
|
401
426
|
fetch: this.config.fetch,
|
|
402
|
-
generateId: (_b = this.config.generateId) != null ? _b :
|
|
427
|
+
generateId: (_b = this.config.generateId) != null ? _b : defaultGenerateId,
|
|
403
428
|
supportedUrls: () => ({
|
|
404
429
|
"*": [/^https?:\/\/.*$/, /^gs:\/\/.*$/]
|
|
405
430
|
})
|
|
@@ -423,7 +448,7 @@ var GoogleVertexImageModel = class {
|
|
|
423
448
|
const images = [];
|
|
424
449
|
for (const part of result.content) {
|
|
425
450
|
if (part.type === "file" && part.mediaType.startsWith("image/")) {
|
|
426
|
-
images.push(
|
|
451
|
+
images.push(convertToBase64(part.data));
|
|
427
452
|
}
|
|
428
453
|
}
|
|
429
454
|
return {
|
|
@@ -450,41 +475,41 @@ var GoogleVertexImageModel = class {
|
|
|
450
475
|
function isGeminiModel(modelId) {
|
|
451
476
|
return modelId.startsWith("gemini-");
|
|
452
477
|
}
|
|
453
|
-
var vertexImageResponseSchema =
|
|
454
|
-
predictions:
|
|
455
|
-
|
|
456
|
-
bytesBase64Encoded:
|
|
457
|
-
mimeType:
|
|
458
|
-
prompt:
|
|
478
|
+
var vertexImageResponseSchema = z4.object({
|
|
479
|
+
predictions: z4.array(
|
|
480
|
+
z4.object({
|
|
481
|
+
bytesBase64Encoded: z4.string(),
|
|
482
|
+
mimeType: z4.string(),
|
|
483
|
+
prompt: z4.string().nullish()
|
|
459
484
|
})
|
|
460
485
|
).nullish()
|
|
461
486
|
});
|
|
462
|
-
var googleVertexImageModelOptionsSchema =
|
|
463
|
-
negativePrompt:
|
|
464
|
-
personGeneration:
|
|
465
|
-
safetySetting:
|
|
487
|
+
var googleVertexImageModelOptionsSchema = z4.object({
|
|
488
|
+
negativePrompt: z4.string().nullish(),
|
|
489
|
+
personGeneration: z4.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
490
|
+
safetySetting: z4.enum([
|
|
466
491
|
"block_low_and_above",
|
|
467
492
|
"block_medium_and_above",
|
|
468
493
|
"block_only_high",
|
|
469
494
|
"block_none"
|
|
470
495
|
]).nullish(),
|
|
471
|
-
addWatermark:
|
|
472
|
-
storageUri:
|
|
473
|
-
sampleImageSize:
|
|
496
|
+
addWatermark: z4.boolean().nullish(),
|
|
497
|
+
storageUri: z4.string().nullish(),
|
|
498
|
+
sampleImageSize: z4.enum(["1K", "2K"]).nullish(),
|
|
474
499
|
/**
|
|
475
500
|
* Configuration for image editing operations
|
|
476
501
|
*/
|
|
477
|
-
edit:
|
|
502
|
+
edit: z4.object({
|
|
478
503
|
/**
|
|
479
504
|
* An integer that represents the number of sampling steps.
|
|
480
505
|
* A higher value offers better image quality, a lower value offers better latency.
|
|
481
506
|
* Try 35 steps to start. If the quality doesn't meet your requirements,
|
|
482
507
|
* increase the value towards an upper limit of 75.
|
|
483
508
|
*/
|
|
484
|
-
baseSteps:
|
|
509
|
+
baseSteps: z4.number().nullish(),
|
|
485
510
|
// Edit mode options
|
|
486
511
|
// https://cloud.google.com/vertex-ai/generative-ai/docs/image/edit-insert-objects
|
|
487
|
-
mode:
|
|
512
|
+
mode: z4.enum([
|
|
488
513
|
"EDIT_MODE_INPAINT_INSERTION",
|
|
489
514
|
"EDIT_MODE_INPAINT_REMOVAL",
|
|
490
515
|
"EDIT_MODE_OUTPAINT",
|
|
@@ -500,7 +525,7 @@ var googleVertexImageModelOptionsSchema = import_v44.z.object({
|
|
|
500
525
|
* - `MASK_MODE_CLOTHING_AREA` - Masks from segmenting the clothing area with open-vocab segmentation.
|
|
501
526
|
* - `MASK_MODE_PARSED_PERSON` - Masks from segmenting the person body and clothing using the person-parsing model.
|
|
502
527
|
*/
|
|
503
|
-
maskMode:
|
|
528
|
+
maskMode: z4.enum([
|
|
504
529
|
"MASK_MODE_DEFAULT",
|
|
505
530
|
"MASK_MODE_USER_PROVIDED",
|
|
506
531
|
"MASK_MODE_DETECTION_BOX",
|
|
@@ -512,7 +537,7 @@ var googleVertexImageModelOptionsSchema = import_v44.z.object({
|
|
|
512
537
|
* percentage of the image width to grow the mask by. Using dilation helps
|
|
513
538
|
* compensate for imprecise masks. We recommend a value of 0.01.
|
|
514
539
|
*/
|
|
515
|
-
maskDilation:
|
|
540
|
+
maskDilation: z4.number().nullish()
|
|
516
541
|
}).nullish()
|
|
517
542
|
});
|
|
518
543
|
function getBase64Data(file) {
|
|
@@ -524,30 +549,42 @@ function getBase64Data(file) {
|
|
|
524
549
|
if (typeof file.data === "string") {
|
|
525
550
|
return file.data;
|
|
526
551
|
}
|
|
527
|
-
return
|
|
552
|
+
return convertUint8ArrayToBase64(file.data);
|
|
528
553
|
}
|
|
529
554
|
|
|
530
555
|
// src/google-vertex-tools.ts
|
|
531
|
-
|
|
556
|
+
import { googleTools } from "@ai-sdk/google/internal";
|
|
532
557
|
var googleVertexTools = {
|
|
533
|
-
googleSearch:
|
|
534
|
-
enterpriseWebSearch:
|
|
535
|
-
googleMaps:
|
|
536
|
-
urlContext:
|
|
537
|
-
fileSearch:
|
|
538
|
-
codeExecution:
|
|
539
|
-
vertexRagStore:
|
|
558
|
+
googleSearch: googleTools.googleSearch,
|
|
559
|
+
enterpriseWebSearch: googleTools.enterpriseWebSearch,
|
|
560
|
+
googleMaps: googleTools.googleMaps,
|
|
561
|
+
urlContext: googleTools.urlContext,
|
|
562
|
+
fileSearch: googleTools.fileSearch,
|
|
563
|
+
codeExecution: googleTools.codeExecution,
|
|
564
|
+
vertexRagStore: googleTools.vertexRagStore
|
|
540
565
|
};
|
|
541
566
|
|
|
542
567
|
// src/google-vertex-video-model.ts
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
568
|
+
import {
|
|
569
|
+
AISDKError
|
|
570
|
+
} from "@ai-sdk/provider";
|
|
571
|
+
import {
|
|
572
|
+
combineHeaders as combineHeaders3,
|
|
573
|
+
convertUint8ArrayToBase64 as convertUint8ArrayToBase642,
|
|
574
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
575
|
+
delay,
|
|
576
|
+
lazySchema,
|
|
577
|
+
parseProviderOptions as parseProviderOptions3,
|
|
578
|
+
postJsonToApi as postJsonToApi3,
|
|
579
|
+
resolve as resolve3,
|
|
580
|
+
zodSchema
|
|
581
|
+
} from "@ai-sdk/provider-utils";
|
|
582
|
+
import { z as z5 } from "zod/v4";
|
|
546
583
|
var GoogleVertexVideoModel = class {
|
|
547
584
|
constructor(modelId, config) {
|
|
548
585
|
this.modelId = modelId;
|
|
549
586
|
this.config = config;
|
|
550
|
-
this.specificationVersion = "
|
|
587
|
+
this.specificationVersion = "v4";
|
|
551
588
|
}
|
|
552
589
|
get provider() {
|
|
553
590
|
return this.config.provider;
|
|
@@ -559,7 +596,7 @@ var GoogleVertexVideoModel = class {
|
|
|
559
596
|
var _a, _b, _c, _d, _e, _f;
|
|
560
597
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
561
598
|
const warnings = [];
|
|
562
|
-
const vertexOptions = await (
|
|
599
|
+
const vertexOptions = await parseProviderOptions3({
|
|
563
600
|
provider: "vertex",
|
|
564
601
|
providerOptions: options.providerOptions,
|
|
565
602
|
schema: googleVertexVideoModelOptionsSchema
|
|
@@ -577,7 +614,7 @@ var GoogleVertexVideoModel = class {
|
|
|
577
614
|
details: "Vertex AI video models require base64-encoded images or GCS URIs. URL will be ignored."
|
|
578
615
|
});
|
|
579
616
|
} else {
|
|
580
|
-
const base64Data = typeof options.image.data === "string" ? options.image.data : (
|
|
617
|
+
const base64Data = typeof options.image.data === "string" ? options.image.data : convertUint8ArrayToBase642(options.image.data);
|
|
581
618
|
instance.image = {
|
|
582
619
|
bytesBase64Encoded: base64Data,
|
|
583
620
|
mimeType: options.image.mediaType
|
|
@@ -635,17 +672,17 @@ var GoogleVertexVideoModel = class {
|
|
|
635
672
|
}
|
|
636
673
|
}
|
|
637
674
|
}
|
|
638
|
-
const { value: operation } = await (
|
|
675
|
+
const { value: operation } = await postJsonToApi3({
|
|
639
676
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
640
|
-
headers: (
|
|
641
|
-
await (
|
|
677
|
+
headers: combineHeaders3(
|
|
678
|
+
await resolve3(this.config.headers),
|
|
642
679
|
options.headers
|
|
643
680
|
),
|
|
644
681
|
body: {
|
|
645
682
|
instances,
|
|
646
683
|
parameters
|
|
647
684
|
},
|
|
648
|
-
successfulResponseHandler: (
|
|
685
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
649
686
|
vertexOperationSchema
|
|
650
687
|
),
|
|
651
688
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
@@ -654,7 +691,7 @@ var GoogleVertexVideoModel = class {
|
|
|
654
691
|
});
|
|
655
692
|
const operationName = operation.name;
|
|
656
693
|
if (!operationName) {
|
|
657
|
-
throw new
|
|
694
|
+
throw new AISDKError({
|
|
658
695
|
name: "VERTEX_VIDEO_GENERATION_ERROR",
|
|
659
696
|
message: "No operation name returned from API"
|
|
660
697
|
});
|
|
@@ -666,28 +703,28 @@ var GoogleVertexVideoModel = class {
|
|
|
666
703
|
let responseHeaders;
|
|
667
704
|
while (!finalOperation.done) {
|
|
668
705
|
if (Date.now() - startTime > pollTimeoutMs) {
|
|
669
|
-
throw new
|
|
706
|
+
throw new AISDKError({
|
|
670
707
|
name: "VERTEX_VIDEO_GENERATION_TIMEOUT",
|
|
671
708
|
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
672
709
|
});
|
|
673
710
|
}
|
|
674
|
-
await
|
|
711
|
+
await delay(pollIntervalMs);
|
|
675
712
|
if ((_f = options.abortSignal) == null ? void 0 : _f.aborted) {
|
|
676
|
-
throw new
|
|
713
|
+
throw new AISDKError({
|
|
677
714
|
name: "VERTEX_VIDEO_GENERATION_ABORTED",
|
|
678
715
|
message: "Video generation request was aborted"
|
|
679
716
|
});
|
|
680
717
|
}
|
|
681
|
-
const { value: statusOperation, responseHeaders: pollHeaders } = await (
|
|
718
|
+
const { value: statusOperation, responseHeaders: pollHeaders } = await postJsonToApi3({
|
|
682
719
|
url: `${this.config.baseURL}/models/${this.modelId}:fetchPredictOperation`,
|
|
683
|
-
headers: (
|
|
684
|
-
await (
|
|
720
|
+
headers: combineHeaders3(
|
|
721
|
+
await resolve3(this.config.headers),
|
|
685
722
|
options.headers
|
|
686
723
|
),
|
|
687
724
|
body: {
|
|
688
725
|
operationName
|
|
689
726
|
},
|
|
690
|
-
successfulResponseHandler: (
|
|
727
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
691
728
|
vertexOperationSchema
|
|
692
729
|
),
|
|
693
730
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
@@ -698,14 +735,14 @@ var GoogleVertexVideoModel = class {
|
|
|
698
735
|
responseHeaders = pollHeaders;
|
|
699
736
|
}
|
|
700
737
|
if (finalOperation.error) {
|
|
701
|
-
throw new
|
|
738
|
+
throw new AISDKError({
|
|
702
739
|
name: "VERTEX_VIDEO_GENERATION_FAILED",
|
|
703
740
|
message: `Video generation failed: ${finalOperation.error.message}`
|
|
704
741
|
});
|
|
705
742
|
}
|
|
706
743
|
const response = finalOperation.response;
|
|
707
744
|
if (!(response == null ? void 0 : response.videos) || response.videos.length === 0) {
|
|
708
|
-
throw new
|
|
745
|
+
throw new AISDKError({
|
|
709
746
|
name: "VERTEX_VIDEO_GENERATION_ERROR",
|
|
710
747
|
message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
|
|
711
748
|
});
|
|
@@ -735,7 +772,7 @@ var GoogleVertexVideoModel = class {
|
|
|
735
772
|
}
|
|
736
773
|
}
|
|
737
774
|
if (videos.length === 0) {
|
|
738
|
-
throw new
|
|
775
|
+
throw new AISDKError({
|
|
739
776
|
name: "VERTEX_VIDEO_GENERATION_ERROR",
|
|
740
777
|
message: "No valid videos in response"
|
|
741
778
|
});
|
|
@@ -756,38 +793,38 @@ var GoogleVertexVideoModel = class {
|
|
|
756
793
|
};
|
|
757
794
|
}
|
|
758
795
|
};
|
|
759
|
-
var vertexOperationSchema =
|
|
760
|
-
name:
|
|
761
|
-
done:
|
|
762
|
-
error:
|
|
763
|
-
code:
|
|
764
|
-
message:
|
|
765
|
-
status:
|
|
796
|
+
var vertexOperationSchema = z5.object({
|
|
797
|
+
name: z5.string().nullish(),
|
|
798
|
+
done: z5.boolean().nullish(),
|
|
799
|
+
error: z5.object({
|
|
800
|
+
code: z5.number().nullish(),
|
|
801
|
+
message: z5.string(),
|
|
802
|
+
status: z5.string().nullish()
|
|
766
803
|
}).nullish(),
|
|
767
|
-
response:
|
|
768
|
-
videos:
|
|
769
|
-
|
|
770
|
-
bytesBase64Encoded:
|
|
771
|
-
gcsUri:
|
|
772
|
-
mimeType:
|
|
804
|
+
response: z5.object({
|
|
805
|
+
videos: z5.array(
|
|
806
|
+
z5.object({
|
|
807
|
+
bytesBase64Encoded: z5.string().nullish(),
|
|
808
|
+
gcsUri: z5.string().nullish(),
|
|
809
|
+
mimeType: z5.string().nullish()
|
|
773
810
|
})
|
|
774
811
|
).nullish(),
|
|
775
|
-
raiMediaFilteredCount:
|
|
812
|
+
raiMediaFilteredCount: z5.number().nullish()
|
|
776
813
|
}).nullish()
|
|
777
814
|
});
|
|
778
|
-
var googleVertexVideoModelOptionsSchema =
|
|
779
|
-
() =>
|
|
780
|
-
|
|
781
|
-
pollIntervalMs:
|
|
782
|
-
pollTimeoutMs:
|
|
783
|
-
personGeneration:
|
|
784
|
-
negativePrompt:
|
|
785
|
-
generateAudio:
|
|
786
|
-
gcsOutputDirectory:
|
|
787
|
-
referenceImages:
|
|
788
|
-
|
|
789
|
-
bytesBase64Encoded:
|
|
790
|
-
gcsUri:
|
|
815
|
+
var googleVertexVideoModelOptionsSchema = lazySchema(
|
|
816
|
+
() => zodSchema(
|
|
817
|
+
z5.object({
|
|
818
|
+
pollIntervalMs: z5.number().positive().nullish(),
|
|
819
|
+
pollTimeoutMs: z5.number().positive().nullish(),
|
|
820
|
+
personGeneration: z5.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
821
|
+
negativePrompt: z5.string().nullish(),
|
|
822
|
+
generateAudio: z5.boolean().nullish(),
|
|
823
|
+
gcsOutputDirectory: z5.string().nullish(),
|
|
824
|
+
referenceImages: z5.array(
|
|
825
|
+
z5.object({
|
|
826
|
+
bytesBase64Encoded: z5.string().nullish(),
|
|
827
|
+
gcsUri: z5.string().nullish()
|
|
791
828
|
})
|
|
792
829
|
).nullish()
|
|
793
830
|
}).passthrough()
|
|
@@ -801,7 +838,7 @@ function createExpressModeFetch(apiKey, customFetch) {
|
|
|
801
838
|
const modifiedInit = {
|
|
802
839
|
...init,
|
|
803
840
|
headers: {
|
|
804
|
-
...(init == null ? void 0 : init.headers) ?
|
|
841
|
+
...(init == null ? void 0 : init.headers) ? normalizeHeaders(init.headers) : {},
|
|
805
842
|
"x-goog-api-key": apiKey
|
|
806
843
|
}
|
|
807
844
|
};
|
|
@@ -809,17 +846,17 @@ function createExpressModeFetch(apiKey, customFetch) {
|
|
|
809
846
|
};
|
|
810
847
|
}
|
|
811
848
|
function createVertex(options = {}) {
|
|
812
|
-
const apiKey =
|
|
849
|
+
const apiKey = loadOptionalSetting({
|
|
813
850
|
settingValue: options.apiKey,
|
|
814
851
|
environmentVariableName: "GOOGLE_VERTEX_API_KEY"
|
|
815
852
|
});
|
|
816
|
-
const loadVertexProject = () =>
|
|
853
|
+
const loadVertexProject = () => loadSetting({
|
|
817
854
|
settingValue: options.project,
|
|
818
855
|
settingName: "project",
|
|
819
856
|
environmentVariableName: "GOOGLE_VERTEX_PROJECT",
|
|
820
857
|
description: "Google Vertex project"
|
|
821
858
|
});
|
|
822
|
-
const loadVertexLocation = () =>
|
|
859
|
+
const loadVertexLocation = () => loadSetting({
|
|
823
860
|
settingValue: options.location,
|
|
824
861
|
settingName: "location",
|
|
825
862
|
environmentVariableName: "GOOGLE_VERTEX_LOCATION",
|
|
@@ -828,18 +865,18 @@ function createVertex(options = {}) {
|
|
|
828
865
|
const loadBaseURL = () => {
|
|
829
866
|
var _a, _b;
|
|
830
867
|
if (apiKey) {
|
|
831
|
-
return (_a =
|
|
868
|
+
return (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : EXPRESS_MODE_BASE_URL;
|
|
832
869
|
}
|
|
833
870
|
const region = loadVertexLocation();
|
|
834
871
|
const project = loadVertexProject();
|
|
835
872
|
const baseHost = `${region === "global" ? "" : region + "-"}aiplatform.googleapis.com`;
|
|
836
|
-
return (_b =
|
|
873
|
+
return (_b = withoutTrailingSlash(options.baseURL)) != null ? _b : `https://${baseHost}/v1beta1/projects/${project}/locations/${region}/publishers/google`;
|
|
837
874
|
};
|
|
838
875
|
const createConfig = (name) => {
|
|
839
876
|
const getHeaders = async () => {
|
|
840
877
|
var _a;
|
|
841
|
-
const originalHeaders = await (
|
|
842
|
-
return
|
|
878
|
+
const originalHeaders = await resolve4((_a = options.headers) != null ? _a : {});
|
|
879
|
+
return withUserAgentSuffix(
|
|
843
880
|
originalHeaders,
|
|
844
881
|
`ai-sdk/google-vertex/${VERSION}`
|
|
845
882
|
);
|
|
@@ -853,9 +890,9 @@ function createVertex(options = {}) {
|
|
|
853
890
|
};
|
|
854
891
|
const createChatModel = (modelId) => {
|
|
855
892
|
var _a;
|
|
856
|
-
return new
|
|
893
|
+
return new GoogleLanguageModel2(modelId, {
|
|
857
894
|
...createConfig("chat"),
|
|
858
|
-
generateId: (_a = options.generateId) != null ? _a :
|
|
895
|
+
generateId: (_a = options.generateId) != null ? _a : generateId,
|
|
859
896
|
supportedUrls: () => ({
|
|
860
897
|
"*": [
|
|
861
898
|
// HTTP URLs:
|
|
@@ -871,14 +908,14 @@ function createVertex(options = {}) {
|
|
|
871
908
|
var _a;
|
|
872
909
|
return new GoogleVertexImageModel(modelId, {
|
|
873
910
|
...createConfig("image"),
|
|
874
|
-
generateId: (_a = options.generateId) != null ? _a :
|
|
911
|
+
generateId: (_a = options.generateId) != null ? _a : generateId
|
|
875
912
|
});
|
|
876
913
|
};
|
|
877
914
|
const createVideoModel = (modelId) => {
|
|
878
915
|
var _a;
|
|
879
916
|
return new GoogleVertexVideoModel(modelId, {
|
|
880
917
|
...createConfig("video"),
|
|
881
|
-
generateId: (_a = options.generateId) != null ? _a :
|
|
918
|
+
generateId: (_a = options.generateId) != null ? _a : generateId
|
|
882
919
|
});
|
|
883
920
|
};
|
|
884
921
|
const provider = function(modelId) {
|
|
@@ -889,7 +926,7 @@ function createVertex(options = {}) {
|
|
|
889
926
|
}
|
|
890
927
|
return createChatModel(modelId);
|
|
891
928
|
};
|
|
892
|
-
provider.specificationVersion = "
|
|
929
|
+
provider.specificationVersion = "v4";
|
|
893
930
|
provider.languageModel = createChatModel;
|
|
894
931
|
provider.embeddingModel = createEmbeddingModel;
|
|
895
932
|
provider.textEmbeddingModel = createEmbeddingModel;
|
|
@@ -902,23 +939,28 @@ function createVertex(options = {}) {
|
|
|
902
939
|
}
|
|
903
940
|
|
|
904
941
|
// src/edge/google-vertex-auth-edge.ts
|
|
905
|
-
|
|
942
|
+
import {
|
|
943
|
+
loadOptionalSetting as loadOptionalSetting2,
|
|
944
|
+
loadSetting as loadSetting2,
|
|
945
|
+
withUserAgentSuffix as withUserAgentSuffix2,
|
|
946
|
+
getRuntimeEnvironmentUserAgent
|
|
947
|
+
} from "@ai-sdk/provider-utils";
|
|
906
948
|
var loadCredentials = async () => {
|
|
907
949
|
try {
|
|
908
950
|
return {
|
|
909
|
-
clientEmail: (
|
|
951
|
+
clientEmail: loadSetting2({
|
|
910
952
|
settingValue: void 0,
|
|
911
953
|
settingName: "clientEmail",
|
|
912
954
|
environmentVariableName: "GOOGLE_CLIENT_EMAIL",
|
|
913
955
|
description: "Google client email"
|
|
914
956
|
}),
|
|
915
|
-
privateKey: (
|
|
957
|
+
privateKey: loadSetting2({
|
|
916
958
|
settingValue: void 0,
|
|
917
959
|
settingName: "privateKey",
|
|
918
960
|
environmentVariableName: "GOOGLE_PRIVATE_KEY",
|
|
919
961
|
description: "Google private key"
|
|
920
962
|
}),
|
|
921
|
-
privateKeyId: (
|
|
963
|
+
privateKeyId: loadOptionalSetting2({
|
|
922
964
|
settingValue: void 0,
|
|
923
965
|
environmentVariableName: "GOOGLE_PRIVATE_KEY_ID"
|
|
924
966
|
})
|
|
@@ -987,10 +1029,10 @@ async function generateAuthToken(credentials) {
|
|
|
987
1029
|
const jwt = await buildJwt(creds);
|
|
988
1030
|
const response = await fetch("https://oauth2.googleapis.com/token", {
|
|
989
1031
|
method: "POST",
|
|
990
|
-
headers: (
|
|
1032
|
+
headers: withUserAgentSuffix2(
|
|
991
1033
|
{ "Content-Type": "application/x-www-form-urlencoded" },
|
|
992
1034
|
`ai-sdk/google-vertex/${VERSION}`,
|
|
993
|
-
|
|
1035
|
+
getRuntimeEnvironmentUserAgent()
|
|
994
1036
|
),
|
|
995
1037
|
body: new URLSearchParams({
|
|
996
1038
|
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
|
|
@@ -1009,7 +1051,7 @@ async function generateAuthToken(credentials) {
|
|
|
1009
1051
|
|
|
1010
1052
|
// src/edge/google-vertex-provider-edge.ts
|
|
1011
1053
|
function createVertex2(options = {}) {
|
|
1012
|
-
const apiKey = (
|
|
1054
|
+
const apiKey = loadOptionalSetting3({
|
|
1013
1055
|
settingValue: options.apiKey,
|
|
1014
1056
|
environmentVariableName: "GOOGLE_VERTEX_API_KEY"
|
|
1015
1057
|
});
|
|
@@ -1022,14 +1064,13 @@ function createVertex2(options = {}) {
|
|
|
1022
1064
|
Authorization: `Bearer ${await generateAuthToken(
|
|
1023
1065
|
options.googleCredentials
|
|
1024
1066
|
)}`,
|
|
1025
|
-
...await (
|
|
1067
|
+
...await resolve5(options.headers)
|
|
1026
1068
|
})
|
|
1027
1069
|
});
|
|
1028
1070
|
}
|
|
1029
1071
|
var vertex = createVertex2();
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
createVertex,
|
|
1072
|
+
export {
|
|
1073
|
+
createVertex2 as createVertex,
|
|
1033
1074
|
vertex
|
|
1034
|
-
}
|
|
1075
|
+
};
|
|
1035
1076
|
//# sourceMappingURL=index.js.map
|