chore: read agentrun hwlab defaults from yaml
This commit is contained in:
@@ -193,6 +193,10 @@ export function resolveAgentRunLaneTarget(options: { node?: string | null; lane?
|
||||
return { configPath: config.sourcePath, spec };
|
||||
}
|
||||
|
||||
export function agentRunDefaultProviderId(env: NodeJS.ProcessEnv = process.env): string {
|
||||
return resolveAgentRunLaneTarget({}, env).spec.nodeId;
|
||||
}
|
||||
|
||||
export function agentRunLaneSummary(spec: AgentRunLaneSpec): Record<string, unknown> {
|
||||
return {
|
||||
node: {
|
||||
@@ -314,6 +318,7 @@ export function agentRunPipelineRunName(spec: AgentRunLaneSpec, sourceCommit: st
|
||||
function readAgentRunControlPlaneConfig(env: NodeJS.ProcessEnv): AgentRunControlPlaneConfig {
|
||||
const configPath = env.AGENTRUN_CONTROL_PLANE_CONFIG ?? rootPath(AGENTRUN_CONFIG_PATH);
|
||||
const root = asRecord(Bun.YAML.parse(readFileSync(configPath, "utf8")) as unknown, configPath);
|
||||
validateConfigEnvelope(root, configPath);
|
||||
const controlPlane = recordField(root, "controlPlane", configPath);
|
||||
const defaultTarget = recordField(controlPlane, "default", `${configPath}.controlPlane`);
|
||||
const nodes = parseNodes(recordField(controlPlane, "nodes", `${configPath}.controlPlane`), configPath);
|
||||
@@ -329,6 +334,15 @@ function readAgentRunControlPlaneConfig(env: NodeJS.ProcessEnv): AgentRunControl
|
||||
};
|
||||
}
|
||||
|
||||
function validateConfigEnvelope(root: Record<string, unknown>, configPath: string): void {
|
||||
if (root.version !== 1) throw new Error(`${configPath}.version must be 1`);
|
||||
if (root.kind !== "AgentRunConfig") throw new Error(`${configPath}.kind must be AgentRunConfig`);
|
||||
const metadata = recordField(root, "metadata", configPath);
|
||||
if (stringField(metadata, "name", `${configPath}.metadata`) !== "agentrun") {
|
||||
throw new Error(`${configPath}.metadata.name must be agentrun`);
|
||||
}
|
||||
}
|
||||
|
||||
function parseNodes(input: Record<string, unknown>, configPath: string): Record<string, AgentRunNodeSpec> {
|
||||
const result: Record<string, AgentRunNodeSpec> = {};
|
||||
for (const [id, raw] of Object.entries(input)) {
|
||||
|
||||
Reference in New Issue
Block a user