create-eliza
Version:
Initialize an Eliza project
72 lines (68 loc) • 1.88 kB
JavaScript
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
import {
AgentRuntime,
logger,
v4_default
} from "./chunk-YLRD7CRE.js";
// src/project.ts
import { resolve } from "node:path";
async function loadProject(path) {
try {
const projectPath = resolve(path);
logger.info(`Loading project from ${projectPath}`);
let projectConfig;
try {
const configPath = resolve(projectPath, "eliza.config.js");
logger.info(`Loading config from ${configPath}`);
try {
const module = await import(configPath);
projectConfig = module.default;
} catch (error) {
throw new Error(`Failed to load config: ${error.message}`);
}
if (!projectConfig) {
throw new Error("Config file is empty");
}
if (!projectConfig.agents || !Array.isArray(projectConfig.agents)) {
throw new Error("Config file must have an agents array");
}
} catch (error) {
logger.warn("No eliza.config.js found, using default configuration");
projectConfig = {
agents: [{
character: {
name: "Test Agent",
bio: ["A test agent for running automated tests"],
templates: {},
settings: {}
}
}]
};
}
const agent = projectConfig.agents[0];
if (!agent) {
throw new Error("No agents defined in project configuration");
}
const runtime = new AgentRuntime({
agentId: v4_default(),
character: agent.character,
plugins: agent.plugins || []
});
if (agent.init) {
await agent.init(runtime);
}
return {
runtime,
path: projectPath,
agent
};
} catch (error) {
logger.error("Failed to load project:", error);
throw error;
}
}
export {
loadProject
};
//# sourceMappingURL=chunk-5FERK7PX.js.map