Skip to content

Commit

Permalink
refactor: Update package references and integrate Hummingbot plugin
Browse files Browse the repository at this point in the history
- Replace @ai16z/eliza with @elizaos/core
- Add Hummingbot configuration to .env.example
- Integrate Hummingbot plugin into agent/src/index.ts
- Export hummingbotPlugin function
  • Loading branch information
Sumeet Chougule authored and Sumeet Chougule committed Dec 30, 2024
1 parent eeb6893 commit 89ba3bb
Show file tree
Hide file tree
Showing 7 changed files with 416 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,8 @@ CRONOSZKEVM_PRIVATE_KEY=

# Fuel Ecosystem (FuelVM)
FUEL_WALLET_PRIVATE_KEY=

# Hummingbot Configuration
HUMMINGBOT_API_URL= # Hummingbot REST API URL (default: http://localhost:15888)
HUMMINGBOT_WS_URL= # Hummingbot WebSocket URL (default: ws://localhost:8060)
HUMMINGBOT_API_KEY= # Hummingbot API Key
4 changes: 4 additions & 0 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import { zksyncEraPlugin } from "@elizaos/plugin-zksync-era";
import { cronosZkEVMPlugin } from "@elizaos/plugin-cronoszkevm";
import { abstractPlugin } from "@elizaos/plugin-abstract";
import { avalanchePlugin } from "@elizaos/plugin-avalanche";
import { hummingbotPlugin } from "@elizaos/plugin-hummingbot";
import Database from "better-sqlite3";
import fs from "fs";
import path from "path";
Expand Down Expand Up @@ -600,6 +601,9 @@ export async function createAgent(
getSecret(character, "AVALANCHE_PRIVATE_KEY")
? avalanchePlugin
: null,
getSecret(character, "HUMMINGBOT_PRIVATE_KEY")
? hummingbotPlugin
: null,
].filter(Boolean),
providers: [],
actions: [],
Expand Down
99 changes: 99 additions & 0 deletions packages/client-slack/src/slackHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { EventHandler } from './events'; // Import the EventHandler class
import { WebClient } from '@slack/web-api';
import { MessageManager } from './messages';
import { IAgentRuntime } from '@ai16z/eliza';
import { GitHubClientInterface } from '@ai16z/client-github';

// Function to handle Slack events
export async function handleSlackEvents(event: any, runtime: IAgentRuntime) {
// Instantiate the EventHandler with the necessary configuration and client
const slackConfig = {
appId: process.env.SLACK_APP_ID,
clientId: process.env.SLACK_CLIENT_ID,
clientSecret: process.env.SLACK_CLIENT_SECRET,
signingSecret: process.env.SLACK_SIGNING_SECRET,
verificationToken: process.env.SLACK_VERIFICATION_TOKEN,
botToken: process.env.SLACK_BOT_TOKEN,
botId: process.env.SLACK_BOT_ID
};
const slackClient = new WebClient(process.env.SLACK_API_TOKEN);
const messageManager = new MessageManager(slackClient, runtime, slackConfig.botId);

// Create event handler - it will automatically set up event listeners
const eventHandler = new EventHandler(slackConfig, slackClient, messageManager);

// The event handler will process events through its internal listeners
// No need to call handleEvent directly
}

// Function to handle Slack commands
async function handleSlackCommand(event: any, runtime: IAgentRuntime) {
const text = event.text.toLowerCase().trim();

// Check if the user is asking about GitHub
if (text.includes("github")) {
const missingConfigs = [];
if (!runtime.getSetting("GITHUB_OWNER")) missingConfigs.push("GITHUB_OWNER");
if (!runtime.getSetting("GITHUB_REPO")) missingConfigs.push("GITHUB_REPO");
if (!runtime.getSetting("GITHUB_API_TOKEN")) missingConfigs.push("GITHUB_API_TOKEN");

if (missingConfigs.length > 0) {
// Ask the user to provide missing configuration
await runtime.clients.slack.sendMessage(event.channel, `I noticed you're interested in GitHub. The following configurations are missing: ${missingConfigs.join(", ")}. These configurations need to be set in your environment variables or configuration file.`);

// Notify user about how to set up configurations
await runtime.clients.slack.sendMessage(event.channel, "Please set these configurations in your environment variables or configuration file before proceeding.");

// Return early since we can't proceed without configurations
return;
} else {
await runtime.clients.slack.sendMessage(event.channel, "GitHub is already configured.");

// Initialize GitHub client
const githubClient = await GitHubClientInterface.start(runtime);
if (githubClient) {
runtime.clients.github = githubClient;
await runtime.clients.slack.sendMessage(event.channel, "GitHub client configured successfully!");
}
}
} else if (text.startsWith("!github clone")) {
const githubClient = await GitHubClientInterface.start(runtime, true);
await githubClient.initialize();
await runtime.clients.slack.sendMessage(event.channel, "Repository cloned successfully!");
} else if (text.startsWith("!github list repos")) {
// Example command to list repositories
const githubClient = runtime.clients.github;
if (githubClient) {
const repos = await githubClient.listRepositories();
await runtime.clients.slack.sendMessage(event.channel, `Repositories: ${repos.join(", ")}`);
} else {
await runtime.clients.slack.sendMessage(event.channel, "GitHub client is not configured.");
}
}
}

// Function to wait for a response from a specific channel
function createResponsePromise(channel: string, runtime: IAgentRuntime): Promise<string> {
return new Promise((resolve) => {
const messageHandler = (event: any) => {
if (event.channel === channel) {
// Remove the event listener once we get a response
runtime.clients.slack.removeMessageListener(messageHandler);
resolve(event.text);
}
};

// Add the message listener
runtime.clients.slack.addMessageListener(messageHandler);
});
}

async function promptSlackUser(channel: string, prompt: string, runtime: IAgentRuntime): Promise<string> {
// Send a message to the Slack channel
await runtime.clients.slack.sendMessage(channel, prompt);

// Wait for and return the user's response
return await createResponsePromise(channel, runtime);
}

// Ensure this function is called when Slack events are received
4 changes: 2 additions & 2 deletions packages/plugin-hummingbot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"author": "Nethermind",
"license": "MIT",
"dependencies": {
"@ai16z/eliza": "workspace:*",
"@elizaos/core": "workspace:*",
"axios": "^1.6.0",
"ws": "^8.16.0"
},
Expand All @@ -36,6 +36,6 @@
"typescript": "^5.0.0"
},
"peerDependencies": {
"@ai16z/eliza": "*"
"@elizaos/core": "*"
}
}
6 changes: 5 additions & 1 deletion packages/plugin-hummingbot/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IAgentRuntime, Plugin } from '@ai16z/eliza';
import { IAgentRuntime, Plugin } from '@elizaos/core';
import { MarketDataProvider } from './providers/market-data-provider';
import { OrderService } from './providers/order-provider';
import { StrategyService } from './providers/strategy-provider';
Expand Down Expand Up @@ -170,6 +170,10 @@ export class HummingbotPlugin extends Plugin {
}
}

export const hummingbotPlugin = (config: HummingbotConfig): Plugin => {
return new HummingbotPlugin(config);
};

export * from './actions/market-making';
export * from './actions/orders';
export * from './types';
Loading

0 comments on commit 89ba3bb

Please sign in to comment.