新增世界书模块

This commit is contained in:
2026-02-11 14:55:41 +08:00
parent 1757b92b5f
commit 2bca8e2788
15 changed files with 2311 additions and 11 deletions

View File

@@ -9,18 +9,57 @@ import (
// AIWorldInfo 世界书World Info
type AIWorldInfo struct {
global.GVA_MODEL
UserID uint `json:"userId" gorm:"not null;index;comment:所属用户ID"`
User *AppUser `json:"user" gorm:"foreignKey:UserID"`
CharacterID *uint `json:"characterId" gorm:"index;comment:关联角色ID"`
Character *AICharacter `json:"character" gorm:"foreignKey:CharacterID"`
Name string `json:"name" gorm:"type:varchar(500);not null;comment:世界书名称"`
Keywords pq.StringArray `json:"keywords" gorm:"type:text[];comment:触发关键词"`
Content string `json:"content" gorm:"type:text;not null;comment:内容"`
Priority int `json:"priority" gorm:"default:0;comment:优先级"`
IsEnabled bool `json:"isEnabled" gorm:"default:true;comment:是否启用"`
TriggerConfig datatypes.JSON `json:"triggerConfig" gorm:"type:jsonb;comment:触发条件配置"`
UserID uint `json:"userId" gorm:"not null;index;comment:所属用户ID"`
User *AppUser `json:"user" gorm:"foreignKey:UserID"`
BookName string `json:"bookName" gorm:"type:varchar(500);not null;index;comment:世界书名称"`
IsGlobal bool `json:"isGlobal" gorm:"default:false;index;comment:是否全局世界书"`
Entries datatypes.JSON `json:"entries" gorm:"type:jsonb;not null;comment:世界书条目列表"`
LinkedChars pq.StringArray `json:"linkedChars" gorm:"type:text[];comment:关联的角色ID列表"`
}
func (AIWorldInfo) TableName() string {
return "ai_world_info"
}
// AIWorldInfoEntry 世界书条目(存储在 AIWorldInfo.Entries 中)
type AIWorldInfoEntry struct {
UID string `json:"uid"` // 条目唯一ID
Keys []string `json:"keys"` // 主要关键词
SecondaryKeys []string `json:"secondary_keys"` // 次要关键词(可选匹配)
Content string `json:"content"` // 条目内容
Comment string `json:"comment"` // 备注
Enabled bool `json:"enabled"` // 是否启用
Constant bool `json:"constant"` // 永远激活
Selective bool `json:"selective"` // 选择性激活(需要主键+次键都匹配)
Order int `json:"order"` // 插入顺序(越小越靠前)
Position string `json:"position"` // 插入位置before_char, after_char
Depth int `json:"depth"` // 扫描深度(从最近消息往前扫描几条)
Probability int `json:"probability"` // 激活概率0-100
UseProbability bool `json:"use_probability"` // 是否使用概率
Group string `json:"group"` // 分组(同组只激活一个)
GroupOverride bool `json:"group_override"` // 分组覆盖
GroupWeight int `json:"group_weight"` // 分组权重
PreventRecursion bool `json:"prevent_recursion"` // 防止递归激活
DelayUntilRecursion bool `json:"delay_until_recursion"` // 延迟到递归时激活
ScanDepth *int `json:"scan_depth"` // 扫描深度nil=使用全局设置)
CaseSensitive *bool `json:"case_sensitive"` // 大小写敏感nil=使用全局设置)
MatchWholeWords *bool `json:"match_whole_words"` // 匹配整个单词
UseRegex *bool `json:"use_regex"` // 使用正则表达式
Automation string `json:"automation_id"` // 自动化ID
Role string `json:"role"` // 角色system/user/assistant
VectorizedContent string `json:"vectorized"` // 向量化的内容ID
Extensions map[string]interface{} `json:"extensions"` // 扩展数据
}
// AICharacterWorldInfo 角色关联的世界书(中间表)
type AICharacterWorldInfo struct {
global.GVA_MODEL
CharacterID uint `json:"characterId" gorm:"not null;index:idx_char_world,unique;comment:角色ID"`
Character *AICharacter `json:"character" gorm:"foreignKey:CharacterID"`
WorldInfoID uint `json:"worldInfoId" gorm:"not null;index:idx_char_world,unique;comment:世界书ID"`
WorldInfo *AIWorldInfo `json:"worldInfo" gorm:"foreignKey:WorldInfoID"`
}
func (AICharacterWorldInfo) TableName() string {
return "ai_character_world_info"
}