Skip to content

Commit cea5af9

Browse files
authored
Pass os key on browserbase create params (#232)
* Add support for Haiku 4.5 CUA * Properly serialize os on browserbase session create params * Delete .changeset/polite-dogfish-of-purring.md * formatting * update default model
1 parent 1e7086e commit cea5af9

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
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+
Properly serialize os on browserbase session create params

stagehand/config.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 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
54
from pydantic import BaseModel, ConfigDict, Field, field_validator
65

76
from 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":

stagehand/schemas.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
class AvailableModel(str, Enum):
1616
GPT_4O = "gpt-4o"
1717
GPT_4O_MINI = "gpt-4o-mini"
18+
GPT_4_1_MINI = "gpt-4.1-mini"
1819
CLAUDE_3_5_SONNET_LATEST = "claude-3-5-sonnet-latest"
1920
CLAUDE_3_7_SONNET_LATEST = "claude-3-7-sonnet-latest"
2021
COMPUTER_USE_PREVIEW = "computer-use-preview"

0 commit comments

Comments
 (0)