Skip to content

Commit

Permalink
Merge pull request #17 from sqrDAO/feat/bullmq
Browse files Browse the repository at this point in the history
feat: bullmq
  • Loading branch information
peara authored Dec 26, 2024
2 parents 2140024 + e23f5b0 commit 3feae1f
Show file tree
Hide file tree
Showing 17 changed files with 535 additions and 114 deletions.
7 changes: 6 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ STORY_PRIVATE_KEY= # Story private key
STORY_API_BASE_URL= # Story API base URL
STORY_API_KEY= # Story API key
PINATA_JWT= # Pinata JWT for uploading files to IPFS

# Plugin github
POSTGRES_URL=
GITHUB_PATH=
GITHUB_API_TOKEN=
GITHUB_API_TOKEN=

# Plugin bullmq
REDIS_URL=
26 changes: 23 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,28 @@
"request": "launch",
"name": "Launch via pnpm",
"runtimeExecutable": "pnpm",
"runtimeArgs": ["run", "dev"],
"skipFiles": ["<node_internals>/**"]
"runtimeArgs": [
"run",
"dev"
],
"skipFiles": [
"<node_internals>/**"
]
},
{
"type": "node",
"request": "launch",
"name": "Launch via pnpm character",
"runtimeExecutable": "pnpm",
"runtimeArgs": [
"start",
"--character=characters/custom.character.json"
],
"skipFiles": [
"<node_internals>/**"
],
"runtimeVersion": "23.3.0",
"console": "integratedTerminal"
}
]
}
}
123 changes: 62 additions & 61 deletions agent/package.json
Original file line number Diff line number Diff line change
@@ -1,63 +1,64 @@
{
"name": "@ai16z/agent",
"version": "0.1.6",
"main": "src/index.ts",
"type": "module",
"scripts": {
"start": "node --loader ts-node/esm src/index.ts",
"dev": "node --loader ts-node/esm src/index.ts",
"check-types": "tsc --noEmit"
},
"nodemonConfig": {
"watch": [
"src",
"../core/dist"
],
"ext": "ts,json",
"exec": "node --enable-source-maps --loader ts-node/esm src/index.ts"
},
"dependencies": {
"@sqrdao/plugin-github": "workspace:*",
"@ai16z/adapter-postgres": "workspace:*",
"@ai16z/adapter-redis": "workspace:*",
"@ai16z/adapter-sqlite": "workspace:*",
"@ai16z/client-auto": "workspace:*",
"@ai16z/client-direct": "workspace:*",
"@ai16z/client-discord": "workspace:*",
"@ai16z/client-farcaster": "workspace:*",
"@ai16z/client-lens": "workspace:*",
"@ai16z/client-telegram": "workspace:*",
"@ai16z/client-twitter": "workspace:*",
"@ai16z/client-slack": "workspace:*",
"@ai16z/eliza": "workspace:*",
"@ai16z/plugin-0g": "workspace:*",
"@ai16z/plugin-aptos": "workspace:*",
"@ai16z/plugin-bootstrap": "workspace:*",
"@ai16z/plugin-intiface": "workspace:*",
"@ai16z/plugin-coinbase": "workspace:*",
"@ai16z/plugin-conflux": "workspace:*",
"@ai16z/plugin-evm": "workspace:*",
"@ai16z/plugin-flow": "workspace:*",
"@ai16z/plugin-story": "workspace:*",
"@ai16z/plugin-goat": "workspace:*",
"@ai16z/plugin-icp": "workspace:*",
"@ai16z/plugin-image-generation": "workspace:*",
"@ai16z/plugin-nft-generation": "workspace:*",
"@ai16z/plugin-node": "workspace:*",
"@ai16z/plugin-solana": "workspace:*",
"@ai16z/plugin-starknet": "workspace:*",
"@ai16z/plugin-ton": "workspace:*",
"@ai16z/plugin-sui": "workspace:*",
"@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"
},
"devDependencies": {
"ts-node": "10.9.2",
"tsup": "8.3.5"
}
"name": "@ai16z/agent",
"version": "0.1.6",
"main": "src/index.ts",
"type": "module",
"scripts": {
"start": "node --loader ts-node/esm src/index.ts",
"dev": "node --loader ts-node/esm src/index.ts",
"check-types": "tsc --noEmit"
},
"nodemonConfig": {
"watch": [
"src",
"../core/dist"
],
"ext": "ts,json",
"exec": "node --enable-source-maps --loader ts-node/esm src/index.ts"
},
"dependencies": {
"@sqrdao/plugin-github": "workspace:*",
"@sqrdao/plugin-bullmq": "workspace:*",
"@ai16z/adapter-postgres": "workspace:*",
"@ai16z/adapter-redis": "workspace:*",
"@ai16z/adapter-sqlite": "workspace:*",
"@ai16z/client-auto": "workspace:*",
"@ai16z/client-direct": "workspace:*",
"@ai16z/client-discord": "workspace:*",
"@ai16z/client-farcaster": "workspace:*",
"@ai16z/client-lens": "workspace:*",
"@ai16z/client-telegram": "workspace:*",
"@ai16z/client-twitter": "workspace:*",
"@ai16z/client-slack": "workspace:*",
"@ai16z/eliza": "workspace:*",
"@ai16z/plugin-0g": "workspace:*",
"@ai16z/plugin-aptos": "workspace:*",
"@ai16z/plugin-bootstrap": "workspace:*",
"@ai16z/plugin-intiface": "workspace:*",
"@ai16z/plugin-coinbase": "workspace:*",
"@ai16z/plugin-conflux": "workspace:*",
"@ai16z/plugin-evm": "workspace:*",
"@ai16z/plugin-flow": "workspace:*",
"@ai16z/plugin-story": "workspace:*",
"@ai16z/plugin-goat": "workspace:*",
"@ai16z/plugin-icp": "workspace:*",
"@ai16z/plugin-image-generation": "workspace:*",
"@ai16z/plugin-nft-generation": "workspace:*",
"@ai16z/plugin-node": "workspace:*",
"@ai16z/plugin-solana": "workspace:*",
"@ai16z/plugin-starknet": "workspace:*",
"@ai16z/plugin-ton": "workspace:*",
"@ai16z/plugin-sui": "workspace:*",
"@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"
},
"devDependencies": {
"ts-node": "10.9.2",
"tsup": "8.3.5"
}
}
2 changes: 2 additions & 0 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { TEEMode, teePlugin } from "@ai16z/plugin-tee";
import { tonPlugin } from "@ai16z/plugin-ton";
import { zksyncEraPlugin } from "@ai16z/plugin-zksync-era";
import { githubPlugin } from "@sqrdao/plugin-github";
import { BullMQPlugin } from "@sqrdao/plugin-bullmq";

