From ea906e2f7c38a89884f354d68bed7b45e866a838 Mon Sep 17 00:00:00 2001 From: Shuchang Zheng Date: Thu, 20 Mar 2025 11:03:39 -0700 Subject: [PATCH] task v2 support jinja style (#1978) --- skyvern/forge/sdk/workflow/models/block.py | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/skyvern/forge/sdk/workflow/models/block.py b/skyvern/forge/sdk/workflow/models/block.py index b6a123cc..3b5819c7 100644 --- a/skyvern/forge/sdk/workflow/models/block.py +++ b/skyvern/forge/sdk/workflow/models/block.py @@ -2229,6 +2229,22 @@ class TaskV2Block(Block): ) -> list[PARAMETER_TYPE]: return [] + def format_potential_template_parameters(self, workflow_run_context: WorkflowRunContext) -> None: + self.prompt = self.format_block_parameter_template_from_workflow_run_context(self.prompt, workflow_run_context) + if self.url: + self.url = self.format_block_parameter_template_from_workflow_run_context(self.url, workflow_run_context) + + if self.totp_identifier: + self.totp_identifier = self.format_block_parameter_template_from_workflow_run_context( + self.totp_identifier, workflow_run_context + ) + + if self.totp_verification_url: + self.totp_verification_url = self.format_block_parameter_template_from_workflow_run_context( + self.totp_verification_url, workflow_run_context + ) + self.totp_verification_url = prepend_scheme_and_validate_url(self.totp_verification_url) + async def execute( self, workflow_run_id: str, @@ -2240,6 +2256,19 @@ class TaskV2Block(Block): from skyvern.forge.sdk.services import task_v2_service from skyvern.forge.sdk.workflow.models.workflow import WorkflowRunStatus + workflow_run_context = self.get_workflow_run_context(workflow_run_id) + try: + self.format_potential_template_parameters(workflow_run_context) + except Exception as e: + return await self.build_block_result( + success=False, + failure_reason=f"Failed to format jinja template: {str(e)}", + output_parameter_value=None, + status=BlockStatus.failed, + workflow_run_block_id=workflow_run_block_id, + organization_id=organization_id, + ) + if not self.url: browser_state = app.BROWSER_MANAGER.get_for_workflow_run(workflow_run_id) if browser_state: