refactor(channels): move tool hint rendering out of core (#6498)

* refactor(channels): move tool hint rendering out of core

* test: align progress privacy check with structured tool events
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-29 10:37:29 +08:00
1 parent b1cc89e922
commit acc3750c28
30 files changed
+530 -124

No files matched your search

+17
View File
@@ -3,12 +3,14 @@
from __future__ import annotations
from abc import ABC, abstractmethod
from dataclasses import replace
from pathlib import Path
from typing import Any, cast
from loguru import logger
from nanobot.bus.events import InboundMessage, OutboundMessage
from nanobot.bus.outbound_events import ProgressEvent
from nanobot.bus.queue import MessageBus
from nanobot.config.network import NetworkConfig
from nanobot.pairing import (
@@ -19,6 +21,7 @@ from nanobot.pairing import (
record_delivery,
)
from nanobot.pairing.events import PairingChanged
from nanobot.utils.tool_hints import format_tool_event_hints
class BaseChannel(ABC):
@@ -35,6 +38,7 @@ class BaseChannel(ABC):
uses_shared_proxy: bool = False
send_progress: bool = True
send_tool_hints: bool = True
tool_hint_max_length: int = 40
show_reasoning: bool = True
show_compaction_notices: bool = False
@@ -115,6 +119,19 @@ class BaseChannel(ABC):
"""
pass
def prepare_tool_events(self, msg: OutboundMessage) -> OutboundMessage:
"""Project tool activity once before delivery; override for native UI.
Keep the core event unchanged and reuse the returned envelope throughout
retries, including adapters that track already-sent multipart messages.
"""
event = msg.event
if isinstance(event, ProgressEvent) and event.tool_hint and event.tool_events:
return replace(msg, content=format_tool_event_hints(
event.tool_events, max_length=self.tool_hint_max_length,
))
return msg
@property
def has_pending_delivery(self) -> bool:
"""Whether delivery outlives an awaited ``send``/streaming call.