Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

1.3 KB
Raw Blame
import {
  parseProjectSkillBundleDoc,
  skillFileLiveDocName,
  skillLiveDocName,
  stripMdExt,
} from '@inkeep/open-knowledge-core/constants/cc1';
import type { SkillsListEntry } from '@inkeep/open-knowledge-core/schemas/api';

export { skillLiveDocName };

export function skillEntryLiveDocName(
  skill: Pick<SkillsListEntry, 'scope' | 'name' | 'path' | 'canonicalPath' | 'hostQualifier'>,
): string {
  return skill.scope === 'project'
    ? stripMdExt(skillEntryDocPath(skill))
    : skillLiveDocName(skill.scope, skill.name, skill.hostQualifier);
}

function skillEntryDocPath(skill: Pick<SkillsListEntry, 'path' | 'canonicalPath'>): string {
  return skill.canonicalPath ?? skill.path;
}

export function skillEntryFileLiveDocName(
  skill: Pick<SkillsListEntry, 'scope' | 'name' | 'path' | 'canonicalPath' | 'hostQualifier'>,
  rel: string,
): string {
  if (skill.scope !== 'project')
    return skillFileLiveDocName(skill.scope, skill.name, rel, skill.hostQualifier);
  const dir = skillEntryDocPath(skill).replace(/\/SKILL\.mdx?$/i, '');
  return `${dir}/${stripMdExt(rel)}`;
}

export function parseProjectSkillContentDocName(docName: string): string | null {
  const parsed = parseProjectSkillBundleDoc(docName);
  return parsed?.kind === 'skill' ? parsed.name : null;
}