import { type Server } from "node:http"; import { type Config, type ConfigRef } from "./config.js"; import { type DeliveryLog } from "./delivery-log.js"; import { type Secrets } from "./env.js"; import { type Events } from "./events.js"; import type { LinkStatusView } from "./cloud/link.js"; import type { HealthCache } from "./health.js"; import type { ReadinessCache } from "./readiness.js"; import { type ServiceStatus } from "./service.js"; import { type ApplyUpdateResult } from "./update.js"; import { type JobRecord, type JobStore } from "./jobs.js"; import type { Logger } from "./logger.js"; import type { JobQueue } from "./queue.js"; import type { SkillRegistry } from "./registry.js"; import { type Scheduler, type ScheduleStatus } from "./scheduler.js"; import { type Skill } from "./skills.js"; import type { DaemonSentry } from "./sentry.js"; import type { Paths } from "./paths.js"; export interface ServerDeps { config: Config; paths: Paths; store: JobStore; queue: JobQueue; registry: SkillRegistry; secrets: () => Secrets; logger: Logger; /** Optional daemon-only error reporter; never receives request or job data. */ sentry?: Pick; /** Live schedule state for `/health` (admin); absent when the server runs without a scheduler. */ schedules?: () => ScheduleStatus[]; /** `POST /schedules//pause` and `/resume` (the running scheduler; absent means 404). */ scheduleControl?: Pick; /** The cached health report behind `GET /health/checks` and `GET /doctor` (built by `serve`; absent means 404). */ health?: HealthCache; /** Runner readiness behind `GET /runners` (the queue's pre-flight shares it). */ readiness?: ReadinessCache; /** The live config behind `GET /config`, `PATCH /config` and `POST /config/reload` (built by `serve`). */ configRef?: ConfigRef; /** `POST /control/restart` (built by `serve`; absent means 404). */ control?: ServerControl; /** The cloud link's status for `GET /health` (admin), when `serve` runs one. */ cloud?: () => LinkStatusView | undefined; /** Injectable for tests: the launchd / systemd status and the service log behind `GET /service` and `GET /logs`. */ serviceStatus?: () => Promise; serviceLog?: (lines: number) => string; /** Injectable for tests: the update check and install behind `POST /update`. */ applyUpdate?: (options: { install: boolean; }) => Promise; /** The process-wide event bus: `GET /events` streams it and `GET /jobs//events` follows one job on it. */ events?: Events; /** Where every `/hooks/` request is recorded; `GET /deliveries` reads it. Absent: nothing is recorded. */ deliveryLog?: DeliveryLog; } export interface ServerState { pid: number; host: string; port: number; started_at: string; version: string; public_url?: string; } /** Fixed-window counter per key; good enough to blunt brute force and accidental floods. */ export declare class RateLimiter { private readonly windowMs; private buckets; private readonly limit; constructor(limit: number | (() => number), windowMs?: number); hit(key: string, now?: number): boolean; } /** What `POST /control/restart` needs from `serve`: whether a supervisor brings the server back, and the stop itself. */ export interface ServerControl { supervised(): Promise; /** Pauses dispatch and exits 0 only after running jobs finish; resumes on timeout. Force terminates jobs. Called after the response was sent. */ restart(options: { force: boolean; waitSeconds: number; }): void; } export declare function publicJob(job: JobRecord): Record; export declare function skillSummary(skill: Skill, config: Config, secrets: Secrets): Record; export declare function createServer(deps: ServerDeps): Server; export declare function writeServerState(paths: Paths, state: ServerState): void; export declare function clearServerState(paths: Paths): void;