Skip to content

Commit 60f0e9e

Browse files
committed
refactor: reorganize imports and clean up unused code in agent and plugin-solana
1 parent 6bc783d commit 60f0e9e

File tree

2 files changed

+32
-43
lines changed

2 files changed

+32
-43
lines changed

agent/src/index.ts

+30-41
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,17 @@ import {
3434
stringToUuid,
3535
validateCharacterConfig,
3636
} from "@elizaos/core";
37-
import { TrustScoreDatabase } from "@elizaos/plugin-trustdb";
38-
// import { zgPlugin } from "@elizaos/plugin-0g";
3937
import { zgPlugin } from "@elizaos/plugin-0g";
4038

4139
import { bootstrapPlugin } from "@elizaos/plugin-bootstrap";
4240
import createGoatPlugin from "@elizaos/plugin-goat";
4341
// import { intifacePlugin } from "@elizaos/plugin-intiface";
44-
import { DirectClient } from "@elizaos/client-direct";
4542
import { ThreeDGenerationPlugin } from "@elizaos/plugin-3d-generation";
4643
import { abstractPlugin } from "@elizaos/plugin-abstract";
4744
import { alloraPlugin } from "@elizaos/plugin-allora";
4845
import { aptosPlugin } from "@elizaos/plugin-aptos";
4946
import { artheraPlugin } from "@elizaos/plugin-arthera";
47+
import { autonomePlugin } from "@elizaos/plugin-autonome";
5048
import { availPlugin } from "@elizaos/plugin-avail";
5149
import { avalanchePlugin } from "@elizaos/plugin-avalanche";
5250
import { binancePlugin } from "@elizaos/plugin-binance";
@@ -58,8 +56,8 @@ import {
5856
tradePlugin,
5957
webhookPlugin,
6058
} from "@elizaos/plugin-coinbase";
61-
import { coinmarketcapPlugin } from "@elizaos/plugin-coinmarketcap";
6259
import { coingeckoPlugin } from "@elizaos/plugin-coingecko";
60+
import { coinmarketcapPlugin } from "@elizaos/plugin-coinmarketcap";
6361
import { confluxPlugin } from "@elizaos/plugin-conflux";
6462
import { createCosmosPlugin } from "@elizaos/plugin-cosmos";
6563
import { cronosZkEVMPlugin } from "@elizaos/plugin-cronoszkevm";
@@ -78,7 +76,6 @@ import { obsidianPlugin } from "@elizaos/plugin-obsidian";
7876
import { sgxPlugin } from "@elizaos/plugin-sgx";
7977
import { solanaPlugin } from "@elizaos/plugin-solana";
8078
import { solanaAgentkitPlguin } from "@elizaos/plugin-solana-agentkit";
81-
import { autonomePlugin } from "@elizaos/plugin-autonome";
8279
import { storyPlugin } from "@elizaos/plugin-story";
8380
import { suiPlugin } from "@elizaos/plugin-sui";
8481
import { TEEMode, teePlugin } from "@elizaos/plugin-tee";
@@ -88,23 +85,22 @@ import { tonPlugin } from "@elizaos/plugin-ton";
8885
import { webSearchPlugin } from "@elizaos/plugin-web-search";
8986

9087
import { giphyPlugin } from "@elizaos/plugin-giphy";
88+
import { hyperliquidPlugin } from "@elizaos/plugin-hyperliquid";
9189
import { letzAIPlugin } from "@elizaos/plugin-letzai";
9290
import { thirdwebPlugin } from "@elizaos/plugin-thirdweb";
93-
import { hyperliquidPlugin } from "@elizaos/plugin-hyperliquid";
9491
import { zksyncEraPlugin } from "@elizaos/plugin-zksync-era";
9592

93+
import { akashPlugin } from "@elizaos/plugin-akash";
9694
import { OpacityAdapter } from "@elizaos/plugin-opacity";
9795
import { openWeatherPlugin } from "@elizaos/plugin-open-weather";
98-
import { stargazePlugin } from "@elizaos/plugin-stargaze";
99-
import { akashPlugin } from "@elizaos/plugin-akash";
10096
import { quaiPlugin } from "@elizaos/plugin-quai";
97+
import { stargazePlugin } from "@elizaos/plugin-stargaze";
10198
import Database from "better-sqlite3";
10299
import fs from "fs";
103100
import net from "net";
104101
import path from "path";
105102
import { fileURLToPath } from "url";
106103
import yargs from "yargs";
107-
import {dominosPlugin} from "@elizaos/plugin-dominos";
108104

109105
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
110106
const __dirname = path.dirname(__filename); // get the name of the directory
@@ -626,8 +622,7 @@ export async function createAgent(
626622
character: Character,
627623
db: IDatabaseAdapter,
628624
cache: ICacheManager,
629-
token: string,
630-
trustDb: TrustScoreDatabase
625+
token: string
631626
): Promise<AgentRuntime> {
632627
elizaLogger.log(`Creating runtime for character ${character.name}`);
633628

@@ -707,15 +702,15 @@ export async function createAgent(
707702
databaseAdapter: db,
708703
token,
709704
modelProvider: character.modelProvider,
705+
evaluators: [],
710706
character,
711707
// character.plugins are handled when clients are added
712708
plugins: [
713709
bootstrapPlugin,
714-
twitterPlugin,
715-
// getSecret(character, "CONFLUX_CORE_PRIVATE_KEY")
716-
// ? confluxPlugin
717-
// : null,
718-
// nodePlugin,
710+
getSecret(character, "CONFLUX_CORE_PRIVATE_KEY")
711+
? confluxPlugin
712+
: null,
713+
nodePlugin,
719714
getSecret(character, "TAVILY_API_KEY") ? webSearchPlugin : null,
720715
getSecret(character, "SOLANA_PUBLIC_KEY") ||
721716
(getSecret(character, "WALLET_PUBLIC_KEY") &&
@@ -726,11 +721,11 @@ export async function createAgent(
726721
? solanaAgentkitPlguin
727722
: null,
728723
getSecret(character, "AUTONOME_JWT_TOKEN") ? autonomePlugin : null,
729-
// (getSecret(character, "NEAR_ADDRESS") ||
730-
// getSecret(character, "NEAR_WALLET_PUBLIC_KEY")) &&
731-
// getSecret(character, "NEAR_WALLET_SECRET_KEY")
732-
// ? nearPlugin
733-
// : null,
724+
(getSecret(character, "NEAR_ADDRESS") ||
725+
getSecret(character, "NEAR_WALLET_PUBLIC_KEY")) &&
726+
getSecret(character, "NEAR_WALLET_SECRET_KEY")
727+
? nearPlugin
728+
: null,
734729
getSecret(character, "EVM_PUBLIC_KEY") ||
735730
(getSecret(character, "WALLET_PUBLIC_KEY") &&
736731
getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith("0x"))
@@ -749,7 +744,7 @@ export async function createAgent(
749744
getSecret(character, "SOLANA_ADMIN_PRIVATE_KEY")
750745
? nftGenerationPlugin
751746
: null,
752-
// getSecret(character, "ZEROG_PRIVATE_KEY") ? zgPlugin : null,
747+
getSecret(character, "ZEROG_PRIVATE_KEY") ? zgPlugin : null,
753748
getSecret(character, "COINMARKETCAP_API_KEY")
754749
? coinmarketcapPlugin
755750
: null,
@@ -764,7 +759,7 @@ export async function createAgent(
764759
getSecret(character, "LIVEPEER_GATEWAY_URL")
765760
? imageGenerationPlugin
766761
: null,
767-
// getSecret(character, "FAL_API_KEY") ? ThreeDGenerationPlugin : null,
762+
getSecret(character, "FAL_API_KEY") ? ThreeDGenerationPlugin : null,
768763
...(getSecret(character, "COINBASE_API_KEY") &&
769764
getSecret(character, "COINBASE_PRIVATE_KEY")
770765
? [
@@ -858,8 +853,7 @@ export async function createAgent(
858853
? quaiPlugin
859854
: null,
860855
].filter(Boolean),
861-
evaluators: [whaleDataEvaluator, trustScoreEvaluator],
862-
providers: [whaleDataProvider, trustScoreProvider],
856+
providers: [],
863857
actions: [],
864858
services: [],
865859
managers: [],
@@ -944,9 +938,7 @@ async function startAgent(
944938
character: Character,
945939
directClient: DirectClient
946940
): Promise<AgentRuntime> {
947-
let dbAdapter: IDatabaseAdapter & IDatabaseCacheAdapter;
948-
let trustDb: TrustScoreDatabase;
949-
941+
let db: IDatabaseAdapter & IDatabaseCacheAdapter;
950942
try {
951943
character.id ??= stringToUuid(character.name);
952944
character.username ??= character.name;
@@ -958,25 +950,22 @@ async function startAgent(
958950
fs.mkdirSync(dataDir, { recursive: true });
959951
}
960952

961-
const { db, trustDb: tdb } = initializeDatabase(dataDir) as any;
962-
dbAdapter = db;
963-
trustDb = tdb;
953+
db = initializeDatabase(dataDir) as IDatabaseAdapter &
954+
IDatabaseCacheAdapter;
964955

965-
await dbAdapter.init();
956+
await db.init();
966957

967958
const cache = initializeCache(
968959
process.env.CACHE_STORE ?? CacheStore.DATABASE,
969960
character,
970961
"",
971-
dbAdapter
972-
);
973-
962+
db
963+
); // "" should be replaced with dir for file system caching. THOUGHTS: might probably make this into an env
974964
const runtime: AgentRuntime = await createAgent(
975965
character,
976-
dbAdapter,
966+
db,
977967
cache,
978-
token,
979-
trustDb
968+
token
980969
);
981970

982971
// start services/plugins/process knowledge
@@ -998,8 +987,8 @@ async function startAgent(
998987
error
999988
);
1000989
elizaLogger.error(error);
1001-
if (dbAdapter) {
1002-
await dbAdapter.close();
990+
if (db) {
991+
await db.close();
1003992
}
1004993
throw error;
1005994
}
@@ -1074,4 +1063,4 @@ const startAgents = async () => {
10741063
startAgents().catch((error) => {
10751064
elizaLogger.error("Unhandled error in startAgents:", error);
10761065
process.exit(1);
1077-
});
1066+
});

packages/plugin-solana/src/keypairUtils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { IAgentRuntime, elizaLogger } from "@elizaos/core";
2-
import { DeriveKeyProvider, TEEMode } from "@elizaos/plugin-tee";
31
import { Keypair, PublicKey } from "@solana/web3.js";
2+
import { DeriveKeyProvider, TEEMode } from "@elizaos/plugin-tee";
43
import bs58 from "bs58";
4+
import { IAgentRuntime, elizaLogger } from "@elizaos/core";
55

66
export interface KeypairResult {
77
keypair?: Keypair;

0 commit comments

Comments
 (0)