antcolony
All repositories: gitoria
1.0 KB
// AgentServer.hl — the scheduler's door for its agents (mission 035, antcolony#14): a tiny HTTP server (hl:http1) that// hands every request to `handler(method, path, body, authorization)` and answers { status, body } as JSON. As a class// file, so the daemon can give it a closure over its own state: `new AgentServer(port = …, host = …, handler = fn)`.// Hybriel has no WebSocket CLIENT (hybriel#109), so agents connect OUT with plain HTTPS requests (agent.hl): the agent// asks, the scheduler answers — no connection is held open, a dropped one breaks nothing.import { NativeHttpServer, Response } from 'hl:http1'Number port = 0String host = '127.0.0.1'Function handler = nullhttp = new NativeHttpServer(port = port, host = host)on http.request(req) {let auth = req.headers['authorization']if (auth == null) { auth = req.headers['Authorization'] }let out = handler(req.method, req.path, req.body, auth)return new Response(JSON.stringify(out.body), { status = out.status headers = { 'Content-Type' = 'application/json' } })}
Branches
- mainmain branch