11import asyncio
2- import inspect
32import json
43import os
54import uuid
6- from typing import Any , Dict , Optional , Type , get_type_hints
5+ from typing import Any , Dict
76
8- from llama_index .core .workflow import Event , StartEvent , StopEvent , Workflow
9- from llama_index .core .workflow .decorators import StepConfig
7+ from llama_index .core .workflow import StopEvent , Workflow
108from uipath ._cli ._utils ._console import ConsoleLogger
119from uipath ._cli ._utils ._parse_ast import generate_bindings_json # type: ignore
1210from uipath ._cli .middlewares import MiddlewareResult
@@ -50,45 +48,6 @@ def process_nullable_types(properties: Dict[str, Any]) -> Dict[str, Any]:
5048 return result
5149
5250
53- def find_event_types (workflow : Workflow , event_base_class : Type [Event ]) -> Type [Event ]:
54- """Find the StartEvent or StopEvent class in a workflow"""
55- event_classes = set ()
56-
57- # Get all steps from the workflow
58- steps = {}
59-
60- # Get steps defined as methods
61- for name , method in inspect .getmembers (workflow , inspect .ismethod ):
62- if hasattr (method , "__step_config" ):
63- steps [name ] = method
64-
65- # Get steps defined as free functions
66- class_steps = getattr (workflow .__class__ , "_step_functions" , {})
67- steps .update (class_steps )
68-
69- # Find all event types that are subclasses of event_base_class
70- for step_func in steps .values ():
71- step_config : Optional [StepConfig ] = getattr (step_func , "__step_config" )
72-
73- if event_base_class is StartEvent :
74- # Look in accepted_events for StartEvent
75- for event_type in step_config .accepted_events :
76- if issubclass (event_type , event_base_class ):
77- event_classes .add (event_type )
78- else :
79- # Look in return_types for StopEvent
80- for event_type in step_config .return_types :
81- if issubclass (event_type , event_base_class ):
82- event_classes .add (event_type )
83-
84- if len (event_classes ) == 1 :
85- return event_classes .pop ()
86- elif len (event_classes ) > 1 :
87- # Return the most specific one (the one with the most fields)
88- return max (event_classes , key = lambda cls : len (get_type_hints (cls )))
89- return event_base_class # Default fallback
90-
91-
9251def generate_schema_from_workflow (workflow : Workflow ) -> Dict [str , Any ]:
9352 """Extract input/output schema from a LlamaIndex workflow"""
9453 schema = {
@@ -97,8 +56,8 @@ def generate_schema_from_workflow(workflow: Workflow) -> Dict[str, Any]:
9756 }
9857
9958 # Find the actual StartEvent and StopEvent classes used in this workflow
100- start_event_class = find_event_types ( workflow , StartEvent )
101- stop_event_class = find_event_types ( workflow , StopEvent )
59+ start_event_class = workflow . _start_event_class
60+ stop_event_class = workflow . _stop_event_class
10261
10362 # Generate input schema from StartEvent using Pydantic's schema method
10463 try :
0 commit comments