Skip to content

Commit

Permalink
Merge branch 'add_zksync_era_support' of https://github.com/arose00/e…
Browse files Browse the repository at this point in the history
…liza into develop
  • Loading branch information
lalalune committed Dec 14, 2024
2 parents 451ca90 + d2c8374 commit a8aa112
Show file tree
Hide file tree
Showing 10 changed files with 1,616 additions and 103 deletions.
25 changes: 14 additions & 11 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,6 @@ ECHOCHAMBERS_DEFAULT_ROOM=general
ECHOCHAMBERS_POLL_INTERVAL=60
ECHOCHAMBERS_MAX_MESSAGES=10

# AWS S3 Configuration Settings for File Upload
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_REGION=
AWS_S3_BUCKET=
AWS_S3_UPLOAD_PATH=


# Deepgram
DEEPGRAM_API_KEY=

# MultiversX
MVX_PRIVATE_KEY= # Multiversx private key
MVX_NETWORK= # must be one of mainnet, devnet, testnet
Expand All @@ -287,3 +276,17 @@ NEAR_ADDRESS=
SLIPPAGE=1
RPC_URL=https://rpc.testnet.near.org
NEAR_NETWORK=testnet # or mainnet

# ZKsync Era Configuration
ZKSYNC_ADDRESS=
ZKSYNC_PRIVATE_KEY=

# AWS S3 Configuration Settings for File Upload
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_REGION=
AWS_S3_BUCKET=
AWS_S3_UPLOAD_PATH=

# Deepgram
DEEPGRAM_API_KEY=
1 change: 1 addition & 0 deletions agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@ai16z/plugin-tee": "workspace:*",
"@ai16z/plugin-multiversx": "workspace:*",
"@ai16z/plugin-near": "workspace:*",
"@ai16z/plugin-zksync-era": "workspace:*",
"readline": "1.3.0",
"ws": "8.18.0",
"yargs": "17.7.2"
Expand Down
78 changes: 45 additions & 33 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ import {
webhookPlugin,
advancedTradePlugin,
} from "@ai16z/plugin-coinbase";
import { DirectClient } from "@ai16z/client-direct";
import { confluxPlugin } from "@ai16z/plugin-conflux";
import { zksyncEraPlugin } from "@ai16z/plugin-zksync-era";
import { imageGenerationPlugin } from "@ai16z/plugin-image-generation";
import { evmPlugin } from "@ai16z/plugin-evm";
import { createNodePlugin } from "@ai16z/plugin-node";
Expand Down Expand Up @@ -64,7 +66,7 @@ export const wait = (minTime: number = 1000, maxTime: number = 3000) => {

const logFetch = async (url: string, options: any) => {
elizaLogger.info(`Fetching ${url}`);
elizaLogger.info(options);
elizaLogger.info(JSON.stringify(options, null, 2));
return fetch(url, options);
};

Expand Down Expand Up @@ -512,6 +514,7 @@ export async function createAgent(
: null,
getSecret(character, "APTOS_PRIVATE_KEY") ? aptosPlugin : null,
getSecret(character, "MVX_PRIVATE_KEY") ? multiversxPlugin : null,
getSecret(character, "ZKSYNC_PRIVATE_KEY") ? zksyncEraPlugin : null,
].filter(Boolean),
providers: [],
actions: [],
Expand Down Expand Up @@ -581,7 +584,7 @@ async function startAgent(
`Error starting agent for character ${character.name}:`,
error
);
console.error(error);
elizaLogger.error(error);
if (db) {
await db.close();
}
Expand All @@ -590,7 +593,9 @@ async function startAgent(
}

const startAgents = async () => {
const directClient = await DirectClientInterface.start(null);
const directClient = new DirectClient();
const serverPort = parseInt(settings.SERVER_PORT || "3000");
directClient.start(serverPort);
const args = parseArguments();

let charactersArg = args.characters || args.character;
Expand All @@ -609,9 +614,44 @@ const startAgents = async () => {
elizaLogger.error("Error starting agents:", error);
}

async function handleUserInput(input, agentId) {
elizaLogger.log("handleUserInput", input, agentId);
if (input.toLowerCase() === "exit") {
gracefulExit();
}

try {
const serverPort = parseInt(settings.SERVER_PORT || "3000");

const response = await fetch(
`http://localhost:${serverPort}/${agentId}/message`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
text: input,
userId: "user",
userName: "User",
}),
}
);

const data = await response.json();
elizaLogger.log("data: ", data);
data.forEach((message) =>
elizaLogger.log(`${"Agent"}: ${message.text}`)
);
} catch (error) {
elizaLogger.error("Error fetching response:", error);
}
}

function chat() {
elizaLogger.log("chat");
const agentId = characters[0].name ?? "Agent";
elizaLogger.log("agentId: ", agentId);
rl.question("You: ", async (input) => {
elizaLogger.log("input: ", input);
await handleUserInput(input, agentId);
if (input.toLowerCase() !== "exit") {
chat(); // Loop back to ask another question
Expand All @@ -621,6 +661,8 @@ const startAgents = async () => {

if (!args["non-interactive"]) {
elizaLogger.log("Chat started. Type 'exit' to quit.");
// log an empty line
elizaLogger.log("");
chat();
}
};
Expand All @@ -635,36 +677,6 @@ const rl = readline.createInterface({
output: process.stdout,
});

async function handleUserInput(input, agentId) {
if (input.toLowerCase() === "exit") {
gracefulExit();
}

try {
const serverPort = parseInt(settings.SERVER_PORT || "3000");

const response = await fetch(
`http://localhost:${serverPort}/${agentId}/message`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
text: input,
userId: "user",
userName: "User",
}),
}
);

const data = await response.json();
data.forEach((message) =>
elizaLogger.log(`${"Agent"}: ${message.text}`)
);
} catch (error) {
console.error("Error fetching response:", error);
}
}

async function gracefulExit() {
elizaLogger.log("Terminating and cleaning up resources...");
rl.close();
Expand Down
20 changes: 20 additions & 0 deletions packages/plugin-zksync-era/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@ai16z/plugin-zksync-era",
"version": "0.1.4-alpha.3",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",
"dependencies": {
"@ai16z/eliza": "workspace:*",
"@ai16z/plugin-trustdb": "workspace:*",
"tsup": "^8.3.5",
"web3": "^4.15.0",
"web3-plugin-zksync": "^1.0.8"
},
"scripts": {
"build": "tsup --format esm --dts"
},
"peerDependencies": {
"whatwg-url": "7.1.0"
}
}
Loading

0 comments on commit a8aa112

Please sign in to comment.