From d40e6e0d6911be0bc9bfc419e02bd7c1d5ad5be4 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 22 Jul 2025 12:04:34 +0000 Subject: [PATCH 1/3] fix(parsing): parse extra field types --- src/agentex/_models.py | 25 +++++++++++++++++++++++-- tests/test_models.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/agentex/_models.py b/src/agentex/_models.py index ffcbf67b..b8387ce9 100644 --- a/src/agentex/_models.py +++ b/src/agentex/_models.py @@ -208,14 +208,18 @@ def construct( # pyright: ignore[reportIncompatibleMethodOverride] else: fields_values[name] = field_get_default(field) + extra_field_type = _get_extra_fields_type(__cls) + _extra = {} for key, value in values.items(): if key not in model_fields: + parsed = construct_type(value=value, type_=extra_field_type) if extra_field_type is not None else value + if PYDANTIC_V2: - _extra[key] = value + _extra[key] = parsed else: _fields_set.add(key) - fields_values[key] = value + fields_values[key] = parsed object.__setattr__(m, "__dict__", fields_values) @@ -370,6 +374,23 @@ def _construct_field(value: object, field: FieldInfo, key: str) -> object: return construct_type(value=value, type_=type_, metadata=getattr(field, "metadata", None)) +def _get_extra_fields_type(cls: type[pydantic.BaseModel]) -> type | None: + if not PYDANTIC_V2: + # TODO + return None + + schema = cls.__pydantic_core_schema__ + if schema["type"] == "model": + fields = schema["schema"] + if fields["type"] == "model-fields": + extras = fields.get("extras_schema") + if extras and "cls" in extras: + # mypy can't narrow the type + return extras["cls"] # type: ignore[no-any-return] + + return None + + def is_basemodel(type_: type) -> bool: """Returns whether or not the given type is either a `BaseModel` or a union of `BaseModel`""" if is_union(type_): diff --git a/tests/test_models.py b/tests/test_models.py index a8867d60..14d98180 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,5 +1,5 @@ import json -from typing import Any, Dict, List, Union, Optional, cast +from typing import TYPE_CHECKING, Any, Dict, List, Union, Optional, cast from datetime import datetime, timezone from typing_extensions import Literal, Annotated, TypeAliasType @@ -934,3 +934,30 @@ class Type2(BaseModel): ) assert isinstance(model, Type1) assert isinstance(model.value, InnerType2) + + +@pytest.mark.skipif(not PYDANTIC_V2, reason="this is only supported in pydantic v2 for now") +def test_extra_properties() -> None: + class Item(BaseModel): + prop: int + + class Model(BaseModel): + __pydantic_extra__: Dict[str, Item] = Field(init=False) # pyright: ignore[reportIncompatibleVariableOverride] + + other: str + + if TYPE_CHECKING: + + def __getattr__(self, attr: str) -> Item: ... + + model = construct_type( + type_=Model, + value={ + "a": {"prop": 1}, + "other": "foo", + }, + ) + assert isinstance(model, Model) + assert model.a.prop == 1 + assert isinstance(model.a, Item) + assert model.other == "foo" From 7bde6b727d6d16ebd6805ef843596fc3224445a6 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 22 Jul 2025 16:00:11 +0000 Subject: [PATCH 2/3] fix(api): build errors - update openapi spec - comment out models that don't exist - add back methods for backwards compatibility for now --- .stats.yml | 4 +- README.md | 44 +- api.md | 45 +- src/agentex/_client.py | 4 +- src/agentex/resources/agents/__init__.py | 33 ++ src/agentex/resources/{ => agents}/agents.py | 50 +- src/agentex/resources/agents/name.py | 454 ++++++++++++++++++ src/agentex/resources/tasks/__init__.py | 33 ++ src/agentex/resources/tasks/name.py | 324 +++++++++++++ src/agentex/resources/{ => tasks}/tasks.py | 48 +- src/agentex/types/agents/__init__.py | 6 + .../types/agents/name_handle_rpc_params.py | 85 ++++ src/agentex/types/agents/name_rpc_params.py | 85 ++++ src/agentex/types/tasks/__init__.py | 3 + tests/api_resources/agents/__init__.py | 1 + tests/api_resources/agents/test_name.py | 452 +++++++++++++++++ tests/api_resources/tasks/__init__.py | 1 + tests/api_resources/tasks/test_name.py | 274 +++++++++++ tests/conftest.py | 8 +- tests/test_client.py | 227 ++++++--- 20 files changed, 2044 insertions(+), 137 deletions(-) create mode 100644 src/agentex/resources/agents/__init__.py rename src/agentex/resources/{ => agents}/agents.py (94%) create mode 100644 src/agentex/resources/agents/name.py create mode 100644 src/agentex/resources/tasks/__init__.py create mode 100644 src/agentex/resources/tasks/name.py rename src/agentex/resources/{ => tasks}/tasks.py (94%) create mode 100644 src/agentex/types/agents/__init__.py create mode 100644 src/agentex/types/agents/name_handle_rpc_params.py create mode 100644 src/agentex/types/agents/name_rpc_params.py create mode 100644 src/agentex/types/tasks/__init__.py create mode 100644 tests/api_resources/agents/__init__.py create mode 100644 tests/api_resources/agents/test_name.py create mode 100644 tests/api_resources/tasks/__init__.py create mode 100644 tests/api_resources/tasks/test_name.py diff --git a/.stats.yml b/.stats.yml index 91523e16..5a7503fb 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 34 openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/sgp%2Fagentex-sdk-021b55c88964b7a5bfc9d692d32a52c6b0150445656d2407c4cb8e9dd1e5f100.yml -openapi_spec_hash: ed92c0d5d6bed9cb5617f8a776ac42c9 -config_hash: 7661726e3cccf9f6349179841153601d +openapi_spec_hash: 3f634d45f6241dea4fbdac496b70f5a3 +config_hash: 7c45df33d1cc4df7ea9dac3b0968b0f0 diff --git a/README.md b/README.md index 2bdbb592..588fc8cc 100644 --- a/README.md +++ b/README.md @@ -28,17 +28,16 @@ pip install git+ssh://git@github.com/scaleapi/agentex-python.git The full API of this library can be found in [api.md](api.md). ```python +import os from agentex import Agentex client = Agentex( + api_key=os.environ.get("AGENTEX_SDK_API_KEY"), # This is the default and can be omitted # defaults to "production". environment="development", ) -agent = client.agents.retrieve( - "agent_id", -) -print(agent.id) +tasks = client.tasks.list() ``` While you can provide an `api_key` keyword argument, @@ -51,20 +50,19 @@ so that your API Key is not stored in source control. Simply import `AsyncAgentex` instead of `Agentex` and use `await` with each API call: ```python +import os import asyncio from agentex import AsyncAgentex client = AsyncAgentex( + api_key=os.environ.get("AGENTEX_SDK_API_KEY"), # This is the default and can be omitted # defaults to "production". environment="development", ) async def main() -> None: - agent = await client.agents.retrieve( - "agent_id", - ) - print(agent.id) + tasks = await client.tasks.list() asyncio.run(main()) @@ -93,12 +91,10 @@ from agentex import AsyncAgentex async def main() -> None: async with AsyncAgentex( + api_key="My API Key", http_client=DefaultAioHttpClient(), ) as client: - agent = await client.agents.retrieve( - "agent_id", - ) - print(agent.id) + tasks = await client.tasks.list() asyncio.run(main()) @@ -129,9 +125,7 @@ from agentex import Agentex client = Agentex() try: - client.agents.retrieve( - "agent_id", - ) + client.tasks.list() except agentex.APIConnectionError as e: print("The server could not be reached") print(e.__cause__) # an underlying Exception, likely raised within httpx. @@ -174,9 +168,7 @@ client = Agentex( ) # Or, configure per-request: -client.with_options(max_retries=5).agents.retrieve( - "agent_id", -) +client.with_options(max_retries=5).tasks.list() ``` ### Timeouts @@ -199,9 +191,7 @@ client = Agentex( ) # Override per-request: -client.with_options(timeout=5.0).agents.retrieve( - "agent_id", -) +client.with_options(timeout=5.0).tasks.list() ``` On timeout, an `APITimeoutError` is thrown. @@ -242,13 +232,11 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to from agentex import Agentex client = Agentex() -response = client.agents.with_raw_response.retrieve( - "agent_id", -) +response = client.tasks.with_raw_response.list() print(response.headers.get('X-My-Header')) -agent = response.parse() # get the object that `agents.retrieve()` would have returned -print(agent.id) +task = response.parse() # get the object that `tasks.list()` would have returned +print(task) ``` These methods return an [`APIResponse`](https://github.com/scaleapi/agentex-python/tree/main/src/agentex/_response.py) object. @@ -262,9 +250,7 @@ The above interface eagerly reads the full response body when you make the reque To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods. ```python -with client.agents.with_streaming_response.retrieve( - "agent_id", -) as response: +with client.tasks.with_streaming_response.list() as response: print(response.headers.get("X-My-Header")) for line in response.iter_lines(): diff --git a/api.md b/api.md index 8c2841ca..0d482fb9 100644 --- a/api.md +++ b/api.md @@ -8,13 +8,22 @@ from agentex.types import AcpType, Agent, AgentRpcRequest, AgentListResponse Methods: -- client.agents.retrieve(agent_id) -> Agent -- client.agents.list(\*\*params) -> AgentListResponse -- client.agents.delete(agent_id) -> Agent -- client.agents.delete_by_name(agent_name) -> Agent -- client.agents.retrieve_by_name(agent_name) -> Agent -- client.agents.rpc(agent_id, \*\*params) -> object -- client.agents.rpc_by_name(agent_name, \*\*params) -> object +- client.agents.retrieve(agent_id) -> Agent +- client.agents.list(\*\*params) -> AgentListResponse +- client.agents.delete(agent_id) -> Agent +- client.agents.delete_by_name(agent_name) -> Agent +- client.agents.retrieve_by_name(agent_name) -> Agent +- client.agents.rpc(agent_id, \*\*params) -> object +- client.agents.rpc_by_name(agent_name, \*\*params) -> object + +## Name + +Methods: + +- client.agents.name.retrieve(agent_name) -> Agent +- client.agents.name.delete(agent_name) -> Agent +- client.agents.name.handle_rpc(agent_name, \*\*params) -> object +- client.agents.name.rpc(agent_name, \*\*params) -> object # Tasks @@ -26,13 +35,21 @@ from agentex.types import Task, TaskListResponse Methods: -- client.tasks.retrieve(task_id) -> Task -- client.tasks.list() -> TaskListResponse -- client.tasks.delete(task_id) -> Task -- client.tasks.delete_by_name(task_name) -> Task -- client.tasks.retrieve_by_name(task_name) -> Task -- client.tasks.stream_events(task_id) -> object -- client.tasks.stream_events_by_name(task_name) -> object +- client.tasks.retrieve(task_id) -> Task +- client.tasks.list() -> TaskListResponse +- client.tasks.delete(task_id) -> Task +- client.tasks.delete_by_name(task_name) -> Task +- client.tasks.retrieve_by_name(task_name) -> Task +- client.tasks.stream_events(task_id) -> object +- client.tasks.stream_events_by_name(task_name) -> object + +## Name + +Methods: + +- client.tasks.name.retrieve(task_name) -> Task +- client.tasks.name.delete(task_name) -> Task +- client.tasks.name.stream_events(task_name) -> object # Messages diff --git a/src/agentex/_client.py b/src/agentex/_client.py index 51ebb5e8..d1af575d 100644 --- a/src/agentex/_client.py +++ b/src/agentex/_client.py @@ -21,7 +21,7 @@ ) from ._utils import is_given, get_async_library from ._version import __version__ -from .resources import spans, tasks, agents, events, states, tracker +from .resources import spans, events, states, tracker from ._streaming import Stream as Stream, AsyncStream as AsyncStream from ._exceptions import APIStatusError from ._base_client import ( @@ -29,6 +29,8 @@ SyncAPIClient, AsyncAPIClient, ) +from .resources.tasks import tasks +from .resources.agents import agents from .resources.messages import messages __all__ = [ diff --git a/src/agentex/resources/agents/__init__.py b/src/agentex/resources/agents/__init__.py new file mode 100644 index 00000000..374345e0 --- /dev/null +++ b/src/agentex/resources/agents/__init__.py @@ -0,0 +1,33 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from .name import ( + NameResource, + AsyncNameResource, + NameResourceWithRawResponse, + AsyncNameResourceWithRawResponse, + NameResourceWithStreamingResponse, + AsyncNameResourceWithStreamingResponse, +) +from .agents import ( + AgentsResource, + AsyncAgentsResource, + AgentsResourceWithRawResponse, + AsyncAgentsResourceWithRawResponse, + AgentsResourceWithStreamingResponse, + AsyncAgentsResourceWithStreamingResponse, +) + +__all__ = [ + "NameResource", + "AsyncNameResource", + "NameResourceWithRawResponse", + "AsyncNameResourceWithRawResponse", + "NameResourceWithStreamingResponse", + "AsyncNameResourceWithStreamingResponse", + "AgentsResource", + "AsyncAgentsResource", + "AgentsResourceWithRawResponse", + "AsyncAgentsResourceWithRawResponse", + "AgentsResourceWithStreamingResponse", + "AsyncAgentsResourceWithStreamingResponse", +] diff --git a/src/agentex/resources/agents.py b/src/agentex/resources/agents/agents.py similarity index 94% rename from src/agentex/resources/agents.py rename to src/agentex/resources/agents/agents.py index 9c2e4bd5..cdd3b891 100644 --- a/src/agentex/resources/agents.py +++ b/src/agentex/resources/agents/agents.py @@ -7,25 +7,37 @@ import httpx -from ..types import agent_rpc_params, agent_list_params, agent_rpc_by_name_params -from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven -from .._utils import maybe_transform, async_maybe_transform -from .._compat import cached_property -from .._resource import SyncAPIResource, AsyncAPIResource -from .._response import ( +from .name import ( + NameResource, + AsyncNameResource, + NameResourceWithRawResponse, + AsyncNameResourceWithRawResponse, + NameResourceWithStreamingResponse, + AsyncNameResourceWithStreamingResponse, +) +from ...types import agent_rpc_params, agent_list_params, agent_rpc_by_name_params +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven +from ..._utils import maybe_transform, async_maybe_transform +from ..._compat import cached_property +from ..._resource import SyncAPIResource, AsyncAPIResource +from ..._response import ( to_raw_response_wrapper, to_streamed_response_wrapper, async_to_raw_response_wrapper, async_to_streamed_response_wrapper, ) -from ..types.agent import Agent -from .._base_client import make_request_options -from ..types.agent_list_response import AgentListResponse +from ...types.agent import Agent +from ..._base_client import make_request_options +from ...types.agent_list_response import AgentListResponse __all__ = ["AgentsResource", "AsyncAgentsResource"] class AgentsResource(SyncAPIResource): + @cached_property + def name(self) -> NameResource: + return NameResource(self._client) + @cached_property def with_raw_response(self) -> AgentsResourceWithRawResponse: """ @@ -308,6 +320,10 @@ def rpc_by_name( class AsyncAgentsResource(AsyncAPIResource): + @cached_property + def name(self) -> AsyncNameResource: + return AsyncNameResource(self._client) + @cached_property def with_raw_response(self) -> AsyncAgentsResourceWithRawResponse: """ @@ -615,6 +631,10 @@ def __init__(self, agents: AgentsResource) -> None: agents.rpc_by_name, ) + @cached_property + def name(self) -> NameResourceWithRawResponse: + return NameResourceWithRawResponse(self._agents.name) + class AsyncAgentsResourceWithRawResponse: def __init__(self, agents: AsyncAgentsResource) -> None: @@ -642,6 +662,10 @@ def __init__(self, agents: AsyncAgentsResource) -> None: agents.rpc_by_name, ) + @cached_property + def name(self) -> AsyncNameResourceWithRawResponse: + return AsyncNameResourceWithRawResponse(self._agents.name) + class AgentsResourceWithStreamingResponse: def __init__(self, agents: AgentsResource) -> None: @@ -669,6 +693,10 @@ def __init__(self, agents: AgentsResource) -> None: agents.rpc_by_name, ) + @cached_property + def name(self) -> NameResourceWithStreamingResponse: + return NameResourceWithStreamingResponse(self._agents.name) + class AsyncAgentsResourceWithStreamingResponse: def __init__(self, agents: AsyncAgentsResource) -> None: @@ -695,3 +723,7 @@ def __init__(self, agents: AsyncAgentsResource) -> None: self.rpc_by_name = async_to_streamed_response_wrapper( agents.rpc_by_name, ) + + @cached_property + def name(self) -> AsyncNameResourceWithStreamingResponse: + return AsyncNameResourceWithStreamingResponse(self._agents.name) diff --git a/src/agentex/resources/agents/name.py b/src/agentex/resources/agents/name.py new file mode 100644 index 00000000..fd8c82f9 --- /dev/null +++ b/src/agentex/resources/agents/name.py @@ -0,0 +1,454 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Union +from typing_extensions import Literal + +import httpx + +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven +from ..._utils import maybe_transform, async_maybe_transform +from ..._compat import cached_property +from ..._resource import SyncAPIResource, AsyncAPIResource +from ..._response import ( + to_raw_response_wrapper, + to_streamed_response_wrapper, + async_to_raw_response_wrapper, + async_to_streamed_response_wrapper, +) +from ...types.agent import Agent +from ..._base_client import make_request_options +from ...types.agents import name_rpc_params, name_handle_rpc_params + +__all__ = ["NameResource", "AsyncNameResource"] + + +class NameResource(SyncAPIResource): + @cached_property + def with_raw_response(self) -> NameResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/scaleapi/agentex-python#accessing-raw-response-data-eg-headers + """ + return NameResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> NameResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/scaleapi/agentex-python#with_streaming_response + """ + return NameResourceWithStreamingResponse(self) + + def retrieve( + self, + agent_name: str, + *, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> Agent: + """ + Get an agent by its unique name. + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not agent_name: + raise ValueError(f"Expected a non-empty value for `agent_name` but received {agent_name!r}") + return self._get( + f"/agents/name/{agent_name}", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=Agent, + ) + + def delete( + self, + agent_name: str, + *, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> Agent: + """ + Delete an agent by its unique name. + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not agent_name: + raise ValueError(f"Expected a non-empty value for `agent_name` but received {agent_name!r}") + return self._delete( + f"/agents/name/{agent_name}", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=Agent, + ) + + def handle_rpc( + self, + agent_name: str, + *, + method: Literal["event/send", "task/create", "message/send", "task/cancel"], + params: name_handle_rpc_params.Params, + id: Union[int, str, None] | NotGiven = NOT_GIVEN, + jsonrpc: Literal["2.0"] | NotGiven = NOT_GIVEN, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> object: + """ + Handle JSON-RPC requests for an agent by its unique name. + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not agent_name: + raise ValueError(f"Expected a non-empty value for `agent_name` but received {agent_name!r}") + return self._post( + f"/agents/name/{agent_name}/rpc", + body=maybe_transform( + { + "method": method, + "params": params, + "id": id, + "jsonrpc": jsonrpc, + }, + name_handle_rpc_params.NameHandleRpcParams, + ), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=object, + ) + + def rpc( + self, + agent_name: str, + *, + method: Literal["event/send", "task/create", "message/send", "task/cancel"], + params: name_rpc_params.Params, + id: Union[int, str, None] | NotGiven = NOT_GIVEN, + jsonrpc: Literal["2.0"] | NotGiven = NOT_GIVEN, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> object: + """ + Handle JSON-RPC requests for an agent by its unique name. + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not agent_name: + raise ValueError(f"Expected a non-empty value for `agent_name` but received {agent_name!r}") + return self._post( + f"/agents/name/{agent_name}/rpc", + body=maybe_transform( + { + "method": method, + "params": params, + "id": id, + "jsonrpc": jsonrpc, + }, + name_rpc_params.NameRpcParams, + ), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=object, + ) + + +class AsyncNameResource(AsyncAPIResource): + @cached_property + def with_raw_response(self) -> AsyncNameResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/scaleapi/agentex-python#accessing-raw-response-data-eg-headers + """ + return AsyncNameResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncNameResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/scaleapi/agentex-python#with_streaming_response + """ + return AsyncNameResourceWithStreamingResponse(self) + + async def retrieve( + self, + agent_name: str, + *, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> Agent: + """ + Get an agent by its unique name. + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not agent_name: + raise ValueError(f"Expected a non-empty value for `agent_name` but received {agent_name!r}") + return await self._get( + f"/agents/name/{agent_name}", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=Agent, + ) + + async def delete( + self, + agent_name: str, + *, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> Agent: + """ + Delete an agent by its unique name. + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not agent_name: + raise ValueError(f"Expected a non-empty value for `agent_name` but received {agent_name!r}") + return await self._delete( + f"/agents/name/{agent_name}", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=Agent, + ) + + async def handle_rpc( + self, + agent_name: str, + *, + method: Literal["event/send", "task/create", "message/send", "task/cancel"], + params: name_handle_rpc_params.Params, + id: Union[int, str, None] | NotGiven = NOT_GIVEN, + jsonrpc: Literal["2.0"] | NotGiven = NOT_GIVEN, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> object: + """ + Handle JSON-RPC requests for an agent by its unique name. + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not agent_name: + raise ValueError(f"Expected a non-empty value for `agent_name` but received {agent_name!r}") + return await self._post( + f"/agents/name/{agent_name}/rpc", + body=await async_maybe_transform( + { + "method": method, + "params": params, + "id": id, + "jsonrpc": jsonrpc, + }, + name_handle_rpc_params.NameHandleRpcParams, + ), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=object, + ) + + async def rpc( + self, + agent_name: str, + *, + method: Literal["event/send", "task/create", "message/send", "task/cancel"], + params: name_rpc_params.Params, + id: Union[int, str, None] | NotGiven = NOT_GIVEN, + jsonrpc: Literal["2.0"] | NotGiven = NOT_GIVEN, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> object: + """ + Handle JSON-RPC requests for an agent by its unique name. + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not agent_name: + raise ValueError(f"Expected a non-empty value for `agent_name` but received {agent_name!r}") + return await self._post( + f"/agents/name/{agent_name}/rpc", + body=await async_maybe_transform( + { + "method": method, + "params": params, + "id": id, + "jsonrpc": jsonrpc, + }, + name_rpc_params.NameRpcParams, + ), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=object, + ) + + +class NameResourceWithRawResponse: + def __init__(self, name: NameResource) -> None: + self._name = name + + self.retrieve = to_raw_response_wrapper( + name.retrieve, + ) + self.delete = to_raw_response_wrapper( + name.delete, + ) + self.handle_rpc = to_raw_response_wrapper( + name.handle_rpc, + ) + self.rpc = to_raw_response_wrapper( + name.rpc, + ) + + +class AsyncNameResourceWithRawResponse: + def __init__(self, name: AsyncNameResource) -> None: + self._name = name + + self.retrieve = async_to_raw_response_wrapper( + name.retrieve, + ) + self.delete = async_to_raw_response_wrapper( + name.delete, + ) + self.handle_rpc = async_to_raw_response_wrapper( + name.handle_rpc, + ) + self.rpc = async_to_raw_response_wrapper( + name.rpc, + ) + + +class NameResourceWithStreamingResponse: + def __init__(self, name: NameResource) -> None: + self._name = name + + self.retrieve = to_streamed_response_wrapper( + name.retrieve, + ) + self.delete = to_streamed_response_wrapper( + name.delete, + ) + self.handle_rpc = to_streamed_response_wrapper( + name.handle_rpc, + ) + self.rpc = to_streamed_response_wrapper( + name.rpc, + ) + + +class AsyncNameResourceWithStreamingResponse: + def __init__(self, name: AsyncNameResource) -> None: + self._name = name + + self.retrieve = async_to_streamed_response_wrapper( + name.retrieve, + ) + self.delete = async_to_streamed_response_wrapper( + name.delete, + ) + self.handle_rpc = async_to_streamed_response_wrapper( + name.handle_rpc, + ) + self.rpc = async_to_streamed_response_wrapper( + name.rpc, + ) diff --git a/src/agentex/resources/tasks/__init__.py b/src/agentex/resources/tasks/__init__.py new file mode 100644 index 00000000..5a9c81b0 --- /dev/null +++ b/src/agentex/resources/tasks/__init__.py @@ -0,0 +1,33 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from .name import ( + NameResource, + AsyncNameResource, + NameResourceWithRawResponse, + AsyncNameResourceWithRawResponse, + NameResourceWithStreamingResponse, + AsyncNameResourceWithStreamingResponse, +) +from .tasks import ( + TasksResource, + AsyncTasksResource, + TasksResourceWithRawResponse, + AsyncTasksResourceWithRawResponse, + TasksResourceWithStreamingResponse, + AsyncTasksResourceWithStreamingResponse, +) + +__all__ = [ + "NameResource", + "AsyncNameResource", + "NameResourceWithRawResponse", + "AsyncNameResourceWithRawResponse", + "NameResourceWithStreamingResponse", + "AsyncNameResourceWithStreamingResponse", + "TasksResource", + "AsyncTasksResource", + "TasksResourceWithRawResponse", + "AsyncTasksResourceWithRawResponse", + "TasksResourceWithStreamingResponse", + "AsyncTasksResourceWithStreamingResponse", +] diff --git a/src/agentex/resources/tasks/name.py b/src/agentex/resources/tasks/name.py new file mode 100644 index 00000000..7cef42eb --- /dev/null +++ b/src/agentex/resources/tasks/name.py @@ -0,0 +1,324 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import httpx + +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven +from ..._compat import cached_property +from ..._resource import SyncAPIResource, AsyncAPIResource +from ..._response import ( + to_raw_response_wrapper, + to_streamed_response_wrapper, + async_to_raw_response_wrapper, + async_to_streamed_response_wrapper, +) +from ..._streaming import Stream, AsyncStream +from ...types.task import Task +from ..._base_client import make_request_options + +__all__ = ["NameResource", "AsyncNameResource"] + + +class NameResource(SyncAPIResource): + @cached_property + def with_raw_response(self) -> NameResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/scaleapi/agentex-python#accessing-raw-response-data-eg-headers + """ + return NameResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> NameResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/scaleapi/agentex-python#with_streaming_response + """ + return NameResourceWithStreamingResponse(self) + + def retrieve( + self, + task_name: str, + *, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> Task: + """ + Get a task by its unique name. + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not task_name: + raise ValueError(f"Expected a non-empty value for `task_name` but received {task_name!r}") + return self._get( + f"/tasks/name/{task_name}", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=Task, + ) + + def delete( + self, + task_name: str, + *, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> Task: + """ + Delete a task by its unique name. + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not task_name: + raise ValueError(f"Expected a non-empty value for `task_name` but received {task_name!r}") + return self._delete( + f"/tasks/name/{task_name}", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=Task, + ) + + def stream_events( + self, + task_name: str, + *, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> Stream[object]: + """ + Stream events for a task by its unique name. + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not task_name: + raise ValueError(f"Expected a non-empty value for `task_name` but received {task_name!r}") + return self._get( + f"/tasks/name/{task_name}/stream", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=object, + stream=True, + stream_cls=Stream[object], + ) + + +class AsyncNameResource(AsyncAPIResource): + @cached_property + def with_raw_response(self) -> AsyncNameResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/scaleapi/agentex-python#accessing-raw-response-data-eg-headers + """ + return AsyncNameResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncNameResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/scaleapi/agentex-python#with_streaming_response + """ + return AsyncNameResourceWithStreamingResponse(self) + + async def retrieve( + self, + task_name: str, + *, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> Task: + """ + Get a task by its unique name. + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not task_name: + raise ValueError(f"Expected a non-empty value for `task_name` but received {task_name!r}") + return await self._get( + f"/tasks/name/{task_name}", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=Task, + ) + + async def delete( + self, + task_name: str, + *, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> Task: + """ + Delete a task by its unique name. + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not task_name: + raise ValueError(f"Expected a non-empty value for `task_name` but received {task_name!r}") + return await self._delete( + f"/tasks/name/{task_name}", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=Task, + ) + + async def stream_events( + self, + task_name: str, + *, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> AsyncStream[object]: + """ + Stream events for a task by its unique name. + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not task_name: + raise ValueError(f"Expected a non-empty value for `task_name` but received {task_name!r}") + return await self._get( + f"/tasks/name/{task_name}/stream", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=object, + stream=True, + stream_cls=AsyncStream[object], + ) + + +class NameResourceWithRawResponse: + def __init__(self, name: NameResource) -> None: + self._name = name + + self.retrieve = to_raw_response_wrapper( + name.retrieve, + ) + self.delete = to_raw_response_wrapper( + name.delete, + ) + self.stream_events = to_raw_response_wrapper( + name.stream_events, + ) + + +class AsyncNameResourceWithRawResponse: + def __init__(self, name: AsyncNameResource) -> None: + self._name = name + + self.retrieve = async_to_raw_response_wrapper( + name.retrieve, + ) + self.delete = async_to_raw_response_wrapper( + name.delete, + ) + self.stream_events = async_to_raw_response_wrapper( + name.stream_events, + ) + + +class NameResourceWithStreamingResponse: + def __init__(self, name: NameResource) -> None: + self._name = name + + self.retrieve = to_streamed_response_wrapper( + name.retrieve, + ) + self.delete = to_streamed_response_wrapper( + name.delete, + ) + self.stream_events = to_streamed_response_wrapper( + name.stream_events, + ) + + +class AsyncNameResourceWithStreamingResponse: + def __init__(self, name: AsyncNameResource) -> None: + self._name = name + + self.retrieve = async_to_streamed_response_wrapper( + name.retrieve, + ) + self.delete = async_to_streamed_response_wrapper( + name.delete, + ) + self.stream_events = async_to_streamed_response_wrapper( + name.stream_events, + ) diff --git a/src/agentex/resources/tasks.py b/src/agentex/resources/tasks/tasks.py similarity index 94% rename from src/agentex/resources/tasks.py rename to src/agentex/resources/tasks/tasks.py index 936ee66c..ce1a7813 100644 --- a/src/agentex/resources/tasks.py +++ b/src/agentex/resources/tasks/tasks.py @@ -4,24 +4,36 @@ import httpx -from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven -from .._compat import cached_property -from .._resource import SyncAPIResource, AsyncAPIResource -from .._response import ( +from .name import ( + NameResource, + AsyncNameResource, + NameResourceWithRawResponse, + AsyncNameResourceWithRawResponse, + NameResourceWithStreamingResponse, + AsyncNameResourceWithStreamingResponse, +) +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven +from ..._compat import cached_property +from ..._resource import SyncAPIResource, AsyncAPIResource +from ..._response import ( to_raw_response_wrapper, to_streamed_response_wrapper, async_to_raw_response_wrapper, async_to_streamed_response_wrapper, ) -from .._streaming import Stream, AsyncStream -from ..types.task import Task -from .._base_client import make_request_options -from ..types.task_list_response import TaskListResponse +from ..._streaming import Stream, AsyncStream +from ...types.task import Task +from ..._base_client import make_request_options +from ...types.task_list_response import TaskListResponse __all__ = ["TasksResource", "AsyncTasksResource"] class TasksResource(SyncAPIResource): + @cached_property + def name(self) -> NameResource: + return NameResource(self._client) + @cached_property def with_raw_response(self) -> TasksResourceWithRawResponse: """ @@ -264,6 +276,10 @@ def stream_events_by_name( class AsyncTasksResource(AsyncAPIResource): + @cached_property + def name(self) -> AsyncNameResource: + return AsyncNameResource(self._client) + @cached_property def with_raw_response(self) -> AsyncTasksResourceWithRawResponse: """ @@ -531,6 +547,10 @@ def __init__(self, tasks: TasksResource) -> None: tasks.stream_events_by_name, ) + @cached_property + def name(self) -> NameResourceWithRawResponse: + return NameResourceWithRawResponse(self._tasks.name) + class AsyncTasksResourceWithRawResponse: def __init__(self, tasks: AsyncTasksResource) -> None: @@ -558,6 +578,10 @@ def __init__(self, tasks: AsyncTasksResource) -> None: tasks.stream_events_by_name, ) + @cached_property + def name(self) -> AsyncNameResourceWithRawResponse: + return AsyncNameResourceWithRawResponse(self._tasks.name) + class TasksResourceWithStreamingResponse: def __init__(self, tasks: TasksResource) -> None: @@ -585,6 +609,10 @@ def __init__(self, tasks: TasksResource) -> None: tasks.stream_events_by_name, ) + @cached_property + def name(self) -> NameResourceWithStreamingResponse: + return NameResourceWithStreamingResponse(self._tasks.name) + class AsyncTasksResourceWithStreamingResponse: def __init__(self, tasks: AsyncTasksResource) -> None: @@ -611,3 +639,7 @@ def __init__(self, tasks: AsyncTasksResource) -> None: self.stream_events_by_name = async_to_streamed_response_wrapper( tasks.stream_events_by_name, ) + + @cached_property + def name(self) -> AsyncNameResourceWithStreamingResponse: + return AsyncNameResourceWithStreamingResponse(self._tasks.name) diff --git a/src/agentex/types/agents/__init__.py b/src/agentex/types/agents/__init__.py new file mode 100644 index 00000000..6211202a --- /dev/null +++ b/src/agentex/types/agents/__init__.py @@ -0,0 +1,6 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from .name_rpc_params import NameRpcParams as NameRpcParams +from .name_handle_rpc_params import NameHandleRpcParams as NameHandleRpcParams diff --git a/src/agentex/types/agents/name_handle_rpc_params.py b/src/agentex/types/agents/name_handle_rpc_params.py new file mode 100644 index 00000000..d1d903a6 --- /dev/null +++ b/src/agentex/types/agents/name_handle_rpc_params.py @@ -0,0 +1,85 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Dict, Union, Optional +from typing_extensions import Literal, Required, TypeAlias, TypedDict + +from ..data_content_param import DataContentParam +from ..text_content_param import TextContentParam +from ..tool_request_content_param import ToolRequestContentParam +from ..tool_response_content_param import ToolResponseContentParam + +__all__ = [ + "NameHandleRpcParams", + "Params", + "ParamsCreateTaskRequest", + "ParamsCancelTaskRequest", + "ParamsSendMessageRequest", + "ParamsSendMessageRequestContent", + "ParamsSendEventRequest", + "ParamsSendEventRequestContent", +] + + +class NameHandleRpcParams(TypedDict, total=False): + method: Required[Literal["event/send", "task/create", "message/send", "task/cancel"]] + + params: Required[Params] + + id: Union[int, str, None] + + jsonrpc: Literal["2.0"] + + +class ParamsCreateTaskRequest(TypedDict, total=False): + name: Optional[str] + """The name of the task to create""" + + params: Optional[Dict[str, object]] + """The parameters for the task""" + + +class ParamsCancelTaskRequest(TypedDict, total=False): + task_id: Optional[str] + """The ID of the task to cancel. Either this or task_name must be provided.""" + + task_name: Optional[str] + """The name of the task to cancel. Either this or task_id must be provided.""" + + +ParamsSendMessageRequestContent: TypeAlias = Union[ + TextContentParam, DataContentParam, ToolRequestContentParam, ToolResponseContentParam +] + + +class ParamsSendMessageRequest(TypedDict, total=False): + content: Required[ParamsSendMessageRequestContent] + """The message that was sent to the agent""" + + stream: bool + """Whether to stream the response message back to the client""" + + task_id: Optional[str] + """The ID of the task that the message was sent to""" + + +ParamsSendEventRequestContent: TypeAlias = Union[ + TextContentParam, DataContentParam, ToolRequestContentParam, ToolResponseContentParam +] + + +class ParamsSendEventRequest(TypedDict, total=False): + content: Optional[ParamsSendEventRequestContent] + """The content to send to the event""" + + task_id: Optional[str] + """The ID of the task that the event was sent to""" + + task_name: Optional[str] + """The name of the task that the event was sent to""" + + +Params: TypeAlias = Union[ + ParamsCreateTaskRequest, ParamsCancelTaskRequest, ParamsSendMessageRequest, ParamsSendEventRequest +] diff --git a/src/agentex/types/agents/name_rpc_params.py b/src/agentex/types/agents/name_rpc_params.py new file mode 100644 index 00000000..6a68b0ba --- /dev/null +++ b/src/agentex/types/agents/name_rpc_params.py @@ -0,0 +1,85 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Dict, Union, Optional +from typing_extensions import Literal, Required, TypeAlias, TypedDict + +from ..data_content_param import DataContentParam +from ..text_content_param import TextContentParam +from ..tool_request_content_param import ToolRequestContentParam +from ..tool_response_content_param import ToolResponseContentParam + +__all__ = [ + "NameRpcParams", + "Params", + "ParamsCreateTaskRequest", + "ParamsCancelTaskRequest", + "ParamsSendMessageRequest", + "ParamsSendMessageRequestContent", + "ParamsSendEventRequest", + "ParamsSendEventRequestContent", +] + + +class NameRpcParams(TypedDict, total=False): + method: Required[Literal["event/send", "task/create", "message/send", "task/cancel"]] + + params: Required[Params] + + id: Union[int, str, None] + + jsonrpc: Literal["2.0"] + + +class ParamsCreateTaskRequest(TypedDict, total=False): + name: Optional[str] + """The name of the task to create""" + + params: Optional[Dict[str, object]] + """The parameters for the task""" + + +class ParamsCancelTaskRequest(TypedDict, total=False): + task_id: Optional[str] + """The ID of the task to cancel. Either this or task_name must be provided.""" + + task_name: Optional[str] + """The name of the task to cancel. Either this or task_id must be provided.""" + + +ParamsSendMessageRequestContent: TypeAlias = Union[ + TextContentParam, DataContentParam, ToolRequestContentParam, ToolResponseContentParam +] + + +class ParamsSendMessageRequest(TypedDict, total=False): + content: Required[ParamsSendMessageRequestContent] + """The message that was sent to the agent""" + + stream: bool + """Whether to stream the response message back to the client""" + + task_id: Optional[str] + """The ID of the task that the message was sent to""" + + +ParamsSendEventRequestContent: TypeAlias = Union[ + TextContentParam, DataContentParam, ToolRequestContentParam, ToolResponseContentParam +] + + +class ParamsSendEventRequest(TypedDict, total=False): + content: Optional[ParamsSendEventRequestContent] + """The content to send to the event""" + + task_id: Optional[str] + """The ID of the task that the event was sent to""" + + task_name: Optional[str] + """The name of the task that the event was sent to""" + + +Params: TypeAlias = Union[ + ParamsCreateTaskRequest, ParamsCancelTaskRequest, ParamsSendMessageRequest, ParamsSendEventRequest +] diff --git a/src/agentex/types/tasks/__init__.py b/src/agentex/types/tasks/__init__.py new file mode 100644 index 00000000..f8ee8b14 --- /dev/null +++ b/src/agentex/types/tasks/__init__.py @@ -0,0 +1,3 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations diff --git a/tests/api_resources/agents/__init__.py b/tests/api_resources/agents/__init__.py new file mode 100644 index 00000000..fd8019a9 --- /dev/null +++ b/tests/api_resources/agents/__init__.py @@ -0,0 +1 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. diff --git a/tests/api_resources/agents/test_name.py b/tests/api_resources/agents/test_name.py new file mode 100644 index 00000000..dea82f12 --- /dev/null +++ b/tests/api_resources/agents/test_name.py @@ -0,0 +1,452 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import os +from typing import Any, cast + +import pytest + +from agentex import Agentex, AsyncAgentex +from tests.utils import assert_matches_type +from agentex.types import Agent + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestName: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @pytest.mark.skip() + @parametrize + def test_method_retrieve(self, client: Agentex) -> None: + name = client.agents.name.retrieve( + "agent_name", + ) + assert_matches_type(Agent, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_raw_response_retrieve(self, client: Agentex) -> None: + response = client.agents.name.with_raw_response.retrieve( + "agent_name", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + name = response.parse() + assert_matches_type(Agent, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_streaming_response_retrieve(self, client: Agentex) -> None: + with client.agents.name.with_streaming_response.retrieve( + "agent_name", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + name = response.parse() + assert_matches_type(Agent, name, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + def test_path_params_retrieve(self, client: Agentex) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `agent_name` but received ''"): + client.agents.name.with_raw_response.retrieve( + "", + ) + + @pytest.mark.skip() + @parametrize + def test_method_delete(self, client: Agentex) -> None: + name = client.agents.name.delete( + "agent_name", + ) + assert_matches_type(Agent, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_raw_response_delete(self, client: Agentex) -> None: + response = client.agents.name.with_raw_response.delete( + "agent_name", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + name = response.parse() + assert_matches_type(Agent, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_streaming_response_delete(self, client: Agentex) -> None: + with client.agents.name.with_streaming_response.delete( + "agent_name", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + name = response.parse() + assert_matches_type(Agent, name, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + def test_path_params_delete(self, client: Agentex) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `agent_name` but received ''"): + client.agents.name.with_raw_response.delete( + "", + ) + + @pytest.mark.skip() + @parametrize + def test_method_handle_rpc(self, client: Agentex) -> None: + name = client.agents.name.handle_rpc( + agent_name="agent_name", + method="event/send", + params={}, + ) + assert_matches_type(object, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_method_handle_rpc_with_all_params(self, client: Agentex) -> None: + name = client.agents.name.handle_rpc( + agent_name="agent_name", + method="event/send", + params={ + "name": "name", + "params": {"foo": "bar"}, + }, + id=0, + jsonrpc="2.0", + ) + assert_matches_type(object, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_raw_response_handle_rpc(self, client: Agentex) -> None: + response = client.agents.name.with_raw_response.handle_rpc( + agent_name="agent_name", + method="event/send", + params={}, + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + name = response.parse() + assert_matches_type(object, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_streaming_response_handle_rpc(self, client: Agentex) -> None: + with client.agents.name.with_streaming_response.handle_rpc( + agent_name="agent_name", + method="event/send", + params={}, + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + name = response.parse() + assert_matches_type(object, name, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + def test_path_params_handle_rpc(self, client: Agentex) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `agent_name` but received ''"): + client.agents.name.with_raw_response.handle_rpc( + agent_name="", + method="event/send", + params={}, + ) + + @pytest.mark.skip() + @parametrize + def test_method_rpc(self, client: Agentex) -> None: + name = client.agents.name.rpc( + agent_name="agent_name", + method="event/send", + params={}, + ) + assert_matches_type(object, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_method_rpc_with_all_params(self, client: Agentex) -> None: + name = client.agents.name.rpc( + agent_name="agent_name", + method="event/send", + params={ + "name": "name", + "params": {"foo": "bar"}, + }, + id=0, + jsonrpc="2.0", + ) + assert_matches_type(object, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_raw_response_rpc(self, client: Agentex) -> None: + response = client.agents.name.with_raw_response.rpc( + agent_name="agent_name", + method="event/send", + params={}, + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + name = response.parse() + assert_matches_type(object, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_streaming_response_rpc(self, client: Agentex) -> None: + with client.agents.name.with_streaming_response.rpc( + agent_name="agent_name", + method="event/send", + params={}, + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + name = response.parse() + assert_matches_type(object, name, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + def test_path_params_rpc(self, client: Agentex) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `agent_name` but received ''"): + client.agents.name.with_raw_response.rpc( + agent_name="", + method="event/send", + params={}, + ) + + +class TestAsyncName: + parametrize = pytest.mark.parametrize( + "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"] + ) + + @pytest.mark.skip() + @parametrize + async def test_method_retrieve(self, async_client: AsyncAgentex) -> None: + name = await async_client.agents.name.retrieve( + "agent_name", + ) + assert_matches_type(Agent, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_raw_response_retrieve(self, async_client: AsyncAgentex) -> None: + response = await async_client.agents.name.with_raw_response.retrieve( + "agent_name", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + name = await response.parse() + assert_matches_type(Agent, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_streaming_response_retrieve(self, async_client: AsyncAgentex) -> None: + async with async_client.agents.name.with_streaming_response.retrieve( + "agent_name", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + name = await response.parse() + assert_matches_type(Agent, name, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + async def test_path_params_retrieve(self, async_client: AsyncAgentex) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `agent_name` but received ''"): + await async_client.agents.name.with_raw_response.retrieve( + "", + ) + + @pytest.mark.skip() + @parametrize + async def test_method_delete(self, async_client: AsyncAgentex) -> None: + name = await async_client.agents.name.delete( + "agent_name", + ) + assert_matches_type(Agent, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_raw_response_delete(self, async_client: AsyncAgentex) -> None: + response = await async_client.agents.name.with_raw_response.delete( + "agent_name", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + name = await response.parse() + assert_matches_type(Agent, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_streaming_response_delete(self, async_client: AsyncAgentex) -> None: + async with async_client.agents.name.with_streaming_response.delete( + "agent_name", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + name = await response.parse() + assert_matches_type(Agent, name, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + async def test_path_params_delete(self, async_client: AsyncAgentex) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `agent_name` but received ''"): + await async_client.agents.name.with_raw_response.delete( + "", + ) + + @pytest.mark.skip() + @parametrize + async def test_method_handle_rpc(self, async_client: AsyncAgentex) -> None: + name = await async_client.agents.name.handle_rpc( + agent_name="agent_name", + method="event/send", + params={}, + ) + assert_matches_type(object, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_method_handle_rpc_with_all_params(self, async_client: AsyncAgentex) -> None: + name = await async_client.agents.name.handle_rpc( + agent_name="agent_name", + method="event/send", + params={ + "name": "name", + "params": {"foo": "bar"}, + }, + id=0, + jsonrpc="2.0", + ) + assert_matches_type(object, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_raw_response_handle_rpc(self, async_client: AsyncAgentex) -> None: + response = await async_client.agents.name.with_raw_response.handle_rpc( + agent_name="agent_name", + method="event/send", + params={}, + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + name = await response.parse() + assert_matches_type(object, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_streaming_response_handle_rpc(self, async_client: AsyncAgentex) -> None: + async with async_client.agents.name.with_streaming_response.handle_rpc( + agent_name="agent_name", + method="event/send", + params={}, + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + name = await response.parse() + assert_matches_type(object, name, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + async def test_path_params_handle_rpc(self, async_client: AsyncAgentex) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `agent_name` but received ''"): + await async_client.agents.name.with_raw_response.handle_rpc( + agent_name="", + method="event/send", + params={}, + ) + + @pytest.mark.skip() + @parametrize + async def test_method_rpc(self, async_client: AsyncAgentex) -> None: + name = await async_client.agents.name.rpc( + agent_name="agent_name", + method="event/send", + params={}, + ) + assert_matches_type(object, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_method_rpc_with_all_params(self, async_client: AsyncAgentex) -> None: + name = await async_client.agents.name.rpc( + agent_name="agent_name", + method="event/send", + params={ + "name": "name", + "params": {"foo": "bar"}, + }, + id=0, + jsonrpc="2.0", + ) + assert_matches_type(object, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_raw_response_rpc(self, async_client: AsyncAgentex) -> None: + response = await async_client.agents.name.with_raw_response.rpc( + agent_name="agent_name", + method="event/send", + params={}, + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + name = await response.parse() + assert_matches_type(object, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_streaming_response_rpc(self, async_client: AsyncAgentex) -> None: + async with async_client.agents.name.with_streaming_response.rpc( + agent_name="agent_name", + method="event/send", + params={}, + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + name = await response.parse() + assert_matches_type(object, name, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + async def test_path_params_rpc(self, async_client: AsyncAgentex) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `agent_name` but received ''"): + await async_client.agents.name.with_raw_response.rpc( + agent_name="", + method="event/send", + params={}, + ) diff --git a/tests/api_resources/tasks/__init__.py b/tests/api_resources/tasks/__init__.py new file mode 100644 index 00000000..fd8019a9 --- /dev/null +++ b/tests/api_resources/tasks/__init__.py @@ -0,0 +1 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. diff --git a/tests/api_resources/tasks/test_name.py b/tests/api_resources/tasks/test_name.py new file mode 100644 index 00000000..cb000659 --- /dev/null +++ b/tests/api_resources/tasks/test_name.py @@ -0,0 +1,274 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import os +from typing import Any, cast + +import pytest + +from agentex import Agentex, AsyncAgentex +from tests.utils import assert_matches_type +from agentex.types import Task + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestName: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @pytest.mark.skip() + @parametrize + def test_method_retrieve(self, client: Agentex) -> None: + name = client.tasks.name.retrieve( + "task_name", + ) + assert_matches_type(Task, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_raw_response_retrieve(self, client: Agentex) -> None: + response = client.tasks.name.with_raw_response.retrieve( + "task_name", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + name = response.parse() + assert_matches_type(Task, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_streaming_response_retrieve(self, client: Agentex) -> None: + with client.tasks.name.with_streaming_response.retrieve( + "task_name", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + name = response.parse() + assert_matches_type(Task, name, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + def test_path_params_retrieve(self, client: Agentex) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `task_name` but received ''"): + client.tasks.name.with_raw_response.retrieve( + "", + ) + + @pytest.mark.skip() + @parametrize + def test_method_delete(self, client: Agentex) -> None: + name = client.tasks.name.delete( + "task_name", + ) + assert_matches_type(Task, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_raw_response_delete(self, client: Agentex) -> None: + response = client.tasks.name.with_raw_response.delete( + "task_name", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + name = response.parse() + assert_matches_type(Task, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_streaming_response_delete(self, client: Agentex) -> None: + with client.tasks.name.with_streaming_response.delete( + "task_name", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + name = response.parse() + assert_matches_type(Task, name, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + def test_path_params_delete(self, client: Agentex) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `task_name` but received ''"): + client.tasks.name.with_raw_response.delete( + "", + ) + + @pytest.mark.skip() + @parametrize + def test_method_stream_events(self, client: Agentex) -> None: + name_stream = client.tasks.name.stream_events( + "task_name", + ) + name_stream.response.close() + + @pytest.mark.skip() + @parametrize + def test_raw_response_stream_events(self, client: Agentex) -> None: + response = client.tasks.name.with_raw_response.stream_events( + "task_name", + ) + + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + stream = response.parse() + stream.close() + + @pytest.mark.skip() + @parametrize + def test_streaming_response_stream_events(self, client: Agentex) -> None: + with client.tasks.name.with_streaming_response.stream_events( + "task_name", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + stream = response.parse() + stream.close() + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + def test_path_params_stream_events(self, client: Agentex) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `task_name` but received ''"): + client.tasks.name.with_raw_response.stream_events( + "", + ) + + +class TestAsyncName: + parametrize = pytest.mark.parametrize( + "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"] + ) + + @pytest.mark.skip() + @parametrize + async def test_method_retrieve(self, async_client: AsyncAgentex) -> None: + name = await async_client.tasks.name.retrieve( + "task_name", + ) + assert_matches_type(Task, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_raw_response_retrieve(self, async_client: AsyncAgentex) -> None: + response = await async_client.tasks.name.with_raw_response.retrieve( + "task_name", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + name = await response.parse() + assert_matches_type(Task, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_streaming_response_retrieve(self, async_client: AsyncAgentex) -> None: + async with async_client.tasks.name.with_streaming_response.retrieve( + "task_name", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + name = await response.parse() + assert_matches_type(Task, name, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + async def test_path_params_retrieve(self, async_client: AsyncAgentex) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `task_name` but received ''"): + await async_client.tasks.name.with_raw_response.retrieve( + "", + ) + + @pytest.mark.skip() + @parametrize + async def test_method_delete(self, async_client: AsyncAgentex) -> None: + name = await async_client.tasks.name.delete( + "task_name", + ) + assert_matches_type(Task, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_raw_response_delete(self, async_client: AsyncAgentex) -> None: + response = await async_client.tasks.name.with_raw_response.delete( + "task_name", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + name = await response.parse() + assert_matches_type(Task, name, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_streaming_response_delete(self, async_client: AsyncAgentex) -> None: + async with async_client.tasks.name.with_streaming_response.delete( + "task_name", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + name = await response.parse() + assert_matches_type(Task, name, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + async def test_path_params_delete(self, async_client: AsyncAgentex) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `task_name` but received ''"): + await async_client.tasks.name.with_raw_response.delete( + "", + ) + + @pytest.mark.skip() + @parametrize + async def test_method_stream_events(self, async_client: AsyncAgentex) -> None: + name_stream = await async_client.tasks.name.stream_events( + "task_name", + ) + await name_stream.response.aclose() + + @pytest.mark.skip() + @parametrize + async def test_raw_response_stream_events(self, async_client: AsyncAgentex) -> None: + response = await async_client.tasks.name.with_raw_response.stream_events( + "task_name", + ) + + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + stream = await response.parse() + await stream.close() + + @pytest.mark.skip() + @parametrize + async def test_streaming_response_stream_events(self, async_client: AsyncAgentex) -> None: + async with async_client.tasks.name.with_streaming_response.stream_events( + "task_name", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + stream = await response.parse() + await stream.close() + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + async def test_path_params_stream_events(self, async_client: AsyncAgentex) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `task_name` but received ''"): + await async_client.tasks.name.with_raw_response.stream_events( + "", + ) diff --git a/tests/conftest.py b/tests/conftest.py index b6e6697e..d08e65cf 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -45,6 +45,8 @@ def pytest_collection_modifyitems(items: list[pytest.Function]) -> None: base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") +api_key = "My API Key" + @pytest.fixture(scope="session") def client(request: FixtureRequest) -> Iterator[Agentex]: @@ -52,7 +54,7 @@ def client(request: FixtureRequest) -> Iterator[Agentex]: if not isinstance(strict, bool): raise TypeError(f"Unexpected fixture parameter type {type(strict)}, expected {bool}") - with Agentex(base_url=base_url, _strict_response_validation=strict) as client: + with Agentex(base_url=base_url, api_key=api_key, _strict_response_validation=strict) as client: yield client @@ -76,5 +78,7 @@ async def async_client(request: FixtureRequest) -> AsyncIterator[AsyncAgentex]: else: raise TypeError(f"Unexpected fixture parameter type {type(param)}, expected bool or dict") - async with AsyncAgentex(base_url=base_url, _strict_response_validation=strict, http_client=http_client) as client: + async with AsyncAgentex( + base_url=base_url, api_key=api_key, _strict_response_validation=strict, http_client=http_client + ) as client: yield client diff --git a/tests/test_client.py b/tests/test_client.py index 2fe22ed9..da5399da 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -37,6 +37,7 @@ from .utils import update_env base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") +api_key = "My API Key" def _get_params(client: BaseClient[Any, Any]) -> dict[str, str]: @@ -58,7 +59,7 @@ def _get_open_connections(client: Agentex | AsyncAgentex) -> int: class TestAgentex: - client = Agentex(base_url=base_url, _strict_response_validation=True) + client = Agentex(base_url=base_url, api_key=api_key, _strict_response_validation=True) @pytest.mark.respx(base_url=base_url) def test_raw_response(self, respx_mock: MockRouter) -> None: @@ -84,6 +85,10 @@ def test_copy(self) -> None: copied = self.client.copy() assert id(copied) != id(self.client) + copied = self.client.copy(api_key="another My API Key") + assert copied.api_key == "another My API Key" + assert self.client.api_key == "My API Key" + def test_copy_default_options(self) -> None: # options that have a default are overridden correctly copied = self.client.copy(max_retries=7) @@ -101,7 +106,9 @@ def test_copy_default_options(self) -> None: assert isinstance(self.client.timeout, httpx.Timeout) def test_copy_default_headers(self) -> None: - client = Agentex(base_url=base_url, _strict_response_validation=True, default_headers={"X-Foo": "bar"}) + client = Agentex( + base_url=base_url, api_key=api_key, _strict_response_validation=True, default_headers={"X-Foo": "bar"} + ) assert client.default_headers["X-Foo"] == "bar" # does not override the already given value when not specified @@ -133,7 +140,9 @@ def test_copy_default_headers(self) -> None: client.copy(set_default_headers={}, default_headers={"X-Foo": "Bar"}) def test_copy_default_query(self) -> None: - client = Agentex(base_url=base_url, _strict_response_validation=True, default_query={"foo": "bar"}) + client = Agentex( + base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={"foo": "bar"} + ) assert _get_params(client)["foo"] == "bar" # does not override the already given value when not specified @@ -257,7 +266,7 @@ def test_request_timeout(self) -> None: assert timeout == httpx.Timeout(100.0) def test_client_timeout_option(self) -> None: - client = Agentex(base_url=base_url, _strict_response_validation=True, timeout=httpx.Timeout(0)) + client = Agentex(base_url=base_url, api_key=api_key, _strict_response_validation=True, timeout=httpx.Timeout(0)) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore @@ -266,7 +275,9 @@ def test_client_timeout_option(self) -> None: def test_http_client_timeout_option(self) -> None: # custom timeout given to the httpx client should be used with httpx.Client(timeout=None) as http_client: - client = Agentex(base_url=base_url, _strict_response_validation=True, http_client=http_client) + client = Agentex( + base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client + ) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore @@ -274,7 +285,9 @@ def test_http_client_timeout_option(self) -> None: # no timeout given to the httpx client should not use the httpx default with httpx.Client() as http_client: - client = Agentex(base_url=base_url, _strict_response_validation=True, http_client=http_client) + client = Agentex( + base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client + ) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore @@ -282,7 +295,9 @@ def test_http_client_timeout_option(self) -> None: # explicitly passing the default timeout currently results in it being ignored with httpx.Client(timeout=HTTPX_DEFAULT_TIMEOUT) as http_client: - client = Agentex(base_url=base_url, _strict_response_validation=True, http_client=http_client) + client = Agentex( + base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client + ) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore @@ -291,16 +306,24 @@ def test_http_client_timeout_option(self) -> None: async def test_invalid_http_client(self) -> None: with pytest.raises(TypeError, match="Invalid `http_client` arg"): async with httpx.AsyncClient() as http_client: - Agentex(base_url=base_url, _strict_response_validation=True, http_client=cast(Any, http_client)) + Agentex( + base_url=base_url, + api_key=api_key, + _strict_response_validation=True, + http_client=cast(Any, http_client), + ) def test_default_headers_option(self) -> None: - client = Agentex(base_url=base_url, _strict_response_validation=True, default_headers={"X-Foo": "bar"}) + client = Agentex( + base_url=base_url, api_key=api_key, _strict_response_validation=True, default_headers={"X-Foo": "bar"} + ) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) assert request.headers.get("x-foo") == "bar" assert request.headers.get("x-stainless-lang") == "python" client2 = Agentex( base_url=base_url, + api_key=api_key, _strict_response_validation=True, default_headers={ "X-Foo": "stainless", @@ -311,8 +334,20 @@ def test_default_headers_option(self) -> None: assert request.headers.get("x-foo") == "stainless" assert request.headers.get("x-stainless-lang") == "my-overriding-header" + def test_validate_headers(self) -> None: + client = Agentex(base_url=base_url, api_key=api_key, _strict_response_validation=True) + request = client._build_request(FinalRequestOptions(method="get", url="/foo")) + assert request.headers.get("Authorization") == f"Bearer {api_key}" + + with update_env(**{"AGENTEX_SDK_API_KEY": Omit()}): + client2 = Agentex(base_url=base_url, api_key=None, _strict_response_validation=True) + + client2._build_request(FinalRequestOptions(method="get", url="/foo")) + def test_default_query_option(self) -> None: - client = Agentex(base_url=base_url, _strict_response_validation=True, default_query={"query_param": "bar"}) + client = Agentex( + base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={"query_param": "bar"} + ) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) url = httpx.URL(request.url) assert dict(url.params) == {"query_param": "bar"} @@ -511,7 +546,7 @@ class Model(BaseModel): assert response.foo == 2 def test_base_url_setter(self) -> None: - client = Agentex(base_url="https://example.com/from_init", _strict_response_validation=True) + client = Agentex(base_url="https://example.com/from_init", api_key=api_key, _strict_response_validation=True) assert client.base_url == "https://example.com/from_init/" client.base_url = "https://example.com/from_setter" # type: ignore[assignment] @@ -520,23 +555,24 @@ def test_base_url_setter(self) -> None: def test_base_url_env(self) -> None: with update_env(AGENTEX_BASE_URL="http://localhost:5000/from/env"): - client = Agentex(_strict_response_validation=True) + client = Agentex(api_key=api_key, _strict_response_validation=True) assert client.base_url == "http://localhost:5000/from/env/" # explicit environment arg requires explicitness with update_env(AGENTEX_BASE_URL="http://localhost:5000/from/env"): with pytest.raises(ValueError, match=r"you must pass base_url=None"): - Agentex(_strict_response_validation=True, environment="production") + Agentex(api_key=api_key, _strict_response_validation=True, environment="production") - client = Agentex(base_url=None, _strict_response_validation=True, environment="production") + client = Agentex(base_url=None, api_key=api_key, _strict_response_validation=True, environment="production") assert str(client.base_url).startswith("http://localhost:5003") @pytest.mark.parametrize( "client", [ - Agentex(base_url="http://localhost:5000/custom/path/", _strict_response_validation=True), + Agentex(base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True), Agentex( base_url="http://localhost:5000/custom/path/", + api_key=api_key, _strict_response_validation=True, http_client=httpx.Client(), ), @@ -556,9 +592,10 @@ def test_base_url_trailing_slash(self, client: Agentex) -> None: @pytest.mark.parametrize( "client", [ - Agentex(base_url="http://localhost:5000/custom/path/", _strict_response_validation=True), + Agentex(base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True), Agentex( base_url="http://localhost:5000/custom/path/", + api_key=api_key, _strict_response_validation=True, http_client=httpx.Client(), ), @@ -578,9 +615,10 @@ def test_base_url_no_trailing_slash(self, client: Agentex) -> None: @pytest.mark.parametrize( "client", [ - Agentex(base_url="http://localhost:5000/custom/path/", _strict_response_validation=True), + Agentex(base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True), Agentex( base_url="http://localhost:5000/custom/path/", + api_key=api_key, _strict_response_validation=True, http_client=httpx.Client(), ), @@ -598,7 +636,7 @@ def test_absolute_request_url(self, client: Agentex) -> None: assert request.url == "https://myapi.com/foo" def test_copied_client_does_not_close_http(self) -> None: - client = Agentex(base_url=base_url, _strict_response_validation=True) + client = Agentex(base_url=base_url, api_key=api_key, _strict_response_validation=True) assert not client.is_closed() copied = client.copy() @@ -609,7 +647,7 @@ def test_copied_client_does_not_close_http(self) -> None: assert not client.is_closed() def test_client_context_manager(self) -> None: - client = Agentex(base_url=base_url, _strict_response_validation=True) + client = Agentex(base_url=base_url, api_key=api_key, _strict_response_validation=True) with client as c2: assert c2 is client assert not c2.is_closed() @@ -630,7 +668,7 @@ class Model(BaseModel): def test_client_max_retries_validation(self) -> None: with pytest.raises(TypeError, match=r"max_retries cannot be None"): - Agentex(base_url=base_url, _strict_response_validation=True, max_retries=cast(Any, None)) + Agentex(base_url=base_url, api_key=api_key, _strict_response_validation=True, max_retries=cast(Any, None)) @pytest.mark.respx(base_url=base_url) def test_received_text_for_expected_json(self, respx_mock: MockRouter) -> None: @@ -639,12 +677,12 @@ class Model(BaseModel): respx_mock.get("/foo").mock(return_value=httpx.Response(200, text="my-custom-format")) - strict_client = Agentex(base_url=base_url, _strict_response_validation=True) + strict_client = Agentex(base_url=base_url, api_key=api_key, _strict_response_validation=True) with pytest.raises(APIResponseValidationError): strict_client.get("/foo", cast_to=Model) - client = Agentex(base_url=base_url, _strict_response_validation=False) + client = Agentex(base_url=base_url, api_key=api_key, _strict_response_validation=False) response = client.get("/foo", cast_to=Model) assert isinstance(response, str) # type: ignore[unreachable] @@ -672,7 +710,7 @@ class Model(BaseModel): ) @mock.patch("time.time", mock.MagicMock(return_value=1696004797)) def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str, timeout: float) -> None: - client = Agentex(base_url=base_url, _strict_response_validation=True) + client = Agentex(base_url=base_url, api_key=api_key, _strict_response_validation=True) headers = httpx.Headers({"retry-after": retry_after}) options = FinalRequestOptions(method="get", url="/foo", max_retries=3) @@ -682,20 +720,20 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str @mock.patch("agentex._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) @pytest.mark.respx(base_url=base_url) def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter, client: Agentex) -> None: - respx_mock.get("/agents/agent_id").mock(side_effect=httpx.TimeoutException("Test timeout error")) + respx_mock.get("/tasks").mock(side_effect=httpx.TimeoutException("Test timeout error")) with pytest.raises(APITimeoutError): - client.agents.with_streaming_response.retrieve("agent_id").__enter__() + client.tasks.with_streaming_response.list().__enter__() assert _get_open_connections(self.client) == 0 @mock.patch("agentex._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) @pytest.mark.respx(base_url=base_url) def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, client: Agentex) -> None: - respx_mock.get("/agents/agent_id").mock(return_value=httpx.Response(500)) + respx_mock.get("/tasks").mock(return_value=httpx.Response(500)) with pytest.raises(APIStatusError): - client.agents.with_streaming_response.retrieve("agent_id").__enter__() + client.tasks.with_streaming_response.list().__enter__() assert _get_open_connections(self.client) == 0 @pytest.mark.parametrize("failures_before_success", [0, 2, 4]) @@ -722,9 +760,9 @@ def retry_handler(_request: httpx.Request) -> httpx.Response: return httpx.Response(500) return httpx.Response(200) - respx_mock.get("/agents/agent_id").mock(side_effect=retry_handler) + respx_mock.get("/tasks").mock(side_effect=retry_handler) - response = client.agents.with_raw_response.retrieve("agent_id") + response = client.tasks.with_raw_response.list() assert response.retries_taken == failures_before_success assert int(response.http_request.headers.get("x-stainless-retry-count")) == failures_before_success @@ -746,11 +784,9 @@ def retry_handler(_request: httpx.Request) -> httpx.Response: return httpx.Response(500) return httpx.Response(200) - respx_mock.get("/agents/agent_id").mock(side_effect=retry_handler) + respx_mock.get("/tasks").mock(side_effect=retry_handler) - response = client.agents.with_raw_response.retrieve( - "agent_id", extra_headers={"x-stainless-retry-count": Omit()} - ) + response = client.tasks.with_raw_response.list(extra_headers={"x-stainless-retry-count": Omit()}) assert len(response.http_request.headers.get_list("x-stainless-retry-count")) == 0 @@ -771,9 +807,9 @@ def retry_handler(_request: httpx.Request) -> httpx.Response: return httpx.Response(500) return httpx.Response(200) - respx_mock.get("/agents/agent_id").mock(side_effect=retry_handler) + respx_mock.get("/tasks").mock(side_effect=retry_handler) - response = client.agents.with_raw_response.retrieve("agent_id", extra_headers={"x-stainless-retry-count": "42"}) + response = client.tasks.with_raw_response.list(extra_headers={"x-stainless-retry-count": "42"}) assert response.http_request.headers.get("x-stainless-retry-count") == "42" @@ -828,7 +864,7 @@ def test_follow_redirects_disabled(self, respx_mock: MockRouter) -> None: class TestAsyncAgentex: - client = AsyncAgentex(base_url=base_url, _strict_response_validation=True) + client = AsyncAgentex(base_url=base_url, api_key=api_key, _strict_response_validation=True) @pytest.mark.respx(base_url=base_url) @pytest.mark.asyncio @@ -856,6 +892,10 @@ def test_copy(self) -> None: copied = self.client.copy() assert id(copied) != id(self.client) + copied = self.client.copy(api_key="another My API Key") + assert copied.api_key == "another My API Key" + assert self.client.api_key == "My API Key" + def test_copy_default_options(self) -> None: # options that have a default are overridden correctly copied = self.client.copy(max_retries=7) @@ -873,7 +913,9 @@ def test_copy_default_options(self) -> None: assert isinstance(self.client.timeout, httpx.Timeout) def test_copy_default_headers(self) -> None: - client = AsyncAgentex(base_url=base_url, _strict_response_validation=True, default_headers={"X-Foo": "bar"}) + client = AsyncAgentex( + base_url=base_url, api_key=api_key, _strict_response_validation=True, default_headers={"X-Foo": "bar"} + ) assert client.default_headers["X-Foo"] == "bar" # does not override the already given value when not specified @@ -905,7 +947,9 @@ def test_copy_default_headers(self) -> None: client.copy(set_default_headers={}, default_headers={"X-Foo": "Bar"}) def test_copy_default_query(self) -> None: - client = AsyncAgentex(base_url=base_url, _strict_response_validation=True, default_query={"foo": "bar"}) + client = AsyncAgentex( + base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={"foo": "bar"} + ) assert _get_params(client)["foo"] == "bar" # does not override the already given value when not specified @@ -1029,7 +1073,9 @@ async def test_request_timeout(self) -> None: assert timeout == httpx.Timeout(100.0) async def test_client_timeout_option(self) -> None: - client = AsyncAgentex(base_url=base_url, _strict_response_validation=True, timeout=httpx.Timeout(0)) + client = AsyncAgentex( + base_url=base_url, api_key=api_key, _strict_response_validation=True, timeout=httpx.Timeout(0) + ) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore @@ -1038,7 +1084,9 @@ async def test_client_timeout_option(self) -> None: async def test_http_client_timeout_option(self) -> None: # custom timeout given to the httpx client should be used async with httpx.AsyncClient(timeout=None) as http_client: - client = AsyncAgentex(base_url=base_url, _strict_response_validation=True, http_client=http_client) + client = AsyncAgentex( + base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client + ) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore @@ -1046,7 +1094,9 @@ async def test_http_client_timeout_option(self) -> None: # no timeout given to the httpx client should not use the httpx default async with httpx.AsyncClient() as http_client: - client = AsyncAgentex(base_url=base_url, _strict_response_validation=True, http_client=http_client) + client = AsyncAgentex( + base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client + ) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore @@ -1054,7 +1104,9 @@ async def test_http_client_timeout_option(self) -> None: # explicitly passing the default timeout currently results in it being ignored async with httpx.AsyncClient(timeout=HTTPX_DEFAULT_TIMEOUT) as http_client: - client = AsyncAgentex(base_url=base_url, _strict_response_validation=True, http_client=http_client) + client = AsyncAgentex( + base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client + ) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore @@ -1063,16 +1115,24 @@ async def test_http_client_timeout_option(self) -> None: def test_invalid_http_client(self) -> None: with pytest.raises(TypeError, match="Invalid `http_client` arg"): with httpx.Client() as http_client: - AsyncAgentex(base_url=base_url, _strict_response_validation=True, http_client=cast(Any, http_client)) + AsyncAgentex( + base_url=base_url, + api_key=api_key, + _strict_response_validation=True, + http_client=cast(Any, http_client), + ) def test_default_headers_option(self) -> None: - client = AsyncAgentex(base_url=base_url, _strict_response_validation=True, default_headers={"X-Foo": "bar"}) + client = AsyncAgentex( + base_url=base_url, api_key=api_key, _strict_response_validation=True, default_headers={"X-Foo": "bar"} + ) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) assert request.headers.get("x-foo") == "bar" assert request.headers.get("x-stainless-lang") == "python" client2 = AsyncAgentex( base_url=base_url, + api_key=api_key, _strict_response_validation=True, default_headers={ "X-Foo": "stainless", @@ -1083,8 +1143,20 @@ def test_default_headers_option(self) -> None: assert request.headers.get("x-foo") == "stainless" assert request.headers.get("x-stainless-lang") == "my-overriding-header" + def test_validate_headers(self) -> None: + client = AsyncAgentex(base_url=base_url, api_key=api_key, _strict_response_validation=True) + request = client._build_request(FinalRequestOptions(method="get", url="/foo")) + assert request.headers.get("Authorization") == f"Bearer {api_key}" + + with update_env(**{"AGENTEX_SDK_API_KEY": Omit()}): + client2 = AsyncAgentex(base_url=base_url, api_key=None, _strict_response_validation=True) + + client2._build_request(FinalRequestOptions(method="get", url="/foo")) + def test_default_query_option(self) -> None: - client = AsyncAgentex(base_url=base_url, _strict_response_validation=True, default_query={"query_param": "bar"}) + client = AsyncAgentex( + base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={"query_param": "bar"} + ) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) url = httpx.URL(request.url) assert dict(url.params) == {"query_param": "bar"} @@ -1283,7 +1355,9 @@ class Model(BaseModel): assert response.foo == 2 def test_base_url_setter(self) -> None: - client = AsyncAgentex(base_url="https://example.com/from_init", _strict_response_validation=True) + client = AsyncAgentex( + base_url="https://example.com/from_init", api_key=api_key, _strict_response_validation=True + ) assert client.base_url == "https://example.com/from_init/" client.base_url = "https://example.com/from_setter" # type: ignore[assignment] @@ -1292,23 +1366,28 @@ def test_base_url_setter(self) -> None: def test_base_url_env(self) -> None: with update_env(AGENTEX_BASE_URL="http://localhost:5000/from/env"): - client = AsyncAgentex(_strict_response_validation=True) + client = AsyncAgentex(api_key=api_key, _strict_response_validation=True) assert client.base_url == "http://localhost:5000/from/env/" # explicit environment arg requires explicitness with update_env(AGENTEX_BASE_URL="http://localhost:5000/from/env"): with pytest.raises(ValueError, match=r"you must pass base_url=None"): - AsyncAgentex(_strict_response_validation=True, environment="production") + AsyncAgentex(api_key=api_key, _strict_response_validation=True, environment="production") - client = AsyncAgentex(base_url=None, _strict_response_validation=True, environment="production") + client = AsyncAgentex( + base_url=None, api_key=api_key, _strict_response_validation=True, environment="production" + ) assert str(client.base_url).startswith("http://localhost:5003") @pytest.mark.parametrize( "client", [ - AsyncAgentex(base_url="http://localhost:5000/custom/path/", _strict_response_validation=True), + AsyncAgentex( + base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True + ), AsyncAgentex( base_url="http://localhost:5000/custom/path/", + api_key=api_key, _strict_response_validation=True, http_client=httpx.AsyncClient(), ), @@ -1328,9 +1407,12 @@ def test_base_url_trailing_slash(self, client: AsyncAgentex) -> None: @pytest.mark.parametrize( "client", [ - AsyncAgentex(base_url="http://localhost:5000/custom/path/", _strict_response_validation=True), + AsyncAgentex( + base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True + ), AsyncAgentex( base_url="http://localhost:5000/custom/path/", + api_key=api_key, _strict_response_validation=True, http_client=httpx.AsyncClient(), ), @@ -1350,9 +1432,12 @@ def test_base_url_no_trailing_slash(self, client: AsyncAgentex) -> None: @pytest.mark.parametrize( "client", [ - AsyncAgentex(base_url="http://localhost:5000/custom/path/", _strict_response_validation=True), + AsyncAgentex( + base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True + ), AsyncAgentex( base_url="http://localhost:5000/custom/path/", + api_key=api_key, _strict_response_validation=True, http_client=httpx.AsyncClient(), ), @@ -1370,7 +1455,7 @@ def test_absolute_request_url(self, client: AsyncAgentex) -> None: assert request.url == "https://myapi.com/foo" async def test_copied_client_does_not_close_http(self) -> None: - client = AsyncAgentex(base_url=base_url, _strict_response_validation=True) + client = AsyncAgentex(base_url=base_url, api_key=api_key, _strict_response_validation=True) assert not client.is_closed() copied = client.copy() @@ -1382,7 +1467,7 @@ async def test_copied_client_does_not_close_http(self) -> None: assert not client.is_closed() async def test_client_context_manager(self) -> None: - client = AsyncAgentex(base_url=base_url, _strict_response_validation=True) + client = AsyncAgentex(base_url=base_url, api_key=api_key, _strict_response_validation=True) async with client as c2: assert c2 is client assert not c2.is_closed() @@ -1404,7 +1489,9 @@ class Model(BaseModel): async def test_client_max_retries_validation(self) -> None: with pytest.raises(TypeError, match=r"max_retries cannot be None"): - AsyncAgentex(base_url=base_url, _strict_response_validation=True, max_retries=cast(Any, None)) + AsyncAgentex( + base_url=base_url, api_key=api_key, _strict_response_validation=True, max_retries=cast(Any, None) + ) @pytest.mark.respx(base_url=base_url) @pytest.mark.asyncio @@ -1414,12 +1501,12 @@ class Model(BaseModel): respx_mock.get("/foo").mock(return_value=httpx.Response(200, text="my-custom-format")) - strict_client = AsyncAgentex(base_url=base_url, _strict_response_validation=True) + strict_client = AsyncAgentex(base_url=base_url, api_key=api_key, _strict_response_validation=True) with pytest.raises(APIResponseValidationError): await strict_client.get("/foo", cast_to=Model) - client = AsyncAgentex(base_url=base_url, _strict_response_validation=False) + client = AsyncAgentex(base_url=base_url, api_key=api_key, _strict_response_validation=False) response = await client.get("/foo", cast_to=Model) assert isinstance(response, str) # type: ignore[unreachable] @@ -1448,7 +1535,7 @@ class Model(BaseModel): @mock.patch("time.time", mock.MagicMock(return_value=1696004797)) @pytest.mark.asyncio async def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str, timeout: float) -> None: - client = AsyncAgentex(base_url=base_url, _strict_response_validation=True) + client = AsyncAgentex(base_url=base_url, api_key=api_key, _strict_response_validation=True) headers = httpx.Headers({"retry-after": retry_after}) options = FinalRequestOptions(method="get", url="/foo", max_retries=3) @@ -1460,20 +1547,20 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte async def test_retrying_timeout_errors_doesnt_leak( self, respx_mock: MockRouter, async_client: AsyncAgentex ) -> None: - respx_mock.get("/agents/agent_id").mock(side_effect=httpx.TimeoutException("Test timeout error")) + respx_mock.get("/tasks").mock(side_effect=httpx.TimeoutException("Test timeout error")) with pytest.raises(APITimeoutError): - await async_client.agents.with_streaming_response.retrieve("agent_id").__aenter__() + await async_client.tasks.with_streaming_response.list().__aenter__() assert _get_open_connections(self.client) == 0 @mock.patch("agentex._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) @pytest.mark.respx(base_url=base_url) async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, async_client: AsyncAgentex) -> None: - respx_mock.get("/agents/agent_id").mock(return_value=httpx.Response(500)) + respx_mock.get("/tasks").mock(return_value=httpx.Response(500)) with pytest.raises(APIStatusError): - await async_client.agents.with_streaming_response.retrieve("agent_id").__aenter__() + await async_client.tasks.with_streaming_response.list().__aenter__() assert _get_open_connections(self.client) == 0 @pytest.mark.parametrize("failures_before_success", [0, 2, 4]) @@ -1501,9 +1588,9 @@ def retry_handler(_request: httpx.Request) -> httpx.Response: return httpx.Response(500) return httpx.Response(200) - respx_mock.get("/agents/agent_id").mock(side_effect=retry_handler) + respx_mock.get("/tasks").mock(side_effect=retry_handler) - response = await client.agents.with_raw_response.retrieve("agent_id") + response = await client.tasks.with_raw_response.list() assert response.retries_taken == failures_before_success assert int(response.http_request.headers.get("x-stainless-retry-count")) == failures_before_success @@ -1526,11 +1613,9 @@ def retry_handler(_request: httpx.Request) -> httpx.Response: return httpx.Response(500) return httpx.Response(200) - respx_mock.get("/agents/agent_id").mock(side_effect=retry_handler) + respx_mock.get("/tasks").mock(side_effect=retry_handler) - response = await client.agents.with_raw_response.retrieve( - "agent_id", extra_headers={"x-stainless-retry-count": Omit()} - ) + response = await client.tasks.with_raw_response.list(extra_headers={"x-stainless-retry-count": Omit()}) assert len(response.http_request.headers.get_list("x-stainless-retry-count")) == 0 @@ -1552,11 +1637,9 @@ def retry_handler(_request: httpx.Request) -> httpx.Response: return httpx.Response(500) return httpx.Response(200) - respx_mock.get("/agents/agent_id").mock(side_effect=retry_handler) + respx_mock.get("/tasks").mock(side_effect=retry_handler) - response = await client.agents.with_raw_response.retrieve( - "agent_id", extra_headers={"x-stainless-retry-count": "42"} - ) + response = await client.tasks.with_raw_response.list(extra_headers={"x-stainless-retry-count": "42"}) assert response.http_request.headers.get("x-stainless-retry-count") == "42" From a330fff2e7deaf4dde728e38d1d847110c482d7f Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 22 Jul 2025 16:00:34 +0000 Subject: [PATCH 3/3] release: 0.1.0-alpha.5 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 9 +++++++++ pyproject.toml | 2 +- src/agentex/_version.py | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index b56c3d0b..e8285b71 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.1.0-alpha.4" + ".": "0.1.0-alpha.5" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f014202..a1a74244 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 0.1.0-alpha.5 (2025-07-22) + +Full Changelog: [v0.1.0-alpha.4...v0.1.0-alpha.5](https://github.com/scaleapi/agentex-python/compare/v0.1.0-alpha.4...v0.1.0-alpha.5) + +### Bug Fixes + +* **api:** build errors ([7bde6b7](https://github.com/scaleapi/agentex-python/commit/7bde6b727d6d16ebd6805ef843596fc3224445a6)) +* **parsing:** parse extra field types ([d40e6e0](https://github.com/scaleapi/agentex-python/commit/d40e6e0d6911be0bc9bfc419e02bd7c1d5ad5be4)) + ## 0.1.0-alpha.4 (2025-07-22) Full Changelog: [v0.1.0-alpha.3...v0.1.0-alpha.4](https://github.com/scaleapi/agentex-python/compare/v0.1.0-alpha.3...v0.1.0-alpha.4) diff --git a/pyproject.toml b/pyproject.toml index 8e69b5ed..168acc46 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "agentex" -version = "0.1.0-alpha.4" +version = "0.1.0-alpha.5" description = "The official Python library for the agentex API" dynamic = ["readme"] license = "Apache-2.0" diff --git a/src/agentex/_version.py b/src/agentex/_version.py index 756d68b8..6c4f3e31 100644 --- a/src/agentex/_version.py +++ b/src/agentex/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. __title__ = "agentex" -__version__ = "0.1.0-alpha.4" # x-release-please-version +__version__ = "0.1.0-alpha.5" # x-release-please-version