fix: resolve broken forked sessions with compactions due to missing parent-child message references (#6445)
This commit is contained in:
@@ -151,12 +151,19 @@ export namespace Session {
|
|||||||
directory: Instance.directory,
|
directory: Instance.directory,
|
||||||
})
|
})
|
||||||
const msgs = await messages({ sessionID: input.sessionID })
|
const msgs = await messages({ sessionID: input.sessionID })
|
||||||
|
const idMap = new Map<string, string>()
|
||||||
|
|
||||||
for (const msg of msgs) {
|
for (const msg of msgs) {
|
||||||
if (input.messageID && msg.info.id >= input.messageID) break
|
if (input.messageID && msg.info.id >= input.messageID) break
|
||||||
|
const newID = Identifier.ascending("message")
|
||||||
|
idMap.set(msg.info.id, newID)
|
||||||
|
|
||||||
|
const parentID = msg.info.role === "assistant" && msg.info.parentID ? idMap.get(msg.info.parentID) : undefined
|
||||||
const cloned = await updateMessage({
|
const cloned = await updateMessage({
|
||||||
...msg.info,
|
...msg.info,
|
||||||
sessionID: session.id,
|
sessionID: session.id,
|
||||||
id: Identifier.ascending("message"),
|
id: newID,
|
||||||
|
...(parentID && { parentID }),
|
||||||
})
|
})
|
||||||
|
|
||||||
for (const part of msg.parts) {
|
for (const part of msg.parts) {
|
||||||
|
|||||||
Reference in New Issue
Block a user