@ai-sdk/deepseek 3.0.79 → 3.0.81

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.
@@ -47,8 +47,8 @@ import {
47
47
  } from './deepseek-chat-language-model-options';
48
48
  import { prepareTools } from './deepseek-prepare-tools';
49
49
  import { getResponseMetadata } from './get-response-metadata';
50
- import { isDeepSeekV4Model } from './is-deepseek-v4-model';
51
50
  import { mapDeepSeekFinishReason } from './map-deepseek-finish-reason';
51
+ import { getDeepSeekLanguageModelEntry } from '../deepseek-model-catalog';
52
52
 
53
53
  export type DeepSeekChatConfig = {
54
54
  provider: string;
@@ -250,10 +250,12 @@ export class DeepSeekChatLanguageModel implements LanguageModelV4 {
250
250
  schema: deepseekLanguageModelChatOptions,
251
251
  })) ?? {};
252
252
 
253
- const supportsStructuredOutputs =
254
- this.config.supportsStructuredOutputs === true;
255
- const supportsPenaltySampling =
256
- this.config.supportsPenaltySampling === true;
253
+ const { language: capabilities } = getDeepSeekLanguageModelEntry(
254
+ this.modelId,
255
+ this.config,
256
+ ).capabilities;
257
+ const supportsStructuredOutputs = capabilities.structuredOutput.jsonSchema;
258
+ const supportsPenaltySampling = capabilities.sampling.penalties;
257
259
 
258
260
  const { messages, warnings } = await convertToDeepSeekChatMessages({
259
261
  prompt,
@@ -261,7 +263,7 @@ export class DeepSeekChatLanguageModel implements LanguageModelV4 {
261
263
  modelId: this.modelId,
262
264
  providerOptionsName: this.providerOptionsName,
263
265
  supportsAssistantPrefixCompletion:
264
- this.config.supportsAssistantPrefixCompletion,
266
+ capabilities.endpoints.assistantPrefixCompletion,
265
267
  supportsStructuredOutputs,
266
268
  });
267
269
  const allWarnings: SharedV4Warning[] = [...warnings];
@@ -299,7 +301,10 @@ export class DeepSeekChatLanguageModel implements LanguageModelV4 {
299
301
  } = prepareTools({
300
302
  tools,
301
303
  toolChoice,
302
- supportsStrictToolCalls: this.config.supportsStrictToolCalls,
304
+ supportsStrictToolCalls:
305
+ capabilities.tools.strict === 'unknown'
306
+ ? undefined
307
+ : capabilities.tools.strict,
303
308
  });
304
309
 
305
310
  const thinkingType = deepseekOptions.thinking?.type;
@@ -312,21 +317,18 @@ export class DeepSeekChatLanguageModel implements LanguageModelV4 {
312
317
  });
313
318
  }
314
319
 
315
- const thinking =
316
- this.config.supportsThinking === false
317
- ? undefined
318
- : thinkingType != null
319
- ? { type: thinkingType === 'adaptive' ? 'enabled' : thinkingType }
320
- : isCustomReasoning(reasoning)
321
- ? { type: reasoning === 'none' ? 'disabled' : 'enabled' }
322
- : undefined;
320
+ const thinking = !capabilities.reasoning.configurable
321
+ ? undefined
322
+ : thinkingType != null
323
+ ? { type: thinkingType === 'adaptive' ? 'enabled' : thinkingType }
324
+ : isCustomReasoning(reasoning)
325
+ ? { type: reasoning === 'none' ? 'disabled' : 'enabled' }
326
+ : undefined;
323
327
 
324
328
  const isThinkingEnabled =
325
- this.config.supportsThinking !== false &&
329
+ capabilities.reasoning.configurable &&
326
330
  thinking?.type !== 'disabled' &&
327
- (thinking != null ||
328
- this.modelId === 'deepseek-reasoner' ||
329
- isDeepSeekV4Model(this.modelId));
331
+ (thinking != null || capabilities.reasoning.enabledByDefault);
330
332
 
