@@ -168,57 +168,6 @@ def _render_value(
168
168
return _value (prompt_text )
169
169
170
170
171
- def _generate_text_call (text_value : str , intention : str , parameter_key : str ) -> cst .BaseExpression :
172
- """Create a generate_text function call CST expression."""
173
- return cst .Await (
174
- expression = cst .Call (
175
- func = cst .Attribute (value = cst .Name ("skyvern" ), attr = cst .Name ("generate_text" )),
176
- whitespace_before_args = cst .ParenthesizedWhitespace (
177
- indent = True ,
178
- last_line = cst .SimpleWhitespace (DOUBLE_INDENT ),
179
- ),
180
- args = [
181
- # First positional argument: context.parameters['parameter_key']
182
- cst .Arg (
183
- value = cst .Subscript (
184
- value = cst .Attribute (
185
- value = cst .Name ("context" ),
186
- attr = cst .Name ("parameters" ),
187
- ),
188
- slice = [cst .SubscriptElement (slice = cst .Index (value = _value (parameter_key )))],
189
- ),
190
- whitespace_after_arg = cst .ParenthesizedWhitespace (
191
- indent = True ,
192
- last_line = cst .SimpleWhitespace (DOUBLE_INDENT ),
193
- ),
194
- ),
195
- # intention keyword argument
196
- cst .Arg (
197
- keyword = cst .Name ("intention" ),
198
- value = _value (intention ),
199
- whitespace_after_arg = cst .ParenthesizedWhitespace (
200
- indent = True ,
201
- last_line = cst .SimpleWhitespace (DOUBLE_INDENT ),
202
- ),
203
- ),
204
- # data keyword argument
205
- cst .Arg (
206
- keyword = cst .Name ("data" ),
207
- value = cst .Attribute (
208
- value = cst .Name ("context" ),
209
- attr = cst .Name ("parameters" ),
210
- ),
211
- whitespace_after_arg = cst .ParenthesizedWhitespace (
212
- indent = True ,
213
- last_line = cst .SimpleWhitespace (INDENT ),
214
- ),
215
- comma = cst .Comma (),
216
- ),
217
- ],
218
- )
219
- )
220
-
221
-
222
171
# --------------------------------------------------------------------- #
223
172
# 2. utility builders #
224
173
# --------------------------------------------------------------------- #
@@ -434,7 +383,7 @@ def _action_to_stmt(act: dict[str, Any], task: dict[str, Any], assign_to_output:
434
383
args .append (
435
384
cst .Arg (
436
385
keyword = cst .Name ("prompt" ),
437
- value = _render_value (act ["data_extraction_goal" ]),
386
+ value = _value (act ["data_extraction_goal" ]),
438
387
whitespace_after_arg = cst .ParenthesizedWhitespace (
439
388
indent = True ,
440
389
last_line = cst .SimpleWhitespace (INDENT ),
@@ -459,14 +408,6 @@ def _action_to_stmt(act: dict[str, Any], task: dict[str, Any], assign_to_output:
459
408
cst .Arg (
460
409
keyword = cst .Name ("intention" ),
461
410
value = _value (act .get ("intention" ) or act .get ("reasoning" ) or "" ),
462
- whitespace_after_arg = cst .ParenthesizedWhitespace (
463
- indent = True ,
464
- last_line = cst .SimpleWhitespace (INDENT ),
465
- ),
466
- ),
467
- cst .Arg (
468
- keyword = cst .Name ("data" ),
469
- value = cst .Attribute (value = cst .Name ("context" ), attr = cst .Name ("parameters" )),
470
411
whitespace_after_arg = cst .ParenthesizedWhitespace (indent = True ),
471
412
comma = cst .Comma (),
472
413
),
@@ -646,7 +587,7 @@ def _build_download_statement(
646
587
args = [
647
588
cst .Arg (
648
589
keyword = cst .Name ("prompt" ),
649
- value = _render_value (block .get ("navigation_goal" ) or "" , data_variable_name = data_variable_name ),
590
+ value = _value (block .get ("navigation_goal" ) or "" ),
650
591
whitespace_after_arg = cst .ParenthesizedWhitespace (
651
592
indent = True ,
652
593
last_line = cst .SimpleWhitespace (INDENT ),
@@ -657,7 +598,7 @@ def _build_download_statement(
657
598
args .append (
658
599
cst .Arg (
659
600
keyword = cst .Name ("download_suffix" ),
660
- value = _render_value (block .get ("download_suffix" ), data_variable_name = data_variable_name ),
601
+ value = _value (block .get ("download_suffix" )),
661
602
whitespace_after_arg = cst .ParenthesizedWhitespace (
662
603
indent = True ,
663
604
last_line = cst .SimpleWhitespace (INDENT ),
@@ -694,7 +635,7 @@ def _build_action_statement(
694
635
args = [
695
636
cst .Arg (
696
637
keyword = cst .Name ("prompt" ),
697
- value = _render_value (block .get ("navigation_goal" , "" ), data_variable_name = data_variable_name ),
638
+ value = _value (block .get ("navigation_goal" , "" )),
698
639
whitespace_after_arg = cst .ParenthesizedWhitespace (
699
640
indent = True ,
700
641
last_line = cst .SimpleWhitespace (INDENT ),
@@ -746,7 +687,7 @@ def _build_extract_statement(
746
687
args = [
747
688
cst .Arg (
748
689
keyword = cst .Name ("prompt" ),
749
- value = _render_value (block .get ("data_extraction_goal" , "" ), data_variable_name = data_variable_name ),
690
+ value = _value (block .get ("data_extraction_goal" , "" )),
750
691
whitespace_after_arg = cst .ParenthesizedWhitespace (
751
692
indent = True ,
752
693
last_line = cst .SimpleWhitespace (INDENT ),
@@ -870,7 +811,7 @@ def _build_validate_statement(block: dict[str, Any]) -> cst.SimpleStatementLine:
870
811
args = [
871
812
cst .Arg (
872
813
keyword = cst .Name ("prompt" ),
873
- value = _render_value (block .get ("navigation_goal" , "" )),
814
+ value = _value (block .get ("navigation_goal" , "" )),
874
815
whitespace_after_arg = cst .ParenthesizedWhitespace (
875
816
indent = True ,
876
817
),
@@ -896,6 +837,14 @@ def _build_wait_statement(block: dict[str, Any]) -> cst.SimpleStatementLine:
896
837
cst .Arg (
897
838
keyword = cst .Name ("seconds" ),
898
839
value = _value (block .get ("wait_sec" , 1 )),
840
+ whitespace_after_arg = cst .ParenthesizedWhitespace (
841
+ indent = True ,
842
+ last_line = cst .SimpleWhitespace (INDENT ),
843
+ ),
844
+ ),
845
+ cst .Arg (
846
+ keyword = cst .Name ("label" ),
847
+ value = _value (block .get ("label" )),
899
848
whitespace_after_arg = cst .ParenthesizedWhitespace (
900
849
indent = True ,
901
850
),
@@ -920,7 +869,7 @@ def _build_goto_statement(block: dict[str, Any], data_variable_name: str | None
920
869
args = [
921
870
cst .Arg (
922
871
keyword = cst .Name ("url" ),
923
- value = _render_value (block .get ("url" , "" ), data_variable_name = data_variable_name ),
872
+ value = _value (block .get ("url" , "" )),
924
873
whitespace_after_arg = cst .ParenthesizedWhitespace (
925
874
indent = True ,
926
875
last_line = cst .SimpleWhitespace (INDENT ),
@@ -1212,7 +1161,7 @@ def _build_prompt_statement(block: dict[str, Any]) -> cst.SimpleStatementLine:
1212
1161
args = [
1213
1162
cst .Arg (
1214
1163
keyword = cst .Name ("prompt" ),
1215
- value = _render_value (block .get ("prompt" , "" )),
1164
+ value = _value (block .get ("prompt" , "" )),
1216
1165
whitespace_after_arg = cst .ParenthesizedWhitespace (
1217
1166
indent = True ,
1218
1167
last_line = cst .SimpleWhitespace (INDENT ),
@@ -1275,7 +1224,7 @@ def _build_for_loop_statement(block_title: str, block: dict[str, Any]) -> cst.Fo
1275
1224
1276
1225
An example of a for loop statement:
1277
1226
```
1278
- for current_value in context.parameters["urls"]:
1227
+ async for current_value in skyvern.loop( context.parameters["urls"]) :
1279
1228
await skyvern.goto(
1280
1229
url=current_value,
1281
1230
label="block_4",
@@ -1309,28 +1258,28 @@ def _build_for_loop_statement(block_title: str, block: dict[str, Any]) -> cst.Fo
1309
1258
body_statements = []
1310
1259
1311
1260
# Add loop_data assignment as the first statement
1312
- loop_data_variable_name = "loop_data"
1313
- loop_data_assignment = cst .SimpleStatementLine (
1314
- [
1315
- cst .Assign (
1316
- targets = [cst .AssignTarget (target = cst .Name (loop_data_variable_name ))],
1317
- value = cst .Dict (
1318
- [cst .DictElement (key = cst .SimpleString ('"current_value"' ), value = cst .Name ("current_value" ))]
1319
- ),
1320
- )
1321
- ]
1322
- )
1323
- body_statements .append (loop_data_assignment )
1324
-
1325
1261
for loop_block in loop_blocks :
1326
- stmt = _build_block_statement (loop_block , data_variable_name = loop_data_variable_name )
1262
+ stmt = _build_block_statement (loop_block )
1327
1263
body_statements .append (stmt )
1328
1264
1329
- # Create the for loop
1265
+ # create skyvern.loop(loop_over_parameter_key, label=block_title)
1266
+ loop_call_args = [cst .Arg (keyword = cst .Name ("values" ), value = _value (loop_over_parameter_key ))]
1267
+ if block .get ("complete_if_empty" ):
1268
+ loop_call_args .append (
1269
+ cst .Arg (keyword = cst .Name ("complete_if_empty" ), value = _value (block .get ("complete_if_empty" )))
1270
+ )
1271
+ loop_call_args .append (cst .Arg (keyword = cst .Name ("label" ), value = _value (block_title )))
1272
+ loop_call = cst .Call (
1273
+ func = cst .Attribute (value = cst .Name ("skyvern" ), attr = cst .Name ("loop" )),
1274
+ args = loop_call_args ,
1275
+ )
1276
+
1277
+ # Create the async for loop
1330
1278
for_loop = cst .For (
1331
1279
target = target ,
1332
- iter = _render_value ( loop_over_parameter_key , render_func_name = "render_list" ) ,
1280
+ iter = loop_call ,
1333
1281
body = cst .IndentedBlock (body = body_statements ),
1282
+ asynchronous = cst .Asynchronous (),
1334
1283
whitespace_after_for = cst .SimpleWhitespace (" " ),
1335
1284
whitespace_before_in = cst .SimpleWhitespace (" " ),
1336
1285
whitespace_after_in = cst .SimpleWhitespace (" " ),
@@ -1405,7 +1354,7 @@ def __build_base_task_statement(
1405
1354
args = [
1406
1355
cst .Arg (
1407
1356
keyword = cst .Name ("prompt" ),
1408
- value = _render_value (prompt , data_variable_name = data_variable_name ),
1357
+ value = _value (prompt ),
1409
1358
whitespace_after_arg = cst .ParenthesizedWhitespace (
1410
1359
indent = True ,
1411
1360
last_line = cst .SimpleWhitespace (INDENT ),
@@ -1416,7 +1365,7 @@ def __build_base_task_statement(
1416
1365
args .append (
1417
1366
cst .Arg (
1418
1367
keyword = cst .Name ("url" ),
1419
- value = _render_value (block .get ("url" , "" )),
1368
+ value = _value (block .get ("url" , "" )),
1420
1369
whitespace_after_arg = cst .ParenthesizedWhitespace (
1421
1370
indent = True ,
1422
1371
last_line = cst .SimpleWhitespace (INDENT ),
@@ -1439,7 +1388,7 @@ def __build_base_task_statement(
1439
1388
args .append (
1440
1389
cst .Arg (
1441
1390
keyword = cst .Name ("totp_identifier" ),
1442
- value = _render_value (block .get ("totp_identifier" , "" )),
1391
+ value = _value (block .get ("totp_identifier" , "" )),
1443
1392
whitespace_after_arg = cst .ParenthesizedWhitespace (
1444
1393
indent = True ,
1445
1394
last_line = cst .SimpleWhitespace (INDENT ),
@@ -1450,7 +1399,7 @@ def __build_base_task_statement(
1450
1399
args .append (
1451
1400
cst .Arg (
1452
1401
keyword = cst .Name ("totp_url" ),
1453
- value = _render_value (block .get ("totp_verification_url" , "" )),
1402
+ value = _value (block .get ("totp_verification_url" , "" )),
1454
1403
whitespace_after_arg = cst .ParenthesizedWhitespace (
1455
1404
indent = True ,
1456
1405
last_line = cst .SimpleWhitespace (INDENT ),
0 commit comments