@ai-sdk/deepseek 2.0.58 → 2.0.60

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.
@@ -21,20 +21,115 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  DeepSeekChatLanguageModel: () => DeepSeekChatLanguageModel,
24
- deepseekLanguageModelOptions: () => deepseekLanguageModelOptions
24
+ deepseekAssistantMessageProviderOptions: () => deepseekAssistantMessageProviderOptions,
25
+ deepseekLanguageModelOptions: () => deepseekLanguageModelOptions,
26
+ deepseekMessageProviderOptions: () => deepseekMessageProviderOptions
25
27
  });
26
28
  module.exports = __toCommonJS(index_exports);
27
29
 
28
30
  // src/chat/deepseek-chat-language-model.ts
29
- var import_provider = require("@ai-sdk/provider");
31
+ var import_provider3 = require("@ai-sdk/provider");
30
32
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
31
33
 
32
34
  // src/chat/convert-to-deepseek-chat-messages.ts
35
+ var import_provider = require("@ai-sdk/provider");
33
36
  var import_provider_utils = require("@ai-sdk/provider-utils");
34
- function convertToDeepSeekChatMessages({
37
+
38
+ // src/chat/deepseek-chat-options.ts
39
+ var import_v4 = require("zod/v4");
40
+ var deepseekLanguageModelOptions = import_v4.z.object({
41
+ /**
42
+ * Whether to return log probabilities for generated tokens.
43
+ */
44
+ logprobs: import_v4.z.boolean().optional(),
45
+ /**
46
+ * Number of most likely tokens to return at each token position.
47
+ *
48
+ * Setting this option automatically enables `logprobs`.
49
+ */
50
+ topLogprobs: import_v4.z.number().int().min(0).max(20).optional(),
51
+ /**
52
+ * An opaque identifier for the end user. DeepSeek uses this identifier for
53
+ * content-safety tracing and request isolation.
54
+ *
55
+ * Must contain only ASCII letters, numbers, underscores, and hyphens, and
56
+ * must be at most 512 characters long.
57
+ */
58
+ userId: import_v4.z.string().regex(/^[a-zA-Z0-9_-]+$/, "userId must match /^[a-zA-Z0-9_-]+$/").max(512, "userId must be at most 512 characters long").optional(),
59
+ /**
60
+ * Type of thinking to use. Defaults to `enabled`.
61
+ */
62
+ thinking: import_v4.z.object({
63
+ // `adaptive` is accepted at runtime for backwards compatibility and
64
+ // mapped to `enabled`, but is intentionally excluded from the exported
65
+ // provider options type.
66
+ type: import_v4.z.enum(["adaptive", "enabled", "disabled"]).optional()
67
+ }).optional(),
68
+ /**
69
+ * Controls the thinking strength for DeepSeek V4 reasoning models.
70
+ */
71
+ // `medium` and `xhigh` are accepted at runtime for backwards compatibility
72
+ // and mapped to canonical DeepSeek values, but are intentionally excluded
73
+ // from the exported provider options type.
74
+ reasoningEffort: import_v4.z.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
75
+ /**
76
+ * Whether to use strict JSON schema validation for structured outputs.
77
+ * Only applies when the serving endpoint supports JSON schema response
78
+ * formats (e.g. Azure). Defaults to `true`.
79
+ */
80
+ strictJsonSchema: import_v4.z.boolean().optional()
81
+ });
82
+ var deepseekMessageProviderOptions = import_v4.z.object({
83
+ /**
84
+ * The name of the participant represented by the message.
85
+ *
86
+ * Supported on system, user, and assistant messages.
87
+ */
88
+ name: import_v4.z.string().optional()
89
+ });
90
+ var deepseekAssistantMessageProviderOptions = deepseekMessageProviderOptions.extend({
91
+ /**
92
+ * Whether the assistant message content is a prefix that DeepSeek should
93
+ * continue. This beta feature is only supported on the final assistant
94
+ * message when using a beta base URL.
95
+ */
96
+ prefix: import_v4.z.literal(true).optional()
97
+ });
98
+
99
+ // src/chat/deepseek-file-part-options.ts
100
+ var import_v42 = require("zod/v4");
101
+ var deepseekFilePartProviderOptions = import_v42.z.object({
102
+ /**
103
+ * Controls how DeepSeek processes an image sent as an `image_url` part.
104
+ *
105
+ * @see https://api-docs.deepseek.com/api/create-chat-completion/
106
+ */
107
+ imageDetail: import_v42.z.enum(["low", "high", "original", "auto"]).optional(),
108
+ /**
109
+ * Sends inline image data as a DeepSeek `file` part using `file_data`
110
+ * instead of an `image_url` data URL. When set, the file part's filename
111
+ * is preserved.
112
+ *
113
+ * This option only applies to inline image data. It cannot be combined
114
+ * with `imageDetail`.
115
+ */
116
+ fileData: import_v42.z.literal(true).optional()
117
+ });
118
+
119
+ // src/chat/convert-to-deepseek-chat-messages.ts
120
+ var supportedImageMediaTypes = /* @__PURE__ */ new Set([
121
+ "image/gif",
122
+ "image/jpeg",
123
+ "image/jpg",
124
+ "image/png",
125
+ "image/webp"
126
+ ]);
127
+ async function convertToDeepSeekChatMessages({
35
128
  prompt,
36
129
  responseFormat,
37
130
  modelId,
131
+ providerOptionsName = "deepseek",
132
+ supportsAssistantPrefixCompletion = false,
38
133
  supportsStructuredOutputs = false
39
134
  }) {
40
135
  var _a;
@@ -67,11 +162,28 @@ function convertToDeepSeekChatMessages({
67
162
  }
68
163
  }
69
164
  let index = -1;
70
- for (const { role, content } of prompt) {
165
+ for (const { role, content, providerOptions } of prompt) {
71
166
  index++;
167
+ const deepseekMessageOptions = await (0, import_provider_utils.parseProviderOptions)({
168
+ provider: providerOptionsName,
169
+ providerOptions,
170
+ schema: deepseekAssistantMessageProviderOptions
171
+ });
172
+ if ((deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.prefix) === true && role !== "assistant") {
173
+ throw new import_provider.InvalidPromptError({
174
+ prompt,
175
+ message: "DeepSeek assistant prefix completion requires `prefix: true` on an assistant message."
176
+ });
177
+ }
72
178
  switch (role) {
73
179
  case "system": {
74
- messages.push({ role: "system", content });
180
+ messages.push({
181
+ role: "system",
182
+ content,
183
+ ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
184
+ name: deepseekMessageOptions.name
185
+ }
186
+ });
75
187
  break;
76
188
  }
77
189
  case "user": {
@@ -90,7 +202,13 @@ function convertToDeepSeekChatMessages({
90
202
  });
91
203
  }
92
204
  }
93
- messages.push({ role: "user", content: userContent2 });
205
+ messages.push({
206
+ role: "user",
207
+ content: userContent2,
208
+ ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
209
+ name: deepseekMessageOptions.name
210
+ }
211
+ });
94
212
  break;
95
213
  }
96
214
  const userContent = [];
@@ -98,13 +216,67 @@ function convertToDeepSeekChatMessages({
98
216
  if (part.type === "text") {
99
217
  userContent.push({ type: "text", text: part.text });
100
218
  } else if (part.type === "file" && (part.mediaType === "image" || part.mediaType.startsWith("image/"))) {
101
- const mediaType = part.mediaType === "image" || part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
102
- userContent.push({
103
- type: "image_url",
104
- image_url: {
105
- url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${(0, import_provider_utils.convertToBase64)(part.data)}`
106
- }
219
+ const filePartOptions = await (0, import_provider_utils.parseProviderOptions)({
220
+ provider: providerOptionsName,
221
+ providerOptions: part.providerOptions,
222
+ schema: deepseekFilePartProviderOptions
107
223
  });
224
+ const resolvedMediaType = part.mediaType === "image" || part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
225
+ if (!supportedImageMediaTypes.has(resolvedMediaType)) {
226
+ throw new import_provider.UnsupportedFunctionalityError({
227
+ functionality: `DeepSeek image media type ${resolvedMediaType}`,
228
+ message: "DeepSeek supports JPEG, PNG, GIF, and WebP image inputs."
229
+ });
230
+ }
231
+ if (part.data instanceof URL) {
232
+ const url = part.data.toString();
233
+ if (url.length > 8192) {
234
+ throw new import_provider.InvalidPromptError({
235
+ prompt,
236
+ message: "DeepSeek image URLs must not exceed 8192 characters."
237
+ });
238
+ }
239
+ if ((filePartOptions == null ? void 0 : filePartOptions.fileData) === true) {
240
+ throw new import_provider.InvalidPromptError({
241
+ prompt,
242
+ message: "DeepSeek `fileData` image parts require inline data, not a URL."
243
+ });
244
+ }
245
+ userContent.push({
246
+ type: "image_url",
247
+ image_url: {
248
+ url,
249
+ ...(filePartOptions == null ? void 0 : filePartOptions.imageDetail) != null && {
250
+ detail: filePartOptions.imageDetail
251
+ }
252
+ }
253
+ });
254
+ } else {
255
+ const dataUrl = `data:${resolvedMediaType === "image/jpg" ? "image/jpeg" : resolvedMediaType};base64,${(0, import_provider_utils.convertToBase64)(part.data)}`;
256
+ if ((filePartOptions == null ? void 0 : filePartOptions.fileData) === true) {
257
+ if (filePartOptions.imageDetail != null) {
258
+ throw new import_provider.InvalidPromptError({
259
+ prompt,
260
+ message: "DeepSeek `imageDetail` cannot be combined with `fileData`."
261
+ });
262
+ }
263
+ userContent.push({
264
+ type: "file",
265
+ file_data: dataUrl,
266
+ ...part.filename != null && { filename: part.filename }
267
+ });
268
+ } else {
269
+ userContent.push({
270
+ type: "image_url",
271
+ image_url: {
272
+ url: dataUrl,
273
+ ...(filePartOptions == null ? void 0 : filePartOptions.imageDetail) != null && {
274
+ detail: filePartOptions.imageDetail
275
+ }
276
+ }
277
+ });
278
+ }
279
+ }
108
280
  } else {
109
281
  warnings.push({
110
282
  type: "unsupported",
@@ -112,10 +284,30 @@ function convertToDeepSeekChatMessages({
112
284
  });
113
285
  }
114
286
  }
115
- messages.push({ role: "user", content: userContent });
287
+ messages.push({
288
+ role: "user",
289
+ content: userContent,
290
+ ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
291
+ name: deepseekMessageOptions.name
292
+ }
293
+ });
116
294
  break;
117
295
  }
118
296
  case "assistant": {
297
+ if ((deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.prefix) === true) {
298
+ if (index !== prompt.length - 1) {
299
+ throw new import_provider.InvalidPromptError({
300
+ prompt,
301
+ message: "DeepSeek assistant prefix completion requires the prefixed assistant message to be the final message."
302
+ });
303
+ }
304
+ if (!supportsAssistantPrefixCompletion) {
305
+ throw new import_provider.UnsupportedFunctionalityError({
306
+ functionality: "DeepSeek assistant prefix completion",
307
+ message: "DeepSeek assistant prefix completion requires a beta base URL ending in `/beta`."
308
+ });
309
+ }
310
+ }
119
311
  let text = "";
120
312
  let reasoning;
121
313
  const toolCalls = [];
@@ -152,12 +344,24 @@ function convertToDeepSeekChatMessages({
152
344
  messages.push({
153
345
  role: "assistant",
154
346
  content: text,
347
+ ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
348
+ name: deepseekMessageOptions.name
349
+ },
350
+ ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.prefix) === true && {
351
+ prefix: true
352
+ },
155
353
  reasoning_content: reasoning != null ? reasoning : isDeepSeekV4 ? "" : void 0,
156
354
  tool_calls: toolCalls.length > 0 ? toolCalls : void 0
157
355
  });
158
356
  break;
159
357
  }
160
358
  case "tool": {
359
+ if ((deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null) {
360
+ warnings.push({
361
+ type: "unsupported",
362
+ feature: "message name on tool messages"
363
+ });
364
+ }
161
365
  for (const toolResponse of content) {
162
366
  if (toolResponse.type === "tool-approval-response") {
163
367
  continue;
@@ -230,7 +434,7 @@ function convertDeepSeekUsage(usage) {
230
434
  },
231
435
  outputTokens: {
232
436
  total: completionTokens,
233
- text: completionTokens - reasoningTokens,
437
+ text: Math.max(0, completionTokens - reasoningTokens),
234
438
  reasoning: reasoningTokens
235
439
  },
236
440
  raw: usage
@@ -239,75 +443,101 @@ function convertDeepSeekUsage(usage) {
239
443
 
240
444
  // src/chat/deepseek-chat-api-types.ts
241
445
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
242
- var import_v4 = require("zod/v4");
243
- var tokenUsageSchema = import_v4.z.object({
244
- prompt_tokens: import_v4.z.number().nullish(),
245
- completion_tokens: import_v4.z.number().nullish(),
246
- prompt_cache_hit_tokens: import_v4.z.number().nullish(),
247
- prompt_cache_miss_tokens: import_v4.z.number().nullish(),
248
- total_tokens: import_v4.z.number().nullish(),
249
- completion_tokens_details: import_v4.z.object({
250
- reasoning_tokens: import_v4.z.number().nullish()
446
+ var import_v43 = require("zod/v4");
447
+ var tokenUsageSchema = import_v43.z.object({
448
+ prompt_tokens: import_v43.z.number().nullish(),
449
+ completion_tokens: import_v43.z.number().nullish(),
450
+ prompt_cache_hit_tokens: import_v43.z.number().nullish(),
451
+ prompt_cache_miss_tokens: import_v43.z.number().nullish(),
452
+ total_tokens: import_v43.z.number().nullish(),
453
+ completion_tokens_details: import_v43.z.object({
454
+ reasoning_tokens: import_v43.z.number().nullish()
251
455
  }).nullish()
252
456
  }).nullish();
253
- var deepSeekErrorSchema = import_v4.z.object({
254
- error: import_v4.z.object({
255
- message: import_v4.z.string(),
256
- type: import_v4.z.string().nullish(),
257
- param: import_v4.z.any().nullish(),
258
- code: import_v4.z.union([import_v4.z.string(), import_v4.z.number()]).nullish()
457
+ var deepSeekErrorSchema = import_v43.z.object({
458
+ error: import_v43.z.object({
459
+ message: import_v43.z.string(),
460
+ type: import_v43.z.string().nullish(),
461
+ param: import_v43.z.any().nullish(),
462
+ code: import_v43.z.union([import_v43.z.string(), import_v43.z.number()]).nullish()
259
463
  })
260
464
  });
261
- var deepseekChatResponseSchema = import_v4.z.object({
262
- id: import_v4.z.string().nullish(),
263
- created: import_v4.z.number().nullish(),
264
- model: import_v4.z.string().nullish(),
265
- choices: import_v4.z.array(
266
- import_v4.z.object({
267
- message: import_v4.z.object({
268
- role: import_v4.z.literal("assistant").nullish(),
269
- content: import_v4.z.string().nullish(),
270
- reasoning_content: import_v4.z.string().nullish(),
271
- tool_calls: import_v4.z.array(
272
- import_v4.z.object({
273
- id: import_v4.z.string().nullish(),
274
- function: import_v4.z.object({
275
- name: import_v4.z.string(),
276
- arguments: import_v4.z.string()
465
+ var deepseekChatLogprobSchema = import_v43.z.object({
466
+ token: import_v43.z.string(),
467
+ logprob: import_v43.z.number(),
468
+ bytes: import_v43.z.array(import_v43.z.number()).nullable(),
469
+ top_logprobs: import_v43.z.array(
470
+ import_v43.z.object({
471
+ token: import_v43.z.string(),
472
+ logprob: import_v43.z.number(),
473
+ bytes: import_v43.z.array(import_v43.z.number()).nullable()
474
+ })
475
+ )
476
+ });
477
+ var deepseekChatLogprobsSchema = import_v43.z.object({
478
+ content: import_v43.z.array(deepseekChatLogprobSchema).nullish(),
479
+ reasoning_content: import_v43.z.array(deepseekChatLogprobSchema).nullish()
480
+ }).nullish();
481
+ var deepseekChatResponseSchema = import_v43.z.object({
482
+ id: import_v43.z.string().nullish(),
483
+ created: import_v43.z.number().nullish(),
484
+ model: import_v43.z.string().nullish(),
485
+ object: import_v43.z.literal("chat.completion").nullish(),
486
+ system_fingerprint: import_v43.z.string().nullish(),
487
+ choices: import_v43.z.array(
488
+ import_v43.z.object({
489
+ index: import_v43.z.number().nullish(),
490
+ message: import_v43.z.object({
491
+ role: import_v43.z.literal("assistant").nullish(),
492
+ content: import_v43.z.string().nullish(),
493
+ reasoning_content: import_v43.z.string().nullish(),
494
+ tool_calls: import_v43.z.array(
495
+ import_v43.z.object({
496
+ id: import_v43.z.string().nullish(),
497
+ type: import_v43.z.literal("function").nullish(),
498
+ function: import_v43.z.object({
499
+ name: import_v43.z.string(),
500
+ arguments: import_v43.z.string()
277
501
  })
278
502
  })
279
503
  ).nullish()
280
504
  }),
281
- finish_reason: import_v4.z.string().nullish()
505
+ logprobs: deepseekChatLogprobsSchema,
506
+ finish_reason: import_v43.z.string().nullish()
282
507
  })
283
508
  ),
284
509
  usage: tokenUsageSchema
285
510
  });
286
511
  var deepseekChatChunkSchema = (0, import_provider_utils2.lazySchema)(
287
512
  () => (0, import_provider_utils2.zodSchema)(
288
- import_v4.z.union([
289
- import_v4.z.object({
290
- id: import_v4.z.string().nullish(),
291
- created: import_v4.z.number().nullish(),
292
- model: import_v4.z.string().nullish(),
293
- choices: import_v4.z.array(
294
- import_v4.z.object({
295
- delta: import_v4.z.object({
296
- role: import_v4.z.enum(["assistant"]).nullish(),
297
- content: import_v4.z.string().nullish(),
298
- reasoning_content: import_v4.z.string().nullish(),
299
- tool_calls: import_v4.z.array(
300
- import_v4.z.object({
301
- index: import_v4.z.number(),
302
- id: import_v4.z.string().nullish(),
303
- function: import_v4.z.object({
304
- name: import_v4.z.string().nullish(),
305
- arguments: import_v4.z.string().nullish()
513
+ import_v43.z.union([
514
+ import_v43.z.object({
515
+ id: import_v43.z.string().nullish(),
516
+ created: import_v43.z.number().nullish(),
517
+ model: import_v43.z.string().nullish(),
518
+ object: import_v43.z.literal("chat.completion.chunk").nullish(),
519
+ system_fingerprint: import_v43.z.string().nullish(),
520
+ choices: import_v43.z.array(
521
+ import_v43.z.object({
522
+ index: import_v43.z.number().nullish(),
523
+ delta: import_v43.z.object({
524
+ role: import_v43.z.enum(["assistant"]).nullish(),
525
+ content: import_v43.z.string().nullish(),
526
+ reasoning_content: import_v43.z.string().nullish(),
527
+ tool_calls: import_v43.z.array(
528
+ import_v43.z.object({
529
+ index: import_v43.z.number(),
530
+ id: import_v43.z.string().nullish(),
531
+ type: import_v43.z.literal("function").nullish(),
532
+ function: import_v43.z.object({
533
+ name: import_v43.z.string().nullish(),
534
+ arguments: import_v43.z.string().nullish()
306
535
  })
307
536
  })
308
537
  ).nullish()
309
538
  }).nullish(),
310
- finish_reason: import_v4.z.string().nullish()
539
+ logprobs: deepseekChatLogprobsSchema,
540
+ finish_reason: import_v43.z.string().nullish()
311
541
  })
312
542
  ),
313
543
  usage: tokenUsageSchema
@@ -317,44 +547,32 @@ var deepseekChatChunkSchema = (0, import_provider_utils2.lazySchema)(
317
547
  )
318
548
  );
319
549
 
320
- // src/chat/deepseek-chat-options.ts
321
- var import_v42 = require("zod/v4");
322
- var deepseekLanguageModelOptions = import_v42.z.object({
323
- /**
324
- * Type of thinking to use. Defaults to `enabled`.
325
- *
326
- * See https://api-docs.deepseek.com/guides/thinking_mode for the
327
- * `adaptive` option, which lets the model decide when to think.
328
- */
329
- thinking: import_v42.z.object({
330
- type: import_v42.z.enum(["adaptive", "enabled", "disabled"]).optional()
331
- }).optional(),
332
- /**
333
- * Controls the thinking strength for DeepSeek V4 reasoning models.
334
- *
335
- * DeepSeek's API accepts `low`, `medium`, `high`, `xhigh`, and `max`.
336
- * Per their docs, `low` and `medium` are mapped to `high`, and `xhigh`
337
- * is mapped to `max` server-side for compatibility with other providers.
338
- */
339
- reasoningEffort: import_v42.z.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
340
- /**
341
- * Whether to use strict JSON schema validation for structured outputs.
342
- * Only applies when the serving endpoint supports JSON schema response
343
- * formats (e.g. Azure). Defaults to `true`.
344
- */
345
- strictJsonSchema: import_v42.z.boolean().optional()
346
- });
347
-
348
550
  // src/chat/deepseek-prepare-tools.ts
551
+ var import_provider2 = require("@ai-sdk/provider");
349
552
  function prepareTools({
350
553
  tools,
351
- toolChoice
554
+ toolChoice,
555
+ supportsStrictToolCalls
352
556
  }) {
353
557
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
354
558
  const toolWarnings = [];
355
559
  if (tools == null) {
356
560
  return { tools: void 0, toolChoice: void 0, toolWarnings };
357
561
  }
562
+ const functionTools = tools.filter((tool) => tool.type === "function");
563
+ const hasStrictTool = functionTools.some((tool) => tool.strict === true);
564
+ if (hasStrictTool && supportsStrictToolCalls === false) {
565
+ throw new import_provider2.UnsupportedFunctionalityError({
566
+ functionality: "DeepSeek strict tool calls",
567
+ message: "DeepSeek strict tool calls require a beta base URL ending in `/beta`."
568
+ });
569
+ }
570
+ if (hasStrictTool && supportsStrictToolCalls === true && functionTools.some((tool) => tool.strict !== true)) {
571
+ throw new import_provider2.UnsupportedFunctionalityError({
572
+ functionality: "mixed DeepSeek strict and non-strict tool calls",
573
+ message: "DeepSeek strict mode requires every function tool in the request to set `strict: true`."
574
+ });
575
+ }
358
576
  const deepseekTools = [];
359
577
  for (const tool of tools) {
360
578
  if (tool.type === "provider") {
@@ -440,6 +658,20 @@ function mapDeepSeekFinishReason(finishReason) {
440
658
  }
441
659
 
442
660
  // src/chat/deepseek-chat-language-model.ts
661
+ function mapDeepSeekProviderReasoningEffort({
662
+ reasoningEffort,
663
+ warnings
664
+ }) {
665
+ const mapped = reasoningEffort === "medium" ? "high" : reasoningEffort === "xhigh" ? "max" : reasoningEffort;
666
+ if (mapped !== reasoningEffort) {
667
+ warnings.push({
668
+ type: "compatibility",
669
+ feature: "reasoningEffort",
670
+ details: `reasoningEffort "${reasoningEffort}" is not a canonical DeepSeek value. mapped to "${mapped}".`
671
+ });
672
+ }
673
+ return mapped;
674
+ }
443
675
  var DeepSeekChatLanguageModel = class {
444
676
  constructor(modelId, config) {
445
677
  this.specificationVersion = "v3";
@@ -481,17 +713,33 @@ var DeepSeekChatLanguageModel = class {
481
713
  schema: deepseekLanguageModelOptions
482
714
  })) != null ? _a : {};
483
715
  const supportsStructuredOutputs = this.config.supportsStructuredOutputs === true;
484
- const { messages, warnings } = convertToDeepSeekChatMessages({
716
+ const supportsPenaltySampling = this.config.supportsPenaltySampling === true;
717
+ const { messages, warnings } = await convertToDeepSeekChatMessages({
485
718
  prompt,
486
719
  responseFormat,
487
720
  modelId: this.modelId,
721
+ providerOptionsName: this.providerOptionsName,
722
+ supportsAssistantPrefixCompletion: this.config.supportsAssistantPrefixCompletion,
488
723
  supportsStructuredOutputs
489
724
  });
725
+ const allWarnings = [...warnings];
490
726
  if (topK != null) {
491
- warnings.push({ type: "unsupported", feature: "topK" });
727
+ allWarnings.push({ type: "unsupported", feature: "topK" });
492
728
  }
493
729
  if (seed != null) {
494
- warnings.push({ type: "unsupported", feature: "seed" });
730
+ allWarnings.push({ type: "unsupported", feature: "seed" });
731
+ }
732
+ if (!supportsPenaltySampling && frequencyPenalty != null) {
733
+ allWarnings.push({
734
+ type: "other",
735
+ message: "frequencyPenalty is deprecated by DeepSeek and has been omitted. Remove frequencyPenalty from the request."
736
+ });
737
+ }
738
+ if (!supportsPenaltySampling && presencePenalty != null) {
739
+ allWarnings.push({
740
+ type: "other",
741
+ message: "presencePenalty is deprecated by DeepSeek and has been omitted. Remove presencePenalty from the request."
742
+ });
495
743
  }
496
744
  const {
497
745
  tools: deepseekTools,
@@ -499,17 +747,50 @@ var DeepSeekChatLanguageModel = class {
499
747
  toolWarnings
500
748
  } = prepareTools({
501
749
  tools,
502
- toolChoice
750
+ toolChoice,
751
+ supportsStrictToolCalls: this.config.supportsStrictToolCalls
503
752
  });
504
- const thinking = this.config.supportsThinking === false ? void 0 : ((_b = deepseekOptions.thinking) == null ? void 0 : _b.type) != null ? { type: deepseekOptions.thinking.type } : void 0;
753
+ allWarnings.push(...toolWarnings);
754
+ const thinkingType = (_b = deepseekOptions.thinking) == null ? void 0 : _b.type;
755
+ if (thinkingType === "adaptive") {
756
+ allWarnings.push({
757
+ type: "compatibility",
758
+ feature: "thinking.type",
759
+ details: 'thinking.type "adaptive" is not a canonical DeepSeek value. mapped to "enabled".'
760
+ });
761
+ }
762
+ const thinking = this.config.supportsThinking === false ? void 0 : thinkingType != null ? { type: thinkingType === "adaptive" ? "enabled" : thinkingType } : void 0;
763
+ const isThinkingEnabled = this.config.supportsThinking !== false && (thinking == null ? void 0 : thinking.type) !== "disabled" && (thinking != null || this.modelId === "deepseek-reasoner" || this.modelId.includes("deepseek-v4"));
764
+ if (isThinkingEnabled && temperature != null) {
765
+ allWarnings.push({
766
+ type: "unsupported",
767
+ feature: "temperature",
768
+ details: "temperature has no effect when DeepSeek thinking is enabled. Set providerOptions.deepseek.thinking.type to 'disabled' to use temperature."
769
+ });
770
+ }
771
+ if (isThinkingEnabled && topP != null) {
772
+ allWarnings.push({
773
+ type: "unsupported",
774
+ feature: "topP",
775
+ details: "topP has no effect when DeepSeek thinking is enabled. Set providerOptions.deepseek.thinking.type to 'disabled' to use topP."
776
+ });
777
+ }
778
+ const reasoningEffort = deepseekOptions.reasoningEffort != null ? mapDeepSeekProviderReasoningEffort({
779
+ reasoningEffort: deepseekOptions.reasoningEffort,
780
+ warnings: allWarnings
781
+ }) : void 0;
505
782
  return {
506
783
  args: {
507
784
  model: this.modelId,
785
+ ...(deepseekOptions.logprobs === true || deepseekOptions.topLogprobs != null) && { logprobs: true },
786
+ ...deepseekOptions.topLogprobs != null && {
787
+ top_logprobs: deepseekOptions.topLogprobs
788
+ },
508
789
  max_tokens: maxOutputTokens,
509
- temperature,
510
- top_p: topP,
511
- frequency_penalty: frequencyPenalty,
512
- presence_penalty: presencePenalty,
790
+ temperature: isThinkingEnabled ? void 0 : temperature,
791
+ top_p: isThinkingEnabled ? void 0 : topP,
792
+ frequency_penalty: supportsPenaltySampling ? frequencyPenalty : void 0,
793
+ presence_penalty: supportsPenaltySampling ? presencePenalty : void 0,
513
794
  response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? supportsStructuredOutputs && responseFormat.schema != null ? {
514
795
  type: "json_schema",
515
796
  json_schema: {
@@ -524,11 +805,14 @@ var DeepSeekChatLanguageModel = class {
524
805
  tools: deepseekTools,
525
806
  tool_choice: deepseekToolChoices,
526
807
  thinking,
527
- ...(thinking == null ? void 0 : thinking.type) !== "disabled" && deepseekOptions.reasoningEffort != null && {
528
- reasoning_effort: deepseekOptions.reasoningEffort
808
+ ...deepseekOptions.userId != null && {
809
+ user_id: deepseekOptions.userId
810
+ },
811
+ ...(thinking == null ? void 0 : thinking.type) !== "disabled" && reasoningEffort != null && {
812
+ reasoning_effort: reasoningEffort
529
813
  }
530
814
  },
531
- warnings: [...warnings, ...toolWarnings]
815
+ warnings: allWarnings
532
816
  };
533
817
  }
534
818
  async doGenerate(options) {
@@ -585,7 +869,21 @@ var DeepSeekChatLanguageModel = class {
585
869
  providerMetadata: {
586
870
  [this.providerOptionsName]: {
587
871
  promptCacheHitTokens: (_c = responseBody.usage) == null ? void 0 : _c.prompt_cache_hit_tokens,
588
- promptCacheMissTokens: (_d = responseBody.usage) == null ? void 0 : _d.prompt_cache_miss_tokens
872
+ promptCacheMissTokens: (_d = responseBody.usage) == null ? void 0 : _d.prompt_cache_miss_tokens,
873
+ ...responseBody.object != null && {
874
+ responseObject: responseBody.object
875
+ },
876
+ ...choice.index != null && { choiceIndex: choice.index },
877
+ ...choice.message.role != null && {
878
+ messageRole: choice.message.role
879
+ },
880
+ ...choice.message.tool_calls != null && {
881
+ toolCallTypes: choice.message.tool_calls.map((toolCall) => toolCall.type).filter((type) => type != null)
882
+ },
883
+ ...choice.logprobs != null && { logprobs: choice.logprobs },
884
+ ...responseBody.system_fingerprint != null && {
885
+ systemFingerprint: responseBody.system_fingerprint
886
+ }
589
887
  }
590
888
  },
591
889
  request: { body: args },
@@ -624,10 +922,17 @@ var DeepSeekChatLanguageModel = class {
624
922
  raw: void 0
625
923
  };
626
924
  let usage = void 0;
925
+ let systemFingerprint = void 0;
627
926
  let isFirstChunk = true;
628
927
  const providerOptionsName = this.providerOptionsName;
629
928
  let isActiveReasoning = false;
630
929
  let isActiveText = false;
930
+ let responseObject;
931
+ let choiceIndex;
932
+ let messageRole;
933
+ const toolCallTypes = /* @__PURE__ */ new Map();
934
+ const contentLogprobs = [];
935
+ const reasoningLogprobs = [];
631
936
  return {
632
937
  stream: response.pipeThrough(
633
938
  new TransformStream({
@@ -635,7 +940,7 @@ var DeepSeekChatLanguageModel = class {
635
940
  controller.enqueue({ type: "stream-start", warnings });
636
941
  },
637
942
  transform(chunk, controller) {
638
- var _a, _b, _c, _d, _e, _f, _g, _h;
943
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
639
944
  if (options.includeRawChunks) {
640
945
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
641
946
  }
@@ -660,17 +965,35 @@ var DeepSeekChatLanguageModel = class {
660
965
  if (value.usage != null) {
661
966
  usage = value.usage;
662
967
  }
968
+ if (value.object != null) {
969
+ responseObject = value.object;
970
+ }
971
+ if (value.system_fingerprint != null) {
972
+ systemFingerprint = value.system_fingerprint;
973
+ }
663
974
  const choice = value.choices[0];
975
+ if ((choice == null ? void 0 : choice.index) != null) {
976
+ choiceIndex = choice.index;
977
+ }
664
978
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
665
979
  finishReason = {
666
980
  unified: mapDeepSeekFinishReason(choice.finish_reason),
667
981
  raw: choice.finish_reason
668
982
  };
669
983
  }
984
+ if (((_a = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _a.content) != null) {
985
+ contentLogprobs.push(...choice.logprobs.content);
986
+ }
987
+ if (((_b = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _b.reasoning_content) != null) {
988
+ reasoningLogprobs.push(...choice.logprobs.reasoning_content);
989
+ }
670
990
  if ((choice == null ? void 0 : choice.delta) == null) {
671
991
  return;
672
992
  }
673
993
  const delta = choice.delta;
994
+ if (delta.role != null) {
995
+ messageRole = delta.role;
996
+ }
674
997
  const reasoningContent = delta.reasoning_content;
675
998
  if (reasoningContent) {
676
999
  if (!isActiveReasoning) {
@@ -713,16 +1036,19 @@ var DeepSeekChatLanguageModel = class {
713
1036
  isActiveReasoning = false;
714
1037
  }
715
1038
  for (const toolCallDelta of delta.tool_calls) {
1039
+ if (toolCallDelta.type != null) {
1040
+ toolCallTypes.set(toolCallDelta.index, toolCallDelta.type);
1041
+ }
716
1042
  const index = toolCallDelta.index;
717
1043
  if (toolCalls[index] == null) {
718
1044
  if (toolCallDelta.id == null) {
719
- throw new import_provider.InvalidResponseDataError({
1045
+ throw new import_provider3.InvalidResponseDataError({
720
1046
  data: toolCallDelta,
721
1047
  message: `Expected 'id' to be a string.`
722
1048
  });
723
1049
  }
724
- if (((_a = toolCallDelta.function) == null ? void 0 : _a.name) == null) {
725
- throw new import_provider.InvalidResponseDataError({
1050
+ if (((_c = toolCallDelta.function) == null ? void 0 : _c.name) == null) {
1051
+ throw new import_provider3.InvalidResponseDataError({
726
1052
  data: toolCallDelta,
727
1053
  message: `Expected 'function.name' to be a string.`
728
1054
  });
@@ -737,12 +1063,12 @@ var DeepSeekChatLanguageModel = class {
737
1063
  type: "function",
738
1064
  function: {
739
1065
  name: toolCallDelta.function.name,
740
- arguments: (_b = toolCallDelta.function.arguments) != null ? _b : ""
1066
+ arguments: (_d = toolCallDelta.function.arguments) != null ? _d : ""
741
1067
  },
742
1068
  hasFinished: false
743
1069
  };
744
1070
  const toolCall2 = toolCalls[index];
745
- if (((_c = toolCall2.function) == null ? void 0 : _c.name) != null && ((_d = toolCall2.function) == null ? void 0 : _d.arguments) != null) {
1071
+ if (((_e = toolCall2.function) == null ? void 0 : _e.name) != null && ((_f = toolCall2.function) == null ? void 0 : _f.arguments) != null) {
746
1072
  if (toolCall2.function.arguments.length > 0) {
747
1073
  controller.enqueue({
748
1074
  type: "tool-input-delta",
@@ -757,13 +1083,13 @@ var DeepSeekChatLanguageModel = class {
757
1083
  if (toolCall.hasFinished) {
758
1084
  continue;
759
1085
  }
760
- if (((_e = toolCallDelta.function) == null ? void 0 : _e.arguments) != null) {
761
- toolCall.function.arguments += (_g = (_f = toolCallDelta.function) == null ? void 0 : _f.arguments) != null ? _g : "";
1086
+ if (((_g = toolCallDelta.function) == null ? void 0 : _g.arguments) != null) {
1087
+ toolCall.function.arguments += (_i = (_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null ? _i : "";
762
1088
  }
763
1089
  controller.enqueue({
764
1090
  type: "tool-input-delta",
765
1091
  id: toolCall.id,
766
- delta: (_h = toolCallDelta.function.arguments) != null ? _h : ""
1092
+ delta: (_j = toolCallDelta.function.arguments) != null ? _j : ""
767
1093
  });
768
1094
  }
769
1095
  }
@@ -797,7 +1123,24 @@ var DeepSeekChatLanguageModel = class {
797
1123
  providerMetadata: {
798
1124
  [providerOptionsName]: {
799
1125
  promptCacheHitTokens: (_b = usage == null ? void 0 : usage.prompt_cache_hit_tokens) != null ? _b : void 0,
800
- promptCacheMissTokens: (_c = usage == null ? void 0 : usage.prompt_cache_miss_tokens) != null ? _c : void 0
1126
+ promptCacheMissTokens: (_c = usage == null ? void 0 : usage.prompt_cache_miss_tokens) != null ? _c : void 0,
1127
+ ...responseObject != null && { responseObject },
1128
+ ...choiceIndex != null && { choiceIndex },
1129
+ ...messageRole != null && { messageRole },
1130
+ ...toolCallTypes.size > 0 && {
1131
+ toolCallTypes: [...toolCallTypes.entries()].sort(([left], [right]) => left - right).map(([, type]) => type)
1132
+ },
1133
+ ...(contentLogprobs.length > 0 || reasoningLogprobs.length > 0) && {
1134
+ logprobs: {
1135
+ ...contentLogprobs.length > 0 && {
1136
+ content: contentLogprobs
1137
+ },
1138
+ ...reasoningLogprobs.length > 0 && {
1139
+ reasoning_content: reasoningLogprobs
1140
+ }
1141
+ }
1142
+ },
1143
+ ...systemFingerprint != null && { systemFingerprint }
801
1144
  }
802
1145
  }
803
1146
  });
@@ -812,6 +1155,8 @@ var DeepSeekChatLanguageModel = class {
812
1155
  // Annotate the CommonJS export names for ESM import in node:
813
1156
  0 && (module.exports = {
814
1157
  DeepSeekChatLanguageModel,
815
- deepseekLanguageModelOptions
1158
+ deepseekAssistantMessageProviderOptions,
1159
+ deepseekLanguageModelOptions,
1160
+ deepseekMessageProviderOptions
816
1161
  });
817
1162
  //# sourceMappingURL=index.js.map