@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/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
- var import_provider4 = require("@ai-sdk/provider");
31
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
32
- var import_v44 = require("zod/v4");
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
- var import_internal2 = require("@ai-sdk/openai-compatible/internal");
36
- var import_provider2 = require("@ai-sdk/provider");
37
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
38
- var import_v42 = require("zod/v4");
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
- var import_v4 = require("zod/v4");
42
- var alibabaLanguageModelOptions = import_v4.z.object({
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: import_v4.z.boolean().optional(),
42
+ enableThinking: z.boolean().optional(),
50
43
  /**
51
44
  * Maximum number of reasoning tokens to generate.
52
45
  */
53
- thinkingBudget: import_v4.z.number().positive().optional(),
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: import_v4.z.boolean().optional()
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
- var import_internal = require("@ai-sdk/openai-compatible/internal");
71
+ import { convertOpenAICompatibleChatUsage } from "@ai-sdk/openai-compatible/internal";
64
72
  function convertAlibabaUsage(usage) {
65
73
  var _a, _b, _c, _d;
66
- const baseUsage = (0, import_internal.convertOpenAICompatibleChatUsage)(usage);
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,13 +85,24 @@ function convertAlibabaUsage(usage) {
77
85
  }
78
86
 
79
87
  // src/convert-to-alibaba-chat-messages.ts
80
- var import_provider = require("@ai-sdk/provider");
81
- var import_provider_utils = require("@ai-sdk/provider-utils");
82
- function formatImageUrl({
83
- data,
84
- mediaType
85
- }) {
86
- return data instanceof URL ? data.toString() : `data:${mediaType};base64,${(0, import_provider_utils.convertToBase64)(data)}`;
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,
@@ -129,19 +148,33 @@ function convertToAlibabaChatMessages({
129
148
  };
130
149
  }
131
150
  case "file": {
132
- if (part.mediaType.startsWith("image/")) {
133
- const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
134
- return {
135
- type: "image_url",
136
- image_url: {
137
- url: formatImageUrl({ data: part.data, mediaType })
138
- },
139
- ...partCacheControl ? { cache_control: partCacheControl } : {}
140
- };
141
- } else {
142
- throw new import_provider.UnsupportedFunctionalityError({
143
- functionality: "Only image file parts are supported"
144
- });
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
+ }
145
178
  }
146
179
  }
147
180
  }
@@ -200,7 +233,7 @@ function convertToAlibabaChatMessages({
200
233
  contentValue = output.value;
201
234
  break;
202
235
  case "execution-denied":
203
- contentValue = (_b = output.reason) != null ? _b : "Tool execution denied.";
236
+ contentValue = (_b = output.reason) != null ? _b : "Tool call execution denied.";
204
237
  break;
205
238
  case "content":
206
239
  case "json":
@@ -264,7 +297,7 @@ var CacheControlValidator = class {
264
297
  };
265
298
 
266
299
  // src/alibaba-chat-language-model.ts
267
- var AlibabaLanguageModel = class {
300
+ var AlibabaChatLanguageModel = class _AlibabaChatLanguageModel {
268
301
  constructor(modelId, config) {
269
302
  this.specificationVersion = "v4";
270
303
  this.supportedUrls = {
@@ -273,6 +306,15 @@ var AlibabaLanguageModel = class {
273
306
  this.modelId = modelId;
274
307
  this.config = config;
275
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
+ }
276
318
  get provider() {
277
319
  return this.config.provider;
278
320
  }
@@ -291,6 +333,7 @@ var AlibabaLanguageModel = class {
291
333
  stopSequences,
292
334
  responseFormat,
293
335
  seed,
336
+ reasoning,
294
337
  providerOptions,
295
338
  tools,
296
339
  toolChoice
@@ -298,10 +341,10 @@ var AlibabaLanguageModel = class {
298
341
  var _a;
299
342
  const warnings = [];
300
343
  const cacheControlValidator = new CacheControlValidator();
301
- const alibabaOptions = await (0, import_provider_utils2.parseProviderOptions)({
344
+ const alibabaOptions = await parseProviderOptions({
302
345
  provider: "alibaba",
303
346
  providerOptions,
304
- schema: alibabaLanguageModelOptions
347
+ schema: alibabaLanguageModelChatOptions
305
348
  });
306
349
  if (frequencyPenalty != null) {
307
350
  warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
@@ -323,9 +366,11 @@ var AlibabaLanguageModel = class {
323
366
  description: responseFormat.description
324
367
  }
325
368
  } : { type: "json_object" } : void 0,
326
- // Alibaba-specific options
327
- ...(alibabaOptions == null ? void 0 : alibabaOptions.enableThinking) != null ? { enable_thinking: alibabaOptions.enableThinking } : {},
328
- ...(alibabaOptions == null ? void 0 : alibabaOptions.thinkingBudget) != null ? { thinking_budget: alibabaOptions.thinkingBudget } : {},
369
+ ...resolveAlibabaThinking({
370
+ reasoning,
371
+ alibabaOptions,
372
+ warnings
373
+ }),
329
374
  // Convert messages with cache control support
330
375
  messages: convertToAlibabaChatMessages({
331
376
  prompt,
@@ -336,7 +381,7 @@ var AlibabaLanguageModel = class {
336
381
  tools: alibabaTools,
337
382
  toolChoice: alibabaToolChoice,
338
383
  toolWarnings
339
- } = (0, import_internal2.prepareTools)({ tools, toolChoice });
384
+ } = prepareTools({ tools, toolChoice });
340
385
  warnings.push(...cacheControlValidator.getWarnings());
341
386
  return {
342
387
  args: {
@@ -349,18 +394,18 @@ var AlibabaLanguageModel = class {
349
394
  };
350
395
  }
351
396
  async doGenerate(options) {
352
- var _a;
397
+ var _a, _b, _c, _d;
353
398
  const { args, warnings } = await this.getArgs(options);
354
399
  const {
355
400
  responseHeaders,
356
401
  value: response,
357
402
  rawValue: rawResponse
358
- } = await (0, import_provider_utils2.postJsonToApi)({
403
+ } = await postJsonToApi({
359
404
  url: `${this.config.baseURL}/chat/completions`,
360
- headers: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.headers),
405
+ headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
361
406
  body: args,
362
407
  failedResponseHandler: alibabaFailedResponseHandler,
363
- successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(
408
+ successfulResponseHandler: createJsonResponseHandler(
364
409
  alibabaChatResponseSchema
365
410
  ),
366
411
  abortSignal: options.abortSignal,
@@ -383,7 +428,7 @@ var AlibabaLanguageModel = class {
383
428
  for (const toolCall of choice.message.tool_calls) {
384
429
  content.push({
385
430
  type: "tool-call",
386
- toolCallId: toolCall.id,
431
+ toolCallId: (_c = toolCall.id) != null ? _c : generateId(),
387
432
  toolName: toolCall.function.name,
388
433
  input: toolCall.function.arguments
389
434
  });
@@ -392,13 +437,13 @@ var AlibabaLanguageModel = class {
392
437
  return {
393
438
  content,
394
439
  finishReason: {
395
- unified: (0, import_internal2.mapOpenAICompatibleFinishReason)(choice.finish_reason),
396
- raw: (_a = choice.finish_reason) != null ? _a : void 0
440
+ unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
441
+ raw: (_d = choice.finish_reason) != null ? _d : void 0
397
442
  },
398
443
  usage: convertAlibabaUsage(response.usage),
399
444
  request: { body: JSON.stringify(args) },
400
445
  response: {
401
- ...(0, import_internal2.getResponseMetadata)(response),
446
+ ...getResponseMetadata(response),
402
447
  headers: responseHeaders,
403
448
  body: rawResponse
404
449
  },
@@ -406,18 +451,19 @@ var AlibabaLanguageModel = class {
406
451
  };
407
452
  }
408
453
  async doStream(options) {
454
+ var _a, _b;
409
455
  const { args, warnings } = await this.getArgs(options);
410
456
  const body = {
411
457
  ...args,
412
458
  stream: true,
413
459
  stream_options: this.config.includeUsage ? { include_usage: true } : void 0
414
460
  };
415
- const { responseHeaders, value: response } = await (0, import_provider_utils2.postJsonToApi)({
461
+ const { responseHeaders, value: response } = await postJsonToApi({
416
462
  url: `${this.config.baseURL}/chat/completions`,
417
- headers: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.headers),
463
+ headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
418
464
  body,
419
465
  failedResponseHandler: alibabaFailedResponseHandler,
420
- successfulResponseHandler: (0, import_provider_utils2.createEventSourceResponseHandler)(
466
+ successfulResponseHandler: createEventSourceResponseHandler(
421
467
  alibabaChatChunkSchema
422
468
  ),
423
469
  abortSignal: options.abortSignal,
@@ -431,15 +477,17 @@ var AlibabaLanguageModel = class {
431
477
  let isFirstChunk = true;
432
478
  let activeText = false;
433
479
  let activeReasoningId = null;
434
- const toolCalls = [];
480
+ let toolCallTracker;
435
481
  return {
436
482
  stream: response.pipeThrough(
437
483
  new TransformStream({
438
484
  start(controller) {
485
+ toolCallTracker = new StreamingToolCallTracker(controller, {
486
+ generateId
487
+ });
439
488
  controller.enqueue({ type: "stream-start", warnings });
440
489
  },
441
490
  transform(chunk, controller) {
442
- var _a, _b, _c, _d;
443
491
  if (options.includeRawChunks) {
444
492
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
445
493
  }
@@ -452,7 +500,7 @@ var AlibabaLanguageModel = class {
452
500
  isFirstChunk = false;
453
501
  controller.enqueue({
454
502
  type: "response-metadata",
455
- ...(0, import_internal2.getResponseMetadata)(value)
503
+ ...getResponseMetadata(value)
456
504
  });
457
505
  }
458
506
  if (value.usage != null) {
@@ -469,7 +517,7 @@ var AlibabaLanguageModel = class {
469
517
  controller.enqueue({ type: "text-end", id: "0" });
470
518
  activeText = false;
471
519
  }
472
- activeReasoningId = (0, import_provider_utils2.generateId)();
520
+ activeReasoningId = generateId();
473
521
  controller.enqueue({
474
522
  type: "reasoning-start",
475
523
  id: activeReasoningId
@@ -512,87 +560,12 @@ var AlibabaLanguageModel = class {
512
560
  activeText = false;
513
561
  }
514
562
  for (const toolCallDelta of delta.tool_calls) {
515
- const index = (_a = toolCallDelta.index) != null ? _a : toolCalls.length;
516
- if (toolCalls[index] == null) {
517
- if (toolCallDelta.id == null) {
518
- throw new import_provider2.InvalidResponseDataError({
519
- data: toolCallDelta,
520
- message: `Expected 'id' to be a string.`
521
- });
522
- }
523
- if (((_b = toolCallDelta.function) == null ? void 0 : _b.name) == null) {
524
- throw new import_provider2.InvalidResponseDataError({
525
- data: toolCallDelta,
526
- message: `Expected 'function.name' to be a string.`
527
- });
528
- }
529
- controller.enqueue({
530
- type: "tool-input-start",
531
- id: toolCallDelta.id,
532
- toolName: toolCallDelta.function.name
533
- });
534
- toolCalls[index] = {
535
- id: toolCallDelta.id,
536
- type: "function",
537
- function: {
538
- name: toolCallDelta.function.name,
539
- arguments: (_c = toolCallDelta.function.arguments) != null ? _c : ""
540
- },
541
- hasFinished: false
542
- };
543
- const toolCall2 = toolCalls[index];
544
- if (toolCall2.function.arguments.length > 0) {
545
- controller.enqueue({
546
- type: "tool-input-delta",
547
- id: toolCall2.id,
548
- delta: toolCall2.function.arguments
549
- });
550
- }
551
- if ((0, import_provider_utils2.isParsableJson)(toolCall2.function.arguments)) {
552
- controller.enqueue({
553
- type: "tool-input-end",
554
- id: toolCall2.id
555
- });
556
- controller.enqueue({
557
- type: "tool-call",
558
- toolCallId: toolCall2.id,
559
- toolName: toolCall2.function.name,
560
- input: toolCall2.function.arguments
561
- });
562
- toolCall2.hasFinished = true;
563
- }
564
- continue;
565
- }
566
- const toolCall = toolCalls[index];
567
- if (toolCall.hasFinished) {
568
- continue;
569
- }
570
- if (((_d = toolCallDelta.function) == null ? void 0 : _d.arguments) != null) {
571
- toolCall.function.arguments += toolCallDelta.function.arguments;
572
- controller.enqueue({
573
- type: "tool-input-delta",
574
- id: toolCall.id,
575
- delta: toolCallDelta.function.arguments
576
- });
577
- }
578
- if ((0, import_provider_utils2.isParsableJson)(toolCall.function.arguments)) {
579
- controller.enqueue({
580
- type: "tool-input-end",
581
- id: toolCall.id
582
- });
583
- controller.enqueue({
584
- type: "tool-call",
585
- toolCallId: toolCall.id,
586
- toolName: toolCall.function.name,
587
- input: toolCall.function.arguments
588
- });
589
- toolCall.hasFinished = true;
590
- }
563
+ toolCallTracker.processDelta(toolCallDelta);
591
564
  }
592
565
  }
593
566
  if (choice.finish_reason != null) {
594
567
  finishReason = {
595
- unified: (0, import_internal2.mapOpenAICompatibleFinishReason)(choice.finish_reason),
568
+ unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
596
569
  raw: choice.finish_reason
597
570
  };
598
571
  }
@@ -607,6 +580,7 @@ var AlibabaLanguageModel = class {
607
580
  if (activeText) {
608
581
  controller.enqueue({ type: "text-end", id: "0" });
609
582
  }
583
+ toolCallTracker.flush();
610
584
  controller.enqueue({
611
585
  type: "finish",
612
586
  finishReason,
@@ -620,72 +594,100 @@ var AlibabaLanguageModel = class {
620
594
  };
621
595
  }
622
596
  };
623
- var alibabaUsageSchema = import_v42.z.object({
624
- prompt_tokens: import_v42.z.number(),
625
- completion_tokens: import_v42.z.number(),
626
- total_tokens: import_v42.z.number(),
627
- prompt_tokens_details: import_v42.z.object({
628
- cached_tokens: import_v42.z.number().nullish(),
629
- cache_creation_input_tokens: import_v42.z.number().nullish()
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()
630
632
  }).nullish(),
631
- completion_tokens_details: import_v42.z.object({
632
- reasoning_tokens: import_v42.z.number().nullish()
633
+ completion_tokens_details: z3.object({
634
+ reasoning_tokens: z3.number().nullish()
633
635
  }).nullish()
634
636
  });
635
- var alibabaChatResponseSchema = import_v42.z.object({
636
- id: import_v42.z.string().nullish(),
637
- created: import_v42.z.number().nullish(),
638
- model: import_v42.z.string().nullish(),
639
- choices: import_v42.z.array(
640
- import_v42.z.object({
641
- message: import_v42.z.object({
642
- role: import_v42.z.literal("assistant").nullish(),
643
- content: import_v42.z.string().nullish(),
644
- reasoning_content: import_v42.z.string().nullish(),
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(),
645
647
  // Alibaba thinking mode
646
- tool_calls: import_v42.z.array(
647
- import_v42.z.object({
648
- id: import_v42.z.string(),
649
- type: import_v42.z.literal("function"),
650
- function: import_v42.z.object({
651
- name: import_v42.z.string(),
652
- arguments: import_v42.z.string()
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()
653
655
  })
654
656
  })
655
657
  ).nullish()
656
658
  }),
657
- finish_reason: import_v42.z.string().nullish(),
658
- index: import_v42.z.number()
659
+ finish_reason: z3.string().nullish(),
660
+ index: z3.number()
659
661
  })
660
662
  ),
661
663
  usage: alibabaUsageSchema.nullish()
662
664
  });
663
- var alibabaChatChunkSchema = import_v42.z.object({
664
- id: import_v42.z.string().nullish(),
665
- created: import_v42.z.number().nullish(),
666
- model: import_v42.z.string().nullish(),
667
- choices: import_v42.z.array(
668
- import_v42.z.object({
669
- delta: import_v42.z.object({
670
- role: import_v42.z.enum(["assistant"]).nullish(),
671
- content: import_v42.z.string().nullish(),
672
- reasoning_content: import_v42.z.string().nullish(),
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(),
673
675
  // Alibaba thinking mode delta
674
- tool_calls: import_v42.z.array(
675
- import_v42.z.object({
676
- index: import_v42.z.number().nullish(),
676
+ tool_calls: z3.array(
677
+ z3.object({
678
+ index: z3.number().nullish(),
677
679
  // Index for accumulating tool calls
678
- id: import_v42.z.string().nullish(),
679
- type: import_v42.z.literal("function").nullish(),
680
- function: import_v42.z.object({
681
- name: import_v42.z.string().nullish(),
682
- arguments: import_v42.z.string().nullish()
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()
683
685
  }).nullish()
684
686
  })
685
687
  ).nullish()
686
688
  }),
687
- finish_reason: import_v42.z.string().nullish(),
688
- index: import_v42.z.number()
689
+ finish_reason: z3.string().nullish(),
690
+ index: z3.number()
689
691
  })
690
692
  ),
691
693
  usage: alibabaUsageSchema.nullish()
@@ -693,60 +695,78 @@ var alibabaChatChunkSchema = import_v42.z.object({
693
695
  });
694
696
 
695
697
  // src/alibaba-video-model.ts
696
- var import_provider3 = require("@ai-sdk/provider");
697
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
698
- var import_v43 = require("zod/v4");
699
- var alibabaVideoModelOptionsSchema = (0, import_provider_utils3.lazySchema)(
700
- () => (0, import_provider_utils3.zodSchema)(
701
- import_v43.z.object({
702
- negativePrompt: import_v43.z.string().nullish(),
703
- audioUrl: import_v43.z.string().nullish(),
704
- promptExtend: import_v43.z.boolean().nullish(),
705
- shotType: import_v43.z.enum(["single", "multi"]).nullish(),
706
- watermark: import_v43.z.boolean().nullish(),
707
- audio: import_v43.z.boolean().nullish(),
708
- referenceUrls: import_v43.z.array(import_v43.z.string()).nullish(),
709
- pollIntervalMs: import_v43.z.number().positive().nullish(),
710
- pollTimeoutMs: import_v43.z.number().positive().nullish()
698
+ import {
699
+ AISDKError
700
+ } from "@ai-sdk/provider";
701
+ import {
702
+ combineHeaders as combineHeaders2,
703
+ convertUint8ArrayToBase64,
704
+ createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
705
+ createJsonResponseHandler as createJsonResponseHandler2,
706
+ delay,
707
+ getFromApi,
708
+ parseProviderOptions as parseProviderOptions2,
709
+ postJsonToApi as postJsonToApi2,
710
+ resolve
711
+ } from "@ai-sdk/provider-utils";
712
+ import { z as z5 } from "zod/v4";
713
+
714
+ // src/alibaba-video-model-options.ts
715
+ import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
716
+ import { z as z4 } from "zod/v4";
717
+ var alibabaVideoModelOptionsSchema = lazySchema(
718
+ () => zodSchema(
719
+ z4.object({
720
+ negativePrompt: z4.string().nullish(),
721
+ audioUrl: z4.string().nullish(),
722
+ promptExtend: z4.boolean().nullish(),
723
+ shotType: z4.enum(["single", "multi"]).nullish(),
724
+ watermark: z4.boolean().nullish(),
725
+ audio: z4.boolean().nullish(),
726
+ referenceUrls: z4.array(z4.string()).nullish(),
727
+ pollIntervalMs: z4.number().positive().nullish(),
728
+ pollTimeoutMs: z4.number().positive().nullish()
711
729
  }).passthrough()
712
730
  )
713
731
  );
714
- var alibabaVideoErrorSchema = import_v43.z.object({
715
- code: import_v43.z.string().nullish(),
716
- message: import_v43.z.string(),
717
- request_id: import_v43.z.string().nullish()
732
+
733
+ // src/alibaba-video-model.ts
734
+ var alibabaVideoErrorSchema = z5.object({
735
+ code: z5.string().nullish(),
736
+ message: z5.string(),
737
+ request_id: z5.string().nullish()
718
738
  });
719
- var alibabaVideoFailedResponseHandler = (0, import_provider_utils3.createJsonErrorResponseHandler)({
739
+ var alibabaVideoFailedResponseHandler = createJsonErrorResponseHandler2({
720
740
  errorSchema: alibabaVideoErrorSchema,
721
741
  errorToMessage: (data) => data.message
722
742
  });
723
- var alibabaVideoCreateTaskSchema = import_v43.z.object({
724
- output: import_v43.z.object({
725
- task_status: import_v43.z.string(),
726
- task_id: import_v43.z.string()
743
+ var alibabaVideoCreateTaskSchema = z5.object({
744
+ output: z5.object({
745
+ task_status: z5.string(),
746
+ task_id: z5.string()
727
747
  }).nullish(),
728
- request_id: import_v43.z.string().nullish()
748
+ request_id: z5.string().nullish()
729
749
  });
730
- var alibabaVideoTaskStatusSchema = import_v43.z.object({
731
- output: import_v43.z.object({
732
- task_id: import_v43.z.string(),
733
- task_status: import_v43.z.string(),
734
- video_url: import_v43.z.string().nullish(),
735
- submit_time: import_v43.z.string().nullish(),
736
- scheduled_time: import_v43.z.string().nullish(),
737
- end_time: import_v43.z.string().nullish(),
738
- orig_prompt: import_v43.z.string().nullish(),
739
- actual_prompt: import_v43.z.string().nullish(),
740
- code: import_v43.z.string().nullish(),
741
- message: import_v43.z.string().nullish()
750
+ var alibabaVideoTaskStatusSchema = z5.object({
751
+ output: z5.object({
752
+ task_id: z5.string(),
753
+ task_status: z5.string(),
754
+ video_url: z5.string().nullish(),
755
+ submit_time: z5.string().nullish(),
756
+ scheduled_time: z5.string().nullish(),
757
+ end_time: z5.string().nullish(),
758
+ orig_prompt: z5.string().nullish(),
759
+ actual_prompt: z5.string().nullish(),
760
+ code: z5.string().nullish(),
761
+ message: z5.string().nullish()
742
762
  }).nullish(),
743
- usage: import_v43.z.object({
744
- duration: import_v43.z.number().nullish(),
745
- output_video_duration: import_v43.z.number().nullish(),
746
- SR: import_v43.z.number().nullish(),
747
- size: import_v43.z.string().nullish()
763
+ usage: z5.object({
764
+ duration: z5.number().nullish(),
765
+ output_video_duration: z5.number().nullish(),
766
+ SR: z5.number().nullish(),
767
+ size: z5.string().nullish()
748
768
  }).nullish(),
749
- request_id: import_v43.z.string().nullish()
769
+ request_id: z5.string().nullish()
750
770
  });
751
771
  function detectMode(modelId) {
752
772
  if (modelId.includes("-i2v")) return "i2v";
@@ -768,7 +788,7 @@ var AlibabaVideoModel = class {
768
788
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
769
789
  const warnings = [];
770
790
  const mode = detectMode(this.modelId);
771
- const alibabaOptions = await (0, import_provider_utils3.parseProviderOptions)({
791
+ const alibabaOptions = await parseProviderOptions2({
772
792
  provider: "alibaba",
773
793
  providerOptions: options.providerOptions,
774
794
  schema: alibabaVideoModelOptionsSchema
@@ -787,7 +807,7 @@ var AlibabaVideoModel = class {
787
807
  if (options.image.type === "url") {
788
808
  input.img_url = options.image.url;
789
809
  } else {
790
- const base64Data = typeof options.image.data === "string" ? options.image.data : (0, import_provider_utils3.convertUint8ArrayToBase64)(options.image.data);
810
+ const base64Data = typeof options.image.data === "string" ? options.image.data : convertUint8ArrayToBase64(options.image.data);
791
811
  input.img_url = base64Data;
792
812
  }
793
813
  }
@@ -856,10 +876,10 @@ var AlibabaVideoModel = class {
856
876
  details: "Alibaba video models only support generating 1 video per call."
857
877
  });
858
878
  }
859
- const { value: createResponse } = await (0, import_provider_utils3.postJsonToApi)({
879
+ const { value: createResponse } = await postJsonToApi2({
860
880
  url: `${this.config.baseURL}/api/v1/services/aigc/video-generation/video-synthesis`,
861
- headers: (0, import_provider_utils3.combineHeaders)(
862
- await (0, import_provider_utils3.resolve)(this.config.headers),
881
+ headers: combineHeaders2(
882
+ await resolve(this.config.headers),
863
883
  options.headers,
864
884
  {
865
885
  "X-DashScope-Async": "enable"
@@ -870,7 +890,7 @@ var AlibabaVideoModel = class {
870
890
  input,
871
891
  parameters
872
892
  },
873
- successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
893
+ successfulResponseHandler: createJsonResponseHandler2(
874
894
  alibabaVideoCreateTaskSchema
875
895
  ),
876
896
  failedResponseHandler: alibabaVideoFailedResponseHandler,
@@ -879,7 +899,7 @@ var AlibabaVideoModel = class {
879
899
  });
880
900
  const taskId = (_d = createResponse.output) == null ? void 0 : _d.task_id;
881
901
  if (!taskId) {
882
- throw new import_provider3.AISDKError({
902
+ throw new AISDKError({
883
903
  name: "ALIBABA_VIDEO_GENERATION_ERROR",
884
904
  message: `No task_id returned from Alibaba API. Response: ${JSON.stringify(createResponse)}`
885
905
  });
@@ -890,20 +910,20 @@ var AlibabaVideoModel = class {
890
910
  let finalResponse;
891
911
  let responseHeaders;
892
912
  while (true) {
893
- await (0, import_provider_utils3.delay)(pollIntervalMs, { abortSignal: options.abortSignal });
913
+ await delay(pollIntervalMs, { abortSignal: options.abortSignal });
894
914
  if (Date.now() - startTime > pollTimeoutMs) {
895
- throw new import_provider3.AISDKError({
915
+ throw new AISDKError({
896
916
  name: "ALIBABA_VIDEO_GENERATION_TIMEOUT",
897
917
  message: `Video generation timed out after ${pollTimeoutMs}ms`
898
918
  });
899
919
  }
900
- const { value: statusResponse, responseHeaders: pollHeaders } = await (0, import_provider_utils3.getFromApi)({
920
+ const { value: statusResponse, responseHeaders: pollHeaders } = await getFromApi({
901
921
  url: `${this.config.baseURL}/api/v1/tasks/${taskId}`,
902
- headers: (0, import_provider_utils3.combineHeaders)(
903
- await (0, import_provider_utils3.resolve)(this.config.headers),
922
+ headers: combineHeaders2(
923
+ await resolve(this.config.headers),
904
924
  options.headers
905
925
  ),
906
- successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
926
+ successfulResponseHandler: createJsonResponseHandler2(
907
927
  alibabaVideoTaskStatusSchema
908
928
  ),
909
929
  failedResponseHandler: alibabaVideoFailedResponseHandler,
@@ -917,7 +937,7 @@ var AlibabaVideoModel = class {
917
937
  break;
918
938
  }
919
939
  if (taskStatus === "FAILED" || taskStatus === "CANCELED") {
920
- throw new import_provider3.AISDKError({
940
+ throw new AISDKError({
921
941
  name: "ALIBABA_VIDEO_GENERATION_FAILED",
922
942
  message: `Video generation ${taskStatus.toLowerCase()}. Task ID: ${taskId}. ${(_i = (_h = statusResponse.output) == null ? void 0 : _h.message) != null ? _i : ""}`
923
943
  });
@@ -925,7 +945,7 @@ var AlibabaVideoModel = class {
925
945
  }
926
946
  const videoUrl = (_j = finalResponse == null ? void 0 : finalResponse.output) == null ? void 0 : _j.video_url;
927
947
  if (!videoUrl) {
928
- throw new import_provider3.AISDKError({
948
+ throw new AISDKError({
929
949
  name: "ALIBABA_VIDEO_GENERATION_ERROR",
930
950
  message: `No video URL in response. Task ID: ${taskId}`
931
951
  });
@@ -964,27 +984,16 @@ var AlibabaVideoModel = class {
964
984
  };
965
985
 
966
986
  // src/version.ts
967
- var VERSION = "2.0.0-beta.9";
987
+ var VERSION = "2.0.0-canary.39";
968
988
 
969
989
  // src/alibaba-provider.ts
970
- var alibabaErrorDataSchema = import_v44.z.object({
971
- error: import_v44.z.object({
972
- message: import_v44.z.string(),
973
- code: import_v44.z.string().nullish(),
974
- type: import_v44.z.string().nullish()
975
- })
976
- });
977
- var alibabaFailedResponseHandler = (0, import_provider_utils4.createJsonErrorResponseHandler)({
978
- errorSchema: alibabaErrorDataSchema,
979
- errorToMessage: (data) => data.error.message
980
- });
981
990
  function createAlibaba(options = {}) {
982
991
  var _a, _b;
983
- const baseURL = (_a = (0, import_provider_utils4.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://dashscope-intl.aliyuncs.com/compatible-mode/v1";
984
- const videoBaseURL = (_b = (0, import_provider_utils4.withoutTrailingSlash)(options.videoBaseURL)) != null ? _b : "https://dashscope-intl.aliyuncs.com";
985
- const getHeaders = () => (0, import_provider_utils4.withUserAgentSuffix)(
992
+ const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://dashscope-intl.aliyuncs.com/compatible-mode/v1";
993
+ const videoBaseURL = (_b = withoutTrailingSlash(options.videoBaseURL)) != null ? _b : "https://dashscope-intl.aliyuncs.com";
994
+ const getHeaders = () => withUserAgentSuffix(
986
995
  {
987
- Authorization: `Bearer ${(0, import_provider_utils4.loadApiKey)({
996
+ Authorization: `Bearer ${loadApiKey({
988
997
  apiKey: options.apiKey,
989
998
  environmentVariableName: "ALIBABA_API_KEY",
990
999
  description: "Alibaba Cloud (DashScope)"
@@ -995,7 +1004,7 @@ function createAlibaba(options = {}) {
995
1004
  );
996
1005
  const createLanguageModel = (modelId) => {
997
1006
  var _a2;
998
- return new AlibabaLanguageModel(modelId, {
1007
+ return new AlibabaChatLanguageModel(modelId, {
999
1008
  provider: "alibaba.chat",
1000
1009
  baseURL,
1001
1010
  headers: getHeaders,
@@ -1023,18 +1032,17 @@ function createAlibaba(options = {}) {
1023
1032
  provider.video = createVideoModel;
1024
1033
  provider.videoModel = createVideoModel;
1025
1034
  provider.imageModel = (modelId) => {
1026
- throw new import_provider4.NoSuchModelError({ modelId, modelType: "imageModel" });
1035
+ throw new NoSuchModelError({ modelId, modelType: "imageModel" });
1027
1036
  };
1028
1037
  provider.embeddingModel = (modelId) => {
1029
- throw new import_provider4.NoSuchModelError({ modelId, modelType: "embeddingModel" });
1038
+ throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
1030
1039
  };
1031
1040
  return provider;
1032
1041
  }
1033
1042
  var alibaba = createAlibaba();
1034
- // Annotate the CommonJS export names for ESM import in node:
1035
- 0 && (module.exports = {
1043
+ export {
1036
1044
  VERSION,
1037
1045
  alibaba,
1038
1046
  createAlibaba
1039
- });
1047
+ };
1040
1048
  //# sourceMappingURL=index.js.map