@@ -126,6 +126,32 @@ def _cached_find_elements_hwnd(
126126 )
127127
128128
129+ def _slim_element (el : dict ) -> dict :
130+ """Strip an element dict to the fields the LLM needs."""
131+ slim = {"oculos_id" : el .get ("oculos_id" )}
132+ if el .get ("element_type" ):
133+ slim ["element_type" ] = el ["element_type" ]
134+ for key in ("name" , "title" , "label" ):
135+ val = el .get (key )
136+ if val :
137+ slim [key ] = val
138+ for key in ("value" , "text_content" ):
139+ val = el .get (key )
140+ if val :
141+ slim [key ] = val
142+ for key in ("checked" , "toggle_state" , "is_selected" ):
143+ val = el .get (key )
144+ if val is not None :
145+ slim [key ] = val
146+ if el .get ("is_enabled" ) is False :
147+ slim ["is_enabled" ] = False
148+ return slim
149+
150+
151+ def _slim_elements (elements : list [dict ]) -> list [dict ]:
152+ return [_slim_element (el ) for el in elements ]
153+
154+
129155def list_active_windows () -> Dict [str , Any ]:
130156 """
131157 Retrieves a list of all currently visible desktop windows.
@@ -318,7 +344,7 @@ def find_ui_elements(
318344 eid = el .get ("oculos_id" )
319345 if eid :
320346 _element_meta [eid ] = {"pid" : pid , "query" : query , "element_type" : element_type }
321- return {"status" : "success" , "elements" : elements }
347+ return {"status" : "success" , "elements" : _slim_elements ( elements ) }
322348 except Exception as e :
323349 return {"status" : "error" , "message" : f"Failed to find elements: { str (e )} " }
324350
@@ -391,7 +417,7 @@ def find_ui_elements_hwnd(
391417 "message" : "No elements found matching the criteria." ,
392418 "elements" : [],
393419 }
394- return {"status" : "success" , "elements" : elements }
420+ return {"status" : "success" , "elements" : _slim_elements ( elements ) }
395421 except Exception as e :
396422 return {
397423 "status" : "error" ,
0 commit comments