Skip to content

Commit

Permalink
UrlBlock should be a task block with no navigation_goal and no data_e…
Browse files Browse the repository at this point in the history
…xtraction goal
  • Loading branch information
wintonzheng committed Jan 2, 2025
1 parent cb50d97 commit ca18f3e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 77 deletions.
78 changes: 2 additions & 76 deletions skyvern/forge/sdk/workflow/models/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from skyvern.exceptions import (
ContextParameterValueNotFound,
DisabledBlockExecutionError,
FailedToNavigateToUrl,
MissingBrowserState,
MissingBrowserStatePage,
SkyvernException,
Expand Down Expand Up @@ -1801,85 +1800,12 @@ class LoginBlock(BaseTaskBlock):

class FileDownloadBlock(BaseTaskBlock):
block_type: Literal[BlockType.FILE_DOWNLOAD] = BlockType.FILE_DOWNLOAD


class UrlBlock(Block):

class UrlBlock(BaseTaskBlock):
block_type: Literal[BlockType.GOTO_URL] = BlockType.GOTO_URL
url: str

async def execute(
self, workflow_run_id: str, workflow_run_block_id: str, organization_id: str | None = None, **kwargs: dict
) -> BlockResult:
workflow_run = await app.DATABASE.get_workflow_run(workflow_run_id=workflow_run_id, organization_id=organization_id)
if not workflow_run:
return await self.build_block_result(
success=False,
failure_reason="Workflow run not found",
output_parameter_value=None,
status=BlockStatus.failed,
workflow_run_block_id=workflow_run_block_id,
organization_id=organization_id,
)
# create a new browser state
browser_state: BrowserState | None = None
# the first task block will create the browser state and do the navigation
try:
browser_state = await app.BROWSER_MANAGER.get_or_create_for_workflow_run(
workflow_run=workflow_run, url=self.url,
)
except Exception as e:
LOG.exception(
"Failed to get browser state for url block",
workflow_run_id=workflow_run_id,
)
return await self.build_block_result(
success=False,
failure_reason=f"Skyvern browser has failed to navigate to url {self.url}",
output_parameter_value=None,
status=BlockStatus.failed,
workflow_run_block_id=workflow_run_block_id,
organization_id=organization_id,
)

# navigate to the url
working_page = await browser_state.get_working_page()
if not working_page:
LOG.error("Failed to get working page for url block", url=self.url, workflow_run_id=workflow_run_id)
return await self.build_block_result(
success=False,
failure_reason=f"Skyvern browser has failed to navigate to url {self.url}. The page might have been closed.",
output_parameter_value=None,
status=BlockStatus.failed,
workflow_run_block_id=workflow_run_block_id,
organization_id=organization_id,
)

try:
await browser_state.navigate_to_url(page=working_page, url=self.url)
except Exception as e:
LOG.exception(
"Failed to navigate to url",
url=self.url,
workflow_run_id=workflow_run_id,
)
return await self.build_block_result(
success=False,
failure_reason=f"Skyvern browser has failed to navigate to url {self.url}",
output_parameter_value=None,
status=BlockStatus.failed,
workflow_run_block_id=workflow_run_block_id,
organization_id=organization_id,
)

return await self.build_block_result(
success=True,
failure_reason=None,
output_parameter_value=None,
status=BlockStatus.completed,
workflow_run_block_id=workflow_run_block_id,
organization_id=organization_id,
)


BlockSubclasses = Union[
ForLoopBlock,
Expand Down
2 changes: 1 addition & 1 deletion skyvern/forge/sdk/workflow/models/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ class FileDownloadBlockYAML(BlockYAML):
totp_verification_url: str | None = None
totp_identifier: str | None = None
cache_actions: bool = False


class UrlBlockYAML(BlockYAML):
block_type: Literal[BlockType.GOTO_URL] = BlockType.GOTO_URL # type: ignore
Expand Down

0 comments on commit ca18f3e

Please sign in to comment.