add get_actual_value interface in SkyvernPage and use it differently in script page and browser page for input text action with ai='fallback' mode (#4281)
This commit is contained in:
@@ -30,6 +30,7 @@ from skyvern.webeye.actions.actions import (
|
||||
UploadFileAction,
|
||||
)
|
||||
from skyvern.webeye.actions.handler import (
|
||||
get_actual_value_of_parameter_if_secret,
|
||||
handle_click_action,
|
||||
handle_input_text_action,
|
||||
handle_select_option_action,
|
||||
@@ -280,9 +281,7 @@ class RealSkyvernPageAi(SkyvernPageAi):
|
||||
value = json_response.get("answer", value)
|
||||
|
||||
if context and context.workflow_run_id:
|
||||
transformed_value = await _get_actual_value_of_parameter_if_secret(
|
||||
context.workflow_run_id, str(value)
|
||||
)
|
||||
transformed_value = get_actual_value_of_parameter_if_secret(context.workflow_run_id, str(value))
|
||||
action = InputTextAction(
|
||||
element_id=element_id,
|
||||
text=value,
|
||||
@@ -797,16 +796,3 @@ class RealSkyvernPageAi(SkyvernPageAi):
|
||||
|
||||
except Exception:
|
||||
LOG.exception("ai_act: failed to execute action", action_type=action_type, prompt=prompt)
|
||||
|
||||
|
||||
async def _get_actual_value_of_parameter_if_secret(workflow_run_id: str, parameter: str) -> Any:
|
||||
"""
|
||||
Get the actual value of a parameter if it's a secret. If it's not a secret, return the parameter value as is.
|
||||
|
||||
Just return the parameter value if the task isn't a workflow's task.
|
||||
|
||||
This is only used for InputTextAction, UploadFileAction, and ClickAction (if it has a file_url).
|
||||
"""
|
||||
workflow_run_context = app.WORKFLOW_CONTEXT_MANAGER.get_workflow_run_context(workflow_run_id)
|
||||
secret_value = workflow_run_context.get_original_secret_value_or_none(parameter)
|
||||
return secret_value if secret_value is not None else parameter
|
||||
|
||||
@@ -25,7 +25,12 @@ from skyvern.webeye.actions.actions import (
|
||||
SelectOption,
|
||||
SolveCaptchaAction,
|
||||
)
|
||||
from skyvern.webeye.actions.handler import ActionHandler, handle_complete_action
|
||||
from skyvern.webeye.actions.handler import (
|
||||
ActionHandler,
|
||||
generate_totp_value,
|
||||
get_actual_value_of_parameter_if_secret,
|
||||
handle_complete_action,
|
||||
)
|
||||
from skyvern.webeye.browser_state import BrowserState
|
||||
from skyvern.webeye.scraper.scraped_page import ScrapedPage
|
||||
|
||||
@@ -393,6 +398,17 @@ class ScriptSkyvernPage(SkyvernPage):
|
||||
# If screenshot creation fails, don't block execution
|
||||
pass
|
||||
|
||||
async def get_actual_value(self, value: str) -> str:
|
||||
"""Input text into an element identified by ``selector``."""
|
||||
context = skyvern_context.ensure_context()
|
||||
if context and context.workflow_run_id:
|
||||
# support TOTP secret and internal it to TOTP code
|
||||
is_totp_value = value == "BW_TOTP" or value == "OP_TOTP" or value == "AZ_TOTP"
|
||||
if is_totp_value:
|
||||
value = generate_totp_value(context.workflow_run_id, value)
|
||||
value = get_actual_value_of_parameter_if_secret(context.workflow_run_id, value)
|
||||
return value
|
||||
|
||||
async def goto(self, url: str, **kwargs: Any) -> None:
|
||||
url = render_template(url)
|
||||
url = prepend_scheme_and_validate_url(url)
|
||||
|
||||
@@ -96,6 +96,9 @@ class SkyvernPage(Page):
|
||||
timeout = kwargs.pop("timeout", settings.BROWSER_LOADING_TIMEOUT_MS)
|
||||
await self.page.goto(url, timeout=timeout, **kwargs)
|
||||
|
||||
async def get_actual_value(self, value: str) -> str:
|
||||
return value
|
||||
|
||||
######### Public Interfaces #########
|
||||
|
||||
@overload
|
||||
@@ -387,6 +390,7 @@ class SkyvernPage(Page):
|
||||
error_to_raise = None
|
||||
if selector:
|
||||
try:
|
||||
value = await self.get_actual_value(value)
|
||||
locator = self.page.locator(selector)
|
||||
await handler_utils.input_sequentially(locator, value, timeout=timeout)
|
||||
return value
|
||||
|
||||
Reference in New Issue
Block a user