@ai-sdk/deepseek 1.0.30 → 1.0.32

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