mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import { z } from 'zod';
|
|
import type { Tool } from './Tool';
|
|
import type { JSRuntimeFS } from '../JSRuntime';
|
|
import { findSkill, readSkillContent } from '../plugins';
|
|
|
|
interface SkillParams {
|
|
name: string;
|
|
}
|
|
|
|
export class SkillTool implements Tool<SkillParams> {
|
|
private fs: JSRuntimeFS;
|
|
private pluginsPath: string;
|
|
|
|
readonly description = 'Load and execute a skill from the configured plugins. Skills are reusable AI workflows that can be invoked by name.';
|
|
|
|
readonly inputSchema = z.object({
|
|
name: z.string().describe('The name of the skill to execute (alphanumeric lowercase only)'),
|
|
});
|
|
|
|
constructor(fs: JSRuntimeFS, pluginsPath: string) {
|
|
this.fs = fs;
|
|
this.pluginsPath = pluginsPath;
|
|
}
|
|
|
|
async execute(args: SkillParams): Promise<string> {
|
|
const { name } = args;
|
|
|
|
try {
|
|
// Find the skill across all plugins
|
|
const skill = await findSkill(this.fs, this.pluginsPath, name);
|
|
|
|
if (!skill) {
|
|
throw new Error(`Skill "${name}" not found. Use the skill tool to list available skills or configure plugins in Settings > AI.`);
|
|
}
|
|
|
|
// Read and return the skill content
|
|
const content = await readSkillContent(this.fs, skill);
|
|
|
|
return `# Skill: ${skill.name}
|
|
|
|
**Plugin**: ${skill.plugin}
|
|
**Description**: ${skill.description}
|
|
**Path**: ${skill.path}
|
|
|
|
---
|
|
|
|
${content}`;
|
|
} catch (error) {
|
|
if (error instanceof Error) {
|
|
throw error;
|
|
}
|
|
throw new Error(`Failed to execute skill "${name}": ${String(error)}`);
|
|
}
|
|
}
|
|
}
|