@ai-sdk/deepseek 3.0.69 → 3.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.
@@ -1,4 +1,8 @@
1
- import { lazySchema, zodSchema } from '@ai-sdk/provider-utils';
1
+ import {
2
+ type InferSchema,
3
+ lazySchema,
4
+ zodSchema,
5
+ } from '@ai-sdk/provider-utils';
2
6
  import { z } from 'zod/v4';
3
7
 
4
8
  export type DeepSeekChatPrompt = Array<DeepSeekMessage>;
@@ -92,95 +96,135 @@ export type DeepSeekToolChoice =
92
96
  | undefined;
93
97
 
94
98
  // Loose, nested objects included: the parsed value is returned as `usage.raw`.
95
- const tokenUsageSchema = z
96
- .looseObject({
97
- prompt_tokens: z.number().nullish(),
98
- completion_tokens: z.number().nullish(),
99
- prompt_cache_hit_tokens: z.number().nullish(),
100
- prompt_cache_miss_tokens: z.number().nullish(),
101
- total_tokens: z.number().nullish(),
102
- prompt_tokens_details: z
103
- .looseObject({
104
- cached_tokens: z.number().nullish(),
105
- })
106
- .nullish(),
107
- completion_tokens_details: z
108
- .looseObject({
109
- reasoning_tokens: z.number().nullish(),
110
- })
111
- .nullish(),
112
- })
113
- .nullish();
114
-
115
- export type DeepSeekChatTokenUsage = z.infer<typeof tokenUsageSchema>;
116
-
117
- export const deepSeekErrorSchema = z.object({
118
- error: z.object({
119
- message: z.string(),
120
- type: z.string().nullish(),
121
- param: z.any().nullish(),
122
- code: z.union([z.string(), z.number()]).nullish(),
123
- }),
124
- });
125
-
126
- export type DeepSeekErrorData = z.infer<typeof deepSeekErrorSchema>;
127
-
128
- const deepseekChatLogprobSchema = z.object({
129
- token: z.string(),
130
- logprob: z.number(),
131
- bytes: z.array(z.number()).nullable(),
132
- top_logprobs: z.array(
133
- z.object({
134
- token: z.string(),
135
- logprob: z.number(),
136
- bytes: z.array(z.number()).nullable(),
99
+ function createTokenUsageSchema() {
100
+ return z
101
+ .looseObject({
102
+ prompt_tokens: z.number().nullish(),
103
+ completion_tokens: z.number().nullish(),
104
+ prompt_cache_hit_tokens: z.number().nullish(),
105
+ prompt_cache_miss_tokens: z.number().nullish(),
106
+ total_tokens: z.number().nullish(),
107
+ prompt_tokens_details: z
108
+ .looseObject({
109
+ cached_tokens: z.number().nullish(),
110
+ })
111
+ .nullish(),
112
+ completion_tokens_details: z
113
+ .looseObject({
114
+ reasoning_tokens: z.number().nullish(),
115
+ })
116
+ .nullish(),
117
+ })
118
+ .nullish();
119
+ }
120
+
121
+ let tokenUsageSchema: ReturnType<typeof createTokenUsageSchema> | undefined;
122
+
123
+ function getTokenUsageSchema() {
124
+ return (tokenUsageSchema ??= createTokenUsageSchema());
125
+ }
126
+
127
+ export type DeepSeekChatTokenUsage = z.infer<
128
+ ReturnType<typeof getTokenUsageSchema>
129
+ >;
130
+
131
+ function createDeepSeekErrorSchema() {
132
+ return z.object({
133
+ error: z.object({
134
+ message: z.string(),
135
+ type: z.string().nullish(),
136
+ param: z.any().nullish(),
137
+ code: z.union([z.string(), z.number()]).nullish(),
137
138
  }),
138
- ),
139
- });
139
+ });
140
+ }
141
+
142
+ let errorSchema: ReturnType<typeof createDeepSeekErrorSchema> | undefined;
143
+
144
+ function getDeepSeekErrorSchema() {
145
+ return (errorSchema ??= createDeepSeekErrorSchema());
146
+ }
147
+
148
+ export const deepSeekErrorSchema = lazySchema(() =>
149
+ zodSchema(getDeepSeekErrorSchema()),
150
+ );
140
151
 
141
- const deepseekChatLogprobsSchema = z
142
- .object({
143
- content: z.array(deepseekChatLogprobSchema).nullish(),
144
- reasoning_content: z.array(deepseekChatLogprobSchema).nullish(),
145
- })
146
- .nullish();
152
+ export type DeepSeekErrorData = InferSchema<typeof deepSeekErrorSchema>;
147
153
 
148
- export type DeepSeekChatLogprob = z.infer<typeof deepseekChatLogprobSchema>;
154
+ function createDeepseekChatLogprobsSchema() {
155
+ const deepseekChatLogprobSchema = z.object({
156
+ token: z.string(),
157
+ logprob: z.number(),
158
+ bytes: z.array(z.number()).nullable(),
159
+ top_logprobs: z.array(
160
+ z.object({
161
+ token: z.string(),
162
+ logprob: z.number(),
163
+ bytes: z.array(z.number()).nullable(),
164
+ }),
165
+ ),
166
+ });
167
+
168
+ return z
169
+ .object({
170
+ content: z.array(deepseekChatLogprobSchema).nullish(),
171
+ reasoning_content: z.array(deepseekChatLogprobSchema).nullish(),
172
+ })
173
+ .nullish();
174
+ }
175
+
176
+ let logprobsSchema:
177
+ | ReturnType<typeof createDeepseekChatLogprobsSchema>
178
+ | undefined;
179
+
180
+ function getDeepseekChatLogprobsSchema() {
181
+ return (logprobsSchema ??= createDeepseekChatLogprobsSchema());
182
+ }
183
+
184
+ export type DeepSeekChatLogprob = NonNullable<
185
+ NonNullable<
186
+ z.infer<ReturnType<typeof getDeepseekChatLogprobsSchema>>
187
+ >['content']
188
+ >[number];
149
189
 
150
190
  // limited version of the schema, focussed on what is needed for the implementation
151
191
  // this approach limits breakages when the API changes and increases efficiency
152
- export const deepseekChatResponseSchema = z.object({
153
- id: z.string().nullish(),
154
- created: z.number().nullish(),
155
- model: z.string().nullish(),
156
- object: z.literal('chat.completion').nullish(),
157
- system_fingerprint: z.string().nullish(),
158
- choices: z.array(
192
+ export const deepseekChatResponseSchema = lazySchema(() =>
193
+ zodSchema(
159
194
  z.object({
160
- index: z.number().nullish(),
161
- message: z.object({
162
- role: z.literal('assistant').nullish(),
163
- content: z.string().nullish(),
164
- reasoning_content: z.string().nullish(),
165
- tool_calls: z
166
- .array(
167
- z.object({
168
- id: z.string().nullish(),
169
- type: z.literal('function').nullish(),
170
- function: z.object({
171
- name: z.string(),
172
- arguments: z.string(),
173
- }),
174
- }),
175
- )
176
- .nullish(),
177
- }),
178
- logprobs: deepseekChatLogprobsSchema,
179
- finish_reason: z.string().nullish(),
195
+ id: z.string().nullish(),
196
+ created: z.number().nullish(),
197
+ model: z.string().nullish(),
198
+ object: z.literal('chat.completion').nullish(),
199
+ system_fingerprint: z.string().nullish(),
200
+ choices: z.array(
201
+ z.object({
202
+ index: z.number().nullish(),
203
+ message: z.object({
204
+ role: z.literal('assistant').nullish(),
205
+ content: z.string().nullish(),
206
+ reasoning_content: z.string().nullish(),
207
+ tool_calls: z
208
+ .array(
209
+ z.object({
210
+ id: z.string().nullish(),
211
+ type: z.literal('function').nullish(),
212
+ function: z.object({
213
+ name: z.string(),
214
+ arguments: z.string(),
215
+ }),
216
+ }),
217
+ )
218
+ .nullish(),
219
+ }),
220
+ logprobs: getDeepseekChatLogprobsSchema(),
221
+ finish_reason: z.string().nullish(),
222
+ }),
223
+ ),
224
+ usage: getTokenUsageSchema(),
180
225
  }),
181
226
  ),
182
- usage: tokenUsageSchema,
183
- });
227
+ );
184
228
 
185
229
  // limited version of the schema, focussed on what is needed for the implementation
186
230
  // this approach limits breakages when the API changes and increases efficiency
@@ -216,13 +260,13 @@ export const deepseekChatChunkSchema = lazySchema(() =>
216
260
  .nullish(),
217
261
  })
218
262
  .nullish(),
219
- logprobs: deepseekChatLogprobsSchema,
263
+ logprobs: getDeepseekChatLogprobsSchema(),
220
264
  finish_reason: z.string().nullish(),
221
265
  }),
