77from typing import Any , Callable , Dict , List , Union , get_args , get_origin
88
99from pydantic import BaseModel
10- import requests
1110
12- from application_sdk .constants import AUTOMATION_ENGINE_API_URL
1311from application_sdk .observability .logger_adaptor import get_logger
1412
1513logger = get_logger (__name__ )
1614
1715
1816# Global registry to collect decorated activities
19- ACTIVITY_REGISTRY : List [dict [str , Any ]] = []
17+ ACTIVITY_SPECS : List [dict [str , Any ]] = []
2018
2119
2220def _type_to_json_schema (annotation : Any ) -> Dict [str , Any ]:
@@ -117,7 +115,7 @@ def decorator(func: Callable[..., Any]) -> Callable[..., Any]:
117115 output_schema : dict [str , Any ] = _generate_output_schema (func )
118116
119117 logger .info (f"Collected automation activity: { name } " )
120- ACTIVITY_REGISTRY .append (
118+ ACTIVITY_SPECS .append (
121119 {
122120 "name" : name ,
123121 "description" : description ,
@@ -129,78 +127,3 @@ def decorator(func: Callable[..., Any]) -> Callable[..., Any]:
129127 return func
130128
131129 return decorator
132-
133-
134- def flush_activity_registrations (
135- app_name : str ,
136- ) -> None :
137- """Flush all collected registrations by calling the activities create API via HTTP."""
138- if not ACTIVITY_REGISTRY :
139- logger .info ("No activities to register" )
140- return
141-
142- if not AUTOMATION_ENGINE_API_URL :
143- logger .warning (
144- "Automation engine API URL not configured. Skipping activity registration."
145- )
146- return
147-
148- # Perform health check first
149- try :
150- health_check_url : str = f"{ AUTOMATION_ENGINE_API_URL } /api/health"
151- health_response : requests .Response = requests .get (health_check_url , timeout = 5.0 )
152- health_response .raise_for_status ()
153- logger .info ("Automation engine health check passed" )
154- except Exception as e :
155- logger .warning (
156- f"Automation engine health check failed: { e } . "
157- "Skipping activity registration. "
158- "Check if the automation engine is deployed and accessible."
159- )
160- return
161-
162- logger .info (
163- f"Registering { len (ACTIVITY_REGISTRY )} activities with automation engine"
164- )
165-
166- # Generate app qualified name
167- app_qualified_name : str = f"default/apps/{ app_name } "
168-
169- # Build tools payload without function objects (not JSON serializable)
170- tools = [
171- {
172- "name" : item ["name" ],
173- "description" : item ["description" ],
174- "input_schema" : item ["input_schema" ],
175- "output_schema" : item ["output_schema" ],
176- }
177- for item in ACTIVITY_REGISTRY
178- ]
179-
180- payload = {
181- "app_qualified_name" : app_qualified_name ,
182- "app_name" : app_name ,
183- "tools" : tools ,
184- }
185-
186- try :
187- response : requests .Response = requests .post (
188- f"{ AUTOMATION_ENGINE_API_URL } /api/tools" ,
189- json = payload ,
190- timeout = 30.0 ,
191- )
192- response .raise_for_status ()
193- result = response .json ()
194-
195- if result .get ("status" ) == "success" :
196- logger .info (
197- f"Successfully registered { len (tools )} activities with automation engine"
198- )
199- else :
200- logger .warning (
201- f"Failed to register activities with automation engine: { result .get ('message' )} "
202- )
203- except Exception as e :
204- raise Exception (
205- f"Failed to register activities with automation engine: { e } "
206- ) from e
0 commit comments