@ai-sdk/deepseek 3.0.80 → 3.0.83

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.
@@ -0,0 +1,87 @@
1
+ import type {
2
+ LanguageModelV4CallOptions,
3
+ SharedV4Warning,
4
+ } from '@ai-sdk/provider';
5
+ import type {
6
+ DeepSeekResponsesTool,
7
+ DeepSeekResponsesToolChoice,
8
+ } from './deepseek-responses-api';
9
+
10
+ export function prepareDeepSeekResponsesTools({
11
+ tools,
12
+ toolChoice,
13
+ }: {
14
+ tools: LanguageModelV4CallOptions['tools'];
15
+ toolChoice?: LanguageModelV4CallOptions['toolChoice'];
16
+ }): {
17
+ tools: Array<DeepSeekResponsesTool> | undefined;
18
+ toolChoice: DeepSeekResponsesToolChoice | undefined;
19
+ toolWarnings: SharedV4Warning[];
20
+ } {
21
+ const toolWarnings: SharedV4Warning[] = [];
22
+
23
+ if (tools == null || tools.length === 0) {
24
+ return { tools: undefined, toolChoice: undefined, toolWarnings };
25
+ }
26
+
27
+ const deepseekTools: Array<DeepSeekResponsesTool> = [];
28
+
29
+ for (const tool of tools) {
30
+ if (tool.type === 'provider') {
31
+ if (tool.id === 'deepseek.web_search') {
32
+ deepseekTools.push({ type: 'web_search' });
33
+ } else {
34
+ toolWarnings.push({
35
+ type: 'unsupported',
36
+ feature: `provider-defined tool ${tool.id}`,
37
+ });
38
+ }
39
+ continue;
40
+ }
41
+
42
+ if (tool.strict != null) {
43
+ toolWarnings.push({
44
+ type: 'unsupported',
45
+ feature: 'strict tool calls',
46
+ details: 'The DeepSeek Responses API does not support strict mode.',
47
+ });
48
+ }
49
+
50
+ deepseekTools.push({
51
+ type: 'function',
52
+ name: tool.name,
53
+ description: tool.description,
54
+ parameters: tool.inputSchema,
55
+ });
56
+ }
57
+
58
+ if (toolChoice == null) {
59
+ return { tools: deepseekTools, toolChoice: undefined, toolWarnings };
60
+ }
61
+
62
+ switch (toolChoice.type) {
63
+ case 'auto':
64
+ case 'none':
65
+ case 'required':
66
+ return {
67
+ tools: deepseekTools,
68
+ toolChoice: toolChoice.type,
69
+ toolWarnings,
70
+ };
71
+ case 'tool': {
72
+ const selected = tools.find(tool => tool.name === toolChoice.toolName);
73
+ if (selected?.type === 'provider') {
74
+ toolWarnings.push({
75
+ type: 'unsupported',
76
+ feature: `toolChoice for provider-defined tool ${selected.id}`,
77
+ });
78
+ return { tools: deepseekTools, toolChoice: undefined, toolWarnings };
79
+ }
80
+ return {
81
+ tools: deepseekTools,
82
+ toolChoice: { type: 'function', name: toolChoice.toolName },
83
+ toolWarnings,
84
+ };
85
+ }
86
+ }
87
+ }
@@ -0,0 +1,26 @@
1
+ import type { LanguageModelV4FinishReason } from '@ai-sdk/provider';
2
+
3
+ export function mapDeepSeekResponsesFinishReason({
4
+ status,
5
+ incompleteReason,
6
+ hasFunctionCall,
7
+ }: {
8
+ status: string | null | undefined;
9
+ incompleteReason: string | null | undefined;
10
+ hasFunctionCall: boolean;
11
+ }): LanguageModelV4FinishReason['unified'] {
12
+ switch (status) {
13
+ case 'completed':
14
+ return hasFunctionCall ? 'tool-calls' : 'stop';
15
+ case 'incomplete':
16
+ return incompleteReason === 'max_output_tokens'
17
+ ? 'length'
18
+ : incompleteReason === 'content_filter'
19
+ ? 'content-filter'
20
+ : 'other';
21
+ case 'failed':
22
+ return 'error';
23
+ default:
24
+ return 'other';
25
+ }
26
+ }
@@ -0,0 +1,7 @@
1
+ import { webSearch } from './web-search';
2
+
3
+ export { webSearch };
4
+
5
+ export const deepseekTools = {
6
+ webSearch,
7
+ };
@@ -0,0 +1,47 @@
1
+ import {
2
+ createProviderExecutedToolFactory,
3
+ lazySchema,
4
+ zodSchema,
5
+ } from '@ai-sdk/provider-utils';
6
+ import { z } from 'zod/v4';
7
+
8
+ export const webSearchOutputSchema = lazySchema(() =>
9
+ zodSchema(
10
+ z.object({
11
+ status: z.string().optional(),
12
+ action: z.record(z.string(), z.unknown()).optional(),
13
+ }),
14
+ ),
15
+ );
16
+
17
+ const webSearchToolFactory = createProviderExecutedToolFactory<
18
+ {},
19
+ {
20
+ /**
21
+ * Status of the server-side web search call.
22
+ */
23
+ status?: string;
24
+
25
+ /**
26
+ * The search action reported by DeepSeek, such as the query that was run.
27
+ */
28
+ action?: Record<string, unknown>;
29
+ },
30
+ {}
31
+ >({
32
+ id: 'deepseek.web_search',
33
+ inputSchema: lazySchema(() => zodSchema(z.object({}))),
34
+ outputSchema: webSearchOutputSchema,
35
+ });
36
+
37
+ /**
38
+ * DeepSeek's server-side web search for the Responses API. DeepSeek runs the
39
+ * searches and page reads during generation and adds the results to the
40
+ * model context. Supported with `deepseek-v4-pro`.
41
+ *
42
+ * Successful searches and page reads are billed per operation and reported in
43
+ * `usage.raw.server_tool_use` and `providerMetadata.deepseek.serverToolUse`.
44
+ */
45
+ export const webSearch = (
46
+ args: Parameters<typeof webSearchToolFactory>[0] = {},
47
+ ) => webSearchToolFactory(args);