@ai-sdk/deepseek 3.0.52 → 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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @ai-sdk/deepseek
2
2
 
3
+ ## 3.0.54
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [af9597b]
8
+ - Updated dependencies [bc49f78]
9
+ - @ai-sdk/provider-utils@5.0.49
10
+
11
+ ## 3.0.53
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [be877ff]
16
+ - @ai-sdk/provider-utils@5.0.48
17
+
3
18
  ## 3.0.52
4
19
 
5
20
  ### Patch Changes
package/dist/index.js CHANGED
@@ -165,11 +165,10 @@ async function convertToDeepSeekChatMessages({
165
165
  supportsAssistantPrefixCompletion = false,
166
166
  supportsStructuredOutputs = false
167
167
  }) {
168
- var _a;
169
168
  const isDeepSeekV4 = isDeepSeekV4Model(modelId);
170
169
  const messages = [];
171
170
  const warnings = [];
172
- if ((responseFormat == null ? void 0 : responseFormat.type) === "json") {
171
+ if (responseFormat?.type === "json") {
173
172
  if (responseFormat.schema == null) {
174
173
  messages.push({
175
174
  role: "system",
@@ -202,7 +201,7 @@ async function convertToDeepSeekChatMessages({
202
201
  providerOptions,
203
202
  schema: deepseekAssistantMessageProviderOptions
204
203
  });
205
- if ((deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.prefix) === true && role !== "assistant") {
204
+ if (deepseekMessageOptions?.prefix === true && role !== "assistant") {
206
205
  throw new InvalidPromptError({
207
206
  prompt,
208
207
  message: "DeepSeek assistant prefix completion requires `prefix: true` on an assistant message."
@@ -213,7 +212,7 @@ async function convertToDeepSeekChatMessages({
213
212
  messages.push({
214
213
  role: "system",
215
214
  content,
216
- ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
215
+ ...deepseekMessageOptions?.name != null && {
217
216
  name: deepseekMessageOptions.name
218
217
  }
219
218
  });
@@ -238,7 +237,7 @@ async function convertToDeepSeekChatMessages({
238
237
  messages.push({
239
238
  role: "user",
240
239
  content: userContent2,
241
- ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
240
+ ...deepseekMessageOptions?.name != null && {
242
241
  name: deepseekMessageOptions.name
243
242
  }
244
243
  });
@@ -267,7 +266,7 @@ async function convertToDeepSeekChatMessages({
267
266
  if (part.data.type === "url") {
268
267
  const url = part.data.url.toString();
269
268
  validateDeepSeekImageUrl({ url, prompt });
270
- if ((filePartOptions == null ? void 0 : filePartOptions.fileData) === true) {
269
+ if (filePartOptions?.fileData === true) {
271
270
  throw new InvalidPromptError({
272
271
  prompt,
273
272
  message: "DeepSeek `fileData` image parts require inline data, not a URL."
@@ -277,14 +276,14 @@ async function convertToDeepSeekChatMessages({
277
276
  type: "image_url",
278
277
  image_url: {
279
278
  url,
280
- ...(filePartOptions == null ? void 0 : filePartOptions.imageDetail) != null && {
279
+ ...filePartOptions?.imageDetail != null && {
281
280
  detail: filePartOptions.imageDetail
282
281
  }
283
282
  }
284
283
  });
285
284
  } else {
286
285
  const dataUrl = `data:${resolvedMediaType === "image/jpg" ? "image/jpeg" : resolvedMediaType};base64,${convertToBase64(part.data.data)}`;
287
- if ((filePartOptions == null ? void 0 : filePartOptions.fileData) === true) {
286
+ if (filePartOptions?.fileData === true) {
288
287
  if (filePartOptions.imageDetail != null) {
289
288
  throw new InvalidPromptError({
290
289
  prompt,
@@ -301,7 +300,7 @@ async function convertToDeepSeekChatMessages({
301
300
  type: "image_url",
302
301
  image_url: {
303
302
  url: dataUrl,
304
- ...(filePartOptions == null ? void 0 : filePartOptions.imageDetail) != null && {
303
+ ...filePartOptions?.imageDetail != null && {
305
304
  detail: filePartOptions.imageDetail
306
305
  }
307
306
  }
@@ -324,14 +323,14 @@ async function convertToDeepSeekChatMessages({
324
323
  messages.push({
325
324
  role: "user",
326
325
  content: userContent,
327
- ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
326
+ ...deepseekMessageOptions?.name != null && {
328
327
  name: deepseekMessageOptions.name
329
328
  }
330
329
  });
331
330
  break;
332
331
  }
333
332
  case "assistant": {
334
- if ((deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.prefix) === true) {
333
+ if (deepseekMessageOptions?.prefix === true) {
335
334
  if (index !== prompt.length - 1) {
336
335
  throw new InvalidPromptError({
337
336
  prompt,
@@ -381,19 +380,19 @@ async function convertToDeepSeekChatMessages({
381
380
  messages.push({
382
381
  role: "assistant",
383
382
  content: text,
384
- ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null && {
383
+ ...deepseekMessageOptions?.name != null && {
385
384
  name: deepseekMessageOptions.name
386
385
  },
387
- ...(deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.prefix) === true && {
386
+ ...deepseekMessageOptions?.prefix === true && {
388
387
  prefix: true
389
388
  },
390
- reasoning_content: reasoning != null ? reasoning : isDeepSeekV4 ? "" : void 0,
389
+ reasoning_content: reasoning ?? (isDeepSeekV4 ? "" : void 0),
391
390
  tool_calls: toolCalls.length > 0 ? toolCalls : void 0
392
391
  });
393
392
  break;
394
393
  }
395
394
  case "tool": {
396
- if ((deepseekMessageOptions == null ? void 0 : deepseekMessageOptions.name) != null) {
395
+ if (deepseekMessageOptions?.name != null) {
397
396
  warnings.push({
398
397
  type: "unsupported",
399
398
  feature: "message name on tool messages"
@@ -411,7 +410,7 @@ async function convertToDeepSeekChatMessages({
411
410
  contentValue = output.value;
412
411
  break;
413
412
  case "execution-denied":
414
- contentValue = (_a = output.reason) != null ? _a : "Tool call execution denied.";
413
+ contentValue = output.reason ?? "Tool call execution denied.";
415
414
  break;
416
415
  case "json":
417
416
  case "error-json":
@@ -457,7 +456,7 @@ async function convertToDeepSeekChatMessages({
457
456
  type: "image_url",
458
457
  image_url: {
459
458
  url,
460
- ...(filePartOptions == null ? void 0 : filePartOptions.imageDetail) != null && {
459
+ ...filePartOptions?.imageDetail != null && {
461
460
  detail: filePartOptions.imageDetail
462
461
  }
463
462
  }
@@ -495,14 +494,13 @@ async function convertToDeepSeekChatMessages({
495
494
  // src/chat/convert-to-deepseek-usage.ts
496
495
  import { createNullLanguageModelUsage } from "@ai-sdk/provider-utils";
497
496
  function convertDeepSeekUsage(usage) {
498
- var _a, _b, _c, _d, _e;
499
497
  if (usage == null) {
500
498
  return createNullLanguageModelUsage();
501
499
  }
502
- const promptTokens = (_a = usage.prompt_tokens) != null ? _a : 0;
503
- const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
504
- const cacheReadTokens = (_c = usage.prompt_cache_hit_tokens) != null ? _c : 0;
505
- const reasoningTokens = (_e = (_d = usage.completion_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : 0;
500
+ const promptTokens = usage.prompt_tokens ?? 0;
501
+ const completionTokens = usage.completion_tokens ?? 0;
502
+ const cacheReadTokens = usage.prompt_cache_hit_tokens ?? 0;
503
+ const reasoningTokens = usage.completion_tokens_details?.reasoning_tokens ?? 0;
506
504
  return {
507
505
  inputTokens: {
508
506
  total: promptTokens,
@@ -637,7 +635,7 @@ function prepareTools({
637
635
  toolChoice,
638
636
  supportsStrictToolCalls
639
637
  }) {
640
- tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
638
+ tools = tools?.length ? tools : void 0;
641
639
  const toolWarnings = [];
642
640
  if (tools == null) {
643
641
  return { tools: void 0, toolChoice: void 0, toolWarnings };
@@ -678,7 +676,7 @@ function prepareTools({
678
676
  if (toolChoice == null) {
679
677
  return { tools: deepseekTools, toolChoice: void 0, toolWarnings };
680
678
  }
681
- const type = toolChoice == null ? void 0 : toolChoice.type;
679
+ const type = toolChoice?.type;
682
680
  switch (type) {
683
681
  case "auto":
684
682
  case "none":
@@ -732,12 +730,11 @@ function mapDeepSeekFinishReason(finishReason) {
732
730
 
733
731
  // src/chat/deepseek-chat-language-model.ts
734
732
  function createDeepSeekStreamError(error, data) {
735
- var _a, _b;
736
733
  const metadata = getDeepSeekStreamErrorMetadata(error);
737
734
  return createProviderStreamError({
738
735
  message: error.message,
739
- type: (_a = error.type) != null ? _a : void 0,
740
- code: (_b = error.code) != null ? _b : void 0,
736
+ type: error.type ?? void 0,
737
+ code: error.code ?? void 0,
741
738
  ...metadata,
742
739
  data
743
740
  });
@@ -849,12 +846,11 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
849
846
  toolChoice,
850
847
  tools
851
848
  }) {
852
- var _a, _b, _c, _d;
853
- const deepseekOptions = (_a = await parseProviderOptions2({
849
+ const deepseekOptions = await parseProviderOptions2({
854
850
  provider: this.providerOptionsName,
855
851
  providerOptions,
856
852
  schema: deepseekLanguageModelChatOptions
857
- })) != null ? _a : {};
853
+ }) ?? {};
858
854
  const supportsStructuredOutputs = this.config.supportsStructuredOutputs === true;
859
855
  const supportsPenaltySampling = this.config.supportsPenaltySampling === true;
860
856
  const { messages, warnings } = await convertToDeepSeekChatMessages({
@@ -895,7 +891,7 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
895
891
  toolChoice,
896
892
  supportsStrictToolCalls: this.config.supportsStrictToolCalls
897
893
  });
898
- const thinkingType = (_b = deepseekOptions.thinking) == null ? void 0 : _b.type;
894
+ const thinkingType = deepseekOptions.thinking?.type;
899
895
  if (thinkingType === "adaptive") {
900
896
  allWarnings.push({
901
897
  type: "compatibility",
@@ -904,7 +900,7 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
904
900
  });
905
901
  }
906
902
  const thinking = this.config.supportsThinking === false ? void 0 : thinkingType != null ? { type: thinkingType === "adaptive" ? "enabled" : thinkingType } : isCustomReasoning(reasoning) ? { type: reasoning === "none" ? "disabled" : "enabled" } : void 0;
907
- const isThinkingEnabled = this.config.supportsThinking !== false && (thinking == null ? void 0 : thinking.type) !== "disabled" && (thinking != null || this.modelId === "deepseek-reasoner" || isDeepSeekV4Model(this.modelId));
903
+ const isThinkingEnabled = this.config.supportsThinking !== false && thinking?.type !== "disabled" && (thinking != null || this.modelId === "deepseek-reasoner" || isDeepSeekV4Model(this.modelId));
908
904
  if (isThinkingEnabled && temperature != null) {
909
905
  allWarnings.push({
910
906
  type: "unsupported",
@@ -945,12 +941,12 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
945
941
  top_p: isThinkingEnabled ? void 0 : topP,
946
942
  frequency_penalty: supportsPenaltySampling ? frequencyPenalty : void 0,
947
943
  presence_penalty: supportsPenaltySampling ? presencePenalty : void 0,
948
- response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? supportsStructuredOutputs && responseFormat.schema != null ? {
944
+ response_format: responseFormat?.type === "json" ? supportsStructuredOutputs && responseFormat.schema != null ? {
949
945
  type: "json_schema",
950
946
  json_schema: {
951
947
  schema: responseFormat.schema,
952
- strict: (_c = deepseekOptions.strictJsonSchema) != null ? _c : true,
953
- name: (_d = responseFormat.name) != null ? _d : "response",
948
+ strict: deepseekOptions.strictJsonSchema ?? true,
949
+ name: responseFormat.name ?? "response",
954
950
  description: responseFormat.description
955
951
  }
956
952
  } : { type: "json_object" } : void 0,
@@ -962,7 +958,7 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
962
958
  ...deepseekOptions.userId != null && {
963
959
  user_id: deepseekOptions.userId
964
960
  },
965
- ...(thinking == null ? void 0 : thinking.type) !== "disabled" && reasoningEffort != null && {
961
+ ...thinking?.type !== "disabled" && reasoningEffort != null && {
966
962
  reasoning_effort: reasoningEffort
967
963
  }
968
964
  },
@@ -970,7 +966,6 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
970
966
  };
971
967
  }
972
968
  async doGenerate(options) {
973
- var _a, _b, _c, _d, _e;
974
969
  const { args, warnings } = await this.getArgs({ ...options });
975
970
  const {
976
971
  responseHeaders,
@@ -981,7 +976,7 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
981
976
  path: "/chat/completions",
982
977
  modelId: this.modelId
983
978
  }),
984
- headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
979
+ headers: combineHeaders(this.config.headers?.(), options.headers),
985
980
  body: args,
986
981
  failedResponseHandler: this.failedResponseHandler,
987
982
  successfulResponseHandler: createJsonResponseHandler(
@@ -1023,13 +1018,13 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
1023
1018
  content,
1024
1019
  finishReason: {
1025
1020
  unified: mapDeepSeekFinishReason(choice.finish_reason),
1026
- raw: (_c = choice.finish_reason) != null ? _c : void 0
1021
+ raw: choice.finish_reason ?? void 0
1027
1022
  },
1028
1023
  usage: convertDeepSeekUsage(responseBody.usage),
1029
1024
  providerMetadata: {
1030
1025
  [this.providerOptionsName]: {
1031
- promptCacheHitTokens: (_d = responseBody.usage) == null ? void 0 : _d.prompt_cache_hit_tokens,
1032
- promptCacheMissTokens: (_e = responseBody.usage) == null ? void 0 : _e.prompt_cache_miss_tokens,
1026
+ promptCacheHitTokens: responseBody.usage?.prompt_cache_hit_tokens,
1027
+ promptCacheMissTokens: responseBody.usage?.prompt_cache_miss_tokens,
1033
1028
  ...responseBody.object != null && {
1034
1029
  responseObject: responseBody.object
1035
1030
  },
@@ -1056,7 +1051,6 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
1056
1051
  };
1057
1052
  }
1058
1053
  async doStream(options) {
1059
- var _a, _b;
1060
1054
  const { args, warnings } = await this.getArgs({ ...options });
1061
1055
  const body = {
1062
1056
  ...args,
@@ -1068,7 +1062,7 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
1068
1062
  path: "/chat/completions",
1069
1063
  modelId: this.modelId
1070
1064
  }),
1071
- headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
1065
+ headers: combineHeaders(this.config.headers?.(), options.headers),
1072
1066
  body,
1073
1067
  failedResponseHandler: this.failedResponseHandler,
1074
1068
  successfulResponseHandler: createEventSourceResponseHandler(
@@ -1104,7 +1098,6 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
1104
1098
  controller.enqueue({ type: "stream-start", warnings });
1105
1099
  },
1106
1100
  transform(chunk, controller) {
1107
- var _a2, _b2;
1108
1101
  if (options.includeRawChunks) {
1109
1102
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1110
1103
  }
@@ -1139,22 +1132,22 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
1139
1132
  systemFingerprint = value.system_fingerprint;
1140
1133
  }
1141
1134
  const choice = value.choices[0];
1142
- if ((choice == null ? void 0 : choice.index) != null) {
1135
+ if (choice?.index != null) {
1143
1136
  choiceIndex = choice.index;
1144
1137
  }
1145
- if ((choice == null ? void 0 : choice.finish_reason) != null) {
1138
+ if (choice?.finish_reason != null) {
1146
1139
  finishReason = {
1147
1140
  unified: mapDeepSeekFinishReason(choice.finish_reason),
1148
1141
  raw: choice.finish_reason
1149
1142
  };
1150
1143
  }
1151
- if (((_a2 = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _a2.content) != null) {
1144
+ if (choice?.logprobs?.content != null) {
1152
1145
  contentLogprobs.push(...choice.logprobs.content);
1153
1146
  }
1154
- if (((_b2 = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _b2.reasoning_content) != null) {
1147
+ if (choice?.logprobs?.reasoning_content != null) {
1155
1148
  reasoningLogprobs.push(...choice.logprobs.reasoning_content);
1156
1149
  }
1157
- if ((choice == null ? void 0 : choice.delta) == null) {
1150
+ if (choice?.delta == null) {
1158
1151
  return;
1159
1152
  }
1160
1153
  const delta = choice.delta;
@@ -1211,7 +1204,6 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
1211
1204
  }
1212
1205
  },
1213
1206
  flush(controller) {
1214
- var _a2, _b2;
1215
1207
  if (isActiveReasoning) {
1216
1208
  controller.enqueue({ type: "reasoning-end", id: "reasoning-0" });
1217
1209
  }
@@ -1225,8 +1217,8 @@ var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
1225
1217
  usage: convertDeepSeekUsage(usage),
1226
1218
  providerMetadata: {
1227
1219
  [providerOptionsName]: {
1228
- promptCacheHitTokens: (_a2 = usage == null ? void 0 : usage.prompt_cache_hit_tokens) != null ? _a2 : void 0,
1229
- promptCacheMissTokens: (_b2 = usage == null ? void 0 : usage.prompt_cache_miss_tokens) != null ? _b2 : void 0,
1220
+ promptCacheHitTokens: usage?.prompt_cache_hit_tokens ?? void 0,
1221
+ promptCacheMissTokens: usage?.prompt_cache_miss_tokens ?? void 0,
1230
1222
  ...responseObject != null && { responseObject },
1231
1223
  ...choiceIndex != null && { choiceIndex },
1232
1224
  ...messageRole != null && { messageRole },
@@ -1354,7 +1346,6 @@ var DeepSeekFiles = class {
1354
1346
  headers,
1355
1347
  providerOptions
1356
1348
  }) {
1357
- var _a, _b;
1358
1349
  const deepSeekOptions = await parseProviderOptions3({
1359
1350
  provider: "deepseek",
1360
1351
  providerOptions,
@@ -1370,7 +1361,7 @@ var DeepSeekFiles = class {
1370
1361
  formData.append("file", blob);
1371
1362
  }
1372
1363
  formData.append("purpose", "user_data");
1373
- if ((deepSeekOptions == null ? void 0 : deepSeekOptions.expiresAfter) != null) {
1364
+ if (deepSeekOptions?.expiresAfter != null) {
1374
1365
  formData.append("expires_after[anchor]", "created_at");
1375
1366
  formData.append(
1376
1367
  "expires_after[seconds]",
@@ -1391,7 +1382,7 @@ var DeepSeekFiles = class {
1391
1382
  return {
1392
1383
  warnings: [],
1393
1384
  providerReference: { deepseek: response.id },
1394
- ...((_a = response.filename) != null ? _a : filename) ? { filename: (_b = response.filename) != null ? _b : filename } : {},
1385
+ ...response.filename ?? filename ? { filename: response.filename ?? filename } : {},
1395
1386
  ...mediaType != null ? { mediaType } : {},
1396
1387
  providerMetadata: {
1397
1388
  deepseek: {
@@ -1465,12 +1456,11 @@ function hasSupportedFilenameExtension(filename) {
1465
1456
  }
1466
1457
 
1467
1458
  // src/version.ts
1468
- var VERSION = true ? "3.0.52" : "0.0.0-test";
1459
+ var VERSION = true ? "3.0.54" : "0.0.0-test";
1469
1460
 
1470
1461
  // src/deepseek-provider.ts
1471
1462
  function createDeepSeek(options = {}) {
1472
- var _a, _b;
1473
- const baseURL = (_b = withoutTrailingSlash((_a = options.baseURL) != null ? _a : "https://api.deepseek.com")) != null ? _b : "https://api.deepseek.com";
1463
+ const baseURL = withoutTrailingSlash(options.baseURL ?? "https://api.deepseek.com") ?? "https://api.deepseek.com";
1474
1464
  const getHeaders = () => withUserAgentSuffix(
1475
1465
  {
1476
1466
  Authorization: `Bearer ${loadApiKey({