Skip to content

Commit 93f5c97

Browse files
chrisreadsfDerek Meeganmiguelg719
authored
remove need for project id in Browserbase params if already passed to stagehand (#196)
* relax browserbase params and add pre hook to validator to add project id to browserbase params before field validation * fix 1) formatting 2) test for api key * add changeset * Update tests/integration/local/test_core_local.py --------- Co-authored-by: Derek Meegan <[email protected]> Co-authored-by: Miguel <[email protected]>
1 parent ab31b6e commit 93f5c97

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"stagehand": patch
3+
---
4+
5+
remove duplicate project id if already passed to Stagehand

stagehand/config.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import os
2-
from typing import Any, Callable, Literal, Optional
2+
from typing import Any, Callable, Literal, Optional, Union
33

44
from browserbase.types import SessionCreateParams as BrowserbaseSessionCreateParams
5-
from pydantic import BaseModel, ConfigDict, Field
5+
from pydantic import BaseModel, ConfigDict, Field, field_validator
66

77
from stagehand.schemas import AvailableModel
88

@@ -71,7 +71,9 @@ class StagehandConfig(BaseModel):
7171
alias="domSettleTimeoutMs",
7272
description="Timeout for DOM to settle (in ms)",
7373
)
74-
browserbase_session_create_params: Optional[BrowserbaseSessionCreateParams] = Field(
74+
browserbase_session_create_params: Optional[
75+
Union[BrowserbaseSessionCreateParams, dict[str, Any]]
76+
] = Field(
7577
None,
7678
alias="browserbaseSessionCreateParams",
7779
description="Browserbase session create params",
@@ -118,6 +120,17 @@ class StagehandConfig(BaseModel):
118120

119121
model_config = ConfigDict(populate_by_name=True)
120122

123+
@field_validator("browserbase_session_create_params", mode="before")
124+
@classmethod
125+
def validate_browserbase_params(cls, v, info):
126+
"""Validate and convert browserbase session create params."""
127+
if isinstance(v, dict) and "project_id" not in v:
128+
values = info.data
129+
project_id = values.get("project_id") or values.get("projectId")
130+
if project_id:
131+
v = {**v, "project_id": project_id}
132+
return v
133+
121134
def with_overrides(self, **overrides) -> "StagehandConfig":
122135
"""
123136
Create a new config instance with the specified overrides.

0 commit comments

Comments
 (0)