admin

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ServeStatic

func ServeStatic(w http.ResponseWriter, r *http.Request)

ServeStatic serves static files from the embedded assets. Checks dist/assets/ first (compiled CSS/JS), then dist/ root (static files from Vite publicDir).

Types

type Admin

type Admin struct {
	// contains filtered or unexported fields
}

Admin handles admin UI requests

func New

func New(config *types.Config, getStats func() *Stats, getProviders func() []ProviderInfo, getMCPServers func() []MCPServerInfo, getMCPTools func(string) ([]ToolInfo, error), getMCPResources func(string) ([]ResourceInfo, error), getMCPPrompts func(string) ([]PromptInfo, error), getModels func() []ModelInfo, mcpStorage storage.MCPStorage, mcpStorageWritable bool, onMCPServerChange func(), onMCPCacheRefresh func()) *Admin

New creates a new Admin handler. Returns nil when the admin UI should be completely disabled: no password AND bound to a non-loopback address (i.e. network-accessible without auth = security risk).

When bound to localhost (127.0.0.1 / ::1) with no password, the admin UI is enabled with open access — safe for desktop mode and local-only dev. Set --admin-password to require login.

func (*Admin) ChatPageHandler added in v0.5.0

func (a *Admin) ChatPageHandler() http.HandlerFunc

ChatPageHandler returns the HTTP handler for /chat. Uses requirePageAuth (same admin session as every other page). One password, one role.

func (*Admin) Enabled

func (a *Admin) Enabled() bool

Enabled returns true if admin UI is enabled (admin password set).

func (*Admin) HandleCallMCPServerTool added in v0.5.1

func (a *Admin) HandleCallMCPServerTool(w http.ResponseWriter, r *http.Request)

HandleCallMCPServerTool executes a tool on a remote MCP server and returns the result for display in the admin UI. The popup stays open between calls, so the client may POST repeatedly with different arguments.

func (*Admin) HandleCreateMCPServer

func (a *Admin) HandleCreateMCPServer(w http.ResponseWriter, r *http.Request)

HandleCreateMCPServer creates a new MCP server

func (*Admin) HandleCreatePersona added in v0.5.1

func (a *Admin) HandleCreatePersona(w http.ResponseWriter, r *http.Request)

HandleCreatePersona creates a new persona in storage. The ID is derived from the name (sha256[:8]) so it's stable, URL-safe, and survives renames.

func (*Admin) HandleCreateProvider added in v0.5.0

func (a *Admin) HandleCreateProvider(w http.ResponseWriter, r *http.Request)

HandleCreateProvider creates a new provider in storage.

func (*Admin) HandleDashboard

func (a *Admin) HandleDashboard(w http.ResponseWriter, r *http.Request)

HandleDashboard renders the dashboard page

func (*Admin) HandleDeleteMCPServer

func (a *Admin) HandleDeleteMCPServer(w http.ResponseWriter, r *http.Request)

HandleDeleteMCPServer deletes an MCP server

func (*Admin) HandleDeletePersona added in v0.5.1

func (a *Admin) HandleDeletePersona(w http.ResponseWriter, r *http.Request)

HandleDeletePersona deletes a stored persona. File-based personas cannot be deleted from the UI.

func (*Admin) HandleDeleteProvider added in v0.5.0

func (a *Admin) HandleDeleteProvider(w http.ResponseWriter, r *http.Request)

HandleDeleteProvider deletes a stored provider.

func (*Admin) HandleGetMCPServer

func (a *Admin) HandleGetMCPServer(w http.ResponseWriter, r *http.Request)

HandleGetMCPServer returns a single MCP server

func (*Admin) HandleGetMCPServerPrompts added in v0.5.0

func (a *Admin) HandleGetMCPServerPrompts(w http.ResponseWriter, r *http.Request)

HandleGetMCPServerPrompts returns prompts for an MCP server. Like resources, prompts are read-only in the UI.

func (*Admin) HandleGetMCPServerResources added in v0.5.0

func (a *Admin) HandleGetMCPServerResources(w http.ResponseWriter, r *http.Request)

server. Resources are read-only in the UI — there is no storage-level toggle the way there is for tools.

func (*Admin) HandleGetMCPServerTools

func (a *Admin) HandleGetMCPServerTools(w http.ResponseWriter, r *http.Request)

HandleGetMCPServerTools returns tools for an MCP server

func (*Admin) HandleGetPersona added in v0.5.1

func (a *Admin) HandleGetPersona(w http.ResponseWriter, r *http.Request)

HandleGetPersona returns a single persona by ID. Checks the merged list from the router (file + stored) so a GET works regardless of source.

func (*Admin) HandleGetProvider added in v0.5.0

func (a *Admin) HandleGetProvider(w http.ResponseWriter, r *http.Request)

