@ai-sdk/alibaba 1.0.1 → 1.0.2

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,11 @@
1
1
  # @ai-sdk/alibaba
2
2
 
3
+ ## 1.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 4d8c6b9: feat (provider/alibaba): add video generation support
8
+
3
9
  ## 1.0.1
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import { FetchFunction } from '@ai-sdk/provider-utils';
2
- import { ProviderV3, LanguageModelV3 } from '@ai-sdk/provider';
3
1
  import { z } from 'zod/v4';
2
+ import { FetchFunction } from '@ai-sdk/provider-utils';
3
+ import { ProviderV3, LanguageModelV3, Experimental_VideoModelV3 } from '@ai-sdk/provider';
4
4
 
5
5
  type AlibabaChatModelId = 'qwen3-max' | 'qwen3-max-preview' | 'qwen-plus' | 'qwen-plus-latest' | 'qwen-flash' | 'qwen-turbo' | 'qwen-turbo-latest' | 'qwen3-235b-a22b' | 'qwen3-32b' | 'qwen3-30b-a3b' | 'qwen3-14b' | 'qwen3-next-80b-a3b-thinking' | 'qwen3-235b-a22b-thinking-2507' | 'qwen3-30b-a3b-thinking-2507' | 'qwq-plus' | 'qwq-plus-latest' | 'qwq-32b' | 'qwen-coder' | 'qwen3-coder-plus' | 'qwen3-coder-flash' | (string & {});
6
6
  declare const alibabaProviderOptions: z.ZodObject<{
@@ -10,6 +10,12 @@ declare const alibabaProviderOptions: z.ZodObject<{
10
10
  }, z.core.$strip>;
11
11
  type AlibabaProviderOptions = z.infer<typeof alibabaProviderOptions>;
12
12
 
13
+ type AlibabaCacheControl = {
14
+ type: string;
15
+ };
16
+
17
+ type AlibabaVideoModelId = 'wan2.6-t2v' | 'wan2.5-t2v-preview' | 'wan2.6-i2v' | 'wan2.6-i2v-flash' | 'wan2.6-r2v' | 'wan2.6-r2v-flash' | (string & {});
18
+
13
19
  interface AlibabaProvider extends ProviderV3 {
14
20
  (modelId: AlibabaChatModelId): LanguageModelV3;
15
21
  /**
@@ -20,6 +26,14 @@ interface AlibabaProvider extends ProviderV3 {
20
26
  * Creates a chat model for text generation.
21
27
  */
22
28
  chatModel(modelId: AlibabaChatModelId): LanguageModelV3;
29
+ /**
30
+ * Creates a model for video generation.
31
+ */
32
+ video(modelId: AlibabaVideoModelId): Experimental_VideoModelV3;
33
+ /**
34
+ * Creates a model for video generation.
35
+ */
36
+ videoModel(modelId: AlibabaVideoModelId): Experimental_VideoModelV3;
23
37
  }
24
38
  interface AlibabaProviderSettings {
25
39
  /**
@@ -27,6 +41,12 @@ interface AlibabaProviderSettings {
27
41
  * The default prefix is `https://dashscope-intl.aliyuncs.com/compatible-mode/v1`.
28
42
  */
29
43
  baseURL?: string;
44
+ /**
45
+ * Use a different URL prefix for video generation API calls.
46
+ * The video API uses the DashScope native endpoint (not the OpenAI-compatible endpoint).
47
+ * The default prefix is `https://dashscope-intl.aliyuncs.com`.
48
+ */
49
+ videoBaseURL?: string;
30
50
  /**
31
51
  * API key that is being sent using the `Authorization` header.
32
52
  * It defaults to the `ALIBABA_API_KEY` environment variable.
@@ -55,8 +75,30 @@ interface AlibabaProviderSettings {
55
75
  declare function createAlibaba(options?: AlibabaProviderSettings): AlibabaProvider;
56
76
  declare const alibaba: AlibabaProvider;
57
77
 
58
- type AlibabaCacheControl = {
59
- type: string;
78
+ type AlibabaVideoProviderOptions = {
79
+ /** Negative prompt to specify what to avoid (max 500 chars). */
80
+ negativePrompt?: string | null;
81
+ /** URL to audio file for audio-video sync (WAV/MP3, 3-30s, max 15MB). */
82
+ audioUrl?: string | null;
83
+ /** Enable prompt extension/rewriting for better generation. Defaults to true. */
84
+ promptExtend?: boolean | null;
85
+ /** Shot type: 'single' for single-shot or 'multi' for multi-shot narrative. */
86
+ shotType?: 'single' | 'multi' | null;
87
+ /** Whether to add watermark to generated video. Defaults to false. */
88
+ watermark?: boolean | null;
89
+ /** Enable audio generation (for I2V/R2V models). */
90
+ audio?: boolean | null;
91
+ /**
92
+ * Reference URLs for reference-to-video mode.
93
+ * Array of URLs to images (0-5) and/or videos (0-3), max 5 total.
94
+ * Use character identifiers (character1, character2) in prompts to reference them.
95
+ */
96
+ referenceUrls?: string[] | null;
97
+ /** Polling interval in milliseconds. Defaults to 5000 (5 seconds). */
98
+ pollIntervalMs?: number | null;
99
+ /** Maximum wait time in milliseconds for video generation. Defaults to 600000 (10 minutes). */
100
+ pollTimeoutMs?: number | null;
101
+ [key: string]: unknown;
60
102
  };
61
103
 
62
104
  type AlibabaUsage = {
@@ -74,4 +116,4 @@ type AlibabaUsage = {
74
116
 
75
117
  declare const VERSION: string;
76
118
 
77
- export { type AlibabaCacheControl, type AlibabaChatModelId, type AlibabaProvider, type AlibabaProviderOptions, type AlibabaProviderSettings, type AlibabaUsage, VERSION, alibaba, createAlibaba };
119
+ export { type AlibabaCacheControl, type AlibabaChatModelId, type AlibabaProvider, type AlibabaProviderOptions, type AlibabaProviderSettings, type AlibabaUsage, type AlibabaVideoModelId, type AlibabaVideoProviderOptions, VERSION, alibaba, createAlibaba };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { FetchFunction } from '@ai-sdk/provider-utils';
2
- import { ProviderV3, LanguageModelV3 } from '@ai-sdk/provider';
3
1
  import { z } from 'zod/v4';
2
+ import { FetchFunction } from '@ai-sdk/provider-utils';
3
+ import { ProviderV3, LanguageModelV3, Experimental_VideoModelV3 } from '@ai-sdk/provider';
4
4
 
5
5
  type AlibabaChatModelId = 'qwen3-max' | 'qwen3-max-preview' | 'qwen-plus' | 'qwen-plus-latest' | 'qwen-flash' | 'qwen-turbo' | 'qwen-turbo-latest' | 'qwen3-235b-a22b' | 'qwen3-32b' | 'qwen3-30b-a3b' | 'qwen3-14b' | 'qwen3-next-80b-a3b-thinking' | 'qwen3-235b-a22b-thinking-2507' | 'qwen3-30b-a3b-thinking-2507' | 'qwq-plus' | 'qwq-plus-latest' | 'qwq-32b' | 'qwen-coder' | 'qwen3-coder-plus' | 'qwen3-coder-flash' | (string & {});
6
6
  declare const alibabaProviderOptions: z.ZodObject<{
@@ -10,6 +10,12 @@ declare const alibabaProviderOptions: z.ZodObject<{
10
10
  }, z.core.$strip>;
11
11
  type AlibabaProviderOptions = z.infer<typeof alibabaProviderOptions>;
12
12
 
13
+ type AlibabaCacheControl = {
14
+ type: string;
15
+ };
16
+
17
+ type AlibabaVideoModelId = 'wan2.6-t2v' | 'wan2.5-t2v-preview' | 'wan2.6-i2v' | 'wan2.6-i2v-flash' | 'wan2.6-r2v' | 'wan2.6-r2v-flash' | (string & {});
18
+
13
19
  interface AlibabaProvider extends ProviderV3 {
14
20
  (modelId: AlibabaChatModelId): LanguageModelV3;
15
21
  /**
@@ -20,6 +26,14 @@ interface AlibabaProvider extends ProviderV3 {
20
26
  * Creates a chat model for text generation.
21
27
  */
22
28
  chatModel(modelId: AlibabaChatModelId): LanguageModelV3;
29
+ /**
30
+ * Creates a model for video generation.
31
+ */
32
+ video(modelId: AlibabaVideoModelId): Experimental_VideoModelV3;
33
+ /**
34
+ * Creates a model for video generation.
35
+ */
36
+ videoModel(modelId: AlibabaVideoModelId): Experimental_VideoModelV3;
23
37
  }
24
38
  interface AlibabaProviderSettings {
25
39
  /**
@@ -27,6 +41,12 @@ interface AlibabaProviderSettings {
27
41
  * The default prefix is `https://dashscope-intl.aliyuncs.com/compatible-mode/v1`.
28
42
  */
29
43
  baseURL?: string;
44
+ /**
45
+ * Use a different URL prefix for video generation API calls.
46
+ * The video API uses the DashScope native endpoint (not the OpenAI-compatible endpoint).
47
+ * The default prefix is `https://dashscope-intl.aliyuncs.com`.
48
+ */
49
+ videoBaseURL?: string;
30
50
  /**
31
51
  * API key that is being sent using the `Authorization` header.
32
52
  * It defaults to the `ALIBABA_API_KEY` environment variable.
@@ -55,8 +75,30 @@ interface AlibabaProviderSettings {
55
75
  declare function createAlibaba(options?: AlibabaProviderSettings): AlibabaProvider;
56
76
  declare const alibaba: AlibabaProvider;
57
77
 
58
- type AlibabaCacheControl = {
59
- type: string;
78
+ type AlibabaVideoProviderOptions = {
79
+ /** Negative prompt to specify what to avoid (max 500 chars). */
80
+ negativePrompt?: string | null;
81
+ /** URL to audio file for audio-video sync (WAV/MP3, 3-30s, max 15MB). */
82
+ audioUrl?: string | null;
83
+ /** Enable prompt extension/rewriting for better generation. Defaults to true. */
84
+ promptExtend?: boolean | null;
85
+ /** Shot type: 'single' for single-shot or 'multi' for multi-shot narrative. */
86
+ shotType?: 'single' | 'multi' | null;
87
+ /** Whether to add watermark to generated video. Defaults to false. */
88
+ watermark?: boolean | null;
89
+ /** Enable audio generation (for I2V/R2V models). */
90
+ audio?: boolean | null;
91
+ /**
92
+ * Reference URLs for reference-to-video mode.
93
+ * Array of URLs to images (0-5) and/or videos (0-3), max 5 total.
94
+ * Use character identifiers (character1, character2) in prompts to reference them.
95
+ */
96
+ referenceUrls?: string[] | null;
97
+ /** Polling interval in milliseconds. Defaults to 5000 (5 seconds). */
98
+ pollIntervalMs?: number | null;
99
+ /** Maximum wait time in milliseconds for video generation. Defaults to 600000 (10 minutes). */
100
+ pollTimeoutMs?: number | null;
101
+ [key: string]: unknown;
60
102
  };
61
103
 
62
104
  type AlibabaUsage = {
@@ -74,4 +116,4 @@ type AlibabaUsage = {
74
116
 
75
117
  declare const VERSION: string;
76
118
 
77
- export { type AlibabaCacheControl, type AlibabaChatModelId, type AlibabaProvider, type AlibabaProviderOptions, type AlibabaProviderSettings, type AlibabaUsage, VERSION, alibaba, createAlibaba };
119
+ export { type AlibabaCacheControl, type AlibabaChatModelId, type AlibabaProvider, type AlibabaProviderOptions, type AlibabaProviderSettings, type AlibabaUsage, type AlibabaVideoModelId, type AlibabaVideoProviderOptions, VERSION, alibaba, createAlibaba };
package/dist/index.js CHANGED
@@ -27,15 +27,15 @@ __export(src_exports, {
27
27
  module.exports = __toCommonJS(src_exports);
28
28
 
29
29
  // src/alibaba-provider.ts
30
- var import_provider3 = require("@ai-sdk/provider");
31
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
32
- var import_v43 = require("zod/v4");
30
+ var import_provider4 = require("@ai-sdk/provider");
31
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
32
+ var import_v44 = require("zod/v4");
33
33
 
34
34
  // src/alibaba-chat-language-model.ts
35
+ var import_internal2 = require("@ai-sdk/openai-compatible/internal");
35
36
  var import_provider2 = require("@ai-sdk/provider");
36
37
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
37
38
  var import_v42 = require("zod/v4");
38
- var import_internal2 = require("@ai-sdk/openai-compatible/internal");
39
39
 
40
40
  // src/alibaba-chat-options.ts
41
41
  var import_v4 = require("zod/v4");
@@ -59,6 +59,23 @@ var alibabaProviderOptions = import_v4.z.object({
59
59
  parallelToolCalls: import_v4.z.boolean().optional()
60
60
  });
61
61
 
62
+ // src/convert-alibaba-usage.ts
63
+ var import_internal = require("@ai-sdk/openai-compatible/internal");
64
+ function convertAlibabaUsage(usage) {
65
+ var _a, _b, _c, _d;
66
+ const baseUsage = (0, import_internal.convertOpenAICompatibleChatUsage)(usage);
67
+ const cacheWriteTokens = (_b = (_a = usage == null ? void 0 : usage.prompt_tokens_details) == null ? void 0 : _a.cache_creation_input_tokens) != null ? _b : 0;
68
+ const noCacheTokens = ((_c = baseUsage.inputTokens.total) != null ? _c : 0) - ((_d = baseUsage.inputTokens.cacheRead) != null ? _d : 0) - cacheWriteTokens;
69
+ return {
70
+ ...baseUsage,
71
+ inputTokens: {
72
+ ...baseUsage.inputTokens,
73
+ cacheWrite: cacheWriteTokens,
74
+ noCache: noCacheTokens
75
+ }
76
+ };
77
+ }
78
+
62
79
  // src/convert-to-alibaba-chat-messages.ts
63
80
  var import_provider = require("@ai-sdk/provider");
64
81
  var import_provider_utils = require("@ai-sdk/provider-utils");
@@ -202,23 +219,6 @@ function convertToAlibabaChatMessages({
202
219
  return messages;
203
220
  }
204
221
 
205
- // src/convert-alibaba-usage.ts
206
- var import_internal = require("@ai-sdk/openai-compatible/internal");
207
- function convertAlibabaUsage(usage) {
208
- var _a, _b, _c, _d;
209
- const baseUsage = (0, import_internal.convertOpenAICompatibleChatUsage)(usage);
210
- const cacheWriteTokens = (_b = (_a = usage == null ? void 0 : usage.prompt_tokens_details) == null ? void 0 : _a.cache_creation_input_tokens) != null ? _b : 0;
211
- const noCacheTokens = ((_c = baseUsage.inputTokens.total) != null ? _c : 0) - ((_d = baseUsage.inputTokens.cacheRead) != null ? _d : 0) - cacheWriteTokens;
212
- return {
213
- ...baseUsage,
214
- inputTokens: {
215
- ...baseUsage.inputTokens,
216
- cacheWrite: cacheWriteTokens,
217
- noCache: noCacheTokens
218
- }
219
- };
220
- }
221
-
222
222
  // src/get-cache-control.ts
223
223
  var MAX_CACHE_BREAKPOINTS = 4;
224
224
  function getCacheControl(providerMetadata) {
@@ -682,27 +682,299 @@ var alibabaChatChunkSchema = import_v42.z.object({
682
682
  // Usage only appears in final chunk
683
683
  });
684
684
 
685
+ // src/alibaba-video-model.ts
686
+ var import_provider3 = require("@ai-sdk/provider");
687
+ var import_provider_utils3 = require("@ai-sdk/provider-utils");
688
+ var import_v43 = require("zod/v4");
689
+ var alibabaVideoProviderOptionsSchema = (0, import_provider_utils3.lazySchema)(
690
+ () => (0, import_provider_utils3.zodSchema)(
691
+ import_v43.z.object({
692
+ negativePrompt: import_v43.z.string().nullish(),
693
+ audioUrl: import_v43.z.string().nullish(),
694
+ promptExtend: import_v43.z.boolean().nullish(),
695
+ shotType: import_v43.z.enum(["single", "multi"]).nullish(),
696
+ watermark: import_v43.z.boolean().nullish(),
697
+ audio: import_v43.z.boolean().nullish(),
698
+ referenceUrls: import_v43.z.array(import_v43.z.string()).nullish(),
699
+ pollIntervalMs: import_v43.z.number().positive().nullish(),
700
+ pollTimeoutMs: import_v43.z.number().positive().nullish()
701
+ }).passthrough()
702
+ )
703
+ );
704
+ var alibabaVideoErrorSchema = import_v43.z.object({
705
+ code: import_v43.z.string().nullish(),
706
+ message: import_v43.z.string(),
707
+ request_id: import_v43.z.string().nullish()
708
+ });
709
+ var alibabaVideoFailedResponseHandler = (0, import_provider_utils3.createJsonErrorResponseHandler)({
710
+ errorSchema: alibabaVideoErrorSchema,
711
+ errorToMessage: (data) => data.message
712
+ });
713
+ var alibabaVideoCreateTaskSchema = import_v43.z.object({
714
+ output: import_v43.z.object({
715
+ task_status: import_v43.z.string(),
716
+ task_id: import_v43.z.string()
717
+ }).nullish(),
718
+ request_id: import_v43.z.string().nullish()
719
+ });
720
+ var alibabaVideoTaskStatusSchema = import_v43.z.object({
721
+ output: import_v43.z.object({
722
+ task_id: import_v43.z.string(),
723
+ task_status: import_v43.z.string(),
724
+ video_url: import_v43.z.string().nullish(),
725
+ submit_time: import_v43.z.string().nullish(),
726
+ scheduled_time: import_v43.z.string().nullish(),
727
+ end_time: import_v43.z.string().nullish(),
728
+ orig_prompt: import_v43.z.string().nullish(),
729
+ actual_prompt: import_v43.z.string().nullish(),
730
+ code: import_v43.z.string().nullish(),
731
+ message: import_v43.z.string().nullish()
732
+ }).nullish(),
733
+ usage: import_v43.z.object({
734
+ duration: import_v43.z.number().nullish(),
735
+ output_video_duration: import_v43.z.number().nullish(),
736
+ SR: import_v43.z.number().nullish(),
737
+ size: import_v43.z.string().nullish()
738
+ }).nullish(),
739
+ request_id: import_v43.z.string().nullish()
740
+ });
741
+ function detectMode(modelId) {
742
+ if (modelId.includes("-i2v")) return "i2v";
743
+ if (modelId.includes("-r2v")) return "r2v";
744
+ return "t2v";
745
+ }
746
+ var AlibabaVideoModel = class {
747
+ constructor(modelId, config) {
748
+ this.modelId = modelId;
749
+ this.config = config;
750
+ this.specificationVersion = "v3";
751
+ this.maxVideosPerCall = 1;
752
+ }
753
+ get provider() {
754
+ return this.config.provider;
755
+ }
756
+ async doGenerate(options) {
757
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
758
+ const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
759
+ const warnings = [];
760
+ const mode = detectMode(this.modelId);
761
+ const alibabaOptions = await (0, import_provider_utils3.parseProviderOptions)({
762
+ provider: "alibaba",
763
+ providerOptions: options.providerOptions,
764
+ schema: alibabaVideoProviderOptionsSchema
765
+ });
766
+ const input = {};
767
+ if (options.prompt != null) {
768
+ input.prompt = options.prompt;
769
+ }
770
+ if ((alibabaOptions == null ? void 0 : alibabaOptions.negativePrompt) != null) {
771
+ input.negative_prompt = alibabaOptions.negativePrompt;
772
+ }
773
+ if ((alibabaOptions == null ? void 0 : alibabaOptions.audioUrl) != null) {
774
+ input.audio_url = alibabaOptions.audioUrl;
775
+ }
776
+ if (mode === "i2v" && options.image != null) {
777
+ if (options.image.type === "url") {
778
+ input.img_url = options.image.url;
779
+ } else {
780
+ const base64Data = typeof options.image.data === "string" ? options.image.data : (0, import_provider_utils3.convertUint8ArrayToBase64)(options.image.data);
781
+ input.img_url = base64Data;
782
+ }
783
+ }
784
+ if (mode === "r2v" && (alibabaOptions == null ? void 0 : alibabaOptions.referenceUrls) != null) {
785
+ input.reference_urls = alibabaOptions.referenceUrls;
786
+ }
787
+ const parameters = {};
788
+ if (options.duration != null) {
789
+ parameters.duration = options.duration;
790
+ }
791
+ if (options.seed != null) {
792
+ parameters.seed = options.seed;
793
+ }
794
+ if (options.resolution != null) {
795
+ if (mode === "i2v") {
796
+ const resolutionMap = {
797
+ "1280x720": "720P",
798
+ "720x1280": "720P",
799
+ "960x960": "720P",
800
+ "1088x832": "720P",
801
+ "832x1088": "720P",
802
+ "1920x1080": "1080P",
803
+ "1080x1920": "1080P",
804
+ "1440x1440": "1080P",
805
+ "1632x1248": "1080P",
806
+ "1248x1632": "1080P",
807
+ "832x480": "480P",
808
+ "480x832": "480P",
809
+ "624x624": "480P"
810
+ };
811
+ parameters.resolution = resolutionMap[options.resolution] || options.resolution;
812
+ } else {
813
+ parameters.size = options.resolution.replace("x", "*");
814
+ }
815
+ }
816
+ if ((alibabaOptions == null ? void 0 : alibabaOptions.promptExtend) != null) {
817
+ parameters.prompt_extend = alibabaOptions.promptExtend;
818
+ }
819
+ if ((alibabaOptions == null ? void 0 : alibabaOptions.shotType) != null) {
820
+ parameters.shot_type = alibabaOptions.shotType;
821
+ }
822
+ if ((alibabaOptions == null ? void 0 : alibabaOptions.watermark) != null) {
823
+ parameters.watermark = alibabaOptions.watermark;
824
+ }
825
+ if ((alibabaOptions == null ? void 0 : alibabaOptions.audio) != null) {
826
+ parameters.audio = alibabaOptions.audio;
827
+ }
828
+ if (options.aspectRatio) {
829
+ warnings.push({
830
+ type: "unsupported",
831
+ feature: "aspectRatio",
832
+ details: "Alibaba video models use explicit size/resolution dimensions. Use the resolution option or providerOptions.alibaba for size control."
833
+ });
834
+ }
835
+ if (options.fps) {
836
+ warnings.push({
837
+ type: "unsupported",
838
+ feature: "fps",
839
+ details: "Alibaba video models do not support custom FPS."
840
+ });
841
+ }
842
+ if (options.n != null && options.n > 1) {
843
+ warnings.push({
844
+ type: "unsupported",
845
+ feature: "n",
846
+ details: "Alibaba video models only support generating 1 video per call."
847
+ });
848
+ }
849
+ const { value: createResponse } = await (0, import_provider_utils3.postJsonToApi)({
850
+ url: `${this.config.baseURL}/api/v1/services/aigc/video-generation/video-synthesis`,
851
+ headers: (0, import_provider_utils3.combineHeaders)(
852
+ await (0, import_provider_utils3.resolve)(this.config.headers),
853
+ options.headers,
854
+ {
855
+ "X-DashScope-Async": "enable"
856
+ }
857
+ ),
858
+ body: {
859
+ model: this.modelId,
860
+ input,
861
+ parameters
862
+ },
863
+ successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
864
+ alibabaVideoCreateTaskSchema
865
+ ),
866
+ failedResponseHandler: alibabaVideoFailedResponseHandler,
867
+ abortSignal: options.abortSignal,
868
+ fetch: this.config.fetch
869
+ });
870
+ const taskId = (_d = createResponse.output) == null ? void 0 : _d.task_id;
871
+ if (!taskId) {
872
+ throw new import_provider3.AISDKError({
873
+ name: "ALIBABA_VIDEO_GENERATION_ERROR",
874
+ message: `No task_id returned from Alibaba API. Response: ${JSON.stringify(createResponse)}`
875
+ });
876
+ }
877
+ const pollIntervalMs = (_e = alibabaOptions == null ? void 0 : alibabaOptions.pollIntervalMs) != null ? _e : 5e3;
878
+ const pollTimeoutMs = (_f = alibabaOptions == null ? void 0 : alibabaOptions.pollTimeoutMs) != null ? _f : 6e5;
879
+ const startTime = Date.now();
880
+ let finalResponse;
881
+ let responseHeaders;
882
+ while (true) {
883
+ await (0, import_provider_utils3.delay)(pollIntervalMs, { abortSignal: options.abortSignal });
884
+ if (Date.now() - startTime > pollTimeoutMs) {
885
+ throw new import_provider3.AISDKError({
886
+ name: "ALIBABA_VIDEO_GENERATION_TIMEOUT",
887
+ message: `Video generation timed out after ${pollTimeoutMs}ms`
888
+ });
889
+ }
890
+ const { value: statusResponse, responseHeaders: pollHeaders } = await (0, import_provider_utils3.getFromApi)({
891
+ url: `${this.config.baseURL}/api/v1/tasks/${taskId}`,
892
+ headers: (0, import_provider_utils3.combineHeaders)(
893
+ await (0, import_provider_utils3.resolve)(this.config.headers),
894
+ options.headers
895
+ ),
896
+ successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
897
+ alibabaVideoTaskStatusSchema
898
+ ),
899
+ failedResponseHandler: alibabaVideoFailedResponseHandler,
900
+ abortSignal: options.abortSignal,
901
+ fetch: this.config.fetch
902
+ });
903
+ responseHeaders = pollHeaders;
904
+ const taskStatus = (_g = statusResponse.output) == null ? void 0 : _g.task_status;
905
+ if (taskStatus === "SUCCEEDED") {
906
+ finalResponse = statusResponse;
907
+ break;
908
+ }
909
+ if (taskStatus === "FAILED" || taskStatus === "CANCELED") {
910
+ throw new import_provider3.AISDKError({
911
+ name: "ALIBABA_VIDEO_GENERATION_FAILED",
912
+ message: `Video generation ${taskStatus.toLowerCase()}. Task ID: ${taskId}. ${(_i = (_h = statusResponse.output) == null ? void 0 : _h.message) != null ? _i : ""}`
913
+ });
914
+ }
915
+ }
916
+ const videoUrl = (_j = finalResponse == null ? void 0 : finalResponse.output) == null ? void 0 : _j.video_url;
917
+ if (!videoUrl) {
918
+ throw new import_provider3.AISDKError({
919
+ name: "ALIBABA_VIDEO_GENERATION_ERROR",
920
+ message: `No video URL in response. Task ID: ${taskId}`
921
+ });
922
+ }
923
+ return {
924
+ videos: [
925
+ {
926
+ type: "url",
927
+ url: videoUrl,
928
+ mediaType: "video/mp4"
929
+ }
930
+ ],
931
+ warnings,
932
+ response: {
933
+ timestamp: currentDate,
934
+ modelId: this.modelId,
935
+ headers: responseHeaders
936
+ },
937
+ providerMetadata: {
938
+ alibaba: {
939
+ taskId,
940
+ videoUrl,
941
+ ...((_k = finalResponse == null ? void 0 : finalResponse.output) == null ? void 0 : _k.actual_prompt) ? { actualPrompt: finalResponse.output.actual_prompt } : {},
942
+ ...(finalResponse == null ? void 0 : finalResponse.usage) ? {
943
+ usage: {
944
+ duration: finalResponse.usage.duration,
945
+ outputVideoDuration: finalResponse.usage.output_video_duration,
946
+ resolution: finalResponse.usage.SR,
947
+ size: finalResponse.usage.size
948
+ }
949
+ } : {}
950
+ }
951
+ }
952
+ };
953
+ }
954
+ };
955
+
685
956
  // src/version.ts
686
- var VERSION = "1.0.1";
957
+ var VERSION = "1.0.2";
687
958
 
688
959
  // src/alibaba-provider.ts
689
- var alibabaErrorDataSchema = import_v43.z.object({
690
- error: import_v43.z.object({
691
- message: import_v43.z.string(),
692
- code: import_v43.z.string().nullish(),
693
- type: import_v43.z.string().nullish()
960
+ var alibabaErrorDataSchema = import_v44.z.object({
961
+ error: import_v44.z.object({
962
+ message: import_v44.z.string(),
963
+ code: import_v44.z.string().nullish(),
964
+ type: import_v44.z.string().nullish()
694
965
  })
695
966
  });
696
- var alibabaFailedResponseHandler = (0, import_provider_utils3.createJsonErrorResponseHandler)({
967
+ var alibabaFailedResponseHandler = (0, import_provider_utils4.createJsonErrorResponseHandler)({
697
968
  errorSchema: alibabaErrorDataSchema,
698
969
  errorToMessage: (data) => data.error.message
699
970
  });
700
971
  function createAlibaba(options = {}) {
701
- var _a;
702
- const baseURL = (_a = (0, import_provider_utils3.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://dashscope-intl.aliyuncs.com/compatible-mode/v1";
703
- const getHeaders = () => (0, import_provider_utils3.withUserAgentSuffix)(
972
+ var _a, _b;
973
+ const baseURL = (_a = (0, import_provider_utils4.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://dashscope-intl.aliyuncs.com/compatible-mode/v1";
974
+ const videoBaseURL = (_b = (0, import_provider_utils4.withoutTrailingSlash)(options.videoBaseURL)) != null ? _b : "https://dashscope-intl.aliyuncs.com";
975
+ const getHeaders = () => (0, import_provider_utils4.withUserAgentSuffix)(
704
976
  {
705
- Authorization: `Bearer ${(0, import_provider_utils3.loadApiKey)({
977
+ Authorization: `Bearer ${(0, import_provider_utils4.loadApiKey)({
706
978
  apiKey: options.apiKey,
707
979
  environmentVariableName: "ALIBABA_API_KEY",
708
980
  description: "Alibaba Cloud (DashScope)"
@@ -721,6 +993,12 @@ function createAlibaba(options = {}) {
721
993
  includeUsage: (_a2 = options.includeUsage) != null ? _a2 : true
722
994
  });
723
995
  };
996
+ const createVideoModel = (modelId) => new AlibabaVideoModel(modelId, {
997
+ provider: "alibaba.video",
998
+ baseURL: videoBaseURL,
999
+ headers: getHeaders,
1000
+ fetch: options.fetch
1001
+ });
724
1002
  const provider = function(modelId) {
725
1003
  if (new.target) {
726
1004
  throw new Error(
@@ -732,11 +1010,13 @@ function createAlibaba(options = {}) {
732
1010
  provider.specificationVersion = "v3";
733
1011
  provider.languageModel = createLanguageModel;
734
1012
  provider.chatModel = createLanguageModel;
1013
+ provider.video = createVideoModel;
1014
+ provider.videoModel = createVideoModel;
735
1015
  provider.imageModel = (modelId) => {
736
- throw new import_provider3.NoSuchModelError({ modelId, modelType: "imageModel" });
1016
+ throw new import_provider4.NoSuchModelError({ modelId, modelType: "imageModel" });
737
1017
  };
738
1018
  provider.embeddingModel = (modelId) => {
739
- throw new import_provider3.NoSuchModelError({ modelId, modelType: "embeddingModel" });
1019
+ throw new import_provider4.NoSuchModelError({ modelId, modelType: "embeddingModel" });
740
1020
  };
741
1021
  return provider;
742
1022
  }