import Database from "better-sqlite3";
import fs from "fs";
Expand Down Expand Up @@ -570,6 +571,7 @@ export async function createAgent(
getSecret(character, "SUI_PRIVATE_KEY") ? suiPlugin : null,
getSecret(character, "STORY_PRIVATE_KEY") ? storyPlugin : null,
githubPlugin,
BullMQPlugin,
].filter(Boolean),
providers: [],
actions: [],
Expand Down
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@types/uuid": "10.0.0",
"ai": "3.4.33",
"anthropic-vertex-ai": "1.0.2",
"bullmq": "^5.34.4",
"fastembed": "1.14.1",
"fastestsmallesttextencoderdecoder": "1.0.22",
"gaxios": "6.7.1",
Expand Down
13 changes: 12 additions & 1 deletion packages/core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Readable } from "stream";

import { Job, JobsOptions, QueueOptions } from "bullmq";
/**
* Represents a UUID string in the format "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
*/
Expand Down Expand Up @@ -1191,6 +1191,16 @@ export interface IAwsS3Service extends Service {
generateSignedUrl(fileName: string, expiresIn: number): Promise<string>;
}

export interface IBullMQService extends Service {
createQueue(queueName: string): Promise<void>;
createJob(
queueName: string,
jobName: string,
data: any,
opts: JobsOptions
): Promise<Job>;
getQueueOptions(): QueueOptions;
}
export type SearchResult = {
title: string;
url: string;
Expand Down Expand Up @@ -1220,6 +1230,7 @@ export enum ServiceType {
AWS_S3 = "aws_s3",
BUTTPLUG = "buttplug",
SLACK = "slack",
BULL_MQ = "bull_mq",
}

export enum LoggingLevel {
Expand Down
7 changes: 7 additions & 0 deletions packages/plugin-bullmq/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*

!dist/**
!package.json
!readme.md
!tsup.config.ts
!tsconfig.json
3 changes: 3 additions & 0 deletions packages/plugin-bullmq/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import eslintGlobalConfig from "../../eslint.global.mjs";

export default [...eslintGlobalConfig];
25 changes: 25 additions & 0 deletions packages/plugin-bullmq/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@sqrdao/plugin-bullmq",
"version": "0.0.1",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",
"dependencies": {
"@ai16z/eliza": "workspace:^",
"bullmq": "^5.34.4",
"pg": "8.13.1",
"tsup": "^8.3.5"
},
"devDependencies": {
"eslint": "9.13.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.2.1",
"eslint-plugin-vitest": "0.5.4",
"typescript": "^5.7.2"
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --watch",
"lint": "eslint . --fix"
}
}
63 changes: 63 additions & 0 deletions packages/plugin-bullmq/src/actions/ggSchedule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import {
Action,
elizaLogger,
HandlerCallback,
IAgentRuntime,
IBullMQService,
Memory,
State,
} from "@ai16z/eliza";
import { Job, Worker } from "bullmq";
import { BullService } from "../services/bullmq";

const worker = new Worker(
"gg_schedule",
async (job: Job) => {
await job.updateProgress(0);
await job.updateProgress(100);
},
BullService.getInstance<IBullMQService>().getQueueOptions()
);

worker.on("progress", (job: Job, progress: number) => {
elizaLogger.log(`Job ${job.id} is ${progress}% done`);
});

export const ggScheduleAction: Action = {
name: "GG_SCHEDULE",
similes: ["schedule", "plan", "book"],
description: "Schedule a meeting or event",
validate: async (runtime: IAgentRuntime, _message: Memory) => {
return true;
},
handler: async (
runtime: IAgentRuntime,
message: Memory,
_state: State,
_options: any,
callback: HandlerCallback
) => {
try {
const bullService = runtime.getService<IBullMQService>(
BullService.serviceType
);
if (!bullService) {
throw new Error("BullMQ service not found");
}
await bullService.createQueue("gg_schedule");
await bullService.createJob("gg_schedule", "gg_schedule", {}, {});
await (BullService.getInstance() as BullService).createQueue(
"gg_schedule"
);
callback({
text: "Meeting scheduled successfully",
});
} catch (error) {
elizaLogger.error("Error scheduling meeting", error);
callback({
text: "Error scheduling meeting" + error,
});
}
},
examples: [],
};
11 changes: 11 additions & 0 deletions packages/plugin-bullmq/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { BullService } from "./services/bullmq";
import { Plugin } from "@ai16z/eliza";
import { ggScheduleAction } from "./actions/ggSchedule";
export { BullService };

export const BullMQPlugin: Plugin = {
name: "bullmqPlugin",
description: "BullMQ plugin",
actions: [ggScheduleAction],
services: [new BullService()],
};
Loading

0 comments on commit 3feae1f

Please sign in to comment.