@ai-sdk/deepseek 2.0.0-beta.42 → 2.0.0-beta.44

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,736 @@ 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
+ function prepareTools({
258
+ tools,
259
+ toolChoice
260
+ }) {
261
+ tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
262
+ const toolWarnings = [];
263
+ if (tools == null) {
264
+ return { tools: void 0, toolChoice: void 0, toolWarnings };
265
+ }
266
+ const deepseekTools = [];
267
+ for (const tool of tools) {
268
+ if (tool.type === "provider") {
269
+ toolWarnings.push({
270
+ type: "unsupported",
271
+ feature: `provider-defined tool ${tool.id}`
272
+ });
273
+ } else {
274
+ deepseekTools.push({
275
+ type: "function",
276
+ function: {
277
+ name: tool.name,
278
+ description: tool.description,
279
+ parameters: tool.inputSchema,
280
+ ...tool.strict != null ? { strict: tool.strict } : {}
281
+ }
282
+ });
283
+ }
284
+ }
285
+ if (toolChoice == null) {
286
+ return { tools: deepseekTools, toolChoice: void 0, toolWarnings };
287
+ }
288
+ const type = toolChoice == null ? void 0 : toolChoice.type;
289
+ switch (type) {
290
+ case "auto":
291
+ case "none":
292
+ case "required":
293
+ return { tools: deepseekTools, toolChoice: type, toolWarnings };
294
+ case "tool":
295
+ return {
296
+ tools: deepseekTools,
297
+ toolChoice: {
298
+ type: "function",
299
+ function: { name: toolChoice.toolName }
300
+ },
301
+ toolWarnings
302
+ };
303
+ default: {
304
+ return {
305
+ tools: deepseekTools,
306
+ toolChoice: void 0,
307
+ toolWarnings: [
308
+ ...toolWarnings,
309
+ {
310
+ type: "unsupported",
311
+ feature: `tool choice type: ${type}`
312
+ }
313
+ ]
314
+ };
315
+ }
316
+ }
317
+ }
318
+
319
+ // src/chat/get-response-metadata.ts
320
+ function getResponseMetadata({
321
+ id,
322
+ model,
323
+ created
324
+ }) {
325
+ return {
326
+ id: id != null ? id : void 0,
327
+ modelId: model != null ? model : void 0,
328
+ timestamp: created != null ? new Date(created * 1e3) : void 0
329
+ };
330
+ }
331
+
332
+ // src/chat/map-deepseek-finish-reason.ts
333
+ function mapDeepSeekFinishReason(finishReason) {
334
+ switch (finishReason) {
335
+ case "stop":
336
+ return "stop";
337
+ case "length":
338
+ return "length";
339
+ case "content_filter":
340
+ return "content-filter";
341
+ case "tool_calls":
342
+ return "tool-calls";
343
+ case "insufficient_system_resource":
344
+ return "error";
345
+ default:
346
+ return "unknown";
347
+ }
348
+ }
349
+
350
+ // src/chat/deepseek-chat-language-model.ts
351
+ var DeepSeekChatLanguageModel = class {
352
+ constructor(modelId, config) {
353
+ this.specificationVersion = "v3";
354
+ this.supportedUrls = {};
355
+ this.modelId = modelId;
356
+ this.config = config;
357
+ this.failedResponseHandler = createJsonErrorResponseHandler({
358
+ errorSchema: deepSeekErrorSchema,
359
+ errorToMessage: (error) => error.error.message
360
+ });
361
+ }
362
+ get provider() {
363
+ return this.config.provider;
364
+ }
365
+ get providerOptionsName() {
366
+ return this.config.provider.split(".")[0].trim();
367
+ }
368
+ async getArgs({
369
+ prompt,
370
+ maxOutputTokens,
371
+ temperature,
372
+ topP,
373
+ topK,
374
+ frequencyPenalty,
375
+ presencePenalty,
376
+ providerOptions,
377
+ stopSequences,
378
+ responseFormat,
379
+ seed,
380
+ toolChoice,
381
+ tools
382
+ }) {
383
+ var _a, _b;
384
+ const deepseekOptions = (_a = await parseProviderOptions({
385
+ provider: this.providerOptionsName,
386
+ providerOptions,
387
+ schema: deepseekChatOptions
388
+ })) != null ? _a : {};
389
+ const { messages, warnings } = convertToDeepSeekChatMessages({
390
+ prompt,
391
+ responseFormat
392
+ });
393
+ if (topK != null) {
394
+ warnings.push({ type: "unsupported", feature: "topK" });
395
+ }
396
+ if (seed != null) {
397
+ warnings.push({ type: "unsupported", feature: "seed" });
398
+ }
399
+ const {
400
+ tools: deepseekTools,
401
+ toolChoice: deepseekToolChoices,
402
+ toolWarnings
403
+ } = prepareTools({
404
+ tools,
405
+ toolChoice
406
+ });
407
+ return {
408
+ args: {
409
+ model: this.modelId,
410
+ max_tokens: maxOutputTokens,
411
+ temperature,
412
+ top_p: topP,
413
+ frequency_penalty: frequencyPenalty,
414
+ presence_penalty: presencePenalty,
415
+ response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? { type: "json_object" } : void 0,
416
+ stop: stopSequences,
417
+ messages,
418
+ tools: deepseekTools,
419
+ tool_choice: deepseekToolChoices,
420
+ thinking: ((_b = deepseekOptions.thinking) == null ? void 0 : _b.type) != null ? { type: deepseekOptions.thinking.type } : void 0
421
+ },
422
+ warnings: [...warnings, ...toolWarnings]
423
+ };
424
+ }
425
+ async doGenerate(options) {
426
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
427
+ const { args, warnings } = await this.getArgs({ ...options });
428
+ const {
429
+ responseHeaders,
430
+ value: responseBody,
431
+ rawValue: rawResponse
432
+ } = await postJsonToApi({
433
+ url: this.config.url({
434
+ path: "/chat/completions",
435
+ modelId: this.modelId
436
+ }),
437
+ headers: combineHeaders(this.config.headers(), options.headers),
438
+ body: args,
439
+ failedResponseHandler: this.failedResponseHandler,
440
+ successfulResponseHandler: createJsonResponseHandler(
441
+ deepseekChatResponseSchema
442
+ ),
443
+ abortSignal: options.abortSignal,
444
+ fetch: this.config.fetch
445
+ });
446
+ const choice = responseBody.choices[0];
447
+ const content = [];
448
+ const reasoning = choice.message.reasoning_content;
449
+ if (reasoning != null && reasoning.length > 0) {
450
+ content.push({
451
+ type: "reasoning",
452
+ text: reasoning
453
+ });
454
+ }
455
+ if (choice.message.tool_calls != null) {
456
+ for (const toolCall of choice.message.tool_calls) {
457
+ content.push({
458
+ type: "tool-call",
459
+ toolCallId: (_a = toolCall.id) != null ? _a : generateId(),
460
+ toolName: toolCall.function.name,
461
+ input: toolCall.function.arguments
462
+ });
463
+ }
464
+ }
465
+ const text = choice.message.content;
466
+ if (text != null && text.length > 0) {
467
+ content.push({ type: "text", text });
468
+ }
469
+ return {
470
+ content,
471
+ finishReason: mapDeepSeekFinishReason(choice.finish_reason),
472
+ usage: {
473
+ inputTokens: (_c = (_b = responseBody.usage) == null ? void 0 : _b.prompt_tokens) != null ? _c : void 0,
474
+ outputTokens: (_e = (_d = responseBody.usage) == null ? void 0 : _d.completion_tokens) != null ? _e : void 0,
475
+ totalTokens: (_g = (_f = responseBody.usage) == null ? void 0 : _f.total_tokens) != null ? _g : void 0,
476
+ reasoningTokens: (_j = (_i = (_h = responseBody.usage) == null ? void 0 : _h.completion_tokens_details) == null ? void 0 : _i.reasoning_tokens) != null ? _j : void 0,
477
+ cachedInputTokens: (_l = (_k = responseBody.usage) == null ? void 0 : _k.prompt_cache_hit_tokens) != null ? _l : void 0
478
+ },
479
+ providerMetadata: {
480
+ [this.providerOptionsName]: {
481
+ promptCacheHitTokens: (_m = responseBody.usage) == null ? void 0 : _m.prompt_cache_hit_tokens,
482
+ promptCacheMissTokens: (_n = responseBody.usage) == null ? void 0 : _n.prompt_cache_miss_tokens
483
+ }
484
+ },
485
+ request: { body: args },
486
+ response: {
487
+ ...getResponseMetadata(responseBody),
488
+ headers: responseHeaders,
489
+ body: rawResponse
490
+ },
491
+ warnings
492
+ };
493
+ }
494
+ async doStream(options) {
495
+ const { args, warnings } = await this.getArgs({ ...options });
496
+ const body = {
497
+ ...args,
498
+ stream: true,
499
+ stream_options: { include_usage: true }
500
+ };
501
+ const { responseHeaders, value: response } = await postJsonToApi({
502
+ url: this.config.url({
503
+ path: "/chat/completions",
504
+ modelId: this.modelId
505
+ }),
506
+ headers: combineHeaders(this.config.headers(), options.headers),
507
+ body,
508
+ failedResponseHandler: this.failedResponseHandler,
509
+ successfulResponseHandler: createEventSourceResponseHandler(
510
+ deepseekChatChunkSchema
511
+ ),
512
+ abortSignal: options.abortSignal,
513
+ fetch: this.config.fetch
514
+ });
515
+ const toolCalls = [];
516
+ let finishReason = "unknown";
517
+ let usage = void 0;
518
+ let isFirstChunk = true;
519
+ const providerOptionsName = this.providerOptionsName;
520
+ let isActiveReasoning = false;
521
+ let isActiveText = false;
522
+ return {
523
+ stream: response.pipeThrough(
524
+ new TransformStream({
525
+ start(controller) {
526
+ controller.enqueue({ type: "stream-start", warnings });
527
+ },
528
+ transform(chunk, controller) {
529
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
530
+ if (options.includeRawChunks) {
531
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
532
+ }
533
+ if (!chunk.success) {
534
+ finishReason = "error";
535
+ controller.enqueue({ type: "error", error: chunk.error });
536
+ return;
537
+ }
538
+ const value = chunk.value;
539
+ if ("error" in value) {
540
+ finishReason = "error";
541
+ controller.enqueue({ type: "error", error: value.error.message });
542
+ return;
543
+ }
544
+ if (isFirstChunk) {
545
+ isFirstChunk = false;
546
+ controller.enqueue({
547
+ type: "response-metadata",
548
+ ...getResponseMetadata(value)
549
+ });
550
+ }
551
+ if (value.usage != null) {
552
+ usage = value.usage;
553
+ }
554
+ const choice = value.choices[0];
555
+ if ((choice == null ? void 0 : choice.finish_reason) != null) {
556
+ finishReason = mapDeepSeekFinishReason(choice.finish_reason);
557
+ }
558
+ if ((choice == null ? void 0 : choice.delta) == null) {
559
+ return;
560
+ }
561
+ const delta = choice.delta;
562
+ const reasoningContent = delta.reasoning_content;
563
+ if (reasoningContent) {
564
+ if (!isActiveReasoning) {
565
+ controller.enqueue({
566
+ type: "reasoning-start",
567
+ id: "reasoning-0"
568
+ });
569
+ isActiveReasoning = true;
570
+ }
571
+ controller.enqueue({
572
+ type: "reasoning-delta",
573
+ id: "reasoning-0",
574
+ delta: reasoningContent
575
+ });
576
+ }
577
+ if (delta.content) {
578
+ if (!isActiveText) {
579
+ controller.enqueue({ type: "text-start", id: "txt-0" });
580
+ isActiveText = true;
581
+ }
582
+ if (isActiveReasoning) {
583
+ controller.enqueue({
584
+ type: "reasoning-end",
585
+ id: "reasoning-0"
586
+ });
587
+ isActiveReasoning = false;
588
+ }
589
+ controller.enqueue({
590
+ type: "text-delta",
591
+ id: "txt-0",
592
+ delta: delta.content
593
+ });
594
+ }
595
+ if (delta.tool_calls != null) {
596
+ if (isActiveReasoning) {
597
+ controller.enqueue({
598
+ type: "reasoning-end",
599
+ id: "reasoning-0"
600
+ });
601
+ isActiveReasoning = false;
602
+ }
603
+ for (const toolCallDelta of delta.tool_calls) {
604
+ const index = toolCallDelta.index;
605
+ if (toolCalls[index] == null) {
606
+ if (toolCallDelta.id == null) {
607
+ throw new InvalidResponseDataError({
608
+ data: toolCallDelta,
609
+ message: `Expected 'id' to be a string.`
610
+ });
611
+ }
612
+ if (((_a = toolCallDelta.function) == null ? void 0 : _a.name) == null) {
613
+ throw new InvalidResponseDataError({
614
+ data: toolCallDelta,
615
+ message: `Expected 'function.name' to be a string.`
616
+ });
617
+ }
618
+ controller.enqueue({
619
+ type: "tool-input-start",
620
+ id: toolCallDelta.id,
621
+ toolName: toolCallDelta.function.name
622
+ });
623
+ toolCalls[index] = {
624
+ id: toolCallDelta.id,
625
+ type: "function",
626
+ function: {
627
+ name: toolCallDelta.function.name,
628
+ arguments: (_b = toolCallDelta.function.arguments) != null ? _b : ""
629
+ },
630
+ hasFinished: false
631
+ };
632
+ const toolCall2 = toolCalls[index];
633
+ if (((_c = toolCall2.function) == null ? void 0 : _c.name) != null && ((_d = toolCall2.function) == null ? void 0 : _d.arguments) != null) {
634
+ if (toolCall2.function.arguments.length > 0) {
635
+ controller.enqueue({
636
+ type: "tool-input-delta",
637
+ id: toolCall2.id,
638
+ delta: toolCall2.function.arguments
639
+ });
640
+ }
641
+ if (isParsableJson(toolCall2.function.arguments)) {
642
+ controller.enqueue({
643
+ type: "tool-input-end",
644
+ id: toolCall2.id
645
+ });
646
+ controller.enqueue({
647
+ type: "tool-call",
648
+ toolCallId: (_e = toolCall2.id) != null ? _e : generateId(),
649
+ toolName: toolCall2.function.name,
650
+ input: toolCall2.function.arguments
651
+ });
652
+ toolCall2.hasFinished = true;
653
+ }
654
+ }
655
+ continue;
656
+ }
657
+ const toolCall = toolCalls[index];
658
+ if (toolCall.hasFinished) {
659
+ continue;
660
+ }
661
+ if (((_f = toolCallDelta.function) == null ? void 0 : _f.arguments) != null) {
662
+ toolCall.function.arguments += (_h = (_g = toolCallDelta.function) == null ? void 0 : _g.arguments) != null ? _h : "";
663
+ }
664
+ controller.enqueue({
665
+ type: "tool-input-delta",
666
+ id: toolCall.id,
667
+ delta: (_i = toolCallDelta.function.arguments) != null ? _i : ""
668
+ });
669
+ if (((_j = toolCall.function) == null ? void 0 : _j.name) != null && ((_k = toolCall.function) == null ? void 0 : _k.arguments) != null && isParsableJson(toolCall.function.arguments)) {
670
+ controller.enqueue({
671
+ type: "tool-input-end",
672
+ id: toolCall.id
673
+ });
674
+ controller.enqueue({
675
+ type: "tool-call",
676
+ toolCallId: (_l = toolCall.id) != null ? _l : generateId(),
677
+ toolName: toolCall.function.name,
678
+ input: toolCall.function.arguments
679
+ });
680
+ toolCall.hasFinished = true;
681
+ }
682
+ }
683
+ }
684
+ },
685
+ flush(controller) {
686
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
687
+ if (isActiveReasoning) {
688
+ controller.enqueue({ type: "reasoning-end", id: "reasoning-0" });
689
+ }
690
+ if (isActiveText) {
691
+ controller.enqueue({ type: "text-end", id: "txt-0" });
692
+ }
693
+ for (const toolCall of toolCalls.filter(
694
+ (toolCall2) => !toolCall2.hasFinished
695
+ )) {
696
+ controller.enqueue({
697
+ type: "tool-input-end",
698
+ id: toolCall.id
699
+ });
700
+ controller.enqueue({
701
+ type: "tool-call",
702
+ toolCallId: (_a = toolCall.id) != null ? _a : generateId(),
703
+ toolName: toolCall.function.name,
704
+ input: toolCall.function.arguments
705
+ });
706
+ }
707
+ controller.enqueue({
708
+ type: "finish",
709
+ finishReason,
710
+ usage: {
711
+ inputTokens: (_b = usage == null ? void 0 : usage.prompt_tokens) != null ? _b : void 0,
712
+ outputTokens: (_c = usage == null ? void 0 : usage.completion_tokens) != null ? _c : void 0,
713
+ totalTokens: (_d = usage == null ? void 0 : usage.total_tokens) != null ? _d : void 0,
714
+ reasoningTokens: (_f = (_e = usage == null ? void 0 : usage.completion_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : void 0,
715
+ cachedInputTokens: (_g = usage == null ? void 0 : usage.prompt_cache_hit_tokens) != null ? _g : void 0
716
+ },
717
+ providerMetadata: {
718
+ [providerOptionsName]: {
719
+ promptCacheHitTokens: (_h = usage == null ? void 0 : usage.prompt_cache_hit_tokens) != null ? _h : void 0,
720
+ promptCacheMissTokens: (_i = usage == null ? void 0 : usage.prompt_cache_miss_tokens) != null ? _i : void 0
721
+ }
722
+ }
723
+ });
724
+ }
725
+ })
726
+ ),
727
+ request: { body },
728
+ response: { headers: responseHeaders }
729
+ };
730
+ }
731
+ };
732
+
65
733
  // src/version.ts
66
- var VERSION = true ? "2.0.0-beta.42" : "0.0.0-test";
734
+ var VERSION = true ? "2.0.0-beta.44" : "0.0.0-test";
67
735
 
68
736
  // src/deepseek-provider.ts
69
737
  function createDeepSeek(options = {}) {
70
738
  var _a;
71
739
  const baseURL = withoutTrailingSlash(
72
- (_a = options.baseURL) != null ? _a : "https://api.deepseek.com/v1"
740
+ (_a = options.baseURL) != null ? _a : "https://api.deepseek.com"
73
741
  );
74
742
  const getHeaders = () => withUserAgentSuffix(
75
743
  {
@@ -82,32 +750,12 @@ function createDeepSeek(options = {}) {
82
750
  },
83
751
  `ai-sdk/deepseek/${VERSION}`
84
752
  );
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
753
  const createLanguageModel = (modelId) => {
105
754
  return new DeepSeekChatLanguageModel(modelId, {
106
755
  provider: `deepseek.chat`,
107
756
  url: ({ path }) => `${baseURL}${path}`,
108
757
  headers: getHeaders,
109
- fetch: options.fetch,
110
- metadataExtractor: deepSeekMetadataExtractor
758
+ fetch: options.fetch
111
759
  });
112
760
  };
113
761
  const provider = (modelId) => createLanguageModel(modelId);