mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-03 07:57:22 +00:00
List available skills in the skill tool itself
This commit is contained in:
2 files changed
+56
-21
No files matched your search
@@ -59,6 +59,7 @@ import { buildMessageContent } from '@/lib/buildMessageContent';
|
||||
import { DotAI } from '@/lib/DotAI';
|
||||
import { parseProviderModel } from '@/lib/parseProviderModel';
|
||||
import { AIMessage } from '@/lib/SessionManager';
|
||||
import { getAllSkills } from '@/lib/skills';
|
||||
|
||||
// Clean interfaces now handled by proper hooks
|
||||
|
||||
@@ -106,6 +107,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
const [templateInfo, setTemplateInfo] = useState<{ name: string; description: string; url: string } | null>(null);
|
||||
const [showTemplateInfo, setShowTemplateInfo] = useState(false);
|
||||
const [showToolsDialog, setShowToolsDialog] = useState(false);
|
||||
const [availableSkills, setAvailableSkills] = useState<Array<{ name: string; description: string; path: string; plugin: string }>>([]);
|
||||
|
||||
// Determine which error to show - AI errors take priority over console errors
|
||||
// since they are more immediately relevant to the user's current action
|
||||
@@ -176,6 +178,19 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
queryClient.invalidateQueries({ queryKey: ['git-sync', cwd] });
|
||||
}, [queryClient, cwd]);
|
||||
|
||||
// Load available skills
|
||||
useEffect(() => {
|
||||
const loadSkills = async () => {
|
||||
const skills = await getAllSkills(fs, pluginsPath, cwd);
|
||||
setAvailableSkills(skills);
|
||||
};
|
||||
|
||||
loadSkills().catch(err => {
|
||||
console.error('Failed to load skills:', err);
|
||||
setAvailableSkills([]);
|
||||
});
|
||||
}, [fs, pluginsPath, cwd]);
|
||||
|
||||
// Fetch MCP tools
|
||||
const { tools: mcpOpenAITools, clients: mcpClients } = useMCPTools();
|
||||
|
||||
@@ -204,7 +219,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
nostr_publish_events: new NostrPublishEventsTool(),
|
||||
shell: new ShellTool(fs, cwd, git, config.corsProxy, user?.signer),
|
||||
read_console_messages: new ReadConsoleMessagesTool(),
|
||||
skill: new SkillTool(fs, pluginsPath, cwd),
|
||||
skill: new SkillTool(fs, availableSkills),
|
||||
webfetch: new WebFetchTool({ corsProxy: config.corsProxy }),
|
||||
websearch: new WebSearchTool(),
|
||||
todowrite: new TodoWriteTool(fs, projectId, { projectsPath }),
|
||||
@@ -260,7 +275,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
}
|
||||
|
||||
return tools;
|
||||
}, [fs, git, cwd, user, projectsPath, tmpPath, pluginsPath, config.corsProxy, settings, aiSettings, models, handleFileChanged, handleCommit, projectId]);
|
||||
}, [fs, git, cwd, user, projectsPath, tmpPath, config.corsProxy, settings, aiSettings, models, handleFileChanged, handleCommit, projectId, availableSkills]);
|
||||
|
||||
// MCP tools wrapped for execution
|
||||
const mcpToolWrappers = useMemo(() => createMCPTools(mcpClients), [mcpClients]);
|
||||
|
||||
+39
-19
@@ -1,7 +1,7 @@
|
||||
import { z } from 'zod';
|
||||
import type { Tool, ToolResult } from './Tool';
|
||||
import type { JSRuntimeFS } from '../JSRuntime';
|
||||
import { findSkill, readSkillContent } from '../skills';
|
||||
import { readSkillContent, type Skill } from '../skills';
|
||||
|
||||
interface SkillParams {
|
||||
name: string;
|
||||
@@ -9,45 +9,65 @@ interface SkillParams {
|
||||
|
||||
export class SkillTool implements Tool<SkillParams> {
|
||||
private fs: JSRuntimeFS;
|
||||
private pluginsPath: string;
|
||||
private projectPath: string;
|
||||
|
||||
readonly description = 'Load and execute a skill from the configured plugins or project. Skills are reusable AI workflows that can be invoked by name.';
|
||||
private availableSkills: Skill[];
|
||||
readonly description: string;
|
||||
|
||||
readonly inputSchema = z.object({
|
||||
name: z.string().describe('The name of the skill to execute (lowercase alphanumeric with hyphens)'),
|
||||
name: z.string().describe('The skill identifier from available_skills'),
|
||||
});
|
||||
|
||||
constructor(fs: JSRuntimeFS, pluginsPath: string, projectPath: string) {
|
||||
/**
|
||||
* Create a SkillTool instance.
|
||||
* @param fs - Filesystem instance
|
||||
* @param availableSkills - List of available skills (should be pre-loaded)
|
||||
*/
|
||||
constructor(fs: JSRuntimeFS, availableSkills: Skill[]) {
|
||||
this.fs = fs;
|
||||
this.pluginsPath = pluginsPath;
|
||||
this.projectPath = projectPath;
|
||||
this.availableSkills = availableSkills;
|
||||
this.description = this.generateDescription(availableSkills);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate description text for SkillTool based on available skills.
|
||||
*/
|
||||
private generateDescription(skills: Skill[]): string {
|
||||
if (skills.length === 0) {
|
||||
return 'Load a skill to get detailed instructions for a specific task. No skills are currently available.';
|
||||
}
|
||||
|
||||
return [
|
||||
'Load a skill to get detailed instructions for a specific task.',
|
||||
'Skills provide specialized knowledge and step-by-step guidance.',
|
||||
'Use this when a task matches an available skill\'s description.',
|
||||
'<available_skills>',
|
||||
...skills.map(skill =>
|
||||
` <skill>\n <name>${skill.name}</name>\n <description>${skill.description}</description>\n </skill>`
|
||||
),
|
||||
'</available_skills>',
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
async execute(args: SkillParams): Promise<ToolResult> {
|
||||
const { name } = args;
|
||||
|
||||
try {
|
||||
// Find the skill across all plugins and project
|
||||
const skill = await findSkill(this.fs, this.pluginsPath, this.projectPath, name);
|
||||
// Find the skill in the pre-loaded list
|
||||
const skill = this.availableSkills.find(s => s.name === name);
|
||||
|
||||
if (!skill) {
|
||||
throw new Error(`Skill "${name}" not found. Use the skill tool to list available skills or configure plugins in Settings > AI.`);
|
||||
const available = this.availableSkills.map(s => s.name).join(', ');
|
||||
throw new Error(`Skill "${name}" not found. Available skills: ${available || 'none'}`);
|
||||
}
|
||||
|
||||
// Read and return the skill content
|
||||
const content = await readSkillContent(this.fs, skill);
|
||||
|
||||
return {
|
||||
content: `# Skill: ${skill.name}
|
||||
content: `## Skill: ${skill.name}
|
||||
|
||||
**Source**: ${skill.plugin === 'project' ? 'Project' : `Plugin: ${skill.plugin}`}
|
||||
**Description**: ${skill.description}
|
||||
**Path**: ${skill.path}
|
||||
**Base directory**: ${skill.path}
|
||||
|
||||
---
|
||||
|
||||
${content}`
|
||||
${content.trim()}`
|
||||
};
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
|
||||
Reference in new issue
Block a user