|
1 | 1 | import os
|
2 |
| -from typing import Any, Callable, Optional |
3 |
| -from urllib.parse import urlparse |
| 2 | +from typing import Any, Callable, Literal, Optional, Union |
4 | 3 |
|
| 4 | +from browserbase.types import SessionCreateParams as BrowserbaseSessionCreateParams |
5 | 5 | from pydantic import BaseModel, ConfigDict, Field, field_validator, ValidationError
|
6 | 6 |
|
7 | 7 | from stagehand.schemas import AvailableModel
|
@@ -78,7 +78,14 @@ class StagehandConfig(BaseModel):
|
78 | 78 | dom_settle_timeout_ms: Optional[int] = Field(
|
79 | 79 | 3000,
|
80 | 80 | alias="domSettleTimeoutMs",
|
81 |
| - description="Timeout in milliseconds to wait for DOM to settle after actions", |
| 81 | + description="Timeout for DOM to settle (in ms)", |
| 82 | + ) |
| 83 | + browserbase_session_create_params: Optional[ |
| 84 | + Union[BrowserbaseSessionCreateParams, dict[str, Any]] |
| 85 | + ] = Field( |
| 86 | + None, |
| 87 | + alias="browserbaseSessionCreateParams", |
| 88 | + description="Browserbase session create params", |
82 | 89 | )
|
83 | 90 | enable_caching: Optional[bool] = Field(
|
84 | 91 | False,
|
@@ -171,6 +178,16 @@ def validate_dom_settle_timeout(cls, v):
|
171 | 178 | """Validate DOM settle timeout is positive."""
|
172 | 179 | if v is not None and v < 0:
|
173 | 180 | raise ValueError("dom_settle_timeout_ms must be non-negative")
|
| 181 | + |
| 182 | + @field_validator("browserbase_session_create_params", mode="before") |
| 183 | + @classmethod |
| 184 | + def validate_browserbase_params(cls, v, info): |
| 185 | + """Validate and convert browserbase session create params.""" |
| 186 | + if isinstance(v, dict) and "project_id" not in v: |
| 187 | + values = info.data |
| 188 | + project_id = values.get("project_id") or values.get("projectId") |
| 189 | + if project_id: |
| 190 | + v = {**v, "project_id": project_id} |
174 | 191 | return v
|
175 | 192 |
|
176 | 193 | def with_overrides(self, **overrides) -> "StagehandConfig":
|
|
0 commit comments