mirror of
https://github.com/penpot/penpot.git
synced 2026-09-12 15:09:38 +00:00
♻️ Adjust ConfigurationLoader to use markdown file instead of yml
This commit is contained in:
parent
024aedc3ca
commit
71507fb9b7
@ -1,18 +1,7 @@
|
|||||||
import { readFileSync, existsSync } from "fs";
|
import { existsSync, readFileSync } from "fs";
|
||||||
import { join, dirname } from "path";
|
import { join } from "path";
|
||||||
import { fileURLToPath } from "url";
|
|
||||||
import yaml from "js-yaml";
|
|
||||||
import { createLogger } from "./logger.js";
|
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.
|
* Configuration loader for prompts and server settings.
|
||||||
*
|
*
|
||||||
@ -23,7 +12,7 @@ export interface PromptsConfig {
|
|||||||
export class ConfigurationLoader {
|
export class ConfigurationLoader {
|
||||||
private readonly logger = createLogger("ConfigurationLoader");
|
private readonly logger = createLogger("ConfigurationLoader");
|
||||||
private readonly baseDir: string;
|
private readonly baseDir: string;
|
||||||
private promptsConfig: PromptsConfig | null = null;
|
private initialInstructions: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new configuration loader instance.
|
* Creates a new configuration loader instance.
|
||||||
@ -32,34 +21,14 @@ export class ConfigurationLoader {
|
|||||||
*/
|
*/
|
||||||
constructor(baseDir: string) {
|
constructor(baseDir: string) {
|
||||||
this.baseDir = baseDir;
|
this.baseDir = baseDir;
|
||||||
|
this.initialInstructions = this.loadFileContent(join(this.baseDir, "data", "initial_instructions.md"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private loadFileContent(filePath: string): string {
|
||||||
* Loads the prompts configuration from the YAML file.
|
if (!existsSync(filePath)) {
|
||||||
*
|
throw new Error(`Configuration file not found at ${filePath}`);
|
||||||
* 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;
|
|
||||||
}
|
}
|
||||||
|
return readFileSync(filePath, "utf8");
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,18 +37,6 @@ export class ConfigurationLoader {
|
|||||||
* @returns The initial instructions string, or undefined if not configured
|
* @returns The initial instructions string, or undefined if not configured
|
||||||
*/
|
*/
|
||||||
public getInitialInstructions(): string {
|
public getInitialInstructions(): string {
|
||||||
const config = this.getPromptsConfig();
|
return this.initialInstructions;
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user