195 lines
8.5 KiB
Go
195 lines
8.5 KiB
Go
package ctxmgr
|
|
|
|
import (
|
|
"time"
|
|
|
|
"chat-agent-system/internal/storage"
|
|
)
|
|
|
|
// CommunicationStyle 用户沟通风格
|
|
type CommunicationStyle string
|
|
|
|
const (
|
|
StyleConciseStructured CommunicationStyle = "concise_structured" // 结构精炼、结论先行、拒绝冗长
|
|
StyleDetailedAnalytical CommunicationStyle = "detailed_analytical" // 详尽论证、全面对比、深挖细节
|
|
StyleExecutiveSummary CommunicationStyle = "executive_summary" // 高管要点、商业决策导向
|
|
)
|
|
|
|
// UserPreference 用户工作习惯与产出偏好画像
|
|
type UserPreference struct {
|
|
UserID int64 `json:"user_id"`
|
|
AccountID string `json:"account_id"`
|
|
Name string `json:"name"`
|
|
Role string `json:"role"`
|
|
CommunicationStyle CommunicationStyle `json:"communication_style"`
|
|
FocusAreas []string `json:"focus_areas"` // 关注维度,如 "reg_compliance", "cost_budget", "timeline", "optical_quality"
|
|
OutputFormatPref string `json:"output_format_pref"` // 报告格式要求,如 "standard_report", "bilingual_brief", "ppt_bullets"
|
|
CustomInstructions string `json:"custom_instructions"` // 用户直接指定的定制要求
|
|
MemoryFacts map[string]string `json:"memory_facts"` // 异步蒸馏出的长期事实记忆 (如 "预算通常按千万级申报", "偏好使用迈瑞作为对标竞品")
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// ActivityItem 项目活动记录 (操作、决策、上传、下载)
|
|
type ActivityItem struct {
|
|
ID int64 `json:"id"`
|
|
ProjectID int64 `json:"project_id"`
|
|
UserID int64 `json:"user_id"`
|
|
UserName string `json:"user_name"`
|
|
ActivityType string `json:"activity_type"` // decision, operation, upload, download, stage_advance, chat
|
|
Title string `json:"title"`
|
|
Detail map[string]any `json:"detail,omitempty"`
|
|
RawWeight float64 `json:"raw_weight"` // 初始权重
|
|
DecayedWeight float64 `json:"decayed_weight"`// 时间衰减后当前有效权重
|
|
IsMilestone bool `json:"is_milestone"` // 里程碑事件不衰减
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
// TimeDecayConfig 时间权重衰减配置
|
|
type TimeDecayConfig struct {
|
|
Enabled bool `json:"enabled"`
|
|
HalfLifeDays float64 `json:"half_life_days"` // 半衰期天数 (如 7.0 天)
|
|
MinWeightFloor float64 `json:"min_weight_floor"` // 权重衰减下限 (如 0.10,防止被完全抹除)
|
|
MilestoneExempt bool `json:"milestone_exempt"` // 里程碑事件是否豁免衰减 (默认 true)
|
|
}
|
|
|
|
// DefaultTimeDecayConfig 默认时间衰减配置
|
|
func DefaultTimeDecayConfig() TimeDecayConfig {
|
|
return TimeDecayConfig{
|
|
Enabled: true,
|
|
HalfLifeDays: 7.0,
|
|
MinWeightFloor: 0.15,
|
|
MilestoneExempt: true,
|
|
}
|
|
}
|
|
|
|
// SingleUserContext 单用户私有上下文
|
|
type SingleUserContext struct {
|
|
UserID int64 `json:"user_id"`
|
|
AccountID string `json:"account_id"`
|
|
Name string `json:"name"`
|
|
Role string `json:"role"`
|
|
Preference *UserPreference `json:"preference"`
|
|
SessionID string `json:"session_id"`
|
|
RecentChats []ChatMessageRecord `json:"recent_chats"`
|
|
MyActivities []ActivityItem `json:"my_activities"`
|
|
MyFiles []*storage.FileReference `json:"my_files"`
|
|
AssembledAt time.Time `json:"assembled_at"`
|
|
}
|
|
|
|
// ProjectCollectiveContext 项目级多方协同上下文
|
|
type ProjectCollectiveContext struct {
|
|
ProjectID int64 `json:"project_id"`
|
|
ProjectCode string `json:"project_code"`
|
|
ProjectName string `json:"project_name"`
|
|
CurrentStage string `json:"current_stage"`
|
|
BlackboardFacts map[string]string `json:"blackboard_facts"`
|
|
AllActivities []ActivityItem `json:"all_activities"`
|
|
MilestoneDecisions []ActivityItem `json:"milestone_decisions"`
|
|
SharedFiles []*storage.FileReference `json:"shared_files"`
|
|
ParticipatingUsers []UserSummary `json:"participating_users"`
|
|
AssembledAt time.Time `json:"assembled_at"`
|
|
}
|
|
|
|
// UserSummary 参与项目的用户摘要
|
|
type UserSummary struct {
|
|
UserID int64 `json:"user_id"`
|
|
Name string `json:"name"`
|
|
Role string `json:"role"`
|
|
}
|
|
|
|
// ChatMessageRecord 结构化会话消息
|
|
type ChatMessageRecord struct {
|
|
ID int64 `json:"id"`
|
|
SessionID string `json:"session_id"`
|
|
UserID int64 `json:"user_id"`
|
|
Role string `json:"role"`
|
|
Content string `json:"content"`
|
|
Intent string `json:"intent,omitempty"`
|
|
Branch string `json:"branch,omitempty"`
|
|
Metadata map[string]any `json:"metadata,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
// BlendedSquadContext 智能体小队混合上下文 (用于注入到 Agent Prompt 中)
|
|
type BlendedSquadContext struct {
|
|
ProjectName string `json:"project_name"`
|
|
CurrentStage string `json:"current_stage"`
|
|
TaskKey string `json:"task_key"`
|
|
AgentRole string `json:"agent_role"`
|
|
BlackboardFacts map[string]string `json:"blackboard_facts"`
|
|
KeyDecisions []string `json:"key_decisions"`
|
|
RelevantFiles []string `json:"relevant_files"`
|
|
TriggerUserPreference *UserPreference `json:"trigger_user_preference,omitempty"`
|
|
PersonalizedGuidance string `json:"personalized_guidance"` // 针对当前用户偏好生成的注入指导语
|
|
AssembledAt time.Time `json:"assembled_at"`
|
|
}
|
|
|
|
// SessionFilter 历史会话查询过滤条件
|
|
type SessionFilter struct {
|
|
UserID int64 `json:"user_id,omitempty"`
|
|
ProjectID int64 `json:"project_id,omitempty"`
|
|
Limit int `json:"limit"`
|
|
Offset int `json:"offset"`
|
|
}
|
|
|
|
// ChatSessionSummary 会话摘要说明
|
|
type ChatSessionSummary struct {
|
|
SessionID string `json:"session_id"`
|
|
Title string `json:"title"`
|
|
UserID int64 `json:"user_id"`
|
|
ProjectID int64 `json:"project_id,omitempty"`
|
|
ProjectName string `json:"project_name,omitempty"`
|
|
MessageCount int `json:"message_count"`
|
|
LastMessage string `json:"last_message,omitempty"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// CaseRecommendationItem 相似标杆案例自推荐条目
|
|
type CaseRecommendationItem struct {
|
|
DocID string `json:"doc_id"`
|
|
ProjectID int64 `json:"project_id"`
|
|
ProjectName string `json:"project_name"`
|
|
TaskKey string `json:"task_key"`
|
|
ArtifactTitle string `json:"artifact_title"`
|
|
SectionTitle string `json:"section_title"`
|
|
SummarySnippet string `json:"summary_snippet"`
|
|
KeyRegulations []string `json:"key_regulations,omitempty"`
|
|
SimilarityScore float64 `json:"similarity_score"`
|
|
ApprovedAt string `json:"approved_at"`
|
|
}
|
|
|
|
// CaseSearchOptions 标杆案例语义检索参数
|
|
type CaseSearchOptions struct {
|
|
Query string `json:"query"`
|
|
TaskKey string `json:"task_key,omitempty"`
|
|
ExcludeDoc string `json:"exclude_doc,omitempty"`
|
|
Limit int `json:"limit"`
|
|
MinScore float64 `json:"min_score"`
|
|
}
|
|
|
|
// MemoryChunkItem 语义记忆切片结构
|
|
type MemoryChunkItem struct {
|
|
ID int64 `json:"id"`
|
|
Domain string `json:"domain"`
|
|
ProjectID int64 `json:"project_id"`
|
|
UserID int64 `json:"user_id"`
|
|
ReferenceID string `json:"reference_id"`
|
|
Title string `json:"title"`
|
|
Content string `json:"content"`
|
|
ChunkHash string `json:"chunk_hash"`
|
|
Embedding []float32 `json:"embedding,omitempty"`
|
|
ImportanceWeight float64 `json:"importance_weight"`
|
|
Metadata map[string]any `json:"metadata,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
// RestoredSessionContext 从持久化记录中重构的会话上下文
|
|
type RestoredSessionContext struct {
|
|
SessionID string `json:"session_id"`
|
|
UserID int64 `json:"user_id"`
|
|
ProjectID int64 `json:"project_id,omitempty"`
|
|
Title string `json:"title"`
|
|
Messages []ChatMessageRecord `json:"messages"`
|
|
Facts map[string]string `json:"facts,omitempty"`
|
|
}
|