A working example of @earendil-works/pi-durable running in a Cloudflare Durable Object.
Start with the Pi Durable announcement for the ideas behind the harness. This repository shows one way to put those ideas into a small, usable web application.
Pi Durable is experimental, so its APIs may still change.
- Create a shared chat session and open it in multiple browsers.
- Run several conversations at once and fork a conversation from an earlier message.
- Reconnect without losing committed transcripts or queued prompts.
- Schedule one-time or recurring follow-ups.
- Ask a search subagent about earlier conversations.
- Open Activity to inspect live task ownership, waits, sleeps, tool calls, and background work while conversations run, and to retry a task parked after repeated crashes.
This is a sample, not a production service. It intentionally has no authentication or rate limiting.
You need Node.js 22.19 or newer, pnpm 11, and an OpenAI API key.
pnpm install
cp .dev.vars.example .dev.varsAdd your key to .dev.vars:
OPENAI_API_KEY=your-keyThen start the Worker and React client together:
pnpm devOpen the local URL printed by Vite, create a session, and send a message. Open the session URL in another browser to try the multiplayer flow.
The shortest path through the project is:
src/chat.tsdefines the models, extensions, tools, and default agent.src/session.tshosts the harness with Pi Durable's built-in Durable Object SQLite storage and connects it to Cloudflare's native hibernating WebSockets and alarms.src/tools.ts,src/schedule.ts, andsrc/search.tscontain the example tools and tasks.src/client/is the React client and its event-driven session state.test/covers application flows including restart recovery, scheduling, forks, and inboxes. Pi Durable tests its built-in Cloudflare storage adapter inside a Durable Object itself.
The code is the documentation for this integration. In particular, the tests are useful examples of restart behavior, scheduling, forks, and inboxes.
pnpm dev # local development
pnpm test # test suite
pnpm check # formatting, types, build, and deploy dry run
pnpm build # production build
pnpm preview # preview the production build locallyAuthenticate Wrangler, store the API key as a Worker secret, then deploy:
pnpm exec wrangler login
pnpm exec wrangler secret put OPENAI_API_KEY
pnpm deployBefore exposing a deployment, add authentication, authorization, and rate limiting. Anyone who can reach this sample can create sessions that use your model credentials.