Skip to content

Commit

Permalink
Feat: Enable Multiple remote character urls
Browse files Browse the repository at this point in the history
  • Loading branch information
leeran7 committed Jan 15, 2025
1 parent 640b4e8 commit 55bc6cc
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 52 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ SERVER_PORT=3000
SUPABASE_URL=
SUPABASE_ANON_KEY=

# Remote character url (optional)
REMOTE_CHARACTER_URL=
# Comma separated list of remote character urls (optional)
REMOTE_CHARACTER_URLS=

###############################
#### Client Configurations ####
Expand Down
105 changes: 55 additions & 50 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,15 @@ async function loadCharacter(filePath: string): Promise<Character> {
return jsonToCharacter(filePath, character);
}

function commaSeparatedStringToArray(commaSeparated: string): string[] {
return commaSeparated?.split(",").map(value => value.trim())
}


export async function loadCharacters(
charactersArg: string
): Promise<Character[]> {
let characterPaths = charactersArg
?.split(",")
.map((filePath) => filePath.trim());
let characterPaths = commaSeparatedStringToArray(charactersArg)
const loadedCharacters: Character[] = [];

if (characterPaths?.length > 0) {
Expand Down Expand Up @@ -321,17 +324,19 @@ export async function loadCharacters(
}
}

if (loadedCharacters.length === 0) {
if (
process.env.REMOTE_CHARACTER_URL != "" &&
process.env.REMOTE_CHARACTER_URL.startsWith("http")
) {
const character = await loadCharacterFromUrl(
process.env.REMOTE_CHARACTER_URL
);
if (
process.env.REMOTE_CHARACTER_URLS != "" &&
process.env.REMOTE_CHARACTER_URLS.startsWith("http")
) {
elizaLogger.info("Loading characters from remote URLs");
let characterUrls = commaSeparatedStringToArray(process.env.REMOTE_CHARACTER_URLS)
for (const characterUrl of characterUrls) {
const character = await loadCharacterFromUrl(characterUrl);
loadedCharacters.push(character);
}
}

if (loadedCharacters.length === 0) {
elizaLogger.info("No characters found, using default character");
loadedCharacters.push(defaultCharacter);
}
Expand Down Expand Up @@ -773,8 +778,8 @@ export async function createAgent(
nodePlugin,
getSecret(character, "TAVILY_API_KEY") ? webSearchPlugin : null,
getSecret(character, "SOLANA_PUBLIC_KEY") ||
(getSecret(character, "WALLET_PUBLIC_KEY") &&
!getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith("0x"))
(getSecret(character, "WALLET_PUBLIC_KEY") &&
!getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith("0x"))
? solanaPlugin
: null,
getSecret(character, "SOLANA_PRIVATE_KEY")
Expand All @@ -783,25 +788,25 @@ export async function createAgent(
getSecret(character, "AUTONOME_JWT_TOKEN") ? autonomePlugin : null,
(getSecret(character, "NEAR_ADDRESS") ||
getSecret(character, "NEAR_WALLET_PUBLIC_KEY")) &&
getSecret(character, "NEAR_WALLET_SECRET_KEY")
getSecret(character, "NEAR_WALLET_SECRET_KEY")
? nearPlugin
: null,
getSecret(character, "EVM_PUBLIC_KEY") ||
(getSecret(character, "WALLET_PUBLIC_KEY") &&
getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith("0x"))
(getSecret(character, "WALLET_PUBLIC_KEY") &&
getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith("0x"))
? evmPlugin
: null,
getSecret(character, "COSMOS_RECOVERY_PHRASE") &&
getSecret(character, "COSMOS_AVAILABLE_CHAINS") &&
createCosmosPlugin(),
getSecret(character, "COSMOS_AVAILABLE_CHAINS") &&
createCosmosPlugin(),
(getSecret(character, "SOLANA_PUBLIC_KEY") ||
(getSecret(character, "WALLET_PUBLIC_KEY") &&
!getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith(
"0x"
))) &&
getSecret(character, "SOLANA_ADMIN_PUBLIC_KEY") &&
getSecret(character, "SOLANA_PRIVATE_KEY") &&
getSecret(character, "SOLANA_ADMIN_PRIVATE_KEY")
getSecret(character, "SOLANA_ADMIN_PUBLIC_KEY") &&
getSecret(character, "SOLANA_PRIVATE_KEY") &&
getSecret(character, "SOLANA_ADMIN_PRIVATE_KEY")
? nftGenerationPlugin
: null,
getSecret(character, "ZEROG_PRIVATE_KEY") ? zgPlugin : null,
Expand All @@ -812,43 +817,43 @@ export async function createAgent(
? coinbaseCommercePlugin
: null,
getSecret(character, "FAL_API_KEY") ||
getSecret(character, "OPENAI_API_KEY") ||
getSecret(character, "VENICE_API_KEY") ||
getSecret(character, "NINETEEN_AI_API_KEY") ||
getSecret(character, "HEURIST_API_KEY") ||
getSecret(character, "LIVEPEER_GATEWAY_URL")
getSecret(character, "OPENAI_API_KEY") ||
getSecret(character, "VENICE_API_KEY") ||
getSecret(character, "NINETEEN_AI_API_KEY") ||
getSecret(character, "HEURIST_API_KEY") ||
getSecret(character, "LIVEPEER_GATEWAY_URL")
? imageGenerationPlugin
: null,
getSecret(character, "FAL_API_KEY") ? ThreeDGenerationPlugin : null,
...(getSecret(character, "COINBASE_API_KEY") &&
getSecret(character, "COINBASE_PRIVATE_KEY")
getSecret(character, "COINBASE_PRIVATE_KEY")
? [
coinbaseMassPaymentsPlugin,
tradePlugin,
tokenContractPlugin,
advancedTradePlugin,
]
coinbaseMassPaymentsPlugin,
tradePlugin,
tokenContractPlugin,
advancedTradePlugin,
]
: []),
...(teeMode !== TEEMode.OFF && walletSecretSalt ? [teePlugin] : []),
teeMode !== TEEMode.OFF &&
walletSecretSalt &&
getSecret(character, "VLOG")
walletSecretSalt &&
getSecret(character, "VLOG")
? verifiableLogPlugin
: null,
getSecret(character, "SGX") ? sgxPlugin : null,
getSecret(character, "ENABLE_TEE_LOG") &&
((teeMode !== TEEMode.OFF && walletSecretSalt) ||
getSecret(character, "SGX"))
((teeMode !== TEEMode.OFF && walletSecretSalt) ||
getSecret(character, "SGX"))
? teeLogPlugin
: null,
getSecret(character, "COINBASE_API_KEY") &&
getSecret(character, "COINBASE_PRIVATE_KEY") &&
getSecret(character, "COINBASE_NOTIFICATION_URI")
getSecret(character, "COINBASE_PRIVATE_KEY") &&
getSecret(character, "COINBASE_NOTIFICATION_URI")
? webhookPlugin
: null,
goatPlugin,
getSecret(character, "COINGECKO_API_KEY") ||
getSecret(character, "COINGECKO_PRO_API_KEY")
getSecret(character, "COINGECKO_PRO_API_KEY")
? coingeckoPlugin
: null,
getSecret(character, "EVM_PROVIDER_URL") ? goatPlugin : null,
Expand All @@ -857,15 +862,15 @@ export async function createAgent(
: null,
getSecret(character, "B2_PRIVATE_KEY") ? b2Plugin : null,
getSecret(character, "BINANCE_API_KEY") &&
getSecret(character, "BINANCE_SECRET_KEY")
getSecret(character, "BINANCE_SECRET_KEY")
? binancePlugin
: null,
getSecret(character, "FLOW_ADDRESS") &&
getSecret(character, "FLOW_PRIVATE_KEY")
getSecret(character, "FLOW_PRIVATE_KEY")
? flowPlugin
: null,
getSecret(character, "LENS_ADDRESS") &&
getSecret(character, "LENS_PRIVATE_KEY")
getSecret(character, "LENS_PRIVATE_KEY")
? lensPlugin
: null,
getSecret(character, "APTOS_PRIVATE_KEY") ? aptosPlugin : null,
Expand All @@ -880,10 +885,10 @@ export async function createAgent(
getSecret(character, "SUI_PRIVATE_KEY") ? suiPlugin : null,
getSecret(character, "STORY_PRIVATE_KEY") ? storyPlugin : null,
getSecret(character, "SQUID_SDK_URL") &&
getSecret(character, "SQUID_INTEGRATOR_ID") &&
getSecret(character, "SQUID_EVM_ADDRESS") &&
getSecret(character, "SQUID_EVM_PRIVATE_KEY") &&
getSecret(character, "SQUID_API_THROTTLE_INTERVAL")
getSecret(character, "SQUID_INTEGRATOR_ID") &&
getSecret(character, "SQUID_EVM_ADDRESS") &&
getSecret(character, "SQUID_EVM_PRIVATE_KEY") &&
getSecret(character, "SQUID_API_THROTTLE_INTERVAL")
? squidRouterPlugin
: null,
getSecret(character, "FUEL_PRIVATE_KEY") ? fuelPlugin : null,
Expand All @@ -892,7 +897,7 @@ export async function createAgent(
: null,
getSecret(character, "BIRDEYE_API_KEY") ? birdeyePlugin : null,
getSecret(character, "ECHOCHAMBERS_API_URL") &&
getSecret(character, "ECHOCHAMBERS_API_KEY")
getSecret(character, "ECHOCHAMBERS_API_KEY")
? echoChambersPlugin
: null,
getSecret(character, "LETZAI_API_KEY") ? letzAIPlugin : null,
Expand All @@ -905,7 +910,7 @@ export async function createAgent(
? genLayerPlugin
: null,
getSecret(character, "AVAIL_SEED") &&
getSecret(character, "AVAIL_APP_ID")
getSecret(character, "AVAIL_APP_ID")
? availPlugin
: null,
getSecret(character, "OPEN_WEATHER_API_KEY")
Expand All @@ -923,7 +928,7 @@ export async function createAgent(
? hyperliquidPlugin
: null,
getSecret(character, "AKASH_MNEMONIC") &&
getSecret(character, "AKASH_WALLET_ADDRESS")
getSecret(character, "AKASH_WALLET_ADDRESS")
? akashPlugin
: null,
getSecret(character, "QUAI_PRIVATE_KEY") ? quaiPlugin : null,
Expand Down Expand Up @@ -1098,7 +1103,7 @@ const startAgents = async () => {
let charactersArg = args.characters || args.character;
let characters = [defaultCharacter];

if (charactersArg) {
if (charactersArg || process.env.REMOTE_CHARACTER_URLS != "") {
characters = await loadCharacters(charactersArg);
}

Expand Down

0 comments on commit 55bc6cc

Please sign in to comment.