Skip to content

Commit 492c7a8

Browse files
committed
Update tasks.py
1 parent 6318ceb commit 492c7a8

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

src/browser_use_sdk/resources/tasks.py

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ def stream(
12361236
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
12371237
) -> AsyncIterator[TaskView]: ...
12381238

1239-
def stream(
1239+
async def stream(
12401240
self,
12411241
task_id: str,
12421242
structured_output_json: type[T] | None | NotGiven = NOT_GIVEN,
@@ -1252,32 +1252,29 @@ def stream(
12521252
Stream the task view as it is updated until the task is finished.
12531253
"""
12541254

1255-
async def _gen() -> AsyncIterator[TaskView | TaskViewWithOutput[T]]:
1256-
async for res in self._watch(
1257-
task_id=task_id,
1258-
extra_headers=extra_headers,
1259-
extra_query=extra_query,
1260-
extra_body=extra_body,
1261-
timeout=timeout,
1262-
):
1263-
if structured_output_json is not None and isinstance(structured_output_json, type):
1264-
if res.done_output is None:
1265-
yield TaskViewWithOutput[T](
1266-
**res.model_dump(),
1267-
parsed_output=None,
1268-
)
1269-
else:
1270-
schema: type[T] = structured_output_json
1271-
# pydantic returns the model instance, but the type checker can’t infer it.
1272-
parsed_output: T = schema.model_validate_json(res.done_output)
1273-
yield TaskViewWithOutput[T](
1274-
**res.model_dump(),
1275-
parsed_output=parsed_output,
1276-
)
1255+
async for res in self._watch(
1256+
task_id=task_id,
1257+
extra_headers=extra_headers,
1258+
extra_query=extra_query,
1259+
extra_body=extra_body,
1260+
timeout=timeout,
1261+
):
1262+
if structured_output_json is not None and isinstance(structured_output_json, type):
1263+
if res.done_output is None:
1264+
yield TaskViewWithOutput[T](
1265+
**res.model_dump(),
1266+
parsed_output=None,
1267+
)
12771268
else:
1278-
yield res
1279-
1280-
return _gen()
1269+
schema: type[T] = structured_output_json
1270+
# pydantic returns the model instance, but the type checker can’t infer it.
1271+
parsed_output: T = schema.model_validate_json(res.done_output)
1272+
yield TaskViewWithOutput[T](
1273+
**res.model_dump(),
1274+
parsed_output=parsed_output,
1275+
)
1276+
else:
1277+
yield res
12811278

12821279
async def _watch(
12831280
self,

0 commit comments

Comments
 (0)