Initial commit: Discord-Claude Gateway with event-driven agent runtime
This commit is contained in:
66
src/markdown-config-loader.ts
Normal file
66
src/markdown-config-loader.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
export interface MarkdownConfigs {
|
||||
soul: string | null;
|
||||
identity: string | null;
|
||||
agents: string | null;
|
||||
user: string | null;
|
||||
memory: string | null;
|
||||
tools: string | null;
|
||||
}
|
||||
|
||||
const CONFIG_FILES = ["soul.md", "identity.md", "agents.md", "user.md", "memory.md", "tools.md"] as const;
|
||||
|
||||
type ConfigKey = "soul" | "identity" | "agents" | "user" | "memory" | "tools";
|
||||
|
||||
const FILE_TO_KEY: Record<string, ConfigKey> = {
|
||||
"soul.md": "soul",
|
||||
"identity.md": "identity",
|
||||
"agents.md": "agents",
|
||||
"user.md": "user",
|
||||
"memory.md": "memory",
|
||||
"tools.md": "tools",
|
||||
};
|
||||
|
||||
export class MarkdownConfigLoader {
|
||||
async loadAll(configDir: string): Promise<MarkdownConfigs> {
|
||||
const configs: MarkdownConfigs = {
|
||||
soul: null,
|
||||
identity: null,
|
||||
agents: null,
|
||||
user: null,
|
||||
memory: null,
|
||||
tools: null,
|
||||
};
|
||||
|
||||
for (const filename of CONFIG_FILES) {
|
||||
const key = FILE_TO_KEY[filename];
|
||||
const filePath = join(configDir, filename);
|
||||
|
||||
try {
|
||||
const content = await readFile(filePath, "utf-8");
|
||||
configs[key] = content;
|
||||
} catch {
|
||||
if (filename === "memory.md") {
|
||||
const defaultContent = "# Memory\n";
|
||||
await writeFile(filePath, defaultContent, "utf-8");
|
||||
configs[key] = defaultContent;
|
||||
} else {
|
||||
console.warn(`Warning: ${filename} not found in ${configDir}`);
|
||||
configs[key] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return configs;
|
||||
}
|
||||
|
||||
async loadFile(configDir: string, filename: string): Promise<string | null> {
|
||||
try {
|
||||
return await readFile(join(configDir, filename), "utf-8");
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user