MCPcopy Index your code
hub / github.com/coder/coder / chatMessagesForInfiniteScroll

Function chatMessagesForInfiniteScroll

site/src/api/queries/chats.ts:617–634  ·  view source on GitHub ↗
(chatId: string)

Source from the content-addressed store, hash-verified

615const MESSAGES_PAGE_SIZE = 50;
616
617export 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.
637const PROMPT_HISTORY_LIMIT = 500;

Callers 1

AgentChatPageFunction · 0.90

Calls 2

chatMessagesKeyFunction · 0.85
getChatMessagesMethod · 0.80

Tested by

no test coverage detected