local-agent
Version:
A CLI agentic system for orchestrating tools and memory with per-folder scoping
74 lines • 2.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfigService = void 0;
/**
* @fileoverview
* Centralized configuration service for loading and validating config files.
*/
const fs_1 = require("fs");
const types_1 = require("../types");
const errors_1 = require("../errors");
/**
* Service for loading and validating configuration files.
*/
class ConfigService {
/**
* Loads and validates the main agent configuration.
*
* @param filePath Path to the configuration file
* @returns Parsed and validated configuration
* @throws ConfigurationError if file is invalid or missing
*/
static loadConfig(filePath) {
try {
const configData = JSON.parse((0, fs_1.readFileSync)(filePath, 'utf8'));
return types_1.GenerateTextParamsSchema.parse(configData);
}
catch (err) {
if (err instanceof Error && err.message.includes('ENOENT')) {
throw new errors_1.ConfigurationError(`Configuration file not found: ${filePath}`);
}
throw new errors_1.ConfigurationError(`Invalid configuration in ${filePath}: ${err}`);
}
}
/**
* Loads and validates the tools configuration.
*
* @param filePath Path to the tools configuration file
* @returns Parsed and validated tools configuration
* @throws ConfigurationError if file is invalid or missing
*/
static loadTools(filePath) {
try {
const toolsData = JSON.parse((0, fs_1.readFileSync)(filePath, 'utf8'));
return types_1.ToolsJsonSchema.parse(toolsData);
}
catch (err) {
if (err instanceof Error && err.message.includes('ENOENT')) {
throw new errors_1.ConfigurationError(`Tools configuration file not found: ${filePath}`);
}
throw new errors_1.ConfigurationError(`Invalid tools configuration in ${filePath}: ${err}`);
}
}
/**
* Loads and validates the API keys configuration.
*
* @param filePath Path to the keys configuration file
* @returns Parsed and validated keys configuration
* @throws ConfigurationError if file is invalid or missing
*/
static loadKeys(filePath) {
try {
const keysData = JSON.parse((0, fs_1.readFileSync)(filePath, 'utf8'));
return types_1.KeysJsonSchema.parse(keysData);
}
catch (err) {
if (err instanceof Error && err.message.includes('ENOENT')) {
throw new errors_1.ConfigurationError(`Keys configuration file not found: ${filePath}`);
}
throw new errors_1.ConfigurationError(`Invalid keys configuration in ${filePath}: ${err}`);
}
}
}
exports.ConfigService = ConfigService;
//# sourceMappingURL=config-service.js.map