storage

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateConversationID

func GenerateConversationID() string

func GenerateMessageID

func GenerateMessageID() string

Types

type ConversationStorage

type ConversationStorage interface {
	Store(ctx context.Context, conversation *StoredConversation) error
	Get(ctx context.Context, id string) (*StoredConversation, error)
	Delete(ctx context.Context, id string) error
	Update(ctx context.Context, id string, metadata map[string]interface{}) error
	AddItems(ctx context.Context, conversationID string, items []openai.ConversationItem) error
	GetItems(ctx context.Context, conversationID string, after string, limit int, order string) ([]openai.ConversationItem, bool, error)
	GetItem(ctx context.Context, conversationID string, itemID string) (*openai.ConversationItem, error)
	DeleteItem(ctx context.Context, conversationID string, itemID string) error
}

ConversationStorage defines the interface for conversation storage

type MCPServerConfig

type MCPServerConfig struct {
	Namespace         string   `json:"namespace"`
	URL               string   `json:"url"`
	Command           string   `json:"command,omitempty"`   // stdio: executable to launch (empty for HTTP)
	Args              []string `json:"args,omitempty"`      // stdio: command-line arguments
	Env               []string `json:"env,omitempty"`       // stdio: extra KEY=VALUE environment variables (merged on top of the parent environment)
	AuthType          string   `json:"auth_type,omitempty"` // "bearer" (default) or "oauth2"
	Token             string   `json:"token,omitempty"`
	OAuthClientID     string   `json:"oauth_client_id,omitempty"`
	OAuthTokenURL     string   `json:"oauth_token_url,omitempty"`
	OAuthAccessToken  string   `json:"oauth_access_token,omitempty"`
	OAuthRefreshToken string   `json:"oauth_refresh_token,omitempty"`
	Enabled           bool     `json:"enabled"`         // Server is active (default true)
	ToolVisibility    string   `json:"tool_visibility"` // "native" (default) or "ondemand"
	ToolAllowlist     []string `json:"tool_allowlist,omitempty"`
	ToolDenylist      []string `json:"tool_denylist,omitempty"`
	DisabledTools     []string `json:"disabled_tools,omitempty"` // Tools disabled via UI toggle
	RemoteSearch      bool     `json:"remote_search,omitempty"`  // Delegate tool_search to this remote
	Notifications     bool     `json:"notifications,omitempty"`  // Accept listChanged notifications from this server and propagate them
	CreatedAt         int64    `json:"created_at"`
	UpdatedAt         int64    `json:"updated_at"`
}

MCPServerConfig represents a stored MCP server configuration

func (*MCPServerConfig) IsToolEnabled

func (c *MCPServerConfig) IsToolEnabled(toolName string) bool

IsToolEnabled checks if a tool is enabled based on allowlist, denylist, and disabled_tools

func (*MCPServerConfig) MarshalJSON

func (c *MCPServerConfig) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for MCPServerConfig

func (*MCPServerConfig) ToJSON

func (c *MCPServerConfig) ToJSON(includeToken bool) map[string]any

ToJSON returns a JSON representation safe for API responses

type MCPStorage

type MCPStorage interface {
	Create(ctx context.Context, server *MCPServerConfig) error
	Get(ctx context.Context, namespace string) (*MCPServerConfig, error)
	List(ctx context.Context) ([]*MCPServerConfig, error)
	Update(ctx context.Context, server *MCPServerConfig) error
	Delete(ctx context.Context, namespace string) error
	ToggleTool(ctx context.Context, namespace, toolName string, enabled bool) error
}

MCPStorage defines the interface for MCP server storage

type MemoryConversationStorage

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

MemoryConversationStorage implements ConversationStorage using in-memory storage

func NewMemoryConversationStorage

func NewMemoryConversationStorage() *MemoryConversationStorage

NewMemoryConversationStorage creates a new memory-based conversation storage

func (*MemoryConversationStorage) AddItems

func (s *MemoryConversationStorage) AddItems(ctx context.Context, conversationID string, items []openai.ConversationItem) error

func (*MemoryConversationStorage) Delete

func (*MemoryConversationStorage) DeleteItem

func (s *MemoryConversationStorage) DeleteItem(ctx context.Context, conversationID string, itemID string) error

func (*MemoryConversationStorage) Get

func (*MemoryConversationStorage) GetItem

func (s *MemoryConversationStorage) GetItem(ctx context.Context, conversationID string, itemID string) (*openai.ConversationItem, error)

func (*MemoryConversationStorage) GetItems

func (s *MemoryConversationStorage) GetItems(ctx context.Context, conversationID string, after string, limit int, order string) ([]openai.ConversationItem, bool, error)

func (*MemoryConversationStorage) ListConversations

func (s *MemoryConversationStorage) ListConversations() []string

ListConversations returns all conversation IDs (for admin/debug purposes)

func (*MemoryConversationStorage) Store

func (s *MemoryConversationStorage) Store(ctx context.Context, conversation *StoredConversation) error

func (*MemoryConversationStorage) Update

func (s *MemoryConversationStorage) Update(ctx context.Context, id string, metadata map[string]interface{}) error

type MemoryMCPStorage

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

MemoryMCPStorage implements MCPStorage using in-memory storage

func NewMemoryMCPStorage

func NewMemoryMCPStorage() *MemoryMCPStorage

NewMemoryMCPStorage creates a new in-memory MCP storage

func (*MemoryMCPStorage) Create

func (s *MemoryMCPStorage) Create(ctx context.Context, server *MCPServerConfig) error

func (*MemoryMCPStorage) Delete

func (s *MemoryMCPStorage) Delete(ctx context.Context, namespace string) error

func (*MemoryMCPStorage) Get

func (s *MemoryMCPStorage) Get(ctx context.Context, namespace string) (*MCPServerConfig, error)

func (*MemoryMCPStorage) List

func (*MemoryMCPStorage) ToggleTool

func (s *MemoryMCPStorage) ToggleTool(ctx context.Context, namespace, toolName string, enabled bool) error

func (*MemoryMCPStorage) Update

func (s *MemoryMCPStorage) Update(ctx context.Context, server *MCPServerConfig) error

type MemoryPersonaStorage added in v0.5.1

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

MemoryPersonaStorage implements PersonaStorage using in-memory storage.

func NewMemoryPersonaStorage added in v0.5.1

func NewMemoryPersonaStorage() *MemoryPersonaStorage

func (*MemoryPersonaStorage) Create added in v0.5.1

func (s *MemoryPersonaStorage) Create(ctx context.Context, persona *StoredPersona) error

func (*MemoryPersonaStorage) Delete added in v0.5.1

func (s *MemoryPersonaStorage) Delete(ctx context.Context, id string) error

func (*MemoryPersonaStorage) Get added in v0.5.1

func (*MemoryPersonaStorage) List added in v0.5.1

func (*MemoryPersonaStorage) Update added in v0.5.1

func (s *MemoryPersonaStorage) Update(ctx context.Context, persona *StoredPersona) error

type MemoryProviderStorage added in v0.5.0

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

MemoryProviderStorage implements ProviderStorage using in-memory storage.

func NewMemoryProviderStorage added in v0.5.0

func NewMemoryProviderStorage() *MemoryProviderStorage

func (*MemoryProviderStorage) Create added in v0.5.0

func (*MemoryProviderStorage) Delete added in v0.5.0

func (s *MemoryProviderStorage) Delete(ctx context.Context, name string) error

func (*MemoryProviderStorage) Get added in v0.5.0

func (*MemoryProviderStorage) List added in v0.5.0

func (*MemoryProviderStorage) Rename added in v0.8.0

func (s *MemoryProviderStorage) Rename(ctx context.Context, oldName, newName string) error

Rename changes a provider's key from oldName to newName, preserving the stored config (including CreatedAt) and updating the embedded Name field.

func (*MemoryProviderStorage) Update added in v0.5.0

type PersonaStorage added in v0.5.1

type PersonaStorage interface {
	Create(ctx context.Context, persona *StoredPersona) error
	Get(ctx context.Context, id string) (*StoredPersona, error)
	List(ctx context.Context) ([]*StoredPersona, error)
	Update(ctx context.Context, persona *StoredPersona) error
	Delete(ctx context.Context, id string) error
}

PersonaStorage defines the interface for persona storage. As with ProviderStorage, the admin UI treats config-file personas as read-only and only stored personas support CRUD.

