diff --git a/docs/feature-map/pages.md b/docs/feature-map/pages.md index 0e2017c..118880c 100644 --- a/docs/feature-map/pages.md +++ b/docs/feature-map/pages.md @@ -39,6 +39,7 @@ Bot 把要追蹤、整理、比較的事寫成一頁,之後一直更新同一 ## 陷阱 +- 使用者要的「工作流」「流程」是 AnyBot 的工作流畫布(`workflow`,[workflow](workflow.md)),不是頁面:頁面上的 steps 只是一張清單,不會跑、也不會出現在畫布上。 - 只能改自己做的頁面:帶別人頁面的 id 會被擋下(請它改,或不帶 id 自己做一頁);帶一個找不到的 id 會說找不到頁面,不會另開新的。 - 同一個 Bot 用同樣的標題寫(不分大小寫、不管空白),會換掉那一頁,不是另開一頁。 - content 是整頁內容,不是要加上去的那一段:更新時要給完整的新版本。只改種類、摘要、結論這些時不帶 content,內容就不會被換掉。 diff --git a/docs/feature-map/routines.md b/docs/feature-map/routines.md index 861fa65..f53b48e 100644 --- a/docs/feature-map/routines.md +++ b/docs/feature-map/routines.md @@ -37,6 +37,7 @@ Bot 照排程(每天、每週、每月、只一次)或某件事發生時(P ## 陷阱 +- 要好幾步串起來(好幾個 Bot、中間要你確認、要檢查結果),或使用者說「工作流」「流程」「畫布」:用 `workflow` 做在工作流畫布上([workflow](workflow.md)),不是例行任務;例行任務是一個 Bot 照排程做一件事。 - 沒人在看的一輪(例行任務、事件觸發、訊息管道和團隊成員的訊息)遇到模型忙碌或連不上,最多試 8 次、每次最多等 30 秒(加減兩成,避免大家同一秒再問);有人在看的一輪照舊試 3 次就停,讓你按重試。 - 送出幾則看系統的計數和送出證據,不看 Bot 的回報:Bot 說「完成 5 則」可能只送出 3 則。 - 加這些紀錄之前跑過的,沒有執行紀錄;`list_routines` 會說「查不到」,不是「沒跑過」。 diff --git a/docs/feature-map/workflow.md b/docs/feature-map/workflow.md index da59985..a395ce4 100644 --- a/docs/feature-map/workflow.md +++ b/docs/feature-map/workflow.md @@ -8,7 +8,7 @@ - `workflow-nodes` 卡片:觸發器(手動,或每天、每週…的排程,寫「下次執行」,有「立即執行」)、Bot 步驟(哪個 Bot、要它做什麼)、等你確認(問你的話)、檢查(哪個 Bot、要做到什麼才通過)、交付(結果放進哪個 Bot 的聊天)、通知你(「{結果}」換成上一步結果的第一行)。從卡片底下的點拉到另一張卡就連線;不能連回觸發器、不能繞成一圈。點卡片在右邊改設定;Delete 刪掉選到的卡片或線(觸發器刪不掉)。 - `workflow-draw` 畫和註解:畫筆、便利貼(六種顏色,下面寫誰貼的,雙擊改字)、形狀、文字;點選後右邊換顏色、改文字、刪除。只是給人看,不會執行。 - `workflow-run` 執行:照線從觸發器往下走(一張接到好幾張時,上面的先,再左邊)。Bot 步驟是那個 Bot 聊天裡的一則訊息「[工作流「名稱」第 k/n 步]…」加上上一步的結果,它這一輪最後的回答就是這一步的結果;它正忙就排在後面,等它做完手上那一輪。檢查要回「通過」才往下,否則停下並寫原因。等你確認:畫布上方一條「等你確認:…」,「繼續」/「停止」,並發通知(電腦和手機)。交付把結果放進那個 Bot 的聊天(它正在回答時,等這一輪結束才放);通知你發通知。一次只跑一個;排程到了自動跑。停止時,還排在 Bot 後面的那一步問題直接拿掉,不會停掉 Bot 手上別的事。卡片上標完成、進行中、等你確認、失敗;「執行紀錄」留最近 20 次(誰開始的、每一步的結果、為什麼停)。 -- `workflow-chat` 聊出來:在聊天裡請 Bot 做工作流,它用 `workflow` 工具建立、看、改(加步驟、改內容、刪步驟、連線、貼便利貼、整理排版)、執行、停止、刪除(刪除先問你)。你正看著那個 Bot 的聊天時(只有它),畫布自動開在聊天旁邊,跳到那個工作流,它改到的卡片和便利貼亮一下;跑出畫面就自動縮放到看得到全部。Bot 做的排成一欄,插在中間時後面的往下移;你自己排過的不重排。要刪除時,允許卡片寫的就是會刪的那一個(沒指定時是畫布上開著的)。旁邊的聊天跟著側邊欄選的 Bot 換。 +- `workflow-chat` 聊出來:在聊天裡請 Bot 做工作流,它用 `workflow` 工具建立、看、改(加步驟、改內容、刪步驟、連線、貼便利貼、整理排版)、執行、停止、刪除(刪除先問你)。你正看著那個 Bot 的聊天時(只有它),畫布自動開在聊天旁邊,跳到那個工作流,它改到的卡片和便利貼亮一下;跑出畫面就自動縮放到看得到全部。Bot 做的排成一欄,插在中間時後面的往下移;你自己排過的不重排。要刪除時,允許卡片寫的就是會刪的那一個(沒指定時是畫布上開著的)。旁邊的聊天跟著側邊欄選的 Bot 換。Bot 知道有哪些工作流(說明裡列著),你在畫布旁邊打的每一則都帶著「開著工作流「X」(#1)的畫布」,所以「這個」「畫布上」它知道是哪一個。 - `workflow-versions` 版本歷史:改完停手 20 秒、關掉畫布、每次執行前、Bot 每次改之前,各留一版(一樣的不重複留),最多 30 版;選單 › 版本歷史點一版就還原,還原前先留目前的樣子。 ## 使用者怎麼到 diff --git a/src/app.rs b/src/app.rs index 318df80..d477258 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1673,7 +1673,8 @@ impl App { self.queue_steer(bot_id, text.trim().to_string(), attachments); return; } - let m = person_message(&self.state, bot_id, text.trim(), attachments, picks); + let mut m = person_message(&self.state, bot_id, text.trim(), attachments, picks); + m.seen = self.wf_seen(); if let Some(b) = self.state.bot_mut(bot_id) { b.messages.push(m); } @@ -8067,7 +8068,13 @@ fn system_prompt(b: &Bot, st: &State, computers: &[tools::Target], default_compu let mut app: Vec = Vec::new(); if has(b, "routines") { app.push("- 使用者想定期或在某個時間做事(每天、每週一、每月一號、提醒我…),就用 create_routine 設成例行任務;時間照使用者的時區。查看、修改、暫停、刪除用 list_routines / update_routine / delete_routine。".into()); - app.push("- 使用者要一套多步驟的流程(好幾步、好幾個 Bot、中間要他確認或要檢查結果),或說「工作流」「流程」,就用 workflow 做在畫布上:使用者在聊天旁邊看著畫布跟著你改。先 create 把步驟放好,再一次一個 edit 調整,每次用一句話說改了什麼;改別人做的先 show 看編號;要解釋或提問就貼便利貼(notes)。".into()); + app.push("- 使用者要一套多步驟的流程(好幾步、好幾個 Bot、中間要他確認或要檢查結果),或說「工作流」「流程」「畫布」,就用 workflow 做在 AnyBot 的工作流畫布上:使用者在聊天旁邊看著畫布跟著你改。工作流只能用 workflow 建立和修改,不要用頁面(write_page)或例行任務代替;這一輪的工具清單有 workflow 就做得到,之前在這個聊天說過做不到的,以現在為準。先 create 把步驟放好,再一次一個 edit 調整,每次用一句話說改了什麼;改別人做的先 show 看編號;要解釋或提問就貼便利貼(notes)。".into()); + // (The workflows there are, so 「我的工作流」「畫布上那個」 mean something; the person's + // message says which one is open beside the chat.) + if !st.workflows.is_empty() { + let list: Vec = st.workflows.iter().take(12).map(|w| format!("#{}「{}」({} 個步驟{})", w.id, w.name, w.step_count(), w.schedule().map(|s| format!(",{}", crate::routines::describe(s))).unwrap_or_default())).collect(); + app.push(format!("- 目前的工作流:{}。", list.join("、"))); + } } if has(b, "admin") { app.push("- 換模型或供應商、改名字、建立新 Bot:update_bot / create_bot;看有哪些 Bot:list_bots。".into()); @@ -8781,6 +8788,22 @@ mod tests { assert!(sys.contains("不要說他已經看到,以 send_file 結果後面的〔交付狀態〕為準")); } + /// The instructions name the workflows there are and say the canvas is made with the + /// `workflow` tool — not a page or a routine, even after the chat said it couldn't. + #[test] + fn the_instructions_know_the_workflows() { + let mut st = State::demo(); + let none: Vec = vec![]; + let sys = super::system_prompt(&st.bots[0].clone(), &st, &[], "", &tools::Roles::default(), None, &[], false, true, &none, &[]); + assert!(sys.contains("工作流只能用 workflow 建立和修改") && !sys.contains("目前的工作流"), "none yet: no list"); + let mut w = crate::workflow::Workflow::new(1, "海巡", 0); + w.nodes.push(crate::workflow::Node { id: 2, kind: crate::workflow::NodeKind::Notify { text: "好了".into() }, x: 0.0, y: 190.0 }); + w.connect(1, 2); + st.workflows.push(w); + let sys = super::system_prompt(&st.bots[0].clone(), &st, &[], "", &tools::Roles::default(), None, &[], false, true, &none, &[]); + assert!(sys.contains("目前的工作流:#1「海巡」(1 個步驟)。"), "{sys}"); + } + /// The model's cache holds only when what was sent last turn comes back word for word: the /// instructions don't change with the clock or the message, and each message of the person's /// reads the same (its time and memories come from what it keeps). diff --git a/src/app/mirror_ui.rs b/src/app/mirror_ui.rs index 83a308a..b17720b 100644 --- a/src/app/mirror_ui.rs +++ b/src/app/mirror_ui.rs @@ -475,6 +475,9 @@ pub(super) enum Job { memories: Option>, #[serde(default)] typed: bool, + /// What was open beside the chat when it was typed (a workflow's canvas), for the model. + #[serde(default, skip_serializing_if = "String::is_empty")] + seen: String, /// Where the brain keeps the files already sent up (the first of `atts`, in order): a /// try again sends only the rest — a big file over a slow line was sent whole every time. #[serde(default)] @@ -604,7 +607,7 @@ fn arrived_in(msgs: &[Message], text: &str, atts: &[crate::attach::Attachment], fn try_job(s: &crate::remote::Settings, client: &str, job: &mut Job) -> Result { match job { Job::Edit { seq, ops } => remote::sync_try(s, "/edit", &[], json!({"ops": ops, "client": client, "seq": seq}).to_string().as_bytes(), 20), - Job::Send { bot, id, text, atts, memories, uploaded, .. } => { + Job::Send { bot, id, text, atts, memories, uploaded, seen, .. } => { // (One file that can't go keeps the whole message here — words without their file // would be a different message.) for a in atts.iter().skip(uploaded.len()) { @@ -619,6 +622,9 @@ fn try_job(s: &crate::remote::Settings, client: &str, job: &mut Job) -> Result {} } } - Cmd::Send { bot, text, attachments, from, memories, member } => { + Cmd::Send { bot, text, attachments, from, memories, member, seen } => { if self.state.bot(bot).is_none() { return; } @@ -585,6 +585,9 @@ impl App { } let mut m = super::person_message(&self.state, bot, &text, atts, if member { Some(vec![]) } else { memories }); m.untrusted_sender = member; + if !member { + m.seen = seen; + } if let Some(b) = self.state.bot_mut(bot) { b.messages.push(m); } diff --git a/src/app/voice_ui.rs b/src/app/voice_ui.rs index 18787a7..58ad045 100644 --- a/src/app/voice_ui.rs +++ b/src/app/voice_ui.rs @@ -273,7 +273,7 @@ impl App { a }); match stored { - Ok(a) => self.remote_cmd(ctx, Cmd::Send { bot, text: MEETING_ASK.into(), attachments: vec![a.path], from: String::new(), memories: None, member: false }), + Ok(a) => self.remote_cmd(ctx, Cmd::Send { bot, text: MEETING_ASK.into(), attachments: vec![a.path], from: String::new(), memories: None, member: false, seen: String::new() }), // Said in the chat: the person may be at another screen, or the phone. Err(e) => { if let Some(b) = self.state.bot_mut(bot) { diff --git a/src/app/workflow_run.rs b/src/app/workflow_run.rs index 773f54e..b3cdb45 100644 --- a/src/app/workflow_run.rs +++ b/src/app/workflow_run.rs @@ -734,4 +734,21 @@ mod tests { app.wf_show_change(bot, 99, vec![]); assert_eq!(app.wf.current, 1); } + + /// The person's message says which canvas is open beside the chat (the model reads it after + /// the words); with the canvas closed or the chat put away, nothing. + #[test] + fn a_message_says_which_canvas_is_open() { + let (_ctx, mut app, bot) = app_with(vec![(2, NodeKind::Step { bot: 0, prompt: "查".into() })]); + assert_eq!(app.wf_seen(), ""); + app.state.selected = bot; + app.wf.open = true; + app.wf.current = 1; + let seen = app.wf_seen(); + assert!(seen.starts_with("工作流「早報」(#1,1 個步驟)的畫布") && seen.contains("workflow(id 1)"), "{seen}"); + let m = Message { seen: seen.clone(), at: 0, ..Message::user("幫我加一步") }; + assert!(crate::memory::context_of(&m, "Asia/Taipei").contains(&format!("〔使用者送出這則時開著:{seen}〕"))); + app.wf.chat_hidden = true; + assert_eq!(app.wf_seen(), ""); + } } diff --git a/src/app/workflow_ui.rs b/src/app/workflow_ui.rs index 10d441f..45610ca 100644 --- a/src/app/workflow_ui.rs +++ b/src/app/workflow_ui.rs @@ -184,6 +184,15 @@ impl App { !self.wf.chat_hidden && width >= CHAT_BESIDE_FROM && self.state.bot(self.state.selected).is_some() } + /// What the bot is told the person has open beside its chat when they send (empty: no canvas). + pub(super) fn wf_seen(&self) -> String { + if !self.wf.open || self.wf.chat_hidden { + return String::new(); + } + let Some(w) = self.state.workflows.iter().find(|w| w.id == self.wf.current) else { return String::new() }; + format!("工作流「{}」(#{},{} 個步驟)的畫布,就在你的聊天旁邊——看和改它用 workflow(id {})", w.name, w.id, w.step_count(), w.id) + } + /// A bot changed this workflow from its chat: the person looking at that chat (or at the /// canvas) sees the canvas beside it, on that workflow, with what changed lit up. pub(super) fn wf_show_change(&mut self, bot_id: u64, wf: u64, touched: Vec) { diff --git a/src/memory.rs b/src/memory.rs index c42a64d..b57c14e 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -689,6 +689,12 @@ pub fn context_of(m: &crate::model::Message, timezone: &str) -> String { s.push_str(&format!("〔送出時間:{}({wd}){}〕", t.format("%Y-%m-%d"), t.format("%H:%M"))); } } + if !m.seen.trim().is_empty() { + if !s.is_empty() { + s.push('\n'); + } + s.push_str(&format!("〔使用者送出這則時開著:{}〕", m.seen.trim())); + } if !m.memories.is_empty() { if !s.is_empty() { s.push('\n'); diff --git a/src/model.rs b/src/model.rs index 9ad1bb3..3a072aa 100644 --- a/src/model.rs +++ b/src/model.rs @@ -97,6 +97,10 @@ pub struct Message { /// `memories` is decided (picked by the person, or chosen once): don't choose again. #[serde(default, skip_serializing_if = "std::ops::Not::not")] pub memories_set: bool, + /// What the person had open beside the chat when they sent it (「工作流「早報」(#1)的畫布」): + /// the model reads it after the words, so 「這個」「畫布上」 mean something. + #[serde(default, skip_serializing_if = "String::is_empty")] + pub seen: String, /// 目標 (/goal): the goal this message works toward — the person's 「/goal …」, or AnyBot's /// 「還沒達成」 that starts the next turn. The model reads it after the words (goal::context_line). #[serde(default, skip_serializing_if = "String::is_empty")] diff --git a/src/remote.rs b/src/remote.rs index 63900e5..88adf09 100644 --- a/src/remote.rs +++ b/src/remote.rs @@ -194,7 +194,9 @@ pub enum Cmd { /// `from`: the account computer the person typed it on (empty: the phone, or this one). /// `memories`: what the person picked under the composer (None: they didn't; the brain chooses). /// `member`: sent by a team `member` (not owner/admin). - Send { bot: u64, text: String, attachments: Vec, from: String, memories: Option>, member: bool }, + /// `seen`: what the person had open beside the chat on the computer they typed on (a + /// workflow's canvas), for the model. + Send { bot: u64, text: String, attachments: Vec, from: String, memories: Option>, member: bool, seen: String }, Stop { bot: u64 }, /// (`text`: the answers of a 問題卡.) /// `call`: the key of the card it answers (on_new_approval gives each card one; the phone's @@ -963,7 +965,7 @@ pub fn handle(req: Req, via_relay: bool) -> Resp { if !first_delivery(bot, b["id"].as_str().unwrap_or("")) { return Resp::json(&json!({"ok": true, "again": true})); } - Cmd::Send { bot, text, attachments, from: String::new(), memories: if role == "owner" { picks_of(&b) } else { Some(vec![]) }, member } + Cmd::Send { bot, text, attachments, from: String::new(), memories: if role == "owner" { picks_of(&b) } else { Some(vec![]) }, member, seen: String::new() } } "stop" => Cmd::Stop { bot }, "answer" => Cmd::Answer { bot, answer: b["answer"].as_str().unwrap_or("reject").to_string(), text: b["text"].as_str().unwrap_or("").to_string(), call: b["call"].as_str().unwrap_or("").to_string(), notice: b["from"].as_str() == Some("notice"), screen: false }, @@ -1129,6 +1131,7 @@ pub fn handle(req: Req, via_relay: bool) -> Resp { from: req.header("x-anybot-from").to_string(), memories: picks_of(&b), member: false, + seen: b["seen"].as_str().unwrap_or("").chars().take(300).collect(), }, "stop" => Cmd::Stop { bot }, "answer" => Cmd::Answer { bot, answer: b["answer"].as_str().unwrap_or("reject").to_string(), text: b["text"].as_str().unwrap_or("").to_string(), call: b["call"].as_str().unwrap_or("").to_string(), notice: b["from"].as_str() == Some("notice"), screen: true }, @@ -4350,7 +4353,7 @@ mod tests { assert_eq!(handle(send, false).status, 200); let cmds = hub().take_cmds(); assert!(cmds.iter().any(|c| matches!(c, Cmd::DeviceAdded(d) if d.name == "iPhone"))); - assert!(cmds.contains(&Cmd::Send { bot: 1, text: "你好".into(), attachments: vec![], from: String::new(), memories: Some(vec![]), member: false }) || cmds.contains(&Cmd::Send { bot: 1, text: "你好".into(), attachments: vec![], from: String::new(), memories: None, member: false })); + assert!(cmds.contains(&Cmd::Send { bot: 1, text: "你好".into(), attachments: vec![], from: String::new(), memories: Some(vec![]), member: false, seen: String::new() }) || cmds.contains(&Cmd::Send { bot: 1, text: "你好".into(), attachments: vec![], from: String::new(), memories: None, member: false, seen: String::new() })); // 「/always-approve」 typed on a direct connection is the 直接操作 switch in other words: // refused, nothing queued (it turned 直接操作 and 一律放行 on); status and off go through, // and so does the owner through the account.