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 ¶
- type Deps
- type Server
- func (s *Server) ContinueChat(ctx context.Context, req api.ContinueChatRequestObject) (api.ContinueChatResponseObject, error)
- func (s *Server) CreateChat(ctx context.Context, req api.CreateChatRequestObject) (api.CreateChatResponseObject, error)
- func (s *Server) CreateMCPServer(ctx context.Context, req api.CreateMCPServerRequestObject) (api.CreateMCPServerResponseObject, error)
- func (s *Server) CreateUser(ctx context.Context, req api.CreateUserRequestObject) (api.CreateUserResponseObject, error)
- func (s *Server) DeleteChat(ctx context.Context, req api.DeleteChatRequestObject) (api.DeleteChatResponseObject, error)
- func (s *Server) DeleteMCPServer(ctx context.Context, req api.DeleteMCPServerRequestObject) (api.DeleteMCPServerResponseObject, error)
- func (s *Server) DeleteUser(ctx context.Context, req api.DeleteUserRequestObject) (api.DeleteUserResponseObject, error)
- func (s *Server) GetAdminReadiness(ctx context.Context, _ api.GetAdminReadinessRequestObject) (api.GetAdminReadinessResponseObject, error)
- func (s *Server) GetAuthStatus(ctx context.Context, _ api.GetAuthStatusRequestObject) (api.GetAuthStatusResponseObject, error)
- func (s *Server) GetChat(ctx context.Context, req api.GetChatRequestObject) (api.GetChatResponseObject, error)
- func (s *Server) GetHealth(_ context.Context, _ api.GetHealthRequestObject) (api.GetHealthResponseObject, error)
- func (s *Server) GetOrCreateEmptyChat(ctx context.Context, _ api.GetOrCreateEmptyChatRequestObject) (api.GetOrCreateEmptyChatResponseObject, error)
- func (s *Server) Handler() http.Handler
- func (s *Server) ImportMCP(ctx context.Context, req api.ImportMCPRequestObject) (api.ImportMCPResponseObject, error)
- func (s *Server) ListChatMCPServers(ctx context.Context, req api.ListChatMCPServersRequestObject) (api.ListChatMCPServersResponseObject, error)
- func (s *Server) ListChatMessages(ctx context.Context, req api.ListChatMessagesRequestObject) (api.ListChatMessagesResponseObject, error)
- func (s *Server) ListChats(ctx context.Context, req api.ListChatsRequestObject) (api.ListChatsResponseObject, error)
- func (s *Server) ListMCPServerTools(ctx context.Context, req api.ListMCPServerToolsRequestObject) (api.ListMCPServerToolsResponseObject, error)
- func (s *Server) ListMCPServers(ctx context.Context, _ api.ListMCPServersRequestObject) (api.ListMCPServersResponseObject, error)
- func (s *Server) ListModels(ctx context.Context, _ api.ListModelsRequestObject) (api.ListModelsResponseObject, error)
- func (s *Server) ListUpstreamHealth(ctx context.Context, _ api.ListUpstreamHealthRequestObject) (api.ListUpstreamHealthResponseObject, error)
- func (s *Server) ListUsers(ctx context.Context, _ api.ListUsersRequestObject) (api.ListUsersResponseObject, error)
- func (s *Server) Login(ctx context.Context, req api.LoginRequestObject) (api.LoginResponseObject, error)
- func (s *Server) Logout(ctx context.Context, _ api.LogoutRequestObject) (api.LogoutResponseObject, error)
- func (s *Server) PreviewChatContext(ctx context.Context, req api.PreviewChatContextRequestObject) (api.PreviewChatContextResponseObject, error)
- func (s *Server) ReconnectMCPServer(ctx context.Context, req api.ReconnectMCPServerRequestObject) (api.ReconnectMCPServerResponseObject, error)
- func (s *Server) RenameChat(ctx context.Context, req api.RenameChatRequestObject) (api.RenameChatResponseObject, error)
- func (s *Server) Serve(ctx context.Context, addr string) error
- func (s *Server) Setup(ctx context.Context, req api.SetupRequestObject) (api.SetupResponseObject, error)
- func (s *Server) UpdateChatMCPServer(ctx context.Context, req api.UpdateChatMCPServerRequestObject) (api.UpdateChatMCPServerResponseObject, error)
- func (s *Server) UpdateChatSettings(ctx context.Context, req api.UpdateChatSettingsRequestObject) (api.UpdateChatSettingsResponseObject, error)
- func (s *Server) UpdateMCPServer(ctx context.Context, req api.UpdateMCPServerRequestObject) (api.UpdateMCPServerResponseObject, error)
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 ¶
New wires the echo server: request logging, session auth, and the generated strict handlers.
func (*Server) ContinueChat ¶
func (s *Server) ContinueChat( ctx context.Context, req api.ContinueChatRequestObject, ) (api.ContinueChatResponseObject, error)
ContinueChat continues a chat and streams the next assistant turn (SSE).
func (*Server) CreateChat ¶
func (s *Server) CreateChat( ctx context.Context, req api.CreateChatRequestObject, ) (api.CreateChatResponseObject, error)
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 ¶
func (s *Server) CreateMCPServer( ctx context.Context, req api.CreateMCPServerRequestObject, ) (api.CreateMCPServerResponseObject, error)
CreateMCPServer adds an MCP server, sealing its secrets, persisting it, and connecting. Admin only.
func (*Server) CreateUser ¶
func (s *Server) CreateUser( ctx context.Context, req api.CreateUserRequestObject, ) (api.CreateUserResponseObject, error)
CreateUser provisions a user. Admin only.
func (*Server) DeleteChat ¶
func (s *Server) DeleteChat( ctx context.Context, req api.DeleteChatRequestObject, ) (api.DeleteChatResponseObject, error)
DeleteChat soft-deletes one caller-owned chat.
func (*Server) DeleteMCPServer ¶
func (s *Server) DeleteMCPServer( ctx context.Context, req api.DeleteMCPServerRequestObject, ) (api.DeleteMCPServerResponseObject, error)
DeleteMCPServer removes an MCP server. Admin only.
func (*Server) DeleteUser ¶
func (s *Server) DeleteUser( ctx context.Context, req api.DeleteUserRequestObject, ) (api.DeleteUserResponseObject, error)
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 ¶
func (s *Server) GetAdminReadiness( ctx context.Context, _ api.GetAdminReadinessRequestObject, ) (api.GetAdminReadinessResponseObject, error)
GetAdminReadiness returns the truthful operational snapshot for an admin.
func (*Server) GetAuthStatus ¶
func (s *Server) GetAuthStatus( ctx context.Context, _ api.GetAuthStatusRequestObject, ) (api.GetAuthStatusResponseObject, error)
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 ¶
func (s *Server) GetChat( ctx context.Context, req api.GetChatRequestObject, ) (api.GetChatResponseObject, error)
GetChat returns a chat's metadata (ownership-checked). Messages are fetched separately via ListChatMessages.
func (*Server) GetHealth ¶
func (s *Server) GetHealth( _ context.Context, _ api.GetHealthRequestObject, ) (api.GetHealthResponseObject, error)
GetHealth is the liveness probe.
func (*Server) GetOrCreateEmptyChat ¶
func (s *Server) GetOrCreateEmptyChat( ctx context.Context, _ api.GetOrCreateEmptyChatRequestObject, ) (api.GetOrCreateEmptyChatResponseObject, error)
GetOrCreateEmptyChat returns the caller's reusable "empty chat" (creating one if none exists) — see chats.Service.GetOrCreateEmpty.
func (*Server) ImportMCP ¶
func (s *Server) ImportMCP( ctx context.Context, req api.ImportMCPRequestObject, ) (api.ImportMCPResponseObject, error)
ImportMCP imports MCP servers from a Claude-style .mcp.json. Admin only.
func (*Server) ListChatMCPServers ¶
func (s *Server) ListChatMCPServers( ctx context.Context, req api.ListChatMCPServersRequestObject, ) (api.ListChatMCPServersResponseObject, error)
ListChatMCPServers lists the MCP servers with each one's live status and whether it is enabled for this chat (ownership-checked).
func (*Server) ListChatMessages ¶
func (s *Server) ListChatMessages( ctx context.Context, req api.ListChatMessagesRequestObject, ) (api.ListChatMessagesResponseObject, error)
ListChatMessages lists a page of a chat's messages, oldest-first (ownership-checked).
func (*Server) ListChats ¶
func (s *Server) ListChats( ctx context.Context, req api.ListChatsRequestObject, ) (api.ListChatsResponseObject, error)
ListChats lists a page of the caller's chats, newest activity first.
func (*Server) ListMCPServerTools ¶
func (s *Server) ListMCPServerTools( ctx context.Context, req api.ListMCPServerToolsRequestObject, ) (api.ListMCPServerToolsResponseObject, error)
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 ¶
func (s *Server) ListMCPServers( ctx context.Context, _ api.ListMCPServersRequestObject, ) (api.ListMCPServersResponseObject, error)
ListMCPServers lists configured MCP servers. Admin only.
func (*Server) ListModels ¶
func (s *Server) ListModels( ctx context.Context, _ api.ListModelsRequestObject, ) (api.ListModelsResponseObject, error)
ListModels returns the merged model list across all configured upstreams.
func (*Server) ListUpstreamHealth ¶
func (s *Server) ListUpstreamHealth( ctx context.Context, _ api.ListUpstreamHealthRequestObject, ) (api.ListUpstreamHealthResponseObject, error)
ListUpstreamHealth returns redacted per-upstream health for administrators.
func (*Server) ListUsers ¶
func (s *Server) ListUsers( ctx context.Context, _ api.ListUsersRequestObject, ) (api.ListUsersResponseObject, error)
ListUsers lists all users. Admin only.
func (*Server) Login ¶
func (s *Server) Login( ctx context.Context, req api.LoginRequestObject, ) (api.LoginResponseObject, error)
Login authenticates a user and issues a session cookie. Public.
func (*Server) Logout ¶
func (s *Server) Logout( ctx context.Context, _ api.LogoutRequestObject, ) (api.LogoutResponseObject, error)
Logout revokes the current session. Idempotent.
func (*Server) PreviewChatContext ¶
func (s *Server) PreviewChatContext( ctx context.Context, req api.PreviewChatContextRequestObject, ) (api.PreviewChatContextResponseObject, error)
PreviewChatContext returns the exact prompt context selection for an unsent message. The service owns transcript loading, tokenization, and selection.
func (*Server) ReconnectMCPServer ¶
func (s *Server) ReconnectMCPServer( ctx context.Context, req api.ReconnectMCPServerRequestObject, ) (api.ReconnectMCPServerResponseObject, error)
ReconnectMCPServer kicks off a background reconnect for one server. Admin only. Returns the server with its (connecting) status.
func (*Server) RenameChat ¶
func (s *Server) RenameChat( ctx context.Context, req api.RenameChatRequestObject, ) (api.RenameChatResponseObject, error)
RenameChat sets a chat's title (ownership-checked).
func (*Server) Setup ¶
func (s *Server) Setup( ctx context.Context, req api.SetupRequestObject, ) (api.SetupResponseObject, error)
Setup bootstraps the first admin user and logs them in. Public, one-shot.
func (*Server) UpdateChatMCPServer ¶
func (s *Server) UpdateChatMCPServer( ctx context.Context, req api.UpdateChatMCPServerRequestObject, ) (api.UpdateChatMCPServerResponseObject, error)
UpdateChatMCPServer enables or disables one MCP server for this chat (ownership-checked).
func (*Server) UpdateChatSettings ¶
func (s *Server) UpdateChatSettings( ctx context.Context, req api.UpdateChatSettingsRequestObject, ) (api.UpdateChatSettingsResponseObject, error)
UpdateChatSettings replaces a chat's model-generation settings (full replacement — an omitted field clears that setting).
func (*Server) UpdateMCPServer ¶
func (s *Server) UpdateMCPServer( ctx context.Context, req api.UpdateMCPServerRequestObject, ) (api.UpdateMCPServerResponseObject, error)
UpdateMCPServer edits a server, reseals its secrets, persists, and reconnects (or disables when enabled=false). Admin only.