Skip to content

AA1: the app on Workers - #2

Merged
ruehowl merged 1 commit into
mainfrom
aa/1-the-app-on-workers
Oct 28, 2026
Merged

ruehowl merged 1 commit into
mainfrom
aa/1-the-app-on-workers

Conversation

@ruehowl

@ruehowl ruehowl commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

E2B's Fragments in apps/web, on one Cloudflare Worker with Static Assets built by @opennextjs/cloudflare. It runs on the reference stack: Next.js 16, React 19, and AI SDK 7 with @ai-sdk/react 4. streamObject and experimental_useObject are unchanged.

Upstream Here
A vendor key for every model Workers AI through the AI binding (workers-ai-provider, the fragment's schema sent as JSON mode) is the default and needs no key. Upstream's vendor models stay, sent with the visitor's key or a server key (an optional Worker secret). A vendor model with neither is refused, naming the key to add.
E2B_API_KEY env An optional Worker secret. Without it the fragment is still written and shown, and a notice says what running it needs.
Upstash rate limit on Vercel KV A fixed window per client IP in the KV binding (same variables).
Vercel KV share links + middleware fragment:<id> keys in KV. /s/<id> is a route handler, and the link uses the visitor's own origin.
Supabase sign-in, PostHog, Vercel Analytics, Google Tag Manager Left out. The account menu keeps its links.
Vertex, Ollama Left out: a service-account file and a local server do not fit a Worker.

The PR also adds:

  • /api/health, which the deploy's smoke reads. It is read-only, so a public route can't spend KV writes.
  • wrangler.template.jsonc and wiring.fixture.json, which render wrangler.jsonc (committed as the fixture render).
  • component.yaml, the deploy contract. The enforced edge on cloudflare-kv lands in AA2. Each stored key goes to the Worker as a secret, and none reaches the bundle.
  • tests/web: upstream's model, request-schema and route tests ported to vitest, plus the KV rate limit, the links, and the sandbox, health and short-link routes. They run against in-memory bindings with no network: 98 tests.

Checked locally:

  • pnpm install --frozen-lockfile, wire:fixture (no diff), typecheck, lint (0 errors) and test all pass.
  • build passes. The Worker is 9073 KiB, 1875 KiB gzipped, so it fits Workers Free.
  • wrangler dev, with the AI binding pointed at a Workers AI stand-in, serves the page and health. It also streams a fragment, answers that E2B isn't connected, refuses an unkeyed vendor model, rate-limits on the 11th request and redirects an unknown short link home.

Upstream's code is kept as written. The lint rules that eslint-config-next 16 added after it was written are turned off by name, as the reference starters do.


Generated by Claude Code

E2B's Fragments in apps/web, on one Cloudflare Worker + Static Assets built by
@opennextjs/cloudflare, on the reference stack (Next.js 16, React 19, AI SDK 7
with @ai-sdk/react 4 — streamObject and experimental_useObject unchanged).

- Models: Workers AI through the Worker's own AI binding (workers-ai-provider,
  the fragment's schema sent as JSON mode) is the default and needs no key;
  upstream's vendor models stay, sent with the visitor's key or a server key
  (an optional Worker secret). A vendor model with neither is refused with
  the key to add. Vertex and Ollama are left out (a service-account file and
  a local server do not fit a Worker).
- E2B: the sandbox route runs fragments with E2B_API_KEY, an optional Worker
  secret; without it the fragment is still written and shown, and the page
  says what running it needs.
- Upstash rate limiting and the Vercel KV share links become a fixed window
  and fragment:<id> keys in the KV binding; /s/<id> is a route handler
  instead of middleware; a published link uses the visitor's own origin.
- Supabase sign-in, PostHog, Vercel Analytics and Google Tag Manager are left
  out; the account menu keeps its links.
- /api/health (read-only) is what the deploy's smoke reads.
- wrangler.template.jsonc + wiring.fixture.json render wrangler.jsonc per
  environment from the cloudflare-kv root's wiring document; component.yaml
  carries the deploy contract, pushing each stored key to the Worker as a
  secret (worker-secrets.mjs) with none reaching the bundle.
- tests/web: upstream's model, request-schema and route tests ported to
  vitest, plus the KV rate limit, the links, the sandbox, health and
  short-link routes, against in-memory bindings and no network (98 tests).

Upstream's code is kept as written; the lint rules eslint-config-next 16
added after it are turned off by name. The Worker is 1875 KiB gzipped.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019PcpNVpFBcbeiX3EHdXfmn
@ruehowl
ruehowl merged commit 5284294 into main Oct 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants