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