1515 BatchResourceWithStreamingResponse ,
1616 AsyncBatchResourceWithStreamingResponse ,
1717)
18- from ...types import message_list_params , message_create_params , message_update_params
18+ from ...types import (
19+ message_list_params ,
20+ message_create_params ,
21+ message_update_params ,
22+ message_list_paginated_params ,
23+ )
1924from ..._types import Body , Omit , Query , Headers , NotGiven , omit , not_given
2025from ..._utils import maybe_transform , async_maybe_transform
2126from ..._compat import cached_property
3035from ...types .task_message import TaskMessage
3136from ...types .message_list_response import MessageListResponse
3237from ...types .task_message_content_param import TaskMessageContentParam
38+ from ...types .message_list_paginated_response import MessageListPaginatedResponse
3339
3440__all__ = ["MessagesResource" , "AsyncMessagesResource" ]
3541
@@ -192,7 +198,10 @@ def list(
192198 timeout : float | httpx .Timeout | None | NotGiven = not_given ,
193199 ) -> MessageListResponse :
194200 """
195- List Messages
201+ List messages for a task with offset-based pagination.
202+
203+ For cursor-based pagination with infinite scroll support, use
204+ /messages/paginated.
196205
197206 Args:
198207 task_id: The task ID
@@ -226,6 +235,70 @@ def list(
226235 cast_to = MessageListResponse ,
227236 )
228237
238+ def list_paginated (
239+ self ,
240+ * ,
241+ task_id : str ,
242+ cursor : Optional [str ] | Omit = omit ,
243+ direction : Literal ["older" , "newer" ] | Omit = omit ,
244+ limit : int | Omit = omit ,
245+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
246+ # The extra values given here take precedence over values defined on the client or passed to this method.
247+ extra_headers : Headers | None = None ,
248+ extra_query : Query | None = None ,
249+ extra_body : Body | None = None ,
250+ timeout : float | httpx .Timeout | None | NotGiven = not_given ,
251+ ) -> MessageListPaginatedResponse :
252+ """
253+ List messages for a task with cursor-based pagination.
254+
255+ This endpoint is designed for infinite scroll UIs where new messages may arrive
256+ while paginating through older ones.
257+
258+ Args: task_id: The task ID to filter messages by limit: Maximum number of
259+ messages to return (default: 50) cursor: Opaque cursor string for pagination.
260+ Pass the `next_cursor` from a previous response to get the next page. direction:
261+ Pagination direction - "older" to get older messages (default), "newer" to get
262+ newer messages.
263+
264+ Returns: PaginatedMessagesResponse with: - data: List of messages (newest first
265+ when direction="older") - next_cursor: Cursor for fetching the next page (null
266+ if no more pages) - has_more: Whether there are more messages to fetch
267+
268+ Example: First request: GET /messages/paginated?task_id=xxx&limit=50 Next page:
269+ GET /messages/paginated?task_id=xxx&limit=50&cursor=<next_cursor>
270+
271+ Args:
272+ task_id: The task ID
273+
274+ extra_headers: Send extra headers
275+
276+ extra_query: Add additional query parameters to the request
277+
278+ extra_body: Add additional JSON properties to the request
279+
280+ timeout: Override the client-level default timeout for this request, in seconds
281+ """
282+ return self ._get (
283+ "/messages/paginated" ,
284+ options = make_request_options (
285+ extra_headers = extra_headers ,
286+ extra_query = extra_query ,
287+ extra_body = extra_body ,
288+ timeout = timeout ,
289+ query = maybe_transform (
290+ {
291+ "task_id" : task_id ,
292+ "cursor" : cursor ,
293+ "direction" : direction ,
294+ "limit" : limit ,
295+ },
296+ message_list_paginated_params .MessageListPaginatedParams ,
297+ ),
298+ ),
299+ cast_to = MessageListPaginatedResponse ,
300+ )
301+
229302
230303class AsyncMessagesResource (AsyncAPIResource ):
231304 @cached_property
@@ -385,7 +458,10 @@ async def list(
385458 timeout : float | httpx .Timeout | None | NotGiven = not_given ,
386459 ) -> MessageListResponse :
387460 """
388- List Messages
461+ List messages for a task with offset-based pagination.
462+
463+ For cursor-based pagination with infinite scroll support, use
464+ /messages/paginated.
389465
390466 Args:
391467 task_id: The task ID
@@ -419,6 +495,70 @@ async def list(
419495 cast_to = MessageListResponse ,
420496 )
421497
498+ async def list_paginated (
499+ self ,
500+ * ,
501+ task_id : str ,
502+ cursor : Optional [str ] | Omit = omit ,
503+ direction : Literal ["older" , "newer" ] | Omit = omit ,
504+ limit : int | Omit = omit ,
505+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
506+ # The extra values given here take precedence over values defined on the client or passed to this method.
507+ extra_headers : Headers | None = None ,
508+ extra_query : Query | None = None ,
509+ extra_body : Body | None = None ,
510+ timeout : float | httpx .Timeout | None | NotGiven = not_given ,
511+ ) -> MessageListPaginatedResponse :
512+ """
513+ List messages for a task with cursor-based pagination.
514+
515+ This endpoint is designed for infinite scroll UIs where new messages may arrive
516+ while paginating through older ones.
517+
518+ Args: task_id: The task ID to filter messages by limit: Maximum number of
519+ messages to return (default: 50) cursor: Opaque cursor string for pagination.
520+ Pass the `next_cursor` from a previous response to get the next page. direction:
521+ Pagination direction - "older" to get older messages (default), "newer" to get
522+ newer messages.
523+
524+ Returns: PaginatedMessagesResponse with: - data: List of messages (newest first
525+ when direction="older") - next_cursor: Cursor for fetching the next page (null
526+ if no more pages) - has_more: Whether there are more messages to fetch
527+
528+ Example: First request: GET /messages/paginated?task_id=xxx&limit=50 Next page:
529+ GET /messages/paginated?task_id=xxx&limit=50&cursor=<next_cursor>
530+
531+ Args:
532+ task_id: The task ID
533+
534+ extra_headers: Send extra headers
535+
536+ extra_query: Add additional query parameters to the request
537+
538+ extra_body: Add additional JSON properties to the request
539+
540+ timeout: Override the client-level default timeout for this request, in seconds
541+ """
542+ return await self ._get (
543+ "/messages/paginated" ,
544+ options = make_request_options (
545+ extra_headers = extra_headers ,
546+ extra_query = extra_query ,
547+ extra_body = extra_body ,
548+ timeout = timeout ,
549+ query = await async_maybe_transform (
550+ {
551+ "task_id" : task_id ,
552+ "cursor" : cursor ,
553+ "direction" : direction ,
554+ "limit" : limit ,
555+ },
556+ message_list_paginated_params .MessageListPaginatedParams ,
557+ ),
558+ ),
559+ cast_to = MessageListPaginatedResponse ,
560+ )
561+
422562
423563class MessagesResourceWithRawResponse :
424564 def __init__ (self , messages : MessagesResource ) -> None :
@@ -436,6 +576,9 @@ def __init__(self, messages: MessagesResource) -> None:
436576 self .list = to_raw_response_wrapper (
437577 messages .list ,
438578 )
579+ self .list_paginated = to_raw_response_wrapper (
580+ messages .list_paginated ,
581+ )
439582
440583 @cached_property
441584 def batch (self ) -> BatchResourceWithRawResponse :
@@ -458,6 +601,9 @@ def __init__(self, messages: AsyncMessagesResource) -> None:
458601 self .list = async_to_raw_response_wrapper (
459602 messages .list ,
460603 )
604+ self .list_paginated = async_to_raw_response_wrapper (
605+ messages .list_paginated ,
606+ )
461607
462608 @cached_property
463609 def batch (self ) -> AsyncBatchResourceWithRawResponse :
@@ -480,6 +626,9 @@ def __init__(self, messages: MessagesResource) -> None:
480626 self .list = to_streamed_response_wrapper (
481627 messages .list ,
482628 )
629+ self .list_paginated = to_streamed_response_wrapper (
630+ messages .list_paginated ,
631+ )
483632
484633 @cached_property
485634 def batch (self ) -> BatchResourceWithStreamingResponse :
@@ -502,6 +651,9 @@ def __init__(self, messages: AsyncMessagesResource) -> None:
502651 self .list = async_to_streamed_response_wrapper (
503652 messages .list ,
504653 )
654+ self .list_paginated = async_to_streamed_response_wrapper (
655+ messages .list_paginated ,
656+ )
505657
506658 @cached_property
507659 def batch (self ) -> AsyncBatchResourceWithStreamingResponse :
0 commit comments