@ai-sdk/google-vertex 5.0.0-beta.45 → 5.0.0-beta.47
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 +22 -0
- package/dist/anthropic/edge/index.js +44 -59
- package/dist/anthropic/edge/index.js.map +1 -1
- package/dist/anthropic/index.js +34 -54
- package/dist/anthropic/index.js.map +1 -1
- package/dist/edge/index.js +184 -170
- package/dist/edge/index.js.map +1 -1
- package/dist/index.js +175 -167
- package/dist/index.js.map +1 -1
- package/dist/maas/edge/index.js +27 -46
- package/dist/maas/edge/index.js.map +1 -1
- package/dist/maas/index.js +17 -41
- package/dist/maas/index.js.map +1 -1
- package/package.json +20 -20
- package/dist/anthropic/edge/index.d.mts +0 -276
- package/dist/anthropic/edge/index.mjs +0 -281
- package/dist/anthropic/edge/index.mjs.map +0 -1
- package/dist/anthropic/index.d.mts +0 -260
- package/dist/anthropic/index.mjs +0 -186
- 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/maas/edge/index.d.mts +0 -76
- package/dist/maas/edge/index.mjs +0 -196
- package/dist/maas/edge/index.mjs.map +0 -1
- package/dist/maas/index.d.mts +0 -60
- package/dist/maas/index.mjs +0 -101
- package/dist/maas/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 index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
VERSION: () => VERSION,
|
|
24
|
-
createVertex: () => createVertex2,
|
|
25
|
-
vertex: () => vertex
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(index_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,44 @@ 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.47" : "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
|
+
} from "@ai-sdk/provider-utils";
|
|
51
|
+
import { z as z3 } from "zod/v4";
|
|
64
52
|
|
|
65
53
|
// src/google-vertex-error.ts
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
var googleVertexErrorDataSchema =
|
|
69
|
-
error:
|
|
70
|
-
code:
|
|
71
|
-
message:
|
|
72
|
-
status:
|
|
54
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
55
|
+
import { z } from "zod/v4";
|
|
56
|
+
var googleVertexErrorDataSchema = z.object({
|
|
57
|
+
error: z.object({
|
|
58
|
+
code: z.number().nullable(),
|
|
59
|
+
message: z.string(),
|
|
60
|
+
status: z.string()
|
|
73
61
|
})
|
|
74
62
|
});
|
|
75
|
-
var googleVertexFailedResponseHandler =
|
|
63
|
+
var googleVertexFailedResponseHandler = createJsonErrorResponseHandler(
|
|
76
64
|
{
|
|
77
65
|
errorSchema: googleVertexErrorDataSchema,
|
|
78
66
|
errorToMessage: (data) => data.error.message
|
|
@@ -80,13 +68,13 @@ var googleVertexFailedResponseHandler = (0, import_provider_utils.createJsonErro
|
|
|
80
68
|
);
|
|
81
69
|
|
|
82
70
|
// src/google-vertex-embedding-options.ts
|
|
83
|
-
|
|
84
|
-
var googleVertexEmbeddingModelOptions =
|
|
71
|
+
import { z as z2 } from "zod/v4";
|
|
72
|
+
var googleVertexEmbeddingModelOptions = z2.object({
|
|
85
73
|
/**
|
|
86
74
|
* Optional. Optional reduced dimension for the output embedding.
|
|
87
75
|
* If set, excessive values in the output embedding are truncated from the end.
|
|
88
76
|
*/
|
|
89
|
-
outputDimensionality:
|
|
77
|
+
outputDimensionality: z2.number().optional(),
|
|
90
78
|
/**
|
|
91
79
|
* Optional. Specifies the task type for generating embeddings.
|
|
92
80
|
* Supported task types:
|
|
@@ -99,7 +87,7 @@ var googleVertexEmbeddingModelOptions = import_v42.z.object({
|
|
|
99
87
|
* - FACT_VERIFICATION: Optimized for verifying factual information.
|
|
100
88
|
* - CODE_RETRIEVAL_QUERY: Optimized for retrieving code blocks based on natural language queries.
|
|
101
89
|
*/
|
|
102
|
-
taskType:
|
|
90
|
+
taskType: z2.enum([
|
|
103
91
|
"SEMANTIC_SIMILARITY",
|
|
104
92
|
"CLASSIFICATION",
|
|
105
93
|
"CLUSTERING",
|
|
@@ -114,12 +102,12 @@ var googleVertexEmbeddingModelOptions = import_v42.z.object({
|
|
|
114
102
|
* Only valid when task_type is set to 'RETRIEVAL_DOCUMENT'.
|
|
115
103
|
* Helps the model produce better embeddings by providing additional context.
|
|
116
104
|
*/
|
|
117
|
-
title:
|
|
105
|
+
title: z2.string().optional(),
|
|
118
106
|
/**
|
|
119
107
|
* Optional. When set to true, input text will be truncated. When set to false,
|
|
120
108
|
* an error is returned if the input text is longer than the maximum length supported by the model. Defaults to true.
|
|
121
109
|
*/
|
|
122
|
-
autoTruncate:
|
|
110
|
+
autoTruncate: z2.boolean().optional()
|
|
123
111
|
});
|
|
124
112
|
|
|
125
113
|
// src/google-vertex-embedding-model.ts
|
|
@@ -140,13 +128,13 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
140
128
|
abortSignal,
|
|
141
129
|
providerOptions
|
|
142
130
|
}) {
|
|
143
|
-
let googleOptions = await
|
|
131
|
+
let googleOptions = await parseProviderOptions({
|
|
144
132
|
provider: "vertex",
|
|
145
133
|
providerOptions,
|
|
146
134
|
schema: googleVertexEmbeddingModelOptions
|
|
147
135
|
});
|
|
148
136
|
if (googleOptions == null) {
|
|
149
|
-
googleOptions = await
|
|
137
|
+
googleOptions = await parseProviderOptions({
|
|
150
138
|
provider: "google",
|
|
151
139
|
providerOptions,
|
|
152
140
|
schema: googleVertexEmbeddingModelOptions
|
|
@@ -154,15 +142,15 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
154
142
|
}
|
|
155
143
|
googleOptions = googleOptions != null ? googleOptions : {};
|
|
156
144
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
157
|
-
throw new
|
|
145
|
+
throw new TooManyEmbeddingValuesForCallError({
|
|
158
146
|
provider: this.provider,
|
|
159
147
|
modelId: this.modelId,
|
|
160
148
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
161
149
|
values
|
|
162
150
|
});
|
|
163
151
|
}
|
|
164
|
-
const mergedHeaders =
|
|
165
|
-
await
|
|
152
|
+
const mergedHeaders = combineHeaders(
|
|
153
|
+
await resolve(this.config.headers),
|
|
166
154
|
headers
|
|
167
155
|
);
|
|
168
156
|
const url = `${this.config.baseURL}/models/${this.modelId}:predict`;
|
|
@@ -170,7 +158,7 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
170
158
|
responseHeaders,
|
|
171
159
|
value: response,
|
|
172
160
|
rawValue
|
|
173
|
-
} = await
|
|
161
|
+
} = await postJsonToApi({
|
|
174
162
|
url,
|
|
175
163
|
headers: mergedHeaders,
|
|
176
164
|
body: {
|
|
@@ -185,7 +173,7 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
185
173
|
}
|
|
186
174
|
},
|
|
187
175
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
188
|
-
successfulResponseHandler:
|
|
176
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
189
177
|
googleVertexTextEmbeddingResponseSchema
|
|
190
178
|
),
|
|
191
179
|
abortSignal,
|
|
@@ -206,13 +194,13 @@ var GoogleVertexEmbeddingModel = class {
|
|
|
206
194
|
};
|
|
207
195
|
}
|
|
208
196
|
};
|
|
209
|
-
var googleVertexTextEmbeddingResponseSchema =
|
|
210
|
-
predictions:
|
|
211
|
-
|
|
212
|
-
embeddings:
|
|
213
|
-
values:
|
|
214
|
-
statistics:
|
|
215
|
-
token_count:
|
|
197
|
+
var googleVertexTextEmbeddingResponseSchema = z3.object({
|
|
198
|
+
predictions: z3.array(
|
|
199
|
+
z3.object({
|
|
200
|
+
embeddings: z3.object({
|
|
201
|
+
values: z3.array(z3.number()),
|
|
202
|
+
statistics: z3.object({
|
|
203
|
+
token_count: z3.number()
|
|
216
204
|
})
|
|
217
205
|
})
|
|
218
206
|
})
|
|
@@ -220,9 +208,18 @@ var googleVertexTextEmbeddingResponseSchema = import_v43.z.object({
|
|
|
220
208
|
});
|
|
221
209
|
|
|
222
210
|
// src/google-vertex-image-model.ts
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
211
|
+
import { GoogleGenerativeAILanguageModel } from "@ai-sdk/google/internal";
|
|
212
|
+
import {
|
|
213
|
+
combineHeaders as combineHeaders2,
|
|
214
|
+
convertToBase64,
|
|
215
|
+
convertUint8ArrayToBase64,
|
|
216
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
217
|
+
generateId as defaultGenerateId,
|
|
218
|
+
parseProviderOptions as parseProviderOptions2,
|
|
219
|
+
postJsonToApi as postJsonToApi2,
|
|
220
|
+
resolve as resolve2
|
|
221
|
+
} from "@ai-sdk/provider-utils";
|
|
222
|
+
import { z as z4 } from "zod/v4";
|
|
226
223
|
var GoogleVertexImageModel = class {
|
|
227
224
|
constructor(modelId, config) {
|
|
228
225
|
this.modelId = modelId;
|
|
@@ -265,7 +262,7 @@ var GoogleVertexImageModel = class {
|
|
|
265
262
|
details: "This model does not support the `size` option. Use `aspectRatio` instead."
|
|
266
263
|
});
|
|
267
264
|
}
|
|
268
|
-
const vertexImageOptions = await (
|
|
265
|
+
const vertexImageOptions = await parseProviderOptions2({
|
|
269
266
|
provider: "vertex",
|
|
270
267
|
providerOptions,
|
|
271
268
|
schema: googleVertexImageModelOptionsSchema
|
|
@@ -327,12 +324,12 @@ var GoogleVertexImageModel = class {
|
|
|
327
324
|
};
|
|
328
325
|
}
|
|
329
326
|
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 (
|
|
327
|
+
const { value: response, responseHeaders } = await postJsonToApi2({
|
|
331
328
|
url: `${this.config.baseURL}/models/${this.modelId}:predict`,
|
|
332
|
-
headers: (
|
|
329
|
+
headers: combineHeaders2(await resolve2(this.config.headers), headers),
|
|
333
330
|
body,
|
|
334
331
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
335
|
-
successfulResponseHandler: (
|
|
332
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
336
333
|
vertexImageResponseSchema
|
|
337
334
|
),
|
|
338
335
|
abortSignal,
|
|
@@ -416,12 +413,12 @@ var GoogleVertexImageModel = class {
|
|
|
416
413
|
const languageModelPrompt = [
|
|
417
414
|
{ role: "user", content: userContent }
|
|
418
415
|
];
|
|
419
|
-
const languageModel = new
|
|
416
|
+
const languageModel = new GoogleGenerativeAILanguageModel(this.modelId, {
|
|
420
417
|
provider: this.config.provider,
|
|
421
418
|
baseURL: this.config.baseURL,
|
|
422
419
|
headers: (_a = this.config.headers) != null ? _a : {},
|
|
423
420
|
fetch: this.config.fetch,
|
|
424
|
-
generateId: (_b = this.config.generateId) != null ? _b :
|
|
421
|
+
generateId: (_b = this.config.generateId) != null ? _b : defaultGenerateId,
|
|
425
422
|
supportedUrls: () => ({
|
|
426
423
|
"*": [/^https?:\/\/.*$/, /^gs:\/\/.*$/]
|
|
427
424
|
})
|
|
@@ -445,7 +442,7 @@ var GoogleVertexImageModel = class {
|
|
|
445
442
|
const images = [];
|
|
446
443
|
for (const part of result.content) {
|
|
447
444
|
if (part.type === "file" && part.mediaType.startsWith("image/")) {
|
|
448
|
-
images.push(
|
|
445
|
+
images.push(convertToBase64(part.data));
|
|
449
446
|
}
|
|
450
447
|
}
|
|
451
448
|
return {
|
|
@@ -472,41 +469,41 @@ var GoogleVertexImageModel = class {
|
|
|
472
469
|
function isGeminiModel(modelId) {
|
|
473
470
|
return modelId.startsWith("gemini-");
|
|
474
471
|
}
|
|
475
|
-
var vertexImageResponseSchema =
|
|
476
|
-
predictions:
|
|
477
|
-
|
|
478
|
-
bytesBase64Encoded:
|
|
479
|
-
mimeType:
|
|
480
|
-
prompt:
|
|
472
|
+
var vertexImageResponseSchema = z4.object({
|
|
473
|
+
predictions: z4.array(
|
|
474
|
+
z4.object({
|
|
475
|
+
bytesBase64Encoded: z4.string(),
|
|
476
|
+
mimeType: z4.string(),
|
|
477
|
+
prompt: z4.string().nullish()
|
|
481
478
|
})
|
|
482
479
|
).nullish()
|
|
483
480
|
});
|
|
484
|
-
var googleVertexImageModelOptionsSchema =
|
|
485
|
-
negativePrompt:
|
|
486
|
-
personGeneration:
|
|
487
|
-
safetySetting:
|
|
481
|
+
var googleVertexImageModelOptionsSchema = z4.object({
|
|
482
|
+
negativePrompt: z4.string().nullish(),
|
|
483
|
+
personGeneration: z4.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
484
|
+
safetySetting: z4.enum([
|
|
488
485
|
"block_low_and_above",
|
|
489
486
|
"block_medium_and_above",
|
|
490
487
|
"block_only_high",
|
|
491
488
|
"block_none"
|
|
492
489
|
]).nullish(),
|
|
493
|
-
addWatermark:
|
|
494
|
-
storageUri:
|
|
495
|
-
sampleImageSize:
|
|
490
|
+
addWatermark: z4.boolean().nullish(),
|
|
491
|
+
storageUri: z4.string().nullish(),
|
|
492
|
+
sampleImageSize: z4.enum(["1K", "2K"]).nullish(),
|
|
496
493
|
/**
|
|
497
494
|
* Configuration for image editing operations
|
|
498
495
|
*/
|
|
499
|
-
edit:
|
|
496
|
+
edit: z4.object({
|
|
500
497
|
/**
|
|
501
498
|
* An integer that represents the number of sampling steps.
|
|
502
499
|
* A higher value offers better image quality, a lower value offers better latency.
|
|
503
500
|
* Try 35 steps to start. If the quality doesn't meet your requirements,
|
|
504
501
|
* increase the value towards an upper limit of 75.
|
|
505
502
|
*/
|
|
506
|
-
baseSteps:
|
|
503
|
+
baseSteps: z4.number().nullish(),
|
|
507
504
|
// Edit mode options
|
|
508
505
|
// https://cloud.google.com/vertex-ai/generative-ai/docs/image/edit-insert-objects
|
|
509
|
-
mode:
|
|
506
|
+
mode: z4.enum([
|
|
510
507
|
"EDIT_MODE_INPAINT_INSERTION",
|
|
511
508
|
"EDIT_MODE_INPAINT_REMOVAL",
|
|
512
509
|
"EDIT_MODE_OUTPAINT",
|
|
@@ -522,7 +519,7 @@ var googleVertexImageModelOptionsSchema = import_v44.z.object({
|
|
|
522
519
|
* - `MASK_MODE_CLOTHING_AREA` - Masks from segmenting the clothing area with open-vocab segmentation.
|
|
523
520
|
* - `MASK_MODE_PARSED_PERSON` - Masks from segmenting the person body and clothing using the person-parsing model.
|
|
524
521
|
*/
|
|
525
|
-
maskMode:
|
|
522
|
+
maskMode: z4.enum([
|
|
526
523
|
"MASK_MODE_DEFAULT",
|
|
527
524
|
"MASK_MODE_USER_PROVIDED",
|
|
528
525
|
"MASK_MODE_DETECTION_BOX",
|
|
@@ -534,7 +531,7 @@ var googleVertexImageModelOptionsSchema = import_v44.z.object({
|
|
|
534
531
|
* percentage of the image width to grow the mask by. Using dilation helps
|
|
535
532
|
* compensate for imprecise masks. We recommend a value of 0.01.
|
|
536
533
|
*/
|
|
537
|
-
maskDilation:
|
|
534
|
+
maskDilation: z4.number().nullish()
|
|
538
535
|
}).nullish()
|
|
539
536
|
});
|
|
540
537
|
function getBase64Data(file) {
|
|
@@ -546,25 +543,37 @@ function getBase64Data(file) {
|
|
|
546
543
|
if (typeof file.data === "string") {
|
|
547
544
|
return file.data;
|
|
548
545
|
}
|
|
549
|
-
return
|
|
546
|
+
return convertUint8ArrayToBase64(file.data);
|
|
550
547
|
}
|
|
551
548
|
|
|
552
549
|
// src/google-vertex-tools.ts
|
|
553
|
-
|
|
550
|
+
import { googleTools } from "@ai-sdk/google/internal";
|
|
554
551
|
var googleVertexTools = {
|
|
555
|
-
googleSearch:
|
|
556
|
-
enterpriseWebSearch:
|
|
557
|
-
googleMaps:
|
|
558
|
-
urlContext:
|
|
559
|
-
fileSearch:
|
|
560
|
-
codeExecution:
|
|
561
|
-
vertexRagStore:
|
|
552
|
+
googleSearch: googleTools.googleSearch,
|
|
553
|
+
enterpriseWebSearch: googleTools.enterpriseWebSearch,
|
|
554
|
+
googleMaps: googleTools.googleMaps,
|
|
555
|
+
urlContext: googleTools.urlContext,
|
|
556
|
+
fileSearch: googleTools.fileSearch,
|
|
557
|
+
codeExecution: googleTools.codeExecution,
|
|
558
|
+
vertexRagStore: googleTools.vertexRagStore
|
|
562
559
|
};
|
|
563
560
|
|
|
564
561
|
// src/google-vertex-video-model.ts
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
562
|
+
import {
|
|
563
|
+
AISDKError
|
|
564
|
+
} from "@ai-sdk/provider";
|
|
565
|
+
import {
|
|
566
|
+
combineHeaders as combineHeaders3,
|
|
567
|
+
convertUint8ArrayToBase64 as convertUint8ArrayToBase642,
|
|
568
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
569
|
+
delay,
|
|
570
|
+
lazySchema,
|
|
571
|
+
parseProviderOptions as parseProviderOptions3,
|
|
572
|
+
postJsonToApi as postJsonToApi3,
|
|
573
|
+
resolve as resolve3,
|
|
574
|
+
zodSchema
|
|
575
|
+
} from "@ai-sdk/provider-utils";
|
|
576
|
+
import { z as z5 } from "zod/v4";
|
|
568
577
|
var GoogleVertexVideoModel = class {
|
|
569
578
|
constructor(modelId, config) {
|
|
570
579
|
this.modelId = modelId;
|
|
@@ -581,7 +590,7 @@ var GoogleVertexVideoModel = class {
|
|
|
581
590
|
var _a, _b, _c, _d, _e, _f;
|
|
582
591
|
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
592
|
const warnings = [];
|
|
584
|
-
const vertexOptions = await (
|
|
593
|
+
const vertexOptions = await parseProviderOptions3({
|
|
585
594
|
provider: "vertex",
|
|
586
595
|
providerOptions: options.providerOptions,
|
|
587
596
|
schema: googleVertexVideoModelOptionsSchema
|
|
@@ -599,7 +608,7 @@ var GoogleVertexVideoModel = class {
|
|
|
599
608
|
details: "Vertex AI video models require base64-encoded images or GCS URIs. URL will be ignored."
|
|
600
609
|
});
|
|
601
610
|
} else {
|
|
602
|
-
const base64Data = typeof options.image.data === "string" ? options.image.data : (
|
|
611
|
+
const base64Data = typeof options.image.data === "string" ? options.image.data : convertUint8ArrayToBase642(options.image.data);
|
|
603
612
|
instance.image = {
|
|
604
613
|
bytesBase64Encoded: base64Data,
|
|
605
614
|
mimeType: options.image.mediaType
|
|
@@ -657,17 +666,17 @@ var GoogleVertexVideoModel = class {
|
|
|
657
666
|
}
|
|
658
667
|
}
|
|
659
668
|
}
|
|
660
|
-
const { value: operation } = await (
|
|
669
|
+
const { value: operation } = await postJsonToApi3({
|
|
661
670
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
662
|
-
headers: (
|
|
663
|
-
await (
|
|
671
|
+
headers: combineHeaders3(
|
|
672
|
+
await resolve3(this.config.headers),
|
|
664
673
|
options.headers
|
|
665
674
|
),
|
|
666
675
|
body: {
|
|
667
676
|
instances,
|
|
668
677
|
parameters
|
|
669
678
|
},
|
|
670
|
-
successfulResponseHandler: (
|
|
679
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
671
680
|
vertexOperationSchema
|
|
672
681
|
),
|
|
673
682
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
@@ -676,7 +685,7 @@ var GoogleVertexVideoModel = class {
|
|
|
676
685
|
});
|
|
677
686
|
const operationName = operation.name;
|
|
678
687
|
if (!operationName) {
|
|
679
|
-
throw new
|
|
688
|
+
throw new AISDKError({
|
|
680
689
|
name: "VERTEX_VIDEO_GENERATION_ERROR",
|
|
681
690
|
message: "No operation name returned from API"
|
|
682
691
|
});
|
|
@@ -688,28 +697,28 @@ var GoogleVertexVideoModel = class {
|
|
|
688
697
|
let responseHeaders;
|
|
689
698
|
while (!finalOperation.done) {
|
|
690
699
|
if (Date.now() - startTime > pollTimeoutMs) {
|
|
691
|
-
throw new
|
|
700
|
+
throw new AISDKError({
|
|
692
701
|
name: "VERTEX_VIDEO_GENERATION_TIMEOUT",
|
|
693
702
|
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
694
703
|
});
|
|
695
704
|
}
|
|
696
|
-
await
|
|
705
|
+
await delay(pollIntervalMs);
|
|
697
706
|
if ((_f = options.abortSignal) == null ? void 0 : _f.aborted) {
|
|
698
|
-
throw new
|
|
707
|
+
throw new AISDKError({
|
|
699
708
|
name: "VERTEX_VIDEO_GENERATION_ABORTED",
|
|
700
709
|
message: "Video generation request was aborted"
|
|
701
710
|
});
|
|
702
711
|
}
|
|
703
|
-
const { value: statusOperation, responseHeaders: pollHeaders } = await (
|
|
712
|
+
const { value: statusOperation, responseHeaders: pollHeaders } = await postJsonToApi3({
|
|
704
713
|
url: `${this.config.baseURL}/models/${this.modelId}:fetchPredictOperation`,
|
|
705
|
-
headers: (
|
|
706
|
-
await (
|
|
714
|
+
headers: combineHeaders3(
|
|
715
|
+
await resolve3(this.config.headers),
|
|
707
716
|
options.headers
|
|
708
717
|
),
|
|
709
718
|
body: {
|
|
710
719
|
operationName
|
|
711
720
|
},
|
|
712
|
-
successfulResponseHandler: (
|
|
721
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
713
722
|
vertexOperationSchema
|
|
714
723
|
),
|
|
715
724
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
@@ -720,14 +729,14 @@ var GoogleVertexVideoModel = class {
|
|
|
720
729
|
responseHeaders = pollHeaders;
|
|
721
730
|
}
|
|
722
731
|
if (finalOperation.error) {
|
|
723
|
-
throw new
|
|
732
|
+
throw new AISDKError({
|
|
724
733
|
name: "VERTEX_VIDEO_GENERATION_FAILED",
|
|
725
734
|
message: `Video generation failed: ${finalOperation.error.message}`
|
|
726
735
|
});
|
|
727
736
|
}
|
|
728
737
|
const response = finalOperation.response;
|
|
729
738
|
if (!(response == null ? void 0 : response.videos) || response.videos.length === 0) {
|
|
730
|
-
throw new
|
|
739
|
+
throw new AISDKError({
|
|
731
740
|
name: "VERTEX_VIDEO_GENERATION_ERROR",
|
|
732
741
|
message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
|
|
733
742
|
});
|
|
@@ -757,7 +766,7 @@ var GoogleVertexVideoModel = class {
|
|
|
757
766
|
}
|
|
758
767
|
}
|
|
759
768
|
if (videos.length === 0) {
|
|
760
|
-
throw new
|
|
769
|
+
throw new AISDKError({
|
|
761
770
|
name: "VERTEX_VIDEO_GENERATION_ERROR",
|
|
762
771
|
message: "No valid videos in response"
|
|
763
772
|
});
|
|
@@ -778,38 +787,38 @@ var GoogleVertexVideoModel = class {
|
|
|
778
787
|
};
|
|
779
788
|
}
|
|
780
789
|
};
|
|
781
|
-
var vertexOperationSchema =
|
|
782
|
-
name:
|
|
783
|
-
done:
|
|
784
|
-
error:
|
|
785
|
-
code:
|
|
786
|
-
message:
|
|
787
|
-
status:
|
|
790
|
+
var vertexOperationSchema = z5.object({
|
|
791
|
+
name: z5.string().nullish(),
|
|
792
|
+
done: z5.boolean().nullish(),
|
|
793
|
+
error: z5.object({
|
|
794
|
+
code: z5.number().nullish(),
|
|
795
|
+
message: z5.string(),
|
|
796
|
+
status: z5.string().nullish()
|
|
788
797
|
}).nullish(),
|
|
789
|
-
response:
|
|
790
|
-
videos:
|
|
791
|
-
|
|
792
|
-
bytesBase64Encoded:
|
|
793
|
-
gcsUri:
|
|
794
|
-
mimeType:
|
|
798
|
+
response: z5.object({
|
|
799
|
+
videos: z5.array(
|
|
800
|
+
z5.object({
|
|
801
|
+
bytesBase64Encoded: z5.string().nullish(),
|
|
802
|
+
gcsUri: z5.string().nullish(),
|
|
803
|
+
mimeType: z5.string().nullish()
|
|
795
804
|
})
|
|
796
805
|
).nullish(),
|
|
797
|
-
raiMediaFilteredCount:
|
|
806
|
+
raiMediaFilteredCount: z5.number().nullish()
|
|
798
807
|
}).nullish()
|
|
799
808
|
});
|
|
800
|
-
var googleVertexVideoModelOptionsSchema =
|
|
801
|
-
() =>
|
|
802
|
-
|
|
803
|
-
pollIntervalMs:
|
|
804
|
-
pollTimeoutMs:
|
|
805
|
-
personGeneration:
|
|
806
|
-
negativePrompt:
|
|
807
|
-
generateAudio:
|
|
808
|
-
gcsOutputDirectory:
|
|
809
|
-
referenceImages:
|
|
810
|
-
|
|
811
|
-
bytesBase64Encoded:
|
|
812
|
-
gcsUri:
|
|
809
|
+
var googleVertexVideoModelOptionsSchema = lazySchema(
|
|
810
|
+
() => zodSchema(
|
|
811
|
+
z5.object({
|
|
812
|
+
pollIntervalMs: z5.number().positive().nullish(),
|
|
813
|
+
pollTimeoutMs: z5.number().positive().nullish(),
|
|
814
|
+
personGeneration: z5.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
815
|
+
negativePrompt: z5.string().nullish(),
|
|
816
|
+
generateAudio: z5.boolean().nullish(),
|
|
817
|
+
gcsOutputDirectory: z5.string().nullish(),
|
|
818
|
+
referenceImages: z5.array(
|
|
819
|
+
z5.object({
|
|
820
|
+
bytesBase64Encoded: z5.string().nullish(),
|
|
821
|
+
gcsUri: z5.string().nullish()
|
|
813
822
|
})
|
|
814
823
|
).nullish()
|
|
815
824
|
}).passthrough()
|
|
@@ -823,7 +832,7 @@ function createExpressModeFetch(apiKey, customFetch) {
|
|
|
823
832
|
const modifiedInit = {
|
|
824
833
|
...init,
|
|
825
834
|
headers: {
|
|
826
|
-
...(init == null ? void 0 : init.headers) ?
|
|
835
|
+
...(init == null ? void 0 : init.headers) ? normalizeHeaders(init.headers) : {},
|
|
827
836
|
"x-goog-api-key": apiKey
|
|
828
837
|
}
|
|
829
838
|
};
|
|
@@ -831,17 +840,17 @@ function createExpressModeFetch(apiKey, customFetch) {
|
|
|
831
840
|
};
|
|
832
841
|
}
|
|
833
842
|
function createVertex(options = {}) {
|
|
834
|
-
const apiKey =
|
|
843
|
+
const apiKey = loadOptionalSetting({
|
|
835
844
|
settingValue: options.apiKey,
|
|
836
845
|
environmentVariableName: "GOOGLE_VERTEX_API_KEY"
|
|
837
846
|
});
|
|
838
|
-
const loadVertexProject = () =>
|
|
847
|
+
const loadVertexProject = () => loadSetting({
|
|
839
848
|
settingValue: options.project,
|
|
840
849
|
settingName: "project",
|
|
841
850
|
environmentVariableName: "GOOGLE_VERTEX_PROJECT",
|
|
842
851
|
description: "Google Vertex project"
|
|
843
852
|
});
|
|
844
|
-
const loadVertexLocation = () =>
|
|
853
|
+
const loadVertexLocation = () => loadSetting({
|
|
845
854
|
settingValue: options.location,
|
|
846
855
|
settingName: "location",
|
|
847
856
|
environmentVariableName: "GOOGLE_VERTEX_LOCATION",
|
|
@@ -850,18 +859,18 @@ function createVertex(options = {}) {
|
|
|
850
859
|
const loadBaseURL = () => {
|
|
851
860
|
var _a, _b;
|
|
852
861
|
if (apiKey) {
|
|
853
|
-
return (_a =
|
|
862
|
+
return (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : EXPRESS_MODE_BASE_URL;
|
|
854
863
|
}
|
|
855
864
|
const region = loadVertexLocation();
|
|
856
865
|
const project = loadVertexProject();
|
|
857
866
|
const baseHost = `${region === "global" ? "" : region + "-"}aiplatform.googleapis.com`;
|
|
858
|
-
return (_b =
|
|
867
|
+
return (_b = withoutTrailingSlash(options.baseURL)) != null ? _b : `https://${baseHost}/v1beta1/projects/${project}/locations/${region}/publishers/google`;
|
|
859
868
|
};
|
|
860
869
|
const createConfig = (name) => {
|
|
861
870
|
const getHeaders = async () => {
|
|
862
871
|
var _a;
|
|
863
|
-
const originalHeaders = await (
|
|
864
|
-
return
|
|
872
|
+
const originalHeaders = await resolve4((_a = options.headers) != null ? _a : {});
|
|
873
|
+
return withUserAgentSuffix(
|
|
865
874
|
originalHeaders,
|
|
866
875
|
`ai-sdk/google-vertex/${VERSION}`
|
|
867
876
|
);
|
|
@@ -875,9 +884,9 @@ function createVertex(options = {}) {
|
|
|
875
884
|
};
|
|
876
885
|
const createChatModel = (modelId) => {
|
|
877
886
|
var _a;
|
|
878
|
-
return new
|
|
887
|
+
return new GoogleGenerativeAILanguageModel2(modelId, {
|
|
879
888
|
...createConfig("chat"),
|
|
880
|
-
generateId: (_a = options.generateId) != null ? _a :
|
|
889
|
+
generateId: (_a = options.generateId) != null ? _a : generateId,
|
|
881
890
|
supportedUrls: () => ({
|
|
882
891
|
"*": [
|
|
883
892
|
// HTTP URLs:
|
|
@@ -893,14 +902,14 @@ function createVertex(options = {}) {
|
|
|
893
902
|
var _a;
|
|
894
903
|
return new GoogleVertexImageModel(modelId, {
|
|
895
904
|
...createConfig("image"),
|
|
896
|
-
generateId: (_a = options.generateId) != null ? _a :
|
|
905
|
+
generateId: (_a = options.generateId) != null ? _a : generateId
|
|
897
906
|
});
|
|
898
907
|
};
|
|
899
908
|
const createVideoModel = (modelId) => {
|
|
900
909
|
var _a;
|
|
901
910
|
return new GoogleVertexVideoModel(modelId, {
|
|
902
911
|
...createConfig("video"),
|
|
903
|
-
generateId: (_a = options.generateId) != null ? _a :
|
|
912
|
+
generateId: (_a = options.generateId) != null ? _a : generateId
|
|
904
913
|
});
|
|
905
914
|
};
|
|
906
915
|
const provider = function(modelId) {
|
|
@@ -925,7 +934,7 @@ function createVertex(options = {}) {
|
|
|
925
934
|
|
|
926
935
|
// src/google-vertex-provider-node.ts
|
|
927
936
|
function createVertex2(options = {}) {
|
|
928
|
-
const apiKey = (
|
|
937
|
+
const apiKey = loadOptionalSetting2({
|
|
929
938
|
settingValue: options.apiKey,
|
|
930
939
|
environmentVariableName: "GOOGLE_VERTEX_API_KEY"
|
|
931
940
|
});
|
|
@@ -938,15 +947,14 @@ function createVertex2(options = {}) {
|
|
|
938
947
|
Authorization: `Bearer ${await generateAuthToken(
|
|
939
948
|
options.googleAuthOptions
|
|
940
949
|
)}`,
|
|
941
|
-
...await (
|
|
950
|
+
...await resolve5(options.headers)
|
|
942
951
|
})
|
|
943
952
|
});
|
|
944
953
|
}
|
|
945
954
|
var vertex = createVertex2();
|
|
946
|
-
|
|
947
|
-
0 && (module.exports = {
|
|
955
|
+
export {
|
|
948
956
|
VERSION,
|
|
949
|
-
createVertex,
|
|
957
|
+
createVertex2 as createVertex,
|
|
950
958
|
vertex
|
|
951
|
-
}
|
|
959
|
+
};
|
|
952
960
|
//# sourceMappingURL=index.js.map
|