# 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.personal_knowledge_settings_response import PersonalKnowledgeSettingsResponse
from ..types.personal_store_file_list_response import PersonalStoreFileListResponse
from ..types.personal_store_file_response import PersonalStoreFileResponse
from ..types.personal_store_list_response import PersonalStoreListResponse
from ..types.personal_store_response import PersonalStoreResponse
from ..types.teach_response import TeachResponse

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


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

    def list_personal_stores(
        self,
        *,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[PersonalStoreListResponse]:
        """
        Retrieve all personal vector stores for the authenticated user. Returns stores ordered by creation date, with the default store included.

        Parameters
        ----------
        limit : typing.Optional[int]
            Number of stores to return

        offset : typing.Optional[int]
            Number of stores to skip

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

        Returns
        -------
        HttpResponse[PersonalStoreListResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/me/knowledge/stores",
            method="GET",
            params={
                "limit": limit,
                "offset": offset,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PersonalStoreListResponse,
                    parse_obj_as(
                        type_=PersonalStoreListResponse,  # 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(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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 create_personal_store(
        self,
        *,
        name: str,
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[PersonalStoreResponse]:
        """
        Create an additional personal vector store. Each user can have multiple stores to organize different topics.

        Parameters
        ----------
        name : str
            Store name

        description : typing.Optional[str]
            Optional description

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

        Returns
        -------
        HttpResponse[PersonalStoreResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/me/knowledge/stores",
            method="POST",
            json={
                "name": name,
                "description": description,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PersonalStoreResponse,
                    parse_obj_as(
                        type_=PersonalStoreResponse,  # 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(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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 get_personal_store(
        self, store_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[PersonalStoreResponse]:
        """
        Retrieve details of a specific personal vector store. Only accessible by the store owner.

        Parameters
        ----------
        store_id : str

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

        Returns
        -------
        HttpResponse[PersonalStoreResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/me/knowledge/stores/{jsonable_encoder(store_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PersonalStoreResponse,
                    parse_obj_as(
                        type_=PersonalStoreResponse,  # 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(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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 delete_personal_store(
        self, store_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[None]:
        """
        Delete a personal vector store. The default store cannot be deleted (returns 409).

        Parameters
        ----------
        store_id : str

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

        Returns
        -------
        HttpResponse[None]
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/me/knowledge/stores/{jsonable_encoder(store_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return HttpResponse(response=_response, data=None)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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 update_personal_store(
        self,
        store_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[PersonalStoreResponse]:
        """
        Update the name or description of a personal vector store.

        Parameters
        ----------
        store_id : str

        name : typing.Optional[str]

        description : typing.Optional[str]

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

        Returns
        -------
        HttpResponse[PersonalStoreResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/me/knowledge/stores/{jsonable_encoder(store_id)}",
            method="PATCH",
            json={
                "name": name,
                "description": description,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PersonalStoreResponse,
                    parse_obj_as(
                        type_=PersonalStoreResponse,  # 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(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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 list_store_files(
        self,
        store_id: str,
        *,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[PersonalStoreFileListResponse]:
        """
        Retrieve all files associated with a personal vector store. Returns files ordered by when they were added.

        Parameters
        ----------
        store_id : str

        limit : typing.Optional[int]
            Number of files to return

        offset : typing.Optional[int]
            Number of files to skip

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

        Returns
        -------
        HttpResponse[PersonalStoreFileListResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/me/knowledge/stores/{jsonable_encoder(store_id)}/files",
            method="GET",
            params={
                "limit": limit,
                "offset": offset,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PersonalStoreFileListResponse,
                    parse_obj_as(
                        type_=PersonalStoreFileListResponse,  # 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(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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 add_file_to_store(
        self, store_id: str, *, file_id: str, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[PersonalStoreFileResponse]:
        """
        Associate an existing file with a personal vector store. The file must already be uploaded via the POST /v1/files endpoint.

        Parameters
        ----------
        store_id : str

        file_id : str
            ID of a previously uploaded file

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

        Returns
        -------
        HttpResponse[PersonalStoreFileResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/me/knowledge/stores/{jsonable_encoder(store_id)}/files",
            method="POST",
            json={
                "file_id": file_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PersonalStoreFileResponse,
                    parse_obj_as(
                        type_=PersonalStoreFileResponse,  # 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(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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 remove_file_from_store(
        self, store_id: str, file_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[None]:
        """
        Remove a file association from a personal vector store. This does not delete the underlying file.

        Parameters
        ----------
        store_id : str

        file_id : str

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

        Returns
        -------
        HttpResponse[None]
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/me/knowledge/stores/{jsonable_encoder(store_id)}/files/{jsonable_encoder(file_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return HttpResponse(response=_response, data=None)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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 teach(
        self,
        *,
        content: str,
        store_id: typing.Optional[str] = OMIT,
        category: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[TeachResponse]:
        """
        Submit free-text content to be chunked, embedded, and stored in the user's personal vector store. If no store_id is specified, uses the default personal store. Content is limited to 10,000 characters.

        Parameters
        ----------
        content : str
            Text content to add as personal knowledge

        store_id : typing.Optional[str]
            Target store ID. Uses default if not specified.

        category : typing.Optional[str]
            Optional category tag for the content

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

        Returns
        -------
        HttpResponse[TeachResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/me/knowledge/teach",
            method="POST",
            json={
                "content": content,
                "store_id": store_id,
                "category": category,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    TeachResponse,
                    parse_obj_as(
                        type_=TeachResponse,  # 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(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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 get_settings(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[PersonalKnowledgeSettingsResponse]:
        """
        Retrieve the authenticated user's personal knowledge settings. Auto-provisions defaults on first access — always returns 200, never 404.

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

        Returns
        -------
        HttpResponse[PersonalKnowledgeSettingsResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/me/knowledge/settings",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PersonalKnowledgeSettingsResponse,
                    parse_obj_as(
                        type_=PersonalKnowledgeSettingsResponse,  # 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 update_settings(
        self,
        *,
        revision: int,
        memories_enabled: typing.Optional[bool] = OMIT,
        auto_extract_enabled: typing.Optional[bool] = OMIT,
        personal_knowledge_enabled: typing.Optional[bool] = OMIT,
        config: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[PersonalKnowledgeSettingsResponse]:
        """
        Update the authenticated user's personal knowledge settings with optimistic concurrency. The revision field must match the current server revision or a 409 Conflict will be returned.

        Parameters
        ----------
        revision : int
            Required for optimistic concurrency — must match current server revision

        memories_enabled : typing.Optional[bool]
            Enable/disable memories feature

        auto_extract_enabled : typing.Optional[bool]
            Enable/disable automatic memory extraction from conversations

        personal_knowledge_enabled : typing.Optional[bool]
            Enable/disable personal knowledge stores

        config : typing.Optional[typing.Dict[str, typing.Any]]
            Additional configuration overrides

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

        Returns
        -------
        HttpResponse[PersonalKnowledgeSettingsResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/me/knowledge/settings",
            method="PATCH",
            json={
                "memories_enabled": memories_enabled,
                "auto_extract_enabled": auto_extract_enabled,
                "personal_knowledge_enabled": personal_knowledge_enabled,
                "config": config,
                "revision": revision,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PersonalKnowledgeSettingsResponse,
                    parse_obj_as(
                        type_=PersonalKnowledgeSettingsResponse,  # 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(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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 AsyncRawPersonalKnowledgeClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def list_personal_stores(
        self,
        *,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[PersonalStoreListResponse]:
        """
        Retrieve all personal vector stores for the authenticated user. Returns stores ordered by creation date, with the default store included.

        Parameters
        ----------
        limit : typing.Optional[int]
            Number of stores to return

        offset : typing.Optional[int]
            Number of stores to skip

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

        Returns
        -------
        AsyncHttpResponse[PersonalStoreListResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/me/knowledge/stores",
            method="GET",
            params={
                "limit": limit,
                "offset": offset,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PersonalStoreListResponse,
                    parse_obj_as(
                        type_=PersonalStoreListResponse,  # 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(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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 create_personal_store(
        self,
        *,
        name: str,
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[PersonalStoreResponse]:
        """
        Create an additional personal vector store. Each user can have multiple stores to organize different topics.

        Parameters
        ----------
        name : str
            Store name

        description : typing.Optional[str]
            Optional description

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

        Returns
        -------
        AsyncHttpResponse[PersonalStoreResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/me/knowledge/stores",
            method="POST",
            json={
                "name": name,
                "description": description,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PersonalStoreResponse,
                    parse_obj_as(
                        type_=PersonalStoreResponse,  # 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(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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 get_personal_store(
        self, store_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[PersonalStoreResponse]:
        """
        Retrieve details of a specific personal vector store. Only accessible by the store owner.

        Parameters
        ----------
        store_id : str

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

        Returns
        -------
        AsyncHttpResponse[PersonalStoreResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/me/knowledge/stores/{jsonable_encoder(store_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PersonalStoreResponse,
                    parse_obj_as(
                        type_=PersonalStoreResponse,  # 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(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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 delete_personal_store(
        self, store_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[None]:
        """
        Delete a personal vector store. The default store cannot be deleted (returns 409).

        Parameters
        ----------
        store_id : str

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

        Returns
        -------
        AsyncHttpResponse[None]
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/me/knowledge/stores/{jsonable_encoder(store_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return AsyncHttpResponse(response=_response, data=None)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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 update_personal_store(
        self,
        store_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[PersonalStoreResponse]:
        """
        Update the name or description of a personal vector store.

        Parameters
        ----------
        store_id : str

        name : typing.Optional[str]

        description : typing.Optional[str]

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

        Returns
        -------
        AsyncHttpResponse[PersonalStoreResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/me/knowledge/stores/{jsonable_encoder(store_id)}",
            method="PATCH",
            json={
                "name": name,
                "description": description,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PersonalStoreResponse,
                    parse_obj_as(
                        type_=PersonalStoreResponse,  # 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(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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 list_store_files(
        self,
        store_id: str,
        *,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[PersonalStoreFileListResponse]:
        """
        Retrieve all files associated with a personal vector store. Returns files ordered by when they were added.

        Parameters
        ----------
        store_id : str

        limit : typing.Optional[int]
            Number of files to return

        offset : typing.Optional[int]
            Number of files to skip

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

        Returns
        -------
        AsyncHttpResponse[PersonalStoreFileListResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/me/knowledge/stores/{jsonable_encoder(store_id)}/files",
            method="GET",
            params={
                "limit": limit,
                "offset": offset,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PersonalStoreFileListResponse,
                    parse_obj_as(
                        type_=PersonalStoreFileListResponse,  # 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(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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 add_file_to_store(
        self, store_id: str, *, file_id: str, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[PersonalStoreFileResponse]:
        """
        Associate an existing file with a personal vector store. The file must already be uploaded via the POST /v1/files endpoint.

        Parameters
        ----------
        store_id : str

        file_id : str
            ID of a previously uploaded file

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

        Returns
        -------
        AsyncHttpResponse[PersonalStoreFileResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/me/knowledge/stores/{jsonable_encoder(store_id)}/files",
            method="POST",
            json={
                "file_id": file_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PersonalStoreFileResponse,
                    parse_obj_as(
                        type_=PersonalStoreFileResponse,  # 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(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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 remove_file_from_store(
        self, store_id: str, file_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[None]:
        """
        Remove a file association from a personal vector store. This does not delete the underlying file.

        Parameters
        ----------
        store_id : str

        file_id : str

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

        Returns
        -------
        AsyncHttpResponse[None]
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/me/knowledge/stores/{jsonable_encoder(store_id)}/files/{jsonable_encoder(file_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return AsyncHttpResponse(response=_response, data=None)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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 teach(
        self,
        *,
        content: str,
        store_id: typing.Optional[str] = OMIT,
        category: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[TeachResponse]:
        """
        Submit free-text content to be chunked, embedded, and stored in the user's personal vector store. If no store_id is specified, uses the default personal store. Content is limited to 10,000 characters.

        Parameters
        ----------
        content : str
            Text content to add as personal knowledge

        store_id : typing.Optional[str]
            Target store ID. Uses default if not specified.

        category : typing.Optional[str]
            Optional category tag for the content

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

        Returns
        -------
        AsyncHttpResponse[TeachResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/me/knowledge/teach",
            method="POST",
            json={
                "content": content,
                "store_id": store_id,
                "category": category,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    TeachResponse,
                    parse_obj_as(
                        type_=TeachResponse,  # 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(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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 get_settings(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[PersonalKnowledgeSettingsResponse]:
        """
        Retrieve the authenticated user's personal knowledge settings. Auto-provisions defaults on first access — always returns 200, never 404.

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

        Returns
        -------
        AsyncHttpResponse[PersonalKnowledgeSettingsResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/me/knowledge/settings",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PersonalKnowledgeSettingsResponse,
                    parse_obj_as(
                        type_=PersonalKnowledgeSettingsResponse,  # 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 update_settings(
        self,
        *,
        revision: int,
        memories_enabled: typing.Optional[bool] = OMIT,
        auto_extract_enabled: typing.Optional[bool] = OMIT,
        personal_knowledge_enabled: typing.Optional[bool] = OMIT,
        config: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[PersonalKnowledgeSettingsResponse]:
        """
        Update the authenticated user's personal knowledge settings with optimistic concurrency. The revision field must match the current server revision or a 409 Conflict will be returned.

        Parameters
        ----------
        revision : int
            Required for optimistic concurrency — must match current server revision

        memories_enabled : typing.Optional[bool]
            Enable/disable memories feature

        auto_extract_enabled : typing.Optional[bool]
            Enable/disable automatic memory extraction from conversations

        personal_knowledge_enabled : typing.Optional[bool]
            Enable/disable personal knowledge stores

        config : typing.Optional[typing.Dict[str, typing.Any]]
            Additional configuration overrides

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

        Returns
        -------
        AsyncHttpResponse[PersonalKnowledgeSettingsResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/me/knowledge/settings",
            method="PATCH",
            json={
                "memories_enabled": memories_enabled,
                "auto_extract_enabled": auto_extract_enabled,
                "personal_knowledge_enabled": personal_knowledge_enabled,
                "config": config,
                "revision": revision,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    PersonalKnowledgeSettingsResponse,
                    parse_obj_as(
                        type_=PersonalKnowledgeSettingsResponse,  # 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(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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)
