From 70f18bcb89765c9172a0dfa27fc3fffb831bb979 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 10 Jul 2025 15:35:00 -0300 Subject: [PATCH] feat: add utility to insert code field into build config dictionary (#8933) feat: add code field to build configuration in custom component update if it was removed - Introduced `add_code_field_to_build_config` utility function to enhance build configuration with a code field. - Updated `custom_component_update` to conditionally add the code field if it is not already present, improving component customization capabilities. Co-authored-by: Edwin Jose --- src/backend/base/langflow/api/v1/endpoints.py | 9 ++++++++- src/backend/base/langflow/custom/utils.py | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/backend/base/langflow/api/v1/endpoints.py b/src/backend/base/langflow/api/v1/endpoints.py index 85e1eac6c..f1ce98f35 100644 --- a/src/backend/base/langflow/api/v1/endpoints.py +++ b/src/backend/base/langflow/api/v1/endpoints.py @@ -27,7 +27,12 @@ from langflow.api.v1.schemas import ( UploadFileResponse, ) from langflow.custom.custom_component.component import Component -from langflow.custom.utils import build_custom_component_template, get_instance_name, update_component_build_config +from langflow.custom.utils import ( + add_code_field_to_build_config, + build_custom_component_template, + get_instance_name, + update_component_build_config, +) from langflow.events.event_manager import create_stream_tokens_event_manager from langflow.exceptions.api import APIException, InvalidChatInputError from langflow.exceptions.serialization import SerializationError @@ -727,6 +732,8 @@ async def custom_component_update( field_value=code_request.field_value, field_name=code_request.field, ) + if "code" not in updated_build_config: + updated_build_config = add_code_field_to_build_config(updated_build_config, code_request.code) component_node["template"] = updated_build_config if isinstance(cc_instance, Component): diff --git a/src/backend/base/langflow/custom/utils.py b/src/backend/base/langflow/custom/utils.py index 6cc2b6896..2d2b82305 100644 --- a/src/backend/base/langflow/custom/utils.py +++ b/src/backend/base/langflow/custom/utils.py @@ -398,6 +398,22 @@ def add_code_field(frontend_node: CustomComponentFrontendNode, raw_code): return frontend_node +def add_code_field_to_build_config(build_config: dict, raw_code: str): + build_config["code"] = Input( + dynamic=True, + required=True, + placeholder="", + multiline=True, + value=raw_code, + password=False, + name="code", + advanced=True, + field_type="code", + is_list=False, + ).model_dump() + return build_config + + def build_custom_component_template_from_inputs( custom_component: Component | CustomComponent, user_id: str | UUID | None = None ):