@@ -60,6 +60,24 @@ def scan_script_dirs(scripts_dir_path):
6060 return []
6161
6262
63+ def scan_versions (agent_dir_path ):
64+ """Scan for version directories in generated_scripts/versions/"""
65+ try :
66+ if not agent_dir_path :
67+ return ["latest" ]
68+ agent_dir = Path (agent_dir_path )
69+ versions_dir = agent_dir / "generated_scripts" / "versions"
70+ if not versions_dir .exists ():
71+ return ["latest" ]
72+ versions = ["latest" ] + [d .name for d in sorted (versions_dir .iterdir (), reverse = True ) if d .is_dir () and not d .name .startswith ("_" )]
73+ return versions
74+ except Exception as e :
75+ print (f"Error scanning versions: { e } " )
76+ import traceback
77+ traceback .print_exc ()
78+ return ["latest" ]
79+
80+
6381
6482
6583def websocket_worker ():
@@ -99,6 +117,7 @@ async def _run():
99117
100118_init_agents = scan_agent_scripts (str (DEFAULT_AGENT_DIR ))
101119_init_tests = scan_script_dirs (str (DEFAULT_TESTS_DIR ))
120+ _init_versions = scan_versions (str (DEFAULT_AGENT_DIR ))
102121
103122with gr .Blocks () as demo :
104123 with gr .Row ():
@@ -137,6 +156,11 @@ async def _run():
137156 with gr .Row ():
138157 output_logs = gr .Textbox (label = "Logs" , lines = 20 )
139158 with gr .Column ():
159+ version_dropdown = gr .Dropdown (
160+ label = "libE scripts" ,
161+ choices = _init_versions ,
162+ value = "latest"
163+ )
140164 script_file_dropdown = gr .Dropdown (label = "Generated Scripts" , choices = [], value = None )
141165 output_script = gr .Code (label = "Script Content" , language = "python" , lines = 10 )
142166 output_plot = gr .Image (label = "Plot" , visible = False )
@@ -215,23 +239,23 @@ def apply_settings(agent_dir, scripts_dir):
215239
216240 agent_choices = scan_agent_scripts (new_agent_dir )
217241 scripts_choices = scan_script_dirs (new_scripts_dir )
242+ version_choices = scan_versions (new_agent_dir )
218243
219244 return (
220245 new_agent_dir ,
221246 new_scripts_dir ,
222247 gr .update (choices = agent_choices , value = agent_choices [0 ] if agent_choices else None ),
223248 gr .update (choices = scripts_choices , value = None ),
249+ gr .update (choices = version_choices , value = "latest" ),
224250 False , # settings_visible - close modal
225251 gr .update (visible = False ) # settings_modal
226252 )
227253
228254 def send_and_clear (agent_script , scripts_dir , agent_dir_state_val , scripts_dir_state_val ):
229255 if agent_script and scripts_dir :
230- # Use configured directories
231256 agent_dir = Path (agent_dir_state_val ) if agent_dir_state_val else DEFAULT_AGENT_DIR
232257 scripts_base_dir = Path (scripts_dir_state_val ) if scripts_dir_state_val else DEFAULT_TESTS_DIR
233258
234- # Convert directory name to full path
235259 if not Path (scripts_dir ).is_absolute ():
236260 scripts_dir = str (scripts_base_dir / scripts_dir )
237261
@@ -241,12 +265,30 @@ def send_and_clear(agent_script, scripts_dir, agent_dir_state_val, scripts_dir_s
241265 except Empty :
242266 break
243267 msg = json .dumps ({
244- "agent_script" : agent_script , # Just the filename
268+ "agent_script" : agent_script ,
245269 "scripts_dir" : scripts_dir ,
246- "agent_dir" : str (agent_dir ) # Send agent dir so backend knows where to run from
270+ "agent_dir" : str (agent_dir )
247271 })
248272 message_queue .put (msg )
249273 return ""
274+
275+ def load_version_scripts (version , agent_dir_state_val ):
276+ """Load scripts directly from a version directory"""
277+ agent_dir = Path (agent_dir_state_val ) if agent_dir_state_val else DEFAULT_AGENT_DIR
278+ if version and version != "latest" :
279+ scripts_dir = agent_dir / "generated_scripts" / "versions" / version
280+ else :
281+ scripts_dir = agent_dir / "generated_scripts"
282+
283+ scripts = {}
284+ if scripts_dir .exists ():
285+ for f in sorted (scripts_dir .glob ("*.py" )):
286+ scripts [f .name ] = f .read_text ()
287+
288+ names = list (scripts .keys ())
289+ selected = names [0 ] if names else None
290+ content = scripts .get (selected , "" ) if selected else ""
291+ return scripts , gr .update (choices = names , value = selected ), content
250292
251293 def reset_ui ():
252294 while not output_queue .empty ():
@@ -292,9 +334,14 @@ def close_settings():
292334 apply_settings_btn .click (
293335 apply_settings ,
294336 inputs = [agent_dir_input , scripts_dir_input ],
295- outputs = [agent_dir_state , scripts_dir_state , agent_dropdown , scripts_dropdown , settings_visible , settings_modal ]
337+ outputs = [agent_dir_state , scripts_dir_state , agent_dropdown , scripts_dropdown , version_dropdown , settings_visible , settings_modal ]
296338 )
297339
340+ def refresh_versions (agent_dir_state_val ):
341+ """Refresh version list"""
342+ versions = scan_versions (agent_dir_state_val )
343+ return gr .update (choices = versions )
344+
298345 run_btn .click (
299346 send_and_clear ,
300347 inputs = [agent_dropdown , scripts_dropdown , agent_dir_state , scripts_dir_state ],
@@ -303,6 +350,10 @@ def close_settings():
303350 process_messages ,
304351 inputs = [scripts_dict ],
305352 outputs = [output_logs , scripts_dict , script_file_dropdown , output_script ]
353+ ).then (
354+ refresh_versions ,
355+ inputs = [agent_dir_state ],
356+ outputs = [version_dropdown ]
306357 )
307358
308359 reset_btn .click (
@@ -315,6 +366,12 @@ def close_settings():
315366 inputs = [script_file_dropdown , scripts_dict ],
316367 outputs = output_script
317368 )
369+
370+ version_dropdown .change (
371+ load_version_scripts ,
372+ inputs = [version_dropdown , agent_dir_state ],
373+ outputs = [scripts_dict , script_file_dropdown , output_script ]
374+ )
318375
319376
320377def start_uvicorn_server ():
0 commit comments