@ai-sdk/alibaba 2.0.0-beta.3 → 2.0.0-beta.31

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,64 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- VERSION: () => VERSION,
24
- alibaba: () => alibaba,
25
- createAlibaba: () => createAlibaba
26
- });
27
- module.exports = __toCommonJS(src_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
+ createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
7
+ loadApiKey,
8
+ withoutTrailingSlash,
9
+ withUserAgentSuffix
10
+ } from "@ai-sdk/provider-utils";
11
+ import { z as z4 } from "zod/v4";
33
12
 
34
13
  // src/alibaba-chat-language-model.ts
35
- 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");
14
+ import {
15
+ getResponseMetadata,
16
+ mapOpenAICompatibleFinishReason,
17
+ prepareTools
18
+ } from "@ai-sdk/openai-compatible/internal";
19
+ import {
20
+ combineHeaders,
21
+ createEventSourceResponseHandler,
22
+ createJsonResponseHandler,
23
+ generateId,
24
+ isCustomReasoning,
25
+ mapReasoningToProviderBudget,
26
+ parseProviderOptions,
27
+ postJsonToApi,
28
+ serializeModelOptions,
29
+ StreamingToolCallTracker,
30
+ WORKFLOW_SERIALIZE,
31
+ WORKFLOW_DESERIALIZE
32
+ } from "@ai-sdk/provider-utils";
33
+ import { z as z2 } from "zod/v4";
39
34
 
40
35
  // src/alibaba-chat-options.ts
41
- var import_v4 = require("zod/v4");
42
- var alibabaLanguageModelOptions = import_v4.z.object({
36
+ import { z } from "zod/v4";
37
+ var alibabaLanguageModelOptions = z.object({
43
38
  /**
44
39
  * Enable thinking/reasoning mode for supported models.
45
40
  * When enabled, the model generates reasoning content before the response.
46
41
  *
47
42
  * @default false
48
43
  */
49
- enableThinking: import_v4.z.boolean().optional(),
44
+ enableThinking: z.boolean().optional(),
50
45
  /**
51
46
  * Maximum number of reasoning tokens to generate.
52
47
  */
53
- thinkingBudget: import_v4.z.number().positive().optional(),
48
+ thinkingBudget: z.number().positive().optional(),
54
49
  /**
55
50
  * Whether to enable parallel function calling during tool use.
56
51
  *
57
52
  * @default true
58
53
  */
59
- parallelToolCalls: import_v4.z.boolean().optional()
54
+ parallelToolCalls: z.boolean().optional()
60
55
  });
61
56
 
62
57
  // src/convert-alibaba-usage.ts
63
- var import_internal = require("@ai-sdk/openai-compatible/internal");
58
+ import { convertOpenAICompatibleChatUsage } from "@ai-sdk/openai-compatible/internal";
64
59
  function convertAlibabaUsage(usage) {
65
60
  var _a, _b, _c, _d;
66
- const baseUsage = (0, import_internal.convertOpenAICompatibleChatUsage)(usage);
61
+ const baseUsage = convertOpenAICompatibleChatUsage(usage);
67
62
  const cacheWriteTokens = (_b = (_a = usage == null ? void 0 : usage.prompt_tokens_details) == null ? void 0 : _a.cache_creation_input_tokens) != null ? _b : 0;
68
63
  const noCacheTokens = ((_c = baseUsage.inputTokens.total) != null ? _c : 0) - ((_d = baseUsage.inputTokens.cacheRead) != null ? _d : 0) - cacheWriteTokens;
69
64
  return {
@@ -77,19 +72,21 @@ function convertAlibabaUsage(usage) {
77
72
  }
78
73
 
79
74
  // 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");
75
+ import {
76
+ UnsupportedFunctionalityError
77
+ } from "@ai-sdk/provider";
78
+ import { convertToBase64, isProviderReference } from "@ai-sdk/provider-utils";
82
79
  function formatImageUrl({
83
80
  data,
84
81
  mediaType
85
82
  }) {
86
- return data instanceof URL ? data.toString() : `data:${mediaType};base64,${(0, import_provider_utils.convertToBase64)(data)}`;
83
+ return data instanceof URL ? data.toString() : `data:${mediaType};base64,${convertToBase64(data)}`;
87
84
  }
88
85
  function convertToAlibabaChatMessages({
89
86
  prompt,
90
87
  cacheControlValidator
91
88
  }) {
92
- var _a;
89
+ var _a, _b;
93
90
  const messages = [];
94
91
  for (const { role, content, ...message } of prompt) {
95
92
  const messageCacheControl = cacheControlValidator == null ? void 0 : cacheControlValidator.getCacheControl(
@@ -114,18 +111,12 @@ function convertToAlibabaChatMessages({
114
111
  break;
115
112
  }
116
113
  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
114
  messages.push({
126
115
  role: "user",
127
- content: content.map((part) => {
128
- const partCacheControl = isSinglePart ? messageCacheControl : cacheControlValidator == null ? void 0 : cacheControlValidator.getCacheControl(part.providerOptions);
116
+ content: content.map((part, index) => {
117
+ var _a2;
118
+ const isLastPart = index === content.length - 1;
119
+ const partCacheControl = (_a2 = cacheControlValidator == null ? void 0 : cacheControlValidator.getCacheControl(part.providerOptions)) != null ? _a2 : isLastPart ? messageCacheControl : void 0;
129
120
  switch (part.type) {
130
121
  case "text": {
131
122
  return {
@@ -135,6 +126,11 @@ function convertToAlibabaChatMessages({
135
126
  };
136
127
  }
137
128
  case "file": {
129
+ if (isProviderReference(part.data)) {
130
+ throw new UnsupportedFunctionalityError({
131
+ functionality: "file parts with provider references"
132
+ });
133
+ }
138
134
  if (part.mediaType.startsWith("image/")) {
139
135
  const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
140
136
  return {
@@ -145,7 +141,7 @@ function convertToAlibabaChatMessages({
145
141
  ...partCacheControl ? { cache_control: partCacheControl } : {}
146
142
  };
147
143
  } else {
148
- throw new import_provider.UnsupportedFunctionalityError({
144
+ throw new UnsupportedFunctionalityError({
149
145
  functionality: "Only image file parts are supported"
150
146
  });
151
147
  }
@@ -192,13 +188,13 @@ function convertToAlibabaChatMessages({
192
188
  const toolResponses = content.filter(
193
189
  (r) => r.type !== "tool-approval-response"
194
190
  );
195
- const isSinglePart = toolResponses.length === 1;
196
191
  for (let i = 0; i < toolResponses.length; i++) {
197
192
  const toolResponse = toolResponses[i];
198
193
  const output = toolResponse.output;
199
- const partCacheControl = isSinglePart ? messageCacheControl : cacheControlValidator == null ? void 0 : cacheControlValidator.getCacheControl(
194
+ const isLastPart = i === toolResponses.length - 1;
195
+ const partCacheControl = (_a = cacheControlValidator == null ? void 0 : cacheControlValidator.getCacheControl(
200
196
  toolResponse.providerOptions
201
- );
197
+ )) != null ? _a : isLastPart ? messageCacheControl : void 0;
202
198
  let contentValue;
203
199
  switch (output.type) {
204
200
  case "text":
@@ -206,7 +202,7 @@ function convertToAlibabaChatMessages({
206
202
  contentValue = output.value;
207
203
  break;
208
204
  case "execution-denied":
209
- contentValue = (_a = output.reason) != null ? _a : "Tool execution denied.";
205
+ contentValue = (_b = output.reason) != null ? _b : "Tool execution denied.";
210
206
  break;
211
207
  case "content":
212
208
  case "json":
@@ -270,7 +266,7 @@ var CacheControlValidator = class {
270
266
  };
271
267
 
272
268
  // src/alibaba-chat-language-model.ts
273
- var AlibabaLanguageModel = class {
269
+ var AlibabaLanguageModel = class _AlibabaLanguageModel {
274
270
  constructor(modelId, config) {
275
271
  this.specificationVersion = "v4";
276
272
  this.supportedUrls = {
@@ -279,6 +275,15 @@ var AlibabaLanguageModel = class {
279
275
  this.modelId = modelId;
280
276
  this.config = config;
281
277
  }
278
+ static [WORKFLOW_SERIALIZE](model) {
279
+ return serializeModelOptions({
280
+ modelId: model.modelId,
281
+ config: model.config
282
+ });
283
+ }
284
+ static [WORKFLOW_DESERIALIZE](options) {
285
+ return new _AlibabaLanguageModel(options.modelId, options.config);
286
+ }
282
287
  get provider() {
283
288
  return this.config.provider;
284
289
  }
@@ -297,6 +302,7 @@ var AlibabaLanguageModel = class {
297
302
  stopSequences,
298
303
  responseFormat,
299
304
  seed,
305
+ reasoning,
300
306
  providerOptions,
301
307
  tools,
302
308
  toolChoice
@@ -304,7 +310,7 @@ var AlibabaLanguageModel = class {
304
310
  var _a;
305
311
  const warnings = [];
306
312
  const cacheControlValidator = new CacheControlValidator();
307
- const alibabaOptions = await (0, import_provider_utils2.parseProviderOptions)({
313
+ const alibabaOptions = await parseProviderOptions({
308
314
  provider: "alibaba",
309
315
  providerOptions,
310
316
  schema: alibabaLanguageModelOptions
@@ -329,9 +335,11 @@ var AlibabaLanguageModel = class {
329
335
  description: responseFormat.description
330
336
  }
331
337
  } : { type: "json_object" } : void 0,
332
- // Alibaba-specific options
333
- ...(alibabaOptions == null ? void 0 : alibabaOptions.enableThinking) != null ? { enable_thinking: alibabaOptions.enableThinking } : {},
334
- ...(alibabaOptions == null ? void 0 : alibabaOptions.thinkingBudget) != null ? { thinking_budget: alibabaOptions.thinkingBudget } : {},
338
+ ...resolveAlibabaThinking({
339
+ reasoning,
340
+ alibabaOptions,
341
+ warnings
342
+ }),
335
343
  // Convert messages with cache control support
336
344
  messages: convertToAlibabaChatMessages({
337
345
  prompt,
@@ -342,7 +350,7 @@ var AlibabaLanguageModel = class {
342
350
  tools: alibabaTools,
343
351
  toolChoice: alibabaToolChoice,
344
352
  toolWarnings
345
- } = (0, import_internal2.prepareTools)({ tools, toolChoice });
353
+ } = prepareTools({ tools, toolChoice });
346
354
  warnings.push(...cacheControlValidator.getWarnings());
347
355
  return {
348
356
  args: {
@@ -355,18 +363,18 @@ var AlibabaLanguageModel = class {
355
363
  };
356
364
  }
357
365
  async doGenerate(options) {
358
- var _a;
366
+ var _a, _b, _c, _d;
359
367
  const { args, warnings } = await this.getArgs(options);
360
368
  const {
361
369
  responseHeaders,
362
370
  value: response,
363
371
  rawValue: rawResponse
364
- } = await (0, import_provider_utils2.postJsonToApi)({
372
+ } = await postJsonToApi({
365
373
  url: `${this.config.baseURL}/chat/completions`,
366
- headers: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.headers),
374
+ headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
367
375
  body: args,
368
376
  failedResponseHandler: alibabaFailedResponseHandler,
369
- successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(
377
+ successfulResponseHandler: createJsonResponseHandler(
370
378
  alibabaChatResponseSchema
371
379
  ),
372
380
  abortSignal: options.abortSignal,
@@ -389,7 +397,7 @@ var AlibabaLanguageModel = class {
389
397
  for (const toolCall of choice.message.tool_calls) {
390
398
  content.push({
391
399
  type: "tool-call",
392
- toolCallId: toolCall.id,
400
+ toolCallId: (_c = toolCall.id) != null ? _c : generateId(),
393
401
  toolName: toolCall.function.name,
394
402
  input: toolCall.function.arguments
395
403
  });
@@ -398,13 +406,13 @@ var AlibabaLanguageModel = class {
398
406
  return {
399
407
  content,
400
408
  finishReason: {
401
- unified: (0, import_internal2.mapOpenAICompatibleFinishReason)(choice.finish_reason),
402
- raw: (_a = choice.finish_reason) != null ? _a : void 0
409
+ unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
410
+ raw: (_d = choice.finish_reason) != null ? _d : void 0
403
411
  },
404
412
  usage: convertAlibabaUsage(response.usage),
405
413
  request: { body: JSON.stringify(args) },
406
414
  response: {
407
- ...(0, import_internal2.getResponseMetadata)(response),
415
+ ...getResponseMetadata(response),
408
416
  headers: responseHeaders,
409
417
  body: rawResponse
410
418
  },
@@ -412,18 +420,19 @@ var AlibabaLanguageModel = class {
412
420
  };
413
421
  }
414
422
  async doStream(options) {
423
+ var _a, _b;
415
424
  const { args, warnings } = await this.getArgs(options);
416
425
  const body = {
417
426
  ...args,
418
427
  stream: true,
419
428
  stream_options: this.config.includeUsage ? { include_usage: true } : void 0
420
429
  };
421
- const { responseHeaders, value: response } = await (0, import_provider_utils2.postJsonToApi)({
430
+ const { responseHeaders, value: response } = await postJsonToApi({
422
431
  url: `${this.config.baseURL}/chat/completions`,
423
- headers: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.headers),
432
+ headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
424
433
  body,
425
434
  failedResponseHandler: alibabaFailedResponseHandler,
426
- successfulResponseHandler: (0, import_provider_utils2.createEventSourceResponseHandler)(
435
+ successfulResponseHandler: createEventSourceResponseHandler(
427
436
  alibabaChatChunkSchema
428
437
  ),
429
438
  abortSignal: options.abortSignal,
@@ -437,7 +446,7 @@ var AlibabaLanguageModel = class {
437
446
  let isFirstChunk = true;
438
447
  let activeText = false;
439
448
  let activeReasoningId = null;
440
- const toolCalls = [];
449
+ const toolCallTracker = new StreamingToolCallTracker({ generateId });
441
450
  return {
442
451
  stream: response.pipeThrough(
443
452
  new TransformStream({
@@ -445,7 +454,6 @@ var AlibabaLanguageModel = class {
445
454
  controller.enqueue({ type: "stream-start", warnings });
446
455
  },
447
456
  transform(chunk, controller) {
448
- var _a, _b, _c, _d;
449
457
  if (options.includeRawChunks) {
450
458
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
451
459
  }
@@ -458,7 +466,7 @@ var AlibabaLanguageModel = class {
458
466
  isFirstChunk = false;
459
467
  controller.enqueue({
460
468
  type: "response-metadata",
461
- ...(0, import_internal2.getResponseMetadata)(value)
469
+ ...getResponseMetadata(value)
462
470
  });
463
471
  }
464
472
  if (value.usage != null) {
@@ -475,7 +483,7 @@ var AlibabaLanguageModel = class {
475
483
  controller.enqueue({ type: "text-end", id: "0" });
476
484
  activeText = false;
477
485
  }
478
- activeReasoningId = (0, import_provider_utils2.generateId)();
486
+ activeReasoningId = generateId();
479
487
  controller.enqueue({
480
488
  type: "reasoning-start",
481
489
  id: activeReasoningId
@@ -518,87 +526,15 @@ var AlibabaLanguageModel = class {
518
526
  activeText = false;
519
527
  }
520
528
  for (const toolCallDelta of delta.tool_calls) {
521
- const index = (_a = toolCallDelta.index) != null ? _a : toolCalls.length;
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
- }
529
+ toolCallTracker.processDelta(
530
+ toolCallDelta,
531
+ controller.enqueue.bind(controller)
532
+ );
597
533
  }
598
534
  }
599
535
  if (choice.finish_reason != null) {
600
536
  finishReason = {
601
- unified: (0, import_internal2.mapOpenAICompatibleFinishReason)(choice.finish_reason),
537
+ unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
602
538
  raw: choice.finish_reason
603
539
  };
604
540
  }
@@ -613,6 +549,7 @@ var AlibabaLanguageModel = class {
613
549
  if (activeText) {
614
550
  controller.enqueue({ type: "text-end", id: "0" });
615
551
  }
552
+ toolCallTracker.flush(controller.enqueue.bind(controller));
616
553
  controller.enqueue({
617
554
  type: "finish",
618
555
  finishReason,
@@ -626,72 +563,100 @@ var AlibabaLanguageModel = class {
626
563
  };
627
564
  }
628
565
  };
629
- var alibabaUsageSchema = import_v42.z.object({
630
- prompt_tokens: import_v42.z.number(),
631
- completion_tokens: import_v42.z.number(),
632
- total_tokens: import_v42.z.number(),
633
- prompt_tokens_details: import_v42.z.object({
634
- cached_tokens: import_v42.z.number().nullish(),
635
- cache_creation_input_tokens: import_v42.z.number().nullish()
566
+ function resolveAlibabaThinking({
567
+ reasoning,
568
+ alibabaOptions,
569
+ warnings
570
+ }) {
571
+ if ((alibabaOptions == null ? void 0 : alibabaOptions.enableThinking) != null || (alibabaOptions == null ? void 0 : alibabaOptions.thinkingBudget) != null) {
572
+ return {
573
+ ...alibabaOptions.enableThinking != null ? { enable_thinking: alibabaOptions.enableThinking } : {},
574
+ ...alibabaOptions.thinkingBudget != null ? { thinking_budget: alibabaOptions.thinkingBudget } : {}
575
+ };
576
+ }
577
+ if (!isCustomReasoning(reasoning)) {
578
+ return {};
579
+ }
580
+ if (reasoning === "none") {
581
+ return { enable_thinking: false };
582
+ }
583
+ const thinkingBudget = mapReasoningToProviderBudget({
584
+ reasoning,
585
+ maxOutputTokens: 16384,
586
+ maxReasoningBudget: 16384,
587
+ warnings
588
+ });
589
+ return {
590
+ enable_thinking: true,
591
+ ...thinkingBudget != null ? { thinking_budget: thinkingBudget } : {}
592
+ };
593
+ }
594
+ var alibabaUsageSchema = z2.object({
595
+ prompt_tokens: z2.number(),
596
+ completion_tokens: z2.number(),
597
+ total_tokens: z2.number(),
598
+ prompt_tokens_details: z2.object({
599
+ cached_tokens: z2.number().nullish(),
600
+ cache_creation_input_tokens: z2.number().nullish()
636
601
  }).nullish(),
637
- completion_tokens_details: import_v42.z.object({
638
- reasoning_tokens: import_v42.z.number().nullish()
602
+ completion_tokens_details: z2.object({
603
+ reasoning_tokens: z2.number().nullish()
639
604
  }).nullish()
640
605
  });
641
- var alibabaChatResponseSchema = import_v42.z.object({
642
- id: import_v42.z.string().nullish(),
643
- created: import_v42.z.number().nullish(),
644
- model: import_v42.z.string().nullish(),
645
- choices: import_v42.z.array(
646
- import_v42.z.object({
647
- message: import_v42.z.object({
648
- role: import_v42.z.literal("assistant").nullish(),
649
- content: import_v42.z.string().nullish(),
650
- reasoning_content: import_v42.z.string().nullish(),
606
+ var alibabaChatResponseSchema = z2.object({
607
+ id: z2.string().nullish(),
608
+ created: z2.number().nullish(),
609
+ model: z2.string().nullish(),
610
+ choices: z2.array(
611
+ z2.object({
612
+ message: z2.object({
613
+ role: z2.literal("assistant").nullish(),
614
+ content: z2.string().nullish(),
615
+ reasoning_content: z2.string().nullish(),
651
616
  // Alibaba thinking mode
652
- tool_calls: import_v42.z.array(
653
- import_v42.z.object({
654
- id: import_v42.z.string(),
655
- type: import_v42.z.literal("function"),
656
- function: import_v42.z.object({
657
- name: import_v42.z.string(),
658
- arguments: import_v42.z.string()
617
+ tool_calls: z2.array(
618
+ z2.object({
619
+ id: z2.string(),
620
+ type: z2.literal("function"),
621
+ function: z2.object({
622
+ name: z2.string(),
623
+ arguments: z2.string()
659
624
  })
660
625
  })
661
626
  ).nullish()
662
627
  }),
663
- finish_reason: import_v42.z.string().nullish(),
664
- index: import_v42.z.number()
628
+ finish_reason: z2.string().nullish(),
629
+ index: z2.number()
665
630
  })
666
631
  ),
667
632
  usage: alibabaUsageSchema.nullish()
668
633
  });
669
- var alibabaChatChunkSchema = import_v42.z.object({
670
- id: import_v42.z.string().nullish(),
671
- created: import_v42.z.number().nullish(),
672
- model: import_v42.z.string().nullish(),
673
- choices: import_v42.z.array(
674
- import_v42.z.object({
675
- delta: import_v42.z.object({
676
- role: import_v42.z.enum(["assistant"]).nullish(),
677
- content: import_v42.z.string().nullish(),
678
- reasoning_content: import_v42.z.string().nullish(),
634
+ var alibabaChatChunkSchema = z2.object({
635
+ id: z2.string().nullish(),
636
+ created: z2.number().nullish(),
637
+ model: z2.string().nullish(),
638
+ choices: z2.array(
639
+ z2.object({
640
+ delta: z2.object({
641
+ role: z2.enum(["assistant"]).nullish(),
642
+ content: z2.string().nullish(),
643
+ reasoning_content: z2.string().nullish(),
679
644
  // Alibaba thinking mode delta
680
- tool_calls: import_v42.z.array(
681
- import_v42.z.object({
682
- index: import_v42.z.number().nullish(),
645
+ tool_calls: z2.array(
646
+ z2.object({
647
+ index: z2.number().nullish(),
683
648
  // Index for accumulating tool calls
684
- id: import_v42.z.string().nullish(),
685
- type: import_v42.z.literal("function").nullish(),
686
- function: import_v42.z.object({
687
- name: import_v42.z.string().nullish(),
688
- arguments: import_v42.z.string().nullish()
649
+ id: z2.string().nullish(),
650
+ type: z2.literal("function").nullish(),
651
+ function: z2.object({
652
+ name: z2.string().nullish(),
653
+ arguments: z2.string().nullish()
689
654
  }).nullish()
690
655
  })
691
656
  ).nullish()
692
657
  }),
693
- finish_reason: import_v42.z.string().nullish(),
694
- index: import_v42.z.number()
658
+ finish_reason: z2.string().nullish(),
659
+ index: z2.number()
695
660
  })
696
661
  ),
697
662
  usage: alibabaUsageSchema.nullish()
@@ -699,60 +664,74 @@ var alibabaChatChunkSchema = import_v42.z.object({
699
664
  });
700
665
 
701
666
  // src/alibaba-video-model.ts
702
- var import_provider3 = require("@ai-sdk/provider");
703
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
704
- var import_v43 = require("zod/v4");
705
- var alibabaVideoModelOptionsSchema = (0, import_provider_utils3.lazySchema)(
706
- () => (0, import_provider_utils3.zodSchema)(
707
- import_v43.z.object({
708
- negativePrompt: import_v43.z.string().nullish(),
709
- audioUrl: import_v43.z.string().nullish(),
710
- promptExtend: import_v43.z.boolean().nullish(),
711
- shotType: import_v43.z.enum(["single", "multi"]).nullish(),
712
- watermark: import_v43.z.boolean().nullish(),
713
- audio: import_v43.z.boolean().nullish(),
714
- referenceUrls: import_v43.z.array(import_v43.z.string()).nullish(),
715
- pollIntervalMs: import_v43.z.number().positive().nullish(),
716
- pollTimeoutMs: import_v43.z.number().positive().nullish()
667
+ import {
668
+ AISDKError
669
+ } from "@ai-sdk/provider";
670
+ import {
671
+ combineHeaders as combineHeaders2,
672
+ convertUint8ArrayToBase64,
673
+ createJsonErrorResponseHandler,
674
+ createJsonResponseHandler as createJsonResponseHandler2,
675
+ delay,
676
+ getFromApi,
677
+ lazySchema,
678
+ parseProviderOptions as parseProviderOptions2,
679
+ postJsonToApi as postJsonToApi2,
680
+ resolve,
681
+ zodSchema
682
+ } from "@ai-sdk/provider-utils";
683
+ import { z as z3 } from "zod/v4";
684
+ var alibabaVideoModelOptionsSchema = lazySchema(
685
+ () => zodSchema(
686
+ z3.object({
687
+ negativePrompt: z3.string().nullish(),
688
+ audioUrl: z3.string().nullish(),
689
+ promptExtend: z3.boolean().nullish(),
690
+ shotType: z3.enum(["single", "multi"]).nullish(),
691
+ watermark: z3.boolean().nullish(),
692
+ audio: z3.boolean().nullish(),
693
+ referenceUrls: z3.array(z3.string()).nullish(),
694
+ pollIntervalMs: z3.number().positive().nullish(),
695
+ pollTimeoutMs: z3.number().positive().nullish()
717
696
  }).passthrough()
718
697
  )
719
698
  );
720
- var alibabaVideoErrorSchema = import_v43.z.object({
721
- code: import_v43.z.string().nullish(),
722
- message: import_v43.z.string(),
723
- request_id: import_v43.z.string().nullish()
699
+ var alibabaVideoErrorSchema = z3.object({
700
+ code: z3.string().nullish(),
701
+ message: z3.string(),
702
+ request_id: z3.string().nullish()
724
703
  });
725
- var alibabaVideoFailedResponseHandler = (0, import_provider_utils3.createJsonErrorResponseHandler)({
704
+ var alibabaVideoFailedResponseHandler = createJsonErrorResponseHandler({
726
705
  errorSchema: alibabaVideoErrorSchema,
727
706
  errorToMessage: (data) => data.message
728
707
  });
729
- var alibabaVideoCreateTaskSchema = import_v43.z.object({
730
- output: import_v43.z.object({
731
- task_status: import_v43.z.string(),
732
- task_id: import_v43.z.string()
708
+ var alibabaVideoCreateTaskSchema = z3.object({
709
+ output: z3.object({
710
+ task_status: z3.string(),
711
+ task_id: z3.string()
733
712
  }).nullish(),
734
- request_id: import_v43.z.string().nullish()
713
+ request_id: z3.string().nullish()
735
714
  });
736
- var alibabaVideoTaskStatusSchema = import_v43.z.object({
737
- output: import_v43.z.object({
738
- task_id: import_v43.z.string(),
739
- task_status: import_v43.z.string(),
740
- video_url: import_v43.z.string().nullish(),
741
- submit_time: import_v43.z.string().nullish(),
742
- scheduled_time: import_v43.z.string().nullish(),
743
- end_time: import_v43.z.string().nullish(),
744
- orig_prompt: import_v43.z.string().nullish(),
745
- actual_prompt: import_v43.z.string().nullish(),
746
- code: import_v43.z.string().nullish(),
747
- message: import_v43.z.string().nullish()
715
+ var alibabaVideoTaskStatusSchema = z3.object({
716
+ output: z3.object({
717
+ task_id: z3.string(),
718
+ task_status: z3.string(),
719
+ video_url: z3.string().nullish(),
720
+ submit_time: z3.string().nullish(),
721
+ scheduled_time: z3.string().nullish(),
722
+ end_time: z3.string().nullish(),
723
+ orig_prompt: z3.string().nullish(),
724
+ actual_prompt: z3.string().nullish(),
725
+ code: z3.string().nullish(),
726
+ message: z3.string().nullish()
748
727
  }).nullish(),
749
- usage: import_v43.z.object({
750
- duration: import_v43.z.number().nullish(),
751
- output_video_duration: import_v43.z.number().nullish(),
752
- SR: import_v43.z.number().nullish(),
753
- size: import_v43.z.string().nullish()
728
+ usage: z3.object({
729
+ duration: z3.number().nullish(),
730
+ output_video_duration: z3.number().nullish(),
731
+ SR: z3.number().nullish(),
732
+ size: z3.string().nullish()
754
733
  }).nullish(),
755
- request_id: import_v43.z.string().nullish()
734
+ request_id: z3.string().nullish()
756
735
  });
757
736
  function detectMode(modelId) {
758
737
  if (modelId.includes("-i2v")) return "i2v";
@@ -774,7 +753,7 @@ var AlibabaVideoModel = class {
774
753
  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
754
  const warnings = [];
776
755
  const mode = detectMode(this.modelId);
777
- const alibabaOptions = await (0, import_provider_utils3.parseProviderOptions)({
756
+ const alibabaOptions = await parseProviderOptions2({
778
757
  provider: "alibaba",
779
758
  providerOptions: options.providerOptions,
780
759
  schema: alibabaVideoModelOptionsSchema
@@ -793,7 +772,7 @@ var AlibabaVideoModel = class {
793
772
  if (options.image.type === "url") {
794
773
  input.img_url = options.image.url;
795
774
  } else {
796
- const base64Data = typeof options.image.data === "string" ? options.image.data : (0, import_provider_utils3.convertUint8ArrayToBase64)(options.image.data);
775
+ const base64Data = typeof options.image.data === "string" ? options.image.data : convertUint8ArrayToBase64(options.image.data);
797
776
  input.img_url = base64Data;
798
777
  }
799
778
  }
@@ -862,10 +841,10 @@ var AlibabaVideoModel = class {
862
841
  details: "Alibaba video models only support generating 1 video per call."
863
842
  });
864
843
  }
865
- const { value: createResponse } = await (0, import_provider_utils3.postJsonToApi)({
844
+ const { value: createResponse } = await postJsonToApi2({
866
845
  url: `${this.config.baseURL}/api/v1/services/aigc/video-generation/video-synthesis`,
867
- headers: (0, import_provider_utils3.combineHeaders)(
868
- await (0, import_provider_utils3.resolve)(this.config.headers),
846
+ headers: combineHeaders2(
847
+ await resolve(this.config.headers),
869
848
  options.headers,
870
849
  {
871
850
  "X-DashScope-Async": "enable"
@@ -876,7 +855,7 @@ var AlibabaVideoModel = class {
876
855
  input,
877
856
  parameters
878
857
  },
879
- successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
858
+ successfulResponseHandler: createJsonResponseHandler2(
880
859
  alibabaVideoCreateTaskSchema
881
860
  ),
882
861
  failedResponseHandler: alibabaVideoFailedResponseHandler,
@@ -885,7 +864,7 @@ var AlibabaVideoModel = class {
885
864
  });
886
865
  const taskId = (_d = createResponse.output) == null ? void 0 : _d.task_id;
887
866
  if (!taskId) {
888
- throw new import_provider3.AISDKError({
867
+ throw new AISDKError({
889
868
  name: "ALIBABA_VIDEO_GENERATION_ERROR",
890
869
  message: `No task_id returned from Alibaba API. Response: ${JSON.stringify(createResponse)}`
891
870
  });
@@ -896,20 +875,20 @@ var AlibabaVideoModel = class {
896
875
  let finalResponse;
897
876
  let responseHeaders;
898
877
  while (true) {
899
- await (0, import_provider_utils3.delay)(pollIntervalMs, { abortSignal: options.abortSignal });
878
+ await delay(pollIntervalMs, { abortSignal: options.abortSignal });
900
879
  if (Date.now() - startTime > pollTimeoutMs) {
901
- throw new import_provider3.AISDKError({
880
+ throw new AISDKError({
902
881
  name: "ALIBABA_VIDEO_GENERATION_TIMEOUT",
903
882
  message: `Video generation timed out after ${pollTimeoutMs}ms`
904
883
  });
905
884
  }
906
- const { value: statusResponse, responseHeaders: pollHeaders } = await (0, import_provider_utils3.getFromApi)({
885
+ const { value: statusResponse, responseHeaders: pollHeaders } = await getFromApi({
907
886
  url: `${this.config.baseURL}/api/v1/tasks/${taskId}`,
908
- headers: (0, import_provider_utils3.combineHeaders)(
909
- await (0, import_provider_utils3.resolve)(this.config.headers),
887
+ headers: combineHeaders2(
888
+ await resolve(this.config.headers),
910
889
  options.headers
911
890
  ),
912
- successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
891
+ successfulResponseHandler: createJsonResponseHandler2(
913
892
  alibabaVideoTaskStatusSchema
914
893
  ),
915
894
  failedResponseHandler: alibabaVideoFailedResponseHandler,
@@ -923,7 +902,7 @@ var AlibabaVideoModel = class {
923
902
  break;
924
903
  }
925
904
  if (taskStatus === "FAILED" || taskStatus === "CANCELED") {
926
- throw new import_provider3.AISDKError({
905
+ throw new AISDKError({
927
906
  name: "ALIBABA_VIDEO_GENERATION_FAILED",
928
907
  message: `Video generation ${taskStatus.toLowerCase()}. Task ID: ${taskId}. ${(_i = (_h = statusResponse.output) == null ? void 0 : _h.message) != null ? _i : ""}`
929
908
  });
@@ -931,7 +910,7 @@ var AlibabaVideoModel = class {
931
910
  }
932
911
  const videoUrl = (_j = finalResponse == null ? void 0 : finalResponse.output) == null ? void 0 : _j.video_url;
933
912
  if (!videoUrl) {
934
- throw new import_provider3.AISDKError({
913
+ throw new AISDKError({
935
914
  name: "ALIBABA_VIDEO_GENERATION_ERROR",
936
915
  message: `No video URL in response. Task ID: ${taskId}`
937
916
  });
@@ -970,27 +949,27 @@ var AlibabaVideoModel = class {
970
949
  };
971
950
 
972
951
  // src/version.ts
973
- var VERSION = "2.0.0-beta.3";
952
+ var VERSION = "2.0.0-beta.31";
974
953
 
975
954
  // 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()
955
+ var alibabaErrorDataSchema = z4.object({
956
+ error: z4.object({
957
+ message: z4.string(),
958
+ code: z4.string().nullish(),
959
+ type: z4.string().nullish()
981
960
  })
982
961
  });
983
- var alibabaFailedResponseHandler = (0, import_provider_utils4.createJsonErrorResponseHandler)({
962
+ var alibabaFailedResponseHandler = createJsonErrorResponseHandler2({
984
963
  errorSchema: alibabaErrorDataSchema,
985
964
  errorToMessage: (data) => data.error.message
986
965
  });
987
966
  function createAlibaba(options = {}) {
988
967
  var _a, _b;
989
- const baseURL = (_a = (0, import_provider_utils4.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://dashscope-intl.aliyuncs.com/compatible-mode/v1";
990
- const videoBaseURL = (_b = (0, import_provider_utils4.withoutTrailingSlash)(options.videoBaseURL)) != null ? _b : "https://dashscope-intl.aliyuncs.com";
991
- const getHeaders = () => (0, import_provider_utils4.withUserAgentSuffix)(
968
+ const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://dashscope-intl.aliyuncs.com/compatible-mode/v1";
969
+ const videoBaseURL = (_b = withoutTrailingSlash(options.videoBaseURL)) != null ? _b : "https://dashscope-intl.aliyuncs.com";
970
+ const getHeaders = () => withUserAgentSuffix(
992
971
  {
993
- Authorization: `Bearer ${(0, import_provider_utils4.loadApiKey)({
972
+ Authorization: `Bearer ${loadApiKey({
994
973
  apiKey: options.apiKey,
995
974
  environmentVariableName: "ALIBABA_API_KEY",
996
975
  description: "Alibaba Cloud (DashScope)"
@@ -1029,18 +1008,17 @@ function createAlibaba(options = {}) {
1029
1008
  provider.video = createVideoModel;
1030
1009
  provider.videoModel = createVideoModel;
1031
1010
  provider.imageModel = (modelId) => {
1032
- throw new import_provider4.NoSuchModelError({ modelId, modelType: "imageModel" });
1011
+ throw new NoSuchModelError({ modelId, modelType: "imageModel" });
1033
1012
  };
1034
1013
  provider.embeddingModel = (modelId) => {
1035
- throw new import_provider4.NoSuchModelError({ modelId, modelType: "embeddingModel" });
1014
+ throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
1036
1015
  };
1037
1016
  return provider;
1038
1017
  }
1039
1018
  var alibaba = createAlibaba();
1040
- // Annotate the CommonJS export names for ESM import in node:
1041
- 0 && (module.exports = {
1019
+ export {
1042
1020
  VERSION,
1043
1021
  alibaba,
1044
1022
  createAlibaba
1045
- });
1023
+ };
1046
1024
  //# sourceMappingURL=index.js.map