@ai-sdk/google-vertex 4.0.153 → 4.0.155

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.
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  AISDKError,
3
3
  type Experimental_VideoModelV3,
4
+ type Experimental_VideoModelV3File,
4
5
  type SharedV3Warning,
5
6
  } from '@ai-sdk/provider';
6
7
  import {
@@ -53,6 +54,78 @@ interface GoogleVertexVideoModelConfig {
53
54
  };
54
55
  }
55
56
 
57
+ function getFirstFrameImage(
58
+ options: Parameters<Experimental_VideoModelV3['doGenerate']>[0],
59
+ ): Experimental_VideoModelV3File | undefined {
60
+ return options.frameImages?.find(frame => frame.frameType === 'first_frame')
61
+ ?.image;
62
+ }
63
+
64
+ function resolveStartImage(
65
+ options: Parameters<Experimental_VideoModelV3['doGenerate']>[0],
66
+ ): Experimental_VideoModelV3File | undefined {
67
+ return getFirstFrameImage(options) ?? options.image;
68
+ }
69
+
70
+ function getLastFrameImage(
71
+ options: Parameters<Experimental_VideoModelV3['doGenerate']>[0],
72
+ ): Experimental_VideoModelV3File | undefined {
73
+ return options.frameImages?.find(frame => frame.frameType === 'last_frame')
74
+ ?.image;
75
+ }
76
+
77
+ function getInputReferences(
78
+ options: Parameters<Experimental_VideoModelV3['doGenerate']>[0],
79
+ ): Array<Experimental_VideoModelV3File> | undefined {
80
+ if (options.frameImages != null && options.frameImages.length > 0) {
81
+ return undefined;
82
+ }
83
+
84
+ return options.inputReferences != null && options.inputReferences.length > 0
85
+ ? options.inputReferences
86
+ : undefined;
87
+ }
88
+
89
+ function convertFileToVertexImage(
90
+ file: Experimental_VideoModelV3File,
91
+ warnings: SharedV3Warning[],
92
+ ): Record<string, unknown> | undefined {
93
+ if (file.type === 'url') {
94
+ if (file.url.startsWith('gs://')) {
95
+ return {
96
+ gcsUri: file.url,
97
+ mimeType: 'image/png',
98
+ };
99
+ }
100
+
101
+ warnings.push({
102
+ type: 'unsupported',
103
+ feature: 'URL-based image input',
104
+ details:
105
+ 'Vertex AI video models require base64-encoded images or GCS URIs. URL will be ignored.',
106
+ });
107
+ return undefined;
108
+ }
109
+
110
+ const base64Data =
111
+ typeof file.data === 'string'
112
+ ? file.data
113
+ : convertUint8ArrayToBase64(file.data);
114
+
115
+ return {
116
+ bytesBase64Encoded: base64Data,
117
+ mimeType: file.mediaType || 'image/png',
118
+ };
119
+ }
120
+
121
+ function convertInputReferenceImage(
122
+ file: Experimental_VideoModelV3File,
123
+ warnings: SharedV3Warning[],
124
+ ): Record<string, unknown> | undefined {
125
+ const image = convertFileToVertexImage(file, warnings);
126
+ return image != null ? { image, referenceType: 'asset' } : undefined;
127
+ }
128
+
56
129
  export class GoogleVertexVideoModel implements Experimental_VideoModelV3 {
57
130
  readonly specificationVersion = 'v3';
58
131
 
@@ -89,28 +162,29 @@ export class GoogleVertexVideoModel implements Experimental_VideoModelV3 {
89
162
  instance.prompt = options.prompt;
90
163
  }
91
164
 
92
- if (options.image != null) {
93
- if (options.image.type === 'url') {
94
- warnings.push({
95
- type: 'unsupported',
96
- feature: 'URL-based image input',
97
- details:
98
- 'Vertex AI video models require base64-encoded images or GCS URIs. URL will be ignored.',
99
- });
100
- } else {
101
- const base64Data =
102
- typeof options.image.data === 'string'
103
- ? options.image.data
104
- : convertUint8ArrayToBase64(options.image.data);
105
-
106
- instance.image = {
107
- bytesBase64Encoded: base64Data,
108
- mimeType: options.image.mediaType,
109
- };
165
+ const startImage = resolveStartImage(options);
166
+ if (startImage != null) {
167
+ const image = convertFileToVertexImage(startImage, warnings);
168
+ if (image != null) {
169
+ instance.image = image;
170
+ }
171
+ }
172
+
173
+ const lastFrameImage = getLastFrameImage(options);
174
+ if (lastFrameImage != null) {
175
+ const lastFrame = convertFileToVertexImage(lastFrameImage, warnings);
176
+ if (lastFrame != null) {
177
+ instance.lastFrame = lastFrame;
110
178
  }
111
179
  }
112
180
 
113
- if (vertexOptions?.referenceImages != null) {
181
+ const inputReferences = getInputReferences(options);
182
+ if (inputReferences != null) {
183
+ instance.referenceImages = inputReferences.flatMap(reference => {
184
+ const converted = convertInputReferenceImage(reference, warnings);
185
+ return converted != null ? [converted] : [];
186
+ });
187
+ } else if (vertexOptions?.referenceImages != null) {
114
188
  instance.referenceImages = vertexOptions.referenceImages;
115
189
  }
116
190