AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
// 手機與帳號 in the window: what the phone sees (published when something changes), carrying out
|
|
|
|
|
|
// what the phone asks, and the settings page (phone password, account at the relay, backups,
|
|
|
|
|
|
// 裝置連結).
|
|
|
|
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
|
|
use crate::remote::{self, Cmd, Settings};
|
|
|
|
|
|
use serde_json::json;
|
|
|
|
|
|
use std::hash::{Hash, Hasher};
|
|
|
|
|
|
|
Clippy is clean on macOS and Linux, for the app and the relay
Every warning `cargo clippy --all-targets` gave (50 on macOS, 8 more only on
Linux, 1 in the relay), fixed without changing what anything does:
- long types get a name (Peer, Members, Imported, Joining, Mention, Stream…);
- the two big enum variants are boxed (the vault's login plan, joining an
account);
- a test now waits for the copy it relaunched (it left a zombie behind);
- a hint's format had a dead `if` whose two branches were both "";
- the rest is what clippy suggests: sort_by_key, as_chunks, is_none_or,
is_multiple_of, while let, from_ref, next_back, struct init, no casts to
the same type.
Checked: cargo test (177 macOS, 181 Linux), relay tests (11), remote_e2e
28/28, and the live Linux test (X11; Wayland clicks, keys, Chinese typing,
scroll and screenshots).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-07 02:10:28 +00:00
|
|
|
|
/// 團隊 as the relay answered: each (user, role), or why it could not be loaded.
|
|
|
|
|
|
type Members = Result<Vec<(String, String)>, String>;
|
|
|
|
|
|
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
#[derive(Default)]
|
|
|
|
|
|
pub struct RemoteUi {
|
|
|
|
|
|
sig: u64,
|
|
|
|
|
|
last_publish: Option<Instant>,
|
|
|
|
|
|
/// The settings the server threads were last given.
|
|
|
|
|
|
pushed: Option<Settings>,
|
Voice: its own 設定 › 語音, run by the brain for every screen and the phone
Voice was three implementations that broke on their own: speech to text
borrowed the OpenAI key (so with only Grok set up the mic recorded,
then failed), OpenAI's models it hard-coded stop on 2027-02-26, read
aloud was macOS `say` or espeak-ng (silently nothing on Windows, where
espeak isn't installed), and the phone used the browser's own
recognition. Now:
- 設定 › 語音 has 聽 and 說, each a service: off, OpenAI-compatible
(OpenAI, Groq, a Whisper server of your own: the address decides),
xAI or ElevenLabs. An empty key borrows 設定 › 模型's for the same
service. Each side says 可以用 or what it lacks; 聽 has 試試看
(record a sentence, show what was heard), 說 has 試聽 and the voice
list. speech.rs does the calls; xAI's both ways were checked for real
(Mandarin read, then heard back, in Traditional characters).
- The brain does it all: the phone POSTs its recording (MediaRecorder)
to /api/voice/transcribe, screens to /api/sync/voice/transcribe;
answers come back as MP3 from …/voice/speech and are played on the
device (rodio; an <audio> on the phone, 「唸出來」 in a message's
menu). Keys stay on the brain (the voice keys are redacted for
screens like the others).
- No service, no voice anywhere: the mic, 語音聊天, 會議錄音 and 朗讀
only appear once 聽 (and 說) can be called; the phone's state says
which. Without voice the send arrow just rests where 語音聊天 was.
- 會議錄音 is uploaded to the brain, which turns it into text in the
background and hands it to the bot itself: a meeting is longer than
the 35 s the account lets a request wait, and a brain on a server has
no window (the jobs are polled in background()).
- Recognisers answer Mandarin in Simplified: in a Traditional Chinese
window or phone the text becomes Traditional with Taiwan wording.
- Older saves: whoever had an OpenAI key keeps voice input (聽 =
OpenAI); everyone else starts with it off. Bots' macOS voice names
are cleared. 對話詳細資訊's 加入會議 started plain voice input; it
starts a meeting now.
2026-11-10 14:58:18 +00:00
|
|
|
|
/// And the voice service.
|
|
|
|
|
|
voice: crate::speech::Engines,
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
pw1: String,
|
|
|
|
|
|
pw2: String,
|
|
|
|
|
|
relay_url: String,
|
|
|
|
|
|
user: String,
|
|
|
|
|
|
pass: String,
|
|
|
|
|
|
invite: String,
|
|
|
|
|
|
create: bool,
|
Bug sweep: gates, relay 2FA, Windows input, snapshots, encodings
Permissions and reach
- a file leaving a computer passes the same questions as reading it;
"looking" shell commands that do more than look ask first
- a symlink out of the work/sealed folder counts as outside it
(real paths, not just lexical ones); the search walk skips links
- web_fetch and skill_install read the public web only: localhost, the
LAN and cloud metadata are refused, at every redirect
- preview shows a file without running it; browser_upload may ask
- vault: logins no longer match across shared suffixes (pages.dev,
com.tw, ...); registrable_domain knows public suffixes
- axwrite: found elements are retained (use-after-free)
Relay
- replacing or turning off 2FA needs the current code (rate-limited);
new recovery codes only count once enrollment is verified
- a removed computer loses its socket and its `call` access
- a site name taken by another account answers 409
- RELAY_TRUST_PROXY: the login lock counts the caller's address, not
the proxy's (compose files and README)
- httpd: half a body is not a request
Desktop
- sign-in, join and restore work with 2FA on (code field; --serve reads
ANYBOT_ACCOUNT_CODE; the setup wizard points to a pairing code)
- Windows: text was typed twice; modifiers are held through click, drag
and scroll; horizontal scroll; screen control is no longer refused
- a recording that hits the limit is transcribed, not thrown away
- bot's computer: a new home volume restores the snapshot; a snapshot
is read through before the home is wiped; a failed volume removal
stops reset/restore
- events of a stopped turn no longer land in the next one; each channel
message gets a turn of its own
- saving a bot's settings keeps what it got meanwhile (three-way merge);
a save file that cannot be read is kept
- pages in Big5/GBK/Shift_JIS are read in their own encoding
(encoding_rs); osascript output past 64 KB no longer stalls
- pick_tab keeps a job's own non-http tab; pictures larger than the
texture limit are fitted; the auto-update time field takes typing
- skills live in <data>/skills; memories are unnumbered in the prompt;
the phone may skillify and skill_install
CI
- the test step fails when the tests fail (it piped into tail)
Tests: anybot 268 passed, 27 ignored; relay 16 passed; clippy unchanged.
Not run: Windows on a real machine (win.rs type-checked alone), the
Docker paths of the bot's computer, the live accessibility writes.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-10 03:46:17 +00:00
|
|
|
|
/// 兩步驗證: the code that goes with the password, asked once the account said it has it on.
|
|
|
|
|
|
code: String,
|
|
|
|
|
|
need_code: bool,
|
2026-11-05 06:25:01 +00:00
|
|
|
|
pub(super) note: Arc<Mutex<String>>,
|
|
|
|
|
|
join_rx: Option<Receiver<Result<(Settings, remote::AccountFind), String>>>,
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
restore_rx: Option<Receiver<Result<Vec<u8>, String>>>,
|
|
|
|
|
|
busy: Arc<AtomicBool>,
|
|
|
|
|
|
peers: Arc<Mutex<Vec<(String, String, bool)>>>,
|
|
|
|
|
|
last_seen_mark: Option<Instant>,
|
|
|
|
|
|
peers_at: Option<Instant>,
|
|
|
|
|
|
/// 團隊: (user, role) shared with, loaded from the relay; the form to add one.
|
Clippy is clean on macOS and Linux, for the app and the relay
Every warning `cargo clippy --all-targets` gave (50 on macOS, 8 more only on
Linux, 1 in the relay), fixed without changing what anything does:
- long types get a name (Peer, Members, Imported, Joining, Mention, Stream…);
- the two big enum variants are boxed (the vault's login plan, joining an
account);
- a test now waits for the copy it relaunched (it left a zombie behind);
- a hint's format had a dead `if` whose two branches were both "";
- the rest is what clippy suggests: sort_by_key, as_chunks, is_none_or,
is_multiple_of, while let, from_ref, next_back, struct init, no casts to
the same type.
Checked: cargo test (177 macOS, 181 Linux), relay tests (11), remote_e2e
28/28, and the live Linux test (X11; Wayland clicks, keys, Chinese typing,
scroll and screenshots).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-07 02:10:28 +00:00
|
|
|
|
members: Arc<Mutex<Option<Members>>>,
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
new_member: String,
|
|
|
|
|
|
new_admin: bool,
|
|
|
|
|
|
started: bool,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Approvals as the phone shows them.
|
|
|
|
|
|
fn approval_json(bot: &Bot, a: &Approval) -> serde_json::Value {
|
|
|
|
|
|
let what = remote::tool_label(&a.tool);
|
|
|
|
|
|
let title = match a.kind {
|
|
|
|
|
|
ApprovalKind::EnableTools => format!("允許 {} 使用電腦工具嗎?", bot.name),
|
|
|
|
|
|
ApprovalKind::EnableThisComputer => format!("允許 {} 在你的電腦上執行任務嗎?", bot.name),
|
|
|
|
|
|
ApprovalKind::Action => format!("{} 想要{what}", bot.name),
|
2026-11-05 09:29:55 +00:00
|
|
|
|
ApprovalKind::Handoff => format!("{}:需要你", bot.name),
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
};
|
2026-11-05 09:29:55 +00:00
|
|
|
|
let handoff = a.kind == ApprovalKind::Handoff;
|
|
|
|
|
|
json!({"bot": bot.id, "title": title, "reason": a.reason, "tool": a.tool, "can_always": !handoff && (a.kind != ApprovalKind::Action || !a.grant.is_empty()), "kind": if handoff { "handoff" } else { "ask" }, "computer": if handoff { a.grant.as_str() } else { "" }})
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl App {
|
|
|
|
|
|
pub(super) fn remote_start(&mut self, ctx: &egui::Context) {
|
|
|
|
|
|
if self.demo || self.rm.started {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
self.rm.started = true;
|
2026-11-04 09:46:43 +00:00
|
|
|
|
self.ctx_handle = Some(ctx.clone());
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let c = ctx.clone();
|
|
|
|
|
|
remote::hub().set_repaint(Arc::new(move || c.request_repaint()));
|
|
|
|
|
|
self.remote_apply_settings();
|
2026-11-04 09:46:43 +00:00
|
|
|
|
self.mirror_boot();
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Hand changed settings to the server threads (and restart what depends on them).
|
|
|
|
|
|
fn remote_apply_settings(&mut self) {
|
|
|
|
|
|
let s = self.state.remote.clone();
|
|
|
|
|
|
if self.rm.pushed.as_ref() == Some(&s) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let old = self.rm.pushed.replace(s.clone());
|
|
|
|
|
|
remote::hub().set_settings(&s);
|
|
|
|
|
|
let lan_changed = old.as_ref().map(|o| o.lan) != Some(s.lan);
|
|
|
|
|
|
if lan_changed {
|
|
|
|
|
|
match remote::set_lan(s.lan) {
|
|
|
|
|
|
Ok(_) => {}
|
|
|
|
|
|
Err(e) => *self.rm.note.lock().unwrap() = e,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
let relay_changed = old.as_ref().map(|o| (o.relay_url.clone(), o.host_token.clone())) != Some((s.relay_url.clone(), s.host_token.clone()));
|
|
|
|
|
|
if relay_changed {
|
|
|
|
|
|
remote::relay_restart(&s);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Every frame: run what the phone asked and refresh what it sees.
|
|
|
|
|
|
pub(super) fn remote_tick(&mut self, ctx: &egui::Context) {
|
|
|
|
|
|
if self.demo {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
self.remote_apply_settings();
|
Voice: its own 設定 › 語音, run by the brain for every screen and the phone
Voice was three implementations that broke on their own: speech to text
borrowed the OpenAI key (so with only Grok set up the mic recorded,
then failed), OpenAI's models it hard-coded stop on 2027-02-26, read
aloud was macOS `say` or espeak-ng (silently nothing on Windows, where
espeak isn't installed), and the phone used the browser's own
recognition. Now:
- 設定 › 語音 has 聽 and 說, each a service: off, OpenAI-compatible
(OpenAI, Groq, a Whisper server of your own: the address decides),
xAI or ElevenLabs. An empty key borrows 設定 › 模型's for the same
service. Each side says 可以用 or what it lacks; 聽 has 試試看
(record a sentence, show what was heard), 說 has 試聽 and the voice
list. speech.rs does the calls; xAI's both ways were checked for real
(Mandarin read, then heard back, in Traditional characters).
- The brain does it all: the phone POSTs its recording (MediaRecorder)
to /api/voice/transcribe, screens to /api/sync/voice/transcribe;
answers come back as MP3 from …/voice/speech and are played on the
device (rodio; an <audio> on the phone, 「唸出來」 in a message's
menu). Keys stay on the brain (the voice keys are redacted for
screens like the others).
- No service, no voice anywhere: the mic, 語音聊天, 會議錄音 and 朗讀
only appear once 聽 (and 說) can be called; the phone's state says
which. Without voice the send arrow just rests where 語音聊天 was.
- 會議錄音 is uploaded to the brain, which turns it into text in the
background and hands it to the bot itself: a meeting is longer than
the 35 s the account lets a request wait, and a brain on a server has
no window (the jobs are polled in background()).
- Recognisers answer Mandarin in Simplified: in a Traditional Chinese
window or phone the text becomes Traditional with Taiwan wording.
- Older saves: whoever had an OpenAI key keeps voice input (聽 =
OpenAI); everyone else starts with it off. Bots' macOS voice names
are cleared. 對話詳細資訊's 加入會議 started plain voice input; it
starts a meeting now.
2026-11-10 14:58:18 +00:00
|
|
|
|
// 設定 › 語音 with its keys, for the phone's and the screens' recordings.
|
|
|
|
|
|
let voice = crate::speech::Engines::of(&self.state);
|
|
|
|
|
|
if self.rm.voice != voice {
|
|
|
|
|
|
remote::hub().set_voice(voice.clone());
|
|
|
|
|
|
self.rm.voice = voice;
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
for c in remote::hub().take_cmds() {
|
2026-11-04 09:46:43 +00:00
|
|
|
|
// A screen of another brain has no bots of its own to run phone requests on.
|
|
|
|
|
|
if self.mir.on && !matches!(c, Cmd::DeviceAdded(_) | Cmd::DeviceSeen(_)) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
self.remote_cmd(ctx, c);
|
|
|
|
|
|
}
|
The phone page does what the desktop does, laid out like it
A new mobile/index.html in the desktop's (and Grok Bot's) shape: the sidebar
with its sections and folders, the chat with steps, thinking, reactions, quotes
and the approval card, 對話詳細資訊, Bot 設定, routines, pages, computers and
設定. Each action goes to the desktop's own code on the app's thread
(api/act/<what> -> App::phone_act): appctl, set_pinned, restart_bot,
toggle_reaction, box_task, channels_restart and the rest. No new rules.
Keys, channel tokens and the vault never reach the phone; a model key can only
be written. Admins keep what the phone always let them do; making, changing or
deleting bots, routines, memories, pages, folders and settings stays the
owner's. The state the phone polls now carries the sidebar's section order.
Checked by using it on a preview brain: routines, memories, templates, folders,
keys, signing another phone out, approvals and a chat with a fake model.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 19:05:12 +00:00
|
|
|
|
self.brain_serve(ctx);
|
2026-11-04 09:46:43 +00:00
|
|
|
|
self.brain_watch();
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
if let Some(rx) = &self.rm.join_rx {
|
|
|
|
|
|
if let Ok(r) = rx.try_recv() {
|
|
|
|
|
|
self.rm.join_rx = None;
|
|
|
|
|
|
match r {
|
2026-11-05 06:25:01 +00:00
|
|
|
|
Ok((s, found)) => {
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
self.state.remote = s;
|
|
|
|
|
|
self.rm.pass.clear();
|
Bug sweep: gates, relay 2FA, Windows input, snapshots, encodings
Permissions and reach
- a file leaving a computer passes the same questions as reading it;
"looking" shell commands that do more than look ask first
- a symlink out of the work/sealed folder counts as outside it
(real paths, not just lexical ones); the search walk skips links
- web_fetch and skill_install read the public web only: localhost, the
LAN and cloud metadata are refused, at every redirect
- preview shows a file without running it; browser_upload may ask
- vault: logins no longer match across shared suffixes (pages.dev,
com.tw, ...); registrable_domain knows public suffixes
- axwrite: found elements are retained (use-after-free)
Relay
- replacing or turning off 2FA needs the current code (rate-limited);
new recovery codes only count once enrollment is verified
- a removed computer loses its socket and its `call` access
- a site name taken by another account answers 409
- RELAY_TRUST_PROXY: the login lock counts the caller's address, not
the proxy's (compose files and README)
- httpd: half a body is not a request
Desktop
- sign-in, join and restore work with 2FA on (code field; --serve reads
ANYBOT_ACCOUNT_CODE; the setup wizard points to a pairing code)
- Windows: text was typed twice; modifiers are held through click, drag
and scroll; horizontal scroll; screen control is no longer refused
- a recording that hits the limit is transcribed, not thrown away
- bot's computer: a new home volume restores the snapshot; a snapshot
is read through before the home is wiped; a failed volume removal
stops reset/restore
- events of a stopped turn no longer land in the next one; each channel
message gets a turn of its own
- saving a bot's settings keeps what it got meanwhile (three-way merge);
a save file that cannot be read is kept
- pages in Big5/GBK/Shift_JIS are read in their own encoding
(encoding_rs); osascript output past 64 KB no longer stalls
- pick_tab keeps a job's own non-http tab; pictures larger than the
texture limit are fitted; the auto-update time field takes typing
- skills live in <data>/skills; memories are unnumbered in the prompt;
the phone may skillify and skill_install
CI
- the test step fails when the tests fail (it piped into tail)
Tests: anybot 268 passed, 27 ignored; relay 16 passed; clippy unchanged.
Not run: Windows on a real machine (win.rs type-checked alone), the
Docker paths of the bot's computer, the live accessibility writes.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-10 03:46:17 +00:00
|
|
|
|
self.rm.code.clear();
|
|
|
|
|
|
self.rm.need_code = false;
|
2026-11-05 06:25:01 +00:00
|
|
|
|
self.account_sync(found);
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
self.mark();
|
|
|
|
|
|
}
|
Bug sweep: gates, relay 2FA, Windows input, snapshots, encodings
Permissions and reach
- a file leaving a computer passes the same questions as reading it;
"looking" shell commands that do more than look ask first
- a symlink out of the work/sealed folder counts as outside it
(real paths, not just lexical ones); the search walk skips links
- web_fetch and skill_install read the public web only: localhost, the
LAN and cloud metadata are refused, at every redirect
- preview shows a file without running it; browser_upload may ask
- vault: logins no longer match across shared suffixes (pages.dev,
com.tw, ...); registrable_domain knows public suffixes
- axwrite: found elements are retained (use-after-free)
Relay
- replacing or turning off 2FA needs the current code (rate-limited);
new recovery codes only count once enrollment is verified
- a removed computer loses its socket and its `call` access
- a site name taken by another account answers 409
- RELAY_TRUST_PROXY: the login lock counts the caller's address, not
the proxy's (compose files and README)
- httpd: half a body is not a request
Desktop
- sign-in, join and restore work with 2FA on (code field; --serve reads
ANYBOT_ACCOUNT_CODE; the setup wizard points to a pairing code)
- Windows: text was typed twice; modifiers are held through click, drag
and scroll; horizontal scroll; screen control is no longer refused
- a recording that hits the limit is transcribed, not thrown away
- bot's computer: a new home volume restores the snapshot; a snapshot
is read through before the home is wiped; a failed volume removal
stops reset/restore
- events of a stopped turn no longer land in the next one; each channel
message gets a turn of its own
- saving a bot's settings keeps what it got meanwhile (three-way merge);
a save file that cannot be read is kept
- pages in Big5/GBK/Shift_JIS are read in their own encoding
(encoding_rs); osascript output past 64 KB no longer stalls
- pick_tab keeps a job's own non-http tab; pictures larger than the
texture limit are fitted; the auto-update time field takes typing
- skills live in <data>/skills; memories are unnumbered in the prompt;
the phone may skillify and skill_install
CI
- the test step fails when the tests fail (it piped into tail)
Tests: anybot 268 passed, 27 ignored; relay 16 passed; clippy unchanged.
Not run: Windows on a real machine (win.rs type-checked alone), the
Docker paths of the bot's computer, the live accessibility writes.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-10 03:46:17 +00:00
|
|
|
|
Err(e) => {
|
|
|
|
|
|
self.rm.need_code |= e.starts_with(remote::NEED_CODE);
|
|
|
|
|
|
// (A code is good for one try.)
|
|
|
|
|
|
self.rm.code.clear();
|
|
|
|
|
|
*self.rm.note.lock().unwrap() = e;
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if let Some(rx) = &self.rm.restore_rx {
|
|
|
|
|
|
if let Ok(r) = rx.try_recv() {
|
|
|
|
|
|
self.rm.restore_rx = None;
|
|
|
|
|
|
match r.and_then(|bytes| serde_json::from_slice::<State>(&bytes).map_err(|e| format!("備份內容讀不出來:{e}"))) {
|
|
|
|
|
|
Ok(mut st) => {
|
|
|
|
|
|
// Keep this computer's own phone and account settings.
|
|
|
|
|
|
st.remote = self.state.remote.clone();
|
|
|
|
|
|
let n = st.bots.len();
|
|
|
|
|
|
self.state = st;
|
|
|
|
|
|
self.state.save();
|
|
|
|
|
|
*self.rm.note.lock().unwrap() = format!("已從備份還原 {n} 個 Bot");
|
|
|
|
|
|
}
|
Bug sweep: gates, relay 2FA, Windows input, snapshots, encodings
Permissions and reach
- a file leaving a computer passes the same questions as reading it;
"looking" shell commands that do more than look ask first
- a symlink out of the work/sealed folder counts as outside it
(real paths, not just lexical ones); the search walk skips links
- web_fetch and skill_install read the public web only: localhost, the
LAN and cloud metadata are refused, at every redirect
- preview shows a file without running it; browser_upload may ask
- vault: logins no longer match across shared suffixes (pages.dev,
com.tw, ...); registrable_domain knows public suffixes
- axwrite: found elements are retained (use-after-free)
Relay
- replacing or turning off 2FA needs the current code (rate-limited);
new recovery codes only count once enrollment is verified
- a removed computer loses its socket and its `call` access
- a site name taken by another account answers 409
- RELAY_TRUST_PROXY: the login lock counts the caller's address, not
the proxy's (compose files and README)
- httpd: half a body is not a request
Desktop
- sign-in, join and restore work with 2FA on (code field; --serve reads
ANYBOT_ACCOUNT_CODE; the setup wizard points to a pairing code)
- Windows: text was typed twice; modifiers are held through click, drag
and scroll; horizontal scroll; screen control is no longer refused
- a recording that hits the limit is transcribed, not thrown away
- bot's computer: a new home volume restores the snapshot; a snapshot
is read through before the home is wiped; a failed volume removal
stops reset/restore
- events of a stopped turn no longer land in the next one; each channel
message gets a turn of its own
- saving a bot's settings keeps what it got meanwhile (three-way merge);
a save file that cannot be read is kept
- pages in Big5/GBK/Shift_JIS are read in their own encoding
(encoding_rs); osascript output past 64 KB no longer stalls
- pick_tab keeps a job's own non-http tab; pictures larger than the
texture limit are fitted; the auto-update time field takes typing
- skills live in <data>/skills; memories are unnumbered in the prompt;
the phone may skillify and skill_install
CI
- the test step fails when the tests fail (it piped into tail)
Tests: anybot 268 passed, 27 ignored; relay 16 passed; clippy unchanged.
Not run: Windows on a real machine (win.rs type-checked alone), the
Docker paths of the bot's computer, the live accessibility writes.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-10 03:46:17 +00:00
|
|
|
|
Err(e) => {
|
|
|
|
|
|
self.rm.need_code |= e.starts_with(remote::NEED_CODE);
|
|
|
|
|
|
self.rm.code.clear();
|
|
|
|
|
|
*self.rm.note.lock().unwrap() = e;
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// 自動備份: once a day while signed in.
|
|
|
|
|
|
let s = &self.state.remote;
|
2026-11-04 09:46:43 +00:00
|
|
|
|
if !self.mir.on && s.auto_backup && !s.backup_key.is_empty() && !s.relay_url.is_empty() && chrono::Utc::now().timestamp() - s.last_backup > 86_400 && !self.rm.busy.load(Ordering::SeqCst) {
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
self.remote_backup();
|
|
|
|
|
|
}
|
Remote brain: a computer that just came on is known at once; an offline computer is said, not swapped; snapshots survive an open browser; end-to-end test
- The brain looked the account's computers up once a minute: for up to a minute after the Mac
came on, 「我的電腦」 was unknown and steps went elsewhere. Now every 15 s, and at once when a
message comes from a computer it doesn't know yet.
- A step naming a computer that is off says so in words instead of running on the chosen one
with a note that the person hadn't asked.
- Snapshots: tar's 'file changed' (the open browser) is not a failure; browser caches are left
out; ten minutes for a large home folder.
- box_end_to_end clicks the terminal where it opened; restore only with ANYBOT_TEST_RESTORE=1.
- deploy/test/remote_e2e.py: account server + headless brain + hands + scripted model, 27 checks
(computers, redirect, agent-desktop on the hands, hand-off 3 ways, phone view, sync copy,
edits, hands offline/back, brain restart, clear). anybot --sample-state for such tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 10:14:23 +00:00
|
|
|
|
// 裝置連結: keep the list of this account's computers fresh (every 15 s: a computer that
|
|
|
|
|
|
// comes on is one the bots can use soon after).
|
|
|
|
|
|
if !self.state.remote.host_token.is_empty() && !self.rm.peers_at.map(|t| t.elapsed().as_secs() < 15).unwrap_or(false) {
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
self.rm.peers_at = Some(Instant::now());
|
|
|
|
|
|
let (peers, s) = (self.rm.peers.clone(), self.state.remote.clone());
|
|
|
|
|
|
std::thread::spawn(move || {
|
|
|
|
|
|
let v = remote::devices_online(&s);
|
|
|
|
|
|
if !v.is_empty() {
|
|
|
|
|
|
*peers.lock().unwrap() = v;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2026-11-04 09:46:43 +00:00
|
|
|
|
if !self.mir.on && !self.rm.last_publish.map(|t| t.elapsed().as_millis() < 120).unwrap_or(false) {
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
self.remote_publish();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
One installer for every platform, first run included
install.sh now covers every common Linux distro (apt, dnf, yum, pacman,
zypper, apk, xbps), macOS on arm64/x86_64, and hands off to install.ps1
under Git Bash. install.ps1 + install.cmd give Windows a double-click.
Autostart: systemd user unit on Linux, launchd on macOS, Task Scheduler
on Windows. A terminal guides the role choice and the first key or bot;
agents get --print JSON and ANYBOT_NONINTERACTIVE=1 with env seeding.
`加一台電腦` shows the Windows and the Mac/Linux line together.
2026-11-10 06:07:01 +00:00
|
|
|
|
/// 加一台電腦: lines for Mac, any Linux (desktop or headless) and Windows. Each installs
|
|
|
|
|
|
/// AnyBot if needed and joins as hands, including the first pairing, with nothing to answer.
|
2026-11-04 12:56:06 +00:00
|
|
|
|
fn pair_section(&mut self, ui: &mut egui::Ui) {
|
|
|
|
|
|
let p = self.pal;
|
|
|
|
|
|
ui.add_space(6.0);
|
|
|
|
|
|
ui.separator();
|
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
|
ui.label(RichText::new(t("加一台電腦")).size(13.5).strong());
|
One installer for every platform, first run included
install.sh now covers every common Linux distro (apt, dnf, yum, pacman,
zypper, apk, xbps), macOS on arm64/x86_64, and hands off to install.ps1
under Git Bash. install.ps1 + install.cmd give Windows a double-click.
Autostart: systemd user unit on Linux, launchd on macOS, Task Scheduler
on Windows. A terminal guides the role choice and the first key or bot;
agents get --print JSON and ANYBOT_NONINTERACTIVE=1 with env seeding.
`加一台電腦` shows the Windows and the Mac/Linux line together.
2026-11-10 06:07:01 +00:00
|
|
|
|
help_mark(ui, "讓另一台電腦當大腦的手腳:Mac、任何 Linux(含沒有螢幕的)、已登入的 Windows。貼上對應的那一行就會裝好並完成第一次配對,不用帳號密碼。它會在開機或登入後自動執行,只讓這個大腦使用。", p);
|
2026-11-04 12:56:06 +00:00
|
|
|
|
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
|
|
|
|
|
|
if ui.add(secondary_button("產生配對碼")).clicked() {
|
|
|
|
|
|
let (s, slot) = (self.state.remote.clone(), self.mir.pair.clone());
|
|
|
|
|
|
let for_host = if self.mir.on { s.brain_id.clone() } else { s.host_id.clone() };
|
|
|
|
|
|
*slot.lock().unwrap() = (t("正在產生…"), false, None);
|
|
|
|
|
|
std::thread::spawn(move || {
|
|
|
|
|
|
*slot.lock().unwrap() = match crate::remote::pair_code(&s, &for_host) {
|
One installer for every platform, first run included
install.sh now covers every common Linux distro (apt, dnf, yum, pacman,
zypper, apk, xbps), macOS on arm64/x86_64, and hands off to install.ps1
under Git Bash. install.ps1 + install.cmd give Windows a double-click.
Autostart: systemd user unit on Linux, launchd on macOS, Task Scheduler
on Windows. A terminal guides the role choice and the first key or bot;
agents get --print JSON and ANYBOT_NONINTERACTIVE=1 with env seeding.
`加一台電腦` shows the Windows and the Mac/Linux line together.
2026-11-10 06:07:01 +00:00
|
|
|
|
Ok(code) => (crate::remote::pair_block(&s.relay_url, &code), true, Some(Instant::now())),
|
2026-11-04 12:56:06 +00:00
|
|
|
|
Err(e) => (e, false, None),
|
|
|
|
|
|
};
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
let (line, ok, at) = self.mir.pair.lock().unwrap().clone();
|
|
|
|
|
|
if line.is_empty() {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let left = at.map(|t| 600u64.saturating_sub(t.elapsed().as_secs())).unwrap_or(0);
|
|
|
|
|
|
if ok && left == 0 {
|
|
|
|
|
|
hint(ui, "配對碼過期了,再按一次「產生配對碼」。", p);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
let c = if line.ends_with('…') { p.text2 } else { p.danger };
|
|
|
|
|
|
ui.label(RichText::new(line).size(12.5).color(c));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
Frame::new().fill(p.hover).corner_radius(8).inner_margin(Margin::symmetric(10, 8)).show(ui, |ui| {
|
|
|
|
|
|
ui.horizontal(|ui| {
|
One installer for every platform, first run included
install.sh now covers every common Linux distro (apt, dnf, yum, pacman,
zypper, apk, xbps), macOS on arm64/x86_64, and hands off to install.ps1
under Git Bash. install.ps1 + install.cmd give Windows a double-click.
Autostart: systemd user unit on Linux, launchd on macOS, Task Scheduler
on Windows. A terminal guides the role choice and the first key or bot;
agents get --print JSON and ANYBOT_NONINTERACTIVE=1 with env seeding.
`加一台電腦` shows the Windows and the Mac/Linux line together.
2026-11-10 06:07:01 +00:00
|
|
|
|
ui.add(egui::Label::new(RichText::new(&line).monospace().size(12.0)).selectable(true).wrap());
|
2026-11-04 12:56:06 +00:00
|
|
|
|
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
|
|
|
|
|
|
if ui.add(secondary_button("複製")).clicked() {
|
|
|
|
|
|
ui.ctx().copy_text(line.clone());
|
One installer for every platform, first run included
install.sh now covers every common Linux distro (apt, dnf, yum, pacman,
zypper, apk, xbps), macOS on arm64/x86_64, and hands off to install.ps1
under Git Bash. install.ps1 + install.cmd give Windows a double-click.
Autostart: systemd user unit on Linux, launchd on macOS, Task Scheduler
on Windows. A terminal guides the role choice and the first key or bot;
agents get --print JSON and ANYBOT_NONINTERACTIVE=1 with env seeding.
`加一台電腦` shows the Windows and the Mac/Linux line together.
2026-11-10 06:07:01 +00:00
|
|
|
|
self.notice = Some(t("已複製。Mac 和 Linux 貼終端機那一行,Windows 貼 PowerShell 那一行"));
|
2026-11-04 12:56:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
One installer for every platform, first run included
install.sh now covers every common Linux distro (apt, dnf, yum, pacman,
zypper, apk, xbps), macOS on arm64/x86_64, and hands off to install.ps1
under Git Bash. install.ps1 + install.cmd give Windows a double-click.
Autostart: systemd user unit on Linux, launchd on macOS, Task Scheduler
on Windows. A terminal guides the role choice and the first key or bot;
agents get --print JSON and ANYBOT_NONINTERACTIVE=1 with env seeding.
`加一台電腦` shows the Windows and the Mac/Linux line together.
2026-11-10 06:07:01 +00:00
|
|
|
|
ui.label(RichText::new(format!("{}(還有 {} 分 {:02} 秒,只能用一次)", t("在那台電腦貼上對應的那一行"), left / 60, left % 60)).size(12.0).color(p.text3));
|
2026-11-04 12:56:06 +00:00
|
|
|
|
// Just made: bring it into view.
|
|
|
|
|
|
if at.map(|t| t.elapsed().as_millis() < 800).unwrap_or(false) {
|
|
|
|
|
|
ui.scroll_to_cursor(Some(Align::Max));
|
|
|
|
|
|
}
|
|
|
|
|
|
ui.ctx().request_repaint_after(std::time::Duration::from_secs(1));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
fn remote_signature(&self) -> u64 {
|
|
|
|
|
|
let mut h = std::collections::hash_map::DefaultHasher::new();
|
|
|
|
|
|
self.state.remote.host_name.hash(&mut h);
|
2026-11-06 12:33:06 +00:00
|
|
|
|
self.state.timezone.hash(&mut h);
|
2026-11-04 09:46:43 +00:00
|
|
|
|
self.scr.cfg_hash.hash(&mut h);
|
The phone page does what the desktop does, laid out like it
A new mobile/index.html in the desktop's (and Grok Bot's) shape: the sidebar
with its sections and folders, the chat with steps, thinking, reactions, quotes
and the approval card, 對話詳細資訊, Bot 設定, routines, pages, computers and
設定. Each action goes to the desktop's own code on the app's thread
(api/act/<what> -> App::phone_act): appctl, set_pinned, restart_bot,
toggle_reaction, box_task, channels_restart and the rest. No new rules.
Keys, channel tokens and the vault never reach the phone; a model key can only
be written. Admins keep what the phone always let them do; making, changing or
deleting bots, routines, memories, pages, folders and settings stays the
owner's. The state the phone polls now carries the sidebar's section order.
Checked by using it on a preview brain: routines, memories, templates, folders,
keys, signing another phone out, approvals and a chat with a fake model.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 19:05:12 +00:00
|
|
|
|
(&self.state.folders, self.state.loose_index).hash(&mut h);
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
for b in &self.state.bots {
|
|
|
|
|
|
(b.id, &b.name, &b.color, b.unread, b.messages.len()).hash(&mut h);
|
The phone page does what the desktop does, laid out like it
A new mobile/index.html in the desktop's (and Grok Bot's) shape: the sidebar
with its sections and folders, the chat with steps, thinking, reactions, quotes
and the approval card, 對話詳細資訊, Bot 設定, routines, pages, computers and
設定. Each action goes to the desktop's own code on the app's thread
(api/act/<what> -> App::phone_act): appctl, set_pinned, restart_bot,
toggle_reaction, box_task, channels_restart and the rest. No new rules.
Keys, channel tokens and the vault never reach the phone; a model key can only
be written. Admins keep what the phone always let them do; making, changing or
deleting bots, routines, memories, pages, folders and settings stays the
owner's. The state the phone polls now carries the sidebar's section order.
Checked by using it on a preview brain: routines, memories, templates, folders,
keys, signing another phone out, approvals and a chat with a fake model.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 19:05:12 +00:00
|
|
|
|
// (What the phone's home, editor and reactions show.)
|
|
|
|
|
|
(&b.description, &b.shape, b.pinned, &b.folder, b.members.len(), b.instructions.len(), b.memories.len(), b.tools_enabled).hash(&mut h);
|
|
|
|
|
|
b.messages.iter().rev().take(remote::PHONE_TAIL).map(|m| m.reactions.len()).sum::<usize>().hash(&mut h);
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
if let Some(m) = b.messages.last() {
|
2026-11-04 11:07:55 +00:00
|
|
|
|
(m.text.len(), m.thinking.len(), m.tool_calls.len(), m.error).hash(&mut h);
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
for c in &m.tool_calls {
|
|
|
|
|
|
(c.status as u8).hash(&mut h);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if let Some(l) = self.streams.get(&b.id) {
|
The phone page does what the desktop does, laid out like it
A new mobile/index.html in the desktop's (and Grok Bot's) shape: the sidebar
with its sections and folders, the chat with steps, thinking, reactions, quotes
and the approval card, 對話詳細資訊, Bot 設定, routines, pages, computers and
設定. Each action goes to the desktop's own code on the app's thread
(api/act/<what> -> App::phone_act): appctl, set_pinned, restart_bot,
toggle_reaction, box_task, channels_restart and the rest. No new rules.
Keys, channel tokens and the vault never reach the phone; a model key can only
be written. Admins keep what the phone always let them do; making, changing or
deleting bots, routines, memories, pages, folders and settings stays the
owner's. The state the phone polls now carries the sidebar's section order.
Checked by using it on a preview brain: routines, memories, templates, folders,
keys, signing another phone out, approvals and a chat with a fake model.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 19:05:12 +00:00
|
|
|
|
(1u8, &l.status, l.paused, l.steer.lock().unwrap().len()).hash(&mut h);
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
self.approvals.get(&b.id).map(|a| a.call_id.clone()).hash(&mut h);
|
Phone: a home with the computers, pages and routines; each bot's settings a tap away; long jobs fold up
The phone page was bare: one row per bot, a chat listing every step, a menu with four lines.
- Home: the main bot large at the top with its model and last words, the other bots with times,
then its computers (own box and the account's, online or not, 看畫面), the newest pages and the
routines with their next run.
- Chat: the bot's name opens its settings — model (chat models only), computer, past conversations
(restore), regenerate, new chat. A turn's steps fold into 「已完成 N 個步驟」 when done (the newest
three stay while it works); copy and regenerate under replies; four ready starts in a new chat;
a jump back to the newest message.
- Menu: 外觀 (follow the phone, light, dark).
- API: api/state carries pages and models; each bot its model, computers, routines, past
conversations; POST api/bots/{id}/set | regenerate | restore. The home's last line skips errors.
Checked on a local copy of the brain's data (cut off from the account and Docker) at iPhone size.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 12:28:08 +00:00
|
|
|
|
// The phone's home and bot sheet: its model, computer, routines and past chats.
|
|
|
|
|
|
(b.provider, &b.model, &b.default_computer, b.threads.len(), b.id == self.state.primary_bot).hash(&mut h);
|
|
|
|
|
|
for r in &b.routines {
|
|
|
|
|
|
(r.id, &r.title, r.paused, r.next_run).hash(&mut h);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for (id, _, online) in self.rm.peers.lock().unwrap().iter() {
|
|
|
|
|
|
(id, online).hash(&mut h);
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
Phone: a home with the computers, pages and routines; each bot's settings a tap away; long jobs fold up
The phone page was bare: one row per bot, a chat listing every step, a menu with four lines.
- Home: the main bot large at the top with its model and last words, the other bots with times,
then its computers (own box and the account's, online or not, 看畫面), the newest pages and the
routines with their next run.
- Chat: the bot's name opens its settings — model (chat models only), computer, past conversations
(restore), regenerate, new chat. A turn's steps fold into 「已完成 N 個步驟」 when done (the newest
three stay while it works); copy and regenerate under replies; four ready starts in a new chat;
a jump back to the newest message.
- Menu: 外觀 (follow the phone, light, dark).
- API: api/state carries pages and models; each bot its model, computers, routines, past
conversations; POST api/bots/{id}/set | regenerate | restore. The home's last line skips errors.
Checked on a local copy of the brain's data (cut off from the account and Docker) at iPhone size.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 12:28:08 +00:00
|
|
|
|
crate::cloudbox::run_state().label().hash(&mut h);
|
頁面: pages a bot makes and keeps up to date (like the original's tracking pages)
- write_page / read_page / list_pages: Markdown pages with versions (last 10 kept), per bot;
the reply gets a card (title, fading preview, page icon, 頁面 · 更新時間, 最近更新), and
[標題](page:ID) links open the page
- The page opens large: summary, what changed, the version picker, 複製 / 存成檔案 / 刪除;
listed under 資料庫 in the right panel
- Page blocks for richer pages, in the chat's Markdown too: ```stats tiles, ```steps progress,
> [!NOTE]/[!TIP]/[!WARNING]/[!IMPORTANT] call-outs (with tables and Mermaid charts)
- Phone: the card in chats, page links, a page view with the same blocks; charts drawn by the
AnyBot as SVG (GET /api/pages/<id>[/chart/<n>]); members may read pages
- Bots are told to make a page for things to track and to update it from a routine only when
there is real news
- Screenshot views: ANYBOT_SHOT_VIEW=pagecard / page
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 17:41:41 +00:00
|
|
|
|
for pg in &self.state.pages {
|
|
|
|
|
|
(pg.id, pg.revision, pg.updated, &pg.title).hash(&mut h);
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
h.finish()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn remote_publish(&mut self) {
|
|
|
|
|
|
let sig = self.remote_signature();
|
|
|
|
|
|
if sig == self.rm.sig {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
self.rm.sig = sig;
|
|
|
|
|
|
self.rm.last_publish = Some(Instant::now());
|
2026-11-06 12:33:06 +00:00
|
|
|
|
crate::routines::set_person_timezone(&self.state.timezone);
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let names: HashMap<u64, String> = self.state.bots.iter().map(|b| (b.id, b.name.clone())).collect();
|
|
|
|
|
|
let mut bots: Vec<&Bot> = self.state.bots.iter().collect();
|
|
|
|
|
|
// Pinned first, then the most recently active.
|
|
|
|
|
|
bots.sort_by_key(|b| (!b.pinned, -(b.last_turn.as_ref().map(|t| t.settled_at_ms).unwrap_or(0))));
|
The phone page does what the desktop does, laid out like it
A new mobile/index.html in the desktop's (and Grok Bot's) shape: the sidebar
with its sections and folders, the chat with steps, thinking, reactions, quotes
and the approval card, 對話詳細資訊, Bot 設定, routines, pages, computers and
設定. Each action goes to the desktop's own code on the app's thread
(api/act/<what> -> App::phone_act): appctl, set_pinned, restart_bot,
toggle_reaction, box_task, channels_restart and the rest. No new rules.
Keys, channel tokens and the vault never reach the phone; a model key can only
be written. Admins keep what the phone always let them do; making, changing or
deleting bots, routines, memories, pages, folders and settings stays the
owner's. The state the phone polls now carries the sidebar's section order.
Checked by using it on a preview brain: routines, memories, templates, folders,
keys, signing another phone out, approvals and a chat with a fake model.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 19:05:12 +00:00
|
|
|
|
let mut view = remote::View { host: self.state.remote.host_name.clone(), sections: self.section_order(), ..Default::default() };
|
Phone: a home with the computers, pages and routines; each bot's settings a tap away; long jobs fold up
The phone page was bare: one row per bot, a chat listing every step, a menu with four lines.
- Home: the main bot large at the top with its model and last words, the other bots with times,
then its computers (own box and the account's, online or not, 看畫面), the newest pages and the
routines with their next run.
- Chat: the bot's name opens its settings — model (chat models only), computer, past conversations
(restore), regenerate, new chat. A turn's steps fold into 「已完成 N 個步驟」 when done (the newest
three stay while it works); copy and regenerate under replies; four ready starts in a new chat;
a jump back to the newest message.
- Menu: 外觀 (follow the phone, light, dark).
- API: api/state carries pages and models; each bot its model, computers, routines, past
conversations; POST api/bots/{id}/set | regenerate | restore. The home's last line skips errors.
Checked on a local copy of the brain's data (cut off from the account and Docker) at iPhone size.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 12:28:08 +00:00
|
|
|
|
let peers = self.rm.peers.lock().unwrap().clone();
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
for b in bots {
|
Phone: a home with the computers, pages and routines; each bot's settings a tap away; long jobs fold up
The phone page was bare: one row per bot, a chat listing every step, a menu with four lines.
- Home: the main bot large at the top with its model and last words, the other bots with times,
then its computers (own box and the account's, online or not, 看畫面), the newest pages and the
routines with their next run.
- Chat: the bot's name opens its settings — model (chat models only), computer, past conversations
(restore), regenerate, new chat. A turn's steps fold into 「已完成 N 個步驟」 when done (the newest
three stay while it works); copy and regenerate under replies; four ready starts in a new chat;
a jump back to the newest message.
- Menu: 外觀 (follow the phone, light, dark).
- API: api/state carries pages and models; each bot its model, computers, routines, past
conversations; POST api/bots/{id}/set | regenerate | restore. The home's last line skips errors.
Checked on a local copy of the brain's data (cut off from the account and Docker) at iPhone size.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 12:28:08 +00:00
|
|
|
|
// Its computers, each as the phone shows it: what it is and whether it is there now.
|
|
|
|
|
|
let targets = self.targets_for(b);
|
|
|
|
|
|
let roles = self.roles_for(b, &targets);
|
|
|
|
|
|
let computer = Self::chosen_computer(b, &targets, &roles).0;
|
|
|
|
|
|
let computers: Vec<serde_json::Value> = targets.iter().map(|t| {
|
|
|
|
|
|
let (kind, online) = match &t.place {
|
|
|
|
|
|
tools::Place::Box { .. } => ("own", crate::cloudbox::available()),
|
|
|
|
|
|
tools::Place::Sealed { .. } => ("own", false),
|
|
|
|
|
|
tools::Place::Local { .. } => ("this", true),
|
|
|
|
|
|
tools::Place::Device { host, .. } => ("device", peers.iter().any(|(id, _, on)| id == host && *on)),
|
|
|
|
|
|
tools::Place::Ssh { .. } => ("ssh", true),
|
|
|
|
|
|
};
|
|
|
|
|
|
json!({"name": t.name, "kind": kind, "online": online, "person": roles.person.as_deref() == Some(t.name.as_str())})
|
|
|
|
|
|
}).collect();
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let live = self.streams.get(&b.id);
|
Phone: a home with the computers, pages and routines; each bot's settings a tap away; long jobs fold up
The phone page was bare: one row per bot, a chat listing every step, a menu with four lines.
- Home: the main bot large at the top with its model and last words, the other bots with times,
then its computers (own box and the account's, online or not, 看畫面), the newest pages and the
routines with their next run.
- Chat: the bot's name opens its settings — model (chat models only), computer, past conversations
(restore), regenerate, new chat. A turn's steps fold into 「已完成 N 個步驟」 when done (the newest
three stay while it works); copy and regenerate under replies; four ready starts in a new chat;
a jump back to the newest message.
- Menu: 外觀 (follow the phone, light, dark).
- API: api/state carries pages and models; each bot its model, computers, routines, past
conversations; POST api/bots/{id}/set | regenerate | restore. The home's last line skips errors.
Checked on a local copy of the brain's data (cut off from the account and Docker) at iPhone size.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 12:28:08 +00:00
|
|
|
|
// The last thing said (not an error the model service sent, which then sat on the home).
|
|
|
|
|
|
let last = b.messages.iter().rev().find(|m| !m.text.trim().is_empty() && m.role != Role::Tool && !m.error).map(|m| first_line(&m.text, 60)).unwrap_or_default();
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let c = crate::avatar::color(&b.color);
|
|
|
|
|
|
let hex = format!("#{:02x}{:02x}{:02x}", c.r(), c.g(), c.b());
|
|
|
|
|
|
view.bots.push(json!({
|
|
|
|
|
|
"id": b.id, "name": b.name, "description": b.description, "color": hex, "shape": b.shape,
|
|
|
|
|
|
"busy": live.is_some(), "status": live.and_then(|l| l.status.clone()).unwrap_or_default(),
|
|
|
|
|
|
"unread": b.unread, "last": last, "members": !b.members.is_empty(), "pinned": b.pinned,
|
Phone: a home with the computers, pages and routines; each bot's settings a tap away; long jobs fold up
The phone page was bare: one row per bot, a chat listing every step, a menu with four lines.
- Home: the main bot large at the top with its model and last words, the other bots with times,
then its computers (own box and the account's, online or not, 看畫面), the newest pages and the
routines with their next run.
- Chat: the bot's name opens its settings — model (chat models only), computer, past conversations
(restore), regenerate, new chat. A turn's steps fold into 「已完成 N 個步驟」 when done (the newest
three stay while it works); copy and regenerate under replies; four ready starts in a new chat;
a jump back to the newest message.
- Menu: 外觀 (follow the phone, light, dark).
- API: api/state carries pages and models; each bot its model, computers, routines, past
conversations; POST api/bots/{id}/set | regenerate | restore. The home's last line skips errors.
Checked on a local copy of the brain's data (cut off from the account and Docker) at iPhone size.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 12:28:08 +00:00
|
|
|
|
"primary": b.id == self.state.primary_bot,
|
|
|
|
|
|
"time": b.messages.iter().rev().find(|m| m.role != Role::Tool).map(|m| m.at).unwrap_or(0),
|
|
|
|
|
|
"via": format!("{} · {}", b.provider.label(), b.model),
|
|
|
|
|
|
"provider": serde_json::to_value(b.provider).unwrap_or_default(), "model": b.model,
|
|
|
|
|
|
"computer": computer, "computers": computers,
|
|
|
|
|
|
"routines": b.routines.iter().map(|r| json!({"id": r.id, "title": r.title, "paused": r.paused, "when": crate::appctl::routine_when(r)})).collect::<Vec<_>>(),
|
|
|
|
|
|
"threads": b.threads.iter().enumerate().rev().take(20).map(|(i, (title, msgs))| json!({"index": i, "title": title, "count": msgs.len(), "at": msgs.last().map(|m| m.at).unwrap_or(0)})).collect::<Vec<_>>(),
|
The phone page does what the desktop does, laid out like it
A new mobile/index.html in the desktop's (and Grok Bot's) shape: the sidebar
with its sections and folders, the chat with steps, thinking, reactions, quotes
and the approval card, 對話詳細資訊, Bot 設定, routines, pages, computers and
設定. Each action goes to the desktop's own code on the app's thread
(api/act/<what> -> App::phone_act): appctl, set_pinned, restart_bot,
toggle_reaction, box_task, channels_restart and the rest. No new rules.
Keys, channel tokens and the vault never reach the phone; a model key can only
be written. Admins keep what the phone always let them do; making, changing or
deleting bots, routines, memories, pages, folders and settings stays the
owner's. The state the phone polls now carries the sidebar's section order.
Checked by using it on a preview brain: routines, memories, templates, folders,
keys, signing another phone out, approvals and a chat with a fake model.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 19:05:12 +00:00
|
|
|
|
// The sidebar's sections, the colour by name (the editor), what is queued while it works.
|
|
|
|
|
|
"folder": b.folder, "color_key": b.color,
|
A turn cut off by a crash leaves a 「繼續」 card, and nothing it may have done runs twice
Each bot keeps a work log (oplog/bot-<id>.jsonl, after pi's durable-harness design, cut down):
before something happens a line says it is about to — the turn, each model call, each step once
its checks passed (with the arguments it runs with and whether it may run again), each message
typed mid-turn — synced to disk first. When the turn ends the file shrinks to the messages still
waiting, usually nothing.
On the next start after AnyBot was killed mid-turn, the log puts the chat right before anything
runs: the message the turn answered comes back if the chat lost it; a step that was running and
reaches outside (a text, a click, a file, a published site) shows as 「可能已經執行了」, both to the
person and in the result the bot reads — no longer as "not allowed"; a step that only looked shows
as cut off; messages typed mid-turn that never reached the bot go back into the chat. The chat is
saved, then the log closes the turn. A turn the person didn't stop ends with a 「繼續」 card (what
it was doing, what may have run, the messages put back); it goes on only when they press it — in
the window, on a screen of the brain, or on the phone — from where its steps stand, never running
a step that may have run again. Pressing stop is on disk at once, and a stopped turn stays
stopped.
Also in the turn loop:
- 自動審核 that doesn't answer (or answers something that isn't a verdict) asks the person; in
直接操作 mode it used to let the step through unchecked.
- "Too long for this model" folds older messages into a summary and asks the same step again,
once per thing the person said, instead of ending the turn.
- Folding keeps the person's chat whole: the summary goes in at the fold and the model reads from
the newest summary on (it used to delete what it folded).
- A step moved to the chosen computer runs there, but the chat keeps the call as the model wrote
it; the result says where it ran.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha5F5gJt93t3yEx3XcS
2026-11-08 16:49:12 +00:00
|
|
|
|
"queued": live.map(|l| l.steer.lock().unwrap().iter().map(|q| q.text.clone()).collect::<Vec<_>>()).unwrap_or_default(),
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}));
|
|
|
|
|
|
let start = b.messages.len().saturating_sub(remote::PHONE_TAIL);
|
The phone page does what the desktop does, laid out like it
A new mobile/index.html in the desktop's (and Grok Bot's) shape: the sidebar
with its sections and folders, the chat with steps, thinking, reactions, quotes
and the approval card, 對話詳細資訊, Bot 設定, routines, pages, computers and
設定. Each action goes to the desktop's own code on the app's thread
(api/act/<what> -> App::phone_act): appctl, set_pinned, restart_bot,
toggle_reaction, box_task, channels_restart and the rest. No new rules.
Keys, channel tokens and the vault never reach the phone; a model key can only
be written. Admins keep what the phone always let them do; making, changing or
deleting bots, routines, memories, pages, folders and settings stays the
owner's. The state the phone polls now carries the sidebar's section order.
Checked by using it on a preview brain: routines, memories, templates, folders,
keys, signing another phone out, approvals and a chat with a fake model.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 19:05:12 +00:00
|
|
|
|
// Each message with its place in the chat (表情回應), its thinking and, on each step,
|
|
|
|
|
|
// what came back (the desktop's 顯示步驟 / 思考過程), in short.
|
|
|
|
|
|
let results: HashMap<&str, &str> = b.messages[start..].iter().filter(|m| m.role == Role::Tool).map(|m| (m.tool_call_id.as_str(), m.text.as_str())).collect();
|
|
|
|
|
|
let msgs: Vec<serde_json::Value> = b.messages[start..]
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.enumerate()
|
|
|
|
|
|
.filter_map(|(k, m)| {
|
|
|
|
|
|
let mut v = remote::message_json(m, &names, &self.state.pages)?;
|
|
|
|
|
|
v["index"] = json!(start + k);
|
|
|
|
|
|
if !m.thinking.trim().is_empty() {
|
|
|
|
|
|
v["thinking"] = json!(clip(m.thinking.trim(), 1500));
|
|
|
|
|
|
}
|
|
|
|
|
|
if let Some(tools) = v["tools"].as_array_mut() {
|
|
|
|
|
|
for (t, c) in tools.iter_mut().zip(m.tool_calls.iter()) {
|
|
|
|
|
|
if t.get("label").is_some() {
|
|
|
|
|
|
t["name"] = json!(c.name);
|
|
|
|
|
|
if let Some(r) = results.get(c.id.as_str()) {
|
|
|
|
|
|
t["result"] = json!(clip(r.trim(), 600));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
Some(v)
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect();
|
|
|
|
|
|
view.messages.insert(b.id, msgs);
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
if let Some(a) = self.approvals.get(&b.id) {
|
|
|
|
|
|
view.approvals.push(approval_json(b, a));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
頁面: pages a bot makes and keeps up to date (like the original's tracking pages)
- write_page / read_page / list_pages: Markdown pages with versions (last 10 kept), per bot;
the reply gets a card (title, fading preview, page icon, 頁面 · 更新時間, 最近更新), and
[標題](page:ID) links open the page
- The page opens large: summary, what changed, the version picker, 複製 / 存成檔案 / 刪除;
listed under 資料庫 in the right panel
- Page blocks for richer pages, in the chat's Markdown too: ```stats tiles, ```steps progress,
> [!NOTE]/[!TIP]/[!WARNING]/[!IMPORTANT] call-outs (with tables and Mermaid charts)
- Phone: the card in chats, page links, a page view with the same blocks; charts drawn by the
AnyBot as SVG (GET /api/pages/<id>[/chart/<n>]); members may read pages
- Bots are told to make a page for things to track and to update it from a routine only when
there is real news
- Screenshot views: ANYBOT_SHOT_VIEW=pagecard / page
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 17:41:41 +00:00
|
|
|
|
view.pages = self.state.pages.clone();
|
Phone: a home with the computers, pages and routines; each bot's settings a tap away; long jobs fold up
The phone page was bare: one row per bot, a chat listing every step, a menu with four lines.
- Home: the main bot large at the top with its model and last words, the other bots with times,
then its computers (own box and the account's, online or not, 看畫面), the newest pages and the
routines with their next run.
- Chat: the bot's name opens its settings — model (chat models only), computer, past conversations
(restore), regenerate, new chat. A turn's steps fold into 「已完成 N 個步驟」 when done (the newest
three stay while it works); copy and regenerate under replies; four ready starts in a new chat;
a jump back to the newest message.
- Menu: 外觀 (follow the phone, light, dark).
- API: api/state carries pages and models; each bot its model, computers, routines, past
conversations; POST api/bots/{id}/set | regenerate | restore. The home's last line skips errors.
Checked on a local copy of the brain's data (cut off from the account and Docker) at iPhone size.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 12:28:08 +00:00
|
|
|
|
// The models a bot can be switched to from the phone: each provider that is ready.
|
|
|
|
|
|
view.models = crate::providers::ALL_PROVIDERS
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.filter(|&&k| !k.needs_key() || !crate::providers::resolve_key(k, &self.state.provider(k).api_key).is_empty())
|
|
|
|
|
|
// Only models that chat: an image or video generator picked for a bot would break it.
|
|
|
|
|
|
.map(|&k| json!({"provider": serde_json::to_value(k).unwrap_or_default(), "label": k.label(), "models": self.models_for(k).into_iter().filter(|m| chats(m)).collect::<Vec<_>>()}))
|
|
|
|
|
|
.collect();
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
remote::hub().publish(view);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Voice: its own 設定 › 語音, run by the brain for every screen and the phone
Voice was three implementations that broke on their own: speech to text
borrowed the OpenAI key (so with only Grok set up the mic recorded,
then failed), OpenAI's models it hard-coded stop on 2027-02-26, read
aloud was macOS `say` or espeak-ng (silently nothing on Windows, where
espeak isn't installed), and the phone used the browser's own
recognition. Now:
- 設定 › 語音 has 聽 and 說, each a service: off, OpenAI-compatible
(OpenAI, Groq, a Whisper server of your own: the address decides),
xAI or ElevenLabs. An empty key borrows 設定 › 模型's for the same
service. Each side says 可以用 or what it lacks; 聽 has 試試看
(record a sentence, show what was heard), 說 has 試聽 and the voice
list. speech.rs does the calls; xAI's both ways were checked for real
(Mandarin read, then heard back, in Traditional characters).
- The brain does it all: the phone POSTs its recording (MediaRecorder)
to /api/voice/transcribe, screens to /api/sync/voice/transcribe;
answers come back as MP3 from …/voice/speech and are played on the
device (rodio; an <audio> on the phone, 「唸出來」 in a message's
menu). Keys stay on the brain (the voice keys are redacted for
screens like the others).
- No service, no voice anywhere: the mic, 語音聊天, 會議錄音 and 朗讀
only appear once 聽 (and 說) can be called; the phone's state says
which. Without voice the send arrow just rests where 語音聊天 was.
- 會議錄音 is uploaded to the brain, which turns it into text in the
background and hands it to the bot itself: a meeting is longer than
the 35 s the account lets a request wait, and a brain on a server has
no window (the jobs are polled in background()).
- Recognisers answer Mandarin in Simplified: in a Traditional Chinese
window or phone the text becomes Traditional with Taiwan wording.
- Older saves: whoever had an OpenAI key keeps voice input (聽 =
OpenAI); everyone else starts with it off. Bots' macOS voice names
are cleared. 對話詳細資訊's 加入會議 started plain voice input; it
starts a meeting now.
2026-11-10 14:58:18 +00:00
|
|
|
|
pub(super) fn remote_cmd(&mut self, ctx: &egui::Context, c: Cmd) {
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
match c {
|
Voice: its own 設定 › 語音, run by the brain for every screen and the phone
Voice was three implementations that broke on their own: speech to text
borrowed the OpenAI key (so with only Grok set up the mic recorded,
then failed), OpenAI's models it hard-coded stop on 2027-02-26, read
aloud was macOS `say` or espeak-ng (silently nothing on Windows, where
espeak isn't installed), and the phone used the browser's own
recognition. Now:
- 設定 › 語音 has 聽 and 說, each a service: off, OpenAI-compatible
(OpenAI, Groq, a Whisper server of your own: the address decides),
xAI or ElevenLabs. An empty key borrows 設定 › 模型's for the same
service. Each side says 可以用 or what it lacks; 聽 has 試試看
(record a sentence, show what was heard), 說 has 試聽 and the voice
list. speech.rs does the calls; xAI's both ways were checked for real
(Mandarin read, then heard back, in Traditional characters).
- The brain does it all: the phone POSTs its recording (MediaRecorder)
to /api/voice/transcribe, screens to /api/sync/voice/transcribe;
answers come back as MP3 from …/voice/speech and are played on the
device (rodio; an <audio> on the phone, 「唸出來」 in a message's
menu). Keys stay on the brain (the voice keys are redacted for
screens like the others).
- No service, no voice anywhere: the mic, 語音聊天, 會議錄音 and 朗讀
only appear once 聽 (and 說) can be called; the phone's state says
which. Without voice the send arrow just rests where 語音聊天 was.
- 會議錄音 is uploaded to the brain, which turns it into text in the
background and hands it to the bot itself: a meeting is longer than
the 35 s the account lets a request wait, and a brain on a server has
no window (the jobs are polled in background()).
- Recognisers answer Mandarin in Simplified: in a Traditional Chinese
window or phone the text becomes Traditional with Taiwan wording.
- Older saves: whoever had an OpenAI key keeps voice input (聽 =
OpenAI); everyone else starts with it off. Bots' macOS voice names
are cleared. 對話詳細資訊's 加入會議 started plain voice input; it
starts a meeting now.
2026-11-10 14:58:18 +00:00
|
|
|
|
Cmd::Meeting { bot, path, lang } => {
|
|
|
|
|
|
// Only a recording the app itself stored (uploaded into its attachments).
|
|
|
|
|
|
let root = crate::model::State::path().parent().map(|p| p.join("attachments")).and_then(|p| p.canonicalize().ok());
|
|
|
|
|
|
match (std::path::Path::new(&path).canonicalize().ok(), root) {
|
|
|
|
|
|
(Some(f), Some(root)) if f.starts_with(&root) && f.is_file() => self.meeting_job(bot, f, lang, true),
|
|
|
|
|
|
_ => {}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
記憶: a page to see it, a few lines picked while typing, a local model
The memory had grown into a list carried whole, a top-14 recalled by a
trigram index and pasted into the system prompt with the clock, and a
page that broke its own layout. Nobody could see what went to the
model, the prompt cache missed every message, and 「記住」 kept saying
the same thing twice. Rebuilt per the spec (docs/memory.md):
- Three kinds in memory.db: 記得的事 (fact), 做過的事 (event, a line per
finished turn), 整理過的 (rollup). Each keeps pinned, uses,
last_used, deleted, superseded_by, span. state.json keeps the facts
as the copy that syncs; the page reads SQLite.
- Search: jieba words ∪ CJK bigrams in an FTS5 unicode61 table
(Traditional text goes through Simplified first), weighted share of
query terms hit; plus local vectors, vec = clamp((cos−0.35)/0.35).
score = max + 0.15×min, events ×0.9. ≥0.15 suggested, ≥0.5 ticked,
≥0.55 carried when nobody chose (3 at most).
- What the model gets: the system prompt has the time zone and the
pinned memories only, the same every turn. Each person message gets
〔送出時間〕 and 〔相關記憶〕 from Message.memories, built in
group_history into a transient Message.context, so the beginning of
a chat reads the same next turn (cache hits) and the event log,
skills and audit see only what was typed. A memory already carried
in view isn't carried again; each carry counts a use.
- Picks travel with the message: Cmd::Send / POST send / sync act
"memories" (empty = none; absent = the brain chooses, once, saved).
- remember finds the like one (cos ≥ 0.85 or the same words) and asks
for `replaces`; the old one is superseded, never carried. A fact
forgotten and remembered again comes back. New search_memory
(query, kind), with dates; read-only.
- Nightly on the brain, no model: events past 30 days fold into a line
per week (「11/3–11/9 做過的事(14 件):整理照片 ×3…」, ≤400 chars,
like with like by words or vectors), weeks past 180 days into months;
the folded go to 最近刪除 for 30 days. Facts are never removed. The
page offers duplicates, facts unused for half a year, and what can
fold now.
- Local model: minishlab/potion-multilingual-128M through m2v.rs (same
token ids as model2vec-rs on 13/13 sentences, cos ≥ 0.9999, without
tokenizers' 1.1 GB). Converted while downloading: vocab.bin,
table.i8 (int8 + row scales), dims.json, 137 MB kept of 530 MB;
ANYBOT_HF_BASE picks a mirror (now passed into the server's brain
container too). Loaded when first needed (34 ms), let go after 10
idle minutes. The brain loads it; a screen only with a document
folder set; hands and phones never. 設定 › 一般 › 語意搜尋:
本機模型/Ollama/關閉; a new engine clears every vector.
- Three files, three connections: memory.db (backed up nightly, 7
kept), docs.db (a cache), oplog/audit.db (30 days). An old audit.db
hands its memories and documents over once and shrinks (a real one:
172 MB → 16 KB). docs_search scans every chunk now, vectors cached
in RAM (it stopped at 8000); FTS optimize + VACUUM daily (260 MB of
tombstones over 31 MB of text).
- API: POST /api/memory (owner) and /api/sync/memory (mirror). Reads
answer on the HTTP thread; writes go through phone_act("memory").
- Screens: a memory dialog (Bot menu 記憶…, Bot settings 打開記憶) with
counts, live search, filters, suggestions, per-item kind/date/uses
and pin/edit/forget/restore; chips above the composer 300 ms after
typing stops, with a token estimate; 「帶了 N 條記憶」 under person
messages. The phone has the same as a 記憶 tab, chips and tag.
Checked: make test passes (app 297, relay 16), with new tests for the
scores and thresholds, Traditional Chinese segmentation, remember's
dedupe and replaces, two turns sending the same beginning, no double
carry, weekly/monthly folding and the trash, and the audit.db move.
Brain idle 37 MB as before, ~230 MB with the model loaded; search on
the brain 0.2–0.5 ms, 7–44 ms from the phone page. A deadlock found on
the way (stats re-taking the lock) is fixed and tested.
Docs: docs/memory.md has the whole design; FEATURES.md, protocol,
architecture (zh/en), multi-device and install say what changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3SYw9JJ9dXwaNvYh4
2026-11-10 23:46:50 +00:00
|
|
|
|
Cmd::Send { bot, text, attachments, from, memories } => {
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
if self.state.bot(bot).is_none() {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-11-05 08:47:28 +00:00
|
|
|
|
// Typed on one of the account's computers: that one is the person's now (for
|
|
|
|
|
|
// 「我的電腦」 and the model on their network). The phone isn't a computer.
|
|
|
|
|
|
if !from.is_empty() {
|
|
|
|
|
|
remote::set_person_host(&from);
|
Remote brain: a computer that just came on is known at once; an offline computer is said, not swapped; snapshots survive an open browser; end-to-end test
- The brain looked the account's computers up once a minute: for up to a minute after the Mac
came on, 「我的電腦」 was unknown and steps went elsewhere. Now every 15 s, and at once when a
message comes from a computer it doesn't know yet.
- A step naming a computer that is off says so in words instead of running on the chosen one
with a note that the person hadn't asked.
- Snapshots: tar's 'file changed' (the open browser) is not a failure; browser caches are left
out; ten minutes for a large home folder.
- box_end_to_end clicks the terminal where it opened; restore only with ANYBOT_TEST_RESTORE=1.
- deploy/test/remote_e2e.py: account server + headless brain + hands + scripted model, 27 checks
(computers, redirect, agent-desktop on the hands, hand-off 3 ways, phone view, sync copy,
edits, hands offline/back, brain restart, clear). anybot --sample-state for such tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 10:14:23 +00:00
|
|
|
|
// A computer this brain hasn't heard of yet (it just came on): look the
|
|
|
|
|
|
// account's computers up now, or its 「我的電腦」 wouldn't be known for a minute.
|
|
|
|
|
|
if !self.rm.peers.lock().unwrap().iter().any(|(id, _, online)| *id == from && *online) {
|
|
|
|
|
|
let v = remote::devices_online(&self.state.remote);
|
|
|
|
|
|
if !v.is_empty() {
|
|
|
|
|
|
*self.rm.peers.lock().unwrap() = v;
|
|
|
|
|
|
}
|
|
|
|
|
|
self.rm.peers_at = Some(Instant::now());
|
|
|
|
|
|
}
|
2026-11-05 08:47:28 +00:00
|
|
|
|
self.typed_on = Some(from);
|
|
|
|
|
|
}
|
2026-11-05 07:48:20 +00:00
|
|
|
|
// Only files the app itself stored in its attachments folder may ride along;
|
|
|
|
|
|
// resolve first, so "../../" paths cannot escape it (the phone can name any path).
|
|
|
|
|
|
let root = crate::model::State::path().parent().map(|p| p.join("attachments")).and_then(|p| p.canonicalize().ok());
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let atts: Vec<crate::attach::Attachment> = attachments
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.filter_map(|p| {
|
2026-11-05 07:48:20 +00:00
|
|
|
|
let f = std::path::Path::new(p).canonicalize().ok()?;
|
|
|
|
|
|
if !root.as_ref().map(|r| f.starts_with(r) && f.is_file()).unwrap_or(false) {
|
|
|
|
|
|
return None;
|
|
|
|
|
|
}
|
|
|
|
|
|
let meta = std::fs::metadata(&f).ok()?;
|
|
|
|
|
|
let file = f.file_name()?.to_string_lossy().to_string();
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let name = file.split_once('-').map(|x| x.1.to_string()).unwrap_or(file);
|
2026-11-05 09:07:04 +00:00
|
|
|
|
// Also on the bot's own computer, where it works (a brain on a server
|
|
|
|
|
|
// has no other computer of its own to read it from).
|
|
|
|
|
|
let on_box = crate::cloudbox::copy_in(&f.display().to_string(), bot, &name).unwrap_or_default();
|
|
|
|
|
|
Some(crate::attach::Attachment { image: crate::attach::is_image_name(&name), name, path: f.display().to_string(), bytes: meta.len(), on_box })
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
})
|
|
|
|
|
|
.collect();
|
A turn cut off by a crash leaves a 「繼續」 card, and nothing it may have done runs twice
Each bot keeps a work log (oplog/bot-<id>.jsonl, after pi's durable-harness design, cut down):
before something happens a line says it is about to — the turn, each model call, each step once
its checks passed (with the arguments it runs with and whether it may run again), each message
typed mid-turn — synced to disk first. When the turn ends the file shrinks to the messages still
waiting, usually nothing.
On the next start after AnyBot was killed mid-turn, the log puts the chat right before anything
runs: the message the turn answered comes back if the chat lost it; a step that was running and
reaches outside (a text, a click, a file, a published site) shows as 「可能已經執行了」, both to the
person and in the result the bot reads — no longer as "not allowed"; a step that only looked shows
as cut off; messages typed mid-turn that never reached the bot go back into the chat. The chat is
saved, then the log closes the turn. A turn the person didn't stop ends with a 「繼續」 card (what
it was doing, what may have run, the messages put back); it goes on only when they press it — in
the window, on a screen of the brain, or on the phone — from where its steps stand, never running
a step that may have run again. Pressing stop is on disk at once, and a stopped turn stays
stopped.
Also in the turn loop:
- 自動審核 that doesn't answer (or answers something that isn't a verdict) asks the person; in
直接操作 mode it used to let the step through unchecked.
- "Too long for this model" folds older messages into a summary and asks the same step again,
once per thing the person said, instead of ending the turn.
- Folding keeps the person's chat whole: the summary goes in at the fold and the model reads from
the newest summary on (it used to delete what it folded).
- A step moved to the chosen computer runs there, but the chat keeps the call as the model wrote
it; the result says where it ran.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha5F5gJt93t3yEx3XcS
2026-11-08 16:49:12 +00:00
|
|
|
|
if self.streams.contains_key(&bot) {
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let (extra, _) = crate::attach::for_model(&atts);
|
A turn cut off by a crash leaves a 「繼續」 card, and nothing it may have done runs twice
Each bot keeps a work log (oplog/bot-<id>.jsonl, after pi's durable-harness design, cut down):
before something happens a line says it is about to — the turn, each model call, each step once
its checks passed (with the arguments it runs with and whether it may run again), each message
typed mid-turn — synced to disk first. When the turn ends the file shrinks to the messages still
waiting, usually nothing.
On the next start after AnyBot was killed mid-turn, the log puts the chat right before anything
runs: the message the turn answered comes back if the chat lost it; a step that was running and
reaches outside (a text, a click, a file, a published site) shows as 「可能已經執行了」, both to the
person and in the result the bot reads — no longer as "not allowed"; a step that only looked shows
as cut off; messages typed mid-turn that never reached the bot go back into the chat. The chat is
saved, then the log closes the turn. A turn the person didn't stop ends with a 「繼續」 card (what
it was doing, what may have run, the messages put back); it goes on only when they press it — in
the window, on a screen of the brain, or on the phone — from where its steps stand, never running
a step that may have run again. Pressing stop is on disk at once, and a stopped turn stays
stopped.
Also in the turn loop:
- 自動審核 that doesn't answer (or answers something that isn't a verdict) asks the person; in
直接操作 mode it used to let the step through unchecked.
- "Too long for this model" folds older messages into a summary and asks the same step again,
once per thing the person said, instead of ending the turn.
- Folding keeps the person's chat whole: the summary goes in at the fold and the model reads from
the newest summary on (it used to delete what it folded).
- A step moved to the chosen computer runs there, but the chat keeps the call as the model wrote
it; the result says where it ran.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha5F5gJt93t3yEx3XcS
2026-11-08 16:49:12 +00:00
|
|
|
|
self.queue_steer(bot, format!("{text}{extra}"));
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
記憶: a page to see it, a few lines picked while typing, a local model
The memory had grown into a list carried whole, a top-14 recalled by a
trigram index and pasted into the system prompt with the clock, and a
page that broke its own layout. Nobody could see what went to the
model, the prompt cache missed every message, and 「記住」 kept saying
the same thing twice. Rebuilt per the spec (docs/memory.md):
- Three kinds in memory.db: 記得的事 (fact), 做過的事 (event, a line per
finished turn), 整理過的 (rollup). Each keeps pinned, uses,
last_used, deleted, superseded_by, span. state.json keeps the facts
as the copy that syncs; the page reads SQLite.
- Search: jieba words ∪ CJK bigrams in an FTS5 unicode61 table
(Traditional text goes through Simplified first), weighted share of
query terms hit; plus local vectors, vec = clamp((cos−0.35)/0.35).
score = max + 0.15×min, events ×0.9. ≥0.15 suggested, ≥0.5 ticked,
≥0.55 carried when nobody chose (3 at most).
- What the model gets: the system prompt has the time zone and the
pinned memories only, the same every turn. Each person message gets
〔送出時間〕 and 〔相關記憶〕 from Message.memories, built in
group_history into a transient Message.context, so the beginning of
a chat reads the same next turn (cache hits) and the event log,
skills and audit see only what was typed. A memory already carried
in view isn't carried again; each carry counts a use.
- Picks travel with the message: Cmd::Send / POST send / sync act
"memories" (empty = none; absent = the brain chooses, once, saved).
- remember finds the like one (cos ≥ 0.85 or the same words) and asks
for `replaces`; the old one is superseded, never carried. A fact
forgotten and remembered again comes back. New search_memory
(query, kind), with dates; read-only.
- Nightly on the brain, no model: events past 30 days fold into a line
per week (「11/3–11/9 做過的事(14 件):整理照片 ×3…」, ≤400 chars,
like with like by words or vectors), weeks past 180 days into months;
the folded go to 最近刪除 for 30 days. Facts are never removed. The
page offers duplicates, facts unused for half a year, and what can
fold now.
- Local model: minishlab/potion-multilingual-128M through m2v.rs (same
token ids as model2vec-rs on 13/13 sentences, cos ≥ 0.9999, without
tokenizers' 1.1 GB). Converted while downloading: vocab.bin,
table.i8 (int8 + row scales), dims.json, 137 MB kept of 530 MB;
ANYBOT_HF_BASE picks a mirror (now passed into the server's brain
container too). Loaded when first needed (34 ms), let go after 10
idle minutes. The brain loads it; a screen only with a document
folder set; hands and phones never. 設定 › 一般 › 語意搜尋:
本機模型/Ollama/關閉; a new engine clears every vector.
- Three files, three connections: memory.db (backed up nightly, 7
kept), docs.db (a cache), oplog/audit.db (30 days). An old audit.db
hands its memories and documents over once and shrinks (a real one:
172 MB → 16 KB). docs_search scans every chunk now, vectors cached
in RAM (it stopped at 8000); FTS optimize + VACUUM daily (260 MB of
tombstones over 31 MB of text).
- API: POST /api/memory (owner) and /api/sync/memory (mirror). Reads
answer on the HTTP thread; writes go through phone_act("memory").
- Screens: a memory dialog (Bot menu 記憶…, Bot settings 打開記憶) with
counts, live search, filters, suggestions, per-item kind/date/uses
and pin/edit/forget/restore; chips above the composer 300 ms after
typing stops, with a token estimate; 「帶了 N 條記憶」 under person
messages. The phone has the same as a 記憶 tab, chips and tag.
Checked: make test passes (app 297, relay 16), with new tests for the
scores and thresholds, Traditional Chinese segmentation, remember's
dedupe and replaces, two turns sending the same beginning, no double
carry, weekly/monthly folding and the trash, and the audit.db move.
Brain idle 37 MB as before, ~230 MB with the model loaded; search on
the brain 0.2–0.5 ms, 7–44 ms from the phone page. A deadlock found on
the way (stats re-taking the lock) is fixed and tested.
Docs: docs/memory.md has the whole design; FEATURES.md, protocol,
architecture (zh/en), multi-device and install say what changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3SYw9JJ9dXwaNvYh4
2026-11-10 23:46:50 +00:00
|
|
|
|
let m = super::person_message(&self.state, bot, &text, atts, memories);
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
if let Some(b) = self.state.bot_mut(bot) {
|
記憶: a page to see it, a few lines picked while typing, a local model
The memory had grown into a list carried whole, a top-14 recalled by a
trigram index and pasted into the system prompt with the clock, and a
page that broke its own layout. Nobody could see what went to the
model, the prompt cache missed every message, and 「記住」 kept saying
the same thing twice. Rebuilt per the spec (docs/memory.md):
- Three kinds in memory.db: 記得的事 (fact), 做過的事 (event, a line per
finished turn), 整理過的 (rollup). Each keeps pinned, uses,
last_used, deleted, superseded_by, span. state.json keeps the facts
as the copy that syncs; the page reads SQLite.
- Search: jieba words ∪ CJK bigrams in an FTS5 unicode61 table
(Traditional text goes through Simplified first), weighted share of
query terms hit; plus local vectors, vec = clamp((cos−0.35)/0.35).
score = max + 0.15×min, events ×0.9. ≥0.15 suggested, ≥0.5 ticked,
≥0.55 carried when nobody chose (3 at most).
- What the model gets: the system prompt has the time zone and the
pinned memories only, the same every turn. Each person message gets
〔送出時間〕 and 〔相關記憶〕 from Message.memories, built in
group_history into a transient Message.context, so the beginning of
a chat reads the same next turn (cache hits) and the event log,
skills and audit see only what was typed. A memory already carried
in view isn't carried again; each carry counts a use.
- Picks travel with the message: Cmd::Send / POST send / sync act
"memories" (empty = none; absent = the brain chooses, once, saved).
- remember finds the like one (cos ≥ 0.85 or the same words) and asks
for `replaces`; the old one is superseded, never carried. A fact
forgotten and remembered again comes back. New search_memory
(query, kind), with dates; read-only.
- Nightly on the brain, no model: events past 30 days fold into a line
per week (「11/3–11/9 做過的事(14 件):整理照片 ×3…」, ≤400 chars,
like with like by words or vectors), weeks past 180 days into months;
the folded go to 最近刪除 for 30 days. Facts are never removed. The
page offers duplicates, facts unused for half a year, and what can
fold now.
- Local model: minishlab/potion-multilingual-128M through m2v.rs (same
token ids as model2vec-rs on 13/13 sentences, cos ≥ 0.9999, without
tokenizers' 1.1 GB). Converted while downloading: vocab.bin,
table.i8 (int8 + row scales), dims.json, 137 MB kept of 530 MB;
ANYBOT_HF_BASE picks a mirror (now passed into the server's brain
container too). Loaded when first needed (34 ms), let go after 10
idle minutes. The brain loads it; a screen only with a document
folder set; hands and phones never. 設定 › 一般 › 語意搜尋:
本機模型/Ollama/關閉; a new engine clears every vector.
- Three files, three connections: memory.db (backed up nightly, 7
kept), docs.db (a cache), oplog/audit.db (30 days). An old audit.db
hands its memories and documents over once and shrinks (a real one:
172 MB → 16 KB). docs_search scans every chunk now, vectors cached
in RAM (it stopped at 8000); FTS optimize + VACUUM daily (260 MB of
tombstones over 31 MB of text).
- API: POST /api/memory (owner) and /api/sync/memory (mirror). Reads
answer on the HTTP thread; writes go through phone_act("memory").
- Screens: a memory dialog (Bot menu 記憶…, Bot settings 打開記憶) with
counts, live search, filters, suggestions, per-item kind/date/uses
and pin/edit/forget/restore; chips above the composer 300 ms after
typing stops, with a token estimate; 「帶了 N 條記憶」 under person
messages. The phone has the same as a 記憶 tab, chips and tag.
Checked: make test passes (app 297, relay 16), with new tests for the
scores and thresholds, Traditional Chinese segmentation, remember's
dedupe and replaces, two turns sending the same beginning, no double
carry, weekly/monthly folding and the trash, and the audit.db move.
Brain idle 37 MB as before, ~230 MB with the model loaded; search on
the brain 0.2–0.5 ms, 7–44 ms from the phone page. A deadlock found on
the way (stats re-taking the lock) is fixed and tested.
Docs: docs/memory.md has the whole design; FEATURES.md, protocol,
architecture (zh/en), multi-device and install say what changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3SYw9JJ9dXwaNvYh4
2026-11-10 23:46:50 +00:00
|
|
|
|
b.messages.push(m);
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
self.start_reply(ctx, bot);
|
|
|
|
|
|
}
|
|
|
|
|
|
Cmd::Stop { bot } => self.stop(bot),
|
2026-11-06 12:33:06 +00:00
|
|
|
|
// The server's own zone (UTC) was never the person's choice: take theirs. A zone the
|
|
|
|
|
|
// person set on purpose stays.
|
|
|
|
|
|
Cmd::PersonTimezone(tz) => {
|
|
|
|
|
|
if crate::routines::is_server_default_zone(&self.state.timezone) && tz != self.state.timezone {
|
|
|
|
|
|
self.state.timezone = tz;
|
|
|
|
|
|
self.mark();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
Phone: a home with the computers, pages and routines; each bot's settings a tap away; long jobs fold up
The phone page was bare: one row per bot, a chat listing every step, a menu with four lines.
- Home: the main bot large at the top with its model and last words, the other bots with times,
then its computers (own box and the account's, online or not, 看畫面), the newest pages and the
routines with their next run.
- Chat: the bot's name opens its settings — model (chat models only), computer, past conversations
(restore), regenerate, new chat. A turn's steps fold into 「已完成 N 個步驟」 when done (the newest
three stay while it works); copy and regenerate under replies; four ready starts in a new chat;
a jump back to the newest message.
- Menu: 外觀 (follow the phone, light, dark).
- API: api/state carries pages and models; each bot its model, computers, routines, past
conversations; POST api/bots/{id}/set | regenerate | restore. The home's last line skips errors.
Checked on a local copy of the brain's data (cut off from the account and Docker) at iPhone size.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 12:28:08 +00:00
|
|
|
|
Cmd::SetBot { bot, provider, model, computer } => {
|
|
|
|
|
|
let kind = serde_json::from_value::<crate::providers::ProviderKind>(json!(provider)).ok();
|
|
|
|
|
|
if let (Some(k), false) = (kind, model.is_empty()) {
|
|
|
|
|
|
if let Some(b) = self.state.bot_mut(bot) {
|
|
|
|
|
|
b.provider = k;
|
|
|
|
|
|
b.model = model;
|
|
|
|
|
|
}
|
|
|
|
|
|
self.mark();
|
|
|
|
|
|
}
|
|
|
|
|
|
if !computer.is_empty() {
|
|
|
|
|
|
let _ = self.update_bot_computer(bot, &json!({"default_computer": computer}).to_string());
|
|
|
|
|
|
self.mark();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-04 09:46:43 +00:00
|
|
|
|
Cmd::Regenerate { bot } => self.regenerate(ctx, bot),
|
|
|
|
|
|
Cmd::Reply { bot } => {
|
|
|
|
|
|
if !self.streams.contains_key(&bot) && self.state.bot(bot).and_then(|b| b.messages.last()).map(|m| m.role == Role::User).unwrap_or(false) {
|
|
|
|
|
|
self.start_reply(ctx, bot);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
A turn cut off by a crash leaves a 「繼續」 card, and nothing it may have done runs twice
Each bot keeps a work log (oplog/bot-<id>.jsonl, after pi's durable-harness design, cut down):
before something happens a line says it is about to — the turn, each model call, each step once
its checks passed (with the arguments it runs with and whether it may run again), each message
typed mid-turn — synced to disk first. When the turn ends the file shrinks to the messages still
waiting, usually nothing.
On the next start after AnyBot was killed mid-turn, the log puts the chat right before anything
runs: the message the turn answered comes back if the chat lost it; a step that was running and
reaches outside (a text, a click, a file, a published site) shows as 「可能已經執行了」, both to the
person and in the result the bot reads — no longer as "not allowed"; a step that only looked shows
as cut off; messages typed mid-turn that never reached the bot go back into the chat. The chat is
saved, then the log closes the turn. A turn the person didn't stop ends with a 「繼續」 card (what
it was doing, what may have run, the messages put back); it goes on only when they press it — in
the window, on a screen of the brain, or on the phone — from where its steps stand, never running
a step that may have run again. Pressing stop is on disk at once, and a stopped turn stays
stopped.
Also in the turn loop:
- 自動審核 that doesn't answer (or answers something that isn't a verdict) asks the person; in
直接操作 mode it used to let the step through unchecked.
- "Too long for this model" folds older messages into a summary and asks the same step again,
once per thing the person said, instead of ending the turn.
- Folding keeps the person's chat whole: the summary goes in at the fold and the model reads from
the newest summary on (it used to delete what it folded).
- A step moved to the chosen computer runs there, but the chat keeps the call as the model wrote
it; the result says where it ran.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha5F5gJt93t3yEx3XcS
2026-11-08 16:49:12 +00:00
|
|
|
|
Cmd::Resume { bot } => self.resume_turn(ctx, bot),
|
2026-11-04 09:46:43 +00:00
|
|
|
|
Cmd::RestoreThread { bot, index } => {
|
|
|
|
|
|
self.stop(bot);
|
|
|
|
|
|
if let Some(b) = self.state.bot_mut(bot) {
|
|
|
|
|
|
if index < b.threads.len() {
|
|
|
|
|
|
let (_, msgs) = b.threads.remove(index);
|
|
|
|
|
|
if !b.messages.is_empty() {
|
|
|
|
|
|
let title = b.messages.iter().find(|m| m.role == Role::User).map(|m| first_line(&m.text, 24)).unwrap_or_else(|| "對話".into());
|
|
|
|
|
|
let cur = std::mem::take(&mut b.messages);
|
|
|
|
|
|
b.threads.insert(0, (title, cur));
|
|
|
|
|
|
}
|
|
|
|
|
|
b.messages = msgs;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
self.mark();
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
Cmd::Answer { bot, answer } => {
|
|
|
|
|
|
let grant = self.approvals.get(&bot).map(|a| a.grant.clone()).unwrap_or_default();
|
|
|
|
|
|
let a = match answer.as_str() {
|
|
|
|
|
|
"once" => ApprovalAnswer::Once,
|
|
|
|
|
|
"always" => ApprovalAnswer::Always(grant),
|
|
|
|
|
|
_ => ApprovalAnswer::Reject,
|
|
|
|
|
|
};
|
|
|
|
|
|
self.answer(ctx, bot, a);
|
|
|
|
|
|
}
|
|
|
|
|
|
Cmd::Read { bot } => {
|
|
|
|
|
|
if let Some(b) = self.state.bot_mut(bot) {
|
|
|
|
|
|
if b.unread {
|
|
|
|
|
|
b.unread = false;
|
|
|
|
|
|
self.mark();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-05 08:47:28 +00:00
|
|
|
|
Cmd::Clear { bot } => {
|
|
|
|
|
|
self.stop(bot);
|
|
|
|
|
|
if let Some(b) = self.state.bot_mut(bot) {
|
|
|
|
|
|
b.messages.clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
self.mark();
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
Cmd::NewThread { bot } => {
|
|
|
|
|
|
self.stop(bot);
|
|
|
|
|
|
if let Some(b) = self.state.bot_mut(bot) {
|
|
|
|
|
|
if !b.messages.is_empty() {
|
|
|
|
|
|
let title = b.messages.iter().find(|m| m.role == Role::User).map(|m| first_line(&m.text, 24)).unwrap_or_else(|| "對話".into());
|
|
|
|
|
|
let msgs = std::mem::take(&mut b.messages);
|
|
|
|
|
|
b.threads.insert(0, (title, msgs));
|
|
|
|
|
|
b.threads.truncate(50);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
self.mark();
|
|
|
|
|
|
}
|
|
|
|
|
|
Cmd::DeviceAdded(d) => {
|
|
|
|
|
|
self.state.remote.devices.push(d);
|
|
|
|
|
|
self.mark();
|
|
|
|
|
|
}
|
|
|
|
|
|
Cmd::DeviceSeen(h) => {
|
|
|
|
|
|
if let Some(gone) = h.strip_prefix('-') {
|
|
|
|
|
|
self.state.remote.devices.retain(|d| d.token_hash != gone);
|
|
|
|
|
|
self.mark();
|
|
|
|
|
|
} else if !self.rm.last_seen_mark.map(|t| t.elapsed().as_secs() < 60).unwrap_or(false) {
|
|
|
|
|
|
self.rm.last_seen_mark = Some(Instant::now());
|
|
|
|
|
|
if let Some(d) = self.state.remote.devices.iter_mut().find(|d| d.token_hash == h) {
|
|
|
|
|
|
d.last_seen = chrono::Utc::now().timestamp();
|
|
|
|
|
|
self.mark();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-05 06:25:01 +00:00
|
|
|
|
/// 登入後同步: the account's bots and this computer's become one set.
|
|
|
|
|
|
/// • Another AnyBot of the account is the brain → show it, and copy this computer's bots
|
|
|
|
|
|
/// there (once it answers; bots it already has are skipped).
|
|
|
|
|
|
/// • This one is the only one → take in the backup's bots it doesn't have, then back up
|
|
|
|
|
|
/// the whole set, so the account has this computer's bots too.
|
|
|
|
|
|
fn account_sync(&mut self, found: remote::AccountFind) {
|
|
|
|
|
|
if let Some((id, name)) = found.brain {
|
|
|
|
|
|
*self.rm.note.lock().unwrap() = format!("已登入,改用「{name}」當大腦:那邊的 Bot 會同步過來,這台的也會搬過去");
|
|
|
|
|
|
self.mir.want = Some((id, name));
|
|
|
|
|
|
self.mir.move_after_join = true;
|
|
|
|
|
|
// The brain's bots may use this computer (each action still asks).
|
|
|
|
|
|
self.state.remote.device_link = true;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let got = found.backup.and_then(|b| serde_json::from_slice::<State>(&b).ok());
|
|
|
|
|
|
let n = got.map(|st| self.state.take_in_bots(&st)).unwrap_or(0);
|
|
|
|
|
|
*self.rm.note.lock().unwrap() = if n > 0 { format!("已登入,帳號裡的 {n} 個 Bot 已同步到這台") } else { "已登入,這台 AnyBot 已加入帳號".into() };
|
|
|
|
|
|
if !self.state.bots.is_empty() && self.state.remote.auto_backup {
|
|
|
|
|
|
self.remote_backup();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
fn remote_backup(&mut self) {
|
|
|
|
|
|
if self.rm.busy.swap(true, Ordering::SeqCst) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
self.state.remote.last_backup = chrono::Utc::now().timestamp();
|
|
|
|
|
|
self.mark();
|
|
|
|
|
|
let s = self.state.remote.clone();
|
|
|
|
|
|
let mut st = self.state.clone();
|
|
|
|
|
|
// The backup is for the bots; this computer's own keys to the relay and phones stay here.
|
|
|
|
|
|
st.remote = Default::default();
|
|
|
|
|
|
let bytes = serde_json::to_vec(&st).unwrap_or_default();
|
|
|
|
|
|
let (note, busy) = (self.rm.note.clone(), self.rm.busy.clone());
|
|
|
|
|
|
std::thread::spawn(move || {
|
|
|
|
|
|
*note.lock().unwrap() = match remote::backup_now(&s, &bytes) {
|
|
|
|
|
|
Ok(n) => format!("已備份({},已加密)", crate::cloudbox::human(n as u64)),
|
|
|
|
|
|
Err(e) => e,
|
|
|
|
|
|
};
|
|
|
|
|
|
busy.store(false, Ordering::SeqCst);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn remote_page(&mut self, ui: &mut egui::Ui, _ctx: &egui::Context) {
|
|
|
|
|
|
let p = self.pal;
|
|
|
|
|
|
let mut changed = false;
|
|
|
|
|
|
setting_card(ui, p, |ui| {
|
|
|
|
|
|
setting_title(ui, "手機與帳號", "在手機上和 Bot 聊天、核准它要做的事、看著它的電腦。", p);
|
|
|
|
|
|
hint(ui, "兩種連法:同一個網路(或 Tailscale)直接連這台電腦;或登入帳號,透過你的帳號伺服器從任何地方連,這台電腦不用開放任何連接埠。", p);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// ── 帳號(薄後端) ──
|
|
|
|
|
|
setting_card(ui, p, |ui| {
|
|
|
|
|
|
setting_title(ui, "AnyBot 帳號", "帳號伺服器保管帳號、裝置清單和加密備份,手機從外面連進來也靠它轉送。", p);
|
|
|
|
|
|
let s = &self.state.remote;
|
|
|
|
|
|
if !s.host_token.is_empty() {
|
|
|
|
|
|
let status = remote::hub().relay_status();
|
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
|
let ok = status == "已連線";
|
|
|
|
|
|
let (r, _) = ui.allocate_exact_size(vec2(10.0, 10.0), egui::Sense::hover());
|
|
|
|
|
|
ui.painter().circle_filled(r.center(), 4.0, if ok { Color32::from_rgb(0x14, 0xc3, 0x70) } else { p.text3 });
|
|
|
|
|
|
ui.label(RichText::new(format!("{} · {}", s.relay_user, s.relay_url)).size(FONT_BASE));
|
|
|
|
|
|
ui.label(RichText::new(if status.is_empty() { "—".to_string() } else { status }).size(12.0).color(p.text3));
|
|
|
|
|
|
});
|
|
|
|
|
|
hint(ui, format!("手機打開 {} 用同一個帳號登入就能用。可以「加入主畫面」當成 App。", s.relay_url), p);
|
|
|
|
|
|
ui.add_space(4.0);
|
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
|
ui.label(RichText::new(t("這台電腦在手機上叫")).size(13.0).color(p.text2));
|
|
|
|
|
|
if ui.add(egui::TextEdit::singleline(&mut self.state.remote.host_name).desired_width(180.0)).lost_focus() {
|
|
|
|
|
|
changed = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if ui.checkbox(&mut self.state.remote.auto_backup, t("每天自動備份到帳號(加密,金鑰由你的密碼產生,伺服器打不開)")).changed() {
|
|
|
|
|
|
changed = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
|
let busy = self.rm.busy.load(Ordering::SeqCst);
|
|
|
|
|
|
if ui.add_enabled(!busy, secondary_button(if busy { "備份中…" } else { "立刻備份" })).clicked() {
|
|
|
|
|
|
self.remote_backup();
|
|
|
|
|
|
}
|
|
|
|
|
|
if self.state.remote.last_backup > 0 {
|
|
|
|
|
|
let t = chrono::DateTime::from_timestamp(self.state.remote.last_backup, 0).map(|d| d.with_timezone(&chrono::Local).format("%m/%d %H:%M").to_string()).unwrap_or_default();
|
|
|
|
|
|
ui.label(RichText::new(format!("上次備份 {t}")).size(12.0).color(p.text3));
|
|
|
|
|
|
}
|
|
|
|
|
|
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
|
|
|
|
|
|
if ui.add(egui::Button::new(RichText::new(t("登出帳號")).size(12.5).color(p.danger)).frame(false)).clicked() {
|
|
|
|
|
|
let keep_name = self.state.remote.host_name.clone();
|
2026-11-05 07:48:20 +00:00
|
|
|
|
// Say goodbye to the account server: the machine's registration is
|
|
|
|
|
|
// removed, so its key dies with the sign-out.
|
|
|
|
|
|
let (url, token) = (self.state.remote.relay_url.clone(), self.state.remote.host_token.clone());
|
|
|
|
|
|
if !url.is_empty() && !token.is_empty() {
|
|
|
|
|
|
std::thread::spawn(move || {
|
|
|
|
|
|
let _ = remote::relay_post(&format!("{url}/relay/host/remove"), &token, &serde_json::json!({}));
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let s = &mut self.state.remote;
|
|
|
|
|
|
s.host_id.clear();
|
|
|
|
|
|
s.host_token.clear();
|
|
|
|
|
|
s.backup_key.clear();
|
|
|
|
|
|
s.host_name = keep_name;
|
|
|
|
|
|
changed = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
let busy = self.rm.join_rx.is_some();
|
|
|
|
|
|
form_row(ui, "帳號伺服器", p, |ui| {
|
|
|
|
|
|
ui.add(egui::TextEdit::singleline(&mut self.rm.relay_url).hint_text(t("https://anybot.你的網域")).desired_width(f32::INFINITY));
|
|
|
|
|
|
});
|
|
|
|
|
|
form_row(ui, "帳號", p, |ui| {
|
|
|
|
|
|
ui.add(egui::TextEdit::singleline(&mut self.rm.user).desired_width(f32::INFINITY));
|
|
|
|
|
|
});
|
|
|
|
|
|
form_row(ui, "密碼", p, |ui| {
|
|
|
|
|
|
ui.add(egui::TextEdit::singleline(&mut self.rm.pass).password(true).desired_width(f32::INFINITY));
|
|
|
|
|
|
});
|
Bug sweep: gates, relay 2FA, Windows input, snapshots, encodings
Permissions and reach
- a file leaving a computer passes the same questions as reading it;
"looking" shell commands that do more than look ask first
- a symlink out of the work/sealed folder counts as outside it
(real paths, not just lexical ones); the search walk skips links
- web_fetch and skill_install read the public web only: localhost, the
LAN and cloud metadata are refused, at every redirect
- preview shows a file without running it; browser_upload may ask
- vault: logins no longer match across shared suffixes (pages.dev,
com.tw, ...); registrable_domain knows public suffixes
- axwrite: found elements are retained (use-after-free)
Relay
- replacing or turning off 2FA needs the current code (rate-limited);
new recovery codes only count once enrollment is verified
- a removed computer loses its socket and its `call` access
- a site name taken by another account answers 409
- RELAY_TRUST_PROXY: the login lock counts the caller's address, not
the proxy's (compose files and README)
- httpd: half a body is not a request
Desktop
- sign-in, join and restore work with 2FA on (code field; --serve reads
ANYBOT_ACCOUNT_CODE; the setup wizard points to a pairing code)
- Windows: text was typed twice; modifiers are held through click, drag
and scroll; horizontal scroll; screen control is no longer refused
- a recording that hits the limit is transcribed, not thrown away
- bot's computer: a new home volume restores the snapshot; a snapshot
is read through before the home is wiped; a failed volume removal
stops reset/restore
- events of a stopped turn no longer land in the next one; each channel
message gets a turn of its own
- saving a bot's settings keeps what it got meanwhile (three-way merge);
a save file that cannot be read is kept
- pages in Big5/GBK/Shift_JIS are read in their own encoding
(encoding_rs); osascript output past 64 KB no longer stalls
- pick_tab keeps a job's own non-http tab; pictures larger than the
texture limit are fitted; the auto-update time field takes typing
- skills live in <data>/skills; memories are unnumbered in the prompt;
the phone may skillify and skill_install
CI
- the test step fails when the tests fail (it piped into tail)
Tests: anybot 268 passed, 27 ignored; relay 16 passed; clippy unchanged.
Not run: Windows on a real machine (win.rs type-checked alone), the
Docker paths of the bot's computer, the live accessibility writes.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-10 03:46:17 +00:00
|
|
|
|
if self.rm.need_code {
|
|
|
|
|
|
form_row(ui, "驗證碼", p, |ui| {
|
|
|
|
|
|
ui.add(egui::TextEdit::singleline(&mut self.rm.code).hint_text(t("驗證器 App 的六位碼,或一組恢復碼")).desired_width(f32::INFINITY));
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
ui.checkbox(&mut self.rm.create, t("建立新帳號"));
|
|
|
|
|
|
if self.rm.create {
|
|
|
|
|
|
form_row(ui, "邀請碼", p, |ui| {
|
|
|
|
|
|
ui.add(egui::TextEdit::singleline(&mut self.rm.invite).hint_text(t("伺服器設定了才需要")).desired_width(f32::INFINITY));
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
|
let ready = !self.rm.relay_url.trim().is_empty() && !self.rm.user.trim().is_empty() && self.rm.pass.len() >= 8;
|
|
|
|
|
|
if ui.add_enabled(ready && !busy, primary_button(if busy { "連線中…" } else if self.rm.create { "建立並登入" } else { "登入" }, p)).clicked() {
|
|
|
|
|
|
let (tx, rx) = channel();
|
|
|
|
|
|
self.rm.join_rx = Some(rx);
|
Bug sweep: gates, relay 2FA, Windows input, snapshots, encodings
Permissions and reach
- a file leaving a computer passes the same questions as reading it;
"looking" shell commands that do more than look ask first
- a symlink out of the work/sealed folder counts as outside it
(real paths, not just lexical ones); the search walk skips links
- web_fetch and skill_install read the public web only: localhost, the
LAN and cloud metadata are refused, at every redirect
- preview shows a file without running it; browser_upload may ask
- vault: logins no longer match across shared suffixes (pages.dev,
com.tw, ...); registrable_domain knows public suffixes
- axwrite: found elements are retained (use-after-free)
Relay
- replacing or turning off 2FA needs the current code (rate-limited);
new recovery codes only count once enrollment is verified
- a removed computer loses its socket and its `call` access
- a site name taken by another account answers 409
- RELAY_TRUST_PROXY: the login lock counts the caller's address, not
the proxy's (compose files and README)
- httpd: half a body is not a request
Desktop
- sign-in, join and restore work with 2FA on (code field; --serve reads
ANYBOT_ACCOUNT_CODE; the setup wizard points to a pairing code)
- Windows: text was typed twice; modifiers are held through click, drag
and scroll; horizontal scroll; screen control is no longer refused
- a recording that hits the limit is transcribed, not thrown away
- bot's computer: a new home volume restores the snapshot; a snapshot
is read through before the home is wiped; a failed volume removal
stops reset/restore
- events of a stopped turn no longer land in the next one; each channel
message gets a turn of its own
- saving a bot's settings keeps what it got meanwhile (three-way merge);
a save file that cannot be read is kept
- pages in Big5/GBK/Shift_JIS are read in their own encoding
(encoding_rs); osascript output past 64 KB no longer stalls
- pick_tab keeps a job's own non-http tab; pictures larger than the
texture limit are fitted; the auto-update time field takes typing
- skills live in <data>/skills; memories are unnumbered in the prompt;
the phone may skillify and skill_install
CI
- the test step fails when the tests fail (it piped into tail)
Tests: anybot 268 passed, 27 ignored; relay 16 passed; clippy unchanged.
Not run: Windows on a real machine (win.rs type-checked alone), the
Docker paths of the bot's computer, the live accessibility writes.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-10 03:46:17 +00:00
|
|
|
|
let (url, user, pass, create, invite, base, code) = (self.rm.relay_url.clone(), self.rm.user.trim().to_string(), self.rm.pass.clone(), self.rm.create, self.rm.invite.clone(), self.state.remote.clone(), self.rm.code.clone());
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
std::thread::spawn(move || {
|
2026-11-05 06:25:01 +00:00
|
|
|
|
// Signed in: look right away for the bots the account already has.
|
Bug sweep: gates, relay 2FA, Windows input, snapshots, encodings
Permissions and reach
- a file leaving a computer passes the same questions as reading it;
"looking" shell commands that do more than look ask first
- a symlink out of the work/sealed folder counts as outside it
(real paths, not just lexical ones); the search walk skips links
- web_fetch and skill_install read the public web only: localhost, the
LAN and cloud metadata are refused, at every redirect
- preview shows a file without running it; browser_upload may ask
- vault: logins no longer match across shared suffixes (pages.dev,
com.tw, ...); registrable_domain knows public suffixes
- axwrite: found elements are retained (use-after-free)
Relay
- replacing or turning off 2FA needs the current code (rate-limited);
new recovery codes only count once enrollment is verified
- a removed computer loses its socket and its `call` access
- a site name taken by another account answers 409
- RELAY_TRUST_PROXY: the login lock counts the caller's address, not
the proxy's (compose files and README)
- httpd: half a body is not a request
Desktop
- sign-in, join and restore work with 2FA on (code field; --serve reads
ANYBOT_ACCOUNT_CODE; the setup wizard points to a pairing code)
- Windows: text was typed twice; modifiers are held through click, drag
and scroll; horizontal scroll; screen control is no longer refused
- a recording that hits the limit is transcribed, not thrown away
- bot's computer: a new home volume restores the snapshot; a snapshot
is read through before the home is wiped; a failed volume removal
stops reset/restore
- events of a stopped turn no longer land in the next one; each channel
message gets a turn of its own
- saving a bot's settings keeps what it got meanwhile (three-way merge);
a save file that cannot be read is kept
- pages in Big5/GBK/Shift_JIS are read in their own encoding
(encoding_rs); osascript output past 64 KB no longer stalls
- pick_tab keeps a job's own non-http tab; pictures larger than the
texture limit are fitted; the auto-update time field takes typing
- skills live in <data>/skills; memories are unnumbered in the prompt;
the phone may skillify and skill_install
CI
- the test step fails when the tests fail (it piped into tail)
Tests: anybot 268 passed, 27 ignored; relay 16 passed; clippy unchanged.
Not run: Windows on a real machine (win.rs type-checked alone), the
Docker paths of the bot's computer, the live accessibility writes.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-10 03:46:17 +00:00
|
|
|
|
let r = remote::relay_join(&base, &url, &user, &pass, create, &invite, &code).map(|s| {
|
|
|
|
|
|
let found = remote::find_account_bots(&s, &pass, &code);
|
2026-11-05 06:25:01 +00:00
|
|
|
|
(s, found)
|
|
|
|
|
|
});
|
|
|
|
|
|
let _ = tx.send(r);
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
if ui.add_enabled(ready && self.rm.restore_rx.is_none(), secondary_button("從帳號備份還原")).on_hover_text(t("把這台電腦的 Bot 換成帳號裡最新的備份")).clicked() {
|
|
|
|
|
|
let (tx, rx) = channel();
|
|
|
|
|
|
self.rm.restore_rx = Some(rx);
|
Bug sweep: gates, relay 2FA, Windows input, snapshots, encodings
Permissions and reach
- a file leaving a computer passes the same questions as reading it;
"looking" shell commands that do more than look ask first
- a symlink out of the work/sealed folder counts as outside it
(real paths, not just lexical ones); the search walk skips links
- web_fetch and skill_install read the public web only: localhost, the
LAN and cloud metadata are refused, at every redirect
- preview shows a file without running it; browser_upload may ask
- vault: logins no longer match across shared suffixes (pages.dev,
com.tw, ...); registrable_domain knows public suffixes
- axwrite: found elements are retained (use-after-free)
Relay
- replacing or turning off 2FA needs the current code (rate-limited);
new recovery codes only count once enrollment is verified
- a removed computer loses its socket and its `call` access
- a site name taken by another account answers 409
- RELAY_TRUST_PROXY: the login lock counts the caller's address, not
the proxy's (compose files and README)
- httpd: half a body is not a request
Desktop
- sign-in, join and restore work with 2FA on (code field; --serve reads
ANYBOT_ACCOUNT_CODE; the setup wizard points to a pairing code)
- Windows: text was typed twice; modifiers are held through click, drag
and scroll; horizontal scroll; screen control is no longer refused
- a recording that hits the limit is transcribed, not thrown away
- bot's computer: a new home volume restores the snapshot; a snapshot
is read through before the home is wiped; a failed volume removal
stops reset/restore
- events of a stopped turn no longer land in the next one; each channel
message gets a turn of its own
- saving a bot's settings keeps what it got meanwhile (three-way merge);
a save file that cannot be read is kept
- pages in Big5/GBK/Shift_JIS are read in their own encoding
(encoding_rs); osascript output past 64 KB no longer stalls
- pick_tab keeps a job's own non-http tab; pictures larger than the
texture limit are fitted; the auto-update time field takes typing
- skills live in <data>/skills; memories are unnumbered in the prompt;
the phone may skillify and skill_install
CI
- the test step fails when the tests fail (it piped into tail)
Tests: anybot 268 passed, 27 ignored; relay 16 passed; clippy unchanged.
Not run: Windows on a real machine (win.rs type-checked alone), the
Docker paths of the bot's computer, the live accessibility writes.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-10 03:46:17 +00:00
|
|
|
|
let (url, user, pass, code) = (self.rm.relay_url.clone(), self.rm.user.trim().to_string(), self.rm.pass.clone(), self.rm.code.clone());
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
std::thread::spawn(move || {
|
Bug sweep: gates, relay 2FA, Windows input, snapshots, encodings
Permissions and reach
- a file leaving a computer passes the same questions as reading it;
"looking" shell commands that do more than look ask first
- a symlink out of the work/sealed folder counts as outside it
(real paths, not just lexical ones); the search walk skips links
- web_fetch and skill_install read the public web only: localhost, the
LAN and cloud metadata are refused, at every redirect
- preview shows a file without running it; browser_upload may ask
- vault: logins no longer match across shared suffixes (pages.dev,
com.tw, ...); registrable_domain knows public suffixes
- axwrite: found elements are retained (use-after-free)
Relay
- replacing or turning off 2FA needs the current code (rate-limited);
new recovery codes only count once enrollment is verified
- a removed computer loses its socket and its `call` access
- a site name taken by another account answers 409
- RELAY_TRUST_PROXY: the login lock counts the caller's address, not
the proxy's (compose files and README)
- httpd: half a body is not a request
Desktop
- sign-in, join and restore work with 2FA on (code field; --serve reads
ANYBOT_ACCOUNT_CODE; the setup wizard points to a pairing code)
- Windows: text was typed twice; modifiers are held through click, drag
and scroll; horizontal scroll; screen control is no longer refused
- a recording that hits the limit is transcribed, not thrown away
- bot's computer: a new home volume restores the snapshot; a snapshot
is read through before the home is wiped; a failed volume removal
stops reset/restore
- events of a stopped turn no longer land in the next one; each channel
message gets a turn of its own
- saving a bot's settings keeps what it got meanwhile (three-way merge);
a save file that cannot be read is kept
- pages in Big5/GBK/Shift_JIS are read in their own encoding
(encoding_rs); osascript output past 64 KB no longer stalls
- pick_tab keeps a job's own non-http tab; pictures larger than the
texture limit are fitted; the auto-update time field takes typing
- skills live in <data>/skills; memories are unnumbered in the prompt;
the phone may skillify and skill_install
CI
- the test step fails when the tests fail (it piped into tail)
Tests: anybot 268 passed, 27 ignored; relay 16 passed; clippy unchanged.
Not run: Windows on a real machine (win.rs type-checked alone), the
Docker paths of the bot's computer, the live accessibility writes.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-10 03:46:17 +00:00
|
|
|
|
let _ = tx.send(remote::restore(&url, &user, &pass, &code));
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
hint(ui, "密碼至少 8 個字。帳號伺服器在 relay/ 資料夾,可以放在任何一台小主機(說明見 relay/README.md)。", p);
|
|
|
|
|
|
}
|
|
|
|
|
|
let note = self.rm.note.lock().unwrap().clone();
|
|
|
|
|
|
if !note.is_empty() {
|
|
|
|
|
|
ui.label(RichText::new(note).size(12.5).color(p.text2));
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-11-04 09:46:43 +00:00
|
|
|
|
// ── 大腦 ──
|
|
|
|
|
|
if !self.state.remote.host_token.is_empty() {
|
|
|
|
|
|
setting_card(ui, p, |ui| {
|
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
|
ui.label(RichText::new(t("大腦")).size(FONT_BASE).strong());
|
|
|
|
|
|
help_mark(ui, "帳號裡選一台 AnyBot 當大腦(通常是跟帳號伺服器放在一起、一直開著的那台)。所有 Bot、聊天、記憶和例行任務都放在大腦上,由它思考和排程。其他電腦打開 AnyBot 看到的都是同一份,同時也是大腦的手腳:大腦的 Bot 可以透過裝置連結操作它們。大腦連不到時,這裡還能看之前的對話,但不能傳訊息,連回來就恢復。", p);
|
|
|
|
|
|
});
|
|
|
|
|
|
let s = &self.state.remote;
|
|
|
|
|
|
let status = self.mir.status.lock().unwrap().clone();
|
|
|
|
|
|
if self.mir.on {
|
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
|
let (r, _) = ui.allocate_exact_size(vec2(10.0, 10.0), egui::Sense::hover());
|
|
|
|
|
|
ui.painter().circle_filled(r.center(), 4.0, if self.mir.online { Color32::from_rgb(0x14, 0xc3, 0x70) } else { p.text3 });
|
|
|
|
|
|
ui.label(RichText::new(status).size(13.0).color(p.text2));
|
|
|
|
|
|
});
|
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
|
let busy = self.mir.moving.load(Ordering::SeqCst);
|
|
|
|
|
|
if ui.add_enabled(self.mir.online && !busy, secondary_button("把這台的 Bot 搬過去")).on_hover_text(t("把這台電腦原本的 Bot(連同聊天)、模型金鑰、技能和連接器複製到大腦。這台的原始資料不會刪掉。")).clicked() {
|
|
|
|
|
|
self.mirror_move_local();
|
|
|
|
|
|
}
|
|
|
|
|
|
if ui.add(secondary_button("改回用這台自己的 Bot")).clicked() {
|
|
|
|
|
|
self.mir.leave = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
let note = self.mir.move_note.lock().unwrap().clone();
|
|
|
|
|
|
if !note.is_empty() {
|
|
|
|
|
|
ui.label(RichText::new(note).size(12.5).color(p.text2));
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
ui.label(RichText::new(t("這台就是大腦:Bot 在這台電腦上思考和工作。")).size(13.0).color(p.text2));
|
|
|
|
|
|
let me = s.host_id.clone();
|
2026-11-04 12:56:06 +00:00
|
|
|
|
let peers: Vec<(String, String, bool)> = self.rm.peers.lock().unwrap().iter().filter(|(id, _, _)| !id.is_empty() && *id != me && !remote::is_hands(id)).cloned().collect();
|
2026-11-04 09:46:43 +00:00
|
|
|
|
if peers.is_empty() {
|
2026-11-04 12:56:06 +00:00
|
|
|
|
hint(ui, "帳號裡還沒有別台可以當大腦的 AnyBot。", p);
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
for (id, name, online) in peers {
|
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
|
let (r, _) = ui.allocate_exact_size(vec2(10.0, 10.0), egui::Sense::hover());
|
|
|
|
|
|
ui.painter().circle_filled(r.center(), 4.0, if online { Color32::from_rgb(0x14, 0xc3, 0x70) } else { p.text3 });
|
|
|
|
|
|
ui.label(RichText::new(&name).size(13.5));
|
|
|
|
|
|
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
|
|
|
|
|
|
if ui.add_enabled(online, secondary_button("改用它當大腦")).clicked() {
|
|
|
|
|
|
self.mir.want = Some((id.clone(), name.clone()));
|
|
|
|
|
|
// The brain's bots may use this computer (each action still asks).
|
|
|
|
|
|
self.state.remote.device_link = true;
|
|
|
|
|
|
changed = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-04 12:56:06 +00:00
|
|
|
|
self.pair_section(ui);
|
2026-11-04 09:46:43 +00:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
// ── 同一個網路 ──
|
|
|
|
|
|
setting_card(ui, p, |ui| {
|
|
|
|
|
|
setting_title(ui, "同一個網路直接連", "手機和這台電腦在同一個 Wi-Fi,或都裝了 Tailscale 時使用。", p);
|
|
|
|
|
|
let has_pw = !self.state.remote.password.is_empty();
|
|
|
|
|
|
if ui.add_enabled(has_pw, egui::Checkbox::new(&mut self.state.remote.lan, t("讓手機直接連這台電腦"))).changed() {
|
|
|
|
|
|
changed = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if self.state.remote.lan {
|
|
|
|
|
|
if let Some(port) = remote::lan_port() {
|
|
|
|
|
|
for a in remote::addresses(port) {
|
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
|
ui.label(RichText::new(&a).monospace().size(13.0));
|
|
|
|
|
|
if ui.small_button(t("複製")).clicked() {
|
|
|
|
|
|
ui.ctx().copy_text(a.clone());
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
ui.add_space(4.0);
|
|
|
|
|
|
form_row(ui, if has_pw { "更改手機密碼" } else { "設定手機密碼" }, p, |ui| {
|
|
|
|
|
|
ui.add(egui::TextEdit::singleline(&mut self.rm.pw1).password(true).hint_text(t("至少 8 個字")).desired_width(f32::INFINITY));
|
|
|
|
|
|
});
|
|
|
|
|
|
form_row(ui, "再輸入一次", p, |ui| {
|
|
|
|
|
|
ui.add(egui::TextEdit::singleline(&mut self.rm.pw2).password(true).desired_width(f32::INFINITY));
|
|
|
|
|
|
});
|
|
|
|
|
|
let ok = self.rm.pw1.chars().count() >= 8 && self.rm.pw1 == self.rm.pw2;
|
|
|
|
|
|
if ui.add_enabled(ok, secondary_button("儲存密碼")).clicked() {
|
|
|
|
|
|
self.state.remote.password = crate::httpd::hash_password(&self.rm.pw1);
|
|
|
|
|
|
// A new password signs every phone out.
|
|
|
|
|
|
self.state.remote.devices.clear();
|
|
|
|
|
|
self.rm.pw1.clear();
|
|
|
|
|
|
self.rm.pw2.clear();
|
|
|
|
|
|
changed = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if !self.rm.pw2.is_empty() && self.rm.pw1 != self.rm.pw2 {
|
|
|
|
|
|
hint(ui, "兩次輸入的密碼不一樣", p);
|
|
|
|
|
|
}
|
|
|
|
|
|
hint(ui, "不要把這個連接埠開放到網際網路上;從外面連請用上面的帳號,或 Tailscale。", p);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// ── 允許手機做什麼 ──
|
|
|
|
|
|
setting_card(ui, p, |ui| {
|
|
|
|
|
|
setting_title(ui, "手機可以做什麼", "聊天、核准、看 Bot 的電腦一律可以。下面這些會碰到這台電腦本身,預設關閉。", p);
|
|
|
|
|
|
if ui.checkbox(&mut self.state.remote.mac_from_phone, t("從手機看這台電腦的螢幕並操作(點、打字、按鍵)")).changed() {
|
|
|
|
|
|
changed = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ui.checkbox(&mut self.state.remote.device_link, t("裝置連結:讓帳號裡其他的 AnyBot(例如放在伺服器上的)操作這台電腦")).changed() {
|
|
|
|
|
|
changed = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
hint(ui, "裝置連結開著時,伺服器上的 Bot 可以把「你的電腦」的螢幕、檔案、指令和 Mac App 工具交給這台電腦執行。每個動作仍照那邊的權限規則詢問你(手機上也能核准)。", p);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// ── 已登入的裝置 ──
|
|
|
|
|
|
setting_card(ui, p, |ui| {
|
|
|
|
|
|
setting_title(ui, "直接連線的裝置", "用手機密碼登入過的手機和瀏覽器", p);
|
|
|
|
|
|
if self.state.remote.devices.is_empty() {
|
|
|
|
|
|
hint(ui, "還沒有", p);
|
|
|
|
|
|
}
|
|
|
|
|
|
let mut remove = None;
|
|
|
|
|
|
for (i, d) in self.state.remote.devices.iter().enumerate() {
|
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
|
ui.label(RichText::new(&d.name).size(FONT_BASE));
|
|
|
|
|
|
let seen = chrono::DateTime::from_timestamp(d.last_seen.max(d.created), 0).map(|t| t.with_timezone(&chrono::Local).format("最近 %m/%d %H:%M").to_string()).unwrap_or_default();
|
|
|
|
|
|
ui.label(RichText::new(seen).size(12.0).color(p.text3));
|
|
|
|
|
|
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
|
|
|
|
|
|
if ui.add(egui::Button::new(RichText::new(t("登出")).size(12.0).color(p.danger)).frame(false)).clicked() {
|
|
|
|
|
|
remove = Some(i);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
if let Some(i) = remove {
|
|
|
|
|
|
self.state.remote.devices.remove(i);
|
|
|
|
|
|
changed = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// ── 團隊 ──
|
|
|
|
|
|
if !self.state.remote.host_token.is_empty() {
|
|
|
|
|
|
setting_card(ui, p, |ui| {
|
|
|
|
|
|
setting_title(ui, "分享給團隊", "讓帳號伺服器上的其他帳號也能用這台 AnyBot 的 Bot。", p);
|
|
|
|
|
|
hint(ui, "成員:可以和 Bot 聊天、附加檔案;Bot 會知道是誰在說話。管理員:另外可以核准 Bot 要做的事、停止、看和操作電腦畫面。需要你允許的事只通知你和管理員。", p);
|
|
|
|
|
|
let loaded = self.rm.members.lock().unwrap().clone();
|
|
|
|
|
|
if loaded.is_none() {
|
|
|
|
|
|
*self.rm.members.lock().unwrap() = Some(Ok(vec![]));
|
|
|
|
|
|
let (m, s) = (self.rm.members.clone(), self.state.remote.clone());
|
|
|
|
|
|
std::thread::spawn(move || *m.lock().unwrap() = Some(remote::members(&s)));
|
|
|
|
|
|
}
|
|
|
|
|
|
let mut change: Option<(String, &str)> = None;
|
|
|
|
|
|
match loaded {
|
|
|
|
|
|
Some(Ok(list)) => {
|
|
|
|
|
|
for (user, role) in list {
|
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
|
ui.label(RichText::new(&user).size(FONT_BASE));
|
|
|
|
|
|
ui.label(RichText::new(if role == "admin" { "管理員" } else { "成員" }).size(12.0).color(p.text3));
|
|
|
|
|
|
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
|
|
|
|
|
|
if ui.add(egui::Button::new(RichText::new(t("移除")).size(12.0).color(p.danger)).frame(false)).clicked() {
|
|
|
|
|
|
change = Some((user.clone(), "remove"));
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
Some(Err(e)) => hint(ui, format!("讀不到分享清單:{e}"), p),
|
|
|
|
|
|
None => {}
|
|
|
|
|
|
}
|
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
|
ui.add(egui::TextEdit::singleline(&mut self.rm.new_member).hint_text(t("對方的帳號")).desired_width(160.0));
|
|
|
|
|
|
ui.checkbox(&mut self.rm.new_admin, t("管理員"));
|
|
|
|
|
|
if ui.add_enabled(!self.rm.new_member.trim().is_empty(), secondary_button("分享")).clicked() {
|
|
|
|
|
|
change = Some((self.rm.new_member.trim().to_string(), if self.rm.new_admin { "admin" } else { "member" }));
|
|
|
|
|
|
self.rm.new_member.clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
// Talk to the relay off the window's thread, then show the new list.
|
|
|
|
|
|
if let Some((user, role)) = change {
|
|
|
|
|
|
let (m, note, s, role) = (self.rm.members.clone(), self.rm.note.clone(), self.state.remote.clone(), role.to_string());
|
|
|
|
|
|
std::thread::spawn(move || {
|
|
|
|
|
|
let r = remote::set_member(&s, &user, &role);
|
|
|
|
|
|
*note.lock().unwrap() = match r {
|
|
|
|
|
|
Ok(()) if role == "remove" => format!("已停止分享給 {user}"),
|
|
|
|
|
|
Ok(()) => format!("已分享給 {user}"),
|
|
|
|
|
|
Err(e) => e,
|
|
|
|
|
|
};
|
|
|
|
|
|
*m.lock().unwrap() = Some(remote::members(&s));
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ── 帳號裡的其他電腦 ──
|
|
|
|
|
|
if !self.state.remote.host_token.is_empty() {
|
|
|
|
|
|
setting_card(ui, p, |ui| {
|
|
|
|
|
|
setting_title(ui, "帳號裡的電腦", "登入同一個帳號的 AnyBot。開了裝置連結的電腦,Bot 可以操作它。", p);
|
|
|
|
|
|
if ui.small_button(t("重新整理")).clicked() || (self.rm.peers.lock().unwrap().is_empty() && !self.rm.busy.load(Ordering::SeqCst)) {
|
|
|
|
|
|
let (peers, s) = (self.rm.peers.clone(), self.state.remote.clone());
|
|
|
|
|
|
let first = peers.lock().unwrap().is_empty();
|
|
|
|
|
|
if first {
|
|
|
|
|
|
peers.lock().unwrap().push((String::new(), "讀取中…".into(), false));
|
|
|
|
|
|
}
|
|
|
|
|
|
std::thread::spawn(move || {
|
|
|
|
|
|
let v = remote::devices_online(&s);
|
|
|
|
|
|
*peers.lock().unwrap() = if v.is_empty() { vec![(String::new(), "(沒有)".into(), false)] } else { v };
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
for (id, name, online) in self.rm.peers.lock().unwrap().iter() {
|
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
|
let (r, _) = ui.allocate_exact_size(vec2(10.0, 10.0), egui::Sense::hover());
|
|
|
|
|
|
if !id.is_empty() {
|
|
|
|
|
|
ui.painter().circle_filled(r.center(), 4.0, if *online { Color32::from_rgb(0x14, 0xc3, 0x70) } else { p.text3 });
|
|
|
|
|
|
}
|
|
|
|
|
|
let me = *id == self.state.remote.host_id;
|
|
|
|
|
|
ui.label(RichText::new(format!("{name}{}", if me { "(這台)" } else { "" })).size(13.5));
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
if changed {
|
|
|
|
|
|
self.mark();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Other AnyBots of this account that let bots operate them (裝置連結), as computers.
|
|
|
|
|
|
pub(super) fn linked_devices(&self) -> Vec<tools::Target> {
|
|
|
|
|
|
if self.state.remote.host_token.is_empty() {
|
|
|
|
|
|
return vec![];
|
|
|
|
|
|
}
|
2026-11-05 06:40:01 +00:00
|
|
|
|
let has_hands = !remote::my_hands(&self.state.remote.host_id).is_empty();
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
self.rm
|
|
|
|
|
|
.peers
|
|
|
|
|
|
.lock()
|
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.filter(|(id, _, online)| !id.is_empty() && *online && *id != self.state.remote.host_id)
|
2026-11-05 06:40:01 +00:00
|
|
|
|
// A brain with hands of its own works on those, not on the account's other brains.
|
|
|
|
|
|
.filter(|(id, _, _)| !has_hands || remote::is_hands(id))
|
2026-11-05 08:47:28 +00:00
|
|
|
|
// A computer showing another brain lends its hands to that one, not to this.
|
|
|
|
|
|
.filter(|(id, _, _)| {
|
|
|
|
|
|
let uses = remote::peer_uses(id);
|
|
|
|
|
|
uses.is_empty() || uses == self.state.remote.host_id
|
|
|
|
|
|
})
|
2026-11-05 13:28:32 +00:00
|
|
|
|
.map(|(id, name, _)| tools::Target { name: name.clone(), place: tools::Place::Device { host: id.clone(), dir: String::new() } })
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
.collect()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
Phone: a home with the computers, pages and routines; each bot's settings a tap away; long jobs fold up
The phone page was bare: one row per bot, a chat listing every step, a menu with four lines.
- Home: the main bot large at the top with its model and last words, the other bots with times,
then its computers (own box and the account's, online or not, 看畫面), the newest pages and the
routines with their next run.
- Chat: the bot's name opens its settings — model (chat models only), computer, past conversations
(restore), regenerate, new chat. A turn's steps fold into 「已完成 N 個步驟」 when done (the newest
three stay while it works); copy and regenerate under replies; four ready starts in a new chat;
a jump back to the newest message.
- Menu: 外觀 (follow the phone, light, dark).
- API: api/state carries pages and models; each bot its model, computers, routines, past
conversations; POST api/bots/{id}/set | regenerate | restore. The home's last line skips errors.
Checked on a local copy of the brain's data (cut off from the account and Docker) at iPhone size.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 12:28:08 +00:00
|
|
|
|
|
|
|
|
|
|
/// A model one can chat with (not an image, video, speech or embedding one).
|
|
|
|
|
|
fn chats(model: &str) -> bool {
|
|
|
|
|
|
let m = model.to_lowercase();
|
|
|
|
|
|
!["imagine", "image", "video", "embed", "tts", "whisper", "audio", "moderation", "dall-e", "sora", "veo"].iter().any(|k| m.contains(k))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
|
mod phone_tests {
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn only_chat_models_are_offered() {
|
|
|
|
|
|
assert!(super::chats("grok-4.7") && super::chats("claude-opus-5-5") && super::chats("gpt-5-mini"));
|
|
|
|
|
|
assert!(!super::chats("grok-imagine-video-1.5") && !super::chats("text-embedding-3-large") && !super::chats("gpt-4o-mini-tts"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
The phone page does what the desktop does, laid out like it
A new mobile/index.html in the desktop's (and Grok Bot's) shape: the sidebar
with its sections and folders, the chat with steps, thinking, reactions, quotes
and the approval card, 對話詳細資訊, Bot 設定, routines, pages, computers and
設定. Each action goes to the desktop's own code on the app's thread
(api/act/<what> -> App::phone_act): appctl, set_pinned, restart_bot,
toggle_reaction, box_task, channels_restart and the rest. No new rules.
Keys, channel tokens and the vault never reach the phone; a model key can only
be written. Admins keep what the phone always let them do; making, changing or
deleting bots, routines, memories, pages, folders and settings stays the
owner's. The state the phone polls now carries the sidebar's section order.
Checked by using it on a preview brain: routines, memories, templates, folders,
keys, signing another phone out, approvals and a chat with a fake model.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 19:05:12 +00:00
|
|
|
|
|
|
|
|
|
|
// ---------- 手機: everything the desktop does, from the phone ----------
|
|
|
|
|
|
// Each action calls what the desktop's own button calls (appctl for the actions a bot can take
|
|
|
|
|
|
// too, set_pinned, restart_bot, toggle_reaction, enable_direct_mode, box_task…), so the phone
|
|
|
|
|
|
// adds no ways of its own. Members never get here (remote::role_allows); some things are the
|
|
|
|
|
|
// owner's alone: deleting a bot, permissions and rules, channels, connectors and the box's
|
|
|
|
|
|
// runtime, update and schedule. Keys, tokens and the vault's secrets are never sent.
|
|
|
|
|
|
|
|
|
|
|
|
/// Docker facts for the phone's 電腦 settings, refreshed in the background (asking Docker on the
|
|
|
|
|
|
/// app's thread would stall the window): (when, update available, gVisor here, runs on).
|
|
|
|
|
|
static BOX_FACTS: std::sync::Mutex<Option<(Instant, serde_json::Value)>> = std::sync::Mutex::new(None);
|
|
|
|
|
|
static BOX_FACTS_BUSY: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
|
|
|
|
|
|
|
|
|
|
|
|
fn box_facts() -> serde_json::Value {
|
|
|
|
|
|
let (stale, v) = {
|
|
|
|
|
|
let g = BOX_FACTS.lock().unwrap_or_else(|e| e.into_inner());
|
|
|
|
|
|
(g.as_ref().map(|(t, _)| t.elapsed().as_secs() > 20).unwrap_or(true), g.as_ref().map(|(_, v)| v.clone()).unwrap_or_else(|| json!({})))
|
|
|
|
|
|
};
|
|
|
|
|
|
// (Unit tests don't ask Docker.)
|
|
|
|
|
|
if stale && !cfg!(test) && !BOX_FACTS_BUSY.swap(true, std::sync::atomic::Ordering::SeqCst) {
|
|
|
|
|
|
std::thread::spawn(|| {
|
|
|
|
|
|
let (n, exec_ms, total_ms) = crate::cloudbox::step_stats();
|
|
|
|
|
|
let v = json!({
|
|
|
|
|
|
"update": crate::cloudbox::update_available(),
|
|
|
|
|
|
"gvisor": crate::cloudbox::host_has_gvisor(),
|
|
|
|
|
|
"running": crate::cloudbox::running_runtime(),
|
|
|
|
|
|
"steps": {"n": n, "exec_ms": exec_ms, "total_ms": total_ms},
|
|
|
|
|
|
});
|
|
|
|
|
|
*BOX_FACTS.lock().unwrap_or_else(|e| e.into_inner()) = Some((Instant::now(), v));
|
|
|
|
|
|
BOX_FACTS_BUSY.store(false, std::sync::atomic::Ordering::SeqCst);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
v
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// At most `n` characters (the phone shows excerpts).
|
|
|
|
|
|
fn clip(s: &str, n: usize) -> String {
|
|
|
|
|
|
if s.chars().count() <= n {
|
|
|
|
|
|
s.to_string()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
format!("{}…", s.chars().take(n).collect::<String>())
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl App {
|
|
|
|
|
|
pub(super) fn phone_act(&mut self, ctx: &egui::Context, action: &str, b: &serde_json::Value, role: &str) -> serde_json::Value {
|
|
|
|
|
|
let owner = role == "owner";
|
|
|
|
|
|
let bot = b["bot"].as_u64().unwrap_or(0);
|
|
|
|
|
|
let s = |k: &str| b[k].as_str().unwrap_or("").trim().to_string();
|
|
|
|
|
|
let fail = |e: &str| json!({"error": e});
|
|
|
|
|
|
let done = |t: &str| json!({"ok": true, "text": t});
|
|
|
|
|
|
let owner_only = || json!({"error": "這件事只有這台 AnyBot 的擁有者能做"});
|
|
|
|
|
|
// 團隊: an admin keeps what the phone always let them do (approve, stop, the screens, the
|
|
|
|
|
|
// model and computer, a new chat, regenerate) plus looking and small chat things; making,
|
|
|
|
|
|
// changing or deleting bots, routines, memories, pages and settings stays the owner's.
|
|
|
|
|
|
let admin_ok = match action {
|
A turn cut off by a crash leaves a 「繼續」 card, and nothing it may have done runs twice
Each bot keeps a work log (oplog/bot-<id>.jsonl, after pi's durable-harness design, cut down):
before something happens a line says it is about to — the turn, each model call, each step once
its checks passed (with the arguments it runs with and whether it may run again), each message
typed mid-turn — synced to disk first. When the turn ends the file shrinks to the messages still
waiting, usually nothing.
On the next start after AnyBot was killed mid-turn, the log puts the chat right before anything
runs: the message the turn answered comes back if the chat lost it; a step that was running and
reaches outside (a text, a click, a file, a published site) shows as 「可能已經執行了」, both to the
person and in the result the bot reads — no longer as "not allowed"; a step that only looked shows
as cut off; messages typed mid-turn that never reached the bot go back into the chat. The chat is
saved, then the log closes the turn. A turn the person didn't stop ends with a 「繼續」 card (what
it was doing, what may have run, the messages put back); it goes on only when they press it — in
the window, on a screen of the brain, or on the phone — from where its steps stand, never running
a step that may have run again. Pressing stop is on disk at once, and a stopped turn stays
stopped.
Also in the turn loop:
- 自動審核 that doesn't answer (or answers something that isn't a verdict) asks the person; in
直接操作 mode it used to let the step through unchecked.
- "Too long for this model" folds older messages into a summary and asks the same step again,
once per thing the person said, instead of ending the turn.
- Folding keeps the person's chat whole: the summary goes in at the fold and the model reads from
the newest summary on (it used to delete what it folded).
- A step moved to the chosen computer runs there, but the chat keeps the call as the model wrote
it; the result says where it ran.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha5F5gJt93t3yEx3XcS
2026-11-08 16:49:12 +00:00
|
|
|
|
"detail" | "settings" | "pages" | "restart_bot" | "react" | "reply" | "resume" => true,
|
The phone page does what the desktop does, laid out like it
A new mobile/index.html in the desktop's (and Grok Bot's) shape: the sidebar
with its sections and folders, the chat with steps, thinking, reactions, quotes
and the approval card, 對話詳細資訊, Bot 設定, routines, pages, computers and
設定. Each action goes to the desktop's own code on the app's thread
(api/act/<what> -> App::phone_act): appctl, set_pinned, restart_bot,
toggle_reaction, box_task, channels_restart and the rest. No new rules.
Keys, channel tokens and the vault never reach the phone; a model key can only
be written. Admins keep what the phone always let them do; making, changing or
deleting bots, routines, memories, pages, folders and settings stays the
owner's. The state the phone polls now carries the sidebar's section order.
Checked by using it on a preview brain: routines, memories, templates, folders,
keys, signing another phone out, approvals and a chat with a fake model.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 19:05:12 +00:00
|
|
|
|
"bot" => b["key"].as_str() == Some("unread"),
|
|
|
|
|
|
"box" => matches!(b["op"].as_str(), Some("wake" | "disk")),
|
|
|
|
|
|
_ => false,
|
|
|
|
|
|
};
|
|
|
|
|
|
if !owner && !admin_ok {
|
|
|
|
|
|
return owner_only();
|
|
|
|
|
|
}
|
|
|
|
|
|
match action {
|
記憶: a page to see it, a few lines picked while typing, a local model
The memory had grown into a list carried whole, a top-14 recalled by a
trigram index and pasted into the system prompt with the clock, and a
page that broke its own layout. Nobody could see what went to the
model, the prompt cache missed every message, and 「記住」 kept saying
the same thing twice. Rebuilt per the spec (docs/memory.md):
- Three kinds in memory.db: 記得的事 (fact), 做過的事 (event, a line per
finished turn), 整理過的 (rollup). Each keeps pinned, uses,
last_used, deleted, superseded_by, span. state.json keeps the facts
as the copy that syncs; the page reads SQLite.
- Search: jieba words ∪ CJK bigrams in an FTS5 unicode61 table
(Traditional text goes through Simplified first), weighted share of
query terms hit; plus local vectors, vec = clamp((cos−0.35)/0.35).
score = max + 0.15×min, events ×0.9. ≥0.15 suggested, ≥0.5 ticked,
≥0.55 carried when nobody chose (3 at most).
- What the model gets: the system prompt has the time zone and the
pinned memories only, the same every turn. Each person message gets
〔送出時間〕 and 〔相關記憶〕 from Message.memories, built in
group_history into a transient Message.context, so the beginning of
a chat reads the same next turn (cache hits) and the event log,
skills and audit see only what was typed. A memory already carried
in view isn't carried again; each carry counts a use.
- Picks travel with the message: Cmd::Send / POST send / sync act
"memories" (empty = none; absent = the brain chooses, once, saved).
- remember finds the like one (cos ≥ 0.85 or the same words) and asks
for `replaces`; the old one is superseded, never carried. A fact
forgotten and remembered again comes back. New search_memory
(query, kind), with dates; read-only.
- Nightly on the brain, no model: events past 30 days fold into a line
per week (「11/3–11/9 做過的事(14 件):整理照片 ×3…」, ≤400 chars,
like with like by words or vectors), weeks past 180 days into months;
the folded go to 最近刪除 for 30 days. Facts are never removed. The
page offers duplicates, facts unused for half a year, and what can
fold now.
- Local model: minishlab/potion-multilingual-128M through m2v.rs (same
token ids as model2vec-rs on 13/13 sentences, cos ≥ 0.9999, without
tokenizers' 1.1 GB). Converted while downloading: vocab.bin,
table.i8 (int8 + row scales), dims.json, 137 MB kept of 530 MB;
ANYBOT_HF_BASE picks a mirror (now passed into the server's brain
container too). Loaded when first needed (34 ms), let go after 10
idle minutes. The brain loads it; a screen only with a document
folder set; hands and phones never. 設定 › 一般 › 語意搜尋:
本機模型/Ollama/關閉; a new engine clears every vector.
- Three files, three connections: memory.db (backed up nightly, 7
kept), docs.db (a cache), oplog/audit.db (30 days). An old audit.db
hands its memories and documents over once and shrinks (a real one:
172 MB → 16 KB). docs_search scans every chunk now, vectors cached
in RAM (it stopped at 8000); FTS optimize + VACUUM daily (260 MB of
tombstones over 31 MB of text).
- API: POST /api/memory (owner) and /api/sync/memory (mirror). Reads
answer on the HTTP thread; writes go through phone_act("memory").
- Screens: a memory dialog (Bot menu 記憶…, Bot settings 打開記憶) with
counts, live search, filters, suggestions, per-item kind/date/uses
and pin/edit/forget/restore; chips above the composer 300 ms after
typing stops, with a token estimate; 「帶了 N 條記憶」 under person
messages. The phone has the same as a 記憶 tab, chips and tag.
Checked: make test passes (app 297, relay 16), with new tests for the
scores and thresholds, Traditional Chinese segmentation, remember's
dedupe and replaces, two turns sending the same beginning, no double
carry, weekly/monthly folding and the trash, and the audit.db move.
Brain idle 37 MB as before, ~230 MB with the model loaded; search on
the brain 0.2–0.5 ms, 7–44 ms from the phone page. A deadlock found on
the way (stats re-taking the lock) is fixed and tested.
Docs: docs/memory.md has the whole design; FEATURES.md, protocol,
architecture (zh/en), multi-device and install say what changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3SYw9JJ9dXwaNvYh4
2026-11-10 23:46:50 +00:00
|
|
|
|
"memory" => {
|
|
|
|
|
|
let v = crate::memory::api_write(&mut self.state, b);
|
|
|
|
|
|
if v.get("ok").is_some() {
|
|
|
|
|
|
self.dirty = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
v
|
|
|
|
|
|
}
|
The phone page does what the desktop does, laid out like it
A new mobile/index.html in the desktop's (and Grok Bot's) shape: the sidebar
with its sections and folders, the chat with steps, thinking, reactions, quotes
and the approval card, 對話詳細資訊, Bot 設定, routines, pages, computers and
設定. Each action goes to the desktop's own code on the app's thread
(api/act/<what> -> App::phone_act): appctl, set_pinned, restart_bot,
toggle_reaction, box_task, channels_restart and the rest. No new rules.
Keys, channel tokens and the vault never reach the phone; a model key can only
be written. Admins keep what the phone always let them do; making, changing or
deleting bots, routines, memories, pages, folders and settings stays the
owner's. The state the phone polls now carries the sidebar's section order.
Checked by using it on a preview brain: routines, memories, templates, folders,
keys, signing another phone out, approvals and a chat with a fake model.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 19:05:12 +00:00
|
|
|
|
"detail" => match self.state.bot(bot) {
|
|
|
|
|
|
Some(x) => self.phone_detail(x),
|
|
|
|
|
|
None => fail("找不到這個 Bot"),
|
|
|
|
|
|
},
|
|
|
|
|
|
"settings" => self.phone_settings(owner),
|
|
|
|
|
|
// Every page, newest first (the state the phone polls carries only the latest few).
|
|
|
|
|
|
"pages" => {
|
|
|
|
|
|
let now = crate::model::now_ms();
|
|
|
|
|
|
let mut list: Vec<&crate::pages::Page> = self.state.pages.iter().collect();
|
|
|
|
|
|
list.sort_by_key(|p| std::cmp::Reverse(p.updated));
|
|
|
|
|
|
let pages: Vec<serde_json::Value> = list
|
|
|
|
|
|
.into_iter()
|
|
|
|
|
|
.map(|p| {
|
|
|
|
|
|
let mut c = crate::pages::card_json(p, now);
|
|
|
|
|
|
c["bot"] = json!(self.state.bot(p.bot).map(|x| x.name.clone()).unwrap_or_default());
|
|
|
|
|
|
c
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect();
|
|
|
|
|
|
json!({"ok": true, "pages": pages})
|
|
|
|
|
|
}
|
|
|
|
|
|
// The actions a bot can take on the app (the same appctl path as its tools).
|
|
|
|
|
|
"app" => {
|
Bug sweep: gates, relay 2FA, Windows input, snapshots, encodings
Permissions and reach
- a file leaving a computer passes the same questions as reading it;
"looking" shell commands that do more than look ask first
- a symlink out of the work/sealed folder counts as outside it
(real paths, not just lexical ones); the search walk skips links
- web_fetch and skill_install read the public web only: localhost, the
LAN and cloud metadata are refused, at every redirect
- preview shows a file without running it; browser_upload may ask
- vault: logins no longer match across shared suffixes (pages.dev,
com.tw, ...); registrable_domain knows public suffixes
- axwrite: found elements are retained (use-after-free)
Relay
- replacing or turning off 2FA needs the current code (rate-limited);
new recovery codes only count once enrollment is verified
- a removed computer loses its socket and its `call` access
- a site name taken by another account answers 409
- RELAY_TRUST_PROXY: the login lock counts the caller's address, not
the proxy's (compose files and README)
- httpd: half a body is not a request
Desktop
- sign-in, join and restore work with 2FA on (code field; --serve reads
ANYBOT_ACCOUNT_CODE; the setup wizard points to a pairing code)
- Windows: text was typed twice; modifiers are held through click, drag
and scroll; horizontal scroll; screen control is no longer refused
- a recording that hits the limit is transcribed, not thrown away
- bot's computer: a new home volume restores the snapshot; a snapshot
is read through before the home is wiped; a failed volume removal
stops reset/restore
- events of a stopped turn no longer land in the next one; each channel
message gets a turn of its own
- saving a bot's settings keeps what it got meanwhile (three-way merge);
a save file that cannot be read is kept
- pages in Big5/GBK/Shift_JIS are read in their own encoding
(encoding_rs); osascript output past 64 KB no longer stalls
- pick_tab keeps a job's own non-http tab; pictures larger than the
texture limit are fitted; the auto-update time field takes typing
- skills live in <data>/skills; memories are unnumbered in the prompt;
the phone may skillify and skill_install
CI
- the test step fails when the tests fail (it piped into tail)
Tests: anybot 268 passed, 27 ignored; relay 16 passed; clippy unchanged.
Not run: Windows on a real machine (win.rs type-checked alone), the
Docker paths of the bot's computer, the live accessibility writes.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-10 03:46:17 +00:00
|
|
|
|
// (skillify and skill_install are the phone's 「教我做」 and 「從網址安裝技能」.)
|
|
|
|
|
|
const ALLOWED: [&str; 17] = [
|
|
|
|
|
|
"create_bot", "update_bot", "remember", "forget", "save_skill", "delete_skill", "skillify", "skill_install", "create_routine", "update_routine",
|
The phone page does what the desktop does, laid out like it
A new mobile/index.html in the desktop's (and Grok Bot's) shape: the sidebar
with its sections and folders, the chat with steps, thinking, reactions, quotes
and the approval card, 對話詳細資訊, Bot 設定, routines, pages, computers and
設定. Each action goes to the desktop's own code on the app's thread
(api/act/<what> -> App::phone_act): appctl, set_pinned, restart_bot,
toggle_reaction, box_task, channels_restart and the rest. No new rules.
Keys, channel tokens and the vault never reach the phone; a model key can only
be written. Admins keep what the phone always let them do; making, changing or
deleting bots, routines, memories, pages, folders and settings stays the
owner's. The state the phone polls now carries the sidebar's section order.
Checked by using it on a preview brain: routines, memories, templates, folders,
keys, signing another phone out, approvals and a chat with a fake model.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 19:05:12 +00:00
|
|
|
|
"delete_routine", "run_routine_now", "create_group", "move_to_group", "rename_group", "delete_group", "update_settings",
|
|
|
|
|
|
];
|
|
|
|
|
|
let name = s("name");
|
|
|
|
|
|
if !ALLOWED.contains(&name.as_str()) {
|
|
|
|
|
|
return fail("手機不能做這件事");
|
|
|
|
|
|
}
|
|
|
|
|
|
let args = match &b["args"] {
|
|
|
|
|
|
serde_json::Value::String(t) => t.clone(),
|
|
|
|
|
|
v if v.is_object() => v.to_string(),
|
|
|
|
|
|
_ => "{}".to_string(),
|
|
|
|
|
|
};
|
|
|
|
|
|
// (The bot it is about; the app-wide ones act as the main bot, as from its chat.)
|
|
|
|
|
|
let id = [bot, self.state.primary_bot].into_iter().find(|i| self.state.bot(*i).is_some()).or_else(|| self.state.bots.first().map(|x| x.id)).unwrap_or(0);
|
|
|
|
|
|
let next = self.state.next_id;
|
|
|
|
|
|
let out = if name == "update_bot" && serde_json::from_str::<serde_json::Value>(&args).map(|v| v["default_computer"].is_string()).unwrap_or(false) {
|
|
|
|
|
|
self.update_bot_computer(id, &args)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
appctl::apply(&mut self.state, id, &name, &args)
|
|
|
|
|
|
};
|
|
|
|
|
|
if out.theme_changed {
|
|
|
|
|
|
self.apply_theme(ctx);
|
|
|
|
|
|
}
|
|
|
|
|
|
for (target, msg) in out.wake {
|
|
|
|
|
|
self.wake(ctx, target, msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
self.dirty = true;
|
|
|
|
|
|
if !out.ok {
|
|
|
|
|
|
return fail(&out.text);
|
|
|
|
|
|
}
|
|
|
|
|
|
let made = (self.state.next_id > next).then_some(next);
|
|
|
|
|
|
json!({"ok": true, "text": out.text, "bot": made})
|
|
|
|
|
|
}
|
|
|
|
|
|
// A bot's switches from its menu and editor.
|
|
|
|
|
|
"bot" => {
|
|
|
|
|
|
if self.state.bot(bot).is_none() {
|
|
|
|
|
|
return fail("找不到這個 Bot");
|
|
|
|
|
|
}
|
|
|
|
|
|
let v = &b["value"];
|
|
|
|
|
|
let key = s("key");
|
|
|
|
|
|
if matches!(key.as_str(), "tools" | "allow_remove") && !owner {
|
|
|
|
|
|
return owner_only();
|
|
|
|
|
|
}
|
|
|
|
|
|
match key.as_str() {
|
|
|
|
|
|
"pinned" => self.set_pinned(bot, v.as_bool().unwrap_or(false), None),
|
|
|
|
|
|
"primary" => self.state.primary_bot = bot,
|
|
|
|
|
|
"members" => {
|
|
|
|
|
|
let ids: Vec<u64> = v.as_array().map(|a| a.iter().filter_map(|x| x.as_u64()).collect()).unwrap_or_default();
|
|
|
|
|
|
let ok: Vec<u64> = ids.into_iter().filter(|i| *i != bot && self.state.bot(*i).map(|x| x.members.is_empty()).unwrap_or(false)).collect();
|
|
|
|
|
|
if ok.is_empty() {
|
|
|
|
|
|
return fail("群組至少要有一個成員");
|
|
|
|
|
|
}
|
|
|
|
|
|
if let Some(x) = self.state.bot_mut(bot) {
|
|
|
|
|
|
x.members = ok;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
k => {
|
|
|
|
|
|
let Some(x) = self.state.bot_mut(bot) else { return fail("找不到這個 Bot") };
|
|
|
|
|
|
match k {
|
|
|
|
|
|
"unread" => x.unread = v.as_bool().unwrap_or(true),
|
|
|
|
|
|
"tools" => x.tools_enabled = v.as_bool().unwrap_or(true),
|
|
|
|
|
|
"shape" if v.as_str().map(|t| crate::avatar::SHAPES.contains(&t)).unwrap_or(false) => x.shape = v.as_str().unwrap_or("").to_string(),
|
|
|
|
|
|
"color" if v.as_str().map(|t| crate::avatar::COLORS.iter().any(|c| c.0 == t)).unwrap_or(false) => x.color = v.as_str().unwrap_or("").to_string(),
|
|
|
|
|
|
"context" => x.context_tokens = v.as_u64().unwrap_or(x.context_tokens).clamp(4_000, 2_000_000),
|
|
|
|
|
|
"allow_remove" => x.allow_rules.retain(|r| Some(r.as_str()) != v.as_str()),
|
|
|
|
|
|
_ => return fail("不認得這個設定"),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
self.dirty = true;
|
|
|
|
|
|
done("好了")
|
|
|
|
|
|
}
|
|
|
|
|
|
"group_chat" => {
|
|
|
|
|
|
// 群組聊天, as the desktop's new-bot menu makes it.
|
|
|
|
|
|
let ids: Vec<u64> = b["members"].as_array().map(|a| a.iter().filter_map(|x| x.as_u64()).collect()).unwrap_or_default();
|
|
|
|
|
|
let members: Vec<u64> = ids.into_iter().filter(|i| self.state.bot(*i).map(|x| x.members.is_empty()).unwrap_or(false)).collect();
|
|
|
|
|
|
if members.is_empty() {
|
|
|
|
|
|
return fail("選至少一個 Bot 當成員");
|
|
|
|
|
|
}
|
|
|
|
|
|
let id = self.state.next_id;
|
|
|
|
|
|
let name = Some(s("name")).filter(|n| !n.is_empty()).unwrap_or_else(|| "群組聊天".into());
|
|
|
|
|
|
let sel = self.state.selected;
|
|
|
|
|
|
let out = appctl::apply(&mut self.state, sel, "create_bot", &json!({"name": name, "description": "成員依序回答"}).to_string());
|
|
|
|
|
|
if !out.ok {
|
|
|
|
|
|
return fail(&out.text);
|
|
|
|
|
|
}
|
|
|
|
|
|
if let Some(x) = self.state.bot_mut(id) {
|
|
|
|
|
|
x.members = members;
|
|
|
|
|
|
x.shape = "cloud".into();
|
|
|
|
|
|
}
|
|
|
|
|
|
self.dirty = true;
|
|
|
|
|
|
json!({"ok": true, "text": out.text, "bot": id})
|
|
|
|
|
|
}
|
|
|
|
|
|
"delete_bot" => {
|
|
|
|
|
|
if !owner {
|
|
|
|
|
|
return owner_only();
|
|
|
|
|
|
}
|
|
|
|
|
|
if self.state.bot(bot).is_none() {
|
|
|
|
|
|
return fail("找不到這個 Bot");
|
|
|
|
|
|
}
|
|
|
|
|
|
// As the desktop's 刪除 Bot dialog.
|
|
|
|
|
|
self.stop(bot);
|
|
|
|
|
|
self.state.bots.retain(|x| x.id != bot);
|
|
|
|
|
|
self.state.fix_primary();
|
|
|
|
|
|
self.dirty = true;
|
|
|
|
|
|
done("已刪除")
|
|
|
|
|
|
}
|
|
|
|
|
|
"restart_bot" => {
|
|
|
|
|
|
if self.state.bot(bot).is_none() {
|
|
|
|
|
|
return fail("找不到這個 Bot");
|
|
|
|
|
|
}
|
|
|
|
|
|
self.restart_bot(bot);
|
|
|
|
|
|
done("已重新啟動")
|
|
|
|
|
|
}
|
|
|
|
|
|
"react" => {
|
|
|
|
|
|
let idx = b["index"].as_u64().unwrap_or(u64::MAX) as usize;
|
|
|
|
|
|
let emoji = s("emoji");
|
|
|
|
|
|
if emoji.is_empty() || emoji.chars().count() > 8 || self.state.bot(bot).map(|x| idx >= x.messages.len()).unwrap_or(true) {
|
|
|
|
|
|
return fail("找不到這則訊息");
|
|
|
|
|
|
}
|
|
|
|
|
|
self.toggle_reaction(bot, idx, &emoji);
|
|
|
|
|
|
done("好了")
|
|
|
|
|
|
}
|
|
|
|
|
|
"reply" => {
|
|
|
|
|
|
self.remote_cmd(ctx, Cmd::Reply { bot });
|
|
|
|
|
|
done("重新傳送中…")
|
|
|
|
|
|
}
|
A turn cut off by a crash leaves a 「繼續」 card, and nothing it may have done runs twice
Each bot keeps a work log (oplog/bot-<id>.jsonl, after pi's durable-harness design, cut down):
before something happens a line says it is about to — the turn, each model call, each step once
its checks passed (with the arguments it runs with and whether it may run again), each message
typed mid-turn — synced to disk first. When the turn ends the file shrinks to the messages still
waiting, usually nothing.
On the next start after AnyBot was killed mid-turn, the log puts the chat right before anything
runs: the message the turn answered comes back if the chat lost it; a step that was running and
reaches outside (a text, a click, a file, a published site) shows as 「可能已經執行了」, both to the
person and in the result the bot reads — no longer as "not allowed"; a step that only looked shows
as cut off; messages typed mid-turn that never reached the bot go back into the chat. The chat is
saved, then the log closes the turn. A turn the person didn't stop ends with a 「繼續」 card (what
it was doing, what may have run, the messages put back); it goes on only when they press it — in
the window, on a screen of the brain, or on the phone — from where its steps stand, never running
a step that may have run again. Pressing stop is on disk at once, and a stopped turn stays
stopped.
Also in the turn loop:
- 自動審核 that doesn't answer (or answers something that isn't a verdict) asks the person; in
直接操作 mode it used to let the step through unchecked.
- "Too long for this model" folds older messages into a summary and asks the same step again,
once per thing the person said, instead of ending the turn.
- Folding keeps the person's chat whole: the summary goes in at the fold and the model reads from
the newest summary on (it used to delete what it folded).
- A step moved to the chosen computer runs there, but the chat keeps the call as the model wrote
it; the result says where it ran.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha5F5gJt93t3yEx3XcS
2026-11-08 16:49:12 +00:00
|
|
|
|
"resume" => {
|
|
|
|
|
|
self.remote_cmd(ctx, Cmd::Resume { bot });
|
|
|
|
|
|
done("繼續中…")
|
|
|
|
|
|
}
|
The phone page does what the desktop does, laid out like it
A new mobile/index.html in the desktop's (and Grok Bot's) shape: the sidebar
with its sections and folders, the chat with steps, thinking, reactions, quotes
and the approval card, 對話詳細資訊, Bot 設定, routines, pages, computers and
設定. Each action goes to the desktop's own code on the app's thread
(api/act/<what> -> App::phone_act): appctl, set_pinned, restart_bot,
toggle_reaction, box_task, channels_restart and the rest. No new rules.
Keys, channel tokens and the vault never reach the phone; a model key can only
be written. Admins keep what the phone always let them do; making, changing or
deleting bots, routines, memories, pages, folders and settings stays the
owner's. The state the phone polls now carries the sidebar's section order.
Checked by using it on a preview brain: routines, memories, templates, folders,
keys, signing another phone out, approvals and a chat with a fake model.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 19:05:12 +00:00
|
|
|
|
"clear" => {
|
|
|
|
|
|
self.remote_cmd(ctx, Cmd::Clear { bot });
|
|
|
|
|
|
done("已清除聊天記錄")
|
|
|
|
|
|
}
|
|
|
|
|
|
"delete_page" => {
|
|
|
|
|
|
let id = b["id"].as_u64().unwrap_or(0);
|
|
|
|
|
|
let before = self.state.pages.len();
|
|
|
|
|
|
self.state.pages.retain(|x| x.id != id);
|
|
|
|
|
|
if self.state.pages.len() == before {
|
|
|
|
|
|
return fail("這個頁面已經刪除了");
|
|
|
|
|
|
}
|
|
|
|
|
|
self.mark();
|
|
|
|
|
|
done("已刪除頁面")
|
|
|
|
|
|
}
|
|
|
|
|
|
// 設定 › 一般 / 權限 (the owner's).
|
|
|
|
|
|
"setting" => {
|
|
|
|
|
|
if !owner {
|
|
|
|
|
|
return owner_only();
|
|
|
|
|
|
}
|
|
|
|
|
|
let v = &b["value"];
|
|
|
|
|
|
match s("key").as_str() {
|
|
|
|
|
|
"direct_mode" => {
|
|
|
|
|
|
if v.as_bool().unwrap_or(false) {
|
|
|
|
|
|
self.enable_direct_mode()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
self.disable_direct_mode()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
"auto_review" => self.state.auto_review = v.as_bool().unwrap_or(false),
|
|
|
|
|
|
"notify" => self.state.notify = v.as_bool().unwrap_or(true),
|
|
|
|
|
|
"rule_add" | "rule_remove" => {
|
|
|
|
|
|
let text = v.as_str().unwrap_or("").trim().to_string();
|
|
|
|
|
|
let list = if s("list") == "ask" { &mut self.state.review_ask_rules } else { &mut self.state.review_allow_rules };
|
|
|
|
|
|
if s("key") == "rule_add" {
|
|
|
|
|
|
if text.is_empty() {
|
|
|
|
|
|
return fail("規則是空的");
|
|
|
|
|
|
}
|
|
|
|
|
|
if !list.contains(&text) {
|
|
|
|
|
|
list.push(text);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
list.retain(|r| *r != text);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
_ => return fail("不認得這個設定"),
|
|
|
|
|
|
}
|
|
|
|
|
|
self.dirty = true;
|
|
|
|
|
|
done("好了")
|
|
|
|
|
|
}
|
|
|
|
|
|
// 設定 › 模型: a provider's key (written, never read back) and new bots' model.
|
|
|
|
|
|
"provider" => {
|
|
|
|
|
|
if !owner {
|
|
|
|
|
|
return owner_only();
|
|
|
|
|
|
}
|
|
|
|
|
|
let Some(kind) = crate::providers::ALL_PROVIDERS.iter().copied().find(|k| serde_json::to_value(k).ok().as_ref() == Some(&b["provider"])) else { return fail("不認得這個模型服務") };
|
|
|
|
|
|
let ps = self.state.providers.entry(kind.key().to_string()).or_default();
|
|
|
|
|
|
if let Some(k) = b["key"].as_str() {
|
|
|
|
|
|
ps.api_key = k.trim().to_string();
|
|
|
|
|
|
}
|
|
|
|
|
|
if let Some(m) = b["default_model"].as_str() {
|
|
|
|
|
|
ps.default_model = m.trim().to_string();
|
|
|
|
|
|
}
|
|
|
|
|
|
self.dirty = true;
|
|
|
|
|
|
done("好了")
|
|
|
|
|
|
}
|
|
|
|
|
|
// 手機與帳號: sign a direct-connection phone out (as the desktop's list does).
|
|
|
|
|
|
"device_remove" => {
|
|
|
|
|
|
if !owner {
|
|
|
|
|
|
return owner_only();
|
|
|
|
|
|
}
|
|
|
|
|
|
let (name, created) = (s("name"), b["created"].as_i64().unwrap_or(0));
|
|
|
|
|
|
let before = self.state.remote.devices.len();
|
|
|
|
|
|
self.state.remote.devices.retain(|d| !(d.name == name && d.created == created));
|
|
|
|
|
|
if self.state.remote.devices.len() == before {
|
|
|
|
|
|
return fail("找不到這支手機");
|
|
|
|
|
|
}
|
|
|
|
|
|
self.dirty = true;
|
|
|
|
|
|
done("已登出那支手機")
|
|
|
|
|
|
}
|
|
|
|
|
|
"channel" => {
|
|
|
|
|
|
if !owner {
|
|
|
|
|
|
return owner_only();
|
|
|
|
|
|
}
|
|
|
|
|
|
let id = b["id"].as_u64().unwrap_or(0);
|
|
|
|
|
|
if !self.state.channels.iter().any(|c| c.id == id) {
|
|
|
|
|
|
return fail("找不到這個管道");
|
|
|
|
|
|
}
|
|
|
|
|
|
if b["remove"].as_bool().unwrap_or(false) {
|
|
|
|
|
|
self.state.channels.retain(|c| c.id != id);
|
|
|
|
|
|
} else if let Some(c) = self.state.channels.iter_mut().find(|c| c.id == id) {
|
|
|
|
|
|
c.enabled = b["enabled"].as_bool().unwrap_or(c.enabled);
|
|
|
|
|
|
}
|
|
|
|
|
|
self.dirty = true;
|
|
|
|
|
|
self.channels_restart(ctx);
|
|
|
|
|
|
done("好了")
|
|
|
|
|
|
}
|
|
|
|
|
|
"mcp" => {
|
|
|
|
|
|
if !owner {
|
|
|
|
|
|
return owner_only();
|
|
|
|
|
|
}
|
|
|
|
|
|
let name = s("name");
|
|
|
|
|
|
if !self.state.mcp_servers.iter().any(|m| m.name == name) {
|
|
|
|
|
|
return fail("找不到這個連接器");
|
|
|
|
|
|
}
|
|
|
|
|
|
// (mcp_poll connects or drops it when the list changes.)
|
|
|
|
|
|
if b["remove"].as_bool().unwrap_or(false) {
|
|
|
|
|
|
self.state.mcp_servers.retain(|m| m.name != name);
|
|
|
|
|
|
} else if let Some(m) = self.state.mcp_servers.iter_mut().find(|m| m.name == name) {
|
|
|
|
|
|
m.enabled = b["enabled"].as_bool().unwrap_or(m.enabled);
|
|
|
|
|
|
}
|
|
|
|
|
|
self.dirty = true;
|
|
|
|
|
|
done("好了")
|
|
|
|
|
|
}
|
|
|
|
|
|
// 設定 › 電腦's buttons for Bot 的電腦.
|
|
|
|
|
|
"box" => {
|
|
|
|
|
|
let op = s("op");
|
|
|
|
|
|
if matches!(op.as_str(), "update" | "reset" | "runtime" | "auto_update") && !owner {
|
|
|
|
|
|
return owner_only();
|
|
|
|
|
|
}
|
|
|
|
|
|
match op.as_str() {
|
|
|
|
|
|
"wake" => self.box_task(|| crate::cloudbox::ensure_running().map(|_| "Bot 的電腦已經開好了。".to_string())),
|
|
|
|
|
|
"snapshot" => self.box_task(|| crate::cloudbox::save_snapshot().map(|n| format!("已儲存快照({})。", crate::cloudbox::human(n)))),
|
|
|
|
|
|
"disk" => {
|
|
|
|
|
|
let slot = self.cu.disk.clone();
|
|
|
|
|
|
*slot.lock().unwrap() = Some("檢查中…".into());
|
|
|
|
|
|
std::thread::spawn(move || {
|
|
|
|
|
|
let r = crate::cloudbox::disk_report().unwrap_or_else(|e| e);
|
|
|
|
|
|
*slot.lock().unwrap() = Some(r);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
"update" => {
|
|
|
|
|
|
// As the desktop's 更新: the bots stop first, the files and logins stay.
|
|
|
|
|
|
let ids: Vec<u64> = self.streams.keys().copied().collect();
|
|
|
|
|
|
for id in ids {
|
|
|
|
|
|
self.stop(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
*self.cu.note.lock().unwrap() = match crate::cloudbox::rebuild(crate::cloudbox::Rebuild::Update) {
|
|
|
|
|
|
Ok(()) => t("更新已開始。"),
|
|
|
|
|
|
Err(e) => e,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
"reset" => {
|
|
|
|
|
|
// As the desktop's 重設: back to the last snapshot (the current box saved
|
|
|
|
|
|
// first), or a brand-new computer when there is none.
|
|
|
|
|
|
let ids: Vec<u64> = self.streams.keys().copied().collect();
|
|
|
|
|
|
for id in ids {
|
|
|
|
|
|
self.stop(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
let kind = if crate::cloudbox::snapshot_time().is_some() { crate::cloudbox::Rebuild::Restore } else { crate::cloudbox::Rebuild::Reset };
|
|
|
|
|
|
*self.cu.note.lock().unwrap() = match crate::cloudbox::rebuild(kind) {
|
|
|
|
|
|
Ok(()) => t("已開始。"),
|
|
|
|
|
|
Err(e) => e,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
"runtime" => crate::cloudbox::set_box_runtime(&s("value")),
|
|
|
|
|
|
"auto_update" => {
|
|
|
|
|
|
let at = s("value");
|
|
|
|
|
|
if !at.is_empty() && chrono::NaiveTime::parse_from_str(&at, "%H:%M").is_err() {
|
|
|
|
|
|
return fail("時間要寫成 HH:MM");
|
|
|
|
|
|
}
|
|
|
|
|
|
crate::cloudbox::set_auto_update_at((!at.is_empty()).then_some(at));
|
|
|
|
|
|
}
|
|
|
|
|
|
_ => return fail("不認得這個動作"),
|
|
|
|
|
|
}
|
|
|
|
|
|
*BOX_FACTS.lock().unwrap_or_else(|e| e.into_inner()) = None;
|
|
|
|
|
|
done("好了")
|
|
|
|
|
|
}
|
|
|
|
|
|
_ => fail("沒有這個動作"),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// A bot as its editor and the panel beside the chat show it.
|
|
|
|
|
|
fn phone_detail(&self, b: &Bot) -> serde_json::Value {
|
|
|
|
|
|
let names: HashMap<u64, String> = self.state.bots.iter().map(|x| (x.id, x.name.clone())).collect();
|
|
|
|
|
|
let (choices, chosen) = self.computer_choices(b);
|
|
|
|
|
|
let trig = crate::triggers::statuses().lock().unwrap().clone();
|
|
|
|
|
|
// 資料庫: the chat's files, newest first (pictures and documents the person or the bot sent).
|
|
|
|
|
|
let mut files: Vec<serde_json::Value> = vec![];
|
|
|
|
|
|
for m in b.messages.iter().rev() {
|
|
|
|
|
|
for a in &m.attachments {
|
|
|
|
|
|
if files.len() < 80 {
|
|
|
|
|
|
files.push(json!({"name": a.name, "path": a.path, "image": a.image, "at": m.at, "mine": m.role == Role::User}));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
json!({
|
|
|
|
|
|
"id": b.id, "name": b.name, "description": b.description, "instructions": b.instructions,
|
|
|
|
|
|
"shape": b.shape, "color": b.color, "provider": serde_json::to_value(b.provider).unwrap_or_default(), "model": b.model,
|
|
|
|
|
|
"computer": chosen, "computers": choices.iter().map(|(name, note)| json!({"name": name, "note": note})).collect::<Vec<_>>(),
|
|
|
|
|
|
"tools_enabled": b.tools_enabled, "context_tokens": b.context_tokens, "folder": b.folder, "pinned": b.pinned,
|
|
|
|
|
|
"primary": b.id == self.state.primary_bot, "unread": b.unread,
|
|
|
|
|
|
"members": b.members.iter().map(|i| json!({"id": i, "name": names.get(i).cloned().unwrap_or_default()})).collect::<Vec<_>>(),
|
|
|
|
|
|
"memories": b.memories, "allow_rules": b.allow_rules,
|
|
|
|
|
|
"demos": b.demos.iter().map(|d| json!({"name": d.name, "created": d.created, "steps": d.steps.len()})).collect::<Vec<_>>(),
|
|
|
|
|
|
"routines": b.routines.iter().map(|r| json!({
|
|
|
|
|
|
"id": r.id, "title": r.title, "prompt": r.prompt, "paused": r.paused, "when": appctl::routine_when(r),
|
|
|
|
|
|
"schedule": serde_json::to_value(&r.schedule).unwrap_or_default(), "repeat": crate::routines::describe(&r.schedule),
|
|
|
|
|
|
"trigger": r.trigger.as_ref().map(|t| t.describe()), "status": trig.get(&r.id).cloned(),
|
|
|
|
|
|
"last": r.last_run.map(|t| crate::routines::describe_when(t, &r.schedule.timezone)), "computer": r.computer,
|
|
|
|
|
|
})).collect::<Vec<_>>(),
|
|
|
|
|
|
"threads": b.threads.iter().enumerate().rev().map(|(i, (title, msgs))| json!({"index": i, "title": title, "count": msgs.len(), "at": msgs.last().map(|m| m.at).unwrap_or(0)})).collect::<Vec<_>>(),
|
|
|
|
|
|
"files": files,
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 設定 as the phone shows it (nothing secret: keys only as "set or not").
|
|
|
|
|
|
fn phone_settings(&self, owner: bool) -> serde_json::Value {
|
|
|
|
|
|
let st = &self.state;
|
|
|
|
|
|
let ch_status = crate::channels::statuses().lock().unwrap().iter().map(|(k, v)| (*k, (v.ok, v.note.clone(), v.received))).collect::<HashMap<_, _>>();
|
|
|
|
|
|
let mcp = crate::mcp::status();
|
|
|
|
|
|
let mcp_err = self.ch.mcp_errors.lock().unwrap().clone();
|
|
|
|
|
|
let bot_name = |id: u64| st.bot(id).map(|b| b.name.clone()).unwrap_or_else(|| "(Bot 已刪除)".into());
|
|
|
|
|
|
let log = crate::cloudbox::log_lines();
|
|
|
|
|
|
let mut out = json!({
|
|
|
|
|
|
"role": if owner { "owner" } else { "admin" },
|
|
|
|
|
|
"host": st.remote.host_name, "version": version_label(self.exe_built), "newer": self.newer_build.is_some(),
|
|
|
|
|
|
"theme": match st.theme { Theme::Light => "light", Theme::Dark => "dark", Theme::System => "system" },
|
|
|
|
|
|
"accent": serde_json::to_value(st.accent).unwrap_or_default(),
|
|
|
|
|
|
"timezone": st.timezone, "notify": st.notify, "language": st.language,
|
|
|
|
|
|
"direct_mode": st.direct_mode, "direct_locked": !self.managed.direct.allows() || !self.managed.local.allows(),
|
|
|
|
|
|
"auto_review": st.auto_review, "allow_rules": st.review_allow_rules, "ask_rules": st.review_ask_rules,
|
|
|
|
|
|
"providers": crate::providers::ALL_PROVIDERS.iter().map(|&k| {
|
|
|
|
|
|
let ps = st.provider(k);
|
|
|
|
|
|
json!({"key": serde_json::to_value(k).unwrap_or_default(), "label": k.label(), "needs_key": k.needs_key(),
|
|
|
|
|
|
"ready": !k.needs_key() || !crate::providers::resolve_key(k, &ps.api_key).is_empty(),
|
|
|
|
|
|
"default_model": ps.default_model, "custom_url": !ps.base_url.is_empty()})
|
|
|
|
|
|
}).collect::<Vec<_>>(),
|
|
|
|
|
|
"skills": st.skills.iter().map(|k| json!({"name": k.name, "description": k.description, "instructions": k.instructions})).collect::<Vec<_>>(),
|
|
|
|
|
|
"templates": crate::memory::TEMPLATES.iter().map(|t| {
|
|
|
|
|
|
let c = crate::avatar::color(t.color);
|
|
|
|
|
|
json!({"name": t.name, "description": t.description, "shape": t.shape, "color": format!("#{:02x}{:02x}{:02x}", c.r(), c.g(), c.b())})
|
|
|
|
|
|
}).collect::<Vec<_>>(),
|
|
|
|
|
|
"shapes": crate::avatar::SHAPES,
|
|
|
|
|
|
"colors": crate::avatar::COLORS.iter().map(|(k, n, c)| json!({"key": k, "name": n, "hex": format!("#{:02x}{:02x}{:02x}", c[0], c[1], c[2])})).collect::<Vec<_>>(),
|
|
|
|
|
|
"folders": st.folders,
|
|
|
|
|
|
"channels": st.channels.iter().map(|c| {
|
|
|
|
|
|
let (ok, note, received) = ch_status.get(&c.id).cloned().unwrap_or((false, String::new(), 0));
|
|
|
|
|
|
json!({"id": c.id, "kind": c.kind.label(), "name": c.name, "bot": bot_name(c.bot_id), "target": c.target, "enabled": c.enabled, "ok": ok, "note": note, "received": received})
|
|
|
|
|
|
}).collect::<Vec<_>>(),
|
|
|
|
|
|
"mcp": st.mcp_servers.iter().map(|m| json!({
|
|
|
|
|
|
"name": m.name, "enabled": m.enabled, "tools": mcp.get(&m.name), "error": mcp_err.iter().find(|e| e.0 == m.name).map(|e| e.1.clone()),
|
|
|
|
|
|
"what": if m.url.is_empty() { m.command.clone() } else { m.url.clone() },
|
|
|
|
|
|
})).collect::<Vec<_>>(),
|
|
|
|
|
|
"box": {
|
|
|
|
|
|
"state": crate::cloudbox::run_state().label(), "available": crate::cloudbox::available(),
|
|
|
|
|
|
"version": crate::cloudbox::wanted_version(), "runtime": crate::cloudbox::box_runtime(),
|
|
|
|
|
|
"snapshot": crate::cloudbox::snapshot_time().map(|t| t.format("%m/%d %H:%M").to_string()),
|
|
|
|
|
|
"auto_update": crate::cloudbox::auto_update_at(),
|
|
|
|
|
|
"note": self.cu.note.lock().unwrap().clone(), "disk": self.cu.disk.lock().unwrap().clone(),
|
|
|
|
|
|
"log": log.iter().rev().take(40).rev().cloned().collect::<Vec<_>>(),
|
|
|
|
|
|
"facts": box_facts(),
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
if owner {
|
|
|
|
|
|
out["devices"] = json!(st.remote.devices.iter().map(|d| json!({"name": d.name, "created": d.created, "last_seen": d.last_seen})).collect::<Vec<_>>());
|
|
|
|
|
|
out["docker_host"] = json!(crate::cloudbox::docker_host());
|
|
|
|
|
|
}
|
|
|
|
|
|
out
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
|
mod phone_act_tests {
|
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
|
|
/// The demo app (sample bots, nothing read from or saved to disk).
|
|
|
|
|
|
fn demo() -> (egui::Context, App) {
|
|
|
|
|
|
let ctx = egui::Context::default();
|
|
|
|
|
|
let app = App::new(&ctx, Some(std::env::temp_dir().join("anybot-phone-act-test.png")));
|
|
|
|
|
|
(ctx, app)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn the_phone_does_what_the_desktop_does() {
|
|
|
|
|
|
let (ctx, mut app) = demo();
|
|
|
|
|
|
assert!(app.demo && app.state.bots.len() >= 2);
|
|
|
|
|
|
let b = app.state.bots[0].id;
|
|
|
|
|
|
let act = |app: &mut App, what: &str, body: serde_json::Value, role: &str| app.phone_act(&ctx, what, &body, role);
|
|
|
|
|
|
// The actions a bot can take, by the same appctl path.
|
|
|
|
|
|
let v = act(&mut app, "app", json!({"bot": b, "name": "create_routine", "args": {"title": "早報", "prompt": "整理新聞", "schedule": {"frequency": "daily", "time": "08:00"}}}), "owner");
|
|
|
|
|
|
assert_eq!(v["ok"], true, "{v}");
|
|
|
|
|
|
let rid = app.state.bot(b).unwrap().routines.iter().find(|r| r.title == "早報").map(|r| r.id).expect("routine made");
|
|
|
|
|
|
assert_eq!(act(&mut app, "app", json!({"bot": b, "name": "update_routine", "args": {"id": rid, "paused": true}}), "owner")["ok"], true);
|
|
|
|
|
|
assert!(app.state.bot(b).unwrap().routines.iter().any(|r| r.id == rid && r.paused));
|
|
|
|
|
|
assert_eq!(act(&mut app, "app", json!({"bot": b, "name": "remember", "args": {"fact": "週末不排工作"}}), "owner")["ok"], true);
|
|
|
|
|
|
assert!(app.state.bot(b).unwrap().memories.contains(&"週末不排工作".to_string()));
|
|
|
|
|
|
// Only the app actions a bot has; nothing else through this door.
|
|
|
|
|
|
assert!(act(&mut app, "app", json!({"bot": b, "name": "write_page", "args": {}}), "owner")["error"].is_string());
|
|
|
|
|
|
assert!(act(&mut app, "nothing", json!({}), "owner")["error"].is_string());
|
|
|
|
|
|
// A bot's switches, checked like the editor checks them.
|
|
|
|
|
|
assert_eq!(act(&mut app, "bot", json!({"bot": b, "key": "shape", "value": "star"}), "owner")["ok"], true);
|
|
|
|
|
|
assert_eq!(app.state.bot(b).unwrap().shape, "star");
|
|
|
|
|
|
assert!(act(&mut app, "bot", json!({"bot": b, "key": "shape", "value": "<script>"}), "owner")["error"].is_string());
|
|
|
|
|
|
assert_eq!(act(&mut app, "bot", json!({"bot": b, "key": "pinned", "value": true}), "owner")["ok"], true);
|
|
|
|
|
|
assert!(app.state.bot(b).unwrap().pinned);
|
|
|
|
|
|
// 團隊: an admin keeps what the phone always let them do, and small chat things…
|
|
|
|
|
|
assert_eq!(act(&mut app, "bot", json!({"bot": b, "key": "unread", "value": true}), "admin")["ok"], true);
|
|
|
|
|
|
assert!(act(&mut app, "detail", json!({"bot": b}), "admin")["id"].is_u64());
|
|
|
|
|
|
// …but making, changing or deleting bots, routines, memories, pages and folders is the owner's.
|
|
|
|
|
|
for (what, body) in [
|
|
|
|
|
|
("app", json!({"bot": b, "name": "update_routine", "args": {"id": rid, "paused": false}})),
|
|
|
|
|
|
("app", json!({"bot": b, "name": "create_bot", "args": {"name": "x"}})),
|
|
|
|
|
|
("app", json!({"bot": b, "name": "remember", "args": {"fact": "x"}})),
|
|
|
|
|
|
("bot", json!({"bot": b, "key": "pinned", "value": false})),
|
|
|
|
|
|
("bot", json!({"bot": b, "key": "shape", "value": "cloud"})),
|
|
|
|
|
|
("group_chat", json!({"members": [b]})),
|
|
|
|
|
|
("clear", json!({"bot": b})),
|
|
|
|
|
|
("delete_page", json!({"id": 1})),
|
|
|
|
|
|
("box", json!({"op": "snapshot"})),
|
|
|
|
|
|
] {
|
|
|
|
|
|
assert!(act(&mut app, what, body.clone(), "admin")["error"].is_string(), "admin did {what} {body}");
|
|
|
|
|
|
}
|
|
|
|
|
|
assert!(app.state.bot(b).unwrap().routines.iter().any(|r| r.id == rid && r.paused));
|
|
|
|
|
|
assert!(app.state.bot(b).unwrap().pinned && app.state.bot(b).unwrap().shape == "star");
|
|
|
|
|
|
// The owner's alone: permissions, a bot's computer tools, deleting a bot.
|
|
|
|
|
|
assert!(act(&mut app, "setting", json!({"key": "auto_review", "value": true}), "admin")["error"].is_string());
|
|
|
|
|
|
assert!(act(&mut app, "bot", json!({"bot": b, "key": "tools", "value": true}), "admin")["error"].is_string());
|
|
|
|
|
|
assert!(act(&mut app, "delete_bot", json!({"bot": b}), "admin")["error"].is_string());
|
|
|
|
|
|
assert_eq!(act(&mut app, "setting", json!({"key": "rule_add", "list": "ask", "value": "付款前先問我"}), "owner")["ok"], true);
|
|
|
|
|
|
assert!(app.state.review_ask_rules.contains(&"付款前先問我".to_string()));
|
|
|
|
|
|
assert_eq!(act(&mut app, "setting", json!({"key": "rule_remove", "list": "ask", "value": "付款前先問我"}), "owner")["ok"], true);
|
|
|
|
|
|
assert!(!app.state.review_ask_rules.contains(&"付款前先問我".to_string()));
|
|
|
|
|
|
// 群組聊天 as the desktop's menu makes it.
|
|
|
|
|
|
let others: Vec<u64> = app.state.bots.iter().filter(|x| x.members.is_empty()).map(|x| x.id).take(2).collect();
|
|
|
|
|
|
let g = act(&mut app, "group_chat", json!({"members": others}), "owner");
|
|
|
|
|
|
let gid = g["bot"].as_u64().expect("group made");
|
|
|
|
|
|
assert_eq!(app.state.bot(gid).unwrap().members, others);
|
|
|
|
|
|
// Deleting (the owner): gone, and there is still a main bot.
|
|
|
|
|
|
assert_eq!(act(&mut app, "delete_bot", json!({"bot": gid}), "owner")["ok"], true);
|
|
|
|
|
|
assert!(app.state.bot(gid).is_none() && app.state.bot(app.state.primary_bot).is_some());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn the_phone_never_gets_keys_or_secrets() {
|
|
|
|
|
|
let (ctx, mut app) = demo();
|
|
|
|
|
|
let key = "sk-test-very-secret-1234567890";
|
|
|
|
|
|
app.state.providers.entry("openai".into()).or_default().api_key = key.into();
|
|
|
|
|
|
app.state.channels.push(crate::channels::Channel { id: 9, kind: crate::channels::Kind::Telegram, name: "t".into(), bot_id: app.state.bots[0].id, token: "tg-secret-token".into(), target: String::new(), enabled: true, client_id: String::new(), tenant: String::new() });
|
|
|
|
|
|
for role in ["owner", "admin"] {
|
|
|
|
|
|
let s = app.phone_act(&ctx, "settings", &json!({}), role).to_string();
|
|
|
|
|
|
assert!(!s.contains(key) && !s.contains("tg-secret-token"), "{role}: {s}");
|
|
|
|
|
|
assert!(s.contains("\"ready\":true"), "{s}");
|
|
|
|
|
|
}
|
|
|
|
|
|
// A key goes in (the owner's), and still never comes out.
|
|
|
|
|
|
let openai = serde_json::to_value(crate::providers::ProviderKind::OpenAi).unwrap();
|
|
|
|
|
|
assert!(app.phone_act(&ctx, "provider", &json!({"provider": openai, "key": "sk-new-secret-999"}), "admin")["error"].is_string());
|
|
|
|
|
|
assert_eq!(app.phone_act(&ctx, "provider", &json!({"provider": openai, "key": "sk-new-secret-999", "default_model": "gpt-5"}), "owner")["ok"], true);
|
|
|
|
|
|
assert_eq!(app.state.provider(crate::providers::ProviderKind::OpenAi).api_key, "sk-new-secret-999");
|
|
|
|
|
|
assert!(!app.phone_act(&ctx, "settings", &json!({}), "owner").to_string().contains("sk-new-secret-999"));
|
|
|
|
|
|
assert!(app.phone_act(&ctx, "box", &json!({"op": "reset"}), "admin")["error"].is_string());
|
|
|
|
|
|
// The owner's own lists only to the owner.
|
|
|
|
|
|
assert!(app.phone_act(&ctx, "settings", &json!({}), "admin").get("devices").is_none());
|
|
|
|
|
|
assert!(app.phone_act(&ctx, "settings", &json!({}), "owner").get("devices").is_some());
|
|
|
|
|
|
let b = app.state.bots[0].id;
|
|
|
|
|
|
let d = app.phone_act(&ctx, "detail", &json!({"bot": b}), "owner").to_string();
|
|
|
|
|
|
assert!(!d.contains(key) && d.contains("\"memories\""), "{d}");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|