HandleGetProvider returns a single provider's config. Checks storage first, then falls back to static config from runtime info.

func (*Admin) HandleListMCPServers

func (a *Admin) HandleListMCPServers(w http.ResponseWriter, r *http.Request)

func (*Admin) HandleListPersonas added in v0.5.1

func (a *Admin) HandleListPersonas(w http.ResponseWriter, r *http.Request)

HandleListPersonas returns all personas (file-based + stored) for the management page. File-based personas are read-only; stored personas support full CRUD. Merging happens in the router's persona source so chat and admin see the same set.

func (*Admin) HandleListProviders added in v0.5.0

func (a *Admin) HandleListProviders(w http.ResponseWriter, r *http.Request)

HandleListProviders returns all providers (static + stored) for the management page. Static providers are read-only; stored providers support full CRUD.

func (*Admin) HandleLogin

func (a *Admin) HandleLogin(w http.ResponseWriter, r *http.Request)

HandleLogin handles login requests. One password, one session type.

func (*Admin) HandleLoginPage

func (a *Admin) HandleLoginPage(w http.ResponseWriter, r *http.Request)

HandleLoginPage renders the login page. If no password is set, redirects straight to the dashboard (no auth needed).

func (*Admin) HandleLogout

func (a *Admin) HandleLogout(w http.ResponseWriter, r *http.Request)

HandleLogout invalidates the session

func (*Admin) HandleMCPServersPage

func (a *Admin) HandleMCPServersPage(w http.ResponseWriter, r *http.Request)

HandleMCPServersPage renders the MCP servers page.

func (*Admin) HandleMCPStorageStatus

func (a *Admin) HandleMCPStorageStatus(w http.ResponseWriter, r *http.Request)

HandleMCPStorageStatus returns whether MCP server storage is writable

func (*Admin) HandleModels

func (a *Admin) HandleModels(w http.ResponseWriter, r *http.Request)

HandleModels returns model information

func (*Admin) HandleModelsPage

func (a *Admin) HandleModelsPage(w http.ResponseWriter, r *http.Request)

HandleModelsPage renders the models page

func (*Admin) HandleOAuthCallback

func (a *Admin) HandleOAuthCallback(w http.ResponseWriter, r *http.Request)

HandleOAuthCallback handles the redirect back from the OAuth2 server. GET /admin/oauth/callback

func (*Admin) HandleOAuthStart

func (a *Admin) HandleOAuthStart(w http.ResponseWriter, r *http.Request)

HandleOAuthStart initiates the PKCE flow for a new OAuth2 MCP server. POST /admin/api/mcp-servers/oauth/start

func (*Admin) HandlePersonasPage added in v0.5.1

func (a *Admin) HandlePersonasPage(w http.ResponseWriter, r *http.Request)

HandlePersonasPage renders the personas management page.

func (*Admin) HandleProviders

func (a *Admin) HandleProviders(w http.ResponseWriter, r *http.Request)

HandleProviders returns provider information

func (*Admin) HandleProvidersPage added in v0.5.0

func (a *Admin) HandleProvidersPage(w http.ResponseWriter, r *http.Request)

HandleProvidersPage renders the providers management page.

func (*Admin) HandleRefreshMCPCache added in v0.1.5

func (a *Admin) HandleRefreshMCPCache(w http.ResponseWriter, r *http.Request)

HandleRefreshMCPCache refreshes the tool cache from all remote MCP servers

func (*Admin) HandleRefreshModels added in v0.5.5

func (a *Admin) HandleRefreshModels(w http.ResponseWriter, r *http.Request)

HandleRefreshModels forces a rescan of models from all providers and returns the updated model list.

func (*Admin) HandleStats

func (a *Admin) HandleStats(w http.ResponseWriter, r *http.Request)

HandleStats returns dashboard statistics HandleStats returns dashboard statistics

func (*Admin) HandleToggleMCPServer

func (a *Admin) HandleToggleMCPServer(w http.ResponseWriter, r *http.Request)

HandleToggleMCPServer toggles an MCP server's enabled state

func (*Admin) HandleToggleMCPServerTool

func (a *Admin) HandleToggleMCPServerTool(w http.ResponseWriter, r *http.Request)

HandleToggleMCPServerTool toggles a tool's enabled state (lazy write)

func (*Admin) HandleToggleProvider added in v0.5.5

func (a *Admin) HandleToggleProvider(w http.ResponseWriter, r *http.Request)

HandleToggleProvider toggles a stored provider's enabled state.

func (*Admin) HandleUpdateMCPServer

func (a *Admin) HandleUpdateMCPServer(w http.ResponseWriter, r *http.Request)

HandleUpdateMCPServer updates an MCP server

func (*Admin) HandleUpdatePersona added in v0.5.1

func (a *Admin) HandleUpdatePersona(w http.ResponseWriter, r *http.Request)

