* fix: externlize bun from step bundle
* changeset
* fix: add bun to node module esbuild plugin
* feat: add bun to node module esbuild plugin match
* feat: add hint for using bun inside workflow in ts lsp
* fix: add support for bun:* modules
Added support for transforming step functions that are returned from factory functions.
### What changed?
Enhanced the SWC plugin to detect and transform step functions that are defined within object literals returned by factory functions. The transformation now properly identifies arrow functions with object literal bodies and processes their step functions accordingly.
Added test fixtures to verify the functionality:
- Created test cases for a factory function that returns an object with a step method
- Added corresponding output files for client, step, and workflow modes
### How to test?
1. Create a factory function that returns an object with methods marked as steps:
```javascript
const myFactory = () => ({
myStep: async () => {
'use step';
await fs.mkdir('test');
},
});
```
2. Verify that the step function is properly transformed and registered when used in a workflow.
### Why make this change?
This enhancement supports a common pattern where developers create factory functions that return objects containing step methods. Without this change, step functions defined in this pattern weren't being properly transformed, which limited the flexibility of the workflow system.
### What changed?
- Enhanced the SWC plugin to detect and collect closure variables from nested step functions
- Modified the workflow runtime to pass closure variables to step functions during execution
- Updated the serialization/deserialization logic to handle the new closure variable format
- Added a mechanism to access closure variables within step functions
- Added tests to verify closure variable functionality in nested step functions
- Closure variables are stored on the step function execution's `AsyncLocalStorage` context
### Example
```typescript
export async function myWorkflow(baseValue: number) {
'use workflow';
const multiplier = 3;
const prefix = 'Result: ';
const calculate = async () => {
'use step';
const result = baseValue * multiplier;
return `${prefix}${result}`;
};
return await calculate();
}
```
### Why make this change?
Previously, nested step functions couldn't access variables from their parent workflow scope, limiting their usefulness and requiring workarounds like passing all needed values as parameters. This change enables a more natural programming model where step functions can access variables from their enclosing scope, making workflow code more intuitive and reducing the need for explicit parameter passing.
* Disable Turborepo cache for CI related tasks
Disable cache for all tasks except "build"
* Checkout swc-plugin test fixture files with Unix newlines for Windows (#331)
* postgres: use non-deprecated drizzle signatures
Signed-off-by: Gal Schlezinger <gal@spitfire.co.il>
* postgres: store metadata in the hook
Signed-off-by: Gal Schlezinger <gal@spitfire.co.il>
* core: do not rely on module cache for world config. instead, use a global and a symbol.
this makes sure that streamers can use in-memory event emitters and that it won't be compiled away into the different flow.js and step.js files.
this was figured out when i was adding a hooks tests to world-testing.
Signed-off-by: Gal Schlezinger <gal@spitfire.co.il>
* add postgres world to all workbench packages
we try to run them with the postgres world but it's not installed
Signed-off-by: Gal Schlezinger <gal@spitfire.co.il>
* Replace jsonb with cbor because zero byte does not work in jsonb :(
Signed-off-by: Gal Schlezinger <gal@spitfire.co.il>
* fix error handling: attempts start at 0 now, and not 1 like when we released. so initial attempt in postgres should reflect that.
Signed-off-by: Gal Schlezinger <gal@spitfire.co.il>
* drain stuff
Signed-off-by: Gal Schlezinger <gal@spitfire.co.il>
* fallback metadata to metadataJson
Signed-off-by: Gal Schlezinger <gal@spitfire.co.il>
* Make code more readable
Signed-off-by: Gal Schlezinger <gal@spitfire.co.il>
* apply Vade fix
Signed-off-by: Gal Schlezinger <gal@spitfire.co.il>
---------
Signed-off-by: Gal Schlezinger <gal@spitfire.co.il>
* Initial plan
* Fix DurableAgent to handle FatalError in tool calls
Convert FatalError exceptions in tool execution to tool-result errors that get
propagated back to the LLM, mimicking AI SDK behavior. Non-fatal errors are
re-thrown to allow workflow retry mechanisms to handle them.
- Updated executeTool to catch FatalError and convert to error-text tool result
- Added comprehensive tests for error handling scenarios
- All tests passing
Co-authored-by: pranaygp <1797812+pranaygp@users.noreply.github.com>
* Address code review feedback and add changeset
Remove unnecessary type assertion and add changeset for the DurableAgent fix
Co-authored-by: pranaygp <1797812+pranaygp@users.noreply.github.com>
* Update packages/ai/src/agent/durable-agent.ts
* Apply suggestion from @pranaygp
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: pranaygp <1797812+pranaygp@users.noreply.github.com>
Co-authored-by: Peter Wielander <mittgfu@gmail.com>
Co-authored-by: Pranay Prakash <pranay.gp@gmail.com>
Fixed a bug where default export workflow functions with names (e.g., `export default async function testWorkflow()`) would fail at runtime with `ReferenceError: $$default is not defined`. The SWC plugin now correctly keeps the default export as-is and simply adds the workflowId assignment after it, since the function name is available as a binding in the module scope.
Also adds support for anonymous and arrow function default exports, which previously were not being transformed at all.
Fixes#367.
* Fix workflow failing because of function timeouts
* Update packages/core/src/runtime.ts
Co-authored-by: Peter Wielander <mittgfu@gmail.com>
---------
Co-authored-by: Peter Wielander <mittgfu@gmail.com>
* Add e2e tests for postgres world
* Add e2e tests for postgres world
- Add new e2e-local-postgres job to test all workbenches against postgres world
- Configure PostgreSQL service container in GitHub Actions
- Update world-postgres build script to chmod +x the setup.js bin
- Use direct path to setup script in CI for reliability
- Tests run in production mode similar to e2e-local-prod tests
Made the `tools` parameter optional in the `DurableAgent` class.
### What changed?
- Updated the `DurableAgentOptions` interface to make the `tools` property optional
- Modified the constructor to initialize `this.tools` with an empty object (`{}`) when `options.tools` is not provided
Added support for defining `model` as a step function initializer in the AI workflow package.
### What changed?
- Modified the `DurableAgent` class to accept either a string model ID or a function that returns a `LanguageModelV2` instance
- Updated the `doStreamStep` function to handle both string model IDs and function initializers
- Added proper error handling for invalid model initialization arguments
### How to test?
Test both initialization methods:
1. Using a string model ID:
```typescript
const agent = new DurableAgent({
model: 'anthropic/claude-opus',
// other options
});
```
2. Using a step function initializer:
```typescript
import { xai } from "@ai-sdk/xai"
const agent = new DurableAgent({
model: async () => {
"use step";
return xai("grok-4");
},
// other options
});
```
### Why make this change?
This enhancement provides more flexibility in how language models are initialized and used within the workflow. By supporting function initializers, users can now:
- Use custom model instances with specialized configurations
- Implement more complex model initialization logic that wasn't possible with just string identifiers