Skip to content

Remove Need to Add Project ID in Browserbase Params if Already Passed to Stagehand #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions stagehand/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
from typing import Any, Callable, Literal, Optional
from typing import Any, Callable, Literal, Optional, Union

from browserbase.types import SessionCreateParams as BrowserbaseSessionCreateParams
from pydantic import BaseModel, ConfigDict, Field
from pydantic import BaseModel, ConfigDict, Field, field_validator

from stagehand.schemas import AvailableModel

Expand Down Expand Up @@ -65,7 +65,7 @@ class StagehandConfig(BaseModel):
alias="domSettleTimeoutMs",
description="Timeout for DOM to settle (in ms)",
)
browserbase_session_create_params: Optional[BrowserbaseSessionCreateParams] = Field(
browserbase_session_create_params: Optional[Union[BrowserbaseSessionCreateParams, dict[str, Any]]] = Field(
None,
alias="browserbaseSessionCreateParams",
description="Browserbase session create params",
Expand Down Expand Up @@ -111,6 +111,17 @@ class StagehandConfig(BaseModel):
)

model_config = ConfigDict(populate_by_name=True)

@field_validator('browserbase_session_create_params', mode='before')
@classmethod
def validate_browserbase_params(cls, v, info):
"""Validate and convert browserbase session create params."""
if isinstance(v, dict) and 'project_id' not in v:
values = info.data
project_id = values.get('project_id') or values.get('projectId')
if project_id:
v = {**v, 'project_id': project_id}
return v

def with_overrides(self, **overrides) -> "StagehandConfig":
"""
Expand Down
Loading