HandleUpdatePersona updates a stored persona. The "default" persona is special: it may not exist in storage yet (it starts as a synthetic entry), so the first edit creates it (upsert). Its name is always "Default" and cannot be changed. File-based personas are immutable from the UI.

func (*Admin) HandleUpdateProvider added in v0.5.0

func (a *Admin) HandleUpdateProvider(w http.ResponseWriter, r *http.Request)

HandleUpdateProvider updates a stored provider.

func (*Admin) HandleWatch added in v0.8.0

func (a *Admin) HandleWatch(w http.ResponseWriter, r *http.Request)

HandleWatch is the SSE endpoint at GET /admin/api/watch. Connected clients receive a real-time stream of LLM request/response events. The connection stays open until the client disconnects (closing the overlay in the browser). When the last client disconnects, the watcher deactivates and the router stops serializing events — zero overhead in normal operation.

func (*Admin) RegisterRoutes

func (a *Admin) RegisterRoutes(mux *http.ServeMux)

RegisterRoutes registers admin routes on the given mux. Routes are always registered. When no admin password is set, the auth middleware allows open access — intended for desktop mode and local-only deployments. Set --admin-password to require authentication.

func (*Admin) RequireAuthMiddleware added in v0.5.0

func (a *Admin) RequireAuthMiddleware() func(http.Handler) http.Handler

RequireAuthMiddleware returns an http.Handler middleware that checks for a valid session. Used by lmchatkit to gate its API + asset routes with the same admin session as the rest of the app. Returns nil if no admin password is set (open access — for local dev behind a reverse proxy).

func (*Admin) Serve404 added in v0.1.2

func (a *Admin) Serve404(w http.ResponseWriter, r *http.Request)

Serve404 renders the 404 page

func (*Admin) SetMCPToolCaller added in v0.5.1

func (a *Admin) SetMCPToolCaller(fn func(namespace, toolName string, args map[string]any) (*ToolCallResult, error))

SetMCPToolCaller wires live tool execution from the admin UI. Called after New but before RegisterRoutes. If fn is nil, the tool-call endpoint returns 503 (tool execution not available).

func (*Admin) SetPersonaStorage added in v0.5.1

func (a *Admin) SetPersonaStorage(ps storage.PersonaStorage, writable bool, onChange func(), getPersonas func() []PersonaInfo)

SetPersonaStorage wires dynamic persona management. Called after New but before RegisterRoutes. getPersonas returns the merged file+stored list for display; CRUD handlers operate on ps directly. If ps is nil, persona management is disabled (config-file personas are still shown read-only).

func (*Admin) SetProviderStorage added in v0.5.0

func (a *Admin) SetProviderStorage(ps storage.ProviderStorage, writable bool, onChange func())

SetProviderStorage wires dynamic provider management. Called after New but before RegisterRoutes. If ps is nil, provider management is disabled (config-file providers are still shown read-only).

func (*Admin) SetRefreshModels added in v0.5.5

func (a *Admin) SetRefreshModels(fn func())

SetRefreshModels wires a forced model rescan from the admin UI. Called after New but before RegisterRoutes. If fn is nil, the rescan endpoint returns 500 (refresh not available).

func (*Admin) SetRequestWatcher added in v0.8.0

func (a *Admin) SetRequestWatcher(subscribe func() chan []byte, unsubscribe func(chan []byte))

SetRequestWatcher wires the live LLM data flow viewer. subscribe returns a channel that delivers JSON-encoded WatchEvent payloads. unsubscribe closes and removes the channel. When both are nil, the watch endpoint returns 503.

type MCPServerInfo

type MCPServerInfo struct {
	Namespace      string   `json:"namespace"`
	URL            string   `json:"url"`
	Command        string   `json:"command,omitempty"`
	Args           []string `json:"args,omitempty"`
	Env            []string `json:"env,omitempty"`
	AuthType       string   `json:"auth_type,omitempty"`
	Enabled        bool     `json:"enabled"`
	ToolVisibility string   `json:"tool_visibility"`
	ToolAllowlist  []string `json:"tool_allowlist,omitempty"`
	ToolDenylist   []string `json:"tool_denylist,omitempty"`
	StaticServer   bool     `json:"static_server"`
	RemoteSearch   bool     `json:"remote_search"`
}

MCPServerInfo represents MCP server information for the UI

type ModelInfo

type ModelInfo struct {
	ID        string   `json:"id"`
	Providers []string `json:"providers"`
	Context   int      `json:"context,omitempty"` // resolved context window in tokens (0 = unknown)
}

ModelInfo represents a model and its providers for the UI

type PersonaInfo added in v0.5.1

type PersonaInfo struct {
	ID           string                 `json:"id"`
	Name         string                 `json:"name"`
	Description  string                 `json:"description,omitempty"`
	SystemPrompt string                 `json:"system_prompt,omitempty"`
	DefaultModel string                 `json:"default_model,omitempty"`
	Params       map[string]interface{} `json:"params,omitempty"`
	Static       bool                   `json:"static"`
}

