@ai-sdk/deepseek 2.0.58 → 2.0.59

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