Changeset 0.10.2 (#58)
This commit is contained in:
@@ -480,6 +480,9 @@ func (h *CompletionHandler) resolveConfig(userID string, channelID string, req c
|
||||
// loadConversation builds the message history for the LLM by walking the
|
||||
// active path through the message tree. Only the current branch is sent —
|
||||
// sibling branches are never included in context.
|
||||
//
|
||||
// Summary-aware: if the path contains a summary node (metadata.type = "summary"),
|
||||
// messages before it are replaced by the summary content as a system message.
|
||||
func (h *CompletionHandler) loadConversation(channelID, userID, presetSystemPrompt string) ([]providers.Message, error) {
|
||||
messages := make([]providers.Message, 0)
|
||||
|
||||
@@ -519,10 +522,32 @@ func (h *CompletionHandler) loadConversation(channelID, userID, presetSystemProm
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, m := range path {
|
||||
// Find the most recent summary node in the path
|
||||
summaryIdx := -1
|
||||
for i, m := range path {
|
||||
if isSummaryMessage(&m) {
|
||||
summaryIdx = i
|
||||
}
|
||||
}
|
||||
|
||||
// If we found a summary, inject it as a system message and skip prior messages
|
||||
startIdx := 0
|
||||
if summaryIdx >= 0 {
|
||||
messages = append(messages, providers.Message{
|
||||
Role: "system",
|
||||
Content: "Previous conversation summary:\n" + path[summaryIdx].Content,
|
||||
})
|
||||
startIdx = summaryIdx + 1
|
||||
}
|
||||
|
||||
for _, m := range path[startIdx:] {
|
||||
if m.Role == "system" {
|
||||
continue // system prompts handled above
|
||||
}
|
||||
// Skip summary nodes that aren't the boundary (shouldn't happen, but defensive)
|
||||
if isSummaryMessage(&m) {
|
||||
continue
|
||||
}
|
||||
messages = append(messages, providers.Message{
|
||||
Role: m.Role,
|
||||
Content: m.Content,
|
||||
@@ -532,6 +557,18 @@ func (h *CompletionHandler) loadConversation(channelID, userID, presetSystemProm
|
||||
return messages, nil
|
||||
}
|
||||
|
||||
// isSummaryMessage checks if a PathMessage has summary metadata.
|
||||
func isSummaryMessage(m *PathMessage) bool {
|
||||
if m.Metadata == nil {
|
||||
return false
|
||||
}
|
||||
var meta map[string]interface{}
|
||||
if err := json.Unmarshal(*m.Metadata, &meta); err != nil {
|
||||
return false
|
||||
}
|
||||
return meta["type"] == "summary"
|
||||
}
|
||||
|
||||
// ── Message Persistence ─────────────────────
|
||||
|
||||
// persistMessage inserts a message into the tree, updates the cursor, and
|
||||
|
||||
Reference in New Issue
Block a user