"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfigService = void 0;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
/**
* Service for managing server configuration
*/
class ConfigService {
/**
* Initialize the configuration service
* @param configPath - Path to the configuration file
*/
constructor(configPath = path_1.default.join(process.cwd(), 'config.json')) {
this.configPath = configPath;
/**
* Default configuration values
*/
this.defaultConfig = {
port: 3000,
contextPath: path_1.default.join(process.cwd(), 'context.json'),
autoInject: true,
triggerKeywords: ['new project', 'build', 'create', 'develop'],
knowledgeGraphReference: true,
knowledgeGraphReferenceText: "Please reference my Knowledge Graph for development frameworks, workflows, and patterns."
};
this.config = this.loadConfig();
}
/**
* Load configuration from file or use defaults
* @returns The loaded configuration
*/
loadConfig() {
try {
if (fs_1.default.existsSync(this.configPath)) {
const fileContent = fs_1.default.readFileSync(this.configPath, 'utf8');
const loadedConfig = JSON.parse(fileContent);
// Merge with default config to ensure all properties exist
return { ...this.defaultConfig, ...loadedConfig };
}
// If file doesn't exist, return default config
return this.defaultConfig;
}
catch (error) {
console.error('Error loading config:', error instanceof Error ? error.message : String(error));
return this.defaultConfig;
}
}
/**
* Get the current configuration
* @returns The current server configuration
*/
getConfig() {
return { ...this.config };
}
/**
* Update the configuration
* @param newConfig - New configuration values
* @returns The updated configuration
*/
updateConfig(newConfig) {
this.config = { ...this.config, ...newConfig };
this.saveConfig();
return { ...this.config };
}
/**
* Save the current configuration to file
*/
saveConfig() {
try {
fs_1.default.writeFileSync(this.configPath, JSON.stringify(this.config, null, 2));
}
catch (error) {
console.error('Error saving config:', error instanceof Error ? error.message : String(error));
}
}
}
exports.ConfigService = ConfigService;
//# sourceMappingURL=config.service.js.map