feat(core): publish tool.result on the bus for the activity panel
This commit is contained in:
@@ -12,6 +12,9 @@ from claude_agent_sdk import (
|
||||
ResultMessage,
|
||||
StreamEvent,
|
||||
TextBlock,
|
||||
ToolResultBlock,
|
||||
ToolUseBlock,
|
||||
UserMessage,
|
||||
project_key_for_directory,
|
||||
)
|
||||
|
||||
@@ -655,3 +658,40 @@ def test_agent_kinds_follow_prompts(tmp_path: Path) -> None:
|
||||
kinds=("master", "deep"),
|
||||
prompts=Prompts(master=()),
|
||||
)
|
||||
|
||||
|
||||
async def test_observer_publishes_tool_results_for_the_panel(world: World) -> None:
|
||||
seen: list[dict[str, Any]] = []
|
||||
|
||||
async def collect() -> None:
|
||||
async for event in world.bus.stream(conversation_id="c1"):
|
||||
seen.append(event)
|
||||
|
||||
task = asyncio.create_task(collect())
|
||||
await asyncio.sleep(0)
|
||||
observe = world.conversations._observer("c1", "t1", "user")
|
||||
observe(
|
||||
AssistantMessage(
|
||||
content=[ToolUseBlock(id="toolu_1", name="Bash", input={"command": "ls"})],
|
||||
model="m",
|
||||
parent_tool_use_id="toolu_0",
|
||||
)
|
||||
)
|
||||
observe(
|
||||
UserMessage(
|
||||
content=[
|
||||
ToolResultBlock(tool_use_id="toolu_1", content="a\nb", is_error=False)
|
||||
],
|
||||
parent_tool_use_id="toolu_0",
|
||||
)
|
||||
)
|
||||
observe(UserMessage(content="plain text, no tool result"))
|
||||
await asyncio.sleep(0.05)
|
||||
task.cancel()
|
||||
assert [e["type"] for e in seen] == ["tool", "tool.result"]
|
||||
tool, result = seen
|
||||
assert tool["tool_use_id"] == "toolu_1" and tool["parent_tool_use_id"] == "toolu_0"
|
||||
assert result["tool_use_id"] == "toolu_1"
|
||||
assert result["parent_tool_use_id"] == "toolu_0"
|
||||
assert result["turn_id"] == "t1" and result["is_error"] is False
|
||||
assert result["content"] == "a\nb"
|
||||
|
||||
Reference in New Issue
Block a user