type ProviderStorage added in v0.5.0

type ProviderStorage interface {
	Create(ctx context.Context, provider *StoredProviderConfig) error
	Get(ctx context.Context, name string) (*StoredProviderConfig, error)
	List(ctx context.Context) ([]*StoredProviderConfig, error)
	Update(ctx context.Context, provider *StoredProviderConfig) error
	Rename(ctx context.Context, oldName, newName string) error
	Delete(ctx context.Context, name string) error
}

ProviderStorage defines the interface for provider storage.

type SnapshotConversationStorage

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

SnapshotConversationStorage implements ConversationStorage using snapshotkv

func NewSnapshotConversationStorage

func NewSnapshotConversationStorage(db *snapshotkv.DB, ttl time.Duration) *SnapshotConversationStorage

NewSnapshotConversationStorage creates a new snapshotkv-based conversation storage

func (*SnapshotConversationStorage) AddItems

func (s *SnapshotConversationStorage) AddItems(ctx context.Context, conversationID string, items []openai.ConversationItem) error

func (*SnapshotConversationStorage) Delete

func (*SnapshotConversationStorage) DeleteItem

func (s *SnapshotConversationStorage) DeleteItem(ctx context.Context, conversationID string, itemID string) error

func (*SnapshotConversationStorage) Get

func (*SnapshotConversationStorage) GetItem

func (s *SnapshotConversationStorage) GetItem(ctx context.Context, conversationID string, itemID string) (*openai.ConversationItem, error)

func (*SnapshotConversationStorage) GetItems

func (s *SnapshotConversationStorage) GetItems(ctx context.Context, conversationID string, after string, limit int, order string) ([]openai.ConversationItem, bool, error)

func (*SnapshotConversationStorage) ListConversations

func (s *SnapshotConversationStorage) ListConversations() []string

ListConversations returns all conversation IDs (for admin/debug purposes)

func (*SnapshotConversationStorage) Store

func (*SnapshotConversationStorage) Update

func (s *SnapshotConversationStorage) Update(ctx context.Context, id string, metadata map[string]interface{}) error

type SnapshotMCPStorage

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

SnapshotMCPStorage implements MCPStorage using snapshotkv

func NewSnapshotMCPStorage

func NewSnapshotMCPStorage(db *snapshotkv.DB) *SnapshotMCPStorage

NewSnapshotMCPStorage creates a new snapshotkv-backed MCP storage

func (*SnapshotMCPStorage) Create

func (s *SnapshotMCPStorage) Create(ctx context.Context, server *MCPServerConfig) error

func (*SnapshotMCPStorage) Delete

func (s *SnapshotMCPStorage) Delete(ctx context.Context, namespace string) error

func (*SnapshotMCPStorage) Get

func (s *SnapshotMCPStorage) Get(ctx context.Context, namespace string) (*MCPServerConfig, error)

func (*SnapshotMCPStorage) List

func (*SnapshotMCPStorage) ToggleTool

func (s *SnapshotMCPStorage) ToggleTool(ctx context.Context, namespace, toolName string, enabled bool) error

ToggleTool enables or disables a specific tool for an MCP server This is a lazy write - it only updates the disabled_tools list

func (*SnapshotMCPStorage) Update

func (s *SnapshotMCPStorage) Update(ctx context.Context, server *MCPServerConfig) error

type SnapshotPersonaStorage added in v0.5.1

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

SnapshotPersonaStorage implements PersonaStorage using snapshotkv. Personas are serialised as JSON blobs (Params is a free-form map, so JSON avoids the type-assertion soup that map[string]any storage would require on read-back).

func NewSnapshotPersonaStorage added in v0.5.1

func NewSnapshotPersonaStorage(db *snapshotkv.DB) *SnapshotPersonaStorage

func (*SnapshotPersonaStorage) Create added in v0.5.1

func (s *SnapshotPersonaStorage) Create(ctx context.Context, persona *StoredPersona) error

func (*SnapshotPersonaStorage) Delete added in v0.5.1

func (s *SnapshotPersonaStorage) Delete(ctx context.Context, id string) error

func (*SnapshotPersonaStorage) Get added in v0.5.1

func (*SnapshotPersonaStorage) List added in v0.5.1

