Open History to see the last commit
1import type { ServerProviderSkill, ServerProviderSlashCommand } from "@t3tools/contracts";
2
3export type ProviderSkillSourceKind = "app" | "repo" | "project" | "personal" | "system" | "other";
4
5function titleCaseWords(value: string): string {
6 const words: string[] = [];
7 for (const segment of value.split(/[\s:_-]+/)) {
8 if (segment.length === 0) continue;
9 words.push(segment.charAt(0).toUpperCase() + segment.slice(1));
10 }
11 return words.join(" ");
12}
13
14function normalizePathSeparators(pathValue: string): string {
15 return pathValue.replaceAll("\\", "/");
16}
17
18export function formatProviderSkillDisplayName(
19 skill: Pick<ServerProviderSkill, "name" | "displayName">,
20): string {
21 const displayName = skill.displayName?.trim();
22 if (displayName) {
23 return displayName;
24 }
25 return titleCaseWords(skill.name);
26}
27
28export function getProviderSkillsForSlashMenu(
29 skills: ReadonlyArray<ServerProviderSkill>,
30 showSkillsInSlashMenu: boolean,
31): ServerProviderSkill[] {
32 return showSkillsInSlashMenu ? skills.filter((skill) => skill.enabled) : [];
33}
34
35export function getProviderSlashCommandsForSlashMenu(
36 slashCommands: ReadonlyArray<ServerProviderSlashCommand>,
37 visibleSkills: ReadonlyArray<ServerProviderSkill>,
38): ServerProviderSlashCommand[] {
39 const skillNames = new Set(visibleSkills.map((skill) => skill.name.trim().toLowerCase()));
40 return slashCommands.filter((command) => !skillNames.has(command.name.trim().toLowerCase()));
41}
42
43export function resolveProviderSkillSourceKind(
44 skill: Pick<ServerProviderSkill, "path" | "scope">,
45): ProviderSkillSourceKind {
46 const normalizedPath = normalizePathSeparators(skill.path);
47 if (normalizedPath.includes("/.codex/plugins/") || normalizedPath.includes("/.agents/plugins/")) {
48 return "app";
49 }
50
51 const normalizedScope = skill.scope?.trim().toLowerCase();
52 switch (normalizedScope) {
53 case "repo":
54 case "repository":
55 return "repo";
56 case "project":
57 case "workspace":
58 case "local":
59 return "project";
60 case "user":
61 case "personal":
62 return "personal";
63 case "system":
64 return "system";
65 case undefined:
66 case "":
67 return "other";
68 default:
69 return "other";
70 }
71}