Help us shape the future of Go! Take the 2026 Go Developer Survey

setting

package
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const SettingsTokenBudget = 12000

SettingsTokenBudget 是注入 system 消息时设定的软上限(token)。 设计依据:12k 占 200k 上下文窗口 6%,中文 12k 约等于 6-9k 字,能装较完整的世界观/力量体系。 超预算时按 updated_at DESC 保留最近活跃的,末尾追加截断提示(让 LLM 知道有内容被截断、应合并而非新建)。

Variables

This section is empty.

Functions

func CountSettingsTokens

func CountSettingsTokens(items []SettingItem) (int, error)

CountSettingsTokens 估算设定列表全量 token 数(不截断),用于 App 层报告超预算状态。 与 FormatSettings 输出格式一致,但不做截断,返回完整文本的 token 数。 用于 GetNovelSettings 返回 token_count + over_budget,前端可据此显示但不阻塞。

func FormatSettings

func FormatSettings(items []SettingItem) (string, int)

FormatSettings 格式化设定列表为可读文本,每条带 id 前缀。 用于 NovelState 注入 system 消息,agent 看到后可通过 id 调 upsert_setting 更新。 空 items 返回空字符串。

排序:调用方(NovelState)SQL 已按 updated_at DESC 排序——最近活跃在前。 FormatSettings 信任调用方顺序,不重复排序。 超预算处理:逐条累加 token,超 SettingsTokenBudget 时停止拼接并丢弃剩余条目, 末尾追加截断提示。返回 (text, truncatedCount)。

v2 取消 is_global 后不再分组,单列表平铺。

Types

type ListOptions

type ListOptions struct {
	PageParams storage.PageParams
	Search     string // 空字符串=不过滤,按 content LIKE OR category LIKE 模糊匹配
	Order      string // 空字符串=默认 created_at ASC(重构前硬编码值,Order 保留约束)
}

ListOptions 是 ListByNovel 的可选参数。

type SettingItem

type SettingItem struct {
	ID        int64     `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
	NovelID   int64     `gorm:"column:novel_id;not null;index"     json:"novel_id"` // 必填,归属小说
	Category  string    `gorm:"column:category"                   json:"category"`  // 自由文本:世界观/力量体系/角色/地理/历史/物品
	Content   string    `gorm:"column:content;not null"           json:"content"`   // 自由文本,不强行结构化
	CreatedAt time.Time `gorm:"column:created_at;autoCreateTime"  json:"created_at"`
	UpdatedAt time.Time `gorm:"column:updated_at;autoUpdateTime"  json:"updated_at"`
}

SettingItem 是小说世界观/设定条目(in-fiction 事实)。 设定本质是小说级(v2 取消全局设定概念):跨小说复用的"通用力量体系"等不合理, 用户想要通用规则应放偏好(procedural)。 与 PreferenceItem 区分:Setting 装小说世界内事实(修仙等级、主角武器),Preference 装创作规则(用短句)。

func (SettingItem) TableName

func (SettingItem) TableName() string

TableName 指定 GORM 表名。

type Store

type Store struct {
	DB *gorm.DB
	// contains filtered or unexported fields
}

Store 管理 SettingItem 持久化。

func NewStore

func NewStore(db *gorm.DB, logger *slog.Logger) *Store

NewStore 创建 setting 存储。

func (*Store) ListByNovel

func (s *Store) ListByNovel(ctx context.Context, novelID int64, opts ListOptions) (*storage.PageResult[SettingItem], error)

ListByNovel 返回该小说的全部设定,前端展示用。 支持搜索(content/category LIKE)和分页,前端全量拉取(Size=-1)和全局搜索复用。

注:注入 LLM 走 agentcfg.NovelProfile 直接查 db(updated_at DESC,截断保留最近活跃的), 不经此方法;此方法只服务前端 + 全局搜索,排序 created_at ASC(最早在前,跟 preference store 一致)。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL