@ai-sdk/google 4.0.2 → 4.0.3

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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 4.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 0274f34: feat (video): add first-class `frameImages` and `inputReferences` call options for video generation
8
+ - Updated dependencies [0274f34]
9
+ - @ai-sdk/provider@4.0.1
10
+ - @ai-sdk/provider-utils@5.0.2
11
+
3
12
  ## 4.0.2
4
13
 
5
14
  ### Patch Changes
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  } from "@ai-sdk/provider-utils";
8
8
 
9
9
  // src/version.ts
10
- var VERSION = true ? "4.0.2" : "0.0.0-test";
10
+ var VERSION = true ? "4.0.3" : "0.0.0-test";
11
11
 
12
12
  // src/google-embedding-model.ts
13
13
  import {
@@ -3360,6 +3360,67 @@ var googleVideoModelOptionsSchema = lazySchema15(
3360
3360
  );
3361
3361
 
3362
3362
  // src/google-video-model.ts
3363
+ function getFirstFrameImage(options) {
3364
+ var _a, _b;
3365
+ return (_b = (_a = options.frameImages) == null ? void 0 : _a.find((frame) => frame.frameType === "first_frame")) == null ? void 0 : _b.image;
3366
+ }
3367
+ function resolveStartImage(options) {
3368
+ var _a;
3369
+ return (_a = getFirstFrameImage(options)) != null ? _a : options.image;
3370
+ }
3371
+ function getLastFrameImage(options) {
3372
+ var _a, _b;
3373
+ return (_b = (_a = options.frameImages) == null ? void 0 : _a.find((frame) => frame.frameType === "last_frame")) == null ? void 0 : _b.image;
3374
+ }
3375
+ function getInputReferences(options) {
3376
+ if (options.frameImages != null && options.frameImages.length > 0) {
3377
+ return void 0;
3378
+ }
3379
+ return options.inputReferences != null && options.inputReferences.length > 0 ? options.inputReferences : void 0;
3380
+ }
3381
+ function convertFileToGoogleImage(file, warnings) {
3382
+ if (file.type === "url") {
3383
+ if (file.url.startsWith("gs://")) {
3384
+ return {
3385
+ gcsUri: file.url,
3386
+ mimeType: "image/png"
3387
+ };
3388
+ }
3389
+ warnings.push({
3390
+ type: "unsupported",
3391
+ feature: "URL-based image input",
3392
+ details: "Google Generative AI video models require base64-encoded images or GCS URIs. URL will be ignored."
3393
+ });
3394
+ return void 0;
3395
+ }
3396
+ const base64Data = typeof file.data === "string" ? file.data : convertUint8ArrayToBase64(file.data);
3397
+ return {
3398
+ inlineData: {
3399
+ mimeType: file.mediaType || "image/png",
3400
+ data: base64Data
3401
+ }
3402
+ };
3403
+ }
3404
+ function convertProviderReferenceImage(refImg) {
3405
+ if (refImg.bytesBase64Encoded) {
3406
+ return {
3407
+ inlineData: {
3408
+ mimeType: "image/png",
3409
+ data: refImg.bytesBase64Encoded
3410
+ }
3411
+ };
3412
+ }
3413
+ if (refImg.gcsUri) {
3414
+ return {
3415
+ gcsUri: refImg.gcsUri
3416
+ };
3417
+ }
3418
+ return refImg;
3419
+ }
3420
+ function convertInputReferenceImage(file, warnings) {
3421
+ const image = convertFileToGoogleImage(file, warnings);
3422
+ return image != null ? { image, referenceType: "asset" } : void 0;
3423
+ }
3363
3424
  var GoogleVideoModel = class {
3364
3425
  constructor(modelId, config) {
3365
3426
  this.modelId = modelId;
@@ -3386,39 +3447,30 @@ var GoogleVideoModel = class {
3386
3447
  if (options.prompt != null) {
3387
3448
  instance.prompt = options.prompt;
3388
3449
  }
3389
- if (options.image != null) {
3390
- if (options.image.type === "url") {
3391
- warnings.push({
3392
- type: "unsupported",
3393
- feature: "URL-based image input",
3394
- details: "Google Generative AI video models require base64-encoded images. URL will be ignored."
3395
- });
3396
- } else {
3397
- const base64Data = typeof options.image.data === "string" ? options.image.data : convertUint8ArrayToBase64(options.image.data);
3398
- instance.image = {
3399
- inlineData: {
3400
- mimeType: options.image.mediaType || "image/png",
3401
- data: base64Data
3402
- }
3403
- };
3450
+ const startImage = resolveStartImage(options);
3451
+ if (startImage != null) {
3452
+ const image = convertFileToGoogleImage(startImage, warnings);
3453
+ if (image != null) {
3454
+ instance.image = image;
3404
3455
  }
3405
3456
  }
3406
- if ((googleOptions == null ? void 0 : googleOptions.referenceImages) != null) {
3407
- instance.referenceImages = googleOptions.referenceImages.map((refImg) => {
3408
- if (refImg.bytesBase64Encoded) {
3409
- return {
3410
- inlineData: {
3411
- mimeType: "image/png",
3412
- data: refImg.bytesBase64Encoded
3413
- }
3414
- };
3415
- } else if (refImg.gcsUri) {
3416
- return {
3417
- gcsUri: refImg.gcsUri
3418
- };
3419
- }
3420
- return refImg;
3457
+ const lastFrameImage = getLastFrameImage(options);
3458
+ if (lastFrameImage != null) {
3459
+ const lastFrame = convertFileToGoogleImage(lastFrameImage, warnings);
3460
+ if (lastFrame != null) {
3461
+ instance.lastFrame = lastFrame;
3462
+ }
3463
+ }
3464
+ const inputReferences = getInputReferences(options);
3465
+ if (inputReferences != null) {
3466
+ instance.referenceImages = inputReferences.flatMap((reference) => {
3467
+ const converted = convertInputReferenceImage(reference, warnings);
3468
+ return converted != null ? [converted] : [];
3421
3469
  });
3470
+ } else if ((googleOptions == null ? void 0 : googleOptions.referenceImages) != null) {
3471
+ instance.referenceImages = googleOptions.referenceImages.map(
3472
+ (refImg) => convertProviderReferenceImage(refImg)
3473
+ );
3422
3474
  }
3423
3475
  const parameters = {
3424
3476
  sampleCount: options.n