feat(asset-read): rewrite read_asset as a reader registry and Operations (#498)

Replace the monolithic agent read_asset tool with a reader registry in
@shumai/core/src/asset-read (model3d, image, video, document) behind a
shared pipeline that handles access checks, version stacks, annotations,
render tasks, and waiting.

- Add read_asset and get_asset_render Operations (agent surface only).
  Renders that outlast the caller's wait budget return "pending" with the
  workflow task ID; the read request is stored on the task payload so
  get_asset_render works across restarts and instances (requester only).
- Add workflowService.waitFor and presign expiry support.
- Keep agent output compatible via an agent tool extension (s3KeyOnly,
  image blocks, session image details); autofill keeps its team-scoped tool.
- Cap video frames at 20 per call; add the get_asset_render agent toggle.
This commit is contained in:
Yiling-J
2026-10-27 08:09:10 +08:00
committed by GitHub
parent e44938cb8f
commit 155fb95a0e
40 changed files with 3787 additions and 2229 deletions
@@ -0,0 +1,43 @@
import { getAssetRender, readAsset, type Via } from '@shumai/operations'
import { assetReadService, toAssetReadOutput } from '@shumai/core/src/asset-read'
import { implementOperation } from '../implement'
/**
* How long each surface waits for a render before returning `pending`. MCP clients commonly
* time out around 60s, so MCP and generic API callers get a short budget.
*/
export const READ_WAIT_BUDGET_MS: Record<Via, number> = {
agent: 60_000,
mcp: 20_000,
cli: 120_000,
api: 20_000,
}
/** `maxWaitSeconds` can only shorten the surface budget. */
export function waitBudgetMs(via: Via, maxWaitSeconds: number | undefined): number {
const budget = READ_WAIT_BUDGET_MS[via]
return maxWaitSeconds === undefined ? budget : Math.min(budget, maxWaitSeconds * 1000)
}
export const readAssetOp = implementOperation(readAsset, {
// assetReadService checks Read on the asset before planning or creating any render task.
authz: () => [],
execute: async (input, ctx) => {
const { maxWaitSeconds, ...request } = input
const outcome = await assetReadService.read({ kind: 'user', userId: ctx.userId }, request, {
waitBudgetMs: waitBudgetMs(ctx.via, maxWaitSeconds),
})
return toAssetReadOutput(outcome, { includeKeys: ctx.via === 'agent' })
},
})
export const getAssetRenderOp = implementOperation(getAssetRender, {
// Only the requesting user, with Read on the asset, can fetch a render (checked by the service).
authz: () => [],
execute: async (input, ctx) => {
const outcome = await assetReadService.getRender(ctx.userId, input.taskId, {
waitBudgetMs: waitBudgetMs(ctx.via, input.maxWaitSeconds),
})
return toAssetReadOutput(outcome, { includeKeys: ctx.via === 'agent' })
},
})
+6
View File
@@ -14,5 +14,11 @@ export { createFolderOp } from './asset/create-folder'
export { deleteAssetOp } from './asset/delete-asset'
export { listAssetsOp } from './asset/list-assets'
export { moveAssetsOp } from './asset/move-assets'
export {
getAssetRenderOp,
READ_WAIT_BUDGET_MS,
readAssetOp,
waitBudgetMs,
} from './asset/read-asset'
export { renameAssetOp } from './asset/rename-asset'
export { listProjectsOp } from './project/list-projects'
+3
View File
@@ -3,6 +3,7 @@ import { createFolderOp } from './asset/create-folder'
import { deleteAssetOp } from './asset/delete-asset'
import { listAssetsOp } from './asset/list-assets'
import { moveAssetsOp } from './asset/move-assets'
import { getAssetRenderOp, readAssetOp } from './asset/read-asset'
import { renameAssetOp } from './asset/rename-asset'
import type { Operation } from './implement'
import { listProjectsOp } from './project/list-projects'
@@ -31,6 +32,8 @@ export const operations = defineRegistry([
renameAssetOp,
moveAssetsOp,
deleteAssetOp,
readAssetOp,
getAssetRenderOp,
] as const)
const operationsByName = new Map<string, Operation>()