♻️ Adjust ConfigurationLoader to use markdown file instead of yml

This commit is contained in:
Dominik Jain
2026-02-09 17:25:21 +01:00
parent 024aedc3ca
commit 71507fb9b7

View File

@@ -1,18 +1,7 @@
import { readFileSync, existsSync } from "fs";
import { join, dirname } from "path";
import { fileURLToPath } from "url";
import yaml from "js-yaml";
import { existsSync, readFileSync } from "fs";
import { join } from "path";
import { createLogger } from "./logger.js";
/**
* Interface defining the structure of the prompts configuration file.
*/
export interface PromptsConfig {
/** Initial instructions displayed when the server starts or connects to a client */
initial_instructions: string;
[key: string]: any; // Allow for future extension with additional prompt types
}
/**
* Configuration loader for prompts and server settings.
*
@@ -23,7 +12,7 @@ export interface PromptsConfig {
export class ConfigurationLoader {
private readonly logger = createLogger("ConfigurationLoader");
private readonly baseDir: string;
private promptsConfig: PromptsConfig | null = null;
private initialInstructions: string;
/**
* Creates a new configuration loader instance.
@@ -32,34 +21,14 @@ export class ConfigurationLoader {
*/
constructor(baseDir: string) {
this.baseDir = baseDir;
this.initialInstructions = this.loadFileContent(join(this.baseDir, "data", "initial_instructions.md"));
}
/**
* Loads the prompts configuration from the YAML file.
*
* Reads and parses the prompts.yml file, providing cached access
* to configuration values on subsequent calls.
*
* @returns The parsed prompts configuration object
*/
public getPromptsConfig(): PromptsConfig {
if (this.promptsConfig !== null) {
return this.promptsConfig;
private loadFileContent(filePath: string): string {
if (!existsSync(filePath)) {
throw new Error(`Configuration file not found at ${filePath}`);
}
const promptsPath = join(this.baseDir, "data", "prompts.yml");
if (!existsSync(promptsPath)) {
throw new Error(`Prompts configuration file not found at ${promptsPath}, using defaults`);
}
const fileContent = readFileSync(promptsPath, "utf8");
const parsedConfig = yaml.load(fileContent) as PromptsConfig;
this.promptsConfig = parsedConfig || {};
this.logger.info(`Loaded prompts configuration from ${promptsPath}`);
return this.promptsConfig;
return readFileSync(filePath, "utf8");
}
/**
@@ -68,18 +37,6 @@ export class ConfigurationLoader {
* @returns The initial instructions string, or undefined if not configured
*/
public getInitialInstructions(): string {
const config = this.getPromptsConfig();
return config.initial_instructions;
}
/**
* Reloads the configuration from disk.
*
* Forces a fresh read of the configuration file on the next access,
* useful for development or when configuration files are updated at runtime.
*/
public reloadConfiguration(): void {
this.promptsConfig = null;
this.logger.info("Configuration cache cleared, will reload on next access");
return this.initialInstructions;
}
}