Documentation
¶
Overview ¶
Package server provides the HTTP API server, middleware, and handlers for Talon.
Package server provides HTTP API handlers; this file adds CoPaw-specific dashboard and stats.
Index ¶
- func AdminKeyMiddleware(adminKey string) func(http.Handler) http.Handler
- func CORSMiddleware(allowedOrigins []string) func(http.Handler) http.Handler
- func IsAdminFromContext(ctx context.Context) bool
- func RateLimitMiddleware(tm *tenant.Manager) func(http.Handler) http.Handler
- func SetTenantID(ctx context.Context, tenantID string) context.Context
- func TenantIDFromContext(ctx context.Context) string
- func TenantKeyMiddleware(tenantKeys map[string]string) func(http.Handler) http.Handler
- func TenantOrAdminMiddleware(tenantKeys map[string]string, adminKey string) func(http.Handler) http.Handler
- type Option
- func WithActiveRunTracker(tracker *agent.ActiveRunTracker) Option
- func WithCORSOrigins(origins []string) Option
- func WithDashboard(html string) Option
- func WithGateway(h http.Handler) Option
- func WithGatewayDashboard(html string) Option
- func WithGraphEventsHandler(pe *policy.Engine, eg *evidence.Generator, es *evidence.Store) Option
- func WithMCPProxy(h http.Handler) Option
- func WithMCPServer(h http.Handler) Option
- func WithMemoryStore(m *memory.Store) Option
- func WithMetricsCollector(c *metrics.Collector) Option
- func WithOverrideStore(os *agent.OverrideStore) Option
- func WithPlanReviewStore(pr *agent.PlanReviewStore) Option
- func WithRunRegistry(rr *agent.RunRegistry) Option
- func WithSessionStore(ss *session.Store) Option
- func WithTenantManager(tm *tenant.Manager) Option
- func WithToolApprovalStore(tas *agent.ToolApprovalStore) Option
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AdminKeyMiddleware ¶
AdminKeyMiddleware returns a middleware that validates X-Talon-Admin-Key (or Authorization: Bearer fallback) against the configured admin key.
func CORSMiddleware ¶
CORSMiddleware returns a middleware that sets CORS headers. allowedOrigins can be ["*"] for any.
func IsAdminFromContext ¶
IsAdminFromContext returns true when the request is authenticated as admin.
func RateLimitMiddleware ¶
RateLimitMiddleware returns a middleware that calls tenantManager.ValidateRequest(tenantID) and returns 429 with Retry-After and X-RateLimit-* headers when exceeded.
func SetTenantID ¶
SetTenantID stores tenant_id in the request context.
func TenantIDFromContext ¶
TenantIDFromContext returns the tenant_id from context, or "" if not set.
func TenantKeyMiddleware ¶
TenantKeyMiddleware returns a middleware that validates Authorization: Bearer <tenant_key> and sets tenant_id in context. tenantKeys maps key -> tenant_id.
func TenantOrAdminMiddleware ¶
func TenantOrAdminMiddleware(tenantKeys map[string]string, adminKey string) func(http.Handler) http.Handler
TenantOrAdminMiddleware allows either an admin key or tenant key. Admin auth checks X-Talon-Admin-Key first, then Bearer fallback. Tenant auth checks Authorization: Bearer <tenant_key>.
Types ¶
type Option ¶
type Option func(*Server)
Option configures the Server.
func WithActiveRunTracker ¶
func WithActiveRunTracker(tracker *agent.ActiveRunTracker) Option
WithActiveRunTracker sets the in-flight run tracker for status/dashboard active_runs.
func WithCORSOrigins ¶
WithCORSOrigins sets allowed CORS origins (e.g. ["*"] for MVP).
func WithDashboard ¶
WithDashboard sets the embedded dashboard HTML.
func WithGateway ¶
WithGateway sets the LLM API gateway handler (optional). Mounted at /v1/proxy/* with its own caller auth.
func WithGatewayDashboard ¶
WithGatewayDashboard sets the embedded gateway dashboard HTML.
func WithGraphEventsHandler ¶ added in v1.4.5
WithGraphEventsHandler sets the handler for external graph runtime governance events.
func WithMCPProxy ¶
WithMCPProxy sets the MCP proxy handler (optional).
func WithMCPServer ¶
WithMCPServer sets the native MCP handler.
func WithMemoryStore ¶
WithMemoryStore sets the memory store (optional).
func WithMetricsCollector ¶
WithMetricsCollector sets the metrics collector for the gateway dashboard API.
func WithOverrideStore ¶
func WithOverrideStore(os *agent.OverrideStore) Option
WithOverrideStore sets the override store for runtime policy overrides and tenant lockdown.
func WithPlanReviewStore ¶
func WithPlanReviewStore(pr *agent.PlanReviewStore) Option
WithPlanReviewStore sets the plan review store for EU AI Act Art. 14.
func WithRunRegistry ¶
func WithRunRegistry(rr *agent.RunRegistry) Option
WithRunRegistry sets the run registry for lifecycle tracking and control endpoints.
func WithSessionStore ¶
WithSessionStore sets the session store (optional).
func WithTenantManager ¶
WithTenantManager sets the tenant manager for rate limiting and budgets.
func WithToolApprovalStore ¶
func WithToolApprovalStore(tas *agent.ToolApprovalStore) Option
WithToolApprovalStore sets the tool approval store for pre-tool human-in-the-loop gates.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server holds all dependencies for the HTTP API and MCP endpoints.
func NewServer ¶
func NewServer( runner *agent.Runner, evidenceStore *evidence.Store, webhookHandler *trigger.WebhookHandler, policyEngine *policy.Engine, policy *policy.Policy, policyPath string, secretsStore *secrets.SecretStore, adminKey string, tenantKeys map[string]string, opts ...Option, ) *Server
NewServer builds a Server with the required dependencies and optional Option(s).