@@ -61,20 +61,23 @@ def _request(self, method: str, path: str, **kwargs: Any) -> httpx.Response:
6161
6262 def send (
6363 self ,
64- to : str ,
64+ to : " str | list[str]" ,
6565 text : str ,
6666 * ,
6767 thread_id : Optional [str ] = None ,
6868 reply_to : Optional [str ] = None ,
69+ close_thread : bool = False ,
6970 wait : bool = True ,
7071 timeout : int = 30 ,
7172 ) -> dict :
72- """Send a message to a remote agent ."""
73+ """Send a message to one or more remote agents ."""
7374 body : dict = {"to" : to , "body" : {"text" : text }}
7475 if thread_id :
7576 body ["thread_id" ] = thread_id
7677 if reply_to :
7778 body ["reply_to" ] = reply_to
79+ if close_thread :
80+ body ["close_thread" ] = True
7881 resp = self ._request (
7982 "POST" ,
8083 "/v1/messages" ,
@@ -83,14 +86,25 @@ def send(
8386 )
8487 return resp .json ()
8588
86- def cancel_message (self , message_id : str ) -> None :
87- """Cancel a sent message."""
88- self ._request ("POST" , "/v1/messages/%s/cancel" % message_id )
89+ def stream_start (self , to : str , * , thread_id : Optional [str ] = None ) -> dict :
90+ """Open a streaming connection to a remote agent."""
91+ body : dict = {"to" : to }
92+ if thread_id :
93+ body ["thread_id" ] = thread_id
94+ return self ._request ("POST" , "/v1/stream/start" , json = body ).json ()
95+
96+ def stream_chunk (self , stream_id : str , text : str ) -> dict :
97+ """Send a text chunk on an open stream."""
98+ return self ._request (
99+ "POST" , "/v1/stream/chunk" , json = {"stream_id" : stream_id , "text" : text }
100+ ).json ()
89101
90- def send_streaming (self , to : str , text : str , ** kwargs : Any ) -> dict :
91- """Send a message using streaming delivery."""
92- body : dict = {"to" : to , "body" : {"text" : text }, ** kwargs }
93- return self ._request ("POST" , "/v1/messages/stream" , json = body ).json ()
102+ def stream_end (self , stream_id : str , * , close_thread : bool = False ) -> dict :
103+ """End a stream, optionally closing the thread."""
104+ body : dict = {"stream_id" : stream_id }
105+ if close_thread :
106+ body ["close_thread" ] = True
107+ return self ._request ("POST" , "/v1/stream/end" , json = body ).json ()
94108
95109 # ── Threads ──────────────────────────────────────────
96110
@@ -248,20 +262,23 @@ async def _request(self, method: str, path: str, **kwargs: Any) -> httpx.Respons
248262
249263 async def send (
250264 self ,
251- to : str ,
265+ to : " str | list[str]" ,
252266 text : str ,
253267 * ,
254268 thread_id : Optional [str ] = None ,
255269 reply_to : Optional [str ] = None ,
270+ close_thread : bool = False ,
256271 wait : bool = True ,
257272 timeout : int = 30 ,
258273 ) -> dict :
259- """Send a message to a remote agent ."""
274+ """Send a message to one or more remote agents ."""
260275 body : dict = {"to" : to , "body" : {"text" : text }}
261276 if thread_id :
262277 body ["thread_id" ] = thread_id
263278 if reply_to :
264279 body ["reply_to" ] = reply_to
280+ if close_thread :
281+ body ["close_thread" ] = True
265282 resp = await self ._request (
266283 "POST" ,
267284 "/v1/messages" ,
@@ -291,14 +308,25 @@ async def messages(self) -> AsyncIterator[Message]:
291308 _client = self ,
292309 )
293310
294- async def cancel_message (self , message_id : str ) -> None :
295- """Cancel a sent message."""
296- await self ._request ("POST" , "/v1/messages/%s/cancel" % message_id )
311+ async def stream_start (self , to : str , * , thread_id : Optional [str ] = None ) -> dict :
312+ """Open a streaming connection to a remote agent."""
313+ body : dict = {"to" : to }
314+ if thread_id :
315+ body ["thread_id" ] = thread_id
316+ return (await self ._request ("POST" , "/v1/stream/start" , json = body )).json ()
297317
298- async def send_streaming (self , to : str , text : str , ** kwargs : Any ) -> dict :
299- """Send a message using streaming delivery."""
300- body : dict = {"to" : to , "body" : {"text" : text }, ** kwargs }
301- return (await self ._request ("POST" , "/v1/messages/stream" , json = body )).json ()
318+ async def stream_chunk (self , stream_id : str , text : str ) -> dict :
319+ """Send a text chunk on an open stream."""
320+ return (await self ._request (
321+ "POST" , "/v1/stream/chunk" , json = {"stream_id" : stream_id , "text" : text }
322+ )).json ()
323+
324+ async def stream_end (self , stream_id : str , * , close_thread : bool = False ) -> dict :
325+ """End a stream, optionally closing the thread."""
326+ body : dict = {"stream_id" : stream_id }
327+ if close_thread :
328+ body ["close_thread" ] = True
329+ return (await self ._request ("POST" , "/v1/stream/end" , json = body )).json ()
302330
303331 # ── Threads ──────────────────────────────────────────
304332
0 commit comments