import { defaultSeedAgentConfig } from "./defaults.js";
function isRecord(value) {
    return typeof value === "object" && value !== null && !Array.isArray(value);
}
function mergeValue(base, override) {
    if (override === undefined)
        return base;
    if (Array.isArray(base))
        return (Array.isArray(override) ? override : base);
    if (isRecord(base) && isRecord(override)) {
        const merged = { ...base };
        for (const [key, value] of Object.entries(override)) {
            merged[key] = mergeValue(merged[key], value);
        }
        return merged;
    }
    return override;
}
export function mergeSeedConfig(...overrides) {
    let result = structuredClone(defaultSeedAgentConfig);
    for (const override of overrides) {
        if (!override)
            continue;
        result = mergeValue(result, override);
    }
    return normalizeSeedAgentConfig(result);
}
function normalizeSeedAgentConfig(config) {
    const next = structuredClone(config);
    next.default_run_agent = "lab-representative";
    next.agent_order = ["lab-representative"];
    const labRepresentativeOverride = isRecord(next.agents) ? next.agents["lab-representative"] : undefined;
    next.agents = {
        ...(isRecord(labRepresentativeOverride) ? { "lab-representative": labRepresentativeOverride } : {}),
    };
    return next;
}
//# sourceMappingURL=merge.js.map