@ai-sdk/alibaba 1.0.49 → 1.0.51
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 +18 -0
- package/dist/index.d.mts +16 -8
- package/dist/index.d.ts +16 -8
- package/dist/index.js +74 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +74 -36
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/alibaba-video-model.ts +130 -39
- package/src/alibaba-video-settings.ts +2 -0
package/dist/index.mjs
CHANGED
|
@@ -871,13 +871,17 @@ var alibabaVideoModelOptionsSchema = lazySchema(
|
|
|
871
871
|
type: z6.enum([
|
|
872
872
|
"reference_image",
|
|
873
873
|
"reference_video",
|
|
874
|
-
"
|
|
874
|
+
"reference_audio",
|
|
875
|
+
"first_frame",
|
|
876
|
+
"last_frame",
|
|
877
|
+
"file",
|
|
878
|
+
"link"
|
|
875
879
|
]),
|
|
876
880
|
url: z6.string(),
|
|
877
881
|
referenceVoice: z6.string().nullish()
|
|
878
882
|
})
|
|
879
883
|
).nullish(),
|
|
880
|
-
ratio: z6.enum(["16:9", "9:16", "1:1", "4:3", "3:4"]).nullish(),
|
|
884
|
+
ratio: z6.enum(["adaptive", "16:9", "9:16", "1:1", "4:3", "3:4"]).nullish(),
|
|
881
885
|
pollIntervalMs: z6.number().positive().nullish(),
|
|
882
886
|
pollTimeoutMs: z6.number().positive().nullish()
|
|
883
887
|
}).passthrough()
|
|
@@ -915,8 +919,12 @@ var alibabaVideoTaskStatusSchema = z6.object({
|
|
|
915
919
|
usage: z6.object({
|
|
916
920
|
duration: z6.number().nullish(),
|
|
917
921
|
output_video_duration: z6.number().nullish(),
|
|
922
|
+
// wan3 splits the total: input video counts toward its 30s ceiling.
|
|
923
|
+
input_video_duration: z6.number().nullish(),
|
|
924
|
+
fps: z6.number().nullish(),
|
|
918
925
|
SR: z6.number().nullish(),
|
|
919
|
-
size: z6.string().nullish()
|
|
926
|
+
size: z6.string().nullish(),
|
|
927
|
+
ratio: z6.string().nullish()
|
|
920
928
|
}).nullish(),
|
|
921
929
|
request_id: z6.string().nullish()
|
|
922
930
|
});
|
|
@@ -925,8 +933,10 @@ function detectMode(modelId) {
|
|
|
925
933
|
if (modelId.includes("-r2v")) return "r2v";
|
|
926
934
|
return "t2v";
|
|
927
935
|
}
|
|
928
|
-
function
|
|
929
|
-
|
|
936
|
+
function detectProtocol(modelId) {
|
|
937
|
+
if (modelId.startsWith("wan3")) return "wan3";
|
|
938
|
+
if (modelId.startsWith("wan2.7")) return "wan27";
|
|
939
|
+
return "legacy";
|
|
930
940
|
}
|
|
931
941
|
var resolutionTierMap = {
|
|
932
942
|
"1280x720": "720P",
|
|
@@ -967,6 +977,10 @@ function getFirstFrameImage(options) {
|
|
|
967
977
|
var _a, _b;
|
|
968
978
|
return (_b = (_a = options.frameImages) == null ? void 0 : _a.find((frame) => frame.frameType === "first_frame")) == null ? void 0 : _b.image;
|
|
969
979
|
}
|
|
980
|
+
function getLastFrameImage(options) {
|
|
981
|
+
var _a, _b;
|
|
982
|
+
return (_b = (_a = options.frameImages) == null ? void 0 : _a.find((frame) => frame.frameType === "last_frame")) == null ? void 0 : _b.image;
|
|
983
|
+
}
|
|
970
984
|
function resolveStartImage(options) {
|
|
971
985
|
var _a;
|
|
972
986
|
return (_a = getFirstFrameImage(options)) != null ? _a : options.image;
|
|
@@ -974,7 +988,7 @@ function resolveStartImage(options) {
|
|
|
974
988
|
function isVideoUrl(url) {
|
|
975
989
|
return /\.(mp4|mov)([?#]|$)/i.test(url);
|
|
976
990
|
}
|
|
977
|
-
function resolveMedia(options, alibabaOptions, warnings) {
|
|
991
|
+
function resolveMedia(options, alibabaOptions, warnings, frames) {
|
|
978
992
|
var _a;
|
|
979
993
|
if ((alibabaOptions == null ? void 0 : alibabaOptions.media) != null && alibabaOptions.media.length > 0) {
|
|
980
994
|
return alibabaOptions.media.map((item) => ({
|
|
@@ -1003,11 +1017,16 @@ function resolveMedia(options, alibabaOptions, warnings) {
|
|
|
1003
1017
|
});
|
|
1004
1018
|
}
|
|
1005
1019
|
}
|
|
1006
|
-
|
|
1007
|
-
if (firstFrame != null) {
|
|
1020
|
+
if (frames.first != null) {
|
|
1008
1021
|
media.push({
|
|
1009
1022
|
type: "first_frame",
|
|
1010
|
-
url: convertImageModelFileToDataUri(
|
|
1023
|
+
url: convertImageModelFileToDataUri(frames.first)
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
if (frames.last != null) {
|
|
1027
|
+
media.push({
|
|
1028
|
+
type: "last_frame",
|
|
1029
|
+
url: convertImageModelFileToDataUri(frames.last)
|
|
1011
1030
|
});
|
|
1012
1031
|
}
|
|
1013
1032
|
return media.length > 0 ? media : void 0;
|
|
@@ -1045,7 +1064,7 @@ var AlibabaVideoModel = class {
|
|
|
1045
1064
|
return this.config.provider;
|
|
1046
1065
|
}
|
|
1047
1066
|
async doGenerate(options) {
|
|
1048
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n
|
|
1067
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
1049
1068
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1050
1069
|
const warnings = [];
|
|
1051
1070
|
const mode = detectMode(this.modelId);
|
|
@@ -1065,14 +1084,27 @@ var AlibabaVideoModel = class {
|
|
|
1065
1084
|
input.audio_url = alibabaOptions.audioUrl;
|
|
1066
1085
|
}
|
|
1067
1086
|
const startImage = resolveStartImage(options);
|
|
1068
|
-
const
|
|
1069
|
-
const
|
|
1070
|
-
|
|
1087
|
+
const protocol = detectProtocol(this.modelId);
|
|
1088
|
+
const wan27 = protocol === "wan27";
|
|
1089
|
+
const wan3 = protocol === "wan3";
|
|
1090
|
+
const tieredProtocol = wan27 || wan3;
|
|
1091
|
+
const supportsRatio = wan3 || wan27 && mode !== "i2v";
|
|
1092
|
+
if (!wan3 && mode === "i2v" && startImage != null) {
|
|
1071
1093
|
input.img_url = fileToImageString(startImage);
|
|
1072
1094
|
}
|
|
1073
|
-
if (
|
|
1095
|
+
if (wan3) {
|
|
1096
|
+
const media = resolveMedia(options, alibabaOptions, warnings, {
|
|
1097
|
+
first: startImage,
|
|
1098
|
+
last: getLastFrameImage(options)
|
|
1099
|
+
});
|
|
1100
|
+
if (media != null) {
|
|
1101
|
+
input.media = media;
|
|
1102
|
+
}
|
|
1103
|
+
} else if (mode === "r2v") {
|
|
1074
1104
|
if (wan27) {
|
|
1075
|
-
const media = resolveMedia(options, alibabaOptions, warnings
|
|
1105
|
+
const media = resolveMedia(options, alibabaOptions, warnings, {
|
|
1106
|
+
first: getFirstFrameImage(options)
|
|
1107
|
+
});
|
|
1076
1108
|
if (media != null) {
|
|
1077
1109
|
input.media = media;
|
|
1078
1110
|
}
|
|
@@ -1087,17 +1119,15 @@ var AlibabaVideoModel = class {
|
|
|
1087
1119
|
}
|
|
1088
1120
|
}
|
|
1089
1121
|
}
|
|
1090
|
-
const lastFrame = (
|
|
1091
|
-
|
|
1092
|
-
)) == null ? void 0 : _e.image;
|
|
1093
|
-
if (lastFrame != null) {
|
|
1122
|
+
const lastFrame = getLastFrameImage(options);
|
|
1123
|
+
if (lastFrame != null && !wan3) {
|
|
1094
1124
|
warnings.push({
|
|
1095
1125
|
type: "unsupported",
|
|
1096
1126
|
feature: "frameImages",
|
|
1097
1127
|
details: "This model does not support last_frame. The last frame image was ignored."
|
|
1098
1128
|
});
|
|
1099
1129
|
}
|
|
1100
|
-
if (options.inputReferences != null && options.inputReferences.length > 0 && mode !== "r2v") {
|
|
1130
|
+
if (options.inputReferences != null && options.inputReferences.length > 0 && mode !== "r2v" && !wan3) {
|
|
1101
1131
|
warnings.push({
|
|
1102
1132
|
type: "unsupported",
|
|
1103
1133
|
feature: "inputReferences",
|
|
@@ -1112,13 +1142,14 @@ var AlibabaVideoModel = class {
|
|
|
1112
1142
|
parameters.seed = options.seed;
|
|
1113
1143
|
}
|
|
1114
1144
|
if (options.resolution != null) {
|
|
1115
|
-
if (mode === "i2v" ||
|
|
1145
|
+
if (mode === "i2v" || tieredProtocol) {
|
|
1116
1146
|
const resolutionTier = resolutionTierMap[options.resolution] || options.resolution;
|
|
1117
|
-
|
|
1147
|
+
const supportedTiers = wan3 ? ["480P", "720P", "1080P"] : ["720P", "1080P"];
|
|
1148
|
+
if (tieredProtocol && !supportedTiers.includes(resolutionTier)) {
|
|
1118
1149
|
warnings.push({
|
|
1119
1150
|
type: "unsupported",
|
|
1120
1151
|
feature: "resolution",
|
|
1121
|
-
details:
|
|
1152
|
+
details: `${wan3 ? "wan3" : "wan2.7"} models only support the ${supportedTiers.join(", ")} resolution tiers. The resolution "${options.resolution}" was ignored.`
|
|
1122
1153
|
});
|
|
1123
1154
|
} else {
|
|
1124
1155
|
parameters.resolution = resolutionTier;
|
|
@@ -1128,7 +1159,7 @@ var AlibabaVideoModel = class {
|
|
|
1128
1159
|
}
|
|
1129
1160
|
}
|
|
1130
1161
|
if (supportsRatio) {
|
|
1131
|
-
const ratio = (
|
|
1162
|
+
const ratio = (_e = (_d = alibabaOptions == null ? void 0 : alibabaOptions.ratio) != null ? _d : options.aspectRatio) != null ? _e : options.resolution != null ? deriveRatioFromResolution(options.resolution) : void 0;
|
|
1132
1163
|
if (ratio != null) {
|
|
1133
1164
|
parameters.ratio = ratio;
|
|
1134
1165
|
}
|
|
@@ -1137,11 +1168,11 @@ var AlibabaVideoModel = class {
|
|
|
1137
1168
|
parameters.prompt_extend = alibabaOptions.promptExtend;
|
|
1138
1169
|
}
|
|
1139
1170
|
if ((alibabaOptions == null ? void 0 : alibabaOptions.shotType) != null) {
|
|
1140
|
-
if (
|
|
1171
|
+
if (tieredProtocol) {
|
|
1141
1172
|
warnings.push({
|
|
1142
1173
|
type: "unsupported",
|
|
1143
1174
|
feature: "shotType",
|
|
1144
|
-
details: "wan2.7 models do not support the shotType option. Describe the shot structure in the prompt instead
|
|
1175
|
+
details: `${wan3 ? "wan3" : "wan2.7"} models do not support the shotType option. Describe the shot structure in the prompt instead.`
|
|
1145
1176
|
});
|
|
1146
1177
|
} else {
|
|
1147
1178
|
parameters.shot_type = alibabaOptions.shotType;
|
|
@@ -1150,7 +1181,7 @@ var AlibabaVideoModel = class {
|
|
|
1150
1181
|
if ((alibabaOptions == null ? void 0 : alibabaOptions.watermark) != null) {
|
|
1151
1182
|
parameters.watermark = alibabaOptions.watermark;
|
|
1152
1183
|
}
|
|
1153
|
-
const audio = (
|
|
1184
|
+
const audio = (_f = options.generateAudio) != null ? _f : alibabaOptions == null ? void 0 : alibabaOptions.audio;
|
|
1154
1185
|
if (audio != null) {
|
|
1155
1186
|
if (wan27) {
|
|
1156
1187
|
warnings.push({
|
|
@@ -1204,15 +1235,15 @@ var AlibabaVideoModel = class {
|
|
|
1204
1235
|
abortSignal: options.abortSignal,
|
|
1205
1236
|
fetch: this.config.fetch
|
|
1206
1237
|
});
|
|
1207
|
-
const taskId = (
|
|
1238
|
+
const taskId = (_g = createResponse.output) == null ? void 0 : _g.task_id;
|
|
1208
1239
|
if (!taskId) {
|
|
1209
1240
|
throw new AISDKError({
|
|
1210
1241
|
name: "ALIBABA_VIDEO_GENERATION_ERROR",
|
|
1211
1242
|
message: `No task_id returned from Alibaba API. Response: ${JSON.stringify(createResponse)}`
|
|
1212
1243
|
});
|
|
1213
1244
|
}
|
|
1214
|
-
const pollIntervalMs = (
|
|
1215
|
-
const pollTimeoutMs = (
|
|
1245
|
+
const pollIntervalMs = (_h = alibabaOptions == null ? void 0 : alibabaOptions.pollIntervalMs) != null ? _h : 5e3;
|
|
1246
|
+
const pollTimeoutMs = (_i = alibabaOptions == null ? void 0 : alibabaOptions.pollTimeoutMs) != null ? _i : 6e5;
|
|
1216
1247
|
const startTime = Date.now();
|
|
1217
1248
|
let finalResponse;
|
|
1218
1249
|
let responseHeaders;
|
|
@@ -1238,7 +1269,7 @@ var AlibabaVideoModel = class {
|
|
|
1238
1269
|
fetch: this.config.fetch
|
|
1239
1270
|
});
|
|
1240
1271
|
responseHeaders = pollHeaders;
|
|
1241
|
-
const taskStatus = (
|
|
1272
|
+
const taskStatus = (_j = statusResponse.output) == null ? void 0 : _j.task_status;
|
|
1242
1273
|
if (taskStatus === "SUCCEEDED") {
|
|
1243
1274
|
finalResponse = statusResponse;
|
|
1244
1275
|
break;
|
|
@@ -1246,11 +1277,11 @@ var AlibabaVideoModel = class {
|
|
|
1246
1277
|
if (taskStatus === "FAILED" || taskStatus === "CANCELED") {
|
|
1247
1278
|
throw new AISDKError({
|
|
1248
1279
|
name: "ALIBABA_VIDEO_GENERATION_FAILED",
|
|
1249
|
-
message: `Video generation ${taskStatus.toLowerCase()}. Task ID: ${taskId}. ${(
|
|
1280
|
+
message: `Video generation ${taskStatus.toLowerCase()}. Task ID: ${taskId}. ${(_l = (_k = statusResponse.output) == null ? void 0 : _k.message) != null ? _l : ""}`
|
|
1250
1281
|
});
|
|
1251
1282
|
}
|
|
1252
1283
|
}
|
|
1253
|
-
const videoUrl = (
|
|
1284
|
+
const videoUrl = (_m = finalResponse == null ? void 0 : finalResponse.output) == null ? void 0 : _m.video_url;
|
|
1254
1285
|
if (!videoUrl) {
|
|
1255
1286
|
throw new AISDKError({
|
|
1256
1287
|
name: "ALIBABA_VIDEO_GENERATION_ERROR",
|
|
@@ -1275,13 +1306,20 @@ var AlibabaVideoModel = class {
|
|
|
1275
1306
|
alibaba: {
|
|
1276
1307
|
taskId,
|
|
1277
1308
|
videoUrl,
|
|
1278
|
-
...((
|
|
1309
|
+
...((_n = finalResponse == null ? void 0 : finalResponse.output) == null ? void 0 : _n.actual_prompt) ? { actualPrompt: finalResponse.output.actual_prompt } : {},
|
|
1279
1310
|
...(finalResponse == null ? void 0 : finalResponse.usage) ? {
|
|
1280
1311
|
usage: {
|
|
1281
1312
|
duration: finalResponse.usage.duration,
|
|
1282
1313
|
outputVideoDuration: finalResponse.usage.output_video_duration,
|
|
1283
1314
|
resolution: finalResponse.usage.SR,
|
|
1284
|
-
size: finalResponse.usage.size
|
|
1315
|
+
size: finalResponse.usage.size,
|
|
1316
|
+
// wan3-only. Spread rather than set to undefined so the
|
|
1317
|
+
// metadata shape for older wan models is unchanged.
|
|
1318
|
+
...finalResponse.usage.input_video_duration != null ? {
|
|
1319
|
+
inputVideoDuration: finalResponse.usage.input_video_duration
|
|
1320
|
+
} : {},
|
|
1321
|
+
...finalResponse.usage.fps != null ? { fps: finalResponse.usage.fps } : {},
|
|
1322
|
+
...finalResponse.usage.ratio != null ? { ratio: finalResponse.usage.ratio } : {}
|
|
1285
1323
|
}
|
|
1286
1324
|
} : {}
|
|
1287
1325
|
}
|
|
@@ -1291,7 +1329,7 @@ var AlibabaVideoModel = class {
|
|
|
1291
1329
|
};
|
|
1292
1330
|
|
|
1293
1331
|
// src/version.ts
|
|
1294
|
-
var VERSION = true ? "1.0.
|
|
1332
|
+
var VERSION = true ? "1.0.51" : "0.0.0-test";
|
|
1295
1333
|
|
|
1296
1334
|
// src/alibaba-provider.ts
|
|
1297
1335
|
function createAlibaba(options = {}) {
|