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>
This commit is contained in:
@@ -122,6 +122,30 @@ pub struct ChatAction {
|
||||
pub emoji: Option<String>,
|
||||
}
|
||||
|
||||
/// The brain's schedule tool asks the app for the person asking (voice_worker.spec.md, "Schedules").
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq)]
|
||||
pub struct ScheduleAction {
|
||||
pub id: String,
|
||||
/// `add`, `list` or `delete`.
|
||||
pub action: String,
|
||||
pub user: String,
|
||||
/// `voice` or `chat`: where they asked.
|
||||
pub via: String,
|
||||
#[serde(default)]
|
||||
pub channel: Option<String>,
|
||||
#[serde(default)]
|
||||
pub kind: Option<String>,
|
||||
#[serde(default)]
|
||||
pub text: Option<String>,
|
||||
#[serde(default)]
|
||||
pub at: Option<f64>,
|
||||
#[serde(default)]
|
||||
pub repeat: Option<String>,
|
||||
/// delete: the schedule's id.
|
||||
#[serde(default)]
|
||||
pub schedule: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum WorkerEvent {
|
||||
Ready(HelloOk),
|
||||
@@ -132,6 +156,7 @@ pub enum WorkerEvent {
|
||||
TtsAudio { id: String, seq: u32, pcm: Vec<u8> },
|
||||
TtsDone(TtsDone),
|
||||
ChatAction(ChatAction),
|
||||
ScheduleAction(ScheduleAction),
|
||||
/// The brain's answer to `reply` (empty and `failed` when it gave none).
|
||||
ReplyText { id: String, text: String, failed: bool },
|
||||
/// Was the utterance said to Jarvis? (a failed judgement is a no)
|
||||
@@ -320,6 +345,21 @@ impl WorkerClient {
|
||||
self.send_json(v);
|
||||
}
|
||||
|
||||
/// The outcome of a `schedule_action`: `{item}` or `{items}`, or why it failed.
|
||||
pub fn schedule_action_result(&self, id: &str, result: Result<Value, String>) {
|
||||
let msg = match result {
|
||||
Ok(Value::Object(mut m)) => {
|
||||
m.insert("type".into(), json!("schedule_action_result"));
|
||||
m.insert("id".into(), json!(id));
|
||||
m.insert("ok".into(), json!(true));
|
||||
Value::Object(m)
|
||||
}
|
||||
Ok(_) => json!({"type": "schedule_action_result", "id": id, "ok": true}),
|
||||
Err(e) => json!({"type": "schedule_action_result", "id": id, "ok": false, "error": e}),
|
||||
};
|
||||
self.send_json(msg);
|
||||
}
|
||||
|
||||
pub fn chat_delete(&self, channel: u64, message: u64) {
|
||||
self.send_json(json!({"type": "chat_delete", "channel": channel.to_string(),
|
||||
"message_id": message.to_string()}));
|
||||
@@ -330,13 +370,23 @@ impl WorkerClient {
|
||||
/// Ask the brain to answer `user`. With `speak` the answer is spoken under `id` (its audio and
|
||||
/// `tts_done` come like a TTS request's); it ends as failed when it cannot be sent, the brain gives
|
||||
/// no answer, or the worker refuses it.
|
||||
/// `via`: `voice` or `chat` (the brain's history scope and where the answer is stored).
|
||||
/// `via`: `voice`, `chat` or `task` (a scheduled task: read-only tools, never spoken).
|
||||
pub fn reply(&self, id: &str, user: u64, text: &str, via: &str, speak: bool) -> bool {
|
||||
self.reply_in(id, user, text, via, speak, None)
|
||||
}
|
||||
|
||||
/// `reply`, naming the chat channel a chat message was written in (the brain's schedule tool
|
||||
/// delivers there).
|
||||
pub fn reply_in(&self, id: &str, user: u64, text: &str, via: &str, speak: bool, channel: Option<u64>) -> bool {
|
||||
if speak {
|
||||
self.inner.state.lock().unwrap().open_tts.insert(id.to_owned());
|
||||
}
|
||||
let sent = self.send_json(json!({"type": "reply", "id": id, "user": user.to_string(), "text": text,
|
||||
"via": via, "speak": speak}));
|
||||
let mut msg = json!({"type": "reply", "id": id, "user": user.to_string(), "text": text, "via": via,
|
||||
"speak": speak});
|
||||
if let Some(c) = channel {
|
||||
msg["channel"] = json!(c.to_string());
|
||||
}
|
||||
let sent = self.send_json(msg);
|
||||
if !sent && speak {
|
||||
self.end_failed(id);
|
||||
}
|
||||
@@ -580,6 +630,7 @@ fn on_text(inner: &Inner, t: &str) {
|
||||
"partial" => serde_json::from_value(v).ok().map(WorkerEvent::Partial),
|
||||
"final" => serde_json::from_value(v).ok().map(WorkerEvent::Final),
|
||||
"chat_action" => serde_json::from_value(v).ok().map(WorkerEvent::ChatAction),
|
||||
"schedule_action" => serde_json::from_value(v).ok().map(WorkerEvent::ScheduleAction),
|
||||
"llm_idle" => {
|
||||
if let Some(id) = v["id"].as_u64() {
|
||||
inner.llm_idle.send_if_modified(|got| if id > *got { *got = id; true } else { false });
|
||||
|
||||
Reference in New Issue
Block a user