Documentation
¶
Index ¶
- type ArtifactModel
- type Config
- type EventModel
- type Service
- func (s *Service) AppendEvent(ctx context.Context, sessionID string, event *session.Event) error
- func (s *Service) Close() error
- func (s *Service) Create(ctx context.Context, req *session.CreateRequest) (*session.SessionData, error)
- func (s *Service) Delete(ctx context.Context, sessionID string) error
- func (s *Service) Get(ctx context.Context, sessionID string) (*session.SessionData, error)
- func (s *Service) GetEvents(ctx context.Context, sessionID string, opts *session.EventOptions) ([]*session.Event, error)
- func (s *Service) GetState(ctx context.Context, sessionID string, scope string) (map[string]any, error)
- func (s *Service) List(ctx context.Context, userID string, opts *session.ListOptions) ([]*session.SessionData, error)
- type SessionModel
- type StateModel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArtifactModel ¶
type ArtifactModel struct {
ID string `gorm:"primaryKey;type:varchar(36)"`
SessionID string `gorm:"type:varchar(36);not null;index:idx_artifacts"`
Name string `gorm:"type:varchar(255);not null;index:idx_artifacts"`
Version int `gorm:"not null;index:idx_artifacts"`
Content []byte `gorm:"type:longblob"`
MimeType string `gorm:"type:varchar(100)"`
Size int64 `gorm:"default:0"`
CreatedAt time.Time `gorm:"not null;default:CURRENT_TIMESTAMP"`
// 唯一约束:同一 session 下,同一工件的同一版本只能有一条记录
Session SessionModel `gorm:"foreignKey:SessionID;references:ID"`
}
ArtifactModel MySQL 工件模型 对应表: session_artifacts
type Config ¶
type Config struct {
// DSN 数据库连接字符串
// 例如: "user:password@tcp(127.0.0.1:3306)/agentsdk?charset=utf8mb4&parseTime=True&loc=Local"
DSN string
// MaxIdleConns 最大空闲连接数
MaxIdleConns int
// MaxOpenConns 最大打开连接数
MaxOpenConns int
// ConnMaxLifetime 连接最大生命周期
ConnMaxLifetime time.Duration
// LogLevel GORM 日志级别
LogLevel logger.LogLevel
// AutoMigrate 是否自动迁移表结构
AutoMigrate bool
}
Config MySQL 配置
type EventModel ¶
type EventModel struct {
ID string `gorm:"primaryKey;type:varchar(36)"`
SessionID string `gorm:"type:varchar(36);not null;index:idx_session_events"`
InvocationID string `gorm:"type:varchar(255);not null;index:idx_invocation_events"`
Branch string `gorm:"type:varchar(500);not null;index:idx_branch_events"`
Author string `gorm:"type:varchar(255);not null"`
AgentID string `gorm:"type:varchar(255);not null"`
Timestamp time.Time `gorm:"not null;default:CURRENT_TIMESTAMP;index:idx_session_events"`
// 内容 - JSON 存储
Content []byte `gorm:"type:json;not null"`
// 动作 - JSON 存储
Actions []byte `gorm:"type:json"`
// 长时运行工具 ID 列表 - JSON 数组存储
LongRunningToolIDs []byte `gorm:"type:json"`
// 元数据 - JSON 存储
Metadata []byte `gorm:"type:json"`
// 关联关系
Session SessionModel `gorm:"foreignKey:SessionID;references:ID"`
}
EventModel MySQL 事件模型 对应表: session_events
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service MySQL Session 服务实现 支持 MySQL 8.0+ (JSON 列类型)
func (*Service) AppendEvent ¶
AppendEvent 实现 session.Service 接口
func (*Service) Create ¶
func (s *Service) Create(ctx context.Context, req *session.CreateRequest) (*session.SessionData, error)
Create 实现 session.Service 接口
func (*Service) GetEvents ¶
func (s *Service) GetEvents(ctx context.Context, sessionID string, opts *session.EventOptions) ([]*session.Event, error)
GetEvents 获取会话的所有事件
type SessionModel ¶
type SessionModel struct {
ID string `gorm:"primaryKey;type:varchar(36)"`
AppName string `gorm:"type:varchar(255);not null;index:idx_app_sessions"`
UserID string `gorm:"type:varchar(255);not null;index:idx_user_sessions"`
AgentID string `gorm:"type:varchar(255);not null;index:idx_agent_sessions"`
CreatedAt time.Time `gorm:"not null;default:CURRENT_TIMESTAMP"`
UpdatedAt time.Time `gorm:"not null;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;index:idx_user_sessions,idx_app_sessions"`
// 关联关系
States []StateModel `gorm:"foreignKey:SessionID;constraint:OnDelete:CASCADE"`
Events []EventModel `gorm:"foreignKey:SessionID;constraint:OnDelete:CASCADE"`
Artifacts []ArtifactModel `gorm:"foreignKey:SessionID;constraint:OnDelete:CASCADE"`
}
SessionModel MySQL 会话模型 对应表: sessions
type StateModel ¶
type StateModel struct {
SessionID string `gorm:"primaryKey;type:varchar(36)"`
Scope string `gorm:"primaryKey;type:varchar(50)"`
Key string `gorm:"primaryKey;type:varchar(255);column:key"` // key 是 MySQL 保留字,需要转义
Value []byte `gorm:"type:json;not null"` // MySQL 8.0+ JSON 类型
CreatedAt time.Time `gorm:"not null;default:CURRENT_TIMESTAMP"`
UpdatedAt time.Time `gorm:"not null;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"`
// 关联关系
Session SessionModel `gorm:"foreignKey:SessionID;references:ID"`
}
StateModel MySQL 状态模型 对应表: session_states
Click to show internal directories.
Click to hide internal directories.