feat: preserve manual component data if code unchanged (#5482)

* chore: preserve manual component data if code unchanged

* Fixed tool mode switch not changing with code

* Removed console.log

* Made tool mode not be lost when mutating template

* use setNode instead of setNodes on component code

* refactor: tool_mode return

* Fix tool mode being reverted on toggle

* fix: tool_mode outputs return

* change: logic for setting `tool_mode`

---------

Co-authored-by: Lucas Oliveira <62335616+lucaseduoli@users.noreply.github.com>
Co-authored-by: Lucas Oliveira <lucas.edu.oli@hotmail.com>
Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
This commit is contained in:
Ítalo Johnny 2025-01-20 08:34:52 -03:00 • committed by GitHub
commit c8eb408b5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 44 additions and 30 deletions

View file

@ -78,5 +78,28 @@ def update_frontend_node_with_template_values(frontend_node, raw_frontend_node):
old_code = raw_frontend_node["template"]["code"]["value"]
new_code = frontend_node["template"]["code"]["value"]
frontend_node["edited"] = raw_frontend_node["edited"] or (old_code != new_code)
frontend_node["tool_mode"] = raw_frontend_node.get("tool_mode", False)
if any(extract_tool_modes(raw_frontend_node["template"])):
frontend_node["tool_mode"] = False
if not frontend_node.get("edited", False):
frontend_node["display_name"] = raw_frontend_node["display_name"]
frontend_node["description"] = raw_frontend_node["description"]
return frontend_node
def extract_tool_modes(data: dict | list) -> list[bool | None]:
tool_models = []
if isinstance(data, dict):
for key, value in data.items():
if key == "tool_mode":
tool_models.append(value)
else:
tool_models.extend(extract_tool_modes(value))
elif isinstance(data, list):
for item in data:
tool_models.extend(extract_tool_modes(item))
return tool_models