Miquel Farré commited on
Commit ·
28d5a31
1
Parent(s): 0185d4a
changing behavior after failure
Browse files218 unmodified lines2192202212222232242252262272282296 unmodified lines236237238239240241243 unmodified lines485486487488489490491492493494495496497498499500501502503504505506507508509510218 unmodified linesconsole.log("Error detected!");showBSOD('Error');clearInterval(resultsInterval);break;}}}, 1000);};// Start monitoring for timeouts immediatelycheckSandboxTimeout();6 unmodified linesif (e.target.tagName === 'BUTTON') {if (e.target.innerText === "Let's go!") {resetBSOD();}setTimeout(monitorForErrors, 3000);}243 unmodified lines)# # 3. Then set back to interactive mode# task_result.then(# fn=set_interactive_mode,# inputs=None, # No inputs needed here# outputs=html_output# )# 3. Define a function to check the result and only return to interactive mode if successfuldef check_result_and_set_mode(result, request: gr.Request):# Only switch back to interactive mode if the agent completed successfullyif result.startswith("Task completed:"):return update_html(True, request)else:# Keep the view-only mode (with BSOD displayed by JS)return None# 3. Then conditionally set back to interactive mode based on successtask_result.then(fn=check_result_and_set_mode,inputs=[results_output], # Pass the result text to checkoutputs=html_output)# Load the sandbox on app start with initial HTML218 unmodified lines2192202212222232242252262272282292302312322332342352362372382392402412422432442452466 unmodified lines253254255256257258259243 unmodified lines503504505506507508509510511512513514218 unmodified linesconsole.log("Error detected!");showBSOD('Error');clearInterval(resultsInterval);window.agentFailed = true;break;}}}, 1000);};// Add a new function to conditionally go to interactive modewindow.shouldSwitchToInteractive = function() {const resultsElements = document.querySelectorAll('textarea, .output-text');for (let elem of resultsElements) {const content = elem.value || elem.innerText || '';// If we see an error message or our flag is set, don't switch to interactiveif (content.includes('Error running agent') || window.agentFailed === true) {console.log("Error detected, not switching to interactive mode");return false;}}console.log("No errors detected, switching to interactive mode");return true;};// Start monitoring for timeouts immediatelycheckSandboxTimeout();6 unmodified linesif (e.target.tagName === 'BUTTON') {if (e.target.innerText === "Let's go!") {resetBSOD();window.agentFailed = false;}setTimeout(monitorForErrors, 3000);}243 unmodified lines)# # 3. Then set back to interactive modetask_result.then(fn=set_interactive_mode,inputs=None, # No inputs needed hereoutputs=html_output,_js="() => window.shouldSwitchToInteractive() ? [] : null")# Load the sandbox on app start with initial HTML
app.py+23-19