手機聊天不再列出思考過程和步驟(跟電腦版一樣):長按回答(電腦的瀏覽器按右鍵)或按 ⋯ 選「顯示步驟(N)」(只有思考時「顯示思考過程」)在那一輪展開,「收起」或「隱藏步驟」收回;工作中只寫它在做什麼,點那一行看這一輪到目前的思考和步驟;沒有字、檔案或卡片可以按的那輪留一行「已完成 N 個步驟」。順手修:Bot 做完時聊天沒再變,手機一直停在「正在…」、最後一則沒有時間和按鈕。驗證用的假模型多 [[think 字]](送思考內容);功能地圖 phone、chat 和 FEATURES 跟著改。

已驗證: cargo test 全過(884);verify-anybot 手機頁面:有思考又有步驟、只有思考、沒有思考的三種回合聊天裡都看不到思考和步驟;長按、⋯、右鍵打開,收起和隱藏步驟收回;工作中點「正在…」看到思考和正在跑的步驟;做完「正在…」自己消失;phone.md「聊天」、chat.md「插話」照寫的步驟從頭跑過。
未驗證: 真的 iPhone 上手指長按(無頭 Chrome 模擬的觸控長按有開出選單);真的模型很長的思考內容。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2uBHmbnuWBhNzjbJm
This commit is contained in:
王性驊 2026-11-22 19:50:28 +08:00
parent c1fdcbd7c1
commit 272340f86f
6 changed files with 96 additions and 47 deletions

View File

@ -136,6 +136,7 @@ $CTL serve # 用完再開回來
- 訊息裡有 `[[call 工具 {JSON}]]` → 叫那個工具,例如 `[[call update_bot {"name":"新名字"}]]`。這一輪沒有那個工具時,回答裡會列出有哪些。
- 最後一則是工具結果 → `FAKE-MODEL 收到工具結果:…`,這一輪結束(不會無限迴圈)。
- 沒帶工具的請求(AnyBot 自己的小工作)→ `FAKE-MODEL 輔助回答`。
- 訊息裡有 `[[think 字]]` → 這一輪每個回應前面先送一段思考(`reasoning_content`「FAKE-MODEL 思考(第 N 步):字」),看思考過程怎麼顯示。
- 指定答案:`$CTL model-reply <比對的字> <回答>` 之後,system 或最後一則使用者訊息含那段字的請求都回那個答案(後加的先比對;`--clear` 全拿掉)。給 AnyBot 自己的子任務用:目標評審(system 開頭「你是驗收員」)、自動審核(「你是動作審核員」)…。回答裡的 `[[call 工具 {JSON}]]` 照叫——不管這一輪有沒有那個工具,用來看 AnyBot 怎麼擋——最後一則是工具結果時改回其餘的字,例如 `$CTL model-reply 你是驗收員 '[[call read_file {"path":"hello.txt"}]] {"verdict":"met","reason":"…"}'`。

View File