331
333
  if (isThinkingEnabled && temperature != null) {
332
334
  allWarnings.push({
@@ -1,3 +1,5 @@
1
+ import { getDeepSeekLanguageModelEntry } from '../deepseek-model-catalog';
2
+
1
3
  /**
2
4
  * Whether a model id uses DeepSeek V4-or-newer behavior (thinking mode on by
3
5
  * default, `reasoning_content` required on every assistant turn).
@@ -8,7 +10,6 @@
8
10
  * their previous behavior; unrecognized IDs inherit the current protocol.
9
11
  */
10
12
  export function isDeepSeekV4Model(modelId: string): boolean {
11
- return !/(^|[/.])deepseek-(?:chat|reasoner|v[1-3](?:\.\d+)?)(?=[-/:.]|$)/.test(
12
- modelId,
13
- );
13
+ return getDeepSeekLanguageModelEntry(modelId).capabilities.language.reasoning
14
+ .assistantHistory;
14
15
  }
@@ -0,0 +1,169 @@
1
+ import type {
2
+ ModelCapabilities,
3
+ ModelCapability,
4
+ ModelEntry,
5
+ ProviderOptionDefinition,
6
+ ProviderOptionDefinitions,
7
+ } from '@ai-sdk/provider';
8
+ import type { DeepSeekLanguageModelChatOptions } from './chat/deepseek-chat-language-model-options';
9
+
10
+ export const deepseekProviderOptions = {
11
+ language: {
12
+ logprobs: { description: 'Return token log probabilities.' },
13
+ topLogprobs: {
14
+ description: 'Number of token log probabilities to return.',
15
+ },
16
+ userId: { description: 'End-user identifier for request isolation.' },
17
+ thinking: { description: 'Enable or disable thinking.' },
18
+ reasoningEffort: { description: 'Thinking strength for reasoning models.' },
19
+ strictJsonSchema: {
20
+ description: 'Use strict JSON schema validation on supporting endpoints.',
21
+ },
22
+ } satisfies Record<
23
+ keyof DeepSeekLanguageModelChatOptions,
24
+ ProviderOptionDefinition
25
+ >,
26
+ } as const satisfies ProviderOptionDefinitions;
27
+
28
+ export type DeepSeekEndpointOptions = {
29
+ supportsAssistantPrefixCompletion?: boolean;
30
+ supportsStrictToolCalls?: boolean;
31
+ supportsPenaltySampling?: boolean;
32
+ supportsThinking?: boolean;
33
+ supportsStructuredOutputs?: boolean;
34
+ };
35
+
36
+ type LanguageCapabilities = NonNullable<ModelCapabilities['language']> & {
37
+ textGeneration: ModelCapability;
38
+ tools: NonNullable<ModelCapabilities['language']>['tools'] & {
39
+ strict: boolean | 'unknown';
40
+ };
41
+ reasoning: NonNullable<ModelCapabilities['language']>['reasoning'] & {
42
+ configurable: boolean;
43
+ enabledByDefault: boolean;
44
+ assistantHistory: boolean;
45
+ };
46
+ sampling: NonNullable<ModelCapabilities['language']>['sampling'] & {
47
+ penalties: boolean;
48
+ topK: false;
49
+ seed: false;
50
+ };
51
+ structuredOutput: { jsonSchema: boolean };
52
+ endpoints: { assistantPrefixCompletion: boolean };
53
+ };
54
+
55
+ export type DeepSeekLanguageModelEntry = ModelEntry & {
56
+ capabilities: { language: LanguageCapabilities };
57
+ providerOptions: {
58
+ language: Record<keyof DeepSeekLanguageModelChatOptions, ModelCapability>;
59
+ };
60
+ };
61
+
62
+ // Preserve the provider page's model set and its image-input exception.
63
+ const languageDefinitions: Record<string, boolean> = {
64
+ 'deepseek-flash': false,
65
+ 'deepseek-v4-flash': false,
66
+ 'deepseek-v4-pro': false,
67
+ 'deepseek-v4-flash-vision-exp': true,
68
+ };
69
+
70
+ function createLanguageModelEntry(
71
+ modelId: string,
72
+ image?: boolean,
73
+ ): DeepSeekLanguageModelEntry {
74
+ // Legacy aliases and pre-V4 IDs retain their previous protocol. Unknown IDs
75
+ // inherit the current protocol, including assistant reasoning history.
76
+ const assistantHistory =
77
+ !/(^|[/.])deepseek-(?:chat|reasoner|v[1-3](?:\.\d+)?)(?=[-/:.]|$)/.test(
78
+ modelId,
79
+ );
80
+ const support = image != null ? true : 'unknown';
81
+ const language: LanguageCapabilities = {
82
+ textGeneration: support,
83
+ inputs: { image: image ?? 'unknown', audio: false },
84
+ objectGeneration: support,
85
+ tools: { usage: support, streaming: support, strict: 'unknown' },
86
+ reasoning: {
87
+ support,
88
+ ...(image != null ? { efforts: ['low', 'high', 'max'] } : {}),
89
+ configurable: true,
90
+ enabledByDefault: modelId === 'deepseek-reasoner' || assistantHistory,
91
+ assistantHistory,
92
+ },
93
+ sampling: {
94
+ temperature: { condition: 'Only effective when thinking is disabled.' },
95
+ topP: { condition: 'Only effective when thinking is disabled.' },
96
+ logprobs: support,
97
+ penalties: false,
98
+ topK: false,
99
+ seed: false,
100
+ },
101
+ structuredOutput: { jsonSchema: false },
102
+ endpoints: { assistantPrefixCompletion: false },
103
+ };
104
+ return {
105
+ capabilities: { language },
106
+ providerOptions: {
107
+ language: {
108
+ logprobs: language.sampling.logprobs,
109
+ topLogprobs: language.sampling.logprobs,
110
+ userId: support,
111
+ thinking: language.reasoning.support,
112
+ reasoningEffort: language.reasoning.support,
113
+ strictJsonSchema: {
114
+ condition:
115
+ 'Requires a serving endpoint with JSON schema response formatting.',
116
+ },
117
+ },
118
+ },
119
+ };
120
+ }
121
+
122
+ export const deepseekModelCatalog: Readonly<
123
+ Record<string, DeepSeekLanguageModelEntry>
124
+ > = Object.fromEntries(
125
+ Object.entries(languageDefinitions).map(([modelId, image]) => [
126
+ modelId,
127
+ createLanguageModelEntry(modelId, image),
128
+ ]),
129
+ );
130
+
131
+ export function getDeepSeekLanguageModelEntry(
132
+ modelId: string,
133
+ endpoint: DeepSeekEndpointOptions = {},
134
+ ): DeepSeekLanguageModelEntry {
135
+ const entry = Object.prototype.hasOwnProperty.call(
136
+ deepseekModelCatalog,
137
+ modelId,
138
+ )
139
+ ? deepseekModelCatalog[modelId]
140
+ : createLanguageModelEntry(modelId);
141
+ const { language } = entry.capabilities;
142
+ return {
143
+ ...entry,
144
+ capabilities: {
145
+ language: {
146
+ ...language,
147
+ tools: {
148
+ ...language.tools,
149
+ strict: endpoint.supportsStrictToolCalls ?? 'unknown',
150
+ },
151
+ reasoning: {
152
+ ...language.reasoning,
153
+ configurable: endpoint.supportsThinking !== false,
154
+ },
155
+ sampling: {
156
+ ...language.sampling,
157
+ penalties: endpoint.supportsPenaltySampling === true,
158
+ },
159
+ structuredOutput: {
160
+ jsonSchema: endpoint.supportsStructuredOutputs === true,
161
+ },
162
+ endpoints: {
163
+ assistantPrefixCompletion:
164
+ endpoint.supportsAssistantPrefixCompletion === true,
165
+ },
166
+ },
167
+ },
168
+ };
169
+ }