Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
API + SDK support - get workflow run (#2324)
Shuchang Zheng8f37625f517b
diff --git a/skyvern/forge/sdk/routes/agent_protocol.py b/skyvern/forge/sdk/routes/agent_protocol.pyindex e49a9f48f..401e4dda1 100644--- a/skyvern/forge/sdk/routes/agent_protocol.py+++ b/skyvern/forge/sdk/routes/agent_protocol.py@@ -1683,6 +1683,7 @@ async def run_workflow(run_request=workflow_run_request,downloaded_files=None,recording_url=None,+ app_url=f"{settings.SKYVERN_APP_URL.rstrip('/')}/{workflow_run.workflow_permanent_id}/{workflow_run.workflow_run_id}",)diff --git a/skyvern/forge/sdk/workflow/service.py b/skyvern/forge/sdk/workflow/service.pyindex 19c15c710..0c6783a58 100644--- a/skyvern/forge/sdk/workflow/service.py+++ b/skyvern/forge/sdk/workflow/service.py@@ -969,7 +969,7 @@ class WorkflowService:async def build_workflow_run_status_response_by_workflow_id(self,workflow_run_id: str,- organization_id: str,+ organization_id: str | None = None,include_cost: bool = False,) -> WorkflowRunResponseBase:workflow_run = await self.get_workflow_run(workflow_run_id=workflow_run_id, organization_id=organization_id)@@ -988,7 +988,7 @@ class WorkflowService:self,workflow_permanent_id: str,workflow_run_id: str,- organization_id: str,+ organization_id: str | None = None,include_cost: bool = False,) -> WorkflowRunResponseBase:workflow = await self.get_workflow_by_permanent_id(workflow_permanent_id)diff --git a/skyvern/services/run_service.py b/skyvern/services/run_service.pyindex 4c29043bb..e88a7768c 100644--- a/skyvern/services/run_service.py+++ b/skyvern/services/run_service.py@@ -6,7 +6,7 @@ from skyvern.forge import appfrom skyvern.forge.sdk.schemas.tasks import TaskStatusfrom skyvern.forge.sdk.workflow.models.workflow import WorkflowRunStatusfrom skyvern.schemas.runs import RunEngine, RunResponse, RunType, TaskRunRequest, TaskRunResponse-from skyvern.services import task_v2_service+from skyvern.services import task_v2_service, workflow_serviceasync def get_run_response(run_id: str, organization_id: str | None = None) -> RunResponse | None:@@ -79,16 +79,7 @@ async def get_run_response(run_id: str, organization_id: str | None = None) -> R),)elif run.task_run_type == RunType.workflow_run:- raise NotImplementedError("Workflow run response not implemented")- # return WorkflowRunResponse(- # run_id=run.run_id,- # run_type=run.task_run_type,- # status=run.status,- # output=run.output,- # parameters=None,- # created_at=run.created_at,- # modified_at=run.modified_at,- # )+ return await workflow_service.get_workflow_run_response(run.run_id, organization_id=organization_id)raise ValueError(f"Invalid task run type: {run.task_run_type}")diff --git a/skyvern/services/workflow_service.py b/skyvern/services/workflow_service.pyindex 2f4ca9a0a..01ea782bc 100644--- a/skyvern/services/workflow_service.py+++ b/skyvern/services/workflow_service.py@@ -1,12 +1,13 @@import structlogfrom fastapi import BackgroundTasks, Request+from skyvern.config import settingsfrom skyvern.forge import appfrom skyvern.forge.sdk.executor.factory import AsyncExecutorFactoryfrom skyvern.forge.sdk.schemas.organizations import Organizationfrom skyvern.forge.sdk.workflow.exceptions import InvalidTemplateWorkflowPermanentIdfrom skyvern.forge.sdk.workflow.models.workflow import WorkflowRequestBody, WorkflowRun-from skyvern.schemas.runs import RunType+from skyvern.schemas.runs import RunStatus, RunType, WorkflowRunRequest, WorkflowRunResponseLOG = structlog.get_logger(__name__)@@ -60,3 +61,40 @@ async def run_workflow(api_key=api_key,)return workflow_run+++async def get_workflow_run_response(+ workflow_run_id: str, organization_id: str | None = None+) -> WorkflowRunResponse | None:+ workflow_run = await app.DATABASE.get_workflow_run(workflow_run_id, organization_id=organization_id)+ if not workflow_run:+ return None+ workflow_run_resp = await app.WORKFLOW_SERVICE.build_workflow_run_status_response_by_workflow_id(+ workflow_run_id=workflow_run.workflow_run_id,+ organization_id=organization_id,+ )+ app_url = (+ f"{settings.SKYVERN_APP_URL.rstrip('/')}/{workflow_run.workflow_permanent_id}/{workflow_run.workflow_run_id}"+ )+ return WorkflowRunResponse(+ run_id=workflow_run_id,+ run_type=RunType.workflow_run,+ status=RunStatus(workflow_run.status),+ output=workflow_run_resp.outputs,+ downloaded_files=workflow_run_resp.downloaded_files,+ recording_url=workflow_run_resp.recording_url,+ failure_reason=workflow_run_resp.failure_reason,+ app_url=app_url,+ created_at=workflow_run.created_at,+ modified_at=workflow_run.modified_at,+ run_request=WorkflowRunRequest(+ workflow_id=workflow_run.workflow_id,+ title=workflow_run.title,+ parameters=workflow_run_resp.parameters,+ proxy_location=workflow_run.proxy_location,+ webhook_url=workflow_run.webhook_callback_url,+ totp_url=workflow_run.totp_verification_url,+ totp_identifier=workflow_run.totp_identifier,+ # TODO: add browser session id+ ),+ )