@ai-sdk/google-vertex 5.0.59 → 5.0.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 +10 -0
- package/dist/anthropic/edge/index.js +1 -1
- package/dist/edge/index.d.ts +1 -1
- package/dist/edge/index.js +124 -339
- package/dist/edge/index.js.map +1 -1
- package/dist/index.d.ts +3 -42
- package/dist/index.js +124 -339
- package/dist/index.js.map +1 -1
- package/dist/maas/edge/index.js +1 -1
- package/dist/xai/edge/index.js +1 -1
- package/docs/16-google-vertex.mdx +11 -208
- package/package.json +3 -3
- package/src/google-vertex-image-model-options.ts +4 -72
- package/src/google-vertex-image-model.ts +37 -232
- package/src/google-vertex-image-settings.ts +0 -6
package/dist/edge/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/edge/google-vertex-provider-edge.ts
|
|
2
|
-
import { loadOptionalSetting as loadOptionalSetting3, resolve as
|
|
2
|
+
import { loadOptionalSetting as loadOptionalSetting3, resolve as resolve6 } from "@ai-sdk/provider-utils";
|
|
3
3
|
|
|
4
4
|
// src/google-vertex-provider-base.ts
|
|
5
5
|
import {
|
|
@@ -12,13 +12,13 @@ import {
|
|
|
12
12
|
loadOptionalSetting,
|
|
13
13
|
loadSetting,
|
|
14
14
|
normalizeHeaders,
|
|
15
|
-
resolve as
|
|
15
|
+
resolve as resolve5,
|
|
16
16
|
withoutTrailingSlash,
|
|
17
17
|
withUserAgentSuffix
|
|
18
18
|
} from "@ai-sdk/provider-utils";
|
|
19
19
|
|
|
20
20
|
// src/version.ts
|
|
21
|
-
var VERSION = true ? "5.0.
|
|
21
|
+
var VERSION = true ? "5.0.60" : "0.0.0-test";
|
|
22
22
|
|
|
23
23
|
// src/google-vertex-embedding-model.ts
|
|
24
24
|
import {
|
|
@@ -259,85 +259,18 @@ function usesEmbedContentEndpoint(modelId) {
|
|
|
259
259
|
// src/google-vertex-image-model.ts
|
|
260
260
|
import { GoogleLanguageModel } from "@ai-sdk/google/internal";
|
|
261
261
|
import {
|
|
262
|
-
combineHeaders as combineHeaders2,
|
|
263
262
|
convertToBase64,
|
|
264
|
-
convertUint8ArrayToBase64,
|
|
265
|
-
createJsonResponseHandler as createJsonResponseHandler2,
|
|
266
263
|
generateId as defaultGenerateId,
|
|
267
|
-
parseProviderOptions as parseProviderOptions2,
|
|
268
|
-
postJsonToApi as postJsonToApi2,
|
|
269
|
-
resolve as resolve2,
|
|
270
264
|
serializeModelOptions as serializeModelOptions2,
|
|
271
265
|
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
|
|
272
266
|
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
|
|
273
267
|
} from "@ai-sdk/provider-utils";
|
|
274
|
-
import { z as z5 } from "zod/v4";
|
|
275
|
-
|
|
276
|
-
// src/google-vertex-image-model-options.ts
|
|
277
|
-
import { z as z4 } from "zod/v4";
|
|
278
|
-
var googleVertexImageModelOptionsSchema = z4.object({
|
|
279
|
-
negativePrompt: z4.string().nullish(),
|
|
280
|
-
personGeneration: z4.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
281
|
-
safetySetting: z4.enum([
|
|
282
|
-
"block_low_and_above",
|
|
283
|
-
"block_medium_and_above",
|
|
284
|
-
"block_only_high",
|
|
285
|
-
"block_none"
|
|
286
|
-
]).nullish(),
|
|
287
|
-
addWatermark: z4.boolean().nullish(),
|
|
288
|
-
storageUri: z4.string().nullish(),
|
|
289
|
-
sampleImageSize: z4.enum(["1K", "2K"]).nullish(),
|
|
290
|
-
/**
|
|
291
|
-
* Configuration for image editing operations
|
|
292
|
-
*/
|
|
293
|
-
edit: z4.object({
|
|
294
|
-
/**
|
|
295
|
-
* An integer that represents the number of sampling steps.
|
|
296
|
-
* A higher value offers better image quality, a lower value offers better latency.
|
|
297
|
-
* Try 35 steps to start. If the quality doesn't meet your requirements,
|
|
298
|
-
* increase the value towards an upper limit of 75.
|
|
299
|
-
*/
|
|
300
|
-
baseSteps: z4.number().nullish(),
|
|
301
|
-
// Edit mode options
|
|
302
|
-
// https://cloud.google.com/vertex-ai/generative-ai/docs/image/edit-insert-objects
|
|
303
|
-
mode: z4.enum([
|
|
304
|
-
"EDIT_MODE_INPAINT_INSERTION",
|
|
305
|
-
"EDIT_MODE_INPAINT_REMOVAL",
|
|
306
|
-
"EDIT_MODE_OUTPAINT",
|
|
307
|
-
"EDIT_MODE_CONTROLLED_EDITING",
|
|
308
|
-
"EDIT_MODE_PRODUCT_IMAGE",
|
|
309
|
-
"EDIT_MODE_BGSWAP"
|
|
310
|
-
]).nullish(),
|
|
311
|
-
/**
|
|
312
|
-
* The mask mode to use.
|
|
313
|
-
* - `MASK_MODE_DEFAULT` - Default value for mask mode.
|
|
314
|
-
* - `MASK_MODE_USER_PROVIDED` - User provided mask. No segmentation needed.
|
|
315
|
-
* - `MASK_MODE_DETECTION_BOX` - Mask from detected bounding boxes.
|
|
316
|
-
* - `MASK_MODE_CLOTHING_AREA` - Masks from segmenting the clothing area with open-vocab segmentation.
|
|
317
|
-
* - `MASK_MODE_PARSED_PERSON` - Masks from segmenting the person body and clothing using the person-parsing model.
|
|
318
|
-
*/
|
|
319
|
-
maskMode: z4.enum([
|
|
320
|
-
"MASK_MODE_DEFAULT",
|
|
321
|
-
"MASK_MODE_USER_PROVIDED",
|
|
322
|
-
"MASK_MODE_DETECTION_BOX",
|
|
323
|
-
"MASK_MODE_CLOTHING_AREA",
|
|
324
|
-
"MASK_MODE_PARSED_PERSON"
|
|
325
|
-
]).nullish(),
|
|
326
|
-
/**
|
|
327
|
-
* Optional. A float value between 0 and 1, inclusive, that represents the
|
|
328
|
-
* percentage of the image width to grow the mask by. Using dilation helps
|
|
329
|
-
* compensate for imprecise masks. We recommend a value of 0.01.
|
|
330
|
-
*/
|
|
331
|
-
maskDilation: z4.number().nullish()
|
|
332
|
-
}).nullish()
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
// src/google-vertex-image-model.ts
|
|
336
268
|
var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
337
269
|
constructor(modelId, config) {
|
|
338
270
|
this.modelId = modelId;
|
|
339
271
|
this.config = config;
|
|
340
272
|
this.specificationVersion = "v4";
|
|
273
|
+
this.maxImagesPerCall = 10;
|
|
341
274
|
}
|
|
342
275
|
static [WORKFLOW_SERIALIZE2](model) {
|
|
343
276
|
return serializeModelOptions2({
|
|
@@ -348,160 +281,28 @@ var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
|
348
281
|
static [WORKFLOW_DESERIALIZE2](options) {
|
|
349
282
|
return new _GoogleVertexImageModel(options.modelId, options.config);
|
|
350
283
|
}
|
|
351
|
-
get maxImagesPerCall() {
|
|
352
|
-
if (isGeminiModel(this.modelId)) {
|
|
353
|
-
return 10;
|
|
354
|
-
}
|
|
355
|
-
return 4;
|
|
356
|
-
}
|
|
357
284
|
get provider() {
|
|
358
285
|
return this.config.provider;
|
|
359
286
|
}
|
|
360
287
|
async doGenerate(options) {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
async doGenerateImagen({
|
|
367
|
-
prompt,
|
|
368
|
-
n,
|
|
369
|
-
size,
|
|
370
|
-
aspectRatio,
|
|
371
|
-
seed,
|
|
372
|
-
providerOptions,
|
|
373
|
-
headers,
|
|
374
|
-
abortSignal,
|
|
375
|
-
files,
|
|
376
|
-
mask
|
|
377
|
-
}) {
|
|
378
|
-
var _a, _b, _c, _d, _e, _f;
|
|
379
|
-
const warnings = [];
|
|
380
|
-
if (size != null) {
|
|
381
|
-
warnings.push({
|
|
382
|
-
type: "unsupported",
|
|
383
|
-
feature: "size",
|
|
384
|
-
details: "This model does not support the `size` option. Use `aspectRatio` instead."
|
|
385
|
-
});
|
|
288
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
289
|
+
if (!this.modelId.startsWith("gemini-")) {
|
|
290
|
+
throw new Error(
|
|
291
|
+
"Google image models other than Gemini are no longer supported. Use a model ID that starts with `gemini-`."
|
|
292
|
+
);
|
|
386
293
|
}
|
|
387
|
-
const
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
294
|
+
const {
|
|
295
|
+
prompt,
|
|
296
|
+
n,
|
|
297
|
+
size,
|
|
298
|
+
aspectRatio,
|
|
299
|
+
seed,
|
|
393
300
|
providerOptions,
|
|
394
|
-
|
|
395
|
-
});
|
|
396
|
-
const { edit, ...otherOptions } = googleVertexImageOptions != null ? googleVertexImageOptions : {};
|
|
397
|
-
const { mode: editMode, baseSteps, maskMode, maskDilation } = edit != null ? edit : {};
|
|
398
|
-
const isEditMode = files != null && files.length > 0;
|
|
399
|
-
let body;
|
|
400
|
-
if (isEditMode) {
|
|
401
|
-
const referenceImages = [];
|
|
402
|
-
for (let i = 0; i < files.length; i++) {
|
|
403
|
-
const file = files[i];
|
|
404
|
-
referenceImages.push({
|
|
405
|
-
referenceType: "REFERENCE_TYPE_RAW",
|
|
406
|
-
referenceId: i + 1,
|
|
407
|
-
referenceImage: {
|
|
408
|
-
bytesBase64Encoded: getBase64Data(file)
|
|
409
|
-
}
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
if (mask != null) {
|
|
413
|
-
referenceImages.push({
|
|
414
|
-
referenceType: "REFERENCE_TYPE_MASK",
|
|
415
|
-
referenceId: files.length + 1,
|
|
416
|
-
referenceImage: {
|
|
417
|
-
bytesBase64Encoded: getBase64Data(mask)
|
|
418
|
-
},
|
|
419
|
-
maskImageConfig: {
|
|
420
|
-
maskMode: maskMode != null ? maskMode : "MASK_MODE_USER_PROVIDED",
|
|
421
|
-
...maskDilation != null ? { dilation: maskDilation } : {}
|
|
422
|
-
}
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
body = {
|
|
426
|
-
instances: [
|
|
427
|
-
{
|
|
428
|
-
prompt,
|
|
429
|
-
referenceImages
|
|
430
|
-
}
|
|
431
|
-
],
|
|
432
|
-
parameters: {
|
|
433
|
-
sampleCount: n,
|
|
434
|
-
...aspectRatio != null ? { aspectRatio } : {},
|
|
435
|
-
...seed != null ? { seed } : {},
|
|
436
|
-
editMode: editMode != null ? editMode : "EDIT_MODE_INPAINT_INSERTION",
|
|
437
|
-
...baseSteps != null ? { editConfig: { baseSteps } } : {},
|
|
438
|
-
...otherOptions
|
|
439
|
-
}
|
|
440
|
-
};
|
|
441
|
-
} else {
|
|
442
|
-
body = {
|
|
443
|
-
instances: [{ prompt }],
|
|
444
|
-
parameters: {
|
|
445
|
-
sampleCount: n,
|
|
446
|
-
...aspectRatio != null ? { aspectRatio } : {},
|
|
447
|
-
...seed != null ? { seed } : {},
|
|
448
|
-
...otherOptions
|
|
449
|
-
}
|
|
450
|
-
};
|
|
451
|
-
}
|
|
452
|
-
const currentDate = (_d = (_c = (_b = this.config._internal) == null ? void 0 : _b.currentDate) == null ? void 0 : _c.call(_b)) != null ? _d : /* @__PURE__ */ new Date();
|
|
453
|
-
const { value: response, responseHeaders } = await postJsonToApi2({
|
|
454
|
-
url: `${this.config.baseURL}/models/${this.modelId}:predict`,
|
|
455
|
-
headers: combineHeaders2(
|
|
456
|
-
this.config.headers ? await resolve2(this.config.headers) : void 0,
|
|
457
|
-
headers
|
|
458
|
-
),
|
|
459
|
-
body,
|
|
460
|
-
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
461
|
-
successfulResponseHandler: createJsonResponseHandler2(
|
|
462
|
-
googleVertexImageResponseSchema
|
|
463
|
-
),
|
|
301
|
+
headers,
|
|
464
302
|
abortSignal,
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
images: (_f = (_e = response.predictions) == null ? void 0 : _e.map(
|
|
469
|
-
({ bytesBase64Encoded }) => bytesBase64Encoded
|
|
470
|
-
)) != null ? _f : [],
|
|
471
|
-
warnings,
|
|
472
|
-
response: {
|
|
473
|
-
timestamp: currentDate,
|
|
474
|
-
modelId: this.modelId,
|
|
475
|
-
headers: responseHeaders
|
|
476
|
-
},
|
|
477
|
-
providerMetadata: (() => {
|
|
478
|
-
var _a2, _b2;
|
|
479
|
-
const payload = {
|
|
480
|
-
images: (_b2 = (_a2 = response.predictions) == null ? void 0 : _a2.map((prediction) => {
|
|
481
|
-
const {
|
|
482
|
-
// normalize revised prompt property
|
|
483
|
-
prompt: revisedPrompt
|
|
484
|
-
} = prediction;
|
|
485
|
-
return { ...revisedPrompt != null && { revisedPrompt } };
|
|
486
|
-
})) != null ? _b2 : []
|
|
487
|
-
};
|
|
488
|
-
return { googleVertex: payload, vertex: payload };
|
|
489
|
-
})()
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
async doGenerateGemini({
|
|
493
|
-
prompt,
|
|
494
|
-
n,
|
|
495
|
-
size,
|
|
496
|
-
aspectRatio,
|
|
497
|
-
seed,
|
|
498
|
-
providerOptions,
|
|
499
|
-
headers,
|
|
500
|
-
abortSignal,
|
|
501
|
-
files,
|
|
502
|
-
mask
|
|
503
|
-
}) {
|
|
504
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
303
|
+
files,
|
|
304
|
+
mask
|
|
305
|
+
} = options;
|
|
505
306
|
const warnings = [];
|
|
506
307
|
if (mask != null) {
|
|
507
308
|
throw new Error(
|
|
@@ -557,13 +358,20 @@ var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
|
557
358
|
"*": [/^https?:\/\/.*$/, /^gs:\/\/.*$/]
|
|
558
359
|
})
|
|
559
360
|
});
|
|
560
|
-
const
|
|
361
|
+
const {
|
|
362
|
+
responseModalities: _strippedResponseModalities,
|
|
363
|
+
imageConfig: userImageConfig,
|
|
364
|
+
...userVertexOptions
|
|
365
|
+
} = (_d = (_c = providerOptions == null ? void 0 : providerOptions.googleVertex) != null ? _c : providerOptions == null ? void 0 : providerOptions.vertex) != null ? _d : {};
|
|
561
366
|
const innerVertexOptions = {
|
|
367
|
+
...userVertexOptions,
|
|
562
368
|
responseModalities: ["IMAGE"],
|
|
563
|
-
imageConfig: aspectRatio ? {
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
369
|
+
imageConfig: aspectRatio != null || userImageConfig != null ? {
|
|
370
|
+
...userImageConfig,
|
|
371
|
+
...aspectRatio != null ? {
|
|
372
|
+
aspectRatio
|
|
373
|
+
} : {}
|
|
374
|
+
} : void 0
|
|
567
375
|
};
|
|
568
376
|
const result = await languageModel.doGenerate({
|
|
569
377
|
prompt: languageModelPrompt,
|
|
@@ -575,7 +383,7 @@ var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
|
575
383
|
headers,
|
|
576
384
|
abortSignal
|
|
577
385
|
});
|
|
578
|
-
const currentDate = (
|
|
386
|
+
const currentDate = (_g = (_f = (_e = this.config._internal) == null ? void 0 : _e.currentDate) == null ? void 0 : _f.call(_e)) != null ? _g : /* @__PURE__ */ new Date();
|
|
579
387
|
const images = [];
|
|
580
388
|
for (const part of result.content) {
|
|
581
389
|
if (part.type === "file" && part.mediaType.startsWith("image/") && part.data.type === "data") {
|
|
@@ -595,52 +403,29 @@ var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
|
595
403
|
response: {
|
|
596
404
|
timestamp: currentDate,
|
|
597
405
|
modelId: this.modelId,
|
|
598
|
-
headers: (
|
|
406
|
+
headers: (_h = result.response) == null ? void 0 : _h.headers
|
|
599
407
|
},
|
|
600
408
|
usage: result.usage ? {
|
|
601
409
|
inputTokens: result.usage.inputTokens.total,
|
|
602
410
|
outputTokens: result.usage.outputTokens.total,
|
|
603
|
-
totalTokens: ((
|
|
411
|
+
totalTokens: ((_i = result.usage.inputTokens.total) != null ? _i : 0) + ((_j = result.usage.outputTokens.total) != null ? _j : 0)
|
|
604
412
|
} : void 0
|
|
605
413
|
};
|
|
606
414
|
}
|
|
607
415
|
};
|
|
608
|
-
function isGeminiModel(modelId) {
|
|
609
|
-
return modelId.startsWith("gemini-");
|
|
610
|
-
}
|
|
611
|
-
var googleVertexImageResponseSchema = z5.object({
|
|
612
|
-
predictions: z5.array(
|
|
613
|
-
z5.object({
|
|
614
|
-
bytesBase64Encoded: z5.string(),
|
|
615
|
-
mimeType: z5.string(),
|
|
616
|
-
prompt: z5.string().nullish()
|
|
617
|
-
})
|
|
618
|
-
).nullish()
|
|
619
|
-
});
|
|
620
|
-
function getBase64Data(file) {
|
|
621
|
-
if (file.type === "url") {
|
|
622
|
-
throw new Error(
|
|
623
|
-
"URL-based images are not supported for Google Vertex image editing. Please provide the image data directly."
|
|
624
|
-
);
|
|
625
|
-
}
|
|
626
|
-
if (typeof file.data === "string") {
|
|
627
|
-
return file.data;
|
|
628
|
-
}
|
|
629
|
-
return convertUint8ArrayToBase64(file.data);
|
|
630
|
-
}
|
|
631
416
|
|
|
632
417
|
// src/google-vertex-cloud-tts-speech-model.ts
|
|
633
418
|
import {
|
|
634
|
-
combineHeaders as
|
|
419
|
+
combineHeaders as combineHeaders2,
|
|
635
420
|
convertBase64ToUint8Array,
|
|
636
|
-
createJsonResponseHandler as
|
|
637
|
-
postJsonToApi as
|
|
638
|
-
resolve as
|
|
421
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
422
|
+
postJsonToApi as postJsonToApi2,
|
|
423
|
+
resolve as resolve2,
|
|
639
424
|
serializeModelOptions as serializeModelOptions3,
|
|
640
425
|
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3,
|
|
641
426
|
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3
|
|
642
427
|
} from "@ai-sdk/provider-utils";
|
|
643
|
-
import { z as
|
|
428
|
+
import { z as z4 } from "zod/v4";
|
|
644
429
|
var DEFAULT_VOICE = "Kore";
|
|
645
430
|
var DEFAULT_LANGUAGE = "en-US";
|
|
646
431
|
var CHIRP3_HD_VOICE_INFIX = "Chirp3-HD";
|
|
@@ -711,15 +496,15 @@ var GoogleVertexCloudTTSSpeechModel = class _GoogleVertexCloudTTSSpeechModel {
|
|
|
711
496
|
value: response,
|
|
712
497
|
responseHeaders,
|
|
713
498
|
rawValue: rawResponse
|
|
714
|
-
} = await
|
|
499
|
+
} = await postJsonToApi2({
|
|
715
500
|
url: CLOUD_TTS_SYNTHESIZE_URL,
|
|
716
|
-
headers:
|
|
717
|
-
this.config.headers ? await
|
|
501
|
+
headers: combineHeaders2(
|
|
502
|
+
this.config.headers ? await resolve2(this.config.headers) : void 0,
|
|
718
503
|
options.headers
|
|
719
504
|
),
|
|
720
505
|
body: requestBody,
|
|
721
506
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
722
|
-
successfulResponseHandler:
|
|
507
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
723
508
|
googleVertexCloudTTSResponseSchema
|
|
724
509
|
),
|
|
725
510
|
abortSignal: options.abortSignal,
|
|
@@ -746,8 +531,8 @@ var GoogleVertexCloudTTSSpeechModel = class _GoogleVertexCloudTTSSpeechModel {
|
|
|
746
531
|
};
|
|
747
532
|
}
|
|
748
533
|
};
|
|
749
|
-
var googleVertexCloudTTSResponseSchema =
|
|
750
|
-
audioContent:
|
|
534
|
+
var googleVertexCloudTTSResponseSchema = z4.object({
|
|
535
|
+
audioContent: z4.string().nullish()
|
|
751
536
|
});
|
|
752
537
|
|
|
753
538
|
// src/google-vertex-tools.ts
|
|
@@ -764,31 +549,31 @@ var googleVertexTools = {
|
|
|
764
549
|
|
|
765
550
|
// src/google-vertex-transcription-model.ts
|
|
766
551
|
import {
|
|
767
|
-
combineHeaders as
|
|
768
|
-
convertUint8ArrayToBase64
|
|
769
|
-
createJsonResponseHandler as
|
|
770
|
-
parseProviderOptions as
|
|
771
|
-
postJsonToApi as
|
|
772
|
-
resolve as
|
|
552
|
+
combineHeaders as combineHeaders3,
|
|
553
|
+
convertUint8ArrayToBase64,
|
|
554
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
555
|
+
parseProviderOptions as parseProviderOptions2,
|
|
556
|
+
postJsonToApi as postJsonToApi3,
|
|
557
|
+
resolve as resolve3,
|
|
773
558
|
serializeModelOptions as serializeModelOptions4,
|
|
774
559
|
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE4,
|
|
775
560
|
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE4
|
|
776
561
|
} from "@ai-sdk/provider-utils";
|
|
777
|
-
import { z as
|
|
562
|
+
import { z as z6 } from "zod/v4";
|
|
778
563
|
|
|
779
564
|
// src/google-vertex-transcription-model-options.ts
|
|
780
|
-
import { z as
|
|
781
|
-
var googleVertexTranscriptionProviderOptionsSchema =
|
|
565
|
+
import { z as z5 } from "zod/v4";
|
|
566
|
+
var googleVertexTranscriptionProviderOptionsSchema = z5.object({
|
|
782
567
|
/**
|
|
783
568
|
* BCP-47 language codes to recognize (e.g. `['en-US']`), or `['auto']` to let
|
|
784
569
|
* Chirp auto-detect the spoken language. Defaults to `['auto']`. For
|
|
785
570
|
* `telephony`, pass a supported explicit language code.
|
|
786
571
|
*/
|
|
787
|
-
languageCodes:
|
|
572
|
+
languageCodes: z5.array(z5.string()).optional(),
|
|
788
573
|
/**
|
|
789
574
|
* Whether to add punctuation to the transcript. Defaults to `true`.
|
|
790
575
|
*/
|
|
791
|
-
enableAutomaticPunctuation:
|
|
576
|
+
enableAutomaticPunctuation: z5.boolean().optional(),
|
|
792
577
|
/**
|
|
793
578
|
* Whether to include word-level timestamps. Defaults to `true` so the
|
|
794
579
|
* transcription result can include segments.
|
|
@@ -796,7 +581,7 @@ var googleVertexTranscriptionProviderOptionsSchema = z7.object({
|
|
|
796
581
|
* Enabling word-level timestamps can reduce transcription quality and speed
|
|
797
582
|
* for Chirp models.
|
|
798
583
|
*/
|
|
799
|
-
enableWordTimeOffsets:
|
|
584
|
+
enableWordTimeOffsets: z5.boolean().optional(),
|
|
800
585
|
/**
|
|
801
586
|
* The Cloud Speech-to-Text region for the request (e.g. `'us'`, `'eu'`,
|
|
802
587
|
* `'us-central1'`). Defaults to the provider `location`.
|
|
@@ -805,7 +590,7 @@ var googleVertexTranscriptionProviderOptionsSchema = z7.object({
|
|
|
805
590
|
* available in specific Speech-to-Text regions and is not available in the
|
|
806
591
|
* `global` location.
|
|
807
592
|
*/
|
|
808
|
-
region:
|
|
593
|
+
region: z5.string().optional()
|
|
809
594
|
});
|
|
810
595
|
|
|
811
596
|
// src/google-vertex-transcription-model.ts
|
|
@@ -851,7 +636,7 @@ var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
|
|
|
851
636
|
const warnings = [];
|
|
852
637
|
let googleOptions;
|
|
853
638
|
for (const provider of ["googleVertex", "vertex", "google"]) {
|
|
854
|
-
googleOptions = await
|
|
639
|
+
googleOptions = await parseProviderOptions2({
|
|
855
640
|
provider,
|
|
856
641
|
providerOptions: options.providerOptions,
|
|
857
642
|
schema: googleVertexTranscriptionProviderOptionsSchema
|
|
@@ -862,7 +647,7 @@ var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
|
|
|
862
647
|
}
|
|
863
648
|
const region = (_d = googleOptions == null ? void 0 : googleOptions.region) != null ? _d : this.config.location;
|
|
864
649
|
const languageCodes = (_e = googleOptions == null ? void 0 : googleOptions.languageCodes) != null ? _e : ["auto"];
|
|
865
|
-
const content = typeof options.audio === "string" ? options.audio :
|
|
650
|
+
const content = typeof options.audio === "string" ? options.audio : convertUint8ArrayToBase64(options.audio);
|
|
866
651
|
const requestBody = {
|
|
867
652
|
config: {
|
|
868
653
|
model: this.modelId,
|
|
@@ -883,15 +668,15 @@ var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
|
|
|
883
668
|
value: response,
|
|
884
669
|
responseHeaders,
|
|
885
670
|
rawValue: rawResponse
|
|
886
|
-
} = await
|
|
671
|
+
} = await postJsonToApi3({
|
|
887
672
|
url,
|
|
888
|
-
headers:
|
|
889
|
-
this.config.headers ? await
|
|
673
|
+
headers: combineHeaders3(
|
|
674
|
+
this.config.headers ? await resolve3(this.config.headers) : void 0,
|
|
890
675
|
options.headers
|
|
891
676
|
),
|
|
892
677
|
body: requestBody,
|
|
893
678
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
894
|
-
successfulResponseHandler:
|
|
679
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
895
680
|
googleVertexTranscriptionResponseSchema
|
|
896
681
|
),
|
|
897
682
|
abortSignal: options.abortSignal,
|
|
@@ -930,26 +715,26 @@ var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
|
|
|
930
715
|
};
|
|
931
716
|
}
|
|
932
717
|
};
|
|
933
|
-
var googleVertexTranscriptionResponseSchema =
|
|
934
|
-
results:
|
|
935
|
-
|
|
936
|
-
alternatives:
|
|
937
|
-
|
|
938
|
-
transcript:
|
|
939
|
-
words:
|
|
940
|
-
|
|
941
|
-
word:
|
|
942
|
-
startOffset:
|
|
943
|
-
endOffset:
|
|
718
|
+
var googleVertexTranscriptionResponseSchema = z6.object({
|
|
719
|
+
results: z6.array(
|
|
720
|
+
z6.object({
|
|
721
|
+
alternatives: z6.array(
|
|
722
|
+
z6.object({
|
|
723
|
+
transcript: z6.string().nullish(),
|
|
724
|
+
words: z6.array(
|
|
725
|
+
z6.object({
|
|
726
|
+
word: z6.string().nullish(),
|
|
727
|
+
startOffset: z6.string().nullish(),
|
|
728
|
+
endOffset: z6.string().nullish()
|
|
944
729
|
})
|
|
945
730
|
).nullish()
|
|
946
731
|
})
|
|
947
732
|
).nullish(),
|
|
948
|
-
languageCode:
|
|
733
|
+
languageCode: z6.string().nullish()
|
|
949
734
|
})
|
|
950
735
|
).nullish(),
|
|
951
|
-
metadata:
|
|
952
|
-
totalBilledDuration:
|
|
736
|
+
metadata: z6.object({
|
|
737
|
+
totalBilledDuration: z6.string().nullish()
|
|
953
738
|
}).nullish()
|
|
954
739
|
});
|
|
955
740
|
|
|
@@ -958,31 +743,31 @@ import {
|
|
|
958
743
|
AISDKError
|
|
959
744
|
} from "@ai-sdk/provider";
|
|
960
745
|
import {
|
|
961
|
-
combineHeaders as
|
|
962
|
-
convertUint8ArrayToBase64 as
|
|
963
|
-
createJsonResponseHandler as
|
|
964
|
-
parseProviderOptions as
|
|
965
|
-
postJsonToApi as
|
|
966
|
-
resolve as
|
|
746
|
+
combineHeaders as combineHeaders4,
|
|
747
|
+
convertUint8ArrayToBase64 as convertUint8ArrayToBase642,
|
|
748
|
+
createJsonResponseHandler as createJsonResponseHandler4,
|
|
749
|
+
parseProviderOptions as parseProviderOptions3,
|
|
750
|
+
postJsonToApi as postJsonToApi4,
|
|
751
|
+
resolve as resolve4
|
|
967
752
|
} from "@ai-sdk/provider-utils";
|
|
968
|
-
import { z as
|
|
753
|
+
import { z as z8 } from "zod/v4";
|
|
969
754
|
|
|
970
755
|
// src/google-vertex-video-model-options.ts
|
|
971
756
|
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
972
|
-
import { z as
|
|
757
|
+
import { z as z7 } from "zod/v4";
|
|
973
758
|
var googleVertexVideoModelOptionsSchema = lazySchema(
|
|
974
759
|
() => zodSchema(
|
|
975
|
-
|
|
976
|
-
pollIntervalMs:
|
|
977
|
-
pollTimeoutMs:
|
|
978
|
-
personGeneration:
|
|
979
|
-
negativePrompt:
|
|
980
|
-
generateAudio:
|
|
981
|
-
gcsOutputDirectory:
|
|
982
|
-
referenceImages:
|
|
983
|
-
|
|
984
|
-
bytesBase64Encoded:
|
|
985
|
-
gcsUri:
|
|
760
|
+
z7.looseObject({
|
|
761
|
+
pollIntervalMs: z7.number().positive().nullish(),
|
|
762
|
+
pollTimeoutMs: z7.number().positive().nullish(),
|
|
763
|
+
personGeneration: z7.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
764
|
+
negativePrompt: z7.string().nullish(),
|
|
765
|
+
generateAudio: z7.boolean().nullish(),
|
|
766
|
+
gcsOutputDirectory: z7.string().nullish(),
|
|
767
|
+
referenceImages: z7.array(
|
|
768
|
+
z7.object({
|
|
769
|
+
bytesBase64Encoded: z7.string().nullish(),
|
|
770
|
+
gcsUri: z7.string().nullish()
|
|
986
771
|
})
|
|
987
772
|
).nullish()
|
|
988
773
|
})
|
|
@@ -1023,7 +808,7 @@ function convertFileToVertexImage(file, warnings) {
|
|
|
1023
808
|
});
|
|
1024
809
|
return void 0;
|
|
1025
810
|
}
|
|
1026
|
-
const base64Data = typeof file.data === "string" ? file.data :
|
|
811
|
+
const base64Data = typeof file.data === "string" ? file.data : convertUint8ArrayToBase642(file.data);
|
|
1027
812
|
return {
|
|
1028
813
|
bytesBase64Encoded: base64Data,
|
|
1029
814
|
mimeType: file.mediaType || "image/png"
|
|
@@ -1048,11 +833,11 @@ var GoogleVertexVideoModel = class {
|
|
|
1048
833
|
async buildRequest(options) {
|
|
1049
834
|
var _a, _b;
|
|
1050
835
|
const warnings = [];
|
|
1051
|
-
const googleVertexOptions = (_a = await
|
|
836
|
+
const googleVertexOptions = (_a = await parseProviderOptions3({
|
|
1052
837
|
provider: "googleVertex",
|
|
1053
838
|
providerOptions: options.providerOptions,
|
|
1054
839
|
schema: googleVertexVideoModelOptionsSchema
|
|
1055
|
-
})) != null ? _a : await
|
|
840
|
+
})) != null ? _a : await parseProviderOptions3({
|
|
1056
841
|
provider: "vertex",
|
|
1057
842
|
providerOptions: options.providerOptions,
|
|
1058
843
|
schema: googleVertexVideoModelOptionsSchema
|
|
@@ -1203,17 +988,17 @@ var GoogleVertexVideoModel = class {
|
|
|
1203
988
|
var _a, _b, _c;
|
|
1204
989
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1205
990
|
const { instances, parameters, warnings } = await this.buildRequest(options);
|
|
1206
|
-
const { value: operation, responseHeaders } = await
|
|
991
|
+
const { value: operation, responseHeaders } = await postJsonToApi4({
|
|
1207
992
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
1208
|
-
headers:
|
|
1209
|
-
await
|
|
993
|
+
headers: combineHeaders4(
|
|
994
|
+
await resolve4(this.config.headers),
|
|
1210
995
|
options.headers
|
|
1211
996
|
),
|
|
1212
997
|
body: {
|
|
1213
998
|
instances,
|
|
1214
999
|
parameters
|
|
1215
1000
|
},
|
|
1216
|
-
successfulResponseHandler:
|
|
1001
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
1217
1002
|
googleVertexOperationSchema
|
|
1218
1003
|
),
|
|
1219
1004
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
@@ -1241,16 +1026,16 @@ var GoogleVertexVideoModel = class {
|
|
|
1241
1026
|
var _a, _b, _c;
|
|
1242
1027
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1243
1028
|
const { operationName } = options.operation;
|
|
1244
|
-
const { value: statusOperation, responseHeaders } = await
|
|
1029
|
+
const { value: statusOperation, responseHeaders } = await postJsonToApi4({
|
|
1245
1030
|
url: `${this.config.baseURL}/models/${this.modelId}:fetchPredictOperation`,
|
|
1246
|
-
headers:
|
|
1247
|
-
await
|
|
1031
|
+
headers: combineHeaders4(
|
|
1032
|
+
await resolve4(this.config.headers),
|
|
1248
1033
|
options.headers
|
|
1249
1034
|
),
|
|
1250
1035
|
body: {
|
|
1251
1036
|
operationName
|
|
1252
1037
|
},
|
|
1253
|
-
successfulResponseHandler:
|
|
1038
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
1254
1039
|
googleVertexOperationSchema
|
|
1255
1040
|
),
|
|
1256
1041
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
@@ -1286,23 +1071,23 @@ var GoogleVertexVideoModel = class {
|
|
|
1286
1071
|
});
|
|
1287
1072
|
}
|
|
1288
1073
|
};
|
|
1289
|
-
var googleVertexOperationSchema =
|
|
1290
|
-
name:
|
|
1291
|
-
done:
|
|
1292
|
-
error:
|
|
1293
|
-
code:
|
|
1294
|
-
message:
|
|
1295
|
-
status:
|
|
1074
|
+
var googleVertexOperationSchema = z8.object({
|
|
1075
|
+
name: z8.string().nullish(),
|
|
1076
|
+
done: z8.boolean().nullish(),
|
|
1077
|
+
error: z8.object({
|
|
1078
|
+
code: z8.number().nullish(),
|
|
1079
|
+
message: z8.string(),
|
|
1080
|
+
status: z8.string().nullish()
|
|
1296
1081
|
}).nullish(),
|
|
1297
|
-
response:
|
|
1298
|
-
videos:
|
|
1299
|
-
|
|
1300
|
-
bytesBase64Encoded:
|
|
1301
|
-
gcsUri:
|
|
1302
|
-
mimeType:
|
|
1082
|
+
response: z8.object({
|
|
1083
|
+
videos: z8.array(
|
|
1084
|
+
z8.object({
|
|
1085
|
+
bytesBase64Encoded: z8.string().nullish(),
|
|
1086
|
+
gcsUri: z8.string().nullish(),
|
|
1087
|
+
mimeType: z8.string().nullish()
|
|
1303
1088
|
})
|
|
1304
1089
|
).nullish(),
|
|
1305
|
-
raiMediaFilteredCount:
|
|
1090
|
+
raiMediaFilteredCount: z8.number().nullish()
|
|
1306
1091
|
}).nullish()
|
|
1307
1092
|
});
|
|
1308
1093
|
|
|
@@ -1362,7 +1147,7 @@ function createGoogleVertex(options = {}) {
|
|
|
1362
1147
|
const createConfig = (name, { endpoint = false } = {}) => {
|
|
1363
1148
|
const getHeaders = async () => {
|
|
1364
1149
|
var _a;
|
|
1365
|
-
const originalHeaders = await
|
|
1150
|
+
const originalHeaders = await resolve5((_a = options.headers) != null ? _a : {});
|
|
1366
1151
|
return withUserAgentSuffix(
|
|
1367
1152
|
originalHeaders,
|
|
1368
1153
|
`ai-sdk/google-vertex/${VERSION}`
|
|
@@ -1612,7 +1397,7 @@ function createGoogleVertex2(options = {}) {
|
|
|
1612
1397
|
Authorization: `Bearer ${await generateAuthToken(
|
|
1613
1398
|
options.googleCredentials
|
|
1614
1399
|
)}`,
|
|
1615
|
-
...await
|
|
1400
|
+
...await resolve6(options.headers)
|
|
1616
1401
|
})
|
|
1617
1402
|
});
|
|
1618
1403
|
}
|