[Worker]

Cloudflare Worker for AXIS: /api/run proxy, keys, scripts, usage, and Durable Object stream relay.

Worker

Abstract

The AXIS Cloudflare Worker (frontend/worker/) is the edge data plane for the PWA: JSON APIs, optional script library (D1), API keys (KV), usage meters, and a WebSocket session relay (Durable Objects). It is not a full Pine interpreter in production today.

Honest runtime fact: POST /api/run proxies to EXTERNAL_BACKEND (typically Flask) unless PYODIDE_IN_WORKER=enabled and the in-worker path succeeds. In-worker Pyodide is planned / feature-gated — see Runtime and frontend/worker/RUNTIME.md.

Conceptual model

Infrastructure names (frozen)

SurfaceValue
Wrangler / Pages projectpynescript-superchartdo not rename lightly
npm packagepynescript-superchart-worker
Health JSON servicepynescript-axis-worker
Product brandAXIS

Custom domains / aliases may say axis.*; leave the CF project id stable so KV/D1 IDs and CI stay valid.

Interface surface

PathMethodRole
/, /healthGETHealth + feature flags (scripts, d1, keys)
/api/runPOSTRun script (proxy / gated Pyodide)
/api/keysGET/POSTValidate / create keys (X-Admin-Token for create)
/api/usageGETUsage stub / KV-backed counters
/api/scriptsCRUDScript library (Bearer)
/api/streamWSSession DO relay

Entry: frontend/worker/src/index.ts.

Local entrypoints

cd frontend/worker
npm install   # or bun install
npm run dev   # wrangler dev → http://127.0.0.1:8787

Makefile: make worker-dev, make worker-deploy.

Implementation status

FeatureStatus
/api/runEXTERNAL_BACKENDWorks today
Admin /api/keysWorks (KV or shape-check)
Usage KV increment on runWorks when USAGE bound
SessionDO + /api/streamImplemented; binding often commented until provisioned
/api/scripts + D1 schemaImplemented; memory fallback without D1
Pyodide scaffoldpyodide_runtime.ts + flag; wheel pipeline incomplete
Response cache for /api/runDeferred

Page map

PageTopic
Runtime/api/run, proxy, Pyodide plan
Durable ObjectsStream fan-out
Data planeScripts, D1, drafts
AuthBearer keys, admin token
Bindingswrangler.toml, vars, provision

See also