MCPcopy Create free account
hub / github.com/agenticsorg/edge-agents / getConfigValue

Function getConfigValue

scripts/sparc2/src/cli/cli.ts:347–384  ·  view source on GitHub ↗

* Get configuration value * @param key Configuration key * @returns Configuration value

(key: string)

Source from the content-addressed store, hash-verified

345 * @returns Configuration value
346 */
347async function getConfigValue(key: string): Promise<any> {
348 const configPath = Deno.env.get("SPARC2_CONFIG_PATH") || "config/sparc2-config.toml";
349
350 try {
351 // Check if config file exists
352 try {
353 await Deno.stat(configPath);
354 } catch {
355 // Config file doesn't exist, create it
356 await Deno.writeTextFile(configPath, "# SPARC2 Configuration\n");
357 return undefined;
358 }
359
360 // Read config file
361 const configContent = await Deno.readTextFile(configPath);
362
363 // Parse TOML
364 const config = parse(configContent);
365
366 // Handle nested keys (e.g., "agent.name")
367 const keys = key.split(".");
368 let value: any = config;
369
370 for (const k of keys) {
371 if (value === undefined || value === null) {
372 return undefined;
373 }
374
375 value = value[k];
376 }
377
378 return value;
379 } catch (error: unknown) {
380 const errorMessage = error instanceof Error ? error.message : String(error);
381 console.error(`Error reading configuration: ${errorMessage}`);
382 return undefined;
383 }
384}
385
386/**
387 * Set configuration value

Callers 1

configCommandFunction · 0.85

Calls 1

getMethod · 0.65

Tested by

no test coverage detected