All files / src config.ts

92.85% Statements 13/14
100% Branches 6/6
100% Functions 1/1
92.85% Lines 13/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 561x 1x                               1x                         1x 4x 4x   4x 2x 2x           4x             4x 3x     4x    
import * as fs from 'fs';
import * as path from 'path';
 
export interface SeraphConfig {
  port: number;
  workers: number;
  apiKey: string | null;
  llm?: {
    provider: 'gemini' | 'anthropic' | 'openai';
    model?: string;
  };
  alertManager?: {
    url: string;
  };
  preFilters?: string[];
}
 
const defaultConfig: SeraphConfig = {
  port: 8080,
  workers: 4,
  apiKey: process.env.SERAPH_API_KEY || null,
  llm: {
    provider: 'gemini',
  },
  alertManager: {
    url: 'http://localhost:9093/api/v2/alerts' // Default for Prometheus Alertmanager
  },
  preFilters: [],
};
 
export function loadConfig(): SeraphConfig {
  const configPath = path.join(process.cwd(), 'seraph.config.json');
  let userConfig: Partial<SeraphConfig> = {};
 
  if (fs.existsSync(configPath)) {
    try {
      userConfig = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
    } catch (error) {
      console.error("Error reading or parsing 'seraph.config.json'.", error);
    }
  }
 
  const config: SeraphConfig = {
    ...defaultConfig,
    ...userConfig,
    llm: { ...defaultConfig.llm, ...userConfig.llm } as SeraphConfig['llm'],
    alertManager: { ...defaultConfig.alertManager, ...userConfig.alertManager } as SeraphConfig['alertManager'],
  };
 
  if (!config.apiKey) {
    config.apiKey = process.env.SERAPH_API_KEY || null;
  }
 
  return config;
}