defmerge_configs(config:Union[Dict[str,Any],Config],*updates:Union[Dict[str,Any],Config],remove_extra:bool=False,)->Union[Dict[str,Any],Config]:"""Deep merge two configs."""defdeep_set(current,path,val):path=path.split(".")forpartinpath[:-1]:current=current[part]current[path[-1]]=valdefrec(old,new):ifremove_extra:# Filter out values in the original config that are not in defaultskeys=list(new.keys())forkeyinkeys:ifkeynotinold:delnew[key]forkey,new_valinlist(new.items()):if"."inkey:deep_set(old,key,new_val)continueifkeynotinold:old[key]=new_valcontinueold_val=old[key]ifisinstance(old_val,dict)andisinstance(new_val,dict):old_promise=next((kforkinold_valifk.startswith("@")),None)new_promise=next((kforkinnew_valifk.startswith("@")),None)if(new_promiseisnotNoneandold_promise!=new_promiseorold_val.get(old_promise)!=new_val.get(new_promise)):old[key]=new_valelse:rec(old[key],new_val)else:old[key]=new_valreturnoldconfig=deepcopy(config)foruinupdates:u=deepcopy(u)rec(config,u)returnConfig(config)