storage

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: MIT Imports: 9 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"`
	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
	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 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 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) IsMemory

func (s *Store) IsMemory() bool

func (*Store) NewConversationStorage

func (s *Store) NewConversationStorage() ConversationStorage

func (*Store) NewMCPStorage

func (s *Store) NewMCPStorage() MCPStorage

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

Jump to

Keyboard shortcuts

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