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

providerSkillPresentation.ts

53 lines1.4 KB

1import type { ServerProviderSkill } from "@t3tools/contracts";
2​
3function titleCaseWords(value: string): string {
4 const words: string[] = [];
5 for (const segment of value.split(/[\s:_-]+/)) {
6 if (segment.length === 0) continue;
7 words.push(segment.charAt(0).toUpperCase() + segment.slice(1));
8 }
9 return words.join(" ");
11​
12function normalizePathSeparators(pathValue: string): string {
13 return pathValue.replaceAll("\\", "/");
15​
16export function formatProviderSkillDisplayName(
17 skill: Pick<ServerProviderSkill, "name" | "displayName">,
18): string {
19 const displayName = skill.displayName?.trim();
20 if (displayName) {
21 return displayName;
22 }
23 return titleCaseWords(skill.name);
25​
26export function formatProviderSkillInstallSource(
27 skill: Pick<ServerProviderSkill, "path" | "scope">,
28): string | null {
29 const normalizedPath = normalizePathSeparators(skill.path);
30 if (normalizedPath.includes("/.codex/plugins/") || normalizedPath.includes("/.agents/plugins/")) {
31 return "App";
32 }
33​
34 const normalizedScope = skill.scope?.trim().toLowerCase();
35 if (normalizedScope === "system") {
36 return "System";
37 }
38 if (
39 normalizedScope === "project" ||
40 normalizedScope === "workspace" ||
41 normalizedScope === "local"
42 ) {
43 return "Project";
44 }
45 if (normalizedScope === "user" || normalizedScope === "personal") {
46 return "Personal";
47 }
48 if (normalizedScope) {
49 return titleCaseWords(normalizedScope);
50 }
51​
52 return null;