@ai-sdk/deepseek 1.0.52 → 1.0.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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_provider3 = 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_provider2 = 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 deepseekChatOptions = 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
  const isDeepSeekV4 = modelId.includes("deepseek-v4");
@@ -66,11 +159,28 @@ function convertToDeepSeekChatMessages({
66
159
  }
67
160
  }
68
161
  let index = -1;
69
- for (const { role, content } of prompt) {
162
+ for (const { role, content, providerOptions } of prompt) {
70
163
  index++;
164
+ const deepseekMessageOptions = await (0, import_provider_utils.parseProviderOptions)({
165
+ provider: providerOptionsName,
166
+ providerOptions,
167
+ schema: deepseekAssistantMessageProviderOptions
168
+ });
169
+ if ((deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.prefix) === true && role !== "assistant") {
170
+ throw new import_provider.InvalidPromptError({
171
+ prompt,
172
+ message: "DeepSeek assistant prefix completion requires `prefix: true` on an assistant message."
173
+ });
174
+ }
71
175
  switch (role) {
72
176
  case "system": {
73
- messages.push({ role: "system", content });
177
+ messages.push({
178
+ role: "system",
179
+ content,
180
+ ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
181
+ name: deepseekMessageOptions.name
182
+ }
183
+ });
74
184
  break;
75
185
  }
76
186
  case "user": {
@@ -89,7 +199,13 @@ function convertToDeepSeekChatMessages({
89
199
  });
90
200
  }
91
201
  }
92
- messages.push({ role: "user", content: userContent2 });
202
+ messages.push({
203
+ role: "user",
204
+ content: userContent2,
205
+ ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
206
+ name: deepseekMessageOptions.name
207
+ }
208
+ });
93
209
  break;
94
210
  }
95
211
  const userContent = [];
