server

package
v1.4.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdminKeyMiddleware

func AdminKeyMiddleware(adminKey string) func(http.Handler) http.Handler

AdminKeyMiddleware returns a middleware that validates X-Talon-Admin-Key (or Authorization: Bearer fallback) against the configured admin key.

func CORSMiddleware

func CORSMiddleware(allowedOrigins []string) func(http.Handler) http.Handler

CORSMiddleware returns a middleware that sets CORS headers. allowedOrigins can be ["*"] for any.

func IsAdminFromContext

func IsAdminFromContext(ctx context.Context) bool

IsAdminFromContext returns true when the request is authenticated as admin.

func RateLimitMiddleware

func RateLimitMiddleware(tm *tenant.Manager) func(http.Handler) http.Handler

RateLimitMiddleware returns a middleware that calls tenantManager.ValidateRequest(tenantID) and returns 429 with Retry-After and X-RateLimit-* headers when exceeded.

func SetTenantID

func SetTenantID(ctx context.Context, tenantID string) context.Context

SetTenantID stores tenant_id in the request context.

func TenantIDFromContext

func TenantIDFromContext(ctx context.Context) string

TenantIDFromContext returns the tenant_id from context, or "" if not set.

func TenantKeyMiddleware

func TenantKeyMiddleware(tenantKeys map[string]string) func(http.Handler) http.Handler

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

func WithCORSOrigins(origins []string) Option

WithCORSOrigins sets allowed CORS origins (e.g. ["*"] for MVP).

func WithDashboard

func WithDashboard(html string) Option

WithDashboard sets the embedded dashboard HTML.

func WithGateway

func WithGateway(h http.Handler) Option

WithGateway sets the LLM API gateway handler (optional). Mounted at /v1/proxy/* with its own caller auth.

func WithGatewayDashboard

func WithGatewayDashboard(html string) Option

WithGatewayDashboard sets the embedded gateway dashboard HTML.

func WithGraphEventsHandler added in v1.4.5

func WithGraphEventsHandler(pe *policy.Engine, eg *evidence.Generator, es *evidence.Store) Option

WithGraphEventsHandler sets the handler for external graph runtime governance events.

func WithMCPProxy

func WithMCPProxy(h http.Handler) Option

WithMCPProxy sets the MCP proxy handler (optional).

func WithMCPServer

func WithMCPServer(h http.Handler) Option

WithMCPServer sets the native MCP handler.

func WithMemoryStore

func WithMemoryStore(m *memory.Store) Option

WithMemoryStore sets the memory store (optional).

func WithMetricsCollector

func WithMetricsCollector(c *metrics.Collector) Option

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

func WithSessionStore(ss *session.Store) Option

WithSessionStore sets the session store (optional).

func WithTenantManager

func WithTenantManager(tm *tenant.Manager) Option

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).

func (*Server) Routes

func (s *Server) Routes() http.Handler

Routes returns the configured http.Handler (chi router with all middleware and routes). Long-running routes (/v1/agents/run, /v1/chat/completions) are registered without the default request timeout so handler-level 30-minute timeouts take effect.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL