| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from typing import List |
| 4 |
from itertools import chain |
| 5 |
|
| 6 |
import httpx2 |
| 7 |
|
| 8 |
from ...._types import Body, Omit, Query, Headers, NotGiven, omit, not_given |
| 9 |
from ...._utils import is_given, path_template, strip_not_given |
| 10 |
from ...._compat import cached_property |
| 11 |
from ...._resource import SyncAPIResource, AsyncAPIResource |
| 12 |
from ...._response import ( |
| 13 |
to_raw_response_wrapper, |
| 14 |
to_streamed_response_wrapper, |
| 15 |
async_to_raw_response_wrapper, |
| 16 |
async_to_streamed_response_wrapper, |
| 17 |
) |
| 18 |
from ....pagination import SyncPageCursor, AsyncPageCursor |
| 19 |
from ...._base_client import AsyncPaginator, make_request_options |
| 20 |
from ....types.anthropic_beta_param import AnthropicBetaParam |
| 21 |
from ....types.beta.beta_managed_agents_agent import BetaManagedAgentsAgent |
| 22 |
|
| 23 |
__all__ = ["Versions", "AsyncVersions"] |
| 24 |
|
| 25 |
|
| 26 |
class Versions(SyncAPIResource): |
| 27 |
@cached_property |
| 28 |
def with_raw_response(self) -> VersionsWithRawResponse: |
| 29 |
""" |
| 30 |
This property can be used as a prefix for any HTTP method call to return |
| 31 |
the raw response object instead of the parsed content. |
| 32 |
|
| 33 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers |
| 34 |
""" |
| 35 |
return VersionsWithRawResponse(self) |
| 36 |
|
| 37 |
@cached_property |
| 38 |
def with_streaming_response(self) -> VersionsWithStreamingResponse: |
| 39 |
""" |
| 40 |
An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 41 |
|
| 42 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response |
| 43 |
""" |
| 44 |
return VersionsWithStreamingResponse(self) |
| 45 |
|
| 46 |
def list( |
| 47 |
self, |
| 48 |
agent_id: str, |
| 49 |
*, |
| 50 |
limit: int | Omit = omit, |
| 51 |
page: str | Omit = omit, |
| 52 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 53 |
workspace_id: str | Omit = omit, |
| 54 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 55 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 56 |
extra_headers: Headers | None = None, |
| 57 |
extra_query: Query | None = None, |
| 58 |
extra_body: Body | None = None, |
| 59 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 60 |
) -> SyncPageCursor[BetaManagedAgentsAgent]: |
| 61 |
""" |
| 62 |
List Agent Versions |
| 63 |
|
| 64 |
Args: |
| 65 |
agent_id: Agent ID to list versions for. |
| 66 |
|
| 67 |
limit: Maximum results per page. Default 20, maximum 100. |
| 68 |
|
| 69 |
page: Opaque pagination cursor. |
| 70 |
|
| 71 |
betas: Optional header to specify the beta version(s) you want to use. |
| 72 |
|
| 73 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 74 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 75 |
|
| 76 |
Only needed for credentials that can act on more than one Workspace. A |
| 77 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 78 |
match that Workspace. |
| 79 |
|
| 80 |
extra_headers: Send extra headers |
| 81 |
|
| 82 |
extra_query: Add additional query parameters to the request |
| 83 |
|
| 84 |
extra_body: Add additional JSON properties to the request |
| 85 |
|
| 86 |
timeout: Override the client-level default timeout for this request, in seconds |
| 87 |
""" |
| 88 |
if not agent_id: |
| 89 |
raise ValueError(f"Expected a non-empty value for `agent_id` but received {agent_id!r}") |
| 90 |
extra_headers = { |
| 91 |
**strip_not_given( |
| 92 |
{ |
| 93 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 94 |
if is_given(betas) |
| 95 |
else not_given, |
| 96 |
"anthropic-workspace-id": workspace_id, |
| 97 |
} |
| 98 |
), |
| 99 |
**(extra_headers or {}), |
| 100 |
} |
| 101 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 102 |
return self._get_api_list( |
| 103 |
path_template("/v1/agents/{agent_id}/versions?beta=true", agent_id=agent_id), |
| 104 |
page=SyncPageCursor[BetaManagedAgentsAgent], |
| 105 |
options=make_request_options( |
| 106 |
extra_headers=extra_headers, |
| 107 |
extra_query=extra_query, |
| 108 |
extra_body=extra_body, |
| 109 |
timeout=timeout, |
| 110 |
query={ |
| 111 |
"limit": limit, |
| 112 |
"page": page, |
| 113 |
}, |
| 114 |
), |
| 115 |
model=BetaManagedAgentsAgent, |
| 116 |
) |
| 117 |
|
| 118 |
|
| 119 |
class AsyncVersions(AsyncAPIResource): |
| 120 |
@cached_property |
| 121 |
def with_raw_response(self) -> AsyncVersionsWithRawResponse: |
| 122 |
""" |
| 123 |
This property can be used as a prefix for any HTTP method call to return |
| 124 |
the raw response object instead of the parsed content. |
| 125 |
|
| 126 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers |
| 127 |
""" |
| 128 |
return AsyncVersionsWithRawResponse(self) |
| 129 |
|
| 130 |
@cached_property |
| 131 |
def with_streaming_response(self) -> AsyncVersionsWithStreamingResponse: |
| 132 |
""" |
| 133 |
An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 134 |
|
| 135 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response |
| 136 |
""" |
| 137 |
return AsyncVersionsWithStreamingResponse(self) |
| 138 |
|
| 139 |
def list( |
| 140 |
self, |
| 141 |
agent_id: str, |
| 142 |
*, |
| 143 |
limit: int | Omit = omit, |
| 144 |
page: str | Omit = omit, |
| 145 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 146 |
workspace_id: str | Omit = omit, |
| 147 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 148 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 149 |
extra_headers: Headers | None = None, |
| 150 |
extra_query: Query | None = None, |
| 151 |
extra_body: Body | None = None, |
| 152 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 153 |
) -> AsyncPaginator[BetaManagedAgentsAgent, AsyncPageCursor[BetaManagedAgentsAgent]]: |
| 154 |
""" |
| 155 |
List Agent Versions |
| 156 |
|
| 157 |
Args: |
| 158 |
agent_id: Agent ID to list versions for. |
| 159 |
|
| 160 |
limit: Maximum results per page. Default 20, maximum 100. |
| 161 |
|
| 162 |
page: Opaque pagination cursor. |
| 163 |
|
| 164 |
betas: Optional header to specify the beta version(s) you want to use. |
| 165 |
|
| 166 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 167 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 168 |
|
| 169 |
Only needed for credentials that can act on more than one Workspace. A |
| 170 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 171 |
match that Workspace. |
| 172 |
|
| 173 |
extra_headers: Send extra headers |
| 174 |
|
| 175 |
extra_query: Add additional query parameters to the request |
| 176 |
|
| 177 |
extra_body: Add additional JSON properties to the request |
| 178 |
|
| 179 |
timeout: Override the client-level default timeout for this request, in seconds |
| 180 |
""" |
| 181 |
if not agent_id: |
| 182 |
raise ValueError(f"Expected a non-empty value for `agent_id` but received {agent_id!r}") |
| 183 |
extra_headers = { |
| 184 |
**strip_not_given( |
| 185 |
{ |
| 186 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 187 |
if is_given(betas) |
| 188 |
else not_given, |
| 189 |
"anthropic-workspace-id": workspace_id, |
| 190 |
} |
| 191 |
), |
| 192 |
**(extra_headers or {}), |
| 193 |
} |
| 194 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 195 |
return self._get_api_list( |
| 196 |
path_template("/v1/agents/{agent_id}/versions?beta=true", agent_id=agent_id), |
| 197 |
page=AsyncPageCursor[BetaManagedAgentsAgent], |
| 198 |
options=make_request_options( |
| 199 |
extra_headers=extra_headers, |
| 200 |
extra_query=extra_query, |
| 201 |
extra_body=extra_body, |
| 202 |
timeout=timeout, |
| 203 |
query={ |
| 204 |
"limit": limit, |
| 205 |
"page": page, |
| 206 |
}, |
| 207 |
), |
| 208 |
model=BetaManagedAgentsAgent, |
| 209 |
) |
| 210 |
|
| 211 |
|
| 212 |
class VersionsWithRawResponse: |
| 213 |
def __init__(self, versions: Versions) -> None: |
| 214 |
self._versions = versions |
| 215 |
|
| 216 |
self.list = to_raw_response_wrapper( |
| 217 |
versions.list, |
| 218 |
) |
| 219 |
|
| 220 |
|
| 221 |
class AsyncVersionsWithRawResponse: |
| 222 |
def __init__(self, versions: AsyncVersions) -> None: |
| 223 |
self._versions = versions |
| 224 |
|
| 225 |
self.list = async_to_raw_response_wrapper( |
| 226 |
versions.list, |
| 227 |
) |
| 228 |
|
| 229 |
|
| 230 |
class VersionsWithStreamingResponse: |
| 231 |
def __init__(self, versions: Versions) -> None: |
| 232 |
self._versions = versions |
| 233 |
|
| 234 |
self.list = to_streamed_response_wrapper( |
| 235 |
versions.list, |
| 236 |
) |
| 237 |
|
| 238 |
|
| 239 |
class AsyncVersionsWithStreamingResponse: |
| 240 |
def __init__(self, versions: AsyncVersions) -> None: |
| 241 |
self._versions = versions |
| 242 |
|
| 243 |
self.list = async_to_streamed_response_wrapper( |
| 244 |
versions.list, |
| 245 |
) |