@@ -97,13 +213,67 @@ function convertToDeepSeekChatMessages({
97
213
  if (part.type === "text") {
98
214
  userContent.push({ type: "text", text: part.text });
99
215
  } else if (part.type === "file" && (part.mediaType === "image" || part.mediaType.startsWith("image/"))) {
100
- const mediaType = part.mediaType === "image" || part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
101
- userContent.push({
102
- type: "image_url",
103
- image_url: {
104
- url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${(0, import_provider_utils.convertToBase64)(part.data)}`
105
- }
216
+ const filePartOptions = await (0, import_provider_utils.parseProviderOptions)({
217
+ provider: providerOptionsName,
218
+ providerOptions: part.providerOptions,
219
+ schema: deepseekFilePartProviderOptions
106
220
  });
221
+ const resolvedMediaType = part.mediaType === "image" || part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
222
+ if (!supportedImageMediaTypes.has(resolvedMediaType)) {
223
+ throw new import_provider.UnsupportedFunctionalityError({
224
+ functionality: `DeepSeek image media type ${resolvedMediaType}`,
225
+ message: "DeepSeek supports JPEG, PNG, GIF, and WebP image inputs."
226
+ });
227
+ }
228
+ if (part.data instanceof URL) {
229
+ const url = part.data.toString();
230
+ if (url.length > 8192) {
231
+ throw new import_provider.InvalidPromptError({
232
+ prompt,
233
+ message: "DeepSeek image URLs must not exceed 8192 characters."
234
+ });
235
+ }
236
+ if ((filePartOptions == null ? void 0 : filePartOptions.fileData) === true) {
237
+ throw new import_provider.InvalidPromptError({
238
+ prompt,
239
+ message: "DeepSeek `fileData` image parts require inline data, not a URL."
240
+ });
241
+ }
242
+ userContent.push({
243
+ type: "image_url",
244
+ image_url: {
245
+ url,
246
+ ...(filePartOptions == null ? void 0 : filePartOptions.imageDetail) != null && {
247
+ detail: filePartOptions.imageDetail
248
+ }
249
+ }
250
+ });
251
+ } else {
252
+ const dataUrl = `data:${resolvedMediaType === "image/jpg" ? "image/jpeg" : resolvedMediaType};base64,${(0, import_provider_utils.convertToBase64)(part.data)}`;
253
+ if ((filePartOptions == null ? void 0 : filePartOptions.fileData) === true) {
254
+ if (filePartOptions.imageDetail != null) {
255
+ throw new import_provider.InvalidPromptError({
256
+ prompt,
257
+ message: "DeepSeek `imageDetail` cannot be combined with `fileData`."
258
+ });
259
+ }
260
+ userContent.push({
261
+ type: "file",
262
+ file_data: dataUrl,
263
+ ...part.filename != null && { filename: part.filename }
264
+ });
265
+ } else {
266
+ userContent.push({
267
+ type: "image_url",
268
+ image_url: {
269
+ url: dataUrl,
270
+ ...(filePartOptions == null ? void 0 : filePartOptions.imageDetail) != null && {
271
+ detail: filePartOptions.imageDetail
272
+ }
273
+ }
274
+ });
275
+ }
276
+ }
107
277
  } else {
108
278
  warnings.push({
109
279
  type: "other",
@@ -111,10 +281,30 @@ function convertToDeepSeekChatMessages({
111
281
  });
112
282
  }
113
283
  }
114
- messages.push({ role: "user", content: userContent });
284
+ messages.push({
285
+ role: "user",
286
+ content: userContent,
287
+ ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
288
+ name: deepseekMessageOptions.name
289
+ }
290
+ });
115
291
  break;
116
292
  }
117
293
  case "assistant": {
294
+ if ((deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.prefix) === true) {
295
+ if (index !== prompt.length - 1) {
296
+ throw new import_provider.InvalidPromptError({
297
+ prompt,
298
+ message: "DeepSeek assistant prefix completion requires the prefixed assistant message to be the final message."
299
+ });
300
+ }
301
+ if (!supportsAssistantPrefixCompletion) {
302
+ throw new import_provider.UnsupportedFunctionalityError({
303
+ functionality: "DeepSeek assistant prefix completion",
304
+ message: "DeepSeek assistant prefix completion requires a beta base URL ending in `/beta`."
305
+ });
306
+ }
307
+ }
118
308
  let text = "";
119
309
  let reasoning;
120
310
  const toolCalls = [];
@@ -151,12 +341,24 @@ function convertToDeepSeekChatMessages({
151
341
  messages.push({
152
342
  role: "assistant",
153
343
  content: text,
344
+ ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
345
+ name: deepseekMessageOptions.name
346
+ },
347
+ ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.prefix) === true && {
348
+ prefix: true
349
+ },
154
350
  reasoning_content: reasoning != null ? reasoning : isDeepSeekV4 ? "" : void 0,
155
351
  tool_calls: toolCalls.length > 0 ? toolCalls : void 0
156
352
  });
157
353
  break;
158
354
  }
159
355
  case "tool": {
356
+ if ((deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null) {
357
+ warnings.push({
358
+ type: "other",
359
+ message: "DeepSeek does not support message names on tool messages. The name has been omitted."
360
+ });
361
+ }
160
362
  for (const toolResponse of content) {
161
363
  const output = toolResponse.output;
162
364
  let contentValue;
@@ -193,75 +395,101 @@ function convertToDeepSeekChatMessages({
193
395
 
194
396
  // src/chat/deepseek-chat-api-types.ts
195
397
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
196
- var import_v4 = require("zod/v4");
197
- var tokenUsageSchema = import_v4.z.object({
198
- prompt_tokens: import_v4.z.number().nullish(),
199
- completion_tokens: import_v4.z.number().nullish(),
200
- prompt_cache_hit_tokens: import_v4.z.number().nullish(),
201
- prompt_cache_miss_tokens: import_v4.z.number().nullish(),
202
- total_tokens: import_v4.z.number().nullish(),
203
- completion_tokens_details: import_v4.z.object({
204
- reasoning_tokens: import_v4.z.number().nullish()
398
+ var import_v43 = require("zod/v4");
399
+ var tokenUsageSchema = import_v43.z.object({
400
+ prompt_tokens: import_v43.z.number().nullish(),
401
+ completion_tokens: import_v43.z.number().nullish(),
402
+ prompt_cache_hit_tokens: import_v43.z.number().nullish(),
403
+ prompt_cache_miss_tokens: import_v43.z.number().nullish(),
404
+ total_tokens: import_v43.z.number().nullish(),
405
+ completion_tokens_details: import_v43.z.object({
406
+ reasoning_tokens: import_v43.z.number().nullish()
205
407
  }).nullish()
206
408
  }).nullish();
207
- var deepSeekErrorSchema = import_v4.z.object({
208
- error: import_v4.z.object({
209
- message: import_v4.z.string(),
210
- type: import_v4.z.string().nullish(),
211
- param: import_v4.z.any().nullish(),
212
- code: import_v4.z.union([import_v4.z.string(), import_v4.z.number()]).nullish()
409
+ var deepSeekErrorSchema = import_v43.z.object({
410
+ error: import_v43.z.object({
411
+ message: import_v43.z.string(),
412
+ type: import_v43.z.string().nullish(),
413
+ param: import_v43.z.any().nullish(),
414
+ code: import_v43.z.union([import_v43.z.string(), import_v43.z.number()]).nullish()
213
415
  })
214
416
  });
215
- var deepseekChatResponseSchema = import_v4.z.object({
216
- id: import_v4.z.string().nullish(),
217
- created: import_v4.z.number().nullish(),
218
- model: import_v4.z.string().nullish(),
219
- choices: import_v4.z.array(
220
- import_v4.z.object({
221
- message: import_v4.z.object({
222
- role: import_v4.z.literal("assistant").nullish(),
223
- content: import_v4.z.string().nullish(),
224
- reasoning_content: import_v4.z.string().nullish(),
225
- tool_calls: import_v4.z.array(
226
- import_v4.z.object({
227
- id: import_v4.z.string().nullish(),
228
- function: import_v4.z.object({
229
- name: import_v4.z.string(),
230
- arguments: import_v4.z.string()
417
+ var deepseekChatLogprobSchema = import_v43.z.object({
418
+ token: import_v43.z.string(),
419
+ logprob: import_v43.z.number(),
420
+ bytes: import_v43.z.array(import_v43.z.number()).nullable(),
421
+ top_logprobs: import_v43.z.array(
422
+ import_v43.z.object({
423
+ token: import_v43.z.string(),
424
+ logprob: import_v43.z.number(),
425
+ bytes: import_v43.z.array(import_v43.z.number()).nullable()
426
+ })
427
+ )
428
+ });
429
+ var deepseekChatLogprobsSchema = import_v43.z.object({
430
+ content: import_v43.z.array(deepseekChatLogprobSchema).nullish(),
431
+ reasoning_content: import_v43.z.array(deepseekChatLogprobSchema).nullish()
432
+ }).nullish();
433
+ var deepseekChatResponseSchema = import_v43.z.object({
434
+ id: import_v43.z.string().nullish(),
435
+ created: import_v43.z.number().nullish(),
436
+ model: import_v43.z.string().nullish(),
437
+ object: import_v43.z.literal("chat.completion").nullish(),
438
+ system_fingerprint: import_v43.z.string().nullish(),
439
+ choices: import_v43.z.array(
440
+ import_v43.z.object({
441
+ index: import_v43.z.number().nullish(),
442
+ message: import_v43.z.object({
443
+ role: import_v43.z.literal("assistant").nullish(),
444
+ content: import_v43.z.string().nullish(),
445
+ reasoning_content: import_v43.z.string().nullish(),
446
+ tool_calls: import_v43.z.array(
447
+ import_v43.z.object({
448
+ id: import_v43.z.string().nullish(),
449
+ type: import_v43.z.literal("function").nullish(),
450
+ function: import_v43.z.object({
451
+ name: import_v43.z.string(),
452
+ arguments: import_v43.z.string()
231
453
  })
232
454
  })
233
455
  ).nullish()
234
456
  }),
235
- finish_reason: import_v4.z.string().nullish()
457
+ logprobs: deepseekChatLogprobsSchema,
458
+ finish_reason: import_v43.z.string().nullish()
236
459
  })
237
460
  ),
238
461
  usage: tokenUsageSchema
239
462
  });
240
463
  var deepseekChatChunkSchema = (0, import_provider_utils2.lazySchema)(
241
464
  () => (0, import_provider_utils2.zodSchema)(
242
- import_v4.z.union([
243
- import_v4.z.object({
244
- id: import_v4.z.string().nullish(),
245
- created: import_v4.z.number().nullish(),
246
- model: import_v4.z.string().nullish(),
247
- choices: import_v4.z.array(
248
- import_v4.z.object({
249
- delta: import_v4.z.object({
250
- role: import_v4.z.enum(["assistant"]).nullish(),
251
- content: import_v4.z.string().nullish(),
252
- reasoning_content: import_v4.z.string().nullish(),
253
- tool_calls: import_v4.z.array(
254
- import_v4.z.object({
255
- index: import_v4.z.number(),
256
- id: import_v4.z.string().nullish(),
257
- function: import_v4.z.object({
258
- name: import_v4.z.string().nullish(),
259
- arguments: import_v4.z.string().nullish()
465
+ import_v43.z.union([
466
+ import_v43.z.object({
467
+ id: import_v43.z.string().nullish(),
468
+ created: import_v43.z.number().nullish(),
469
+ model: import_v43.z.string().nullish(),
470
+ object: import_v43.z.literal("chat.completion.chunk").nullish(),
471
+ system_fingerprint: import_v43.z.string().nullish(),
472
+ choices: import_v43.z.array(
473
+ import_v43.z.object({
474
+ index: import_v43.z.number().nullish(),
475
+ delta: import_v43.z.object({
476
+ role: import_v43.z.enum(["assistant"]).nullish(),
477
+ content: import_v43.z.string().nullish(),
478
+ reasoning_content: import_v43.z.string().nullish(),
479
+ tool_calls: import_v43.z.array(
480
+ import_v43.z.object({
481
+ index: import_v43.z.number(),
482
+ id: import_v43.z.string().nullish(),
483
+ type: import_v43.z.literal("function").nullish(),
484
+ function: import_v43.z.object({
485
+ name: import_v43.z.string().nullish(),
486
+ arguments: import_v43.z.string().nullish()
260
487
  })
261
488
  })
262
489
  ).nullish()
263
490
  }).nullish(),
264
- finish_reason: import_v4.z.string().nullish()
491
+ logprobs: deepseekChatLogprobsSchema,
492
+ finish_reason: import_v43.z.string().nullish()
265
493
  })
266
494
  ),
267
495
  usage: tokenUsageSchema
@@ -271,36 +499,8 @@ var deepseekChatChunkSchema = (0, import_provider_utils2.lazySchema)(
271
499
  )
272
500
  );
273
501
 
274
- // src/chat/deepseek-chat-options.ts
275
- var import_v42 = require("zod/v4");
276
- var deepseekChatOptions = import_v42.z.object({
277
- /**
278
- * Type of thinking to use. Defaults to `enabled`.
279
- *
280
- * See https://api-docs.deepseek.com/guides/thinking_mode for the
281
- * `adaptive` option, which lets the model decide when to think.
282
- */
283
- thinking: import_v42.z.object({
284
- type: import_v42.z.enum(["adaptive", "enabled", "disabled"]).optional()
285
- }).optional(),
286
- /**
287
- * Controls the thinking strength for DeepSeek V4 reasoning models.
288
- *
289
- * DeepSeek's API accepts `low`, `medium`, `high`, `xhigh`, and `max`.
290
- * Per their docs, `low` and `medium` are mapped to `high`, and `xhigh`
291
- * is mapped to `max` server-side for compatibility with other providers.
292
- */
293
- reasoningEffort: import_v42.z.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
294
- /**
295
- * Whether to use strict JSON schema validation for structured outputs.
296
- * Only applies when the serving endpoint supports JSON schema response
297
- * formats (e.g. Azure). Defaults to `true`.
298
- */
299
- strictJsonSchema: import_v42.z.boolean().optional()
300
- });
301
-
302
502
  // src/chat/deepseek-prepare-tools.ts
303
- var import_provider = require("@ai-sdk/provider");
503
+ var import_provider2 = require("@ai-sdk/provider");
304
504
  function prepareTools({
305
505
  tools,
306
506
  toolChoice
@@ -348,7 +548,7 @@ function prepareTools({
348
548
  };
349
549
  default: {
350
550
  const _exhaustiveCheck = type;
351
- throw new import_provider.UnsupportedFunctionalityError({
551
+ throw new import_provider2.UnsupportedFunctionalityError({
352
552
  functionality: `tool choice type: ${_exhaustiveCheck}`
353
553
  });
354
554
  }
@@ -387,6 +587,19 @@ function mapDeepSeekFinishReason(finishReason) {
387
587
  }
388
588
 
389
589
  // src/chat/deepseek-chat-language-model.ts
590
+ function mapDeepSeekProviderReasoningEffort({
591
+ reasoningEffort,
592
+ warnings
593
+ }) {
594
+ const mapped = reasoningEffort === "medium" ? "high" : reasoningEffort === "xhigh" ? "max" : reasoningEffort;
595
+ if (mapped !== reasoningEffort) {
596
+ warnings.push({
597
+ type: "other",
598
+ message: `reasoningEffort "${reasoningEffort}" is not a canonical DeepSeek value. mapped to "${mapped}".`
599
+ });
600
+ }
601
+ return mapped;
602
+ }
390
603
  var DeepSeekChatLanguageModel = class {
391
604
  constructor(modelId, config) {
392
605
  this.specificationVersion = "v2";
@@ -428,17 +641,33 @@ var DeepSeekChatLanguageModel = class {
428
641
  schema: deepseekChatOptions
429
642
  })) != null ? _a : {};
430
643
  const supportsStructuredOutputs = this.config.supportsStructuredOutputs === true;
431
- const { messages, warnings } = convertToDeepSeekChatMessages({
644
+ const supportsPenaltySampling = this.config.supportsPenaltySampling === true;
645
+ const { messages, warnings } = await convertToDeepSeekChatMessages({
432
646
  prompt,
433
647
  responseFormat,
434
648
  modelId: this.modelId,
649
+ providerOptionsName: this.providerOptionsName,
650
+ supportsAssistantPrefixCompletion: this.config.supportsAssistantPrefixCompletion,
435
651
  supportsStructuredOutputs
436
652
  });
653
+ const allWarnings = [...warnings];
437
654
  if (topK != null) {
438
- warnings.push({ type: "unsupported-setting", setting: "topK" });
655
+ allWarnings.push({ type: "unsupported-setting", setting: "topK" });
439
656
  }
440
657
  if (seed != null) {
441
- warnings.push({ type: "unsupported-setting", setting: "seed" });
658
+ allWarnings.push({ type: "unsupported-setting", setting: "seed" });
659
+ }
660
+ if (!supportsPenaltySampling && frequencyPenalty != null) {
661
+ allWarnings.push({
662
+ type: "other",
663
+ message: "frequencyPenalty is deprecated by DeepSeek and has been omitted. Remove frequencyPenalty from the request."
664
+ });
665
+ }
666
+ if (!supportsPenaltySampling && presencePenalty != null) {
667
+ allWarnings.push({
668
+ type: "other",
669
+ message: "presencePenalty is deprecated by DeepSeek and has been omitted. Remove presencePenalty from the request."
670
+ });
442
671
  }
443
672
  const {
444
673
  tools: deepseekTools,
@@ -448,15 +677,46 @@ var DeepSeekChatLanguageModel = class {
448
677
  tools,
449
678
  toolChoice
450
679
  });
451
- const thinking = this.config.supportsThinking === false ? void 0 : ((_b = deepseekOptions.thinking) == null ? void 0 : _b.type) != null ? { type: deepseekOptions.thinking.type } : void 0;
680
+ allWarnings.push(...toolWarnings);
681
+ const thinkingType = (_b = deepseekOptions.thinking) == null ? void 0 : _b.type;
682
+ if (thinkingType === "adaptive") {
683
+ allWarnings.push({
684
+ type: "other",
685
+ message: 'thinking.type "adaptive" is not a canonical DeepSeek value. mapped to "enabled".'
686
+ });
687
+ }
688
+ const thinking = this.config.supportsThinking === false ? void 0 : thinkingType != null ? { type: thinkingType === "adaptive" ? "enabled" : thinkingType } : void 0;
689
+ const isThinkingEnabled = this.config.supportsThinking !== false && (thinking == null ? void 0 : thinking.type) !== "disabled" && (thinking != null || this.modelId === "deepseek-reasoner" || this.modelId.includes("deepseek-v4"));
690
+ if (isThinkingEnabled && temperature != null) {
691
+ allWarnings.push({
692
+ type: "unsupported-setting",
693
+ setting: "temperature",
694
+ details: "temperature has no effect when DeepSeek thinking is enabled. Set providerOptions.deepseek.thinking.type to 'disabled' to use temperature."
695
+ });
696
+ }
697
+ if (isThinkingEnabled && topP != null) {
698
+ allWarnings.push({
699
+ type: "unsupported-setting",
700
+ setting: "topP",
701
+ details: "topP has no effect when DeepSeek thinking is enabled. Set providerOptions.deepseek.thinking.type to 'disabled' to use topP."
702
+ });
703
+ }
704
+ const reasoningEffort = deepseekOptions.reasoningEffort != null ? mapDeepSeekProviderReasoningEffort({
705
+ reasoningEffort: deepseekOptions.reasoningEffort,
706
+ warnings: allWarnings
707
+ }) : void 0;
452
708
  return {
453
709
  args: {
454
710
  model: this.modelId,
711
+ ...(deepseekOptions.logprobs === true || deepseekOptions.topLogprobs != null) && { logprobs: true },
712
+ ...deepseekOptions.topLogprobs != null && {
713
+ top_logprobs: deepseekOptions.topLogprobs
714
+ },
455
715
  max_tokens: maxOutputTokens,
456
- temperature,
457
- top_p: topP,
458
- frequency_penalty: frequencyPenalty,
459
- presence_penalty: presencePenalty,
716
+ temperature: isThinkingEnabled ? void 0 : temperature,
717
+ top_p: isThinkingEnabled ? void 0 : topP,
718
+ frequency_penalty: supportsPenaltySampling ? frequencyPenalty : void 0,
719
+ presence_penalty: supportsPenaltySampling ? presencePenalty : void 0,
460
720
  response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? supportsStructuredOutputs && responseFormat.schema != null ? {
461
721
  type: "json_schema",
462
722
  json_schema: {
@@ -471,11 +731,14 @@ var DeepSeekChatLanguageModel = class {
471
731
  tools: deepseekTools,
472
732
  tool_choice: deepseekToolChoices,
473
733
  thinking,
474
- ...(thinking == null ? void 0 : thinking.type) !== "disabled" && deepseekOptions.reasoningEffort != null && {
475
- reasoning_effort: deepseekOptions.reasoningEffort
734
+ ...deepseekOptions.userId != null && {
735
+ user_id: deepseekOptions.userId
736
+ },
737
+ ...(thinking == null ? void 0 : thinking.type) !== "disabled" && reasoningEffort != null && {
738
+ reasoning_effort: reasoningEffort
476
739
  }
477
740
  },
478
- warnings: [...warnings, ...toolWarnings]
741
+ warnings: allWarnings
479
742
  };
480
743
  }
481
744
  async doGenerate(options) {
@@ -535,7 +798,21 @@ var DeepSeekChatLanguageModel = class {
535
798
  providerMetadata: {
536
799
  [this.providerOptionsName]: {
537
800
  promptCacheHitTokens: (_n = (_m = responseBody.usage) == null ? void 0 : _m.prompt_cache_hit_tokens) != null ? _n : null,
538
- promptCacheMissTokens: (_p = (_o = responseBody.usage) == null ? void 0 : _o.prompt_cache_miss_tokens) != null ? _p : null
801
+ promptCacheMissTokens: (_p = (_o = responseBody.usage) == null ? void 0 : _o.prompt_cache_miss_tokens) != null ? _p : null,
802
+ ...responseBody.object != null && {
803
+ responseObject: responseBody.object
804
+ },
805
+ ...choice.index != null && { choiceIndex: choice.index },
806
+ ...choice.message.role != null && {
807
+ messageRole: choice.message.role
808
+ },
809
+ ...choice.message.tool_calls != null && {
810
+ toolCallTypes: choice.message.tool_calls.map((toolCall) => toolCall.type).filter((type) => type != null)
811
+ },
812
+ ...choice.logprobs != null && { logprobs: choice.logprobs },
813
+ ...responseBody.system_fingerprint != null && {
814
+ systemFingerprint: responseBody.system_fingerprint
815
+ }
539
816
  }
540
817
  },
541
818
  request: { body: args },
@@ -571,10 +848,17 @@ var DeepSeekChatLanguageModel = class {
571
848
  const toolCalls = [];
572
849
  let finishReason = "unknown";
573
850
  let usage = void 0;
851
+ let systemFingerprint = void 0;
574
852
  let isFirstChunk = true;
575
853
  const providerOptionsName = this.providerOptionsName;
576
854
  let isActiveReasoning = false;
577
855
  let isActiveText = false;
856
+ let responseObject;
857
+ let choiceIndex;
858
+ let messageRole;
859
+ const toolCallTypes = /* @__PURE__ */ new Map();
860
+ const contentLogprobs = [];
861
+ const reasoningLogprobs = [];
578
862
  return {
579
863
  stream: response.pipeThrough(
580
864
  new TransformStream({
@@ -582,7 +866,7 @@ var DeepSeekChatLanguageModel = class {
582
866
  controller.enqueue({ type: "stream-start", warnings });
583
867
  },
584
868
  transform(chunk, controller) {
585
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
869
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
586
870
  if (options.includeRawChunks) {
587
871
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
588
872
  }
@@ -607,14 +891,32 @@ var DeepSeekChatLanguageModel = class {
607
891
  if (value.usage != null) {
608
892
  usage = value.usage;
609
893
  }
894
+ if (value.object != null) {
895
+ responseObject = value.object;
896
+ }
897
+ if (value.system_fingerprint != null) {
898
+ systemFingerprint = value.system_fingerprint;
899
+ }
610
900
  const choice = value.choices[0];
901
+ if ((choice == null ? void 0 : choice.index) != null) {
902
+ choiceIndex = choice.index;
903
+ }
611
904
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
612
905
  finishReason = mapDeepSeekFinishReason(choice.finish_reason);
613
906
  }
907
+ if (((_a = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _a.content) != null) {
908
+ contentLogprobs.push(...choice.logprobs.content);
909
+ }
910
+ if (((_b = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _b.reasoning_content) != null) {
911
+ reasoningLogprobs.push(...choice.logprobs.reasoning_content);
912
+ }
614
913
  if ((choice == null ? void 0 : choice.delta) == null) {
615
914
  return;
616
915
  }
617
916
  const delta = choice.delta;
917
+ if (delta.role != null) {
918
+ messageRole = delta.role;
919
+ }
618
920
  const reasoningContent = delta.reasoning_content;
619
921
  if (reasoningContent) {
620
922
  if (!isActiveReasoning) {
@@ -657,16 +959,19 @@ var DeepSeekChatLanguageModel = class {
657
959
  isActiveReasoning = false;
658
960
  }
659
961
  for (const toolCallDelta of delta.tool_calls) {
962
+ if (toolCallDelta.type != null) {
963
+ toolCallTypes.set(toolCallDelta.index, toolCallDelta.type);
964
+ }
660
965
  const index = toolCallDelta.index;
661
966
  if (toolCalls[index] == null) {
662
967
  if (toolCallDelta.id == null) {
663
- throw new import_provider2.InvalidResponseDataError({
968
+ throw new import_provider3.InvalidResponseDataError({
664
969
  data: toolCallDelta,
665
970
  message: `Expected 'id' to be a string.`
666
971
  });
667
972
  }
668
- if (((_a = toolCallDelta.function) == null ? void 0 : _a.name) == null) {
669
- throw new import_provider2.InvalidResponseDataError({
973
+ if (((_c = toolCallDelta.function) == null ? void 0 : _c.name) == null) {
974
+ throw new import_provider3.InvalidResponseDataError({
670
975
  data: toolCallDelta,
671
976
  message: `Expected 'function.name' to be a string.`
672
977
  });
@@ -681,12 +986,12 @@ var DeepSeekChatLanguageModel = class {
681
986
  type: "function",
682
987
  function: {
683
988
  name: toolCallDelta.function.name,
684
- arguments: (_b = toolCallDelta.function.arguments) != null ? _b : ""
989
+ arguments: (_d = toolCallDelta.function.arguments) != null ? _d : ""
685
990
  },
686
991
  hasFinished: false
687
992
  };
688
993
  const toolCall2 = toolCalls[index];
689
- if (((_c = toolCall2.function) == null ? void 0 : _c.name) != null && ((_d = toolCall2.function) == null ? void 0 : _d.arguments) != null) {
994
+ if (((_e = toolCall2.function) == null ? void 0 : _e.name) != null && ((_f = toolCall2.function) == null ? void 0 : _f.arguments) != null) {
690
995
  if (toolCall2.function.arguments.length > 0) {
691
996
  controller.enqueue({
692
997
  type: "tool-input-delta",
@@ -701,7 +1006,7 @@ var DeepSeekChatLanguageModel = class {
701
1006
  });
702
1007
  controller.enqueue({
703
1008
  type: "tool-call",
704
- toolCallId: (_e = toolCall2.id) != null ? _e : (0, import_provider_utils3.generateId)(),
1009
+ toolCallId: (_g = toolCall2.id) != null ? _g : (0, import_provider_utils3.generateId)(),
705
1010
  toolName: toolCall2.function.name,
706
1011
  input: toolCall2.function.arguments
707
1012
  });
@@ -714,22 +1019,22 @@ var DeepSeekChatLanguageModel = class {
714
1019
  if (toolCall.hasFinished) {
715
1020
  continue;
716
1021
  }
717
- if (((_f = toolCallDelta.function) == null ? void 0 : _f.arguments) != null) {
718
- toolCall.function.arguments += (_h = (_g = toolCallDelta.function) == null ? void 0 : _g.arguments) != null ? _h : "";
1022
+ if (((_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null) {
1023
+ toolCall.function.arguments += (_j = (_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null ? _j : "";
719
1024
  }
720
1025
  controller.enqueue({
721
1026
  type: "tool-input-delta",
722
1027
  id: toolCall.id,
723
- delta: (_i = toolCallDelta.function.arguments) != null ? _i : ""
1028
+ delta: (_k = toolCallDelta.function.arguments) != null ? _k : ""
724
1029
  });
725
- if (((_j = toolCall.function) == null ? void 0 : _j.name) != null && ((_k = toolCall.function) == null ? void 0 : _k.arguments) != null && (0, import_provider_utils3.isParsableJson)(toolCall.function.arguments)) {
1030
+ if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null && (0, import_provider_utils3.isParsableJson)(toolCall.function.arguments)) {
726
1031
  controller.enqueue({
727
1032
  type: "tool-input-end",
728
1033
  id: toolCall.id
729
1034
  });
730
1035
  controller.enqueue({
731
1036
  type: "tool-call",
732
- toolCallId: (_l = toolCall.id) != null ? _l : (0, import_provider_utils3.generateId)(),
1037
+ toolCallId: (_n = toolCall.id) != null ? _n : (0, import_provider_utils3.generateId)(),
733
1038
  toolName: toolCall.function.name,
734
1039
  input: toolCall.function.arguments
735
1040
  });
@@ -773,7 +1078,24 @@ var DeepSeekChatLanguageModel = class {
773
1078
  providerMetadata: {
774
1079
  [providerOptionsName]: {
775
1080
  promptCacheHitTokens: (_h = usage == null ? void 0 : usage.prompt_cache_hit_tokens) != null ? _h : null,
776
- promptCacheMissTokens: (_i = usage == null ? void 0 : usage.prompt_cache_miss_tokens) != null ? _i : null
1081
+ promptCacheMissTokens: (_i = usage == null ? void 0 : usage.prompt_cache_miss_tokens) != null ? _i : null,
1082
+ ...responseObject != null && { responseObject },
1083
+ ...choiceIndex != null && { choiceIndex },
1084
+ ...messageRole != null && { messageRole },
1085
+ ...toolCallTypes.size > 0 && {
1086
+ toolCallTypes: [...toolCallTypes.entries()].sort(([left], [right]) => left - right).map(([, type]) => type)
1087
+ },
1088
+ ...(contentLogprobs.length > 0 || reasoningLogprobs.length > 0) && {
1089
+ logprobs: {
1090
+ ...contentLogprobs.length > 0 && {
1091
+ content: contentLogprobs
1092
+ },
1093
+ ...reasoningLogprobs.length > 0 && {
1094
+ reasoning_content: reasoningLogprobs
1095
+ }
1096
+ }
1097
+ },
1098
+ ...systemFingerprint != null && { systemFingerprint }
777
1099
  }
778
1100
  }
779
1101
  });
@@ -787,14 +1109,12 @@ var DeepSeekChatLanguageModel = class {
787
1109
  };
788
1110
 
789
1111
  // src/version.ts
790
- var VERSION = true ? "1.0.52" : "0.0.0-test";
1112
+ var VERSION = true ? "1.0.54" : "0.0.0-test";
791
1113
 
792
1114
  // src/deepseek-provider.ts
793
1115
  function createDeepSeek(options = {}) {
794
1116
  var _a;
795
- const baseURL = (0, import_provider_utils4.withoutTrailingSlash)(
796
- (_a = options.baseURL) != null ? _a : "https://api.deepseek.com"
797
- );
1117
+ const baseURL = (_a = (0, import_provider_utils4.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.deepseek.com";
798
1118
  const getHeaders = () => (0, import_provider_utils4.withUserAgentSuffix)(
799
1119
  {
800
1120
  Authorization: `Bearer ${(0, import_provider_utils4.loadApiKey)({
@@ -811,17 +1131,18 @@ function createDeepSeek(options = {}) {
811
1131
  provider: `deepseek.chat`,
812
1132
  url: ({ path }) => `${baseURL}${path}`,
813
1133
  headers: getHeaders,
814
- fetch: options.fetch
1134
+ fetch: options.fetch,
1135
+ supportsAssistantPrefixCompletion: baseURL.endsWith("/beta")
815
1136
  });
816
1137
  };
817
1138
  const provider = (modelId) => createLanguageModel(modelId);
818
1139
  provider.languageModel = createLanguageModel;
819
1140
  provider.chat = createLanguageModel;
820
1141
  provider.textEmbeddingModel = (modelId) => {
821
- throw new import_provider3.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
1142
+ throw new import_provider4.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
822
1143
  };
823
1144
  provider.imageModel = (modelId) => {
824
- throw new import_provider3.NoSuchModelError({ modelId, modelType: "imageModel" });
1145
+ throw new import_provider4.NoSuchModelError({ modelId, modelType: "imageModel" });
825
1146
  };
826
1147
  return provider;
827
1148
  }