feat(webui): persist agent activity events
This commit is contained in:
@@ -10,13 +10,21 @@ from nanobot.agent.hook import AgentHookContext
|
||||
|
||||
|
||||
def on_progress_accepts_tool_events(cb: Callable[..., Any]) -> bool:
|
||||
return _on_progress_accepts(cb, "tool_events")
|
||||
|
||||
|
||||
def on_progress_accepts_file_edit_events(cb: Callable[..., Any]) -> bool:
|
||||
return _on_progress_accepts(cb, "file_edit_events")
|
||||
|
||||
|
||||
def _on_progress_accepts(cb: Callable[..., Any], name: str) -> bool:
|
||||
try:
|
||||
sig = inspect.signature(cb)
|
||||
except (TypeError, ValueError):
|
||||
return False
|
||||
if any(p.kind == inspect.Parameter.VAR_KEYWORD for p in sig.parameters.values()):
|
||||
return True
|
||||
return "tool_events" in sig.parameters
|
||||
return name in sig.parameters
|
||||
|
||||
|
||||
async def invoke_on_progress(
|
||||
@@ -32,6 +40,15 @@ async def invoke_on_progress(
|
||||
await on_progress(content, tool_hint=tool_hint)
|
||||
|
||||
|
||||
async def invoke_file_edit_progress(
|
||||
on_progress: Callable[..., Awaitable[None]],
|
||||
file_edit_events: list[dict[str, Any]],
|
||||
) -> None:
|
||||
if not file_edit_events or not on_progress_accepts_file_edit_events(on_progress):
|
||||
return
|
||||
await on_progress("", file_edit_events=file_edit_events)
|
||||
|
||||
|
||||
def build_tool_event_start_payload(tool_call: Any) -> dict[str, Any]:
|
||||
return {
|
||||
"version": 1,
|
||||
|
||||
Reference in New Issue
Block a user