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
@@ -107,6 +110,19 @@ def __init__(
107110 self ._consumers = consumers
108111 self ._middleware = middleware
109112
113+ async def __aenter__ (self ) -> Self :
114+ """Enters the async context manager."""
115+ return self
116+
117+ async def __aexit__ (
118+ self ,
119+ exc_type : type [BaseException ] | None ,
120+ exc_val : BaseException | None ,
121+ exc_tb : TracebackType | None ,
122+ ) -> None :
123+ """Exits the async context manager and closes the client."""
124+ await self .close ()
125+
110126 @abstractmethod
111127 async def send_message (
112128 self ,
@@ -209,3 +225,7 @@ async def consume(
209225 return
210226 for c in self ._consumers :
211227 await c (event , card )
228+
229+ @abstractmethod
230+ async def close (self ) -> None :
231+ """Closes the client and releases any underlying resources."""
You can’t perform that action at this time.
0 commit comments