|
| 1 | +# This file is auto-generated by oagen. Do not edit. |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from typing import TYPE_CHECKING, Any, Dict, Literal, Optional, Union |
| 6 | + |
| 7 | +if TYPE_CHECKING: |
| 8 | + from .._client import AsyncWorkOSClient, WorkOSClient |
| 9 | + |
| 10 | +from .._types import RequestOptions, enum_value |
| 11 | +from .models import ( |
| 12 | + AgentAdminLinkClaimAttemptToExternalUserRequestUser, |
| 13 | + AgentCredentialValidation, |
| 14 | + AgentRegistration, |
| 15 | + ClaimViewResponse, |
| 16 | +) |
| 17 | +from workos.common.models.agent_admin_validate_credential_request_type import ( |
| 18 | + AgentAdminValidateCredentialRequestType, |
| 19 | +) |
| 20 | + |
| 21 | + |
| 22 | +class Agents: |
| 23 | + """Agents API resources.""" |
| 24 | + |
| 25 | + def __init__(self, client: "WorkOSClient") -> None: |
| 26 | + self._client = client |
| 27 | + |
| 28 | + def update_attempts( |
| 29 | + self, |
| 30 | + *, |
| 31 | + type: Literal["link_external_user"], |
| 32 | + claim_attempt_token: str, |
| 33 | + user: AgentAdminLinkClaimAttemptToExternalUserRequestUser, |
| 34 | + organization_id: Optional[str] = None, |
| 35 | + request_options: Optional[RequestOptions] = None, |
| 36 | + ) -> ClaimViewResponse: |
| 37 | + """Link a claim attempt to an external user |
| 38 | +
|
| 39 | + Link an external user to a claim attempt and retrieve the code needed for the agent to complete the claim. The user is looked up by external ID; if no user exists, one is created. When the user belongs to multiple organizations, an explicit organization must be provided. |
| 40 | +
|
| 41 | + Args: |
| 42 | + type: The operation to perform on the claim attempt. Currently only `link_external_user` is supported. |
| 43 | + claim_attempt_token: The token identifying the claim attempt. |
| 44 | + user: The user to attach to the claim attempt, identified by email and external ID. |
| 45 | + organization_id: The organization to place the agent in. Required when the user belongs to more than one organization. |
| 46 | + request_options: Per-request options. Supports extra_headers, timeout, max_retries, and base_url override. |
| 47 | +
|
| 48 | + Returns: |
| 49 | + ClaimViewResponse |
| 50 | +
|
| 51 | + Raises: |
| 52 | + BadRequestError: If the request is malformed (400). |
| 53 | + AuthorizationError: If the request is forbidden (403). |
| 54 | + ConflictError: If a conflict occurs (409). |
| 55 | + AuthenticationError: If the API key is invalid (401). |
| 56 | + RateLimitExceededError: If rate limited (429). |
| 57 | + ServerError: If the server returns a 5xx error. |
| 58 | + """ |
| 59 | + body: Dict[str, Any] = { |
| 60 | + k: v |
| 61 | + for k, v in { |
| 62 | + "type": type, |
| 63 | + "claim_attempt_token": claim_attempt_token, |
| 64 | + "user": user.to_dict(), |
| 65 | + "organization_id": organization_id, |
| 66 | + }.items() |
| 67 | + if v is not None |
| 68 | + } |
| 69 | + return self._client.request( |
| 70 | + method="patch", |
| 71 | + path=("agents", "claims", "attempts"), |
| 72 | + body=body, |
| 73 | + model=ClaimViewResponse, |
| 74 | + request_options=request_options, |
| 75 | + ) |
| 76 | + |
| 77 | + def create_validate( |
| 78 | + self, |
| 79 | + *, |
| 80 | + type: Union[AgentAdminValidateCredentialRequestType, str], |
| 81 | + credential: str, |
| 82 | + audience: Optional[str] = None, |
| 83 | + request_options: Optional[RequestOptions] = None, |
| 84 | + ) -> AgentCredentialValidation: |
| 85 | + """Validate an agent credential |
| 86 | +
|
| 87 | + Validate an agent credential — an API key or access token — against the environment of the API key used to authenticate the request. This is a read-only check: it never consumes or mutates the credential. |
| 88 | +
|
| 89 | + Args: |
| 90 | + type: The kind of credential being validated — an agent API key or an agent access token. |
| 91 | + credential: The credential value to validate: the API key value for `api_key`, or the access token (JWT) for `access_token`. |
| 92 | + audience: When provided, the access token's `aud` claim is verified against this value. Tokens issued for a different resource are rejected. |
| 93 | + request_options: Per-request options. Supports extra_headers, timeout, max_retries, and base_url override. |
| 94 | +
|
| 95 | + Returns: |
| 96 | + AgentCredentialValidation |
| 97 | +
|
| 98 | + Raises: |
| 99 | + BadRequestError: If the request is malformed (400). |
| 100 | + AuthenticationError: If the API key is invalid (401). |
| 101 | + RateLimitExceededError: If rate limited (429). |
| 102 | + ServerError: If the server returns a 5xx error. |
| 103 | + """ |
| 104 | + body: Dict[str, Any] = { |
| 105 | + k: v |
| 106 | + for k, v in { |
| 107 | + "type": enum_value(type), |
| 108 | + "credential": credential, |
| 109 | + "audience": audience, |
| 110 | + }.items() |
| 111 | + if v is not None |
| 112 | + } |
| 113 | + return self._client.request( |
| 114 | + method="post", |
| 115 | + path=("agents", "credentials", "validate"), |
| 116 | + body=body, |
| 117 | + model=AgentCredentialValidation, |
| 118 | + request_options=request_options, |
| 119 | + ) |
| 120 | + |
| 121 | + def get_registration( |
| 122 | + self, |
| 123 | + id: str, |
| 124 | + *, |
| 125 | + request_options: Optional[RequestOptions] = None, |
| 126 | + ) -> AgentRegistration: |
| 127 | + """Get an agent registration |
| 128 | +
|
| 129 | + Retrieve the details of an agent registration by ID. The registration is scoped to the environment of the API key used to authenticate the request. |
| 130 | +
|
| 131 | + Args: |
| 132 | + id: The unique ID of the agent registration. |
| 133 | + request_options: Per-request options. Supports extra_headers, timeout, max_retries, and base_url override. |
| 134 | +
|
| 135 | + Returns: |
| 136 | + AgentRegistration |
| 137 | +
|
| 138 | + Raises: |
| 139 | + NotFoundError: If the resource is not found (404). |
| 140 | + AuthenticationError: If the API key is invalid (401). |
| 141 | + RateLimitExceededError: If rate limited (429). |
| 142 | + ServerError: If the server returns a 5xx error. |
| 143 | + """ |
| 144 | + return self._client.request( |
| 145 | + method="get", |
| 146 | + path=("agents", "registrations", str(id)), |
| 147 | + model=AgentRegistration, |
| 148 | + request_options=request_options, |
| 149 | + ) |
| 150 | + |
| 151 | + |
| 152 | +class AsyncAgents: |
| 153 | + """Agents API resources (async).""" |
| 154 | + |
| 155 | + def __init__(self, client: "AsyncWorkOSClient") -> None: |
| 156 | + self._client = client |
| 157 | + |
| 158 | + async def update_attempts( |
| 159 | + self, |
| 160 | + *, |
| 161 | + type: Literal["link_external_user"], |
| 162 | + claim_attempt_token: str, |
| 163 | + user: AgentAdminLinkClaimAttemptToExternalUserRequestUser, |
| 164 | + organization_id: Optional[str] = None, |
| 165 | + request_options: Optional[RequestOptions] = None, |
| 166 | + ) -> ClaimViewResponse: |
| 167 | + """Link a claim attempt to an external user |
| 168 | +
|
| 169 | + Link an external user to a claim attempt and retrieve the code needed for the agent to complete the claim. The user is looked up by external ID; if no user exists, one is created. When the user belongs to multiple organizations, an explicit organization must be provided. |
| 170 | +
|
| 171 | + Args: |
| 172 | + type: The operation to perform on the claim attempt. Currently only `link_external_user` is supported. |
| 173 | + claim_attempt_token: The token identifying the claim attempt. |
| 174 | + user: The user to attach to the claim attempt, identified by email and external ID. |
| 175 | + organization_id: The organization to place the agent in. Required when the user belongs to more than one organization. |
| 176 | + request_options: Per-request options. Supports extra_headers, timeout, max_retries, and base_url override. |
| 177 | +
|
| 178 | + Returns: |
| 179 | + ClaimViewResponse |
| 180 | +
|
| 181 | + Raises: |
| 182 | + BadRequestError: If the request is malformed (400). |
| 183 | + AuthorizationError: If the request is forbidden (403). |
| 184 | + ConflictError: If a conflict occurs (409). |
| 185 | + AuthenticationError: If the API key is invalid (401). |
| 186 | + RateLimitExceededError: If rate limited (429). |
| 187 | + ServerError: If the server returns a 5xx error. |
| 188 | + """ |
| 189 | + body: Dict[str, Any] = { |
| 190 | + k: v |
| 191 | + for k, v in { |
| 192 | + "type": type, |
| 193 | + "claim_attempt_token": claim_attempt_token, |
| 194 | + "user": user.to_dict(), |
| 195 | + "organization_id": organization_id, |
| 196 | + }.items() |
| 197 | + if v is not None |
| 198 | + } |
| 199 | + return await self._client.request( |
| 200 | + method="patch", |
| 201 | + path=("agents", "claims", "attempts"), |
| 202 | + body=body, |
| 203 | + model=ClaimViewResponse, |
| 204 | + request_options=request_options, |
| 205 | + ) |
| 206 | + |
| 207 | + async def create_validate( |
| 208 | + self, |
| 209 | + *, |
| 210 | + type: Union[AgentAdminValidateCredentialRequestType, str], |
| 211 | + credential: str, |
| 212 | + audience: Optional[str] = None, |
| 213 | + request_options: Optional[RequestOptions] = None, |
| 214 | + ) -> AgentCredentialValidation: |
| 215 | + """Validate an agent credential |
| 216 | +
|
| 217 | + Validate an agent credential — an API key or access token — against the environment of the API key used to authenticate the request. This is a read-only check: it never consumes or mutates the credential. |
| 218 | +
|
| 219 | + Args: |
| 220 | + type: The kind of credential being validated — an agent API key or an agent access token. |
| 221 | + credential: The credential value to validate: the API key value for `api_key`, or the access token (JWT) for `access_token`. |
| 222 | + audience: When provided, the access token's `aud` claim is verified against this value. Tokens issued for a different resource are rejected. |
| 223 | + request_options: Per-request options. Supports extra_headers, timeout, max_retries, and base_url override. |
| 224 | +
|
| 225 | + Returns: |
| 226 | + AgentCredentialValidation |
| 227 | +
|
| 228 | + Raises: |
| 229 | + BadRequestError: If the request is malformed (400). |
| 230 | + AuthenticationError: If the API key is invalid (401). |
| 231 | + RateLimitExceededError: If rate limited (429). |
| 232 | + ServerError: If the server returns a 5xx error. |
| 233 | + """ |
| 234 | + body: Dict[str, Any] = { |
| 235 | + k: v |
| 236 | + for k, v in { |
| 237 | + "type": enum_value(type), |
| 238 | + "credential": credential, |
| 239 | + "audience": audience, |
| 240 | + }.items() |
| 241 | + if v is not None |
| 242 | + } |
| 243 | + return await self._client.request( |
| 244 | + method="post", |
| 245 | + path=("agents", "credentials", "validate"), |
| 246 | + body=body, |
| 247 | + model=AgentCredentialValidation, |
| 248 | + request_options=request_options, |
| 249 | + ) |
| 250 | + |
| 251 | + async def get_registration( |
| 252 | + self, |
| 253 | + id: str, |
| 254 | + *, |
| 255 | + request_options: Optional[RequestOptions] = None, |
| 256 | + ) -> AgentRegistration: |
| 257 | + """Get an agent registration |
| 258 | +
|
| 259 | + Retrieve the details of an agent registration by ID. The registration is scoped to the environment of the API key used to authenticate the request. |
| 260 | +
|
| 261 | + Args: |
| 262 | + id: The unique ID of the agent registration. |
| 263 | + request_options: Per-request options. Supports extra_headers, timeout, max_retries, and base_url override. |
| 264 | +
|
| 265 | + Returns: |
| 266 | + AgentRegistration |
| 267 | +
|
| 268 | + Raises: |
| 269 | + NotFoundError: If the resource is not found (404). |
| 270 | + AuthenticationError: If the API key is invalid (401). |
| 271 | + RateLimitExceededError: If rate limited (429). |
| 272 | + ServerError: If the server returns a 5xx error. |
| 273 | + """ |
| 274 | + return await self._client.request( |
| 275 | + method="get", |
| 276 | + path=("agents", "registrations", str(id)), |
| 277 | + model=AgentRegistration, |
| 278 | + request_options=request_options, |
| 279 | + ) |
0 commit comments