Skip to content

Commit

Permalink
fix ensure dataDir exists
Browse files Browse the repository at this point in the history
  • Loading branch information
bmgalego committed Nov 20, 2024
1 parent bc00ef1 commit bf22b2c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,7 @@ export function createAgent(

function intializeFsCache(baseDir: string, character: Character) {
const cacheDir = path.resolve(baseDir, character.id, "cache");
if (!fs.existsSync(cacheDir)) {
fs.mkdirSync(cacheDir, { recursive: true });
}

const cache = new CacheManager(new FsCacheAdapter(cacheDir));
return cache;
}
Expand All @@ -277,7 +275,12 @@ async function startAgent(character: Character, directClient: DirectClient) {
character.id ??= stringToUuid(character.name);

const token = getTokenForProvider(character.modelProvider, character);
const dataDir = path.join(__dirname, "../../../data");
const dataDir = path.join(__dirname, "../data");

if (!fs.existsSync(dataDir)) {
fs.mkdirSync(dataDir, { recursive: true });
}

const db = initializeDatabase(dataDir);
const cache = intializeDbCache(character, db);
const runtime = createAgent(character, db, cache, token);
Expand All @@ -292,6 +295,7 @@ async function startAgent(character: Character, directClient: DirectClient) {
`Error starting agent for character ${character.name}:`,
error
);
console.error(error);
throw error;
}
}
Expand Down

0 comments on commit bf22b2c

Please sign in to comment.