Skip to content

Add support for step functions defined as object properties#342

Merged
TooTallNate merged 2 commits into
mainfrom
11-13-add_support_for_step_functions_defined_as_object_properties
Nov 15, 2025
Merged

Add support for step functions defined as object properties#342
TooTallNate merged 2 commits into
mainfrom
11-13-add_support_for_step_functions_defined_as_object_properties

Conversation

@TooTallNate
Copy link
Copy Markdown
Member

@TooTallNate TooTallNate commented Nov 14, 2025

Added support for step functions defined as object properties in the SWC plugin.

What changed?

This PR extends the SWC plugin to support step functions defined as object properties. It now handles three different patterns:

  1. Arrow functions in object properties: tool({ execute: async () => { "use step"; ... } })
  2. Function expressions in object properties: tool({ execute: async function() { "use step"; ... } })
  3. Method syntax in objects: tool({ async execute() { "use step"; ... } })

The implementation:

  • Detects "use step" directives in object property functions
  • Hoists these functions in step mode
  • Converts them to step initializer calls in workflow mode
  • Properly tracks and registers these functions with appropriate identifiers
  • Updates metadata generation to include object property step functions

How to test?

Test with various object property function patterns:

// Arrow function in object property
const weatherTool = tool({
  execute: async ({ location }) => {
    "use step";
    return { location, temperature: 72 };
  }
});

// Function expression in object property
const timeTool = tool({
  execute: async function() {
    "use step";
    return { time: new Date().toISOString() };
  }
});

// Method syntax
const dateTool = tool({
  async execute() {
    "use step";
    return { date: new Date().toDateString() };
  }
});

Why make this change?

This change enables a common pattern in JavaScript where functions are defined as object properties, particularly in AI SDK tool definitions.

Previously, the SWC plugin only supported top-level function declarations and expressions with the "use step" directive. This enhancement provides a more natural developer experience by allowing step functions to be defined directly within their object context.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Nov 14, 2025

🦋 Changeset detected

Latest commit: 48ddccb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@workflow/swc-plugin Patch
@workflow/builders Patch
@workflow/cli Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/sveltekit Patch
workflow Patch
@workflow/world-testing Patch
@workflow/nuxt Patch
@workflow/ai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Nov 14, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
example-nextjs-workflow-turbopack Ready Ready Preview Comment Nov 15, 2025 7:19am
example-nextjs-workflow-webpack Ready Ready Preview Comment Nov 15, 2025 7:19am
example-workflow Ready Ready Preview Comment Nov 15, 2025 7:19am
workbench-hono-workflow Ready Ready Preview Comment Nov 15, 2025 7:19am
workbench-nitro-workflow Ready Ready Preview Comment Nov 15, 2025 7:19am
workbench-nuxt-workflow Ready Ready Preview Comment Nov 15, 2025 7:19am
workbench-sveltekit-workflow Ready Ready Preview Comment Nov 15, 2025 7:19am
workbench-vite-workflow Ready Ready Preview Comment Nov 15, 2025 7:19am
workflow-docs Ready Ready Preview Comment Nov 15, 2025 7:19am

@TooTallNate TooTallNate marked this pull request as ready for review November 14, 2025 01:44
@TooTallNate TooTallNate force-pushed the 11-13-add_support_for_step_functions_defined_as_object_properties branch from a2ddb2b to 577f570 Compare November 15, 2025 07:16
@graphite-app graphite-app Bot changed the base branch from graphite-base/342 to main November 15, 2025 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants