Files
smartmate/backend/model/active_schedule_session.go
Losita a3eaa9b2c2 Version: 0.9.61.dev.260501
后端:
1. 主动调度 graph + session bridge 收口——把 dry-run / select / preview / confirm / rerun 串成受限 graph,新增 active_schedule_sessions 缓存与聊天拦截,ready_preview 后释放回自由聊天
2. 会话与通知链路对齐——notification 统一绑定 conversation_id,action_url 指向 /assistant/{conversation_id},会话不存在改回 404 语义,避免 wrong param type 误导排障
3. estimated_sections 写入与主动调度消费链路补齐——任务创建、quick task 与随口记入口都透传估计节数,主动调度只消费落库值

前端:
4. AssistantPanel 最小适配主动调度预览与失败态——复用主动调度卡片/微调弹窗,补历史加载失败可见提示与跨账号会话拦截

文档:
5. 更新主动调度缺口分阶段实施计划和实现方案,标记阶段 0-2 收口并同步接力状态
2026-05-01 20:48:32 +08:00

83 lines
4.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package model
import "time"
const (
// ActiveScheduleSessionStatusWaitingUserReply 表示当前会话正在等待用户补充信息,后端应拦截普通聊天。
ActiveScheduleSessionStatusWaitingUserReply = "waiting_user_reply"
// ActiveScheduleSessionStatusRerunning 表示用户已回复,主动调度图正在重跑,后端仍需拦截普通聊天。
ActiveScheduleSessionStatusRerunning = "rerunning"
// ActiveScheduleSessionStatusReadyPreview 表示已生成可展示预览,当前会话可以释放回普通聊天。
ActiveScheduleSessionStatusReadyPreview = "ready_preview"
// ActiveScheduleSessionStatusApplied 表示用户已确认应用,主动调度会话已经收口。
ActiveScheduleSessionStatusApplied = "applied"
// ActiveScheduleSessionStatusIgnored 表示用户明确忽略本次建议。
ActiveScheduleSessionStatusIgnored = "ignored"
// ActiveScheduleSessionStatusExpired 表示会话已过期,不再承担路由管辖权。
ActiveScheduleSessionStatusExpired = "expired"
// ActiveScheduleSessionStatusFailed 表示会话在绑定、重跑或写回过程中失败。
ActiveScheduleSessionStatusFailed = "failed"
)
// ActiveScheduleSession 是“主动调度会话路由桥”的持久化模型。
//
// 职责边界:
// 1. 只保存会话级路由权与轻量状态,不承载 preview 主表的完整业务内容;
// 2. conversation_id 允许在通知前为空,等站内会话绑定完成后再写入;
// 3. state_json 只存轻量状态,避免把重对象和历史消息继续塞进 session 表。
type ActiveScheduleSession struct {
SessionID string `gorm:"column:session_id;type:varchar(64);primaryKey"`
// 1. user_id + conversation_id 用于在聊天入口侧定位当前管辖中的主动调度会话。
// 2. conversation_id 允许为空,因此这里使用可空列,方便先建 session 再绑定会话。
UserID int `gorm:"column:user_id;not null;index:idx_active_schedule_sessions_user_conv,priority:1;index:idx_active_schedule_sessions_user_status_updated,priority:1"`
ConversationID *string `gorm:"column:conversation_id;type:varchar(128);index:idx_active_schedule_sessions_user_conv,priority:2;index:idx_active_schedule_sessions_conversation_status_updated,priority:1"`
// 3. trigger_id / current_preview_id 分别串起触发源与当前预览,方便后续审计和回放。
TriggerID string `gorm:"column:trigger_id;type:varchar(64);not null;index:idx_active_schedule_sessions_trigger_id"`
CurrentPreviewID *string `gorm:"column:current_preview_id;type:varchar(64);index:idx_active_schedule_sessions_preview_id"`
Status string `gorm:"column:status;type:varchar(32);not null;default:'waiting_user_reply';index:idx_active_schedule_sessions_user_status_updated,priority:2;index:idx_active_schedule_sessions_status_updated,priority:1;index:idx_active_schedule_sessions_conversation_status_updated,priority:2"`
StateJSON string `gorm:"column:state_json;type:json;not null"`
CreatedAt time.Time `gorm:"column:created_at;autoCreateTime"`
UpdatedAt time.Time `gorm:"column:updated_at;autoUpdateTime;index:idx_active_schedule_sessions_user_status_updated,priority:3;index:idx_active_schedule_sessions_status_updated,priority:2;index:idx_active_schedule_sessions_conversation_status_updated,priority:3"`
}
// TableName 返回主动调度会话表名。
func (ActiveScheduleSession) TableName() string {
return "active_schedule_sessions"
}
// ActiveScheduleSessionState 是 session 表内 state_json 对应的轻量状态。
//
// 职责边界:
// 1. 这里只放“路由和补信息闭环”需要的少量字段;
// 2. 不承载完整 preview、正文历史或大块工具结果
// 3. 便于 cache / DAO 之间直接复用同一份 JSON 语义。
type ActiveScheduleSessionState struct {
PendingQuestion string `json:"pending_question,omitempty"`
MissingInfo []string `json:"missing_info,omitempty"`
LastCandidateID string `json:"last_candidate_id,omitempty"`
LastNotificationID string `json:"last_notification_id,omitempty"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
FailedReason string `json:"failed_reason,omitempty"`
}
// ActiveScheduleSessionSnapshot 是 service、DAO、cache 之间共享的会话快照 DTO。
//
// 职责边界:
// 1. 负责在三层之间传递强类型会话状态;
// 2. 不负责业务决策,不负责拦截判定;
// 3. DAO 再把它拆成数据库列和 state_jsoncache 则直接按 JSON 存取。
type ActiveScheduleSessionSnapshot struct {
SessionID string
UserID int
ConversationID string
TriggerID string
CurrentPreviewID string
Status string
State ActiveScheduleSessionState
CreatedAt time.Time
UpdatedAt time.Time
}