File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33
44from abc import ABC , abstractmethod
55from collections .abc import AsyncIterator , Callable , Coroutine
6+ from types import TracebackType
67from typing import Any
78
9+ from typing_extensions import Self
10+
811import httpx
912
1013from a2a .client .middleware import ClientCallContext , ClientCallInterceptor
@@ -106,6 +109,19 @@ def __init__(
106109 self ._consumers = consumers
107110 self ._middleware = middleware
108111
112+ async def __aenter__ (self ) -> Self :
113+ """Enters the async context manager."""
114+ return self
115+
116+ async def __aexit__ (
117+ self ,
118+ exc_type : type [BaseException ] | None ,
119+ exc_val : BaseException | None ,
120+ exc_tb : TracebackType | None ,
121+ ) -> None :
122+ """Exits the async context manager and closes the client."""
123+ await self .close ()
124+
109125 @abstractmethod
110126 async def send_message (
111127 self ,
@@ -217,3 +233,7 @@ async def consume(
217233 return
218234 for c in self ._consumers :
219235 await c (event , card )
236+
237+ @abstractmethod
238+ async def close (self ) -> None :
239+ """Closes the client and releases any underlying resources."""
You can’t perform that action at this time.
0 commit comments