mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-29 20:34:28 +00:00
feat(asset-download): share download_asset across agent, MCP and CLI
Turn the agent-only download_asset tool into an Operation on all three surfaces. - download_asset takes up to 50 file or version stack IDs and returns presigned links. proxy (default true) picks the web preview when there is one, as the agent always did; proxy: false returns the original. Folders are rejected. Read is checked on every ID before anything runs. - Agent: an extension saves the files into the .pi sandbox and keeps the agent-only storage key mode (e.g. frames from read_asset). Agent tool extensions gain description, parameterOverrides and intercept. - CLI: `shumai-cli download <assetId...> [--out <dir>] [--original]` streams files to disk without overwriting existing names. - read_asset's unsupported-type error now names the right way to download on each surface (download_asset, or `shumai-cli download`). - Add the Download Asset toggle to agent settings.
This commit is contained in:
@@ -22,7 +22,8 @@ type ExecutableTool = {
|
||||
|
||||
/**
|
||||
* read_asset end to end: real render workflows (frames, PDF pages) through the reader
|
||||
* pipeline, the pending → get_asset_render path, and the agent tool in a chat workflow.
|
||||
* pipeline, the pending → get_asset_render path, and the agent's read_asset and
|
||||
* download_asset tools in a chat workflow.
|
||||
* Only the model call is mocked.
|
||||
*/
|
||||
describe('Workflow E2E - read_asset', () => {
|
||||
@@ -56,10 +57,20 @@ describe('Workflow E2E - read_asset', () => {
|
||||
})
|
||||
const text = result.content.find((c) => c.type === 'text')?.text ?? ''
|
||||
const images = result.content.filter((c) => c.type === 'image' && c.data)
|
||||
// download_asset saves the original into the agent's sandbox (.pi)
|
||||
const download = this.getTools().find((t) => t.name === 'download_asset') as unknown as
|
||||
ExecutableTool | undefined
|
||||
const downloaded = download
|
||||
? await download.execute('call-2', { assetIds: [videoAssetId], proxy: false })
|
||||
: undefined
|
||||
const savedPath = (
|
||||
downloaded as unknown as { details?: { files?: Array<{ absolutePath: string }> } }
|
||||
)?.details?.files?.[0]?.absolutePath
|
||||
const summary = [
|
||||
`images:${images.length}`,
|
||||
`frames:${(text.match(/- Frame at /g) ?? []).length}`,
|
||||
`render_tool:${hasRenderTool ? 'present' : 'absent'}`,
|
||||
`downloaded:${savedPath ?? 'none'}`,
|
||||
].join('|')
|
||||
return {
|
||||
content: [{ type: 'text', text: summary }],
|
||||
@@ -283,6 +294,12 @@ describe('Workflow E2E - read_asset', () => {
|
||||
expect(reply?.message).toContain('images:2')
|
||||
expect(reply?.message).toContain('frames:2')
|
||||
expect(reply?.message).toContain('render_tool:present')
|
||||
const savedPath = /downloaded:([^|]+)/.exec(reply?.message ?? '')?.[1] ?? 'none'
|
||||
expect(savedPath).not.toBe('none')
|
||||
expect(
|
||||
fs.readFileSync(savedPath).equals(fs.readFileSync(path.join(fixturesDir, 'small.mp4'))),
|
||||
).toBe(true)
|
||||
fs.rmSync(savedPath, { force: true })
|
||||
|
||||
const render = await prisma.workflowTask.findFirstOrThrow({
|
||||
where: { assetId: video.id, type: 'transcode_screenshot' },
|
||||
|
||||
Reference in New Issue
Block a user