Documentation
¶
Overview ¶
Package lmchatkit adapts the github.com/paularlott/lmchatkit library to knot's per-user, MCP-backed chat architecture.
Knot uses lmchatkit.StandardHost (same as llmrouter) with the OpenAI base URL pointing at knot's configured LLM endpoint. This is required because the MCP AI client's StreamChatCompletion SUPPRESSES tool-call delta chunks when MCP servers are present — lmchatkit's manual approval flow needs those chunks to reach the frontend. StandardHost uses TranslateOpenAIStream on the raw HTTP response, bypassing the suppression.
Per-user MCP tools are injected via the auth middleware (which wraps every lmchatkit route): it sets up the tool provider in the request context so StandardHost.ListTools / CallTool resolve the user's tools through the MCP server's context-aware methods.
Index ¶
- func AuthMiddleware(apiAuthMiddleware func(http.Handler) http.Handler, mcpServer *mcplib.Server, ...) func(http.Handler) http.Handler
- func BroadcastCommandEvent()
- func BroadcastConversationEvent(eventType, id string)
- func ChatCompletionsURL(provider, baseURL string) string
- func NewCommandSource() lmchatkit.CommandSource
- func NewHistoryStore() lmchatkit.HistoryStore
- func NewHost(cfg config.ChatConfig, mcpServer *mcplib.Server, ...) *lmchatkit.StandardHost
- func PersonaSource() lmchatkit.PersonaSource
- func SetEventBroadcaster(b *lmchatkit.EventBroadcaster)
- type ScriptToolsProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthMiddleware ¶
func AuthMiddleware(apiAuthMiddleware func(http.Handler) http.Handler, mcpServer *mcplib.Server, scriptToolsProvider ScriptToolsProvider) func(http.Handler) http.Handler
AuthMiddleware returns the middleware that wraps every lmchatkit HTTP handler. It authenticates the user (delegating to knot's ApiAuth + permission check) and injects the per-user MCP tool, skill and resource providers into the request context so that StandardHost.ListTools/CallTool resolve the user's script and method tools, StandardHost surfaces the skills extension (including the lmchatkit__get_skill virtual tool and its reads), and StandardHost.ReadResource can fetch an MCP Apps view's linked ui:// resource from whichever of the user's remote servers registered it.
func BroadcastCommandEvent ¶
func BroadcastCommandEvent()
BroadcastCommandEvent pushes a commands_changed event to all connected chat clients so they reload their slash command list.
func BroadcastConversationEvent ¶
func BroadcastConversationEvent(eventType, id string)
BroadcastConversationEvent pushes a chat-history SSE event to every lmchatkit client connected to THIS server. It is the receive-side half of the gossip→SSE bridge: when a remote server gossips a conversation change, internal/cluster calls this so local chat windows reload. (The originating server's own clients are notified automatically by lmchatkit's handlers.)
func ChatCompletionsURL ¶ added in v0.37.0
ChatCompletionsURL returns the OpenAI-compatible chat completions URL for a provider's base URL. The web chat always speaks the OpenAI protocol, which Gemini serves under /openai. A base URL without a path (e.g. http://host:1234) gets /v1, as before.
func NewCommandSource ¶
func NewCommandSource() lmchatkit.CommandSource
func NewHistoryStore ¶
func NewHistoryStore() lmchatkit.HistoryStore
NewHistoryStore returns the lmchatkit.HistoryStore backed by knot's database + gossip. nil user in the context yields an empty store, so unauthenticated requests simply see no history.
func NewHost ¶
func NewHost(cfg config.ChatConfig, mcpServer *mcplib.Server, scriptToolsProvider ScriptToolsProvider) *lmchatkit.StandardHost
NewHost builds a lmchatkit.StandardHost configured for knot's LLM endpoint, MCP server, and single persona. The per-user tool provider is injected by AuthMiddleware (callers must wrap lmchatkit's routes with it).
func PersonaSource ¶
func PersonaSource() lmchatkit.PersonaSource
PersonaSource returns a lmchatkit.PersonaSource backed by knot's single system-defined persona (loaded from the configured system prompt file).
func SetEventBroadcaster ¶
func SetEventBroadcaster(b *lmchatkit.EventBroadcaster)
SetEventBroadcaster stores the broadcaster for later use by BroadcastCommandEvent. Called once during server startup.
Types ¶
type ScriptToolsProvider ¶
ScriptToolsProvider returns the per-user MCP tool providers (script tools, method tools, remote servers), matching the MCPServerContext middleware logic. Returned as a slice — not merged into one mcp.NewMultiProvider — so each provider stays individually visible to mcp.GetToolProviders(ctx): StandardHost's SourceScopedHost support needs to type-assert the remote server provider as a lmchatkit.SourcedToolProvider, which a MultiProvider wrapper would hide (it only forwards GetTools/ExecuteTool).