Files
synapbus/internal/api/trust_handler.go
T
Algis DumbrisandClaude Opus 4.6 8df22457ab feat: trust scores, claim semantics, state-change webhooks (011-trust-claims-triggers)
Trust scores: per (agent, action_type) pair, stored in agent_trust
table. Auto-adjusts when human reacts to AI agent messages (approve
+0.05, reject -0.1). Scores clamped [0.0, 1.0]. MCP get_trust action
+ REST API /api/trust/{agent}. Web UI shows trust progress bars on
agent detail pages.

Claim semantics: only one in_progress reaction per message enforced.
First agent to claim wins, duplicates rejected with clear error.

State-change webhooks: StateChangeNotifier interface fires
workflow.state_changed events through existing webhook infrastructure
when reactions change a message's derived workflow state.

Channel thresholds: publish_threshold and approve_threshold fields
on channels for configuring autonomy gates.

Migration 014_trust_claims.sql. 17 new test cases across trust
model + store.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 21:41:54 +02:00

45 lines
1.1 KiB
Go

package api
import (
"log/slog"
"net/http"
"github.com/go-chi/chi/v5"
"github.com/synapbus/synapbus/internal/trust"
)
// TrustHandler handles REST API requests for agent trust scores.
type TrustHandler struct {
trustService *trust.Service
logger *slog.Logger
}
// NewTrustHandler creates a new trust handler.
func NewTrustHandler(trustService *trust.Service) *TrustHandler {
return &TrustHandler{
trustService: trustService,
logger: slog.Default().With("component", "api.trust"),
}
}
// GetScores handles GET /api/trust/{name}.
func (h *TrustHandler) GetScores(w http.ResponseWriter, r *http.Request) {
agentName := chi.URLParam(r, "name")
if agentName == "" {
writeJSON(w, http.StatusBadRequest, errorBody("invalid_name", "Agent name is required"))
return
}
scores, err := h.trustService.GetScores(r.Context(), agentName)
if err != nil {
h.logger.Error("failed to get trust scores", "agent", agentName, "error", err)
writeJSON(w, http.StatusInternalServerError, errorBody("internal", "Failed to get trust scores"))
return
}
writeJSON(w, http.StatusOK, map[string]any{
"scores": scores,
})
}