feat: 第四轮大版本更新 — 修复4个严重Bug、2个UI Bug,实现自主思考重构与主-子会话架构
## 🐛 Bug 修复 - 修复前端对话无响应:消除 ChatContainer 中的双重 WebSocket 连接,优化 sendMessage 失败提示 - 修复 Memory-Service 数据库迁移失败:ai-core 和 memory-service 均添加 ALTER TABLE ADD COLUMN IF NOT EXISTS 模式演化 - 修复语音/STT 不可用:添加 MediaRecorder API 降级方案,修复 whisper-cli 输出文件名错误 - 修复仪表盘数据库按钮失效:补充按钮 ID 属性,重写 controlDB() 控制逻辑 ## 🎨 UI 修复 - 修正用户消息头像位置:从 flex-row-reverse 改为 justify-end - 移除空聊天列表的 emoji 占位图标 ## ✨ 新功能 - devtools 新增 STT 处理日志面板(环形缓冲区 + WebSocket 广播 + 可视化表格) - 新增 ADMIN_NICKNAME 环境变量,支持自定义管理员昵称 ## 🔧 改进 - 注册流程增加昵称必填字段(前后端同步) ## 🏗️ 架构重构 - 重构自主思考逻辑:从定时器轮询改为事件驱动(对话后触发 + 静默检测),优化提示词使其更自然人性化 - 实现主-子会话架构:新增 4 种子会话类型(general/memory/iot/knowledge),意图分析 → 并行分发 → 结果合成流程 ## 📄 新增文档 - docs/architecture/main-session-sub-session-design.md — 子会话架构设计文档
This commit is contained in:
@@ -22,3 +22,20 @@ type SessionCreateParams struct {
|
||||
Persona string `json:"persona"`
|
||||
Mode string `json:"mode"`
|
||||
}
|
||||
|
||||
// MainSession 主会话 — 用户可见的对话会话 (扩展 Session)
|
||||
type MainSession struct {
|
||||
ID string `json:"id"`
|
||||
UserID string `json:"user_id"`
|
||||
Title string `json:"title"`
|
||||
Persona string `json:"persona"`
|
||||
Mode string `json:"mode"`
|
||||
Status MainSessionStatus `json:"status"`
|
||||
MessageCount int `json:"message_count"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 新增字段
|
||||
SubSessions []string `json:"sub_sessions"` // 关联的子会话 ID 列表
|
||||
LastIntent *IntentResult `json:"last_intent"` // 最近一次意图分析结果
|
||||
}
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
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" // 网络搜索子会话 (预留)
|
||||
)
|
||||
|
||||
// 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
|
||||
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
|
||||
Delta string `json:"delta,omitempty"` // 逐 token delta
|
||||
Segments []Segment `json:"segments,omitempty"` // 断句片段
|
||||
Error error `json:"-"` // 内部错误
|
||||
}
|
||||
|
||||
// StreamEventType 流式事件类型
|
||||
type StreamEventType string
|
||||
|
||||
const (
|
||||
StreamDelta StreamEventType = "delta"
|
||||
StreamSegments StreamEventType = "segments"
|
||||
StreamDone StreamEventType = "done"
|
||||
StreamError StreamEventType = "error"
|
||||
)
|
||||
|
||||
// Segment 语音片段
|
||||
type Segment struct {
|
||||
Index int `json:"index"`
|
||||
Text string `json:"text"`
|
||||
}
|
||||
Reference in New Issue
Block a user