Runtime Interface
TypeScript SDK
Zero-dependency worker client with strict payload schemas and deterministic replay.
npm install @relay-engine/sdk
src/workflows/dunning.ts Declare deterministic steps with typed inputs and automatic state checkpointing.
import { workflow } from "@relay-engine/sdk";
export const dunningCycle = workflow({
id: "billing.dunning",
retry: { attempts: 5, backoff: "exponential", baseMs: 500 },
async run(ctx, input: { invoiceId: string }) {
const attempt = await ctx.step("charge", () =>
payments.capture(input.invoiceId)
);
if (attempt.status === "declined") {
await ctx.sleep("grace-window", "72h");
await ctx.step("notify", () => mailer.sendNotice(input.invoiceId));
}
return { settled: attempt.status === "paid" };
},
}); src/workflows/approval.ts Suspend a workflow indefinitely until an external webhook or operator signal arrives.
import { workflow } from "@relay-engine/sdk";
export const releaseGate = workflow({
id: "deploy.approval",
async run(ctx, input: { releaseSha: string }) {
await ctx.step("stage", () => deploys.pushStaging(input.releaseSha));
const decision = await ctx.waitForSignal<{ approved: boolean }>(
"ops.decision",
{ timeout: "24h" }
);
if (!decision?.approved) {
return { promoted: false };
}
await ctx.step("promote", () => deploys.pushProd(input.releaseSha));
return { promoted: true };
},
}); src/cli/redrive.ts Filter dead-lettered runs by error code and re-drive them safely without duplicate side effects.
import { RelayClient } from "@relay-engine/sdk";
const client = new RelayClient({
endpoint: process.env.RELAY_URL!,
token: process.env.RELAY_TOKEN!,
});
const batch = await client.deadLetters.redrive({
workflowId: "webhooks.fanout",
errorCode: "UPSTREAM_TIMEOUT",
limit: 250,
ratePerSecond: 40,
});
console.log(`Re-queued ${batch.accepted} runs.`); Runs on Node 22, Bun, and edge workers.
Compare quotas →