24f827fe02
添加 review_parser.go 从 LLM 输出中提取 Markdown 和代码块,创建独立 ReviewMessage 类型 (markdown/code/search_result)。前端新增安全 Markdown 渲染器 (HTML 转义优先),代码块以深色背景+语言标签展示。Markdown/代码 类型禁止断句拆分,避免格式损坏。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
169 lines
6.9 KiB
Go
169 lines
6.9 KiB
Go
package model
|
|
|
|
import "time"
|
|
|
|
// SubSessionType 子会话类型
|
|
type SubSessionType string
|
|
|
|
const (
|
|
SubSessionMemory SubSessionType = "memory" // 记忆检索子会话
|
|
SubSessionIoT SubSessionType = "iot" // IoT 控制子会话
|
|
SubSessionGeneral SubSessionType = "general" // 通用对话子会话
|
|
SubSessionKnowledge SubSessionType = "knowledge" // 知识库查询子会话 (预留)
|
|
SubSessionWebSearch SubSessionType = "web_search" // 网络搜索子会话 (预留)
|
|
SubSessionReview SubSessionType = "review" // 最终审查子会话
|
|
)
|
|
|
|
// SubSessionStatus 子会话状态
|
|
type SubSessionStatus string
|
|
|
|
const (
|
|
SubSessionPending SubSessionStatus = "pending"
|
|
SubSessionRunning SubSessionStatus = "running"
|
|
SubSessionCompleted SubSessionStatus = "completed"
|
|
SubSessionFailed SubSessionStatus = "failed"
|
|
SubSessionTimeout SubSessionStatus = "timeout"
|
|
)
|
|
|
|
// SubSession 子会话 — 内部处理单元
|
|
type SubSession struct {
|
|
ID string `json:"id"`
|
|
ParentID string `json:"parent_id"` // 主会话 ID
|
|
Type SubSessionType `json:"type"`
|
|
Status SubSessionStatus `json:"status"`
|
|
SystemPrompt string `json:"system_prompt"` // 该子会话专用的系统提示词
|
|
Context []LLMMessage `json:"-"` // LLM 上下文 (内存中)
|
|
Result *SubSessionResult `json:"result,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
CompletedAt *time.Time `json:"completed_at,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
}
|
|
|
|
// SubSessionResult 子会话处理结果
|
|
type SubSessionResult struct {
|
|
Type SubSessionType `json:"type"` // 子会话类型
|
|
Summary string `json:"summary"` // 结果摘要 (供主会话参考)
|
|
Details string `json:"details"` // 详细信息
|
|
ToolCalls []ToolCallRecord `json:"tool_calls"` // 工具调用记录
|
|
Memories []MemorySnippet `json:"memories"` // 检索到的记忆片段
|
|
Confidence float64 `json:"confidence"` // 置信度 0-1
|
|
Progress float64 `json:"progress"` // 执行进度 0.0 ~ 1.0
|
|
Error string `json:"error,omitempty"`
|
|
Metadata map[string]any `json:"metadata"` // 类型特定的元数据
|
|
}
|
|
|
|
// ToolCallRecord 工具调用记录
|
|
type ToolCallRecord struct {
|
|
Name string `json:"name"`
|
|
Arguments map[string]any `json:"arguments"`
|
|
Result any `json:"result"`
|
|
}
|
|
|
|
// MemorySnippet 记忆片段 (供子会话返回)
|
|
type MemorySnippet struct {
|
|
ID string `json:"id"`
|
|
Content string `json:"content"`
|
|
Category string `json:"category"`
|
|
Importance int `json:"importance"`
|
|
Relevance float64 `json:"relevance"` // 与当前查询的相关度
|
|
}
|
|
|
|
// IntentResult 意图分析结果
|
|
type IntentResult struct {
|
|
Primary string `json:"primary"` // 主要意图
|
|
SubIntents []string `json:"sub_intents"` // 次要意图
|
|
Entities map[string]string `json:"entities"` // 实体提取
|
|
NeedsIoT bool `json:"needs_iot"` // 是否需要 IoT 控制
|
|
NeedsMemory bool `json:"needs_memory"` // 是否需要深度记忆检索
|
|
NeedsKnowledge bool `json:"needs_knowledge"` // 是否需要知识库查询
|
|
Urgency string `json:"urgency"` // 紧急程度: low/medium/high
|
|
Sentiment string `json:"sentiment"` // 情感: positive/neutral/negative
|
|
}
|
|
|
|
// MainSessionStatus 主会话状态
|
|
type MainSessionStatus string
|
|
|
|
const (
|
|
MainSessionIdle MainSessionStatus = "idle"
|
|
MainSessionThinking MainSessionStatus = "thinking"
|
|
MainSessionStreaming MainSessionStatus = "streaming"
|
|
)
|
|
|
|
// MultiMessage 多条消息的容器 (用于单次发送多条短消息)
|
|
type MultiMessage struct {
|
|
Messages []MultiMessageItem `json:"messages"`
|
|
}
|
|
|
|
// MultiMessageItem 多消息中的单条
|
|
type MultiMessageItem struct {
|
|
Index int `json:"index"`
|
|
Content string `json:"content"`
|
|
}
|
|
|
|
// StreamEvent 流式事件
|
|
type StreamEvent struct {
|
|
Type StreamEventType `json:"type"` // delta, segments, done, error, review, thinking, tool_progress, system_info
|
|
Delta string `json:"delta,omitempty"` // 逐 token delta
|
|
Segments []Segment `json:"segments,omitempty"` // 断句片段
|
|
ReviewMessages []ReviewMessage `json:"review_messages,omitempty"` // 审查后的带类型消息
|
|
ThinkingContent string `json:"thinking_content,omitempty"` // 思考内容
|
|
ToolProgress *ToolProgressInfo `json:"tool_progress,omitempty"` // 工具进度
|
|
SystemInfo *SystemInfoPayload `json:"system_info,omitempty"` // 系统信息
|
|
ProtocolVersion int `json:"protocol_version,omitempty"` // 协议版本
|
|
Error error `json:"-"` // 内部错误
|
|
}
|
|
|
|
// ToolProgressInfo 工具执行进度
|
|
type ToolProgressInfo struct {
|
|
ToolName string `json:"tool_name"`
|
|
Status string `json:"status"` // started, running, completed, failed
|
|
Progress float64 `json:"progress"`
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
// SystemInfoPayload 系统信息负载
|
|
type SystemInfoPayload struct {
|
|
Level string `json:"level"` // info, warning, error
|
|
Message string `json:"message"`
|
|
Action string `json:"action,omitempty"`
|
|
}
|
|
|
|
// StreamEventType 流式事件类型
|
|
type StreamEventType string
|
|
|
|
const (
|
|
StreamDelta StreamEventType = "delta"
|
|
StreamSegments StreamEventType = "segments"
|
|
StreamDone StreamEventType = "done"
|
|
StreamError StreamEventType = "error"
|
|
StreamReview StreamEventType = "review" // 审查后的带类型消息
|
|
StreamThinking StreamEventType = "thinking" // 思考内容
|
|
StreamToolProgress StreamEventType = "tool_progress" // 工具执行进度
|
|
StreamSystemInfo StreamEventType = "system_info" // 系统通知
|
|
)
|
|
|
|
// ReviewMessageType 审查消息类型
|
|
type ReviewMessageType string
|
|
|
|
const (
|
|
ReviewMessageAction ReviewMessageType = "action" // 动作消息 (括号内容)
|
|
ReviewMessageChat ReviewMessageType = "chat" // 聊天消息 (普通文本)
|
|
ReviewMessageMarkdown ReviewMessageType = "markdown" // Markdown 格式内容 (标题/列表/表格/链接/粗斜体等)
|
|
ReviewMessageCode ReviewMessageType = "code" // 代码块 (带语言标识)
|
|
ReviewMessageSearchResult ReviewMessageType = "search_result" // 单条搜索结果
|
|
)
|
|
|
|
// ReviewMessage 审查后的消息
|
|
type ReviewMessage struct {
|
|
Type ReviewMessageType `json:"type"`
|
|
Content string `json:"content"`
|
|
DelayMs int `json:"delay_ms,omitempty"` // ms to wait before sending (0 = immediate)
|
|
Metadata map[string]any `json:"metadata,omitempty"` // 类型特定元数据 (code语言、搜索结果URL等)
|
|
}
|
|
|
|
// Segment 语音片段
|
|
type Segment struct {
|
|
Index int `json:"index"`
|
|
Text string `json:"text"`
|
|
}
|