Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

1.5 KB
Raw Blame
import { parsePathId } from '@inkeep/open-knowledge-core/agent-registry';
import {
  EDITOR_PROJECT_SKILL_ROOT,
  EDITOR_USER_SKILL_ROOT,
  RESERVED_PROJECT_SKILL_NAME,
  STABLE_EDITOR_PROJECT_CONFIG_PATH,
} from '@inkeep/open-knowledge-core/constants/editors';
import { AGENTS_SKILLS_ROOT } from '@inkeep/open-knowledge-core/constants/skills';

export function connectionPathDisplay(pathId: string | undefined): string | null {
  if (pathId === undefined) return null;
  const location = parsePathId(pathId);
  if (location === null) return null;

  if (location.kind === 'central-skill-store') return `~/${AGENTS_SKILLS_ROOT}/`;

  switch (location.kind) {
    case 'editor-project-config':
      return STABLE_EDITOR_PROJECT_CONFIG_PATH[location.editor];
    case 'editor-project-skill-root': {
      const root = EDITOR_PROJECT_SKILL_ROOT[location.editor];
      return root === null ? null : `${root}/${RESERVED_PROJECT_SKILL_NAME}/`;
    }
    case 'editor-user-skill-root': {
      const root = EDITOR_USER_SKILL_ROOT[location.editor];
      return root === null ? null : `~/${root}/`;
    }
    case 'editor-user-config':
      return null;
  }
}

export function sharedPathDisplays(pathId: string | undefined, peers: readonly string[]): string[] {
  if (pathId === undefined || peers.length === 0) return [];
  const location = parsePathId(pathId);
  if (location === null || location.kind === 'central-skill-store') return [];
  return peers
    .map((peer) => connectionPathDisplay(`${location.kind}:${peer}`))
    .filter((path): path is string => path !== null);
}