Repository navigation
Expand file tree
/
Copy pathfetchSkill.ts
More file actions
68 lines (62 loc) · 1.76 KB
/
Copy pathfetchSkill.ts
File metadata and controls
68 lines (62 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { tool } from "langchain";
import { z } from "zod";
import {
listSkillManifests,
loadSkillMarkdown,
type AgentSkillManifest,
} from "./skills/registry.js";
const fetchSkillSchema = z.object({
skillName: z
.string()
.describe(
"Name of the custom AdminForth skill to load, for example fetch_data or mutate_data.",
),
});
function serializeSkillManifests(skillManifests: AgentSkillManifest[]) {
return skillManifests.map((skill) => ({
name: skill.name,
description: skill.description,
}));
}
export async function createFetchSkillTool(
customComponentsDir: string,
pluginCustomFolderPaths: string[] = [],
) {
const availableSkills = await listSkillManifests(
customComponentsDir,
pluginCustomFolderPaths,
);
const availableSkillNames = availableSkills.map((skill) => skill.name);
return tool(
async ({ skillName }) => {
try {
const skillMarkdown = await loadSkillMarkdown(
skillName,
customComponentsDir,
pluginCustomFolderPaths,
);
if (!skillMarkdown) {
return [
`Skill "${skillName}" not found.`,
"Available skills:",
JSON.stringify(serializeSkillManifests(availableSkills), null, 2),
].join("\n");
}
return skillMarkdown;
} catch (error) {
return `Failed to load skill "${skillName}": ${
error instanceof Error ? error.message : String(error)
}`;
}
},
{
name: "fetch_skill",
description: `Fetch the raw SKILL.md content for a custom AdminForth skill by name.${
availableSkillNames.length > 0
? ` Available skills: ${availableSkillNames.join(", ")}.`
: ""
}`,
schema: fetchSkillSchema,
},
);
}