script gen fix file upload and file download blocks (#3417)
This commit is contained in:
@@ -151,8 +151,10 @@ def _value(value: Any) -> cst.BaseExpression:
|
|||||||
return cst.SimpleString(repr(str(value)))
|
return cst.SimpleString(repr(str(value)))
|
||||||
|
|
||||||
|
|
||||||
def _render_value(prompt_text: str) -> cst.BaseExpression:
|
def _render_value(prompt_text: str | None = None) -> cst.BaseExpression:
|
||||||
"""Create a prompt value with template rendering logic if needed."""
|
"""Create a prompt value with template rendering logic if needed."""
|
||||||
|
if not prompt_text:
|
||||||
|
return cst.SimpleString("")
|
||||||
if "{{" in prompt_text and "}}" in prompt_text:
|
if "{{" in prompt_text and "}}" in prompt_text:
|
||||||
# Generate code for: render_template(prompt_text)
|
# Generate code for: render_template(prompt_text)
|
||||||
return cst.Call(
|
return cst.Call(
|
||||||
@@ -556,7 +558,7 @@ def _build_download_statement(block_title: str, block: dict[str, Any]) -> cst.Si
|
|||||||
args = [
|
args = [
|
||||||
cst.Arg(
|
cst.Arg(
|
||||||
keyword=cst.Name("prompt"),
|
keyword=cst.Name("prompt"),
|
||||||
value=_render_value(block.get("navigation_goal", "")),
|
value=_render_value(block.get("navigation_goal") or ""),
|
||||||
whitespace_after_arg=cst.ParenthesizedWhitespace(
|
whitespace_after_arg=cst.ParenthesizedWhitespace(
|
||||||
indent=True,
|
indent=True,
|
||||||
last_line=cst.SimpleWhitespace(INDENT),
|
last_line=cst.SimpleWhitespace(INDENT),
|
||||||
@@ -570,14 +572,19 @@ def _build_download_statement(block_title: str, block: dict[str, Any]) -> cst.Si
|
|||||||
last_line=cst.SimpleWhitespace(INDENT),
|
last_line=cst.SimpleWhitespace(INDENT),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
cst.Arg(
|
]
|
||||||
keyword=cst.Name("download_suffix"),
|
if block.get("download_suffix"):
|
||||||
value=_render_value(block.get("download_suffix", "")),
|
args.append(
|
||||||
whitespace_after_arg=cst.ParenthesizedWhitespace(
|
cst.Arg(
|
||||||
indent=True,
|
keyword=cst.Name("download_suffix"),
|
||||||
last_line=cst.SimpleWhitespace(INDENT),
|
value=_render_value(block.get("download_suffix")),
|
||||||
),
|
whitespace_after_arg=cst.ParenthesizedWhitespace(
|
||||||
),
|
indent=True,
|
||||||
|
last_line=cst.SimpleWhitespace(INDENT),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
args.append(
|
||||||
cst.Arg(
|
cst.Arg(
|
||||||
keyword=cst.Name("cache_key"),
|
keyword=cst.Name("cache_key"),
|
||||||
value=_value(block_title),
|
value=_value(block_title),
|
||||||
@@ -585,8 +592,8 @@ def _build_download_statement(block_title: str, block: dict[str, Any]) -> cst.Si
|
|||||||
indent=True,
|
indent=True,
|
||||||
),
|
),
|
||||||
comma=cst.Comma(),
|
comma=cst.Comma(),
|
||||||
),
|
)
|
||||||
]
|
)
|
||||||
|
|
||||||
call = cst.Call(
|
call = cst.Call(
|
||||||
func=cst.Attribute(value=cst.Name("skyvern"), attr=cst.Name("download")),
|
func=cst.Attribute(value=cst.Name("skyvern"), attr=cst.Name("download")),
|
||||||
@@ -982,7 +989,7 @@ def _build_file_upload_statement(block: dict[str, Any]) -> cst.SimpleStatementLi
|
|||||||
),
|
),
|
||||||
cst.Arg(
|
cst.Arg(
|
||||||
keyword=cst.Name("storage_type"),
|
keyword=cst.Name("storage_type"),
|
||||||
value=_value(block.get("storage_type", FileStorageType.S3)),
|
value=_value(str(block.get("storage_type", FileStorageType.S3))),
|
||||||
whitespace_after_arg=cst.ParenthesizedWhitespace(
|
whitespace_after_arg=cst.ParenthesizedWhitespace(
|
||||||
indent=True,
|
indent=True,
|
||||||
last_line=cst.SimpleWhitespace(INDENT),
|
last_line=cst.SimpleWhitespace(INDENT),
|
||||||
@@ -1426,42 +1433,6 @@ def _build_run_fn(blocks: list[dict[str, Any]], wf_req: dict[str, Any]) -> Funct
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
whitespace_after_param=cst.ParenthesizedWhitespace(
|
|
||||||
indent=True,
|
|
||||||
last_line=cst.SimpleWhitespace(INDENT),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Param(
|
|
||||||
name=cst.Name("title"),
|
|
||||||
annotation=cst.Annotation(cst.Name("str")),
|
|
||||||
default=_value(wf_req.get("title", "")),
|
|
||||||
whitespace_after_param=cst.ParenthesizedWhitespace(
|
|
||||||
indent=True,
|
|
||||||
last_line=cst.SimpleWhitespace(INDENT),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Param(
|
|
||||||
name=cst.Name("webhook_url"),
|
|
||||||
annotation=cst.Annotation(cst.parse_expression("str | None")),
|
|
||||||
default=_value(wf_req.get("webhook_url")),
|
|
||||||
whitespace_after_param=cst.ParenthesizedWhitespace(
|
|
||||||
indent=True,
|
|
||||||
last_line=cst.SimpleWhitespace(INDENT),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Param(
|
|
||||||
name=cst.Name("totp_url"),
|
|
||||||
annotation=cst.Annotation(cst.parse_expression("str | None")),
|
|
||||||
default=_value(wf_req.get("totp_url")),
|
|
||||||
whitespace_after_param=cst.ParenthesizedWhitespace(
|
|
||||||
indent=True,
|
|
||||||
last_line=cst.SimpleWhitespace(INDENT),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Param(
|
|
||||||
name=cst.Name("totp_identifier"),
|
|
||||||
annotation=cst.Annotation(cst.parse_expression("str | None")),
|
|
||||||
default=_value(wf_req.get("totp_identifier")),
|
|
||||||
whitespace_after_param=cst.ParenthesizedWhitespace(),
|
whitespace_after_param=cst.ParenthesizedWhitespace(),
|
||||||
comma=cst.Comma(),
|
comma=cst.Comma(),
|
||||||
),
|
),
|
||||||
@@ -1637,9 +1608,6 @@ async def generate_workflow_script(
|
|||||||
module_body = [
|
module_body = [
|
||||||
*start_block_body,
|
*start_block_body,
|
||||||
*block_fns,
|
*block_fns,
|
||||||
cst.EmptyLine(),
|
|
||||||
cst.EmptyLine(),
|
|
||||||
cst.parse_statement("if __name__ == '__main__':\n asyncio.run(run_workflow())"),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
module = cst.Module(body=module_body)
|
module = cst.Module(body=module_body)
|
||||||
|
|||||||
Reference in New Issue
Block a user