-
Notifications
You must be signed in to change notification settings - Fork 0
Updated the SDK to handle attachments #minor #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Contains endpoint functions for accessing the API""" |
283 changes: 283 additions & 0 deletions
283
...ents/serve_agent_run_attachment_api_v2_agent_runs_run_id_attachments_attachment_id_get.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,283 @@ | ||
| from http import HTTPStatus | ||
| from io import BytesIO | ||
| from typing import Any | ||
| from urllib.parse import quote | ||
| from uuid import UUID | ||
|
|
||
| import httpx | ||
|
|
||
| from ... import errors | ||
| from ...client import AuthenticatedClient, Client | ||
| from ...models.http_validation_error import HTTPValidationError | ||
| from ...types import UNSET, File, Response, Unset | ||
|
|
||
|
|
||
| def _get_kwargs( | ||
| run_id: UUID, | ||
| attachment_id: str, | ||
| *, | ||
| download_name: None | str | Unset = UNSET, | ||
| x_account_id: UUID | Unset = UNSET, | ||
| ) -> dict[str, Any]: | ||
| headers: dict[str, Any] = {} | ||
| if not isinstance(x_account_id, Unset): | ||
| headers["X-Account-Id"] = x_account_id | ||
|
|
||
| params: dict[str, Any] = {} | ||
|
|
||
| json_download_name: None | str | Unset | ||
| if isinstance(download_name, Unset): | ||
| json_download_name = UNSET | ||
| else: | ||
| json_download_name = download_name | ||
| params["download_name"] = json_download_name | ||
|
|
||
| params = {k: v for k, v in params.items() if v is not UNSET and v is not None} | ||
|
|
||
| _kwargs: dict[str, Any] = { | ||
| "method": "get", | ||
| "url": "/v2/agent-runs/{run_id}/attachments/{attachment_id}".format( | ||
| run_id=quote(str(run_id), safe=""), | ||
| attachment_id=quote(str(attachment_id), safe=""), | ||
| ), | ||
| "params": params, | ||
| } | ||
|
|
||
| _kwargs["headers"] = headers | ||
| return _kwargs | ||
|
|
||
|
|
||
| def _parse_response( | ||
| *, client: AuthenticatedClient | Client, response: httpx.Response | ||
| ) -> File | HTTPValidationError | None: | ||
| if response.status_code == 200: | ||
| response_200 = File(payload=BytesIO(response.content)) | ||
|
|
||
| return response_200 | ||
|
|
||
| if response.status_code == 422: | ||
| response_422 = HTTPValidationError.from_dict(response.json()) | ||
|
|
||
| return response_422 | ||
|
|
||
| if client.raise_on_unexpected_status: | ||
| raise errors.UnexpectedStatus(response.status_code, response.content) | ||
| else: | ||
| return None | ||
|
|
||
|
|
||
| def _build_response( | ||
| *, client: AuthenticatedClient | Client, response: httpx.Response | ||
| ) -> Response[File | HTTPValidationError]: | ||
| return Response( | ||
| status_code=HTTPStatus(response.status_code), | ||
| content=response.content, | ||
| headers=response.headers, | ||
| parsed=_parse_response(client=client, response=response), | ||
| ) | ||
|
|
||
|
|
||
| def sync_detailed( | ||
| run_id: UUID, | ||
| attachment_id: str, | ||
| *, | ||
| client: AuthenticatedClient | Client, | ||
| download_name: None | str | Unset = UNSET, | ||
| x_account_id: UUID | Unset = UNSET, | ||
| ) -> Response[File | HTTPValidationError]: | ||
| """Download an agent-run attachment | ||
|
|
||
| Streams the bytes of an attachment emitted by a step in the given agent run. ``attachment_id`` is | ||
| the URL-safe-base64-encoded ``storage_key`` (use the encoder shared by webhook + email payload | ||
| builders). | ||
|
|
||
| Auth & scoping: | ||
| - Requires `X-API-Key` header or OAuth Bearer token. | ||
| - The calling account must own ``run_id``; lookup failures (missing run, cross-account run, soft- | ||
| deleted agent, unreferenced storage_key) all collapse to a single 404 to prevent cross-tenant | ||
| existence enumeration. | ||
|
|
||
| MIME handling: | ||
| - Inline-safe MIMEs (image/*, audio/*, video/*, application/pdf, text/plain, | ||
| application/vnd.seclai.manifest+json) are served with their declared type. | ||
| - Everything else is served as ``application/octet-stream`` with an attachment disposition to | ||
| prevent stored-XSS. | ||
|
|
||
| Args: | ||
| run_id (UUID): | ||
| attachment_id (str): | ||
| download_name (None | str | Unset): | ||
| x_account_id (UUID | Unset): | ||
|
|
||
| Raises: | ||
| errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. | ||
| httpx.TimeoutException: If the request takes longer than Client.timeout. | ||
|
|
||
| Returns: | ||
| Response[File | HTTPValidationError] | ||
| """ | ||
|
|
||
| kwargs = _get_kwargs( | ||
| run_id=run_id, | ||
| attachment_id=attachment_id, | ||
| download_name=download_name, | ||
| x_account_id=x_account_id, | ||
| ) | ||
|
|
||
| response = client.get_httpx_client().request( | ||
| **kwargs, | ||
| ) | ||
|
|
||
| return _build_response(client=client, response=response) | ||
|
|
||
|
|
||
| def sync( | ||
| run_id: UUID, | ||
| attachment_id: str, | ||
| *, | ||
| client: AuthenticatedClient | Client, | ||
| download_name: None | str | Unset = UNSET, | ||
| x_account_id: UUID | Unset = UNSET, | ||
| ) -> File | HTTPValidationError | None: | ||
| """Download an agent-run attachment | ||
|
|
||
| Streams the bytes of an attachment emitted by a step in the given agent run. ``attachment_id`` is | ||
| the URL-safe-base64-encoded ``storage_key`` (use the encoder shared by webhook + email payload | ||
| builders). | ||
|
|
||
| Auth & scoping: | ||
| - Requires `X-API-Key` header or OAuth Bearer token. | ||
| - The calling account must own ``run_id``; lookup failures (missing run, cross-account run, soft- | ||
| deleted agent, unreferenced storage_key) all collapse to a single 404 to prevent cross-tenant | ||
| existence enumeration. | ||
|
|
||
| MIME handling: | ||
| - Inline-safe MIMEs (image/*, audio/*, video/*, application/pdf, text/plain, | ||
| application/vnd.seclai.manifest+json) are served with their declared type. | ||
| - Everything else is served as ``application/octet-stream`` with an attachment disposition to | ||
| prevent stored-XSS. | ||
|
|
||
| Args: | ||
| run_id (UUID): | ||
| attachment_id (str): | ||
| download_name (None | str | Unset): | ||
| x_account_id (UUID | Unset): | ||
|
|
||
| Raises: | ||
| errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. | ||
| httpx.TimeoutException: If the request takes longer than Client.timeout. | ||
|
|
||
| Returns: | ||
| File | HTTPValidationError | ||
| """ | ||
|
|
||
| return sync_detailed( | ||
| run_id=run_id, | ||
| attachment_id=attachment_id, | ||
| client=client, | ||
| download_name=download_name, | ||
| x_account_id=x_account_id, | ||
| ).parsed | ||
|
|
||
|
|
||
| async def asyncio_detailed( | ||
| run_id: UUID, | ||
| attachment_id: str, | ||
| *, | ||
| client: AuthenticatedClient | Client, | ||
| download_name: None | str | Unset = UNSET, | ||
| x_account_id: UUID | Unset = UNSET, | ||
| ) -> Response[File | HTTPValidationError]: | ||
| """Download an agent-run attachment | ||
|
|
||
| Streams the bytes of an attachment emitted by a step in the given agent run. ``attachment_id`` is | ||
| the URL-safe-base64-encoded ``storage_key`` (use the encoder shared by webhook + email payload | ||
| builders). | ||
|
|
||
| Auth & scoping: | ||
| - Requires `X-API-Key` header or OAuth Bearer token. | ||
| - The calling account must own ``run_id``; lookup failures (missing run, cross-account run, soft- | ||
| deleted agent, unreferenced storage_key) all collapse to a single 404 to prevent cross-tenant | ||
| existence enumeration. | ||
|
|
||
| MIME handling: | ||
| - Inline-safe MIMEs (image/*, audio/*, video/*, application/pdf, text/plain, | ||
| application/vnd.seclai.manifest+json) are served with their declared type. | ||
| - Everything else is served as ``application/octet-stream`` with an attachment disposition to | ||
| prevent stored-XSS. | ||
|
|
||
| Args: | ||
| run_id (UUID): | ||
| attachment_id (str): | ||
| download_name (None | str | Unset): | ||
| x_account_id (UUID | Unset): | ||
|
|
||
| Raises: | ||
| errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. | ||
| httpx.TimeoutException: If the request takes longer than Client.timeout. | ||
|
|
||
| Returns: | ||
| Response[File | HTTPValidationError] | ||
| """ | ||
|
|
||
| kwargs = _get_kwargs( | ||
| run_id=run_id, | ||
| attachment_id=attachment_id, | ||
| download_name=download_name, | ||
| x_account_id=x_account_id, | ||
| ) | ||
|
|
||
| response = await client.get_async_httpx_client().request(**kwargs) | ||
|
|
||
| return _build_response(client=client, response=response) | ||
|
|
||
|
|
||
| async def asyncio( | ||
| run_id: UUID, | ||
| attachment_id: str, | ||
| *, | ||
| client: AuthenticatedClient | Client, | ||
| download_name: None | str | Unset = UNSET, | ||
| x_account_id: UUID | Unset = UNSET, | ||
| ) -> File | HTTPValidationError | None: | ||
| """Download an agent-run attachment | ||
|
|
||
| Streams the bytes of an attachment emitted by a step in the given agent run. ``attachment_id`` is | ||
| the URL-safe-base64-encoded ``storage_key`` (use the encoder shared by webhook + email payload | ||
| builders). | ||
|
|
||
| Auth & scoping: | ||
| - Requires `X-API-Key` header or OAuth Bearer token. | ||
| - The calling account must own ``run_id``; lookup failures (missing run, cross-account run, soft- | ||
| deleted agent, unreferenced storage_key) all collapse to a single 404 to prevent cross-tenant | ||
| existence enumeration. | ||
|
|
||
| MIME handling: | ||
| - Inline-safe MIMEs (image/*, audio/*, video/*, application/pdf, text/plain, | ||
| application/vnd.seclai.manifest+json) are served with their declared type. | ||
| - Everything else is served as ``application/octet-stream`` with an attachment disposition to | ||
| prevent stored-XSS. | ||
|
|
||
| Args: | ||
| run_id (UUID): | ||
| attachment_id (str): | ||
| download_name (None | str | Unset): | ||
| x_account_id (UUID | Unset): | ||
|
|
||
| Raises: | ||
| errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. | ||
| httpx.TimeoutException: If the request takes longer than Client.timeout. | ||
|
|
||
| Returns: | ||
| File | HTTPValidationError | ||
| """ | ||
|
|
||
| return ( | ||
| await asyncio_detailed( | ||
| run_id=run_id, | ||
| attachment_id=attachment_id, | ||
| client=client, | ||
| download_name=download_name, | ||
| x_account_id=x_account_id, | ||
| ) | ||
| ).parsed | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.