Add flow_records attribute and update build method in RunFlowComponent

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-03-04 10:26:02 -03:00
commit 46520e84a3

View file

@ -12,6 +12,7 @@ class RunFlowComponent(CustomComponent):
def get_flow_names(self) -> List[str]: def get_flow_names(self) -> List[str]:
flow_records = self.list_flows() flow_records = self.list_flows()
self.flow_records = flow_records
return [flow_record.data["name"] for flow_record in flow_records] return [flow_record.data["name"] for flow_record in flow_records]
def build_config(self): def build_config(self):
@ -20,7 +21,7 @@ class RunFlowComponent(CustomComponent):
"display_name": "Input Value", "display_name": "Input Value",
"multiline": True, "multiline": True,
}, },
"flow_id": { "flow": {
"display_name": "Flow ID", "display_name": "Flow ID",
"info": "The ID of the flow to run.", "info": "The ID of the flow to run.",
"options": self.get_flow_names, "options": self.get_flow_names,
@ -31,10 +32,17 @@ class RunFlowComponent(CustomComponent):
}, },
} }
async def build( async def build(self, input_value: Text, flow: str, tweaks: NestedDict) -> Record:
self, input_value: Text, flow_id: str, tweaks: NestedDict
) -> Record:
input_dict = {"input_value": input_value} input_dict = {"input_value": input_value}
flow_ids = [
flow_record.data["id"]
for flow_record in self.flow_records
if flow_record.data["name"] == flow
]
if not flow_ids:
raise ValueError(f"Flow {flow} not found.")
flow_id = flow_ids[0]
result: List[Optional[ResultData]] = await self.run_flow( result: List[Optional[ResultData]] = await self.run_flow(
input_value=input_dict, flow_id=flow_id, tweaks=tweaks input_value=input_dict, flow_id=flow_id, tweaks=tweaks
) )