MCPcopy Create free account
hub / github.com/anomalyco/opencode-sdk-python / to_streamed_response_wrapper

Function to_streamed_response_wrapper

src/opencode_ai/_response.py:647–663  ·  view source on GitHub ↗

Higher order function that takes one of our bound API methods and wraps it to support streaming and returning the raw `APIResponse` object directly.

(func: Callable[P, R])

Source from the content-addressed store, hash-verified

645
646
647def to_streamed_response_wrapper(func: Callable[P, R]) -> Callable[P, ResponseContextManager[APIResponse[R]]]:
648 """Higher order function that takes one of our bound API methods and wraps it
649 to support streaming and returning the raw `APIResponse` object directly.
650 """
651
652 @functools.wraps(func)
653 def wrapped(*args: P.args, **kwargs: P.kwargs) -> ResponseContextManager[APIResponse[R]]:
654 extra_headers: dict[str, str] = {**(cast(Any, kwargs.get("extra_headers")) or {})}
655 extra_headers[RAW_RESPONSE_HEADER] = "stream"
656
657 kwargs["extra_headers"] = extra_headers
658
659 make_request = functools.partial(func, *args, **kwargs)
660
661 return ResponseContextManager(cast(Callable[[], APIResponse[R]], make_request))
662
663 return wrapped
664
665
666def async_to_streamed_response_wrapper(

Callers 7

__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected