Skip to content

fix: apply pagination to AgentFlow chat messages#6395

Open
xxiaoxiong wants to merge 2 commits into
FlowiseAI:mainfrom
xxiaoxiong:fix/agentflow-pagination-6297
Open

fix: apply pagination to AgentFlow chat messages#6395
xxiaoxiong wants to merge 2 commits into
FlowiseAI:mainfrom
xxiaoxiong:fix/agentflow-pagination-6297

Conversation

@xxiaoxiong
Copy link
Copy Markdown

Description

Fixes #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.

Root Cause

The pagination logic (skip and take options) was present in handleFeedbackQuery but was missing from the main query path used by AgentFlow chatflows in utilGetChatMessage.

Changes

  • ✅ Add skip and take options to the TypeORM query in utilGetChatMessage
  • ✅ Apply pagination when page > -1 and pageSize > -1
  • ✅ Maintain backward compatibility (no pagination when page/pageSize are -1)

Code Changes

const messages = await appServer.AppDataSource.getRepository(ChatMessage).find({
    // ... existing where, relations, order options ...
    skip: page > -1 && pageSize > -1 ? page * pageSize : undefined,
    take: page > -1 && pageSize > -1 ? pageSize : undefined
})

Testing

Before

  • AgentFlow: All messages returned regardless of page and limit parameters
  • Chatflow: Pagination worked correctly

After

  • AgentFlow: Pagination works correctly, respects page and limit
  • Chatflow: Continues to work as before
  • Backward compatibility: Empty or invalid page/pageSize parameters default to no pagination

Test Scenario (from issue)

  1. Create an AgentFlow with 138 messages
  2. Request page 1: GET /api/v1/chatmessage/:id?page=1&limit=100
  3. Request page 2: GET /api/v1/chatmessage/:id?page=2&limit=100
  4. ✅ Page 1 returns messages 1-100
  5. ✅ Page 2 returns messages 101-138

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • The fix maintains backward compatibility
  • The fix is consistent with existing pagination logic in handleFeedbackQuery

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
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +119 to +120
skip: page > -1 && pageSize > -1 ? page * pageSize : undefined,
take: page > -1 && pageSize > -1 ? pageSize : undefined
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pagination not working for AgentFlow in /api/v1/chatmessage endpoint

1 participant