螢幕電腦上的工作流什麼都能做(以前新增、改名、刪除、畫筆、便利貼、形狀、文字、+ 新增節點都藏起來,只寫「這台是螢幕」);側邊欄窄的時候不再破版。
- 螢幕上的畫布跟大腦一樣能編輯:改的內容照其他設定一樣傳到大腦;執行、停止、等你確認的繼續/停止,送 /api/sync/act 的 workflow 動作請大腦做(remote.rs 的 Cmd::Workflow → wf_do)。日程卡片的「立即執行」也是。
- 大腦收到螢幕改的 workflows 時,runs 和 next_run 用自己的:螢幕上慢一步的那份不會把正在跑的那次蓋掉(mirror_ui 的 brain_set_top)。
- 螢幕收到大腦的工作流時,比對前後(workflow::changes):Bot 在大腦上改的那幾步和便利貼在螢幕上也亮,若是旁邊這個 Bot 剛用了 workflow 工具,畫布開在它的聊天旁邊(wf_remote_changes)。
- 側邊欄:最上面那排放不下六個按鈕(6 × 36 + 5 × 8 點)時,日程、工作流、所有檔案收進「⋯」;左下那排算進按鈕之間的間距,市集的按鈕不再被切掉(這個是 4bdc126 就有的)。
- 截圖多了 ANYBOT_SHOT_SCREEN=1(當成雲端大腦的螢幕)。
已驗證: cargo test 861 過(新:a_screen_edits_workflows_and_sees_a_bots_changes——螢幕改名傳到大腦、大腦的那次執行留著;Bot 在大腦加一步,螢幕上畫布打開、那一步亮);clippy 沒有新的。截圖(螢幕模式、側邊欄 240):最上面「⋯ 任務 搜尋 +」、左下兩個按鈕都在邊內,畫布有畫筆/便利貼/形狀/文字/+ 新增節點、停止、繼續,名稱選單有新建、版本歷史、重新命名、建立副本、刪除,「⋯」裡是日程、工作流、所有檔案。
未驗證: 真的兩台(螢幕+雲端大腦)一起跑:要大腦也更新成這一版,舊的大腦不認得 workflow 這個動作(回「沒有這個動作」)。macOS 視窗左上角的紅黃綠按鈕跟側邊欄最上面那排疊到的問題,截圖模式畫不出來,等排版重做。
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2uBHmbnuWBhNzjbJm
This commit is contained in:
parent
b62cf1d98e
commit
3c78dbf65f
|
|
@ -1941,7 +1941,8 @@ computer_use_screenshot、click、mouse_move、mouse_button(按住/放開)
|
||||||
- 執行:照線從觸發器往下(一張接到好幾張時上面的先、再左邊)。Bot 步驟是那個 Bot 聊天裡的一則「[工作流「名稱」第 k/n 步]…」加上一步的結果,它這一輪最後的回答交給下一步(它正忙就排在後面)。檢查回「通過」才往下。等你確認在畫布上方一條「繼續/停止」,並發通知。一次只跑一個,排程到了自動跑;卡片標完成、進行中、等你確認、失敗;執行紀錄留 20 次。
|
- 執行:照線從觸發器往下(一張接到好幾張時上面的先、再左邊)。Bot 步驟是那個 Bot 聊天裡的一則「[工作流「名稱」第 k/n 步]…」加上一步的結果,它這一輪最後的回答交給下一步(它正忙就排在後面)。檢查回「通過」才往下。等你確認在畫布上方一條「繼續/停止」,並發通知。一次只跑一個,排程到了自動跑;卡片標完成、進行中、等你確認、失敗;執行紀錄留 20 次。
|
||||||
- 版本歷史:停手 20 秒、關畫布、每次執行前、Bot 每次改之前各留一版,最多 30 版,點一版就還原。
|
- 版本歷史:停手 20 秒、關畫布、每次執行前、Bot 每次改之前各留一版,最多 30 版,點一版就還原。
|
||||||
- 在聊天裡做:跟 Bot 用一般的話說要什麼流程(「每天早上 9 點去 Threads 找 5 則熱門育兒討論,整理好先問我,我說可以再傳給我」),Bot 用 `workflow` 工具建立、看、改(加步驟、改內容、刪步驟、連線、貼便利貼、整理排版)、執行、停止、刪除(刪除先問)。你看著那個 Bot 的聊天時,畫布自動開在聊天旁邊(視窗夠寬時),它改到的卡片和便利貼亮一下,跑出畫面就縮到看得到全部;Bot 做的排成一欄,插在中間時後面的往下移,你自己排過的不重排。旁邊的聊天跟著側邊欄選的 Bot 換。
|
- 在聊天裡做:跟 Bot 用一般的話說要什麼流程(「每天早上 9 點去 Threads 找 5 則熱門育兒討論,整理好先問我,我說可以再傳給我」),Bot 用 `workflow` 工具建立、看、改(加步驟、改內容、刪步驟、連線、貼便利貼、整理排版)、執行、停止、刪除(刪除先問)。你看著那個 Bot 的聊天時,畫布自動開在聊天旁邊(視窗夠寬時),它改到的卡片和便利貼亮一下,跑出畫面就縮到看得到全部;Bot 做的排成一欄,插在中間時後面的往下移,你自己排過的不重排。旁邊的聊天跟著側邊欄選的 Bot 換。
|
||||||
- 手機沒有畫布:在聊天裡請 Bot 做、改、跑,它用文字說工作流的樣子;「等你確認」的通知會到手機,按「繼續」要在電腦上。螢幕電腦只能看。
|
- 手機沒有畫布:在聊天裡請 Bot 做、改、跑,它用文字說工作流的樣子;「等你確認」的通知會到手機,按「繼續」要在電腦上。螢幕電腦(看著帳號裡大腦的那台)一樣能新增、修改、刪除、畫和註解,執行、停止、繼續交給大腦做;執行紀錄以大腦的為準。
|
||||||
|
- 側邊欄太窄放不下六個按鈕時,日程、工作流、所有檔案收進最上面那排的「⋯」。
|
||||||
|
|
||||||
### 日程(側邊欄最上面一排的日曆圖示)
|
### 日程(側邊欄最上面一排的日曆圖示)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
- `schedule-views` 看法:右上「日/週/月」,左上「‹ 今天 ›」往前往後、回到今天,旁邊寫「2026年11月」「11月16日 – 22日」「11月21日 星期六」;右上角寫「時間以 Asia/Taipei 為準」(你的時區)。週和月從週一開始,今天那格是強調色的框。
|
- `schedule-views` 看法:右上「日/週/月」,左上「‹ 今天 ›」往前往後、回到今天,旁邊寫「2026年11月」「11月16日 – 22日」「11月21日 星期六」;右上角寫「時間以 Asia/Taipei 為準」(你的時區)。週和月從週一開始,今天那格是強調色的框。
|
||||||
- `schedule-entries` 每一筆:跑過的照它的執行紀錄(✓ 完成、✗ 失敗或中斷、■ 停止、圓點執行中),還沒到的照排程算出來(圓點;暫停的變灰、帶 ‖)。週:每天一欄,每筆是時間、Bot 的頭像,下面是名稱。月:每天最多三筆「時間 名稱」,多的寫「還有 N 個」;點那一天換成那天的日看法。日:照時間一列列,寫「名稱 · 時間 · 怎麼重複 · 啟用中/已暫停/完成」。事件觸發的例行任務沒有預定的時間,只看得到跑過的。時間到了但 Bot 正忙的,照原來的時間留著(圓點),等它空下來跑。每小時跑的排滿月看法的六週;每 5 分鐘跑的大約只列得下四天。
|
- `schedule-entries` 每一筆:跑過的照它的執行紀錄(✓ 完成、✗ 失敗或中斷、■ 停止、圓點執行中),還沒到的照排程算出來(圓點;暫停的變灰、帶 ‖)。週:每天一欄,每筆是時間、Bot 的頭像,下面是名稱。月:每天最多三筆「時間 名稱」,多的寫「還有 N 個」;點那一天換成那天的日看法。日:照時間一列列,寫「名稱 · 時間 · 怎麼重複 · 啟用中/已暫停/完成」。事件觸發的例行任務沒有預定的時間,只看得到跑過的。時間到了但 Bot 正忙的,照原來的時間留著(圓點),等它空下來跑。每小時跑的排滿月看法的六週;每 5 分鐘跑的大約只列得下四天。
|
||||||
- `schedule-coming` 即將執行:所有 Bot 接下來兩週內最先要跑的六筆(暫停的不算),每筆「名稱 · 明天 08:30 · 每天 08:30」和 Bot 的頭像;沒有時說怎麼設一個。
|
- `schedule-coming` 即將執行:所有 Bot 接下來兩週內最先要跑的六筆(暫停的不算),每筆「名稱 · 明天 08:30 · 每天 08:30」和 Bot 的頭像;沒有時說怎麼設一個。
|
||||||
- `schedule-card` 點任何一筆打開卡片:哪個 Bot、那一次的時間和狀態、怎麼重複、最近一次怎麼樣、要它做什麼;按鈕「打開聊天」「立即執行」「暫停/繼續」。工作流的是「打開工作流」「立即執行」(螢幕電腦上沒有「立即執行」:工作流在大腦上跑)。
|
- `schedule-card` 點任何一筆打開卡片:哪個 Bot、那一次的時間和狀態、怎麼重複、最近一次怎麼樣、要它做什麼;按鈕「打開聊天」「立即執行」「暫停/繼續」。工作流的是「打開工作流」「立即執行」(在螢幕電腦上按,交給大腦執行)。
|
||||||
- `schedule-new` 「+ 新增例行任務」:回到那個 Bot 的聊天,輸入框先放好「每天早上 9 點幫我」,接著說要做什麼;Bot 用 `create_routine` 設好,日程上就出現。
|
- `schedule-new` 「+ 新增例行任務」:回到那個 Bot 的聊天,輸入框先放好「每天早上 9 點幫我」,接著說要做什麼;Bot 用 `create_routine` 設好,日程上就出現。
|
||||||
|
|
||||||
## 使用者怎麼到
|
## 使用者怎麼到
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,6 @@
|
||||||
- 改正在跑的工作流:那次照開始時的步驟走,刪掉的步驟輪到時會停下來(新加的步驟不會用到刪掉的編號)。
|
- 改正在跑的工作流:那次照開始時的步驟走,刪掉的步驟輪到時會停下來(新加的步驟不會用到刪掉的編號)。
|
||||||
- AnyBot 關掉時正在跑的那次:再開時標成失敗「AnyBot 在執行中被關掉,這一步可能做到一半」;停在等你確認的那次留著,等著交付的那次重開後照樣交付。還在等你確認時排程到了,不會再開一次。
|
- AnyBot 關掉時正在跑的那次:再開時標成失敗「AnyBot 在執行中被關掉,這一步可能做到一半」;停在等你確認的那次留著,等著交付的那次重開後照樣交付。還在等你確認時排程到了,不會再開一次。
|
||||||
- 步驟的 Bot 在做的時候被刪掉:那次停下來,寫「這一步的 Bot 已經不在了」。
|
- 步驟的 Bot 在做的時候被刪掉:那次停下來,寫「這一步的 Bot 已經不在了」。
|
||||||
- 螢幕電腦只能看:工作流在大腦上改和跑。
|
- 螢幕電腦(看著帳號裡大腦的那台)一樣可以新增、修改、刪除、畫和註解,改的內容傳到大腦;執行、停止、繼續交給大腦做(大腦要是一樣新的版本)。執行紀錄永遠是大腦的:螢幕上慢一步的那份不會蓋掉正在跑的。Bot 在大腦上改了,螢幕上也會亮、會開在那個 Bot 的聊天旁邊。
|
||||||
- (驗證)有真資料的桌面截圖前 500 格左右是啟動畫面:`ANYBOT_SHOT_FRAMES` 至少 520。
|
- (驗證)有真資料的桌面截圖前 500 格左右是啟動畫面:`ANYBOT_SHOT_FRAMES` 至少 520。
|
||||||
- (驗證)假模型的回答不是「通過」開頭:跑到檢查之前先 `$CTL model-reply '步・檢查' '通過'`。
|
- (驗證)假模型的回答不是「通過」開頭:跑到檢查之前先 `$CTL model-reply '步・檢查' '通過'`。
|
||||||
|
|
|
||||||
12
src/app.rs
12
src/app.rs
|
|
@ -1381,6 +1381,18 @@ impl App {
|
||||||
let ago = std::time::Duration::from_secs(h.trim().parse::<u64>().unwrap_or(0) * 3600);
|
let ago = std::time::Duration::from_secs(h.trim().parse::<u64>().unwrap_or(0) * 3600);
|
||||||
app.newer_build = std::time::SystemTime::now().checked_sub(ago);
|
app.newer_build = std::time::SystemTime::now().checked_sub(ago);
|
||||||
}
|
}
|
||||||
|
// ANYBOT_SHOT_SCREEN=1: this window a screen of 雲端大腦 (an account server that
|
||||||
|
// refuses at once; the screen's copy in a temp folder).
|
||||||
|
if std::env::var("ANYBOT_SHOT_SCREEN").is_ok_and(|v| v == "1") {
|
||||||
|
let r = &mut app.state.remote;
|
||||||
|
r.relay_url = "https://127.0.0.1:9/demo".into();
|
||||||
|
r.host_token = "demo".into();
|
||||||
|
r.brain_id = "brain-1".into();
|
||||||
|
r.brain_name = "雲端".into();
|
||||||
|
app.mir.dir = std::env::temp_dir().join("anybot-shot-screen");
|
||||||
|
app.mir.on = true;
|
||||||
|
app.mir.online = true;
|
||||||
|
}
|
||||||
// ANYBOT_SHOT_SIDEBAR=<points>: the sidebar that wide.
|
// ANYBOT_SHOT_SIDEBAR=<points>: the sidebar that wide.
|
||||||
if let Some(w) = std::env::var("ANYBOT_SHOT_SIDEBAR").ok().and_then(|v| v.parse::<f32>().ok()) {
|
if let Some(w) = std::env::var("ANYBOT_SHOT_SIDEBAR").ok().and_then(|v| v.parse::<f32>().ok()) {
|
||||||
app.state.sidebar_width = w.clamp(SIDEBAR_MIN_WIDTH, SIDEBAR_MAX_WIDTH);
|
app.state.sidebar_width = w.clamp(SIDEBAR_MIN_WIDTH, SIDEBAR_MAX_WIDTH);
|
||||||
|
|
|
||||||
|
|
@ -1197,6 +1197,25 @@ impl App {
|
||||||
if key.starts_with("next_") {
|
if key.starts_with("next_") {
|
||||||
value = json!(value.as_u64().unwrap_or(0).max(top[key].as_u64().unwrap_or(0)));
|
value = json!(value.as_u64().unwrap_or(0).max(top[key].as_u64().unwrap_or(0)));
|
||||||
}
|
}
|
||||||
|
// 工作流: a screen edits the canvas; the runs are the brain's (a screen's copy may be
|
||||||
|
// behind a run that went on meanwhile — it never overwrites one).
|
||||||
|
if key == "workflows" {
|
||||||
|
for w in value.as_array_mut().into_iter().flatten() {
|
||||||
|
let mine = top[key].as_array().and_then(|a| a.iter().find(|x| x["id"] == w["id"])).cloned();
|
||||||
|
if let Some(o) = w.as_object_mut() {
|
||||||
|
for k in ["runs", "next_run"] {
|
||||||
|
match mine.as_ref().map(|m| m[k].clone()).filter(|v| !v.is_null()) {
|
||||||
|
Some(v) => {
|
||||||
|
o.insert(k.into(), v);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
o.remove(k);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
top[key] = value;
|
top[key] = value;
|
||||||
let ok = match serde_json::from_value::<State>(top) {
|
let ok = match serde_json::from_value::<State>(top) {
|
||||||
Ok(mut st) => {
|
Ok(mut st) => {
|
||||||
|
|
@ -1394,6 +1413,8 @@ impl App {
|
||||||
}
|
}
|
||||||
self.state = st;
|
self.state = st;
|
||||||
self.keep_local_fields(&local);
|
self.keep_local_fields(&local);
|
||||||
|
// (What a bot changed on a workflow lights up here too.)
|
||||||
|
self.wf_remote_changes(&local.workflows);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
@ -2648,6 +2669,44 @@ mod tests {
|
||||||
assert!(r.is_err_and(|(_, e)| !e.contains("讀不到")), "the file here wasn't read again");
|
assert!(r.is_err_and(|(_, e)| !e.contains("讀不到")), "the file here wasn't read again");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 工作流 on a screen: its canvas edits reach the brain, never its runs (a run that went on at
|
||||||
|
/// the brain meanwhile stays as it is); a bot's change at the brain lights up on the screen,
|
||||||
|
/// beside that bot's chat.
|
||||||
|
#[test]
|
||||||
|
fn a_screen_edits_workflows_and_sees_a_bots_changes() {
|
||||||
|
let ctx = egui::Context::default();
|
||||||
|
let dir = fresh_dir("screen-workflow");
|
||||||
|
let (mut brain, mut screen) = brain_and_screen(&ctx, &dir);
|
||||||
|
let bot = brain.state.bots[0].id;
|
||||||
|
let mut w = crate::workflow::Workflow::new(1, "早報", 0);
|
||||||
|
w.nodes.push(crate::workflow::Node { id: 2, kind: crate::workflow::NodeKind::Step { bot, prompt: "查".into() }, x: 0.0, y: 190.0 });
|
||||||
|
assert!(w.connect(1, 2));
|
||||||
|
brain.state.workflows = vec![w];
|
||||||
|
let base = serde_json::to_value(&brain.state).unwrap();
|
||||||
|
// A run starts at the brain; the screen, behind, renames the workflow.
|
||||||
|
brain.state.workflows[0].start_run("手動", 5);
|
||||||
|
let mut cur = base.clone();
|
||||||
|
cur["workflows"][0]["name"] = json!("晚報");
|
||||||
|
let ops = diff_ops(&base, &cur);
|
||||||
|
assert!(!ops.is_empty());
|
||||||
|
let r = brain.brain_edit(&json!({"ops": ops, "client": "screen-1", "seq": 1}));
|
||||||
|
assert_eq!(r["applied"], json!(ops.len()), "{r}");
|
||||||
|
assert_eq!((brain.state.workflows[0].name.as_str(), brain.state.workflows[0].runs.len()), ("晚報", 1), "the name changes, the run stays");
|
||||||
|
// At the brain a bot adds a step from its chat; the screen takes the brain's workflows in.
|
||||||
|
let old = brain.state.workflows.clone();
|
||||||
|
let mut next = old.clone();
|
||||||
|
next[0].nodes.push(crate::workflow::Node { id: 3, kind: crate::workflow::NodeKind::Notify { text: "好了".into() }, x: 0.0, y: 380.0 });
|
||||||
|
next[0].connect(2, 3);
|
||||||
|
screen.state.selected = bot;
|
||||||
|
screen.state.workflows = next;
|
||||||
|
if let Some(b) = screen.state.bot_mut(bot) {
|
||||||
|
b.messages.push(Message { tool_calls: vec![crate::model::ToolCall { id: "c".into(), name: crate::workflow::TOOL.into(), args: "{}".into(), status: crate::model::ToolStatus::Done }], ..Message::assistant("", "m") });
|
||||||
|
}
|
||||||
|
screen.wf_remote_changes(&old);
|
||||||
|
assert!(screen.wf.open && screen.wf.current == 1, "the canvas opens beside that chat");
|
||||||
|
assert_eq!(screen.wf.flash.as_ref().map(|f| f.1.clone()), Some(vec![3]), "what the bot added lights up");
|
||||||
|
}
|
||||||
|
|
||||||
/// 沒網路照樣能改設定: an edit made while the brain is out of reach waits in the queue; the
|
/// 沒網路照樣能改設定: an edit made while the brain is out of reach waits in the queue; the
|
||||||
/// brain's newer settings, when they come, keep it on top (nothing the brain changed
|
/// brain's newer settings, when they come, keep it on top (nothing the brain changed
|
||||||
/// meanwhile is undone), and once it is sent the brain has both.
|
/// meanwhile is undone), and once it is sent the brain has both.
|
||||||
|
|
|
||||||
|
|
@ -717,6 +717,11 @@ impl App {
|
||||||
self.mark();
|
self.mark();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 工作流 from a screen: the brain runs them.
|
||||||
|
Cmd::Workflow { wf, act } => {
|
||||||
|
self.wf_do(ctx, wf, &act);
|
||||||
|
self.mark();
|
||||||
|
}
|
||||||
Cmd::NewThread { bot } => {
|
Cmd::NewThread { bot } => {
|
||||||
self.goal_drop(bot);
|
self.goal_drop(bot);
|
||||||
self.stop(bot);
|
self.stop(bot);
|
||||||
|
|
|
||||||
|
|
@ -454,9 +454,8 @@ impl App {
|
||||||
} else if ui.add(primary_button("打開聊天", p)).clicked() {
|
} else if ui.add(primary_button("打開聊天", p)).clicked() {
|
||||||
act = Some("chat");
|
act = Some("chat");
|
||||||
}
|
}
|
||||||
// (A screen doesn't start a workflow itself: the brain runs them. A routine's
|
// (On a screen both are asked of the brain, which runs them.)
|
||||||
// run is passed on to the brain.)
|
if ui.add(secondary_button("立即執行")).clicked() {
|
||||||
if !(workflow.is_some() && self.mir.on) && ui.add(secondary_button("立即執行")).clicked() {
|
|
||||||
act = Some("run");
|
act = Some("run");
|
||||||
}
|
}
|
||||||
if let Some(r) = &routine {
|
if let Some(r) = &routine {
|
||||||
|
|
@ -487,9 +486,7 @@ impl App {
|
||||||
self.wf.fitted = 0;
|
self.wf.fitted = 0;
|
||||||
self.wf_open();
|
self.wf_open();
|
||||||
}
|
}
|
||||||
(What::Workflow { id }, "run") if !self.mir.on => {
|
(What::Workflow { id }, "run") => self.wf_do(ctx, id, "run"),
|
||||||
self.wf_start(ctx, id, "手動");
|
|
||||||
}
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
|
|
|
||||||
|
|
@ -266,7 +266,9 @@ impl App {
|
||||||
let name = self.person_name();
|
let name = self.person_name();
|
||||||
let initials: String = name.split_whitespace().filter_map(|w| w.chars().next()).take(2).collect::<String>().to_uppercase();
|
let initials: String = name.split_whitespace().filter_map(|w| w.chars().next()).take(2).collect::<String>().to_uppercase();
|
||||||
let initials = if initials.is_empty() { name.chars().take(1).collect() } else { initials };
|
let initials = if initials.is_empty() { name.chars().take(1).collect() } else { initials };
|
||||||
let w = ui.available_width() - 88.0;
|
// (Room for the two buttons and the gaps between: the last button was pushed past
|
||||||
|
// the sidebar's edge in a narrow sidebar.)
|
||||||
|
let w = ui.available_width() - 2.0 * 36.0 - 2.0 * ui.spacing().item_spacing.x - 2.0;
|
||||||
let (rect, r) = ui.allocate_exact_size(vec2(w, 40.0), egui::Sense::click());
|
let (rect, r) = ui.allocate_exact_size(vec2(w, 40.0), egui::Sense::click());
|
||||||
if r.hovered() {
|
if r.hovered() {
|
||||||
ui.painter().rect_filled(rect, R_M, p.hover);
|
ui.painter().rect_filled(rect, R_M, p.hover);
|
||||||
|
|
@ -314,6 +316,9 @@ impl App {
|
||||||
ui.set_height(36.0);
|
ui.set_height(36.0);
|
||||||
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
|
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
|
||||||
ui.spacing_mut().item_spacing.x = 8.0;
|
ui.spacing_mut().item_spacing.x = 8.0;
|
||||||
|
// (Six buttons need 6 × 36 + 5 × 8 points: in a narrower sidebar 日程, 工作流 and
|
||||||
|
// 所有檔案 fold into one ⋯ — none is cut off at the edge.)
|
||||||
|
let all_fit = ui.available_width() >= 6.0 * 36.0 + 5.0 * 8.0;
|
||||||
let plus = pill_icon(ui, crate::icons::Icon::Plus, p).on_hover_text(t("新增"));
|
let plus = pill_icon(ui, crate::icons::Icon::Plus, p).on_hover_text(t("新增"));
|
||||||
egui::Popup::menu(&plus).show(|ui| {
|
egui::Popup::menu(&plus).show(|ui| {
|
||||||
ui.set_min_width(menu_ui::MENU_W);
|
ui.set_min_width(menu_ui::MENU_W);
|
||||||
|
|
@ -345,6 +350,28 @@ impl App {
|
||||||
}
|
}
|
||||||
// 任務: every bot's tasks and how each stands (tasks_ui.rs).
|
// 任務: every bot's tasks and how each stands (tasks_ui.rs).
|
||||||
self.tasks_button(ui);
|
self.tasks_button(ui);
|
||||||
|
if !all_fit {
|
||||||
|
let more = pill_icon(ui, crate::icons::Icon::More, p).on_hover_text(t("日程、工作流、所有檔案"));
|
||||||
|
egui::Popup::menu(&more).show(|ui| {
|
||||||
|
ui.set_min_width(menu_ui::MENU_W);
|
||||||
|
ui.spacing_mut().item_spacing.y = 0.0;
|
||||||
|
if menu_ui::item(ui, p, crate::icons::Icon::Calendar, "日程").clicked() {
|
||||||
|
self.sched_open();
|
||||||
|
ui.close();
|
||||||
|
}
|
||||||
|
if menu_ui::item(ui, p, crate::icons::Icon::Workflow, "工作流").clicked() {
|
||||||
|
self.sched.open = false;
|
||||||
|
self.wf_open();
|
||||||
|
ui.close();
|
||||||
|
}
|
||||||
|
if menu_ui::item(ui, p, crate::icons::Icon::Folder, "所有檔案").clicked() {
|
||||||
|
self.lib.open = true;
|
||||||
|
self.lib.at = None;
|
||||||
|
ui.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 日程: what every bot is set to do, on a calendar (schedule_ui.rs); again closes it.
|
// 日程: what every bot is set to do, on a calendar (schedule_ui.rs); again closes it.
|
||||||
if pill_icon(ui, crate::icons::Icon::Calendar, p).on_hover_text(t("日程")).clicked() {
|
if pill_icon(ui, crate::icons::Icon::Calendar, p).on_hover_text(t("日程")).clicked() {
|
||||||
if self.sched.open {
|
if self.sched.open {
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,42 @@ impl App {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 執行 (run), 停止 (stop), 等你確認的繼續 (go) or 停止 (halt), from this window: done here on
|
||||||
|
/// the brain; a screen asks the brain, which runs them (its answer comes back with the state).
|
||||||
|
pub(super) fn wf_do(&mut self, ctx: &egui::Context, wf: u64, what: &str) {
|
||||||
|
if self.mir.on {
|
||||||
|
self.mirror_act(serde_json::json!({"bot": 0, "action": "workflow", "wf": wf, "do": what}));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
match what {
|
||||||
|
"run" => {
|
||||||
|
self.wf_start(ctx, wf, "手動");
|
||||||
|
}
|
||||||
|
"stop" => self.wf_stop(wf),
|
||||||
|
"go" => self.wf_confirm(ctx, wf, true),
|
||||||
|
"halt" => self.wf_confirm(ctx, wf, false),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A screen took in the brain's workflows: what a bot changed there (not this window's own
|
||||||
|
/// edits coming back) lights up, and opens beside the chat of the bot that changed it, as on
|
||||||
|
/// the brain itself.
|
||||||
|
pub(super) fn wf_remote_changes(&mut self, old: &[crate::workflow::Workflow]) {
|
||||||
|
let changed = crate::workflow::changes(old, &self.state.workflows);
|
||||||
|
if changed.is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let sel = self.state.selected;
|
||||||
|
// (The chat on show is the bot's that changed it when its latest turn used the tool.)
|
||||||
|
let by_selected = self.state.bot(sel).is_some_and(|b| b.messages.iter().rev().take(6).any(|m| m.tool_calls.iter().any(|c| c.name == crate::workflow::TOOL)));
|
||||||
|
for (wf, touched) in changed {
|
||||||
|
if by_selected || (self.wf.open && self.wf.current == wf) {
|
||||||
|
self.wf_show_change(sel, wf, touched);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Stop this workflow's run (a bot working on its step is stopped too).
|
/// Stop this workflow's run (a bot working on its step is stopped too).
|
||||||
pub(super) fn wf_stop(&mut self, wf: u64) {
|
pub(super) fn wf_stop(&mut self, wf: u64) {
|
||||||
let now = crate::routines::now();
|
let now = crate::routines::now();
|
||||||
|
|
|
||||||
|
|
@ -283,7 +283,9 @@ impl App {
|
||||||
if self.wf.changed_since.is_some_and(|t| t.elapsed().as_secs() >= KEEP_AFTER_SECS) {
|
if self.wf.changed_since.is_some_and(|t| t.elapsed().as_secs() >= KEEP_AFTER_SECS) {
|
||||||
self.wf_keep_version();
|
self.wf_keep_version();
|
||||||
}
|
}
|
||||||
let screen = self.mir.on;
|
// (A screen edits like the brain: the edits reach it like every other setting, and
|
||||||
|
// 執行/停止/繼續 are asked of it — wf_do.)
|
||||||
|
let screen = false;
|
||||||
let full = ui.available_rect_before_wrap();
|
let full = ui.available_rect_before_wrap();
|
||||||
let top = Rect::from_min_size(full.min, vec2(full.width(), 52.0));
|
let top = Rect::from_min_size(full.min, vec2(full.width(), 52.0));
|
||||||
let canvas = Rect::from_min_max(egui::pos2(full.min.x, top.max.y), full.max);
|
let canvas = Rect::from_min_max(egui::pos2(full.min.x, top.max.y), full.max);
|
||||||
|
|
@ -320,15 +322,15 @@ impl App {
|
||||||
match live {
|
match live {
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
if ui.add(danger_button("■ 停止", p)).clicked() {
|
if ui.add(danger_button("■ 停止", p)).clicked() {
|
||||||
let id = self.wf.current;
|
let (ctx, id) = (ui.ctx().clone(), self.wf.current);
|
||||||
self.wf_stop(id);
|
self.wf_do(&ctx, id, "stop");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
if ui.add(primary_button("▷ 執行工作流", p)).clicked() {
|
if ui.add(primary_button("▷ 執行工作流", p)).clicked() {
|
||||||
let (ctx, id) = (ui.ctx().clone(), self.wf.current);
|
let (ctx, id) = (ui.ctx().clone(), self.wf.current);
|
||||||
self.wf_keep_version();
|
self.wf_keep_version();
|
||||||
self.wf_start(&ctx, id, "手動");
|
self.wf_do(&ctx, id, "run");
|
||||||
self.wf.runs_open = true;
|
self.wf.runs_open = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -385,18 +387,13 @@ impl App {
|
||||||
ui.close();
|
ui.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !self.mir.on && menu_ui::item(ui, p, Icon::Plus, "新建工作流").clicked() {
|
if menu_ui::item(ui, p, Icon::Plus, "新建工作流").clicked() {
|
||||||
self.wf_keep_version();
|
self.wf_keep_version();
|
||||||
self.wf_new();
|
self.wf_new();
|
||||||
ui.close();
|
ui.close();
|
||||||
}
|
}
|
||||||
menu_ui::sep(ui, p);
|
menu_ui::sep(ui, p);
|
||||||
let Some(i) = self.wf_index() else { return };
|
let Some(i) = self.wf_index() else { return };
|
||||||
if self.mir.on {
|
|
||||||
// (A screen shows the brain's: made, renamed, restored and deleted there.)
|
|
||||||
ui.label(RichText::new(t("這台是螢幕:在大腦上新建、改名、還原或刪除")).size(FONT_XS).color(p.text3));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let versions: Vec<(usize, String, usize)> = self.state.workflows[i]
|
let versions: Vec<(usize, String, usize)> = self.state.workflows[i]
|
||||||
.versions
|
.versions
|
||||||
.iter()
|
.iter()
|
||||||
|
|
@ -481,7 +478,7 @@ impl App {
|
||||||
if yes {
|
if yes {
|
||||||
let id = self.wf.current;
|
let id = self.wf.current;
|
||||||
if self.state.workflows.iter().any(|w| w.id == id && w.live_run().is_some()) {
|
if self.state.workflows.iter().any(|w| w.id == id && w.live_run().is_some()) {
|
||||||
self.wf_stop(id);
|
self.wf_do(ctx, id, "stop");
|
||||||
}
|
}
|
||||||
self.state.workflows.retain(|w| w.id != id);
|
self.state.workflows.retain(|w| w.id != id);
|
||||||
self.wf.current = self.state.workflows.first().map(|w| w.id).unwrap_or(0);
|
self.wf.current = self.state.workflows.first().map(|w| w.id).unwrap_or(0);
|
||||||
|
|
@ -763,7 +760,7 @@ impl App {
|
||||||
}
|
}
|
||||||
if let Some(id) = run_now {
|
if let Some(id) = run_now {
|
||||||
self.wf_keep_version();
|
self.wf_keep_version();
|
||||||
self.wf_start(&ctx, id, "手動");
|
self.wf_do(&ctx, id, "run");
|
||||||
self.wf.runs_open = true;
|
self.wf.runs_open = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -826,10 +823,10 @@ impl App {
|
||||||
if !screen {
|
if !screen {
|
||||||
let id = self.wf.current;
|
let id = self.wf.current;
|
||||||
if ui.add(secondary_button("停止")).clicked() {
|
if ui.add(secondary_button("停止")).clicked() {
|
||||||
self.wf_confirm(&ctx, id, false);
|
self.wf_do(&ctx, id, "halt");
|
||||||
}
|
}
|
||||||
if ui.add(primary_button("繼續", p)).clicked() {
|
if ui.add(primary_button("繼續", p)).clicked() {
|
||||||
self.wf_confirm(&ctx, id, true);
|
self.wf_do(&ctx, id, "go");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ui.with_layout(Layout::left_to_right(Align::Center), |ui| {
|
ui.with_layout(Layout::left_to_right(Align::Center), |ui| {
|
||||||
|
|
@ -1460,7 +1457,7 @@ impl App {
|
||||||
let ctx = ui.ctx().clone();
|
let ctx = ui.ctx().clone();
|
||||||
let wf = self.wf.current;
|
let wf = self.wf.current;
|
||||||
self.wf_keep_version();
|
self.wf_keep_version();
|
||||||
self.wf_start(&ctx, wf, "手動");
|
self.wf_do(&ctx, wf, "run");
|
||||||
self.wf.runs_open = true;
|
self.wf.runs_open = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -228,6 +228,8 @@ pub enum Cmd {
|
||||||
Clear { bot: u64 },
|
Clear { bot: u64 },
|
||||||
/// 立即執行例行任務 from a screen of this brain.
|
/// 立即執行例行任務 from a screen of this brain.
|
||||||
RunRoutine { bot: u64, routine: u64 },
|
RunRoutine { bot: u64, routine: u64 },
|
||||||
|
/// 工作流 from a screen of this brain: 執行 (run), 停止 (stop), 等你確認的繼續 (go) or 停止 (halt).
|
||||||
|
Workflow { wf: u64, act: String },
|
||||||
/// 會議錄音 from a screen (uploaded here first): turn it into text, then hand it to the bot.
|
/// 會議錄音 from a screen (uploaded here first): turn it into text, then hand it to the bot.
|
||||||
Meeting { bot: u64, path: String, lang: String },
|
Meeting { bot: u64, path: String, lang: String },
|
||||||
/// A new phone signed in (to remember), or one was signed out.
|
/// A new phone signed in (to remember), or one was signed out.
|
||||||
|
|
@ -1147,6 +1149,7 @@ pub fn handle(req: Req, via_relay: bool) -> Resp {
|
||||||
"restore" => Cmd::RestoreThread { bot, index: b["index"].as_u64().unwrap_or(0) as usize },
|
"restore" => Cmd::RestoreThread { bot, index: b["index"].as_u64().unwrap_or(0) as usize },
|
||||||
"clear" => Cmd::Clear { bot },
|
"clear" => Cmd::Clear { bot },
|
||||||
"run_routine" => Cmd::RunRoutine { bot, routine: b["routine"].as_u64().unwrap_or(0) },
|
"run_routine" => Cmd::RunRoutine { bot, routine: b["routine"].as_u64().unwrap_or(0) },
|
||||||
|
"workflow" => Cmd::Workflow { wf: b["wf"].as_u64().unwrap_or(0), act: b["do"].as_str().unwrap_or("").to_string() },
|
||||||
"meeting" => Cmd::Meeting { bot, path: b["path"].as_str().unwrap_or("").to_string(), lang: b["lang"].as_str().unwrap_or("").to_string() },
|
"meeting" => Cmd::Meeting { bot, path: b["path"].as_str().unwrap_or("").to_string(), lang: b["lang"].as_str().unwrap_or("").to_string() },
|
||||||
_ => return Resp::error(404, "沒有這個動作"),
|
_ => return Resp::error(404, "沒有這個動作"),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -857,6 +857,28 @@ fn list_line(w: &Workflow, tz: &str) -> String {
|
||||||
format!("#{}「{}」 {} 個步驟 · {when}{next}{last}", w.id, w.name, w.step_count())
|
format!("#{}「{}」 {} 個步驟 · {when}{next}{last}", w.id, w.name, w.step_count())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// What changed from `old` to `new`, workflow by workflow: the steps added or changed (what they
|
||||||
|
/// are or do — not where they sit), and the notes added or reworded. A workflow that is new: all
|
||||||
|
/// of it. Unchanged ones are left out.
|
||||||
|
pub fn changes(old: &[Workflow], new: &[Workflow]) -> Vec<(u64, Vec<u64>)> {
|
||||||
|
let mut out = vec![];
|
||||||
|
for w in new {
|
||||||
|
let before = old.iter().find(|o| o.id == w.id);
|
||||||
|
let touched: Vec<u64> = w
|
||||||
|
.nodes
|
||||||
|
.iter()
|
||||||
|
.filter(|n| before.is_none_or(|o| o.node(n.id).is_none_or(|m| m.kind != n.kind)))
|
||||||
|
.map(|n| n.id)
|
||||||
|
.chain(w.notes.iter().filter(|n| before.is_none_or(|o| o.notes.iter().find(|m| m.id == n.id).is_none_or(|m| m.text != n.text || m.color != n.color))).map(|n| n.id))
|
||||||
|
.collect();
|
||||||
|
let relinked = before.is_some_and(|o| o.edges != w.edges);
|
||||||
|
if !touched.is_empty() || relinked {
|
||||||
|
out.push((w.id, touched));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
/// How a run stands, in words.
|
/// How a run stands, in words.
|
||||||
pub fn describe_run(r: &Run) -> String {
|
pub fn describe_run(r: &Run) -> String {
|
||||||
run_words(r)
|
run_words(r)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue