import type { ClawdbotConfig } from "./config.js"; import type { WhatsAppConfig } from "./types.js"; export type MergeSectionOptions = { unsetOnUndefined?: Array; }; export function mergeConfigSection>( base: T | undefined, patch: Partial, options: MergeSectionOptions = {}, ): T { const next: Record = { ...(base ?? undefined) }; for (const [key, value] of Object.entries(patch) as [keyof T, T[keyof T]][]) { if (value === undefined) { if (options.unsetOnUndefined?.includes(key)) { delete next[key as string]; } continue; } next[key as string] = value as unknown; } return next as T; } export function mergeWhatsAppConfig( cfg: ClawdbotConfig, patch: Partial, options?: MergeSectionOptions, ): ClawdbotConfig { return { ...cfg, whatsapp: mergeConfigSection(cfg.whatsapp, patch, options), }; }