mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-24 14:49:24 +00:00
fix(agent): block non-pdf assets in read_pdf_pages and remove mediaType fallback in AgentChatPromptBuilder
This commit is contained in:
@@ -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.',
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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 = ''
|
||||
|
||||
Reference in New Issue
Block a user