package app import ( "git.echol.cn/loser/st/server/global" "github.com/lib/pq" "gorm.io/datatypes" ) // 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"` 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" }