Skip to content

Commit

Permalink
feat(api): api update (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] committed Jan 23, 2025
1 parent 7b9eb8e commit b2f6eda
Show file tree
Hide file tree
Showing 7 changed files with 458 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 14
configured_endpoints: 15
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/riza%2Friza-api-53d443fce326642ac4579e178d39bd12a49ed8230f1264bda8da4c805d4ae71f.yml
3 changes: 2 additions & 1 deletion api.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ Methods:
Types:

```python
from rizaio.types import CommandExecResponse
from rizaio.types import CommandExecResponse, CommandExecFuncResponse
```

Methods:

- <code title="post /v1/execute">client.command.<a href="./src/rizaio/resources/command.py">exec</a>(\*\*<a href="src/rizaio/types/command_exec_params.py">params</a>) -> <a href="./src/rizaio/types/command_exec_response.py">CommandExecResponse</a></code>
- <code title="post /v1/execute-function">client.command.<a href="./src/rizaio/resources/command.py">exec_func</a>(\*\*<a href="src/rizaio/types/command_exec_func_params.py">params</a>) -> <a href="./src/rizaio/types/command_exec_func_response.py">CommandExecFuncResponse</a></code>

# Runtimes

Expand Down
151 changes: 150 additions & 1 deletion src/rizaio/resources/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import httpx

from ..types import command_exec_params
from ..types import command_exec_params, command_exec_func_params
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven
from .._utils import (
maybe_transform,
Expand All @@ -23,6 +23,7 @@
)
from .._base_client import make_request_options
from ..types.command_exec_response import CommandExecResponse
from ..types.command_exec_func_response import CommandExecFuncResponse

__all__ = ["CommandResource", "AsyncCommandResource"]

Expand Down Expand Up @@ -125,6 +126,74 @@ def exec(
cast_to=CommandExecResponse,
)

def exec_func(
self,
*,
code: str,
language: Literal["python", "javascript", "typescript", "ruby", "php"],
env: Dict[str, str] | NotGiven = NOT_GIVEN,
files: Iterable[command_exec_func_params.File] | NotGiven = NOT_GIVEN,
http: Optional[command_exec_func_params.HTTP] | NotGiven = NOT_GIVEN,
input: object | NotGiven = NOT_GIVEN,
limits: Optional[command_exec_func_params.Limits] | NotGiven = NOT_GIVEN,
runtime_revision_id: 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,
) -> CommandExecFuncResponse:
"""Run a function in a secure, isolated environment.
Define a function named
`execute`. The function will be passed `input` as an object.
Args:
code: The function to execute. Your code must define a function named 'execute' and
return a JSON-serializable value.
language: The interpreter to use when executing code.
env: Set of key-value pairs to add to the script's execution environment.
files: List of input files.
http: Configuration for HTTP requests and authentication.
limits: Configuration for execution environment limits.
runtime_revision_id: The ID of the runtime revision to use when executing code.
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(
"/v1/execute-function",
body=maybe_transform(
{
"code": code,
"language": language,
"env": env,
"files": files,
"http": http,
"input": input,
"limits": limits,
"runtime_revision_id": runtime_revision_id,
},
command_exec_func_params.CommandExecFuncParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=CommandExecFuncResponse,
)


class AsyncCommandResource(AsyncAPIResource):
@cached_property
Expand Down Expand Up @@ -224,6 +293,74 @@ async def exec(
cast_to=CommandExecResponse,
)

async def exec_func(
self,
*,
code: str,
language: Literal["python", "javascript", "typescript", "ruby", "php"],
env: Dict[str, str] | NotGiven = NOT_GIVEN,
files: Iterable[command_exec_func_params.File] | NotGiven = NOT_GIVEN,
http: Optional[command_exec_func_params.HTTP] | NotGiven = NOT_GIVEN,
input: object | NotGiven = NOT_GIVEN,
limits: Optional[command_exec_func_params.Limits] | NotGiven = NOT_GIVEN,
runtime_revision_id: 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,
) -> CommandExecFuncResponse:
"""Run a function in a secure, isolated environment.
Define a function named
`execute`. The function will be passed `input` as an object.
Args:
code: The function to execute. Your code must define a function named 'execute' and
return a JSON-serializable value.
language: The interpreter to use when executing code.
env: Set of key-value pairs to add to the script's execution environment.
files: List of input files.
http: Configuration for HTTP requests and authentication.
limits: Configuration for execution environment limits.
runtime_revision_id: The ID of the runtime revision to use when executing code.
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(
"/v1/execute-function",
body=await async_maybe_transform(
{
"code": code,
"language": language,
"env": env,
"files": files,
"http": http,
"input": input,
"limits": limits,
"runtime_revision_id": runtime_revision_id,
},
command_exec_func_params.CommandExecFuncParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=CommandExecFuncResponse,
)


class CommandResourceWithRawResponse:
def __init__(self, command: CommandResource) -> None:
Expand All @@ -232,6 +369,9 @@ def __init__(self, command: CommandResource) -> None:
self.exec = to_raw_response_wrapper(
command.exec,
)
self.exec_func = to_raw_response_wrapper(
command.exec_func,
)


class AsyncCommandResourceWithRawResponse:
Expand All @@ -241,6 +381,9 @@ def __init__(self, command: AsyncCommandResource) -> None:
self.exec = async_to_raw_response_wrapper(
command.exec,
)
self.exec_func = async_to_raw_response_wrapper(
command.exec_func,
)


class CommandResourceWithStreamingResponse:
Expand All @@ -250,6 +393,9 @@ def __init__(self, command: CommandResource) -> None:
self.exec = to_streamed_response_wrapper(
command.exec,
)
self.exec_func = to_streamed_response_wrapper(
command.exec_func,
)


class AsyncCommandResourceWithStreamingResponse:
Expand All @@ -259,3 +405,6 @@ def __init__(self, command: AsyncCommandResource) -> None:
self.exec = async_to_streamed_response_wrapper(
command.exec,
)
self.exec_func = async_to_streamed_response_wrapper(
command.exec_func,
)
2 changes: 2 additions & 0 deletions src/rizaio/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
from .command_exec_response import CommandExecResponse as CommandExecResponse
from .runtime_create_params import RuntimeCreateParams as RuntimeCreateParams
from .runtime_list_response import RuntimeListResponse as RuntimeListResponse
from .command_exec_func_params import CommandExecFuncParams as CommandExecFuncParams
from .command_exec_func_response import CommandExecFuncResponse as CommandExecFuncResponse
111 changes: 111 additions & 0 deletions src/rizaio/types/command_exec_func_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

from typing import Dict, Iterable, Optional
from typing_extensions import Literal, Required, TypedDict

__all__ = [
"CommandExecFuncParams",
"File",
"HTTP",
"HTTPAllow",
"HTTPAllowAuth",
"HTTPAllowAuthBasic",
"HTTPAllowAuthBearer",
"HTTPAllowAuthHeader",
"HTTPAllowAuthQuery",
"Limits",
]


class CommandExecFuncParams(TypedDict, total=False):
code: Required[str]
"""The function to execute.
Your code must define a function named 'execute' and return a JSON-serializable
value.
"""

language: Required[Literal["python", "javascript", "typescript", "ruby", "php"]]
"""The interpreter to use when executing code."""

env: Dict[str, str]
"""Set of key-value pairs to add to the script's execution environment."""

files: Iterable[File]
"""List of input files."""

http: Optional[HTTP]
"""Configuration for HTTP requests and authentication."""

input: object

limits: Optional[Limits]
"""Configuration for execution environment limits."""

runtime_revision_id: str
"""The ID of the runtime revision to use when executing code."""


class File(TypedDict, total=False):
contents: str
"""The contents of the file."""

path: str
"""The relative path of the file."""


class HTTPAllowAuthBasic(TypedDict, total=False):
password: str

user_id: str


class HTTPAllowAuthBearer(TypedDict, total=False):
token: str
"""The token to set, e.g. 'Authorization: Bearer <token>'."""


class HTTPAllowAuthHeader(TypedDict, total=False):
name: str

value: str


class HTTPAllowAuthQuery(TypedDict, total=False):
key: str

value: str


class HTTPAllowAuth(TypedDict, total=False):
basic: Optional[HTTPAllowAuthBasic]

bearer: Optional[HTTPAllowAuthBearer]
"""Configuration to add an 'Authorization' header using the 'Bearer' scheme."""

header: Optional[HTTPAllowAuthHeader]

query: Optional[HTTPAllowAuthQuery]


class HTTPAllow(TypedDict, total=False):
auth: HTTPAllowAuth
"""Authentication configuration for outbound requests to this host."""

host: str
"""The hostname to allow."""


class HTTP(TypedDict, total=False):
allow: Iterable[HTTPAllow]
"""List of allowed HTTP hosts and associated authentication."""


class Limits(TypedDict, total=False):
execution_timeout: int
"""The maximum time allowed for execution (in seconds). Default is 30."""

memory_size: int
"""The maximum memory allowed for execution (in MiB). Default is 128."""
37 changes: 37 additions & 0 deletions src/rizaio/types/command_exec_func_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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__ = ["CommandExecFuncResponse", "Execution"]


class Execution(BaseModel):
exit_code: Optional[int] = None
"""The exit code returned by the script.
Will often be '0' on success and non-zero on failure.
"""

stderr: Optional[str] = None
"""The contents of 'stderr' after executing the script."""

stdout: Optional[str] = None
"""The contents of 'stdout' after executing the script."""


class CommandExecFuncResponse(BaseModel):
execution: Optional[Execution] = None

output: Optional[object] = None

output_status: Optional[Literal["error", "json_serialization_error", "valid"]] = None
"""The status of the output.
"valid" means your function executed successfully and returned a valid
JSON-serializable object, or void. "json_serialization_error" means your
function executed successfully, but returned a nonserializable object. "error"
means your function failed to execute.
"""
Loading

0 comments on commit b2f6eda

Please sign in to comment.