Skip to content

Commit 577cea0

Browse files
feat(api): manual updates
1 parent 0cdb22b commit 577cea0

16 files changed

+2146
-313
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-e96507dd78e76fccc77ba7fb09704da127ead6f4d73ea854e9b2150e90787ff4.yml
3-
openapi_spec_hash: 0c2548b8fdd6de6789b19123e69609c1
4-
config_hash: c3abb41dbe698d59b3bf12f393013d54
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fstagehand-f7d6b6489159f611a2bfdc267ce0a6fc0455bed1ffa0c310044baaa5d8381b9b.yml
3+
openapi_spec_hash: cd88d8068abfde8382da0bed674e440c
4+
config_hash: 5c69fb596588b8ace08203858518c149

api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Types:
66
from stagehand.types import (
77
Action,
88
ModelConfig,
9+
StreamEvent,
910
SessionActResponse,
1011
SessionEndResponse,
1112
SessionExecuteResponse,

src/stagehand/_client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ def __init__(
124124
_strict_response_validation=_strict_response_validation,
125125
)
126126

127+
self._default_stream_cls = Stream
128+
127129
@cached_property
128130
def sessions(self) -> SessionsResource:
129131
from .resources.sessions import SessionsResource
@@ -339,6 +341,8 @@ def __init__(
339341
_strict_response_validation=_strict_response_validation,
340342
)
341343

344+
self._default_stream_cls = AsyncStream
345+
342346
@cached_property
343347
def sessions(self) -> AsyncSessionsResource:
344348
from .resources.sessions import AsyncSessionsResource

src/stagehand/_streaming.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,26 @@ def __stream__(self) -> Iterator[_T]:
5656

5757
try:
5858
for sse in iterator:
59-
yield process_data(data=sse.json(), cast_to=cast_to, response=response)
59+
if sse.data.startswith("finished"):
60+
break
61+
62+
if sse.data.startswith("error"):
63+
body = sse.data
64+
65+
try:
66+
body = sse.json()
67+
err_msg = f"{body}"
68+
except Exception:
69+
err_msg = sse.data or f"Error code: {response.status_code}"
70+
71+
raise self._client._make_status_error(
72+
err_msg,
73+
body=body,
74+
response=self.response,
75+
)
76+
77+
if sse.event is None:
78+
yield process_data(data=sse.json(), cast_to=cast_to, response=response)
6079
finally:
6180
# Ensure the response is closed even if the consumer doesn't read all data
6281
response.close()
@@ -120,7 +139,26 @@ async def __stream__(self) -> AsyncIterator[_T]:
120139

121140
try:
122141
async for sse in iterator:
123-
yield process_data(data=sse.json(), cast_to=cast_to, response=response)
142+
if sse.data.startswith("finished"):
143+
break
144+
145+
if sse.data.startswith("error"):
146+
body = sse.data
147+
148+
try:
149+
body = sse.json()
150+
err_msg = f"{body}"
151+
except Exception:
152+
err_msg = sse.data or f"Error code: {response.status_code}"
153+
154+
raise self._client._make_status_error(
155+
err_msg,
156+
body=body,
157+
response=self.response,
158+
)
159+
160+
if sse.event is None:
161+
yield process_data(data=sse.json(), cast_to=cast_to, response=response)
124162
finally:
125163
# Ensure the response is closed even if the consumer doesn't read all data
126164
await response.aclose()

0 commit comments

Comments
 (0)