nested state path

This commit is contained in:
lda
2026-05-17 15:44:41 +07:00 Verified
parent c6360d3892
commit 5476010f12
10 changed files with 161 additions and 26 deletions
+5 -1
View File
@@ -141,7 +141,11 @@ def pick_path(input: PickPathInput) -> ValueOutput:
def project_fields(input: ProjectFieldsInput) -> MappingOutput:
"""Return only the requested existing fields from a mapping."""
return MappingOutput(
mapping={field: input.mapping[field] for field in input.fields if field in input.mapping}
mapping={
field: input.mapping[field]
for field in input.fields
if field in input.mapping
}
)
+2 -2
View File
@@ -17,7 +17,7 @@ class SchemaRef(BaseModel):
class StateField(BaseModel):
"""Declared root state field plus its runtime merge behavior."""
"""Declared state path plus its runtime merge behavior."""
type: str
merge_strategy: Literal["replace", "append", "merge_object"] = "replace"
@@ -26,7 +26,7 @@ class StateField(BaseModel):
class StateSchema(BaseModel):
"""Workflow state schema keyed by declared root field name."""
"""Workflow state schema keyed by declared exact state path."""
model_config = ConfigDict(extra="allow")
+13 -5
View File
@@ -23,15 +23,23 @@ def apply_builtin_merge(
if strategy == "append":
if current_value is None:
return [incoming_value] if not isinstance(incoming_value, list) else incoming_value
return (
[incoming_value]
if not isinstance(incoming_value, list)
else incoming_value
)
if not isinstance(current_value, list):
raise WorkflowExecutionError(
f"cannot append into non-list state path {destination_path!r}"
)
return [
*current_value,
*incoming_value,
] if isinstance(incoming_value, list) else [*current_value, incoming_value]
return (
[
*current_value,
*incoming_value,
]
if isinstance(incoming_value, list)
else [*current_value, incoming_value]
)
if strategy == "merge_object":
if current_value is None:
+5 -3
View File
@@ -39,7 +39,9 @@ def apply_mapped_state(
missing_field_message: str,
) -> dict[str, Any]:
if has_overlapping_paths(mapping.values()):
raise WorkflowExecutionError("mapped state patch has overlapping destination paths")
raise WorkflowExecutionError(
"mapped state patch has overlapping destination paths"
)
patch: dict[str, Any] = {}
for source_field, destination_path in mapping.items():
@@ -69,8 +71,8 @@ def write_state_value(
f"executor only supports writes into state.*, got {destination_path!r}"
)
field_name = parts[0]
declared_field = workflow.state_schema.fields.get(field_name)
declared_path = ".".join(parts)
declared_field = workflow.state_schema.fields.get(declared_path)
merge_strategy = declared_field.merge_strategy if declared_field else "replace"
key_path = parts
current_value = get_nested_value(state, key_path)