Expose world helpers via workflow/api (v2) #259
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR: Expose world helpers via workflow/api (v2)
Summary
getWorldplus everyWorldhelper (runs/steps/events/hooks/queue/streams/start) directly fromworkflow/api, so application code can manage runs without reimplementingcreateWorld.setWorldto assert each helper delegates correctly and specifically exercises the “list runs then cancel” flow requested for Next.js/server usage.workflowpackage.Use Cases Addressed
listRuns,cancelRun, etc., without importing fromworkflow/runtime.getWorld()fromworkflow/api, matching CLI behavior across dev/test/prod setups.queue,createQueueHandler,writeToStream, etc.).setWorldin tests while still using the exported helpers, ensuring parity with production behavior.Implementation Details
packages/workflow/src/api.tsnow imports the relevant types from@workflow/world, re-exports them, and defines thin wrappers for everyWorldsubfunction plusstartWorld.@workflow/worldtopackages/workflow/package.jsondependencies and syncedpnpm-lock.yaml.packages/workflow/src/api.test.tswith full delegation coverage and the “list -> cancel” scenario.docs/content/docs/api-reference/workflow-api/world.mdx, updated the API index cards, and inserted a new “Programmatically list and control runs” section instarting-workflows.mdx..changeset/expose-world-helpers.mdso theworkflowpackage gets a patch bump.Verification
pnpm --filter workflow test -- src/api.test.tspnpm --filter workflow typecheckpnpm biome check packages/workflow/src/api.ts packages/workflow/src/api.test.tsNotes