@ai-sdk/deepseek 1.0.41 → 1.0.43

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,730 @@
1
+ // src/chat/deepseek-chat-language-model.ts
2
+ import {
3
+ InvalidResponseDataError
4
+ } from "@ai-sdk/provider";
5
+ import {
6
+ combineHeaders,
7
+ createEventSourceResponseHandler,
8
+ createJsonErrorResponseHandler,
9
+ createJsonResponseHandler,
10
+ generateId,
11
+ isParsableJson,
12
+ parseProviderOptions,
13
+ postJsonToApi
14
+ } from "@ai-sdk/provider-utils";
15
+
16
+ // src/chat/convert-to-deepseek-chat-messages.ts
17
+ function convertToDeepSeekChatMessages({
18
+ prompt,
19
+ responseFormat,
20
+ modelId
21
+ }) {
22
+ const isDeepSeekV4 = modelId.includes("deepseek-v4");
23
+ const messages = [];
24
+ const warnings = [];
25
+ if ((responseFormat == null ? void 0 : responseFormat.type) === "json") {
26
+ if (responseFormat.schema == null) {
27
+ messages.push({
28
+ role: "system",
29
+ content: "Return JSON."
30
+ });
31
+ } else {
32
+ messages.push({
33
+ role: "system",
34
+ content: "Return JSON that conforms to the following schema: " + JSON.stringify(responseFormat.schema)
35
+ });
36
+ }
37
+ }
38
+ let lastUserMessageIndex = -1;
39
+ for (let i = prompt.length - 1; i >= 0; i--) {
40
+ if (prompt[i].role === "user") {
41
+ lastUserMessageIndex = i;
42
+ break;
43
+ }
44
+ }
45
+ let index = -1;
46
+ for (const { role, content } of prompt) {
47
+ index++;
48
+ switch (role) {
49
+ case "system": {
50
+ messages.push({ role: "system", content });
51
+ break;
52
+ }
53
+ case "user": {
54
+ let userContent = "";
55
+ for (const part of content) {
56
+ if (part.type === "text") {
57
+ userContent += part.text;
58
+ } else {
59
+ warnings.push({
60
+ type: "other",
61
+ message: `Unsupported user message part type: ${part.type}`
62
+ });
63
+ }
64
+ }
65
+ messages.push({
66
+ role: "user",
67
+ content: userContent
68
+ });
69
+ break;
70
+ }
71
+ case "assistant": {
72
+ let text = "";
73
+ let reasoning;
74
+ const toolCalls = [];
75
+ for (const part of content) {
76
+ switch (part.type) {
77
+ case "text": {
78
+ text += part.text;
79
+ break;
80
+ }
81
+ case "reasoning": {
82
+ if (index <= lastUserMessageIndex && !isDeepSeekV4) {
83
+ break;
84
+ }
85
+ if (reasoning == null) {
86
+ reasoning = part.text;
87
+ } else {
88
+ reasoning += part.text;
89
+ }
90
+ break;
91
+ }
92
+ case "tool-call": {
93
+ toolCalls.push({
94
+ id: part.toolCallId,
95
+ type: "function",
96
+ function: {
97
+ name: part.toolName,
98
+ arguments: JSON.stringify(part.input)
99
+ }
100
+ });
101
+ break;
102
+ }
103
+ }
104
+ }
105
+ messages.push({
106
+ role: "assistant",
107
+ content: text,
108
+ reasoning_content: reasoning != null ? reasoning : isDeepSeekV4 ? "" : void 0,
109
+ tool_calls: toolCalls.length > 0 ? toolCalls : void 0
110
+ });
111
+ break;
112
+ }
113
+ case "tool": {
114
+ for (const toolResponse of content) {
115
+ const output = toolResponse.output;
116
+ let contentValue;
117
+ switch (output.type) {
118
+ case "text":
119
+ case "error-text":
120
+ contentValue = output.value;
121
+ break;
122
+ case "content":
123
+ case "json":
124
+ case "error-json":
125
+ contentValue = JSON.stringify(output.value);
126
+ break;
127
+ }
128
+ messages.push({
129
+ role: "tool",
130
+ tool_call_id: toolResponse.toolCallId,
131
+ content: contentValue
132
+ });
133
+ }
134
+ break;
135
+ }
136
+ default: {
137
+ warnings.push({
138
+ type: "other",
139
+ message: `Unsupported message role: ${role}`
140
+ });
141
+ break;
142
+ }
143
+ }
144
+ }
145
+ return { messages, warnings };
146
+ }
147
+
148
+ // src/chat/deepseek-chat-api-types.ts
149
+ import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
150
+ import { z } from "zod/v4";
151
+ var tokenUsageSchema = z.object({
152
+ prompt_tokens: z.number().nullish(),
153
+ completion_tokens: z.number().nullish(),
154
+ prompt_cache_hit_tokens: z.number().nullish(),
155
+ prompt_cache_miss_tokens: z.number().nullish(),
156
+ total_tokens: z.number().nullish(),
157
+ completion_tokens_details: z.object({
158
+ reasoning_tokens: z.number().nullish()
159
+ }).nullish()
160
+ }).nullish();
161
+ var deepSeekErrorSchema = z.object({
162
+ error: z.object({
163
+ message: z.string(),
164
+ type: z.string().nullish(),
165
+ param: z.any().nullish(),
166
+ code: z.union([z.string(), z.number()]).nullish()
167
+ })
168
+ });
169
+ var deepseekChatResponseSchema = z.object({
170
+ id: z.string().nullish(),
171
+ created: z.number().nullish(),
172
+ model: z.string().nullish(),
173
+ choices: z.array(
174
+ z.object({
175
+ message: z.object({
176
+ role: z.literal("assistant").nullish(),
177
+ content: z.string().nullish(),
178
+ reasoning_content: z.string().nullish(),
179
+ tool_calls: z.array(
180
+ z.object({
181
+ id: z.string().nullish(),
182
+ function: z.object({
183
+ name: z.string(),
184
+ arguments: z.string()
185
+ })
186
+ })
187
+ ).nullish()
188
+ }),
189
+ finish_reason: z.string().nullish()
190
+ })
191
+ ),
192
+ usage: tokenUsageSchema
193
+ });
194
+ var deepseekChatChunkSchema = lazySchema(
195
+ () => zodSchema(
196
+ z.union([
197
+ z.object({
198
+ id: z.string().nullish(),
199
+ created: z.number().nullish(),
200
+ model: z.string().nullish(),
201
+ choices: z.array(
202
+ z.object({
203
+ delta: z.object({
204
+ role: z.enum(["assistant"]).nullish(),
205
+ content: z.string().nullish(),
206
+ reasoning_content: z.string().nullish(),
207
+ tool_calls: z.array(
208
+ z.object({
209
+ index: z.number(),
210
+ id: z.string().nullish(),
211
+ function: z.object({
212
+ name: z.string().nullish(),
213
+ arguments: z.string().nullish()
214
+ })
215
+ })
216
+ ).nullish()
217
+ }).nullish(),
218
+ finish_reason: z.string().nullish()
219
+ })
220
+ ),
221
+ usage: tokenUsageSchema
222
+ }),
223
+ deepSeekErrorSchema
224
+ ])
225
+ )
226
+ );
227
+
228
+ // src/chat/deepseek-chat-options.ts
229
+ import { z as z2 } from "zod/v4";
230
+ var deepseekChatOptions = z2.object({
231
+ /**
232
+ * Type of thinking to use. Defaults to `enabled`.
233
+ *
234
+ * See https://api-docs.deepseek.com/guides/thinking_mode for the
235
+ * `adaptive` option, which lets the model decide when to think.
236
+ */
237
+ thinking: z2.object({
238
+ type: z2.enum(["adaptive", "enabled", "disabled"]).optional()
239
+ }).optional(),
240
+ /**
241
+ * Controls the thinking strength for DeepSeek V4 reasoning models.
242
+ *
243
+ * DeepSeek's API accepts `low`, `medium`, `high`, `xhigh`, and `max`.
244
+ * Per their docs, `low` and `medium` are mapped to `high`, and `xhigh`
245
+ * is mapped to `max` server-side for compatibility with other providers.
246
+ */
247
+ reasoningEffort: z2.enum(["low", "medium", "high", "xhigh", "max"]).optional()
248
+ });
249
+
250
+ // src/chat/deepseek-prepare-tools.ts
251
+ import {
252
+ UnsupportedFunctionalityError
253
+ } from "@ai-sdk/provider";
254
+ function prepareTools({
255
+ tools,
256
+ toolChoice
257
+ }) {
258
+ tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
259
+ const toolWarnings = [];
260
+ if (tools == null) {
261
+ return { tools: void 0, toolChoice: void 0, toolWarnings };
262
+ }
263
+ const deepseekTools = [];
264
+ for (const tool of tools) {
265
+ if (tool.type === "provider-defined") {
266
+ toolWarnings.push({
267
+ type: "unsupported-tool",
268
+ tool
269
+ });
270
+ } else {
271
+ deepseekTools.push({
272
+ type: "function",
273
+ function: {
274
+ name: tool.name,
275
+ description: tool.description,
276
+ parameters: tool.inputSchema
277
+ }
278
+ });
279
+ }
280
+ }
281
+ if (toolChoice == null) {
282
+ return { tools: deepseekTools, toolChoice: void 0, toolWarnings };
283
+ }
284
+ const type = toolChoice.type;
285
+ switch (type) {
286
+ case "auto":
287
+ case "none":
288
+ case "required":
289
+ return { tools: deepseekTools, toolChoice: type, toolWarnings };
290
+ case "tool":
291
+ return {
292
+ tools: deepseekTools,
293
+ toolChoice: {
294
+ type: "function",
295
+ function: { name: toolChoice.toolName }
296
+ },
297
+ toolWarnings
298
+ };
299
+ default: {
300
+ const _exhaustiveCheck = type;
301
+ throw new UnsupportedFunctionalityError({
302
+ functionality: `tool choice type: ${_exhaustiveCheck}`
303
+ });
304
+ }
305
+ }
306
+ }
307
+
308
+ // src/chat/get-response-metadata.ts
309
+ function getResponseMetadata({
310
+ id,
311
+ model,
312
+ created
313
+ }) {
314
+ return {
315
+ id: id != null ? id : void 0,
316
+ modelId: model != null ? model : void 0,
317
+ timestamp: created != null ? new Date(created * 1e3) : void 0
318
+ };
319
+ }
320
+
321
+ // src/chat/map-deepseek-finish-reason.ts
322
+ function mapDeepSeekFinishReason(finishReason) {
323
+ switch (finishReason) {
324
+ case "stop":
325
+ return "stop";
326
+ case "length":
327
+ return "length";
328
+ case "content_filter":
329
+ return "content-filter";
330
+ case "tool_calls":
331
+ return "tool-calls";
332
+ case "insufficient_system_resource":
333
+ return "error";
334
+ default:
335
+ return "unknown";
336
+ }
337
+ }
338
+
339
+ // src/chat/deepseek-chat-language-model.ts
340
+ var DeepSeekChatLanguageModel = class {
341
+ constructor(modelId, config) {
342
+ this.specificationVersion = "v2";
343
+ this.supportedUrls = {};
344
+ this.modelId = modelId;
345
+ this.config = config;
346
+ this.failedResponseHandler = createJsonErrorResponseHandler({
347
+ errorSchema: deepSeekErrorSchema,
348
+ errorToMessage: (error) => error.error.message
349
+ });
350
+ }
351
+ get provider() {
352
+ return this.config.provider;
353
+ }
354
+ get providerOptionsName() {
355
+ return this.config.provider.split(".")[0].trim();
356
+ }
357
+ async getArgs({
358
+ prompt,
359
+ maxOutputTokens,
360
+ temperature,
361
+ topP,
362
+ topK,
363
+ frequencyPenalty,
364
+ presencePenalty,
365
+ providerOptions,
366
+ stopSequences,
367
+ responseFormat,
368
+ tools,
369
+ toolChoice,
370
+ seed
371
+ }) {
372
+ var _a, _b;
373
+ const deepseekOptions = (_a = await parseProviderOptions({
374
+ provider: this.providerOptionsName,
375
+ providerOptions,
376
+ schema: deepseekChatOptions
377
+ })) != null ? _a : {};
378
+ const { messages, warnings } = convertToDeepSeekChatMessages({
379
+ prompt,
380
+ responseFormat,
381
+ modelId: this.modelId
382
+ });
383
+ if (topK != null) {
384
+ warnings.push({ type: "unsupported-setting", setting: "topK" });
385
+ }
386
+ if (seed != null) {
387
+ warnings.push({ type: "unsupported-setting", setting: "seed" });
388
+ }
389
+ const {
390
+ tools: deepseekTools,
391
+ toolChoice: deepseekToolChoices,
392
+ toolWarnings
393
+ } = prepareTools({
394
+ tools,
395
+ toolChoice
396
+ });
397
+ const thinking = this.config.supportsThinking === false ? void 0 : ((_b = deepseekOptions.thinking) == null ? void 0 : _b.type) != null ? { type: deepseekOptions.thinking.type } : void 0;
398
+ return {
399
+ args: {
400
+ model: this.modelId,
401
+ max_tokens: maxOutputTokens,
402
+ temperature,
403
+ top_p: topP,
404
+ frequency_penalty: frequencyPenalty,
405
+ presence_penalty: presencePenalty,
406
+ response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? { type: "json_object" } : void 0,
407
+ stop: stopSequences,
408
+ messages,
409
+ tools: deepseekTools,
410
+ tool_choice: deepseekToolChoices,
411
+ thinking,
412
+ ...(thinking == null ? void 0 : thinking.type) !== "disabled" && deepseekOptions.reasoningEffort != null && {
413
+ reasoning_effort: deepseekOptions.reasoningEffort
414
+ }
415
+ },
416
+ warnings: [...warnings, ...toolWarnings]
417
+ };
418
+ }
419
+ async doGenerate(options) {
420
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
421
+ const { args, warnings } = await this.getArgs({ ...options });
422
+ const {
423
+ responseHeaders,
424
+ value: responseBody,
425
+ rawValue: rawResponse
426
+ } = await postJsonToApi({
427
+ url: this.config.url({
428
+ path: "/chat/completions",
429
+ modelId: this.modelId
430
+ }),
431
+ headers: combineHeaders(this.config.headers(), options.headers),
432
+ body: args,
433
+ failedResponseHandler: this.failedResponseHandler,
434
+ successfulResponseHandler: createJsonResponseHandler(
435
+ deepseekChatResponseSchema
436
+ ),
437
+ abortSignal: options.abortSignal,
438
+ fetch: this.config.fetch
439
+ });
440
+ const choice = responseBody.choices[0];
441
+ const content = [];
442
+ const reasoning = choice.message.reasoning_content;
443
+ if (reasoning != null && reasoning.length > 0) {
444
+ content.push({
445
+ type: "reasoning",
446
+ text: reasoning
447
+ });
448
+ }
449
+ if (choice.message.tool_calls != null) {
450
+ for (const toolCall of choice.message.tool_calls) {
451
+ content.push({
452
+ type: "tool-call",
453
+ toolCallId: (_a = toolCall.id) != null ? _a : generateId(),
454
+ toolName: toolCall.function.name,
455
+ input: toolCall.function.arguments
456
+ });
457
+ }
458
+ }
459
+ const text = choice.message.content;
460
+ if (text != null && text.length > 0) {
461
+ content.push({ type: "text", text });
462
+ }
463
+ return {
464
+ content,
465
+ finishReason: mapDeepSeekFinishReason(choice.finish_reason),
466
+ usage: {
467
+ inputTokens: (_c = (_b = responseBody.usage) == null ? void 0 : _b.prompt_tokens) != null ? _c : void 0,
468
+ outputTokens: (_e = (_d = responseBody.usage) == null ? void 0 : _d.completion_tokens) != null ? _e : void 0,
469
+ totalTokens: (_g = (_f = responseBody.usage) == null ? void 0 : _f.total_tokens) != null ? _g : void 0,
470
+ reasoningTokens: (_j = (_i = (_h = responseBody.usage) == null ? void 0 : _h.completion_tokens_details) == null ? void 0 : _i.reasoning_tokens) != null ? _j : void 0,
471
+ cachedInputTokens: (_l = (_k = responseBody.usage) == null ? void 0 : _k.prompt_cache_hit_tokens) != null ? _l : void 0
472
+ },
473
+ providerMetadata: {
474
+ [this.providerOptionsName]: {
475
+ promptCacheHitTokens: (_n = (_m = responseBody.usage) == null ? void 0 : _m.prompt_cache_hit_tokens) != null ? _n : null,
476
+ promptCacheMissTokens: (_p = (_o = responseBody.usage) == null ? void 0 : _o.prompt_cache_miss_tokens) != null ? _p : null
477
+ }
478
+ },
479
+ request: { body: args },
480
+ response: {
481
+ ...getResponseMetadata(responseBody),
482
+ headers: responseHeaders,
483
+ body: rawResponse
484
+ },
485
+ warnings
486
+ };
487
+ }
488
+ async doStream(options) {
489
+ const { args, warnings } = await this.getArgs({ ...options });
490
+ const body = {
491
+ ...args,
492
+ stream: true,
493
+ stream_options: { include_usage: true }
494
+ };
495
+ const { responseHeaders, value: response } = await postJsonToApi({
496
+ url: this.config.url({
497
+ path: "/chat/completions",
498
+ modelId: this.modelId
499
+ }),
500
+ headers: combineHeaders(this.config.headers(), options.headers),
501
+ body,
502
+ failedResponseHandler: this.failedResponseHandler,
503
+ successfulResponseHandler: createEventSourceResponseHandler(
504
+ deepseekChatChunkSchema
505
+ ),
506
+ abortSignal: options.abortSignal,
507
+ fetch: this.config.fetch
508
+ });
509
+ const toolCalls = [];
510
+ let finishReason = "unknown";
511
+ let usage = void 0;
512
+ let isFirstChunk = true;
513
+ const providerOptionsName = this.providerOptionsName;
514
+ let isActiveReasoning = false;
515
+ let isActiveText = false;
516
+ return {
517
+ stream: response.pipeThrough(
518
+ new TransformStream({
519
+ start(controller) {
520
+ controller.enqueue({ type: "stream-start", warnings });
521
+ },
522
+ transform(chunk, controller) {
523
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
524
+ if (options.includeRawChunks) {
525
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
526
+ }
527
+ if (!chunk.success) {
528
+ finishReason = "error";
529
+ controller.enqueue({ type: "error", error: chunk.error });
530
+ return;
531
+ }
532
+ const value = chunk.value;
533
+ if ("error" in value) {
534
+ finishReason = "error";
535
+ controller.enqueue({ type: "error", error: value.error.message });
536
+ return;
537
+ }
538
+ if (isFirstChunk) {
539
+ isFirstChunk = false;
540
+ controller.enqueue({
541
+ type: "response-metadata",
542
+ ...getResponseMetadata(value)
543
+ });
544
+ }
545
+ if (value.usage != null) {
546
+ usage = value.usage;
547
+ }
548
+ const choice = value.choices[0];
549
+ if ((choice == null ? void 0 : choice.finish_reason) != null) {
550
+ finishReason = mapDeepSeekFinishReason(choice.finish_reason);
551
+ }
552
+ if ((choice == null ? void 0 : choice.delta) == null) {
553
+ return;
554
+ }
555
+ const delta = choice.delta;
556
+ const reasoningContent = delta.reasoning_content;
557
+ if (reasoningContent) {
558
+ if (!isActiveReasoning) {
559
+ controller.enqueue({
560
+ type: "reasoning-start",
561
+ id: "reasoning-0"
562
+ });
563
+ isActiveReasoning = true;
564
+ }
565
+ controller.enqueue({
566
+ type: "reasoning-delta",
567
+ id: "reasoning-0",
568
+ delta: reasoningContent
569
+ });
570
+ }
571
+ if (delta.content) {
572
+ if (!isActiveText) {
573
+ controller.enqueue({ type: "text-start", id: "txt-0" });
574
+ isActiveText = true;
575
+ }
576
+ if (isActiveReasoning) {
577
+ controller.enqueue({
578
+ type: "reasoning-end",
579
+ id: "reasoning-0"
580
+ });
581
+ isActiveReasoning = false;
582
+ }
583
+ controller.enqueue({
584
+ type: "text-delta",
585
+ id: "txt-0",
586
+ delta: delta.content
587
+ });
588
+ }
589
+ if (delta.tool_calls != null) {
590
+ if (isActiveReasoning) {
591
+ controller.enqueue({
592
+ type: "reasoning-end",
593
+ id: "reasoning-0"
594
+ });
595
+ isActiveReasoning = false;
596
+ }
597
+ for (const toolCallDelta of delta.tool_calls) {
598
+ const index = toolCallDelta.index;
599
+ if (toolCalls[index] == null) {
600
+ if (toolCallDelta.id == null) {
601
+ throw new InvalidResponseDataError({
602
+ data: toolCallDelta,
603
+ message: `Expected 'id' to be a string.`
604
+ });
605
+ }
606
+ if (((_a = toolCallDelta.function) == null ? void 0 : _a.name) == null) {
607
+ throw new InvalidResponseDataError({
608
+ data: toolCallDelta,
609
+ message: `Expected 'function.name' to be a string.`
610
+ });
611
+ }
612
+ controller.enqueue({
613
+ type: "tool-input-start",
614
+ id: toolCallDelta.id,
615
+ toolName: toolCallDelta.function.name
616
+ });
617
+ toolCalls[index] = {
618
+ id: toolCallDelta.id,
619
+ type: "function",
620
+ function: {
621
+ name: toolCallDelta.function.name,
622
+ arguments: (_b = toolCallDelta.function.arguments) != null ? _b : ""
623
+ },
624
+ hasFinished: false
625
+ };
626
+ const toolCall2 = toolCalls[index];
627
+ if (((_c = toolCall2.function) == null ? void 0 : _c.name) != null && ((_d = toolCall2.function) == null ? void 0 : _d.arguments) != null) {
628
+ if (toolCall2.function.arguments.length > 0) {
629
+ controller.enqueue({
630
+ type: "tool-input-delta",
631
+ id: toolCall2.id,
632
+ delta: toolCall2.function.arguments
633
+ });
634
+ }
635
+ if (isParsableJson(toolCall2.function.arguments)) {
636
+ controller.enqueue({
637
+ type: "tool-input-end",
638
+ id: toolCall2.id
639
+ });
640
+ controller.enqueue({
641
+ type: "tool-call",
642
+ toolCallId: (_e = toolCall2.id) != null ? _e : generateId(),
643
+ toolName: toolCall2.function.name,
644
+ input: toolCall2.function.arguments
645
+ });
646
+ toolCall2.hasFinished = true;
647
+ }
648
+ }
649
+ continue;
650
+ }
651
+ const toolCall = toolCalls[index];
652
+ if (toolCall.hasFinished) {
653
+ continue;
654
+ }
655
+ if (((_f = toolCallDelta.function) == null ? void 0 : _f.arguments) != null) {
656
+ toolCall.function.arguments += (_h = (_g = toolCallDelta.function) == null ? void 0 : _g.arguments) != null ? _h : "";
657
+ }
658
+ controller.enqueue({
659
+ type: "tool-input-delta",
660
+ id: toolCall.id,
661
+ delta: (_i = toolCallDelta.function.arguments) != null ? _i : ""
662
+ });
663
+ if (((_j = toolCall.function) == null ? void 0 : _j.name) != null && ((_k = toolCall.function) == null ? void 0 : _k.arguments) != null && isParsableJson(toolCall.function.arguments)) {
664
+ controller.enqueue({
665
+ type: "tool-input-end",
666
+ id: toolCall.id
667
+ });
668
+ controller.enqueue({
669
+ type: "tool-call",
670
+ toolCallId: (_l = toolCall.id) != null ? _l : generateId(),
671
+ toolName: toolCall.function.name,
672
+ input: toolCall.function.arguments
673
+ });
674
+ toolCall.hasFinished = true;
675
+ }
676
+ }
677
+ }
678
+ },
679
+ flush(controller) {
680
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
681
+ if (isActiveReasoning) {
682
+ controller.enqueue({ type: "reasoning-end", id: "reasoning-0" });
683
+ }
684
+ if (isActiveText) {
685
+ controller.enqueue({ type: "text-end", id: "txt-0" });
686
+ }
687
+ for (const toolCall of toolCalls.filter(
688
+ (toolCall2) => !toolCall2.hasFinished
689
+ )) {
690
+ controller.enqueue({
691
+ type: "tool-input-end",
692
+ id: toolCall.id
693
+ });
694
+ controller.enqueue({
695
+ type: "tool-call",
696
+ toolCallId: (_a = toolCall.id) != null ? _a : generateId(),
697
+ toolName: toolCall.function.name,
698
+ input: toolCall.function.arguments
699
+ });
700
+ }
701
+ controller.enqueue({
702
+ type: "finish",
703
+ finishReason,
704
+ usage: {
705
+ inputTokens: (_b = usage == null ? void 0 : usage.prompt_tokens) != null ? _b : void 0,
706
+ outputTokens: (_c = usage == null ? void 0 : usage.completion_tokens) != null ? _c : void 0,
707
+ totalTokens: (_d = usage == null ? void 0 : usage.total_tokens) != null ? _d : void 0,
708
+ reasoningTokens: (_f = (_e = usage == null ? void 0 : usage.completion_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : void 0,
709
+ cachedInputTokens: (_g = usage == null ? void 0 : usage.prompt_cache_hit_tokens) != null ? _g : void 0
710
+ },
711
+ providerMetadata: {
712
+ [providerOptionsName]: {
713
+ promptCacheHitTokens: (_h = usage == null ? void 0 : usage.prompt_cache_hit_tokens) != null ? _h : null,
714
+ promptCacheMissTokens: (_i = usage == null ? void 0 : usage.prompt_cache_miss_tokens) != null ? _i : null
715
+ }
716
+ }
717
+ });
718
+ }
719
+ })
720
+ ),
721
+ request: { body },
722
+ response: { headers: responseHeaders }
723
+ };
724
+ }
725
+ };
726
+ export {
727
+ DeepSeekChatLanguageModel,
728
+ deepseekChatOptions
729
+ };
730
+ //# sourceMappingURL=index.mjs.map