feat: simplify SOP to immediate-effect configuration

This commit is contained in:
Eric 1549169735@qq.com
2026-08-18 16:27:02 +08:00
parent c5ab886b70
commit 8de48fb05e
150 changed files with 6764 additions and 1626 deletions

View File

@@ -66,7 +66,7 @@ func matchRule(rule map[string]interface{}, answers map[string]interface{}) (boo
if field == "" || operator == "" {
return false, fmt.Errorf("condition field and operator are required")
}
actual, exists := answers[field]
actual, exists := lookupContextValue(answers, field)
expected := rule["value"]
switch operator {
case "exists":
@@ -105,6 +105,35 @@ func matchRule(rule map[string]interface{}, answers map[string]interface{}) (boo
}
}
// lookupContextValue accepts the public namespaced form (input.foo/derived.foo)
// and the legacy bare form used by SOP edge conditions.
func lookupContextValue(values map[string]interface{}, field string) (interface{}, bool) {
if value, ok := values[field]; ok {
return value, true
}
for _, prefix := range []string{"input.", "derived.", "form."} {
if strings.HasPrefix(field, prefix) {
key := strings.TrimPrefix(field, prefix)
if namespace, ok := values[strings.TrimSuffix(prefix, ".")].(map[string]interface{}); ok {
value, exists := namespace[key]
return value, exists
}
value, ok := values[key]
return value, ok
}
}
return nil, false
}
func runtimeContext(input, derived, form map[string]interface{}) map[string]interface{} {
context := mergeValues(input, derived)
context = mergeValues(context, form)
context["input"] = input
context["derived"] = derived
context["form"] = form
return context
}
func normalizeValue(value interface{}) interface{} {
switch typed := value.(type) {
case json.Number: