UNPKG

create-eliza

Version:

Initialize an Eliza project

66 lines (62 loc) 1.79 kB
import { createRequire } from 'module'; const require = createRequire(import.meta.url); import { logger } from "./chunk-UIEY2LL5.js"; // src/project.ts import * as fs from "node:fs"; import path from "node:path"; async function loadProject(dir) { try { const entryPoints = [ path.join(dir, "src/index.ts"), path.join(dir, "src/index.js"), path.join(dir, "dist/index.js"), path.join(dir, "index.ts"), path.join(dir, "index.js") ]; let projectModule = null; for (const entryPoint of entryPoints) { if (fs.existsSync(entryPoint)) { try { const importPath = path.resolve(entryPoint); projectModule = await import(importPath); logger.info(`Loaded project from ${entryPoint}`); break; } catch (error) { logger.warn(`Failed to import project from ${entryPoint}:`, error); } } } if (!projectModule) { throw new Error("Could not find project entry point"); } const agents = []; for (const [key, value] of Object.entries(projectModule)) { if (key === "default" && value && typeof value === "object") { if (Array.isArray(value.agents)) { agents.push(...value.agents); } else if (value.character && value.init) { agents.push(value); } } else if (value && typeof value === "object" && value.character && value.init) { agents.push(value); } } if (agents.length === 0) { throw new Error("No agents found in project"); } const project = { agents, dir }; return project; } catch (error) { logger.error("Error loading project:", error); throw error; } } export { loadProject }; //# sourceMappingURL=chunk-R52L4YNH.js.map