# This file was auto-generated by Fern from our API Definition.

import typing
from json.decoder import JSONDecodeError

from ..core.api_error import ApiError
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.http_response import AsyncHttpResponse, HttpResponse
from ..core.jsonable_encoder import jsonable_encoder
from ..core.pydantic_utilities import parse_obj_as
from ..core.request_options import RequestOptions
from ..errors.unprocessable_entity_error import UnprocessableEntityError
from ..types.http_validation_error import HttpValidationError
from ..types.response import Response
from ..types.response_bash_exec_result import ResponseBashExecResult
from ..types.response_bash_output_result import ResponseBashOutputResult
from ..types.response_bash_session_info import ResponseBashSessionInfo
from ..types.response_list_bash_session_info import ResponseListBashSessionInfo

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class RawBashClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper

    def exec(
        self,
        *,
        command: str,
        session_id: typing.Optional[str] = OMIT,
        exec_dir: typing.Optional[str] = OMIT,
        env: typing.Optional[typing.Dict[str, typing.Optional[str]]] = OMIT,
        async_mode: typing.Optional[bool] = OMIT,
        timeout: typing.Optional[float] = OMIT,
        hard_timeout: typing.Optional[float] = OMIT,
        max_output_length: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[ResponseBashExecResult]:
        """
        Execute a bash command.

        - async_mode=true: returns immediately with RUNNING status
        - async_mode=false + timeout: waits up to timeout, then returns RUNNING if not done
        - async_mode=false + no timeout: waits until command completes
        - hard_timeout: kills the process after this many seconds
        - env: extra environment variables for this command only

        Parameters
        ----------
        command : str
            Shell command to execute

        session_id : typing.Optional[str]
            Target session ID. If not provided, a new session is created automatically.

        exec_dir : typing.Optional[str]
            Working directory for command execution (absolute path)

        env : typing.Optional[typing.Dict[str, typing.Optional[str]]]
            Extra environment variables to inject for this command only.

        async_mode : typing.Optional[bool]
            If true, return immediately with running status. Use /output to poll results.

        timeout : typing.Optional[float]
            HTTP timeout (seconds). Only effective when async_mode=false. If the command does not complete within this time, HTTP returns running status and the command continues in the background. Use /output to get results.

        hard_timeout : typing.Optional[float]
            Hard execution timeout (seconds). When reached, the process is killed and status becomes timed_out. None means no limit.

        max_output_length : typing.Optional[int]
            Maximum character length for stdout/stderr in the response. When output exceeds this limit, middle truncation is applied (head and tail preserved, middle replaced with a marker). Only effective in sync mode (async_mode=false). Set to 0 to disable truncation.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[ResponseBashExecResult]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/bash/exec",
            method="POST",
            json={
                "session_id": session_id,
                "command": command,
                "exec_dir": exec_dir,
                "env": env,
                "async_mode": async_mode,
                "timeout": timeout,
                "hard_timeout": hard_timeout,
                "max_output_length": max_output_length,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ResponseBashExecResult,
                    parse_obj_as(
                        type_=ResponseBashExecResult,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def output(
        self,
        *,
        session_id: str,
        command_id: typing.Optional[str] = OMIT,
        offset: typing.Optional[int] = OMIT,
        stderr_offset: typing.Optional[int] = OMIT,
        wait: typing.Optional[bool] = OMIT,
        wait_timeout: typing.Optional[float] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[ResponseBashOutputResult]:
        """
        Read output from a bash session using offset-based streaming.

        - offset/stderr_offset: byte offsets to read from (use values from previous response)
        - wait=true: long-poll until new output arrives or wait_timeout

        Parameters
        ----------
        session_id : str
            Target session ID

        command_id : typing.Optional[str]
            Target a specific async command. If not set, uses session-level output.

        offset : typing.Optional[int]
            Stdout byte offset to read from

        stderr_offset : typing.Optional[int]
            Stderr byte offset to read from

        wait : typing.Optional[bool]
            If true, long-poll until new output is available or wait_timeout is reached.

        wait_timeout : typing.Optional[float]
            Max seconds to wait for new output when wait=true.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[ResponseBashOutputResult]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/bash/output",
            method="POST",
            json={
                "session_id": session_id,
                "command_id": command_id,
                "offset": offset,
                "stderr_offset": stderr_offset,
                "wait": wait,
                "wait_timeout": wait_timeout,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ResponseBashOutputResult,
                    parse_obj_as(
                        type_=ResponseBashOutputResult,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def write(
        self,
        *,
        session_id: str,
        input: str,
        command_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[Response]:
        """
        Write input to a bash session's stdin.

        Parameters
        ----------
        session_id : str
            Target session ID

        input : str
            Content to write to the process stdin

        command_id : typing.Optional[str]
            Target a specific async command. If not set, writes to current command.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[Response]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/bash/write",
            method="POST",
            json={
                "session_id": session_id,
                "command_id": command_id,
                "input": input,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    Response,
                    parse_obj_as(
                        type_=Response,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def kill(
        self,
        *,
        session_id: str,
        signal: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[Response]:
        """
        Send a signal to a bash session's process.

        Parameters
        ----------
        session_id : str
            Target session ID

        signal : typing.Optional[str]
            Signal to send: SIGTERM, SIGKILL, or SIGINT

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[Response]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/bash/kill",
            method="POST",
            json={
                "session_id": session_id,
                "signal": signal,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    Response,
                    parse_obj_as(
                        type_=Response,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def sessions(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[ResponseListBashSessionInfo]:
        """
        List all active bash sessions.

        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[ResponseListBashSessionInfo]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/bash/sessions",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ResponseListBashSessionInfo,
                    parse_obj_as(
                        type_=ResponseListBashSessionInfo,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def create_session(
        self,
        *,
        session_id: typing.Optional[str] = OMIT,
        exec_dir: typing.Optional[str] = OMIT,
        snapshot_path: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[ResponseBashSessionInfo]:
        """
        Create a new bash session.

        Parameters
        ----------
        session_id : typing.Optional[str]
            Session ID. Auto-generated if not provided.

        exec_dir : typing.Optional[str]
            Working directory for the new session (absolute path)

        snapshot_path : typing.Optional[str]
            Path to a shell snapshot script to source on session init

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[ResponseBashSessionInfo]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/bash/sessions/create",
            method="POST",
            json={
                "session_id": session_id,
                "exec_dir": exec_dir,
                "snapshot_path": snapshot_path,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ResponseBashSessionInfo,
                    parse_obj_as(
                        type_=ResponseBashSessionInfo,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def close_session(
        self, session_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[Response]:
        """
        Close a bash session.

        Parameters
        ----------
        session_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[Response]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/bash/sessions/{jsonable_encoder(session_id)}/close",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    Response,
                    parse_obj_as(
                        type_=Response,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)


class AsyncRawBashClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def exec(
        self,
        *,
        command: str,
        session_id: typing.Optional[str] = OMIT,
        exec_dir: typing.Optional[str] = OMIT,
        env: typing.Optional[typing.Dict[str, typing.Optional[str]]] = OMIT,
        async_mode: typing.Optional[bool] = OMIT,
        timeout: typing.Optional[float] = OMIT,
        hard_timeout: typing.Optional[float] = OMIT,
        max_output_length: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[ResponseBashExecResult]:
        """
        Execute a bash command.

        - async_mode=true: returns immediately with RUNNING status
        - async_mode=false + timeout: waits up to timeout, then returns RUNNING if not done
        - async_mode=false + no timeout: waits until command completes
        - hard_timeout: kills the process after this many seconds
        - env: extra environment variables for this command only

        Parameters
        ----------
        command : str
            Shell command to execute

        session_id : typing.Optional[str]
            Target session ID. If not provided, a new session is created automatically.

        exec_dir : typing.Optional[str]
            Working directory for command execution (absolute path)

        env : typing.Optional[typing.Dict[str, typing.Optional[str]]]
            Extra environment variables to inject for this command only.

        async_mode : typing.Optional[bool]
            If true, return immediately with running status. Use /output to poll results.

        timeout : typing.Optional[float]
            HTTP timeout (seconds). Only effective when async_mode=false. If the command does not complete within this time, HTTP returns running status and the command continues in the background. Use /output to get results.

        hard_timeout : typing.Optional[float]
            Hard execution timeout (seconds). When reached, the process is killed and status becomes timed_out. None means no limit.

        max_output_length : typing.Optional[int]
            Maximum character length for stdout/stderr in the response. When output exceeds this limit, middle truncation is applied (head and tail preserved, middle replaced with a marker). Only effective in sync mode (async_mode=false). Set to 0 to disable truncation.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[ResponseBashExecResult]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/bash/exec",
            method="POST",
            json={
                "session_id": session_id,
                "command": command,
                "exec_dir": exec_dir,
                "env": env,
                "async_mode": async_mode,
                "timeout": timeout,
                "hard_timeout": hard_timeout,
                "max_output_length": max_output_length,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ResponseBashExecResult,
                    parse_obj_as(
                        type_=ResponseBashExecResult,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def output(
        self,
        *,
        session_id: str,
        command_id: typing.Optional[str] = OMIT,
        offset: typing.Optional[int] = OMIT,
        stderr_offset: typing.Optional[int] = OMIT,
        wait: typing.Optional[bool] = OMIT,
        wait_timeout: typing.Optional[float] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[ResponseBashOutputResult]:
        """
        Read output from a bash session using offset-based streaming.

        - offset/stderr_offset: byte offsets to read from (use values from previous response)
        - wait=true: long-poll until new output arrives or wait_timeout

        Parameters
        ----------
        session_id : str
            Target session ID

        command_id : typing.Optional[str]
            Target a specific async command. If not set, uses session-level output.

        offset : typing.Optional[int]
            Stdout byte offset to read from

        stderr_offset : typing.Optional[int]
            Stderr byte offset to read from

        wait : typing.Optional[bool]
            If true, long-poll until new output is available or wait_timeout is reached.

        wait_timeout : typing.Optional[float]
            Max seconds to wait for new output when wait=true.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[ResponseBashOutputResult]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/bash/output",
            method="POST",
            json={
                "session_id": session_id,
                "command_id": command_id,
                "offset": offset,
                "stderr_offset": stderr_offset,
                "wait": wait,
                "wait_timeout": wait_timeout,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ResponseBashOutputResult,
                    parse_obj_as(
                        type_=ResponseBashOutputResult,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def write(
        self,
        *,
        session_id: str,
        input: str,
        command_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[Response]:
        """
        Write input to a bash session's stdin.

        Parameters
        ----------
        session_id : str
            Target session ID

        input : str
            Content to write to the process stdin

        command_id : typing.Optional[str]
            Target a specific async command. If not set, writes to current command.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[Response]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/bash/write",
            method="POST",
            json={
                "session_id": session_id,
                "command_id": command_id,
                "input": input,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    Response,
                    parse_obj_as(
                        type_=Response,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def kill(
        self,
        *,
        session_id: str,
        signal: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[Response]:
        """
        Send a signal to a bash session's process.

        Parameters
        ----------
        session_id : str
            Target session ID

        signal : typing.Optional[str]
            Signal to send: SIGTERM, SIGKILL, or SIGINT

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[Response]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/bash/kill",
            method="POST",
            json={
                "session_id": session_id,
                "signal": signal,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    Response,
                    parse_obj_as(
                        type_=Response,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def sessions(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[ResponseListBashSessionInfo]:
        """
        List all active bash sessions.

        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[ResponseListBashSessionInfo]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/bash/sessions",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ResponseListBashSessionInfo,
                    parse_obj_as(
                        type_=ResponseListBashSessionInfo,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def create_session(
        self,
        *,
        session_id: typing.Optional[str] = OMIT,
        exec_dir: typing.Optional[str] = OMIT,
        snapshot_path: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[ResponseBashSessionInfo]:
        """
        Create a new bash session.

        Parameters
        ----------
        session_id : typing.Optional[str]
            Session ID. Auto-generated if not provided.

        exec_dir : typing.Optional[str]
            Working directory for the new session (absolute path)

        snapshot_path : typing.Optional[str]
            Path to a shell snapshot script to source on session init

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[ResponseBashSessionInfo]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/bash/sessions/create",
            method="POST",
            json={
                "session_id": session_id,
                "exec_dir": exec_dir,
                "snapshot_path": snapshot_path,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ResponseBashSessionInfo,
                    parse_obj_as(
                        type_=ResponseBashSessionInfo,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def close_session(
        self, session_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[Response]:
        """
        Close a bash session.

        Parameters
        ----------
        session_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[Response]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/bash/sessions/{jsonable_encoder(session_id)}/close",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    Response,
                    parse_obj_as(
                        type_=Response,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
