diff --git a/agent/package.json b/agent/package.json index a09a8ee082..c52b837a8b 100644 --- a/agent/package.json +++ b/agent/package.json @@ -18,6 +18,7 @@ "exec": "node --enable-source-maps --loader ts-node/esm src/index.ts" }, "dependencies": { + "@elizaos/adapter-supabase": "workspace:*", "@elizaos/adapter-postgres": "workspace:*", "@elizaos/adapter-redis": "workspace:*", "@elizaos/adapter-sqlite": "workspace:*", diff --git a/agent/src/index.ts b/agent/src/index.ts index d3f1a0276e..57501c2c13 100644 --- a/agent/src/index.ts +++ b/agent/src/index.ts @@ -2,6 +2,7 @@ import { PGLiteDatabaseAdapter } from "@elizaos/adapter-pglite"; import { PostgresDatabaseAdapter } from "@elizaos/adapter-postgres"; import { RedisClient } from "@elizaos/adapter-redis"; import { SqliteDatabaseAdapter } from "@elizaos/adapter-sqlite"; +import { SupabaseDatabaseAdapter } from "@elizaos/adapter-supabase"; import { AutoClientInterface } from "@elizaos/client-auto"; import { DiscordClientInterface } from "@elizaos/client-discord"; import { FarcasterAgentClient } from "@elizaos/client-farcaster"; @@ -456,7 +457,24 @@ export function getTokenForProvider( } function initializeDatabase(dataDir: string) { - if (process.env.POSTGRES_URL) { + 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() + .then(() => { + elizaLogger.success("Successfully connected to Supabase database"); + }) + .catch((error) => { + elizaLogger.error("Failed to connect to Supabase:", error); + }); + + return db; + } else if (process.env.POSTGRES_URL) { elizaLogger.info("Initializing PostgreSQL connection..."); const db = new PostgresDatabaseAdapter({ connectionString: process.env.POSTGRES_URL, @@ -466,9 +484,7 @@ function initializeDatabase(dataDir: string) { // Test the connection db.init() .then(() => { - elizaLogger.success( - "Successfully connected to PostgreSQL database" - ); + elizaLogger.success("Successfully connected to PostgreSQL database"); }) .catch((error) => { elizaLogger.error("Failed to connect to PostgreSQL:", error); @@ -483,10 +499,19 @@ function initializeDatabase(dataDir: string) { }); return db; } else { - const filePath = - process.env.SQLITE_FILE ?? path.resolve(dataDir, "db.sqlite"); - // ":memory:"; + const filePath = process.env.SQLITE_FILE ?? path.resolve(dataDir, "db.sqlite"); + elizaLogger.info(`Initializing SQLite database at ${filePath}...`); const db = new SqliteDatabaseAdapter(new Database(filePath)); + + // Test the connection + db.init() + .then(() => { + elizaLogger.success("Successfully connected to SQLite database"); + }) + .catch((error) => { + elizaLogger.error("Failed to connect to SQLite:", error); + }); + return db; } }