(chatId: string)
| 615 | const MESSAGES_PAGE_SIZE = 50; |
| 616 | |
| 617 | export const chatMessagesForInfiniteScroll = (chatId: string) => ({ |
| 618 | queryKey: chatMessagesKey(chatId), |
| 619 | initialPageParam: undefined as number | undefined, |
| 620 | queryFn: ({ pageParam }: { pageParam: number | undefined }) => |
| 621 | API.experimental.getChatMessages(chatId, { |
| 622 | before_id: pageParam, |
| 623 | limit: MESSAGES_PAGE_SIZE, |
| 624 | }), |
| 625 | getNextPageParam: (lastPage: TypesGen.ChatMessagesResponse) => { |
| 626 | if (!lastPage.has_more || lastPage.messages.length === 0) { |
| 627 | return undefined; |
| 628 | } |
| 629 | // The API returns messages in DESC order (newest first). |
| 630 | // The last item in the array is the oldest in this page. |
| 631 | // Use its ID as the cursor for the next (older) page. |
| 632 | return lastPage.messages[lastPage.messages.length - 1].id; |
| 633 | }, |
| 634 | }); |
| 635 | |
| 636 | // Cap requested prompts to keep the response small; well under the server-side maximum. |
| 637 | const PROMPT_HISTORY_LIMIT = 500; |
no test coverage detected