@ai-sdk/alibaba 2.0.0-beta.25 → 2.0.0-beta.26
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 +13 -0
- package/dist/index.js +199 -189
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/dist/index.d.mts +0 -119
- package/dist/index.mjs +0 -1086
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,69 +1,64 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
VERSION: () => VERSION,
|
|
24
|
-
alibaba: () => alibaba,
|
|
25
|
-
createAlibaba: () => createAlibaba
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(index_exports);
|
|
28
|
-
|
|
29
1
|
// src/alibaba-provider.ts
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
2
|
+
import {
|
|
3
|
+
NoSuchModelError
|
|
4
|
+
} from "@ai-sdk/provider";
|
|
5
|
+
import {
|
|
6
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
|
|
7
|
+
loadApiKey,
|
|
8
|
+
withoutTrailingSlash,
|
|
9
|
+
withUserAgentSuffix
|
|
10
|
+
} from "@ai-sdk/provider-utils";
|
|
11
|
+
import { z as z4 } from "zod/v4";
|
|
33
12
|
|
|
34
13
|
// src/alibaba-chat-language-model.ts
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
14
|
+
import {
|
|
15
|
+
getResponseMetadata,
|
|
16
|
+
mapOpenAICompatibleFinishReason,
|
|
17
|
+
prepareTools
|
|
18
|
+
} from "@ai-sdk/openai-compatible/internal";
|
|
19
|
+
import {
|
|
20
|
+
InvalidResponseDataError
|
|
21
|
+
} from "@ai-sdk/provider";
|
|
22
|
+
import {
|
|
23
|
+
combineHeaders,
|
|
24
|
+
createEventSourceResponseHandler,
|
|
25
|
+
createJsonResponseHandler,
|
|
26
|
+
generateId,
|
|
27
|
+
isCustomReasoning,
|
|
28
|
+
isParsableJson,
|
|
29
|
+
mapReasoningToProviderBudget,
|
|
30
|
+
parseProviderOptions,
|
|
31
|
+
postJsonToApi
|
|
32
|
+
} from "@ai-sdk/provider-utils";
|
|
33
|
+
import { z as z2 } from "zod/v4";
|
|
39
34
|
|
|
40
35
|
// src/alibaba-chat-options.ts
|
|
41
|
-
|
|
42
|
-
var alibabaLanguageModelOptions =
|
|
36
|
+
import { z } from "zod/v4";
|
|
37
|
+
var alibabaLanguageModelOptions = z.object({
|
|
43
38
|
/**
|
|
44
39
|
* Enable thinking/reasoning mode for supported models.
|
|
45
40
|
* When enabled, the model generates reasoning content before the response.
|
|
46
41
|
*
|
|
47
42
|
* @default false
|
|
48
43
|
*/
|
|
49
|
-
enableThinking:
|
|
44
|
+
enableThinking: z.boolean().optional(),
|
|
50
45
|
/**
|
|
51
46
|
* Maximum number of reasoning tokens to generate.
|
|
52
47
|
*/
|
|
53
|
-
thinkingBudget:
|
|
48
|
+
thinkingBudget: z.number().positive().optional(),
|
|
54
49
|
/**
|
|
55
50
|
* Whether to enable parallel function calling during tool use.
|
|
56
51
|
*
|
|
57
52
|
* @default true
|
|
58
53
|
*/
|
|
59
|
-
parallelToolCalls:
|
|
54
|
+
parallelToolCalls: z.boolean().optional()
|
|
60
55
|
});
|
|
61
56
|
|
|
62
57
|
// src/convert-alibaba-usage.ts
|
|
63
|
-
|
|
58
|
+
import { convertOpenAICompatibleChatUsage } from "@ai-sdk/openai-compatible/internal";
|
|
64
59
|
function convertAlibabaUsage(usage) {
|
|
65
60
|
var _a, _b, _c, _d;
|
|
66
|
-
const baseUsage =
|
|
61
|
+
const baseUsage = convertOpenAICompatibleChatUsage(usage);
|
|
67
62
|
const cacheWriteTokens = (_b = (_a = usage == null ? void 0 : usage.prompt_tokens_details) == null ? void 0 : _a.cache_creation_input_tokens) != null ? _b : 0;
|
|
68
63
|
const noCacheTokens = ((_c = baseUsage.inputTokens.total) != null ? _c : 0) - ((_d = baseUsage.inputTokens.cacheRead) != null ? _d : 0) - cacheWriteTokens;
|
|
69
64
|
return {
|
|
@@ -77,13 +72,15 @@ function convertAlibabaUsage(usage) {
|
|
|
77
72
|
}
|
|
78
73
|
|
|
79
74
|
// src/convert-to-alibaba-chat-messages.ts
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
import {
|
|
76
|
+
UnsupportedFunctionalityError
|
|
77
|
+
} from "@ai-sdk/provider";
|
|
78
|
+
import { convertToBase64, isProviderReference } from "@ai-sdk/provider-utils";
|
|
82
79
|
function formatImageUrl({
|
|
83
80
|
data,
|
|
84
81
|
mediaType
|
|
85
82
|
}) {
|
|
86
|
-
return data instanceof URL ? data.toString() : `data:${mediaType};base64,${
|
|
83
|
+
return data instanceof URL ? data.toString() : `data:${mediaType};base64,${convertToBase64(data)}`;
|
|
87
84
|
}
|
|
88
85
|
function convertToAlibabaChatMessages({
|
|
89
86
|
prompt,
|
|
@@ -129,8 +126,8 @@ function convertToAlibabaChatMessages({
|
|
|
129
126
|
};
|
|
130
127
|
}
|
|
131
128
|
case "file": {
|
|
132
|
-
if (
|
|
133
|
-
throw new
|
|
129
|
+
if (isProviderReference(part.data)) {
|
|
130
|
+
throw new UnsupportedFunctionalityError({
|
|
134
131
|
functionality: "file parts with provider references"
|
|
135
132
|
});
|
|
136
133
|
}
|
|
@@ -144,7 +141,7 @@ function convertToAlibabaChatMessages({
|
|
|
144
141
|
...partCacheControl ? { cache_control: partCacheControl } : {}
|
|
145
142
|
};
|
|
146
143
|
} else {
|
|
147
|
-
throw new
|
|
144
|
+
throw new UnsupportedFunctionalityError({
|
|
148
145
|
functionality: "Only image file parts are supported"
|
|
149
146
|
});
|
|
150
147
|
}
|
|
@@ -304,7 +301,7 @@ var AlibabaLanguageModel = class {
|
|
|
304
301
|
var _a;
|
|
305
302
|
const warnings = [];
|
|
306
303
|
const cacheControlValidator = new CacheControlValidator();
|
|
307
|
-
const alibabaOptions = await
|
|
304
|
+
const alibabaOptions = await parseProviderOptions({
|
|
308
305
|
provider: "alibaba",
|
|
309
306
|
providerOptions,
|
|
310
307
|
schema: alibabaLanguageModelOptions
|
|
@@ -344,7 +341,7 @@ var AlibabaLanguageModel = class {
|
|
|
344
341
|
tools: alibabaTools,
|
|
345
342
|
toolChoice: alibabaToolChoice,
|
|
346
343
|
toolWarnings
|
|
347
|
-
} =
|
|
344
|
+
} = prepareTools({ tools, toolChoice });
|
|
348
345
|
warnings.push(...cacheControlValidator.getWarnings());
|
|
349
346
|
return {
|
|
350
347
|
args: {
|
|
@@ -363,12 +360,12 @@ var AlibabaLanguageModel = class {
|
|
|
363
360
|
responseHeaders,
|
|
364
361
|
value: response,
|
|
365
362
|
rawValue: rawResponse
|
|
366
|
-
} = await
|
|
363
|
+
} = await postJsonToApi({
|
|
367
364
|
url: `${this.config.baseURL}/chat/completions`,
|
|
368
|
-
headers:
|
|
365
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
369
366
|
body: args,
|
|
370
367
|
failedResponseHandler: alibabaFailedResponseHandler,
|
|
371
|
-
successfulResponseHandler:
|
|
368
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
372
369
|
alibabaChatResponseSchema
|
|
373
370
|
),
|
|
374
371
|
abortSignal: options.abortSignal,
|
|
@@ -400,13 +397,13 @@ var AlibabaLanguageModel = class {
|
|
|
400
397
|
return {
|
|
401
398
|
content,
|
|
402
399
|
finishReason: {
|
|
403
|
-
unified:
|
|
400
|
+
unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
|
|
404
401
|
raw: (_a = choice.finish_reason) != null ? _a : void 0
|
|
405
402
|
},
|
|
406
403
|
usage: convertAlibabaUsage(response.usage),
|
|
407
404
|
request: { body: JSON.stringify(args) },
|
|
408
405
|
response: {
|
|
409
|
-
...
|
|
406
|
+
...getResponseMetadata(response),
|
|
410
407
|
headers: responseHeaders,
|
|
411
408
|
body: rawResponse
|
|
412
409
|
},
|
|
@@ -420,12 +417,12 @@ var AlibabaLanguageModel = class {
|
|
|
420
417
|
stream: true,
|
|
421
418
|
stream_options: this.config.includeUsage ? { include_usage: true } : void 0
|
|
422
419
|
};
|
|
423
|
-
const { responseHeaders, value: response } = await
|
|
420
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
424
421
|
url: `${this.config.baseURL}/chat/completions`,
|
|
425
|
-
headers:
|
|
422
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
426
423
|
body,
|
|
427
424
|
failedResponseHandler: alibabaFailedResponseHandler,
|
|
428
|
-
successfulResponseHandler:
|
|
425
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
429
426
|
alibabaChatChunkSchema
|
|
430
427
|
),
|
|
431
428
|
abortSignal: options.abortSignal,
|
|
@@ -460,7 +457,7 @@ var AlibabaLanguageModel = class {
|
|
|
460
457
|
isFirstChunk = false;
|
|
461
458
|
controller.enqueue({
|
|
462
459
|
type: "response-metadata",
|
|
463
|
-
...
|
|
460
|
+
...getResponseMetadata(value)
|
|
464
461
|
});
|
|
465
462
|
}
|
|
466
463
|
if (value.usage != null) {
|
|
@@ -477,7 +474,7 @@ var AlibabaLanguageModel = class {
|
|
|
477
474
|
controller.enqueue({ type: "text-end", id: "0" });
|
|
478
475
|
activeText = false;
|
|
479
476
|
}
|
|
480
|
-
activeReasoningId =
|
|
477
|
+
activeReasoningId = generateId();
|
|
481
478
|
controller.enqueue({
|
|
482
479
|
type: "reasoning-start",
|
|
483
480
|
id: activeReasoningId
|
|
@@ -523,13 +520,13 @@ var AlibabaLanguageModel = class {
|
|
|
523
520
|
const index = (_a = toolCallDelta.index) != null ? _a : toolCalls.length;
|
|
524
521
|
if (toolCalls[index] == null) {
|
|
525
522
|
if (toolCallDelta.id == null) {
|
|
526
|
-
throw new
|
|
523
|
+
throw new InvalidResponseDataError({
|
|
527
524
|
data: toolCallDelta,
|
|
528
525
|
message: `Expected 'id' to be a string.`
|
|
529
526
|
});
|
|
530
527
|
}
|
|
531
528
|
if (((_b = toolCallDelta.function) == null ? void 0 : _b.name) == null) {
|
|
532
|
-
throw new
|
|
529
|
+
throw new InvalidResponseDataError({
|
|
533
530
|
data: toolCallDelta,
|
|
534
531
|
message: `Expected 'function.name' to be a string.`
|
|
535
532
|
});
|
|
@@ -556,7 +553,7 @@ var AlibabaLanguageModel = class {
|
|
|
556
553
|
delta: toolCall2.function.arguments
|
|
557
554
|
});
|
|
558
555
|
}
|
|
559
|
-
if (
|
|
556
|
+
if (isParsableJson(toolCall2.function.arguments)) {
|
|
560
557
|
controller.enqueue({
|
|
561
558
|
type: "tool-input-end",
|
|
562
559
|
id: toolCall2.id
|
|
@@ -583,7 +580,7 @@ var AlibabaLanguageModel = class {
|
|
|
583
580
|
delta: toolCallDelta.function.arguments
|
|
584
581
|
});
|
|
585
582
|
}
|
|
586
|
-
if (
|
|
583
|
+
if (isParsableJson(toolCall.function.arguments)) {
|
|
587
584
|
controller.enqueue({
|
|
588
585
|
type: "tool-input-end",
|
|
589
586
|
id: toolCall.id
|
|
@@ -600,7 +597,7 @@ var AlibabaLanguageModel = class {
|
|
|
600
597
|
}
|
|
601
598
|
if (choice.finish_reason != null) {
|
|
602
599
|
finishReason = {
|
|
603
|
-
unified:
|
|
600
|
+
unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
|
|
604
601
|
raw: choice.finish_reason
|
|
605
602
|
};
|
|
606
603
|
}
|
|
@@ -639,13 +636,13 @@ function resolveAlibabaThinking({
|
|
|
639
636
|
...alibabaOptions.thinkingBudget != null ? { thinking_budget: alibabaOptions.thinkingBudget } : {}
|
|
640
637
|
};
|
|
641
638
|
}
|
|
642
|
-
if (!
|
|
639
|
+
if (!isCustomReasoning(reasoning)) {
|
|
643
640
|
return {};
|
|
644
641
|
}
|
|
645
642
|
if (reasoning === "none") {
|
|
646
643
|
return { enable_thinking: false };
|
|
647
644
|
}
|
|
648
|
-
const thinkingBudget =
|
|
645
|
+
const thinkingBudget = mapReasoningToProviderBudget({
|
|
649
646
|
reasoning,
|
|
650
647
|
maxOutputTokens: 16384,
|
|
651
648
|
maxReasoningBudget: 16384,
|
|
@@ -656,72 +653,72 @@ function resolveAlibabaThinking({
|
|
|
656
653
|
...thinkingBudget != null ? { thinking_budget: thinkingBudget } : {}
|
|
657
654
|
};
|
|
658
655
|
}
|
|
659
|
-
var alibabaUsageSchema =
|
|
660
|
-
prompt_tokens:
|
|
661
|
-
completion_tokens:
|
|
662
|
-
total_tokens:
|
|
663
|
-
prompt_tokens_details:
|
|
664
|
-
cached_tokens:
|
|
665
|
-
cache_creation_input_tokens:
|
|
656
|
+
var alibabaUsageSchema = z2.object({
|
|
657
|
+
prompt_tokens: z2.number(),
|
|
658
|
+
completion_tokens: z2.number(),
|
|
659
|
+
total_tokens: z2.number(),
|
|
660
|
+
prompt_tokens_details: z2.object({
|
|
661
|
+
cached_tokens: z2.number().nullish(),
|
|
662
|
+
cache_creation_input_tokens: z2.number().nullish()
|
|
666
663
|
}).nullish(),
|
|
667
|
-
completion_tokens_details:
|
|
668
|
-
reasoning_tokens:
|
|
664
|
+
completion_tokens_details: z2.object({
|
|
665
|
+
reasoning_tokens: z2.number().nullish()
|
|
669
666
|
}).nullish()
|
|
670
667
|
});
|
|
671
|
-
var alibabaChatResponseSchema =
|
|
672
|
-
id:
|
|
673
|
-
created:
|
|
674
|
-
model:
|
|
675
|
-
choices:
|
|
676
|
-
|
|
677
|
-
message:
|
|
678
|
-
role:
|
|
679
|
-
content:
|
|
680
|
-
reasoning_content:
|
|
668
|
+
var alibabaChatResponseSchema = z2.object({
|
|
669
|
+
id: z2.string().nullish(),
|
|
670
|
+
created: z2.number().nullish(),
|
|
671
|
+
model: z2.string().nullish(),
|
|
672
|
+
choices: z2.array(
|
|
673
|
+
z2.object({
|
|
674
|
+
message: z2.object({
|
|
675
|
+
role: z2.literal("assistant").nullish(),
|
|
676
|
+
content: z2.string().nullish(),
|
|
677
|
+
reasoning_content: z2.string().nullish(),
|
|
681
678
|
// Alibaba thinking mode
|
|
682
|
-
tool_calls:
|
|
683
|
-
|
|
684
|
-
id:
|
|
685
|
-
type:
|
|
686
|
-
function:
|
|
687
|
-
name:
|
|
688
|
-
arguments:
|
|
679
|
+
tool_calls: z2.array(
|
|
680
|
+
z2.object({
|
|
681
|
+
id: z2.string(),
|
|
682
|
+
type: z2.literal("function"),
|
|
683
|
+
function: z2.object({
|
|
684
|
+
name: z2.string(),
|
|
685
|
+
arguments: z2.string()
|
|
689
686
|
})
|
|
690
687
|
})
|
|
691
688
|
).nullish()
|
|
692
689
|
}),
|
|
693
|
-
finish_reason:
|
|
694
|
-
index:
|
|
690
|
+
finish_reason: z2.string().nullish(),
|
|
691
|
+
index: z2.number()
|
|
695
692
|
})
|
|
696
693
|
),
|
|
697
694
|
usage: alibabaUsageSchema.nullish()
|
|
698
695
|
});
|
|
699
|
-
var alibabaChatChunkSchema =
|
|
700
|
-
id:
|
|
701
|
-
created:
|
|
702
|
-
model:
|
|
703
|
-
choices:
|
|
704
|
-
|
|
705
|
-
delta:
|
|
706
|
-
role:
|
|
707
|
-
content:
|
|
708
|
-
reasoning_content:
|
|
696
|
+
var alibabaChatChunkSchema = z2.object({
|
|
697
|
+
id: z2.string().nullish(),
|
|
698
|
+
created: z2.number().nullish(),
|
|
699
|
+
model: z2.string().nullish(),
|
|
700
|
+
choices: z2.array(
|
|
701
|
+
z2.object({
|
|
702
|
+
delta: z2.object({
|
|
703
|
+
role: z2.enum(["assistant"]).nullish(),
|
|
704
|
+
content: z2.string().nullish(),
|
|
705
|
+
reasoning_content: z2.string().nullish(),
|
|
709
706
|
// Alibaba thinking mode delta
|
|
710
|
-
tool_calls:
|
|
711
|
-
|
|
712
|
-
index:
|
|
707
|
+
tool_calls: z2.array(
|
|
708
|
+
z2.object({
|
|
709
|
+
index: z2.number().nullish(),
|
|
713
710
|
// Index for accumulating tool calls
|
|
714
|
-
id:
|
|
715
|
-
type:
|
|
716
|
-
function:
|
|
717
|
-
name:
|
|
718
|
-
arguments:
|
|
711
|
+
id: z2.string().nullish(),
|
|
712
|
+
type: z2.literal("function").nullish(),
|
|
713
|
+
function: z2.object({
|
|
714
|
+
name: z2.string().nullish(),
|
|
715
|
+
arguments: z2.string().nullish()
|
|
719
716
|
}).nullish()
|
|
720
717
|
})
|
|
721
718
|
).nullish()
|
|
722
719
|
}),
|
|
723
|
-
finish_reason:
|
|
724
|
-
index:
|
|
720
|
+
finish_reason: z2.string().nullish(),
|
|
721
|
+
index: z2.number()
|
|
725
722
|
})
|
|
726
723
|
),
|
|
727
724
|
usage: alibabaUsageSchema.nullish()
|
|
@@ -729,60 +726,74 @@ var alibabaChatChunkSchema = import_v42.z.object({
|
|
|
729
726
|
});
|
|
730
727
|
|
|
731
728
|
// src/alibaba-video-model.ts
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
729
|
+
import {
|
|
730
|
+
AISDKError
|
|
731
|
+
} from "@ai-sdk/provider";
|
|
732
|
+
import {
|
|
733
|
+
combineHeaders as combineHeaders2,
|
|
734
|
+
convertUint8ArrayToBase64,
|
|
735
|
+
createJsonErrorResponseHandler,
|
|
736
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
737
|
+
delay,
|
|
738
|
+
getFromApi,
|
|
739
|
+
lazySchema,
|
|
740
|
+
parseProviderOptions as parseProviderOptions2,
|
|
741
|
+
postJsonToApi as postJsonToApi2,
|
|
742
|
+
resolve,
|
|
743
|
+
zodSchema
|
|
744
|
+
} from "@ai-sdk/provider-utils";
|
|
745
|
+
import { z as z3 } from "zod/v4";
|
|
746
|
+
var alibabaVideoModelOptionsSchema = lazySchema(
|
|
747
|
+
() => zodSchema(
|
|
748
|
+
z3.object({
|
|
749
|
+
negativePrompt: z3.string().nullish(),
|
|
750
|
+
audioUrl: z3.string().nullish(),
|
|
751
|
+
promptExtend: z3.boolean().nullish(),
|
|
752
|
+
shotType: z3.enum(["single", "multi"]).nullish(),
|
|
753
|
+
watermark: z3.boolean().nullish(),
|
|
754
|
+
audio: z3.boolean().nullish(),
|
|
755
|
+
referenceUrls: z3.array(z3.string()).nullish(),
|
|
756
|
+
pollIntervalMs: z3.number().positive().nullish(),
|
|
757
|
+
pollTimeoutMs: z3.number().positive().nullish()
|
|
747
758
|
}).passthrough()
|
|
748
759
|
)
|
|
749
760
|
);
|
|
750
|
-
var alibabaVideoErrorSchema =
|
|
751
|
-
code:
|
|
752
|
-
message:
|
|
753
|
-
request_id:
|
|
761
|
+
var alibabaVideoErrorSchema = z3.object({
|
|
762
|
+
code: z3.string().nullish(),
|
|
763
|
+
message: z3.string(),
|
|
764
|
+
request_id: z3.string().nullish()
|
|
754
765
|
});
|
|
755
|
-
var alibabaVideoFailedResponseHandler =
|
|
766
|
+
var alibabaVideoFailedResponseHandler = createJsonErrorResponseHandler({
|
|
756
767
|
errorSchema: alibabaVideoErrorSchema,
|
|
757
768
|
errorToMessage: (data) => data.message
|
|
758
769
|
});
|
|
759
|
-
var alibabaVideoCreateTaskSchema =
|
|
760
|
-
output:
|
|
761
|
-
task_status:
|
|
762
|
-
task_id:
|
|
770
|
+
var alibabaVideoCreateTaskSchema = z3.object({
|
|
771
|
+
output: z3.object({
|
|
772
|
+
task_status: z3.string(),
|
|
773
|
+
task_id: z3.string()
|
|
763
774
|
}).nullish(),
|
|
764
|
-
request_id:
|
|
775
|
+
request_id: z3.string().nullish()
|
|
765
776
|
});
|
|
766
|
-
var alibabaVideoTaskStatusSchema =
|
|
767
|
-
output:
|
|
768
|
-
task_id:
|
|
769
|
-
task_status:
|
|
770
|
-
video_url:
|
|
771
|
-
submit_time:
|
|
772
|
-
scheduled_time:
|
|
773
|
-
end_time:
|
|
774
|
-
orig_prompt:
|
|
775
|
-
actual_prompt:
|
|
776
|
-
code:
|
|
777
|
-
message:
|
|
777
|
+
var alibabaVideoTaskStatusSchema = z3.object({
|
|
778
|
+
output: z3.object({
|
|
779
|
+
task_id: z3.string(),
|
|
780
|
+
task_status: z3.string(),
|
|
781
|
+
video_url: z3.string().nullish(),
|
|
782
|
+
submit_time: z3.string().nullish(),
|
|
783
|
+
scheduled_time: z3.string().nullish(),
|
|
784
|
+
end_time: z3.string().nullish(),
|
|
785
|
+
orig_prompt: z3.string().nullish(),
|
|
786
|
+
actual_prompt: z3.string().nullish(),
|
|
787
|
+
code: z3.string().nullish(),
|
|
788
|
+
message: z3.string().nullish()
|
|
778
789
|
}).nullish(),
|
|
779
|
-
usage:
|
|
780
|
-
duration:
|
|
781
|
-
output_video_duration:
|
|
782
|
-
SR:
|
|
783
|
-
size:
|
|
790
|
+
usage: z3.object({
|
|
791
|
+
duration: z3.number().nullish(),
|
|
792
|
+
output_video_duration: z3.number().nullish(),
|
|
793
|
+
SR: z3.number().nullish(),
|
|
794
|
+
size: z3.string().nullish()
|
|
784
795
|
}).nullish(),
|
|
785
|
-
request_id:
|
|
796
|
+
request_id: z3.string().nullish()
|
|
786
797
|
});
|
|
787
798
|
function detectMode(modelId) {
|
|
788
799
|
if (modelId.includes("-i2v")) return "i2v";
|
|
@@ -804,7 +815,7 @@ var AlibabaVideoModel = class {
|
|
|
804
815
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
805
816
|
const warnings = [];
|
|
806
817
|
const mode = detectMode(this.modelId);
|
|
807
|
-
const alibabaOptions = await (
|
|
818
|
+
const alibabaOptions = await parseProviderOptions2({
|
|
808
819
|
provider: "alibaba",
|
|
809
820
|
providerOptions: options.providerOptions,
|
|
810
821
|
schema: alibabaVideoModelOptionsSchema
|
|
@@ -823,7 +834,7 @@ var AlibabaVideoModel = class {
|
|
|
823
834
|
if (options.image.type === "url") {
|
|
824
835
|
input.img_url = options.image.url;
|
|
825
836
|
} else {
|
|
826
|
-
const base64Data = typeof options.image.data === "string" ? options.image.data :
|
|
837
|
+
const base64Data = typeof options.image.data === "string" ? options.image.data : convertUint8ArrayToBase64(options.image.data);
|
|
827
838
|
input.img_url = base64Data;
|
|
828
839
|
}
|
|
829
840
|
}
|
|
@@ -892,10 +903,10 @@ var AlibabaVideoModel = class {
|
|
|
892
903
|
details: "Alibaba video models only support generating 1 video per call."
|
|
893
904
|
});
|
|
894
905
|
}
|
|
895
|
-
const { value: createResponse } = await (
|
|
906
|
+
const { value: createResponse } = await postJsonToApi2({
|
|
896
907
|
url: `${this.config.baseURL}/api/v1/services/aigc/video-generation/video-synthesis`,
|
|
897
|
-
headers: (
|
|
898
|
-
await
|
|
908
|
+
headers: combineHeaders2(
|
|
909
|
+
await resolve(this.config.headers),
|
|
899
910
|
options.headers,
|
|
900
911
|
{
|
|
901
912
|
"X-DashScope-Async": "enable"
|
|
@@ -906,7 +917,7 @@ var AlibabaVideoModel = class {
|
|
|
906
917
|
input,
|
|
907
918
|
parameters
|
|
908
919
|
},
|
|
909
|
-
successfulResponseHandler: (
|
|
920
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
910
921
|
alibabaVideoCreateTaskSchema
|
|
911
922
|
),
|
|
912
923
|
failedResponseHandler: alibabaVideoFailedResponseHandler,
|
|
@@ -915,7 +926,7 @@ var AlibabaVideoModel = class {
|
|
|
915
926
|
});
|
|
916
927
|
const taskId = (_d = createResponse.output) == null ? void 0 : _d.task_id;
|
|
917
928
|
if (!taskId) {
|
|
918
|
-
throw new
|
|
929
|
+
throw new AISDKError({
|
|
919
930
|
name: "ALIBABA_VIDEO_GENERATION_ERROR",
|
|
920
931
|
message: `No task_id returned from Alibaba API. Response: ${JSON.stringify(createResponse)}`
|
|
921
932
|
});
|
|
@@ -926,20 +937,20 @@ var AlibabaVideoModel = class {
|
|
|
926
937
|
let finalResponse;
|
|
927
938
|
let responseHeaders;
|
|
928
939
|
while (true) {
|
|
929
|
-
await
|
|
940
|
+
await delay(pollIntervalMs, { abortSignal: options.abortSignal });
|
|
930
941
|
if (Date.now() - startTime > pollTimeoutMs) {
|
|
931
|
-
throw new
|
|
942
|
+
throw new AISDKError({
|
|
932
943
|
name: "ALIBABA_VIDEO_GENERATION_TIMEOUT",
|
|
933
944
|
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
934
945
|
});
|
|
935
946
|
}
|
|
936
|
-
const { value: statusResponse, responseHeaders: pollHeaders } = await
|
|
947
|
+
const { value: statusResponse, responseHeaders: pollHeaders } = await getFromApi({
|
|
937
948
|
url: `${this.config.baseURL}/api/v1/tasks/${taskId}`,
|
|
938
|
-
headers: (
|
|
939
|
-
await
|
|
949
|
+
headers: combineHeaders2(
|
|
950
|
+
await resolve(this.config.headers),
|
|
940
951
|
options.headers
|
|
941
952
|
),
|
|
942
|
-
successfulResponseHandler: (
|
|
953
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
943
954
|
alibabaVideoTaskStatusSchema
|
|
944
955
|
),
|
|
945
956
|
failedResponseHandler: alibabaVideoFailedResponseHandler,
|
|
@@ -953,7 +964,7 @@ var AlibabaVideoModel = class {
|
|
|
953
964
|
break;
|
|
954
965
|
}
|
|
955
966
|
if (taskStatus === "FAILED" || taskStatus === "CANCELED") {
|
|
956
|
-
throw new
|
|
967
|
+
throw new AISDKError({
|
|
957
968
|
name: "ALIBABA_VIDEO_GENERATION_FAILED",
|
|
958
969
|
message: `Video generation ${taskStatus.toLowerCase()}. Task ID: ${taskId}. ${(_i = (_h = statusResponse.output) == null ? void 0 : _h.message) != null ? _i : ""}`
|
|
959
970
|
});
|
|
@@ -961,7 +972,7 @@ var AlibabaVideoModel = class {
|
|
|
961
972
|
}
|
|
962
973
|
const videoUrl = (_j = finalResponse == null ? void 0 : finalResponse.output) == null ? void 0 : _j.video_url;
|
|
963
974
|
if (!videoUrl) {
|
|
964
|
-
throw new
|
|
975
|
+
throw new AISDKError({
|
|
965
976
|
name: "ALIBABA_VIDEO_GENERATION_ERROR",
|
|
966
977
|
message: `No video URL in response. Task ID: ${taskId}`
|
|
967
978
|
});
|
|
@@ -1000,27 +1011,27 @@ var AlibabaVideoModel = class {
|
|
|
1000
1011
|
};
|
|
1001
1012
|
|
|
1002
1013
|
// src/version.ts
|
|
1003
|
-
var VERSION = "2.0.0-beta.
|
|
1014
|
+
var VERSION = "2.0.0-beta.26";
|
|
1004
1015
|
|
|
1005
1016
|
// src/alibaba-provider.ts
|
|
1006
|
-
var alibabaErrorDataSchema =
|
|
1007
|
-
error:
|
|
1008
|
-
message:
|
|
1009
|
-
code:
|
|
1010
|
-
type:
|
|
1017
|
+
var alibabaErrorDataSchema = z4.object({
|
|
1018
|
+
error: z4.object({
|
|
1019
|
+
message: z4.string(),
|
|
1020
|
+
code: z4.string().nullish(),
|
|
1021
|
+
type: z4.string().nullish()
|
|
1011
1022
|
})
|
|
1012
1023
|
});
|
|
1013
|
-
var alibabaFailedResponseHandler = (
|
|
1024
|
+
var alibabaFailedResponseHandler = createJsonErrorResponseHandler2({
|
|
1014
1025
|
errorSchema: alibabaErrorDataSchema,
|
|
1015
1026
|
errorToMessage: (data) => data.error.message
|
|
1016
1027
|
});
|
|
1017
1028
|
function createAlibaba(options = {}) {
|
|
1018
1029
|
var _a, _b;
|
|
1019
|
-
const baseURL = (_a =
|
|
1020
|
-
const videoBaseURL = (_b =
|
|
1021
|
-
const getHeaders = () =>
|
|
1030
|
+
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://dashscope-intl.aliyuncs.com/compatible-mode/v1";
|
|
1031
|
+
const videoBaseURL = (_b = withoutTrailingSlash(options.videoBaseURL)) != null ? _b : "https://dashscope-intl.aliyuncs.com";
|
|
1032
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
1022
1033
|
{
|
|
1023
|
-
Authorization: `Bearer ${
|
|
1034
|
+
Authorization: `Bearer ${loadApiKey({
|
|
1024
1035
|
apiKey: options.apiKey,
|
|
1025
1036
|
environmentVariableName: "ALIBABA_API_KEY",
|
|
1026
1037
|
description: "Alibaba Cloud (DashScope)"
|
|
@@ -1059,18 +1070,17 @@ function createAlibaba(options = {}) {
|
|
|
1059
1070
|
provider.video = createVideoModel;
|
|
1060
1071
|
provider.videoModel = createVideoModel;
|
|
1061
1072
|
provider.imageModel = (modelId) => {
|
|
1062
|
-
throw new
|
|
1073
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
1063
1074
|
};
|
|
1064
1075
|
provider.embeddingModel = (modelId) => {
|
|
1065
|
-
throw new
|
|
1076
|
+
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
1066
1077
|
};
|
|
1067
1078
|
return provider;
|
|
1068
1079
|
}
|
|
1069
1080
|
var alibaba = createAlibaba();
|
|
1070
|
-
|
|
1071
|
-
0 && (module.exports = {
|
|
1081
|
+
export {
|
|
1072
1082
|
VERSION,
|
|
1073
1083
|
alibaba,
|
|
1074
1084
|
createAlibaba
|
|
1075
|
-
}
|
|
1085
|
+
};
|
|
1076
1086
|
//# sourceMappingURL=index.js.map
|