mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-05-20 00:22:31 +00:00
refactor(loop): extract _build_retry_wait_callback
This commit is contained in:
parent
b2fb776a68
commit
d2cb8ac17f
@ -591,6 +591,25 @@ class AgentLoop:
|
|||||||
|
|
||||||
return _bus_progress
|
return _bus_progress
|
||||||
|
|
||||||
|
async def _build_retry_wait_callback(
|
||||||
|
self, msg: InboundMessage
|
||||||
|
) -> Callable[[str], Awaitable[None]]:
|
||||||
|
"""Build a retry-wait callback that publishes to the message bus."""
|
||||||
|
|
||||||
|
async def _on_retry_wait(content: str) -> None:
|
||||||
|
meta = dict(msg.metadata or {})
|
||||||
|
meta["_retry_wait"] = True
|
||||||
|
await self.bus.publish_outbound(
|
||||||
|
OutboundMessage(
|
||||||
|
channel=msg.channel,
|
||||||
|
chat_id=msg.chat_id,
|
||||||
|
content=content,
|
||||||
|
metadata=meta,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return _on_retry_wait
|
||||||
|
|
||||||
async def _dispatch_command_inline(
|
async def _dispatch_command_inline(
|
||||||
self,
|
self,
|
||||||
msg: InboundMessage,
|
msg: InboundMessage,
|
||||||
@ -1192,18 +1211,7 @@ class AgentLoop:
|
|||||||
)
|
)
|
||||||
|
|
||||||
_bus_progress = await self._build_bus_progress_callback(msg)
|
_bus_progress = await self._build_bus_progress_callback(msg)
|
||||||
|
_on_retry_wait = await self._build_retry_wait_callback(msg)
|
||||||
async def _on_retry_wait(content: str) -> None:
|
|
||||||
meta = dict(msg.metadata or {})
|
|
||||||
meta["_retry_wait"] = True
|
|
||||||
await self.bus.publish_outbound(
|
|
||||||
OutboundMessage(
|
|
||||||
channel=msg.channel,
|
|
||||||
chat_id=msg.chat_id,
|
|
||||||
content=content,
|
|
||||||
metadata=meta,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Persist the triggering user message up front so a mid-turn crash
|
# Persist the triggering user message up front so a mid-turn crash
|
||||||
# doesn't silently lose the prompt on recovery. ``media`` rides along
|
# doesn't silently lose the prompt on recovery. ``media`` rides along
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user