Test mode: plans are proposed and nobody is charged yet.

← Docs

Camshaft workflows in TypeScript

Write a workflow as an async function; Camshaft's engine runs it durably. Steps run once and are recorded; sleeps and waits for signals last as long as they need to, with no process staying up meanwhile.

import { handler, type Workflow } from "@camshaft/sdk";

const refund: Workflow = async (ctx, order) => {
  const amount = await ctx.step("look up", () => lookUp(order));      // runs once, recorded
  const ok = await ctx.waitSignal<boolean>("approval", "approve");    // waits for a person, durably
  if (!ok) return "declined";
  await ctx.sleep("cool off", 60_000);                                // a minute, durably
  const note = await ctx.waitSignalUntil<string>("note", "note", 3_600_000); // or null after an hour
  const label = await ctx.child<string>("label", "print-label", order);  // another workflow, in any language
  return ctx.step("refund", () => pay(order, amount));                // runs once, even if this server restarts
};

export default { fetch: handler({ refund }, { secret: process.env.CAMSHAFT_SECRET! }) };

Updates and queries: ctx.waitUpdate(name, "add") takes the next update sent with POST /runs/{id}/updates/add ({id, value}), ctx.answer(name, update, {value} | {error}) answers it (its sender is waiting), and ctx.publish(name, "total", 42) publishes a value anyone reads with GET /runs/{id}/published. ctx.tag(name, ["stage=shipped"]) tags the run to find it by (GET /runs?tag=); a key=value tag replaces its key.

Serve the handler anywhere that takes HTTP (Node, Astropause, any runtime with Request and Response), and tell the engine where it is: CAMSHAFT_REMOTE='{"refund": {"url": "https://refunds.example/camshaft", "secret": "…"}}' (see docs/operating.md). Start runs with the HTTP API or camshaftctl start refund <id> '"order 7"'.

How it runs

(The protocol itself, for an SDK in another language: docs/remote-protocol.md.)

The engine keeps the run and calls your handler with its journal (what's recorded so far). The handler runs the workflow from the top: each recorded step, sleep or signal returns its recorded result at once, and the first thing not recorded is sent back to the engine, which records it and calls again. So:

Status: a first version for review (2026-11-30). Not published as a package (publishing is a person's step); use it from this repository. Needs Node 22.6+ for its tests (npm test, TypeScript run directly).

A client of the HTTP API: @camshaft/sdk/client

The other direction: call Camshaft from TypeScript (docs/openapi.json), mirroring sdk/go and Python's camshaft.client. It lives in this package (src/client.ts, imported as @camshaft/sdk/client) and shares nothing with the workflow server. fetch only, no dependencies: Node 18+, Deno, Bun, browsers and Workers.

import { Client, NodRequired, Conflict, RateLimited } from "@camshaft/sdk/client";

const c = new Client("https://camshaft.example", () => currentToken()); // a string, or a (async) function asked
                                                                        // before each call and once more after a 401
await c.saveFlow("refunds", { input: "string", steps: [/* ... */], output: /* ... */ });
const st = await c.startRun({ id: "order-9", flow: "refunds", input: "9", priority: 10 }); // st.created, st.debounced
const run = await c.getRun(st.id);
for await (const e of c.watchRun(st.id)) { /* {type: "status"|"live"|"end", ...}: through waits, to its end */ }
for await (const r of c.eachRun({ flow: "refunds", status: "failed", limit: 50 })) { /* cursor paging; listRuns gives a page */ }
await c.retryRun(r.id); await c.signalRun(r.id, "go", true); await c.cancelRun(r.id, "reason");
await c.approve(runId, "agent step", "call_2");            // a person's own token only: others get Forbidden
await c.sendEvent("refunds", "paid", { id: "e1", data: { customer: "acme" } });
await c.setSchedule({ name: "nightly", flow: "refunds", cron: "0 2 * * *", tz: "Europe/Berlin" }); await c.listSchedules();
await c.getPacing("refunds"); await c.getConcurrency("refunds", "acme");

try { await c.deleteFlow("refunds"); } catch (e) {
  if (e instanceof NodRequired) {
    // ask e.issuer for a person's approval of exactly e.authorizationDetails (CIBA), then:
    await c.deleteFlow("refunds", approvalToken);
  } else if (e instanceof RateLimited) { /* wait e.retryAfter seconds */ } else if (e instanceof Conflict) { /* ... */ } else throw e;
}

A run on a frontend: @camshaft/sdk/react and @camshaft/sdk/follow

A screen that shows a run as it goes (its status, an agent's answer as it streams, the output at the end):

import { useRun } from "@camshaft/sdk/react";

function Refund({ client, id }: { client: Client; id: string }) {
  const { run, status, live, done, error } = useRun(client, id); // follows while mounted, stops on unmount
  if (error) return <p>{error.message}</p>;
  return <>
    <p>{status}</p>
    {live && !done && <pre>{live.text}</pre>}
    {done && <pre>{JSON.stringify(run?.output)}</pre>}
  </>;
}

useRun reads the run, then follows its stream (watchRun), reading it again on each status change and at the end. React is a peer dependency, only for this import. Without React, followRun(client, id) is the same thing as a subscribe/getSnapshot pair (each change a new object), for any framework's store. The client's token needs runs:read: in a browser, a short-lived token your own backend hands out, never a long-lived one.

Every call takes { signal } last, an AbortSignal. Every refused call throws an ApiError (status, detail) or a subclass: BadRequest, Unauthorized, Forbidden, NotFound, Conflict, RateLimited (retryAfter in seconds, limit), ServiceUnavailable; a 403 that asks for a nod is a NodRequired (a Forbidden). Types are hand-written to match docs/openapi.json. Tests: npm test; test/integration.test.ts runs against the real binary and a throwaway PostgreSQL when CAMSHAFT_BIN and KIT_PG_BIN are set. Not published (a person's step).