@ai-sdk/deepseek 2.0.63 → 2.0.64

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @ai-sdk/deepseek
2
2
 
3
+ ## 2.0.64
4
+
5
+ ### Patch Changes
6
+
7
+ - 1b70db6: fix(provider/deepseek): treat the `deepseek-flash` alias as a V4 model so prior-turn `reasoning_content` is preserved in multi-turn requests
8
+ - 4bd2599: fix(deepseek): preserve reasoning streams across empty tool-call deltas
9
+
3
10
  ## 2.0.63
4
11
 
5
12
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -2,7 +2,7 @@ import { ProviderV3, LanguageModelV3 } from '@ai-sdk/provider';
2
2
  import { FetchFunction } from '@ai-sdk/provider-utils';
3
3
  import { z } from 'zod/v4';
4
4
 
5
- type DeepSeekChatModelId = 'deepseek-v4-flash' | 'deepseek-v4-pro' | 'deepseek-v4-flash-vision-exp' | (string & {});
5
+ type DeepSeekChatModelId = 'deepseek-flash' | 'deepseek-v4-flash' | 'deepseek-v4-pro' | 'deepseek-v4-flash-vision-exp' | (string & {});
6
6
  type DeepSeekLanguageModelOptions = {
7
7
  /**
8
8
  * Whether to return log probabilities for generated tokens.
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { ProviderV3, LanguageModelV3 } from '@ai-sdk/provider';
2
2
  import { FetchFunction } from '@ai-sdk/provider-utils';
3
3
  import { z } from 'zod/v4';
4
4
 
5
- type DeepSeekChatModelId = 'deepseek-v4-flash' | 'deepseek-v4-pro' | 'deepseek-v4-flash-vision-exp' | (string & {});
5
+ type DeepSeekChatModelId = 'deepseek-flash' | 'deepseek-v4-flash' | 'deepseek-v4-pro' | 'deepseek-v4-flash-vision-exp' | (string & {});
6
6
  type DeepSeekLanguageModelOptions = {
7
7
  /**
8
8
  * Whether to return log probabilities for generated tokens.
package/dist/index.js CHANGED
@@ -119,6 +119,11 @@ var deepseekFilePartProviderOptions = import_v42.z.object({
119
119
  fileData: import_v42.z.literal(true).optional()
120
120
  });
121
121
 
122
+ // src/chat/is-deepseek-v4-model.ts
123
+ function isDeepSeekV4Model(modelId) {
124
+ return modelId.includes("deepseek-v4") || modelId.startsWith("deepseek-flash") || modelId.startsWith("deepseek-pro");
125
+ }
126
+
122
127
  // src/chat/convert-to-deepseek-chat-messages.ts
123
128
  var supportedImageMediaTypes = /* @__PURE__ */ new Set([
124
129
  "image/gif",
@@ -136,7 +141,7 @@ async function convertToDeepSeekChatMessages({
136
141
  supportsStructuredOutputs = false
137
142
  }) {
138
143
  var _a;
139
- const isDeepSeekV4 = modelId.includes("deepseek-v4");
144
+ const isDeepSeekV4 = isDeepSeekV4Model(modelId);
140
145
  const messages = [];
141
146
  const warnings = [];
142
147
  if ((responseFormat == null ? void 0 : responseFormat.type) === "json") {
@@ -766,7 +771,7 @@ var DeepSeekChatLanguageModel = class {
766
771
  });
767
772
  }
768
773
  const thinking = this.config.supportsThinking === false ? void 0 : thinkingType != null ? { type: thinkingType === "adaptive" ? "enabled" : thinkingType } : void 0;
769
- const isThinkingEnabled = this.config.supportsThinking !== false && (thinking == null ? void 0 : thinking.type) !== "disabled" && (thinking != null || this.modelId === "deepseek-reasoner" || this.modelId.includes("deepseek-v4"));
774
+ const isThinkingEnabled = this.config.supportsThinking !== false && (thinking == null ? void 0 : thinking.type) !== "disabled" && (thinking != null || this.modelId === "deepseek-reasoner" || isDeepSeekV4Model(this.modelId));
770
775
  if (isThinkingEnabled && temperature != null) {
771
776
  allWarnings.push({
772
777
  type: "unsupported",
@@ -1033,7 +1038,7 @@ var DeepSeekChatLanguageModel = class {
1033
1038
  delta: delta.content
1034
1039
  });
1035
1040
  }
1036
- if (delta.tool_calls != null) {
1041
+ if (delta.tool_calls != null && delta.tool_calls.length > 0) {
1037
1042
  if (isActiveReasoning) {
1038
1043
  controller.enqueue({
1039
1044
  type: "reasoning-end",
@@ -1160,7 +1165,7 @@ var DeepSeekChatLanguageModel = class {
1160
1165
  };
1161
1166
 
1162
1167
  // src/version.ts
1163
- var VERSION = true ? "2.0.63" : "0.0.0-test";
1168
+ var VERSION = true ? "2.0.64" : "0.0.0-test";
1164
1169
 
1165
1170
  // src/deepseek-provider.ts
1166
1171
  function createDeepSeek(options = {}) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/deepseek-provider.ts","../src/chat/deepseek-chat-language-model.ts","../src/chat/convert-to-deepseek-chat-messages.ts","../src/chat/deepseek-chat-options.ts","../src/chat/deepseek-file-part-options.ts","../src/chat/convert-to-deepseek-usage.ts","../src/chat/deepseek-chat-api-types.ts","../src/chat/deepseek-prepare-tools.ts","../src/chat/get-response-metadata.ts","../src/chat/map-deepseek-finish-reason.ts","../src/version.ts"],"sourcesContent":["export { createDeepSeek, deepseek } from './deepseek-provider';\nexport type {\n DeepSeekProvider,\n DeepSeekProviderSettings,\n} from './deepseek-provider';\nexport { VERSION } from './version';\nexport type {\n DeepSeekAssistantMessageProviderOptions,\n DeepSeekLanguageModelOptions,\n DeepSeekMessageProviderOptions,\n /** @deprecated Use `DeepSeekLanguageModelOptions` instead. */\n DeepSeekLanguageModelOptions as DeepSeekChatOptions,\n} from './chat/deepseek-chat-options';\nexport type { DeepSeekErrorData } from './chat/deepseek-chat-api-types';\nexport type { DeepSeekFilePartProviderOptions } from './chat/deepseek-file-part-options';\n","import {\n NoSuchModelError,\n type LanguageModelV3,\n type ProviderV3,\n} from '@ai-sdk/provider';\nimport {\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport type { DeepSeekChatModelId } from './chat/deepseek-chat-options';\nimport { DeepSeekChatLanguageModel } from './chat/deepseek-chat-language-model';\nimport { VERSION } from './version';\n\nexport interface DeepSeekProviderSettings {\n /**\n * DeepSeek API key.\n */\n apiKey?: string;\n\n /**\n * Base URL for the API calls.\n */\n baseURL?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface DeepSeekProvider extends ProviderV3 {\n /**\n * Creates a DeepSeek model for text generation.\n */\n (modelId: DeepSeekChatModelId): LanguageModelV3;\n\n /**\n * Creates a DeepSeek model for text generation.\n */\n languageModel(modelId: DeepSeekChatModelId): LanguageModelV3;\n\n /**\n * Creates a DeepSeek chat model for text generation.\n */\n chat(modelId: DeepSeekChatModelId): LanguageModelV3;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nexport function createDeepSeek(\n options: DeepSeekProviderSettings = {},\n): DeepSeekProvider {\n const baseURL =\n withoutTrailingSlash(options.baseURL) ?? 'https://api.deepseek.com';\n\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'DEEPSEEK_API_KEY',\n description: 'DeepSeek API key',\n })}`,\n ...options.headers,\n },\n `ai-sdk/deepseek/${VERSION}`,\n );\n\n const createLanguageModel = (modelId: DeepSeekChatModelId) => {\n return new DeepSeekChatLanguageModel(modelId, {\n provider: `deepseek.chat`,\n url: ({ path }) => `${baseURL}${path}`,\n headers: getHeaders,\n fetch: options.fetch,\n supportsAssistantPrefixCompletion: baseURL.endsWith('/beta'),\n supportsStrictToolCalls: baseURL.endsWith('/beta'),\n });\n };\n\n const provider = (modelId: DeepSeekChatModelId) =>\n createLanguageModel(modelId);\n\n provider.specificationVersion = 'v3' as const;\n provider.languageModel = createLanguageModel;\n provider.chat = createLanguageModel;\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n return provider;\n}\n\nexport const deepseek = createDeepSeek();\n","import {\n InvalidResponseDataError,\n type APICallError,\n type LanguageModelV3,\n type LanguageModelV3CallOptions,\n type LanguageModelV3Content,\n type LanguageModelV3FinishReason,\n type LanguageModelV3GenerateResult,\n type LanguageModelV3StreamPart,\n type LanguageModelV3StreamResult,\n type SharedV3Warning,\n} from '@ai-sdk/provider';\nimport {\n combineHeaders,\n createEventSourceResponseHandler,\n createJsonErrorResponseHandler,\n createJsonResponseHandler,\n generateId,\n parseProviderOptions,\n postJsonToApi,\n type FetchFunction,\n type InferSchema,\n type ParseResult,\n type ResponseHandler,\n} from '@ai-sdk/provider-utils';\nimport { convertToDeepSeekChatMessages } from './convert-to-deepseek-chat-messages';\nimport { convertDeepSeekUsage } from './convert-to-deepseek-usage';\nimport {\n deepseekChatChunkSchema,\n deepseekChatResponseSchema,\n deepSeekErrorSchema,\n type DeepSeekChatLogprob,\n type DeepSeekChatTokenUsage,\n} from './deepseek-chat-api-types';\nimport {\n deepseekLanguageModelOptions,\n type DeepSeekChatModelId,\n} from './deepseek-chat-options';\nimport { prepareTools } from './deepseek-prepare-tools';\nimport { getResponseMetadata } from './get-response-metadata';\nimport { mapDeepSeekFinishReason } from './map-deepseek-finish-reason';\n\nexport type DeepSeekChatConfig = {\n provider: string;\n headers: () => Record<string, string | undefined>;\n url: (options: { modelId: string; path: string }) => string;\n fetch?: FetchFunction;\n supportsAssistantPrefixCompletion?: boolean;\n supportsPenaltySampling?: boolean;\n supportsStrictToolCalls?: boolean;\n supportsThinking?: boolean;\n supportsStructuredOutputs?: boolean;\n};\n\nfunction mapDeepSeekProviderReasoningEffort({\n reasoningEffort,\n warnings,\n}: {\n reasoningEffort: 'low' | 'medium' | 'high' | 'xhigh' | 'max';\n warnings: SharedV3Warning[];\n}): 'low' | 'high' | 'max' {\n const mapped =\n reasoningEffort === 'medium'\n ? 'high'\n : reasoningEffort === 'xhigh'\n ? 'max'\n : reasoningEffort;\n\n if (mapped !== reasoningEffort) {\n warnings.push({\n type: 'compatibility',\n feature: 'reasoningEffort',\n details: `reasoningEffort \"${reasoningEffort}\" is not a canonical DeepSeek value. mapped to \"${mapped}\".`,\n });\n }\n\n return mapped;\n}\n\nexport class DeepSeekChatLanguageModel implements LanguageModelV3 {\n readonly specificationVersion = 'v3';\n\n readonly modelId: DeepSeekChatModelId;\n\n readonly supportedUrls = {\n 'image/*': [/^https?:\\/\\/.*$/],\n };\n\n private readonly config: DeepSeekChatConfig;\n private readonly failedResponseHandler: ResponseHandler<APICallError>;\n\n constructor(modelId: DeepSeekChatModelId, config: DeepSeekChatConfig) {\n this.modelId = modelId;\n this.config = config;\n\n this.failedResponseHandler = createJsonErrorResponseHandler({\n errorSchema: deepSeekErrorSchema,\n errorToMessage: (error: InferSchema<typeof deepSeekErrorSchema>) =>\n error.error.message,\n });\n }\n\n get provider(): string {\n return this.config.provider;\n }\n\n private get providerOptionsName(): string {\n return this.config.provider.split('.')[0].trim();\n }\n\n private async getArgs({\n prompt,\n maxOutputTokens,\n temperature,\n topP,\n topK,\n frequencyPenalty,\n presencePenalty,\n providerOptions,\n stopSequences,\n responseFormat,\n seed,\n toolChoice,\n tools,\n }: LanguageModelV3CallOptions) {\n const deepseekOptions =\n (await parseProviderOptions({\n provider: this.providerOptionsName,\n providerOptions,\n schema: deepseekLanguageModelOptions,\n })) ?? {};\n\n const supportsStructuredOutputs =\n this.config.supportsStructuredOutputs === true;\n const supportsPenaltySampling =\n this.config.supportsPenaltySampling === true;\n\n const { messages, warnings } = await convertToDeepSeekChatMessages({\n prompt,\n responseFormat,\n modelId: this.modelId,\n providerOptionsName: this.providerOptionsName,\n supportsAssistantPrefixCompletion:\n this.config.supportsAssistantPrefixCompletion,\n supportsStructuredOutputs,\n });\n const allWarnings = [...warnings];\n\n if (topK != null) {\n allWarnings.push({ type: 'unsupported', feature: 'topK' });\n }\n\n if (seed != null) {\n allWarnings.push({ type: 'unsupported', feature: 'seed' });\n }\n\n if (!supportsPenaltySampling && frequencyPenalty != null) {\n allWarnings.push({\n type: 'other',\n message:\n 'frequencyPenalty is deprecated by DeepSeek and has been omitted. Remove frequencyPenalty from the request.',\n });\n }\n\n if (!supportsPenaltySampling && presencePenalty != null) {\n allWarnings.push({\n type: 'other',\n message:\n 'presencePenalty is deprecated by DeepSeek and has been omitted. Remove presencePenalty from the request.',\n });\n }\n\n const {\n tools: deepseekTools,\n toolChoice: deepseekToolChoices,\n toolWarnings,\n } = prepareTools({\n tools,\n toolChoice,\n supportsStrictToolCalls: this.config.supportsStrictToolCalls,\n });\n allWarnings.push(...toolWarnings);\n\n const thinkingType = deepseekOptions.thinking?.type;\n if (thinkingType === 'adaptive') {\n allWarnings.push({\n type: 'compatibility',\n feature: 'thinking.type',\n details:\n 'thinking.type \"adaptive\" is not a canonical DeepSeek value. mapped to \"enabled\".',\n });\n }\n\n const thinking =\n this.config.supportsThinking === false\n ? undefined\n : thinkingType != null\n ? { type: thinkingType === 'adaptive' ? 'enabled' : thinkingType }\n : undefined;\n\n const isThinkingEnabled =\n this.config.supportsThinking !== false &&\n thinking?.type !== 'disabled' &&\n (thinking != null ||\n this.modelId === 'deepseek-reasoner' ||\n this.modelId.includes('deepseek-v4'));\n\n if (isThinkingEnabled && temperature != null) {\n allWarnings.push({\n type: 'unsupported',\n feature: 'temperature',\n details:\n \"temperature has no effect when DeepSeek thinking is enabled. Set providerOptions.deepseek.thinking.type to 'disabled' to use temperature.\",\n });\n }\n\n if (isThinkingEnabled && topP != null) {\n allWarnings.push({\n type: 'unsupported',\n feature: 'topP',\n details:\n \"topP has no effect when DeepSeek thinking is enabled. Set providerOptions.deepseek.thinking.type to 'disabled' to use topP.\",\n });\n }\n\n const reasoningEffort =\n deepseekOptions.reasoningEffort != null\n ? mapDeepSeekProviderReasoningEffort({\n reasoningEffort: deepseekOptions.reasoningEffort,\n warnings: allWarnings,\n })\n : undefined;\n\n return {\n args: {\n model: this.modelId,\n ...((deepseekOptions.logprobs === true ||\n deepseekOptions.topLogprobs != null) && { logprobs: true }),\n ...(deepseekOptions.topLogprobs != null && {\n top_logprobs: deepseekOptions.topLogprobs,\n }),\n max_tokens: maxOutputTokens,\n temperature: isThinkingEnabled ? undefined : temperature,\n top_p: isThinkingEnabled ? undefined : topP,\n frequency_penalty: supportsPenaltySampling\n ? frequencyPenalty\n : undefined,\n presence_penalty: supportsPenaltySampling ? presencePenalty : undefined,\n response_format:\n responseFormat?.type === 'json'\n ? supportsStructuredOutputs && responseFormat.schema != null\n ? {\n type: 'json_schema',\n json_schema: {\n schema: responseFormat.schema,\n strict: deepseekOptions.strictJsonSchema ?? true,\n name: responseFormat.name ?? 'response',\n description: responseFormat.description,\n },\n }\n : { type: 'json_object' }\n : undefined,\n stop: stopSequences,\n messages,\n tools: deepseekTools,\n tool_choice: deepseekToolChoices,\n thinking,\n ...(deepseekOptions.userId != null && {\n user_id: deepseekOptions.userId,\n }),\n ...(thinking?.type !== 'disabled' &&\n reasoningEffort != null && {\n reasoning_effort: reasoningEffort,\n }),\n },\n warnings: allWarnings,\n };\n }\n\n async doGenerate(\n options: LanguageModelV3CallOptions,\n ): Promise<LanguageModelV3GenerateResult> {\n const { args, warnings } = await this.getArgs({ ...options });\n\n const {\n responseHeaders,\n value: responseBody,\n rawValue: rawResponse,\n } = await postJsonToApi({\n url: this.config.url({\n path: '/chat/completions',\n modelId: this.modelId,\n }),\n headers: combineHeaders(this.config.headers(), options.headers),\n body: args,\n failedResponseHandler: this.failedResponseHandler,\n successfulResponseHandler: createJsonResponseHandler(\n deepseekChatResponseSchema,\n ),\n abortSignal: options.abortSignal,\n fetch: this.config.fetch,\n });\n\n const choice = responseBody.choices[0];\n const content: Array<LanguageModelV3Content> = [];\n\n // reasoning content (before text):\n const reasoning = choice.message.reasoning_content;\n if (reasoning != null && reasoning.length > 0) {\n content.push({\n type: 'reasoning',\n text: reasoning,\n });\n }\n\n // tool calls:\n if (choice.message.tool_calls != null) {\n for (const toolCall of choice.message.tool_calls) {\n content.push({\n type: 'tool-call',\n toolCallId: toolCall.id ?? generateId(),\n toolName: toolCall.function.name,\n input: toolCall.function.arguments!,\n });\n }\n }\n\n // text content:\n const text = choice.message.content;\n if (text != null && text.length > 0) {\n content.push({ type: 'text', text });\n }\n\n return {\n content,\n finishReason: {\n unified: mapDeepSeekFinishReason(choice.finish_reason),\n raw: choice.finish_reason ?? undefined,\n },\n usage: convertDeepSeekUsage(responseBody.usage),\n providerMetadata: {\n [this.providerOptionsName]: {\n promptCacheHitTokens: responseBody.usage?.prompt_cache_hit_tokens,\n promptCacheMissTokens: responseBody.usage?.prompt_cache_miss_tokens,\n ...(responseBody.object != null && {\n responseObject: responseBody.object,\n }),\n ...(choice.index != null && { choiceIndex: choice.index }),\n ...(choice.message.role != null && {\n messageRole: choice.message.role,\n }),\n ...(choice.message.tool_calls != null && {\n toolCallTypes: choice.message.tool_calls\n .map(toolCall => toolCall.type)\n .filter(type => type != null),\n }),\n ...(choice.logprobs != null && { logprobs: choice.logprobs }),\n ...(responseBody.system_fingerprint != null && {\n systemFingerprint: responseBody.system_fingerprint,\n }),\n },\n },\n request: { body: args },\n response: {\n ...getResponseMetadata(responseBody),\n headers: responseHeaders,\n body: rawResponse,\n },\n warnings,\n };\n }\n\n async doStream(\n options: LanguageModelV3CallOptions,\n ): Promise<LanguageModelV3StreamResult> {\n const { args, warnings } = await this.getArgs({ ...options });\n\n const body = {\n ...args,\n stream: true,\n stream_options: { include_usage: true },\n };\n\n const { responseHeaders, value: response } = await postJsonToApi({\n url: this.config.url({\n path: '/chat/completions',\n modelId: this.modelId,\n }),\n headers: combineHeaders(this.config.headers(), options.headers),\n body,\n failedResponseHandler: this.failedResponseHandler,\n successfulResponseHandler: createEventSourceResponseHandler(\n deepseekChatChunkSchema,\n ),\n abortSignal: options.abortSignal,\n fetch: this.config.fetch,\n });\n\n const toolCalls: Array<{\n id: string;\n type: 'function';\n function: {\n name: string;\n arguments: string;\n };\n hasFinished: boolean;\n }> = [];\n\n let finishReason: LanguageModelV3FinishReason = {\n unified: 'other',\n raw: undefined,\n };\n let usage: DeepSeekChatTokenUsage | undefined = undefined;\n let systemFingerprint: string | undefined = undefined;\n let isFirstChunk = true;\n const providerOptionsName = this.providerOptionsName;\n let isActiveReasoning = false;\n let isActiveText = false;\n let responseObject: 'chat.completion.chunk' | undefined;\n let choiceIndex: number | undefined;\n let messageRole: 'assistant' | undefined;\n const toolCallTypes = new Map<number, 'function'>();\n const contentLogprobs: DeepSeekChatLogprob[] = [];\n const reasoningLogprobs: DeepSeekChatLogprob[] = [];\n\n return {\n stream: response.pipeThrough(\n new TransformStream<\n ParseResult<InferSchema<typeof deepseekChatChunkSchema>>,\n LanguageModelV3StreamPart\n >({\n start(controller) {\n controller.enqueue({ type: 'stream-start', warnings });\n },\n\n transform(chunk, controller) {\n // Emit raw chunk if requested (before anything else)\n if (options.includeRawChunks) {\n controller.enqueue({ type: 'raw', rawValue: chunk.rawValue });\n }\n\n // handle failed chunk parsing / validation:\n if (!chunk.success) {\n finishReason = { unified: 'error', raw: undefined };\n controller.enqueue({ type: 'error', error: chunk.error });\n return;\n }\n const value = chunk.value;\n\n // handle error chunks:\n if ('error' in value) {\n finishReason = { unified: 'error', raw: undefined };\n controller.enqueue({ type: 'error', error: value.error.message });\n return;\n }\n\n if (isFirstChunk) {\n isFirstChunk = false;\n\n controller.enqueue({\n type: 'response-metadata',\n ...getResponseMetadata(value),\n });\n }\n\n if (value.usage != null) {\n usage = value.usage;\n }\n\n if (value.object != null) {\n responseObject = value.object;\n }\n\n // The fingerprint is repeated on stream chunks; keep the latest\n // non-null value in case it changes during the response.\n if (value.system_fingerprint != null) {\n systemFingerprint = value.system_fingerprint;\n }\n\n const choice = value.choices[0];\n\n if (choice?.index != null) {\n choiceIndex = choice.index;\n }\n\n if (choice?.finish_reason != null) {\n finishReason = {\n unified: mapDeepSeekFinishReason(choice.finish_reason),\n raw: choice.finish_reason,\n };\n }\n\n if (choice?.logprobs?.content != null) {\n contentLogprobs.push(...choice.logprobs.content);\n }\n\n if (choice?.logprobs?.reasoning_content != null) {\n reasoningLogprobs.push(...choice.logprobs.reasoning_content);\n }\n\n if (choice?.delta == null) {\n return;\n }\n\n const delta = choice.delta;\n\n if (delta.role != null) {\n messageRole = delta.role;\n }\n\n // enqueue reasoning before text deltas:\n const reasoningContent = delta.reasoning_content;\n if (reasoningContent) {\n if (!isActiveReasoning) {\n controller.enqueue({\n type: 'reasoning-start',\n id: 'reasoning-0',\n });\n isActiveReasoning = true;\n }\n\n controller.enqueue({\n type: 'reasoning-delta',\n id: 'reasoning-0',\n delta: reasoningContent,\n });\n }\n\n if (delta.content) {\n if (!isActiveText) {\n controller.enqueue({ type: 'text-start', id: 'txt-0' });\n isActiveText = true;\n }\n\n // end reasoning when text starts:\n if (isActiveReasoning) {\n controller.enqueue({\n type: 'reasoning-end',\n id: 'reasoning-0',\n });\n isActiveReasoning = false;\n }\n\n controller.enqueue({\n type: 'text-delta',\n id: 'txt-0',\n delta: delta.content,\n });\n }\n\n if (delta.tool_calls != null) {\n // end reasoning when tool calls start:\n if (isActiveReasoning) {\n controller.enqueue({\n type: 'reasoning-end',\n id: 'reasoning-0',\n });\n isActiveReasoning = false;\n }\n\n for (const toolCallDelta of delta.tool_calls) {\n if (toolCallDelta.type != null) {\n toolCallTypes.set(toolCallDelta.index, toolCallDelta.type);\n }\n\n const index = toolCallDelta.index;\n\n if (toolCalls[index] == null) {\n if (toolCallDelta.id == null) {\n throw new InvalidResponseDataError({\n data: toolCallDelta,\n message: `Expected 'id' to be a string.`,\n });\n }\n\n if (toolCallDelta.function?.name == null) {\n throw new InvalidResponseDataError({\n data: toolCallDelta,\n message: `Expected 'function.name' to be a string.`,\n });\n }\n\n controller.enqueue({\n type: 'tool-input-start',\n id: toolCallDelta.id,\n toolName: toolCallDelta.function.name,\n });\n\n toolCalls[index] = {\n id: toolCallDelta.id,\n type: 'function',\n function: {\n name: toolCallDelta.function.name,\n arguments: toolCallDelta.function.arguments ?? '',\n },\n hasFinished: false,\n };\n\n const toolCall = toolCalls[index];\n\n if (\n toolCall.function?.name != null &&\n toolCall.function?.arguments != null\n ) {\n // send delta if the argument text has already started:\n if (toolCall.function.arguments.length > 0) {\n controller.enqueue({\n type: 'tool-input-delta',\n id: toolCall.id,\n delta: toolCall.function.arguments,\n });\n }\n }\n\n continue;\n }\n\n // existing tool call, merge if not finished\n const toolCall = toolCalls[index];\n\n if (toolCall.hasFinished) {\n continue;\n }\n\n if (toolCallDelta.function?.arguments != null) {\n toolCall.function!.arguments +=\n toolCallDelta.function?.arguments ?? '';\n }\n\n // send delta\n controller.enqueue({\n type: 'tool-input-delta',\n id: toolCall.id,\n delta: toolCallDelta.function.arguments ?? '',\n });\n }\n }\n },\n\n flush(controller) {\n if (isActiveReasoning) {\n controller.enqueue({ type: 'reasoning-end', id: 'reasoning-0' });\n }\n\n if (isActiveText) {\n controller.enqueue({ type: 'text-end', id: 'txt-0' });\n }\n\n // go through all tool calls and send the ones that are not finished\n for (const toolCall of toolCalls.filter(\n toolCall => !toolCall.hasFinished,\n )) {\n controller.enqueue({\n type: 'tool-input-end',\n id: toolCall.id,\n });\n\n controller.enqueue({\n type: 'tool-call',\n toolCallId: toolCall.id ?? generateId(),\n toolName: toolCall.function.name,\n input: toolCall.function.arguments,\n });\n }\n\n controller.enqueue({\n type: 'finish',\n finishReason,\n usage: convertDeepSeekUsage(usage),\n providerMetadata: {\n [providerOptionsName]: {\n promptCacheHitTokens:\n usage?.prompt_cache_hit_tokens ?? undefined,\n promptCacheMissTokens:\n usage?.prompt_cache_miss_tokens ?? undefined,\n ...(responseObject != null && { responseObject }),\n ...(choiceIndex != null && { choiceIndex }),\n ...(messageRole != null && { messageRole }),\n ...(toolCallTypes.size > 0 && {\n toolCallTypes: [...toolCallTypes.entries()]\n .sort(([left], [right]) => left - right)\n .map(([, type]) => type),\n }),\n ...((contentLogprobs.length > 0 ||\n reasoningLogprobs.length > 0) && {\n logprobs: {\n ...(contentLogprobs.length > 0 && {\n content: contentLogprobs,\n }),\n ...(reasoningLogprobs.length > 0 && {\n reasoning_content: reasoningLogprobs,\n }),\n },\n }),\n ...(systemFingerprint != null && { systemFingerprint }),\n },\n },\n });\n },\n }),\n ),\n request: { body },\n response: { headers: responseHeaders },\n };\n }\n}\n","import {\n InvalidPromptError,\n UnsupportedFunctionalityError,\n type LanguageModelV3CallOptions,\n type LanguageModelV3Prompt,\n type SharedV3Warning,\n} from '@ai-sdk/provider';\nimport { convertToBase64, parseProviderOptions } from '@ai-sdk/provider-utils';\nimport type {\n DeepSeekChatPrompt,\n DeepSeekContentPart,\n} from './deepseek-chat-api-types';\nimport { deepseekAssistantMessageProviderOptions } from './deepseek-chat-options';\nimport { deepseekFilePartProviderOptions } from './deepseek-file-part-options';\n\nconst supportedImageMediaTypes = new Set([\n 'image/gif',\n 'image/jpeg',\n 'image/jpg',\n 'image/png',\n 'image/webp',\n]);\n\nexport async function convertToDeepSeekChatMessages({\n prompt,\n responseFormat,\n modelId,\n providerOptionsName = 'deepseek',\n supportsAssistantPrefixCompletion = false,\n supportsStructuredOutputs = false,\n}: {\n prompt: LanguageModelV3Prompt;\n responseFormat: LanguageModelV3CallOptions['responseFormat'];\n modelId: string;\n providerOptionsName?: string;\n supportsAssistantPrefixCompletion?: boolean;\n supportsStructuredOutputs?: boolean;\n}): Promise<{\n messages: DeepSeekChatPrompt;\n warnings: Array<SharedV3Warning>;\n}> {\n const isDeepSeekV4 = modelId.includes('deepseek-v4');\n const messages: DeepSeekChatPrompt = [];\n const warnings: Array<SharedV3Warning> = [];\n\n // Inject system message if response format is JSON\n if (responseFormat?.type === 'json') {\n if (responseFormat.schema == null) {\n messages.push({\n role: 'system',\n content: 'Return JSON.',\n });\n } else if (!supportsStructuredOutputs) {\n messages.push({\n role: 'system',\n content:\n 'Return JSON that conforms to the following schema: ' +\n JSON.stringify(responseFormat.schema),\n });\n warnings.push({\n type: 'compatibility',\n feature: 'responseFormat JSON schema',\n details: 'JSON response schema is injected into the system message.',\n });\n }\n }\n\n // TODO use findLastIndex once we use ES2023\n let lastUserMessageIndex = -1;\n for (let i = prompt.length - 1; i >= 0; i--) {\n if (prompt[i].role === 'user') {\n lastUserMessageIndex = i;\n break;\n }\n }\n\n let index = -1;\n for (const { role, content, providerOptions } of prompt) {\n index++;\n\n // The assistant schema extends the common message schema, so one parse\n // validates names for every role and the assistant-only prefix option.\n const deepseekMessageOptions = await parseProviderOptions({\n provider: providerOptionsName,\n providerOptions,\n schema: deepseekAssistantMessageProviderOptions,\n });\n\n if (deepseekMessageOptions?.prefix === true && role !== 'assistant') {\n throw new InvalidPromptError({\n prompt,\n message:\n 'DeepSeek assistant prefix completion requires `prefix: true` on an assistant message.',\n });\n }\n\n switch (role) {\n case 'system': {\n messages.push({\n role: 'system',\n content,\n ...(deepseekMessageOptions?.name != null && {\n name: deepseekMessageOptions.name,\n }),\n });\n break;\n }\n\n case 'user': {\n const hasImagePart = content.some(\n part =>\n part.type === 'file' &&\n (part.mediaType === 'image' || part.mediaType.startsWith('image/')),\n );\n\n if (!hasImagePart) {\n let userContent = '';\n for (const part of content) {\n if (part.type === 'text') {\n userContent += part.text;\n } else {\n warnings.push({\n type: 'unsupported',\n feature: `user message part type: ${part.type}`,\n });\n }\n }\n\n messages.push({\n role: 'user',\n content: userContent,\n ...(deepseekMessageOptions?.name != null && {\n name: deepseekMessageOptions.name,\n }),\n });\n break;\n }\n\n const userContent: Array<DeepSeekContentPart> = [];\n for (const part of content) {\n if (part.type === 'text') {\n userContent.push({ type: 'text', text: part.text });\n } else if (\n part.type === 'file' &&\n (part.mediaType === 'image' || part.mediaType.startsWith('image/'))\n ) {\n const filePartOptions = await parseProviderOptions({\n provider: providerOptionsName,\n providerOptions: part.providerOptions,\n schema: deepseekFilePartProviderOptions,\n });\n\n const resolvedMediaType =\n part.mediaType === 'image' || part.mediaType === 'image/*'\n ? 'image/jpeg'\n : part.mediaType;\n\n if (!supportedImageMediaTypes.has(resolvedMediaType)) {\n throw new UnsupportedFunctionalityError({\n functionality: `DeepSeek image media type ${resolvedMediaType}`,\n message:\n 'DeepSeek supports JPEG, PNG, GIF, and WebP image inputs.',\n });\n }\n\n if (part.data instanceof URL) {\n const url = part.data.toString();\n\n if (url.length > 8192) {\n throw new InvalidPromptError({\n prompt,\n message:\n 'DeepSeek image URLs must not exceed 8192 characters.',\n });\n }\n\n if (filePartOptions?.fileData === true) {\n throw new InvalidPromptError({\n prompt,\n message:\n 'DeepSeek `fileData` image parts require inline data, not a URL.',\n });\n }\n\n userContent.push({\n type: 'image_url',\n image_url: {\n url,\n ...(filePartOptions?.imageDetail != null && {\n detail: filePartOptions.imageDetail,\n }),\n },\n });\n } else {\n const dataUrl = `data:${\n resolvedMediaType === 'image/jpg'\n ? 'image/jpeg'\n : resolvedMediaType\n };base64,${convertToBase64(part.data)}`;\n\n if (filePartOptions?.fileData === true) {\n if (filePartOptions.imageDetail != null) {\n throw new InvalidPromptError({\n prompt,\n message:\n 'DeepSeek `imageDetail` cannot be combined with `fileData`.',\n });\n }\n\n userContent.push({\n type: 'file',\n file_data: dataUrl,\n ...(part.filename != null && { filename: part.filename }),\n });\n } else {\n userContent.push({\n type: 'image_url',\n image_url: {\n url: dataUrl,\n ...(filePartOptions?.imageDetail != null && {\n detail: filePartOptions.imageDetail,\n }),\n },\n });\n }\n }\n } else {\n warnings.push({\n type: 'unsupported',\n feature: `user message part type: ${part.type}`,\n });\n }\n }\n\n messages.push({\n role: 'user',\n content: userContent,\n ...(deepseekMessageOptions?.name != null && {\n name: deepseekMessageOptions.name,\n }),\n });\n\n break;\n }\n case 'assistant': {\n if (deepseekMessageOptions?.prefix === true) {\n if (index !== prompt.length - 1) {\n throw new InvalidPromptError({\n prompt,\n message:\n 'DeepSeek assistant prefix completion requires the prefixed assistant message to be the final message.',\n });\n }\n\n if (!supportsAssistantPrefixCompletion) {\n throw new UnsupportedFunctionalityError({\n functionality: 'DeepSeek assistant prefix completion',\n message:\n 'DeepSeek assistant prefix completion requires a beta base URL ending in `/beta`.',\n });\n }\n }\n\n let text = '';\n let reasoning: string | undefined;\n\n const toolCalls: Array<{\n id: string;\n type: 'function';\n function: { name: string; arguments: string };\n }> = [];\n\n for (const part of content) {\n switch (part.type) {\n case 'text': {\n text += part.text;\n break;\n }\n case 'reasoning': {\n // R1 must not receive prior reasoning; V4 requires it.\n if (index <= lastUserMessageIndex && !isDeepSeekV4) {\n break;\n }\n\n if (reasoning == null) {\n reasoning = part.text;\n } else {\n reasoning += part.text;\n }\n break;\n }\n case 'tool-call': {\n toolCalls.push({\n id: part.toolCallId,\n type: 'function',\n function: {\n name: part.toolName,\n arguments: JSON.stringify(part.input),\n },\n });\n break;\n }\n }\n }\n\n // V4 demands the field on every assistant turn — back-fill an empty\n // string when the source message had no reasoning part at all.\n messages.push({\n role: 'assistant',\n content: text,\n ...(deepseekMessageOptions?.name != null && {\n name: deepseekMessageOptions.name,\n }),\n ...(deepseekMessageOptions?.prefix === true && {\n prefix: true,\n }),\n reasoning_content: reasoning ?? (isDeepSeekV4 ? '' : undefined),\n tool_calls: toolCalls.length > 0 ? toolCalls : undefined,\n });\n\n break;\n }\n\n case 'tool': {\n if (deepseekMessageOptions?.name != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'message name on tool messages',\n });\n }\n\n for (const toolResponse of content) {\n if (toolResponse.type === 'tool-approval-response') {\n continue;\n }\n const output = toolResponse.output;\n\n let contentValue: string;\n switch (output.type) {\n case 'text':\n case 'error-text':\n contentValue = output.value;\n break;\n case 'execution-denied':\n contentValue = output.reason ?? 'Tool call execution denied.';\n break;\n case 'content':\n case 'json':\n case 'error-json':\n contentValue = JSON.stringify(output.value);\n break;\n }\n\n messages.push({\n role: 'tool',\n tool_call_id: toolResponse.toolCallId,\n content: contentValue,\n });\n }\n break;\n }\n\n default: {\n warnings.push({\n type: 'unsupported',\n feature: `message role: ${role}`,\n });\n break;\n }\n }\n }\n\n return { messages, warnings };\n}\n","import { z } from 'zod/v4';\n\n// https://api-docs.deepseek.com/quick_start/pricing\nexport type DeepSeekChatModelId =\n | 'deepseek-v4-flash'\n | 'deepseek-v4-pro'\n | 'deepseek-v4-flash-vision-exp'\n // Retired aliases remain assignable through the string escape hatch, but are\n // intentionally omitted from first-class editor suggestions.\n | (string & {});\n\nexport const deepseekLanguageModelOptions = z.object({\n /**\n * Whether to return log probabilities for generated tokens.\n */\n logprobs: z.boolean().optional(),\n\n /**\n * Number of most likely tokens to return at each token position.\n *\n * Setting this option automatically enables `logprobs`.\n */\n topLogprobs: z.number().int().min(0).max(20).optional(),\n\n /**\n * An opaque identifier for the end user. DeepSeek uses this identifier for\n * content-safety tracing and request isolation.\n *\n * Must contain only ASCII letters, numbers, underscores, and hyphens, and\n * must be at most 512 characters long.\n */\n userId: z\n .string()\n .regex(/^[a-zA-Z0-9_-]+$/, 'userId must match /^[a-zA-Z0-9_-]+$/')\n .max(512, 'userId must be at most 512 characters long')\n .optional(),\n\n /**\n * Type of thinking to use. Defaults to `enabled`.\n */\n thinking: z\n .object({\n // `adaptive` is accepted at runtime for backwards compatibility and\n // mapped to `enabled`, but is intentionally excluded from the exported\n // provider options type.\n type: z.enum(['adaptive', 'enabled', 'disabled']).optional(),\n })\n .optional(),\n\n /**\n * Controls the thinking strength for DeepSeek V4 reasoning models.\n */\n // `medium` and `xhigh` are accepted at runtime for backwards compatibility\n // and mapped to canonical DeepSeek values, but are intentionally excluded\n // from the exported provider options type.\n reasoningEffort: z.enum(['low', 'medium', 'high', 'xhigh', 'max']).optional(),\n\n /**\n * Whether to use strict JSON schema validation for structured outputs.\n * Only applies when the serving endpoint supports JSON schema response\n * formats (e.g. Azure). Defaults to `true`.\n */\n strictJsonSchema: z.boolean().optional(),\n});\n\nexport type DeepSeekLanguageModelOptions = {\n /**\n * Whether to return log probabilities for generated tokens.\n */\n logprobs?: boolean;\n\n /**\n * Number of most likely tokens to return at each token position.\n *\n * Setting this option automatically enables `logprobs`.\n */\n topLogprobs?: number;\n\n /**\n * An opaque identifier for the end user. DeepSeek uses this identifier for\n * content-safety tracing and request isolation.\n *\n * Must contain only ASCII letters, numbers, underscores, and hyphens, and\n * must be at most 512 characters long.\n */\n userId?: string;\n\n /**\n * Controls whether thinking mode is enabled. Defaults to `enabled`.\n */\n thinking?: {\n type?: 'enabled' | 'disabled';\n };\n\n /**\n * Controls the thinking strength for DeepSeek V4 reasoning models.\n */\n reasoningEffort?: 'low' | 'high' | 'max';\n\n /**\n * Whether to use strict JSON schema validation for structured outputs.\n * Only applies when the serving endpoint supports JSON schema response\n * formats (e.g. Azure). Defaults to `true`.\n */\n strictJsonSchema?: boolean;\n};\n\nexport const deepseekMessageProviderOptions = z.object({\n /**\n * The name of the participant represented by the message.\n *\n * Supported on system, user, and assistant messages.\n */\n name: z.string().optional(),\n});\n\nexport type DeepSeekMessageProviderOptions = z.infer<\n typeof deepseekMessageProviderOptions\n>;\n\nexport const deepseekAssistantMessageProviderOptions =\n deepseekMessageProviderOptions.extend({\n /**\n * Whether the assistant message content is a prefix that DeepSeek should\n * continue. This beta feature is only supported on the final assistant\n * message when using a beta base URL.\n */\n prefix: z.literal(true).optional(),\n });\n\nexport type DeepSeekAssistantMessageProviderOptions = z.infer<\n typeof deepseekAssistantMessageProviderOptions\n>;\n","import { z } from 'zod/v4';\n\nexport const deepseekFilePartProviderOptions = z.object({\n /**\n * Controls how DeepSeek processes an image sent as an `image_url` part.\n *\n * @see https://api-docs.deepseek.com/api/create-chat-completion/\n */\n imageDetail: z.enum(['low', 'high', 'original', 'auto']).optional(),\n\n /**\n * Sends inline image data as a DeepSeek `file` part using `file_data`\n * instead of an `image_url` data URL. When set, the file part's filename\n * is preserved.\n *\n * This option only applies to inline image data. It cannot be combined\n * with `imageDetail`.\n */\n fileData: z.literal(true).optional(),\n});\n\nexport type DeepSeekFilePartProviderOptions = z.infer<\n typeof deepseekFilePartProviderOptions\n>;\n","import type { LanguageModelV3Usage } from '@ai-sdk/provider';\n\nexport function convertDeepSeekUsage(\n usage:\n | {\n prompt_tokens?: number | null | undefined;\n completion_tokens?: number | null | undefined;\n prompt_cache_hit_tokens?: number | null | undefined;\n completion_tokens_details?:\n | {\n reasoning_tokens?: number | null | undefined;\n }\n | null\n | undefined;\n }\n | undefined\n | null,\n): LanguageModelV3Usage {\n if (usage == null) {\n return {\n inputTokens: {\n total: undefined,\n noCache: undefined,\n cacheRead: undefined,\n cacheWrite: undefined,\n },\n outputTokens: {\n total: undefined,\n text: undefined,\n reasoning: undefined,\n },\n raw: undefined,\n };\n }\n\n const promptTokens = usage.prompt_tokens ?? 0;\n const completionTokens = usage.completion_tokens ?? 0;\n const cacheReadTokens = usage.prompt_cache_hit_tokens ?? 0;\n const reasoningTokens =\n usage.completion_tokens_details?.reasoning_tokens ?? 0;\n\n return {\n inputTokens: {\n total: promptTokens,\n noCache: promptTokens - cacheReadTokens,\n cacheRead: cacheReadTokens,\n cacheWrite: undefined,\n },\n outputTokens: {\n total: completionTokens,\n text: Math.max(0, completionTokens - reasoningTokens),\n reasoning: reasoningTokens,\n },\n raw: usage,\n };\n}\n","import { lazySchema, zodSchema } from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\n\nexport type DeepSeekChatPrompt = Array<DeepSeekMessage>;\n\nexport type DeepSeekMessage =\n | DeepSeekSystemMessage\n | DeepSeekUserMessage\n | DeepSeekAssistantMessage\n | DeepSeekToolMessage;\n\nexport interface DeepSeekSystemMessage {\n role: 'system';\n content: string;\n name?: string;\n}\n\nexport interface DeepSeekUserMessage {\n role: 'user';\n content: string | Array<DeepSeekContentPart>;\n name?: string;\n}\n\nexport type DeepSeekContentPart =\n | DeepSeekContentPartText\n | DeepSeekContentPartImage\n | DeepSeekContentPartFile;\n\nexport interface DeepSeekContentPartText {\n type: 'text';\n text: string;\n}\n\nexport interface DeepSeekContentPartImage {\n type: 'image_url';\n image_url: {\n url: string;\n detail?: 'low' | 'high' | 'original' | 'auto';\n };\n}\n\nexport interface DeepSeekContentPartFile {\n type: 'file';\n file_data: string;\n filename?: string;\n}\nexport interface DeepSeekAssistantMessage {\n role: 'assistant';\n content?: string | null;\n name?: string;\n prefix?: true;\n reasoning_content?: string;\n tool_calls?: Array<DeepSeekMessageToolCall>;\n}\n\nexport interface DeepSeekMessageToolCall {\n type: 'function';\n id: string;\n function: {\n arguments: string;\n name: string;\n };\n}\n\nexport interface DeepSeekToolMessage {\n role: 'tool';\n content: string;\n tool_call_id: string;\n}\n\nexport interface DeepSeekFunctionTool {\n type: 'function';\n function: {\n name: string;\n description: string | undefined;\n parameters: unknown;\n strict?: boolean;\n };\n}\n\nexport type DeepSeekToolChoice =\n | { type: 'function'; function: { name: string } }\n | 'auto'\n | 'none'\n | 'required'\n | undefined;\n\n// Loose, nested objects included: the parsed value is returned as `usage.raw`.\nconst tokenUsageSchema = z\n .looseObject({\n prompt_tokens: z.number().nullish(),\n completion_tokens: z.number().nullish(),\n prompt_cache_hit_tokens: z.number().nullish(),\n prompt_cache_miss_tokens: z.number().nullish(),\n total_tokens: z.number().nullish(),\n prompt_tokens_details: z\n .looseObject({\n cached_tokens: z.number().nullish(),\n })\n .nullish(),\n completion_tokens_details: z\n .looseObject({\n reasoning_tokens: z.number().nullish(),\n })\n .nullish(),\n })\n .nullish();\n\nexport type DeepSeekChatTokenUsage = z.infer<typeof tokenUsageSchema>;\n\nexport const deepSeekErrorSchema = z.object({\n error: z.object({\n message: z.string(),\n type: z.string().nullish(),\n param: z.any().nullish(),\n code: z.union([z.string(), z.number()]).nullish(),\n }),\n});\n\nexport type DeepSeekErrorData = z.infer<typeof deepSeekErrorSchema>;\n\nconst deepseekChatLogprobSchema = z.object({\n token: z.string(),\n logprob: z.number(),\n bytes: z.array(z.number()).nullable(),\n top_logprobs: z.array(\n z.object({\n token: z.string(),\n logprob: z.number(),\n bytes: z.array(z.number()).nullable(),\n }),\n ),\n});\n\nconst deepseekChatLogprobsSchema = z\n .object({\n content: z.array(deepseekChatLogprobSchema).nullish(),\n reasoning_content: z.array(deepseekChatLogprobSchema).nullish(),\n })\n .nullish();\n\nexport type DeepSeekChatLogprob = z.infer<typeof deepseekChatLogprobSchema>;\n\n// limited version of the schema, focussed on what is needed for the implementation\n// this approach limits breakages when the API changes and increases efficiency\nexport const deepseekChatResponseSchema = z.object({\n id: z.string().nullish(),\n created: z.number().nullish(),\n model: z.string().nullish(),\n object: z.literal('chat.completion').nullish(),\n system_fingerprint: z.string().nullish(),\n choices: z.array(\n z.object({\n index: z.number().nullish(),\n message: z.object({\n role: z.literal('assistant').nullish(),\n content: z.string().nullish(),\n reasoning_content: z.string().nullish(),\n tool_calls: z\n .array(\n z.object({\n id: z.string().nullish(),\n type: z.literal('function').nullish(),\n function: z.object({\n name: z.string(),\n arguments: z.string(),\n }),\n }),\n )\n .nullish(),\n }),\n logprobs: deepseekChatLogprobsSchema,\n finish_reason: z.string().nullish(),\n }),\n ),\n usage: tokenUsageSchema,\n});\n\n// limited version of the schema, focussed on what is needed for the implementation\n// this approach limits breakages when the API changes and increases efficiency\nexport const deepseekChatChunkSchema = lazySchema(() =>\n zodSchema(\n z.union([\n z.object({\n id: z.string().nullish(),\n created: z.number().nullish(),\n model: z.string().nullish(),\n object: z.literal('chat.completion.chunk').nullish(),\n system_fingerprint: z.string().nullish(),\n choices: z.array(\n z.object({\n index: z.number().nullish(),\n delta: z\n .object({\n role: z.enum(['assistant']).nullish(),\n content: z.string().nullish(),\n reasoning_content: z.string().nullish(),\n tool_calls: z\n .array(\n z.object({\n index: z.number(),\n id: z.string().nullish(),\n type: z.literal('function').nullish(),\n function: z.object({\n name: z.string().nullish(),\n arguments: z.string().nullish(),\n }),\n }),\n )\n .nullish(),\n })\n .nullish(),\n logprobs: deepseekChatLogprobsSchema,\n finish_reason: z.string().nullish(),\n }),\n ),\n usage: tokenUsageSchema,\n }),\n deepSeekErrorSchema,\n ]),\n ),\n);\n","import {\n UnsupportedFunctionalityError,\n type LanguageModelV3CallOptions,\n type SharedV3Warning,\n} from '@ai-sdk/provider';\nimport type {\n DeepSeekFunctionTool,\n DeepSeekToolChoice,\n} from './deepseek-chat-api-types';\n\nexport function prepareTools({\n tools,\n toolChoice,\n supportsStrictToolCalls,\n}: {\n tools: LanguageModelV3CallOptions['tools'];\n toolChoice?: LanguageModelV3CallOptions['toolChoice'];\n supportsStrictToolCalls?: boolean;\n}): {\n tools: undefined | Array<DeepSeekFunctionTool>;\n toolChoice: DeepSeekToolChoice;\n toolWarnings: SharedV3Warning[];\n} {\n // when the tools array is empty, change it to undefined to prevent errors:\n tools = tools?.length ? tools : undefined;\n\n const toolWarnings: SharedV3Warning[] = [];\n\n if (tools == null) {\n return { tools: undefined, toolChoice: undefined, toolWarnings };\n }\n\n const functionTools = tools.filter(tool => tool.type === 'function');\n const hasStrictTool = functionTools.some(tool => tool.strict === true);\n\n if (hasStrictTool && supportsStrictToolCalls === false) {\n throw new UnsupportedFunctionalityError({\n functionality: 'DeepSeek strict tool calls',\n message:\n 'DeepSeek strict tool calls require a beta base URL ending in `/beta`.',\n });\n }\n\n if (\n hasStrictTool &&\n supportsStrictToolCalls === true &&\n functionTools.some(tool => tool.strict !== true)\n ) {\n throw new UnsupportedFunctionalityError({\n functionality: 'mixed DeepSeek strict and non-strict tool calls',\n message:\n 'DeepSeek strict mode requires every function tool in the request to set `strict: true`.',\n });\n }\n\n const deepseekTools: Array<DeepSeekFunctionTool> = [];\n\n for (const tool of tools) {\n if (tool.type === 'provider') {\n toolWarnings.push({\n type: 'unsupported',\n feature: `provider-defined tool ${tool.id}`,\n });\n } else {\n deepseekTools.push({\n type: 'function',\n function: {\n name: tool.name,\n description: tool.description,\n parameters: tool.inputSchema,\n ...(tool.strict != null ? { strict: tool.strict } : {}),\n },\n });\n }\n }\n\n if (toolChoice == null) {\n return { tools: deepseekTools, toolChoice: undefined, toolWarnings };\n }\n\n const type = toolChoice?.type;\n\n switch (type) {\n case 'auto':\n case 'none':\n case 'required':\n return { tools: deepseekTools, toolChoice: type, toolWarnings };\n case 'tool':\n return {\n tools: deepseekTools,\n toolChoice: {\n type: 'function',\n function: { name: toolChoice.toolName },\n },\n toolWarnings,\n };\n default: {\n return {\n tools: deepseekTools,\n toolChoice: undefined,\n toolWarnings: [\n ...toolWarnings,\n {\n type: 'unsupported',\n feature: `tool choice type: ${type}`,\n },\n ],\n };\n }\n }\n}\n","export function getResponseMetadata({\n id,\n model,\n created,\n}: {\n id?: string | undefined | null;\n created?: number | undefined | null;\n model?: string | undefined | null;\n}) {\n return {\n id: id ?? undefined,\n modelId: model ?? undefined,\n timestamp: created != null ? new Date(created * 1000) : undefined,\n };\n}\n","import type { LanguageModelV3FinishReason } from '@ai-sdk/provider';\n\nexport function mapDeepSeekFinishReason(\n finishReason: string | null | undefined,\n): LanguageModelV3FinishReason['unified'] {\n switch (finishReason) {\n case 'stop':\n return 'stop';\n case 'length':\n return 'length';\n case 'content_filter':\n return 'content-filter';\n case 'tool_calls':\n return 'tool-calls';\n case 'insufficient_system_resource':\n return 'error';\n default:\n return 'other';\n }\n}\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,mBAIO;AACP,IAAAC,yBAKO;;;ACVP,IAAAC,mBAWO;AACP,IAAAC,yBAYO;;;ACxBP,sBAMO;AACP,4BAAsD;;;ACPtD,gBAAkB;AAWX,IAAM,+BAA+B,YAAE,OAAO;AAAA;AAAA;AAAA;AAAA,EAInD,UAAU,YAAE,QAAQ,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO/B,aAAa,YAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAStD,QAAQ,YACL,OAAO,EACP,MAAM,oBAAoB,sCAAsC,EAChE,I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AG,OAAO,GAAG,IAAI;AAAA,MACpC,SAAS;AAAA,MACT,OAAO,QAAQ;AAAA,MACf,mCAAmC,QAAQ,SAAS,OAAO;AAAA,MAC3D,yBAAyB,QAAQ,SAAS,OAAO;AAAA,IACnD,CAAC;AAAA,EACH;AAEA,QAAM,WAAW,CAAC,YAChB,oBAAoB,OAAO;AAE7B,WAAS,uBAAuB;AAChC,WAAS,gBAAgB;AACzB,WAAS,OAAO;AAEhB,WAAS,iBAAiB,CAAC,YAAoB;AAC7C,UAAM,IAAI,kCAAiB,EAAE,SAAS,WAAW,iBAAiB,CAAC;AAAA,EACrE;AACA,WAAS,qBAAqB,SAAS;AACvC,WAAS,aAAa,CAAC,YAAoB;AACzC,UAAM,IAAI,kCAAiB,EAAE,SAAS,WAAW,aAAa,CAAC;AAAA,EACjE;AAEA,SAAO;AACT;AAEO,IAAM,WAAW,eAAe;","names":["import_provider","import_provider_utils","import_provider","import_provider_utils","import_v4","userContent","import_provider_utils","import_v4","import_provider","toolCall"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/deepseek-provider.ts","../src/chat/deepseek-chat-language-model.ts","../src/chat/convert-to-deepseek-chat-messages.ts","../src/chat/deepseek-chat-options.ts","../src/chat/deepseek-file-part-options.ts","../src/chat/is-deepseek-v4-model.ts","../src/chat/convert-to-deepseek-usage.ts","../src/chat/deepseek-chat-api-types.ts","../src/chat/deepseek-prepare-tools.ts","../src/chat/get-response-metadata.ts","../src/chat/map-deepseek-finish-reason.ts","../src/version.ts"],"sourcesContent":["export { createDeepSeek, deepseek } from './deepseek-provider';\nexport type {\n DeepSeekProvider,\n DeepSeekProviderSettings,\n} from './deepseek-provider';\nexport { VERSION } from './version';\nexport type {\n DeepSeekAssistantMessageProviderOptions,\n DeepSeekLanguageModelOptions,\n DeepSeekMessageProviderOptions,\n /** @deprecated Use `DeepSeekLanguageModelOptions` instead. */\n DeepSeekLanguageModelOptions as DeepSeekChatOptions,\n} from './chat/deepseek-chat-options';\nexport type { DeepSeekErrorData } from './chat/deepseek-chat-api-types';\nexport type { DeepSeekFilePartProviderOptions } from './chat/deepseek-file-part-options';\n","import {\n NoSuchModelError,\n type LanguageModelV3,\n type ProviderV3,\n} from '@ai-sdk/provider';\nimport {\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport type { DeepSeekChatModelId } from './chat/deepseek-chat-options';\nimport { DeepSeekChatLanguageModel } from './chat/deepseek-chat-language-model';\nimport { VERSION } from './version';\n\nexport interface DeepSeekProviderSettings {\n /**\n * DeepSeek API key.\n */\n apiKey?: string;\n\n /**\n * Base URL for the API calls.\n */\n baseURL?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface DeepSeekProvider extends ProviderV3 {\n /**\n * Creates a DeepSeek model for text generation.\n */\n (modelId: DeepSeekChatModelId): LanguageModelV3;\n\n /**\n * Creates a DeepSeek model for text generation.\n */\n languageModel(modelId: DeepSeekChatModelId): LanguageModelV3;\n\n /**\n * Creates a DeepSeek chat model for text generation.\n */\n chat(modelId: DeepSeekChatModelId): LanguageModelV3;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nexport function createDeepSeek(\n options: DeepSeekProviderSettings = {},\n): DeepSeekProvider {\n const baseURL =\n withoutTrailingSlash(options.baseURL) ?? 'https://api.deepseek.com';\n\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'DEEPSEEK_API_KEY',\n description: 'DeepSeek API key',\n })}`,\n ...options.headers,\n },\n `ai-sdk/deepseek/${VERSION}`,\n );\n\n const createLanguageModel = (modelId: DeepSeekChatModelId) => {\n return new DeepSeekChatLanguageModel(modelId, {\n provider: `deepseek.chat`,\n url: ({ path }) => `${baseURL}${path}`,\n headers: getHeaders,\n fetch: options.fetch,\n supportsAssistantPrefixCompletion: baseURL.endsWith('/beta'),\n supportsStrictToolCalls: baseURL.endsWith('/beta'),\n });\n };\n\n const provider = (modelId: DeepSeekChatModelId) =>\n createLanguageModel(modelId);\n\n provider.specificationVersion = 'v3' as const;\n provider.languageModel = createLanguageModel;\n provider.chat = createLanguageModel;\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n return provider;\n}\n\nexport const deepseek = createDeepSeek();\n","import {\n InvalidResponseDataError,\n type APICallError,\n type LanguageModelV3,\n type LanguageModelV3CallOptions,\n type LanguageModelV3Content,\n type LanguageModelV3FinishReason,\n type LanguageModelV3GenerateResult,\n type LanguageModelV3StreamPart,\n type LanguageModelV3StreamResult,\n type SharedV3Warning,\n} from '@ai-sdk/provider';\nimport {\n combineHeaders,\n createEventSourceResponseHandler,\n createJsonErrorResponseHandler,\n createJsonResponseHandler,\n generateId,\n parseProviderOptions,\n postJsonToApi,\n type FetchFunction,\n type InferSchema,\n type ParseResult,\n type ResponseHandler,\n} from '@ai-sdk/provider-utils';\nimport { convertToDeepSeekChatMessages } from './convert-to-deepseek-chat-messages';\nimport { convertDeepSeekUsage } from './convert-to-deepseek-usage';\nimport {\n deepseekChatChunkSchema,\n deepseekChatResponseSchema,\n deepSeekErrorSchema,\n type DeepSeekChatLogprob,\n type DeepSeekChatTokenUsage,\n} from './deepseek-chat-api-types';\nimport {\n deepseekLanguageModelOptions,\n type DeepSeekChatModelId,\n} from './deepseek-chat-options';\nimport { prepareTools } from './deepseek-prepare-tools';\nimport { getResponseMetadata } from './get-response-metadata';\nimport { isDeepSeekV4Model } from './is-deepseek-v4-model';\nimport { mapDeepSeekFinishReason } from './map-deepseek-finish-reason';\n\nexport type DeepSeekChatConfig = {\n provider: string;\n headers: () => Record<string, string | undefined>;\n url: (options: { modelId: string; path: string }) => string;\n fetch?: FetchFunction;\n supportsAssistantPrefixCompletion?: boolean;\n supportsPenaltySampling?: boolean;\n supportsStrictToolCalls?: boolean;\n supportsThinking?: boolean;\n supportsStructuredOutputs?: boolean;\n};\n\nfunction mapDeepSeekProviderReasoningEffort({\n reasoningEffort,\n warnings,\n}: {\n reasoningEffort: 'low' | 'medium' | 'high' | 'xhigh' | 'max';\n warnings: SharedV3Warning[];\n}): 'low' | 'high' | 'max' {\n const mapped =\n reasoningEffort === 'medium'\n ? 'high'\n : reasoningEffort === 'xhigh'\n ? 'max'\n : reasoningEffort;\n\n if (mapped !== reasoningEffort) {\n warnings.push({\n type: 'compatibility',\n feature: 'reasoningEffort',\n details: `reasoningEffort \"${reasoningEffort}\" is not a canonical DeepSeek value. mapped to \"${mapped}\".`,\n });\n }\n\n return mapped;\n}\n\nexport class DeepSeekChatLanguageModel implements LanguageModelV3 {\n readonly specificationVersion = 'v3';\n\n readonly modelId: DeepSeekChatModelId;\n\n readonly supportedUrls = {\n 'image/*': [/^https?:\\/\\/.*$/],\n };\n\n private readonly config: DeepSeekChatConfig;\n private readonly failedResponseHandler: ResponseHandler<APICallError>;\n\n constructor(modelId: DeepSeekChatModelId, config: DeepSeekChatConfig) {\n this.modelId = modelId;\n this.config = config;\n\n this.failedResponseHandler = createJsonErrorResponseHandler({\n errorSchema: deepSeekErrorSchema,\n errorToMessage: (error: InferSchema<typeof deepSeekErrorSchema>) =>\n error.error.message,\n });\n }\n\n get provider(): string {\n return this.config.provider;\n }\n\n private get providerOptionsName(): string {\n return this.config.provider.split('.')[0].trim();\n }\n\n private async getArgs({\n prompt,\n maxOutputTokens,\n temperature,\n topP,\n topK,\n frequencyPenalty,\n presencePenalty,\n providerOptions,\n stopSequences,\n responseFormat,\n seed,\n toolChoice,\n tools,\n }: LanguageModelV3CallOptions) {\n const deepseekOptions =\n (await parseProviderOptions({\n provider: this.providerOptionsName,\n providerOptions,\n schema: deepseekLanguageModelOptions,\n })) ?? {};\n\n const supportsStructuredOutputs =\n this.config.supportsStructuredOutputs === true;\n const supportsPenaltySampling =\n this.config.supportsPenaltySampling === true;\n\n const { messages, warnings } = await convertToDeepSeekChatMessages({\n prompt,\n responseFormat,\n modelId: this.modelId,\n providerOptionsName: this.providerOptionsName,\n supportsAssistantPrefixCompletion:\n this.config.supportsAssistantPrefixCompletion,\n supportsStructuredOutputs,\n });\n const allWarnings = [...warnings];\n\n if (topK != null) {\n allWarnings.push({ type: 'unsupported', feature: 'topK' });\n }\n\n if (seed != null) {\n allWarnings.push({ type: 'unsupported', feature: 'seed' });\n }\n\n if (!supportsPenaltySampling && frequencyPenalty != null) {\n allWarnings.push({\n type: 'other',\n message:\n 'frequencyPenalty is deprecated by DeepSeek and has been omitted. Remove frequencyPenalty from the request.',\n });\n }\n\n if (!supportsPenaltySampling && presencePenalty != null) {\n allWarnings.push({\n type: 'other',\n message:\n 'presencePenalty is deprecated by DeepSeek and has been omitted. Remove presencePenalty from the request.',\n });\n }\n\n const {\n tools: deepseekTools,\n toolChoice: deepseekToolChoices,\n toolWarnings,\n } = prepareTools({\n tools,\n toolChoice,\n supportsStrictToolCalls: this.config.supportsStrictToolCalls,\n });\n allWarnings.push(...toolWarnings);\n\n const thinkingType = deepseekOptions.thinking?.type;\n if (thinkingType === 'adaptive') {\n allWarnings.push({\n type: 'compatibility',\n feature: 'thinking.type',\n details:\n 'thinking.type \"adaptive\" is not a canonical DeepSeek value. mapped to \"enabled\".',\n });\n }\n\n const thinking =\n this.config.supportsThinking === false\n ? undefined\n : thinkingType != null\n ? { type: thinkingType === 'adaptive' ? 'enabled' : thinkingType }\n : undefined;\n\n const isThinkingEnabled =\n this.config.supportsThinking !== false &&\n thinking?.type !== 'disabled' &&\n (thinking != null ||\n this.modelId === 'deepseek-reasoner' ||\n isDeepSeekV4Model(this.modelId));\n\n if (isThinkingEnabled && temperature != null) {\n allWarnings.push({\n type: 'unsupported',\n feature: 'temperature',\n details:\n \"temperature has no effect when DeepSeek thinking is enabled. Set providerOptions.deepseek.thinking.type to 'disabled' to use temperature.\",\n });\n }\n\n if (isThinkingEnabled && topP != null) {\n allWarnings.push({\n type: 'unsupported',\n feature: 'topP',\n details:\n \"topP has no effect when DeepSeek thinking is enabled. Set providerOptions.deepseek.thinking.type to 'disabled' to use topP.\",\n });\n }\n\n const reasoningEffort =\n deepseekOptions.reasoningEffort != null\n ? mapDeepSeekProviderReasoningEffort({\n reasoningEffort: deepseekOptions.reasoningEffort,\n warnings: allWarnings,\n })\n : undefined;\n\n return {\n args: {\n model: this.modelId,\n ...((deepseekOptions.logprobs === true ||\n deepseekOptions.topLogprobs != null) && { logprobs: true }),\n ...(deepseekOptions.topLogprobs != null && {\n top_logprobs: deepseekOptions.topLogprobs,\n }),\n max_tokens: maxOutputTokens,\n temperature: isThinkingEnabled ? undefined : temperature,\n top_p: isThinkingEnabled ? undefined : topP,\n frequency_penalty: supportsPenaltySampling\n ? frequencyPenalty\n : undefined,\n presence_penalty: supportsPenaltySampling ? presencePenalty : undefined,\n response_format:\n responseFormat?.type === 'json'\n ? supportsStructuredOutputs && responseFormat.schema != null\n ? {\n type: 'json_schema',\n json_schema: {\n schema: responseFormat.schema,\n strict: deepseekOptions.strictJsonSchema ?? true,\n name: responseFormat.name ?? 'response',\n description: responseFormat.description,\n },\n }\n : { type: 'json_object' }\n : undefined,\n stop: stopSequences,\n messages,\n tools: deepseekTools,\n tool_choice: deepseekToolChoices,\n thinking,\n ...(deepseekOptions.userId != null && {\n user_id: deepseekOptions.userId,\n }),\n ...(thinking?.type !== 'disabled' &&\n reasoningEffort != null && {\n reasoning_effort: reasoningEffort,\n }),\n },\n warnings: allWarnings,\n };\n }\n\n async doGenerate(\n options: LanguageModelV3CallOptions,\n ): Promise<LanguageModelV3GenerateResult> {\n const { args, warnings } = await this.getArgs({ ...options });\n\n const {\n responseHeaders,\n value: responseBody,\n rawValue: rawResponse,\n } = await postJsonToApi({\n url: this.config.url({\n path: '/chat/completions',\n modelId: this.modelId,\n }),\n headers: combineHeaders(this.config.headers(), options.headers),\n body: args,\n failedResponseHandler: this.failedResponseHandler,\n successfulResponseHandler: createJsonResponseHandler(\n deepseekChatResponseSchema,\n ),\n abortSignal: options.abortSignal,\n fetch: this.config.fetch,\n });\n\n const choice = responseBody.choices[0];\n const content: Array<LanguageModelV3Content> = [];\n\n // reasoning content (before text):\n const reasoning = choice.message.reasoning_content;\n if (reasoning != null && reasoning.length > 0) {\n content.push({\n type: 'reasoning',\n text: reasoning,\n });\n }\n\n // tool calls:\n if (choice.message.tool_calls != null) {\n for (const toolCall of choice.message.tool_calls) {\n content.push({\n type: 'tool-call',\n toolCallId: toolCall.id ?? generateId(),\n toolName: toolCall.function.name,\n input: toolCall.function.arguments!,\n });\n }\n }\n\n // text content:\n const text = choice.message.content;\n if (text != null && text.length > 0) {\n content.push({ type: 'text', text });\n }\n\n return {\n content,\n finishReason: {\n unified: mapDeepSeekFinishReason(choice.finish_reason),\n raw: choice.finish_reason ?? undefined,\n },\n usage: convertDeepSeekUsage(responseBody.usage),\n providerMetadata: {\n [this.providerOptionsName]: {\n promptCacheHitTokens: responseBody.usage?.prompt_cache_hit_tokens,\n promptCacheMissTokens: responseBody.usage?.prompt_cache_miss_tokens,\n ...(responseBody.object != null && {\n responseObject: responseBody.object,\n }),\n ...(choice.index != null && { choiceIndex: choice.index }),\n ...(choice.message.role != null && {\n messageRole: choice.message.role,\n }),\n ...(choice.message.tool_calls != null && {\n toolCallTypes: choice.message.tool_calls\n .map(toolCall => toolCall.type)\n .filter(type => type != null),\n }),\n ...(choice.logprobs != null && { logprobs: choice.logprobs }),\n ...(responseBody.system_fingerprint != null && {\n systemFingerprint: responseBody.system_fingerprint,\n }),\n },\n },\n request: { body: args },\n response: {\n ...getResponseMetadata(responseBody),\n headers: responseHeaders,\n body: rawResponse,\n },\n warnings,\n };\n }\n\n async doStream(\n options: LanguageModelV3CallOptions,\n ): Promise<LanguageModelV3StreamResult> {\n const { args, warnings } = await this.getArgs({ ...options });\n\n const body = {\n ...args,\n stream: true,\n stream_options: { include_usage: true },\n };\n\n const { responseHeaders, value: response } = await postJsonToApi({\n url: this.config.url({\n path: '/chat/completions',\n modelId: this.modelId,\n }),\n headers: combineHeaders(this.config.headers(), options.headers),\n body,\n failedResponseHandler: this.failedResponseHandler,\n successfulResponseHandler: createEventSourceResponseHandler(\n deepseekChatChunkSchema,\n ),\n abortSignal: options.abortSignal,\n fetch: this.config.fetch,\n });\n\n const toolCalls: Array<{\n id: string;\n type: 'function';\n function: {\n name: string;\n arguments: string;\n };\n hasFinished: boolean;\n }> = [];\n\n let finishReason: LanguageModelV3FinishReason = {\n unified: 'other',\n raw: undefined,\n };\n let usage: DeepSeekChatTokenUsage | undefined = undefined;\n let systemFingerprint: string | undefined = undefined;\n let isFirstChunk = true;\n const providerOptionsName = this.providerOptionsName;\n let isActiveReasoning = false;\n let isActiveText = false;\n let responseObject: 'chat.completion.chunk' | undefined;\n let choiceIndex: number | undefined;\n let messageRole: 'assistant' | undefined;\n const toolCallTypes = new Map<number, 'function'>();\n const contentLogprobs: DeepSeekChatLogprob[] = [];\n const reasoningLogprobs: DeepSeekChatLogprob[] = [];\n\n return {\n stream: response.pipeThrough(\n new TransformStream<\n ParseResult<InferSchema<typeof deepseekChatChunkSchema>>,\n LanguageModelV3StreamPart\n >({\n start(controller) {\n controller.enqueue({ type: 'stream-start', warnings });\n },\n\n transform(chunk, controller) {\n // Emit raw chunk if requested (before anything else)\n if (options.includeRawChunks) {\n controller.enqueue({ type: 'raw', rawValue: chunk.rawValue });\n }\n\n // handle failed chunk parsing / validation:\n if (!chunk.success) {\n finishReason = { unified: 'error', raw: undefined };\n controller.enqueue({ type: 'error', error: chunk.error });\n return;\n }\n const value = chunk.value;\n\n // handle error chunks:\n if ('error' in value) {\n finishReason = { unified: 'error', raw: undefined };\n controller.enqueue({ type: 'error', error: value.error.message });\n return;\n }\n\n if (isFirstChunk) {\n isFirstChunk = false;\n\n controller.enqueue({\n type: 'response-metadata',\n ...getResponseMetadata(value),\n });\n }\n\n if (value.usage != null) {\n usage = value.usage;\n }\n\n if (value.object != null) {\n responseObject = value.object;\n }\n\n // The fingerprint is repeated on stream chunks; keep the latest\n // non-null value in case it changes during the response.\n if (value.system_fingerprint != null) {\n systemFingerprint = value.system_fingerprint;\n }\n\n const choice = value.choices[0];\n\n if (choice?.index != null) {\n choiceIndex = choice.index;\n }\n\n if (choice?.finish_reason != null) {\n finishReason = {\n unified: mapDeepSeekFinishReason(choice.finish_reason),\n raw: choice.finish_reason,\n };\n }\n\n if (choice?.logprobs?.content != null) {\n contentLogprobs.push(...choice.logprobs.content);\n }\n\n if (choice?.logprobs?.reasoning_content != null) {\n reasoningLogprobs.push(...choice.logprobs.reasoning_content);\n }\n\n if (choice?.delta == null) {\n return;\n }\n\n const delta = choice.delta;\n\n if (delta.role != null) {\n messageRole = delta.role;\n }\n\n // enqueue reasoning before text deltas:\n const reasoningContent = delta.reasoning_content;\n if (reasoningContent) {\n if (!isActiveReasoning) {\n controller.enqueue({\n type: 'reasoning-start',\n id: 'reasoning-0',\n });\n isActiveReasoning = true;\n }\n\n controller.enqueue({\n type: 'reasoning-delta',\n id: 'reasoning-0',\n delta: reasoningContent,\n });\n }\n\n if (delta.content) {\n if (!isActiveText) {\n controller.enqueue({ type: 'text-start', id: 'txt-0' });\n isActiveText = true;\n }\n\n // end reasoning when text starts:\n if (isActiveReasoning) {\n controller.enqueue({\n type: 'reasoning-end',\n id: 'reasoning-0',\n });\n isActiveReasoning = false;\n }\n\n controller.enqueue({\n type: 'text-delta',\n id: 'txt-0',\n delta: delta.content,\n });\n }\n\n if (delta.tool_calls != null && delta.tool_calls.length > 0) {\n // end reasoning when tool calls start:\n if (isActiveReasoning) {\n controller.enqueue({\n type: 'reasoning-end',\n id: 'reasoning-0',\n });\n isActiveReasoning = false;\n }\n\n for (const toolCallDelta of delta.tool_calls) {\n if (toolCallDelta.type != null) {\n toolCallTypes.set(toolCallDelta.index, toolCallDelta.type);\n }\n\n const index = toolCallDelta.index;\n\n if (toolCalls[index] == null) {\n if (toolCallDelta.id == null) {\n throw new InvalidResponseDataError({\n data: toolCallDelta,\n message: `Expected 'id' to be a string.`,\n });\n }\n\n if (toolCallDelta.function?.name == null) {\n throw new InvalidResponseDataError({\n data: toolCallDelta,\n message: `Expected 'function.name' to be a string.`,\n });\n }\n\n controller.enqueue({\n type: 'tool-input-start',\n id: toolCallDelta.id,\n toolName: toolCallDelta.function.name,\n });\n\n toolCalls[index] = {\n id: toolCallDelta.id,\n type: 'function',\n function: {\n name: toolCallDelta.function.name,\n arguments: toolCallDelta.function.arguments ?? '',\n },\n hasFinished: false,\n };\n\n const toolCall = toolCalls[index];\n\n if (\n toolCall.function?.name != null &&\n toolCall.function?.arguments != null\n ) {\n // send delta if the argument text has already started:\n if (toolCall.function.arguments.length > 0) {\n controller.enqueue({\n type: 'tool-input-delta',\n id: toolCall.id,\n delta: toolCall.function.arguments,\n });\n }\n }\n\n continue;\n }\n\n // existing tool call, merge if not finished\n const toolCall = toolCalls[index];\n\n if (toolCall.hasFinished) {\n continue;\n }\n\n if (toolCallDelta.function?.arguments != null) {\n toolCall.function!.arguments +=\n toolCallDelta.function?.arguments ?? '';\n }\n\n // send delta\n controller.enqueue({\n type: 'tool-input-delta',\n id: toolCall.id,\n delta: toolCallDelta.function.arguments ?? '',\n });\n }\n }\n },\n\n flush(controller) {\n if (isActiveReasoning) {\n controller.enqueue({ type: 'reasoning-end', id: 'reasoning-0' });\n }\n\n if (isActiveText) {\n controller.enqueue({ type: 'text-end', id: 'txt-0' });\n }\n\n // go through all tool calls and send the ones that are not finished\n for (const toolCall of toolCalls.filter(\n toolCall => !toolCall.hasFinished,\n )) {\n controller.enqueue({\n type: 'tool-input-end',\n id: toolCall.id,\n });\n\n controller.enqueue({\n type: 'tool-call',\n toolCallId: toolCall.id ?? generateId(),\n toolName: toolCall.function.name,\n input: toolCall.function.arguments,\n });\n }\n\n controller.enqueue({\n type: 'finish',\n finishReason,\n usage: convertDeepSeekUsage(usage),\n providerMetadata: {\n [providerOptionsName]: {\n promptCacheHitTokens:\n usage?.prompt_cache_hit_tokens ?? undefined,\n promptCacheMissTokens:\n usage?.prompt_cache_miss_tokens ?? undefined,\n ...(responseObject != null && { responseObject }),\n ...(choiceIndex != null && { choiceIndex }),\n ...(messageRole != null && { messageRole }),\n ...(toolCallTypes.size > 0 && {\n toolCallTypes: [...toolCallTypes.entries()]\n .sort(([left], [right]) => left - right)\n .map(([, type]) => type),\n }),\n ...((contentLogprobs.length > 0 ||\n reasoningLogprobs.length > 0) && {\n logprobs: {\n ...(contentLogprobs.length > 0 && {\n content: contentLogprobs,\n }),\n ...(reasoningLogprobs.length > 0 && {\n reasoning_content: reasoningLogprobs,\n }),\n },\n }),\n ...(systemFingerprint != null && { systemFingerprint }),\n },\n },\n });\n },\n }),\n ),\n request: { body },\n response: { headers: responseHeaders },\n };\n }\n}\n","import {\n InvalidPromptError,\n UnsupportedFunctionalityError,\n type LanguageModelV3CallOptions,\n type LanguageModelV3Prompt,\n type SharedV3Warning,\n} from '@ai-sdk/provider';\nimport { convertToBase64, parseProviderOptions } from '@ai-sdk/provider-utils';\nimport type {\n DeepSeekChatPrompt,\n DeepSeekContentPart,\n} from './deepseek-chat-api-types';\nimport { deepseekAssistantMessageProviderOptions } from './deepseek-chat-options';\nimport { deepseekFilePartProviderOptions } from './deepseek-file-part-options';\nimport { isDeepSeekV4Model } from './is-deepseek-v4-model';\n\nconst supportedImageMediaTypes = new Set([\n 'image/gif',\n 'image/jpeg',\n 'image/jpg',\n 'image/png',\n 'image/webp',\n]);\n\nexport async function convertToDeepSeekChatMessages({\n prompt,\n responseFormat,\n modelId,\n providerOptionsName = 'deepseek',\n supportsAssistantPrefixCompletion = false,\n supportsStructuredOutputs = false,\n}: {\n prompt: LanguageModelV3Prompt;\n responseFormat: LanguageModelV3CallOptions['responseFormat'];\n modelId: string;\n providerOptionsName?: string;\n supportsAssistantPrefixCompletion?: boolean;\n supportsStructuredOutputs?: boolean;\n}): Promise<{\n messages: DeepSeekChatPrompt;\n warnings: Array<SharedV3Warning>;\n}> {\n const isDeepSeekV4 = isDeepSeekV4Model(modelId);\n const messages: DeepSeekChatPrompt = [];\n const warnings: Array<SharedV3Warning> = [];\n\n // Inject system message if response format is JSON\n if (responseFormat?.type === 'json') {\n if (responseFormat.schema == null) {\n messages.push({\n role: 'system',\n content: 'Return JSON.',\n });\n } else if (!supportsStructuredOutputs) {\n messages.push({\n role: 'system',\n content:\n 'Return JSON that conforms to the following schema: ' +\n JSON.stringify(responseFormat.schema),\n });\n warnings.push({\n type: 'compatibility',\n feature: 'responseFormat JSON schema',\n details: 'JSON response schema is injected into the system message.',\n });\n }\n }\n\n // TODO use findLastIndex once we use ES2023\n let lastUserMessageIndex = -1;\n for (let i = prompt.length - 1; i >= 0; i--) {\n if (prompt[i].role === 'user') {\n lastUserMessageIndex = i;\n break;\n }\n }\n\n let index = -1;\n for (const { role, content, providerOptions } of prompt) {\n index++;\n\n // The assistant schema extends the common message schema, so one parse\n // validates names for every role and the assistant-only prefix option.\n const deepseekMessageOptions = await parseProviderOptions({\n provider: providerOptionsName,\n providerOptions,\n schema: deepseekAssistantMessageProviderOptions,\n });\n\n if (deepseekMessageOptions?.prefix === true && role !== 'assistant') {\n throw new InvalidPromptError({\n prompt,\n message:\n 'DeepSeek assistant prefix completion requires `prefix: true` on an assistant message.',\n });\n }\n\n switch (role) {\n case 'system': {\n messages.push({\n role: 'system',\n content,\n ...(deepseekMessageOptions?.name != null && {\n name: deepseekMessageOptions.name,\n }),\n });\n break;\n }\n\n case 'user': {\n const hasImagePart = content.some(\n part =>\n part.type === 'file' &&\n (part.mediaType === 'image' || part.mediaType.startsWith('image/')),\n );\n\n if (!hasImagePart) {\n let userContent = '';\n for (const part of content) {\n if (part.type === 'text') {\n userContent += part.text;\n } else {\n warnings.push({\n type: 'unsupported',\n feature: `user message part type: ${part.type}`,\n });\n }\n }\n\n messages.push({\n role: 'user',\n content: userContent,\n ...(deepseekMessageOptions?.name != null && {\n name: deepseekMessageOptions.name,\n }),\n });\n break;\n }\n\n const userContent: Array<DeepSeekContentPart> = [];\n for (const part of content) {\n if (part.type === 'text') {\n userContent.push({ type: 'text', text: part.text });\n } else if (\n part.type === 'file' &&\n (part.mediaType === 'image' || part.mediaType.startsWith('image/'))\n ) {\n const filePartOptions = await parseProviderOptions({\n provider: providerOptionsName,\n providerOptions: part.providerOptions,\n schema: deepseekFilePartProviderOptions,\n });\n\n const resolvedMediaType =\n part.mediaType === 'image' || part.mediaType === 'image/*'\n ? 'image/jpeg'\n : part.mediaType;\n\n if (!supportedImageMediaTypes.has(resolvedMediaType)) {\n throw new UnsupportedFunctionalityError({\n functionality: `DeepSeek image media type ${resolvedMediaType}`,\n message:\n 'DeepSeek supports JPEG, PNG, GIF, and WebP image inputs.',\n });\n }\n\n if (part.data instanceof URL) {\n const url = part.data.toString();\n\n if (url.length > 8192) {\n throw new InvalidPromptError({\n prompt,\n message:\n 'DeepSeek image URLs must not exceed 8192 characters.',\n });\n }\n\n if (filePartOptions?.fileData === true) {\n throw new InvalidPromptError({\n prompt,\n message:\n 'DeepSeek `fileData` image parts require inline data, not a URL.',\n });\n }\n\n userContent.push({\n type: 'image_url',\n image_url: {\n url,\n ...(filePartOptions?.imageDetail != null && {\n detail: filePartOptions.imageDetail,\n }),\n },\n });\n } else {\n const dataUrl = `data:${\n resolvedMediaType === 'image/jpg'\n ? 'image/jpeg'\n : resolvedMediaType\n };base64,${convertToBase64(part.data)}`;\n\n if (filePartOptions?.fileData === true) {\n if (filePartOptions.imageDetail != null) {\n throw new InvalidPromptError({\n prompt,\n message:\n 'DeepSeek `imageDetail` cannot be combined with `fileData`.',\n });\n }\n\n userContent.push({\n type: 'file',\n file_data: dataUrl,\n ...(part.filename != null && { filename: part.filename }),\n });\n } else {\n userContent.push({\n type: 'image_url',\n image_url: {\n url: dataUrl,\n ...(filePartOptions?.imageDetail != null && {\n detail: filePartOptions.imageDetail,\n }),\n },\n });\n }\n }\n } else {\n warnings.push({\n type: 'unsupported',\n feature: `user message part type: ${part.type}`,\n });\n }\n }\n\n messages.push({\n role: 'user',\n content: userContent,\n ...(deepseekMessageOptions?.name != null && {\n name: deepseekMessageOptions.name,\n }),\n });\n\n break;\n }\n case 'assistant': {\n if (deepseekMessageOptions?.prefix === true) {\n if (index !== prompt.length - 1) {\n throw new InvalidPromptError({\n prompt,\n message:\n 'DeepSeek assistant prefix completion requires the prefixed assistant message to be the final message.',\n });\n }\n\n if (!supportsAssistantPrefixCompletion) {\n throw new UnsupportedFunctionalityError({\n functionality: 'DeepSeek assistant prefix completion',\n message:\n 'DeepSeek assistant prefix completion requires a beta base URL ending in `/beta`.',\n });\n }\n }\n\n let text = '';\n let reasoning: string | undefined;\n\n const toolCalls: Array<{\n id: string;\n type: 'function';\n function: { name: string; arguments: string };\n }> = [];\n\n for (const part of content) {\n switch (part.type) {\n case 'text': {\n text += part.text;\n break;\n }\n case 'reasoning': {\n // R1 must not receive prior reasoning; V4 requires it.\n if (index <= lastUserMessageIndex && !isDeepSeekV4) {\n break;\n }\n\n if (reasoning == null) {\n reasoning = part.text;\n } else {\n reasoning += part.text;\n }\n break;\n }\n case 'tool-call': {\n toolCalls.push({\n id: part.toolCallId,\n type: 'function',\n function: {\n name: part.toolName,\n arguments: JSON.stringify(part.input),\n },\n });\n break;\n }\n }\n }\n\n // V4 demands the field on every assistant turn — back-fill an empty\n // string when the source message had no reasoning part at all.\n messages.push({\n role: 'assistant',\n content: text,\n ...(deepseekMessageOptions?.name != null && {\n name: deepseekMessageOptions.name,\n }),\n ...(deepseekMessageOptions?.prefix === true && {\n prefix: true,\n }),\n reasoning_content: reasoning ?? (isDeepSeekV4 ? '' : undefined),\n tool_calls: toolCalls.length > 0 ? toolCalls : undefined,\n });\n\n break;\n }\n\n case 'tool': {\n if (deepseekMessageOptions?.name != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'message name on tool messages',\n });\n }\n\n for (const toolResponse of content) {\n if (toolResponse.type === 'tool-approval-response') {\n continue;\n }\n const output = toolResponse.output;\n\n let contentValue: string;\n switch (output.type) {\n case 'text':\n case 'error-text':\n contentValue = output.value;\n break;\n case 'execution-denied':\n contentValue = output.reason ?? 'Tool call execution denied.';\n break;\n case 'content':\n case 'json':\n case 'error-json':\n contentValue = JSON.stringify(output.value);\n break;\n }\n\n messages.push({\n role: 'tool',\n tool_call_id: toolResponse.toolCallId,\n content: contentValue,\n });\n }\n break;\n }\n\n default: {\n warnings.push({\n type: 'unsupported',\n feature: `message role: ${role}`,\n });\n break;\n }\n }\n }\n\n return { messages, warnings };\n}\n","import { z } from 'zod/v4';\n\n// https://api-docs.deepseek.com/quick_start/pricing\nexport type DeepSeekChatModelId =\n | 'deepseek-flash'\n | 'deepseek-v4-flash'\n | 'deepseek-v4-pro'\n | 'deepseek-v4-flash-vision-exp'\n // Retired aliases remain assignable through the string escape hatch, but are\n // intentionally omitted from first-class editor suggestions.\n | (string & {});\n\nexport const deepseekLanguageModelOptions = z.object({\n /**\n * Whether to return log probabilities for generated tokens.\n */\n logprobs: z.boolean().optional(),\n\n /**\n * Number of most likely tokens to return at each token position.\n *\n * Setting this option automatically enables `logprobs`.\n */\n topLogprobs: z.number().int().min(0).max(20).optional(),\n\n /**\n * An opaque identifier for the end user. DeepSeek uses this identifier for\n * content-safety tracing and request isolation.\n *\n * Must contain only ASCII letters, numbers, underscores, and hyphens, and\n * must be at most 512 characters long.\n */\n userId: z\n .string()\n .regex(/^[a-zA-Z0-9_-]+$/, 'userId must match /^[a-zA-Z0-9_-]+$/')\n .max(512, 'userId must be at most 512 characters long')\n .optional(),\n\n /**\n * Type of thinking to use. Defaults to `enabled`.\n */\n thinking: z\n .object({\n // `adaptive` is accepted at runtime for backwards compatibility and\n // mapped to `enabled`, but is intentionally excluded from the exported\n // provider options type.\n type: z.enum(['adaptive', 'enabled', 'disabled']).optional(),\n })\n .optional(),\n\n /**\n * Controls the thinking strength for DeepSeek V4 reasoning models.\n */\n // `medium` and `xhigh` are accepted at runtime for backwards compatibility\n // and mapped to canonical DeepSeek values, but are intentionally excluded\n // from the exported provider options type.\n reasoningEffort: z.enum(['low', 'medium', 'high', 'xhigh', 'max']).optional(),\n\n /**\n * Whether to use strict JSON schema validation for structured outputs.\n * Only applies when the serving endpoint supports JSON schema response\n * formats (e.g. Azure). Defaults to `true`.\n */\n strictJsonSchema: z.boolean().optional(),\n});\n\nexport type DeepSeekLanguageModelOptions = {\n /**\n * Whether to return log probabilities for generated tokens.\n */\n logprobs?: boolean;\n\n /**\n * Number of most likely tokens to return at each token position.\n *\n * Setting this option automatically enables `logprobs`.\n */\n topLogprobs?: number;\n\n /**\n * An opaque identifier for the end user. DeepSeek uses this identifier for\n * content-safety tracing and request isolation.\n *\n * Must contain only ASCII letters, numbers, underscores, and hyphens, and\n * must be at most 512 characters long.\n */\n userId?: string;\n\n /**\n * Controls whether thinking mode is enabled. Defaults to `enabled`.\n */\n thinking?: {\n type?: 'enabled' | 'disabled';\n };\n\n /**\n * Controls the thinking strength for DeepSeek V4 reasoning models.\n */\n reasoningEffort?: 'low' | 'high' | 'max';\n\n /**\n * Whether to use strict JSON schema validation for structured outputs.\n * Only applies when the serving endpoint supports JSON schema response\n * formats (e.g. Azure). Defaults to `true`.\n */\n strictJsonSchema?: boolean;\n};\n\nexport const deepseekMessageProviderOptions = z.object({\n /**\n * The name of the participant represented by the message.\n *\n * Supported on system, user, and assistant messages.\n */\n name: z.string().optional(),\n});\n\nexport type DeepSeekMessageProviderOptions = z.infer<\n typeof deepseekMessageProviderOptions\n>;\n\nexport const deepseekAssistantMessageProviderOptions =\n deepseekMessageProviderOptions.extend({\n /**\n * Whether the assistant message content is a prefix that DeepSeek should\n * continue. This beta feature is only supported on the final assistant\n * message when using a beta base URL.\n */\n prefix: z.literal(true).optional(),\n });\n\nexport type DeepSeekAssistantMessageProviderOptions = z.infer<\n typeof deepseekAssistantMessageProviderOptions\n>;\n","import { z } from 'zod/v4';\n\nexport const deepseekFilePartProviderOptions = z.object({\n /**\n * Controls how DeepSeek processes an image sent as an `image_url` part.\n *\n * @see https://api-docs.deepseek.com/api/create-chat-completion/\n */\n imageDetail: z.enum(['low', 'high', 'original', 'auto']).optional(),\n\n /**\n * Sends inline image data as a DeepSeek `file` part using `file_data`\n * instead of an `image_url` data URL. When set, the file part's filename\n * is preserved.\n *\n * This option only applies to inline image data. It cannot be combined\n * with `imageDetail`.\n */\n fileData: z.literal(true).optional(),\n});\n\nexport type DeepSeekFilePartProviderOptions = z.infer<\n typeof deepseekFilePartProviderOptions\n>;\n","/**\n * Whether a model id is a DeepSeek V4-generation model (thinking mode on by\n * default, `reasoning_content` required on every assistant turn).\n *\n * DeepSeek publishes V4 models under both versioned ids (`deepseek-v4-pro`,\n * `deepseek-v4-flash-*`) and unversioned aliases (`deepseek-flash`, currently\n * serving V4.1 Flash). Only the legacy `deepseek-chat` / `deepseek-reasoner`\n * ids predate V4.\n */\nexport function isDeepSeekV4Model(modelId: string): boolean {\n return (\n modelId.includes('deepseek-v4') ||\n modelId.startsWith('deepseek-flash') ||\n modelId.startsWith('deepseek-pro')\n );\n}\n","import type { LanguageModelV3Usage } from '@ai-sdk/provider';\n\nexport function convertDeepSeekUsage(\n usage:\n | {\n prompt_tokens?: number | null | undefined;\n completion_tokens?: number | null | undefined;\n prompt_cache_hit_tokens?: number | null | undefined;\n completion_tokens_details?:\n | {\n reasoning_tokens?: number | null | undefined;\n }\n | null\n | undefined;\n }\n | undefined\n | null,\n): LanguageModelV3Usage {\n if (usage == null) {\n return {\n inputTokens: {\n total: undefined,\n noCache: undefined,\n cacheRead: undefined,\n cacheWrite: undefined,\n },\n outputTokens: {\n total: undefined,\n text: undefined,\n reasoning: undefined,\n },\n raw: undefined,\n };\n }\n\n const promptTokens = usage.prompt_tokens ?? 0;\n const completionTokens = usage.completion_tokens ?? 0;\n const cacheReadTokens = usage.prompt_cache_hit_tokens ?? 0;\n const reasoningTokens =\n usage.completion_tokens_details?.reasoning_tokens ?? 0;\n\n return {\n inputTokens: {\n total: promptTokens,\n noCache: promptTokens - cacheReadTokens,\n cacheRead: cacheReadTokens,\n cacheWrite: undefined,\n },\n outputTokens: {\n total: completionTokens,\n text: Math.max(0, completionTokens - reasoningTokens),\n reasoning: reasoningTokens,\n },\n raw: usage,\n };\n}\n","import { lazySchema, zodSchema } from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\n\nexport type DeepSeekChatPrompt = Array<DeepSeekMessage>;\n\nexport type DeepSeekMessage =\n | DeepSeekSystemMessage\n | DeepSeekUserMessage\n | DeepSeekAssistantMessage\n | DeepSeekToolMessage;\n\nexport interface DeepSeekSystemMessage {\n role: 'system';\n content: string;\n name?: string;\n}\n\nexport interface DeepSeekUserMessage {\n role: 'user';\n content: string | Array<DeepSeekContentPart>;\n name?: string;\n}\n\nexport type DeepSeekContentPart =\n | DeepSeekContentPartText\n | DeepSeekContentPartImage\n | DeepSeekContentPartFile;\n\nexport interface DeepSeekContentPartText {\n type: 'text';\n text: string;\n}\n\nexport interface DeepSeekContentPartImage {\n type: 'image_url';\n image_url: {\n url: string;\n detail?: 'low' | 'high' | 'original' | 'auto';\n };\n}\n\nexport interface DeepSeekContentPartFile {\n type: 'file';\n file_data: string;\n filename?: string;\n}\nexport interface DeepSeekAssistantMessage {\n role: 'assistant';\n content?: string | null;\n name?: string;\n prefix?: true;\n reasoning_content?: string;\n tool_calls?: Array<DeepSeekMessageToolCall>;\n}\n\nexport interface DeepSeekMessageToolCall {\n type: 'function';\n id: string;\n function: {\n arguments: string;\n name: string;\n };\n}\n\nexport interface DeepSeekToolMessage {\n role: 'tool';\n content: string;\n tool_call_id: string;\n}\n\nexport interface DeepSeekFunctionTool {\n type: 'function';\n function: {\n name: string;\n description: string | undefined;\n parameters: unknown;\n strict?: boolean;\n };\n}\n\nexport type DeepSeekToolChoice =\n | { type: 'function'; function: { name: string } }\n | 'auto'\n | 'none'\n | 'required'\n | undefined;\n\n// Loose, nested objects included: the parsed value is returned as `usage.raw`.\nconst tokenUsageSchema = z\n .looseObject({\n prompt_tokens: z.number().nullish(),\n completion_tokens: z.number().nullish(),\n prompt_cache_hit_tokens: z.number().nullish(),\n prompt_cache_miss_tokens: z.number().nullish(),\n total_tokens: z.number().nullish(),\n prompt_tokens_details: z\n .looseObject({\n cached_tokens: z.number().nullish(),\n })\n .nullish(),\n completion_tokens_details: z\n .looseObject({\n reasoning_tokens: z.number().nullish(),\n })\n .nullish(),\n })\n .nullish();\n\nexport type DeepSeekChatTokenUsage = z.infer<typeof tokenUsageSchema>;\n\nexport const deepSeekErrorSchema = z.object({\n error: z.object({\n message: z.string(),\n type: z.string().nullish(),\n param: z.any().nullish(),\n code: z.union([z.string(), z.number()]).nullish(),\n }),\n});\n\nexport type DeepSeekErrorData = z.infer<typeof deepSeekErrorSchema>;\n\nconst deepseekChatLogprobSchema = z.object({\n token: z.string(),\n logprob: z.number(),\n bytes: z.array(z.number()).nullable(),\n top_logprobs: z.array(\n z.object({\n token: z.string(),\n logprob: z.number(),\n bytes: z.array(z.number()).nullable(),\n }),\n ),\n});\n\nconst deepseekChatLogprobsSchema = z\n .object({\n content: z.array(deepseekChatLogprobSchema).nullish(),\n reasoning_content: z.array(deepseekChatLogprobSchema).nullish(),\n })\n .nullish();\n\nexport type DeepSeekChatLogprob = z.infer<typeof deepseekChatLogprobSchema>;\n\n// limited version of the schema, focussed on what is needed for the implementation\n// this approach limits breakages when the API changes and increases efficiency\nexport const deepseekChatResponseSchema = z.object({\n id: z.string().nullish(),\n created: z.number().nullish(),\n model: z.string().nullish(),\n object: z.literal('chat.completion').nullish(),\n system_fingerprint: z.string().nullish(),\n choices: z.array(\n z.object({\n index: z.number().nullish(),\n message: z.object({\n role: z.literal('assistant').nullish(),\n content: z.string().nullish(),\n reasoning_content: z.string().nullish(),\n tool_calls: z\n .array(\n z.object({\n id: z.string().nullish(),\n type: z.literal('function').nullish(),\n function: z.object({\n name: z.string(),\n arguments: z.string(),\n }),\n }),\n )\n .nullish(),\n }),\n logprobs: deepseekChatLogprobsSchema,\n finish_reason: z.string().nullish(),\n }),\n ),\n usage: tokenUsageSchema,\n});\n\n// limited version of the schema, focussed on what is needed for the implementation\n// this approach limits breakages when the API changes and increases efficiency\nexport const deepseekChatChunkSchema = lazySchema(() =>\n zodSchema(\n z.union([\n z.object({\n id: z.string().nullish(),\n created: z.number().nullish(),\n model: z.string().nullish(),\n object: z.literal('chat.completion.chunk').nullish(),\n system_fingerprint: z.string().nullish(),\n choices: z.array(\n z.object({\n index: z.number().nullish(),\n delta: z\n .object({\n role: z.enum(['assistant']).nullish(),\n content: z.string().nullish(),\n reasoning_content: z.string().nullish(),\n tool_calls: z\n .array(\n z.object({\n index: z.number(),\n id: z.string().nullish(),\n type: z.literal('function').nullish(),\n function: z.object({\n name: z.string().nullish(),\n arguments: z.string().nullish(),\n }),\n }),\n )\n .nullish(),\n })\n .nullish(),\n logprobs: deepseekChatLogprobsSchema,\n finish_reason: z.string().nullish(),\n }),\n ),\n usage: tokenUsageSchema,\n }),\n deepSeekErrorSchema,\n ]),\n ),\n);\n","import {\n UnsupportedFunctionalityError,\n type LanguageModelV3CallOptions,\n type SharedV3Warning,\n} from '@ai-sdk/provider';\nimport type {\n DeepSeekFunctionTool,\n DeepSeekToolChoice,\n} from './deepseek-chat-api-types';\n\nexport function prepareTools({\n tools,\n toolChoice,\n supportsStrictToolCalls,\n}: {\n tools: LanguageModelV3CallOptions['tools'];\n toolChoice?: LanguageModelV3CallOptions['toolChoice'];\n supportsStrictToolCalls?: boolean;\n}): {\n tools: undefined | Array<DeepSeekFunctionTool>;\n toolChoice: DeepSeekToolChoice;\n toolWarnings: SharedV3Warning[];\n} {\n // when the tools array is empty, change it to undefined to prevent errors:\n tools = tools?.length ? tools : undefined;\n\n const toolWarnings: SharedV3Warning[] = [];\n\n if (tools == null) {\n return { tools: undefined, toolChoice: undefined, toolWarnings };\n }\n\n const functionTools = tools.filter(tool => tool.type === 'function');\n const hasStrictTool = functionTools.some(tool => tool.strict === true);\n\n if (hasStrictTool && supportsStrictToolCalls === false) {\n throw new UnsupportedFunctionalityError({\n functionality: 'DeepSeek strict tool calls',\n message:\n 'DeepSeek strict tool calls require a beta base URL ending in `/beta`.',\n });\n }\n\n if (\n hasStrictTool &&\n supportsStrictToolCalls === true &&\n functionTools.some(tool => tool.strict !== true)\n ) {\n throw new UnsupportedFunctionalityError({\n functionality: 'mixed DeepSeek strict and non-strict tool calls',\n message:\n 'DeepSeek strict mode requires every function tool in the request to set `strict: true`.',\n });\n }\n\n const deepseekTools: Array<DeepSeekFunctionTool> = [];\n\n for (const tool of tools) {\n if (tool.type === 'provider') {\n toolWarnings.push({\n type: 'unsupported',\n feature: `provider-defined tool ${tool.id}`,\n });\n } else {\n deepseekTools.push({\n type: 'function',\n function: {\n name: tool.name,\n description: tool.description,\n parameters: tool.inputSchema,\n ...(tool.strict != null ? { strict: tool.strict } : {}),\n },\n });\n }\n }\n\n if (toolChoice == null) {\n return { tools: deepseekTools, toolChoice: undefined, toolWarnings };\n }\n\n const type = toolChoice?.type;\n\n switch (type) {\n case 'auto':\n case 'none':\n case 'required':\n return { tools: deepseekTools, toolChoice: type, toolWarnings };\n case 'tool':\n return {\n tools: deepseekTools,\n toolChoice: {\n type: 'function',\n function: { name: toolChoice.toolName },\n },\n toolWarnings,\n };\n default: {\n return {\n tools: deepseekTools,\n toolChoice: undefined,\n toolWarnings: [\n ...toolWarnings,\n {\n type: 'unsupported',\n feature: `tool choice type: ${type}`,\n },\n ],\n };\n }\n }\n}\n","export function getResponseMetadata({\n id,\n model,\n created,\n}: {\n id?: string | undefined | null;\n created?: number | undefined | null;\n model?: string | undefined | null;\n}) {\n return {\n id: id ?? undefined,\n modelId: model ?? undefined,\n timestamp: created != null ? new Date(created * 1000) : undefined,\n };\n}\n","import type { LanguageModelV3FinishReason } from '@ai-sdk/provider';\n\nexport function mapDeepSeekFinishReason(\n finishReason: string | null | undefined,\n): LanguageModelV3FinishReason['unified'] {\n switch (finishReason) {\n case 'stop':\n return 'stop';\n case 'length':\n return 'length';\n case 'content_filter':\n return 'content-filter';\n case 'tool_calls':\n return 'tool-calls';\n case 'insufficient_system_resource':\n return 'error';\n default:\n return 'other';\n }\n}\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,mBAIO;AACP,IAAAC,yBAKO;;;ACVP,IAAAC,mBAWO;AACP,IAAAC,yBAYO;;;ACxBP,sBAMO;AACP,4BAAsD;;;ACPtD,gBAAkB;AAYX,IAAM,+BAA+B,YAAE,OAAO;AAAA;AAAA;AAAA;AAAA,EAInD,UAAU,YAAE,QAAQ,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO/B,aAAa,YAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAStD,QAAQ,YACL,OAAO,EACP,MAAM,oBAAoB,sCAAsC,EAChE,IAAI,KAAK,4CAA4C,EACrD,SAAS;AAAA;AAAA;AAAA;AAAA,EAKZ,UAAU,YACP,OAAO;AAAA;AAAA;AAAA;AAAA,IAIN,MAAM,YAAE,KAAK,CAAC,YAAY,WAAW,UAAU,CAAC,EAAE,SAAS;AAAA,EAC7D,CAAC,EACA,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQZ,iBAAiB,YAAE,KAAK,CAAC,OAAO,UAAU,QAAQ,SAAS,KAAK,CAAC,EAAE,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;A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B,WAAS,uBAAuB;AAChC,WAAS,gBAAgB;AACzB,WAAS,OAAO;AAEhB,WAAS,iBAAiB,CAAC,YAAoB;AAC7C,UAAM,IAAI,kCAAiB,EAAE,SAAS,WAAW,iBAAiB,CAAC;AAAA,EACrE;AACA,WAAS,qBAAqB,SAAS;AACvC,WAAS,aAAa,CAAC,YAAoB;AACzC,UAAM,IAAI,kCAAiB,EAAE,SAAS,WAAW,aAAa,CAAC;AAAA,EACjE;AAEA,SAAO;AACT;AAEO,IAAM,WAAW,eAAe;","names":["import_provider","import_provider_utils","import_provider","import_provider_utils","import_v4","userContent","import_provider_utils","import_v4","import_provider","toolCall"]}
package/dist/index.mjs CHANGED
@@ -110,6 +110,11 @@ var deepseekFilePartProviderOptions = z2.object({
110
110
  fileData: z2.literal(true).optional()
111
111
  });
112
112
 
113
+ // src/chat/is-deepseek-v4-model.ts
114
+ function isDeepSeekV4Model(modelId) {
115
+ return modelId.includes("deepseek-v4") || modelId.startsWith("deepseek-flash") || modelId.startsWith("deepseek-pro");
116
+ }
117
+
113
118
  // src/chat/convert-to-deepseek-chat-messages.ts
114
119
  var supportedImageMediaTypes = /* @__PURE__ */ new Set([
115
120
  "image/gif",
@@ -127,7 +132,7 @@ async function convertToDeepSeekChatMessages({
127
132
  supportsStructuredOutputs = false
128
133
  }) {
129
134
  var _a;
130
- const isDeepSeekV4 = modelId.includes("deepseek-v4");
135
+ const isDeepSeekV4 = isDeepSeekV4Model(modelId);
131
136
  const messages = [];
132
137
  const warnings = [];
133
138
  if ((responseFormat == null ? void 0 : responseFormat.type) === "json") {
@@ -759,7 +764,7 @@ var DeepSeekChatLanguageModel = class {
759
764
  });
760
765
  }
761
766
  const thinking = this.config.supportsThinking === false ? void 0 : thinkingType != null ? { type: thinkingType === "adaptive" ? "enabled" : thinkingType } : void 0;
762
- const isThinkingEnabled = this.config.supportsThinking !== false && (thinking == null ? void 0 : thinking.type) !== "disabled" && (thinking != null || this.modelId === "deepseek-reasoner" || this.modelId.includes("deepseek-v4"));
767
+ const isThinkingEnabled = this.config.supportsThinking !== false && (thinking == null ? void 0 : thinking.type) !== "disabled" && (thinking != null || this.modelId === "deepseek-reasoner" || isDeepSeekV4Model(this.modelId));
763
768
  if (isThinkingEnabled && temperature != null) {
764
769
  allWarnings.push({
765
770
  type: "unsupported",
@@ -1026,7 +1031,7 @@ var DeepSeekChatLanguageModel = class {
1026
1031
  delta: delta.content
1027
1032
  });
1028
1033
  }
1029
- if (delta.tool_calls != null) {
1034
+ if (delta.tool_calls != null && delta.tool_calls.length > 0) {
1030
1035
  if (isActiveReasoning) {
1031
1036
  controller.enqueue({
1032
1037
  type: "reasoning-end",
@@ -1153,7 +1158,7 @@ var DeepSeekChatLanguageModel = class {
1153
1158
  };
1154
1159
 
1155
1160
  // src/version.ts
1156
- var VERSION = true ? "2.0.63" : "0.0.0-test";
1161
+ var VERSION = true ? "2.0.64" : "0.0.0-test";
1157
1162
 
1158
1163
  // src/deepseek-provider.ts
1159
1164
  function createDeepSeek(options = {}) {