feat(api): add pagination to messages endpoint and improve chat API robustness

- Add pagination support to /api/conversations/[id]/messages with limit and before query params, returning hasMore and cursor for efficient message fetching
- Enhance /api/ollama/chat by adding non-blocking Ollama availability check and conditionally disabling debug logging in production环境下Featured
This commit is contained in:
Evandro Fonseca Junior committed 2025-10-29 17:22:21 -03:00
1 parent 30290ae87a
commit 1545020afe
9 files changed
+114 -38

No files matched your search

+15
View File
@@ -39,6 +39,21 @@ export class MessageRepository {
.all(conversationId) as Message[];
}
findByConversationPaged(
conversationId: string,
limit: number,
beforeTs?: number
): Message[] {
const sql = beforeTs
? `SELECT * FROM messages WHERE conversation_id = ? AND timestamp < ? ORDER BY timestamp DESC LIMIT ?`
: `SELECT * FROM messages WHERE conversation_id = ? ORDER BY timestamp DESC LIMIT ?`;
const rows = beforeTs
? (this.db.prepare(sql).all(conversationId, beforeTs, limit) as Message[])
: (this.db.prepare(sql).all(conversationId, limit) as Message[]);
// Reverter para ascendente no retorno
return rows.reverse();
}
findById(id: string): Message | null {
return this.db
.prepare(