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

chore: add conditionals for supabase to agent directory #2032

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
39 changes: 32 additions & 7 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PostgresDatabaseAdapter } from "@elizaos/adapter-postgres";
import { SqliteDatabaseAdapter } from "@elizaos/adapter-sqlite";
import { SupabaseDatabaseAdapter } from "../adapters/supabase";
import { AutoClientInterface } from "@elizaos/client-auto";
import { DiscordClientInterface } from "@elizaos/client-discord";
import { FarcasterAgentClient } from "@elizaos/client-farcaster";
Expand Down Expand Up @@ -357,7 +358,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,
Expand All @@ -367,20 +385,27 @@ 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);
});

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;
}
}
Expand Down
Loading