Skip to content

Commit 722abc9

Browse files
feat(api): manual updates
1 parent 0eba9d2 commit 722abc9

23 files changed

+1986
-465
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-c1a6f03afe5d6823c198e5ac476fb688dacc783dae1fefdf6bf142084e298e16.yml
3-
openapi_spec_hash: d20e8f697ce8d5bb80295fc1e8ce02e8
4-
config_hash: e457d704d820df5d25acfd379169f132
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fstagehand-349e1b0f6291eedd731c1660155a50adcb3424fb8cd9e17bbdc0939ff3bbffcd.yml
3+
openapi_spec_hash: 456b593ea71d72bc31a6338a25363e9f
4+
config_hash: 5f6b5ec6e84fb01932ba87c6a9623d9b

README.md

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ client = Stagehand(
4141
model_api_key=os.environ.get("MODEL_API_KEY"), # This is the default and can be omitted
4242
)
4343

44-
response = client.sessions.start()
44+
response = client.sessions.act(
45+
id="c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123",
46+
input="Click the login button",
47+
)
48+
print(response.data)
4549
```
4650

4751
While you can provide a `browserbase_api_key` keyword argument,
@@ -70,7 +74,11 @@ client = AsyncStagehand(
7074

7175

7276
async def main() -> None:
73-
response = await client.sessions.start()
77+
response = await client.sessions.act(
78+
id="c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123",
79+
input="Click the login button",
80+
)
81+
print(response.data)
7482

7583

7684
asyncio.run(main())
@@ -109,7 +117,11 @@ async def main() -> None:
109117
model_api_key=os.environ.get("MODEL_API_KEY"), # This is the default and can be omitted
110118
http_client=DefaultAioHttpClient(),
111119
) as client:
112-
response = await client.sessions.start()
120+
response = await client.sessions.act(
121+
id="c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123",
122+
input="Click the login button",
123+
)
124+
print(response.data)
113125

114126

115127
asyncio.run(main())
@@ -124,6 +136,23 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
124136

125137
Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.
126138

139+
## Nested params
140+
141+
Nested parameters are dictionaries, typed using `TypedDict`, for example:
142+
143+
```python
144+
from stagehand import Stagehand
145+
146+
client = Stagehand()
147+
148+
response = client.sessions.act(
149+
id="c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123",
150+
input="Click the login button",
151+
options={},
152+
)
153+
print(response.options)
154+
```
155+
127156
## Handling errors
128157

129158
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `stagehand.APIConnectionError` is raised.
@@ -140,7 +169,10 @@ from stagehand import Stagehand
140169
client = Stagehand()
141170

142171
try:
143-
client.sessions.start()
172+
client.sessions.act(
173+
id="c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123",
174+
input="Click the login button",
175+
)
144176
except stagehand.APIConnectionError as e:
145177
print("The server could not be reached")
146178
print(e.__cause__) # an underlying Exception, likely raised within httpx.
@@ -183,7 +215,10 @@ client = Stagehand(
183215
)
184216

185217
# Or, configure per-request:
186-
client.with_options(max_retries=5).sessions.start()
218+
client.with_options(max_retries=5).sessions.act(
219+
id="c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123",
220+
input="Click the login button",
221+
)
187222
```
188223

189224
### Timeouts
@@ -206,7 +241,10 @@ client = Stagehand(
206241
)
207242

208243
# Override per-request:
209-
client.with_options(timeout=5.0).sessions.start()
244+
client.with_options(timeout=5.0).sessions.act(
245+
id="c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123",
246+
input="Click the login button",
247+
)
210248
```
211249

212250
On timeout, an `APITimeoutError` is thrown.
@@ -247,11 +285,14 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
247285
from stagehand import Stagehand
248286

249287
client = Stagehand()
250-
response = client.sessions.with_raw_response.start()
288+
response = client.sessions.with_raw_response.act(
289+
id="c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123",
290+
input="Click the login button",
291+
)
251292
print(response.headers.get('X-My-Header'))
252293

253-
session = response.parse() # get the object that `sessions.start()` would have returned
254-
print(session)
294+
session = response.parse() # get the object that `sessions.act()` would have returned
295+
print(session.data)
255296
```
256297

