@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/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/google-vertex-provider.ts
|
|
2
|
-
import { loadOptionalSetting as loadOptionalSetting2, resolve as
|
|
2
|
+
import { loadOptionalSetting as loadOptionalSetting2, resolve as resolve6 } from "@ai-sdk/provider-utils";
|
|
3
3
|
|
|
4
4
|
// src/google-vertex-auth-google-auth-library.ts
|
|
5
5
|
import { GoogleAuth } from "google-auth-library";
|
|
@@ -27,13 +27,13 @@ import {
|
|
|
27
27
|
loadOptionalSetting,
|
|
28
28
|
loadSetting,
|
|
29
29
|
normalizeHeaders,
|
|
30
|
-
resolve as
|
|
30
|
+
resolve as resolve5,
|
|
31
31
|
withoutTrailingSlash,
|
|
32
32
|
withUserAgentSuffix
|
|
33
33
|
} from "@ai-sdk/provider-utils";
|
|
34
34
|
|
|
35
35
|
// src/version.ts
|
|
36
|
-
var VERSION = true ? "5.0.
|
|
36
|
+
var VERSION = true ? "5.0.60" : "0.0.0-test";
|
|
37
37
|
|
|
38
38
|
// src/google-vertex-embedding-model.ts
|
|
39
39
|
import {
|
|
@@ -274,85 +274,18 @@ function usesEmbedContentEndpoint(modelId) {
|
|
|
274
274
|
// src/google-vertex-image-model.ts
|
|
275
275
|
import { GoogleLanguageModel } from "@ai-sdk/google/internal";
|
|
276
276
|
import {
|
|
277
|
-
combineHeaders as combineHeaders2,
|
|
278
277
|
convertToBase64,
|
|
279
|
-
convertUint8ArrayToBase64,
|
|
280
|
-
createJsonResponseHandler as createJsonResponseHandler2,
|
|
281
278
|
generateId as defaultGenerateId,
|
|
282
|
-
parseProviderOptions as parseProviderOptions2,
|
|
283
|
-
postJsonToApi as postJsonToApi2,
|
|
284
|
-
resolve as resolve2,
|
|
285
279
|
serializeModelOptions as serializeModelOptions2,
|
|
286
280
|
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
|
|
287
281
|
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
|
|
288
282
|
} from "@ai-sdk/provider-utils";
|
|
289
|
-
import { z as z5 } from "zod/v4";
|
|
290
|
-
|
|
291
|
-
// src/google-vertex-image-model-options.ts
|
|
292
|
-
import { z as z4 } from "zod/v4";
|
|
293
|
-
var googleVertexImageModelOptionsSchema = z4.object({
|
|
294
|
-
negativePrompt: z4.string().nullish(),
|
|
295
|
-
personGeneration: z4.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
296
|
-
safetySetting: z4.enum([
|
|
297
|
-
"block_low_and_above",
|
|
298
|
-
"block_medium_and_above",
|
|
299
|
-
"block_only_high",
|
|
300
|
-
"block_none"
|
|
301
|
-
]).nullish(),
|
|
302
|
-
addWatermark: z4.boolean().nullish(),
|
|
303
|
-
storageUri: z4.string().nullish(),
|
|
304
|
-
sampleImageSize: z4.enum(["1K", "2K"]).nullish(),
|
|
305
|
-
/**
|
|
306
|
-
* Configuration for image editing operations
|
|
307
|
-
*/
|
|
308
|
-
edit: z4.object({
|
|
309
|
-
/**
|
|
310
|
-
* An integer that represents the number of sampling steps.
|
|
311
|
-
* A higher value offers better image quality, a lower value offers better latency.
|
|
312
|
-
* Try 35 steps to start. If the quality doesn't meet your requirements,
|
|
313
|
-
* increase the value towards an upper limit of 75.
|
|
314
|
-
*/
|
|
315
|
-
baseSteps: z4.number().nullish(),
|
|
316
|
-
// Edit mode options
|
|
317
|
-
// https://cloud.google.com/vertex-ai/generative-ai/docs/image/edit-insert-objects
|
|
318
|
-
mode: z4.enum([
|
|
319
|
-
"EDIT_MODE_INPAINT_INSERTION",
|
|
320
|
-
"EDIT_MODE_INPAINT_REMOVAL",
|
|
321
|
-
"EDIT_MODE_OUTPAINT",
|
|
322
|
-
"EDIT_MODE_CONTROLLED_EDITING",
|
|
323
|
-
"EDIT_MODE_PRODUCT_IMAGE",
|
|
324
|
-
"EDIT_MODE_BGSWAP"
|
|
325
|
-
]).nullish(),
|
|
326
|
-
/**
|
|
327
|
-
* The mask mode to use.
|
|
328
|
-
* - `MASK_MODE_DEFAULT` - Default value for mask mode.
|
|
329
|
-
* - `MASK_MODE_USER_PROVIDED` - User provided mask. No segmentation needed.
|
|
330
|
-
* - `MASK_MODE_DETECTION_BOX` - Mask from detected bounding boxes.
|
|
331
|
-
* - `MASK_MODE_CLOTHING_AREA` - Masks from segmenting the clothing area with open-vocab segmentation.
|
|
332
|
-
* - `MASK_MODE_PARSED_PERSON` - Masks from segmenting the person body and clothing using the person-parsing model.
|
|
333
|
-
*/
|
|
334
|
-
maskMode: z4.enum([
|
|
335
|
-
"MASK_MODE_DEFAULT",
|
|
336
|
-
"MASK_MODE_USER_PROVIDED",
|
|
337
|
-
"MASK_MODE_DETECTION_BOX",
|
|
338
|
-
"MASK_MODE_CLOTHING_AREA",
|
|
339
|
-
"MASK_MODE_PARSED_PERSON"
|
|
340
|
-
]).nullish(),
|
|
341
|
-
/**
|
|
342
|
-
* Optional. A float value between 0 and 1, inclusive, that represents the
|
|
343
|
-
* percentage of the image width to grow the mask by. Using dilation helps
|
|
344
|
-
* compensate for imprecise masks. We recommend a value of 0.01.
|
|
345
|
-
*/
|
|
346
|
-
maskDilation: z4.number().nullish()
|
|
347
|
-
}).nullish()
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
// src/google-vertex-image-model.ts
|
|
351
283
|
var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
352
284
|
constructor(modelId, config) {
|
|
353
285
|
this.modelId = modelId;
|
|
354
286
|
this.config = config;
|
|
355
287
|
this.specificationVersion = "v4";
|
|
288
|
+
this.maxImagesPerCall = 10;
|
|
356
289
|
}
|
|
357
290
|
static [WORKFLOW_SERIALIZE2](model) {
|
|
358
291
|
return serializeModelOptions2({
|
|
@@ -363,160 +296,28 @@ var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
|
363
296
|
static [WORKFLOW_DESERIALIZE2](options) {
|
|
364
297
|
return new _GoogleVertexImageModel(options.modelId, options.config);
|
|
365
298
|
}
|
|
366
|
-
get maxImagesPerCall() {
|
|
367
|
-
if (isGeminiModel(this.modelId)) {
|
|
368
|
-
return 10;
|
|
369
|
-
}
|
|
370
|
-
return 4;
|
|
371
|
-
}
|
|
372
299
|
get provider() {
|
|
373
300
|
return this.config.provider;
|
|
374
301
|
}
|
|
375
302
|
async doGenerate(options) {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
async doGenerateImagen({
|
|
382
|
-
prompt,
|
|
383
|
-
n,
|
|
384
|
-
size,
|
|
385
|
-
aspectRatio,
|
|
386
|
-
seed,
|
|
387
|
-
providerOptions,
|
|
388
|
-
headers,
|
|
389
|
-
abortSignal,
|
|
390
|
-
files,
|
|
391
|
-
mask
|
|
392
|
-
}) {
|
|
393
|
-
var _a, _b, _c, _d, _e, _f;
|
|
394
|
-
const warnings = [];
|
|
395
|
-
if (size != null) {
|
|
396
|
-
warnings.push({
|
|
397
|
-
type: "unsupported",
|
|
398
|
-
feature: "size",
|
|
399
|
-
details: "This model does not support the `size` option. Use `aspectRatio` instead."
|
|
400
|
-
});
|
|
303
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
304
|
+
if (!this.modelId.startsWith("gemini-")) {
|
|
305
|
+
throw new Error(
|
|
306
|
+
"Google image models other than Gemini are no longer supported. Use a model ID that starts with `gemini-`."
|
|
307
|
+
);
|
|
401
308
|
}
|
|
402
|
-
const
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
309
|
+
const {
|
|
310
|
+
prompt,
|
|
311
|
+
n,
|
|
312
|
+
size,
|
|
313
|
+
aspectRatio,
|
|
314
|
+
seed,
|
|
408
315
|
providerOptions,
|
|
409
|
-
|
|
410
|
-
});
|
|
411
|
-
const { edit, ...otherOptions } = googleVertexImageOptions != null ? googleVertexImageOptions : {};
|
|
412
|
-
const { mode: editMode, baseSteps, maskMode, maskDilation } = edit != null ? edit : {};
|
|
413
|
-
const isEditMode = files != null && files.length > 0;
|
|
414
|
-
let body;
|
|
415
|
-
if (isEditMode) {
|
|
416
|
-
const referenceImages = [];
|
|
417
|
-
for (let i = 0; i < files.length; i++) {
|
|
418
|
-
const file = files[i];
|
|
419
|
-
referenceImages.push({
|
|
420
|
-
referenceType: "REFERENCE_TYPE_RAW",
|
|
421
|
-
referenceId: i + 1,
|
|
422
|
-
referenceImage: {
|
|
423
|
-
bytesBase64Encoded: getBase64Data(file)
|
|
424
|
-
}
|
|
425
|
-
});
|
|
426
|
-
}
|
|
427
|
-
if (mask != null) {
|
|
428
|
-
referenceImages.push({
|
|
429
|
-
referenceType: "REFERENCE_TYPE_MASK",
|
|
430
|
-
referenceId: files.length + 1,
|
|
431
|
-
referenceImage: {
|
|
432
|
-
bytesBase64Encoded: getBase64Data(mask)
|
|
433
|
-
},
|
|
434
|
-
maskImageConfig: {
|
|
435
|
-
maskMode: maskMode != null ? maskMode : "MASK_MODE_USER_PROVIDED",
|
|
436
|
-
...maskDilation != null ? { dilation: maskDilation } : {}
|
|
437
|
-
}
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
body = {
|
|
441
|
-
instances: [
|
|
442
|
-
{
|
|
443
|
-
prompt,
|
|
444
|
-
referenceImages
|
|
445
|
-
}
|
|
446
|
-
],
|
|
447
|
-
parameters: {
|
|
448
|
-
sampleCount: n,
|
|
449
|
-
...aspectRatio != null ? { aspectRatio } : {},
|
|
450
|
-
...seed != null ? { seed } : {},
|
|
451
|
-
editMode: editMode != null ? editMode : "EDIT_MODE_INPAINT_INSERTION",
|
|
452
|
-
...baseSteps != null ? { editConfig: { baseSteps } } : {},
|
|
453
|
-
...otherOptions
|
|
454
|
-
}
|
|
455
|
-
};
|
|
456
|
-
} else {
|
|
457
|
-
body = {
|
|
458
|
-
instances: [{ prompt }],
|
|
459
|
-
parameters: {
|
|
460
|
-
sampleCount: n,
|
|
461
|
-
...aspectRatio != null ? { aspectRatio } : {},
|
|
462
|
-
...seed != null ? { seed } : {},
|
|
463
|
-
...otherOptions
|
|
464
|
-
}
|
|
465
|
-
};
|
|
466
|
-
}
|
|
467
|
-
const currentDate = (_d = (_c = (_b = this.config._internal) == null ? void 0 : _b.currentDate) == null ? void 0 : _c.call(_b)) != null ? _d : /* @__PURE__ */ new Date();
|
|
468
|
-
const { value: response, responseHeaders } = await postJsonToApi2({
|
|
469
|
-
url: `${this.config.baseURL}/models/${this.modelId}:predict`,
|
|
470
|
-
headers: combineHeaders2(
|
|
471
|
-
this.config.headers ? await resolve2(this.config.headers) : void 0,
|
|
472
|
-
headers
|
|
473
|
-
),
|
|
474
|
-
body,
|
|
475
|
-
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
476
|
-
successfulResponseHandler: createJsonResponseHandler2(
|
|
477
|
-
googleVertexImageResponseSchema
|
|
478
|
-
),
|
|
316
|
+
headers,
|
|
479
317
|
abortSignal,
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
images: (_f = (_e = response.predictions) == null ? void 0 : _e.map(
|
|
484
|
-
({ bytesBase64Encoded }) => bytesBase64Encoded
|
|
485
|
-
)) != null ? _f : [],
|
|
486
|
-
warnings,
|
|
487
|
-
response: {
|
|
488
|
-
timestamp: currentDate,
|
|
489
|
-
modelId: this.modelId,
|
|
490
|
-
headers: responseHeaders
|
|
491
|
-
},
|
|
492
|
-
providerMetadata: (() => {
|
|
493
|
-
var _a2, _b2;
|
|
494
|
-
const payload = {
|
|
495
|
-
images: (_b2 = (_a2 = response.predictions) == null ? void 0 : _a2.map((prediction) => {
|
|
496
|
-
const {
|
|
497
|
-
// normalize revised prompt property
|
|
498
|
-
prompt: revisedPrompt
|
|
499
|
-
} = prediction;
|
|
500
|
-
return { ...revisedPrompt != null && { revisedPrompt } };
|
|
501
|
-
})) != null ? _b2 : []
|
|
502
|
-
};
|
|
503
|
-
return { googleVertex: payload, vertex: payload };
|
|
504
|
-
})()
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
async doGenerateGemini({
|
|
508
|
-
prompt,
|
|
509
|
-
n,
|
|
510
|
-
size,
|
|
511
|
-
aspectRatio,
|
|
512
|
-
seed,
|
|
513
|
-
providerOptions,
|
|
514
|
-
headers,
|
|
515
|
-
abortSignal,
|
|
516
|
-
files,
|
|
517
|
-
mask
|
|
518
|
-
}) {
|
|
519
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
318
|
+
files,
|
|
319
|
+
mask
|
|
320
|
+
} = options;
|
|
520
321
|
const warnings = [];
|
|
521
322
|
if (mask != null) {
|
|
522
323
|
throw new Error(
|
|
@@ -572,13 +373,20 @@ var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
|
572
373
|
"*": [/^https?:\/\/.*$/, /^gs:\/\/.*$/]
|
|
573
374
|
})
|
|
574
375
|
});
|
|
575
|
-
const
|
|
376
|
+
const {
|
|
377
|
+
responseModalities: _strippedResponseModalities,
|
|
378
|
+
imageConfig: userImageConfig,
|
|
379
|
+
...userVertexOptions
|
|
380
|
+
} = (_d = (_c = providerOptions == null ? void 0 : providerOptions.googleVertex) != null ? _c : providerOptions == null ? void 0 : providerOptions.vertex) != null ? _d : {};
|
|
576
381
|
const innerVertexOptions = {
|
|
382
|
+
...userVertexOptions,
|
|
577
383
|
responseModalities: ["IMAGE"],
|
|
578
|
-
imageConfig: aspectRatio ? {
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
384
|
+
imageConfig: aspectRatio != null || userImageConfig != null ? {
|
|
385
|
+
...userImageConfig,
|
|
386
|
+
...aspectRatio != null ? {
|
|
387
|
+
aspectRatio
|
|
388
|
+
} : {}
|
|
389
|
+
} : void 0
|
|
582
390
|
};
|
|
583
391
|
const result = await languageModel.doGenerate({
|
|
584
392
|
prompt: languageModelPrompt,
|
|
@@ -590,7 +398,7 @@ var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
|
590
398
|
headers,
|
|
591
399
|
abortSignal
|
|
592
400
|
});
|
|
593
|
-
const currentDate = (
|
|
401
|
+
const currentDate = (_g = (_f = (_e = this.config._internal) == null ? void 0 : _e.currentDate) == null ? void 0 : _f.call(_e)) != null ? _g : /* @__PURE__ */ new Date();
|
|
594
402
|
const images = [];
|
|
595
403
|
for (const part of result.content) {
|
|
596
404
|
if (part.type === "file" && part.mediaType.startsWith("image/") && part.data.type === "data") {
|
|
@@ -610,52 +418,29 @@ var GoogleVertexImageModel = class _GoogleVertexImageModel {
|
|
|
610
418
|
response: {
|
|
611
419
|
timestamp: currentDate,
|
|
612
420
|
modelId: this.modelId,
|
|
613
|
-
headers: (
|
|
421
|
+
headers: (_h = result.response) == null ? void 0 : _h.headers
|
|
614
422
|
},
|
|
615
423
|
usage: result.usage ? {
|
|
616
424
|
inputTokens: result.usage.inputTokens.total,
|
|
617
425
|
outputTokens: result.usage.outputTokens.total,
|
|
618
|
-
totalTokens: ((
|
|
426
|
+
totalTokens: ((_i = result.usage.inputTokens.total) != null ? _i : 0) + ((_j = result.usage.outputTokens.total) != null ? _j : 0)
|
|
619
427
|
} : void 0
|
|
620
428
|
};
|
|
621
429
|
}
|
|
622
430
|
};
|
|
623
|
-
function isGeminiModel(modelId) {
|
|
624
|
-
return modelId.startsWith("gemini-");
|
|
625
|
-
}
|
|
626
|
-
var googleVertexImageResponseSchema = z5.object({
|
|
627
|
-
predictions: z5.array(
|
|
628
|
-
z5.object({
|
|
629
|
-
bytesBase64Encoded: z5.string(),
|
|
630
|
-
mimeType: z5.string(),
|
|
631
|
-
prompt: z5.string().nullish()
|
|
632
|
-
})
|
|
633
|
-
).nullish()
|
|
634
|
-
});
|
|
635
|
-
function getBase64Data(file) {
|
|
636
|
-
if (file.type === "url") {
|
|
637
|
-
throw new Error(
|
|
638
|
-
"URL-based images are not supported for Google Vertex image editing. Please provide the image data directly."
|
|
639
|
-
);
|
|
640
|
-
}
|
|
641
|
-
if (typeof file.data === "string") {
|
|
642
|
-
return file.data;
|
|
643
|
-
}
|
|
644
|
-
return convertUint8ArrayToBase64(file.data);
|
|
645
|
-
}
|
|
646
431
|
|
|
647
432
|
// src/google-vertex-cloud-tts-speech-model.ts
|
|
648
433
|
import {
|
|
649
|
-
combineHeaders as
|
|
434
|
+
combineHeaders as combineHeaders2,
|
|
650
435
|
convertBase64ToUint8Array,
|
|
651
|
-
createJsonResponseHandler as
|
|
652
|
-
postJsonToApi as
|
|
653
|
-
resolve as
|
|
436
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
437
|
+
postJsonToApi as postJsonToApi2,
|
|
438
|
+
resolve as resolve2,
|
|
654
439
|
serializeModelOptions as serializeModelOptions3,
|
|
655
440
|
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3,
|
|
656
441
|
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3
|
|
657
442
|
} from "@ai-sdk/provider-utils";
|
|
658
|
-
import { z as
|
|
443
|
+
import { z as z4 } from "zod/v4";
|
|
659
444
|
var DEFAULT_VOICE = "Kore";
|
|
660
445
|
var DEFAULT_LANGUAGE = "en-US";
|
|
661
446
|
var CHIRP3_HD_VOICE_INFIX = "Chirp3-HD";
|
|
@@ -726,15 +511,15 @@ var GoogleVertexCloudTTSSpeechModel = class _GoogleVertexCloudTTSSpeechModel {
|
|
|
726
511
|
value: response,
|
|
727
512
|
responseHeaders,
|
|
728
513
|
rawValue: rawResponse
|
|
729
|
-
} = await
|
|
514
|
+
} = await postJsonToApi2({
|
|
730
515
|
url: CLOUD_TTS_SYNTHESIZE_URL,
|
|
731
|
-
headers:
|
|
732
|
-
this.config.headers ? await
|
|
516
|
+
headers: combineHeaders2(
|
|
517
|
+
this.config.headers ? await resolve2(this.config.headers) : void 0,
|
|
733
518
|
options.headers
|
|
734
519
|
),
|
|
735
520
|
body: requestBody,
|
|
736
521
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
737
|
-
successfulResponseHandler:
|
|
522
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
738
523
|
googleVertexCloudTTSResponseSchema
|
|
739
524
|
),
|
|
740
525
|
abortSignal: options.abortSignal,
|
|
@@ -761,8 +546,8 @@ var GoogleVertexCloudTTSSpeechModel = class _GoogleVertexCloudTTSSpeechModel {
|
|
|
761
546
|
};
|
|
762
547
|
}
|
|
763
548
|
};
|
|
764
|
-
var googleVertexCloudTTSResponseSchema =
|
|
765
|
-
audioContent:
|
|
549
|
+
var googleVertexCloudTTSResponseSchema = z4.object({
|
|
550
|
+
audioContent: z4.string().nullish()
|
|
766
551
|
});
|
|
767
552
|
|
|
768
553
|
// src/google-vertex-tools.ts
|
|
@@ -779,31 +564,31 @@ var googleVertexTools = {
|
|
|
779
564
|
|
|
780
565
|
// src/google-vertex-transcription-model.ts
|
|
781
566
|
import {
|
|
782
|
-
combineHeaders as
|
|
783
|
-
convertUint8ArrayToBase64
|
|
784
|
-
createJsonResponseHandler as
|
|
785
|
-
parseProviderOptions as
|
|
786
|
-
postJsonToApi as
|
|
787
|
-
resolve as
|
|
567
|
+
combineHeaders as combineHeaders3,
|
|
568
|
+
convertUint8ArrayToBase64,
|
|
569
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
570
|
+
parseProviderOptions as parseProviderOptions2,
|
|
571
|
+
postJsonToApi as postJsonToApi3,
|
|
572
|
+
resolve as resolve3,
|
|
788
573
|
serializeModelOptions as serializeModelOptions4,
|
|
789
574
|
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE4,
|
|
790
575
|
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE4
|
|
791
576
|
} from "@ai-sdk/provider-utils";
|
|
792
|
-
import { z as
|
|
577
|
+
import { z as z6 } from "zod/v4";
|
|
793
578
|
|
|
794
579
|
// src/google-vertex-transcription-model-options.ts
|
|
795
|
-
import { z as
|
|
796
|
-
var googleVertexTranscriptionProviderOptionsSchema =
|
|
580
|
+
import { z as z5 } from "zod/v4";
|
|
581
|
+
var googleVertexTranscriptionProviderOptionsSchema = z5.object({
|
|
797
582
|
/**
|
|
798
583
|
* BCP-47 language codes to recognize (e.g. `['en-US']`), or `['auto']` to let
|
|
799
584
|
* Chirp auto-detect the spoken language. Defaults to `['auto']`. For
|
|
800
585
|
* `telephony`, pass a supported explicit language code.
|
|
801
586
|
*/
|
|
802
|
-
languageCodes:
|
|
587
|
+
languageCodes: z5.array(z5.string()).optional(),
|
|
803
588
|
/**
|
|
804
589
|
* Whether to add punctuation to the transcript. Defaults to `true`.
|
|
805
590
|
*/
|
|
806
|
-
enableAutomaticPunctuation:
|
|
591
|
+
enableAutomaticPunctuation: z5.boolean().optional(),
|
|
807
592
|
/**
|
|
808
593
|
* Whether to include word-level timestamps. Defaults to `true` so the
|
|
809
594
|
* transcription result can include segments.
|
|
@@ -811,7 +596,7 @@ var googleVertexTranscriptionProviderOptionsSchema = z7.object({
|
|
|
811
596
|
* Enabling word-level timestamps can reduce transcription quality and speed
|
|
812
597
|
* for Chirp models.
|
|
813
598
|
*/
|
|
814
|
-
enableWordTimeOffsets:
|
|
599
|
+
enableWordTimeOffsets: z5.boolean().optional(),
|
|
815
600
|
/**
|
|
816
601
|
* The Cloud Speech-to-Text region for the request (e.g. `'us'`, `'eu'`,
|
|
817
602
|
* `'us-central1'`). Defaults to the provider `location`.
|
|
@@ -820,7 +605,7 @@ var googleVertexTranscriptionProviderOptionsSchema = z7.object({
|
|
|
820
605
|
* available in specific Speech-to-Text regions and is not available in the
|
|
821
606
|
* `global` location.
|
|
822
607
|
*/
|
|
823
|
-
region:
|
|
608
|
+
region: z5.string().optional()
|
|
824
609
|
});
|
|
825
610
|
|
|
826
611
|
// src/google-vertex-transcription-model.ts
|
|
@@ -866,7 +651,7 @@ var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
|
|
|
866
651
|
const warnings = [];
|
|
867
652
|
let googleOptions;
|
|
868
653
|
for (const provider of ["googleVertex", "vertex", "google"]) {
|
|
869
|
-
googleOptions = await
|
|
654
|
+
googleOptions = await parseProviderOptions2({
|
|
870
655
|
provider,
|
|
871
656
|
providerOptions: options.providerOptions,
|
|
872
657
|
schema: googleVertexTranscriptionProviderOptionsSchema
|
|
@@ -877,7 +662,7 @@ var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
|
|
|
877
662
|
}
|
|
878
663
|
const region = (_d = googleOptions == null ? void 0 : googleOptions.region) != null ? _d : this.config.location;
|
|
879
664
|
const languageCodes = (_e = googleOptions == null ? void 0 : googleOptions.languageCodes) != null ? _e : ["auto"];
|
|
880
|
-
const content = typeof options.audio === "string" ? options.audio :
|
|
665
|
+
const content = typeof options.audio === "string" ? options.audio : convertUint8ArrayToBase64(options.audio);
|
|
881
666
|
const requestBody = {
|
|
882
667
|
config: {
|
|
883
668
|
model: this.modelId,
|
|
@@ -898,15 +683,15 @@ var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
|
|
|
898
683
|
value: response,
|
|
899
684
|
responseHeaders,
|
|
900
685
|
rawValue: rawResponse
|
|
901
|
-
} = await
|
|
686
|
+
} = await postJsonToApi3({
|
|
902
687
|
url,
|
|
903
|
-
headers:
|
|
904
|
-
this.config.headers ? await
|
|
688
|
+
headers: combineHeaders3(
|
|
689
|
+
this.config.headers ? await resolve3(this.config.headers) : void 0,
|
|
905
690
|
options.headers
|
|
906
691
|
),
|
|
907
692
|
body: requestBody,
|
|
908
693
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
909
|
-
successfulResponseHandler:
|
|
694
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
910
695
|
googleVertexTranscriptionResponseSchema
|
|
911
696
|
),
|
|
912
697
|
abortSignal: options.abortSignal,
|
|
@@ -945,26 +730,26 @@ var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
|
|
|
945
730
|
};
|
|
946
731
|
}
|
|
947
732
|
};
|
|
948
|
-
var googleVertexTranscriptionResponseSchema =
|
|
949
|
-
results:
|
|
950
|
-
|
|
951
|
-
alternatives:
|
|
952
|
-
|
|
953
|
-
transcript:
|
|
954
|
-
words:
|
|
955
|
-
|
|
956
|
-
word:
|
|
957
|
-
startOffset:
|
|
958
|
-
endOffset:
|
|
733
|
+
var googleVertexTranscriptionResponseSchema = z6.object({
|
|
734
|
+
results: z6.array(
|
|
735
|
+
z6.object({
|
|
736
|
+
alternatives: z6.array(
|
|
737
|
+
z6.object({
|
|
738
|
+
transcript: z6.string().nullish(),
|
|
739
|
+
words: z6.array(
|
|
740
|
+
z6.object({
|
|
741
|
+
word: z6.string().nullish(),
|
|
742
|
+
startOffset: z6.string().nullish(),
|
|
743
|
+
endOffset: z6.string().nullish()
|
|
959
744
|
})
|
|
960
745
|
).nullish()
|
|
961
746
|
})
|
|
962
747
|
).nullish(),
|
|
963
|
-
languageCode:
|
|
748
|
+
languageCode: z6.string().nullish()
|
|
964
749
|
})
|
|
965
750
|
).nullish(),
|
|
966
|
-
metadata:
|
|
967
|
-
totalBilledDuration:
|
|
751
|
+
metadata: z6.object({
|
|
752
|
+
totalBilledDuration: z6.string().nullish()
|
|
968
753
|
}).nullish()
|
|
969
754
|
});
|
|
970
755
|
|
|
@@ -973,31 +758,31 @@ import {
|
|
|
973
758
|
AISDKError
|
|
974
759
|
} from "@ai-sdk/provider";
|
|
975
760
|
import {
|
|
976
|
-
combineHeaders as
|
|
977
|
-
convertUint8ArrayToBase64 as
|
|
978
|
-
createJsonResponseHandler as
|
|
979
|
-
parseProviderOptions as
|
|
980
|
-
postJsonToApi as
|
|
981
|
-
resolve as
|
|
761
|
+
combineHeaders as combineHeaders4,
|
|
762
|
+
convertUint8ArrayToBase64 as convertUint8ArrayToBase642,
|
|
763
|
+
createJsonResponseHandler as createJsonResponseHandler4,
|
|
764
|
+
parseProviderOptions as parseProviderOptions3,
|
|
765
|
+
postJsonToApi as postJsonToApi4,
|
|
766
|
+
resolve as resolve4
|
|
982
767
|
} from "@ai-sdk/provider-utils";
|
|
983
|
-
import { z as
|
|
768
|
+
import { z as z8 } from "zod/v4";
|
|
984
769
|
|
|
985
770
|
// src/google-vertex-video-model-options.ts
|
|
986
771
|
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
987
|
-
import { z as
|
|
772
|
+
import { z as z7 } from "zod/v4";
|
|
988
773
|
var googleVertexVideoModelOptionsSchema = lazySchema(
|
|
989
774
|
() => zodSchema(
|
|
990
|
-
|
|
991
|
-
pollIntervalMs:
|
|
992
|
-
pollTimeoutMs:
|
|
993
|
-
personGeneration:
|
|
994
|
-
negativePrompt:
|
|
995
|
-
generateAudio:
|
|
996
|
-
gcsOutputDirectory:
|
|
997
|
-
referenceImages:
|
|
998
|
-
|
|
999
|
-
bytesBase64Encoded:
|
|
1000
|
-
gcsUri:
|
|
775
|
+
z7.looseObject({
|
|
776
|
+
pollIntervalMs: z7.number().positive().nullish(),
|
|
777
|
+
pollTimeoutMs: z7.number().positive().nullish(),
|
|
778
|
+
personGeneration: z7.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
779
|
+
negativePrompt: z7.string().nullish(),
|
|
780
|
+
generateAudio: z7.boolean().nullish(),
|
|
781
|
+
gcsOutputDirectory: z7.string().nullish(),
|
|
782
|
+
referenceImages: z7.array(
|
|
783
|
+
z7.object({
|
|
784
|
+
bytesBase64Encoded: z7.string().nullish(),
|
|
785
|
+
gcsUri: z7.string().nullish()
|
|
1001
786
|
})
|
|
1002
787
|
).nullish()
|
|
1003
788
|
})
|
|
@@ -1038,7 +823,7 @@ function convertFileToVertexImage(file, warnings) {
|
|
|
1038
823
|
});
|
|
1039
824
|
return void 0;
|
|
1040
825
|
}
|
|
1041
|
-
const base64Data = typeof file.data === "string" ? file.data :
|
|
826
|
+
const base64Data = typeof file.data === "string" ? file.data : convertUint8ArrayToBase642(file.data);
|
|
1042
827
|
return {
|
|
1043
828
|
bytesBase64Encoded: base64Data,
|
|
1044
829
|
mimeType: file.mediaType || "image/png"
|
|
@@ -1063,11 +848,11 @@ var GoogleVertexVideoModel = class {
|
|
|
1063
848
|
async buildRequest(options) {
|
|
1064
849
|
var _a, _b;
|
|
1065
850
|
const warnings = [];
|
|
1066
|
-
const googleVertexOptions = (_a = await
|
|
851
|
+
const googleVertexOptions = (_a = await parseProviderOptions3({
|
|
1067
852
|
provider: "googleVertex",
|
|
1068
853
|
providerOptions: options.providerOptions,
|
|
1069
854
|
schema: googleVertexVideoModelOptionsSchema
|
|
1070
|
-
})) != null ? _a : await
|
|
855
|
+
})) != null ? _a : await parseProviderOptions3({
|
|
1071
856
|
provider: "vertex",
|
|
1072
857
|
providerOptions: options.providerOptions,
|
|
1073
858
|
schema: googleVertexVideoModelOptionsSchema
|
|
@@ -1218,17 +1003,17 @@ var GoogleVertexVideoModel = class {
|
|
|
1218
1003
|
var _a, _b, _c;
|
|
1219
1004
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1220
1005
|
const { instances, parameters, warnings } = await this.buildRequest(options);
|
|
1221
|
-
const { value: operation, responseHeaders } = await
|
|
1006
|
+
const { value: operation, responseHeaders } = await postJsonToApi4({
|
|
1222
1007
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
1223
|
-
headers:
|
|
1224
|
-
await
|
|
1008
|
+
headers: combineHeaders4(
|
|
1009
|
+
await resolve4(this.config.headers),
|
|
1225
1010
|
options.headers
|
|
1226
1011
|
),
|
|
1227
1012
|
body: {
|
|
1228
1013
|
instances,
|
|
1229
1014
|
parameters
|
|
1230
1015
|
},
|
|
1231
|
-
successfulResponseHandler:
|
|
1016
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
1232
1017
|
googleVertexOperationSchema
|
|
1233
1018
|
),
|
|
1234
1019
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
@@ -1256,16 +1041,16 @@ var GoogleVertexVideoModel = class {
|
|
|
1256
1041
|
var _a, _b, _c;
|
|
1257
1042
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1258
1043
|
const { operationName } = options.operation;
|
|
1259
|
-
const { value: statusOperation, responseHeaders } = await
|
|
1044
|
+
const { value: statusOperation, responseHeaders } = await postJsonToApi4({
|
|
1260
1045
|
url: `${this.config.baseURL}/models/${this.modelId}:fetchPredictOperation`,
|
|
1261
|
-
headers:
|
|
1262
|
-
await
|
|
1046
|
+
headers: combineHeaders4(
|
|
1047
|
+
await resolve4(this.config.headers),
|
|
1263
1048
|
options.headers
|
|
1264
1049
|
),
|
|
1265
1050
|
body: {
|
|
1266
1051
|
operationName
|
|
1267
1052
|
},
|
|
1268
|
-
successfulResponseHandler:
|
|
1053
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
1269
1054
|
googleVertexOperationSchema
|
|
1270
1055
|
),
|
|
1271
1056
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
@@ -1301,23 +1086,23 @@ var GoogleVertexVideoModel = class {
|
|
|
1301
1086
|
});
|
|
1302
1087
|
}
|
|
1303
1088
|
};
|
|
1304
|
-
var googleVertexOperationSchema =
|
|
1305
|
-
name:
|
|
1306
|
-
done:
|
|
1307
|
-
error:
|
|
1308
|
-
code:
|
|
1309
|
-
message:
|
|
1310
|
-
status:
|
|
1089
|
+
var googleVertexOperationSchema = z8.object({
|
|
1090
|
+
name: z8.string().nullish(),
|
|
1091
|
+
done: z8.boolean().nullish(),
|
|
1092
|
+
error: z8.object({
|
|
1093
|
+
code: z8.number().nullish(),
|
|
1094
|
+
message: z8.string(),
|
|
1095
|
+
status: z8.string().nullish()
|
|
1311
1096
|
}).nullish(),
|
|
1312
|
-
response:
|
|
1313
|
-
videos:
|
|
1314
|
-
|
|
1315
|
-
bytesBase64Encoded:
|
|
1316
|
-
gcsUri:
|
|
1317
|
-
mimeType:
|
|
1097
|
+
response: z8.object({
|
|
1098
|
+
videos: z8.array(
|
|
1099
|
+
z8.object({
|
|
1100
|
+
bytesBase64Encoded: z8.string().nullish(),
|
|
1101
|
+
gcsUri: z8.string().nullish(),
|
|
1102
|
+
mimeType: z8.string().nullish()
|
|
1318
1103
|
})
|
|
1319
1104
|
).nullish(),
|
|
1320
|
-
raiMediaFilteredCount:
|
|
1105
|
+
raiMediaFilteredCount: z8.number().nullish()
|
|
1321
1106
|
}).nullish()
|
|
1322
1107
|
});
|
|
1323
1108
|
|
|
@@ -1377,7 +1162,7 @@ function createGoogleVertex(options = {}) {
|
|
|
1377
1162
|
const createConfig = (name, { endpoint = false } = {}) => {
|
|
1378
1163
|
const getHeaders = async () => {
|
|
1379
1164
|
var _a;
|
|
1380
|
-
const originalHeaders = await
|
|
1165
|
+
const originalHeaders = await resolve5((_a = options.headers) != null ? _a : {});
|
|
1381
1166
|
return withUserAgentSuffix(
|
|
1382
1167
|
originalHeaders,
|
|
1383
1168
|
`ai-sdk/google-vertex/${VERSION}`
|
|
@@ -1519,7 +1304,7 @@ function createGoogleVertex2(options = {}) {
|
|
|
1519
1304
|
...options,
|
|
1520
1305
|
headers: async () => ({
|
|
1521
1306
|
Authorization: `Bearer ${await generateAuthToken()}`,
|
|
1522
|
-
...await
|
|
1307
|
+
...await resolve6(options.headers)
|
|
1523
1308
|
})
|
|
1524
1309
|
});
|
|
1525
1310
|
}
|