Skip to content

Commit

Permalink
fix: char
Browse files Browse the repository at this point in the history
  • Loading branch information
ponderingdemocritus committed Nov 23, 2024
1 parent 986d02e commit 4cfe830
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
11 changes: 9 additions & 2 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import readline from "readline";
import yargs from "yargs";
import path from "path";
import { fileURLToPath } from "url";
import blobert from "./blobert.ts";
import { character } from "./character.ts";
import type { DirectClient } from "@ai16z/client-direct";

const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
Expand Down Expand Up @@ -263,6 +263,13 @@ export function createAgent(
});
}

function intializeFsCache(baseDir: string, character: Character) {
const cacheDir = path.resolve(baseDir, character.id, "cache");

const cache = new CacheManager(new FsCacheAdapter(cacheDir));
return cache;
}

function intializeDbCache(character: Character, db: IDatabaseCacheAdapter) {
const cache = new CacheManager(new DbCacheAdapter(db, character.id));
return cache;
Expand Down Expand Up @@ -310,7 +317,7 @@ const startAgents = async () => {

let charactersArg = args.characters || args.character;

let characters = [blobert];
let characters = [character];

if (charactersArg) {
characters = await loadCharacters(charactersArg);
Expand Down
12 changes: 8 additions & 4 deletions packages/adapter-postgres/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,9 @@ export class PostgresDatabaseAdapter
);

if (existingParticipant.rows.length > 0) {
console.log(`Participant with userId ${userId} already exists in room ${roomId}.`);
console.log(
`Participant with userId ${userId} already exists in room ${roomId}.`
);
return; // Exit early if the participant already exists
}

Expand All @@ -750,11 +752,13 @@ export class PostgresDatabaseAdapter
} catch (error) {
// This is to prevent duplicate participant error in case of a race condition
// Handle unique constraint violation error (code 23505)
if (error.code === '23505') {
console.warn(`Participant with userId ${userId} already exists in room ${roomId}.`); // Optionally, you can log this or handle it differently
if (error.code === "23505") {
console.warn(
`Participant with userId ${userId} already exists in room ${roomId}.`
); // Optionally, you can log this or handle it differently
} else {
// Handle other errors
console.error('Error adding participant:', error);
console.error("Error adding participant:", error);
return false;
}
} finally {
Expand Down

0 comments on commit 4cfe830

Please sign in to comment.