222
266
  ),
223
- usage: tokenUsageSchema,
267
+ usage: getTokenUsageSchema(),
224
268
  }),
225
- deepSeekErrorSchema,
269
+ getDeepSeekErrorSchema(),
226
270
  ]),
227
271
  ),
228
272
  );
@@ -1,3 +1,8 @@
1
+ import {
2
+ type InferSchema,
3
+ lazySchema,
4
+ zodSchema,
5
+ } from '@ai-sdk/provider-utils';
1
6
  import { z } from 'zod/v4';
2
7
 
3
8
  // https://api-docs.deepseek.com/quick_start/pricing
@@ -10,59 +15,75 @@ export type DeepSeekChatModelId =
10
15
  // intentionally omitted from first-class editor suggestions.
11
16
  | (string & {});
12
17
 
13
- export const deepseekLanguageModelChatOptions = z.object({
14
- /**
15
- * Whether to return log probabilities for generated tokens.
16
- */
17
- logprobs: z.boolean().optional(),
18
+ function createDeepseekChatOptionsSchema() {
19
+ return z.object({
20
+ /**
21
+ * Whether to return log probabilities for generated tokens.
22
+ */
23
+ logprobs: z.boolean().optional(),
18
24
 
19
- /**
20
- * Number of most likely tokens to return at each token position.
21
- *
22
- * Setting this option automatically enables `logprobs`.
23
- */
24
- topLogprobs: z.number().int().min(0).max(20).optional(),
25
+ /**
26
+ * Number of most likely tokens to return at each token position.
27
+ *
28
+ * Setting this option automatically enables `logprobs`.
29
+ */
30
+ topLogprobs: z.number().int().min(0).max(20).optional(),
25
31
 
26
- /**
27
- * An opaque identifier for the end user. DeepSeek uses this identifier for
28
- * content-safety tracing and request isolation.
29
- *
30
- * Must contain only ASCII letters, numbers, underscores, and hyphens, and
31
- * must be at most 512 characters long.
32
- */
33
- userId: z
34
- .string()
35
- .regex(/^[a-zA-Z0-9_-]+$/, 'userId must match /^[a-zA-Z0-9_-]+$/')
36
- .max(512, 'userId must be at most 512 characters long')
37
- .optional(),
32
+ /**
33
+ * An opaque identifier for the end user. DeepSeek uses this identifier for
34
+ * content-safety tracing and request isolation.
35
+ *
36
+ * Must contain only ASCII letters, numbers, underscores, and hyphens, and
37
+ * must be at most 512 characters long.
38
+ */
39
+ userId: z
40
+ .string()
41
+ .regex(/^[a-zA-Z0-9_-]+$/, 'userId must match /^[a-zA-Z0-9_-]+$/')
42
+ .max(512, 'userId must be at most 512 characters long')
43
+ .optional(),
38
44
 
39
- /**
40
- * Type of thinking to use. Defaults to `enabled`.
41
- */
42
- thinking: z
43
- .object({
44
- // `adaptive` is accepted at runtime for backwards compatibility and
45
- // mapped to `enabled`, but is intentionally excluded from the exported
46
- // provider options type.
47
- type: z.enum(['adaptive', 'enabled', 'disabled']).optional(),
48
- })
49
- .optional(),
45
+ /**
46
+ * Type of thinking to use. Defaults to `enabled`.
47
+ */
48
+ thinking: z
49
+ .object({
50
+ // `adaptive` is accepted at runtime for backwards compatibility and
51
+ // mapped to `enabled`, but is intentionally excluded from the exported
52
+ // provider options type.
53
+ type: z.enum(['adaptive', 'enabled', 'disabled']).optional(),
54
+ })
55
+ .optional(),
50
56
 
51
- /**
52
- * Controls the thinking strength for DeepSeek V4 reasoning models.
53
- */
54
- // `medium` and `xhigh` are accepted at runtime for backwards compatibility
55
- // and mapped to canonical DeepSeek values, but are intentionally excluded
56
- // from the exported provider options type.
57
- reasoningEffort: z.enum(['low', 'medium', 'high', 'xhigh', 'max']).optional(),
57
+ /**
58
+ * Controls the thinking strength for DeepSeek V4 reasoning models.
59
+ */
60
+ // `medium` and `xhigh` are accepted at runtime for backwards compatibility
61
+ // and mapped to canonical DeepSeek values, but are intentionally excluded
62
+ // from the exported provider options type.
63
+ reasoningEffort: z
64
+ .enum(['low', 'medium', 'high', 'xhigh', 'max'])
65
+ .optional(),
58
66
 
59
- /**
60
- * Whether to use strict JSON schema validation for structured outputs.
61
- * Only applies when the serving endpoint supports JSON schema response
62
- * formats (e.g. Azure). Defaults to `true`.
63
- */
64
- strictJsonSchema: z.boolean().optional(),
65
- });
67
+ /**
68
+ * Whether to use strict JSON schema validation for structured outputs.
69
+ * Only applies when the serving endpoint supports JSON schema response
70
+ * formats (e.g. Azure). Defaults to `true`.
71
+ */
72
+ strictJsonSchema: z.boolean().optional(),
73
+ });
74
+ }
75
+
76
+ let chatOptionsSchema:
77
+ | ReturnType<typeof createDeepseekChatOptionsSchema>
78
+ | undefined;
79
+
80
+ export function getDeepseekChatOptionsSchema() {
81
+ return (chatOptionsSchema ??= createDeepseekChatOptionsSchema());
82
+ }
83
+
84
+ export const deepseekLanguageModelChatOptions = lazySchema(() =>
85
+ zodSchema(getDeepseekChatOptionsSchema()),
86
+ );
66
87
 
