mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-22 09:07:38 +00:00
* feat(operations): move MCP to /mcp and add search, comment, metadata, version, and upload operations - Serve the MCP server at /mcp instead of /api/mcp - Add search_assets, copy_assets, get_folder_instructions, list_comments, create_comment, resolve_comment, list_metadata_fields, update_asset_metadata, create_version_stack, list_versions, and remove_version on the agent, MCP, and CLI - Add create_file and create_version (agent, MCP) with Creation Context metadata, and complete_upload (MCP) for presigned two-step uploads - Replace the native agent create_file/create_version tools with Operation-backed ones - Route the comment-complete, metadata, copy, version stack, and AGENTS.md read REST endpoints through their Operations * docs(readme): add built-in MCP server and CLI to features list
78 lines
2.5 KiB
TypeScript
78 lines
2.5 KiB
TypeScript
import { Hono } from 'hono'
|
|
import { zValidator } from '@hono/zod-validator'
|
|
import { versionStackService } from '@shumai/core/src/versionStack/versionStack'
|
|
import { assetService } from '@shumai/core/src/asset/asset'
|
|
import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
|
|
import { createVersionStackOp, removeVersionOp, runOperation } from '@shumai/core/src/operations'
|
|
import { createVersionStackRequestSchema, changeStackFileVersionRequestSchema } from '@shumai/dtos'
|
|
import type { Prisma } from '@shumai/db'
|
|
|
|
type User = Prisma.UserGetPayload<Record<string, never>>
|
|
|
|
const app = new Hono<{ Variables: { user: User } }>()
|
|
|
|
const route = app
|
|
.post(
|
|
'/projects/:projectId/version_stacks',
|
|
zValidator('json', createVersionStackRequestSchema),
|
|
async (c) => {
|
|
const req = c.req.valid('json')
|
|
// Authorization and the stack's project come from the files, not the path.
|
|
const stack = await runOperation(
|
|
createVersionStackOp,
|
|
{ userId: c.get('user').id, via: 'api' },
|
|
{ fileIds: req.fileIds },
|
|
)
|
|
return c.json(await assetService.getAsset({ assetId: stack.id }))
|
|
},
|
|
)
|
|
.post(
|
|
'/version_stacks/:stackId/order',
|
|
zValidator('json', changeStackFileVersionRequestSchema),
|
|
async (c) => {
|
|
const stackId = c.req.param('stackId')
|
|
const user = c.get('user')
|
|
const req = c.req.valid('json')
|
|
|
|
await authzService.hasPermission({
|
|
user,
|
|
permission: Permission.Edit,
|
|
type: ResourceType.Asset,
|
|
id: stackId,
|
|
})
|
|
|
|
await versionStackService.changeStackFileVersion({
|
|
stackId,
|
|
fileId: req.fileId,
|
|
beforeId: req.beforeId,
|
|
})
|
|
|
|
return new Response(null, { status: 200 })
|
|
},
|
|
)
|
|
.get('/version_stacks/:stackId/versions', async (c) => {
|
|
const stackId = c.req.param('stackId')
|
|
const user = c.get('user')
|
|
|
|
await authzService.hasPermission({
|
|
user,
|
|
permission: Permission.Read,
|
|
type: ResourceType.Asset,
|
|
id: stackId,
|
|
})
|
|
|
|
const versions = await assetService.getStackVersions(stackId)
|
|
return c.json(versions)
|
|
})
|
|
.delete('/version_stacks/:stackId/versions/:versionId', async (c) => {
|
|
// The stack is the version's parent; the path's stackId is not needed.
|
|
await runOperation(
|
|
removeVersionOp,
|
|
{ userId: c.get('user').id, via: 'api' },
|
|
{ versionId: c.req.param('versionId') },
|
|
)
|
|
return new Response(null, { status: 200 })
|
|
})
|
|
|
|
export default route
|