mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-05-22 17:42:24 +00:00
feat(dream): non-blocking /dream with progress feedback
This commit is contained in:
parent
401d1f57fa
commit
acf652358c
@ -93,14 +93,30 @@ async def cmd_new(ctx: CommandContext) -> OutboundMessage:
|
|||||||
|
|
||||||
async def cmd_dream(ctx: CommandContext) -> OutboundMessage:
|
async def cmd_dream(ctx: CommandContext) -> OutboundMessage:
|
||||||
"""Manually trigger a Dream consolidation run."""
|
"""Manually trigger a Dream consolidation run."""
|
||||||
|
import time
|
||||||
|
|
||||||
loop = ctx.loop
|
loop = ctx.loop
|
||||||
try:
|
msg = ctx.msg
|
||||||
did_work = await loop.dream.run()
|
|
||||||
content = "Dream completed." if did_work else "Dream: nothing to process."
|
async def _run_dream():
|
||||||
except Exception as e:
|
t0 = time.monotonic()
|
||||||
content = f"Dream failed: {e}"
|
try:
|
||||||
|
did_work = await loop.dream.run()
|
||||||
|
elapsed = time.monotonic() - t0
|
||||||
|
if did_work:
|
||||||
|
content = f"Dream completed in {elapsed:.1f}s."
|
||||||
|
else:
|
||||||
|
content = "Dream: nothing to process."
|
||||||
|
except Exception as e:
|
||||||
|
elapsed = time.monotonic() - t0
|
||||||
|
content = f"Dream failed after {elapsed:.1f}s: {e}"
|
||||||
|
await loop.bus.publish_outbound(OutboundMessage(
|
||||||
|
channel=msg.channel, chat_id=msg.chat_id, content=content,
|
||||||
|
))
|
||||||
|
|
||||||
|
asyncio.create_task(_run_dream())
|
||||||
return OutboundMessage(
|
return OutboundMessage(
|
||||||
channel=ctx.msg.channel, chat_id=ctx.msg.chat_id, content=content,
|
channel=msg.channel, chat_id=msg.chat_id, content="Dreaming...",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user