11import os
2- from typing import Any , Callable , Literal , Optional , Union
2+ from typing import Any , Callable , Literal , Optional
33
4- from browserbase .types import SessionCreateParams as BrowserbaseSessionCreateParams
54from pydantic import BaseModel , ConfigDict , Field , field_validator
65
76from stagehand .schemas import AvailableModel
@@ -71,9 +70,7 @@ class StagehandConfig(BaseModel):
7170 alias = "domSettleTimeoutMs" ,
7271 description = "Timeout for DOM to settle (in ms)" ,
7372 )
74- browserbase_session_create_params : Optional [
75- Union [BrowserbaseSessionCreateParams , dict [str , Any ]]
76- ] = Field (
73+ browserbase_session_create_params : Optional [dict [str , Any ]] = Field (
7774 None ,
7875 alias = "browserbaseSessionCreateParams" ,
7976 description = "Browserbase session create params" ,
@@ -87,7 +84,9 @@ class StagehandConfig(BaseModel):
8784 description = "Session ID for resuming Browserbase sessions" ,
8885 )
8986 model_name : Optional [str ] = Field (
90- AvailableModel .GPT_4O , alias = "modelName" , description = "Name of the model to use"
87+ AvailableModel .GPT_4_1_MINI ,
88+ alias = "modelName" ,
89+ description = "Name of the model to use" ,
9190 )
9291 self_heal : Optional [bool ] = Field (
9392 True , alias = "selfHeal" , description = "Enable self-healing functionality"
@@ -124,11 +123,25 @@ class StagehandConfig(BaseModel):
124123 @classmethod
125124 def validate_browserbase_params (cls , v , info ):
126125 """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 }
126+ if isinstance (v , dict ):
127+ # Make a copy to avoid mutating the original
128+ v = dict (v )
129+
130+ # Add project_id if not present
131+ if "project_id" not in v :
132+ values = info .data
133+ project_id = values .get ("project_id" ) or values .get ("projectId" )
134+ if project_id :
135+ v ["project_id" ] = project_id
136+
137+ # Handle browser_settings
138+ if "browser_settings" in v :
139+ # Make a copy of browser_settings to avoid mutating
140+ v ["browser_settings" ] = dict (v ["browser_settings" ])
141+
142+ # Normalize 'os' key to lowercase
143+ if "os" in v ["browser_settings" ]:
144+ v ["browser_settings" ]["os" ] = v ["browser_settings" ]["os" ].lower ()
132145 return v
133146
134147 def with_overrides (self , ** overrides ) -> "StagehandConfig" :
0 commit comments