From ca49c0e68cc5df2b62eaeef8950de5786441cf67 Mon Sep 17 00:00:00 2001 From: John Naulty Date: Tue, 10 Dec 2024 22:50:26 -0800 Subject: [PATCH] feat: make NodePlugin and GoatPlugin creation conditional - NodePlugin is now only created when all required AWS credentials are present (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION, AWS_S3_BUCKET) - GoatPlugin is now only created when ALCHEMY_API_KEY is present - Added type annotations for plugins to handle undefined cases These changes prevent unnecessary plugin initialization when required credentials are missing and improve type safety. Issues introduced in: https://github.com/ai16z/eliza/pull/941 and https://github.com/ai16z/eliza/pull/898 --- agent/src/index.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/agent/src/index.ts b/agent/src/index.ts index 26d62c0995..f3ae5f04b3 100644 --- a/agent/src/index.ts +++ b/agent/src/index.ts @@ -371,7 +371,12 @@ export async function createAgent( character.name ); - nodePlugin ??= createNodePlugin(); + nodePlugin ??= ( + getSecret(character, "AWS_ACCESS_KEY_ID") && + getSecret(character, "AWS_SECRET_ACCESS_KEY") && + getSecret(character, "AWS_REGION") && + getSecret(character, "AWS_S3_BUCKET") + ) ? createNodePlugin() : undefined; const teeMode = getSecret(character, "TEE_MODE") || "OFF"; const walletSecretSalt = getSecret(character, "WALLET_SECRET_SALT"); @@ -384,9 +389,12 @@ export async function createAgent( throw new Error("Invalid TEE configuration"); } - const goatPlugin = await createGoatPlugin((secret) => - getSecret(character, secret) - ); + let goatPlugin: any | undefined; + if (getSecret(character, "ALCHEMY_API_KEY")) { + goatPlugin = await createGoatPlugin((secret) => + getSecret(character, secret) + ); + } return new AgentRuntime({ databaseAdapter: db,