@ai-sdk/deepseek 2.0.76 → 2.0.78
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/CHANGELOG.md +16 -0
- package/dist/index.d.mts +25 -30
- package/dist/index.d.ts +25 -30
- package/dist/index.js +223 -165
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +213 -146
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +41 -31
- package/dist/internal/index.d.ts +41 -31
- package/dist/internal/index.js +229 -166
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +223 -151
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/chat/deepseek-chat-api-types.ts +128 -84
- package/src/chat/deepseek-chat-options.ts +109 -60
- package/src/chat/deepseek-file-part-options.ts +27 -18
- package/src/internal/index.ts +18 -1
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
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>;
|
|
@@ -86,95 +90,135 @@ export type DeepSeekToolChoice =
|
|
|
86
90
|
| undefined;
|
|
87
91
|
|
|
88
92
|
// Loose, nested objects included: the parsed value is returned as `usage.raw`.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
token: z.string(),
|
|
129
|
-
logprob: z.number(),
|
|
130
|
-
bytes: z.array(z.number()).nullable(),
|
|
93
|
+
function createTokenUsageSchema() {
|
|
94
|
+
return z
|
|
95
|
+
.looseObject({
|
|
96
|
+
prompt_tokens: z.number().nullish(),
|
|
97
|
+
completion_tokens: z.number().nullish(),
|
|
98
|
+
prompt_cache_hit_tokens: z.number().nullish(),
|
|
99
|
+
prompt_cache_miss_tokens: z.number().nullish(),
|
|
100
|
+
total_tokens: z.number().nullish(),
|
|
101
|
+
prompt_tokens_details: z
|
|
102
|
+
.looseObject({
|
|
103
|
+
cached_tokens: z.number().nullish(),
|
|
104
|
+
})
|
|
105
|
+
.nullish(),
|
|
106
|
+
completion_tokens_details: z
|
|
107
|
+
.looseObject({
|
|
108
|
+
reasoning_tokens: z.number().nullish(),
|
|
109
|
+
})
|
|
110
|
+
.nullish(),
|
|
111
|
+
})
|
|
112
|
+
.nullish();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
let tokenUsageSchema: ReturnType<typeof createTokenUsageSchema> | undefined;
|
|
116
|
+
|
|
117
|
+
function getTokenUsageSchema() {
|
|
118
|
+
return (tokenUsageSchema ??= createTokenUsageSchema());
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export type DeepSeekChatTokenUsage = z.infer<
|
|
122
|
+
ReturnType<typeof getTokenUsageSchema>
|
|
123
|
+
>;
|
|
124
|
+
|
|
125
|
+
function createDeepSeekErrorSchema() {
|
|
126
|
+
return z.object({
|
|
127
|
+
error: z.object({
|
|
128
|
+
message: z.string(),
|
|
129
|
+
type: z.string().nullish(),
|
|
130
|
+
param: z.any().nullish(),
|
|
131
|
+
code: z.union([z.string(), z.number()]).nullish(),
|
|
131
132
|
}),
|
|
132
|
-
)
|
|
133
|
-
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
let errorSchema: ReturnType<typeof createDeepSeekErrorSchema> | undefined;
|
|
137
|
+
|
|
138
|
+
function getDeepSeekErrorSchema() {
|
|
139
|
+
return (errorSchema ??= createDeepSeekErrorSchema());
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export const deepSeekErrorSchema = lazySchema(() =>
|
|
143
|
+
zodSchema(getDeepSeekErrorSchema()),
|
|
144
|
+
);
|
|
134
145
|
|
|
135
|
-
|
|
136
|
-
.object({
|
|
137
|
-
content: z.array(deepseekChatLogprobSchema).nullish(),
|
|
138
|
-
reasoning_content: z.array(deepseekChatLogprobSchema).nullish(),
|
|
139
|
-
})
|
|
140
|
-
.nullish();
|
|
146
|
+
export type DeepSeekErrorData = InferSchema<typeof deepSeekErrorSchema>;
|
|
141
147
|
|
|
142
|
-
|
|
148
|
+
function createDeepseekChatLogprobsSchema() {
|
|
149
|
+
const deepseekChatLogprobSchema = z.object({
|
|
150
|
+
token: z.string(),
|
|
151
|
+
logprob: z.number(),
|
|
152
|
+
bytes: z.array(z.number()).nullable(),
|
|
153
|
+
top_logprobs: z.array(
|
|
154
|
+
z.object({
|
|
155
|
+
token: z.string(),
|
|
156
|
+
logprob: z.number(),
|
|
157
|
+
bytes: z.array(z.number()).nullable(),
|
|
158
|
+
}),
|
|
159
|
+
),
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
return z
|
|
163
|
+
.object({
|
|
164
|
+
content: z.array(deepseekChatLogprobSchema).nullish(),
|
|
165
|
+
reasoning_content: z.array(deepseekChatLogprobSchema).nullish(),
|
|
166
|
+
})
|
|
167
|
+
.nullish();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
let logprobsSchema:
|
|
171
|
+
| ReturnType<typeof createDeepseekChatLogprobsSchema>
|
|
172
|
+
| undefined;
|
|
173
|
+
|
|
174
|
+
function getDeepseekChatLogprobsSchema() {
|
|
175
|
+
return (logprobsSchema ??= createDeepseekChatLogprobsSchema());
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export type DeepSeekChatLogprob = NonNullable<
|
|
179
|
+
NonNullable<
|
|
180
|
+
z.infer<ReturnType<typeof getDeepseekChatLogprobsSchema>>
|
|
181
|
+
>['content']
|
|
182
|
+
>[number];
|
|
143
183
|
|
|
144
184
|
// limited version of the schema, focussed on what is needed for the implementation
|
|
145
185
|
// this approach limits breakages when the API changes and increases efficiency
|
|
146
|
-
export const deepseekChatResponseSchema =
|
|
147
|
-
|
|
148
|
-
created: z.number().nullish(),
|
|
149
|
-
model: z.string().nullish(),
|
|
150
|
-
object: z.literal('chat.completion').nullish(),
|
|
151
|
-
system_fingerprint: z.string().nullish(),
|
|
152
|
-
choices: z.array(
|
|
186
|
+
export const deepseekChatResponseSchema = lazySchema(() =>
|
|
187
|
+
zodSchema(
|
|
153
188
|
z.object({
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
189
|
+
id: z.string().nullish(),
|
|
190
|
+
created: z.number().nullish(),
|
|
191
|
+
model: z.string().nullish(),
|
|
192
|
+
object: z.literal('chat.completion').nullish(),
|
|
193
|
+
system_fingerprint: z.string().nullish(),
|
|
194
|
+
choices: z.array(
|
|
195
|
+
z.object({
|
|
196
|
+
index: z.number().nullish(),
|
|
197
|
+
message: z.object({
|
|
198
|
+
role: z.literal('assistant').nullish(),
|
|
199
|
+
content: z.string().nullish(),
|
|
200
|
+
reasoning_content: z.string().nullish(),
|
|
201
|
+
tool_calls: z
|
|
202
|
+
.array(
|
|
203
|
+
z.object({
|
|
204
|
+
id: z.string().nullish(),
|
|
205
|
+
type: z.literal('function').nullish(),
|
|
206
|
+
function: z.object({
|
|
207
|
+
name: z.string(),
|
|
208
|
+
arguments: z.string(),
|
|
209
|
+
}),
|
|
210
|
+
}),
|
|
211
|
+
)
|
|
212
|
+
.nullish(),
|
|
213
|
+
}),
|
|
214
|
+
logprobs: getDeepseekChatLogprobsSchema(),
|
|
215
|
+
finish_reason: z.string().nullish(),
|
|
216
|
+
}),
|
|
217
|
+
),
|
|
218
|
+
usage: getTokenUsageSchema(),
|
|
174
219
|
}),
|
|
175
220
|
),
|
|
176
|
-
|
|
177
|
-
});
|
|
221
|
+
);
|
|
178
222
|
|
|
179
223
|
// limited version of the schema, focussed on what is needed for the implementation
|
|
180
224
|
// this approach limits breakages when the API changes and increases efficiency
|
|
@@ -210,13 +254,13 @@ export const deepseekChatChunkSchema = lazySchema(() =>
|
|
|
210
254
|
.nullish(),
|
|
211
255
|
})
|
|
212
256
|
.nullish(),
|
|
213
|
-
logprobs:
|
|
257
|
+
logprobs: getDeepseekChatLogprobsSchema(),
|
|
214
258
|
finish_reason: z.string().nullish(),
|
|
215
259
|
}),
|
|
216
260
|
),
|
|
217
|
-
usage:
|
|
261
|
+
usage: getTokenUsageSchema(),
|
|
218
262
|
}),
|
|
219
|
-
|
|
263
|
+
getDeepSeekErrorSchema(),
|
|
220
264
|
]),
|
|
221
265
|
),
|
|
222
266
|
);
|
|
@@ -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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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 deepseekLanguageModelOptions = lazySchema(() =>
|
|
85
|
+
zodSchema(getDeepseekChatOptionsSchema()),
|
|
86
|
+
);
|
|
66
87
|
|
|
67
88
|
export type DeepSeekLanguageModelOptions = {
|
|
68
89
|
/**
|
|
@@ -106,21 +127,35 @@ export type DeepSeekLanguageModelOptions = {
|
|
|
106
127
|
strictJsonSchema?: boolean;
|
|
107
128
|
};
|
|
108
129
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
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
|
-
|
|
123
|
-
|
|
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 =
|
|
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 =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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 =
|
|
31
|
+
export type DeepSeekFilePartProviderOptions = InferSchema<
|
|
23
32
|
typeof deepseekFilePartProviderOptions
|
|
24
33
|
>;
|
package/src/internal/index.ts
CHANGED
|
@@ -1,2 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getDeepseekAssistantMessageOptionsSchema,
|
|
3
|
+
getDeepseekChatOptionsSchema,
|
|
4
|
+
getDeepseekMessageOptionsSchema,
|
|
5
|
+
} from '../chat/deepseek-chat-options';
|
|
6
|
+
|
|
1
7
|
export * from '../chat/deepseek-chat-language-model';
|
|
2
|
-
export
|
|
8
|
+
export type {
|
|
9
|
+
DeepSeekAssistantMessageProviderOptions,
|
|
10
|
+
DeepSeekChatModelId,
|
|
11
|
+
DeepSeekLanguageModelOptions,
|
|
12
|
+
DeepSeekMessageProviderOptions,
|
|
13
|
+
} from '../chat/deepseek-chat-options';
|
|
14
|
+
|
|
15
|
+
// Preserve the Zod object exports for consumers of the internal entry point.
|
|
16
|
+
export const deepseekLanguageModelOptions = getDeepseekChatOptionsSchema();
|
|
17
|
+
export const deepseekMessageProviderOptions = getDeepseekMessageOptionsSchema();
|
|
18
|
+
export const deepseekAssistantMessageProviderOptions =
|
|
19
|
+
getDeepseekAssistantMessageOptionsSchema();
|