handler_utils.input_sequentially (#2722)

This commit is contained in:
Shuchang Zheng
2025-06-14 17:01:53 -07:00
committed by GitHub
parent 90e6038cd6
commit 53ce34459a
4 changed files with 26 additions and 18 deletions

View File

@@ -1,15 +1,18 @@
from typing import Any
import structlog
from playwright.async_api import Locator
from skyvern.forge.sdk.api.files import download_file
from skyvern.config import settings
from skyvern.constants import TEXT_INPUT_DELAY, TEXT_PRESS_MAX_LENGTH
from skyvern.forge.sdk.api.files import download_file as download_file_api
LOG = structlog.get_logger()
async def download_file_safe(file_url: str, action: dict[str, Any] | None = None) -> str | list[str]:
async def download_file(file_url: str, action: dict[str, Any] | None = None) -> str | list[str]:
try:
return await download_file(file_url)
return await download_file_api(file_url)
except Exception:
LOG.exception(
"Failed to download file, continuing without it",
@@ -17,3 +20,14 @@ async def download_file_safe(file_url: str, action: dict[str, Any] | None = None
file_url=file_url,
)
return []
async def input_sequentially(locator: Locator, text: str, timeout: float = settings.BROWSER_ACTION_TIMEOUT_MS) -> None:
length = len(text)
if length > TEXT_PRESS_MAX_LENGTH:
# if the text is longer than TEXT_PRESS_MAX_LENGTH characters, we will locator.fill in initial texts until the last TEXT_PRESS_MAX_LENGTH characters
# and then type the last TEXT_PRESS_MAX_LENGTH characters with locator.press_sequentially
await locator.fill(text, timeout=timeout)
text = text[length - TEXT_PRESS_MAX_LENGTH :]
await locator.press_sequentially(text, delay=TEXT_INPUT_DELAY, timeout=timeout)