UNPKG

create-eliza

Version:

Initialize an Eliza project

85 lines (81 loc) 2.49 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 isPlugin = !projectModule.agents && typeof projectModule.name === "string" && typeof projectModule.description === "string"; if (isPlugin) { logger.info("Detected plugin module instead of project"); const dummyCharacter = { name: `Test Agent for ${projectModule.name}`, bio: `Test agent for running tests on the ${projectModule.name} plugin`, system: "You are a test agent for running plugin tests" }; const dummyAgent = { character: dummyCharacter, plugins: [projectModule] }; return { agents: [dummyAgent], dir, isPlugin: true, pluginModule: projectModule }; } 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-KFUCLUH5.js.map