diff --git a/FEATURES.md b/FEATURES.md index d8006a0..a5d08f3 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -1580,10 +1580,18 @@ computer_use_screenshot、click、mouse_move、mouse_button(按住/放開) - **用量**:7 天/30 天/90 天/一年。token(新讀、寫、快取讀到)、呼叫次數、花費——只算模型服務自己回報的(例如 OpenRouter),沒回報的寫「未定價」(部分有部分沒有:「US$0.97(另有 694 次呼叫未定價)」),不是 0 元;每天一條(滑過看數字)、依模型、依 Bot(前 8 名,發布前檢查、目標檢查各自一列,刪掉的 Bot 寫「Bot 9(已刪除)」)。 - 都從已經有的紀錄算(`usage/YYYY-MM.jsonl` 和每則訊息的時間),不另外存;用大腦的時區切日子;打開時在背景算,一分鐘內再看不重算。螢幕電腦向大腦要(`api/sync/stats`),手機用 `api/stats`(擁有者才有)。 +### 所有檔案(側邊欄的資料夾按鈕) + +- 每個 Bot 交給你的、你傳給 Bot 的檔案,跨 Bot、跨對話放在一個視窗(照 OpenBot 檔案庫的排版)。從聊天(包括較早的對話)裡已經記下的附件來,不掃硬碟;同一個檔案只列一次,新的在前;視窗開著每 5 秒重讀。 +- 從哪裡開:側邊欄最上面一排第一個(資料夾圖示,任務按鈕左邊);左下角選單「所有檔案…」。截圖用 `ANYBOT_SHOT_VIEW=library`。 +- 左欄:搜尋檔名、「所有檔案」、「最近 7 天」、每個有檔案的 Bot(顏色點、數量)。上面種類分頁帶數量:全部、圖片、文件、程式碼、表格、影音、其他(沒有的不列)。右上「格子/清單」:格子是縮圖或副檔名+檔名+「Bot · 日期」,一排幾張撐滿寬度;清單是「Bot · 日期 · 大小」。視窗高度固定,切種類、看法不跳。 +- 檔案不在原處(刪掉或搬走):灰字、紅字「不見了」,點不開。其他點一下用 AnyBot 的檢視器打開(Markdown、表格、圖片、PDF、影音、程式碼;用其他 App 打開、下載)。 +- 螢幕電腦看的是從大腦抓過來的副本。手機還沒有(只有每個對話的「資料庫」)。功能地圖新的一區 library.md。 + ### Bot 在哪一台(左下角) - 左下角你的名字下面多一行:Bot 在哪一台——「這台電腦」,或「大腦「雲端大腦」」(綠點連得到、灰點連不到)。不用打開設定就看得出現在看的是哪一台的 Bot。 -- 點一下開「Bot 在哪一台」選單(以前是直接打開設定):「這台電腦(這台的名字)」、帳號裡每台可以當大腦的電腦(手腳不列),現在用的那台打勾,離線的灰、不能點;點一下就換過去——跟 設定 › 手機與帳號 大腦那一欄的「改用它當大腦」「改回用這台自己的 Bot」是同一件事。沒登入帳號時多一行「登入帳號,才能換到別台大腦…」;最下面「設定…」(⌘, 照舊)。帳號裡的電腦清單每 15 秒更新一次。截圖用 `ANYBOT_SHOT_VIEW=whose`(示範資料:已登入、是「雲端大腦」的螢幕、另一台離線)。 +- 點一下開「Bot 在哪一台」選單(以前是直接打開設定):「這台電腦(這台的名字)」、帳號裡每台可以當大腦的電腦(手腳不列),現在用的那台打勾,離線的灰、不能點;點一下就換過去——跟 設定 › 手機與帳號 大腦那一欄的「改用它當大腦」「改回用這台自己的 Bot」是同一件事。沒登入帳號時多一行「登入帳號,才能換到別台大腦…」;分隔線下「所有檔案…」「個人資料與用量…」「設定…」(⌘, 照舊)。帳號裡的電腦清單每 15 秒更新一次。截圖用 `ANYBOT_SHOT_VIEW=whose`(示範資料:已登入、是「雲端大腦」的螢幕、另一台離線)。 - 螢幕電腦上,設定每一頁最上面一行寫這頁是誰的(計畫 B2):「兩邊都有」——一般(外觀和帳戶是這台的;時區、記憶、通知是大腦的)、電腦(「在這台電腦上執行」「讓帳號裡的其他電腦使用這台」和訊息是這台的;其餘是大腦的)、更新(更新的是這台的 AnyBot;Bot 的電腦在大腦上);「這台電腦」——手機與帳號;「大腦「名字」」——模型、整合、權限、語音(改了存在大腦,帳號裡每台看到的都一樣)。依據是同步時每台留著自己的那幾項(帳號、外觀、側欄、在這台執行的規則、訊息)。保險庫不標(還沒確認是哪一邊)。大腦本身不顯示(全部都是這台的)。 ### 模型在哪裡跑(本機/區網/雲端) diff --git a/docs/feature-map/README.md b/docs/feature-map/README.md index 17b2a1a..76a9eb2 100644 --- a/docs/feature-map/README.md +++ b/docs/feature-map/README.md @@ -98,6 +98,7 @@ Bot 讀得到的是開頭、子功能、使用者怎麼到、Bot 那一行和沒 - [box](box.md):Bot 的電腦:桌面、更新、從帳號看畫面。 - [files](files.md):指令、檔案、終端機、監看、檢查點(/rewind)。 - [deliver](deliver.md):送檔、打開給使用者看、發佈網站。 +- [library](library.md):所有檔案:每個 Bot 的檔案放一起,種類、Bot、最近 7 天、搜尋,格子/清單,不見了的標出來,點開預覽。 - [claims](claims.md):完成宣稱檢查:說做好了卻沒做到、打不開的連結、未驗證、叫醒改正。 - [browser](browser.md):AnyBot 瀏覽器、設定檔、發布關卡、已送帳本。 - [screen](screen.md):截圖、點擊、打字、批次、交給使用者操作、示範教學。 diff --git a/docs/feature-map/library.md b/docs/feature-map/library.md new file mode 100644 index 0000000..c7b8e8f --- /dev/null +++ b/docs/feature-map/library.md @@ -0,0 +1,39 @@ +# 所有檔案 + +每個 Bot 交給你的、你傳給 Bot 的檔案,跨 Bot、跨對話放在一個視窗:照種類分頁、照 Bot 或最近 7 天看、搜尋檔名,格子或清單,點一下在 AnyBot 裡打開。清單從聊天裡已經記下的附件來,不掃硬碟;檔案被刪掉或搬走的標「不見了」。只在電腦版。 + +## 子功能 + +- `library-gather` 從哪來:每個 Bot 的聊天(包括較早的對話)裡的附件——你附上的檔案、Bot 用 `send_file` 交的、給你看的截圖;同一個檔案只列一次,新的在前。視窗開著時每 5 秒重讀一次。 +- `library-kinds` 種類:上面一排「全部、圖片、文件、程式碼、表格、影音、其他」,各帶數量,沒有的那類不列。圖片含 heic;文件是 Markdown、PDF、Word、HTML、純文字;表格是 xlsx、csv 這類;影音是錄音和影片;程式碼看副檔名(rs、py、js、ts、json、yaml…)。 +- `library-place` 左欄:搜尋(只比對檔名)、「所有檔案」、「最近 7 天」,「Bot」下面每個有檔案的 Bot 一列(Bot 的顏色點、數量,多的在前)。左欄的數量是全部的;上面種類的數量照左欄選的和搜尋算。 +- `library-view` 兩種看法(右上「格子/清單」):格子每張卡上面是縮圖(圖片)或副檔名,下面檔名和「哪個 Bot · 日期」(今天的寫「今天 14:05」),一排放得下幾張就幾張、撐滿寬度;清單每列圖示、檔名,右邊「Bot · 日期 · 大小」。滑過看完整路徑和大小。切種類、看法時視窗大小不變。 +- `library-gone` 不見了:檔案已經不在原來的地方(刪掉或搬走),檔名變灰、紅字「不見了(檔案已經刪掉或搬走)」(清單寫「不見了」),點不開。 +- `library-open` 點一下用 AnyBot 自己的檢視器打開,跟聊天裡的檔案卡片一樣(Markdown 排版、表格、圖片、PDF、錄音影片、程式碼…),右上「用其他 App 打開」、下載、關閉。 + +## 使用者怎麼到 + +- 側邊欄最上面一排第一個(資料夾圖示,滑過寫「所有檔案」),在任務按鈕左邊。 +- 左下角帳戶那一列的選單 ›「所有檔案…」。 +- 只看這個對話的檔案:右側面板「資料庫」([deliver](deliver.md));手機在「對話詳細資訊 › 資料庫」。 + +## 怎麼操作(verify-anybot) + +- Bot:沒有專門的工具;使用者找以前交過或傳過的檔案,請他打開「所有檔案」(側邊欄最上面的資料夾按鈕);檔案還在 Bot 電腦上的,可以 `send_file` 再交一次。 + +前提: + +- 基本前提和「手機已登入」(README),開著 Bot 1 的聊天:`$CTL phone click '.row[data-bot="1"]'`。桌面的步驟要開視窗(`ABV_ALLOW_WINDOW=1`,先 `ctl stop`),座標照 1200×820。 + +- **放七個檔案**(covers `library-gather`):從手機附上七個檔案送出,再刪掉其中一個存在 AnyBot 裡的那份。指令:`D=$(mktemp -d) && cp cat-1.png "$D/貓一.png" && cp cat-2.png "$D/貓二.png" && printf '# 發布計畫\n\n- 11/22 上線\n' > "$D/release-notes-v4.md" && printf '日期,用量\n11/20,3610\n' > "$D/用量.csv" && printf 'print("hello")\n' > "$D/hello.py" && printf 'x' > "$D/舊的.txt" && (cd "$D" && zip -q 封存.zip hello.py) && for f in 貓一.png 貓二.png release-notes-v4.md 用量.csv hello.py 舊的.txt 封存.zip; do $CTL phone upload '#file' "$D/$f" && $CTL phone wait-text "$f" --in '#chips' 20; done && $CTL phone send 這些檔案先放著 && $CTL phone wait-text 'FAKE-MODEL 回答:這些檔案先放著' --in '#msgs' && SCR=$(sed -n 's/^SCR=//p' target/verify-anybot/current/run.env) && rm -f "$(find "$SCR/data/attachments" -name '*舊的.txt' | head -1)" && $CTL api GET /api/bots/1 --jq '[.messages[].attachments[]?.name]'`。看到:API 列出七個檔名;舊的.txt 在 AnyBot 裡的那份刪掉了。 +- **格子、分類、不見了**(covers `library-place`、`library-kinds`、`library-view`、`library-gone`):從側邊欄的資料夾按鈕打開。指令:`$CTL phone stop && $CTL stop && ABV_ALLOW_WINDOW=1 $CTL desktop-shot library ANYBOT_SHOT_REAL=1 ANYBOT_SHOT_SIZE=1200x820 ANYBOT_SHOT_FRAMES=520 'ANYBOT_SHOT_CLICK=120,30@440'`。看到:「所有檔案」視窗,左欄「所有檔案 7」「最近 7 天 7」、「Bot」下「驗證小幫手 7」;上面「全部 7、圖片 2、文件 2、程式碼 1、表格 1、其他 1」(沒有影音);三張一排撐滿,兩張貓是縮圖,其他寫 MD、CSV、PY、TXT、ZIP;舊的.txt 灰字、紅字「不見了(檔案已經刪掉或搬走)」。 +- **清單、打開**(covers `library-view`、`library-open`、`library-gone`):按「清單」,再按 release-notes-v4.md 那列。指令:`ABV_ALLOW_WINDOW=1 $CTL desktop-shot library-list ANYBOT_SHOT_REAL=1 ANYBOT_SHOT_SIZE=1200x820 ANYBOT_SHOT_FRAMES=500 'ANYBOT_SHOT_CLICK=120,30@440;1033,127@470' && ABV_ALLOW_WINDOW=1 $CTL desktop-shot library-open ANYBOT_SHOT_REAL=1 ANYBOT_SHOT_SIZE=1200x820 ANYBOT_SHOT_FRAMES=540 'ANYBOT_SHOT_CLICK=120,30@440;1033,127@470;450,267@500'`。看到:視窗沒有跳動;每列「名稱……驗證小幫手 · 今天 HH:MM · 31 B」,舊的.txt 右邊紅字「不見了」;release-notes-v4.md 在 AnyBot 的檢視器打開:「發布計畫」「11/22 上線」,右上「用其他 App 打開」、下載、關閉。帳戶選單的「所有檔案…」、搜尋、選某個 Bot:靠自動測試和版面檢查。 +- 自動測試:`cargo test app::library_ui::`、`cargo test layout_audit::`(「所有檔案」這一景)。 + +## 陷阱 + +- 只列聊天裡記下的附件:Bot 在它電腦上做出來、沒有用 `send_file` 交的檔案不在這裡(請它交給你)。刪掉 Bot,它的檔案也不再列。 +- 「不見了」只看檔案還在不在,不比內容;內容對不對看檔案卡上的「檔案核對」([deliver](deliver.md))。 +- 螢幕電腦上看的是從大腦抓過來的副本:剛連上還沒抓完的暫時顯示「不見了」;大腦那邊刪掉了,這台的副本照樣在。 +- 手機還沒有「所有檔案」,只有每個對話的「資料庫」。 +- (驗證)座標是 1200×820 的視窗;視窗大小一換,按鈕位置跟著換。 diff --git a/docs/feature-map/settings.md b/docs/feature-map/settings.md index 76212c6..9e9e697 100644 --- a/docs/feature-map/settings.md +++ b/docs/feature-map/settings.md @@ -10,7 +10,7 @@ - 通知:Bot 做完或等你時通知、需要你時響一聲([account](account.md))。Mac 上的通知是 AnyBot.app 自己發的(貓的圖示),點一下打開那個 Bot;從建置資料夾直接跑(不是 .app)時改用系統的 display notification,圖示是「工序指令編寫程式」。 - Bot:時區,例行任務和提醒用([routines](routines.md))。 - 帳戶:「登入」或「管理帳戶」打開「手機與帳號」頁;資料放在哪。 -- `settings-whose` 左下角(你的名字):名字下面一行寫 Bot 在哪一台——「這台電腦」,或「大腦「名字」」(綠點連得到、灰點連不到)。點一下開「Bot 在哪一台」選單:「這台電腦(這台的名字)」、帳號裡每台可以當大腦的電腦(現在用的打勾,離線的灰、不能點),點一下就換——跟「手機與帳號」頁大腦那一欄的「改用它當大腦」「改回用這台自己的 Bot」一樣([account](account.md));沒登入帳號多一行「登入帳號,才能換到別台大腦…」;最下面「設定…」(⌘, 也可以)。 +- `settings-whose` 左下角(你的名字):名字下面一行寫 Bot 在哪一台——「這台電腦」,或「大腦「名字」」(綠點連得到、灰點連不到)。點一下開「Bot 在哪一台」選單:「這台電腦(這台的名字)」、帳號裡每台可以當大腦的電腦(現在用的打勾,離線的灰、不能點),點一下就換——跟「手機與帳號」頁大腦那一欄的「改用它當大腦」「改回用這台自己的 Bot」一樣([account](account.md));沒登入帳號多一行「登入帳號,才能換到別台大腦…」;分隔線下「所有檔案…」([library](library.md))、「個人資料與用量…」、「設定…」(⌘, 也可以)。 - `settings-me` 「個人資料」:名字、過去一年有幾個活躍日;五張卡——Token(過去一年,不算快取命中)、最活躍的一天、訊息、目前連續天數(今天還沒用不算斷)、最長連續天數;「活動」一年的熱度格子(一週一欄、越忙顏色越深,滑過看日期、token、訊息數);「用量」選 7 天/30 天/90 天/一年:token(新讀、寫、快取讀到)、呼叫次數、花費(模型服務回報的,沒回報寫「未定價」,不是 0 元)、每天一條、依模型、依 Bot。左下角選單也有「個人資料與用量…」。螢幕電腦上算的是大腦的(向大腦要);手機和螢幕的路是 `api/stats`、`api/sync/stats`(擁有者才有)。 - `settings-account` 「手機與帳號」頁(從 一般 › 帳戶 進去,[account](account.md)):「AnyBot 帳號」(登入、備份、還原)、大腦和「加一台電腦」([computers](computers.md))、「同一個網路直接連」、「手機可以做什麼」、「直接連線的裝置」、「分享給團隊」([team](team.md))、「帳號裡的電腦」。 - `settings-models` 「模型」:每家 AI 供應商的 API 金鑰、服務網址、新 Bot 預設模型、「測試連線並取得模型清單」([models](models.md));本機或區網的供應商多「看不到圖時,請雲端模型看截圖和附件」(預設關,[chat](chat.md))。「ChatGPT 方案」沒有金鑰和網址欄,改成「ChatGPT 帳號」:登入狀態、「使用 ChatGPT 繼續」「登出」「換帳號」「打開登入頁」「管理用量」;連到別台大腦時多一格貼回登入網址和「完成登入」。 @@ -46,7 +46,7 @@ - 基本前提和「手機已登入」(README),開著 Bot 1 的聊天:`$CTL phone click '.row[data-bot="1"]'`。 -- **左下角:Bot 在哪一台**(covers `settings-whose`):前提:要開視窗。指令:`$CTL stop && ABV_ALLOW_WINDOW=1 $CTL desktop-shot whose ANYBOT_SHOT_VIEW=whose ANYBOT_SHOT_SIZE=1000x620 'ANYBOT_SHOT_CLICK=90,595@6' ANYBOT_SHOT_FRAMES=14`(示範資料:已登入、是「雲端大腦」的螢幕、jenny-Host 離線),再不帶 `ANYBOT_SHOT_VIEW` 跑一次(沒登入)。看到:左下角「daniel/● 大腦「雲端大腦」」;選單「Bot 在哪一台」下「這台電腦(…)」「✓ 雲端大腦」「jenny-Host(離線)」(灰),分隔線下「設定…」;沒登入時是「✓ 這台電腦(…)」「登入帳號,才能換到別台大腦…」「設定…」。真的切換要帳號裡有另一台大腦:走不到,和「手機與帳號」頁的按鈕是同一段(`mir.want`、`mir.leave`)。 +- **左下角:Bot 在哪一台**(covers `settings-whose`):前提:要開視窗。指令:`$CTL stop && ABV_ALLOW_WINDOW=1 $CTL desktop-shot whose ANYBOT_SHOT_VIEW=whose ANYBOT_SHOT_SIZE=1000x620 'ANYBOT_SHOT_CLICK=90,595@6' ANYBOT_SHOT_FRAMES=60`(示範資料:已登入、是「雲端大腦」的螢幕、jenny-Host 離線),再不帶 `ANYBOT_SHOT_VIEW` 跑一次(沒登入)。看到:左下角「daniel/● 大腦「雲端大腦」」;選單「Bot 在哪一台」下「這台電腦(…)」「✓ 雲端大腦」「jenny-Host(離線)」(灰),分隔線下「所有檔案…」「個人資料與用量…」「設定…」;沒登入時是「✓ 這台電腦(…)」「登入帳號,才能換到別台大腦…」,分隔線下同樣三項。真的切換要帳號裡有另一台大腦:走不到,和「手機與帳號」頁的按鈕是同一段(`mir.want`、`mir.leave`)。 - **個人資料與用量**(covers `settings-me`):指令:`$CTL api GET /api/stats --jq '{tokens_year, messages_year, streak_now, active_days, d: (.days|length), p: (.periods|keys)}'`;桌面要開視窗:`$CTL stop && ABV_ALLOW_WINDOW=1 $CTL desktop-shot me ANYBOT_SHOT_TAB=me ANYBOT_SHOT_SIZE=1000x900`。看到:API 有 371 天的 days、periods 7/30/90/365;畫面上五張卡、熱度格子、「用量」和那四個期間、依模型、依 Bot。scratch 的假模型不回報用量,token 是 0、花費「未定價」(真的數字靠 `cargo test stats::`)。 - **Bot 改三樣**(covers `settings-by-bot`、`settings-general`):請 Bot 換深色、只用黑色、時區紐約,再傳一句。指令:`$CTL phone send '改 [[call update_settings {"theme":"dark","accent":"black","timezone":"America/New_York"}]]' && $CTL phone wait-text '時區 → America/New_York' --in '#msgs' && $CTL phone send 幾點 && $CTL phone wait-text 'FAKE-MODEL 回答:幾點' --in '#msgs' && $CTL model 'select(.kind == "turn") | .user' && TZ=America/New_York date +%H:%M`。看到:不用卡片,「已更新:主題 → dark、聊天的顏色 → black、時區 → America/New_York」;Bot 收到的〔送出時間〕是紐約時間。 - **錯的時區**(covers `settings-by-bot`):指令:`$CTL phone send '錯 [[call update_settings {"timezone":"Mars/Base"}]]' && $CTL phone wait-text '不是有效的時區名稱' --in '#msgs' && $CTL state .timezone`。看到:「「Mars/Base」不是有效的時區名稱(例如 Asia/Taipei)」;還是 America/New_York。 diff --git a/docs/plan-2026-11-openbot.md b/docs/plan-2026-11-openbot.md index 768eb3a..f300e09 100644 --- a/docs/plan-2026-11-openbot.md +++ b/docs/plan-2026-11-openbot.md @@ -144,7 +144,7 @@ 花費記「供應商自己回報」或「照價目表估計」(`rate_basis`),不知道價錢的顯示「未定價」不是 $0; 用量頁可選 Bot/模型、花費或 token、7/30/90 天/一年,分頁看模型/Bot/日期/技能;註明是估計。 -**C6. 檔案**:檔案庫從大腦已有的附件紀錄建(不掃硬碟),每個檔標「還在/不見了」;上面分類分頁帶數量 +**C6. 檔案**(11/21 做了:電腦版「所有檔案」——左欄搜尋、所有檔案、最近 7 天、每個 Bot;種類分頁帶數量;格子/清單;不見了;點開用現有的檢視器。瀑布流、未歸檔、已刪除的 Bot、右側預覽面板、手機版還沒做):檔案庫從大腦已有的附件紀錄建(不掃硬碟),每個檔標「還在/不見了」;上面分類分頁帶數量 (現況:沒有跨 Bot 的檔案庫;右側欄「資料庫」只列這個聊天的頁面和檔案(本週/更早,各 5 個再展開),只有清單、沒有分類和搜尋。預覽器其實很強:試算表、Markdown、docx、圖片(含 heic)、PDF、音訊、影片首格、程式碼都能看;pptx、doc、rtf 不行。) (全部、圖片、文件、程式碼、表格、影音、其他);左欄:所有檔案、最近 7 天、未歸檔、每個 Bot 一個、 「已刪除的 Bot」(有孤兒檔才出現);瀑布流(預設)/格子/清單三種檢視;點開是右側預覽面板:Markdown 排版(可切原文)、 diff --git a/src/app.rs b/src/app.rs index 18c3e78..d5156d8 100644 --- a/src/app.rs +++ b/src/app.rs @@ -44,6 +44,7 @@ mod drops_ui; mod tasks_ui; mod me_ui; mod activity_ui; +mod library_ui; mod memory_ui; mod goal_ui; mod context_ui; @@ -340,6 +341,7 @@ pub struct App { tk: tasks_ui::TasksUi, me: me_ui::MeUi, act: activity_ui::ActivityUi, + lib: library_ui::LibraryUi, drop_last: String, nightly_checked: Option, /// Files and pictures waiting to go with the next message. @@ -607,6 +609,7 @@ impl App { tk: Default::default(), me: Default::default(), act: Default::default(), + lib: Default::default(), drop_last: String::new(), nightly_checked: None, att: Default::default(), @@ -730,6 +733,8 @@ impl App { // Optional view for checking the dialogs in a picture. match std::env::var("ANYBOT_SHOT_VIEW").as_deref() { Ok("chat") => app.state.selected = 1, + // 所有檔案. + Ok("library") => app.lib.open = true, // 在哪一台 (bottom left): signed in, a screen of 雲端大腦, another brain off. (An // account server that refuses at once; the screen's copy in a temp folder.) Ok("whose") => { @@ -1371,6 +1376,7 @@ impl App { app.show_settings = true; app.settings_tab = SettingsTab::Remote; } + Ok("library") => app.lib.open = true, Ok("computers") => { app.show_settings = true; app.settings_tab = SettingsTab::Computers; @@ -7205,6 +7211,7 @@ impl eframe::App for App { self.memory_page(ctx); self.drops_page(ctx); self.tasks_window(ctx); + self.library_window(ctx); self.settings(ctx); } self.delete_dialog(ctx); diff --git a/src/app/attach_ui.rs b/src/app/attach_ui.rs index 756d757..be0c97a 100644 --- a/src/app/attach_ui.rs +++ b/src/app/attach_ui.rs @@ -114,7 +114,7 @@ impl App { painter.text(inner.center(), egui::Align2::CENTER_CENTER, "放開以附加檔案", egui::FontId::proportional(FONT_H3), p.accent); } - fn thumb(&mut self, ctx: &egui::Context, path: &str) -> Option { + pub(super) fn thumb(&mut self, ctx: &egui::Context, path: &str) -> Option { if let Some(t) = self.att.thumbs.get(path) { return t.clone(); } diff --git a/src/app/layout_audit.rs b/src/app/layout_audit.rs index 5482bcb..766eefd 100644 --- a/src/app/layout_audit.rs +++ b/src/app/layout_audit.rs @@ -154,6 +154,12 @@ fn scenes() -> Vec<(&'static str, Open)> { ), ("設定 › 模型", tab(SettingsTab::Providers)), ("設定 › 個人資料", tab(SettingsTab::Me)), + ( + "所有檔案", + Box::new(|a: &mut App| { + a.lib.open = true; + }), + ), // A screen of a brain: each page says at its top whose settings it holds (the longest // sentences are these two). ("設定 › 一般(螢幕電腦)", screen_of_brain(SettingsTab::General)), diff --git a/src/app/library_ui.rs b/src/app/library_ui.rs new file mode 100644 index 0000000..2bcc1e5 --- /dev/null +++ b/src/app/library_ui.rs @@ -0,0 +1,301 @@ +// 所有檔案 (plan C6, laid out like OpenBot's library): every file the bots handed over or were +// given, across bots and conversations, from the attachments the chats already keep — nothing on +// disk is scanned. By kind (圖片、文件、程式碼、表格、影音、其他, each with its count), by bot, the +// last 7 days, a search; as cards or a list; each still there or gone; opened in AnyBot's own +// viewer (files_ui). Gathered when the window opens and again every few seconds while it shows. + +use super::*; + +#[derive(Default)] +pub(super) struct LibraryUi { + pub open: bool, + files: Vec, + pub at: Option, + kind: &'static str, + place: Place, + query: String, + list: bool, +} + +#[derive(Default, Clone, Copy, PartialEq)] +enum Place { + #[default] + All, + Recent, + Bot(u64), +} + +#[derive(Clone)] +struct Item { + name: String, + path: String, + bot: u64, + at: i64, + bytes: u64, + kind: &'static str, + there: bool, + image: bool, +} + +const KINDS: [(&str, &str); 7] = [("all", "全部"), ("image", "圖片"), ("doc", "文件"), ("code", "程式碼"), ("sheet", "表格"), ("media", "影音"), ("other", "其他")]; +const EVERY_SECS: u64 = 5; +const CARD_W: f32 = 168.0; +const CARD_H: f32 = 156.0; +const CODE_EXT: &[&str] = &[ + "rs", "py", "pyi", "js", "jsx", "mjs", "cjs", "ts", "tsx", "go", "java", "kt", "swift", "c", "h", "cc", "cpp", "hpp", "m", "mm", "rb", "php", "sh", "bash", "zsh", "fish", "ps1", "lua", "sql", "css", "scss", "vue", "svelte", "json", "jsonl", + "yaml", "yml", "toml", "xml", +]; + +/// A file's kind in the library: 圖片、文件、程式碼、表格、影音、其他. +pub(super) fn library_kind(name: &str) -> &'static str { + let ext = name.rsplit_once('.').map(|(_, e)| e.to_lowercase()).unwrap_or_default(); + match crate::preview::kind_of(name) { + "image" => "image", + "video" | "audio" => "media", + "sheet" => "sheet", + _ if CODE_EXT.contains(&ext.as_str()) => "code", + "markdown" | "docx" | "doc" | "pdf" | "html" | "text" => "doc", + _ => "other", + } +} + +impl App { + fn library_gather(&mut self) { + let mut seen = std::collections::HashSet::new(); + let mut files = vec![]; + for b in &self.state.bots { + let all = b.messages.iter().chain(b.threads.iter().flat_map(|(_, m)| m.iter())); + for m in all { + for a in &m.attachments { + if a.path.is_empty() || !seen.insert(a.path.clone()) { + continue; + } + files.push(Item { name: a.name.clone(), path: a.path.clone(), bot: b.id, at: m.at, bytes: a.bytes, kind: library_kind(&a.name), there: std::path::Path::new(&a.path).exists(), image: a.image }); + } + } + } + files.sort_by_key(|f| std::cmp::Reverse(f.at)); + self.lib.files = files; + self.lib.at = Some(Instant::now()); + } + + /// The window. + pub(super) fn library_window(&mut self, ctx: &egui::Context) { + if !self.lib.open { + return; + } + if self.lib.at.is_none_or(|t| t.elapsed().as_secs() >= EVERY_SECS) { + self.library_gather(); + } + if self.lib.kind.is_empty() { + self.lib.kind = "all"; + } + let p = self.pal; + let body_h = dialog_max_height(ctx) - 48.0; + let names: HashMap = self.state.bots.iter().map(|b| (b.id, (b.name.clone(), self.bot_color(b)))).collect(); + let week = crate::model::now_ms() - 7 * 86_400_000; + let q = self.lib.query.trim().to_lowercase(); + let in_place = |f: &Item, place: Place| match place { + Place::All => true, + Place::Recent => f.at >= week, + Place::Bot(id) => f.bot == id, + }; + let mut open: Option<(String, String)> = None; + let closed = dialog(ctx, "library", "所有檔案", 960.0, true, p, |ui| { + // (The left column keeps off the dialog's edge; the right one's files get their margin + // from dialog_body, and the kinds above them take the same.) + Frame::new().inner_margin(Margin { left: 16, right: 0, top: 10, bottom: 0 }).show(ui, |ui| { + ui.horizontal_top(|ui| { + // Left: the search, where, each bot. + ui.vertical(|ui| { + ui.set_width(200.0); + ui.add(egui::TextEdit::singleline(&mut self.lib.query).hint_text(t("搜尋檔案名稱")).desired_width(196.0)); + ui.add_space(8.0); + let count = |place: Place| self.lib.files.iter().filter(|f| in_place(f, place)).count(); + let mut pick: Option = None; + let mut row = |ui: &mut egui::Ui, place: Place, label: &str, dot: Option, n: usize, cur: Place| { + let (rect, r) = ui.allocate_exact_size(vec2(196.0, 30.0), egui::Sense::click()); + if cur == place || r.hovered() { + ui.painter().rect_filled(rect, R_M, if cur == place { p.active } else { p.hover }); + } + let mut x = rect.left() + 10.0; + if let Some(c) = dot { + ui.painter().circle_filled(egui::pos2(x + 5.0, rect.center().y), 5.0, c); + x += 16.0; + } + let label = super::sidebar_ui::shorten_width(ui, label, 196.0 - (x - rect.left()) - 40.0, FONT_SM); + ui.painter().text(egui::pos2(x, rect.center().y), egui::Align2::LEFT_CENTER, label, egui::FontId::proportional(FONT_SM), p.text); + ui.painter().text(rect.right_center() - vec2(10.0, 0.0), egui::Align2::RIGHT_CENTER, n.to_string(), egui::FontId::proportional(FONT_XS), p.text3); + if r.on_hover_cursor(egui::CursorIcon::PointingHand).clicked() { + pick = Some(place); + } + }; + let cur = self.lib.place; + row(ui, Place::All, &t("所有檔案"), None, count(Place::All), cur); + row(ui, Place::Recent, &t("最近 7 天"), None, count(Place::Recent), cur); + ui.add_space(10.0); + ui.label(RichText::new(t("Bot")).size(FONT_XS).color(p.text3)); + let mut bots: Vec<(u64, String, Color32, usize)> = names.iter().map(|(id, (n, c))| (*id, n.clone(), *c, count(Place::Bot(*id)))).filter(|b| b.3 > 0).collect(); + bots.sort_by_key(|b| (std::cmp::Reverse(b.3), b.1.clone())); + for (id, n, c, k) in bots { + row(ui, Place::Bot(id), &n, Some(c), k, cur); + } + if let Some(pl) = pick { + self.lib.place = pl; + } + }); + ui.add_space(12.0); + // Right: the kinds, the view, the files. (Given its height: a column in a row only + // gets the row's, and the files would scroll in a strip.) + ui.allocate_ui_with_layout(vec2(ui.available_width(), body_h - 20.0), Layout::top_down(Align::Min), |ui| { + // One height whatever is shown: switching kinds or views doesn't make the + // window jump. + ui.set_min_height(body_h - 20.0); + let here: Vec<&Item> = self.lib.files.iter().filter(|f| in_place(f, self.lib.place) && (q.is_empty() || f.name.to_lowercase().contains(&q))).collect(); + Frame::new().inner_margin(Margin { left: 20, right: 20, top: 0, bottom: 0 }).show(ui, |ui| { + ui.horizontal_wrapped(|ui| { + for (k, label) in KINDS { + let n = here.iter().filter(|f| k == "all" || f.kind == k).count(); + if n == 0 && k != "all" { + continue; + } + let on = self.lib.kind == k; + let text = RichText::new(format!("{} {n}", t(label))).size(FONT_SM).color(if on { p.text } else { p.text2 }); + if ui.add(egui::Button::new(if on { text.strong() } else { text }).fill(if on { p.active } else { Color32::TRANSPARENT }).corner_radius(R_M)).clicked() { + self.lib.kind = k; + } + } + ui.with_layout(Layout::right_to_left(Align::Center), |ui| { + if let Some(v) = segmented(ui, p, self.lib.list, &[(false, "格子"), (true, "清單")]) { + self.lib.list = v; + } + }); + }); + }); + ui.add_space(8.0); + let shown: Vec = here.into_iter().filter(|f| self.lib.kind == "all" || f.kind == self.lib.kind).cloned().collect(); + dialog_body(ui, "library-body", body_h - 60.0, |ui| { + if shown.is_empty() { + hint(ui, if self.lib.files.is_empty() { "還沒有檔案。Bot 交給你的、你傳給 Bot 的檔案都會出現在這裡。" } else { "沒有符合的檔案" }, p); + return; + } + if self.lib.list { + for f in &shown { + if self.library_row(ui, f, &names) { + open = Some((f.name.clone(), f.path.clone())); + } + } + } else { + // As many as fit, widened to fill the row. + let avail = ui.available_width(); + let cols = ((avail + 10.0) / (CARD_W + 10.0)).floor().max(1.0) as usize; + let w = ((avail - 10.0 * (cols - 1) as f32) / cols as f32).floor(); + for chunk in shown.chunks(cols) { + ui.horizontal(|ui| { + ui.spacing_mut().item_spacing.x = 10.0; + for f in chunk { + if self.library_card(ui, f, w, &names) { + open = Some((f.name.clone(), f.path.clone())); + } + } + }); + ui.add_space(10.0); + } + } + }); + }); + }); + }); + }); + if let Some((name, path)) = open { + self.open_file(&name, &path); + } + if closed { + self.lib.open = false; + } + } + + /// One file as a card: the picture (or its kind), the name, whose and when; a gone one says so. + fn library_card(&mut self, ui: &mut egui::Ui, f: &Item, w: f32, names: &HashMap) -> bool { + let p = self.pal; + let (rect, r) = ui.allocate_exact_size(vec2(w, CARD_H), if f.there { egui::Sense::click() } else { egui::Sense::hover() }); + ui.painter().rect_filled(rect, R_L, if r.hovered() && f.there { p.hover } else { p.elevated }); + ui.painter().rect_stroke(rect, R_L, Stroke::new(1.0, p.border), egui::StrokeKind::Inside); + let top = egui::Rect::from_min_size(rect.min + vec2(8.0, 8.0), vec2(w - 16.0, 96.0)); + let ctx = ui.ctx().clone(); + let thumb = if f.image && f.there { self.thumb(&ctx, &f.path) } else { None }; + match thumb { + Some(tex) => { + let s = tex.size_vec2(); + let k = (top.width() / s.x).max(top.height() / s.y); + let shown = s * k; + let uv = egui::Rect::from_center_size(egui::pos2(0.5, 0.5), vec2(top.width() / shown.x, top.height() / shown.y)); + egui::Image::new((tex.id(), top.size())).uv(uv).corner_radius(R_M).paint_at(ui, top); + } + None => { + ui.painter().rect_filled(top, R_M, p.hover); + let ext = f.name.rsplit_once('.').map(|(_, e)| e.to_uppercase()).unwrap_or_else(|| "FILE".into()); + ui.painter().text(top.center(), egui::Align2::CENTER_CENTER, ext.chars().take(5).collect::(), egui::FontId::new(FONT_H3, crate::bold()), p.text2); + } + } + let name = super::sidebar_ui::shorten_width(ui, &f.name, w - 16.0, FONT_SM); + ui.painter().text(egui::pos2(rect.left() + 8.0, top.bottom() + 10.0), egui::Align2::LEFT_TOP, name, egui::FontId::proportional(FONT_SM), if f.there { p.text } else { p.text3 }); + let sub = if f.there { format!("{} · {}", names.get(&f.bot).map(|x| x.0.as_str()).unwrap_or("?"), when_words(f.at)) } else { t("不見了(檔案已經刪掉或搬走)") }; + let sub = super::sidebar_ui::shorten_width(ui, &sub, w - 16.0, FONT_XS); + ui.painter().text(egui::pos2(rect.left() + 8.0, top.bottom() + 30.0), egui::Align2::LEFT_TOP, sub, egui::FontId::proportional(FONT_XS), if f.there { p.text3 } else { p.danger }); + let tip = format!("{}\n{}{}", f.name, f.path, if f.bytes > 0 { format!("\n{}", size_words(f.bytes)) } else { String::new() }); + r.on_hover_text(tip).clicked() + } + + /// One file as a row (the list view). + fn library_row(&mut self, ui: &mut egui::Ui, f: &Item, names: &HashMap) -> bool { + let p = self.pal; + let (rect, r) = ui.allocate_exact_size(vec2(ui.available_width(), 34.0), if f.there { egui::Sense::click() } else { egui::Sense::hover() }); + if r.hovered() && f.there { + ui.painter().rect_filled(rect, R_M, p.hover); + } + super::panel_ui::file_glyph(ui.painter(), egui::Rect::from_center_size(rect.left_center() + vec2(16.0, 0.0), vec2(16.0, 18.0)), &f.name, p); + let right = if f.there { format!("{} · {} · {}", names.get(&f.bot).map(|x| x.0.as_str()).unwrap_or("?"), when_words(f.at), size_words(f.bytes)) } else { t("不見了") }; + let rw = super::panel_ui::text_width(ui, &right, FONT_XS) + 12.0; + let name = super::sidebar_ui::shorten_width(ui, &f.name, rect.width() - 40.0 - rw, FONT_SM); + ui.painter().text(rect.left_center() + vec2(32.0, 0.0), egui::Align2::LEFT_CENTER, name, egui::FontId::proportional(FONT_SM), if f.there { p.text } else { p.text3 }); + ui.painter().text(rect.right_center() - vec2(8.0, 0.0), egui::Align2::RIGHT_CENTER, right, egui::FontId::proportional(FONT_XS), if f.there { p.text3 } else { p.danger }); + r.on_hover_text(&f.path).clicked() + } +} + +/// 11/20, 今天 14:05. +fn when_words(ms: i64) -> String { + use chrono::TimeZone; + let Some(d) = chrono::Local.timestamp_millis_opt(ms).single() else { return String::new() }; + if d.date_naive() == chrono::Local::now().date_naive() { + format!("今天 {}", d.format("%H:%M")) + } else { + d.format("%-m/%-d").to_string() + } +} + +/// 812 B, 4.2 KB, 1.3 MB. +fn size_words(b: u64) -> String { + match b { + 0 => String::new(), + 1..=1023 => format!("{b} B"), + 1024..=1_048_575 => format!("{:.1} KB", b as f64 / 1024.0), + _ => format!("{:.1} MB", b as f64 / 1_048_576.0), + } +} + +#[cfg(test)] +mod tests { + use super::library_kind as k; + + #[test] + fn files_are_sorted_into_kinds() { + assert_eq!((k("a.PNG"), k("b.heic"), k("c.mp4"), k("d.m4a")), ("image", "image", "media", "media")); + assert_eq!((k("e.xlsx"), k("f.csv")), ("sheet", "sheet")); + assert_eq!((k("g.md"), k("h.pdf"), k("i.docx"), k("j.txt"), k("k.html")), ("doc", "doc", "doc", "doc", "doc")); + assert_eq!((k("l.rs"), k("m.py"), k("n.json"), k("o.yaml")), ("code", "code", "code", "code")); + assert_eq!((k("p.zip"), k("noext")), ("other", "other")); + assert_eq!((super::size_words(0), super::size_words(812), super::size_words(4_300), super::size_words(1_363_149)), ("".into(), "812 B".into(), "4.2 KB".into(), "1.3 MB".into())); + } +} diff --git a/src/app/panel_ui.rs b/src/app/panel_ui.rs index 19085ee..92dfc7b 100644 --- a/src/app/panel_ui.rs +++ b/src/app/panel_ui.rs @@ -595,7 +595,7 @@ fn trim_rate(r: f32) -> String { s.trim_end_matches('0').trim_end_matches('.').to_string() } -fn text_width(ui: &egui::Ui, s: &str, size: f32) -> f32 { +pub(super) fn text_width(ui: &egui::Ui, s: &str, size: f32) -> f32 { ui.painter().layout_no_wrap(s.to_string(), egui::FontId::proportional(size), Color32::WHITE).size().x } @@ -623,7 +623,7 @@ pub(super) fn shorten_size(ui: &egui::Ui, s: &str, max_w: f32, size: f32) -> Str } /// A small mark for the file's kind (the same Lucide icons as the cards). -fn file_glyph(painter: &egui::Painter, r: egui::Rect, name: &str, p: Palette) { +pub(super) fn file_glyph(painter: &egui::Painter, r: egui::Rect, name: &str, p: Palette) { let col = match crate::preview::kind_of(name) { "sheet" => Color32::from_rgb(0x1f, 0xb3, 0x5d), "markdown" => Color32::from_rgb(0x8b, 0x5c, 0xf6), diff --git a/src/app/sidebar_ui.rs b/src/app/sidebar_ui.rs index 8ceaf2f..f5e640e 100644 --- a/src/app/sidebar_ui.rs +++ b/src/app/sidebar_ui.rs @@ -299,6 +299,11 @@ impl App { } // 任務: every bot's tasks and how each stands (tasks_ui.rs). self.tasks_button(ui); + // 所有檔案: every file of every bot (library_ui.rs). + if pill_icon(ui, crate::icons::Icon::Folder, p).on_hover_text(t("所有檔案")).clicked() { + self.lib.open = true; + self.lib.at = None; + } }); }); if self.search_open || !self.search.is_empty() { @@ -995,6 +1000,11 @@ impl App { ui.close(); } menu_ui::sep(ui, p); + if menu_ui::item(ui, p, crate::icons::Icon::Folder, "所有檔案…").clicked() { + self.lib.open = true; + self.lib.at = None; + ui.close(); + } if menu_ui::item(ui, p, crate::icons::Icon::Person, "個人資料與用量…").clicked() { self.show_settings = true; self.settings_tab = SettingsTab::Me; diff --git a/src/featuremap.rs b/src/featuremap.rs index 88b71c8..65af9b1 100644 --- a/src/featuremap.rs +++ b/src/featuremap.rs @@ -53,6 +53,7 @@ pub const AREAS: &[Area] = &[ area!("box", "Bot 的電腦"), area!("files", "檔案與指令"), area!("deliver", "交出結果:傳檔、打開、發佈網站"), + area!("library", "所有檔案"), area!("claims", "完成宣稱檢查"), area!("browser", "瀏覽器"), area!("screen", "螢幕操作"),