Local SDK

createLocalSdk creates a typed client that triggers workflows through a WorkflowInvoker in the same process. The SDK is parameterized with your Router type, so workflowId and params are checked at compile time.

Setup

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

const sdk = createLocalSdk<Router>(invoker);

sdk.trigger

Triggers a workflow and returns { executionId } immediately. The workflow runs in the background.

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

sdk.triggerAndWait

Triggers a workflow and blocks until it completes. Returns the workflow's return value.

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

The promise resolves when the WorkflowInvoker emits the 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