diff --git a/packages/api/src/files/encode/document.spec.ts b/packages/api/src/files/encode/document.spec.ts index 846b61eb8883..a528b2ca4743 100644 --- a/packages/api/src/files/encode/document.spec.ts +++ b/packages/api/src/files/encode/document.spec.ts @@ -948,6 +948,29 @@ describe('encodeAndFormatDocuments - fileConfig integration', () => { expect(result.files).toHaveLength(1); }); + it('should skip file blocks for DeepSeek models routed through the OpenAI provider', async () => { + const req = createMockRequest(15) as ServerRequest; + const mimeType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; + const file = createMockDocFile(1, mimeType, 'brief.docx'); + + const mockContent = Buffer.from('docx-binary-content').toString('base64'); + mockedGetFileStream.mockResolvedValue({ + file, + content: mockContent, + metadata: file, + }); + + const result = await encodeAndFormatDocuments( + req, + [file], + { provider: Providers.OPENAI, model: 'deepseek-v4-pro' }, + mockStrategyFunctions, + ); + + expect(result.documents).toHaveLength(0); + expect(result.files).toHaveLength(0); + }); + it('should skip non-Bedrock-document types for Bedrock provider', async () => { const req = createMockRequest() as ServerRequest; const file = createMockDocFile(1, 'application/zip', 'archive.zip'); diff --git a/packages/api/src/files/encode/document.ts b/packages/api/src/files/encode/document.ts index 9f595fee1ee3..ab9e945c5e3e 100644 --- a/packages/api/src/files/encode/document.ts +++ b/packages/api/src/files/encode/document.ts @@ -22,6 +22,23 @@ const ANTHROPIC_CITATION_TYPES = new Set([ 'text/html', 'text/markdown', ]); +const DEEPSEEK_TARGET_PATTERN = /^deepseek(?:[-_.]|$)/i; + +function targetsDeepSeek(...values: Array): boolean { + for (const value of values) { + if (!value) { + continue; + } + + const normalized = value.replace(/^~/, ''); + const segments = normalized.split(/[/:]/); + if (segments.some((segment) => DEEPSEEK_TARGET_PATTERN.test(segment))) { + return true; + } + } + + return false; +} /** * Formats a base64-encoded document into the appropriate provider-specific block. @@ -33,6 +50,8 @@ function formatDocumentBlock( content: string, filename: string | undefined, useResponsesApi: boolean | undefined, + endpoint: string | undefined, + model: string | undefined, ): DocumentBlock | null { if (provider === Providers.ANTHROPIC) { const document: AnthropicDocumentBlock = { @@ -63,6 +82,10 @@ function formatDocumentBlock( }; } + if (provider === Providers.DEEPSEEK || targetsDeepSeek(endpoint, model)) { + return null; + } + const resolvedFilename = filename ?? 'document'; if (useResponsesApi) { @@ -214,6 +237,8 @@ export async function encodeAndFormatDocuments( content, file.filename, useResponsesApi, + endpoint, + model, ); if (block) { result.documents.push(block); @@ -233,6 +258,8 @@ export async function encodeAndFormatDocuments( content, file.filename, useResponsesApi, + endpoint, + model, ); if (block) { result.documents.push(block);