Skip to content

Commit

Permalink
Merge pull request elizaOS#784 from xwxtwd/fix/character_json_file_pl…
Browse files Browse the repository at this point in the history
…ugins_field

fix: When the plugins field in the .character.json file is configured with plugin name.
  • Loading branch information
lalalune authored Dec 2, 2024
2 parents 9829852 + 83176f8 commit a973379
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 6 additions & 2 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ function tryLoadFile(filePath: string): string | null {
}
}

function isAllStrings(arr: unknown[]): boolean {
return Array.isArray(arr) && arr.every((item) => typeof item === "string");
}

export async function loadCharacters(
charactersArg: string
): Promise<Character[]> {
Expand Down Expand Up @@ -149,12 +153,12 @@ export async function loadCharacters(
validateCharacterConfig(character);

// Handle plugins
if (character.plugins) {
if (isAllStrings(character.plugins)) {
elizaLogger.info("Plugins are: ", character.plugins);
const importedPlugins = await Promise.all(
character.plugins.map(async (plugin) => {
const importedPlugin = await import(plugin);
return importedPlugin;
return importedPlugin.default;
})
);
character.plugins = importedPlugins;
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/enviroment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ export const CharacterSchema = z.object({
adjectives: z.array(z.string()),
knowledge: z.array(z.string()).optional(),
clients: z.array(z.nativeEnum(Clients)),
plugins: z.array(PluginSchema),
plugins: z.union([
z.array(z.string()),
z.array(PluginSchema),
]),
settings: z
.object({
secrets: z.record(z.string()).optional(),
Expand Down

0 comments on commit a973379

Please sign in to comment.