From 6a34a6f3c423a7c57616762eb4cea2b7da52eaf3 Mon Sep 17 00:00:00 2001 From: soryu Date: Sun, 22 Feb 2026 14:39:14 +0000 Subject: 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 --- makima/cloudflare-agent/src/index.ts | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 makima/cloudflare-agent/src/index.ts (limited to 'makima/cloudflare-agent/src/index.ts') 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 { + 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); + }, +}; -- cgit v1.2.3