Files
Cyrene/backend/ai-core/internal/model/sub_session.go
T
AskaEth a058b0ab8e fix: 第一轮修复 - 记忆管理/IoT操控/历史消息持久化/动作消息/链路优化/安全配置
- 修复记忆管理数据库连接不可用 (ai-core重编译+Unicode修复)
- 修复IoT子会话工具调用链路日志缺失
- 新增最终审查子会话(review_provider) 支持消息格式解析拆分
- 实现历史消息持久化(后端存储+前端分页加载)
- 前端新增动作消息(ActionMessage)类型和渲染
- 优化对话链路速度(非阻塞子会话+快速问候通道)
- JWT密钥环境变量化(无默认值启动panic)
- Token自动刷新机制(401拦截器+refresh接口)
- WebSocket指数退避重连(jitter+最大10次)
- localStorage清理一致性(cyrene_前缀+版本检查)
- IoT环境变量统一为IOT_SERVICE_URL
2026-05-21 23:10:07 +08:00

141 lines
5.2 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
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
Delta string `json:"delta,omitempty"` // 逐 token delta
Segments []Segment `json:"segments,omitempty"` // 断句片段
ReviewMessages []ReviewMessage `json:"review_messages,omitempty"` // 审查后的带类型消息
Error error `json:"-"` // 内部错误
}
// StreamEventType 流式事件类型
type StreamEventType string
const (
StreamDelta StreamEventType = "delta"
StreamSegments StreamEventType = "segments"
StreamDone StreamEventType = "done"
StreamError StreamEventType = "error"
StreamReview StreamEventType = "review" // 审查后的带类型消息
)
// ReviewMessageType 审查消息类型
type ReviewMessageType string
const (
ReviewMessageAction ReviewMessageType = "action" // 动作消息 (括号内容)
ReviewMessageChat ReviewMessageType = "chat" // 聊天消息 (引号/普通内容)
)
// ReviewMessage 审查后的消息
type ReviewMessage struct {
Type ReviewMessageType `json:"type"`
Content string `json:"content"`
}
// Segment 语音片段
type Segment struct {
Index int `json:"index"`
Text string `json:"text"`
}