On Postgres or SQLite
@abyssinia-labs/wake-server: the server half of wake/v1 over HTTP, for any TypeScript app, on Postgres or SQLite (Cloudflare D1) with Drizzle.
bun add @abyssinia-labs/wake-server drizzle-ormNo Convex needed: Wake reaches your app over the HTTP transport, and the pending list comes as server-sent events. It runs anywhere the Fetch API does: Next.js, Hono, Bun, Deno, Cloudflare Workers. Storage is Drizzle on Postgres (any driver) or SQLite, Cloudflare D1 among them.
Install
Section titled “Install”Add the three tables to your Drizzle schema and migrate as usual:
export { wakeCodes, wakePlaces, wakeSummonses } from "@abyssinia-labs/wake-server/drizzle";Wire it up
Section titled “Wire it up”import { drizzleStore } from "@abyssinia-labs/wake-server/drizzle";import { discovery, Wake, wakeHandler } from "@abyssinia-labs/wake-server";
export const wake = new Wake({ app: "acme", store: drizzleStore(db), keyPrefix: "acme_" });const routes = wakeHandler(wake);Mount routes under your httpBase. It answers its own paths and null
for anything else. In Next.js, app/api/wake/v1/[route]/route.ts:
const handle = async (req: Request) => (await routes(req)) ?? new Response(null, { status: 404 });export { handle as GET, handle as POST };export const dynamic = "force-dynamic";Serve discovery at /.well-known/wake:
Response.json(discovery({ httpBase: "https://acme.dev/api" }));Call it from your app
Section titled “Call it from your app”The same calls as the Convex component: issueCode for
your “pair Wake” tool, summon when a person assigns or mentions an agent,
answer, settle, forSubject to show a run by name where it was asked,
forOwner for a person’s runs list, places, forgetPlace,
revokeAgent and deleteScope. See Examples for the
summon calls and prompts; they read the same.
On Cloudflare D1
Section titled “On Cloudflare D1”import { drizzle } from "drizzle-orm/d1";import { sqliteStore } from "@abyssinia-labs/wake-server/sqlite";
const wake = new Wake({ app: "acme", store: sqliteStore(drizzle(env.DB)), keyPrefix: "acme_" });The SQLite tables are wakePlaces, wakeCodes and wakeSummonses from
@abyssinia-labs/wake-server/sqlite, or the statements in
WAKE_SQLITE_TABLES. On D1 the stream’s re-reads cost rows read rather
than a database kept awake, so an idle app costs next to nothing.
Several instances, and serverless
Section titled “Several instances, and serverless”A change made in the same process reaches Wake at once; each open stream
also reads the list again every 10 seconds (pollMs), so a change another
instance made arrives within that. On a host with a request time limit,
set maxStreamMs under it and Wake reconnects when the stream ends.
Try it
Section titled “Try it”The repository’s
packages/server/example/server.ts
is the smallest app that serves wake/v1 this way:
bun packages/server/example/server.tswake check localhost:3210