Documentation
¶
Index ¶
- Variables
- func DecodeValue(src any, dest any) error
- type AgentInfo
- type AgentMessage
- type AgentSnapshot
- type AgentTodo
- type AgentToolRecord
- type CollectionItem
- type Config
- type JSONStore
- func (js *JSONStore) Delete(ctx context.Context, collection, key string) error
- func (js *JSONStore) DeleteAgent(ctx context.Context, agentID string) error
- func (js *JSONStore) Exists(ctx context.Context, collection, key string) (bool, error)
- func (js *JSONStore) Get(ctx context.Context, collection, key string, dest any) error
- func (js *JSONStore) List(ctx context.Context, collection string) ([]any, error)
- func (js *JSONStore) ListAgents(ctx context.Context) ([]string, error)
- func (js *JSONStore) ListSnapshots(ctx context.Context, agentID string) ([]types.Snapshot, error)
- func (js *JSONStore) LoadInfo(ctx context.Context, agentID string) (*types.AgentInfo, error)
- func (js *JSONStore) LoadMessages(ctx context.Context, agentID string) ([]types.Message, error)
- func (js *JSONStore) LoadSnapshot(ctx context.Context, agentID string, snapshotID string) (*types.Snapshot, error)
- func (js *JSONStore) LoadTodos(ctx context.Context, agentID string) (any, error)
- func (js *JSONStore) LoadToolCallRecords(ctx context.Context, agentID string) ([]types.ToolCallRecord, error)
- func (js *JSONStore) SaveInfo(ctx context.Context, agentID string, info types.AgentInfo) error
- func (js *JSONStore) SaveMessages(ctx context.Context, agentID string, messages []types.Message) error
- func (js *JSONStore) SaveSnapshot(ctx context.Context, agentID string, snapshot types.Snapshot) error
- func (js *JSONStore) SaveTodos(ctx context.Context, agentID string, todos any) error
- func (js *JSONStore) SaveToolCallRecords(ctx context.Context, agentID string, records []types.ToolCallRecord) error
- func (js *JSONStore) Set(ctx context.Context, collection, key string, value any) error
- func (js *JSONStore) TrimMessages(ctx context.Context, agentID string, maxMessages int) error
- type MySQLConfig
- type MySQLStore
- func (s *MySQLStore) Close() error
- func (s *MySQLStore) Delete(ctx context.Context, collection, key string) error
- func (s *MySQLStore) DeleteAgent(ctx context.Context, agentID string) error
- func (s *MySQLStore) Exists(ctx context.Context, collection, key string) (bool, error)
- func (s *MySQLStore) Get(ctx context.Context, collection, key string, dest any) error
- func (s *MySQLStore) List(ctx context.Context, collection string) ([]any, error)
- func (s *MySQLStore) ListAgents(ctx context.Context) ([]string, error)
- func (s *MySQLStore) ListSnapshots(ctx context.Context, agentID string) ([]types.Snapshot, error)
- func (s *MySQLStore) LoadInfo(ctx context.Context, agentID string) (*types.AgentInfo, error)
- func (s *MySQLStore) LoadMessages(ctx context.Context, agentID string) ([]types.Message, error)
- func (s *MySQLStore) LoadSnapshot(ctx context.Context, agentID string, snapshotID string) (*types.Snapshot, error)
- func (s *MySQLStore) LoadTodos(ctx context.Context, agentID string) (any, error)
- func (s *MySQLStore) LoadToolCallRecords(ctx context.Context, agentID string) ([]types.ToolCallRecord, error)
- func (s *MySQLStore) SaveInfo(ctx context.Context, agentID string, info types.AgentInfo) error
- func (s *MySQLStore) SaveMessages(ctx context.Context, agentID string, messages []types.Message) error
- func (s *MySQLStore) SaveSnapshot(ctx context.Context, agentID string, snapshot types.Snapshot) error
- func (s *MySQLStore) SaveTodos(ctx context.Context, agentID string, todos any) error
- func (s *MySQLStore) SaveToolCallRecords(ctx context.Context, agentID string, records []types.ToolCallRecord) error
- func (s *MySQLStore) Set(ctx context.Context, collection, key string, value any) error
- func (s *MySQLStore) TrimMessages(ctx context.Context, agentID string, maxMessages int) error
- type RedisConfig
- type RedisStore
- func (rs *RedisStore) Close() error
- func (rs *RedisStore) Delete(ctx context.Context, collection, key string) error
- func (rs *RedisStore) DeleteAgent(ctx context.Context, agentID string) error
- func (rs *RedisStore) Exists(ctx context.Context, collection, key string) (bool, error)
- func (rs *RedisStore) Get(ctx context.Context, collection, key string, dest any) error
- func (rs *RedisStore) List(ctx context.Context, collection string) ([]any, error)
- func (rs *RedisStore) ListAgents(ctx context.Context) ([]string, error)
- func (rs *RedisStore) ListSnapshots(ctx context.Context, agentID string) ([]types.Snapshot, error)
- func (rs *RedisStore) LoadInfo(ctx context.Context, agentID string) (*types.AgentInfo, error)
- func (rs *RedisStore) LoadMessages(ctx context.Context, agentID string) ([]types.Message, error)
- func (rs *RedisStore) LoadSnapshot(ctx context.Context, agentID string, snapshotID string) (*types.Snapshot, error)
- func (rs *RedisStore) LoadTodos(ctx context.Context, agentID string) (any, error)
- func (rs *RedisStore) LoadToolCallRecords(ctx context.Context, agentID string) ([]types.ToolCallRecord, error)
- func (rs *RedisStore) Ping(ctx context.Context) error
- func (rs *RedisStore) SaveInfo(ctx context.Context, agentID string, info types.AgentInfo) error
- func (rs *RedisStore) SaveMessages(ctx context.Context, agentID string, messages []types.Message) error
- func (rs *RedisStore) SaveSnapshot(ctx context.Context, agentID string, snapshot types.Snapshot) error
- func (rs *RedisStore) SaveTodos(ctx context.Context, agentID string, todos any) error
- func (rs *RedisStore) SaveToolCallRecords(ctx context.Context, agentID string, records []types.ToolCallRecord) error
- func (rs *RedisStore) Set(ctx context.Context, collection, key string, value any) error
- func (rs *RedisStore) TrimMessages(ctx context.Context, agentID string, maxMessages int) error
- type Store
- type StoreError
- type StoreType
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound 资源未找到错误 ErrNotFound = &StoreError{Code: "not_found", Message: "resource not found"} // ErrAlreadyExists 资源已存在错误 ErrAlreadyExists = &StoreError{Code: "already_exists", Message: "resource already exists"} )
Functions ¶
Types ¶
type AgentMessage ¶ added in v0.32.0
type AgentMessage struct {
ID uint `gorm:"primaryKey"`
AgentID string `gorm:"index;size:255"`
Messages string `gorm:"type:longtext"` // JSON 存储
CreatedAt time.Time `gorm:"autoCreateTime"`
UpdatedAt time.Time `gorm:"autoUpdateTime"`
}
MySQL 数据模型
type AgentSnapshot ¶ added in v0.32.0
type AgentToolRecord ¶ added in v0.32.0
type CollectionItem ¶ added in v0.32.0
type CollectionItem struct {
ID uint `gorm:"primaryKey"`
Collection string `gorm:"index;size:255"`
Key string `gorm:"index;size:255"`
Data string `gorm:"type:longtext"` // JSON 存储
CreatedAt time.Time `gorm:"autoCreateTime"`
UpdatedAt time.Time `gorm:"autoUpdateTime"`
}
func (CollectionItem) TableName ¶ added in v0.32.0
func (CollectionItem) TableName() string
type Config ¶ added in v0.31.0
type Config struct {
Type StoreType `json:"type" yaml:"type"` // Store 类型: json, redis, mysql
// JSON Store 配置
DataDir string `json:"data_dir,omitempty" yaml:"data_dir,omitempty"` // 数据目录
// Redis Store 配置
RedisAddr string `json:"redis_addr,omitempty" yaml:"redis_addr,omitempty"` // Redis 地址
RedisPassword string `json:"redis_password,omitempty" yaml:"redis_password,omitempty"` // Redis 密码
RedisDB int `json:"redis_db,omitempty" yaml:"redis_db,omitempty"` // Redis 数据库
RedisPrefix string `json:"redis_prefix,omitempty" yaml:"redis_prefix,omitempty"` // Redis Key 前缀
RedisTTL time.Duration `json:"redis_ttl,omitempty" yaml:"redis_ttl,omitempty"` // Redis 数据过期时间
// MySQL Store 配置
MySQLDSN string `json:"mysql_dsn,omitempty" yaml:"mysql_dsn,omitempty"` // MySQL DSN
MySQLMaxOpenConns int `json:"mysql_max_open_conns,omitempty" yaml:"mysql_max_open_conns,omitempty"` // 最大打开连接数
MySQLMaxIdleConns int `json:"mysql_max_idle_conns,omitempty" yaml:"mysql_max_idle_conns,omitempty"` // 最大空闲连接数
MySQLMaxLifetime time.Duration `json:"mysql_max_lifetime,omitempty" yaml:"mysql_max_lifetime,omitempty"` // 连接最大生命周期
}
Config Store 配置
type JSONStore ¶
type JSONStore struct {
// contains filtered or unexported fields
}
JSONStore JSON文件存储实现
func (*JSONStore) DeleteAgent ¶
DeleteAgent 删除Agent所有数据
func (*JSONStore) ListAgents ¶
ListAgents 列出所有Agent
func (*JSONStore) ListSnapshots ¶
ListSnapshots 列出快照
func (*JSONStore) LoadMessages ¶
LoadMessages 加载消息列表
func (*JSONStore) LoadSnapshot ¶
func (js *JSONStore) LoadSnapshot(ctx context.Context, agentID string, snapshotID string) (*types.Snapshot, error)
LoadSnapshot 加载快照
func (*JSONStore) LoadToolCallRecords ¶
func (js *JSONStore) LoadToolCallRecords(ctx context.Context, agentID string) ([]types.ToolCallRecord, error)
LoadToolCallRecords 加载工具调用记录
func (*JSONStore) SaveMessages ¶
func (js *JSONStore) SaveMessages(ctx context.Context, agentID string, messages []types.Message) error
SaveMessages 保存消息列表
func (*JSONStore) SaveSnapshot ¶
func (js *JSONStore) SaveSnapshot(ctx context.Context, agentID string, snapshot types.Snapshot) error
SaveSnapshot 保存快照
func (*JSONStore) SaveToolCallRecords ¶
func (js *JSONStore) SaveToolCallRecords(ctx context.Context, agentID string, records []types.ToolCallRecord) error
SaveToolCallRecords 保存工具调用记录
type MySQLConfig ¶ added in v0.32.0
type MySQLConfig struct {
DSN string // MySQL DSN
MaxOpenConns int // 最大打开连接数
MaxIdleConns int // 最大空闲连接数
MaxLifetime time.Duration // 连接最大生命周期
}
MySQLConfig MySQL 存储配置
type MySQLStore ¶ added in v0.32.0
type MySQLStore struct {
// contains filtered or unexported fields
}
MySQLStore MySQL 存储实现
func NewMySQLStore ¶ added in v0.32.0
func NewMySQLStore(config MySQLConfig) (*MySQLStore, error)
NewMySQLStore 创建 MySQL 存储
func (*MySQLStore) Delete ¶ added in v0.32.0
func (s *MySQLStore) Delete(ctx context.Context, collection, key string) error
Delete 删除资源
func (*MySQLStore) DeleteAgent ¶ added in v0.32.0
func (s *MySQLStore) DeleteAgent(ctx context.Context, agentID string) error
DeleteAgent 删除Agent所有数据
func (*MySQLStore) ListAgents ¶ added in v0.32.0
func (s *MySQLStore) ListAgents(ctx context.Context) ([]string, error)
ListAgents 列出所有Agent
func (*MySQLStore) ListSnapshots ¶ added in v0.32.0
ListSnapshots 列出快照
func (*MySQLStore) LoadMessages ¶ added in v0.32.0
LoadMessages 加载消息列表
func (*MySQLStore) LoadSnapshot ¶ added in v0.32.0
func (s *MySQLStore) LoadSnapshot(ctx context.Context, agentID string, snapshotID string) (*types.Snapshot, error)
LoadSnapshot 加载快照
func (*MySQLStore) LoadToolCallRecords ¶ added in v0.32.0
func (s *MySQLStore) LoadToolCallRecords(ctx context.Context, agentID string) ([]types.ToolCallRecord, error)
LoadToolCallRecords 加载工具调用记录
func (*MySQLStore) SaveMessages ¶ added in v0.32.0
func (s *MySQLStore) SaveMessages(ctx context.Context, agentID string, messages []types.Message) error
SaveMessages 保存消息列表
func (*MySQLStore) SaveSnapshot ¶ added in v0.32.0
func (s *MySQLStore) SaveSnapshot(ctx context.Context, agentID string, snapshot types.Snapshot) error
SaveSnapshot 保存快照
func (*MySQLStore) SaveToolCallRecords ¶ added in v0.32.0
func (s *MySQLStore) SaveToolCallRecords(ctx context.Context, agentID string, records []types.ToolCallRecord) error
SaveToolCallRecords 保存工具调用记录
func (*MySQLStore) TrimMessages ¶ added in v0.32.0
TrimMessages 修剪消息列表
type RedisConfig ¶ added in v0.31.0
type RedisConfig struct {
Addr string // Redis 地址,格式: "host:port"
Password string // 密码
DB int // 数据库编号 (0-15)
Prefix string // Key 前缀,默认 "aster:"
TTL time.Duration // 数据过期时间,默认 7 天
}
RedisConfig Redis 配置
type RedisStore ¶ added in v0.31.0
type RedisStore struct {
// contains filtered or unexported fields
}
RedisStore Redis 持久化存储 适用于分布式环境,支持多节点共享状态
func NewRedisStore ¶ added in v0.31.0
func NewRedisStore(config RedisConfig) (*RedisStore, error)
NewRedisStore 创建 Redis Store
func (*RedisStore) Delete ¶ added in v0.31.0
func (rs *RedisStore) Delete(ctx context.Context, collection, key string) error
Delete 删除资源
func (*RedisStore) DeleteAgent ¶ added in v0.31.0
func (rs *RedisStore) DeleteAgent(ctx context.Context, agentID string) error
DeleteAgent 删除 Agent 所有数据
func (*RedisStore) ListAgents ¶ added in v0.31.0
func (rs *RedisStore) ListAgents(ctx context.Context) ([]string, error)
ListAgents 列出所有 Agent
func (*RedisStore) ListSnapshots ¶ added in v0.31.0
ListSnapshots 列出快照
func (*RedisStore) LoadMessages ¶ added in v0.31.0
LoadMessages 加载消息列表
func (*RedisStore) LoadSnapshot ¶ added in v0.31.0
func (rs *RedisStore) LoadSnapshot(ctx context.Context, agentID string, snapshotID string) (*types.Snapshot, error)
LoadSnapshot 加载快照
func (*RedisStore) LoadToolCallRecords ¶ added in v0.31.0
func (rs *RedisStore) LoadToolCallRecords(ctx context.Context, agentID string) ([]types.ToolCallRecord, error)
LoadToolCallRecords 加载工具调用记录
func (*RedisStore) Ping ¶ added in v0.31.0
func (rs *RedisStore) Ping(ctx context.Context) error
Ping 检查 Redis 连接
func (*RedisStore) SaveMessages ¶ added in v0.31.0
func (rs *RedisStore) SaveMessages(ctx context.Context, agentID string, messages []types.Message) error
SaveMessages 保存消息列表
func (*RedisStore) SaveSnapshot ¶ added in v0.31.0
func (rs *RedisStore) SaveSnapshot(ctx context.Context, agentID string, snapshot types.Snapshot) error
SaveSnapshot 保存快照
func (*RedisStore) SaveToolCallRecords ¶ added in v0.31.0
func (rs *RedisStore) SaveToolCallRecords(ctx context.Context, agentID string, records []types.ToolCallRecord) error
SaveToolCallRecords 保存工具调用记录
func (*RedisStore) TrimMessages ¶ added in v0.31.0
TrimMessages 修剪消息列表(原子操作)
type Store ¶
type Store interface {
// SaveMessages 保存消息列表
SaveMessages(ctx context.Context, agentID string, messages []types.Message) error
// LoadMessages 加载消息列表
LoadMessages(ctx context.Context, agentID string) ([]types.Message, error)
// TrimMessages 修剪消息列表,保留最近的 N 条消息
// 如果 maxMessages <= 0,则不修剪
TrimMessages(ctx context.Context, agentID string, maxMessages int) error
// SaveToolCallRecords 保存工具调用记录
SaveToolCallRecords(ctx context.Context, agentID string, records []types.ToolCallRecord) error
// LoadToolCallRecords 加载工具调用记录
LoadToolCallRecords(ctx context.Context, agentID string) ([]types.ToolCallRecord, error)
// SaveSnapshot 保存快照
SaveSnapshot(ctx context.Context, agentID string, snapshot types.Snapshot) error
// LoadSnapshot 加载快照
LoadSnapshot(ctx context.Context, agentID string, snapshotID string) (*types.Snapshot, error)
// ListSnapshots 列出快照
ListSnapshots(ctx context.Context, agentID string) ([]types.Snapshot, error)
// SaveInfo 保存Agent元信息
SaveInfo(ctx context.Context, agentID string, info types.AgentInfo) error
// LoadInfo 加载Agent元信息
LoadInfo(ctx context.Context, agentID string) (*types.AgentInfo, error)
// SaveTodos 保存Todo列表
SaveTodos(ctx context.Context, agentID string, todos any) error
// LoadTodos 加载Todo列表
LoadTodos(ctx context.Context, agentID string) (any, error)
// DeleteAgent 删除Agent所有数据
DeleteAgent(ctx context.Context, agentID string) error
// ListAgents 列出所有Agent
ListAgents(ctx context.Context) ([]string, error)
// Get 获取单个资源
Get(ctx context.Context, collection, key string, dest any) error
// Set 设置资源
Set(ctx context.Context, collection, key string, value any) error
// Delete 删除资源
Delete(ctx context.Context, collection, key string) error
// List 列出资源
List(ctx context.Context, collection string) ([]any, error)
// Exists 检查资源是否存在
Exists(ctx context.Context, collection, key string) (bool, error)
}
Store 持久化存储接口
func MustNewStore ¶ added in v0.31.0
MustNewStore 创建 Store,失败时 panic
type StoreError ¶
StoreError Store 错误类型
func (*StoreError) Error ¶
func (e *StoreError) Error() string
func (*StoreError) Unwrap ¶
func (e *StoreError) Unwrap() error