Merge pull request #762 from tnfssc/sharath/suna-394-select-messages-from-db-bypass-the-max-rows-returned-limit

This commit is contained in:
Sharath 2025-06-18 10:13:24 +05:30 committed by GitHub
commit 1b62a7e47c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 29 additions and 13 deletions

View File

@ -511,13 +511,20 @@ export const addUserMessage = async (
export const getMessages = async (threadId: string): Promise<Message[]> => { export const getMessages = async (threadId: string): Promise<Message[]> => {
const supabase = createClient(); const supabase = createClient();
let allMessages: Message[] = [];
let from = 0;
const batchSize = 1000;
let hasMore = true;
while (hasMore) {
const { data, error } = await supabase const { data, error } = await supabase
.from('messages') .from('messages')
.select('*') .select('*')
.eq('thread_id', threadId) .eq('thread_id', threadId)
.neq('type', 'cost') .neq('type', 'cost')
.neq('type', 'summary') .neq('type', 'summary')
.order('created_at', { ascending: true }); .order('created_at', { ascending: true })
.range(from, from + batchSize - 1);
if (error) { if (error) {
console.error('Error fetching messages:', error); console.error('Error fetching messages:', error);
@ -525,9 +532,18 @@ export const getMessages = async (threadId: string): Promise<Message[]> => {
throw new Error(`Error getting messages: ${error.message}`); throw new Error(`Error getting messages: ${error.message}`);
} }
console.log('[API] Messages fetched:', data); if (data && data.length > 0) {
allMessages = allMessages.concat(data);
from += batchSize;
hasMore = data.length === batchSize;
} else {
hasMore = false;
}
}
return data || []; console.log('[API] Messages fetched count:', allMessages.length);
return allMessages;
}; };
// Agent APIs // Agent APIs