diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d9000d..51b16df 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,6 +30,30 @@ jobs: - name: Run lints run: ./scripts/lint + upload: + if: github.repository == 'stainless-sdks/kernel-python' + timeout-minutes: 10 + name: upload + permissions: + contents: read + id-token: write + runs-on: depot-ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + + - name: Get GitHub OIDC Token + id: github-oidc + uses: actions/github-script@v6 + with: + script: core.setOutput('github_token', await core.getIDToken()); + + - name: Upload tarball + env: + URL: https://pkg.stainless.com/s + AUTH: ${{ steps.github-oidc.outputs.github_token }} + SHA: ${{ github.sha }} + run: ./scripts/utils/upload-artifact.sh + test: timeout-minutes: 10 name: test diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 46b9b6b..3b005e5 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.1.0-alpha.9" + ".": "0.1.0-alpha.10" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index d6d797a..6f21bcb 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 4 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-07d481d1498bf9677437b555e9ec2d843d50107faa7501e4c430a32b1f3c3343.yml -openapi_spec_hash: 296f78d82afbac95fad12c5eabd71f18 -config_hash: 2c8351ba6611ce4a352e248405783846 +configured_endpoints: 5 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-f40e779e2a48f5e37361f2f4a9879e5c40f2851b8033c23db69ec7b91242bf69.yml +openapi_spec_hash: 2dfa146149e61363f1ec40bf9251eb7c +config_hash: 2ddaa85513b6670889b1a56c905423c7 diff --git a/CHANGELOG.md b/CHANGELOG.md index a1a7bf6..472dc2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## 0.1.0-alpha.10 (2025-05-19) + +Full Changelog: [v0.1.0-alpha.9...v0.1.0-alpha.10](https://github.com/onkernel/kernel-python-sdk/compare/v0.1.0-alpha.9...v0.1.0-alpha.10) + +### Features + +* **api:** update via SDK Studio ([a382570](https://github.com/onkernel/kernel-python-sdk/commit/a382570e96f3bae625cb176e746038fcdf0e8e73)) + + +### Chores + +* **ci:** fix installation instructions ([c897375](https://github.com/onkernel/kernel-python-sdk/commit/c8973750a1ae58f7c8eee588bbe874862dbbb46d)) +* **ci:** upload sdks to package manager ([03d0f7f](https://github.com/onkernel/kernel-python-sdk/commit/03d0f7f19be9614f5a81bd5c31117febd68ec5e9)) +* **internal:** codegen related update ([49143bd](https://github.com/onkernel/kernel-python-sdk/commit/49143bdcb6635ae79b1c4c5fddc9017d8d81b4d7)) + ## 0.1.0-alpha.9 (2025-05-14) Full Changelog: [v0.1.0-alpha.8...v0.1.0-alpha.9](https://github.com/onkernel/kernel-python-sdk/compare/v0.1.0-alpha.8...v0.1.0-alpha.9) diff --git a/README.md b/README.md index 801b34f..1f5a5bb 100644 --- a/README.md +++ b/README.md @@ -33,12 +33,12 @@ client = Kernel( environment="development", ) -response = client.apps.deploy( - entrypoint_rel_path="app.py", +deployment = client.apps.deployments.create( + entrypoint_rel_path="main.ts", file=b"REPLACE_ME", - version="REPLACE_ME", + version="1.0.0", ) -print(response.apps) +print(deployment.apps) ``` While you can provide an `api_key` keyword argument, @@ -63,12 +63,12 @@ client = AsyncKernel( async def main() -> None: - response = await client.apps.deploy( - entrypoint_rel_path="app.py", + deployment = await client.apps.deployments.create( + entrypoint_rel_path="main.ts", file=b"REPLACE_ME", - version="REPLACE_ME", + version="1.0.0", ) - print(response.apps) + print(deployment.apps) asyncio.run(main()) @@ -95,8 +95,8 @@ from kernel import Kernel client = Kernel() -client.apps.deploy( - entrypoint_rel_path="app.py", +client.apps.deployments.create( + entrypoint_rel_path="src/app.py", file=Path("/path/to/file"), ) ``` @@ -119,10 +119,8 @@ from kernel import Kernel client = Kernel() try: - client.apps.deploy( - entrypoint_rel_path="app.py", - file=b"REPLACE_ME", - version="REPLACE_ME", + client.browsers.create( + invocation_id="REPLACE_ME", ) except kernel.APIConnectionError as e: print("The server could not be reached") @@ -166,10 +164,8 @@ client = Kernel( ) # Or, configure per-request: -client.with_options(max_retries=5).apps.deploy( - entrypoint_rel_path="app.py", - file=b"REPLACE_ME", - version="REPLACE_ME", +client.with_options(max_retries=5).browsers.create( + invocation_id="REPLACE_ME", ) ``` @@ -193,10 +189,8 @@ client = Kernel( ) # Override per-request: -client.with_options(timeout=5.0).apps.deploy( - entrypoint_rel_path="app.py", - file=b"REPLACE_ME", - version="REPLACE_ME", +client.with_options(timeout=5.0).browsers.create( + invocation_id="REPLACE_ME", ) ``` @@ -238,15 +232,13 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to from kernel import Kernel client = Kernel() -response = client.apps.with_raw_response.deploy( - entrypoint_rel_path="app.py", - file=b"REPLACE_ME", - version="REPLACE_ME", +response = client.browsers.with_raw_response.create( + invocation_id="REPLACE_ME", ) print(response.headers.get('X-My-Header')) -app = response.parse() # get the object that `apps.deploy()` would have returned -print(app.apps) +browser = response.parse() # get the object that `browsers.create()` would have returned +print(browser.session_id) ``` These methods return an [`APIResponse`](https://github.com/onkernel/kernel-python-sdk/tree/main/src/kernel/_response.py) object. @@ -260,10 +252,8 @@ The above interface eagerly reads the full response body when you make the reque To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods. ```python -with client.apps.with_streaming_response.deploy( - entrypoint_rel_path="app.py", - file=b"REPLACE_ME", - version="REPLACE_ME", +with client.browsers.with_streaming_response.create( + invocation_id="REPLACE_ME", ) as response: print(response.headers.get("X-My-Header")) diff --git a/api.md b/api.md index 581c76f..3456b56 100644 --- a/api.md +++ b/api.md @@ -1,25 +1,39 @@ # Apps +## Deployments + +Types: + +```python +from kernel.types.apps import DeploymentCreateResponse +``` + +Methods: + +- client.apps.deployments.create(\*\*params) -> DeploymentCreateResponse + +## Invocations + Types: ```python -from kernel.types import AppDeployResponse, AppInvokeResponse, AppRetrieveInvocationResponse +from kernel.types.apps import InvocationCreateResponse, InvocationRetrieveResponse ``` Methods: -- client.apps.deploy(\*\*params) -> AppDeployResponse -- client.apps.invoke(\*\*params) -> AppInvokeResponse -- client.apps.retrieve_invocation(id) -> AppRetrieveInvocationResponse +- client.apps.invocations.create(\*\*params) -> InvocationCreateResponse +- client.apps.invocations.retrieve(id) -> InvocationRetrieveResponse -# Browser +# Browsers Types: ```python -from kernel.types import BrowserCreateSessionResponse +from kernel.types import BrowserCreateResponse, BrowserRetrieveResponse ``` Methods: -- client.browser.create_session(\*\*params) -> BrowserCreateSessionResponse +- client.browsers.create(\*\*params) -> BrowserCreateResponse +- client.browsers.retrieve(id) -> BrowserRetrieveResponse diff --git a/pyproject.toml b/pyproject.toml index 5045418..b8cbab8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "kernel" -version = "0.1.0-alpha.9" +version = "0.1.0-alpha.10" description = "The official Python library for the kernel API" dynamic = ["readme"] license = "Apache-2.0" diff --git a/scripts/utils/upload-artifact.sh b/scripts/utils/upload-artifact.sh new file mode 100755 index 0000000..c55ebbc --- /dev/null +++ b/scripts/utils/upload-artifact.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -exuo pipefail + +RESPONSE=$(curl -X POST "$URL" \ + -H "Authorization: Bearer $AUTH" \ + -H "Content-Type: application/json") + +SIGNED_URL=$(echo "$RESPONSE" | jq -r '.url') + +if [[ "$SIGNED_URL" == "null" ]]; then + echo -e "\033[31mFailed to get signed URL.\033[0m" + exit 1 +fi + +UPLOAD_RESPONSE=$(tar -cz . | curl -v -X PUT \ + -H "Content-Type: application/gzip" \ + --data-binary @- "$SIGNED_URL" 2>&1) + +if echo "$UPLOAD_RESPONSE" | grep -q "HTTP/[0-9.]* 200"; then + echo -e "\033[32mUploaded build to Stainless storage.\033[0m" + echo -e "\033[32mInstallation: pip install --pre 'https://pkg.stainless.com/s/kernel-python/$SHA'\033[0m" +else + echo -e "\033[31mFailed to upload artifact.\033[0m" + exit 1 +fi diff --git a/src/kernel/_client.py b/src/kernel/_client.py index 28871ba..bf6fbb4 100644 --- a/src/kernel/_client.py +++ b/src/kernel/_client.py @@ -21,7 +21,7 @@ ) from ._utils import is_given, get_async_library from ._version import __version__ -from .resources import apps, browser +from .resources import browsers from ._streaming import Stream as Stream, AsyncStream as AsyncStream from ._exceptions import KernelError, APIStatusError from ._base_client import ( @@ -29,6 +29,7 @@ SyncAPIClient, AsyncAPIClient, ) +from .resources.apps import apps __all__ = [ "ENVIRONMENTS", @@ -50,7 +51,7 @@ class Kernel(SyncAPIClient): apps: apps.AppsResource - browser: browser.BrowserResource + browsers: browsers.BrowsersResource with_raw_response: KernelWithRawResponse with_streaming_response: KernelWithStreamedResponse @@ -133,7 +134,7 @@ def __init__( ) self.apps = apps.AppsResource(self) - self.browser = browser.BrowserResource(self) + self.browsers = browsers.BrowsersResource(self) self.with_raw_response = KernelWithRawResponse(self) self.with_streaming_response = KernelWithStreamedResponse(self) @@ -246,7 +247,7 @@ def _make_status_error( class AsyncKernel(AsyncAPIClient): apps: apps.AsyncAppsResource - browser: browser.AsyncBrowserResource + browsers: browsers.AsyncBrowsersResource with_raw_response: AsyncKernelWithRawResponse with_streaming_response: AsyncKernelWithStreamedResponse @@ -329,7 +330,7 @@ def __init__( ) self.apps = apps.AsyncAppsResource(self) - self.browser = browser.AsyncBrowserResource(self) + self.browsers = browsers.AsyncBrowsersResource(self) self.with_raw_response = AsyncKernelWithRawResponse(self) self.with_streaming_response = AsyncKernelWithStreamedResponse(self) @@ -443,25 +444,25 @@ def _make_status_error( class KernelWithRawResponse: def __init__(self, client: Kernel) -> None: self.apps = apps.AppsResourceWithRawResponse(client.apps) - self.browser = browser.BrowserResourceWithRawResponse(client.browser) + self.browsers = browsers.BrowsersResourceWithRawResponse(client.browsers) class AsyncKernelWithRawResponse: def __init__(self, client: AsyncKernel) -> None: self.apps = apps.AsyncAppsResourceWithRawResponse(client.apps) - self.browser = browser.AsyncBrowserResourceWithRawResponse(client.browser) + self.browsers = browsers.AsyncBrowsersResourceWithRawResponse(client.browsers) class KernelWithStreamedResponse: def __init__(self, client: Kernel) -> None: self.apps = apps.AppsResourceWithStreamingResponse(client.apps) - self.browser = browser.BrowserResourceWithStreamingResponse(client.browser) + self.browsers = browsers.BrowsersResourceWithStreamingResponse(client.browsers) class AsyncKernelWithStreamedResponse: def __init__(self, client: AsyncKernel) -> None: self.apps = apps.AsyncAppsResourceWithStreamingResponse(client.apps) - self.browser = browser.AsyncBrowserResourceWithStreamingResponse(client.browser) + self.browsers = browsers.AsyncBrowsersResourceWithStreamingResponse(client.browsers) Client = Kernel diff --git a/src/kernel/_version.py b/src/kernel/_version.py index 7716ecb..edb86b3 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.1.0-alpha.9" # x-release-please-version +__version__ = "0.1.0-alpha.10" # x-release-please-version diff --git a/src/kernel/resources/__init__.py b/src/kernel/resources/__init__.py index a0d1ea6..647bde6 100644 --- a/src/kernel/resources/__init__.py +++ b/src/kernel/resources/__init__.py @@ -8,13 +8,13 @@ AppsResourceWithStreamingResponse, AsyncAppsResourceWithStreamingResponse, ) -from .browser import ( - BrowserResource, - AsyncBrowserResource, - BrowserResourceWithRawResponse, - AsyncBrowserResourceWithRawResponse, - BrowserResourceWithStreamingResponse, - AsyncBrowserResourceWithStreamingResponse, +from .browsers import ( + BrowsersResource, + AsyncBrowsersResource, + BrowsersResourceWithRawResponse, + AsyncBrowsersResourceWithRawResponse, + BrowsersResourceWithStreamingResponse, + AsyncBrowsersResourceWithStreamingResponse, ) __all__ = [ @@ -24,10 +24,10 @@ "AsyncAppsResourceWithRawResponse", "AppsResourceWithStreamingResponse", "AsyncAppsResourceWithStreamingResponse", - "BrowserResource", - "AsyncBrowserResource", - "BrowserResourceWithRawResponse", - "AsyncBrowserResourceWithRawResponse", - "BrowserResourceWithStreamingResponse", - "AsyncBrowserResourceWithStreamingResponse", + "BrowsersResource", + "AsyncBrowsersResource", + "BrowsersResourceWithRawResponse", + "AsyncBrowsersResourceWithRawResponse", + "BrowsersResourceWithStreamingResponse", + "AsyncBrowsersResourceWithStreamingResponse", ] diff --git a/src/kernel/resources/apps.py b/src/kernel/resources/apps.py deleted file mode 100644 index 023f214..0000000 --- a/src/kernel/resources/apps.py +++ /dev/null @@ -1,418 +0,0 @@ -# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -from __future__ import annotations - -from typing import Mapping, cast -from typing_extensions import Literal - -import httpx - -from ..types import app_deploy_params, app_invoke_params -from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven, FileTypes -from .._utils import extract_files, maybe_transform, deepcopy_minimal, 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 .._base_client import make_request_options -from ..types.app_deploy_response import AppDeployResponse -from ..types.app_invoke_response import AppInvokeResponse -from ..types.app_retrieve_invocation_response import AppRetrieveInvocationResponse - -__all__ = ["AppsResource", "AsyncAppsResource"] - - -class AppsResource(SyncAPIResource): - @cached_property - def with_raw_response(self) -> AppsResourceWithRawResponse: - """ - 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/onkernel/kernel-python-sdk#accessing-raw-response-data-eg-headers - """ - return AppsResourceWithRawResponse(self) - - @cached_property - def with_streaming_response(self) -> AppsResourceWithStreamingResponse: - """ - An alternative to `.with_raw_response` that doesn't eagerly read the response body. - - For more information, see https://www.github.com/onkernel/kernel-python-sdk#with_streaming_response - """ - return AppsResourceWithStreamingResponse(self) - - def deploy( - self, - *, - entrypoint_rel_path: str, - file: FileTypes, - force: Literal["true", "false"] | NotGiven = NOT_GIVEN, - region: Literal["aws.us-east-1a"] | NotGiven = NOT_GIVEN, - version: str | NotGiven = NOT_GIVEN, - # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. - # The extra values given here take precedence over values defined on the client or passed to this method. - extra_headers: Headers | None = None, - extra_query: Query | None = None, - extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> AppDeployResponse: - """ - Deploy a new application - - Args: - entrypoint_rel_path: Relative path to the entrypoint of the application - - file: ZIP file containing the application source directory - - force: Allow overwriting an existing app version - - region: Region for deployment. Currently we only support "aws.us-east-1a" - - version: Version of the application. Can be any string. - - 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 - """ - body = deepcopy_minimal( - { - "entrypoint_rel_path": entrypoint_rel_path, - "file": file, - "force": force, - "region": region, - "version": version, - } - ) - files = extract_files(cast(Mapping[str, object], body), paths=[["file"]]) - # It should be noted that the actual Content-Type header that will be - # sent to the server will contain a `boundary` parameter, e.g. - # multipart/form-data; boundary=---abc-- - extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})} - return self._post( - "/apps/deploy", - body=maybe_transform(body, app_deploy_params.AppDeployParams), - files=files, - options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout - ), - cast_to=AppDeployResponse, - ) - - def invoke( - self, - *, - action_name: str, - app_name: str, - payload: object, - version: 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, - ) -> AppInvokeResponse: - """ - Invoke an application - - Args: - action_name: Name of the action to invoke - - app_name: Name of the application - - payload: Input data for the application - - version: Version of the application - - 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._post( - "/apps/invoke", - body=maybe_transform( - { - "action_name": action_name, - "app_name": app_name, - "payload": payload, - "version": version, - }, - app_invoke_params.AppInvokeParams, - ), - options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout - ), - cast_to=AppInvokeResponse, - ) - - def retrieve_invocation( - 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, - ) -> AppRetrieveInvocationResponse: - """ - Get an app invocation by id - - 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( - f"/apps/invocations/{id}", - options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout - ), - cast_to=AppRetrieveInvocationResponse, - ) - - -class AsyncAppsResource(AsyncAPIResource): - @cached_property - def with_raw_response(self) -> AsyncAppsResourceWithRawResponse: - """ - 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/onkernel/kernel-python-sdk#accessing-raw-response-data-eg-headers - """ - return AsyncAppsResourceWithRawResponse(self) - - @cached_property - def with_streaming_response(self) -> AsyncAppsResourceWithStreamingResponse: - """ - An alternative to `.with_raw_response` that doesn't eagerly read the response body. - - For more information, see https://www.github.com/onkernel/kernel-python-sdk#with_streaming_response - """ - return AsyncAppsResourceWithStreamingResponse(self) - - async def deploy( - self, - *, - entrypoint_rel_path: str, - file: FileTypes, - force: Literal["true", "false"] | NotGiven = NOT_GIVEN, - region: Literal["aws.us-east-1a"] | NotGiven = NOT_GIVEN, - version: str | NotGiven = NOT_GIVEN, - # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. - # The extra values given here take precedence over values defined on the client or passed to this method. - extra_headers: Headers | None = None, - extra_query: Query | None = None, - extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> AppDeployResponse: - """ - Deploy a new application - - Args: - entrypoint_rel_path: Relative path to the entrypoint of the application - - file: ZIP file containing the application source directory - - force: Allow overwriting an existing app version - - region: Region for deployment. Currently we only support "aws.us-east-1a" - - version: Version of the application. Can be any string. - - 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 - """ - body = deepcopy_minimal( - { - "entrypoint_rel_path": entrypoint_rel_path, - "file": file, - "force": force, - "region": region, - "version": version, - } - ) - files = extract_files(cast(Mapping[str, object], body), paths=[["file"]]) - # It should be noted that the actual Content-Type header that will be - # sent to the server will contain a `boundary` parameter, e.g. - # multipart/form-data; boundary=---abc-- - extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})} - return await self._post( - "/apps/deploy", - body=await async_maybe_transform(body, app_deploy_params.AppDeployParams), - files=files, - options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout - ), - cast_to=AppDeployResponse, - ) - - async def invoke( - self, - *, - action_name: str, - app_name: str, - payload: object, - version: 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, - ) -> AppInvokeResponse: - """ - Invoke an application - - Args: - action_name: Name of the action to invoke - - app_name: Name of the application - - payload: Input data for the application - - version: Version of the application - - 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 await self._post( - "/apps/invoke", - body=await async_maybe_transform( - { - "action_name": action_name, - "app_name": app_name, - "payload": payload, - "version": version, - }, - app_invoke_params.AppInvokeParams, - ), - options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout - ), - cast_to=AppInvokeResponse, - ) - - async def retrieve_invocation( - 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, - ) -> AppRetrieveInvocationResponse: - """ - Get an app invocation by id - - 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( - f"/apps/invocations/{id}", - options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout - ), - cast_to=AppRetrieveInvocationResponse, - ) - - -class AppsResourceWithRawResponse: - def __init__(self, apps: AppsResource) -> None: - self._apps = apps - - self.deploy = to_raw_response_wrapper( - apps.deploy, - ) - self.invoke = to_raw_response_wrapper( - apps.invoke, - ) - self.retrieve_invocation = to_raw_response_wrapper( - apps.retrieve_invocation, - ) - - -class AsyncAppsResourceWithRawResponse: - def __init__(self, apps: AsyncAppsResource) -> None: - self._apps = apps - - self.deploy = async_to_raw_response_wrapper( - apps.deploy, - ) - self.invoke = async_to_raw_response_wrapper( - apps.invoke, - ) - self.retrieve_invocation = async_to_raw_response_wrapper( - apps.retrieve_invocation, - ) - - -class AppsResourceWithStreamingResponse: - def __init__(self, apps: AppsResource) -> None: - self._apps = apps - - self.deploy = to_streamed_response_wrapper( - apps.deploy, - ) - self.invoke = to_streamed_response_wrapper( - apps.invoke, - ) - self.retrieve_invocation = to_streamed_response_wrapper( - apps.retrieve_invocation, - ) - - -class AsyncAppsResourceWithStreamingResponse: - def __init__(self, apps: AsyncAppsResource) -> None: - self._apps = apps - - self.deploy = async_to_streamed_response_wrapper( - apps.deploy, - ) - self.invoke = async_to_streamed_response_wrapper( - apps.invoke, - ) - self.retrieve_invocation = async_to_streamed_response_wrapper( - apps.retrieve_invocation, - ) diff --git a/src/kernel/resources/apps/__init__.py b/src/kernel/resources/apps/__init__.py new file mode 100644 index 0000000..5602ad7 --- /dev/null +++ b/src/kernel/resources/apps/__init__.py @@ -0,0 +1,47 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from .apps import ( + AppsResource, + AsyncAppsResource, + AppsResourceWithRawResponse, + AsyncAppsResourceWithRawResponse, + AppsResourceWithStreamingResponse, + AsyncAppsResourceWithStreamingResponse, +) +from .deployments import ( + DeploymentsResource, + AsyncDeploymentsResource, + DeploymentsResourceWithRawResponse, + AsyncDeploymentsResourceWithRawResponse, + DeploymentsResourceWithStreamingResponse, + AsyncDeploymentsResourceWithStreamingResponse, +) +from .invocations import ( + InvocationsResource, + AsyncInvocationsResource, + InvocationsResourceWithRawResponse, + AsyncInvocationsResourceWithRawResponse, + InvocationsResourceWithStreamingResponse, + AsyncInvocationsResourceWithStreamingResponse, +) + +__all__ = [ + "DeploymentsResource", + "AsyncDeploymentsResource", + "DeploymentsResourceWithRawResponse", + "AsyncDeploymentsResourceWithRawResponse", + "DeploymentsResourceWithStreamingResponse", + "AsyncDeploymentsResourceWithStreamingResponse", + "InvocationsResource", + "AsyncInvocationsResource", + "InvocationsResourceWithRawResponse", + "AsyncInvocationsResourceWithRawResponse", + "InvocationsResourceWithStreamingResponse", + "AsyncInvocationsResourceWithStreamingResponse", + "AppsResource", + "AsyncAppsResource", + "AppsResourceWithRawResponse", + "AsyncAppsResourceWithRawResponse", + "AppsResourceWithStreamingResponse", + "AsyncAppsResourceWithStreamingResponse", +] diff --git a/src/kernel/resources/apps/apps.py b/src/kernel/resources/apps/apps.py new file mode 100644 index 0000000..848b765 --- /dev/null +++ b/src/kernel/resources/apps/apps.py @@ -0,0 +1,134 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from ..._compat import cached_property +from ..._resource import SyncAPIResource, AsyncAPIResource +from .deployments import ( + DeploymentsResource, + AsyncDeploymentsResource, + DeploymentsResourceWithRawResponse, + AsyncDeploymentsResourceWithRawResponse, + DeploymentsResourceWithStreamingResponse, + AsyncDeploymentsResourceWithStreamingResponse, +) +from .invocations import ( + InvocationsResource, + AsyncInvocationsResource, + InvocationsResourceWithRawResponse, + AsyncInvocationsResourceWithRawResponse, + InvocationsResourceWithStreamingResponse, + AsyncInvocationsResourceWithStreamingResponse, +) + +__all__ = ["AppsResource", "AsyncAppsResource"] + + +class AppsResource(SyncAPIResource): + @cached_property + def deployments(self) -> DeploymentsResource: + return DeploymentsResource(self._client) + + @cached_property + def invocations(self) -> InvocationsResource: + return InvocationsResource(self._client) + + @cached_property + def with_raw_response(self) -> AppsResourceWithRawResponse: + """ + 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/onkernel/kernel-python-sdk#accessing-raw-response-data-eg-headers + """ + return AppsResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AppsResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/onkernel/kernel-python-sdk#with_streaming_response + """ + return AppsResourceWithStreamingResponse(self) + + +class AsyncAppsResource(AsyncAPIResource): + @cached_property + def deployments(self) -> AsyncDeploymentsResource: + return AsyncDeploymentsResource(self._client) + + @cached_property + def invocations(self) -> AsyncInvocationsResource: + return AsyncInvocationsResource(self._client) + + @cached_property + def with_raw_response(self) -> AsyncAppsResourceWithRawResponse: + """ + 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/onkernel/kernel-python-sdk#accessing-raw-response-data-eg-headers + """ + return AsyncAppsResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncAppsResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/onkernel/kernel-python-sdk#with_streaming_response + """ + return AsyncAppsResourceWithStreamingResponse(self) + + +class AppsResourceWithRawResponse: + def __init__(self, apps: AppsResource) -> None: + self._apps = apps + + @cached_property + def deployments(self) -> DeploymentsResourceWithRawResponse: + return DeploymentsResourceWithRawResponse(self._apps.deployments) + + @cached_property + def invocations(self) -> InvocationsResourceWithRawResponse: + return InvocationsResourceWithRawResponse(self._apps.invocations) + + +class AsyncAppsResourceWithRawResponse: + def __init__(self, apps: AsyncAppsResource) -> None: + self._apps = apps + + @cached_property + def deployments(self) -> AsyncDeploymentsResourceWithRawResponse: + return AsyncDeploymentsResourceWithRawResponse(self._apps.deployments) + + @cached_property + def invocations(self) -> AsyncInvocationsResourceWithRawResponse: + return AsyncInvocationsResourceWithRawResponse(self._apps.invocations) + + +class AppsResourceWithStreamingResponse: + def __init__(self, apps: AppsResource) -> None: + self._apps = apps + + @cached_property + def deployments(self) -> DeploymentsResourceWithStreamingResponse: + return DeploymentsResourceWithStreamingResponse(self._apps.deployments) + + @cached_property + def invocations(self) -> InvocationsResourceWithStreamingResponse: + return InvocationsResourceWithStreamingResponse(self._apps.invocations) + + +class AsyncAppsResourceWithStreamingResponse: + def __init__(self, apps: AsyncAppsResource) -> None: + self._apps = apps + + @cached_property + def deployments(self) -> AsyncDeploymentsResourceWithStreamingResponse: + return AsyncDeploymentsResourceWithStreamingResponse(self._apps.deployments) + + @cached_property + def invocations(self) -> AsyncInvocationsResourceWithStreamingResponse: + return AsyncInvocationsResourceWithStreamingResponse(self._apps.invocations) diff --git a/src/kernel/resources/apps/deployments.py b/src/kernel/resources/apps/deployments.py new file mode 100644 index 0000000..0b88fd1 --- /dev/null +++ b/src/kernel/resources/apps/deployments.py @@ -0,0 +1,224 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Mapping, cast +from typing_extensions import Literal + +import httpx + +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven, FileTypes +from ..._utils import extract_files, maybe_transform, deepcopy_minimal, async_maybe_transform +from ..._compat import cached_property +from ..._resource import SyncAPIResource, AsyncAPIResource +from ..._response import ( + to_raw_response_wrapper, + to_streamed_response_wrapper, + async_to_raw_response_wrapper, + async_to_streamed_response_wrapper, +) +from ...types.apps import deployment_create_params +from ..._base_client import make_request_options +from ...types.apps.deployment_create_response import DeploymentCreateResponse + +__all__ = ["DeploymentsResource", "AsyncDeploymentsResource"] + + +class DeploymentsResource(SyncAPIResource): + @cached_property + def with_raw_response(self) -> DeploymentsResourceWithRawResponse: + """ + 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/onkernel/kernel-python-sdk#accessing-raw-response-data-eg-headers + """ + return DeploymentsResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> DeploymentsResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/onkernel/kernel-python-sdk#with_streaming_response + """ + return DeploymentsResourceWithStreamingResponse(self) + + def create( + self, + *, + entrypoint_rel_path: str, + file: FileTypes, + force: bool | NotGiven = NOT_GIVEN, + region: Literal["aws.us-east-1a"] | NotGiven = NOT_GIVEN, + version: str | NotGiven = NOT_GIVEN, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> DeploymentCreateResponse: + """ + Deploy a new application + + Args: + entrypoint_rel_path: Relative path to the entrypoint of the application + + file: ZIP file containing the application source directory + + force: Allow overwriting an existing app version + + region: Region for deployment. Currently we only support "aws.us-east-1a" + + version: Version of the application. Can be any string. + + 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 + """ + body = deepcopy_minimal( + { + "entrypoint_rel_path": entrypoint_rel_path, + "file": file, + "force": force, + "region": region, + "version": version, + } + ) + files = extract_files(cast(Mapping[str, object], body), paths=[["file"]]) + # It should be noted that the actual Content-Type header that will be + # sent to the server will contain a `boundary` parameter, e.g. + # multipart/form-data; boundary=---abc-- + extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})} + return self._post( + "/deploy", + body=maybe_transform(body, deployment_create_params.DeploymentCreateParams), + files=files, + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=DeploymentCreateResponse, + ) + + +class AsyncDeploymentsResource(AsyncAPIResource): + @cached_property + def with_raw_response(self) -> AsyncDeploymentsResourceWithRawResponse: + """ + 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/onkernel/kernel-python-sdk#accessing-raw-response-data-eg-headers + """ + return AsyncDeploymentsResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncDeploymentsResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/onkernel/kernel-python-sdk#with_streaming_response + """ + return AsyncDeploymentsResourceWithStreamingResponse(self) + + async def create( + self, + *, + entrypoint_rel_path: str, + file: FileTypes, + force: bool | NotGiven = NOT_GIVEN, + region: Literal["aws.us-east-1a"] | NotGiven = NOT_GIVEN, + version: str | NotGiven = NOT_GIVEN, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> DeploymentCreateResponse: + """ + Deploy a new application + + Args: + entrypoint_rel_path: Relative path to the entrypoint of the application + + file: ZIP file containing the application source directory + + force: Allow overwriting an existing app version + + region: Region for deployment. Currently we only support "aws.us-east-1a" + + version: Version of the application. Can be any string. + + 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 + """ + body = deepcopy_minimal( + { + "entrypoint_rel_path": entrypoint_rel_path, + "file": file, + "force": force, + "region": region, + "version": version, + } + ) + files = extract_files(cast(Mapping[str, object], body), paths=[["file"]]) + # It should be noted that the actual Content-Type header that will be + # sent to the server will contain a `boundary` parameter, e.g. + # multipart/form-data; boundary=---abc-- + extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})} + return await self._post( + "/deploy", + body=await async_maybe_transform(body, deployment_create_params.DeploymentCreateParams), + files=files, + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=DeploymentCreateResponse, + ) + + +class DeploymentsResourceWithRawResponse: + def __init__(self, deployments: DeploymentsResource) -> None: + self._deployments = deployments + + self.create = to_raw_response_wrapper( + deployments.create, + ) + + +class AsyncDeploymentsResourceWithRawResponse: + def __init__(self, deployments: AsyncDeploymentsResource) -> None: + self._deployments = deployments + + self.create = async_to_raw_response_wrapper( + deployments.create, + ) + + +class DeploymentsResourceWithStreamingResponse: + def __init__(self, deployments: DeploymentsResource) -> None: + self._deployments = deployments + + self.create = to_streamed_response_wrapper( + deployments.create, + ) + + +class AsyncDeploymentsResourceWithStreamingResponse: + def __init__(self, deployments: AsyncDeploymentsResource) -> None: + self._deployments = deployments + + self.create = async_to_streamed_response_wrapper( + deployments.create, + ) diff --git a/src/kernel/resources/apps/invocations.py b/src/kernel/resources/apps/invocations.py new file mode 100644 index 0000000..4401501 --- /dev/null +++ b/src/kernel/resources/apps/invocations.py @@ -0,0 +1,280 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import httpx + +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven +from ..._utils import maybe_transform, async_maybe_transform +from ..._compat import cached_property +from ..._resource import SyncAPIResource, AsyncAPIResource +from ..._response import ( + to_raw_response_wrapper, + to_streamed_response_wrapper, + async_to_raw_response_wrapper, + async_to_streamed_response_wrapper, +) +from ...types.apps import invocation_create_params +from ..._base_client import make_request_options +from ...types.apps.invocation_create_response import InvocationCreateResponse +from ...types.apps.invocation_retrieve_response import InvocationRetrieveResponse + +__all__ = ["InvocationsResource", "AsyncInvocationsResource"] + + +class InvocationsResource(SyncAPIResource): + @cached_property + def with_raw_response(self) -> InvocationsResourceWithRawResponse: + """ + 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/onkernel/kernel-python-sdk#accessing-raw-response-data-eg-headers + """ + return InvocationsResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> InvocationsResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/onkernel/kernel-python-sdk#with_streaming_response + """ + return InvocationsResourceWithStreamingResponse(self) + + def create( + self, + *, + action_name: str, + app_name: str, + version: str, + payload: str | NotGiven = NOT_GIVEN, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> InvocationCreateResponse: + """ + Invoke an application + + Args: + action_name: Name of the action to invoke + + app_name: Name of the application + + version: Version of the application + + payload: Input data for the action, sent as a JSON string. + + 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._post( + "/invocations", + body=maybe_transform( + { + "action_name": action_name, + "app_name": app_name, + "version": version, + "payload": payload, + }, + invocation_create_params.InvocationCreateParams, + ), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=InvocationCreateResponse, + ) + + 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, + ) -> InvocationRetrieveResponse: + """ + Get an app invocation by id + + 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( + f"/invocations/{id}", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=InvocationRetrieveResponse, + ) + + +class AsyncInvocationsResource(AsyncAPIResource): + @cached_property + def with_raw_response(self) -> AsyncInvocationsResourceWithRawResponse: + """ + 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/onkernel/kernel-python-sdk#accessing-raw-response-data-eg-headers + """ + return AsyncInvocationsResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncInvocationsResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/onkernel/kernel-python-sdk#with_streaming_response + """ + return AsyncInvocationsResourceWithStreamingResponse(self) + + async def create( + self, + *, + action_name: str, + app_name: str, + version: str, + payload: str | NotGiven = NOT_GIVEN, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> InvocationCreateResponse: + """ + Invoke an application + + Args: + action_name: Name of the action to invoke + + app_name: Name of the application + + version: Version of the application + + payload: Input data for the action, sent as a JSON string. + + 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 await self._post( + "/invocations", + body=await async_maybe_transform( + { + "action_name": action_name, + "app_name": app_name, + "version": version, + "payload": payload, + }, + invocation_create_params.InvocationCreateParams, + ), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=InvocationCreateResponse, + ) + + 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, + ) -> InvocationRetrieveResponse: + """ + Get an app invocation by id + + 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( + f"/invocations/{id}", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=InvocationRetrieveResponse, + ) + + +class InvocationsResourceWithRawResponse: + def __init__(self, invocations: InvocationsResource) -> None: + self._invocations = invocations + + self.create = to_raw_response_wrapper( + invocations.create, + ) + self.retrieve = to_raw_response_wrapper( + invocations.retrieve, + ) + + +class AsyncInvocationsResourceWithRawResponse: + def __init__(self, invocations: AsyncInvocationsResource) -> None: + self._invocations = invocations + + self.create = async_to_raw_response_wrapper( + invocations.create, + ) + self.retrieve = async_to_raw_response_wrapper( + invocations.retrieve, + ) + + +class InvocationsResourceWithStreamingResponse: + def __init__(self, invocations: InvocationsResource) -> None: + self._invocations = invocations + + self.create = to_streamed_response_wrapper( + invocations.create, + ) + self.retrieve = to_streamed_response_wrapper( + invocations.retrieve, + ) + + +class AsyncInvocationsResourceWithStreamingResponse: + def __init__(self, invocations: AsyncInvocationsResource) -> None: + self._invocations = invocations + + self.create = async_to_streamed_response_wrapper( + invocations.create, + ) + self.retrieve = async_to_streamed_response_wrapper( + invocations.retrieve, + ) diff --git a/src/kernel/resources/browser.py b/src/kernel/resources/browser.py deleted file mode 100644 index 3edf8c0..0000000 --- a/src/kernel/resources/browser.py +++ /dev/null @@ -1,171 +0,0 @@ -# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -from __future__ import annotations - -import httpx - -from ..types import browser_create_session_params -from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven -from .._utils import maybe_transform, async_maybe_transform -from .._compat import cached_property -from .._resource import SyncAPIResource, AsyncAPIResource -from .._response import ( - to_raw_response_wrapper, - to_streamed_response_wrapper, - async_to_raw_response_wrapper, - async_to_streamed_response_wrapper, -) -from .._base_client import make_request_options -from ..types.browser_create_session_response import BrowserCreateSessionResponse - -__all__ = ["BrowserResource", "AsyncBrowserResource"] - - -class BrowserResource(SyncAPIResource): - @cached_property - def with_raw_response(self) -> BrowserResourceWithRawResponse: - """ - 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/onkernel/kernel-python-sdk#accessing-raw-response-data-eg-headers - """ - return BrowserResourceWithRawResponse(self) - - @cached_property - def with_streaming_response(self) -> BrowserResourceWithStreamingResponse: - """ - An alternative to `.with_raw_response` that doesn't eagerly read the response body. - - For more information, see https://www.github.com/onkernel/kernel-python-sdk#with_streaming_response - """ - return BrowserResourceWithStreamingResponse(self) - - def create_session( - self, - *, - invocation_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, - ) -> BrowserCreateSessionResponse: - """ - Create Browser Session - - Args: - invocation_id: Kernel App invocation 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._post( - "/browser", - body=maybe_transform( - {"invocation_id": invocation_id}, browser_create_session_params.BrowserCreateSessionParams - ), - options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout - ), - cast_to=BrowserCreateSessionResponse, - ) - - -class AsyncBrowserResource(AsyncAPIResource): - @cached_property - def with_raw_response(self) -> AsyncBrowserResourceWithRawResponse: - """ - 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/onkernel/kernel-python-sdk#accessing-raw-response-data-eg-headers - """ - return AsyncBrowserResourceWithRawResponse(self) - - @cached_property - def with_streaming_response(self) -> AsyncBrowserResourceWithStreamingResponse: - """ - An alternative to `.with_raw_response` that doesn't eagerly read the response body. - - For more information, see https://www.github.com/onkernel/kernel-python-sdk#with_streaming_response - """ - return AsyncBrowserResourceWithStreamingResponse(self) - - async def create_session( - self, - *, - invocation_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, - ) -> BrowserCreateSessionResponse: - """ - Create Browser Session - - Args: - invocation_id: Kernel App invocation 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 await self._post( - "/browser", - body=await async_maybe_transform( - {"invocation_id": invocation_id}, browser_create_session_params.BrowserCreateSessionParams - ), - options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout - ), - cast_to=BrowserCreateSessionResponse, - ) - - -class BrowserResourceWithRawResponse: - def __init__(self, browser: BrowserResource) -> None: - self._browser = browser - - self.create_session = to_raw_response_wrapper( - browser.create_session, - ) - - -class AsyncBrowserResourceWithRawResponse: - def __init__(self, browser: AsyncBrowserResource) -> None: - self._browser = browser - - self.create_session = async_to_raw_response_wrapper( - browser.create_session, - ) - - -class BrowserResourceWithStreamingResponse: - def __init__(self, browser: BrowserResource) -> None: - self._browser = browser - - self.create_session = to_streamed_response_wrapper( - browser.create_session, - ) - - -class AsyncBrowserResourceWithStreamingResponse: - def __init__(self, browser: AsyncBrowserResource) -> None: - self._browser = browser - - self.create_session = async_to_streamed_response_wrapper( - browser.create_session, - ) diff --git a/src/kernel/resources/browsers.py b/src/kernel/resources/browsers.py new file mode 100644 index 0000000..2aa307a --- /dev/null +++ b/src/kernel/resources/browsers.py @@ -0,0 +1,248 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import httpx + +from ..types import browser_create_params +from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven +from .._utils import maybe_transform, async_maybe_transform +from .._compat import cached_property +from .._resource import SyncAPIResource, AsyncAPIResource +from .._response import ( + to_raw_response_wrapper, + to_streamed_response_wrapper, + async_to_raw_response_wrapper, + async_to_streamed_response_wrapper, +) +from .._base_client import make_request_options +from ..types.browser_create_response import BrowserCreateResponse +from ..types.browser_retrieve_response import BrowserRetrieveResponse + +__all__ = ["BrowsersResource", "AsyncBrowsersResource"] + + +class BrowsersResource(SyncAPIResource): + @cached_property + def with_raw_response(self) -> BrowsersResourceWithRawResponse: + """ + 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/onkernel/kernel-python-sdk#accessing-raw-response-data-eg-headers + """ + return BrowsersResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> BrowsersResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/onkernel/kernel-python-sdk#with_streaming_response + """ + return BrowsersResourceWithStreamingResponse(self) + + def create( + self, + *, + invocation_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, + ) -> BrowserCreateResponse: + """ + Create Browser Session + + Args: + invocation_id: action invocation 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._post( + "/browsers", + body=maybe_transform({"invocation_id": invocation_id}, browser_create_params.BrowserCreateParams), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=BrowserCreateResponse, + ) + + 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, + ) -> BrowserRetrieveResponse: + """ + Get Browser Session by ID + + 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( + f"/browsers/{id}", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=BrowserRetrieveResponse, + ) + + +class AsyncBrowsersResource(AsyncAPIResource): + @cached_property + def with_raw_response(self) -> AsyncBrowsersResourceWithRawResponse: + """ + 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/onkernel/kernel-python-sdk#accessing-raw-response-data-eg-headers + """ + return AsyncBrowsersResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncBrowsersResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/onkernel/kernel-python-sdk#with_streaming_response + """ + return AsyncBrowsersResourceWithStreamingResponse(self) + + async def create( + self, + *, + invocation_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, + ) -> BrowserCreateResponse: + """ + Create Browser Session + + Args: + invocation_id: action invocation 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 await self._post( + "/browsers", + body=await async_maybe_transform( + {"invocation_id": invocation_id}, browser_create_params.BrowserCreateParams + ), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=BrowserCreateResponse, + ) + + 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, + ) -> BrowserRetrieveResponse: + """ + Get Browser Session by ID + + 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( + f"/browsers/{id}", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=BrowserRetrieveResponse, + ) + + +class BrowsersResourceWithRawResponse: + def __init__(self, browsers: BrowsersResource) -> None: + self._browsers = browsers + + self.create = to_raw_response_wrapper( + browsers.create, + ) + self.retrieve = to_raw_response_wrapper( + browsers.retrieve, + ) + + +class AsyncBrowsersResourceWithRawResponse: + def __init__(self, browsers: AsyncBrowsersResource) -> None: + self._browsers = browsers + + self.create = async_to_raw_response_wrapper( + browsers.create, + ) + self.retrieve = async_to_raw_response_wrapper( + browsers.retrieve, + ) + + +class BrowsersResourceWithStreamingResponse: + def __init__(self, browsers: BrowsersResource) -> None: + self._browsers = browsers + + self.create = to_streamed_response_wrapper( + browsers.create, + ) + self.retrieve = to_streamed_response_wrapper( + browsers.retrieve, + ) + + +class AsyncBrowsersResourceWithStreamingResponse: + def __init__(self, browsers: AsyncBrowsersResource) -> None: + self._browsers = browsers + + self.create = async_to_streamed_response_wrapper( + browsers.create, + ) + self.retrieve = async_to_streamed_response_wrapper( + browsers.retrieve, + ) diff --git a/src/kernel/types/__init__.py b/src/kernel/types/__init__.py index 32a4768..282c889 100644 --- a/src/kernel/types/__init__.py +++ b/src/kernel/types/__init__.py @@ -2,10 +2,6 @@ from __future__ import annotations -from .app_deploy_params import AppDeployParams as AppDeployParams -from .app_invoke_params import AppInvokeParams as AppInvokeParams -from .app_deploy_response import AppDeployResponse as AppDeployResponse -from .app_invoke_response import AppInvokeResponse as AppInvokeResponse -from .browser_create_session_params import BrowserCreateSessionParams as BrowserCreateSessionParams -from .browser_create_session_response import BrowserCreateSessionResponse as BrowserCreateSessionResponse -from .app_retrieve_invocation_response import AppRetrieveInvocationResponse as AppRetrieveInvocationResponse +from .browser_create_params import BrowserCreateParams as BrowserCreateParams +from .browser_create_response import BrowserCreateResponse as BrowserCreateResponse +from .browser_retrieve_response import BrowserRetrieveResponse as BrowserRetrieveResponse diff --git a/src/kernel/types/app_deploy_response.py b/src/kernel/types/app_deploy_response.py deleted file mode 100644 index e82164e..0000000 --- a/src/kernel/types/app_deploy_response.py +++ /dev/null @@ -1,32 +0,0 @@ -# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -from typing import List - -from .._models import BaseModel - -__all__ = ["AppDeployResponse", "App", "AppAction"] - - -class AppAction(BaseModel): - name: str - """Name of the action""" - - -class App(BaseModel): - id: str - """ID for the app version deployed""" - - actions: List[AppAction] - - name: str - """Name of the app""" - - -class AppDeployResponse(BaseModel): - apps: List[App] - - message: str - """Success message""" - - success: bool - """Status of the deployment""" diff --git a/src/kernel/types/app_invoke_params.py b/src/kernel/types/app_invoke_params.py deleted file mode 100644 index 414da98..0000000 --- a/src/kernel/types/app_invoke_params.py +++ /dev/null @@ -1,23 +0,0 @@ -# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -from __future__ import annotations - -from typing_extensions import Required, Annotated, TypedDict - -from .._utils import PropertyInfo - -__all__ = ["AppInvokeParams"] - - -class AppInvokeParams(TypedDict, total=False): - action_name: Required[Annotated[str, PropertyInfo(alias="actionName")]] - """Name of the action to invoke""" - - app_name: Required[Annotated[str, PropertyInfo(alias="appName")]] - """Name of the application""" - - payload: Required[object] - """Input data for the application""" - - version: Required[str] - """Version of the application""" diff --git a/src/kernel/types/app_invoke_response.py b/src/kernel/types/app_invoke_response.py deleted file mode 100644 index e76a9fd..0000000 --- a/src/kernel/types/app_invoke_response.py +++ /dev/null @@ -1,19 +0,0 @@ -# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -from typing import Optional -from typing_extensions import Literal - -from .._models import BaseModel - -__all__ = ["AppInvokeResponse"] - - -class AppInvokeResponse(BaseModel): - id: str - """ID of the invocation""" - - status: Literal["QUEUED", "RUNNING", "SUCCEEDED", "FAILED"] - """Status of the invocation""" - - output: Optional[str] = None - """Output from the invocation (if available)""" diff --git a/src/kernel/types/app_retrieve_invocation_response.py b/src/kernel/types/app_retrieve_invocation_response.py deleted file mode 100644 index 8b3de1f..0000000 --- a/src/kernel/types/app_retrieve_invocation_response.py +++ /dev/null @@ -1,25 +0,0 @@ -# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -from typing import Optional - -from pydantic import Field as FieldInfo - -from .._models import BaseModel - -__all__ = ["AppRetrieveInvocationResponse"] - - -class AppRetrieveInvocationResponse(BaseModel): - id: str - - app_name: str = FieldInfo(alias="appName") - - finished_at: Optional[str] = FieldInfo(alias="finishedAt", default=None) - - input: str - - output: str - - started_at: str = FieldInfo(alias="startedAt") - - status: str diff --git a/src/kernel/types/apps/__init__.py b/src/kernel/types/apps/__init__.py new file mode 100644 index 0000000..f4d451c --- /dev/null +++ b/src/kernel/types/apps/__init__.py @@ -0,0 +1,9 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from .deployment_create_params import DeploymentCreateParams as DeploymentCreateParams +from .invocation_create_params import InvocationCreateParams as InvocationCreateParams +from .deployment_create_response import DeploymentCreateResponse as DeploymentCreateResponse +from .invocation_create_response import InvocationCreateResponse as InvocationCreateResponse +from .invocation_retrieve_response import InvocationRetrieveResponse as InvocationRetrieveResponse diff --git a/src/kernel/types/app_deploy_params.py b/src/kernel/types/apps/deployment_create_params.py similarity index 60% rename from src/kernel/types/app_deploy_params.py rename to src/kernel/types/apps/deployment_create_params.py index 790743d..92ff258 100644 --- a/src/kernel/types/app_deploy_params.py +++ b/src/kernel/types/apps/deployment_create_params.py @@ -2,22 +2,21 @@ from __future__ import annotations -from typing_extensions import Literal, Required, Annotated, TypedDict +from typing_extensions import Literal, Required, TypedDict -from .._types import FileTypes -from .._utils import PropertyInfo +from ..._types import FileTypes -__all__ = ["AppDeployParams"] +__all__ = ["DeploymentCreateParams"] -class AppDeployParams(TypedDict, total=False): - entrypoint_rel_path: Required[Annotated[str, PropertyInfo(alias="entrypointRelPath")]] +class DeploymentCreateParams(TypedDict, total=False): + entrypoint_rel_path: Required[str] """Relative path to the entrypoint of the application""" file: Required[FileTypes] """ZIP file containing the application source directory""" - force: Literal["true", "false"] + force: bool """Allow overwriting an existing app version""" region: Literal["aws.us-east-1a"] diff --git a/src/kernel/types/apps/deployment_create_response.py b/src/kernel/types/apps/deployment_create_response.py new file mode 100644 index 0000000..f801195 --- /dev/null +++ b/src/kernel/types/apps/deployment_create_response.py @@ -0,0 +1,35 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import List, Optional +from typing_extensions import Literal + +from ..._models import BaseModel + +__all__ = ["DeploymentCreateResponse", "App", "AppAction"] + + +class AppAction(BaseModel): + name: str + """Name of the action""" + + +class App(BaseModel): + id: str + """ID for the app version deployed""" + + actions: List[AppAction] + """List of actions available on the app""" + + name: str + """Name of the app""" + + +class DeploymentCreateResponse(BaseModel): + apps: List[App] + """List of apps deployed""" + + status: Literal["queued", "deploying", "succeeded", "failed"] + """Current status of the deployment""" + + status_reason: Optional[str] = None + """Status reason""" diff --git a/src/kernel/types/apps/invocation_create_params.py b/src/kernel/types/apps/invocation_create_params.py new file mode 100644 index 0000000..a97a2c5 --- /dev/null +++ b/src/kernel/types/apps/invocation_create_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__ = ["InvocationCreateParams"] + + +class InvocationCreateParams(TypedDict, total=False): + action_name: Required[str] + """Name of the action to invoke""" + + app_name: Required[str] + """Name of the application""" + + version: Required[str] + """Version of the application""" + + payload: str + """Input data for the action, sent as a JSON string.""" diff --git a/src/kernel/types/apps/invocation_create_response.py b/src/kernel/types/apps/invocation_create_response.py new file mode 100644 index 0000000..df4a166 --- /dev/null +++ b/src/kernel/types/apps/invocation_create_response.py @@ -0,0 +1,25 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Optional +from typing_extensions import Literal + +from ..._models import BaseModel + +__all__ = ["InvocationCreateResponse"] + + +class InvocationCreateResponse(BaseModel): + id: str + """ID of the invocation""" + + status: Literal["queued", "running", "succeeded", "failed"] + """Status of the invocation""" + + output: Optional[str] = None + """The return value of the action that was invoked, rendered as a JSON string. + + This could be: string, number, boolean, array, object, or null. + """ + + status_reason: Optional[str] = None + """Status reason""" diff --git a/src/kernel/types/apps/invocation_retrieve_response.py b/src/kernel/types/apps/invocation_retrieve_response.py new file mode 100644 index 0000000..f328b14 --- /dev/null +++ b/src/kernel/types/apps/invocation_retrieve_response.py @@ -0,0 +1,47 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Optional +from datetime import datetime +from typing_extensions import Literal + +from ..._models import BaseModel + +__all__ = ["InvocationRetrieveResponse"] + + +class InvocationRetrieveResponse(BaseModel): + id: str + """ID of the invocation""" + + action_name: str + """Name of the action invoked""" + + app_name: str + """Name of the application""" + + started_at: datetime + """RFC 3339 Nanoseconds timestamp when the invocation started""" + + status: Literal["queued", "running", "succeeded", "failed"] + """Status of the invocation""" + + finished_at: Optional[datetime] = None + """ + RFC 3339 Nanoseconds timestamp when the invocation finished (null if still + running) + """ + + output: Optional[str] = None + """Output produced by the action, rendered as a JSON string. + + This could be: string, number, boolean, array, object, or null. + """ + + payload: Optional[str] = None + """Payload provided to the invocation. + + This is a string that can be parsed as JSON. + """ + + status_reason: Optional[str] = None + """Status reason""" diff --git a/src/kernel/types/browser_create_params.py b/src/kernel/types/browser_create_params.py new file mode 100644 index 0000000..0944a61 --- /dev/null +++ b/src/kernel/types/browser_create_params.py @@ -0,0 +1,12 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing_extensions import Required, TypedDict + +__all__ = ["BrowserCreateParams"] + + +class BrowserCreateParams(TypedDict, total=False): + invocation_id: Required[str] + """action invocation ID""" diff --git a/src/kernel/types/browser_create_session_response.py b/src/kernel/types/browser_create_response.py similarity index 62% rename from src/kernel/types/browser_create_session_response.py rename to src/kernel/types/browser_create_response.py index d4e46da..647dfc8 100644 --- a/src/kernel/types/browser_create_session_response.py +++ b/src/kernel/types/browser_create_response.py @@ -1,18 +1,16 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -from pydantic import Field as FieldInfo - from .._models import BaseModel -__all__ = ["BrowserCreateSessionResponse"] +__all__ = ["BrowserCreateResponse"] + +class BrowserCreateResponse(BaseModel): + browser_live_view_url: str + """Remote URL for live viewing the browser session""" -class BrowserCreateSessionResponse(BaseModel): cdp_ws_url: str """Websocket URL for Chrome DevTools Protocol connections to the browser session""" - remote_url: str - """Remote URL for live viewing the browser session""" - - session_id: str = FieldInfo(alias="sessionId") + session_id: str """Unique identifier for the browser session""" diff --git a/src/kernel/types/browser_create_session_params.py b/src/kernel/types/browser_create_session_params.py deleted file mode 100644 index 73389be..0000000 --- a/src/kernel/types/browser_create_session_params.py +++ /dev/null @@ -1,14 +0,0 @@ -# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -from __future__ import annotations - -from typing_extensions import Required, Annotated, TypedDict - -from .._utils import PropertyInfo - -__all__ = ["BrowserCreateSessionParams"] - - -class BrowserCreateSessionParams(TypedDict, total=False): - invocation_id: Required[Annotated[str, PropertyInfo(alias="invocationId")]] - """Kernel App invocation ID""" diff --git a/src/kernel/types/browser_retrieve_response.py b/src/kernel/types/browser_retrieve_response.py new file mode 100644 index 0000000..e84bb01 --- /dev/null +++ b/src/kernel/types/browser_retrieve_response.py @@ -0,0 +1,16 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from .._models import BaseModel + +__all__ = ["BrowserRetrieveResponse"] + + +class BrowserRetrieveResponse(BaseModel): + browser_live_view_url: str + """Remote URL for live viewing the browser session""" + + cdp_ws_url: str + """Websocket URL for Chrome DevTools Protocol connections to the browser session""" + + session_id: str + """Unique identifier for the browser session""" diff --git a/tests/api_resources/apps/__init__.py b/tests/api_resources/apps/__init__.py new file mode 100644 index 0000000..fd8019a --- /dev/null +++ b/tests/api_resources/apps/__init__.py @@ -0,0 +1 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. diff --git a/tests/api_resources/apps/test_deployments.py b/tests/api_resources/apps/test_deployments.py new file mode 100644 index 0000000..e2f2a3d --- /dev/null +++ b/tests/api_resources/apps/test_deployments.py @@ -0,0 +1,120 @@ +# 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.apps import DeploymentCreateResponse + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestDeployments: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @pytest.mark.skip() + @parametrize + def test_method_create(self, client: Kernel) -> None: + deployment = client.apps.deployments.create( + entrypoint_rel_path="src/app.py", + file=b"raw file contents", + ) + assert_matches_type(DeploymentCreateResponse, deployment, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_method_create_with_all_params(self, client: Kernel) -> None: + deployment = client.apps.deployments.create( + entrypoint_rel_path="src/app.py", + file=b"raw file contents", + force=False, + region="aws.us-east-1a", + version="1.0.0", + ) + assert_matches_type(DeploymentCreateResponse, deployment, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_raw_response_create(self, client: Kernel) -> None: + response = client.apps.deployments.with_raw_response.create( + entrypoint_rel_path="src/app.py", + file=b"raw file contents", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + deployment = response.parse() + assert_matches_type(DeploymentCreateResponse, deployment, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_streaming_response_create(self, client: Kernel) -> None: + with client.apps.deployments.with_streaming_response.create( + entrypoint_rel_path="src/app.py", + file=b"raw file contents", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + deployment = response.parse() + assert_matches_type(DeploymentCreateResponse, deployment, path=["response"]) + + assert cast(Any, response.is_closed) is True + + +class TestAsyncDeployments: + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + + @pytest.mark.skip() + @parametrize + async def test_method_create(self, async_client: AsyncKernel) -> None: + deployment = await async_client.apps.deployments.create( + entrypoint_rel_path="src/app.py", + file=b"raw file contents", + ) + assert_matches_type(DeploymentCreateResponse, deployment, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_method_create_with_all_params(self, async_client: AsyncKernel) -> None: + deployment = await async_client.apps.deployments.create( + entrypoint_rel_path="src/app.py", + file=b"raw file contents", + force=False, + region="aws.us-east-1a", + version="1.0.0", + ) + assert_matches_type(DeploymentCreateResponse, deployment, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_raw_response_create(self, async_client: AsyncKernel) -> None: + response = await async_client.apps.deployments.with_raw_response.create( + entrypoint_rel_path="src/app.py", + file=b"raw file contents", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + deployment = await response.parse() + assert_matches_type(DeploymentCreateResponse, deployment, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_streaming_response_create(self, async_client: AsyncKernel) -> None: + async with async_client.apps.deployments.with_streaming_response.create( + entrypoint_rel_path="src/app.py", + file=b"raw file contents", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + deployment = await response.parse() + assert_matches_type(DeploymentCreateResponse, deployment, path=["response"]) + + assert cast(Any, response.is_closed) is True diff --git a/tests/api_resources/apps/test_invocations.py b/tests/api_resources/apps/test_invocations.py new file mode 100644 index 0000000..61af031 --- /dev/null +++ b/tests/api_resources/apps/test_invocations.py @@ -0,0 +1,208 @@ +# 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.apps import InvocationCreateResponse, InvocationRetrieveResponse + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestInvocations: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @pytest.mark.skip() + @parametrize + def test_method_create(self, client: Kernel) -> None: + invocation = client.apps.invocations.create( + action_name="analyze", + app_name="my-app", + version="1.0.0", + ) + assert_matches_type(InvocationCreateResponse, invocation, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_method_create_with_all_params(self, client: Kernel) -> None: + invocation = client.apps.invocations.create( + action_name="analyze", + app_name="my-app", + version="1.0.0", + payload='{"data":"example input"}', + ) + assert_matches_type(InvocationCreateResponse, invocation, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_raw_response_create(self, client: Kernel) -> None: + response = client.apps.invocations.with_raw_response.create( + action_name="analyze", + app_name="my-app", + version="1.0.0", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + invocation = response.parse() + assert_matches_type(InvocationCreateResponse, invocation, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_streaming_response_create(self, client: Kernel) -> None: + with client.apps.invocations.with_streaming_response.create( + action_name="analyze", + app_name="my-app", + version="1.0.0", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + invocation = response.parse() + assert_matches_type(InvocationCreateResponse, invocation, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + def test_method_retrieve(self, client: Kernel) -> None: + invocation = client.apps.invocations.retrieve( + "id", + ) + assert_matches_type(InvocationRetrieveResponse, invocation, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_raw_response_retrieve(self, client: Kernel) -> None: + response = client.apps.invocations.with_raw_response.retrieve( + "id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + invocation = response.parse() + assert_matches_type(InvocationRetrieveResponse, invocation, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_streaming_response_retrieve(self, client: Kernel) -> None: + with client.apps.invocations.with_streaming_response.retrieve( + "id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + invocation = response.parse() + assert_matches_type(InvocationRetrieveResponse, invocation, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @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.apps.invocations.with_raw_response.retrieve( + "", + ) + + +class TestAsyncInvocations: + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + + @pytest.mark.skip() + @parametrize + async def test_method_create(self, async_client: AsyncKernel) -> None: + invocation = await async_client.apps.invocations.create( + action_name="analyze", + app_name="my-app", + version="1.0.0", + ) + assert_matches_type(InvocationCreateResponse, invocation, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_method_create_with_all_params(self, async_client: AsyncKernel) -> None: + invocation = await async_client.apps.invocations.create( + action_name="analyze", + app_name="my-app", + version="1.0.0", + payload='{"data":"example input"}', + ) + assert_matches_type(InvocationCreateResponse, invocation, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_raw_response_create(self, async_client: AsyncKernel) -> None: + response = await async_client.apps.invocations.with_raw_response.create( + action_name="analyze", + app_name="my-app", + version="1.0.0", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + invocation = await response.parse() + assert_matches_type(InvocationCreateResponse, invocation, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_streaming_response_create(self, async_client: AsyncKernel) -> None: + async with async_client.apps.invocations.with_streaming_response.create( + action_name="analyze", + app_name="my-app", + version="1.0.0", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + invocation = await response.parse() + assert_matches_type(InvocationCreateResponse, invocation, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + async def test_method_retrieve(self, async_client: AsyncKernel) -> None: + invocation = await async_client.apps.invocations.retrieve( + "id", + ) + assert_matches_type(InvocationRetrieveResponse, invocation, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_raw_response_retrieve(self, async_client: AsyncKernel) -> None: + response = await async_client.apps.invocations.with_raw_response.retrieve( + "id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + invocation = await response.parse() + assert_matches_type(InvocationRetrieveResponse, invocation, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_streaming_response_retrieve(self, async_client: AsyncKernel) -> None: + async with async_client.apps.invocations.with_streaming_response.retrieve( + "id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + invocation = await response.parse() + assert_matches_type(InvocationRetrieveResponse, invocation, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @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.apps.invocations.with_raw_response.retrieve( + "", + ) diff --git a/tests/api_resources/test_apps.py b/tests/api_resources/test_apps.py deleted file mode 100644 index 8719486..0000000 --- a/tests/api_resources/test_apps.py +++ /dev/null @@ -1,294 +0,0 @@ -# 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 ( - AppDeployResponse, - AppInvokeResponse, - AppRetrieveInvocationResponse, -) - -base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") - - -class TestApps: - parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) - - @pytest.mark.skip() - @parametrize - def test_method_deploy(self, client: Kernel) -> None: - app = client.apps.deploy( - entrypoint_rel_path="app.py", - file=b"raw file contents", - ) - assert_matches_type(AppDeployResponse, app, path=["response"]) - - @pytest.mark.skip() - @parametrize - def test_method_deploy_with_all_params(self, client: Kernel) -> None: - app = client.apps.deploy( - entrypoint_rel_path="app.py", - file=b"raw file contents", - force="false", - region="aws.us-east-1a", - version="1.0.0", - ) - assert_matches_type(AppDeployResponse, app, path=["response"]) - - @pytest.mark.skip() - @parametrize - def test_raw_response_deploy(self, client: Kernel) -> None: - response = client.apps.with_raw_response.deploy( - entrypoint_rel_path="app.py", - file=b"raw file contents", - ) - - assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - app = response.parse() - assert_matches_type(AppDeployResponse, app, path=["response"]) - - @pytest.mark.skip() - @parametrize - def test_streaming_response_deploy(self, client: Kernel) -> None: - with client.apps.with_streaming_response.deploy( - entrypoint_rel_path="app.py", - file=b"raw file contents", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - - app = response.parse() - assert_matches_type(AppDeployResponse, app, path=["response"]) - - assert cast(Any, response.is_closed) is True - - @pytest.mark.skip() - @parametrize - def test_method_invoke(self, client: Kernel) -> None: - app = client.apps.invoke( - action_name="analyze", - app_name="my-awesome-app", - payload={"data": "example input"}, - version="1.0.0", - ) - assert_matches_type(AppInvokeResponse, app, path=["response"]) - - @pytest.mark.skip() - @parametrize - def test_raw_response_invoke(self, client: Kernel) -> None: - response = client.apps.with_raw_response.invoke( - action_name="analyze", - app_name="my-awesome-app", - payload={"data": "example input"}, - version="1.0.0", - ) - - assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - app = response.parse() - assert_matches_type(AppInvokeResponse, app, path=["response"]) - - @pytest.mark.skip() - @parametrize - def test_streaming_response_invoke(self, client: Kernel) -> None: - with client.apps.with_streaming_response.invoke( - action_name="analyze", - app_name="my-awesome-app", - payload={"data": "example input"}, - version="1.0.0", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - - app = response.parse() - assert_matches_type(AppInvokeResponse, app, path=["response"]) - - assert cast(Any, response.is_closed) is True - - @pytest.mark.skip() - @parametrize - def test_method_retrieve_invocation(self, client: Kernel) -> None: - app = client.apps.retrieve_invocation( - "id", - ) - assert_matches_type(AppRetrieveInvocationResponse, app, path=["response"]) - - @pytest.mark.skip() - @parametrize - def test_raw_response_retrieve_invocation(self, client: Kernel) -> None: - response = client.apps.with_raw_response.retrieve_invocation( - "id", - ) - - assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - app = response.parse() - assert_matches_type(AppRetrieveInvocationResponse, app, path=["response"]) - - @pytest.mark.skip() - @parametrize - def test_streaming_response_retrieve_invocation(self, client: Kernel) -> None: - with client.apps.with_streaming_response.retrieve_invocation( - "id", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - - app = response.parse() - assert_matches_type(AppRetrieveInvocationResponse, app, path=["response"]) - - assert cast(Any, response.is_closed) is True - - @pytest.mark.skip() - @parametrize - def test_path_params_retrieve_invocation(self, client: Kernel) -> None: - with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): - client.apps.with_raw_response.retrieve_invocation( - "", - ) - - -class TestAsyncApps: - parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) - - @pytest.mark.skip() - @parametrize - async def test_method_deploy(self, async_client: AsyncKernel) -> None: - app = await async_client.apps.deploy( - entrypoint_rel_path="app.py", - file=b"raw file contents", - ) - assert_matches_type(AppDeployResponse, app, path=["response"]) - - @pytest.mark.skip() - @parametrize - async def test_method_deploy_with_all_params(self, async_client: AsyncKernel) -> None: - app = await async_client.apps.deploy( - entrypoint_rel_path="app.py", - file=b"raw file contents", - force="false", - region="aws.us-east-1a", - version="1.0.0", - ) - assert_matches_type(AppDeployResponse, app, path=["response"]) - - @pytest.mark.skip() - @parametrize - async def test_raw_response_deploy(self, async_client: AsyncKernel) -> None: - response = await async_client.apps.with_raw_response.deploy( - entrypoint_rel_path="app.py", - file=b"raw file contents", - ) - - assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - app = await response.parse() - assert_matches_type(AppDeployResponse, app, path=["response"]) - - @pytest.mark.skip() - @parametrize - async def test_streaming_response_deploy(self, async_client: AsyncKernel) -> None: - async with async_client.apps.with_streaming_response.deploy( - entrypoint_rel_path="app.py", - file=b"raw file contents", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - - app = await response.parse() - assert_matches_type(AppDeployResponse, app, path=["response"]) - - assert cast(Any, response.is_closed) is True - - @pytest.mark.skip() - @parametrize - async def test_method_invoke(self, async_client: AsyncKernel) -> None: - app = await async_client.apps.invoke( - action_name="analyze", - app_name="my-awesome-app", - payload={"data": "example input"}, - version="1.0.0", - ) - assert_matches_type(AppInvokeResponse, app, path=["response"]) - - @pytest.mark.skip() - @parametrize - async def test_raw_response_invoke(self, async_client: AsyncKernel) -> None: - response = await async_client.apps.with_raw_response.invoke( - action_name="analyze", - app_name="my-awesome-app", - payload={"data": "example input"}, - version="1.0.0", - ) - - assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - app = await response.parse() - assert_matches_type(AppInvokeResponse, app, path=["response"]) - - @pytest.mark.skip() - @parametrize - async def test_streaming_response_invoke(self, async_client: AsyncKernel) -> None: - async with async_client.apps.with_streaming_response.invoke( - action_name="analyze", - app_name="my-awesome-app", - payload={"data": "example input"}, - version="1.0.0", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - - app = await response.parse() - assert_matches_type(AppInvokeResponse, app, path=["response"]) - - assert cast(Any, response.is_closed) is True - - @pytest.mark.skip() - @parametrize - async def test_method_retrieve_invocation(self, async_client: AsyncKernel) -> None: - app = await async_client.apps.retrieve_invocation( - "id", - ) - assert_matches_type(AppRetrieveInvocationResponse, app, path=["response"]) - - @pytest.mark.skip() - @parametrize - async def test_raw_response_retrieve_invocation(self, async_client: AsyncKernel) -> None: - response = await async_client.apps.with_raw_response.retrieve_invocation( - "id", - ) - - assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - app = await response.parse() - assert_matches_type(AppRetrieveInvocationResponse, app, path=["response"]) - - @pytest.mark.skip() - @parametrize - async def test_streaming_response_retrieve_invocation(self, async_client: AsyncKernel) -> None: - async with async_client.apps.with_streaming_response.retrieve_invocation( - "id", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - - app = await response.parse() - assert_matches_type(AppRetrieveInvocationResponse, app, path=["response"]) - - assert cast(Any, response.is_closed) is True - - @pytest.mark.skip() - @parametrize - async def test_path_params_retrieve_invocation(self, async_client: AsyncKernel) -> None: - with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): - await async_client.apps.with_raw_response.retrieve_invocation( - "", - ) diff --git a/tests/api_resources/test_browser.py b/tests/api_resources/test_browser.py deleted file mode 100644 index 3280e05..0000000 --- a/tests/api_resources/test_browser.py +++ /dev/null @@ -1,90 +0,0 @@ -# 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 BrowserCreateSessionResponse - -base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") - - -class TestBrowser: - parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) - - @pytest.mark.skip() - @parametrize - def test_method_create_session(self, client: Kernel) -> None: - browser = client.browser.create_session( - invocation_id="invocationId", - ) - assert_matches_type(BrowserCreateSessionResponse, browser, path=["response"]) - - @pytest.mark.skip() - @parametrize - def test_raw_response_create_session(self, client: Kernel) -> None: - response = client.browser.with_raw_response.create_session( - invocation_id="invocationId", - ) - - assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - browser = response.parse() - assert_matches_type(BrowserCreateSessionResponse, browser, path=["response"]) - - @pytest.mark.skip() - @parametrize - def test_streaming_response_create_session(self, client: Kernel) -> None: - with client.browser.with_streaming_response.create_session( - invocation_id="invocationId", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - - browser = response.parse() - assert_matches_type(BrowserCreateSessionResponse, browser, path=["response"]) - - assert cast(Any, response.is_closed) is True - - -class TestAsyncBrowser: - parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) - - @pytest.mark.skip() - @parametrize - async def test_method_create_session(self, async_client: AsyncKernel) -> None: - browser = await async_client.browser.create_session( - invocation_id="invocationId", - ) - assert_matches_type(BrowserCreateSessionResponse, browser, path=["response"]) - - @pytest.mark.skip() - @parametrize - async def test_raw_response_create_session(self, async_client: AsyncKernel) -> None: - response = await async_client.browser.with_raw_response.create_session( - invocation_id="invocationId", - ) - - assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - browser = await response.parse() - assert_matches_type(BrowserCreateSessionResponse, browser, path=["response"]) - - @pytest.mark.skip() - @parametrize - async def test_streaming_response_create_session(self, async_client: AsyncKernel) -> None: - async with async_client.browser.with_streaming_response.create_session( - invocation_id="invocationId", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - - browser = await response.parse() - assert_matches_type(BrowserCreateSessionResponse, browser, path=["response"]) - - assert cast(Any, response.is_closed) is True diff --git a/tests/api_resources/test_browsers.py b/tests/api_resources/test_browsers.py new file mode 100644 index 0000000..91fc83e --- /dev/null +++ b/tests/api_resources/test_browsers.py @@ -0,0 +1,174 @@ +# 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 BrowserCreateResponse, BrowserRetrieveResponse + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestBrowsers: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @pytest.mark.skip() + @parametrize + def test_method_create(self, client: Kernel) -> None: + browser = client.browsers.create( + invocation_id="ckqwer3o20000jb9s7abcdef", + ) + assert_matches_type(BrowserCreateResponse, browser, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_raw_response_create(self, client: Kernel) -> None: + response = client.browsers.with_raw_response.create( + invocation_id="ckqwer3o20000jb9s7abcdef", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + browser = response.parse() + assert_matches_type(BrowserCreateResponse, browser, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_streaming_response_create(self, client: Kernel) -> None: + with client.browsers.with_streaming_response.create( + invocation_id="ckqwer3o20000jb9s7abcdef", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + browser = response.parse() + assert_matches_type(BrowserCreateResponse, browser, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + def test_method_retrieve(self, client: Kernel) -> None: + browser = client.browsers.retrieve( + "id", + ) + assert_matches_type(BrowserRetrieveResponse, browser, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_raw_response_retrieve(self, client: Kernel) -> None: + response = client.browsers.with_raw_response.retrieve( + "id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + browser = response.parse() + assert_matches_type(BrowserRetrieveResponse, browser, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_streaming_response_retrieve(self, client: Kernel) -> None: + with client.browsers.with_streaming_response.retrieve( + "id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + browser = response.parse() + assert_matches_type(BrowserRetrieveResponse, browser, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @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.browsers.with_raw_response.retrieve( + "", + ) + + +class TestAsyncBrowsers: + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + + @pytest.mark.skip() + @parametrize + async def test_method_create(self, async_client: AsyncKernel) -> None: + browser = await async_client.browsers.create( + invocation_id="ckqwer3o20000jb9s7abcdef", + ) + assert_matches_type(BrowserCreateResponse, browser, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_raw_response_create(self, async_client: AsyncKernel) -> None: + response = await async_client.browsers.with_raw_response.create( + invocation_id="ckqwer3o20000jb9s7abcdef", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + browser = await response.parse() + assert_matches_type(BrowserCreateResponse, browser, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_streaming_response_create(self, async_client: AsyncKernel) -> None: + async with async_client.browsers.with_streaming_response.create( + invocation_id="ckqwer3o20000jb9s7abcdef", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + browser = await response.parse() + assert_matches_type(BrowserCreateResponse, browser, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + async def test_method_retrieve(self, async_client: AsyncKernel) -> None: + browser = await async_client.browsers.retrieve( + "id", + ) + assert_matches_type(BrowserRetrieveResponse, browser, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_raw_response_retrieve(self, async_client: AsyncKernel) -> None: + response = await async_client.browsers.with_raw_response.retrieve( + "id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + browser = await response.parse() + assert_matches_type(BrowserRetrieveResponse, browser, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_streaming_response_retrieve(self, async_client: AsyncKernel) -> None: + async with async_client.browsers.with_streaming_response.retrieve( + "id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + browser = await response.parse() + assert_matches_type(BrowserRetrieveResponse, browser, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @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.browsers.with_raw_response.retrieve( + "", + ) diff --git a/tests/test_client.py b/tests/test_client.py index 0ed12bf..a2d2dd1 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -28,7 +28,7 @@ from kernel._constants import RAW_RESPONSE_HEADER from kernel._exceptions import KernelError, APIStatusError, APITimeoutError, APIResponseValidationError from kernel._base_client import DEFAULT_TIMEOUT, HTTPX_DEFAULT_TIMEOUT, BaseClient, make_request_options -from kernel.types.app_deploy_params import AppDeployParams +from kernel.types.browser_create_params import BrowserCreateParams from .utils import update_env @@ -716,17 +716,12 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str @mock.patch("kernel._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) @pytest.mark.respx(base_url=base_url) def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: - respx_mock.post("/apps/deploy").mock(side_effect=httpx.TimeoutException("Test timeout error")) + respx_mock.post("/browsers").mock(side_effect=httpx.TimeoutException("Test timeout error")) with pytest.raises(APITimeoutError): self.client.post( - "/apps/deploy", - body=cast( - object, - maybe_transform( - dict(entrypoint_rel_path="app.py", file=b"REPLACE_ME", version="REPLACE_ME"), AppDeployParams - ), - ), + "/browsers", + body=cast(object, maybe_transform(dict(invocation_id="REPLACE_ME"), BrowserCreateParams)), cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, ) @@ -737,17 +732,12 @@ def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> No @mock.patch("kernel._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) @pytest.mark.respx(base_url=base_url) def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: - respx_mock.post("/apps/deploy").mock(return_value=httpx.Response(500)) + respx_mock.post("/browsers").mock(return_value=httpx.Response(500)) with pytest.raises(APIStatusError): self.client.post( - "/apps/deploy", - body=cast( - object, - maybe_transform( - dict(entrypoint_rel_path="app.py", file=b"REPLACE_ME", version="REPLACE_ME"), AppDeployParams - ), - ), + "/browsers", + body=cast(object, maybe_transform(dict(invocation_id="REPLACE_ME"), BrowserCreateParams)), cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, ) @@ -778,9 +768,9 @@ def retry_handler(_request: httpx.Request) -> httpx.Response: return httpx.Response(500) return httpx.Response(200) - respx_mock.post("/apps/deploy").mock(side_effect=retry_handler) + respx_mock.post("/browsers").mock(side_effect=retry_handler) - response = client.apps.with_raw_response.deploy(entrypoint_rel_path="app.py", file=b"raw file contents") + response = client.browsers.with_raw_response.create(invocation_id="ckqwer3o20000jb9s7abcdef") assert response.retries_taken == failures_before_success assert int(response.http_request.headers.get("x-stainless-retry-count")) == failures_before_success @@ -802,10 +792,10 @@ def retry_handler(_request: httpx.Request) -> httpx.Response: return httpx.Response(500) return httpx.Response(200) - respx_mock.post("/apps/deploy").mock(side_effect=retry_handler) + respx_mock.post("/browsers").mock(side_effect=retry_handler) - response = client.apps.with_raw_response.deploy( - entrypoint_rel_path="app.py", file=b"raw file contents", extra_headers={"x-stainless-retry-count": Omit()} + response = client.browsers.with_raw_response.create( + invocation_id="ckqwer3o20000jb9s7abcdef", extra_headers={"x-stainless-retry-count": Omit()} ) assert len(response.http_request.headers.get_list("x-stainless-retry-count")) == 0 @@ -827,10 +817,10 @@ def retry_handler(_request: httpx.Request) -> httpx.Response: return httpx.Response(500) return httpx.Response(200) - respx_mock.post("/apps/deploy").mock(side_effect=retry_handler) + respx_mock.post("/browsers").mock(side_effect=retry_handler) - response = client.apps.with_raw_response.deploy( - entrypoint_rel_path="app.py", file=b"raw file contents", extra_headers={"x-stainless-retry-count": "42"} + response = client.browsers.with_raw_response.create( + invocation_id="ckqwer3o20000jb9s7abcdef", extra_headers={"x-stainless-retry-count": "42"} ) assert response.http_request.headers.get("x-stainless-retry-count") == "42" @@ -1518,17 +1508,12 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte @mock.patch("kernel._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) @pytest.mark.respx(base_url=base_url) async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: - respx_mock.post("/apps/deploy").mock(side_effect=httpx.TimeoutException("Test timeout error")) + respx_mock.post("/browsers").mock(side_effect=httpx.TimeoutException("Test timeout error")) with pytest.raises(APITimeoutError): await self.client.post( - "/apps/deploy", - body=cast( - object, - maybe_transform( - dict(entrypoint_rel_path="app.py", file=b"REPLACE_ME", version="REPLACE_ME"), AppDeployParams - ), - ), + "/browsers", + body=cast(object, maybe_transform(dict(invocation_id="REPLACE_ME"), BrowserCreateParams)), cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, ) @@ -1539,17 +1524,12 @@ async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) @mock.patch("kernel._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) @pytest.mark.respx(base_url=base_url) async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: - respx_mock.post("/apps/deploy").mock(return_value=httpx.Response(500)) + respx_mock.post("/browsers").mock(return_value=httpx.Response(500)) with pytest.raises(APIStatusError): await self.client.post( - "/apps/deploy", - body=cast( - object, - maybe_transform( - dict(entrypoint_rel_path="app.py", file=b"REPLACE_ME", version="REPLACE_ME"), AppDeployParams - ), - ), + "/browsers", + body=cast(object, maybe_transform(dict(invocation_id="REPLACE_ME"), BrowserCreateParams)), cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, ) @@ -1581,9 +1561,9 @@ def retry_handler(_request: httpx.Request) -> httpx.Response: return httpx.Response(500) return httpx.Response(200) - respx_mock.post("/apps/deploy").mock(side_effect=retry_handler) + respx_mock.post("/browsers").mock(side_effect=retry_handler) - response = await client.apps.with_raw_response.deploy(entrypoint_rel_path="app.py", file=b"raw file contents") + response = await client.browsers.with_raw_response.create(invocation_id="ckqwer3o20000jb9s7abcdef") assert response.retries_taken == failures_before_success assert int(response.http_request.headers.get("x-stainless-retry-count")) == failures_before_success @@ -1606,10 +1586,10 @@ def retry_handler(_request: httpx.Request) -> httpx.Response: return httpx.Response(500) return httpx.Response(200) - respx_mock.post("/apps/deploy").mock(side_effect=retry_handler) + respx_mock.post("/browsers").mock(side_effect=retry_handler) - response = await client.apps.with_raw_response.deploy( - entrypoint_rel_path="app.py", file=b"raw file contents", extra_headers={"x-stainless-retry-count": Omit()} + response = await client.browsers.with_raw_response.create( + invocation_id="ckqwer3o20000jb9s7abcdef", extra_headers={"x-stainless-retry-count": Omit()} ) assert len(response.http_request.headers.get_list("x-stainless-retry-count")) == 0 @@ -1632,10 +1612,10 @@ def retry_handler(_request: httpx.Request) -> httpx.Response: return httpx.Response(500) return httpx.Response(200) - respx_mock.post("/apps/deploy").mock(side_effect=retry_handler) + respx_mock.post("/browsers").mock(side_effect=retry_handler) - response = await client.apps.with_raw_response.deploy( - entrypoint_rel_path="app.py", file=b"raw file contents", extra_headers={"x-stainless-retry-count": "42"} + response = await client.browsers.with_raw_response.create( + invocation_id="ckqwer3o20000jb9s7abcdef", extra_headers={"x-stainless-retry-count": "42"} ) assert response.http_request.headers.get("x-stainless-retry-count") == "42"