fix(agent): block non-pdf assets in read_pdf_pages and remove mediaType fallback in AgentChatPromptBuilder

This commit is contained in:
yiling
2026-07-20 11:01:22 +08:00
parent fea153e94f
commit 4ad0df5876
3 changed files with 35 additions and 2 deletions
@@ -49,6 +49,7 @@ describe('readPdfPagesTool', () => {
vi.mocked(prisma.asset.findUnique).mockResolvedValue({
id: 'asset-1',
projectId: 'project-1',
media: { proxyType: 'pdf' },
} as unknown as Asset)
vi.mocked(prisma.assetComment.findUnique).mockResolvedValue({
@@ -167,4 +168,36 @@ describe('readPdfPagesTool', () => {
text: 'Asset with ID asset-1 not found.',
})
})
it('should return error text if proxyType is not pdf', async () => {
vi.mocked(prisma.asset.findUnique).mockResolvedValue({
id: 'asset-1',
projectId: 'project-1',
media: { proxyType: 'image' },
} as unknown as Asset)
const tool = createReadPdfPagesTool('asset-1')
const result = await tool.execute('call-1', { start: 1, end: 3 })
expect(result.content[0]).toEqual({
type: 'text',
text: 'Asset asset-1 is not a PDF or document.',
})
})
it('should return error text if proxyType is null/undefined (unprocessed)', async () => {
vi.mocked(prisma.asset.findUnique).mockResolvedValue({
id: 'asset-1',
projectId: 'project-1',
media: null,
} as unknown as Asset)
const tool = createReadPdfPagesTool('asset-1')
const result = await tool.execute('call-1', { start: 1, end: 3 })
expect(result.content[0]).toEqual({
type: 'text',
text: 'Asset asset-1 is not a PDF or document.',
})
})
})
+1 -1
View File
@@ -78,7 +78,7 @@ export function createReadPdfPagesTool(
}
const proxyType = (asset.media as PrismaJson.MediaInfo | null)?.proxyType
if (proxyType && proxyType !== 'pdf') {
if (proxyType !== 'pdf') {
return {
content: [{ type: 'text', text: `Asset ${targetAssetId} is not a PDF or document.` }],
details: {},
@@ -76,7 +76,7 @@ export class AgentChatPromptBuilder {
}
build(): string {
const effectiveType = this.proxyType || this.mediaType
const effectiveType = this.proxyType
if (this.isContinuation) {
let instruction = ''