Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

providerSkills.ts

56 lines1.5 KB

1import type { ServerProviderSkill } 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(" ");
13​
14function normalizePathSeparators(pathValue: string): string {
15 return pathValue.replaceAll("\\", "/");
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);
27​
28export function resolveProviderSkillSourceKind(
29 skill: Pick<ServerProviderSkill, "path" | "scope">,
30): ProviderSkillSourceKind {
31 const normalizedPath = normalizePathSeparators(skill.path);
32 if (normalizedPath.includes("/.codex/plugins/") || normalizedPath.includes("/.agents/plugins/")) {
33 return "app";
34 }
35​
36 const normalizedScope = skill.scope?.trim().toLowerCase();
37 switch (normalizedScope) {
38 case "repo":
39 case "repository":
40 return "repo";
41 case "project":
42 case "workspace":
43 case "local":
44 return "project";
45 case "user":
46 case "personal":
47 return "personal";
48 case "system":
49 return "system";
50 case undefined:
51 case "":
52 return "other";
53 default:
54 return "other";
55 }