refactor: 重构工作流执行图构建与节点上下文处理
This commit is contained in:
@@ -583,7 +583,7 @@ func ImgNode(ctx context.Context, nodeInput *flowDto.NodeExecutionInput, skillNa
|
||||
outputRes = append(outputRes, node.NodeFormField{
|
||||
Field: fmt.Sprintf("img_url:%v:%d", k, i),
|
||||
Value: v,
|
||||
Label: fmt.Sprintf("img_url%v:%d", k, i),
|
||||
Label: fmt.Sprintf("图片内容%v:%d", k, i),
|
||||
Type: "string",
|
||||
})
|
||||
}
|
||||
@@ -674,7 +674,7 @@ func AudioOptimizeNode(ctx context.Context, nodeInput *flowDto.NodeExecutionInpu
|
||||
outputRes = append(outputRes, node.NodeFormField{
|
||||
Field: fmt.Sprintf("audio_url:%v:%d", k, i),
|
||||
Value: v,
|
||||
Label: fmt.Sprintf("audio_url:%v:%d", k, i),
|
||||
Label: fmt.Sprintf("音频内容:%v:%d", k, i),
|
||||
Type: "string",
|
||||
})
|
||||
}
|
||||
@@ -939,23 +939,17 @@ func HttpNode(ctx context.Context, nodeInput *flowDto.NodeExecutionInput) ([]nod
|
||||
func BuildParam(nodeInput *flowDto.NodeExecutionInput) (skillName string, resultFrom []map[string]any, resultUserFrom []map[string]any) {
|
||||
inputMap, outputMap, modelMap := GetNodeContextContent(nodeInput.Global, nodeInput.Config)
|
||||
var outputResult []node.NodeFormField
|
||||
for _, valueAny := range inputMap {
|
||||
if field, ok := valueAny.(node.NodeFormField); ok {
|
||||
outputResult = append(outputResult, field)
|
||||
}
|
||||
}
|
||||
outputResult = append(outputResult, inputMap...)
|
||||
|
||||
resultUserFrom = []map[string]any{}
|
||||
for _, valueAny := range outputMap {
|
||||
if field, ok := valueAny.(node.NodeFormField); ok {
|
||||
if !strings.Contains(field.Field, "text_url") && !strings.Contains(field.Field, "img_url") {
|
||||
if strings.Contains(field.Field, "text_content") {
|
||||
field.Value = StripHtmlTags(gconv.String(field.Value))
|
||||
}
|
||||
resultUserFrom = append(resultUserFrom, map[string]any{
|
||||
field.Label: field.Value,
|
||||
})
|
||||
for _, field := range outputMap {
|
||||
if !strings.Contains(field.Field, "text_url") && !strings.Contains(field.Field, "img_url") {
|
||||
if strings.Contains(field.Field, "text_content") {
|
||||
field.Value = StripHtmlTags(gconv.String(field.Value))
|
||||
}
|
||||
resultUserFrom = append(resultUserFrom, map[string]any{
|
||||
field.Label: field.Value,
|
||||
})
|
||||
}
|
||||
}
|
||||
for _, valueAny := range modelMap {
|
||||
@@ -963,18 +957,13 @@ func BuildParam(nodeInput *flowDto.NodeExecutionInput) (skillName string, result
|
||||
outputResult = append(outputResult, field)
|
||||
}
|
||||
}
|
||||
//if !nodeInput.Global.IsDialogue {
|
||||
for _, item := range outputResult {
|
||||
resultUserFrom = append(resultUserFrom, map[string]any{
|
||||
item.Label: item.Value,
|
||||
})
|
||||
if !nodeInput.Global.IsDialogue {
|
||||
for _, item := range outputResult {
|
||||
resultUserFrom = append(resultUserFrom, map[string]any{
|
||||
item.Label: item.Value,
|
||||
})
|
||||
}
|
||||
}
|
||||
for _, item := range nodeInput.Config.FormConfig {
|
||||
resultUserFrom = append(resultUserFrom, map[string]any{
|
||||
item.Label: item.Value,
|
||||
})
|
||||
}
|
||||
//}
|
||||
if !g.IsEmpty(nodeInput.Global.Desc) {
|
||||
resultUserFrom = append(resultUserFrom, map[string]any{
|
||||
"desc": nodeInput.Global.Desc,
|
||||
@@ -998,83 +987,40 @@ func BuildParam(nodeInput *flowDto.NodeExecutionInput) (skillName string, result
|
||||
return skillName, resultFrom, resultUserFrom
|
||||
}
|
||||
|
||||
func GetNodeContextContent(execInput *flowDto.FlowExecutionInput, nodeEntity *entity.FlowNode) (map[string]any, map[string]any, map[string]any) {
|
||||
input := make(map[string]any)
|
||||
output := make(map[string]any)
|
||||
func GetNodeContextContent(execInput *flowDto.FlowExecutionInput, nodeEntity *entity.FlowNode) ([]node.NodeFormField, []node.NodeFormField, map[string]any) {
|
||||
var input []node.NodeFormField
|
||||
var output []node.NodeFormField
|
||||
model := make(map[string]any)
|
||||
// 1. 有引用 → 取引用节点的字段值
|
||||
if len(nodeEntity.InputSource) > 0 {
|
||||
for _, source := range nodeEntity.InputSource {
|
||||
refNodeID := source.NodeId
|
||||
fields := source.Field
|
||||
|
||||
refNode, ok := execInput.ConfigMap[refNodeID]
|
||||
refNode, ok := execInput.ConfigMap[source.NodeId]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
inputMap := buildInputMap(refNode)
|
||||
outputMap := mergeOutput(refNode.OutputResult)
|
||||
modelMap := mergeModel(refNode.ModelConfig)
|
||||
if len(fields) > 0 {
|
||||
if len(source.Field) > 0 {
|
||||
// 取指定字段
|
||||
for _, f := range fields {
|
||||
if v, ok := inputMap[f]; ok {
|
||||
input[f] = v
|
||||
}
|
||||
if v, ok := modelMap[f]; ok {
|
||||
model[f] = v
|
||||
}
|
||||
for k, v := range outputMap {
|
||||
if strings.Contains(k, f) {
|
||||
model[k] = v
|
||||
for _, f := range source.Field {
|
||||
for _, v := range refNode.FormConfig {
|
||||
if strings.Contains(v.Label, f) {
|
||||
input = append(input, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 取全部
|
||||
if refNode.NodeCode != node.NodeTypeHttp {
|
||||
for k, v := range inputMap {
|
||||
input[k] = v
|
||||
for _, v := range refNode.ModelConfig.ModelForm {
|
||||
if g.IsEmpty(v.Value) {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(v.Label, f) {
|
||||
model[f] = v
|
||||
}
|
||||
}
|
||||
for _, v := range refNode.OutputResult {
|
||||
if strings.Contains(v.Label, f) {
|
||||
output = append(output, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
for k, v := range modelMap {
|
||||
model[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return input, output, model
|
||||
}
|
||||
|
||||
// buildInputMap 从 FormConfig 构造输入map
|
||||
func buildInputMap(node *entity.FlowNode) map[string]any {
|
||||
m := make(map[string]any)
|
||||
for _, item := range node.FormConfig {
|
||||
m[item.Label] = item
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// mergeOutput 合并节点输出 []map → 单map
|
||||
func mergeOutput(output []node.NodeFormField) map[string]any {
|
||||
m := make(map[string]any)
|
||||
for _, item := range output {
|
||||
m[item.Label] = item
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// mergeOutput 合并节点输出 []map → 单map
|
||||
func mergeModel(output node.ModelItem) map[string]any {
|
||||
m := make(map[string]any)
|
||||
// 遍历 output.ModelForm 里的每一个 key 和原始值
|
||||
for _, rawValue := range output.ModelForm {
|
||||
if g.IsEmpty(rawValue.Value) {
|
||||
continue
|
||||
}
|
||||
// 包装成 { "value": 原始值 }
|
||||
m[rawValue.Label] = rawValue.Value
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user