Documentation
¶
Overview ¶
normalize.go 复刻官方 session-title/normalize:把不可信标题文本清洗为单行 (剥离转义/控制字符/方向控制、空白归一),并按 UTF-8 字节预算截断而不拆字符。
Package sessiontitle 提供会话标题生成能力(任务 S08:Session Title)。
对齐上游:packages/storage/session-title
会话标题的派生路径(latest-wins fold)已在 M05 中通过 session/session-title 事件 与 FoldSessionTitle 投影实现。本包补齐「标题怎么算出来」这部分:
- Fallback:从首条用户消息内容取前缀(默认前 30 个 Unicode 字符)作为标题;
- LLM Helper:可选地注入一个 LLMAdapter,让模型基于首条消息生成更精炼的标题; LLM 失败或未启用时回退到 Fallback,保证标题永不缺失。
设计要点:
- 按 rune(Unicode 码点)截断而非按 byte,避免把多字节字符切断成乱码;
- 只依赖首条 user 消息,与事件折叠解耦,可独立单测;
- Generate 返回 {Title, Source},Source 标明标题来自 "llm" 还是 "fallback", 便于上层写入 session/title 事件时知晓来源。
Index ¶
- Variables
- func CleanTitle(input string) string
- func Fallback(firstUserMessage string) string
- func FallbackMax(firstUserMessage string, maxRunes int) string
- func Normalize(input string, maxBytes int) string
- func TrimTitle(s string) string
- func TruncateUTF8(input string, maxBytes int) string
- type Generator
- type Result
- type Source
Constants ¶
This section is empty.
Variables ¶
View Source
var FallbackSystemPrompt = "" /* 166-byte string literal not displayed */
FallbackSystemPrompt 内置的标题提练系统提示词:要求模型给出一句话精炼标题。
Functions ¶
func FallbackMax ¶
FallbackMax 按指定的最大字符数生成前缀标题。
func TruncateUTF8 ¶
TruncateUTF8 按 UTF-8 字节预算返回最长的完整 rune 前缀,不拆分字符。
Types ¶
type Generator ¶
type Generator struct {
// LLM 可选(nil 时强制走 fallback)。启用后模型基于首条用户消息提练标题。
LLM llm.LLMAdapter
// Model 显式指定用于标题生成的模型名;为空时由适配器默认决定。
Model string
// MaxRunes fallback 标题最大字符数;<=0 使用默认 30。
MaxRunes int
// System 传给 LLM 的系统提示词(可选,默认使用内置提练提示词)。
System string
// MaxTokens LLM 单次标题生成的最大 token 数。
MaxTokens int
}
Generator 依据是否启用 LLM helper 生成会话标题。
Click to show internal directories.
Click to hide internal directories.