Phase 11. Entities are mind-scoped nodes with canonical matching,
aliases and deterministic kind guessing (hostnames and hyphenated ids
are systems, capitalised names people, file suffixes documents).
Relationships carry a relation from the shared vocabulary, confidence,
source, reinforcement count and the event that produced them; links tie
entities to memories, beliefs, events, goals and predictions.
The perceive and attend handlers upsert the entities a message or
observation mentions and record co-mention edges cited to the event, so
the graph grows only from what was actually seen. Operators can merge
("these are the same": edges and links move, the old name becomes an
alias, the old id still resolves), record that two entities are
different, correct kinds and add typed edges; every correction is an
operator action and a corrections row.
The explorer renders a bounded subgraph on a canvas with a small
force-directed layout in plain JavaScript, with kind filters, focus on
a neighbourhood and a side panel per entity. API, entity page, CLI and
docs/graph.md.
71 lines
2.4 KiB
Go
71 lines
2.4 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
|
|
"github.com/andydixon/noema/internal/app"
|
|
"github.com/andydixon/noema/internal/auth"
|
|
)
|
|
|
|
// Server composes the API routes, the web UI and the middleware chain.
|
|
type Server struct {
|
|
deps app.Deps
|
|
mux *http.ServeMux
|
|
}
|
|
|
|
// New builds the server. ui registers the HTML routes on the same mux so that
|
|
// a single middleware chain (auth, CSRF, headers, limits) covers both.
|
|
func New(deps app.Deps, ui interface{ Register(*http.ServeMux) }) *Server {
|
|
s := &Server{deps: deps, mux: http.NewServeMux()}
|
|
s.routes()
|
|
if ui != nil {
|
|
ui.Register(s.mux)
|
|
}
|
|
return s
|
|
}
|
|
|
|
// Handler returns the fully wrapped root handler.
|
|
func (s *Server) Handler() http.Handler {
|
|
return chain(s.mux, s.requestID, s.recoverer, s.securityHeaders, s.bodyLimit, s.logging, s.deps.Auth.Middleware)
|
|
}
|
|
|
|
func (s *Server) routes() {
|
|
m := s.mux
|
|
m.HandleFunc("GET /healthz", s.healthz)
|
|
m.HandleFunc("GET /readyz", s.readyz)
|
|
// Metrics need a token with at least observer role; Prometheus supports bearer_token.
|
|
m.Handle("GET /metrics", require(auth.RoleObserver, promhttp.HandlerFor(s.deps.Metrics.Registry, promhttp.HandlerOpts{}).ServeHTTP))
|
|
|
|
m.Handle("GET /api/v1/system/status", require(auth.RoleObserver, s.systemStatus))
|
|
m.Handle("GET /api/v1/audit", require(auth.RoleOperator, s.auditList))
|
|
|
|
m.Handle("GET /api/v1/users", require(auth.RoleAdministrator, s.usersList))
|
|
m.Handle("POST /api/v1/users", require(auth.RoleAdministrator, s.usersCreate))
|
|
m.Handle("PATCH /api/v1/users/{id}", require(auth.RoleAdministrator, s.usersPatch))
|
|
m.Handle("GET /api/v1/me", require(auth.RoleObserver, s.me))
|
|
m.Handle("GET /api/v1/me/sessions", require(auth.RoleObserver, s.mySessions))
|
|
m.Handle("DELETE /api/v1/me/sessions/{id}", require(auth.RoleObserver, s.mySessionRevoke))
|
|
m.Handle("POST /api/v1/me/tokens", require(auth.RoleObserver, s.myTokenCreate))
|
|
m.Handle("GET /api/v1/me/tokens", require(auth.RoleObserver, s.myTokens))
|
|
m.Handle("DELETE /api/v1/me/tokens/{id}", require(auth.RoleObserver, s.myTokenRevoke))
|
|
|
|
s.mindRoutes()
|
|
s.eventRoutes()
|
|
s.workspaceRoutes()
|
|
s.memoryRoutes()
|
|
s.beliefRoutes()
|
|
s.llmRoutes()
|
|
s.promptRoutes()
|
|
s.conversationRoutes()
|
|
s.importRoutes()
|
|
s.motivationRoutes()
|
|
s.cognitionRoutes()
|
|
s.graphRoutes()
|
|
|
|
m.HandleFunc("/api/", func(w http.ResponseWriter, r *http.Request) {
|
|
writeError(w, r, http.StatusNotFound, "not_found", "no such endpoint")
|
|
})
|
|
}
|