Co-Authored-By: Quentin Torroba <quentin.torroba@mistral.ai> Co-Authored-By: Michel Thomazo <michel.thomazo@mistral.ai> Co-Authored-By: Clément Drouin <clement.drouin@mistral.ai> Co-Authored-By: Vincent Guilloux <vincent.guilloux@mistral.ai> Co-Authored-By: Clément Siriex <clement.sirieix@mistral.ai> Co-Authored-By: Kim-Adeline Miguel <kimadeline.miguel@mistral.ai> Co-Authored-By: Thaddee Tyl <thaddee.tyl@gmail.com> Co-Authored-By: David Brochart <david.brochart@gmail.com> Co-Authored-By: Joseph Guhlin <joseph.guhlin@gmail.com> Co-Authored-By: Thomas Kenbeek <thomaskenbeek@gmail.com> Co-Authored-By: Remenby31 <baptiste.cruvellier31@gmail.com>
130 lines
3.4 KiB
Python
130 lines
3.4 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from acp import (
|
|
Agent as AcpAgent,
|
|
Client,
|
|
KillTerminalCommandResponse,
|
|
ReadTextFileResponse,
|
|
ReleaseTerminalResponse,
|
|
RequestPermissionResponse,
|
|
SessionNotification,
|
|
TerminalHandle,
|
|
TerminalOutputResponse,
|
|
WaitForTerminalExitResponse,
|
|
WriteTextFileResponse,
|
|
)
|
|
from acp.schema import (
|
|
AgentMessageChunk,
|
|
AgentPlanUpdate,
|
|
AgentThoughtChunk,
|
|
AvailableCommandsUpdate,
|
|
CurrentModeUpdate,
|
|
EnvVariable,
|
|
PermissionOption,
|
|
SessionInfoUpdate,
|
|
ToolCallProgress,
|
|
ToolCallStart,
|
|
ToolCallUpdate,
|
|
UserMessageChunk,
|
|
)
|
|
|
|
|
|
class FakeClient(Client):
|
|
agent: AcpAgent
|
|
|
|
def __init__(self) -> None:
|
|
self._session_updates = []
|
|
|
|
async def session_update(
|
|
self,
|
|
session_id: str,
|
|
update: UserMessageChunk
|
|
| AgentMessageChunk
|
|
| AgentThoughtChunk
|
|
| ToolCallStart
|
|
| ToolCallProgress
|
|
| AgentPlanUpdate
|
|
| AvailableCommandsUpdate
|
|
| CurrentModeUpdate
|
|
| SessionInfoUpdate,
|
|
**kwargs: Any,
|
|
) -> None:
|
|
self._session_updates.append(
|
|
SessionNotification(session_id=session_id, update=update)
|
|
)
|
|
|
|
async def request_permission(
|
|
self,
|
|
options: list[PermissionOption],
|
|
session_id: str,
|
|
tool_call: ToolCallUpdate,
|
|
**kwargs: Any,
|
|
) -> RequestPermissionResponse:
|
|
raise NotImplementedError()
|
|
|
|
async def read_text_file(
|
|
self,
|
|
path: str,
|
|
session_id: str,
|
|
limit: int | None = None,
|
|
line: int | None = None,
|
|
**kwargs: Any,
|
|
) -> ReadTextFileResponse:
|
|
raise NotImplementedError()
|
|
|
|
async def write_text_file(
|
|
self, content: str, path: str, session_id: str, **kwargs: Any
|
|
) -> WriteTextFileResponse | None:
|
|
raise NotImplementedError()
|
|
|
|
async def create_terminal(
|
|
self,
|
|
command: str,
|
|
session_id: str,
|
|
args: list[str] | None = None,
|
|
cwd: str | None = None,
|
|
env: list[EnvVariable] | None = None,
|
|
output_byte_limit: int | None = None,
|
|
**kwargs: Any,
|
|
) -> TerminalHandle:
|
|
raise NotImplementedError()
|
|
|
|
async def terminal_output(
|
|
self, session_id: str, terminal_id: str, **kwargs: Any
|
|
) -> TerminalOutputResponse:
|
|
raise NotImplementedError()
|
|
|
|
async def release_terminal(
|
|
self, session_id: str, terminal_id: str, **kwargs: Any
|
|
) -> ReleaseTerminalResponse | None:
|
|
raise NotImplementedError()
|
|
|
|
async def wait_for_terminal_exit(
|
|
self, session_id: str, terminal_id: str, **kwargs: Any
|
|
) -> WaitForTerminalExitResponse:
|
|
raise NotImplementedError()
|
|
|
|
async def kill_terminal(
|
|
self, session_id: str, terminal_id: str, **kwargs: Any
|
|
) -> KillTerminalCommandResponse | None:
|
|
raise NotImplementedError()
|
|
|
|
async def ext_method(self, method: str, params: dict[str, Any]) -> dict[str, Any]:
|
|
raise NotImplementedError()
|
|
|
|
async def ext_notification(self, method: str, params: dict[str, Any]) -> None:
|
|
raise NotImplementedError()
|
|
|
|
async def close(self) -> None:
|
|
raise NotImplementedError()
|
|
|
|
def on_connect(self, conn: AcpAgent) -> None:
|
|
self.agent = conn
|
|
|
|
async def __aenter__(self) -> FakeClient:
|
|
return self
|
|
|
|
async def __aexit__(self, exc_type, exc, tb) -> None:
|
|
await self.close()
|