Local SDK

createLocalSdk builds a typed client that triggers workflows through a WorkflowInvoker running in the same process. It takes your Router type as a generic parameter, so TypeScript checks every workflowId and its corresponding params at compile time.

Setup

import { createLocalSdk } from "yieldstar";
import type { Router } from "./shared";

const sdk = createLocalSdk<Router>(invoker);

sdk.trigger

Starts a workflow and returns { executionId } immediately while the workflow continues running in the background.

const { executionId } = await sdk.trigger({
  workflowId: "process-order",
  params: { orderId: "abc123" },
});

sdk.triggerAndWait

Starts a workflow and blocks until it completes, then returns the workflow's return value.

const result = await sdk.triggerAndWait({
  workflowId: "process-order",
  params: { orderId: "abc123" },
});

The returned promise resolves when the WorkflowInvoker emits the matching executionId on its workflowEndEmitter. If the workflow throws, the error propagates to the caller.

Trigger event shape

FieldTypeRequiredDescription
workflowIdstringYesID matching a key in the router
paramsRecord<string, any>Depends on workflow typeInput data accessible via event.params inside the workflow
executionIdstringNoCustom execution ID. Auto-generated via nanoid if omitted