Skip to content

Deployment

Everything you need to run and deploy the Worker.

Local Development

Install dependencies:

npm install

Run locally:

npm run dev

or:

npx wrangler dev

Deploy:

npm run deploy

or:

npx wrangler deploy

Dry-run bundle check:

npx wrangler deploy --dry-run

Cloudflare Configuration

wrangler.toml:

name = "puter-api"
main = "src/index.js"
compatibility_date = "2026-04-21"

[observability.logs]
enabled = true
invocation_logs = true

[[durable_objects.bindings]]
name = "CHAT_MEMORY"
class_name = "ChatMemorySQLite"

[[migrations]]
tag = "v2"
new_sqlite_classes = ["ChatMemorySQLite"]

Important

The Worker expects the CHAT_MEMORY Durable Object binding to exist in production.

If the binding is unavailable, the code has an in-memory fallback map. That fallback is only useful for local/non-persistent execution and should not be treated as durable production memory.

Project Files

src/index.js              Main deployed Worker and Durable Object.
src/model-tier-pools.js   Puter fallback model pools.
wrangler.toml             Cloudflare Worker configuration.
package.json              npm scripts and dependencies.
chat (1) (1).html         Standalone browser chat client.
test-chat.js              Puppeteer smoke test for the HTML client.
README.md                 This documentation.

There are also root-level older/stale copies:

index.js
model-tier-pools.js
sr

Warning

Wrangler deploys src/index.js, not the root index.js.

Dependencies

Runtime/imported by the Worker:

minisearch

Development/testing/client-related dependencies:

wrangler
puppeteer
jsdom

Operational Notes

The Worker uses:

Multiple upstream AI providers in a waterfall pattern
Authentication backend for caller API key validation
Durable Objects for memory and model-usage rotation
MiniSearch for BM25 text recall
Background compaction for long conversation efficiency

Most important runtime metadata visible to clients

info.provider                          Always "x0root"
info.model                             The model that produced the answer
info.pool                              The router tier/pool
memory.injected                        Whether chat memory was used
memory.total_indexed_messages          Total messages in the index
memory.compaction_triggered            Whether compaction ran