forked from elizaOS/eliza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.ts
45 lines (38 loc) · 1.29 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import fs from "fs";
import yaml from "js-yaml";
import path from "path";
import { fileURLToPath } from "url";
import { Action } from "../core/types";
const ROOT_DIR = path.resolve(fileURLToPath(import.meta.url), "../../../src");
interface ActionConfig {
name: string;
path: string;
}
export function loadActionConfigs(configPath: string): ActionConfig[] {
if (!fs.existsSync(configPath)) {
console.error(`Config file not found at path: ${configPath}`);
return [];
}
const configFile = fs.readFileSync(configPath, "utf8");
const parsedConfig = yaml.load(configFile) as { actions: ActionConfig[] };
return parsedConfig?.actions || [];
}
export async function loadCustomActions(
actionConfigs: ActionConfig[]
): Promise<Action[]> {
const actions = [];
for (const config of actionConfigs) {
const resolvedPath = path.resolve(ROOT_DIR, config.path);
console.log(`Importing action from: ${resolvedPath}`); // Debugging log
try {
const actionModule = await import(resolvedPath);
actions.push(actionModule[config.name]);
} catch (error) {
console.error(
`Failed to import action from ${resolvedPath}:`,
error
);
}
}
return actions;
}