()
| 50 | * @returns Full configuration object |
| 51 | */ |
| 52 | export function loadConfig(): Config { |
| 53 | if (cachedConfig) { |
| 54 | return cachedConfig; |
| 55 | } |
| 56 | |
| 57 | if (!existsSync(CONFIG_FILE)) { |
| 58 | throw new Error(`Configuration file not found at: ${CONFIG_FILE}\n` + `Please create the configuration file.`); |
| 59 | } |
| 60 | |
| 61 | try { |
| 62 | const fileContent = readFileSync(CONFIG_FILE, 'utf8'); |
| 63 | const rawConfig = yaml.load(fileContent) as Config; |
| 64 | |
| 65 | if (!rawConfig) { |
| 66 | throw new Error('Invalid config.yaml structure: configuration is empty'); |
| 67 | } |
| 68 | |
| 69 | cachedConfig = rawConfig; |
| 70 | return cachedConfig; |
| 71 | } catch (error) { |
| 72 | if (error instanceof Error) { |
| 73 | throw new Error(`Failed to load config.yaml: ${error.message}`); |
| 74 | } |
| 75 | throw error; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Get model configuration from config.yaml |
no outgoing calls
no test coverage detected