From f3d96f9ca166d5a28da03cac26a4138978615ec7 Mon Sep 17 00:00:00 2001 From: "kernel-internal[bot]" <260533166+kernel-internal[bot]@users.noreply.github.com> Date: Fri, 13 Nov 2026 00:42:21 +0000 Subject: [PATCH 1/6] Build SDK Stainless-Generated-From: 85b54291039b626d126c5af578674be5ba4fbbb8 --- .../agentcard_checkout_authorization.py | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/kernel/types/vaults/agentcard_checkout_authorization.py b/src/kernel/types/vaults/agentcard_checkout_authorization.py index 2a0dc815..32eb95bd 100644 --- a/src/kernel/types/vaults/agentcard_checkout_authorization.py +++ b/src/kernel/types/vaults/agentcard_checkout_authorization.py @@ -34,9 +34,21 @@ class AgentcardCheckoutAuthorization(BaseModel): amount: Optional[str] = None """Display amount shown on the approval screen.""" - amount_authority: Optional[Literal["display_only", "stripe_payment_intent"]] = None + amount_authority: Optional[Literal["processor", "agent", "page", "none", "display_only"]] = None + """Source of the approved amount. + + `processor` is read from the processor request or payment; `agent` is the item's + declared amount; `page` is the checkout page total; `none` means no amount was + named. `display_only` appears only on authorizations recovered without a + provider read. `agent` and `display_only` don't prove what the processor + charged. + """ amount_verified: Optional[bool] = None + """Whether the processor charged the approved amount. + + Absent when there was no charge to compare, including tokenization checkouts. + """ approval_url: Optional[str] = None @@ -44,10 +56,24 @@ class AgentcardCheckoutAuthorization(BaseModel): """Browser session that submitted the checkout.""" charged_amount_cents: Optional[int] = None + """Amount the processor reported collecting. + + Absent when the provider didn't observe a charge. + """ charged_currency: Optional[str] = None + """Currency of `charged_amount_cents`. + + Absent when the provider didn't observe a charge. + """ charged_kind: Optional[Literal["captured", "authorized", "none"]] = None + """What the processor collected. + + `none` means the checkout produced a token or payment method that the merchant + charges later. Absent when the provider reported nothing, which is common for + tokenization checkouts; use item events and the merchant's order record instead. + """ expected_cents: Optional[int] = None From a0d2e4c7dadedba5ae4e3a6020cb3577afeda002 Mon Sep 17 00:00:00 2001 From: Rafael Date: Fri, 13 Nov 2026 16:49:19 -0500 Subject: [PATCH 2/6] Lock workflow action dependencies with actions.lock (#14) Co-authored-by: rgarcia <72655+rgarcia@users.noreply.github.com> --- .github/workflows/actions.lock | 49 ++++++++++++++++++++++++++++ .github/workflows/release-please.yml | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/actions.lock diff --git a/.github/workflows/actions.lock b/.github/workflows/actions.lock new file mode 100644 index 00000000..2b0c5d00 --- /dev/null +++ b/.github/workflows/actions.lock @@ -0,0 +1,49 @@ +# This file is machine-generated by `gh actions-lock`. +# Do not edit by hand; run `gh actions-lock` to update. +# Docs: https://gh.io/actions-lockfile +version: 'v0.0.3' +workflows: + '.github/workflows/ci.yml': + - 'actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd' + - 'actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd' + '.github/workflows/publish-pypi.yml': + - 'actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd' + '.github/workflows/release-doctor.yml': + - 'actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd' + '.github/workflows/release-please.yml': + - 'actions/create-github-app-token@d72941d797fd3113feb6b93fd0dec494b13a2547' + - 'actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020' + - 'pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1' + '.github/workflows/semgrep.yml': [] + '.github/workflows/stlc-promote.yml': + - 'actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd' + - 'actions/create-github-app-token@d72941d797fd3113feb6b93fd0dec494b13a2547' + '.github/workflows/stlc-sync.yml': + - 'actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd' + '.github/workflows/vuln-remediation.yml': [] +dependencies: + 'actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd': + ref: 'v6.0.2' + commit: 'sha1-de0fac2e4500dabe0009e67214ff5f5447ce83dd' + owner_id: 44036562 + repo_id: 197814629 + 'actions/create-github-app-token@d72941d797fd3113feb6b93fd0dec494b13a2547': + ref: 'v1.12.0' + commit: 'sha1-d72941d797fd3113feb6b93fd0dec494b13a2547' + owner_id: 44036562 + repo_id: 642580244 + 'actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd': + ref: 'v8.0.0' + commit: 'sha1-ed597411d8f924073f98dfc5c65a23a2325f34cd' + owner_id: 44036562 + repo_id: 205262760 + 'actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020': + ref: 'v4.4.0' + commit: 'sha1-49933ea5288caeca8642d1e84afbd3f7d6820020' + owner_id: 44036562 + repo_id: 189476904 + 'pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1': + ref: 'v4.3.0' + commit: 'sha1-b906affcce14559ad1aafd4ab0e942779e9f58b1' + owner_id: 21320719 + repo_id: 262289747 diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 4737ca42..5afb4921 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -41,7 +41,7 @@ jobs: node-version: '18.20.2' - name: Set up pnpm - uses: pnpm/action-setup@f40ffcd9367d9f12939873eb1018b921a783ffaa # v4 + uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4.3.0 with: version: '9.11.0' run_install: false From 5dd6af87afa61b5fbbc5770585ae04f4ec2fe49c Mon Sep 17 00:00:00 2001 From: "kernel-internal[bot]" <260533166+kernel-internal[bot]@users.noreply.github.com> Date: Mon, 16 Nov 2026 20:36:16 +0000 Subject: [PATCH 3/6] feat: Add tasks API: create, list, get, and link browsers Stainless-Generated-From: 7522e2bfb4ce63825f43c1b990ca66cb88f07911 --- .stats.yml | 2 +- api.md | 15 + src/kernel/_client.py | 44 ++ src/kernel/resources/__init__.py | 14 + src/kernel/resources/tasks.py | 544 ++++++++++++++++++ src/kernel/types/__init__.py | 6 + src/kernel/types/task.py | 44 ++ src/kernel/types/task_create_params.py | 41 ++ src/kernel/types/task_link_browsers_params.py | 18 + src/kernel/types/task_list_params.py | 18 + src/kernel/types/task_metadata.py | 8 + src/kernel/types/task_metadata_param.py | 10 + tests/api_resources/test_tasks.py | 376 ++++++++++++ 13 files changed, 1139 insertions(+), 1 deletion(-) create mode 100644 src/kernel/resources/tasks.py create mode 100644 src/kernel/types/task.py create mode 100644 src/kernel/types/task_create_params.py create mode 100644 src/kernel/types/task_link_browsers_params.py create mode 100644 src/kernel/types/task_list_params.py create mode 100644 src/kernel/types/task_metadata.py create mode 100644 src/kernel/types/task_metadata_param.py create mode 100644 tests/api_resources/test_tasks.py diff --git a/.stats.yml b/.stats.yml index 4731cdc5..83b7ea96 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1 +1 @@ -configured_endpoints: 179 +configured_endpoints: 183 diff --git a/api.md b/api.md index b6bbfdd2..26ca093d 100644 --- a/api.md +++ b/api.md @@ -425,6 +425,21 @@ Methods: - client.profiles.delete(id_or_name) -> None - client.profiles.download(id_or_name, \*\*params) -> BinaryAPIResponse +# Tasks + +Types: + +```python +from kernel.types import Task, TaskMetadata +``` + +Methods: + +- client.tasks.create(\*\*params) -> Task +- client.tasks.retrieve(id) -> Task +- client.tasks.list(\*\*params) -> SyncOffsetPagination[Task] +- client.tasks.link_browsers(id, \*\*params) -> Task + # Auth ## Context diff --git a/src/kernel/_client.py b/src/kernel/_client.py index 1d347980..ba0a733f 100644 --- a/src/kernel/_client.py +++ b/src/kernel/_client.py @@ -57,6 +57,7 @@ from .resources import ( apps, auth, + tasks, search, vaults, proxies, @@ -78,6 +79,7 @@ vault_provider_configs, ) from .resources.apps import AppsResource, AsyncAppsResource + from .resources.tasks import TasksResource, AsyncTasksResource from .resources.proxies import ProxiesResource, AsyncProxiesResource from .resources.api_keys import APIKeysResource, AsyncAPIKeysResource from .resources.profiles import ProfilesResource, AsyncProfilesResource @@ -264,6 +266,13 @@ def profiles(self) -> ProfilesResource: return ProfilesResource(self) + @cached_property + def tasks(self) -> TasksResource: + """Define tasks that agents work toward and link the browsers they use.""" + from .resources.tasks import TasksResource + + return TasksResource(self) + @cached_property def auth(self) -> AuthResource: from .resources.auth import AuthResource @@ -680,6 +689,13 @@ def profiles(self) -> AsyncProfilesResource: return AsyncProfilesResource(self) + @cached_property + def tasks(self) -> AsyncTasksResource: + """Define tasks that agents work toward and link the browsers they use.""" + from .resources.tasks import AsyncTasksResource + + return AsyncTasksResource(self) + @cached_property def auth(self) -> AsyncAuthResource: from .resources.auth import AsyncAuthResource @@ -996,6 +1012,13 @@ def profiles(self) -> profiles.ProfilesResourceWithRawResponse: return ProfilesResourceWithRawResponse(self._client.profiles) + @cached_property + def tasks(self) -> tasks.TasksResourceWithRawResponse: + """Define tasks that agents work toward and link the browsers they use.""" + from .resources.tasks import TasksResourceWithRawResponse + + return TasksResourceWithRawResponse(self._client.tasks) + @cached_property def auth(self) -> auth.AuthResourceWithRawResponse: from .resources.auth import AuthResourceWithRawResponse @@ -1144,6 +1167,13 @@ def profiles(self) -> profiles.AsyncProfilesResourceWithRawResponse: return AsyncProfilesResourceWithRawResponse(self._client.profiles) + @cached_property + def tasks(self) -> tasks.AsyncTasksResourceWithRawResponse: + """Define tasks that agents work toward and link the browsers they use.""" + from .resources.tasks import AsyncTasksResourceWithRawResponse + + return AsyncTasksResourceWithRawResponse(self._client.tasks) + @cached_property def auth(self) -> auth.AsyncAuthResourceWithRawResponse: from .resources.auth import AsyncAuthResourceWithRawResponse @@ -1292,6 +1322,13 @@ def profiles(self) -> profiles.ProfilesResourceWithStreamingResponse: return ProfilesResourceWithStreamingResponse(self._client.profiles) + @cached_property + def tasks(self) -> tasks.TasksResourceWithStreamingResponse: + """Define tasks that agents work toward and link the browsers they use.""" + from .resources.tasks import TasksResourceWithStreamingResponse + + return TasksResourceWithStreamingResponse(self._client.tasks) + @cached_property def auth(self) -> auth.AuthResourceWithStreamingResponse: from .resources.auth import AuthResourceWithStreamingResponse @@ -1440,6 +1477,13 @@ def profiles(self) -> profiles.AsyncProfilesResourceWithStreamingResponse: return AsyncProfilesResourceWithStreamingResponse(self._client.profiles) + @cached_property + def tasks(self) -> tasks.AsyncTasksResourceWithStreamingResponse: + """Define tasks that agents work toward and link the browsers they use.""" + from .resources.tasks import AsyncTasksResourceWithStreamingResponse + + return AsyncTasksResourceWithStreamingResponse(self._client.tasks) + @cached_property def auth(self) -> auth.AsyncAuthResourceWithStreamingResponse: from .resources.auth import AsyncAuthResourceWithStreamingResponse diff --git a/src/kernel/resources/__init__.py b/src/kernel/resources/__init__.py index 0827e925..fdbbdf89 100644 --- a/src/kernel/resources/__init__.py +++ b/src/kernel/resources/__init__.py @@ -16,6 +16,14 @@ AuthResourceWithStreamingResponse, AsyncAuthResourceWithStreamingResponse, ) +from .tasks import ( + TasksResource, + AsyncTasksResource, + TasksResourceWithRawResponse, + AsyncTasksResourceWithRawResponse, + TasksResourceWithStreamingResponse, + AsyncTasksResourceWithStreamingResponse, +) from .search import ( SearchResource, AsyncSearchResource, @@ -206,6 +214,12 @@ "AsyncProfilesResourceWithRawResponse", "ProfilesResourceWithStreamingResponse", "AsyncProfilesResourceWithStreamingResponse", + "TasksResource", + "AsyncTasksResource", + "TasksResourceWithRawResponse", + "AsyncTasksResourceWithRawResponse", + "TasksResourceWithStreamingResponse", + "AsyncTasksResourceWithStreamingResponse", "AuthResource", "AsyncAuthResource", "AuthResourceWithRawResponse", diff --git a/src/kernel/resources/tasks.py b/src/kernel/resources/tasks.py new file mode 100644 index 00000000..96a49ade --- /dev/null +++ b/src/kernel/resources/tasks.py @@ -0,0 +1,544 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Union +from datetime import datetime + +import httpx + +from ..types import task_list_params, task_create_params, task_link_browsers_params +from .._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given +from .._utils import path_template, 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 ..pagination import SyncOffsetPagination, AsyncOffsetPagination +from ..types.task import Task +from .._base_client import AsyncPaginator, make_request_options +from ..types.task_metadata_param import TaskMetadataParam + +__all__ = ["TasksResource", "AsyncTasksResource"] + + +class TasksResource(SyncAPIResource): + """Define tasks that agents work toward and link the browsers they use.""" + + @cached_property + def with_raw_response(self) -> TasksResourceWithRawResponse: + """ + 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/kernel/kernel-python-sdk#accessing-raw-response-data-eg-headers + """ + return TasksResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> TasksResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/kernel/kernel-python-sdk#with_streaming_response + """ + return TasksResourceWithStreamingResponse(self) + + def create( + self, + *, + description: str, + metadata: TaskMetadataParam | Omit = omit, + session_ids: SequenceNotStr[str] | Omit = omit, + started_at: Union[str, datetime] | Omit = omit, + target_website: str | Omit = omit, + # 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, + idempotency_key: str | None = None, + ) -> Task: + """ + Define a task before or while an agent works on it, optionally linking the + browsers it uses. Submit reports against the returned task ID. + + Args: + description: What the task is meant to accomplish, at most 4 KB. + + metadata: Caller-defined string key-value pairs for grouping and filtering tasks, such as + a user or thread ID. At most 20 keys; keys are 1-64 characters, values at most + 256 characters, and keys and values together at most 4 KB. + + session_ids: IDs of browsers to link to the task. Each must belong to the request's project; + deleted browsers can be linked. + + started_at: When work on the task started. Defaults to the time the task is created. Must be + no more than 5 minutes in the future or 30 days in the past. + + target_website: Hostname of the website the task targets, without a scheme or path. + + 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 + + idempotency_key: Specify a custom idempotency key for this request + """ + return self._post( + "/tasks", + body=maybe_transform( + { + "description": description, + "metadata": metadata, + "session_ids": session_ids, + "started_at": started_at, + "target_website": target_website, + }, + task_create_params.TaskCreateParams, + ), + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + idempotency_key=idempotency_key, + ), + cast_to=Task, + ) + + def retrieve( + self, + id: 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: + """ + Retrieve a task and the IDs of its linked browsers. + + 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 id: + raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + return self._get( + path_template("/tasks/{id}", id=id), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=Task, + ) + + def list( + self, + *, + limit: int | Omit = omit, + offset: int | Omit = omit, + session_id: str | Omit = omit, + # 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, + ) -> SyncOffsetPagination[Task]: + """ + List tasks in the request's project, newest first. + + Args: + limit: Limit the number of tasks to return. + + offset: Offset the number of tasks to return. + + session_id: Only return tasks linked to this browser ID. + + 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 + """ + return self._get_api_list( + "/tasks", + page=SyncOffsetPagination[Task], + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + query=maybe_transform( + { + "limit": limit, + "offset": offset, + "session_id": session_id, + }, + task_list_params.TaskListParams, + ), + ), + model=Task, + ) + + def link_browsers( + self, + id: str, + *, + session_ids: SequenceNotStr[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, + idempotency_key: str | None = None, + ) -> Task: + """Link browsers to an existing task. + + Linking a browser that is already linked has + no effect, so the call is safe to retry. Returns the updated task. + + Args: + session_ids: IDs of browsers to link. Each must belong to the task's project; deleted + browsers can be linked. Browsers already linked are ignored. A task can have at + most 100 linked browsers. + + 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 + + idempotency_key: Specify a custom idempotency key for this request + """ + if not id: + raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + return self._post( + path_template("/tasks/{id}/browsers", id=id), + body=maybe_transform({"session_ids": session_ids}, task_link_browsers_params.TaskLinkBrowsersParams), + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + idempotency_key=idempotency_key, + ), + cast_to=Task, + ) + + +class AsyncTasksResource(AsyncAPIResource): + """Define tasks that agents work toward and link the browsers they use.""" + + @cached_property + def with_raw_response(self) -> AsyncTasksResourceWithRawResponse: + """ + 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/kernel/kernel-python-sdk#accessing-raw-response-data-eg-headers + """ + return AsyncTasksResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncTasksResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/kernel/kernel-python-sdk#with_streaming_response + """ + return AsyncTasksResourceWithStreamingResponse(self) + + async def create( + self, + *, + description: str, + metadata: TaskMetadataParam | Omit = omit, + session_ids: SequenceNotStr[str] | Omit = omit, + started_at: Union[str, datetime] | Omit = omit, + target_website: str | Omit = omit, + # 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, + idempotency_key: str | None = None, + ) -> Task: + """ + Define a task before or while an agent works on it, optionally linking the + browsers it uses. Submit reports against the returned task ID. + + Args: + description: What the task is meant to accomplish, at most 4 KB. + + metadata: Caller-defined string key-value pairs for grouping and filtering tasks, such as + a user or thread ID. At most 20 keys; keys are 1-64 characters, values at most + 256 characters, and keys and values together at most 4 KB. + + session_ids: IDs of browsers to link to the task. Each must belong to the request's project; + deleted browsers can be linked. + + started_at: When work on the task started. Defaults to the time the task is created. Must be + no more than 5 minutes in the future or 30 days in the past. + + target_website: Hostname of the website the task targets, without a scheme or path. + + 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 + + idempotency_key: Specify a custom idempotency key for this request + """ + return await self._post( + "/tasks", + body=await async_maybe_transform( + { + "description": description, + "metadata": metadata, + "session_ids": session_ids, + "started_at": started_at, + "target_website": target_website, + }, + task_create_params.TaskCreateParams, + ), + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + idempotency_key=idempotency_key, + ), + cast_to=Task, + ) + + async def retrieve( + self, + id: 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: + """ + Retrieve a task and the IDs of its linked browsers. + + 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 id: + raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + return await self._get( + path_template("/tasks/{id}", id=id), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=Task, + ) + + def list( + self, + *, + limit: int | Omit = omit, + offset: int | Omit = omit, + session_id: str | Omit = omit, + # 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, + ) -> AsyncPaginator[Task, AsyncOffsetPagination[Task]]: + """ + List tasks in the request's project, newest first. + + Args: + limit: Limit the number of tasks to return. + + offset: Offset the number of tasks to return. + + session_id: Only return tasks linked to this browser ID. + + 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 + """ + return self._get_api_list( + "/tasks", + page=AsyncOffsetPagination[Task], + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + query=maybe_transform( + { + "limit": limit, + "offset": offset, + "session_id": session_id, + }, + task_list_params.TaskListParams, + ), + ), + model=Task, + ) + + async def link_browsers( + self, + id: str, + *, + session_ids: SequenceNotStr[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, + idempotency_key: str | None = None, + ) -> Task: + """Link browsers to an existing task. + + Linking a browser that is already linked has + no effect, so the call is safe to retry. Returns the updated task. + + Args: + session_ids: IDs of browsers to link. Each must belong to the task's project; deleted + browsers can be linked. Browsers already linked are ignored. A task can have at + most 100 linked browsers. + + 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 + + idempotency_key: Specify a custom idempotency key for this request + """ + if not id: + raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + return await self._post( + path_template("/tasks/{id}/browsers", id=id), + body=await async_maybe_transform( + {"session_ids": session_ids}, task_link_browsers_params.TaskLinkBrowsersParams + ), + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + idempotency_key=idempotency_key, + ), + cast_to=Task, + ) + + +class TasksResourceWithRawResponse: + def __init__(self, tasks: TasksResource) -> None: + self._tasks = tasks + + self.create = to_raw_response_wrapper( + tasks.create, + ) + self.retrieve = to_raw_response_wrapper( + tasks.retrieve, + ) + self.list = to_raw_response_wrapper( + tasks.list, + ) + self.link_browsers = to_raw_response_wrapper( + tasks.link_browsers, + ) + + +class AsyncTasksResourceWithRawResponse: + def __init__(self, tasks: AsyncTasksResource) -> None: + self._tasks = tasks + + self.create = async_to_raw_response_wrapper( + tasks.create, + ) + self.retrieve = async_to_raw_response_wrapper( + tasks.retrieve, + ) + self.list = async_to_raw_response_wrapper( + tasks.list, + ) + self.link_browsers = async_to_raw_response_wrapper( + tasks.link_browsers, + ) + + +class TasksResourceWithStreamingResponse: + def __init__(self, tasks: TasksResource) -> None: + self._tasks = tasks + + self.create = to_streamed_response_wrapper( + tasks.create, + ) + self.retrieve = to_streamed_response_wrapper( + tasks.retrieve, + ) + self.list = to_streamed_response_wrapper( + tasks.list, + ) + self.link_browsers = to_streamed_response_wrapper( + tasks.link_browsers, + ) + + +class AsyncTasksResourceWithStreamingResponse: + def __init__(self, tasks: AsyncTasksResource) -> None: + self._tasks = tasks + + self.create = async_to_streamed_response_wrapper( + tasks.create, + ) + self.retrieve = async_to_streamed_response_wrapper( + tasks.retrieve, + ) + self.list = async_to_streamed_response_wrapper( + tasks.list, + ) + self.link_browsers = async_to_streamed_response_wrapper( + tasks.link_browsers, + ) diff --git a/src/kernel/types/__init__.py b/src/kernel/types/__init__.py index 45cc0ec4..2a4e2e02 100644 --- a/src/kernel/types/__init__.py +++ b/src/kernel/types/__init__.py @@ -5,6 +5,7 @@ from . import browsers from .. import _compat from .tags import Tags as Tags +from .task import Task as Task from .proxy import Proxy as Proxy from .usage import Usage as Usage from .vault import Vault as Vault @@ -36,6 +37,7 @@ from .browser_pool import BrowserPool as BrowserPool from .browser_proxy import BrowserProxy as BrowserProxy from .browser_usage import BrowserUsage as BrowserUsage +from .task_metadata import TaskMetadata as TaskMetadata from .browser_memory import BrowserMemory as BrowserMemory from .recommendation import Recommendation as Recommendation from .strategy_param import StrategyParam as StrategyParam @@ -48,12 +50,14 @@ from .analysis_summary import AnalysisSummary as AnalysisSummary from .browser_location import BrowserLocation as BrowserLocation from .browser_pool_ref import BrowserPoolRef as BrowserPoolRef +from .task_list_params import TaskListParams as TaskListParams from .app_list_response import AppListResponse as AppListResponse from .no_recommendation import NoRecommendation as NoRecommendation from .proxy_list_params import ProxyListParams as ProxyListParams from .vault_list_params import VaultListParams as VaultListParams from .browser_proxy_mode import BrowserProxyMode as BrowserProxyMode from .proxy_check_params import ProxyCheckParams as ProxyCheckParams +from .task_create_params import TaskCreateParams as TaskCreateParams from .api_key_list_params import APIKeyListParams as APIKeyListParams from .browser_curl_params import BrowserCurlParams as BrowserCurlParams from .browser_list_params import BrowserListParams as BrowserListParams @@ -65,6 +69,7 @@ from .proxy_create_params import ProxyCreateParams as ProxyCreateParams from .proxy_list_response import ProxyListResponse as ProxyListResponse from .proxy_update_params import ProxyUpdateParams as ProxyUpdateParams +from .task_metadata_param import TaskMetadataParam as TaskMetadataParam from .vault_upsert_params import VaultUpsertParams as VaultUpsertParams from .browser_proxy_config import BrowserProxyConfig as BrowserProxyConfig from .browser_repl_content import BrowserReplContent as BrowserReplContent @@ -127,6 +132,7 @@ from .browser_repl_text_content import BrowserReplTextContent as BrowserReplTextContent from .browser_retrieve_response import BrowserRetrieveResponse as BrowserRetrieveResponse from .extension_upload_response import ExtensionUploadResponse as ExtensionUploadResponse +from .task_link_browsers_params import TaskLinkBrowsersParams as TaskLinkBrowsersParams from .browser_pool_create_params import BrowserPoolCreateParams as BrowserPoolCreateParams from .browser_pool_delete_params import BrowserPoolDeleteParams as BrowserPoolDeleteParams from .browser_pool_update_params import BrowserPoolUpdateParams as BrowserPoolUpdateParams diff --git a/src/kernel/types/task.py b/src/kernel/types/task.py new file mode 100644 index 00000000..00681a5f --- /dev/null +++ b/src/kernel/types/task.py @@ -0,0 +1,44 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import List, Optional +from datetime import datetime + +from .._models import BaseModel +from .task_metadata import TaskMetadata + +__all__ = ["Task"] + + +class Task(BaseModel): + """A goal an agent works toward. + + Reports are submitted against a task, and browsers can be linked to it. Tasks are immutable apart from added browser links. + """ + + id: str + """Unique identifier for the task""" + + created_at: datetime + """When the task was created""" + + description: str + """What the task is meant to accomplish""" + + metadata: TaskMetadata + """ + Caller-defined string key-value pairs for grouping and filtering tasks, such as + a user or thread ID. At most 20 keys; keys are 1-64 characters, values at most + 256 characters, and keys and values together at most 4 KB. + """ + + session_ids: List[str] + """IDs of browsers linked to the task, oldest link first. + + Linked browsers may since have been deleted. + """ + + started_at: datetime + """When work on the task started""" + + target_website: Optional[str] = None + """Hostname of the website the task targets""" diff --git a/src/kernel/types/task_create_params.py b/src/kernel/types/task_create_params.py new file mode 100644 index 00000000..7819c716 --- /dev/null +++ b/src/kernel/types/task_create_params.py @@ -0,0 +1,41 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Union +from datetime import datetime +from typing_extensions import Required, Annotated, TypedDict + +from .._types import SequenceNotStr +from .._utils import PropertyInfo +from .task_metadata_param import TaskMetadataParam + +__all__ = ["TaskCreateParams"] + + +class TaskCreateParams(TypedDict, total=False): + description: Required[str] + """What the task is meant to accomplish, at most 4 KB.""" + + metadata: TaskMetadataParam + """ + Caller-defined string key-value pairs for grouping and filtering tasks, such as + a user or thread ID. At most 20 keys; keys are 1-64 characters, values at most + 256 characters, and keys and values together at most 4 KB. + """ + + session_ids: SequenceNotStr[str] + """IDs of browsers to link to the task. + + Each must belong to the request's project; deleted browsers can be linked. + """ + + started_at: Annotated[Union[str, datetime], PropertyInfo(format="iso8601")] + """When work on the task started. + + Defaults to the time the task is created. Must be no more than 5 minutes in the + future or 30 days in the past. + """ + + target_website: str + """Hostname of the website the task targets, without a scheme or path.""" diff --git a/src/kernel/types/task_link_browsers_params.py b/src/kernel/types/task_link_browsers_params.py new file mode 100644 index 00000000..8679f59a --- /dev/null +++ b/src/kernel/types/task_link_browsers_params.py @@ -0,0 +1,18 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing_extensions import Required, TypedDict + +from .._types import SequenceNotStr + +__all__ = ["TaskLinkBrowsersParams"] + + +class TaskLinkBrowsersParams(TypedDict, total=False): + session_ids: Required[SequenceNotStr[str]] + """IDs of browsers to link. + + Each must belong to the task's project; deleted browsers can be linked. Browsers + already linked are ignored. A task can have at most 100 linked browsers. + """ diff --git a/src/kernel/types/task_list_params.py b/src/kernel/types/task_list_params.py new file mode 100644 index 00000000..3868b002 --- /dev/null +++ b/src/kernel/types/task_list_params.py @@ -0,0 +1,18 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing_extensions import TypedDict + +__all__ = ["TaskListParams"] + + +class TaskListParams(TypedDict, total=False): + limit: int + """Limit the number of tasks to return.""" + + offset: int + """Offset the number of tasks to return.""" + + session_id: str + """Only return tasks linked to this browser ID.""" diff --git a/src/kernel/types/task_metadata.py b/src/kernel/types/task_metadata.py new file mode 100644 index 00000000..f7c4116e --- /dev/null +++ b/src/kernel/types/task_metadata.py @@ -0,0 +1,8 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Dict +from typing_extensions import TypeAlias + +__all__ = ["TaskMetadata"] + +TaskMetadata: TypeAlias = Dict[str, str] diff --git a/src/kernel/types/task_metadata_param.py b/src/kernel/types/task_metadata_param.py new file mode 100644 index 00000000..c7fe6c38 --- /dev/null +++ b/src/kernel/types/task_metadata_param.py @@ -0,0 +1,10 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Dict +from typing_extensions import TypeAlias + +__all__ = ["TaskMetadataParam"] + +TaskMetadataParam: TypeAlias = Dict[str, str] diff --git a/tests/api_resources/test_tasks.py b/tests/api_resources/test_tasks.py new file mode 100644 index 00000000..2ef81f1a --- /dev/null +++ b/tests/api_resources/test_tasks.py @@ -0,0 +1,376 @@ +# 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 kernel import Kernel, AsyncKernel +from tests.utils import assert_matches_type +from kernel.types import Task +from kernel._utils import parse_datetime +from kernel.pagination import SyncOffsetPagination, AsyncOffsetPagination + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestTasks: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_create(self, client: Kernel) -> None: + task = client.tasks.create( + description="Book a hotel room for two nights", + ) + assert_matches_type(Task, task, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_create_with_all_params(self, client: Kernel) -> None: + task = client.tasks.create( + description="Book a hotel room for two nights", + metadata={ + "user_id": "user_123", + "thread_id": "thread_456", + }, + session_ids=["x"], + started_at=parse_datetime("2019-12-27T18:11:19.117Z"), + target_website="booking.com", + ) + assert_matches_type(Task, task, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_raw_response_create(self, client: Kernel) -> None: + response = client.tasks.with_raw_response.create( + description="Book a hotel room for two nights", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + task = response.parse() + assert_matches_type(Task, task, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_streaming_response_create(self, client: Kernel) -> None: + with client.tasks.with_streaming_response.create( + description="Book a hotel room for two nights", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + task = response.parse() + assert_matches_type(Task, task, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_retrieve(self, client: Kernel) -> None: + task = client.tasks.retrieve( + "id", + ) + assert_matches_type(Task, task, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_raw_response_retrieve(self, client: Kernel) -> None: + response = client.tasks.with_raw_response.retrieve( + "id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + task = response.parse() + assert_matches_type(Task, task, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_streaming_response_retrieve(self, client: Kernel) -> None: + with client.tasks.with_streaming_response.retrieve( + "id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + task = response.parse() + assert_matches_type(Task, task, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_path_params_retrieve(self, client: Kernel) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): + client.tasks.with_raw_response.retrieve( + "", + ) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_list(self, client: Kernel) -> None: + task = client.tasks.list() + assert_matches_type(SyncOffsetPagination[Task], task, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_list_with_all_params(self, client: Kernel) -> None: + task = client.tasks.list( + limit=1, + offset=0, + session_id="session_id", + ) + assert_matches_type(SyncOffsetPagination[Task], task, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_raw_response_list(self, client: Kernel) -> None: + response = client.tasks.with_raw_response.list() + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + task = response.parse() + assert_matches_type(SyncOffsetPagination[Task], task, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_streaming_response_list(self, client: Kernel) -> None: + with client.tasks.with_streaming_response.list() as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + task = response.parse() + assert_matches_type(SyncOffsetPagination[Task], task, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_link_browsers(self, client: Kernel) -> None: + task = client.tasks.link_browsers( + id="id", + session_ids=["x"], + ) + assert_matches_type(Task, task, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_raw_response_link_browsers(self, client: Kernel) -> None: + response = client.tasks.with_raw_response.link_browsers( + id="id", + session_ids=["x"], + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + task = response.parse() + assert_matches_type(Task, task, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_streaming_response_link_browsers(self, client: Kernel) -> None: + with client.tasks.with_streaming_response.link_browsers( + id="id", + session_ids=["x"], + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + task = response.parse() + assert_matches_type(Task, task, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_path_params_link_browsers(self, client: Kernel) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): + client.tasks.with_raw_response.link_browsers( + id="", + session_ids=["x"], + ) + + +class TestAsyncTasks: + parametrize = pytest.mark.parametrize( + "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"] + ) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_create(self, async_client: AsyncKernel) -> None: + task = await async_client.tasks.create( + description="Book a hotel room for two nights", + ) + assert_matches_type(Task, task, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_create_with_all_params(self, async_client: AsyncKernel) -> None: + task = await async_client.tasks.create( + description="Book a hotel room for two nights", + metadata={ + "user_id": "user_123", + "thread_id": "thread_456", + }, + session_ids=["x"], + started_at=parse_datetime("2019-12-27T18:11:19.117Z"), + target_website="booking.com", + ) + assert_matches_type(Task, task, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_raw_response_create(self, async_client: AsyncKernel) -> None: + response = await async_client.tasks.with_raw_response.create( + description="Book a hotel room for two nights", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + task = await response.parse() + assert_matches_type(Task, task, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_streaming_response_create(self, async_client: AsyncKernel) -> None: + async with async_client.tasks.with_streaming_response.create( + description="Book a hotel room for two nights", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + task = await response.parse() + assert_matches_type(Task, task, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_retrieve(self, async_client: AsyncKernel) -> None: + task = await async_client.tasks.retrieve( + "id", + ) + assert_matches_type(Task, task, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_raw_response_retrieve(self, async_client: AsyncKernel) -> None: + response = await async_client.tasks.with_raw_response.retrieve( + "id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + task = await response.parse() + assert_matches_type(Task, task, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_streaming_response_retrieve(self, async_client: AsyncKernel) -> None: + async with async_client.tasks.with_streaming_response.retrieve( + "id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + task = await response.parse() + assert_matches_type(Task, task, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_path_params_retrieve(self, async_client: AsyncKernel) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): + await async_client.tasks.with_raw_response.retrieve( + "", + ) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_list(self, async_client: AsyncKernel) -> None: + task = await async_client.tasks.list() + assert_matches_type(AsyncOffsetPagination[Task], task, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_list_with_all_params(self, async_client: AsyncKernel) -> None: + task = await async_client.tasks.list( + limit=1, + offset=0, + session_id="session_id", + ) + assert_matches_type(AsyncOffsetPagination[Task], task, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_raw_response_list(self, async_client: AsyncKernel) -> None: + response = await async_client.tasks.with_raw_response.list() + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + task = await response.parse() + assert_matches_type(AsyncOffsetPagination[Task], task, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_streaming_response_list(self, async_client: AsyncKernel) -> None: + async with async_client.tasks.with_streaming_response.list() as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + task = await response.parse() + assert_matches_type(AsyncOffsetPagination[Task], task, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_link_browsers(self, async_client: AsyncKernel) -> None: + task = await async_client.tasks.link_browsers( + id="id", + session_ids=["x"], + ) + assert_matches_type(Task, task, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_raw_response_link_browsers(self, async_client: AsyncKernel) -> None: + response = await async_client.tasks.with_raw_response.link_browsers( + id="id", + session_ids=["x"], + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + task = await response.parse() + assert_matches_type(Task, task, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_streaming_response_link_browsers(self, async_client: AsyncKernel) -> None: + async with async_client.tasks.with_streaming_response.link_browsers( + id="id", + session_ids=["x"], + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + task = await response.parse() + assert_matches_type(Task, task, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_path_params_link_browsers(self, async_client: AsyncKernel) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): + await async_client.tasks.with_raw_response.link_browsers( + id="", + session_ids=["x"], + ) From 0c8d11c5f62aa2ddd7e663e87d31267ef4364390 Mon Sep 17 00:00:00 2001 From: "kernel-internal[bot]" <260533166+kernel-internal[bot]@users.noreply.github.com> Date: Mon, 16 Nov 2026 22:23:56 +0000 Subject: [PATCH 4/6] feat: Add reports API and report type discovery Stainless-Generated-From: 5db3763ceae6c253f41f82161819fb056c222fa0 --- .stats.yml | 2 +- api.md | 39 ++ src/kernel/_client.py | 88 ++++ src/kernel/resources/__init__.py | 28 ++ src/kernel/resources/report_types/__init__.py | 33 ++ .../resources/report_types/report_types.py | 327 +++++++++++++ src/kernel/resources/report_types/versions.py | 170 +++++++ src/kernel/resources/reports.py | 457 ++++++++++++++++++ src/kernel/types/__init__.py | 7 + src/kernel/types/report.py | 39 ++ src/kernel/types/report_create_params.py | 49 ++ src/kernel/types/report_list_params.py | 21 + src/kernel/types/report_type.py | 39 ++ src/kernel/types/report_type_list_params.py | 18 + src/kernel/types/report_type_summary.py | 25 + .../types/report_type_version_summary.py | 19 + src/kernel/types/report_types/__init__.py | 5 + .../types/report_types/report_type_version.py | 32 ++ tests/api_resources/report_types/__init__.py | 1 + .../report_types/test_versions.py | 116 +++++ tests/api_resources/test_report_types.py | 197 ++++++++ tests/api_resources/test_reports.py | 330 +++++++++++++ 22 files changed, 2041 insertions(+), 1 deletion(-) create mode 100644 src/kernel/resources/report_types/__init__.py create mode 100644 src/kernel/resources/report_types/report_types.py create mode 100644 src/kernel/resources/report_types/versions.py create mode 100644 src/kernel/resources/reports.py create mode 100644 src/kernel/types/report.py create mode 100644 src/kernel/types/report_create_params.py create mode 100644 src/kernel/types/report_list_params.py create mode 100644 src/kernel/types/report_type.py create mode 100644 src/kernel/types/report_type_list_params.py create mode 100644 src/kernel/types/report_type_summary.py create mode 100644 src/kernel/types/report_type_version_summary.py create mode 100644 src/kernel/types/report_types/__init__.py create mode 100644 src/kernel/types/report_types/report_type_version.py create mode 100644 tests/api_resources/report_types/__init__.py create mode 100644 tests/api_resources/report_types/test_versions.py create mode 100644 tests/api_resources/test_report_types.py create mode 100644 tests/api_resources/test_reports.py diff --git a/.stats.yml b/.stats.yml index 83b7ea96..a4bdf76d 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1 +1 @@ -configured_endpoints: 183 +configured_endpoints: 189 diff --git a/api.md b/api.md index 26ca093d..be6a4d65 100644 --- a/api.md +++ b/api.md @@ -440,6 +440,45 @@ Methods: - client.tasks.list(\*\*params) -> SyncOffsetPagination[Task] - client.tasks.link_browsers(id, \*\*params) -> Task +# Reports + +Types: + +```python +from kernel.types import Report +``` + +Methods: + +- client.reports.create(\*\*params) -> Report +- client.reports.retrieve(id) -> Report +- client.reports.list(\*\*params) -> SyncOffsetPagination[Report] + +# ReportTypes + +Types: + +```python +from kernel.types import ReportType, ReportTypeSummary, ReportTypeVersionSummary +``` + +Methods: + +- client.report_types.retrieve(type) -> ReportType +- client.report_types.list(\*\*params) -> SyncOffsetPagination[ReportTypeSummary] + +## Versions + +Types: + +```python +from kernel.types.report_types import ReportTypeVersion +``` + +Methods: + +- client.report_types.versions.retrieve(version, \*, type) -> ReportTypeVersion + # Auth ## Context diff --git a/src/kernel/_client.py b/src/kernel/_client.py index ba0a733f..e25ec71a 100644 --- a/src/kernel/_client.py +++ b/src/kernel/_client.py @@ -61,6 +61,7 @@ search, vaults, proxies, + reports, api_keys, browsers, profiles, @@ -73,6 +74,7 @@ deployments, invocations, organization, + report_types, browser_pools, config_registry, credential_providers, @@ -81,6 +83,7 @@ from .resources.apps import AppsResource, AsyncAppsResource from .resources.tasks import TasksResource, AsyncTasksResource from .resources.proxies import ProxiesResource, AsyncProxiesResource + from .resources.reports import ReportsResource, AsyncReportsResource from .resources.api_keys import APIKeysResource, AsyncAPIKeysResource from .resources.profiles import ProfilesResource, AsyncProfilesResource from .resources.auth.auth import AuthResource, AsyncAuthResource @@ -99,6 +102,7 @@ from .resources.audit_logs.audit_logs import AuditLogsResource, AsyncAuditLogsResource from .resources.vault_provider_configs import VaultProviderConfigsResource, AsyncVaultProviderConfigsResource from .resources.organization.organization import OrganizationResource, AsyncOrganizationResource + from .resources.report_types.report_types import ReportTypesResource, AsyncReportTypesResource from .resources.config_registry.config_registry import ConfigRegistryResource, AsyncConfigRegistryResource __all__ = [ @@ -273,6 +277,20 @@ def tasks(self) -> TasksResource: return TasksResource(self) + @cached_property + def reports(self) -> ReportsResource: + """Discover report types and submit typed reports against tasks.""" + from .resources.reports import ReportsResource + + return ReportsResource(self) + + @cached_property + def report_types(self) -> ReportTypesResource: + """Discover report types and submit typed reports against tasks.""" + from .resources.report_types import ReportTypesResource + + return ReportTypesResource(self) + @cached_property def auth(self) -> AuthResource: from .resources.auth import AuthResource @@ -696,6 +714,20 @@ def tasks(self) -> AsyncTasksResource: return AsyncTasksResource(self) + @cached_property + def reports(self) -> AsyncReportsResource: + """Discover report types and submit typed reports against tasks.""" + from .resources.reports import AsyncReportsResource + + return AsyncReportsResource(self) + + @cached_property + def report_types(self) -> AsyncReportTypesResource: + """Discover report types and submit typed reports against tasks.""" + from .resources.report_types import AsyncReportTypesResource + + return AsyncReportTypesResource(self) + @cached_property def auth(self) -> AsyncAuthResource: from .resources.auth import AsyncAuthResource @@ -1019,6 +1051,20 @@ def tasks(self) -> tasks.TasksResourceWithRawResponse: return TasksResourceWithRawResponse(self._client.tasks) + @cached_property + def reports(self) -> reports.ReportsResourceWithRawResponse: + """Discover report types and submit typed reports against tasks.""" + from .resources.reports import ReportsResourceWithRawResponse + + return ReportsResourceWithRawResponse(self._client.reports) + + @cached_property + def report_types(self) -> report_types.ReportTypesResourceWithRawResponse: + """Discover report types and submit typed reports against tasks.""" + from .resources.report_types import ReportTypesResourceWithRawResponse + + return ReportTypesResourceWithRawResponse(self._client.report_types) + @cached_property def auth(self) -> auth.AuthResourceWithRawResponse: from .resources.auth import AuthResourceWithRawResponse @@ -1174,6 +1220,20 @@ def tasks(self) -> tasks.AsyncTasksResourceWithRawResponse: return AsyncTasksResourceWithRawResponse(self._client.tasks) + @cached_property + def reports(self) -> reports.AsyncReportsResourceWithRawResponse: + """Discover report types and submit typed reports against tasks.""" + from .resources.reports import AsyncReportsResourceWithRawResponse + + return AsyncReportsResourceWithRawResponse(self._client.reports) + + @cached_property + def report_types(self) -> report_types.AsyncReportTypesResourceWithRawResponse: + """Discover report types and submit typed reports against tasks.""" + from .resources.report_types import AsyncReportTypesResourceWithRawResponse + + return AsyncReportTypesResourceWithRawResponse(self._client.report_types) + @cached_property def auth(self) -> auth.AsyncAuthResourceWithRawResponse: from .resources.auth import AsyncAuthResourceWithRawResponse @@ -1329,6 +1389,20 @@ def tasks(self) -> tasks.TasksResourceWithStreamingResponse: return TasksResourceWithStreamingResponse(self._client.tasks) + @cached_property + def reports(self) -> reports.ReportsResourceWithStreamingResponse: + """Discover report types and submit typed reports against tasks.""" + from .resources.reports import ReportsResourceWithStreamingResponse + + return ReportsResourceWithStreamingResponse(self._client.reports) + + @cached_property + def report_types(self) -> report_types.ReportTypesResourceWithStreamingResponse: + """Discover report types and submit typed reports against tasks.""" + from .resources.report_types import ReportTypesResourceWithStreamingResponse + + return ReportTypesResourceWithStreamingResponse(self._client.report_types) + @cached_property def auth(self) -> auth.AuthResourceWithStreamingResponse: from .resources.auth import AuthResourceWithStreamingResponse @@ -1484,6 +1558,20 @@ def tasks(self) -> tasks.AsyncTasksResourceWithStreamingResponse: return AsyncTasksResourceWithStreamingResponse(self._client.tasks) + @cached_property + def reports(self) -> reports.AsyncReportsResourceWithStreamingResponse: + """Discover report types and submit typed reports against tasks.""" + from .resources.reports import AsyncReportsResourceWithStreamingResponse + + return AsyncReportsResourceWithStreamingResponse(self._client.reports) + + @cached_property + def report_types(self) -> report_types.AsyncReportTypesResourceWithStreamingResponse: + """Discover report types and submit typed reports against tasks.""" + from .resources.report_types import AsyncReportTypesResourceWithStreamingResponse + + return AsyncReportTypesResourceWithStreamingResponse(self._client.report_types) + @cached_property def auth(self) -> auth.AsyncAuthResourceWithStreamingResponse: from .resources.auth import AsyncAuthResourceWithStreamingResponse diff --git a/src/kernel/resources/__init__.py b/src/kernel/resources/__init__.py index fdbbdf89..100f8646 100644 --- a/src/kernel/resources/__init__.py +++ b/src/kernel/resources/__init__.py @@ -48,6 +48,14 @@ ProxiesResourceWithStreamingResponse, AsyncProxiesResourceWithStreamingResponse, ) +from .reports import ( + ReportsResource, + AsyncReportsResource, + ReportsResourceWithRawResponse, + AsyncReportsResourceWithRawResponse, + ReportsResourceWithStreamingResponse, + AsyncReportsResourceWithStreamingResponse, +) from .api_keys import ( APIKeysResource, AsyncAPIKeysResource, @@ -144,6 +152,14 @@ OrganizationResourceWithStreamingResponse, AsyncOrganizationResourceWithStreamingResponse, ) +from .report_types import ( + ReportTypesResource, + AsyncReportTypesResource, + ReportTypesResourceWithRawResponse, + AsyncReportTypesResourceWithRawResponse, + ReportTypesResourceWithStreamingResponse, + AsyncReportTypesResourceWithStreamingResponse, +) from .browser_pools import ( BrowserPoolsResource, AsyncBrowserPoolsResource, @@ -220,6 +236,18 @@ "AsyncTasksResourceWithRawResponse", "TasksResourceWithStreamingResponse", "AsyncTasksResourceWithStreamingResponse", + "ReportsResource", + "AsyncReportsResource", + "ReportsResourceWithRawResponse", + "AsyncReportsResourceWithRawResponse", + "ReportsResourceWithStreamingResponse", + "AsyncReportsResourceWithStreamingResponse", + "ReportTypesResource", + "AsyncReportTypesResource", + "ReportTypesResourceWithRawResponse", + "AsyncReportTypesResourceWithRawResponse", + "ReportTypesResourceWithStreamingResponse", + "AsyncReportTypesResourceWithStreamingResponse", "AuthResource", "AsyncAuthResource", "AuthResourceWithRawResponse", diff --git a/src/kernel/resources/report_types/__init__.py b/src/kernel/resources/report_types/__init__.py new file mode 100644 index 00000000..bf8653f0 --- /dev/null +++ b/src/kernel/resources/report_types/__init__.py @@ -0,0 +1,33 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from .versions import ( + VersionsResource, + AsyncVersionsResource, + VersionsResourceWithRawResponse, + AsyncVersionsResourceWithRawResponse, + VersionsResourceWithStreamingResponse, + AsyncVersionsResourceWithStreamingResponse, +) +from .report_types import ( + ReportTypesResource, + AsyncReportTypesResource, + ReportTypesResourceWithRawResponse, + AsyncReportTypesResourceWithRawResponse, + ReportTypesResourceWithStreamingResponse, + AsyncReportTypesResourceWithStreamingResponse, +) + +__all__ = [ + "VersionsResource", + "AsyncVersionsResource", + "VersionsResourceWithRawResponse", + "AsyncVersionsResourceWithRawResponse", + "VersionsResourceWithStreamingResponse", + "AsyncVersionsResourceWithStreamingResponse", + "ReportTypesResource", + "AsyncReportTypesResource", + "ReportTypesResourceWithRawResponse", + "AsyncReportTypesResourceWithRawResponse", + "ReportTypesResourceWithStreamingResponse", + "AsyncReportTypesResourceWithStreamingResponse", +] diff --git a/src/kernel/resources/report_types/report_types.py b/src/kernel/resources/report_types/report_types.py new file mode 100644 index 00000000..a4085924 --- /dev/null +++ b/src/kernel/resources/report_types/report_types.py @@ -0,0 +1,327 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import httpx + +from ...types import report_type_list_params +from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given +from ..._utils import path_template, maybe_transform +from .versions import ( + VersionsResource, + AsyncVersionsResource, + VersionsResourceWithRawResponse, + AsyncVersionsResourceWithRawResponse, + VersionsResourceWithStreamingResponse, + AsyncVersionsResourceWithStreamingResponse, +) +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 ...pagination import SyncOffsetPagination, AsyncOffsetPagination +from ..._base_client import AsyncPaginator, make_request_options +from ...types.report_type import ReportType +from ...types.report_type_summary import ReportTypeSummary + +__all__ = ["ReportTypesResource", "AsyncReportTypesResource"] + + +class ReportTypesResource(SyncAPIResource): + """Discover report types and submit typed reports against tasks.""" + + @cached_property + def versions(self) -> VersionsResource: + """Discover report types and submit typed reports against tasks.""" + return VersionsResource(self._client) + + @cached_property + def with_raw_response(self) -> ReportTypesResourceWithRawResponse: + """ + 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/kernel/kernel-python-sdk#accessing-raw-response-data-eg-headers + """ + return ReportTypesResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> ReportTypesResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/kernel/kernel-python-sdk#with_streaming_response + """ + return ReportTypesResourceWithStreamingResponse(self) + + def retrieve( + self, + type: 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, + ) -> ReportType: + """ + Retrieve a report type, its versions, and the JSON Schema of its latest version. + + 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 type: + raise ValueError(f"Expected a non-empty value for `type` but received {type!r}") + return self._get( + path_template("/report_types/{type}", type=type), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=ReportType, + ) + + def list( + self, + *, + task_id: str, + limit: int | Omit = omit, + offset: int | Omit = omit, + # 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, + ) -> SyncOffsetPagination[ReportTypeSummary]: + """List the report types agents can submit for a task. + + Retrieve a type for the JSON + Schema of its data. + + Args: + task_id: Task the agent is finding a report type for. + + limit: Limit the number of report types to return. + + offset: Offset the number of report types to return. + + 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 + """ + return self._get_api_list( + "/report_types", + page=SyncOffsetPagination[ReportTypeSummary], + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + query=maybe_transform( + { + "task_id": task_id, + "limit": limit, + "offset": offset, + }, + report_type_list_params.ReportTypeListParams, + ), + ), + model=ReportTypeSummary, + ) + + +class AsyncReportTypesResource(AsyncAPIResource): + """Discover report types and submit typed reports against tasks.""" + + @cached_property + def versions(self) -> AsyncVersionsResource: + """Discover report types and submit typed reports against tasks.""" + return AsyncVersionsResource(self._client) + + @cached_property + def with_raw_response(self) -> AsyncReportTypesResourceWithRawResponse: + """ + 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/kernel/kernel-python-sdk#accessing-raw-response-data-eg-headers + """ + return AsyncReportTypesResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncReportTypesResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/kernel/kernel-python-sdk#with_streaming_response + """ + return AsyncReportTypesResourceWithStreamingResponse(self) + + async def retrieve( + self, + type: 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, + ) -> ReportType: + """ + Retrieve a report type, its versions, and the JSON Schema of its latest version. + + 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 type: + raise ValueError(f"Expected a non-empty value for `type` but received {type!r}") + return await self._get( + path_template("/report_types/{type}", type=type), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=ReportType, + ) + + def list( + self, + *, + task_id: str, + limit: int | Omit = omit, + offset: int | Omit = omit, + # 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, + ) -> AsyncPaginator[ReportTypeSummary, AsyncOffsetPagination[ReportTypeSummary]]: + """List the report types agents can submit for a task. + + Retrieve a type for the JSON + Schema of its data. + + Args: + task_id: Task the agent is finding a report type for. + + limit: Limit the number of report types to return. + + offset: Offset the number of report types to return. + + 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 + """ + return self._get_api_list( + "/report_types", + page=AsyncOffsetPagination[ReportTypeSummary], + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + query=maybe_transform( + { + "task_id": task_id, + "limit": limit, + "offset": offset, + }, + report_type_list_params.ReportTypeListParams, + ), + ), + model=ReportTypeSummary, + ) + + +class ReportTypesResourceWithRawResponse: + def __init__(self, report_types: ReportTypesResource) -> None: + self._report_types = report_types + + self.retrieve = to_raw_response_wrapper( + report_types.retrieve, + ) + self.list = to_raw_response_wrapper( + report_types.list, + ) + + @cached_property + def versions(self) -> VersionsResourceWithRawResponse: + """Discover report types and submit typed reports against tasks.""" + return VersionsResourceWithRawResponse(self._report_types.versions) + + +class AsyncReportTypesResourceWithRawResponse: + def __init__(self, report_types: AsyncReportTypesResource) -> None: + self._report_types = report_types + + self.retrieve = async_to_raw_response_wrapper( + report_types.retrieve, + ) + self.list = async_to_raw_response_wrapper( + report_types.list, + ) + + @cached_property + def versions(self) -> AsyncVersionsResourceWithRawResponse: + """Discover report types and submit typed reports against tasks.""" + return AsyncVersionsResourceWithRawResponse(self._report_types.versions) + + +class ReportTypesResourceWithStreamingResponse: + def __init__(self, report_types: ReportTypesResource) -> None: + self._report_types = report_types + + self.retrieve = to_streamed_response_wrapper( + report_types.retrieve, + ) + self.list = to_streamed_response_wrapper( + report_types.list, + ) + + @cached_property + def versions(self) -> VersionsResourceWithStreamingResponse: + """Discover report types and submit typed reports against tasks.""" + return VersionsResourceWithStreamingResponse(self._report_types.versions) + + +class AsyncReportTypesResourceWithStreamingResponse: + def __init__(self, report_types: AsyncReportTypesResource) -> None: + self._report_types = report_types + + self.retrieve = async_to_streamed_response_wrapper( + report_types.retrieve, + ) + self.list = async_to_streamed_response_wrapper( + report_types.list, + ) + + @cached_property + def versions(self) -> AsyncVersionsResourceWithStreamingResponse: + """Discover report types and submit typed reports against tasks.""" + return AsyncVersionsResourceWithStreamingResponse(self._report_types.versions) diff --git a/src/kernel/resources/report_types/versions.py b/src/kernel/resources/report_types/versions.py new file mode 100644 index 00000000..bd9b6394 --- /dev/null +++ b/src/kernel/resources/report_types/versions.py @@ -0,0 +1,170 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import httpx + +from ..._types import Body, Query, Headers, NotGiven, not_given +from ..._utils import path_template +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 ..._base_client import make_request_options +from ...types.report_types.report_type_version import ReportTypeVersion + +__all__ = ["VersionsResource", "AsyncVersionsResource"] + + +class VersionsResource(SyncAPIResource): + """Discover report types and submit typed reports against tasks.""" + + @cached_property + def with_raw_response(self) -> VersionsResourceWithRawResponse: + """ + 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/kernel/kernel-python-sdk#accessing-raw-response-data-eg-headers + """ + return VersionsResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> VersionsResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/kernel/kernel-python-sdk#with_streaming_response + """ + return VersionsResourceWithStreamingResponse(self) + + def retrieve( + self, + version: int, + *, + type: 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, + ) -> ReportTypeVersion: + """ + Retrieve one schema version of a report type, including retired versions. + + 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 type: + raise ValueError(f"Expected a non-empty value for `type` but received {type!r}") + return self._get( + path_template("/report_types/{type}/versions/{version}", type=type, version=version), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=ReportTypeVersion, + ) + + +class AsyncVersionsResource(AsyncAPIResource): + """Discover report types and submit typed reports against tasks.""" + + @cached_property + def with_raw_response(self) -> AsyncVersionsResourceWithRawResponse: + """ + 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/kernel/kernel-python-sdk#accessing-raw-response-data-eg-headers + """ + return AsyncVersionsResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncVersionsResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/kernel/kernel-python-sdk#with_streaming_response + """ + return AsyncVersionsResourceWithStreamingResponse(self) + + async def retrieve( + self, + version: int, + *, + type: 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, + ) -> ReportTypeVersion: + """ + Retrieve one schema version of a report type, including retired versions. + + 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 type: + raise ValueError(f"Expected a non-empty value for `type` but received {type!r}") + return await self._get( + path_template("/report_types/{type}/versions/{version}", type=type, version=version), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=ReportTypeVersion, + ) + + +class VersionsResourceWithRawResponse: + def __init__(self, versions: VersionsResource) -> None: + self._versions = versions + + self.retrieve = to_raw_response_wrapper( + versions.retrieve, + ) + + +class AsyncVersionsResourceWithRawResponse: + def __init__(self, versions: AsyncVersionsResource) -> None: + self._versions = versions + + self.retrieve = async_to_raw_response_wrapper( + versions.retrieve, + ) + + +class VersionsResourceWithStreamingResponse: + def __init__(self, versions: VersionsResource) -> None: + self._versions = versions + + self.retrieve = to_streamed_response_wrapper( + versions.retrieve, + ) + + +class AsyncVersionsResourceWithStreamingResponse: + def __init__(self, versions: AsyncVersionsResource) -> None: + self._versions = versions + + self.retrieve = async_to_streamed_response_wrapper( + versions.retrieve, + ) diff --git a/src/kernel/resources/reports.py b/src/kernel/resources/reports.py new file mode 100644 index 00000000..46c68809 --- /dev/null +++ b/src/kernel/resources/reports.py @@ -0,0 +1,457 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Dict, Union +from datetime import datetime + +import httpx + +from ..types import report_list_params, report_create_params +from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given +from .._utils import path_template, 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 ..pagination import SyncOffsetPagination, AsyncOffsetPagination +from .._base_client import AsyncPaginator, make_request_options +from ..types.report import Report + +__all__ = ["ReportsResource", "AsyncReportsResource"] + + +class ReportsResource(SyncAPIResource): + """Discover report types and submit typed reports against tasks.""" + + @cached_property + def with_raw_response(self) -> ReportsResourceWithRawResponse: + """ + 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/kernel/kernel-python-sdk#accessing-raw-response-data-eg-headers + """ + return ReportsResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> ReportsResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/kernel/kernel-python-sdk#with_streaming_response + """ + return ReportsResourceWithStreamingResponse(self) + + def create( + self, + *, + data: Dict[str, object], + task_id: str, + type: str, + occurred_at: Union[str, datetime] | Omit = omit, + schema_version: int | Omit = omit, + session_id: str | Omit = omit, + # 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, + idempotency_key: str | None = None, + ) -> Report: + """Submit a typed report against a task. + + The data is validated against the report + type's schema; a validation failure returns 400 with one detail per invalid + field. A task can have at most 500 reports. + + Args: + data: Report data. It must match the schema of the report type's version and encode to + at most 16 KB of JSON. + + task_id: ID of the task to report against. + + type: Report type name. List report types to see the available types and their + schemas. + + occurred_at: When the reported event happened. Defaults to the time the report is submitted. + Must be no more than 5 minutes in the future or 30 days in the past. + + schema_version: Version of the report type's schema to validate data against. Defaults to the + type's latest version, which the response returns. + + session_id: ID of the browser the report was observed in. It must belong to the task's + project; deleted browsers are accepted. The browser is linked to the task if it + is not already. + + 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 + + idempotency_key: Specify a custom idempotency key for this request + """ + return self._post( + "/reports", + body=maybe_transform( + { + "data": data, + "task_id": task_id, + "type": type, + "occurred_at": occurred_at, + "schema_version": schema_version, + "session_id": session_id, + }, + report_create_params.ReportCreateParams, + ), + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + idempotency_key=idempotency_key, + ), + cast_to=Report, + ) + + def retrieve( + self, + id: 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, + ) -> Report: + """ + Retrieve a report. + + 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 id: + raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + return self._get( + path_template("/reports/{id}", id=id), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=Report, + ) + + def list( + self, + *, + task_id: str, + limit: int | Omit = omit, + offset: int | Omit = omit, + type: str | Omit = omit, + # 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, + ) -> SyncOffsetPagination[Report]: + """ + List a task's reports in the order they were submitted, oldest first. + + Args: + task_id: Task whose reports to list. + + limit: Limit the number of reports to return. + + offset: Offset the number of reports to return. + + type: Only return reports of this type. + + 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 + """ + return self._get_api_list( + "/reports", + page=SyncOffsetPagination[Report], + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + query=maybe_transform( + { + "task_id": task_id, + "limit": limit, + "offset": offset, + "type": type, + }, + report_list_params.ReportListParams, + ), + ), + model=Report, + ) + + +class AsyncReportsResource(AsyncAPIResource): + """Discover report types and submit typed reports against tasks.""" + + @cached_property + def with_raw_response(self) -> AsyncReportsResourceWithRawResponse: + """ + 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/kernel/kernel-python-sdk#accessing-raw-response-data-eg-headers + """ + return AsyncReportsResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncReportsResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/kernel/kernel-python-sdk#with_streaming_response + """ + return AsyncReportsResourceWithStreamingResponse(self) + + async def create( + self, + *, + data: Dict[str, object], + task_id: str, + type: str, + occurred_at: Union[str, datetime] | Omit = omit, + schema_version: int | Omit = omit, + session_id: str | Omit = omit, + # 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, + idempotency_key: str | None = None, + ) -> Report: + """Submit a typed report against a task. + + The data is validated against the report + type's schema; a validation failure returns 400 with one detail per invalid + field. A task can have at most 500 reports. + + Args: + data: Report data. It must match the schema of the report type's version and encode to + at most 16 KB of JSON. + + task_id: ID of the task to report against. + + type: Report type name. List report types to see the available types and their + schemas. + + occurred_at: When the reported event happened. Defaults to the time the report is submitted. + Must be no more than 5 minutes in the future or 30 days in the past. + + schema_version: Version of the report type's schema to validate data against. Defaults to the + type's latest version, which the response returns. + + session_id: ID of the browser the report was observed in. It must belong to the task's + project; deleted browsers are accepted. The browser is linked to the task if it + is not already. + + 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 + + idempotency_key: Specify a custom idempotency key for this request + """ + return await self._post( + "/reports", + body=await async_maybe_transform( + { + "data": data, + "task_id": task_id, + "type": type, + "occurred_at": occurred_at, + "schema_version": schema_version, + "session_id": session_id, + }, + report_create_params.ReportCreateParams, + ), + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + idempotency_key=idempotency_key, + ), + cast_to=Report, + ) + + async def retrieve( + self, + id: 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, + ) -> Report: + """ + Retrieve a report. + + 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 id: + raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + return await self._get( + path_template("/reports/{id}", id=id), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=Report, + ) + + def list( + self, + *, + task_id: str, + limit: int | Omit = omit, + offset: int | Omit = omit, + type: str | Omit = omit, + # 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, + ) -> AsyncPaginator[Report, AsyncOffsetPagination[Report]]: + """ + List a task's reports in the order they were submitted, oldest first. + + Args: + task_id: Task whose reports to list. + + limit: Limit the number of reports to return. + + offset: Offset the number of reports to return. + + type: Only return reports of this type. + + 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 + """ + return self._get_api_list( + "/reports", + page=AsyncOffsetPagination[Report], + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + query=maybe_transform( + { + "task_id": task_id, + "limit": limit, + "offset": offset, + "type": type, + }, + report_list_params.ReportListParams, + ), + ), + model=Report, + ) + + +class ReportsResourceWithRawResponse: + def __init__(self, reports: ReportsResource) -> None: + self._reports = reports + + self.create = to_raw_response_wrapper( + reports.create, + ) + self.retrieve = to_raw_response_wrapper( + reports.retrieve, + ) + self.list = to_raw_response_wrapper( + reports.list, + ) + + +class AsyncReportsResourceWithRawResponse: + def __init__(self, reports: AsyncReportsResource) -> None: + self._reports = reports + + self.create = async_to_raw_response_wrapper( + reports.create, + ) + self.retrieve = async_to_raw_response_wrapper( + reports.retrieve, + ) + self.list = async_to_raw_response_wrapper( + reports.list, + ) + + +class ReportsResourceWithStreamingResponse: + def __init__(self, reports: ReportsResource) -> None: + self._reports = reports + + self.create = to_streamed_response_wrapper( + reports.create, + ) + self.retrieve = to_streamed_response_wrapper( + reports.retrieve, + ) + self.list = to_streamed_response_wrapper( + reports.list, + ) + + +class AsyncReportsResourceWithStreamingResponse: + def __init__(self, reports: AsyncReportsResource) -> None: + self._reports = reports + + self.create = async_to_streamed_response_wrapper( + reports.create, + ) + self.retrieve = async_to_streamed_response_wrapper( + reports.retrieve, + ) + self.list = async_to_streamed_response_wrapper( + reports.list, + ) diff --git a/src/kernel/types/__init__.py b/src/kernel/types/__init__.py index 2a4e2e02..507d0f2a 100644 --- a/src/kernel/types/__init__.py +++ b/src/kernel/types/__init__.py @@ -9,6 +9,7 @@ from .proxy import Proxy as Proxy from .usage import Usage as Usage from .vault import Vault as Vault +from .report import Report as Report from .result import Result as Result from .search import Search as Search from .shared import ( @@ -34,6 +35,7 @@ from .proxy_ip import ProxyIP as ProxyIP from .credential import Credential as Credential from .tags_param import TagsParam as TagsParam +from .report_type import ReportType as ReportType from .browser_pool import BrowserPool as BrowserPool from .browser_proxy import BrowserProxy as BrowserProxy from .browser_usage import BrowserUsage as BrowserUsage @@ -57,6 +59,7 @@ from .vault_list_params import VaultListParams as VaultListParams from .browser_proxy_mode import BrowserProxyMode as BrowserProxyMode from .proxy_check_params import ProxyCheckParams as ProxyCheckParams +from .report_list_params import ReportListParams as ReportListParams from .task_create_params import TaskCreateParams as TaskCreateParams from .api_key_list_params import APIKeyListParams as APIKeyListParams from .browser_curl_params import BrowserCurlParams as BrowserCurlParams @@ -69,6 +72,7 @@ from .proxy_create_params import ProxyCreateParams as ProxyCreateParams from .proxy_list_response import ProxyListResponse as ProxyListResponse from .proxy_update_params import ProxyUpdateParams as ProxyUpdateParams +from .report_type_summary import ReportTypeSummary as ReportTypeSummary from .task_metadata_param import TaskMetadataParam as TaskMetadataParam from .vault_upsert_params import VaultUpsertParams as VaultUpsertParams from .browser_proxy_config import BrowserProxyConfig as BrowserProxyConfig @@ -76,6 +80,7 @@ from .browser_video_memory import BrowserVideoMemory as BrowserVideoMemory from .proxy_check_response import ProxyCheckResponse as ProxyCheckResponse from .proxy_ip_list_params import ProxyIPListParams as ProxyIPListParams +from .report_create_params import ReportCreateParams as ReportCreateParams from .search_create_params import SearchCreateParams as SearchCreateParams from .vault_encryption_key import VaultEncryptionKey as VaultEncryptionKey from .api_key_create_params import APIKeyCreateParams as APIKeyCreateParams @@ -116,6 +121,7 @@ from .extension_upload_params import ExtensionUploadParams as ExtensionUploadParams from .profile_download_params import ProfileDownloadParams as ProfileDownloadParams from .proxy_retrieve_response import ProxyRetrieveResponse as ProxyRetrieveResponse +from .report_type_list_params import ReportTypeListParams as ReportTypeListParams from .browser_pool_list_params import BrowserPoolListParams as BrowserPoolListParams from .config_registry_response import ConfigRegistryResponse as ConfigRegistryResponse from .credential_create_params import CredentialCreateParams as CredentialCreateParams @@ -147,6 +153,7 @@ from .browser_pool_release_params import BrowserPoolReleaseParams as BrowserPoolReleaseParams from .browser_save_profile_params import BrowserSaveProfileParams as BrowserSaveProfileParams from .config_registry_list_params import ConfigRegistryListParams as ConfigRegistryListParams +from .report_type_version_summary import ReportTypeVersionSummary as ReportTypeVersionSummary from .browser_network_config_param import BrowserNetworkConfigParam as BrowserNetworkConfigParam from .browser_network_update_param import BrowserNetworkUpdateParam as BrowserNetworkUpdateParam from .deployment_retrieve_response import DeploymentRetrieveResponse as DeploymentRetrieveResponse diff --git a/src/kernel/types/report.py b/src/kernel/types/report.py new file mode 100644 index 00000000..27a9bc90 --- /dev/null +++ b/src/kernel/types/report.py @@ -0,0 +1,39 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Dict, Optional +from datetime import datetime + +from .._models import BaseModel + +__all__ = ["Report"] + + +class Report(BaseModel): + """A typed, schema-validated report an agent submitted against a task. + + Reports are immutable. + """ + + id: str + """Unique identifier for the report""" + + created_at: datetime + """When the report was submitted""" + + data: Dict[str, object] + """Report data, matching the report type's schema""" + + occurred_at: datetime + """When the reported event happened""" + + schema_version: int + """Version of the report type's schema that data was validated against""" + + task_id: str + """ID of the task the report belongs to""" + + type: str + """Report type name""" + + session_id: Optional[str] = None + """ID of the browser the report was observed in, if any""" diff --git a/src/kernel/types/report_create_params.py b/src/kernel/types/report_create_params.py new file mode 100644 index 00000000..a6e98230 --- /dev/null +++ b/src/kernel/types/report_create_params.py @@ -0,0 +1,49 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Dict, Union +from datetime import datetime +from typing_extensions import Required, Annotated, TypedDict + +from .._utils import PropertyInfo + +__all__ = ["ReportCreateParams"] + + +class ReportCreateParams(TypedDict, total=False): + data: Required[Dict[str, object]] + """Report data. + + It must match the schema of the report type's version and encode to at most 16 + KB of JSON. + """ + + task_id: Required[str] + """ID of the task to report against.""" + + type: Required[str] + """Report type name. + + List report types to see the available types and their schemas. + """ + + occurred_at: Annotated[Union[str, datetime], PropertyInfo(format="iso8601")] + """When the reported event happened. + + Defaults to the time the report is submitted. Must be no more than 5 minutes in + the future or 30 days in the past. + """ + + schema_version: int + """Version of the report type's schema to validate data against. + + Defaults to the type's latest version, which the response returns. + """ + + session_id: str + """ID of the browser the report was observed in. + + It must belong to the task's project; deleted browsers are accepted. The browser + is linked to the task if it is not already. + """ diff --git a/src/kernel/types/report_list_params.py b/src/kernel/types/report_list_params.py new file mode 100644 index 00000000..15858914 --- /dev/null +++ b/src/kernel/types/report_list_params.py @@ -0,0 +1,21 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing_extensions import Required, TypedDict + +__all__ = ["ReportListParams"] + + +class ReportListParams(TypedDict, total=False): + task_id: Required[str] + """Task whose reports to list.""" + + limit: int + """Limit the number of reports to return.""" + + offset: int + """Offset the number of reports to return.""" + + type: str + """Only return reports of this type.""" diff --git a/src/kernel/types/report_type.py b/src/kernel/types/report_type.py new file mode 100644 index 00000000..27111f3c --- /dev/null +++ b/src/kernel/types/report_type.py @@ -0,0 +1,39 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Dict, List, Optional + +from pydantic import Field as FieldInfo + +from .._models import BaseModel +from .report_type_version_summary import ReportTypeVersionSummary + +__all__ = ["ReportType"] + + +class ReportType(BaseModel): + """ + A kind of report agents can submit against a task, with its versions and the JSON Schema of its latest version. A shipped version never changes; changes ship as new versions. + """ + + description: str + """What the report type records and when to submit it""" + + latest_version: int + """Highest version that is not retired. + + A report submitted without a schema_version uses this version. It is 0 when + every version is retired. + """ + + schema_: Optional[Dict[str, object]] = FieldInfo(alias="schema", default=None) + """ + JSON Schema (draft 2020-12) of the latest version, which a report's data must + match. Its field descriptions and examples describe what to send. Null when + every version is retired. + """ + + type: str + """Report type name, such as task.result""" + + versions: List[ReportTypeVersionSummary] + """Every version of the type, oldest first, including retired versions.""" diff --git a/src/kernel/types/report_type_list_params.py b/src/kernel/types/report_type_list_params.py new file mode 100644 index 00000000..aa46ee1f --- /dev/null +++ b/src/kernel/types/report_type_list_params.py @@ -0,0 +1,18 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing_extensions import Required, TypedDict + +__all__ = ["ReportTypeListParams"] + + +class ReportTypeListParams(TypedDict, total=False): + task_id: Required[str] + """Task the agent is finding a report type for.""" + + limit: int + """Limit the number of report types to return.""" + + offset: int + """Offset the number of report types to return.""" diff --git a/src/kernel/types/report_type_summary.py b/src/kernel/types/report_type_summary.py new file mode 100644 index 00000000..3772ecbb --- /dev/null +++ b/src/kernel/types/report_type_summary.py @@ -0,0 +1,25 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from .._models import BaseModel + +__all__ = ["ReportTypeSummary"] + + +class ReportTypeSummary(BaseModel): + """A kind of report agents can submit against a task. + + Retrieve the type for the JSON Schema of its data. + """ + + description: str + """What the report type records and when to submit it""" + + latest_version: int + """Highest version that is not retired. + + A report submitted without a schema_version uses this version. It is 0 when + every version is retired. + """ + + type: str + """Report type name, such as task.result""" diff --git a/src/kernel/types/report_type_version_summary.py b/src/kernel/types/report_type_version_summary.py new file mode 100644 index 00000000..995b2e9f --- /dev/null +++ b/src/kernel/types/report_type_version_summary.py @@ -0,0 +1,19 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from .._models import BaseModel + +__all__ = ["ReportTypeVersionSummary"] + + +class ReportTypeVersionSummary(BaseModel): + """One schema version of a report type, without its schema.""" + + retired: bool + """Whether the version is retired. + + Retired versions are no longer accepted for new reports; existing reports keep + them. + """ + + version: int + """Schema version number, starting at 1.""" diff --git a/src/kernel/types/report_types/__init__.py b/src/kernel/types/report_types/__init__.py new file mode 100644 index 00000000..56137aa9 --- /dev/null +++ b/src/kernel/types/report_types/__init__.py @@ -0,0 +1,5 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from .report_type_version import ReportTypeVersion as ReportTypeVersion diff --git a/src/kernel/types/report_types/report_type_version.py b/src/kernel/types/report_types/report_type_version.py new file mode 100644 index 00000000..dc163f53 --- /dev/null +++ b/src/kernel/types/report_types/report_type_version.py @@ -0,0 +1,32 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Dict + +from pydantic import Field as FieldInfo + +from ..._models import BaseModel + +__all__ = ["ReportTypeVersion"] + + +class ReportTypeVersion(BaseModel): + """One immutable schema version of a report type.""" + + retired: bool + """Whether the version is retired. + + Retired versions are no longer accepted for new reports; existing reports keep + them. + """ + + schema_: Dict[str, object] = FieldInfo(alias="schema") + """JSON Schema (draft 2020-12) that a report's data must match. + + Its field descriptions and examples describe what to send. + """ + + type: str + """Report type name, such as task.result""" + + version: int + """Schema version number, starting at 1.""" diff --git a/tests/api_resources/report_types/__init__.py b/tests/api_resources/report_types/__init__.py new file mode 100644 index 00000000..fd8019a9 --- /dev/null +++ b/tests/api_resources/report_types/__init__.py @@ -0,0 +1 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. diff --git a/tests/api_resources/report_types/test_versions.py b/tests/api_resources/report_types/test_versions.py new file mode 100644 index 00000000..4de06c06 --- /dev/null +++ b/tests/api_resources/report_types/test_versions.py @@ -0,0 +1,116 @@ +# 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 kernel import Kernel, AsyncKernel +from tests.utils import assert_matches_type +from kernel.types.report_types import ReportTypeVersion + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestVersions: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_retrieve(self, client: Kernel) -> None: + version = client.report_types.versions.retrieve( + version=0, + type="type", + ) + assert_matches_type(ReportTypeVersion, version, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_raw_response_retrieve(self, client: Kernel) -> None: + response = client.report_types.versions.with_raw_response.retrieve( + version=0, + type="type", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + version = response.parse() + assert_matches_type(ReportTypeVersion, version, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_streaming_response_retrieve(self, client: Kernel) -> None: + with client.report_types.versions.with_streaming_response.retrieve( + version=0, + type="type", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + version = response.parse() + assert_matches_type(ReportTypeVersion, version, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_path_params_retrieve(self, client: Kernel) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `type` but received ''"): + client.report_types.versions.with_raw_response.retrieve( + version=0, + type="", + ) + + +class TestAsyncVersions: + parametrize = pytest.mark.parametrize( + "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"] + ) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_retrieve(self, async_client: AsyncKernel) -> None: + version = await async_client.report_types.versions.retrieve( + version=0, + type="type", + ) + assert_matches_type(ReportTypeVersion, version, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_raw_response_retrieve(self, async_client: AsyncKernel) -> None: + response = await async_client.report_types.versions.with_raw_response.retrieve( + version=0, + type="type", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + version = await response.parse() + assert_matches_type(ReportTypeVersion, version, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_streaming_response_retrieve(self, async_client: AsyncKernel) -> None: + async with async_client.report_types.versions.with_streaming_response.retrieve( + version=0, + type="type", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + version = await response.parse() + assert_matches_type(ReportTypeVersion, version, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_path_params_retrieve(self, async_client: AsyncKernel) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `type` but received ''"): + await async_client.report_types.versions.with_raw_response.retrieve( + version=0, + type="", + ) diff --git a/tests/api_resources/test_report_types.py b/tests/api_resources/test_report_types.py new file mode 100644 index 00000000..56cbad8e --- /dev/null +++ b/tests/api_resources/test_report_types.py @@ -0,0 +1,197 @@ +# 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 kernel import Kernel, AsyncKernel +from tests.utils import assert_matches_type +from kernel.types import ReportType, ReportTypeSummary +from kernel.pagination import SyncOffsetPagination, AsyncOffsetPagination + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestReportTypes: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_retrieve(self, client: Kernel) -> None: + report_type = client.report_types.retrieve( + "type", + ) + assert_matches_type(ReportType, report_type, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_raw_response_retrieve(self, client: Kernel) -> None: + response = client.report_types.with_raw_response.retrieve( + "type", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + report_type = response.parse() + assert_matches_type(ReportType, report_type, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_streaming_response_retrieve(self, client: Kernel) -> None: + with client.report_types.with_streaming_response.retrieve( + "type", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + report_type = response.parse() + assert_matches_type(ReportType, report_type, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_path_params_retrieve(self, client: Kernel) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `type` but received ''"): + client.report_types.with_raw_response.retrieve( + "", + ) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_list(self, client: Kernel) -> None: + report_type = client.report_types.list( + task_id="task_id", + ) + assert_matches_type(SyncOffsetPagination[ReportTypeSummary], report_type, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_list_with_all_params(self, client: Kernel) -> None: + report_type = client.report_types.list( + task_id="task_id", + limit=1, + offset=0, + ) + assert_matches_type(SyncOffsetPagination[ReportTypeSummary], report_type, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_raw_response_list(self, client: Kernel) -> None: + response = client.report_types.with_raw_response.list( + task_id="task_id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + report_type = response.parse() + assert_matches_type(SyncOffsetPagination[ReportTypeSummary], report_type, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_streaming_response_list(self, client: Kernel) -> None: + with client.report_types.with_streaming_response.list( + task_id="task_id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + report_type = response.parse() + assert_matches_type(SyncOffsetPagination[ReportTypeSummary], report_type, path=["response"]) + + assert cast(Any, response.is_closed) is True + + +class TestAsyncReportTypes: + parametrize = pytest.mark.parametrize( + "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"] + ) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_retrieve(self, async_client: AsyncKernel) -> None: + report_type = await async_client.report_types.retrieve( + "type", + ) + assert_matches_type(ReportType, report_type, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_raw_response_retrieve(self, async_client: AsyncKernel) -> None: + response = await async_client.report_types.with_raw_response.retrieve( + "type", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + report_type = await response.parse() + assert_matches_type(ReportType, report_type, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_streaming_response_retrieve(self, async_client: AsyncKernel) -> None: + async with async_client.report_types.with_streaming_response.retrieve( + "type", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + report_type = await response.parse() + assert_matches_type(ReportType, report_type, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_path_params_retrieve(self, async_client: AsyncKernel) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `type` but received ''"): + await async_client.report_types.with_raw_response.retrieve( + "", + ) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_list(self, async_client: AsyncKernel) -> None: + report_type = await async_client.report_types.list( + task_id="task_id", + ) + assert_matches_type(AsyncOffsetPagination[ReportTypeSummary], report_type, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_list_with_all_params(self, async_client: AsyncKernel) -> None: + report_type = await async_client.report_types.list( + task_id="task_id", + limit=1, + offset=0, + ) + assert_matches_type(AsyncOffsetPagination[ReportTypeSummary], report_type, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_raw_response_list(self, async_client: AsyncKernel) -> None: + response = await async_client.report_types.with_raw_response.list( + task_id="task_id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + report_type = await response.parse() + assert_matches_type(AsyncOffsetPagination[ReportTypeSummary], report_type, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_streaming_response_list(self, async_client: AsyncKernel) -> None: + async with async_client.report_types.with_streaming_response.list( + task_id="task_id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + report_type = await response.parse() + assert_matches_type(AsyncOffsetPagination[ReportTypeSummary], report_type, path=["response"]) + + assert cast(Any, response.is_closed) is True diff --git a/tests/api_resources/test_reports.py b/tests/api_resources/test_reports.py new file mode 100644 index 00000000..29f83768 --- /dev/null +++ b/tests/api_resources/test_reports.py @@ -0,0 +1,330 @@ +# 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 kernel import Kernel, AsyncKernel +from tests.utils import assert_matches_type +from kernel.types import Report +from kernel._utils import parse_datetime +from kernel.pagination import SyncOffsetPagination, AsyncOffsetPagination + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestReports: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_create(self, client: Kernel) -> None: + report = client.reports.create( + data={ + "result": "bar", + "evidence": "bar", + }, + task_id="x", + type="task.result", + ) + assert_matches_type(Report, report, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_create_with_all_params(self, client: Kernel) -> None: + report = client.reports.create( + data={ + "result": "bar", + "evidence": "bar", + }, + task_id="x", + type="task.result", + occurred_at=parse_datetime("2019-12-27T18:11:19.117Z"), + schema_version=1, + session_id="x", + ) + assert_matches_type(Report, report, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_raw_response_create(self, client: Kernel) -> None: + response = client.reports.with_raw_response.create( + data={ + "result": "bar", + "evidence": "bar", + }, + task_id="x", + type="task.result", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + report = response.parse() + assert_matches_type(Report, report, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_streaming_response_create(self, client: Kernel) -> None: + with client.reports.with_streaming_response.create( + data={ + "result": "bar", + "evidence": "bar", + }, + task_id="x", + type="task.result", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + report = response.parse() + assert_matches_type(Report, report, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_retrieve(self, client: Kernel) -> None: + report = client.reports.retrieve( + "id", + ) + assert_matches_type(Report, report, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_raw_response_retrieve(self, client: Kernel) -> None: + response = client.reports.with_raw_response.retrieve( + "id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + report = response.parse() + assert_matches_type(Report, report, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_streaming_response_retrieve(self, client: Kernel) -> None: + with client.reports.with_streaming_response.retrieve( + "id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + report = response.parse() + assert_matches_type(Report, report, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_path_params_retrieve(self, client: Kernel) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): + client.reports.with_raw_response.retrieve( + "", + ) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_list(self, client: Kernel) -> None: + report = client.reports.list( + task_id="task_id", + ) + assert_matches_type(SyncOffsetPagination[Report], report, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_list_with_all_params(self, client: Kernel) -> None: + report = client.reports.list( + task_id="task_id", + limit=1, + offset=0, + type="type", + ) + assert_matches_type(SyncOffsetPagination[Report], report, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_raw_response_list(self, client: Kernel) -> None: + response = client.reports.with_raw_response.list( + task_id="task_id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + report = response.parse() + assert_matches_type(SyncOffsetPagination[Report], report, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_streaming_response_list(self, client: Kernel) -> None: + with client.reports.with_streaming_response.list( + task_id="task_id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + report = response.parse() + assert_matches_type(SyncOffsetPagination[Report], report, path=["response"]) + + assert cast(Any, response.is_closed) is True + + +class TestAsyncReports: + parametrize = pytest.mark.parametrize( + "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"] + ) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_create(self, async_client: AsyncKernel) -> None: + report = await async_client.reports.create( + data={ + "result": "bar", + "evidence": "bar", + }, + task_id="x", + type="task.result", + ) + assert_matches_type(Report, report, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_create_with_all_params(self, async_client: AsyncKernel) -> None: + report = await async_client.reports.create( + data={ + "result": "bar", + "evidence": "bar", + }, + task_id="x", + type="task.result", + occurred_at=parse_datetime("2019-12-27T18:11:19.117Z"), + schema_version=1, + session_id="x", + ) + assert_matches_type(Report, report, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_raw_response_create(self, async_client: AsyncKernel) -> None: + response = await async_client.reports.with_raw_response.create( + data={ + "result": "bar", + "evidence": "bar", + }, + task_id="x", + type="task.result", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + report = await response.parse() + assert_matches_type(Report, report, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_streaming_response_create(self, async_client: AsyncKernel) -> None: + async with async_client.reports.with_streaming_response.create( + data={ + "result": "bar", + "evidence": "bar", + }, + task_id="x", + type="task.result", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + report = await response.parse() + assert_matches_type(Report, report, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_retrieve(self, async_client: AsyncKernel) -> None: + report = await async_client.reports.retrieve( + "id", + ) + assert_matches_type(Report, report, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_raw_response_retrieve(self, async_client: AsyncKernel) -> None: + response = await async_client.reports.with_raw_response.retrieve( + "id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + report = await response.parse() + assert_matches_type(Report, report, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_streaming_response_retrieve(self, async_client: AsyncKernel) -> None: + async with async_client.reports.with_streaming_response.retrieve( + "id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + report = await response.parse() + assert_matches_type(Report, report, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_path_params_retrieve(self, async_client: AsyncKernel) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): + await async_client.reports.with_raw_response.retrieve( + "", + ) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_list(self, async_client: AsyncKernel) -> None: + report = await async_client.reports.list( + task_id="task_id", + ) + assert_matches_type(AsyncOffsetPagination[Report], report, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_list_with_all_params(self, async_client: AsyncKernel) -> None: + report = await async_client.reports.list( + task_id="task_id", + limit=1, + offset=0, + type="type", + ) + assert_matches_type(AsyncOffsetPagination[Report], report, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_raw_response_list(self, async_client: AsyncKernel) -> None: + response = await async_client.reports.with_raw_response.list( + task_id="task_id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + report = await response.parse() + assert_matches_type(AsyncOffsetPagination[Report], report, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_streaming_response_list(self, async_client: AsyncKernel) -> None: + async with async_client.reports.with_streaming_response.list( + task_id="task_id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + report = await response.parse() + assert_matches_type(AsyncOffsetPagination[Report], report, path=["response"]) + + assert cast(Any, response.is_closed) is True From 54a0df62916a5cd8f0991a8780aa47bdefbfacd3 Mon Sep 17 00:00:00 2001 From: "kernel-internal[bot]" <260533166+kernel-internal[bot]@users.noreply.github.com> Date: Mon, 16 Nov 2026 23:17:13 +0000 Subject: [PATCH 5/6] feat: Let vault item events be read after the item or vault is deleted Stainless-Generated-From: 503e1e1f7d8bc84ca8f9984ed03b4e0073251f49 --- src/kernel/resources/vaults/items.py | 14 ++++++++++++++ src/kernel/types/vaults/item_events_params.py | 9 +++++++++ tests/api_resources/vaults/test_items.py | 2 ++ 3 files changed, 25 insertions(+) diff --git a/src/kernel/resources/vaults/items.py b/src/kernel/resources/vaults/items.py index 4db4472a..5d14ad0f 100644 --- a/src/kernel/resources/vaults/items.py +++ b/src/kernel/resources/vaults/items.py @@ -428,6 +428,7 @@ def events( *, id_or_name: str, after: str | Omit = omit, + include_deleted: bool | Omit = omit, wait: int | Omit = omit, # 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. @@ -442,6 +443,11 @@ def events( Args: after: Return events after this event ID. + include_deleted: When true, also finds deleted items, and deleted vaults by ID only. `key` then + also accepts an item ID, which takes precedence over a key with the same value; + the lookup order is the item ID, then the live item with that key, then the most + recently deleted one. `wait` is ignored for a deleted item or vault. + wait: Long-poll for new events for up to this many seconds. extra_headers: Send extra headers @@ -466,6 +472,7 @@ def events( query=maybe_transform( { "after": after, + "include_deleted": include_deleted, "wait": wait, }, item_events_params.ItemEventsParams, @@ -2522,6 +2529,7 @@ async def events( *, id_or_name: str, after: str | Omit = omit, + include_deleted: bool | Omit = omit, wait: int | Omit = omit, # 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. @@ -2536,6 +2544,11 @@ async def events( Args: after: Return events after this event ID. + include_deleted: When true, also finds deleted items, and deleted vaults by ID only. `key` then + also accepts an item ID, which takes precedence over a key with the same value; + the lookup order is the item ID, then the live item with that key, then the most + recently deleted one. `wait` is ignored for a deleted item or vault. + wait: Long-poll for new events for up to this many seconds. extra_headers: Send extra headers @@ -2560,6 +2573,7 @@ async def events( query=await async_maybe_transform( { "after": after, + "include_deleted": include_deleted, "wait": wait, }, item_events_params.ItemEventsParams, diff --git a/src/kernel/types/vaults/item_events_params.py b/src/kernel/types/vaults/item_events_params.py index cee33414..3d2fcc7b 100644 --- a/src/kernel/types/vaults/item_events_params.py +++ b/src/kernel/types/vaults/item_events_params.py @@ -13,5 +13,14 @@ class ItemEventsParams(TypedDict, total=False): after: str """Return events after this event ID.""" + include_deleted: bool + """When true, also finds deleted items, and deleted vaults by ID only. + + `key` then also accepts an item ID, which takes precedence over a key with the + same value; the lookup order is the item ID, then the live item with that key, + then the most recently deleted one. `wait` is ignored for a deleted item or + vault. + """ + wait: int """Long-poll for new events for up to this many seconds.""" diff --git a/tests/api_resources/vaults/test_items.py b/tests/api_resources/vaults/test_items.py index 4a474b16..97a13504 100644 --- a/tests/api_resources/vaults/test_items.py +++ b/tests/api_resources/vaults/test_items.py @@ -605,6 +605,7 @@ def test_method_events_with_all_params(self, client: Kernel) -> None: key="key", id_or_name="id_or_name", after="after", + include_deleted=True, wait=0, ) assert_matches_type(ItemEventsResponse, item, path=["response"]) @@ -3299,6 +3300,7 @@ async def test_method_events_with_all_params(self, async_client: AsyncKernel) -> key="key", id_or_name="id_or_name", after="after", + include_deleted=True, wait=0, ) assert_matches_type(ItemEventsResponse, item, path=["response"]) From 549096ba24c06f14dd60583882a19e7d8fac16ee Mon Sep 17 00:00:00 2001 From: "kernel-internal[bot]" <260533166+kernel-internal[bot]@users.noreply.github.com> Date: Mon, 16 Nov 2026 23:22:35 +0000 Subject: [PATCH 6/6] release: 0.149.0 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 9 +++++++++ pyproject.toml | 2 +- src/kernel/_version.py | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 2b1627bc..023707a7 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.148.0" + ".": "0.149.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 377050c6..395df25d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## [0.149.0](https://github.com/kernel/kernel-python-sdk/compare/v0.148.0...v0.149.0) (2026-11-16) + + +### Features + +* Add reports API and report type discovery ([0c8d11c](https://github.com/kernel/kernel-python-sdk/commit/0c8d11c5f62aa2ddd7e663e87d31267ef4364390)) +* Add tasks API: create, list, get, and link browsers ([5dd6af8](https://github.com/kernel/kernel-python-sdk/commit/5dd6af87afa61b5fbbc5770585ae04f4ec2fe49c)) +* Let vault item events be read after the item or vault is deleted ([54a0df6](https://github.com/kernel/kernel-python-sdk/commit/54a0df62916a5cd8f0991a8780aa47bdefbfacd3)) + ## [0.148.0](https://github.com/kernel/kernel-python-sdk/compare/v0.147.0...v0.148.0) (2026-11-12) diff --git a/pyproject.toml b/pyproject.toml index db1d4adb..74542735 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "kernel" -version = "0.148.0" +version = "0.149.0" description = "The official Python library for the kernel API" dynamic = ["readme"] license = "Apache-2.0" diff --git a/src/kernel/_version.py b/src/kernel/_version.py index eb83d220..ee4c69f0 100644 --- a/src/kernel/_version.py +++ b/src/kernel/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. __title__ = "kernel" -__version__ = "0.148.0" # x-release-please-version +__version__ = "0.149.0" # x-release-please-version