Skip to content

Conversation

@gabrycina
Copy link
Contributor

@gabrycina gabrycina commented Dec 7, 2025

Summary

Implements cursor-based pagination for the /messages endpoint to enable infinite scroll in the UI.

Breaking Change

GET /messages now returns PaginatedMessagesResponse instead of raw array:

{ "data": [...], "next_cursor": "...", "has_more": true }

Backend Changes

  • Add cursor and direction query params to /messages
  • Return {data, next_cursor, has_more} response format
  • Add pagination.py with cursor encode/decode utilities
  • Add find_by_field_with_cursor() to MongoDB adapter

Frontend Changes

  • Replace useTaskMessages with useInfiniteTaskMessages hook
  • Implement infinite scroll with IntersectionObserver
  • Add scroll position preservation when loading older messages
  • Fix Thinking indicator timing
  • Remove deprecated custom-subscribe-task-state.tsx

Related PRs

Suggested Deployment Order

  1. Deploy this PR (backend)
  2. Publish TypeScript SDK
  3. Publish Python SDK
  4. Deploy frontend (after updating SDK version)

BREAKING CHANGE: /messages endpoint now returns PaginatedMessagesResponse
instead of raw array.

Backend:
- Add cursor/direction params to /messages endpoint
- Return {data, next_cursor, has_more} response format
- Add pagination.py with encode/decode cursor utilities
- Add find_by_field_with_cursor to MongoDB adapter

Frontend:
- Replace useTaskMessages with useInfiniteTaskMessages hook
- Implement infinite scroll with IntersectionObserver
- Add scroll position preservation when loading older messages
- Fix Thinking indicator to hide when streaming starts
- Remove deprecated custom-subscribe-task-state.tsx
Backwards-compatible change:
- Original GET /messages endpoint unchanged (returns list[TaskMessage])
- New GET /messages/paginated endpoint with cursor pagination (returns PaginatedMessagesResponse)

This allows existing SDK users to continue using the API without updates.
Copy link
Collaborator

@smoreinis smoreinis left a comment

Choose a reason for hiding this comment

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

Backend changes LG (just one minor question)

@smoreinis
Copy link
Collaborator

also, looks like the Agentex UI lint & typecheck is failing

gabrycina and others added 7 commits December 8, 2025 23:23
- MongoDB cursor uses compound (created_at, _id) comparison to handle timestamp ties
- UI hooks use listPaginated() instead of list() for paginated endpoints
- Rename PaginatedMessagesResponse -> MessageListPaginatedResponse
- Add null coalescing for optional fields (next_cursor, has_more)
SDK now includes listPaginated() and MessageListPaginatedResponse
Frontend changes moved to feature/cursor-pagination-messages-ui branch.
This PR now contains only backend changes for /messages/paginated endpoint.
@MichaelSun48 MichaelSun48 merged commit 560853b into scaleapi:main Dec 9, 2025
7 checks passed
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.

3 participants