@ai-sdk/alibaba 1.0.32 → 1.0.34

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 {
@@ -133,6 +134,60 @@ function detectMode(modelId: string): 't2v' | 'i2v' | 'r2v' {
133
134
  return 't2v';
134
135
  }
135
136
 
137
+ function fileToImageString(file: Experimental_VideoModelV3File): string {
138
+ if (file.type === 'url') {
139
+ return file.url;
140
+ }
141
+ return typeof file.data === 'string'
142
+ ? file.data
143
+ : convertUint8ArrayToBase64(file.data);
144
+ }
145
+
146
+ function getFirstFrameImage(
147
+ options: Parameters<Experimental_VideoModelV3['doGenerate']>[0],
148
+ ): Experimental_VideoModelV3File | undefined {
149
+ return options.frameImages?.find(frame => frame.frameType === 'first_frame')
150
+ ?.image;
151
+ }
152
+
153
+ function resolveStartImage(
154
+ options: Parameters<Experimental_VideoModelV3['doGenerate']>[0],
155
+ ): Experimental_VideoModelV3File | undefined {
156
+ return getFirstFrameImage(options) ?? options.image;
157
+ }
158
+
159
+ function resolveReferenceUrls(
160
+ options: Parameters<Experimental_VideoModelV3['doGenerate']>[0],
161
+ alibabaOptions: AlibabaVideoModelOptions | undefined,
162
+ warnings: SharedV3Warning[],
163
+ ): string[] | undefined {
164
+ if (options.frameImages != null && options.frameImages.length > 0) {
165
+ return undefined;
166
+ }
167
+
168
+ if (options.inputReferences != null && options.inputReferences.length > 0) {
169
+ const urls: string[] = [];
170
+
171
+ for (const reference of options.inputReferences) {
172
+ if (reference.type === 'url') {
173
+ urls.push(reference.url);
174
+ } else {
175
+ warnings.push({
176
+ type: 'unsupported',
177
+ feature: 'inputReferences',
178
+ details:
179
+ 'Alibaba reference-to-video requires URL references. ' +
180
+ 'Non-URL reference was skipped.',
181
+ });
182
+ }
183
+ }
184
+
185
+ return urls.length > 0 ? urls : undefined;
186
+ }
187
+
188
+ return alibabaOptions?.referenceUrls ?? undefined;
189
+ }
190
+
136
191
  export class AlibabaVideoModel implements Experimental_VideoModelV3 {
137
192
  readonly specificationVersion = 'v3';
138
193
  readonly maxVideosPerCall = 1;
@@ -174,22 +229,49 @@ export class AlibabaVideoModel implements Experimental_VideoModelV3 {
174
229
  input.audio_url = alibabaOptions.audioUrl;
175
230
  }
176
231
 
232
+ const startImage = resolveStartImage(options);
233
+ const referenceUrls = resolveReferenceUrls(
234
+ options,
235
+ alibabaOptions,
236
+ warnings,
237
+ );
238
+
177
239
  // Handle image input for I2V mode
178
- if (mode === 'i2v' && options.image != null) {
179
- if (options.image.type === 'url') {
180
- input.img_url = options.image.url;
181
- } else {
182
- const base64Data =
183
- typeof options.image.data === 'string'
184
- ? options.image.data
185
- : convertUint8ArrayToBase64(options.image.data);
186
- input.img_url = base64Data;
187
- }
240
+ if (mode === 'i2v' && startImage != null) {
241
+ input.img_url = fileToImageString(startImage);
188
242
  }
189
243
 
190
244
  // Handle reference URLs for R2V mode
191
- if (mode === 'r2v' && alibabaOptions?.referenceUrls != null) {
192
- input.reference_urls = alibabaOptions.referenceUrls;
245
+ if (mode === 'r2v' && referenceUrls != null && referenceUrls.length > 0) {
246
+ input.reference_urls = referenceUrls;
247
+ }
248
+
249
+ const lastFrame = options.frameImages?.find(
250
+ frame => frame.frameType === 'last_frame',
251
+ )?.image;
252
+
253
+ if (lastFrame != null) {
254
+ warnings.push({
255
+ type: 'unsupported',
256
+ feature: 'frameImages',
257
+ details:
258
+ 'This model does not support last_frame. ' +
259
+ 'The last frame image was ignored.',
260
+ });
261
+ }
262
+
263
+ if (
264
+ options.inputReferences != null &&
265
+ options.inputReferences.length > 0 &&
266
+ mode !== 'r2v'
267
+ ) {
268
+ warnings.push({
269
+ type: 'unsupported',
270
+ feature: 'inputReferences',
271
+ details:
272
+ 'Alibaba only supports inputReferences (reference-to-video) on ' +
273
+ 'reference-to-video models. The reference images were ignored.',
274
+ });
193
275
  }
194
276
 
195
277
  // Build parameters object