mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-06-10 12:10:53 +00:00
75c570e951
- Secure CLI credential injection via AES-256-GCM encrypted env vars - API key management with fine-grained RBAC scopes - resolveAuth/requireAuth middleware across all 25+ HTTP handlers - In-memory API key cache with TTL, negative caching, pubsub invalidation - Sandbox-first execution (fails if unavailable, no silent fallback) - Credential scrubbing, constant-time token comparison, Admin-only CLI creds - SQL migration 000020: secure_cli_binaries + api_keys tables - 14 unit tests for cache and RBAC with race detector Closes #197
50 lines
2.0 KiB
Go
50 lines
2.0 KiB
Go
package http
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
kg "github.com/nextlevelbuilder/goclaw/internal/knowledgegraph"
|
|
"github.com/nextlevelbuilder/goclaw/internal/providers"
|
|
"github.com/nextlevelbuilder/goclaw/internal/store"
|
|
)
|
|
|
|
// KnowledgeGraphHandler handles KG entity/relation management endpoints.
|
|
type KnowledgeGraphHandler struct {
|
|
store store.KnowledgeGraphStore
|
|
providerReg *providers.Registry
|
|
token string
|
|
}
|
|
|
|
// NewKnowledgeGraphHandler creates a handler for KG management endpoints.
|
|
func NewKnowledgeGraphHandler(s store.KnowledgeGraphStore, providerReg *providers.Registry, token string) *KnowledgeGraphHandler {
|
|
return &KnowledgeGraphHandler{store: s, providerReg: providerReg, token: token}
|
|
}
|
|
|
|
// NewExtractor creates an Extractor from the given provider name and model.
|
|
func (h *KnowledgeGraphHandler) NewExtractor(providerName, model string, minConfidence float64) *kg.Extractor {
|
|
if h.providerReg == nil || providerName == "" || model == "" {
|
|
return nil
|
|
}
|
|
p, err := h.providerReg.Get(providerName)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return kg.NewExtractor(p, model, minConfidence)
|
|
}
|
|
|
|
// RegisterRoutes registers all KG routes on the given mux.
|
|
func (h *KnowledgeGraphHandler) RegisterRoutes(mux *http.ServeMux) {
|
|
mux.HandleFunc("GET /v1/agents/{agentID}/kg/entities", h.auth(h.handleListEntities))
|
|
mux.HandleFunc("GET /v1/agents/{agentID}/kg/entities/{entityID}", h.auth(h.handleGetEntity))
|
|
mux.HandleFunc("POST /v1/agents/{agentID}/kg/entities", h.auth(h.handleUpsertEntity))
|
|
mux.HandleFunc("DELETE /v1/agents/{agentID}/kg/entities/{entityID}", h.auth(h.handleDeleteEntity))
|
|
mux.HandleFunc("POST /v1/agents/{agentID}/kg/traverse", h.auth(h.handleTraverse))
|
|
mux.HandleFunc("POST /v1/agents/{agentID}/kg/extract", h.auth(h.handleExtract))
|
|
mux.HandleFunc("GET /v1/agents/{agentID}/kg/stats", h.auth(h.handleStats))
|
|
mux.HandleFunc("GET /v1/agents/{agentID}/kg/graph", h.auth(h.handleGraph))
|
|
}
|
|
|
|
func (h *KnowledgeGraphHandler) auth(next http.HandlerFunc) http.HandlerFunc {
|
|
return requireAuth(h.token, "", next)
|
|
}
|