@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.mjs
CHANGED
|
@@ -9,16 +9,112 @@ import {
|
|
|
9
9
|
createJsonResponseHandler,
|
|
10
10
|
generateId,
|
|
11
11
|
isParsableJson,
|
|
12
|
-
parseProviderOptions,
|
|
12
|
+
parseProviderOptions as parseProviderOptions2,
|
|
13
13
|
postJsonToApi
|
|
14
14
|
} from "@ai-sdk/provider-utils";
|
|
15
15
|
|
|
16
16
|
// src/chat/convert-to-deepseek-chat-messages.ts
|
|
17
|
-
import {
|
|
18
|
-
|
|
17
|
+
import {
|
|
18
|
+
InvalidPromptError,
|
|
19
|
+
UnsupportedFunctionalityError
|
|
20
|
+
} from "@ai-sdk/provider";
|
|
21
|
+
import { convertToBase64, parseProviderOptions } from "@ai-sdk/provider-utils";
|
|
22
|
+
|
|
23
|
+
// src/chat/deepseek-chat-options.ts
|
|
24
|
+
import { z } from "zod/v4";
|
|
25
|
+
var deepseekChatOptions = z.object({
|
|
26
|
+
/**
|
|
27
|
+
* Whether to return log probabilities for generated tokens.
|
|
28
|
+
*/
|
|
29
|
+
logprobs: z.boolean().optional(),
|
|
30
|
+
/**
|
|
31
|
+
* Number of most likely tokens to return at each token position.
|
|
32
|
+
*
|
|
33
|
+
* Setting this option automatically enables `logprobs`.
|
|
34
|
+
*/
|
|
35
|
+
topLogprobs: z.number().int().min(0).max(20).optional(),
|
|
36
|
+
/**
|
|
37
|
+
* An opaque identifier for the end user. DeepSeek uses this identifier for
|
|
38
|
+
* content-safety tracing and request isolation.
|
|
39
|
+
*
|
|
40
|
+
* Must contain only ASCII letters, numbers, underscores, and hyphens, and
|
|
41
|
+
* must be at most 512 characters long.
|
|
42
|
+
*/
|
|
43
|
+
userId: 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(),
|
|
44
|
+
/**
|
|
45
|
+
* Type of thinking to use. Defaults to `enabled`.
|
|
46
|
+
*/
|
|
47
|
+
thinking: z.object({
|
|
48
|
+
// `adaptive` is accepted at runtime for backwards compatibility and
|
|
49
|
+
// mapped to `enabled`, but is intentionally excluded from the exported
|
|
50
|
+
// provider options type.
|
|
51
|
+
type: z.enum(["adaptive", "enabled", "disabled"]).optional()
|
|
52
|
+
}).optional(),
|
|
53
|
+
/**
|
|
54
|
+
* Controls the thinking strength for DeepSeek V4 reasoning models.
|
|
55
|
+
*/
|
|
56
|
+
// `medium` and `xhigh` are accepted at runtime for backwards compatibility
|
|
57
|
+
// and mapped to canonical DeepSeek values, but are intentionally excluded
|
|
58
|
+
// from the exported provider options type.
|
|
59
|
+
reasoningEffort: z.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
|
|
60
|
+
/**
|
|
61
|
+
* Whether to use strict JSON schema validation for structured outputs.
|
|
62
|
+
* Only applies when the serving endpoint supports JSON schema response
|
|
63
|
+
* formats (e.g. Azure). Defaults to `true`.
|
|
64
|
+
*/
|
|
65
|
+
strictJsonSchema: z.boolean().optional()
|
|
66
|
+
});
|
|
67
|
+
var deepseekMessageProviderOptions = z.object({
|
|
68
|
+
/**
|
|
69
|
+
* The name of the participant represented by the message.
|
|
70
|
+
*
|
|
71
|
+
* Supported on system, user, and assistant messages.
|
|
72
|
+
*/
|
|
73
|
+
name: z.string().optional()
|
|
74
|
+
});
|
|
75
|
+
var deepseekAssistantMessageProviderOptions = deepseekMessageProviderOptions.extend({
|
|
76
|
+
/**
|
|
77
|
+
* Whether the assistant message content is a prefix that DeepSeek should
|
|
78
|
+
* continue. This beta feature is only supported on the final assistant
|
|
79
|
+
* message when using a beta base URL.
|
|
80
|
+
*/
|
|
81
|
+
prefix: z.literal(true).optional()
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// src/chat/deepseek-file-part-options.ts
|
|
85
|
+
import { z as z2 } from "zod/v4";
|
|
86
|
+
var deepseekFilePartProviderOptions = z2.object({
|
|
87
|
+
/**
|
|
88
|
+
* Controls how DeepSeek processes an image sent as an `image_url` part.
|
|
89
|
+
*
|
|
90
|
+
* @see https://api-docs.deepseek.com/api/create-chat-completion/
|
|
91
|
+
*/
|
|
92
|
+
imageDetail: z2.enum(["low", "high", "original", "auto"]).optional(),
|
|
93
|
+
/**
|
|
94
|
+
* Sends inline image data as a DeepSeek `file` part using `file_data`
|
|
95
|
+
* instead of an `image_url` data URL. When set, the file part's filename
|
|
96
|
+
* is preserved.
|
|
97
|
+
*
|
|
98
|
+
* This option only applies to inline image data. It cannot be combined
|
|
99
|
+
* with `imageDetail`.
|
|
100
|
+
*/
|
|
101
|
+
fileData: z2.literal(true).optional()
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// src/chat/convert-to-deepseek-chat-messages.ts
|
|
105
|
+
var supportedImageMediaTypes = /* @__PURE__ */ new Set([
|
|
106
|
+
"image/gif",
|
|
107
|
+
"image/jpeg",
|
|
108
|
+
"image/jpg",
|
|
109
|
+
"image/png",
|
|
110
|
+
"image/webp"
|
|
111
|
+
]);
|
|
112
|
+
async function convertToDeepSeekChatMessages({
|
|
19
113
|
prompt,
|
|
20
114
|
responseFormat,
|
|
21
115
|
modelId,
|
|
116
|
+
providerOptionsName = "deepseek",
|
|
117
|
+
supportsAssistantPrefixCompletion = false,
|
|
22
118
|
supportsStructuredOutputs = false
|
|
23
119
|
}) {
|
|
24
120
|
const isDeepSeekV4 = modelId.includes("deepseek-v4");
|
|
@@ -45,11 +141,28 @@ function convertToDeepSeekChatMessages({
|
|
|
45
141
|
}
|
|
46
142
|
}
|
|
47
143
|
let index = -1;
|
|
48
|
-
for (const { role, content } of prompt) {
|
|
144
|
+
for (const { role, content, providerOptions } of prompt) {
|
|
49
145
|
index++;
|
|
146
|
+
const deepseekMessageOptions = await parseProviderOptions({
|
|
147
|
+
provider: providerOptionsName,
|
|
148
|
+
providerOptions,
|
|
149
|
+
schema: deepseekAssistantMessageProviderOptions
|
|
150
|
+
});
|
|
151
|
+
if ((deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.prefix) === true && role !== "assistant") {
|
|
152
|
+
throw new InvalidPromptError({
|
|
153
|
+
prompt,
|
|
154
|
+
message: "DeepSeek assistant prefix completion requires `prefix: true` on an assistant message."
|
|
155
|
+
});
|
|
156
|
+
}
|
|
50
157
|
switch (role) {
|
|
51
158
|
case "system": {
|
|
52
|
-
messages.push({
|
|
159
|
+
messages.push({
|
|
160
|
+
role: "system",
|
|
161
|
+
content,
|
|
162
|
+
...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
|
|
163
|
+
name: deepseekMessageOptions.name
|
|
164
|
+
}
|
|
165
|
+
});
|
|
53
166
|
break;
|
|
54
167
|
}
|
|
55
168
|
case "user": {
|
|
@@ -68,7 +181,13 @@ function convertToDeepSeekChatMessages({
|
|
|
68
181
|
});
|
|
69
182
|
}
|
|
70
183
|
}
|
|
71
|
-
messages.push({
|
|
184
|
+
messages.push({
|
|
185
|
+
role: "user",
|
|
186
|
+
content: userContent2,
|
|
187
|
+
...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
|
|
188
|
+
name: deepseekMessageOptions.name
|
|
189
|
+
}
|
|
190
|
+
});
|
|
72
191
|
break;
|
|
73
192
|
}
|
|
74
193
|
const userContent = [];
|
|
@@ -76,13 +195,67 @@ function convertToDeepSeekChatMessages({
|
|
|
76
195
|
if (part.type === "text") {
|
|
77
196
|
userContent.push({ type: "text", text: part.text });
|
|
78
197
|
} else if (part.type === "file" && (part.mediaType === "image" || part.mediaType.startsWith("image/"))) {
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`
|
|
84
|
-
}
|
|
198
|
+
const filePartOptions = await parseProviderOptions({
|
|
199
|
+
provider: providerOptionsName,
|
|
200
|
+
providerOptions: part.providerOptions,
|
|
201
|
+
schema: deepseekFilePartProviderOptions
|
|
85
202
|
});
|
|
203
|
+
const resolvedMediaType = part.mediaType === "image" || part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
204
|
+
if (!supportedImageMediaTypes.has(resolvedMediaType)) {
|
|
205
|
+
throw new UnsupportedFunctionalityError({
|
|
206
|
+
functionality: `DeepSeek image media type ${resolvedMediaType}`,
|
|
207
|
+
message: "DeepSeek supports JPEG, PNG, GIF, and WebP image inputs."
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
if (part.data instanceof URL) {
|
|
211
|
+
const url = part.data.toString();
|
|
212
|
+
if (url.length > 8192) {
|
|
213
|
+
throw new InvalidPromptError({
|
|
214
|
+
prompt,
|
|
215
|
+
message: "DeepSeek image URLs must not exceed 8192 characters."
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
if ((filePartOptions == null ? void 0 : filePartOptions.fileData) === true) {
|
|
219
|
+
throw new InvalidPromptError({
|
|
220
|
+
prompt,
|
|
221
|
+
message: "DeepSeek `fileData` image parts require inline data, not a URL."
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
userContent.push({
|
|
225
|
+
type: "image_url",
|
|
226
|
+
image_url: {
|
|
227
|
+
url,
|
|
228
|
+
...(filePartOptions == null ? void 0 : filePartOptions.imageDetail) != null && {
|
|
229
|
+
detail: filePartOptions.imageDetail
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
} else {
|
|
234
|
+
const dataUrl = `data:${resolvedMediaType === "image/jpg" ? "image/jpeg" : resolvedMediaType};base64,${convertToBase64(part.data)}`;
|
|
235
|
+
if ((filePartOptions == null ? void 0 : filePartOptions.fileData) === true) {
|
|
236
|
+
if (filePartOptions.imageDetail != null) {
|
|
237
|
+
throw new InvalidPromptError({
|
|
238
|
+
prompt,
|
|
239
|
+
message: "DeepSeek `imageDetail` cannot be combined with `fileData`."
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
userContent.push({
|
|
243
|
+
type: "file",
|
|
244
|
+
file_data: dataUrl,
|
|
245
|
+
...part.filename != null && { filename: part.filename }
|
|
246
|
+
});
|
|
247
|
+
} else {
|
|
248
|
+
userContent.push({
|
|
249
|
+
type: "image_url",
|
|
250
|
+
image_url: {
|
|
251
|
+
url: dataUrl,
|
|
252
|
+
...(filePartOptions == null ? void 0 : filePartOptions.imageDetail) != null && {
|
|
253
|
+
detail: filePartOptions.imageDetail
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
}
|
|
86
259
|
} else {
|
|
87
260
|
warnings.push({
|
|
88
261
|
type: "other",
|
|
@@ -90,10 +263,30 @@ function convertToDeepSeekChatMessages({
|
|
|
90
263
|
});
|
|
91
264
|
}
|
|
92
265
|
}
|
|
93
|
-
messages.push({
|
|
266
|
+
messages.push({
|
|
267
|
+
role: "user",
|
|
268
|
+
content: userContent,
|
|
269
|
+
...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
|
|
270
|
+
name: deepseekMessageOptions.name
|
|
271
|
+
}
|
|
272
|
+
});
|
|
94
273
|
break;
|
|
95
274
|
}
|
|
96
275
|
case "assistant": {
|
|
276
|
+
if ((deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.prefix) === true) {
|
|
277
|
+
if (index !== prompt.length - 1) {
|
|
278
|
+
throw new InvalidPromptError({
|
|
279
|
+
prompt,
|
|
280
|
+
message: "DeepSeek assistant prefix completion requires the prefixed assistant message to be the final message."
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
if (!supportsAssistantPrefixCompletion) {
|
|
284
|
+
throw new UnsupportedFunctionalityError({
|
|
285
|
+
functionality: "DeepSeek assistant prefix completion",
|
|
286
|
+
message: "DeepSeek assistant prefix completion requires a beta base URL ending in `/beta`."
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
}
|
|
97
290
|
let text = "";
|
|
98
291
|
let reasoning;
|
|
99
292
|
const toolCalls = [];
|
|
@@ -130,12 +323,24 @@ function convertToDeepSeekChatMessages({
|
|
|
130
323
|
messages.push({
|
|
131
324
|
role: "assistant",
|
|
132
325
|
content: text,
|
|
326
|
+
...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
|
|
327
|
+
name: deepseekMessageOptions.name
|
|
328
|
+
},
|
|
329
|
+
...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.prefix) === true && {
|
|
330
|
+
prefix: true
|
|
331
|
+
},
|
|
133
332
|
reasoning_content: reasoning != null ? reasoning : isDeepSeekV4 ? "" : void 0,
|
|
134
333
|
tool_calls: toolCalls.length > 0 ? toolCalls : void 0
|
|
135
334
|
});
|
|
136
335
|
break;
|
|
137
336
|
}
|
|
138
337
|
case "tool": {
|
|
338
|
+
if ((deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null) {
|
|
339
|
+
warnings.push({
|
|
340
|
+
type: "other",
|
|
341
|
+
message: "DeepSeek does not support message names on tool messages. The name has been omitted."
|
|
342
|
+
});
|
|
343
|
+
}
|
|
139
344
|
for (const toolResponse of content) {
|
|
140
345
|
const output = toolResponse.output;
|
|
141
346
|
let contentValue;
|
|
@@ -172,75 +377,101 @@ function convertToDeepSeekChatMessages({
|
|
|
172
377
|
|
|
173
378
|
// src/chat/deepseek-chat-api-types.ts
|
|
174
379
|
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
175
|
-
import { z } from "zod/v4";
|
|
176
|
-
var tokenUsageSchema =
|
|
177
|
-
prompt_tokens:
|
|
178
|
-
completion_tokens:
|
|
179
|
-
prompt_cache_hit_tokens:
|
|
180
|
-
prompt_cache_miss_tokens:
|
|
181
|
-
total_tokens:
|
|
182
|
-
completion_tokens_details:
|
|
183
|
-
reasoning_tokens:
|
|
380
|
+
import { z as z3 } from "zod/v4";
|
|
381
|
+
var tokenUsageSchema = z3.object({
|
|
382
|
+
prompt_tokens: z3.number().nullish(),
|
|
383
|
+
completion_tokens: z3.number().nullish(),
|
|
384
|
+
prompt_cache_hit_tokens: z3.number().nullish(),
|
|
385
|
+
prompt_cache_miss_tokens: z3.number().nullish(),
|
|
386
|
+
total_tokens: z3.number().nullish(),
|
|
387
|
+
completion_tokens_details: z3.object({
|
|
388
|
+
reasoning_tokens: z3.number().nullish()
|
|
184
389
|
}).nullish()
|
|
185
390
|
}).nullish();
|
|
186
|
-
var deepSeekErrorSchema =
|
|
187
|
-
error:
|
|
188
|
-
message:
|
|
189
|
-
type:
|
|
190
|
-
param:
|
|
191
|
-
code:
|
|
391
|
+
var deepSeekErrorSchema = z3.object({
|
|
392
|
+
error: z3.object({
|
|
393
|
+
message: z3.string(),
|
|
394
|
+
type: z3.string().nullish(),
|
|
395
|
+
param: z3.any().nullish(),
|
|
396
|
+
code: z3.union([z3.string(), z3.number()]).nullish()
|
|
192
397
|
})
|
|
193
398
|
});
|
|
194
|
-
var
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
399
|
+
var deepseekChatLogprobSchema = z3.object({
|
|
400
|
+
token: z3.string(),
|
|
401
|
+
logprob: z3.number(),
|
|
402
|
+
bytes: z3.array(z3.number()).nullable(),
|
|
403
|
+
top_logprobs: z3.array(
|
|
404
|
+
z3.object({
|
|
405
|
+
token: z3.string(),
|
|
406
|
+
logprob: z3.number(),
|
|
407
|
+
bytes: z3.array(z3.number()).nullable()
|
|
408
|
+
})
|
|
409
|
+
)
|
|
410
|
+
});
|
|
411
|
+
var deepseekChatLogprobsSchema = z3.object({
|
|
412
|
+
content: z3.array(deepseekChatLogprobSchema).nullish(),
|
|
413
|
+
reasoning_content: z3.array(deepseekChatLogprobSchema).nullish()
|
|
414
|
+
}).nullish();
|
|
415
|
+
var deepseekChatResponseSchema = z3.object({
|
|
416
|
+
id: z3.string().nullish(),
|
|
417
|
+
created: z3.number().nullish(),
|
|
418
|
+
model: z3.string().nullish(),
|
|
419
|
+
object: z3.literal("chat.completion").nullish(),
|
|
420
|
+
system_fingerprint: z3.string().nullish(),
|
|
421
|
+
choices: z3.array(
|
|
422
|
+
z3.object({
|
|
423
|
+
index: z3.number().nullish(),
|
|
424
|
+
message: z3.object({
|
|
425
|
+
role: z3.literal("assistant").nullish(),
|
|
426
|
+
content: z3.string().nullish(),
|
|
427
|
+
reasoning_content: z3.string().nullish(),
|
|
428
|
+
tool_calls: z3.array(
|
|
429
|
+
z3.object({
|
|
430
|
+
id: z3.string().nullish(),
|
|
431
|
+
type: z3.literal("function").nullish(),
|
|
432
|
+
function: z3.object({
|
|
433
|
+
name: z3.string(),
|
|
434
|
+
arguments: z3.string()
|
|
210
435
|
})
|
|
211
436
|
})
|
|
212
437
|
).nullish()
|
|
213
438
|
}),
|
|
214
|
-
|
|
439
|
+
logprobs: deepseekChatLogprobsSchema,
|
|
440
|
+
finish_reason: z3.string().nullish()
|
|
215
441
|
})
|
|
216
442
|
),
|
|
217
443
|
usage: tokenUsageSchema
|
|
218
444
|
});
|
|
219
445
|
var deepseekChatChunkSchema = lazySchema(
|
|
220
446
|
() => zodSchema(
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
id:
|
|
224
|
-
created:
|
|
225
|
-
model:
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
447
|
+
z3.union([
|
|
448
|
+
z3.object({
|
|
449
|
+
id: z3.string().nullish(),
|
|
450
|
+
created: z3.number().nullish(),
|
|
451
|
+
model: z3.string().nullish(),
|
|
452
|
+
object: z3.literal("chat.completion.chunk").nullish(),
|
|
453
|
+
system_fingerprint: z3.string().nullish(),
|
|
454
|
+
choices: z3.array(
|
|
455
|
+
z3.object({
|
|
456
|
+
index: z3.number().nullish(),
|
|
457
|
+
delta: z3.object({
|
|
458
|
+
role: z3.enum(["assistant"]).nullish(),
|
|
459
|
+
content: z3.string().nullish(),
|
|
460
|
+
reasoning_content: z3.string().nullish(),
|
|
461
|
+
tool_calls: z3.array(
|
|
462
|
+
z3.object({
|
|
463
|
+
index: z3.number(),
|
|
464
|
+
id: z3.string().nullish(),
|
|
465
|
+
type: z3.literal("function").nullish(),
|
|
466
|
+
function: z3.object({
|
|
467
|
+
name: z3.string().nullish(),
|
|
468
|
+
arguments: z3.string().nullish()
|
|
239
469
|
})
|
|
240
470
|
})
|
|
241
471
|
).nullish()
|
|
242
472
|
}).nullish(),
|
|
243
|
-
|
|
473
|
+
logprobs: deepseekChatLogprobsSchema,
|
|
474
|
+
finish_reason: z3.string().nullish()
|
|
244
475
|
})
|
|
245
476
|
),
|
|
246
477
|
usage: tokenUsageSchema
|
|
@@ -250,37 +481,9 @@ var deepseekChatChunkSchema = lazySchema(
|
|
|
250
481
|
)
|
|
251
482
|
);
|
|
252
483
|
|
|
253
|
-
// src/chat/deepseek-chat-options.ts
|
|
254
|
-
import { z as z2 } from "zod/v4";
|
|
255
|
-
var deepseekChatOptions = z2.object({
|
|
256
|
-
/**
|
|
257
|
-
* Type of thinking to use. Defaults to `enabled`.
|
|
258
|
-
*
|
|
259
|
-
* See https://api-docs.deepseek.com/guides/thinking_mode for the
|
|
260
|
-
* `adaptive` option, which lets the model decide when to think.
|
|
261
|
-
*/
|
|
262
|
-
thinking: z2.object({
|
|
263
|
-
type: z2.enum(["adaptive", "enabled", "disabled"]).optional()
|
|
264
|
-
}).optional(),
|
|
265
|
-
/**
|
|
266
|
-
* Controls the thinking strength for DeepSeek V4 reasoning models.
|
|
267
|
-
*
|
|
268
|
-
* DeepSeek's API accepts `low`, `medium`, `high`, `xhigh`, and `max`.
|
|
269
|
-
* Per their docs, `low` and `medium` are mapped to `high`, and `xhigh`
|
|
270
|
-
* is mapped to `max` server-side for compatibility with other providers.
|
|
271
|
-
*/
|
|
272
|
-
reasoningEffort: z2.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
|
|
273
|
-
/**
|
|
274
|
-
* Whether to use strict JSON schema validation for structured outputs.
|
|
275
|
-
* Only applies when the serving endpoint supports JSON schema response
|
|
276
|
-
* formats (e.g. Azure). Defaults to `true`.
|
|
277
|
-
*/
|
|
278
|
-
strictJsonSchema: z2.boolean().optional()
|
|
279
|
-
});
|
|
280
|
-
|
|
281
484
|
// src/chat/deepseek-prepare-tools.ts
|
|
282
485
|
import {
|
|
283
|
-
UnsupportedFunctionalityError
|
|
486
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
284
487
|
} from "@ai-sdk/provider";
|
|
285
488
|
function prepareTools({
|
|
286
489
|
tools,
|
|
@@ -329,7 +532,7 @@ function prepareTools({
|
|
|
329
532
|
};
|
|
330
533
|
default: {
|
|
331
534
|
const _exhaustiveCheck = type;
|
|
332
|
-
throw new
|
|
535
|
+
throw new UnsupportedFunctionalityError2({
|
|
333
536
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
334
537
|
});
|
|
335
538
|
}
|
|
@@ -368,6 +571,19 @@ function mapDeepSeekFinishReason(finishReason) {
|
|
|
368
571
|
}
|
|
369
572
|
|
|
370
573
|
// src/chat/deepseek-chat-language-model.ts
|
|
574
|
+
function mapDeepSeekProviderReasoningEffort({
|
|
575
|
+
reasoningEffort,
|
|
576
|
+
warnings
|
|
577
|
+
}) {
|
|
578
|
+
const mapped = reasoningEffort === "medium" ? "high" : reasoningEffort === "xhigh" ? "max" : reasoningEffort;
|
|
579
|
+
if (mapped !== reasoningEffort) {
|
|
580
|
+
warnings.push({
|
|
581
|
+
type: "other",
|
|
582
|
+
message: `reasoningEffort "${reasoningEffort}" is not a canonical DeepSeek value. mapped to "${mapped}".`
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
return mapped;
|
|
586
|
+
}
|
|
371
587
|
var DeepSeekChatLanguageModel = class {
|
|
372
588
|
constructor(modelId, config) {
|
|
373
589
|
this.specificationVersion = "v2";
|
|
@@ -403,23 +619,39 @@ var DeepSeekChatLanguageModel = class {
|
|
|
403
619
|
seed
|
|
404
620
|
}) {
|
|
405
621
|
var _a, _b, _c, _d;
|
|
406
|
-
const deepseekOptions = (_a = await
|
|
622
|
+
const deepseekOptions = (_a = await parseProviderOptions2({
|
|
407
623
|
provider: this.providerOptionsName,
|
|
408
624
|
providerOptions,
|
|
409
625
|
schema: deepseekChatOptions
|
|
410
626
|
})) != null ? _a : {};
|
|
411
627
|
const supportsStructuredOutputs = this.config.supportsStructuredOutputs === true;
|
|
412
|
-
const
|
|
628
|
+
const supportsPenaltySampling = this.config.supportsPenaltySampling === true;
|
|
629
|
+
const { messages, warnings } = await convertToDeepSeekChatMessages({
|
|
413
630
|
prompt,
|
|
414
631
|
responseFormat,
|
|
415
632
|
modelId: this.modelId,
|
|
633
|
+
providerOptionsName: this.providerOptionsName,
|
|
634
|
+
supportsAssistantPrefixCompletion: this.config.supportsAssistantPrefixCompletion,
|
|
416
635
|
supportsStructuredOutputs
|
|
417
636
|
});
|
|
637
|
+
const allWarnings = [...warnings];
|
|
418
638
|
if (topK != null) {
|
|
419
|
-
|
|
639
|
+
allWarnings.push({ type: "unsupported-setting", setting: "topK" });
|
|
420
640
|
}
|
|
421
641
|
if (seed != null) {
|
|
422
|
-
|
|
642
|
+
allWarnings.push({ type: "unsupported-setting", setting: "seed" });
|
|
643
|
+
}
|
|
644
|
+
if (!supportsPenaltySampling && frequencyPenalty != null) {
|
|
645
|
+
allWarnings.push({
|
|
646
|
+
type: "other",
|
|
647
|
+
message: "frequencyPenalty is deprecated by DeepSeek and has been omitted. Remove frequencyPenalty from the request."
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
if (!supportsPenaltySampling && presencePenalty != null) {
|
|
651
|
+
allWarnings.push({
|
|
652
|
+
type: "other",
|
|
653
|
+
message: "presencePenalty is deprecated by DeepSeek and has been omitted. Remove presencePenalty from the request."
|
|
654
|
+
});
|
|
423
655
|
}
|
|
424
656
|
const {
|
|
425
657
|
tools: deepseekTools,
|
|
@@ -429,15 +661,46 @@ var DeepSeekChatLanguageModel = class {
|
|
|
429
661
|
tools,
|
|
430
662
|
toolChoice
|
|
431
663
|
});
|
|
432
|
-
|
|
664
|
+
allWarnings.push(...toolWarnings);
|
|
665
|
+
const thinkingType = (_b = deepseekOptions.thinking) == null ? void 0 : _b.type;
|
|
666
|
+
if (thinkingType === "adaptive") {
|
|
667
|
+
allWarnings.push({
|
|
668
|
+
type: "other",
|
|
669
|
+
message: 'thinking.type "adaptive" is not a canonical DeepSeek value. mapped to "enabled".'
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
const thinking = this.config.supportsThinking === false ? void 0 : thinkingType != null ? { type: thinkingType === "adaptive" ? "enabled" : thinkingType } : void 0;
|
|
673
|
+
const isThinkingEnabled = this.config.supportsThinking !== false && (thinking == null ? void 0 : thinking.type) !== "disabled" && (thinking != null || this.modelId === "deepseek-reasoner" || this.modelId.includes("deepseek-v4"));
|
|
674
|
+
if (isThinkingEnabled && temperature != null) {
|
|
675
|
+
allWarnings.push({
|
|
676
|
+
type: "unsupported-setting",
|
|
677
|
+
setting: "temperature",
|
|
678
|
+
details: "temperature has no effect when DeepSeek thinking is enabled. Set providerOptions.deepseek.thinking.type to 'disabled' to use temperature."
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
if (isThinkingEnabled && topP != null) {
|
|
682
|
+
allWarnings.push({
|
|
683
|
+
type: "unsupported-setting",
|
|
684
|
+
setting: "topP",
|
|
685
|
+
details: "topP has no effect when DeepSeek thinking is enabled. Set providerOptions.deepseek.thinking.type to 'disabled' to use topP."
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
const reasoningEffort = deepseekOptions.reasoningEffort != null ? mapDeepSeekProviderReasoningEffort({
|
|
689
|
+
reasoningEffort: deepseekOptions.reasoningEffort,
|
|
690
|
+
warnings: allWarnings
|
|
691
|
+
}) : void 0;
|
|
433
692
|
return {
|
|
434
693
|
args: {
|
|
435
694
|
model: this.modelId,
|
|
695
|
+
...(deepseekOptions.logprobs === true || deepseekOptions.topLogprobs != null) && { logprobs: true },
|
|
696
|
+
...deepseekOptions.topLogprobs != null && {
|
|
697
|
+
top_logprobs: deepseekOptions.topLogprobs
|
|
698
|
+
},
|
|
436
699
|
max_tokens: maxOutputTokens,
|
|
437
|
-
temperature,
|
|
438
|
-
top_p: topP,
|
|
439
|
-
frequency_penalty: frequencyPenalty,
|
|
440
|
-
presence_penalty: presencePenalty,
|
|
700
|
+
temperature: isThinkingEnabled ? void 0 : temperature,
|
|
701
|
+
top_p: isThinkingEnabled ? void 0 : topP,
|
|
702
|
+
frequency_penalty: supportsPenaltySampling ? frequencyPenalty : void 0,
|
|
703
|
+
presence_penalty: supportsPenaltySampling ? presencePenalty : void 0,
|
|
441
704
|
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? supportsStructuredOutputs && responseFormat.schema != null ? {
|
|
442
705
|
type: "json_schema",
|
|
443
706
|
json_schema: {
|
|
@@ -452,11 +715,14 @@ var DeepSeekChatLanguageModel = class {
|
|
|
452
715
|
tools: deepseekTools,
|
|
453
716
|
tool_choice: deepseekToolChoices,
|
|
454
717
|
thinking,
|
|
455
|
-
...
|
|
456
|
-
|
|
718
|
+
...deepseekOptions.userId != null && {
|
|
719
|
+
user_id: deepseekOptions.userId
|
|
720
|
+
},
|
|
721
|
+
...(thinking == null ? void 0 : thinking.type) !== "disabled" && reasoningEffort != null && {
|
|
722
|
+
reasoning_effort: reasoningEffort
|
|
457
723
|
}
|
|
458
724
|
},
|
|
459
|
-
warnings:
|
|
725
|
+
warnings: allWarnings
|
|
460
726
|
};
|
|
461
727
|
}
|
|
462
728
|
async doGenerate(options) {
|
|
@@ -516,7 +782,21 @@ var DeepSeekChatLanguageModel = class {
|
|
|
516
782
|
providerMetadata: {
|
|
517
783
|
[this.providerOptionsName]: {
|
|
518
784
|
promptCacheHitTokens: (_n = (_m = responseBody.usage) == null ? void 0 : _m.prompt_cache_hit_tokens) != null ? _n : null,
|
|
519
|
-
promptCacheMissTokens: (_p = (_o = responseBody.usage) == null ? void 0 : _o.prompt_cache_miss_tokens) != null ? _p : null
|
|
785
|
+
promptCacheMissTokens: (_p = (_o = responseBody.usage) == null ? void 0 : _o.prompt_cache_miss_tokens) != null ? _p : null,
|
|
786
|
+
...responseBody.object != null && {
|
|
787
|
+
responseObject: responseBody.object
|
|
788
|
+
},
|
|
789
|
+
...choice.index != null && { choiceIndex: choice.index },
|
|
790
|
+
...choice.message.role != null && {
|
|
791
|
+
messageRole: choice.message.role
|
|
792
|
+
},
|
|
793
|
+
...choice.message.tool_calls != null && {
|
|
794
|
+
toolCallTypes: choice.message.tool_calls.map((toolCall) => toolCall.type).filter((type) => type != null)
|
|
795
|
+
},
|
|
796
|
+
...choice.logprobs != null && { logprobs: choice.logprobs },
|
|
797
|
+
...responseBody.system_fingerprint != null && {
|
|
798
|
+
systemFingerprint: responseBody.system_fingerprint
|
|
799
|
+
}
|
|
520
800
|
}
|
|
521
801
|
},
|
|
522
802
|
request: { body: args },
|
|
@@ -552,10 +832,17 @@ var DeepSeekChatLanguageModel = class {
|
|
|
552
832
|
const toolCalls = [];
|
|
553
833
|
let finishReason = "unknown";
|
|
554
834
|
let usage = void 0;
|
|
835
|
+
let systemFingerprint = void 0;
|
|
555
836
|
let isFirstChunk = true;
|
|
556
837
|
const providerOptionsName = this.providerOptionsName;
|
|
557
838
|
let isActiveReasoning = false;
|
|
558
839
|
let isActiveText = false;
|
|
840
|
+
let responseObject;
|
|
841
|
+
let choiceIndex;
|
|
842
|
+
let messageRole;
|
|
843
|
+
const toolCallTypes = /* @__PURE__ */ new Map();
|
|
844
|
+
const contentLogprobs = [];
|
|
845
|
+
const reasoningLogprobs = [];
|
|
559
846
|
return {
|
|
560
847
|
stream: response.pipeThrough(
|
|
561
848
|
new TransformStream({
|
|
@@ -563,7 +850,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
563
850
|
controller.enqueue({ type: "stream-start", warnings });
|
|
564
851
|
},
|
|
565
852
|
transform(chunk, controller) {
|
|
566
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
853
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
567
854
|
if (options.includeRawChunks) {
|
|
568
855
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
569
856
|
}
|
|
@@ -588,14 +875,32 @@ var DeepSeekChatLanguageModel = class {
|
|
|
588
875
|
if (value.usage != null) {
|
|
589
876
|
usage = value.usage;
|
|
590
877
|
}
|
|
878
|
+
if (value.object != null) {
|
|
879
|
+
responseObject = value.object;
|
|
880
|
+
}
|
|
881
|
+
if (value.system_fingerprint != null) {
|
|
882
|
+
systemFingerprint = value.system_fingerprint;
|
|
883
|
+
}
|
|
591
884
|
const choice = value.choices[0];
|
|
885
|
+
if ((choice == null ? void 0 : choice.index) != null) {
|
|
886
|
+
choiceIndex = choice.index;
|
|
887
|
+
}
|
|
592
888
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
593
889
|
finishReason = mapDeepSeekFinishReason(choice.finish_reason);
|
|
594
890
|
}
|
|
891
|
+
if (((_a = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _a.content) != null) {
|
|
892
|
+
contentLogprobs.push(...choice.logprobs.content);
|
|
893
|
+
}
|
|
894
|
+
if (((_b = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _b.reasoning_content) != null) {
|
|
895
|
+
reasoningLogprobs.push(...choice.logprobs.reasoning_content);
|
|
896
|
+
}
|
|
595
897
|
if ((choice == null ? void 0 : choice.delta) == null) {
|
|
596
898
|
return;
|
|
597
899
|
}
|
|
598
900
|
const delta = choice.delta;
|
|
901
|
+
if (delta.role != null) {
|
|
902
|
+
messageRole = delta.role;
|
|
903
|
+
}
|
|
599
904
|
const reasoningContent = delta.reasoning_content;
|
|
600
905
|
if (reasoningContent) {
|
|
601
906
|
if (!isActiveReasoning) {
|
|
@@ -638,6 +943,9 @@ var DeepSeekChatLanguageModel = class {
|
|
|
638
943
|
isActiveReasoning = false;
|
|
639
944
|
}
|
|
640
945
|
for (const toolCallDelta of delta.tool_calls) {
|
|
946
|
+
if (toolCallDelta.type != null) {
|
|
947
|
+
toolCallTypes.set(toolCallDelta.index, toolCallDelta.type);
|
|
948
|
+
}
|
|
641
949
|
const index = toolCallDelta.index;
|
|
642
950
|
if (toolCalls[index] == null) {
|
|
643
951
|
if (toolCallDelta.id == null) {
|
|
@@ -646,7 +954,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
646
954
|
message: `Expected 'id' to be a string.`
|
|
647
955
|
});
|
|
648
956
|
}
|
|
649
|
-
if (((
|
|
957
|
+
if (((_c = toolCallDelta.function) == null ? void 0 : _c.name) == null) {
|
|
650
958
|
throw new InvalidResponseDataError({
|
|
651
959
|
data: toolCallDelta,
|
|
652
960
|
message: `Expected 'function.name' to be a string.`
|
|
@@ -662,12 +970,12 @@ var DeepSeekChatLanguageModel = class {
|
|
|
662
970
|
type: "function",
|
|
663
971
|
function: {
|
|
664
972
|
name: toolCallDelta.function.name,
|
|
665
|
-
arguments: (
|
|
973
|
+
arguments: (_d = toolCallDelta.function.arguments) != null ? _d : ""
|
|
666
974
|
},
|
|
667
975
|
hasFinished: false
|
|
668
976
|
};
|
|
669
977
|
const toolCall2 = toolCalls[index];
|
|
670
|
-
if (((
|
|
978
|
+
if (((_e = toolCall2.function) == null ? void 0 : _e.name) != null && ((_f = toolCall2.function) == null ? void 0 : _f.arguments) != null) {
|
|
671
979
|
if (toolCall2.function.arguments.length > 0) {
|
|
672
980
|
controller.enqueue({
|
|
673
981
|
type: "tool-input-delta",
|
|
@@ -682,7 +990,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
682
990
|
});
|
|
683
991
|
controller.enqueue({
|
|
684
992
|
type: "tool-call",
|
|
685
|
-
toolCallId: (
|
|
993
|
+
toolCallId: (_g = toolCall2.id) != null ? _g : generateId(),
|
|
686
994
|
toolName: toolCall2.function.name,
|
|
687
995
|
input: toolCall2.function.arguments
|
|
688
996
|
});
|
|
@@ -695,22 +1003,22 @@ var DeepSeekChatLanguageModel = class {
|
|
|
695
1003
|
if (toolCall.hasFinished) {
|
|
696
1004
|
continue;
|
|
697
1005
|
}
|
|
698
|
-
if (((
|
|
699
|
-
toolCall.function.arguments += (
|
|
1006
|
+
if (((_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null) {
|
|
1007
|
+
toolCall.function.arguments += (_j = (_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null ? _j : "";
|
|
700
1008
|
}
|
|
701
1009
|
controller.enqueue({
|
|
702
1010
|
type: "tool-input-delta",
|
|
703
1011
|
id: toolCall.id,
|
|
704
|
-
delta: (
|
|
1012
|
+
delta: (_k = toolCallDelta.function.arguments) != null ? _k : ""
|
|
705
1013
|
});
|
|
706
|
-
if (((
|
|
1014
|
+
if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
707
1015
|
controller.enqueue({
|
|
708
1016
|
type: "tool-input-end",
|
|
709
1017
|
id: toolCall.id
|
|
710
1018
|
});
|
|
711
1019
|
controller.enqueue({
|
|
712
1020
|
type: "tool-call",
|
|
713
|
-
toolCallId: (
|
|
1021
|
+
toolCallId: (_n = toolCall.id) != null ? _n : generateId(),
|
|
714
1022
|
toolName: toolCall.function.name,
|
|
715
1023
|
input: toolCall.function.arguments
|
|
716
1024
|
});
|
|
@@ -754,7 +1062,24 @@ var DeepSeekChatLanguageModel = class {
|
|
|
754
1062
|
providerMetadata: {
|
|
755
1063
|
[providerOptionsName]: {
|
|
756
1064
|
promptCacheHitTokens: (_h = usage == null ? void 0 : usage.prompt_cache_hit_tokens) != null ? _h : null,
|
|
757
|
-
promptCacheMissTokens: (_i = usage == null ? void 0 : usage.prompt_cache_miss_tokens) != null ? _i : null
|
|
1065
|
+
promptCacheMissTokens: (_i = usage == null ? void 0 : usage.prompt_cache_miss_tokens) != null ? _i : null,
|
|
1066
|
+
...responseObject != null && { responseObject },
|
|
1067
|
+
...choiceIndex != null && { choiceIndex },
|
|
1068
|
+
...messageRole != null && { messageRole },
|
|
1069
|
+
...toolCallTypes.size > 0 && {
|
|
1070
|
+
toolCallTypes: [...toolCallTypes.entries()].sort(([left], [right]) => left - right).map(([, type]) => type)
|
|
1071
|
+
},
|
|
1072
|
+
...(contentLogprobs.length > 0 || reasoningLogprobs.length > 0) && {
|
|
1073
|
+
logprobs: {
|
|
1074
|
+
...contentLogprobs.length > 0 && {
|
|
1075
|
+
content: contentLogprobs
|
|
1076
|
+
},
|
|
1077
|
+
...reasoningLogprobs.length > 0 && {
|
|
1078
|
+
reasoning_content: reasoningLogprobs
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
},
|
|
1082
|
+
...systemFingerprint != null && { systemFingerprint }
|
|
758
1083
|
}
|
|
759
1084
|
}
|
|
760
1085
|
});
|
|
@@ -768,6 +1093,8 @@ var DeepSeekChatLanguageModel = class {
|
|
|
768
1093
|
};
|
|
769
1094
|
export {
|
|
770
1095
|
DeepSeekChatLanguageModel,
|
|
771
|
-
|
|
1096
|
+
deepseekAssistantMessageProviderOptions,
|
|
1097
|
+
deepseekChatOptions,
|
|
1098
|
+
deepseekMessageProviderOptions
|
|
772
1099
|
};
|
|
773
1100
|
//# sourceMappingURL=index.mjs.map
|