OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.
Python
fix: split oversized ingest chunks (#2549)
Wallgaue43dec2590d7
diff --git a/custom_components/openrag/split_text.py b/custom_components/openrag/split_text.pynew file mode 100644index 000000000..c84112ea3--- /dev/null+++ b/custom_components/openrag/split_text.py@@ -0,0 +1,171 @@+from langchain_text_splitters import RecursiveCharacterTextSplitter+from lfx.custom.custom_component.component import Component+from lfx.io import BoolInput, DropdownInput, HandleInput, IntInput, MessageTextInput, Output+from lfx.schema.data import Data+from lfx.schema.dataframe import DataFrame+from lfx.schema.message import Message+from lfx.utils.util import unescape_string++# Tried in order after the configured separator. Docling joins consecutive+# lines that have no blank line between them into one Markdown paragraph, so a+# long document can arrive with almost no newlines; without these fallbacks a+# single paragraph becomes one chunk of any size.+FALLBACK_SEPARATORS = ("\n\n", "\n", "。", ". ", " ", "")+++def build_separators(separator: str) -> list[str]:+ separators = [separator] if separator else []+ separators += [s for s in FALLBACK_SEPARATORS if s not in separators]+ return separators+++class OpenRAGSplitTextComponent(Component):+ display_name: str = "Split Text"+ description: str = "Split text into chunks no longer than the chunk size."+ documentation: str = "https://docs.langflow.org/split-text"+ icon = "scissors-line-dashed"+ # Distinct from Langflow's built-in "SplitText": in restricted mode Langflow+ # replaces drifted code of a known built-in type with its own copy.+ name = "OpenRAGSplitText"++ inputs = [+ HandleInput(+ name="data_inputs",+ display_name="Input",+ info="The data with texts to split in chunks.",+ input_types=["Data", "JSON", "DataFrame", "Table", "Message"],+ required=True,+ ),+ IntInput(+ name="chunk_overlap",+ display_name="Chunk Overlap",+ info="Number of characters to overlap between chunks.",+ value=200,+ ),+ IntInput(+ name="chunk_size",+ display_name="Chunk Size",+ info=(+ "The maximum length of each chunk. Text is split on the separator first; "+ "any piece still longer than this is split on finer boundaries "+ "(lines, sentences, spaces, then characters)."+ ),+ value=1000,+ ),+ MessageTextInput(+ name="separator",+ display_name="Separator",+ info=(+ "The preferred character to split on. Use \\n for newline. "+ "Examples: \\n\\n for paragraphs, \\n for lines, . for sentences"+ ),+ value="\n",+ ),+ MessageTextInput(+ name="text_key",+ display_name="Text Key",+ info="The key to use for the text column.",+ value="text",+ advanced=True,+ ),+ DropdownInput(+ name="keep_separator",+ display_name="Keep Separator",+ info="Whether to keep the separator in the output chunks and where to place it.",+ options=["False", "True", "Start", "End"],+ value="False",+ advanced=True,+ ),+ BoolInput(+ name="clean_output",+ display_name="Clean Output",+ info="When enabled, only the text column is included in the output. Metadata columns are removed.",+ value=False,+ advanced=True,+ ),+ ]++ outputs = [+ Output(display_name="Chunks", name="dataframe", method="split_text"),+ ]++ def _docs_to_data(self, docs, *, clean: bool = False) -> list[Data]:+ return [+ Data(text=doc.page_content) if clean else Data(text=doc.page_content, data=doc.metadata)+ for doc in docs+ ]++ def _fix_separator(self, separator: str) -> str:+ """Fix common separator issues and convert to proper format."""+ if separator == "/n":+ return "\n"+ if separator == "/t":+ return "\t"+ return separator++ def split_text_base(self):+ separator = self._fix_separator(self.separator)+ separator = unescape_string(separator)++ if isinstance(self.data_inputs, DataFrame):+ if not len(self.data_inputs):+ msg = "DataFrame is empty"+ raise TypeError(msg)++ self.data_inputs.text_key = self.text_key+ try:+ documents = self.data_inputs.to_lc_documents()+ except Exception as e:+ msg = f"Error converting DataFrame to documents: {e}"+ raise TypeError(msg) from e+ elif isinstance(self.data_inputs, Message):+ self.data_inputs = [self.data_inputs.to_data()]+ return self.split_text_base()+ else:+ if not self.data_inputs:+ msg = "No data inputs provided"+ raise TypeError(msg)++ documents = []+ if isinstance(self.data_inputs, Data):+ self.data_inputs.text_key = self.text_key+ documents = [self.data_inputs.to_lc_document()]+ else:+ try:+ documents = [+ input_.to_lc_document()+ for input_ in self.data_inputs+ if isinstance(input_, Data)+ ]+ if not documents:+ msg = f"No valid Data inputs found in {type(self.data_inputs)}"+ raise TypeError(msg)+ except AttributeError as e:+ msg = f"Invalid input type in collection: {e}"+ raise TypeError(msg) from e+ try:+ # Convert string 'False'/'True' to boolean+ keep_sep = self.keep_separator+ if isinstance(keep_sep, str):+ keep_sep = keep_sep.lower()+ if keep_sep == "false":+ keep_sep = False+ elif keep_sep == "true":+ keep_sep = True+ # LangChain only recognises lowercase 'start' and 'end'++ splitter = RecursiveCharacterTextSplitter(+ chunk_overlap=self.chunk_overlap,+ chunk_size=self.chunk_size,+ separators=build_separators(separator),+ keep_separator=keep_sep,+ )+ return splitter.split_documents(documents)+ except Exception as e:+ msg = f"Error splitting text: {e}"+ raise TypeError(msg) from e++ def split_text(self) -> DataFrame:+ docs = self.split_text_base()+ df = DataFrame(self._docs_to_data(docs, clean=self.clean_output))+ return df if self.clean_output else df.smart_column_order()diff --git a/flows/ingestion_flow.json b/flows/ingestion_flow.jsonindex 9db862dcb..1847c18c7 100644--- a/flows/ingestion_flow.json+++ b/flows/ingestion_flow.json@@ -37,146 +37,142 @@"className": "","data": {"sourceHandle": {- "dataType": "ExportDoclingDocument",- "id": "ExportDoclingDocument-zZdRg",- "name": "dataframe",+ "dataType": "OpenAICompatibleEmbedding",+ "id": "OpenAICompatibleEmbedding-MloZd",+ "name": "embeddings","output_types": [- "Table"+ "Embeddings"]},"targetHandle": {- "fieldName": "df",- "id": "Operations-IC6CD",+ "fieldName": "embedding",+ "id": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28","inputTypes": [- "DataFrame",- "Table"+ "Embeddings"],"type": "other"}},- "id": "xy-edge__ExportDoclingDocument-zZdRg{œdataTypeœ:œExportDoclingDocumentœ,œidœ:œExportDoclingDocument-zZdRgœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}-Operations-IC6CD{œfieldNameœ:œdfœ,œidœ:œOperations-IC6CDœ,œinputTypesœ:[œDataFrameœ,œTableœ],œtypeœ:œotherœ}",+ "id": "xy-edge__OpenAICompatibleEmbedding-MloZd{œdataTypeœ:œOpenAICompatibleEmbeddingœ,œidœ:œOpenAICompatibleEmbedding-MloZdœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}-OpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28{œfieldNameœ:œembeddingœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28œ,œinputTypesœ:[œEmbeddingsœ],œtypeœ:œotherœ}","selected": false,- "source": "ExportDoclingDocument-zZdRg",- "sourceHandle": "{œdataTypeœ:œExportDoclingDocumentœ,œidœ:œExportDoclingDocument-zZdRgœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}",- "target": "Operations-IC6CD",- "targetHandle": "{œfieldNameœ:œdfœ,œidœ:œOperations-IC6CDœ,œinputTypesœ:[œDataFrameœ,œTableœ],œtypeœ:œotherœ}"+ "source": "OpenAICompatibleEmbedding-MloZd",+ "sourceHandle": "{œdataTypeœ:œOpenAICompatibleEmbeddingœ,œidœ:œOpenAICompatibleEmbedding-MloZdœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}",+ "target": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28",+ "targetHandle": "{œfieldNameœ:œembeddingœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28œ,œinputTypesœ:[œEmbeddingsœ],œtypeœ:œotherœ}"},{"animated": false,- "className": "","data": {"sourceHandle": {"dataType": "Operations",- "id": "Operations-IC6CD",+ "id": "Operations-VUCJC","name": "dataframe_output","output_types": ["Table"]},"targetHandle": {- "fieldName": "df",- "id": "Operations-VUCJC",+ "fieldName": "data_inputs",+ "id": "ext:openrag:OpenRAGSplitTextComponent@extra-0ttMH","inputTypes": [+ "Data",+ "JSON","DataFrame",- "Table"+ "Table",+ "Message"],"type": "other"}},- "id": "xy-edge__Operations-IC6CD{œdataTypeœ:œOperationsœ,œidœ:œOperations-IC6CDœ,œnameœ:œdataframe_outputœ,œoutput_typesœ:[œTableœ]}-Operations-VUCJC{œfieldNameœ:œdfœ,œidœ:œOperations-VUCJCœ,œinputTypesœ:[œDataFrameœ,œTableœ],œtypeœ:œotherœ}",+ "id": "xy-edge__Operations-VUCJC{œdataTypeœ:œOperationsœ,œidœ:œOperations-VUCJCœ,œnameœ:œdataframe_outputœ,œoutput_typesœ:[œTableœ]}-ext:openrag:OpenRAGSplitTextComponent@extra-0ttMH{œfieldNameœ:œdata_inputsœ,œidœ:œext:openrag:OpenRAGSplitTextComponent@extra-0ttMHœ,œinputTypesœ:[œDataœ,œJSONœ,œDataFrameœ,œTableœ,œMessageœ],œtypeœ:œotherœ}","selected": false,- "source": "Operations-IC6CD",- "sourceHandle": "{œdataTypeœ:œOperationsœ,œidœ:œOperations-IC6CDœ,œnameœ:œdataframe_outputœ,œoutput_typesœ:[œTableœ]}",- "target": "Operations-VUCJC",- "targetHandle": "{œfieldNameœ:œdfœ,œidœ:œOperations-VUCJCœ,œinputTypesœ:[œDataFrameœ,œTableœ],œtypeœ:œotherœ}"+ "source": "Operations-VUCJC",+ "sourceHandle": "{œdataTypeœ:œOperationsœ,œidœ:œOperations-VUCJCœ,œnameœ:œdataframe_outputœ,œoutput_typesœ:[œTableœ]}",+ "target": "ext:openrag:OpenRAGSplitTextComponent@extra-0ttMH",+ "targetHandle": "{œfieldNameœ:œdata_inputsœ,œidœ:œext:openrag:OpenRAGSplitTextComponent@extra-0ttMHœ,œinputTypesœ:[œDataœ,œJSONœ,œDataFrameœ,œTableœ,œMessageœ],œtypeœ:œotherœ}"},{"animated": false,- "className": "","data": {"sourceHandle": {- "dataType": "Operations",- "id": "Operations-VUCJC",- "name": "dataframe_output",+ "dataType": "ext:openrag:OpenRAGSplitTextComponent@extra",+ "id": "ext:openrag:OpenRAGSplitTextComponent@extra-0ttMH",+ "name": "dataframe","output_types": ["Table"]},"targetHandle": {- "fieldName": "data_inputs",- "id": "SplitText-QIKhg",+ "fieldName": "ingest_data",+ "id": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28","inputTypes": ["Data",- "JSON","DataFrame",- "Table",- "Message"+ "Table"],"type": "other"}},- "id": "xy-edge__Operations-VUCJC{œdataTypeœ:œOperationsœ,œidœ:œOperations-VUCJCœ,œnameœ:œdataframe_outputœ,œoutput_typesœ:[œTableœ]}-SplitText-QIKhg{œfieldNameœ:œdata_inputsœ,œidœ:œSplitText-QIKhgœ,œinputTypesœ:[œDataœ,œJSONœ,œDataFrameœ,œTableœ,œMessageœ],œtypeœ:œotherœ}",+ "id": "xy-edge__ext:openrag:OpenRAGSplitTextComponent@extra-0ttMH{œdataTypeœ:œext:openrag:OpenRAGSplitTextComponent@extraœ,œidœ:œext:openrag:OpenRAGSplitTextComponent@extra-0ttMHœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}-OpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28{œfieldNameœ:œingest_dataœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28œ,œinputTypesœ:[œDataœ,œDataFrameœ,œTableœ],œtypeœ:œotherœ}","selected": false,- "source": "Operations-VUCJC",- "sourceHandle": "{œdataTypeœ:œOperationsœ,œidœ:œOperations-VUCJCœ,œnameœ:œdataframe_outputœ,œoutput_typesœ:[œTableœ]}",- "target": "SplitText-QIKhg",- "targetHandle": "{œfieldNameœ:œdata_inputsœ,œidœ:œSplitText-QIKhgœ,œinputTypesœ:[œDataœ,œJSONœ,œDataFrameœ,œTableœ,œMessageœ],œtypeœ:œotherœ}"+ "source": "ext:openrag:OpenRAGSplitTextComponent@extra-0ttMH",+ "sourceHandle": "{œdataTypeœ:œext:openrag:OpenRAGSplitTextComponent@extraœ,œidœ:œext:openrag:OpenRAGSplitTextComponent@extra-0ttMHœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}",+ "target": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28",+ "targetHandle": "{œfieldNameœ:œingest_dataœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28œ,œinputTypesœ:[œDataœ,œDataFrameœ,œTableœ],œtypeœ:œotherœ}"},{"animated": false,"data": {"sourceHandle": {- "dataType": "OpenAICompatibleEmbedding",- "id": "OpenAICompatibleEmbedding-MloZd",- "name": "embeddings",+ "dataType": "ExportDoclingDocument",+ "id": "ExportDoclingDocument-zZdRg",+ "name": "dataframe","output_types": [- "Embeddings"+ "Table"]},"targetHandle": {- "fieldName": "embedding",- "id": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28",+ "fieldName": "df",+ "id": "Operations-IC6CD","inputTypes": [- "Embeddings"+ "DataFrame",+ "Table"],"type": "other"}},- "id": "xy-edge__OpenAICompatibleEmbedding-MloZd{œdataTypeœ:œOpenAICompatibleEmbeddingœ,œidœ:œOpenAICompatibleEmbedding-MloZdœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}-OpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28{œfieldNameœ:œembeddingœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28œ,œinputTypesœ:[œEmbeddingsœ],œtypeœ:œotherœ}",+ "id": "xy-edge__ExportDoclingDocument-zZdRg{œdataTypeœ:œExportDoclingDocumentœ,œidœ:œExportDoclingDocument-zZdRgœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}-Operations-IC6CD{œfieldNameœ:œdfœ,œidœ:œOperations-IC6CDœ,œinputTypesœ:[œDataFrameœ,œTableœ],œtypeœ:œotherœ}","selected": false,- "source": "OpenAICompatibleEmbedding-MloZd",- "sourceHandle": "{œdataTypeœ:œOpenAICompatibleEmbeddingœ,œidœ:œOpenAICompatibleEmbedding-MloZdœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}",- "target": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28",- "targetHandle": "{œfieldNameœ:œembeddingœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28œ,œinputTypesœ:[œEmbeddingsœ],œtypeœ:œotherœ}"+ "source": "ExportDoclingDocument-zZdRg",+ "sourceHandle": "{œdataTypeœ:œExportDoclingDocumentœ,œidœ:œExportDoclingDocument-zZdRgœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}",+ "target": "Operations-IC6CD",+ "targetHandle": "{œfieldNameœ:œdfœ,œidœ:œOperations-IC6CDœ,œinputTypesœ:[œDataFrameœ,œTableœ],œtypeœ:œotherœ}"},{- "animated": false,"data": {"sourceHandle": {- "dataType": "SplitText",- "id": "SplitText-QIKhg",- "name": "dataframe",+ "dataType": "Operations",+ "id": "Operations-IC6CD",+ "name": "dataframe_output","output_types": ["Table"]},"targetHandle": {- "fieldName": "ingest_data",- "id": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28",+ "fieldName": "df",+ "id": "Operations-VUCJC","inputTypes": [- "Data","DataFrame","Table"],"type": "other"}},- "id": "xy-edge__SplitText-QIKhg{œdataTypeœ:œSplitTextœ,œidœ:œSplitText-QIKhgœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}-OpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28{œfieldNameœ:œingest_dataœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28œ,œinputTypesœ:[œDataœ,œDataFrameœ,œTableœ],œtypeœ:œotherœ}",- "selected": false,- "source": "SplitText-QIKhg",- "sourceHandle": "{œdataTypeœ:œSplitTextœ,œidœ:œSplitText-QIKhgœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}",- "target": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28",- "targetHandle": "{œfieldNameœ:œingest_dataœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-WaE28œ,œinputTypesœ:[œDataœ,œDataFrameœ,œTableœ],œtypeœ:œotherœ}"+ "id": "xy-edge__Operations-IC6CD{œdataTypeœ:œOperationsœ,œidœ:œOperations-IC6CDœ,œnameœ:œdataframe_outputœ,œoutput_typesœ:[œTableœ]}-Operations-VUCJC{œfieldNameœ:œdfœ,œidœ:œOperations-VUCJCœ,œinputTypesœ:[œDataFrameœ,œTableœ],œtypeœ:œotherœ}",+ "source": "Operations-IC6CD",+ "sourceHandle": "{œdataTypeœ:œOperationsœ,œidœ:œOperations-IC6CDœ,œnameœ:œdataframe_outputœ,œoutput_typesœ:[œTableœ]}",+ "target": "Operations-VUCJC",+ "targetHandle": "{œfieldNameœ:œdfœ,œidœ:œOperations-VUCJCœ,œinputTypesœ:[œDataFrameœ,œTableœ],œtypeœ:œotherœ}"}],"nodes": [@@ -993,6 +989,8 @@},{"data": {+ "description": "Perform operations on Text, JSON, and Tables from a single component.",+ "display_name": "Data Operations","id": "Operations-IC6CD","node": {"base_classes": [@@ -1054,10 +1052,10 @@],"frozen": false,"icon": "wand-sparkles",- "last_updated": "2026-07-17T19:10:01.879Z",+ "last_updated": "2026-10-27T20:14:20.463Z","legacy": false,"metadata": {- "code_hash": "4c2a33c778d3",+ "code_hash": "f15ba610cfd0","dependencies": {"dependencies": [{@@ -1066,11 +1064,11 @@},{"name": "json_repair",- "version": "0.61.4"+ "version": "0.61.7"},{"name": "lfx",- "version": null+ "version": "1.12.3"},{"name": "jq",@@ -1121,7 +1119,7 @@"data manipulation","data transformation"],- "module": "lfx.components.processing.operations.OperationsComponent"+ "module": "custom_components.data_operations"},"minimized": false,"output_types": [],@@ -1129,7 +1127,7 @@{"allows_loop": false,"cache": true,- "display_name": "Message",+ "display_name": "Table","group_outputs": false,"hidden": null,"loop_types": null,@@ -1151,7 +1149,7 @@"value": "5488df7c-b93f-4f87-a446-b67028bc0813"},"_frontend_node_folder_id": {- "value": "f1efb4f8-3ca5-4e89-8685-0e8b2ba1187f"+ "value": "f3f8bf74-7a73-4ab3-9769-0d8a4ebbaec9"},"_type": "Component","append_update_data": {@@ -1246,7 +1244,7 @@"show": true,"title_case": false,"type": "code",- "value": "\"\"\"Unified Operations component.\n\nBrings together the previously separate JSON, Table, and Text operation\ncomponents into a single component. An \"Input Type\" selector (Text / JSON /\nTable) drives everything: it filters the \"Operation\" picker to the operations\nthat apply to that type, reveals the matching input (Text / JSON / Table) and\nits operation-specific fields, and advertises the appropriate output type.\n\nThe three original components (JSON Operations, Table Operations, Text\nOperations) remain available as legacy components for backward compatibility\nwith existing flows.\n\"\"\"\n\nimport ast\nimport contextlib\nimport json\nimport re\nfrom typing import TYPE_CHECKING, Any\n\nimport pandas as pd\nfrom json_repair import repair_json\n\nfrom lfx.custom import Component\nfrom lfx.field_typing import RangeSpec\nfrom lfx.inputs import DictInput, SortableListInput, TabInput\nfrom lfx.io import (\n BoolInput,\n DataFrameInput,\n DataInput,\n DropdownInput,\n IntInput,\n MessageTextInput,\n MultilineInput,\n Output,\n StrInput,\n)\nfrom lfx.log.logger import logger\nfrom lfx.schema import Data\nfrom lfx.schema.dataframe import DataFrame\nfrom lfx.schema.dotdict import dotdict\nfrom lfx.schema.message import Message\n\nif TYPE_CHECKING:\n from collections.abc import Callable\n\n# The \"Input Type\" selector tabs. Each value maps a Langflow data type to the\n# operations, input, and output that belong to it.\nINPUT_TYPES = [\"Text\", \"JSON\", \"Table\"]\n\n# Operations grouped by input type, in display order, each with the icon shown\n# in the Operation picker. This is the single source of truth for the picker;\n# update_build_config swaps the picker's options to the selected type's list.\nOPERATIONS_BY_TYPE: dict[str, list[dict[str, str]]] = {\n \"Text\": [\n {\"name\": \"Word Count\", \"icon\": \"hash\"},\n {\"name\": \"Case Conversion\", \"icon\": \"type\"},\n {\"name\": \"Text Replace\", \"icon\": \"replace\"},\n {\"name\": \"Text Extract\", \"icon\": \"search\"},\n {\"name\": \"Text Head\", \"icon\": \"chevron-left\"},\n {\"name\": \"Text Tail\", \"icon\": \"chevron-right\"},\n {\"name\": \"Text Strip\", \"icon\": \"minus\"},\n {\"name\": \"Text Join\", \"icon\": \"link\"},\n {\"name\": \"Text Clean\", \"icon\": \"sparkles\"},\n {\"name\": \"Text to DataFrame\", \"icon\": \"table\"},\n ],\n \"JSON\": [\n {\"name\": \"Select Keys\", \"icon\": \"lasso-select\"},\n {\"name\": \"Literal Eval\", \"icon\": \"braces\"},\n {\"name\": \"Combine\", \"icon\": \"merge\"},\n {\"name\": \"Append or Update\", \"icon\": \"circle-plus\"},\n {\"name\": \"Remove Keys\", \"icon\": \"eraser\"},\n {\"name\": \"Rename Keys\", \"icon\": \"pencil-line\"},\n {\"name\": \"Path Selection\", \"icon\": \"mouse-pointer\"},\n {\"name\": \"JQ Expression\", \"icon\": \"terminal\"},\n ],\n \"Table\": [\n {\"name\": \"Add Column\", \"icon\": \"plus\"},\n {\"name\": \"Concatenate\", \"icon\": \"combine\"},\n {\"name\": \"Drop Column\", \"icon\": \"minus\"},\n {\"name\": \"Filter\", \"icon\": \"filter\"},\n {\"name\": \"Head\", \"icon\": \"arrow-up\"},\n {\"name\": \"Merge\", \"icon\": \"merge\"},\n {\"name\": \"Rename Column\", \"icon\": \"pencil\"},\n {\"name\": \"Replace Value\", \"icon\": \"replace\"},\n {\"name\": \"Select Columns\", \"icon\": \"columns\"},\n {\"name\": \"Sort\", \"icon\": \"arrow-up-down\"},\n {\"name\": \"Tail\", \"icon\": \"arrow-down\"},\n {\"name\": \"Drop Duplicates\", \"icon\": \"copy-x\"},\n ],\n}\n\n# Operation-name sets derived from the picker, used for dispatch and output\n# routing. Keeping them derived from OPERATIONS_BY_TYPE avoids any drift.\nJSON_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"JSON\"]}\nTABLE_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"Table\"]}\nTEXT_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"Text\"]}\n\n# Each input type maps to its main input field and its default output. \"Text\"\n# normally outputs a Message; \"JSON\" a Data; \"Table\" a DataFrame. A few text\n# operations override this (Word Count -> Data, Text to DataFrame -> DataFrame).\nINPUT_TYPE_TO_MAIN_INPUT = {\"Text\": \"text_input\", \"JSON\": \"data\", \"Table\": \"df\"}\n\n# Case conversions for the Text \"Case Conversion\" operation.\nCASE_CONVERTERS: dict[str, Any] = {\n \"uppercase\": str.upper,\n \"lowercase\": str.lower,\n \"title\": str.title,\n \"capitalize\": str.capitalize,\n \"swapcase\": str.swapcase,\n}\n\n\nclass OperationsComponent(Component):\n display_name = \"Data Operations\"\n description = \"Perform operations on Text, JSON, and Tables from a single component.\"\n documentation: str = \"https://docs.langflow.org/components-processing#operations\"\n icon = \"wand-sparkles\"\n name = \"Operations\"\n metadata = {\n \"keywords\": [\n \"operations\",\n \"data operations\",\n \"json\",\n \"json operations\",\n \"table\",\n \"table operations\",\n \"dataframe\",\n \"dataframe operations\",\n \"text\",\n \"text operations\",\n \"select keys\",\n \"literal eval\",\n \"combine\",\n \"append or update\",\n \"remove keys\",\n \"rename keys\",\n \"path selection\",\n \"jq expression\",\n \"parse json\",\n \"add column\",\n \"concatenate\",\n \"drop column\",\n \"filter\",\n \"head\",\n \"merge\",\n \"rename column\",\n \"replace value\",\n \"select columns\",\n \"sort\",\n \"tail\",\n \"drop duplicates\",\n \"word count\",\n \"case conversion\",\n \"text replace\",\n \"text extract\",\n \"text join\",\n \"text clean\",\n \"text to dataframe\",\n \"data manipulation\",\n \"data transformation\",\n ],\n }\n\n # Operation -> operation-specific input fields to reveal when selected.\n OPERATION_FIELDS: dict[str, list[str]] = {\n # JSON\n \"Select Keys\": [\"select_keys_input\"],\n \"Literal Eval\": [],\n \"Combine\": [],\n \"Append or Update\": [\"append_update_data\"],\n \"Remove Keys\": [\"remove_keys_input\"],\n \"Rename Keys\": [\"rename_keys_input\"],\n \"Path Selection\": [\"mapped_json_display\", \"selected_key\"],\n \"JQ Expression\": [\"query\"],\n # Table\n \"Add Column\": [\"new_column_name\", \"new_column_value\"],\n \"Concatenate\": [],\n \"Drop Column\": [\"column_name\"],\n \"Filter\": [\"column_name\", \"filter_value\", \"filter_operator\"],\n \"Head\": [\"num_rows\"],\n \"Merge\": [\"left_dataframe\", \"right_dataframe\", \"merge_on_column\", \"merge_how\"],\n \"Rename Column\": [\"column_name\", \"new_column_name\"],\n \"Replace Value\": [\"column_name\", \"replace_value\", \"replacement_value\"],\n \"Select Columns\": [\"columns_to_select\"],\n \"Sort\": [\"column_name\", \"ascending\"],\n \"Tail\": [\"num_rows\"],\n \"Drop Duplicates\": [\"column_name\"],\n # Text\n \"Word Count\": [\"count_words\", \"count_characters\", \"count_lines\"],\n \"Case Conversion\": [\"case_type\"],\n \"Text Replace\": [\"search_pattern\", \"replacement_text\", \"use_regex\"],\n \"Text Extract\": [\"extract_pattern\", \"max_matches\"],\n \"Text Head\": [\"head_characters\"],\n \"Text Tail\": [\"tail_characters\"],\n \"Text Strip\": [\"strip_mode\", \"strip_characters\"],\n \"Text Join\": [\"text_input_2\"],\n \"Text Clean\": [\"remove_extra_spaces\", \"remove_special_chars\", \"remove_empty_lines\"],\n \"Text to DataFrame\": [\"table_separator\", \"has_header\"],\n }\n\n # The three main inputs (one per data type). They are never treated as\n # operation-specific fields; the input-type selector toggles them.\n MAIN_INPUTS = (\"text_input\", \"data\", \"df\")\n\n # Every operation-specific field (union of all the lists above), used to\n # hide and reset fields whenever the input type or operation changes.\n ALL_OPERATION_FIELDS: list[str] = [\n # JSON\n \"select_keys_input\",\n \"append_update_data\",\n \"remove_keys_input\",\n \"rename_keys_input\",\n \"mapped_json_display\",\n \"selected_key\",\n \"query\",\n # Table\n \"column_name\",\n \"filter_value\",\n \"filter_operator\",\n \"ascending\",\n \"new_column_name\",\n \"new_column_value\",\n \"columns_to_select\",\n \"num_rows\",\n \"replace_value\",\n \"replacement_value\",\n \"left_dataframe\",\n \"right_dataframe\",\n \"merge_on_column\",\n \"merge_how\",\n # Text\n \"table_separator\",\n \"has_header\",\n \"count_words\",\n \"count_characters\",\n \"count_lines\",\n \"case_type\",\n \"use_regex\",\n \"search_pattern\",\n \"replacement_text\",\n \"extract_pattern\",\n \"max_matches\",\n \"head_characters\",\n \"tail_characters\",\n \"strip_mode\",\n \"strip_characters\",\n \"text_input_2\",\n \"remove_extra_spaces\",\n \"remove_special_chars\",\n \"remove_empty_lines\",\n ]\n\n # Defaults applied to the JSON operation fields when the operation changes,\n # mirroring the JSON Operations component's reset behavior.\n OPERATION_FIELD_DEFAULTS: dict[str, Any] = {\n \"select_keys_input\": [],\n \"append_update_data\": {\"key\": \"value\"},\n \"remove_keys_input\": [],\n \"rename_keys_input\": {\"old_key\": \"new_key\"},\n \"mapped_json_display\": \"\",\n \"selected_key\": None,\n \"query\": \"\",\n }\n\n inputs = [\n # --- Input type selector: drives operations, input, and output ---\n TabInput(\n name=\"input_type\",\n display_name=\"Input Type\",\n options=INPUT_TYPES,\n value=\"Text\",\n info=\"Select the type of input to operate on.\",\n real_time_refresh=True,\n ),\n # --- Main inputs: one per data type, shown contextually ---\n MultilineInput(\n name=\"text_input\",\n display_name=\"Text\",\n info=\"The input text to process.\",\n show=True,\n ),\n DataInput(\n name=\"data\",\n display_name=\"JSON\",\n info=\"The JSON / Data object to operate on.\",\n is_list=True,\n show=False,\n ),\n DataFrameInput(\n name=\"df\",\n display_name=\"Table\",\n info=\"The input Table to operate on. Connect multiple Tables for merge or concatenate operations.\",\n is_list=True,\n show=False,\n ),\n # --- Operation picker (options are filtered by Input Type) ---\n SortableListInput(\n name=\"operation\",\n display_name=\"Operation\",\n placeholder=\"Select Operation\",\n info=\"Select the operation to perform. The matching fields and output appear once you choose one.\",\n options=OPERATIONS_BY_TYPE[\"Text\"],\n real_time_refresh=True,\n limit=1,\n ),\n # --- JSON operation fields ---\n MessageTextInput(\n name=\"select_keys_input\",\n display_name=\"Select Keys\",\n info=\"List of keys to select from the data. Only top-level keys can be selected.\",\n show=False,\n is_list=True,\n value=[],\n ),\n DictInput(\n name=\"append_update_data\",\n display_name=\"Append or Update\",\n info=\"Data to append or update the existing data with. Only top-level keys are checked.\",\n show=False,\n value={\"key\": \"value\"},\n is_list=True,\n ),\n MessageTextInput(\n name=\"remove_keys_input\",\n display_name=\"Remove Keys\",\n info=\"List of keys to remove from the data.\",\n show=False,\n is_list=True,\n value=[],\n ),\n DictInput(\n name=\"rename_keys_input\",\n display_name=\"Rename Keys\",\n info=\"List of keys to rename in the data.\",\n show=False,\n is_list=True,\n value={\"old_key\": \"new_key\"},\n ),\n MultilineInput(\n name=\"mapped_json_display\",\n display_name=\"JSON to Map\",\n info=\"Paste or preview your JSON here to explore its structure and select a path for extraction.\",\n required=False,\n refresh_button=True,\n real_time_refresh=True,\n placeholder=\"Add a JSON example.\",\n show=False,\n ),\n DropdownInput(\n name=\"selected_key\",\n display_name=\"Select Path\",\n options=[],\n required=False,\n dynamic=True,\n show=False,\n value=None,\n ),\n MessageTextInput(\n name=\"query\",\n display_name=\"JQ Expression\",\n info=\"JSON Query to filter the data. Used by Path Selection and JQ Expression operations.\",\n placeholder=\"e.g., .properties.id\",\n show=False,\n ),\n # --- Table operation fields ---\n StrInput(\n name=\"column_name\",\n display_name=\"Column Name\",\n info=\"The column name to use for the operation.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"filter_value\",\n display_name=\"Filter Value\",\n info=\"The value to filter rows by.\",\n dynamic=True,\n show=False,\n ),\n DropdownInput(\n name=\"filter_operator\",\n display_name=\"Filter Operator\",\n options=[\n \"equals\",\n \"not equals\",\n \"contains\",\n \"not contains\",\n \"starts with\",\n \"ends with\",\n \"greater than\",\n \"less than\",\n ],\n value=\"equals\",\n info=\"The operator to apply for filtering rows.\",\n advanced=False,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"ascending\",\n display_name=\"Sort Ascending\",\n info=\"Whether to sort in ascending order.\",\n dynamic=True,\n show=False,\n value=True,\n ),\n StrInput(\n name=\"new_column_name\",\n display_name=\"New Column Name\",\n info=\"The new column name when renaming or adding a column.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"new_column_value\",\n display_name=\"New Column Value\",\n info=\"The value to populate the new column with.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"columns_to_select\",\n display_name=\"Columns to Select\",\n dynamic=True,\n is_list=True,\n show=False,\n ),\n IntInput(\n name=\"num_rows\",\n display_name=\"Number of Rows\",\n info=\"Number of rows to return (for head/tail).\",\n dynamic=True,\n show=False,\n value=5,\n ),\n MessageTextInput(\n name=\"replace_value\",\n display_name=\"Value to Replace\",\n info=\"The value to replace in the column.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"replacement_value\",\n display_name=\"Replacement Value\",\n info=\"The value to replace with.\",\n dynamic=True,\n show=False,\n ),\n DataFrameInput(\n name=\"left_dataframe\",\n display_name=\"Left Table\",\n info=\"The left (primary) Table for merge operations. \"\n \"In a left merge, all rows from this table are preserved.\",\n dynamic=True,\n show=False,\n ),\n DataFrameInput(\n name=\"right_dataframe\",\n display_name=\"Right Table\",\n info=\"The right (secondary) Table for merge operations. \"\n \"In a right merge, all rows from this table are preserved.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"merge_on_column\",\n display_name=\"Merge On Column\",\n info=\"The column name to merge Tables on. Must exist in both Tables.\",\n dynamic=True,\n show=False,\n ),\n DropdownInput(\n name=\"merge_how\",\n display_name=\"Merge Type\",\n options=[\"inner\", \"outer\", \"left\", \"right\"],\n value=\"inner\",\n info=\"Type of merge: inner (intersection), outer (union), left, or right.\",\n dynamic=True,\n show=False,\n ),\n # --- Text operation fields ---\n StrInput(\n name=\"table_separator\",\n display_name=\"Table Separator\",\n info=\"Separator used in the table (default: '|').\",\n value=\"|\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"has_header\",\n display_name=\"Has Header\",\n info=\"Whether the table has a header row.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_words\",\n display_name=\"Count Words\",\n info=\"Include word count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_characters\",\n display_name=\"Count Characters\",\n info=\"Include character count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_lines\",\n display_name=\"Count Lines\",\n info=\"Include line count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n DropdownInput(\n name=\"case_type\",\n display_name=\"Case Type\",\n options=[\"uppercase\", \"lowercase\", \"title\", \"capitalize\", \"swapcase\"],\n value=\"lowercase\",\n info=\"Type of case conversion to apply.\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"use_regex\",\n display_name=\"Use Regex\",\n info=\"Whether to treat search pattern as regex.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"search_pattern\",\n display_name=\"Search Pattern\",\n info=\"Text pattern to search for (supports regex).\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"replacement_text\",\n display_name=\"Replacement Text\",\n info=\"Text to replace the search pattern with.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"extract_pattern\",\n display_name=\"Extract Pattern\",\n info=\"Regex pattern to extract from text.\",\n dynamic=True,\n show=False,\n ),\n IntInput(\n name=\"max_matches\",\n display_name=\"Max Matches\",\n info=\"Maximum number of matches to extract.\",\n value=10,\n dynamic=True,\n show=False,\n ),\n IntInput(\n name=\"head_characters\",\n display_name=\"Characters from Start\",\n info=\"Number of characters to extract from the beginning of text. Must be non-negative.\",\n value=100,\n dynamic=True,\n show=False,\n range_spec=RangeSpec(min=0, max=1000000, step=1, step_type=\"int\"),\n ),\n IntInput(\n name=\"tail_characters\",\n display_name=\"Characters from End\",\n info=\"Number of characters to extract from the end of text. Must be non-negative.\",\n value=100,\n dynamic=True,\n show=False,\n range_spec=RangeSpec(min=0, max=1000000, step=1, step_type=\"int\"),\n ),\n DropdownInput(\n name=\"strip_mode\",\n display_name=\"Strip Mode\",\n options=[\"both\", \"left\", \"right\"],\n value=\"both\",\n info=\"Which sides to strip whitespace from.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"strip_characters\",\n display_name=\"Characters to Strip\",\n info=\"Specific characters to remove (leave empty for whitespace).\",\n value=\"\",\n dynamic=True,\n show=False,\n ),\n MultilineInput(\n name=\"text_input_2\",\n display_name=\"Second Text Input\",\n info=\"Second text to join with the first text.\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_extra_spaces\",\n display_name=\"Remove Extra Spaces\",\n info=\"Remove multiple consecutive spaces.\",\n value=True,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_special_chars\",\n display_name=\"Remove Special Characters\",\n info=\"Remove special characters except alphanumeric and spaces.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_empty_lines\",\n display_name=\"Remove Empty Lines\",\n info=\"Remove empty lines from text.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n ]\n\n # Default output matches the default Input Type (\"Text\" -> Message).\n # update_outputs / update_frontend_node narrow it to the selected type and\n # operation.\n outputs = [Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\")]\n\n # ------------------------------------------------------------------\n # Operation routing helpers\n # ------------------------------------------------------------------\n @staticmethod\n def _extract_operation_name(field_value: Any) -> str:\n \"\"\"Extract the operation name from a SortableListInput value.\"\"\"\n if isinstance(field_value, list) and len(field_value) > 0 and isinstance(field_value[0], dict):\n return field_value[0].get(\"name\", \"\")\n if isinstance(field_value, str):\n return field_value\n return \"\"\n\n def _operation_name(self) -> str:\n \"\"\"Get the currently selected operation name.\"\"\"\n return self._extract_operation_name(getattr(self, \"operation\", []))\n\n @staticmethod\n def _default_output_for_type(input_type: str) -> Output:\n \"\"\"Return the output advertised for an input type when no operation is selected yet.\"\"\"\n if input_type == \"JSON\":\n return Output(display_name=\"JSON\", name=\"data_output\", method=\"as_data\")\n if input_type == \"Table\":\n return Output(display_name=\"Table\", name=\"dataframe_output\", method=\"as_dataframe\")\n return Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\")\n\n # ------------------------------------------------------------------\n # Dynamic UI\n # ------------------------------------------------------------------\n def _reset_operation_fields(self, build_config: dotdict) -> None:\n \"\"\"Hide every operation-specific field and restore its default value.\"\"\"\n for field in self.ALL_OPERATION_FIELDS:\n if field in build_config:\n build_config[field][\"show\"] = False\n if field in self.OPERATION_FIELD_DEFAULTS:\n build_config[field][\"value\"] = self.OPERATION_FIELD_DEFAULTS[field]\n\n def _show_main_input(self, build_config: dotdict, input_type: str, operation: str) -> None:\n \"\"\"Show only the main input that matches the input type; hide the others.\"\"\"\n for inp in self.MAIN_INPUTS:\n if inp in build_config:\n build_config[inp][\"show\"] = False\n build_config[inp][\"required\"] = False\n\n main_input = INPUT_TYPE_TO_MAIN_INPUT.get(input_type)\n if main_input and main_input in build_config:\n build_config[main_input][\"show\"] = True\n build_config[main_input][\"required\"] = True\n # The JSON \"Combine\" operation consumes a list of Data objects.\n if main_input == \"data\":\n build_config[\"data\"][\"is_list\"] = operation == \"Combine\"\n\n def update_build_config(self, build_config: dotdict, field_value: Any, field_name: str | None = None) -> dotdict:\n # Path Selection: refresh the available JSON paths from the pasted JSON.\n if field_name == \"mapped_json_display\":\n try:\n parsed_json = json.loads(field_value)\n keys = self.extract_all_paths(parsed_json)\n build_config[\"selected_key\"][\"options\"] = keys\n build_config[\"selected_key\"][\"show\"] = True\n except (json.JSONDecodeError, TypeError, ValueError) as e:\n logger.error(f\"Error parsing mapped JSON: {e}\")\n build_config[\"selected_key\"][\"show\"] = False\n return build_config\n\n # Input type changed: swap the operation list, clear the selection, and\n # show only the matching input. No operation-specific fields are shown\n # until an operation is picked.\n if field_name == \"input_type\":\n input_type = field_value if field_value in OPERATIONS_BY_TYPE else \"Text\"\n build_config[\"operation\"][\"options\"] = OPERATIONS_BY_TYPE[input_type]\n build_config[\"operation\"][\"value\"] = []\n self._reset_operation_fields(build_config)\n self._show_main_input(build_config, input_type, operation=\"\")\n return build_config\n\n # Operation changed: reset fields, show the input for the current type,\n # then reveal the operation-specific fields.\n if field_name == \"operation\":\n operation = self._extract_operation_name(field_value)\n self._reset_operation_fields(build_config)\n\n input_type = build_config.get(\"input_type\", {}).get(\"value\", \"Text\")\n self._show_main_input(build_config, input_type, operation)\n\n for field in self.OPERATION_FIELDS.get(operation, []):\n if field in build_config:\n build_config[field][\"show\"] = True\n\n return build_config\n\n return build_config\n\n def update_outputs(self, frontend_node: dict, field_name: str, field_value: Any) -> dict:\n \"\"\"Create the output(s) appropriate to the selected input type and operation.\"\"\"\n if field_name == \"input_type\":\n # Switching type clears the operation; advertise the type's default.\n input_type = field_value if field_value in OPERATIONS_BY_TYPE else \"Text\"\n frontend_node[\"outputs\"] = [self._default_output_for_type(input_type)]\n return frontend_node\n\n template = frontend_node.get(\"template\", {})\n input_type = template.get(\"input_type\", {}).get(\"value\", \"Text\")\n\n if field_name == \"operation\":\n operation = self._extract_operation_name(field_value)\n else:\n # Any other refresh (e.g. Path Selection's \"JSON to Map\" field)\n # reaches here on a freshly rebuilt node whose outputs were reset\n # to the class default (Message). Re-derive the output from the\n # saved operation so the refresh doesn't swap the real output type.\n operation = self._extract_operation_name(template.get(\"operation\", {}).get(\"value\", []))\n\n if not operation:\n # No operation selected: fall back to the input type's default output.\n frontend_node[\"outputs\"] = [self._default_output_for_type(input_type)]\n return frontend_node\n\n frontend_node[\"outputs\"] = []\n if operation in JSON_OPERATIONS or operation == \"Word Count\":\n frontend_node[\"outputs\"].append(Output(display_name=\"JSON\", name=\"data_output\", method=\"as_data\"))\n elif operation in TABLE_OPERATIONS or operation == \"Text to DataFrame\":\n frontend_node[\"outputs\"].append(\n Output(display_name=\"Table\", name=\"dataframe_output\", method=\"as_dataframe\")\n )\n elif operation == \"Text Join\":\n frontend_node[\"outputs\"].append(Output(display_name=\"Text\", name=\"text_output\", method=\"as_text\"))\n frontend_node[\"outputs\"].append(Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\"))\n else:\n frontend_node[\"outputs\"].append(Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\"))\n\n return frontend_node\n\n async def update_frontend_node(self, new_frontend_node: dict, current_frontend_node: dict) -> dict:\n \"\"\"Keep the operation options and outputs in sync with the saved input type on load.\"\"\"\n await super().update_frontend_node(new_frontend_node, current_frontend_node)\n\n template = new_frontend_node.get(\"template\", {})\n input_type = template.get(\"input_type\", {}).get(\"value\", \"Text\")\n if input_type not in OPERATIONS_BY_TYPE:\n input_type = \"Text\"\n\n # Filter the operation picker to the saved input type.\n if \"operation\" in template:\n template[\"operation\"][\"options\"] = OPERATIONS_BY_TYPE[input_type]\n\n # Re-derive the outputs from the saved input type + operation.\n operation_value = template.get(\"operation\", {}).get(\"value\", [])\n if self._extract_operation_name(operation_value):\n self.update_outputs(new_frontend_node, \"operation\", operation_value)\n else:\n self.update_outputs(new_frontend_node, \"input_type\", input_type)\n\n return new_frontend_node\n\n # ==================================================================\n # Output methods (referenced by update_outputs)\n # ==================================================================\n def as_data(self) -> Data:\n \"\"\"JSON-typed output: JSON operations and Word Count.\"\"\"\n operation = self._operation_name()\n if operation in JSON_OPERATIONS:\n handler = self._json_handlers().get(operation)\n if handler:\n try:\n return handler()\n except Exception as e:\n logger.error(f\"Error executing {operation}: {e!s}\")\n raise\n if operation == \"Word Count\":\n return self._word_count_data()\n return Data(data={})\n\n def as_dataframe(self) -> DataFrame:\n \"\"\"Table-typed output: Table operations and Text to DataFrame.\"\"\"\n operation = self._operation_name()\n if operation in TABLE_OPERATIONS:\n return self._run_table_operation(operation)\n if operation == \"Text to DataFrame\":\n return self._text_to_dataframe(getattr(self, \"text_input\", \"\") or \"\")\n return DataFrame(pd.DataFrame())\n\n def as_message(self) -> Message:\n \"\"\"Message-typed output: generic text operations (and Text Join).\"\"\"\n return Message(text=self._format_result_as_text(self._run_text_operation()))\n\n def as_text(self) -> Message:\n \"\"\"Text output for the Text Join operation.\"\"\"\n return self.as_message()\n\n # ==================================================================\n # JSON operations\n # ==================================================================\n @staticmethod\n def extract_all_paths(obj, path=\"\"):\n paths = []\n if isinstance(obj, dict):\n for k, v in obj.items():\n new_path = f\"{path}.{k}\" if path else f\".{k}\"\n paths.append(new_path)\n paths.extend(OperationsComponent.extract_all_paths(v, new_path))\n elif isinstance(obj, list) and obj:\n new_path = f\"{path}[0]\"\n paths.append(new_path)\n paths.extend(OperationsComponent.extract_all_paths(obj[0], new_path))\n return paths\n\n @staticmethod\n def remove_keys_recursive(obj, keys_to_remove):\n if isinstance(obj, dict):\n return {\n k: OperationsComponent.remove_keys_recursive(v, keys_to_remove)\n for k, v in obj.items()\n if k not in keys_to_remove\n }\n if isinstance(obj, list):\n return [OperationsComponent.remove_keys_recursive(item, keys_to_remove) for item in obj]\n return obj\n\n @staticmethod\n def rename_keys_recursive(obj, rename_map):\n if isinstance(obj, dict):\n return {\n rename_map.get(k, k): OperationsComponent.rename_keys_recursive(v, rename_map) for k, v in obj.items()\n }\n if isinstance(obj, list):\n return [OperationsComponent.rename_keys_recursive(item, rename_map) for item in obj]\n return obj\n\n def _json_handlers(self) -> \"dict[str, Callable[[], Data]]\":\n return {\n \"Select Keys\": self.select_keys,\n \"Literal Eval\": self.evaluate_data,\n \"Combine\": self.combine_data,\n \"Append or Update\": self.append_update,\n \"Remove Keys\": self.remove_keys,\n \"Rename Keys\": self.rename_keys,\n \"Path Selection\": self.json_path,\n \"JQ Expression\": self.json_query,\n }\n\n def get_data_dict(self) -> dict:\n \"\"\"Extract data dictionary from Data object.\"\"\"\n data = self.data[0] if isinstance(self.data, list) and len(self.data) == 1 else self.data\n return data.model_dump()\n\n def get_normalized_data(self) -> dict:\n \"\"\"Get normalized data dictionary, handling the 'data' key if present.\"\"\"\n data_dict = self.get_data_dict()\n return data_dict.get(\"data\", data_dict)\n\n def data_is_list(self) -> bool:\n \"\"\"Check if data contains multiple items.\"\"\"\n return isinstance(self.data, list) and len(self.data) > 1\n\n def validate_single_data(self, operation: str) -> None:\n \"\"\"Validate that the operation is being performed on a single data object.\"\"\"\n if self.data_is_list():\n msg = f\"{operation} operation is not supported for multiple data objects.\"\n raise ValueError(msg)\n\n def select_keys(self) -> Data:\n \"\"\"Select specific keys from the data dictionary.\"\"\"\n self.validate_single_data(\"Select Keys\")\n data_dict = self.get_normalized_data()\n filter_criteria: list[str] = self.select_keys_input\n\n if len(filter_criteria) == 1 and filter_criteria[0] == \"data\":\n filtered = data_dict[\"data\"]\n else:\n if not all(key in data_dict for key in filter_criteria):\n msg = f\"Select key not found in data. Available keys: {list(data_dict.keys())}\"\n raise ValueError(msg)\n filtered = {key: value for key, value in data_dict.items() if key in filter_criteria}\n\n return Data(data=filtered)\n\n def remove_keys(self) -> Data:\n \"\"\"Remove specified keys from the data dictionary, recursively.\"\"\"\n self.validate_single_data(\"Remove Keys\")\n data_dict = self.get_normalized_data()\n remove_keys_input: list[str] = self.remove_keys_input\n filtered = OperationsComponent.remove_keys_recursive(data_dict, set(remove_keys_input))\n return Data(data=filtered)\n\n def rename_keys(self) -> Data:\n \"\"\"Rename keys in the data dictionary, recursively.\"\"\"\n self.validate_single_data(\"Rename Keys\")\n data_dict = self.get_normalized_data()\n rename_keys_input: dict[str, str] = self.rename_keys_input\n renamed = OperationsComponent.rename_keys_recursive(data_dict, rename_keys_input)\n return Data(data=renamed)\n\n def recursive_eval(self, data: Any) -> Any:\n \"\"\"Recursively evaluate string values that look like Python literals.\"\"\"\n if isinstance(data, dict):\n return {k: self.recursive_eval(v) for k, v in data.items()}\n if isinstance(data, list):\n return [self.recursive_eval(item) for item in data]\n if isinstance(data, str):\n try:\n if (\n data.strip().startswith((\"{\", \"[\", \"(\", \"'\", '\"'))\n or data.strip().lower() in (\"true\", \"false\", \"none\")\n or data.strip().replace(\".\", \"\").isdigit()\n ):\n return ast.literal_eval(data)\n except (ValueError, SyntaxError, TypeError, MemoryError):\n return data\n else:\n return data\n return data\n\n def evaluate_data(self) -> Data:\n \"\"\"Evaluate string values in the data dictionary.\"\"\"\n self.validate_single_data(\"Literal Eval\")\n logger.info(\"evaluating data\")\n return Data(**self.recursive_eval(self.get_data_dict()))\n\n def combine_data(self) -> Data:\n \"\"\"Combine multiple data objects into one.\"\"\"\n logger.info(\"combining data\")\n if not self.data_is_list():\n return self.data[0] if self.data else Data(data={})\n\n data_dicts = [data.model_dump().get(\"data\", data.model_dump()) for data in self.data]\n combined_data: dict[str, Any] = {}\n\n for data_dict in data_dicts:\n for key, value in data_dict.items():\n if key not in combined_data:\n combined_data[key] = value\n elif isinstance(combined_data[key], list):\n if isinstance(value, list):\n combined_data[key].extend(value)\n else:\n combined_data[key].append(value)\n else:\n combined_data[key] = (\n [combined_data[key], value] if not isinstance(value, list) else [combined_data[key], *value]\n )\n\n return Data(**combined_data)\n\n def append_update(self) -> Data:\n \"\"\"Append or update the data with new key-value pairs.\"\"\"\n self.validate_single_data(\"Append or Update\")\n data_filtered = self.get_normalized_data()\n for key, value in self.append_update_data.items():\n data_filtered[key] = value\n return Data(**data_filtered)\n\n def json_path(self) -> Data:\n \"\"\"Extract a value from the data using the selected JQ path.\"\"\"\n try:\n import jq\n except ImportError:\n msg = \"jq is required for Path Selection. Install with: pip install jq\"\n raise ImportError(msg) from None\n\n try:\n if not self.data or not self.selected_key:\n msg = \"Missing input data or selected key.\"\n raise ValueError(msg)\n input_payload = self.data[0].data if isinstance(self.data, list) else self.data.data\n compiled = jq.compile(self.selected_key)\n result = compiled.input(input_payload).first()\n if isinstance(result, dict):\n return Data(data=result)\n return Data(data={\"result\": result})\n except (ValueError, TypeError, KeyError) as e:\n self.status = f\"Error: {e!s}\"\n self.log(self.status)\n return Data(data={\"error\": str(e)})\n\n def json_query(self) -> Data:\n \"\"\"Run a JQ expression against the data.\"\"\"\n try:\n import jq\n except ImportError:\n msg = \"jq is required for JQ Expression. Install with: pip install jq\"\n raise ImportError(msg) from None\n\n if not self.query or not self.query.strip():\n msg = \"JSON Query is required and cannot be blank.\"\n raise ValueError(msg)\n raw_data = self.get_data_dict()\n try:\n input_str = json.dumps(raw_data)\n repaired = repair_json(input_str)\n data_json = json.loads(repaired)\n jq_input = data_json[\"data\"] if isinstance(data_json, dict) and \"data\" in data_json else data_json\n results = jq.compile(self.query).input(jq_input).all()\n if not results:\n msg = \"No result from JSON query.\"\n raise ValueError(msg)\n result = results[0] if len(results) == 1 else results\n if result is None or result == \"None\":\n msg = \"JSON query returned null/None. Check if the path exists in your data.\"\n raise ValueError(msg)\n if isinstance(result, dict):\n return Data(data=result)\n return Data(data={\"result\": result})\n except (ValueError, TypeError, KeyError, json.JSONDecodeError) as e:\n logger.error(f\"JSON Query failed: {e}\")\n msg = f\"JSON Query error: {e}\"\n raise ValueError(msg) from e\n\n # ==================================================================\n # Table operations\n # ==================================================================\n def _get_primary_dataframe(self) -> DataFrame:\n \"\"\"Get the first DataFrame from input (handles both single and list inputs).\"\"\"\n if isinstance(self.df, list):\n return self.df[0].copy() if self.df else DataFrame()\n return self.df.copy()\n\n def _run_table_operation(self, operation: str) -> DataFrame:\n # Merge and Concatenate use their own inputs, not the primary df.\n if operation == \"Merge\":\n return self.merge_dataframes()\n if operation == \"Concatenate\":\n return self.concatenate_dataframes()\n\n df_copy = self._get_primary_dataframe()\n table_handlers = {\n \"Filter\": self.filter_rows_by_value,\n \"Sort\": self.sort_by_column,\n \"Drop Column\": self.drop_column,\n \"Rename Column\": self.rename_column,\n \"Add Column\": self.add_column,\n \"Select Columns\": self.select_columns,\n \"Head\": self.head,\n \"Tail\": self.tail,\n \"Replace Value\": self.replace_values,\n \"Drop Duplicates\": self.drop_duplicates,\n }\n handler = table_handlers.get(operation)\n if handler is None:\n msg = f\"Unsupported operation: {operation}\"\n logger.error(msg)\n raise ValueError(msg)\n return handler(df_copy)\n\n def filter_rows_by_value(self, df: DataFrame) -> DataFrame:\n column = df[self.column_name]\n filter_value = self.filter_value\n operator = getattr(self, \"filter_operator\", \"equals\")\n\n if operator == \"equals\":\n mask = column == filter_value\n elif operator == \"not equals\":\n mask = column != filter_value\n elif operator == \"contains\":\n mask = column.astype(str).str.contains(str(filter_value), na=False)\n elif operator == \"not contains\":\n mask = ~column.astype(str).str.contains(str(filter_value), na=False)\n elif operator == \"starts with\":\n mask = column.astype(str).str.startswith(str(filter_value), na=False)\n elif operator == \"ends with\":\n mask = column.astype(str).str.endswith(str(filter_value), na=False)\n elif operator == \"greater than\":\n try:\n numeric_value = pd.to_numeric(filter_value)\n mask = column > numeric_value\n except (ValueError, TypeError):\n mask = column.astype(str) > str(filter_value)\n elif operator == \"less than\":\n try:\n numeric_value = pd.to_numeric(filter_value)\n mask = column < numeric_value\n except (ValueError, TypeError):\n mask = column.astype(str) < str(filter_value)\n else:\n mask = column == filter_value\n\n return DataFrame(df[mask])\n\n def sort_by_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.sort_values(by=self.column_name, ascending=self.ascending))\n\n def drop_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.drop(columns=[self.column_name]))\n\n def rename_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.rename(columns={self.column_name: self.new_column_name}))\n\n def add_column(self, df: DataFrame) -> DataFrame:\n df[self.new_column_name] = [self.new_column_value] * len(df)\n return DataFrame(df)\n\n def select_columns(self, df: DataFrame) -> DataFrame:\n columns = [col.strip() for col in self.columns_to_select]\n return DataFrame(df[columns])\n\n def head(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.head(self.num_rows))\n\n def tail(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.tail(self.num_rows))\n\n def replace_values(self, df: DataFrame) -> DataFrame:\n df[self.column_name] = df[self.column_name].replace(self.replace_value, self.replacement_value)\n return DataFrame(df)\n\n def drop_duplicates(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.drop_duplicates(subset=self.column_name))\n\n def concatenate_dataframes(self) -> DataFrame:\n \"\"\"Concatenate multiple DataFrames vertically (stack rows).\"\"\"\n if not isinstance(self.df, list) or len(self.df) == 0:\n return self.df.copy() if self.df is not None else DataFrame()\n\n if len(self.df) == 1:\n return self.df[0].copy()\n\n concatenated = pd.concat(self.df, ignore_index=True)\n return DataFrame(concatenated)\n\n def merge_dataframes(self) -> DataFrame:\n \"\"\"Merge two DataFrames based on a common column (join operation).\"\"\"\n left_df = getattr(self, \"left_dataframe\", None)\n right_df = getattr(self, \"right_dataframe\", None)\n\n if left_df is None:\n return DataFrame()\n if right_df is None:\n return left_df.copy()\n\n df_left = left_df.copy()\n df_right = right_df.copy()\n\n merge_on = getattr(self, \"merge_on_column\", None)\n merge_how = getattr(self, \"merge_how\", \"inner\")\n\n if merge_on:\n if merge_on not in df_left.columns:\n msg = f\"Column '{merge_on}' not found in left DataFrame. Available: {list(df_left.columns)}\"\n raise ValueError(msg)\n if merge_on not in df_right.columns:\n msg = f\"Column '{merge_on}' not found in right DataFrame. Available: {list(df_right.columns)}\"\n raise ValueError(msg)\n merged = df_left.merge(df_right, on=merge_on, how=merge_how, suffixes=(\"\", \"_right\"))\n else:\n merged = df_left.merge(df_right, left_index=True, right_index=True, how=merge_how, suffixes=(\"\", \"_right\"))\n\n cols_to_drop = []\n for col in merged.columns:\n if col.endswith(\"_right\"):\n original_col = col[:-6]\n if original_col in merged.columns:\n merged[original_col] = merged[original_col].combine_first(merged[col])\n cols_to_drop.append(col)\n\n if cols_to_drop:\n merged = merged.drop(columns=cols_to_drop)\n\n return DataFrame(merged)\n\n # ==================================================================\n # Text operations\n # ==================================================================\n def _run_text_operation(self) -> Any:\n \"\"\"Process text based on the selected operation (Message/Text outputs).\"\"\"\n text = getattr(self, \"text_input\", \"\")\n operation = self._operation_name()\n\n # Allow empty text for Text Join (second input may have content).\n if not text and operation != \"Text Join\":\n return None\n\n text_handlers = {\n \"Case Conversion\": self._case_conversion,\n \"Text Replace\": self._text_replace,\n \"Text Extract\": self._text_extract,\n \"Text Head\": self._text_head,\n \"Text Tail\": self._text_tail,\n \"Text Strip\": self._text_strip,\n \"Text Join\": self._text_join,\n \"Text Clean\": self._text_clean,\n }\n handler = text_handlers.get(operation)\n if handler:\n return handler(text)\n return text\n\n def _word_count_data(self) -> Data:\n \"\"\"Word Count operation result as a Data object.\"\"\"\n result = self._word_count(getattr(self, \"text_input\", \"\") or \"\")\n return Data(data=result)\n\n def _word_count(self, text: str) -> dict[str, Any]:\n \"\"\"Count words, characters, and lines in text.\"\"\"\n result: dict[str, Any] = {}\n text_str = str(text) if text else \"\"\n is_empty = not text_str or not text_str.strip()\n\n if getattr(self, \"count_words\", True):\n if is_empty:\n result[\"word_count\"] = 0\n result[\"unique_words\"] = 0\n else:\n words = text_str.split()\n result[\"word_count\"] = len(words)\n result[\"unique_words\"] = len(set(words))\n\n if getattr(self, \"count_characters\", True):\n if is_empty:\n result[\"character_count\"] = 0\n result[\"character_count_no_spaces\"] = 0\n else:\n result[\"character_count\"] = len(text_str)\n result[\"character_count_no_spaces\"] = len(text_str.replace(\" \", \"\"))\n\n if getattr(self, \"count_lines\", True):\n if is_empty:\n result[\"line_count\"] = 0\n result[\"non_empty_lines\"] = 0\n else:\n lines = text_str.split(\"\\n\")\n result[\"line_count\"] = len(lines)\n result[\"non_empty_lines\"] = len([line for line in lines if line.strip()])\n\n return result\n\n def _text_to_dataframe(self, text: str) -> DataFrame:\n \"\"\"Convert markdown-style table text to a DataFrame.\"\"\"\n lines = [line.strip() for line in text.strip().split(\"\\n\") if line.strip()]\n if not lines:\n return DataFrame(pd.DataFrame())\n\n separator = getattr(self, \"table_separator\", \"|\")\n has_header = getattr(self, \"has_header\", True)\n\n rows = self._parse_table_rows(lines, separator)\n if not rows:\n return DataFrame(pd.DataFrame())\n\n df = self._create_dataframe(rows, has_header=has_header)\n self._convert_numeric_columns(df)\n self.log(f\"Converted text to DataFrame: {len(df)} rows, {len(df.columns)} columns\")\n return DataFrame(df)\n\n def _parse_table_rows(self, lines: list[str], separator: str) -> list[list[str]]:\n rows = []\n for line in lines:\n cleaned_line = line.strip(separator)\n cells = [cell.strip() for cell in cleaned_line.split(separator)]\n rows.append(cells)\n return rows\n\n def _create_dataframe(self, rows: list[list[str]], *, has_header: bool) -> pd.DataFrame:\n if has_header and len(rows) > 1:\n header = rows[0]\n data_rows = rows[1:]\n header_col_count = len(header)\n for i, row in enumerate(data_rows):\n row_col_count = len(row)\n if row_col_count != header_col_count:\n msg = (\n f\"Header mismatch: {header_col_count} column(s) in header vs \"\n f\"{row_col_count} column(s) in data row {i + 1}. \"\n \"Please ensure the header has the same number of columns as your data.\"\n )\n raise ValueError(msg)\n return pd.DataFrame(data_rows, columns=header)\n\n max_cols = max(len(row) for row in rows) if rows else 0\n columns = [f\"col_{i}\" for i in range(max_cols)]\n return pd.DataFrame(rows, columns=columns)\n\n def _convert_numeric_columns(self, df: pd.DataFrame) -> None:\n for col in df.columns:\n with contextlib.suppress(ValueError, TypeError):\n df[col] = pd.to_numeric(df[col])\n\n def _case_conversion(self, text: str) -> str:\n case_type = getattr(self, \"case_type\", \"lowercase\")\n converter = CASE_CONVERTERS.get(case_type)\n return converter(text) if converter else text\n\n def _text_replace(self, text: str) -> str:\n search_pattern = getattr(self, \"search_pattern\", \"\")\n if not search_pattern:\n return text\n replacement_text = getattr(self, \"replacement_text\", \"\")\n use_regex = getattr(self, \"use_regex\", False)\n if use_regex:\n try:\n return re.sub(search_pattern, replacement_text, text)\n except re.error as e:\n self.log(f\"Invalid regex pattern: {e}\")\n return text\n return text.replace(search_pattern, replacement_text)\n\n def _text_extract(self, text: str) -> list[str]:\n extract_pattern = getattr(self, \"extract_pattern\", \"\")\n if not extract_pattern:\n return []\n max_matches = getattr(self, \"max_matches\", 10)\n try:\n matches = re.findall(extract_pattern, text)\n except re.error as e:\n msg = f\"Invalid regex pattern '{extract_pattern}': {e}\"\n raise ValueError(msg) from e\n return matches[:max_matches] if max_matches > 0 else matches\n\n def _text_head(self, text: str) -> str:\n head_characters = getattr(self, \"head_characters\", 100)\n if head_characters < 0:\n msg = f\"Characters from Start must be a non-negative integer, got {head_characters}\"\n raise ValueError(msg)\n if head_characters == 0:\n return \"\"\n return text[:head_characters]\n\n def _text_tail(self, text: str) -> str:\n tail_characters = getattr(self, \"tail_characters\", 100)\n if tail_characters < 0:\n msg = f\"Characters from End must be a non-negative integer, got {tail_characters}\"\n raise ValueError(msg)\n if tail_characters == 0:\n return \"\"\n return text[-tail_characters:]\n\n def _text_strip(self, text: str) -> str:\n strip_mode = getattr(self, \"strip_mode\", \"both\")\n strip_characters = getattr(self, \"strip_characters\", \"\")\n text_str = str(text) if text else \"\"\n chars_to_strip = strip_characters if strip_characters else None\n if strip_mode == \"left\":\n return text_str.lstrip(chars_to_strip)\n if strip_mode == \"right\":\n return text_str.rstrip(chars_to_strip)\n return text_str.strip(chars_to_strip)\n\n def _text_join(self, text: str) -> str:\n text_input_2 = getattr(self, \"text_input_2\", \"\")\n text1 = str(text) if text else \"\"\n text2 = str(text_input_2) if text_input_2 else \"\"\n if text1 and text2:\n return f\"{text1}\\n{text2}\"\n return text1 or text2\n\n def _text_clean(self, text: str) -> str:\n result = text\n if getattr(self, \"remove_extra_spaces\", True):\n # Collapse runs of horizontal whitespace but preserve newlines so\n # that remove_empty_lines stays effective when both are enabled.\n result = re.sub(r\"[^\\S\\n]+\", \" \", result)\n if getattr(self, \"remove_special_chars\", False):\n result = re.sub(r\"[^\\w\\s]\", \"\", result)\n if getattr(self, \"remove_empty_lines\", False):\n lines = [line for line in result.split(\"\\n\") if line.strip()]\n result = \"\\n\".join(lines)\n return result\n\n def _format_result_as_text(self, result: Any) -> str:\n if result is None:\n return \"\"\n if isinstance(result, list):\n return \"\\n\".join(str(item) for item in result)\n return str(result)\n"+ "value": "\"\"\"Unified Operations component.\n\nBrings together the previously separate JSON, Table, and Text operation\ncomponents into a single component. An \"Input Type\" selector (Text / JSON /\nTable) drives everything: it filters the \"Operation\" picker to the operations\nthat apply to that type, reveals the matching input (Text / JSON / Table) and\nits operation-specific fields, and advertises the appropriate output type.\n\nThe three original components (JSON Operations, Table Operations, Text\nOperations) remain available as legacy components for backward compatibility\nwith existing flows.\n\"\"\"\n\nimport ast\nimport contextlib\nimport json\nimport re\nfrom typing import TYPE_CHECKING, Any\n\nimport pandas as pd\nfrom json_repair import repair_json\n\nfrom lfx.custom import Component\nfrom lfx.field_typing import RangeSpec\nfrom lfx.inputs import DictInput, SortableListInput, TabInput\nfrom lfx.io import (\n BoolInput,\n DataFrameInput,\n DataInput,\n DropdownInput,\n IntInput,\n MessageTextInput,\n MultilineInput,\n Output,\n StrInput,\n)\nfrom lfx.log.logger import logger\nfrom lfx.schema import Data\nfrom lfx.schema.dataframe import DataFrame\nfrom lfx.schema.dotdict import dotdict\nfrom lfx.schema.message import Message\nfrom lfx.utils.jq_security import validate_jq_program\n\nif TYPE_CHECKING:\n from collections.abc import Callable\n\n# The \"Input Type\" selector tabs. Each value maps a Langflow data type to the\n# operations, input, and output that belong to it.\nINPUT_TYPES = [\"Text\", \"JSON\", \"Table\"]\n\n# Operations grouped by input type, in display order, each with the icon shown\n# in the Operation picker. This is the single source of truth for the picker;\n# update_build_config swaps the picker's options to the selected type's list.\nOPERATIONS_BY_TYPE: dict[str, list[dict[str, str]]] = {\n \"Text\": [\n {\"name\": \"Word Count\", \"icon\": \"hash\"},\n {\"name\": \"Case Conversion\", \"icon\": \"type\"},\n {\"name\": \"Text Replace\", \"icon\": \"replace\"},\n {\"name\": \"Text Extract\", \"icon\": \"search\"},\n {\"name\": \"Text Head\", \"icon\": \"chevron-left\"},\n {\"name\": \"Text Tail\", \"icon\": \"chevron-right\"},\n {\"name\": \"Text Strip\", \"icon\": \"minus\"},\n {\"name\": \"Text Join\", \"icon\": \"link\"},\n {\"name\": \"Text Clean\", \"icon\": \"sparkles\"},\n {\"name\": \"Text to DataFrame\", \"icon\": \"table\"},\n ],\n \"JSON\": [\n {\"name\": \"Select Keys\", \"icon\": \"lasso-select\"},\n {\"name\": \"Literal Eval\", \"icon\": \"braces\"},\n {\"name\": \"Combine\", \"icon\": \"merge\"},\n {\"name\": \"Append or Update\", \"icon\": \"circle-plus\"},\n {\"name\": \"Remove Keys\", \"icon\": \"eraser\"},\n {\"name\": \"Rename Keys\", \"icon\": \"pencil-line\"},\n {\"name\": \"Path Selection\", \"icon\": \"mouse-pointer\"},\n {\"name\": \"JQ Expression\", \"icon\": \"terminal\"},\n ],\n \"Table\": [\n {\"name\": \"Add Column\", \"icon\": \"plus\"},\n {\"name\": \"Concatenate\", \"icon\": \"combine\"},\n {\"name\": \"Drop Column\", \"icon\": \"minus\"},\n {\"name\": \"Filter\", \"icon\": \"filter\"},\n {\"name\": \"Head\", \"icon\": \"arrow-up\"},\n {\"name\": \"Merge\", \"icon\": \"merge\"},\n {\"name\": \"Rename Column\", \"icon\": \"pencil\"},\n {\"name\": \"Replace Value\", \"icon\": \"replace\"},\n {\"name\": \"Select Columns\", \"icon\": \"columns\"},\n {\"name\": \"Sort\", \"icon\": \"arrow-up-down\"},\n {\"name\": \"Tail\", \"icon\": \"arrow-down\"},\n {\"name\": \"Drop Duplicates\", \"icon\": \"copy-x\"},\n ],\n}\n\n# Operation-name sets derived from the picker, used for dispatch and output\n# routing. Keeping them derived from OPERATIONS_BY_TYPE avoids any drift.\nJSON_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"JSON\"]}\nTABLE_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"Table\"]}\nTEXT_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"Text\"]}\n\n# Each input type maps to its main input field and its default output. \"Text\"\n# normally outputs a Message; \"JSON\" a Data; \"Table\" a DataFrame. A few text\n# operations override this (Word Count -> Data, Text to DataFrame -> DataFrame).\nINPUT_TYPE_TO_MAIN_INPUT = {\"Text\": \"text_input\", \"JSON\": \"data\", \"Table\": \"df\"}\n\n# Case conversions for the Text \"Case Conversion\" operation.\nCASE_CONVERTERS: dict[str, Any] = {\n \"uppercase\": str.upper,\n \"lowercase\": str.lower,\n \"title\": str.title,\n \"capitalize\": str.capitalize,\n \"swapcase\": str.swapcase,\n}\n\n\nclass OperationsComponent(Component):\n display_name = \"Data Operations\"\n description = \"Perform operations on Text, JSON, and Tables from a single component.\"\n documentation: str = \"https://docs.langflow.org/components-processing#operations\"\n icon = \"wand-sparkles\"\n name = \"Operations\"\n metadata = {\n \"keywords\": [\n \"operations\",\n \"data operations\",\n \"json\",\n \"json operations\",\n \"table\",\n \"table operations\",\n \"dataframe\",\n \"dataframe operations\",\n \"text\",\n \"text operations\",\n \"select keys\",\n \"literal eval\",\n \"combine\",\n \"append or update\",\n \"remove keys\",\n \"rename keys\",\n \"path selection\",\n \"jq expression\",\n \"parse json\",\n \"add column\",\n \"concatenate\",\n \"drop column\",\n \"filter\",\n \"head\",\n \"merge\",\n \"rename column\",\n \"replace value\",\n \"select columns\",\n \"sort\",\n \"tail\",\n \"drop duplicates\",\n \"word count\",\n \"case conversion\",\n \"text replace\",\n \"text extract\",\n \"text join\",\n \"text clean\",\n \"text to dataframe\",\n \"data manipulation\",\n \"data transformation\",\n ],\n }\n\n # Operation -> operation-specific input fields to reveal when selected.\n OPERATION_FIELDS: dict[str, list[str]] = {\n # JSON\n \"Select Keys\": [\"select_keys_input\"],\n \"Literal Eval\": [],\n \"Combine\": [],\n \"Append or Update\": [\"append_update_data\"],\n \"Remove Keys\": [\"remove_keys_input\"],\n \"Rename Keys\": [\"rename_keys_input\"],\n \"Path Selection\": [\"mapped_json_display\", \"selected_key\"],\n \"JQ Expression\": [\"query\"],\n # Table\n \"Add Column\": [\"new_column_name\", \"new_column_value\"],\n \"Concatenate\": [],\n \"Drop Column\": [\"column_name\"],\n \"Filter\": [\"column_name\", \"filter_value\", \"filter_operator\"],\n \"Head\": [\"num_rows\"],\n \"Merge\": [\"left_dataframe\", \"right_dataframe\", \"merge_on_column\", \"merge_how\"],\n \"Rename Column\": [\"column_name\", \"new_column_name\"],\n \"Replace Value\": [\"column_name\", \"replace_value\", \"replacement_value\"],\n \"Select Columns\": [\"columns_to_select\"],\n \"Sort\": [\"column_name\", \"ascending\"],\n \"Tail\": [\"num_rows\"],\n \"Drop Duplicates\": [\"column_name\"],\n # Text\n \"Word Count\": [\"count_words\", \"count_characters\", \"count_lines\"],\n \"Case Conversion\": [\"case_type\"],\n \"Text Replace\": [\"search_pattern\", \"replacement_text\", \"use_regex\"],\n \"Text Extract\": [\"extract_pattern\", \"max_matches\"],\n \"Text Head\": [\"head_characters\"],\n \"Text Tail\": [\"tail_characters\"],\n \"Text Strip\": [\"strip_mode\", \"strip_characters\"],\n \"Text Join\": [\"text_input_2\"],\n \"Text Clean\": [\"remove_extra_spaces\", \"remove_special_chars\", \"remove_empty_lines\"],\n \"Text to DataFrame\": [\"table_separator\", \"has_header\"],\n }\n\n # The three main inputs (one per data type). They are never treated as\n # operation-specific fields; the input-type selector toggles them.\n MAIN_INPUTS = (\"text_input\", \"data\", \"df\")\n\n # Every operation-specific field (union of all the lists above), used to\n # hide and reset fields whenever the input type or operation changes.\n ALL_OPERATION_FIELDS: list[str] = [\n # JSON\n \"select_keys_input\",\n \"append_update_data\",\n \"remove_keys_input\",\n \"rename_keys_input\",\n \"mapped_json_display\",\n \"selected_key\",\n \"query\",\n # Table\n \"column_name\",\n \"filter_value\",\n \"filter_operator\",\n \"ascending\",\n \"new_column_name\",\n \"new_column_value\",\n \"columns_to_select\",\n \"num_rows\",\n \"replace_value\",\n \"replacement_value\",\n \"left_dataframe\",\n \"right_dataframe\",\n \"merge_on_column\",\n \"merge_how\",\n # Text\n \"table_separator\",\n \"has_header\",\n \"count_words\",\n \"count_characters\",\n \"count_lines\",\n \"case_type\",\n \"use_regex\",\n \"search_pattern\",\n \"replacement_text\",\n \"extract_pattern\",\n \"max_matches\",\n \"head_characters\",\n \"tail_characters\",\n \"strip_mode\",\n \"strip_characters\",\n \"text_input_2\",\n \"remove_extra_spaces\",\n \"remove_special_chars\",\n \"remove_empty_lines\",\n ]\n\n # Defaults applied to the JSON operation fields when the operation changes,\n # mirroring the JSON Operations component's reset behavior.\n OPERATION_FIELD_DEFAULTS: dict[str, Any] = {\n \"select_keys_input\": [],\n \"append_update_data\": {\"key\": \"value\"},\n \"remove_keys_input\": [],\n \"rename_keys_input\": {\"old_key\": \"new_key\"},\n \"mapped_json_display\": \"\",\n \"selected_key\": None,\n \"query\": \"\",\n }\n\n inputs = [\n # --- Input type selector: drives operations, input, and output ---\n TabInput(\n name=\"input_type\",\n display_name=\"Input Type\",\n options=INPUT_TYPES,\n value=\"Text\",\n info=\"Select the type of input to operate on.\",\n real_time_refresh=True,\n ),\n # --- Main inputs: one per data type, shown contextually ---\n MultilineInput(\n name=\"text_input\",\n display_name=\"Text\",\n info=\"The input text to process.\",\n show=True,\n ),\n DataInput(\n name=\"data\",\n display_name=\"JSON\",\n info=\"The JSON / Data object to operate on.\",\n is_list=True,\n show=False,\n ),\n DataFrameInput(\n name=\"df\",\n display_name=\"Table\",\n info=\"The input Table to operate on. Connect multiple Tables for merge or concatenate operations.\",\n is_list=True,\n show=False,\n ),\n # --- Operation picker (options are filtered by Input Type) ---\n SortableListInput(\n name=\"operation\",\n display_name=\"Operation\",\n placeholder=\"Select Operation\",\n info=\"Select the operation to perform. The matching fields and output appear once you choose one.\",\n options=OPERATIONS_BY_TYPE[\"Text\"],\n real_time_refresh=True,\n limit=1,\n ),\n # --- JSON operation fields ---\n MessageTextInput(\n name=\"select_keys_input\",\n display_name=\"Select Keys\",\n info=\"List of keys to select from the data. Only top-level keys can be selected.\",\n show=False,\n is_list=True,\n value=[],\n ),\n DictInput(\n name=\"append_update_data\",\n display_name=\"Append or Update\",\n info=\"Data to append or update the existing data with. Only top-level keys are checked.\",\n show=False,\n value={\"key\": \"value\"},\n is_list=True,\n ),\n MessageTextInput(\n name=\"remove_keys_input\",\n display_name=\"Remove Keys\",\n info=\"List of keys to remove from the data.\",\n show=False,\n is_list=True,\n value=[],\n ),\n DictInput(\n name=\"rename_keys_input\",\n display_name=\"Rename Keys\",\n info=\"List of keys to rename in the data.\",\n show=False,\n is_list=True,\n value={\"old_key\": \"new_key\"},\n ),\n MultilineInput(\n name=\"mapped_json_display\",\n display_name=\"JSON to Map\",\n info=\"Paste or preview your JSON here to explore its structure and select a path for extraction.\",\n required=False,\n refresh_button=True,\n real_time_refresh=True,\n placeholder=\"Add a JSON example.\",\n show=False,\n ),\n DropdownInput(\n name=\"selected_key\",\n display_name=\"Select Path\",\n options=[],\n required=False,\n dynamic=True,\n show=False,\n value=None,\n ),\n MessageTextInput(\n name=\"query\",\n display_name=\"JQ Expression\",\n info=\"JSON Query to filter the data. Used by Path Selection and JQ Expression operations.\",\n placeholder=\"e.g., .properties.id\",\n show=False,\n ),\n # --- Table operation fields ---\n StrInput(\n name=\"column_name\",\n display_name=\"Column Name\",\n info=\"The column name to use for the operation.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"filter_value\",\n display_name=\"Filter Value\",\n info=\"The value to filter rows by.\",\n dynamic=True,\n show=False,\n ),\n DropdownInput(\n name=\"filter_operator\",\n display_name=\"Filter Operator\",\n options=[\n \"equals\",\n \"not equals\",\n \"contains\",\n \"not contains\",\n \"starts with\",\n \"ends with\",\n \"greater than\",\n \"less than\",\n ],\n value=\"equals\",\n info=\"The operator to apply for filtering rows.\",\n advanced=False,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"ascending\",\n display_name=\"Sort Ascending\",\n info=\"Whether to sort in ascending order.\",\n dynamic=True,\n show=False,\n value=True,\n ),\n StrInput(\n name=\"new_column_name\",\n display_name=\"New Column Name\",\n info=\"The new column name when renaming or adding a column.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"new_column_value\",\n display_name=\"New Column Value\",\n info=\"The value to populate the new column with.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"columns_to_select\",\n display_name=\"Columns to Select\",\n dynamic=True,\n is_list=True,\n show=False,\n ),\n IntInput(\n name=\"num_rows\",\n display_name=\"Number of Rows\",\n info=\"Number of rows to return (for head/tail).\",\n dynamic=True,\n show=False,\n value=5,\n ),\n MessageTextInput(\n name=\"replace_value\",\n display_name=\"Value to Replace\",\n info=\"The value to replace in the column.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"replacement_value\",\n display_name=\"Replacement Value\",\n info=\"The value to replace with.\",\n dynamic=True,\n show=False,\n ),\n DataFrameInput(\n name=\"left_dataframe\",\n display_name=\"Left Table\",\n info=\"The left (primary) Table for merge operations. \"\n \"In a left merge, all rows from this table are preserved.\",\n dynamic=True,\n show=False,\n ),\n DataFrameInput(\n name=\"right_dataframe\",\n display_name=\"Right Table\",\n info=\"The right (secondary) Table for merge operations. \"\n \"In a right merge, all rows from this table are preserved.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"merge_on_column\",\n display_name=\"Merge On Column\",\n info=\"The column name to merge Tables on. Must exist in both Tables.\",\n dynamic=True,\n show=False,\n ),\n DropdownInput(\n name=\"merge_how\",\n display_name=\"Merge Type\",\n options=[\"inner\", \"outer\", \"left\", \"right\"],\n value=\"inner\",\n info=\"Type of merge: inner (intersection), outer (union), left, or right.\",\n dynamic=True,\n show=False,\n ),\n # --- Text operation fields ---\n StrInput(\n name=\"table_separator\",\n display_name=\"Table Separator\",\n info=\"Separator used in the table (default: '|').\",\n value=\"|\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"has_header\",\n display_name=\"Has Header\",\n info=\"Whether the table has a header row.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_words\",\n display_name=\"Count Words\",\n info=\"Include word count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_characters\",\n display_name=\"Count Characters\",\n info=\"Include character count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_lines\",\n display_name=\"Count Lines\",\n info=\"Include line count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n DropdownInput(\n name=\"case_type\",\n display_name=\"Case Type\",\n options=[\"uppercase\", \"lowercase\", \"title\", \"capitalize\", \"swapcase\"],\n value=\"lowercase\",\n info=\"Type of case conversion to apply.\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"use_regex\",\n display_name=\"Use Regex\",\n info=\"Whether to treat search pattern as regex.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"search_pattern\",\n display_name=\"Search Pattern\",\n info=\"Text pattern to search for (supports regex).\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"replacement_text\",\n display_name=\"Replacement Text\",\n info=\"Text to replace the search pattern with.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"extract_pattern\",\n display_name=\"Extract Pattern\",\n info=\"Regex pattern to extract from text.\",\n dynamic=True,\n show=False,\n ),\n IntInput(\n name=\"max_matches\",\n display_name=\"Max Matches\",\n info=\"Maximum number of matches to extract.\",\n value=10,\n dynamic=True,\n show=False,\n ),\n IntInput(\n name=\"head_characters\",\n display_name=\"Characters from Start\",\n info=\"Number of characters to extract from the beginning of text. Must be non-negative.\",\n value=100,\n dynamic=True,\n show=False,\n range_spec=RangeSpec(min=0, max=1000000, step=1, step_type=\"int\"),\n ),\n IntInput(\n name=\"tail_characters\",\n display_name=\"Characters from End\",\n info=\"Number of characters to extract from the end of text. Must be non-negative.\",\n value=100,\n dynamic=True,\n show=False,\n range_spec=RangeSpec(min=0, max=1000000, step=1, step_type=\"int\"),\n ),\n DropdownInput(\n name=\"strip_mode\",\n display_name=\"Strip Mode\",\n options=[\"both\", \"left\", \"right\"],\n value=\"both\",\n info=\"Which sides to strip whitespace from.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"strip_characters\",\n display_name=\"Characters to Strip\",\n info=\"Specific characters to remove (leave empty for whitespace).\",\n value=\"\",\n dynamic=True,\n show=False,\n ),\n MultilineInput(\n name=\"text_input_2\",\n display_name=\"Second Text Input\",\n info=\"Second text to join with the first text.\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_extra_spaces\",\n display_name=\"Remove Extra Spaces\",\n info=\"Remove multiple consecutive spaces.\",\n value=True,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_special_chars\",\n display_name=\"Remove Special Characters\",\n info=\"Remove special characters except alphanumeric and spaces.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_empty_lines\",\n display_name=\"Remove Empty Lines\",\n info=\"Remove empty lines from text.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n ]\n\n # Default output matches the default Input Type (\"Text\" -> Message).\n # update_outputs / update_frontend_node narrow it to the selected type and\n # operation.\n outputs = [Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\")]\n\n # ------------------------------------------------------------------\n # Operation routing helpers\n # ------------------------------------------------------------------\n @staticmethod\n def _extract_operation_name(field_value: Any) -> str:\n \"\"\"Extract the operation name from a SortableListInput value.\"\"\"\n if isinstance(field_value, list) and len(field_value) > 0 and isinstance(field_value[0], dict):\n return field_value[0].get(\"name\", \"\")\n if isinstance(field_value, str):\n return field_value\n return \"\"\n\n def _operation_name(self) -> str:\n \"\"\"Get the currently selected operation name.\"\"\"\n return self._extract_operation_name(getattr(self, \"operation\", []))\n\n @staticmethod\n def _default_output_for_type(input_type: str) -> Output:\n \"\"\"Return the output advertised for an input type when no operation is selected yet.\"\"\"\n if input_type == \"JSON\":\n return Output(display_name=\"JSON\", name=\"data_output\", method=\"as_data\")\n if input_type == \"Table\":\n return Output(display_name=\"Table\", name=\"dataframe_output\", method=\"as_dataframe\")\n return Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\")\n\n # ------------------------------------------------------------------\n # Dynamic UI\n # ------------------------------------------------------------------\n def _reset_operation_fields(self, build_config: dotdict) -> None:\n \"\"\"Hide every operation-specific field and restore its default value.\"\"\"\n for field in self.ALL_OPERATION_FIELDS:\n if field in build_config:\n build_config[field][\"show\"] = False\n if field in self.OPERATION_FIELD_DEFAULTS:\n build_config[field][\"value\"] = self.OPERATION_FIELD_DEFAULTS[field]\n\n def _show_main_input(self, build_config: dotdict, input_type: str, operation: str) -> None:\n \"\"\"Show only the main input that matches the input type; hide the others.\"\"\"\n for inp in self.MAIN_INPUTS:\n if inp in build_config:\n build_config[inp][\"show\"] = False\n build_config[inp][\"required\"] = False\n\n main_input = INPUT_TYPE_TO_MAIN_INPUT.get(input_type)\n if main_input and main_input in build_config:\n build_config[main_input][\"show\"] = True\n build_config[main_input][\"required\"] = True\n # The JSON \"Combine\" operation consumes a list of Data objects.\n if main_input == \"data\":\n build_config[\"data\"][\"is_list\"] = operation == \"Combine\"\n\n def update_build_config(self, build_config: dotdict, field_value: Any, field_name: str | None = None) -> dotdict:\n # Path Selection: refresh the available JSON paths from the pasted JSON.\n if field_name == \"mapped_json_display\":\n try:\n parsed_json = json.loads(field_value)\n keys = self.extract_all_paths(parsed_json)\n build_config[\"selected_key\"][\"options\"] = keys\n build_config[\"selected_key\"][\"show\"] = True\n except (json.JSONDecodeError, TypeError, ValueError) as e:\n logger.error(f\"Error parsing mapped JSON: {e}\")\n build_config[\"selected_key\"][\"show\"] = False\n return build_config\n\n # Input type changed: swap the operation list, clear the selection, and\n # show only the matching input. No operation-specific fields are shown\n # until an operation is picked.\n if field_name == \"input_type\":\n input_type = field_value if field_value in OPERATIONS_BY_TYPE else \"Text\"\n build_config[\"operation\"][\"options\"] = OPERATIONS_BY_TYPE[input_type]\n build_config[\"operation\"][\"value\"] = []\n self._reset_operation_fields(build_config)\n self._show_main_input(build_config, input_type, operation=\"\")\n return build_config\n\n # Operation changed: reset fields, show the input for the current type,\n # then reveal the operation-specific fields.\n if field_name == \"operation\":\n operation = self._extract_operation_name(field_value)\n self._reset_operation_fields(build_config)\n\n input_type = build_config.get(\"input_type\", {}).get(\"value\", \"Text\")\n self._show_main_input(build_config, input_type, operation)\n\n for field in self.OPERATION_FIELDS.get(operation, []):\n if field in build_config:\n build_config[field][\"show\"] = True\n\n return build_config\n\n return build_config\n\n def update_outputs(self, frontend_node: dict, field_name: str, field_value: Any) -> dict:\n \"\"\"Create the output(s) appropriate to the selected input type and operation.\"\"\"\n if field_name == \"input_type\":\n # Switching type clears the operation; advertise the type's default.\n input_type = field_value if field_value in OPERATIONS_BY_TYPE else \"Text\"\n frontend_node[\"outputs\"] = [self._default_output_for_type(input_type)]\n return frontend_node\n\n template = frontend_node.get(\"template\", {})\n input_type = template.get(\"input_type\", {}).get(\"value\", \"Text\")\n\n if field_name == \"operation\":\n operation = self._extract_operation_name(field_value)\n else:\n # Any other refresh (e.g. Path Selection's \"JSON to Map\" field)\n # reaches here on a freshly rebuilt node whose outputs were reset\n # to the class default (Message). Re-derive the output from the\n # saved operation so the refresh doesn't swap the real output type.\n operation = self._extract_operation_name(template.get(\"operation\", {}).get(\"value\", []))\n\n if not operation:\n # No operation selected: fall back to the input type's default output.\n frontend_node[\"outputs\"] = [self._default_output_for_type(input_type)]\n return frontend_node\n\n frontend_node[\"outputs\"] = []\n if operation in JSON_OPERATIONS or operation == \"Word Count\":\n frontend_node[\"outputs\"].append(Output(display_name=\"JSON\", name=\"data_output\", method=\"as_data\"))\n elif operation in TABLE_OPERATIONS or operation == \"Text to DataFrame\":\n frontend_node[\"outputs\"].append(\n Output(display_name=\"Table\", name=\"dataframe_output\", method=\"as_dataframe\")\n )\n elif operation == \"Text Join\":\n frontend_node[\"outputs\"].append(Output(display_name=\"Text\", name=\"text_output\", method=\"as_text\"))\n frontend_node[\"outputs\"].append(Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\"))\n else:\n frontend_node[\"outputs\"].append(Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\"))\n\n return frontend_node\n\n async def update_frontend_node(self, new_frontend_node: dict, current_frontend_node: dict) -> dict:\n \"\"\"Keep the operation options and outputs in sync with the saved input type on load.\"\"\"\n await super().update_frontend_node(new_frontend_node, current_frontend_node)\n\n template = new_frontend_node.get(\"template\", {})\n input_type = template.get(\"input_type\", {}).get(\"value\", \"Text\")\n if input_type not in OPERATIONS_BY_TYPE:\n input_type = \"Text\"\n\n # Filter the operation picker to the saved input type.\n if \"operation\" in template:\n template[\"operation\"][\"options\"] = OPERATIONS_BY_TYPE[input_type]\n\n # Re-derive the outputs from the saved input type + operation.\n operation_value = template.get(\"operation\", {}).get(\"value\", [])\n if self._extract_operation_name(operation_value):\n self.update_outputs(new_frontend_node, \"operation\", operation_value)\n else:\n self.update_outputs(new_frontend_node, \"input_type\", input_type)\n\n return new_frontend_node\n\n # ==================================================================\n # Output methods (referenced by update_outputs)\n # ==================================================================\n def as_data(self) -> Data:\n \"\"\"JSON-typed output: JSON operations and Word Count.\"\"\"\n operation = self._operation_name()\n if operation in JSON_OPERATIONS:\n handler = self._json_handlers().get(operation)\n if handler:\n try:\n return handler()\n except Exception as e:\n logger.error(f\"Error executing {operation}: {e!s}\")\n raise\n if operation == \"Word Count\":\n return self._word_count_data()\n return Data(data={})\n\n def as_dataframe(self) -> DataFrame:\n \"\"\"Table-typed output: Table operations and Text to DataFrame.\"\"\"\n operation = self._operation_name()\n if operation in TABLE_OPERATIONS:\n return self._run_table_operation(operation)\n if operation == \"Text to DataFrame\":\n return self._text_to_dataframe(getattr(self, \"text_input\", \"\") or \"\")\n return DataFrame(pd.DataFrame())\n\n def as_message(self) -> Message:\n \"\"\"Message-typed output: generic text operations (and Text Join).\"\"\"\n return Message(text=self._format_result_as_text(self._run_text_operation()))\n\n def as_text(self) -> Message:\n \"\"\"Text output for the Text Join operation.\"\"\"\n return self.as_message()\n\n # ==================================================================\n # JSON operations\n # ==================================================================\n @staticmethod\n def extract_all_paths(obj, path=\"\"):\n paths = []\n if isinstance(obj, dict):\n for k, v in obj.items():\n new_path = f\"{path}.{k}\" if path else f\".{k}\"\n paths.append(new_path)\n paths.extend(OperationsComponent.extract_all_paths(v, new_path))\n elif isinstance(obj, list) and obj:\n new_path = f\"{path}[0]\"\n paths.append(new_path)\n paths.extend(OperationsComponent.extract_all_paths(obj[0], new_path))\n return paths\n\n @staticmethod\n def remove_keys_recursive(obj, keys_to_remove):\n if isinstance(obj, dict):\n return {\n k: OperationsComponent.remove_keys_recursive(v, keys_to_remove)\n for k, v in obj.items()\n if k not in keys_to_remove\n }\n if isinstance(obj, list):\n return [OperationsComponent.remove_keys_recursive(item, keys_to_remove) for item in obj]\n return obj\n\n @staticmethod\n def rename_keys_recursive(obj, rename_map):\n if isinstance(obj, dict):\n return {\n rename_map.get(k, k): OperationsComponent.rename_keys_recursive(v, rename_map) for k, v in obj.items()\n }\n if isinstance(obj, list):\n return [OperationsComponent.rename_keys_recursive(item, rename_map) for item in obj]\n return obj\n\n def _json_handlers(self) -> \"dict[str, Callable[[], Data]]\":\n return {\n \"Select Keys\": self.select_keys,\n \"Literal Eval\": self.evaluate_data,\n \"Combine\": self.combine_data,\n \"Append or Update\": self.append_update,\n \"Remove Keys\": self.remove_keys,\n \"Rename Keys\": self.rename_keys,\n \"Path Selection\": self.json_path,\n \"JQ Expression\": self.json_query,\n }\n\n def get_data_dict(self) -> dict:\n \"\"\"Extract data dictionary from Data object.\"\"\"\n data = self.data[0] if isinstance(self.data, list) and len(self.data) == 1 else self.data\n return data.model_dump()\n\n def get_normalized_data(self) -> dict:\n \"\"\"Get normalized data dictionary, handling the 'data' key if present.\"\"\"\n data_dict = self.get_data_dict()\n return data_dict.get(\"data\", data_dict)\n\n def data_is_list(self) -> bool:\n \"\"\"Check if data contains multiple items.\"\"\"\n return isinstance(self.data, list) and len(self.data) > 1\n\n def validate_single_data(self, operation: str) -> None:\n \"\"\"Validate that the operation is being performed on a single data object.\"\"\"\n if self.data_is_list():\n msg = f\"{operation} operation is not supported for multiple data objects.\"\n raise ValueError(msg)\n\n def select_keys(self) -> Data:\n \"\"\"Select specific keys from the data dictionary.\"\"\"\n self.validate_single_data(\"Select Keys\")\n data_dict = self.get_normalized_data()\n filter_criteria: list[str] = self.select_keys_input\n\n if len(filter_criteria) == 1 and filter_criteria[0] == \"data\":\n filtered = data_dict[\"data\"]\n else:\n if not all(key in data_dict for key in filter_criteria):\n msg = f\"Select key not found in data. Available keys: {list(data_dict.keys())}\"\n raise ValueError(msg)\n filtered = {key: value for key, value in data_dict.items() if key in filter_criteria}\n\n return Data(data=filtered)\n\n def remove_keys(self) -> Data:\n \"\"\"Remove specified keys from the data dictionary, recursively.\"\"\"\n self.validate_single_data(\"Remove Keys\")\n data_dict = self.get_normalized_data()\n remove_keys_input: list[str] = self.remove_keys_input\n filtered = OperationsComponent.remove_keys_recursive(data_dict, set(remove_keys_input))\n return Data(data=filtered)\n\n def rename_keys(self) -> Data:\n \"\"\"Rename keys in the data dictionary, recursively.\"\"\"\n self.validate_single_data(\"Rename Keys\")\n data_dict = self.get_normalized_data()\n rename_keys_input: dict[str, str] = self.rename_keys_input\n renamed = OperationsComponent.rename_keys_recursive(data_dict, rename_keys_input)\n return Data(data=renamed)\n\n def recursive_eval(self, data: Any) -> Any:\n \"\"\"Recursively evaluate string values that look like Python literals.\"\"\"\n if isinstance(data, dict):\n return {k: self.recursive_eval(v) for k, v in data.items()}\n if isinstance(data, list):\n return [self.recursive_eval(item) for item in data]\n if isinstance(data, str):\n try:\n if (\n data.strip().startswith((\"{\", \"[\", \"(\", \"'\", '\"'))\n or data.strip().lower() in (\"true\", \"false\", \"none\")\n or data.strip().replace(\".\", \"\").isdigit()\n ):\n return ast.literal_eval(data)\n except (ValueError, SyntaxError, TypeError, MemoryError):\n return data\n else:\n return data\n return data\n\n def evaluate_data(self) -> Data:\n \"\"\"Evaluate string values in the data dictionary.\"\"\"\n self.validate_single_data(\"Literal Eval\")\n logger.info(\"evaluating data\")\n return Data(**self.recursive_eval(self.get_data_dict()))\n\n def combine_data(self) -> Data:\n \"\"\"Combine multiple data objects into one.\"\"\"\n logger.info(\"combining data\")\n if not self.data_is_list():\n return self.data[0] if self.data else Data(data={})\n\n data_dicts = [data.model_dump().get(\"data\", data.model_dump()) for data in self.data]\n combined_data: dict[str, Any] = {}\n\n for data_dict in data_dicts:\n for key, value in data_dict.items():\n if key not in combined_data:\n combined_data[key] = value\n elif isinstance(combined_data[key], list):\n if isinstance(value, list):\n combined_data[key].extend(value)\n else:\n combined_data[key].append(value)\n else:\n combined_data[key] = (\n [combined_data[key], value] if not isinstance(value, list) else [combined_data[key], *value]\n )\n\n return Data(**combined_data)\n\n def append_update(self) -> Data:\n \"\"\"Append or update the data with new key-value pairs.\"\"\"\n self.validate_single_data(\"Append or Update\")\n data_filtered = self.get_normalized_data()\n for key, value in self.append_update_data.items():\n data_filtered[key] = value\n return Data(**data_filtered)\n\n def json_path(self) -> Data:\n \"\"\"Extract a value from the data using the selected JQ path.\"\"\"\n try:\n import jq\n except ImportError:\n msg = \"jq is required for Path Selection. Install with: pip install jq\"\n raise ImportError(msg) from None\n\n try:\n if not self.data or not self.selected_key:\n msg = \"Missing input data or selected key.\"\n raise ValueError(msg)\n input_payload = self.data[0].data if isinstance(self.data, list) else self.data.data\n validate_jq_program(self.selected_key)\n compiled = jq.compile(self.selected_key)\n result = compiled.input(input_payload).first()\n if isinstance(result, dict):\n return Data(data=result)\n return Data(data={\"result\": result})\n except (ValueError, TypeError, KeyError) as e:\n self.status = f\"Error: {e!s}\"\n self.log(self.status)\n return Data(data={\"error\": str(e)})\n\n def json_query(self) -> Data:\n \"\"\"Run a JQ expression against the data.\"\"\"\n try:\n import jq\n except ImportError:\n msg = \"jq is required for JQ Expression. Install with: pip install jq\"\n raise ImportError(msg) from None\n\n if not self.query or not self.query.strip():\n msg = \"JSON Query is required and cannot be blank.\"\n raise ValueError(msg)\n raw_data = self.get_data_dict()\n try:\n input_str = json.dumps(raw_data)\n repaired = repair_json(input_str)\n data_json = json.loads(repaired)\n jq_input = data_json[\"data\"] if isinstance(data_json, dict) and \"data\" in data_json else data_json\n validate_jq_program(self.query)\n results = jq.compile(self.query).input(jq_input).all()\n if not results:\n msg = \"No result from JSON query.\"\n raise ValueError(msg)\n result = results[0] if len(results) == 1 else results\n if result is None or result == \"None\":\n msg = \"JSON query returned null/None. Check if the path exists in your data.\"\n raise ValueError(msg)\n if isinstance(result, dict):\n return Data(data=result)\n return Data(data={\"result\": result})\n except (ValueError, TypeError, KeyError, json.JSONDecodeError) as e:\n logger.error(f\"JSON Query failed: {e}\")\n msg = f\"JSON Query error: {e}\"\n raise ValueError(msg) from e\n\n # ==================================================================\n # Table operations\n # ==================================================================\n def _get_primary_dataframe(self) -> DataFrame:\n \"\"\"Get the first DataFrame from input (handles both single and list inputs).\"\"\"\n if isinstance(self.df, list):\n return self.df[0].copy() if self.df else DataFrame()\n return self.df.copy()\n\n def _run_table_operation(self, operation: str) -> DataFrame:\n # Merge and Concatenate use their own inputs, not the primary df.\n if operation == \"Merge\":\n return self.merge_dataframes()\n if operation == \"Concatenate\":\n return self.concatenate_dataframes()\n\n df_copy = self._get_primary_dataframe()\n table_handlers = {\n \"Filter\": self.filter_rows_by_value,\n \"Sort\": self.sort_by_column,\n \"Drop Column\": self.drop_column,\n \"Rename Column\": self.rename_column,\n \"Add Column\": self.add_column,\n \"Select Columns\": self.select_columns,\n \"Head\": self.head,\n \"Tail\": self.tail,\n \"Replace Value\": self.replace_values,\n \"Drop Duplicates\": self.drop_duplicates,\n }\n handler = table_handlers.get(operation)\n if handler is None:\n msg = f\"Unsupported operation: {operation}\"\n logger.error(msg)\n raise ValueError(msg)\n return handler(df_copy)\n\n def filter_rows_by_value(self, df: DataFrame) -> DataFrame:\n column = df[self.column_name]\n filter_value = self.filter_value\n operator = getattr(self, \"filter_operator\", \"equals\")\n\n if operator == \"equals\":\n mask = column == filter_value\n elif operator == \"not equals\":\n mask = column != filter_value\n elif operator == \"contains\":\n mask = column.astype(str).str.contains(str(filter_value), na=False)\n elif operator == \"not contains\":\n mask = ~column.astype(str).str.contains(str(filter_value), na=False)\n elif operator == \"starts with\":\n mask = column.astype(str).str.startswith(str(filter_value), na=False)\n elif operator == \"ends with\":\n mask = column.astype(str).str.endswith(str(filter_value), na=False)\n elif operator == \"greater than\":\n try:\n numeric_value = pd.to_numeric(filter_value)\n mask = column > numeric_value\n except (ValueError, TypeError):\n mask = column.astype(str) > str(filter_value)\n elif operator == \"less than\":\n try:\n numeric_value = pd.to_numeric(filter_value)\n mask = column < numeric_value\n except (ValueError, TypeError):\n mask = column.astype(str) < str(filter_value)\n else:\n mask = column == filter_value\n\n return DataFrame(df[mask])\n\n def sort_by_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.sort_values(by=self.column_name, ascending=self.ascending))\n\n def drop_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.drop(columns=[self.column_name]))\n\n def rename_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.rename(columns={self.column_name: self.new_column_name}))\n\n def add_column(self, df: DataFrame) -> DataFrame:\n df[self.new_column_name] = [self.new_column_value] * len(df)\n return DataFrame(df)\n\n def select_columns(self, df: DataFrame) -> DataFrame:\n columns = [col.strip() for col in self.columns_to_select]\n return DataFrame(df[columns])\n\n def head(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.head(self.num_rows))\n\n def tail(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.tail(self.num_rows))\n\n def replace_values(self, df: DataFrame) -> DataFrame:\n df[self.column_name] = df[self.column_name].replace(self.replace_value, self.replacement_value)\n return DataFrame(df)\n\n def drop_duplicates(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.drop_duplicates(subset=self.column_name))\n\n def concatenate_dataframes(self) -> DataFrame:\n \"\"\"Concatenate multiple DataFrames vertically (stack rows).\"\"\"\n if not isinstance(self.df, list) or len(self.df) == 0:\n return self.df.copy() if self.df is not None else DataFrame()\n\n if len(self.df) == 1:\n return self.df[0].copy()\n\n concatenated = pd.concat(self.df, ignore_index=True)\n return DataFrame(concatenated)\n\n def merge_dataframes(self) -> DataFrame:\n \"\"\"Merge two DataFrames based on a common column (join operation).\"\"\"\n left_df = getattr(self, \"left_dataframe\", None)\n right_df = getattr(self, \"right_dataframe\", None)\n\n if left_df is None:\n return DataFrame()\n if right_df is None:\n return left_df.copy()\n\n df_left = left_df.copy()\n df_right = right_df.copy()\n\n merge_on = getattr(self, \"merge_on_column\", None)\n merge_how = getattr(self, \"merge_how\", \"inner\")\n\n if merge_on:\n if merge_on not in df_left.columns:\n msg = f\"Column '{merge_on}' not found in left DataFrame. Available: {list(df_left.columns)}\"\n raise ValueError(msg)\n if merge_on not in df_right.columns:\n msg = f\"Column '{merge_on}' not found in right DataFrame. Available: {list(df_right.columns)}\"\n raise ValueError(msg)\n merged = df_left.merge(df_right, on=merge_on, how=merge_how, suffixes=(\"\", \"_right\"))\n else:\n merged = df_left.merge(df_right, left_index=True, right_index=True, how=merge_how, suffixes=(\"\", \"_right\"))\n\n cols_to_drop = []\n for col in merged.columns:\n if col.endswith(\"_right\"):\n original_col = col[:-6]\n if original_col in merged.columns:\n merged[original_col] = merged[original_col].combine_first(merged[col])\n cols_to_drop.append(col)\n\n if cols_to_drop:\n merged = merged.drop(columns=cols_to_drop)\n\n return DataFrame(merged)\n\n # ==================================================================\n # Text operations\n # ==================================================================\n def _run_text_operation(self) -> Any:\n \"\"\"Process text based on the selected operation (Message/Text outputs).\"\"\"\n text = getattr(self, \"text_input\", \"\")\n operation = self._operation_name()\n\n # Allow empty text for Text Join (second input may have content).\n if not text and operation != \"Text Join\":\n return None\n\n text_handlers = {\n \"Case Conversion\": self._case_conversion,\n \"Text Replace\": self._text_replace,\n \"Text Extract\": self._text_extract,\n \"Text Head\": self._text_head,\n \"Text Tail\": self._text_tail,\n \"Text Strip\": self._text_strip,\n \"Text Join\": self._text_join,\n \"Text Clean\": self._text_clean,\n }\n handler = text_handlers.get(operation)\n if handler:\n return handler(text)\n return text\n\n def _word_count_data(self) -> Data:\n \"\"\"Word Count operation result as a Data object.\"\"\"\n result = self._word_count(getattr(self, \"text_input\", \"\") or \"\")\n return Data(data=result)\n\n def _word_count(self, text: str) -> dict[str, Any]:\n \"\"\"Count words, characters, and lines in text.\"\"\"\n result: dict[str, Any] = {}\n text_str = str(text) if text else \"\"\n is_empty = not text_str or not text_str.strip()\n\n if getattr(self, \"count_words\", True):\n if is_empty:\n result[\"word_count\"] = 0\n result[\"unique_words\"] = 0\n else:\n words = text_str.split()\n result[\"word_count\"] = len(words)\n result[\"unique_words\"] = len(set(words))\n\n if getattr(self, \"count_characters\", True):\n if is_empty:\n result[\"character_count\"] = 0\n result[\"character_count_no_spaces\"] = 0\n else:\n result[\"character_count\"] = len(text_str)\n result[\"character_count_no_spaces\"] = len(text_str.replace(\" \", \"\"))\n\n if getattr(self, \"count_lines\", True):\n if is_empty:\n result[\"line_count\"] = 0\n result[\"non_empty_lines\"] = 0\n else:\n lines = text_str.split(\"\\n\")\n result[\"line_count\"] = len(lines)\n result[\"non_empty_lines\"] = len([line for line in lines if line.strip()])\n\n return result\n\n def _text_to_dataframe(self, text: str) -> DataFrame:\n \"\"\"Convert markdown-style table text to a DataFrame.\"\"\"\n lines = [line.strip() for line in text.strip().split(\"\\n\") if line.strip()]\n if not lines:\n return DataFrame(pd.DataFrame())\n\n separator = getattr(self, \"table_separator\", \"|\")\n has_header = getattr(self, \"has_header\", True)\n\n rows = self._parse_table_rows(lines, separator)\n if not rows:\n return DataFrame(pd.DataFrame())\n\n df = self._create_dataframe(rows, has_header=has_header)\n self._convert_numeric_columns(df)\n self.log(f\"Converted text to DataFrame: {len(df)} rows, {len(df.columns)} columns\")\n return DataFrame(df)\n\n def _parse_table_rows(self, lines: list[str], separator: str) -> list[list[str]]:\n rows = []\n for line in lines:\n cleaned_line = line.strip(separator)\n cells = [cell.strip() for cell in cleaned_line.split(separator)]\n rows.append(cells)\n return rows\n\n def _create_dataframe(self, rows: list[list[str]], *, has_header: bool) -> pd.DataFrame:\n if has_header and len(rows) > 1:\n header = rows[0]\n data_rows = rows[1:]\n header_col_count = len(header)\n for i, row in enumerate(data_rows):\n row_col_count = len(row)\n if row_col_count != header_col_count:\n msg = (\n f\"Header mismatch: {header_col_count} column(s) in header vs \"\n f\"{row_col_count} column(s) in data row {i + 1}. \"\n \"Please ensure the header has the same number of columns as your data.\"\n )\n raise ValueError(msg)\n return pd.DataFrame(data_rows, columns=header)\n\n max_cols = max(len(row) for row in rows) if rows else 0\n columns = [f\"col_{i}\" for i in range(max_cols)]\n return pd.DataFrame(rows, columns=columns)\n\n def _convert_numeric_columns(self, df: pd.DataFrame) -> None:\n for col in df.columns:\n with contextlib.suppress(ValueError, TypeError):\n df[col] = pd.to_numeric(df[col])\n\n def _case_conversion(self, text: str) -> str:\n case_type = getattr(self, \"case_type\", \"lowercase\")\n converter = CASE_CONVERTERS.get(case_type)\n return converter(text) if converter else text\n\n def _text_replace(self, text: str) -> str:\n search_pattern = getattr(self, \"search_pattern\", \"\")\n if not search_pattern:\n return text\n replacement_text = getattr(self, \"replacement_text\", \"\")\n use_regex = getattr(self, \"use_regex\", False)\n if use_regex:\n try:\n return re.sub(search_pattern, replacement_text, text)\n except re.error as e:\n self.log(f\"Invalid regex pattern: {e}\")\n return text\n return text.replace(search_pattern, replacement_text)\n\n def _text_extract(self, text: str) -> list[str]:\n extract_pattern = getattr(self, \"extract_pattern\", \"\")\n if not extract_pattern:\n return []\n max_matches = getattr(self, \"max_matches\", 10)\n try:\n matches = re.findall(extract_pattern, text)\n except re.error as e:\n msg = f\"Invalid regex pattern '{extract_pattern}': {e}\"\n raise ValueError(msg) from e\n return matches[:max_matches] if max_matches > 0 else matches\n\n def _text_head(self, text: str) -> str:\n head_characters = getattr(self, \"head_characters\", 100)\n if head_characters < 0:\n msg = f\"Characters from Start must be a non-negative integer, got {head_characters}\"\n raise ValueError(msg)\n if head_characters == 0:\n return \"\"\n return text[:head_characters]\n\n def _text_tail(self, text: str) -> str:\n tail_characters = getattr(self, \"tail_characters\", 100)\n if tail_characters < 0:\n msg = f\"Characters from End must be a non-negative integer, got {tail_characters}\"\n raise ValueError(msg)\n if tail_characters == 0:\n return \"\"\n return text[-tail_characters:]\n\n def _text_strip(self, text: str) -> str:\n strip_mode = getattr(self, \"strip_mode\", \"both\")\n strip_characters = getattr(self, \"strip_characters\", \"\")\n text_str = str(text) if text else \"\"\n chars_to_strip = strip_characters if strip_characters else None\n if strip_mode == \"left\":\n return text_str.lstrip(chars_to_strip)\n if strip_mode == \"right\":\n return text_str.rstrip(chars_to_strip)\n return text_str.strip(chars_to_strip)\n\n def _text_join(self, text: str) -> str:\n text_input_2 = getattr(self, \"text_input_2\", \"\")\n text1 = str(text) if text else \"\"\n text2 = str(text_input_2) if text_input_2 else \"\"\n if text1 and text2:\n return f\"{text1}\\n{text2}\"\n return text1 or text2\n\n def _text_clean(self, text: str) -> str:\n result = text\n if getattr(self, \"remove_extra_spaces\", True):\n # Collapse runs of horizontal whitespace but preserve newlines so\n # that remove_empty_lines stays effective when both are enabled.\n result = re.sub(r\"[^\\S\\n]+\", \" \", result)\n if getattr(self, \"remove_special_chars\", False):\n result = re.sub(r\"[^\\w\\s]\", \"\", result)\n if getattr(self, \"remove_empty_lines\", False):\n lines = [line for line in result.split(\"\\n\") if line.strip()]\n result = \"\\n\".join(lines)\n return result\n\n def _format_result_as_text(self, result: Any) -> str:\n if result is None:\n return \"\"\n if isinstance(result, list):\n return \"\\n\".join(str(item) for item in result)\n return str(result)\n"},"column_name": {"_input_type": "StrInput",@@ -1544,6 +1542,7 @@"display_name": "Input Type","dynamic": false,"info": "Select the type of input to operate on.",+ "load_from_db": false,"name": "input_type","options": ["Text",@@ -1771,6 +1770,7 @@"dynamic": false,"info": "Select the operation to perform. The matching fields and output appear once you choose one.","limit": 1,+ "load_from_db": false,"name": "operation","options": [{@@ -2355,6 +2355,8 @@},{"data": {+ "description": "Perform operations on Text, JSON, and Tables from a single component.",+ "display_name": "Data Operations","id": "Operations-VUCJC","node": {"base_classes": [@@ -2416,10 +2418,10 @@],"frozen": false,"icon": "wand-sparkles",- "last_updated": "2026-07-17T19:10:01.879Z",+ "last_updated": "2026-10-27T20:14:15.099Z","legacy": false,"metadata": {- "code_hash": "4c2a33c778d3",+ "code_hash": "f15ba610cfd0","dependencies": {"dependencies": [{@@ -2428,11 +2430,11 @@},{"name": "json_repair",- "version": "0.61.4"+ "version": "0.61.7"},{"name": "lfx",- "version": null+ "version": "1.12.3"},{"name": "jq",@@ -2483,7 +2485,7 @@"data manipulation","data transformation"],- "module": "lfx.components.processing.operations.OperationsComponent"+ "module": "custom_components.data_operations"},"minimized": false,"output_types": [],@@ -2491,7 +2493,7 @@{"allows_loop": false,"cache": true,- "display_name": "Message",+ "display_name": "Table","group_outputs": false,"hidden": null,"loop_types": null,@@ -2513,7 +2515,7 @@"value": "5488df7c-b93f-4f87-a446-b67028bc0813"},"_frontend_node_folder_id": {- "value": "f1efb4f8-3ca5-4e89-8685-0e8b2ba1187f"+ "value": "f3f8bf74-7a73-4ab3-9769-0d8a4ebbaec9"},"_type": "Component","append_update_data": {@@ -2608,7 +2610,7 @@"show": true,"title_case": false,"type": "code",- "value": "\"\"\"Unified Operations component.\n\nBrings together the previously separate JSON, Table, and Text operation\ncomponents into a single component. An \"Input Type\" selector (Text / JSON /\nTable) drives everything: it filters the \"Operation\" picker to the operations\nthat apply to that type, reveals the matching input (Text / JSON / Table) and\nits operation-specific fields, and advertises the appropriate output type.\n\nThe three original components (JSON Operations, Table Operations, Text\nOperations) remain available as legacy components for backward compatibility\nwith existing flows.\n\"\"\"\n\nimport ast\nimport contextlib\nimport json\nimport re\nfrom typing import TYPE_CHECKING, Any\n\nimport pandas as pd\nfrom json_repair import repair_json\n\nfrom lfx.custom import Component\nfrom lfx.field_typing import RangeSpec\nfrom lfx.inputs import DictInput, SortableListInput, TabInput\nfrom lfx.io import (\n BoolInput,\n DataFrameInput,\n DataInput,\n DropdownInput,\n IntInput,\n MessageTextInput,\n MultilineInput,\n Output,\n StrInput,\n)\nfrom lfx.log.logger import logger\nfrom lfx.schema import Data\nfrom lfx.schema.dataframe import DataFrame\nfrom lfx.schema.dotdict import dotdict\nfrom lfx.schema.message import Message\n\nif TYPE_CHECKING:\n from collections.abc import Callable\n\n# The \"Input Type\" selector tabs. Each value maps a Langflow data type to the\n# operations, input, and output that belong to it.\nINPUT_TYPES = [\"Text\", \"JSON\", \"Table\"]\n\n# Operations grouped by input type, in display order, each with the icon shown\n# in the Operation picker. This is the single source of truth for the picker;\n# update_build_config swaps the picker's options to the selected type's list.\nOPERATIONS_BY_TYPE: dict[str, list[dict[str, str]]] = {\n \"Text\": [\n {\"name\": \"Word Count\", \"icon\": \"hash\"},\n {\"name\": \"Case Conversion\", \"icon\": \"type\"},\n {\"name\": \"Text Replace\", \"icon\": \"replace\"},\n {\"name\": \"Text Extract\", \"icon\": \"search\"},\n {\"name\": \"Text Head\", \"icon\": \"chevron-left\"},\n {\"name\": \"Text Tail\", \"icon\": \"chevron-right\"},\n {\"name\": \"Text Strip\", \"icon\": \"minus\"},\n {\"name\": \"Text Join\", \"icon\": \"link\"},\n {\"name\": \"Text Clean\", \"icon\": \"sparkles\"},\n {\"name\": \"Text to DataFrame\", \"icon\": \"table\"},\n ],\n \"JSON\": [\n {\"name\": \"Select Keys\", \"icon\": \"lasso-select\"},\n {\"name\": \"Literal Eval\", \"icon\": \"braces\"},\n {\"name\": \"Combine\", \"icon\": \"merge\"},\n {\"name\": \"Append or Update\", \"icon\": \"circle-plus\"},\n {\"name\": \"Remove Keys\", \"icon\": \"eraser\"},\n {\"name\": \"Rename Keys\", \"icon\": \"pencil-line\"},\n {\"name\": \"Path Selection\", \"icon\": \"mouse-pointer\"},\n {\"name\": \"JQ Expression\", \"icon\": \"terminal\"},\n ],\n \"Table\": [\n {\"name\": \"Add Column\", \"icon\": \"plus\"},\n {\"name\": \"Concatenate\", \"icon\": \"combine\"},\n {\"name\": \"Drop Column\", \"icon\": \"minus\"},\n {\"name\": \"Filter\", \"icon\": \"filter\"},\n {\"name\": \"Head\", \"icon\": \"arrow-up\"},\n {\"name\": \"Merge\", \"icon\": \"merge\"},\n {\"name\": \"Rename Column\", \"icon\": \"pencil\"},\n {\"name\": \"Replace Value\", \"icon\": \"replace\"},\n {\"name\": \"Select Columns\", \"icon\": \"columns\"},\n {\"name\": \"Sort\", \"icon\": \"arrow-up-down\"},\n {\"name\": \"Tail\", \"icon\": \"arrow-down\"},\n {\"name\": \"Drop Duplicates\", \"icon\": \"copy-x\"},\n ],\n}\n\n# Operation-name sets derived from the picker, used for dispatch and output\n# routing. Keeping them derived from OPERATIONS_BY_TYPE avoids any drift.\nJSON_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"JSON\"]}\nTABLE_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"Table\"]}\nTEXT_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"Text\"]}\n\n# Each input type maps to its main input field and its default output. \"Text\"\n# normally outputs a Message; \"JSON\" a Data; \"Table\" a DataFrame. A few text\n# operations override this (Word Count -> Data, Text to DataFrame -> DataFrame).\nINPUT_TYPE_TO_MAIN_INPUT = {\"Text\": \"text_input\", \"JSON\": \"data\", \"Table\": \"df\"}\n\n# Case conversions for the Text \"Case Conversion\" operation.\nCASE_CONVERTERS: dict[str, Any] = {\n \"uppercase\": str.upper,\n \"lowercase\": str.lower,\n \"title\": str.title,\n \"capitalize\": str.capitalize,\n \"swapcase\": str.swapcase,\n}\n\n\nclass OperationsComponent(Component):\n display_name = \"Data Operations\"\n description = \"Perform operations on Text, JSON, and Tables from a single component.\"\n documentation: str = \"https://docs.langflow.org/components-processing#operations\"\n icon = \"wand-sparkles\"\n name = \"Operations\"\n metadata = {\n \"keywords\": [\n \"operations\",\n \"data operations\",\n \"json\",\n \"json operations\",\n \"table\",\n \"table operations\",\n \"dataframe\",\n \"dataframe operations\",\n \"text\",\n \"text operations\",\n \"select keys\",\n \"literal eval\",\n \"combine\",\n \"append or update\",\n \"remove keys\",\n \"rename keys\",\n \"path selection\",\n \"jq expression\",\n \"parse json\",\n \"add column\",\n \"concatenate\",\n \"drop column\",\n \"filter\",\n \"head\",\n \"merge\",\n \"rename column\",\n \"replace value\",\n \"select columns\",\n \"sort\",\n \"tail\",\n \"drop duplicates\",\n \"word count\",\n \"case conversion\",\n \"text replace\",\n \"text extract\",\n \"text join\",\n \"text clean\",\n \"text to dataframe\",\n \"data manipulation\",\n \"data transformation\",\n ],\n }\n\n # Operation -> operation-specific input fields to reveal when selected.\n OPERATION_FIELDS: dict[str, list[str]] = {\n # JSON\n \"Select Keys\": [\"select_keys_input\"],\n \"Literal Eval\": [],\n \"Combine\": [],\n \"Append or Update\": [\"append_update_data\"],\n \"Remove Keys\": [\"remove_keys_input\"],\n \"Rename Keys\": [\"rename_keys_input\"],\n \"Path Selection\": [\"mapped_json_display\", \"selected_key\"],\n \"JQ Expression\": [\"query\"],\n # Table\n \"Add Column\": [\"new_column_name\", \"new_column_value\"],\n \"Concatenate\": [],\n \"Drop Column\": [\"column_name\"],\n \"Filter\": [\"column_name\", \"filter_value\", \"filter_operator\"],\n \"Head\": [\"num_rows\"],\n \"Merge\": [\"left_dataframe\", \"right_dataframe\", \"merge_on_column\", \"merge_how\"],\n \"Rename Column\": [\"column_name\", \"new_column_name\"],\n \"Replace Value\": [\"column_name\", \"replace_value\", \"replacement_value\"],\n \"Select Columns\": [\"columns_to_select\"],\n \"Sort\": [\"column_name\", \"ascending\"],\n \"Tail\": [\"num_rows\"],\n \"Drop Duplicates\": [\"column_name\"],\n # Text\n \"Word Count\": [\"count_words\", \"count_characters\", \"count_lines\"],\n \"Case Conversion\": [\"case_type\"],\n \"Text Replace\": [\"search_pattern\", \"replacement_text\", \"use_regex\"],\n \"Text Extract\": [\"extract_pattern\", \"max_matches\"],\n \"Text Head\": [\"head_characters\"],\n \"Text Tail\": [\"tail_characters\"],\n \"Text Strip\": [\"strip_mode\", \"strip_characters\"],\n \"Text Join\": [\"text_input_2\"],\n \"Text Clean\": [\"remove_extra_spaces\", \"remove_special_chars\", \"remove_empty_lines\"],\n \"Text to DataFrame\": [\"table_separator\", \"has_header\"],\n }\n\n # The three main inputs (one per data type). They are never treated as\n # operation-specific fields; the input-type selector toggles them.\n MAIN_INPUTS = (\"text_input\", \"data\", \"df\")\n\n # Every operation-specific field (union of all the lists above), used to\n # hide and reset fields whenever the input type or operation changes.\n ALL_OPERATION_FIELDS: list[str] = [\n # JSON\n \"select_keys_input\",\n \"append_update_data\",\n \"remove_keys_input\",\n \"rename_keys_input\",\n \"mapped_json_display\",\n \"selected_key\",\n \"query\",\n # Table\n \"column_name\",\n \"filter_value\",\n \"filter_operator\",\n \"ascending\",\n \"new_column_name\",\n \"new_column_value\",\n \"columns_to_select\",\n \"num_rows\",\n \"replace_value\",\n \"replacement_value\",\n \"left_dataframe\",\n \"right_dataframe\",\n \"merge_on_column\",\n \"merge_how\",\n # Text\n \"table_separator\",\n \"has_header\",\n \"count_words\",\n \"count_characters\",\n \"count_lines\",\n \"case_type\",\n \"use_regex\",\n \"search_pattern\",\n \"replacement_text\",\n \"extract_pattern\",\n \"max_matches\",\n \"head_characters\",\n \"tail_characters\",\n \"strip_mode\",\n \"strip_characters\",\n \"text_input_2\",\n \"remove_extra_spaces\",\n \"remove_special_chars\",\n \"remove_empty_lines\",\n ]\n\n # Defaults applied to the JSON operation fields when the operation changes,\n # mirroring the JSON Operations component's reset behavior.\n OPERATION_FIELD_DEFAULTS: dict[str, Any] = {\n \"select_keys_input\": [],\n \"append_update_data\": {\"key\": \"value\"},\n \"remove_keys_input\": [],\n \"rename_keys_input\": {\"old_key\": \"new_key\"},\n \"mapped_json_display\": \"\",\n \"selected_key\": None,\n \"query\": \"\",\n }\n\n inputs = [\n # --- Input type selector: drives operations, input, and output ---\n TabInput(\n name=\"input_type\",\n display_name=\"Input Type\",\n options=INPUT_TYPES,\n value=\"Text\",\n info=\"Select the type of input to operate on.\",\n real_time_refresh=True,\n ),\n # --- Main inputs: one per data type, shown contextually ---\n MultilineInput(\n name=\"text_input\",\n display_name=\"Text\",\n info=\"The input text to process.\",\n show=True,\n ),\n DataInput(\n name=\"data\",\n display_name=\"JSON\",\n info=\"The JSON / Data object to operate on.\",\n is_list=True,\n show=False,\n ),\n DataFrameInput(\n name=\"df\",\n display_name=\"Table\",\n info=\"The input Table to operate on. Connect multiple Tables for merge or concatenate operations.\",\n is_list=True,\n show=False,\n ),\n # --- Operation picker (options are filtered by Input Type) ---\n SortableListInput(\n name=\"operation\",\n display_name=\"Operation\",\n placeholder=\"Select Operation\",\n info=\"Select the operation to perform. The matching fields and output appear once you choose one.\",\n options=OPERATIONS_BY_TYPE[\"Text\"],\n real_time_refresh=True,\n limit=1,\n ),\n # --- JSON operation fields ---\n MessageTextInput(\n name=\"select_keys_input\",\n display_name=\"Select Keys\",\n info=\"List of keys to select from the data. Only top-level keys can be selected.\",\n show=False,\n is_list=True,\n value=[],\n ),\n DictInput(\n name=\"append_update_data\",\n display_name=\"Append or Update\",\n info=\"Data to append or update the existing data with. Only top-level keys are checked.\",\n show=False,\n value={\"key\": \"value\"},\n is_list=True,\n ),\n MessageTextInput(\n name=\"remove_keys_input\",\n display_name=\"Remove Keys\",\n info=\"List of keys to remove from the data.\",\n show=False,\n is_list=True,\n value=[],\n ),\n DictInput(\n name=\"rename_keys_input\",\n display_name=\"Rename Keys\",\n info=\"List of keys to rename in the data.\",\n show=False,\n is_list=True,\n value={\"old_key\": \"new_key\"},\n ),\n MultilineInput(\n name=\"mapped_json_display\",\n display_name=\"JSON to Map\",\n info=\"Paste or preview your JSON here to explore its structure and select a path for extraction.\",\n required=False,\n refresh_button=True,\n real_time_refresh=True,\n placeholder=\"Add a JSON example.\",\n show=False,\n ),\n DropdownInput(\n name=\"selected_key\",\n display_name=\"Select Path\",\n options=[],\n required=False,\n dynamic=True,\n show=False,\n value=None,\n ),\n MessageTextInput(\n name=\"query\",\n display_name=\"JQ Expression\",\n info=\"JSON Query to filter the data. Used by Path Selection and JQ Expression operations.\",\n placeholder=\"e.g., .properties.id\",\n show=False,\n ),\n # --- Table operation fields ---\n StrInput(\n name=\"column_name\",\n display_name=\"Column Name\",\n info=\"The column name to use for the operation.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"filter_value\",\n display_name=\"Filter Value\",\n info=\"The value to filter rows by.\",\n dynamic=True,\n show=False,\n ),\n DropdownInput(\n name=\"filter_operator\",\n display_name=\"Filter Operator\",\n options=[\n \"equals\",\n \"not equals\",\n \"contains\",\n \"not contains\",\n \"starts with\",\n \"ends with\",\n \"greater than\",\n \"less than\",\n ],\n value=\"equals\",\n info=\"The operator to apply for filtering rows.\",\n advanced=False,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"ascending\",\n display_name=\"Sort Ascending\",\n info=\"Whether to sort in ascending order.\",\n dynamic=True,\n show=False,\n value=True,\n ),\n StrInput(\n name=\"new_column_name\",\n display_name=\"New Column Name\",\n info=\"The new column name when renaming or adding a column.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"new_column_value\",\n display_name=\"New Column Value\",\n info=\"The value to populate the new column with.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"columns_to_select\",\n display_name=\"Columns to Select\",\n dynamic=True,\n is_list=True,\n show=False,\n ),\n IntInput(\n name=\"num_rows\",\n display_name=\"Number of Rows\",\n info=\"Number of rows to return (for head/tail).\",\n dynamic=True,\n show=False,\n value=5,\n ),\n MessageTextInput(\n name=\"replace_value\",\n display_name=\"Value to Replace\",\n info=\"The value to replace in the column.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"replacement_value\",\n display_name=\"Replacement Value\",\n info=\"The value to replace with.\",\n dynamic=True,\n show=False,\n ),\n DataFrameInput(\n name=\"left_dataframe\",\n display_name=\"Left Table\",\n info=\"The left (primary) Table for merge operations. \"\n \"In a left merge, all rows from this table are preserved.\",\n dynamic=True,\n show=False,\n ),\n DataFrameInput(\n name=\"right_dataframe\",\n display_name=\"Right Table\",\n info=\"The right (secondary) Table for merge operations. \"\n \"In a right merge, all rows from this table are preserved.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"merge_on_column\",\n display_name=\"Merge On Column\",\n info=\"The column name to merge Tables on. Must exist in both Tables.\",\n dynamic=True,\n show=False,\n ),\n DropdownInput(\n name=\"merge_how\",\n display_name=\"Merge Type\",\n options=[\"inner\", \"outer\", \"left\", \"right\"],\n value=\"inner\",\n info=\"Type of merge: inner (intersection), outer (union), left, or right.\",\n dynamic=True,\n show=False,\n ),\n # --- Text operation fields ---\n StrInput(\n name=\"table_separator\",\n display_name=\"Table Separator\",\n info=\"Separator used in the table (default: '|').\",\n value=\"|\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"has_header\",\n display_name=\"Has Header\",\n info=\"Whether the table has a header row.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_words\",\n display_name=\"Count Words\",\n info=\"Include word count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_characters\",\n display_name=\"Count Characters\",\n info=\"Include character count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_lines\",\n display_name=\"Count Lines\",\n info=\"Include line count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n DropdownInput(\n name=\"case_type\",\n display_name=\"Case Type\",\n options=[\"uppercase\", \"lowercase\", \"title\", \"capitalize\", \"swapcase\"],\n value=\"lowercase\",\n info=\"Type of case conversion to apply.\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"use_regex\",\n display_name=\"Use Regex\",\n info=\"Whether to treat search pattern as regex.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"search_pattern\",\n display_name=\"Search Pattern\",\n info=\"Text pattern to search for (supports regex).\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"replacement_text\",\n display_name=\"Replacement Text\",\n info=\"Text to replace the search pattern with.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"extract_pattern\",\n display_name=\"Extract Pattern\",\n info=\"Regex pattern to extract from text.\",\n dynamic=True,\n show=False,\n ),\n IntInput(\n name=\"max_matches\",\n display_name=\"Max Matches\",\n info=\"Maximum number of matches to extract.\",\n value=10,\n dynamic=True,\n show=False,\n ),\n IntInput(\n name=\"head_characters\",\n display_name=\"Characters from Start\",\n info=\"Number of characters to extract from the beginning of text. Must be non-negative.\",\n value=100,\n dynamic=True,\n show=False,\n range_spec=RangeSpec(min=0, max=1000000, step=1, step_type=\"int\"),\n ),\n IntInput(\n name=\"tail_characters\",\n display_name=\"Characters from End\",\n info=\"Number of characters to extract from the end of text. Must be non-negative.\",\n value=100,\n dynamic=True,\n show=False,\n range_spec=RangeSpec(min=0, max=1000000, step=1, step_type=\"int\"),\n ),\n DropdownInput(\n name=\"strip_mode\",\n display_name=\"Strip Mode\",\n options=[\"both\", \"left\", \"right\"],\n value=\"both\",\n info=\"Which sides to strip whitespace from.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"strip_characters\",\n display_name=\"Characters to Strip\",\n info=\"Specific characters to remove (leave empty for whitespace).\",\n value=\"\",\n dynamic=True,\n show=False,\n ),\n MultilineInput(\n name=\"text_input_2\",\n display_name=\"Second Text Input\",\n info=\"Second text to join with the first text.\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_extra_spaces\",\n display_name=\"Remove Extra Spaces\",\n info=\"Remove multiple consecutive spaces.\",\n value=True,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_special_chars\",\n display_name=\"Remove Special Characters\",\n info=\"Remove special characters except alphanumeric and spaces.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_empty_lines\",\n display_name=\"Remove Empty Lines\",\n info=\"Remove empty lines from text.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n ]\n\n # Default output matches the default Input Type (\"Text\" -> Message).\n # update_outputs / update_frontend_node narrow it to the selected type and\n # operation.\n outputs = [Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\")]\n\n # ------------------------------------------------------------------\n # Operation routing helpers\n # ------------------------------------------------------------------\n @staticmethod\n def _extract_operation_name(field_value: Any) -> str:\n \"\"\"Extract the operation name from a SortableListInput value.\"\"\"\n if isinstance(field_value, list) and len(field_value) > 0 and isinstance(field_value[0], dict):\n return field_value[0].get(\"name\", \"\")\n if isinstance(field_value, str):\n return field_value\n return \"\"\n\n def _operation_name(self) -> str:\n \"\"\"Get the currently selected operation name.\"\"\"\n return self._extract_operation_name(getattr(self, \"operation\", []))\n\n @staticmethod\n def _default_output_for_type(input_type: str) -> Output:\n \"\"\"Return the output advertised for an input type when no operation is selected yet.\"\"\"\n if input_type == \"JSON\":\n return Output(display_name=\"JSON\", name=\"data_output\", method=\"as_data\")\n if input_type == \"Table\":\n return Output(display_name=\"Table\", name=\"dataframe_output\", method=\"as_dataframe\")\n return Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\")\n\n # ------------------------------------------------------------------\n # Dynamic UI\n # ------------------------------------------------------------------\n def _reset_operation_fields(self, build_config: dotdict) -> None:\n \"\"\"Hide every operation-specific field and restore its default value.\"\"\"\n for field in self.ALL_OPERATION_FIELDS:\n if field in build_config:\n build_config[field][\"show\"] = False\n if field in self.OPERATION_FIELD_DEFAULTS:\n build_config[field][\"value\"] = self.OPERATION_FIELD_DEFAULTS[field]\n\n def _show_main_input(self, build_config: dotdict, input_type: str, operation: str) -> None:\n \"\"\"Show only the main input that matches the input type; hide the others.\"\"\"\n for inp in self.MAIN_INPUTS:\n if inp in build_config:\n build_config[inp][\"show\"] = False\n build_config[inp][\"required\"] = False\n\n main_input = INPUT_TYPE_TO_MAIN_INPUT.get(input_type)\n if main_input and main_input in build_config:\n build_config[main_input][\"show\"] = True\n build_config[main_input][\"required\"] = True\n # The JSON \"Combine\" operation consumes a list of Data objects.\n if main_input == \"data\":\n build_config[\"data\"][\"is_list\"] = operation == \"Combine\"\n\n def update_build_config(self, build_config: dotdict, field_value: Any, field_name: str | None = None) -> dotdict:\n # Path Selection: refresh the available JSON paths from the pasted JSON.\n if field_name == \"mapped_json_display\":\n try:\n parsed_json = json.loads(field_value)\n keys = self.extract_all_paths(parsed_json)\n build_config[\"selected_key\"][\"options\"] = keys\n build_config[\"selected_key\"][\"show\"] = True\n except (json.JSONDecodeError, TypeError, ValueError) as e:\n logger.error(f\"Error parsing mapped JSON: {e}\")\n build_config[\"selected_key\"][\"show\"] = False\n return build_config\n\n # Input type changed: swap the operation list, clear the selection, and\n # show only the matching input. No operation-specific fields are shown\n # until an operation is picked.\n if field_name == \"input_type\":\n input_type = field_value if field_value in OPERATIONS_BY_TYPE else \"Text\"\n build_config[\"operation\"][\"options\"] = OPERATIONS_BY_TYPE[input_type]\n build_config[\"operation\"][\"value\"] = []\n self._reset_operation_fields(build_config)\n self._show_main_input(build_config, input_type, operation=\"\")\n return build_config\n\n # Operation changed: reset fields, show the input for the current type,\n # then reveal the operation-specific fields.\n if field_name == \"operation\":\n operation = self._extract_operation_name(field_value)\n self._reset_operation_fields(build_config)\n\n input_type = build_config.get(\"input_type\", {}).get(\"value\", \"Text\")\n self._show_main_input(build_config, input_type, operation)\n\n for field in self.OPERATION_FIELDS.get(operation, []):\n if field in build_config:\n build_config[field][\"show\"] = True\n\n return build_config\n\n return build_config\n\n def update_outputs(self, frontend_node: dict, field_name: str, field_value: Any) -> dict:\n \"\"\"Create the output(s) appropriate to the selected input type and operation.\"\"\"\n if field_name == \"input_type\":\n # Switching type clears the operation; advertise the type's default.\n input_type = field_value if field_value in OPERATIONS_BY_TYPE else \"Text\"\n frontend_node[\"outputs\"] = [self._default_output_for_type(input_type)]\n return frontend_node\n\n template = frontend_node.get(\"template\", {})\n input_type = template.get(\"input_type\", {}).get(\"value\", \"Text\")\n\n if field_name == \"operation\":\n operation = self._extract_operation_name(field_value)\n else:\n # Any other refresh (e.g. Path Selection's \"JSON to Map\" field)\n # reaches here on a freshly rebuilt node whose outputs were reset\n # to the class default (Message). Re-derive the output from the\n # saved operation so the refresh doesn't swap the real output type.\n operation = self._extract_operation_name(template.get(\"operation\", {}).get(\"value\", []))\n\n if not operation:\n # No operation selected: fall back to the input type's default output.\n frontend_node[\"outputs\"] = [self._default_output_for_type(input_type)]\n return frontend_node\n\n frontend_node[\"outputs\"] = []\n if operation in JSON_OPERATIONS or operation == \"Word Count\":\n frontend_node[\"outputs\"].append(Output(display_name=\"JSON\", name=\"data_output\", method=\"as_data\"))\n elif operation in TABLE_OPERATIONS or operation == \"Text to DataFrame\":\n frontend_node[\"outputs\"].append(\n Output(display_name=\"Table\", name=\"dataframe_output\", method=\"as_dataframe\")\n )\n elif operation == \"Text Join\":\n frontend_node[\"outputs\"].append(Output(display_name=\"Text\", name=\"text_output\", method=\"as_text\"))\n frontend_node[\"outputs\"].append(Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\"))\n else:\n frontend_node[\"outputs\"].append(Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\"))\n\n return frontend_node\n\n async def update_frontend_node(self, new_frontend_node: dict, current_frontend_node: dict) -> dict:\n \"\"\"Keep the operation options and outputs in sync with the saved input type on load.\"\"\"\n await super().update_frontend_node(new_frontend_node, current_frontend_node)\n\n template = new_frontend_node.get(\"template\", {})\n input_type = template.get(\"input_type\", {}).get(\"value\", \"Text\")\n if input_type not in OPERATIONS_BY_TYPE:\n input_type = \"Text\"\n\n # Filter the operation picker to the saved input type.\n if \"operation\" in template:\n template[\"operation\"][\"options\"] = OPERATIONS_BY_TYPE[input_type]\n\n # Re-derive the outputs from the saved input type + operation.\n operation_value = template.get(\"operation\", {}).get(\"value\", [])\n if self._extract_operation_name(operation_value):\n self.update_outputs(new_frontend_node, \"operation\", operation_value)\n else:\n self.update_outputs(new_frontend_node, \"input_type\", input_type)\n\n return new_frontend_node\n\n # ==================================================================\n # Output methods (referenced by update_outputs)\n # ==================================================================\n def as_data(self) -> Data:\n \"\"\"JSON-typed output: JSON operations and Word Count.\"\"\"\n operation = self._operation_name()\n if operation in JSON_OPERATIONS:\n handler = self._json_handlers().get(operation)\n if handler:\n try:\n return handler()\n except Exception as e:\n logger.error(f\"Error executing {operation}: {e!s}\")\n raise\n if operation == \"Word Count\":\n return self._word_count_data()\n return Data(data={})\n\n def as_dataframe(self) -> DataFrame:\n \"\"\"Table-typed output: Table operations and Text to DataFrame.\"\"\"\n operation = self._operation_name()\n if operation in TABLE_OPERATIONS:\n return self._run_table_operation(operation)\n if operation == \"Text to DataFrame\":\n return self._text_to_dataframe(getattr(self, \"text_input\", \"\") or \"\")\n return DataFrame(pd.DataFrame())\n\n def as_message(self) -> Message:\n \"\"\"Message-typed output: generic text operations (and Text Join).\"\"\"\n return Message(text=self._format_result_as_text(self._run_text_operation()))\n\n def as_text(self) -> Message:\n \"\"\"Text output for the Text Join operation.\"\"\"\n return self.as_message()\n\n # ==================================================================\n # JSON operations\n # ==================================================================\n @staticmethod\n def extract_all_paths(obj, path=\"\"):\n paths = []\n if isinstance(obj, dict):\n for k, v in obj.items():\n new_path = f\"{path}.{k}\" if path else f\".{k}\"\n paths.append(new_path)\n paths.extend(OperationsComponent.extract_all_paths(v, new_path))\n elif isinstance(obj, list) and obj:\n new_path = f\"{path}[0]\"\n paths.append(new_path)\n paths.extend(OperationsComponent.extract_all_paths(obj[0], new_path))\n return paths\n\n @staticmethod\n def remove_keys_recursive(obj, keys_to_remove):\n if isinstance(obj, dict):\n return {\n k: OperationsComponent.remove_keys_recursive(v, keys_to_remove)\n for k, v in obj.items()\n if k not in keys_to_remove\n }\n if isinstance(obj, list):\n return [OperationsComponent.remove_keys_recursive(item, keys_to_remove) for item in obj]\n return obj\n\n @staticmethod\n def rename_keys_recursive(obj, rename_map):\n if isinstance(obj, dict):\n return {\n rename_map.get(k, k): OperationsComponent.rename_keys_recursive(v, rename_map) for k, v in obj.items()\n }\n if isinstance(obj, list):\n return [OperationsComponent.rename_keys_recursive(item, rename_map) for item in obj]\n return obj\n\n def _json_handlers(self) -> \"dict[str, Callable[[], Data]]\":\n return {\n \"Select Keys\": self.select_keys,\n \"Literal Eval\": self.evaluate_data,\n \"Combine\": self.combine_data,\n \"Append or Update\": self.append_update,\n \"Remove Keys\": self.remove_keys,\n \"Rename Keys\": self.rename_keys,\n \"Path Selection\": self.json_path,\n \"JQ Expression\": self.json_query,\n }\n\n def get_data_dict(self) -> dict:\n \"\"\"Extract data dictionary from Data object.\"\"\"\n data = self.data[0] if isinstance(self.data, list) and len(self.data) == 1 else self.data\n return data.model_dump()\n\n def get_normalized_data(self) -> dict:\n \"\"\"Get normalized data dictionary, handling the 'data' key if present.\"\"\"\n data_dict = self.get_data_dict()\n return data_dict.get(\"data\", data_dict)\n\n def data_is_list(self) -> bool:\n \"\"\"Check if data contains multiple items.\"\"\"\n return isinstance(self.data, list) and len(self.data) > 1\n\n def validate_single_data(self, operation: str) -> None:\n \"\"\"Validate that the operation is being performed on a single data object.\"\"\"\n if self.data_is_list():\n msg = f\"{operation} operation is not supported for multiple data objects.\"\n raise ValueError(msg)\n\n def select_keys(self) -> Data:\n \"\"\"Select specific keys from the data dictionary.\"\"\"\n self.validate_single_data(\"Select Keys\")\n data_dict = self.get_normalized_data()\n filter_criteria: list[str] = self.select_keys_input\n\n if len(filter_criteria) == 1 and filter_criteria[0] == \"data\":\n filtered = data_dict[\"data\"]\n else:\n if not all(key in data_dict for key in filter_criteria):\n msg = f\"Select key not found in data. Available keys: {list(data_dict.keys())}\"\n raise ValueError(msg)\n filtered = {key: value for key, value in data_dict.items() if key in filter_criteria}\n\n return Data(data=filtered)\n\n def remove_keys(self) -> Data:\n \"\"\"Remove specified keys from the data dictionary, recursively.\"\"\"\n self.validate_single_data(\"Remove Keys\")\n data_dict = self.get_normalized_data()\n remove_keys_input: list[str] = self.remove_keys_input\n filtered = OperationsComponent.remove_keys_recursive(data_dict, set(remove_keys_input))\n return Data(data=filtered)\n\n def rename_keys(self) -> Data:\n \"\"\"Rename keys in the data dictionary, recursively.\"\"\"\n self.validate_single_data(\"Rename Keys\")\n data_dict = self.get_normalized_data()\n rename_keys_input: dict[str, str] = self.rename_keys_input\n renamed = OperationsComponent.rename_keys_recursive(data_dict, rename_keys_input)\n return Data(data=renamed)\n\n def recursive_eval(self, data: Any) -> Any:\n \"\"\"Recursively evaluate string values that look like Python literals.\"\"\"\n if isinstance(data, dict):\n return {k: self.recursive_eval(v) for k, v in data.items()}\n if isinstance(data, list):\n return [self.recursive_eval(item) for item in data]\n if isinstance(data, str):\n try:\n if (\n data.strip().startswith((\"{\", \"[\", \"(\", \"'\", '\"'))\n or data.strip().lower() in (\"true\", \"false\", \"none\")\n or data.strip().replace(\".\", \"\").isdigit()\n ):\n return ast.literal_eval(data)\n except (ValueError, SyntaxError, TypeError, MemoryError):\n return data\n else:\n return data\n return data\n\n def evaluate_data(self) -> Data:\n \"\"\"Evaluate string values in the data dictionary.\"\"\"\n self.validate_single_data(\"Literal Eval\")\n logger.info(\"evaluating data\")\n return Data(**self.recursive_eval(self.get_data_dict()))\n\n def combine_data(self) -> Data:\n \"\"\"Combine multiple data objects into one.\"\"\"\n logger.info(\"combining data\")\n if not self.data_is_list():\n return self.data[0] if self.data else Data(data={})\n\n data_dicts = [data.model_dump().get(\"data\", data.model_dump()) for data in self.data]\n combined_data: dict[str, Any] = {}\n\n for data_dict in data_dicts:\n for key, value in data_dict.items():\n if key not in combined_data:\n combined_data[key] = value\n elif isinstance(combined_data[key], list):\n if isinstance(value, list):\n combined_data[key].extend(value)\n else:\n combined_data[key].append(value)\n else:\n combined_data[key] = (\n [combined_data[key], value] if not isinstance(value, list) else [combined_data[key], *value]\n )\n\n return Data(**combined_data)\n\n def append_update(self) -> Data:\n \"\"\"Append or update the data with new key-value pairs.\"\"\"\n self.validate_single_data(\"Append or Update\")\n data_filtered = self.get_normalized_data()\n for key, value in self.append_update_data.items():\n data_filtered[key] = value\n return Data(**data_filtered)\n\n def json_path(self) -> Data:\n \"\"\"Extract a value from the data using the selected JQ path.\"\"\"\n try:\n import jq\n except ImportError:\n msg = \"jq is required for Path Selection. Install with: pip install jq\"\n raise ImportError(msg) from None\n\n try:\n if not self.data or not self.selected_key:\n msg = \"Missing input data or selected key.\"\n raise ValueError(msg)\n input_payload = self.data[0].data if isinstance(self.data, list) else self.data.data\n compiled = jq.compile(self.selected_key)\n result = compiled.input(input_payload).first()\n if isinstance(result, dict):\n return Data(data=result)\n return Data(data={\"result\": result})\n except (ValueError, TypeError, KeyError) as e:\n self.status = f\"Error: {e!s}\"\n self.log(self.status)\n return Data(data={\"error\": str(e)})\n\n def json_query(self) -> Data:\n \"\"\"Run a JQ expression against the data.\"\"\"\n try:\n import jq\n except ImportError:\n msg = \"jq is required for JQ Expression. Install with: pip install jq\"\n raise ImportError(msg) from None\n\n if not self.query or not self.query.strip():\n msg = \"JSON Query is required and cannot be blank.\"\n raise ValueError(msg)\n raw_data = self.get_data_dict()\n try:\n input_str = json.dumps(raw_data)\n repaired = repair_json(input_str)\n data_json = json.loads(repaired)\n jq_input = data_json[\"data\"] if isinstance(data_json, dict) and \"data\" in data_json else data_json\n results = jq.compile(self.query).input(jq_input).all()\n if not results:\n msg = \"No result from JSON query.\"\n raise ValueError(msg)\n result = results[0] if len(results) == 1 else results\n if result is None or result == \"None\":\n msg = \"JSON query returned null/None. Check if the path exists in your data.\"\n raise ValueError(msg)\n if isinstance(result, dict):\n return Data(data=result)\n return Data(data={\"result\": result})\n except (ValueError, TypeError, KeyError, json.JSONDecodeError) as e:\n logger.error(f\"JSON Query failed: {e}\")\n msg = f\"JSON Query error: {e}\"\n raise ValueError(msg) from e\n\n # ==================================================================\n # Table operations\n # ==================================================================\n def _get_primary_dataframe(self) -> DataFrame:\n \"\"\"Get the first DataFrame from input (handles both single and list inputs).\"\"\"\n if isinstance(self.df, list):\n return self.df[0].copy() if self.df else DataFrame()\n return self.df.copy()\n\n def _run_table_operation(self, operation: str) -> DataFrame:\n # Merge and Concatenate use their own inputs, not the primary df.\n if operation == \"Merge\":\n return self.merge_dataframes()\n if operation == \"Concatenate\":\n return self.concatenate_dataframes()\n\n df_copy = self._get_primary_dataframe()\n table_handlers = {\n \"Filter\": self.filter_rows_by_value,\n \"Sort\": self.sort_by_column,\n \"Drop Column\": self.drop_column,\n \"Rename Column\": self.rename_column,\n \"Add Column\": self.add_column,\n \"Select Columns\": self.select_columns,\n \"Head\": self.head,\n \"Tail\": self.tail,\n \"Replace Value\": self.replace_values,\n \"Drop Duplicates\": self.drop_duplicates,\n }\n handler = table_handlers.get(operation)\n if handler is None:\n msg = f\"Unsupported operation: {operation}\"\n logger.error(msg)\n raise ValueError(msg)\n return handler(df_copy)\n\n def filter_rows_by_value(self, df: DataFrame) -> DataFrame:\n column = df[self.column_name]\n filter_value = self.filter_value\n operator = getattr(self, \"filter_operator\", \"equals\")\n\n if operator == \"equals\":\n mask = column == filter_value\n elif operator == \"not equals\":\n mask = column != filter_value\n elif operator == \"contains\":\n mask = column.astype(str).str.contains(str(filter_value), na=False)\n elif operator == \"not contains\":\n mask = ~column.astype(str).str.contains(str(filter_value), na=False)\n elif operator == \"starts with\":\n mask = column.astype(str).str.startswith(str(filter_value), na=False)\n elif operator == \"ends with\":\n mask = column.astype(str).str.endswith(str(filter_value), na=False)\n elif operator == \"greater than\":\n try:\n numeric_value = pd.to_numeric(filter_value)\n mask = column > numeric_value\n except (ValueError, TypeError):\n mask = column.astype(str) > str(filter_value)\n elif operator == \"less than\":\n try:\n numeric_value = pd.to_numeric(filter_value)\n mask = column < numeric_value\n except (ValueError, TypeError):\n mask = column.astype(str) < str(filter_value)\n else:\n mask = column == filter_value\n\n return DataFrame(df[mask])\n\n def sort_by_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.sort_values(by=self.column_name, ascending=self.ascending))\n\n def drop_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.drop(columns=[self.column_name]))\n\n def rename_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.rename(columns={self.column_name: self.new_column_name}))\n\n def add_column(self, df: DataFrame) -> DataFrame:\n df[self.new_column_name] = [self.new_column_value] * len(df)\n return DataFrame(df)\n\n def select_columns(self, df: DataFrame) -> DataFrame:\n columns = [col.strip() for col in self.columns_to_select]\n return DataFrame(df[columns])\n\n def head(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.head(self.num_rows))\n\n def tail(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.tail(self.num_rows))\n\n def replace_values(self, df: DataFrame) -> DataFrame:\n df[self.column_name] = df[self.column_name].replace(self.replace_value, self.replacement_value)\n return DataFrame(df)\n\n def drop_duplicates(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.drop_duplicates(subset=self.column_name))\n\n def concatenate_dataframes(self) -> DataFrame:\n \"\"\"Concatenate multiple DataFrames vertically (stack rows).\"\"\"\n if not isinstance(self.df, list) or len(self.df) == 0:\n return self.df.copy() if self.df is not None else DataFrame()\n\n if len(self.df) == 1:\n return self.df[0].copy()\n\n concatenated = pd.concat(self.df, ignore_index=True)\n return DataFrame(concatenated)\n\n def merge_dataframes(self) -> DataFrame:\n \"\"\"Merge two DataFrames based on a common column (join operation).\"\"\"\n left_df = getattr(self, \"left_dataframe\", None)\n right_df = getattr(self, \"right_dataframe\", None)\n\n if left_df is None:\n return DataFrame()\n if right_df is None:\n return left_df.copy()\n\n df_left = left_df.copy()\n df_right = right_df.copy()\n\n merge_on = getattr(self, \"merge_on_column\", None)\n merge_how = getattr(self, \"merge_how\", \"inner\")\n\n if merge_on:\n if merge_on not in df_left.columns:\n msg = f\"Column '{merge_on}' not found in left DataFrame. Available: {list(df_left.columns)}\"\n raise ValueError(msg)\n if merge_on not in df_right.columns:\n msg = f\"Column '{merge_on}' not found in right DataFrame. Available: {list(df_right.columns)}\"\n raise ValueError(msg)\n merged = df_left.merge(df_right, on=merge_on, how=merge_how, suffixes=(\"\", \"_right\"))\n else:\n merged = df_left.merge(df_right, left_index=True, right_index=True, how=merge_how, suffixes=(\"\", \"_right\"))\n\n cols_to_drop = []\n for col in merged.columns:\n if col.endswith(\"_right\"):\n original_col = col[:-6]\n if original_col in merged.columns:\n merged[original_col] = merged[original_col].combine_first(merged[col])\n cols_to_drop.append(col)\n\n if cols_to_drop:\n merged = merged.drop(columns=cols_to_drop)\n\n return DataFrame(merged)\n\n # ==================================================================\n # Text operations\n # ==================================================================\n def _run_text_operation(self) -> Any:\n \"\"\"Process text based on the selected operation (Message/Text outputs).\"\"\"\n text = getattr(self, \"text_input\", \"\")\n operation = self._operation_name()\n\n # Allow empty text for Text Join (second input may have content).\n if not text and operation != \"Text Join\":\n return None\n\n text_handlers = {\n \"Case Conversion\": self._case_conversion,\n \"Text Replace\": self._text_replace,\n \"Text Extract\": self._text_extract,\n \"Text Head\": self._text_head,\n \"Text Tail\": self._text_tail,\n \"Text Strip\": self._text_strip,\n \"Text Join\": self._text_join,\n \"Text Clean\": self._text_clean,\n }\n handler = text_handlers.get(operation)\n if handler:\n return handler(text)\n return text\n\n def _word_count_data(self) -> Data:\n \"\"\"Word Count operation result as a Data object.\"\"\"\n result = self._word_count(getattr(self, \"text_input\", \"\") or \"\")\n return Data(data=result)\n\n def _word_count(self, text: str) -> dict[str, Any]:\n \"\"\"Count words, characters, and lines in text.\"\"\"\n result: dict[str, Any] = {}\n text_str = str(text) if text else \"\"\n is_empty = not text_str or not text_str.strip()\n\n if getattr(self, \"count_words\", True):\n if is_empty:\n result[\"word_count\"] = 0\n result[\"unique_words\"] = 0\n else:\n words = text_str.split()\n result[\"word_count\"] = len(words)\n result[\"unique_words\"] = len(set(words))\n\n if getattr(self, \"count_characters\", True):\n if is_empty:\n result[\"character_count\"] = 0\n result[\"character_count_no_spaces\"] = 0\n else:\n result[\"character_count\"] = len(text_str)\n result[\"character_count_no_spaces\"] = len(text_str.replace(\" \", \"\"))\n\n if getattr(self, \"count_lines\", True):\n if is_empty:\n result[\"line_count\"] = 0\n result[\"non_empty_lines\"] = 0\n else:\n lines = text_str.split(\"\\n\")\n result[\"line_count\"] = len(lines)\n result[\"non_empty_lines\"] = len([line for line in lines if line.strip()])\n\n return result\n\n def _text_to_dataframe(self, text: str) -> DataFrame:\n \"\"\"Convert markdown-style table text to a DataFrame.\"\"\"\n lines = [line.strip() for line in text.strip().split(\"\\n\") if line.strip()]\n if not lines:\n return DataFrame(pd.DataFrame())\n\n separator = getattr(self, \"table_separator\", \"|\")\n has_header = getattr(self, \"has_header\", True)\n\n rows = self._parse_table_rows(lines, separator)\n if not rows:\n return DataFrame(pd.DataFrame())\n\n df = self._create_dataframe(rows, has_header=has_header)\n self._convert_numeric_columns(df)\n self.log(f\"Converted text to DataFrame: {len(df)} rows, {len(df.columns)} columns\")\n return DataFrame(df)\n\n def _parse_table_rows(self, lines: list[str], separator: str) -> list[list[str]]:\n rows = []\n for line in lines:\n cleaned_line = line.strip(separator)\n cells = [cell.strip() for cell in cleaned_line.split(separator)]\n rows.append(cells)\n return rows\n\n def _create_dataframe(self, rows: list[list[str]], *, has_header: bool) -> pd.DataFrame:\n if has_header and len(rows) > 1:\n header = rows[0]\n data_rows = rows[1:]\n header_col_count = len(header)\n for i, row in enumerate(data_rows):\n row_col_count = len(row)\n if row_col_count != header_col_count:\n msg = (\n f\"Header mismatch: {header_col_count} column(s) in header vs \"\n f\"{row_col_count} column(s) in data row {i + 1}. \"\n \"Please ensure the header has the same number of columns as your data.\"\n )\n raise ValueError(msg)\n return pd.DataFrame(data_rows, columns=header)\n\n max_cols = max(len(row) for row in rows) if rows else 0\n columns = [f\"col_{i}\" for i in range(max_cols)]\n return pd.DataFrame(rows, columns=columns)\n\n def _convert_numeric_columns(self, df: pd.DataFrame) -> None:\n for col in df.columns:\n with contextlib.suppress(ValueError, TypeError):\n df[col] = pd.to_numeric(df[col])\n\n def _case_conversion(self, text: str) -> str:\n case_type = getattr(self, \"case_type\", \"lowercase\")\n converter = CASE_CONVERTERS.get(case_type)\n return converter(text) if converter else text\n\n def _text_replace(self, text: str) -> str:\n search_pattern = getattr(self, \"search_pattern\", \"\")\n if not search_pattern:\n return text\n replacement_text = getattr(self, \"replacement_text\", \"\")\n use_regex = getattr(self, \"use_regex\", False)\n if use_regex:\n try:\n return re.sub(search_pattern, replacement_text, text)\n except re.error as e:\n self.log(f\"Invalid regex pattern: {e}\")\n return text\n return text.replace(search_pattern, replacement_text)\n\n def _text_extract(self, text: str) -> list[str]:\n extract_pattern = getattr(self, \"extract_pattern\", \"\")\n if not extract_pattern:\n return []\n max_matches = getattr(self, \"max_matches\", 10)\n try:\n matches = re.findall(extract_pattern, text)\n except re.error as e:\n msg = f\"Invalid regex pattern '{extract_pattern}': {e}\"\n raise ValueError(msg) from e\n return matches[:max_matches] if max_matches > 0 else matches\n\n def _text_head(self, text: str) -> str:\n head_characters = getattr(self, \"head_characters\", 100)\n if head_characters < 0:\n msg = f\"Characters from Start must be a non-negative integer, got {head_characters}\"\n raise ValueError(msg)\n if head_characters == 0:\n return \"\"\n return text[:head_characters]\n\n def _text_tail(self, text: str) -> str:\n tail_characters = getattr(self, \"tail_characters\", 100)\n if tail_characters < 0:\n msg = f\"Characters from End must be a non-negative integer, got {tail_characters}\"\n raise ValueError(msg)\n if tail_characters == 0:\n return \"\"\n return text[-tail_characters:]\n\n def _text_strip(self, text: str) -> str:\n strip_mode = getattr(self, \"strip_mode\", \"both\")\n strip_characters = getattr(self, \"strip_characters\", \"\")\n text_str = str(text) if text else \"\"\n chars_to_strip = strip_characters if strip_characters else None\n if strip_mode == \"left\":\n return text_str.lstrip(chars_to_strip)\n if strip_mode == \"right\":\n return text_str.rstrip(chars_to_strip)\n return text_str.strip(chars_to_strip)\n\n def _text_join(self, text: str) -> str:\n text_input_2 = getattr(self, \"text_input_2\", \"\")\n text1 = str(text) if text else \"\"\n text2 = str(text_input_2) if text_input_2 else \"\"\n if text1 and text2:\n return f\"{text1}\\n{text2}\"\n return text1 or text2\n\n def _text_clean(self, text: str) -> str:\n result = text\n if getattr(self, \"remove_extra_spaces\", True):\n # Collapse runs of horizontal whitespace but preserve newlines so\n # that remove_empty_lines stays effective when both are enabled.\n result = re.sub(r\"[^\\S\\n]+\", \" \", result)\n if getattr(self, \"remove_special_chars\", False):\n result = re.sub(r\"[^\\w\\s]\", \"\", result)\n if getattr(self, \"remove_empty_lines\", False):\n lines = [line for line in result.split(\"\\n\") if line.strip()]\n result = \"\\n\".join(lines)\n return result\n\n def _format_result_as_text(self, result: Any) -> str:\n if result is None:\n return \"\"\n if isinstance(result, list):\n return \"\\n\".join(str(item) for item in result)\n return str(result)\n"+ "value": "\"\"\"Unified Operations component.\n\nBrings together the previously separate JSON, Table, and Text operation\ncomponents into a single component. An \"Input Type\" selector (Text / JSON /\nTable) drives everything: it filters the \"Operation\" picker to the operations\nthat apply to that type, reveals the matching input (Text / JSON / Table) and\nits operation-specific fields, and advertises the appropriate output type.\n\nThe three original components (JSON Operations, Table Operations, Text\nOperations) remain available as legacy components for backward compatibility\nwith existing flows.\n\"\"\"\n\nimport ast\nimport contextlib\nimport json\nimport re\nfrom typing import TYPE_CHECKING, Any\n\nimport pandas as pd\nfrom json_repair import repair_json\n\nfrom lfx.custom import Component\nfrom lfx.field_typing import RangeSpec\nfrom lfx.inputs import DictInput, SortableListInput, TabInput\nfrom lfx.io import (\n BoolInput,\n DataFrameInput,\n DataInput,\n DropdownInput,\n IntInput,\n MessageTextInput,\n MultilineInput,\n Output,\n StrInput,\n)\nfrom lfx.log.logger import logger\nfrom lfx.schema import Data\nfrom lfx.schema.dataframe import DataFrame\nfrom lfx.schema.dotdict import dotdict\nfrom lfx.schema.message import Message\nfrom lfx.utils.jq_security import validate_jq_program\n\nif TYPE_CHECKING:\n from collections.abc import Callable\n\n# The \"Input Type\" selector tabs. Each value maps a Langflow data type to the\n# operations, input, and output that belong to it.\nINPUT_TYPES = [\"Text\", \"JSON\", \"Table\"]\n\n# Operations grouped by input type, in display order, each with the icon shown\n# in the Operation picker. This is the single source of truth for the picker;\n# update_build_config swaps the picker's options to the selected type's list.\nOPERATIONS_BY_TYPE: dict[str, list[dict[str, str]]] = {\n \"Text\": [\n {\"name\": \"Word Count\", \"icon\": \"hash\"},\n {\"name\": \"Case Conversion\", \"icon\": \"type\"},\n {\"name\": \"Text Replace\", \"icon\": \"replace\"},\n {\"name\": \"Text Extract\", \"icon\": \"search\"},\n {\"name\": \"Text Head\", \"icon\": \"chevron-left\"},\n {\"name\": \"Text Tail\", \"icon\": \"chevron-right\"},\n {\"name\": \"Text Strip\", \"icon\": \"minus\"},\n {\"name\": \"Text Join\", \"icon\": \"link\"},\n {\"name\": \"Text Clean\", \"icon\": \"sparkles\"},\n {\"name\": \"Text to DataFrame\", \"icon\": \"table\"},\n ],\n \"JSON\": [\n {\"name\": \"Select Keys\", \"icon\": \"lasso-select\"},\n {\"name\": \"Literal Eval\", \"icon\": \"braces\"},\n {\"name\": \"Combine\", \"icon\": \"merge\"},\n {\"name\": \"Append or Update\", \"icon\": \"circle-plus\"},\n {\"name\": \"Remove Keys\", \"icon\": \"eraser\"},\n {\"name\": \"Rename Keys\", \"icon\": \"pencil-line\"},\n {\"name\": \"Path Selection\", \"icon\": \"mouse-pointer\"},\n {\"name\": \"JQ Expression\", \"icon\": \"terminal\"},\n ],\n \"Table\": [\n {\"name\": \"Add Column\", \"icon\": \"plus\"},\n {\"name\": \"Concatenate\", \"icon\": \"combine\"},\n {\"name\": \"Drop Column\", \"icon\": \"minus\"},\n {\"name\": \"Filter\", \"icon\": \"filter\"},\n {\"name\": \"Head\", \"icon\": \"arrow-up\"},\n {\"name\": \"Merge\", \"icon\": \"merge\"},\n {\"name\": \"Rename Column\", \"icon\": \"pencil\"},\n {\"name\": \"Replace Value\", \"icon\": \"replace\"},\n {\"name\": \"Select Columns\", \"icon\": \"columns\"},\n {\"name\": \"Sort\", \"icon\": \"arrow-up-down\"},\n {\"name\": \"Tail\", \"icon\": \"arrow-down\"},\n {\"name\": \"Drop Duplicates\", \"icon\": \"copy-x\"},\n ],\n}\n\n# Operation-name sets derived from the picker, used for dispatch and output\n# routing. Keeping them derived from OPERATIONS_BY_TYPE avoids any drift.\nJSON_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"JSON\"]}\nTABLE_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"Table\"]}\nTEXT_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"Text\"]}\n\n# Each input type maps to its main input field and its default output. \"Text\"\n# normally outputs a Message; \"JSON\" a Data; \"Table\" a DataFrame. A few text\n# operations override this (Word Count -> Data, Text to DataFrame -> DataFrame).\nINPUT_TYPE_TO_MAIN_INPUT = {\"Text\": \"text_input\", \"JSON\": \"data\", \"Table\": \"df\"}\n\n# Case conversions for the Text \"Case Conversion\" operation.\nCASE_CONVERTERS: dict[str, Any] = {\n \"uppercase\": str.upper,\n \"lowercase\": str.lower,\n \"title\": str.title,\n \"capitalize\": str.capitalize,\n \"swapcase\": str.swapcase,\n}\n\n\nclass OperationsComponent(Component):\n display_name = \"Data Operations\"\n description = \"Perform operations on Text, JSON, and Tables from a single component.\"\n documentation: str = \"https://docs.langflow.org/components-processing#operations\"\n icon = \"wand-sparkles\"\n name = \"Operations\"\n metadata = {\n \"keywords\": [\n \"operations\",\n \"data operations\",\n \"json\",\n \"json operations\",\n \"table\",\n \"table operations\",\n \"dataframe\",\n \"dataframe operations\",\n \"text\",\n \"text operations\",\n \"select keys\",\n \"literal eval\",\n \"combine\",\n \"append or update\",\n \"remove keys\",\n \"rename keys\",\n \"path selection\",\n \"jq expression\",\n \"parse json\",\n \"add column\",\n \"concatenate\",\n \"drop column\",\n \"filter\",\n \"head\",\n \"merge\",\n \"rename column\",\n \"replace value\",\n \"select columns\",\n \"sort\",\n \"tail\",\n \"drop duplicates\",\n \"word count\",\n \"case conversion\",\n \"text replace\",\n \"text extract\",\n \"text join\",\n \"text clean\",\n \"text to dataframe\",\n \"data manipulation\",\n \"data transformation\",\n ],\n }\n\n # Operation -> operation-specific input fields to reveal when selected.\n OPERATION_FIELDS: dict[str, list[str]] = {\n # JSON\n \"Select Keys\": [\"select_keys_input\"],\n \"Literal Eval\": [],\n \"Combine\": [],\n \"Append or Update\": [\"append_update_data\"],\n \"Remove Keys\": [\"remove_keys_input\"],\n \"Rename Keys\": [\"rename_keys_input\"],\n \"Path Selection\": [\"mapped_json_display\", \"selected_key\"],\n \"JQ Expression\": [\"query\"],\n # Table\n \"Add Column\": [\"new_column_name\", \"new_column_value\"],\n \"Concatenate\": [],\n \"Drop Column\": [\"column_name\"],\n \"Filter\": [\"column_name\", \"filter_value\", \"filter_operator\"],\n \"Head\": [\"num_rows\"],\n \"Merge\": [\"left_dataframe\", \"right_dataframe\", \"merge_on_column\", \"merge_how\"],\n \"Rename Column\": [\"column_name\", \"new_column_name\"],\n \"Replace Value\": [\"column_name\", \"replace_value\", \"replacement_value\"],\n \"Select Columns\": [\"columns_to_select\"],\n \"Sort\": [\"column_name\", \"ascending\"],\n \"Tail\": [\"num_rows\"],\n \"Drop Duplicates\": [\"column_name\"],\n # Text\n \"Word Count\": [\"count_words\", \"count_characters\", \"count_lines\"],\n \"Case Conversion\": [\"case_type\"],\n \"Text Replace\": [\"search_pattern\", \"replacement_text\", \"use_regex\"],\n \"Text Extract\": [\"extract_pattern\", \"max_matches\"],\n \"Text Head\": [\"head_characters\"],\n \"Text Tail\": [\"tail_characters\"],\n \"Text Strip\": [\"strip_mode\", \"strip_characters\"],\n \"Text Join\": [\"text_input_2\"],\n \"Text Clean\": [\"remove_extra_spaces\", \"remove_special_chars\", \"remove_empty_lines\"],\n \"Text to DataFrame\": [\"table_separator\", \"has_header\"],\n }\n\n # The three main inputs (one per data type). They are never treated as\n # operation-specific fields; the input-type selector toggles them.\n MAIN_INPUTS = (\"text_input\", \"data\", \"df\")\n\n # Every operation-specific field (union of all the lists above), used to\n # hide and reset fields whenever the input type or operation changes.\n ALL_OPERATION_FIELDS: list[str] = [\n # JSON\n \"select_keys_input\",\n \"append_update_data\",\n \"remove_keys_input\",\n \"rename_keys_input\",\n \"mapped_json_display\",\n \"selected_key\",\n \"query\",\n # Table\n \"column_name\",\n \"filter_value\",\n \"filter_operator\",\n \"ascending\",\n \"new_column_name\",\n \"new_column_value\",\n \"columns_to_select\",\n \"num_rows\",\n \"replace_value\",\n \"replacement_value\",\n \"left_dataframe\",\n \"right_dataframe\",\n \"merge_on_column\",\n \"merge_how\",\n # Text\n \"table_separator\",\n \"has_header\",\n \"count_words\",\n \"count_characters\",\n \"count_lines\",\n \"case_type\",\n \"use_regex\",\n \"search_pattern\",\n \"replacement_text\",\n \"extract_pattern\",\n \"max_matches\",\n \"head_characters\",\n \"tail_characters\",\n \"strip_mode\",\n \"strip_characters\",\n \"text_input_2\",\n \"remove_extra_spaces\",\n \"remove_special_chars\",\n \"remove_empty_lines\",\n ]\n\n # Defaults applied to the JSON operation fields when the operation changes,\n # mirroring the JSON Operations component's reset behavior.\n OPERATION_FIELD_DEFAULTS: dict[str, Any] = {\n \"select_keys_input\": [],\n \"append_update_data\": {\"key\": \"value\"},\n \"remove_keys_input\": [],\n \"rename_keys_input\": {\"old_key\": \"new_key\"},\n \"mapped_json_display\": \"\",\n \"selected_key\": None,\n \"query\": \"\",\n }\n\n inputs = [\n # --- Input type selector: drives operations, input, and output ---\n TabInput(\n name=\"input_type\",\n display_name=\"Input Type\",\n options=INPUT_TYPES,\n value=\"Text\",\n info=\"Select the type of input to operate on.\",\n real_time_refresh=True,\n ),\n # --- Main inputs: one per data type, shown contextually ---\n MultilineInput(\n name=\"text_input\",\n display_name=\"Text\",\n info=\"The input text to process.\",\n show=True,\n ),\n DataInput(\n name=\"data\",\n display_name=\"JSON\",\n info=\"The JSON / Data object to operate on.\",\n is_list=True,\n show=False,\n ),\n DataFrameInput(\n name=\"df\",\n display_name=\"Table\",\n info=\"The input Table to operate on. Connect multiple Tables for merge or concatenate operations.\",\n is_list=True,\n show=False,\n ),\n # --- Operation picker (options are filtered by Input Type) ---\n SortableListInput(\n name=\"operation\",\n display_name=\"Operation\",\n placeholder=\"Select Operation\",\n info=\"Select the operation to perform. The matching fields and output appear once you choose one.\",\n options=OPERATIONS_BY_TYPE[\"Text\"],\n real_time_refresh=True,\n limit=1,\n ),\n # --- JSON operation fields ---\n MessageTextInput(\n name=\"select_keys_input\",\n display_name=\"Select Keys\",\n info=\"List of keys to select from the data. Only top-level keys can be selected.\",\n show=False,\n is_list=True,\n value=[],\n ),\n DictInput(\n name=\"append_update_data\",\n display_name=\"Append or Update\",\n info=\"Data to append or update the existing data with. Only top-level keys are checked.\",\n show=False,\n value={\"key\": \"value\"},\n is_list=True,\n ),\n MessageTextInput(\n name=\"remove_keys_input\",\n display_name=\"Remove Keys\",\n info=\"List of keys to remove from the data.\",\n show=False,\n is_list=True,\n value=[],\n ),\n DictInput(\n name=\"rename_keys_input\",\n display_name=\"Rename Keys\",\n info=\"List of keys to rename in the data.\",\n show=False,\n is_list=True,\n value={\"old_key\": \"new_key\"},\n ),\n MultilineInput(\n name=\"mapped_json_display\",\n display_name=\"JSON to Map\",\n info=\"Paste or preview your JSON here to explore its structure and select a path for extraction.\",\n required=False,\n refresh_button=True,\n real_time_refresh=True,\n placeholder=\"Add a JSON example.\",\n show=False,\n ),\n DropdownInput(\n name=\"selected_key\",\n display_name=\"Select Path\",\n options=[],\n required=False,\n dynamic=True,\n show=False,\n value=None,\n ),\n MessageTextInput(\n name=\"query\",\n display_name=\"JQ Expression\",\n info=\"JSON Query to filter the data. Used by Path Selection and JQ Expression operations.\",\n placeholder=\"e.g., .properties.id\",\n show=False,\n ),\n # --- Table operation fields ---\n StrInput(\n name=\"column_name\",\n display_name=\"Column Name\",\n info=\"The column name to use for the operation.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"filter_value\",\n display_name=\"Filter Value\",\n info=\"The value to filter rows by.\",\n dynamic=True,\n show=False,\n ),\n DropdownInput(\n name=\"filter_operator\",\n display_name=\"Filter Operator\",\n options=[\n \"equals\",\n \"not equals\",\n \"contains\",\n \"not contains\",\n \"starts with\",\n \"ends with\",\n \"greater than\",\n \"less than\",\n ],\n value=\"equals\",\n info=\"The operator to apply for filtering rows.\",\n advanced=False,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"ascending\",\n display_name=\"Sort Ascending\",\n info=\"Whether to sort in ascending order.\",\n dynamic=True,\n show=False,\n value=True,\n ),\n StrInput(\n name=\"new_column_name\",\n display_name=\"New Column Name\",\n info=\"The new column name when renaming or adding a column.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"new_column_value\",\n display_name=\"New Column Value\",\n info=\"The value to populate the new column with.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"columns_to_select\",\n display_name=\"Columns to Select\",\n dynamic=True,\n is_list=True,\n show=False,\n ),\n IntInput(\n name=\"num_rows\",\n display_name=\"Number of Rows\",\n info=\"Number of rows to return (for head/tail).\",\n dynamic=True,\n show=False,\n value=5,\n ),\n MessageTextInput(\n name=\"replace_value\",\n display_name=\"Value to Replace\",\n info=\"The value to replace in the column.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"replacement_value\",\n display_name=\"Replacement Value\",\n info=\"The value to replace with.\",\n dynamic=True,\n show=False,\n ),\n DataFrameInput(\n name=\"left_dataframe\",\n display_name=\"Left Table\",\n info=\"The left (primary) Table for merge operations. \"\n \"In a left merge, all rows from this table are preserved.\",\n dynamic=True,\n show=False,\n ),\n DataFrameInput(\n name=\"right_dataframe\",\n display_name=\"Right Table\",\n info=\"The right (secondary) Table for merge operations. \"\n \"In a right merge, all rows from this table are preserved.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"merge_on_column\",\n display_name=\"Merge On Column\",\n info=\"The column name to merge Tables on. Must exist in both Tables.\",\n dynamic=True,\n show=False,\n ),\n DropdownInput(\n name=\"merge_how\",\n display_name=\"Merge Type\",\n options=[\"inner\", \"outer\", \"left\", \"right\"],\n value=\"inner\",\n info=\"Type of merge: inner (intersection), outer (union), left, or right.\",\n dynamic=True,\n show=False,\n ),\n # --- Text operation fields ---\n StrInput(\n name=\"table_separator\",\n display_name=\"Table Separator\",\n info=\"Separator used in the table (default: '|').\",\n value=\"|\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"has_header\",\n display_name=\"Has Header\",\n info=\"Whether the table has a header row.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_words\",\n display_name=\"Count Words\",\n info=\"Include word count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_characters\",\n display_name=\"Count Characters\",\n info=\"Include character count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_lines\",\n display_name=\"Count Lines\",\n info=\"Include line count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n DropdownInput(\n name=\"case_type\",\n display_name=\"Case Type\",\n options=[\"uppercase\", \"lowercase\", \"title\", \"capitalize\", \"swapcase\"],\n value=\"lowercase\",\n info=\"Type of case conversion to apply.\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"use_regex\",\n display_name=\"Use Regex\",\n info=\"Whether to treat search pattern as regex.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"search_pattern\",\n display_name=\"Search Pattern\",\n info=\"Text pattern to search for (supports regex).\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"replacement_text\",\n display_name=\"Replacement Text\",\n info=\"Text to replace the search pattern with.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"extract_pattern\",\n display_name=\"Extract Pattern\",\n info=\"Regex pattern to extract from text.\",\n dynamic=True,\n show=False,\n ),\n IntInput(\n name=\"max_matches\",\n display_name=\"Max Matches\",\n info=\"Maximum number of matches to extract.\",\n value=10,\n dynamic=True,\n show=False,\n ),\n IntInput(\n name=\"head_characters\",\n display_name=\"Characters from Start\",\n info=\"Number of characters to extract from the beginning of text. Must be non-negative.\",\n value=100,\n dynamic=True,\n show=False,\n range_spec=RangeSpec(min=0, max=1000000, step=1, step_type=\"int\"),\n ),\n IntInput(\n name=\"tail_characters\",\n display_name=\"Characters from End\",\n info=\"Number of characters to extract from the end of text. Must be non-negative.\",\n value=100,\n dynamic=True,\n show=False,\n range_spec=RangeSpec(min=0, max=1000000, step=1, step_type=\"int\"),\n ),\n DropdownInput(\n name=\"strip_mode\",\n display_name=\"Strip Mode\",\n options=[\"both\", \"left\", \"right\"],\n value=\"both\",\n info=\"Which sides to strip whitespace from.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"strip_characters\",\n display_name=\"Characters to Strip\",\n info=\"Specific characters to remove (leave empty for whitespace).\",\n value=\"\",\n dynamic=True,\n show=False,\n ),\n MultilineInput(\n name=\"text_input_2\",\n display_name=\"Second Text Input\",\n info=\"Second text to join with the first text.\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_extra_spaces\",\n display_name=\"Remove Extra Spaces\",\n info=\"Remove multiple consecutive spaces.\",\n value=True,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_special_chars\",\n display_name=\"Remove Special Characters\",\n info=\"Remove special characters except alphanumeric and spaces.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_empty_lines\",\n display_name=\"Remove Empty Lines\",\n info=\"Remove empty lines from text.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n ]\n\n # Default output matches the default Input Type (\"Text\" -> Message).\n # update_outputs / update_frontend_node narrow it to the selected type and\n # operation.\n outputs = [Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\")]\n\n # ------------------------------------------------------------------\n # Operation routing helpers\n # ------------------------------------------------------------------\n @staticmethod\n def _extract_operation_name(field_value: Any) -> str:\n \"\"\"Extract the operation name from a SortableListInput value.\"\"\"\n if isinstance(field_value, list) and len(field_value) > 0 and isinstance(field_value[0], dict):\n return field_value[0].get(\"name\", \"\")\n if isinstance(field_value, str):\n return field_value\n return \"\"\n\n def _operation_name(self) -> str:\n \"\"\"Get the currently selected operation name.\"\"\"\n return self._extract_operation_name(getattr(self, \"operation\", []))\n\n @staticmethod\n def _default_output_for_type(input_type: str) -> Output:\n \"\"\"Return the output advertised for an input type when no operation is selected yet.\"\"\"\n if input_type == \"JSON\":\n return Output(display_name=\"JSON\", name=\"data_output\", method=\"as_data\")\n if input_type == \"Table\":\n return Output(display_name=\"Table\", name=\"dataframe_output\", method=\"as_dataframe\")\n return Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\")\n\n # ------------------------------------------------------------------\n # Dynamic UI\n # ------------------------------------------------------------------\n def _reset_operation_fields(self, build_config: dotdict) -> None:\n \"\"\"Hide every operation-specific field and restore its default value.\"\"\"\n for field in self.ALL_OPERATION_FIELDS:\n if field in build_config:\n build_config[field][\"show\"] = False\n if field in self.OPERATION_FIELD_DEFAULTS:\n build_config[field][\"value\"] = self.OPERATION_FIELD_DEFAULTS[field]\n\n def _show_main_input(self, build_config: dotdict, input_type: str, operation: str) -> None:\n \"\"\"Show only the main input that matches the input type; hide the others.\"\"\"\n for inp in self.MAIN_INPUTS:\n if inp in build_config:\n build_config[inp][\"show\"] = False\n build_config[inp][\"required\"] = False\n\n main_input = INPUT_TYPE_TO_MAIN_INPUT.get(input_type)\n if main_input and main_input in build_config:\n build_config[main_input][\"show\"] = True\n build_config[main_input][\"required\"] = True\n # The JSON \"Combine\" operation consumes a list of Data objects.\n if main_input == \"data\":\n build_config[\"data\"][\"is_list\"] = operation == \"Combine\"\n\n def update_build_config(self, build_config: dotdict, field_value: Any, field_name: str | None = None) -> dotdict:\n # Path Selection: refresh the available JSON paths from the pasted JSON.\n if field_name == \"mapped_json_display\":\n try:\n parsed_json = json.loads(field_value)\n keys = self.extract_all_paths(parsed_json)\n build_config[\"selected_key\"][\"options\"] = keys\n build_config[\"selected_key\"][\"show\"] = True\n except (json.JSONDecodeError, TypeError, ValueError) as e:\n logger.error(f\"Error parsing mapped JSON: {e}\")\n build_config[\"selected_key\"][\"show\"] = False\n return build_config\n\n # Input type changed: swap the operation list, clear the selection, and\n # show only the matching input. No operation-specific fields are shown\n # until an operation is picked.\n if field_name == \"input_type\":\n input_type = field_value if field_value in OPERATIONS_BY_TYPE else \"Text\"\n build_config[\"operation\"][\"options\"] = OPERATIONS_BY_TYPE[input_type]\n build_config[\"operation\"][\"value\"] = []\n self._reset_operation_fields(build_config)\n self._show_main_input(build_config, input_type, operation=\"\")\n return build_config\n\n # Operation changed: reset fields, show the input for the current type,\n # then reveal the operation-specific fields.\n if field_name == \"operation\":\n operation = self._extract_operation_name(field_value)\n self._reset_operation_fields(build_config)\n\n input_type = build_config.get(\"input_type\", {}).get(\"value\", \"Text\")\n self._show_main_input(build_config, input_type, operation)\n\n for field in self.OPERATION_FIELDS.get(operation, []):\n if field in build_config:\n build_config[field][\"show\"] = True\n\n return build_config\n\n return build_config\n\n def update_outputs(self, frontend_node: dict, field_name: str, field_value: Any) -> dict:\n \"\"\"Create the output(s) appropriate to the selected input type and operation.\"\"\"\n if field_name == \"input_type\":\n # Switching type clears the operation; advertise the type's default.\n input_type = field_value if field_value in OPERATIONS_BY_TYPE else \"Text\"\n frontend_node[\"outputs\"] = [self._default_output_for_type(input_type)]\n return frontend_node\n\n template = frontend_node.get(\"template\", {})\n input_type = template.get(\"input_type\", {}).get(\"value\", \"Text\")\n\n if field_name == \"operation\":\n operation = self._extract_operation_name(field_value)\n else:\n # Any other refresh (e.g. Path Selection's \"JSON to Map\" field)\n # reaches here on a freshly rebuilt node whose outputs were reset\n # to the class default (Message). Re-derive the output from the\n # saved operation so the refresh doesn't swap the real output type.\n operation = self._extract_operation_name(template.get(\"operation\", {}).get(\"value\", []))\n\n if not operation:\n # No operation selected: fall back to the input type's default output.\n frontend_node[\"outputs\"] = [self._default_output_for_type(input_type)]\n return frontend_node\n\n frontend_node[\"outputs\"] = []\n if operation in JSON_OPERATIONS or operation == \"Word Count\":\n frontend_node[\"outputs\"].append(Output(display_name=\"JSON\", name=\"data_output\", method=\"as_data\"))\n elif operation in TABLE_OPERATIONS or operation == \"Text to DataFrame\":\n frontend_node[\"outputs\"].append(\n Output(display_name=\"Table\", name=\"dataframe_output\", method=\"as_dataframe\")\n )\n elif operation == \"Text Join\":\n frontend_node[\"outputs\"].append(Output(display_name=\"Text\", name=\"text_output\", method=\"as_text\"))\n frontend_node[\"outputs\"].append(Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\"))\n else:\n frontend_node[\"outputs\"].append(Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\"))\n\n return frontend_node\n\n async def update_frontend_node(self, new_frontend_node: dict, current_frontend_node: dict) -> dict:\n \"\"\"Keep the operation options and outputs in sync with the saved input type on load.\"\"\"\n await super().update_frontend_node(new_frontend_node, current_frontend_node)\n\n template = new_frontend_node.get(\"template\", {})\n input_type = template.get(\"input_type\", {}).get(\"value\", \"Text\")\n if input_type not in OPERATIONS_BY_TYPE:\n input_type = \"Text\"\n\n # Filter the operation picker to the saved input type.\n if \"operation\" in template:\n template[\"operation\"][\"options\"] = OPERATIONS_BY_TYPE[input_type]\n\n # Re-derive the outputs from the saved input type + operation.\n operation_value = template.get(\"operation\", {}).get(\"value\", [])\n if self._extract_operation_name(operation_value):\n self.update_outputs(new_frontend_node, \"operation\", operation_value)\n else:\n self.update_outputs(new_frontend_node, \"input_type\", input_type)\n\n return new_frontend_node\n\n # ==================================================================\n # Output methods (referenced by update_outputs)\n # ==================================================================\n def as_data(self) -> Data:\n \"\"\"JSON-typed output: JSON operations and Word Count.\"\"\"\n operation = self._operation_name()\n if operation in JSON_OPERATIONS:\n handler = self._json_handlers().get(operation)\n if handler:\n try:\n return handler()\n except Exception as e:\n logger.error(f\"Error executing {operation}: {e!s}\")\n raise\n if operation == \"Word Count\":\n return self._word_count_data()\n return Data(data={})\n\n def as_dataframe(self) -> DataFrame:\n \"\"\"Table-typed output: Table operations and Text to DataFrame.\"\"\"\n operation = self._operation_name()\n if operation in TABLE_OPERATIONS:\n return self._run_table_operation(operation)\n if operation == \"Text to DataFrame\":\n return self._text_to_dataframe(getattr(self, \"text_input\", \"\") or \"\")\n return DataFrame(pd.DataFrame())\n\n def as_message(self) -> Message:\n \"\"\"Message-typed output: generic text operations (and Text Join).\"\"\"\n return Message(text=self._format_result_as_text(self._run_text_operation()))\n\n def as_text(self) -> Message:\n \"\"\"Text output for the Text Join operation.\"\"\"\n return self.as_message()\n\n # ==================================================================\n # JSON operations\n # ==================================================================\n @staticmethod\n def extract_all_paths(obj, path=\"\"):\n paths = []\n if isinstance(obj, dict):\n for k, v in obj.items():\n new_path = f\"{path}.{k}\" if path else f\".{k}\"\n paths.append(new_path)\n paths.extend(OperationsComponent.extract_all_paths(v, new_path))\n elif isinstance(obj, list) and obj:\n new_path = f\"{path}[0]\"\n paths.append(new_path)\n paths.extend(OperationsComponent.extract_all_paths(obj[0], new_path))\n return paths\n\n @staticmethod\n def remove_keys_recursive(obj, keys_to_remove):\n if isinstance(obj, dict):\n return {\n k: OperationsComponent.remove_keys_recursive(v, keys_to_remove)\n for k, v in obj.items()\n if k not in keys_to_remove\n }\n if isinstance(obj, list):\n return [OperationsComponent.remove_keys_recursive(item, keys_to_remove) for item in obj]\n return obj\n\n @staticmethod\n def rename_keys_recursive(obj, rename_map):\n if isinstance(obj, dict):\n return {\n rename_map.get(k, k): OperationsComponent.rename_keys_recursive(v, rename_map) for k, v in obj.items()\n }\n if isinstance(obj, list):\n return [OperationsComponent.rename_keys_recursive(item, rename_map) for item in obj]\n return obj\n\n def _json_handlers(self) -> \"dict[str, Callable[[], Data]]\":\n return {\n \"Select Keys\": self.select_keys,\n \"Literal Eval\": self.evaluate_data,\n \"Combine\": self.combine_data,\n \"Append or Update\": self.append_update,\n \"Remove Keys\": self.remove_keys,\n \"Rename Keys\": self.rename_keys,\n \"Path Selection\": self.json_path,\n \"JQ Expression\": self.json_query,\n }\n\n def get_data_dict(self) -> dict:\n \"\"\"Extract data dictionary from Data object.\"\"\"\n data = self.data[0] if isinstance(self.data, list) and len(self.data) == 1 else self.data\n return data.model_dump()\n\n def get_normalized_data(self) -> dict:\n \"\"\"Get normalized data dictionary, handling the 'data' key if present.\"\"\"\n data_dict = self.get_data_dict()\n return data_dict.get(\"data\", data_dict)\n\n def data_is_list(self) -> bool:\n \"\"\"Check if data contains multiple items.\"\"\"\n return isinstance(self.data, list) and len(self.data) > 1\n\n def validate_single_data(self, operation: str) -> None:\n \"\"\"Validate that the operation is being performed on a single data object.\"\"\"\n if self.data_is_list():\n msg = f\"{operation} operation is not supported for multiple data objects.\"\n raise ValueError(msg)\n\n def select_keys(self) -> Data:\n \"\"\"Select specific keys from the data dictionary.\"\"\"\n self.validate_single_data(\"Select Keys\")\n data_dict = self.get_normalized_data()\n filter_criteria: list[str] = self.select_keys_input\n\n if len(filter_criteria) == 1 and filter_criteria[0] == \"data\":\n filtered = data_dict[\"data\"]\n else:\n if not all(key in data_dict for key in filter_criteria):\n msg = f\"Select key not found in data. Available keys: {list(data_dict.keys())}\"\n raise ValueError(msg)\n filtered = {key: value for key, value in data_dict.items() if key in filter_criteria}\n\n return Data(data=filtered)\n\n def remove_keys(self) -> Data:\n \"\"\"Remove specified keys from the data dictionary, recursively.\"\"\"\n self.validate_single_data(\"Remove Keys\")\n data_dict = self.get_normalized_data()\n remove_keys_input: list[str] = self.remove_keys_input\n filtered = OperationsComponent.remove_keys_recursive(data_dict, set(remove_keys_input))\n return Data(data=filtered)\n\n def rename_keys(self) -> Data:\n \"\"\"Rename keys in the data dictionary, recursively.\"\"\"\n self.validate_single_data(\"Rename Keys\")\n data_dict = self.get_normalized_data()\n rename_keys_input: dict[str, str] = self.rename_keys_input\n renamed = OperationsComponent.rename_keys_recursive(data_dict, rename_keys_input)\n return Data(data=renamed)\n\n def recursive_eval(self, data: Any) -> Any:\n \"\"\"Recursively evaluate string values that look like Python literals.\"\"\"\n if isinstance(data, dict):\n return {k: self.recursive_eval(v) for k, v in data.items()}\n if isinstance(data, list):\n return [self.recursive_eval(item) for item in data]\n if isinstance(data, str):\n try:\n if (\n data.strip().startswith((\"{\", \"[\", \"(\", \"'\", '\"'))\n or data.strip().lower() in (\"true\", \"false\", \"none\")\n or data.strip().replace(\".\", \"\").isdigit()\n ):\n return ast.literal_eval(data)\n except (ValueError, SyntaxError, TypeError, MemoryError):\n return data\n else:\n return data\n return data\n\n def evaluate_data(self) -> Data:\n \"\"\"Evaluate string values in the data dictionary.\"\"\"\n self.validate_single_data(\"Literal Eval\")\n logger.info(\"evaluating data\")\n return Data(**self.recursive_eval(self.get_data_dict()))\n\n def combine_data(self) -> Data:\n \"\"\"Combine multiple data objects into one.\"\"\"\n logger.info(\"combining data\")\n if not self.data_is_list():\n return self.data[0] if self.data else Data(data={})\n\n data_dicts = [data.model_dump().get(\"data\", data.model_dump()) for data in self.data]\n combined_data: dict[str, Any] = {}\n\n for data_dict in data_dicts:\n for key, value in data_dict.items():\n if key not in combined_data:\n combined_data[key] = value\n elif isinstance(combined_data[key], list):\n if isinstance(value, list):\n combined_data[key].extend(value)\n else:\n combined_data[key].append(value)\n else:\n combined_data[key] = (\n [combined_data[key], value] if not isinstance(value, list) else [combined_data[key], *value]\n )\n\n return Data(**combined_data)\n\n def append_update(self) -> Data:\n \"\"\"Append or update the data with new key-value pairs.\"\"\"\n self.validate_single_data(\"Append or Update\")\n data_filtered = self.get_normalized_data()\n for key, value in self.append_update_data.items():\n data_filtered[key] = value\n return Data(**data_filtered)\n\n def json_path(self) -> Data:\n \"\"\"Extract a value from the data using the selected JQ path.\"\"\"\n try:\n import jq\n except ImportError:\n msg = \"jq is required for Path Selection. Install with: pip install jq\"\n raise ImportError(msg) from None\n\n try:\n if not self.data or not self.selected_key:\n msg = \"Missing input data or selected key.\"\n raise ValueError(msg)\n input_payload = self.data[0].data if isinstance(self.data, list) else self.data.data\n validate_jq_program(self.selected_key)\n compiled = jq.compile(self.selected_key)\n result = compiled.input(input_payload).first()\n if isinstance(result, dict):\n return Data(data=result)\n return Data(data={\"result\": result})\n except (ValueError, TypeError, KeyError) as e:\n self.status = f\"Error: {e!s}\"\n self.log(self.status)\n return Data(data={\"error\": str(e)})\n\n def json_query(self) -> Data:\n \"\"\"Run a JQ expression against the data.\"\"\"\n try:\n import jq\n except ImportError:\n msg = \"jq is required for JQ Expression. Install with: pip install jq\"\n raise ImportError(msg) from None\n\n if not self.query or not self.query.strip():\n msg = \"JSON Query is required and cannot be blank.\"\n raise ValueError(msg)\n raw_data = self.get_data_dict()\n try:\n input_str = json.dumps(raw_data)\n repaired = repair_json(input_str)\n data_json = json.loads(repaired)\n jq_input = data_json[\"data\"] if isinstance(data_json, dict) and \"data\" in data_json else data_json\n validate_jq_program(self.query)\n results = jq.compile(self.query).input(jq_input).all()\n if not results:\n msg = \"No result from JSON query.\"\n raise ValueError(msg)\n result = results[0] if len(results) == 1 else results\n if result is None or result == \"None\":\n msg = \"JSON query returned null/None. Check if the path exists in your data.\"\n raise ValueError(msg)\n if isinstance(result, dict):\n return Data(data=result)\n return Data(data={\"result\": result})\n except (ValueError, TypeError, KeyError, json.JSONDecodeError) as e:\n logger.error(f\"JSON Query failed: {e}\")\n msg = f\"JSON Query error: {e}\"\n raise ValueError(msg) from e\n\n # ==================================================================\n # Table operations\n # ==================================================================\n def _get_primary_dataframe(self) -> DataFrame:\n \"\"\"Get the first DataFrame from input (handles both single and list inputs).\"\"\"\n if isinstance(self.df, list):\n return self.df[0].copy() if self.df else DataFrame()\n return self.df.copy()\n\n def _run_table_operation(self, operation: str) -> DataFrame:\n # Merge and Concatenate use their own inputs, not the primary df.\n if operation == \"Merge\":\n return self.merge_dataframes()\n if operation == \"Concatenate\":\n return self.concatenate_dataframes()\n\n df_copy = self._get_primary_dataframe()\n table_handlers = {\n \"Filter\": self.filter_rows_by_value,\n \"Sort\": self.sort_by_column,\n \"Drop Column\": self.drop_column,\n \"Rename Column\": self.rename_column,\n \"Add Column\": self.add_column,\n \"Select Columns\": self.select_columns,\n \"Head\": self.head,\n \"Tail\": self.tail,\n \"Replace Value\": self.replace_values,\n \"Drop Duplicates\": self.drop_duplicates,\n }\n handler = table_handlers.get(operation)\n if handler is None:\n msg = f\"Unsupported operation: {operation}\"\n logger.error(msg)\n raise ValueError(msg)\n return handler(df_copy)\n\n def filter_rows_by_value(self, df: DataFrame) -> DataFrame:\n column = df[self.column_name]\n filter_value = self.filter_value\n operator = getattr(self, \"filter_operator\", \"equals\")\n\n if operator == \"equals\":\n mask = column == filter_value\n elif operator == \"not equals\":\n mask = column != filter_value\n elif operator == \"contains\":\n mask = column.astype(str).str.contains(str(filter_value), na=False)\n elif operator == \"not contains\":\n mask = ~column.astype(str).str.contains(str(filter_value), na=False)\n elif operator == \"starts with\":\n mask = column.astype(str).str.startswith(str(filter_value), na=False)\n elif operator == \"ends with\":\n mask = column.astype(str).str.endswith(str(filter_value), na=False)\n elif operator == \"greater than\":\n try:\n numeric_value = pd.to_numeric(filter_value)\n mask = column > numeric_value\n except (ValueError, TypeError):\n mask = column.astype(str) > str(filter_value)\n elif operator == \"less than\":\n try:\n numeric_value = pd.to_numeric(filter_value)\n mask = column < numeric_value\n except (ValueError, TypeError):\n mask = column.astype(str) < str(filter_value)\n else:\n mask = column == filter_value\n\n return DataFrame(df[mask])\n\n def sort_by_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.sort_values(by=self.column_name, ascending=self.ascending))\n\n def drop_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.drop(columns=[self.column_name]))\n\n def rename_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.rename(columns={self.column_name: self.new_column_name}))\n\n def add_column(self, df: DataFrame) -> DataFrame:\n df[self.new_column_name] = [self.new_column_value] * len(df)\n return DataFrame(df)\n\n def select_columns(self, df: DataFrame) -> DataFrame:\n columns = [col.strip() for col in self.columns_to_select]\n return DataFrame(df[columns])\n\n def head(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.head(self.num_rows))\n\n def tail(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.tail(self.num_rows))\n\n def replace_values(self, df: DataFrame) -> DataFrame:\n df[self.column_name] = df[self.column_name].replace(self.replace_value, self.replacement_value)\n return DataFrame(df)\n\n def drop_duplicates(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.drop_duplicates(subset=self.column_name))\n\n def concatenate_dataframes(self) -> DataFrame:\n \"\"\"Concatenate multiple DataFrames vertically (stack rows).\"\"\"\n if not isinstance(self.df, list) or len(self.df) == 0:\n return self.df.copy() if self.df is not None else DataFrame()\n\n if len(self.df) == 1:\n return self.df[0].copy()\n\n concatenated = pd.concat(self.df, ignore_index=True)\n return DataFrame(concatenated)\n\n def merge_dataframes(self) -> DataFrame:\n \"\"\"Merge two DataFrames based on a common column (join operation).\"\"\"\n left_df = getattr(self, \"left_dataframe\", None)\n right_df = getattr(self, \"right_dataframe\", None)\n\n if left_df is None:\n return DataFrame()\n if right_df is None:\n return left_df.copy()\n\n df_left = left_df.copy()\n df_right = right_df.copy()\n\n merge_on = getattr(self, \"merge_on_column\", None)\n merge_how = getattr(self, \"merge_how\", \"inner\")\n\n if merge_on:\n if merge_on not in df_left.columns:\n msg = f\"Column '{merge_on}' not found in left DataFrame. Available: {list(df_left.columns)}\"\n raise ValueError(msg)\n if merge_on not in df_right.columns:\n msg = f\"Column '{merge_on}' not found in right DataFrame. Available: {list(df_right.columns)}\"\n raise ValueError(msg)\n merged = df_left.merge(df_right, on=merge_on, how=merge_how, suffixes=(\"\", \"_right\"))\n else:\n merged = df_left.merge(df_right, left_index=True, right_index=True, how=merge_how, suffixes=(\"\", \"_right\"))\n\n cols_to_drop = []\n for col in merged.columns:\n if col.endswith(\"_right\"):\n original_col = col[:-6]\n if original_col in merged.columns:\n merged[original_col] = merged[original_col].combine_first(merged[col])\n cols_to_drop.append(col)\n\n if cols_to_drop:\n merged = merged.drop(columns=cols_to_drop)\n\n return DataFrame(merged)\n\n # ==================================================================\n # Text operations\n # ==================================================================\n def _run_text_operation(self) -> Any:\n \"\"\"Process text based on the selected operation (Message/Text outputs).\"\"\"\n text = getattr(self, \"text_input\", \"\")\n operation = self._operation_name()\n\n # Allow empty text for Text Join (second input may have content).\n if not text and operation != \"Text Join\":\n return None\n\n text_handlers = {\n \"Case Conversion\": self._case_conversion,\n \"Text Replace\": self._text_replace,\n \"Text Extract\": self._text_extract,\n \"Text Head\": self._text_head,\n \"Text Tail\": self._text_tail,\n \"Text Strip\": self._text_strip,\n \"Text Join\": self._text_join,\n \"Text Clean\": self._text_clean,\n }\n handler = text_handlers.get(operation)\n if handler:\n return handler(text)\n return text\n\n def _word_count_data(self) -> Data:\n \"\"\"Word Count operation result as a Data object.\"\"\"\n result = self._word_count(getattr(self, \"text_input\", \"\") or \"\")\n return Data(data=result)\n\n def _word_count(self, text: str) -> dict[str, Any]:\n \"\"\"Count words, characters, and lines in text.\"\"\"\n result: dict[str, Any] = {}\n text_str = str(text) if text else \"\"\n is_empty = not text_str or not text_str.strip()\n\n if getattr(self, \"count_words\", True):\n if is_empty:\n result[\"word_count\"] = 0\n result[\"unique_words\"] = 0\n else:\n words = text_str.split()\n result[\"word_count\"] = len(words)\n result[\"unique_words\"] = len(set(words))\n\n if getattr(self, \"count_characters\", True):\n if is_empty:\n result[\"character_count\"] = 0\n result[\"character_count_no_spaces\"] = 0\n else:\n result[\"character_count\"] = len(text_str)\n result[\"character_count_no_spaces\"] = len(text_str.replace(\" \", \"\"))\n\n if getattr(self, \"count_lines\", True):\n if is_empty:\n result[\"line_count\"] = 0\n result[\"non_empty_lines\"] = 0\n else:\n lines = text_str.split(\"\\n\")\n result[\"line_count\"] = len(lines)\n result[\"non_empty_lines\"] = len([line for line in lines if line.strip()])\n\n return result\n\n def _text_to_dataframe(self, text: str) -> DataFrame:\n \"\"\"Convert markdown-style table text to a DataFrame.\"\"\"\n lines = [line.strip() for line in text.strip().split(\"\\n\") if line.strip()]\n if not lines:\n return DataFrame(pd.DataFrame())\n\n separator = getattr(self, \"table_separator\", \"|\")\n has_header = getattr(self, \"has_header\", True)\n\n rows = self._parse_table_rows(lines, separator)\n if not rows:\n return DataFrame(pd.DataFrame())\n\n df = self._create_dataframe(rows, has_header=has_header)\n self._convert_numeric_columns(df)\n self.log(f\"Converted text to DataFrame: {len(df)} rows, {len(df.columns)} columns\")\n return DataFrame(df)\n\n def _parse_table_rows(self, lines: list[str], separator: str) -> list[list[str]]:\n rows = []\n for line in lines:\n cleaned_line = line.strip(separator)\n cells = [cell.strip() for cell in cleaned_line.split(separator)]\n rows.append(cells)\n return rows\n\n def _create_dataframe(self, rows: list[list[str]], *, has_header: bool) -> pd.DataFrame:\n if has_header and len(rows) > 1:\n header = rows[0]\n data_rows = rows[1:]\n header_col_count = len(header)\n for i, row in enumerate(data_rows):\n row_col_count = len(row)\n if row_col_count != header_col_count:\n msg = (\n f\"Header mismatch: {header_col_count} column(s) in header vs \"\n f\"{row_col_count} column(s) in data row {i + 1}. \"\n \"Please ensure the header has the same number of columns as your data.\"\n )\n raise ValueError(msg)\n return pd.DataFrame(data_rows, columns=header)\n\n max_cols = max(len(row) for row in rows) if rows else 0\n columns = [f\"col_{i}\" for i in range(max_cols)]\n return pd.DataFrame(rows, columns=columns)\n\n def _convert_numeric_columns(self, df: pd.DataFrame) -> None:\n for col in df.columns:\n with contextlib.suppress(ValueError, TypeError):\n df[col] = pd.to_numeric(df[col])\n\n def _case_conversion(self, text: str) -> str:\n case_type = getattr(self, \"case_type\", \"lowercase\")\n converter = CASE_CONVERTERS.get(case_type)\n return converter(text) if converter else text\n\n def _text_replace(self, text: str) -> str:\n search_pattern = getattr(self, \"search_pattern\", \"\")\n if not search_pattern:\n return text\n replacement_text = getattr(self, \"replacement_text\", \"\")\n use_regex = getattr(self, \"use_regex\", False)\n if use_regex:\n try:\n return re.sub(search_pattern, replacement_text, text)\n except re.error as e:\n self.log(f\"Invalid regex pattern: {e}\")\n return text\n return text.replace(search_pattern, replacement_text)\n\n def _text_extract(self, text: str) -> list[str]:\n extract_pattern = getattr(self, \"extract_pattern\", \"\")\n if not extract_pattern:\n return []\n max_matches = getattr(self, \"max_matches\", 10)\n try:\n matches = re.findall(extract_pattern, text)\n except re.error as e:\n msg = f\"Invalid regex pattern '{extract_pattern}': {e}\"\n raise ValueError(msg) from e\n return matches[:max_matches] if max_matches > 0 else matches\n\n def _text_head(self, text: str) -> str:\n head_characters = getattr(self, \"head_characters\", 100)\n if head_characters < 0:\n msg = f\"Characters from Start must be a non-negative integer, got {head_characters}\"\n raise ValueError(msg)\n if head_characters == 0:\n return \"\"\n return text[:head_characters]\n\n def _text_tail(self, text: str) -> str:\n tail_characters = getattr(self, \"tail_characters\", 100)\n if tail_characters < 0:\n msg = f\"Characters from End must be a non-negative integer, got {tail_characters}\"\n raise ValueError(msg)\n if tail_characters == 0:\n return \"\"\n return text[-tail_characters:]\n\n def _text_strip(self, text: str) -> str:\n strip_mode = getattr(self, \"strip_mode\", \"both\")\n strip_characters = getattr(self, \"strip_characters\", \"\")\n text_str = str(text) if text else \"\"\n chars_to_strip = strip_characters if strip_characters else None\n if strip_mode == \"left\":\n return text_str.lstrip(chars_to_strip)\n if strip_mode == \"right\":\n return text_str.rstrip(chars_to_strip)\n return text_str.strip(chars_to_strip)\n\n def _text_join(self, text: str) -> str:\n text_input_2 = getattr(self, \"text_input_2\", \"\")\n text1 = str(text) if text else \"\"\n text2 = str(text_input_2) if text_input_2 else \"\"\n if text1 and text2:\n return f\"{text1}\\n{text2}\"\n return text1 or text2\n\n def _text_clean(self, text: str) -> str:\n result = text\n if getattr(self, \"remove_extra_spaces\", True):\n # Collapse runs of horizontal whitespace but preserve newlines so\n # that remove_empty_lines stays effective when both are enabled.\n result = re.sub(r\"[^\\S\\n]+\", \" \", result)\n if getattr(self, \"remove_special_chars\", False):\n result = re.sub(r\"[^\\w\\s]\", \"\", result)\n if getattr(self, \"remove_empty_lines\", False):\n lines = [line for line in result.split(\"\\n\") if line.strip()]\n result = \"\\n\".join(lines)\n return result\n\n def _format_result_as_text(self, result: Any) -> str:\n if result is None:\n return \"\"\n if isinstance(result, list):\n return \"\\n\".join(str(item) for item in result)\n return str(result)\n"},"column_name": {"_input_type": "StrInput",@@ -2906,6 +2908,7 @@"display_name": "Input Type","dynamic": false,"info": "Select the type of input to operate on.",+ "load_from_db": false,"name": "input_type","options": ["Text",@@ -3133,6 +3136,7 @@"dynamic": false,"info": "Select the operation to perform. The matching fields and output appear once you choose one.","limit": 1,+ "load_from_db": false,"name": "operation","options": [{@@ -3717,47 +3721,44 @@},{"data": {- "id": "SplitText-QIKhg",+ "id": "OpenAICompatibleEmbedding-MloZd","node": {"base_classes": [- "Table"+ "Embeddings"],"beta": false,"conditional_paths": [],"custom_fields": {},- "description": "Split text into chunks based on specified criteria.",- "display_name": "Split Text",- "documentation": "https://docs.langflow.org/split-text",+ "description": "Embeddings via OpenRAG's OpenAI-compatible /v1 proxy. Uses the same base URL and hop token as the chat component.",+ "display_name": "OpenRAG Embeddings",+ "documentation": "","edited": false,"field_order": [- "data_inputs",- "chunk_overlap",- "chunk_size",- "separator",- "text_key",- "keep_separator",- "clean_output"+ "model_name",+ "api_key",+ "api_base",+ "dimensions",+ "chunk_size"],"frozen": false,- "icon": "scissors-line-dashed",+ "icon": "OpenRAG","legacy": false,- "lf_version": "0.11.1rc0","metadata": {- "code_hash": "859adebdf672",+ "code_hash": "d4b6a5d67c0b","dependencies": {"dependencies": [{- "name": "langchain_text_splitters",- "version": "1.1.2"+ "name": "langchain_openai",+ "version": "1.5.2"},{"name": "lfx",- "version": null+ "version": "1.11.2"}],"total_dependencies": 2},- "module": "lfx.components.processing.split_text.SplitTextComponent"+ "module": "custom_components.openrag_embeddings"},"minimized": false,"output_types": [],@@ -3765,14 +3766,14 @@{"allows_loop": false,"cache": true,- "display_name": "Chunks",+ "display_name": "Embedding Model","group_outputs": false,- "method": "split_text",- "name": "dataframe",- "selected": "Table",+ "method": "build_embeddings",+ "name": "embeddings",+ "selected": "Embeddings","tool_mode": true,"types": [- "Table"+ "Embeddings"],"value": "__UNDEFINED__"}@@ -3780,16 +3781,17 @@"pinned": false,"template": {"_type": "Component",- "chunk_overlap": {- "_input_type": "IntInput",+ "api_base": {+ "_input_type": "StrInput","advanced": false,"api_editable": false,- "display_name": "Chunk Overlap",+ "display_name": "OpenAI API Base","dynamic": false,- "info": "Number of characters to overlap between chunks.",+ "info": "Bound to OPENRAG_LLM_BASE_URL at runtime. It is either the public /v1 base or the private router base. Same URL as chat.","list": false,"list_add_label": "Add More",- "name": "chunk_overlap",+ "load_from_db": true,+ "name": "api_base","override_skip": false,"placeholder": "","required": false,@@ -3797,41 +3799,40 @@"title_case": false,"tool_mode": false,"trace_as_metadata": true,- "track_in_telemetry": true,- "type": "int",- "value": 200+ "track_in_telemetry": false,+ "type": "str",+ "value": "OPENRAG_LLM_BASE_URL"},- "chunk_size": {- "_input_type": "IntInput",+ "api_key": {+ "_input_type": "SecretStrInput","advanced": false,"api_editable": false,- "display_name": "Chunk Size",+ "display_name": "OpenRAG LLM Token","dynamic": false,- "info": "The maximum length of each chunk. Text is first split by separator, then chunks are merged up to this size. Individual splits larger than this won't be further divided.",- "list": false,- "list_add_label": "Add More",- "name": "chunk_size",+ "info": "Hop token from OPENRAG_LLM_TOKEN. Same token as the chat component.",+ "input_types": [],+ "load_from_db": true,+ "name": "api_key","override_skip": false,+ "password": true,"placeholder": "","required": false,"show": true,"title_case": false,- "tool_mode": false,- "trace_as_metadata": true,- "track_in_telemetry": true,- "type": "int",- "value": 1000+ "track_in_telemetry": false,+ "type": "str",+ "value": "OPENRAG_LLM_TOKEN"},- "clean_output": {- "_input_type": "BoolInput",+ "chunk_size": {+ "_input_type": "IntInput","advanced": true,"api_editable": false,- "display_name": "Clean Output",+ "display_name": "Chunk Size","dynamic": false,- "info": "When enabled, only the text column is included in the output. Metadata columns are removed.",+ "info": "","list": false,"list_add_label": "Add More",- "name": "clean_output",+ "name": "chunk_size","override_skip": false,"placeholder": "","required": false,@@ -3840,8 +3841,8 @@"tool_mode": false,"trace_as_metadata": true,"track_in_telemetry": true,- "type": "bool",- "value": false+ "type": "int",+ "value": 1000},"code": {"advanced": true,@@ -3860,312 +3861,40 @@"show": true,"title_case": false,"type": "code",- "value": "from langchain_text_splitters import CharacterTextSplitter\n\nfrom lfx.custom.custom_component.component import Component\nfrom lfx.io import BoolInput, DropdownInput, HandleInput, IntInput, MessageTextInput, Output\nfrom lfx.schema.data import Data\nfrom lfx.schema.dataframe import DataFrame\nfrom lfx.schema.message import Message\nfrom lfx.utils.util import unescape_string\n\n\nclass SplitTextComponent(Component):\n display_name: str = \"Split Text\"\n description: str = \"Split text into chunks based on specified criteria.\"\n documentation: str = \"https://docs.langflow.org/split-text\"\n icon = \"scissors-line-dashed\"\n name = \"SplitText\"\n\n inputs = [\n HandleInput(\n name=\"data_inputs\",\n display_name=\"Input\",\n info=\"The data with texts to split in chunks.\",\n input_types=[\"Data\", \"JSON\", \"DataFrame\", \"Table\", \"Message\"],\n required=True,\n ),\n IntInput(\n name=\"chunk_overlap\",\n display_name=\"Chunk Overlap\",\n info=\"Number of characters to overlap between chunks.\",\n value=200,\n ),\n IntInput(\n name=\"chunk_size\",\n display_name=\"Chunk Size\",\n info=(\n \"The maximum length of each chunk. Text is first split by separator, \"\n \"then chunks are merged up to this size. \"\n \"Individual splits larger than this won't be further divided.\"\n ),\n value=1000,\n ),\n MessageTextInput(\n name=\"separator\",\n display_name=\"Separator\",\n info=(\n \"The character to split on. Use \\\\n for newline. \"\n \"Examples: \\\\n\\\\n for paragraphs, \\\\n for lines, . for sentences\"\n ),\n value=\"\\n\",\n ),\n MessageTextInput(\n name=\"text_key\",\n display_name=\"Text Key\",\n info=\"The key to use for the text column.\",\n value=\"text\",\n advanced=True,\n ),\n DropdownInput(\n name=\"keep_separator\",\n display_name=\"Keep Separator\",\n info=\"Whether to keep the separator in the output chunks and where to place it.\",\n options=[\"False\", \"True\", \"Start\", \"End\"],\n value=\"False\",\n advanced=True,\n ),\n BoolInput(\n name=\"clean_output\",\n display_name=\"Clean Output\",\n info=\"When enabled, only the text column is included in the output. Metadata columns are removed.\",\n value=False,\n advanced=True,\n ),\n ]\n\n outputs = [\n Output(display_name=\"Chunks\", name=\"dataframe\", method=\"split_text\"),\n ]\n\n def _docs_to_data(self, docs, *, clean: bool = False) -> list[Data]:\n return [\n Data(text=doc.page_content) if clean else Data(text=doc.page_content, data=doc.metadata) for doc in docs\n ]\n\n def _fix_separator(self, separator: str) -> str:\n \"\"\"Fix common separator issues and convert to proper format.\"\"\"\n if separator == \"/n\":\n return \"\\n\"\n if separator == \"/t\":\n return \"\\t\"\n return separator\n\n def split_text_base(self):\n separator = self._fix_separator(self.separator)\n separator = unescape_string(separator)\n\n if isinstance(self.data_inputs, DataFrame):\n if not len(self.data_inputs):\n msg = \"DataFrame is empty\"\n raise TypeError(msg)\n\n self.data_inputs.text_key = self.text_key\n try:\n documents = self.data_inputs.to_lc_documents()\n except Exception as e:\n msg = f\"Error converting DataFrame to documents: {e}\"\n raise TypeError(msg) from e\n elif isinstance(self.data_inputs, Message):\n self.data_inputs = [self.data_inputs.to_data()]\n return self.split_text_base()\n else:\n if not self.data_inputs:\n msg = \"No data inputs provided\"\n raise TypeError(msg)\n\n documents = []\n if isinstance(self.data_inputs, Data):\n self.data_inputs.text_key = self.text_key\n documents = [self.data_inputs.to_lc_document()]\n else:\n try:\n documents = [input_.to_lc_document() for input_ in self.data_inputs if isinstance(input_, Data)]\n if not documents:\n msg = f\"No valid Data inputs found in {type(self.data_inputs)}\"\n raise TypeError(msg)\n except AttributeError as e:\n msg = f\"Invalid input type in collection: {e}\"\n raise TypeError(msg) from e\n try:\n # Convert string 'False'/'True' to boolean\n keep_sep = self.keep_separator\n if isinstance(keep_sep, str):\n if keep_sep.lower() == \"false\":\n keep_sep = False\n elif keep_sep.lower() == \"true\":\n keep_sep = True\n # 'start' and 'end' are kept as strings\n\n splitter = CharacterTextSplitter(\n chunk_overlap=self.chunk_overlap,\n chunk_size=self.chunk_size,\n separator=separator,\n keep_separator=keep_sep,\n )\n return splitter.split_documents(documents)\n except Exception as e:\n msg = f\"Error splitting text: {e}\"\n raise TypeError(msg) from e\n\n def split_text(self) -> DataFrame:\n docs = self.split_text_base()\n df = DataFrame(self._docs_to_data(docs, clean=self.clean_output))\n return df if self.clean_output else df.smart_column_order()\n"+ "value": "\"\"\"OpenAI-compatible embeddings that talk to the OpenRAG LLM proxy.\n\nEmbeddings work the same way as chat: Langflow never holds upstream vendor\nkeys. At runtime OpenRAG injects:\n\n- ``OPENRAG_LLM_TOKEN`` — the same short-lived hop token as chat\n- ``OPENRAG_LLM_BASE_URL`` — the backend's ``/v1`` base or the router's\n private unversioned base\n- ``SELECTED_EMBEDDING_MODEL`` — configured embedding model id\n\n``OpenAIEmbeddings`` posts to ``{base_url}/embeddings``. The backend gateway\nroutes by the configured embedding provider (which can differ from the chat\nprovider).\n\"\"\"\n\nfrom __future__ import annotations\n\nfrom typing import Any\n\nfrom langchain_core.embeddings import Embeddings\nfrom langchain_openai import OpenAIEmbeddings\nfrom lfx.base.embeddings.model import LCEmbeddingsModel\nfrom lfx.io import IntInput, SecretStrInput, StrInput\n\n# Names must match src/api/settings/langflow_sync.py + src/utils/langflow_headers.py\nOPENRAG_LLM_BASE_URL_VAR = \"OPENRAG_LLM_BASE_URL\"\nOPENRAG_LLM_TOKEN_VAR = \"OPENRAG_LLM_TOKEN\"\nSELECTED_EMBEDDING_MODEL_VAR = \"SELECTED_EMBEDDING_MODEL\"\nSELECTED_EMBEDDING_PROVIDER_VAR = \"SELECTED_EMBEDDING_PROVIDER\"\nLEGACY_EMBEDDING_ROUTE_PREFIX = \"legacy:\"\nINDEXED_EMBEDDING_ROUTE_PREFIX = \"space:\"\n\n\ndef _as_str(value: object) -> str | None:\n if value is None:\n return None\n getter = getattr(value, \"get_secret_value\", None)\n if callable(getter):\n value = getter()\n text = str(value).strip()\n return text or None\n\n\ndef _embedding_route_identity(route: str) -> tuple[str | None, str]:\n \"\"\"Return the provider and model identity encoded in a retrieval route.\"\"\"\n if route.startswith(LEGACY_EMBEDDING_ROUTE_PREFIX):\n return None, route.removeprefix(LEGACY_EMBEDDING_ROUTE_PREFIX)\n if route.startswith(INDEXED_EMBEDDING_ROUTE_PREFIX):\n qualified = route.removeprefix(INDEXED_EMBEDDING_ROUTE_PREFIX)\n provider, separator, model_name = qualified.partition(\":\")\n if separator and provider and model_name:\n return provider.lower(), model_name\n return None, qualified\n return None, route\n\n\nclass OpenRAGEmbeddings(Embeddings):\n \"\"\"One immutable model route plus a factory for other retrieval routes.\"\"\"\n\n def __init__(\n self,\n *,\n model_name: str,\n api_key: str | None,\n api_base: str | None,\n provider_name: str | None = None,\n chunk_size: int | None = None,\n dimensions: int | None = None,\n ) -> None:\n self.model = model_name\n self.deployment = model_name\n self._api_key = api_key\n self._api_base = api_base\n self._provider_name = (provider_name or \"openai\").strip().lower()\n self._chunk_size = chunk_size\n self._dimensions = dimensions\n\n kwargs: dict[str, Any] = {\n \"model\": self.model,\n # Keep identity aligned with ``model``. LangChain otherwise exposes\n # its ada-002 class default as the deployment for every instance.\n \"deployment\": self.model_name,\n \"api_key\": api_key,\n \"base_url\": api_base,\n \"check_embedding_ctx_length\": False,\n }\n if chunk_size:\n kwargs[\"chunk_size\"] = chunk_size\n if dimensions:\n kwargs[\"dimensions\"] = dimensions\n self._delegate = OpenAIEmbeddings(**kwargs)\n\n @property\n def model_name(self) -> str:\n return self.model\n\n def for_model(self, model_name: str) -> Embeddings:\n \"\"\"Return a dedicated adapter; never mutate the selected ingestion model.\"\"\"\n route = (model_name or \"\").strip()\n if not route:\n raise ValueError(\"Embedding model route is required\")\n route_provider, route_model = _embedding_route_identity(route)\n is_selected_route = route_provider == self._provider_name and route_model == self.model_name\n dimensions = self._dimensions if is_selected_route else None\n return OpenRAGEmbeddings(\n model_name=route,\n api_key=self._api_key,\n api_base=self._api_base,\n provider_name=self._provider_name,\n chunk_size=self._chunk_size,\n dimensions=dimensions,\n )\n\n def embed_documents(self, texts: list[str]) -> list[list[float]]:\n return self._delegate.embed_documents(texts)\n\n def embed_query(self, text: str) -> list[float]:\n return self._delegate.embed_query(text)\n\n async def aembed_documents(self, texts: list[str]) -> list[list[float]]:\n return await self._delegate.aembed_documents(texts)\n\n async def aembed_query(self, text: str) -> list[float]:\n return await self._delegate.aembed_query(text)\n\n\nclass OpenAICompatibleEmbeddingComponent(LCEmbeddingsModel):\n display_name = \"OpenRAG Embeddings\"\n description = (\n \"Embeddings via OpenRAG's OpenAI-compatible proxy. \"\n \"Uses the same base URL and hop token as the chat component.\"\n )\n icon = \"OpenRAG\"\n name = \"OpenAICompatibleEmbedding\"\n\n inputs = [\n StrInput(\n name=\"model_name\",\n display_name=\"Model Name\",\n info=\"Embedding model id. Bound to SELECTED_EMBEDDING_MODEL at runtime.\",\n value=SELECTED_EMBEDDING_MODEL_VAR,\n load_from_db=True,\n ),\n StrInput(\n name=\"provider_name\",\n display_name=\"Provider Name\",\n info=\"Embedding provider id. Bound to SELECTED_EMBEDDING_PROVIDER at runtime.\",\n value=SELECTED_EMBEDDING_PROVIDER_VAR,\n load_from_db=True,\n ),\n SecretStrInput(\n name=\"api_key\",\n display_name=\"OpenRAG LLM Token\",\n info=\"Hop token from OPENRAG_LLM_TOKEN. Same token as the chat component.\",\n value=OPENRAG_LLM_TOKEN_VAR,\n required=False,\n load_from_db=True,\n ),\n StrInput(\n name=\"api_base\",\n display_name=\"OpenAI API Base\",\n info=(\n \"Bound to OPENRAG_LLM_BASE_URL at runtime. It is either the public \"\n \"/v1 base or the private router base. Same URL as chat.\"\n ),\n value=OPENRAG_LLM_BASE_URL_VAR,\n load_from_db=True,\n ),\n IntInput(\n name=\"dimensions\",\n display_name=\"Dimensions\",\n info=\"Output dimensions when the embedding model supports it.\",\n advanced=True,\n ),\n IntInput(\n name=\"chunk_size\",\n display_name=\"Chunk Size\",\n advanced=True,\n value=1000,\n ),\n ]\n\n def build_embeddings(self) -> Embeddings:\n api_key = _as_str(self.api_key)\n api_base = _as_str(self.api_base)\n if api_base:\n api_base = api_base.rstrip(\"/\")\n return OpenRAGEmbeddings(\n model_name=self.model_name,\n api_key=api_key,\n api_base=api_base,\n provider_name=getattr(self, \"provider_name\", None),\n chunk_size=getattr(self, \"chunk_size\", None),\n dimensions=getattr(self, \"dimensions\", None),\n )\n"},- "data_inputs": {- "_input_type": "HandleInput",- "advanced": false,+ "dimensions": {+ "_input_type": "IntInput",+ "advanced": true,"api_editable": false,- "display_name": "Input",+ "display_name": "Dimensions","dynamic": false,- "info": "The data with texts to split in chunks.",- "input_types": [- "Data",- "JSON",- "DataFrame",- "Table",- "Message"- ],+ "info": "Output dimensions when the embedding model supports it.","list": false,"list_add_label": "Add More",- "name": "data_inputs",+ "name": "dimensions","override_skip": false,"placeholder": "",- "required": true,+ "required": false,"show": true,"title_case": false,+ "tool_mode": false,"trace_as_metadata": true,- "track_in_telemetry": false,- "type": "other",- "value": ""+ "track_in_telemetry": true,+ "type": "int",+ "value": 0},- "keep_separator": {- "_input_type": "DropdownInput",- "advanced": true,+ "model_name": {+ "_input_type": "StrInput",+ "advanced": false,"api_editable": false,- "combobox": false,- "dialog_inputs": {},- "display_name": "Keep Separator",+ "display_name": "Model Name","dynamic": false,- "external_options": {},- "info": "Whether to keep the separator in the output chunks and where to place it.",- "name": "keep_separator",- "options": [- "False",- "True",- "Start",- "End"- ],- "options_metadata": [],- "override_skip": false,- "placeholder": "",- "required": false,- "show": true,- "title_case": false,- "toggle": false,- "tool_mode": false,- "trace_as_metadata": true,- "track_in_telemetry": true,- "type": "str",- "value": "False"- },- "separator": {- "_input_type": "MessageTextInput",- "advanced": false,- "api_editable": false,- "display_name": "Separator",- "dynamic": false,- "info": "The character to split on. Use \\n for newline. Examples: \\n\\n for paragraphs, \\n for lines, . for sentences",- "input_types": [- "Message"- ],- "list": false,- "list_add_label": "Add More",- "load_from_db": false,- "name": "separator",- "override_skip": false,- "placeholder": "",- "required": false,- "show": true,- "title_case": false,- "tool_mode": false,- "trace_as_input": true,- "trace_as_metadata": true,- "track_in_telemetry": false,- "type": "str",- "value": "\n"- },- "text_key": {- "_input_type": "MessageTextInput",- "advanced": true,- "api_editable": false,- "display_name": "Text Key",- "dynamic": false,- "info": "The key to use for the text column.",- "input_types": [- "Message"- ],- "list": false,- "list_add_label": "Add More",- "load_from_db": false,- "name": "text_key",- "override_skip": false,- "placeholder": "",- "required": false,- "show": true,- "title_case": false,- "tool_mode": false,- "trace_as_input": true,- "trace_as_metadata": true,- "track_in_telemetry": false,- "type": "str",- "value": "text"- }- },- "tool_mode": false- },- "showNode": false,- "type": "SplitText"- },- "dragging": false,- "id": "SplitText-QIKhg",- "measured": {- "height": 80,- "width": 192- },- "position": {- "x": 1483.6566983203961,- "y": 1839.4043723057894- },- "selected": false,- "type": "genericNode"- },- {- "data": {- "id": "OpenAICompatibleEmbedding-MloZd",- "node": {- "base_classes": [- "Embeddings"- ],- "beta": false,- "conditional_paths": [],- "custom_fields": {},- "description": "Embeddings via OpenRAG's OpenAI-compatible /v1 proxy. Uses the same base URL and hop token as the chat component.",- "display_name": "OpenRAG Embeddings",- "documentation": "",- "edited": false,- "field_order": [- "model_name",- "api_key",- "api_base",- "dimensions",- "chunk_size"- ],- "frozen": false,- "icon": "OpenRAG",- "legacy": false,- "metadata": {- "code_hash": "d4b6a5d67c0b",- "dependencies": {- "dependencies": [- {- "name": "langchain_openai",- "version": "1.5.2"- },- {- "name": "lfx",- "version": "1.11.2"- }- ],- "total_dependencies": 2- },- "module": "custom_components.openrag_embeddings"- },- "minimized": false,- "output_types": [],- "outputs": [- {- "allows_loop": false,- "cache": true,- "display_name": "Embedding Model",- "group_outputs": false,- "method": "build_embeddings",- "name": "embeddings",- "selected": "Embeddings",- "tool_mode": true,- "types": [- "Embeddings"- ],- "value": "__UNDEFINED__"- }- ],- "pinned": false,- "template": {- "_type": "Component",- "api_base": {- "_input_type": "StrInput",- "advanced": false,- "api_editable": false,- "display_name": "OpenAI API Base",- "dynamic": false,- "info": "Must end with /v1 (for example http://openrag-backend:8000/v1). Bound to OPENRAG_LLM_BASE_URL at runtime. Same URL as chat.",- "list": false,- "list_add_label": "Add More",- "load_from_db": true,- "name": "api_base",- "override_skip": false,- "placeholder": "",- "required": false,- "show": true,- "title_case": false,- "tool_mode": false,- "trace_as_metadata": true,- "track_in_telemetry": false,- "type": "str",- "value": "OPENRAG_LLM_BASE_URL"- },- "api_key": {- "_input_type": "SecretStrInput",- "advanced": false,- "api_editable": false,- "display_name": "OpenRAG LLM Token",- "dynamic": false,- "info": "Hop token from OPENRAG_LLM_TOKEN. Same token as the chat component.",- "input_types": [],- "load_from_db": true,- "name": "api_key",- "override_skip": false,- "password": true,- "placeholder": "",- "required": false,- "show": true,- "title_case": false,- "track_in_telemetry": false,- "type": "str",- "value": "OPENRAG_LLM_TOKEN"- },- "chunk_size": {- "_input_type": "IntInput",- "advanced": true,- "api_editable": false,- "display_name": "Chunk Size",- "dynamic": false,- "info": "",- "list": false,- "list_add_label": "Add More",- "name": "chunk_size",- "override_skip": false,- "placeholder": "",- "required": false,- "show": true,- "title_case": false,- "tool_mode": false,- "trace_as_metadata": true,- "track_in_telemetry": true,- "type": "int",- "value": 1000- },- "code": {- "advanced": true,- "api_editable": false,- "dynamic": true,- "fileTypes": [],- "file_path": "",- "info": "",- "list": false,- "load_from_db": false,- "multiline": true,- "name": "code",- "password": false,- "placeholder": "",- "required": true,- "show": true,- "title_case": false,- "type": "code",- "value": "\"\"\"OpenAI-compatible embeddings that talk to the OpenRAG LLM proxy.\n\nEmbeddings work the same way as chat: Langflow never holds upstream vendor\nkeys. At runtime OpenRAG injects:\n\n- ``OPENRAG_LLM_TOKEN`` — the same short-lived hop token as chat\n- ``OPENRAG_LLM_BASE_URL`` — the backend's ``/v1`` base or the router's\n private unversioned base\n- ``SELECTED_EMBEDDING_MODEL`` — configured embedding model id\n\n``OpenAIEmbeddings`` posts to ``{base_url}/embeddings``. The backend gateway\nroutes by the configured embedding provider (which can differ from the chat\nprovider).\n\"\"\"\n\nfrom __future__ import annotations\n\nfrom typing import Any\n\nfrom langchain_core.embeddings import Embeddings\nfrom langchain_openai import OpenAIEmbeddings\nfrom lfx.base.embeddings.model import LCEmbeddingsModel\nfrom lfx.io import IntInput, SecretStrInput, StrInput\n\n# Names must match src/api/settings/langflow_sync.py + src/utils/langflow_headers.py\nOPENRAG_LLM_BASE_URL_VAR = \"OPENRAG_LLM_BASE_URL\"\nOPENRAG_LLM_TOKEN_VAR = \"OPENRAG_LLM_TOKEN\"\nSELECTED_EMBEDDING_MODEL_VAR = \"SELECTED_EMBEDDING_MODEL\"\nSELECTED_EMBEDDING_PROVIDER_VAR = \"SELECTED_EMBEDDING_PROVIDER\"\nLEGACY_EMBEDDING_ROUTE_PREFIX = \"legacy:\"\nINDEXED_EMBEDDING_ROUTE_PREFIX = \"space:\"\n\n\ndef _as_str(value: object) -> str | None:\n if value is None:\n return None\n getter = getattr(value, \"get_secret_value\", None)\n if callable(getter):\n value = getter()\n text = str(value).strip()\n return text or None\n\n\ndef _embedding_route_identity(route: str) -> tuple[str | None, str]:\n \"\"\"Return the provider and model identity encoded in a retrieval route.\"\"\"\n if route.startswith(LEGACY_EMBEDDING_ROUTE_PREFIX):\n return None, route.removeprefix(LEGACY_EMBEDDING_ROUTE_PREFIX)\n if route.startswith(INDEXED_EMBEDDING_ROUTE_PREFIX):\n qualified = route.removeprefix(INDEXED_EMBEDDING_ROUTE_PREFIX)\n provider, separator, model_name = qualified.partition(\":\")\n if separator and provider and model_name:\n return provider.lower(), model_name\n return None, qualified\n return None, route\n\n\nclass OpenRAGEmbeddings(Embeddings):\n \"\"\"One immutable model route plus a factory for other retrieval routes.\"\"\"\n\n def __init__(\n self,\n *,\n model_name: str,\n api_key: str | None,\n api_base: str | None,\n provider_name: str | None = None,\n chunk_size: int | None = None,\n dimensions: int | None = None,\n ) -> None:\n self.model = model_name\n self.deployment = model_name\n self._api_key = api_key\n self._api_base = api_base\n self._provider_name = (provider_name or \"openai\").strip().lower()\n self._chunk_size = chunk_size\n self._dimensions = dimensions\n\n kwargs: dict[str, Any] = {\n \"model\": self.model,\n # Keep identity aligned with ``model``. LangChain otherwise exposes\n # its ada-002 class default as the deployment for every instance.\n \"deployment\": self.model_name,\n \"api_key\": api_key,\n \"base_url\": api_base,\n \"check_embedding_ctx_length\": False,\n }\n if chunk_size:\n kwargs[\"chunk_size\"] = chunk_size\n if dimensions:\n kwargs[\"dimensions\"] = dimensions\n self._delegate = OpenAIEmbeddings(**kwargs)\n\n @property\n def model_name(self) -> str:\n return self.model\n\n def for_model(self, model_name: str) -> Embeddings:\n \"\"\"Return a dedicated adapter; never mutate the selected ingestion model.\"\"\"\n route = (model_name or \"\").strip()\n if not route:\n raise ValueError(\"Embedding model route is required\")\n route_provider, route_model = _embedding_route_identity(route)\n is_selected_route = route_provider == self._provider_name and route_model == self.model_name\n dimensions = self._dimensions if is_selected_route else None\n return OpenRAGEmbeddings(\n model_name=route,\n api_key=self._api_key,\n api_base=self._api_base,\n provider_name=self._provider_name,\n chunk_size=self._chunk_size,\n dimensions=dimensions,\n )\n\n def embed_documents(self, texts: list[str]) -> list[list[float]]:\n return self._delegate.embed_documents(texts)\n\n def embed_query(self, text: str) -> list[float]:\n return self._delegate.embed_query(text)\n\n async def aembed_documents(self, texts: list[str]) -> list[list[float]]:\n return await self._delegate.aembed_documents(texts)\n\n async def aembed_query(self, text: str) -> list[float]:\n return await self._delegate.aembed_query(text)\n\n\nclass OpenAICompatibleEmbeddingComponent(LCEmbeddingsModel):\n display_name = \"OpenRAG Embeddings\"\n description = (\n \"Embeddings via OpenRAG's OpenAI-compatible proxy. \"\n \"Uses the same base URL and hop token as the chat component.\"\n )\n icon = \"OpenRAG\"\n name = \"OpenAICompatibleEmbedding\"\n\n inputs = [\n StrInput(\n name=\"model_name\",\n display_name=\"Model Name\",\n info=\"Embedding model id. Bound to SELECTED_EMBEDDING_MODEL at runtime.\",\n value=SELECTED_EMBEDDING_MODEL_VAR,\n load_from_db=True,\n ),\n StrInput(\n name=\"provider_name\",\n display_name=\"Provider Name\",\n info=\"Embedding provider id. Bound to SELECTED_EMBEDDING_PROVIDER at runtime.\",\n value=SELECTED_EMBEDDING_PROVIDER_VAR,\n load_from_db=True,\n ),\n SecretStrInput(\n name=\"api_key\",\n display_name=\"OpenRAG LLM Token\",\n info=\"Hop token from OPENRAG_LLM_TOKEN. Same token as the chat component.\",\n value=OPENRAG_LLM_TOKEN_VAR,\n required=False,\n load_from_db=True,\n ),\n StrInput(\n name=\"api_base\",\n display_name=\"OpenAI API Base\",\n info=(\n \"Bound to OPENRAG_LLM_BASE_URL at runtime. It is either the public \"\n \"/v1 base or the private router base. Same URL as chat.\"\n ),\n value=OPENRAG_LLM_BASE_URL_VAR,\n load_from_db=True,\n ),\n IntInput(\n name=\"dimensions\",\n display_name=\"Dimensions\",\n info=\"Output dimensions when the embedding model supports it.\",\n advanced=True,\n ),\n IntInput(\n name=\"chunk_size\",\n display_name=\"Chunk Size\",\n advanced=True,\n value=1000,\n ),\n ]\n\n def build_embeddings(self) -> Embeddings:\n api_key = _as_str(self.api_key)\n api_base = _as_str(self.api_base)\n if api_base:\n api_base = api_base.rstrip(\"/\")\n return OpenRAGEmbeddings(\n model_name=self.model_name,\n api_key=api_key,\n api_base=api_base,\n provider_name=getattr(self, \"provider_name\", None),\n chunk_size=getattr(self, \"chunk_size\", None),\n dimensions=getattr(self, \"dimensions\", None),\n )\n"- },- "dimensions": {- "_input_type": "IntInput",- "advanced": true,- "api_editable": false,- "display_name": "Dimensions",- "dynamic": false,- "info": "Output dimensions when the embedding model supports it.",- "list": false,- "list_add_label": "Add More",- "name": "dimensions",- "override_skip": false,- "placeholder": "",- "required": false,- "show": true,- "title_case": false,- "tool_mode": false,- "trace_as_metadata": true,- "track_in_telemetry": true,- "type": "int",- "value": 0- },- "model_name": {- "_input_type": "StrInput",- "advanced": false,- "api_editable": false,- "display_name": "Model Name",- "dynamic": false,- "info": "Embedding model id. Bound to SELECTED_EMBEDDING_MODEL at runtime.",- "list": false,- "list_add_label": "Add More",- "load_from_db": true,- "name": "model_name",+ "info": "Embedding model id. Bound to SELECTED_EMBEDDING_MODEL at runtime.",+ "list": false,+ "list_add_label": "Add More",+ "load_from_db": true,+ "name": "model_name","override_skip": false,"placeholder": "","required": false,@@ -5121,20 +4850,300 @@},"selected": false,"type": "genericNode"+ },+ {+ "data": {+ "id": "ext:openrag:OpenRAGSplitTextComponent@extra-0ttMH",+ "node": {+ "base_classes": [+ "Table"+ ],+ "beta": false,+ "bundle": "openrag",+ "conditional_paths": [],+ "custom_fields": {},+ "description": "Split text into chunks no longer than the chunk size.",+ "display_name": "Split Text",+ "documentation": "https://docs.langflow.org/split-text",+ "edited": false,+ "extension": "openrag",+ "extension_version": "0.0.0",+ "field_order": [+ "data_inputs",+ "chunk_overlap",+ "chunk_size",+ "separator",+ "text_key",+ "keep_separator",+ "clean_output"+ ],+ "frozen": false,+ "icon": "scissors-line-dashed",+ "legacy": false,+ "legacy_module": "split_text",+ "metadata": {+ "code_hash": "a94056a09995",+ "dependencies": {+ "dependencies": [+ {+ "name": "langchain_text_splitters",+ "version": "1.1.2"+ },+ {+ "name": "lfx",+ "version": "1.12.3"+ }+ ],+ "total_dependencies": 2+ },+ "module": "_lfx_ext.extra.openrag.split_text"+ },+ "minimized": false,+ "name": "OpenRAGSplitText",+ "namespaced_id": "ext:openrag:OpenRAGSplitTextComponent@extra",+ "output_types": [],+ "outputs": [+ {+ "allows_loop": false,+ "cache": true,+ "display_name": "Chunks",+ "group_outputs": false,+ "method": "split_text",+ "name": "dataframe",+ "selected": "Table",+ "tool_mode": true,+ "types": [+ "Table"+ ],+ "value": "__UNDEFINED__"+ }+ ],+ "pinned": false,+ "template": {+ "_type": "Component",+ "chunk_overlap": {+ "_input_type": "IntInput",+ "advanced": false,+ "api_editable": false,+ "display_name": "Chunk Overlap",+ "dynamic": false,+ "info": "Number of characters to overlap between chunks.",+ "list": false,+ "list_add_label": "Add More",+ "name": "chunk_overlap",+ "override_skip": false,+ "placeholder": "",+ "required": false,+ "show": true,+ "title_case": false,+ "tool_mode": false,+ "trace_as_metadata": true,+ "track_in_telemetry": true,+ "type": "int",+ "value": 200+ },+ "chunk_size": {+ "_input_type": "IntInput",+ "advanced": false,+ "api_editable": false,+ "display_name": "Chunk Size",+ "dynamic": false,+ "info": "The maximum length of each chunk. Text is split on the separator first; any piece still longer than this is split on finer boundaries (lines, sentences, spaces, then characters).",+ "list": false,+ "list_add_label": "Add More",+ "name": "chunk_size",+ "override_skip": false,+ "placeholder": "",+ "required": false,+ "show": true,+ "title_case": false,+ "tool_mode": false,+ "trace_as_metadata": true,+ "track_in_telemetry": true,+ "type": "int",+ "value": 1000+ },+ "clean_output": {+ "_input_type": "BoolInput",+ "advanced": true,+ "api_editable": false,+ "display_name": "Clean Output",+ "dynamic": false,+ "info": "When enabled, only the text column is included in the output. Metadata columns are removed.",+ "list": false,+ "list_add_label": "Add More",+ "name": "clean_output",+ "override_skip": false,+ "placeholder": "",+ "required": false,+ "show": true,+ "title_case": false,+ "tool_mode": false,+ "trace_as_metadata": true,+ "track_in_telemetry": true,+ "type": "bool",+ "value": false+ },+ "code": {+ "advanced": true,+ "api_editable": false,+ "dynamic": true,+ "fileTypes": [],+ "file_path": "",+ "info": "",+ "list": false,+ "load_from_db": false,+ "multiline": true,+ "name": "code",+ "password": false,+ "placeholder": "",+ "required": true,+ "show": true,+ "title_case": false,+ "type": "code",+ "value": "from langchain_text_splitters import RecursiveCharacterTextSplitter\nfrom lfx.custom.custom_component.component import Component\nfrom lfx.io import BoolInput, DropdownInput, HandleInput, IntInput, MessageTextInput, Output\nfrom lfx.schema.data import Data\nfrom lfx.schema.dataframe import DataFrame\nfrom lfx.schema.message import Message\nfrom lfx.utils.util import unescape_string\n\n# Tried in order after the configured separator. Docling joins consecutive\n# lines that have no blank line between them into one Markdown paragraph, so a\n# long document can arrive with almost no newlines; without these fallbacks a\n# single paragraph becomes one chunk of any size.\nFALLBACK_SEPARATORS = (\"\\n\\n\", \"\\n\", \"。\", \". \", \" \", \"\")\n\n\ndef build_separators(separator: str) -> list[str]:\n separators = [separator] if separator else []\n separators += [s for s in FALLBACK_SEPARATORS if s not in separators]\n return separators\n\n\nclass OpenRAGSplitTextComponent(Component):\n display_name: str = \"Split Text\"\n description: str = \"Split text into chunks no longer than the chunk size.\"\n documentation: str = \"https://docs.langflow.org/split-text\"\n icon = \"scissors-line-dashed\"\n # Distinct from Langflow's built-in \"SplitText\": in restricted mode Langflow\n # replaces drifted code of a known built-in type with its own copy.\n name = \"OpenRAGSplitText\"\n\n inputs = [\n HandleInput(\n name=\"data_inputs\",\n display_name=\"Input\",\n info=\"The data with texts to split in chunks.\",\n input_types=[\"Data\", \"JSON\", \"DataFrame\", \"Table\", \"Message\"],\n required=True,\n ),\n IntInput(\n name=\"chunk_overlap\",\n display_name=\"Chunk Overlap\",\n info=\"Number of characters to overlap between chunks.\",\n value=200,\n ),\n IntInput(\n name=\"chunk_size\",\n display_name=\"Chunk Size\",\n info=(\n \"The maximum length of each chunk. Text is split on the separator first; \"\n \"any piece still longer than this is split on finer boundaries \"\n \"(lines, sentences, spaces, then characters).\"\n ),\n value=1000,\n ),\n MessageTextInput(\n name=\"separator\",\n display_name=\"Separator\",\n info=(\n \"The preferred character to split on. Use \\\\n for newline. \"\n \"Examples: \\\\n\\\\n for paragraphs, \\\\n for lines, . for sentences\"\n ),\n value=\"\\n\",\n ),\n MessageTextInput(\n name=\"text_key\",\n display_name=\"Text Key\",\n info=\"The key to use for the text column.\",\n value=\"text\",\n advanced=True,\n ),\n DropdownInput(\n name=\"keep_separator\",\n display_name=\"Keep Separator\",\n info=\"Whether to keep the separator in the output chunks and where to place it.\",\n options=[\"False\", \"True\", \"Start\", \"End\"],\n value=\"False\",\n advanced=True,\n ),\n BoolInput(\n name=\"clean_output\",\n display_name=\"Clean Output\",\n info=\"When enabled, only the text column is included in the output. Metadata columns are removed.\",\n value=False,\n advanced=True,\n ),\n ]\n\n outputs = [\n Output(display_name=\"Chunks\", name=\"dataframe\", method=\"split_text\"),\n ]\n\n def _docs_to_data(self, docs, *, clean: bool = False) -> list[Data]:\n return [\n Data(text=doc.page_content) if clean else Data(text=doc.page_content, data=doc.metadata)\n for doc in docs\n ]\n\n def _fix_separator(self, separator: str) -> str:\n \"\"\"Fix common separator issues and convert to proper format.\"\"\"\n if separator == \"/n\":\n return \"\\n\"\n if separator == \"/t\":\n return \"\\t\"\n return separator\n\n def split_text_base(self):\n separator = self._fix_separator(self.separator)\n separator = unescape_string(separator)\n\n if isinstance(self.data_inputs, DataFrame):\n if not len(self.data_inputs):\n msg = \"DataFrame is empty\"\n raise TypeError(msg)\n\n self.data_inputs.text_key = self.text_key\n try:\n documents = self.data_inputs.to_lc_documents()\n except Exception as e:\n msg = f\"Error converting DataFrame to documents: {e}\"\n raise TypeError(msg) from e\n elif isinstance(self.data_inputs, Message):\n self.data_inputs = [self.data_inputs.to_data()]\n return self.split_text_base()\n else:\n if not self.data_inputs:\n msg = \"No data inputs provided\"\n raise TypeError(msg)\n\n documents = []\n if isinstance(self.data_inputs, Data):\n self.data_inputs.text_key = self.text_key\n documents = [self.data_inputs.to_lc_document()]\n else:\n try:\n documents = [\n input_.to_lc_document()\n for input_ in self.data_inputs\n if isinstance(input_, Data)\n ]\n if not documents:\n msg = f\"No valid Data inputs found in {type(self.data_inputs)}\"\n raise TypeError(msg)\n except AttributeError as e:\n msg = f\"Invalid input type in collection: {e}\"\n raise TypeError(msg) from e\n try:\n # Convert string 'False'/'True' to boolean\n keep_sep = self.keep_separator\n if isinstance(keep_sep, str):\n keep_sep = keep_sep.lower()\n if keep_sep == \"false\":\n keep_sep = False\n elif keep_sep == \"true\":\n keep_sep = True\n # LangChain only recognises lowercase 'start' and 'end'\n\n splitter = RecursiveCharacterTextSplitter(\n chunk_overlap=self.chunk_overlap,\n chunk_size=self.chunk_size,\n separators=build_separators(separator),\n keep_separator=keep_sep,\n )\n return splitter.split_documents(documents)\n except Exception as e:\n msg = f\"Error splitting text: {e}\"\n raise TypeError(msg) from e\n\n def split_text(self) -> DataFrame:\n docs = self.split_text_base()\n df = DataFrame(self._docs_to_data(docs, clean=self.clean_output))\n return df if self.clean_output else df.smart_column_order()\n"+ },+ "data_inputs": {+ "_input_type": "HandleInput",+ "advanced": false,+ "api_editable": false,+ "display_name": "Input",+ "dynamic": false,+ "info": "The data with texts to split in chunks.",+ "input_types": [+ "Data",+ "JSON",+ "DataFrame",+ "Table",+ "Message"+ ],+ "list": false,+ "list_add_label": "Add More",+ "name": "data_inputs",+ "override_skip": false,+ "placeholder": "",+ "required": true,+ "show": true,+ "title_case": false,+ "trace_as_metadata": true,+ "track_in_telemetry": false,+ "type": "other",+ "value": ""+ },+ "keep_separator": {+ "_input_type": "DropdownInput",+ "advanced": true,+ "api_editable": false,+ "combobox": false,+ "dialog_inputs": {},+ "display_name": "Keep Separator",+ "dynamic": false,+ "external_options": {},+ "info": "Whether to keep the separator in the output chunks and where to place it.",+ "name": "keep_separator",+ "options": [+ "False",+ "True",+ "Start",+ "End"+ ],+ "options_metadata": [],+ "override_skip": false,+ "placeholder": "",+ "required": false,+ "show": true,+ "title_case": false,+ "toggle": false,+ "tool_mode": false,+ "trace_as_metadata": true,+ "track_in_telemetry": true,+ "type": "str",+ "value": "False"+ },+ "separator": {+ "_input_type": "MessageTextInput",+ "advanced": false,+ "api_editable": false,+ "display_name": "Separator",+ "dynamic": false,+ "info": "The preferred character to split on. Use \\n for newline. Examples: \\n\\n for paragraphs, \\n for lines, . for sentences",+ "input_types": [+ "Message"+ ],+ "list": false,+ "list_add_label": "Add More",+ "load_from_db": false,+ "name": "separator",+ "override_skip": false,+ "placeholder": "",+ "required": false,+ "show": true,+ "title_case": false,+ "tool_mode": false,+ "trace_as_input": true,+ "trace_as_metadata": true,+ "track_in_telemetry": false,+ "type": "str",+ "value": "\n"+ },+ "text_key": {+ "_input_type": "MessageTextInput",+ "advanced": true,+ "api_editable": false,+ "display_name": "Text Key",+ "dynamic": false,+ "info": "The key to use for the text column.",+ "input_types": [+ "Message"+ ],+ "list": false,+ "list_add_label": "Add More",+ "load_from_db": false,+ "name": "text_key",+ "override_skip": false,+ "placeholder": "",+ "required": false,+ "show": true,+ "title_case": false,+ "tool_mode": false,+ "trace_as_input": true,+ "trace_as_metadata": true,+ "track_in_telemetry": false,+ "type": "str",+ "value": "text"+ }+ },+ "tool_mode": false+ },+ "showNode": false,+ "type": "ext:openrag:OpenRAGSplitTextComponent@extra"+ },+ "dragging": false,+ "id": "ext:openrag:OpenRAGSplitTextComponent@extra-0ttMH",+ "measured": {+ "height": 80,+ "width": 192+ },+ "position": {+ "x": 1480.0015861525885,+ "y": 1826.6203215715343+ },+ "selected": false,+ "type": "genericNode"}],"viewport": {- "x": -1244.045984357672,- "y": -1687.476697445286,- "zoom": 1.0133085834963953+ "x": 112.92283618168915,+ "y": -599.3634033121324,+ "zoom": 0.48571813243964146}},"description": "Load your data for chat context with Retrieval Augmented Generation.","endpoint_name": null,"id": "5488df7c-b93f-4f87-a446-b67028bc0813","is_component": false,- "last_tested_version": "0.11.2",- "locked": false,+ "last_tested_version": "1.12.3",+ "locked": true,"name": "OpenSearch Ingestion Flow","tags": ["openai",@@ -5142,4 +5151,4 @@"rag","q-a"]-}+}\ No newline at end of filediff --git a/flows/openrag_url_mcp.json b/flows/openrag_url_mcp.jsonindex 78d8d60ee..689cc51b6 100644--- a/flows/openrag_url_mcp.json+++ b/flows/openrag_url_mcp.json@@ -34,65 +34,63 @@"className": "","data": {"sourceHandle": {- "dataType": "SplitText",- "id": "SplitText-QIKhg",- "name": "dataframe",+ "dataType": "Operations",+ "id": "Operations-uhog5",+ "name": "dataframe_output","output_types": ["Table"]},"targetHandle": {- "fieldName": "df",- "id": "Operations-uhog5",+ "fieldName": "input_value",+ "id": "ChatOutput-0XHyo","inputTypes": [+ "Data",+ "JSON","DataFrame",- "Table"+ "Table",+ "Message"],"type": "other"}},- "id": "xy-edge__SplitText-QIKhg{œdataTypeœ:œSplitTextœ,œidœ:œSplitText-QIKhgœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}-Operations-uhog5{œfieldNameœ:œdfœ,œidœ:œOperations-uhog5œ,œinputTypesœ:[œDataFrameœ,œTableœ],œtypeœ:œotherœ}",+ "id": "xy-edge__Operations-uhog5{œdataTypeœ:œOperationsœ,œidœ:œOperations-uhog5œ,œnameœ:œdataframe_outputœ,œoutput_typesœ:[œTableœ]}-ChatOutput-0XHyo{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-0XHyoœ,œinputTypesœ:[œDataœ,œJSONœ,œDataFrameœ,œTableœ,œMessageœ],œtypeœ:œotherœ}","selected": false,- "source": "SplitText-QIKhg",- "sourceHandle": "{œdataTypeœ:œSplitTextœ,œidœ:œSplitText-QIKhgœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}",- "target": "Operations-uhog5",- "targetHandle": "{œfieldNameœ:œdfœ,œidœ:œOperations-uhog5œ,œinputTypesœ:[œDataFrameœ,œTableœ],œtypeœ:œotherœ}"+ "source": "Operations-uhog5",+ "sourceHandle": "{œdataTypeœ:œOperationsœ,œidœ:œOperations-uhog5œ,œnameœ:œdataframe_outputœ,œoutput_typesœ:[œTableœ]}",+ "target": "ChatOutput-0XHyo",+ "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-0XHyoœ,œinputTypesœ:[œDataœ,œJSONœ,œDataFrameœ,œTableœ,œMessageœ],œtypeœ:œotherœ}"},{"animated": false,"className": "","data": {"sourceHandle": {- "dataType": "Operations",- "id": "Operations-uhog5",- "name": "dataframe_output",+ "dataType": "OpenAICompatibleEmbedding",+ "id": "OpenAICompatibleEmbedding-aIHce",+ "name": "embeddings","output_types": [- "Table"+ "Embeddings"]},"targetHandle": {- "fieldName": "input_value",- "id": "ChatOutput-0XHyo",+ "fieldName": "embedding",+ "id": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKf","inputTypes": [- "Data",- "JSON",- "DataFrame",- "Table",- "Message"+ "Embeddings"],"type": "other"}},- "id": "xy-edge__Operations-uhog5{œdataTypeœ:œOperationsœ,œidœ:œOperations-uhog5œ,œnameœ:œdataframe_outputœ,œoutput_typesœ:[œTableœ]}-ChatOutput-0XHyo{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-0XHyoœ,œinputTypesœ:[œDataœ,œJSONœ,œDataFrameœ,œTableœ,œMessageœ],œtypeœ:œotherœ}",+ "id": "xy-edge__OpenAICompatibleEmbedding-aIHce{œdataTypeœ:œOpenAICompatibleEmbeddingœ,œidœ:œOpenAICompatibleEmbedding-aIHceœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}-OpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKf{œfieldNameœ:œembeddingœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKfœ,œinputTypesœ:[œEmbeddingsœ],œtypeœ:œotherœ}","selected": false,- "source": "Operations-uhog5",- "sourceHandle": "{œdataTypeœ:œOperationsœ,œidœ:œOperations-uhog5œ,œnameœ:œdataframe_outputœ,œoutput_typesœ:[œTableœ]}",- "target": "ChatOutput-0XHyo",- "targetHandle": "{œfieldNameœ:œinput_valueœ,œidœ:œChatOutput-0XHyoœ,œinputTypesœ:[œDataœ,œJSONœ,œDataFrameœ,œTableœ,œMessageœ],œtypeœ:œotherœ}"+ "source": "OpenAICompatibleEmbedding-aIHce",+ "sourceHandle": "{œdataTypeœ:œOpenAICompatibleEmbeddingœ,œidœ:œOpenAICompatibleEmbedding-aIHceœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}",+ "target": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKf",+ "targetHandle": "{œfieldNameœ:œembeddingœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKfœ,œinputTypesœ:[œEmbeddingsœ],œtypeœ:œotherœ}"},{"animated": false,- "className": "","data": {"sourceHandle": {"dataType": "URLComponent",@@ -121,7 +119,6 @@},{"animated": false,- "className": "","data": {"sourceHandle": {"dataType": "Operations",@@ -150,7 +147,6 @@},{"animated": false,- "className": "","data": {"sourceHandle": {"dataType": "Operations",@@ -162,7 +158,7 @@},"targetHandle": {"fieldName": "data_inputs",- "id": "SplitText-QIKhg",+ "id": "ext:openrag:OpenRAGSplitTextComponent@extra-tutKN","inputTypes": ["Data","JSON",@@ -173,118 +169,130 @@"type": "other"}},- "id": "xy-edge__Operations-fX1Im{œdataTypeœ:œOperationsœ,œidœ:œOperations-fX1Imœ,œnameœ:œdataframe_outputœ,œoutput_typesœ:[œTableœ]}-SplitText-QIKhg{œfieldNameœ:œdata_inputsœ,œidœ:œSplitText-QIKhgœ,œinputTypesœ:[œDataœ,œJSONœ,œDataFrameœ,œTableœ,œMessageœ],œtypeœ:œotherœ}",+ "id": "xy-edge__Operations-fX1Im{œdataTypeœ:œOperationsœ,œidœ:œOperations-fX1Imœ,œnameœ:œdataframe_outputœ,œoutput_typesœ:[œTableœ]}-ext:openrag:OpenRAGSplitTextComponent@extra-tutKN{œfieldNameœ:œdata_inputsœ,œidœ:œext:openrag:OpenRAGSplitTextComponent@extra-tutKNœ,œinputTypesœ:[œDataœ,œJSONœ,œDataFrameœ,œTableœ,œMessageœ],œtypeœ:œotherœ}","selected": false,"source": "Operations-fX1Im","sourceHandle": "{œdataTypeœ:œOperationsœ,œidœ:œOperations-fX1Imœ,œnameœ:œdataframe_outputœ,œoutput_typesœ:[œTableœ]}",- "target": "SplitText-QIKhg",- "targetHandle": "{œfieldNameœ:œdata_inputsœ,œidœ:œSplitText-QIKhgœ,œinputTypesœ:[œDataœ,œJSONœ,œDataFrameœ,œTableœ,œMessageœ],œtypeœ:œotherœ}"+ "target": "ext:openrag:OpenRAGSplitTextComponent@extra-tutKN",+ "targetHandle": "{œfieldNameœ:œdata_inputsœ,œidœ:œext:openrag:OpenRAGSplitTextComponent@extra-tutKNœ,œinputTypesœ:[œDataœ,œJSONœ,œDataFrameœ,œTableœ,œMessageœ],œtypeœ:œotherœ}"},{"animated": false,- "className": "","data": {"sourceHandle": {- "dataType": "SplitText",- "id": "SplitText-QIKhg",+ "dataType": "ext:openrag:OpenRAGSplitTextComponent@extra",+ "id": "ext:openrag:OpenRAGSplitTextComponent@extra-tutKN","name": "dataframe","output_types": ["Table"]},"targetHandle": {- "fieldName": "ingest_data",- "id": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKf",+ "fieldName": "df",+ "id": "Operations-uhog5","inputTypes": [- "Data","DataFrame","Table"],"type": "other"}},- "id": "xy-edge__SplitText-QIKhg{œdataTypeœ:œSplitTextœ,œidœ:œSplitText-QIKhgœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}-OpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKf{œfieldNameœ:œingest_dataœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKfœ,œinputTypesœ:[œDataœ,œDataFrameœ,œTableœ],œtypeœ:œotherœ}",+ "id": "xy-edge__ext:openrag:OpenRAGSplitTextComponent@extra-tutKN{œdataTypeœ:œext:openrag:OpenRAGSplitTextComponent@extraœ,œidœ:œext:openrag:OpenRAGSplitTextComponent@extra-tutKNœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}-Operations-uhog5{œfieldNameœ:œdfœ,œidœ:œOperations-uhog5œ,œinputTypesœ:[œDataFrameœ,œTableœ],œtypeœ:œotherœ}","selected": false,- "source": "SplitText-QIKhg",- "sourceHandle": "{œdataTypeœ:œSplitTextœ,œidœ:œSplitText-QIKhgœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}",- "target": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKf",- "targetHandle": "{œfieldNameœ:œingest_dataœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKfœ,œinputTypesœ:[œDataœ,œDataFrameœ,œTableœ],œtypeœ:œotherœ}"+ "source": "ext:openrag:OpenRAGSplitTextComponent@extra-tutKN",+ "sourceHandle": "{œdataTypeœ:œext:openrag:OpenRAGSplitTextComponent@extraœ,œidœ:œext:openrag:OpenRAGSplitTextComponent@extra-tutKNœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}",+ "target": "Operations-uhog5",+ "targetHandle": "{œfieldNameœ:œdfœ,œidœ:œOperations-uhog5œ,œinputTypesœ:[œDataFrameœ,œTableœ],œtypeœ:œotherœ}"},{"animated": false,- "className": "","data": {"sourceHandle": {- "dataType": "OpenAICompatibleEmbedding",- "id": "OpenAICompatibleEmbedding-aIHce",- "name": "embeddings",+ "dataType": "ext:openrag:OpenRAGSplitTextComponent@extra",+ "id": "ext:openrag:OpenRAGSplitTextComponent@extra-tutKN",+ "name": "dataframe","output_types": [- "Embeddings"+ "Table"]},"targetHandle": {- "fieldName": "embedding",+ "fieldName": "ingest_data","id": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKf","inputTypes": [- "Embeddings"+ "Data",+ "DataFrame",+ "Table"],"type": "other"}},- "id": "xy-edge__OpenAICompatibleEmbedding-aIHce{œdataTypeœ:œOpenAICompatibleEmbeddingœ,œidœ:œOpenAICompatibleEmbedding-aIHceœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}-OpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKf{œfieldNameœ:œembeddingœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKfœ,œinputTypesœ:[œEmbeddingsœ],œtypeœ:œotherœ}",+ "id": "xy-edge__ext:openrag:OpenRAGSplitTextComponent@extra-tutKN{œdataTypeœ:œext:openrag:OpenRAGSplitTextComponent@extraœ,œidœ:œext:openrag:OpenRAGSplitTextComponent@extra-tutKNœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}-OpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKf{œfieldNameœ:œingest_dataœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKfœ,œinputTypesœ:[œDataœ,œDataFrameœ,œTableœ],œtypeœ:œotherœ}","selected": false,- "source": "OpenAICompatibleEmbedding-aIHce",- "sourceHandle": "{œdataTypeœ:œOpenAICompatibleEmbeddingœ,œidœ:œOpenAICompatibleEmbedding-aIHceœ,œnameœ:œembeddingsœ,œoutput_typesœ:[œEmbeddingsœ]}",+ "source": "ext:openrag:OpenRAGSplitTextComponent@extra-tutKN",+ "sourceHandle": "{œdataTypeœ:œext:openrag:OpenRAGSplitTextComponent@extraœ,œidœ:œext:openrag:OpenRAGSplitTextComponent@extra-tutKNœ,œnameœ:œdataframeœ,œoutput_typesœ:[œTableœ]}","target": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKf",- "targetHandle": "{œfieldNameœ:œembeddingœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKfœ,œinputTypesœ:[œEmbeddingsœ],œtypeœ:œotherœ}"+ "targetHandle": "{œfieldNameœ:œingest_dataœ,œidœ:œOpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKfœ,œinputTypesœ:[œDataœ,œDataFrameœ,œTableœ],œtypeœ:œotherœ}"}],"nodes": [{"data": {- "description": "Split text into chunks based on specified criteria.",- "display_name": "Split Text",- "id": "SplitText-QIKhg",+ "description": "Fetch content from one or more web pages, following links recursively.",+ "display_name": "URL",+ "id": "URLComponent-lnA0q","node": {"base_classes": [+ "Message","Table"],"beta": false,"conditional_paths": [],"custom_fields": {},- "description": "Split text into chunks based on specified criteria.",- "display_name": "Split Text",- "documentation": "https://docs.langflow.org/split-text",+ "description": "Fetch content from one or more web pages, following links recursively.",+ "display_name": "URL",+ "documentation": "https://docs.langflow.org/url","edited": false,"field_order": [- "data_inputs",- "chunk_overlap",- "chunk_size",- "separator",- "text_key",- "keep_separator",- "clean_output"+ "urls",+ "max_depth",+ "prevent_outside",+ "use_async",+ "follow_redirects",+ "format",+ "timeout",+ "headers",+ "filter_text_html",+ "continue_on_failure",+ "check_response_status",+ "autoset_encoding"],"frozen": false,- "icon": "scissors-line-dashed",+ "icon": "layout-template","legacy": false,- "lf_version": "0.11.2rc0","metadata": {- "code_hash": "859adebdf672",+ "code_hash": "4a950f09dc59","dependencies": {"dependencies": [{- "name": "langchain_text_splitters",- "version": "1.1.1"+ "name": "httpx",+ "version": "0.28.1"+ },+ {+ "name": "bs4",+ "version": "4.15.0"+ },+ {+ "name": "markitdown",+ "version": "0.1.6"},{"name": "lfx",- "version": null+ "version": "1.12.3"}],- "total_dependencies": 2+ "total_dependencies": 4},- "module": "custom_components.split_text"+ "module": "custom_components.url"},"minimized": false,"output_types": [],@@ -292,12 +300,12 @@{"allows_loop": false,"cache": true,- "display_name": "Chunks",+ "display_name": "Extracted Pages","group_outputs": false,"hidden": null,"loop_types": null,- "method": "split_text",- "name": "dataframe",+ "method": "fetch_content",+ "name": "page_results","options": null,"required_inputs": null,"selected": "Table",@@ -306,40 +314,39 @@"Table"],"value": "__UNDEFINED__"+ },+ {+ "allows_loop": false,+ "cache": true,+ "display_name": "Raw Content",+ "group_outputs": false,+ "hidden": null,+ "loop_types": null,+ "method": "fetch_content_as_message",+ "name": "raw_results",+ "options": null,+ "required_inputs": null,+ "selected": "Message",+ "tool_mode": false,+ "types": [+ "Message"+ ],+ "value": "__UNDEFINED__"}],"pinned": false,"template": {"_type": "Component",- "chunk_overlap": {- "_input_type": "IntInput",- "advanced": false,- "display_name": "Chunk Overlap",- "dynamic": false,- "info": "Number of characters to overlap between chunks.",- "list": false,- "list_add_label": "Add More",- "name": "chunk_overlap",- "override_skip": false,- "placeholder": "",- "required": false,- "show": true,- "title_case": false,- "tool_mode": false,- "trace_as_metadata": true,- "track_in_telemetry": true,- "type": "int",- "value": 200- },- "chunk_size": {- "_input_type": "IntInput",- "advanced": false,- "display_name": "Chunk Size",+ "autoset_encoding": {+ "_input_type": "BoolInput",+ "advanced": true,+ "api_editable": false,+ "display_name": "Autoset Encoding","dynamic": false,- "info": "The maximum length of each chunk. Text is first split by separator, then chunks are merged up to this size. Individual splits larger than this won't be further divided.",+ "info": "If enabled, automatically sets the encoding of the request.","list": false,"list_add_label": "Add More",- "name": "chunk_size",+ "name": "autoset_encoding","override_skip": false,"placeholder": "","required": false,@@ -348,18 +355,19 @@"tool_mode": false,"trace_as_metadata": true,"track_in_telemetry": true,- "type": "int",- "value": 1000+ "type": "bool",+ "value": true},- "clean_output": {+ "check_response_status": {"_input_type": "BoolInput","advanced": true,- "display_name": "Clean Output",+ "api_editable": false,+ "display_name": "Check Response Status","dynamic": false,- "info": "When enabled, only the text column is included in the output. Metadata columns are removed.",+ "info": "If enabled, checks the response status of the request.","list": false,"list_add_label": "Add More",- "name": "clean_output",+ "name": "check_response_status","override_skip": false,"placeholder": "","required": false,@@ -373,6 +381,7 @@},"code": {"advanced": true,+ "api_editable": false,"dynamic": true,"fileTypes": [],"file_path": "",@@ -387,342 +396,49 @@"show": true,"title_case": false,"type": "code",- "value": "from langchain_text_splitters import CharacterTextSplitter\n\nfrom lfx.custom.custom_component.component import Component\nfrom lfx.io import BoolInput, DropdownInput, HandleInput, IntInput, MessageTextInput, Output\nfrom lfx.schema.data import Data\nfrom lfx.schema.dataframe import DataFrame\nfrom lfx.schema.message import Message\nfrom lfx.utils.util import unescape_string\n\n\nclass SplitTextComponent(Component):\n display_name: str = \"Split Text\"\n description: str = \"Split text into chunks based on specified criteria.\"\n documentation: str = \"https://docs.langflow.org/split-text\"\n icon = \"scissors-line-dashed\"\n name = \"SplitText\"\n\n inputs = [\n HandleInput(\n name=\"data_inputs\",\n display_name=\"Input\",\n info=\"The data with texts to split in chunks.\",\n input_types=[\"Data\", \"JSON\", \"DataFrame\", \"Table\", \"Message\"],\n required=True,\n ),\n IntInput(\n name=\"chunk_overlap\",\n display_name=\"Chunk Overlap\",\n info=\"Number of characters to overlap between chunks.\",\n value=200,\n ),\n IntInput(\n name=\"chunk_size\",\n display_name=\"Chunk Size\",\n info=(\n \"The maximum length of each chunk. Text is first split by separator, \"\n \"then chunks are merged up to this size. \"\n \"Individual splits larger than this won't be further divided.\"\n ),\n value=1000,\n ),\n MessageTextInput(\n name=\"separator\",\n display_name=\"Separator\",\n info=(\n \"The character to split on. Use \\\\n for newline. \"\n \"Examples: \\\\n\\\\n for paragraphs, \\\\n for lines, . for sentences\"\n ),\n value=\"\\n\",\n ),\n MessageTextInput(\n name=\"text_key\",\n display_name=\"Text Key\",\n info=\"The key to use for the text column.\",\n value=\"text\",\n advanced=True,\n ),\n DropdownInput(\n name=\"keep_separator\",\n display_name=\"Keep Separator\",\n info=\"Whether to keep the separator in the output chunks and where to place it.\",\n options=[\"False\", \"True\", \"Start\", \"End\"],\n value=\"False\",\n advanced=True,\n ),\n BoolInput(\n name=\"clean_output\",\n display_name=\"Clean Output\",\n info=\"When enabled, only the text column is included in the output. Metadata columns are removed.\",\n value=False,\n advanced=True,\n ),\n ]\n\n outputs = [\n Output(display_name=\"Chunks\", name=\"dataframe\", method=\"split_text\"),\n ]\n\n def _docs_to_data(self, docs, *, clean: bool = False) -> list[Data]:\n return [\n Data(text=doc.page_content) if clean else Data(text=doc.page_content, data=doc.metadata) for doc in docs\n ]\n\n def _fix_separator(self, separator: str) -> str:\n \"\"\"Fix common separator issues and convert to proper format.\"\"\"\n if separator == \"/n\":\n return \"\\n\"\n if separator == \"/t\":\n return \"\\t\"\n return separator\n\n def split_text_base(self):\n separator = self._fix_separator(self.separator)\n separator = unescape_string(separator)\n\n if isinstance(self.data_inputs, DataFrame):\n if not len(self.data_inputs):\n msg = \"DataFrame is empty\"\n raise TypeError(msg)\n\n self.data_inputs.text_key = self.text_key\n try:\n documents = self.data_inputs.to_lc_documents()\n except Exception as e:\n msg = f\"Error converting DataFrame to documents: {e}\"\n raise TypeError(msg) from e\n elif isinstance(self.data_inputs, Message):\n self.data_inputs = [self.data_inputs.to_data()]\n return self.split_text_base()\n else:\n if not self.data_inputs:\n msg = \"No data inputs provided\"\n raise TypeError(msg)\n\n documents = []\n if isinstance(self.data_inputs, Data):\n self.data_inputs.text_key = self.text_key\n documents = [self.data_inputs.to_lc_document()]\n else:\n try:\n documents = [input_.to_lc_document() for input_ in self.data_inputs if isinstance(input_, Data)]\n if not documents:\n msg = f\"No valid Data inputs found in {type(self.data_inputs)}\"\n raise TypeError(msg)\n except AttributeError as e:\n msg = f\"Invalid input type in collection: {e}\"\n raise TypeError(msg) from e\n try:\n # Convert string 'False'/'True' to boolean\n keep_sep = self.keep_separator\n if isinstance(keep_sep, str):\n if keep_sep.lower() == \"false\":\n keep_sep = False\n elif keep_sep.lower() == \"true\":\n keep_sep = True\n # 'start' and 'end' are kept as strings\n\n splitter = CharacterTextSplitter(\n chunk_overlap=self.chunk_overlap,\n chunk_size=self.chunk_size,\n separator=separator,\n keep_separator=keep_sep,\n )\n return splitter.split_documents(documents)\n except Exception as e:\n msg = f\"Error splitting text: {e}\"\n raise TypeError(msg) from e\n\n def split_text(self) -> DataFrame:\n docs = self.split_text_base()\n df = DataFrame(self._docs_to_data(docs, clean=self.clean_output))\n return df if self.clean_output else df.smart_column_order()\n"+ "value": "import importlib.util\nimport io\nimport re\nfrom urllib.parse import urljoin, urlparse\n\nimport httpx\nfrom bs4 import BeautifulSoup\nfrom markitdown import MarkItDown\n\nfrom lfx.custom.custom_component.component import Component\nfrom lfx.field_typing.range_spec import RangeSpec\nfrom lfx.helpers.data import safe_convert\nfrom lfx.io import BoolInput, DropdownInput, IntInput, MessageTextInput, Output, SliderInput, TableInput\nfrom lfx.log.logger import logger\nfrom lfx.schema.dataframe import DataFrame\nfrom lfx.schema.message import Message\nfrom lfx.utils.request_utils import get_user_agent\nfrom lfx.utils.ssrf_protection import SSRFProtectionError, is_ssrf_protection_enabled, validate_and_resolve_url\nfrom lfx.utils.ssrf_transport import create_ssrf_protected_client, pin_host_for_url\n\n# Constants\nDEFAULT_TIMEOUT = 30\nDEFAULT_MAX_DEPTH = 1\nDEFAULT_FORMAT = \"Text\"\n\n# HTTP status codes that carry a redirect Location header (RFC 9110).\nREDIRECT_STATUS_CODES = frozenset({301, 302, 303, 307, 308})\n\n# Maximum number of redirects to follow. Each hop is re-validated for SSRF safety;\n# matches httpx's default and the API Request component.\nMAX_REDIRECTS = 20\n\n# Default ports per scheme, used to compare redirect origins.\nDEFAULT_SCHEME_PORTS = {\"http\": 80, \"https\": 443}\n\n\nURL_REGEX = re.compile(\n r\"^(https?:\\/\\/)?\" r\"(www\\.)?\" r\"([a-zA-Z0-9.-]+)\" r\"(\\.[a-zA-Z]{2,})?\" r\"(:\\d+)?\" r\"(\\/[^\\s]*)?$\",\n re.IGNORECASE,\n)\n\nUSER_AGENT = None\n# Check if langflow is installed using importlib.util.find_spec(name))\nif importlib.util.find_spec(\"langflow\"):\n langflow_installed = True\n USER_AGENT = get_user_agent()\nelse:\n langflow_installed = False\n USER_AGENT = \"lfx\"\n\n\nclass URLComponent(Component):\n \"\"\"A component that loads and parses content from web pages recursively.\n\n This component allows fetching content from one or more URLs, with options to:\n - Control crawl depth\n - Prevent crawling outside the root domain\n - Use async loading for better performance\n - Extract either raw HTML or clean text\n - Configure request headers and timeouts\n \"\"\"\n\n display_name = \"URL\"\n description = \"Fetch content from one or more web pages, following links recursively.\"\n documentation: str = \"https://docs.langflow.org/url\"\n icon = \"layout-template\"\n name = \"URLComponent\"\n\n inputs = [\n MessageTextInput(\n name=\"urls\",\n display_name=\"URLs\",\n info=\"Enter one or more URLs to crawl recursively, by clicking the '+' button.\",\n is_list=True,\n tool_mode=True,\n placeholder=\"Enter a URL...\",\n list_add_label=\"Add URL\",\n input_types=[\"Message\"],\n ),\n SliderInput(\n name=\"max_depth\",\n display_name=\"Depth\",\n info=(\n \"Controls how many 'clicks' away from the initial page the crawler will go:\\n\"\n \"- depth 1: only the initial page\\n\"\n \"- depth 2: initial page + all pages linked directly from it\\n\"\n \"- depth 3: initial page + direct links + links found on those direct link pages\\n\"\n \"Note: This is about link traversal, not URL path depth.\"\n ),\n value=DEFAULT_MAX_DEPTH,\n range_spec=RangeSpec(min=1, max=5, step=1),\n required=False,\n min_label=\" \",\n max_label=\" \",\n min_label_icon=\"None\",\n max_label_icon=\"None\",\n # slider_input=True\n ),\n BoolInput(\n name=\"prevent_outside\",\n display_name=\"Prevent Outside\",\n info=(\n \"If enabled, only crawls URLs within the same domain as the root URL. \"\n \"This helps prevent the crawler from going to external websites.\"\n ),\n value=True,\n required=False,\n advanced=True,\n ),\n BoolInput(\n name=\"use_async\",\n display_name=\"Use Async\",\n info=(\n \"If enabled, uses asynchronous loading which can be significantly faster \"\n \"but might use more system resources.\"\n ),\n value=True,\n required=False,\n advanced=True,\n ),\n BoolInput(\n name=\"follow_redirects\",\n display_name=\"Follow Redirects\",\n info=(\n \"If enabled, follows HTTP redirects such as http→https or www/non-www \"\n \"normalization, which most sites rely on to serve their content. When SSRF \"\n \"protection is enabled (the default), every redirect hop is re-validated against \"\n \"the same blocked-IP denylist and DNS-pinned before it is fetched, so following \"\n \"redirects cannot be used to reach internal resources. Disable to capture the \"\n \"first response as-is without following redirects.\"\n ),\n value=True,\n required=False,\n advanced=True,\n ),\n DropdownInput(\n name=\"format\",\n display_name=\"Output Format\",\n info=(\n \"Output Format. Use 'Text' to extract the text from the HTML, \"\n \"'Markdown' to parse the HTML into Markdown format, or 'HTML' \"\n \"for the raw HTML content.\"\n ),\n options=[\"Text\", \"HTML\", \"Markdown\"],\n value=DEFAULT_FORMAT,\n advanced=True,\n ),\n IntInput(\n name=\"timeout\",\n display_name=\"Timeout\",\n info=\"Timeout for the request in seconds.\",\n value=DEFAULT_TIMEOUT,\n required=False,\n advanced=True,\n ),\n TableInput(\n name=\"headers\",\n display_name=\"Headers\",\n info=\"The headers to send with the request\",\n table_schema=[\n {\n \"name\": \"key\",\n \"display_name\": \"Header\",\n \"type\": \"str\",\n \"description\": \"Header name\",\n },\n {\n \"name\": \"value\",\n \"display_name\": \"Value\",\n \"type\": \"str\",\n \"description\": \"Header value\",\n },\n ],\n value=[{\"key\": \"User-Agent\", \"value\": USER_AGENT}],\n advanced=True,\n input_types=[\"DataFrame\", \"Table\"],\n ),\n BoolInput(\n name=\"filter_text_html\",\n display_name=\"Filter Text/HTML\",\n info=\"If enabled, filters out text/css content type from the results.\",\n value=True,\n required=False,\n advanced=True,\n ),\n BoolInput(\n name=\"continue_on_failure\",\n display_name=\"Continue on Failure\",\n info=\"If enabled, continues crawling even if some requests fail.\",\n value=True,\n required=False,\n advanced=True,\n ),\n BoolInput(\n name=\"check_response_status\",\n display_name=\"Check Response Status\",\n info=\"If enabled, checks the response status of the request.\",\n value=False,\n required=False,\n advanced=True,\n ),\n BoolInput(\n name=\"autoset_encoding\",\n display_name=\"Autoset Encoding\",\n info=\"If enabled, automatically sets the encoding of the request.\",\n value=True,\n required=False,\n advanced=True,\n ),\n ]\n\n outputs = [\n Output(display_name=\"Extracted Pages\", name=\"page_results\", method=\"fetch_content\"),\n Output(display_name=\"Raw Content\", name=\"raw_results\", method=\"fetch_content_as_message\", tool_mode=False),\n ]\n\n @staticmethod\n def _html_extractor(x: str) -> str:\n \"\"\"Extract raw HTML content.\"\"\"\n return x\n\n @staticmethod\n def _text_extractor(x: str) -> str:\n \"\"\"Extract clean text from HTML.\"\"\"\n return BeautifulSoup(x, \"lxml\").get_text()\n\n @staticmethod\n def _markdown_extractor(x: str) -> str:\n \"\"\"Convert HTML to Markdown format.\"\"\"\n stream = io.BytesIO(x.encode(\"utf-8\"))\n result = MarkItDown(enable_plugins=False).convert_stream(stream)\n return result.markdown\n\n @staticmethod\n def validate_url(url: str) -> bool:\n \"\"\"Validates if the given string matches URL pattern.\n\n Args:\n url: The URL string to validate\n\n Returns:\n bool: True if the URL is valid, False otherwise\n \"\"\"\n return bool(URL_REGEX.match(url))\n\n def ensure_url(self, url: str) -> tuple[str, list[str]]:\n \"\"\"Ensures the given string is a valid URL and returns validated IPs for DNS pinning.\n\n Args:\n url: The URL string to validate and normalize\n\n Returns:\n tuple[str, list[str]]: The normalized URL and list of validated IPs for DNS pinning\n\n Raises:\n ValueError: If the URL is invalid or blocked by SSRF protection\n \"\"\"\n url = url.strip()\n if not url.startswith((\"http://\", \"https://\")):\n url = \"https://\" + url\n\n if not self.validate_url(url):\n msg = f\"Invalid URL: {url}\"\n raise ValueError(msg)\n\n # ============================================================================\n # SSRF Protection with DNS Pinning\n # ============================================================================\n # This prevents DNS rebinding attacks by:\n # 1. Resolving DNS and validating IPs during security check\n # 2. Returning the validated IP addresses for DNS pinning\n # 3. Using a custom HTTP transport that forces use of the pinned IPs\n # 4. Ignoring any new DNS resolutions (prevents rebinding)\n #\n # Without DNS pinning, an attacker could:\n # - First DNS lookup: returns public IP (passes validation)\n # - Second DNS lookup: returns internal IP (bypasses protection)\n # - Attack succeeds: accesses internal services\n #\n # With DNS pinning:\n # - First DNS lookup: returns public IP (passes validation)\n # - IPs are pinned and returned\n # - HTTP request: uses pinned IPs directly (no new DNS lookup)\n # - Attack fails: even if DNS changes, we use the validated IPs\n # ============================================================================\n try:\n _validated_url, validated_ips = validate_and_resolve_url(url)\n except SSRFProtectionError as e:\n msg = f\"SSRF Protection: {e}\"\n raise ValueError(msg) from e\n else:\n # Log DNS pinning information for security auditing\n if validated_ips:\n logger.debug(f\"SSRF Protection: Using DNS pinning with {len(validated_ips)} validated IP(s) for {url}\")\n\n return url, validated_ips\n\n def _build_http_client(self, url: str, validated_ips: list[str]) -> httpx.AsyncClient:\n \"\"\"Create an HTTP client with DNS pinning for SSRF protection.\n\n Args:\n url: The request URL whose hostname will be pinned\n validated_ips: IPs validated by validate_and_resolve_url for this URL\n\n Returns:\n httpx.AsyncClient: A client with DNS pinning when SSRF protection is enabled\n \"\"\"\n if is_ssrf_protection_enabled() and validated_ips:\n hostname = pin_host_for_url(url)\n if hostname:\n return create_ssrf_protected_client(hostname=hostname, validated_ips=validated_ips)\n return httpx.AsyncClient()\n\n @staticmethod\n def _headers_for_redirect(headers: dict | None, current_url: str, next_url: str) -> dict | None:\n \"\"\"Drop sensitive headers when a redirect crosses to a different origin.\n\n Mirrors httpx's auto-follow behavior so manually following redirects does not\n leak credentials (Authorization / Cookie) to an origin other than the one the\n caller intended them for. Headers are kept only when the redirect stays on the\n same origin (scheme, host, port) or is a direct https upgrade of the same host\n on default ports - the exact cases where httpx keeps the Authorization header.\n \"\"\"\n if not headers:\n return headers\n current, nxt = urlparse(current_url), urlparse(next_url)\n current_port = current.port or DEFAULT_SCHEME_PORTS.get(current.scheme)\n next_port = nxt.port or DEFAULT_SCHEME_PORTS.get(nxt.scheme)\n same_origin = (current.scheme, current.hostname, current_port) == (nxt.scheme, nxt.hostname, next_port)\n https_upgrade = (\n current.hostname == nxt.hostname\n and current.scheme == \"http\"\n and nxt.scheme == \"https\"\n and current_port == DEFAULT_SCHEME_PORTS[\"http\"]\n and next_port == DEFAULT_SCHEME_PORTS[\"https\"]\n )\n if same_origin or https_upgrade:\n return headers\n sensitive = {\"authorization\", \"proxy-authorization\", \"cookie\"}\n return {k: v for k, v in headers.items() if k.lower() not in sensitive}\n\n def _process_response(self, response: httpx.Response) -> tuple[str, dict]:\n \"\"\"Turn a final (non-redirect) response into its HTML content and metadata.\n\n Args:\n response: The HTTP response to process\n\n Returns:\n tuple[str, dict]: The HTML content and metadata\n \"\"\"\n if self.check_response_status:\n response.raise_for_status()\n\n content_type = response.headers.get(\"content-type\", \"\").lower()\n\n # Filter out CSS files if requested\n if self.filter_text_html and \"text/css\" in content_type:\n logger.debug(f\"Skipping CSS file: {response.url}\")\n return \"\", {}\n\n # Get the HTML content\n html_content = response.text\n\n # Extract metadata\n metadata = {\n \"source\": str(response.url),\n \"title\": \"\",\n \"description\": \"\",\n \"content_type\": content_type,\n \"language\": \"\",\n }\n\n # Try to extract title and description from HTML\n try:\n soup = BeautifulSoup(html_content, \"lxml\")\n except Exception: # noqa: BLE001\n # Broad exception is acceptable here - metadata extraction is optional\n # and we don't want to fail the entire request if it fails\n logger.debug(f\"Failed to extract metadata from {response.url}\")\n else:\n if soup.title:\n metadata[\"title\"] = soup.title.string or \"\"\n\n # Try to get description from meta tags\n meta_desc = soup.find(\"meta\", attrs={\"name\": \"description\"})\n if meta_desc and meta_desc.get(\"content\"):\n metadata[\"description\"] = meta_desc[\"content\"]\n\n # Try to get language\n html_tag = soup.find(\"html\")\n if html_tag and html_tag.get(\"lang\"):\n metadata[\"language\"] = html_tag[\"lang\"]\n\n return html_content, metadata\n\n async def _fetch_with_revalidated_redirects(\n self, url: str, validated_ips: list[str], headers: dict\n ) -> tuple[str, dict]:\n \"\"\"Fetch ``url``, following redirects manually and re-validating every hop.\n\n This closes an SSRF bypass: with redirects enabled, httpx would otherwise\n auto-follow a redirect from a validated public URL to an internal address that\n the pinned transport never checked (the redirect target is a different host, so\n it is not in the pin map). Each redirect ``Location`` is resolved (relative\n locations included) and re-validated with ``ensure_url`` - the same private/\n loopback/link-local denylist and DNS pinning applied to the initial request -\n before any connection to it is made. A blocked hop raises ``ValueError`` (unless\n ``continue_on_failure``); the chain is capped at ``MAX_REDIRECTS`` hops.\n\n Args:\n url: The URL to fetch\n validated_ips: Validated IPs for DNS pinning of the initial URL\n headers: HTTP headers to send\n\n Returns:\n tuple[str, dict]: The HTML content and metadata\n \"\"\"\n current_url = url\n current_ips = validated_ips\n\n for _ in range(MAX_REDIRECTS + 1):\n async with self._build_http_client(current_url, current_ips) as client:\n response = await client.get(current_url, headers=headers, timeout=self.timeout, follow_redirects=False)\n\n location = response.headers.get(\"location\")\n if response.status_code in REDIRECT_STATUS_CODES and location:\n # Resolve relative redirects against the current URL.\n next_url = urljoin(current_url, location)\n\n # Re-validate the redirect target with the same SSRF denylist + DNS pinning.\n try:\n validated_next_url, current_ips = self.ensure_url(next_url)\n except (ValueError, SSRFProtectionError) as e:\n if self.continue_on_failure:\n logger.warning(f\"Skipping blocked or invalid redirect to {next_url}: {e}\")\n return \"\", {}\n msg = f\"SSRF Protection: blocked redirect to {next_url}: {e}\"\n raise ValueError(msg) from e\n\n headers = self._headers_for_redirect(headers, current_url, next_url)\n current_url = validated_next_url\n continue\n\n # Not a redirect (or no Location header) - this is the final response.\n return self._process_response(response)\n\n # Exhausted the redirect budget.\n if self.continue_on_failure:\n logger.warning(f\"Exceeded the maximum of {MAX_REDIRECTS} redirects while requesting {url}\")\n return \"\", {}\n msg = f\"SSRF Protection: exceeded the maximum of {MAX_REDIRECTS} redirects while requesting {url}\"\n raise ValueError(msg)\n\n async def _fetch_url_with_pinning(self, url: str, validated_ips: list[str], headers: dict) -> tuple[str, dict]:\n \"\"\"Fetch a single URL with DNS pinning protection, following redirects safely.\n\n Args:\n url: The URL to fetch\n validated_ips: Validated IPs for DNS pinning\n headers: HTTP headers to send\n\n Returns:\n tuple[str, dict]: The HTML content and metadata\n \"\"\"\n try:\n # When SSRF protection is enabled we must follow redirects manually so each hop\n # is re-validated and DNS-pinned; letting httpx auto-follow would connect to the\n # redirect target without pinning (different host, not in the pin map) and re-open\n # the SSRF hole that DNS pinning closes. With protection disabled there is no pin\n # to bypass, so httpx can follow redirects natively.\n if self.follow_redirects and is_ssrf_protection_enabled():\n return await self._fetch_with_revalidated_redirects(url, validated_ips, headers)\n\n async with self._build_http_client(url, validated_ips) as client:\n response = await client.get(\n url, headers=headers, timeout=self.timeout, follow_redirects=self.follow_redirects\n )\n return self._process_response(response)\n\n except httpx.HTTPError as e:\n if self.continue_on_failure:\n logger.warning(f\"Failed to fetch {url}: {e}\")\n return \"\", {}\n raise\n\n async def _crawl_recursive(\n self, start_url: str, validated_ips: list[str], headers: dict, visited: set, depth: int = 0\n ) -> list[dict]:\n \"\"\"Recursively crawl URLs with DNS pinning protection.\n\n Args:\n start_url: The URL to start crawling from\n validated_ips: Validated IPs for DNS pinning\n headers: HTTP headers to send\n visited: Set of already visited URLs\n depth: Current crawl depth\n\n Returns:\n list[dict]: List of documents with content and metadata\n \"\"\"\n if depth >= self.max_depth or start_url in visited:\n return []\n\n visited.add(start_url)\n documents = []\n\n # Fetch the current URL\n html_content, metadata = await self._fetch_url_with_pinning(start_url, validated_ips, headers)\n\n # Redirects may have landed on a different canonical URL (http->https, www\n # normalization). Resolve relative links and the prevent_outside check against\n # the URL the content actually came from, and mark it visited so links back to\n # the canonical form are not re-crawled.\n base_url = metadata.get(\"source\") or start_url\n visited.add(base_url)\n\n if not html_content:\n return documents\n\n # Extract content based on format\n extractors = {\n \"HTML\": self._html_extractor,\n \"Markdown\": self._markdown_extractor,\n \"Text\": self._text_extractor,\n }\n extractor = extractors.get(self.format, self._text_extractor)\n extracted_content = extractor(html_content)\n\n # Add the document\n documents.append(\n {\n \"page_content\": extracted_content,\n \"metadata\": metadata,\n }\n )\n\n # If we haven't reached max depth, extract and follow links\n if depth < self.max_depth - 1:\n try:\n soup = BeautifulSoup(html_content, \"lxml\")\n links = soup.find_all(\"a\", href=True)\n\n for link in links:\n href = link[\"href\"]\n # Resolve relative URLs\n absolute_url = urljoin(base_url, href)\n\n # Skip if already visited\n if absolute_url in visited:\n continue\n\n # Check if we should prevent going outside the domain\n if self.prevent_outside:\n start_domain = urlparse(base_url).netloc\n link_domain = urlparse(absolute_url).netloc\n if start_domain != link_domain:\n continue\n\n # Validate and crawl the linked URL\n try:\n _, link_validated_ips = self.ensure_url(absolute_url)\n sub_docs = await self._crawl_recursive(\n absolute_url, link_validated_ips, headers, visited, depth + 1\n )\n documents.extend(sub_docs)\n except (ValueError, SSRFProtectionError) as e:\n if self.continue_on_failure:\n logger.warning(f\"Skipping {absolute_url}: {e}\")\n continue\n raise\n\n except Exception: # noqa: BLE001\n # Broad exception is acceptable here - link extraction is optional\n # and we don't want to fail the entire crawl if one page has issues\n logger.debug(f\"Failed to extract links from {start_url}\")\n\n return documents\n\n async def fetch_url_contents(self) -> list[dict]:\n \"\"\"Load documents from the configured URLs with SSRF protection and DNS pinning.\n\n This method implements comprehensive SSRF (Server-Side Request Forgery) protection\n using DNS pinning to prevent DNS rebinding attacks. Each URL is validated and its\n DNS resolution is pinned before any HTTP requests are made.\n\n Returns:\n list[dict]: List of documents with content and metadata\n\n Raises:\n ValueError: If no valid URLs are provided or if there's an error loading documents\n \"\"\"\n try:\n # Validate all URLs and get their validated IPs for DNS pinning\n validated_urls = []\n first_validation_error: Exception | None = None\n for url in self.urls:\n if not url.strip():\n continue\n try:\n normalized_url, validated_ips = self.ensure_url(url)\n validated_urls.append((normalized_url, validated_ips))\n except (ValueError, SSRFProtectionError) as e:\n # Remember the first rejection so its real cause (for example an\n # SSRF block) can be surfaced if no URL survives validation,\n # instead of being hidden behind \"No valid URLs provided\".\n if first_validation_error is None:\n first_validation_error = e\n if self.continue_on_failure:\n logger.warning(f\"Skipping invalid URL {url}: {e}\")\n continue\n raise\n\n # Remove duplicates while preserving order\n seen = set()\n unique_validated_urls = []\n for url, ips in validated_urls:\n if url not in seen:\n seen.add(url)\n unique_validated_urls.append((url, ips))\n\n logger.debug(f\"Validated {len(unique_validated_urls)} unique URL(s)\")\n\n if not unique_validated_urls:\n # Surface the actual reason every candidate URL was rejected (e.g. an\n # SSRF block) rather than a generic message, so a security failure is\n # not silently swallowed when continue_on_failure is enabled.\n if first_validation_error is not None:\n raise first_validation_error\n msg = \"No valid URLs provided.\"\n raise ValueError(msg)\n\n # Prepare headers\n headers_dict = {header[\"key\"]: header[\"value\"] for header in self.headers if header[\"value\"] is not None}\n\n # Crawl all URLs\n all_docs = []\n for url, validated_ips in unique_validated_urls:\n logger.debug(f\"Crawling {url} with max_depth={self.max_depth}\")\n\n try:\n visited = set()\n docs = await self._crawl_recursive(url, validated_ips, headers_dict, visited, depth=0)\n\n if not docs:\n logger.warning(f\"No documents found for {url}\")\n continue\n\n logger.debug(f\"Found {len(docs)} document(s) from {url}\")\n all_docs.extend(docs)\n\n except httpx.HTTPError as e:\n if self.continue_on_failure:\n logger.warning(f\"Error loading documents from {url}: {e}\")\n continue\n msg = f\"Error loading documents from {url}: {e}\"\n raise ValueError(msg) from e\n\n if not all_docs:\n msg = \"No documents were successfully loaded from any URL\"\n raise ValueError(msg)\n\n # Convert to output format\n return [\n {\n \"text\": safe_convert(doc[\"page_content\"], clean_data=True),\n \"url\": doc[\"metadata\"].get(\"source\", \"\"),\n \"title\": doc[\"metadata\"].get(\"title\", \"\"),\n \"description\": doc[\"metadata\"].get(\"description\", \"\"),\n \"content_type\": doc[\"metadata\"].get(\"content_type\", \"\"),\n \"language\": doc[\"metadata\"].get(\"language\", \"\"),\n }\n for doc in all_docs\n ]\n\n except Exception as e:\n error_msg = e.message if hasattr(e, \"message\") else str(e)\n msg = f\"Error loading documents: {error_msg}\"\n logger.exception(msg)\n raise ValueError(msg) from e\n\n async def fetch_content(self) -> DataFrame:\n \"\"\"Convert the documents to a DataFrame.\"\"\"\n url_contents = await self.fetch_url_contents()\n return DataFrame(data=url_contents)\n\n async def fetch_content_as_message(self) -> Message:\n \"\"\"Convert the documents to a Message.\"\"\"\n url_contents = await self.fetch_url_contents()\n return Message(text=\"\\n\\n\".join([x[\"text\"] for x in url_contents]), data={\"data\": url_contents})\n"},- "data_inputs": {- "_input_type": "HandleInput",- "advanced": false,- "display_name": "Input",+ "continue_on_failure": {+ "_input_type": "BoolInput",+ "advanced": true,+ "api_editable": false,+ "display_name": "Continue on Failure","dynamic": false,- "info": "The data with texts to split in chunks.",- "input_types": [- "Data",- "JSON",- "DataFrame",- "Table",- "Message"- ],+ "info": "If enabled, continues crawling even if some requests fail.","list": false,"list_add_label": "Add More",- "name": "data_inputs",+ "name": "continue_on_failure","override_skip": false,"placeholder": "",- "required": true,+ "required": false,"show": true,"title_case": false,+ "tool_mode": false,"trace_as_metadata": true,- "track_in_telemetry": false,- "type": "other",- "value": ""+ "track_in_telemetry": true,+ "type": "bool",+ "value": true},- "keep_separator": {- "_input_type": "DropdownInput",+ "filter_text_html": {+ "_input_type": "BoolInput","advanced": true,- "combobox": false,- "dialog_inputs": {},- "display_name": "Keep Separator",+ "api_editable": false,+ "display_name": "Filter Text/HTML","dynamic": false,- "external_options": {},- "info": "Whether to keep the separator in the output chunks and where to place it.",- "name": "keep_separator",- "options": [- "False",- "True",- "Start",- "End"- ],- "options_metadata": [],+ "info": "If enabled, filters out text/css content type from the results.",+ "list": false,+ "list_add_label": "Add More",+ "name": "filter_text_html","override_skip": false,"placeholder": "","required": false,"show": true,"title_case": false,- "toggle": false,"tool_mode": false,"trace_as_metadata": true,"track_in_telemetry": true,- "type": "str",- "value": "False"- },- "separator": {- "_input_type": "MessageTextInput",- "advanced": false,- "display_name": "Separator",- "dynamic": false,- "info": "The character to split on. Use \\n for newline. Examples: \\n\\n for paragraphs, \\n for lines, . for sentences",- "input_types": [- "Message"- ],- "list": false,- "list_add_label": "Add More",- "load_from_db": false,- "name": "separator",- "override_skip": false,- "placeholder": "",- "required": false,- "show": true,- "title_case": false,- "tool_mode": false,- "trace_as_input": true,- "trace_as_metadata": true,- "track_in_telemetry": false,- "type": "str",- "value": "\n"- },- "text_key": {- "_input_type": "MessageTextInput",- "advanced": true,- "display_name": "Text Key",- "dynamic": false,- "info": "The key to use for the text column.",- "input_types": [- "Message"- ],- "list": false,- "list_add_label": "Add More",- "load_from_db": false,- "name": "text_key",- "override_skip": false,- "placeholder": "",- "required": false,- "show": true,- "title_case": false,- "tool_mode": false,- "trace_as_input": true,- "trace_as_metadata": true,- "track_in_telemetry": false,- "type": "str",- "value": "text"- }- },- "tool_mode": false- },- "selected_output": "chunks",- "showNode": false,- "type": "SplitText"- },- "dragging": false,- "id": "SplitText-QIKhg",- "measured": {- "height": 80,- "width": 192- },- "position": {- "x": 2022.4035325410573,- "y": 1615.010391456511- },- "positionAbsolute": {- "x": 1683.4543896546102,- "y": 1350.7871623588553- },- "selected": false,- "type": "genericNode"- },- {- "data": {- "description": "Fetch content from one or more web pages, following links recursively.",- "display_name": "URL",- "id": "URLComponent-lnA0q",- "node": {- "base_classes": [- "Message",- "Table"- ],- "beta": false,- "conditional_paths": [],- "custom_fields": {},- "description": "Fetch content from one or more web pages, following links recursively.",- "display_name": "URL",- "documentation": "https://docs.langflow.org/url",- "edited": false,- "field_order": [- "urls",- "max_depth",- "prevent_outside",- "use_async",- "follow_redirects",- "format",- "timeout",- "headers",- "filter_text_html",- "continue_on_failure",- "check_response_status",- "autoset_encoding"- ],- "frozen": false,- "icon": "layout-template",- "legacy": false,- "lf_version": "0.11.2rc0",- "metadata": {- "code_hash": "52b5bd602242",- "dependencies": {- "dependencies": [- {- "name": "httpx",- "version": "0.28.1"- },- {- "name": "bs4",- "version": "4.15.0"- },- {- "name": "markitdown",- "version": "0.1.6"- },- {- "name": "lfx",- "version": null- }- ],- "total_dependencies": 4- },- "module": "custom_components.url"- },- "minimized": false,- "output_types": [],- "outputs": [- {- "allows_loop": false,- "cache": true,- "display_name": "Extracted Pages",- "group_outputs": false,- "hidden": null,- "loop_types": null,- "method": "fetch_content",- "name": "page_results",- "options": null,- "required_inputs": null,- "selected": "Table",- "tool_mode": true,- "types": [- "Table"- ],- "value": "__UNDEFINED__"- },- {- "allows_loop": false,- "cache": true,- "display_name": "Raw Content",- "group_outputs": false,- "hidden": null,- "loop_types": null,- "method": "fetch_content_as_message",- "name": "raw_results",- "options": null,- "required_inputs": null,- "selected": "Message",- "tool_mode": false,- "types": [- "Message"- ],- "value": "__UNDEFINED__"- }- ],- "pinned": false,- "template": {- "_type": "Component",- "autoset_encoding": {- "_input_type": "BoolInput",- "advanced": true,- "api_editable": false,- "display_name": "Autoset Encoding",- "dynamic": false,- "info": "If enabled, automatically sets the encoding of the request.",- "list": false,- "list_add_label": "Add More",- "name": "autoset_encoding",- "override_skip": false,- "placeholder": "",- "required": false,- "show": true,- "title_case": false,- "tool_mode": false,- "trace_as_metadata": true,- "track_in_telemetry": true,- "type": "bool",- "value": true- },- "check_response_status": {- "_input_type": "BoolInput",- "advanced": true,- "api_editable": false,- "display_name": "Check Response Status",- "dynamic": false,- "info": "If enabled, checks the response status of the request.",- "list": false,- "list_add_label": "Add More",- "name": "check_response_status",- "override_skip": false,- "placeholder": "",- "required": false,- "show": true,- "title_case": false,- "tool_mode": false,- "trace_as_metadata": true,- "track_in_telemetry": true,- "type": "bool",- "value": false- },- "code": {- "advanced": true,- "api_editable": false,- "dynamic": true,- "fileTypes": [],- "file_path": "",- "info": "",- "list": false,- "load_from_db": false,- "multiline": true,- "name": "code",- "password": false,- "placeholder": "",- "required": true,- "show": true,- "title_case": false,- "type": "code",- "value": "import importlib.util\nimport io\nimport re\nfrom urllib.parse import urljoin, urlparse\n\nimport httpx\nfrom bs4 import BeautifulSoup\nfrom markitdown import MarkItDown\n\nfrom lfx.custom.custom_component.component import Component\nfrom lfx.field_typing.range_spec import RangeSpec\nfrom lfx.helpers.data import safe_convert\nfrom lfx.io import BoolInput, DropdownInput, IntInput, MessageTextInput, Output, SliderInput, TableInput\nfrom lfx.log.logger import logger\nfrom lfx.schema.dataframe import DataFrame\nfrom lfx.schema.message import Message\nfrom lfx.utils.request_utils import get_user_agent\nfrom lfx.utils.ssrf_protection import SSRFProtectionError, is_ssrf_protection_enabled, validate_and_resolve_url\nfrom lfx.utils.ssrf_transport import create_ssrf_protected_client\n\n# Constants\nDEFAULT_TIMEOUT = 30\nDEFAULT_MAX_DEPTH = 1\nDEFAULT_FORMAT = \"Text\"\n\n# HTTP status codes that carry a redirect Location header (RFC 9110).\nREDIRECT_STATUS_CODES = frozenset({301, 302, 303, 307, 308})\n\n# Maximum number of redirects to follow. Each hop is re-validated for SSRF safety;\n# matches httpx's default and the API Request component.\nMAX_REDIRECTS = 20\n\n# Default ports per scheme, used to compare redirect origins.\nDEFAULT_SCHEME_PORTS = {\"http\": 80, \"https\": 443}\n\n\nURL_REGEX = re.compile(\n r\"^(https?:\\/\\/)?\" r\"(www\\.)?\" r\"([a-zA-Z0-9.-]+)\" r\"(\\.[a-zA-Z]{2,})?\" r\"(:\\d+)?\" r\"(\\/[^\\s]*)?$\",\n re.IGNORECASE,\n)\n\nUSER_AGENT = None\n# Check if langflow is installed using importlib.util.find_spec(name))\nif importlib.util.find_spec(\"langflow\"):\n langflow_installed = True\n USER_AGENT = get_user_agent()\nelse:\n langflow_installed = False\n USER_AGENT = \"lfx\"\n\n\nclass URLComponent(Component):\n \"\"\"A component that loads and parses content from web pages recursively.\n\n This component allows fetching content from one or more URLs, with options to:\n - Control crawl depth\n - Prevent crawling outside the root domain\n - Use async loading for better performance\n - Extract either raw HTML or clean text\n - Configure request headers and timeouts\n \"\"\"\n\n display_name = \"URL\"\n description = \"Fetch content from one or more web pages, following links recursively.\"\n documentation: str = \"https://docs.langflow.org/url\"\n icon = \"layout-template\"\n name = \"URLComponent\"\n\n inputs = [\n MessageTextInput(\n name=\"urls\",\n display_name=\"URLs\",\n info=\"Enter one or more URLs to crawl recursively, by clicking the '+' button.\",\n is_list=True,\n tool_mode=True,\n placeholder=\"Enter a URL...\",\n list_add_label=\"Add URL\",\n input_types=[\"Message\"],\n ),\n SliderInput(\n name=\"max_depth\",\n display_name=\"Depth\",\n info=(\n \"Controls how many 'clicks' away from the initial page the crawler will go:\\n\"\n \"- depth 1: only the initial page\\n\"\n \"- depth 2: initial page + all pages linked directly from it\\n\"\n \"- depth 3: initial page + direct links + links found on those direct link pages\\n\"\n \"Note: This is about link traversal, not URL path depth.\"\n ),\n value=DEFAULT_MAX_DEPTH,\n range_spec=RangeSpec(min=1, max=5, step=1),\n required=False,\n min_label=\" \",\n max_label=\" \",\n min_label_icon=\"None\",\n max_label_icon=\"None\",\n # slider_input=True\n ),\n BoolInput(\n name=\"prevent_outside\",\n display_name=\"Prevent Outside\",\n info=(\n \"If enabled, only crawls URLs within the same domain as the root URL. \"\n \"This helps prevent the crawler from going to external websites.\"\n ),\n value=True,\n required=False,\n advanced=True,\n ),\n BoolInput(\n name=\"use_async\",\n display_name=\"Use Async\",\n info=(\n \"If enabled, uses asynchronous loading which can be significantly faster \"\n \"but might use more system resources.\"\n ),\n value=True,\n required=False,\n advanced=True,\n ),\n BoolInput(\n name=\"follow_redirects\",\n display_name=\"Follow Redirects\",\n info=(\n \"If enabled, follows HTTP redirects such as http→https or www/non-www \"\n \"normalization, which most sites rely on to serve their content. When SSRF \"\n \"protection is enabled (the default), every redirect hop is re-validated against \"\n \"the same blocked-IP denylist and DNS-pinned before it is fetched, so following \"\n \"redirects cannot be used to reach internal resources. Disable to capture the \"\n \"first response as-is without following redirects.\"\n ),\n value=True,\n required=False,\n advanced=True,\n ),\n DropdownInput(\n name=\"format\",\n display_name=\"Output Format\",\n info=(\n \"Output Format. Use 'Text' to extract the text from the HTML, \"\n \"'Markdown' to parse the HTML into Markdown format, or 'HTML' \"\n \"for the raw HTML content.\"\n ),\n options=[\"Text\", \"HTML\", \"Markdown\"],\n value=DEFAULT_FORMAT,\n advanced=True,\n ),\n IntInput(\n name=\"timeout\",\n display_name=\"Timeout\",\n info=\"Timeout for the request in seconds.\",\n value=DEFAULT_TIMEOUT,\n required=False,\n advanced=True,\n ),\n TableInput(\n name=\"headers\",\n display_name=\"Headers\",\n info=\"The headers to send with the request\",\n table_schema=[\n {\n \"name\": \"key\",\n \"display_name\": \"Header\",\n \"type\": \"str\",\n \"description\": \"Header name\",\n },\n {\n \"name\": \"value\",\n \"display_name\": \"Value\",\n \"type\": \"str\",\n \"description\": \"Header value\",\n },\n ],\n value=[{\"key\": \"User-Agent\", \"value\": USER_AGENT}],\n advanced=True,\n input_types=[\"DataFrame\", \"Table\"],\n ),\n BoolInput(\n name=\"filter_text_html\",\n display_name=\"Filter Text/HTML\",\n info=\"If enabled, filters out text/css content type from the results.\",\n value=True,\n required=False,\n advanced=True,\n ),\n BoolInput(\n name=\"continue_on_failure\",\n display_name=\"Continue on Failure\",\n info=\"If enabled, continues crawling even if some requests fail.\",\n value=True,\n required=False,\n advanced=True,\n ),\n BoolInput(\n name=\"check_response_status\",\n display_name=\"Check Response Status\",\n info=\"If enabled, checks the response status of the request.\",\n value=False,\n required=False,\n advanced=True,\n ),\n BoolInput(\n name=\"autoset_encoding\",\n display_name=\"Autoset Encoding\",\n info=\"If enabled, automatically sets the encoding of the request.\",\n value=True,\n required=False,\n advanced=True,\n ),\n ]\n\n outputs = [\n Output(display_name=\"Extracted Pages\", name=\"page_results\", method=\"fetch_content\"),\n Output(display_name=\"Raw Content\", name=\"raw_results\", method=\"fetch_content_as_message\", tool_mode=False),\n ]\n\n @staticmethod\n def _html_extractor(x: str) -> str:\n \"\"\"Extract raw HTML content.\"\"\"\n return x\n\n @staticmethod\n def _text_extractor(x: str) -> str:\n \"\"\"Extract clean text from HTML.\"\"\"\n return BeautifulSoup(x, \"lxml\").get_text()\n\n @staticmethod\n def _markdown_extractor(x: str) -> str:\n \"\"\"Convert HTML to Markdown format.\"\"\"\n stream = io.BytesIO(x.encode(\"utf-8\"))\n result = MarkItDown(enable_plugins=False).convert_stream(stream)\n return result.markdown\n\n @staticmethod\n def validate_url(url: str) -> bool:\n \"\"\"Validates if the given string matches URL pattern.\n\n Args:\n url: The URL string to validate\n\n Returns:\n bool: True if the URL is valid, False otherwise\n \"\"\"\n return bool(URL_REGEX.match(url))\n\n def ensure_url(self, url: str) -> tuple[str, list[str]]:\n \"\"\"Ensures the given string is a valid URL and returns validated IPs for DNS pinning.\n\n Args:\n url: The URL string to validate and normalize\n\n Returns:\n tuple[str, list[str]]: The normalized URL and list of validated IPs for DNS pinning\n\n Raises:\n ValueError: If the URL is invalid or blocked by SSRF protection\n \"\"\"\n url = url.strip()\n if not url.startswith((\"http://\", \"https://\")):\n url = \"https://\" + url\n\n if not self.validate_url(url):\n msg = f\"Invalid URL: {url}\"\n raise ValueError(msg)\n\n # ============================================================================\n # SSRF Protection with DNS Pinning\n # ============================================================================\n # This prevents DNS rebinding attacks by:\n # 1. Resolving DNS and validating IPs during security check\n # 2. Returning the validated IP addresses for DNS pinning\n # 3. Using a custom HTTP transport that forces use of the pinned IPs\n # 4. Ignoring any new DNS resolutions (prevents rebinding)\n #\n # Without DNS pinning, an attacker could:\n # - First DNS lookup: returns public IP (passes validation)\n # - Second DNS lookup: returns internal IP (bypasses protection)\n # - Attack succeeds: accesses internal services\n #\n # With DNS pinning:\n # - First DNS lookup: returns public IP (passes validation)\n # - IPs are pinned and returned\n # - HTTP request: uses pinned IPs directly (no new DNS lookup)\n # - Attack fails: even if DNS changes, we use the validated IPs\n # ============================================================================\n try:\n _validated_url, validated_ips = validate_and_resolve_url(url)\n except SSRFProtectionError as e:\n msg = f\"SSRF Protection: {e}\"\n raise ValueError(msg) from e\n else:\n # Log DNS pinning information for security auditing\n if validated_ips:\n logger.debug(f\"SSRF Protection: Using DNS pinning with {len(validated_ips)} validated IP(s) for {url}\")\n\n return url, validated_ips\n\n def _build_http_client(self, url: str, validated_ips: list[str]) -> httpx.AsyncClient:\n \"\"\"Create an HTTP client with DNS pinning for SSRF protection.\n\n Args:\n url: The request URL whose hostname will be pinned\n validated_ips: IPs validated by validate_and_resolve_url for this URL\n\n Returns:\n httpx.AsyncClient: A client with DNS pinning when SSRF protection is enabled\n \"\"\"\n if is_ssrf_protection_enabled() and validated_ips:\n hostname = urlparse(url).hostname\n if hostname:\n return create_ssrf_protected_client(hostname=hostname, validated_ips=validated_ips)\n return httpx.AsyncClient()\n\n @staticmethod\n def _headers_for_redirect(headers: dict | None, current_url: str, next_url: str) -> dict | None:\n \"\"\"Drop sensitive headers when a redirect crosses to a different origin.\n\n Mirrors httpx's auto-follow behavior so manually following redirects does not\n leak credentials (Authorization / Cookie) to an origin other than the one the\n caller intended them for. Headers are kept only when the redirect stays on the\n same origin (scheme, host, port) or is a direct https upgrade of the same host\n on default ports - the exact cases where httpx keeps the Authorization header.\n \"\"\"\n if not headers:\n return headers\n current, nxt = urlparse(current_url), urlparse(next_url)\n current_port = current.port or DEFAULT_SCHEME_PORTS.get(current.scheme)\n next_port = nxt.port or DEFAULT_SCHEME_PORTS.get(nxt.scheme)\n same_origin = (current.scheme, current.hostname, current_port) == (nxt.scheme, nxt.hostname, next_port)\n https_upgrade = (\n current.hostname == nxt.hostname\n and current.scheme == \"http\"\n and nxt.scheme == \"https\"\n and current_port == DEFAULT_SCHEME_PORTS[\"http\"]\n and next_port == DEFAULT_SCHEME_PORTS[\"https\"]\n )\n if same_origin or https_upgrade:\n return headers\n sensitive = {\"authorization\", \"proxy-authorization\", \"cookie\"}\n return {k: v for k, v in headers.items() if k.lower() not in sensitive}\n\n def _process_response(self, response: httpx.Response) -> tuple[str, dict]:\n \"\"\"Turn a final (non-redirect) response into its HTML content and metadata.\n\n Args:\n response: The HTTP response to process\n\n Returns:\n tuple[str, dict]: The HTML content and metadata\n \"\"\"\n if self.check_response_status:\n response.raise_for_status()\n\n content_type = response.headers.get(\"content-type\", \"\").lower()\n\n # Filter out CSS files if requested\n if self.filter_text_html and \"text/css\" in content_type:\n logger.debug(f\"Skipping CSS file: {response.url}\")\n return \"\", {}\n\n # Get the HTML content\n html_content = response.text\n\n # Extract metadata\n metadata = {\n \"source\": str(response.url),\n \"title\": \"\",\n \"description\": \"\",\n \"content_type\": content_type,\n \"language\": \"\",\n }\n\n # Try to extract title and description from HTML\n try:\n soup = BeautifulSoup(html_content, \"lxml\")\n except Exception: # noqa: BLE001\n # Broad exception is acceptable here - metadata extraction is optional\n # and we don't want to fail the entire request if it fails\n logger.debug(f\"Failed to extract metadata from {response.url}\")\n else:\n if soup.title:\n metadata[\"title\"] = soup.title.string or \"\"\n\n # Try to get description from meta tags\n meta_desc = soup.find(\"meta\", attrs={\"name\": \"description\"})\n if meta_desc and meta_desc.get(\"content\"):\n metadata[\"description\"] = meta_desc[\"content\"]\n\n # Try to get language\n html_tag = soup.find(\"html\")\n if html_tag and html_tag.get(\"lang\"):\n metadata[\"language\"] = html_tag[\"lang\"]\n\n return html_content, metadata\n\n async def _fetch_with_revalidated_redirects(\n self, url: str, validated_ips: list[str], headers: dict\n ) -> tuple[str, dict]:\n \"\"\"Fetch ``url``, following redirects manually and re-validating every hop.\n\n This closes an SSRF bypass: with redirects enabled, httpx would otherwise\n auto-follow a redirect from a validated public URL to an internal address that\n the pinned transport never checked (the redirect target is a different host, so\n it is not in the pin map). Each redirect ``Location`` is resolved (relative\n locations included) and re-validated with ``ensure_url`` - the same private/\n loopback/link-local denylist and DNS pinning applied to the initial request -\n before any connection to it is made. A blocked hop raises ``ValueError`` (unless\n ``continue_on_failure``); the chain is capped at ``MAX_REDIRECTS`` hops.\n\n Args:\n url: The URL to fetch\n validated_ips: Validated IPs for DNS pinning of the initial URL\n headers: HTTP headers to send\n\n Returns:\n tuple[str, dict]: The HTML content and metadata\n \"\"\"\n current_url = url\n current_ips = validated_ips\n\n for _ in range(MAX_REDIRECTS + 1):\n async with self._build_http_client(current_url, current_ips) as client:\n response = await client.get(current_url, headers=headers, timeout=self.timeout, follow_redirects=False)\n\n location = response.headers.get(\"location\")\n if response.status_code in REDIRECT_STATUS_CODES and location:\n # Resolve relative redirects against the current URL.\n next_url = urljoin(current_url, location)\n\n # Re-validate the redirect target with the same SSRF denylist + DNS pinning.\n try:\n validated_next_url, current_ips = self.ensure_url(next_url)\n except (ValueError, SSRFProtectionError) as e:\n if self.continue_on_failure:\n logger.warning(f\"Skipping blocked or invalid redirect to {next_url}: {e}\")\n return \"\", {}\n msg = f\"SSRF Protection: blocked redirect to {next_url}: {e}\"\n raise ValueError(msg) from e\n\n headers = self._headers_for_redirect(headers, current_url, next_url)\n current_url = validated_next_url\n continue\n\n # Not a redirect (or no Location header) - this is the final response.\n return self._process_response(response)\n\n # Exhausted the redirect budget.\n if self.continue_on_failure:\n logger.warning(f\"Exceeded the maximum of {MAX_REDIRECTS} redirects while requesting {url}\")\n return \"\", {}\n msg = f\"SSRF Protection: exceeded the maximum of {MAX_REDIRECTS} redirects while requesting {url}\"\n raise ValueError(msg)\n\n async def _fetch_url_with_pinning(self, url: str, validated_ips: list[str], headers: dict) -> tuple[str, dict]:\n \"\"\"Fetch a single URL with DNS pinning protection, following redirects safely.\n\n Args:\n url: The URL to fetch\n validated_ips: Validated IPs for DNS pinning\n headers: HTTP headers to send\n\n Returns:\n tuple[str, dict]: The HTML content and metadata\n \"\"\"\n try:\n # When SSRF protection is enabled we must follow redirects manually so each hop\n # is re-validated and DNS-pinned; letting httpx auto-follow would connect to the\n # redirect target without pinning (different host, not in the pin map) and re-open\n # the SSRF hole that DNS pinning closes. With protection disabled there is no pin\n # to bypass, so httpx can follow redirects natively.\n if self.follow_redirects and is_ssrf_protection_enabled():\n return await self._fetch_with_revalidated_redirects(url, validated_ips, headers)\n\n async with self._build_http_client(url, validated_ips) as client:\n response = await client.get(\n url, headers=headers, timeout=self.timeout, follow_redirects=self.follow_redirects\n )\n return self._process_response(response)\n\n except httpx.HTTPError as e:\n if self.continue_on_failure:\n logger.warning(f\"Failed to fetch {url}: {e}\")\n return \"\", {}\n raise\n\n async def _crawl_recursive(\n self, start_url: str, validated_ips: list[str], headers: dict, visited: set, depth: int = 0\n ) -> list[dict]:\n \"\"\"Recursively crawl URLs with DNS pinning protection.\n\n Args:\n start_url: The URL to start crawling from\n validated_ips: Validated IPs for DNS pinning\n headers: HTTP headers to send\n visited: Set of already visited URLs\n depth: Current crawl depth\n\n Returns:\n list[dict]: List of documents with content and metadata\n \"\"\"\n if depth >= self.max_depth or start_url in visited:\n return []\n\n visited.add(start_url)\n documents = []\n\n # Fetch the current URL\n html_content, metadata = await self._fetch_url_with_pinning(start_url, validated_ips, headers)\n\n # Redirects may have landed on a different canonical URL (http->https, www\n # normalization). Resolve relative links and the prevent_outside check against\n # the URL the content actually came from, and mark it visited so links back to\n # the canonical form are not re-crawled.\n base_url = metadata.get(\"source\") or start_url\n visited.add(base_url)\n\n if not html_content:\n return documents\n\n # Extract content based on format\n extractors = {\n \"HTML\": self._html_extractor,\n \"Markdown\": self._markdown_extractor,\n \"Text\": self._text_extractor,\n }\n extractor = extractors.get(self.format, self._text_extractor)\n extracted_content = extractor(html_content)\n\n # Add the document\n documents.append(\n {\n \"page_content\": extracted_content,\n \"metadata\": metadata,\n }\n )\n\n # If we haven't reached max depth, extract and follow links\n if depth < self.max_depth - 1:\n try:\n soup = BeautifulSoup(html_content, \"lxml\")\n links = soup.find_all(\"a\", href=True)\n\n for link in links:\n href = link[\"href\"]\n # Resolve relative URLs\n absolute_url = urljoin(base_url, href)\n\n # Skip if already visited\n if absolute_url in visited:\n continue\n\n # Check if we should prevent going outside the domain\n if self.prevent_outside:\n start_domain = urlparse(base_url).netloc\n link_domain = urlparse(absolute_url).netloc\n if start_domain != link_domain:\n continue\n\n # Validate and crawl the linked URL\n try:\n _, link_validated_ips = self.ensure_url(absolute_url)\n sub_docs = await self._crawl_recursive(\n absolute_url, link_validated_ips, headers, visited, depth + 1\n )\n documents.extend(sub_docs)\n except (ValueError, SSRFProtectionError) as e:\n if self.continue_on_failure:\n logger.warning(f\"Skipping {absolute_url}: {e}\")\n continue\n raise\n\n except Exception: # noqa: BLE001\n # Broad exception is acceptable here - link extraction is optional\n # and we don't want to fail the entire crawl if one page has issues\n logger.debug(f\"Failed to extract links from {start_url}\")\n\n return documents\n\n async def fetch_url_contents(self) -> list[dict]:\n \"\"\"Load documents from the configured URLs with SSRF protection and DNS pinning.\n\n This method implements comprehensive SSRF (Server-Side Request Forgery) protection\n using DNS pinning to prevent DNS rebinding attacks. Each URL is validated and its\n DNS resolution is pinned before any HTTP requests are made.\n\n Returns:\n list[dict]: List of documents with content and metadata\n\n Raises:\n ValueError: If no valid URLs are provided or if there's an error loading documents\n \"\"\"\n try:\n # Validate all URLs and get their validated IPs for DNS pinning\n validated_urls = []\n first_validation_error: Exception | None = None\n for url in self.urls:\n if not url.strip():\n continue\n try:\n normalized_url, validated_ips = self.ensure_url(url)\n validated_urls.append((normalized_url, validated_ips))\n except (ValueError, SSRFProtectionError) as e:\n # Remember the first rejection so its real cause (for example an\n # SSRF block) can be surfaced if no URL survives validation,\n # instead of being hidden behind \"No valid URLs provided\".\n if first_validation_error is None:\n first_validation_error = e\n if self.continue_on_failure:\n logger.warning(f\"Skipping invalid URL {url}: {e}\")\n continue\n raise\n\n # Remove duplicates while preserving order\n seen = set()\n unique_validated_urls = []\n for url, ips in validated_urls:\n if url not in seen:\n seen.add(url)\n unique_validated_urls.append((url, ips))\n\n logger.debug(f\"Validated {len(unique_validated_urls)} unique URL(s)\")\n\n if not unique_validated_urls:\n # Surface the actual reason every candidate URL was rejected (e.g. an\n # SSRF block) rather than a generic message, so a security failure is\n # not silently swallowed when continue_on_failure is enabled.\n if first_validation_error is not None:\n raise first_validation_error\n msg = \"No valid URLs provided.\"\n raise ValueError(msg)\n\n # Prepare headers\n headers_dict = {header[\"key\"]: header[\"value\"] for header in self.headers if header[\"value\"] is not None}\n\n # Crawl all URLs\n all_docs = []\n for url, validated_ips in unique_validated_urls:\n logger.debug(f\"Crawling {url} with max_depth={self.max_depth}\")\n\n try:\n visited = set()\n docs = await self._crawl_recursive(url, validated_ips, headers_dict, visited, depth=0)\n\n if not docs:\n logger.warning(f\"No documents found for {url}\")\n continue\n\n logger.debug(f\"Found {len(docs)} document(s) from {url}\")\n all_docs.extend(docs)\n\n except httpx.HTTPError as e:\n if self.continue_on_failure:\n logger.warning(f\"Error loading documents from {url}: {e}\")\n continue\n msg = f\"Error loading documents from {url}: {e}\"\n raise ValueError(msg) from e\n\n if not all_docs:\n msg = \"No documents were successfully loaded from any URL\"\n raise ValueError(msg)\n\n # Convert to output format\n return [\n {\n \"text\": safe_convert(doc[\"page_content\"], clean_data=True),\n \"url\": doc[\"metadata\"].get(\"source\", \"\"),\n \"title\": doc[\"metadata\"].get(\"title\", \"\"),\n \"description\": doc[\"metadata\"].get(\"description\", \"\"),\n \"content_type\": doc[\"metadata\"].get(\"content_type\", \"\"),\n \"language\": doc[\"metadata\"].get(\"language\", \"\"),\n }\n for doc in all_docs\n ]\n\n except Exception as e:\n error_msg = e.message if hasattr(e, \"message\") else str(e)\n msg = f\"Error loading documents: {error_msg}\"\n logger.exception(msg)\n raise ValueError(msg) from e\n\n async def fetch_content(self) -> DataFrame:\n \"\"\"Convert the documents to a DataFrame.\"\"\"\n url_contents = await self.fetch_url_contents()\n return DataFrame(data=url_contents)\n\n async def fetch_content_as_message(self) -> Message:\n \"\"\"Convert the documents to a Message.\"\"\"\n url_contents = await self.fetch_url_contents()\n return Message(text=\"\\n\\n\".join([x[\"text\"] for x in url_contents]), data={\"data\": url_contents})\n"- },- "continue_on_failure": {- "_input_type": "BoolInput",- "advanced": true,- "api_editable": false,- "display_name": "Continue on Failure",- "dynamic": false,- "info": "If enabled, continues crawling even if some requests fail.",- "list": false,- "list_add_label": "Add More",- "name": "continue_on_failure",- "override_skip": false,- "placeholder": "",- "required": false,- "show": true,- "title_case": false,- "tool_mode": false,- "trace_as_metadata": true,- "track_in_telemetry": true,- "type": "bool",- "value": true- },- "filter_text_html": {- "_input_type": "BoolInput",- "advanced": true,- "api_editable": false,- "display_name": "Filter Text/HTML",- "dynamic": false,- "info": "If enabled, filters out text/css content type from the results.",- "list": false,- "list_add_label": "Add More",- "name": "filter_text_html",- "override_skip": false,- "placeholder": "",- "required": false,- "show": true,- "title_case": false,- "tool_mode": false,- "trace_as_metadata": true,- "track_in_telemetry": true,- "type": "bool",- "value": true+ "type": "bool",+ "value": true},"follow_redirects": {"_input_type": "BoolInput",@@ -846,12 +562,14 @@"show": true,"slider_buttons": false,"slider_buttons_options": [],+ "slider_color": "default","slider_input": false,"title_case": false,"tool_mode": false,"track_in_telemetry": false,"type": "slider",- "value": 1+ "value": 1,+ "value_inverted": false},"prevent_outside": {"_input_type": "BoolInput",@@ -1574,6 +1292,8 @@},{"data": {+ "description": "Perform operations on Text, JSON, and Tables from a single component.",+ "display_name": "Data Operations","id": "Operations-uhog5","node": {"base_classes": [@@ -1635,11 +1355,10 @@],"frozen": false,"icon": "wand-sparkles",- "last_updated": "2026-07-17T19:26:36.210Z",+ "last_updated": "2026-10-27T20:16:08.410Z","legacy": false,- "lf_version": "0.11.1rc0","metadata": {- "code_hash": "4c2a33c778d3",+ "code_hash": "f15ba610cfd0","dependencies": {"dependencies": [{@@ -1648,11 +1367,11 @@},{"name": "json_repair",- "version": "0.61.4"+ "version": "0.61.7"},{"name": "lfx",- "version": null+ "version": "1.12.3"},{"name": "jq",@@ -1703,7 +1422,7 @@"data manipulation","data transformation"],- "module": "lfx.components.processing.operations.OperationsComponent"+ "module": "custom_components.data_operations"},"minimized": false,"output_types": [],@@ -1711,7 +1430,7 @@{"allows_loop": false,"cache": true,- "display_name": "Message",+ "display_name": "Table","group_outputs": false,"hidden": null,"loop_types": null,@@ -1733,7 +1452,7 @@"value": "72c3d17c-2dac-4a73-b48a-6518473d7830"},"_frontend_node_folder_id": {- "value": "f1efb4f8-3ca5-4e89-8685-0e8b2ba1187f"+ "value": "f3f8bf74-7a73-4ab3-9769-0d8a4ebbaec9"},"_type": "Component","append_update_data": {@@ -1828,7 +1547,7 @@"show": true,"title_case": false,"type": "code",- "value": "\"\"\"Unified Operations component.\n\nBrings together the previously separate JSON, Table, and Text operation\ncomponents into a single component. An \"Input Type\" selector (Text / JSON /\nTable) drives everything: it filters the \"Operation\" picker to the operations\nthat apply to that type, reveals the matching input (Text / JSON / Table) and\nits operation-specific fields, and advertises the appropriate output type.\n\nThe three original components (JSON Operations, Table Operations, Text\nOperations) remain available as legacy components for backward compatibility\nwith existing flows.\n\"\"\"\n\nimport ast\nimport contextlib\nimport json\nimport re\nfrom typing import TYPE_CHECKING, Any\n\nimport pandas as pd\nfrom json_repair import repair_json\n\nfrom lfx.custom import Component\nfrom lfx.field_typing import RangeSpec\nfrom lfx.inputs import DictInput, SortableListInput, TabInput\nfrom lfx.io import (\n BoolInput,\n DataFrameInput,\n DataInput,\n DropdownInput,\n IntInput,\n MessageTextInput,\n MultilineInput,\n Output,\n StrInput,\n)\nfrom lfx.log.logger import logger\nfrom lfx.schema import Data\nfrom lfx.schema.dataframe import DataFrame\nfrom lfx.schema.dotdict import dotdict\nfrom lfx.schema.message import Message\n\nif TYPE_CHECKING:\n from collections.abc import Callable\n\n# The \"Input Type\" selector tabs. Each value maps a Langflow data type to the\n# operations, input, and output that belong to it.\nINPUT_TYPES = [\"Text\", \"JSON\", \"Table\"]\n\n# Operations grouped by input type, in display order, each with the icon shown\n# in the Operation picker. This is the single source of truth for the picker;\n# update_build_config swaps the picker's options to the selected type's list.\nOPERATIONS_BY_TYPE: dict[str, list[dict[str, str]]] = {\n \"Text\": [\n {\"name\": \"Word Count\", \"icon\": \"hash\"},\n {\"name\": \"Case Conversion\", \"icon\": \"type\"},\n {\"name\": \"Text Replace\", \"icon\": \"replace\"},\n {\"name\": \"Text Extract\", \"icon\": \"search\"},\n {\"name\": \"Text Head\", \"icon\": \"chevron-left\"},\n {\"name\": \"Text Tail\", \"icon\": \"chevron-right\"},\n {\"name\": \"Text Strip\", \"icon\": \"minus\"},\n {\"name\": \"Text Join\", \"icon\": \"link\"},\n {\"name\": \"Text Clean\", \"icon\": \"sparkles\"},\n {\"name\": \"Text to DataFrame\", \"icon\": \"table\"},\n ],\n \"JSON\": [\n {\"name\": \"Select Keys\", \"icon\": \"lasso-select\"},\n {\"name\": \"Literal Eval\", \"icon\": \"braces\"},\n {\"name\": \"Combine\", \"icon\": \"merge\"},\n {\"name\": \"Append or Update\", \"icon\": \"circle-plus\"},\n {\"name\": \"Remove Keys\", \"icon\": \"eraser\"},\n {\"name\": \"Rename Keys\", \"icon\": \"pencil-line\"},\n {\"name\": \"Path Selection\", \"icon\": \"mouse-pointer\"},\n {\"name\": \"JQ Expression\", \"icon\": \"terminal\"},\n ],\n \"Table\": [\n {\"name\": \"Add Column\", \"icon\": \"plus\"},\n {\"name\": \"Concatenate\", \"icon\": \"combine\"},\n {\"name\": \"Drop Column\", \"icon\": \"minus\"},\n {\"name\": \"Filter\", \"icon\": \"filter\"},\n {\"name\": \"Head\", \"icon\": \"arrow-up\"},\n {\"name\": \"Merge\", \"icon\": \"merge\"},\n {\"name\": \"Rename Column\", \"icon\": \"pencil\"},\n {\"name\": \"Replace Value\", \"icon\": \"replace\"},\n {\"name\": \"Select Columns\", \"icon\": \"columns\"},\n {\"name\": \"Sort\", \"icon\": \"arrow-up-down\"},\n {\"name\": \"Tail\", \"icon\": \"arrow-down\"},\n {\"name\": \"Drop Duplicates\", \"icon\": \"copy-x\"},\n ],\n}\n\n# Operation-name sets derived from the picker, used for dispatch and output\n# routing. Keeping them derived from OPERATIONS_BY_TYPE avoids any drift.\nJSON_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"JSON\"]}\nTABLE_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"Table\"]}\nTEXT_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"Text\"]}\n\n# Each input type maps to its main input field and its default output. \"Text\"\n# normally outputs a Message; \"JSON\" a Data; \"Table\" a DataFrame. A few text\n# operations override this (Word Count -> Data, Text to DataFrame -> DataFrame).\nINPUT_TYPE_TO_MAIN_INPUT = {\"Text\": \"text_input\", \"JSON\": \"data\", \"Table\": \"df\"}\n\n# Case conversions for the Text \"Case Conversion\" operation.\nCASE_CONVERTERS: dict[str, Any] = {\n \"uppercase\": str.upper,\n \"lowercase\": str.lower,\n \"title\": str.title,\n \"capitalize\": str.capitalize,\n \"swapcase\": str.swapcase,\n}\n\n\nclass OperationsComponent(Component):\n display_name = \"Data Operations\"\n description = \"Perform operations on Text, JSON, and Tables from a single component.\"\n documentation: str = \"https://docs.langflow.org/components-processing#operations\"\n icon = \"wand-sparkles\"\n name = \"Operations\"\n metadata = {\n \"keywords\": [\n \"operations\",\n \"data operations\",\n \"json\",\n \"json operations\",\n \"table\",\n \"table operations\",\n \"dataframe\",\n \"dataframe operations\",\n \"text\",\n \"text operations\",\n \"select keys\",\n \"literal eval\",\n \"combine\",\n \"append or update\",\n \"remove keys\",\n \"rename keys\",\n \"path selection\",\n \"jq expression\",\n \"parse json\",\n \"add column\",\n \"concatenate\",\n \"drop column\",\n \"filter\",\n \"head\",\n \"merge\",\n \"rename column\",\n \"replace value\",\n \"select columns\",\n \"sort\",\n \"tail\",\n \"drop duplicates\",\n \"word count\",\n \"case conversion\",\n \"text replace\",\n \"text extract\",\n \"text join\",\n \"text clean\",\n \"text to dataframe\",\n \"data manipulation\",\n \"data transformation\",\n ],\n }\n\n # Operation -> operation-specific input fields to reveal when selected.\n OPERATION_FIELDS: dict[str, list[str]] = {\n # JSON\n \"Select Keys\": [\"select_keys_input\"],\n \"Literal Eval\": [],\n \"Combine\": [],\n \"Append or Update\": [\"append_update_data\"],\n \"Remove Keys\": [\"remove_keys_input\"],\n \"Rename Keys\": [\"rename_keys_input\"],\n \"Path Selection\": [\"mapped_json_display\", \"selected_key\"],\n \"JQ Expression\": [\"query\"],\n # Table\n \"Add Column\": [\"new_column_name\", \"new_column_value\"],\n \"Concatenate\": [],\n \"Drop Column\": [\"column_name\"],\n \"Filter\": [\"column_name\", \"filter_value\", \"filter_operator\"],\n \"Head\": [\"num_rows\"],\n \"Merge\": [\"left_dataframe\", \"right_dataframe\", \"merge_on_column\", \"merge_how\"],\n \"Rename Column\": [\"column_name\", \"new_column_name\"],\n \"Replace Value\": [\"column_name\", \"replace_value\", \"replacement_value\"],\n \"Select Columns\": [\"columns_to_select\"],\n \"Sort\": [\"column_name\", \"ascending\"],\n \"Tail\": [\"num_rows\"],\n \"Drop Duplicates\": [\"column_name\"],\n # Text\n \"Word Count\": [\"count_words\", \"count_characters\", \"count_lines\"],\n \"Case Conversion\": [\"case_type\"],\n \"Text Replace\": [\"search_pattern\", \"replacement_text\", \"use_regex\"],\n \"Text Extract\": [\"extract_pattern\", \"max_matches\"],\n \"Text Head\": [\"head_characters\"],\n \"Text Tail\": [\"tail_characters\"],\n \"Text Strip\": [\"strip_mode\", \"strip_characters\"],\n \"Text Join\": [\"text_input_2\"],\n \"Text Clean\": [\"remove_extra_spaces\", \"remove_special_chars\", \"remove_empty_lines\"],\n \"Text to DataFrame\": [\"table_separator\", \"has_header\"],\n }\n\n # The three main inputs (one per data type). They are never treated as\n # operation-specific fields; the input-type selector toggles them.\n MAIN_INPUTS = (\"text_input\", \"data\", \"df\")\n\n # Every operation-specific field (union of all the lists above), used to\n # hide and reset fields whenever the input type or operation changes.\n ALL_OPERATION_FIELDS: list[str] = [\n # JSON\n \"select_keys_input\",\n \"append_update_data\",\n \"remove_keys_input\",\n \"rename_keys_input\",\n \"mapped_json_display\",\n \"selected_key\",\n \"query\",\n # Table\n \"column_name\",\n \"filter_value\",\n \"filter_operator\",\n \"ascending\",\n \"new_column_name\",\n \"new_column_value\",\n \"columns_to_select\",\n \"num_rows\",\n \"replace_value\",\n \"replacement_value\",\n \"left_dataframe\",\n \"right_dataframe\",\n \"merge_on_column\",\n \"merge_how\",\n # Text\n \"table_separator\",\n \"has_header\",\n \"count_words\",\n \"count_characters\",\n \"count_lines\",\n \"case_type\",\n \"use_regex\",\n \"search_pattern\",\n \"replacement_text\",\n \"extract_pattern\",\n \"max_matches\",\n \"head_characters\",\n \"tail_characters\",\n \"strip_mode\",\n \"strip_characters\",\n \"text_input_2\",\n \"remove_extra_spaces\",\n \"remove_special_chars\",\n \"remove_empty_lines\",\n ]\n\n # Defaults applied to the JSON operation fields when the operation changes,\n # mirroring the JSON Operations component's reset behavior.\n OPERATION_FIELD_DEFAULTS: dict[str, Any] = {\n \"select_keys_input\": [],\n \"append_update_data\": {\"key\": \"value\"},\n \"remove_keys_input\": [],\n \"rename_keys_input\": {\"old_key\": \"new_key\"},\n \"mapped_json_display\": \"\",\n \"selected_key\": None,\n \"query\": \"\",\n }\n\n inputs = [\n # --- Input type selector: drives operations, input, and output ---\n TabInput(\n name=\"input_type\",\n display_name=\"Input Type\",\n options=INPUT_TYPES,\n value=\"Text\",\n info=\"Select the type of input to operate on.\",\n real_time_refresh=True,\n ),\n # --- Main inputs: one per data type, shown contextually ---\n MultilineInput(\n name=\"text_input\",\n display_name=\"Text\",\n info=\"The input text to process.\",\n show=True,\n ),\n DataInput(\n name=\"data\",\n display_name=\"JSON\",\n info=\"The JSON / Data object to operate on.\",\n is_list=True,\n show=False,\n ),\n DataFrameInput(\n name=\"df\",\n display_name=\"Table\",\n info=\"The input Table to operate on. Connect multiple Tables for merge or concatenate operations.\",\n is_list=True,\n show=False,\n ),\n # --- Operation picker (options are filtered by Input Type) ---\n SortableListInput(\n name=\"operation\",\n display_name=\"Operation\",\n placeholder=\"Select Operation\",\n info=\"Select the operation to perform. The matching fields and output appear once you choose one.\",\n options=OPERATIONS_BY_TYPE[\"Text\"],\n real_time_refresh=True,\n limit=1,\n ),\n # --- JSON operation fields ---\n MessageTextInput(\n name=\"select_keys_input\",\n display_name=\"Select Keys\",\n info=\"List of keys to select from the data. Only top-level keys can be selected.\",\n show=False,\n is_list=True,\n value=[],\n ),\n DictInput(\n name=\"append_update_data\",\n display_name=\"Append or Update\",\n info=\"Data to append or update the existing data with. Only top-level keys are checked.\",\n show=False,\n value={\"key\": \"value\"},\n is_list=True,\n ),\n MessageTextInput(\n name=\"remove_keys_input\",\n display_name=\"Remove Keys\",\n info=\"List of keys to remove from the data.\",\n show=False,\n is_list=True,\n value=[],\n ),\n DictInput(\n name=\"rename_keys_input\",\n display_name=\"Rename Keys\",\n info=\"List of keys to rename in the data.\",\n show=False,\n is_list=True,\n value={\"old_key\": \"new_key\"},\n ),\n MultilineInput(\n name=\"mapped_json_display\",\n display_name=\"JSON to Map\",\n info=\"Paste or preview your JSON here to explore its structure and select a path for extraction.\",\n required=False,\n refresh_button=True,\n real_time_refresh=True,\n placeholder=\"Add a JSON example.\",\n show=False,\n ),\n DropdownInput(\n name=\"selected_key\",\n display_name=\"Select Path\",\n options=[],\n required=False,\n dynamic=True,\n show=False,\n value=None,\n ),\n MessageTextInput(\n name=\"query\",\n display_name=\"JQ Expression\",\n info=\"JSON Query to filter the data. Used by Path Selection and JQ Expression operations.\",\n placeholder=\"e.g., .properties.id\",\n show=False,\n ),\n # --- Table operation fields ---\n StrInput(\n name=\"column_name\",\n display_name=\"Column Name\",\n info=\"The column name to use for the operation.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"filter_value\",\n display_name=\"Filter Value\",\n info=\"The value to filter rows by.\",\n dynamic=True,\n show=False,\n ),\n DropdownInput(\n name=\"filter_operator\",\n display_name=\"Filter Operator\",\n options=[\n \"equals\",\n \"not equals\",\n \"contains\",\n \"not contains\",\n \"starts with\",\n \"ends with\",\n \"greater than\",\n \"less than\",\n ],\n value=\"equals\",\n info=\"The operator to apply for filtering rows.\",\n advanced=False,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"ascending\",\n display_name=\"Sort Ascending\",\n info=\"Whether to sort in ascending order.\",\n dynamic=True,\n show=False,\n value=True,\n ),\n StrInput(\n name=\"new_column_name\",\n display_name=\"New Column Name\",\n info=\"The new column name when renaming or adding a column.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"new_column_value\",\n display_name=\"New Column Value\",\n info=\"The value to populate the new column with.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"columns_to_select\",\n display_name=\"Columns to Select\",\n dynamic=True,\n is_list=True,\n show=False,\n ),\n IntInput(\n name=\"num_rows\",\n display_name=\"Number of Rows\",\n info=\"Number of rows to return (for head/tail).\",\n dynamic=True,\n show=False,\n value=5,\n ),\n MessageTextInput(\n name=\"replace_value\",\n display_name=\"Value to Replace\",\n info=\"The value to replace in the column.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"replacement_value\",\n display_name=\"Replacement Value\",\n info=\"The value to replace with.\",\n dynamic=True,\n show=False,\n ),\n DataFrameInput(\n name=\"left_dataframe\",\n display_name=\"Left Table\",\n info=\"The left (primary) Table for merge operations. \"\n \"In a left merge, all rows from this table are preserved.\",\n dynamic=True,\n show=False,\n ),\n DataFrameInput(\n name=\"right_dataframe\",\n display_name=\"Right Table\",\n info=\"The right (secondary) Table for merge operations. \"\n \"In a right merge, all rows from this table are preserved.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"merge_on_column\",\n display_name=\"Merge On Column\",\n info=\"The column name to merge Tables on. Must exist in both Tables.\",\n dynamic=True,\n show=False,\n ),\n DropdownInput(\n name=\"merge_how\",\n display_name=\"Merge Type\",\n options=[\"inner\", \"outer\", \"left\", \"right\"],\n value=\"inner\",\n info=\"Type of merge: inner (intersection), outer (union), left, or right.\",\n dynamic=True,\n show=False,\n ),\n # --- Text operation fields ---\n StrInput(\n name=\"table_separator\",\n display_name=\"Table Separator\",\n info=\"Separator used in the table (default: '|').\",\n value=\"|\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"has_header\",\n display_name=\"Has Header\",\n info=\"Whether the table has a header row.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_words\",\n display_name=\"Count Words\",\n info=\"Include word count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_characters\",\n display_name=\"Count Characters\",\n info=\"Include character count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_lines\",\n display_name=\"Count Lines\",\n info=\"Include line count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n DropdownInput(\n name=\"case_type\",\n display_name=\"Case Type\",\n options=[\"uppercase\", \"lowercase\", \"title\", \"capitalize\", \"swapcase\"],\n value=\"lowercase\",\n info=\"Type of case conversion to apply.\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"use_regex\",\n display_name=\"Use Regex\",\n info=\"Whether to treat search pattern as regex.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"search_pattern\",\n display_name=\"Search Pattern\",\n info=\"Text pattern to search for (supports regex).\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"replacement_text\",\n display_name=\"Replacement Text\",\n info=\"Text to replace the search pattern with.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"extract_pattern\",\n display_name=\"Extract Pattern\",\n info=\"Regex pattern to extract from text.\",\n dynamic=True,\n show=False,\n ),\n IntInput(\n name=\"max_matches\",\n display_name=\"Max Matches\",\n info=\"Maximum number of matches to extract.\",\n value=10,\n dynamic=True,\n show=False,\n ),\n IntInput(\n name=\"head_characters\",\n display_name=\"Characters from Start\",\n info=\"Number of characters to extract from the beginning of text. Must be non-negative.\",\n value=100,\n dynamic=True,\n show=False,\n range_spec=RangeSpec(min=0, max=1000000, step=1, step_type=\"int\"),\n ),\n IntInput(\n name=\"tail_characters\",\n display_name=\"Characters from End\",\n info=\"Number of characters to extract from the end of text. Must be non-negative.\",\n value=100,\n dynamic=True,\n show=False,\n range_spec=RangeSpec(min=0, max=1000000, step=1, step_type=\"int\"),\n ),\n DropdownInput(\n name=\"strip_mode\",\n display_name=\"Strip Mode\",\n options=[\"both\", \"left\", \"right\"],\n value=\"both\",\n info=\"Which sides to strip whitespace from.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"strip_characters\",\n display_name=\"Characters to Strip\",\n info=\"Specific characters to remove (leave empty for whitespace).\",\n value=\"\",\n dynamic=True,\n show=False,\n ),\n MultilineInput(\n name=\"text_input_2\",\n display_name=\"Second Text Input\",\n info=\"Second text to join with the first text.\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_extra_spaces\",\n display_name=\"Remove Extra Spaces\",\n info=\"Remove multiple consecutive spaces.\",\n value=True,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_special_chars\",\n display_name=\"Remove Special Characters\",\n info=\"Remove special characters except alphanumeric and spaces.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_empty_lines\",\n display_name=\"Remove Empty Lines\",\n info=\"Remove empty lines from text.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n ]\n\n # Default output matches the default Input Type (\"Text\" -> Message).\n # update_outputs / update_frontend_node narrow it to the selected type and\n # operation.\n outputs = [Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\")]\n\n # ------------------------------------------------------------------\n # Operation routing helpers\n # ------------------------------------------------------------------\n @staticmethod\n def _extract_operation_name(field_value: Any) -> str:\n \"\"\"Extract the operation name from a SortableListInput value.\"\"\"\n if isinstance(field_value, list) and len(field_value) > 0 and isinstance(field_value[0], dict):\n return field_value[0].get(\"name\", \"\")\n if isinstance(field_value, str):\n return field_value\n return \"\"\n\n def _operation_name(self) -> str:\n \"\"\"Get the currently selected operation name.\"\"\"\n return self._extract_operation_name(getattr(self, \"operation\", []))\n\n @staticmethod\n def _default_output_for_type(input_type: str) -> Output:\n \"\"\"Return the output advertised for an input type when no operation is selected yet.\"\"\"\n if input_type == \"JSON\":\n return Output(display_name=\"JSON\", name=\"data_output\", method=\"as_data\")\n if input_type == \"Table\":\n return Output(display_name=\"Table\", name=\"dataframe_output\", method=\"as_dataframe\")\n return Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\")\n\n # ------------------------------------------------------------------\n # Dynamic UI\n # ------------------------------------------------------------------\n def _reset_operation_fields(self, build_config: dotdict) -> None:\n \"\"\"Hide every operation-specific field and restore its default value.\"\"\"\n for field in self.ALL_OPERATION_FIELDS:\n if field in build_config:\n build_config[field][\"show\"] = False\n if field in self.OPERATION_FIELD_DEFAULTS:\n build_config[field][\"value\"] = self.OPERATION_FIELD_DEFAULTS[field]\n\n def _show_main_input(self, build_config: dotdict, input_type: str, operation: str) -> None:\n \"\"\"Show only the main input that matches the input type; hide the others.\"\"\"\n for inp in self.MAIN_INPUTS:\n if inp in build_config:\n build_config[inp][\"show\"] = False\n build_config[inp][\"required\"] = False\n\n main_input = INPUT_TYPE_TO_MAIN_INPUT.get(input_type)\n if main_input and main_input in build_config:\n build_config[main_input][\"show\"] = True\n build_config[main_input][\"required\"] = True\n # The JSON \"Combine\" operation consumes a list of Data objects.\n if main_input == \"data\":\n build_config[\"data\"][\"is_list\"] = operation == \"Combine\"\n\n def update_build_config(self, build_config: dotdict, field_value: Any, field_name: str | None = None) -> dotdict:\n # Path Selection: refresh the available JSON paths from the pasted JSON.\n if field_name == \"mapped_json_display\":\n try:\n parsed_json = json.loads(field_value)\n keys = self.extract_all_paths(parsed_json)\n build_config[\"selected_key\"][\"options\"] = keys\n build_config[\"selected_key\"][\"show\"] = True\n except (json.JSONDecodeError, TypeError, ValueError) as e:\n logger.error(f\"Error parsing mapped JSON: {e}\")\n build_config[\"selected_key\"][\"show\"] = False\n return build_config\n\n # Input type changed: swap the operation list, clear the selection, and\n # show only the matching input. No operation-specific fields are shown\n # until an operation is picked.\n if field_name == \"input_type\":\n input_type = field_value if field_value in OPERATIONS_BY_TYPE else \"Text\"\n build_config[\"operation\"][\"options\"] = OPERATIONS_BY_TYPE[input_type]\n build_config[\"operation\"][\"value\"] = []\n self._reset_operation_fields(build_config)\n self._show_main_input(build_config, input_type, operation=\"\")\n return build_config\n\n # Operation changed: reset fields, show the input for the current type,\n # then reveal the operation-specific fields.\n if field_name == \"operation\":\n operation = self._extract_operation_name(field_value)\n self._reset_operation_fields(build_config)\n\n input_type = build_config.get(\"input_type\", {}).get(\"value\", \"Text\")\n self._show_main_input(build_config, input_type, operation)\n\n for field in self.OPERATION_FIELDS.get(operation, []):\n if field in build_config:\n build_config[field][\"show\"] = True\n\n return build_config\n\n return build_config\n\n def update_outputs(self, frontend_node: dict, field_name: str, field_value: Any) -> dict:\n \"\"\"Create the output(s) appropriate to the selected input type and operation.\"\"\"\n if field_name == \"input_type\":\n # Switching type clears the operation; advertise the type's default.\n input_type = field_value if field_value in OPERATIONS_BY_TYPE else \"Text\"\n frontend_node[\"outputs\"] = [self._default_output_for_type(input_type)]\n return frontend_node\n\n template = frontend_node.get(\"template\", {})\n input_type = template.get(\"input_type\", {}).get(\"value\", \"Text\")\n\n if field_name == \"operation\":\n operation = self._extract_operation_name(field_value)\n else:\n # Any other refresh (e.g. Path Selection's \"JSON to Map\" field)\n # reaches here on a freshly rebuilt node whose outputs were reset\n # to the class default (Message). Re-derive the output from the\n # saved operation so the refresh doesn't swap the real output type.\n operation = self._extract_operation_name(template.get(\"operation\", {}).get(\"value\", []))\n\n if not operation:\n # No operation selected: fall back to the input type's default output.\n frontend_node[\"outputs\"] = [self._default_output_for_type(input_type)]\n return frontend_node\n\n frontend_node[\"outputs\"] = []\n if operation in JSON_OPERATIONS or operation == \"Word Count\":\n frontend_node[\"outputs\"].append(Output(display_name=\"JSON\", name=\"data_output\", method=\"as_data\"))\n elif operation in TABLE_OPERATIONS or operation == \"Text to DataFrame\":\n frontend_node[\"outputs\"].append(\n Output(display_name=\"Table\", name=\"dataframe_output\", method=\"as_dataframe\")\n )\n elif operation == \"Text Join\":\n frontend_node[\"outputs\"].append(Output(display_name=\"Text\", name=\"text_output\", method=\"as_text\"))\n frontend_node[\"outputs\"].append(Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\"))\n else:\n frontend_node[\"outputs\"].append(Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\"))\n\n return frontend_node\n\n async def update_frontend_node(self, new_frontend_node: dict, current_frontend_node: dict) -> dict:\n \"\"\"Keep the operation options and outputs in sync with the saved input type on load.\"\"\"\n await super().update_frontend_node(new_frontend_node, current_frontend_node)\n\n template = new_frontend_node.get(\"template\", {})\n input_type = template.get(\"input_type\", {}).get(\"value\", \"Text\")\n if input_type not in OPERATIONS_BY_TYPE:\n input_type = \"Text\"\n\n # Filter the operation picker to the saved input type.\n if \"operation\" in template:\n template[\"operation\"][\"options\"] = OPERATIONS_BY_TYPE[input_type]\n\n # Re-derive the outputs from the saved input type + operation.\n operation_value = template.get(\"operation\", {}).get(\"value\", [])\n if self._extract_operation_name(operation_value):\n self.update_outputs(new_frontend_node, \"operation\", operation_value)\n else:\n self.update_outputs(new_frontend_node, \"input_type\", input_type)\n\n return new_frontend_node\n\n # ==================================================================\n # Output methods (referenced by update_outputs)\n # ==================================================================\n def as_data(self) -> Data:\n \"\"\"JSON-typed output: JSON operations and Word Count.\"\"\"\n operation = self._operation_name()\n if operation in JSON_OPERATIONS:\n handler = self._json_handlers().get(operation)\n if handler:\n try:\n return handler()\n except Exception as e:\n logger.error(f\"Error executing {operation}: {e!s}\")\n raise\n if operation == \"Word Count\":\n return self._word_count_data()\n return Data(data={})\n\n def as_dataframe(self) -> DataFrame:\n \"\"\"Table-typed output: Table operations and Text to DataFrame.\"\"\"\n operation = self._operation_name()\n if operation in TABLE_OPERATIONS:\n return self._run_table_operation(operation)\n if operation == \"Text to DataFrame\":\n return self._text_to_dataframe(getattr(self, \"text_input\", \"\") or \"\")\n return DataFrame(pd.DataFrame())\n\n def as_message(self) -> Message:\n \"\"\"Message-typed output: generic text operations (and Text Join).\"\"\"\n return Message(text=self._format_result_as_text(self._run_text_operation()))\n\n def as_text(self) -> Message:\n \"\"\"Text output for the Text Join operation.\"\"\"\n return self.as_message()\n\n # ==================================================================\n # JSON operations\n # ==================================================================\n @staticmethod\n def extract_all_paths(obj, path=\"\"):\n paths = []\n if isinstance(obj, dict):\n for k, v in obj.items():\n new_path = f\"{path}.{k}\" if path else f\".{k}\"\n paths.append(new_path)\n paths.extend(OperationsComponent.extract_all_paths(v, new_path))\n elif isinstance(obj, list) and obj:\n new_path = f\"{path}[0]\"\n paths.append(new_path)\n paths.extend(OperationsComponent.extract_all_paths(obj[0], new_path))\n return paths\n\n @staticmethod\n def remove_keys_recursive(obj, keys_to_remove):\n if isinstance(obj, dict):\n return {\n k: OperationsComponent.remove_keys_recursive(v, keys_to_remove)\n for k, v in obj.items()\n if k not in keys_to_remove\n }\n if isinstance(obj, list):\n return [OperationsComponent.remove_keys_recursive(item, keys_to_remove) for item in obj]\n return obj\n\n @staticmethod\n def rename_keys_recursive(obj, rename_map):\n if isinstance(obj, dict):\n return {\n rename_map.get(k, k): OperationsComponent.rename_keys_recursive(v, rename_map) for k, v in obj.items()\n }\n if isinstance(obj, list):\n return [OperationsComponent.rename_keys_recursive(item, rename_map) for item in obj]\n return obj\n\n def _json_handlers(self) -> \"dict[str, Callable[[], Data]]\":\n return {\n \"Select Keys\": self.select_keys,\n \"Literal Eval\": self.evaluate_data,\n \"Combine\": self.combine_data,\n \"Append or Update\": self.append_update,\n \"Remove Keys\": self.remove_keys,\n \"Rename Keys\": self.rename_keys,\n \"Path Selection\": self.json_path,\n \"JQ Expression\": self.json_query,\n }\n\n def get_data_dict(self) -> dict:\n \"\"\"Extract data dictionary from Data object.\"\"\"\n data = self.data[0] if isinstance(self.data, list) and len(self.data) == 1 else self.data\n return data.model_dump()\n\n def get_normalized_data(self) -> dict:\n \"\"\"Get normalized data dictionary, handling the 'data' key if present.\"\"\"\n data_dict = self.get_data_dict()\n return data_dict.get(\"data\", data_dict)\n\n def data_is_list(self) -> bool:\n \"\"\"Check if data contains multiple items.\"\"\"\n return isinstance(self.data, list) and len(self.data) > 1\n\n def validate_single_data(self, operation: str) -> None:\n \"\"\"Validate that the operation is being performed on a single data object.\"\"\"\n if self.data_is_list():\n msg = f\"{operation} operation is not supported for multiple data objects.\"\n raise ValueError(msg)\n\n def select_keys(self) -> Data:\n \"\"\"Select specific keys from the data dictionary.\"\"\"\n self.validate_single_data(\"Select Keys\")\n data_dict = self.get_normalized_data()\n filter_criteria: list[str] = self.select_keys_input\n\n if len(filter_criteria) == 1 and filter_criteria[0] == \"data\":\n filtered = data_dict[\"data\"]\n else:\n if not all(key in data_dict for key in filter_criteria):\n msg = f\"Select key not found in data. Available keys: {list(data_dict.keys())}\"\n raise ValueError(msg)\n filtered = {key: value for key, value in data_dict.items() if key in filter_criteria}\n\n return Data(data=filtered)\n\n def remove_keys(self) -> Data:\n \"\"\"Remove specified keys from the data dictionary, recursively.\"\"\"\n self.validate_single_data(\"Remove Keys\")\n data_dict = self.get_normalized_data()\n remove_keys_input: list[str] = self.remove_keys_input\n filtered = OperationsComponent.remove_keys_recursive(data_dict, set(remove_keys_input))\n return Data(data=filtered)\n\n def rename_keys(self) -> Data:\n \"\"\"Rename keys in the data dictionary, recursively.\"\"\"\n self.validate_single_data(\"Rename Keys\")\n data_dict = self.get_normalized_data()\n rename_keys_input: dict[str, str] = self.rename_keys_input\n renamed = OperationsComponent.rename_keys_recursive(data_dict, rename_keys_input)\n return Data(data=renamed)\n\n def recursive_eval(self, data: Any) -> Any:\n \"\"\"Recursively evaluate string values that look like Python literals.\"\"\"\n if isinstance(data, dict):\n return {k: self.recursive_eval(v) for k, v in data.items()}\n if isinstance(data, list):\n return [self.recursive_eval(item) for item in data]\n if isinstance(data, str):\n try:\n if (\n data.strip().startswith((\"{\", \"[\", \"(\", \"'\", '\"'))\n or data.strip().lower() in (\"true\", \"false\", \"none\")\n or data.strip().replace(\".\", \"\").isdigit()\n ):\n return ast.literal_eval(data)\n except (ValueError, SyntaxError, TypeError, MemoryError):\n return data\n else:\n return data\n return data\n\n def evaluate_data(self) -> Data:\n \"\"\"Evaluate string values in the data dictionary.\"\"\"\n self.validate_single_data(\"Literal Eval\")\n logger.info(\"evaluating data\")\n return Data(**self.recursive_eval(self.get_data_dict()))\n\n def combine_data(self) -> Data:\n \"\"\"Combine multiple data objects into one.\"\"\"\n logger.info(\"combining data\")\n if not self.data_is_list():\n return self.data[0] if self.data else Data(data={})\n\n data_dicts = [data.model_dump().get(\"data\", data.model_dump()) for data in self.data]\n combined_data: dict[str, Any] = {}\n\n for data_dict in data_dicts:\n for key, value in data_dict.items():\n if key not in combined_data:\n combined_data[key] = value\n elif isinstance(combined_data[key], list):\n if isinstance(value, list):\n combined_data[key].extend(value)\n else:\n combined_data[key].append(value)\n else:\n combined_data[key] = (\n [combined_data[key], value] if not isinstance(value, list) else [combined_data[key], *value]\n )\n\n return Data(**combined_data)\n\n def append_update(self) -> Data:\n \"\"\"Append or update the data with new key-value pairs.\"\"\"\n self.validate_single_data(\"Append or Update\")\n data_filtered = self.get_normalized_data()\n for key, value in self.append_update_data.items():\n data_filtered[key] = value\n return Data(**data_filtered)\n\n def json_path(self) -> Data:\n \"\"\"Extract a value from the data using the selected JQ path.\"\"\"\n try:\n import jq\n except ImportError:\n msg = \"jq is required for Path Selection. Install with: pip install jq\"\n raise ImportError(msg) from None\n\n try:\n if not self.data or not self.selected_key:\n msg = \"Missing input data or selected key.\"\n raise ValueError(msg)\n input_payload = self.data[0].data if isinstance(self.data, list) else self.data.data\n compiled = jq.compile(self.selected_key)\n result = compiled.input(input_payload).first()\n if isinstance(result, dict):\n return Data(data=result)\n return Data(data={\"result\": result})\n except (ValueError, TypeError, KeyError) as e:\n self.status = f\"Error: {e!s}\"\n self.log(self.status)\n return Data(data={\"error\": str(e)})\n\n def json_query(self) -> Data:\n \"\"\"Run a JQ expression against the data.\"\"\"\n try:\n import jq\n except ImportError:\n msg = \"jq is required for JQ Expression. Install with: pip install jq\"\n raise ImportError(msg) from None\n\n if not self.query or not self.query.strip():\n msg = \"JSON Query is required and cannot be blank.\"\n raise ValueError(msg)\n raw_data = self.get_data_dict()\n try:\n input_str = json.dumps(raw_data)\n repaired = repair_json(input_str)\n data_json = json.loads(repaired)\n jq_input = data_json[\"data\"] if isinstance(data_json, dict) and \"data\" in data_json else data_json\n results = jq.compile(self.query).input(jq_input).all()\n if not results:\n msg = \"No result from JSON query.\"\n raise ValueError(msg)\n result = results[0] if len(results) == 1 else results\n if result is None or result == \"None\":\n msg = \"JSON query returned null/None. Check if the path exists in your data.\"\n raise ValueError(msg)\n if isinstance(result, dict):\n return Data(data=result)\n return Data(data={\"result\": result})\n except (ValueError, TypeError, KeyError, json.JSONDecodeError) as e:\n logger.error(f\"JSON Query failed: {e}\")\n msg = f\"JSON Query error: {e}\"\n raise ValueError(msg) from e\n\n # ==================================================================\n # Table operations\n # ==================================================================\n def _get_primary_dataframe(self) -> DataFrame:\n \"\"\"Get the first DataFrame from input (handles both single and list inputs).\"\"\"\n if isinstance(self.df, list):\n return self.df[0].copy() if self.df else DataFrame()\n return self.df.copy()\n\n def _run_table_operation(self, operation: str) -> DataFrame:\n # Merge and Concatenate use their own inputs, not the primary df.\n if operation == \"Merge\":\n return self.merge_dataframes()\n if operation == \"Concatenate\":\n return self.concatenate_dataframes()\n\n df_copy = self._get_primary_dataframe()\n table_handlers = {\n \"Filter\": self.filter_rows_by_value,\n \"Sort\": self.sort_by_column,\n \"Drop Column\": self.drop_column,\n \"Rename Column\": self.rename_column,\n \"Add Column\": self.add_column,\n \"Select Columns\": self.select_columns,\n \"Head\": self.head,\n \"Tail\": self.tail,\n \"Replace Value\": self.replace_values,\n \"Drop Duplicates\": self.drop_duplicates,\n }\n handler = table_handlers.get(operation)\n if handler is None:\n msg = f\"Unsupported operation: {operation}\"\n logger.error(msg)\n raise ValueError(msg)\n return handler(df_copy)\n\n def filter_rows_by_value(self, df: DataFrame) -> DataFrame:\n column = df[self.column_name]\n filter_value = self.filter_value\n operator = getattr(self, \"filter_operator\", \"equals\")\n\n if operator == \"equals\":\n mask = column == filter_value\n elif operator == \"not equals\":\n mask = column != filter_value\n elif operator == \"contains\":\n mask = column.astype(str).str.contains(str(filter_value), na=False)\n elif operator == \"not contains\":\n mask = ~column.astype(str).str.contains(str(filter_value), na=False)\n elif operator == \"starts with\":\n mask = column.astype(str).str.startswith(str(filter_value), na=False)\n elif operator == \"ends with\":\n mask = column.astype(str).str.endswith(str(filter_value), na=False)\n elif operator == \"greater than\":\n try:\n numeric_value = pd.to_numeric(filter_value)\n mask = column > numeric_value\n except (ValueError, TypeError):\n mask = column.astype(str) > str(filter_value)\n elif operator == \"less than\":\n try:\n numeric_value = pd.to_numeric(filter_value)\n mask = column < numeric_value\n except (ValueError, TypeError):\n mask = column.astype(str) < str(filter_value)\n else:\n mask = column == filter_value\n\n return DataFrame(df[mask])\n\n def sort_by_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.sort_values(by=self.column_name, ascending=self.ascending))\n\n def drop_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.drop(columns=[self.column_name]))\n\n def rename_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.rename(columns={self.column_name: self.new_column_name}))\n\n def add_column(self, df: DataFrame) -> DataFrame:\n df[self.new_column_name] = [self.new_column_value] * len(df)\n return DataFrame(df)\n\n def select_columns(self, df: DataFrame) -> DataFrame:\n columns = [col.strip() for col in self.columns_to_select]\n return DataFrame(df[columns])\n\n def head(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.head(self.num_rows))\n\n def tail(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.tail(self.num_rows))\n\n def replace_values(self, df: DataFrame) -> DataFrame:\n df[self.column_name] = df[self.column_name].replace(self.replace_value, self.replacement_value)\n return DataFrame(df)\n\n def drop_duplicates(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.drop_duplicates(subset=self.column_name))\n\n def concatenate_dataframes(self) -> DataFrame:\n \"\"\"Concatenate multiple DataFrames vertically (stack rows).\"\"\"\n if not isinstance(self.df, list) or len(self.df) == 0:\n return self.df.copy() if self.df is not None else DataFrame()\n\n if len(self.df) == 1:\n return self.df[0].copy()\n\n concatenated = pd.concat(self.df, ignore_index=True)\n return DataFrame(concatenated)\n\n def merge_dataframes(self) -> DataFrame:\n \"\"\"Merge two DataFrames based on a common column (join operation).\"\"\"\n left_df = getattr(self, \"left_dataframe\", None)\n right_df = getattr(self, \"right_dataframe\", None)\n\n if left_df is None:\n return DataFrame()\n if right_df is None:\n return left_df.copy()\n\n df_left = left_df.copy()\n df_right = right_df.copy()\n\n merge_on = getattr(self, \"merge_on_column\", None)\n merge_how = getattr(self, \"merge_how\", \"inner\")\n\n if merge_on:\n if merge_on not in df_left.columns:\n msg = f\"Column '{merge_on}' not found in left DataFrame. Available: {list(df_left.columns)}\"\n raise ValueError(msg)\n if merge_on not in df_right.columns:\n msg = f\"Column '{merge_on}' not found in right DataFrame. Available: {list(df_right.columns)}\"\n raise ValueError(msg)\n merged = df_left.merge(df_right, on=merge_on, how=merge_how, suffixes=(\"\", \"_right\"))\n else:\n merged = df_left.merge(df_right, left_index=True, right_index=True, how=merge_how, suffixes=(\"\", \"_right\"))\n\n cols_to_drop = []\n for col in merged.columns:\n if col.endswith(\"_right\"):\n original_col = col[:-6]\n if original_col in merged.columns:\n merged[original_col] = merged[original_col].combine_first(merged[col])\n cols_to_drop.append(col)\n\n if cols_to_drop:\n merged = merged.drop(columns=cols_to_drop)\n\n return DataFrame(merged)\n\n # ==================================================================\n # Text operations\n # ==================================================================\n def _run_text_operation(self) -> Any:\n \"\"\"Process text based on the selected operation (Message/Text outputs).\"\"\"\n text = getattr(self, \"text_input\", \"\")\n operation = self._operation_name()\n\n # Allow empty text for Text Join (second input may have content).\n if not text and operation != \"Text Join\":\n return None\n\n text_handlers = {\n \"Case Conversion\": self._case_conversion,\n \"Text Replace\": self._text_replace,\n \"Text Extract\": self._text_extract,\n \"Text Head\": self._text_head,\n \"Text Tail\": self._text_tail,\n \"Text Strip\": self._text_strip,\n \"Text Join\": self._text_join,\n \"Text Clean\": self._text_clean,\n }\n handler = text_handlers.get(operation)\n if handler:\n return handler(text)\n return text\n\n def _word_count_data(self) -> Data:\n \"\"\"Word Count operation result as a Data object.\"\"\"\n result = self._word_count(getattr(self, \"text_input\", \"\") or \"\")\n return Data(data=result)\n\n def _word_count(self, text: str) -> dict[str, Any]:\n \"\"\"Count words, characters, and lines in text.\"\"\"\n result: dict[str, Any] = {}\n text_str = str(text) if text else \"\"\n is_empty = not text_str or not text_str.strip()\n\n if getattr(self, \"count_words\", True):\n if is_empty:\n result[\"word_count\"] = 0\n result[\"unique_words\"] = 0\n else:\n words = text_str.split()\n result[\"word_count\"] = len(words)\n result[\"unique_words\"] = len(set(words))\n\n if getattr(self, \"count_characters\", True):\n if is_empty:\n result[\"character_count\"] = 0\n result[\"character_count_no_spaces\"] = 0\n else:\n result[\"character_count\"] = len(text_str)\n result[\"character_count_no_spaces\"] = len(text_str.replace(\" \", \"\"))\n\n if getattr(self, \"count_lines\", True):\n if is_empty:\n result[\"line_count\"] = 0\n result[\"non_empty_lines\"] = 0\n else:\n lines = text_str.split(\"\\n\")\n result[\"line_count\"] = len(lines)\n result[\"non_empty_lines\"] = len([line for line in lines if line.strip()])\n\n return result\n\n def _text_to_dataframe(self, text: str) -> DataFrame:\n \"\"\"Convert markdown-style table text to a DataFrame.\"\"\"\n lines = [line.strip() for line in text.strip().split(\"\\n\") if line.strip()]\n if not lines:\n return DataFrame(pd.DataFrame())\n\n separator = getattr(self, \"table_separator\", \"|\")\n has_header = getattr(self, \"has_header\", True)\n\n rows = self._parse_table_rows(lines, separator)\n if not rows:\n return DataFrame(pd.DataFrame())\n\n df = self._create_dataframe(rows, has_header=has_header)\n self._convert_numeric_columns(df)\n self.log(f\"Converted text to DataFrame: {len(df)} rows, {len(df.columns)} columns\")\n return DataFrame(df)\n\n def _parse_table_rows(self, lines: list[str], separator: str) -> list[list[str]]:\n rows = []\n for line in lines:\n cleaned_line = line.strip(separator)\n cells = [cell.strip() for cell in cleaned_line.split(separator)]\n rows.append(cells)\n return rows\n\n def _create_dataframe(self, rows: list[list[str]], *, has_header: bool) -> pd.DataFrame:\n if has_header and len(rows) > 1:\n header = rows[0]\n data_rows = rows[1:]\n header_col_count = len(header)\n for i, row in enumerate(data_rows):\n row_col_count = len(row)\n if row_col_count != header_col_count:\n msg = (\n f\"Header mismatch: {header_col_count} column(s) in header vs \"\n f\"{row_col_count} column(s) in data row {i + 1}. \"\n \"Please ensure the header has the same number of columns as your data.\"\n )\n raise ValueError(msg)\n return pd.DataFrame(data_rows, columns=header)\n\n max_cols = max(len(row) for row in rows) if rows else 0\n columns = [f\"col_{i}\" for i in range(max_cols)]\n return pd.DataFrame(rows, columns=columns)\n\n def _convert_numeric_columns(self, df: pd.DataFrame) -> None:\n for col in df.columns:\n with contextlib.suppress(ValueError, TypeError):\n df[col] = pd.to_numeric(df[col])\n\n def _case_conversion(self, text: str) -> str:\n case_type = getattr(self, \"case_type\", \"lowercase\")\n converter = CASE_CONVERTERS.get(case_type)\n return converter(text) if converter else text\n\n def _text_replace(self, text: str) -> str:\n search_pattern = getattr(self, \"search_pattern\", \"\")\n if not search_pattern:\n return text\n replacement_text = getattr(self, \"replacement_text\", \"\")\n use_regex = getattr(self, \"use_regex\", False)\n if use_regex:\n try:\n return re.sub(search_pattern, replacement_text, text)\n except re.error as e:\n self.log(f\"Invalid regex pattern: {e}\")\n return text\n return text.replace(search_pattern, replacement_text)\n\n def _text_extract(self, text: str) -> list[str]:\n extract_pattern = getattr(self, \"extract_pattern\", \"\")\n if not extract_pattern:\n return []\n max_matches = getattr(self, \"max_matches\", 10)\n try:\n matches = re.findall(extract_pattern, text)\n except re.error as e:\n msg = f\"Invalid regex pattern '{extract_pattern}': {e}\"\n raise ValueError(msg) from e\n return matches[:max_matches] if max_matches > 0 else matches\n\n def _text_head(self, text: str) -> str:\n head_characters = getattr(self, \"head_characters\", 100)\n if head_characters < 0:\n msg = f\"Characters from Start must be a non-negative integer, got {head_characters}\"\n raise ValueError(msg)\n if head_characters == 0:\n return \"\"\n return text[:head_characters]\n\n def _text_tail(self, text: str) -> str:\n tail_characters = getattr(self, \"tail_characters\", 100)\n if tail_characters < 0:\n msg = f\"Characters from End must be a non-negative integer, got {tail_characters}\"\n raise ValueError(msg)\n if tail_characters == 0:\n return \"\"\n return text[-tail_characters:]\n\n def _text_strip(self, text: str) -> str:\n strip_mode = getattr(self, \"strip_mode\", \"both\")\n strip_characters = getattr(self, \"strip_characters\", \"\")\n text_str = str(text) if text else \"\"\n chars_to_strip = strip_characters if strip_characters else None\n if strip_mode == \"left\":\n return text_str.lstrip(chars_to_strip)\n if strip_mode == \"right\":\n return text_str.rstrip(chars_to_strip)\n return text_str.strip(chars_to_strip)\n\n def _text_join(self, text: str) -> str:\n text_input_2 = getattr(self, \"text_input_2\", \"\")\n text1 = str(text) if text else \"\"\n text2 = str(text_input_2) if text_input_2 else \"\"\n if text1 and text2:\n return f\"{text1}\\n{text2}\"\n return text1 or text2\n\n def _text_clean(self, text: str) -> str:\n result = text\n if getattr(self, \"remove_extra_spaces\", True):\n # Collapse runs of horizontal whitespace but preserve newlines so\n # that remove_empty_lines stays effective when both are enabled.\n result = re.sub(r\"[^\\S\\n]+\", \" \", result)\n if getattr(self, \"remove_special_chars\", False):\n result = re.sub(r\"[^\\w\\s]\", \"\", result)\n if getattr(self, \"remove_empty_lines\", False):\n lines = [line for line in result.split(\"\\n\") if line.strip()]\n result = \"\\n\".join(lines)\n return result\n\n def _format_result_as_text(self, result: Any) -> str:\n if result is None:\n return \"\"\n if isinstance(result, list):\n return \"\\n\".join(str(item) for item in result)\n return str(result)\n"+ "value": "\"\"\"Unified Operations component.\n\nBrings together the previously separate JSON, Table, and Text operation\ncomponents into a single component. An \"Input Type\" selector (Text / JSON /\nTable) drives everything: it filters the \"Operation\" picker to the operations\nthat apply to that type, reveals the matching input (Text / JSON / Table) and\nits operation-specific fields, and advertises the appropriate output type.\n\nThe three original components (JSON Operations, Table Operations, Text\nOperations) remain available as legacy components for backward compatibility\nwith existing flows.\n\"\"\"\n\nimport ast\nimport contextlib\nimport json\nimport re\nfrom typing import TYPE_CHECKING, Any\n\nimport pandas as pd\nfrom json_repair import repair_json\n\nfrom lfx.custom import Component\nfrom lfx.field_typing import RangeSpec\nfrom lfx.inputs import DictInput, SortableListInput, TabInput\nfrom lfx.io import (\n BoolInput,\n DataFrameInput,\n DataInput,\n DropdownInput,\n IntInput,\n MessageTextInput,\n MultilineInput,\n Output,\n StrInput,\n)\nfrom lfx.log.logger import logger\nfrom lfx.schema import Data\nfrom lfx.schema.dataframe import DataFrame\nfrom lfx.schema.dotdict import dotdict\nfrom lfx.schema.message import Message\nfrom lfx.utils.jq_security import validate_jq_program\n\nif TYPE_CHECKING:\n from collections.abc import Callable\n\n# The \"Input Type\" selector tabs. Each value maps a Langflow data type to the\n# operations, input, and output that belong to it.\nINPUT_TYPES = [\"Text\", \"JSON\", \"Table\"]\n\n# Operations grouped by input type, in display order, each with the icon shown\n# in the Operation picker. This is the single source of truth for the picker;\n# update_build_config swaps the picker's options to the selected type's list.\nOPERATIONS_BY_TYPE: dict[str, list[dict[str, str]]] = {\n \"Text\": [\n {\"name\": \"Word Count\", \"icon\": \"hash\"},\n {\"name\": \"Case Conversion\", \"icon\": \"type\"},\n {\"name\": \"Text Replace\", \"icon\": \"replace\"},\n {\"name\": \"Text Extract\", \"icon\": \"search\"},\n {\"name\": \"Text Head\", \"icon\": \"chevron-left\"},\n {\"name\": \"Text Tail\", \"icon\": \"chevron-right\"},\n {\"name\": \"Text Strip\", \"icon\": \"minus\"},\n {\"name\": \"Text Join\", \"icon\": \"link\"},\n {\"name\": \"Text Clean\", \"icon\": \"sparkles\"},\n {\"name\": \"Text to DataFrame\", \"icon\": \"table\"},\n ],\n \"JSON\": [\n {\"name\": \"Select Keys\", \"icon\": \"lasso-select\"},\n {\"name\": \"Literal Eval\", \"icon\": \"braces\"},\n {\"name\": \"Combine\", \"icon\": \"merge\"},\n {\"name\": \"Append or Update\", \"icon\": \"circle-plus\"},\n {\"name\": \"Remove Keys\", \"icon\": \"eraser\"},\n {\"name\": \"Rename Keys\", \"icon\": \"pencil-line\"},\n {\"name\": \"Path Selection\", \"icon\": \"mouse-pointer\"},\n {\"name\": \"JQ Expression\", \"icon\": \"terminal\"},\n ],\n \"Table\": [\n {\"name\": \"Add Column\", \"icon\": \"plus\"},\n {\"name\": \"Concatenate\", \"icon\": \"combine\"},\n {\"name\": \"Drop Column\", \"icon\": \"minus\"},\n {\"name\": \"Filter\", \"icon\": \"filter\"},\n {\"name\": \"Head\", \"icon\": \"arrow-up\"},\n {\"name\": \"Merge\", \"icon\": \"merge\"},\n {\"name\": \"Rename Column\", \"icon\": \"pencil\"},\n {\"name\": \"Replace Value\", \"icon\": \"replace\"},\n {\"name\": \"Select Columns\", \"icon\": \"columns\"},\n {\"name\": \"Sort\", \"icon\": \"arrow-up-down\"},\n {\"name\": \"Tail\", \"icon\": \"arrow-down\"},\n {\"name\": \"Drop Duplicates\", \"icon\": \"copy-x\"},\n ],\n}\n\n# Operation-name sets derived from the picker, used for dispatch and output\n# routing. Keeping them derived from OPERATIONS_BY_TYPE avoids any drift.\nJSON_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"JSON\"]}\nTABLE_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"Table\"]}\nTEXT_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"Text\"]}\n\n# Each input type maps to its main input field and its default output. \"Text\"\n# normally outputs a Message; \"JSON\" a Data; \"Table\" a DataFrame. A few text\n# operations override this (Word Count -> Data, Text to DataFrame -> DataFrame).\nINPUT_TYPE_TO_MAIN_INPUT = {\"Text\": \"text_input\", \"JSON\": \"data\", \"Table\": \"df\"}\n\n# Case conversions for the Text \"Case Conversion\" operation.\nCASE_CONVERTERS: dict[str, Any] = {\n \"uppercase\": str.upper,\n \"lowercase\": str.lower,\n \"title\": str.title,\n \"capitalize\": str.capitalize,\n \"swapcase\": str.swapcase,\n}\n\n\nclass OperationsComponent(Component):\n display_name = \"Data Operations\"\n description = \"Perform operations on Text, JSON, and Tables from a single component.\"\n documentation: str = \"https://docs.langflow.org/components-processing#operations\"\n icon = \"wand-sparkles\"\n name = \"Operations\"\n metadata = {\n \"keywords\": [\n \"operations\",\n \"data operations\",\n \"json\",\n \"json operations\",\n \"table\",\n \"table operations\",\n \"dataframe\",\n \"dataframe operations\",\n \"text\",\n \"text operations\",\n \"select keys\",\n \"literal eval\",\n \"combine\",\n \"append or update\",\n \"remove keys\",\n \"rename keys\",\n \"path selection\",\n \"jq expression\",\n \"parse json\",\n \"add column\",\n \"concatenate\",\n \"drop column\",\n \"filter\",\n \"head\",\n \"merge\",\n \"rename column\",\n \"replace value\",\n \"select columns\",\n \"sort\",\n \"tail\",\n \"drop duplicates\",\n \"word count\",\n \"case conversion\",\n \"text replace\",\n \"text extract\",\n \"text join\",\n \"text clean\",\n \"text to dataframe\",\n \"data manipulation\",\n \"data transformation\",\n ],\n }\n\n # Operation -> operation-specific input fields to reveal when selected.\n OPERATION_FIELDS: dict[str, list[str]] = {\n # JSON\n \"Select Keys\": [\"select_keys_input\"],\n \"Literal Eval\": [],\n \"Combine\": [],\n \"Append or Update\": [\"append_update_data\"],\n \"Remove Keys\": [\"remove_keys_input\"],\n \"Rename Keys\": [\"rename_keys_input\"],\n \"Path Selection\": [\"mapped_json_display\", \"selected_key\"],\n \"JQ Expression\": [\"query\"],\n # Table\n \"Add Column\": [\"new_column_name\", \"new_column_value\"],\n \"Concatenate\": [],\n \"Drop Column\": [\"column_name\"],\n \"Filter\": [\"column_name\", \"filter_value\", \"filter_operator\"],\n \"Head\": [\"num_rows\"],\n \"Merge\": [\"left_dataframe\", \"right_dataframe\", \"merge_on_column\", \"merge_how\"],\n \"Rename Column\": [\"column_name\", \"new_column_name\"],\n \"Replace Value\": [\"column_name\", \"replace_value\", \"replacement_value\"],\n \"Select Columns\": [\"columns_to_select\"],\n \"Sort\": [\"column_name\", \"ascending\"],\n \"Tail\": [\"num_rows\"],\n \"Drop Duplicates\": [\"column_name\"],\n # Text\n \"Word Count\": [\"count_words\", \"count_characters\", \"count_lines\"],\n \"Case Conversion\": [\"case_type\"],\n \"Text Replace\": [\"search_pattern\", \"replacement_text\", \"use_regex\"],\n \"Text Extract\": [\"extract_pattern\", \"max_matches\"],\n \"Text Head\": [\"head_characters\"],\n \"Text Tail\": [\"tail_characters\"],\n \"Text Strip\": [\"strip_mode\", \"strip_characters\"],\n \"Text Join\": [\"text_input_2\"],\n \"Text Clean\": [\"remove_extra_spaces\", \"remove_special_chars\", \"remove_empty_lines\"],\n \"Text to DataFrame\": [\"table_separator\", \"has_header\"],\n }\n\n # The three main inputs (one per data type). They are never treated as\n # operation-specific fields; the input-type selector toggles them.\n MAIN_INPUTS = (\"text_input\", \"data\", \"df\")\n\n # Every operation-specific field (union of all the lists above), used to\n # hide and reset fields whenever the input type or operation changes.\n ALL_OPERATION_FIELDS: list[str] = [\n # JSON\n \"select_keys_input\",\n \"append_update_data\",\n \"remove_keys_input\",\n \"rename_keys_input\",\n \"mapped_json_display\",\n \"selected_key\",\n \"query\",\n # Table\n \"column_name\",\n \"filter_value\",\n \"filter_operator\",\n \"ascending\",\n \"new_column_name\",\n \"new_column_value\",\n \"columns_to_select\",\n \"num_rows\",\n \"replace_value\",\n \"replacement_value\",\n \"left_dataframe\",\n \"right_dataframe\",\n \"merge_on_column\",\n \"merge_how\",\n # Text\n \"table_separator\",\n \"has_header\",\n \"count_words\",\n \"count_characters\",\n \"count_lines\",\n \"case_type\",\n \"use_regex\",\n \"search_pattern\",\n \"replacement_text\",\n \"extract_pattern\",\n \"max_matches\",\n \"head_characters\",\n \"tail_characters\",\n \"strip_mode\",\n \"strip_characters\",\n \"text_input_2\",\n \"remove_extra_spaces\",\n \"remove_special_chars\",\n \"remove_empty_lines\",\n ]\n\n # Defaults applied to the JSON operation fields when the operation changes,\n # mirroring the JSON Operations component's reset behavior.\n OPERATION_FIELD_DEFAULTS: dict[str, Any] = {\n \"select_keys_input\": [],\n \"append_update_data\": {\"key\": \"value\"},\n \"remove_keys_input\": [],\n \"rename_keys_input\": {\"old_key\": \"new_key\"},\n \"mapped_json_display\": \"\",\n \"selected_key\": None,\n \"query\": \"\",\n }\n\n inputs = [\n # --- Input type selector: drives operations, input, and output ---\n TabInput(\n name=\"input_type\",\n display_name=\"Input Type\",\n options=INPUT_TYPES,\n value=\"Text\",\n info=\"Select the type of input to operate on.\",\n real_time_refresh=True,\n ),\n # --- Main inputs: one per data type, shown contextually ---\n MultilineInput(\n name=\"text_input\",\n display_name=\"Text\",\n info=\"The input text to process.\",\n show=True,\n ),\n DataInput(\n name=\"data\",\n display_name=\"JSON\",\n info=\"The JSON / Data object to operate on.\",\n is_list=True,\n show=False,\n ),\n DataFrameInput(\n name=\"df\",\n display_name=\"Table\",\n info=\"The input Table to operate on. Connect multiple Tables for merge or concatenate operations.\",\n is_list=True,\n show=False,\n ),\n # --- Operation picker (options are filtered by Input Type) ---\n SortableListInput(\n name=\"operation\",\n display_name=\"Operation\",\n placeholder=\"Select Operation\",\n info=\"Select the operation to perform. The matching fields and output appear once you choose one.\",\n options=OPERATIONS_BY_TYPE[\"Text\"],\n real_time_refresh=True,\n limit=1,\n ),\n # --- JSON operation fields ---\n MessageTextInput(\n name=\"select_keys_input\",\n display_name=\"Select Keys\",\n info=\"List of keys to select from the data. Only top-level keys can be selected.\",\n show=False,\n is_list=True,\n value=[],\n ),\n DictInput(\n name=\"append_update_data\",\n display_name=\"Append or Update\",\n info=\"Data to append or update the existing data with. Only top-level keys are checked.\",\n show=False,\n value={\"key\": \"value\"},\n is_list=True,\n ),\n MessageTextInput(\n name=\"remove_keys_input\",\n display_name=\"Remove Keys\",\n info=\"List of keys to remove from the data.\",\n show=False,\n is_list=True,\n value=[],\n ),\n DictInput(\n name=\"rename_keys_input\",\n display_name=\"Rename Keys\",\n info=\"List of keys to rename in the data.\",\n show=False,\n is_list=True,\n value={\"old_key\": \"new_key\"},\n ),\n MultilineInput(\n name=\"mapped_json_display\",\n display_name=\"JSON to Map\",\n info=\"Paste or preview your JSON here to explore its structure and select a path for extraction.\",\n required=False,\n refresh_button=True,\n real_time_refresh=True,\n placeholder=\"Add a JSON example.\",\n show=False,\n ),\n DropdownInput(\n name=\"selected_key\",\n display_name=\"Select Path\",\n options=[],\n required=False,\n dynamic=True,\n show=False,\n value=None,\n ),\n MessageTextInput(\n name=\"query\",\n display_name=\"JQ Expression\",\n info=\"JSON Query to filter the data. Used by Path Selection and JQ Expression operations.\",\n placeholder=\"e.g., .properties.id\",\n show=False,\n ),\n # --- Table operation fields ---\n StrInput(\n name=\"column_name\",\n display_name=\"Column Name\",\n info=\"The column name to use for the operation.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"filter_value\",\n display_name=\"Filter Value\",\n info=\"The value to filter rows by.\",\n dynamic=True,\n show=False,\n ),\n DropdownInput(\n name=\"filter_operator\",\n display_name=\"Filter Operator\",\n options=[\n \"equals\",\n \"not equals\",\n \"contains\",\n \"not contains\",\n \"starts with\",\n \"ends with\",\n \"greater than\",\n \"less than\",\n ],\n value=\"equals\",\n info=\"The operator to apply for filtering rows.\",\n advanced=False,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"ascending\",\n display_name=\"Sort Ascending\",\n info=\"Whether to sort in ascending order.\",\n dynamic=True,\n show=False,\n value=True,\n ),\n StrInput(\n name=\"new_column_name\",\n display_name=\"New Column Name\",\n info=\"The new column name when renaming or adding a column.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"new_column_value\",\n display_name=\"New Column Value\",\n info=\"The value to populate the new column with.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"columns_to_select\",\n display_name=\"Columns to Select\",\n dynamic=True,\n is_list=True,\n show=False,\n ),\n IntInput(\n name=\"num_rows\",\n display_name=\"Number of Rows\",\n info=\"Number of rows to return (for head/tail).\",\n dynamic=True,\n show=False,\n value=5,\n ),\n MessageTextInput(\n name=\"replace_value\",\n display_name=\"Value to Replace\",\n info=\"The value to replace in the column.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"replacement_value\",\n display_name=\"Replacement Value\",\n info=\"The value to replace with.\",\n dynamic=True,\n show=False,\n ),\n DataFrameInput(\n name=\"left_dataframe\",\n display_name=\"Left Table\",\n info=\"The left (primary) Table for merge operations. \"\n \"In a left merge, all rows from this table are preserved.\",\n dynamic=True,\n show=False,\n ),\n DataFrameInput(\n name=\"right_dataframe\",\n display_name=\"Right Table\",\n info=\"The right (secondary) Table for merge operations. \"\n \"In a right merge, all rows from this table are preserved.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"merge_on_column\",\n display_name=\"Merge On Column\",\n info=\"The column name to merge Tables on. Must exist in both Tables.\",\n dynamic=True,\n show=False,\n ),\n DropdownInput(\n name=\"merge_how\",\n display_name=\"Merge Type\",\n options=[\"inner\", \"outer\", \"left\", \"right\"],\n value=\"inner\",\n info=\"Type of merge: inner (intersection), outer (union), left, or right.\",\n dynamic=True,\n show=False,\n ),\n # --- Text operation fields ---\n StrInput(\n name=\"table_separator\",\n display_name=\"Table Separator\",\n info=\"Separator used in the table (default: '|').\",\n value=\"|\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"has_header\",\n display_name=\"Has Header\",\n info=\"Whether the table has a header row.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_words\",\n display_name=\"Count Words\",\n info=\"Include word count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_characters\",\n display_name=\"Count Characters\",\n info=\"Include character count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_lines\",\n display_name=\"Count Lines\",\n info=\"Include line count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n DropdownInput(\n name=\"case_type\",\n display_name=\"Case Type\",\n options=[\"uppercase\", \"lowercase\", \"title\", \"capitalize\", \"swapcase\"],\n value=\"lowercase\",\n info=\"Type of case conversion to apply.\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"use_regex\",\n display_name=\"Use Regex\",\n info=\"Whether to treat search pattern as regex.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"search_pattern\",\n display_name=\"Search Pattern\",\n info=\"Text pattern to search for (supports regex).\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"replacement_text\",\n display_name=\"Replacement Text\",\n info=\"Text to replace the search pattern with.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"extract_pattern\",\n display_name=\"Extract Pattern\",\n info=\"Regex pattern to extract from text.\",\n dynamic=True,\n show=False,\n ),\n IntInput(\n name=\"max_matches\",\n display_name=\"Max Matches\",\n info=\"Maximum number of matches to extract.\",\n value=10,\n dynamic=True,\n show=False,\n ),\n IntInput(\n name=\"head_characters\",\n display_name=\"Characters from Start\",\n info=\"Number of characters to extract from the beginning of text. Must be non-negative.\",\n value=100,\n dynamic=True,\n show=False,\n range_spec=RangeSpec(min=0, max=1000000, step=1, step_type=\"int\"),\n ),\n IntInput(\n name=\"tail_characters\",\n display_name=\"Characters from End\",\n info=\"Number of characters to extract from the end of text. Must be non-negative.\",\n value=100,\n dynamic=True,\n show=False,\n range_spec=RangeSpec(min=0, max=1000000, step=1, step_type=\"int\"),\n ),\n DropdownInput(\n name=\"strip_mode\",\n display_name=\"Strip Mode\",\n options=[\"both\", \"left\", \"right\"],\n value=\"both\",\n info=\"Which sides to strip whitespace from.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"strip_characters\",\n display_name=\"Characters to Strip\",\n info=\"Specific characters to remove (leave empty for whitespace).\",\n value=\"\",\n dynamic=True,\n show=False,\n ),\n MultilineInput(\n name=\"text_input_2\",\n display_name=\"Second Text Input\",\n info=\"Second text to join with the first text.\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_extra_spaces\",\n display_name=\"Remove Extra Spaces\",\n info=\"Remove multiple consecutive spaces.\",\n value=True,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_special_chars\",\n display_name=\"Remove Special Characters\",\n info=\"Remove special characters except alphanumeric and spaces.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_empty_lines\",\n display_name=\"Remove Empty Lines\",\n info=\"Remove empty lines from text.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n ]\n\n # Default output matches the default Input Type (\"Text\" -> Message).\n # update_outputs / update_frontend_node narrow it to the selected type and\n # operation.\n outputs = [Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\")]\n\n # ------------------------------------------------------------------\n # Operation routing helpers\n # ------------------------------------------------------------------\n @staticmethod\n def _extract_operation_name(field_value: Any) -> str:\n \"\"\"Extract the operation name from a SortableListInput value.\"\"\"\n if isinstance(field_value, list) and len(field_value) > 0 and isinstance(field_value[0], dict):\n return field_value[0].get(\"name\", \"\")\n if isinstance(field_value, str):\n return field_value\n return \"\"\n\n def _operation_name(self) -> str:\n \"\"\"Get the currently selected operation name.\"\"\"\n return self._extract_operation_name(getattr(self, \"operation\", []))\n\n @staticmethod\n def _default_output_for_type(input_type: str) -> Output:\n \"\"\"Return the output advertised for an input type when no operation is selected yet.\"\"\"\n if input_type == \"JSON\":\n return Output(display_name=\"JSON\", name=\"data_output\", method=\"as_data\")\n if input_type == \"Table\":\n return Output(display_name=\"Table\", name=\"dataframe_output\", method=\"as_dataframe\")\n return Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\")\n\n # ------------------------------------------------------------------\n # Dynamic UI\n # ------------------------------------------------------------------\n def _reset_operation_fields(self, build_config: dotdict) -> None:\n \"\"\"Hide every operation-specific field and restore its default value.\"\"\"\n for field in self.ALL_OPERATION_FIELDS:\n if field in build_config:\n build_config[field][\"show\"] = False\n if field in self.OPERATION_FIELD_DEFAULTS:\n build_config[field][\"value\"] = self.OPERATION_FIELD_DEFAULTS[field]\n\n def _show_main_input(self, build_config: dotdict, input_type: str, operation: str) -> None:\n \"\"\"Show only the main input that matches the input type; hide the others.\"\"\"\n for inp in self.MAIN_INPUTS:\n if inp in build_config:\n build_config[inp][\"show\"] = False\n build_config[inp][\"required\"] = False\n\n main_input = INPUT_TYPE_TO_MAIN_INPUT.get(input_type)\n if main_input and main_input in build_config:\n build_config[main_input][\"show\"] = True\n build_config[main_input][\"required\"] = True\n # The JSON \"Combine\" operation consumes a list of Data objects.\n if main_input == \"data\":\n build_config[\"data\"][\"is_list\"] = operation == \"Combine\"\n\n def update_build_config(self, build_config: dotdict, field_value: Any, field_name: str | None = None) -> dotdict:\n # Path Selection: refresh the available JSON paths from the pasted JSON.\n if field_name == \"mapped_json_display\":\n try:\n parsed_json = json.loads(field_value)\n keys = self.extract_all_paths(parsed_json)\n build_config[\"selected_key\"][\"options\"] = keys\n build_config[\"selected_key\"][\"show\"] = True\n except (json.JSONDecodeError, TypeError, ValueError) as e:\n logger.error(f\"Error parsing mapped JSON: {e}\")\n build_config[\"selected_key\"][\"show\"] = False\n return build_config\n\n # Input type changed: swap the operation list, clear the selection, and\n # show only the matching input. No operation-specific fields are shown\n # until an operation is picked.\n if field_name == \"input_type\":\n input_type = field_value if field_value in OPERATIONS_BY_TYPE else \"Text\"\n build_config[\"operation\"][\"options\"] = OPERATIONS_BY_TYPE[input_type]\n build_config[\"operation\"][\"value\"] = []\n self._reset_operation_fields(build_config)\n self._show_main_input(build_config, input_type, operation=\"\")\n return build_config\n\n # Operation changed: reset fields, show the input for the current type,\n # then reveal the operation-specific fields.\n if field_name == \"operation\":\n operation = self._extract_operation_name(field_value)\n self._reset_operation_fields(build_config)\n\n input_type = build_config.get(\"input_type\", {}).get(\"value\", \"Text\")\n self._show_main_input(build_config, input_type, operation)\n\n for field in self.OPERATION_FIELDS.get(operation, []):\n if field in build_config:\n build_config[field][\"show\"] = True\n\n return build_config\n\n return build_config\n\n def update_outputs(self, frontend_node: dict, field_name: str, field_value: Any) -> dict:\n \"\"\"Create the output(s) appropriate to the selected input type and operation.\"\"\"\n if field_name == \"input_type\":\n # Switching type clears the operation; advertise the type's default.\n input_type = field_value if field_value in OPERATIONS_BY_TYPE else \"Text\"\n frontend_node[\"outputs\"] = [self._default_output_for_type(input_type)]\n return frontend_node\n\n template = frontend_node.get(\"template\", {})\n input_type = template.get(\"input_type\", {}).get(\"value\", \"Text\")\n\n if field_name == \"operation\":\n operation = self._extract_operation_name(field_value)\n else:\n # Any other refresh (e.g. Path Selection's \"JSON to Map\" field)\n # reaches here on a freshly rebuilt node whose outputs were reset\n # to the class default (Message). Re-derive the output from the\n # saved operation so the refresh doesn't swap the real output type.\n operation = self._extract_operation_name(template.get(\"operation\", {}).get(\"value\", []))\n\n if not operation:\n # No operation selected: fall back to the input type's default output.\n frontend_node[\"outputs\"] = [self._default_output_for_type(input_type)]\n return frontend_node\n\n frontend_node[\"outputs\"] = []\n if operation in JSON_OPERATIONS or operation == \"Word Count\":\n frontend_node[\"outputs\"].append(Output(display_name=\"JSON\", name=\"data_output\", method=\"as_data\"))\n elif operation in TABLE_OPERATIONS or operation == \"Text to DataFrame\":\n frontend_node[\"outputs\"].append(\n Output(display_name=\"Table\", name=\"dataframe_output\", method=\"as_dataframe\")\n )\n elif operation == \"Text Join\":\n frontend_node[\"outputs\"].append(Output(display_name=\"Text\", name=\"text_output\", method=\"as_text\"))\n frontend_node[\"outputs\"].append(Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\"))\n else:\n frontend_node[\"outputs\"].append(Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\"))\n\n return frontend_node\n\n async def update_frontend_node(self, new_frontend_node: dict, current_frontend_node: dict) -> dict:\n \"\"\"Keep the operation options and outputs in sync with the saved input type on load.\"\"\"\n await super().update_frontend_node(new_frontend_node, current_frontend_node)\n\n template = new_frontend_node.get(\"template\", {})\n input_type = template.get(\"input_type\", {}).get(\"value\", \"Text\")\n if input_type not in OPERATIONS_BY_TYPE:\n input_type = \"Text\"\n\n # Filter the operation picker to the saved input type.\n if \"operation\" in template:\n template[\"operation\"][\"options\"] = OPERATIONS_BY_TYPE[input_type]\n\n # Re-derive the outputs from the saved input type + operation.\n operation_value = template.get(\"operation\", {}).get(\"value\", [])\n if self._extract_operation_name(operation_value):\n self.update_outputs(new_frontend_node, \"operation\", operation_value)\n else:\n self.update_outputs(new_frontend_node, \"input_type\", input_type)\n\n return new_frontend_node\n\n # ==================================================================\n # Output methods (referenced by update_outputs)\n # ==================================================================\n def as_data(self) -> Data:\n \"\"\"JSON-typed output: JSON operations and Word Count.\"\"\"\n operation = self._operation_name()\n if operation in JSON_OPERATIONS:\n handler = self._json_handlers().get(operation)\n if handler:\n try:\n return handler()\n except Exception as e:\n logger.error(f\"Error executing {operation}: {e!s}\")\n raise\n if operation == \"Word Count\":\n return self._word_count_data()\n return Data(data={})\n\n def as_dataframe(self) -> DataFrame:\n \"\"\"Table-typed output: Table operations and Text to DataFrame.\"\"\"\n operation = self._operation_name()\n if operation in TABLE_OPERATIONS:\n return self._run_table_operation(operation)\n if operation == \"Text to DataFrame\":\n return self._text_to_dataframe(getattr(self, \"text_input\", \"\") or \"\")\n return DataFrame(pd.DataFrame())\n\n def as_message(self) -> Message:\n \"\"\"Message-typed output: generic text operations (and Text Join).\"\"\"\n return Message(text=self._format_result_as_text(self._run_text_operation()))\n\n def as_text(self) -> Message:\n \"\"\"Text output for the Text Join operation.\"\"\"\n return self.as_message()\n\n # ==================================================================\n # JSON operations\n # ==================================================================\n @staticmethod\n def extract_all_paths(obj, path=\"\"):\n paths = []\n if isinstance(obj, dict):\n for k, v in obj.items():\n new_path = f\"{path}.{k}\" if path else f\".{k}\"\n paths.append(new_path)\n paths.extend(OperationsComponent.extract_all_paths(v, new_path))\n elif isinstance(obj, list) and obj:\n new_path = f\"{path}[0]\"\n paths.append(new_path)\n paths.extend(OperationsComponent.extract_all_paths(obj[0], new_path))\n return paths\n\n @staticmethod\n def remove_keys_recursive(obj, keys_to_remove):\n if isinstance(obj, dict):\n return {\n k: OperationsComponent.remove_keys_recursive(v, keys_to_remove)\n for k, v in obj.items()\n if k not in keys_to_remove\n }\n if isinstance(obj, list):\n return [OperationsComponent.remove_keys_recursive(item, keys_to_remove) for item in obj]\n return obj\n\n @staticmethod\n def rename_keys_recursive(obj, rename_map):\n if isinstance(obj, dict):\n return {\n rename_map.get(k, k): OperationsComponent.rename_keys_recursive(v, rename_map) for k, v in obj.items()\n }\n if isinstance(obj, list):\n return [OperationsComponent.rename_keys_recursive(item, rename_map) for item in obj]\n return obj\n\n def _json_handlers(self) -> \"dict[str, Callable[[], Data]]\":\n return {\n \"Select Keys\": self.select_keys,\n \"Literal Eval\": self.evaluate_data,\n \"Combine\": self.combine_data,\n \"Append or Update\": self.append_update,\n \"Remove Keys\": self.remove_keys,\n \"Rename Keys\": self.rename_keys,\n \"Path Selection\": self.json_path,\n \"JQ Expression\": self.json_query,\n }\n\n def get_data_dict(self) -> dict:\n \"\"\"Extract data dictionary from Data object.\"\"\"\n data = self.data[0] if isinstance(self.data, list) and len(self.data) == 1 else self.data\n return data.model_dump()\n\n def get_normalized_data(self) -> dict:\n \"\"\"Get normalized data dictionary, handling the 'data' key if present.\"\"\"\n data_dict = self.get_data_dict()\n return data_dict.get(\"data\", data_dict)\n\n def data_is_list(self) -> bool:\n \"\"\"Check if data contains multiple items.\"\"\"\n return isinstance(self.data, list) and len(self.data) > 1\n\n def validate_single_data(self, operation: str) -> None:\n \"\"\"Validate that the operation is being performed on a single data object.\"\"\"\n if self.data_is_list():\n msg = f\"{operation} operation is not supported for multiple data objects.\"\n raise ValueError(msg)\n\n def select_keys(self) -> Data:\n \"\"\"Select specific keys from the data dictionary.\"\"\"\n self.validate_single_data(\"Select Keys\")\n data_dict = self.get_normalized_data()\n filter_criteria: list[str] = self.select_keys_input\n\n if len(filter_criteria) == 1 and filter_criteria[0] == \"data\":\n filtered = data_dict[\"data\"]\n else:\n if not all(key in data_dict for key in filter_criteria):\n msg = f\"Select key not found in data. Available keys: {list(data_dict.keys())}\"\n raise ValueError(msg)\n filtered = {key: value for key, value in data_dict.items() if key in filter_criteria}\n\n return Data(data=filtered)\n\n def remove_keys(self) -> Data:\n \"\"\"Remove specified keys from the data dictionary, recursively.\"\"\"\n self.validate_single_data(\"Remove Keys\")\n data_dict = self.get_normalized_data()\n remove_keys_input: list[str] = self.remove_keys_input\n filtered = OperationsComponent.remove_keys_recursive(data_dict, set(remove_keys_input))\n return Data(data=filtered)\n\n def rename_keys(self) -> Data:\n \"\"\"Rename keys in the data dictionary, recursively.\"\"\"\n self.validate_single_data(\"Rename Keys\")\n data_dict = self.get_normalized_data()\n rename_keys_input: dict[str, str] = self.rename_keys_input\n renamed = OperationsComponent.rename_keys_recursive(data_dict, rename_keys_input)\n return Data(data=renamed)\n\n def recursive_eval(self, data: Any) -> Any:\n \"\"\"Recursively evaluate string values that look like Python literals.\"\"\"\n if isinstance(data, dict):\n return {k: self.recursive_eval(v) for k, v in data.items()}\n if isinstance(data, list):\n return [self.recursive_eval(item) for item in data]\n if isinstance(data, str):\n try:\n if (\n data.strip().startswith((\"{\", \"[\", \"(\", \"'\", '\"'))\n or data.strip().lower() in (\"true\", \"false\", \"none\")\n or data.strip().replace(\".\", \"\").isdigit()\n ):\n return ast.literal_eval(data)\n except (ValueError, SyntaxError, TypeError, MemoryError):\n return data\n else:\n return data\n return data\n\n def evaluate_data(self) -> Data:\n \"\"\"Evaluate string values in the data dictionary.\"\"\"\n self.validate_single_data(\"Literal Eval\")\n logger.info(\"evaluating data\")\n return Data(**self.recursive_eval(self.get_data_dict()))\n\n def combine_data(self) -> Data:\n \"\"\"Combine multiple data objects into one.\"\"\"\n logger.info(\"combining data\")\n if not self.data_is_list():\n return self.data[0] if self.data else Data(data={})\n\n data_dicts = [data.model_dump().get(\"data\", data.model_dump()) for data in self.data]\n combined_data: dict[str, Any] = {}\n\n for data_dict in data_dicts:\n for key, value in data_dict.items():\n if key not in combined_data:\n combined_data[key] = value\n elif isinstance(combined_data[key], list):\n if isinstance(value, list):\n combined_data[key].extend(value)\n else:\n combined_data[key].append(value)\n else:\n combined_data[key] = (\n [combined_data[key], value] if not isinstance(value, list) else [combined_data[key], *value]\n )\n\n return Data(**combined_data)\n\n def append_update(self) -> Data:\n \"\"\"Append or update the data with new key-value pairs.\"\"\"\n self.validate_single_data(\"Append or Update\")\n data_filtered = self.get_normalized_data()\n for key, value in self.append_update_data.items():\n data_filtered[key] = value\n return Data(**data_filtered)\n\n def json_path(self) -> Data:\n \"\"\"Extract a value from the data using the selected JQ path.\"\"\"\n try:\n import jq\n except ImportError:\n msg = \"jq is required for Path Selection. Install with: pip install jq\"\n raise ImportError(msg) from None\n\n try:\n if not self.data or not self.selected_key:\n msg = \"Missing input data or selected key.\"\n raise ValueError(msg)\n input_payload = self.data[0].data if isinstance(self.data, list) else self.data.data\n validate_jq_program(self.selected_key)\n compiled = jq.compile(self.selected_key)\n result = compiled.input(input_payload).first()\n if isinstance(result, dict):\n return Data(data=result)\n return Data(data={\"result\": result})\n except (ValueError, TypeError, KeyError) as e:\n self.status = f\"Error: {e!s}\"\n self.log(self.status)\n return Data(data={\"error\": str(e)})\n\n def json_query(self) -> Data:\n \"\"\"Run a JQ expression against the data.\"\"\"\n try:\n import jq\n except ImportError:\n msg = \"jq is required for JQ Expression. Install with: pip install jq\"\n raise ImportError(msg) from None\n\n if not self.query or not self.query.strip():\n msg = \"JSON Query is required and cannot be blank.\"\n raise ValueError(msg)\n raw_data = self.get_data_dict()\n try:\n input_str = json.dumps(raw_data)\n repaired = repair_json(input_str)\n data_json = json.loads(repaired)\n jq_input = data_json[\"data\"] if isinstance(data_json, dict) and \"data\" in data_json else data_json\n validate_jq_program(self.query)\n results = jq.compile(self.query).input(jq_input).all()\n if not results:\n msg = \"No result from JSON query.\"\n raise ValueError(msg)\n result = results[0] if len(results) == 1 else results\n if result is None or result == \"None\":\n msg = \"JSON query returned null/None. Check if the path exists in your data.\"\n raise ValueError(msg)\n if isinstance(result, dict):\n return Data(data=result)\n return Data(data={\"result\": result})\n except (ValueError, TypeError, KeyError, json.JSONDecodeError) as e:\n logger.error(f\"JSON Query failed: {e}\")\n msg = f\"JSON Query error: {e}\"\n raise ValueError(msg) from e\n\n # ==================================================================\n # Table operations\n # ==================================================================\n def _get_primary_dataframe(self) -> DataFrame:\n \"\"\"Get the first DataFrame from input (handles both single and list inputs).\"\"\"\n if isinstance(self.df, list):\n return self.df[0].copy() if self.df else DataFrame()\n return self.df.copy()\n\n def _run_table_operation(self, operation: str) -> DataFrame:\n # Merge and Concatenate use their own inputs, not the primary df.\n if operation == \"Merge\":\n return self.merge_dataframes()\n if operation == \"Concatenate\":\n return self.concatenate_dataframes()\n\n df_copy = self._get_primary_dataframe()\n table_handlers = {\n \"Filter\": self.filter_rows_by_value,\n \"Sort\": self.sort_by_column,\n \"Drop Column\": self.drop_column,\n \"Rename Column\": self.rename_column,\n \"Add Column\": self.add_column,\n \"Select Columns\": self.select_columns,\n \"Head\": self.head,\n \"Tail\": self.tail,\n \"Replace Value\": self.replace_values,\n \"Drop Duplicates\": self.drop_duplicates,\n }\n handler = table_handlers.get(operation)\n if handler is None:\n msg = f\"Unsupported operation: {operation}\"\n logger.error(msg)\n raise ValueError(msg)\n return handler(df_copy)\n\n def filter_rows_by_value(self, df: DataFrame) -> DataFrame:\n column = df[self.column_name]\n filter_value = self.filter_value\n operator = getattr(self, \"filter_operator\", \"equals\")\n\n if operator == \"equals\":\n mask = column == filter_value\n elif operator == \"not equals\":\n mask = column != filter_value\n elif operator == \"contains\":\n mask = column.astype(str).str.contains(str(filter_value), na=False)\n elif operator == \"not contains\":\n mask = ~column.astype(str).str.contains(str(filter_value), na=False)\n elif operator == \"starts with\":\n mask = column.astype(str).str.startswith(str(filter_value), na=False)\n elif operator == \"ends with\":\n mask = column.astype(str).str.endswith(str(filter_value), na=False)\n elif operator == \"greater than\":\n try:\n numeric_value = pd.to_numeric(filter_value)\n mask = column > numeric_value\n except (ValueError, TypeError):\n mask = column.astype(str) > str(filter_value)\n elif operator == \"less than\":\n try:\n numeric_value = pd.to_numeric(filter_value)\n mask = column < numeric_value\n except (ValueError, TypeError):\n mask = column.astype(str) < str(filter_value)\n else:\n mask = column == filter_value\n\n return DataFrame(df[mask])\n\n def sort_by_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.sort_values(by=self.column_name, ascending=self.ascending))\n\n def drop_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.drop(columns=[self.column_name]))\n\n def rename_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.rename(columns={self.column_name: self.new_column_name}))\n\n def add_column(self, df: DataFrame) -> DataFrame:\n df[self.new_column_name] = [self.new_column_value] * len(df)\n return DataFrame(df)\n\n def select_columns(self, df: DataFrame) -> DataFrame:\n columns = [col.strip() for col in self.columns_to_select]\n return DataFrame(df[columns])\n\n def head(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.head(self.num_rows))\n\n def tail(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.tail(self.num_rows))\n\n def replace_values(self, df: DataFrame) -> DataFrame:\n df[self.column_name] = df[self.column_name].replace(self.replace_value, self.replacement_value)\n return DataFrame(df)\n\n def drop_duplicates(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.drop_duplicates(subset=self.column_name))\n\n def concatenate_dataframes(self) -> DataFrame:\n \"\"\"Concatenate multiple DataFrames vertically (stack rows).\"\"\"\n if not isinstance(self.df, list) or len(self.df) == 0:\n return self.df.copy() if self.df is not None else DataFrame()\n\n if len(self.df) == 1:\n return self.df[0].copy()\n\n concatenated = pd.concat(self.df, ignore_index=True)\n return DataFrame(concatenated)\n\n def merge_dataframes(self) -> DataFrame:\n \"\"\"Merge two DataFrames based on a common column (join operation).\"\"\"\n left_df = getattr(self, \"left_dataframe\", None)\n right_df = getattr(self, \"right_dataframe\", None)\n\n if left_df is None:\n return DataFrame()\n if right_df is None:\n return left_df.copy()\n\n df_left = left_df.copy()\n df_right = right_df.copy()\n\n merge_on = getattr(self, \"merge_on_column\", None)\n merge_how = getattr(self, \"merge_how\", \"inner\")\n\n if merge_on:\n if merge_on not in df_left.columns:\n msg = f\"Column '{merge_on}' not found in left DataFrame. Available: {list(df_left.columns)}\"\n raise ValueError(msg)\n if merge_on not in df_right.columns:\n msg = f\"Column '{merge_on}' not found in right DataFrame. Available: {list(df_right.columns)}\"\n raise ValueError(msg)\n merged = df_left.merge(df_right, on=merge_on, how=merge_how, suffixes=(\"\", \"_right\"))\n else:\n merged = df_left.merge(df_right, left_index=True, right_index=True, how=merge_how, suffixes=(\"\", \"_right\"))\n\n cols_to_drop = []\n for col in merged.columns:\n if col.endswith(\"_right\"):\n original_col = col[:-6]\n if original_col in merged.columns:\n merged[original_col] = merged[original_col].combine_first(merged[col])\n cols_to_drop.append(col)\n\n if cols_to_drop:\n merged = merged.drop(columns=cols_to_drop)\n\n return DataFrame(merged)\n\n # ==================================================================\n # Text operations\n # ==================================================================\n def _run_text_operation(self) -> Any:\n \"\"\"Process text based on the selected operation (Message/Text outputs).\"\"\"\n text = getattr(self, \"text_input\", \"\")\n operation = self._operation_name()\n\n # Allow empty text for Text Join (second input may have content).\n if not text and operation != \"Text Join\":\n return None\n\n text_handlers = {\n \"Case Conversion\": self._case_conversion,\n \"Text Replace\": self._text_replace,\n \"Text Extract\": self._text_extract,\n \"Text Head\": self._text_head,\n \"Text Tail\": self._text_tail,\n \"Text Strip\": self._text_strip,\n \"Text Join\": self._text_join,\n \"Text Clean\": self._text_clean,\n }\n handler = text_handlers.get(operation)\n if handler:\n return handler(text)\n return text\n\n def _word_count_data(self) -> Data:\n \"\"\"Word Count operation result as a Data object.\"\"\"\n result = self._word_count(getattr(self, \"text_input\", \"\") or \"\")\n return Data(data=result)\n\n def _word_count(self, text: str) -> dict[str, Any]:\n \"\"\"Count words, characters, and lines in text.\"\"\"\n result: dict[str, Any] = {}\n text_str = str(text) if text else \"\"\n is_empty = not text_str or not text_str.strip()\n\n if getattr(self, \"count_words\", True):\n if is_empty:\n result[\"word_count\"] = 0\n result[\"unique_words\"] = 0\n else:\n words = text_str.split()\n result[\"word_count\"] = len(words)\n result[\"unique_words\"] = len(set(words))\n\n if getattr(self, \"count_characters\", True):\n if is_empty:\n result[\"character_count\"] = 0\n result[\"character_count_no_spaces\"] = 0\n else:\n result[\"character_count\"] = len(text_str)\n result[\"character_count_no_spaces\"] = len(text_str.replace(\" \", \"\"))\n\n if getattr(self, \"count_lines\", True):\n if is_empty:\n result[\"line_count\"] = 0\n result[\"non_empty_lines\"] = 0\n else:\n lines = text_str.split(\"\\n\")\n result[\"line_count\"] = len(lines)\n result[\"non_empty_lines\"] = len([line for line in lines if line.strip()])\n\n return result\n\n def _text_to_dataframe(self, text: str) -> DataFrame:\n \"\"\"Convert markdown-style table text to a DataFrame.\"\"\"\n lines = [line.strip() for line in text.strip().split(\"\\n\") if line.strip()]\n if not lines:\n return DataFrame(pd.DataFrame())\n\n separator = getattr(self, \"table_separator\", \"|\")\n has_header = getattr(self, \"has_header\", True)\n\n rows = self._parse_table_rows(lines, separator)\n if not rows:\n return DataFrame(pd.DataFrame())\n\n df = self._create_dataframe(rows, has_header=has_header)\n self._convert_numeric_columns(df)\n self.log(f\"Converted text to DataFrame: {len(df)} rows, {len(df.columns)} columns\")\n return DataFrame(df)\n\n def _parse_table_rows(self, lines: list[str], separator: str) -> list[list[str]]:\n rows = []\n for line in lines:\n cleaned_line = line.strip(separator)\n cells = [cell.strip() for cell in cleaned_line.split(separator)]\n rows.append(cells)\n return rows\n\n def _create_dataframe(self, rows: list[list[str]], *, has_header: bool) -> pd.DataFrame:\n if has_header and len(rows) > 1:\n header = rows[0]\n data_rows = rows[1:]\n header_col_count = len(header)\n for i, row in enumerate(data_rows):\n row_col_count = len(row)\n if row_col_count != header_col_count:\n msg = (\n f\"Header mismatch: {header_col_count} column(s) in header vs \"\n f\"{row_col_count} column(s) in data row {i + 1}. \"\n \"Please ensure the header has the same number of columns as your data.\"\n )\n raise ValueError(msg)\n return pd.DataFrame(data_rows, columns=header)\n\n max_cols = max(len(row) for row in rows) if rows else 0\n columns = [f\"col_{i}\" for i in range(max_cols)]\n return pd.DataFrame(rows, columns=columns)\n\n def _convert_numeric_columns(self, df: pd.DataFrame) -> None:\n for col in df.columns:\n with contextlib.suppress(ValueError, TypeError):\n df[col] = pd.to_numeric(df[col])\n\n def _case_conversion(self, text: str) -> str:\n case_type = getattr(self, \"case_type\", \"lowercase\")\n converter = CASE_CONVERTERS.get(case_type)\n return converter(text) if converter else text\n\n def _text_replace(self, text: str) -> str:\n search_pattern = getattr(self, \"search_pattern\", \"\")\n if not search_pattern:\n return text\n replacement_text = getattr(self, \"replacement_text\", \"\")\n use_regex = getattr(self, \"use_regex\", False)\n if use_regex:\n try:\n return re.sub(search_pattern, replacement_text, text)\n except re.error as e:\n self.log(f\"Invalid regex pattern: {e}\")\n return text\n return text.replace(search_pattern, replacement_text)\n\n def _text_extract(self, text: str) -> list[str]:\n extract_pattern = getattr(self, \"extract_pattern\", \"\")\n if not extract_pattern:\n return []\n max_matches = getattr(self, \"max_matches\", 10)\n try:\n matches = re.findall(extract_pattern, text)\n except re.error as e:\n msg = f\"Invalid regex pattern '{extract_pattern}': {e}\"\n raise ValueError(msg) from e\n return matches[:max_matches] if max_matches > 0 else matches\n\n def _text_head(self, text: str) -> str:\n head_characters = getattr(self, \"head_characters\", 100)\n if head_characters < 0:\n msg = f\"Characters from Start must be a non-negative integer, got {head_characters}\"\n raise ValueError(msg)\n if head_characters == 0:\n return \"\"\n return text[:head_characters]\n\n def _text_tail(self, text: str) -> str:\n tail_characters = getattr(self, \"tail_characters\", 100)\n if tail_characters < 0:\n msg = f\"Characters from End must be a non-negative integer, got {tail_characters}\"\n raise ValueError(msg)\n if tail_characters == 0:\n return \"\"\n return text[-tail_characters:]\n\n def _text_strip(self, text: str) -> str:\n strip_mode = getattr(self, \"strip_mode\", \"both\")\n strip_characters = getattr(self, \"strip_characters\", \"\")\n text_str = str(text) if text else \"\"\n chars_to_strip = strip_characters if strip_characters else None\n if strip_mode == \"left\":\n return text_str.lstrip(chars_to_strip)\n if strip_mode == \"right\":\n return text_str.rstrip(chars_to_strip)\n return text_str.strip(chars_to_strip)\n\n def _text_join(self, text: str) -> str:\n text_input_2 = getattr(self, \"text_input_2\", \"\")\n text1 = str(text) if text else \"\"\n text2 = str(text_input_2) if text_input_2 else \"\"\n if text1 and text2:\n return f\"{text1}\\n{text2}\"\n return text1 or text2\n\n def _text_clean(self, text: str) -> str:\n result = text\n if getattr(self, \"remove_extra_spaces\", True):\n # Collapse runs of horizontal whitespace but preserve newlines so\n # that remove_empty_lines stays effective when both are enabled.\n result = re.sub(r\"[^\\S\\n]+\", \" \", result)\n if getattr(self, \"remove_special_chars\", False):\n result = re.sub(r\"[^\\w\\s]\", \"\", result)\n if getattr(self, \"remove_empty_lines\", False):\n lines = [line for line in result.split(\"\\n\") if line.strip()]\n result = \"\\n\".join(lines)\n return result\n\n def _format_result_as_text(self, result: Any) -> str:\n if result is None:\n return \"\"\n if isinstance(result, list):\n return \"\\n\".join(str(item) for item in result)\n return str(result)\n"},"column_name": {"_input_type": "StrInput",@@ -2128,6 +1847,7 @@"display_name": "Input Type","dynamic": false,"info": "Select the type of input to operate on.",+ "load_from_db": false,"name": "input_type","options": ["Text",@@ -2355,6 +2075,7 @@"dynamic": false,"info": "Select the operation to perform. The matching fields and output appear once you choose one.","limit": 1,+ "load_from_db": false,"name": "operation","options": [{@@ -2939,6 +2660,8 @@},{"data": {+ "description": "Perform operations on Text, JSON, and Tables from a single component.",+ "display_name": "Data Operations","id": "Operations-jsRu6","node": {"base_classes": [@@ -3000,11 +2723,10 @@],"frozen": false,"icon": "wand-sparkles",- "last_updated": "2026-07-30T17:22:27.467Z",+ "last_updated": "2026-10-27T20:15:39.924Z","legacy": false,- "lf_version": "0.11.2rc0","metadata": {- "code_hash": "4c2a33c778d3",+ "code_hash": "f15ba610cfd0","dependencies": {"dependencies": [{@@ -3013,11 +2735,11 @@},{"name": "json_repair",- "version": "0.61.4"+ "version": "0.61.7"},{"name": "lfx",- "version": null+ "version": "1.12.3"},{"name": "jq",@@ -3068,7 +2790,7 @@"data manipulation","data transformation"],- "module": "lfx.components.processing.operations.OperationsComponent"+ "module": "custom_components.data_operations"},"minimized": false,"output_types": [],@@ -3076,7 +2798,7 @@{"allows_loop": false,"cache": true,- "display_name": "Message",+ "display_name": "Table","group_outputs": false,"hidden": null,"loop_types": null,@@ -3098,7 +2820,7 @@"value": "72c3d17c-2dac-4a73-b48a-6518473d7830"},"_frontend_node_folder_id": {- "value": "2d3b55c9-689c-4ef1-a4bd-23eb2159566c"+ "value": "f3f8bf74-7a73-4ab3-9769-0d8a4ebbaec9"},"_type": "Component","append_update_data": {@@ -3193,7 +2915,7 @@"show": true,"title_case": false,"type": "code",- "value": "\"\"\"Unified Operations component.\n\nBrings together the previously separate JSON, Table, and Text operation\ncomponents into a single component. An \"Input Type\" selector (Text / JSON /\nTable) drives everything: it filters the \"Operation\" picker to the operations\nthat apply to that type, reveals the matching input (Text / JSON / Table) and\nits operation-specific fields, and advertises the appropriate output type.\n\nThe three original components (JSON Operations, Table Operations, Text\nOperations) remain available as legacy components for backward compatibility\nwith existing flows.\n\"\"\"\n\nimport ast\nimport contextlib\nimport json\nimport re\nfrom typing import TYPE_CHECKING, Any\n\nimport pandas as pd\nfrom json_repair import repair_json\n\nfrom lfx.custom import Component\nfrom lfx.field_typing import RangeSpec\nfrom lfx.inputs import DictInput, SortableListInput, TabInput\nfrom lfx.io import (\n BoolInput,\n DataFrameInput,\n DataInput,\n DropdownInput,\n IntInput,\n MessageTextInput,\n MultilineInput,\n Output,\n StrInput,\n)\nfrom lfx.log.logger import logger\nfrom lfx.schema import Data\nfrom lfx.schema.dataframe import DataFrame\nfrom lfx.schema.dotdict import dotdict\nfrom lfx.schema.message import Message\n\nif TYPE_CHECKING:\n from collections.abc import Callable\n\n# The \"Input Type\" selector tabs. Each value maps a Langflow data type to the\n# operations, input, and output that belong to it.\nINPUT_TYPES = [\"Text\", \"JSON\", \"Table\"]\n\n# Operations grouped by input type, in display order, each with the icon shown\n# in the Operation picker. This is the single source of truth for the picker;\n# update_build_config swaps the picker's options to the selected type's list.\nOPERATIONS_BY_TYPE: dict[str, list[dict[str, str]]] = {\n \"Text\": [\n {\"name\": \"Word Count\", \"icon\": \"hash\"},\n {\"name\": \"Case Conversion\", \"icon\": \"type\"},\n {\"name\": \"Text Replace\", \"icon\": \"replace\"},\n {\"name\": \"Text Extract\", \"icon\": \"search\"},\n {\"name\": \"Text Head\", \"icon\": \"chevron-left\"},\n {\"name\": \"Text Tail\", \"icon\": \"chevron-right\"},\n {\"name\": \"Text Strip\", \"icon\": \"minus\"},\n {\"name\": \"Text Join\", \"icon\": \"link\"},\n {\"name\": \"Text Clean\", \"icon\": \"sparkles\"},\n {\"name\": \"Text to DataFrame\", \"icon\": \"table\"},\n ],\n \"JSON\": [\n {\"name\": \"Select Keys\", \"icon\": \"lasso-select\"},\n {\"name\": \"Literal Eval\", \"icon\": \"braces\"},\n {\"name\": \"Combine\", \"icon\": \"merge\"},\n {\"name\": \"Append or Update\", \"icon\": \"circle-plus\"},\n {\"name\": \"Remove Keys\", \"icon\": \"eraser\"},\n {\"name\": \"Rename Keys\", \"icon\": \"pencil-line\"},\n {\"name\": \"Path Selection\", \"icon\": \"mouse-pointer\"},\n {\"name\": \"JQ Expression\", \"icon\": \"terminal\"},\n ],\n \"Table\": [\n {\"name\": \"Add Column\", \"icon\": \"plus\"},\n {\"name\": \"Concatenate\", \"icon\": \"combine\"},\n {\"name\": \"Drop Column\", \"icon\": \"minus\"},\n {\"name\": \"Filter\", \"icon\": \"filter\"},\n {\"name\": \"Head\", \"icon\": \"arrow-up\"},\n {\"name\": \"Merge\", \"icon\": \"merge\"},\n {\"name\": \"Rename Column\", \"icon\": \"pencil\"},\n {\"name\": \"Replace Value\", \"icon\": \"replace\"},\n {\"name\": \"Select Columns\", \"icon\": \"columns\"},\n {\"name\": \"Sort\", \"icon\": \"arrow-up-down\"},\n {\"name\": \"Tail\", \"icon\": \"arrow-down\"},\n {\"name\": \"Drop Duplicates\", \"icon\": \"copy-x\"},\n ],\n}\n\n# Operation-name sets derived from the picker, used for dispatch and output\n# routing. Keeping them derived from OPERATIONS_BY_TYPE avoids any drift.\nJSON_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"JSON\"]}\nTABLE_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"Table\"]}\nTEXT_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"Text\"]}\n\n# Each input type maps to its main input field and its default output. \"Text\"\n# normally outputs a Message; \"JSON\" a Data; \"Table\" a DataFrame. A few text\n# operations override this (Word Count -> Data, Text to DataFrame -> DataFrame).\nINPUT_TYPE_TO_MAIN_INPUT = {\"Text\": \"text_input\", \"JSON\": \"data\", \"Table\": \"df\"}\n\n# Case conversions for the Text \"Case Conversion\" operation.\nCASE_CONVERTERS: dict[str, Any] = {\n \"uppercase\": str.upper,\n \"lowercase\": str.lower,\n \"title\": str.title,\n \"capitalize\": str.capitalize,\n \"swapcase\": str.swapcase,\n}\n\n\nclass OperationsComponent(Component):\n display_name = \"Data Operations\"\n description = \"Perform operations on Text, JSON, and Tables from a single component.\"\n documentation: str = \"https://docs.langflow.org/components-processing#operations\"\n icon = \"wand-sparkles\"\n name = \"Operations\"\n metadata = {\n \"keywords\": [\n \"operations\",\n \"data operations\",\n \"json\",\n \"json operations\",\n \"table\",\n \"table operations\",\n \"dataframe\",\n \"dataframe operations\",\n \"text\",\n \"text operations\",\n \"select keys\",\n \"literal eval\",\n \"combine\",\n \"append or update\",\n \"remove keys\",\n \"rename keys\",\n \"path selection\",\n \"jq expression\",\n \"parse json\",\n \"add column\",\n \"concatenate\",\n \"drop column\",\n \"filter\",\n \"head\",\n \"merge\",\n \"rename column\",\n \"replace value\",\n \"select columns\",\n \"sort\",\n \"tail\",\n \"drop duplicates\",\n \"word count\",\n \"case conversion\",\n \"text replace\",\n \"text extract\",\n \"text join\",\n \"text clean\",\n \"text to dataframe\",\n \"data manipulation\",\n \"data transformation\",\n ],\n }\n\n # Operation -> operation-specific input fields to reveal when selected.\n OPERATION_FIELDS: dict[str, list[str]] = {\n # JSON\n \"Select Keys\": [\"select_keys_input\"],\n \"Literal Eval\": [],\n \"Combine\": [],\n \"Append or Update\": [\"append_update_data\"],\n \"Remove Keys\": [\"remove_keys_input\"],\n \"Rename Keys\": [\"rename_keys_input\"],\n \"Path Selection\": [\"mapped_json_display\", \"selected_key\"],\n \"JQ Expression\": [\"query\"],\n # Table\n \"Add Column\": [\"new_column_name\", \"new_column_value\"],\n \"Concatenate\": [],\n \"Drop Column\": [\"column_name\"],\n \"Filter\": [\"column_name\", \"filter_value\", \"filter_operator\"],\n \"Head\": [\"num_rows\"],\n \"Merge\": [\"left_dataframe\", \"right_dataframe\", \"merge_on_column\", \"merge_how\"],\n \"Rename Column\": [\"column_name\", \"new_column_name\"],\n \"Replace Value\": [\"column_name\", \"replace_value\", \"replacement_value\"],\n \"Select Columns\": [\"columns_to_select\"],\n \"Sort\": [\"column_name\", \"ascending\"],\n \"Tail\": [\"num_rows\"],\n \"Drop Duplicates\": [\"column_name\"],\n # Text\n \"Word Count\": [\"count_words\", \"count_characters\", \"count_lines\"],\n \"Case Conversion\": [\"case_type\"],\n \"Text Replace\": [\"search_pattern\", \"replacement_text\", \"use_regex\"],\n \"Text Extract\": [\"extract_pattern\", \"max_matches\"],\n \"Text Head\": [\"head_characters\"],\n \"Text Tail\": [\"tail_characters\"],\n \"Text Strip\": [\"strip_mode\", \"strip_characters\"],\n \"Text Join\": [\"text_input_2\"],\n \"Text Clean\": [\"remove_extra_spaces\", \"remove_special_chars\", \"remove_empty_lines\"],\n \"Text to DataFrame\": [\"table_separator\", \"has_header\"],\n }\n\n # The three main inputs (one per data type). They are never treated as\n # operation-specific fields; the input-type selector toggles them.\n MAIN_INPUTS = (\"text_input\", \"data\", \"df\")\n\n # Every operation-specific field (union of all the lists above), used to\n # hide and reset fields whenever the input type or operation changes.\n ALL_OPERATION_FIELDS: list[str] = [\n # JSON\n \"select_keys_input\",\n \"append_update_data\",\n \"remove_keys_input\",\n \"rename_keys_input\",\n \"mapped_json_display\",\n \"selected_key\",\n \"query\",\n # Table\n \"column_name\",\n \"filter_value\",\n \"filter_operator\",\n \"ascending\",\n \"new_column_name\",\n \"new_column_value\",\n \"columns_to_select\",\n \"num_rows\",\n \"replace_value\",\n \"replacement_value\",\n \"left_dataframe\",\n \"right_dataframe\",\n \"merge_on_column\",\n \"merge_how\",\n # Text\n \"table_separator\",\n \"has_header\",\n \"count_words\",\n \"count_characters\",\n \"count_lines\",\n \"case_type\",\n \"use_regex\",\n \"search_pattern\",\n \"replacement_text\",\n \"extract_pattern\",\n \"max_matches\",\n \"head_characters\",\n \"tail_characters\",\n \"strip_mode\",\n \"strip_characters\",\n \"text_input_2\",\n \"remove_extra_spaces\",\n \"remove_special_chars\",\n \"remove_empty_lines\",\n ]\n\n # Defaults applied to the JSON operation fields when the operation changes,\n # mirroring the JSON Operations component's reset behavior.\n OPERATION_FIELD_DEFAULTS: dict[str, Any] = {\n \"select_keys_input\": [],\n \"append_update_data\": {\"key\": \"value\"},\n \"remove_keys_input\": [],\n \"rename_keys_input\": {\"old_key\": \"new_key\"},\n \"mapped_json_display\": \"\",\n \"selected_key\": None,\n \"query\": \"\",\n }\n\n inputs = [\n # --- Input type selector: drives operations, input, and output ---\n TabInput(\n name=\"input_type\",\n display_name=\"Input Type\",\n options=INPUT_TYPES,\n value=\"Text\",\n info=\"Select the type of input to operate on.\",\n real_time_refresh=True,\n ),\n # --- Main inputs: one per data type, shown contextually ---\n MultilineInput(\n name=\"text_input\",\n display_name=\"Text\",\n info=\"The input text to process.\",\n show=True,\n ),\n DataInput(\n name=\"data\",\n display_name=\"JSON\",\n info=\"The JSON / Data object to operate on.\",\n is_list=True,\n show=False,\n ),\n DataFrameInput(\n name=\"df\",\n display_name=\"Table\",\n info=\"The input Table to operate on. Connect multiple Tables for merge or concatenate operations.\",\n is_list=True,\n show=False,\n ),\n # --- Operation picker (options are filtered by Input Type) ---\n SortableListInput(\n name=\"operation\",\n display_name=\"Operation\",\n placeholder=\"Select Operation\",\n info=\"Select the operation to perform. The matching fields and output appear once you choose one.\",\n options=OPERATIONS_BY_TYPE[\"Text\"],\n real_time_refresh=True,\n limit=1,\n ),\n # --- JSON operation fields ---\n MessageTextInput(\n name=\"select_keys_input\",\n display_name=\"Select Keys\",\n info=\"List of keys to select from the data. Only top-level keys can be selected.\",\n show=False,\n is_list=True,\n value=[],\n ),\n DictInput(\n name=\"append_update_data\",\n display_name=\"Append or Update\",\n info=\"Data to append or update the existing data with. Only top-level keys are checked.\",\n show=False,\n value={\"key\": \"value\"},\n is_list=True,\n ),\n MessageTextInput(\n name=\"remove_keys_input\",\n display_name=\"Remove Keys\",\n info=\"List of keys to remove from the data.\",\n show=False,\n is_list=True,\n value=[],\n ),\n DictInput(\n name=\"rename_keys_input\",\n display_name=\"Rename Keys\",\n info=\"List of keys to rename in the data.\",\n show=False,\n is_list=True,\n value={\"old_key\": \"new_key\"},\n ),\n MultilineInput(\n name=\"mapped_json_display\",\n display_name=\"JSON to Map\",\n info=\"Paste or preview your JSON here to explore its structure and select a path for extraction.\",\n required=False,\n refresh_button=True,\n real_time_refresh=True,\n placeholder=\"Add a JSON example.\",\n show=False,\n ),\n DropdownInput(\n name=\"selected_key\",\n display_name=\"Select Path\",\n options=[],\n required=False,\n dynamic=True,\n show=False,\n value=None,\n ),\n MessageTextInput(\n name=\"query\",\n display_name=\"JQ Expression\",\n info=\"JSON Query to filter the data. Used by Path Selection and JQ Expression operations.\",\n placeholder=\"e.g., .properties.id\",\n show=False,\n ),\n # --- Table operation fields ---\n StrInput(\n name=\"column_name\",\n display_name=\"Column Name\",\n info=\"The column name to use for the operation.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"filter_value\",\n display_name=\"Filter Value\",\n info=\"The value to filter rows by.\",\n dynamic=True,\n show=False,\n ),\n DropdownInput(\n name=\"filter_operator\",\n display_name=\"Filter Operator\",\n options=[\n \"equals\",\n \"not equals\",\n \"contains\",\n \"not contains\",\n \"starts with\",\n \"ends with\",\n \"greater than\",\n \"less than\",\n ],\n value=\"equals\",\n info=\"The operator to apply for filtering rows.\",\n advanced=False,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"ascending\",\n display_name=\"Sort Ascending\",\n info=\"Whether to sort in ascending order.\",\n dynamic=True,\n show=False,\n value=True,\n ),\n StrInput(\n name=\"new_column_name\",\n display_name=\"New Column Name\",\n info=\"The new column name when renaming or adding a column.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"new_column_value\",\n display_name=\"New Column Value\",\n info=\"The value to populate the new column with.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"columns_to_select\",\n display_name=\"Columns to Select\",\n dynamic=True,\n is_list=True,\n show=False,\n ),\n IntInput(\n name=\"num_rows\",\n display_name=\"Number of Rows\",\n info=\"Number of rows to return (for head/tail).\",\n dynamic=True,\n show=False,\n value=5,\n ),\n MessageTextInput(\n name=\"replace_value\",\n display_name=\"Value to Replace\",\n info=\"The value to replace in the column.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"replacement_value\",\n display_name=\"Replacement Value\",\n info=\"The value to replace with.\",\n dynamic=True,\n show=False,\n ),\n DataFrameInput(\n name=\"left_dataframe\",\n display_name=\"Left Table\",\n info=\"The left (primary) Table for merge operations. \"\n \"In a left merge, all rows from this table are preserved.\",\n dynamic=True,\n show=False,\n ),\n DataFrameInput(\n name=\"right_dataframe\",\n display_name=\"Right Table\",\n info=\"The right (secondary) Table for merge operations. \"\n \"In a right merge, all rows from this table are preserved.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"merge_on_column\",\n display_name=\"Merge On Column\",\n info=\"The column name to merge Tables on. Must exist in both Tables.\",\n dynamic=True,\n show=False,\n ),\n DropdownInput(\n name=\"merge_how\",\n display_name=\"Merge Type\",\n options=[\"inner\", \"outer\", \"left\", \"right\"],\n value=\"inner\",\n info=\"Type of merge: inner (intersection), outer (union), left, or right.\",\n dynamic=True,\n show=False,\n ),\n # --- Text operation fields ---\n StrInput(\n name=\"table_separator\",\n display_name=\"Table Separator\",\n info=\"Separator used in the table (default: '|').\",\n value=\"|\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"has_header\",\n display_name=\"Has Header\",\n info=\"Whether the table has a header row.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_words\",\n display_name=\"Count Words\",\n info=\"Include word count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_characters\",\n display_name=\"Count Characters\",\n info=\"Include character count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_lines\",\n display_name=\"Count Lines\",\n info=\"Include line count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n DropdownInput(\n name=\"case_type\",\n display_name=\"Case Type\",\n options=[\"uppercase\", \"lowercase\", \"title\", \"capitalize\", \"swapcase\"],\n value=\"lowercase\",\n info=\"Type of case conversion to apply.\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"use_regex\",\n display_name=\"Use Regex\",\n info=\"Whether to treat search pattern as regex.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"search_pattern\",\n display_name=\"Search Pattern\",\n info=\"Text pattern to search for (supports regex).\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"replacement_text\",\n display_name=\"Replacement Text\",\n info=\"Text to replace the search pattern with.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"extract_pattern\",\n display_name=\"Extract Pattern\",\n info=\"Regex pattern to extract from text.\",\n dynamic=True,\n show=False,\n ),\n IntInput(\n name=\"max_matches\",\n display_name=\"Max Matches\",\n info=\"Maximum number of matches to extract.\",\n value=10,\n dynamic=True,\n show=False,\n ),\n IntInput(\n name=\"head_characters\",\n display_name=\"Characters from Start\",\n info=\"Number of characters to extract from the beginning of text. Must be non-negative.\",\n value=100,\n dynamic=True,\n show=False,\n range_spec=RangeSpec(min=0, max=1000000, step=1, step_type=\"int\"),\n ),\n IntInput(\n name=\"tail_characters\",\n display_name=\"Characters from End\",\n info=\"Number of characters to extract from the end of text. Must be non-negative.\",\n value=100,\n dynamic=True,\n show=False,\n range_spec=RangeSpec(min=0, max=1000000, step=1, step_type=\"int\"),\n ),\n DropdownInput(\n name=\"strip_mode\",\n display_name=\"Strip Mode\",\n options=[\"both\", \"left\", \"right\"],\n value=\"both\",\n info=\"Which sides to strip whitespace from.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"strip_characters\",\n display_name=\"Characters to Strip\",\n info=\"Specific characters to remove (leave empty for whitespace).\",\n value=\"\",\n dynamic=True,\n show=False,\n ),\n MultilineInput(\n name=\"text_input_2\",\n display_name=\"Second Text Input\",\n info=\"Second text to join with the first text.\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_extra_spaces\",\n display_name=\"Remove Extra Spaces\",\n info=\"Remove multiple consecutive spaces.\",\n value=True,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_special_chars\",\n display_name=\"Remove Special Characters\",\n info=\"Remove special characters except alphanumeric and spaces.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_empty_lines\",\n display_name=\"Remove Empty Lines\",\n info=\"Remove empty lines from text.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n ]\n\n # Default output matches the default Input Type (\"Text\" -> Message).\n # update_outputs / update_frontend_node narrow it to the selected type and\n # operation.\n outputs = [Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\")]\n\n # ------------------------------------------------------------------\n # Operation routing helpers\n # ------------------------------------------------------------------\n @staticmethod\n def _extract_operation_name(field_value: Any) -> str:\n \"\"\"Extract the operation name from a SortableListInput value.\"\"\"\n if isinstance(field_value, list) and len(field_value) > 0 and isinstance(field_value[0], dict):\n return field_value[0].get(\"name\", \"\")\n if isinstance(field_value, str):\n return field_value\n return \"\"\n\n def _operation_name(self) -> str:\n \"\"\"Get the currently selected operation name.\"\"\"\n return self._extract_operation_name(getattr(self, \"operation\", []))\n\n @staticmethod\n def _default_output_for_type(input_type: str) -> Output:\n \"\"\"Return the output advertised for an input type when no operation is selected yet.\"\"\"\n if input_type == \"JSON\":\n return Output(display_name=\"JSON\", name=\"data_output\", method=\"as_data\")\n if input_type == \"Table\":\n return Output(display_name=\"Table\", name=\"dataframe_output\", method=\"as_dataframe\")\n return Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\")\n\n # ------------------------------------------------------------------\n # Dynamic UI\n # ------------------------------------------------------------------\n def _reset_operation_fields(self, build_config: dotdict) -> None:\n \"\"\"Hide every operation-specific field and restore its default value.\"\"\"\n for field in self.ALL_OPERATION_FIELDS:\n if field in build_config:\n build_config[field][\"show\"] = False\n if field in self.OPERATION_FIELD_DEFAULTS:\n build_config[field][\"value\"] = self.OPERATION_FIELD_DEFAULTS[field]\n\n def _show_main_input(self, build_config: dotdict, input_type: str, operation: str) -> None:\n \"\"\"Show only the main input that matches the input type; hide the others.\"\"\"\n for inp in self.MAIN_INPUTS:\n if inp in build_config:\n build_config[inp][\"show\"] = False\n build_config[inp][\"required\"] = False\n\n main_input = INPUT_TYPE_TO_MAIN_INPUT.get(input_type)\n if main_input and main_input in build_config:\n build_config[main_input][\"show\"] = True\n build_config[main_input][\"required\"] = True\n # The JSON \"Combine\" operation consumes a list of Data objects.\n if main_input == \"data\":\n build_config[\"data\"][\"is_list\"] = operation == \"Combine\"\n\n def update_build_config(self, build_config: dotdict, field_value: Any, field_name: str | None = None) -> dotdict:\n # Path Selection: refresh the available JSON paths from the pasted JSON.\n if field_name == \"mapped_json_display\":\n try:\n parsed_json = json.loads(field_value)\n keys = self.extract_all_paths(parsed_json)\n build_config[\"selected_key\"][\"options\"] = keys\n build_config[\"selected_key\"][\"show\"] = True\n except (json.JSONDecodeError, TypeError, ValueError) as e:\n logger.error(f\"Error parsing mapped JSON: {e}\")\n build_config[\"selected_key\"][\"show\"] = False\n return build_config\n\n # Input type changed: swap the operation list, clear the selection, and\n # show only the matching input. No operation-specific fields are shown\n # until an operation is picked.\n if field_name == \"input_type\":\n input_type = field_value if field_value in OPERATIONS_BY_TYPE else \"Text\"\n build_config[\"operation\"][\"options\"] = OPERATIONS_BY_TYPE[input_type]\n build_config[\"operation\"][\"value\"] = []\n self._reset_operation_fields(build_config)\n self._show_main_input(build_config, input_type, operation=\"\")\n return build_config\n\n # Operation changed: reset fields, show the input for the current type,\n # then reveal the operation-specific fields.\n if field_name == \"operation\":\n operation = self._extract_operation_name(field_value)\n self._reset_operation_fields(build_config)\n\n input_type = build_config.get(\"input_type\", {}).get(\"value\", \"Text\")\n self._show_main_input(build_config, input_type, operation)\n\n for field in self.OPERATION_FIELDS.get(operation, []):\n if field in build_config:\n build_config[field][\"show\"] = True\n\n return build_config\n\n return build_config\n\n def update_outputs(self, frontend_node: dict, field_name: str, field_value: Any) -> dict:\n \"\"\"Create the output(s) appropriate to the selected input type and operation.\"\"\"\n if field_name == \"input_type\":\n # Switching type clears the operation; advertise the type's default.\n input_type = field_value if field_value in OPERATIONS_BY_TYPE else \"Text\"\n frontend_node[\"outputs\"] = [self._default_output_for_type(input_type)]\n return frontend_node\n\n template = frontend_node.get(\"template\", {})\n input_type = template.get(\"input_type\", {}).get(\"value\", \"Text\")\n\n if field_name == \"operation\":\n operation = self._extract_operation_name(field_value)\n else:\n # Any other refresh (e.g. Path Selection's \"JSON to Map\" field)\n # reaches here on a freshly rebuilt node whose outputs were reset\n # to the class default (Message). Re-derive the output from the\n # saved operation so the refresh doesn't swap the real output type.\n operation = self._extract_operation_name(template.get(\"operation\", {}).get(\"value\", []))\n\n if not operation:\n # No operation selected: fall back to the input type's default output.\n frontend_node[\"outputs\"] = [self._default_output_for_type(input_type)]\n return frontend_node\n\n frontend_node[\"outputs\"] = []\n if operation in JSON_OPERATIONS or operation == \"Word Count\":\n frontend_node[\"outputs\"].append(Output(display_name=\"JSON\", name=\"data_output\", method=\"as_data\"))\n elif operation in TABLE_OPERATIONS or operation == \"Text to DataFrame\":\n frontend_node[\"outputs\"].append(\n Output(display_name=\"Table\", name=\"dataframe_output\", method=\"as_dataframe\")\n )\n elif operation == \"Text Join\":\n frontend_node[\"outputs\"].append(Output(display_name=\"Text\", name=\"text_output\", method=\"as_text\"))\n frontend_node[\"outputs\"].append(Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\"))\n else:\n frontend_node[\"outputs\"].append(Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\"))\n\n return frontend_node\n\n async def update_frontend_node(self, new_frontend_node: dict, current_frontend_node: dict) -> dict:\n \"\"\"Keep the operation options and outputs in sync with the saved input type on load.\"\"\"\n await super().update_frontend_node(new_frontend_node, current_frontend_node)\n\n template = new_frontend_node.get(\"template\", {})\n input_type = template.get(\"input_type\", {}).get(\"value\", \"Text\")\n if input_type not in OPERATIONS_BY_TYPE:\n input_type = \"Text\"\n\n # Filter the operation picker to the saved input type.\n if \"operation\" in template:\n template[\"operation\"][\"options\"] = OPERATIONS_BY_TYPE[input_type]\n\n # Re-derive the outputs from the saved input type + operation.\n operation_value = template.get(\"operation\", {}).get(\"value\", [])\n if self._extract_operation_name(operation_value):\n self.update_outputs(new_frontend_node, \"operation\", operation_value)\n else:\n self.update_outputs(new_frontend_node, \"input_type\", input_type)\n\n return new_frontend_node\n\n # ==================================================================\n # Output methods (referenced by update_outputs)\n # ==================================================================\n def as_data(self) -> Data:\n \"\"\"JSON-typed output: JSON operations and Word Count.\"\"\"\n operation = self._operation_name()\n if operation in JSON_OPERATIONS:\n handler = self._json_handlers().get(operation)\n if handler:\n try:\n return handler()\n except Exception as e:\n logger.error(f\"Error executing {operation}: {e!s}\")\n raise\n if operation == \"Word Count\":\n return self._word_count_data()\n return Data(data={})\n\n def as_dataframe(self) -> DataFrame:\n \"\"\"Table-typed output: Table operations and Text to DataFrame.\"\"\"\n operation = self._operation_name()\n if operation in TABLE_OPERATIONS:\n return self._run_table_operation(operation)\n if operation == \"Text to DataFrame\":\n return self._text_to_dataframe(getattr(self, \"text_input\", \"\") or \"\")\n return DataFrame(pd.DataFrame())\n\n def as_message(self) -> Message:\n \"\"\"Message-typed output: generic text operations (and Text Join).\"\"\"\n return Message(text=self._format_result_as_text(self._run_text_operation()))\n\n def as_text(self) -> Message:\n \"\"\"Text output for the Text Join operation.\"\"\"\n return self.as_message()\n\n # ==================================================================\n # JSON operations\n # ==================================================================\n @staticmethod\n def extract_all_paths(obj, path=\"\"):\n paths = []\n if isinstance(obj, dict):\n for k, v in obj.items():\n new_path = f\"{path}.{k}\" if path else f\".{k}\"\n paths.append(new_path)\n paths.extend(OperationsComponent.extract_all_paths(v, new_path))\n elif isinstance(obj, list) and obj:\n new_path = f\"{path}[0]\"\n paths.append(new_path)\n paths.extend(OperationsComponent.extract_all_paths(obj[0], new_path))\n return paths\n\n @staticmethod\n def remove_keys_recursive(obj, keys_to_remove):\n if isinstance(obj, dict):\n return {\n k: OperationsComponent.remove_keys_recursive(v, keys_to_remove)\n for k, v in obj.items()\n if k not in keys_to_remove\n }\n if isinstance(obj, list):\n return [OperationsComponent.remove_keys_recursive(item, keys_to_remove) for item in obj]\n return obj\n\n @staticmethod\n def rename_keys_recursive(obj, rename_map):\n if isinstance(obj, dict):\n return {\n rename_map.get(k, k): OperationsComponent.rename_keys_recursive(v, rename_map) for k, v in obj.items()\n }\n if isinstance(obj, list):\n return [OperationsComponent.rename_keys_recursive(item, rename_map) for item in obj]\n return obj\n\n def _json_handlers(self) -> \"dict[str, Callable[[], Data]]\":\n return {\n \"Select Keys\": self.select_keys,\n \"Literal Eval\": self.evaluate_data,\n \"Combine\": self.combine_data,\n \"Append or Update\": self.append_update,\n \"Remove Keys\": self.remove_keys,\n \"Rename Keys\": self.rename_keys,\n \"Path Selection\": self.json_path,\n \"JQ Expression\": self.json_query,\n }\n\n def get_data_dict(self) -> dict:\n \"\"\"Extract data dictionary from Data object.\"\"\"\n data = self.data[0] if isinstance(self.data, list) and len(self.data) == 1 else self.data\n return data.model_dump()\n\n def get_normalized_data(self) -> dict:\n \"\"\"Get normalized data dictionary, handling the 'data' key if present.\"\"\"\n data_dict = self.get_data_dict()\n return data_dict.get(\"data\", data_dict)\n\n def data_is_list(self) -> bool:\n \"\"\"Check if data contains multiple items.\"\"\"\n return isinstance(self.data, list) and len(self.data) > 1\n\n def validate_single_data(self, operation: str) -> None:\n \"\"\"Validate that the operation is being performed on a single data object.\"\"\"\n if self.data_is_list():\n msg = f\"{operation} operation is not supported for multiple data objects.\"\n raise ValueError(msg)\n\n def select_keys(self) -> Data:\n \"\"\"Select specific keys from the data dictionary.\"\"\"\n self.validate_single_data(\"Select Keys\")\n data_dict = self.get_normalized_data()\n filter_criteria: list[str] = self.select_keys_input\n\n if len(filter_criteria) == 1 and filter_criteria[0] == \"data\":\n filtered = data_dict[\"data\"]\n else:\n if not all(key in data_dict for key in filter_criteria):\n msg = f\"Select key not found in data. Available keys: {list(data_dict.keys())}\"\n raise ValueError(msg)\n filtered = {key: value for key, value in data_dict.items() if key in filter_criteria}\n\n return Data(data=filtered)\n\n def remove_keys(self) -> Data:\n \"\"\"Remove specified keys from the data dictionary, recursively.\"\"\"\n self.validate_single_data(\"Remove Keys\")\n data_dict = self.get_normalized_data()\n remove_keys_input: list[str] = self.remove_keys_input\n filtered = OperationsComponent.remove_keys_recursive(data_dict, set(remove_keys_input))\n return Data(data=filtered)\n\n def rename_keys(self) -> Data:\n \"\"\"Rename keys in the data dictionary, recursively.\"\"\"\n self.validate_single_data(\"Rename Keys\")\n data_dict = self.get_normalized_data()\n rename_keys_input: dict[str, str] = self.rename_keys_input\n renamed = OperationsComponent.rename_keys_recursive(data_dict, rename_keys_input)\n return Data(data=renamed)\n\n def recursive_eval(self, data: Any) -> Any:\n \"\"\"Recursively evaluate string values that look like Python literals.\"\"\"\n if isinstance(data, dict):\n return {k: self.recursive_eval(v) for k, v in data.items()}\n if isinstance(data, list):\n return [self.recursive_eval(item) for item in data]\n if isinstance(data, str):\n try:\n if (\n data.strip().startswith((\"{\", \"[\", \"(\", \"'\", '\"'))\n or data.strip().lower() in (\"true\", \"false\", \"none\")\n or data.strip().replace(\".\", \"\").isdigit()\n ):\n return ast.literal_eval(data)\n except (ValueError, SyntaxError, TypeError, MemoryError):\n return data\n else:\n return data\n return data\n\n def evaluate_data(self) -> Data:\n \"\"\"Evaluate string values in the data dictionary.\"\"\"\n self.validate_single_data(\"Literal Eval\")\n logger.info(\"evaluating data\")\n return Data(**self.recursive_eval(self.get_data_dict()))\n\n def combine_data(self) -> Data:\n \"\"\"Combine multiple data objects into one.\"\"\"\n logger.info(\"combining data\")\n if not self.data_is_list():\n return self.data[0] if self.data else Data(data={})\n\n data_dicts = [data.model_dump().get(\"data\", data.model_dump()) for data in self.data]\n combined_data: dict[str, Any] = {}\n\n for data_dict in data_dicts:\n for key, value in data_dict.items():\n if key not in combined_data:\n combined_data[key] = value\n elif isinstance(combined_data[key], list):\n if isinstance(value, list):\n combined_data[key].extend(value)\n else:\n combined_data[key].append(value)\n else:\n combined_data[key] = (\n [combined_data[key], value] if not isinstance(value, list) else [combined_data[key], *value]\n )\n\n return Data(**combined_data)\n\n def append_update(self) -> Data:\n \"\"\"Append or update the data with new key-value pairs.\"\"\"\n self.validate_single_data(\"Append or Update\")\n data_filtered = self.get_normalized_data()\n for key, value in self.append_update_data.items():\n data_filtered[key] = value\n return Data(**data_filtered)\n\n def json_path(self) -> Data:\n \"\"\"Extract a value from the data using the selected JQ path.\"\"\"\n try:\n import jq\n except ImportError:\n msg = \"jq is required for Path Selection. Install with: pip install jq\"\n raise ImportError(msg) from None\n\n try:\n if not self.data or not self.selected_key:\n msg = \"Missing input data or selected key.\"\n raise ValueError(msg)\n input_payload = self.data[0].data if isinstance(self.data, list) else self.data.data\n compiled = jq.compile(self.selected_key)\n result = compiled.input(input_payload).first()\n if isinstance(result, dict):\n return Data(data=result)\n return Data(data={\"result\": result})\n except (ValueError, TypeError, KeyError) as e:\n self.status = f\"Error: {e!s}\"\n self.log(self.status)\n return Data(data={\"error\": str(e)})\n\n def json_query(self) -> Data:\n \"\"\"Run a JQ expression against the data.\"\"\"\n try:\n import jq\n except ImportError:\n msg = \"jq is required for JQ Expression. Install with: pip install jq\"\n raise ImportError(msg) from None\n\n if not self.query or not self.query.strip():\n msg = \"JSON Query is required and cannot be blank.\"\n raise ValueError(msg)\n raw_data = self.get_data_dict()\n try:\n input_str = json.dumps(raw_data)\n repaired = repair_json(input_str)\n data_json = json.loads(repaired)\n jq_input = data_json[\"data\"] if isinstance(data_json, dict) and \"data\" in data_json else data_json\n results = jq.compile(self.query).input(jq_input).all()\n if not results:\n msg = \"No result from JSON query.\"\n raise ValueError(msg)\n result = results[0] if len(results) == 1 else results\n if result is None or result == \"None\":\n msg = \"JSON query returned null/None. Check if the path exists in your data.\"\n raise ValueError(msg)\n if isinstance(result, dict):\n return Data(data=result)\n return Data(data={\"result\": result})\n except (ValueError, TypeError, KeyError, json.JSONDecodeError) as e:\n logger.error(f\"JSON Query failed: {e}\")\n msg = f\"JSON Query error: {e}\"\n raise ValueError(msg) from e\n\n # ==================================================================\n # Table operations\n # ==================================================================\n def _get_primary_dataframe(self) -> DataFrame:\n \"\"\"Get the first DataFrame from input (handles both single and list inputs).\"\"\"\n if isinstance(self.df, list):\n return self.df[0].copy() if self.df else DataFrame()\n return self.df.copy()\n\n def _run_table_operation(self, operation: str) -> DataFrame:\n # Merge and Concatenate use their own inputs, not the primary df.\n if operation == \"Merge\":\n return self.merge_dataframes()\n if operation == \"Concatenate\":\n return self.concatenate_dataframes()\n\n df_copy = self._get_primary_dataframe()\n table_handlers = {\n \"Filter\": self.filter_rows_by_value,\n \"Sort\": self.sort_by_column,\n \"Drop Column\": self.drop_column,\n \"Rename Column\": self.rename_column,\n \"Add Column\": self.add_column,\n \"Select Columns\": self.select_columns,\n \"Head\": self.head,\n \"Tail\": self.tail,\n \"Replace Value\": self.replace_values,\n \"Drop Duplicates\": self.drop_duplicates,\n }\n handler = table_handlers.get(operation)\n if handler is None:\n msg = f\"Unsupported operation: {operation}\"\n logger.error(msg)\n raise ValueError(msg)\n return handler(df_copy)\n\n def filter_rows_by_value(self, df: DataFrame) -> DataFrame:\n column = df[self.column_name]\n filter_value = self.filter_value\n operator = getattr(self, \"filter_operator\", \"equals\")\n\n if operator == \"equals\":\n mask = column == filter_value\n elif operator == \"not equals\":\n mask = column != filter_value\n elif operator == \"contains\":\n mask = column.astype(str).str.contains(str(filter_value), na=False)\n elif operator == \"not contains\":\n mask = ~column.astype(str).str.contains(str(filter_value), na=False)\n elif operator == \"starts with\":\n mask = column.astype(str).str.startswith(str(filter_value), na=False)\n elif operator == \"ends with\":\n mask = column.astype(str).str.endswith(str(filter_value), na=False)\n elif operator == \"greater than\":\n try:\n numeric_value = pd.to_numeric(filter_value)\n mask = column > numeric_value\n except (ValueError, TypeError):\n mask = column.astype(str) > str(filter_value)\n elif operator == \"less than\":\n try:\n numeric_value = pd.to_numeric(filter_value)\n mask = column < numeric_value\n except (ValueError, TypeError):\n mask = column.astype(str) < str(filter_value)\n else:\n mask = column == filter_value\n\n return DataFrame(df[mask])\n\n def sort_by_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.sort_values(by=self.column_name, ascending=self.ascending))\n\n def drop_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.drop(columns=[self.column_name]))\n\n def rename_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.rename(columns={self.column_name: self.new_column_name}))\n\n def add_column(self, df: DataFrame) -> DataFrame:\n df[self.new_column_name] = [self.new_column_value] * len(df)\n return DataFrame(df)\n\n def select_columns(self, df: DataFrame) -> DataFrame:\n columns = [col.strip() for col in self.columns_to_select]\n return DataFrame(df[columns])\n\n def head(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.head(self.num_rows))\n\n def tail(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.tail(self.num_rows))\n\n def replace_values(self, df: DataFrame) -> DataFrame:\n df[self.column_name] = df[self.column_name].replace(self.replace_value, self.replacement_value)\n return DataFrame(df)\n\n def drop_duplicates(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.drop_duplicates(subset=self.column_name))\n\n def concatenate_dataframes(self) -> DataFrame:\n \"\"\"Concatenate multiple DataFrames vertically (stack rows).\"\"\"\n if not isinstance(self.df, list) or len(self.df) == 0:\n return self.df.copy() if self.df is not None else DataFrame()\n\n if len(self.df) == 1:\n return self.df[0].copy()\n\n concatenated = pd.concat(self.df, ignore_index=True)\n return DataFrame(concatenated)\n\n def merge_dataframes(self) -> DataFrame:\n \"\"\"Merge two DataFrames based on a common column (join operation).\"\"\"\n left_df = getattr(self, \"left_dataframe\", None)\n right_df = getattr(self, \"right_dataframe\", None)\n\n if left_df is None:\n return DataFrame()\n if right_df is None:\n return left_df.copy()\n\n df_left = left_df.copy()\n df_right = right_df.copy()\n\n merge_on = getattr(self, \"merge_on_column\", None)\n merge_how = getattr(self, \"merge_how\", \"inner\")\n\n if merge_on:\n if merge_on not in df_left.columns:\n msg = f\"Column '{merge_on}' not found in left DataFrame. Available: {list(df_left.columns)}\"\n raise ValueError(msg)\n if merge_on not in df_right.columns:\n msg = f\"Column '{merge_on}' not found in right DataFrame. Available: {list(df_right.columns)}\"\n raise ValueError(msg)\n merged = df_left.merge(df_right, on=merge_on, how=merge_how, suffixes=(\"\", \"_right\"))\n else:\n merged = df_left.merge(df_right, left_index=True, right_index=True, how=merge_how, suffixes=(\"\", \"_right\"))\n\n cols_to_drop = []\n for col in merged.columns:\n if col.endswith(\"_right\"):\n original_col = col[:-6]\n if original_col in merged.columns:\n merged[original_col] = merged[original_col].combine_first(merged[col])\n cols_to_drop.append(col)\n\n if cols_to_drop:\n merged = merged.drop(columns=cols_to_drop)\n\n return DataFrame(merged)\n\n # ==================================================================\n # Text operations\n # ==================================================================\n def _run_text_operation(self) -> Any:\n \"\"\"Process text based on the selected operation (Message/Text outputs).\"\"\"\n text = getattr(self, \"text_input\", \"\")\n operation = self._operation_name()\n\n # Allow empty text for Text Join (second input may have content).\n if not text and operation != \"Text Join\":\n return None\n\n text_handlers = {\n \"Case Conversion\": self._case_conversion,\n \"Text Replace\": self._text_replace,\n \"Text Extract\": self._text_extract,\n \"Text Head\": self._text_head,\n \"Text Tail\": self._text_tail,\n \"Text Strip\": self._text_strip,\n \"Text Join\": self._text_join,\n \"Text Clean\": self._text_clean,\n }\n handler = text_handlers.get(operation)\n if handler:\n return handler(text)\n return text\n\n def _word_count_data(self) -> Data:\n \"\"\"Word Count operation result as a Data object.\"\"\"\n result = self._word_count(getattr(self, \"text_input\", \"\") or \"\")\n return Data(data=result)\n\n def _word_count(self, text: str) -> dict[str, Any]:\n \"\"\"Count words, characters, and lines in text.\"\"\"\n result: dict[str, Any] = {}\n text_str = str(text) if text else \"\"\n is_empty = not text_str or not text_str.strip()\n\n if getattr(self, \"count_words\", True):\n if is_empty:\n result[\"word_count\"] = 0\n result[\"unique_words\"] = 0\n else:\n words = text_str.split()\n result[\"word_count\"] = len(words)\n result[\"unique_words\"] = len(set(words))\n\n if getattr(self, \"count_characters\", True):\n if is_empty:\n result[\"character_count\"] = 0\n result[\"character_count_no_spaces\"] = 0\n else:\n result[\"character_count\"] = len(text_str)\n result[\"character_count_no_spaces\"] = len(text_str.replace(\" \", \"\"))\n\n if getattr(self, \"count_lines\", True):\n if is_empty:\n result[\"line_count\"] = 0\n result[\"non_empty_lines\"] = 0\n else:\n lines = text_str.split(\"\\n\")\n result[\"line_count\"] = len(lines)\n result[\"non_empty_lines\"] = len([line for line in lines if line.strip()])\n\n return result\n\n def _text_to_dataframe(self, text: str) -> DataFrame:\n \"\"\"Convert markdown-style table text to a DataFrame.\"\"\"\n lines = [line.strip() for line in text.strip().split(\"\\n\") if line.strip()]\n if not lines:\n return DataFrame(pd.DataFrame())\n\n separator = getattr(self, \"table_separator\", \"|\")\n has_header = getattr(self, \"has_header\", True)\n\n rows = self._parse_table_rows(lines, separator)\n if not rows:\n return DataFrame(pd.DataFrame())\n\n df = self._create_dataframe(rows, has_header=has_header)\n self._convert_numeric_columns(df)\n self.log(f\"Converted text to DataFrame: {len(df)} rows, {len(df.columns)} columns\")\n return DataFrame(df)\n\n def _parse_table_rows(self, lines: list[str], separator: str) -> list[list[str]]:\n rows = []\n for line in lines:\n cleaned_line = line.strip(separator)\n cells = [cell.strip() for cell in cleaned_line.split(separator)]\n rows.append(cells)\n return rows\n\n def _create_dataframe(self, rows: list[list[str]], *, has_header: bool) -> pd.DataFrame:\n if has_header and len(rows) > 1:\n header = rows[0]\n data_rows = rows[1:]\n header_col_count = len(header)\n for i, row in enumerate(data_rows):\n row_col_count = len(row)\n if row_col_count != header_col_count:\n msg = (\n f\"Header mismatch: {header_col_count} column(s) in header vs \"\n f\"{row_col_count} column(s) in data row {i + 1}. \"\n \"Please ensure the header has the same number of columns as your data.\"\n )\n raise ValueError(msg)\n return pd.DataFrame(data_rows, columns=header)\n\n max_cols = max(len(row) for row in rows) if rows else 0\n columns = [f\"col_{i}\" for i in range(max_cols)]\n return pd.DataFrame(rows, columns=columns)\n\n def _convert_numeric_columns(self, df: pd.DataFrame) -> None:\n for col in df.columns:\n with contextlib.suppress(ValueError, TypeError):\n df[col] = pd.to_numeric(df[col])\n\n def _case_conversion(self, text: str) -> str:\n case_type = getattr(self, \"case_type\", \"lowercase\")\n converter = CASE_CONVERTERS.get(case_type)\n return converter(text) if converter else text\n\n def _text_replace(self, text: str) -> str:\n search_pattern = getattr(self, \"search_pattern\", \"\")\n if not search_pattern:\n return text\n replacement_text = getattr(self, \"replacement_text\", \"\")\n use_regex = getattr(self, \"use_regex\", False)\n if use_regex:\n try:\n return re.sub(search_pattern, replacement_text, text)\n except re.error as e:\n self.log(f\"Invalid regex pattern: {e}\")\n return text\n return text.replace(search_pattern, replacement_text)\n\n def _text_extract(self, text: str) -> list[str]:\n extract_pattern = getattr(self, \"extract_pattern\", \"\")\n if not extract_pattern:\n return []\n max_matches = getattr(self, \"max_matches\", 10)\n try:\n matches = re.findall(extract_pattern, text)\n except re.error as e:\n msg = f\"Invalid regex pattern '{extract_pattern}': {e}\"\n raise ValueError(msg) from e\n return matches[:max_matches] if max_matches > 0 else matches\n\n def _text_head(self, text: str) -> str:\n head_characters = getattr(self, \"head_characters\", 100)\n if head_characters < 0:\n msg = f\"Characters from Start must be a non-negative integer, got {head_characters}\"\n raise ValueError(msg)\n if head_characters == 0:\n return \"\"\n return text[:head_characters]\n\n def _text_tail(self, text: str) -> str:\n tail_characters = getattr(self, \"tail_characters\", 100)\n if tail_characters < 0:\n msg = f\"Characters from End must be a non-negative integer, got {tail_characters}\"\n raise ValueError(msg)\n if tail_characters == 0:\n return \"\"\n return text[-tail_characters:]\n\n def _text_strip(self, text: str) -> str:\n strip_mode = getattr(self, \"strip_mode\", \"both\")\n strip_characters = getattr(self, \"strip_characters\", \"\")\n text_str = str(text) if text else \"\"\n chars_to_strip = strip_characters if strip_characters else None\n if strip_mode == \"left\":\n return text_str.lstrip(chars_to_strip)\n if strip_mode == \"right\":\n return text_str.rstrip(chars_to_strip)\n return text_str.strip(chars_to_strip)\n\n def _text_join(self, text: str) -> str:\n text_input_2 = getattr(self, \"text_input_2\", \"\")\n text1 = str(text) if text else \"\"\n text2 = str(text_input_2) if text_input_2 else \"\"\n if text1 and text2:\n return f\"{text1}\\n{text2}\"\n return text1 or text2\n\n def _text_clean(self, text: str) -> str:\n result = text\n if getattr(self, \"remove_extra_spaces\", True):\n # Collapse runs of horizontal whitespace but preserve newlines so\n # that remove_empty_lines stays effective when both are enabled.\n result = re.sub(r\"[^\\S\\n]+\", \" \", result)\n if getattr(self, \"remove_special_chars\", False):\n result = re.sub(r\"[^\\w\\s]\", \"\", result)\n if getattr(self, \"remove_empty_lines\", False):\n lines = [line for line in result.split(\"\\n\") if line.strip()]\n result = \"\\n\".join(lines)\n return result\n\n def _format_result_as_text(self, result: Any) -> str:\n if result is None:\n return \"\"\n if isinstance(result, list):\n return \"\\n\".join(str(item) for item in result)\n return str(result)\n"+ "value": "\"\"\"Unified Operations component.\n\nBrings together the previously separate JSON, Table, and Text operation\ncomponents into a single component. An \"Input Type\" selector (Text / JSON /\nTable) drives everything: it filters the \"Operation\" picker to the operations\nthat apply to that type, reveals the matching input (Text / JSON / Table) and\nits operation-specific fields, and advertises the appropriate output type.\n\nThe three original components (JSON Operations, Table Operations, Text\nOperations) remain available as legacy components for backward compatibility\nwith existing flows.\n\"\"\"\n\nimport ast\nimport contextlib\nimport json\nimport re\nfrom typing import TYPE_CHECKING, Any\n\nimport pandas as pd\nfrom json_repair import repair_json\n\nfrom lfx.custom import Component\nfrom lfx.field_typing import RangeSpec\nfrom lfx.inputs import DictInput, SortableListInput, TabInput\nfrom lfx.io import (\n BoolInput,\n DataFrameInput,\n DataInput,\n DropdownInput,\n IntInput,\n MessageTextInput,\n MultilineInput,\n Output,\n StrInput,\n)\nfrom lfx.log.logger import logger\nfrom lfx.schema import Data\nfrom lfx.schema.dataframe import DataFrame\nfrom lfx.schema.dotdict import dotdict\nfrom lfx.schema.message import Message\nfrom lfx.utils.jq_security import validate_jq_program\n\nif TYPE_CHECKING:\n from collections.abc import Callable\n\n# The \"Input Type\" selector tabs. Each value maps a Langflow data type to the\n# operations, input, and output that belong to it.\nINPUT_TYPES = [\"Text\", \"JSON\", \"Table\"]\n\n# Operations grouped by input type, in display order, each with the icon shown\n# in the Operation picker. This is the single source of truth for the picker;\n# update_build_config swaps the picker's options to the selected type's list.\nOPERATIONS_BY_TYPE: dict[str, list[dict[str, str]]] = {\n \"Text\": [\n {\"name\": \"Word Count\", \"icon\": \"hash\"},\n {\"name\": \"Case Conversion\", \"icon\": \"type\"},\n {\"name\": \"Text Replace\", \"icon\": \"replace\"},\n {\"name\": \"Text Extract\", \"icon\": \"search\"},\n {\"name\": \"Text Head\", \"icon\": \"chevron-left\"},\n {\"name\": \"Text Tail\", \"icon\": \"chevron-right\"},\n {\"name\": \"Text Strip\", \"icon\": \"minus\"},\n {\"name\": \"Text Join\", \"icon\": \"link\"},\n {\"name\": \"Text Clean\", \"icon\": \"sparkles\"},\n {\"name\": \"Text to DataFrame\", \"icon\": \"table\"},\n ],\n \"JSON\": [\n {\"name\": \"Select Keys\", \"icon\": \"lasso-select\"},\n {\"name\": \"Literal Eval\", \"icon\": \"braces\"},\n {\"name\": \"Combine\", \"icon\": \"merge\"},\n {\"name\": \"Append or Update\", \"icon\": \"circle-plus\"},\n {\"name\": \"Remove Keys\", \"icon\": \"eraser\"},\n {\"name\": \"Rename Keys\", \"icon\": \"pencil-line\"},\n {\"name\": \"Path Selection\", \"icon\": \"mouse-pointer\"},\n {\"name\": \"JQ Expression\", \"icon\": \"terminal\"},\n ],\n \"Table\": [\n {\"name\": \"Add Column\", \"icon\": \"plus\"},\n {\"name\": \"Concatenate\", \"icon\": \"combine\"},\n {\"name\": \"Drop Column\", \"icon\": \"minus\"},\n {\"name\": \"Filter\", \"icon\": \"filter\"},\n {\"name\": \"Head\", \"icon\": \"arrow-up\"},\n {\"name\": \"Merge\", \"icon\": \"merge\"},\n {\"name\": \"Rename Column\", \"icon\": \"pencil\"},\n {\"name\": \"Replace Value\", \"icon\": \"replace\"},\n {\"name\": \"Select Columns\", \"icon\": \"columns\"},\n {\"name\": \"Sort\", \"icon\": \"arrow-up-down\"},\n {\"name\": \"Tail\", \"icon\": \"arrow-down\"},\n {\"name\": \"Drop Duplicates\", \"icon\": \"copy-x\"},\n ],\n}\n\n# Operation-name sets derived from the picker, used for dispatch and output\n# routing. Keeping them derived from OPERATIONS_BY_TYPE avoids any drift.\nJSON_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"JSON\"]}\nTABLE_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"Table\"]}\nTEXT_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"Text\"]}\n\n# Each input type maps to its main input field and its default output. \"Text\"\n# normally outputs a Message; \"JSON\" a Data; \"Table\" a DataFrame. A few text\n# operations override this (Word Count -> Data, Text to DataFrame -> DataFrame).\nINPUT_TYPE_TO_MAIN_INPUT = {\"Text\": \"text_input\", \"JSON\": \"data\", \"Table\": \"df\"}\n\n# Case conversions for the Text \"Case Conversion\" operation.\nCASE_CONVERTERS: dict[str, Any] = {\n \"uppercase\": str.upper,\n \"lowercase\": str.lower,\n \"title\": str.title,\n \"capitalize\": str.capitalize,\n \"swapcase\": str.swapcase,\n}\n\n\nclass OperationsComponent(Component):\n display_name = \"Data Operations\"\n description = \"Perform operations on Text, JSON, and Tables from a single component.\"\n documentation: str = \"https://docs.langflow.org/components-processing#operations\"\n icon = \"wand-sparkles\"\n name = \"Operations\"\n metadata = {\n \"keywords\": [\n \"operations\",\n \"data operations\",\n \"json\",\n \"json operations\",\n \"table\",\n \"table operations\",\n \"dataframe\",\n \"dataframe operations\",\n \"text\",\n \"text operations\",\n \"select keys\",\n \"literal eval\",\n \"combine\",\n \"append or update\",\n \"remove keys\",\n \"rename keys\",\n \"path selection\",\n \"jq expression\",\n \"parse json\",\n \"add column\",\n \"concatenate\",\n \"drop column\",\n \"filter\",\n \"head\",\n \"merge\",\n \"rename column\",\n \"replace value\",\n \"select columns\",\n \"sort\",\n \"tail\",\n \"drop duplicates\",\n \"word count\",\n \"case conversion\",\n \"text replace\",\n \"text extract\",\n \"text join\",\n \"text clean\",\n \"text to dataframe\",\n \"data manipulation\",\n \"data transformation\",\n ],\n }\n\n # Operation -> operation-specific input fields to reveal when selected.\n OPERATION_FIELDS: dict[str, list[str]] = {\n # JSON\n \"Select Keys\": [\"select_keys_input\"],\n \"Literal Eval\": [],\n \"Combine\": [],\n \"Append or Update\": [\"append_update_data\"],\n \"Remove Keys\": [\"remove_keys_input\"],\n \"Rename Keys\": [\"rename_keys_input\"],\n \"Path Selection\": [\"mapped_json_display\", \"selected_key\"],\n \"JQ Expression\": [\"query\"],\n # Table\n \"Add Column\": [\"new_column_name\", \"new_column_value\"],\n \"Concatenate\": [],\n \"Drop Column\": [\"column_name\"],\n \"Filter\": [\"column_name\", \"filter_value\", \"filter_operator\"],\n \"Head\": [\"num_rows\"],\n \"Merge\": [\"left_dataframe\", \"right_dataframe\", \"merge_on_column\", \"merge_how\"],\n \"Rename Column\": [\"column_name\", \"new_column_name\"],\n \"Replace Value\": [\"column_name\", \"replace_value\", \"replacement_value\"],\n \"Select Columns\": [\"columns_to_select\"],\n \"Sort\": [\"column_name\", \"ascending\"],\n \"Tail\": [\"num_rows\"],\n \"Drop Duplicates\": [\"column_name\"],\n # Text\n \"Word Count\": [\"count_words\", \"count_characters\", \"count_lines\"],\n \"Case Conversion\": [\"case_type\"],\n \"Text Replace\": [\"search_pattern\", \"replacement_text\", \"use_regex\"],\n \"Text Extract\": [\"extract_pattern\", \"max_matches\"],\n \"Text Head\": [\"head_characters\"],\n \"Text Tail\": [\"tail_characters\"],\n \"Text Strip\": [\"strip_mode\", \"strip_characters\"],\n \"Text Join\": [\"text_input_2\"],\n \"Text Clean\": [\"remove_extra_spaces\", \"remove_special_chars\", \"remove_empty_lines\"],\n \"Text to DataFrame\": [\"table_separator\", \"has_header\"],\n }\n\n # The three main inputs (one per data type). They are never treated as\n # operation-specific fields; the input-type selector toggles them.\n MAIN_INPUTS = (\"text_input\", \"data\", \"df\")\n\n # Every operation-specific field (union of all the lists above), used to\n # hide and reset fields whenever the input type or operation changes.\n ALL_OPERATION_FIELDS: list[str] = [\n # JSON\n \"select_keys_input\",\n \"append_update_data\",\n \"remove_keys_input\",\n \"rename_keys_input\",\n \"mapped_json_display\",\n \"selected_key\",\n \"query\",\n # Table\n \"column_name\",\n \"filter_value\",\n \"filter_operator\",\n \"ascending\",\n \"new_column_name\",\n \"new_column_value\",\n \"columns_to_select\",\n \"num_rows\",\n \"replace_value\",\n \"replacement_value\",\n \"left_dataframe\",\n \"right_dataframe\",\n \"merge_on_column\",\n \"merge_how\",\n # Text\n \"table_separator\",\n \"has_header\",\n \"count_words\",\n \"count_characters\",\n \"count_lines\",\n \"case_type\",\n \"use_regex\",\n \"search_pattern\",\n \"replacement_text\",\n \"extract_pattern\",\n \"max_matches\",\n \"head_characters\",\n \"tail_characters\",\n \"strip_mode\",\n \"strip_characters\",\n \"text_input_2\",\n \"remove_extra_spaces\",\n \"remove_special_chars\",\n \"remove_empty_lines\",\n ]\n\n # Defaults applied to the JSON operation fields when the operation changes,\n # mirroring the JSON Operations component's reset behavior.\n OPERATION_FIELD_DEFAULTS: dict[str, Any] = {\n \"select_keys_input\": [],\n \"append_update_data\": {\"key\": \"value\"},\n \"remove_keys_input\": [],\n \"rename_keys_input\": {\"old_key\": \"new_key\"},\n \"mapped_json_display\": \"\",\n \"selected_key\": None,\n \"query\": \"\",\n }\n\n inputs = [\n # --- Input type selector: drives operations, input, and output ---\n TabInput(\n name=\"input_type\",\n display_name=\"Input Type\",\n options=INPUT_TYPES,\n value=\"Text\",\n info=\"Select the type of input to operate on.\",\n real_time_refresh=True,\n ),\n # --- Main inputs: one per data type, shown contextually ---\n MultilineInput(\n name=\"text_input\",\n display_name=\"Text\",\n info=\"The input text to process.\",\n show=True,\n ),\n DataInput(\n name=\"data\",\n display_name=\"JSON\",\n info=\"The JSON / Data object to operate on.\",\n is_list=True,\n show=False,\n ),\n DataFrameInput(\n name=\"df\",\n display_name=\"Table\",\n info=\"The input Table to operate on. Connect multiple Tables for merge or concatenate operations.\",\n is_list=True,\n show=False,\n ),\n # --- Operation picker (options are filtered by Input Type) ---\n SortableListInput(\n name=\"operation\",\n display_name=\"Operation\",\n placeholder=\"Select Operation\",\n info=\"Select the operation to perform. The matching fields and output appear once you choose one.\",\n options=OPERATIONS_BY_TYPE[\"Text\"],\n real_time_refresh=True,\n limit=1,\n ),\n # --- JSON operation fields ---\n MessageTextInput(\n name=\"select_keys_input\",\n display_name=\"Select Keys\",\n info=\"List of keys to select from the data. Only top-level keys can be selected.\",\n show=False,\n is_list=True,\n value=[],\n ),\n DictInput(\n name=\"append_update_data\",\n display_name=\"Append or Update\",\n info=\"Data to append or update the existing data with. Only top-level keys are checked.\",\n show=False,\n value={\"key\": \"value\"},\n is_list=True,\n ),\n MessageTextInput(\n name=\"remove_keys_input\",\n display_name=\"Remove Keys\",\n info=\"List of keys to remove from the data.\",\n show=False,\n is_list=True,\n value=[],\n ),\n DictInput(\n name=\"rename_keys_input\",\n display_name=\"Rename Keys\",\n info=\"List of keys to rename in the data.\",\n show=False,\n is_list=True,\n value={\"old_key\": \"new_key\"},\n ),\n MultilineInput(\n name=\"mapped_json_display\",\n display_name=\"JSON to Map\",\n info=\"Paste or preview your JSON here to explore its structure and select a path for extraction.\",\n required=False,\n refresh_button=True,\n real_time_refresh=True,\n placeholder=\"Add a JSON example.\",\n show=False,\n ),\n DropdownInput(\n name=\"selected_key\",\n display_name=\"Select Path\",\n options=[],\n required=False,\n dynamic=True,\n show=False,\n value=None,\n ),\n MessageTextInput(\n name=\"query\",\n display_name=\"JQ Expression\",\n info=\"JSON Query to filter the data. Used by Path Selection and JQ Expression operations.\",\n placeholder=\"e.g., .properties.id\",\n show=False,\n ),\n # --- Table operation fields ---\n StrInput(\n name=\"column_name\",\n display_name=\"Column Name\",\n info=\"The column name to use for the operation.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"filter_value\",\n display_name=\"Filter Value\",\n info=\"The value to filter rows by.\",\n dynamic=True,\n show=False,\n ),\n DropdownInput(\n name=\"filter_operator\",\n display_name=\"Filter Operator\",\n options=[\n \"equals\",\n \"not equals\",\n \"contains\",\n \"not contains\",\n \"starts with\",\n \"ends with\",\n \"greater than\",\n \"less than\",\n ],\n value=\"equals\",\n info=\"The operator to apply for filtering rows.\",\n advanced=False,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"ascending\",\n display_name=\"Sort Ascending\",\n info=\"Whether to sort in ascending order.\",\n dynamic=True,\n show=False,\n value=True,\n ),\n StrInput(\n name=\"new_column_name\",\n display_name=\"New Column Name\",\n info=\"The new column name when renaming or adding a column.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"new_column_value\",\n display_name=\"New Column Value\",\n info=\"The value to populate the new column with.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"columns_to_select\",\n display_name=\"Columns to Select\",\n dynamic=True,\n is_list=True,\n show=False,\n ),\n IntInput(\n name=\"num_rows\",\n display_name=\"Number of Rows\",\n info=\"Number of rows to return (for head/tail).\",\n dynamic=True,\n show=False,\n value=5,\n ),\n MessageTextInput(\n name=\"replace_value\",\n display_name=\"Value to Replace\",\n info=\"The value to replace in the column.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"replacement_value\",\n display_name=\"Replacement Value\",\n info=\"The value to replace with.\",\n dynamic=True,\n show=False,\n ),\n DataFrameInput(\n name=\"left_dataframe\",\n display_name=\"Left Table\",\n info=\"The left (primary) Table for merge operations. \"\n \"In a left merge, all rows from this table are preserved.\",\n dynamic=True,\n show=False,\n ),\n DataFrameInput(\n name=\"right_dataframe\",\n display_name=\"Right Table\",\n info=\"The right (secondary) Table for merge operations. \"\n \"In a right merge, all rows from this table are preserved.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"merge_on_column\",\n display_name=\"Merge On Column\",\n info=\"The column name to merge Tables on. Must exist in both Tables.\",\n dynamic=True,\n show=False,\n ),\n DropdownInput(\n name=\"merge_how\",\n display_name=\"Merge Type\",\n options=[\"inner\", \"outer\", \"left\", \"right\"],\n value=\"inner\",\n info=\"Type of merge: inner (intersection), outer (union), left, or right.\",\n dynamic=True,\n show=False,\n ),\n # --- Text operation fields ---\n StrInput(\n name=\"table_separator\",\n display_name=\"Table Separator\",\n info=\"Separator used in the table (default: '|').\",\n value=\"|\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"has_header\",\n display_name=\"Has Header\",\n info=\"Whether the table has a header row.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_words\",\n display_name=\"Count Words\",\n info=\"Include word count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_characters\",\n display_name=\"Count Characters\",\n info=\"Include character count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_lines\",\n display_name=\"Count Lines\",\n info=\"Include line count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n DropdownInput(\n name=\"case_type\",\n display_name=\"Case Type\",\n options=[\"uppercase\", \"lowercase\", \"title\", \"capitalize\", \"swapcase\"],\n value=\"lowercase\",\n info=\"Type of case conversion to apply.\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"use_regex\",\n display_name=\"Use Regex\",\n info=\"Whether to treat search pattern as regex.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"search_pattern\",\n display_name=\"Search Pattern\",\n info=\"Text pattern to search for (supports regex).\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"replacement_text\",\n display_name=\"Replacement Text\",\n info=\"Text to replace the search pattern with.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"extract_pattern\",\n display_name=\"Extract Pattern\",\n info=\"Regex pattern to extract from text.\",\n dynamic=True,\n show=False,\n ),\n IntInput(\n name=\"max_matches\",\n display_name=\"Max Matches\",\n info=\"Maximum number of matches to extract.\",\n value=10,\n dynamic=True,\n show=False,\n ),\n IntInput(\n name=\"head_characters\",\n display_name=\"Characters from Start\",\n info=\"Number of characters to extract from the beginning of text. Must be non-negative.\",\n value=100,\n dynamic=True,\n show=False,\n range_spec=RangeSpec(min=0, max=1000000, step=1, step_type=\"int\"),\n ),\n IntInput(\n name=\"tail_characters\",\n display_name=\"Characters from End\",\n info=\"Number of characters to extract from the end of text. Must be non-negative.\",\n value=100,\n dynamic=True,\n show=False,\n range_spec=RangeSpec(min=0, max=1000000, step=1, step_type=\"int\"),\n ),\n DropdownInput(\n name=\"strip_mode\",\n display_name=\"Strip Mode\",\n options=[\"both\", \"left\", \"right\"],\n value=\"both\",\n info=\"Which sides to strip whitespace from.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"strip_characters\",\n display_name=\"Characters to Strip\",\n info=\"Specific characters to remove (leave empty for whitespace).\",\n value=\"\",\n dynamic=True,\n show=False,\n ),\n MultilineInput(\n name=\"text_input_2\",\n display_name=\"Second Text Input\",\n info=\"Second text to join with the first text.\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_extra_spaces\",\n display_name=\"Remove Extra Spaces\",\n info=\"Remove multiple consecutive spaces.\",\n value=True,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_special_chars\",\n display_name=\"Remove Special Characters\",\n info=\"Remove special characters except alphanumeric and spaces.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_empty_lines\",\n display_name=\"Remove Empty Lines\",\n info=\"Remove empty lines from text.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n ]\n\n # Default output matches the default Input Type (\"Text\" -> Message).\n # update_outputs / update_frontend_node narrow it to the selected type and\n # operation.\n outputs = [Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\")]\n\n # ------------------------------------------------------------------\n # Operation routing helpers\n # ------------------------------------------------------------------\n @staticmethod\n def _extract_operation_name(field_value: Any) -> str:\n \"\"\"Extract the operation name from a SortableListInput value.\"\"\"\n if isinstance(field_value, list) and len(field_value) > 0 and isinstance(field_value[0], dict):\n return field_value[0].get(\"name\", \"\")\n if isinstance(field_value, str):\n return field_value\n return \"\"\n\n def _operation_name(self) -> str:\n \"\"\"Get the currently selected operation name.\"\"\"\n return self._extract_operation_name(getattr(self, \"operation\", []))\n\n @staticmethod\n def _default_output_for_type(input_type: str) -> Output:\n \"\"\"Return the output advertised for an input type when no operation is selected yet.\"\"\"\n if input_type == \"JSON\":\n return Output(display_name=\"JSON\", name=\"data_output\", method=\"as_data\")\n if input_type == \"Table\":\n return Output(display_name=\"Table\", name=\"dataframe_output\", method=\"as_dataframe\")\n return Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\")\n\n # ------------------------------------------------------------------\n # Dynamic UI\n # ------------------------------------------------------------------\n def _reset_operation_fields(self, build_config: dotdict) -> None:\n \"\"\"Hide every operation-specific field and restore its default value.\"\"\"\n for field in self.ALL_OPERATION_FIELDS:\n if field in build_config:\n build_config[field][\"show\"] = False\n if field in self.OPERATION_FIELD_DEFAULTS:\n build_config[field][\"value\"] = self.OPERATION_FIELD_DEFAULTS[field]\n\n def _show_main_input(self, build_config: dotdict, input_type: str, operation: str) -> None:\n \"\"\"Show only the main input that matches the input type; hide the others.\"\"\"\n for inp in self.MAIN_INPUTS:\n if inp in build_config:\n build_config[inp][\"show\"] = False\n build_config[inp][\"required\"] = False\n\n main_input = INPUT_TYPE_TO_MAIN_INPUT.get(input_type)\n if main_input and main_input in build_config:\n build_config[main_input][\"show\"] = True\n build_config[main_input][\"required\"] = True\n # The JSON \"Combine\" operation consumes a list of Data objects.\n if main_input == \"data\":\n build_config[\"data\"][\"is_list\"] = operation == \"Combine\"\n\n def update_build_config(self, build_config: dotdict, field_value: Any, field_name: str | None = None) -> dotdict:\n # Path Selection: refresh the available JSON paths from the pasted JSON.\n if field_name == \"mapped_json_display\":\n try:\n parsed_json = json.loads(field_value)\n keys = self.extract_all_paths(parsed_json)\n build_config[\"selected_key\"][\"options\"] = keys\n build_config[\"selected_key\"][\"show\"] = True\n except (json.JSONDecodeError, TypeError, ValueError) as e:\n logger.error(f\"Error parsing mapped JSON: {e}\")\n build_config[\"selected_key\"][\"show\"] = False\n return build_config\n\n # Input type changed: swap the operation list, clear the selection, and\n # show only the matching input. No operation-specific fields are shown\n # until an operation is picked.\n if field_name == \"input_type\":\n input_type = field_value if field_value in OPERATIONS_BY_TYPE else \"Text\"\n build_config[\"operation\"][\"options\"] = OPERATIONS_BY_TYPE[input_type]\n build_config[\"operation\"][\"value\"] = []\n self._reset_operation_fields(build_config)\n self._show_main_input(build_config, input_type, operation=\"\")\n return build_config\n\n # Operation changed: reset fields, show the input for the current type,\n # then reveal the operation-specific fields.\n if field_name == \"operation\":\n operation = self._extract_operation_name(field_value)\n self._reset_operation_fields(build_config)\n\n input_type = build_config.get(\"input_type\", {}).get(\"value\", \"Text\")\n self._show_main_input(build_config, input_type, operation)\n\n for field in self.OPERATION_FIELDS.get(operation, []):\n if field in build_config:\n build_config[field][\"show\"] = True\n\n return build_config\n\n return build_config\n\n def update_outputs(self, frontend_node: dict, field_name: str, field_value: Any) -> dict:\n \"\"\"Create the output(s) appropriate to the selected input type and operation.\"\"\"\n if field_name == \"input_type\":\n # Switching type clears the operation; advertise the type's default.\n input_type = field_value if field_value in OPERATIONS_BY_TYPE else \"Text\"\n frontend_node[\"outputs\"] = [self._default_output_for_type(input_type)]\n return frontend_node\n\n template = frontend_node.get(\"template\", {})\n input_type = template.get(\"input_type\", {}).get(\"value\", \"Text\")\n\n if field_name == \"operation\":\n operation = self._extract_operation_name(field_value)\n else:\n # Any other refresh (e.g. Path Selection's \"JSON to Map\" field)\n # reaches here on a freshly rebuilt node whose outputs were reset\n # to the class default (Message). Re-derive the output from the\n # saved operation so the refresh doesn't swap the real output type.\n operation = self._extract_operation_name(template.get(\"operation\", {}).get(\"value\", []))\n\n if not operation:\n # No operation selected: fall back to the input type's default output.\n frontend_node[\"outputs\"] = [self._default_output_for_type(input_type)]\n return frontend_node\n\n frontend_node[\"outputs\"] = []\n if operation in JSON_OPERATIONS or operation == \"Word Count\":\n frontend_node[\"outputs\"].append(Output(display_name=\"JSON\", name=\"data_output\", method=\"as_data\"))\n elif operation in TABLE_OPERATIONS or operation == \"Text to DataFrame\":\n frontend_node[\"outputs\"].append(\n Output(display_name=\"Table\", name=\"dataframe_output\", method=\"as_dataframe\")\n )\n elif operation == \"Text Join\":\n frontend_node[\"outputs\"].append(Output(display_name=\"Text\", name=\"text_output\", method=\"as_text\"))\n frontend_node[\"outputs\"].append(Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\"))\n else:\n frontend_node[\"outputs\"].append(Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\"))\n\n return frontend_node\n\n async def update_frontend_node(self, new_frontend_node: dict, current_frontend_node: dict) -> dict:\n \"\"\"Keep the operation options and outputs in sync with the saved input type on load.\"\"\"\n await super().update_frontend_node(new_frontend_node, current_frontend_node)\n\n template = new_frontend_node.get(\"template\", {})\n input_type = template.get(\"input_type\", {}).get(\"value\", \"Text\")\n if input_type not in OPERATIONS_BY_TYPE:\n input_type = \"Text\"\n\n # Filter the operation picker to the saved input type.\n if \"operation\" in template:\n template[\"operation\"][\"options\"] = OPERATIONS_BY_TYPE[input_type]\n\n # Re-derive the outputs from the saved input type + operation.\n operation_value = template.get(\"operation\", {}).get(\"value\", [])\n if self._extract_operation_name(operation_value):\n self.update_outputs(new_frontend_node, \"operation\", operation_value)\n else:\n self.update_outputs(new_frontend_node, \"input_type\", input_type)\n\n return new_frontend_node\n\n # ==================================================================\n # Output methods (referenced by update_outputs)\n # ==================================================================\n def as_data(self) -> Data:\n \"\"\"JSON-typed output: JSON operations and Word Count.\"\"\"\n operation = self._operation_name()\n if operation in JSON_OPERATIONS:\n handler = self._json_handlers().get(operation)\n if handler:\n try:\n return handler()\n except Exception as e:\n logger.error(f\"Error executing {operation}: {e!s}\")\n raise\n if operation == \"Word Count\":\n return self._word_count_data()\n return Data(data={})\n\n def as_dataframe(self) -> DataFrame:\n \"\"\"Table-typed output: Table operations and Text to DataFrame.\"\"\"\n operation = self._operation_name()\n if operation in TABLE_OPERATIONS:\n return self._run_table_operation(operation)\n if operation == \"Text to DataFrame\":\n return self._text_to_dataframe(getattr(self, \"text_input\", \"\") or \"\")\n return DataFrame(pd.DataFrame())\n\n def as_message(self) -> Message:\n \"\"\"Message-typed output: generic text operations (and Text Join).\"\"\"\n return Message(text=self._format_result_as_text(self._run_text_operation()))\n\n def as_text(self) -> Message:\n \"\"\"Text output for the Text Join operation.\"\"\"\n return self.as_message()\n\n # ==================================================================\n # JSON operations\n # ==================================================================\n @staticmethod\n def extract_all_paths(obj, path=\"\"):\n paths = []\n if isinstance(obj, dict):\n for k, v in obj.items():\n new_path = f\"{path}.{k}\" if path else f\".{k}\"\n paths.append(new_path)\n paths.extend(OperationsComponent.extract_all_paths(v, new_path))\n elif isinstance(obj, list) and obj:\n new_path = f\"{path}[0]\"\n paths.append(new_path)\n paths.extend(OperationsComponent.extract_all_paths(obj[0], new_path))\n return paths\n\n @staticmethod\n def remove_keys_recursive(obj, keys_to_remove):\n if isinstance(obj, dict):\n return {\n k: OperationsComponent.remove_keys_recursive(v, keys_to_remove)\n for k, v in obj.items()\n if k not in keys_to_remove\n }\n if isinstance(obj, list):\n return [OperationsComponent.remove_keys_recursive(item, keys_to_remove) for item in obj]\n return obj\n\n @staticmethod\n def rename_keys_recursive(obj, rename_map):\n if isinstance(obj, dict):\n return {\n rename_map.get(k, k): OperationsComponent.rename_keys_recursive(v, rename_map) for k, v in obj.items()\n }\n if isinstance(obj, list):\n return [OperationsComponent.rename_keys_recursive(item, rename_map) for item in obj]\n return obj\n\n def _json_handlers(self) -> \"dict[str, Callable[[], Data]]\":\n return {\n \"Select Keys\": self.select_keys,\n \"Literal Eval\": self.evaluate_data,\n \"Combine\": self.combine_data,\n \"Append or Update\": self.append_update,\n \"Remove Keys\": self.remove_keys,\n \"Rename Keys\": self.rename_keys,\n \"Path Selection\": self.json_path,\n \"JQ Expression\": self.json_query,\n }\n\n def get_data_dict(self) -> dict:\n \"\"\"Extract data dictionary from Data object.\"\"\"\n data = self.data[0] if isinstance(self.data, list) and len(self.data) == 1 else self.data\n return data.model_dump()\n\n def get_normalized_data(self) -> dict:\n \"\"\"Get normalized data dictionary, handling the 'data' key if present.\"\"\"\n data_dict = self.get_data_dict()\n return data_dict.get(\"data\", data_dict)\n\n def data_is_list(self) -> bool:\n \"\"\"Check if data contains multiple items.\"\"\"\n return isinstance(self.data, list) and len(self.data) > 1\n\n def validate_single_data(self, operation: str) -> None:\n \"\"\"Validate that the operation is being performed on a single data object.\"\"\"\n if self.data_is_list():\n msg = f\"{operation} operation is not supported for multiple data objects.\"\n raise ValueError(msg)\n\n def select_keys(self) -> Data:\n \"\"\"Select specific keys from the data dictionary.\"\"\"\n self.validate_single_data(\"Select Keys\")\n data_dict = self.get_normalized_data()\n filter_criteria: list[str] = self.select_keys_input\n\n if len(filter_criteria) == 1 and filter_criteria[0] == \"data\":\n filtered = data_dict[\"data\"]\n else:\n if not all(key in data_dict for key in filter_criteria):\n msg = f\"Select key not found in data. Available keys: {list(data_dict.keys())}\"\n raise ValueError(msg)\n filtered = {key: value for key, value in data_dict.items() if key in filter_criteria}\n\n return Data(data=filtered)\n\n def remove_keys(self) -> Data:\n \"\"\"Remove specified keys from the data dictionary, recursively.\"\"\"\n self.validate_single_data(\"Remove Keys\")\n data_dict = self.get_normalized_data()\n remove_keys_input: list[str] = self.remove_keys_input\n filtered = OperationsComponent.remove_keys_recursive(data_dict, set(remove_keys_input))\n return Data(data=filtered)\n\n def rename_keys(self) -> Data:\n \"\"\"Rename keys in the data dictionary, recursively.\"\"\"\n self.validate_single_data(\"Rename Keys\")\n data_dict = self.get_normalized_data()\n rename_keys_input: dict[str, str] = self.rename_keys_input\n renamed = OperationsComponent.rename_keys_recursive(data_dict, rename_keys_input)\n return Data(data=renamed)\n\n def recursive_eval(self, data: Any) -> Any:\n \"\"\"Recursively evaluate string values that look like Python literals.\"\"\"\n if isinstance(data, dict):\n return {k: self.recursive_eval(v) for k, v in data.items()}\n if isinstance(data, list):\n return [self.recursive_eval(item) for item in data]\n if isinstance(data, str):\n try:\n if (\n data.strip().startswith((\"{\", \"[\", \"(\", \"'\", '\"'))\n or data.strip().lower() in (\"true\", \"false\", \"none\")\n or data.strip().replace(\".\", \"\").isdigit()\n ):\n return ast.literal_eval(data)\n except (ValueError, SyntaxError, TypeError, MemoryError):\n return data\n else:\n return data\n return data\n\n def evaluate_data(self) -> Data:\n \"\"\"Evaluate string values in the data dictionary.\"\"\"\n self.validate_single_data(\"Literal Eval\")\n logger.info(\"evaluating data\")\n return Data(**self.recursive_eval(self.get_data_dict()))\n\n def combine_data(self) -> Data:\n \"\"\"Combine multiple data objects into one.\"\"\"\n logger.info(\"combining data\")\n if not self.data_is_list():\n return self.data[0] if self.data else Data(data={})\n\n data_dicts = [data.model_dump().get(\"data\", data.model_dump()) for data in self.data]\n combined_data: dict[str, Any] = {}\n\n for data_dict in data_dicts:\n for key, value in data_dict.items():\n if key not in combined_data:\n combined_data[key] = value\n elif isinstance(combined_data[key], list):\n if isinstance(value, list):\n combined_data[key].extend(value)\n else:\n combined_data[key].append(value)\n else:\n combined_data[key] = (\n [combined_data[key], value] if not isinstance(value, list) else [combined_data[key], *value]\n )\n\n return Data(**combined_data)\n\n def append_update(self) -> Data:\n \"\"\"Append or update the data with new key-value pairs.\"\"\"\n self.validate_single_data(\"Append or Update\")\n data_filtered = self.get_normalized_data()\n for key, value in self.append_update_data.items():\n data_filtered[key] = value\n return Data(**data_filtered)\n\n def json_path(self) -> Data:\n \"\"\"Extract a value from the data using the selected JQ path.\"\"\"\n try:\n import jq\n except ImportError:\n msg = \"jq is required for Path Selection. Install with: pip install jq\"\n raise ImportError(msg) from None\n\n try:\n if not self.data or not self.selected_key:\n msg = \"Missing input data or selected key.\"\n raise ValueError(msg)\n input_payload = self.data[0].data if isinstance(self.data, list) else self.data.data\n validate_jq_program(self.selected_key)\n compiled = jq.compile(self.selected_key)\n result = compiled.input(input_payload).first()\n if isinstance(result, dict):\n return Data(data=result)\n return Data(data={\"result\": result})\n except (ValueError, TypeError, KeyError) as e:\n self.status = f\"Error: {e!s}\"\n self.log(self.status)\n return Data(data={\"error\": str(e)})\n\n def json_query(self) -> Data:\n \"\"\"Run a JQ expression against the data.\"\"\"\n try:\n import jq\n except ImportError:\n msg = \"jq is required for JQ Expression. Install with: pip install jq\"\n raise ImportError(msg) from None\n\n if not self.query or not self.query.strip():\n msg = \"JSON Query is required and cannot be blank.\"\n raise ValueError(msg)\n raw_data = self.get_data_dict()\n try:\n input_str = json.dumps(raw_data)\n repaired = repair_json(input_str)\n data_json = json.loads(repaired)\n jq_input = data_json[\"data\"] if isinstance(data_json, dict) and \"data\" in data_json else data_json\n validate_jq_program(self.query)\n results = jq.compile(self.query).input(jq_input).all()\n if not results:\n msg = \"No result from JSON query.\"\n raise ValueError(msg)\n result = results[0] if len(results) == 1 else results\n if result is None or result == \"None\":\n msg = \"JSON query returned null/None. Check if the path exists in your data.\"\n raise ValueError(msg)\n if isinstance(result, dict):\n return Data(data=result)\n return Data(data={\"result\": result})\n except (ValueError, TypeError, KeyError, json.JSONDecodeError) as e:\n logger.error(f\"JSON Query failed: {e}\")\n msg = f\"JSON Query error: {e}\"\n raise ValueError(msg) from e\n\n # ==================================================================\n # Table operations\n # ==================================================================\n def _get_primary_dataframe(self) -> DataFrame:\n \"\"\"Get the first DataFrame from input (handles both single and list inputs).\"\"\"\n if isinstance(self.df, list):\n return self.df[0].copy() if self.df else DataFrame()\n return self.df.copy()\n\n def _run_table_operation(self, operation: str) -> DataFrame:\n # Merge and Concatenate use their own inputs, not the primary df.\n if operation == \"Merge\":\n return self.merge_dataframes()\n if operation == \"Concatenate\":\n return self.concatenate_dataframes()\n\n df_copy = self._get_primary_dataframe()\n table_handlers = {\n \"Filter\": self.filter_rows_by_value,\n \"Sort\": self.sort_by_column,\n \"Drop Column\": self.drop_column,\n \"Rename Column\": self.rename_column,\n \"Add Column\": self.add_column,\n \"Select Columns\": self.select_columns,\n \"Head\": self.head,\n \"Tail\": self.tail,\n \"Replace Value\": self.replace_values,\n \"Drop Duplicates\": self.drop_duplicates,\n }\n handler = table_handlers.get(operation)\n if handler is None:\n msg = f\"Unsupported operation: {operation}\"\n logger.error(msg)\n raise ValueError(msg)\n return handler(df_copy)\n\n def filter_rows_by_value(self, df: DataFrame) -> DataFrame:\n column = df[self.column_name]\n filter_value = self.filter_value\n operator = getattr(self, \"filter_operator\", \"equals\")\n\n if operator == \"equals\":\n mask = column == filter_value\n elif operator == \"not equals\":\n mask = column != filter_value\n elif operator == \"contains\":\n mask = column.astype(str).str.contains(str(filter_value), na=False)\n elif operator == \"not contains\":\n mask = ~column.astype(str).str.contains(str(filter_value), na=False)\n elif operator == \"starts with\":\n mask = column.astype(str).str.startswith(str(filter_value), na=False)\n elif operator == \"ends with\":\n mask = column.astype(str).str.endswith(str(filter_value), na=False)\n elif operator == \"greater than\":\n try:\n numeric_value = pd.to_numeric(filter_value)\n mask = column > numeric_value\n except (ValueError, TypeError):\n mask = column.astype(str) > str(filter_value)\n elif operator == \"less than\":\n try:\n numeric_value = pd.to_numeric(filter_value)\n mask = column < numeric_value\n except (ValueError, TypeError):\n mask = column.astype(str) < str(filter_value)\n else:\n mask = column == filter_value\n\n return DataFrame(df[mask])\n\n def sort_by_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.sort_values(by=self.column_name, ascending=self.ascending))\n\n def drop_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.drop(columns=[self.column_name]))\n\n def rename_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.rename(columns={self.column_name: self.new_column_name}))\n\n def add_column(self, df: DataFrame) -> DataFrame:\n df[self.new_column_name] = [self.new_column_value] * len(df)\n return DataFrame(df)\n\n def select_columns(self, df: DataFrame) -> DataFrame:\n columns = [col.strip() for col in self.columns_to_select]\n return DataFrame(df[columns])\n\n def head(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.head(self.num_rows))\n\n def tail(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.tail(self.num_rows))\n\n def replace_values(self, df: DataFrame) -> DataFrame:\n df[self.column_name] = df[self.column_name].replace(self.replace_value, self.replacement_value)\n return DataFrame(df)\n\n def drop_duplicates(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.drop_duplicates(subset=self.column_name))\n\n def concatenate_dataframes(self) -> DataFrame:\n \"\"\"Concatenate multiple DataFrames vertically (stack rows).\"\"\"\n if not isinstance(self.df, list) or len(self.df) == 0:\n return self.df.copy() if self.df is not None else DataFrame()\n\n if len(self.df) == 1:\n return self.df[0].copy()\n\n concatenated = pd.concat(self.df, ignore_index=True)\n return DataFrame(concatenated)\n\n def merge_dataframes(self) -> DataFrame:\n \"\"\"Merge two DataFrames based on a common column (join operation).\"\"\"\n left_df = getattr(self, \"left_dataframe\", None)\n right_df = getattr(self, \"right_dataframe\", None)\n\n if left_df is None:\n return DataFrame()\n if right_df is None:\n return left_df.copy()\n\n df_left = left_df.copy()\n df_right = right_df.copy()\n\n merge_on = getattr(self, \"merge_on_column\", None)\n merge_how = getattr(self, \"merge_how\", \"inner\")\n\n if merge_on:\n if merge_on not in df_left.columns:\n msg = f\"Column '{merge_on}' not found in left DataFrame. Available: {list(df_left.columns)}\"\n raise ValueError(msg)\n if merge_on not in df_right.columns:\n msg = f\"Column '{merge_on}' not found in right DataFrame. Available: {list(df_right.columns)}\"\n raise ValueError(msg)\n merged = df_left.merge(df_right, on=merge_on, how=merge_how, suffixes=(\"\", \"_right\"))\n else:\n merged = df_left.merge(df_right, left_index=True, right_index=True, how=merge_how, suffixes=(\"\", \"_right\"))\n\n cols_to_drop = []\n for col in merged.columns:\n if col.endswith(\"_right\"):\n original_col = col[:-6]\n if original_col in merged.columns:\n merged[original_col] = merged[original_col].combine_first(merged[col])\n cols_to_drop.append(col)\n\n if cols_to_drop:\n merged = merged.drop(columns=cols_to_drop)\n\n return DataFrame(merged)\n\n # ==================================================================\n # Text operations\n # ==================================================================\n def _run_text_operation(self) -> Any:\n \"\"\"Process text based on the selected operation (Message/Text outputs).\"\"\"\n text = getattr(self, \"text_input\", \"\")\n operation = self._operation_name()\n\n # Allow empty text for Text Join (second input may have content).\n if not text and operation != \"Text Join\":\n return None\n\n text_handlers = {\n \"Case Conversion\": self._case_conversion,\n \"Text Replace\": self._text_replace,\n \"Text Extract\": self._text_extract,\n \"Text Head\": self._text_head,\n \"Text Tail\": self._text_tail,\n \"Text Strip\": self._text_strip,\n \"Text Join\": self._text_join,\n \"Text Clean\": self._text_clean,\n }\n handler = text_handlers.get(operation)\n if handler:\n return handler(text)\n return text\n\n def _word_count_data(self) -> Data:\n \"\"\"Word Count operation result as a Data object.\"\"\"\n result = self._word_count(getattr(self, \"text_input\", \"\") or \"\")\n return Data(data=result)\n\n def _word_count(self, text: str) -> dict[str, Any]:\n \"\"\"Count words, characters, and lines in text.\"\"\"\n result: dict[str, Any] = {}\n text_str = str(text) if text else \"\"\n is_empty = not text_str or not text_str.strip()\n\n if getattr(self, \"count_words\", True):\n if is_empty:\n result[\"word_count\"] = 0\n result[\"unique_words\"] = 0\n else:\n words = text_str.split()\n result[\"word_count\"] = len(words)\n result[\"unique_words\"] = len(set(words))\n\n if getattr(self, \"count_characters\", True):\n if is_empty:\n result[\"character_count\"] = 0\n result[\"character_count_no_spaces\"] = 0\n else:\n result[\"character_count\"] = len(text_str)\n result[\"character_count_no_spaces\"] = len(text_str.replace(\" \", \"\"))\n\n if getattr(self, \"count_lines\", True):\n if is_empty:\n result[\"line_count\"] = 0\n result[\"non_empty_lines\"] = 0\n else:\n lines = text_str.split(\"\\n\")\n result[\"line_count\"] = len(lines)\n result[\"non_empty_lines\"] = len([line for line in lines if line.strip()])\n\n return result\n\n def _text_to_dataframe(self, text: str) -> DataFrame:\n \"\"\"Convert markdown-style table text to a DataFrame.\"\"\"\n lines = [line.strip() for line in text.strip().split(\"\\n\") if line.strip()]\n if not lines:\n return DataFrame(pd.DataFrame())\n\n separator = getattr(self, \"table_separator\", \"|\")\n has_header = getattr(self, \"has_header\", True)\n\n rows = self._parse_table_rows(lines, separator)\n if not rows:\n return DataFrame(pd.DataFrame())\n\n df = self._create_dataframe(rows, has_header=has_header)\n self._convert_numeric_columns(df)\n self.log(f\"Converted text to DataFrame: {len(df)} rows, {len(df.columns)} columns\")\n return DataFrame(df)\n\n def _parse_table_rows(self, lines: list[str], separator: str) -> list[list[str]]:\n rows = []\n for line in lines:\n cleaned_line = line.strip(separator)\n cells = [cell.strip() for cell in cleaned_line.split(separator)]\n rows.append(cells)\n return rows\n\n def _create_dataframe(self, rows: list[list[str]], *, has_header: bool) -> pd.DataFrame:\n if has_header and len(rows) > 1:\n header = rows[0]\n data_rows = rows[1:]\n header_col_count = len(header)\n for i, row in enumerate(data_rows):\n row_col_count = len(row)\n if row_col_count != header_col_count:\n msg = (\n f\"Header mismatch: {header_col_count} column(s) in header vs \"\n f\"{row_col_count} column(s) in data row {i + 1}. \"\n \"Please ensure the header has the same number of columns as your data.\"\n )\n raise ValueError(msg)\n return pd.DataFrame(data_rows, columns=header)\n\n max_cols = max(len(row) for row in rows) if rows else 0\n columns = [f\"col_{i}\" for i in range(max_cols)]\n return pd.DataFrame(rows, columns=columns)\n\n def _convert_numeric_columns(self, df: pd.DataFrame) -> None:\n for col in df.columns:\n with contextlib.suppress(ValueError, TypeError):\n df[col] = pd.to_numeric(df[col])\n\n def _case_conversion(self, text: str) -> str:\n case_type = getattr(self, \"case_type\", \"lowercase\")\n converter = CASE_CONVERTERS.get(case_type)\n return converter(text) if converter else text\n\n def _text_replace(self, text: str) -> str:\n search_pattern = getattr(self, \"search_pattern\", \"\")\n if not search_pattern:\n return text\n replacement_text = getattr(self, \"replacement_text\", \"\")\n use_regex = getattr(self, \"use_regex\", False)\n if use_regex:\n try:\n return re.sub(search_pattern, replacement_text, text)\n except re.error as e:\n self.log(f\"Invalid regex pattern: {e}\")\n return text\n return text.replace(search_pattern, replacement_text)\n\n def _text_extract(self, text: str) -> list[str]:\n extract_pattern = getattr(self, \"extract_pattern\", \"\")\n if not extract_pattern:\n return []\n max_matches = getattr(self, \"max_matches\", 10)\n try:\n matches = re.findall(extract_pattern, text)\n except re.error as e:\n msg = f\"Invalid regex pattern '{extract_pattern}': {e}\"\n raise ValueError(msg) from e\n return matches[:max_matches] if max_matches > 0 else matches\n\n def _text_head(self, text: str) -> str:\n head_characters = getattr(self, \"head_characters\", 100)\n if head_characters < 0:\n msg = f\"Characters from Start must be a non-negative integer, got {head_characters}\"\n raise ValueError(msg)\n if head_characters == 0:\n return \"\"\n return text[:head_characters]\n\n def _text_tail(self, text: str) -> str:\n tail_characters = getattr(self, \"tail_characters\", 100)\n if tail_characters < 0:\n msg = f\"Characters from End must be a non-negative integer, got {tail_characters}\"\n raise ValueError(msg)\n if tail_characters == 0:\n return \"\"\n return text[-tail_characters:]\n\n def _text_strip(self, text: str) -> str:\n strip_mode = getattr(self, \"strip_mode\", \"both\")\n strip_characters = getattr(self, \"strip_characters\", \"\")\n text_str = str(text) if text else \"\"\n chars_to_strip = strip_characters if strip_characters else None\n if strip_mode == \"left\":\n return text_str.lstrip(chars_to_strip)\n if strip_mode == \"right\":\n return text_str.rstrip(chars_to_strip)\n return text_str.strip(chars_to_strip)\n\n def _text_join(self, text: str) -> str:\n text_input_2 = getattr(self, \"text_input_2\", \"\")\n text1 = str(text) if text else \"\"\n text2 = str(text_input_2) if text_input_2 else \"\"\n if text1 and text2:\n return f\"{text1}\\n{text2}\"\n return text1 or text2\n\n def _text_clean(self, text: str) -> str:\n result = text\n if getattr(self, \"remove_extra_spaces\", True):\n # Collapse runs of horizontal whitespace but preserve newlines so\n # that remove_empty_lines stays effective when both are enabled.\n result = re.sub(r\"[^\\S\\n]+\", \" \", result)\n if getattr(self, \"remove_special_chars\", False):\n result = re.sub(r\"[^\\w\\s]\", \"\", result)\n if getattr(self, \"remove_empty_lines\", False):\n lines = [line for line in result.split(\"\\n\") if line.strip()]\n result = \"\\n\".join(lines)\n return result\n\n def _format_result_as_text(self, result: Any) -> str:\n if result is None:\n return \"\"\n if isinstance(result, list):\n return \"\\n\".join(str(item) for item in result)\n return str(result)\n"},"column_name": {"_input_type": "StrInput",@@ -3493,6 +3215,7 @@"display_name": "Input Type","dynamic": false,"info": "Select the type of input to operate on.",+ "load_from_db": false,"name": "input_type","options": ["Text",@@ -3720,6 +3443,7 @@"dynamic": false,"info": "Select the operation to perform. The matching fields and output appear once you choose one.","limit": 1,+ "load_from_db": false,"name": "operation","options": [{@@ -4304,6 +4028,8 @@},{"data": {+ "description": "Perform operations on Text, JSON, and Tables from a single component.",+ "display_name": "Data Operations","id": "Operations-fX1Im","node": {"base_classes": [@@ -4365,11 +4091,10 @@],"frozen": false,"icon": "wand-sparkles",- "last_updated": "2026-07-30T17:22:27.467Z",+ "last_updated": "2026-10-27T20:15:57.690Z","legacy": false,- "lf_version": "0.11.2rc0","metadata": {- "code_hash": "4c2a33c778d3",+ "code_hash": "f15ba610cfd0","dependencies": {"dependencies": [{@@ -4378,11 +4103,11 @@},{"name": "json_repair",- "version": "0.61.4"+ "version": "0.61.7"},{"name": "lfx",- "version": null+ "version": "1.12.3"},{"name": "jq",@@ -4433,7 +4158,7 @@"data manipulation","data transformation"],- "module": "lfx.components.processing.operations.OperationsComponent"+ "module": "custom_components.data_operations"},"minimized": false,"output_types": [],@@ -4441,7 +4166,7 @@{"allows_loop": false,"cache": true,- "display_name": "Message",+ "display_name": "Table","group_outputs": false,"hidden": null,"loop_types": null,@@ -4463,7 +4188,7 @@"value": "72c3d17c-2dac-4a73-b48a-6518473d7830"},"_frontend_node_folder_id": {- "value": "2d3b55c9-689c-4ef1-a4bd-23eb2159566c"+ "value": "f3f8bf74-7a73-4ab3-9769-0d8a4ebbaec9"},"_type": "Component","append_update_data": {@@ -4558,7 +4283,7 @@"show": true,"title_case": false,"type": "code",- "value": "\"\"\"Unified Operations component.\n\nBrings together the previously separate JSON, Table, and Text operation\ncomponents into a single component. An \"Input Type\" selector (Text / JSON /\nTable) drives everything: it filters the \"Operation\" picker to the operations\nthat apply to that type, reveals the matching input (Text / JSON / Table) and\nits operation-specific fields, and advertises the appropriate output type.\n\nThe three original components (JSON Operations, Table Operations, Text\nOperations) remain available as legacy components for backward compatibility\nwith existing flows.\n\"\"\"\n\nimport ast\nimport contextlib\nimport json\nimport re\nfrom typing import TYPE_CHECKING, Any\n\nimport pandas as pd\nfrom json_repair import repair_json\n\nfrom lfx.custom import Component\nfrom lfx.field_typing import RangeSpec\nfrom lfx.inputs import DictInput, SortableListInput, TabInput\nfrom lfx.io import (\n BoolInput,\n DataFrameInput,\n DataInput,\n DropdownInput,\n IntInput,\n MessageTextInput,\n MultilineInput,\n Output,\n StrInput,\n)\nfrom lfx.log.logger import logger\nfrom lfx.schema import Data\nfrom lfx.schema.dataframe import DataFrame\nfrom lfx.schema.dotdict import dotdict\nfrom lfx.schema.message import Message\n\nif TYPE_CHECKING:\n from collections.abc import Callable\n\n# The \"Input Type\" selector tabs. Each value maps a Langflow data type to the\n# operations, input, and output that belong to it.\nINPUT_TYPES = [\"Text\", \"JSON\", \"Table\"]\n\n# Operations grouped by input type, in display order, each with the icon shown\n# in the Operation picker. This is the single source of truth for the picker;\n# update_build_config swaps the picker's options to the selected type's list.\nOPERATIONS_BY_TYPE: dict[str, list[dict[str, str]]] = {\n \"Text\": [\n {\"name\": \"Word Count\", \"icon\": \"hash\"},\n {\"name\": \"Case Conversion\", \"icon\": \"type\"},\n {\"name\": \"Text Replace\", \"icon\": \"replace\"},\n {\"name\": \"Text Extract\", \"icon\": \"search\"},\n {\"name\": \"Text Head\", \"icon\": \"chevron-left\"},\n {\"name\": \"Text Tail\", \"icon\": \"chevron-right\"},\n {\"name\": \"Text Strip\", \"icon\": \"minus\"},\n {\"name\": \"Text Join\", \"icon\": \"link\"},\n {\"name\": \"Text Clean\", \"icon\": \"sparkles\"},\n {\"name\": \"Text to DataFrame\", \"icon\": \"table\"},\n ],\n \"JSON\": [\n {\"name\": \"Select Keys\", \"icon\": \"lasso-select\"},\n {\"name\": \"Literal Eval\", \"icon\": \"braces\"},\n {\"name\": \"Combine\", \"icon\": \"merge\"},\n {\"name\": \"Append or Update\", \"icon\": \"circle-plus\"},\n {\"name\": \"Remove Keys\", \"icon\": \"eraser\"},\n {\"name\": \"Rename Keys\", \"icon\": \"pencil-line\"},\n {\"name\": \"Path Selection\", \"icon\": \"mouse-pointer\"},\n {\"name\": \"JQ Expression\", \"icon\": \"terminal\"},\n ],\n \"Table\": [\n {\"name\": \"Add Column\", \"icon\": \"plus\"},\n {\"name\": \"Concatenate\", \"icon\": \"combine\"},\n {\"name\": \"Drop Column\", \"icon\": \"minus\"},\n {\"name\": \"Filter\", \"icon\": \"filter\"},\n {\"name\": \"Head\", \"icon\": \"arrow-up\"},\n {\"name\": \"Merge\", \"icon\": \"merge\"},\n {\"name\": \"Rename Column\", \"icon\": \"pencil\"},\n {\"name\": \"Replace Value\", \"icon\": \"replace\"},\n {\"name\": \"Select Columns\", \"icon\": \"columns\"},\n {\"name\": \"Sort\", \"icon\": \"arrow-up-down\"},\n {\"name\": \"Tail\", \"icon\": \"arrow-down\"},\n {\"name\": \"Drop Duplicates\", \"icon\": \"copy-x\"},\n ],\n}\n\n# Operation-name sets derived from the picker, used for dispatch and output\n# routing. Keeping them derived from OPERATIONS_BY_TYPE avoids any drift.\nJSON_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"JSON\"]}\nTABLE_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"Table\"]}\nTEXT_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"Text\"]}\n\n# Each input type maps to its main input field and its default output. \"Text\"\n# normally outputs a Message; \"JSON\" a Data; \"Table\" a DataFrame. A few text\n# operations override this (Word Count -> Data, Text to DataFrame -> DataFrame).\nINPUT_TYPE_TO_MAIN_INPUT = {\"Text\": \"text_input\", \"JSON\": \"data\", \"Table\": \"df\"}\n\n# Case conversions for the Text \"Case Conversion\" operation.\nCASE_CONVERTERS: dict[str, Any] = {\n \"uppercase\": str.upper,\n \"lowercase\": str.lower,\n \"title\": str.title,\n \"capitalize\": str.capitalize,\n \"swapcase\": str.swapcase,\n}\n\n\nclass OperationsComponent(Component):\n display_name = \"Data Operations\"\n description = \"Perform operations on Text, JSON, and Tables from a single component.\"\n documentation: str = \"https://docs.langflow.org/components-processing#operations\"\n icon = \"wand-sparkles\"\n name = \"Operations\"\n metadata = {\n \"keywords\": [\n \"operations\",\n \"data operations\",\n \"json\",\n \"json operations\",\n \"table\",\n \"table operations\",\n \"dataframe\",\n \"dataframe operations\",\n \"text\",\n \"text operations\",\n \"select keys\",\n \"literal eval\",\n \"combine\",\n \"append or update\",\n \"remove keys\",\n \"rename keys\",\n \"path selection\",\n \"jq expression\",\n \"parse json\",\n \"add column\",\n \"concatenate\",\n \"drop column\",\n \"filter\",\n \"head\",\n \"merge\",\n \"rename column\",\n \"replace value\",\n \"select columns\",\n \"sort\",\n \"tail\",\n \"drop duplicates\",\n \"word count\",\n \"case conversion\",\n \"text replace\",\n \"text extract\",\n \"text join\",\n \"text clean\",\n \"text to dataframe\",\n \"data manipulation\",\n \"data transformation\",\n ],\n }\n\n # Operation -> operation-specific input fields to reveal when selected.\n OPERATION_FIELDS: dict[str, list[str]] = {\n # JSON\n \"Select Keys\": [\"select_keys_input\"],\n \"Literal Eval\": [],\n \"Combine\": [],\n \"Append or Update\": [\"append_update_data\"],\n \"Remove Keys\": [\"remove_keys_input\"],\n \"Rename Keys\": [\"rename_keys_input\"],\n \"Path Selection\": [\"mapped_json_display\", \"selected_key\"],\n \"JQ Expression\": [\"query\"],\n # Table\n \"Add Column\": [\"new_column_name\", \"new_column_value\"],\n \"Concatenate\": [],\n \"Drop Column\": [\"column_name\"],\n \"Filter\": [\"column_name\", \"filter_value\", \"filter_operator\"],\n \"Head\": [\"num_rows\"],\n \"Merge\": [\"left_dataframe\", \"right_dataframe\", \"merge_on_column\", \"merge_how\"],\n \"Rename Column\": [\"column_name\", \"new_column_name\"],\n \"Replace Value\": [\"column_name\", \"replace_value\", \"replacement_value\"],\n \"Select Columns\": [\"columns_to_select\"],\n \"Sort\": [\"column_name\", \"ascending\"],\n \"Tail\": [\"num_rows\"],\n \"Drop Duplicates\": [\"column_name\"],\n # Text\n \"Word Count\": [\"count_words\", \"count_characters\", \"count_lines\"],\n \"Case Conversion\": [\"case_type\"],\n \"Text Replace\": [\"search_pattern\", \"replacement_text\", \"use_regex\"],\n \"Text Extract\": [\"extract_pattern\", \"max_matches\"],\n \"Text Head\": [\"head_characters\"],\n \"Text Tail\": [\"tail_characters\"],\n \"Text Strip\": [\"strip_mode\", \"strip_characters\"],\n \"Text Join\": [\"text_input_2\"],\n \"Text Clean\": [\"remove_extra_spaces\", \"remove_special_chars\", \"remove_empty_lines\"],\n \"Text to DataFrame\": [\"table_separator\", \"has_header\"],\n }\n\n # The three main inputs (one per data type). They are never treated as\n # operation-specific fields; the input-type selector toggles them.\n MAIN_INPUTS = (\"text_input\", \"data\", \"df\")\n\n # Every operation-specific field (union of all the lists above), used to\n # hide and reset fields whenever the input type or operation changes.\n ALL_OPERATION_FIELDS: list[str] = [\n # JSON\n \"select_keys_input\",\n \"append_update_data\",\n \"remove_keys_input\",\n \"rename_keys_input\",\n \"mapped_json_display\",\n \"selected_key\",\n \"query\",\n # Table\n \"column_name\",\n \"filter_value\",\n \"filter_operator\",\n \"ascending\",\n \"new_column_name\",\n \"new_column_value\",\n \"columns_to_select\",\n \"num_rows\",\n \"replace_value\",\n \"replacement_value\",\n \"left_dataframe\",\n \"right_dataframe\",\n \"merge_on_column\",\n \"merge_how\",\n # Text\n \"table_separator\",\n \"has_header\",\n \"count_words\",\n \"count_characters\",\n \"count_lines\",\n \"case_type\",\n \"use_regex\",\n \"search_pattern\",\n \"replacement_text\",\n \"extract_pattern\",\n \"max_matches\",\n \"head_characters\",\n \"tail_characters\",\n \"strip_mode\",\n \"strip_characters\",\n \"text_input_2\",\n \"remove_extra_spaces\",\n \"remove_special_chars\",\n \"remove_empty_lines\",\n ]\n\n # Defaults applied to the JSON operation fields when the operation changes,\n # mirroring the JSON Operations component's reset behavior.\n OPERATION_FIELD_DEFAULTS: dict[str, Any] = {\n \"select_keys_input\": [],\n \"append_update_data\": {\"key\": \"value\"},\n \"remove_keys_input\": [],\n \"rename_keys_input\": {\"old_key\": \"new_key\"},\n \"mapped_json_display\": \"\",\n \"selected_key\": None,\n \"query\": \"\",\n }\n\n inputs = [\n # --- Input type selector: drives operations, input, and output ---\n TabInput(\n name=\"input_type\",\n display_name=\"Input Type\",\n options=INPUT_TYPES,\n value=\"Text\",\n info=\"Select the type of input to operate on.\",\n real_time_refresh=True,\n ),\n # --- Main inputs: one per data type, shown contextually ---\n MultilineInput(\n name=\"text_input\",\n display_name=\"Text\",\n info=\"The input text to process.\",\n show=True,\n ),\n DataInput(\n name=\"data\",\n display_name=\"JSON\",\n info=\"The JSON / Data object to operate on.\",\n is_list=True,\n show=False,\n ),\n DataFrameInput(\n name=\"df\",\n display_name=\"Table\",\n info=\"The input Table to operate on. Connect multiple Tables for merge or concatenate operations.\",\n is_list=True,\n show=False,\n ),\n # --- Operation picker (options are filtered by Input Type) ---\n SortableListInput(\n name=\"operation\",\n display_name=\"Operation\",\n placeholder=\"Select Operation\",\n info=\"Select the operation to perform. The matching fields and output appear once you choose one.\",\n options=OPERATIONS_BY_TYPE[\"Text\"],\n real_time_refresh=True,\n limit=1,\n ),\n # --- JSON operation fields ---\n MessageTextInput(\n name=\"select_keys_input\",\n display_name=\"Select Keys\",\n info=\"List of keys to select from the data. Only top-level keys can be selected.\",\n show=False,\n is_list=True,\n value=[],\n ),\n DictInput(\n name=\"append_update_data\",\n display_name=\"Append or Update\",\n info=\"Data to append or update the existing data with. Only top-level keys are checked.\",\n show=False,\n value={\"key\": \"value\"},\n is_list=True,\n ),\n MessageTextInput(\n name=\"remove_keys_input\",\n display_name=\"Remove Keys\",\n info=\"List of keys to remove from the data.\",\n show=False,\n is_list=True,\n value=[],\n ),\n DictInput(\n name=\"rename_keys_input\",\n display_name=\"Rename Keys\",\n info=\"List of keys to rename in the data.\",\n show=False,\n is_list=True,\n value={\"old_key\": \"new_key\"},\n ),\n MultilineInput(\n name=\"mapped_json_display\",\n display_name=\"JSON to Map\",\n info=\"Paste or preview your JSON here to explore its structure and select a path for extraction.\",\n required=False,\n refresh_button=True,\n real_time_refresh=True,\n placeholder=\"Add a JSON example.\",\n show=False,\n ),\n DropdownInput(\n name=\"selected_key\",\n display_name=\"Select Path\",\n options=[],\n required=False,\n dynamic=True,\n show=False,\n value=None,\n ),\n MessageTextInput(\n name=\"query\",\n display_name=\"JQ Expression\",\n info=\"JSON Query to filter the data. Used by Path Selection and JQ Expression operations.\",\n placeholder=\"e.g., .properties.id\",\n show=False,\n ),\n # --- Table operation fields ---\n StrInput(\n name=\"column_name\",\n display_name=\"Column Name\",\n info=\"The column name to use for the operation.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"filter_value\",\n display_name=\"Filter Value\",\n info=\"The value to filter rows by.\",\n dynamic=True,\n show=False,\n ),\n DropdownInput(\n name=\"filter_operator\",\n display_name=\"Filter Operator\",\n options=[\n \"equals\",\n \"not equals\",\n \"contains\",\n \"not contains\",\n \"starts with\",\n \"ends with\",\n \"greater than\",\n \"less than\",\n ],\n value=\"equals\",\n info=\"The operator to apply for filtering rows.\",\n advanced=False,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"ascending\",\n display_name=\"Sort Ascending\",\n info=\"Whether to sort in ascending order.\",\n dynamic=True,\n show=False,\n value=True,\n ),\n StrInput(\n name=\"new_column_name\",\n display_name=\"New Column Name\",\n info=\"The new column name when renaming or adding a column.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"new_column_value\",\n display_name=\"New Column Value\",\n info=\"The value to populate the new column with.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"columns_to_select\",\n display_name=\"Columns to Select\",\n dynamic=True,\n is_list=True,\n show=False,\n ),\n IntInput(\n name=\"num_rows\",\n display_name=\"Number of Rows\",\n info=\"Number of rows to return (for head/tail).\",\n dynamic=True,\n show=False,\n value=5,\n ),\n MessageTextInput(\n name=\"replace_value\",\n display_name=\"Value to Replace\",\n info=\"The value to replace in the column.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"replacement_value\",\n display_name=\"Replacement Value\",\n info=\"The value to replace with.\",\n dynamic=True,\n show=False,\n ),\n DataFrameInput(\n name=\"left_dataframe\",\n display_name=\"Left Table\",\n info=\"The left (primary) Table for merge operations. \"\n \"In a left merge, all rows from this table are preserved.\",\n dynamic=True,\n show=False,\n ),\n DataFrameInput(\n name=\"right_dataframe\",\n display_name=\"Right Table\",\n info=\"The right (secondary) Table for merge operations. \"\n \"In a right merge, all rows from this table are preserved.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"merge_on_column\",\n display_name=\"Merge On Column\",\n info=\"The column name to merge Tables on. Must exist in both Tables.\",\n dynamic=True,\n show=False,\n ),\n DropdownInput(\n name=\"merge_how\",\n display_name=\"Merge Type\",\n options=[\"inner\", \"outer\", \"left\", \"right\"],\n value=\"inner\",\n info=\"Type of merge: inner (intersection), outer (union), left, or right.\",\n dynamic=True,\n show=False,\n ),\n # --- Text operation fields ---\n StrInput(\n name=\"table_separator\",\n display_name=\"Table Separator\",\n info=\"Separator used in the table (default: '|').\",\n value=\"|\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"has_header\",\n display_name=\"Has Header\",\n info=\"Whether the table has a header row.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_words\",\n display_name=\"Count Words\",\n info=\"Include word count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_characters\",\n display_name=\"Count Characters\",\n info=\"Include character count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_lines\",\n display_name=\"Count Lines\",\n info=\"Include line count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n DropdownInput(\n name=\"case_type\",\n display_name=\"Case Type\",\n options=[\"uppercase\", \"lowercase\", \"title\", \"capitalize\", \"swapcase\"],\n value=\"lowercase\",\n info=\"Type of case conversion to apply.\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"use_regex\",\n display_name=\"Use Regex\",\n info=\"Whether to treat search pattern as regex.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"search_pattern\",\n display_name=\"Search Pattern\",\n info=\"Text pattern to search for (supports regex).\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"replacement_text\",\n display_name=\"Replacement Text\",\n info=\"Text to replace the search pattern with.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"extract_pattern\",\n display_name=\"Extract Pattern\",\n info=\"Regex pattern to extract from text.\",\n dynamic=True,\n show=False,\n ),\n IntInput(\n name=\"max_matches\",\n display_name=\"Max Matches\",\n info=\"Maximum number of matches to extract.\",\n value=10,\n dynamic=True,\n show=False,\n ),\n IntInput(\n name=\"head_characters\",\n display_name=\"Characters from Start\",\n info=\"Number of characters to extract from the beginning of text. Must be non-negative.\",\n value=100,\n dynamic=True,\n show=False,\n range_spec=RangeSpec(min=0, max=1000000, step=1, step_type=\"int\"),\n ),\n IntInput(\n name=\"tail_characters\",\n display_name=\"Characters from End\",\n info=\"Number of characters to extract from the end of text. Must be non-negative.\",\n value=100,\n dynamic=True,\n show=False,\n range_spec=RangeSpec(min=0, max=1000000, step=1, step_type=\"int\"),\n ),\n DropdownInput(\n name=\"strip_mode\",\n display_name=\"Strip Mode\",\n options=[\"both\", \"left\", \"right\"],\n value=\"both\",\n info=\"Which sides to strip whitespace from.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"strip_characters\",\n display_name=\"Characters to Strip\",\n info=\"Specific characters to remove (leave empty for whitespace).\",\n value=\"\",\n dynamic=True,\n show=False,\n ),\n MultilineInput(\n name=\"text_input_2\",\n display_name=\"Second Text Input\",\n info=\"Second text to join with the first text.\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_extra_spaces\",\n display_name=\"Remove Extra Spaces\",\n info=\"Remove multiple consecutive spaces.\",\n value=True,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_special_chars\",\n display_name=\"Remove Special Characters\",\n info=\"Remove special characters except alphanumeric and spaces.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_empty_lines\",\n display_name=\"Remove Empty Lines\",\n info=\"Remove empty lines from text.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n ]\n\n # Default output matches the default Input Type (\"Text\" -> Message).\n # update_outputs / update_frontend_node narrow it to the selected type and\n # operation.\n outputs = [Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\")]\n\n # ------------------------------------------------------------------\n # Operation routing helpers\n # ------------------------------------------------------------------\n @staticmethod\n def _extract_operation_name(field_value: Any) -> str:\n \"\"\"Extract the operation name from a SortableListInput value.\"\"\"\n if isinstance(field_value, list) and len(field_value) > 0 and isinstance(field_value[0], dict):\n return field_value[0].get(\"name\", \"\")\n if isinstance(field_value, str):\n return field_value\n return \"\"\n\n def _operation_name(self) -> str:\n \"\"\"Get the currently selected operation name.\"\"\"\n return self._extract_operation_name(getattr(self, \"operation\", []))\n\n @staticmethod\n def _default_output_for_type(input_type: str) -> Output:\n \"\"\"Return the output advertised for an input type when no operation is selected yet.\"\"\"\n if input_type == \"JSON\":\n return Output(display_name=\"JSON\", name=\"data_output\", method=\"as_data\")\n if input_type == \"Table\":\n return Output(display_name=\"Table\", name=\"dataframe_output\", method=\"as_dataframe\")\n return Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\")\n\n # ------------------------------------------------------------------\n # Dynamic UI\n # ------------------------------------------------------------------\n def _reset_operation_fields(self, build_config: dotdict) -> None:\n \"\"\"Hide every operation-specific field and restore its default value.\"\"\"\n for field in self.ALL_OPERATION_FIELDS:\n if field in build_config:\n build_config[field][\"show\"] = False\n if field in self.OPERATION_FIELD_DEFAULTS:\n build_config[field][\"value\"] = self.OPERATION_FIELD_DEFAULTS[field]\n\n def _show_main_input(self, build_config: dotdict, input_type: str, operation: str) -> None:\n \"\"\"Show only the main input that matches the input type; hide the others.\"\"\"\n for inp in self.MAIN_INPUTS:\n if inp in build_config:\n build_config[inp][\"show\"] = False\n build_config[inp][\"required\"] = False\n\n main_input = INPUT_TYPE_TO_MAIN_INPUT.get(input_type)\n if main_input and main_input in build_config:\n build_config[main_input][\"show\"] = True\n build_config[main_input][\"required\"] = True\n # The JSON \"Combine\" operation consumes a list of Data objects.\n if main_input == \"data\":\n build_config[\"data\"][\"is_list\"] = operation == \"Combine\"\n\n def update_build_config(self, build_config: dotdict, field_value: Any, field_name: str | None = None) -> dotdict:\n # Path Selection: refresh the available JSON paths from the pasted JSON.\n if field_name == \"mapped_json_display\":\n try:\n parsed_json = json.loads(field_value)\n keys = self.extract_all_paths(parsed_json)\n build_config[\"selected_key\"][\"options\"] = keys\n build_config[\"selected_key\"][\"show\"] = True\n except (json.JSONDecodeError, TypeError, ValueError) as e:\n logger.error(f\"Error parsing mapped JSON: {e}\")\n build_config[\"selected_key\"][\"show\"] = False\n return build_config\n\n # Input type changed: swap the operation list, clear the selection, and\n # show only the matching input. No operation-specific fields are shown\n # until an operation is picked.\n if field_name == \"input_type\":\n input_type = field_value if field_value in OPERATIONS_BY_TYPE else \"Text\"\n build_config[\"operation\"][\"options\"] = OPERATIONS_BY_TYPE[input_type]\n build_config[\"operation\"][\"value\"] = []\n self._reset_operation_fields(build_config)\n self._show_main_input(build_config, input_type, operation=\"\")\n return build_config\n\n # Operation changed: reset fields, show the input for the current type,\n # then reveal the operation-specific fields.\n if field_name == \"operation\":\n operation = self._extract_operation_name(field_value)\n self._reset_operation_fields(build_config)\n\n input_type = build_config.get(\"input_type\", {}).get(\"value\", \"Text\")\n self._show_main_input(build_config, input_type, operation)\n\n for field in self.OPERATION_FIELDS.get(operation, []):\n if field in build_config:\n build_config[field][\"show\"] = True\n\n return build_config\n\n return build_config\n\n def update_outputs(self, frontend_node: dict, field_name: str, field_value: Any) -> dict:\n \"\"\"Create the output(s) appropriate to the selected input type and operation.\"\"\"\n if field_name == \"input_type\":\n # Switching type clears the operation; advertise the type's default.\n input_type = field_value if field_value in OPERATIONS_BY_TYPE else \"Text\"\n frontend_node[\"outputs\"] = [self._default_output_for_type(input_type)]\n return frontend_node\n\n template = frontend_node.get(\"template\", {})\n input_type = template.get(\"input_type\", {}).get(\"value\", \"Text\")\n\n if field_name == \"operation\":\n operation = self._extract_operation_name(field_value)\n else:\n # Any other refresh (e.g. Path Selection's \"JSON to Map\" field)\n # reaches here on a freshly rebuilt node whose outputs were reset\n # to the class default (Message). Re-derive the output from the\n # saved operation so the refresh doesn't swap the real output type.\n operation = self._extract_operation_name(template.get(\"operation\", {}).get(\"value\", []))\n\n if not operation:\n # No operation selected: fall back to the input type's default output.\n frontend_node[\"outputs\"] = [self._default_output_for_type(input_type)]\n return frontend_node\n\n frontend_node[\"outputs\"] = []\n if operation in JSON_OPERATIONS or operation == \"Word Count\":\n frontend_node[\"outputs\"].append(Output(display_name=\"JSON\", name=\"data_output\", method=\"as_data\"))\n elif operation in TABLE_OPERATIONS or operation == \"Text to DataFrame\":\n frontend_node[\"outputs\"].append(\n Output(display_name=\"Table\", name=\"dataframe_output\", method=\"as_dataframe\")\n )\n elif operation == \"Text Join\":\n frontend_node[\"outputs\"].append(Output(display_name=\"Text\", name=\"text_output\", method=\"as_text\"))\n frontend_node[\"outputs\"].append(Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\"))\n else:\n frontend_node[\"outputs\"].append(Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\"))\n\n return frontend_node\n\n async def update_frontend_node(self, new_frontend_node: dict, current_frontend_node: dict) -> dict:\n \"\"\"Keep the operation options and outputs in sync with the saved input type on load.\"\"\"\n await super().update_frontend_node(new_frontend_node, current_frontend_node)\n\n template = new_frontend_node.get(\"template\", {})\n input_type = template.get(\"input_type\", {}).get(\"value\", \"Text\")\n if input_type not in OPERATIONS_BY_TYPE:\n input_type = \"Text\"\n\n # Filter the operation picker to the saved input type.\n if \"operation\" in template:\n template[\"operation\"][\"options\"] = OPERATIONS_BY_TYPE[input_type]\n\n # Re-derive the outputs from the saved input type + operation.\n operation_value = template.get(\"operation\", {}).get(\"value\", [])\n if self._extract_operation_name(operation_value):\n self.update_outputs(new_frontend_node, \"operation\", operation_value)\n else:\n self.update_outputs(new_frontend_node, \"input_type\", input_type)\n\n return new_frontend_node\n\n # ==================================================================\n # Output methods (referenced by update_outputs)\n # ==================================================================\n def as_data(self) -> Data:\n \"\"\"JSON-typed output: JSON operations and Word Count.\"\"\"\n operation = self._operation_name()\n if operation in JSON_OPERATIONS:\n handler = self._json_handlers().get(operation)\n if handler:\n try:\n return handler()\n except Exception as e:\n logger.error(f\"Error executing {operation}: {e!s}\")\n raise\n if operation == \"Word Count\":\n return self._word_count_data()\n return Data(data={})\n\n def as_dataframe(self) -> DataFrame:\n \"\"\"Table-typed output: Table operations and Text to DataFrame.\"\"\"\n operation = self._operation_name()\n if operation in TABLE_OPERATIONS:\n return self._run_table_operation(operation)\n if operation == \"Text to DataFrame\":\n return self._text_to_dataframe(getattr(self, \"text_input\", \"\") or \"\")\n return DataFrame(pd.DataFrame())\n\n def as_message(self) -> Message:\n \"\"\"Message-typed output: generic text operations (and Text Join).\"\"\"\n return Message(text=self._format_result_as_text(self._run_text_operation()))\n\n def as_text(self) -> Message:\n \"\"\"Text output for the Text Join operation.\"\"\"\n return self.as_message()\n\n # ==================================================================\n # JSON operations\n # ==================================================================\n @staticmethod\n def extract_all_paths(obj, path=\"\"):\n paths = []\n if isinstance(obj, dict):\n for k, v in obj.items():\n new_path = f\"{path}.{k}\" if path else f\".{k}\"\n paths.append(new_path)\n paths.extend(OperationsComponent.extract_all_paths(v, new_path))\n elif isinstance(obj, list) and obj:\n new_path = f\"{path}[0]\"\n paths.append(new_path)\n paths.extend(OperationsComponent.extract_all_paths(obj[0], new_path))\n return paths\n\n @staticmethod\n def remove_keys_recursive(obj, keys_to_remove):\n if isinstance(obj, dict):\n return {\n k: OperationsComponent.remove_keys_recursive(v, keys_to_remove)\n for k, v in obj.items()\n if k not in keys_to_remove\n }\n if isinstance(obj, list):\n return [OperationsComponent.remove_keys_recursive(item, keys_to_remove) for item in obj]\n return obj\n\n @staticmethod\n def rename_keys_recursive(obj, rename_map):\n if isinstance(obj, dict):\n return {\n rename_map.get(k, k): OperationsComponent.rename_keys_recursive(v, rename_map) for k, v in obj.items()\n }\n if isinstance(obj, list):\n return [OperationsComponent.rename_keys_recursive(item, rename_map) for item in obj]\n return obj\n\n def _json_handlers(self) -> \"dict[str, Callable[[], Data]]\":\n return {\n \"Select Keys\": self.select_keys,\n \"Literal Eval\": self.evaluate_data,\n \"Combine\": self.combine_data,\n \"Append or Update\": self.append_update,\n \"Remove Keys\": self.remove_keys,\n \"Rename Keys\": self.rename_keys,\n \"Path Selection\": self.json_path,\n \"JQ Expression\": self.json_query,\n }\n\n def get_data_dict(self) -> dict:\n \"\"\"Extract data dictionary from Data object.\"\"\"\n data = self.data[0] if isinstance(self.data, list) and len(self.data) == 1 else self.data\n return data.model_dump()\n\n def get_normalized_data(self) -> dict:\n \"\"\"Get normalized data dictionary, handling the 'data' key if present.\"\"\"\n data_dict = self.get_data_dict()\n return data_dict.get(\"data\", data_dict)\n\n def data_is_list(self) -> bool:\n \"\"\"Check if data contains multiple items.\"\"\"\n return isinstance(self.data, list) and len(self.data) > 1\n\n def validate_single_data(self, operation: str) -> None:\n \"\"\"Validate that the operation is being performed on a single data object.\"\"\"\n if self.data_is_list():\n msg = f\"{operation} operation is not supported for multiple data objects.\"\n raise ValueError(msg)\n\n def select_keys(self) -> Data:\n \"\"\"Select specific keys from the data dictionary.\"\"\"\n self.validate_single_data(\"Select Keys\")\n data_dict = self.get_normalized_data()\n filter_criteria: list[str] = self.select_keys_input\n\n if len(filter_criteria) == 1 and filter_criteria[0] == \"data\":\n filtered = data_dict[\"data\"]\n else:\n if not all(key in data_dict for key in filter_criteria):\n msg = f\"Select key not found in data. Available keys: {list(data_dict.keys())}\"\n raise ValueError(msg)\n filtered = {key: value for key, value in data_dict.items() if key in filter_criteria}\n\n return Data(data=filtered)\n\n def remove_keys(self) -> Data:\n \"\"\"Remove specified keys from the data dictionary, recursively.\"\"\"\n self.validate_single_data(\"Remove Keys\")\n data_dict = self.get_normalized_data()\n remove_keys_input: list[str] = self.remove_keys_input\n filtered = OperationsComponent.remove_keys_recursive(data_dict, set(remove_keys_input))\n return Data(data=filtered)\n\n def rename_keys(self) -> Data:\n \"\"\"Rename keys in the data dictionary, recursively.\"\"\"\n self.validate_single_data(\"Rename Keys\")\n data_dict = self.get_normalized_data()\n rename_keys_input: dict[str, str] = self.rename_keys_input\n renamed = OperationsComponent.rename_keys_recursive(data_dict, rename_keys_input)\n return Data(data=renamed)\n\n def recursive_eval(self, data: Any) -> Any:\n \"\"\"Recursively evaluate string values that look like Python literals.\"\"\"\n if isinstance(data, dict):\n return {k: self.recursive_eval(v) for k, v in data.items()}\n if isinstance(data, list):\n return [self.recursive_eval(item) for item in data]\n if isinstance(data, str):\n try:\n if (\n data.strip().startswith((\"{\", \"[\", \"(\", \"'\", '\"'))\n or data.strip().lower() in (\"true\", \"false\", \"none\")\n or data.strip().replace(\".\", \"\").isdigit()\n ):\n return ast.literal_eval(data)\n except (ValueError, SyntaxError, TypeError, MemoryError):\n return data\n else:\n return data\n return data\n\n def evaluate_data(self) -> Data:\n \"\"\"Evaluate string values in the data dictionary.\"\"\"\n self.validate_single_data(\"Literal Eval\")\n logger.info(\"evaluating data\")\n return Data(**self.recursive_eval(self.get_data_dict()))\n\n def combine_data(self) -> Data:\n \"\"\"Combine multiple data objects into one.\"\"\"\n logger.info(\"combining data\")\n if not self.data_is_list():\n return self.data[0] if self.data else Data(data={})\n\n data_dicts = [data.model_dump().get(\"data\", data.model_dump()) for data in self.data]\n combined_data: dict[str, Any] = {}\n\n for data_dict in data_dicts:\n for key, value in data_dict.items():\n if key not in combined_data:\n combined_data[key] = value\n elif isinstance(combined_data[key], list):\n if isinstance(value, list):\n combined_data[key].extend(value)\n else:\n combined_data[key].append(value)\n else:\n combined_data[key] = (\n [combined_data[key], value] if not isinstance(value, list) else [combined_data[key], *value]\n )\n\n return Data(**combined_data)\n\n def append_update(self) -> Data:\n \"\"\"Append or update the data with new key-value pairs.\"\"\"\n self.validate_single_data(\"Append or Update\")\n data_filtered = self.get_normalized_data()\n for key, value in self.append_update_data.items():\n data_filtered[key] = value\n return Data(**data_filtered)\n\n def json_path(self) -> Data:\n \"\"\"Extract a value from the data using the selected JQ path.\"\"\"\n try:\n import jq\n except ImportError:\n msg = \"jq is required for Path Selection. Install with: pip install jq\"\n raise ImportError(msg) from None\n\n try:\n if not self.data or not self.selected_key:\n msg = \"Missing input data or selected key.\"\n raise ValueError(msg)\n input_payload = self.data[0].data if isinstance(self.data, list) else self.data.data\n compiled = jq.compile(self.selected_key)\n result = compiled.input(input_payload).first()\n if isinstance(result, dict):\n return Data(data=result)\n return Data(data={\"result\": result})\n except (ValueError, TypeError, KeyError) as e:\n self.status = f\"Error: {e!s}\"\n self.log(self.status)\n return Data(data={\"error\": str(e)})\n\n def json_query(self) -> Data:\n \"\"\"Run a JQ expression against the data.\"\"\"\n try:\n import jq\n except ImportError:\n msg = \"jq is required for JQ Expression. Install with: pip install jq\"\n raise ImportError(msg) from None\n\n if not self.query or not self.query.strip():\n msg = \"JSON Query is required and cannot be blank.\"\n raise ValueError(msg)\n raw_data = self.get_data_dict()\n try:\n input_str = json.dumps(raw_data)\n repaired = repair_json(input_str)\n data_json = json.loads(repaired)\n jq_input = data_json[\"data\"] if isinstance(data_json, dict) and \"data\" in data_json else data_json\n results = jq.compile(self.query).input(jq_input).all()\n if not results:\n msg = \"No result from JSON query.\"\n raise ValueError(msg)\n result = results[0] if len(results) == 1 else results\n if result is None or result == \"None\":\n msg = \"JSON query returned null/None. Check if the path exists in your data.\"\n raise ValueError(msg)\n if isinstance(result, dict):\n return Data(data=result)\n return Data(data={\"result\": result})\n except (ValueError, TypeError, KeyError, json.JSONDecodeError) as e:\n logger.error(f\"JSON Query failed: {e}\")\n msg = f\"JSON Query error: {e}\"\n raise ValueError(msg) from e\n\n # ==================================================================\n # Table operations\n # ==================================================================\n def _get_primary_dataframe(self) -> DataFrame:\n \"\"\"Get the first DataFrame from input (handles both single and list inputs).\"\"\"\n if isinstance(self.df, list):\n return self.df[0].copy() if self.df else DataFrame()\n return self.df.copy()\n\n def _run_table_operation(self, operation: str) -> DataFrame:\n # Merge and Concatenate use their own inputs, not the primary df.\n if operation == \"Merge\":\n return self.merge_dataframes()\n if operation == \"Concatenate\":\n return self.concatenate_dataframes()\n\n df_copy = self._get_primary_dataframe()\n table_handlers = {\n \"Filter\": self.filter_rows_by_value,\n \"Sort\": self.sort_by_column,\n \"Drop Column\": self.drop_column,\n \"Rename Column\": self.rename_column,\n \"Add Column\": self.add_column,\n \"Select Columns\": self.select_columns,\n \"Head\": self.head,\n \"Tail\": self.tail,\n \"Replace Value\": self.replace_values,\n \"Drop Duplicates\": self.drop_duplicates,\n }\n handler = table_handlers.get(operation)\n if handler is None:\n msg = f\"Unsupported operation: {operation}\"\n logger.error(msg)\n raise ValueError(msg)\n return handler(df_copy)\n\n def filter_rows_by_value(self, df: DataFrame) -> DataFrame:\n column = df[self.column_name]\n filter_value = self.filter_value\n operator = getattr(self, \"filter_operator\", \"equals\")\n\n if operator == \"equals\":\n mask = column == filter_value\n elif operator == \"not equals\":\n mask = column != filter_value\n elif operator == \"contains\":\n mask = column.astype(str).str.contains(str(filter_value), na=False)\n elif operator == \"not contains\":\n mask = ~column.astype(str).str.contains(str(filter_value), na=False)\n elif operator == \"starts with\":\n mask = column.astype(str).str.startswith(str(filter_value), na=False)\n elif operator == \"ends with\":\n mask = column.astype(str).str.endswith(str(filter_value), na=False)\n elif operator == \"greater than\":\n try:\n numeric_value = pd.to_numeric(filter_value)\n mask = column > numeric_value\n except (ValueError, TypeError):\n mask = column.astype(str) > str(filter_value)\n elif operator == \"less than\":\n try:\n numeric_value = pd.to_numeric(filter_value)\n mask = column < numeric_value\n except (ValueError, TypeError):\n mask = column.astype(str) < str(filter_value)\n else:\n mask = column == filter_value\n\n return DataFrame(df[mask])\n\n def sort_by_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.sort_values(by=self.column_name, ascending=self.ascending))\n\n def drop_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.drop(columns=[self.column_name]))\n\n def rename_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.rename(columns={self.column_name: self.new_column_name}))\n\n def add_column(self, df: DataFrame) -> DataFrame:\n df[self.new_column_name] = [self.new_column_value] * len(df)\n return DataFrame(df)\n\n def select_columns(self, df: DataFrame) -> DataFrame:\n columns = [col.strip() for col in self.columns_to_select]\n return DataFrame(df[columns])\n\n def head(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.head(self.num_rows))\n\n def tail(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.tail(self.num_rows))\n\n def replace_values(self, df: DataFrame) -> DataFrame:\n df[self.column_name] = df[self.column_name].replace(self.replace_value, self.replacement_value)\n return DataFrame(df)\n\n def drop_duplicates(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.drop_duplicates(subset=self.column_name))\n\n def concatenate_dataframes(self) -> DataFrame:\n \"\"\"Concatenate multiple DataFrames vertically (stack rows).\"\"\"\n if not isinstance(self.df, list) or len(self.df) == 0:\n return self.df.copy() if self.df is not None else DataFrame()\n\n if len(self.df) == 1:\n return self.df[0].copy()\n\n concatenated = pd.concat(self.df, ignore_index=True)\n return DataFrame(concatenated)\n\n def merge_dataframes(self) -> DataFrame:\n \"\"\"Merge two DataFrames based on a common column (join operation).\"\"\"\n left_df = getattr(self, \"left_dataframe\", None)\n right_df = getattr(self, \"right_dataframe\", None)\n\n if left_df is None:\n return DataFrame()\n if right_df is None:\n return left_df.copy()\n\n df_left = left_df.copy()\n df_right = right_df.copy()\n\n merge_on = getattr(self, \"merge_on_column\", None)\n merge_how = getattr(self, \"merge_how\", \"inner\")\n\n if merge_on:\n if merge_on not in df_left.columns:\n msg = f\"Column '{merge_on}' not found in left DataFrame. Available: {list(df_left.columns)}\"\n raise ValueError(msg)\n if merge_on not in df_right.columns:\n msg = f\"Column '{merge_on}' not found in right DataFrame. Available: {list(df_right.columns)}\"\n raise ValueError(msg)\n merged = df_left.merge(df_right, on=merge_on, how=merge_how, suffixes=(\"\", \"_right\"))\n else:\n merged = df_left.merge(df_right, left_index=True, right_index=True, how=merge_how, suffixes=(\"\", \"_right\"))\n\n cols_to_drop = []\n for col in merged.columns:\n if col.endswith(\"_right\"):\n original_col = col[:-6]\n if original_col in merged.columns:\n merged[original_col] = merged[original_col].combine_first(merged[col])\n cols_to_drop.append(col)\n\n if cols_to_drop:\n merged = merged.drop(columns=cols_to_drop)\n\n return DataFrame(merged)\n\n # ==================================================================\n # Text operations\n # ==================================================================\n def _run_text_operation(self) -> Any:\n \"\"\"Process text based on the selected operation (Message/Text outputs).\"\"\"\n text = getattr(self, \"text_input\", \"\")\n operation = self._operation_name()\n\n # Allow empty text for Text Join (second input may have content).\n if not text and operation != \"Text Join\":\n return None\n\n text_handlers = {\n \"Case Conversion\": self._case_conversion,\n \"Text Replace\": self._text_replace,\n \"Text Extract\": self._text_extract,\n \"Text Head\": self._text_head,\n \"Text Tail\": self._text_tail,\n \"Text Strip\": self._text_strip,\n \"Text Join\": self._text_join,\n \"Text Clean\": self._text_clean,\n }\n handler = text_handlers.get(operation)\n if handler:\n return handler(text)\n return text\n\n def _word_count_data(self) -> Data:\n \"\"\"Word Count operation result as a Data object.\"\"\"\n result = self._word_count(getattr(self, \"text_input\", \"\") or \"\")\n return Data(data=result)\n\n def _word_count(self, text: str) -> dict[str, Any]:\n \"\"\"Count words, characters, and lines in text.\"\"\"\n result: dict[str, Any] = {}\n text_str = str(text) if text else \"\"\n is_empty = not text_str or not text_str.strip()\n\n if getattr(self, \"count_words\", True):\n if is_empty:\n result[\"word_count\"] = 0\n result[\"unique_words\"] = 0\n else:\n words = text_str.split()\n result[\"word_count\"] = len(words)\n result[\"unique_words\"] = len(set(words))\n\n if getattr(self, \"count_characters\", True):\n if is_empty:\n result[\"character_count\"] = 0\n result[\"character_count_no_spaces\"] = 0\n else:\n result[\"character_count\"] = len(text_str)\n result[\"character_count_no_spaces\"] = len(text_str.replace(\" \", \"\"))\n\n if getattr(self, \"count_lines\", True):\n if is_empty:\n result[\"line_count\"] = 0\n result[\"non_empty_lines\"] = 0\n else:\n lines = text_str.split(\"\\n\")\n result[\"line_count\"] = len(lines)\n result[\"non_empty_lines\"] = len([line for line in lines if line.strip()])\n\n return result\n\n def _text_to_dataframe(self, text: str) -> DataFrame:\n \"\"\"Convert markdown-style table text to a DataFrame.\"\"\"\n lines = [line.strip() for line in text.strip().split(\"\\n\") if line.strip()]\n if not lines:\n return DataFrame(pd.DataFrame())\n\n separator = getattr(self, \"table_separator\", \"|\")\n has_header = getattr(self, \"has_header\", True)\n\n rows = self._parse_table_rows(lines, separator)\n if not rows:\n return DataFrame(pd.DataFrame())\n\n df = self._create_dataframe(rows, has_header=has_header)\n self._convert_numeric_columns(df)\n self.log(f\"Converted text to DataFrame: {len(df)} rows, {len(df.columns)} columns\")\n return DataFrame(df)\n\n def _parse_table_rows(self, lines: list[str], separator: str) -> list[list[str]]:\n rows = []\n for line in lines:\n cleaned_line = line.strip(separator)\n cells = [cell.strip() for cell in cleaned_line.split(separator)]\n rows.append(cells)\n return rows\n\n def _create_dataframe(self, rows: list[list[str]], *, has_header: bool) -> pd.DataFrame:\n if has_header and len(rows) > 1:\n header = rows[0]\n data_rows = rows[1:]\n header_col_count = len(header)\n for i, row in enumerate(data_rows):\n row_col_count = len(row)\n if row_col_count != header_col_count:\n msg = (\n f\"Header mismatch: {header_col_count} column(s) in header vs \"\n f\"{row_col_count} column(s) in data row {i + 1}. \"\n \"Please ensure the header has the same number of columns as your data.\"\n )\n raise ValueError(msg)\n return pd.DataFrame(data_rows, columns=header)\n\n max_cols = max(len(row) for row in rows) if rows else 0\n columns = [f\"col_{i}\" for i in range(max_cols)]\n return pd.DataFrame(rows, columns=columns)\n\n def _convert_numeric_columns(self, df: pd.DataFrame) -> None:\n for col in df.columns:\n with contextlib.suppress(ValueError, TypeError):\n df[col] = pd.to_numeric(df[col])\n\n def _case_conversion(self, text: str) -> str:\n case_type = getattr(self, \"case_type\", \"lowercase\")\n converter = CASE_CONVERTERS.get(case_type)\n return converter(text) if converter else text\n\n def _text_replace(self, text: str) -> str:\n search_pattern = getattr(self, \"search_pattern\", \"\")\n if not search_pattern:\n return text\n replacement_text = getattr(self, \"replacement_text\", \"\")\n use_regex = getattr(self, \"use_regex\", False)\n if use_regex:\n try:\n return re.sub(search_pattern, replacement_text, text)\n except re.error as e:\n self.log(f\"Invalid regex pattern: {e}\")\n return text\n return text.replace(search_pattern, replacement_text)\n\n def _text_extract(self, text: str) -> list[str]:\n extract_pattern = getattr(self, \"extract_pattern\", \"\")\n if not extract_pattern:\n return []\n max_matches = getattr(self, \"max_matches\", 10)\n try:\n matches = re.findall(extract_pattern, text)\n except re.error as e:\n msg = f\"Invalid regex pattern '{extract_pattern}': {e}\"\n raise ValueError(msg) from e\n return matches[:max_matches] if max_matches > 0 else matches\n\n def _text_head(self, text: str) -> str:\n head_characters = getattr(self, \"head_characters\", 100)\n if head_characters < 0:\n msg = f\"Characters from Start must be a non-negative integer, got {head_characters}\"\n raise ValueError(msg)\n if head_characters == 0:\n return \"\"\n return text[:head_characters]\n\n def _text_tail(self, text: str) -> str:\n tail_characters = getattr(self, \"tail_characters\", 100)\n if tail_characters < 0:\n msg = f\"Characters from End must be a non-negative integer, got {tail_characters}\"\n raise ValueError(msg)\n if tail_characters == 0:\n return \"\"\n return text[-tail_characters:]\n\n def _text_strip(self, text: str) -> str:\n strip_mode = getattr(self, \"strip_mode\", \"both\")\n strip_characters = getattr(self, \"strip_characters\", \"\")\n text_str = str(text) if text else \"\"\n chars_to_strip = strip_characters if strip_characters else None\n if strip_mode == \"left\":\n return text_str.lstrip(chars_to_strip)\n if strip_mode == \"right\":\n return text_str.rstrip(chars_to_strip)\n return text_str.strip(chars_to_strip)\n\n def _text_join(self, text: str) -> str:\n text_input_2 = getattr(self, \"text_input_2\", \"\")\n text1 = str(text) if text else \"\"\n text2 = str(text_input_2) if text_input_2 else \"\"\n if text1 and text2:\n return f\"{text1}\\n{text2}\"\n return text1 or text2\n\n def _text_clean(self, text: str) -> str:\n result = text\n if getattr(self, \"remove_extra_spaces\", True):\n # Collapse runs of horizontal whitespace but preserve newlines so\n # that remove_empty_lines stays effective when both are enabled.\n result = re.sub(r\"[^\\S\\n]+\", \" \", result)\n if getattr(self, \"remove_special_chars\", False):\n result = re.sub(r\"[^\\w\\s]\", \"\", result)\n if getattr(self, \"remove_empty_lines\", False):\n lines = [line for line in result.split(\"\\n\") if line.strip()]\n result = \"\\n\".join(lines)\n return result\n\n def _format_result_as_text(self, result: Any) -> str:\n if result is None:\n return \"\"\n if isinstance(result, list):\n return \"\\n\".join(str(item) for item in result)\n return str(result)\n"+ "value": "\"\"\"Unified Operations component.\n\nBrings together the previously separate JSON, Table, and Text operation\ncomponents into a single component. An \"Input Type\" selector (Text / JSON /\nTable) drives everything: it filters the \"Operation\" picker to the operations\nthat apply to that type, reveals the matching input (Text / JSON / Table) and\nits operation-specific fields, and advertises the appropriate output type.\n\nThe three original components (JSON Operations, Table Operations, Text\nOperations) remain available as legacy components for backward compatibility\nwith existing flows.\n\"\"\"\n\nimport ast\nimport contextlib\nimport json\nimport re\nfrom typing import TYPE_CHECKING, Any\n\nimport pandas as pd\nfrom json_repair import repair_json\n\nfrom lfx.custom import Component\nfrom lfx.field_typing import RangeSpec\nfrom lfx.inputs import DictInput, SortableListInput, TabInput\nfrom lfx.io import (\n BoolInput,\n DataFrameInput,\n DataInput,\n DropdownInput,\n IntInput,\n MessageTextInput,\n MultilineInput,\n Output,\n StrInput,\n)\nfrom lfx.log.logger import logger\nfrom lfx.schema import Data\nfrom lfx.schema.dataframe import DataFrame\nfrom lfx.schema.dotdict import dotdict\nfrom lfx.schema.message import Message\nfrom lfx.utils.jq_security import validate_jq_program\n\nif TYPE_CHECKING:\n from collections.abc import Callable\n\n# The \"Input Type\" selector tabs. Each value maps a Langflow data type to the\n# operations, input, and output that belong to it.\nINPUT_TYPES = [\"Text\", \"JSON\", \"Table\"]\n\n# Operations grouped by input type, in display order, each with the icon shown\n# in the Operation picker. This is the single source of truth for the picker;\n# update_build_config swaps the picker's options to the selected type's list.\nOPERATIONS_BY_TYPE: dict[str, list[dict[str, str]]] = {\n \"Text\": [\n {\"name\": \"Word Count\", \"icon\": \"hash\"},\n {\"name\": \"Case Conversion\", \"icon\": \"type\"},\n {\"name\": \"Text Replace\", \"icon\": \"replace\"},\n {\"name\": \"Text Extract\", \"icon\": \"search\"},\n {\"name\": \"Text Head\", \"icon\": \"chevron-left\"},\n {\"name\": \"Text Tail\", \"icon\": \"chevron-right\"},\n {\"name\": \"Text Strip\", \"icon\": \"minus\"},\n {\"name\": \"Text Join\", \"icon\": \"link\"},\n {\"name\": \"Text Clean\", \"icon\": \"sparkles\"},\n {\"name\": \"Text to DataFrame\", \"icon\": \"table\"},\n ],\n \"JSON\": [\n {\"name\": \"Select Keys\", \"icon\": \"lasso-select\"},\n {\"name\": \"Literal Eval\", \"icon\": \"braces\"},\n {\"name\": \"Combine\", \"icon\": \"merge\"},\n {\"name\": \"Append or Update\", \"icon\": \"circle-plus\"},\n {\"name\": \"Remove Keys\", \"icon\": \"eraser\"},\n {\"name\": \"Rename Keys\", \"icon\": \"pencil-line\"},\n {\"name\": \"Path Selection\", \"icon\": \"mouse-pointer\"},\n {\"name\": \"JQ Expression\", \"icon\": \"terminal\"},\n ],\n \"Table\": [\n {\"name\": \"Add Column\", \"icon\": \"plus\"},\n {\"name\": \"Concatenate\", \"icon\": \"combine\"},\n {\"name\": \"Drop Column\", \"icon\": \"minus\"},\n {\"name\": \"Filter\", \"icon\": \"filter\"},\n {\"name\": \"Head\", \"icon\": \"arrow-up\"},\n {\"name\": \"Merge\", \"icon\": \"merge\"},\n {\"name\": \"Rename Column\", \"icon\": \"pencil\"},\n {\"name\": \"Replace Value\", \"icon\": \"replace\"},\n {\"name\": \"Select Columns\", \"icon\": \"columns\"},\n {\"name\": \"Sort\", \"icon\": \"arrow-up-down\"},\n {\"name\": \"Tail\", \"icon\": \"arrow-down\"},\n {\"name\": \"Drop Duplicates\", \"icon\": \"copy-x\"},\n ],\n}\n\n# Operation-name sets derived from the picker, used for dispatch and output\n# routing. Keeping them derived from OPERATIONS_BY_TYPE avoids any drift.\nJSON_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"JSON\"]}\nTABLE_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"Table\"]}\nTEXT_OPERATIONS = {op[\"name\"] for op in OPERATIONS_BY_TYPE[\"Text\"]}\n\n# Each input type maps to its main input field and its default output. \"Text\"\n# normally outputs a Message; \"JSON\" a Data; \"Table\" a DataFrame. A few text\n# operations override this (Word Count -> Data, Text to DataFrame -> DataFrame).\nINPUT_TYPE_TO_MAIN_INPUT = {\"Text\": \"text_input\", \"JSON\": \"data\", \"Table\": \"df\"}\n\n# Case conversions for the Text \"Case Conversion\" operation.\nCASE_CONVERTERS: dict[str, Any] = {\n \"uppercase\": str.upper,\n \"lowercase\": str.lower,\n \"title\": str.title,\n \"capitalize\": str.capitalize,\n \"swapcase\": str.swapcase,\n}\n\n\nclass OperationsComponent(Component):\n display_name = \"Data Operations\"\n description = \"Perform operations on Text, JSON, and Tables from a single component.\"\n documentation: str = \"https://docs.langflow.org/components-processing#operations\"\n icon = \"wand-sparkles\"\n name = \"Operations\"\n metadata = {\n \"keywords\": [\n \"operations\",\n \"data operations\",\n \"json\",\n \"json operations\",\n \"table\",\n \"table operations\",\n \"dataframe\",\n \"dataframe operations\",\n \"text\",\n \"text operations\",\n \"select keys\",\n \"literal eval\",\n \"combine\",\n \"append or update\",\n \"remove keys\",\n \"rename keys\",\n \"path selection\",\n \"jq expression\",\n \"parse json\",\n \"add column\",\n \"concatenate\",\n \"drop column\",\n \"filter\",\n \"head\",\n \"merge\",\n \"rename column\",\n \"replace value\",\n \"select columns\",\n \"sort\",\n \"tail\",\n \"drop duplicates\",\n \"word count\",\n \"case conversion\",\n \"text replace\",\n \"text extract\",\n \"text join\",\n \"text clean\",\n \"text to dataframe\",\n \"data manipulation\",\n \"data transformation\",\n ],\n }\n\n # Operation -> operation-specific input fields to reveal when selected.\n OPERATION_FIELDS: dict[str, list[str]] = {\n # JSON\n \"Select Keys\": [\"select_keys_input\"],\n \"Literal Eval\": [],\n \"Combine\": [],\n \"Append or Update\": [\"append_update_data\"],\n \"Remove Keys\": [\"remove_keys_input\"],\n \"Rename Keys\": [\"rename_keys_input\"],\n \"Path Selection\": [\"mapped_json_display\", \"selected_key\"],\n \"JQ Expression\": [\"query\"],\n # Table\n \"Add Column\": [\"new_column_name\", \"new_column_value\"],\n \"Concatenate\": [],\n \"Drop Column\": [\"column_name\"],\n \"Filter\": [\"column_name\", \"filter_value\", \"filter_operator\"],\n \"Head\": [\"num_rows\"],\n \"Merge\": [\"left_dataframe\", \"right_dataframe\", \"merge_on_column\", \"merge_how\"],\n \"Rename Column\": [\"column_name\", \"new_column_name\"],\n \"Replace Value\": [\"column_name\", \"replace_value\", \"replacement_value\"],\n \"Select Columns\": [\"columns_to_select\"],\n \"Sort\": [\"column_name\", \"ascending\"],\n \"Tail\": [\"num_rows\"],\n \"Drop Duplicates\": [\"column_name\"],\n # Text\n \"Word Count\": [\"count_words\", \"count_characters\", \"count_lines\"],\n \"Case Conversion\": [\"case_type\"],\n \"Text Replace\": [\"search_pattern\", \"replacement_text\", \"use_regex\"],\n \"Text Extract\": [\"extract_pattern\", \"max_matches\"],\n \"Text Head\": [\"head_characters\"],\n \"Text Tail\": [\"tail_characters\"],\n \"Text Strip\": [\"strip_mode\", \"strip_characters\"],\n \"Text Join\": [\"text_input_2\"],\n \"Text Clean\": [\"remove_extra_spaces\", \"remove_special_chars\", \"remove_empty_lines\"],\n \"Text to DataFrame\": [\"table_separator\", \"has_header\"],\n }\n\n # The three main inputs (one per data type). They are never treated as\n # operation-specific fields; the input-type selector toggles them.\n MAIN_INPUTS = (\"text_input\", \"data\", \"df\")\n\n # Every operation-specific field (union of all the lists above), used to\n # hide and reset fields whenever the input type or operation changes.\n ALL_OPERATION_FIELDS: list[str] = [\n # JSON\n \"select_keys_input\",\n \"append_update_data\",\n \"remove_keys_input\",\n \"rename_keys_input\",\n \"mapped_json_display\",\n \"selected_key\",\n \"query\",\n # Table\n \"column_name\",\n \"filter_value\",\n \"filter_operator\",\n \"ascending\",\n \"new_column_name\",\n \"new_column_value\",\n \"columns_to_select\",\n \"num_rows\",\n \"replace_value\",\n \"replacement_value\",\n \"left_dataframe\",\n \"right_dataframe\",\n \"merge_on_column\",\n \"merge_how\",\n # Text\n \"table_separator\",\n \"has_header\",\n \"count_words\",\n \"count_characters\",\n \"count_lines\",\n \"case_type\",\n \"use_regex\",\n \"search_pattern\",\n \"replacement_text\",\n \"extract_pattern\",\n \"max_matches\",\n \"head_characters\",\n \"tail_characters\",\n \"strip_mode\",\n \"strip_characters\",\n \"text_input_2\",\n \"remove_extra_spaces\",\n \"remove_special_chars\",\n \"remove_empty_lines\",\n ]\n\n # Defaults applied to the JSON operation fields when the operation changes,\n # mirroring the JSON Operations component's reset behavior.\n OPERATION_FIELD_DEFAULTS: dict[str, Any] = {\n \"select_keys_input\": [],\n \"append_update_data\": {\"key\": \"value\"},\n \"remove_keys_input\": [],\n \"rename_keys_input\": {\"old_key\": \"new_key\"},\n \"mapped_json_display\": \"\",\n \"selected_key\": None,\n \"query\": \"\",\n }\n\n inputs = [\n # --- Input type selector: drives operations, input, and output ---\n TabInput(\n name=\"input_type\",\n display_name=\"Input Type\",\n options=INPUT_TYPES,\n value=\"Text\",\n info=\"Select the type of input to operate on.\",\n real_time_refresh=True,\n ),\n # --- Main inputs: one per data type, shown contextually ---\n MultilineInput(\n name=\"text_input\",\n display_name=\"Text\",\n info=\"The input text to process.\",\n show=True,\n ),\n DataInput(\n name=\"data\",\n display_name=\"JSON\",\n info=\"The JSON / Data object to operate on.\",\n is_list=True,\n show=False,\n ),\n DataFrameInput(\n name=\"df\",\n display_name=\"Table\",\n info=\"The input Table to operate on. Connect multiple Tables for merge or concatenate operations.\",\n is_list=True,\n show=False,\n ),\n # --- Operation picker (options are filtered by Input Type) ---\n SortableListInput(\n name=\"operation\",\n display_name=\"Operation\",\n placeholder=\"Select Operation\",\n info=\"Select the operation to perform. The matching fields and output appear once you choose one.\",\n options=OPERATIONS_BY_TYPE[\"Text\"],\n real_time_refresh=True,\n limit=1,\n ),\n # --- JSON operation fields ---\n MessageTextInput(\n name=\"select_keys_input\",\n display_name=\"Select Keys\",\n info=\"List of keys to select from the data. Only top-level keys can be selected.\",\n show=False,\n is_list=True,\n value=[],\n ),\n DictInput(\n name=\"append_update_data\",\n display_name=\"Append or Update\",\n info=\"Data to append or update the existing data with. Only top-level keys are checked.\",\n show=False,\n value={\"key\": \"value\"},\n is_list=True,\n ),\n MessageTextInput(\n name=\"remove_keys_input\",\n display_name=\"Remove Keys\",\n info=\"List of keys to remove from the data.\",\n show=False,\n is_list=True,\n value=[],\n ),\n DictInput(\n name=\"rename_keys_input\",\n display_name=\"Rename Keys\",\n info=\"List of keys to rename in the data.\",\n show=False,\n is_list=True,\n value={\"old_key\": \"new_key\"},\n ),\n MultilineInput(\n name=\"mapped_json_display\",\n display_name=\"JSON to Map\",\n info=\"Paste or preview your JSON here to explore its structure and select a path for extraction.\",\n required=False,\n refresh_button=True,\n real_time_refresh=True,\n placeholder=\"Add a JSON example.\",\n show=False,\n ),\n DropdownInput(\n name=\"selected_key\",\n display_name=\"Select Path\",\n options=[],\n required=False,\n dynamic=True,\n show=False,\n value=None,\n ),\n MessageTextInput(\n name=\"query\",\n display_name=\"JQ Expression\",\n info=\"JSON Query to filter the data. Used by Path Selection and JQ Expression operations.\",\n placeholder=\"e.g., .properties.id\",\n show=False,\n ),\n # --- Table operation fields ---\n StrInput(\n name=\"column_name\",\n display_name=\"Column Name\",\n info=\"The column name to use for the operation.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"filter_value\",\n display_name=\"Filter Value\",\n info=\"The value to filter rows by.\",\n dynamic=True,\n show=False,\n ),\n DropdownInput(\n name=\"filter_operator\",\n display_name=\"Filter Operator\",\n options=[\n \"equals\",\n \"not equals\",\n \"contains\",\n \"not contains\",\n \"starts with\",\n \"ends with\",\n \"greater than\",\n \"less than\",\n ],\n value=\"equals\",\n info=\"The operator to apply for filtering rows.\",\n advanced=False,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"ascending\",\n display_name=\"Sort Ascending\",\n info=\"Whether to sort in ascending order.\",\n dynamic=True,\n show=False,\n value=True,\n ),\n StrInput(\n name=\"new_column_name\",\n display_name=\"New Column Name\",\n info=\"The new column name when renaming or adding a column.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"new_column_value\",\n display_name=\"New Column Value\",\n info=\"The value to populate the new column with.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"columns_to_select\",\n display_name=\"Columns to Select\",\n dynamic=True,\n is_list=True,\n show=False,\n ),\n IntInput(\n name=\"num_rows\",\n display_name=\"Number of Rows\",\n info=\"Number of rows to return (for head/tail).\",\n dynamic=True,\n show=False,\n value=5,\n ),\n MessageTextInput(\n name=\"replace_value\",\n display_name=\"Value to Replace\",\n info=\"The value to replace in the column.\",\n dynamic=True,\n show=False,\n ),\n MessageTextInput(\n name=\"replacement_value\",\n display_name=\"Replacement Value\",\n info=\"The value to replace with.\",\n dynamic=True,\n show=False,\n ),\n DataFrameInput(\n name=\"left_dataframe\",\n display_name=\"Left Table\",\n info=\"The left (primary) Table for merge operations. \"\n \"In a left merge, all rows from this table are preserved.\",\n dynamic=True,\n show=False,\n ),\n DataFrameInput(\n name=\"right_dataframe\",\n display_name=\"Right Table\",\n info=\"The right (secondary) Table for merge operations. \"\n \"In a right merge, all rows from this table are preserved.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"merge_on_column\",\n display_name=\"Merge On Column\",\n info=\"The column name to merge Tables on. Must exist in both Tables.\",\n dynamic=True,\n show=False,\n ),\n DropdownInput(\n name=\"merge_how\",\n display_name=\"Merge Type\",\n options=[\"inner\", \"outer\", \"left\", \"right\"],\n value=\"inner\",\n info=\"Type of merge: inner (intersection), outer (union), left, or right.\",\n dynamic=True,\n show=False,\n ),\n # --- Text operation fields ---\n StrInput(\n name=\"table_separator\",\n display_name=\"Table Separator\",\n info=\"Separator used in the table (default: '|').\",\n value=\"|\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"has_header\",\n display_name=\"Has Header\",\n info=\"Whether the table has a header row.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_words\",\n display_name=\"Count Words\",\n info=\"Include word count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_characters\",\n display_name=\"Count Characters\",\n info=\"Include character count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n BoolInput(\n name=\"count_lines\",\n display_name=\"Count Lines\",\n info=\"Include line count in analysis.\",\n value=True,\n dynamic=True,\n advanced=True,\n show=False,\n ),\n DropdownInput(\n name=\"case_type\",\n display_name=\"Case Type\",\n options=[\"uppercase\", \"lowercase\", \"title\", \"capitalize\", \"swapcase\"],\n value=\"lowercase\",\n info=\"Type of case conversion to apply.\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"use_regex\",\n display_name=\"Use Regex\",\n info=\"Whether to treat search pattern as regex.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"search_pattern\",\n display_name=\"Search Pattern\",\n info=\"Text pattern to search for (supports regex).\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"replacement_text\",\n display_name=\"Replacement Text\",\n info=\"Text to replace the search pattern with.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"extract_pattern\",\n display_name=\"Extract Pattern\",\n info=\"Regex pattern to extract from text.\",\n dynamic=True,\n show=False,\n ),\n IntInput(\n name=\"max_matches\",\n display_name=\"Max Matches\",\n info=\"Maximum number of matches to extract.\",\n value=10,\n dynamic=True,\n show=False,\n ),\n IntInput(\n name=\"head_characters\",\n display_name=\"Characters from Start\",\n info=\"Number of characters to extract from the beginning of text. Must be non-negative.\",\n value=100,\n dynamic=True,\n show=False,\n range_spec=RangeSpec(min=0, max=1000000, step=1, step_type=\"int\"),\n ),\n IntInput(\n name=\"tail_characters\",\n display_name=\"Characters from End\",\n info=\"Number of characters to extract from the end of text. Must be non-negative.\",\n value=100,\n dynamic=True,\n show=False,\n range_spec=RangeSpec(min=0, max=1000000, step=1, step_type=\"int\"),\n ),\n DropdownInput(\n name=\"strip_mode\",\n display_name=\"Strip Mode\",\n options=[\"both\", \"left\", \"right\"],\n value=\"both\",\n info=\"Which sides to strip whitespace from.\",\n dynamic=True,\n show=False,\n ),\n StrInput(\n name=\"strip_characters\",\n display_name=\"Characters to Strip\",\n info=\"Specific characters to remove (leave empty for whitespace).\",\n value=\"\",\n dynamic=True,\n show=False,\n ),\n MultilineInput(\n name=\"text_input_2\",\n display_name=\"Second Text Input\",\n info=\"Second text to join with the first text.\",\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_extra_spaces\",\n display_name=\"Remove Extra Spaces\",\n info=\"Remove multiple consecutive spaces.\",\n value=True,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_special_chars\",\n display_name=\"Remove Special Characters\",\n info=\"Remove special characters except alphanumeric and spaces.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n BoolInput(\n name=\"remove_empty_lines\",\n display_name=\"Remove Empty Lines\",\n info=\"Remove empty lines from text.\",\n value=False,\n dynamic=True,\n show=False,\n ),\n ]\n\n # Default output matches the default Input Type (\"Text\" -> Message).\n # update_outputs / update_frontend_node narrow it to the selected type and\n # operation.\n outputs = [Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\")]\n\n # ------------------------------------------------------------------\n # Operation routing helpers\n # ------------------------------------------------------------------\n @staticmethod\n def _extract_operation_name(field_value: Any) -> str:\n \"\"\"Extract the operation name from a SortableListInput value.\"\"\"\n if isinstance(field_value, list) and len(field_value) > 0 and isinstance(field_value[0], dict):\n return field_value[0].get(\"name\", \"\")\n if isinstance(field_value, str):\n return field_value\n return \"\"\n\n def _operation_name(self) -> str:\n \"\"\"Get the currently selected operation name.\"\"\"\n return self._extract_operation_name(getattr(self, \"operation\", []))\n\n @staticmethod\n def _default_output_for_type(input_type: str) -> Output:\n \"\"\"Return the output advertised for an input type when no operation is selected yet.\"\"\"\n if input_type == \"JSON\":\n return Output(display_name=\"JSON\", name=\"data_output\", method=\"as_data\")\n if input_type == \"Table\":\n return Output(display_name=\"Table\", name=\"dataframe_output\", method=\"as_dataframe\")\n return Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\")\n\n # ------------------------------------------------------------------\n # Dynamic UI\n # ------------------------------------------------------------------\n def _reset_operation_fields(self, build_config: dotdict) -> None:\n \"\"\"Hide every operation-specific field and restore its default value.\"\"\"\n for field in self.ALL_OPERATION_FIELDS:\n if field in build_config:\n build_config[field][\"show\"] = False\n if field in self.OPERATION_FIELD_DEFAULTS:\n build_config[field][\"value\"] = self.OPERATION_FIELD_DEFAULTS[field]\n\n def _show_main_input(self, build_config: dotdict, input_type: str, operation: str) -> None:\n \"\"\"Show only the main input that matches the input type; hide the others.\"\"\"\n for inp in self.MAIN_INPUTS:\n if inp in build_config:\n build_config[inp][\"show\"] = False\n build_config[inp][\"required\"] = False\n\n main_input = INPUT_TYPE_TO_MAIN_INPUT.get(input_type)\n if main_input and main_input in build_config:\n build_config[main_input][\"show\"] = True\n build_config[main_input][\"required\"] = True\n # The JSON \"Combine\" operation consumes a list of Data objects.\n if main_input == \"data\":\n build_config[\"data\"][\"is_list\"] = operation == \"Combine\"\n\n def update_build_config(self, build_config: dotdict, field_value: Any, field_name: str | None = None) -> dotdict:\n # Path Selection: refresh the available JSON paths from the pasted JSON.\n if field_name == \"mapped_json_display\":\n try:\n parsed_json = json.loads(field_value)\n keys = self.extract_all_paths(parsed_json)\n build_config[\"selected_key\"][\"options\"] = keys\n build_config[\"selected_key\"][\"show\"] = True\n except (json.JSONDecodeError, TypeError, ValueError) as e:\n logger.error(f\"Error parsing mapped JSON: {e}\")\n build_config[\"selected_key\"][\"show\"] = False\n return build_config\n\n # Input type changed: swap the operation list, clear the selection, and\n # show only the matching input. No operation-specific fields are shown\n # until an operation is picked.\n if field_name == \"input_type\":\n input_type = field_value if field_value in OPERATIONS_BY_TYPE else \"Text\"\n build_config[\"operation\"][\"options\"] = OPERATIONS_BY_TYPE[input_type]\n build_config[\"operation\"][\"value\"] = []\n self._reset_operation_fields(build_config)\n self._show_main_input(build_config, input_type, operation=\"\")\n return build_config\n\n # Operation changed: reset fields, show the input for the current type,\n # then reveal the operation-specific fields.\n if field_name == \"operation\":\n operation = self._extract_operation_name(field_value)\n self._reset_operation_fields(build_config)\n\n input_type = build_config.get(\"input_type\", {}).get(\"value\", \"Text\")\n self._show_main_input(build_config, input_type, operation)\n\n for field in self.OPERATION_FIELDS.get(operation, []):\n if field in build_config:\n build_config[field][\"show\"] = True\n\n return build_config\n\n return build_config\n\n def update_outputs(self, frontend_node: dict, field_name: str, field_value: Any) -> dict:\n \"\"\"Create the output(s) appropriate to the selected input type and operation.\"\"\"\n if field_name == \"input_type\":\n # Switching type clears the operation; advertise the type's default.\n input_type = field_value if field_value in OPERATIONS_BY_TYPE else \"Text\"\n frontend_node[\"outputs\"] = [self._default_output_for_type(input_type)]\n return frontend_node\n\n template = frontend_node.get(\"template\", {})\n input_type = template.get(\"input_type\", {}).get(\"value\", \"Text\")\n\n if field_name == \"operation\":\n operation = self._extract_operation_name(field_value)\n else:\n # Any other refresh (e.g. Path Selection's \"JSON to Map\" field)\n # reaches here on a freshly rebuilt node whose outputs were reset\n # to the class default (Message). Re-derive the output from the\n # saved operation so the refresh doesn't swap the real output type.\n operation = self._extract_operation_name(template.get(\"operation\", {}).get(\"value\", []))\n\n if not operation:\n # No operation selected: fall back to the input type's default output.\n frontend_node[\"outputs\"] = [self._default_output_for_type(input_type)]\n return frontend_node\n\n frontend_node[\"outputs\"] = []\n if operation in JSON_OPERATIONS or operation == \"Word Count\":\n frontend_node[\"outputs\"].append(Output(display_name=\"JSON\", name=\"data_output\", method=\"as_data\"))\n elif operation in TABLE_OPERATIONS or operation == \"Text to DataFrame\":\n frontend_node[\"outputs\"].append(\n Output(display_name=\"Table\", name=\"dataframe_output\", method=\"as_dataframe\")\n )\n elif operation == \"Text Join\":\n frontend_node[\"outputs\"].append(Output(display_name=\"Text\", name=\"text_output\", method=\"as_text\"))\n frontend_node[\"outputs\"].append(Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\"))\n else:\n frontend_node[\"outputs\"].append(Output(display_name=\"Message\", name=\"message_output\", method=\"as_message\"))\n\n return frontend_node\n\n async def update_frontend_node(self, new_frontend_node: dict, current_frontend_node: dict) -> dict:\n \"\"\"Keep the operation options and outputs in sync with the saved input type on load.\"\"\"\n await super().update_frontend_node(new_frontend_node, current_frontend_node)\n\n template = new_frontend_node.get(\"template\", {})\n input_type = template.get(\"input_type\", {}).get(\"value\", \"Text\")\n if input_type not in OPERATIONS_BY_TYPE:\n input_type = \"Text\"\n\n # Filter the operation picker to the saved input type.\n if \"operation\" in template:\n template[\"operation\"][\"options\"] = OPERATIONS_BY_TYPE[input_type]\n\n # Re-derive the outputs from the saved input type + operation.\n operation_value = template.get(\"operation\", {}).get(\"value\", [])\n if self._extract_operation_name(operation_value):\n self.update_outputs(new_frontend_node, \"operation\", operation_value)\n else:\n self.update_outputs(new_frontend_node, \"input_type\", input_type)\n\n return new_frontend_node\n\n # ==================================================================\n # Output methods (referenced by update_outputs)\n # ==================================================================\n def as_data(self) -> Data:\n \"\"\"JSON-typed output: JSON operations and Word Count.\"\"\"\n operation = self._operation_name()\n if operation in JSON_OPERATIONS:\n handler = self._json_handlers().get(operation)\n if handler:\n try:\n return handler()\n except Exception as e:\n logger.error(f\"Error executing {operation}: {e!s}\")\n raise\n if operation == \"Word Count\":\n return self._word_count_data()\n return Data(data={})\n\n def as_dataframe(self) -> DataFrame:\n \"\"\"Table-typed output: Table operations and Text to DataFrame.\"\"\"\n operation = self._operation_name()\n if operation in TABLE_OPERATIONS:\n return self._run_table_operation(operation)\n if operation == \"Text to DataFrame\":\n return self._text_to_dataframe(getattr(self, \"text_input\", \"\") or \"\")\n return DataFrame(pd.DataFrame())\n\n def as_message(self) -> Message:\n \"\"\"Message-typed output: generic text operations (and Text Join).\"\"\"\n return Message(text=self._format_result_as_text(self._run_text_operation()))\n\n def as_text(self) -> Message:\n \"\"\"Text output for the Text Join operation.\"\"\"\n return self.as_message()\n\n # ==================================================================\n # JSON operations\n # ==================================================================\n @staticmethod\n def extract_all_paths(obj, path=\"\"):\n paths = []\n if isinstance(obj, dict):\n for k, v in obj.items():\n new_path = f\"{path}.{k}\" if path else f\".{k}\"\n paths.append(new_path)\n paths.extend(OperationsComponent.extract_all_paths(v, new_path))\n elif isinstance(obj, list) and obj:\n new_path = f\"{path}[0]\"\n paths.append(new_path)\n paths.extend(OperationsComponent.extract_all_paths(obj[0], new_path))\n return paths\n\n @staticmethod\n def remove_keys_recursive(obj, keys_to_remove):\n if isinstance(obj, dict):\n return {\n k: OperationsComponent.remove_keys_recursive(v, keys_to_remove)\n for k, v in obj.items()\n if k not in keys_to_remove\n }\n if isinstance(obj, list):\n return [OperationsComponent.remove_keys_recursive(item, keys_to_remove) for item in obj]\n return obj\n\n @staticmethod\n def rename_keys_recursive(obj, rename_map):\n if isinstance(obj, dict):\n return {\n rename_map.get(k, k): OperationsComponent.rename_keys_recursive(v, rename_map) for k, v in obj.items()\n }\n if isinstance(obj, list):\n return [OperationsComponent.rename_keys_recursive(item, rename_map) for item in obj]\n return obj\n\n def _json_handlers(self) -> \"dict[str, Callable[[], Data]]\":\n return {\n \"Select Keys\": self.select_keys,\n \"Literal Eval\": self.evaluate_data,\n \"Combine\": self.combine_data,\n \"Append or Update\": self.append_update,\n \"Remove Keys\": self.remove_keys,\n \"Rename Keys\": self.rename_keys,\n \"Path Selection\": self.json_path,\n \"JQ Expression\": self.json_query,\n }\n\n def get_data_dict(self) -> dict:\n \"\"\"Extract data dictionary from Data object.\"\"\"\n data = self.data[0] if isinstance(self.data, list) and len(self.data) == 1 else self.data\n return data.model_dump()\n\n def get_normalized_data(self) -> dict:\n \"\"\"Get normalized data dictionary, handling the 'data' key if present.\"\"\"\n data_dict = self.get_data_dict()\n return data_dict.get(\"data\", data_dict)\n\n def data_is_list(self) -> bool:\n \"\"\"Check if data contains multiple items.\"\"\"\n return isinstance(self.data, list) and len(self.data) > 1\n\n def validate_single_data(self, operation: str) -> None:\n \"\"\"Validate that the operation is being performed on a single data object.\"\"\"\n if self.data_is_list():\n msg = f\"{operation} operation is not supported for multiple data objects.\"\n raise ValueError(msg)\n\n def select_keys(self) -> Data:\n \"\"\"Select specific keys from the data dictionary.\"\"\"\n self.validate_single_data(\"Select Keys\")\n data_dict = self.get_normalized_data()\n filter_criteria: list[str] = self.select_keys_input\n\n if len(filter_criteria) == 1 and filter_criteria[0] == \"data\":\n filtered = data_dict[\"data\"]\n else:\n if not all(key in data_dict for key in filter_criteria):\n msg = f\"Select key not found in data. Available keys: {list(data_dict.keys())}\"\n raise ValueError(msg)\n filtered = {key: value for key, value in data_dict.items() if key in filter_criteria}\n\n return Data(data=filtered)\n\n def remove_keys(self) -> Data:\n \"\"\"Remove specified keys from the data dictionary, recursively.\"\"\"\n self.validate_single_data(\"Remove Keys\")\n data_dict = self.get_normalized_data()\n remove_keys_input: list[str] = self.remove_keys_input\n filtered = OperationsComponent.remove_keys_recursive(data_dict, set(remove_keys_input))\n return Data(data=filtered)\n\n def rename_keys(self) -> Data:\n \"\"\"Rename keys in the data dictionary, recursively.\"\"\"\n self.validate_single_data(\"Rename Keys\")\n data_dict = self.get_normalized_data()\n rename_keys_input: dict[str, str] = self.rename_keys_input\n renamed = OperationsComponent.rename_keys_recursive(data_dict, rename_keys_input)\n return Data(data=renamed)\n\n def recursive_eval(self, data: Any) -> Any:\n \"\"\"Recursively evaluate string values that look like Python literals.\"\"\"\n if isinstance(data, dict):\n return {k: self.recursive_eval(v) for k, v in data.items()}\n if isinstance(data, list):\n return [self.recursive_eval(item) for item in data]\n if isinstance(data, str):\n try:\n if (\n data.strip().startswith((\"{\", \"[\", \"(\", \"'\", '\"'))\n or data.strip().lower() in (\"true\", \"false\", \"none\")\n or data.strip().replace(\".\", \"\").isdigit()\n ):\n return ast.literal_eval(data)\n except (ValueError, SyntaxError, TypeError, MemoryError):\n return data\n else:\n return data\n return data\n\n def evaluate_data(self) -> Data:\n \"\"\"Evaluate string values in the data dictionary.\"\"\"\n self.validate_single_data(\"Literal Eval\")\n logger.info(\"evaluating data\")\n return Data(**self.recursive_eval(self.get_data_dict()))\n\n def combine_data(self) -> Data:\n \"\"\"Combine multiple data objects into one.\"\"\"\n logger.info(\"combining data\")\n if not self.data_is_list():\n return self.data[0] if self.data else Data(data={})\n\n data_dicts = [data.model_dump().get(\"data\", data.model_dump()) for data in self.data]\n combined_data: dict[str, Any] = {}\n\n for data_dict in data_dicts:\n for key, value in data_dict.items():\n if key not in combined_data:\n combined_data[key] = value\n elif isinstance(combined_data[key], list):\n if isinstance(value, list):\n combined_data[key].extend(value)\n else:\n combined_data[key].append(value)\n else:\n combined_data[key] = (\n [combined_data[key], value] if not isinstance(value, list) else [combined_data[key], *value]\n )\n\n return Data(**combined_data)\n\n def append_update(self) -> Data:\n \"\"\"Append or update the data with new key-value pairs.\"\"\"\n self.validate_single_data(\"Append or Update\")\n data_filtered = self.get_normalized_data()\n for key, value in self.append_update_data.items():\n data_filtered[key] = value\n return Data(**data_filtered)\n\n def json_path(self) -> Data:\n \"\"\"Extract a value from the data using the selected JQ path.\"\"\"\n try:\n import jq\n except ImportError:\n msg = \"jq is required for Path Selection. Install with: pip install jq\"\n raise ImportError(msg) from None\n\n try:\n if not self.data or not self.selected_key:\n msg = \"Missing input data or selected key.\"\n raise ValueError(msg)\n input_payload = self.data[0].data if isinstance(self.data, list) else self.data.data\n validate_jq_program(self.selected_key)\n compiled = jq.compile(self.selected_key)\n result = compiled.input(input_payload).first()\n if isinstance(result, dict):\n return Data(data=result)\n return Data(data={\"result\": result})\n except (ValueError, TypeError, KeyError) as e:\n self.status = f\"Error: {e!s}\"\n self.log(self.status)\n return Data(data={\"error\": str(e)})\n\n def json_query(self) -> Data:\n \"\"\"Run a JQ expression against the data.\"\"\"\n try:\n import jq\n except ImportError:\n msg = \"jq is required for JQ Expression. Install with: pip install jq\"\n raise ImportError(msg) from None\n\n if not self.query or not self.query.strip():\n msg = \"JSON Query is required and cannot be blank.\"\n raise ValueError(msg)\n raw_data = self.get_data_dict()\n try:\n input_str = json.dumps(raw_data)\n repaired = repair_json(input_str)\n data_json = json.loads(repaired)\n jq_input = data_json[\"data\"] if isinstance(data_json, dict) and \"data\" in data_json else data_json\n validate_jq_program(self.query)\n results = jq.compile(self.query).input(jq_input).all()\n if not results:\n msg = \"No result from JSON query.\"\n raise ValueError(msg)\n result = results[0] if len(results) == 1 else results\n if result is None or result == \"None\":\n msg = \"JSON query returned null/None. Check if the path exists in your data.\"\n raise ValueError(msg)\n if isinstance(result, dict):\n return Data(data=result)\n return Data(data={\"result\": result})\n except (ValueError, TypeError, KeyError, json.JSONDecodeError) as e:\n logger.error(f\"JSON Query failed: {e}\")\n msg = f\"JSON Query error: {e}\"\n raise ValueError(msg) from e\n\n # ==================================================================\n # Table operations\n # ==================================================================\n def _get_primary_dataframe(self) -> DataFrame:\n \"\"\"Get the first DataFrame from input (handles both single and list inputs).\"\"\"\n if isinstance(self.df, list):\n return self.df[0].copy() if self.df else DataFrame()\n return self.df.copy()\n\n def _run_table_operation(self, operation: str) -> DataFrame:\n # Merge and Concatenate use their own inputs, not the primary df.\n if operation == \"Merge\":\n return self.merge_dataframes()\n if operation == \"Concatenate\":\n return self.concatenate_dataframes()\n\n df_copy = self._get_primary_dataframe()\n table_handlers = {\n \"Filter\": self.filter_rows_by_value,\n \"Sort\": self.sort_by_column,\n \"Drop Column\": self.drop_column,\n \"Rename Column\": self.rename_column,\n \"Add Column\": self.add_column,\n \"Select Columns\": self.select_columns,\n \"Head\": self.head,\n \"Tail\": self.tail,\n \"Replace Value\": self.replace_values,\n \"Drop Duplicates\": self.drop_duplicates,\n }\n handler = table_handlers.get(operation)\n if handler is None:\n msg = f\"Unsupported operation: {operation}\"\n logger.error(msg)\n raise ValueError(msg)\n return handler(df_copy)\n\n def filter_rows_by_value(self, df: DataFrame) -> DataFrame:\n column = df[self.column_name]\n filter_value = self.filter_value\n operator = getattr(self, \"filter_operator\", \"equals\")\n\n if operator == \"equals\":\n mask = column == filter_value\n elif operator == \"not equals\":\n mask = column != filter_value\n elif operator == \"contains\":\n mask = column.astype(str).str.contains(str(filter_value), na=False)\n elif operator == \"not contains\":\n mask = ~column.astype(str).str.contains(str(filter_value), na=False)\n elif operator == \"starts with\":\n mask = column.astype(str).str.startswith(str(filter_value), na=False)\n elif operator == \"ends with\":\n mask = column.astype(str).str.endswith(str(filter_value), na=False)\n elif operator == \"greater than\":\n try:\n numeric_value = pd.to_numeric(filter_value)\n mask = column > numeric_value\n except (ValueError, TypeError):\n mask = column.astype(str) > str(filter_value)\n elif operator == \"less than\":\n try:\n numeric_value = pd.to_numeric(filter_value)\n mask = column < numeric_value\n except (ValueError, TypeError):\n mask = column.astype(str) < str(filter_value)\n else:\n mask = column == filter_value\n\n return DataFrame(df[mask])\n\n def sort_by_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.sort_values(by=self.column_name, ascending=self.ascending))\n\n def drop_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.drop(columns=[self.column_name]))\n\n def rename_column(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.rename(columns={self.column_name: self.new_column_name}))\n\n def add_column(self, df: DataFrame) -> DataFrame:\n df[self.new_column_name] = [self.new_column_value] * len(df)\n return DataFrame(df)\n\n def select_columns(self, df: DataFrame) -> DataFrame:\n columns = [col.strip() for col in self.columns_to_select]\n return DataFrame(df[columns])\n\n def head(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.head(self.num_rows))\n\n def tail(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.tail(self.num_rows))\n\n def replace_values(self, df: DataFrame) -> DataFrame:\n df[self.column_name] = df[self.column_name].replace(self.replace_value, self.replacement_value)\n return DataFrame(df)\n\n def drop_duplicates(self, df: DataFrame) -> DataFrame:\n return DataFrame(df.drop_duplicates(subset=self.column_name))\n\n def concatenate_dataframes(self) -> DataFrame:\n \"\"\"Concatenate multiple DataFrames vertically (stack rows).\"\"\"\n if not isinstance(self.df, list) or len(self.df) == 0:\n return self.df.copy() if self.df is not None else DataFrame()\n\n if len(self.df) == 1:\n return self.df[0].copy()\n\n concatenated = pd.concat(self.df, ignore_index=True)\n return DataFrame(concatenated)\n\n def merge_dataframes(self) -> DataFrame:\n \"\"\"Merge two DataFrames based on a common column (join operation).\"\"\"\n left_df = getattr(self, \"left_dataframe\", None)\n right_df = getattr(self, \"right_dataframe\", None)\n\n if left_df is None:\n return DataFrame()\n if right_df is None:\n return left_df.copy()\n\n df_left = left_df.copy()\n df_right = right_df.copy()\n\n merge_on = getattr(self, \"merge_on_column\", None)\n merge_how = getattr(self, \"merge_how\", \"inner\")\n\n if merge_on:\n if merge_on not in df_left.columns:\n msg = f\"Column '{merge_on}' not found in left DataFrame. Available: {list(df_left.columns)}\"\n raise ValueError(msg)\n if merge_on not in df_right.columns:\n msg = f\"Column '{merge_on}' not found in right DataFrame. Available: {list(df_right.columns)}\"\n raise ValueError(msg)\n merged = df_left.merge(df_right, on=merge_on, how=merge_how, suffixes=(\"\", \"_right\"))\n else:\n merged = df_left.merge(df_right, left_index=True, right_index=True, how=merge_how, suffixes=(\"\", \"_right\"))\n\n cols_to_drop = []\n for col in merged.columns:\n if col.endswith(\"_right\"):\n original_col = col[:-6]\n if original_col in merged.columns:\n merged[original_col] = merged[original_col].combine_first(merged[col])\n cols_to_drop.append(col)\n\n if cols_to_drop:\n merged = merged.drop(columns=cols_to_drop)\n\n return DataFrame(merged)\n\n # ==================================================================\n # Text operations\n # ==================================================================\n def _run_text_operation(self) -> Any:\n \"\"\"Process text based on the selected operation (Message/Text outputs).\"\"\"\n text = getattr(self, \"text_input\", \"\")\n operation = self._operation_name()\n\n # Allow empty text for Text Join (second input may have content).\n if not text and operation != \"Text Join\":\n return None\n\n text_handlers = {\n \"Case Conversion\": self._case_conversion,\n \"Text Replace\": self._text_replace,\n \"Text Extract\": self._text_extract,\n \"Text Head\": self._text_head,\n \"Text Tail\": self._text_tail,\n \"Text Strip\": self._text_strip,\n \"Text Join\": self._text_join,\n \"Text Clean\": self._text_clean,\n }\n handler = text_handlers.get(operation)\n if handler:\n return handler(text)\n return text\n\n def _word_count_data(self) -> Data:\n \"\"\"Word Count operation result as a Data object.\"\"\"\n result = self._word_count(getattr(self, \"text_input\", \"\") or \"\")\n return Data(data=result)\n\n def _word_count(self, text: str) -> dict[str, Any]:\n \"\"\"Count words, characters, and lines in text.\"\"\"\n result: dict[str, Any] = {}\n text_str = str(text) if text else \"\"\n is_empty = not text_str or not text_str.strip()\n\n if getattr(self, \"count_words\", True):\n if is_empty:\n result[\"word_count\"] = 0\n result[\"unique_words\"] = 0\n else:\n words = text_str.split()\n result[\"word_count\"] = len(words)\n result[\"unique_words\"] = len(set(words))\n\n if getattr(self, \"count_characters\", True):\n if is_empty:\n result[\"character_count\"] = 0\n result[\"character_count_no_spaces\"] = 0\n else:\n result[\"character_count\"] = len(text_str)\n result[\"character_count_no_spaces\"] = len(text_str.replace(\" \", \"\"))\n\n if getattr(self, \"count_lines\", True):\n if is_empty:\n result[\"line_count\"] = 0\n result[\"non_empty_lines\"] = 0\n else:\n lines = text_str.split(\"\\n\")\n result[\"line_count\"] = len(lines)\n result[\"non_empty_lines\"] = len([line for line in lines if line.strip()])\n\n return result\n\n def _text_to_dataframe(self, text: str) -> DataFrame:\n \"\"\"Convert markdown-style table text to a DataFrame.\"\"\"\n lines = [line.strip() for line in text.strip().split(\"\\n\") if line.strip()]\n if not lines:\n return DataFrame(pd.DataFrame())\n\n separator = getattr(self, \"table_separator\", \"|\")\n has_header = getattr(self, \"has_header\", True)\n\n rows = self._parse_table_rows(lines, separator)\n if not rows:\n return DataFrame(pd.DataFrame())\n\n df = self._create_dataframe(rows, has_header=has_header)\n self._convert_numeric_columns(df)\n self.log(f\"Converted text to DataFrame: {len(df)} rows, {len(df.columns)} columns\")\n return DataFrame(df)\n\n def _parse_table_rows(self, lines: list[str], separator: str) -> list[list[str]]:\n rows = []\n for line in lines:\n cleaned_line = line.strip(separator)\n cells = [cell.strip() for cell in cleaned_line.split(separator)]\n rows.append(cells)\n return rows\n\n def _create_dataframe(self, rows: list[list[str]], *, has_header: bool) -> pd.DataFrame:\n if has_header and len(rows) > 1:\n header = rows[0]\n data_rows = rows[1:]\n header_col_count = len(header)\n for i, row in enumerate(data_rows):\n row_col_count = len(row)\n if row_col_count != header_col_count:\n msg = (\n f\"Header mismatch: {header_col_count} column(s) in header vs \"\n f\"{row_col_count} column(s) in data row {i + 1}. \"\n \"Please ensure the header has the same number of columns as your data.\"\n )\n raise ValueError(msg)\n return pd.DataFrame(data_rows, columns=header)\n\n max_cols = max(len(row) for row in rows) if rows else 0\n columns = [f\"col_{i}\" for i in range(max_cols)]\n return pd.DataFrame(rows, columns=columns)\n\n def _convert_numeric_columns(self, df: pd.DataFrame) -> None:\n for col in df.columns:\n with contextlib.suppress(ValueError, TypeError):\n df[col] = pd.to_numeric(df[col])\n\n def _case_conversion(self, text: str) -> str:\n case_type = getattr(self, \"case_type\", \"lowercase\")\n converter = CASE_CONVERTERS.get(case_type)\n return converter(text) if converter else text\n\n def _text_replace(self, text: str) -> str:\n search_pattern = getattr(self, \"search_pattern\", \"\")\n if not search_pattern:\n return text\n replacement_text = getattr(self, \"replacement_text\", \"\")\n use_regex = getattr(self, \"use_regex\", False)\n if use_regex:\n try:\n return re.sub(search_pattern, replacement_text, text)\n except re.error as e:\n self.log(f\"Invalid regex pattern: {e}\")\n return text\n return text.replace(search_pattern, replacement_text)\n\n def _text_extract(self, text: str) -> list[str]:\n extract_pattern = getattr(self, \"extract_pattern\", \"\")\n if not extract_pattern:\n return []\n max_matches = getattr(self, \"max_matches\", 10)\n try:\n matches = re.findall(extract_pattern, text)\n except re.error as e:\n msg = f\"Invalid regex pattern '{extract_pattern}': {e}\"\n raise ValueError(msg) from e\n return matches[:max_matches] if max_matches > 0 else matches\n\n def _text_head(self, text: str) -> str:\n head_characters = getattr(self, \"head_characters\", 100)\n if head_characters < 0:\n msg = f\"Characters from Start must be a non-negative integer, got {head_characters}\"\n raise ValueError(msg)\n if head_characters == 0:\n return \"\"\n return text[:head_characters]\n\n def _text_tail(self, text: str) -> str:\n tail_characters = getattr(self, \"tail_characters\", 100)\n if tail_characters < 0:\n msg = f\"Characters from End must be a non-negative integer, got {tail_characters}\"\n raise ValueError(msg)\n if tail_characters == 0:\n return \"\"\n return text[-tail_characters:]\n\n def _text_strip(self, text: str) -> str:\n strip_mode = getattr(self, \"strip_mode\", \"both\")\n strip_characters = getattr(self, \"strip_characters\", \"\")\n text_str = str(text) if text else \"\"\n chars_to_strip = strip_characters if strip_characters else None\n if strip_mode == \"left\":\n return text_str.lstrip(chars_to_strip)\n if strip_mode == \"right\":\n return text_str.rstrip(chars_to_strip)\n return text_str.strip(chars_to_strip)\n\n def _text_join(self, text: str) -> str:\n text_input_2 = getattr(self, \"text_input_2\", \"\")\n text1 = str(text) if text else \"\"\n text2 = str(text_input_2) if text_input_2 else \"\"\n if text1 and text2:\n return f\"{text1}\\n{text2}\"\n return text1 or text2\n\n def _text_clean(self, text: str) -> str:\n result = text\n if getattr(self, \"remove_extra_spaces\", True):\n # Collapse runs of horizontal whitespace but preserve newlines so\n # that remove_empty_lines stays effective when both are enabled.\n result = re.sub(r\"[^\\S\\n]+\", \" \", result)\n if getattr(self, \"remove_special_chars\", False):\n result = re.sub(r\"[^\\w\\s]\", \"\", result)\n if getattr(self, \"remove_empty_lines\", False):\n lines = [line for line in result.split(\"\\n\") if line.strip()]\n result = \"\\n\".join(lines)\n return result\n\n def _format_result_as_text(self, result: Any) -> str:\n if result is None:\n return \"\"\n if isinstance(result, list):\n return \"\\n\".join(str(item) for item in result)\n return str(result)\n"},"column_name": {"_input_type": "StrInput",@@ -4858,6 +4583,7 @@"display_name": "Input Type","dynamic": false,"info": "Select the type of input to operate on.",+ "load_from_db": false,"name": "input_type","options": ["Text",@@ -5085,6 +4811,7 @@"dynamic": false,"info": "Select the operation to perform. The matching fields and output appear once you choose one.","limit": 1,+ "load_from_db": false,"name": "operation","options": [{@@ -5735,7 +5462,7 @@"api_editable": false,"display_name": "OpenAI API Base","dynamic": false,- "info": "Must end with /v1 (for example http://openrag-backend:8000/v1). Bound to OPENRAG_LLM_BASE_URL at runtime. Same URL as chat.",+ "info": "Bound to OPENRAG_LLM_BASE_URL at runtime. It is either the public /v1 base or the private router base. Same URL as chat.","list": false,"list_add_label": "Add More","load_from_db": true,@@ -5870,7 +5597,7 @@"x": 2026.2607693884997,"y": 1754.074435768159},- "selected": true,+ "selected": false,"type": "genericNode"},{@@ -6332,34 +6059,257 @@"_input_type": "StrInput","advanced": true,"api_editable": false,- "display_name": "JWT Header Name",+ "display_name": "JWT Header Name",+ "dynamic": false,+ "info": "",+ "list": false,+ "list_add_label": "Add More",+ "load_from_db": false,+ "name": "jwt_header",+ "override_skip": false,+ "placeholder": "",+ "required": false,+ "show": false,+ "title_case": false,+ "tool_mode": false,+ "trace_as_metadata": true,+ "track_in_telemetry": false,+ "type": "str",+ "value": "Authorization"+ },+ "jwt_token": {+ "_input_type": "SecretStrInput",+ "advanced": false,+ "api_editable": false,+ "display_name": "JWT Token",+ "dynamic": false,+ "info": "Valid JSON Web Token for authentication. Will be sent in the Authorization header (with optional 'Bearer ' prefix).",+ "input_types": [],+ "load_from_db": false,+ "name": "jwt_token",+ "override_skip": false,+ "password": true,+ "placeholder": "",+ "required": false,+ "show": false,+ "title_case": false,+ "track_in_telemetry": false,+ "type": "str",+ "value": ""+ },+ "m": {+ "_input_type": "IntInput",+ "advanced": true,+ "api_editable": false,+ "display_name": "M Parameter",+ "dynamic": false,+ "info": "Number of bidirectional connections for each vector in the HNSW graph. Higher values improve search quality but increase memory usage and indexing time.",+ "list": false,+ "list_add_label": "Add More",+ "name": "m",+ "override_skip": false,+ "placeholder": "",+ "required": false,+ "show": true,+ "title_case": false,+ "tool_mode": false,+ "trace_as_metadata": true,+ "track_in_telemetry": true,+ "type": "int",+ "value": 16+ },+ "max_retries": {+ "_input_type": "StrInput",+ "advanced": true,+ "api_editable": false,+ "display_name": "Max Retries",+ "dynamic": false,+ "info": "Number of retries for failed connections before raising an error.",+ "list": false,+ "list_add_label": "Add More",+ "load_from_db": false,+ "name": "max_retries",+ "override_skip": false,+ "placeholder": "",+ "required": false,+ "show": true,+ "title_case": false,+ "tool_mode": false,+ "trace_as_metadata": true,+ "track_in_telemetry": false,+ "type": "str",+ "value": "3"+ },+ "num_candidates": {+ "_input_type": "IntInput",+ "advanced": true,+ "api_editable": false,+ "display_name": "Candidate Pool Size",+ "dynamic": false,+ "info": "Number of approximate neighbors to consider for each KNN query. Some OpenSearch deployments do not support this parameter; set to 0 to disable.",+ "list": false,+ "list_add_label": "Add More",+ "name": "num_candidates",+ "override_skip": false,+ "placeholder": "",+ "required": false,+ "show": true,+ "title_case": false,+ "tool_mode": false,+ "trace_as_metadata": true,+ "track_in_telemetry": true,+ "type": "int",+ "value": 1000+ },+ "number_of_results": {+ "_input_type": "IntInput",+ "advanced": true,+ "api_editable": false,+ "display_name": "Default Result Limit",+ "dynamic": false,+ "info": "Default maximum number of search results to return when no limit is specified in the filter expression.",+ "list": false,+ "list_add_label": "Add More",+ "name": "number_of_results",+ "override_skip": false,+ "placeholder": "",+ "required": false,+ "show": true,+ "title_case": false,+ "tool_mode": false,+ "trace_as_metadata": true,+ "track_in_telemetry": true,+ "type": "int",+ "value": 10+ },+ "openrag_ingest_batch_size": {+ "_input_type": "IntInput",+ "advanced": false,+ "api_editable": false,+ "display_name": "OpenRAG Ingest Batch Size",+ "dynamic": false,+ "info": "",+ "list": false,+ "list_add_label": "Add More",+ "name": "openrag_ingest_batch_size",+ "override_skip": false,+ "placeholder": "",+ "required": false,+ "show": true,+ "title_case": false,+ "tool_mode": false,+ "trace_as_metadata": true,+ "track_in_telemetry": true,+ "type": "int",+ "value": 100+ },+ "openrag_ingest_run_id": {+ "_input_type": "StrInput",+ "advanced": false,+ "api_editable": false,+ "display_name": "OpenRAG Ingest Run ID",+ "dynamic": false,+ "info": "",+ "input_types": [+ "Text",+ "Message"+ ],+ "list": false,+ "list_add_label": "Add More",+ "load_from_db": true,+ "name": "openrag_ingest_run_id",+ "override_skip": false,+ "placeholder": "",+ "required": true,+ "show": true,+ "title_case": false,+ "tool_mode": false,+ "trace_as_metadata": true,+ "track_in_telemetry": false,+ "type": "str",+ "value": "OPENRAG_INGEST_RUN_ID"+ },+ "openrag_ingest_token": {+ "_input_type": "SecretStrInput",+ "advanced": false,+ "api_editable": false,+ "display_name": "OpenRAG Ingest Token",+ "dynamic": false,+ "info": "Short-lived token used only for OpenRAG ingest callbacks.",+ "input_types": [+ "Text",+ "Message"+ ],+ "load_from_db": true,+ "name": "openrag_ingest_token",+ "override_skip": false,+ "password": true,+ "placeholder": "",+ "required": true,+ "show": true,+ "title_case": false,+ "track_in_telemetry": false,+ "type": "str",+ "value": "OPENRAG_INGEST_TOKEN"+ },+ "openrag_ingest_url": {+ "_input_type": "StrInput",+ "advanced": false,+ "api_editable": false,+ "display_name": "OpenRAG Ingest URL",+ "dynamic": false,+ "info": "Internal OpenRAG callback URL for backend-owned document indexing.",+ "input_types": [+ "Text",+ "Message"+ ],+ "list": false,+ "list_add_label": "Add More",+ "load_from_db": true,+ "name": "openrag_ingest_url",+ "override_skip": false,+ "placeholder": "",+ "required": true,+ "show": true,+ "title_case": false,+ "tool_mode": false,+ "trace_as_metadata": true,+ "track_in_telemetry": false,+ "type": "str",+ "value": "OPENRAG_INGEST_URL"+ },+ "opensearch_url": {+ "_input_type": "StrInput",+ "advanced": false,+ "api_editable": false,+ "display_name": "OpenSearch URL","dynamic": false,- "info": "",+ "info": "The connection URL for your OpenSearch cluster (e.g., http://localhost:9200 for local development or your cloud endpoint).","list": false,"list_add_label": "Add More",- "load_from_db": false,- "name": "jwt_header",+ "load_from_db": true,+ "name": "opensearch_url","override_skip": false,"placeholder": "","required": false,- "show": false,+ "show": true,"title_case": false,"tool_mode": false,"trace_as_metadata": true,"track_in_telemetry": false,"type": "str",- "value": "Authorization"+ "value": "OPENSEARCH_URL"},- "jwt_token": {+ "password": {"_input_type": "SecretStrInput","advanced": false,"api_editable": false,- "display_name": "JWT Token",+ "display_name": "OpenSearch Password","dynamic": false,- "info": "Valid JSON Web Token for authentication. Will be sent in the Authorization header (with optional 'Bearer ' prefix).",+ "info": "","input_types": [],- "load_from_db": false,- "name": "jwt_token",+ "load_from_db": true,+ "name": "password","override_skip": false,"password": true,"placeholder": "",@@ -6368,18 +6318,19 @@"title_case": false,"track_in_telemetry": false,"type": "str",- "value": ""+ "value": "OPENSEARCH_PASSWORD"},- "m": {- "_input_type": "IntInput",+ "request_timeout": {+ "_input_type": "StrInput","advanced": true,"api_editable": false,- "display_name": "M Parameter",+ "display_name": "Request Timeout (seconds)","dynamic": false,- "info": "Number of bidirectional connections for each vector in the HNSW graph. Higher values improve search quality but increase memory usage and indexing time.",+ "info": "Time in seconds to wait for a response from OpenSearch. Increase for large bulk ingestion or complex hybrid queries.","list": false,"list_add_label": "Add More",- "name": "m",+ "load_from_db": false,+ "name": "request_timeout","override_skip": false,"placeholder": "","required": false,@@ -6387,42 +6338,46 @@"title_case": false,"tool_mode": false,"trace_as_metadata": true,- "track_in_telemetry": true,- "type": "int",- "value": 16+ "track_in_telemetry": false,+ "type": "str",+ "value": "60"},- "max_retries": {- "_input_type": "StrInput",- "advanced": true,+ "search_query": {+ "_input_type": "QueryInput",+ "advanced": false,"api_editable": false,- "display_name": "Max Retries",+ "display_name": "Search Query","dynamic": false,- "info": "Number of retries for failed connections before raising an error.",+ "info": "Enter a query to run a similarity search.",+ "input_types": [+ "Message"+ ],"list": false,"list_add_label": "Add More","load_from_db": false,- "name": "max_retries",+ "name": "search_query","override_skip": false,- "placeholder": "",+ "placeholder": "Enter a query...","required": false,"show": true,"title_case": false,- "tool_mode": false,+ "tool_mode": true,+ "trace_as_input": true,"trace_as_metadata": true,"track_in_telemetry": false,- "type": "str",- "value": "3"+ "type": "query",+ "value": ""},- "num_candidates": {- "_input_type": "IntInput",+ "should_cache_vector_store": {+ "_input_type": "BoolInput","advanced": true,"api_editable": false,- "display_name": "Candidate Pool Size",+ "display_name": "Cache Vector Store","dynamic": false,- "info": "Number of approximate neighbors to consider for each KNN query. Some OpenSearch deployments do not support this parameter; set to 0 to disable.",+ "info": "If True, the vector store will be cached for the current build of the component. This is useful for components that have multiple output methods and want to share the same vector store.","list": false,"list_add_label": "Add More",- "name": "num_candidates",+ "name": "should_cache_vector_store","override_skip": false,"placeholder": "","required": false,@@ -6431,40 +6386,50 @@"tool_mode": false,"trace_as_metadata": true,"track_in_telemetry": true,- "type": "int",- "value": 1000+ "type": "bool",+ "value": true},- "number_of_results": {- "_input_type": "IntInput",+ "space_type": {+ "_input_type": "DropdownInput","advanced": true,"api_editable": false,- "display_name": "Default Result Limit",+ "combobox": false,+ "dialog_inputs": {},+ "display_name": "Distance Metric","dynamic": false,- "info": "Default maximum number of search results to return when no limit is specified in the filter expression.",- "list": false,- "list_add_label": "Add More",- "name": "number_of_results",+ "external_options": {},+ "info": "Distance metric for calculating vector similarity. 'l2' (Euclidean) is most common, 'cosinesimil' for cosine similarity, 'innerproduct' for dot product.",+ "name": "space_type",+ "options": [+ "l2",+ "l1",+ "cosinesimil",+ "linf",+ "innerproduct"+ ],+ "options_metadata": [],"override_skip": false,"placeholder": "","required": false,"show": true,"title_case": false,+ "toggle": false,"tool_mode": false,"trace_as_metadata": true,"track_in_telemetry": true,- "type": "int",- "value": 10+ "type": "str",+ "value": "l2"},- "openrag_ingest_batch_size": {- "_input_type": "IntInput",- "advanced": false,+ "use_ssl": {+ "_input_type": "BoolInput",+ "advanced": true,"api_editable": false,- "display_name": "OpenRAG Ingest Batch Size",+ "display_name": "Use SSL/TLS","dynamic": false,- "info": "",+ "info": "Enable SSL/TLS encryption for secure connections to OpenSearch.","list": false,"list_add_label": "Add More",- "name": "openrag_ingest_batch_size",+ "name": "use_ssl","override_skip": false,"placeholder": "","required": false,@@ -6473,95 +6438,195 @@"tool_mode": false,"trace_as_metadata": true,"track_in_telemetry": true,- "type": "int",- "value": 100+ "type": "bool",+ "value": true},- "openrag_ingest_run_id": {+ "username": {"_input_type": "StrInput","advanced": false,"api_editable": false,- "display_name": "OpenRAG Ingest Run ID",+ "display_name": "Username","dynamic": false,"info": "",- "input_types": [- "Text",- "Message"- ],"list": false,"list_add_label": "Add More",- "load_from_db": true,- "name": "openrag_ingest_run_id",+ "load_from_db": false,+ "name": "username","override_skip": false,"placeholder": "",- "required": true,+ "required": false,+ "show": false,+ "title_case": false,+ "tool_mode": false,+ "trace_as_metadata": true,+ "track_in_telemetry": false,+ "type": "str",+ "value": "admin"+ },+ "vector_field": {+ "_input_type": "StrInput",+ "advanced": true,+ "api_editable": false,+ "display_name": "Legacy Vector Field Name",+ "dynamic": false,+ "info": "Legacy field name for backward compatibility. New documents use dynamic fields (chunk_embedding_{model_name}) based on the embedding_model_name.",+ "list": false,+ "list_add_label": "Add More",+ "load_from_db": false,+ "name": "vector_field",+ "override_skip": false,+ "placeholder": "",+ "required": false,"show": true,"title_case": false,"tool_mode": false,"trace_as_metadata": true,"track_in_telemetry": false,"type": "str",- "value": "OPENRAG_INGEST_RUN_ID"+ "value": "chunk_embedding"},- "openrag_ingest_token": {- "_input_type": "SecretStrInput",- "advanced": false,+ "verify_certs": {+ "_input_type": "BoolInput",+ "advanced": true,"api_editable": false,- "display_name": "OpenRAG Ingest Token",+ "display_name": "Verify SSL Certificates","dynamic": false,- "info": "Short-lived token used only for OpenRAG ingest callbacks.",- "input_types": [- "Text",- "Message"+ "info": "Verify SSL certificates when connecting. Disable for self-signed certificates in development environments.",+ "list": false,+ "list_add_label": "Add More",+ "name": "verify_certs",+ "override_skip": false,+ "placeholder": "",+ "required": false,+ "show": true,+ "title_case": false,+ "tool_mode": false,+ "trace_as_metadata": true,+ "track_in_telemetry": true,+ "type": "bool",+ "value": false+ }+ },+ "tool_mode": false+ },+ "selected_output": "search_results",+ "showNode": false,+ "type": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra"+ },+ "dragging": false,+ "id": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKf",+ "measured": {+ "height": 188,+ "width": 192+ },+ "position": {+ "x": 2376.807670689636,+ "y": 1551.0689633093473+ },+ "selected": false,+ "type": "genericNode"+ },+ {+ "data": {+ "id": "ext:openrag:OpenRAGSplitTextComponent@extra-tutKN",+ "node": {+ "base_classes": [+ "Table"+ ],+ "beta": false,+ "bundle": "openrag",+ "conditional_paths": [],+ "custom_fields": {},+ "description": "Split text into chunks no longer than the chunk size.",+ "display_name": "Split Text",+ "documentation": "https://docs.langflow.org/split-text",+ "edited": false,+ "extension": "openrag",+ "extension_version": "0.0.0",+ "field_order": [+ "data_inputs",+ "chunk_overlap",+ "chunk_size",+ "separator",+ "text_key",+ "keep_separator",+ "clean_output"+ ],+ "frozen": false,+ "icon": "scissors-line-dashed",+ "legacy": false,+ "legacy_module": "split_text",+ "metadata": {+ "code_hash": "a94056a09995",+ "dependencies": {+ "dependencies": [+ {+ "name": "langchain_text_splitters",+ "version": "1.1.2"+ },+ {+ "name": "lfx",+ "version": "1.12.3"+ }+ ],+ "total_dependencies": 2+ },+ "module": "_lfx_ext.extra.openrag.split_text"+ },+ "minimized": false,+ "name": "OpenRAGSplitText",+ "namespaced_id": "ext:openrag:OpenRAGSplitTextComponent@extra",+ "output_types": [],+ "outputs": [+ {+ "allows_loop": false,+ "cache": true,+ "display_name": "Chunks",+ "group_outputs": false,+ "method": "split_text",+ "name": "dataframe",+ "selected": "Table",+ "tool_mode": true,+ "types": [+ "Table"],- "load_from_db": true,- "name": "openrag_ingest_token",- "override_skip": false,- "password": true,- "placeholder": "",- "required": true,- "show": true,- "title_case": false,- "track_in_telemetry": false,- "type": "str",- "value": "OPENRAG_INGEST_TOKEN"- },- "openrag_ingest_url": {- "_input_type": "StrInput",+ "value": "__UNDEFINED__"+ }+ ],+ "pinned": false,+ "template": {+ "_type": "Component",+ "chunk_overlap": {+ "_input_type": "IntInput","advanced": false,"api_editable": false,- "display_name": "OpenRAG Ingest URL",+ "display_name": "Chunk Overlap","dynamic": false,- "info": "Internal OpenRAG callback URL for backend-owned document indexing.",- "input_types": [- "Text",- "Message"- ],+ "info": "Number of characters to overlap between chunks.","list": false,"list_add_label": "Add More",- "load_from_db": true,- "name": "openrag_ingest_url",+ "name": "chunk_overlap","override_skip": false,"placeholder": "",- "required": true,+ "required": false,"show": true,"title_case": false,"tool_mode": false,"trace_as_metadata": true,- "track_in_telemetry": false,- "type": "str",- "value": "OPENRAG_INGEST_URL"+ "track_in_telemetry": true,+ "type": "int",+ "value": 200},- "opensearch_url": {- "_input_type": "StrInput",+ "chunk_size": {+ "_input_type": "IntInput","advanced": false,"api_editable": false,- "display_name": "OpenSearch URL",+ "display_name": "Chunk Size","dynamic": false,- "info": "The connection URL for your OpenSearch cluster (e.g., http://localhost:9200 for local development or your cloud endpoint).",+ "info": "The maximum length of each chunk. Text is split on the separator first; any piece still longer than this is split on finer boundaries (lines, sentences, spaces, then characters).","list": false,"list_add_label": "Add More",- "load_from_db": true,- "name": "opensearch_url",+ "name": "chunk_size","override_skip": false,"placeholder": "","required": false,@@ -6569,116 +6634,93 @@"title_case": false,"tool_mode": false,"trace_as_metadata": true,- "track_in_telemetry": false,- "type": "str",- "value": "OPENSEARCH_URL"+ "track_in_telemetry": true,+ "type": "int",+ "value": 1000},- "password": {- "_input_type": "SecretStrInput",- "advanced": false,+ "clean_output": {+ "_input_type": "BoolInput",+ "advanced": true,"api_editable": false,- "display_name": "OpenSearch Password",+ "display_name": "Clean Output","dynamic": false,- "info": "",- "input_types": [],- "load_from_db": true,- "name": "password",+ "info": "When enabled, only the text column is included in the output. Metadata columns are removed.",+ "list": false,+ "list_add_label": "Add More",+ "name": "clean_output","override_skip": false,- "password": true,"placeholder": "","required": false,- "show": false,+ "show": true,"title_case": false,- "track_in_telemetry": false,- "type": "str",- "value": "OPENSEARCH_PASSWORD"+ "tool_mode": false,+ "trace_as_metadata": true,+ "track_in_telemetry": true,+ "type": "bool",+ "value": false},- "request_timeout": {- "_input_type": "StrInput",+ "code": {"advanced": true,"api_editable": false,- "display_name": "Request Timeout (seconds)",- "dynamic": false,- "info": "Time in seconds to wait for a response from OpenSearch. Increase for large bulk ingestion or complex hybrid queries.",+ "dynamic": true,+ "fileTypes": [],+ "file_path": "",+ "info": "","list": false,- "list_add_label": "Add More","load_from_db": false,- "name": "request_timeout",- "override_skip": false,+ "multiline": true,+ "name": "code",+ "password": false,"placeholder": "",- "required": false,+ "required": true,"show": true,"title_case": false,- "tool_mode": false,- "trace_as_metadata": true,- "track_in_telemetry": false,- "type": "str",- "value": "60"+ "type": "code",+ "value": "from langchain_text_splitters import RecursiveCharacterTextSplitter\nfrom lfx.custom.custom_component.component import Component\nfrom lfx.io import BoolInput, DropdownInput, HandleInput, IntInput, MessageTextInput, Output\nfrom lfx.schema.data import Data\nfrom lfx.schema.dataframe import DataFrame\nfrom lfx.schema.message import Message\nfrom lfx.utils.util import unescape_string\n\n# Tried in order after the configured separator. Docling joins consecutive\n# lines that have no blank line between them into one Markdown paragraph, so a\n# long document can arrive with almost no newlines; without these fallbacks a\n# single paragraph becomes one chunk of any size.\nFALLBACK_SEPARATORS = (\"\\n\\n\", \"\\n\", \"。\", \". \", \" \", \"\")\n\n\ndef build_separators(separator: str) -> list[str]:\n separators = [separator] if separator else []\n separators += [s for s in FALLBACK_SEPARATORS if s not in separators]\n return separators\n\n\nclass OpenRAGSplitTextComponent(Component):\n display_name: str = \"Split Text\"\n description: str = \"Split text into chunks no longer than the chunk size.\"\n documentation: str = \"https://docs.langflow.org/split-text\"\n icon = \"scissors-line-dashed\"\n # Distinct from Langflow's built-in \"SplitText\": in restricted mode Langflow\n # replaces drifted code of a known built-in type with its own copy.\n name = \"OpenRAGSplitText\"\n\n inputs = [\n HandleInput(\n name=\"data_inputs\",\n display_name=\"Input\",\n info=\"The data with texts to split in chunks.\",\n input_types=[\"Data\", \"JSON\", \"DataFrame\", \"Table\", \"Message\"],\n required=True,\n ),\n IntInput(\n name=\"chunk_overlap\",\n display_name=\"Chunk Overlap\",\n info=\"Number of characters to overlap between chunks.\",\n value=200,\n ),\n IntInput(\n name=\"chunk_size\",\n display_name=\"Chunk Size\",\n info=(\n \"The maximum length of each chunk. Text is split on the separator first; \"\n \"any piece still longer than this is split on finer boundaries \"\n \"(lines, sentences, spaces, then characters).\"\n ),\n value=1000,\n ),\n MessageTextInput(\n name=\"separator\",\n display_name=\"Separator\",\n info=(\n \"The preferred character to split on. Use \\\\n for newline. \"\n \"Examples: \\\\n\\\\n for paragraphs, \\\\n for lines, . for sentences\"\n ),\n value=\"\\n\",\n ),\n MessageTextInput(\n name=\"text_key\",\n display_name=\"Text Key\",\n info=\"The key to use for the text column.\",\n value=\"text\",\n advanced=True,\n ),\n DropdownInput(\n name=\"keep_separator\",\n display_name=\"Keep Separator\",\n info=\"Whether to keep the separator in the output chunks and where to place it.\",\n options=[\"False\", \"True\", \"Start\", \"End\"],\n value=\"False\",\n advanced=True,\n ),\n BoolInput(\n name=\"clean_output\",\n display_name=\"Clean Output\",\n info=\"When enabled, only the text column is included in the output. Metadata columns are removed.\",\n value=False,\n advanced=True,\n ),\n ]\n\n outputs = [\n Output(display_name=\"Chunks\", name=\"dataframe\", method=\"split_text\"),\n ]\n\n def _docs_to_data(self, docs, *, clean: bool = False) -> list[Data]:\n return [\n Data(text=doc.page_content) if clean else Data(text=doc.page_content, data=doc.metadata)\n for doc in docs\n ]\n\n def _fix_separator(self, separator: str) -> str:\n \"\"\"Fix common separator issues and convert to proper format.\"\"\"\n if separator == \"/n\":\n return \"\\n\"\n if separator == \"/t\":\n return \"\\t\"\n return separator\n\n def split_text_base(self):\n separator = self._fix_separator(self.separator)\n separator = unescape_string(separator)\n\n if isinstance(self.data_inputs, DataFrame):\n if not len(self.data_inputs):\n msg = \"DataFrame is empty\"\n raise TypeError(msg)\n\n self.data_inputs.text_key = self.text_key\n try:\n documents = self.data_inputs.to_lc_documents()\n except Exception as e:\n msg = f\"Error converting DataFrame to documents: {e}\"\n raise TypeError(msg) from e\n elif isinstance(self.data_inputs, Message):\n self.data_inputs = [self.data_inputs.to_data()]\n return self.split_text_base()\n else:\n if not self.data_inputs:\n msg = \"No data inputs provided\"\n raise TypeError(msg)\n\n documents = []\n if isinstance(self.data_inputs, Data):\n self.data_inputs.text_key = self.text_key\n documents = [self.data_inputs.to_lc_document()]\n else:\n try:\n documents = [\n input_.to_lc_document()\n for input_ in self.data_inputs\n if isinstance(input_, Data)\n ]\n if not documents:\n msg = f\"No valid Data inputs found in {type(self.data_inputs)}\"\n raise TypeError(msg)\n except AttributeError as e:\n msg = f\"Invalid input type in collection: {e}\"\n raise TypeError(msg) from e\n try:\n # Convert string 'False'/'True' to boolean\n keep_sep = self.keep_separator\n if isinstance(keep_sep, str):\n keep_sep = keep_sep.lower()\n if keep_sep == \"false\":\n keep_sep = False\n elif keep_sep == \"true\":\n keep_sep = True\n # LangChain only recognises lowercase 'start' and 'end'\n\n splitter = RecursiveCharacterTextSplitter(\n chunk_overlap=self.chunk_overlap,\n chunk_size=self.chunk_size,\n separators=build_separators(separator),\n keep_separator=keep_sep,\n )\n return splitter.split_documents(documents)\n except Exception as e:\n msg = f\"Error splitting text: {e}\"\n raise TypeError(msg) from e\n\n def split_text(self) -> DataFrame:\n docs = self.split_text_base()\n df = DataFrame(self._docs_to_data(docs, clean=self.clean_output))\n return df if self.clean_output else df.smart_column_order()\n"},- "search_query": {- "_input_type": "QueryInput",+ "data_inputs": {+ "_input_type": "HandleInput","advanced": false,"api_editable": false,- "display_name": "Search Query",+ "display_name": "Input","dynamic": false,- "info": "Enter a query to run a similarity search.",+ "info": "The data with texts to split in chunks.","input_types": [+ "Data",+ "JSON",+ "DataFrame",+ "Table","Message"],"list": false,"list_add_label": "Add More",- "load_from_db": false,- "name": "search_query",+ "name": "data_inputs","override_skip": false,- "placeholder": "Enter a query...",- "required": false,+ "placeholder": "",+ "required": true,"show": true,"title_case": false,- "tool_mode": true,- "trace_as_input": true,"trace_as_metadata": true,"track_in_telemetry": false,- "type": "query",+ "type": "other","value": ""},- "should_cache_vector_store": {- "_input_type": "BoolInput",- "advanced": true,- "api_editable": false,- "display_name": "Cache Vector Store",- "dynamic": false,- "info": "If True, the vector store will be cached for the current build of the component. This is useful for components that have multiple output methods and want to share the same vector store.",- "list": false,- "list_add_label": "Add More",- "name": "should_cache_vector_store",- "override_skip": false,- "placeholder": "",- "required": false,- "show": true,- "title_case": false,- "tool_mode": false,- "trace_as_metadata": true,- "track_in_telemetry": true,- "type": "bool",- "value": true- },- "space_type": {+ "keep_separator": {"_input_type": "DropdownInput","advanced": true,"api_editable": false,"combobox": false,"dialog_inputs": {},- "display_name": "Distance Metric",+ "display_name": "Keep Separator","dynamic": false,"external_options": {},- "info": "Distance metric for calculating vector similarity. 'l2' (Euclidean) is most common, 'cosinesimil' for cosine similarity, 'innerproduct' for dot product.",- "name": "space_type",+ "info": "Whether to keep the separator in the output chunks and where to place it.",+ "name": "keep_separator","options": [- "l2",- "l1",- "cosinesimil",- "linf",- "innerproduct"+ "False",+ "True",+ "Start",+ "End"],"options_metadata": [],"override_skip": false,@@ -6691,126 +6733,91 @@"trace_as_metadata": true,"track_in_telemetry": true,"type": "str",- "value": "l2"- },- "use_ssl": {- "_input_type": "BoolInput",- "advanced": true,- "api_editable": false,- "display_name": "Use SSL/TLS",- "dynamic": false,- "info": "Enable SSL/TLS encryption for secure connections to OpenSearch.",- "list": false,- "list_add_label": "Add More",- "name": "use_ssl",- "override_skip": false,- "placeholder": "",- "required": false,- "show": true,- "title_case": false,- "tool_mode": false,- "trace_as_metadata": true,- "track_in_telemetry": true,- "type": "bool",- "value": true+ "value": "False"},- "username": {- "_input_type": "StrInput",+ "separator": {+ "_input_type": "MessageTextInput","advanced": false,"api_editable": false,- "display_name": "Username",+ "display_name": "Separator","dynamic": false,- "info": "",+ "info": "The preferred character to split on. Use \\n for newline. Examples: \\n\\n for paragraphs, \\n for lines, . for sentences",+ "input_types": [+ "Message"+ ],"list": false,"list_add_label": "Add More","load_from_db": false,- "name": "username",+ "name": "separator","override_skip": false,"placeholder": "","required": false,- "show": false,+ "show": true,"title_case": false,"tool_mode": false,+ "trace_as_input": true,"trace_as_metadata": true,"track_in_telemetry": false,"type": "str",- "value": "admin"+ "value": "\n"},- "vector_field": {- "_input_type": "StrInput",+ "text_key": {+ "_input_type": "MessageTextInput","advanced": true,"api_editable": false,- "display_name": "Legacy Vector Field Name",+ "display_name": "Text Key","dynamic": false,- "info": "Legacy field name for backward compatibility. New documents use dynamic fields (chunk_embedding_{model_name}) based on the embedding_model_name.",+ "info": "The key to use for the text column.",+ "input_types": [+ "Message"+ ],"list": false,"list_add_label": "Add More","load_from_db": false,- "name": "vector_field",+ "name": "text_key","override_skip": false,"placeholder": "","required": false,"show": true,"title_case": false,"tool_mode": false,+ "trace_as_input": true,"trace_as_metadata": true,"track_in_telemetry": false,"type": "str",- "value": "chunk_embedding"- },- "verify_certs": {- "_input_type": "BoolInput",- "advanced": true,- "api_editable": false,- "display_name": "Verify SSL Certificates",- "dynamic": false,- "info": "Verify SSL certificates when connecting. Disable for self-signed certificates in development environments.",- "list": false,- "list_add_label": "Add More",- "name": "verify_certs",- "override_skip": false,- "placeholder": "",- "required": false,- "show": true,- "title_case": false,- "tool_mode": false,- "trace_as_metadata": true,- "track_in_telemetry": true,- "type": "bool",- "value": false+ "value": "text"}},"tool_mode": false},- "selected_output": "search_results","showNode": false,- "type": "ext:openrag:OpenSearchVectorStoreComponentMultimodalMultiEmbedding@extra"+ "type": "ext:openrag:OpenRAGSplitTextComponent@extra"},"dragging": false,- "id": "OpenSearchVectorStoreComponentMultimodalMultiEmbedding-dihKf",+ "id": "ext:openrag:OpenRAGSplitTextComponent@extra-tutKN","measured": {- "height": 188,+ "height": 80,"width": 192},"position": {- "x": 2376.807670689636,- "y": 1551.0689633093473+ "x": 2035.3566968494886,+ "y": 1554.1985641894335},"selected": false,"type": "genericNode"}],"viewport": {- "x": -436.49158784467363,- "y": -524.7268247650767,- "zoom": 0.5381200623918984+ "x": -600.99465524025,+ "y": -544.8939772193618,+ "zoom": 0.5452796392357185}},"description": "This flow is to ingest the URL to open search.","endpoint_name": null,"id": "72c3d17c-2dac-4a73-b48a-6518473d7830","is_component": false,- "last_tested_version": "0.11.6",+ "last_tested_version": "1.12.3","mcp_enabled": true,"locked": true,"name": "OpenSearch URL Ingestion Flow",@@ -6820,4 +6827,4 @@"rag","q-a"]-}+}\ No newline at end of filediff --git a/pyproject.toml b/pyproject.tomlindex e09cef211..57b8315af 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -98,6 +98,8 @@ dev = ["mypy>=2.0.0",# The tracing extra, so its unit tests (tests/unit/observability) run."langfuse>=4.16,<5",+ # Used by the Langflow Split Text component, so its unit tests run the real splitter.+ "langchain-text-splitters>=1.1.2,<2",][project.scripts]diff --git a/src/utils/document_processing.py b/src/utils/document_processing.pyindex 7d063c1f3..e4b002d4a 100644--- a/src/utils/document_processing.py+++ b/src/utils/document_processing.py@@ -1,4 +1,5 @@import os+import reimport unicodedatafrom collections import defaultdict@@ -24,6 +25,43 @@ def normalize_cjk_radicals(text: str) -> str:return text.translate(_CJK_RADICAL_TABLE)+_SENTENCE_END = re.compile(r"(?<=[。.!?.!?])")+++def split_to_size(+ text: str, limit: int, levels: tuple[str, ...] = ("line", "sentence")+) -> list[str]:+ """Split text into pieces of at most ``limit`` characters.++ Cuts on line breaks first, then after sentence-ending punctuation, and only+ then at a fixed character count, so pieces end at natural boundaries when+ the text has any.+ """+ if len(text) <= limit:+ return [text]+ if not levels:+ return [text[i : i + limit] for i in range(0, len(text), limit)]+ if levels[0] == "line":+ parts, joiner = text.split("\n"), "\n"+ else:+ parts, joiner = _SENTENCE_END.split(text), ""++ pieces: list[str] = []+ current = ""+ for part in parts:+ for sub in split_to_size(part, limit, levels[1:]):+ candidate = f"{current}{joiner}{sub}" if current else sub+ if len(candidate) <= limit:+ current = candidate+ else:+ if current:+ pieces.append(current)+ current = sub+ if current:+ pieces.append(current)+ return pieces++def process_text_file(file_path: str) -> dict:"""Process a plain text file without using docling.@@ -55,8 +93,12 @@ def process_text_file(file_path: str) -> dict:current_chunk = ""chunk_index = 0- for para in paragraphs:- para = para.strip()+ # A file with no blank lines is one paragraph, so oversized paragraphs are+ # cut on lines and sentences before packing.+ pieces = (+ piece.strip() for para in paragraphs for piece in split_to_size(para.strip(), chunk_size)+ )+ for para in pieces:if not para:continuediff --git a/tests/unit/test_document_processing_text_file.py b/tests/unit/test_document_processing_text_file.pynew file mode 100644index 000000000..2834e0394--- /dev/null+++ b/tests/unit/test_document_processing_text_file.py@@ -0,0 +1,45 @@+"""Plain-text files are chunked to size even when they have no blank lines."""++from src.utils.document_processing import process_text_file, split_to_size+++def test_file_without_blank_lines_is_chunked_on_lines(tmp_path):+ lines = [f"第{i}行は日本の首都について説明する短い一文である。" for i in range(2000)]+ path = tmp_path / "wiki.txt"+ path.write_text("\n".join(lines) + "\n", encoding="utf-8")++ chunks = process_text_file(str(path))["chunks"]++ assert len(chunks) > 1+ assert max(len(chunk["text"]) for chunk in chunks) <= 1000+ joined = "\n".join(chunk["text"] for chunk in chunks)+ assert all(line in joined for line in lines)+++def test_paragraph_breaks_are_still_used_when_present(tmp_path):+ paragraphs = [f"Paragraph {i}. " + "word " * 40 for i in range(30)]+ path = tmp_path / "notes.txt"+ path.write_text("\n\n".join(paragraphs), encoding="utf-8")++ chunks = process_text_file(str(path))["chunks"]++ for chunk in chunks:+ assert all(+ part.strip() in [p.strip() for p in paragraphs] for part in chunk["text"].split("\n\n")+ )+++def test_split_to_size_prefers_sentences_over_hard_cuts():+ text = "".join(f"これは{i}番目の文です。" for i in range(200))++ pieces = split_to_size(text, 100)++ assert max(len(piece) for piece in pieces) <= 100+ assert "".join(pieces) == text+ assert all(piece.endswith("。") for piece in pieces)+++def test_split_to_size_hard_cuts_text_with_no_boundaries():+ pieces = split_to_size("x" * 2500, 1000)++ assert [len(piece) for piece in pieces] == [1000, 1000, 500]diff --git a/tests/unit/test_openrag_split_text_component.py b/tests/unit/test_openrag_split_text_component.pynew file mode 100644index 000000000..0dd4e571e--- /dev/null+++ b/tests/unit/test_openrag_split_text_component.py@@ -0,0 +1,168 @@+"""The ingest flow's Split Text component never returns a chunk over chunk_size.++Docling joins consecutive lines that have no blank line between them into one+Markdown paragraph, so a plain-text file with one sentence per line reaches the+splitter as a few huge newline-free paragraphs. Langflow's built-in Split Text+only cuts on its separator, and kept each such paragraph as a single chunk of+hundreds of thousands of characters.+"""++import hashlib+import importlib+import importlib.util+import json+import sys+from pathlib import Path+from types import ModuleType++import pytest+from langchain_core.documents import Document++BUNDLE = Path("custom_components/openrag")+SOURCE = BUNDLE / "split_text.py"+NODE_TYPE = "ext:openrag:OpenRAGSplitTextComponent@extra"+FLOWS_WITH_SPLITTER = ("ingestion_flow.json", "openrag_url_mcp.json")+++class FakeData:+ def __init__(self, text: str = "", data: dict | None = None) -> None:+ self.text = text+ self.data = data or {}+ self.text_key = "text"++ def to_lc_document(self) -> Document:+ return Document(page_content=self.text, metadata=dict(self.data))+++class FakeInput:+ def __init__(self, **kwargs: object) -> None:+ self.name = kwargs.get("name")+++def component_module(monkeypatch: pytest.MonkeyPatch):+ modules = {+ name: ModuleType(name)+ for name in (+ "lfx",+ "lfx.custom",+ "lfx.custom.custom_component",+ "lfx.custom.custom_component.component",+ "lfx.io",+ "lfx.schema",+ "lfx.schema.data",+ "lfx.schema.dataframe",+ "lfx.schema.message",+ "lfx.utils",+ "lfx.utils.util",+ )+ }+ vars(modules["lfx.custom.custom_component.component"])["Component"] = object+ for input_name in (+ "BoolInput",+ "DropdownInput",+ "HandleInput",+ "IntInput",+ "MessageTextInput",+ "Output",+ ):+ setattr(modules["lfx.io"], input_name, FakeInput)+ vars(modules["lfx.schema.data"])["Data"] = FakeData+ vars(modules["lfx.schema.dataframe"])["DataFrame"] = type("DataFrame", (), {})+ vars(modules["lfx.schema.message"])["Message"] = type("Message", (), {})+ vars(modules["lfx.utils.util"])["unescape_string"] = lambda s: s.replace("\\n", "\n")+ for name, module in modules.items():+ monkeypatch.setitem(sys.modules, name, module)++ module_name = "custom_components.openrag.split_text"+ sys.modules.pop(module_name, None)+ yield importlib.import_module(module_name)+ sys.modules.pop(module_name, None)+++def _split(module, text: str, *, chunk_size=1000, chunk_overlap=200, separator="\\n"):+ component = module.OpenRAGSplitTextComponent()+ component.data_inputs = [FakeData(text, {"filename": "wiki.txt"})]+ component.chunk_size = chunk_size+ component.chunk_overlap = chunk_overlap+ component.separator = separator+ component.text_key = "text"+ component.keep_separator = "False"+ return component.split_text_base()+++def _sentences(count: int) -> list[str]:+ return [f"東京は日本の首都であり、第{i}番目の文はここで終わる。" for i in range(count)]+++def test_newline_free_paragraph_is_split_to_chunk_size(component_module):+ sentences = _sentences(5000)+ text = " ".join(sentences)+ assert "\n" not in text++ docs = _split(component_module, text)++ assert len(docs) > 1+ assert max(len(doc.page_content) for doc in docs) <= 1000+ joined = "\n".join(doc.page_content for doc in docs)+ # With Keep Separator off, a "。" that falls on a chunk boundary is dropped.+ assert all(sentence.rstrip("。") in joined for sentence in sentences)+ assert all(doc.metadata == {"filename": "wiki.txt"} for doc in docs)+++def test_single_long_line_among_short_lines_is_split(component_module):+ long_line = "x" * 5000+ text = "\n".join(["short line one", long_line, "short line two"])++ docs = _split(component_module, text)++ assert max(len(doc.page_content) for doc in docs) <= 1000+ assert sum(doc.page_content.count("x") for doc in docs) >= 5000+++def test_configured_separator_is_still_preferred(component_module):+ lines = [f"line {i:03d} " + "y" * 80 for i in range(40)]++ docs = _split(component_module, "\n".join(lines))++ for doc in docs:+ assert all(part in lines for part in doc.page_content.split("\n"))+++def test_separators_try_the_configured_one_first_without_duplicates(component_module):+ separators = component_module.build_separators("\n")++ assert separators[0] == "\n"+ assert separators[-1] == ""+ assert len(separators) == len(set(separators))+ assert "。" in separators+++def test_component_type_differs_from_langflow_builtin():+ """Restricted Langflow swaps drifted code of a known built-in type for its own copy."""+ source = SOURCE.read_text(encoding="utf-8")+ assert 'name = "OpenRAGSplitText"' in source+ assert 'display_name: str = "Split Text"' in source++[email protected]("flow_name", FLOWS_WITH_SPLITTER)+def test_flows_embed_the_openrag_split_text_component(flow_name):+ source = SOURCE.read_text(encoding="utf-8")+ expected_hash = hashlib.sha256(source.encode("utf-8")).hexdigest()[:12]+ flow = json.loads((Path("flows") / flow_name).read_text(encoding="utf-8"))+ nodes = flow["data"]["nodes"]++ assert not [n for n in nodes if n["data"].get("type") == "SplitText"]+ splitters = [n for n in nodes if n["data"].get("type") == NODE_TYPE]+ assert len(splitters) == 1+ component = splitters[0]["data"]["node"]+ # flows_service and the ingest tweaks find this node by display name+ assert component["display_name"] == "Split Text"+ assert component["template"]["code"]["value"] == source+ assert component["metadata"]["code_hash"] == expected_hash++ node_id = splitters[0]["id"]+ for edge in flow["data"]["edges"]:+ if edge["source"] == node_id:+ assert edge["data"]["sourceHandle"]["dataType"] == NODE_TYPE+ assert "œdataTypeœ:œSplitTextœ" not in edge["sourceHandle"]diff --git a/uv.lock b/uv.lockindex 09c69515c..aae01ecda 100644--- a/uv.lock+++ b/uv.lock@@ -1,5 +1,5 @@version = 1-revision = 2+revision = 3requires-python = ">=3.13"resolution-markers = ["python_full_version >= '3.15'",@@ -1200,6 +1200,19 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/7e/f5/f66802a942d491edb555dd61e3a9961140fd64c90bce1eafd741609d334d/httpcore-1.0.9-py3-none-any.whl", hash = "sha256:2d400746a40668fc9dec9810239072b40b4484b640a8c38fd654a024c7a1bf55", size = 78784, upload-time = "2025-04-24T22:06:20.566Z" },]+[[package]]+name = "httpcore2"+version = "2.16.0"+source = { registry = "https://pypi.org/simple" }+dependencies = [+ { name = "h11" },+ { name = "truststore" },+]+sdist = { url = "https://files.pythonhosted.org/packages/c0/61/afa9d6b7452f9eca73f73d45324eb0bb52f098fd5e6049bf6b8263be9b4e/httpcore2-2.16.0.tar.gz", hash = "sha256:c72cd0413563b17e1cd8354677dff887466f8ec2551679759e93126534428643", size = 69886, upload-time = "2026-10-21T07:09:45.31Z" }+wheels = [+ { url = "https://files.pythonhosted.org/packages/af/c2/ce417c397afa5181f0e3c6ff01a4d01639414e1adef08730d97571297151/httpcore2-2.16.0-py3-none-any.whl", hash = "sha256:5c4358319f2602d984ad93182c9fee5160f22e9da7babdda870a5e7c4e2dc34f", size = 85070, upload-time = "2026-10-21T07:09:42.802Z" },+]+[[package]]name = "httplib2"version = "0.32.0"@@ -1241,6 +1254,31 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/d2/fd/6668e5aec43ab844de6fc74927e155a3b37bf40d7c3790e49fc0406b6578/httpx_sse-0.4.3-py3-none-any.whl", hash = "sha256:0ac1c9fe3c0afad2e0ebb25a934a59f4c7823b60792691f779fad2c5568830fc", size = 8960, upload-time = "2025-10-10T21:48:21.158Z" },]+[[package]]+name = "httpx2"+version = "2.16.0"+source = { registry = "https://pypi.org/simple" }+dependencies = [+ { name = "anyio", marker = "sys_platform != 'emscripten'" },+ { name = "httpcore2", marker = "sys_platform != 'emscripten'" },+ { name = "httpx2-jsfetch", marker = "sys_platform == 'emscripten'" },+ { name = "idna" },+ { name = "truststore", marker = "sys_platform != 'emscripten'" },+]+sdist = { url = "https://files.pythonhosted.org/packages/43/73/5ca2cedf5e4e50423d1c258877865a6b62793633b561c58499f8aeb33b7e/httpx2-2.16.0.tar.gz", hash = "sha256:0d54c98128e8f2ff7fbbde0fca8c359e5f032edeaaaac443cdb7f31f685bcd7f", size = 103116, upload-time = "2026-10-21T07:09:46.348Z" }+wheels = [+ { url = "https://files.pythonhosted.org/packages/7b/3d/2e4bc4fd1ef9770871669adb348d612a6e4786b303a23f9935b81c48dd60/httpx2-2.16.0-py3-none-any.whl", hash = "sha256:fd2c5d7909e8d86fe92d53020c310ca0e4e431b838c207c5754b9bbf0308d49a", size = 97880, upload-time = "2026-10-21T07:09:44.01Z" },+]++[[package]]+name = "httpx2-jsfetch"+version = "1.0"+source = { registry = "https://pypi.org/simple" }+sdist = { url = "https://files.pythonhosted.org/packages/cd/c4/0e5636363151a2a1795e0a77617168b9ca438e1748ec05fc9b5687f93d64/httpx2_jsfetch-1.0.tar.gz", hash = "sha256:70a0e3eabfef7cce5ad9c629f7d01ca05e418f586646f4ddf14782e4c1454c60", size = 6872, upload-time = "2026-08-07T00:13:07.492Z" }+wheels = [+ { url = "https://files.pythonhosted.org/packages/9b/43/832f631d32e4f1211caa2ba368317739fe71f0b8530e4c9d15dc454bac2a/httpx2_jsfetch-1.0-py3-none-any.whl", hash = "sha256:cb916b707601e69a07721aabc8f3f6659be3a6893bc1ff5c6f9e02241df2da32", size = 6382, upload-time = "2026-08-07T00:13:06.567Z" },+]+[[package]]name = "huggingface-hub"version = "1.10.1"@@ -1489,6 +1527,27 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/67/c5/82addfd375e5ee6520644e0553e4aadde92d668c4fc99cc716d337fe7bb3/joserfc-1.7.5-py3-none-any.whl", hash = "sha256:add2c2c84e8373b084d526a8b53daba5d7a513a118cd2dcd9fc9f979d0922159", size = 71269, upload-time = "2026-08-29T13:05:40.718Z" },]+[[package]]+name = "jsonpatch"+version = "1.38"+source = { registry = "https://pypi.org/simple" }+dependencies = [+ { name = "jsonpointer" },+]+sdist = { url = "https://files.pythonhosted.org/packages/31/fd/359c6b0bf41d43eba15cafcd185fd82a11250f00606599ca8f296820fae2/jsonpatch-1.38.tar.gz", hash = "sha256:debc3e7bdc3d446468d64987f51a0e7a9deea42987ff90a6d1005a489b471c19", size = 42237, upload-time = "2026-10-26T21:19:22.05Z" }+wheels = [+ { url = "https://files.pythonhosted.org/packages/c7/67/3589e1fae8c43bcb2b3ca28afca742ed7cded199dd9d95bc74f67b1e1991/jsonpatch-1.38-py3-none-any.whl", hash = "sha256:46260c5df952abd4734a098f94512dc00bc38539152ac3ef069ed0475e4f5695", size = 17440, upload-time = "2026-10-26T21:19:20.75Z" },+]++[[package]]+name = "jsonpointer"+version = "3.6"+source = { registry = "https://pypi.org/simple" }+sdist = { url = "https://files.pythonhosted.org/packages/54/04/e35b34f4e441473e62d82d6ed9a8f748d93d895f4c05d4e645aa0fde51d7/jsonpointer-3.6.tar.gz", hash = "sha256:82e839a3ba3a9e2b54394fda8b3d276c2459d80408d06ef9a6fbc369d7544ffc", size = 14352, upload-time = "2026-10-26T20:59:26.307Z" }+wheels = [+ { url = "https://files.pythonhosted.org/packages/6e/34/cee746fb30473bfaa92f19267fcc102a1118eaec83e7e2b5652a91ead01c/jsonpointer-3.6-py3-none-any.whl", hash = "sha256:a45c858f8a9e171f6b3790ed9446c9382782f6c4cb4589176813c5a553f4cfcd", size = 9333, upload-time = "2026-10-26T20:59:24.947Z" },+]+[[package]]name = "jsonref"version = "1.1.0"@@ -1556,6 +1615,53 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/81/db/e655086b7f3a705df045bf0933bdd9c2f79bb3c97bfef1384598bb79a217/keyring-25.7.0-py3-none-any.whl", hash = "sha256:be4a0b195f149690c166e850609a477c532ddbfbaed96a404d4e43f8d5e2689f", size = 39160, upload-time = "2025-11-16T16:26:08.402Z" },]+[[package]]+name = "langchain-core"+version = "1.7.0"+source = { registry = "https://pypi.org/simple" }+dependencies = [+ { name = "httpx" },+ { name = "jsonpatch" },+ { name = "langchain-protocol" },+ { name = "langsmith" },+ { name = "packaging" },+ { name = "pydantic" },+ { name = "pyyaml" },+ { name = "tenacity" },+ { name = "typing-extensions", version = "4.15.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.15'" },+ { name = "typing-extensions", version = "4.16.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.15'" },+ { name = "uuid-utils" },+]+sdist = { url = "https://files.pythonhosted.org/packages/64/cb/77d1dabe57d0dc0f96f65cba321366c341627295d1c09eefa58549e34391/langchain_core-1.7.0.tar.gz", hash = "sha256:c34e53358b103cd73f43c63f5f46f9b5c6c3467efdffcdf134892b89020494e4", size = 1020046, upload-time = "2026-10-22T17:47:21.554Z" }+wheels = [+ { url = "https://files.pythonhosted.org/packages/b3/d8/ed130e91cee0525cb47d185b98a5a6ffd6a8b660a100fbee43d887e745d6/langchain_core-1.7.0-py3-none-any.whl", hash = "sha256:e82b24d7ac51fc74874baa29d6b3c0b8234880d4f3d897f8ff57fb80dfd9b07d", size = 574676, upload-time = "2026-10-22T17:47:19.749Z" },+]++[[package]]+name = "langchain-protocol"+version = "0.0.20"+source = { registry = "https://pypi.org/simple" }+dependencies = [+ { name = "typing-extensions", version = "4.15.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.15'" },+ { name = "typing-extensions", version = "4.16.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.15'" },+]+sdist = { url = "https://files.pythonhosted.org/packages/cb/8b/d908d082c3cf5368ddd1816ed114de79c873f979ba7f98b95fab0e841643/langchain_protocol-0.0.20.tar.gz", hash = "sha256:0f5bd002474265648e91161771a9e0438fe9480bd55a416e51af0f60070637ec", size = 6280, upload-time = "2026-10-20T11:13:50.84Z" }+wheels = [+ { url = "https://files.pythonhosted.org/packages/02/4b/f1c99a0b27c5ff8b4b131c0d6e62012c17cc424089efe213767db927afd2/langchain_protocol-0.0.20-py3-none-any.whl", hash = "sha256:3c935e5e46b0f6f9cb52f45ba7cfa53d1b9fa80c82c4a277d47f03e07f7385b1", size = 7347, upload-time = "2026-10-20T11:13:49.566Z" },+]++[[package]]+name = "langchain-text-splitters"+version = "1.1.3"+source = { registry = "https://pypi.org/simple" }+dependencies = [+ { name = "langchain-core" },+]+sdist = { url = "https://files.pythonhosted.org/packages/85/22/d401fffe8d3f1339f6ac880e5d637db73933efa95635304849b2d44ab0fe/langchain_text_splitters-1.1.3.tar.gz", hash = "sha256:929b6c76f99d611a5b1d8f5591ef302909b86a436ceb3217034d24e4757868d8", size = 308295, upload-time = "2026-10-02T15:46:33.173Z" }+wheels = [+ { url = "https://files.pythonhosted.org/packages/c7/51/2880d2e88cce13c1180178f7e8dc796c2f45b2dc09cc09ed407d116c08cc/langchain_text_splitters-1.1.3-py3-none-any.whl", hash = "sha256:50edeb318b3be6a6308dddd7d616ab82823a9ccbea59a9c14c58a7b91df60295", size = 38217, upload-time = "2026-10-02T15:46:32.271Z" },+]+[[package]]name = "langfuse"version = "4.18.0"@@ -1577,6 +1683,32 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/49/49/2569267383ee0d0afeaab904aefaf77eb69fed023354e833fb49ebe7411e/langfuse-4.18.0-py3-none-any.whl", hash = "sha256:b0f14f30f9f147ca662eaa9998af374fc57b9e8a894f0ae86789cbbd96448289", size = 709950, upload-time = "2026-10-14T08:40:47.196Z" },]+[[package]]+name = "langsmith"+version = "0.14.12"+source = { registry = "https://pypi.org/simple" }+dependencies = [+ { name = "anyio" },+ { name = "distro" },+ { name = "httpx2" },+ { name = "orjson", marker = "platform_python_implementation != 'PyPy'" },+ { name = "packaging" },+ { name = "pydantic" },+ { name = "requests" },+ { name = "requests-toolbelt" },+ { name = "sniffio" },+ { name = "typing-extensions", version = "4.15.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.15'" },+ { name = "typing-extensions", version = "4.16.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.15'" },+ { name = "uuid-utils" },+ { name = "websockets" },+ { name = "xxhash" },+ { name = "zstandard" },+]+sdist = { url = "https://files.pythonhosted.org/packages/a2/f7/07a02241b6e6ed3df4e31a64ed09cb522c47227816da3d71097e7cf94657/langsmith-0.14.12.tar.gz", hash = "sha256:b4d6a24ed74333095da476803ad9d22ee35f9dae1052cebf1e366d3889a9b675", size = 5038994, upload-time = "2026-10-21T20:16:22.565Z" }+wheels = [+ { url = "https://files.pythonhosted.org/packages/c6/6c/33e2de8d8d809895263e4f24ef7619e5535e3ece7de863ffbe49c1b7a60d/langsmith-0.14.12-py3-none-any.whl", hash = "sha256:9dafba7f615afa77204dc8afbb9c803e4ba1b55e96249f12c8f9aafb23fae6d0", size = 883644, upload-time = "2026-10-21T20:16:20.039Z" },+]+[[package]]name = "librt"version = "0.10.0"@@ -2089,6 +2221,7 @@ tracing = [[package.dev-dependencies]dev = [+ { name = "langchain-text-splitters" },{ name = "langfuse" },{ name = "mypy" },{ name = "pytest" },@@ -2157,6 +2290,7 @@ provides-extras = ["apm", "tracing"][package.metadata.requires-dev]dev = [+ { name = "langchain-text-splitters", specifier = ">=1.1.2,<2" },{ name = "langfuse", specifier = ">=4.16,<5" },{ name = "mypy", specifier = ">=2.0.0" },{ name = "pytest", specifier = ">=9.0.3" },@@ -2316,6 +2450,44 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/bc/14/67f8aa798857f8cf686f515bf93d9bb877ce952ddc8efae0fa25b45ce0d6/opentelemetry_semantic_conventions-0.66b1-py3-none-any.whl", hash = "sha256:d4cddeb4315490b35213f55e2bdc9ac54bb1e4d318927475bed62b35545e581b", size = 206279, upload-time = "2026-10-06T17:32:56.103Z" },]+[[package]]+name = "orjson"+version = "3.13.0"+source = { registry = "https://pypi.org/simple" }+sdist = { url = "https://files.pythonhosted.org/packages/f2/72/380b97dc45bd162d23afe5194721ef678d9eac7cfaa549fe2873f7f0a518/orjson-3.13.0.tar.gz", hash = "sha256:d1de5eb04485110c5da4c657e49168995d55e076b1ce60f1a042e254f4186c4f", size = 2732604, upload-time = "2026-10-07T14:09:25.719Z" }+wheels = [+ { url = "https://files.pythonhosted.org/packages/a9/56/f8ad2546150168858c16915c452b00eecb79597597524d1ad6ae14ad4eab/orjson-3.13.0-cp313-cp313-macosx_10_15_x86_64.macosx_11_0_arm64.macosx_10_15_universal2.whl", hash = "sha256:64e8f345048d988c8b68d3882e5d41028fca1219a9939b32e4a77be34c8ae8e3", size = 222892, upload-time = "2026-10-07T14:08:37.495Z" },+ { url = "https://files.pythonhosted.org/packages/1f/19/725d23160b2471a3f27026c55bb79af34687652d8be8f5f583cee5dcd42f/orjson-3.13.0-cp313-cp313-macosx_15_0_arm64.whl", hash = "sha256:ded33b972cffdaf4ca0ac917338ab61d2bb10d68987dbcae641c313fbfdbf499", size = 123319, upload-time = "2026-10-07T14:08:38.989Z" },+ { url = "https://files.pythonhosted.org/packages/ac/08/e5d81a00b22c73dfcb60d80da3bd92d5a7684346593536565f184dbae3c9/orjson-3.13.0-cp313-cp313-manylinux2014_armv7l.manylinux_2_17_armv7l.whl", hash = "sha256:45e34deb3437509f4ec9888dd9ee5dc426cfe21be10f1eb4ea3a9e4d33034f9e", size = 113196, upload-time = "2026-10-07T14:08:40.383Z" },+ { url = "https://files.pythonhosted.org/packages/67/78/fda6117c69a43e470b1e9dff38dd8c5f0bc6fd8a47e4d4561ab023039335/orjson-3.13.0-cp313-cp313-manylinux2014_i686.manylinux_2_17_i686.whl", hash = "sha256:9825b954155b345c4759f24e5f8d652b9aec2261bb5d4e1abe06bba0a1200535", size = 130245, upload-time = "2026-10-07T14:08:41.878Z" },+ { url = "https://files.pythonhosted.org/packages/6d/31/d0cfebd456defb234414795ae7599696bf124843dfe077d0c9ece0c93554/orjson-3.13.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b081f0e7b600ff24513dec4ca75507fa05e904607847e386e8310d5b7b96b6c7", size = 128981, upload-time = "2026-10-07T14:08:43.716Z" },+ { url = "https://files.pythonhosted.org/packages/45/46/f8d83189ff5b7b2ff225a58c5908618cc4e86afe09e65d17a30ac68c9da4/orjson-3.13.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:cbed5f4c4b88d94bcc36115f4c3bb3aa25da1563a5c3328aa3acebce2b083040", size = 130370, upload-time = "2026-10-07T14:08:45.132Z" },+ { url = "https://files.pythonhosted.org/packages/e6/6a/d6344c305003ea826b3fa0482645a897a3cd6d477ed74e1fe15d3322cb23/orjson-3.13.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:e9b61676116f755126b90e740a9cff36b91562f47ec330056cc88cc3b9f02f4b", size = 134595, upload-time = "2026-10-07T14:08:46.63Z" },+ { url = "https://files.pythonhosted.org/packages/9f/52/d73fa44f88d53e02d10de1cf77c16ed13204ff5bca47e1692da6b406619c/orjson-3.13.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:3ef75ed7e81dae34a3649f82df52cd85f9ac839a7d6ec78ab355b33b3b27ef7f", size = 126513, upload-time = "2026-10-07T14:08:48.111Z" },+ { url = "https://files.pythonhosted.org/packages/fb/f8/bcfc50b4ab851c4f9c0ee62f52bf3b28f0bcd0d9fe08e0ad98d4585148db/orjson-3.13.0-cp313-cp313-win_amd64.whl", hash = "sha256:4ee06e53b998c71ce3eb93b86222912fdd9dcced685ac64d4525d36fac338ea4", size = 121371, upload-time = "2026-10-07T14:08:49.549Z" },+ { url = "https://files.pythonhosted.org/packages/7b/7a/d6927845712ec2b1e89263cd12d7203531db185dbad67f914226f2fca156/orjson-3.13.0-cp313-cp313-win_arm64.whl", hash = "sha256:89efecad02515df7f318d0613b5dfd6d2a1acd323a2b8294712789a715945525", size = 126134, upload-time = "2026-10-07T14:08:51.118Z" },+ { url = "https://files.pythonhosted.org/packages/f0/10/98b5a3cdc086abf78d8cd20bb0cba124485d4b6a745722197bd209d967a5/orjson-3.13.0-cp314-cp314-macosx_10_15_x86_64.macosx_11_0_arm64.macosx_10_15_universal2.whl", hash = "sha256:a7bfc7db961c7d96cb75889dc6a1e4ae1e91d87ee61da564f582bd742b8dfeef", size = 222889, upload-time = "2026-10-07T14:08:52.673Z" },+ { url = "https://files.pythonhosted.org/packages/22/7c/7728c5280ab5202f4891ff4b0b96e2e1dbd5520dfee53edf083c54409a64/orjson-3.13.0-cp314-cp314-macosx_15_0_arm64.whl", hash = "sha256:91d933e668ff0ffe164d7c2daec36beba6d1ce7fadb71538fbe142a71f8a1e6e", size = 123312, upload-time = "2026-10-07T14:08:54.25Z" },+ { url = "https://files.pythonhosted.org/packages/a9/a5/d9a44321e6f66c0f64b45be587395f87ad94cb447bce7d92286f6b97d46a/orjson-3.13.0-cp314-cp314-manylinux2014_armv7l.manylinux_2_17_armv7l.whl", hash = "sha256:6c8bfe728b81b0fd58a3c7f3f9c5a113f87f2992c9948e0f28707aafd737c0bc", size = 113146, upload-time = "2026-10-07T14:08:55.803Z" },+ { url = "https://files.pythonhosted.org/packages/80/da/d95c80d413f288feb471e16d82e5c1512d2439728e3bac917d058c31f098/orjson-3.13.0-cp314-cp314-manylinux2014_i686.manylinux_2_17_i686.whl", hash = "sha256:e8e05549f3b30f9d8a8e28c5aba11cc2a4b90b90961ec685ca58444b0815fc09", size = 130348, upload-time = "2026-10-07T14:08:57.31Z" },+ { url = "https://files.pythonhosted.org/packages/04/0f/36fdfb32ad1852997bac00e3ce52c7888d8a1094ba9dcdcbb22fcc6b953a/orjson-3.13.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c749ab3ac30b5ab1ffb7677f8b92eacfdfdc5260210baa398f845bc3714c05d8", size = 128971, upload-time = "2026-10-07T14:08:58.843Z" },+ { url = "https://files.pythonhosted.org/packages/25/de/a82acf93bdcca0c79ccff25ef0c6868d24ccbc2e72f21fae39c8cabce4f1/orjson-3.13.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:58a9619d88f8818d9ab6b39d70d203789457ba13c1ed5d274f33ce9ae7e81a36", size = 130359, upload-time = "2026-10-07T14:09:00.412Z" },+ { url = "https://files.pythonhosted.org/packages/71/ca/2bc4f7697cb9f6897bf61aca11803df096a5d971bf69ef5538b243bb1fa8/orjson-3.13.0-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:2715c4808d1571029ed18fd07a82140bf3ba7def0dc89f8d015c416e3649bf87", size = 134583, upload-time = "2026-10-07T14:09:02.047Z" },+ { url = "https://files.pythonhosted.org/packages/23/b3/12b1af9b87ff9fa0aaf4e5724c87672b30bb5de76f275f7fac64e8219c1b/orjson-3.13.0-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:08bf722f923d2100bc5e5a5dcf72c656db557049c1bea26582fdd5dd9d5395a1", size = 126500, upload-time = "2026-10-07T14:09:03.863Z" },+ { url = "https://files.pythonhosted.org/packages/ad/ea/cf257fc8a7f4b18f5677c22b3a9673a1b51d4b7161f25177ed389b76560e/orjson-3.13.0-cp314-cp314-win_amd64.whl", hash = "sha256:6adcaa85d79977659a448b4123a88eb33511a11ed2db243535ad7ea88a6668e0", size = 121378, upload-time = "2026-10-07T14:09:05.375Z" },+ { url = "https://files.pythonhosted.org/packages/05/0a/9f4643f849e9918eab11983b83928af3aac14bedb04002e28e885ee1936f/orjson-3.13.0-cp314-cp314-win_arm64.whl", hash = "sha256:83705c12b4afde10c62a5dd3fe6fdb21b7900bd0dcd5af1c85612ae94d0ee590", size = 126123, upload-time = "2026-10-07T14:09:07.085Z" },+ { url = "https://files.pythonhosted.org/packages/8c/15/d265f2b556c0c7c0b30ea830316d6e5af5b85dde08f234a1ebed60fab386/orjson-3.13.0-cp315-cp315-macosx_10_15_x86_64.macosx_11_0_arm64.macosx_10_15_universal2.whl", hash = "sha256:5ef4d4157392a0439b74f7e49e5636b4ea43d9616bd0884effc0195fffcaa2d5", size = 223305, upload-time = "2026-10-07T14:09:08.84Z" },+ { url = "https://files.pythonhosted.org/packages/0c/97/781be8b80a33b8171b3f5acea941af47182c8b4b5827c2b7c3fea706f21c/orjson-3.13.0-cp315-cp315-macosx_15_0_arm64.whl", hash = "sha256:84d87e322e1674408f85adea63f11aa19201eba082755aec20ebc217f493bbd2", size = 123515, upload-time = "2026-10-07T14:09:10.792Z" },+ { url = "https://files.pythonhosted.org/packages/20/68/011bb98fa7da7b430b363db1bb7ef9160c438fc5c43e7468fb593c220037/orjson-3.13.0-cp315-cp315-manylinux_2_39_aarch64.whl", hash = "sha256:8c2ac5c09b017c484df1b4c68b2cf250b4e8ba08204cb58e7cd6cbbc71a9c902", size = 129222, upload-time = "2026-10-07T14:09:12.542Z" },+ { url = "https://files.pythonhosted.org/packages/86/7f/d96fa2aedaaec14c095ea9cd48d2158fdf33c0f4fd6e7a598d899d536b03/orjson-3.13.0-cp315-cp315-manylinux_2_39_armv7l.whl", hash = "sha256:51d11525bc3ca736fa97ce4e4c7da9999cc00bf261522bede43b4e7531bd7965", size = 113152, upload-time = "2026-10-07T14:09:14.059Z" },+ { url = "https://files.pythonhosted.org/packages/e9/2d/ee77aa685c54bd920a1f0e2936986b46269adb0d72bf5098c2c694dbeb36/orjson-3.13.0-cp315-cp315-manylinux_2_39_i686.whl", hash = "sha256:ac81530647c3423107cf61c3481e91f57134e9ddfb6ef83f5150ccbdcbc3a3ee", size = 130749, upload-time = "2026-10-07T14:09:15.835Z" },+ { url = "https://files.pythonhosted.org/packages/48/eb/3411fbfdad61b3f3af22343b5af7ed5c8a1679e35f442e8f1b229b33040e/orjson-3.13.0-cp315-cp315-manylinux_2_39_x86_64.whl", hash = "sha256:0526a3456db67b264c6d661b5f090077f326b6cd074d0ef53a72763595dec5d7", size = 130471, upload-time = "2026-10-07T14:09:17.463Z" },+ { url = "https://files.pythonhosted.org/packages/87/71/abdc2b8c70b8d85a6cb22f404da0f52d7d712f9d49cda039a0cb1adcb973/orjson-3.13.0-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:dd61e64802d51d1e4f16531c64536354fc3bc67932dc0cff254044f72bf0f187", size = 134793, upload-time = "2026-10-07T14:09:19.084Z" },+ { url = "https://files.pythonhosted.org/packages/0a/2e/1c13552d8b0241083116de02b2f284ee38501ef06ebfb79893f741538168/orjson-3.13.0-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:c5e3ccaac3106e8fa6e2f2f6962449d7c757d7b067e41b395a19d6f0d6cec892", size = 126711, upload-time = "2026-10-07T14:09:20.645Z" },+ { url = "https://files.pythonhosted.org/packages/85/f8/d4ece953a519d064cf690adaa68cd389d5b64fd261726334841b32978d6a/orjson-3.13.0-cp315-cp315-win_amd64.whl", hash = "sha256:7804dd1d6161da0e53b284c2aebf20f23e78eaac617300803e1467d1828d987f", size = 121496, upload-time = "2026-10-07T14:09:22.359Z" },+ { url = "https://files.pythonhosted.org/packages/70/cf/f691388c4a9bc4af7dcc1648c4b40845869908b517d7c0009d005c7d1fa1/orjson-3.13.0-cp315-cp315-win_arm64.whl", hash = "sha256:f5c05a8fee59309f537590a1ff12d3c1009c485e96a50a9ac60dd085c09d0fc0", size = 126260, upload-time = "2026-10-07T14:09:23.928Z" },+]+[[package]]name = "packaging"version = "26.0"@@ -2948,6 +3120,18 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/3b/5d/63d4ae3b9daea098d5d6f5da83984853c1bbacd5dc826764b249fe119d24/requests_oauthlib-2.0.0-py2.py3-none-any.whl", hash = "sha256:7dd8a5c40426b779b0868c404bdef9768deccf22749cde15852df527e6269b36", size = 24179, upload-time = "2024-03-22T20:32:28.055Z" },]+[[package]]+name = "requests-toolbelt"+version = "1.0.0"+source = { registry = "https://pypi.org/simple" }+dependencies = [+ { name = "requests" },+]+sdist = { url = "https://files.pythonhosted.org/packages/f3/61/d7545dafb7ac2230c70d38d31cbfe4cc64f7144dc41f6e4e4b78ecd9f5bb/requests-toolbelt-1.0.0.tar.gz", hash = "sha256:7681a0a3d047012b5bdc0ee37d7f8f07ebe76ab08caeccfc3921ce23c88d5bc6", size = 206888, upload-time = "2023-05-01T04:11:33.229Z" }+wheels = [+ { url = "https://files.pythonhosted.org/packages/3f/51/d4db610ef29373b879047326cbf6fa98b6c1969d6f6dc423279de2b1be2c/requests_toolbelt-1.0.0-py2.py3-none-any.whl", hash = "sha256:cccfdd665f0a24fcf4726e690f65639d272bb0637b9b92dfd91a5568ccf6bd06", size = 54481, upload-time = "2023-05-01T04:11:28.427Z" },+]+[[package]]name = "rich"version = "14.3.3"@@ -3329,6 +3513,15 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/16/e1/3079a9ff9b8e11b846c6ac5c8b5bfb7ff225eee721825310c91b3b50304f/tqdm-4.67.3-py3-none-any.whl", hash = "sha256:ee1e4c0e59148062281c49d80b25b67771a127c85fc9676d3be5f243206826bf", size = 78374, upload-time = "2026-02-03T17:35:50.982Z" },]+[[package]]+name = "truststore"+version = "0.10.5"+source = { registry = "https://pypi.org/simple" }+sdist = { url = "https://files.pythonhosted.org/packages/ee/9f/c5201d42a484c061e528825fc8e2d565f5abd50a4ced6fb7d29c4ec99b2b/truststore-0.10.5.tar.gz", hash = "sha256:30d36967ccaded5cbb38d602c433f53600036c79d502f4533a49b60a03bbefcd", size = 28091, upload-time = "2026-10-12T22:27:31.808Z" }+wheels = [+ { url = "https://files.pythonhosted.org/packages/51/e9/3a7820be2bb0fe53b6bc9c3be26d3d1158004e4c3ab953aa6840b955b1e9/truststore-0.10.5-py3-none-any.whl", hash = "sha256:9aaaedaefaf06d8b206278cf8b5012bc897f485a874503501e12d776df78951c", size = 19017, upload-time = "2026-10-12T22:27:30.377Z" },+]+[[package]]name = "typer"version = "0.23.1"@@ -3432,6 +3625,58 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/92/9d/c4e665119135114480843e7ab388fa94d8480650450e6f8e26b70d323a4c/urllib3-2.8.0-py3-none-any.whl", hash = "sha256:0cf3cae568d36aa9576b28dfb35f11328f1cb974ca7647d9475ebb86c75ac6e3", size = 135717, upload-time = "2026-09-15T19:29:34.577Z" },]+[[package]]+name = "uuid-utils"+version = "0.19.0"+source = { registry = "https://pypi.org/simple" }+sdist = { url = "https://files.pythonhosted.org/packages/f1/0f/cd9b3e495e514441e9af3a42c5c63436aee620f61412cafcce67e259228b/uuid_utils-0.19.0.tar.gz", hash = "sha256:4b2996bb9d12da9b62f6f4c64a066b26926fa75dbe47b4f8e309e24e187abf1d", size = 43343, upload-time = "2026-10-26T10:55:23.821Z" }+wheels = [+ { url = "https://files.pythonhosted.org/packages/fa/ce/78f9d79c820b8afc9b0498b0a5f5ef87ea970a19cc382127087f36cd4839/uuid_utils-0.19.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:84929d8c594381c6f1444afa2a25cce9ff7edac99d35e071ebc48275bae83730", size = 574701, upload-time = "2026-10-26T10:54:06.751Z" },+ { url = "https://files.pythonhosted.org/packages/fc/63/fe81dda73d651fb6bf8b0e21c4ea34209fc535ca109634c0d93f14ac21dc/uuid_utils-0.19.0-cp310-abi3-macosx_10_12_x86_64.whl", hash = "sha256:a416c78167b750186095a0ea950d95b8b4e157e3172fc6ccdc317b6ca2896580", size = 294226, upload-time = "2026-10-26T10:54:08.422Z" },+ { url = "https://files.pythonhosted.org/packages/81/6c/118c7e11fb579b5631212bfbbb31542a1778936dfb7c55591aa9b52c7c99/uuid_utils-0.19.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:82573c0e5090732c0ae2e18626e06cb35fe7cfcf6fe9534d4c1638af41d25d36", size = 327869, upload-time = "2026-10-26T10:54:10.016Z" },+ { url = "https://files.pythonhosted.org/packages/a3/76/80e9bad735cbf92f127183ee5c44ee0d83604e56197bddcaaaed2c66f7e6/uuid_utils-0.19.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:c78d527fddf5495e80032caeca2f140731ef394298ef4cbecaaf51aa2c257e1e", size = 334737, upload-time = "2026-10-26T10:54:11.434Z" },+ { url = "https://files.pythonhosted.org/packages/9e/7b/c8eb8e45569e8681f20e381859248d18635d823b8aedc70de8a0bd5faca6/uuid_utils-0.19.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:3c33b5c62cf82d509945c770201b1656448c2560e12931d1a8d698a683e9125d", size = 440438, upload-time = "2026-10-26T10:54:12.864Z" },+ { url = "https://files.pythonhosted.org/packages/be/45/8238eac588b668e5c500cb187fd74a9f6d984c09f3f3f2fa4161d3c07eb7/uuid_utils-0.19.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b8060530a8fa27f11947489c79bc36e6ebb465b2d714945364dc397283309417", size = 330342, upload-time = "2026-10-26T10:54:14.309Z" },+ { url = "https://files.pythonhosted.org/packages/0e/45/8215129786e67842d479480a44066cac8a7086f345ac9707f629ed777cfe/uuid_utils-0.19.0-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:96429c78eab28ac71b2121fb47c66783bfe5d06632b5bd5200004707fdc0faad", size = 354275, upload-time = "2026-10-26T10:54:15.753Z" },+ { url = "https://files.pythonhosted.org/packages/7f/bc/a673bfd116eb26419dd82bffa9bc2bc1e915af02bf68ac8c09598dc678ec/uuid_utils-0.19.0-cp310-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:80e0b37b3ddf60c50c51b869e1b02df61415941aa68bc903f61562fd8df04b18", size = 504446, upload-time = "2026-10-26T10:54:17.45Z" },+ { url = "https://files.pythonhosted.org/packages/af/ff/61867210f202c603d4a5ca1c5b3c4c76e8d8724eeebd7cf1307d18b63a9a/uuid_utils-0.19.0-cp310-abi3-musllinux_1_2_armv7l.whl", hash = "sha256:f629f2a4f95e46d99ee673536ab9706899696cdc6686e93314ea756d3b394ce4", size = 609016, upload-time = "2026-10-26T10:54:18.914Z" },+ { url = "https://files.pythonhosted.org/packages/42/81/6fb8a2ee8010a6a0c5cb29f5efed2604717613cc9888f9e5c999dc36b84b/uuid_utils-0.19.0-cp310-abi3-musllinux_1_2_i686.whl", hash = "sha256:ec330297c09e40b82d613326b57bb381d68535e8a341fa2e501b46791cbdfeec", size = 570293, upload-time = "2026-10-26T10:54:20.328Z" },+ { url = "https://files.pythonhosted.org/packages/0f/2f/e1c749b65c584ebd8bc5379cf18e26c67cdff8f2bd9f8f77111a47083408/uuid_utils-0.19.0-cp310-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:313de97d59dbbb09f4598cece2c799cc233d8673bb075ad7eff442cd485623c2", size = 535321, upload-time = "2026-10-26T10:54:21.735Z" },+ { url = "https://files.pythonhosted.org/packages/87/ba/f423f68fd784124e68ab1b1afe27ab4591ffd5363b39eccfcbaf8f3b0ff3/uuid_utils-0.19.0-cp310-abi3-pyemscripten_2025_0_wasm32.whl", hash = "sha256:5c47c7fc35e91a801996477f0d746d506a2e5b47a13accbf41dc29844786c40c", size = 103141, upload-time = "2026-10-26T10:54:23.192Z" },+ { url = "https://files.pythonhosted.org/packages/f1/9a/7a0a0dad166db9f4437f3d259e47ce74d552ccc50d8aa63d05b2510e3096/uuid_utils-0.19.0-cp310-abi3-pyemscripten_2026_0_wasm32.whl", hash = "sha256:23868cdc4dfa71021fec6cf43fbb83797345362ac1c866b50dbf17f479587413", size = 103069, upload-time = "2026-10-26T10:54:24.709Z" },+ { url = "https://files.pythonhosted.org/packages/e1/3c/c5fef96cea027de66a035b4173951fc29c2e83ed49a5d5b3fa7b632f95b5/uuid_utils-0.19.0-cp310-abi3-win32.whl", hash = "sha256:0cff166cf6348e9a705740e6575ce7bc727554a71a6add60b9ceceaaf169002a", size = 175479, upload-time = "2026-10-26T10:54:25.949Z" },+ { url = "https://files.pythonhosted.org/packages/3f/16/edfb8edc8a4624cfaf1387a57bf37cd53e5d7f213ebeb8dd6fbd2f6b2c64/uuid_utils-0.19.0-cp310-abi3-win_amd64.whl", hash = "sha256:b763ae8f23334ccd95d0b81fb19ee418f38f9e80ebfb521f313a9745280bc07c", size = 182891, upload-time = "2026-10-26T10:54:27.527Z" },+ { url = "https://files.pythonhosted.org/packages/63/17/258e5dd380bc594731b2b705082360fb4cef1e5cbaab46ef307439a6f415/uuid_utils-0.19.0-cp310-abi3-win_arm64.whl", hash = "sha256:b244ea25bfe1b34e40fabf8f079d59a9f153b22bd4095842065bb0a9dfaa477b", size = 180849, upload-time = "2026-10-26T10:54:28.86Z" },+ { url = "https://files.pythonhosted.org/packages/cb/64/b5554f686d5395db970bc07944b9c59c26ab0e192a27d7c8b555e5fc6332/uuid_utils-0.19.0-cp314-cp314t-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:9adf8d69574f0018a25aed0cc194bffacc05fb91b922fdd8e794109c45ad80ed", size = 565592, upload-time = "2026-10-26T10:54:30.242Z" },+ { url = "https://files.pythonhosted.org/packages/4a/a3/d8d0b7bf4892c41dbbb0e81a356d20aad781cc28d3029669e167eb72d9a1/uuid_utils-0.19.0-cp314-cp314t-macosx_10_12_x86_64.whl", hash = "sha256:ac37f30acc7fe01266c73f19a686d0ea1fbd22495d81205cc3b572e2fb2293a6", size = 292083, upload-time = "2026-10-26T10:54:32.053Z" },+ { url = "https://files.pythonhosted.org/packages/fa/c1/770ccb569b4c15ee81c36bc40e74f03c5e0a2ee71ecc534d3fe7cfa5696d/uuid_utils-0.19.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:afc1dc05c83163ec58304350ee61d20f1f3285d0e8fb873e4d85a97988c284ad", size = 323275, upload-time = "2026-10-26T10:54:33.896Z" },+ { url = "https://files.pythonhosted.org/packages/c7/12/798e09469358bf59848534291aa62d16cc6fbd66767f469c5d8278d0bc4d/uuid_utils-0.19.0-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:16e68b1a4b81301fa7ba52d500947094226d8b0c1521695746ec57ff0779ff6f", size = 328681, upload-time = "2026-10-26T10:54:35.506Z" },+ { url = "https://files.pythonhosted.org/packages/42/16/71df642a7969381747de36d4e365e59683cdaa2c425da0530e9383e4de86/uuid_utils-0.19.0-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:833edd2b38ef08a324e9f3aed4269d2ab955d4cb66417422eeb3af28a6237427", size = 434504, upload-time = "2026-10-26T10:54:36.96Z" },+ { url = "https://files.pythonhosted.org/packages/c1/18/35c86d901bbd6d3f088217f37a6ff01aae4ce8f8cdb3f9ddb5220887a122/uuid_utils-0.19.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:21356ba99b82c813c1945054a09ff7ebc1bf55b858b41a6ae084e6ed2c8bb9a9", size = 325810, upload-time = "2026-10-26T10:54:38.492Z" },+ { url = "https://files.pythonhosted.org/packages/fc/51/25427eee1031946d5abe0d8985123f6fd4a1931c8a5a8660b1c76368ca12/uuid_utils-0.19.0-cp314-cp314t-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:2477161656105e787a5f986adb63191b61f129c9d7399b2bce406f87a1407b4d", size = 346300, upload-time = "2026-10-26T10:54:39.864Z" },+ { url = "https://files.pythonhosted.org/packages/26/4b/edbb0ebdc948549a0250363f441883c31fef42fb4e4bb607b9a083efaeba/uuid_utils-0.19.0-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:ddf61d8443993d683c8d6fcd05cbb711c2655042952850fc0cf25af969e3a213", size = 501365, upload-time = "2026-10-26T10:54:41.268Z" },+ { url = "https://files.pythonhosted.org/packages/68/e4/f5a788fae45e315d8d04d5889a0b0809543e27c8d08b9fe10b09d0766b9b/uuid_utils-0.19.0-cp314-cp314t-musllinux_1_2_armv7l.whl", hash = "sha256:cb9ead0aeae67ad2de3f660f2e978ece77e14ad3f2a7082b768e2c75866664a2", size = 604290, upload-time = "2026-10-26T10:54:42.686Z" },+ { url = "https://files.pythonhosted.org/packages/a7/90/3800a0b2083d6c156a4d686e75f26c055a48fcf315b9310ba211b7e3659c/uuid_utils-0.19.0-cp314-cp314t-musllinux_1_2_i686.whl", hash = "sha256:4e5155902b7779ae7b692ac69e6031f41481d62fa85a530d3725c270799940a0", size = 563566, upload-time = "2026-10-26T10:54:44.068Z" },+ { url = "https://files.pythonhosted.org/packages/7f/37/1b58a17a041bd560a1d652afccd57ecd5d0e0c4d6280deded663b783de43/uuid_utils-0.19.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:fd3bcc556e249bb70b1c7fd78e659a1ebfb5572e7ff2091d096aecbac62edb1c", size = 531143, upload-time = "2026-10-26T10:54:45.599Z" },+ { url = "https://files.pythonhosted.org/packages/66/ac/f6286bcfad2f321be2acd04961934a58e4a6c15ba78070a13d193cbbb9f0/uuid_utils-0.19.0-cp314-cp314t-win32.whl", hash = "sha256:9b9064d96c6fe5e43ff4486722c5c891083a7fa91ee36311286cfd833b4b5562", size = 172229, upload-time = "2026-10-26T10:54:46.925Z" },+ { url = "https://files.pythonhosted.org/packages/87/45/0df876abf12875ef82bcd8f034c0c7adc1507dd721a5942232120b6267e8/uuid_utils-0.19.0-cp314-cp314t-win_amd64.whl", hash = "sha256:eeaf6b77ed2ec9815988e10d043d1533a1ae8c6535e7fb5479fd7e2e6ad25dff", size = 178436, upload-time = "2026-10-26T10:54:48.249Z" },+ { url = "https://files.pythonhosted.org/packages/d2/ae/c9b4aaa8ee95581b444a7be681dc0ceb57a465b50b28b2f2517f5fec1c51/uuid_utils-0.19.0-cp314-cp314t-win_arm64.whl", hash = "sha256:ebb011b9010ddbd8acd4650896e87db2715f2cfc70fb194c03ebcbf4150d3844", size = 175725, upload-time = "2026-10-26T10:54:49.562Z" },+ { url = "https://files.pythonhosted.org/packages/41/6e/3a3fdaa9689b687f105ba885e61f6b2e8336ec4d209fd51d41923ad83479/uuid_utils-0.19.0-cp315-cp315t-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:8c76f01a815a0ca8b698202f2f5e40098a4b3cd56305e1fc9ed3d959ac718ff0", size = 565325, upload-time = "2026-10-26T10:54:50.924Z" },+ { url = "https://files.pythonhosted.org/packages/5e/1a/23dacf86dfe52f4606694501a6072379156025a3c6988e16f477f627249c/uuid_utils-0.19.0-cp315-cp315t-macosx_10_12_x86_64.whl", hash = "sha256:f3828e1fc0831a9d539e702992e9fcfeb400e80f737467b8e557921cdc8ae067", size = 291930, upload-time = "2026-10-26T10:54:52.529Z" },+ { url = "https://files.pythonhosted.org/packages/4e/f2/adf223ded569b0d75e8ac10db14be8fc253da900a63e678436bc3ff3b72a/uuid_utils-0.19.0-cp315-cp315t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b25ddec2775c2f500a36029ab93af09f39d5c417786df02a464464e030152014", size = 322729, upload-time = "2026-10-26T10:54:54.01Z" },+ { url = "https://files.pythonhosted.org/packages/88/df/0f78e7f22c778d2e48ef092a3a1c44d5b8b487b7e178e1044e7a39195b17/uuid_utils-0.19.0-cp315-cp315t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:1fc412a5ef2f1e6f96d132a6656af59bae2dba9fd04f8df2a2f6eb913fe6180a", size = 328838, upload-time = "2026-10-26T10:54:55.473Z" },+ { url = "https://files.pythonhosted.org/packages/b3/96/9a9d6f7bef37b3545203eaf643e7f4d574f4ea3a6364af8865c071847df5/uuid_utils-0.19.0-cp315-cp315t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:94cbef978d789b18014c477f51c8311800803cd2a0c7e1de6d2af85377210053", size = 433992, upload-time = "2026-10-26T10:54:56.911Z" },+ { url = "https://files.pythonhosted.org/packages/07/92/62f67dc40a036ab890ac3f55eaab610999c713654bb3d0b56d5676ce3eaa/uuid_utils-0.19.0-cp315-cp315t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d4b012d2a2c5516e11ded4fb70cdd730f36e2d40b45018b9a40c6605dc5c0666", size = 326138, upload-time = "2026-10-26T10:54:58.533Z" },+ { url = "https://files.pythonhosted.org/packages/c8/b7/740525de1aa1a150eb7a80a667c997d54284f407b7f3b38ce8f90f948813/uuid_utils-0.19.0-cp315-cp315t-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:4062c0dfd6697ce7c91a504d8ff6eb8dcaf4e790fb6adec69c4c83fd89870d4a", size = 346714, upload-time = "2026-10-26T10:55:00.01Z" },+ { url = "https://files.pythonhosted.org/packages/3c/1a/c9d2be770a2061da608164d022becda3fc7ddabb34ec7a1950d29ae51ca0/uuid_utils-0.19.0-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:361cfd0fba0a49f1c8b6df741a35f7d948f0fae3d3914f8622ba261dc4656a5a", size = 500974, upload-time = "2026-10-26T10:55:01.392Z" },+ { url = "https://files.pythonhosted.org/packages/36/2e/ee7522207a7f9477c58757f040f05c4eedb68f362623d4e40da4983bdf5b/uuid_utils-0.19.0-cp315-cp315t-musllinux_1_2_armv7l.whl", hash = "sha256:a15c8943e02ac59992eaad1ce69793720dc711ce66188d386be1cbf8f5b5a2e4", size = 604607, upload-time = "2026-10-26T10:55:03.141Z" },+ { url = "https://files.pythonhosted.org/packages/07/b8/c9a1f21627238171a2021dd777177a211df20b12c0c5e45b828ee9bc3c84/uuid_utils-0.19.0-cp315-cp315t-musllinux_1_2_i686.whl", hash = "sha256:4bd00a485e973cb3bcefe06f13a663cf4ee0c54caeacb2a656a5f901d1505a03", size = 563749, upload-time = "2026-10-26T10:55:04.809Z" },+ { url = "https://files.pythonhosted.org/packages/e5/9e/ed7d14d4d7bdb94159909e722337a557c855e8990a7fdff55ef6b016fb38/uuid_utils-0.19.0-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:9fe68c4b2e017fb13c5e460b76b76c5cfa717ddd653cea184c2664bc2a852011", size = 530994, upload-time = "2026-10-26T10:55:06.511Z" },+ { url = "https://files.pythonhosted.org/packages/07/92/5b84a87dd4127a14337d42eb4a24a764583e4decc2675a9949d4568b16e1/uuid_utils-0.19.0-cp315-cp315t-win32.whl", hash = "sha256:5397581f40e268535cd48230e4f2f372dc5f3e70ce79e0aff9cb5ceb838163c8", size = 172512, upload-time = "2026-10-26T10:55:08.261Z" },+ { url = "https://files.pythonhosted.org/packages/d6/43/a11a33e39f64c50f17483842652933b8ef769ce7cac3399ed7d2a2b928c2/uuid_utils-0.19.0-cp315-cp315t-win_amd64.whl", hash = "sha256:225752e3c36b7c861eb1bbceb5c9197c134c806b210ed53dcacf6339a3d599e6", size = 178626, upload-time = "2026-10-26T10:55:09.658Z" },+ { url = "https://files.pythonhosted.org/packages/ab/78/4f9dc891db194ce8107c9704d7e2e51da558af457e64134da1b1a7c5db1f/uuid_utils-0.19.0-cp315-cp315t-win_arm64.whl", hash = "sha256:bfcda2352c1500230227da5475139ab177bb2516309254cd74ade19a28cb842d", size = 175582, upload-time = "2026-10-26T10:55:11.001Z" },+]+[[package]]name = "uvicorn"version = "0.44.0"@@ -3591,6 +3836,131 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/00/39/3daf9f47be208606586de4568ba6713db53ebc8fd7a575aea1fe57983b69/wrapt-2.3.0-py3-none-any.whl", hash = "sha256:d8c7ed08477429752b8c44991f40ad7838b18332a160698740a6bfbc10d998a2", size = 61866, upload-time = "2026-07-28T06:06:12.9Z" },]+[[package]]+name = "xxhash"+version = "4.0.2"+source = { registry = "https://pypi.org/simple" }+sdist = { url = "https://files.pythonhosted.org/packages/39/e6/ed6c428055ffd3f9299db3ec8671fd78b70c24173c040b8faafb6348ebbb/xxhash-4.0.2.tar.gz", hash = "sha256:af3d1b3cfa5280e84d8968e9f30c9eca75781db4915eb6d6acb0dd4fc93e0f47", size = 101549, upload-time = "2026-10-19T06:00:08.459Z" }+wheels = [+ { url = "https://files.pythonhosted.org/packages/6f/cd/4fa514d99643a90d4f4886ed387689a4e47c7f9cc541611b16336e13c44a/xxhash-4.0.2-cp313-cp313-android_24_arm64_v8a.whl", hash = "sha256:570ba2952f1fe3b4f7a272314db64903e5c9121032e1dbe20800c7e0e5a13145", size = 43621, upload-time = "2026-10-19T05:58:31.906Z" },+ { url = "https://files.pythonhosted.org/packages/ef/97/6634acaad90e17490974f44d9aa7ba99f8edc7bd1c59df4e0f6c59d4ee14/xxhash-4.0.2-cp313-cp313-android_24_x86_64.whl", hash = "sha256:5223b3d133b81197fdbede79601b9b0f0bdf07818a71b751e9d2480bdba72a70", size = 40639, upload-time = "2026-10-19T05:59:22.154Z" },+ { url = "https://files.pythonhosted.org/packages/2a/ac/23fa9e10335f7000a053ed9818e3fa03b57b88bb6eaecc43d8d3097d7f9a/xxhash-4.0.2-cp313-cp313-ios_13_0_arm64_iphoneos.whl", hash = "sha256:b91b42f62e6cf6c1aaec9cea6b9e4b8ae18119517242d22ffbd967b275f9d12d", size = 34691, upload-time = "2026-10-19T05:58:10.854Z" },+ { url = "https://files.pythonhosted.org/packages/09/d8/2f2db4b6166e5c982ed071821f40ffb15ea0ab45bd768f7e24eba814bb27/xxhash-4.0.2-cp313-cp313-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:e553d545d05094f3950ef36b328f75f5ef8568a0438c26966d9a0f1fc187a42b", size = 35636, upload-time = "2026-10-19T06:01:24.654Z" },+ { url = "https://files.pythonhosted.org/packages/80/9b/605e93a007a03fe5f314a5033f3860f0597e7ea552f4a56006c4b9b72ca5/xxhash-4.0.2-cp313-cp313-ios_13_0_x86_64_iphonesimulator.whl", hash = "sha256:56ee43c284daffc12d269b3fb36b1fc624c7ab007064a24d54099049ee71ce80", size = 37935, upload-time = "2026-10-19T05:59:22.612Z" },+ { url = "https://files.pythonhosted.org/packages/7d/d2/426b35da1dda15fe12bd91d02031186036d7500e9c5c462825193621fe9f/xxhash-4.0.2-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:d9cd501f5d6c737e26b8d45f0facff43d3b7f2f5a8c2ef1c88800f6f310da418", size = 38014, upload-time = "2026-10-19T05:58:10.101Z" },+ { url = "https://files.pythonhosted.org/packages/0c/4a/ad4ffa5a8189a809abee76b8541b71b26402e9d84dfe49090082edd3f919/xxhash-4.0.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:f64380470531ca49aceb15179ea47dd7be2fc38e41207eca4f7d05e4d6c9f795", size = 35875, upload-time = "2026-10-19T06:00:02.345Z" },+ { url = "https://files.pythonhosted.org/packages/dd/e7/2600f32d4dfc5ace4fd3f999a7ef1fd2c3e37d2be9888b1511594a5646e4/xxhash-4.0.2-cp313-cp313-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:1837c43b06cd2823b44ad27e80e51bbceed172a4afd0c3cc2ef543f2be74155e", size = 259451, upload-time = "2026-10-19T05:58:33.978Z" },+ { url = "https://files.pythonhosted.org/packages/70/06/69559862b9c5cb95b7e9d1851903d53ddc5a6e614ff4e951ac7d3ed45e4d/xxhash-4.0.2-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:c04c1aeff5cbe56714dfa49aa5d2edbb69c1a1a798926307b8d6af86549e7534", size = 283951, upload-time = "2026-10-19T05:59:24.224Z" },+ { url = "https://files.pythonhosted.org/packages/56/cb/11026759b7a5e25864000df34ab9231ad7fb4f5ae675d60cc4ecab7d9756/xxhash-4.0.2-cp313-cp313-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:b7f62733495384b424bae45ac457fc80d2143c80de2564416a2a7cd8a4dded4e", size = 303880, upload-time = "2026-10-19T05:58:12.205Z" },+ { url = "https://files.pythonhosted.org/packages/63/a5/6f7d0f3396c7c2157f24fc7d33ee270e769661375924a06f4b6ac63413d3/xxhash-4.0.2-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:7d8d913ecbd21dff2f47f458a8cd37beccb3e41504004341f42234829b973309", size = 287225, upload-time = "2026-10-19T06:01:26.165Z" },+ { url = "https://files.pythonhosted.org/packages/08/22/d226987ffd9f21ce8d1298fc7cc6280450f24cf6d866fe474d80291430d6/xxhash-4.0.2-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:40fab713c1d2f5c5e7450b8731615d8580757599ebf1f8683b211310ed8e5ad4", size = 519846, upload-time = "2026-10-19T05:59:24.631Z" },+ { url = "https://files.pythonhosted.org/packages/7c/0b/223e8d9da7c857f6f906202f3d15337a2dee8db530b88aeec6ae45cc9665/xxhash-4.0.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:61ded7dee4f95da69295c228fc18a65447f5741c45a315aa3f9a3adda6038611", size = 268559, upload-time = "2026-10-19T05:58:11.709Z" },+ { url = "https://files.pythonhosted.org/packages/60/a9/0f1586426d56234f0041e1caf80737b4c3d16aca7f352ddbd4d90a41d7af/xxhash-4.0.2-cp313-cp313-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:9478e4ae8b1db3f6fd72a5d17fc5805fc0ad576e31b58e2acb6bdbeefda2a549", size = 344952, upload-time = "2026-10-19T06:00:04.581Z" },+ { url = "https://files.pythonhosted.org/packages/c7/91/30aaff8fab52f5bc1d179a0de0dd59684b98f556a290f7130c1c7f9771f2/xxhash-4.0.2-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:14873a759b512ff875e01e7f8bd187ff613362cf189c44ba604e5cff833a308f", size = 279938, upload-time = "2026-10-19T05:58:36.001Z" },+ { url = "https://files.pythonhosted.org/packages/37/cf/92a6c96dd93c951bd566e6d2ca92dcf605a248c39313643aac03b6a8fd44/xxhash-4.0.2-cp313-cp313-musllinux_1_2_armv7l.whl", hash = "sha256:17c05e116555586f584c6dce34af2517b6648d56ef5ae7e4d84ea1a19d6743ef", size = 307560, upload-time = "2026-10-19T05:59:26.172Z" },+ { url = "https://files.pythonhosted.org/packages/47/0a/80d985d851ca25d4a4dce47f6694389536e5914f67657b0a9933d3d0b7ff/xxhash-4.0.2-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:d8dc7e4071794c0405dc6a40559dbe77d7eec1e4bbf6eed5dbebc4e6577d12f3", size = 265830, upload-time = "2026-10-19T05:58:13.82Z" },+ { url = "https://files.pythonhosted.org/packages/f8/09/c6c2142414380e2c3dba1f760e74cad2f1a18cb5fd6dbbbca61696dd935d/xxhash-4.0.2-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:983a14a70a018dcccd847e780ba630771d5525d7604b6f519c963634414180c9", size = 284401, upload-time = "2026-10-19T06:01:27.829Z" },+ { url = "https://files.pythonhosted.org/packages/aa/8e/577df6e23e50d19ab206b0b77143b52fff9572b2528fab0505945b537814/xxhash-4.0.2-cp313-cp313-musllinux_1_2_riscv64.whl", hash = "sha256:9a23f0c1dd31aa4136ef8a678a40e73dbaf070b54ee6f2a907b78ba40331b3c3", size = 335902, upload-time = "2026-10-19T05:59:26.864Z" },+ { url = "https://files.pythonhosted.org/packages/cc/35/a1a28980948d2835078e8f00ca7fe2c8573ee72ce667d5f3b2a5058fb9c2/xxhash-4.0.2-cp313-cp313-musllinux_1_2_s390x.whl", hash = "sha256:4d5f0e2bf5257900f60339cf439a23b35fd29a45cb7effed4b9f1b87c094df20", size = 487007, upload-time = "2026-10-19T05:58:13.081Z" },+ { url = "https://files.pythonhosted.org/packages/95/7c/23fb89ca8fbf8919982f3d3c73e15ca2baeae1f423fe72a2723dceaefeef/xxhash-4.0.2-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:892a66641657cf9aa0ae5c2c88258bc281221a33bd4af34bed786eea23e06d83", size = 264315, upload-time = "2026-10-19T06:00:07.131Z" },+ { url = "https://files.pythonhosted.org/packages/02/d0/9a9af3ee99bca69378190f0c284d06e466cdfde4f31445db4ffd6b50bc95/xxhash-4.0.2-cp313-cp313-pyemscripten_2025_0_wasm32.whl", hash = "sha256:050c1d66587e8f1ce70ccb7f661ec117e01497d48da817c14543beba0b8c677e", size = 20561, upload-time = "2026-10-19T05:58:38.487Z" },+ { url = "https://files.pythonhosted.org/packages/73/94/010a372e7b00df7e4ddc46982d1ee600b5bb8a1379fd15e9f436f7aa9773/xxhash-4.0.2-cp313-cp313-win32.whl", hash = "sha256:9c22ed1ea72cc23cec070fc5b9c3574844e67236f3f6e5bf7058e512abefe086", size = 34435, upload-time = "2026-10-19T05:59:28.819Z" },+ { url = "https://files.pythonhosted.org/packages/4d/a0/f9b70971bfe7e2a6aeb606df800d564466c6ae0f0e9db5d7025eafc61f33/xxhash-4.0.2-cp313-cp313-win_amd64.whl", hash = "sha256:99fec645143af9dc697620aebff07e99388c16d4208a2ee8b6a2a9bb7d68a21b", size = 36502, upload-time = "2026-10-19T05:58:16.297Z" },+ { url = "https://files.pythonhosted.org/packages/a6/1d/9790306d9ecabc6e1ff125bb9982fdf327fa6ff5e71b352de66551fdf94d/xxhash-4.0.2-cp313-cp313-win_arm64.whl", hash = "sha256:12d5a3c0687c990124a98a1eb027655075deebd985388b4e8ba4302992b90850", size = 33291, upload-time = "2026-10-19T06:01:29.149Z" },+ { url = "https://files.pythonhosted.org/packages/48/3e/29973fa7eac59122c9104d71add006689657f4a4733684bd2b25fe4d2195/xxhash-4.0.2-cp314-cp314-android_24_arm64_v8a.whl", hash = "sha256:52357b9fee08af3a5c81a793c97110d8be63baba91b88584beee400a2a0113c6", size = 43726, upload-time = "2026-10-19T05:59:29.603Z" },+ { url = "https://files.pythonhosted.org/packages/07/71/f859087e54bba4df27a3e16c380ba8071dd7b87771b9b9cb78dda01e93c7/xxhash-4.0.2-cp314-cp314-android_24_x86_64.whl", hash = "sha256:7779b0f388972029f0de4c83dee4523544b3ee33272425683a34c801c8afe6a3", size = 40728, upload-time = "2026-10-19T05:58:15.452Z" },+ { url = "https://files.pythonhosted.org/packages/41/9a/4b2751b5d9bd6f8000ec1ffe3ccdd6bbde958a9fb0d96ebfa5ec5a3ea553/xxhash-4.0.2-cp314-cp314-ios_13_0_arm64_iphoneos.whl", hash = "sha256:f99686036e0575b4bd1947f9efcf12c5bdf310b2348fb72db84a4861287df6fb", size = 34719, upload-time = "2026-10-19T06:00:09.211Z" },+ { url = "https://files.pythonhosted.org/packages/f5/bf/cb0eca1c15825dceef333e983dcc668ab6fc20577fe66e0c1cf3805b1b88/xxhash-4.0.2-cp314-cp314-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:5d51b2159376d98e99f7a33e19aed3d58d30d24ca641086e2ca0d54875d92ea6", size = 35655, upload-time = "2026-10-19T05:58:40.819Z" },+ { url = "https://files.pythonhosted.org/packages/02/81/a9b1d02517ed1ed1418170e2dec78115f73bf332ba455dd76fff363973f3/xxhash-4.0.2-cp314-cp314-ios_13_0_x86_64_iphonesimulator.whl", hash = "sha256:846189d5cc9a4e6815a04c595148b2a82721da1fcdacfdff13fb0225d0945ea3", size = 38077, upload-time = "2026-10-19T05:59:30.482Z" },+ { url = "https://files.pythonhosted.org/packages/d7/38/0df9b7001ef43d4ef8907a30ad49662d6fda45ff88a0684b169943d4dcff/xxhash-4.0.2-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:bf93a290a49285f75d0d6ec801aa247592a16bd043892a7b48d93f718dfc99c8", size = 38225, upload-time = "2026-10-19T05:58:18.369Z" },+ { url = "https://files.pythonhosted.org/packages/c8/ea/6f587cfa43ac41c793bd1b30d2fed4ffbde2dfbff013059e898292fad323/xxhash-4.0.2-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:28ae2c583d923aa57c0a4301ea4e071bccf1f84b5e16a31f86b854d9f8943151", size = 35889, upload-time = "2026-10-19T06:01:31.327Z" },+ { url = "https://files.pythonhosted.org/packages/c3/4b/0f773dae678b5995010528461d06509a23eb35a6f43f7424c1c0634dc3fe/xxhash-4.0.2-cp314-cp314-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:66fda3f72176bd7d1d3aa71de1f4bc116276e3ca3ac583bf06e5f561f2b1fc74", size = 259575, upload-time = "2026-10-19T05:59:31.014Z" },+ { url = "https://files.pythonhosted.org/packages/94/b6/09d7ce830dd09e3f645eb8b53f45df3ab6187012b4114d652686806afedb/xxhash-4.0.2-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:829ae333a35219c24584755b8f5c718b87e4713ac4233c8531a4e5d3d67fa7b7", size = 284280, upload-time = "2026-10-19T05:58:17.847Z" },+ { url = "https://files.pythonhosted.org/packages/78/23/952144b4332e66319552dea8c33a4ddfe277d3808f59fc2cd62529fa95cc/xxhash-4.0.2-cp314-cp314-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:131d73e1467e9f782048d7f4901eb5ced6997e55ca761b503b598618271da8d8", size = 303957, upload-time = "2026-10-19T06:00:11.924Z" },+ { url = "https://files.pythonhosted.org/packages/81/f5/a5ca9a14090c2a4e1e7002755129ce155687130ed83d358376f1ab6fba79/xxhash-4.0.2-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:3bdbde088f54a5cccb92f0d199e018bd676dbe2e5d2eabf1f9dc8148c6f297e2", size = 287505, upload-time = "2026-10-19T05:58:43.058Z" },+ { url = "https://files.pythonhosted.org/packages/48/56/2c4df935522c7928ff0c14708feed446cc3b81683664340a636c2f8af90d/xxhash-4.0.2-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:dd86600a7083aecd5e0fee0680e5a328cbd1bf18046faa217e2a76cf2e01faf4", size = 519240, upload-time = "2026-10-19T05:59:32.166Z" },+ { url = "https://files.pythonhosted.org/packages/15/b7/f8075159633b5f2d47ab0376f2925c2cb184f4ffd3a88aa330fac7950ee8/xxhash-4.0.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:318e6c3a31d75ccacd1f9b864e3b857d44c9f4bed5e9d5fb5db1dc2fec82f019", size = 268172, upload-time = "2026-10-19T05:58:20.346Z" },+ { url = "https://files.pythonhosted.org/packages/8f/5b/bbd53a3c9167d3e906d9801b0d2746d30c28c3e408a8f004bd3dcb327134/xxhash-4.0.2-cp314-cp314-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:360343b1d61efb44be005c2180cb19f8c0351d7dc63c8ebbdd8e219ca5cbbb4a", size = 345552, upload-time = "2026-10-19T06:01:32.499Z" },+ { url = "https://files.pythonhosted.org/packages/f1/bc/75c3e035d73c39cc45d128cacb5d7127e5d9da44a709994e59d009ee9889/xxhash-4.0.2-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:beb27fc243c6975ea44f74ea2e2c8c5014f9956ba0bf95ed6ee6dd3707e0add2", size = 280523, upload-time = "2026-10-19T05:59:32.621Z" },+ { url = "https://files.pythonhosted.org/packages/3c/92/654eb7b726a61f5cc77f2b8520d90af836611782475b67ff8d59c844b58f/xxhash-4.0.2-cp314-cp314-musllinux_1_2_armv7l.whl", hash = "sha256:605b582e3895fc240b972d9a28606c53fb5444c118c9f6392bffe8795a4c2467", size = 307180, upload-time = "2026-10-19T05:58:19.838Z" },+ { url = "https://files.pythonhosted.org/packages/09/13/e1b71ca763cbc7c49e46d6d58e20cfa60adc13fde8b6d5cad25e2aa6689c/xxhash-4.0.2-cp314-cp314-musllinux_1_2_i686.whl", hash = "sha256:68ed6108f9ef16bf90752582aadaef4c14caa00a50f8b340e282348365a351eb", size = 265863, upload-time = "2026-10-19T06:00:13.335Z" },+ { url = "https://files.pythonhosted.org/packages/17/01/f59a9c24403c21bdb843130f61d9b0db2ef368cf64de031fd353c80bf15c/xxhash-4.0.2-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:07aa7644899f97e4ff208f54b9d57fe4c077bfdf2dea5bd5a4a165e9b57309f1", size = 284533, upload-time = "2026-10-19T05:58:45.808Z" },+ { url = "https://files.pythonhosted.org/packages/c6/2b/510b04251771d37c0928b72b290f7f58990007deb413d78f45ee0127004f/xxhash-4.0.2-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:b97cc2b874d0656e88385fd7ba4c2dedd903f8e23767f69207fbdab79bd0861a", size = 336003, upload-time = "2026-10-19T05:59:34.961Z" },+ { url = "https://files.pythonhosted.org/packages/cf/4d/67dd96c1e4a84b8e4261449ca922bc41a91a37029356095979f7b3446573/xxhash-4.0.2-cp314-cp314-musllinux_1_2_s390x.whl", hash = "sha256:987a83e7a7762bd8d40d6ee75bb047a33f6ed34a4269dd6bdda561666c3e0c54", size = 486652, upload-time = "2026-10-19T05:58:22.75Z" },+ { url = "https://files.pythonhosted.org/packages/09/51/f09c756ce81d13185e11ba20ea99e1f4ff7269e78ae1d7d3194bdbde95b6/xxhash-4.0.2-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:f2b936ead8be8e1771b3a4508f5b8ba4087a57c59e3f6e91bbbb6849000ee302", size = 263737, upload-time = "2026-10-19T06:01:33.849Z" },+ { url = "https://files.pythonhosted.org/packages/d0/f1/cd84ce202b42e3185ca8f74cb07e83d9191fbf1647fc273c2447bbfbd2fe/xxhash-4.0.2-cp314-cp314-pyemscripten_2026_0_wasm32.whl", hash = "sha256:c9d48e67fc623850ac65b350742b758085ea3aeada2f79aacd0200676abc29b3", size = 20542, upload-time = "2026-10-19T05:59:33.855Z" },+ { url = "https://files.pythonhosted.org/packages/9d/f7/1be4a72302122cd65d44ba7845b2c49030ca85ed0367101002208688cebd/xxhash-4.0.2-cp314-cp314-win32.whl", hash = "sha256:74a92b9104c4af158ce37021b32cb165aa74e69c39bd10bacf569f39604bf2c9", size = 35133, upload-time = "2026-10-19T05:58:21.914Z" },+ { url = "https://files.pythonhosted.org/packages/df/db/95d66e6530e2983579a8eceabc40b812dba752c993eaece618f2c3bed64a/xxhash-4.0.2-cp314-cp314-win_amd64.whl", hash = "sha256:2b5849d45e5c12ddd23316c999eafda73c3ad00b589c474285dcf4135205921e", size = 37133, upload-time = "2026-10-19T06:00:14.606Z" },+ { url = "https://files.pythonhosted.org/packages/3c/e8/142c229cd93414feaf84a02c6d6af1bcc111611117c8cb9ba0eaa44185ba/xxhash-4.0.2-cp314-cp314-win_arm64.whl", hash = "sha256:eb90b2efd8d76777995ffdf3a134f079a79d59727a3301ca98f818fc142e841a", size = 34368, upload-time = "2026-10-19T05:58:48.006Z" },+ { url = "https://files.pythonhosted.org/packages/8d/fa/ea1fbc3a8a9667f3458eaae7f9b461276b971ee2842d9c12393967bd4c46/xxhash-4.0.2-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:e83c54a9b8477079d6dbd3814ab444f43819ae1aa06b5098c1020d77747897c0", size = 38632, upload-time = "2026-10-19T05:59:36.344Z" },+ { url = "https://files.pythonhosted.org/packages/a0/0f/d83d50c32da714f714f5813335e2e7b2656e44c9da84fc903c41a2ffcab0/xxhash-4.0.2-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:8c24094617758a4953fbf56e96637262b56d5007fcf34756ecb8d0b60231f53e", size = 36287, upload-time = "2026-10-19T05:58:25.044Z" },+ { url = "https://files.pythonhosted.org/packages/9f/62/31dc032654742df420546c0eafddb5e2e08a19774265ff876e4ae23b0c45/xxhash-4.0.2-cp314-cp314t-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:88fb30a81b5c7cb4b4dac3b4974deb00de06f5ed4b15fbacf5c7e14d670ec049", size = 273710, upload-time = "2026-10-19T06:01:35.155Z" },+ { url = "https://files.pythonhosted.org/packages/5f/79/4ea0c32a32b2b2ad9cac1152463939c5453a870367d6ee9d809c645923ee/xxhash-4.0.2-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:b9c7c18d235991edcfa2275889e84a1458dff0b9315cb7351f5368c5b942bc0d", size = 301060, upload-time = "2026-10-19T05:59:35.389Z" },+ { url = "https://files.pythonhosted.org/packages/a7/5f/263f715b93b5b6a35da9eafce6bc385b94720c023e81a64dfa0e4cd8ad59/xxhash-4.0.2-cp314-cp314t-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:4d3a90ec615e72934be372bf734190626614929054809ac12e59950aca91d8a4", size = 312708, upload-time = "2026-10-19T05:58:24.197Z" },+ { url = "https://files.pythonhosted.org/packages/01/7e/9786187749ecf216baf7c6c4897756e83cd8e8aeb67bce53b118cd65e62d/xxhash-4.0.2-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:bdec072bdb457c65e4b96eab7610af72d1535ce38adb32b4e02fa6957d7cd2b8", size = 301401, upload-time = "2026-10-19T06:00:15.736Z" },+ { url = "https://files.pythonhosted.org/packages/43/65/edb9dabb49c9438922980a1ac76f28f047b1126e9bfb1355c6467f14631a/xxhash-4.0.2-cp314-cp314t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:f6efd3d8a3ee0b86dd7ce3e6ffe47dcc115f71c38cd9f7392e6387fa541a243e", size = 534468, upload-time = "2026-10-19T05:58:50.235Z" },+ { url = "https://files.pythonhosted.org/packages/f3/3c/973412a0e43b02a3538ba6c71ad1732f3b6ccff0dc1855655b36b6c98be4/xxhash-4.0.2-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:52dff0cfe99e1f03614a40867e39d5c5a1d55047e114265db4ec2355d65fc542", size = 279586, upload-time = "2026-10-19T05:59:37.848Z" },+ { url = "https://files.pythonhosted.org/packages/6f/c9/8b04ad1d7a5dd0e3141947897660abd429c9743ee83b2931fcb9ecaadc77/xxhash-4.0.2-cp314-cp314t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:49b93898657ba0dd4517576b5c94fb0aa6738200f6d1ec2dbc9d0981154828dc", size = 358893, upload-time = "2026-10-19T05:58:28.361Z" },+ { url = "https://files.pythonhosted.org/packages/7c/e7/13900a89cbd65f9dd31032fe6df11aa385195cedcd9fd3c8346edb7eb57c/xxhash-4.0.2-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:5065d7e74b7b3e3df03e11b47d9b14bdcdd0171603ae77cf39c89df140e3e948", size = 295297, upload-time = "2026-10-19T06:01:36.691Z" },+ { url = "https://files.pythonhosted.org/packages/dd/15/bc6b5a50c696575094b6081ec637a22170f2ad7b702b056729c1bf2e0110/xxhash-4.0.2-cp314-cp314t-musllinux_1_2_armv7l.whl", hash = "sha256:763a9b3447ece8a5a1e9e27749ef3910a2f6e8ac251b8983a3da2e0801956e02", size = 320215, upload-time = "2026-10-19T05:59:37.064Z" },+ { url = "https://files.pythonhosted.org/packages/9f/09/34efaa3a992a52ad2142a11a547c075af15705292a7d99c2e1f77d443773/xxhash-4.0.2-cp314-cp314t-musllinux_1_2_i686.whl", hash = "sha256:f1a31825aa626279c25d797c105641d398865a93e96a042cb89c7faaa8905e90", size = 279403, upload-time = "2026-10-19T05:58:27.814Z" },+ { url = "https://files.pythonhosted.org/packages/ba/27/751da8c167e1410fc776e3da485a82f54696b1ac2c555cd9e4fbd4677338/xxhash-4.0.2-cp314-cp314t-musllinux_1_2_ppc64le.whl", hash = "sha256:3e229bf3c7fa330c84ca25bbc29a83a6d078ef2cf3b7b826a5c9b3828aac6f07", size = 297577, upload-time = "2026-10-19T06:00:16.937Z" },+ { url = "https://files.pythonhosted.org/packages/29/28/7eebb4bb64e8fa23b09a48e49470dd2090ae33beb93991d7be865119cdd1/xxhash-4.0.2-cp314-cp314t-musllinux_1_2_riscv64.whl", hash = "sha256:fe86ae86241d0aee7561b19bf892c9250a976e4a56fc052405cd537180e7af15", size = 348508, upload-time = "2026-10-19T05:58:53.232Z" },+ { url = "https://files.pythonhosted.org/packages/fa/5b/0cf94b43a664ad1cd24cacc6f37ede95b3f705e3b103b492cb9ce29c1c1a/xxhash-4.0.2-cp314-cp314t-musllinux_1_2_s390x.whl", hash = "sha256:3d8b5da050138043edb95fbd4b79e240a0994d2f272e872cf074dc6acd68249b", size = 499287, upload-time = "2026-10-19T05:59:39.431Z" },+ { url = "https://files.pythonhosted.org/packages/8e/91/22aaa89dd14620376c17c9cee12aa94c3e7d746ab99af4b48c0482add9f5/xxhash-4.0.2-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:cf390edab741574cc770e0b587cc2d6f2573152ba09bf85fdae10e556333ac77", size = 274977, upload-time = "2026-10-19T05:58:30.499Z" },+ { url = "https://files.pythonhosted.org/packages/c0/d6/43ed2405230cb1137c5c451151a3cfb5427423bbf6ad1b20e0de45e1804c/xxhash-4.0.2-cp314-cp314t-win32.whl", hash = "sha256:768aba59c7fb2e3e976560c91223cb01f00f83809088e451e59f05b841486fbf", size = 35463, upload-time = "2026-10-19T06:01:38.092Z" },+ { url = "https://files.pythonhosted.org/packages/ff/74/a20b6ee566d4ea3d81cbe99bc04a116f8c97246e1404f13b930b2ad9cdc4/xxhash-4.0.2-cp314-cp314t-win_amd64.whl", hash = "sha256:ca848e5edfe3aa31ea7355df790b25e55f910dbb540d587e738e1b0c644e1263", size = 37474, upload-time = "2026-10-19T05:59:38.345Z" },+ { url = "https://files.pythonhosted.org/packages/4c/9a/98b69e482b71a7c956fe7a748b118df4b268edb31b10b35e63878a467397/xxhash-4.0.2-cp314-cp314t-win_arm64.whl", hash = "sha256:04fe6c267bb6a04d8e5f56d8058eac0621359dc8fc03faa0c03cf1dd4343304e", size = 34621, upload-time = "2026-10-19T05:58:31.122Z" },+ { url = "https://files.pythonhosted.org/packages/d4/df/58b65a0a654bfa4da9a19168338fc89e30337f60ccb7b7d695fc2ebf7e67/xxhash-4.0.2-cp315-cp315-android_24_arm64_v8a.whl", hash = "sha256:bdee724c52954f6d3a551adc30eac1555a6ab1444dd3e02bffcc51832cbcd5da", size = 43729, upload-time = "2026-10-19T06:00:18.211Z" },+ { url = "https://files.pythonhosted.org/packages/07/aa/d25b1a9f4f7dcd2330651a2253f6bc8aee5efdedd4839349bb734dcc2156/xxhash-4.0.2-cp315-cp315-android_24_x86_64.whl", hash = "sha256:79d832049ab43b88846a13161351887892f3d8cb0bcd3e7c91b3f125caada384", size = 40737, upload-time = "2026-10-19T05:58:55.45Z" },+ { url = "https://files.pythonhosted.org/packages/db/77/bac055f63b9be647f28d81ec040db14ee448ebac4c3eb2066b4170b68ea9/xxhash-4.0.2-cp315-cp315-ios_13_0_arm64_iphoneos.whl", hash = "sha256:fb3dce09d52103f29a4648649df1ab217e28ccc2e9a9c08e8daab472e5cda9c9", size = 34768, upload-time = "2026-10-19T05:59:40.791Z" },+ { url = "https://files.pythonhosted.org/packages/d9/a3/eab44082caa9fc734eac6777a705b659c8de634c2a08da51765e48ccb639/xxhash-4.0.2-cp315-cp315-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:58d8fc67453d337a8cbeed4f5543493c3792cb5f3839c17bc08ecf307592466f", size = 35722, upload-time = "2026-10-19T05:58:32.75Z" },+ { url = "https://files.pythonhosted.org/packages/9a/0c/fd2f4090ee2466e9af1f5dd34b298f3d97463fbb537de066beb47ce961aa/xxhash-4.0.2-cp315-cp315-ios_13_0_x86_64_iphonesimulator.whl", hash = "sha256:4a5955614bf744ac52faaf535ff94df3e935ec057c6242a3d8aa4e1007efa0f0", size = 38079, upload-time = "2026-10-19T06:01:39.191Z" },+ { url = "https://files.pythonhosted.org/packages/73/77/dba9d1377dbab3c37f7302dccaf874fb7dcda0850ac6ca409aa95df39556/xxhash-4.0.2-cp315-cp315-macosx_10_15_x86_64.whl", hash = "sha256:eff48c792788e33ace8e8e3ef6a0db45741d6acdc35c9b89dc914469fa040536", size = 38228, upload-time = "2026-10-19T05:59:39.965Z" },+ { url = "https://files.pythonhosted.org/packages/5b/1a/d38f9b0876959b5dbb3940efd404ff7ff37297b9a494a4152f022292672d/xxhash-4.0.2-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:b881b67c01929df867d30fed94d4221205639072a63049818732c1bae54e74f0", size = 35966, upload-time = "2026-10-19T05:58:33.361Z" },+ { url = "https://files.pythonhosted.org/packages/f6/3c/f65cd98552eb469de81b74db65ad848a94f5259b915ead99ab84080b139d/xxhash-4.0.2-cp315-cp315-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:7016f753d9c79d2ed53a1517b3eb1bd475f05d026fa3fbc3acec393d14ddd396", size = 264586, upload-time = "2026-10-19T06:00:19.361Z" },+ { url = "https://files.pythonhosted.org/packages/83/84/324228db6b7b0ddeb527f0936d2aeb72664e0a6ce4129abdfb0e78444460/xxhash-4.0.2-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f5a509325aea8802d2ab710a5f2fb7c4d7b1a6c90f9a148dbc9f84311a1aa15e", size = 285892, upload-time = "2026-10-19T05:58:57.311Z" },+ { url = "https://files.pythonhosted.org/packages/2d/e4/52f06d36a699084c6743b18fdad46429a657aad83479a88f9a639041fdd7/xxhash-4.0.2-cp315-cp315-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:7c1087b8dc4a08709e1ce358a79671f9aa4d029211aff537d0f821e4a6483305", size = 306548, upload-time = "2026-10-19T05:59:42.377Z" },+ { url = "https://files.pythonhosted.org/packages/73/50/1945f2a0e39a80ac84ab40bb9fde7b83b4039077478119b504ac162d160c/xxhash-4.0.2-cp315-cp315-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:531a1056fdfae837ef56c81e62bb4a0ce3274b813a3164bb558151d913684cce", size = 287958, upload-time = "2026-10-19T05:58:34.589Z" },+ { url = "https://files.pythonhosted.org/packages/d2/f2/8df0a257de50f8550d047b6c03b7df336147f33163dc1c5455ab5c325b44/xxhash-4.0.2-cp315-cp315-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:fe3ae82b1c7d031da7bb300188fe31018fbc05e1e496e0edb7c930d6ecf88d1a", size = 520071, upload-time = "2026-10-19T06:01:40.79Z" },+ { url = "https://files.pythonhosted.org/packages/0a/26/8a5349232374825f418141292a3edda80ac7c5d818126eee5c594fffdb97/xxhash-4.0.2-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:5fb7bfdd0d1136fb73e4efa9a1eaff71a72f45ff7409647f601bf714d7838922", size = 268246, upload-time = "2026-10-19T05:59:41.356Z" },+ { url = "https://files.pythonhosted.org/packages/d0/1f/3248f97b75c221d352bd37d70d5f96384f4cfa9ee375a7ed7956f7d1657f/xxhash-4.0.2-cp315-cp315-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:9a1f6598dc8f7ccdc9bd5ac51264c71431185194e8c88042502a04c1f53b5780", size = 350146, upload-time = "2026-10-19T05:58:35.269Z" },+ { url = "https://files.pythonhosted.org/packages/a7/65/682ffa31455530fb402947eb8956406378dc853185348750c7cd1a1724a7/xxhash-4.0.2-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:329bf14bab110bf111aa7211c613a94e97e4554407d2cc964c01338278cd4213", size = 281953, upload-time = "2026-10-19T06:00:20.692Z" },+ { url = "https://files.pythonhosted.org/packages/66/cb/57c69db6dd0b9959b9ed28a2c73a659f5c621987ab153a824ae76f331d52/xxhash-4.0.2-cp315-cp315-musllinux_1_2_armv7l.whl", hash = "sha256:fbf323d9c22c6ac25cd8c4633566393282fa22db583ef0320f82bded10d7cc2e", size = 307854, upload-time = "2026-10-19T05:58:59.316Z" },+ { url = "https://files.pythonhosted.org/packages/ba/63/755416cb522db17097e32f4d6871a358ba977bba77849efede09bd30a230/xxhash-4.0.2-cp315-cp315-musllinux_1_2_i686.whl", hash = "sha256:1ba7e798c28e327b221270af073f7319c771daaf5974d18856c0ed3d0fa1c6de", size = 268216, upload-time = "2026-10-19T05:59:44.779Z" },+ { url = "https://files.pythonhosted.org/packages/27/77/d10ddc5642addbdd11c7e7ee4f02d2876d00b437bfba8e49cc2eff96e4f7/xxhash-4.0.2-cp315-cp315-musllinux_1_2_ppc64le.whl", hash = "sha256:b9bff92881cfd1d4f98f27e1275f125f90ddf324571ac9a3e35d1dfcf6f42d19", size = 284949, upload-time = "2026-10-19T05:58:36.835Z" },+ { url = "https://files.pythonhosted.org/packages/27/70/dcbd582e7f6bdac6673a93ad7eff2309ad2a06d2f5f92922389a90d8a708/xxhash-4.0.2-cp315-cp315-musllinux_1_2_riscv64.whl", hash = "sha256:bb99a2c5c35cad78284e057f8207856c911ac088ff89d0807dccf07b65775895", size = 338056, upload-time = "2026-10-19T06:01:42.241Z" },+ { url = "https://files.pythonhosted.org/packages/55/28/3ab7cb9ec21f590cf56200facc8850260dfb96d5099919df7f93d4613983/xxhash-4.0.2-cp315-cp315-musllinux_1_2_s390x.whl", hash = "sha256:730fba89df435ac081bc2ae28e4fa0ca5009a9eb5f4947b648abc27acd96e7b3", size = 487603, upload-time = "2026-10-19T05:59:43.003Z" },+ { url = "https://files.pythonhosted.org/packages/c2/d1/f48e74dbb0ca9d40565965845a5a6384216e238b7aa016f8a67dfe929e32/xxhash-4.0.2-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:2ca60825069a19e381f4ed03d0e036907b2b98460d33d4f8d1a93cf2d7e37c7b", size = 263834, upload-time = "2026-10-19T05:58:37.629Z" },+ { url = "https://files.pythonhosted.org/packages/cf/72/cddec8f3243d53d2387e9529a9556e8fe820b411f87c791852ca2056c128/xxhash-4.0.2-cp315-cp315-pyemscripten_2026_5_wasm32.whl", hash = "sha256:89d02277a7d5ce8b3fe21182ce4e32cca54963768c4b9609ce29e1ac82922acf", size = 20549, upload-time = "2026-10-19T06:00:21.926Z" },+ { url = "https://files.pythonhosted.org/packages/26/6f/50f89c9174c2b5fae56a6ec1b81f1d8065ced4792974f9575daf5ef2629b/xxhash-4.0.2-cp315-cp315-win32.whl", hash = "sha256:b4c405512c813a47cf70e47c9886b07702a38e991756216b65ac19f9cbb4f8f8", size = 35136, upload-time = "2026-10-19T05:59:01.461Z" },+ { url = "https://files.pythonhosted.org/packages/77/a4/06a47cf94314277d27f2468888ab93d1b82e8334ad69281775d8b21a3944/xxhash-4.0.2-cp315-cp315-win_amd64.whl", hash = "sha256:30ffd0deaf0e9ea112c38656922323ae23dbaa90878cebdb243f646d121e52db", size = 37154, upload-time = "2026-10-19T05:59:47.022Z" },+ { url = "https://files.pythonhosted.org/packages/dd/ec/9450480bef24ecb6dae89f69456b2d891c59cccf86a4756b2cbe70fdd4ad/xxhash-4.0.2-cp315-cp315-win_arm64.whl", hash = "sha256:6010eab32dd57dcb8070b81a5d459c422d09de3ffd1bf6f11f0ee381582fe5a5", size = 34365, upload-time = "2026-10-19T05:58:39.414Z" },+ { url = "https://files.pythonhosted.org/packages/d5/6a/89f7d7b924e82b852815b04175923d7a2a83b7b993484003b5c9a09b8468/xxhash-4.0.2-cp315-cp315t-macosx_10_15_x86_64.whl", hash = "sha256:fdc8799f1a4835b40c615cbc9ce73c8a42f51c3218726d285367dcf853f36128", size = 38589, upload-time = "2026-10-19T06:01:43.576Z" },+ { url = "https://files.pythonhosted.org/packages/28/c8/35487956f53073b94621cf0a3e157baaf4d9ed79a4b37aae73f26e8ef617/xxhash-4.0.2-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:aa60df2de8dc4f59ae4faddd77237514ff88d15c2afd6d501e21dbe82a4711db", size = 36357, upload-time = "2026-10-19T05:59:45.367Z" },+ { url = "https://files.pythonhosted.org/packages/9b/64/30e6b89adc1b37b0c40885d73682ec5f0a939ded3628f53e6b81e735daa1/xxhash-4.0.2-cp315-cp315t-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:2cf332a7b823e867cc0d8e4c69eb5c82ae96ed827677fe4d96f990a6a1fd86b8", size = 273536, upload-time = "2026-10-19T05:58:40.318Z" },+ { url = "https://files.pythonhosted.org/packages/9e/ce/9dd64e3c06ef7116b3a10ee78fb56276f4382191b008772bd3ceaca80c0f/xxhash-4.0.2-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:5846aa6fe15c5b1cda6738ef9b1ba3cf49028b729507ce44a1e9fc2642586b06", size = 299112, upload-time = "2026-10-19T06:00:23.08Z" },+ { url = "https://files.pythonhosted.org/packages/6c/e2/e58e25d55f5d3d4786b50b537078c1eb57a2efe8aa079bbc55d7f785d196/xxhash-4.0.2-cp315-cp315t-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:07abbc84c3b22064294e8d7f8e8d71a3c0dd3ae9aca8dfda55ad1977d3a7af61", size = 314503, upload-time = "2026-10-19T05:59:03.402Z" },+ { url = "https://files.pythonhosted.org/packages/7c/a6/1d8948e5ebbd7d408b7e06edb0ae4f4fcbb9ac61fcb558bc49d28231a989/xxhash-4.0.2-cp315-cp315t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:0c9ce49f326c85958df18789486d4c28812b52890e74d833b121735200d04bce", size = 299177, upload-time = "2026-10-19T05:59:49.215Z" },+ { url = "https://files.pythonhosted.org/packages/d3/a0/2b3b1c252264965ed7878d927547bf9969d553d75b92a272fba91d268cac/xxhash-4.0.2-cp315-cp315t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:da1a626793a5fde9c97466d443ae7c62f3d9bdc8658fd8363f435852952996d3", size = 531942, upload-time = "2026-10-19T05:58:41.625Z" },+ { url = "https://files.pythonhosted.org/packages/20/18/7163affae311b049315549e3b894983289091dc62c9f72959607b5748bb1/xxhash-4.0.2-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:250048412cb196e1f705134dadbc415eca399e74d2678b935660be0b2e4fc380", size = 278740, upload-time = "2026-10-19T06:01:44.69Z" },+ { url = "https://files.pythonhosted.org/packages/42/48/0f318837dff3b56ed434ae0939da047c280805092b07d993750175f3ba74/xxhash-4.0.2-cp315-cp315t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:b5fbcdf157caa642de731565310bae6a5c3b1e15f28507feb3eddf04bd4a56a9", size = 359859, upload-time = "2026-10-19T05:59:47.605Z" },+ { url = "https://files.pythonhosted.org/packages/99/2f/78c271392a474b5d24f3148ba111a74e36e91718c782a455b847453279af/xxhash-4.0.2-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:4d86d5aaae8312de06d25b91fbc901b891b3b5ce2f5c8359b340b4bcc3d01b8f", size = 293523, upload-time = "2026-10-19T05:58:42.495Z" },+ { url = "https://files.pythonhosted.org/packages/11/16/839eacbb24390476e95a03f6738b30a745a6b79c117e6d02c7e3367e7907/xxhash-4.0.2-cp315-cp315t-musllinux_1_2_armv7l.whl", hash = "sha256:2bc6cfaa4a39bfca4c31878ad769986d2d039673eaf527068f668e88ff65ab99", size = 318759, upload-time = "2026-10-19T06:00:24.336Z" },+ { url = "https://files.pythonhosted.org/packages/a3/ba/c7750692cb427911d3aad8447ff715b9721bcc8ae1de344a9153c7982d6b/xxhash-4.0.2-cp315-cp315t-musllinux_1_2_i686.whl", hash = "sha256:d695979588da837a36d5195d10812c4118515d33e4f41a9b4d0cd92bf7c2f716", size = 277562, upload-time = "2026-10-19T05:59:06.611Z" },+ { url = "https://files.pythonhosted.org/packages/29/65/70fefbf75329b5afb33b2bbf8035ca24eeba52f0f836e1b3d21aae153ac7/xxhash-4.0.2-cp315-cp315t-musllinux_1_2_ppc64le.whl", hash = "sha256:00329536c281e13725283421dcdf4633f5710123e06a608b910d6a6f3bc891cf", size = 295093, upload-time = "2026-10-19T05:59:51.738Z" },+ { url = "https://files.pythonhosted.org/packages/09/3a/fbe36c6fa093c481cdc8299ba63f57c786b01a2bfbc3f2fe3d5caab56731/xxhash-4.0.2-cp315-cp315t-musllinux_1_2_riscv64.whl", hash = "sha256:8113a8cb51a5121b8017f275e9aff2cb9203d57e614c989f943f81937442896b", size = 347048, upload-time = "2026-10-19T05:58:44.217Z" },+ { url = "https://files.pythonhosted.org/packages/45/7f/587b3d99d5948889ecaa01a9d99cc7208ab150dead683f60345a28a48ef1/xxhash-4.0.2-cp315-cp315t-musllinux_1_2_s390x.whl", hash = "sha256:438fdfda0fb1198b7e9a5b4da6b073f36cec5dd7129dd486bbe72c8ecd623adf", size = 497187, upload-time = "2026-10-19T06:01:46.21Z" },+ { url = "https://files.pythonhosted.org/packages/2b/87/738a71217aad9138fada7d16fc69b03325a202aebc95bb0b257d86ed9682/xxhash-4.0.2-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:2f164b788017a4a766884aa9acb3490bbc5f03a79adc7d02894393df44675c1e", size = 274316, upload-time = "2026-10-19T05:59:49.967Z" },+ { url = "https://files.pythonhosted.org/packages/6c/c9/4c59e7436d2d4ce0a84e58cf03cbf6fac603052d1135ed67f125d26f0562/xxhash-4.0.2-cp315-cp315t-win32.whl", hash = "sha256:3d7f484b338ddf6a8e58ffb73c4f9d13ea157f01152fdfdf9c44c9a59666f3ac", size = 35462, upload-time = "2026-10-19T05:58:44.88Z" },+ { url = "https://files.pythonhosted.org/packages/6b/17/78057741b329c90877b242fafffcfbb0fb4d719b7ce706fd401ee033ae73/xxhash-4.0.2-cp315-cp315t-win_amd64.whl", hash = "sha256:33f89d2a64716d7108f49b38d92ebe5344d3c50440f15f48f0f65cbcf4ffb781", size = 37478, upload-time = "2026-10-19T06:00:25.786Z" },+ { url = "https://files.pythonhosted.org/packages/6b/07/c785f081244dbac609607f1f7ab883db45b26cd291d937d9bd8b67326db0/xxhash-4.0.2-cp315-cp315t-win_arm64.whl", hash = "sha256:26f8343b7a5d65f704029a0ebeb7e98a47149cf76dcab0072f0874307181bfb5", size = 34617, upload-time = "2026-10-19T05:59:09.137Z" },+ { url = "https://files.pythonhosted.org/packages/fa/08/7273d1afe165f2035a6d9c3006d5f752df380e238f872d974c856ddc1c0c/xxhash-4.0.2-graalpy313-graalpy253_313_native-macosx_11_0_arm64.whl", hash = "sha256:ce0fd7c57fa4fe9e0a9c390a04e1668c09fc09253e8fd76f1785069508686059", size = 33915, upload-time = "2026-10-19T05:59:59.311Z" },+ { url = "https://files.pythonhosted.org/packages/95/0a/613ed5b8ded6fc2d42f54cf79f4318df1fec7d8fb0d3a9c189337220ad50/xxhash-4.0.2-graalpy313-graalpy253_313_native-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:c45f489790caf482840d2c108d50b8b0d9e77f2f6d17e2b345e2ae3dc48849ff", size = 38377, upload-time = "2026-10-19T05:58:54.679Z" },+ { url = "https://files.pythonhosted.org/packages/b7/4f/2325ba05fc5470dcc0c69e8621d82fe4474271448ba9d0f7599ab492a1ad/xxhash-4.0.2-graalpy313-graalpy253_313_native-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:87255720aa1a1be35256b688c5ee4151d3273894186cda5c8a5b82f1dc05debf", size = 37784, upload-time = "2026-10-19T06:00:31.759Z" },+ { url = "https://files.pythonhosted.org/packages/db/c6/2ca65d85a105f200e60a812fb53f70a4e4a40c2263763397a367186e6c07/xxhash-4.0.2-graalpy313-graalpy253_313_native-win_amd64.whl", hash = "sha256:2a99c2d36df2d9b238a27e1fd8547311dba51c997e4c7681a383a98c0831aee0", size = 36832, upload-time = "2026-10-19T05:59:18.738Z" },+]+[[package]]name = "yarl"version = "1.23.0"@@ -3686,6 +4056,46 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/2e/54/647ade08bf0db230bfea292f893923872fd20be6ac6f53b2b936ba839d75/zipp-3.23.0-py3-none-any.whl", hash = "sha256:071652d6115ed432f5ce1d34c336c0adfd6a884660d1e9712a256d3d3bd4b14e", size = 10276, upload-time = "2025-06-08T17:06:38.034Z" },]+[[package]]+name = "zstandard"+version = "0.25.0"+source = { registry = "https://pypi.org/simple" }+sdist = { url = "https://files.pythonhosted.org/packages/fd/aa/3e0508d5a5dd96529cdc5a97011299056e14c6505b678fd58938792794b1/zstandard-0.25.0.tar.gz", hash = "sha256:7713e1179d162cf5c7906da876ec2ccb9c3a9dcbdffef0cc7f70c3667a205f0b", size = 711513, upload-time = "2025-09-14T22:15:54.002Z" }+wheels = [+ { url = "https://files.pythonhosted.org/packages/35/0b/8df9c4ad06af91d39e94fa96cc010a24ac4ef1378d3efab9223cc8593d40/zstandard-0.25.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:ec996f12524f88e151c339688c3897194821d7f03081ab35d31d1e12ec975e94", size = 795735, upload-time = "2025-09-14T22:17:26.042Z" },+ { url = "https://files.pythonhosted.org/packages/3f/06/9ae96a3e5dcfd119377ba33d4c42a7d89da1efabd5cb3e366b156c45ff4d/zstandard-0.25.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:a1a4ae2dec3993a32247995bdfe367fc3266da832d82f8438c8570f989753de1", size = 640440, upload-time = "2025-09-14T22:17:27.366Z" },+ { url = "https://files.pythonhosted.org/packages/d9/14/933d27204c2bd404229c69f445862454dcc101cd69ef8c6068f15aaec12c/zstandard-0.25.0-cp313-cp313-manylinux2010_i686.manylinux2014_i686.manylinux_2_12_i686.manylinux_2_17_i686.whl", hash = "sha256:e96594a5537722fdfb79951672a2a63aec5ebfb823e7560586f7484819f2a08f", size = 5343070, upload-time = "2025-09-14T22:17:28.896Z" },+ { url = "https://files.pythonhosted.org/packages/6d/db/ddb11011826ed7db9d0e485d13df79b58586bfdec56e5c84a928a9a78c1c/zstandard-0.25.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:bfc4e20784722098822e3eee42b8e576b379ed72cca4a7cb856ae733e62192ea", size = 5063001, upload-time = "2025-09-14T22:17:31.044Z" },+ { url = "https://files.pythonhosted.org/packages/db/00/87466ea3f99599d02a5238498b87bf84a6348290c19571051839ca943777/zstandard-0.25.0-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:457ed498fc58cdc12fc48f7950e02740d4f7ae9493dd4ab2168a47c93c31298e", size = 5394120, upload-time = "2025-09-14T22:17:32.711Z" },+ { url = "https://files.pythonhosted.org/packages/2b/95/fc5531d9c618a679a20ff6c29e2b3ef1d1f4ad66c5e161ae6ff847d102a9/zstandard-0.25.0-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:fd7a5004eb1980d3cefe26b2685bcb0b17989901a70a1040d1ac86f1d898c551", size = 5451230, upload-time = "2025-09-14T22:17:34.41Z" },+ { url = "https://files.pythonhosted.org/packages/63/4b/e3678b4e776db00f9f7b2fe58e547e8928ef32727d7a1ff01dea010f3f13/zstandard-0.25.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:8e735494da3db08694d26480f1493ad2cf86e99bdd53e8e9771b2752a5c0246a", size = 5547173, upload-time = "2025-09-14T22:17:36.084Z" },+ { url = "https://files.pythonhosted.org/packages/4e/d5/ba05ed95c6b8ec30bd468dfeab20589f2cf709b5c940483e31d991f2ca58/zstandard-0.25.0-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:3a39c94ad7866160a4a46d772e43311a743c316942037671beb264e395bdd611", size = 5046736, upload-time = "2025-09-14T22:17:37.891Z" },+ { url = "https://files.pythonhosted.org/packages/50/d5/870aa06b3a76c73eced65c044b92286a3c4e00554005ff51962deef28e28/zstandard-0.25.0-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:172de1f06947577d3a3005416977cce6168f2261284c02080e7ad0185faeced3", size = 5576368, upload-time = "2025-09-14T22:17:40.206Z" },+ { url = "https://files.pythonhosted.org/packages/5d/35/398dc2ffc89d304d59bc12f0fdd931b4ce455bddf7038a0a67733a25f550/zstandard-0.25.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:3c83b0188c852a47cd13ef3bf9209fb0a77fa5374958b8c53aaa699398c6bd7b", size = 4954022, upload-time = "2025-09-14T22:17:41.879Z" },+ { url = "https://files.pythonhosted.org/packages/9a/5c/36ba1e5507d56d2213202ec2b05e8541734af5f2ce378c5d1ceaf4d88dc4/zstandard-0.25.0-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:1673b7199bbe763365b81a4f3252b8e80f44c9e323fc42940dc8843bfeaf9851", size = 5267889, upload-time = "2025-09-14T22:17:43.577Z" },+ { url = "https://files.pythonhosted.org/packages/70/e8/2ec6b6fb7358b2ec0113ae202647ca7c0e9d15b61c005ae5225ad0995df5/zstandard-0.25.0-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:0be7622c37c183406f3dbf0cba104118eb16a4ea7359eeb5752f0794882fc250", size = 5433952, upload-time = "2025-09-14T22:17:45.271Z" },+ { url = "https://files.pythonhosted.org/packages/7b/01/b5f4d4dbc59ef193e870495c6f1275f5b2928e01ff5a81fecb22a06e22fb/zstandard-0.25.0-cp313-cp313-musllinux_1_2_s390x.whl", hash = "sha256:5f5e4c2a23ca271c218ac025bd7d635597048b366d6f31f420aaeb715239fc98", size = 5814054, upload-time = "2025-09-14T22:17:47.08Z" },+ { url = "https://files.pythonhosted.org/packages/b2/e5/fbd822d5c6f427cf158316d012c5a12f233473c2f9c5fe5ab1ae5d21f3d8/zstandard-0.25.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:4f187a0bb61b35119d1926aee039524d1f93aaf38a9916b8c4b78ac8514a0aaf", size = 5360113, upload-time = "2025-09-14T22:17:48.893Z" },+ { url = "https://files.pythonhosted.org/packages/8e/e0/69a553d2047f9a2c7347caa225bb3a63b6d7704ad74610cb7823baa08ed7/zstandard-0.25.0-cp313-cp313-win32.whl", hash = "sha256:7030defa83eef3e51ff26f0b7bfb229f0204b66fe18e04359ce3474ac33cbc09", size = 436936, upload-time = "2025-09-14T22:17:52.658Z" },+ { url = "https://files.pythonhosted.org/packages/d9/82/b9c06c870f3bd8767c201f1edbdf9e8dc34be5b0fbc5682c4f80fe948475/zstandard-0.25.0-cp313-cp313-win_amd64.whl", hash = "sha256:1f830a0dac88719af0ae43b8b2d6aef487d437036468ef3c2ea59c51f9d55fd5", size = 506232, upload-time = "2025-09-14T22:17:50.402Z" },+ { url = "https://files.pythonhosted.org/packages/d4/57/60c3c01243bb81d381c9916e2a6d9e149ab8627c0c7d7abb2d73384b3c0c/zstandard-0.25.0-cp313-cp313-win_arm64.whl", hash = "sha256:85304a43f4d513f5464ceb938aa02c1e78c2943b29f44a750b48b25ac999a049", size = 462671, upload-time = "2025-09-14T22:17:51.533Z" },+ { url = "https://files.pythonhosted.org/packages/3d/5c/f8923b595b55fe49e30612987ad8bf053aef555c14f05bb659dd5dbe3e8a/zstandard-0.25.0-cp314-cp314-macosx_10_13_x86_64.whl", hash = "sha256:e29f0cf06974c899b2c188ef7f783607dbef36da4c242eb6c82dcd8b512855e3", size = 795887, upload-time = "2025-09-14T22:17:54.198Z" },+ { url = "https://files.pythonhosted.org/packages/8d/09/d0a2a14fc3439c5f874042dca72a79c70a532090b7ba0003be73fee37ae2/zstandard-0.25.0-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:05df5136bc5a011f33cd25bc9f506e7426c0c9b3f9954f056831ce68f3b6689f", size = 640658, upload-time = "2025-09-14T22:17:55.423Z" },+ { url = "https://files.pythonhosted.org/packages/5d/7c/8b6b71b1ddd517f68ffb55e10834388d4f793c49c6b83effaaa05785b0b4/zstandard-0.25.0-cp314-cp314-manylinux2010_i686.manylinux_2_12_i686.manylinux_2_28_i686.whl", hash = "sha256:f604efd28f239cc21b3adb53eb061e2a205dc164be408e553b41ba2ffe0ca15c", size = 5379849, upload-time = "2025-09-14T22:17:57.372Z" },+ { url = "https://files.pythonhosted.org/packages/a4/86/a48e56320d0a17189ab7a42645387334fba2200e904ee47fc5a26c1fd8ca/zstandard-0.25.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:223415140608d0f0da010499eaa8ccdb9af210a543fac54bce15babbcfc78439", size = 5058095, upload-time = "2025-09-14T22:17:59.498Z" },+ { url = "https://files.pythonhosted.org/packages/f8/ad/eb659984ee2c0a779f9d06dbfe45e2dc39d99ff40a319895df2d3d9a48e5/zstandard-0.25.0-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:2e54296a283f3ab5a26fc9b8b5d4978ea0532f37b231644f367aa588930aa043", size = 5551751, upload-time = "2025-09-14T22:18:01.618Z" },+ { url = "https://files.pythonhosted.org/packages/61/b3/b637faea43677eb7bd42ab204dfb7053bd5c4582bfe6b1baefa80ac0c47b/zstandard-0.25.0-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:ca54090275939dc8ec5dea2d2afb400e0f83444b2fc24e07df7fdef677110859", size = 6364818, upload-time = "2025-09-14T22:18:03.769Z" },+ { url = "https://files.pythonhosted.org/packages/31/dc/cc50210e11e465c975462439a492516a73300ab8caa8f5e0902544fd748b/zstandard-0.25.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:e09bb6252b6476d8d56100e8147b803befa9a12cea144bbe629dd508800d1ad0", size = 5560402, upload-time = "2025-09-14T22:18:05.954Z" },+ { url = "https://files.pythonhosted.org/packages/c9/ae/56523ae9c142f0c08efd5e868a6da613ae76614eca1305259c3bf6a0ed43/zstandard-0.25.0-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:a9ec8c642d1ec73287ae3e726792dd86c96f5681eb8df274a757bf62b750eae7", size = 4955108, upload-time = "2025-09-14T22:18:07.68Z" },+ { url = "https://files.pythonhosted.org/packages/98/cf/c899f2d6df0840d5e384cf4c4121458c72802e8bda19691f3b16619f51e9/zstandard-0.25.0-cp314-cp314-musllinux_1_2_i686.whl", hash = "sha256:a4089a10e598eae6393756b036e0f419e8c1d60f44a831520f9af41c14216cf2", size = 5269248, upload-time = "2025-09-14T22:18:09.753Z" },+ { url = "https://files.pythonhosted.org/packages/1b/c0/59e912a531d91e1c192d3085fc0f6fb2852753c301a812d856d857ea03c6/zstandard-0.25.0-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:f67e8f1a324a900e75b5e28ffb152bcac9fbed1cc7b43f99cd90f395c4375344", size = 5430330, upload-time = "2025-09-14T22:18:11.966Z" },+ { url = "https://files.pythonhosted.org/packages/a0/1d/7e31db1240de2df22a58e2ea9a93fc6e38cc29353e660c0272b6735d6669/zstandard-0.25.0-cp314-cp314-musllinux_1_2_s390x.whl", hash = "sha256:9654dbc012d8b06fc3d19cc825af3f7bf8ae242226df5f83936cb39f5fdc846c", size = 5811123, upload-time = "2025-09-14T22:18:13.907Z" },+ { url = "https://files.pythonhosted.org/packages/f6/49/fac46df5ad353d50535e118d6983069df68ca5908d4d65b8c466150a4ff1/zstandard-0.25.0-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:4203ce3b31aec23012d3a4cf4a2ed64d12fea5269c49aed5e4c3611b938e4088", size = 5359591, upload-time = "2025-09-14T22:18:16.465Z" },+ { url = "https://files.pythonhosted.org/packages/c2/38/f249a2050ad1eea0bb364046153942e34abba95dd5520af199aed86fbb49/zstandard-0.25.0-cp314-cp314-win32.whl", hash = "sha256:da469dc041701583e34de852d8634703550348d5822e66a0c827d39b05365b12", size = 444513, upload-time = "2025-09-14T22:18:20.61Z" },+ { url = "https://files.pythonhosted.org/packages/3a/43/241f9615bcf8ba8903b3f0432da069e857fc4fd1783bd26183db53c4804b/zstandard-0.25.0-cp314-cp314-win_amd64.whl", hash = "sha256:c19bcdd826e95671065f8692b5a4aa95c52dc7a02a4c5a0cac46deb879a017a2", size = 516118, upload-time = "2025-09-14T22:18:17.849Z" },+ { url = "https://files.pythonhosted.org/packages/f0/ef/da163ce2450ed4febf6467d77ccb4cd52c4c30ab45624bad26ca0a27260c/zstandard-0.25.0-cp314-cp314-win_arm64.whl", hash = "sha256:d7541afd73985c630bafcd6338d2518ae96060075f9463d7dc14cfb33514383d", size = 476940, upload-time = "2025-09-14T22:18:19.088Z" },+]+[[package]]name = "zxcvbn"version = "4.5.0"