Skip to content

Commit 2473ded

Browse files
feat(api): add messages/paginated to stainless config
1 parent 3e03aff commit 2473ded

File tree

7 files changed

+284
-3
lines changed

7 files changed

+284
-3
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 34
1+
configured_endpoints: 35
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/sgp%2Fagentex-sdk-8f9296ac9fa68bb264c4739463e55ce27cdafb31b705b27600d6656db7b0dac5.yml
33
openapi_spec_hash: 8df92140f49cace852d7b71b0964da5b
4-
config_hash: 0197f86ba1a4b1b5ce813d0e62138588
4+
config_hash: 32eb65911c08ac84d117cecdf2759869

api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ from agentex.types import (
7272
ToolRequestContent,
7373
ToolResponseContent,
7474
MessageListResponse,
75+
MessageListPaginatedResponse,
7576
)
7677
```
7778

@@ -81,6 +82,7 @@ Methods:
8182
- <code title="get /messages/{message_id}">client.messages.<a href="./src/agentex/resources/messages/messages.py">retrieve</a>(message_id) -> <a href="./src/agentex/types/task_message.py">TaskMessage</a></code>
8283
- <code title="put /messages/{message_id}">client.messages.<a href="./src/agentex/resources/messages/messages.py">update</a>(message_id, \*\*<a href="src/agentex/types/message_update_params.py">params</a>) -> <a href="./src/agentex/types/task_message.py">TaskMessage</a></code>
8384
- <code title="get /messages">client.messages.<a href="./src/agentex/resources/messages/messages.py">list</a>(\*\*<a href="src/agentex/types/message_list_params.py">params</a>) -> <a href="./src/agentex/types/message_list_response.py">MessageListResponse</a></code>
85+
- <code title="get /messages/paginated">client.messages.<a href="./src/agentex/resources/messages/messages.py">list_paginated</a>(\*\*<a href="src/agentex/types/message_list_paginated_params.py">params</a>) -> <a href="./src/agentex/types/message_list_paginated_response.py">MessageListPaginatedResponse</a></code>
8486

8587
## Batch
8688

src/agentex/resources/messages/messages.py

Lines changed: 147 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
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+
)
1924
from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
2025
from ..._utils import maybe_transform, async_maybe_transform
2126
from ..._compat import cached_property
@@ -30,6 +35,7 @@
3035
from ...types.task_message import TaskMessage
3136
from ...types.message_list_response import MessageListResponse
3237
from ...types.task_message_content_param import TaskMessageContentParam
38+
from ...types.message_list_paginated_response import MessageListPaginatedResponse
3339

3440
__all__ = ["MessagesResource", "AsyncMessagesResource"]
3541

@@ -229,6 +235,70 @@ def list(
229235
cast_to=MessageListResponse,
230236
)
231237

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+
232302

233303
class AsyncMessagesResource(AsyncAPIResource):
234304
@cached_property
@@ -425,6 +495,70 @@ async def list(
425495
cast_to=MessageListResponse,
426496
)
427497

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+
428562

429563
class MessagesResourceWithRawResponse:
430564
def __init__(self, messages: MessagesResource) -> None:
@@ -442,6 +576,9 @@ def __init__(self, messages: MessagesResource) -> None:
442576
self.list = to_raw_response_wrapper(
443577
messages.list,
444578
)
579+
self.list_paginated = to_raw_response_wrapper(
580+
messages.list_paginated,
581+
)
445582

446583
@cached_property
447584
def batch(self) -> BatchResourceWithRawResponse:
@@ -464,6 +601,9 @@ def __init__(self, messages: AsyncMessagesResource) -> None:
464601
self.list = async_to_raw_response_wrapper(
465602
messages.list,
466603
)
604+
self.list_paginated = async_to_raw_response_wrapper(
605+
messages.list_paginated,
606+
)
467607

468608
@cached_property
469609
def batch(self) -> AsyncBatchResourceWithRawResponse:
@@ -486,6 +626,9 @@ def __init__(self, messages: MessagesResource) -> None:
486626
self.list = to_streamed_response_wrapper(
487627
messages.list,
488628
)
629+
self.list_paginated = to_streamed_response_wrapper(
630+
messages.list_paginated,
631+
)
489632

490633
@cached_property
491634
def batch(self) -> BatchResourceWithStreamingResponse:
@@ -508,6 +651,9 @@ def __init__(self, messages: AsyncMessagesResource) -> None:
508651
self.list = async_to_streamed_response_wrapper(
509652
messages.list,
510653
)
654+
self.list_paginated = async_to_streamed_response_wrapper(
655+
messages.list_paginated,
656+
)
511657

512658
@cached_property
513659
def batch(self) -> AsyncBatchResourceWithStreamingResponse:

src/agentex/types/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,7 @@
6464
from .tool_response_content_param import ToolResponseContentParam as ToolResponseContentParam
6565
from .task_retrieve_by_name_params import TaskRetrieveByNameParams as TaskRetrieveByNameParams
6666
from .deployment_history_list_params import DeploymentHistoryListParams as DeploymentHistoryListParams
67+
from .message_list_paginated_params import MessageListPaginatedParams as MessageListPaginatedParams
6768
from .task_retrieve_by_name_response import TaskRetrieveByNameResponse as TaskRetrieveByNameResponse
6869
from .deployment_history_list_response import DeploymentHistoryListResponse as DeploymentHistoryListResponse
70+
from .message_list_paginated_response import MessageListPaginatedResponse as MessageListPaginatedResponse
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
from typing import Optional
6+
from typing_extensions import Literal, Required, TypedDict
7+
8+
__all__ = ["MessageListPaginatedParams"]
9+
10+
11+
class MessageListPaginatedParams(TypedDict, total=False):
12+
task_id: Required[str]
13+
"""The task ID"""
14+
15+
cursor: Optional[str]
16+
17+
direction: Literal["older", "newer"]
18+
19+
limit: int
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing import List, Optional
4+
5+
from .._models import BaseModel
6+
from .task_message import TaskMessage
7+
8+
__all__ = ["MessageListPaginatedResponse"]
9+
10+
11+
class MessageListPaginatedResponse(BaseModel):
12+
"""Response with cursor pagination metadata."""
13+
14+
data: List[TaskMessage]
15+
"""List of messages"""
16+
17+
has_more: Optional[bool] = None
18+
"""Whether there are more messages to fetch"""
19+
20+
next_cursor: Optional[str] = None
21+
"""Cursor for fetching the next page of older messages"""

tests/api_resources/test_messages.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from agentex.types import (
1212
TaskMessage,
1313
MessageListResponse,
14+
MessageListPaginatedResponse,
1415
)
1516

1617
from ..utils import assert_matches_type
@@ -273,6 +274,51 @@ def test_streaming_response_list(self, client: Agentex) -> None:
273274

274275
assert cast(Any, response.is_closed) is True
275276

277+
@pytest.mark.skip(reason="Prism tests are disabled")
278+
@parametrize
279+
def test_method_list_paginated(self, client: Agentex) -> None:
280+
message = client.messages.list_paginated(
281+
task_id="task_id",
282+
)
283+
assert_matches_type(MessageListPaginatedResponse, message, path=["response"])
284+
285+
@pytest.mark.skip(reason="Prism tests are disabled")
286+
@parametrize
287+
def test_method_list_paginated_with_all_params(self, client: Agentex) -> None:
288+
message = client.messages.list_paginated(
289+
task_id="task_id",
290+
cursor="cursor",
291+
direction="older",
292+
limit=0,
293+
)
294+
assert_matches_type(MessageListPaginatedResponse, message, path=["response"])
295+
296+
@pytest.mark.skip(reason="Prism tests are disabled")
297+
@parametrize
298+
def test_raw_response_list_paginated(self, client: Agentex) -> None:
299+
response = client.messages.with_raw_response.list_paginated(
300+
task_id="task_id",
301+
)
302+
303+
assert response.is_closed is True
304+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
305+
message = response.parse()
306+
assert_matches_type(MessageListPaginatedResponse, message, path=["response"])
307+
308+
@pytest.mark.skip(reason="Prism tests are disabled")
309+
@parametrize
310+
def test_streaming_response_list_paginated(self, client: Agentex) -> None:
311+
with client.messages.with_streaming_response.list_paginated(
312+
task_id="task_id",
313+
) as response:
314+
assert not response.is_closed
315+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
316+
317+
message = response.parse()
318+
assert_matches_type(MessageListPaginatedResponse, message, path=["response"])
319+
320+
assert cast(Any, response.is_closed) is True
321+
276322

277323
class TestAsyncMessages:
278324
parametrize = pytest.mark.parametrize(
@@ -530,3 +576,48 @@ async def test_streaming_response_list(self, async_client: AsyncAgentex) -> None
530576
assert_matches_type(MessageListResponse, message, path=["response"])
531577

532578
assert cast(Any, response.is_closed) is True
579+
580+
@pytest.mark.skip(reason="Prism tests are disabled")
581+
@parametrize
582+
async def test_method_list_paginated(self, async_client: AsyncAgentex) -> None:
583+
message = await async_client.messages.list_paginated(
584+
task_id="task_id",
585+
)
586+
assert_matches_type(MessageListPaginatedResponse, message, path=["response"])
587+
588+
@pytest.mark.skip(reason="Prism tests are disabled")
589+
@parametrize
590+
async def test_method_list_paginated_with_all_params(self, async_client: AsyncAgentex) -> None:
591+
message = await async_client.messages.list_paginated(
592+
task_id="task_id",
593+
cursor="cursor",
594+
direction="older",
595+
limit=0,
596+
)
597+
assert_matches_type(MessageListPaginatedResponse, message, path=["response"])
598+
599+
@pytest.mark.skip(reason="Prism tests are disabled")
600+
@parametrize
601+
async def test_raw_response_list_paginated(self, async_client: AsyncAgentex) -> None:
602+
response = await async_client.messages.with_raw_response.list_paginated(
603+
task_id="task_id",
604+
)
605+
606+
assert response.is_closed is True
607+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
608+
message = await response.parse()
609+
assert_matches_type(MessageListPaginatedResponse, message, path=["response"])
610+
611+
@pytest.mark.skip(reason="Prism tests are disabled")
612+
@parametrize
613+
async def test_streaming_response_list_paginated(self, async_client: AsyncAgentex) -> None:
614+
async with async_client.messages.with_streaming_response.list_paginated(
615+
task_id="task_id",
616+
) as response:
617+
assert not response.is_closed
618+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
619+
620+
message = await response.parse()
621+
assert_matches_type(MessageListPaginatedResponse, message, path=["response"])
622+
623+
assert cast(Any, response.is_closed) is True

0 commit comments

Comments
 (0)