"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadBuilderTools = loadBuilderTools;
exports.loadReferenceSection = loadReferenceSection;
const promises_1 = require("fs/promises");
const path_1 = require("path");
const tool_loader_1 = require("../../shared/tool-loader");
const caches_1 = require("./caches");
async function loadBuilderTools(tags) {
    return (0, tool_loader_1.loadToolsFromServers)(tags, { toolServerMap: caches_1.toolServerMap, toolDefCache: caches_1.toolDefCache }, { logPrefix: 'workflowBuilder' });
}
/**
 * Load a specific section from the activity-types reference file.
 * Returns the markdown for the requested activity type (await, signal, interrupt).
 * Returns empty string if the section or file is not found.
 */
async function loadReferenceSection(section) {
    try {
        const refPath = (0, path_1.join)(__dirname, '..', 'reference', 'activity-types.md');
        const content = await (0, promises_1.readFile)(refPath, 'utf-8');
        // Extract the section between ## <name> and the next ## or end of file
        const sectionHeader = `## ${section}`;
        const startIdx = content.indexOf(sectionHeader);
        if (startIdx === -1)
            return '';
        const afterHeader = content.indexOf('\n', startIdx);
        const nextSection = content.indexOf('\n## ', afterHeader + 1);
        const endIdx = nextSection === -1 ? content.length : nextSection;
        return content.slice(startIdx, endIdx).trim();
    }
    catch {
        return '';
    }
}
