@ai-sdk/alibaba 2.0.0-beta.25 → 2.0.0-beta.27
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 +31 -0
- package/dist/index.js +218 -195
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/alibaba-chat-language-model.ts +19 -2
- package/src/alibaba-config.ts +1 -1
- 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,67 @@
|
|
|
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
|
+
serializeModelOptions,
|
|
33
|
+
WORKFLOW_SERIALIZE,
|
|
34
|
+
WORKFLOW_DESERIALIZE
|
|
35
|
+
} from "@ai-sdk/provider-utils";
|
|
36
|
+
import { z as z2 } from "zod/v4";
|
|
39
37
|
|
|
40
38
|
// src/alibaba-chat-options.ts
|
|
41
|
-
|
|
42
|
-
var alibabaLanguageModelOptions =
|
|
39
|
+
import { z } from "zod/v4";
|
|
40
|
+
var alibabaLanguageModelOptions = z.object({
|
|
43
41
|
/**
|
|
44
42
|
* Enable thinking/reasoning mode for supported models.
|
|
45
43
|
* When enabled, the model generates reasoning content before the response.
|
|
46
44
|
*
|
|
47
45
|
* @default false
|
|
48
46
|
*/
|
|
49
|
-
enableThinking:
|
|
47
|
+
enableThinking: z.boolean().optional(),
|
|
50
48
|
/**
|
|
51
49
|
* Maximum number of reasoning tokens to generate.
|
|
52
50
|
*/
|
|
53
|
-
thinkingBudget:
|
|
51
|
+
thinkingBudget: z.number().positive().optional(),
|
|
54
52
|
/**
|
|
55
53
|
* Whether to enable parallel function calling during tool use.
|
|
56
54
|
*
|
|
57
55
|
* @default true
|
|
58
56
|
*/
|
|
59
|
-
parallelToolCalls:
|
|
57
|
+
parallelToolCalls: z.boolean().optional()
|
|
60
58
|
});
|
|
61
59
|
|
|
62
60
|
// src/convert-alibaba-usage.ts
|
|
63
|
-
|
|
61
|
+
import { convertOpenAICompatibleChatUsage } from "@ai-sdk/openai-compatible/internal";
|
|
64
62
|
function convertAlibabaUsage(usage) {
|
|
65
63
|
var _a, _b, _c, _d;
|
|
66
|
-
const baseUsage =
|
|
64
|
+
const baseUsage = convertOpenAICompatibleChatUsage(usage);
|
|
67
65
|
const cacheWriteTokens = (_b = (_a = usage == null ? void 0 : usage.prompt_tokens_details) == null ? void 0 : _a.cache_creation_input_tokens) != null ? _b : 0;
|
|
68
66
|
const noCacheTokens = ((_c = baseUsage.inputTokens.total) != null ? _c : 0) - ((_d = baseUsage.inputTokens.cacheRead) != null ? _d : 0) - cacheWriteTokens;
|
|
69
67
|
return {
|
|
@@ -77,13 +75,15 @@ function convertAlibabaUsage(usage) {
|
|
|
77
75
|
}
|
|
78
76
|
|
|
79
77
|
// src/convert-to-alibaba-chat-messages.ts
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
import {
|
|
79
|
+
UnsupportedFunctionalityError
|
|
80
|
+
} from "@ai-sdk/provider";
|
|
81
|
+
import { convertToBase64, isProviderReference } from "@ai-sdk/provider-utils";
|
|
82
82
|
function formatImageUrl({
|
|
83
83
|
data,
|
|
84
84
|
mediaType
|
|
85
85
|
}) {
|
|
86
|
-
return data instanceof URL ? data.toString() : `data:${mediaType};base64,${
|
|
86
|
+
return data instanceof URL ? data.toString() : `data:${mediaType};base64,${convertToBase64(data)}`;
|
|
87
87
|
}
|
|
88
88
|
function convertToAlibabaChatMessages({
|
|
89
89
|
prompt,
|
|
@@ -129,8 +129,8 @@ function convertToAlibabaChatMessages({
|
|
|
129
129
|
};
|
|
130
130
|
}
|
|
131
131
|
case "file": {
|
|
132
|
-
if (
|
|
133
|
-
throw new
|
|
132
|
+
if (isProviderReference(part.data)) {
|
|
133
|
+
throw new UnsupportedFunctionalityError({
|
|
134
134
|
functionality: "file parts with provider references"
|
|
135
135
|
});
|
|
136
136
|
}
|
|
@@ -144,7 +144,7 @@ function convertToAlibabaChatMessages({
|
|
|
144
144
|
...partCacheControl ? { cache_control: partCacheControl } : {}
|
|
145
145
|
};
|
|
146
146
|
} else {
|
|
147
|
-
throw new
|
|
147
|
+
throw new UnsupportedFunctionalityError({
|
|
148
148
|
functionality: "Only image file parts are supported"
|
|
149
149
|
});
|
|
150
150
|
}
|
|
@@ -269,7 +269,7 @@ var CacheControlValidator = class {
|
|
|
269
269
|
};
|
|
270
270
|
|
|
271
271
|
// src/alibaba-chat-language-model.ts
|
|
272
|
-
var AlibabaLanguageModel = class {
|
|
272
|
+
var AlibabaLanguageModel = class _AlibabaLanguageModel {
|
|
273
273
|
constructor(modelId, config) {
|
|
274
274
|
this.specificationVersion = "v4";
|
|
275
275
|
this.supportedUrls = {
|
|
@@ -278,6 +278,15 @@ var AlibabaLanguageModel = class {
|
|
|
278
278
|
this.modelId = modelId;
|
|
279
279
|
this.config = config;
|
|
280
280
|
}
|
|
281
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
282
|
+
return serializeModelOptions({
|
|
283
|
+
modelId: model.modelId,
|
|
284
|
+
config: model.config
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
288
|
+
return new _AlibabaLanguageModel(options.modelId, options.config);
|
|
289
|
+
}
|
|
281
290
|
get provider() {
|
|
282
291
|
return this.config.provider;
|
|
283
292
|
}
|
|
@@ -304,7 +313,7 @@ var AlibabaLanguageModel = class {
|
|
|
304
313
|
var _a;
|
|
305
314
|
const warnings = [];
|
|
306
315
|
const cacheControlValidator = new CacheControlValidator();
|
|
307
|
-
const alibabaOptions = await
|
|
316
|
+
const alibabaOptions = await parseProviderOptions({
|
|
308
317
|
provider: "alibaba",
|
|
309
318
|
providerOptions,
|
|
310
319
|
schema: alibabaLanguageModelOptions
|
|
@@ -344,7 +353,7 @@ var AlibabaLanguageModel = class {
|
|
|
344
353
|
tools: alibabaTools,
|
|
345
354
|
toolChoice: alibabaToolChoice,
|
|
346
355
|
toolWarnings
|
|
347
|
-
} =
|
|
356
|
+
} = prepareTools({ tools, toolChoice });
|
|
348
357
|
warnings.push(...cacheControlValidator.getWarnings());
|
|
349
358
|
return {
|
|
350
359
|
args: {
|
|
@@ -357,18 +366,18 @@ var AlibabaLanguageModel = class {
|
|
|
357
366
|
};
|
|
358
367
|
}
|
|
359
368
|
async doGenerate(options) {
|
|
360
|
-
var _a;
|
|
369
|
+
var _a, _b, _c;
|
|
361
370
|
const { args, warnings } = await this.getArgs(options);
|
|
362
371
|
const {
|
|
363
372
|
responseHeaders,
|
|
364
373
|
value: response,
|
|
365
374
|
rawValue: rawResponse
|
|
366
|
-
} = await
|
|
375
|
+
} = await postJsonToApi({
|
|
367
376
|
url: `${this.config.baseURL}/chat/completions`,
|
|
368
|
-
headers: (
|
|
377
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
369
378
|
body: args,
|
|
370
379
|
failedResponseHandler: alibabaFailedResponseHandler,
|
|
371
|
-
successfulResponseHandler:
|
|
380
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
372
381
|
alibabaChatResponseSchema
|
|
373
382
|
),
|
|
374
383
|
abortSignal: options.abortSignal,
|
|
@@ -400,13 +409,13 @@ var AlibabaLanguageModel = class {
|
|
|
400
409
|
return {
|
|
401
410
|
content,
|
|
402
411
|
finishReason: {
|
|
403
|
-
unified:
|
|
404
|
-
raw: (
|
|
412
|
+
unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
|
|
413
|
+
raw: (_c = choice.finish_reason) != null ? _c : void 0
|
|
405
414
|
},
|
|
406
415
|
usage: convertAlibabaUsage(response.usage),
|
|
407
416
|
request: { body: JSON.stringify(args) },
|
|
408
417
|
response: {
|
|
409
|
-
...
|
|
418
|
+
...getResponseMetadata(response),
|
|
410
419
|
headers: responseHeaders,
|
|
411
420
|
body: rawResponse
|
|
412
421
|
},
|
|
@@ -414,18 +423,19 @@ var AlibabaLanguageModel = class {
|
|
|
414
423
|
};
|
|
415
424
|
}
|
|
416
425
|
async doStream(options) {
|
|
426
|
+
var _a, _b;
|
|
417
427
|
const { args, warnings } = await this.getArgs(options);
|
|
418
428
|
const body = {
|
|
419
429
|
...args,
|
|
420
430
|
stream: true,
|
|
421
431
|
stream_options: this.config.includeUsage ? { include_usage: true } : void 0
|
|
422
432
|
};
|
|
423
|
-
const { responseHeaders, value: response } = await
|
|
433
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
424
434
|
url: `${this.config.baseURL}/chat/completions`,
|
|
425
|
-
headers: (
|
|
435
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
426
436
|
body,
|
|
427
437
|
failedResponseHandler: alibabaFailedResponseHandler,
|
|
428
|
-
successfulResponseHandler:
|
|
438
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
429
439
|
alibabaChatChunkSchema
|
|
430
440
|
),
|
|
431
441
|
abortSignal: options.abortSignal,
|
|
@@ -447,7 +457,7 @@ var AlibabaLanguageModel = class {
|
|
|
447
457
|
controller.enqueue({ type: "stream-start", warnings });
|
|
448
458
|
},
|
|
449
459
|
transform(chunk, controller) {
|
|
450
|
-
var
|
|
460
|
+
var _a2, _b2, _c, _d;
|
|
451
461
|
if (options.includeRawChunks) {
|
|
452
462
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
453
463
|
}
|
|
@@ -460,7 +470,7 @@ var AlibabaLanguageModel = class {
|
|
|
460
470
|
isFirstChunk = false;
|
|
461
471
|
controller.enqueue({
|
|
462
472
|
type: "response-metadata",
|
|
463
|
-
...
|
|
473
|
+
...getResponseMetadata(value)
|
|
464
474
|
});
|
|
465
475
|
}
|
|
466
476
|
if (value.usage != null) {
|
|
@@ -477,7 +487,7 @@ var AlibabaLanguageModel = class {
|
|
|
477
487
|
controller.enqueue({ type: "text-end", id: "0" });
|
|
478
488
|
activeText = false;
|
|
479
489
|
}
|
|
480
|
-
activeReasoningId =
|
|
490
|
+
activeReasoningId = generateId();
|
|
481
491
|
controller.enqueue({
|
|
482
492
|
type: "reasoning-start",
|
|
483
493
|
id: activeReasoningId
|
|
@@ -520,16 +530,16 @@ var AlibabaLanguageModel = class {
|
|
|
520
530
|
activeText = false;
|
|
521
531
|
}
|
|
522
532
|
for (const toolCallDelta of delta.tool_calls) {
|
|
523
|
-
const index = (
|
|
533
|
+
const index = (_a2 = toolCallDelta.index) != null ? _a2 : toolCalls.length;
|
|
524
534
|
if (toolCalls[index] == null) {
|
|
525
535
|
if (toolCallDelta.id == null) {
|
|
526
|
-
throw new
|
|
536
|
+
throw new InvalidResponseDataError({
|
|
527
537
|
data: toolCallDelta,
|
|
528
538
|
message: `Expected 'id' to be a string.`
|
|
529
539
|
});
|
|
530
540
|
}
|
|
531
|
-
if (((
|
|
532
|
-
throw new
|
|
541
|
+
if (((_b2 = toolCallDelta.function) == null ? void 0 : _b2.name) == null) {
|
|
542
|
+
throw new InvalidResponseDataError({
|
|
533
543
|
data: toolCallDelta,
|
|
534
544
|
message: `Expected 'function.name' to be a string.`
|
|
535
545
|
});
|
|
@@ -556,7 +566,7 @@ var AlibabaLanguageModel = class {
|
|
|
556
566
|
delta: toolCall2.function.arguments
|
|
557
567
|
});
|
|
558
568
|
}
|
|
559
|
-
if (
|
|
569
|
+
if (isParsableJson(toolCall2.function.arguments)) {
|
|
560
570
|
controller.enqueue({
|
|
561
571
|
type: "tool-input-end",
|
|
562
572
|
id: toolCall2.id
|
|
@@ -583,7 +593,7 @@ var AlibabaLanguageModel = class {
|
|
|
583
593
|
delta: toolCallDelta.function.arguments
|
|
584
594
|
});
|
|
585
595
|
}
|
|
586
|
-
if (
|
|
596
|
+
if (isParsableJson(toolCall.function.arguments)) {
|
|
587
597
|
controller.enqueue({
|
|
588
598
|
type: "tool-input-end",
|
|
589
599
|
id: toolCall.id
|
|
@@ -600,7 +610,7 @@ var AlibabaLanguageModel = class {
|
|
|
600
610
|
}
|
|
601
611
|
if (choice.finish_reason != null) {
|
|
602
612
|
finishReason = {
|
|
603
|
-
unified:
|
|
613
|
+
unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
|
|
604
614
|
raw: choice.finish_reason
|
|
605
615
|
};
|
|
606
616
|
}
|
|
@@ -639,13 +649,13 @@ function resolveAlibabaThinking({
|
|
|
639
649
|
...alibabaOptions.thinkingBudget != null ? { thinking_budget: alibabaOptions.thinkingBudget } : {}
|
|
640
650
|
};
|
|
641
651
|
}
|
|
642
|
-
if (!
|
|
652
|
+
if (!isCustomReasoning(reasoning)) {
|
|
643
653
|
return {};
|
|
644
654
|
}
|
|
645
655
|
if (reasoning === "none") {
|
|
646
656
|
return { enable_thinking: false };
|
|
647
657
|
}
|
|
648
|
-
const thinkingBudget =
|
|
658
|
+
const thinkingBudget = mapReasoningToProviderBudget({
|
|
649
659
|
reasoning,
|
|
650
660
|
maxOutputTokens: 16384,
|
|
651
661
|
maxReasoningBudget: 16384,
|
|
@@ -656,72 +666,72 @@ function resolveAlibabaThinking({
|
|
|
656
666
|
...thinkingBudget != null ? { thinking_budget: thinkingBudget } : {}
|
|
657
667
|
};
|
|
658
668
|
}
|
|
659
|
-
var alibabaUsageSchema =
|
|
660
|
-
prompt_tokens:
|
|
661
|
-
completion_tokens:
|
|
662
|
-
total_tokens:
|
|
663
|
-
prompt_tokens_details:
|
|
664
|
-
cached_tokens:
|
|
665
|
-
cache_creation_input_tokens:
|
|
669
|
+
var alibabaUsageSchema = z2.object({
|
|
670
|
+
prompt_tokens: z2.number(),
|
|
671
|
+
completion_tokens: z2.number(),
|
|
672
|
+
total_tokens: z2.number(),
|
|
673
|
+
prompt_tokens_details: z2.object({
|
|
674
|
+
cached_tokens: z2.number().nullish(),
|
|
675
|
+
cache_creation_input_tokens: z2.number().nullish()
|
|
666
676
|
}).nullish(),
|
|
667
|
-
completion_tokens_details:
|
|
668
|
-
reasoning_tokens:
|
|
677
|
+
completion_tokens_details: z2.object({
|
|
678
|
+
reasoning_tokens: z2.number().nullish()
|
|
669
679
|
}).nullish()
|
|
670
680
|
});
|
|
671
|
-
var alibabaChatResponseSchema =
|
|
672
|
-
id:
|
|
673
|
-
created:
|
|
674
|
-
model:
|
|
675
|
-
choices:
|
|
676
|
-
|
|
677
|
-
message:
|
|
678
|
-
role:
|
|
679
|
-
content:
|
|
680
|
-
reasoning_content:
|
|
681
|
+
var alibabaChatResponseSchema = z2.object({
|
|
682
|
+
id: z2.string().nullish(),
|
|
683
|
+
created: z2.number().nullish(),
|
|
684
|
+
model: z2.string().nullish(),
|
|
685
|
+
choices: z2.array(
|
|
686
|
+
z2.object({
|
|
687
|
+
message: z2.object({
|
|
688
|
+
role: z2.literal("assistant").nullish(),
|
|
689
|
+
content: z2.string().nullish(),
|
|
690
|
+
reasoning_content: z2.string().nullish(),
|
|
681
691
|
// Alibaba thinking mode
|
|
682
|
-
tool_calls:
|
|
683
|
-
|
|
684
|
-
id:
|
|
685
|
-
type:
|
|
686
|
-
function:
|
|
687
|
-
name:
|
|
688
|
-
arguments:
|
|
692
|
+
tool_calls: z2.array(
|
|
693
|
+
z2.object({
|
|
694
|
+
id: z2.string(),
|
|
695
|
+
type: z2.literal("function"),
|
|
696
|
+
function: z2.object({
|
|
697
|
+
name: z2.string(),
|
|
698
|
+
arguments: z2.string()
|
|
689
699
|
})
|
|
690
700
|
})
|
|
691
701
|
).nullish()
|
|
692
702
|
}),
|
|
693
|
-
finish_reason:
|
|
694
|
-
index:
|
|
703
|
+
finish_reason: z2.string().nullish(),
|
|
704
|
+
index: z2.number()
|
|
695
705
|
})
|
|
696
706
|
),
|
|
697
707
|
usage: alibabaUsageSchema.nullish()
|
|
698
708
|
});
|
|
699
|
-
var alibabaChatChunkSchema =
|
|
700
|
-
id:
|
|
701
|
-
created:
|
|
702
|
-
model:
|
|
703
|
-
choices:
|
|
704
|
-
|
|
705
|
-
delta:
|
|
706
|
-
role:
|
|
707
|
-
content:
|
|
708
|
-
reasoning_content:
|
|
709
|
+
var alibabaChatChunkSchema = z2.object({
|
|
710
|
+
id: z2.string().nullish(),
|
|
711
|
+
created: z2.number().nullish(),
|
|
712
|
+
model: z2.string().nullish(),
|
|
713
|
+
choices: z2.array(
|
|
714
|
+
z2.object({
|
|
715
|
+
delta: z2.object({
|
|
716
|
+
role: z2.enum(["assistant"]).nullish(),
|
|
717
|
+
content: z2.string().nullish(),
|
|
718
|
+
reasoning_content: z2.string().nullish(),
|
|
709
719
|
// Alibaba thinking mode delta
|
|
710
|
-
tool_calls:
|
|
711
|
-
|
|
712
|
-
index:
|
|
720
|
+
tool_calls: z2.array(
|
|
721
|
+
z2.object({
|
|
722
|
+
index: z2.number().nullish(),
|
|
713
723
|
// Index for accumulating tool calls
|
|
714
|
-
id:
|
|
715
|
-
type:
|
|
716
|
-
function:
|
|
717
|
-
name:
|
|
718
|
-
arguments:
|
|
724
|
+
id: z2.string().nullish(),
|
|
725
|
+
type: z2.literal("function").nullish(),
|
|
726
|
+
function: z2.object({
|
|
727
|
+
name: z2.string().nullish(),
|
|
728
|
+
arguments: z2.string().nullish()
|
|
719
729
|
}).nullish()
|
|
720
730
|
})
|
|
721
731
|
).nullish()
|
|
722
732
|
}),
|
|
723
|
-
finish_reason:
|
|
724
|
-
index:
|
|
733
|
+
finish_reason: z2.string().nullish(),
|
|
734
|
+
index: z2.number()
|
|
725
735
|
})
|
|
726
736
|
),
|
|
727
737
|
usage: alibabaUsageSchema.nullish()
|
|
@@ -729,60 +739,74 @@ var alibabaChatChunkSchema = import_v42.z.object({
|
|
|
729
739
|
});
|
|
730
740
|
|
|
731
741
|
// src/alibaba-video-model.ts
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
742
|
+
import {
|
|
743
|
+
AISDKError
|
|
744
|
+
} from "@ai-sdk/provider";
|
|
745
|
+
import {
|
|
746
|
+
combineHeaders as combineHeaders2,
|
|
747
|
+
convertUint8ArrayToBase64,
|
|
748
|
+
createJsonErrorResponseHandler,
|
|
749
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
750
|
+
delay,
|
|
751
|
+
getFromApi,
|
|
752
|
+
lazySchema,
|
|
753
|
+
parseProviderOptions as parseProviderOptions2,
|
|
754
|
+
postJsonToApi as postJsonToApi2,
|
|
755
|
+
resolve,
|
|
756
|
+
zodSchema
|
|
757
|
+
} from "@ai-sdk/provider-utils";
|
|
758
|
+
import { z as z3 } from "zod/v4";
|
|
759
|
+
var alibabaVideoModelOptionsSchema = lazySchema(
|
|
760
|
+
() => zodSchema(
|
|
761
|
+
z3.object({
|
|
762
|
+
negativePrompt: z3.string().nullish(),
|
|
763
|
+
audioUrl: z3.string().nullish(),
|
|
764
|
+
promptExtend: z3.boolean().nullish(),
|
|
765
|
+
shotType: z3.enum(["single", "multi"]).nullish(),
|
|
766
|
+
watermark: z3.boolean().nullish(),
|
|
767
|
+
audio: z3.boolean().nullish(),
|
|
768
|
+
referenceUrls: z3.array(z3.string()).nullish(),
|
|
769
|
+
pollIntervalMs: z3.number().positive().nullish(),
|
|
770
|
+
pollTimeoutMs: z3.number().positive().nullish()
|
|
747
771
|
}).passthrough()
|
|
748
772
|
)
|
|
749
773
|
);
|
|
750
|
-
var alibabaVideoErrorSchema =
|
|
751
|
-
code:
|
|
752
|
-
message:
|
|
753
|
-
request_id:
|
|
774
|
+
var alibabaVideoErrorSchema = z3.object({
|
|
775
|
+
code: z3.string().nullish(),
|
|
776
|
+
message: z3.string(),
|
|
777
|
+
request_id: z3.string().nullish()
|
|
754
778
|
});
|
|
755
|
-
var alibabaVideoFailedResponseHandler =
|
|
779
|
+
var alibabaVideoFailedResponseHandler = createJsonErrorResponseHandler({
|
|
756
780
|
errorSchema: alibabaVideoErrorSchema,
|
|
757
781
|
errorToMessage: (data) => data.message
|
|
758
782
|
});
|
|
759
|
-
var alibabaVideoCreateTaskSchema =
|
|
760
|
-
output:
|
|
761
|
-
task_status:
|
|
762
|
-
task_id:
|
|
783
|
+
var alibabaVideoCreateTaskSchema = z3.object({
|
|
784
|
+
output: z3.object({
|
|
785
|
+
task_status: z3.string(),
|
|
786
|
+
task_id: z3.string()
|
|
763
787
|
}).nullish(),
|
|
764
|
-
request_id:
|
|
788
|
+
request_id: z3.string().nullish()
|
|
765
789
|
});
|
|
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:
|
|
790
|
+
var alibabaVideoTaskStatusSchema = z3.object({
|
|
791
|
+
output: z3.object({
|
|
792
|
+
task_id: z3.string(),
|
|
793
|
+
task_status: z3.string(),
|
|
794
|
+
video_url: z3.string().nullish(),
|
|
795
|
+
submit_time: z3.string().nullish(),
|
|
796
|
+
scheduled_time: z3.string().nullish(),
|
|
797
|
+
end_time: z3.string().nullish(),
|
|
798
|
+
orig_prompt: z3.string().nullish(),
|
|
799
|
+
actual_prompt: z3.string().nullish(),
|
|
800
|
+
code: z3.string().nullish(),
|
|
801
|
+
message: z3.string().nullish()
|
|
778
802
|
}).nullish(),
|
|
779
|
-
usage:
|
|
780
|
-
duration:
|
|
781
|
-
output_video_duration:
|
|
782
|
-
SR:
|
|
783
|
-
size:
|
|
803
|
+
usage: z3.object({
|
|
804
|
+
duration: z3.number().nullish(),
|
|
805
|
+
output_video_duration: z3.number().nullish(),
|
|
806
|
+
SR: z3.number().nullish(),
|
|
807
|
+
size: z3.string().nullish()
|
|
784
808
|
}).nullish(),
|
|
785
|
-
request_id:
|
|
809
|
+
request_id: z3.string().nullish()
|
|
786
810
|
});
|
|
787
811
|
function detectMode(modelId) {
|
|
788
812
|
if (modelId.includes("-i2v")) return "i2v";
|
|
@@ -804,7 +828,7 @@ var AlibabaVideoModel = class {
|
|
|
804
828
|
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
829
|
const warnings = [];
|
|
806
830
|
const mode = detectMode(this.modelId);
|
|
807
|
-
const alibabaOptions = await (
|
|
831
|
+
const alibabaOptions = await parseProviderOptions2({
|
|
808
832
|
provider: "alibaba",
|
|
809
833
|
providerOptions: options.providerOptions,
|
|
810
834
|
schema: alibabaVideoModelOptionsSchema
|
|
@@ -823,7 +847,7 @@ var AlibabaVideoModel = class {
|
|
|
823
847
|
if (options.image.type === "url") {
|
|
824
848
|
input.img_url = options.image.url;
|
|
825
849
|
} else {
|
|
826
|
-
const base64Data = typeof options.image.data === "string" ? options.image.data :
|
|
850
|
+
const base64Data = typeof options.image.data === "string" ? options.image.data : convertUint8ArrayToBase64(options.image.data);
|
|
827
851
|
input.img_url = base64Data;
|
|
828
852
|
}
|
|
829
853
|
}
|
|
@@ -892,10 +916,10 @@ var AlibabaVideoModel = class {
|
|
|
892
916
|
details: "Alibaba video models only support generating 1 video per call."
|
|
893
917
|
});
|
|
894
918
|
}
|
|
895
|
-
const { value: createResponse } = await (
|
|
919
|
+
const { value: createResponse } = await postJsonToApi2({
|
|
896
920
|
url: `${this.config.baseURL}/api/v1/services/aigc/video-generation/video-synthesis`,
|
|
897
|
-
headers: (
|
|
898
|
-
await
|
|
921
|
+
headers: combineHeaders2(
|
|
922
|
+
await resolve(this.config.headers),
|
|
899
923
|
options.headers,
|
|
900
924
|
{
|
|
901
925
|
"X-DashScope-Async": "enable"
|
|
@@ -906,7 +930,7 @@ var AlibabaVideoModel = class {
|
|
|
906
930
|
input,
|
|
907
931
|
parameters
|
|
908
932
|
},
|
|
909
|
-
successfulResponseHandler: (
|
|
933
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
910
934
|
alibabaVideoCreateTaskSchema
|
|
911
935
|
),
|
|
912
936
|
failedResponseHandler: alibabaVideoFailedResponseHandler,
|
|
@@ -915,7 +939,7 @@ var AlibabaVideoModel = class {
|
|
|
915
939
|
});
|
|
916
940
|
const taskId = (_d = createResponse.output) == null ? void 0 : _d.task_id;
|
|
917
941
|
if (!taskId) {
|
|
918
|
-
throw new
|
|
942
|
+
throw new AISDKError({
|
|
919
943
|
name: "ALIBABA_VIDEO_GENERATION_ERROR",
|
|
920
944
|
message: `No task_id returned from Alibaba API. Response: ${JSON.stringify(createResponse)}`
|
|
921
945
|
});
|
|
@@ -926,20 +950,20 @@ var AlibabaVideoModel = class {
|
|
|
926
950
|
let finalResponse;
|
|
927
951
|
let responseHeaders;
|
|
928
952
|
while (true) {
|
|
929
|
-
await
|
|
953
|
+
await delay(pollIntervalMs, { abortSignal: options.abortSignal });
|
|
930
954
|
if (Date.now() - startTime > pollTimeoutMs) {
|
|
931
|
-
throw new
|
|
955
|
+
throw new AISDKError({
|
|
932
956
|
name: "ALIBABA_VIDEO_GENERATION_TIMEOUT",
|
|
933
957
|
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
934
958
|
});
|
|
935
959
|
}
|
|
936
|
-
const { value: statusResponse, responseHeaders: pollHeaders } = await
|
|
960
|
+
const { value: statusResponse, responseHeaders: pollHeaders } = await getFromApi({
|
|
937
961
|
url: `${this.config.baseURL}/api/v1/tasks/${taskId}`,
|
|
938
|
-
headers: (
|
|
939
|
-
await
|
|
962
|
+
headers: combineHeaders2(
|
|
963
|
+
await resolve(this.config.headers),
|
|
940
964
|
options.headers
|
|
941
965
|
),
|
|
942
|
-
successfulResponseHandler: (
|
|
966
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
943
967
|
alibabaVideoTaskStatusSchema
|
|
944
968
|
),
|
|
945
969
|
failedResponseHandler: alibabaVideoFailedResponseHandler,
|
|
@@ -953,7 +977,7 @@ var AlibabaVideoModel = class {
|
|
|
953
977
|
break;
|
|
954
978
|
}
|
|
955
979
|
if (taskStatus === "FAILED" || taskStatus === "CANCELED") {
|
|
956
|
-
throw new
|
|
980
|
+
throw new AISDKError({
|
|
957
981
|
name: "ALIBABA_VIDEO_GENERATION_FAILED",
|
|
958
982
|
message: `Video generation ${taskStatus.toLowerCase()}. Task ID: ${taskId}. ${(_i = (_h = statusResponse.output) == null ? void 0 : _h.message) != null ? _i : ""}`
|
|
959
983
|
});
|
|
@@ -961,7 +985,7 @@ var AlibabaVideoModel = class {
|
|
|
961
985
|
}
|
|
962
986
|
const videoUrl = (_j = finalResponse == null ? void 0 : finalResponse.output) == null ? void 0 : _j.video_url;
|
|
963
987
|
if (!videoUrl) {
|
|
964
|
-
throw new
|
|
988
|
+
throw new AISDKError({
|
|
965
989
|
name: "ALIBABA_VIDEO_GENERATION_ERROR",
|
|
966
990
|
message: `No video URL in response. Task ID: ${taskId}`
|
|
967
991
|
});
|
|
@@ -1000,27 +1024,27 @@ var AlibabaVideoModel = class {
|
|
|
1000
1024
|
};
|
|
1001
1025
|
|
|
1002
1026
|
// src/version.ts
|
|
1003
|
-
var VERSION = "2.0.0-beta.
|
|
1027
|
+
var VERSION = "2.0.0-beta.27";
|
|
1004
1028
|
|
|
1005
1029
|
// src/alibaba-provider.ts
|
|
1006
|
-
var alibabaErrorDataSchema =
|
|
1007
|
-
error:
|
|
1008
|
-
message:
|
|
1009
|
-
code:
|
|
1010
|
-
type:
|
|
1030
|
+
var alibabaErrorDataSchema = z4.object({
|
|
1031
|
+
error: z4.object({
|
|
1032
|
+
message: z4.string(),
|
|
1033
|
+
code: z4.string().nullish(),
|
|
1034
|
+
type: z4.string().nullish()
|
|
1011
1035
|
})
|
|
1012
1036
|
});
|
|
1013
|
-
var alibabaFailedResponseHandler = (
|
|
1037
|
+
var alibabaFailedResponseHandler = createJsonErrorResponseHandler2({
|
|
1014
1038
|
errorSchema: alibabaErrorDataSchema,
|
|
1015
1039
|
errorToMessage: (data) => data.error.message
|
|
1016
1040
|
});
|
|
1017
1041
|
function createAlibaba(options = {}) {
|
|
1018
1042
|
var _a, _b;
|
|
1019
|
-
const baseURL = (_a =
|
|
1020
|
-
const videoBaseURL = (_b =
|
|
1021
|
-
const getHeaders = () =>
|
|
1043
|
+
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://dashscope-intl.aliyuncs.com/compatible-mode/v1";
|
|
1044
|
+
const videoBaseURL = (_b = withoutTrailingSlash(options.videoBaseURL)) != null ? _b : "https://dashscope-intl.aliyuncs.com";
|
|
1045
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
1022
1046
|
{
|
|
1023
|
-
Authorization: `Bearer ${
|
|
1047
|
+
Authorization: `Bearer ${loadApiKey({
|
|
1024
1048
|
apiKey: options.apiKey,
|
|
1025
1049
|
environmentVariableName: "ALIBABA_API_KEY",
|
|
1026
1050
|
description: "Alibaba Cloud (DashScope)"
|
|
@@ -1059,18 +1083,17 @@ function createAlibaba(options = {}) {
|
|
|
1059
1083
|
provider.video = createVideoModel;
|
|
1060
1084
|
provider.videoModel = createVideoModel;
|
|
1061
1085
|
provider.imageModel = (modelId) => {
|
|
1062
|
-
throw new
|
|
1086
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
1063
1087
|
};
|
|
1064
1088
|
provider.embeddingModel = (modelId) => {
|
|
1065
|
-
throw new
|
|
1089
|
+
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
1066
1090
|
};
|
|
1067
1091
|
return provider;
|
|
1068
1092
|
}
|
|
1069
1093
|
var alibaba = createAlibaba();
|
|
1070
|
-
|
|
1071
|
-
0 && (module.exports = {
|
|
1094
|
+
export {
|
|
1072
1095
|
VERSION,
|
|
1073
1096
|
alibaba,
|
|
1074
1097
|
createAlibaba
|
|
1075
|
-
}
|
|
1098
|
+
};
|
|
1076
1099
|
//# sourceMappingURL=index.js.map
|