@ai-sdk/alibaba 2.0.0-beta.9 → 2.0.0-canary.39
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 +291 -0
- package/README.md +2 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +299 -291
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
- package/src/{alibaba-chat-options.ts → alibaba-chat-language-model-options.ts} +3 -3
- package/src/alibaba-chat-language-model.ts +97 -133
- package/src/alibaba-config.ts +1 -1
- package/src/alibaba-error.ts +17 -0
- package/src/alibaba-provider.ts +7 -21
- package/src/alibaba-video-model-options.ts +46 -0
- package/src/alibaba-video-model.ts +6 -48
- package/src/convert-to-alibaba-chat-messages.ts +49 -33
- package/src/index.ts +7 -5
- package/dist/index.d.mts +0 -119
- package/dist/index.mjs +0 -1048
- package/dist/index.mjs.map +0 -1
|
@@ -3,34 +3,39 @@ import {
|
|
|
3
3
|
mapOpenAICompatibleFinishReason,
|
|
4
4
|
prepareTools,
|
|
5
5
|
} from '@ai-sdk/openai-compatible/internal';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type SharedV4Warning,
|
|
6
|
+
import type {
|
|
7
|
+
LanguageModelV4,
|
|
8
|
+
LanguageModelV4CallOptions,
|
|
9
|
+
LanguageModelV4Content,
|
|
10
|
+
LanguageModelV4FinishReason,
|
|
11
|
+
LanguageModelV4GenerateResult,
|
|
12
|
+
LanguageModelV4StreamPart,
|
|
13
|
+
LanguageModelV4StreamResult,
|
|
14
|
+
SharedV4Warning,
|
|
16
15
|
} from '@ai-sdk/provider';
|
|
17
16
|
import {
|
|
18
17
|
combineHeaders,
|
|
19
18
|
createEventSourceResponseHandler,
|
|
20
19
|
createJsonResponseHandler,
|
|
21
20
|
generateId,
|
|
22
|
-
|
|
21
|
+
isCustomReasoning,
|
|
22
|
+
mapReasoningToProviderBudget,
|
|
23
23
|
parseProviderOptions,
|
|
24
24
|
postJsonToApi,
|
|
25
|
+
serializeModelOptions,
|
|
26
|
+
StreamingToolCallTracker,
|
|
27
|
+
WORKFLOW_SERIALIZE,
|
|
28
|
+
WORKFLOW_DESERIALIZE,
|
|
29
|
+
type InferSchema,
|
|
25
30
|
type ParseResult,
|
|
26
31
|
} from '@ai-sdk/provider-utils';
|
|
27
32
|
import { z } from 'zod/v4';
|
|
28
33
|
import {
|
|
29
|
-
|
|
34
|
+
alibabaLanguageModelChatOptions,
|
|
30
35
|
type AlibabaChatModelId,
|
|
31
|
-
} from './alibaba-chat-options';
|
|
36
|
+
} from './alibaba-chat-language-model-options';
|
|
32
37
|
import type { AlibabaConfig } from './alibaba-config';
|
|
33
|
-
import { alibabaFailedResponseHandler } from './alibaba-
|
|
38
|
+
import { alibabaFailedResponseHandler } from './alibaba-error';
|
|
34
39
|
import { convertAlibabaUsage } from './convert-alibaba-usage';
|
|
35
40
|
import { convertToAlibabaChatMessages } from './convert-to-alibaba-chat-messages';
|
|
36
41
|
import { CacheControlValidator } from './get-cache-control';
|
|
@@ -44,12 +49,26 @@ import { CacheControlValidator } from './get-cache-control';
|
|
|
44
49
|
* - Thinking budget control (thinking_budget)
|
|
45
50
|
* - Prompt caching (cached_tokens tracking)
|
|
46
51
|
*/
|
|
47
|
-
export class
|
|
52
|
+
export class AlibabaChatLanguageModel implements LanguageModelV4 {
|
|
48
53
|
readonly specificationVersion = 'v4';
|
|
49
54
|
readonly modelId: AlibabaChatModelId;
|
|
50
55
|
|
|
51
56
|
private readonly config: AlibabaConfig;
|
|
52
57
|
|
|
58
|
+
static [WORKFLOW_SERIALIZE](model: AlibabaChatLanguageModel) {
|
|
59
|
+
return serializeModelOptions({
|
|
60
|
+
modelId: model.modelId,
|
|
61
|
+
config: model.config,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static [WORKFLOW_DESERIALIZE](options: {
|
|
66
|
+
modelId: AlibabaChatModelId;
|
|
67
|
+
config: AlibabaConfig;
|
|
68
|
+
}) {
|
|
69
|
+
return new AlibabaChatLanguageModel(options.modelId, options.config);
|
|
70
|
+
}
|
|
71
|
+
|
|
53
72
|
constructor(modelId: AlibabaChatModelId, config: AlibabaConfig) {
|
|
54
73
|
this.modelId = modelId;
|
|
55
74
|
this.config = config;
|
|
@@ -78,6 +97,7 @@ export class AlibabaLanguageModel implements LanguageModelV4 {
|
|
|
78
97
|
stopSequences,
|
|
79
98
|
responseFormat,
|
|
80
99
|
seed,
|
|
100
|
+
reasoning,
|
|
81
101
|
providerOptions,
|
|
82
102
|
tools,
|
|
83
103
|
toolChoice,
|
|
@@ -89,7 +109,7 @@ export class AlibabaLanguageModel implements LanguageModelV4 {
|
|
|
89
109
|
const alibabaOptions = await parseProviderOptions({
|
|
90
110
|
provider: 'alibaba',
|
|
91
111
|
providerOptions,
|
|
92
|
-
schema:
|
|
112
|
+
schema: alibabaLanguageModelChatOptions,
|
|
93
113
|
});
|
|
94
114
|
|
|
95
115
|
// Warn about unsupported features
|
|
@@ -121,13 +141,11 @@ export class AlibabaLanguageModel implements LanguageModelV4 {
|
|
|
121
141
|
: { type: 'json_object' }
|
|
122
142
|
: undefined,
|
|
123
143
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
? { thinking_budget: alibabaOptions.thinkingBudget }
|
|
130
|
-
: {}),
|
|
144
|
+
...resolveAlibabaThinking({
|
|
145
|
+
reasoning,
|
|
146
|
+
alibabaOptions,
|
|
147
|
+
warnings,
|
|
148
|
+
}),
|
|
131
149
|
|
|
132
150
|
// Convert messages with cache control support
|
|
133
151
|
messages: convertToAlibabaChatMessages({
|
|
@@ -170,7 +188,7 @@ export class AlibabaLanguageModel implements LanguageModelV4 {
|
|
|
170
188
|
rawValue: rawResponse,
|
|
171
189
|
} = await postJsonToApi({
|
|
172
190
|
url: `${this.config.baseURL}/chat/completions`,
|
|
173
|
-
headers: combineHeaders(this.config.headers(), options.headers),
|
|
191
|
+
headers: combineHeaders(this.config.headers?.(), options.headers),
|
|
174
192
|
body: args,
|
|
175
193
|
failedResponseHandler: alibabaFailedResponseHandler,
|
|
176
194
|
successfulResponseHandler: createJsonResponseHandler(
|
|
@@ -203,7 +221,7 @@ export class AlibabaLanguageModel implements LanguageModelV4 {
|
|
|
203
221
|
for (const toolCall of choice.message.tool_calls) {
|
|
204
222
|
content.push({
|
|
205
223
|
type: 'tool-call',
|
|
206
|
-
toolCallId: toolCall.id,
|
|
224
|
+
toolCallId: toolCall.id ?? generateId(),
|
|
207
225
|
toolName: toolCall.function.name,
|
|
208
226
|
input: toolCall.function.arguments!,
|
|
209
227
|
});
|
|
@@ -241,7 +259,7 @@ export class AlibabaLanguageModel implements LanguageModelV4 {
|
|
|
241
259
|
|
|
242
260
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
243
261
|
url: `${this.config.baseURL}/chat/completions`,
|
|
244
|
-
headers: combineHeaders(this.config.headers(), options.headers),
|
|
262
|
+
headers: combineHeaders(this.config.headers?.(), options.headers),
|
|
245
263
|
body,
|
|
246
264
|
failedResponseHandler: alibabaFailedResponseHandler,
|
|
247
265
|
successfulResponseHandler: createEventSourceResponseHandler(
|
|
@@ -262,13 +280,7 @@ export class AlibabaLanguageModel implements LanguageModelV4 {
|
|
|
262
280
|
let activeText = false;
|
|
263
281
|
let activeReasoningId: string | null = null;
|
|
264
282
|
|
|
265
|
-
|
|
266
|
-
const toolCalls: Array<{
|
|
267
|
-
id: string;
|
|
268
|
-
type: 'function';
|
|
269
|
-
function: { name: string; arguments: string };
|
|
270
|
-
hasFinished: boolean;
|
|
271
|
-
}> = [];
|
|
283
|
+
let toolCallTracker: StreamingToolCallTracker;
|
|
272
284
|
|
|
273
285
|
return {
|
|
274
286
|
stream: response.pipeThrough(
|
|
@@ -277,6 +289,9 @@ export class AlibabaLanguageModel implements LanguageModelV4 {
|
|
|
277
289
|
LanguageModelV4StreamPart
|
|
278
290
|
>({
|
|
279
291
|
start(controller) {
|
|
292
|
+
toolCallTracker = new StreamingToolCallTracker(controller, {
|
|
293
|
+
generateId,
|
|
294
|
+
});
|
|
280
295
|
controller.enqueue({ type: 'stream-start', warnings });
|
|
281
296
|
},
|
|
282
297
|
|
|
@@ -381,106 +396,7 @@ export class AlibabaLanguageModel implements LanguageModelV4 {
|
|
|
381
396
|
}
|
|
382
397
|
|
|
383
398
|
for (const toolCallDelta of delta.tool_calls) {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
// New tool call - first chunk with id and name
|
|
387
|
-
if (toolCalls[index] == null) {
|
|
388
|
-
if (toolCallDelta.id == null) {
|
|
389
|
-
throw new InvalidResponseDataError({
|
|
390
|
-
data: toolCallDelta,
|
|
391
|
-
message: `Expected 'id' to be a string.`,
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
if (toolCallDelta.function?.name == null) {
|
|
396
|
-
throw new InvalidResponseDataError({
|
|
397
|
-
data: toolCallDelta,
|
|
398
|
-
message: `Expected 'function.name' to be a string.`,
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
controller.enqueue({
|
|
403
|
-
type: 'tool-input-start',
|
|
404
|
-
id: toolCallDelta.id,
|
|
405
|
-
toolName: toolCallDelta.function.name,
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
toolCalls[index] = {
|
|
409
|
-
id: toolCallDelta.id,
|
|
410
|
-
type: 'function',
|
|
411
|
-
function: {
|
|
412
|
-
name: toolCallDelta.function.name,
|
|
413
|
-
arguments: toolCallDelta.function.arguments ?? '',
|
|
414
|
-
},
|
|
415
|
-
hasFinished: false,
|
|
416
|
-
};
|
|
417
|
-
|
|
418
|
-
const toolCall = toolCalls[index];
|
|
419
|
-
|
|
420
|
-
// Send initial delta if arguments started
|
|
421
|
-
if (toolCall.function.arguments.length > 0) {
|
|
422
|
-
controller.enqueue({
|
|
423
|
-
type: 'tool-input-delta',
|
|
424
|
-
id: toolCall.id,
|
|
425
|
-
delta: toolCall.function.arguments,
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
// Check if already complete (some providers send full tool call at once)
|
|
430
|
-
if (isParsableJson(toolCall.function.arguments)) {
|
|
431
|
-
controller.enqueue({
|
|
432
|
-
type: 'tool-input-end',
|
|
433
|
-
id: toolCall.id,
|
|
434
|
-
});
|
|
435
|
-
|
|
436
|
-
controller.enqueue({
|
|
437
|
-
type: 'tool-call',
|
|
438
|
-
toolCallId: toolCall.id,
|
|
439
|
-
toolName: toolCall.function.name,
|
|
440
|
-
input: toolCall.function.arguments,
|
|
441
|
-
});
|
|
442
|
-
|
|
443
|
-
toolCall.hasFinished = true;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
continue;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
// Existing tool call - accumulate arguments
|
|
450
|
-
const toolCall = toolCalls[index];
|
|
451
|
-
|
|
452
|
-
if (toolCall.hasFinished) {
|
|
453
|
-
continue;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
// Append arguments if not null (skip arguments: null chunks)
|
|
457
|
-
if (toolCallDelta.function?.arguments != null) {
|
|
458
|
-
toolCall.function.arguments +=
|
|
459
|
-
toolCallDelta.function.arguments;
|
|
460
|
-
|
|
461
|
-
controller.enqueue({
|
|
462
|
-
type: 'tool-input-delta',
|
|
463
|
-
id: toolCall.id,
|
|
464
|
-
delta: toolCallDelta.function.arguments,
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
// Check if tool call is now complete
|
|
469
|
-
if (isParsableJson(toolCall.function.arguments)) {
|
|
470
|
-
controller.enqueue({
|
|
471
|
-
type: 'tool-input-end',
|
|
472
|
-
id: toolCall.id,
|
|
473
|
-
});
|
|
474
|
-
|
|
475
|
-
controller.enqueue({
|
|
476
|
-
type: 'tool-call',
|
|
477
|
-
toolCallId: toolCall.id,
|
|
478
|
-
toolName: toolCall.function.name,
|
|
479
|
-
input: toolCall.function.arguments,
|
|
480
|
-
});
|
|
481
|
-
|
|
482
|
-
toolCall.hasFinished = true;
|
|
483
|
-
}
|
|
399
|
+
toolCallTracker.processDelta(toolCallDelta);
|
|
484
400
|
}
|
|
485
401
|
}
|
|
486
402
|
|
|
@@ -505,6 +421,8 @@ export class AlibabaLanguageModel implements LanguageModelV4 {
|
|
|
505
421
|
controller.enqueue({ type: 'text-end', id: '0' });
|
|
506
422
|
}
|
|
507
423
|
|
|
424
|
+
toolCallTracker.flush();
|
|
425
|
+
|
|
508
426
|
controller.enqueue({
|
|
509
427
|
type: 'finish',
|
|
510
428
|
finishReason,
|
|
@@ -519,6 +437,52 @@ export class AlibabaLanguageModel implements LanguageModelV4 {
|
|
|
519
437
|
}
|
|
520
438
|
}
|
|
521
439
|
|
|
440
|
+
function resolveAlibabaThinking({
|
|
441
|
+
reasoning,
|
|
442
|
+
alibabaOptions,
|
|
443
|
+
warnings,
|
|
444
|
+
}: {
|
|
445
|
+
reasoning: LanguageModelV4CallOptions['reasoning'];
|
|
446
|
+
alibabaOptions:
|
|
447
|
+
| InferSchema<typeof alibabaLanguageModelChatOptions>
|
|
448
|
+
| undefined;
|
|
449
|
+
warnings: SharedV4Warning[];
|
|
450
|
+
}): { enable_thinking?: boolean; thinking_budget?: number } {
|
|
451
|
+
if (
|
|
452
|
+
alibabaOptions?.enableThinking != null ||
|
|
453
|
+
alibabaOptions?.thinkingBudget != null
|
|
454
|
+
) {
|
|
455
|
+
return {
|
|
456
|
+
...(alibabaOptions.enableThinking != null
|
|
457
|
+
? { enable_thinking: alibabaOptions.enableThinking }
|
|
458
|
+
: {}),
|
|
459
|
+
...(alibabaOptions.thinkingBudget != null
|
|
460
|
+
? { thinking_budget: alibabaOptions.thinkingBudget }
|
|
461
|
+
: {}),
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
if (!isCustomReasoning(reasoning)) {
|
|
466
|
+
return {};
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
if (reasoning === 'none') {
|
|
470
|
+
return { enable_thinking: false };
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
const thinkingBudget = mapReasoningToProviderBudget({
|
|
474
|
+
reasoning,
|
|
475
|
+
maxOutputTokens: 16384,
|
|
476
|
+
maxReasoningBudget: 16384,
|
|
477
|
+
warnings,
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
return {
|
|
481
|
+
enable_thinking: true,
|
|
482
|
+
...(thinkingBudget != null ? { thinking_budget: thinkingBudget } : {}),
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
|
|
522
486
|
/**
|
|
523
487
|
* Reference for schemas below:
|
|
524
488
|
* https://www.alibabacloud.com/help/en/model-studio/qwen-api-via-openai-chat-completions
|
package/src/alibaba-config.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { FetchFunction } from '@ai-sdk/provider-utils';
|
|
|
3
3
|
export interface AlibabaConfig {
|
|
4
4
|
provider: string;
|
|
5
5
|
baseURL: string;
|
|
6
|
-
headers
|
|
6
|
+
headers?: () => Record<string, string | undefined>;
|
|
7
7
|
fetch?: FetchFunction;
|
|
8
8
|
includeUsage?: boolean;
|
|
9
9
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createJsonErrorResponseHandler } from '@ai-sdk/provider-utils';
|
|
2
|
+
import { z } from 'zod/v4';
|
|
3
|
+
|
|
4
|
+
const alibabaErrorDataSchema = z.object({
|
|
5
|
+
error: z.object({
|
|
6
|
+
message: z.string(),
|
|
7
|
+
code: z.string().nullish(),
|
|
8
|
+
type: z.string().nullish(),
|
|
9
|
+
}),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export type AlibabaErrorData = z.infer<typeof alibabaErrorDataSchema>;
|
|
13
|
+
|
|
14
|
+
export const alibabaFailedResponseHandler = createJsonErrorResponseHandler({
|
|
15
|
+
errorSchema: alibabaErrorDataSchema,
|
|
16
|
+
errorToMessage: data => data.error.message,
|
|
17
|
+
});
|
package/src/alibaba-provider.ts
CHANGED
|
@@ -1,37 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
|
+
NoSuchModelError,
|
|
2
3
|
type Experimental_VideoModelV4,
|
|
3
4
|
type LanguageModelV4,
|
|
4
|
-
NoSuchModelError,
|
|
5
5
|
type ProviderV4,
|
|
6
6
|
} from '@ai-sdk/provider';
|
|
7
7
|
import {
|
|
8
|
-
createJsonErrorResponseHandler,
|
|
9
|
-
type FetchFunction,
|
|
10
8
|
loadApiKey,
|
|
11
9
|
withoutTrailingSlash,
|
|
12
10
|
withUserAgentSuffix,
|
|
11
|
+
type FetchFunction,
|
|
13
12
|
} from '@ai-sdk/provider-utils';
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import type { AlibabaChatModelId } from './alibaba-chat-options';
|
|
13
|
+
import { AlibabaChatLanguageModel } from './alibaba-chat-language-model';
|
|
14
|
+
import type { AlibabaChatModelId } from './alibaba-chat-language-model-options';
|
|
17
15
|
import { AlibabaVideoModel } from './alibaba-video-model';
|
|
18
16
|
import type { AlibabaVideoModelId } from './alibaba-video-settings';
|
|
19
17
|
import { VERSION } from './version';
|
|
20
18
|
|
|
21
|
-
export type AlibabaErrorData
|
|
22
|
-
|
|
23
|
-
const alibabaErrorDataSchema = z.object({
|
|
24
|
-
error: z.object({
|
|
25
|
-
message: z.string(),
|
|
26
|
-
code: z.string().nullish(),
|
|
27
|
-
type: z.string().nullish(),
|
|
28
|
-
}),
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
export const alibabaFailedResponseHandler = createJsonErrorResponseHandler({
|
|
32
|
-
errorSchema: alibabaErrorDataSchema,
|
|
33
|
-
errorToMessage: data => data.error.message,
|
|
34
|
-
});
|
|
19
|
+
export type { AlibabaErrorData } from './alibaba-error';
|
|
20
|
+
export { alibabaFailedResponseHandler } from './alibaba-error';
|
|
35
21
|
|
|
36
22
|
export interface AlibabaProvider extends ProviderV4 {
|
|
37
23
|
(modelId: AlibabaChatModelId): LanguageModelV4;
|
|
@@ -125,7 +111,7 @@ export function createAlibaba(
|
|
|
125
111
|
);
|
|
126
112
|
|
|
127
113
|
const createLanguageModel = (modelId: AlibabaChatModelId) =>
|
|
128
|
-
new
|
|
114
|
+
new AlibabaChatLanguageModel(modelId, {
|
|
129
115
|
provider: 'alibaba.chat',
|
|
130
116
|
baseURL,
|
|
131
117
|
headers: getHeaders,
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { lazySchema, zodSchema } from '@ai-sdk/provider-utils';
|
|
2
|
+
import { z } from 'zod/v4';
|
|
3
|
+
|
|
4
|
+
export type AlibabaVideoModelOptions = {
|
|
5
|
+
/** Negative prompt to specify what to avoid (max 500 chars). */
|
|
6
|
+
negativePrompt?: string | null;
|
|
7
|
+
/** URL to audio file for audio-video sync (WAV/MP3, 3-30s, max 15MB). */
|
|
8
|
+
audioUrl?: string | null;
|
|
9
|
+
/** Enable prompt extension/rewriting for better generation. Defaults to true. */
|
|
10
|
+
promptExtend?: boolean | null;
|
|
11
|
+
/** Shot type: 'single' for single-shot or 'multi' for multi-shot narrative. */
|
|
12
|
+
shotType?: 'single' | 'multi' | null;
|
|
13
|
+
/** Whether to add watermark to generated video. Defaults to false. */
|
|
14
|
+
watermark?: boolean | null;
|
|
15
|
+
/** Enable audio generation (for I2V/R2V models). */
|
|
16
|
+
audio?: boolean | null;
|
|
17
|
+
/**
|
|
18
|
+
* Reference URLs for reference-to-video mode.
|
|
19
|
+
* Array of URLs to images (0-5) and/or videos (0-3), max 5 total.
|
|
20
|
+
* Use character identifiers (character1, character2) in prompts to reference them.
|
|
21
|
+
*/
|
|
22
|
+
referenceUrls?: string[] | null;
|
|
23
|
+
/** Polling interval in milliseconds. Defaults to 5000 (5 seconds). */
|
|
24
|
+
pollIntervalMs?: number | null;
|
|
25
|
+
/** Maximum wait time in milliseconds for video generation. Defaults to 600000 (10 minutes). */
|
|
26
|
+
pollTimeoutMs?: number | null;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const alibabaVideoModelOptionsSchema = lazySchema(() =>
|
|
31
|
+
zodSchema(
|
|
32
|
+
z
|
|
33
|
+
.object({
|
|
34
|
+
negativePrompt: z.string().nullish(),
|
|
35
|
+
audioUrl: z.string().nullish(),
|
|
36
|
+
promptExtend: z.boolean().nullish(),
|
|
37
|
+
shotType: z.enum(['single', 'multi']).nullish(),
|
|
38
|
+
watermark: z.boolean().nullish(),
|
|
39
|
+
audio: z.boolean().nullish(),
|
|
40
|
+
referenceUrls: z.array(z.string()).nullish(),
|
|
41
|
+
pollIntervalMs: z.number().positive().nullish(),
|
|
42
|
+
pollTimeoutMs: z.number().positive().nullish(),
|
|
43
|
+
})
|
|
44
|
+
.passthrough(),
|
|
45
|
+
),
|
|
46
|
+
);
|
|
@@ -9,62 +9,20 @@ import {
|
|
|
9
9
|
createJsonErrorResponseHandler,
|
|
10
10
|
createJsonResponseHandler,
|
|
11
11
|
delay,
|
|
12
|
-
type FetchFunction,
|
|
13
12
|
getFromApi,
|
|
14
|
-
lazySchema,
|
|
15
13
|
parseProviderOptions,
|
|
16
14
|
postJsonToApi,
|
|
17
|
-
type Resolvable,
|
|
18
15
|
resolve,
|
|
19
|
-
|
|
16
|
+
type FetchFunction,
|
|
17
|
+
type Resolvable,
|
|
20
18
|
} from '@ai-sdk/provider-utils';
|
|
21
19
|
import { z } from 'zod/v4';
|
|
20
|
+
import {
|
|
21
|
+
alibabaVideoModelOptionsSchema,
|
|
22
|
+
type AlibabaVideoModelOptions,
|
|
23
|
+
} from './alibaba-video-model-options';
|
|
22
24
|
import type { AlibabaVideoModelId } from './alibaba-video-settings';
|
|
23
25
|
|
|
24
|
-
export type AlibabaVideoModelOptions = {
|
|
25
|
-
/** Negative prompt to specify what to avoid (max 500 chars). */
|
|
26
|
-
negativePrompt?: string | null;
|
|
27
|
-
/** URL to audio file for audio-video sync (WAV/MP3, 3-30s, max 15MB). */
|
|
28
|
-
audioUrl?: string | null;
|
|
29
|
-
/** Enable prompt extension/rewriting for better generation. Defaults to true. */
|
|
30
|
-
promptExtend?: boolean | null;
|
|
31
|
-
/** Shot type: 'single' for single-shot or 'multi' for multi-shot narrative. */
|
|
32
|
-
shotType?: 'single' | 'multi' | null;
|
|
33
|
-
/** Whether to add watermark to generated video. Defaults to false. */
|
|
34
|
-
watermark?: boolean | null;
|
|
35
|
-
/** Enable audio generation (for I2V/R2V models). */
|
|
36
|
-
audio?: boolean | null;
|
|
37
|
-
/**
|
|
38
|
-
* Reference URLs for reference-to-video mode.
|
|
39
|
-
* Array of URLs to images (0-5) and/or videos (0-3), max 5 total.
|
|
40
|
-
* Use character identifiers (character1, character2) in prompts to reference them.
|
|
41
|
-
*/
|
|
42
|
-
referenceUrls?: string[] | null;
|
|
43
|
-
/** Polling interval in milliseconds. Defaults to 5000 (5 seconds). */
|
|
44
|
-
pollIntervalMs?: number | null;
|
|
45
|
-
/** Maximum wait time in milliseconds for video generation. Defaults to 600000 (10 minutes). */
|
|
46
|
-
pollTimeoutMs?: number | null;
|
|
47
|
-
[key: string]: unknown;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const alibabaVideoModelOptionsSchema = lazySchema(() =>
|
|
51
|
-
zodSchema(
|
|
52
|
-
z
|
|
53
|
-
.object({
|
|
54
|
-
negativePrompt: z.string().nullish(),
|
|
55
|
-
audioUrl: z.string().nullish(),
|
|
56
|
-
promptExtend: z.boolean().nullish(),
|
|
57
|
-
shotType: z.enum(['single', 'multi']).nullish(),
|
|
58
|
-
watermark: z.boolean().nullish(),
|
|
59
|
-
audio: z.boolean().nullish(),
|
|
60
|
-
referenceUrls: z.array(z.string()).nullish(),
|
|
61
|
-
pollIntervalMs: z.number().positive().nullish(),
|
|
62
|
-
pollTimeoutMs: z.number().positive().nullish(),
|
|
63
|
-
})
|
|
64
|
-
.passthrough(),
|
|
65
|
-
),
|
|
66
|
-
);
|
|
67
|
-
|
|
68
26
|
interface AlibabaVideoModelConfig {
|
|
69
27
|
provider: string;
|
|
70
28
|
baseURL: string;
|
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type LanguageModelV4DataContent,
|
|
3
|
-
type LanguageModelV4Prompt,
|
|
4
2
|
UnsupportedFunctionalityError,
|
|
3
|
+
type LanguageModelV4FilePart,
|
|
4
|
+
type LanguageModelV4Prompt,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
convertToBase64,
|
|
8
|
+
getTopLevelMediaType,
|
|
9
|
+
resolveFullMediaType,
|
|
10
|
+
} from '@ai-sdk/provider-utils';
|
|
7
11
|
import type { AlibabaChatPrompt } from './alibaba-chat-prompt';
|
|
8
12
|
import type { CacheControlValidator } from './get-cache-control';
|
|
9
13
|
|
|
10
|
-
function formatImageUrl({
|
|
11
|
-
data
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
function formatImageUrl({ part }: { part: LanguageModelV4FilePart }): string {
|
|
15
|
+
if (part.data.type === 'url') {
|
|
16
|
+
return part.data.url.toString();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (part.data.type === 'data') {
|
|
20
|
+
return `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
throw new UnsupportedFunctionalityError({
|
|
24
|
+
functionality: `file part data type ${part.data.type}`,
|
|
25
|
+
});
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
export function convertToAlibabaChatMessages({
|
|
@@ -73,25 +79,35 @@ export function convertToAlibabaChatMessages({
|
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
case 'file': {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
82
|
+
switch (part.data.type) {
|
|
83
|
+
case 'reference': {
|
|
84
|
+
throw new UnsupportedFunctionalityError({
|
|
85
|
+
functionality: 'file parts with provider references',
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
case 'text': {
|
|
89
|
+
throw new UnsupportedFunctionalityError({
|
|
90
|
+
functionality: 'text file parts',
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
case 'url':
|
|
94
|
+
case 'data': {
|
|
95
|
+
if (getTopLevelMediaType(part.mediaType) === 'image') {
|
|
96
|
+
return {
|
|
97
|
+
type: 'image_url',
|
|
98
|
+
image_url: {
|
|
99
|
+
url: formatImageUrl({ part }),
|
|
100
|
+
},
|
|
101
|
+
...(partCacheControl
|
|
102
|
+
? { cache_control: partCacheControl }
|
|
103
|
+
: {}),
|
|
104
|
+
};
|
|
105
|
+
} else {
|
|
106
|
+
throw new UnsupportedFunctionalityError({
|
|
107
|
+
functionality: 'Only image file parts are supported',
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
95
111
|
}
|
|
96
112
|
}
|
|
97
113
|
}
|
|
@@ -167,7 +183,7 @@ export function convertToAlibabaChatMessages({
|
|
|
167
183
|
contentValue = output.value;
|
|
168
184
|
break;
|
|
169
185
|
case 'execution-denied':
|
|
170
|
-
contentValue = output.reason ?? 'Tool execution denied.';
|
|
186
|
+
contentValue = output.reason ?? 'Tool call execution denied.';
|
|
171
187
|
break;
|
|
172
188
|
case 'content':
|
|
173
189
|
case 'json':
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export type {
|
|
2
2
|
AlibabaChatModelId,
|
|
3
|
-
|
|
4
|
-
/** @deprecated Use `
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
AlibabaLanguageModelChatOptions,
|
|
4
|
+
/** @deprecated Use `AlibabaLanguageModelChatOptions` instead. */
|
|
5
|
+
AlibabaLanguageModelChatOptions as AlibabaLanguageModelOptions,
|
|
6
|
+
/** @deprecated Use `AlibabaLanguageModelChatOptions` instead. */
|
|
7
|
+
AlibabaLanguageModelChatOptions as AlibabaProviderOptions,
|
|
8
|
+
} from './alibaba-chat-language-model-options';
|
|
7
9
|
export type { AlibabaCacheControl } from './alibaba-chat-prompt';
|
|
8
10
|
export {
|
|
9
11
|
type AlibabaProvider,
|
|
@@ -15,7 +17,7 @@ export type {
|
|
|
15
17
|
AlibabaVideoModelOptions,
|
|
16
18
|
/** @deprecated Use `AlibabaVideoModelOptions` instead. */
|
|
17
19
|
AlibabaVideoModelOptions as AlibabaVideoProviderOptions,
|
|
18
|
-
} from './alibaba-video-model';
|
|
20
|
+
} from './alibaba-video-model-options';
|
|
19
21
|
export type { AlibabaVideoModelId } from './alibaba-video-settings';
|
|
20
22
|
export type { AlibabaUsage } from './convert-alibaba-usage';
|
|
21
23
|
export { VERSION } from './version';
|