MCPcopy Create free account
hub / github.com/ForestHubAI/edge-agents / loadValues

Function loadValues

ts/workflow-cli/cli/deploy/index.ts:136–169  ·  view source on GitHub ↗
(source: string)

Source from the content-addressed store, hash-verified

134// Merge a --values file (the base) with explicit flags (which win). Provider
135// keys merge per provider; the scalar flags override only when actually set.
136// An invalid --log-level exits 1 — loud like a bad values file, not silent.
137export function partialFromFlags(flags: RawFlags, fileValues: Partial<DeployConfig>): Partial<DeployConfig> {
138 const llmKeys: Record<string, string> = { ...(fileValues.llmKeys ?? {}), ...flags.llmKeys };
139
140 // Same schema the values file is checked against — one list of valid levels.
141 let flagLogLevel: LogLevel | undefined;
142 if (flags.logLevel !== undefined) {
143 const checked = logLevelSchema.safeParse(flags.logLevel);
144 if (!checked.success) {
145 process.stderr.write(`Invalid --log-level "${flags.logLevel}" — expected ${logLevelSchema.options.join("|")}.\n`);
146 process.exit(1);
147 }
148 flagLogLevel = checked.data;
149 }
150
151 return {
152 ...fileValues,
153 llmKeys,
154 ...(flags.output !== undefined ? { outputDir: flags.output } : {}),
155 ...(flags.force ? { force: true } : {}),
156 ...(flagLogLevel ? { logLevel: flagLogLevel } : {}),
157 };
158}
159
160// Load a --values file: a partial DeployConfig as JSON. Never logged (may carry
161// secrets). Exits 1 on a missing file, malformed JSON, or content that doesn't
162// match valuesFileSchema (wrong types, unknown keys) — listing every problem as
163// a `path: reason` line so a non-interactive caller can fix the file.
164export async function loadValues(source: string): Promise<Partial<DeployConfig>> {
165 const abs = path.resolve(process.cwd(), source);
166 let raw: string;
167 try {
168 raw = await fs.readFile(abs, "utf-8");
169 } catch (err: unknown) {
170 if ((err as NodeJS.ErrnoException).code === "ENOENT") {
171 process.stderr.write(`Values file not found: ${abs}\n`);
172 process.exit(1);

Callers 2

index.test.tsFile · 0.90
deployCommandFunction · 0.85

Calls 1

writeMethod · 0.80

Tested by

no test coverage detected