server

package
v0.7.13 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package server implements chatz's generated StrictServerInterface on echo: session-cookie auth, model discovery, MCP management, and streaming chat. Handlers are split per resource across handler_*.go; this file owns the echo bootstrap, middleware, and the request-scoped identity helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deps

type Deps struct {
	Auth       *auth.Service
	Chats      *chats.Service
	MCP        *mcp.Manager
	MCPServers *mcp.ServerStore
	Models     *upstreams.Registry
	Readiness  *operations.Service
	Secrets    *secrets.Box

	// WebFS, when non-nil, holds the built SPA (index.html + _app/...). Its
	// presence makes New register catch-all SPA serving AFTER the API routes so
	// one service serves API + UI. Nil disables SPA serving entirely (callers /
	// tests that don't set it still compile + run — API-only).
	WebFS fs.FS
}

Deps are the collaborators the handlers drive.

type Server

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

Server implements api.StrictServerInterface.

func New

func New(deps Deps) *Server

New wires the echo server: request logging, session auth, and the generated strict handlers.

func (*Server) ContinueChat

ContinueChat continues a chat and streams the next assistant turn (SSE).

func (*Server) CreateChat

CreateChat creates a chat and streams the first assistant turn (SSE). The new chat id rides in the message_start event's stream_id.

func (*Server) CreateMCPServer

CreateMCPServer adds an MCP server, sealing its secrets, persisting it, and connecting. Admin only.

func (*Server) CreateUser

CreateUser provisions a user. Admin only.

func (*Server) DeleteChat

DeleteChat soft-deletes one caller-owned chat.

func (*Server) DeleteMCPServer

DeleteMCPServer removes an MCP server. Admin only.

func (*Server) DeleteUser

DeleteUser removes a user; the DB cascades their sessions + chats. Admin only, and an admin cannot delete their own account (which would orphan the workspace / lock themselves out).

func (*Server) GetAdminReadiness

GetAdminReadiness returns the truthful operational snapshot for an admin.

func (*Server) GetAuthStatus

GetAuthStatus reports whether setup is needed and whether the caller is authenticated. Public.

When no valid session is present, it attempts single-user passwordless auto-login: if CHATZ_AUTH_PASSWORDLESS is enabled AND the install has exactly one user, it mints a session for that sole admin and sets the session cookie. The guard lives entirely server-side in PasswordlessLogin (passwordless && userCount == 1) — a second user disables it and login is required for everyone.

func (*Server) GetChat

GetChat returns a chat's metadata (ownership-checked). Messages are fetched separately via ListChatMessages.

func (*Server) GetHealth

GetHealth is the liveness probe.

func (*Server) GetOrCreateEmptyChat

GetOrCreateEmptyChat returns the caller's reusable "empty chat" (creating one if none exists) — see chats.Service.GetOrCreateEmpty.

func (*Server) Handler

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

Handler returns the underlying http.Handler (for embedding + tests).

func (*Server) ImportMCP

ImportMCP imports MCP servers from a Claude-style .mcp.json. Admin only.

func (*Server) ListChatMCPServers

ListChatMCPServers lists the MCP servers with each one's live status and whether it is enabled for this chat (ownership-checked).

func (*Server) ListChatMessages

ListChatMessages lists a page of a chat's messages, oldest-first (ownership-checked).

func (*Server) ListChats

ListChats lists a page of the caller's chats, newest activity first.

func (*Server) ListMCPServerTools

ListMCPServerTools lists a connected server's tools (name/description/input schema). Admin only. A server that isn't currently connected yields an empty list — tools exist only while the server is live.

func (*Server) ListMCPServers

ListMCPServers lists configured MCP servers. Admin only.

func (*Server) ListModels

ListModels returns the merged model list across all configured upstreams.

func (*Server) ListUpstreamHealth

ListUpstreamHealth returns redacted per-upstream health for administrators.

func (*Server) ListUsers

ListUsers lists all users. Admin only.

func (*Server) Login

Login authenticates a user and issues a session cookie. Public.

func (*Server) Logout

Logout revokes the current session. Idempotent.

func (*Server) PreviewChatContext

PreviewChatContext returns the exact prompt context selection for an unsent message. The service owns transcript loading, tokenization, and selection.

func (*Server) ReconnectMCPServer

ReconnectMCPServer kicks off a background reconnect for one server. Admin only. Returns the server with its (connecting) status.

func (*Server) RenameChat

RenameChat sets a chat's title (ownership-checked).

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, addr string) error

Serve runs the echo server on addr until ctx is cancelled, then drains it. It owns the http.Server instead of using echo's StartConfig, whose default ReadTimeout would cut long-lived SSE chat streams.

func (*Server) Setup

Setup bootstraps the first admin user and logs them in. Public, one-shot.

func (*Server) UpdateChatMCPServer

UpdateChatMCPServer enables or disables one MCP server for this chat (ownership-checked).

func (*Server) UpdateChatSettings

UpdateChatSettings replaces a chat's model-generation settings (full replacement — an omitted field clears that setting).

func (*Server) UpdateMCPServer

UpdateMCPServer edits a server, reseals its secrets, persists, and reconnects (or disables when enabled=false). Admin only.

Jump to

Keyboard shortcuts

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