refactor(loop): extract _build_retry_wait_callback
This commit is contained in:
+20
-12
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user