Files
memoryweave/go/internal/api/routes/conflicts.go
T
xiaowei 2a350cf781 fix(distill): max_tokens 800→1200 — Agnes推理token预算不足
Agnes 2.0-flash是推理模型,推理token占大量预算。
800仍不够→JSON截断(parse error: unexpected end of JSON input)。
1200确保推理+正文都够用。
2026-08-20 01:13:06 +08:00

60 lines
1.6 KiB
Go

// 织忆 MemoryWeave — 冲突管理 API
package routes
import (
"encoding/json"
"net/http"
"github.com/xiaoxue/memoryweave/internal/governance"
"github.com/xiaoxue/memoryweave/internal/selfoptimize"
)
type ConflictAPI struct {
Detector *governance.ConflictDetector
}
func NewConflictAPI(d *governance.ConflictDetector) *ConflictAPI {
return &ConflictAPI{Detector: d}
}
// GET /api/v1/conflicts
func (ca *ConflictAPI) List(w http.ResponseWriter, r *http.Request) {
list := ca.Detector.ListActive()
pending := 0
for _, c := range list {
if c.Status == "pending" {
pending++
}
}
respond(w, 200, map[string]interface{}{
"conflicts": list, "count": len(list), "pending": pending,
})
}
// POST /api/v1/conflicts/resolve
func (ca *ConflictAPI) Resolve(w http.ResponseWriter, r *http.Request) {
var req struct {
ConflictID string `json:"conflict_id"`
Resolution string `json:"resolution"` // keep_left / keep_right / merge / dismiss
Winner string `json:"winner"` // id of the winning memory
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
respondError(w, 400, "invalid body")
return
}
if req.ConflictID == "" || req.Resolution == "" {
respondError(w, 400, "conflict_id and resolution required")
return
}
err := ca.Detector.Resolve(req.ConflictID, req.Resolution, req.Winner)
if err != nil {
respondError(w, 500, "resolve failed: "+err.Error())
return
}
selfoptimize.Dash.RecordConflictResolved(true)
PushConflictResolved("system", req.ConflictID, req.Resolution)
respond(w, 200, map[string]string{"status": "resolved", "conflict_id": req.ConflictID})
}