mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-02 14:04:50 +00:00
fix(agent): set empty details in asset tool results to avoid data duplication (#370)
This commit is contained in:
@@ -76,7 +76,13 @@ describe('reproduce null coercion in harness tool validation', () => {
|
|||||||
|
|
||||||
// execute must accept the valid call (data-only) without throwing
|
// execute must accept the valid call (data-only) without throwing
|
||||||
const result = await tool.execute('call-1', validated as never)
|
const result = await tool.execute('call-1', validated as never)
|
||||||
expect(result.details).toEqual({ id: 'file-1', name: 'test', type: 'file', size: 100 })
|
expect(result.details).toEqual({})
|
||||||
|
expect(JSON.parse((result.content[0] as { text: string }).text)).toEqual({
|
||||||
|
id: 'file-1',
|
||||||
|
name: 'test',
|
||||||
|
type: 'file',
|
||||||
|
size: 100,
|
||||||
|
})
|
||||||
expect(s3Service.putObject).toHaveBeenCalledTimes(1)
|
expect(s3Service.putObject).toHaveBeenCalledTimes(1)
|
||||||
expect(authzService.hasPermission).toHaveBeenCalledTimes(1)
|
expect(authzService.hasPermission).toHaveBeenCalledTimes(1)
|
||||||
expect(assetService.createFile).toHaveBeenCalledTimes(1)
|
expect(assetService.createFile).toHaveBeenCalledTimes(1)
|
||||||
|
|||||||
@@ -86,7 +86,13 @@ describe('createCreateFileTool', () => {
|
|||||||
metadata: undefined,
|
metadata: undefined,
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(result.details).toEqual({ id: 'file-1', name: 'test', type: 'file', size: 100 })
|
expect(result.details).toEqual({})
|
||||||
|
expect(JSON.parse((result.content[0] as { text: string }).text)).toEqual({
|
||||||
|
id: 'file-1',
|
||||||
|
name: 'test',
|
||||||
|
type: 'file',
|
||||||
|
size: 100,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should forward the metadata to assetService.createFile when provided', async () => {
|
it('should forward the metadata to assetService.createFile when provided', async () => {
|
||||||
@@ -209,7 +215,13 @@ describe('createCreateFileTool', () => {
|
|||||||
metadata: undefined,
|
metadata: undefined,
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(result.details).toEqual({ id: 'file-1', name: 'test', type: 'file', size: 100 })
|
expect(result.details).toEqual({})
|
||||||
|
expect(JSON.parse((result.content[0] as { text: string }).text)).toEqual({
|
||||||
|
id: 'file-1',
|
||||||
|
name: 'test',
|
||||||
|
type: 'file',
|
||||||
|
size: 100,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should default unknown extensions to text/plain when creating from content', async () => {
|
it('should default unknown extensions to text/plain when creating from content', async () => {
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ export function createCreateFileTool(userId: string, metadataSchema?: TSchema):
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
||||||
details: result,
|
details: {},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,8 @@ describe('createCreateFolderTool', () => {
|
|||||||
creatorId: 'user-1',
|
creatorId: 'user-1',
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(result.details).toEqual({
|
expect(result.details).toEqual({})
|
||||||
|
expect(JSON.parse((result.content[0] as { text: string }).text)).toEqual({
|
||||||
id: 'folder-1',
|
id: 'folder-1',
|
||||||
name: 'New Folder',
|
name: 'New Folder',
|
||||||
type: 'folder',
|
type: 'folder',
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export function createCreateFolderTool(userId: string): AgentTool<typeof createF
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
||||||
details: result,
|
details: {},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,13 @@ describe('createCreateVersionTool', () => {
|
|||||||
metadata: undefined,
|
metadata: undefined,
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(result.details).toEqual({ id: 'file-1', name: 'v2', type: 'file', size: 100 })
|
expect(result.details).toEqual({})
|
||||||
|
expect(JSON.parse((result.content[0] as { text: string }).text)).toEqual({
|
||||||
|
id: 'file-1',
|
||||||
|
name: 'v2',
|
||||||
|
type: 'file',
|
||||||
|
size: 100,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should forward the metadata to assetService.createVersion when provided', async () => {
|
it('should forward the metadata to assetService.createVersion when provided', async () => {
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ export function createCreateVersionTool(userId: string, metadataSchema?: TSchema
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
||||||
details: result,
|
details: {},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ describe('createListAssetsTool', () => {
|
|||||||
after: undefined,
|
after: undefined,
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(result.details).toEqual({
|
expect(result.details).toEqual({})
|
||||||
|
expect(JSON.parse((result.content[0] as { text: string }).text)).toEqual({
|
||||||
assets: [
|
assets: [
|
||||||
{ id: '01M2FILE2', name: 'file2.txt', type: 'file', size: 200 },
|
{ id: '01M2FILE2', name: 'file2.txt', type: 'file', size: 200 },
|
||||||
{ id: '01M1FILE1', name: 'file1.txt', type: 'file', size: 100 },
|
{ id: '01M1FILE1', name: 'file1.txt', type: 'file', size: 100 },
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ export function createListAssetsTool(userId: string): AgentTool<typeof listAsset
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
content: [{ type: 'text', text: JSON.stringify(output, null, 2) }],
|
content: [{ type: 'text', text: JSON.stringify(output, null, 2) }],
|
||||||
details: output,
|
details: {},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user