Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Script run - take screenshot for the workflow run block (#3437)
Shuchang Zheng6f212ff32720
diff --git a/skyvern/services/script_service.py b/skyvern/services/script_service.pyindex c98b5e13b..71c664bb2 100644--- a/skyvern/services/script_service.py+++ b/skyvern/services/script_service.py@@ -27,6 +27,7 @@ from skyvern.forge.sdk.core import skyvern_contextfrom skyvern.forge.sdk.models import Step, StepStatusfrom skyvern.forge.sdk.schemas.files import FileInfofrom skyvern.forge.sdk.schemas.tasks import Task, TaskOutput, TaskStatus+from skyvern.forge.sdk.schemas.workflow_runs import WorkflowRunBlockfrom skyvern.forge.sdk.workflow.models.block import (CodeBlock,FileParserBlock,@@ -271,6 +272,33 @@ async def execute_script(LOG.info("Script executed successfully", script_id=script_id)+async def _take_workflow_run_block_screenshot(+ workflow_run_id: str,+ organization_id: str,+ workflow_run_block: WorkflowRunBlock,+) -> None:+ """+ This function is a copy of the block screenshot logic from the execute_safe function in the block.py file.+ """+ browser_state = app.BROWSER_MANAGER.get_for_workflow_run(workflow_run_id)+ if not browser_state:+ LOG.warning("No browser state found when creating workflow_run_block", workflow_run_id=workflow_run_id)+ else:+ screenshot = await browser_state.take_fullpage_screenshot(+ use_playwright_fullpage=app.EXPERIMENTATION_PROVIDER.is_feature_enabled_cached(+ "ENABLE_PLAYWRIGHT_FULLPAGE",+ workflow_run_id,+ properties={"organization_id": str(organization_id)},+ )+ )+ if screenshot:+ await app.ARTIFACT_MANAGER.create_workflow_run_block_artifact(+ workflow_run_block=workflow_run_block,+ artifact_type=ArtifactType.SCREENSHOT_LLM,+ data=screenshot,+ )++async def _create_workflow_block_run_and_task(block_type: BlockType,prompt: str | None = None,@@ -343,6 +371,12 @@ async def _create_workflow_block_run_and_task(organization_id=organization_id,)+ await _take_workflow_run_block_screenshot(+ workflow_run_id=workflow_run_id,+ organization_id=organization_id,+ workflow_run_block=workflow_run_block,+ )+context.step_id = step_idcontext.task_id = task_id