import type { Logger } from "pino"; import type { AutomationManager } from "../automation-manager.js"; import type { AggregateDeviceSource } from "../device-sources/aggregate.js"; import type { DeviceVisibility } from "../device-visibility.js"; import type { EventBus } from "../events/event-bus.js"; import type { LogBuffer } from "../logging/log-buffer.js"; import type { MqttService } from "../mqtt/mqtt-service.js"; import type { RoomManager } from "../room-manager.js"; import type { ServiceRegistry } from "../services/service-registry.js"; import { type StateManager } from "../state/state-manager.js"; /** * Handler function for a registered webhook. * @internal */ export type WebhookHandler = (context: { method: string; headers: Record; query: Record; body: unknown; }) => Promise; /** * HTTP server for health probes, readiness checks, webhook triggers, * and the unified API. * * Public endpoints (no authentication required): * - `GET /healthz` — Liveness probe * - `GET /readyz` — Readiness probe * - `POST /webhook/` — Webhook triggers * * Authenticated endpoints (Bearer token or session cookie): * - `GET /api/status` — Engine and MQTT status * - `GET /api/automations` — List all automations * - `GET /api/automations/:name` — Get automation details * - `PUT /api/automations/:name/enabled` — Enable or disable an automation * - `GET /api/automations/:name/source` — Read the automation's source file * - `GET /api/automations/:name/history` — Execution history (start time, trigger, duration, outcome) * - `GET /api/automations/:name/relationships` — Declared and observed relationships * - `POST /api/automations/:name/trigger` — Manually trigger an automation * - `GET /api/state` — List all state keys and values * - `GET /api/state/:key` — Get a single state value * - `PUT /api/state/:key` — Set a state value * - `DELETE /api/state/:key` — Delete a state key * - `GET /api/logs` — Query log buffer * - `GET /api/device-catalog` — List devices from every available source * - `GET /api/device-catalog/:qualifiedId` — Get a single device by qualified id * - `POST /api/device-catalog/:qualifiedId/command` — Issue a validated command to a device * - `PUT /api/device-catalog/:qualifiedId/room` — Assign a device to a room * - `DELETE /api/device-catalog/:qualifiedId/room` — Clear a device's room assignment * - `PUT /api/device-catalog/:qualifiedId/hidden` — Mark a device hidden * - `DELETE /api/device-catalog/:qualifiedId/hidden` — Mark a device visible * - `GET /api/rooms` — List rooms with membership * - `GET /api/rooms/unassigned` — Devices belonging to no room * - `POST /api/rooms` — Create a room * - `PUT /api/rooms/:id` — Rename a room * - `DELETE /api/rooms/:id` — Delete a room * - `GET /api/events` — Realtime server-sent event stream * * `GET /api/devices` and `GET /api/devices/:friendlyName` (Zigbee-only) are * removed rather than repurposed (design.md R13) — see `/api/device-catalog`. * * Uses `Bun.serve()` backed by a Hono router. * * @internal */ export declare class HttpServer { private readonly port; private readonly mqtt; private readonly token; private readonly logger; private server; private engineStarted; startedAt: number | null; private readonly webhookRoutes; private stateManager; private automationManager; private logBuffer; private deviceSources; private roomManager; private deviceVisibility; private eventStreamHub; private readonly honoApp; constructor(port: number, mqtt: MqttService, token: string, logger: Logger); /** * Set references to managers for the API. * Called by the engine after construction. */ setManagers(state: StateManager, automations: AutomationManager, logs: LogBuffer): void; /** * Wire the unified device catalog endpoints (`/api/device-catalog`, * `/api/device-catalog/:qualifiedId`) to the engine's aggregate device * accessor. Called by the engine after construction; `engine.devices` is * always present, so this is called unconditionally rather than passed * `null` for an unconfigured deployment (task 6.13a). */ setDeviceSources(sources: AggregateDeviceSource): void; /** * Wire the room endpoints (`/api/rooms`, `/api/device-catalog/:qualifiedId/room`) * to the engine's room manager. Called by the engine after construction; * `engine.rooms` is always present, so this is called unconditionally * (task 9.6). */ setRoomManager(rooms: RoomManager): void; /** * Wire the device visibility endpoints (`/api/device-catalog/:qualifiedId/hidden`) * to the engine's `DeviceVisibility`. Called by the engine after * construction; `engine.deviceVisibility` is always present, so this is * called unconditionally (task 5.1). */ setDeviceVisibility(visibility: DeviceVisibility): void; /** * Wire the realtime event stream's `/api/events` endpoint to the engine's * shared {@link EventBus}. * * `deliveryLogger` MUST be the stdout-only logger from `engine.ts` * (design.md D32) — never `this.logger` or any of its children — since the * delivery path's own logging (fan-out failures, overflow, the * fell-behind signal) must not be able to feed back into the log category * it delivers (task 5.0c). Connection accepted/closed logging uses * `this.logger` instead, so stream activity remains visible in the log * view even if delivery itself is failing. */ setEventStream(bus: EventBus, deliveryLogger: Logger): void; /** * Mark the engine as started. */ setEngineStarted(started: boolean): void; /** * Register web UI routes on the server's Hono app. * Lazily imports `registerWebUiRoutes` to keep the web UI tree-shakeable. * Must be called before `start()`. */ mountWebUi(path: string, token: string): Promise; /** * Call `registerRoutes(app)` on every `ServicePlugin` in the given registry * that implements it. Invoke before `start()` so routes are active when the * server starts listening. */ mountServiceRoutes(registry: ServiceRegistry): void; /** * Register a webhook route. */ registerWebhook(path: string, methods: string[], handler: WebhookHandler): void; /** * Remove a webhook route. */ removeWebhook(path: string): void; /** * Start the HTTP server. */ start(): void; /** * Stop the HTTP server. */ stop(): void; /** * Expose the underlying Hono app's fetch handler for direct use in tests * without starting a real `Bun.serve()` listener. */ get fetch(): (req: Request) => Response | Promise; private buildApp; } //# sourceMappingURL=http-server.d.ts.map