mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-19 14:16:29 +00:00
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.
44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
import { createFolder } from './asset/create-folder'
|
|
import { deleteAsset } from './asset/delete-asset'
|
|
import { listAssets } from './asset/list-assets'
|
|
import { moveAssets } from './asset/move-assets'
|
|
import { renameAsset } from './asset/rename-asset'
|
|
import type { AnyOperationDefinition, Surface } from './define'
|
|
import { listProjects } from './project/list-projects'
|
|
|
|
/**
|
|
* Every Operation definition. Adding one here requires a matching implementation in
|
|
* `@shumai/core/src/operations/registry.ts` (enforced by the type checker).
|
|
*/
|
|
export const operationDefinitions = [
|
|
listProjects,
|
|
listAssets,
|
|
createFolder,
|
|
renameAsset,
|
|
moveAssets,
|
|
deleteAsset,
|
|
] as const
|
|
|
|
export type RegisteredOperationDefinition = (typeof operationDefinitions)[number]
|
|
export type OperationName = RegisteredOperationDefinition['name']
|
|
export type OperationDefinitionByName<TName extends OperationName> = Extract<
|
|
RegisteredOperationDefinition,
|
|
{ name: TName }
|
|
>
|
|
|
|
const definitionsByName = new Map<string, AnyOperationDefinition>()
|
|
for (const definition of operationDefinitions) {
|
|
if (definitionsByName.has(definition.name)) {
|
|
throw new Error(`Duplicate operation name "${definition.name}"`)
|
|
}
|
|
definitionsByName.set(definition.name, definition)
|
|
}
|
|
|
|
export function getOperationDefinition(name: string): AnyOperationDefinition | undefined {
|
|
return definitionsByName.get(name)
|
|
}
|
|
|
|
export function getOperationDefinitionsForSurface(surface: Surface): AnyOperationDefinition[] {
|
|
return operationDefinitions.filter((definition) => definition.surfaces.includes(surface))
|
|
}
|