Files
2026-09-24 10:40:57 +08:00

22 lines
1.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Minimal parameter patches, replayed atomically by the normal model executor."""
import copy
def patched_operations(operations,updates):
if not isinstance(updates,list) or not 1<=len(updates)<=32:
raise ValueError('MODEL_PATCH: 需要1–32项参数修改')
result=copy.deepcopy(operations);by_id={op['id']:op for op in result};seen=set()
for update in updates:
if not isinstance(update,dict) or not {'id'} <= set(update) or set(update)-{'id','params','target'} or not ({'params','target'} & set(update)):
raise ValueError('MODEL_PATCH: 每项包含id及params或target;不能改操作类型或顺序')
op_id=update['id'];params=update.get('params',{})
if not isinstance(op_id,str) or op_id not in by_id or op_id in seen:
raise ValueError('MODEL_PATCH: 操作id不存在或重复')
if not isinstance(params,dict) or ('params' in update and not params):
raise ValueError('MODEL_PATCH: params必须是非空参数对象;执行前由原能力契约核验')
if 'target' in update and update['target'] is not None and not isinstance(update['target'],str):
raise ValueError('MODEL_PATCH: target必须是已有目标id或null')
seen.add(op_id);by_id[op_id]['params'].update(copy.deepcopy(params))
if 'target' in update:by_id[op_id]['target']=update['target']
return result