func (*SnapshotPersonaStorage) Update added in v0.5.1

func (s *SnapshotPersonaStorage) Update(ctx context.Context, persona *StoredPersona) error

type SnapshotProviderStorage added in v0.5.0

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

SnapshotProviderStorage implements ProviderStorage using snapshotkv.

func NewSnapshotProviderStorage added in v0.5.0

func NewSnapshotProviderStorage(db *snapshotkv.DB) *SnapshotProviderStorage

func (*SnapshotProviderStorage) Create added in v0.5.0

func (*SnapshotProviderStorage) Delete added in v0.5.0

func (s *SnapshotProviderStorage) Delete(ctx context.Context, name string) error

func (*SnapshotProviderStorage) Get added in v0.5.0

func (*SnapshotProviderStorage) List added in v0.5.0

func (*SnapshotProviderStorage) Rename added in v0.8.0

func (s *SnapshotProviderStorage) Rename(ctx context.Context, oldName, newName string) error

Rename changes a provider's key from oldName to newName, preserving the stored config (including CreatedAt) and updating the embedded Name field.

func (*SnapshotProviderStorage) Update added in v0.5.0

type Store

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

func NewStore

func NewStore(path string, conversationTTL time.Duration) (*Store, error)

func (*Store) Close

func (s *Store) Close() error

func (*Store) DB added in v0.5.0

func (s *Store) DB() *snapshotkv.DB

DB returns the underlying snapshotkv database, or nil in memory mode. Used by packages that need direct KV access (e.g. chat history store).

func (*Store) IsMemory

func (s *Store) IsMemory() bool

func (*Store) NewConversationStorage

func (s *Store) NewConversationStorage() ConversationStorage

func (*Store) NewMCPStorage

func (s *Store) NewMCPStorage() MCPStorage

func (*Store) NewPersonaStorage added in v0.5.1

func (s *Store) NewPersonaStorage() PersonaStorage

func (*Store) NewProviderStorage added in v0.5.0

func (s *Store) NewProviderStorage() ProviderStorage

func (*Store) RunGC

func (s *Store) RunGC() error

type StoredConversation

type StoredConversation struct {
	ID        string
	CreatedAt time.Time
	Metadata  map[string]interface{}
	Items     []openai.ConversationItem
}

StoredConversation represents a conversation stored in the database

type StoredPersona added in v0.5.1

type StoredPersona struct {
	ID           string                 `json:"id"`
	Name         string                 `json:"name"`
	Description  string                 `json:"description,omitempty"`
	SystemPrompt string                 `json:"system_prompt,omitempty"`
	DefaultModel string                 `json:"default_model,omitempty"`
	Params       map[string]interface{} `json:"params,omitempty"`
	CreatedAt    int64                  `json:"created_at"`
	UpdatedAt    int64                  `json:"updated_at"`
}

StoredPersona represents a persona created via the admin UI. Mirrors the fields of a lmchatkit persona TOML file (name, description, system_prompt, default_model, [params]) plus a stable ID and storage metadata.

type StoredProviderConfig added in v0.5.0

type StoredProviderConfig struct {
	Name               string              `json:"name"`
	Provider           string              `json:"provider"`
	BaseURL            string              `json:"base_url,omitempty"`
	Token              string              `json:"token,omitempty"`
	Enabled            bool                `json:"enabled"`
	Weight             float64             `json:"weight,omitempty"`
	Models             []string            `json:"models,omitempty"`
	ModelAllowlist     []string            `json:"model_allowlist,omitempty"`
	Tags               []string            `json:"tags,omitempty"`
	ModelTags          map[string][]string `json:"model_tags,omitempty"`
	ModelDenylist      []string            `json:"model_denylist,omitempty"`
	ModelAliases       map[string]string   `json:"model_aliases,omitempty"`
	DefaultContextSize int                 `json:"default_context_size,omitempty"`
	ModelContext       map[string]int      `json:"model_context,omitempty"`
	CreatedAt          int64               `json:"created_at"`
	UpdatedAt          int64               `json:"updated_at"`
}

StoredProviderConfig represents a provider stored in KV storage. Mirrors types.ProviderConfig but adds timestamps for storage metadata.

Jump to

Keyboard shortcuts

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