@ai-sdk/deepseek 3.0.30 → 3.0.32

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.
@@ -7,7 +7,7 @@ import {
7
7
  generateId,
8
8
  isCustomReasoning,
9
9
  mapReasoningToProviderEffort,
10
- parseProviderOptions,
10
+ parseProviderOptions as parseProviderOptions2,
11
11
  postJsonToApi,
12
12
  serializeModelOptions,
13
13
  StreamingToolCallTracker,
@@ -16,16 +16,113 @@ import {
16
16
  } from "@ai-sdk/provider-utils";
17
17
 
18
18
  // src/chat/convert-to-deepseek-chat-messages.ts
19
+ import {
20
+ InvalidPromptError,
21
+ UnsupportedFunctionalityError
22
+ } from "@ai-sdk/provider";
19
23
  import {
20
24
  convertToBase64,
21
25
  getTopLevelMediaType,
26
+ parseProviderOptions,
22
27
  resolveFullMediaType,
23
28
  resolveProviderReference
24
29
  } from "@ai-sdk/provider-utils";
25
- function convertToDeepSeekChatMessages({
30
+
31
+ // src/chat/deepseek-file-part-options.ts
32
+ import { z } from "zod/v4";
33
+ var deepseekFilePartProviderOptions = z.object({
34
+ /**
35
+ * Controls how DeepSeek processes an image sent as an `image_url` part.
36
+ *
37
+ * @see https://api-docs.deepseek.com/api/create-chat-completion/
38
+ */
39
+ imageDetail: z.enum(["low", "high", "original", "auto"]).optional(),
40
+ /**
41
+ * Sends inline image data as a DeepSeek `file` part using `file_data`
42
+ * instead of an `image_url` data URL. When set, the file part's filename
43
+ * is preserved.
44
+ *
45
+ * This option only applies to inline image data. It cannot be combined
46
+ * with `imageDetail`.
47
+ */
48
+ fileData: z.literal(true).optional()
49
+ });
50
+
51
+ // src/chat/deepseek-chat-language-model-options.ts
52
+ import { z as z2 } from "zod/v4";
53
+ var deepseekLanguageModelChatOptions = z2.object({
54
+ /**
55
+ * Whether to return log probabilities for generated tokens.
56
+ */
57
+ logprobs: z2.boolean().optional(),
58
+ /**
59
+ * Number of most likely tokens to return at each token position.
60
+ *
61
+ * Setting this option automatically enables `logprobs`.
62
+ */
63
+ topLogprobs: z2.number().int().min(0).max(20).optional(),
64
+ /**
65
+ * An opaque identifier for the end user. DeepSeek uses this identifier for
66
+ * content-safety tracing and request isolation.
67
+ *
68
+ * Must contain only ASCII letters, numbers, underscores, and hyphens, and
69
+ * must be at most 512 characters long.
70
+ */
71
+ userId: z2.string().regex(/^[a-zA-Z0-9_-]+$/, "userId must match /^[a-zA-Z0-9_-]+$/").max(512, "userId must be at most 512 characters long").optional(),
72
+ /**
73
+ * Type of thinking to use. Defaults to `enabled`.
74
+ */
75
+ thinking: z2.object({
76
+ // `adaptive` is accepted at runtime for backwards compatibility and
77
+ // mapped to `enabled`, but is intentionally excluded from the exported
78
+ // provider options type.
79
+ type: z2.enum(["adaptive", "enabled", "disabled"]).optional()
80
+ }).optional(),
81
+ /**
82
+ * Controls the thinking strength for DeepSeek V4 reasoning models.
83
+ */
84
+ // `medium` and `xhigh` are accepted at runtime for backwards compatibility
85
+ // and mapped to canonical DeepSeek values, but are intentionally excluded
86
+ // from the exported provider options type.
87
+ reasoningEffort: z2.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
88
+ /**
89
+ * Whether to use strict JSON schema validation for structured outputs.
90
+ * Only applies when the serving endpoint supports JSON schema response
91
+ * formats (e.g. Azure). Defaults to `true`.
92
+ */
93
+ strictJsonSchema: z2.boolean().optional()
94
+ });
95
+ var deepseekMessageProviderOptions = z2.object({
96
+ /**
97
+ * The name of the participant represented by the message.
98
+ *
99
+ * Supported on system, user, and assistant messages.
100
+ */
101
+ name: z2.string().optional()
102
+ });
103
+ var deepseekAssistantMessageProviderOptions = deepseekMessageProviderOptions.extend({
104
+ /**
105
+ * Whether the assistant message content is a prefix that DeepSeek should
106
+ * continue. This beta feature is only supported on the final assistant
107
+ * message when using a beta base URL.
108
+ */
109
+ prefix: z2.literal(true).optional()
110
+ });
111
+
112
+ // src/chat/convert-to-deepseek-chat-messages.ts
113
+ var supportedImageMediaTypes = /* @__PURE__ */ new Set([
114
+ "image/gif",
115
+ "image/jpeg",
116
+ "image/jpg",
117
+ "image/png",
118
+ "image/webp"
119
+ ]);
120
+ async function convertToDeepSeekChatMessages({
26
121
  prompt,
27
122
  responseFormat,
28
123
  modelId,
124
+ providerOptionsName = "deepseek",
125
+ supportsAssistantPrefixCompletion = false,
29
126
  supportsStructuredOutputs = false
30
127
  }) {
31
128
  var _a;
@@ -58,11 +155,28 @@ function convertToDeepSeekChatMessages({
58
155
  }
59
156
  }
60
157
  let index = -1;
61
- for (const { role, content } of prompt) {
158
+ for (const { role, content, providerOptions } of prompt) {
62
159
  index++;
160
+ const deepseekMessageOptions = await parseProviderOptions({
161
+ provider: providerOptionsName,
162
+ providerOptions,
163
+ schema: deepseekAssistantMessageProviderOptions
164
+ });
165
+ if ((deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.prefix) === true && role !== "assistant") {
166
+ throw new InvalidPromptError({
167
+ prompt,
168
+ message: "DeepSeek assistant prefix completion requires `prefix: true` on an assistant message."
169
+ });
170
+ }
63
171
  switch (role) {
64
172
  case "system": {
65
- messages.push({ role: "system", content });
173
+ messages.push({
174
+ role: "system",
175
+ content,
176
+ ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
177
+ name: deepseekMessageOptions.name
178
+ }
179
+ });
66
180
  break;
67
181
  }
68
182
  case "user": {
@@ -81,7 +195,13 @@ function convertToDeepSeekChatMessages({
81
195
  });
82
196
  }
83
197
  }
84
- messages.push({ role: "user", content: userContent2 });
198
+ messages.push({
199
+ role: "user",
200
+ content: userContent2,
201
+ ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
202
+ name: deepseekMessageOptions.name
203
+ }
204
+ });
85
205
  break;
86
206
  }
87
207
  const userContent = [];
@@ -89,6 +209,11 @@ function convertToDeepSeekChatMessages({
89
209
  if (part.type === "text") {
90
210
  userContent.push({ type: "text", text: part.text });
91
211
  } else if (part.type === "file" && getTopLevelMediaType(part.mediaType) === "image") {
212
+ const filePartOptions = await parseProviderOptions({
213
+ provider: providerOptionsName,
214
+ providerOptions: part.providerOptions,
215
+ schema: deepseekFilePartProviderOptions
216
+ });
92
217
  if (part.data.type === "reference") {
93
218
  userContent.push({
94
219
  type: "file",
@@ -98,12 +223,62 @@ function convertToDeepSeekChatMessages({
98
223
  })
99
224
  });
100
225
  } else if (part.data.type === "url" || part.data.type === "data") {
101
- userContent.push({
102
- type: "image_url",
103
- image_url: {
104
- url: part.data.type === "url" ? part.data.url.toString() : `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`
226
+ const resolvedMediaType = resolveFullMediaType({ part });
227
+ if (!supportedImageMediaTypes.has(resolvedMediaType)) {
228
+ throw new UnsupportedFunctionalityError({
229
+ functionality: `DeepSeek image media type ${resolvedMediaType}`,
230
+ message: "DeepSeek supports JPEG, PNG, GIF, and WebP image inputs."
231
+ });
232
+ }
233
+ if (part.data.type === "url") {
234
+ const url = part.data.url.toString();
235
+ if (url.length > 8192) {
236
+ throw new InvalidPromptError({
237
+ prompt,
238
+ message: "DeepSeek image URLs must not exceed 8192 characters."
239
+ });
105
240
  }
106
- });
241
+ if ((filePartOptions == null ? void 0 : filePartOptions.fileData) === true) {
242
+ throw new InvalidPromptError({
243
+ prompt,
244
+ message: "DeepSeek `fileData` image parts require inline data, not a URL."
245
+ });
246
+ }
247
+ userContent.push({
248
+ type: "image_url",
249
+ image_url: {
250
+ url,
251
+ ...(filePartOptions == null ? void 0 : filePartOptions.imageDetail) != null && {
252
+ detail: filePartOptions.imageDetail
253
+ }
254
+ }
255
+ });
256
+ } else {
257
+ const dataUrl = `data:${resolvedMediaType === "image/jpg" ? "image/jpeg" : resolvedMediaType};base64,${convertToBase64(part.data.data)}`;
258
+ if ((filePartOptions == null ? void 0 : filePartOptions.fileData) === true) {
259
+ if (filePartOptions.imageDetail != null) {
260
+ throw new InvalidPromptError({
261
+ prompt,
262
+ message: "DeepSeek `imageDetail` cannot be combined with `fileData`."
263
+ });
264
+ }
265
+ userContent.push({
266
+ type: "file",
267
+ file_data: dataUrl,
268
+ ...part.filename != null && { filename: part.filename }
269
+ });
270
+ } else {
271
+ userContent.push({
272
+ type: "image_url",
273
+ image_url: {
274
+ url: dataUrl,
275
+ ...(filePartOptions == null ? void 0 : filePartOptions.imageDetail) != null && {
276
+ detail: filePartOptions.imageDetail
277
+ }
278
+ }
279
+ });
280
+ }
281
+ }
107
282
  } else {
108
283
  warnings.push({
109
284
  type: "unsupported",
@@ -119,11 +294,28 @@ function convertToDeepSeekChatMessages({
119
294
  }
120
295
  messages.push({
121
296
  role: "user",
122
- content: userContent
297
+ content: userContent,
298
+ ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
299
+ name: deepseekMessageOptions.name
300
+ }
123
301
  });
124
302
  break;
125
303
  }
126
304
  case "assistant": {
305
+ if ((deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.prefix) === true) {
306
+ if (index !== prompt.length - 1) {
307
+ throw new InvalidPromptError({
308
+ prompt,
309
+ message: "DeepSeek assistant prefix completion requires the prefixed assistant message to be the final message."
310
+ });
311
+ }
312
+ if (!supportsAssistantPrefixCompletion) {
313
+ throw new UnsupportedFunctionalityError({
314
+ functionality: "DeepSeek assistant prefix completion",
315
+ message: "DeepSeek assistant prefix completion requires a beta base URL ending in `/beta`."
316
+ });
317
+ }
318
+ }
127
319
  let text = "";
128
320
  let reasoning;
129
321
  const toolCalls = [];
@@ -160,12 +352,24 @@ function convertToDeepSeekChatMessages({
160
352
  messages.push({
161
353
  role: "assistant",
162
354
  content: text,
355
+ ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
356
+ name: deepseekMessageOptions.name
357
+ },
358
+ ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.prefix) === true && {
359
+ prefix: true
360
+ },
163
361
  reasoning_content: reasoning != null ? reasoning : isDeepSeekV4 ? "" : void 0,
164
362
  tool_calls: toolCalls.length > 0 ? toolCalls : void 0
165
363
  });
166
364
  break;
167
365
  }
168
366
  case "tool": {
367
+ if ((deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null) {
368
+ warnings.push({
369
+ type: "unsupported",
370
+ feature: "message name on tool messages"
371
+ });
372
+ }
169
373
  for (const toolResponse of content) {
170
374
  if (toolResponse.type === "tool-approval-response") {
171
375
  continue;
@@ -226,7 +430,7 @@ function convertDeepSeekUsage(usage) {
226
430
  },
227
431
  outputTokens: {
228
432
  total: completionTokens,
229
- text: completionTokens - reasoningTokens,
433
+ text: Math.max(0, completionTokens - reasoningTokens),
230
434
  reasoning: reasoningTokens
231
435
  },
232
436
  raw: usage
@@ -235,75 +439,101 @@ function convertDeepSeekUsage(usage) {
235
439
 
236
440
  // src/chat/deepseek-chat-api-types.ts
237
441
  import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
238
- import { z } from "zod/v4";
239
- var tokenUsageSchema = z.object({
240
- prompt_tokens: z.number().nullish(),
241
- completion_tokens: z.number().nullish(),
242
- prompt_cache_hit_tokens: z.number().nullish(),
243
- prompt_cache_miss_tokens: z.number().nullish(),
244
- total_tokens: z.number().nullish(),
245
- completion_tokens_details: z.object({
246
- reasoning_tokens: z.number().nullish()
442
+ import { z as z3 } from "zod/v4";
443
+ var tokenUsageSchema = z3.object({
444
+ prompt_tokens: z3.number().nullish(),
445
+ completion_tokens: z3.number().nullish(),
446
+ prompt_cache_hit_tokens: z3.number().nullish(),
447
+ prompt_cache_miss_tokens: z3.number().nullish(),
448
+ total_tokens: z3.number().nullish(),
449
+ completion_tokens_details: z3.object({
450
+ reasoning_tokens: z3.number().nullish()
247
451
  }).nullish()
248
452
  }).nullish();
249
- var deepSeekErrorSchema = z.object({
250
- error: z.object({
251
- message: z.string(),
252
- type: z.string().nullish(),
253
- param: z.any().nullish(),
254
- code: z.union([z.string(), z.number()]).nullish()
453
+ var deepSeekErrorSchema = z3.object({
454
+ error: z3.object({
455
+ message: z3.string(),
456
+ type: z3.string().nullish(),
457
+ param: z3.any().nullish(),
458
+ code: z3.union([z3.string(), z3.number()]).nullish()
255
459
  })
256
460
  });
257
- var deepseekChatResponseSchema = z.object({
258
- id: z.string().nullish(),
259
- created: z.number().nullish(),
260
- model: z.string().nullish(),
261
- choices: z.array(
262
- z.object({
263
- message: z.object({
264
- role: z.literal("assistant").nullish(),
265
- content: z.string().nullish(),
266
- reasoning_content: z.string().nullish(),
267
- tool_calls: z.array(
268
- z.object({
269
- id: z.string().nullish(),
270
- function: z.object({
271
- name: z.string(),
272
- arguments: z.string()
461
+ var deepseekChatLogprobSchema = z3.object({
462
+ token: z3.string(),
463
+ logprob: z3.number(),
464
+ bytes: z3.array(z3.number()).nullable(),
465
+ top_logprobs: z3.array(
466
+ z3.object({
467
+ token: z3.string(),
468
+ logprob: z3.number(),
469
+ bytes: z3.array(z3.number()).nullable()
470
+ })
471
+ )
472
+ });
473
+ var deepseekChatLogprobsSchema = z3.object({
474
+ content: z3.array(deepseekChatLogprobSchema).nullish(),
475
+ reasoning_content: z3.array(deepseekChatLogprobSchema).nullish()
476
+ }).nullish();
477
+ var deepseekChatResponseSchema = z3.object({
478
+ id: z3.string().nullish(),
479
+ created: z3.number().nullish(),
480
+ model: z3.string().nullish(),
481
+ object: z3.literal("chat.completion").nullish(),
482
+ system_fingerprint: z3.string().nullish(),
483
+ choices: z3.array(
484
+ z3.object({
485
+ index: z3.number().nullish(),
486
+ message: z3.object({
487
+ role: z3.literal("assistant").nullish(),
488
+ content: z3.string().nullish(),
489
+ reasoning_content: z3.string().nullish(),
490
+ tool_calls: z3.array(
491
+ z3.object({
492
+ id: z3.string().nullish(),
493
+ type: z3.literal("function").nullish(),
494
+ function: z3.object({
495
+ name: z3.string(),
496
+ arguments: z3.string()
273
497
  })
274
498
  })
275
499
  ).nullish()
276
500
  }),
277
- finish_reason: z.string().nullish()
501
+ logprobs: deepseekChatLogprobsSchema,
502
+ finish_reason: z3.string().nullish()
278
503
  })
279
504
  ),
280
505
  usage: tokenUsageSchema
281
506
  });
282
507
  var deepseekChatChunkSchema = lazySchema(
283
508
  () => zodSchema(
284
- z.union([
285
- z.object({
286
- id: z.string().nullish(),
287
- created: z.number().nullish(),
288
- model: z.string().nullish(),
289
- choices: z.array(
290
- z.object({
291
- delta: z.object({
292
- role: z.enum(["assistant"]).nullish(),
293
- content: z.string().nullish(),
294
- reasoning_content: z.string().nullish(),
295
- tool_calls: z.array(
296
- z.object({
297
- index: z.number(),
298
- id: z.string().nullish(),
299
- function: z.object({
300
- name: z.string().nullish(),
301
- arguments: z.string().nullish()
509
+ z3.union([
510
+ z3.object({
511
+ id: z3.string().nullish(),
512
+ created: z3.number().nullish(),
513
+ model: z3.string().nullish(),
514
+ object: z3.literal("chat.completion.chunk").nullish(),
515
+ system_fingerprint: z3.string().nullish(),
516
+ choices: z3.array(
517
+ z3.object({
518
+ index: z3.number().nullish(),
519
+ delta: z3.object({
520
+ role: z3.enum(["assistant"]).nullish(),
521
+ content: z3.string().nullish(),
522
+ reasoning_content: z3.string().nullish(),
523
+ tool_calls: z3.array(
524
+ z3.object({
525
+ index: z3.number(),
526
+ id: z3.string().nullish(),
527
+ type: z3.literal("function").nullish(),
528
+ function: z3.object({
529
+ name: z3.string().nullish(),
530
+ arguments: z3.string().nullish()
302
531
  })
303
532
  })
304
533
  ).nullish()
305
534
  }).nullish(),
306
- finish_reason: z.string().nullish()
535
+ logprobs: deepseekChatLogprobsSchema,
536
+ finish_reason: z3.string().nullish()
307
537
  })
308
538
  ),
309
539
  usage: tokenUsageSchema
@@ -313,44 +543,34 @@ var deepseekChatChunkSchema = lazySchema(
313
543
  )
314
544
  );
315
545
 
316
- // src/chat/deepseek-chat-language-model-options.ts
317
- import { z as z2 } from "zod/v4";
318
- var deepseekLanguageModelChatOptions = z2.object({
319
- /**
320
- * Type of thinking to use. Defaults to `enabled`.
321
- *
322
- * See https://api-docs.deepseek.com/guides/thinking_mode for the
323
- * `adaptive` option, which lets the model decide when to think.
324
- */
325
- thinking: z2.object({
326
- type: z2.enum(["adaptive", "enabled", "disabled"]).optional()
327
- }).optional(),
328
- /**
329
- * Controls the thinking strength for DeepSeek V4 reasoning models.
330
- *
331
- * DeepSeek's API accepts `low`, `medium`, `high`, `xhigh`, and `max`.
332
- * Per their docs, `low` and `medium` are mapped to `high`, and `xhigh`
333
- * is mapped to `max` server-side for compatibility with other providers.
334
- */
335
- reasoningEffort: z2.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
336
- /**
337
- * Whether to use strict JSON schema validation for structured outputs.
338
- * Only applies when the serving endpoint supports JSON schema response
339
- * formats (e.g. Azure). Defaults to `true`.
340
- */
341
- strictJsonSchema: z2.boolean().optional()
342
- });
343
-
344
546
  // src/chat/deepseek-prepare-tools.ts
547
+ import {
548
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError2
549
+ } from "@ai-sdk/provider";
345
550
  function prepareTools({
346
551
  tools,
347
- toolChoice
552
+ toolChoice,
553
+ supportsStrictToolCalls
348
554
  }) {
349
555
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
350
556
  const toolWarnings = [];
351
557
  if (tools == null) {
352
558
  return { tools: void 0, toolChoice: void 0, toolWarnings };
353
559
  }
560
+ const functionTools = tools.filter((tool) => tool.type === "function");
561
+ const hasStrictTool = functionTools.some((tool) => tool.strict === true);
562
+ if (hasStrictTool && supportsStrictToolCalls === false) {
563
+ throw new UnsupportedFunctionalityError2({
564
+ functionality: "DeepSeek strict tool calls",
565
+ message: "DeepSeek strict tool calls require a beta base URL ending in `/beta`."
566
+ });
567
+ }
568
+ if (hasStrictTool && supportsStrictToolCalls === true && functionTools.some((tool) => tool.strict !== true)) {
569
+ throw new UnsupportedFunctionalityError2({
570
+ functionality: "mixed DeepSeek strict and non-strict tool calls",
571
+ message: "DeepSeek strict mode requires every function tool in the request to set `strict: true`."
572
+ });
573
+ }
354
574
  const deepseekTools = [];
355
575
  for (const tool of tools) {
356
576
  if (tool.type === "provider") {
@@ -426,6 +646,20 @@ function mapDeepSeekFinishReason(finishReason) {
426
646
  }
427
647
 
428
648
  // src/chat/deepseek-chat-language-model.ts
649
+ function mapDeepSeekProviderReasoningEffort({
650
+ reasoningEffort,
651
+ warnings
652
+ }) {
653
+ const mapped = reasoningEffort === "medium" ? "high" : reasoningEffort === "xhigh" ? "max" : reasoningEffort;
654
+ if (mapped !== reasoningEffort) {
655
+ warnings.push({
656
+ type: "compatibility",
657
+ feature: "reasoningEffort",
658
+ details: `reasoningEffort "${reasoningEffort}" is not a canonical DeepSeek value. mapped to "${mapped}".`
659
+ });
660
+ }
661
+ return mapped;
662
+ }
429
663
  var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
430
664
  constructor(modelId, config) {
431
665
  this.specificationVersion = "v4";
@@ -470,17 +704,20 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
470
704
  toolChoice,
471
705
  tools
472
706
  }) {
473
- var _a, _b, _c, _d, _e;
474
- const deepseekOptions = (_a = await parseProviderOptions({
707
+ var _a, _b, _c, _d;
708
+ const deepseekOptions = (_a = await parseProviderOptions2({
475
709
  provider: this.providerOptionsName,
476
710
  providerOptions,
477
711
  schema: deepseekLanguageModelChatOptions
478
712
  })) != null ? _a : {};
479
713
  const supportsStructuredOutputs = this.config.supportsStructuredOutputs === true;
480
- const { messages, warnings } = convertToDeepSeekChatMessages({
714
+ const supportsPenaltySampling = this.config.supportsPenaltySampling === true;
715
+ const { messages, warnings } = await convertToDeepSeekChatMessages({
481
716
  prompt,
482
717
  responseFormat,
483
718
  modelId: this.modelId,
719
+ providerOptionsName: this.providerOptionsName,
720
+ supportsAssistantPrefixCompletion: this.config.supportsAssistantPrefixCompletion,
484
721
  supportsStructuredOutputs
485
722
  });
486
723
  const allWarnings = [...warnings];
@@ -490,21 +727,62 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
490
727
  if (seed != null) {
491
728
  allWarnings.push({ type: "unsupported", feature: "seed" });
492
729
  }
730
+ if (!supportsPenaltySampling && frequencyPenalty != null) {
731
+ allWarnings.push({
732
+ type: "deprecated",
733
+ setting: "frequencyPenalty",
734
+ message: "frequencyPenalty is deprecated by DeepSeek and has been omitted. Remove frequencyPenalty from the request."
735
+ });
736
+ }
737
+ if (!supportsPenaltySampling && presencePenalty != null) {
738
+ allWarnings.push({
739
+ type: "deprecated",
740
+ setting: "presencePenalty",
741
+ message: "presencePenalty is deprecated by DeepSeek and has been omitted. Remove presencePenalty from the request."
742
+ });
743
+ }
493
744
  const {
494
745
  tools: deepseekTools,
495
746
  toolChoice: deepseekToolChoices,
496
747
  toolWarnings
497
748
  } = prepareTools({
498
749
  tools,
499
- toolChoice
750
+ toolChoice,
751
+ supportsStrictToolCalls: this.config.supportsStrictToolCalls
500
752
  });
501
- const thinking = this.config.supportsThinking === false ? void 0 : ((_b = deepseekOptions.thinking) == null ? void 0 : _b.type) != null ? { type: deepseekOptions.thinking.type } : isCustomReasoning(reasoning) ? { type: reasoning === "none" ? "disabled" : "enabled" } : void 0;
502
- const reasoningEffort = (_c = deepseekOptions.reasoningEffort) != null ? _c : isCustomReasoning(reasoning) && reasoning !== "none" ? mapReasoningToProviderEffort({
753
+ const thinkingType = (_b = deepseekOptions.thinking) == null ? void 0 : _b.type;
754
+ if (thinkingType === "adaptive") {
755
+ allWarnings.push({
756
+ type: "compatibility",
757
+ feature: "thinking.type",
758
+ details: 'thinking.type "adaptive" is not a canonical DeepSeek value. mapped to "enabled".'
759
+ });
760
+ }
761
+ const thinking = this.config.supportsThinking === false ? void 0 : thinkingType != null ? { type: thinkingType === "adaptive" ? "enabled" : thinkingType } : isCustomReasoning(reasoning) ? { type: reasoning === "none" ? "disabled" : "enabled" } : void 0;
762
+ const isThinkingEnabled = this.config.supportsThinking !== false && (thinking == null ? void 0 : thinking.type) !== "disabled" && (thinking != null || this.modelId === "deepseek-reasoner" || this.modelId.includes("deepseek-v4"));
763
+ if (isThinkingEnabled && temperature != null) {
764
+ allWarnings.push({
765
+ type: "unsupported",
766
+ feature: "temperature",
767
+ details: "temperature has no effect when DeepSeek thinking is enabled. Set providerOptions.deepseek.thinking.type to 'disabled' to use temperature."
768
+ });
769
+ }
770
+ if (isThinkingEnabled && topP != null) {
771
+ allWarnings.push({
772
+ type: "unsupported",
773
+ feature: "topP",
774
+ details: "topP has no effect when DeepSeek thinking is enabled. Set providerOptions.deepseek.thinking.type to 'disabled' to use topP."
775
+ });
776
+ }
777
+ const reasoningEffort = deepseekOptions.reasoningEffort != null ? mapDeepSeekProviderReasoningEffort({
778
+ reasoningEffort: deepseekOptions.reasoningEffort,
779
+ warnings: allWarnings
780
+ }) : isCustomReasoning(reasoning) && reasoning !== "none" ? mapReasoningToProviderEffort({
503
781
  reasoning,
504
782
  effortMap: {
505
783
  minimal: "low",
506
784
  low: "low",
507
- medium: "medium",
785
+ medium: "high",
508
786
  high: "high",
509
787
  xhigh: "max"
510
788
  },
@@ -513,17 +791,21 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
513
791
  return {
514
792
  args: {
515
793
  model: this.modelId,
794
+ ...(deepseekOptions.logprobs === true || deepseekOptions.topLogprobs != null) && { logprobs: true },
795
+ ...deepseekOptions.topLogprobs != null && {
796
+ top_logprobs: deepseekOptions.topLogprobs
797
+ },
516
798
  max_tokens: maxOutputTokens,
517
- temperature,
518
- top_p: topP,
519
- frequency_penalty: frequencyPenalty,
520
- presence_penalty: presencePenalty,
799
+ temperature: isThinkingEnabled ? void 0 : temperature,
800
+ top_p: isThinkingEnabled ? void 0 : topP,
801
+ frequency_penalty: supportsPenaltySampling ? frequencyPenalty : void 0,
802
+ presence_penalty: supportsPenaltySampling ? presencePenalty : void 0,
521
803
  response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? supportsStructuredOutputs && responseFormat.schema != null ? {
522
804
  type: "json_schema",
523
805
  json_schema: {
524
806
  schema: responseFormat.schema,
525
- strict: (_d = deepseekOptions.strictJsonSchema) != null ? _d : true,
526
- name: (_e = responseFormat.name) != null ? _e : "response",
807
+ strict: (_c = deepseekOptions.strictJsonSchema) != null ? _c : true,
808
+ name: (_d = responseFormat.name) != null ? _d : "response",
527
809
  description: responseFormat.description
528
810
  }
529
811
  } : { type: "json_object" } : void 0,
@@ -532,6 +814,9 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
532
814
  tools: deepseekTools,
533
815
  tool_choice: deepseekToolChoices,
534
816
  thinking,
817
+ ...deepseekOptions.userId != null && {
818
+ user_id: deepseekOptions.userId
819
+ },
535
820
  ...(thinking == null ? void 0 : thinking.type) !== "disabled" && reasoningEffort != null && {
536
821
  reasoning_effort: reasoningEffort
537
822
  }
@@ -593,7 +878,21 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
593
878
  providerMetadata: {
594
879
  [this.providerOptionsName]: {
595
880
  promptCacheHitTokens: (_d = responseBody.usage) == null ? void 0 : _d.prompt_cache_hit_tokens,
596
- promptCacheMissTokens: (_e = responseBody.usage) == null ? void 0 : _e.prompt_cache_miss_tokens
881
+ promptCacheMissTokens: (_e = responseBody.usage) == null ? void 0 : _e.prompt_cache_miss_tokens,
882
+ ...responseBody.object != null && {
883
+ responseObject: responseBody.object
884
+ },
885
+ ...choice.index != null && { choiceIndex: choice.index },
886
+ ...choice.message.role != null && {
887
+ messageRole: choice.message.role
888
+ },
889
+ ...choice.message.tool_calls != null && {
890
+ toolCallTypes: choice.message.tool_calls.map((toolCall) => toolCall.type).filter((type) => type != null)
891
+ },
892
+ ...choice.logprobs != null && { logprobs: choice.logprobs },
893
+ ...responseBody.system_fingerprint != null && {
894
+ systemFingerprint: responseBody.system_fingerprint
895
+ }
597
896
  }
598
897
  },
599
898
  request: { body: args },
@@ -633,10 +932,17 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
633
932
  raw: void 0
634
933
  };
635
934
  let usage = void 0;
935
+ let systemFingerprint = void 0;
636
936
  let isFirstChunk = true;
637
937
  const providerOptionsName = this.providerOptionsName;
638
938
  let isActiveReasoning = false;
639
939
  let isActiveText = false;
940
+ let responseObject;
941
+ let choiceIndex;
942
+ let messageRole;
943
+ const toolCallTypes = /* @__PURE__ */ new Map();
944
+ const contentLogprobs = [];
945
+ const reasoningLogprobs = [];
640
946
  return {
641
947
  stream: response.pipeThrough(
642
948
  new TransformStream({
@@ -647,6 +953,7 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
647
953
  controller.enqueue({ type: "stream-start", warnings });
648
954
  },
649
955
  transform(chunk, controller) {
956
+ var _a2, _b2;
650
957
  if (options.includeRawChunks) {
651
958
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
652
959
  }
@@ -671,17 +978,35 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
671
978
  if (value.usage != null) {
672
979
  usage = value.usage;
673
980
  }
981
+ if (value.object != null) {
982
+ responseObject = value.object;
983
+ }
984
+ if (value.system_fingerprint != null) {
985
+ systemFingerprint = value.system_fingerprint;
986
+ }
674
987
  const choice = value.choices[0];
988
+ if ((choice == null ? void 0 : choice.index) != null) {
989
+ choiceIndex = choice.index;
990
+ }
675
991
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
676
992
  finishReason = {
677
993
  unified: mapDeepSeekFinishReason(choice.finish_reason),
678
994
  raw: choice.finish_reason
679
995
  };
680
996
  }
997
+ if (((_a2 = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _a2.content) != null) {
998
+ contentLogprobs.push(...choice.logprobs.content);
999
+ }
1000
+ if (((_b2 = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _b2.reasoning_content) != null) {
1001
+ reasoningLogprobs.push(...choice.logprobs.reasoning_content);
1002
+ }
681
1003
  if ((choice == null ? void 0 : choice.delta) == null) {
682
1004
  return;
683
1005
  }
684
1006
  const delta = choice.delta;
1007
+ if (delta.role != null) {
1008
+ messageRole = delta.role;
1009
+ }
685
1010
  const reasoningContent = delta.reasoning_content;
686
1011
  if (reasoningContent) {
687
1012
  if (!isActiveReasoning) {
@@ -724,6 +1049,9 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
724
1049
  isActiveReasoning = false;
725
1050
  }
726
1051
  for (const toolCallDelta of delta.tool_calls) {
1052
+ if (toolCallDelta.type != null) {
1053
+ toolCallTypes.set(toolCallDelta.index, toolCallDelta.type);
1054
+ }
727
1055
  toolCallTracker.processDelta(toolCallDelta);
728
1056
  }
729
1057
  }
@@ -744,7 +1072,24 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
744
1072
  providerMetadata: {
745
1073
  [providerOptionsName]: {
746
1074
  promptCacheHitTokens: (_a2 = usage == null ? void 0 : usage.prompt_cache_hit_tokens) != null ? _a2 : void 0,
747
- promptCacheMissTokens: (_b2 = usage == null ? void 0 : usage.prompt_cache_miss_tokens) != null ? _b2 : void 0
1075
+ promptCacheMissTokens: (_b2 = usage == null ? void 0 : usage.prompt_cache_miss_tokens) != null ? _b2 : void 0,
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 }
748
1093
  }
749
1094
  }
750
1095
  });
@@ -758,6 +1103,8 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
758
1103
  };
759
1104
  export {
760
1105
  DeepSeekChatLanguageModel,
761
- deepseekLanguageModelChatOptions
1106
+ deepseekAssistantMessageProviderOptions,
1107
+ deepseekLanguageModelChatOptions,
1108
+ deepseekMessageProviderOptions
762
1109
  };
763
1110
  //# sourceMappingURL=index.js.map