@ai-sdk/deepseek 3.0.51 → 3.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.
@@ -155,11 +155,10 @@ async function convertToDeepSeekChatMessages({
155
155
  supportsAssistantPrefixCompletion = false,
156
156
  supportsStructuredOutputs = false
157
157
  }) {
158
- var _a;
159
158
  const isDeepSeekV4 = isDeepSeekV4Model(modelId);
160
159
  const messages = [];
161
160
  const warnings = [];
162
- if ((responseFormat == null ? void 0 : responseFormat.type) === "json") {
161
+ if (responseFormat?.type === "json") {
163
162
  if (responseFormat.schema == null) {
164
163
  messages.push({
165
164
  role: "system",
@@ -192,7 +191,7 @@ async function convertToDeepSeekChatMessages({
192
191
  providerOptions,
193
192
  schema: deepseekAssistantMessageProviderOptions
194
193
  });
195
- if ((deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.prefix) === true && role !== "assistant") {
194
+ if (deepseekMessageOptions?.prefix === true && role !== "assistant") {
196
195
  throw new InvalidPromptError({
197
196
  prompt,
198
197
  message: "DeepSeek assistant prefix completion requires `prefix: true` on an assistant message."
@@ -203,7 +202,7 @@ async function convertToDeepSeekChatMessages({
203
202
  messages.push({
204
203
  role: "system",
205
204
  content,
206
- ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
205
+ ...deepseekMessageOptions?.name != null && {
207
206
  name: deepseekMessageOptions.name
208
207
  }
209
208
  });
@@ -228,7 +227,7 @@ async function convertToDeepSeekChatMessages({
228
227
  messages.push({
229
228
  role: "user",
230
229
  content: userContent2,
231
- ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
230
+ ...deepseekMessageOptions?.name != null && {
232
231
  name: deepseekMessageOptions.name
233
232
  }
234
233
  });
@@ -257,7 +256,7 @@ async function convertToDeepSeekChatMessages({
257
256
  if (part.data.type === "url") {
258
257
  const url = part.data.url.toString();
259
258
  validateDeepSeekImageUrl({ url, prompt });
260
- if ((filePartOptions == null ? void 0 : filePartOptions.fileData) === true) {
259
+ if (filePartOptions?.fileData === true) {
261
260
  throw new InvalidPromptError({
262
261
  prompt,
263
262
  message: "DeepSeek `fileData` image parts require inline data, not a URL."
@@ -267,14 +266,14 @@ async function convertToDeepSeekChatMessages({
267
266
  type: "image_url",
268
267
  image_url: {
269
268
  url,
270
- ...(filePartOptions == null ? void 0 : filePartOptions.imageDetail) != null && {
269
+ ...filePartOptions?.imageDetail != null && {
271
270
  detail: filePartOptions.imageDetail
272
271
  }
273
272
  }
274
273
  });
275
274
  } else {
276
275
  const dataUrl = `data:${resolvedMediaType === "image/jpg" ? "image/jpeg" : resolvedMediaType};base64,${convertToBase64(part.data.data)}`;
277
- if ((filePartOptions == null ? void 0 : filePartOptions.fileData) === true) {
276
+ if (filePartOptions?.fileData === true) {
278
277
  if (filePartOptions.imageDetail != null) {
279
278
  throw new InvalidPromptError({
280
279
  prompt,
@@ -291,7 +290,7 @@ async function convertToDeepSeekChatMessages({
291
290
  type: "image_url",
292
291
  image_url: {
293
292
  url: dataUrl,
294
- ...(filePartOptions == null ? void 0 : filePartOptions.imageDetail) != null && {
293
+ ...filePartOptions?.imageDetail != null && {
295
294
  detail: filePartOptions.imageDetail
296
295
  }
297
296
  }
@@ -314,14 +313,14 @@ async function convertToDeepSeekChatMessages({
314
313
  messages.push({
315
314
  role: "user",
316
315
  content: userContent,
317
- ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
316
+ ...deepseekMessageOptions?.name != null && {
318
317
  name: deepseekMessageOptions.name
319
318
  }
320
319
  });
321
320
  break;
322
321
  }
323
322
  case "assistant": {
324
- if ((deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.prefix) === true) {
323
+ if (deepseekMessageOptions?.prefix === true) {
325
324
  if (index !== prompt.length - 1) {
326
325
  throw new InvalidPromptError({
327
326
  prompt,
@@ -371,19 +370,19 @@ async function convertToDeepSeekChatMessages({
371
370
  messages.push({
372
371
  role: "assistant",
373
372
  content: text,
374
- ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
373
+ ...deepseekMessageOptions?.name != null && {
375
374
  name: deepseekMessageOptions.name
376
375
  },
377
- ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.prefix) === true && {
376
+ ...deepseekMessageOptions?.prefix === true && {
378
377
  prefix: true
379
378
  },
380
- reasoning_content: reasoning != null ? reasoning : isDeepSeekV4 ? "" : void 0,
379
+ reasoning_content: reasoning ?? (isDeepSeekV4 ? "" : void 0),
381
380
  tool_calls: toolCalls.length > 0 ? toolCalls : void 0
382
381
  });
383
382
  break;
384
383
  }
385
384
  case "tool": {
386
- if ((deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null) {
385
+ if (deepseekMessageOptions?.name != null) {
387
386
  warnings.push({
388
387
  type: "unsupported",
389
388
  feature: "message name on tool messages"
@@ -401,7 +400,7 @@ async function convertToDeepSeekChatMessages({
401
400
  contentValue = output.value;
402
401
  break;
403
402
  case "execution-denied":
404
- contentValue = (_a = output.reason) != null ? _a : "Tool call execution denied.";
403
+ contentValue = output.reason ?? "Tool call execution denied.";
405
404
  break;
406
405
  case "json":
407
406
  case "error-json":
@@ -447,7 +446,7 @@ async function convertToDeepSeekChatMessages({
447
446
  type: "image_url",
448
447
  image_url: {
449
448
  url,
450
- ...(filePartOptions == null ? void 0 : filePartOptions.imageDetail) != null && {
449
+ ...filePartOptions?.imageDetail != null && {
451
450
  detail: filePartOptions.imageDetail
452
451
  }
453
452
  }
@@ -485,14 +484,13 @@ async function convertToDeepSeekChatMessages({
485
484
  // src/chat/convert-to-deepseek-usage.ts
486
485
  import { createNullLanguageModelUsage } from "@ai-sdk/provider-utils";
487
486
  function convertDeepSeekUsage(usage) {
488
- var _a, _b, _c, _d, _e;
489
487
  if (usage == null) {
490
488
  return createNullLanguageModelUsage();
491
489
  }
492
- const promptTokens = (_a = usage.prompt_tokens) != null ? _a : 0;
493
- const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
494
- const cacheReadTokens = (_c = usage.prompt_cache_hit_tokens) != null ? _c : 0;
495
- const reasoningTokens = (_e = (_d = usage.completion_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : 0;
490
+ const promptTokens = usage.prompt_tokens ?? 0;
491
+ const completionTokens = usage.completion_tokens ?? 0;
492
+ const cacheReadTokens = usage.prompt_cache_hit_tokens ?? 0;
493
+ const reasoningTokens = usage.completion_tokens_details?.reasoning_tokens ?? 0;
496
494
  return {
497
495
  inputTokens: {
498
496
  total: promptTokens,
@@ -627,7 +625,7 @@ function prepareTools({
627
625
  toolChoice,
628
626
  supportsStrictToolCalls
629
627
  }) {
630
- tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
628
+ tools = tools?.length ? tools : void 0;
631
629
  const toolWarnings = [];
632
630
  if (tools == null) {
633
631
  return { tools: void 0, toolChoice: void 0, toolWarnings };
@@ -668,7 +666,7 @@ function prepareTools({
668
666
  if (toolChoice == null) {
669
667
  return { tools: deepseekTools, toolChoice: void 0, toolWarnings };
670
668
  }
671
- const type = toolChoice == null ? void 0 : toolChoice.type;
669
+ const type = toolChoice?.type;
672
670
  switch (type) {
673
671
  case "auto":
674
672
  case "none":
@@ -722,12 +720,11 @@ function mapDeepSeekFinishReason(finishReason) {
722
720
 
723
721
  // src/chat/deepseek-chat-language-model.ts
724
722
  function createDeepSeekStreamError(error, data) {
725
- var _a, _b;
726
723
  const metadata = getDeepSeekStreamErrorMetadata(error);
727
724
  return createProviderStreamError({
728
725
  message: error.message,
729
- type: (_a = error.type) != null ? _a : void 0,
730
- code: (_b = error.code) != null ? _b : void 0,
726
+ type: error.type ?? void 0,
727
+ code: error.code ?? void 0,
731
728
  ...metadata,
732
729
  data
733
730
  });
@@ -839,12 +836,11 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
839
836
  toolChoice,
840
837
  tools
841
838
  }) {
842
- var _a, _b, _c, _d;
843
- const deepseekOptions = (_a = await parseProviderOptions2({
839
+ const deepseekOptions = await parseProviderOptions2({
844
840
  provider: this.providerOptionsName,
845
841
  providerOptions,
846
842
  schema: deepseekLanguageModelChatOptions
847
- })) != null ? _a : {};
843
+ }) ?? {};
848
844
  const supportsStructuredOutputs = this.config.supportsStructuredOutputs === true;
849
845
  const supportsPenaltySampling = this.config.supportsPenaltySampling === true;
850
846
  const { messages, warnings } = await convertToDeepSeekChatMessages({
@@ -885,7 +881,7 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
885
881
  toolChoice,
886
882
  supportsStrictToolCalls: this.config.supportsStrictToolCalls
887
883
  });
888
- const thinkingType = (_b = deepseekOptions.thinking) == null ? void 0 : _b.type;
884
+ const thinkingType = deepseekOptions.thinking?.type;
889
885
  if (thinkingType === "adaptive") {
890
886
  allWarnings.push({
891
887
  type: "compatibility",
@@ -894,7 +890,7 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
894
890
  });
895
891
  }
896
892
  const thinking = this.config.supportsThinking === false ? void 0 : thinkingType != null ? { type: thinkingType === "adaptive" ? "enabled" : thinkingType } : isCustomReasoning(reasoning) ? { type: reasoning === "none" ? "disabled" : "enabled" } : void 0;
897
- const isThinkingEnabled = this.config.supportsThinking !== false && (thinking == null ? void 0 : thinking.type) !== "disabled" && (thinking != null || this.modelId === "deepseek-reasoner" || isDeepSeekV4Model(this.modelId));
893
+ const isThinkingEnabled = this.config.supportsThinking !== false && thinking?.type !== "disabled" && (thinking != null || this.modelId === "deepseek-reasoner" || isDeepSeekV4Model(this.modelId));
898
894
  if (isThinkingEnabled && temperature != null) {
899
895
  allWarnings.push({
900
896
  type: "unsupported",
@@ -935,12 +931,12 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
935
931
  top_p: isThinkingEnabled ? void 0 : topP,
936
932
  frequency_penalty: supportsPenaltySampling ? frequencyPenalty : void 0,
937
933
  presence_penalty: supportsPenaltySampling ? presencePenalty : void 0,
938
- response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? supportsStructuredOutputs && responseFormat.schema != null ? {
934
+ response_format: responseFormat?.type === "json" ? supportsStructuredOutputs && responseFormat.schema != null ? {
939
935
  type: "json_schema",
940
936
  json_schema: {
941
937
  schema: responseFormat.schema,
942
- strict: (_c = deepseekOptions.strictJsonSchema) != null ? _c : true,
943
- name: (_d = responseFormat.name) != null ? _d : "response",
938
+ strict: deepseekOptions.strictJsonSchema ?? true,
939
+ name: responseFormat.name ?? "response",
944
940
  description: responseFormat.description
945
941
  }
946
942
  } : { type: "json_object" } : void 0,
@@ -952,7 +948,7 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
952
948
  ...deepseekOptions.userId != null && {
953
949
  user_id: deepseekOptions.userId
954
950
  },
955
- ...(thinking == null ? void 0 : thinking.type) !== "disabled" && reasoningEffort != null && {
951
+ ...thinking?.type !== "disabled" && reasoningEffort != null && {
956
952
  reasoning_effort: reasoningEffort
957
953
  }
958
954
  },
@@ -960,7 +956,6 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
960
956
  };
961
957
  }
962
958
  async doGenerate(options) {
963
- var _a, _b, _c, _d, _e;
964
959
  const { args, warnings } = await this.getArgs({ ...options });
965
960
  const {
966
961
  responseHeaders,
@@ -971,7 +966,7 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
971
966
  path: "/chat/completions",
972
967
  modelId: this.modelId
973
968
  }),
974
- headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
969
+ headers: combineHeaders(this.config.headers?.(), options.headers),
975
970
  body: args,
976
971
  failedResponseHandler: this.failedResponseHandler,
977
972
  successfulResponseHandler: createJsonResponseHandler(
@@ -1013,13 +1008,13 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
1013
1008
  content,
1014
1009
  finishReason: {
1015
1010
  unified: mapDeepSeekFinishReason(choice.finish_reason),
1016
- raw: (_c = choice.finish_reason) != null ? _c : void 0
1011
+ raw: choice.finish_reason ?? void 0
1017
1012
  },
1018
1013
  usage: convertDeepSeekUsage(responseBody.usage),
1019
1014
  providerMetadata: {
1020
1015
  [this.providerOptionsName]: {
1021
- promptCacheHitTokens: (_d = responseBody.usage) == null ? void 0 : _d.prompt_cache_hit_tokens,
1022
- promptCacheMissTokens: (_e = responseBody.usage) == null ? void 0 : _e.prompt_cache_miss_tokens,
1016
+ promptCacheHitTokens: responseBody.usage?.prompt_cache_hit_tokens,
1017
+ promptCacheMissTokens: responseBody.usage?.prompt_cache_miss_tokens,
1023
1018
  ...responseBody.object != null && {
1024
1019
  responseObject: responseBody.object
1025
1020
  },
@@ -1046,7 +1041,6 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
1046
1041
  };
1047
1042
  }
1048
1043
  async doStream(options) {
1049
- var _a, _b;
1050
1044
  const { args, warnings } = await this.getArgs({ ...options });
1051
1045
  const body = {
1052
1046
  ...args,
@@ -1058,7 +1052,7 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
1058
1052
  path: "/chat/completions",
1059
1053
  modelId: this.modelId
1060
1054
  }),
1061
- headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
1055
+ headers: combineHeaders(this.config.headers?.(), options.headers),
1062
1056
  body,
1063
1057
  failedResponseHandler: this.failedResponseHandler,
1064
1058
  successfulResponseHandler: createEventSourceResponseHandler(
@@ -1094,7 +1088,6 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
1094
1088
  controller.enqueue({ type: "stream-start", warnings });
1095
1089
  },
1096
1090
  transform(chunk, controller) {
1097
- var _a2, _b2;
1098
1091
  if (options.includeRawChunks) {
1099
1092
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1100
1093
  }
@@ -1129,22 +1122,22 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
1129
1122
  systemFingerprint = value.system_fingerprint;
1130
1123
  }
1131
1124
  const choice = value.choices[0];
1132
- if ((choice == null ? void 0 : choice.index) != null) {
1125
+ if (choice?.index != null) {
1133
1126
  choiceIndex = choice.index;
1134
1127
  }
1135
- if ((choice == null ? void 0 : choice.finish_reason) != null) {
1128
+ if (choice?.finish_reason != null) {
1136
1129
  finishReason = {
1137
1130
  unified: mapDeepSeekFinishReason(choice.finish_reason),
1138
1131
  raw: choice.finish_reason
1139
1132
  };
1140
1133
  }
1141
- if (((_a2 = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _a2.content) != null) {
1134
+ if (choice?.logprobs?.content != null) {
1142
1135
  contentLogprobs.push(...choice.logprobs.content);
1143
1136
  }
1144
- if (((_b2 = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _b2.reasoning_content) != null) {
1137
+ if (choice?.logprobs?.reasoning_content != null) {
1145
1138
  reasoningLogprobs.push(...choice.logprobs.reasoning_content);
1146
1139
  }
1147
- if ((choice == null ? void 0 : choice.delta) == null) {
1140
+ if (choice?.delta == null) {
1148
1141
  return;
1149
1142
  }
1150
1143
  const delta = choice.delta;
@@ -1201,7 +1194,6 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
1201
1194
  }
1202
1195
  },
1203
1196
  flush(controller) {
1204
- var _a2, _b2;
1205
1197
  if (isActiveReasoning) {
1206
1198
  controller.enqueue({ type: "reasoning-end", id: "reasoning-0" });
1207
1199
  }
@@ -1215,8 +1207,8 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
1215
1207
  usage: convertDeepSeekUsage(usage),
1216
1208
  providerMetadata: {
1217
1209
  [providerOptionsName]: {
1218
- promptCacheHitTokens: (_a2 = usage == null ? void 0 : usage.prompt_cache_hit_tokens) != null ? _a2 : void 0,
1219
- promptCacheMissTokens: (_b2 = usage == null ? void 0 : usage.prompt_cache_miss_tokens) != null ? _b2 : void 0,
1210
+ promptCacheHitTokens: usage?.prompt_cache_hit_tokens ?? void 0,
1211
+ promptCacheMissTokens: usage?.prompt_cache_miss_tokens ?? void 0,
1220
1212
  ...responseObject != null && { responseObject },
1221
1213
  ...choiceIndex != null && { choiceIndex },
1222
1214
  ...messageRole != null && { messageRole },