Skip to content

Kitto.Chat.Provider

Provider abstraction for the KittoX in-app help chat. A provider turns the conversation history (plus an optional context: the view the user is on) into an assistant reply. v1 ships a stub provider that returns an honest placeholder; real back-ends (a DocuWiki-grounded Claude provider, a static FAQ matcher, a local LLM) implement the same IKXChatProvider interface and register themselves in TKXChatProviderRegistry, so the active provider is selected by name from HelpChat/Provider in Config.yaml with no code change on the call site.

TKHelpChatConfig class

Help Chat assistant settings (bubble, bottom-right). Opt-in. Root config of the chat domain; each provider adds its own [YamlConfigNode('HelpChat/<X>')] reader in its own unit (e.g. TKClaudeProviderConfig). The class-level [YamlConfigNode('HelpChat')] binds this class to the YAML node so KIDE discovers it via RTTI, without TKConfig referencing it by type. YAML path: HelpChat

HelpChat:
Enabled: True
Provider: docsearch

TKXChatMessage record

A single chat message. A plain value record (strings + enums) so it can be copied into the per-user store and passed to a worker thread without any ownership concern. Assistant messages produced asynchronously start with Pending = True and are later completed (or marked IsError).

TKXChatContext record

Optional context passed to the provider: who is asking and, if the chat was opened from a specific screen, which view (its name and display label). A DocuWiki/RAG provider uses ViewName to fetch the matching help page.

IKXChatProvider interface

Contract every chat back-end implements. Generate returns the full assistant reply; a streaming provider (SupportsStreaming = True) additionally calls AOnToken for each token as it is produced (the returned string is their concatenation, convenient for persistence).

pascal
function GetName: string;

The registered provider name (matches HelpChat/Provider).

pascal
function SupportsStreaming: Boolean;

True if the provider emits tokens incrementally via AOnToken.

pascal
function Generate(const AHistory: TArray<TKXChatMessage>;

Produces the assistant reply for the given history and context.

TKXChatProviderBase class

Convenience base class for providers: reference-counted, non-streaming by default. Descendants override GetName and Generate.

pascal
constructor Create;

Virtual so providers instantiated polymorphically via the registry (LClass.Create) can override it to read their config once at creation time (providers are short-lived, one per chat request).

TKXChatProviderRegistry class

Process-global registry of chat providers, keyed by name. Providers self-register in their unit's initialization section; the active one is created on demand from the name configured in HelpChat/Provider.

pascal
class procedure RegisterProvider(const AName: string;

Registers a provider class under a (case-insensitive) name.

pascal
class procedure UnregisterProvider(const AName: string);

Removes a previously registered provider.

pascal
class function IsRegistered(const AName: string): Boolean;

True if a provider is registered under the given name.

pascal
class function CreateProvider(const AName: string): IKXChatProvider;

Instantiates the named provider, or the stub provider if the name is empty/unknown (so the chat always has a working back-end).

pascal
class function ProviderNames: TArray<string>;

The names of all registered providers.

TKXChatStubProvider class

Default provider (stub): returns a fixed, honest placeholder reply. It validates the whole UI/async pipeline end-to-end without any external dependency or API key, and is the fallback whenever the configured provider name is missing or unknown.

Released under Apache License, Version 2.0.