-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #163 from ponderingdemocritus/main
clean up index
- Loading branch information
Showing
10 changed files
with
379 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
node_modules | ||
dist | ||
elizaConfig.yaml | ||
custom_actions/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Load custom actions from the actions directory | ||
|
||
# Close this into a elizaConfig.yaml file that is ignored by git | ||
|
||
# Paths are relative to the core/src directory | ||
|
||
actions: | ||
- name: askClaude | ||
path: ./actions/askClaude.ts | ||
- name: epicAction | ||
path: ./custom_actions/epicAction.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} |
Oops, something went wrong.