Skip to content

The open alternative to Salesforce, designed for AI.

927 B
Raw Blame
import { tipTapDocumentToMarkdown } from 'twenty-shared/utils';

import { LOAD_SKILL_TOOL_NAME } from 'src/engine/core-modules/tool-provider/tools';
import { type FlatSkill } from 'src/engine/metadata-modules/flat-skill/types/flat-skill.type';

export type ReferencedSkill = Pick<FlatSkill, 'name' | 'label' | 'content'>;

export const buildReferencedSkillsSection = (
  referencedSkills: ReferencedSkill[],
): string => {
  if (referencedSkills.length === 0) {
    return '';
  }

  const skillSections = referencedSkills
    .map(
      (skill) => `### ${skill.label} (\`${skill.name}\`)

${tipTapDocumentToMarkdown(skill.content)}`,
    )
    .join('\n\n');

  return `
## Referenced Skills (already loaded)

The user explicitly referenced these skills with [[skill:...]] in their messages. Their full instructions are below, so follow them directly: do NOT call \`${LOAD_SKILL_TOOL_NAME}\` for them.

${skillSections}`;
};