Each step can return a JSON-serializable value—anything from simple primitives to complex objects.The value is JSON-serialized and automatically restored across requests.
Avoid returning stateful resources such as database connections or file handles.Instead, return plain data (numbers, strings, arrays, objects) so the result can be safely persisted and restored across workflow executions.
Because results are JSON-serialized, class instances are restored as plain objects.
This means instance methods will not be available unless you explicitly rehydrate the object.To fix this, you can recreate the instance using Object.assign() or a custom factory:
Copy
Ask AI
export const { POST } = serve(async (context) => { let user = await context.run("step-1", async () => { // 👇 Return a class instance from step return new User("John Doe", "john.doe@example.com"); }); // 👇 Properties are accessible by default console.log(user.name) // 👇 Create a Proper Instance with Object.assign() user = Object.assign(new User(), user); await context.run("greet", async () => { // 👇 Now instance methods are available as well console.log(user.greet()); }); });