diff --git a/api/core/app/segments/factory.py b/api/core/app/segments/factory.py index f62e44bf07..1196284b18 100644 --- a/api/core/app/segments/factory.py +++ b/api/core/app/segments/factory.py @@ -75,8 +75,7 @@ def build_segment(value: Any, /) -> Segment: return FloatSegment(value=value) if isinstance(value, dict): # TODO: Limit the depth of the object - obj = {k: build_segment(v) for k, v in value.items()} - return ObjectSegment(value=obj) + return ObjectSegment(value=value) if isinstance(value, list): # TODO: Limit the depth of the array elements = [build_segment(v) for v in value] diff --git a/api/core/app/segments/segments.py b/api/core/app/segments/segments.py index 4227f154e6..077d606ad4 100644 --- a/api/core/app/segments/segments.py +++ b/api/core/app/segments/segments.py @@ -85,7 +85,7 @@ class FileSegment(Segment): class ObjectSegment(Segment): value_type: SegmentType = SegmentType.OBJECT - value: Mapping[str, Segment] + value: Mapping[str, Any] @property def text(self) -> str: @@ -102,9 +102,6 @@ class ObjectSegment(Segment): # TODO: Use markdown code block return json.dumps(self.model_dump()['value'], ensure_ascii=False, indent=2) - def to_object(self): - return {k: v.to_object() for k, v in self.value.items()} - class ArraySegment(Segment): @property diff --git a/api/tests/unit_tests/core/app/segments/test_factory.py b/api/tests/unit_tests/core/app/segments/test_factory.py index 85321ee374..a88dd939bb 100644 --- a/api/tests/unit_tests/core/app/segments/test_factory.py +++ b/api/tests/unit_tests/core/app/segments/test_factory.py @@ -67,7 +67,7 @@ def test_build_a_object_variable_with_none_value(): } ) assert isinstance(var, ObjectSegment) - assert isinstance(var.value['key1'], NoneSegment) + assert var.value['key1'] is None def test_object_variable(): diff --git a/api/tests/unit_tests/core/app/segments/test_variables.py b/api/tests/unit_tests/core/app/segments/test_variables.py index e3f513971a..1f45c15f87 100644 --- a/api/tests/unit_tests/core/app/segments/test_variables.py +++ b/api/tests/unit_tests/core/app/segments/test_variables.py @@ -54,20 +54,10 @@ def test_object_variable_to_object(): var = ObjectVariable( name='object', value={ - 'key1': ObjectVariable( - name='object', - value={ - 'key2': StringVariable(name='key2', value='value2'), - }, - ), - 'key2': ArrayAnyVariable( - name='array', - value=[ - StringVariable(name='key5_1', value='value5_1'), - IntegerVariable(name='key5_2', value=42), - ObjectVariable(name='key5_3', value={}), - ], - ), + 'key1': { + 'key2': 'value2', + }, + 'key2': ['value5_1', 42, {}], }, )