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

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,67 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var 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
+ InvalidResponseDataError
21
+ } from "@ai-sdk/provider";
22
+ import {
23
+ combineHeaders,
24
+ createEventSourceResponseHandler,
25
+ createJsonResponseHandler,
26
+ generateId,
27
+ isCustomReasoning,
28
+ isParsableJson,
29
+ mapReasoningToProviderBudget,
30
+ parseProviderOptions,
31
+ postJsonToApi,
32
+ serializeModelOptions,
33
+ WORKFLOW_SERIALIZE,
34
+ WORKFLOW_DESERIALIZE
35
+ } from "@ai-sdk/provider-utils";
36
+ import { z as z2 } from "zod/v4";
39
37
 
40
38
  // src/alibaba-chat-options.ts
41
- var import_v4 = require("zod/v4");
42
- var alibabaLanguageModelOptions = import_v4.z.object({
39
+ import { z } from "zod/v4";
40
+ var alibabaLanguageModelOptions = z.object({
43
41
  /**
44
42
  * Enable thinking/reasoning mode for supported models.
45
43
  * When enabled, the model generates reasoning content before the response.
46
44
  *
47
45
  * @default false
48
46
  */
49
- enableThinking: import_v4.z.boolean().optional(),
47
+ enableThinking: z.boolean().optional(),
50
48
  /**
51
49
  * Maximum number of reasoning tokens to generate.
52
50
  */
53
- thinkingBudget: import_v4.z.number().positive().optional(),
51
+ thinkingBudget: z.number().positive().optional(),
54
52
  /**
55
53
  * Whether to enable parallel function calling during tool use.
56
54
  *
57
55
  * @default true
58
56
  */
59
- parallelToolCalls: import_v4.z.boolean().optional()
57
+ parallelToolCalls: z.boolean().optional()
60
58
  });
61
59
 
62
60
  // src/convert-alibaba-usage.ts
63
- var import_internal = require("@ai-sdk/openai-compatible/internal");
61
+ import { convertOpenAICompatibleChatUsage } from "@ai-sdk/openai-compatible/internal";
64
62
  function convertAlibabaUsage(usage) {
65
63
  var _a, _b, _c, _d;
66
- const baseUsage = (0, import_internal.convertOpenAICompatibleChatUsage)(usage);
64
+ const baseUsage = convertOpenAICompatibleChatUsage(usage);
67
65
  const cacheWriteTokens = (_b = (_a = usage == null ? void 0 : usage.prompt_tokens_details) == null ? void 0 : _a.cache_creation_input_tokens) != null ? _b : 0;
68
66
  const noCacheTokens = ((_c = baseUsage.inputTokens.total) != null ? _c : 0) - ((_d = baseUsage.inputTokens.cacheRead) != null ? _d : 0) - cacheWriteTokens;
69
67
  return {
@@ -77,19 +75,21 @@ function convertAlibabaUsage(usage) {
77
75
  }
78
76
 
79
77
  // 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");
78
+ import {
79
+ UnsupportedFunctionalityError
80
+ } from "@ai-sdk/provider";
81
+ import { convertToBase64, isProviderReference } from "@ai-sdk/provider-utils";
82
82
  function formatImageUrl({
83
83
  data,
84
84
  mediaType
85
85
  }) {
86
- return data instanceof URL ? data.toString() : `data:${mediaType};base64,${(0, import_provider_utils.convertToBase64)(data)}`;
86
+ return data instanceof URL ? data.toString() : `data:${mediaType};base64,${convertToBase64(data)}`;
87
87
  }
88
88
  function convertToAlibabaChatMessages({
89
89
  prompt,
90
90
  cacheControlValidator
91
91
  }) {
92
- var _a;
92
+ var _a, _b;
93
93
  const messages = [];
94
94
  for (const { role, content, ...message } of prompt) {
95
95
  const messageCacheControl = cacheControlValidator == null ? void 0 : cacheControlValidator.getCacheControl(
@@ -114,18 +114,12 @@ function convertToAlibabaChatMessages({
114
114
  break;
115
115
  }
116
116
  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
117
  messages.push({
126
118
  role: "user",
127
- content: content.map((part) => {
128
- const partCacheControl = isSinglePart ? messageCacheControl : cacheControlValidator == null ? void 0 : cacheControlValidator.getCacheControl(part.providerOptions);
119
+ content: content.map((part, index) => {
120
+ var _a2;
121
+ const isLastPart = index === content.length - 1;
122
+ const partCacheControl = (_a2 = cacheControlValidator == null ? void 0 : cacheControlValidator.getCacheControl(part.providerOptions)) != null ? _a2 : isLastPart ? messageCacheControl : void 0;
129
123
  switch (part.type) {
130
124
  case "text": {
131
125
  return {
@@ -135,6 +129,11 @@ function convertToAlibabaChatMessages({
135
129
  };
136
130
  }
137
131
  case "file": {
132
+ if (isProviderReference(part.data)) {
133
+ throw new UnsupportedFunctionalityError({
134
+ functionality: "file parts with provider references"
135
+ });
136
+ }
138
137
  if (part.mediaType.startsWith("image/")) {
139
138
  const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
140
139
  return {
@@ -145,7 +144,7 @@ function convertToAlibabaChatMessages({
145
144
  ...partCacheControl ? { cache_control: partCacheControl } : {}
146
145
  };
147
146
  } else {
148
- throw new import_provider.UnsupportedFunctionalityError({
147
+ throw new UnsupportedFunctionalityError({
149
148
  functionality: "Only image file parts are supported"
150
149
  });
151
150
  }
@@ -192,13 +191,13 @@ function convertToAlibabaChatMessages({
192
191
  const toolResponses = content.filter(
193
192
  (r) => r.type !== "tool-approval-response"
194
193
  );
195
- const isSinglePart = toolResponses.length === 1;
196
194
  for (let i = 0; i < toolResponses.length; i++) {
197
195
  const toolResponse = toolResponses[i];
198
196
  const output = toolResponse.output;
199
- const partCacheControl = isSinglePart ? messageCacheControl : cacheControlValidator == null ? void 0 : cacheControlValidator.getCacheControl(
197
+ const isLastPart = i === toolResponses.length - 1;
198
+ const partCacheControl = (_a = cacheControlValidator == null ? void 0 : cacheControlValidator.getCacheControl(
200
199
  toolResponse.providerOptions
201
- );
200
+ )) != null ? _a : isLastPart ? messageCacheControl : void 0;
202
201
  let contentValue;
203
202
  switch (output.type) {
204
203
  case "text":
@@ -206,7 +205,7 @@ function convertToAlibabaChatMessages({
206
205
  contentValue = output.value;
207
206
  break;
208
207
  case "execution-denied":
209
- contentValue = (_a = output.reason) != null ? _a : "Tool execution denied.";
208
+ contentValue = (_b = output.reason) != null ? _b : "Tool execution denied.";
210
209
  break;
211
210
  case "content":
212
211
  case "json":
@@ -270,7 +269,7 @@ var CacheControlValidator = class {
270
269
  };
271
270
 
272
271
  // src/alibaba-chat-language-model.ts
273
- var AlibabaLanguageModel = class {
272
+ var AlibabaLanguageModel = class _AlibabaLanguageModel {
274
273
  constructor(modelId, config) {
275
274
  this.specificationVersion = "v4";
276
275
  this.supportedUrls = {
@@ -279,6 +278,15 @@ var AlibabaLanguageModel = class {
279
278
  this.modelId = modelId;
280
279
  this.config = config;
281
280
  }
281
+ static [WORKFLOW_SERIALIZE](model) {
282
+ return serializeModelOptions({
283
+ modelId: model.modelId,
284
+ config: model.config
285
+ });
286
+ }
287
+ static [WORKFLOW_DESERIALIZE](options) {
288
+ return new _AlibabaLanguageModel(options.modelId, options.config);
289
+ }
282
290
  get provider() {
283
291
  return this.config.provider;
284
292
  }
@@ -297,6 +305,7 @@ var AlibabaLanguageModel = class {
297
305
  stopSequences,
298
306
  responseFormat,
299
307
  seed,
308
+ reasoning,
300
309
  providerOptions,
301
310
  tools,
302
311
  toolChoice
@@ -304,7 +313,7 @@ var AlibabaLanguageModel = class {
304
313
  var _a;
305
314
  const warnings = [];
306
315
  const cacheControlValidator = new CacheControlValidator();
307
- const alibabaOptions = await (0, import_provider_utils2.parseProviderOptions)({
316
+ const alibabaOptions = await parseProviderOptions({
308
317
  provider: "alibaba",
309
318
  providerOptions,
310
319
  schema: alibabaLanguageModelOptions
@@ -329,9 +338,11 @@ var AlibabaLanguageModel = class {
329
338
  description: responseFormat.description
330
339
  }
331
340
  } : { 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 } : {},
341
+ ...resolveAlibabaThinking({
342
+ reasoning,
343
+ alibabaOptions,
344
+ warnings
345
+ }),
335
346
  // Convert messages with cache control support
336
347
  messages: convertToAlibabaChatMessages({
337
348
  prompt,
@@ -342,7 +353,7 @@ var AlibabaLanguageModel = class {
342
353
  tools: alibabaTools,
343
354
  toolChoice: alibabaToolChoice,
344
355
  toolWarnings
345
- } = (0, import_internal2.prepareTools)({ tools, toolChoice });
356
+ } = prepareTools({ tools, toolChoice });
346
357
  warnings.push(...cacheControlValidator.getWarnings());
347
358
  return {
348
359
  args: {
@@ -355,18 +366,18 @@ var AlibabaLanguageModel = class {
355
366
  };
356
367
  }
357
368
  async doGenerate(options) {
358
- var _a;
369
+ var _a, _b, _c;
359
370
  const { args, warnings } = await this.getArgs(options);
360
371
  const {
361
372
  responseHeaders,
362
373
  value: response,
363
374
  rawValue: rawResponse
364
- } = await (0, import_provider_utils2.postJsonToApi)({
375
+ } = await postJsonToApi({
365
376
  url: `${this.config.baseURL}/chat/completions`,
366
- headers: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.headers),
377
+ headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
367
378
  body: args,
368
379
  failedResponseHandler: alibabaFailedResponseHandler,
369
- successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(
380
+ successfulResponseHandler: createJsonResponseHandler(
370
381
  alibabaChatResponseSchema
371
382
  ),
372
383
  abortSignal: options.abortSignal,
@@ -398,13 +409,13 @@ var AlibabaLanguageModel = class {
398
409
  return {
399
410
  content,
400
411
  finishReason: {
401
- unified: (0, import_internal2.mapOpenAICompatibleFinishReason)(choice.finish_reason),
402
- raw: (_a = choice.finish_reason) != null ? _a : void 0
412
+ unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
413
+ raw: (_c = choice.finish_reason) != null ? _c : void 0
403
414
  },
404
415
  usage: convertAlibabaUsage(response.usage),
405
416
  request: { body: JSON.stringify(args) },
406
417
  response: {
407
- ...(0, import_internal2.getResponseMetadata)(response),
418
+ ...getResponseMetadata(response),
408
419
  headers: responseHeaders,
409
420
  body: rawResponse
410
421
  },
@@ -412,18 +423,19 @@ var AlibabaLanguageModel = class {
412
423
  };
413
424
  }
414
425
  async doStream(options) {
426
+ var _a, _b;
415
427
  const { args, warnings } = await this.getArgs(options);
416
428
  const body = {
417
429
  ...args,
418
430
  stream: true,
419
431
  stream_options: this.config.includeUsage ? { include_usage: true } : void 0
420
432
  };
421
- const { responseHeaders, value: response } = await (0, import_provider_utils2.postJsonToApi)({
433
+ const { responseHeaders, value: response } = await postJsonToApi({
422
434
  url: `${this.config.baseURL}/chat/completions`,
423
- headers: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.headers),
435
+ headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
424
436
  body,
425
437
  failedResponseHandler: alibabaFailedResponseHandler,
426
- successfulResponseHandler: (0, import_provider_utils2.createEventSourceResponseHandler)(
438
+ successfulResponseHandler: createEventSourceResponseHandler(
427
439
  alibabaChatChunkSchema
428
440
  ),
429
441
  abortSignal: options.abortSignal,
@@ -445,7 +457,7 @@ var AlibabaLanguageModel = class {
445
457
  controller.enqueue({ type: "stream-start", warnings });
446
458
  },
447
459
  transform(chunk, controller) {
448
- var _a, _b, _c, _d;
460
+ var _a2, _b2, _c, _d;
449
461
  if (options.includeRawChunks) {
450
462
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
451
463
  }
@@ -458,7 +470,7 @@ var AlibabaLanguageModel = class {
458
470
  isFirstChunk = false;
459
471
  controller.enqueue({
460
472
  type: "response-metadata",
461
- ...(0, import_internal2.getResponseMetadata)(value)
473
+ ...getResponseMetadata(value)
462
474
  });
463
475
  }
464
476
  if (value.usage != null) {
@@ -475,7 +487,7 @@ var AlibabaLanguageModel = class {
475
487
  controller.enqueue({ type: "text-end", id: "0" });
476
488
  activeText = false;
477
489
  }
478
- activeReasoningId = (0, import_provider_utils2.generateId)();
490
+ activeReasoningId = generateId();
479
491
  controller.enqueue({
480
492
  type: "reasoning-start",
481
493
  id: activeReasoningId
@@ -518,16 +530,16 @@ var AlibabaLanguageModel = class {
518
530
  activeText = false;
519
531
  }
520
532
  for (const toolCallDelta of delta.tool_calls) {
521
- const index = (_a = toolCallDelta.index) != null ? _a : toolCalls.length;
533
+ const index = (_a2 = toolCallDelta.index) != null ? _a2 : toolCalls.length;
522
534
  if (toolCalls[index] == null) {
523
535
  if (toolCallDelta.id == null) {
524
- throw new import_provider2.InvalidResponseDataError({
536
+ throw new InvalidResponseDataError({
525
537
  data: toolCallDelta,
526
538
  message: `Expected 'id' to be a string.`
527
539
  });
528
540
  }
529
- if (((_b = toolCallDelta.function) == null ? void 0 : _b.name) == null) {
530
- throw new import_provider2.InvalidResponseDataError({
541
+ if (((_b2 = toolCallDelta.function) == null ? void 0 : _b2.name) == null) {
542
+ throw new InvalidResponseDataError({
531
543
  data: toolCallDelta,
532
544
  message: `Expected 'function.name' to be a string.`
533
545
  });
@@ -554,7 +566,7 @@ var AlibabaLanguageModel = class {
554
566
  delta: toolCall2.function.arguments
555
567
  });
556
568
  }
557
- if ((0, import_provider_utils2.isParsableJson)(toolCall2.function.arguments)) {
569
+ if (isParsableJson(toolCall2.function.arguments)) {
558
570
  controller.enqueue({
559
571
  type: "tool-input-end",
560
572
  id: toolCall2.id
@@ -581,7 +593,7 @@ var AlibabaLanguageModel = class {
581
593
  delta: toolCallDelta.function.arguments
582
594
  });
583
595
  }
584
- if ((0, import_provider_utils2.isParsableJson)(toolCall.function.arguments)) {
596
+ if (isParsableJson(toolCall.function.arguments)) {
585
597
  controller.enqueue({
586
598
  type: "tool-input-end",
587
599
  id: toolCall.id
@@ -598,7 +610,7 @@ var AlibabaLanguageModel = class {
598
610
  }
599
611
  if (choice.finish_reason != null) {
600
612
  finishReason = {
601
- unified: (0, import_internal2.mapOpenAICompatibleFinishReason)(choice.finish_reason),
613
+ unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
602
614
  raw: choice.finish_reason
603
615
  };
604
616
  }
@@ -626,72 +638,100 @@ var AlibabaLanguageModel = class {
626
638
  };
627
639
  }
628
640
  };
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()
641
+ function resolveAlibabaThinking({
642
+ reasoning,
643
+ alibabaOptions,
644
+ warnings
645
+ }) {
646
+ if ((alibabaOptions == null ? void 0 : alibabaOptions.enableThinking) != null || (alibabaOptions == null ? void 0 : alibabaOptions.thinkingBudget) != null) {
647
+ return {
648
+ ...alibabaOptions.enableThinking != null ? { enable_thinking: alibabaOptions.enableThinking } : {},
649
+ ...alibabaOptions.thinkingBudget != null ? { thinking_budget: alibabaOptions.thinkingBudget } : {}
650
+ };
651
+ }
652
+ if (!isCustomReasoning(reasoning)) {
653
+ return {};
654
+ }
655
+ if (reasoning === "none") {
656
+ return { enable_thinking: false };
657
+ }
658
+ const thinkingBudget = mapReasoningToProviderBudget({
659
+ reasoning,
660
+ maxOutputTokens: 16384,
661
+ maxReasoningBudget: 16384,
662
+ warnings
663
+ });
664
+ return {
665
+ enable_thinking: true,
666
+ ...thinkingBudget != null ? { thinking_budget: thinkingBudget } : {}
667
+ };
668
+ }
669
+ var alibabaUsageSchema = z2.object({
670
+ prompt_tokens: z2.number(),
671
+ completion_tokens: z2.number(),
672
+ total_tokens: z2.number(),
673
+ prompt_tokens_details: z2.object({
674
+ cached_tokens: z2.number().nullish(),
675
+ cache_creation_input_tokens: z2.number().nullish()
636
676
  }).nullish(),
637
- completion_tokens_details: import_v42.z.object({
638
- reasoning_tokens: import_v42.z.number().nullish()
677
+ completion_tokens_details: z2.object({
678
+ reasoning_tokens: z2.number().nullish()
639
679
  }).nullish()
640
680
  });
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(),
681
+ var alibabaChatResponseSchema = z2.object({
682
+ id: z2.string().nullish(),
683
+ created: z2.number().nullish(),
684
+ model: z2.string().nullish(),
685
+ choices: z2.array(
686
+ z2.object({
687
+ message: z2.object({
688
+ role: z2.literal("assistant").nullish(),
689
+ content: z2.string().nullish(),
690
+ reasoning_content: z2.string().nullish(),
651
691
  // 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()
692
+ tool_calls: z2.array(
693
+ z2.object({
694
+ id: z2.string(),
695
+ type: z2.literal("function"),
696
+ function: z2.object({
697
+ name: z2.string(),
698
+ arguments: z2.string()
659
699
  })
660
700
  })
661
701
  ).nullish()
662
702
  }),
663
- finish_reason: import_v42.z.string().nullish(),
664
- index: import_v42.z.number()
703
+ finish_reason: z2.string().nullish(),
704
+ index: z2.number()
665
705
  })
666
706
  ),
667
707
  usage: alibabaUsageSchema.nullish()
668
708
  });
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(),
709
+ var alibabaChatChunkSchema = z2.object({
710
+ id: z2.string().nullish(),
711
+ created: z2.number().nullish(),
712
+ model: z2.string().nullish(),
713
+ choices: z2.array(
714
+ z2.object({
715
+ delta: z2.object({
716
+ role: z2.enum(["assistant"]).nullish(),
717
+ content: z2.string().nullish(),
718
+ reasoning_content: z2.string().nullish(),
679
719
  // Alibaba thinking mode delta
680
- tool_calls: import_v42.z.array(
681
- import_v42.z.object({
682
- index: import_v42.z.number().nullish(),
720
+ tool_calls: z2.array(
721
+ z2.object({
722
+ index: z2.number().nullish(),
683
723
  // 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()
724
+ id: z2.string().nullish(),
725
+ type: z2.literal("function").nullish(),
726
+ function: z2.object({
727
+ name: z2.string().nullish(),
728
+ arguments: z2.string().nullish()
689
729
  }).nullish()
690
730
  })
691
731
  ).nullish()
692
732
  }),
693
- finish_reason: import_v42.z.string().nullish(),
694
- index: import_v42.z.number()
733
+ finish_reason: z2.string().nullish(),
734
+ index: z2.number()
695
735
  })
696
736
  ),
697
737
  usage: alibabaUsageSchema.nullish()
@@ -699,60 +739,74 @@ var alibabaChatChunkSchema = import_v42.z.object({
699
739
  });
700
740
 
701
741
  // 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()
742
+ import {
743
+ AISDKError
744
+ } from "@ai-sdk/provider";
745
+ import {
746
+ combineHeaders as combineHeaders2,
747
+ convertUint8ArrayToBase64,
748
+ createJsonErrorResponseHandler,
749
+ createJsonResponseHandler as createJsonResponseHandler2,
750
+ delay,
751
+ getFromApi,
752
+ lazySchema,
753
+ parseProviderOptions as parseProviderOptions2,
754
+ postJsonToApi as postJsonToApi2,
755
+ resolve,
756
+ zodSchema
757
+ } from "@ai-sdk/provider-utils";
758
+ import { z as z3 } from "zod/v4";
759
+ var alibabaVideoModelOptionsSchema = lazySchema(
760
+ () => zodSchema(
761
+ z3.object({
762
+ negativePrompt: z3.string().nullish(),
763
+ audioUrl: z3.string().nullish(),
764
+ promptExtend: z3.boolean().nullish(),
765
+ shotType: z3.enum(["single", "multi"]).nullish(),
766
+ watermark: z3.boolean().nullish(),
767
+ audio: z3.boolean().nullish(),
768
+ referenceUrls: z3.array(z3.string()).nullish(),
769
+ pollIntervalMs: z3.number().positive().nullish(),
770
+ pollTimeoutMs: z3.number().positive().nullish()
717
771
  }).passthrough()
718
772
  )
719
773
  );
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()
774
+ var alibabaVideoErrorSchema = z3.object({
775
+ code: z3.string().nullish(),
776
+ message: z3.string(),
777
+ request_id: z3.string().nullish()
724
778
  });
725
- var alibabaVideoFailedResponseHandler = (0, import_provider_utils3.createJsonErrorResponseHandler)({
779
+ var alibabaVideoFailedResponseHandler = createJsonErrorResponseHandler({
726
780
  errorSchema: alibabaVideoErrorSchema,
727
781
  errorToMessage: (data) => data.message
728
782
  });
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()
783
+ var alibabaVideoCreateTaskSchema = z3.object({
784
+ output: z3.object({
785
+ task_status: z3.string(),
786
+ task_id: z3.string()
733
787
  }).nullish(),
734
- request_id: import_v43.z.string().nullish()
788
+ request_id: z3.string().nullish()
735
789
  });
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()
790
+ var alibabaVideoTaskStatusSchema = z3.object({
791
+ output: z3.object({
792
+ task_id: z3.string(),
793
+ task_status: z3.string(),
794
+ video_url: z3.string().nullish(),
795
+ submit_time: z3.string().nullish(),
796
+ scheduled_time: z3.string().nullish(),
797
+ end_time: z3.string().nullish(),
798
+ orig_prompt: z3.string().nullish(),
799
+ actual_prompt: z3.string().nullish(),
800
+ code: z3.string().nullish(),
801
+ message: z3.string().nullish()
748
802
  }).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()
803
+ usage: z3.object({
804
+ duration: z3.number().nullish(),
805
+ output_video_duration: z3.number().nullish(),
806
+ SR: z3.number().nullish(),
807
+ size: z3.string().nullish()
754
808
  }).nullish(),
755
- request_id: import_v43.z.string().nullish()
809
+ request_id: z3.string().nullish()
756
810
  });
757
811
  function detectMode(modelId) {
758
812
  if (modelId.includes("-i2v")) return "i2v";
@@ -774,7 +828,7 @@ var AlibabaVideoModel = class {
774
828
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
775
829
  const warnings = [];
776
830
  const mode = detectMode(this.modelId);
777
- const alibabaOptions = await (0, import_provider_utils3.parseProviderOptions)({
831
+ const alibabaOptions = await parseProviderOptions2({
778
832
  provider: "alibaba",
779
833
  providerOptions: options.providerOptions,
780
834
  schema: alibabaVideoModelOptionsSchema
@@ -793,7 +847,7 @@ var AlibabaVideoModel = class {
793
847
  if (options.image.type === "url") {
794
848
  input.img_url = options.image.url;
795
849
  } else {
796
- const base64Data = typeof options.image.data === "string" ? options.image.data : (0, import_provider_utils3.convertUint8ArrayToBase64)(options.image.data);
850
+ const base64Data = typeof options.image.data === "string" ? options.image.data : convertUint8ArrayToBase64(options.image.data);
797
851
  input.img_url = base64Data;
798
852
  }
799
853
  }
@@ -862,10 +916,10 @@ var AlibabaVideoModel = class {
862
916
  details: "Alibaba video models only support generating 1 video per call."
863
917
  });
864
918
  }
865
- const { value: createResponse } = await (0, import_provider_utils3.postJsonToApi)({
919
+ const { value: createResponse } = await postJsonToApi2({
866
920
  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),
921
+ headers: combineHeaders2(
922
+ await resolve(this.config.headers),
869
923
  options.headers,
870
924
  {
871
925
  "X-DashScope-Async": "enable"
@@ -876,7 +930,7 @@ var AlibabaVideoModel = class {
876
930
  input,
877
931
  parameters
878
932
  },
879
- successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
933
+ successfulResponseHandler: createJsonResponseHandler2(
880
934
  alibabaVideoCreateTaskSchema
881
935
  ),
882
936
  failedResponseHandler: alibabaVideoFailedResponseHandler,
@@ -885,7 +939,7 @@ var AlibabaVideoModel = class {
885
939
  });
886
940
  const taskId = (_d = createResponse.output) == null ? void 0 : _d.task_id;
887
941
  if (!taskId) {
888
- throw new import_provider3.AISDKError({
942
+ throw new AISDKError({
889
943
  name: "ALIBABA_VIDEO_GENERATION_ERROR",
890
944
  message: `No task_id returned from Alibaba API. Response: ${JSON.stringify(createResponse)}`
891
945
  });
@@ -896,20 +950,20 @@ var AlibabaVideoModel = class {
896
950
  let finalResponse;
897
951
  let responseHeaders;
898
952
  while (true) {
899
- await (0, import_provider_utils3.delay)(pollIntervalMs, { abortSignal: options.abortSignal });
953
+ await delay(pollIntervalMs, { abortSignal: options.abortSignal });
900
954
  if (Date.now() - startTime > pollTimeoutMs) {
901
- throw new import_provider3.AISDKError({
955
+ throw new AISDKError({
902
956
  name: "ALIBABA_VIDEO_GENERATION_TIMEOUT",
903
957
  message: `Video generation timed out after ${pollTimeoutMs}ms`
904
958
  });
905
959
  }
906
- const { value: statusResponse, responseHeaders: pollHeaders } = await (0, import_provider_utils3.getFromApi)({
960
+ const { value: statusResponse, responseHeaders: pollHeaders } = await getFromApi({
907
961
  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),
962
+ headers: combineHeaders2(
963
+ await resolve(this.config.headers),
910
964
  options.headers
911
965
  ),
912
- successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
966
+ successfulResponseHandler: createJsonResponseHandler2(
913
967
  alibabaVideoTaskStatusSchema
914
968
  ),
915
969
  failedResponseHandler: alibabaVideoFailedResponseHandler,
@@ -923,7 +977,7 @@ var AlibabaVideoModel = class {
923
977
  break;
924
978
  }
925
979
  if (taskStatus === "FAILED" || taskStatus === "CANCELED") {
926
- throw new import_provider3.AISDKError({
980
+ throw new AISDKError({
927
981
  name: "ALIBABA_VIDEO_GENERATION_FAILED",
928
982
  message: `Video generation ${taskStatus.toLowerCase()}. Task ID: ${taskId}. ${(_i = (_h = statusResponse.output) == null ? void 0 : _h.message) != null ? _i : ""}`
929
983
  });
@@ -931,7 +985,7 @@ var AlibabaVideoModel = class {
931
985
  }
932
986
  const videoUrl = (_j = finalResponse == null ? void 0 : finalResponse.output) == null ? void 0 : _j.video_url;
933
987
  if (!videoUrl) {
934
- throw new import_provider3.AISDKError({
988
+ throw new AISDKError({
935
989
  name: "ALIBABA_VIDEO_GENERATION_ERROR",
936
990
  message: `No video URL in response. Task ID: ${taskId}`
937
991
  });
@@ -970,27 +1024,27 @@ var AlibabaVideoModel = class {
970
1024
  };
971
1025
 
972
1026
  // src/version.ts
973
- var VERSION = "2.0.0-beta.3";
1027
+ var VERSION = "2.0.0-beta.30";
974
1028
 
975
1029
  // 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()
1030
+ var alibabaErrorDataSchema = z4.object({
1031
+ error: z4.object({
1032
+ message: z4.string(),
1033
+ code: z4.string().nullish(),
1034
+ type: z4.string().nullish()
981
1035
  })
982
1036
  });
983
- var alibabaFailedResponseHandler = (0, import_provider_utils4.createJsonErrorResponseHandler)({
1037
+ var alibabaFailedResponseHandler = createJsonErrorResponseHandler2({
984
1038
  errorSchema: alibabaErrorDataSchema,
985
1039
  errorToMessage: (data) => data.error.message
986
1040
  });
987
1041
  function createAlibaba(options = {}) {
988
1042
  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)(
1043
+ const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://dashscope-intl.aliyuncs.com/compatible-mode/v1";
1044
+ const videoBaseURL = (_b = withoutTrailingSlash(options.videoBaseURL)) != null ? _b : "https://dashscope-intl.aliyuncs.com";
1045
+ const getHeaders = () => withUserAgentSuffix(
992
1046
  {
993
- Authorization: `Bearer ${(0, import_provider_utils4.loadApiKey)({
1047
+ Authorization: `Bearer ${loadApiKey({
994
1048
  apiKey: options.apiKey,
995
1049
  environmentVariableName: "ALIBABA_API_KEY",
996
1050
  description: "Alibaba Cloud (DashScope)"
@@ -1029,18 +1083,17 @@ function createAlibaba(options = {}) {
1029
1083
  provider.video = createVideoModel;
1030
1084
  provider.videoModel = createVideoModel;
1031
1085
  provider.imageModel = (modelId) => {
1032
- throw new import_provider4.NoSuchModelError({ modelId, modelType: "imageModel" });
1086
+ throw new NoSuchModelError({ modelId, modelType: "imageModel" });
1033
1087
  };
1034
1088
  provider.embeddingModel = (modelId) => {
1035
- throw new import_provider4.NoSuchModelError({ modelId, modelType: "embeddingModel" });
1089
+ throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
1036
1090
  };
1037
1091
  return provider;
1038
1092
  }
1039
1093
  var alibaba = createAlibaba();
1040
- // Annotate the CommonJS export names for ESM import in node:
1041
- 0 && (module.exports = {
1094
+ export {
1042
1095
  VERSION,
1043
1096
  alibaba,
1044
1097
  createAlibaba
1045
- });
1098
+ };
1046
1099
  //# sourceMappingURL=index.js.map