diff --git a/pyproject.toml b/pyproject.toml index 1355cde..d10038c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "cradl" -version = "0.4.2" +version = "0.4.3" description = "Python SDK for Cradl" authors = [{ name = "Cradl", email = "hello@cradl.ai" }] readme = "README.md" diff --git a/src/cradl/client.py b/src/cradl/client.py index 26e8029..0860a16 100644 --- a/src/cradl/client.py +++ b/src/cradl/client.py @@ -86,7 +86,7 @@ def _make_fileserver_request( file_url: str, content: Optional[bytes] = None, query_params: Optional[dict] = None, - ) -> Dict: + ) -> bytes: if not content and requests_fn == requests.put: raise EmptyRequestError @@ -2833,7 +2833,7 @@ def list_agent_runs( }) return self._make_request(requests.get, f'/agents/{agent_id}/runs', params=params) - def get_agent_run(self, agent_id: str, run_id: str) -> Dict: + def get_agent_run(self, agent_id: str, run_id: str, *, get_variables: bool = False) -> Dict: """Get agent, calls the GET /agents/{agentId}/runs/{runId} endpoint. :param agent_id: Id of the agent @@ -2846,7 +2846,14 @@ def get_agent_run(self, agent_id: str, run_id: str) -> Dict: :raises: :py:class:`~cradl.InvalidCredentialsException`, :py:class:`~cradl.TooManyRequestsException`,\ :py:class:`~cradl.LimitExceededException`, :py:class:`requests.exception.RequestException` """ - return self._make_request(requests.get, f'/agents/{agent_id}/runs/{run_id}') + agent_run = self._make_request(requests.get, f'/agents/{agent_id}/runs/{run_id}') + if get_variables and agent_run.get('variablesFileUrl'): + agent_run['variables'] = json.loads(self._make_fileserver_request( + requests_fn=requests.get, + file_url=agent_run['variablesFileUrl'], + query_params={}, + ).decode()) + return agent_run def list_hooks(self, *, max_results: Optional[int] = None, next_token: Optional[str] = None) -> Dict: """List hooks available, calls the GET /hooks endpoint.