From 4ee49552ce7ec657c02407cdcd9b9892dec166a7 Mon Sep 17 00:00:00 2001 From: Novice Date: Fri, 16 Jan 2026 17:10:09 +0800 Subject: [PATCH] feat: add prompt variable message --- api/controllers/console/app/workflow_draft_variable.py | 4 +++- api/factories/variable_factory.py | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/api/controllers/console/app/workflow_draft_variable.py b/api/controllers/console/app/workflow_draft_variable.py index 3382b65acc..3ff388d330 100644 --- a/api/controllers/console/app/workflow_draft_variable.py +++ b/api/controllers/console/app/workflow_draft_variable.py @@ -17,7 +17,7 @@ from controllers.console.wraps import account_initialization_required, edit_perm from controllers.web.error import InvalidArgumentError, NotFoundError from core.file import helpers as file_helpers from core.variables.segment_group import SegmentGroup -from core.variables.segments import ArrayFileSegment, FileSegment, Segment +from core.variables.segments import ArrayFileSegment, ArrayPromptMessageSegment, FileSegment, Segment from core.variables.types import SegmentType from core.workflow.constants import CONVERSATION_VARIABLE_NODE_ID, SYSTEM_VARIABLE_NODE_ID from extensions.ext_database import db @@ -58,6 +58,8 @@ def _convert_values_to_json_serializable_object(value: Segment): return value.value.model_dump() elif isinstance(value, ArrayFileSegment): return [i.model_dump() for i in value.value] + elif isinstance(value, ArrayPromptMessageSegment): + return value.to_object() elif isinstance(value, SegmentGroup): return [_convert_values_to_json_serializable_object(i) for i in value.value] else: diff --git a/api/factories/variable_factory.py b/api/factories/variable_factory.py index 03a096b773..17cbb9cfdd 100644 --- a/api/factories/variable_factory.py +++ b/api/factories/variable_factory.py @@ -285,6 +285,10 @@ def build_segment_with_type(segment_type: SegmentType, value: Any) -> Segment: ): segment_class = _segment_factory[inferred_type] return segment_class(value_type=inferred_type, value=value) + elif segment_type == SegmentType.ARRAY_PROMPT_MESSAGE and inferred_type == SegmentType.ARRAY_OBJECT: + # PromptMessage serializes to dict, so ARRAY_OBJECT is compatible with ARRAY_PROMPT_MESSAGE + segment_class = _segment_factory[segment_type] + return segment_class(value_type=segment_type, value=value) else: raise TypeMismatchError(f"Type mismatch: expected {segment_type}, but got {inferred_type}, value={value}")