A client for the session `sesn_1`, whose event history is `history` and whose event stream gives `live`. Reading the history fails when `history` is `None`.
(
respx_mock: MockRouter,
spans: Spans,
*,
history: list[dict[str, Any]] | None,
live: list[dict[str, Any]],
**options: Any,
)
| 2145 | |
| 2146 | |
| 2147 | def session_api( |
| 2148 | respx_mock: MockRouter, |
| 2149 | spans: Spans, |
| 2150 | *, |
| 2151 | history: list[dict[str, Any]] | None, |
| 2152 | live: list[dict[str, Any]], |
| 2153 | **options: Any, |
| 2154 | ) -> AsyncAnthropic: |
| 2155 | """A client for the session `sesn_1`, whose event history is `history` and whose event stream gives `live`. |
| 2156 | |
| 2157 | Reading the history fails when `history` is `None`. |
| 2158 | """ |
| 2159 | body = b"".join(f"event: {event['type']}\ndata: {json.dumps(event)}\n\n".encode() for event in live) |
| 2160 | respx_mock.get("/v1/sessions/sesn_1/events/stream").mock( |
| 2161 | return_value=httpx2.Response(200, content=body, headers={"content-type": "text/event-stream"}) |
| 2162 | ) |
| 2163 | respx_mock.get("/v1/sessions/sesn_1/events").mock( |
| 2164 | return_value=httpx2.Response(400, json={"type": "error", "error": {"type": "invalid_request_error"}}) |
| 2165 | if history is None |
| 2166 | else httpx2.Response(200, json={"data": history, "next_page": None}) |
| 2167 | ) |
| 2168 | respx_mock.post("/v1/sessions/sesn_1/events").mock(return_value=httpx2.Response(200, json={"data": []})) |
| 2169 | return AsyncAnthropic(base_url=base_url, api_key="key", open_telemetry=spans.option(**options)) |
| 2170 | |
| 2171 | |
| 2172 | class TestSessionToolRunnerSpans: |
no test coverage detected