@ai-sdk/deepseek 2.0.35 → 2.0.37

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