mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-09-21 14:07:20 +08:00
fix(pr-view): Update mergeMessages to main
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import type { Message, MessageLoadMode, Part } from "../types/messages"
|
||||
import { sameParts } from "./session-parts"
|
||||
import { withoutResolvedSessionErrors } from "./session-errors"
|
||||
|
||||
export function mergeMessages(current: Message[], incoming: Message[], mode: Exclude<MessageLoadMode, "focus">) {
|
||||
const kept = withoutResolvedSessionErrors(current, incoming)
|
||||
if (mode === "reconcile") {
|
||||
// Tail reconcile: incoming is the authoritative newest-N snapshot.
|
||||
// Local state may already hold some of those IDs and may also hold
|
||||
@@ -10,12 +12,12 @@ export function mergeMessages(current: Message[], incoming: Message[], mode: Exc
|
||||
// server messages land in the right position and optimistic tail
|
||||
// entries stay at the end.
|
||||
const byId = new Map<string, Message>()
|
||||
for (const msg of current) byId.set(msg.id, msg)
|
||||
for (const msg of kept) byId.set(msg.id, msg)
|
||||
for (const msg of incoming) byId.set(msg.id, msg)
|
||||
return [...byId.values()].sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime())
|
||||
}
|
||||
const seen = new Set<string>()
|
||||
const source = mode === "prepend" ? [...incoming, ...current] : incoming
|
||||
const source = mode === "prepend" ? [...incoming, ...kept] : incoming
|
||||
return source.filter((msg) => {
|
||||
if (seen.has(msg.id)) return false
|
||||
seen.add(msg.id)
|
||||
|
||||
Reference in New Issue
Block a user