Changeset 0.10.2 (#58)

This commit is contained in:
2026-02-24 20:29:08 +00:00
parent 13772ebd6c
commit 4061e4a145
20 changed files with 1223 additions and 41 deletions

View File

@@ -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