diff --git a/pkg/workflow/compiler.go b/pkg/workflow/compiler.go index a520aae497..55e6608e22 100644 --- a/pkg/workflow/compiler.go +++ b/pkg/workflow/compiler.go @@ -1444,8 +1444,7 @@ func (c *Compiler) parseOnSection(frontmatter map[string]any, workflowData *Work if reactionStr, ok := reactionValue.(string); ok { // Validate reaction value if !isValidReaction(reactionStr) { - validValues := []string{"+1", "-1", "laugh", "confused", "heart", "hooray", "rocket", "eyes"} - return fmt.Errorf("invalid reaction value '%s': must be one of %v", reactionStr, validValues) + return fmt.Errorf("invalid reaction value '%s': must be one of %v", reactionStr, getValidReactions()) } workflowData.AIReaction = reactionStr } diff --git a/pkg/workflow/reactions.go b/pkg/workflow/reactions.go index 1f920a879e..87d96f14e3 100644 --- a/pkg/workflow/reactions.go +++ b/pkg/workflow/reactions.go @@ -1,16 +1,27 @@ package workflow +// validReactions defines the set of valid reaction values +var validReactions = map[string]bool{ + "+1": true, + "-1": true, + "laugh": true, + "confused": true, + "heart": true, + "hooray": true, + "rocket": true, + "eyes": true, +} + // isValidReaction checks if a reaction value is valid according to the schema func isValidReaction(reaction string) bool { - validReactions := map[string]bool{ - "+1": true, - "-1": true, - "laugh": true, - "confused": true, - "heart": true, - "hooray": true, - "rocket": true, - "eyes": true, - } return validReactions[reaction] } + +// getValidReactions returns the list of valid reaction entries +func getValidReactions() []string { + reactions := make([]string, 0, len(validReactions)) + for reaction := range validReactions { + reactions = append(reactions, reaction) + } + return reactions +}