Merge branch 'main' into pr-1370

This commit is contained in:
Re-bin
2026-03-01 12:48:01 +00:00

View File

@@ -296,18 +296,30 @@ def gateway(
# Set cron callback (needs agent) # Set cron callback (needs agent)
async def on_cron_job(job: CronJob) -> str | None: async def on_cron_job(job: CronJob) -> str | None:
"""Execute a cron job through the agent.""" """Execute a cron job through the agent."""
from nanobot.agent.tools.message import MessageTool
reminder_note = (
"[Scheduled Task] Timer finished.\n\n"
f"Task '{job.name}' has been triggered.\n"
f"Scheduled instruction: {job.payload.message}"
)
response = await agent.process_direct( response = await agent.process_direct(
job.payload.message, reminder_note,
session_key=f"cron:{job.id}", session_key=f"cron:{job.id}",
channel=job.payload.channel or "cli", channel=job.payload.channel or "cli",
chat_id=job.payload.to or "direct", chat_id=job.payload.to or "direct",
) )
if job.payload.deliver and job.payload.to:
message_tool = agent.tools.get("message")
if isinstance(message_tool, MessageTool) and message_tool._sent_in_turn:
return response
if job.payload.deliver and job.payload.to and response:
from nanobot.bus.events import OutboundMessage from nanobot.bus.events import OutboundMessage
await bus.publish_outbound(OutboundMessage( await bus.publish_outbound(OutboundMessage(
channel=job.payload.channel or "cli", channel=job.payload.channel or "cli",
chat_id=job.payload.to, chat_id=job.payload.to,
content=response or "" content=response
)) ))
return response return response
cron.on_job = on_cron_job cron.on_job = on_cron_job