create-eliza
Version:
Initialize an Eliza project
81 lines (77 loc) • 2.41 kB
JavaScript
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
import {
AgentRuntime,
logger,
v4_default
} from "./chunk-RYUT2GQB.js";
// src/project.ts
import { resolve } from "node:path";
import { readFileSync } from "node:fs";
async function loadProject(path) {
try {
const projectPath = resolve(path);
logger.info(`Loading project from ${projectPath}`);
let projectConfig;
try {
const configPath = resolve(projectPath, "eliza.config.json");
logger.info(`Loading config from ${configPath}`);
try {
const configContent = readFileSync(configPath, "utf8");
projectConfig = JSON.parse(configContent);
logger.info("Successfully loaded config:", projectConfig);
} catch (error) {
logger.error("Failed to load config file:", error);
throw new Error(`Failed to load config: ${error.message}`);
}
if (!projectConfig) {
logger.error("Config file is empty");
throw new Error("Config file is empty");
}
if (!projectConfig.agents || !Array.isArray(projectConfig.agents)) {
logger.error("Invalid config format:", projectConfig);
throw new Error("Config file must have an agents array");
}
} catch (error) {
logger.warn("No eliza.config.json found, using default configuration");
projectConfig = {
agents: [{
character: {
name: "Test Agent",
bio: ["A test agent for running automated tests"],
templates: {},
settings: {},
system: "You are a test agent for running automated tests.",
messageExamples: []
}
}]
};
}
const agent = projectConfig.agents[0];
if (!agent) {
logger.error("No agents defined in project configuration");
throw new Error("No agents defined in project configuration");
}
logger.info("Creating runtime with agent:", agent);
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-QNVW46RF.js.map