eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 1.33 kB
JavaScript
import{isAbsolute,posix}from"node:path";import{getSupportedModuleBaseName,normalizeLogicalPath,stripLogicalPathExtension}from"#discover/filesystem.js";function validateProgrammaticLogicalPath(e){return validateProgrammaticLogicalPathInternal(e,!1)}function validateProgrammaticLogicalPathInternal(e,t){if(e.length===0||isAbsolute(e)||e.includes(`\\`))throw Error(`Programmatic module logical path "${e}" must be a relative POSIX path.`);let n=normalizeLogicalPath(e);if(n===`.`||n.startsWith(`../`)||n.includes(`/../`)||posix.normalize(n)!==n)throw Error(`Programmatic module logical path "${e}" may not traverse directories.`);let r=n.split(`/`),i=r.at(-1);if(getSupportedModuleBaseName(i)===null)throw Error(`Programmatic module logical path "${e}" must use a supported JavaScript or TypeScript extension.`);let a=r[0],o=stripLogicalPathExtension(n);if(!(r.length===1&&[`agent`,`memory`,`sandbox`,`instrumentation`].includes(o)||a===`sandbox`&&r.length===2&&getSupportedModuleBaseName(i)===`sandbox`||[`channels`,`connections`,`hooks`,`instructions`,`memory`,`schedules`,`skills`,`tools`].includes(a)&&r.length>=2||t&&a===`extensions`&&r.length===2))throw Error(`Programmatic module logical path "${e}" does not select an eve module slot.`);return n}export{validateProgrammaticLogicalPath,validateProgrammaticLogicalPathInternal};