@ai-sdk/deepseek 1.0.52 → 1.0.55
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 +33 -0
- package/README.md +1 -1
- package/dist/index.d.mts +57 -19
- package/dist/index.d.ts +57 -19
- package/dist/index.js +447 -126
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +447 -123
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +53 -4
- package/dist/internal/index.d.ts +53 -4
- package/dist/internal/index.js +446 -120
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +446 -119
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/internal/index.js
CHANGED
|
@@ -21,20 +21,115 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
DeepSeekChatLanguageModel: () => DeepSeekChatLanguageModel,
|
|
24
|
-
|
|
24
|
+
deepseekAssistantMessageProviderOptions: () => deepseekAssistantMessageProviderOptions,
|
|
25
|
+
deepseekChatOptions: () => deepseekChatOptions,
|
|
26
|
+
deepseekMessageProviderOptions: () => deepseekMessageProviderOptions
|
|
25
27
|
});
|
|
26
28
|
module.exports = __toCommonJS(index_exports);
|
|
27
29
|
|
|
28
30
|
// src/chat/deepseek-chat-language-model.ts
|
|
29
|
-
var
|
|
31
|
+
var import_provider3 = require("@ai-sdk/provider");
|
|
30
32
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
31
33
|
|
|
32
34
|
// src/chat/convert-to-deepseek-chat-messages.ts
|
|
35
|
+
var import_provider = require("@ai-sdk/provider");
|
|
33
36
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
34
|
-
|
|
37
|
+
|
|
38
|
+
// src/chat/deepseek-chat-options.ts
|
|
39
|
+
var import_v4 = require("zod/v4");
|
|
40
|
+
var deepseekChatOptions = import_v4.z.object({
|
|
41
|
+
/**
|
|
42
|
+
* Whether to return log probabilities for generated tokens.
|
|
43
|
+
*/
|
|
44
|
+
logprobs: import_v4.z.boolean().optional(),
|
|
45
|
+
/**
|
|
46
|
+
* Number of most likely tokens to return at each token position.
|
|
47
|
+
*
|
|
48
|
+
* Setting this option automatically enables `logprobs`.
|
|
49
|
+
*/
|
|
50
|
+
topLogprobs: import_v4.z.number().int().min(0).max(20).optional(),
|
|
51
|
+
/**
|
|
52
|
+
* An opaque identifier for the end user. DeepSeek uses this identifier for
|
|
53
|
+
* content-safety tracing and request isolation.
|
|
54
|
+
*
|
|
55
|
+
* Must contain only ASCII letters, numbers, underscores, and hyphens, and
|
|
56
|
+
* must be at most 512 characters long.
|
|
57
|
+
*/
|
|
58
|
+
userId: import_v4.z.string().regex(/^[a-zA-Z0-9_-]+$/, "userId must match /^[a-zA-Z0-9_-]+$/").max(512, "userId must be at most 512 characters long").optional(),
|
|
59
|
+
/**
|
|
60
|
+
* Type of thinking to use. Defaults to `enabled`.
|
|
61
|
+
*/
|
|
62
|
+
thinking: import_v4.z.object({
|
|
63
|
+
// `adaptive` is accepted at runtime for backwards compatibility and
|
|
64
|
+
// mapped to `enabled`, but is intentionally excluded from the exported
|
|
65
|
+
// provider options type.
|
|
66
|
+
type: import_v4.z.enum(["adaptive", "enabled", "disabled"]).optional()
|
|
67
|
+
}).optional(),
|
|
68
|
+
/**
|
|
69
|
+
* Controls the thinking strength for DeepSeek V4 reasoning models.
|
|
70
|
+
*/
|
|
71
|
+
// `medium` and `xhigh` are accepted at runtime for backwards compatibility
|
|
72
|
+
// and mapped to canonical DeepSeek values, but are intentionally excluded
|
|
73
|
+
// from the exported provider options type.
|
|
74
|
+
reasoningEffort: import_v4.z.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
|
|
75
|
+
/**
|
|
76
|
+
* Whether to use strict JSON schema validation for structured outputs.
|
|
77
|
+
* Only applies when the serving endpoint supports JSON schema response
|
|
78
|
+
* formats (e.g. Azure). Defaults to `true`.
|
|
79
|
+
*/
|
|
80
|
+
strictJsonSchema: import_v4.z.boolean().optional()
|
|
81
|
+
});
|
|
82
|
+
var deepseekMessageProviderOptions = import_v4.z.object({
|
|
83
|
+
/**
|
|
84
|
+
* The name of the participant represented by the message.
|
|
85
|
+
*
|
|
86
|
+
* Supported on system, user, and assistant messages.
|
|
87
|
+
*/
|
|
88
|
+
name: import_v4.z.string().optional()
|
|
89
|
+
});
|
|
90
|
+
var deepseekAssistantMessageProviderOptions = deepseekMessageProviderOptions.extend({
|
|
91
|
+
/**
|
|
92
|
+
* Whether the assistant message content is a prefix that DeepSeek should
|
|
93
|
+
* continue. This beta feature is only supported on the final assistant
|
|
94
|
+
* message when using a beta base URL.
|
|
95
|
+
*/
|
|
96
|
+
prefix: import_v4.z.literal(true).optional()
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// src/chat/deepseek-file-part-options.ts
|
|
100
|
+
var import_v42 = require("zod/v4");
|
|
101
|
+
var deepseekFilePartProviderOptions = import_v42.z.object({
|
|
102
|
+
/**
|
|
103
|
+
* Controls how DeepSeek processes an image sent as an `image_url` part.
|
|
104
|
+
*
|
|
105
|
+
* @see https://api-docs.deepseek.com/api/create-chat-completion/
|
|
106
|
+
*/
|
|
107
|
+
imageDetail: import_v42.z.enum(["low", "high", "original", "auto"]).optional(),
|
|
108
|
+
/**
|
|
109
|
+
* Sends inline image data as a DeepSeek `file` part using `file_data`
|
|
110
|
+
* instead of an `image_url` data URL. When set, the file part's filename
|
|
111
|
+
* is preserved.
|
|
112
|
+
*
|
|
113
|
+
* This option only applies to inline image data. It cannot be combined
|
|
114
|
+
* with `imageDetail`.
|
|
115
|
+
*/
|
|
116
|
+
fileData: import_v42.z.literal(true).optional()
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// src/chat/convert-to-deepseek-chat-messages.ts
|
|
120
|
+
var supportedImageMediaTypes = /* @__PURE__ */ new Set([
|
|
121
|
+
"image/gif",
|
|
122
|
+
"image/jpeg",
|
|
123
|
+
"image/jpg",
|
|
124
|
+
"image/png",
|
|
125
|
+
"image/webp"
|
|
126
|
+
]);
|
|
127
|
+
async function convertToDeepSeekChatMessages({
|
|
35
128
|
prompt,
|
|
36
129
|
responseFormat,
|
|
37
130
|
modelId,
|
|
131
|
+
providerOptionsName = "deepseek",
|
|
132
|
+
supportsAssistantPrefixCompletion = false,
|
|
38
133
|
supportsStructuredOutputs = false
|
|
39
134
|
}) {
|
|
40
135
|
const isDeepSeekV4 = modelId.includes("deepseek-v4");
|
|
@@ -61,11 +156,28 @@ function convertToDeepSeekChatMessages({
|
|
|
61
156
|
}
|
|
62
157
|
}
|
|
63
158
|
let index = -1;
|
|
64
|
-
for (const { role, content } of prompt) {
|
|
159
|
+
for (const { role, content, providerOptions } of prompt) {
|
|
65
160
|
index++;
|
|
161
|
+
const deepseekMessageOptions = await (0, import_provider_utils.parseProviderOptions)({
|
|
162
|
+
provider: providerOptionsName,
|
|
163
|
+
providerOptions,
|
|
164
|
+
schema: deepseekAssistantMessageProviderOptions
|
|
165
|
+
});
|
|
166
|
+
if ((deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.prefix) === true && role !== "assistant") {
|
|
167
|
+
throw new import_provider.InvalidPromptError({
|
|
168
|
+
prompt,
|
|
169
|
+
message: "DeepSeek assistant prefix completion requires `prefix: true` on an assistant message."
|
|
170
|
+
});
|
|
171
|
+
}
|
|
66
172
|
switch (role) {
|
|
67
173
|
case "system": {
|
|
68
|
-
messages.push({
|
|
174
|
+
messages.push({
|
|
175
|
+
role: "system",
|
|
176
|
+
content,
|
|
177
|
+
...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
|
|
178
|
+
name: deepseekMessageOptions.name
|
|
179
|
+
}
|
|
180
|
+
});
|
|
69
181
|
break;
|
|
70
182
|
}
|
|
71
183
|
case "user": {
|
|
@@ -84,7 +196,13 @@ function convertToDeepSeekChatMessages({
|
|
|
84
196
|
});
|
|
85
197
|
}
|
|
86
198
|
}
|
|
87
|
-
messages.push({
|
|
199
|
+
messages.push({
|
|
200
|
+
role: "user",
|
|
201
|
+
content: userContent2,
|
|
202
|
+
...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
|
|
203
|
+
name: deepseekMessageOptions.name
|
|
204
|
+
}
|
|
205
|
+
});
|
|
88
206
|
break;
|
|
89
207
|
}
|
|
90
208
|
const userContent = [];
|
|
@@ -92,13 +210,67 @@ function convertToDeepSeekChatMessages({
|
|
|
92
210
|
if (part.type === "text") {
|
|
93
211
|
userContent.push({ type: "text", text: part.text });
|
|
94
212
|
} else if (part.type === "file" && (part.mediaType === "image" || part.mediaType.startsWith("image/"))) {
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${(0, import_provider_utils.convertToBase64)(part.data)}`
|
|
100
|
-
}
|
|
213
|
+
const filePartOptions = await (0, import_provider_utils.parseProviderOptions)({
|
|
214
|
+
provider: providerOptionsName,
|
|
215
|
+
providerOptions: part.providerOptions,
|
|
216
|
+
schema: deepseekFilePartProviderOptions
|
|
101
217
|
});
|
|
218
|
+
const resolvedMediaType = part.mediaType === "image" || part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
219
|
+
if (!supportedImageMediaTypes.has(resolvedMediaType)) {
|
|
220
|
+
throw new import_provider.UnsupportedFunctionalityError({
|
|
221
|
+
functionality: `DeepSeek image media type ${resolvedMediaType}`,
|
|
222
|
+
message: "DeepSeek supports JPEG, PNG, GIF, and WebP image inputs."
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
if (part.data instanceof URL) {
|
|
226
|
+
const url = part.data.toString();
|
|
227
|
+
if (url.length > 8192) {
|
|
228
|
+
throw new import_provider.InvalidPromptError({
|
|
229
|
+
prompt,
|
|
230
|
+
message: "DeepSeek image URLs must not exceed 8192 characters."
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
if ((filePartOptions == null ? void 0 : filePartOptions.fileData) === true) {
|
|
234
|
+
throw new import_provider.InvalidPromptError({
|
|
235
|
+
prompt,
|
|
236
|
+
message: "DeepSeek `fileData` image parts require inline data, not a URL."
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
userContent.push({
|
|
240
|
+
type: "image_url",
|
|
241
|
+
image_url: {
|
|
242
|
+
url,
|
|
243
|
+
...(filePartOptions == null ? void 0 : filePartOptions.imageDetail) != null && {
|
|
244
|
+
detail: filePartOptions.imageDetail
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
} else {
|
|
249
|
+
const dataUrl = `data:${resolvedMediaType === "image/jpg" ? "image/jpeg" : resolvedMediaType};base64,${(0, import_provider_utils.convertToBase64)(part.data)}`;
|
|
250
|
+
if ((filePartOptions == null ? void 0 : filePartOptions.fileData) === true) {
|
|
251
|
+
if (filePartOptions.imageDetail != null) {
|
|
252
|
+
throw new import_provider.InvalidPromptError({
|
|
253
|
+
prompt,
|
|
254
|
+
message: "DeepSeek `imageDetail` cannot be combined with `fileData`."
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
userContent.push({
|
|
258
|
+
type: "file",
|
|
259
|
+
file_data: dataUrl,
|
|
260
|
+
...part.filename != null && { filename: part.filename }
|
|
261
|
+
});
|
|
262
|
+
} else {
|
|
263
|
+
userContent.push({
|
|
264
|
+
type: "image_url",
|
|
265
|
+
image_url: {
|
|
266
|
+
url: dataUrl,
|
|
267
|
+
...(filePartOptions == null ? void 0 : filePartOptions.imageDetail) != null && {
|
|
268
|
+
detail: filePartOptions.imageDetail
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
102
274
|
} else {
|
|
103
275
|
warnings.push({
|
|
104
276
|
type: "other",
|
|
@@ -106,10 +278,30 @@ function convertToDeepSeekChatMessages({
|
|
|
106
278
|
});
|
|
107
279
|
}
|
|
108
280
|
}
|
|
109
|
-
messages.push({
|
|
281
|
+
messages.push({
|
|
282
|
+
role: "user",
|
|
283
|
+
content: userContent,
|
|
284
|
+
...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
|
|
285
|
+
name: deepseekMessageOptions.name
|
|
286
|
+
}
|
|
287
|
+
});
|
|
110
288
|
break;
|
|
111
289
|
}
|
|
112
290
|
case "assistant": {
|
|
291
|
+
if ((deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.prefix) === true) {
|
|
292
|
+
if (index !== prompt.length - 1) {
|
|
293
|
+
throw new import_provider.InvalidPromptError({
|
|
294
|
+
prompt,
|
|
295
|
+
message: "DeepSeek assistant prefix completion requires the prefixed assistant message to be the final message."
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
if (!supportsAssistantPrefixCompletion) {
|
|
299
|
+
throw new import_provider.UnsupportedFunctionalityError({
|
|
300
|
+
functionality: "DeepSeek assistant prefix completion",
|
|
301
|
+
message: "DeepSeek assistant prefix completion requires a beta base URL ending in `/beta`."
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
}
|
|
113
305
|
let text = "";
|
|
114
306
|
let reasoning;
|
|
115
307
|
const toolCalls = [];
|
|
@@ -146,12 +338,24 @@ function convertToDeepSeekChatMessages({
|
|
|
146
338
|
messages.push({
|
|
147
339
|
role: "assistant",
|
|
148
340
|
content: text,
|
|
341
|
+
...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
|
|
342
|
+
name: deepseekMessageOptions.name
|
|
343
|
+
},
|
|
344
|
+
...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.prefix) === true && {
|
|
345
|
+
prefix: true
|
|
346
|
+
},
|
|
149
347
|
reasoning_content: reasoning != null ? reasoning : isDeepSeekV4 ? "" : void 0,
|
|
150
348
|
tool_calls: toolCalls.length > 0 ? toolCalls : void 0
|
|
151
349
|
});
|
|
152
350
|
break;
|
|
153
351
|
}
|
|
154
352
|
case "tool": {
|
|
353
|
+
if ((deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null) {
|
|
354
|
+
warnings.push({
|
|
355
|
+
type: "other",
|
|
356
|
+
message: "DeepSeek does not support message names on tool messages. The name has been omitted."
|
|
357
|
+
});
|
|
358
|
+
}
|
|
155
359
|
for (const toolResponse of content) {
|
|
156
360
|
const output = toolResponse.output;
|
|
157
361
|
let contentValue;
|
|
@@ -188,75 +392,101 @@ function convertToDeepSeekChatMessages({
|
|
|
188
392
|
|
|
189
393
|
// src/chat/deepseek-chat-api-types.ts
|
|
190
394
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
191
|
-
var
|
|
192
|
-
var tokenUsageSchema =
|
|
193
|
-
prompt_tokens:
|
|
194
|
-
completion_tokens:
|
|
195
|
-
prompt_cache_hit_tokens:
|
|
196
|
-
prompt_cache_miss_tokens:
|
|
197
|
-
total_tokens:
|
|
198
|
-
completion_tokens_details:
|
|
199
|
-
reasoning_tokens:
|
|
395
|
+
var import_v43 = require("zod/v4");
|
|
396
|
+
var tokenUsageSchema = import_v43.z.object({
|
|
397
|
+
prompt_tokens: import_v43.z.number().nullish(),
|
|
398
|
+
completion_tokens: import_v43.z.number().nullish(),
|
|
399
|
+
prompt_cache_hit_tokens: import_v43.z.number().nullish(),
|
|
400
|
+
prompt_cache_miss_tokens: import_v43.z.number().nullish(),
|
|
401
|
+
total_tokens: import_v43.z.number().nullish(),
|
|
402
|
+
completion_tokens_details: import_v43.z.object({
|
|
403
|
+
reasoning_tokens: import_v43.z.number().nullish()
|
|
200
404
|
}).nullish()
|
|
201
405
|
}).nullish();
|
|
202
|
-
var deepSeekErrorSchema =
|
|
203
|
-
error:
|
|
204
|
-
message:
|
|
205
|
-
type:
|
|
206
|
-
param:
|
|
207
|
-
code:
|
|
406
|
+
var deepSeekErrorSchema = import_v43.z.object({
|
|
407
|
+
error: import_v43.z.object({
|
|
408
|
+
message: import_v43.z.string(),
|
|
409
|
+
type: import_v43.z.string().nullish(),
|
|
410
|
+
param: import_v43.z.any().nullish(),
|
|
411
|
+
code: import_v43.z.union([import_v43.z.string(), import_v43.z.number()]).nullish()
|
|
208
412
|
})
|
|
209
413
|
});
|
|
210
|
-
var
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
414
|
+
var deepseekChatLogprobSchema = import_v43.z.object({
|
|
415
|
+
token: import_v43.z.string(),
|
|
416
|
+
logprob: import_v43.z.number(),
|
|
417
|
+
bytes: import_v43.z.array(import_v43.z.number()).nullable(),
|
|
418
|
+
top_logprobs: import_v43.z.array(
|
|
419
|
+
import_v43.z.object({
|
|
420
|
+
token: import_v43.z.string(),
|
|
421
|
+
logprob: import_v43.z.number(),
|
|
422
|
+
bytes: import_v43.z.array(import_v43.z.number()).nullable()
|
|
423
|
+
})
|
|
424
|
+
)
|
|
425
|
+
});
|
|
426
|
+
var deepseekChatLogprobsSchema = import_v43.z.object({
|
|
427
|
+
content: import_v43.z.array(deepseekChatLogprobSchema).nullish(),
|
|
428
|
+
reasoning_content: import_v43.z.array(deepseekChatLogprobSchema).nullish()
|
|
429
|
+
}).nullish();
|
|
430
|
+
var deepseekChatResponseSchema = import_v43.z.object({
|
|
431
|
+
id: import_v43.z.string().nullish(),
|
|
432
|
+
created: import_v43.z.number().nullish(),
|
|
433
|
+
model: import_v43.z.string().nullish(),
|
|
434
|
+
object: import_v43.z.literal("chat.completion").nullish(),
|
|
435
|
+
system_fingerprint: import_v43.z.string().nullish(),
|
|
436
|
+
choices: import_v43.z.array(
|
|
437
|
+
import_v43.z.object({
|
|
438
|
+
index: import_v43.z.number().nullish(),
|
|
439
|
+
message: import_v43.z.object({
|
|
440
|
+
role: import_v43.z.literal("assistant").nullish(),
|
|
441
|
+
content: import_v43.z.string().nullish(),
|
|
442
|
+
reasoning_content: import_v43.z.string().nullish(),
|
|
443
|
+
tool_calls: import_v43.z.array(
|
|
444
|
+
import_v43.z.object({
|
|
445
|
+
id: import_v43.z.string().nullish(),
|
|
446
|
+
type: import_v43.z.literal("function").nullish(),
|
|
447
|
+
function: import_v43.z.object({
|
|
448
|
+
name: import_v43.z.string(),
|
|
449
|
+
arguments: import_v43.z.string()
|
|
226
450
|
})
|
|
227
451
|
})
|
|
228
452
|
).nullish()
|
|
229
453
|
}),
|
|
230
|
-
|
|
454
|
+
logprobs: deepseekChatLogprobsSchema,
|
|
455
|
+
finish_reason: import_v43.z.string().nullish()
|
|
231
456
|
})
|
|
232
457
|
),
|
|
233
458
|
usage: tokenUsageSchema
|
|
234
459
|
});
|
|
235
460
|
var deepseekChatChunkSchema = (0, import_provider_utils2.lazySchema)(
|
|
236
461
|
() => (0, import_provider_utils2.zodSchema)(
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
id:
|
|
240
|
-
created:
|
|
241
|
-
model:
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
462
|
+
import_v43.z.union([
|
|
463
|
+
import_v43.z.object({
|
|
464
|
+
id: import_v43.z.string().nullish(),
|
|
465
|
+
created: import_v43.z.number().nullish(),
|
|
466
|
+
model: import_v43.z.string().nullish(),
|
|
467
|
+
object: import_v43.z.literal("chat.completion.chunk").nullish(),
|
|
468
|
+
system_fingerprint: import_v43.z.string().nullish(),
|
|
469
|
+
choices: import_v43.z.array(
|
|
470
|
+
import_v43.z.object({
|
|
471
|
+
index: import_v43.z.number().nullish(),
|
|
472
|
+
delta: import_v43.z.object({
|
|
473
|
+
role: import_v43.z.enum(["assistant"]).nullish(),
|
|
474
|
+
content: import_v43.z.string().nullish(),
|
|
475
|
+
reasoning_content: import_v43.z.string().nullish(),
|
|
476
|
+
tool_calls: import_v43.z.array(
|
|
477
|
+
import_v43.z.object({
|
|
478
|
+
index: import_v43.z.number(),
|
|
479
|
+
id: import_v43.z.string().nullish(),
|
|
480
|
+
type: import_v43.z.literal("function").nullish(),
|
|
481
|
+
function: import_v43.z.object({
|
|
482
|
+
name: import_v43.z.string().nullish(),
|
|
483
|
+
arguments: import_v43.z.string().nullish()
|
|
255
484
|
})
|
|
256
485
|
})
|
|
257
486
|
).nullish()
|
|
258
487
|
}).nullish(),
|
|
259
|
-
|
|
488
|
+
logprobs: deepseekChatLogprobsSchema,
|
|
489
|
+
finish_reason: import_v43.z.string().nullish()
|
|
260
490
|
})
|
|
261
491
|
),
|
|
262
492
|
usage: tokenUsageSchema
|
|
@@ -266,36 +496,8 @@ var deepseekChatChunkSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
266
496
|
)
|
|
267
497
|
);
|
|
268
498
|
|
|
269
|
-
// src/chat/deepseek-chat-options.ts
|
|
270
|
-
var import_v42 = require("zod/v4");
|
|
271
|
-
var deepseekChatOptions = import_v42.z.object({
|
|
272
|
-
/**
|
|
273
|
-
* Type of thinking to use. Defaults to `enabled`.
|
|
274
|
-
*
|
|
275
|
-
* See https://api-docs.deepseek.com/guides/thinking_mode for the
|
|
276
|
-
* `adaptive` option, which lets the model decide when to think.
|
|
277
|
-
*/
|
|
278
|
-
thinking: import_v42.z.object({
|
|
279
|
-
type: import_v42.z.enum(["adaptive", "enabled", "disabled"]).optional()
|
|
280
|
-
}).optional(),
|
|
281
|
-
/**
|
|
282
|
-
* Controls the thinking strength for DeepSeek V4 reasoning models.
|
|
283
|
-
*
|
|
284
|
-
* DeepSeek's API accepts `low`, `medium`, `high`, `xhigh`, and `max`.
|
|
285
|
-
* Per their docs, `low` and `medium` are mapped to `high`, and `xhigh`
|
|
286
|
-
* is mapped to `max` server-side for compatibility with other providers.
|
|
287
|
-
*/
|
|
288
|
-
reasoningEffort: import_v42.z.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
|
|
289
|
-
/**
|
|
290
|
-
* Whether to use strict JSON schema validation for structured outputs.
|
|
291
|
-
* Only applies when the serving endpoint supports JSON schema response
|
|
292
|
-
* formats (e.g. Azure). Defaults to `true`.
|
|
293
|
-
*/
|
|
294
|
-
strictJsonSchema: import_v42.z.boolean().optional()
|
|
295
|
-
});
|
|
296
|
-
|
|
297
499
|
// src/chat/deepseek-prepare-tools.ts
|
|
298
|
-
var
|
|
500
|
+
var import_provider2 = require("@ai-sdk/provider");
|
|
299
501
|
function prepareTools({
|
|
300
502
|
tools,
|
|
301
503
|
toolChoice
|
|
@@ -343,7 +545,7 @@ function prepareTools({
|
|
|
343
545
|
};
|
|
344
546
|
default: {
|
|
345
547
|
const _exhaustiveCheck = type;
|
|
346
|
-
throw new
|
|
548
|
+
throw new import_provider2.UnsupportedFunctionalityError({
|
|
347
549
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
348
550
|
});
|
|
349
551
|
}
|
|
@@ -382,6 +584,19 @@ function mapDeepSeekFinishReason(finishReason) {
|
|
|
382
584
|
}
|
|
383
585
|
|
|
384
586
|
// src/chat/deepseek-chat-language-model.ts
|
|
587
|
+
function mapDeepSeekProviderReasoningEffort({
|
|
588
|
+
reasoningEffort,
|
|
589
|
+
warnings
|
|
590
|
+
}) {
|
|
591
|
+
const mapped = reasoningEffort === "medium" ? "high" : reasoningEffort === "xhigh" ? "max" : reasoningEffort;
|
|
592
|
+
if (mapped !== reasoningEffort) {
|
|
593
|
+
warnings.push({
|
|
594
|
+
type: "other",
|
|
595
|
+
message: `reasoningEffort "${reasoningEffort}" is not a canonical DeepSeek value. mapped to "${mapped}".`
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
return mapped;
|
|
599
|
+
}
|
|
385
600
|
var DeepSeekChatLanguageModel = class {
|
|
386
601
|
constructor(modelId, config) {
|
|
387
602
|
this.specificationVersion = "v2";
|
|
@@ -423,17 +638,33 @@ var DeepSeekChatLanguageModel = class {
|
|
|
423
638
|
schema: deepseekChatOptions
|
|
424
639
|
})) != null ? _a : {};
|
|
425
640
|
const supportsStructuredOutputs = this.config.supportsStructuredOutputs === true;
|
|
426
|
-
const
|
|
641
|
+
const supportsPenaltySampling = this.config.supportsPenaltySampling === true;
|
|
642
|
+
const { messages, warnings } = await convertToDeepSeekChatMessages({
|
|
427
643
|
prompt,
|
|
428
644
|
responseFormat,
|
|
429
645
|
modelId: this.modelId,
|
|
646
|
+
providerOptionsName: this.providerOptionsName,
|
|
647
|
+
supportsAssistantPrefixCompletion: this.config.supportsAssistantPrefixCompletion,
|
|
430
648
|
supportsStructuredOutputs
|
|
431
649
|
});
|
|
650
|
+
const allWarnings = [...warnings];
|
|
432
651
|
if (topK != null) {
|
|
433
|
-
|
|
652
|
+
allWarnings.push({ type: "unsupported-setting", setting: "topK" });
|
|
434
653
|
}
|
|
435
654
|
if (seed != null) {
|
|
436
|
-
|
|
655
|
+
allWarnings.push({ type: "unsupported-setting", setting: "seed" });
|
|
656
|
+
}
|
|
657
|
+
if (!supportsPenaltySampling && frequencyPenalty != null) {
|
|
658
|
+
allWarnings.push({
|
|
659
|
+
type: "other",
|
|
660
|
+
message: "frequencyPenalty is deprecated by DeepSeek and has been omitted. Remove frequencyPenalty from the request."
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
if (!supportsPenaltySampling && presencePenalty != null) {
|
|
664
|
+
allWarnings.push({
|
|
665
|
+
type: "other",
|
|
666
|
+
message: "presencePenalty is deprecated by DeepSeek and has been omitted. Remove presencePenalty from the request."
|
|
667
|
+
});
|
|
437
668
|
}
|
|
438
669
|
const {
|
|
439
670
|
tools: deepseekTools,
|
|
@@ -443,15 +674,46 @@ var DeepSeekChatLanguageModel = class {
|
|
|
443
674
|
tools,
|
|
444
675
|
toolChoice
|
|
445
676
|
});
|
|
446
|
-
|
|
677
|
+
allWarnings.push(...toolWarnings);
|
|
678
|
+
const thinkingType = (_b = deepseekOptions.thinking) == null ? void 0 : _b.type;
|
|
679
|
+
if (thinkingType === "adaptive") {
|
|
680
|
+
allWarnings.push({
|
|
681
|
+
type: "other",
|
|
682
|
+
message: 'thinking.type "adaptive" is not a canonical DeepSeek value. mapped to "enabled".'
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
const thinking = this.config.supportsThinking === false ? void 0 : thinkingType != null ? { type: thinkingType === "adaptive" ? "enabled" : thinkingType } : void 0;
|
|
686
|
+
const isThinkingEnabled = this.config.supportsThinking !== false && (thinking == null ? void 0 : thinking.type) !== "disabled" && (thinking != null || this.modelId === "deepseek-reasoner" || this.modelId.includes("deepseek-v4"));
|
|
687
|
+
if (isThinkingEnabled && temperature != null) {
|
|
688
|
+
allWarnings.push({
|
|
689
|
+
type: "unsupported-setting",
|
|
690
|
+
setting: "temperature",
|
|
691
|
+
details: "temperature has no effect when DeepSeek thinking is enabled. Set providerOptions.deepseek.thinking.type to 'disabled' to use temperature."
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
if (isThinkingEnabled && topP != null) {
|
|
695
|
+
allWarnings.push({
|
|
696
|
+
type: "unsupported-setting",
|
|
697
|
+
setting: "topP",
|
|
698
|
+
details: "topP has no effect when DeepSeek thinking is enabled. Set providerOptions.deepseek.thinking.type to 'disabled' to use topP."
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
const reasoningEffort = deepseekOptions.reasoningEffort != null ? mapDeepSeekProviderReasoningEffort({
|
|
702
|
+
reasoningEffort: deepseekOptions.reasoningEffort,
|
|
703
|
+
warnings: allWarnings
|
|
704
|
+
}) : void 0;
|
|
447
705
|
return {
|
|
448
706
|
args: {
|
|
449
707
|
model: this.modelId,
|
|
708
|
+
...(deepseekOptions.logprobs === true || deepseekOptions.topLogprobs != null) && { logprobs: true },
|
|
709
|
+
...deepseekOptions.topLogprobs != null && {
|
|
710
|
+
top_logprobs: deepseekOptions.topLogprobs
|
|
711
|
+
},
|
|
450
712
|
max_tokens: maxOutputTokens,
|
|
451
|
-
temperature,
|
|
452
|
-
top_p: topP,
|
|
453
|
-
frequency_penalty: frequencyPenalty,
|
|
454
|
-
presence_penalty: presencePenalty,
|
|
713
|
+
temperature: isThinkingEnabled ? void 0 : temperature,
|
|
714
|
+
top_p: isThinkingEnabled ? void 0 : topP,
|
|
715
|
+
frequency_penalty: supportsPenaltySampling ? frequencyPenalty : void 0,
|
|
716
|
+
presence_penalty: supportsPenaltySampling ? presencePenalty : void 0,
|
|
455
717
|
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? supportsStructuredOutputs && responseFormat.schema != null ? {
|
|
456
718
|
type: "json_schema",
|
|
457
719
|
json_schema: {
|
|
@@ -466,11 +728,14 @@ var DeepSeekChatLanguageModel = class {
|
|
|
466
728
|
tools: deepseekTools,
|
|
467
729
|
tool_choice: deepseekToolChoices,
|
|
468
730
|
thinking,
|
|
469
|
-
...
|
|
470
|
-
|
|
731
|
+
...deepseekOptions.userId != null && {
|
|
732
|
+
user_id: deepseekOptions.userId
|
|
733
|
+
},
|
|
734
|
+
...(thinking == null ? void 0 : thinking.type) !== "disabled" && reasoningEffort != null && {
|
|
735
|
+
reasoning_effort: reasoningEffort
|
|
471
736
|
}
|
|
472
737
|
},
|
|
473
|
-
warnings:
|
|
738
|
+
warnings: allWarnings
|
|
474
739
|
};
|
|
475
740
|
}
|
|
476
741
|
async doGenerate(options) {
|
|
@@ -530,7 +795,21 @@ var DeepSeekChatLanguageModel = class {
|
|
|
530
795
|
providerMetadata: {
|
|
531
796
|
[this.providerOptionsName]: {
|
|
532
797
|
promptCacheHitTokens: (_n = (_m = responseBody.usage) == null ? void 0 : _m.prompt_cache_hit_tokens) != null ? _n : null,
|
|
533
|
-
promptCacheMissTokens: (_p = (_o = responseBody.usage) == null ? void 0 : _o.prompt_cache_miss_tokens) != null ? _p : null
|
|
798
|
+
promptCacheMissTokens: (_p = (_o = responseBody.usage) == null ? void 0 : _o.prompt_cache_miss_tokens) != null ? _p : null,
|
|
799
|
+
...responseBody.object != null && {
|
|
800
|
+
responseObject: responseBody.object
|
|
801
|
+
},
|
|
802
|
+
...choice.index != null && { choiceIndex: choice.index },
|
|
803
|
+
...choice.message.role != null && {
|
|
804
|
+
messageRole: choice.message.role
|
|
805
|
+
},
|
|
806
|
+
...choice.message.tool_calls != null && {
|
|
807
|
+
toolCallTypes: choice.message.tool_calls.map((toolCall) => toolCall.type).filter((type) => type != null)
|
|
808
|
+
},
|
|
809
|
+
...choice.logprobs != null && { logprobs: choice.logprobs },
|
|
810
|
+
...responseBody.system_fingerprint != null && {
|
|
811
|
+
systemFingerprint: responseBody.system_fingerprint
|
|
812
|
+
}
|
|
534
813
|
}
|
|
535
814
|
},
|
|
536
815
|
request: { body: args },
|
|
@@ -566,10 +845,17 @@ var DeepSeekChatLanguageModel = class {
|
|
|
566
845
|
const toolCalls = [];
|
|
567
846
|
let finishReason = "unknown";
|
|
568
847
|
let usage = void 0;
|
|
848
|
+
let systemFingerprint = void 0;
|
|
569
849
|
let isFirstChunk = true;
|
|
570
850
|
const providerOptionsName = this.providerOptionsName;
|
|
571
851
|
let isActiveReasoning = false;
|
|
572
852
|
let isActiveText = false;
|
|
853
|
+
let responseObject;
|
|
854
|
+
let choiceIndex;
|
|
855
|
+
let messageRole;
|
|
856
|
+
const toolCallTypes = /* @__PURE__ */ new Map();
|
|
857
|
+
const contentLogprobs = [];
|
|
858
|
+
const reasoningLogprobs = [];
|
|
573
859
|
return {
|
|
574
860
|
stream: response.pipeThrough(
|
|
575
861
|
new TransformStream({
|
|
@@ -577,7 +863,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
577
863
|
controller.enqueue({ type: "stream-start", warnings });
|
|
578
864
|
},
|
|
579
865
|
transform(chunk, controller) {
|
|
580
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
866
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
581
867
|
if (options.includeRawChunks) {
|
|
582
868
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
583
869
|
}
|
|
@@ -602,14 +888,32 @@ var DeepSeekChatLanguageModel = class {
|
|
|
602
888
|
if (value.usage != null) {
|
|
603
889
|
usage = value.usage;
|
|
604
890
|
}
|
|
891
|
+
if (value.object != null) {
|
|
892
|
+
responseObject = value.object;
|
|
893
|
+
}
|
|
894
|
+
if (value.system_fingerprint != null) {
|
|
895
|
+
systemFingerprint = value.system_fingerprint;
|
|
896
|
+
}
|
|
605
897
|
const choice = value.choices[0];
|
|
898
|
+
if ((choice == null ? void 0 : choice.index) != null) {
|
|
899
|
+
choiceIndex = choice.index;
|
|
900
|
+
}
|
|
606
901
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
607
902
|
finishReason = mapDeepSeekFinishReason(choice.finish_reason);
|
|
608
903
|
}
|
|
904
|
+
if (((_a = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _a.content) != null) {
|
|
905
|
+
contentLogprobs.push(...choice.logprobs.content);
|
|
906
|
+
}
|
|
907
|
+
if (((_b = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _b.reasoning_content) != null) {
|
|
908
|
+
reasoningLogprobs.push(...choice.logprobs.reasoning_content);
|
|
909
|
+
}
|
|
609
910
|
if ((choice == null ? void 0 : choice.delta) == null) {
|
|
610
911
|
return;
|
|
611
912
|
}
|
|
612
913
|
const delta = choice.delta;
|
|
914
|
+
if (delta.role != null) {
|
|
915
|
+
messageRole = delta.role;
|
|
916
|
+
}
|
|
613
917
|
const reasoningContent = delta.reasoning_content;
|
|
614
918
|
if (reasoningContent) {
|
|
615
919
|
if (!isActiveReasoning) {
|
|
@@ -652,16 +956,19 @@ var DeepSeekChatLanguageModel = class {
|
|
|
652
956
|
isActiveReasoning = false;
|
|
653
957
|
}
|
|
654
958
|
for (const toolCallDelta of delta.tool_calls) {
|
|
959
|
+
if (toolCallDelta.type != null) {
|
|
960
|
+
toolCallTypes.set(toolCallDelta.index, toolCallDelta.type);
|
|
961
|
+
}
|
|
655
962
|
const index = toolCallDelta.index;
|
|
656
963
|
if (toolCalls[index] == null) {
|
|
657
964
|
if (toolCallDelta.id == null) {
|
|
658
|
-
throw new
|
|
965
|
+
throw new import_provider3.InvalidResponseDataError({
|
|
659
966
|
data: toolCallDelta,
|
|
660
967
|
message: `Expected 'id' to be a string.`
|
|
661
968
|
});
|
|
662
969
|
}
|
|
663
|
-
if (((
|
|
664
|
-
throw new
|
|
970
|
+
if (((_c = toolCallDelta.function) == null ? void 0 : _c.name) == null) {
|
|
971
|
+
throw new import_provider3.InvalidResponseDataError({
|
|
665
972
|
data: toolCallDelta,
|
|
666
973
|
message: `Expected 'function.name' to be a string.`
|
|
667
974
|
});
|
|
@@ -676,12 +983,12 @@ var DeepSeekChatLanguageModel = class {
|
|
|
676
983
|
type: "function",
|
|
677
984
|
function: {
|
|
678
985
|
name: toolCallDelta.function.name,
|
|
679
|
-
arguments: (
|
|
986
|
+
arguments: (_d = toolCallDelta.function.arguments) != null ? _d : ""
|
|
680
987
|
},
|
|
681
988
|
hasFinished: false
|
|
682
989
|
};
|
|
683
990
|
const toolCall2 = toolCalls[index];
|
|
684
|
-
if (((
|
|
991
|
+
if (((_e = toolCall2.function) == null ? void 0 : _e.name) != null && ((_f = toolCall2.function) == null ? void 0 : _f.arguments) != null) {
|
|
685
992
|
if (toolCall2.function.arguments.length > 0) {
|
|
686
993
|
controller.enqueue({
|
|
687
994
|
type: "tool-input-delta",
|
|
@@ -696,7 +1003,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
696
1003
|
});
|
|
697
1004
|
controller.enqueue({
|
|
698
1005
|
type: "tool-call",
|
|
699
|
-
toolCallId: (
|
|
1006
|
+
toolCallId: (_g = toolCall2.id) != null ? _g : (0, import_provider_utils3.generateId)(),
|
|
700
1007
|
toolName: toolCall2.function.name,
|
|
701
1008
|
input: toolCall2.function.arguments
|
|
702
1009
|
});
|
|
@@ -709,22 +1016,22 @@ var DeepSeekChatLanguageModel = class {
|
|
|
709
1016
|
if (toolCall.hasFinished) {
|
|
710
1017
|
continue;
|
|
711
1018
|
}
|
|
712
|
-
if (((
|
|
713
|
-
toolCall.function.arguments += (
|
|
1019
|
+
if (((_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null) {
|
|
1020
|
+
toolCall.function.arguments += (_j = (_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null ? _j : "";
|
|
714
1021
|
}
|
|
715
1022
|
controller.enqueue({
|
|
716
1023
|
type: "tool-input-delta",
|
|
717
1024
|
id: toolCall.id,
|
|
718
|
-
delta: (
|
|
1025
|
+
delta: (_k = toolCallDelta.function.arguments) != null ? _k : ""
|
|
719
1026
|
});
|
|
720
|
-
if (((
|
|
1027
|
+
if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null && (0, import_provider_utils3.isParsableJson)(toolCall.function.arguments)) {
|
|
721
1028
|
controller.enqueue({
|
|
722
1029
|
type: "tool-input-end",
|
|
723
1030
|
id: toolCall.id
|
|
724
1031
|
});
|
|
725
1032
|
controller.enqueue({
|
|
726
1033
|
type: "tool-call",
|
|
727
|
-
toolCallId: (
|
|
1034
|
+
toolCallId: (_n = toolCall.id) != null ? _n : (0, import_provider_utils3.generateId)(),
|
|
728
1035
|
toolName: toolCall.function.name,
|
|
729
1036
|
input: toolCall.function.arguments
|
|
730
1037
|
});
|
|
@@ -768,7 +1075,24 @@ var DeepSeekChatLanguageModel = class {
|
|
|
768
1075
|
providerMetadata: {
|
|
769
1076
|
[providerOptionsName]: {
|
|
770
1077
|
promptCacheHitTokens: (_h = usage == null ? void 0 : usage.prompt_cache_hit_tokens) != null ? _h : null,
|
|
771
|
-
promptCacheMissTokens: (_i = usage == null ? void 0 : usage.prompt_cache_miss_tokens) != null ? _i : null
|
|
1078
|
+
promptCacheMissTokens: (_i = usage == null ? void 0 : usage.prompt_cache_miss_tokens) != null ? _i : null,
|
|
1079
|
+
...responseObject != null && { responseObject },
|
|
1080
|
+
...choiceIndex != null && { choiceIndex },
|
|
1081
|
+
...messageRole != null && { messageRole },
|
|
1082
|
+
...toolCallTypes.size > 0 && {
|
|
1083
|
+
toolCallTypes: [...toolCallTypes.entries()].sort(([left], [right]) => left - right).map(([, type]) => type)
|
|
1084
|
+
},
|
|
1085
|
+
...(contentLogprobs.length > 0 || reasoningLogprobs.length > 0) && {
|
|
1086
|
+
logprobs: {
|
|
1087
|
+
...contentLogprobs.length > 0 && {
|
|
1088
|
+
content: contentLogprobs
|
|
1089
|
+
},
|
|
1090
|
+
...reasoningLogprobs.length > 0 && {
|
|
1091
|
+
reasoning_content: reasoningLogprobs
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
},
|
|
1095
|
+
...systemFingerprint != null && { systemFingerprint }
|
|
772
1096
|
}
|
|
773
1097
|
}
|
|
774
1098
|
});
|
|
@@ -783,6 +1107,8 @@ var DeepSeekChatLanguageModel = class {
|
|
|
783
1107
|
// Annotate the CommonJS export names for ESM import in node:
|
|
784
1108
|
0 && (module.exports = {
|
|
785
1109
|
DeepSeekChatLanguageModel,
|
|
786
|
-
|
|
1110
|
+
deepseekAssistantMessageProviderOptions,
|
|
1111
|
+
deepseekChatOptions,
|
|
1112
|
+
deepseekMessageProviderOptions
|
|
787
1113
|
});
|
|
788
1114
|
//# sourceMappingURL=index.js.map
|