Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/serrrfirat/eliza into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Dec 14, 2024
2 parents c20030f + e2f1658 commit 2f0519c
Show file tree
Hide file tree
Showing 11 changed files with 959 additions and 21 deletions.
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,11 @@ DEEPGRAM_API_KEY=
# MultiversX
MVX_PRIVATE_KEY= # Multiversx private key
MVX_NETWORK= # must be one of mainnet, devnet, testnet

# NEAR
NEAR_WALLET_SECRET_KEY=
NEAR_WALLET_PUBLIC_KEY=
NEAR_ADDRESS=
SLIPPAGE=1
RPC_URL=https://rpc.testnet.near.org
NEAR_NETWORK=testnet # or mainnet
1 change: 1 addition & 0 deletions agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@ai16z/plugin-starknet": "workspace:*",
"@ai16z/plugin-tee": "workspace:*",
"@ai16z/plugin-multiversx": "workspace:*",
"@ai16z/plugin-near": "workspace:*",
"readline": "1.3.0",
"ws": "8.18.0",
"yargs": "17.7.2"
Expand Down
64 changes: 43 additions & 21 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ import { solanaPlugin } from "@ai16z/plugin-solana";
import { teePlugin, TEEMode } from "@ai16z/plugin-tee";
import { aptosPlugin, TransferAptosToken } from "@ai16z/plugin-aptos";
import { flowPlugin } from "@ai16z/plugin-flow";
import { multiversxPlugin } from '@ai16z/plugin-multiversx';
import { multiversxPlugin } from "@ai16z/plugin-multiversx";
import { nearPlugin } from "@ai16z/plugin-near";
import Database from "better-sqlite3";
import fs from "fs";
import path from "path";
Expand Down Expand Up @@ -332,9 +333,9 @@ export async function initializeClients(
// each client can only register once
// and if we want two we can explicitly support it
const clients: Record<string, any> = {};
const clientTypes:string[] =
const clientTypes: string[] =
character.clients?.map((str) => str.toLowerCase()) || [];
elizaLogger.log('initializeClients', clientTypes, 'for', character.name)
elizaLogger.log("initializeClients", clientTypes, "for", character.name);

if (clientTypes.includes("auto")) {
const autoClient = await AutoClientInterface.start(runtime);
Expand All @@ -352,21 +353,25 @@ export async function initializeClients(
}

if (clientTypes.includes("twitter")) {
TwitterClientInterface.enableSearch = !isFalsish(getSecret(character, "TWITTER_SEARCH_ENABLE"));
const twitterClient = await TwitterClientInterface.start(runtime);
// TODO: This might be incorrect, please test if you are concerned about this functionality
// By default we have disabled this because it is annoying for users
(twitterClient as any).enableSearch = !isFalsish(
getSecret(character, "TWITTER_SEARCH_ENABLE")
);
if (twitterClient) clients.twitter = twitterClient;
}

if (clientTypes.includes("farcaster")) {
// why is this one different :(
const farcasterClient = new FarcasterAgentClient(runtime);
if (farcasterClient) {
farcasterClient.start();
clients.farcaster = farcasterClient;
farcasterClient.start();
clients.farcaster = farcasterClient;
}
}

elizaLogger.log('client keys', Object.keys(clients));
elizaLogger.log("client keys", Object.keys(clients));

if (character.plugins?.length > 0) {
for (const plugin of character.plugins) {
Expand All @@ -389,10 +394,19 @@ function isFalsish(input: any): boolean {
}

// Convert input to a string if it's not null or undefined
const value = input == null ? '' : String(input);
const value = input == null ? "" : String(input);

// List of common falsish string representations
const falsishValues = ['false', '0', 'no', 'n', 'off', 'null', 'undefined', ''];
const falsishValues = [
"false",
"0",
"no",
"n",
"off",
"null",
"undefined",
"",
];

// Check if the value (trimmed and lowercased) is in the falsish list
return falsishValues.includes(value.trim().toLowerCase());
Expand All @@ -409,7 +423,7 @@ export async function createAgent(
db: IDatabaseAdapter,
cache: ICacheManager,
token: string
):AgentRuntime {
): Promise<AgentRuntime> {
elizaLogger.success(
elizaLogger.successesTitle,
"Creating runtime for character",
Expand Down Expand Up @@ -454,7 +468,12 @@ export async function createAgent(
!getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith("0x"))
? solanaPlugin
: null,
getSecret(character, "EVM_PRIVATE_KEY") ||
(getSecret(character, "NEAR_ADDRESS") ||
getSecret(character, "NEAR_WALLET_PUBLIC_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"))
? evmPlugin
Expand Down Expand Up @@ -492,7 +511,7 @@ export async function createAgent(
? flowPlugin
: null,
getSecret(character, "APTOS_PRIVATE_KEY") ? aptosPlugin : null,
getSecret(character, 'MVX_PRIVATE_KEY') ? multiversxPlugin : null
getSecret(character, "MVX_PRIVATE_KEY") ? multiversxPlugin : null,
].filter(Boolean),
providers: [],
actions: [],
Expand All @@ -515,7 +534,10 @@ function initializeDbCache(character: Character, db: IDatabaseCacheAdapter) {
return cache;
}

async function startAgent(character: Character, directClient):AgentRuntime {
async function startAgent(
character: Character,
directClient
): Promise<AgentRuntime> {
let db: IDatabaseAdapter & IDatabaseCacheAdapter;
try {
character.id ??= stringToUuid(character.name);
Expand All @@ -534,7 +556,12 @@ async function startAgent(character: Character, directClient):AgentRuntime {
await db.init();

const cache = initializeDbCache(character, db);
const runtime:AgentRuntime = await createAgent(character, db, cache, token);
const runtime: AgentRuntime = await createAgent(
character,
db,
cache,
token
);

// start services/plugins/process knowledge
await runtime.initialize();
Expand All @@ -546,7 +573,7 @@ async function startAgent(character: Character, directClient):AgentRuntime {
directClient.registerAgent(runtime);

// report to console
elizaLogger.debug(`Started ${character.name} as ${runtime.agentId}`)
elizaLogger.debug(`Started ${character.name} as ${runtime.agentId}`);

return runtime;
} catch (error) {
Expand All @@ -563,7 +590,7 @@ async function startAgent(character: Character, directClient):AgentRuntime {
}

const startAgents = async () => {
const directClient = await DirectClientInterface.start();
const directClient = await DirectClientInterface.start(null);
const args = parseArguments();

let charactersArg = args.characters || args.character;
Expand All @@ -581,11 +608,6 @@ const startAgents = async () => {
} catch (error) {
elizaLogger.error("Error starting agents:", error);
}
// upload some agent functionality into directClient
directClient.startAgent = async character => {
// wrap it so we don't have to inject directClient later
return startAgent(character, directClient)
};

function chat() {
const agentId = characters[0].name ?? "Agent";
Expand Down
32 changes: 32 additions & 0 deletions packages/plugin-near/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@ai16z/plugin-near",
"version": "0.0.1",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",
"dependencies": {
"@ai16z/eliza": "workspace:*",
"@ai16z/plugin-trustdb": "workspace:*",
"@ref-finance/ref-sdk": "^1.4.6",
"tsup": "8.3.5",
"near-api-js": "5.0.1",
"bignumber.js": "9.1.2",
"node-cache": "5.1.2"
},
"devDependencies": {
"eslint": "^9.15.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.2.1",
"eslint-plugin-vitest": "0.5.4"
},
"scripts": {
"build": "tsup --format esm,cjs --dts",
"test": "vitest run",
"test:watch": "vitest",
"lint": "eslint . --fix"
},
"peerDependencies": {
"whatwg-url": "7.1.0",
"form-data": "4.0.1"
}
}
Loading

0 comments on commit 2f0519c

Please sign in to comment.