A new recheck mark is posted into the actor's existing project session, and a downstream-impact event does the same. Asking about what a change affects still resolves to impact analysis. Co-authored-by: Cursor <cursoragent@cursor.com>
46 lines
1.5 KiB
Go
46 lines
1.5 KiB
Go
package docnotify
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"chat-agent-system/internal/ctxmgr"
|
|
)
|
|
|
|
// PostProjectNotice writes an assistant message into the actor's latest project session.
|
|
// It does not create a session. Missing chat, user, or session is a no-op.
|
|
func PostProjectNotice(ctx context.Context, chat *ctxmgr.ContextManager, projectID, userID int64, content string, meta map[string]any) error {
|
|
if chat == nil || projectID <= 0 || userID <= 0 || content == "" {
|
|
return nil
|
|
}
|
|
sessions, err := chat.ListChatSessions(ctx, ctxmgr.SessionFilter{UserID: userID, ProjectID: projectID, Limit: 1})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if len(sessions) == 0 || sessions[0].SessionID == "" {
|
|
return nil
|
|
}
|
|
if meta == nil {
|
|
meta = map[string]any{}
|
|
}
|
|
if _, ok := meta["project_id"]; !ok {
|
|
meta["project_id"] = projectID
|
|
}
|
|
_, err = chat.RecordUserMessageWithID(ctx, sessions[0].SessionID, 0, "assistant", content, "IMPACT_ANALYZE", "", meta)
|
|
if err != nil {
|
|
return fmt.Errorf("post project notice: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func downstreamChatBody(docID, impacted string) string {
|
|
switch {
|
|
case docID != "" && impacted != "":
|
|
return fmt.Sprintf("文档 %s 的变更可能影响 %s。需要时可以说「分析影响」。", docID, impacted)
|
|
case docID != "":
|
|
return fmt.Sprintf("文档 %s 有变更,下游内容可能受影响。需要时可以说「分析影响」。", docID)
|
|
default:
|
|
return "有文档变更,下游内容可能受影响。需要时可以说「分析影响」。"
|
|
}
|
|
}
|