Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(new-adapter): mongo-db adaptor #1427

Merged
merged 16 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ VITE_SERVER_PORT=${SERVER_PORT}
SUPABASE_URL=
SUPABASE_ANON_KEY=

# MongoDB
MONGODB_CONNECTION_STRING= #mongodb connection string
MONGODB_DATABASE= #name of the database in mongoDB atlas #default: 'elizaAgent'

# Comma separated list of remote character urls (optional)
REMOTE_CHARACTER_URLS=

Expand Down Expand Up @@ -134,14 +138,23 @@ ETERNALAI_AGENT_ID= # Ex: 1711
ETERNALAI_API_KEY=
ETERNALAI_LOG=false #Default: false

# Hyperbolic Configuration
# Hyperbolic Provider Configuration
HYPERBOLIC_API_KEY= # Hyperbolic API Key
HYPERBOLIC_MODEL=

IMAGE_HYPERBOLIC_MODEL= # Default: FLUX.1-dev
SMALL_HYPERBOLIC_MODEL= # Default: meta-llama/Llama-3.2-3B-Instruct
MEDIUM_HYPERBOLIC_MODEL= # Default: meta-llama/Meta-Llama-3.1-70B-Instruct
LARGE_HYPERBOLIC_MODEL= # Default: meta-llama/Meta-Llama-3.1-405-Instruct


# Hyperbolic Plugin Configuration
HYPERBOLIC_ENV=production
HYPERBOLIC_API_KEY=
HYPERBOLIC_GRANULAR_LOG=true
HYPERBOLIC_SPASH=true
HYPERBOLIC_LOG_LEVEL=debug

# Infera Configuration
INFERA_API_KEY= # visit api.infera.org/docs to obtain an API key under /signup_user
INFERA_MODEL= # Default: llama3.2:latest
Expand Down Expand Up @@ -453,12 +466,6 @@ VLOG= # true/false; if you want to use TEE Verifiable Log, set this to "true"
# Galadriel Configuration
GALADRIEL_API_KEY=gal-* # Get from https://dashboard.galadriel.com/

# Venice Configuration
VENICE_API_KEY= # generate from venice settings
SMALL_VENICE_MODEL= # Default: llama-3.3-70b
MEDIUM_VENICE_MODEL= # Default: llama-3.3-70b
LARGE_VENICE_MODEL= # Default: llama-3.1-405b
IMAGE_VENICE_MODEL= # Default: fluently-xl

# Akash Chat API Configuration docs: https://chatapi.akash.network/documentation
AKASH_CHAT_API_KEY= # Get from https://chatapi.akash.network/
Expand Down Expand Up @@ -555,6 +562,7 @@ COSMOS_AVAILABLE_CHAINS= # mantrachaintestnet2,cosmos # Array of chains
CRONOSZKEVM_ADDRESS=
CRONOSZKEVM_PRIVATE_KEY=


# Fuel Ecosystem (FuelVM)
FUEL_WALLET_PRIVATE_KEY=

Expand Down Expand Up @@ -613,6 +621,7 @@ ECHOCHAMBERS_QUIET_PERIOD=900 # 15 minutes - waits for 15 minutes of silence
ALLORA_API_KEY= # Allora API key, format: UP-f8db7d6558ab432ca0d92716
ALLORA_CHAIN_SLUG= # must be one of mainnet, testnet. If not specified, it will use testnet by default


# B2 Network
B2_PRIVATE_KEY= # Private key of the B2 Network account to use for the agent

Expand Down Expand Up @@ -834,15 +843,6 @@ SUNO_API_KEY=
# Udio AI Music Generation
UDIO_AUTH_TOKEN=

# ####################################
# #### Hyperbolic Configuration ####
# ####################################
HYPERBOLIC_ENV=production
HYPERBOLIC_API_KEY=
HYPERBOLIC_GRANULAR_LOG=true
HYPERBOLIC_SPASH=true
HYPERBOLIC_LOG_LEVEL=debug

# Football Plugin Configuration
FOOTBALL_API_KEY= # API key from Football-Data.org (https://www.football-data.org/)

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ packages/plugin-buttplug/intiface-engine
node-compile-cache

.idea
.vscode
.zed
.DS_Store

dist/
Expand Down
3 changes: 0 additions & 3 deletions .turbo/config.json

This file was deleted.

16 changes: 0 additions & 16 deletions .vscode/launch.json

This file was deleted.

58 changes: 0 additions & 58 deletions .vscode/settings.json

This file was deleted.

14 changes: 0 additions & 14 deletions .vscode/tasks.json

This file was deleted.

1 change: 1 addition & 0 deletions agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@elizaos/adapter-sqlite": "workspace:*",
"@elizaos/adapter-pglite": "workspace:*",
"@elizaos/adapter-qdrant": "workspace:*",
"@elizaos/adapter-mongodb": "workspace:*",
"@elizaos/client-auto": "workspace:*",
"@elizaos/client-direct": "workspace:*",
"@elizaos/client-discord": "workspace:*",
Expand Down
43 changes: 40 additions & 3 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { LensAgentClient } from "@elizaos/client-lens"
import { SlackClientInterface } from "@elizaos/client-slack"
import { TelegramClientInterface } from "@elizaos/client-telegram"
import { TwitterClientInterface } from "@elizaos/client-twitter"
import { MongoDBDatabaseAdapter } from "@elizaos/adapter-mongodb"

import { FarcasterClientInterface } from "@elizaos/client-farcaster"
import { OmniflixPlugin } from "@elizaos/plugin-omniflix"
import { JeeterClientInterface } from "@elizaos/client-simsai"
Expand Down Expand Up @@ -137,6 +139,7 @@ import { zerionPlugin } from "@elizaos/plugin-zerion"
import { minaPlugin } from "@elizaos/plugin-mina"
import { ankrPlugin } from "@elizaos/plugin-ankr";
import { formPlugin } from "@elizaos/plugin-form";
import { MongoClient } from "mongodb";

const __filename = fileURLToPath(import.meta.url) // get the resolved path to the file
const __dirname = path.dirname(__filename) // get the name of the directory
Expand Down Expand Up @@ -510,9 +513,42 @@ export function getTokenForProvider(provider: ModelProviderName, character: Char
}

function initializeDatabase(dataDir: string) {
if (process.env.SUPABASE_URL && process.env.SUPABASE_ANON_KEY) {
elizaLogger.info("Initializing Supabase connection...")
const db = new SupabaseDatabaseAdapter(process.env.SUPABASE_URL, process.env.SUPABASE_ANON_KEY)
if (process.env.MONGODB_CONNECTION_STRING) {
elizaLogger.log("Initializing database on MongoDB Atlas");
const client = new MongoClient(process.env.MONGODB_CONNECTION_STRING, {
wtfsayo marked this conversation as resolved.
Show resolved Hide resolved
maxPoolSize: 100,
minPoolSize: 5,
maxIdleTimeMS: 60000,
connectTimeoutMS: 10000,
serverSelectionTimeoutMS: 5000,
socketTimeoutMS: 45000,
compressors: ['zlib'],
retryWrites: true,
retryReads: true
});

const dbName = process.env.MONGODB_DATABASE || 'elizaAgent';
const db = new MongoDBDatabaseAdapter(client, dbName);

// Test the connection
db.init()
.then(() => {
elizaLogger.success(
"Successfully connected to MongoDB Atlas"
);
})
.catch((error) => {
elizaLogger.error("Failed to connect to MongoDB Atlas:", error);
throw error; // Re-throw to handle it in the calling code
});

return db;
} else if (process.env.SUPABASE_URL && process.env.SUPABASE_ANON_KEY) {
elizaLogger.info("Initializing Supabase connection...");
const db = new SupabaseDatabaseAdapter(
process.env.SUPABASE_URL,
process.env.SUPABASE_ANON_KEY,
);

// Test the connection
db.init()
Expand Down Expand Up @@ -579,6 +615,7 @@ export async function initializeClients(character: Character, runtime: IAgentRun
const clientTypes: string[] = character.clients?.map((str) => str.toLowerCase()) || []
elizaLogger.log("initializeClients", clientTypes, "for", character.name)


// Start Auto Client if "auto" detected as a configured client
if (clientTypes.includes(Clients.AUTO)) {
const autoClient = await AutoClientInterface.start(runtime)
Expand Down
6 changes: 6 additions & 0 deletions packages/adapter-mongodb/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*

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

export default [...eslintGlobalConfig];
37 changes: 37 additions & 0 deletions packages/adapter-mongodb/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "@elizaos/adapter-mongodb",
"version": "0.0.1",
"description": "MongoDB adapter for ElizaOS",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",
"dependencies": {
"@elizaos/core": "workspace:*",
"mongodb": "^6.3.0",
"uuid": "^9.0.1"
},
"devDependencies": {
"@types/jest": "^29.5.11",
"@types/node": "^20.11.5",
"@types/uuid": "^9.0.7",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"tsup": "^8.0.1",
"typescript": "^5.3.3"
},
"scripts": {
"build": "tsup",
"dev": "tsup --format esm --dts --watch",
"lint": "eslint --fix --cache .",
"test": "cd src/__tests__ && ./run_tests.sh",
"test:watch": "jest --watch"
},
"engines": {
"node": ">=16.0.0"
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"testMatch": ["<rootDir>/src/__tests__/**/*.test.ts"]
}
}
16 changes: 16 additions & 0 deletions packages/adapter-mongodb/src/__tests__/docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json
version: '3.8'
services:
mongodb-test:
image: mongo:latest
environment:
MONGO_INITDB_ROOT_USERNAME: mongodb
MONGO_INITDB_ROOT_PASSWORD: mongodb
MONGO_INITDB_DATABASE: eliza_test
ports:
- "27018:27017"
wtfsayo marked this conversation as resolved.
Show resolved Hide resolved
healthcheck:
test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
interval: 5s
timeout: 5s
retries: 5
Loading
Loading