Skip to content

Commit 84a8a39

Browse files
committed
feat: add Rabbi Trader plugin integration to AutoClient and agent
1 parent 0a2f67c commit 84a8a39

File tree

4 files changed

+107
-12
lines changed

4 files changed

+107
-12
lines changed

agent/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"@elizaos/plugin-gitbook": "workspace:*",
5151
"@elizaos/plugin-story": "workspace:*",
5252
"@elizaos/plugin-goat": "workspace:*",
53+
"@elizaos/plugin-rabbi-trader": "workspace:*",
5354
"@elizaos/plugin-lensNetwork": "workspace:*",
5455
"@elizaos/plugin-icp": "workspace:*",
5556
"@elizaos/plugin-image-generation": "workspace:*",

agent/src/index.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import {
3535
validateCharacterConfig,
3636
} from "@elizaos/core";
3737
// import { zgPlugin } from "@elizaos/plugin-0g";
38-
3938
import { bootstrapPlugin } from "@elizaos/plugin-bootstrap";
4039
import createGoatPlugin from "@elizaos/plugin-goat";
4140
// import { intifacePlugin } from "@elizaos/plugin-intiface";
@@ -94,6 +93,7 @@ import { akashPlugin } from "@elizaos/plugin-akash";
9493
import { OpacityAdapter } from "@elizaos/plugin-opacity";
9594
import { openWeatherPlugin } from "@elizaos/plugin-open-weather";
9695
import { quaiPlugin } from "@elizaos/plugin-quai";
96+
import createRabbiTraderPlugin from "@elizaos/plugin-rabbi-trader";
9797
import { stargazePlugin } from "@elizaos/plugin-stargaze";
9898
import Database from "better-sqlite3";
9999
import fs from "fs";
@@ -669,12 +669,33 @@ export async function createAgent(
669669
}
670670

671671
let goatPlugin: any | undefined;
672+
let rabbiPlugin: any | undefined;
672673

673674
if (getSecret(character, "EVM_PRIVATE_KEY")) {
674675
goatPlugin = await createGoatPlugin((secret) =>
675676
getSecret(character, secret)
676677
);
677678
}
679+
if (getSecret(character, "SOLANA_PRIVATE_KEY")) {
680+
const runtime = new AgentRuntime({
681+
databaseAdapter: db,
682+
token,
683+
modelProvider: character.modelProvider,
684+
evaluators: [],
685+
character,
686+
plugins: [],
687+
providers: [],
688+
actions: [],
689+
services: [],
690+
managers: [],
691+
cacheManager: cache,
692+
fetch: logFetch,
693+
});
694+
rabbiPlugin = await createRabbiTraderPlugin(
695+
(secret) => getSecret(character, secret),
696+
runtime
697+
);
698+
}
678699

679700
// Initialize Reclaim adapter if environment variables are present
680701
// let verifiableInferenceAdapter;
@@ -812,6 +833,7 @@ export async function createAgent(
812833
? webhookPlugin
813834
: null,
814835
goatPlugin,
836+
rabbiPlugin,
815837
getSecret(character, "COINGECKO_API_KEY") ||
816838
getSecret(character, "COINGECKO_PRO_API_KEY")
817839
? coingeckoPlugin

packages/client-auto/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
],
2121
"dependencies": {
2222
"@elizaos/core": "workspace:*",
23+
"@elizaos/plugin-rabbi-trader": "workspace:*",
2324
"@types/body-parser": "1.19.5",
2425
"@types/cors": "2.8.17",
2526
"@types/express": "5.0.0",

packages/client-auto/src/index.ts

+82-11
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,100 @@
11
import { Client, IAgentRuntime, elizaLogger } from "@elizaos/core";
2+
import createRabbiTraderPlugin from "@elizaos/plugin-rabbi-trader";
23

34
export class AutoClient {
4-
interval: NodeJS.Timeout;
5-
runtime: IAgentRuntime;
5+
private interval: NodeJS.Timeout | null = null;
6+
private runtime: IAgentRuntime;
7+
private plugin: any;
8+
static readonly CLIENT_NAME = "auto";
69

710
constructor(runtime: IAgentRuntime) {
11+
elizaLogger.log("AutoClient constructor called");
812
this.runtime = runtime;
13+
this.initialize();
14+
}
15+
16+
private async initialize() {
17+
try {
18+
elizaLogger.log("AutoClient initialization started");
19+
await this.initializePlugin();
20+
elizaLogger.log("AutoClient initialization completed");
21+
} catch (error) {
22+
elizaLogger.error("AutoClient initialization failed:", error);
23+
throw error;
24+
}
25+
}
26+
27+
private async initializePlugin() {
28+
try {
29+
elizaLogger.log(
30+
"Initializing Rabbi Trader plugin in AutoClient..."
31+
);
32+
33+
this.plugin = await createRabbiTraderPlugin(
34+
(key: string) => this.runtime.getSetting(key),
35+
this.runtime
36+
);
37+
38+
elizaLogger.log("Plugin created, initializing...");
39+
await this.plugin.initialize(this.runtime);
40+
41+
elizaLogger.log("Plugin initialized, starting...");
42+
await this.plugin.start();
43+
44+
if (this.plugin.onStart) {
45+
elizaLogger.log("Triggering plugin onStart...");
46+
await this.plugin.onStart();
47+
}
48+
49+
elizaLogger.log(
50+
"Rabbi Trader plugin fully initialized and started in AutoClient"
51+
);
52+
} catch (error) {
53+
elizaLogger.error(
54+
"Failed to initialize Rabbi Trader plugin in AutoClient:",
55+
{
56+
error,
57+
phase: "initialization",
58+
pluginState: this.plugin ? "created" : "null",
59+
}
60+
);
61+
throw error;
62+
}
63+
}
64+
65+
public async stop() {
66+
elizaLogger.log("Stopping AutoClient...");
67+
try {
68+
if (this.interval) {
69+
clearInterval(this.interval);
70+
this.interval = null;
71+
}
72+
73+
if (this.plugin?.cleanup) {
74+
await this.plugin.cleanup();
75+
}
976

10-
// start a loop that runs every x seconds
11-
this.interval = setInterval(
12-
async () => {
13-
elizaLogger.log("running auto client...");
14-
},
15-
60 * 60 * 1000
16-
); // 1 hour in milliseconds
77+
elizaLogger.log("AutoClient stopped successfully");
78+
} catch (error) {
79+
elizaLogger.error("Error stopping AutoClient:", error);
80+
throw error;
81+
}
1782
}
1883
}
1984

2085
export const AutoClientInterface: Client = {
2186
start: async (runtime: IAgentRuntime) => {
87+
elizaLogger.log("Starting AutoClient interface...");
2288
const client = new AutoClient(runtime);
2389
return client;
2490
},
25-
stop: async (_runtime: IAgentRuntime) => {
26-
console.warn("Direct client does not support stopping yet");
91+
stop: async (runtime: IAgentRuntime) => {
92+
elizaLogger.log("Stopping AutoClient interface...");
93+
const clients = (runtime as any).clients || {};
94+
const client = clients["auto"] as AutoClient;
95+
if (client) {
96+
await client.stop();
97+
}
2798
},
2899
};
29100

0 commit comments

Comments
 (0)