@ai-sdk/deepseek 3.0.0-beta.5 → 3.0.0-beta.55
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 +410 -4
- package/README.md +2 -0
- package/dist/index.d.ts +12 -4
- package/dist/index.js +169 -225
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +57 -0
- package/dist/{index.mjs → internal/index.js} +83 -182
- package/dist/internal/index.js.map +1 -0
- package/docs/30-deepseek.mdx +31 -19
- package/internal.d.ts +1 -0
- package/package.json +21 -15
- package/src/chat/convert-to-deepseek-chat-messages.ts +11 -5
- package/src/chat/convert-to-deepseek-usage.ts +1 -1
- package/src/chat/deepseek-chat-language-model-options.ts +34 -0
- package/src/chat/deepseek-chat-language-model.ts +77 -154
- package/src/chat/deepseek-prepare-tools.ts +5 -2
- package/src/chat/map-deepseek-finish-reason.ts +1 -1
- package/src/deepseek-provider.ts +5 -5
- package/src/index.ts +12 -5
- package/src/internal/index.ts +2 -0
- package/dist/index.d.mts +0 -68
- package/dist/index.mjs.map +0 -1
- package/src/chat/deepseek-chat-options.ts +0 -22
package/dist/index.js
CHANGED
|
@@ -1,45 +1,38 @@
|
|
|
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
|
+
combineHeaders,
|
|
14
|
+
createEventSourceResponseHandler,
|
|
15
|
+
createJsonErrorResponseHandler,
|
|
16
|
+
createJsonResponseHandler,
|
|
17
|
+
generateId,
|
|
18
|
+
isCustomReasoning,
|
|
19
|
+
mapReasoningToProviderEffort,
|
|
20
|
+
parseProviderOptions,
|
|
21
|
+
postJsonToApi,
|
|
22
|
+
serializeModelOptions,
|
|
23
|
+
StreamingToolCallTracker,
|
|
24
|
+
WORKFLOW_SERIALIZE,
|
|
25
|
+
WORKFLOW_DESERIALIZE
|
|
26
|
+
} from "@ai-sdk/provider-utils";
|
|
36
27
|
|
|
37
28
|
// src/chat/convert-to-deepseek-chat-messages.ts
|
|
38
29
|
function convertToDeepSeekChatMessages({
|
|
39
30
|
prompt,
|
|
40
|
-
responseFormat
|
|
31
|
+
responseFormat,
|
|
32
|
+
modelId
|
|
41
33
|
}) {
|
|
42
34
|
var _a;
|
|
35
|
+
const isDeepSeekV4 = modelId.includes("deepseek-v4");
|
|
43
36
|
const messages = [];
|
|
44
37
|
const warnings = [];
|
|
45
38
|
if ((responseFormat == null ? void 0 : responseFormat.type) === "json") {
|
|
@@ -104,7 +97,7 @@ function convertToDeepSeekChatMessages({
|
|
|
104
97
|
break;
|
|
105
98
|
}
|
|
106
99
|
case "reasoning": {
|
|
107
|
-
if (index <= lastUserMessageIndex) {
|
|
100
|
+
if (index <= lastUserMessageIndex && !isDeepSeekV4) {
|
|
108
101
|
break;
|
|
109
102
|
}
|
|
110
103
|
if (reasoning == null) {
|
|
@@ -130,7 +123,7 @@ function convertToDeepSeekChatMessages({
|
|
|
130
123
|
messages.push({
|
|
131
124
|
role: "assistant",
|
|
132
125
|
content: text,
|
|
133
|
-
reasoning_content: reasoning,
|
|
126
|
+
reasoning_content: reasoning != null ? reasoning : isDeepSeekV4 ? "" : void 0,
|
|
134
127
|
tool_calls: toolCalls.length > 0 ? toolCalls : void 0
|
|
135
128
|
});
|
|
136
129
|
break;
|
|
@@ -148,7 +141,7 @@ function convertToDeepSeekChatMessages({
|
|
|
148
141
|
contentValue = output.value;
|
|
149
142
|
break;
|
|
150
143
|
case "execution-denied":
|
|
151
|
-
contentValue = (_a = output.reason) != null ? _a : "Tool execution denied.";
|
|
144
|
+
contentValue = (_a = output.reason) != null ? _a : "Tool call execution denied.";
|
|
152
145
|
break;
|
|
153
146
|
case "content":
|
|
154
147
|
case "json":
|
|
@@ -216,76 +209,76 @@ function convertDeepSeekUsage(usage) {
|
|
|
216
209
|
}
|
|
217
210
|
|
|
218
211
|
// 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:
|
|
212
|
+
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
213
|
+
import { z } from "zod/v4";
|
|
214
|
+
var tokenUsageSchema = z.object({
|
|
215
|
+
prompt_tokens: z.number().nullish(),
|
|
216
|
+
completion_tokens: z.number().nullish(),
|
|
217
|
+
prompt_cache_hit_tokens: z.number().nullish(),
|
|
218
|
+
prompt_cache_miss_tokens: z.number().nullish(),
|
|
219
|
+
total_tokens: z.number().nullish(),
|
|
220
|
+
completion_tokens_details: z.object({
|
|
221
|
+
reasoning_tokens: z.number().nullish()
|
|
229
222
|
}).nullish()
|
|
230
223
|
}).nullish();
|
|
231
|
-
var deepSeekErrorSchema =
|
|
232
|
-
error:
|
|
233
|
-
message:
|
|
234
|
-
type:
|
|
235
|
-
param:
|
|
236
|
-
code:
|
|
224
|
+
var deepSeekErrorSchema = z.object({
|
|
225
|
+
error: z.object({
|
|
226
|
+
message: z.string(),
|
|
227
|
+
type: z.string().nullish(),
|
|
228
|
+
param: z.any().nullish(),
|
|
229
|
+
code: z.union([z.string(), z.number()]).nullish()
|
|
237
230
|
})
|
|
238
231
|
});
|
|
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:
|
|
232
|
+
var deepseekChatResponseSchema = z.object({
|
|
233
|
+
id: z.string().nullish(),
|
|
234
|
+
created: z.number().nullish(),
|
|
235
|
+
model: z.string().nullish(),
|
|
236
|
+
choices: z.array(
|
|
237
|
+
z.object({
|
|
238
|
+
message: z.object({
|
|
239
|
+
role: z.literal("assistant").nullish(),
|
|
240
|
+
content: z.string().nullish(),
|
|
241
|
+
reasoning_content: z.string().nullish(),
|
|
242
|
+
tool_calls: z.array(
|
|
243
|
+
z.object({
|
|
244
|
+
id: z.string().nullish(),
|
|
245
|
+
function: z.object({
|
|
246
|
+
name: z.string(),
|
|
247
|
+
arguments: z.string()
|
|
255
248
|
})
|
|
256
249
|
})
|
|
257
250
|
).nullish()
|
|
258
251
|
}),
|
|
259
|
-
finish_reason:
|
|
252
|
+
finish_reason: z.string().nullish()
|
|
260
253
|
})
|
|
261
254
|
),
|
|
262
255
|
usage: tokenUsageSchema
|
|
263
256
|
});
|
|
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:
|
|
257
|
+
var deepseekChatChunkSchema = lazySchema(
|
|
258
|
+
() => zodSchema(
|
|
259
|
+
z.union([
|
|
260
|
+
z.object({
|
|
261
|
+
id: z.string().nullish(),
|
|
262
|
+
created: z.number().nullish(),
|
|
263
|
+
model: z.string().nullish(),
|
|
264
|
+
choices: z.array(
|
|
265
|
+
z.object({
|
|
266
|
+
delta: z.object({
|
|
267
|
+
role: z.enum(["assistant"]).nullish(),
|
|
268
|
+
content: z.string().nullish(),
|
|
269
|
+
reasoning_content: z.string().nullish(),
|
|
270
|
+
tool_calls: z.array(
|
|
271
|
+
z.object({
|
|
272
|
+
index: z.number(),
|
|
273
|
+
id: z.string().nullish(),
|
|
274
|
+
function: z.object({
|
|
275
|
+
name: z.string().nullish(),
|
|
276
|
+
arguments: z.string().nullish()
|
|
284
277
|
})
|
|
285
278
|
})
|
|
286
279
|
).nullish()
|
|
287
280
|
}).nullish(),
|
|
288
|
-
finish_reason:
|
|
281
|
+
finish_reason: z.string().nullish()
|
|
289
282
|
})
|
|
290
283
|
),
|
|
291
284
|
usage: tokenUsageSchema
|
|
@@ -295,15 +288,26 @@ var deepseekChatChunkSchema = (0, import_provider_utils.lazySchema)(
|
|
|
295
288
|
)
|
|
296
289
|
);
|
|
297
290
|
|
|
298
|
-
// src/chat/deepseek-chat-options.ts
|
|
299
|
-
|
|
300
|
-
var
|
|
291
|
+
// src/chat/deepseek-chat-language-model-options.ts
|
|
292
|
+
import { z as z2 } from "zod/v4";
|
|
293
|
+
var deepseekLanguageModelChatOptions = z2.object({
|
|
301
294
|
/**
|
|
302
295
|
* Type of thinking to use. Defaults to `enabled`.
|
|
296
|
+
*
|
|
297
|
+
* See https://api-docs.deepseek.com/guides/thinking_mode for the
|
|
298
|
+
* `adaptive` option, which lets the model decide when to think.
|
|
299
|
+
*/
|
|
300
|
+
thinking: z2.object({
|
|
301
|
+
type: z2.enum(["adaptive", "enabled", "disabled"]).optional()
|
|
302
|
+
}).optional(),
|
|
303
|
+
/**
|
|
304
|
+
* Controls the thinking strength for DeepSeek V4 reasoning models.
|
|
305
|
+
*
|
|
306
|
+
* DeepSeek's API accepts `low`, `medium`, `high`, `xhigh`, and `max`.
|
|
307
|
+
* Per their docs, `low` and `medium` are mapped to `high`, and `xhigh`
|
|
308
|
+
* is mapped to `max` server-side for compatibility with other providers.
|
|
303
309
|
*/
|
|
304
|
-
|
|
305
|
-
type: import_v42.z.enum(["enabled", "disabled"]).optional()
|
|
306
|
-
}).optional()
|
|
310
|
+
reasoningEffort: z2.enum(["low", "medium", "high", "xhigh", "max"]).optional()
|
|
307
311
|
});
|
|
308
312
|
|
|
309
313
|
// src/chat/deepseek-prepare-tools.ts
|
|
@@ -401,17 +405,26 @@ function mapDeepSeekFinishReason(finishReason) {
|
|
|
401
405
|
}
|
|
402
406
|
|
|
403
407
|
// src/chat/deepseek-chat-language-model.ts
|
|
404
|
-
var DeepSeekChatLanguageModel = class {
|
|
408
|
+
var DeepSeekChatLanguageModel = class _DeepSeekChatLanguageModel {
|
|
405
409
|
constructor(modelId, config) {
|
|
406
410
|
this.specificationVersion = "v4";
|
|
407
411
|
this.supportedUrls = {};
|
|
408
412
|
this.modelId = modelId;
|
|
409
413
|
this.config = config;
|
|
410
|
-
this.failedResponseHandler =
|
|
414
|
+
this.failedResponseHandler = createJsonErrorResponseHandler({
|
|
411
415
|
errorSchema: deepSeekErrorSchema,
|
|
412
416
|
errorToMessage: (error) => error.error.message
|
|
413
417
|
});
|
|
414
418
|
}
|
|
419
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
420
|
+
return serializeModelOptions({
|
|
421
|
+
modelId: model.modelId,
|
|
422
|
+
config: model.config
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
426
|
+
return new _DeepSeekChatLanguageModel(options.modelId, options.config);
|
|
427
|
+
}
|
|
415
428
|
get provider() {
|
|
416
429
|
return this.config.provider;
|
|
417
430
|
}
|
|
@@ -426,6 +439,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
426
439
|
topK,
|
|
427
440
|
frequencyPenalty,
|
|
428
441
|
presencePenalty,
|
|
442
|
+
reasoning,
|
|
429
443
|
providerOptions,
|
|
430
444
|
stopSequences,
|
|
431
445
|
responseFormat,
|
|
@@ -433,21 +447,23 @@ var DeepSeekChatLanguageModel = class {
|
|
|
433
447
|
toolChoice,
|
|
434
448
|
tools
|
|
435
449
|
}) {
|
|
436
|
-
var _a, _b;
|
|
437
|
-
const deepseekOptions = (_a = await
|
|
450
|
+
var _a, _b, _c;
|
|
451
|
+
const deepseekOptions = (_a = await parseProviderOptions({
|
|
438
452
|
provider: this.providerOptionsName,
|
|
439
453
|
providerOptions,
|
|
440
|
-
schema:
|
|
454
|
+
schema: deepseekLanguageModelChatOptions
|
|
441
455
|
})) != null ? _a : {};
|
|
442
456
|
const { messages, warnings } = convertToDeepSeekChatMessages({
|
|
443
457
|
prompt,
|
|
444
|
-
responseFormat
|
|
458
|
+
responseFormat,
|
|
459
|
+
modelId: this.modelId
|
|
445
460
|
});
|
|
461
|
+
const allWarnings = [...warnings];
|
|
446
462
|
if (topK != null) {
|
|
447
|
-
|
|
463
|
+
allWarnings.push({ type: "unsupported", feature: "topK" });
|
|
448
464
|
}
|
|
449
465
|
if (seed != null) {
|
|
450
|
-
|
|
466
|
+
allWarnings.push({ type: "unsupported", feature: "seed" });
|
|
451
467
|
}
|
|
452
468
|
const {
|
|
453
469
|
tools: deepseekTools,
|
|
@@ -457,6 +473,18 @@ var DeepSeekChatLanguageModel = class {
|
|
|
457
473
|
tools,
|
|
458
474
|
toolChoice
|
|
459
475
|
});
|
|
476
|
+
const thinking = this.config.supportsThinking === false ? void 0 : ((_b = deepseekOptions.thinking) == null ? void 0 : _b.type) != null ? { type: deepseekOptions.thinking.type } : isCustomReasoning(reasoning) ? { type: reasoning === "none" ? "disabled" : "enabled" } : void 0;
|
|
477
|
+
const reasoningEffort = (_c = deepseekOptions.reasoningEffort) != null ? _c : isCustomReasoning(reasoning) && reasoning !== "none" ? mapReasoningToProviderEffort({
|
|
478
|
+
reasoning,
|
|
479
|
+
effortMap: {
|
|
480
|
+
minimal: "low",
|
|
481
|
+
low: "low",
|
|
482
|
+
medium: "medium",
|
|
483
|
+
high: "high",
|
|
484
|
+
xhigh: "max"
|
|
485
|
+
},
|
|
486
|
+
warnings: allWarnings
|
|
487
|
+
}) : void 0;
|
|
460
488
|
return {
|
|
461
489
|
args: {
|
|
462
490
|
model: this.modelId,
|
|
@@ -470,27 +498,30 @@ var DeepSeekChatLanguageModel = class {
|
|
|
470
498
|
messages,
|
|
471
499
|
tools: deepseekTools,
|
|
472
500
|
tool_choice: deepseekToolChoices,
|
|
473
|
-
thinking
|
|
501
|
+
thinking,
|
|
502
|
+
...(thinking == null ? void 0 : thinking.type) !== "disabled" && reasoningEffort != null && {
|
|
503
|
+
reasoning_effort: reasoningEffort
|
|
504
|
+
}
|
|
474
505
|
},
|
|
475
|
-
warnings: [...
|
|
506
|
+
warnings: [...allWarnings, ...toolWarnings]
|
|
476
507
|
};
|
|
477
508
|
}
|
|
478
509
|
async doGenerate(options) {
|
|
479
|
-
var _a, _b, _c, _d;
|
|
510
|
+
var _a, _b, _c, _d, _e, _f;
|
|
480
511
|
const { args, warnings } = await this.getArgs({ ...options });
|
|
481
512
|
const {
|
|
482
513
|
responseHeaders,
|
|
483
514
|
value: responseBody,
|
|
484
515
|
rawValue: rawResponse
|
|
485
|
-
} = await
|
|
516
|
+
} = await postJsonToApi({
|
|
486
517
|
url: this.config.url({
|
|
487
518
|
path: "/chat/completions",
|
|
488
519
|
modelId: this.modelId
|
|
489
520
|
}),
|
|
490
|
-
headers: (
|
|
521
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
491
522
|
body: args,
|
|
492
523
|
failedResponseHandler: this.failedResponseHandler,
|
|
493
|
-
successfulResponseHandler:
|
|
524
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
494
525
|
deepseekChatResponseSchema
|
|
495
526
|
),
|
|
496
527
|
abortSignal: options.abortSignal,
|
|
@@ -509,7 +540,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
509
540
|
for (const toolCall of choice.message.tool_calls) {
|
|
510
541
|
content.push({
|
|
511
542
|
type: "tool-call",
|
|
512
|
-
toolCallId: (
|
|
543
|
+
toolCallId: (_c = toolCall.id) != null ? _c : generateId(),
|
|
513
544
|
toolName: toolCall.function.name,
|
|
514
545
|
input: toolCall.function.arguments
|
|
515
546
|
});
|
|
@@ -523,13 +554,13 @@ var DeepSeekChatLanguageModel = class {
|
|
|
523
554
|
content,
|
|
524
555
|
finishReason: {
|
|
525
556
|
unified: mapDeepSeekFinishReason(choice.finish_reason),
|
|
526
|
-
raw: (
|
|
557
|
+
raw: (_d = choice.finish_reason) != null ? _d : void 0
|
|
527
558
|
},
|
|
528
559
|
usage: convertDeepSeekUsage(responseBody.usage),
|
|
529
560
|
providerMetadata: {
|
|
530
561
|
[this.providerOptionsName]: {
|
|
531
|
-
promptCacheHitTokens: (
|
|
532
|
-
promptCacheMissTokens: (
|
|
562
|
+
promptCacheHitTokens: (_e = responseBody.usage) == null ? void 0 : _e.prompt_cache_hit_tokens,
|
|
563
|
+
promptCacheMissTokens: (_f = responseBody.usage) == null ? void 0 : _f.prompt_cache_miss_tokens
|
|
533
564
|
}
|
|
534
565
|
},
|
|
535
566
|
request: { body: args },
|
|
@@ -542,27 +573,28 @@ var DeepSeekChatLanguageModel = class {
|
|
|
542
573
|
};
|
|
543
574
|
}
|
|
544
575
|
async doStream(options) {
|
|
576
|
+
var _a, _b;
|
|
545
577
|
const { args, warnings } = await this.getArgs({ ...options });
|
|
546
578
|
const body = {
|
|
547
579
|
...args,
|
|
548
580
|
stream: true,
|
|
549
581
|
stream_options: { include_usage: true }
|
|
550
582
|
};
|
|
551
|
-
const { responseHeaders, value: response } = await
|
|
583
|
+
const { responseHeaders, value: response } = await postJsonToApi({
|
|
552
584
|
url: this.config.url({
|
|
553
585
|
path: "/chat/completions",
|
|
554
586
|
modelId: this.modelId
|
|
555
587
|
}),
|
|
556
|
-
headers: (
|
|
588
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
557
589
|
body,
|
|
558
590
|
failedResponseHandler: this.failedResponseHandler,
|
|
559
|
-
successfulResponseHandler:
|
|
591
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
560
592
|
deepseekChatChunkSchema
|
|
561
593
|
),
|
|
562
594
|
abortSignal: options.abortSignal,
|
|
563
595
|
fetch: this.config.fetch
|
|
564
596
|
});
|
|
565
|
-
|
|
597
|
+
let toolCallTracker;
|
|
566
598
|
let finishReason = {
|
|
567
599
|
unified: "other",
|
|
568
600
|
raw: void 0
|
|
@@ -576,10 +608,12 @@ var DeepSeekChatLanguageModel = class {
|
|
|
576
608
|
stream: response.pipeThrough(
|
|
577
609
|
new TransformStream({
|
|
578
610
|
start(controller) {
|
|
611
|
+
toolCallTracker = new StreamingToolCallTracker(controller, {
|
|
612
|
+
generateId
|
|
613
|
+
});
|
|
579
614
|
controller.enqueue({ type: "stream-start", warnings });
|
|
580
615
|
},
|
|
581
616
|
transform(chunk, controller) {
|
|
582
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
583
617
|
if (options.includeRawChunks) {
|
|
584
618
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
585
619
|
}
|
|
@@ -657,117 +691,27 @@ var DeepSeekChatLanguageModel = class {
|
|
|
657
691
|
isActiveReasoning = false;
|
|
658
692
|
}
|
|
659
693
|
for (const toolCallDelta of delta.tool_calls) {
|
|
660
|
-
|
|
661
|
-
if (toolCalls[index] == null) {
|
|
662
|
-
if (toolCallDelta.id == null) {
|
|
663
|
-
throw new import_provider.InvalidResponseDataError({
|
|
664
|
-
data: toolCallDelta,
|
|
665
|
-
message: `Expected 'id' to be a string.`
|
|
666
|
-
});
|
|
667
|
-
}
|
|
668
|
-
if (((_a = toolCallDelta.function) == null ? void 0 : _a.name) == null) {
|
|
669
|
-
throw new import_provider.InvalidResponseDataError({
|
|
670
|
-
data: toolCallDelta,
|
|
671
|
-
message: `Expected 'function.name' to be a string.`
|
|
672
|
-
});
|
|
673
|
-
}
|
|
674
|
-
controller.enqueue({
|
|
675
|
-
type: "tool-input-start",
|
|
676
|
-
id: toolCallDelta.id,
|
|
677
|
-
toolName: toolCallDelta.function.name
|
|
678
|
-
});
|
|
679
|
-
toolCalls[index] = {
|
|
680
|
-
id: toolCallDelta.id,
|
|
681
|
-
type: "function",
|
|
682
|
-
function: {
|
|
683
|
-
name: toolCallDelta.function.name,
|
|
684
|
-
arguments: (_b = toolCallDelta.function.arguments) != null ? _b : ""
|
|
685
|
-
},
|
|
686
|
-
hasFinished: false
|
|
687
|
-
};
|
|
688
|
-
const toolCall2 = toolCalls[index];
|
|
689
|
-
if (((_c = toolCall2.function) == null ? void 0 : _c.name) != null && ((_d = toolCall2.function) == null ? void 0 : _d.arguments) != null) {
|
|
690
|
-
if (toolCall2.function.arguments.length > 0) {
|
|
691
|
-
controller.enqueue({
|
|
692
|
-
type: "tool-input-delta",
|
|
693
|
-
id: toolCall2.id,
|
|
694
|
-
delta: toolCall2.function.arguments
|
|
695
|
-
});
|
|
696
|
-
}
|
|
697
|
-
if ((0, import_provider_utils2.isParsableJson)(toolCall2.function.arguments)) {
|
|
698
|
-
controller.enqueue({
|
|
699
|
-
type: "tool-input-end",
|
|
700
|
-
id: toolCall2.id
|
|
701
|
-
});
|
|
702
|
-
controller.enqueue({
|
|
703
|
-
type: "tool-call",
|
|
704
|
-
toolCallId: (_e = toolCall2.id) != null ? _e : (0, import_provider_utils2.generateId)(),
|
|
705
|
-
toolName: toolCall2.function.name,
|
|
706
|
-
input: toolCall2.function.arguments
|
|
707
|
-
});
|
|
708
|
-
toolCall2.hasFinished = true;
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
continue;
|
|
712
|
-
}
|
|
713
|
-
const toolCall = toolCalls[index];
|
|
714
|
-
if (toolCall.hasFinished) {
|
|
715
|
-
continue;
|
|
716
|
-
}
|
|
717
|
-
if (((_f = toolCallDelta.function) == null ? void 0 : _f.arguments) != null) {
|
|
718
|
-
toolCall.function.arguments += (_h = (_g = toolCallDelta.function) == null ? void 0 : _g.arguments) != null ? _h : "";
|
|
719
|
-
}
|
|
720
|
-
controller.enqueue({
|
|
721
|
-
type: "tool-input-delta",
|
|
722
|
-
id: toolCall.id,
|
|
723
|
-
delta: (_i = toolCallDelta.function.arguments) != null ? _i : ""
|
|
724
|
-
});
|
|
725
|
-
if (((_j = toolCall.function) == null ? void 0 : _j.name) != null && ((_k = toolCall.function) == null ? void 0 : _k.arguments) != null && (0, import_provider_utils2.isParsableJson)(toolCall.function.arguments)) {
|
|
726
|
-
controller.enqueue({
|
|
727
|
-
type: "tool-input-end",
|
|
728
|
-
id: toolCall.id
|
|
729
|
-
});
|
|
730
|
-
controller.enqueue({
|
|
731
|
-
type: "tool-call",
|
|
732
|
-
toolCallId: (_l = toolCall.id) != null ? _l : (0, import_provider_utils2.generateId)(),
|
|
733
|
-
toolName: toolCall.function.name,
|
|
734
|
-
input: toolCall.function.arguments
|
|
735
|
-
});
|
|
736
|
-
toolCall.hasFinished = true;
|
|
737
|
-
}
|
|
694
|
+
toolCallTracker.processDelta(toolCallDelta);
|
|
738
695
|
}
|
|
739
696
|
}
|
|
740
697
|
},
|
|
741
698
|
flush(controller) {
|
|
742
|
-
var
|
|
699
|
+
var _a2, _b2;
|
|
743
700
|
if (isActiveReasoning) {
|
|
744
701
|
controller.enqueue({ type: "reasoning-end", id: "reasoning-0" });
|
|
745
702
|
}
|
|
746
703
|
if (isActiveText) {
|
|
747
704
|
controller.enqueue({ type: "text-end", id: "txt-0" });
|
|
748
705
|
}
|
|
749
|
-
|
|
750
|
-
(toolCall2) => !toolCall2.hasFinished
|
|
751
|
-
)) {
|
|
752
|
-
controller.enqueue({
|
|
753
|
-
type: "tool-input-end",
|
|
754
|
-
id: toolCall.id
|
|
755
|
-
});
|
|
756
|
-
controller.enqueue({
|
|
757
|
-
type: "tool-call",
|
|
758
|
-
toolCallId: (_a = toolCall.id) != null ? _a : (0, import_provider_utils2.generateId)(),
|
|
759
|
-
toolName: toolCall.function.name,
|
|
760
|
-
input: toolCall.function.arguments
|
|
761
|
-
});
|
|
762
|
-
}
|
|
706
|
+
toolCallTracker.flush();
|
|
763
707
|
controller.enqueue({
|
|
764
708
|
type: "finish",
|
|
765
709
|
finishReason,
|
|
766
710
|
usage: convertDeepSeekUsage(usage),
|
|
767
711
|
providerMetadata: {
|
|
768
712
|
[providerOptionsName]: {
|
|
769
|
-
promptCacheHitTokens: (
|
|
770
|
-
promptCacheMissTokens: (
|
|
713
|
+
promptCacheHitTokens: (_a2 = usage == null ? void 0 : usage.prompt_cache_hit_tokens) != null ? _a2 : void 0,
|
|
714
|
+
promptCacheMissTokens: (_b2 = usage == null ? void 0 : usage.prompt_cache_miss_tokens) != null ? _b2 : void 0
|
|
771
715
|
}
|
|
772
716
|
}
|
|
773
717
|
});
|
|
@@ -781,17 +725,17 @@ var DeepSeekChatLanguageModel = class {
|
|
|
781
725
|
};
|
|
782
726
|
|
|
783
727
|
// src/version.ts
|
|
784
|
-
var VERSION = true ? "3.0.0-beta.
|
|
728
|
+
var VERSION = true ? "3.0.0-beta.55" : "0.0.0-test";
|
|
785
729
|
|
|
786
730
|
// src/deepseek-provider.ts
|
|
787
731
|
function createDeepSeek(options = {}) {
|
|
788
732
|
var _a;
|
|
789
|
-
const baseURL =
|
|
733
|
+
const baseURL = withoutTrailingSlash(
|
|
790
734
|
(_a = options.baseURL) != null ? _a : "https://api.deepseek.com"
|
|
791
735
|
);
|
|
792
|
-
const getHeaders = () =>
|
|
736
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
793
737
|
{
|
|
794
|
-
Authorization: `Bearer ${
|
|
738
|
+
Authorization: `Bearer ${loadApiKey({
|
|
795
739
|
apiKey: options.apiKey,
|
|
796
740
|
environmentVariableName: "DEEPSEEK_API_KEY",
|
|
797
741
|
description: "DeepSeek API key"
|
|
@@ -813,19 +757,19 @@ function createDeepSeek(options = {}) {
|
|
|
813
757
|
provider.languageModel = createLanguageModel;
|
|
814
758
|
provider.chat = createLanguageModel;
|
|
815
759
|
provider.embeddingModel = (modelId) => {
|
|
816
|
-
throw new
|
|
760
|
+
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
817
761
|
};
|
|
818
762
|
provider.textEmbeddingModel = provider.embeddingModel;
|
|
819
763
|
provider.imageModel = (modelId) => {
|
|
820
|
-
throw new
|
|
764
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
821
765
|
};
|
|
822
766
|
return provider;
|
|
823
767
|
}
|
|
824
|
-
var
|
|
825
|
-
|
|
826
|
-
0 && (module.exports = {
|
|
768
|
+
var deepSeek = createDeepSeek();
|
|
769
|
+
export {
|
|
827
770
|
VERSION,
|
|
828
771
|
createDeepSeek,
|
|
829
|
-
|
|
830
|
-
|
|
772
|
+
deepSeek,
|
|
773
|
+
deepSeek as deepseek
|
|
774
|
+
};
|
|
831
775
|
//# sourceMappingURL=index.js.map
|