feat: implement skills system for AI agents (#16865)
## Summary This PR introduces a Skills system for AI agents, inspired by the [Agent Skills specification](https://agentskills.io/specification). ## Changes ### Backend - **SkillEntity**: New database entity with migration for storing skills - **V2 Sync Mechanism**: Implemented FlatSkill, builders, validators, and action handlers following the v2 flat entity pattern - **Standard Skills**: Pre-defined skills (workflow-building, data-manipulation, dashboard-building, metadata-building, research, code-interpreter, xlsx, pdf, docx, pptx) - **GraphQL API**: CRUD operations for skills with proper guards and permissions - **Workspace Cache**: Integrated skills into the workspace cache system ### Frontend - **Skills Table**: Searchable table in AI settings showing all skills - **Skill Form**: Create/edit page with Label (primary), Description, and Content (markdown editor) - **API Name**: Following existing patterns, name is derived from label with advanced settings toggle for custom API names - **Standard vs Custom**: Standard skills are read-only, custom skills can be edited/deleted ## Key Design Decisions - Skills are stored in the database (Salesforce-like approach) rather than files - Name is derived from Label by default (isLabelSyncedWithName pattern) - Skills reference functions/files via @ mentions in markdown content rather than explicit relations - Standard skills are synced from code, custom skills are created via UI ## Screenshots Skills table and form UI follow existing settings patterns. ## Testing - [x] Lint passes - [x] Typecheck passes - [ ] CI tests
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
import { UseGuards, UseInterceptors } from '@nestjs/common';
|
||||
import { Args, Mutation, Query, Resolver } from '@nestjs/graphql';
|
||||
|
||||
import { PermissionFlagType } from 'twenty-shared/constants';
|
||||
|
||||
import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';
|
||||
import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
|
||||
import { SettingsPermissionGuard } from 'src/engine/guards/settings-permission.guard';
|
||||
import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
|
||||
import { CreateSkillInput } from 'src/engine/metadata-modules/skill/dtos/create-skill.input';
|
||||
import { SkillDTO } from 'src/engine/metadata-modules/skill/dtos/skill.dto';
|
||||
import { UpdateSkillInput } from 'src/engine/metadata-modules/skill/dtos/update-skill.input';
|
||||
import { SkillGraphqlApiExceptionInterceptor } from 'src/engine/metadata-modules/skill/interceptors/skill-graphql-api-exception.interceptor';
|
||||
import { SkillService } from 'src/engine/metadata-modules/skill/skill.service';
|
||||
import { WorkspaceMigrationBuilderGraphqlApiExceptionInterceptor } from 'src/engine/workspace-manager/workspace-migration-v2/interceptors/workspace-migration-builder-graphql-api-exception.interceptor';
|
||||
|
||||
@UseGuards(WorkspaceAuthGuard, SettingsPermissionGuard(PermissionFlagType.AI))
|
||||
@UseInterceptors(
|
||||
WorkspaceMigrationBuilderGraphqlApiExceptionInterceptor,
|
||||
SkillGraphqlApiExceptionInterceptor,
|
||||
)
|
||||
@Resolver(() => SkillDTO)
|
||||
export class SkillResolver {
|
||||
constructor(private readonly skillService: SkillService) {}
|
||||
|
||||
@Query(() => [SkillDTO])
|
||||
async skills(
|
||||
@AuthWorkspace() workspace: WorkspaceEntity,
|
||||
): Promise<SkillDTO[]> {
|
||||
return this.skillService.findAll(workspace.id);
|
||||
}
|
||||
|
||||
@Query(() => SkillDTO, { nullable: true })
|
||||
async skill(
|
||||
@Args('id', { type: () => UUIDScalarType }) id: string,
|
||||
@AuthWorkspace() workspace: WorkspaceEntity,
|
||||
): Promise<SkillDTO | null> {
|
||||
return this.skillService.findById(id, workspace.id);
|
||||
}
|
||||
|
||||
@Mutation(() => SkillDTO)
|
||||
async createSkill(
|
||||
@Args('input') input: CreateSkillInput,
|
||||
@AuthWorkspace() workspace: WorkspaceEntity,
|
||||
): Promise<SkillDTO> {
|
||||
return this.skillService.create(input, workspace.id);
|
||||
}
|
||||
|
||||
@Mutation(() => SkillDTO)
|
||||
async updateSkill(
|
||||
@Args('input') input: UpdateSkillInput,
|
||||
@AuthWorkspace() workspace: WorkspaceEntity,
|
||||
): Promise<SkillDTO> {
|
||||
return this.skillService.update(input, workspace.id);
|
||||
}
|
||||
|
||||
@Mutation(() => SkillDTO)
|
||||
async deleteSkill(
|
||||
@Args('id', { type: () => UUIDScalarType }) id: string,
|
||||
@AuthWorkspace() workspace: WorkspaceEntity,
|
||||
): Promise<SkillDTO> {
|
||||
return this.skillService.delete(id, workspace.id);
|
||||
}
|
||||
|
||||
@Mutation(() => SkillDTO)
|
||||
async activateSkill(
|
||||
@Args('id', { type: () => UUIDScalarType }) id: string,
|
||||
@AuthWorkspace() workspace: WorkspaceEntity,
|
||||
): Promise<SkillDTO> {
|
||||
return this.skillService.activate(id, workspace.id);
|
||||
}
|
||||
|
||||
@Mutation(() => SkillDTO)
|
||||
async deactivateSkill(
|
||||
@Args('id', { type: () => UUIDScalarType }) id: string,
|
||||
@AuthWorkspace() workspace: WorkspaceEntity,
|
||||
): Promise<SkillDTO> {
|
||||
return this.skillService.deactivate(id, workspace.id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user