Files
javis_bot/src/voice_worker/schedule_bridge.py
javis-bot ea2d3ba958 feat: reminders and scheduled tasks (schedule tool, app store and delivery)
The brain gets a schedule tool (add, list, delete the asker's own reminders,
timers and tasks) offered only with a schedule backend. The voice worker asks
the app through schedule_action and runs fired tasks as reply via task with
read-only tools, no MCP and a fresh short-term memory. The app keeps the
schedules in config/schedules.json, fires them every 5 s, speaks them when the
person is in Jarvis's voice channel and otherwise posts in the chat channel
they asked in (or schedule.chatChannel for voice). A feature switch and a
예약 screen list and delete everyone's schedules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 16:27:42 +09:00

28 lines
1.2 KiB
Python

"""The schedule backend the brain's schedule tool uses during one reply (schedule.spec.md).
The app keeps the schedules: every action goes to it as ``schedule_action`` for the person asking
and waits for its ``schedule_action_result``. Built per reply, on the event loop; ``act`` is called
from the brain's thread.
"""
from __future__ import annotations
import asyncio
from typing import Any, Optional
class ScheduleBridge:
def __init__(self, session, loop: asyncio.AbstractEventLoop, user: str, via: str, channel: Optional[str]):
self._session = session
self._loop = loop
# Who asked and where: the app delivers there (voice, or the chat channel asked in).
self._origin = {"user": user, "via": via, **({"channel": channel} if channel else {})}
def act(self, action: str, **kw: Any) -> dict:
fut = asyncio.run_coroutine_threadsafe(
self._session.schedule_action(action, {**self._origin, **kw}), self._loop)
try:
return fut.result(self._session.worker.chat_timeout_s + 5)
except Exception as e: # loop gone or the wait broke
return {"ok": False, "error": f"the app did not answer ({type(e).__name__})"}