utils

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const ThinkingSep = "\x02"

ThinkingSep 是思考文本与正文之间的分隔标记。 StreamFilter 在思考文本段前插入此标记,TUI 据此切换渲染样式。

Variables

This section is empty.

Functions

func CleanInputLine

func CleanInputLine(s string) string

CleanInputLine 清洗单行人工输入,并去掉首尾空白。

func CleanInputRunes

func CleanInputRunes(runes []rune) string

func CleanInputText

func CleanInputText(s string) string

CleanInputText 删除终端输入中没有业务意义的控制字符,保留用户可见文本。 单行输入场景下,粘贴文本里的换行和制表符会被归一为空格。

func ContainsControl

func ContainsControl(s string) bool

Types

type JSONFieldExtractor

type JSONFieldExtractor struct {
	// contains filtered or unexported fields
}

JSONFieldExtractor 从流式 JSON 碎片中提取指定字段的字符串值。

LLM 流式生成 tool call 时,参数是逐片段到达的(OpenAI/Anthropic) 或一次性到达的(Gemini)。本提取器用状态机逐字符扫描, 检测到目标 key 后提取其字符串值,处理 JSON 转义。

func NewFieldExtractor

func NewFieldExtractor(fieldName string) *JSONFieldExtractor

func (*JSONFieldExtractor) Feed

func (e *JSONFieldExtractor) Feed(delta string) string

Feed 处理一段 delta,返回提取到的文本(可能为空)。

func (*JSONFieldExtractor) Reset

func (e *JSONFieldExtractor) Reset()

Reset 重置状态(新 LLM 消息轮次时调用)。

type StreamFilter

type StreamFilter struct {
	// contains filtered or unexported fields
}

StreamFilter 区分 SubAgent 的文本回复和 JSON 工具调用。 文本回复标记为思考内容(前缀 ThinkingSep);JSON 工具调用只提取指定字段。

判断依据:遇到 { 进入 JSON 模式(追踪大括号深度), 深度归零后回到文本模式。

func NewStreamFilter

func NewStreamFilter(fieldName string) *StreamFilter

func (*StreamFilter) Feed

func (f *StreamFilter) Feed(delta string) string

Feed 处理一段 delta,返回可展示文本。 文本回复直接输出;JSON 中的目标字段值被提取输出;其余 JSON 结构丢弃。

func (*StreamFilter) Reset

func (f *StreamFilter) Reset()

Reset 重置状态。

Jump to

Keyboard shortcuts

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