fix(server): return latest N messages instead of first N in messages endpoint
This commit is contained in:
parent
86fac2bd75
commit
edb72b447b
|
|
@ -184,16 +184,21 @@ export async function readSessionMessages(opts: {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const startIndex = cursorIndex >= 0 ? cursorIndex + 1 : 0
|
let sliced: SessionMessage[]
|
||||||
const sliced = allMessages.slice(startIndex)
|
if (cursorIndex >= 0) {
|
||||||
const limited = opts.limit ? sliced.slice(0, opts.limit) : sliced
|
sliced = allMessages.slice(cursorIndex + 1)
|
||||||
|
} else if (opts.limit) {
|
||||||
|
sliced = allMessages.slice(-opts.limit)
|
||||||
|
} else {
|
||||||
|
sliced = allMessages
|
||||||
|
}
|
||||||
|
|
||||||
const nextCursor =
|
const nextCursor =
|
||||||
opts.limit && sliced.length > opts.limit
|
opts.limit && allMessages.length > sliced.length
|
||||||
? sliced[opts.limit]?.uuid
|
? sliced[0]?.uuid
|
||||||
: undefined
|
: undefined
|
||||||
|
|
||||||
return { messages: limited, nextCursor }
|
return { messages: sliced, nextCursor }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function readSessionTodos(opts: {
|
export async function readSessionTodos(opts: {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user