feat(operations): add shared Operation layer for agent capabilities (#494)

Introduce @shumai/operations (pure definitions: Zod schemas, metadata,
CLI hints) and @shumai/core/src/operations (implementOperation and the
runOperation pipeline: validate, authorize, prepare, execute, validate
output, audit).

Migrate list_assets, create_folder, rename_asset, move_assets and
delete_asset to Operations, and add list_projects. The agent now builds
these tools from the registry, and the folder create/rename, file
rename and reparent routes call the same Operations.

Audit logs gain a nullable via column recording the surface. A lint
rule keeps the Prisma client out of Operation implementations.
This commit is contained in:
Yiling-J
2026-10-27 08:09:09 +08:00
committed by GitHub
parent 47ee794ae4
commit 76057ccd21
65 changed files with 2372 additions and 1149 deletions
+7 -25
View File
@@ -6,6 +6,7 @@ import { notificationService } from '@shumai/core/src/notification/notification'
import { s3Service } from '@shumai/core/src/s3/s3'
import type { Prisma } from '@shumai/db'
import { auditLogService } from '@shumai/core/src/auditLog/auditLog'
import { renameAssetOp, runOperation } from '@shumai/core/src/operations'
import {
createCommentRequestSchema,
deleteFilesRequestSchema,
@@ -63,32 +64,13 @@ const route = new Hono<{ Variables: { user: User } }>()
return c.json(updated)
})
.put('/files/:fileId', zValidator('json', updateFileRequestSchema), async (c) => {
const fileId = c.req.param('fileId')
const user = c.get('user')
const req = c.req.valid('json')
await authzService.hasPermission({
user,
permission: Permission.Edit,
type: ResourceType.Asset,
id: fileId,
})
const updatedAsset = await assetService.updateAssetName({
id: fileId,
name: req.name,
})
const context = await assetService.getAssetContext(fileId)
await auditLogService.logAction({
action: AuditAction.file_update,
teamId: context.teamId,
userId: user.id,
projectId: context.projectId,
itemId: fileId,
})
return c.json(updatedAsset)
const file = await runOperation(
renameAssetOp,
{ userId: c.get('user').id, via: 'api' },
{ assetId: c.req.param('fileId'), name: req.name },
)
return c.json(file)
})
.delete('/files', zValidator('json', deleteFilesRequestSchema), async (c) => {
const user = c.get('user')