From 1c772e22e5bd5673c14e1233827ff9dc24ec46d3 Mon Sep 17 00:00:00 2001 From: miguel Date: Mon, 14 Jul 2025 15:15:12 -0700 Subject: [PATCH 1/5] pass sdk version number to api for debug --- .changeset/belligerent-gharial-of-attack.md | 5 +++++ stagehand/api.py | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 .changeset/belligerent-gharial-of-attack.md diff --git a/.changeset/belligerent-gharial-of-attack.md b/.changeset/belligerent-gharial-of-attack.md new file mode 100644 index 00000000..f7393d44 --- /dev/null +++ b/.changeset/belligerent-gharial-of-attack.md @@ -0,0 +1,5 @@ +--- +"stagehand": patch +--- + +Pass sdk version number to API for debugging diff --git a/stagehand/api.py b/stagehand/api.py index 28eb2161..1f973745 100644 --- a/stagehand/api.py +++ b/stagehand/api.py @@ -1,5 +1,6 @@ import json from datetime import datetime +from importlib.metadata import version as get_version from typing import Any from .utils import convert_dict_keys_to_camel_case @@ -70,6 +71,7 @@ async def _create_session(self): "Content-Type": "application/json", "x-sent-at": datetime.now().isoformat(), "x-language": "python", + "x-sdk-version": get_version("stagehand"), } # async with self._client: From db97a0760132dedb122c9f79bdf42b55eb06f599 Mon Sep 17 00:00:00 2001 From: Roaring <216452114+the-roaring@users.noreply.github.com> Date: Tue, 15 Jul 2025 09:59:29 -0700 Subject: [PATCH 2/5] add exception catch --- stagehand/api.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/stagehand/api.py b/stagehand/api.py index 1f973745..4820248c 100644 --- a/stagehand/api.py +++ b/stagehand/api.py @@ -1,6 +1,6 @@ import json from datetime import datetime -from importlib.metadata import version as get_version +from importlib.metadata import version from typing import Any from .utils import convert_dict_keys_to_camel_case @@ -64,6 +64,13 @@ async def _create_session(self): if hasattr(self, "model_client_options") and self.model_client_options: payload["modelClientOptions"] = self.model_client_options + def get_version(package_str): + try: + result = version(package_str) + except PackageNotFoundError: + result = package_str + " not installed" + return result + headers = { "x-bb-api-key": self.browserbase_api_key, "x-bb-project-id": self.browserbase_project_id, From 5b8b672ba46b34da05c6c03d484b0520e322a239 Mon Sep 17 00:00:00 2001 From: Roaring <216452114+the-roaring@users.noreply.github.com> Date: Tue, 15 Jul 2025 10:50:07 -0700 Subject: [PATCH 3/5] add missing import --- stagehand/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stagehand/api.py b/stagehand/api.py index 4820248c..d9bfae1e 100644 --- a/stagehand/api.py +++ b/stagehand/api.py @@ -1,6 +1,6 @@ import json from datetime import datetime -from importlib.metadata import version +from importlib.metadata import version, PackageNotFoundError from typing import Any from .utils import convert_dict_keys_to_camel_case From f48228da84c40a9dde4b31051962795f19901ab8 Mon Sep 17 00:00:00 2001 From: Roaring <216452114+the-roaring@users.noreply.github.com> Date: Tue, 15 Jul 2025 10:51:02 -0700 Subject: [PATCH 4/5] fix lint --- stagehand/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stagehand/api.py b/stagehand/api.py index d9bfae1e..5f39c670 100644 --- a/stagehand/api.py +++ b/stagehand/api.py @@ -1,6 +1,6 @@ import json from datetime import datetime -from importlib.metadata import version, PackageNotFoundError +from importlib.metadata import PackageNotFoundError, version from typing import Any from .utils import convert_dict_keys_to_camel_case From 213f2f6a7f3ef68de01dafee864372f3cc6bd1f8 Mon Sep 17 00:00:00 2001 From: the-roaring <216452114+the-roaring@users.noreply.github.com> Date: Tue, 15 Jul 2025 10:54:42 -0700 Subject: [PATCH 5/5] just make it null Co-authored-by: Miguel <36487034+miguelg719@users.noreply.github.com> --- stagehand/api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stagehand/api.py b/stagehand/api.py index 5f39c670..6639df29 100644 --- a/stagehand/api.py +++ b/stagehand/api.py @@ -68,7 +68,8 @@ def get_version(package_str): try: result = version(package_str) except PackageNotFoundError: - result = package_str + " not installed" + self.logger.error(package_str + " not installed") + result = None return result headers = {