UNPKG

@chainlink/mcp-server

Version:
76 lines 3.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.loadCreWorkflowContent = exports.loadCreWorkflowsIndex = void 0; const fs_1 = require("fs"); const path_1 = require("path"); const logger_1 = require("../../../utils/logger"); const cache_1 = require("./cache"); const loadCreWorkflowsIndex = async () => { const cached = (0, cache_1.getCachedCreWorkflowsIndex)(); if (cached !== null) return cached; try { const workflowsDir = (0, path_1.join)(__dirname, "..", "..", "..", "..", "external", "cre-sdk-typescript", "packages", "cre-sdk-examples", "src", "workflows"); logger_1.Logger.debug(`Attempting to load CRE workflows from: ${workflowsDir}`); if (!(0, fs_1.existsSync)(workflowsDir)) { logger_1.Logger.debug(`CRE workflows directory not found: ${workflowsDir}`); (0, cache_1.setCachedCreWorkflowsIndex)(null); return null; } const walk = (dir, base) => { const entries = []; for (const name of (0, fs_1.readdirSync)(dir)) { const full = (0, path_1.join)(dir, name); const st = (0, fs_1.statSync)(full); if (st.isDirectory()) { entries.push(...walk(full, base)); } else if (st.isFile() && name.endsWith(".ts")) { const rel = (0, path_1.relative)(base, full); const parts = rel.split("/"); const category = parts.length > 1 ? (parts[0] ?? "misc") : "misc"; const entryName = parts.join("/").replace(/\.(ts|tsx)$/, ""); entries.push({ relativePath: rel, name: entryName, category, }); } } return entries; }; const index = walk(workflowsDir, workflowsDir); (0, cache_1.setCachedCreWorkflowsIndex)(index); logger_1.Logger.debug(`Loaded ${index.length} CRE workflow example files`); return index; } catch (error) { logger_1.Logger.debug(`Failed to index CRE workflows: ${error}`); (0, cache_1.setCachedCreWorkflowsIndex)(null); return null; } }; exports.loadCreWorkflowsIndex = loadCreWorkflowsIndex; const loadCreWorkflowContent = async (relativePath) => { const cached = (0, cache_1.getCachedCreWorkflowContent)(relativePath); if (cached !== undefined) return cached; try { const filePath = (0, path_1.join)(__dirname, "..", "..", "..", "..", "external", "cre-sdk-typescript", "packages", "cre-sdk-examples", "src", "workflows", relativePath); if (!(0, fs_1.existsSync)(filePath)) { logger_1.Logger.debug(`CRE workflow not found: ${filePath}`); (0, cache_1.setCachedCreWorkflowContent)(relativePath, null); return null; } const content = (0, fs_1.readFileSync)(filePath, "utf8"); (0, cache_1.setCachedCreWorkflowContent)(relativePath, content); return content; } catch (error) { logger_1.Logger.debug(`Failed to load CRE workflow ${relativePath}: ${error}`); (0, cache_1.setCachedCreWorkflowContent)(relativePath, null); return null; } }; exports.loadCreWorkflowContent = loadCreWorkflowContent; //# sourceMappingURL=load.js.map