@ai-sdk/alibaba 1.0.68 → 1.0.70

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.
@@ -15,6 +15,9 @@ import {
15
15
  type SharedV3Warning,
16
16
  } from '@ai-sdk/provider';
17
17
  import {
18
+ lazySchema,
19
+ zodSchema,
20
+ type InferSchema,
18
21
  combineHeaders,
19
22
  createEventSourceResponseHandler,
20
23
  createJsonResponseHandler,
@@ -294,7 +297,8 @@ export class AlibabaLanguageModel implements LanguageModelV3 {
294
297
  unified: 'other',
295
298
  raw: undefined,
296
299
  };
297
- let usage: z.infer<typeof alibabaUsageSchema> | undefined = undefined;
300
+ let usage: z.infer<ReturnType<typeof alibabaUsageSchema>> | undefined =
301
+ undefined;
298
302
 
299
303
  let isFirstChunk = true;
300
304
  let activeText = false;
@@ -311,7 +315,7 @@ export class AlibabaLanguageModel implements LanguageModelV3 {
311
315
  return {
312
316
  stream: response.pipeThrough(
313
317
  new TransformStream<
314
- ParseResult<z.infer<typeof alibabaChatChunkSchema>>,
318
+ ParseResult<InferSchema<typeof alibabaChatChunkSchema>>,
315
319
  LanguageModelV3StreamPart
316
320
  >({
317
321
  start(controller) {
@@ -546,82 +550,91 @@ export class AlibabaLanguageModel implements LanguageModelV3 {
546
550
  * Reference for schemas below:
547
551
  * https://www.alibabacloud.com/help/en/model-studio/qwen-api-via-openai-chat-completions
548
552
  */
549
- const alibabaUsageSchema = z.object({
550
- prompt_tokens: z.number(),
551
- completion_tokens: z.number(),
552
- total_tokens: z.number(),
553
- prompt_tokens_details: z
554
- .object({
555
- cached_tokens: z.number().nullish(),
556
- cache_creation_input_tokens: z.number().nullish(),
557
- })
558
- .nullish(),
559
- completion_tokens_details: z
560
- .object({
561
- reasoning_tokens: z.number().nullish(),
562
- })
563
- .nullish(),
564
- });
565
-
566
- const alibabaChatResponseSchema = z.object({
567
- id: z.string().nullish(),
568
- created: z.number().nullish(),
569
- model: z.string().nullish(),
570
- choices: z.array(
553
+ const alibabaUsageSchema = () =>
554
+ z.object({
555
+ prompt_tokens: z.number(),
556
+ completion_tokens: z.number(),
557
+ total_tokens: z.number(),
558
+ prompt_tokens_details: z
559
+ .object({
560
+ cached_tokens: z.number().nullish(),
561
+ cache_creation_input_tokens: z.number().nullish(),
562
+ })
563
+ .nullish(),
564
+ completion_tokens_details: z
565
+ .object({
566
+ reasoning_tokens: z.number().nullish(),
567
+ })
568
+ .nullish(),
569
+ });
570
+
571
+ const alibabaChatResponseSchema = lazySchema(() =>
572
+ zodSchema(
571
573
  z.object({
572
- message: z.object({
573
- role: z.literal('assistant').nullish(),
574
- content: z.string().nullish(),
575
- reasoning_content: z.string().nullish(), // Alibaba thinking mode
576
- tool_calls: z
577
- .array(
578
- z.object({
579
- id: z.string(),
580
- type: z.literal('function'),
581
- function: z.object({
582
- name: z.string(),
583
- arguments: z.string(),
584
- }),
585
- }),
586
- )
587
- .nullish(),
588
- }),
589
- finish_reason: z.string().nullish(),
590
- index: z.number(),
574
+ id: z.string().nullish(),
575
+ created: z.number().nullish(),
576
+ model: z.string().nullish(),
577
+ choices: z.array(
578
+ z.object({
579
+ message: z.object({
580
+ role: z.literal('assistant').nullish(),
581
+ content: z.string().nullish(),
582
+ reasoning_content: z.string().nullish(), // Alibaba thinking mode
583
+ tool_calls: z
584
+ .array(
585
+ z.object({
586
+ id: z.string(),
587
+ type: z.literal('function'),
588
+ function: z.object({
589
+ name: z.string(),
590
+ arguments: z.string(),
591
+ }),
592
+ }),
593
+ )
594
+ .nullish(),
595
+ }),
596
+ finish_reason: z.string().nullish(),
597
+ index: z.number(),
598
+ }),
599
+ ),
600
+ usage: alibabaUsageSchema().nullish(),
591
601
  }),
592
602
  ),
593
- usage: alibabaUsageSchema.nullish(),
594
- });
595
-
596
- const alibabaChatChunkSchema = z.object({
597
- id: z.string().nullish(),
598
- created: z.number().nullish(),
599
- model: z.string().nullish(),
600
- choices: z.array(
603
+ );
604
+
605
+ const alibabaChatChunkSchema = lazySchema(() =>
606
+ zodSchema(
601
607
  z.object({
602
- delta: z.object({
603
- role: z.enum(['assistant']).nullish(),
604
- content: z.string().nullish(),
605
- reasoning_content: z.string().nullish(), // Alibaba thinking mode delta
606
- tool_calls: z
607
- .array(
608
- z.object({
609
- index: z.number().nullish(), // Index for accumulating tool calls
610
- id: z.string().nullish(),
611
- type: z.literal('function').nullish(),
612
- function: z
613
- .object({
614
- name: z.string().nullish(),
615
- arguments: z.string().nullish(),
616
- })
617
- .nullish(),
618
- }),
619
- )
620
- .nullish(),
621
- }),
622
- finish_reason: z.string().nullish(),
623
- index: z.number(),
608
+ id: z.string().nullish(),
609
+ created: z.number().nullish(),
610
+ model: z.string().nullish(),
611
+ choices: z.array(
612
+ z.object({
613
+ delta: z.object({
614
+ role: z.enum(['assistant']).nullish(),
615
+ content: z.string().nullish(),
616
+ reasoning_content: z.string().nullish(), // Alibaba thinking mode delta
617
+ tool_calls: z
618
+ .array(
619
+ z.object({
620
+ index: z.number().nullish(), // Index for accumulating tool calls
621
+ id: z.string().nullish(),
622
+ type: z.literal('function').nullish(),
623
+ function: z
624
+ .object({
625
+ name: z.string().nullish(),
626
+ arguments: z.string().nullish(),
627
+ })
628
+ .nullish(),
629
+ }),
630
+ )
631
+ .nullish(),
632
+ }),
633
+ finish_reason: z.string().nullish(),
634
+ index: z.number(),
635
+ }),
636
+ ),
637
+ usage: alibabaUsageSchema().nullish(), // Usage only appears in final chunk
624
638
  }),
625
639
  ),
626
- usage: alibabaUsageSchema.nullish(), // Usage only appears in final chunk
627
- });
640
+ );
@@ -1,3 +1,8 @@
1
+ import {
2
+ lazySchema,
3
+ zodSchema,
4
+ type InferSchema,
5
+ } from '@ai-sdk/provider-utils';
1
6
  import { z } from 'zod/v4';
2
7
 
3
8
  // https://www.alibabacloud.com/help/en/model-studio/models
@@ -29,38 +34,42 @@ export type AlibabaChatModelId =
29
34
  | 'qwen3-coder-flash'
30
35
  | (string & {});
31
36
 
32
- export const alibabaLanguageModelOptions = z.object({
33
- /**
34
- * Enable thinking/reasoning mode for supported models.
35
- * When enabled, the model generates reasoning content before the response.
36
- *
37
- * @default false
38
- */
39
- enableThinking: z.boolean().optional(),
37
+ export const alibabaLanguageModelOptions = lazySchema(() =>
38
+ zodSchema(
39
+ z.object({
40
+ /**
41
+ * Enable thinking/reasoning mode for supported models.
42
+ * When enabled, the model generates reasoning content before the response.
43
+ *
44
+ * @default false
45
+ */
46
+ enableThinking: z.boolean().optional(),
40
47
 
41
- /**
42
- * Maximum number of reasoning tokens to generate.
43
- */
44
- thinkingBudget: z.number().positive().optional(),
48
+ /**
49
+ * Maximum number of reasoning tokens to generate.
50
+ */
51
+ thinkingBudget: z.number().positive().optional(),
45
52
 
46
- /**
47
- * Whether to preserve reasoning from previous assistant messages.
48
- *
49
- * When enabled, historical reasoning is sent separately as
50
- * `reasoning_content` and Alibaba receives `preserve_thinking: true`.
51
- * Defaults to `true` for models that support preserved thinking; set to
52
- * `false` to opt out.
53
- */
54
- preserveThinking: z.boolean().optional(),
53
+ /**
54
+ * Whether to preserve reasoning from previous assistant messages.
55
+ *
56
+ * When enabled, historical reasoning is sent separately as
57
+ * `reasoning_content` and Alibaba receives `preserve_thinking: true`.
58
+ * Defaults to `true` for models that support preserved thinking; set to
59
+ * `false` to opt out.
60
+ */
61
+ preserveThinking: z.boolean().optional(),
55
62
 
56
- /**
57
- * Whether to enable parallel function calling during tool use.
58
- *
59
- * @default true
60
- */
61
- parallelToolCalls: z.boolean().optional(),
62
- });
63
+ /**
64
+ * Whether to enable parallel function calling during tool use.
65
+ *
66
+ * @default true
67
+ */
68
+ parallelToolCalls: z.boolean().optional(),
69
+ }),
70
+ ),
71
+ );
63
72
 
64
- export type AlibabaLanguageModelOptions = z.infer<
73
+ export type AlibabaLanguageModelOptions = InferSchema<
65
74
  typeof alibabaLanguageModelOptions
66
75
  >;
@@ -4,6 +4,8 @@ import {
4
4
  type EmbeddingModelV3,
5
5
  } from '@ai-sdk/provider';
6
6
  import {
7
+ lazySchema,
8
+ zodSchema,
7
9
  combineHeaders,
8
10
  createJsonErrorResponseHandler,
9
11
  createJsonResponseHandler,
@@ -135,27 +137,32 @@ export class AlibabaEmbeddingModel implements EmbeddingModelV3 {
135
137
  }
136
138
  }
137
139
 
138
- const alibabaTextEmbeddingSparseEmbeddingSchema = z.object({
139
- index: z.number(),
140
- value: z.number(),
141
- token: z.string().nullish(),
142
- });
140
+ const alibabaTextEmbeddingSparseEmbeddingSchema = () =>
141
+ z.object({
142
+ index: z.number(),
143
+ value: z.number(),
144
+ token: z.string().nullish(),
145
+ });
143
146
 
144
- const alibabaTextEmbeddingResponseSchema = z.object({
145
- output: z.object({
146
- embeddings: z.array(
147
- z.object({
148
- embedding: z.array(z.number()),
149
- text_index: z.number(),
150
- sparse_embedding: z
151
- .array(alibabaTextEmbeddingSparseEmbeddingSchema)
152
- .nullish(),
147
+ const alibabaTextEmbeddingResponseSchema = lazySchema(() =>
148
+ zodSchema(
149
+ z.object({
150
+ output: z.object({
151
+ embeddings: z.array(
152
+ z.object({
153
+ embedding: z.array(z.number()),
154
+ text_index: z.number(),
155
+ sparse_embedding: z
156
+ .array(alibabaTextEmbeddingSparseEmbeddingSchema())
157
+ .nullish(),
158
+ }),
159
+ ),
153
160
  }),
154
- ),
155
- }),
156
- usage: z
157
- .object({
158
- total_tokens: z.number(),
159
- })
160
- .nullish(),
161
- });
161
+ usage: z
162
+ .object({
163
+ total_tokens: z.number(),
164
+ })
165
+ .nullish(),
166
+ }),
167
+ ),
168
+ );
@@ -1,3 +1,8 @@
1
+ import {
2
+ lazySchema,
3
+ zodSchema,
4
+ type InferSchema,
5
+ } from '@ai-sdk/provider-utils';
1
6
  import { z } from 'zod/v4';
2
7
 
3
8
  export type AlibabaEmbeddingModelId =
@@ -5,29 +10,33 @@ export type AlibabaEmbeddingModelId =
5
10
  | 'text-embedding-v3'
6
11
  | (string & {});
7
12
 
8
- export const alibabaEmbeddingModelOptions = z.object({
9
- /**
10
- * Differentiates query text from document text for asymmetric retrieval tasks.
11
- * Defaults to `document`.
12
- */
13
- textType: z.enum(['query', 'document']).optional(),
13
+ export const alibabaEmbeddingModelOptions = lazySchema(() =>
14
+ zodSchema(
15
+ z.object({
16
+ /**
17
+ * Differentiates query text from document text for asymmetric retrieval tasks.
18
+ * Defaults to `document`.
19
+ */
20
+ textType: z.enum(['query', 'document']).optional(),
14
21
 
15
- /**
16
- * The dimension of the output embedding vectors. Defaults to 1024.
17
- *
18
- * `text-embedding-v4` also supports 1536 and 2048 dimensions.
19
- */
20
- dimension: z.number().optional(),
22
+ /**
23
+ * The dimension of the output embedding vectors. Defaults to 1024.
24
+ *
25
+ * `text-embedding-v4` also supports 1536 and 2048 dimensions.
26
+ */
27
+ dimension: z.number().optional(),
21
28
 
22
- /**
23
- * The output vector type. Defaults to `dense`.
24
- *
25
- * Sparse-only output is not supported by the AI SDK embedding interface,
26
- * which requires dense number arrays.
27
- */
28
- outputType: z.enum(['dense', 'sparse', 'dense&sparse']).optional(),
29
- });
29
+ /**
30
+ * The output vector type. Defaults to `dense`.
31
+ *
32
+ * Sparse-only output is not supported by the AI SDK embedding interface,
33
+ * which requires dense number arrays.
34
+ */
35
+ outputType: z.enum(['dense', 'sparse', 'dense&sparse']).optional(),
36
+ }),
37
+ ),
38
+ );
30
39
 
31
- export type AlibabaEmbeddingModelOptions = z.infer<
40
+ export type AlibabaEmbeddingModelOptions = InferSchema<
32
41
  typeof alibabaEmbeddingModelOptions
33
42
  >;
@@ -1,15 +1,24 @@
1
- import { createJsonErrorResponseHandler } from '@ai-sdk/provider-utils';
1
+ import {
2
+ lazySchema,
3
+ zodSchema,
4
+ type InferSchema,
5
+ createJsonErrorResponseHandler,
6
+ } from '@ai-sdk/provider-utils';
2
7
  import { z } from 'zod/v4';
3
8
 
4
- const alibabaErrorDataSchema = z.object({
5
- error: z.object({
6
- message: z.string(),
7
- code: z.string().nullish(),
8
- type: z.string().nullish(),
9
- }),
10
- });
9
+ const alibabaErrorDataSchema = lazySchema(() =>
10
+ zodSchema(
11
+ z.object({
12
+ error: z.object({
13
+ message: z.string(),
14
+ code: z.string().nullish(),
15
+ type: z.string().nullish(),
16
+ }),
17
+ }),
18
+ ),
19
+ );
11
20
 
12
- export type AlibabaErrorData = z.infer<typeof alibabaErrorDataSchema>;
21
+ export type AlibabaErrorData = InferSchema<typeof alibabaErrorDataSchema>;
13
22
 
14
23
  export const alibabaFailedResponseHandler = createJsonErrorResponseHandler({
15
24
  errorSchema: alibabaErrorDataSchema,
@@ -5,6 +5,7 @@ import {
5
5
  type SharedV3Warning,
6
6
  } from '@ai-sdk/provider';
7
7
  import {
8
+ type InferSchema,
8
9
  combineHeaders,
9
10
  convertImageModelFileToDataUri,
10
11
  convertUint8ArrayToBase64,
@@ -12,6 +13,7 @@ import {
12
13
  createJsonResponseHandler,
13
14
  delay,
14
15
  type FetchFunction,
16
+ encodePathSegment,
15
17
  getFromApi,
16
18
  lazySchema,
17
19
  parseProviderOptions,
@@ -130,58 +132,70 @@ interface AlibabaVideoModelConfig {
130
132
  }
131
133
 
132
134
  // DashScope native API error format (different from OpenAI-compatible endpoint)
133
- const alibabaVideoErrorSchema = z.object({
134
- code: z.string().nullish(),
135
- message: z.string(),
136
- request_id: z.string().nullish(),
137
- });
135
+ const alibabaVideoErrorSchema = lazySchema(() =>
136
+ zodSchema(
137
+ z.object({
138
+ code: z.string().nullish(),
139
+ message: z.string(),
140
+ request_id: z.string().nullish(),
141
+ }),
142
+ ),
143
+ );
138
144
 
139
145
  const alibabaVideoFailedResponseHandler = createJsonErrorResponseHandler({
140
146
  errorSchema: alibabaVideoErrorSchema,
141
147
  errorToMessage: data => data.message,
142
148
  });
143
149
 
144
- const alibabaVideoCreateTaskSchema = z.object({
145
- output: z
146
- .object({
147
- task_status: z.string(),
148
- task_id: z.string(),
149
- })
150
- .nullish(),
151
- request_id: z.string().nullish(),
152
- });
150
+ const alibabaVideoCreateTaskSchema = lazySchema(() =>
151
+ zodSchema(
152
+ z.object({
153
+ output: z
154
+ .object({
155
+ task_status: z.string(),
156
+ task_id: z.string(),
157
+ })
158
+ .nullish(),
159
+ request_id: z.string().nullish(),
160
+ }),
161
+ ),
162
+ );
153
163
 
154
- const alibabaVideoTaskStatusSchema = z.object({
155
- output: z
156
- .object({
157
- task_id: z.string(),
158
- task_status: z.string(),
159
- video_url: z.string().nullish(),
160
- submit_time: z.string().nullish(),
161
- scheduled_time: z.string().nullish(),
162
- end_time: z.string().nullish(),
163
- orig_prompt: z.string().nullish(),
164
- actual_prompt: z.string().nullish(),
165
- code: z.string().nullish(),
166
- message: z.string().nullish(),
167
- })
168
- .nullish(),
169
- usage: z
170
- .object({
171
- duration: z.number().nullish(),
172
- output_video_duration: z.number().nullish(),
173
- // wan3 splits the total: input video counts toward its 30s ceiling.
174
- input_video_duration: z.number().nullish(),
175
- fps: z.number().nullish(),
176
- SR: z.number().nullish(),
177
- size: z.string().nullish(),
178
- ratio: z.string().nullish(),
179
- })
180
- .nullish(),
181
- request_id: z.string().nullish(),
182
- });
164
+ const alibabaVideoTaskStatusSchema = lazySchema(() =>
165
+ zodSchema(
166
+ z.object({
167
+ output: z
168
+ .object({
169
+ task_id: z.string(),
170
+ task_status: z.string(),
171
+ video_url: z.string().nullish(),
172
+ submit_time: z.string().nullish(),
173
+ scheduled_time: z.string().nullish(),
174
+ end_time: z.string().nullish(),
175
+ orig_prompt: z.string().nullish(),
176
+ actual_prompt: z.string().nullish(),
177
+ code: z.string().nullish(),
178
+ message: z.string().nullish(),
179
+ })
180
+ .nullish(),
181
+ usage: z
182
+ .object({
183
+ duration: z.number().nullish(),
184
+ output_video_duration: z.number().nullish(),
185
+ // wan3 splits the total: input video counts toward its 30s ceiling.
186
+ input_video_duration: z.number().nullish(),
187
+ fps: z.number().nullish(),
188
+ SR: z.number().nullish(),
189
+ size: z.string().nullish(),
190
+ ratio: z.string().nullish(),
191
+ })
192
+ .nullish(),
193
+ request_id: z.string().nullish(),
194
+ }),
195
+ ),
196
+ );
183
197
 
184
- type AlibabaVideoTaskStatusResponse = z.infer<
198
+ type AlibabaVideoTaskStatusResponse = InferSchema<
185
199
  typeof alibabaVideoTaskStatusSchema
186
200
  >;
187
201
 
@@ -667,7 +681,7 @@ export class AlibabaVideoModel implements Experimental_VideoModelV3 {
667
681
 
668
682
  const { value: statusResponse, responseHeaders: pollHeaders } =
669
683
  await getFromApi({
670
- url: `${this.config.baseURL}/api/v1/tasks/${taskId}`,
684
+ url: `${this.config.baseURL}/api/v1/tasks/${encodePathSegment(taskId)}`,
671
685
  headers: combineHeaders(
672
686
  await resolve(this.config.headers),
673
687
  options.headers,