diff options
| author | soryu <soryu@soryu.co> | 2026-02-22 14:39:14 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-22 14:39:14 +0000 |
| commit | 6a34a6f3c423a7c57616762eb4cea2b7da52eaf3 (patch) | |
| tree | 7c596eac896918466e7ef3f149b02333fef09212 /makima/cloudflare-agent/src/index.ts | |
| parent | 0523765af84492640928d571f481e17b26008b13 (diff) | |
| download | soryu-6a34a6f3c423a7c57616762eb4cea2b7da52eaf3.tar.gz soryu-6a34a6f3c423a7c57616762eb4cea2b7da52eaf3.zip | |
feat: Add daemon page with download binary and Cloudflare Agent setup (#77)
* feat: soryu-co/soryu - makima: Create DaemonList and DaemonDetail page components
* feat: soryu-co/soryu - makima: Add daemon page routes, CSS styles, and navigation
* feat: soryu-co/soryu - makima: Create daemon page with download and monitoring
* WIP: heartbeat checkpoint
* WIP: heartbeat checkpoint
* feat: soryu-co/soryu - makima: Integrate Cloudflare Agent setup into daemon page
Diffstat (limited to 'makima/cloudflare-agent/src/index.ts')
| -rw-r--r-- | makima/cloudflare-agent/src/index.ts | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/makima/cloudflare-agent/src/index.ts b/makima/cloudflare-agent/src/index.ts new file mode 100644 index 0000000..0b64af4 --- /dev/null +++ b/makima/cloudflare-agent/src/index.ts @@ -0,0 +1,47 @@ +/** + * Makima Cloudflare Agent — Worker Entry Point + * + * Routes incoming requests to the MakimaAgent Durable Object which manages + * the upstream WebSocket connection to the Makima server and relays tasks + * to downstream native daemon instances. + * + * Routes: + * GET / → Agent status (JSON) + * GET /status → Agent status (JSON) + * GET /health → Health check + * GET /tasks → Task history (paginated) + * GET /logs → Connection logs + * POST /reconnect → Force upstream reconnection + * * /ws → WebSocket upgrade for downstream daemons + * * /agent/* → Forwarded to Agent's onRequest handler + */ + +import { MakimaAgent } from "./agent"; +import type { Env } from "./types"; + +export { MakimaAgent }; + +export default { + async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> { + const url = new URL(request.url); + + // Use a singleton Durable Object — all traffic routes to one agent + // instance identified by a fixed name. This ensures a single persistent + // upstream WebSocket to the Makima server. + const agentId = env.MAKIMA_AGENT.idFromName("makima-relay-primary"); + const agent = env.MAKIMA_AGENT.get(agentId); + + // WebSocket upgrade path — downstream daemons connect here + if (url.pathname === "/ws" || url.pathname === "/ws/daemon") { + const upgradeHeader = request.headers.get("Upgrade"); + if (upgradeHeader !== "websocket") { + return new Response("Expected WebSocket upgrade", { status: 426 }); + } + // Forward the WebSocket upgrade to the Durable Object + return agent.fetch(request); + } + + // All other routes are forwarded to the Durable Object's onRequest handler + return agent.fetch(request); + }, +}; |
