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 13 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

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

Expand Down Expand Up @@ -130,14 +134,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 @@ -438,12 +451,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 @@ -535,6 +542,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 @@ -593,6 +601,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 @@ -810,14 +819,5 @@ 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/)
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/eliza.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/prettier.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
36 changes: 35 additions & 1 deletion agent/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PGLiteDatabaseAdapter } from "@elizaos/adapter-pglite";
import { MongoClient } from 'mongodb';
import { PostgresDatabaseAdapter } from "@elizaos/adapter-postgres";
import { QdrantDatabaseAdapter } from "@elizaos/adapter-qdrant";
import { RedisClient } from "@elizaos/adapter-redis";
Expand All @@ -11,6 +12,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 @@ -657,7 +660,37 @@ export function getTokenForProvider(
}

function initializeDatabase(dataDir: string) {
if (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 || 'CumulusAiAgent'; // Default database name
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,
Expand Down Expand Up @@ -748,6 +781,7 @@ export async function initializeClients(
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];
27 changes: 27 additions & 0 deletions packages/adapter-mongodb/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@elizaos/adapter-mongodb",
"version": "0.1.0",
"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/node": "^20.10.0",
"@types/uuid": "^10.0.0",
"tsup": "8.3.5",
"typescript": "^5.0.0",
"mongodb": "6.3.0"
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch",
"lint": "eslint --fix --cache ."
},
"engines": {
"node": ">=16.0.0"
}
}
Loading
Loading