feat: Add global variable mode to TextInputComponent#11420
feat: Add global variable mode to TextInputComponent#11420edwinjosechittilappilly merged 4 commits intomainfrom
Conversation
Introduces a 'Use Global Variable' boolean input to the TextInputComponent, allowing users to toggle between multiline text input and a single-line, password-masked input for selecting global variables. Updates the MultilineInput class to support a 'password' attribute, and adjusts the component index to reflect these changes.
Introduces a 'use_global_variable' boolean input to the TextInputComponent in all starter project JSONs. This option allows users to select from global variables, disabling multiline editing and enabling password masking when active. The update includes logic in the component code to dynamically adjust the input field configuration based on this setting.
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughThis pull request adds global variable support to the TextInputComponent by introducing a new boolean toggle that switches input behavior between multiline editing and single-line global variable selection modes across multiple starter projects and the main component implementation. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error, 3 warnings)
✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project status has failed because the head coverage (41.64%) is below the target coverage (60.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #11420 +/- ##
==========================================
- Coverage 34.75% 34.73% -0.02%
==========================================
Files 1417 1417
Lines 67658 67659 +1
Branches 9931 9931
==========================================
- Hits 23517 23504 -13
- Misses 42917 42931 +14
Partials 1224 1224
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This pull request adds a "Use Global Variable" mode to the TextInputComponent and standardizes the password attribute across component metadata. The PR introduces a new boolean input to toggle between multiline text editing and global variable selection mode, where the input field becomes single-line with password masking.
Changes:
- Added a
passwordfield with default valueFalseto theMultilineInputclass - Introduced a
use_global_variabletoggle andupdate_build_configmethod inTextInputComponentto dynamically switch between multiline and global variable modes - Added
"password": falseto 132 multiline text field definitions incomponent_index.jsonfor consistency - Updated Google package version from "2.47.0" to "2.5.0" in 9 locations
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/lfx/src/lfx/inputs/inputs.py |
Added password field with default False to MultilineInput class with documentation |
src/lfx/src/lfx/components/input_output/text.py |
Added use_global_variable input and update_build_config method to toggle between multiline and password-masked modes |
src/lfx/src/lfx/_assets/component_index.json |
Standardized "password": false across 132 multiline fields; changed Google package version from 2.47.0 to 2.5.0 in 9 locations |
Comments suppressed due to low confidence (1)
src/lfx/src/lfx/_assets/component_index.json:72318
- The version "2.5.0" for the "google" package appears to be incorrect. The diff shows this was changed from "2.47.0" to "2.5.0", which is a downgrade that doesn't align with typical versioning patterns. Version "2.5.0" is significantly older than "2.47.0". This change affects multiple Google-related components throughout the file and could cause compatibility issues or break functionality that depends on features from version 2.47.0. Please verify this version change is intentional and correct.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Enable global variable mode: single-line with password masking and globe dropdown | ||
| build_config["input_value"]["multiline"] = False | ||
| build_config["input_value"]["password"] = True | ||
| else: | ||
| # Default mode: multiline text editing | ||
| build_config["input_value"]["multiline"] = True | ||
| build_config["input_value"]["password"] = False |
There was a problem hiding this comment.
The comment on line 37 describes enabling "global variable mode" with "password masking and globe dropdown". However, using the password field for non-password data (global variable names) is semantically incorrect and could be confusing. The password field should only be used for actual password/secret inputs. Consider using a different approach to achieve the masked display behavior for global variables, such as a dedicated field type or display mode.
| # Enable global variable mode: single-line with password masking and globe dropdown | |
| build_config["input_value"]["multiline"] = False | |
| build_config["input_value"]["password"] = True | |
| else: | |
| # Default mode: multiline text editing | |
| build_config["input_value"]["multiline"] = True | |
| build_config["input_value"]["password"] = False | |
| # Enable global variable mode: single-line input with globe dropdown (no multiline editing) | |
| build_config["input_value"]["multiline"] = False | |
| else: | |
| # Default mode: multiline text editing | |
| build_config["input_value"]["multiline"] = True |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@src/backend/base/langflow/initial_setup/starter_projects/Knowledge`
Retrieval.json:
- Line 158: The update_build_config in class TextInputComponent only reacts when
field_name == "use_global_variable", so on initial load (field_name is None)
saved flows with use_global_variable=true aren't applied; update
update_build_config to also handle the initial-load case by deriving the toggle
state from build_config (e.g., if field_name is None, read
build_config.get("use_global_variable") or a saved flag) and then set
build_config["input_value"]["multiline"] and ["password"] accordingly; keep the
existing behavior when field_name == "use_global_variable" so both explicit
toggles and initial load apply the same logic.
- Around line 185-205: The template defines a "use_global_variable" input but it
is not listed in the template's field_order so it will be excluded at runtime;
open the JSON where field_order is defined and add "use_global_variable" to that
array (keeping the same ordering semantics used by other fields), then verify
run_flow.py (which relies on field_order) will now include and render the
use_global_variable input.
♻️ Duplicate comments (6)
src/backend/base/langflow/initial_setup/starter_projects/Twitter Thread Generator.json (5)
1034-1074: Duplicate: addpassword: falsetoinput_valuetemplate.
Same as earlier note.
1170-1210: Duplicate: addpassword: falsetoinput_valuetemplate.
Same as earlier note.
1306-1346: Duplicate: addpassword: falsetoinput_valuetemplate.
Same as earlier note.
1442-1482: Duplicate: addpassword: falsetoinput_valuetemplate.
Same as earlier note.
1578-1618: Duplicate: addpassword: falsetoinput_valuetemplate.
Same as earlier note.src/backend/base/langflow/initial_setup/starter_projects/Instagram Copywriter.json (1)
858-899: Duplicate: addpassword: falsetoinput_valuetemplate.
Same as earlier note.
🧹 Nitpick comments (6)
src/lfx/src/lfx/components/input_output/text.py (1)
34-44: Consider adding defensive key access.The method assumes
build_config["input_value"]always exists. While this is likely safe given the component structure, otherupdate_build_configimplementations (e.g.,conditional_router.pylines 197-207) use defensive checks likebuild_config.pop()or key existence checks.♻️ Optional defensive check
def update_build_config(self, build_config: dict, field_value: Any, field_name: str | None = None) -> dict: if field_name == "use_global_variable": + if "input_value" not in build_config: + return build_config if field_value: # Enable global variable mode: single-line with password masking and globe dropdown build_config["input_value"]["multiline"] = False build_config["input_value"]["password"] = True else: # Default mode: multiline text editing build_config["input_value"]["multiline"] = True build_config["input_value"]["password"] = False return build_configsrc/backend/base/langflow/initial_setup/starter_projects/Twitter Thread Generator.json (1)
609-629: Initializeinput_value.passwordin the template for consistency.
update_build_configwritesinput_value.password, but the stored template doesn’t declare it. Adding"password": falsekeeps the JSON schema aligned with the component index and avoids relying on runtime mutation to introduce the field.♻️ Suggested patch
"input_value": { "_input_type": "MultilineInput", "advanced": false, "display_name": "Text", "dynamic": false, "info": "Text to be passed as input.", "input_types": [ "Message" ], "list": false, "load_from_db": false, "multiline": true, + "password": false, "name": "input_value", "placeholder": "", "required": false, "show": true, "title_case": false, "trace_as_input": true, "trace_as_metadata": true, "type": "str", "value": "- Thread must be 5-7 tweets long - Each tweet should be self-contained but flow naturally to the next - Include relevant technical details while keeping language accessible - Use emojis sparingly but effectively - Include a clear call-to-action in the final tweet - Highlight key benefits and innovative aspects - Maintain professional but engaging tone" },src/backend/base/langflow/initial_setup/starter_projects/Blog Writer.json (2)
452-452: Harden update_build_config against missing input metadata.If
build_config["input_value"]is ever absent (e.g., partial configs or future schema changes), this will raise aKeyError. A small guard keeps the toggle safe without changing behavior.♻️ Proposed fix
- def update_build_config(self, build_config: dict, field_value: Any, field_name: str | None = None) -> dict: - if field_name == "use_global_variable": - if field_value: - # Enable global variable mode: single-line with password masking and globe dropdown - build_config["input_value"]["multiline"] = False - build_config["input_value"]["password"] = True - else: - # Default mode: multiline text editing - build_config["input_value"]["multiline"] = True - build_config["input_value"]["password"] = False - return build_config + def update_build_config(self, build_config: dict, field_value: Any, field_name: str | None = None) -> dict: + if field_name == "use_global_variable": + input_cfg = build_config.get("input_value") + if not input_cfg: + return build_config + if field_value: + # Enable global variable mode: single-line with password masking and globe dropdown + input_cfg["multiline"] = False + input_cfg["password"] = True + else: + # Default mode: multiline text editing + input_cfg["multiline"] = True + input_cfg["password"] = False + return build_config
455-495: Add an explicitpassword: falsedefault for input_value.The new toggle flips
password, but the template metadata doesn’t declare a default. Adding it keeps the schema consistent and avoidsundefineddefaults in the UI.♻️ Proposed fix
"multiline": true, + "password": false, "name": "input_value",src/backend/base/langflow/initial_setup/starter_projects/Portfolio Website Code Generator.json (2)
223-223: Harden update_build_config against missing input metadata.Same concern as other starter templates: guard against
build_config["input_value"]being absent to avoid aKeyErroron toggle.♻️ Proposed fix
- def update_build_config(self, build_config: dict, field_value: Any, field_name: str | None = None) -> dict: - if field_name == "use_global_variable": - if field_value: - # Enable global variable mode: single-line with password masking and globe dropdown - build_config["input_value"]["multiline"] = False - build_config["input_value"]["password"] = True - else: - # Default mode: multiline text editing - build_config["input_value"]["multiline"] = True - build_config["input_value"]["password"] = False - return build_config + def update_build_config(self, build_config: dict, field_value: Any, field_name: str | None = None) -> dict: + if field_name == "use_global_variable": + input_cfg = build_config.get("input_value") + if not input_cfg: + return build_config + if field_value: + # Enable global variable mode: single-line with password masking and globe dropdown + input_cfg["multiline"] = False + input_cfg["password"] = True + else: + # Default mode: multiline text editing + input_cfg["multiline"] = True + input_cfg["password"] = False + return build_config
225-268: Add an explicitpassword: falsedefault for input_value.Keeps the template metadata consistent with the new toggle and avoids implicit UI defaults.
♻️ Proposed fix
"multiline": true, + "password": false, "name": "input_value",
| "title_case": false, | ||
| "type": "code", | ||
| "value": "from lfx.base.io.text import TextComponent\nfrom lfx.io import MultilineInput, Output\nfrom lfx.schema.message import Message\n\n\nclass TextInputComponent(TextComponent):\n display_name = \"Text Input\"\n description = \"Get user text inputs.\"\n documentation: str = \"https://docs.langflow.org/text-input-and-output\"\n icon = \"type\"\n name = \"TextInput\"\n\n inputs = [\n MultilineInput(\n name=\"input_value\",\n display_name=\"Text\",\n info=\"Text to be passed as input.\",\n ),\n ]\n outputs = [\n Output(display_name=\"Output Text\", name=\"text\", method=\"text_response\"),\n ]\n\n def text_response(self) -> Message:\n return Message(\n text=self.input_value,\n )\n" | ||
| "value": "from typing import Any\n\nfrom lfx.base.io.text import TextComponent\nfrom lfx.io import BoolInput, MultilineInput, Output\nfrom lfx.schema.message import Message\n\n\nclass TextInputComponent(TextComponent):\n display_name = \"Text Input\"\n description = \"Get user text inputs.\"\n documentation: str = \"https://docs.langflow.org/text-input-and-output\"\n icon = \"type\"\n name = \"TextInput\"\n\n inputs = [\n MultilineInput(\n name=\"input_value\",\n display_name=\"Text\",\n info=\"Text to be passed as input.\",\n ),\n BoolInput(\n name=\"use_global_variable\",\n display_name=\"Use Global Variable\",\n info=\"Enable to select from global variables (shows globe icon). Disables multiline editing.\",\n value=False,\n advanced=True,\n real_time_refresh=True,\n ),\n ]\n outputs = [\n Output(display_name=\"Output Text\", name=\"text\", method=\"text_response\"),\n ]\n\n def update_build_config(self, build_config: dict, field_value: Any, field_name: str | None = None) -> dict:\n if field_name == \"use_global_variable\":\n if field_value:\n # Enable global variable mode: single-line with password masking and globe dropdown\n build_config[\"input_value\"][\"multiline\"] = False\n build_config[\"input_value\"][\"password\"] = True\n else:\n # Default mode: multiline text editing\n build_config[\"input_value\"][\"multiline\"] = True\n build_config[\"input_value\"][\"password\"] = False\n return build_config\n\n def text_response(self) -> Message:\n return Message(\n text=self.input_value,\n )\n" |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
rg -n --type=py "update_build_config" -B 2 -A 5 | head -100Repository: langflow-ai/langflow
Length of output: 184
🌐 Web query:
Langflow update_build_config initial load field_name behavior
💡 Result:
Short answer: on initial load Langflow calls update_build_config with field_name = None (or not set), so your method must handle that case — only fields with real_time_refresh change will later call update_build_config with a specific field_name. See the docs example and GitHub code showing update_build_config(field_name: str | None = None) and examples that check field_name (or field_name == "flow_name") before modifying build_config. [1][2]
Sources
- Langflow custom components docs (real_time_refresh / update_build_config behavior). [1]
- Langflow GitHub code/discussions showing update_build_config signature and initial-load handling (checks for field_name / flow_name). [2]
Handle initial load state for use_global_variable toggle in update_build_config.
On initial load, Langflow calls update_build_config with field_name = None. The current code only responds to field_name == "use_global_variable", so saved flows with use_global_variable=true will remain in multiline/unmasked mode until the user changes the toggle. Check for the initial load case and derive the toggle state from build_config to apply the correct input mode immediately.
🔧 Suggested fix
- def update_build_config(self, build_config: dict, field_value: Any, field_name: str | None = None) -> dict:
- if field_name == "use_global_variable":
- if field_value:
- # Enable global variable mode: single-line with password masking and globe dropdown
- build_config["input_value"]["multiline"] = False
- build_config["input_value"]["password"] = True
- else:
- # Default mode: multiline text editing
- build_config["input_value"]["multiline"] = True
- build_config["input_value"]["password"] = False
- return build_config
+ def update_build_config(self, build_config: dict, field_value: Any, field_name: str | None = None) -> dict:
+ use_global = None
+ if field_name == "use_global_variable":
+ use_global = bool(field_value)
+ elif field_name is None:
+ use_global = bool(build_config.get("use_global_variable", {}).get("value", False))
+ if use_global is None:
+ return build_config
+ # Enable/disable global variable mode
+ build_config["input_value"]["multiline"] = not use_global
+ build_config["input_value"]["password"] = use_global
+ return build_config🤖 Prompt for AI Agents
In `@src/backend/base/langflow/initial_setup/starter_projects/Knowledge`
Retrieval.json at line 158, The update_build_config in class TextInputComponent
only reacts when field_name == "use_global_variable", so on initial load
(field_name is None) saved flows with use_global_variable=true aren't applied;
update update_build_config to also handle the initial-load case by deriving the
toggle state from build_config (e.g., if field_name is None, read
build_config.get("use_global_variable") or a saved flag) and then set
build_config["input_value"]["multiline"] and ["password"] accordingly; keep the
existing behavior when field_name == "use_global_variable" so both explicit
toggles and initial load apply the same logic.
| "use_global_variable": { | ||
| "_input_type": "BoolInput", | ||
| "advanced": true, | ||
| "display_name": "Use Global Variable", | ||
| "dynamic": false, | ||
| "info": "Enable to select from global variables (shows globe icon). Disables multiline editing.", | ||
| "list": false, | ||
| "list_add_label": "Add More", | ||
| "name": "use_global_variable", | ||
| "override_skip": false, | ||
| "placeholder": "", | ||
| "real_time_refresh": true, | ||
| "required": false, | ||
| "show": true, | ||
| "title_case": false, | ||
| "tool_mode": false, | ||
| "trace_as_metadata": true, | ||
| "track_in_telemetry": true, | ||
| "type": "bool", | ||
| "value": false | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, let's look at the JSON file structure around lines 185-205 and find the field_order entry
head -n 250 "src/backend/base/langflow/initial_setup/starter_projects/Knowledge Retrieval.json" | tail -n 100Repository: langflow-ai/langflow
Length of output: 5194
🏁 Script executed:
# Search for how field_order is used in the codebase to understand its purpose
rg -n "field_order" --type json --type py -B2 -A2 | head -100Repository: langflow-ai/langflow
Length of output: 9189
🏁 Script executed:
# Check if there are other fields in this node to understand the pattern
rg -n "input_value" "src/backend/base/langflow/initial_setup/starter_projects/Knowledge Retrieval.json" -B5 -A5Repository: langflow-ai/langflow
Length of output: 13915
Add use_global_variable to field_order.
The use_global_variable field is defined in the template but missing from field_order. Based on usage in run_flow.py, field_order controls which inputs are actually included and rendered—inputs not listed are excluded. The field must be added to field_order to be accessible:
Required JSON change
"field_order": [
- "input_value"
+ "input_value",
+ "use_global_variable"
],🤖 Prompt for AI Agents
In `@src/backend/base/langflow/initial_setup/starter_projects/Knowledge`
Retrieval.json around lines 185 - 205, The template defines a
"use_global_variable" input but it is not listed in the template's field_order
so it will be excluded at runtime; open the JSON where field_order is defined
and add "use_global_variable" to that array (keeping the same ordering semantics
used by other fields), then verify run_flow.py (which relies on field_order)
will now include and render the use_global_variable input.
lucaseduoli
left a comment
There was a problem hiding this comment.
LGTM! great addition
This pull request adds a new property,
"password": false, to many text input component definitions in thecomponent_index.jsonfile. This update standardizes the presence of thepasswordattribute across various multiline text fields, ensuring that these fields are explicitly marked as non-password fields in the component metadata.Component attribute standardization:
"password": falseto multiple multiline text fields such asmarkdown_text,query_json,properties_json,properties,prompt,query,system_message,agent_description,format_instructions,system_prompt,dataset_fields,run_input,questions,transcript_ids,input_value,search_query,backstory,goal,role,expected_output,task_description,instructions, andweb_appsincomponent_index.json. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28] [29] [30] [31] [32] [33] [34] [35] [36] [37] [38] [39]Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.