Documentation
¶
Overview ¶
Package provider defines the abstraction layer between Hikari and AI backends.
Every AI backend (OpenClaw, Hermes, Ollama, …) is represented as a Provider. The Provider interface is intentionally minimal: it covers the lowest common denominator of all backends. Richer capabilities are exposed through the Capabilities struct, which allows TUI and CLI code to conditionally enable features without risking runtime panics from calling unsupported methods.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Capabilities ¶
type Capabilities struct {
// Chat indicates the provider supports basic conversational messages.
// All providers must support this — it is included for completeness.
Chat bool
// Streaming indicates the provider can stream token-by-token responses.
// If false, Chat() will emit a single EventToken followed by EventDone.
Streaming bool
// Models indicates the provider can list available models via Models().
Models bool
// ToolCalling indicates the provider supports structured tool/function calls
// from the AI model (e.g. OpenAI function calling style).
ToolCalling bool
// Memory indicates the provider has server-side memory / long-term context.
Memory bool
// AgentExecution indicates the provider can autonomously execute multi-step
// tasks (e.g. OpenClaw or Hermes with tool chains and planning).
AgentExecution bool
// FilesystemAccess indicates the provider's agent can read/write files on
// the backend server.
FilesystemAccess bool
// CommandExecution indicates the provider's agent can run shell commands
// on the backend server.
CommandExecution bool
}
Capabilities describes which optional features a Provider supports.
The base Provider interface only requires Chat and Status. All other capabilities are optional. Code that uses a Provider should check the relevant Capabilities flag before calling methods that depend on it.
Example:
caps := p.Capabilities()
if caps.Models {
models, err := p.Models(ctx)
}
func CustomCapabilities ¶ added in v1.3.0
func CustomCapabilities() Capabilities
CustomCapabilities returns the capability set for generic custom providers. Custom providers target any OpenAI-compatible HTTP API. We can safely assume chat, streaming, and model listing — but not agent, tool, or memory features because those depend on server-specific capabilities we cannot know statically.
func HermesCapabilities ¶
func HermesCapabilities() Capabilities
HermesCapabilities returns the capability set for Hermes providers. Hermes is an agent provider similar to OpenClaw.
func OllamaCapabilities ¶
func OllamaCapabilities() Capabilities
OllamaCapabilities returns the capability set for Ollama providers. Ollama is a model provider: it supports chat, streaming, and model listing but does not have agent, tool, or memory capabilities.
func OpenClawCapabilities ¶
func OpenClawCapabilities() Capabilities
OpenClawCapabilities returns the capability set for OpenClaw providers. OpenClaw is a full agent provider.
type ConstructorFn ¶
type ConstructorFn func(name string, cfg config.ProviderConfig) (Provider, error)
ConstructorFn is a function that creates a Provider from a ProviderConfig. Each provider implementation registers a constructor here.
type Event ¶
type Event struct {
Type EventType
Content string // text token or status message
Error error // non-nil only when Type == EventError
// Meta is optional provider-specific metadata (tool name, model, etc.).
Meta map[string]any
}
Event is a single message emitted by a provider's streaming channel.
type EventType ¶
type EventType string
EventType classifies events coming from a provider's streaming channel.
const ( // EventToken is a partial text chunk during streaming generation. EventToken EventType = "token" // EventDone signals that the model has finished generating. EventDone EventType = "done" // EventError carries an error from the provider. EventError EventType = "error" // EventStatus is an informational status message from the provider // (e.g. "thinking…", "running tool X"). EventStatus EventType = "status" )
type Model ¶
type Model struct {
ID string
Name string
Description string
Size int64 // bytes, if known (e.g. Ollama local models)
}
Model represents an AI model available on a provider.
type Provider ¶
type Provider interface {
// Connect establishes a connection to the backend and validates credentials.
// It must be called before any other method.
Connect(ctx context.Context) error
// Close releases all resources held by the provider.
Close() error
// Chat sends a message and returns a channel of streaming events.
// The caller is responsible for draining the channel until it is closed.
// Cancelling ctx will cause the provider to close the channel and stop
// generation.
//
// history is the conversation history to send for context.
// message is the new user message.
Chat(ctx context.Context, history []Message, message string) (<-chan Event, error)
// Models returns the list of models available on this provider.
// Returns an error if the provider does not support model listing.
Models(ctx context.Context) ([]Model, error)
// Status returns the current health status of this provider.
Status(ctx context.Context) (ProviderStatus, error)
// Capabilities returns the set of features this provider supports.
// Callers must check Capabilities before calling optional features.
Capabilities() Capabilities
// Name returns the human-readable name of this provider implementation.
Name() string
}
Provider is the core abstraction for all AI backends.
Implementations must be safe for concurrent use from a single goroutine (i.e. the TUI event loop). Chat() may be called while a previous call's channel is still being drained — implementations should handle this cleanly by cancelling the previous request via the context.
type ProviderStatus ¶
type ProviderStatus struct {
Connected bool
Latency time.Duration
Message string // human-readable status
Details []string // extra lines (e.g. loaded models, auth info)
Endpoint string // the URL being checked
}
ProviderStatus describes the health of a provider connection.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds provider constructors (by type) and live instances (by name).
The separation between type constructors and named instances allows the same provider type (e.g. "ollama") to have multiple configured instances (e.g. "ollama-local", "ollama-vps").
func (*Registry) Build ¶
Build instantiates all providers defined in the config and stores them in the registry. Returns the first error encountered.
func (*Registry) Get ¶
Get returns a provider instance by its configured name. Returns nil, error if not found.
func (*Registry) RegisterType ¶
func (r *Registry) RegisterType(providerType string, fn ConstructorFn)
RegisterType registers a constructor for a provider type. This must be called at program startup before any providers are instantiated. Panics if the type is already registered (programming error).
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router manages the currently active provider and supports live switching.
Router is goroutine-safe: provider switches can be triggered from the TUI event loop while a Chat() call may be in flight (the caller is responsible for cancelling the in-flight context before switching).
func (*Router) Active ¶
Active returns the currently active provider and its config name. Returns an error if no provider has been set yet.
func (*Router) ActiveName ¶
ActiveName returns the config-key name of the active provider, or "".
func (*Router) AvailableNames ¶
AvailableNames returns all provider names in the registry.
func (*Router) MustActive ¶
MustActive is like Active but panics if no provider is set. Use only in contexts where a provider is guaranteed.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package custom implements a generic, configurable Hikari Provider for any OpenAI-compatible HTTP API — without requiring code changes.
|
Package custom implements a generic, configurable Hikari Provider for any OpenAI-compatible HTTP API — without requiring code changes. |
|
Package hermes implements the Hikari Provider interface for Hermes.
|
Package hermes implements the Hikari Provider interface for Hermes. |
|
Package ollama implements the Hikari Provider interface for Ollama.
|
Package ollama implements the Hikari Provider interface for Ollama. |
|
Package openclaw implements the Hikari Provider interface for OpenClaw.
|
Package openclaw implements the Hikari Provider interface for OpenClaw. |