@ai-sdk/deepseek 3.0.0-beta.20 → 3.0.0-beta.22
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 +19 -0
- package/dist/index.js +105 -116
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/dist/index.d.mts +0 -68
- package/dist/index.mjs +0 -821
- package/dist/index.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @ai-sdk/deepseek
|
|
2
2
|
|
|
3
|
+
## 3.0.0-beta.22
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- ef992f8: Remove CommonJS exports from all packages. All packages are now ESM-only (`"type": "module"`). Consumers using `require()` must switch to ESM `import` syntax.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [ef992f8]
|
|
12
|
+
- @ai-sdk/provider@4.0.0-beta.11
|
|
13
|
+
- @ai-sdk/provider-utils@5.0.0-beta.19
|
|
14
|
+
|
|
15
|
+
## 3.0.0-beta.21
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [90e2d8a]
|
|
20
|
+
- @ai-sdk/provider-utils@5.0.0-beta.18
|
|
21
|
+
|
|
3
22
|
## 3.0.0-beta.20
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1,38 +1,28 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
VERSION: () => VERSION,
|
|
24
|
-
createDeepSeek: () => createDeepSeek,
|
|
25
|
-
deepseek: () => deepseek
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(index_exports);
|
|
28
|
-
|
|
29
1
|
// src/deepseek-provider.ts
|
|
30
|
-
|
|
31
|
-
|
|
2
|
+
import {
|
|
3
|
+
NoSuchModelError
|
|
4
|
+
} from "@ai-sdk/provider";
|
|
5
|
+
import {
|
|
6
|
+
loadApiKey,
|
|
7
|
+
withoutTrailingSlash,
|
|
8
|
+
withUserAgentSuffix
|
|
9
|
+
} from "@ai-sdk/provider-utils";
|
|
32
10
|
|
|
33
11
|
// src/chat/deepseek-chat-language-model.ts
|
|
34
|
-
|
|
35
|
-
|
|
12
|
+
import {
|
|
13
|
+
InvalidResponseDataError
|
|
14
|
+
} from "@ai-sdk/provider";
|
|
15
|
+
import {
|
|
16
|
+
combineHeaders,
|
|
17
|
+
createEventSourceResponseHandler,
|
|
18
|
+
createJsonErrorResponseHandler,
|
|
19
|
+
createJsonResponseHandler,
|
|
20
|
+
generateId,
|
|
21
|
+
isCustomReasoning,
|
|
22
|
+
isParsableJson,
|
|
23
|
+
parseProviderOptions,
|
|
24
|
+
postJsonToApi
|
|
25
|
+
} from "@ai-sdk/provider-utils";
|
|
36
26
|
|
|
37
27
|
// src/chat/convert-to-deepseek-chat-messages.ts
|
|
38
28
|
function convertToDeepSeekChatMessages({
|
|
@@ -216,76 +206,76 @@ function convertDeepSeekUsage(usage) {
|
|
|
216
206
|
}
|
|
217
207
|
|
|
218
208
|
// src/chat/deepseek-chat-api-types.ts
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
var tokenUsageSchema =
|
|
222
|
-
prompt_tokens:
|
|
223
|
-
completion_tokens:
|
|
224
|
-
prompt_cache_hit_tokens:
|
|
225
|
-
prompt_cache_miss_tokens:
|
|
226
|
-
total_tokens:
|
|
227
|
-
completion_tokens_details:
|
|
228
|
-
reasoning_tokens:
|
|
209
|
+
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
210
|
+
import { z } from "zod/v4";
|
|
211
|
+
var tokenUsageSchema = z.object({
|
|
212
|
+
prompt_tokens: z.number().nullish(),
|
|
213
|
+
completion_tokens: z.number().nullish(),
|
|
214
|
+
prompt_cache_hit_tokens: z.number().nullish(),
|
|
215
|
+
prompt_cache_miss_tokens: z.number().nullish(),
|
|
216
|
+
total_tokens: z.number().nullish(),
|
|
217
|
+
completion_tokens_details: z.object({
|
|
218
|
+
reasoning_tokens: z.number().nullish()
|
|
229
219
|
}).nullish()
|
|
230
220
|
}).nullish();
|
|
231
|
-
var deepSeekErrorSchema =
|
|
232
|
-
error:
|
|
233
|
-
message:
|
|
234
|
-
type:
|
|
235
|
-
param:
|
|
236
|
-
code:
|
|
221
|
+
var deepSeekErrorSchema = z.object({
|
|
222
|
+
error: z.object({
|
|
223
|
+
message: z.string(),
|
|
224
|
+
type: z.string().nullish(),
|
|
225
|
+
param: z.any().nullish(),
|
|
226
|
+
code: z.union([z.string(), z.number()]).nullish()
|
|
237
227
|
})
|
|
238
228
|
});
|
|
239
|
-
var deepseekChatResponseSchema =
|
|
240
|
-
id:
|
|
241
|
-
created:
|
|
242
|
-
model:
|
|
243
|
-
choices:
|
|
244
|
-
|
|
245
|
-
message:
|
|
246
|
-
role:
|
|
247
|
-
content:
|
|
248
|
-
reasoning_content:
|
|
249
|
-
tool_calls:
|
|
250
|
-
|
|
251
|
-
id:
|
|
252
|
-
function:
|
|
253
|
-
name:
|
|
254
|
-
arguments:
|
|
229
|
+
var deepseekChatResponseSchema = z.object({
|
|
230
|
+
id: z.string().nullish(),
|
|
231
|
+
created: z.number().nullish(),
|
|
232
|
+
model: z.string().nullish(),
|
|
233
|
+
choices: z.array(
|
|
234
|
+
z.object({
|
|
235
|
+
message: z.object({
|
|
236
|
+
role: z.literal("assistant").nullish(),
|
|
237
|
+
content: z.string().nullish(),
|
|
238
|
+
reasoning_content: z.string().nullish(),
|
|
239
|
+
tool_calls: z.array(
|
|
240
|
+
z.object({
|
|
241
|
+
id: z.string().nullish(),
|
|
242
|
+
function: z.object({
|
|
243
|
+
name: z.string(),
|
|
244
|
+
arguments: z.string()
|
|
255
245
|
})
|
|
256
246
|
})
|
|
257
247
|
).nullish()
|
|
258
248
|
}),
|
|
259
|
-
finish_reason:
|
|
249
|
+
finish_reason: z.string().nullish()
|
|
260
250
|
})
|
|
261
251
|
),
|
|
262
252
|
usage: tokenUsageSchema
|
|
263
253
|
});
|
|
264
|
-
var deepseekChatChunkSchema =
|
|
265
|
-
() =>
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
id:
|
|
269
|
-
created:
|
|
270
|
-
model:
|
|
271
|
-
choices:
|
|
272
|
-
|
|
273
|
-
delta:
|
|
274
|
-
role:
|
|
275
|
-
content:
|
|
276
|
-
reasoning_content:
|
|
277
|
-
tool_calls:
|
|
278
|
-
|
|
279
|
-
index:
|
|
280
|
-
id:
|
|
281
|
-
function:
|
|
282
|
-
name:
|
|
283
|
-
arguments:
|
|
254
|
+
var deepseekChatChunkSchema = lazySchema(
|
|
255
|
+
() => zodSchema(
|
|
256
|
+
z.union([
|
|
257
|
+
z.object({
|
|
258
|
+
id: z.string().nullish(),
|
|
259
|
+
created: z.number().nullish(),
|
|
260
|
+
model: z.string().nullish(),
|
|
261
|
+
choices: z.array(
|
|
262
|
+
z.object({
|
|
263
|
+
delta: z.object({
|
|
264
|
+
role: z.enum(["assistant"]).nullish(),
|
|
265
|
+
content: z.string().nullish(),
|
|
266
|
+
reasoning_content: z.string().nullish(),
|
|
267
|
+
tool_calls: z.array(
|
|
268
|
+
z.object({
|
|
269
|
+
index: z.number(),
|
|
270
|
+
id: z.string().nullish(),
|
|
271
|
+
function: z.object({
|
|
272
|
+
name: z.string().nullish(),
|
|
273
|
+
arguments: z.string().nullish()
|
|
284
274
|
})
|
|
285
275
|
})
|
|
286
276
|
).nullish()
|
|
287
277
|
}).nullish(),
|
|
288
|
-
finish_reason:
|
|
278
|
+
finish_reason: z.string().nullish()
|
|
289
279
|
})
|
|
290
280
|
),
|
|
291
281
|
usage: tokenUsageSchema
|
|
@@ -296,13 +286,13 @@ var deepseekChatChunkSchema = (0, import_provider_utils.lazySchema)(
|
|
|
296
286
|
);
|
|
297
287
|
|
|
298
288
|
// src/chat/deepseek-chat-options.ts
|
|
299
|
-
|
|
300
|
-
var deepseekLanguageModelOptions =
|
|
289
|
+
import { z as z2 } from "zod/v4";
|
|
290
|
+
var deepseekLanguageModelOptions = z2.object({
|
|
301
291
|
/**
|
|
302
292
|
* Type of thinking to use. Defaults to `enabled`.
|
|
303
293
|
*/
|
|
304
|
-
thinking:
|
|
305
|
-
type:
|
|
294
|
+
thinking: z2.object({
|
|
295
|
+
type: z2.enum(["enabled", "disabled"]).optional()
|
|
306
296
|
}).optional()
|
|
307
297
|
});
|
|
308
298
|
|
|
@@ -407,7 +397,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
407
397
|
this.supportedUrls = {};
|
|
408
398
|
this.modelId = modelId;
|
|
409
399
|
this.config = config;
|
|
410
|
-
this.failedResponseHandler =
|
|
400
|
+
this.failedResponseHandler = createJsonErrorResponseHandler({
|
|
411
401
|
errorSchema: deepSeekErrorSchema,
|
|
412
402
|
errorToMessage: (error) => error.error.message
|
|
413
403
|
});
|
|
@@ -435,7 +425,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
435
425
|
tools
|
|
436
426
|
}) {
|
|
437
427
|
var _a, _b;
|
|
438
|
-
const deepseekOptions = (_a = await
|
|
428
|
+
const deepseekOptions = (_a = await parseProviderOptions({
|
|
439
429
|
provider: this.providerOptionsName,
|
|
440
430
|
providerOptions,
|
|
441
431
|
schema: deepseekLanguageModelOptions
|
|
@@ -471,7 +461,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
471
461
|
messages,
|
|
472
462
|
tools: deepseekTools,
|
|
473
463
|
tool_choice: deepseekToolChoices,
|
|
474
|
-
thinking: ((_b = deepseekOptions.thinking) == null ? void 0 : _b.type) != null ? { type: deepseekOptions.thinking.type } :
|
|
464
|
+
thinking: ((_b = deepseekOptions.thinking) == null ? void 0 : _b.type) != null ? { type: deepseekOptions.thinking.type } : isCustomReasoning(reasoning) ? { type: reasoning === "none" ? "disabled" : "enabled" } : void 0
|
|
475
465
|
},
|
|
476
466
|
warnings: [...warnings, ...toolWarnings]
|
|
477
467
|
};
|
|
@@ -483,15 +473,15 @@ var DeepSeekChatLanguageModel = class {
|
|
|
483
473
|
responseHeaders,
|
|
484
474
|
value: responseBody,
|
|
485
475
|
rawValue: rawResponse
|
|
486
|
-
} = await
|
|
476
|
+
} = await postJsonToApi({
|
|
487
477
|
url: this.config.url({
|
|
488
478
|
path: "/chat/completions",
|
|
489
479
|
modelId: this.modelId
|
|
490
480
|
}),
|
|
491
|
-
headers:
|
|
481
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
492
482
|
body: args,
|
|
493
483
|
failedResponseHandler: this.failedResponseHandler,
|
|
494
|
-
successfulResponseHandler:
|
|
484
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
495
485
|
deepseekChatResponseSchema
|
|
496
486
|
),
|
|
497
487
|
abortSignal: options.abortSignal,
|
|
@@ -510,7 +500,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
510
500
|
for (const toolCall of choice.message.tool_calls) {
|
|
511
501
|
content.push({
|
|
512
502
|
type: "tool-call",
|
|
513
|
-
toolCallId: (_a = toolCall.id) != null ? _a :
|
|
503
|
+
toolCallId: (_a = toolCall.id) != null ? _a : generateId(),
|
|
514
504
|
toolName: toolCall.function.name,
|
|
515
505
|
input: toolCall.function.arguments
|
|
516
506
|
});
|
|
@@ -549,15 +539,15 @@ var DeepSeekChatLanguageModel = class {
|
|
|
549
539
|
stream: true,
|
|
550
540
|
stream_options: { include_usage: true }
|
|
551
541
|
};
|
|
552
|
-
const { responseHeaders, value: response } = await
|
|
542
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
553
543
|
url: this.config.url({
|
|
554
544
|
path: "/chat/completions",
|
|
555
545
|
modelId: this.modelId
|
|
556
546
|
}),
|
|
557
|
-
headers:
|
|
547
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
558
548
|
body,
|
|
559
549
|
failedResponseHandler: this.failedResponseHandler,
|
|
560
|
-
successfulResponseHandler:
|
|
550
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
561
551
|
deepseekChatChunkSchema
|
|
562
552
|
),
|
|
563
553
|
abortSignal: options.abortSignal,
|
|
@@ -661,13 +651,13 @@ var DeepSeekChatLanguageModel = class {
|
|
|
661
651
|
const index = toolCallDelta.index;
|
|
662
652
|
if (toolCalls[index] == null) {
|
|
663
653
|
if (toolCallDelta.id == null) {
|
|
664
|
-
throw new
|
|
654
|
+
throw new InvalidResponseDataError({
|
|
665
655
|
data: toolCallDelta,
|
|
666
656
|
message: `Expected 'id' to be a string.`
|
|
667
657
|
});
|
|
668
658
|
}
|
|
669
659
|
if (((_a = toolCallDelta.function) == null ? void 0 : _a.name) == null) {
|
|
670
|
-
throw new
|
|
660
|
+
throw new InvalidResponseDataError({
|
|
671
661
|
data: toolCallDelta,
|
|
672
662
|
message: `Expected 'function.name' to be a string.`
|
|
673
663
|
});
|
|
@@ -695,14 +685,14 @@ var DeepSeekChatLanguageModel = class {
|
|
|
695
685
|
delta: toolCall2.function.arguments
|
|
696
686
|
});
|
|
697
687
|
}
|
|
698
|
-
if (
|
|
688
|
+
if (isParsableJson(toolCall2.function.arguments)) {
|
|
699
689
|
controller.enqueue({
|
|
700
690
|
type: "tool-input-end",
|
|
701
691
|
id: toolCall2.id
|
|
702
692
|
});
|
|
703
693
|
controller.enqueue({
|
|
704
694
|
type: "tool-call",
|
|
705
|
-
toolCallId: (_e = toolCall2.id) != null ? _e :
|
|
695
|
+
toolCallId: (_e = toolCall2.id) != null ? _e : generateId(),
|
|
706
696
|
toolName: toolCall2.function.name,
|
|
707
697
|
input: toolCall2.function.arguments
|
|
708
698
|
});
|
|
@@ -723,14 +713,14 @@ var DeepSeekChatLanguageModel = class {
|
|
|
723
713
|
id: toolCall.id,
|
|
724
714
|
delta: (_i = toolCallDelta.function.arguments) != null ? _i : ""
|
|
725
715
|
});
|
|
726
|
-
if (((_j = toolCall.function) == null ? void 0 : _j.name) != null && ((_k = toolCall.function) == null ? void 0 : _k.arguments) != null &&
|
|
716
|
+
if (((_j = toolCall.function) == null ? void 0 : _j.name) != null && ((_k = toolCall.function) == null ? void 0 : _k.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
727
717
|
controller.enqueue({
|
|
728
718
|
type: "tool-input-end",
|
|
729
719
|
id: toolCall.id
|
|
730
720
|
});
|
|
731
721
|
controller.enqueue({
|
|
732
722
|
type: "tool-call",
|
|
733
|
-
toolCallId: (_l = toolCall.id) != null ? _l :
|
|
723
|
+
toolCallId: (_l = toolCall.id) != null ? _l : generateId(),
|
|
734
724
|
toolName: toolCall.function.name,
|
|
735
725
|
input: toolCall.function.arguments
|
|
736
726
|
});
|
|
@@ -756,7 +746,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
756
746
|
});
|
|
757
747
|
controller.enqueue({
|
|
758
748
|
type: "tool-call",
|
|
759
|
-
toolCallId: (_a = toolCall.id) != null ? _a :
|
|
749
|
+
toolCallId: (_a = toolCall.id) != null ? _a : generateId(),
|
|
760
750
|
toolName: toolCall.function.name,
|
|
761
751
|
input: toolCall.function.arguments
|
|
762
752
|
});
|
|
@@ -782,17 +772,17 @@ var DeepSeekChatLanguageModel = class {
|
|
|
782
772
|
};
|
|
783
773
|
|
|
784
774
|
// src/version.ts
|
|
785
|
-
var VERSION = true ? "3.0.0-beta.
|
|
775
|
+
var VERSION = true ? "3.0.0-beta.22" : "0.0.0-test";
|
|
786
776
|
|
|
787
777
|
// src/deepseek-provider.ts
|
|
788
778
|
function createDeepSeek(options = {}) {
|
|
789
779
|
var _a;
|
|
790
|
-
const baseURL =
|
|
780
|
+
const baseURL = withoutTrailingSlash(
|
|
791
781
|
(_a = options.baseURL) != null ? _a : "https://api.deepseek.com"
|
|
792
782
|
);
|
|
793
|
-
const getHeaders = () =>
|
|
783
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
794
784
|
{
|
|
795
|
-
Authorization: `Bearer ${
|
|
785
|
+
Authorization: `Bearer ${loadApiKey({
|
|
796
786
|
apiKey: options.apiKey,
|
|
797
787
|
environmentVariableName: "DEEPSEEK_API_KEY",
|
|
798
788
|
description: "DeepSeek API key"
|
|
@@ -814,19 +804,18 @@ function createDeepSeek(options = {}) {
|
|
|
814
804
|
provider.languageModel = createLanguageModel;
|
|
815
805
|
provider.chat = createLanguageModel;
|
|
816
806
|
provider.embeddingModel = (modelId) => {
|
|
817
|
-
throw new
|
|
807
|
+
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
818
808
|
};
|
|
819
809
|
provider.textEmbeddingModel = provider.embeddingModel;
|
|
820
810
|
provider.imageModel = (modelId) => {
|
|
821
|
-
throw new
|
|
811
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
822
812
|
};
|
|
823
813
|
return provider;
|
|
824
814
|
}
|
|
825
815
|
var deepseek = createDeepSeek();
|
|
826
|
-
|
|
827
|
-
0 && (module.exports = {
|
|
816
|
+
export {
|
|
828
817
|
VERSION,
|
|
829
818
|
createDeepSeek,
|
|
830
819
|
deepseek
|
|
831
|
-
}
|
|
820
|
+
};
|
|
832
821
|
//# sourceMappingURL=index.js.map
|