PersonaInfo represents a persona for the management UI. Static=true means it came from a .toml file in PersonasDir (read-only); Static=false means it lives in KV storage and supports full CRUD.

type PromptArgument added in v0.5.0

type PromptArgument struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Required    bool   `json:"required"`
}

PromptArgument describes one argument a prompt accepts.

type PromptInfo added in v0.5.0

type PromptInfo struct {
	Name        string           `json:"name"`
	Description string           `json:"description"`
	Arguments   []PromptArgument `json:"arguments,omitempty"`
}

PromptInfo represents a prompt exposed by an MCP server. Arguments is the (possibly empty) list of named arguments the prompt accepts.

type ProviderDetail added in v0.5.0

type ProviderDetail struct {
	Name               string              `json:"name"`
	Provider           string              `json:"provider"`
	BaseURL            string              `json:"base_url,omitempty"`
	Enabled            bool                `json:"enabled"`
	Healthy            bool                `json:"healthy"`
	Weight             float64             `json:"weight"`
	ModelCount         int                 `json:"model_count"`
	Models             []string            `json:"models,omitempty"`
	ModelAllowlist     []string            `json:"model_allowlist,omitempty"`
	Tags               []string            `json:"tags,omitempty"`
	ModelDenylist      []string            `json:"model_denylist,omitempty"`
	ModelAliases       map[string]string   `json:"model_aliases,omitempty"`
	ModelTags          map[string][]string `json:"model_tags,omitempty"`
	DefaultContextSize int                 `json:"default_context_size,omitempty"`
	ModelContext       map[string]int      `json:"model_context,omitempty"`
	StaticProvider     bool                `json:"static_provider"`
}

ProviderDetail is the full provider config returned by the management API. For static (config-file) providers, only the display fields are populated. For stored providers, all editable fields are included.

type ProviderInfo

type ProviderInfo struct {
	Name           string  `json:"name"`
	Type           string  `json:"type"`
	Healthy        bool    `json:"healthy"`
	ModelCount     int     `json:"model_count"`
	Weight         float64 `json:"weight"`
	StaticProvider bool    `json:"static_provider"` // true = from config file, false = from UI/storage
}

ProviderInfo represents provider information for the UI

type ResourceInfo added in v0.5.0

type ResourceInfo struct {
	URI         string `json:"uri"`
	Template    bool   `json:"template"`
	Name        string `json:"name"`
	Description string `json:"description"`
	MimeType    string `json:"mime_type,omitempty"`
}

ResourceInfo represents a resource (static or template) exposed by an MCP server. Templates carry a URITemplate with {var} placeholders; static resources carry a concrete URI. Both are shown read-only in the UI — the router has no per-resource enable/disable toggle the way it does for tools.

type Session

type Session struct {
	Token     string
	CreatedAt time.Time
}

Session represents an authenticated session.

type Stats

type Stats struct {
	Providers        int  `json:"providers"`
	Models           int  `json:"models"`
	MCPServers       int  `json:"mcp_servers"`
	ActiveRequests   int  `json:"active_requests"`
	PasswordRequired bool `json:"password_required"`
}

Stats represents dashboard statistics

type TemplateData

type TemplateData struct {
	CSSFile string
	JSFile  string
	Prefix  string
}

TemplateData contains data passed to templates

type TemplateRenderer

type TemplateRenderer struct {
	// contains filtered or unexported fields
}

TemplateRenderer handles HTML template rendering

func NewTemplateRenderer

func NewTemplateRenderer(fsys fs.FS) *TemplateRenderer

NewTemplateRenderer creates a new template renderer

func (*TemplateRenderer) Render

func (r *TemplateRenderer) Render(w io.Writer, name string, data *TemplateData) error

Render renders a template with the given data

type ToolCallContent added in v0.5.1

type ToolCallContent struct {
	Type     string `json:"type"`
	Text     string `json:"text,omitempty"`
	Data     string `json:"data,omitempty"`
	MimeType string `json:"mimeType,omitempty"`
}

ToolCallContent is one content item in a tool call result.

type ToolCallResult added in v0.5.1

type ToolCallResult struct {
	Content           []ToolCallContent `json:"content"`
	StructuredContent interface{}       `json:"structuredContent,omitempty"`
}

ToolCallResult represents the result of executing a tool via the admin UI. It mirrors the relevant parts of mcp.ToolResponse without coupling this package to the mcp dependency.

type ToolInfo

type ToolInfo struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	InputSchema map[string]interface{} `json:"input_schema"`
	Enabled     bool                   `json:"enabled"`
}

ToolInfo represents tool information for the UI

Jump to

Keyboard shortcuts

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