67
88
  export type DeepSeekLanguageModelChatOptions = {
68
89
  /**
@@ -106,21 +127,35 @@ export type DeepSeekLanguageModelChatOptions = {
106
127
  strictJsonSchema?: boolean;
107
128
  };
108
129
 
109
- export const deepseekMessageProviderOptions = z.object({
110
- /**
111
- * The name of the participant represented by the message.
112
- *
113
- * Supported on system, user, and assistant messages.
114
- */
115
- name: z.string().optional(),
116
- });
130
+ function createDeepseekMessageOptionsSchema() {
131
+ return z.object({
132
+ /**
133
+ * The name of the participant represented by the message.
134
+ *
135
+ * Supported on system, user, and assistant messages.
136
+ */
137
+ name: z.string().optional(),
138
+ });
139
+ }
117
140
 
118
- export type DeepSeekMessageProviderOptions = z.infer<
141
+ let messageOptionsSchema:
142
+ | ReturnType<typeof createDeepseekMessageOptionsSchema>
143
+ | undefined;
144
+
145
+ export function getDeepseekMessageOptionsSchema() {
146
+ return (messageOptionsSchema ??= createDeepseekMessageOptionsSchema());
147
+ }
148
+
149
+ export const deepseekMessageProviderOptions = lazySchema(() =>
150
+ zodSchema(getDeepseekMessageOptionsSchema()),
151
+ );
152
+
153
+ export type DeepSeekMessageProviderOptions = InferSchema<
119
154
  typeof deepseekMessageProviderOptions
120
155
  >;
121
156
 
122
- export const deepseekAssistantMessageProviderOptions =
123
- deepseekMessageProviderOptions.extend({
157
+ function createDeepseekAssistantMessageOptionsSchema() {
158
+ return getDeepseekMessageOptionsSchema().extend({
124
159
  /**
125
160
  * Whether the assistant message content is a prefix that DeepSeek should
126
161
  * continue. This beta feature is only supported on the final assistant
@@ -128,7 +163,21 @@ export const deepseekAssistantMessageProviderOptions =
128
163
  */
129
164
  prefix: z.literal(true).optional(),
130
165
  });
166
+ }
167
+
168
+ let assistantMessageOptionsSchema:
169
+ | ReturnType<typeof createDeepseekAssistantMessageOptionsSchema>
170
+ | undefined;
171
+
172
+ export function getDeepseekAssistantMessageOptionsSchema() {
173
+ return (assistantMessageOptionsSchema ??=
174
+ createDeepseekAssistantMessageOptionsSchema());
175
+ }
176
+
177
+ export const deepseekAssistantMessageProviderOptions = lazySchema(() =>
178
+ zodSchema(getDeepseekAssistantMessageOptionsSchema()),
179
+ );
131
180
 
132
- export type DeepSeekAssistantMessageProviderOptions = z.infer<
181
+ export type DeepSeekAssistantMessageProviderOptions = InferSchema<
133
182
  typeof deepseekAssistantMessageProviderOptions
134
183
  >;
@@ -1,24 +1,33 @@
1
+ import {
2
+ type InferSchema,
3
+ lazySchema,
4
+ zodSchema,
5
+ } from '@ai-sdk/provider-utils';
1
6
  import { z } from 'zod/v4';
2
7
 
3
- export const deepseekFilePartProviderOptions = z.object({
4
- /**
5
- * Controls how DeepSeek processes an image sent as an `image_url` part.
6
- *
7
- * @see https://api-docs.deepseek.com/api/create-chat-completion/
8
- */
9
- imageDetail: z.enum(['low', 'high', 'original', 'auto']).optional(),
8
+ export const deepseekFilePartProviderOptions = lazySchema(() =>
9
+ zodSchema(
10
+ z.object({
11
+ /**
12
+ * Controls how DeepSeek processes an image sent as an `image_url` part.
13
+ *
14
+ * @see https://api-docs.deepseek.com/api/create-chat-completion/
15
+ */
16
+ imageDetail: z.enum(['low', 'high', 'original', 'auto']).optional(),
10
17
 
11
- /**
12
- * Sends inline image data as a DeepSeek `file` part using `file_data`
13
- * instead of an `image_url` data URL. When set, the file part's filename
14
- * is preserved.
15
- *
16
- * This option only applies to inline image data. It cannot be combined
17
- * with `imageDetail`.
18
- */
19
- fileData: z.literal(true).optional(),
20
- });
18
+ /**
19
+ * Sends inline image data as a DeepSeek `file` part using `file_data`
20
+ * instead of an `image_url` data URL. When set, the file part's filename
21
+ * is preserved.
22
+ *
23
+ * This option only applies to inline image data. It cannot be combined
24
+ * with `imageDetail`.
25
+ */
26
+ fileData: z.literal(true).optional(),
27
+ }),
28
+ ),
29
+ );
21
30
 
22
- export type DeepSeekFilePartProviderOptions = z.infer<
31
+ export type DeepSeekFilePartProviderOptions = InferSchema<
23
32
  typeof deepseekFilePartProviderOptions
24
33
  >;
@@ -1,2 +1,19 @@
1
+ import {
2
+ getDeepseekAssistantMessageOptionsSchema,
3
+ getDeepseekChatOptionsSchema,
4
+ getDeepseekMessageOptionsSchema,
5
+ } from '../chat/deepseek-chat-language-model-options';
6
+
1
7
  export * from '../chat/deepseek-chat-language-model';
2
- export * from '../chat/deepseek-chat-language-model-options';
8
+ export type {
9
+ DeepSeekAssistantMessageProviderOptions,
10
+ DeepSeekChatModelId,
11
+ DeepSeekLanguageModelChatOptions,
12
+ DeepSeekMessageProviderOptions,
13
+ } from '../chat/deepseek-chat-language-model-options';
14
+
15
+ // Preserve the Zod object exports for consumers of the internal entry point.
16
+ export const deepseekLanguageModelChatOptions = getDeepseekChatOptionsSchema();
17
+ export const deepseekMessageProviderOptions = getDeepseekMessageOptionsSchema();
18
+ export const deepseekAssistantMessageProviderOptions =
19
+ getDeepseekAssistantMessageOptionsSchema();