257298
These methods return an [`APIResponse`](https://github.com/browserbase/stagehand-python/tree/stainless/src/stagehand/_response.py) object.
@@ -265,7 +306,10 @@ The above interface eagerly reads the full response body when you make the reque
265306
To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.
266307

267308
```python
268-
with client.sessions.with_streaming_response.start() as response:
309+
with client.sessions.with_streaming_response.act(
310+
id="c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123",
311+
input="Click the login button",
312+
) as response:
269313
print(response.headers.get("X-My-Header"))
270314

271315
for line in response.iter_lines():

api.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,25 @@
33
Types:
44

55
```python
6-
from stagehand.types import Action, ModelConfig
6+
from stagehand.types import (
7+
Action,
8+
ModelConfig,
9+
SessionActResponse,
10+
SessionEndResponse,
11+
SessionExecuteResponse,
12+
SessionExtractResponse,
13+
SessionNavigateResponse,
14+
SessionObserveResponse,
15+
SessionStartResponse,
16+
)
717
```
818

919
Methods:
1020

11-
- <code title="post /sessions/{id}/act">client.sessions.<a href="./src/stagehand/resources/sessions.py">act</a>(id, \*\*<a href="src/stagehand/types/session_act_params.py">params</a>) -> object</code>
12-
- <code title="post /sessions/{id}/end">client.sessions.<a href="./src/stagehand/resources/sessions.py">end</a>(id) -> object</code>
13-
- <code title="post /sessions/{id}/agentExecute">client.sessions.<a href="./src/stagehand/resources/sessions.py">execute_agent</a>(id, \*\*<a href="src/stagehand/types/session_execute_agent_params.py">params</a>) -> object</code>
14-
- <code title="post /sessions/{id}/extract">client.sessions.<a href="./src/stagehand/resources/sessions.py">extract</a>(id, \*\*<a href="src/stagehand/types/session_extract_params.py">params</a>) -> object</code>
15-
- <code title="post /sessions/{id}/navigate">client.sessions.<a href="./src/stagehand/resources/sessions.py">navigate</a>(id, \*\*<a href="src/stagehand/types/session_navigate_params.py">params</a>) -> object</code>
16-
- <code title="post /sessions/{id}/observe">client.sessions.<a href="./src/stagehand/resources/sessions.py">observe</a>(id, \*\*<a href="src/stagehand/types/session_observe_params.py">params</a>) -> object</code>
17-
- <code title="post /sessions/start">client.sessions.<a href="./src/stagehand/resources/sessions.py">start</a>(\*\*<a href="src/stagehand/types/session_start_params.py">params</a>) -> object</code>
21+
- <code title="post /v1/sessions/{id}/act">client.sessions.<a href="./src/stagehand/resources/sessions.py">act</a>(id, \*\*<a href="src/stagehand/types/session_act_params.py">params</a>) -> <a href="./src/stagehand/types/session_act_response.py">SessionActResponse</a></code>
22+
- <code title="post /v1/sessions/{id}/end">client.sessions.<a href="./src/stagehand/resources/sessions.py">end</a>(id) -> <a href="./src/stagehand/types/session_end_response.py">SessionEndResponse</a></code>
23+
- <code title="post /v1/sessions/{id}/agentExecute">client.sessions.<a href="./src/stagehand/resources/sessions.py">execute</a>(id, \*\*<a href="src/stagehand/types/session_execute_params.py">params</a>) -> <a href="./src/stagehand/types/session_execute_response.py">SessionExecuteResponse</a></code>
24+
- <code title="post /v1/sessions/{id}/extract">client.sessions.<a href="./src/stagehand/resources/sessions.py">extract</a>(id, \*\*<a href="src/stagehand/types/session_extract_params.py">params</a>) -> <a href="./src/stagehand/types/session_extract_response.py">SessionExtractResponse</a></code>
25+
- <code title="post /v1/sessions/{id}/navigate">client.sessions.<a href="./src/stagehand/resources/sessions.py">navigate</a>(id, \*\*<a href="src/stagehand/types/session_navigate_params.py">params</a>) -> <a href="./src/stagehand/types/session_navigate_response.py">SessionNavigateResponse</a></code>
26+
- <code title="post /v1/sessions/{id}/observe">client.sessions.<a href="./src/stagehand/resources/sessions.py">observe</a>(id, \*\*<a href="src/stagehand/types/session_observe_params.py">params</a>) -> <a href="./src/stagehand/types/session_observe_response.py">SessionObserveResponse</a></code>
27+
- <code title="post /v1/sessions/start">client.sessions.<a href="./src/stagehand/resources/sessions.py">start</a>(\*\*<a href="src/stagehand/types/session_start_params.py">params</a>) -> <a href="./src/stagehand/types/session_start_response.py">SessionStartResponse</a></code>

0 commit comments

Comments
 (0)