diff --git a/.changeset/neat-kiwis-relate.md b/.changeset/neat-kiwis-relate.md new file mode 100644 index 0000000000..11bb1e2163 --- /dev/null +++ b/.changeset/neat-kiwis-relate.md @@ -0,0 +1,5 @@ +--- +"@workflow/swc-plugin": patch +--- + +Fix step functions nested multiple levels deep in an object diff --git a/packages/swc-plugin-workflow/spec.md b/packages/swc-plugin-workflow/spec.md index 45884fbd1f..d28db0aa14 100644 --- a/packages/swc-plugin-workflow/spec.md +++ b/packages/swc-plugin-workflow/spec.md @@ -184,6 +184,101 @@ example.workflowId = "workflow//./input//example"; registerStepFunction("step//./input//example/innerStep", example$innerStep); ``` +### Steps in Nested Object Properties + +Step functions can be defined inside deeply nested object properties, including function call arguments. The plugin recursively processes nested objects to find step functions, generating compound paths for the step IDs. + +Input: +```javascript +import { agent } from "experimental-agent"; + +export const vade = agent({ + tools: { + VercelRequest: { + execute: async (input, ctx) => { + "use step"; + return 1 + 1; + }, + }, + }, +}); +``` + +Output (Step Mode): +```javascript +import { registerStepFunction } from "workflow/internal/private"; +import { agent } from "experimental-agent"; +/**__internal_workflows{"steps":{"input.js":{"vade/tools/VercelRequest/execute":{"stepId":"step//input.js//vade/tools/VercelRequest/execute"}}}}*/; +var vade$tools$VercelRequest$execute = async function(input, ctx) { + return 1 + 1; +}; +export const vade = agent({ + tools: { + VercelRequest: { + execute: vade$tools$VercelRequest$execute + } + } +}); +registerStepFunction("step//input.js//vade/tools/VercelRequest/execute", vade$tools$VercelRequest$execute); +``` + +Note: Step functions are hoisted as regular function expressions (not arrow functions) to preserve `this` binding when called with `.call()` or `.apply()`. This applies even when the original step function was defined as an arrow function. + +Output (Workflow Mode): +```javascript +import { agent } from "experimental-agent"; +/**__internal_workflows{"steps":{"input.js":{"vade/tools/VercelRequest/execute":{"stepId":"step//input.js//vade/tools/VercelRequest/execute"}}}}*/; +export const vade = agent({ + tools: { + VercelRequest: { + execute: globalThis[Symbol.for("WORKFLOW_USE_STEP")]("step//input.js//vade/tools/VercelRequest/execute") + } + } +}); +``` + +Note: The step ID includes the full path through nested objects (`vade/tools/VercelRequest/execute`), while the hoisted variable name uses `$` as the separator (`vade$tools$VercelRequest$execute`) to create a valid JavaScript identifier. + +#### Shorthand Method Syntax + +Shorthand method syntax (non-arrow functions) is also supported in nested object properties: + +Input: +```javascript +import { agent } from "experimental-agent"; + +export const vade = agent({ + tools: { + VercelRequest: { + async execute(input, { experimental_context }) { + "use step"; + return 1 + 1; + }, + }, + }, +}); +``` + +Output (Step Mode): +```javascript +import { registerStepFunction } from "workflow/internal/private"; +import { agent } from "experimental-agent"; +/**__internal_workflows{"steps":{"input.js":{"vade/tools/VercelRequest/execute":{"stepId":"step//input.js//vade/tools/VercelRequest/execute"}}}}*/; +var vade$tools$VercelRequest$execute = async function(input, { experimental_context }) { + return 1 + 1; +}; +export const vade = agent({ + tools: { + VercelRequest: { + execute: vade$tools$VercelRequest$execute + } + } +}); +registerStepFunction("step//input.js//vade/tools/VercelRequest/execute", vade$tools$VercelRequest$execute); +``` + +Note: Shorthand methods are hoisted as regular function expressions (not arrow functions) to preserve `this` binding when called with `.call()` or `.apply()`. Closure variables are handled the same way as other step functions. + ### Closure Variables When nested steps capture closure variables, they are extracted using `__private_getClosureVars()`: @@ -701,6 +796,7 @@ The plugin supports various function declaration styles: - `var name = async () => { "use step"; }` - Arrow function with var - `const name = async function() { "use step"; }` - Function expression - `{ async method() { "use step"; } }` - Object method +- `{ nested: { execute: async () => { "use step"; } } }` - Nested object property - `static async method() { "use step"; }` - Static class method - `async method() { "use step"; }` - Instance class method (requires custom serialization) diff --git a/packages/swc-plugin-workflow/transform/src/lib.rs b/packages/swc-plugin-workflow/transform/src/lib.rs index e8e4254990..b63f10233f 100644 --- a/packages/swc-plugin-workflow/transform/src/lib.rs +++ b/packages/swc-plugin-workflow/transform/src/lib.rs @@ -332,9 +332,9 @@ pub struct StepTransform { // Track all declared identifiers in module scope to avoid collisions declared_identifiers: HashSet, // Track object property step functions for hoisting in step mode - // (parent_var_name, prop_name, arrow_expr, span, parent_workflow_name) + // (parent_var_name, prop_name, fn_expr, span, parent_workflow_name, was_arrow) object_property_step_functions: - Vec<(String, String, ArrowExpr, swc_core::common::Span, String)>, + Vec<(String, String, FnExpr, swc_core::common::Span, String, bool)>, // Track nested step functions inside workflow functions for hoisting in step mode // (fn_name, fn_expr, span, closure_vars, was_arrow, parent_workflow_name) nested_step_functions: Vec<( @@ -1524,18 +1524,57 @@ impl StepTransform { // Remove the directive first self.remove_use_step_directive_arrow(&mut arrow_expr.body); + // Convert arrow to function expression for hoisting + // (preserves `this` binding when called with .call()/.apply()) + let fn_from_arrow = FnExpr { + ident: None, + function: Box::new(Function { + params: arrow_expr + .params + .iter() + .map(|pat| Param { + span: DUMMY_SP, + decorators: vec![], + pat: pat.clone(), + }) + .collect(), + decorators: vec![], + span: arrow_expr.span, + ctxt: SyntaxContext::empty(), + body: Some(match &*arrow_expr.body { + BlockStmtOrExpr::BlockStmt(block) => { + block.clone() + } + BlockStmtOrExpr::Expr(expr) => BlockStmt { + span: DUMMY_SP, + ctxt: SyntaxContext::empty(), + stmts: vec![Stmt::Return(ReturnStmt { + span: DUMMY_SP, + arg: Some(expr.clone()), + })], + }, + }), + is_generator: arrow_expr.is_generator, + is_async: arrow_expr.is_async, + type_params: None, + return_type: arrow_expr.return_type.clone(), + }), + }; + + let span = arrow_expr.span; + // Track this as an object property step function (after removing directive) self.object_property_step_functions.push(( parent_var_name.to_string(), prop_key.clone(), - arrow_expr.clone(), - arrow_expr.span, + fn_from_arrow, + span, self.current_workflow_function_name .clone() .unwrap_or_default(), + true, // was_arrow )); - let span = arrow_expr.span; let _ = arrow_expr; // Drop the mutable reference self.apply_object_property_transformation( @@ -1556,47 +1595,19 @@ impl StepTransform { // Remove the directive first self.remove_use_step_directive(&mut fn_expr.function.body); - // Convert to arrow expression for hoisting (as arrow functions are simpler to work with) - let arrow_params: Vec = fn_expr - .function - .params - .iter() - .map(|param| param.pat.clone()) - .collect(); - - let arrow_from_fn = ArrowExpr { - span: fn_expr.function.span, - ctxt: SyntaxContext::empty(), - is_async: fn_expr.function.is_async, - is_generator: fn_expr.function.is_generator, - params: arrow_params, - body: Box::new(BlockStmtOrExpr::BlockStmt( - fn_expr - .function - .body - .as_ref() - .cloned() - .unwrap_or_else(|| BlockStmt { - span: DUMMY_SP, - ctxt: SyntaxContext::empty(), - stmts: vec![], - }), - )), - type_params: None, - return_type: fn_expr.function.return_type.clone(), - }; - let span = fn_expr.function.span; // Track this as an object property step function (after removing directive) + // Keep as FnExpr to preserve `this` binding self.object_property_step_functions.push(( parent_var_name.to_string(), prop_key.clone(), - arrow_from_fn, + fn_expr.clone(), span, self.current_workflow_function_name .clone() .unwrap_or_default(), + false, // was_arrow )); let _ = fn_expr; // Drop the mutable reference @@ -1611,6 +1622,32 @@ impl StepTransform { } _ => {} } + } else { + // Not a direct step function - check for nested objects or call expressions + match &mut *kv_prop.value { + Expr::Object(nested_obj) => { + // Recursively process nested objects with compound path + let compound_path = format!("{}/{}", parent_var_name, prop_key); + self.process_object_properties_for_step_functions( + nested_obj, + &compound_path, + ); + } + Expr::Call(call_expr) => { + // Check arguments for object literals containing step functions + for arg in &mut call_expr.args { + if let Expr::Object(nested_obj) = &mut *arg.expr { + let compound_path = + format!("{}/{}", parent_var_name, prop_key); + self.process_object_properties_for_step_functions( + nested_obj, + &compound_path, + ); + } + } + } + _ => {} + } } } Prop::Method(method_prop) => { @@ -1631,31 +1668,11 @@ impl StepTransform { // Remove the directive first self.remove_use_step_directive(&mut method_prop.function.body); - // Convert method to arrow expression for hoisting - let arrow_params: Vec = method_prop - .function - .params - .iter() - .map(|param| param.pat.clone()) - .collect(); - - let arrow_from_method = ArrowExpr { - span: method_prop.function.span, - ctxt: SyntaxContext::empty(), - is_async: method_prop.function.is_async, - is_generator: method_prop.function.is_generator, - params: arrow_params, - body: Box::new(BlockStmtOrExpr::BlockStmt( - method_prop.function.body.as_ref().cloned().unwrap_or_else( - || BlockStmt { - span: DUMMY_SP, - ctxt: SyntaxContext::empty(), - stmts: vec![], - }, - ), - )), - type_params: None, - return_type: method_prop.function.return_type.clone(), + // Convert method to function expression for hoisting + // (preserves `this` binding when called with .call()/.apply()) + let fn_from_method = FnExpr { + ident: None, + function: method_prop.function.clone(), }; let span = method_prop.function.span; @@ -1664,26 +1681,29 @@ impl StepTransform { self.object_property_step_functions.push(( parent_var_name.to_string(), prop_key.clone(), - arrow_from_method, + fn_from_method, span, self.current_workflow_function_name .clone() .unwrap_or_default(), + false, // was_arrow (methods are not arrows) )); // Now handle the transformation based on mode match self.mode { TransformMode::Step => { // In step mode, replace method with key-value property referencing the hoisted variable + // Replace slashes with $ in parent_var_name to create valid JS identifier + let safe_parent_name = parent_var_name.replace('/', "$"); let hoist_var_name = if let Some(ref workflow_name) = self.current_workflow_function_name { format!( "{}${}${}", - workflow_name, parent_var_name, prop_key + workflow_name, safe_parent_name, prop_key ) } else { - format!("{}${}", parent_var_name, prop_key) + format!("{}${}", safe_parent_name, prop_key) }; let step_id = self.create_object_property_id( parent_var_name, @@ -1755,11 +1775,13 @@ impl StepTransform { match self.mode { TransformMode::Step => { // In step mode, replace with reference to hoisted variable + // Replace slashes with $ in parent_var_name to create valid JS identifier + let safe_parent_name = parent_var_name.replace('/', "$"); let hoist_var_name = if let Some(ref workflow_name) = self.current_workflow_function_name { - format!("{}${}${}", workflow_name, parent_var_name, prop_key) + format!("{}${}${}", workflow_name, safe_parent_name, prop_key) } else { - format!("{}${}", parent_var_name, prop_key) + format!("{}${}", safe_parent_name, prop_key) }; *kv_prop.value = Expr::Ident(Ident::new( hoist_var_name.into(), @@ -3758,11 +3780,13 @@ impl VisitMut for StepTransform { .object_property_step_functions .iter() .map( - |(parent_var, prop_name, arrow_expr, _span, workflow_name)| { + |(parent_var, prop_name, fn_expr, _span, workflow_name, _was_arrow)| { + // Replace slashes with $ in parent_var to create valid JS identifier + let safe_parent_var = parent_var.replace('/', "$"); let hoist_var_name = if !workflow_name.is_empty() { - format!("{}${}${}", workflow_name, parent_var, prop_name) + format!("{}${}${}", workflow_name, safe_parent_var, prop_name) } else { - format!("{}${}", parent_var, prop_name) + format!("{}${}", safe_parent_var, prop_name) }; let wf_name = if workflow_name.is_empty() { None @@ -3772,12 +3796,7 @@ impl VisitMut for StepTransform { let step_id = self.create_object_property_id( parent_var, prop_name, false, wf_name, ); - ( - hoist_var_name, - arrow_expr.clone(), - step_id, - parent_var.clone(), - ) + (hoist_var_name, fn_expr.clone(), step_id, parent_var.clone()) }, ) .collect(); @@ -3785,8 +3804,9 @@ impl VisitMut for StepTransform { // Now drain and process self.object_property_step_functions.drain(..); - for (hoist_var_name, arrow_expr, step_id, _parent_var) in hoisting_info { - // Create a const declaration for the hoisted function + for (hoist_var_name, fn_expr, step_id, _parent_var) in hoisting_info { + // Create a var declaration for the hoisted function + // Using function expression (not arrow) to preserve `this` binding let hoisted_decl = ModuleItem::Stmt(Stmt::Decl(Decl::Var(Box::new(VarDecl { span: DUMMY_SP, @@ -3802,7 +3822,7 @@ impl VisitMut for StepTransform { ), type_ann: None, }), - init: Some(Box::new(Expr::Arrow(arrow_expr))), + init: Some(Box::new(Expr::Fn(fn_expr))), definite: false, }], declare: false, diff --git a/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step-shorthand-method/input.js b/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step-shorthand-method/input.js new file mode 100644 index 0000000000..d292bcce46 --- /dev/null +++ b/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step-shorthand-method/input.js @@ -0,0 +1,12 @@ +import { agent } from "experimental-agent"; + +export const vade = agent({ + tools: { + VercelRequest: { + async execute(input, { experimental_context }) { + "use step"; + return 1+1 + }, + }, + }, +}); diff --git a/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step-shorthand-method/output-client.js b/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step-shorthand-method/output-client.js new file mode 100644 index 0000000000..b83d6440cf --- /dev/null +++ b/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step-shorthand-method/output-client.js @@ -0,0 +1,10 @@ +import { agent } from "experimental-agent"; +export const vade = agent({ + tools: { + VercelRequest: { + async execute (input, { experimental_context }) { + return 1 + 1; + } + } + } +}); diff --git a/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step-shorthand-method/output-step.js b/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step-shorthand-method/output-step.js new file mode 100644 index 0000000000..984cf682f5 --- /dev/null +++ b/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step-shorthand-method/output-step.js @@ -0,0 +1,14 @@ +import { registerStepFunction } from "workflow/internal/private"; +import { agent } from "experimental-agent"; +/**__internal_workflows{"steps":{"input.js":{"vade/tools/VercelRequest/execute":{"stepId":"step//./input//vade/tools/VercelRequest/execute"}}}}*/; +var vade$tools$VercelRequest$execute = async function(input, { experimental_context }) { + return 1 + 1; +}; +export const vade = agent({ + tools: { + VercelRequest: { + execute: vade$tools$VercelRequest$execute + } + } +}); +registerStepFunction("step//./input//vade/tools/VercelRequest/execute", vade$tools$VercelRequest$execute); diff --git a/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step-shorthand-method/output-workflow.js b/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step-shorthand-method/output-workflow.js new file mode 100644 index 0000000000..ad61fe0469 --- /dev/null +++ b/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step-shorthand-method/output-workflow.js @@ -0,0 +1,9 @@ +import { agent } from "experimental-agent"; +/**__internal_workflows{"steps":{"input.js":{"vade/tools/VercelRequest/execute":{"stepId":"step//./input//vade/tools/VercelRequest/execute"}}}}*/; +export const vade = agent({ + tools: { + VercelRequest: { + execute: globalThis[Symbol.for("WORKFLOW_USE_STEP")]("step//./input//vade/tools/VercelRequest/execute") + } + } +}); diff --git a/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step/input.js b/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step/input.js new file mode 100644 index 0000000000..4773087c10 --- /dev/null +++ b/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step/input.js @@ -0,0 +1,12 @@ +import { agent } from "experimental-agent"; + +export const vade = agent({ + tools: { + VercelRequest: { + execute: async (input, { experimental_context }) => { + "use step"; + return 1+1 + }, + }, + }, +}); diff --git a/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step/output-client.js b/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step/output-client.js new file mode 100644 index 0000000000..df7da5b12a --- /dev/null +++ b/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step/output-client.js @@ -0,0 +1,10 @@ +import { agent } from "experimental-agent"; +export const vade = agent({ + tools: { + VercelRequest: { + execute: async (input, { experimental_context })=>{ + return 1 + 1; + } + } + } +}); diff --git a/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step/output-step.js b/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step/output-step.js new file mode 100644 index 0000000000..984cf682f5 --- /dev/null +++ b/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step/output-step.js @@ -0,0 +1,14 @@ +import { registerStepFunction } from "workflow/internal/private"; +import { agent } from "experimental-agent"; +/**__internal_workflows{"steps":{"input.js":{"vade/tools/VercelRequest/execute":{"stepId":"step//./input//vade/tools/VercelRequest/execute"}}}}*/; +var vade$tools$VercelRequest$execute = async function(input, { experimental_context }) { + return 1 + 1; +}; +export const vade = agent({ + tools: { + VercelRequest: { + execute: vade$tools$VercelRequest$execute + } + } +}); +registerStepFunction("step//./input//vade/tools/VercelRequest/execute", vade$tools$VercelRequest$execute); diff --git a/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step/output-workflow.js b/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step/output-workflow.js new file mode 100644 index 0000000000..ad61fe0469 --- /dev/null +++ b/packages/swc-plugin-workflow/transform/tests/fixture/agent-with-tool-step/output-workflow.js @@ -0,0 +1,9 @@ +import { agent } from "experimental-agent"; +/**__internal_workflows{"steps":{"input.js":{"vade/tools/VercelRequest/execute":{"stepId":"step//./input//vade/tools/VercelRequest/execute"}}}}*/; +export const vade = agent({ + tools: { + VercelRequest: { + execute: globalThis[Symbol.for("WORKFLOW_USE_STEP")]("step//./input//vade/tools/VercelRequest/execute") + } + } +}); diff --git a/packages/swc-plugin-workflow/transform/tests/fixture/deeply-nested-step/input.js b/packages/swc-plugin-workflow/transform/tests/fixture/deeply-nested-step/input.js new file mode 100644 index 0000000000..2e74281f84 --- /dev/null +++ b/packages/swc-plugin-workflow/transform/tests/fixture/deeply-nested-step/input.js @@ -0,0 +1,15 @@ +import { createConfig } from "some-library"; + +// Test deeply nested step functions (4 levels deep) +export const config = createConfig({ + level1: { + level2: { + level3: { + myStep: async (input) => { + "use step"; + return input * 2; + }, + }, + }, + }, +}); diff --git a/packages/swc-plugin-workflow/transform/tests/fixture/deeply-nested-step/output-client.js b/packages/swc-plugin-workflow/transform/tests/fixture/deeply-nested-step/output-client.js new file mode 100644 index 0000000000..8b7c2fa9c6 --- /dev/null +++ b/packages/swc-plugin-workflow/transform/tests/fixture/deeply-nested-step/output-client.js @@ -0,0 +1,13 @@ +import { createConfig } from "some-library"; +// Test deeply nested step functions (4 levels deep) +export const config = createConfig({ + level1: { + level2: { + level3: { + myStep: async (input)=>{ + return input * 2; + } + } + } + } +}); diff --git a/packages/swc-plugin-workflow/transform/tests/fixture/deeply-nested-step/output-step.js b/packages/swc-plugin-workflow/transform/tests/fixture/deeply-nested-step/output-step.js new file mode 100644 index 0000000000..5548edba9a --- /dev/null +++ b/packages/swc-plugin-workflow/transform/tests/fixture/deeply-nested-step/output-step.js @@ -0,0 +1,17 @@ +import { registerStepFunction } from "workflow/internal/private"; +import { createConfig } from "some-library"; +/**__internal_workflows{"steps":{"input.js":{"config/level1/level2/level3/myStep":{"stepId":"step//./input//config/level1/level2/level3/myStep"}}}}*/; +var config$level1$level2$level3$myStep = async function(input) { + return input * 2; +}; +// Test deeply nested step functions (4 levels deep) +export const config = createConfig({ + level1: { + level2: { + level3: { + myStep: config$level1$level2$level3$myStep + } + } + } +}); +registerStepFunction("step//./input//config/level1/level2/level3/myStep", config$level1$level2$level3$myStep); diff --git a/packages/swc-plugin-workflow/transform/tests/fixture/deeply-nested-step/output-workflow.js b/packages/swc-plugin-workflow/transform/tests/fixture/deeply-nested-step/output-workflow.js new file mode 100644 index 0000000000..d469f361a1 --- /dev/null +++ b/packages/swc-plugin-workflow/transform/tests/fixture/deeply-nested-step/output-workflow.js @@ -0,0 +1,12 @@ +import { createConfig } from "some-library"; +/**__internal_workflows{"steps":{"input.js":{"config/level1/level2/level3/myStep":{"stepId":"step//./input//config/level1/level2/level3/myStep"}}}}*/; +// Test deeply nested step functions (4 levels deep) +export const config = createConfig({ + level1: { + level2: { + level3: { + myStep: globalThis[Symbol.for("WORKFLOW_USE_STEP")]("step//./input//config/level1/level2/level3/myStep") + } + } + } +}); diff --git a/packages/swc-plugin-workflow/transform/tests/fixture/factory-with-step-method/output-step.js b/packages/swc-plugin-workflow/transform/tests/fixture/factory-with-step-method/output-step.js index ebb2b34053..e1993bc7b5 100644 --- a/packages/swc-plugin-workflow/transform/tests/fixture/factory-with-step-method/output-step.js +++ b/packages/swc-plugin-workflow/transform/tests/fixture/factory-with-step-method/output-step.js @@ -1,7 +1,7 @@ import { registerStepFunction } from "workflow/internal/private"; import fs from 'fs/promises'; /**__internal_workflows{"steps":{"input.js":{"myFactory/myStep":{"stepId":"step//./input//myFactory/myStep"}}}}*/; -var myFactory$myStep = async ()=>{ +var myFactory$myStep = async function() { await fs.mkdir('test'); }; const myFactory = ()=>({ diff --git a/packages/swc-plugin-workflow/transform/tests/fixture/nested-step-in-workflow/output-step.js b/packages/swc-plugin-workflow/transform/tests/fixture/nested-step-in-workflow/output-step.js index 0ad8c2f82d..89feb33f1d 100644 --- a/packages/swc-plugin-workflow/transform/tests/fixture/nested-step-in-workflow/output-step.js +++ b/packages/swc-plugin-workflow/transform/tests/fixture/nested-step-in-workflow/output-step.js @@ -7,7 +7,7 @@ async function example$step(a, b) { var example$arrowStep = async (x, y)=>x * y; var example$letArrowStep = async (x, y)=>x - y; var example$varArrowStep = async (x, y)=>x / y; -var example$helpers$objectStep = async (x, y)=>{ +var example$helpers$objectStep = async function(x, y) { return x + y + 10; }; export async function example(a, b) { diff --git a/packages/swc-plugin-workflow/transform/tests/fixture/object-property-step/output-step.js b/packages/swc-plugin-workflow/transform/tests/fixture/object-property-step/output-step.js index 8d0904048e..33346d36c9 100644 --- a/packages/swc-plugin-workflow/transform/tests/fixture/object-property-step/output-step.js +++ b/packages/swc-plugin-workflow/transform/tests/fixture/object-property-step/output-step.js @@ -2,18 +2,18 @@ import { registerStepFunction } from "workflow/internal/private"; import * as z from 'zod'; import { tool } from 'ai'; /**__internal_workflows{"steps":{"input.js":{"timeTool/execute":{"stepId":"step//./input//timeTool/execute"},"weatherTool/execute":{"stepId":"step//./input//weatherTool/execute"},"weatherTool2/execute":{"stepId":"step//./input//weatherTool2/execute"}}}}*/; -var weatherTool$execute = async ({ location })=>{ +var weatherTool$execute = async function({ location }) { return { location, temperature: 72 + Math.floor(Math.random() * 21) - 10 }; }; -var timeTool$execute = async ()=>{ +var timeTool$execute = async function timeToolImpl() { return { time: new Date().toISOString() }; }; -var weatherTool2$execute = async ({ location })=>{ +var weatherTool2$execute = async function({ location }) { return { location, temperature: 72 + Math.floor(Math.random() * 21) - 10