Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.1.0-alpha.12"
".": "0.1.0-alpha.13"
}
8 changes: 4 additions & 4 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 7
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-c9d64df733f286f09d2203f4e3d820ce57e8d4c629c5e2db4e2bfac91fbc1598.yml
openapi_spec_hash: fa407611fc566d55f403864fbfaa6c23
config_hash: 7f67c5b95af1e4b39525515240b72275
configured_endpoints: 6
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-19b0d17ba368f32827ee322d15a7f4ff7e1f3bbf66606fad227b3465f8ffc5ab.yml
openapi_spec_hash: 4a3cb766898e8a134ef99fe6c4c87736
config_hash: 4dfa4d870ce0e23e31ce33ab6a53dd21
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 0.1.0-alpha.13 (2025-05-20)

Full Changelog: [v0.1.0-alpha.12...v0.1.0-alpha.13](https://github.com/onkernel/kernel-python-sdk/compare/v0.1.0-alpha.12...v0.1.0-alpha.13)

### Features

* **api:** update via SDK Studio ([c528c7b](https://github.com/onkernel/kernel-python-sdk/commit/c528c7b45adac371fddfdc2792a435f814b03d67))

## 0.1.0-alpha.12 (2025-05-19)

Full Changelog: [v0.1.0-alpha.11...v0.1.0-alpha.12](https://github.com/onkernel/kernel-python-sdk/compare/v0.1.0-alpha.11...v0.1.0-alpha.12)
Expand Down
10 changes: 0 additions & 10 deletions api.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
# Apps

Types:

```python
from kernel.types import AppListResponse
```

Methods:

- <code title="get /apps">client.apps.<a href="./src/kernel/resources/apps/apps.py">list</a>(\*\*<a href="src/kernel/types/app_list_params.py">params</a>) -> <a href="./src/kernel/types/app_list_response.py">AppListResponse</a></code>

## Deployments

Types:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "kernel"
version = "0.1.0-alpha.12"
version = "0.1.0-alpha.13"
description = "The official Python library for the kernel API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

__title__ = "kernel"
__version__ = "0.1.0-alpha.12" # x-release-please-version
__version__ = "0.1.0-alpha.13" # x-release-please-version
87 changes: 46 additions & 41 deletions src/kernel/app_framework.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import inspect
import functools
from typing import Any, Dict, List, Union, TypeVar, Callable, Optional
from typing import Any, Dict, List, TypeVar, Callable, Optional
from dataclasses import dataclass

T = TypeVar("T")
Expand Down Expand Up @@ -44,53 +44,58 @@ def __init__(self, name: str):
# Register this app in the global registry
_app_registry.register_app(self)

def action(self, name_or_handler: Optional[Union[str, Callable[..., Any]]] = None) -> Callable[..., Any]:
"""Decorator to register an action with the app"""
if name_or_handler is None:
# This is the @app.action() case, which should return the decorator
def decorator(f: Callable[..., Any]) -> Callable[..., Any]:
return self._register_action(f.__name__, f)
return decorator
elif callable(name_or_handler):
# This is the @app.action case (handler passed directly)
return self._register_action(name_or_handler.__name__, name_or_handler)
else:
# This is the @app.action("name") case (name_or_handler is a string)
def decorator(f: Callable[..., Any]) -> Callable[..., Any]:
return self._register_action(name_or_handler, f) # name_or_handler is the name string here
return decorator
def action(self, name: str) -> Callable[..., Any]:
"""
Decorator to register an action with the app

Usage:
@app.action("action-name")
def my_handler(ctx: KernelContext):
# ...

@app.action("action-with-payload")
def my_handler(ctx: KernelContext, payload: dict):
# ...
"""
def decorator(handler: Callable[..., Any]) -> Callable[..., Any]:
return self._register_action(name, handler)
return decorator

def _register_action(self, name: str, handler: Callable[..., Any]) -> Callable[..., Any]:
"""Internal method to register an action"""
# Validate handler signature
sig = inspect.signature(handler)
param_count = len(sig.parameters)

if param_count == 0:
raise TypeError("Action handler must accept at least the context parameter")
elif param_count > 2:
raise TypeError("Action handler can only accept context and payload parameters")

param_names = list(sig.parameters.keys())

@functools.wraps(handler)
def wrapper(*args: Any, **kwargs: Any) -> Any:
# Determine if the original handler accepts context as first argument
sig = inspect.signature(handler)
param_names = list(sig.parameters.keys())
param_count = len(param_names)

# Ensure the first argument is the context
if not args or not isinstance(args[0], KernelContext):
raise TypeError("First argument to action handler must be a KernelContext")

ctx = args[0]

if param_count == 1:
actual_input = None
# The handler only takes input
if len(args) > 0: # Prioritize args if context was implicitly passed
# If context (args[0]) and input (args[1]) were provided, or just input (args[0])
actual_input = args[1] if len(args) > 1 else args[0]
elif kwargs:
# Attempt to find the single expected kwarg
if param_names: # Should always be true if param_count == 1
param_name = param_names[0]
if param_name in kwargs:
actual_input = kwargs[param_name]
elif kwargs: # Fallback if name doesn't match but kwargs exist
actual_input = next(iter(kwargs.values()))
elif kwargs: # param_names is empty but kwargs exist (unlikely for param_count==1)
actual_input = next(iter(kwargs.values()))
# If no args/kwargs, actual_input remains None, handler might raise error or accept None
return handler(actual_input)
else: # param_count == 0 or param_count > 1
# Handler takes context and input (or more), or no args
return handler(*args, **kwargs)
# Handler takes only context
return handler(ctx)
else: # param_count == 2
# Handler takes context and payload
if len(args) >= 2:
return handler(ctx, args[1])
else:
# Try to find payload in kwargs
payload_name = param_names[1]
if payload_name in kwargs:
return handler(ctx, kwargs[payload_name])
else:
raise TypeError(f"Missing required payload parameter '{payload_name}'")

action = KernelAction(name=name, handler=wrapper)
self.actions[name] = action
Expand Down
125 changes: 0 additions & 125 deletions src/kernel/resources/apps/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,8 @@

from __future__ import annotations

import httpx

from ...types import app_list_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 .deployments import (
DeploymentsResource,
AsyncDeploymentsResource,
Expand All @@ -31,8 +20,6 @@
InvocationsResourceWithStreamingResponse,
AsyncInvocationsResourceWithStreamingResponse,
)
from ..._base_client import make_request_options
from ...types.app_list_response import AppListResponse

__all__ = ["AppsResource", "AsyncAppsResource"]

Expand Down Expand Up @@ -65,54 +52,6 @@ def with_streaming_response(self) -> AppsResourceWithStreamingResponse:
"""
return AppsResourceWithStreamingResponse(self)

def list(
self,
*,
app_name: str | 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,
) -> AppListResponse:
"""List application versions for the authenticated user.

Optionally filter by app
name and/or version label.

Args:
app_name: Filter results by application name.

version: Filter results by version label.

extra_headers: Send extra headers

extra_query: Add additional query parameters to the request

extra_body: Add additional JSON properties to the request

timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get(
"/apps",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"app_name": app_name,
"version": version,
},
app_list_params.AppListParams,
),
),
cast_to=AppListResponse,
)


class AsyncAppsResource(AsyncAPIResource):
@cached_property
Expand Down Expand Up @@ -142,63 +81,11 @@ def with_streaming_response(self) -> AsyncAppsResourceWithStreamingResponse:
"""
return AsyncAppsResourceWithStreamingResponse(self)

async def list(
self,
*,
app_name: str | 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,
) -> AppListResponse:
"""List application versions for the authenticated user.

Optionally filter by app
name and/or version label.

Args:
app_name: Filter results by application name.

version: Filter results by version label.

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._get(
"/apps",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=await async_maybe_transform(
{
"app_name": app_name,
"version": version,
},
app_list_params.AppListParams,
),
),
cast_to=AppListResponse,
)


