3939 WriteTextFileRequest ,
4040 WriteTextFileResponse ,
4141)
42- from ..terminal import TerminalHandle
4342from ..utils import compatible_class , notify_model , param_model , request_model , request_optional_model
4443from .router import build_agent_router
4544
5049@final
5150@compatible_class
5251class AgentSideConnection :
53- """Agent-side connection wrapper that dispatches JSON-RPC messages to a Client implementation."""
52+ """Agent-side connection wrapper that dispatches JSON-RPC messages to a Client implementation.
53+ The agent can use this connection to communicate with the Client so it behaves like a Client.
54+ """
5455
5556 def __init__ (
5657 self ,
@@ -62,7 +63,7 @@ def __init__(
6263 use_unstable_protocol : bool = False ,
6364 ** connection_kwargs : Any ,
6465 ) -> None :
65- agent = to_agent (cast ( Client , self ) ) if callable (to_agent ) else to_agent
66+ agent = to_agent (self ) if callable (to_agent ) else to_agent
6667 if not isinstance (input_stream , asyncio .StreamWriter ) or not isinstance (output_stream , asyncio .StreamReader ):
6768 raise TypeError (_AGENT_CONNECTION_ERROR )
6869 handler = build_agent_router (cast (Agent , agent ), use_unstable_protocol = use_unstable_protocol )
@@ -141,8 +142,8 @@ async def create_terminal(
141142 env : list [EnvVariable ] | None = None ,
142143 output_byte_limit : int | None = None ,
143144 ** kwargs : Any ,
144- ) -> TerminalHandle :
145- create_response = await request_model (
145+ ) -> CreateTerminalResponse :
146+ return await request_model (
146147 self ._conn ,
147148 CLIENT_METHODS ["terminal_create" ],
148149 CreateTerminalRequest (
@@ -156,7 +157,6 @@ async def create_terminal(
156157 ),
157158 CreateTerminalResponse ,
158159 )
159- return TerminalHandle (create_response .terminal_id , session_id , self ._conn )
160160
161161 @param_model (TerminalOutputRequest )
162162 async def terminal_output (self , session_id : str , terminal_id : str , ** kwargs : Any ) -> TerminalOutputResponse :
@@ -214,3 +214,7 @@ async def __aenter__(self) -> AgentSideConnection:
214214
215215 async def __aexit__ (self , exc_type , exc , tb ) -> None :
216216 await self .close ()
217+
218+ def on_connect (self , conn : Agent ) -> None :
219+ # A dummy method to match the Client protocol
220+ pass
0 commit comments