Skip to content

Commit 29194d2

Browse files
author
katiue
committed
fix bug
1 parent 0657be2 commit 29194d2

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

webui.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ async def run_browser_agent(
131131
if new_videos - existing_videos:
132132
latest_video = list(new_videos - existing_videos)[0] # Get the first new video
133133

134-
return final_result, errors, model_actions, model_thoughts, latest_video, trace_file
134+
return final_result, errors, model_actions, model_thoughts, latest_video
135135

136136
async def run_org_agent(
137137
llm,
@@ -204,7 +204,7 @@ async def run_org_agent(
204204
import traceback
205205
traceback.print_exc()
206206
errors = str(e) + "\n" + traceback.format_exc()
207-
return '', errors, '', ''
207+
return '', errors, '', '', None, None
208208
finally:
209209
# Handle cleanup based on persistence configuration
210210
if not keep_browser_open:
@@ -288,17 +288,16 @@ async def run_custom_agent(
288288
errors = history.errors()
289289
model_actions = history.model_actions()
290290
model_thoughts = history.model_thoughts()
291+
291292
recorded_files = get_latest_files(save_recording_path)
292293
trace_file = get_latest_files(save_trace_path)
293294

295+
return final_result, errors, model_actions, model_thoughts, trace_file.get('.webm'), recorded_files.get('.zip')
294296
except Exception as e:
295297
import traceback
296298
traceback.print_exc()
297299
errors = str(e) + "\n" + traceback.format_exc()
298-
model_actions = ""
299-
model_thoughts = ""
300-
recorded_files = {}
301-
trace_file = {}
300+
return '', errors, '', '', None, None
302301
finally:
303302
# Handle cleanup based on persistence configuration
304303
if not keep_browser_open:
@@ -309,17 +308,16 @@ async def run_custom_agent(
309308
if _global_browser:
310309
await _global_browser.close()
311310
_global_browser = None
312-
return final_result, errors, model_actions, model_thoughts, trace_file.get('.webm'), recorded_files.get('.zip')
313311

314312
async def run_with_stream(
315313
agent_type,
316314
llm_provider,
317-
keep_browser_open,
318315
llm_model_name,
319316
llm_temperature,
320317
llm_base_url,
321318
llm_api_key,
322319
use_own_browser,
320+
keep_browser_open,
323321
headless,
324322
disable_security,
325323
window_w,
@@ -335,7 +333,7 @@ async def run_with_stream(
335333
tool_call_in_content
336334
):
337335
"""Wrapper to run the agent and handle streaming."""
338-
global _global_browser, _global_browser_context, _global_playwright
336+
global _global_browser, _global_browser_context
339337

340338
try:
341339
# Initialize the global browser if it doesn't exist
@@ -367,11 +365,11 @@ async def run_with_stream(
367365
agent_type=agent_type,
368366
llm_provider=llm_provider,
369367
llm_model_name=llm_model_name,
370-
keep_browser_open=keep_browser_open,
371368
llm_temperature=llm_temperature,
372369
llm_base_url=llm_base_url,
373370
llm_api_key=llm_api_key,
374371
use_own_browser=use_own_browser,
372+
keep_browser_open=keep_browser_open,
375373
headless=headless,
376374
disable_security=disable_security,
377375
window_w=window_w,
@@ -385,8 +383,7 @@ async def run_with_stream(
385383
use_vision=use_vision,
386384
max_actions_per_step=max_actions_per_step,
387385
tool_call_in_content=tool_call_in_content
388-
)
389-
)
386+
))
390387

391388
# Initialize values for streaming
392389
html_content = "<div style='width:80vw; height:90vh'>Using browser...</div>"
@@ -396,10 +393,7 @@ async def run_with_stream(
396393
# Periodically update the stream while the agent task is running
397394
while not agent_task.done():
398395
try:
399-
if isinstance(_global_browser_context, CustomBrowserContext):
400-
html_content = await capture_screenshot(_global_browser_context)
401-
else:
402-
html_content = "<div class='error' style='width:80vw; height:90vh'>Invalid browser context type</div>"
396+
html_content = await capture_screenshot(_global_browser_context)
403397
except Exception as e:
404398
html_content = f"<div class='error' style='width:80vw; height:90vh'>Screenshot error: {str(e)}</div>"
405399

0 commit comments

Comments
 (0)