Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
50eaa28
Support passing step function references across serialization layer
TooTallNate Nov 11, 2025
7b8fbeb
tests
TooTallNate Nov 11, 2025
476147a
.
TooTallNate Nov 11, 2025
530e477
.
TooTallNate Nov 11, 2025
c4cd86b
Use nate's devalue fork
TooTallNate Nov 12, 2025
7c4e850
Fix build
TooTallNate Nov 12, 2025
52d1206
Changeset
TooTallNate Nov 12, 2025
aabc1a1
Merge branch 'main' of github.com:vercel/workflow into update/seriali…
TooTallNate Nov 12, 2025
42f7adc
.
TooTallNate Nov 12, 2025
e7a491d
Update packages/core/src/serialization.ts
TooTallNate Nov 12, 2025
3ea314d
Merge branch 'main' of github.com:vercel/workflow into update/seriali…
TooTallNate Nov 12, 2025
10b77c4
Use latest devalue
TooTallNate Nov 12, 2025
1480889
Isolate test
TooTallNate Nov 12, 2025
0da9cc2
Merge branch 'main' of github.com:vercel/workflow into update/seriali…
TooTallNate Nov 12, 2025
c60de66
Add step name transform to arrow function steps
TooTallNate Nov 12, 2025
57e4899
.
TooTallNate Nov 12, 2025
921ae65
update tsconfig
ijjk Nov 12, 2025
344439c
update
ijjk Nov 12, 2025
de91783
update
ijjk Nov 12, 2025
c655f2b
fix
ijjk Nov 12, 2025
a5f85e4
fix
ijjk Nov 12, 2025
a16ee81
debug stuff
ijjk Nov 12, 2025
8a91661
logs
ijjk Nov 12, 2025
c3674cd
Merge branch 'main' of github.com:vercel/workflow into update/seriali…
TooTallNate Nov 12, 2025
881a9e3
Merge branch 'update/serialize-step-function-reference' of github.com…
TooTallNate Nov 12, 2025
edf679a
.
TooTallNate Nov 12, 2025
456fa95
peter
TooTallNate Nov 13, 2025
35384f6
Fix test
TooTallNate Nov 13, 2025
bc59732
Merge branch 'main' of github.com:vercel/workflow into update/seriali…
TooTallNate Nov 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/src/runtime/world.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createRequire } from 'node:module';
import Path from 'node:path';
import { join } from 'node:path';
import type { World } from '@workflow/world';
import { createEmbeddedWorld } from '@workflow/world-local';
import { createVercelWorld } from '@workflow/world-vercel';

const require = createRequire(Path.join(process.cwd(), 'index.js'));
const require = createRequire(join(process.cwd(), 'index.js'));

let worldCache: World | undefined;
let stubbedWorldCache: World | undefined;
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ export type Serializable =
| Uint8ClampedArray
| Uint16Array
| Uint32Array
| WritableStream<Uint8Array>;
| WritableStream<Uint8Array>
| ((...args: Serializable[]) => Promise<Serializable>); // Step function
17 changes: 17 additions & 0 deletions packages/core/src/serialization.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { WorkflowRuntimeError } from '@workflow/errors';
import * as devalue from 'devalue';
import { getStepFunction } from './private.js';
import { getWorld } from './runtime/world.js';
import {
BODY_INIT_SYMBOL,
STEP_FUNCTION_NAME_SYMBOL,
STREAM_NAME_SYMBOL,
STREAM_TYPE_SYMBOL,
WEBHOOK_RESPONSE_WRITABLE,
Expand Down Expand Up @@ -169,6 +171,7 @@ export interface SerializableSpecial {
redirected: boolean;
};
Set: any[];
StepFunction: string; // step function name/ID
URL: string;
URLSearchParams: string;
Uint8Array: string; // base64 string
Expand Down Expand Up @@ -275,6 +278,11 @@ function getCommonReducers(global: Record<string, any> = globalThis) {
};
},
Set: (value) => value instanceof global.Set && Array.from(value),
StepFunction: (value) => {
if (typeof value !== 'function') return false;
const stepName = value[STEP_FUNCTION_NAME_SYMBOL];
return stepName ? stepName : false;
},
URL: (value) => value instanceof global.URL && value.href,
URLSearchParams: (value) => {
if (!(value instanceof global.URLSearchParams)) return false;
Expand Down Expand Up @@ -516,6 +524,15 @@ function getCommonRevivers(global: Record<string, any> = globalThis) {
Map: (value) => new global.Map(value),
RegExp: (value) => new global.RegExp(value.source, value.flags),
Set: (value) => new global.Set(value),
StepFunction: (value) => {
const stepFn = getStepFunction(value);
if (!stepFn) {
throw new Error(
`Step function "${value}" not found. Make sure the step function is registered.`
);
}
return stepFn;
},
URL: (value) => new global.URL(value),
URLSearchParams: (value) =>
new global.URLSearchParams(value === '.' ? '' : value),
Expand Down
14 changes: 13 additions & 1 deletion packages/core/src/step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { stepLogger } from './logger.js';
import type { WorkflowOrchestratorContext } from './private.js';
import type { Serializable } from './schemas.js';
import { hydrateStepReturnValue } from './serialization.js';
import { STEP_FUNCTION_NAME_SYMBOL } from './symbols.js';

export function createUseStep(ctx: WorkflowOrchestratorContext) {
return function useStep<Args extends Serializable[], Result>(
stepName: string
) {
return (...args: Args): Promise<Result> => {
const stepFunction = (...args: Args): Promise<Result> => {
const { promise, resolve, reject } = withResolvers<Result>();

const correlationId = `step_${ctx.generateUlid()}`;
Expand Down Expand Up @@ -124,5 +125,16 @@ export function createUseStep(ctx: WorkflowOrchestratorContext) {

return promise;
};

// Attach the step name to the function so it can be properly serialized
// when passed as an argument to another step
Object.defineProperty(stepFunction, STEP_FUNCTION_NAME_SYMBOL, {
value: stepName,
writable: false,
enumerable: false,
configurable: false,
});

return stepFunction;
};
}
3 changes: 3 additions & 0 deletions packages/core/src/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ export const BODY_INIT_SYMBOL = Symbol.for('BODY_INIT');
export const WEBHOOK_RESPONSE_WRITABLE = Symbol.for(
'WEBHOOK_RESPONSE_WRITABLE'
);
export const STEP_FUNCTION_NAME_SYMBOL = Symbol.for(
'WORKFLOW_STEP_FUNCTION_NAME'
);
Loading