fix(server): return latest N messages instead of first N in messages endpoint

This commit is contained in:
DoSun 2026-05-12 16:46:26 +08:00
parent 86fac2bd75
commit edb72b447b

View File

@ -184,16 +184,21 @@ export async function readSessionMessages(opts: {
})
}
const startIndex = cursorIndex >= 0 ? cursorIndex + 1 : 0
const sliced = allMessages.slice(startIndex)
const limited = opts.limit ? sliced.slice(0, opts.limit) : sliced
let sliced: SessionMessage[]
if (cursorIndex >= 0) {
sliced = allMessages.slice(cursorIndex + 1)
} else if (opts.limit) {
sliced = allMessages.slice(-opts.limit)
} else {
sliced = allMessages
}
const nextCursor =
opts.limit && sliced.length > opts.limit
? sliced[opts.limit]?.uuid
opts.limit && allMessages.length > sliced.length
? sliced[0]?.uuid
: undefined
return { messages: limited, nextCursor }
return { messages: sliced, nextCursor }
}
export async function readSessionTodos(opts: {