SDKs

forkbase for TypeScript and Python, and supabase-js and supabase-py as they are.

Two kinds of client work with Forkbase:

  • supabase-js / supabase-py for tables, auth, storage and realtime. Forkbase speaks their APIs; point them at your Forkbase URL and anon key.
  • @chronosdb/forkbase (TypeScript) and forkbase (Python) for what Supabase's clients don't cover: agents' runs and jobs. No dependencies.
shell
npm i @chronosdb/forkbase          # Node 18+, browsers, Deno, Bun
pip install forkbase    # Python 3.9+, standard library only

TypeScript

TypeScript
import { createClient } from "@chronosdb/forkbase";

const fb = createClient("https://api.myapp.com", process.env.FORKBASE_AGENT_TOKEN!);

// the usual shape: a block that runs in a world, then proposes
const { outcome, result } = await fb.agents.withRun("close stale carts", async (run) => {
  const r = await run.sql("update carts set closed = true where updated_at < now() - interval '30 days' returning id");
  return r.rows.length;
});
if (outcome.status === "held") console.log("waiting for a person:", outcome.reasons);

withRun proposes when the block returns and discards the run when it throws. propose() never throws for merged, held or conflict: read outcome.status.

createClient(url, key, { fetch?, headers? })

key is an agent token (fba_), a run token (fbr_) or the service key. What you can call depends on it; see Agents, who may call what.

fb.agents

MethodKey
run(intent, opts?)agent, servicea Run
withRun(intent, fn, opts?)agent, service{ run, result, outcome }
get(id)anya Run
listRuns({ status?, limit? })agent, service
create(name, { policy? })servicea new agent, with its token
list()service
approve(id), reject(id, reason?), undo(id, { skipChanged? })service

opts: agent (service key: whose run), ttlSeconds, meta, policy, actAs (a signed-in person's access token: RLS judges the run as theirs).

Run

id, status, token, databaseUrl, data, and:

Method
sql(query, params?){ columns, rows }
changes({ limit? })the rows it changed
propose(){ status: "merged" | "held" | "conflict", reasons? }
discard()
refresh()reload its status

databaseUrl works with any Postgres driver or ORM (pg, Drizzle, Prisma).

fb.jobs (service key)

Method
deploy({ name, files | source, entry?, env?, timeout_s?, memory_mb?, max_attempts?, concurrency?, agent? })
functions()
invoke(name, payload?, { wait?, delayS?, runAt?, idempotencyKey? })
get(id), list({ fn?, status?, before?, limit? })
cancel(id), retry(id)
schedule(fn, cron, payload?)

Everything else

fb.request(method, path, body?) calls any route. await fb.supabase() returns a supabase-js client for the same server (install @supabase/supabase-js).

Errors throw ForkbaseError with status, code and body.

Inside a job

TypeScript
import { step, sleep, sql, context } from "@chronosdb/forkbase";
step(name, fn)run once, remembered across retries
sleep(name, seconds)pause the job without holding a worker
sql(query, params?)agent functions: SQL in the job's world
context(){ payload, job: { id, attempt, function }, run, url, step, sleep, sql }

The job runtime ships this module; functions import it without installing it. See Jobs.

Python

Python
from forkbase import create_client

fb = create_client("https://api.myapp.com", agent_token)

scope = fb.agents.with_run("close stale carts")
with scope as run:
    run.sql("update carts set closed = true where updated_at < now() - interval '30 days'")
print(scope.outcome)   # {"status": "merged" | "held" | "conflict", ...}; an exception in the block discards the run

The same methods in snake_case: fb.agents.run(intent, agent=, ttl_seconds=, meta=, act_as=, policy=), with_run, get, list_runs, create, list, approve, reject, undo(run_id, skip_changed=False); fb.jobs.deploy(**fn), functions, invoke(name, payload, delay_s=, run_at=, idempotency_key=, wait=), get, list, cancel, retry, schedule; fb.request, fb.supabase() (install forkbase[supabase]). Errors raise ForkbaseError (status, code, body).

Inside a job: from forkbase import step, sleep, sql, context.

supabase-js

TypeScript
import { createClient } from "@supabase/supabase-js";
const supabase = createClient("https://api.myapp.com", ANON_KEY, { auth: { flowType: "pkce" } });

await supabase.auth.signInWithPassword({ email, password });
await supabase.from("notes").insert({ body: "hi" });
await supabase.storage.from("avatars").upload("me.png", file);
supabase.channel("notes").on("postgres_changes", { event: "*", schema: "public", table: "notes" }, console.log).subscribe();

What works: tables (from), auth (passwords, OTP, OAuth with PKCE, sessions), storage, realtime changes and broadcast. Not yet: rpc (Postgres functions over REST), presence, edge functions (use Jobs).

Something wrong or missing? Edit this page on GitHub or open an issue.

SDKs · Forkbase