UNPKG

@openai/agents-core

Version:

The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.

98 lines • 3.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.localDirLazySkillSource = localDirLazySkillSource; const node_fs_1 = require("node:fs"); const node_path_1 = require("node:path"); const skills_1 = require("./capabilities/skills.js"); const entries_1 = require("./entries/index.js"); const hostPath_1 = require("./shared/hostPath.js"); function localDirLazySkillSource(srcOrOptions) { const options = typeof srcOrOptions === 'string' ? { src: srcOrOptions } : srcOrOptions; const sourceRoot = (0, node_path_1.resolve)(options.baseDir ?? process.cwd(), options.src); return { source: (0, entries_1.localDir)({ src: sourceRoot }), getIndex: (manifest) => discoverLocalDirSkillIndex(options, manifest.extraPathGrants), }; } function discoverLocalDirSkillIndex(options, sourceGrants = []) { const base = (0, node_path_1.resolve)(options.baseDir ?? process.cwd()); let root; try { root = resolveLocalSkillSourcePath(options.src, base, sourceGrants); } catch { return []; } if (hasLocalSourceSymlinkAncestor(root) || !isDirectory(root)) { return []; } return (0, node_fs_1.readdirSync)(root, { withFileTypes: true }) .filter((entry) => entry.isDirectory()) .sort((left, right) => left.name.localeCompare(right.name)) .flatMap((entry) => { const skillMarkdownPath = (0, node_path_1.join)(root, entry.name, 'SKILL.md'); if (!isRegularFileWithoutSymlink(skillMarkdownPath)) { return []; } let markdown; try { markdown = (0, node_fs_1.readFileSync)(skillMarkdownPath, 'utf8'); } catch { return []; } const frontmatter = (0, skills_1.parseSkillFrontmatter)(markdown); return [ { name: frontmatter.name ?? entry.name, description: frontmatter.description ?? 'No description provided.', path: entry.name, }, ]; }); } function resolveLocalSkillSourcePath(sourcePath, base, sourceGrants) { const resolvedSourcePath = (0, node_path_1.resolve)(base, sourcePath); if ((0, hostPath_1.isHostPathWithinRoot)(base, resolvedSourcePath) || sourceGrants.some((grant) => (0, hostPath_1.isHostPathWithinRoot)((0, node_path_1.resolve)((0, hostPath_1.sandboxPathGrantHostPath)(grant)), resolvedSourcePath))) { return resolvedSourcePath; } throw new Error('local skill source is outside base directory'); } function isDirectory(path) { try { return (0, node_fs_1.lstatSync)(path).isDirectory(); } catch { return false; } } function hasLocalSourceSymlinkAncestor(path) { const resolvedPath = (0, node_path_1.resolve)(path); let current = (0, node_path_1.dirname)(resolvedPath); while (current !== (0, node_path_1.dirname)(current)) { const parent = (0, node_path_1.dirname)(current); if (parent === (0, node_path_1.dirname)(parent)) { break; } try { if ((0, node_fs_1.lstatSync)(current).isSymbolicLink()) { return true; } } catch { return false; } current = parent; } return false; } function isRegularFileWithoutSymlink(path) { try { return (0, node_fs_1.lstatSync)(path).isFile(); } catch { return false; } } //# sourceMappingURL=localSkills.js.map