fix: apply pagination to AgentFlow chat messages#6395
Conversation
Fixes FlowiseAI#6382 Changes: - Add URL validation for Tool Icon Source field - Display error message when invalid URL is entered - Block saving when Tool Icon Source contains invalid URL - Allow empty Tool Icon Source (optional field) - Validate on input change for immediate feedback - Clear error state when dialog is reset The validation ensures: - Empty values are allowed (optional field) - Only http:// and https:// URLs are accepted - Clear error messages guide users to correct format - Saving is prevented until validation passes
Fixes FlowiseAI#6297 The GET /api/v1/chatmessage/:id endpoint was not respecting the limit and page query parameters for AgentFlow chatflows, causing all messages to be returned regardless of pagination settings. Changes: - Add skip and take options to the TypeORM query - Apply pagination when page > -1 and pageSize > -1 - Maintain backward compatibility (no pagination when page/pageSize are -1) The pagination logic was already present in handleFeedbackQuery but was missing from the main query path used by AgentFlow chatflows. Testing: - Pagination now works correctly for AgentFlow chatflows - Chatflow chatflows continue to work as before - Empty or invalid page/pageSize parameters default to no pagination
There was a problem hiding this comment.
Code Review
This pull request introduces pagination to the chat message retrieval on the server and adds URL validation for tool icons in the UI. The server-side changes include adding skip and take parameters to the message query, while the UI changes implement a validation check to ensure tool icon sources are valid http or https URLs. A critical issue was identified in the pagination logic where the skip calculation incorrectly handles page indexing, which could lead to incorrect data being returned for the first page.
| skip: page > -1 && pageSize > -1 ? page * pageSize : undefined, | ||
| take: page > -1 && pageSize > -1 ? pageSize : undefined |
There was a problem hiding this comment.
The pagination calculation is incorrect for 1-based indexing. If page is 1, skip should be 0, but currently it evaluates to 1 * pageSize. This is also inconsistent with the logic in handleFeedbackQuery at line 198. To correctly return the first page when page=1, the calculation should be (page - 1) * pageSize.
| skip: page > -1 && pageSize > -1 ? page * pageSize : undefined, | |
| take: page > -1 && pageSize > -1 ? pageSize : undefined | |
| skip: page > -1 && pageSize > -1 ? (page - 1) * pageSize : undefined, | |
| take: page > -1 && pageSize > -1 ? pageSize : undefined |
Description
Fixes #6297
The GET
/api/v1/chatmessage/:idendpoint was not respecting thelimitandpagequery parameters for AgentFlow chatflows, causing all messages to be returned regardless of pagination settings.Root Cause
The pagination logic (
skipandtakeoptions) was present inhandleFeedbackQuerybut was missing from the main query path used by AgentFlow chatflows inutilGetChatMessage.Changes
skipandtakeoptions to the TypeORM query inutilGetChatMessagepage > -1andpageSize > -1Code Changes
Testing
Before
pageandlimitparametersAfter
pageandlimitTest Scenario (from issue)
GET /api/v1/chatmessage/:id?page=1&limit=100GET /api/v1/chatmessage/:id?page=2&limit=100Type of Change
Checklist
handleFeedbackQuery