fix(cli): keep direct-call rendering compatible in tests
Only use process_direct_outbound when the agent loop actually exposes it as an async method, and otherwise fall back to the legacy process_direct path. This keeps the new CLI render-metadata flow without breaking existing test doubles or older direct-call implementations. Made-with: Cursor
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from contextlib import contextmanager, nullcontext
|
from contextlib import contextmanager, nullcontext
|
||||||
|
import inspect
|
||||||
import os
|
import os
|
||||||
import select
|
import select
|
||||||
import signal
|
import signal
|
||||||
@@ -767,17 +768,27 @@ def agent(
|
|||||||
nonlocal _thinking
|
nonlocal _thinking
|
||||||
_thinking = _ThinkingSpinner(enabled=not logs)
|
_thinking = _ThinkingSpinner(enabled=not logs)
|
||||||
with _thinking:
|
with _thinking:
|
||||||
response = await agent_loop.process_direct_outbound(
|
direct_outbound = getattr(agent_loop, "process_direct_outbound", None)
|
||||||
message,
|
if inspect.iscoroutinefunction(direct_outbound):
|
||||||
session_id,
|
response = await agent_loop.process_direct_outbound(
|
||||||
on_progress=_cli_progress,
|
message,
|
||||||
)
|
session_id,
|
||||||
|
on_progress=_cli_progress,
|
||||||
|
)
|
||||||
|
response_content = response.content if response else ""
|
||||||
|
response_meta = response.metadata if response else None
|
||||||
|
else:
|
||||||
|
response_content = await agent_loop.process_direct(
|
||||||
|
message,
|
||||||
|
session_id,
|
||||||
|
on_progress=_cli_progress,
|
||||||
|
)
|
||||||
|
response_meta = None
|
||||||
_thinking = None
|
_thinking = None
|
||||||
_print_agent_response(
|
kwargs = {"render_markdown": markdown}
|
||||||
response.content if response else "",
|
if response_meta is not None:
|
||||||
render_markdown=markdown,
|
kwargs["metadata"] = response_meta
|
||||||
metadata=response.metadata if response else None,
|
_print_agent_response(response_content, **kwargs)
|
||||||
)
|
|
||||||
await agent_loop.close_mcp()
|
await agent_loop.close_mcp()
|
||||||
|
|
||||||
asyncio.run(run_once())
|
asyncio.run(run_once())
|
||||||
|
|||||||
Reference in New Issue
Block a user