feat(workflow): enable front-end to cover pre-rendered non-variable values

This commit is contained in:
mengyonghao
2026-01-05 11:00:50 +08:00
parent b56994b999
commit 1f6835a8e0
2 changed files with 13 additions and 10 deletions

View File

@@ -1,3 +1,5 @@
from typing import Any
from pydantic import Field, BaseModel from pydantic import Field, BaseModel
from app.core.workflow.nodes.base_config import BaseNodeConfig from app.core.workflow.nodes.base_config import BaseNodeConfig
@@ -19,7 +21,7 @@ class AssignmentItem(BaseModel):
description="Assignment operator", description="Assignment operator",
) )
value: str | list[str] = Field( value: Any = Field(
..., ...,
description="Value(s) to assign to the variable(s)", description="Value(s) to assign to the variable(s)",
) )

View File

@@ -2,7 +2,6 @@ import logging
import re import re
from typing import Any from typing import Any
from app.core.workflow.expression_evaluator import ExpressionEvaluator
from app.core.workflow.nodes.assigner.config import AssignerNodeConfig from app.core.workflow.nodes.assigner.config import AssignerNodeConfig
from app.core.workflow.nodes.base_node import BaseNode, WorkflowState from app.core.workflow.nodes.base_node import BaseNode, WorkflowState
from app.core.workflow.nodes.enums import AssignmentOperator from app.core.workflow.nodes.enums import AssignmentOperator
@@ -29,6 +28,7 @@ class AssignerNode(BaseNode):
None or the result of the assignment operation. None or the result of the assignment operation.
""" """
# Initialize a variable pool for accessing conversation, node, and system variables # Initialize a variable pool for accessing conversation, node, and system variables
logger.info(f"节点 {self.node_id} 开始执行")
pool = VariablePool(state) pool = VariablePool(state)
for assignment in self.typed_config.assignments: for assignment in self.typed_config.assignments:
# Get the target variable selector (e.g., "conv.test") # Get the target variable selector (e.g., "conv.test")
@@ -45,14 +45,13 @@ class AssignerNode(BaseNode):
# Get the value or expression to assign # Get the value or expression to assign
value = assignment.value value = assignment.value
if isinstance(value, list): pattern = r"\{\{\s*(.*?)\s*\}\}"
value = '.'.join(value) if isinstance(value, str):
value = ExpressionEvaluator.evaluate( expression = re.match(pattern, value)
expression=value, if expression:
variables=pool.get_all_conversation_vars(), expression = expression.group(1)
node_outputs=pool.get_all_node_outputs(), expression = re.sub(pattern, r"\1", expression).strip()
system_vars=pool.get_all_system_vars(), value = self.get_variable(expression, state)
)
# Select the appropriate assignment operator instance based on the target variable type # Select the appropriate assignment operator instance based on the target variable type
operator: AssignmentOperatorInstance = AssignmentOperatorResolver.resolve_by_value( operator: AssignmentOperatorInstance = AssignmentOperatorResolver.resolve_by_value(
@@ -63,6 +62,8 @@ class AssignerNode(BaseNode):
# Execute the configured assignment operation # Execute the configured assignment operation
match assignment.operation: match assignment.operation:
case AssignmentOperator.COVER:
operator.assign()
case AssignmentOperator.ASSIGN: case AssignmentOperator.ASSIGN:
operator.assign() operator.assign()
case AssignmentOperator.CLEAR: case AssignmentOperator.CLEAR: