provider

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ModelCacheTTL is the time-to-live for cached models
	ModelCacheTTL = 24 * time.Hour
)

Variables

This section is empty.

Functions

func GetProvidersWithStatus

func GetProvidersWithStatus(store *Store) map[Provider][]ProviderInfo

GetProvidersWithStatus returns all providers grouped by provider name with their status

func IsReady

func IsReady(meta ProviderMeta) bool

IsReady checks if all required environment variables are set for a provider

func Register

func Register(meta ProviderMeta, factory ProviderFactory)

Register registers a provider with its metadata and factory

Types

type AuthMethod

type AuthMethod string

AuthMethod represents an authentication method

const (
	AuthAPIKey  AuthMethod = "api_key"
	AuthVertex  AuthMethod = "vertex"
	AuthBedrock AuthMethod = "bedrock"
)

type ChunkType

type ChunkType string

ChunkType represents the type of a stream chunk

const (
	ChunkTypeText      ChunkType = "text"
	ChunkTypeToolStart ChunkType = "tool_start"
	ChunkTypeToolInput ChunkType = "tool_input"
	ChunkTypeDone      ChunkType = "done"
	ChunkTypeError     ChunkType = "error"
)

type CompletionOptions

type CompletionOptions struct {
	Model        string
	Messages     []Message
	MaxTokens    int
	Temperature  float64
	Tools        []Tool
	SystemPrompt string
}

CompletionOptions contains options for a completion request

type CompletionResponse

type CompletionResponse struct {
	Content    string     `json:"content,omitempty"`
	ToolCalls  []ToolCall `json:"tool_calls,omitempty"`
	StopReason string     `json:"stop_reason"` // "end_turn", "tool_use", "max_tokens"
	Usage      Usage      `json:"usage"`
}

CompletionResponse represents a completion response

func Complete

func Complete(ctx context.Context, provider LLMProvider, opts CompletionOptions) (CompletionResponse, error)

Complete is a helper function that collects stream chunks into a complete response This provides non-streaming output from any LLMProvider

type ConnectionInfo

type ConnectionInfo struct {
	AuthMethod  AuthMethod `json:"authMethod"`
	ConnectedAt time.Time  `json:"connectedAt"`
}

ConnectionInfo stores connection information for a provider

type CurrentModelInfo

type CurrentModelInfo struct {
	ModelID    string     `json:"modelId"`
	Provider   Provider   `json:"provider"`
	AuthMethod AuthMethod `json:"authMethod"`
}

CurrentModelInfo stores the current model with its provider info

type LLMProvider

type LLMProvider interface {
	// Stream sends a completion request and returns a channel of streaming chunks
	Stream(ctx context.Context, opts CompletionOptions) <-chan StreamChunk

	// ListModels returns the available models for this provider
	ListModels(ctx context.Context) ([]ModelInfo, error)

	// Name returns the provider name
	Name() string
}

LLMProvider is the interface that all providers must implement

func GetProvider

func GetProvider(ctx context.Context, provider Provider, authMethod AuthMethod) (LLMProvider, error)

GetProvider returns a provider instance for the given provider and auth method

type Message

type Message struct {
	Role       string      `json:"role"` // "user", "assistant", "system"
	Content    string      `json:"content,omitempty"`
	ToolCalls  []ToolCall  `json:"tool_calls,omitempty"`
	ToolResult *ToolResult `json:"tool_result,omitempty"`
}

Message represents a chat message

type ModelCache

type ModelCache struct {
	CachedAt time.Time   `json:"cachedAt"`
	Models   []ModelInfo `json:"models"`
}

ModelCache stores cached model information

type ModelInfo

type ModelInfo struct {
	ID               string `json:"id"`
	Name             string `json:"name"`
	DisplayName      string `json:"displayName,omitempty"`
	InputTokenLimit  int    `json:"inputTokenLimit,omitempty"`
	OutputTokenLimit int    `json:"outputTokenLimit,omitempty"`
}

ModelInfo represents information about an available model

type Provider

type Provider string

Provider represents a provider name

const (
	ProviderAnthropic Provider = "anthropic"
	ProviderOpenAI    Provider = "openai"
	ProviderGoogle    Provider = "google"
)

type ProviderFactory

type ProviderFactory func(ctx context.Context) (LLMProvider, error)

ProviderFactory creates a new LLMProvider instance

type ProviderInfo

type ProviderInfo struct {
	Meta   ProviderMeta
	Status ProviderStatus
}

ProviderInfo contains provider metadata with its current status

type ProviderMeta

type ProviderMeta struct {
	Provider    Provider
	AuthMethod  AuthMethod
	EnvVars     []string // Required environment variables
	DisplayName string
}

ProviderMeta contains static metadata about a provider

func GetAllMetas

func GetAllMetas() []ProviderMeta

GetAllMetas returns all registered provider metadata

func GetMeta

func GetMeta(provider Provider, authMethod AuthMethod) (ProviderMeta, bool)

GetMeta returns the metadata for a specific provider configuration

func GetReadyProviders

func GetReadyProviders() []ProviderMeta

GetReadyProviders returns all providers that have their required env vars configured

func (ProviderMeta) Key

func (m ProviderMeta) Key() string

Key returns a unique key for this provider configuration

type ProviderStatus

type ProviderStatus string

ProviderStatus represents the connection status of a provider

const (
	StatusConnected     ProviderStatus = "connected"
	StatusAvailable     ProviderStatus = "available"
	StatusNotConfigured ProviderStatus = "not_configured"
)

type Registry

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

Registry manages provider registration and discovery

func (*Registry) GetAllMetas

func (r *Registry) GetAllMetas() []ProviderMeta

GetAllMetas returns all registered provider metadata

func (*Registry) GetMeta

func (r *Registry) GetMeta(provider Provider, authMethod AuthMethod) (ProviderMeta, bool)

GetMeta returns the metadata for a specific provider configuration

func (*Registry) GetProvider

func (r *Registry) GetProvider(ctx context.Context, provider Provider, authMethod AuthMethod) (LLMProvider, error)

GetProvider returns a provider instance for the given provider and auth method

func (*Registry) GetProvidersWithStatus

func (r *Registry) GetProvidersWithStatus(store *Store) map[Provider][]ProviderInfo

GetProvidersWithStatus returns all providers grouped by provider name with their status

func (*Registry) GetReadyProviders

func (r *Registry) GetReadyProviders() []ProviderMeta

GetReadyProviders returns all providers that have their required env vars configured

func (*Registry) IsReady

func (r *Registry) IsReady(meta ProviderMeta) bool

IsReady checks if all required environment variables are set for a provider

func (*Registry) Register

func (r *Registry) Register(meta ProviderMeta, factory ProviderFactory)

Register registers a provider with its metadata and factory

type Store

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

Store manages provider configuration persistence

func NewStore

func NewStore() (*Store, error)

NewStore creates a new Store instance

func (*Store) CacheModels

func (s *Store) CacheModels(provider Provider, authMethod AuthMethod, models []ModelInfo) error

CacheModels saves model information for a provider.

func (*Store) ClearModelCache

func (s *Store) ClearModelCache() error

ClearModelCache clears all cached models

func (*Store) ClearSearchProvider

func (s *Store) ClearSearchProvider() error

ClearSearchProvider clears the search provider (use default)

func (*Store) ClearTokenLimit added in v1.3.0

func (s *Store) ClearTokenLimit(modelID string) error

ClearTokenLimit removes custom token limits for a model

func (*Store) Connect

func (s *Store) Connect(provider Provider, authMethod AuthMethod) error

Connect saves a connection for a provider

func (*Store) Disconnect

func (s *Store) Disconnect(provider Provider) error

Disconnect removes a connection for a provider

func (*Store) GetAllCachedModels

func (s *Store) GetAllCachedModels() map[string][]ModelInfo

GetAllCachedModels returns all cached models grouped by provider key

func (*Store) GetCachedModels

func (s *Store) GetCachedModels(provider Provider, authMethod AuthMethod) ([]ModelInfo, bool)

GetCachedModels returns cached models if they exist and are not expired

func (*Store) GetConnection

func (s *Store) GetConnection(provider Provider) (ConnectionInfo, bool)

GetConnection returns the connection info for a provider

func (*Store) GetConnections

func (s *Store) GetConnections() map[string]ConnectionInfo

GetConnections returns all connections

func (*Store) GetCurrentModel

func (s *Store) GetCurrentModel() *CurrentModelInfo

GetCurrentModel returns the current model info

func (*Store) GetSearchProvider

func (s *Store) GetSearchProvider() string

GetSearchProvider returns the current search provider name

func (*Store) GetTokenLimit added in v1.3.0

func (s *Store) GetTokenLimit(modelID string) (inputLimit, outputLimit int, ok bool)

GetTokenLimit returns custom token limits for a model

func (*Store) IsConnected

func (s *Store) IsConnected(provider Provider, authMethod AuthMethod) bool

IsConnected checks if a provider is connected with the specified auth method

func (*Store) SetCurrentModel

func (s *Store) SetCurrentModel(modelID string, provider Provider, authMethod AuthMethod) error

SetCurrentModel sets the current model with provider info

func (*Store) SetSearchProvider

func (s *Store) SetSearchProvider(name string) error

SetSearchProvider sets the search provider

func (*Store) SetTokenLimit added in v1.3.0

func (s *Store) SetTokenLimit(modelID string, inputLimit, outputLimit int) error

SetTokenLimit sets custom token limits for a model

type StoreData

type StoreData struct {
	Connections    map[string]ConnectionInfo     `json:"connections"`              // key: provider
	Models         map[string]ModelCache         `json:"models"`                   // key: provider:authMethod
	Current        *CurrentModelInfo             `json:"current"`                  // current model with provider info
	SearchProvider *string                       `json:"searchProvider,omitempty"` // search provider name (exa, serper, brave)
	TokenLimits    map[string]TokenLimitOverride `json:"tokenLimits,omitempty"`    // key: modelID
}

StoreData is the persisted data structure

type StreamChunk

type StreamChunk struct {
	Type     ChunkType
	Text     string              // For text chunks
	ToolID   string              // For tool_start chunks
	ToolName string              // For tool_start chunks
	Response *CompletionResponse // For done chunks
	Error    error               // For error chunks
}

StreamChunk represents a chunk in a streaming response

type TokenLimitOverride added in v1.3.0

type TokenLimitOverride struct {
	InputTokenLimit  int `json:"inputTokenLimit"`
	OutputTokenLimit int `json:"outputTokenLimit"`
}

TokenLimitOverride stores custom token limits for a model

type Tool

type Tool struct {
	Name        string      `json:"name"`
	Description string      `json:"description"`
	Parameters  interface{} `json:"parameters"` // JSON Schema
}

Tool represents a tool definition

type ToolCall

type ToolCall struct {
	ID    string `json:"id"`
	Name  string `json:"name"`
	Input string `json:"input"` // JSON string
}

ToolCall represents a tool call from the model

type ToolResult

type ToolResult struct {
	ToolCallID string `json:"tool_call_id"`
	ToolName   string `json:"tool_name,omitempty"`
	Content    string `json:"content"`
	IsError    bool   `json:"is_error,omitempty"`
}

ToolResult represents the result of a tool execution

type Usage

type Usage struct {
	InputTokens  int `json:"input_tokens"`
	OutputTokens int `json:"output_tokens"`
}

Usage contains token usage information

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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