yieldstar

The main SDK package. Exports the workflow definition API, router factory, retry error class, and both SDK clients.

Install

bun add yieldstar

Exports

import { workflow, createWorkflow } from "yieldstar";
import { createWorkflowRouter } from "yieldstar";
import { RetryableError } from "yieldstar";
import { createLocalSdk } from "yieldstar";
import { createHttpSdkFactory } from "yieldstar";
import type { WorkflowFn } from "yieldstar";

workflow(fn) / createWorkflow(fn)

Defines a workflow. Returns a WorkflowGenerator.

const w = workflow<Params, Result>(async function* (step, event, logger) {
  return yield* step.run(() => compute());
});
Type parameterConstraintDescription
ParamsRecord<string, any> | voidShape of event.params
ResultanyReturn type of the workflow
ContextReadonlyMap<any, any>Shape of event.context (set by middleware)

createWorkflowRouter(workflows)

Registers workflows with string IDs. Returns the same object, typed for SDK consumption.

const router = createWorkflowRouter({
  "order": orderWorkflow,
  "reminder": reminderWorkflow,
});
export type Router = typeof router;

RetryableError

Thrown inside step.run to trigger structured retries.

throw new RetryableError(message, { maxAttempts, retryInterval });
PropertyTypeDescription
maxAttemptsnumberTotal attempts including the first
retryIntervalnumberMilliseconds between attempts

createLocalSdk<Router>(invoker)

Creates a local SDK client. See Local SDK.

createHttpSdkFactory<Router>()

Returns a factory for HTTP SDK clients. See HTTP SDK.

Step runner

Available on the first argument of a workflow function:

yield* step.run(fn);
yield* step.run("key", fn);

yield* step.delay(ms);
yield* step.delay("key", ms);

yield* step.poll(opts, predicate);
yield* step.poll("key", opts, predicate);