/**
 * load_skill — agent tool for on-demand skill loading.
 *
 * The agent calls this when it needs domain-specific guidance
 * that is listed in the skill index but not yet loaded.
 */
import { Type as T } from 'typebox';
import { loadSkillContent } from '../skill-loader.js';
export function createLoadSkillTool(skills, graphResolver) {
    const index = new Map(skills.map(s => [s.name, s]));
    return {
        name: 'load_skill',
        label: 'Load Skill',
        description: 'Load domain-specific guidance for a task. Call this when a skill listed in "Available Skills" is relevant to what the user is asking for. Returns the skill\'s markdown content.',
        parameters: T.Object({
            name: T.String({
                description: 'The skill name to load, e.g. "create-deck"',
            }),
            file: T.Optional(T.String({
                description: 'Optional sub-file within the skill to load, e.g. "slide-selection.md". Omit to load the main skill entrypoint.',
            })),
        }),
        execute: async (_toolCallId, params) => {
            const meta = index.get(params.name);
            if (!meta) {
                const available = [...index.keys()].join(', ');
                return {
                    content: [
                        {
                            type: 'text',
                            text: `Skill "${params.name}" not found. Available skills: ${available || 'none'}.`,
                        },
                    ],
                    details: { error: 'not_found', available: [...index.keys()] },
                };
            }
            const content = loadSkillContent(meta, params.file, graphResolver);
            return {
                content: [{ type: 'text', text: content }],
                details: { name: meta.name, file: params.file ?? 'skill.md' },
            };
        },
    };
}
//# sourceMappingURL=load-skill.js.map