Fix small bugs across AI tools, fleet API, and run.bat.

Correct AI uptime/reinstall/sleep, broaden live stats over WebSocket, fix blueprint delete JSON, gate hollowing behind build tag, and stop stale server binds on restart.
This commit is contained in:
drjones
2026-05-28 08:00:01 -07:00
parent a9aeaefb1b
commit edffb03e00
9 changed files with 61 additions and 31 deletions

View File

@@ -114,14 +114,10 @@ func (h *AIHandler) RemoveEngine(agentID string) {
// GetEngine returns the engine for an agent.
func (h *AIHandler) GetEngine(agentID string) *ollama.Engine {
h.mu.RLock()
defer h.mu.RUnlock()
h.mu.Lock()
defer h.mu.Unlock()
if entry, ok := h.engines[agentID]; ok {
h.mu.RUnlock() // Briefly unlock to update timestamp
h.mu.Lock()
entry.lastUsed = time.Now()
h.mu.Unlock()
h.mu.RLock()
return entry.engine
}
return nil

View File

@@ -189,7 +189,7 @@ func (h *BlueprintHandler) deleteBlueprint(w http.ResponseWriter, r *http.Reques
return
}
writeJSON(w, map[string]string{"success": "true", "name": safeName})
writeJSON(w, map[string]interface{}{"success": true, "name": safeName})
}
func sanitizeFilename(name string) string {

View File

@@ -4,7 +4,6 @@ import (
"encoding/json"
"net/http"
"strconv"
"time"
"crypto-miner-server/internal/alerts"
"crypto-miner-server/internal/db"
@@ -70,7 +69,6 @@ func (f *FleetHandler) GetAgentLog(w http.ResponseWriter, r *http.Request) {
}
if r.URL.Query().Get("refresh") == "1" {
_ = f.ws.SendAgentCommand(id, "get_log", map[string]interface{}{"tail_lines": 300})
time.Sleep(800 * time.Millisecond)
}
writeJSON(w, map[string]interface{}{
"agent_id": id,
@@ -116,6 +114,15 @@ func (f *FleetHandler) PostAgentCommand(w http.ResponseWriter, r *http.Request)
}
if id == "all" {
if f.ws.connectedAgentCount() == 0 {
writeJSON(w, map[string]interface{}{
"success": false,
"error": "no connected agents",
"agent_id": id,
"action": req.Action,
})
return
}
f.ws.BroadcastAgentCommand(req.Action, args)
} else {
if err := f.ws.SendAgentCommand(id, req.Action, args); err != nil {

View File

@@ -21,10 +21,11 @@ func NewRouter(database *db.Database, wsHub *WSHub, configHandler *ConfigHandler
r.Use(middleware.Logger)
r.Use(middleware.Recoverer)
r.Use(cors.Handler(cors.Options{
AllowedOrigins: []string{"*"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type"},
AllowCredentials: true,
AllowedOrigins: []string{"*"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type"},
// With AllowedOrigins="*", credentials must be disabled (browsers will reject "*"+credentials).
AllowCredentials: false,
}))
// REST API

View File

@@ -370,11 +370,15 @@ func (h *WSHub) HandleAgentWS(w http.ResponseWriter, r *http.Request) {
h.broadcastDashboard(Message{
Type: "stats_update",
Payload: mustMarshal(map[string]interface{}{
"agent_id": agentID,
"hashrate_15s": stats.Hashrate15s,
"hashrate_1m": stats.Hashrate1m,
"hashrate_15m": stats.Hashrate15m,
"cpu_usage_pct": stats.CPUUsagePct,
"agent_id": agentID,
"hashrate_15s": stats.Hashrate15s,
"hashrate_1m": stats.Hashrate1m,
"hashrate_15m": stats.Hashrate15m,
"cpu_usage_pct": stats.CPUUsagePct,
"memory_usage_pct": stats.MemoryUsagePct,
"uptime_seconds": stats.UptimeSeconds,
"shares_submitted": stats.SharesSubmitted,
"shares_accepted": stats.SharesAccepted,
}),
})