fix(goal): preserve normalized argument shape
This commit is contained in:
@@ -134,28 +134,12 @@ function resolveConfig(config: Config): ResolvedConfig {
|
|||||||
|
|
||||||
/** Remove only empty provider fillers from fields unused by the selected action. */
|
/** Remove only empty provider fillers from fields unused by the selected action. */
|
||||||
function normalizeUpdateArgs(args: Record<string, unknown>): Record<string, unknown> {
|
function normalizeUpdateArgs(args: Record<string, unknown>): Record<string, unknown> {
|
||||||
const normalized = { ...args }
|
const action = args['action']
|
||||||
const empty = (value: unknown): boolean => value === undefined || value === null || value === '' || value === 0
|
const empty = (value: unknown): boolean => value === undefined || value === null || value === '' || value === 0
|
||||||
const removeEmpty = (key: string): void => {
|
const unused = (key: string): boolean => key === 'blocked_reason'
|
||||||
if (empty(normalized[key])) normalized[key] = undefined
|
? action !== 'blocked'
|
||||||
}
|
: (key === 'objective' || key === 'max_goal_rounds') && action !== 'edit'
|
||||||
switch (normalized['action']) {
|
return Object.fromEntries(Object.entries(args).filter(([key, value]) => !unused(key) || !empty(value)))
|
||||||
case 'edit':
|
|
||||||
removeEmpty('blocked_reason')
|
|
||||||
break
|
|
||||||
case 'blocked':
|
|
||||||
removeEmpty('objective')
|
|
||||||
removeEmpty('max_goal_rounds')
|
|
||||||
break
|
|
||||||
case 'pause':
|
|
||||||
case 'resume':
|
|
||||||
case 'complete':
|
|
||||||
removeEmpty('objective')
|
|
||||||
removeEmpty('max_goal_rounds')
|
|
||||||
removeEmpty('blocked_reason')
|
|
||||||
break
|
|
||||||
}
|
|
||||||
return normalized
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Build the exact compare-and-set ref from model arguments. */
|
/** Build the exact compare-and-set ref from model arguments. */
|
||||||
|
|||||||
Reference in New Issue
Block a user