21ff42074d
## 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
148 lines
3.7 KiB
TypeScript
148 lines
3.7 KiB
TypeScript
import { createSkill } from 'test/integration/metadata/suites/skill/utils/create-skill.util';
|
|
import { deleteSkill } from 'test/integration/metadata/suites/skill/utils/delete-skill.util';
|
|
|
|
import { type CreateSkillInput } from 'src/engine/metadata-modules/skill/dtos/create-skill.input';
|
|
|
|
describe('Skill creation should succeed', () => {
|
|
let createdSkillId: string;
|
|
|
|
afterEach(async () => {
|
|
if (createdSkillId) {
|
|
await deleteSkill({
|
|
expectToFail: false,
|
|
input: { id: createdSkillId },
|
|
});
|
|
}
|
|
});
|
|
|
|
it('should create a basic custom skill with minimal input', async () => {
|
|
const { data } = await createSkill({
|
|
expectToFail: false,
|
|
input: {
|
|
name: 'testSkill',
|
|
label: 'Test Skill',
|
|
content: 'This is the skill content with instructions',
|
|
},
|
|
});
|
|
|
|
createdSkillId = data?.createSkill?.id;
|
|
|
|
expect(data.createSkill).toMatchObject({
|
|
id: expect.any(String),
|
|
name: 'testSkill',
|
|
label: 'Test Skill',
|
|
icon: null,
|
|
description: null,
|
|
content: 'This is the skill content with instructions',
|
|
isCustom: true,
|
|
isActive: true,
|
|
});
|
|
});
|
|
|
|
it('should create skill with all optional fields', async () => {
|
|
const input = {
|
|
name: 'customSkillName',
|
|
label: 'Custom Skill Label',
|
|
icon: 'IconSparkles',
|
|
description: 'A custom skill with all fields specified',
|
|
content: 'Detailed instructions for the skill',
|
|
} as const satisfies CreateSkillInput;
|
|
|
|
const { data } = await createSkill({
|
|
expectToFail: false,
|
|
input,
|
|
});
|
|
|
|
createdSkillId = data?.createSkill?.id;
|
|
|
|
expect(data.createSkill).toMatchObject({
|
|
id: expect.any(String),
|
|
...input,
|
|
isCustom: true,
|
|
isActive: true,
|
|
});
|
|
});
|
|
|
|
it('should sanitize input by trimming whitespace', async () => {
|
|
const { data } = await createSkill({
|
|
expectToFail: false,
|
|
input: {
|
|
name: ' skillWithSpaces ',
|
|
label: ' Skill With Spaces ',
|
|
icon: ' IconSparkles ',
|
|
description: ' Description with spaces ',
|
|
content: ' Content with spaces ',
|
|
},
|
|
});
|
|
|
|
createdSkillId = data?.createSkill?.id;
|
|
|
|
expect(data.createSkill).toMatchObject({
|
|
id: expect.any(String),
|
|
name: 'skillWithSpaces',
|
|
label: 'Skill With Spaces',
|
|
icon: 'IconSparkles',
|
|
description: 'Description with spaces',
|
|
content: 'Content with spaces',
|
|
});
|
|
});
|
|
|
|
it('should create skill with long content', async () => {
|
|
const longContent =
|
|
'This is a long content that describes the skill instructions in detail.';
|
|
|
|
const { data } = await createSkill({
|
|
expectToFail: false,
|
|
input: {
|
|
name: 'longContentSkill',
|
|
label: 'Long Content Skill',
|
|
content: longContent,
|
|
},
|
|
});
|
|
|
|
createdSkillId = data?.createSkill?.id;
|
|
|
|
expect(data.createSkill).toMatchObject({
|
|
id: expect.any(String),
|
|
name: 'longContentSkill',
|
|
label: 'Long Content Skill',
|
|
content: longContent,
|
|
isCustom: true,
|
|
isActive: true,
|
|
});
|
|
});
|
|
|
|
it('should preserve markdown formatting with newlines in content', async () => {
|
|
const markdownContent = `# Skill Instructions
|
|
|
|
## Step 1
|
|
Do the first thing.
|
|
|
|
## Step 2
|
|
Do the second thing.
|
|
|
|
- List item 1
|
|
- List item 2`;
|
|
|
|
const { data } = await createSkill({
|
|
expectToFail: false,
|
|
input: {
|
|
name: 'markdownSkill',
|
|
label: 'Markdown Skill',
|
|
content: markdownContent,
|
|
},
|
|
});
|
|
|
|
createdSkillId = data?.createSkill?.id;
|
|
|
|
expect(data.createSkill).toMatchObject({
|
|
id: expect.any(String),
|
|
name: 'markdownSkill',
|
|
label: 'Markdown Skill',
|
|
content: markdownContent,
|
|
isCustom: true,
|
|
isActive: true,
|
|
});
|
|
});
|
|
});
|