| 1 | """ |
| 2 | Минимальный ACP-клиент: поднимает локальный echo_agent.py и шлёт один prompt. |
| 3 | |
| 4 | Запуск из каталога AcpSmoke: |
| 5 | pip install -r requirements.txt |
| 6 | python smoke_client.py |
| 7 | """ |
| 8 | |
| 9 | from __future__ import annotations |
| 10 | |
| 11 | import asyncio |
| 12 | import sys |
| 13 | from pathlib import Path |
| 14 | from typing import Any |
| 15 | |
| 16 | from acp import spawn_agent_process, text_block |
| 17 | from acp.interfaces import Client |
| 18 | |
| 19 | |
| 20 | class SmokeClient(Client): |
| 21 | """Заглушка прав доступа; печатает поток session_update от агента.""" |
| 22 | |
| 23 | async def request_permission(self, options, session_id, tool_call, **kwargs: Any): |
| 24 | return {"outcome": {"outcome": "cancelled"}} |
| 25 | |
| 26 | async def session_update(self, session_id, update, **kwargs): |
| 27 | print("session_update:", session_id, update) |
| 28 | |
| 29 | |
| 30 | async def main() -> None: |
| 31 | root = Path(__file__).resolve().parent |
| 32 | agent_script = root / "echo_agent.py" |
| 33 | if not agent_script.is_file(): |
| 34 | print("Не найден echo_agent.py рядом со smoke_client.py", file=sys.stderr) |
| 35 | sys.exit(1) |
| 36 | |
| 37 | async with spawn_agent_process(SmokeClient(), sys.executable, str(agent_script)) as (conn, _proc): |
| 38 | await conn.initialize(protocol_version=1) |
| 39 | session = await conn.new_session(cwd=str(root), mcp_servers=[]) |
| 40 | await conn.prompt( |
| 41 | session_id=session.session_id, |
| 42 | prompt=[text_block("Hello ACP from Cascade AcpSmoke")], |
| 43 | ) |
| 44 | print("ACP smoke OK") |
| 45 | |
| 46 | |
| 47 | if __name__ == "__main__": |
| 48 | asyncio.run(main()) |
| 49 | |