package api import ( "net/http" "time" ) func handleHealth() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { writeJSON(w, http.StatusOK, map[string]any{ "status": "ok", "server_time": time.Now().UTC().Format(time.RFC3339Nano), }) } } func handleStatus(stores Stores) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { counts, _ := stores.Instructions.Counts() latest, _ := stores.Agents.Latest() cfg, _ := stores.Settings.Get() resp := map[string]any{ "uptime_seconds": int(time.Since(serverStartTime).Seconds()), "queue_pending": counts.PendingCount, "queue_consumed": counts.ConsumedCount, "agent_stale_after_seconds": cfg.AgentStaleAfterSeconds, } if latest != nil { isStale := time.Since(latest.LastSeenAt).Seconds() > float64(cfg.AgentStaleAfterSeconds) resp["agent"] = map[string]any{ "agent_id": latest.AgentID, "last_fetch_at": latest.LastFetchAt.Format(time.RFC3339Nano), "last_result_type": latest.LastResultType, "is_stale": isStale, } } writeJSON(w, http.StatusOK, resp) } }