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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | 1x 1x 1x 5x 5x 5x 5x 5x 5x 4x 4x 1x 3x 1x 2x 2x 3x 1x 3x 1x 2x 1x | import { AgentLabConfig } from "./types"; import * as path from "path"; import * as fs from "fs"; /** * Load AgentLab configuration from agentlab.config.js */ export async function loadConfig(configPath?: string): Promise<AgentLabConfig> { const defaultPaths = [ "agentlab.config.js", "agentlab.config.ts", ".agentlab.config.js", ".agentlab.config.ts", ]; let resolvedPath: string | undefined = configPath; Iif (!resolvedPath) { // Find config file in current directory for (const defaultPath of defaultPaths) { const fullPath = path.resolve(process.cwd(), defaultPath); Iif (fs.existsSync(fullPath)) { resolvedPath = fullPath; break; } } } Iif (!resolvedPath) { throw new Error( `AgentLab config file not found. Please create one of: ${defaultPaths.join( ", " )}` ); } try { // Load the config file const config = require(resolvedPath); const loadedConfig = config.default || config; // Validate required fields if (!loadedConfig.agent) { throw new Error('Config must include an "agent" function'); } if (!loadedConfig.llm || !loadedConfig.llm.apiKey) { throw new Error('Config must include "llm.apiKey" for evaluation'); } // Set defaults const finalConfig: AgentLabConfig = { ...loadedConfig, testMatch: loadedConfig.testMatch || ["**/*.test.yaml", "**/*.test.yml"], timeout: loadedConfig.timeout || 30000, llm: { provider: "openai", model: loadedConfig.llm.model || "gpt-4-turbo-preview", temperature: loadedConfig.llm.temperature || 0.3, ...loadedConfig.llm, }, features: { e2eTesting: true, ...loadedConfig.features, }, }; return finalConfig; } catch (error: any) { throw new Error( `Failed to load config from ${resolvedPath}: ${error.message}` ); } } /** * Validate configuration */ export function validateConfig(config: AgentLabConfig): void { if (typeof config.agent !== "function") { throw new Error('Config "agent" must be a function'); } if (!config.llm.apiKey || typeof config.llm.apiKey !== "string") { throw new Error('Config "llm.apiKey" must be a non-empty string'); } } |