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