mirror of https://github.com/kortix-ai/suna.git
Merge pull request #762 from tnfssc/sharath/suna-394-select-messages-from-db-bypass-the-max-rows-returned-limit
This commit is contained in:
commit
1b62a7e47c
|
@ -511,23 +511,39 @@ 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();
|
||||||
|
|
||||||
const { data, error } = await supabase
|
let allMessages: Message[] = [];
|
||||||
.from('messages')
|
let from = 0;
|
||||||
.select('*')
|
const batchSize = 1000;
|
||||||
.eq('thread_id', threadId)
|
let hasMore = true;
|
||||||
.neq('type', 'cost')
|
|
||||||
.neq('type', 'summary')
|
|
||||||
.order('created_at', { ascending: true });
|
|
||||||
|
|
||||||
if (error) {
|
while (hasMore) {
|
||||||
console.error('Error fetching messages:', error);
|
const { data, error } = await supabase
|
||||||
handleApiError(error, { operation: 'load messages', resource: `messages for thread ${threadId}` });
|
.from('messages')
|
||||||
throw new Error(`Error getting messages: ${error.message}`);
|
.select('*')
|
||||||
|
.eq('thread_id', threadId)
|
||||||
|
.neq('type', 'cost')
|
||||||
|
.neq('type', 'summary')
|
||||||
|
.order('created_at', { ascending: true })
|
||||||
|
.range(from, from + batchSize - 1);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
console.error('Error fetching messages:', error);
|
||||||
|
handleApiError(error, { operation: 'load messages', resource: `messages for thread ${threadId}` });
|
||||||
|
throw new Error(`Error getting messages: ${error.message}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data && data.length > 0) {
|
||||||
|
allMessages = allMessages.concat(data);
|
||||||
|
from += batchSize;
|
||||||
|
hasMore = data.length === batchSize;
|
||||||
|
} else {
|
||||||
|
hasMore = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('[API] Messages fetched:', data);
|
console.log('[API] Messages fetched count:', allMessages.length);
|
||||||
|
|
||||||
return data || [];
|
return allMessages;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Agent APIs
|
// Agent APIs
|
||||||
|
|
Loading…
Reference in New Issue