mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-27 03:14:11 +00:00
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:
@@ -18,6 +18,7 @@ import {
|
||||
import { listMembersQuerySchema, AuditAction } from '@shumai/dtos'
|
||||
import type { Prisma } from '@shumai/db'
|
||||
import { auditLogService } from '@shumai/core/src/auditLog/auditLog'
|
||||
import { moveAssetsOp, runOperation } from '@shumai/core/src/operations'
|
||||
|
||||
type User = Prisma.UserGetPayload<Record<string, never>>
|
||||
|
||||
@@ -291,46 +292,13 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
'/projects/:projectId/reparent',
|
||||
zValidator('json', reparentAssetsRequestSchema),
|
||||
async (c) => {
|
||||
const projectId = c.req.param('projectId')
|
||||
const user = c.get('user')
|
||||
const req = c.req.valid('json')
|
||||
|
||||
// Check Edit permission on target folder/project
|
||||
await authzService.hasPermission({
|
||||
user,
|
||||
permission: Permission.Edit,
|
||||
type: ResourceType.Asset,
|
||||
id: req.newParentId,
|
||||
})
|
||||
|
||||
// Check Edit permission on all source assets
|
||||
for (const assetId of req.assetIds) {
|
||||
await authzService.hasPermission({
|
||||
user,
|
||||
permission: Permission.Edit,
|
||||
type: ResourceType.Asset,
|
||||
id: assetId,
|
||||
})
|
||||
}
|
||||
|
||||
await assetService.reparentAssets({
|
||||
...req,
|
||||
creatorId: user.id,
|
||||
})
|
||||
|
||||
const teamId = await projectService.getProjectTeam(projectId).catch(() => null)
|
||||
if (teamId) {
|
||||
for (const assetId of req.assetIds) {
|
||||
await auditLogService.logAction({
|
||||
action: AuditAction.asset_reparent,
|
||||
teamId,
|
||||
userId: user.id,
|
||||
projectId,
|
||||
itemId: assetId,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Team/project for authorization and audit come from the assets themselves, not the path.
|
||||
await runOperation(
|
||||
moveAssetsOp,
|
||||
{ userId: c.get('user').id, via: 'api' },
|
||||
{ assetIds: req.assetIds, newParentId: req.newParentId },
|
||||
)
|
||||
return c.body(null, 204)
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user