Skip to content

Commit 585015c

Browse files
feat(api): manual updates
1 parent 1a8ec04 commit 585015c

File tree

6 files changed

+99
-94
lines changed

6 files changed

+99
-94
lines changed

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 7
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fstagehand-09064f4021f94fb1b1bd86ce496d998318276b61bbc24de4728ecdb5763847ef.yml
3-
openapi_spec_hash: 911d0631010b372890f98545a038cfb5
4-
config_hash: bb7561632c1f66c2b9efca06f438f904
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fstagehand-6a22863a7da4fa45f904657a4cb8fc1a28e236925f03dc94fca25fd8271ca6db.yml
3+
openapi_spec_hash: d5c6108942ad79f39ea4ff1bee9b7996
4+
config_hash: 2f1ec44e7e07906e07bdc6e075763da9

README.md

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ client = Stagehand(
3737
environment="dev",
3838
)
3939

40-
response = client.sessions.start(
41-
env="LOCAL",
40+
response = client.sessions.act(
41+
session_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
42+
input="click the first link on the page",
4243
)
43-
print(response.available)
44+
print(response.actions)
4445
```
4546

4647
While you can provide an `api_key` keyword argument,
@@ -65,10 +66,11 @@ client = AsyncStagehand(
6566

6667

6768
async def main() -> None:
68-
response = await client.sessions.start(
69-
env="LOCAL",
69+
response = await client.sessions.act(
70+
session_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
71+
input="click the first link on the page",
7072
)
71-
print(response.available)
73+
print(response.actions)
7274

7375

7476
asyncio.run(main())
@@ -101,10 +103,11 @@ async def main() -> None:
101103
api_key=os.environ.get("STAGEHAND_API_KEY"), # This is the default and can be omitted
102104
http_client=DefaultAioHttpClient(),
103105
) as client:
104-
response = await client.sessions.start(
105-
env="LOCAL",
106+
response = await client.sessions.act(
107+
session_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
108+
input="click the first link on the page",
106109
)
107-
print(response.available)
110+
print(response.actions)
108111

109112

110113
asyncio.run(main())
@@ -128,11 +131,12 @@ from stagehand import Stagehand
128131

129132
client = Stagehand()
130133

131-
response = client.sessions.start(
132-
env="LOCAL",
133-
local_browser_launch_options={},
134+
response = client.sessions.act(
135+
session_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
136+
input="click the sign in button",
137+
options={},
134138
)
135-
print(response.local_browser_launch_options)
139+
print(response.options)
136140
```
137141

138142
## Handling errors
@@ -152,7 +156,8 @@ client = Stagehand()
152156

153157
try:
154158
client.sessions.start(
155-
env="LOCAL",
159+
browserbase_api_key="BROWSERBASE_API_KEY",
160+
browserbase_project_id="BROWSERBASE_PROJECT_ID",
156161
)
157162
except stagehand.APIConnectionError as e:
158163
print("The server could not be reached")
@@ -197,7 +202,8 @@ client = Stagehand(
197202

198203
# Or, configure per-request:
199204
client.with_options(max_retries=5).sessions.start(
200-
env="LOCAL",
205+
browserbase_api_key="BROWSERBASE_API_KEY",
206+
browserbase_project_id="BROWSERBASE_PROJECT_ID",
201207
)
202208
```
203209

@@ -222,7 +228,8 @@ client = Stagehand(
222228

223229
# Override per-request:
224230
client.with_options(timeout=5.0).sessions.start(
225-
env="LOCAL",
231+
browserbase_api_key="BROWSERBASE_API_KEY",
232+
browserbase_project_id="BROWSERBASE_PROJECT_ID",
226233
)
227234
```
228235

@@ -265,7 +272,8 @@ from stagehand import Stagehand
265272

266273
client = Stagehand()
267274
response = client.sessions.with_raw_response.start(
268-
env="LOCAL",
275+
browserbase_api_key="BROWSERBASE_API_KEY",
276+
browserbase_project_id="BROWSERBASE_PROJECT_ID",
269277
)
270278
print(response.headers.get('X-My-Header'))
271279

@@ -285,7 +293,8 @@ To stream the response body, use `.with_streaming_response` instead, which requi
285293

286294
```python
287295
with client.sessions.with_streaming_response.start(
288-
env="LOCAL",
296+
browserbase_api_key="BROWSERBASE_API_KEY",
297+
browserbase_project_id="BROWSERBASE_PROJECT_ID",
289298
) as response:
290299
print(response.headers.get("X-My-Header"))
291300

src/stagehand/resources/sessions.py

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,10 @@ def observe(
375375
def start(
376376
self,
377377
*,
378-
env: Literal["LOCAL", "BROWSERBASE"],
379-
api_key: str | Omit = omit,
378+
browserbase_api_key: str,
379+
browserbase_project_id: str,
380380
dom_settle_timeout: int | Omit = omit,
381-
local_browser_launch_options: session_start_params.LocalBrowserLaunchOptions | Omit = omit,
382381
model: str | Omit = omit,
383-
project_id: str | Omit = omit,
384382
self_heal: bool | Omit = omit,
385383
system_prompt: str | Omit = omit,
386384
verbose: int | Omit = omit,
@@ -397,17 +395,13 @@ def start(
397395
ID that must be used for all subsequent requests.
398396
399397
Args:
400-
env: Environment to run the browser in
398+
browserbase_api_key: API key for Browserbase Cloud
401399
402-
api_key: API key for Browserbase (required when env=BROWSERBASE)
400+
browserbase_project_id: Project ID for Browserbase
403401
404402
dom_settle_timeout: Timeout in ms to wait for DOM to settle
405403
406-
local_browser_launch_options: Options for local browser launch
407-
408-
model: AI model to use for actions
409-
410-
project_id: Project ID for Browserbase (required when env=BROWSERBASE)
404+
model: AI model to use for actions (must be prefixed with provider/)
411405
412406
self_heal: Enable self-healing for failed actions
413407
@@ -427,12 +421,10 @@ def start(
427421
"/sessions/start",
428422
body=maybe_transform(
429423
{
430-
"env": env,
431-
"api_key": api_key,
424+
"browserbase_api_key": browserbase_api_key,
425+
"browserbase_project_id": browserbase_project_id,
432426
"dom_settle_timeout": dom_settle_timeout,
433-
"local_browser_launch_options": local_browser_launch_options,
434427
"model": model,
435-
"project_id": project_id,
436428
"self_heal": self_heal,
437429
"system_prompt": system_prompt,
438430
"verbose": verbose,
@@ -784,12 +776,10 @@ async def observe(
784776
async def start(
785777
self,
786778
*,
787-
env: Literal["LOCAL", "BROWSERBASE"],
788-
api_key: str | Omit = omit,
779+
browserbase_api_key: str,
780+
browserbase_project_id: str,
789781
dom_settle_timeout: int | Omit = omit,
790-
local_browser_launch_options: session_start_params.LocalBrowserLaunchOptions | Omit = omit,
791782
model: str | Omit = omit,
792-
project_id: str | Omit = omit,
793783
self_heal: bool | Omit = omit,
794784
system_prompt: str | Omit = omit,
795785
verbose: int | Omit = omit,
@@ -806,17 +796,13 @@ async def start(
806796
ID that must be used for all subsequent requests.
807797
808798
Args:
809-
env: Environment to run the browser in
799+
browserbase_api_key: API key for Browserbase Cloud
810800
811-
api_key: API key for Browserbase (required when env=BROWSERBASE)
801+
browserbase_project_id: Project ID for Browserbase
812802
813803
dom_settle_timeout: Timeout in ms to wait for DOM to settle
814804
815-
local_browser_launch_options: Options for local browser launch
816-
817-
model: AI model to use for actions
818-
819-
project_id: Project ID for Browserbase (required when env=BROWSERBASE)
805+
model: AI model to use for actions (must be prefixed with provider/)
820806
821807
self_heal: Enable self-healing for failed actions
822808
@@ -836,12 +822,10 @@ async def start(
836822
"/sessions/start",
837823
body=await async_maybe_transform(
838824
{
839-
"env": env,
840-
"api_key": api_key,
825+
"browserbase_api_key": browserbase_api_key,
826+
"browserbase_project_id": browserbase_project_id,
841827
"dom_settle_timeout": dom_settle_timeout,
842-
"local_browser_launch_options": local_browser_launch_options,
843828
"model": model,
844-
"project_id": project_id,
845829
"self_heal": self_heal,
846830
"system_prompt": system_prompt,
847831
"verbose": verbose,

src/stagehand/types/session_start_params.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,25 @@
22

33
from __future__ import annotations
44

5-
from typing_extensions import Literal, Required, Annotated, TypedDict
5+
from typing_extensions import Required, Annotated, TypedDict
66

77
from .._utils import PropertyInfo
88

9-
__all__ = ["SessionStartParams", "LocalBrowserLaunchOptions"]
9+
__all__ = ["SessionStartParams"]
1010

1111

1212
class SessionStartParams(TypedDict, total=False):
13-
env: Required[Literal["LOCAL", "BROWSERBASE"]]
14-
"""Environment to run the browser in"""
13+
browserbase_api_key: Required[Annotated[str, PropertyInfo(alias="BROWSERBASE_API_KEY")]]
14+
"""API key for Browserbase Cloud"""
1515

16-
api_key: Annotated[str, PropertyInfo(alias="apiKey")]
17-
"""API key for Browserbase (required when env=BROWSERBASE)"""
16+
browserbase_project_id: Required[Annotated[str, PropertyInfo(alias="BROWSERBASE_PROJECT_ID")]]
17+
"""Project ID for Browserbase"""
1818

1919
dom_settle_timeout: Annotated[int, PropertyInfo(alias="domSettleTimeout")]
2020
"""Timeout in ms to wait for DOM to settle"""
2121

22-
local_browser_launch_options: Annotated[LocalBrowserLaunchOptions, PropertyInfo(alias="localBrowserLaunchOptions")]
23-
"""Options for local browser launch"""
24-
2522
model: str
26-
"""AI model to use for actions"""
27-
28-
project_id: Annotated[str, PropertyInfo(alias="projectId")]
29-
"""Project ID for Browserbase (required when env=BROWSERBASE)"""
23+
"""AI model to use for actions (must be prefixed with provider/)"""
3024

3125
self_heal: Annotated[bool, PropertyInfo(alias="selfHeal")]
3226
"""Enable self-healing for failed actions"""
@@ -36,9 +30,3 @@ class SessionStartParams(TypedDict, total=False):
3630

3731
verbose: int
3832
"""Logging verbosity level"""
39-
40-
41-
class LocalBrowserLaunchOptions(TypedDict, total=False):
42-
"""Options for local browser launch"""
43-
44-
headless: bool

tests/api_resources/test_sessions.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -394,20 +394,19 @@ def test_path_params_observe(self, client: Stagehand) -> None:
394394
@parametrize
395395
def test_method_start(self, client: Stagehand) -> None:
396396
session = client.sessions.start(
397-
env="LOCAL",
397+
browserbase_api_key="BROWSERBASE_API_KEY",
398+
browserbase_project_id="BROWSERBASE_PROJECT_ID",
398399
)
399400
assert_matches_type(SessionStartResponse, session, path=["response"])
400401

401402
@pytest.mark.skip(reason="Prism tests are disabled")
402403
@parametrize
403404
def test_method_start_with_all_params(self, client: Stagehand) -> None:
404405
session = client.sessions.start(
405-
env="LOCAL",
406-
api_key="apiKey",
406+
browserbase_api_key="BROWSERBASE_API_KEY",
407+
browserbase_project_id="BROWSERBASE_PROJECT_ID",
407408
dom_settle_timeout=0,
408-
local_browser_launch_options={"headless": True},
409409
model="openai/gpt-4o",
410-
project_id="projectId",
411410
self_heal=True,
412411
system_prompt="systemPrompt",
413412
verbose=1,
@@ -418,7 +417,8 @@ def test_method_start_with_all_params(self, client: Stagehand) -> None:
418417
@parametrize
419418
def test_raw_response_start(self, client: Stagehand) -> None:
420419
response = client.sessions.with_raw_response.start(
421-
env="LOCAL",
420+
browserbase_api_key="BROWSERBASE_API_KEY",
421+
browserbase_project_id="BROWSERBASE_PROJECT_ID",
422422
)
423423

424424
assert response.is_closed is True
@@ -430,7 +430,8 @@ def test_raw_response_start(self, client: Stagehand) -> None:
430430
@parametrize
431431
def test_streaming_response_start(self, client: Stagehand) -> None:
432432
with client.sessions.with_streaming_response.start(
433-
env="LOCAL",
433+
browserbase_api_key="BROWSERBASE_API_KEY",
434+
browserbase_project_id="BROWSERBASE_PROJECT_ID",
434435
) as response:
435436
assert not response.is_closed
436437
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
@@ -815,20 +816,19 @@ async def test_path_params_observe(self, async_client: AsyncStagehand) -> None:
815816
@parametrize
816817
async def test_method_start(self, async_client: AsyncStagehand) -> None:
817818
session = await async_client.sessions.start(
818-
env="LOCAL",
819+
browserbase_api_key="BROWSERBASE_API_KEY",
820+
browserbase_project_id="BROWSERBASE_PROJECT_ID",
819821
)
820822
assert_matches_type(SessionStartResponse, session, path=["response"])
821823

822824
@pytest.mark.skip(reason="Prism tests are disabled")
823825
@parametrize
824826
async def test_method_start_with_all_params(self, async_client: AsyncStagehand) -> None:
825827
session = await async_client.sessions.start(
826-
env="LOCAL",
827-
api_key="apiKey",
828+
browserbase_api_key="BROWSERBASE_API_KEY",
829+
browserbase_project_id="BROWSERBASE_PROJECT_ID",
828830
dom_settle_timeout=0,
829-
local_browser_launch_options={"headless": True},
830831
model="openai/gpt-4o",
831-
project_id="projectId",
832832
self_heal=True,
833833
system_prompt="systemPrompt",
834834
verbose=1,
@@ -839,7 +839,8 @@ async def test_method_start_with_all_params(self, async_client: AsyncStagehand)
839839
@parametrize
840840
async def test_raw_response_start(self, async_client: AsyncStagehand) -> None:
841841
response = await async_client.sessions.with_raw_response.start(
842-
env="LOCAL",
842+
browserbase_api_key="BROWSERBASE_API_KEY",
843+
browserbase_project_id="BROWSERBASE_PROJECT_ID",
843844
)
844845

845846
assert response.is_closed is True
@@ -851,7 +852,8 @@ async def test_raw_response_start(self, async_client: AsyncStagehand) -> None:
851852
@parametrize
852853
async def test_streaming_response_start(self, async_client: AsyncStagehand) -> None:
853854
async with async_client.sessions.with_streaming_response.start(
854-
env="LOCAL",
855+
browserbase_api_key="BROWSERBASE_API_KEY",
856+
browserbase_project_id="BROWSERBASE_PROJECT_ID",
855857
) as response:
856858
assert not response.is_closed
857859
assert response.http_request.headers.get("X-Stainless-Lang") == "python"

0 commit comments

Comments
 (0)