@ai-sdk/deepseek 3.0.81 → 3.0.84

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,214 @@
1
+ import { lazySchema, zodSchema } from '@ai-sdk/provider-utils';
2
+ import { z } from 'zod/v4';
3
+
4
+ export type DeepSeekResponsesInput = Array<DeepSeekResponsesInputItem>;
5
+
6
+ export type DeepSeekResponsesInputItem =
7
+ | { role: 'system' | 'assistant'; content: string }
8
+ | { role: 'user'; content: Array<DeepSeekResponsesInputContentPart> }
9
+ | {
10
+ type: 'function_call';
11
+ call_id: string;
12
+ name: string;
13
+ arguments: string;
14
+ }
15
+ | {
16
+ type: 'function_call_output';
17
+ call_id: string;
18
+ output: string | Array<DeepSeekResponsesInputContentPart>;
19
+ }
20
+ | {
21
+ type: 'reasoning';
22
+ id?: string;
23
+ content: Array<{ type: 'reasoning_text'; text: string }>;
24
+ }
25
+ | ({ type: 'web_search_call' } & Record<string, unknown>);
26
+
27
+ export type DeepSeekResponsesInputContentPart =
28
+ | { type: 'input_text'; text: string }
29
+ | {
30
+ type: 'input_image';
31
+ image_url?: string;
32
+ file_id?: string;
33
+ detail?: 'low' | 'high' | 'original' | 'auto';
34
+ };
35
+
36
+ export type DeepSeekResponsesTool =
37
+ | {
38
+ type: 'function';
39
+ name: string;
40
+ description?: string;
41
+ parameters: unknown;
42
+ }
43
+ | { type: 'web_search' };
44
+
45
+ export type DeepSeekResponsesToolChoice =
46
+ | 'auto'
47
+ | 'none'
48
+ | 'required'
49
+ | { type: 'function'; name: string };
50
+
51
+ export type DeepSeekResponsesUsage = z.infer<
52
+ ReturnType<typeof createUsageSchema>
53
+ >;
54
+
55
+ export type DeepSeekResponsesOutputItem = z.infer<
56
+ ReturnType<typeof createOutputItemSchema>
57
+ >;
58
+
59
+ export type DeepSeekResponsesChunk = z.infer<
60
+ ReturnType<typeof createChunkSchema>
61
+ >;
62
+
63
+ export const deepseekResponsesResponseSchema = lazySchema(() =>
64
+ zodSchema(createResponseSchema()),
65
+ );
66
+
67
+ export const deepseekResponsesChunkSchema = lazySchema(() =>
68
+ zodSchema(createChunkSchema()),
69
+ );
70
+
71
+ function createUsageSchema() {
72
+ return z.object({
73
+ input_tokens: z.number().nullish(),
74
+ input_tokens_details: z
75
+ .object({ cached_tokens: z.number().nullish() })
76
+ .nullish(),
77
+ output_tokens: z.number().nullish(),
78
+ output_tokens_details: z
79
+ .object({ reasoning_tokens: z.number().nullish() })
80
+ .nullish(),
81
+ total_tokens: z.number().nullish(),
82
+ server_tool_use: z
83
+ .object({
84
+ tool_search: z.number().nullish(),
85
+ tool_fetch: z.number().nullish(),
86
+ })
87
+ .nullish(),
88
+ });
89
+ }
90
+
91
+ function createLogprobSchema() {
92
+ return z.object({
93
+ token: z.string(),
94
+ logprob: z.number(),
95
+ bytes: z.array(z.number()).nullish(),
96
+ top_logprobs: z
97
+ .array(
98
+ z.object({
99
+ token: z.string(),
100
+ logprob: z.number(),
101
+ bytes: z.array(z.number()).nullish(),
102
+ }),
103
+ )
104
+ .nullish(),
105
+ });
106
+ }
107
+
108
+ function createOutputItemSchema() {
109
+ return z.union([
110
+ z.object({
111
+ type: z.literal('message'),
112
+ id: z.string().nullish(),
113
+ content: z
114
+ .array(
115
+ z.object({
116
+ type: z.string(),
117
+ text: z.string().nullish(),
118
+ logprobs: z.array(createLogprobSchema()).nullish(),
119
+ }),
120
+ )
121
+ .nullish(),
122
+ }),
123
+ z.object({
124
+ type: z.literal('reasoning'),
125
+ id: z.string().nullish(),
126
+ content: z
127
+ .array(z.object({ type: z.string(), text: z.string().nullish() }))
128
+ .nullish(),
129
+ }),
130
+ z.object({
131
+ type: z.literal('function_call'),
132
+ id: z.string().nullish(),
133
+ call_id: z.string(),
134
+ name: z.string(),
135
+ arguments: z.string().nullish(),
136
+ }),
137
+ z.looseObject({
138
+ type: z.literal('web_search_call'),
139
+ id: z.string(),
140
+ status: z.string().nullish(),
141
+ action: z.record(z.string(), z.unknown()).nullish(),
142
+ }),
143
+ z.looseObject({ type: z.string() }),
144
+ ]);
145
+ }
146
+
147
+ function createResponseObjectSchema() {
148
+ return z.object({
149
+ id: z.string().nullish(),
150
+ created_at: z.number().nullish(),
151
+ model: z.string().nullish(),
152
+ status: z.string().nullish(),
153
+ error: z
154
+ .object({
155
+ code: z.string().nullish(),
156
+ message: z.string().nullish(),
157
+ })
158
+ .nullish(),
159
+ incomplete_details: z.object({ reason: z.string().nullish() }).nullish(),
160
+ output: z.array(createOutputItemSchema()).nullish(),
161
+ usage: createUsageSchema().nullish(),
162
+ });
163
+ }
164
+
165
+ function createResponseSchema() {
166
+ return createResponseObjectSchema();
167
+ }
168
+
169
+ function createChunkSchema() {
170
+ const responseObject = createResponseObjectSchema();
171
+ const outputItem = createOutputItemSchema();
172
+
173
+ return z.union([
174
+ z.object({
175
+ type: z.enum(['response.created', 'response.in_progress']),
176
+ response: responseObject,
177
+ }),
178
+ z.object({
179
+ type: z.enum([
180
+ 'response.completed',
181
+ 'response.incomplete',
182
+ 'response.failed',
183
+ ]),
184
+ response: responseObject,
185
+ }),
186
+ z.object({
187
+ type: z.enum(['response.output_item.added', 'response.output_item.done']),
188
+ output_index: z.number().nullish(),
189
+ item: outputItem,
190
+ }),
191
+ z.object({
192
+ type: z.literal('response.output_text.delta'),
193
+ item_id: z.string(),
194
+ delta: z.string(),
195
+ logprobs: z.array(createLogprobSchema()).nullish(),
196
+ }),
197
+ z.object({
198
+ type: z.literal('response.reasoning_text.delta'),
199
+ item_id: z.string(),
200
+ delta: z.string(),
201
+ }),
202
+ z.object({
203
+ type: z.literal('response.function_call_arguments.delta'),
204
+ item_id: z.string(),
205
+ delta: z.string(),
206
+ }),
207
+ z.object({
208
+ type: z.literal('error'),
209
+ code: z.string().nullish(),
210
+ message: z.string().nullish(),
211
+ }),
212
+ z.looseObject({ type: z.string() }),
213
+ ]);
214
+ }
@@ -0,0 +1,54 @@
1
+ import { lazySchema, zodSchema } from '@ai-sdk/provider-utils';
2
+ import { z } from 'zod/v4';
3
+
4
+ // https://api-docs.deepseek.com/api/create-response
5
+ export type DeepSeekResponsesModelId =
6
+ | 'deepseek-flash'
7
+ | 'deepseek-v4-pro'
8
+ | (string & {});
9
+
10
+ export const deepseekLanguageModelResponsesOptions = lazySchema(() =>
11
+ zodSchema(
12
+ z.object({
13
+ thinking: z
14
+ .object({ type: z.enum(['enabled', 'disabled']).optional() })
15
+ .optional(),
16
+ reasoningEffort: z.enum(['low', 'high', 'max']).optional(),
17
+ topLogprobs: z.number().int().min(0).max(20).optional(),
18
+ userId: z
19
+ .string()
20
+ .regex(/^[a-zA-Z0-9_-]+$/, 'userId must match /^[a-zA-Z0-9_-]+$/')
21
+ .max(512, 'userId must be at most 512 characters long')
22
+ .optional(),
23
+ }),
24
+ ),
25
+ );
26
+
27
+ export type DeepSeekLanguageModelResponsesOptions = {
28
+ /**
29
+ * Controls whether thinking mode is enabled. Thinking is enabled by default.
30
+ */
31
+ thinking?: {
32
+ type?: 'enabled' | 'disabled';
33
+ };
34
+
35
+ /**
36
+ * Controls the thinking strength when thinking is enabled.
37
+ */
38
+ reasoningEffort?: 'low' | 'high' | 'max';
39
+
40
+ /**
41
+ * Number of most likely tokens to return at each token position (0 to 20).
42
+ * Log probabilities are returned in `providerMetadata.deepseek.logprobs`.
43
+ */
44
+ topLogprobs?: number;
45
+
46
+ /**
47
+ * An opaque identifier for the end user. DeepSeek uses this identifier for
48
+ * content-safety tracing and request isolation.
49
+ *
50
+ * Must contain only ASCII letters, numbers, underscores, and hyphens, and
51
+ * must be at most 512 characters long.
52
+ */
53
+ userId?: string;
54
+ };