@ -7,6 +7,8 @@
// - 使用者訊息裡有 [[call 工具 {JSON}]] → 叫那個工具(這一輪的工具清單裡要有)。
// - 其他 → 文字「FAKE-MODEL 回答:<使用者那句>」。
// - 沒帶工具的請求(AnyBot 自己的小工作:摘要、記憶、標題…)→ 文字「FAKE-MODEL 輔助回答」。
// - 使用者訊息裡有 [[think 字]] → 這一輪每個回應(叫工具、收到結果後的回答)前面先送一段思考
// (reasoning_content「FAKE-MODEL 思考(第幾步):字」),像會思考的模型。
// 指定的回答(--rules 檔,`ctl model-reply` 寫)先看:system 或最後一則使用者訊息含某條規則的
// match,就回那條的 reply——AnyBot 自己的子任務(目標評審、自動審核…)也能照劇本回答。
// reply 裡的 [[call 工具 {JSON}]]:最後一則不是工具結果時照叫(不管這一輪有沒有那個工具,用來看
@ -40,6 +42,7 @@ const textOf = (content) => {
};
const CALL = /\[\[call\s+([A-Za-z0-9_.:-]+)\s*(\{[\s\S]*?\})?\s*\]\]/;
const THINK = /\[\[think\s+([^\]]*)\]\]/;
// The scripted answers (`ctl model-reply`): [{match, reply}], newest last. Read on every request.
function rules() {
@ -47,8 +50,20 @@ function rules() {
try { const r = JSON.parse(fs.readFileSync(RULES, "utf8")); return Array.isArray(r) ? r : []; } catch (_) { return []; }
}
// What to answer: {text} or {call: {name, args}}.
// What to answer: {text} or {call: {name, args}}, and {think} when the person's message asked for it.
function decide(body) {
const d = decide1(body);
const msgs = Array.isArray(body.messages) ? body.messages : [];
const lastUser = [...msgs].reverse().find((m) => m.role === "user");
const t = d.info.kind !== "aux" ? textOf(lastUser?.content).match(THINK) : null;
if (t) {
const round = msgs.slice(msgs.lastIndexOf(lastUser)).filter((m) => m.role === "tool").length + 1;
d.think = `FAKE-MODEL 思考(第 ${round} 步):${t[1].trim()}`;
d.info.think = d.think;
}
return d;
}
function decide1(body) {
const msgs = Array.isArray(body.messages) ? body.messages : [];
const tools = (Array.isArray(body.tools) ? body.tools : []).map((t) => t?.function?.name ?? t?.name).filter(Boolean);
const last = msgs[msgs.length - 1] ?? {};
@ -86,7 +101,7 @@ function decide(body) {
return { info: { ...info, kind: "call" }, call: { name, args } };
}
// (AnyBot 在訊息後面加的〔送出時間…〕〔用繁體中文…〕提示不回聲,答案才固定。)
const said = userText.replace(/〔[^〕]*〕/g, "").replace(/\s+/g, " ").trim();
const said = userText.replace(/〔[^〕]*〕/g, "").replace(new RegExp(THINK.source, "g"), "").replace(/\s+/g, " ").trim();
return { info: { ...info, kind: "turn" }, text: `FAKE-MODEL 回答:${said.slice(0, 200)}` };
}
@ -95,6 +110,7 @@ function answer(res, body, d) {
const id = `call_fake_${++calls}`;
if (body.stream) {
res.writeHead(200, { "Content-Type": "text/event-stream", "Cache-Control": "no-cache", Connection: "close" });
if (d.think) res.write(`data: ${JSON.stringify({ id: "fake", object: "chat.completion.chunk", model: MODEL, choices: [{ index: 0, delta: { role: "assistant", reasoning_content: d.think } }] })}\n\n`);
const delta = d.call
? { tool_calls: [{ index: 0, id, type: "function", function: { name: d.call.name, arguments: JSON.stringify(d.call.args) } }] }
: { role: "assistant", content: d.text };
@ -106,6 +122,7 @@ function answer(res, body, d) {
const message = d.call
? { role: "assistant", content: null, tool_calls: [{ id, type: "function", function: { name: d.call.name, arguments: JSON.stringify(d.call.args) } }] }
: { role: "assistant", content: d.text };
if (d.think) message.reasoning_content = d.think;
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify({ id: "fake", object: "chat.completion", model: MODEL, choices: [{ index: 0, message, finish_reason: d.call ? "tool_calls" : "stop" }] }));
}

View File

@ -2296,8 +2296,8 @@ computer_use_screenshot、click、mouse_move、mouse_button(按住/放開)
- 右上角「+」:建立 Bot、從範本建立、建立群組聊天、新增分區。
- 聊天(電腦版的對話):
- Markdown、程式碼、表格、生活卡片、頁面卡片;日期分隔;群組標出是誰說的;
- 思考過程和工具步驟可以展開,看得到每步的結果;一輪做完會收起來;
- 訊息下方:複製、重新產生;長按(電腦的瀏覽器:右鍵):複製、選取文字、引用回覆、重新產生、重新送出、表情回應;
- 思考過程和工具步驟不放在聊天裡(跟電腦版一樣):長按回答(電腦的瀏覽器:右鍵)或按回答下面的 ⋯,選「顯示步驟(N)」(只有思考時是「顯示思考過程」),就在那一輪展開,看得到每段思考和每步的結果;上面的「收起」或選單的「隱藏步驟」收回去。工作中只在最下面寫它正在做什麼,點那一行看這一輪到目前的思考和步驟;一輪沒有字、檔案或卡片可以按時,留一行「已完成 N 個步驟」打開它;
- 訊息下方:複製、重新產生;長按(電腦的瀏覽器:右鍵):複製、選取文字、引用回覆、重新產生、重新送出、顯示步驟、表情回應;
- 只複製一段:「選取文字」把整則放進下方的面板,手機自己的選取在那裡能用(按住一個字、拖兩端、按「拷貝」;電腦上拖曳再 ⌘C/Ctrl+C),「完成」關掉。聊天裡按住是選單,不是選字。用電腦的瀏覽器時也能直接在聊天裡拖曳選取:在選好的字上按右鍵是瀏覽器自己的選單(複製),在別的地方按右鍵才是訊息選單;按住選好的字也不開選單;連結上按右鍵(Android 長按)是瀏覽器的連結選單。拖曳選取摘要的字不會把它收起或展開,從面板拖到外面的暗處放開也不會關掉面板;
- 允許請求卡片:允許一次、一律允許、拒絕,以及「全部允許,之後直接操作」;Bot 需要你接手時有電腦畫面縮圖;
- 卡片(允許、需要處理、問題卡)只答它畫出來的那一張:回答帶著那張卡的編號,大腦只交給那張卡。那張已經被回答(電腦上、另一支手機上)、被停止、或換成了下一張時,按了不算,聊天裡留一行「手機上的回答沒有用上:那張卡已經不在等了…」;開了很久沒重新整理的舊頁面送不出編號,也不算(「這個頁面太舊…重新整理再回答;還是不行(帳號伺服器還沒更新),就在電腦上回答」)。螢幕電腦上的卡也一樣;比大腦舊的螢幕電腦送不出編號,在它上面按什麼都不算,大腦寫「螢幕電腦上的回答沒有用上:那台電腦的 AnyBot 比這台舊…」,要在那台 設定 › 更新 換新版。支線的卡沒用上時,這一行寫在主線的聊天(支線的卡就顯示在那裡)。「全部允許,之後直接操作」先打開直接操作、直接操作已經放行了那張「可以用電腦嗎」,手機接著送來的回答就不算舊回答、不寫。以前沒帶編號,舊卡上的「允許」「一律允許」會落到後來的那張;

View File

@ -35,7 +35,7 @@
- 基本前提和「手機已登入」(README),開著 Bot 1 的聊天。
- **/ 指令**(covers `chat-commands`):打「/」,再送 /usage、/context。指令:`$CTL phone type '#input' '/' && $CTL phone wait-text '/rewind' --in '#slash' && $CTL phone send '/usage' && $CTL phone wait-text '還沒有用量紀錄' --in '#msgs' && $CTL phone send '/context' && $CTL phone wait-text '到 60% 會自動' --in '#msgs' && $CTL api GET /api/bots/1 --jq '[.messages[] | select(.note) | .text[0:24]]'`。看到:「指令和技能」列出上面那些;兩行 note:「最近 7 天還沒有用量紀錄…」「這個對話…約 N token,fake-model 可讀 128000 token…」。
- **插話**(covers `chat-steer`、`chat-steps`):Bot 跑 15 秒的指令時再傳一句。指令:`$CTL phone send '跑 [[call shell {"command":"sleep 15"}]]' && $CTL wait-api '/api/state?since=0' '.bots[0].busy == true' && $CTL phone send '順便說一聲' && $CTL phone wait-text '已排入:「順便說一聲」' --in '#queued' && $CTL phone wait-text 'FAKE-MODEL 回答:順便說一聲' --in '#msgs' 40 && $CTL model 'select(.user | startswith("順便說一聲")) | {kind, last_role}'`。看到:「已排入:「順便說一聲」…下一步看到」、步驟「執行指令 sleep 15」;跑完同一輪下一步模型讀到那句。
- **插話**(covers `chat-steer`、`chat-steps`):Bot 跑 15 秒的指令時再傳一句。指令:`$CTL phone send '跑 [[call shell {"command":"sleep 15"}]]' && $CTL wait-api '/api/state?since=0' '.bots[0].busy == true' && $CTL phone send '順便說一聲' && $CTL phone wait-text '已排入:「順便說一聲」' --in '#queued' && $CTL phone wait-text 'FAKE-MODEL 回答:順便說一聲' --in '#msgs' 40 && $CTL model 'select(.user | startswith("順便說一聲")) | {kind, last_role}'`。看到:「已排入:「順便說一聲」…下一步看到」、「正在執行指令:sleep 15」;跑完同一輪下一步模型讀到那句。
- **停止**(covers `chat-stop`、`chat-steps`):跑 30 秒的指令,輸入框空著按送出鈕。指令:`$CTL phone send '再跑 [[call shell {"command":"sleep 30"}]]' && $CTL phone wait '#b-send[title="停止"]' && $CTL phone click '#b-send' && $CTL phone wait '#b-send[title="傳送訊息"]' && $CTL api GET /api/bots/1 --jq '[.messages[].tools[]? | select(.name == "shell") | .status]'`。看到:送出鈕變回來、Bot 不再動作;兩個指令步驟 done、denied。
- **重新產生、還原**(covers `chat-actions`):重新產生最後一個回答,再從 ⋯ 還原。指令:`$CTL phone send '重產測試' && $CTL phone wait-text 'FAKE-MODEL 回答:重產測試' --in '#msgs' && $CTL model-reply 重產測試 第二個答案 && $CTL phone click '[data-regen]' && $CTL phone wait-text '第二個答案' --in '#msgs' && $CTL phone click '.meta:has([data-regen]) [data-more]' && $CTL phone click '#sheet-in .opt' --text 還原上一個答案 && $CTL wait-api /api/bots/1 '[.messages[-2:][] | .text] == ["FAKE-MODEL 回答:重產測試", "第二個答案"]' && $CTL model-reply --clear`。看到:新答案換掉舊的;⋯ 有「複製」「選取文字」「引用回覆」「重新產生」「還原上一個答案」和表情;還原後舊在新前。
- **選取一段文字**(covers `chat-select`):按住一則回答 ›「選取文字」,在面板裡拖出「乙丙丁」、按 ⌘C,再按「完成」。指令:`$CTL phone send '選字測試 甲乙丙丁戊' && $CTL phone wait-text 'FAKE-MODEL 回答:選字測試 甲乙丙丁戊' --in '#msgs' && $CTL phone longpress '.m.bot .bub' --text '回答:選字測試' && $CTL phone wait-text 選取文字 --in '#sheet-in' && $CTL phone click '#sheet-in .opt' --text 選取文字 && $CTL phone drag-select '#sheet-in .seltext' 乙丙丁 && $CTL phone selection 乙丙丁 && $CTL phone copy && $CTL phone clipboard 乙丙丁 && $CTL phone click '#sheet-in .opt' --text 完成 && $CTL phone wait-gone '#sheet-in .seltext'`。看到:選單是表情、「複製」「選取文字」「引用回覆」「重新產生」;只有「乙丙丁」反白,⌘C 後剪貼簿是「乙丙丁」;「完成」關掉。

View File

@ -1,15 +1,15 @@
# 手機頁面
手機打開一個網頁就能跟 Bot 聊天、核准、看電腦,長得像 Claude 的手機 App,顏色跟著電腦。怎麼連上(AnyBot 帳號、同一個網路直接連)和推播通知見 [account](account.md)。
手機打開一個網頁就能跟 Bot 聊天、核准、看電腦,長得像 Claude 的手機 App,顏色跟著電腦。怎麼連上和推播通知見 [account](account.md)。
## 子功能
- `phone-pages` 頁面:Bot 清單(分區、工作中/等你)、聊天(附檔、拍照、語音輸入、插話、停止;叫醒 Bot 的訊息上方標是什麼叫醒的;各 Bot 自己的草稿;程式碼塊的「複製」;流程圖畫成圖)、允許請求卡片(「一律允許」「允許一次」、「這輪都准」(智慧模式,一直開著;它是主按鈕)、「拒絕」、「全部允許,之後直接操作」;卡片太高時卡在內面自己捲,輸入框不會被頂出螢幕)、問題卡、「需要處理」與接管、Bot 設定、例行任務(詳細頁有最近幾次執行和送出證據)、頁面、記憶、檔案預覽、Bot 的電腦畫面、設定(一般、個人資料與用量、模型、權限、整合、電腦、保險庫、語音、手機與帳號、更新;開著的設定頁跟著電腦那邊的改變重讀,不用重新整理;直接連線只能收緊、不能放寬,見 [autonomy](autonomy.md))、傳送到其他裝置。智慧模式一直開著,輸入列沒有它的晶片。
- `phone-pages` 頁面:Bot 清單(分區、工作中/等你)、聊天(附檔、拍照、語音輸入、插話、停止;叫醒 Bot 的訊息上方標是什麼叫醒的;各 Bot 自己的草稿;程式碼塊的「複製」;流程圖畫成圖)、允許請求卡片(「一律允許」「允許一次」、「這輪都准」(智慧模式,一直開著,輸入列沒有它的晶片;它是主按鈕)、「拒絕」、「全部允許,之後直接操作」;卡片太高時在卡片裡捲,輸入框不被頂出螢幕)、問題卡、「需要處理」與接管、Bot 設定、例行任務(詳細頁有最近幾次執行和送出證據)、頁面、記憶、檔案預覽、Bot 的電腦畫面、設定(一般、個人資料與用量、模型、權限、整合、電腦、保險庫、語音、手機與帳號、更新;開著的設定頁跟著電腦的改變重讀;直接連線只能收緊、不能放寬,見 [autonomy](autonomy.md))、傳送到其他裝置。
- `phone-cards` 手機上的卡(允許、需要處理、問題卡)只答它畫出來的那一張:那張已經在電腦或另一支手機上回答、被停止、或換成下一張時,按了不算,聊天裡寫「手機上的回答沒有用上…」;開了很久沒重新整理的舊頁面也一樣。螢幕電腦上的卡也是;比大腦舊的螢幕電腦答不了任何卡,要在那台 設定 › 更新 換新版(重新整理沒用)。支線的卡沒用上時,寫在主線的聊天。
- `phone-look` 長相(和電腦版同一份設計規格:字級、間距、圓角都是同一組數字):Bot 的回答不放在泡泡裡,像文件一樣直接排在畫面上,跟介面同一種字(iPhone 是 SF Pro 加蘋方)、16px、行距寬;裡面的表格只有橫向細線、數字欄靠右,提示框([!NOTE] 等)同一種淡底、只有圖示依種類上色,程式碼是淡底圓角塊。標題用半粗體。手機沒有字型選項。
- `phone-colors` 顏色跟電腦版一樣:電腦上 設定 › 一般 › 外觀 的主題(淺色/深色/跟隨系統)、底色、強調色、對比,手機照著穿;手機自己的「外觀」可以選「跟著電腦」(預設)、「跟著手機」、「淺色」、「深色」。狀態列的顏色跟著畫面。舊版的電腦沒送顏色時,手機用內建的「紙」。
- `phone-claude` 像 Claude 的手機 App:上面一條簡單的標題列(Bot 名稱,第二行是它在做什麼或用哪個模型),輸入框是底部一張圓角卡片,回答下面只有時間和複製/重新產生/⋯;按鈕和點的地方至少 44px;清單每列的說明只有一行(太長以 … 結尾);顏色少,強調色只用在連結、選取和新訊息的點。
- `phone-net` 網路慢或斷線都不擋操作:存過這台電腦的資料,打開 App 就用上次的內容進去,不等網路,連上後只補變了的;浮著提示「離線中:顯示的是上次的內容」,拿到就消失。只有第一次(還沒有這台的資料)停在連線畫面:打開 App 時的頭像留在正中間呼吸、外圈漾開,不顯示文字(讀螢幕軟體唸「正在連線」;減少動態時不動),第一份狀態到手才進去。用帳號連、那台不在線上時留在它上次的內容裡,不換到別台。進去之後斷線:浮「連線中斷,正在重新連線…」,自己重試,回到前景或網路恢復時立刻重連。設定、詳細、例行任務先畫手上有的,背景讀新的;要改的先讀到最新的。傳訊息不等網路:按下就出現在聊天裡;連不上標「等連線後送出(點一下拿回來)」,存手機排隊(關 App 也還在),連上後照順序自己送、不限時間,同一則只送一次;點一下連同附件拿回輸入框;連不上時選的附件也排隊。大腦拒收的才標「沒送出,點一下拿回來重送」。從通知打開時按的允許/拒絕等連上才送。只傳有變的部分、文字壓縮;Bot 回答中手機每秒最多更新一次聊天(見 [chat](chat.md) 的開聊天分頁)。頁面和圖示存在手機上:打開直接用,背景問一次換版沒;換了,還在連線畫面就重新載入,已進去就等退到背景、手上沒東西(沒打字、附件、排隊、錄音、選單)才換;重新整理一定先問伺服器。上次的狀態、看過的聊天(合計最多 12 個)、詳細資料、設定、排隊的訊息每台電腦各自存在這個網址的儲存空間,登出(或登入失效)全部清掉。
- `phone-look` 長相(字級、間距、圓角和電腦版同一組數字):回答不放在泡泡裡,像文件一樣直接排在畫面上,跟介面同一種字(iPhone 是 SF Pro 加蘋方)、16px、行距寬;表格只有橫向細線、數字欄靠右,提示框([!NOTE] 等)同一種淡底、只有圖示依種類上色,程式碼是淡底圓角塊。標題用半粗體。手機沒有字型選項。
- `phone-colors` 顏色跟電腦版一樣:電腦上 設定 › 一般 › 外觀 的主題(淺色/深色/跟隨系統)、底色、強調色、對比,手機照著穿;手機自己的「外觀」選「跟著電腦」(預設)、「跟著手機」、「淺色」、「深色」。狀態列的顏色跟著畫面。舊版電腦沒送顏色時用內建的「紙」。
- `phone-claude` 像 Claude 的手機 App:上面一條簡單的標題列(Bot 名稱,第二行是它在做什麼或用哪個模型),輸入框是底部一張圓角卡片,回答下面只有時間和複製/重新產生/⋯;思考和步驟不在聊天裡,長按(右鍵)回答或 ⋯ ›「顯示步驟」才展開(工作中點「正在…」);按鈕和點的地方至少 44px;清單每列的說明只有一行(太長以 … 結尾);顏色少,強調色只用在連結、選取和新訊息的點。
- `phone-net` 網路慢或斷線都不擋操作:存過這台電腦的資料,打開 App 就用上次的內容進去,不等網路,連上後只補變了的;浮著「離線中:顯示的是上次的內容」,拿到就消失。只有第一次(還沒有這台的資料)停在連線畫面:頭像在正中間呼吸、外圈漾開,沒有文字(讀螢幕軟體唸「正在連線」;減少動態時不動),拿到第一份狀態才進去。用帳號連、那台不在線上時留在它上次的內容,不換台。進去後斷線:浮「連線中斷,正在重新連線…」,自己重試,回到前景或網路恢復時立刻重連。設定、詳細、例行任務先畫手上有的,背景讀新的;要改的先讀到最新的。傳訊息不等網路:按下就出現在聊天裡;連不上標「等連線後送出(點一下拿回來)」,存手機排隊(關 App 也還在),連上後照順序自己送、不限時間,同一則只送一次;點一下連同附件拿回輸入框;連不上時選的附件也排隊。大腦拒收的才標「沒送出,點一下拿回來重送」。從通知打開時按的允許/拒絕等連上才送。只傳有變的部分、文字壓縮;Bot 回答中手機每秒最多更新一次聊天([chat](chat.md))。頁面和圖示存在手機上:打開直接用,背景問一次換版沒;換了,還在連線畫面就重新載入,已進去就等退到背景、手上沒東西(沒打字、附件、排隊、錄音、選單)才換;重新整理一定先問伺服器。上次的狀態、看過的聊天(合計最多 12 個)、詳細資料、設定、排隊的訊息每台電腦各自存在這個網址的儲存空間,登出(或登入失效)全部清掉。
- `phone-app` 像 App 一樣:加入主畫面後全螢幕、沒有網址列(避開瀏海和手勢條);首頁會提示「把 AnyBot 裝成 App」(Android 直接安裝,iPhone 教你加入主畫面,可以關掉);換畫面會左右滑動;iPhone 主畫面 App 從左邊緣往右滑回上一頁。
## 使用者怎麼到
@ -26,29 +26,29 @@
- 基本前提和「手機已登入」(README;走的是直接連線,帳號那條見 [account](account.md))。
- **還沒連上就在外面**(covers `phone-net`):打開頁面,等它自己連上。指令:`$CTL phone open --listed && $CTL phone wait-gone '#v-gate.on' 20 && $CTL phone wait '#v-login.on'`。看到:連上之後停在登入,不是 Bot 清單;登入後才進得去。
- **清單和選單**(covers `phone-pages`、`phone-claude`):看首頁,打開 Bot 那列的「⋯」。指令:`$CTL phone wait '.row[data-bot="1"]' && $CTL phone click '[data-botmenu="1"]' && $CTL phone wait-text 對話詳細資訊 --in '#sheet-in' && $CTL phone shot phone-menu && $CTL phone click '#sheet-in .opt' --text 釘選 && $CTL wait-api '/api/state?since=0' '.bots[0].pinned == true'`。看到:一列一個 Bot(第二行一行說明);選單有「對話詳細資訊」「釘選」「移至分區」「更多…」;釘選後大腦那邊 pinned。
- **聊天**(covers `phone-pages`、`phone-look`、`phone-claude`):打開 Bot、傳一句。指令:`$CTL phone click '.row[data-bot="1"]' && $CTL phone send '你好,從手機傳的' && $CTL phone wait-text 'FAKE-MODEL 回答:你好,從手機傳的' --in '#msgs' && $CTL phone shot phone-chat`。看到:標題列是名稱和 fake-model;你的話是泡泡,回答直接排在畫面上、下面只有時間和圖示;輸入框是底部圓角卡片。
- **還沒連上就在外面**(covers `phone-net`):打開頁面,等它自己連上。指令:`$CTL phone open --listed && $CTL phone wait-gone '#v-gate.on' 20 && $CTL phone wait '#v-login.on'`。看到:連上後停在登入,不是 Bot 清單。
- **清單和選單**(covers `phone-pages`、`phone-claude`):看首頁,打開 Bot 那列的「⋯」。指令:`$CTL phone wait '.row[data-bot="1"]' && $CTL phone click '[data-botmenu="1"]' && $CTL phone wait-text 對話詳細資訊 --in '#sheet-in' && $CTL phone shot phone-menu && $CTL phone click '#sheet-in .opt' --text 釘選 && $CTL wait-api '/api/state?since=0' '.bots[0].pinned == true'`。看到:一列一個 Bot(第二行一行說明);選單照「使用者怎麼到」;釘選後大腦 pinned。
- **聊天**(covers `phone-pages`、`phone-look`、`phone-claude`):打開 Bot、傳一句。指令:`$CTL phone click '.row[data-bot="1"]' && $CTL phone send '你好,從手機傳的' && $CTL phone wait-text 'FAKE-MODEL 回答:你好,從手機傳的' --in '#msgs' && $CTL phone shot phone-chat && $CTL phone send '看 [[think 想]] [[call list_dir {"path":"."}]]' && $CTL phone longpress '.m.bot .bub' --text 收到工具結果 && $CTL phone click '#sheet-in .opt' --text 顯示步驟 && $CTL phone wait-text '(第 2 步)' --in '#msgs'`。看到:標題列是名稱和 fake-model;你的話是泡泡,回答直接排在畫面上、下面只有時間和圖示;輸入框是底部圓角卡片;第二輪看不到思考和步驟,長按選了才有。
- **全部允許,之後直接操作**(covers `phone-pages`、`phone-cards`):請 Bot 改名,在卡片上按「全部允許,之後直接操作」›「打開」,再按「允許」。指令:`$CTL phone send '請改名 [[call update_bot {"name":"手機改的名字"}]]' && $CTL phone click '#ask [data-direct]' && $CTL phone click '#sheet-in .opt' --text 打開 && $CTL phone wait-text '只能收緊、不能放寬' && $CTL phone wait '#ask .ask' && $CTL phone click '#ask button[data-a="once"]' && $CTL phone wait-text 手機改的名字 --in '#isl-name'`。看到:直接連線打不開直接操作([autonomy](autonomy.md)),卡片留著;按「允許」才改名。
- **舊頁面的回答不算**(covers `phone-cards`):卡片在等時,一個說不出是哪張卡的回答進來。指令:`$CTL phone send '再改 [[call update_bot {"name":"不該出現的名字"}]]' && $CTL wait-api '/api/state?since=0' '.approvals | length == 1' && $CTL api POST /api/bots/1/answer '{"answer":"once"}' && $CTL phone wait-text '手機上的回答沒有用上' --in '#msgs' && $CTL phone click '#ask button[data-a="reject"]' && $CTL phone wait-gone '#ask .ask' && $CTL state '.bots[0].name'`。看到:「手機上的回答沒有用上:這個頁面太舊…」,卡片還在;拒絕後名字還是「手機改的名字」。
- **顏色跟著電腦**(covers `phone-colors`):請 Bot 把電腦換成深色,重新整理;再把這支手機選「淺色」。指令:`$CTL phone send '換深色 [[call update_settings {"theme":"dark"}]]' && $CTL phone wait-text '主題 → dark' --in '#msgs' && $CTL phone open --listed && $CTL phone wait 'html[data-theme="dark"]' && $CTL phone shot phone-dark && $CTL phone click '#b-me' && $CTL phone click '#sheet-in .opt' --text 這支手機的外觀 && $CTL phone click '#sheet-in .opt' --text 淺色 && $CTL phone wait 'html[data-theme="light"]'`。看到:外觀「跟著電腦」時變深色;選「淺色」就只有這支手機變回淺色。
- **設定頁**(covers `phone-pages`):帳戶選單 › 設定,再點「保險庫」。指令:`$CTL phone click '#b-me' && $CTL phone click '#sheet-in .opt' --text 設定 && $CTL phone wait '[data-go="updates"]' && $CTL phone shot phone-settings && $CTL phone click '[data-go="vault"]' && $CTL phone wait-text '只在電腦上的 AnyBot 管理'`。看到:一般、個人資料與用量、模型、權限、整合、電腦、保險庫、語音、手機與帳號、更新;保險庫只有一句說明(手機看不到密碼)。
- **裝成 App 的提示**(covers `phone-app`):回首頁,看「把 AnyBot 裝成 App」,按 ✕ 關掉。指令:`$CTL phone open --listed && $CTL phone wait-text '把 AnyBot 裝成 App' && $CTL phone shot phone-install && $CTL phone click '#install-no' && $CTL phone wait-gone '#install-go' && $CTL api --no-auth GET /manifest.webmanifest --jq '.display'`。看到:提示和「安裝」(Chrome 給了安裝提示;iPhone 是「怎麼做」);按 ✕ 就不見了;manifest 的 display 是 standalone。
- **斷線又回來**(covers `phone-net`):打開 Bot,把大腦關掉,看提示;斷線時傳一句,再把大腦開回來。指令:`$CTL phone click '.row[data-bot="1"]' && $CTL stop && $CTL phone wait '#net.on' 30 && $CTL phone send '斷線時傳的' && $CTL phone wait-text '等連線後送出' --in '#msgs' 30 && $CTL phone shot phone-offline && $CTL serve && $CTL phone wait-gone '#net.on' 40 && $CTL phone wait-text 'FAKE-MODEL 回答:斷線時傳的' --in '#msgs' 60 && $CTL phone shot phone-back && $CTL model 'select(.tools > 0 and ((.user // "") | startswith("斷線時傳的"))) | .t' | grep -c '^"20'`。看到:標題列下方「連線中斷,正在重新連線…」,沒有另外跳「連不上」的提示,標題沒被蓋住;那句馬上出現在聊天裡,下面寫「等連線後送出(點一下拿回來)」;大腦回來後提示自己消失(沒有重新整理),斷線時傳的那句自己送到、有回答;最後印 `1`:重送了幾次,Bot 都只收到一次。
- **沒網路也打得開**(covers `phone-net`):看過聊天、回首頁後把大腦關掉,重新打開頁面;打開聊天傳一句,再重新打開一次,最後把大腦開回來。指令:`$CTL phone click '[data-back]' && $CTL stop && $CTL phone open --listed && $CTL phone wait '.row[data-bot="1"]' 3 && $CTL phone wait-text '離線中' --in '#net' 15 && $CTL phone click '.row[data-bot="1"]' && $CTL phone wait-text 'FAKE-MODEL 回答:斷線時傳的' --in '#msgs' 2 && $CTL phone send '要拿回來的' && $CTL phone click '.m.sending.held' && $CTL phone wait-gone '.m.sending' 5 && $CTL phone js 'document.querySelector("#input").value=""' && $CTL phone send '離線時傳的' && $CTL phone wait-text '等連線後送出' --in '#msgs' 30 && $CTL phone open --listed && $CTL phone click '.row[data-bot="1"]' && $CTL phone wait-text '離線時傳的' --in '#msgs' 3 && $CTL phone shot phone-kept && $CTL serve && $CTL phone wait-text 'FAKE-MODEL 回答:離線時傳的' --in '#msgs' 90`。看到:大腦關著也在 3 秒內看到 Bot 清單(不是連線畫面),提示「離線中:顯示的是上次的內容」;聊天是上次的內容;點「要拿回來的」它就回到輸入框;離線傳的那句關掉重開還在,大腦回來後自己送到、有回答。
- **只傳有變的**(covers `phone-net`):拿著同一份狀態的指紋再問一次。指令:`S=$($CTL api GET '/api/state?since=0' --jq .ssig | tr -d '"') && $CTL api GET "/api/state?since=0&ssig=$S" --jq '[has("base"), has("bots"), has("host"), has("version")]'`。看到:`[true,false,false,true]`:只回版本,Bot 清單和主機名稱沒有重送。
- **頁面存在手機上**(covers `phone-net`):打開過一次之後再打開,頁面和圖示從手機拿。指令:`$CTL phone open --listed && $CTL phone wait '.row[data-bot="1"]' && $CTL phone js 'navigator.serviceWorker.controller !== null' && $CTL phone js 'caches.open("anybot-shell-v1").then((c) => c.keys()).then((k) => k.map((r) => new URL(r.url).pathname).join(" "))'`。看到:`true`,和存著的 `/ /manifest.webmanifest /icon.svg /icon-180.png /icon-192.png`;`api/`、`h/`、`s/` 開頭的都不在裡面。
- **回到看過的聊天**(covers `phone-net`):打開 Bot、回首頁、再打開。指令:`$CTL phone click '.row[data-bot="1"]' && $CTL phone wait-text 'FAKE-MODEL 回答' --in '#msgs' && $CTL phone click '[data-back]' && $CTL phone click '.row[data-bot="1"]' && $CTL phone wait-text 'FAKE-MODEL 回答' --in '#msgs' 2 && S=$($CTL api GET /api/bots/1 --jq .sig | tr -d '"') && $CTL api GET "/api/bots/1?chat_sig=$S&chat_delta=1" --jq .unchanged`。看到:再打開時訊息馬上就在;大腦對拿著同一份的請求只回 `true`(沒有變),不重送訊息。
- **主畫面 App**(covers `phone-app`):指令:走不到——加入主畫面後的全螢幕、瀏海和手勢條、邊緣滑回要真的 iPhone 或 Android。看到:最接近的真路是上一步的提示和 manifest。
- **顏色跟著電腦**(covers `phone-colors`):請 Bot 把電腦換成深色,重新整理;再把這支手機選「淺色」。指令:`$CTL phone send '換深色 [[call update_settings {"theme":"dark"}]]' && $CTL phone wait-text '主題 → dark' --in '#msgs' && $CTL phone open --listed && $CTL phone wait 'html[data-theme="dark"]' && $CTL phone shot phone-dark && $CTL phone click '#b-me' && $CTL phone click '#sheet-in .opt' --text 這支手機的外觀 && $CTL phone click '#sheet-in .opt' --text 淺色 && $CTL phone wait 'html[data-theme="light"]'`。看到:「跟著電腦」時變深色;選「淺色」只有這支手機變淺。
- **設定頁**(covers `phone-pages`):帳戶選單 › 設定,再點「保險庫」。指令:`$CTL phone click '#b-me' && $CTL phone click '#sheet-in .opt' --text 設定 && $CTL phone wait '[data-go="updates"]' && $CTL phone shot phone-settings && $CTL phone click '[data-go="vault"]' && $CTL phone wait-text '只在電腦上的 AnyBot 管理'`。看到:`phone-pages` 列的設定頁都在;保險庫只有一句說明(手機看不到密碼)。
- **裝成 App 的提示**(covers `phone-app`):回首頁,看「把 AnyBot 裝成 App」,按 ✕ 關掉。指令:`$CTL phone open --listed && $CTL phone wait-text '把 AnyBot 裝成 App' && $CTL phone shot phone-install && $CTL phone click '#install-no' && $CTL phone wait-gone '#install-go' && $CTL api --no-auth GET /manifest.webmanifest --jq '.display'`。看到:提示和「安裝」(iPhone 是「怎麼做」);按 ✕ 就不見;manifest 的 display 是 standalone。
- **斷線又回來**(covers `phone-net`):打開 Bot,把大腦關掉,看提示;斷線時傳一句,再把大腦開回來。指令:`$CTL phone click '.row[data-bot="1"]' && $CTL stop && $CTL phone wait '#net.on' 30 && $CTL phone send '斷線時傳的' && $CTL phone wait-text '等連線後送出' --in '#msgs' 30 && $CTL phone shot phone-offline && $CTL serve && $CTL phone wait-gone '#net.on' 40 && $CTL phone wait-text 'FAKE-MODEL 回答:斷線時傳的' --in '#msgs' 60 && $CTL phone shot phone-back && $CTL model 'select(.tools > 0 and ((.user // "") | startswith("斷線時傳的"))) | .t' | grep -c '^"20'`。看到:標題列下方「連線中斷,正在重新連線…」(沒另跳「連不上」、沒蓋住標題);那句馬上出現、標「等連線後送出(點一下拿回來)」;大腦回來後提示自己消失(沒有重新整理),斷線時傳的那句自己送到、有回答;最後印 `1`:重送了幾次,Bot 都只收到一次。
- **沒網路也打得開**(covers `phone-net`):看過聊天、回首頁後把大腦關掉,重新打開頁面;打開聊天傳一句,再重新打開一次,最後把大腦開回來。指令:`$CTL phone click '[data-back]' && $CTL stop && $CTL phone open --listed && $CTL phone wait '.row[data-bot="1"]' 3 && $CTL phone wait-text '離線中' --in '#net' 15 && $CTL phone click '.row[data-bot="1"]' && $CTL phone wait-text 'FAKE-MODEL 回答:斷線時傳的' --in '#msgs' 2 && $CTL phone send '要拿回來的' && $CTL phone click '.m.sending.held' && $CTL phone wait-gone '.m.sending' 5 && $CTL phone js 'document.querySelector("#input").value=""' && $CTL phone send '離線時傳的' && $CTL phone wait-text '等連線後送出' --in '#msgs' 30 && $CTL phone open --listed && $CTL phone click '.row[data-bot="1"]' && $CTL phone wait-text '離線時傳的' --in '#msgs' 3 && $CTL phone shot phone-kept && $CTL serve && $CTL phone wait-text 'FAKE-MODEL 回答:離線時傳的' --in '#msgs' 90`。看到:大腦關著也 3 秒內看到 Bot 清單和上次的聊天(不是連線畫面),提示「離線中…」;點「要拿回來的」回到輸入框;離線傳的那句重開還在,大腦回來後自己送到、有回答。
- **只傳有變的**(covers `phone-net`):拿著同一份狀態的指紋再問一次。指令:`S=$($CTL api GET '/api/state?since=0' --jq .ssig | tr -d '"') && $CTL api GET "/api/state?since=0&ssig=$S" --jq '[has("base"), has("bots"), has("host"), has("version")]'`。看到:`[true,false,false,true]`:只回版本,Bot 清單和主機名稱不重送。
- **頁面存在手機上**(covers `phone-net`):打開過一次之後再打開,頁面和圖示從手機拿。指令:`$CTL phone open --listed && $CTL phone wait '.row[data-bot="1"]' && $CTL phone js 'navigator.serviceWorker.controller !== null' && $CTL phone js 'caches.open("anybot-shell-v1").then((c) => c.keys()).then((k) => k.map((r) => new URL(r.url).pathname).join(" "))'`。看到:`true`,和存著的 `/ /manifest.webmanifest /icon.svg /icon-180.png /icon-192.png`;`api/`、`h/`、`s/` 開頭的不在。
- **回到看過的聊天**(covers `phone-net`):打開 Bot、回首頁、再打開。指令:`$CTL phone click '.row[data-bot="1"]' && $CTL phone wait-text 'FAKE-MODEL 回答' --in '#msgs' && $CTL phone click '[data-back]' && $CTL phone click '.row[data-bot="1"]' && $CTL phone wait-text 'FAKE-MODEL 回答' --in '#msgs' 2 && S=$($CTL api GET /api/bots/1 --jq .sig | tr -d '"') && $CTL api GET "/api/bots/1?chat_sig=$S&chat_delta=1" --jq .unchanged`。看到:再打開時訊息馬上就在;大腦對拿著同一份的請求只回 `true`,不重送訊息。
- **主畫面 App**(covers `phone-app`):指令:走不到——全螢幕、瀏海、手勢條、邊緣滑回要真的 iPhone 或 Android。看到:最接近的是上一步的提示和 manifest。
- 自動測試:`cargo test remote::`、`cargo test remote_ui::`、`cargo test mirror_ui::`、`cargo test httpd::`;回答落在哪張卡:`.claude/skills/verify-approval-routing/run.sh --replay`。
## 陷阱
- 手機看不到保險庫,也看不到模型金鑰(只能寫入新的)。
- 手機上的卡沒用上時,要看現在在等什麼再按;開了很久的頁面先重新整理。用帳號登入的手機,頁面是帳號伺服器給的:伺服器還沒更新時,手機上的卡都答不了,要在電腦上答。
- 團隊成員的訊息跟訊息管道一樣不受信任:不帶你的記憶、沒有 App 操作工具;要核准的事只通知你和管理員,成員只看到「等擁有者或管理員決定」。
- 排隊的訊息不限時間,幾天後連上也照送。自動重送只認同一則(手機給每則訊息一個代號,大腦記一天):排隊超過一天、或中間大腦重新啟動過,一則送到了但回答掉在路上的那種,可能會多收一次。允許卡片的按鈕不排隊(卡片可能已經換了),連不上時按了會說沒送出。
- 「離線中」時,工作中、等你允許的卡片都是上次的樣子;被別的裝置登出的手機,連上之前也還看得到上次的內容。
- 換新版後第一次打開多半還是舊頁面,App 退到背景、手上沒東西時才換上。舊頁面答卡片照 `phone-cards`;說「頁面太舊」時重新整理(一定拿伺服器的新頁面)。
- (驗證)Service Worker 要沒有憑證錯誤才裝得上:用自簽憑證的直接連線,瀏覽器沒有信任那張憑證時不會存頁面,每次打開照舊下載。
- 手機看不到保險庫,也看不到模型金鑰(只能寫新的)。
- 手機上的卡沒用上時,要看現在在等什麼再按。用帳號登入的手機,頁面是帳號伺服器給的:伺服器還沒更新時卡都答不了,要在電腦上答。
- 團隊成員的訊息跟訊息管道一樣不受信任([channels](channels.md));要核准的事只通知你和管理員,成員只看到「等擁有者或管理員決定」。
- 自動重送只認同一則(每則一個代號,大腦記一天):排隊超過一天或大腦中間重開過,送到了但回答掉在路上的,可能多收一次。允許卡片的按鈕不排隊(卡片可能已經換了),連不上時按了說沒送出。
- 「離線中」時,工作中、等你允許的卡片都是上次的樣子;被別的裝置登出的手機,連上前也還看得到。
- 換新版後第一次打開多半還是舊頁面(`phone-net`)。舊頁面答卡片照 `phone-cards`;說「頁面太舊」時重新整理(一定拿伺服器的新頁面)。
- (驗證)Service Worker 要沒有憑證錯誤才裝得上:直接連線的自簽憑證沒被信任時不存頁面,每次照舊下載。
- (驗證)無頭 Chrome 不是 iPhone:通知、主畫面的全螢幕和手勢都不會出現;卡片和選單用 `wait` 等它滑進來再按。

View File

@ -217,6 +217,7 @@ pre.cb .cpy{position:absolute;top:4px;right:4px;width:30px;height:30px;border-ra
.typing i:nth-child(2){animation-delay:.2s}.typing i:nth-child(3){animation-delay:.4s}
@keyframes blink{0%,80%,100%{opacity:.3}40%{opacity:1}}
.working{display:flex;align-items:center;gap:8px;margin:6px 0;max-width:100%}
.working[data-wturn]{cursor:pointer}
.presence{font-size:var(--fs-small);color:var(--text3);margin:6px 4px;min-width:0;overflow-wrap:anywhere;background:linear-gradient(90deg,var(--text3) 30%,var(--text) 50%,var(--text3) 70%);background-size:200% 100%;-webkit-background-clip:text;background-clip:text;color:transparent;animation:shimmer 2s linear infinite}
@keyframes shimmer{to{background-position:-200% 0}}
.summary{align-self:stretch;margin:8px 0;padding:10px 12px;border-radius:var(--r-m);background:var(--hover);font-size:var(--fs-small);color:var(--text2)}
@ -1544,7 +1545,12 @@ function apply(v) {
// 串流降頻:開著聊天時服務端每秒最多重發一次聊天(最小的差量是一整條訊息),被擋時過一秒再問。
if (c && c.bot === S.open && c.throttled) chatLater();
// 交付確認不在訊息裡:只有 ✓ mark 動了,蓋上新的就好,不重畫整串。
else if (c && c.bot === S.open && c.unchanged) { if (mergeDeliveries(S.msgs, c.deliveries)) renderMsgs(); }
// (Whether it is working moves without the chat: a turn that ended after its last words came
// drops 「正在…」 and gets its time and buttons. What it is doing only changes that line's words.)
else if (c && c.bot === S.open && c.unchanged) {
if (mergeDeliveries(S.msgs, c.deliveries) || S.drawnBusy !== busyKey()) renderMsgs();
else { const p = $("msgs").querySelector(".working .presence"), st = (bot(S.open) || {}).status; if (p && st && p.textContent !== st) p.textContent = st; }
}
// Only where it differs from what this page holds: drop the first few (the oldest left the
// window), keep the next `from`, then the new ones. Told against another list: all of it again.
else if (c && c.bot === S.open && c.messages && c.from !== undefined) { if (c.base === S.chatSig) applyChat(S.msgs.slice(c.drop || 0).slice(0, c.from).concat(c.messages), c.sig, c.deliveries); else loadChat(); }
@ -2017,7 +2023,7 @@ function stepHtml(t, key) {
}
function thinkHtml(m) {
const key = "t" + m.index, open = S.openSteps[key];
return `<div class="steps"><div class="step done ${open ? "open" : ""}" data-step="${key}"><button class="h"><span class="st-i">${ic("brain", 14)}</span><span class="l">思考過程</span><span class="d">${esc(plain(m.thinking).slice(0, 80))}</span><span class="chev">${ic("chevron-right", 13)}</span></button><div class="body"><pre>${esc(m.thinking)}</pre></div></div></div>`;
return `<div class="step done ${open ? "open" : ""}" data-step="${key}"><button class="h"><span class="st-i">${ic("brain", 14)}</span><span class="l">思考過程</span><span class="d">${esc(plain(m.thinking).slice(0, 80))}</span><span class="chev">${ic("chevron-right", 13)}</span></button><div class="body"><pre>${esc(m.thinking)}</pre></div></div>`;
}
function attHtml(a) {
if (!a.path) return `<div class="filec">${ic(a.image ? "image" : "file", 16)}<span class="fn">${esc(a.name)}</span></div>`;
@ -2181,25 +2187,32 @@ function pageCard(p) {
// (The title once: the foot only says what it is and when.)
return `<div class="pcard" data-page="${p.id}"><div class="top"><div class="t">${esc(p.title)}</div>${lines}</div><div class="foot">${GLYPH(22)}<div class="x">頁面 · ${esc(p.updated)}${p.revision > 1 ? " · 已更新" : ""}</div></div></div>`;
}
// Whether the open bot is working (and says what it is doing): what the chat's foot shows of it.
function busyKey() { const b = bot(S.open) || {}; return `${!!b.busy}${!!b.status}`; }
function renderMsgs() {
// 分頁在背景(切到別的 App、鎖螢幕)時不重畫整串訊息:只記下要畫,回到前景再畫一次。
if (document.hidden) { S.msgsStale = true; return; }
S.msgsStale = false;
S.msgsStale = false; S.drawnBusy = busyKey();
const b = bot(S.open) || {};
const busy = b.busy;
// A turn: the bot's messages between two of the person's. Its steps fold into one line once it
// is done; while it works, the newest three stay in view.
// A turn: the bot's messages between two of the person's. Its thinking and steps stay out of the
// chat, like the desktop's: 長按 (right-click) the answer or its ⋯ › 顯示步驟 shows them in place,
// under a 「收起」 line; while it works, the line by its face says what it is doing. A turn with
// nothing else to press (no words, files or cards) keeps one 「已完成 N 個步驟」 line instead.
const turns = []; let curT = null;
S.msgs.forEach((m, i) => {
if (m.role === "user" || m.summary || m.interrupted || m.note) { curT = null; return; }
if (!curT) { curT = {first: i, last: i, key: String(m.at || i), steps: 0}; turns.push(curT); }
curT.last = i; curT.steps += (m.tools || []).filter((t) => !t.page && !t.card && !t.plan && !t.plan_update).length;
if (!curT) { curT = {first: i, last: i, key: String(m.at || i), steps: 0, thinks: 0, said: false}; turns.push(curT); }
curT.last = i; curT.steps += (m.tools || []).filter((t) => !t.page && !t.card && !t.plan && !t.plan_update && !t.talk).length;
if (m.thinking) curT.thinks++;
if (m.text || (m.attachments || []).length || (m.tools || []).some((t) => t.page || t.card || t.plan || t.talk)) curT.said = true;
});
const turnOf = {}; turns.forEach((t) => { for (let i = t.first; i <= t.last; i++) turnOf[i] = t; });
S.turnOf = turnOf; // (for the message menu's 顯示步驟)
const lastTurn = turns[turns.length - 1];
const lastBot = [...S.msgs].reverse().find((m) => m.role !== "user" && m.text && !m.note);
const lastMsg = S.msgs[S.msgs.length - 1];
const shown = {}; let day = "";
let day = "";
let h = "";
// 載入更早:開頁只有最新 30 條,這一鍵一次往回補 60 條。
const atStart = S.olderEnd && S.olderEnd.bot === S.open && S.msgs.length && S.msgs[0].index <= S.olderEnd.at;
@ -2251,7 +2264,16 @@ function renderMsgs() {
}
const t = turnOf[i];
const running = busy && t === lastTurn;
const unfolded = t && (S.unfold[t.key] || t.steps <= 2);
const unfolded = !!(t && S.unfold[t.key]);
// The turn's line, where its first thought or step would be (once per turn): 「收起」 while
// shown; the way in for a turn with nothing else to press.
const foldLine = () => {
if (!t || t.lined || !(unfolded || (!t.said && !running))) return "";
t.lined = true;
const what = unfolded ? (t.steps ? `收起 ${t.steps} 個步驟` : "收起思考過程") : t.steps ? `已完成 ${t.steps} 個步驟` : "思考過程";
return `<button class="fold" data-turn="${esc(t.key)}" aria-expanded="${unfolded}">${ic(t.steps ? "circle-check" : "brain", 14)} ${what} ${ic(unfolded ? "chevron-up" : "chevron-right", 13)}</button>`;
};
const thought = m.thinking ? foldLine() + (unfolded ? thinkHtml(m) : "") : "";
let steps = "", extra = "";
(m.tools || []).forEach((x, k) => {
if (x.page) { extra += pageCard(x.page); return; }
@ -2259,23 +2281,25 @@ function renderMsgs() {
if (x.plan) { extra += planCard(x.plan); return; }
if (x.plan_update) return;
if (x.talk) { extra += talkCard(x.talk, x.status, m.author || (bot(S.open) || {}).name || ""); return; }
const n = (shown[t.key] = (shown[t.key] || 0) + 1);
if (unfolded) { steps += stepHtml(x, m.index + ":" + k); return; }
if (n === 1) steps += `<button class="fold" data-turn="${esc(t.key)}">${ic(running ? "loader" : "circle-check", 14)} ${running ? "已做了" : "已完成"} ${t.steps} 個步驟 ${ic("chevron-right", 13)}</button>`;
if (running && n > t.steps - 3) steps += stepHtml(x, m.index + ":" + k);
steps += foldLine();
if (unfolded) steps += stepHtml(x, m.index + ":" + k);
});
const end = t && i === t.last && !running;
const who = m.author ? `<div class="who">${esc(m.author)}</div>` : "";
const think = m.thinking ? thinkHtml(m) : "";
const think = thought ? `<div class="steps">${thought}</div>` : "";
const bub = m.text ? `<div class="bub">${pageMd(m.text, 0)}</div>` : "";
const atts = (m.attachments || []).map((a) => attHtml(a) + dlvMark(a)).join("");
const meta = end && m.text ? `<div class="meta">${m.at ? esc(clock(m.at)) : ""}<button data-copy="${i}" title="複製">${ic("copy", 14)}</button>${owner() && m === lastBot && t === lastTurn ? `<button data-regen="1" title="重新產生">${ic("refresh", 14)}</button>` : ""}<button data-more="${i}" title="更多">${ic("ellipsis", 14)}</button></div>` : "";
const unv = running ? "" : unvMark(m, i);
h += `<div class="m bot${fr(i)} ${m.error ? "err" : ""}" data-msg="${i}">${who}${think}${bub}${steps ? `<div class="steps">${steps}</div>` : ""}${extra}${atts}${unv}${reacts}${meta}</div>`;
const body = `${think}${bub}${steps ? `<div class="steps">${steps}</div>` : ""}${extra}${atts}${unv}${reacts}${meta}`;
// (A round whose thinking and steps are all behind the line takes no room.)
if (body) h += `<div class="m bot${fr(i)} ${m.error ? "err" : ""}" data-msg="${i}">${who}${body}</div>`;
});
// Still working: what it is doing now; a message nobody answered yet can be sent again.
if (busy) h += (lastMsg && lastMsg.role !== "user" && !lastMsg.text && !(lastMsg.tools || []).length) || lastMsg?.role === "user" ? `<div class="m bot"><div class="typing"><i></i><i></i><i></i></div></div>` : "";
if (busy && b.status) h += `<div class="working">${face(b, "sm")}<div class="presence">${esc(b.status)}</div></div>`;
// (A tap on it shows the running turn's thinking and steps, like 顯示步驟 on an answer.)
const live = busy && lastTurn && lastTurn.last === S.msgs.length - 1 && (lastTurn.steps || lastTurn.thinks) ? lastTurn : null;
if (busy && b.status) h += `<div class="working"${live ? ` data-wturn="${esc(live.key)}"` : ""}>${face(b, "sm")}<div class="presence">${esc(b.status)}</div></div>`;
if (!busy && lastMsg && lastMsg.role === "user" && !lastMsg.wake && owner() && !OUT.some((x) => x.bot === S.open && x.host === S.host)) h += `<div class="meta" style="align-self:flex-end">還沒有回覆 <button data-resend="1">${ic("refresh", 14)} 重新傳送</button></div>`;
if (!S.msgs.length && !S.chatLoaded) h = S.stale || S.offline ? `<div class="empty">這個聊天還沒存在這支手機上,連上後就會出現。</div>` : "";
else if (!S.msgs.length) {
@ -2312,7 +2336,7 @@ $("msgs").addEventListener("click", async (e) => {
const fl = e.target.closest("a.flink"); if (fl) { e.preventDefault(); openDeadLink(fl.dataset.fname); return; }
const st = e.target.closest(".step .h");
if (st) { const k = st.parentElement.dataset.step; S.openSteps[k] = !S.openSteps[k]; st.parentElement.classList.toggle("open"); return; }
const f = e.target.closest(".fold"); if (f) { S.unfold[f.dataset.turn] = true; renderMsgs(); return; }
const f = e.target.closest(".fold,[data-wturn]"); if (f) { const k = f.dataset.turn || f.dataset.wturn; S.unfold[k] = !S.unfold[k]; renderMsgs(); return; }
const bs = e.target.closest("[data-brstop]"); if (bs) { try { await api(base() + `api/bots/${+bs.dataset.brstop}/stop`, {json: {}}); toast("已停止支線"); } catch (err) { toast(err.message); } return; }
// A message not sent (still waiting for the line, or refused): back into the input with its files.
const un = e.target.closest(".sending.failed,.sending.held");
@ -2403,6 +2427,13 @@ function msgMenu(i) {
// 重新產生 kept what it replaced (on the brain): put it back.
if (m === lastBot && owner() && (bot(S.open) || {}).can_restore && !(bot(S.open) || {}).busy) items.push({icon: "history", label: "還原上一個答案", on: async () => { try { await api(base() + `api/bots/${S.open}/restore_answer`, {json: {}}); toast("還原了"); } catch (e) { toast(e.message); } }});
if (m.role === "user" && i === S.msgs.length - 1 && owner()) items.push({icon: "refresh", label: "重新傳送", on: () => act("reply", {bot: S.open})});
// 顯示步驟 (the desktop's ⋯ › 顯示步驟): this turn's thinking and steps, in place, from its top.
const t = m.role !== "user" && S.turnOf ? S.turnOf[i] : null;
if (t && (t.steps || t.thinks)) items.push({icon: t.steps ? "list-checks" : "brain", label: S.unfold[t.key] ? "隱藏步驟" : t.steps ? `顯示步驟(${t.steps})` : "顯示思考過程", on: () => {
S.unfold[t.key] = !S.unfold[t.key]; renderMsgs();
const f = S.unfold[t.key] && document.querySelector(`#msgs .fold[data-turn="${CSS.escape(t.key)}"]`);
if (f) f.scrollIntoView({block: "nearest"});
}});
const emojis = m.index != null && owner() ? `<div class="emojis">${QUICK.map((e) => `<button data-e="${e}">${e}</button>`).join("")}</div>` : "";
const el = sheet("", items, emojis);
el.querySelectorAll("[data-e]").forEach((b) => b.onclick = () => { closeSheet(); act("react", {bot: S.open, index: m.index, emoji: b.dataset.e}, false).then(() => loadChat()); });