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:uuid;default:gen_random_uuid()"`
SessionID string `gorm:"type:uuid;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:bytea"`
MimeType string `gorm:"type:varchar(100)"`
Size int64 `gorm:"default:0"`
CreatedAt time.Time `gorm:"not null;default:now()"`
// 唯一约束: 同一 session 下,同一工件的同一版本只能有一条记录
// 通过 GORM 索引实现
Session SessionModel `gorm:"foreignKey:SessionID;references:ID"`
}
ArtifactModel 工件版本数据库模型 对应表: session_artifacts 支持 EventActions.ArtifactDelta
type Config ¶
type Config struct {
// DSN 数据库连接字符串
// 例如: "host=localhost user=postgres password=postgres dbname=agentsdk port=5432 sslmode=disable"
DSN string
// MaxIdleConns 最大空闲连接数
MaxIdleConns int
// MaxOpenConns 最大打开连接数
MaxOpenConns int
// ConnMaxLifetime 连接最大生命周期
ConnMaxLifetime time.Duration
// LogLevel GORM 日志级别
LogLevel logger.LogLevel
// AutoMigrate 是否自动迁移表结构
AutoMigrate bool
}
Config PostgreSQL 配置
type EventModel ¶
type EventModel struct {
ID string `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
SessionID string `gorm:"type:uuid;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:now();index:idx_session_events"`
// 内容 - JSONB 存储
Content []byte `gorm:"type:jsonb;not null"`
// 动作 - JSONB 存储
Actions []byte `gorm:"type:jsonb"`
// 长时运行工具 ID 列表
LongRunningToolIDs pq.StringArray `gorm:"type:text[]"`
// 元数据 - JSONB 存储
Metadata []byte `gorm:"type:jsonb"`
// 关联关系
Session SessionModel `gorm:"foreignKey:SessionID;references:ID"`
}
EventModel 事件数据库模型 对应表: session_events
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service PostgreSQL Session 服务实现 参考 Google ADK-Go 的 session/database/ 实现
func NewService ¶
NewService 创建 PostgreSQL Session 服务
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:uuid;default:gen_random_uuid()"`
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:now()"`
UpdatedAt time.Time `gorm:"not null;default:now();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 会话数据库模型 对应表: sessions
type StateModel ¶
type StateModel struct {
SessionID string `gorm:"primaryKey;type:uuid"`
Scope string `gorm:"primaryKey;type:varchar(50)"` // app, user, session, temp
Key string `gorm:"primaryKey;type:varchar(255)"`
Value []byte `gorm:"type:jsonb;not null"` // JSONB 存储
CreatedAt time.Time `gorm:"not null;default:now()"`
UpdatedAt time.Time `gorm:"not null;default:now()"`
// 关联关系
Session SessionModel `gorm:"foreignKey:SessionID;references:ID"`
}
StateModel 状态数据库模型 对应表: session_states 支持分层状态: app/user/session/temp
Click to show internal directories.
Click to hide internal directories.