From ef7bf2cff831440953e0e6c64fa068902c2b48cb Mon Sep 17 00:00:00 2001 From: Vinh Date: Fri, 27 Dec 2024 12:20:09 -0800 Subject: [PATCH] standarize name --- core/taskengine/vm.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/core/taskengine/vm.go b/core/taskengine/vm.go index cb1c07d..ae59c44 100644 --- a/core/taskengine/vm.go +++ b/core/taskengine/vm.go @@ -3,6 +3,7 @@ package taskengine import ( "context" "fmt" + "regexp" "strings" "sync" "time" @@ -98,8 +99,20 @@ func (v *VM) WithLogger(logger sdklogging.Logger) *VM { } func (v *VM) GetNodeNameAsVar(nodeID string) string { + // Replace invalid characters with _ + re := regexp.MustCompile(`[^a-zA-Z0-9_$]`) name := v.TaskNodes[nodeID].Name - return name + if name == "" { + name = nodeID + } + standardized := re.ReplaceAllString(v.TaskNodes[nodeID].Name, "_") + + // Ensure the first character is valid + if len(standardized) == 0 || !regexp.MustCompile(`^[a-zA-Z_$]`).MatchString(standardized[:1]) { + standardized = "_" + standardized + } + + return standardized } func NewVMWithData(taskID string, triggerMetadata *avsproto.TriggerMetadata, nodes []*avsproto.TaskNode, edges []*avsproto.TaskEdge) (*VM, error) {