def receive(
        self,
        id: str,
    ) -> _Optional[_JSONRPCResponse]:
        """
        Receive a JSON-RPC response from the device application.

        This method retrieves and parses a JSON-RPC response, including any associated resource files.

        Parameters
        ----------
        id : str
            The ID of the request for which to receive the response.

        Returns
        -------
        Optional[JSONRPCResponse]
            The received response, or None if no response is available.
        """
        responses_directory = self.responses_directory / id
        if responses_directory.is_dir():
            _shutil.rmtree(responses_directory.resolve())

        responses_directory.mkdir(parents=True, exist_ok=False)
        payload = self.device.session.receive_file_from_app(
            destination_path=responses_directory / "message.json",
            source=f"{self.source}/responses/{id}/message.json",
        )

        if payload is None:
            return None

        message_json_file = responses_directory / "message.json"
        if not message_json_file.is_file():
            raise ValueError(f"Response for request-id{id} is missing message.json file.")

        result = None
        error = None
        resource = None
        resource_name = None
        with open(message_json_file, "r") as file:
            message = _json.load(file)
            if not isinstance(message, _Mapping):
                raise ValueError(f"Response for request-id{id} is malformed {message}.")

            response_id = message.get("id", "")
            if response_id != id:
                raise ValueError(f"Response for request-id{id} is malformed {message}.")

            result = message.get("result", None)
            error = _DeviceCtlSocket._parse_error(message.get("error", None))
            resource_name = message.get("resource", None)

        if result is None and error is None:
            raise ValueError(
                f"Response for request-id{id} is malformed {message}, missing result={result} or error={error}."
            )

        resource = None
        if resource_name is not None:
            resource_payload = self.device.session.receive_file_from_app(
                destination_path=responses_directory / resource_name,
                source=f"{self.source}/responses/{id}/{resource_name}",
            )

            if resource_payload is None:
                raise ValueError(
                    f"Response for request-id={id} is missing resource file={resource_name}."
                )

            resource = responses_directory / resource_name

        return _JSONRPCResponse(
            id=id,
            result=result,
            error=error,
            resource=resource,
        )

        Receive a JSON-RPC response from the device application.

        This method retrieves and parses a JSON-RPC response, including any associated resource files.

        Parameters
        ----------
        id : str
            The ID of the request for which to receive the response.

        Returns
        -------
        Optional[JSONRPCResponse]
            The received response, or None if no response is available.
        
coremltools/models/ml_program/experimental/remote_device.py