class AppsResourceWithRawResponse:
def __init__(self, apps: AppsResource) -> None:
self._apps = apps

self.list = to_raw_response_wrapper(
apps.list,
)

@cached_property
def deployments(self) -> DeploymentsResourceWithRawResponse:
return DeploymentsResourceWithRawResponse(self._apps.deployments)
Expand All @@ -212,10 +99,6 @@ class AsyncAppsResourceWithRawResponse:
def __init__(self, apps: AsyncAppsResource) -> None:
self._apps = apps

self.list = async_to_raw_response_wrapper(
apps.list,
)

@cached_property
def deployments(self) -> AsyncDeploymentsResourceWithRawResponse:
return AsyncDeploymentsResourceWithRawResponse(self._apps.deployments)
Expand All @@ -229,10 +112,6 @@ class AppsResourceWithStreamingResponse:
def __init__(self, apps: AppsResource) -> None:
self._apps = apps

self.list = to_streamed_response_wrapper(
apps.list,
)

@cached_property
def deployments(self) -> DeploymentsResourceWithStreamingResponse:
return DeploymentsResourceWithStreamingResponse(self._apps.deployments)
Expand All @@ -246,10 +125,6 @@ class AsyncAppsResourceWithStreamingResponse:
def __init__(self, apps: AsyncAppsResource) -> None:
self._apps = apps

self.list = async_to_streamed_response_wrapper(
apps.list,
)

@cached_property
def deployments(self) -> AsyncDeploymentsResourceWithStreamingResponse:
return AsyncDeploymentsResourceWithStreamingResponse(self._apps.deployments)
Expand Down
2 changes: 0 additions & 2 deletions src/kernel/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from __future__ import annotations

from .app_list_params import AppListParams as AppListParams
from .app_list_response import AppListResponse as AppListResponse
from .browser_create_params import BrowserCreateParams as BrowserCreateParams
from .browser_create_response import BrowserCreateResponse as BrowserCreateResponse
from .browser_retrieve_response import BrowserRetrieveResponse as BrowserRetrieveResponse
15 changes: 0 additions & 15 deletions src/kernel/types/app_list_params.py

This file was deleted.

Loading