@ai-sdk/alibaba 2.0.0-beta.6 → 2.0.0-beta.60
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 +491 -0
- package/README.md +22 -1
- package/dist/index.d.ts +34 -5
- package/dist/index.js +478 -308
- package/dist/index.js.map +1 -1
- package/package.json +15 -15
- package/src/{alibaba-chat-options.ts → alibaba-chat-language-model-options.ts} +4 -3
- package/src/alibaba-chat-language-model.ts +97 -133
- package/src/alibaba-config.ts +1 -1
- package/src/alibaba-embedding-model-options.ts +33 -0
- package/src/alibaba-embedding-model.ts +178 -0
- package/src/alibaba-error.ts +17 -0
- package/src/alibaba-provider.ts +41 -25
- 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 +59 -58
- package/src/index.ts +11 -5
- package/src/version.ts +6 -3
- package/dist/index.d.mts +0 -119
- package/dist/index.mjs +0 -1054
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,69 +1,77 @@
|
|
|
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
|
+
loadApiKey,
|
|
7
|
+
withoutTrailingSlash,
|
|
8
|
+
withUserAgentSuffix
|
|
9
|
+
} from "@ai-sdk/provider-utils";
|
|
33
10
|
|
|
34
11
|
// src/alibaba-chat-language-model.ts
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
12
|
+
import {
|
|
13
|
+
getResponseMetadata,
|
|
14
|
+
mapOpenAICompatibleFinishReason,
|
|
15
|
+
prepareTools
|
|
16
|
+
} from "@ai-sdk/openai-compatible/internal";
|
|
17
|
+
import {
|
|
18
|
+
combineHeaders,
|
|
19
|
+
createEventSourceResponseHandler,
|
|
20
|
+
createJsonResponseHandler,
|
|
21
|
+
generateId,
|
|
22
|
+
isCustomReasoning,
|
|
23
|
+
mapReasoningToProviderBudget,
|
|
24
|
+
parseProviderOptions,
|
|
25
|
+
postJsonToApi,
|
|
26
|
+
serializeModelOptions,
|
|
27
|
+
StreamingToolCallTracker,
|
|
28
|
+
WORKFLOW_SERIALIZE,
|
|
29
|
+
WORKFLOW_DESERIALIZE
|
|
30
|
+
} from "@ai-sdk/provider-utils";
|
|
31
|
+
import { z as z3 } from "zod/v4";
|
|
39
32
|
|
|
40
|
-
// src/alibaba-chat-options.ts
|
|
41
|
-
|
|
42
|
-
var
|
|
33
|
+
// src/alibaba-chat-language-model-options.ts
|
|
34
|
+
import { z } from "zod/v4";
|
|
35
|
+
var alibabaLanguageModelChatOptions = z.object({
|
|
43
36
|
/**
|
|
44
37
|
* Enable thinking/reasoning mode for supported models.
|
|
45
38
|
* When enabled, the model generates reasoning content before the response.
|
|
46
39
|
*
|
|
47
40
|
* @default false
|
|
48
41
|
*/
|
|
49
|
-
enableThinking:
|
|
42
|
+
enableThinking: z.boolean().optional(),
|
|
50
43
|
/**
|
|
51
44
|
* Maximum number of reasoning tokens to generate.
|
|
52
45
|
*/
|
|
53
|
-
thinkingBudget:
|
|
46
|
+
thinkingBudget: z.number().positive().optional(),
|
|
54
47
|
/**
|
|
55
48
|
* Whether to enable parallel function calling during tool use.
|
|
56
49
|
*
|
|
57
50
|
* @default true
|
|
58
51
|
*/
|
|
59
|
-
parallelToolCalls:
|
|
52
|
+
parallelToolCalls: z.boolean().optional()
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// src/alibaba-error.ts
|
|
56
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
57
|
+
import { z as z2 } from "zod/v4";
|
|
58
|
+
var alibabaErrorDataSchema = z2.object({
|
|
59
|
+
error: z2.object({
|
|
60
|
+
message: z2.string(),
|
|
61
|
+
code: z2.string().nullish(),
|
|
62
|
+
type: z2.string().nullish()
|
|
63
|
+
})
|
|
64
|
+
});
|
|
65
|
+
var alibabaFailedResponseHandler = createJsonErrorResponseHandler({
|
|
66
|
+
errorSchema: alibabaErrorDataSchema,
|
|
67
|
+
errorToMessage: (data) => data.error.message
|
|
60
68
|
});
|
|
61
69
|
|
|
62
70
|
// src/convert-alibaba-usage.ts
|
|
63
|
-
|
|
71
|
+
import { convertOpenAICompatibleChatUsage } from "@ai-sdk/openai-compatible/internal";
|
|
64
72
|
function convertAlibabaUsage(usage) {
|
|
65
73
|
var _a, _b, _c, _d;
|
|
66
|
-
const baseUsage =
|
|
74
|
+
const baseUsage = convertOpenAICompatibleChatUsage(usage);
|
|
67
75
|
const cacheWriteTokens = (_b = (_a = usage == null ? void 0 : usage.prompt_tokens_details) == null ? void 0 : _a.cache_creation_input_tokens) != null ? _b : 0;
|
|
68
76
|
const noCacheTokens = ((_c = baseUsage.inputTokens.total) != null ? _c : 0) - ((_d = baseUsage.inputTokens.cacheRead) != null ? _d : 0) - cacheWriteTokens;
|
|
69
77
|
return {
|
|
@@ -77,19 +85,30 @@ function convertAlibabaUsage(usage) {
|
|
|
77
85
|
}
|
|
78
86
|
|
|
79
87
|
// src/convert-to-alibaba-chat-messages.ts
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
import {
|
|
89
|
+
UnsupportedFunctionalityError
|
|
90
|
+
} from "@ai-sdk/provider";
|
|
91
|
+
import {
|
|
92
|
+
convertToBase64,
|
|
93
|
+
getTopLevelMediaType,
|
|
94
|
+
resolveFullMediaType
|
|
95
|
+
} from "@ai-sdk/provider-utils";
|
|
96
|
+
function formatImageUrl({ part }) {
|
|
97
|
+
if (part.data.type === "url") {
|
|
98
|
+
return part.data.url.toString();
|
|
99
|
+
}
|
|
100
|
+
if (part.data.type === "data") {
|
|
101
|
+
return `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`;
|
|
102
|
+
}
|
|
103
|
+
throw new UnsupportedFunctionalityError({
|
|
104
|
+
functionality: `file part data type ${part.data.type}`
|
|
105
|
+
});
|
|
87
106
|
}
|
|
88
107
|
function convertToAlibabaChatMessages({
|
|
89
108
|
prompt,
|
|
90
109
|
cacheControlValidator
|
|
91
110
|
}) {
|
|
92
|
-
var _a;
|
|
111
|
+
var _a, _b;
|
|
93
112
|
const messages = [];
|
|
94
113
|
for (const { role, content, ...message } of prompt) {
|
|
95
114
|
const messageCacheControl = cacheControlValidator == null ? void 0 : cacheControlValidator.getCacheControl(
|
|
@@ -114,18 +133,12 @@ function convertToAlibabaChatMessages({
|
|
|
114
133
|
break;
|
|
115
134
|
}
|
|
116
135
|
case "user": {
|
|
117
|
-
const isSinglePart = content.length === 1;
|
|
118
|
-
if (isSinglePart && content[0].type === "text" && !messageCacheControl) {
|
|
119
|
-
messages.push({
|
|
120
|
-
role: "user",
|
|
121
|
-
content: content[0].text
|
|
122
|
-
});
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
136
|
messages.push({
|
|
126
137
|
role: "user",
|
|
127
|
-
content: content.map((part) => {
|
|
128
|
-
|
|
138
|
+
content: content.map((part, index) => {
|
|
139
|
+
var _a2;
|
|
140
|
+
const isLastPart = index === content.length - 1;
|
|
141
|
+
const partCacheControl = (_a2 = cacheControlValidator == null ? void 0 : cacheControlValidator.getCacheControl(part.providerOptions)) != null ? _a2 : isLastPart ? messageCacheControl : void 0;
|
|
129
142
|
switch (part.type) {
|
|
130
143
|
case "text": {
|
|
131
144
|
return {
|
|
@@ -135,19 +148,33 @@ function convertToAlibabaChatMessages({
|
|
|
135
148
|
};
|
|
136
149
|
}
|
|
137
150
|
case "file": {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
+
switch (part.data.type) {
|
|
152
|
+
case "reference": {
|
|
153
|
+
throw new UnsupportedFunctionalityError({
|
|
154
|
+
functionality: "file parts with provider references"
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
case "text": {
|
|
158
|
+
throw new UnsupportedFunctionalityError({
|
|
159
|
+
functionality: "text file parts"
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
case "url":
|
|
163
|
+
case "data": {
|
|
164
|
+
if (getTopLevelMediaType(part.mediaType) === "image") {
|
|
165
|
+
return {
|
|
166
|
+
type: "image_url",
|
|
167
|
+
image_url: {
|
|
168
|
+
url: formatImageUrl({ part })
|
|
169
|
+
},
|
|
170
|
+
...partCacheControl ? { cache_control: partCacheControl } : {}
|
|
171
|
+
};
|
|
172
|
+
} else {
|
|
173
|
+
throw new UnsupportedFunctionalityError({
|
|
174
|
+
functionality: "Only image file parts are supported"
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
151
178
|
}
|
|
152
179
|
}
|
|
153
180
|
}
|
|
@@ -192,13 +219,13 @@ function convertToAlibabaChatMessages({
|
|
|
192
219
|
const toolResponses = content.filter(
|
|
193
220
|
(r) => r.type !== "tool-approval-response"
|
|
194
221
|
);
|
|
195
|
-
const isSinglePart = toolResponses.length === 1;
|
|
196
222
|
for (let i = 0; i < toolResponses.length; i++) {
|
|
197
223
|
const toolResponse = toolResponses[i];
|
|
198
224
|
const output = toolResponse.output;
|
|
199
|
-
const
|
|
225
|
+
const isLastPart = i === toolResponses.length - 1;
|
|
226
|
+
const partCacheControl = (_a = cacheControlValidator == null ? void 0 : cacheControlValidator.getCacheControl(
|
|
200
227
|
toolResponse.providerOptions
|
|
201
|
-
);
|
|
228
|
+
)) != null ? _a : isLastPart ? messageCacheControl : void 0;
|
|
202
229
|
let contentValue;
|
|
203
230
|
switch (output.type) {
|
|
204
231
|
case "text":
|
|
@@ -206,7 +233,7 @@ function convertToAlibabaChatMessages({
|
|
|
206
233
|
contentValue = output.value;
|
|
207
234
|
break;
|
|
208
235
|
case "execution-denied":
|
|
209
|
-
contentValue = (
|
|
236
|
+
contentValue = (_b = output.reason) != null ? _b : "Tool call execution denied.";
|
|
210
237
|
break;
|
|
211
238
|
case "content":
|
|
212
239
|
case "json":
|
|
@@ -270,7 +297,7 @@ var CacheControlValidator = class {
|
|
|
270
297
|
};
|
|
271
298
|
|
|
272
299
|
// src/alibaba-chat-language-model.ts
|
|
273
|
-
var
|
|
300
|
+
var AlibabaChatLanguageModel = class _AlibabaChatLanguageModel {
|
|
274
301
|
constructor(modelId, config) {
|
|
275
302
|
this.specificationVersion = "v4";
|
|
276
303
|
this.supportedUrls = {
|
|
@@ -279,6 +306,15 @@ var AlibabaLanguageModel = class {
|
|
|
279
306
|
this.modelId = modelId;
|
|
280
307
|
this.config = config;
|
|
281
308
|
}
|
|
309
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
310
|
+
return serializeModelOptions({
|
|
311
|
+
modelId: model.modelId,
|
|
312
|
+
config: model.config
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
316
|
+
return new _AlibabaChatLanguageModel(options.modelId, options.config);
|
|
317
|
+
}
|
|
282
318
|
get provider() {
|
|
283
319
|
return this.config.provider;
|
|
284
320
|
}
|
|
@@ -297,6 +333,7 @@ var AlibabaLanguageModel = class {
|
|
|
297
333
|
stopSequences,
|
|
298
334
|
responseFormat,
|
|
299
335
|
seed,
|
|
336
|
+
reasoning,
|
|
300
337
|
providerOptions,
|
|
301
338
|
tools,
|
|
302
339
|
toolChoice
|
|
@@ -304,10 +341,10 @@ var AlibabaLanguageModel = class {
|
|
|
304
341
|
var _a;
|
|
305
342
|
const warnings = [];
|
|
306
343
|
const cacheControlValidator = new CacheControlValidator();
|
|
307
|
-
const alibabaOptions = await
|
|
344
|
+
const alibabaOptions = await parseProviderOptions({
|
|
308
345
|
provider: "alibaba",
|
|
309
346
|
providerOptions,
|
|
310
|
-
schema:
|
|
347
|
+
schema: alibabaLanguageModelChatOptions
|
|
311
348
|
});
|
|
312
349
|
if (frequencyPenalty != null) {
|
|
313
350
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
@@ -329,9 +366,11 @@ var AlibabaLanguageModel = class {
|
|
|
329
366
|
description: responseFormat.description
|
|
330
367
|
}
|
|
331
368
|
} : { type: "json_object" } : void 0,
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
369
|
+
...resolveAlibabaThinking({
|
|
370
|
+
reasoning,
|
|
371
|
+
alibabaOptions,
|
|
372
|
+
warnings
|
|
373
|
+
}),
|
|
335
374
|
// Convert messages with cache control support
|
|
336
375
|
messages: convertToAlibabaChatMessages({
|
|
337
376
|
prompt,
|
|
@@ -342,7 +381,7 @@ var AlibabaLanguageModel = class {
|
|
|
342
381
|
tools: alibabaTools,
|
|
343
382
|
toolChoice: alibabaToolChoice,
|
|
344
383
|
toolWarnings
|
|
345
|
-
} =
|
|
384
|
+
} = prepareTools({ tools, toolChoice });
|
|
346
385
|
warnings.push(...cacheControlValidator.getWarnings());
|
|
347
386
|
return {
|
|
348
387
|
args: {
|
|
@@ -355,18 +394,18 @@ var AlibabaLanguageModel = class {
|
|
|
355
394
|
};
|
|
356
395
|
}
|
|
357
396
|
async doGenerate(options) {
|
|
358
|
-
var _a;
|
|
397
|
+
var _a, _b, _c, _d;
|
|
359
398
|
const { args, warnings } = await this.getArgs(options);
|
|
360
399
|
const {
|
|
361
400
|
responseHeaders,
|
|
362
401
|
value: response,
|
|
363
402
|
rawValue: rawResponse
|
|
364
|
-
} = await
|
|
403
|
+
} = await postJsonToApi({
|
|
365
404
|
url: `${this.config.baseURL}/chat/completions`,
|
|
366
|
-
headers: (
|
|
405
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
367
406
|
body: args,
|
|
368
407
|
failedResponseHandler: alibabaFailedResponseHandler,
|
|
369
|
-
successfulResponseHandler:
|
|
408
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
370
409
|
alibabaChatResponseSchema
|
|
371
410
|
),
|
|
372
411
|
abortSignal: options.abortSignal,
|
|
@@ -389,7 +428,7 @@ var AlibabaLanguageModel = class {
|
|
|
389
428
|
for (const toolCall of choice.message.tool_calls) {
|
|
390
429
|
content.push({
|
|
391
430
|
type: "tool-call",
|
|
392
|
-
toolCallId: toolCall.id,
|
|
431
|
+
toolCallId: (_c = toolCall.id) != null ? _c : generateId(),
|
|
393
432
|
toolName: toolCall.function.name,
|
|
394
433
|
input: toolCall.function.arguments
|
|
395
434
|
});
|
|
@@ -398,13 +437,13 @@ var AlibabaLanguageModel = class {
|
|
|
398
437
|
return {
|
|
399
438
|
content,
|
|
400
439
|
finishReason: {
|
|
401
|
-
unified:
|
|
402
|
-
raw: (
|
|
440
|
+
unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
|
|
441
|
+
raw: (_d = choice.finish_reason) != null ? _d : void 0
|
|
403
442
|
},
|
|
404
443
|
usage: convertAlibabaUsage(response.usage),
|
|
405
444
|
request: { body: JSON.stringify(args) },
|
|
406
445
|
response: {
|
|
407
|
-
...
|
|
446
|
+
...getResponseMetadata(response),
|
|
408
447
|
headers: responseHeaders,
|
|
409
448
|
body: rawResponse
|
|
410
449
|
},
|
|
@@ -412,18 +451,19 @@ var AlibabaLanguageModel = class {
|
|
|
412
451
|
};
|
|
413
452
|
}
|
|
414
453
|
async doStream(options) {
|
|
454
|
+
var _a, _b;
|
|
415
455
|
const { args, warnings } = await this.getArgs(options);
|
|
416
456
|
const body = {
|
|
417
457
|
...args,
|
|
418
458
|
stream: true,
|
|
419
459
|
stream_options: this.config.includeUsage ? { include_usage: true } : void 0
|
|
420
460
|
};
|
|
421
|
-
const { responseHeaders, value: response } = await
|
|
461
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
422
462
|
url: `${this.config.baseURL}/chat/completions`,
|
|
423
|
-
headers: (
|
|
463
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
424
464
|
body,
|
|
425
465
|
failedResponseHandler: alibabaFailedResponseHandler,
|
|
426
|
-
successfulResponseHandler:
|
|
466
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
427
467
|
alibabaChatChunkSchema
|
|
428
468
|
),
|
|
429
469
|
abortSignal: options.abortSignal,
|
|
@@ -437,15 +477,17 @@ var AlibabaLanguageModel = class {
|
|
|
437
477
|
let isFirstChunk = true;
|
|
438
478
|
let activeText = false;
|
|
439
479
|
let activeReasoningId = null;
|
|
440
|
-
|
|
480
|
+
let toolCallTracker;
|
|
441
481
|
return {
|
|
442
482
|
stream: response.pipeThrough(
|
|
443
483
|
new TransformStream({
|
|
444
484
|
start(controller) {
|
|
485
|
+
toolCallTracker = new StreamingToolCallTracker(controller, {
|
|
486
|
+
generateId
|
|
487
|
+
});
|
|
445
488
|
controller.enqueue({ type: "stream-start", warnings });
|
|
446
489
|
},
|
|
447
490
|
transform(chunk, controller) {
|
|
448
|
-
var _a, _b, _c, _d;
|
|
449
491
|
if (options.includeRawChunks) {
|
|
450
492
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
451
493
|
}
|
|
@@ -458,7 +500,7 @@ var AlibabaLanguageModel = class {
|
|
|
458
500
|
isFirstChunk = false;
|
|
459
501
|
controller.enqueue({
|
|
460
502
|
type: "response-metadata",
|
|
461
|
-
...
|
|
503
|
+
...getResponseMetadata(value)
|
|
462
504
|
});
|
|
463
505
|
}
|
|
464
506
|
if (value.usage != null) {
|
|
@@ -475,7 +517,7 @@ var AlibabaLanguageModel = class {
|
|
|
475
517
|
controller.enqueue({ type: "text-end", id: "0" });
|
|
476
518
|
activeText = false;
|
|
477
519
|
}
|
|
478
|
-
activeReasoningId =
|
|
520
|
+
activeReasoningId = generateId();
|
|
479
521
|
controller.enqueue({
|
|
480
522
|
type: "reasoning-start",
|
|
481
523
|
id: activeReasoningId
|
|
@@ -518,87 +560,12 @@ var AlibabaLanguageModel = class {
|
|
|
518
560
|
activeText = false;
|
|
519
561
|
}
|
|
520
562
|
for (const toolCallDelta of delta.tool_calls) {
|
|
521
|
-
|
|
522
|
-
if (toolCalls[index] == null) {
|
|
523
|
-
if (toolCallDelta.id == null) {
|
|
524
|
-
throw new import_provider2.InvalidResponseDataError({
|
|
525
|
-
data: toolCallDelta,
|
|
526
|
-
message: `Expected 'id' to be a string.`
|
|
527
|
-
});
|
|
528
|
-
}
|
|
529
|
-
if (((_b = toolCallDelta.function) == null ? void 0 : _b.name) == null) {
|
|
530
|
-
throw new import_provider2.InvalidResponseDataError({
|
|
531
|
-
data: toolCallDelta,
|
|
532
|
-
message: `Expected 'function.name' to be a string.`
|
|
533
|
-
});
|
|
534
|
-
}
|
|
535
|
-
controller.enqueue({
|
|
536
|
-
type: "tool-input-start",
|
|
537
|
-
id: toolCallDelta.id,
|
|
538
|
-
toolName: toolCallDelta.function.name
|
|
539
|
-
});
|
|
540
|
-
toolCalls[index] = {
|
|
541
|
-
id: toolCallDelta.id,
|
|
542
|
-
type: "function",
|
|
543
|
-
function: {
|
|
544
|
-
name: toolCallDelta.function.name,
|
|
545
|
-
arguments: (_c = toolCallDelta.function.arguments) != null ? _c : ""
|
|
546
|
-
},
|
|
547
|
-
hasFinished: false
|
|
548
|
-
};
|
|
549
|
-
const toolCall2 = toolCalls[index];
|
|
550
|
-
if (toolCall2.function.arguments.length > 0) {
|
|
551
|
-
controller.enqueue({
|
|
552
|
-
type: "tool-input-delta",
|
|
553
|
-
id: toolCall2.id,
|
|
554
|
-
delta: toolCall2.function.arguments
|
|
555
|
-
});
|
|
556
|
-
}
|
|
557
|
-
if ((0, import_provider_utils2.isParsableJson)(toolCall2.function.arguments)) {
|
|
558
|
-
controller.enqueue({
|
|
559
|
-
type: "tool-input-end",
|
|
560
|
-
id: toolCall2.id
|
|
561
|
-
});
|
|
562
|
-
controller.enqueue({
|
|
563
|
-
type: "tool-call",
|
|
564
|
-
toolCallId: toolCall2.id,
|
|
565
|
-
toolName: toolCall2.function.name,
|
|
566
|
-
input: toolCall2.function.arguments
|
|
567
|
-
});
|
|
568
|
-
toolCall2.hasFinished = true;
|
|
569
|
-
}
|
|
570
|
-
continue;
|
|
571
|
-
}
|
|
572
|
-
const toolCall = toolCalls[index];
|
|
573
|
-
if (toolCall.hasFinished) {
|
|
574
|
-
continue;
|
|
575
|
-
}
|
|
576
|
-
if (((_d = toolCallDelta.function) == null ? void 0 : _d.arguments) != null) {
|
|
577
|
-
toolCall.function.arguments += toolCallDelta.function.arguments;
|
|
578
|
-
controller.enqueue({
|
|
579
|
-
type: "tool-input-delta",
|
|
580
|
-
id: toolCall.id,
|
|
581
|
-
delta: toolCallDelta.function.arguments
|
|
582
|
-
});
|
|
583
|
-
}
|
|
584
|
-
if ((0, import_provider_utils2.isParsableJson)(toolCall.function.arguments)) {
|
|
585
|
-
controller.enqueue({
|
|
586
|
-
type: "tool-input-end",
|
|
587
|
-
id: toolCall.id
|
|
588
|
-
});
|
|
589
|
-
controller.enqueue({
|
|
590
|
-
type: "tool-call",
|
|
591
|
-
toolCallId: toolCall.id,
|
|
592
|
-
toolName: toolCall.function.name,
|
|
593
|
-
input: toolCall.function.arguments
|
|
594
|
-
});
|
|
595
|
-
toolCall.hasFinished = true;
|
|
596
|
-
}
|
|
563
|
+
toolCallTracker.processDelta(toolCallDelta);
|
|
597
564
|
}
|
|
598
565
|
}
|
|
599
566
|
if (choice.finish_reason != null) {
|
|
600
567
|
finishReason = {
|
|
601
|
-
unified:
|
|
568
|
+
unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
|
|
602
569
|
raw: choice.finish_reason
|
|
603
570
|
};
|
|
604
571
|
}
|
|
@@ -613,6 +580,7 @@ var AlibabaLanguageModel = class {
|
|
|
613
580
|
if (activeText) {
|
|
614
581
|
controller.enqueue({ type: "text-end", id: "0" });
|
|
615
582
|
}
|
|
583
|
+
toolCallTracker.flush();
|
|
616
584
|
controller.enqueue({
|
|
617
585
|
type: "finish",
|
|
618
586
|
finishReason,
|
|
@@ -626,133 +594,341 @@ var AlibabaLanguageModel = class {
|
|
|
626
594
|
};
|
|
627
595
|
}
|
|
628
596
|
};
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
597
|
+
function resolveAlibabaThinking({
|
|
598
|
+
reasoning,
|
|
599
|
+
alibabaOptions,
|
|
600
|
+
warnings
|
|
601
|
+
}) {
|
|
602
|
+
if ((alibabaOptions == null ? void 0 : alibabaOptions.enableThinking) != null || (alibabaOptions == null ? void 0 : alibabaOptions.thinkingBudget) != null) {
|
|
603
|
+
return {
|
|
604
|
+
...alibabaOptions.enableThinking != null ? { enable_thinking: alibabaOptions.enableThinking } : {},
|
|
605
|
+
...alibabaOptions.thinkingBudget != null ? { thinking_budget: alibabaOptions.thinkingBudget } : {}
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
if (!isCustomReasoning(reasoning)) {
|
|
609
|
+
return {};
|
|
610
|
+
}
|
|
611
|
+
if (reasoning === "none") {
|
|
612
|
+
return { enable_thinking: false };
|
|
613
|
+
}
|
|
614
|
+
const thinkingBudget = mapReasoningToProviderBudget({
|
|
615
|
+
reasoning,
|
|
616
|
+
maxOutputTokens: 16384,
|
|
617
|
+
maxReasoningBudget: 16384,
|
|
618
|
+
warnings
|
|
619
|
+
});
|
|
620
|
+
return {
|
|
621
|
+
enable_thinking: true,
|
|
622
|
+
...thinkingBudget != null ? { thinking_budget: thinkingBudget } : {}
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
var alibabaUsageSchema = z3.object({
|
|
626
|
+
prompt_tokens: z3.number(),
|
|
627
|
+
completion_tokens: z3.number(),
|
|
628
|
+
total_tokens: z3.number(),
|
|
629
|
+
prompt_tokens_details: z3.object({
|
|
630
|
+
cached_tokens: z3.number().nullish(),
|
|
631
|
+
cache_creation_input_tokens: z3.number().nullish()
|
|
636
632
|
}).nullish(),
|
|
637
|
-
completion_tokens_details:
|
|
638
|
-
reasoning_tokens:
|
|
633
|
+
completion_tokens_details: z3.object({
|
|
634
|
+
reasoning_tokens: z3.number().nullish()
|
|
639
635
|
}).nullish()
|
|
640
636
|
});
|
|
641
|
-
var alibabaChatResponseSchema =
|
|
642
|
-
id:
|
|
643
|
-
created:
|
|
644
|
-
model:
|
|
645
|
-
choices:
|
|
646
|
-
|
|
647
|
-
message:
|
|
648
|
-
role:
|
|
649
|
-
content:
|
|
650
|
-
reasoning_content:
|
|
637
|
+
var alibabaChatResponseSchema = z3.object({
|
|
638
|
+
id: z3.string().nullish(),
|
|
639
|
+
created: z3.number().nullish(),
|
|
640
|
+
model: z3.string().nullish(),
|
|
641
|
+
choices: z3.array(
|
|
642
|
+
z3.object({
|
|
643
|
+
message: z3.object({
|
|
644
|
+
role: z3.literal("assistant").nullish(),
|
|
645
|
+
content: z3.string().nullish(),
|
|
646
|
+
reasoning_content: z3.string().nullish(),
|
|
651
647
|
// Alibaba thinking mode
|
|
652
|
-
tool_calls:
|
|
653
|
-
|
|
654
|
-
id:
|
|
655
|
-
type:
|
|
656
|
-
function:
|
|
657
|
-
name:
|
|
658
|
-
arguments:
|
|
648
|
+
tool_calls: z3.array(
|
|
649
|
+
z3.object({
|
|
650
|
+
id: z3.string(),
|
|
651
|
+
type: z3.literal("function"),
|
|
652
|
+
function: z3.object({
|
|
653
|
+
name: z3.string(),
|
|
654
|
+
arguments: z3.string()
|
|
659
655
|
})
|
|
660
656
|
})
|
|
661
657
|
).nullish()
|
|
662
658
|
}),
|
|
663
|
-
finish_reason:
|
|
664
|
-
index:
|
|
659
|
+
finish_reason: z3.string().nullish(),
|
|
660
|
+
index: z3.number()
|
|
665
661
|
})
|
|
666
662
|
),
|
|
667
663
|
usage: alibabaUsageSchema.nullish()
|
|
668
664
|
});
|
|
669
|
-
var alibabaChatChunkSchema =
|
|
670
|
-
id:
|
|
671
|
-
created:
|
|
672
|
-
model:
|
|
673
|
-
choices:
|
|
674
|
-
|
|
675
|
-
delta:
|
|
676
|
-
role:
|
|
677
|
-
content:
|
|
678
|
-
reasoning_content:
|
|
665
|
+
var alibabaChatChunkSchema = z3.object({
|
|
666
|
+
id: z3.string().nullish(),
|
|
667
|
+
created: z3.number().nullish(),
|
|
668
|
+
model: z3.string().nullish(),
|
|
669
|
+
choices: z3.array(
|
|
670
|
+
z3.object({
|
|
671
|
+
delta: z3.object({
|
|
672
|
+
role: z3.enum(["assistant"]).nullish(),
|
|
673
|
+
content: z3.string().nullish(),
|
|
674
|
+
reasoning_content: z3.string().nullish(),
|
|
679
675
|
// Alibaba thinking mode delta
|
|
680
|
-
tool_calls:
|
|
681
|
-
|
|
682
|
-
index:
|
|
676
|
+
tool_calls: z3.array(
|
|
677
|
+
z3.object({
|
|
678
|
+
index: z3.number().nullish(),
|
|
683
679
|
// Index for accumulating tool calls
|
|
684
|
-
id:
|
|
685
|
-
type:
|
|
686
|
-
function:
|
|
687
|
-
name:
|
|
688
|
-
arguments:
|
|
680
|
+
id: z3.string().nullish(),
|
|
681
|
+
type: z3.literal("function").nullish(),
|
|
682
|
+
function: z3.object({
|
|
683
|
+
name: z3.string().nullish(),
|
|
684
|
+
arguments: z3.string().nullish()
|
|
689
685
|
}).nullish()
|
|
690
686
|
})
|
|
691
687
|
).nullish()
|
|
692
688
|
}),
|
|
693
|
-
finish_reason:
|
|
694
|
-
index:
|
|
689
|
+
finish_reason: z3.string().nullish(),
|
|
690
|
+
index: z3.number()
|
|
695
691
|
})
|
|
696
692
|
),
|
|
697
693
|
usage: alibabaUsageSchema.nullish()
|
|
698
694
|
// Usage only appears in final chunk
|
|
699
695
|
});
|
|
700
696
|
|
|
697
|
+
// src/alibaba-embedding-model.ts
|
|
698
|
+
import {
|
|
699
|
+
TooManyEmbeddingValuesForCallError,
|
|
700
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
701
|
+
} from "@ai-sdk/provider";
|
|
702
|
+
import {
|
|
703
|
+
combineHeaders as combineHeaders2,
|
|
704
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
|
|
705
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
706
|
+
parseProviderOptions as parseProviderOptions2,
|
|
707
|
+
postJsonToApi as postJsonToApi2,
|
|
708
|
+
serializeModelOptions as serializeModelOptions2,
|
|
709
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
|
|
710
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
|
|
711
|
+
} from "@ai-sdk/provider-utils";
|
|
712
|
+
import { z as z5 } from "zod/v4";
|
|
713
|
+
|
|
714
|
+
// src/alibaba-embedding-model-options.ts
|
|
715
|
+
import { z as z4 } from "zod/v4";
|
|
716
|
+
var alibabaEmbeddingModelOptions = z4.object({
|
|
717
|
+
/**
|
|
718
|
+
* Differentiates query text from document text for asymmetric retrieval tasks.
|
|
719
|
+
* Defaults to `document`.
|
|
720
|
+
*/
|
|
721
|
+
textType: z4.enum(["query", "document"]).optional(),
|
|
722
|
+
/**
|
|
723
|
+
* The dimension of the output embedding vectors. Defaults to 1024.
|
|
724
|
+
*
|
|
725
|
+
* `text-embedding-v4` also supports 1536 and 2048 dimensions.
|
|
726
|
+
*/
|
|
727
|
+
dimension: z4.number().optional(),
|
|
728
|
+
/**
|
|
729
|
+
* The output vector type. Defaults to `dense`.
|
|
730
|
+
*
|
|
731
|
+
* Sparse-only output is not supported by the AI SDK embedding interface,
|
|
732
|
+
* which requires dense number arrays.
|
|
733
|
+
*/
|
|
734
|
+
outputType: z4.enum(["dense", "sparse", "dense&sparse"]).optional()
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
// src/alibaba-embedding-model.ts
|
|
738
|
+
var alibabaEmbeddingFailedResponseHandler = createJsonErrorResponseHandler2({
|
|
739
|
+
errorSchema: z5.object({
|
|
740
|
+
code: z5.string().nullish(),
|
|
741
|
+
message: z5.string(),
|
|
742
|
+
request_id: z5.string().nullish()
|
|
743
|
+
}),
|
|
744
|
+
errorToMessage: (data) => data.message
|
|
745
|
+
});
|
|
746
|
+
var AlibabaEmbeddingModel = class _AlibabaEmbeddingModel {
|
|
747
|
+
constructor(modelId, config) {
|
|
748
|
+
this.specificationVersion = "v4";
|
|
749
|
+
this.maxEmbeddingsPerCall = 10;
|
|
750
|
+
this.supportsParallelCalls = false;
|
|
751
|
+
this.modelId = modelId;
|
|
752
|
+
this.config = config;
|
|
753
|
+
}
|
|
754
|
+
static [WORKFLOW_SERIALIZE2](model) {
|
|
755
|
+
return serializeModelOptions2({
|
|
756
|
+
modelId: model.modelId,
|
|
757
|
+
config: model.config
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
static [WORKFLOW_DESERIALIZE2](options) {
|
|
761
|
+
return new _AlibabaEmbeddingModel(options.modelId, options.config);
|
|
762
|
+
}
|
|
763
|
+
get provider() {
|
|
764
|
+
return this.config.provider;
|
|
765
|
+
}
|
|
766
|
+
async doEmbed({
|
|
767
|
+
values,
|
|
768
|
+
headers,
|
|
769
|
+
abortSignal,
|
|
770
|
+
providerOptions
|
|
771
|
+
}) {
|
|
772
|
+
var _a, _b;
|
|
773
|
+
if (values.length > this.maxEmbeddingsPerCall) {
|
|
774
|
+
throw new TooManyEmbeddingValuesForCallError({
|
|
775
|
+
provider: this.provider,
|
|
776
|
+
modelId: this.modelId,
|
|
777
|
+
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
778
|
+
values
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
const alibabaOptions = await parseProviderOptions2({
|
|
782
|
+
provider: "alibaba",
|
|
783
|
+
providerOptions,
|
|
784
|
+
schema: alibabaEmbeddingModelOptions
|
|
785
|
+
});
|
|
786
|
+
if ((alibabaOptions == null ? void 0 : alibabaOptions.outputType) === "sparse") {
|
|
787
|
+
throw new UnsupportedFunctionalityError2({
|
|
788
|
+
functionality: "Alibaba embedding outputType 'sparse'",
|
|
789
|
+
message: "Alibaba embedding outputType 'sparse' is not supported because AI SDK embeddings require dense number arrays. Use 'dense' or 'dense&sparse' instead."
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
const {
|
|
793
|
+
responseHeaders,
|
|
794
|
+
value: response,
|
|
795
|
+
rawValue
|
|
796
|
+
} = await postJsonToApi2({
|
|
797
|
+
url: `${this.config.baseURL}/services/embeddings/text-embedding/text-embedding`,
|
|
798
|
+
headers: combineHeaders2((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), headers),
|
|
799
|
+
body: {
|
|
800
|
+
model: this.modelId,
|
|
801
|
+
input: {
|
|
802
|
+
texts: values
|
|
803
|
+
},
|
|
804
|
+
parameters: {
|
|
805
|
+
text_type: alibabaOptions == null ? void 0 : alibabaOptions.textType,
|
|
806
|
+
dimension: alibabaOptions == null ? void 0 : alibabaOptions.dimension,
|
|
807
|
+
output_type: alibabaOptions == null ? void 0 : alibabaOptions.outputType
|
|
808
|
+
}
|
|
809
|
+
},
|
|
810
|
+
failedResponseHandler: alibabaEmbeddingFailedResponseHandler,
|
|
811
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
812
|
+
alibabaTextEmbeddingResponseSchema
|
|
813
|
+
),
|
|
814
|
+
abortSignal,
|
|
815
|
+
fetch: this.config.fetch
|
|
816
|
+
});
|
|
817
|
+
const sortedEmbeddings = response.output.embeddings.sort(
|
|
818
|
+
(a, b) => a.text_index - b.text_index
|
|
819
|
+
);
|
|
820
|
+
const sparseEmbeddings = sortedEmbeddings.map(
|
|
821
|
+
(item) => item.sparse_embedding == null ? void 0 : {
|
|
822
|
+
textIndex: item.text_index,
|
|
823
|
+
sparseEmbedding: item.sparse_embedding
|
|
824
|
+
}
|
|
825
|
+
).filter((item) => item != null);
|
|
826
|
+
return {
|
|
827
|
+
warnings: [],
|
|
828
|
+
embeddings: sortedEmbeddings.map((item) => item.embedding),
|
|
829
|
+
usage: response.usage ? { tokens: response.usage.total_tokens } : void 0,
|
|
830
|
+
providerMetadata: sparseEmbeddings.length > 0 ? {
|
|
831
|
+
alibaba: {
|
|
832
|
+
sparseEmbeddings
|
|
833
|
+
}
|
|
834
|
+
} : void 0,
|
|
835
|
+
response: { headers: responseHeaders, body: rawValue }
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
var alibabaTextEmbeddingSparseEmbeddingSchema = z5.object({
|
|
840
|
+
index: z5.number(),
|
|
841
|
+
value: z5.number(),
|
|
842
|
+
token: z5.string().nullish()
|
|
843
|
+
});
|
|
844
|
+
var alibabaTextEmbeddingResponseSchema = z5.object({
|
|
845
|
+
output: z5.object({
|
|
846
|
+
embeddings: z5.array(
|
|
847
|
+
z5.object({
|
|
848
|
+
embedding: z5.array(z5.number()),
|
|
849
|
+
text_index: z5.number(),
|
|
850
|
+
sparse_embedding: z5.array(alibabaTextEmbeddingSparseEmbeddingSchema).nullish()
|
|
851
|
+
})
|
|
852
|
+
)
|
|
853
|
+
}),
|
|
854
|
+
usage: z5.object({
|
|
855
|
+
total_tokens: z5.number()
|
|
856
|
+
}).nullish()
|
|
857
|
+
});
|
|
858
|
+
|
|
701
859
|
// src/alibaba-video-model.ts
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
860
|
+
import {
|
|
861
|
+
AISDKError
|
|
862
|
+
} from "@ai-sdk/provider";
|
|
863
|
+
import {
|
|
864
|
+
combineHeaders as combineHeaders3,
|
|
865
|
+
convertUint8ArrayToBase64,
|
|
866
|
+
createJsonErrorResponseHandler as createJsonErrorResponseHandler3,
|
|
867
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
868
|
+
delay,
|
|
869
|
+
getFromApi,
|
|
870
|
+
parseProviderOptions as parseProviderOptions3,
|
|
871
|
+
postJsonToApi as postJsonToApi3,
|
|
872
|
+
resolve
|
|
873
|
+
} from "@ai-sdk/provider-utils";
|
|
874
|
+
import { z as z7 } from "zod/v4";
|
|
875
|
+
|
|
876
|
+
// src/alibaba-video-model-options.ts
|
|
877
|
+
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
878
|
+
import { z as z6 } from "zod/v4";
|
|
879
|
+
var alibabaVideoModelOptionsSchema = lazySchema(
|
|
880
|
+
() => zodSchema(
|
|
881
|
+
z6.object({
|
|
882
|
+
negativePrompt: z6.string().nullish(),
|
|
883
|
+
audioUrl: z6.string().nullish(),
|
|
884
|
+
promptExtend: z6.boolean().nullish(),
|
|
885
|
+
shotType: z6.enum(["single", "multi"]).nullish(),
|
|
886
|
+
watermark: z6.boolean().nullish(),
|
|
887
|
+
audio: z6.boolean().nullish(),
|
|
888
|
+
referenceUrls: z6.array(z6.string()).nullish(),
|
|
889
|
+
pollIntervalMs: z6.number().positive().nullish(),
|
|
890
|
+
pollTimeoutMs: z6.number().positive().nullish()
|
|
717
891
|
}).passthrough()
|
|
718
892
|
)
|
|
719
893
|
);
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
894
|
+
|
|
895
|
+
// src/alibaba-video-model.ts
|
|
896
|
+
var alibabaVideoErrorSchema = z7.object({
|
|
897
|
+
code: z7.string().nullish(),
|
|
898
|
+
message: z7.string(),
|
|
899
|
+
request_id: z7.string().nullish()
|
|
724
900
|
});
|
|
725
|
-
var alibabaVideoFailedResponseHandler = (
|
|
901
|
+
var alibabaVideoFailedResponseHandler = createJsonErrorResponseHandler3({
|
|
726
902
|
errorSchema: alibabaVideoErrorSchema,
|
|
727
903
|
errorToMessage: (data) => data.message
|
|
728
904
|
});
|
|
729
|
-
var alibabaVideoCreateTaskSchema =
|
|
730
|
-
output:
|
|
731
|
-
task_status:
|
|
732
|
-
task_id:
|
|
905
|
+
var alibabaVideoCreateTaskSchema = z7.object({
|
|
906
|
+
output: z7.object({
|
|
907
|
+
task_status: z7.string(),
|
|
908
|
+
task_id: z7.string()
|
|
733
909
|
}).nullish(),
|
|
734
|
-
request_id:
|
|
910
|
+
request_id: z7.string().nullish()
|
|
735
911
|
});
|
|
736
|
-
var alibabaVideoTaskStatusSchema =
|
|
737
|
-
output:
|
|
738
|
-
task_id:
|
|
739
|
-
task_status:
|
|
740
|
-
video_url:
|
|
741
|
-
submit_time:
|
|
742
|
-
scheduled_time:
|
|
743
|
-
end_time:
|
|
744
|
-
orig_prompt:
|
|
745
|
-
actual_prompt:
|
|
746
|
-
code:
|
|
747
|
-
message:
|
|
912
|
+
var alibabaVideoTaskStatusSchema = z7.object({
|
|
913
|
+
output: z7.object({
|
|
914
|
+
task_id: z7.string(),
|
|
915
|
+
task_status: z7.string(),
|
|
916
|
+
video_url: z7.string().nullish(),
|
|
917
|
+
submit_time: z7.string().nullish(),
|
|
918
|
+
scheduled_time: z7.string().nullish(),
|
|
919
|
+
end_time: z7.string().nullish(),
|
|
920
|
+
orig_prompt: z7.string().nullish(),
|
|
921
|
+
actual_prompt: z7.string().nullish(),
|
|
922
|
+
code: z7.string().nullish(),
|
|
923
|
+
message: z7.string().nullish()
|
|
748
924
|
}).nullish(),
|
|
749
|
-
usage:
|
|
750
|
-
duration:
|
|
751
|
-
output_video_duration:
|
|
752
|
-
SR:
|
|
753
|
-
size:
|
|
925
|
+
usage: z7.object({
|
|
926
|
+
duration: z7.number().nullish(),
|
|
927
|
+
output_video_duration: z7.number().nullish(),
|
|
928
|
+
SR: z7.number().nullish(),
|
|
929
|
+
size: z7.string().nullish()
|
|
754
930
|
}).nullish(),
|
|
755
|
-
request_id:
|
|
931
|
+
request_id: z7.string().nullish()
|
|
756
932
|
});
|
|
757
933
|
function detectMode(modelId) {
|
|
758
934
|
if (modelId.includes("-i2v")) return "i2v";
|
|
@@ -774,7 +950,7 @@ var AlibabaVideoModel = class {
|
|
|
774
950
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
775
951
|
const warnings = [];
|
|
776
952
|
const mode = detectMode(this.modelId);
|
|
777
|
-
const alibabaOptions = await (
|
|
953
|
+
const alibabaOptions = await parseProviderOptions3({
|
|
778
954
|
provider: "alibaba",
|
|
779
955
|
providerOptions: options.providerOptions,
|
|
780
956
|
schema: alibabaVideoModelOptionsSchema
|
|
@@ -793,7 +969,7 @@ var AlibabaVideoModel = class {
|
|
|
793
969
|
if (options.image.type === "url") {
|
|
794
970
|
input.img_url = options.image.url;
|
|
795
971
|
} else {
|
|
796
|
-
const base64Data = typeof options.image.data === "string" ? options.image.data :
|
|
972
|
+
const base64Data = typeof options.image.data === "string" ? options.image.data : convertUint8ArrayToBase64(options.image.data);
|
|
797
973
|
input.img_url = base64Data;
|
|
798
974
|
}
|
|
799
975
|
}
|
|
@@ -862,10 +1038,10 @@ var AlibabaVideoModel = class {
|
|
|
862
1038
|
details: "Alibaba video models only support generating 1 video per call."
|
|
863
1039
|
});
|
|
864
1040
|
}
|
|
865
|
-
const { value: createResponse } = await (
|
|
1041
|
+
const { value: createResponse } = await postJsonToApi3({
|
|
866
1042
|
url: `${this.config.baseURL}/api/v1/services/aigc/video-generation/video-synthesis`,
|
|
867
|
-
headers: (
|
|
868
|
-
await
|
|
1043
|
+
headers: combineHeaders3(
|
|
1044
|
+
await resolve(this.config.headers),
|
|
869
1045
|
options.headers,
|
|
870
1046
|
{
|
|
871
1047
|
"X-DashScope-Async": "enable"
|
|
@@ -876,7 +1052,7 @@ var AlibabaVideoModel = class {
|
|
|
876
1052
|
input,
|
|
877
1053
|
parameters
|
|
878
1054
|
},
|
|
879
|
-
successfulResponseHandler: (
|
|
1055
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
880
1056
|
alibabaVideoCreateTaskSchema
|
|
881
1057
|
),
|
|
882
1058
|
failedResponseHandler: alibabaVideoFailedResponseHandler,
|
|
@@ -885,7 +1061,7 @@ var AlibabaVideoModel = class {
|
|
|
885
1061
|
});
|
|
886
1062
|
const taskId = (_d = createResponse.output) == null ? void 0 : _d.task_id;
|
|
887
1063
|
if (!taskId) {
|
|
888
|
-
throw new
|
|
1064
|
+
throw new AISDKError({
|
|
889
1065
|
name: "ALIBABA_VIDEO_GENERATION_ERROR",
|
|
890
1066
|
message: `No task_id returned from Alibaba API. Response: ${JSON.stringify(createResponse)}`
|
|
891
1067
|
});
|
|
@@ -896,20 +1072,20 @@ var AlibabaVideoModel = class {
|
|
|
896
1072
|
let finalResponse;
|
|
897
1073
|
let responseHeaders;
|
|
898
1074
|
while (true) {
|
|
899
|
-
await
|
|
1075
|
+
await delay(pollIntervalMs, { abortSignal: options.abortSignal });
|
|
900
1076
|
if (Date.now() - startTime > pollTimeoutMs) {
|
|
901
|
-
throw new
|
|
1077
|
+
throw new AISDKError({
|
|
902
1078
|
name: "ALIBABA_VIDEO_GENERATION_TIMEOUT",
|
|
903
1079
|
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
904
1080
|
});
|
|
905
1081
|
}
|
|
906
|
-
const { value: statusResponse, responseHeaders: pollHeaders } = await
|
|
1082
|
+
const { value: statusResponse, responseHeaders: pollHeaders } = await getFromApi({
|
|
907
1083
|
url: `${this.config.baseURL}/api/v1/tasks/${taskId}`,
|
|
908
|
-
headers: (
|
|
909
|
-
await
|
|
1084
|
+
headers: combineHeaders3(
|
|
1085
|
+
await resolve(this.config.headers),
|
|
910
1086
|
options.headers
|
|
911
1087
|
),
|
|
912
|
-
successfulResponseHandler: (
|
|
1088
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
913
1089
|
alibabaVideoTaskStatusSchema
|
|
914
1090
|
),
|
|
915
1091
|
failedResponseHandler: alibabaVideoFailedResponseHandler,
|
|
@@ -923,7 +1099,7 @@ var AlibabaVideoModel = class {
|
|
|
923
1099
|
break;
|
|
924
1100
|
}
|
|
925
1101
|
if (taskStatus === "FAILED" || taskStatus === "CANCELED") {
|
|
926
|
-
throw new
|
|
1102
|
+
throw new AISDKError({
|
|
927
1103
|
name: "ALIBABA_VIDEO_GENERATION_FAILED",
|
|
928
1104
|
message: `Video generation ${taskStatus.toLowerCase()}. Task ID: ${taskId}. ${(_i = (_h = statusResponse.output) == null ? void 0 : _h.message) != null ? _i : ""}`
|
|
929
1105
|
});
|
|
@@ -931,7 +1107,7 @@ var AlibabaVideoModel = class {
|
|
|
931
1107
|
}
|
|
932
1108
|
const videoUrl = (_j = finalResponse == null ? void 0 : finalResponse.output) == null ? void 0 : _j.video_url;
|
|
933
1109
|
if (!videoUrl) {
|
|
934
|
-
throw new
|
|
1110
|
+
throw new AISDKError({
|
|
935
1111
|
name: "ALIBABA_VIDEO_GENERATION_ERROR",
|
|
936
1112
|
message: `No video URL in response. Task ID: ${taskId}`
|
|
937
1113
|
});
|
|
@@ -970,27 +1146,17 @@ var AlibabaVideoModel = class {
|
|
|
970
1146
|
};
|
|
971
1147
|
|
|
972
1148
|
// src/version.ts
|
|
973
|
-
var VERSION = "2.0.0-beta.
|
|
1149
|
+
var VERSION = true ? "2.0.0-beta.60" : "0.0.0-test";
|
|
974
1150
|
|
|
975
1151
|
// src/alibaba-provider.ts
|
|
976
|
-
var alibabaErrorDataSchema = import_v44.z.object({
|
|
977
|
-
error: import_v44.z.object({
|
|
978
|
-
message: import_v44.z.string(),
|
|
979
|
-
code: import_v44.z.string().nullish(),
|
|
980
|
-
type: import_v44.z.string().nullish()
|
|
981
|
-
})
|
|
982
|
-
});
|
|
983
|
-
var alibabaFailedResponseHandler = (0, import_provider_utils4.createJsonErrorResponseHandler)({
|
|
984
|
-
errorSchema: alibabaErrorDataSchema,
|
|
985
|
-
errorToMessage: (data) => data.error.message
|
|
986
|
-
});
|
|
987
1152
|
function createAlibaba(options = {}) {
|
|
988
|
-
var _a, _b;
|
|
989
|
-
const baseURL = (_a =
|
|
990
|
-
const videoBaseURL = (_b =
|
|
991
|
-
const
|
|
1153
|
+
var _a, _b, _c;
|
|
1154
|
+
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://dashscope-intl.aliyuncs.com/compatible-mode/v1";
|
|
1155
|
+
const videoBaseURL = (_b = withoutTrailingSlash(options.videoBaseURL)) != null ? _b : "https://dashscope-intl.aliyuncs.com";
|
|
1156
|
+
const embeddingBaseURL = (_c = withoutTrailingSlash(options.embeddingBaseURL)) != null ? _c : "https://dashscope-intl.aliyuncs.com/api/v1";
|
|
1157
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
992
1158
|
{
|
|
993
|
-
Authorization: `Bearer ${
|
|
1159
|
+
Authorization: `Bearer ${loadApiKey({
|
|
994
1160
|
apiKey: options.apiKey,
|
|
995
1161
|
environmentVariableName: "ALIBABA_API_KEY",
|
|
996
1162
|
description: "Alibaba Cloud (DashScope)"
|
|
@@ -1001,7 +1167,7 @@ function createAlibaba(options = {}) {
|
|
|
1001
1167
|
);
|
|
1002
1168
|
const createLanguageModel = (modelId) => {
|
|
1003
1169
|
var _a2;
|
|
1004
|
-
return new
|
|
1170
|
+
return new AlibabaChatLanguageModel(modelId, {
|
|
1005
1171
|
provider: "alibaba.chat",
|
|
1006
1172
|
baseURL,
|
|
1007
1173
|
headers: getHeaders,
|
|
@@ -1009,6 +1175,12 @@ function createAlibaba(options = {}) {
|
|
|
1009
1175
|
includeUsage: (_a2 = options.includeUsage) != null ? _a2 : true
|
|
1010
1176
|
});
|
|
1011
1177
|
};
|
|
1178
|
+
const createEmbeddingModel = (modelId) => new AlibabaEmbeddingModel(modelId, {
|
|
1179
|
+
provider: "alibaba.embedding",
|
|
1180
|
+
baseURL: embeddingBaseURL,
|
|
1181
|
+
headers: getHeaders,
|
|
1182
|
+
fetch: options.fetch
|
|
1183
|
+
});
|
|
1012
1184
|
const createVideoModel = (modelId) => new AlibabaVideoModel(modelId, {
|
|
1013
1185
|
provider: "alibaba.video",
|
|
1014
1186
|
baseURL: videoBaseURL,
|
|
@@ -1026,21 +1198,19 @@ function createAlibaba(options = {}) {
|
|
|
1026
1198
|
provider.specificationVersion = "v4";
|
|
1027
1199
|
provider.languageModel = createLanguageModel;
|
|
1028
1200
|
provider.chatModel = createLanguageModel;
|
|
1201
|
+
provider.embedding = createEmbeddingModel;
|
|
1202
|
+
provider.embeddingModel = createEmbeddingModel;
|
|
1029
1203
|
provider.video = createVideoModel;
|
|
1030
1204
|
provider.videoModel = createVideoModel;
|
|
1031
1205
|
provider.imageModel = (modelId) => {
|
|
1032
|
-
throw new
|
|
1033
|
-
};
|
|
1034
|
-
provider.embeddingModel = (modelId) => {
|
|
1035
|
-
throw new import_provider4.NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
1206
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
1036
1207
|
};
|
|
1037
1208
|
return provider;
|
|
1038
1209
|
}
|
|
1039
1210
|
var alibaba = createAlibaba();
|
|
1040
|
-
|
|
1041
|
-
0 && (module.exports = {
|
|
1211
|
+
export {
|
|
1042
1212
|
VERSION,
|
|
1043
1213
|
alibaba,
|
|
1044
1214
|
createAlibaba
|
|
1045
|
-
}
|
|
1215
|
+
};
|
|
1046
1216
|
//# sourceMappingURL=index.js.map
|