fix: 螢幕電腦改連接器名稱改成明確請大腦改,不再從網址猜
- 螢幕電腦上改名:排一個「把 A 改成 B」給大腦(/api/sync/mcp-rename,同一個工人照順序送, 排在帶新名字的修改之前),大腦改它自己那一個:金鑰、密碼、在清單裡的位置、登入都留著; 空白或同名、或不是擁有者,拒絕。連不到大腦時不改並說原因。 - 這台電腦自己改名,直接把登入搬過去。 - 拿掉從網址猜改名的兩段(大腦偵測改名、還原密鑰時用網址找):斷線時累積的「刪一個、加一個 同網址的」可能被當成改名,把登入和密碼配給錯的連接器。還原密鑰回到只看名字(和 main 一樣)。 - feature-map 拿掉「Bot 也能改名」(manage_connectors 沒有改名);FEATURES.md 的順序照畫面。 已驗證: cargo test 全綠;新測試 the_brain_renames_a_connector_for_a_screen(位置、密碼、登入留著, 同名、空白、非擁有者拒絕);mirror_ui 確認同網址的別的連接器拿不到密碼。 未驗證: 螢幕電腦連真的大腦實際改名(要兩台機器)。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha3KhvSzysuKUobKUTR
This commit is contained in:
parent
406ca12dac
commit
a0e1b36a06
|
|
@ -1491,7 +1491,7 @@ computer_use_screenshot、click、mouse_move、mouse_button(按住/放開)
|
||||||
|
|
||||||
- 設定 →「連接器」。接上 Model Context Protocol 伺服器,Bot 就能用它的工具(原版的 MCP 用戶端)。
|
- 設定 →「連接器」。接上 Model Context Protocol 伺服器,Bot 就能用它的工具(原版的 MCP 用戶端)。
|
||||||
- 本機伺服器填指令(例如 `npx -y @modelcontextprotocol/server-filesystem ~/Documents`)加環境變數;遠端伺服器填網址(Streamable HTTP,JSON 或 SSE 回應都可以)加標頭。
|
- 本機伺服器填指令(例如 `npx -y @modelcontextprotocol/server-filesystem ~/Documents`)加環境變數;遠端伺服器填網址(Streamable HTTP,JSON 或 SSE 回應都可以)加標頭。
|
||||||
- 清單+各自的頁(跟 Claude、ChatGPT 的設定一樣):「已加入」每個連接器一列(名稱、狀態點「已連上,N 個工具」/錯誤原因、開關、›);點一列進到它自己的頁:狀態、登入、重新連線、開關,「設定」(各欄位和「給 Bot 的使用說明」——原版的 MCP 自訂說明,會放進 Bot 的系統指示),「工具(N)」只列它自己的工具(多時可搜尋;大腦本機看得到全部,連到大腦的螢幕電腦每個連接器最多 80 個、說明最多 160 字),最下面「移除這個連接器」(再確認一次)。「瀏覽市集」(連接器市集、公用市集)和「新增連接器」各是一頁。
|
- 清單+各自的頁(跟 Claude、ChatGPT 的設定一樣):「已加入」每個連接器一列(名稱、狀態點「已連上,N 個工具」/錯誤原因、開關、›);點一列進到它自己的頁:狀態、登入、重新連線、開關,「工具(N)」只列它自己的工具(多時可搜尋;大腦本機看得到全部,連到大腦的螢幕電腦每個連接器最多 80 個、說明最多 160 字),「設定」(各欄位和「給 Bot 的使用說明」——原版的 MCP 自訂說明,會放進 Bot 的系統指示),最下面「移除這個連接器」(再確認一次)。名稱打完按 Enter、離開欄位或離開這一頁才改(Esc 放回原來的;空白或同名不改);改名時登入、金鑰、密碼、在清單裡的位置都留著——在螢幕電腦上改名是請大腦改它自己那一個(`/api/sync/mcp-rename`,排在帶新名字的修改之前),不是讓大腦從網址猜。「瀏覽市集」(連接器市集、公用市集)和「新增連接器」各是一頁。
|
||||||
- 技能頁同樣是清單+各自的頁:「已加入(N)」每列名稱、一行說明、開關、›(超過 8 個可搜尋);點進去看完整說明、可重播步數、隨附檔案、內容和「刪除」;內建技能包、Anthropic 開源技能、從網址安裝都在「瀏覽市集」頁。
|
- 技能頁同樣是清單+各自的頁:「已加入(N)」每列名稱、一行說明、開關、›(超過 8 個可搜尋);點進去看完整說明、可重播步數、隨附檔案、內容和「刪除」;內建技能包、Anthropic 開源技能、從網址安裝都在「瀏覽市集」頁。
|
||||||
- 工具名稱給模型看時是 `mcp__<連接器>__<工具>`(最多 64 字;中文名稱的連接器用一段固定代碼)。
|
- 工具名稱給模型看時是 `mcp__<連接器>__<工具>`(最多 64 字;中文名稱的連接器用一段固定代碼)。
|
||||||
- **帳號和密碼**:「新增連接器」頁和每個連接器自己的頁都有「帳號」「密碼」兩欄(給用帳號密碼登入的伺服器,例如公司內部系統)。在連接器的頁上改了就會用新的重新連線。
|
- **帳號和密碼**:「新增連接器」頁和每個連接器自己的頁都有「帳號」「密碼」兩欄(給用帳號密碼登入的伺服器,例如公司內部系統)。在連接器的頁上改了就會用新的重新連線。
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
- 登入帳號(OAuth):遠端連接器回「要先登入」時,到那個連接器自己的頁按「登入」(只在大腦本機),或在聊天請 Bot 登入:瀏覽器打開登入頁,登入完自動接上;瀏覽器在別台電腦、登入後那頁打不開時,把那頁網址貼回聊天。Token 存在大腦、加密,不會同步到螢幕或手機;快到期自動換新,401 時換一次再試。
|
- 登入帳號(OAuth):遠端連接器回「要先登入」時,到那個連接器自己的頁按「登入」(只在大腦本機),或在聊天請 Bot 登入:瀏覽器打開登入頁,登入完自動接上;瀏覽器在別台電腦、登入後那頁打不開時,把那頁網址貼回聊天。Token 存在大腦、加密,不會同步到螢幕或手機;快到期自動換新,401 時換一次再試。
|
||||||
- 帳號、密碼:給要用帳號密碼登入的伺服器。在指令、環境變數、網址或標頭寫「{username}」「{password}」,就填在那裡;都沒寫時,本機伺服器收到環境變數 `MCP_USERNAME`、`MCP_PASSWORD`,遠端伺服器收到 Basic 驗證。
|
- 帳號、密碼:給要用帳號密碼登入的伺服器。在指令、環境變數、網址或標頭寫「{username}」「{password}」,就填在那裡;都沒寫時,本機伺服器收到環境變數 `MCP_USERNAME`、`MCP_PASSWORD`,遠端伺服器收到 Basic 驗證。
|
||||||
- 「給 Bot 的使用說明」:寫進 Bot 的系統指示(例如「查詢客戶資料時先用 search_customers」)。
|
- 「給 Bot 的使用說明」:寫進 Bot 的系統指示(例如「查詢客戶資料時先用 search_customers」)。
|
||||||
- 頁面跟其他 App 的設定一樣是「清單+各自的頁」:最上面一張小卡「連接器(MCP)」和兩個按鈕「瀏覽市集」「新增連接器」;下面「已加入」每個連接器一列,只有名稱、色點和狀態(「已連上,N 個工具」「連線中…」「未連線」「已關閉」或紅字錯誤原因)、開關和 ›。按那一列(開關以外的地方)進到它自己的頁:最上面名稱、狀態、「登入」(遠端的)「重新連線」和開關(下面一行是登入或改名沒成功的原因);接著「工具(N)」列它自己的工具(名字和一行說明,滑過看全文;超過 8 個有「搜尋工具」;連上之後才有);再下面「設定」卡是它的欄位(名稱、指令或網址、環境變數、標頭、帳號和密碼並排、給 Bot 的使用說明——每個欄位名稱都在輸入框上面;名稱打完按 Enter、離開欄位或離開這一頁才改,Esc 放回原來的;空白或跟別的連接器同名不改並說原因;改名後登入跟著新名字(在大腦上:不管是這台、螢幕電腦還是 Bot 改的);在螢幕電腦上改名,大腦照網址或指令找回它的金鑰和密碼);最下面紅字「移除這個連接器」,再按「確定移除」才移除。左上「‹ 連接器」回清單。不再有把所有連接器的工具攤在一起的「可以用的工具」。「新增連接器」是它自己的頁(同樣的欄位,名稱在上、框在下),按「新增」後直接到新連接器的頁看它連線。
|
- 頁面跟其他 App 的設定一樣是「清單+各自的頁」:最上面一張小卡「連接器(MCP)」和兩個按鈕「瀏覽市集」「新增連接器」;下面「已加入」每個連接器一列,只有名稱、色點和狀態(「已連上,N 個工具」「連線中…」「未連線」「已關閉」或紅字錯誤原因)、開關和 ›。按那一列(開關以外的地方)進到它自己的頁:最上面名稱、狀態、「登入」(遠端的)「重新連線」和開關(下面一行是登入或改名沒成功的原因);接著「工具(N)」列它自己的工具(名字和一行說明,滑過看全文;超過 8 個有「搜尋工具」;連上之後才有);再下面「設定」卡是它的欄位(名稱、指令或網址、環境變數、標頭、帳號和密碼並排、給 Bot 的使用說明——每個欄位名稱都在輸入框上面;名稱打完按 Enter、離開欄位或離開這一頁才改,Esc 放回原來的;空白或跟別的連接器同名不改並說原因;改名後登入、金鑰、密碼和在清單裡的位置都留著;在螢幕電腦上改名是請大腦改它自己那一個,連不到大腦時不改;Bot 的 `manage_connectors` 不能改名);最下面紅字「移除這個連接器」,再按「確定移除」才移除。左上「‹ 連接器」回清單。不再有把所有連接器的工具攤在一起的「可以用的工具」。「新增連接器」是它自己的頁(同樣的欄位,名稱在上、框在下),按「新增」後直接到新連接器的頁看它連線。
|
||||||
- 「瀏覽市集」頁的「連接器市集」:8 個常用的(files、memory、thinking、fetch、git、time、playwright、github),按「加入」就能用;要金鑰的(github)會打開「新增連接器」頁並填好,補上 Token 再按「新增」。
|
- 「瀏覽市集」頁的「連接器市集」:8 個常用的(files、memory、thinking、fetch、git、time、playwright、github),按「加入」就能用;要金鑰的(github)會打開「新增連接器」頁並填好,補上 Token 再按「新增」。
|
||||||
- 同一頁的「公用市集(官方 MCP Registry)」:搜尋用網址連的連接器,按「加入」會打開填好的「新增連接器」頁;還有「{…}」沒換成你的值時,按不下「新增」。
|
- 同一頁的「公用市集(官方 MCP Registry)」:搜尋用網址連的連接器,按「加入」會打開填好的「新增連接器」頁;還有「{…}」沒換成你的值時,按不下「新增」。
|
||||||
- 給 Bot 的方式:所有連接器加起來 20 個工具以內,每個工具直接給,名字是 `mcp__連接器__工具`;超過 20 個,只給 `find_connector_tool` 和 `use_connector_tool`。
|
- 給 Bot 的方式:所有連接器加起來 20 個工具以內,每個工具直接給,名字是 `mcp__連接器__工具`;超過 20 個,只給 `find_connector_tool` 和 `use_connector_tool`。
|
||||||
|
|
|
||||||
|
|
@ -48,8 +48,6 @@ pub struct ChannelUi {
|
||||||
mcp_confirm: Option<String>,
|
mcp_confirm: Option<String>,
|
||||||
/// What is typed in a connector's page to find one of its tools.
|
/// What is typed in a connector's page to find one of its tools.
|
||||||
tool_q: String,
|
tool_q: String,
|
||||||
/// The connectors (name, where each connects) as last seen: to tell a rename (follow_renames).
|
|
||||||
mcp_prev: Option<Vec<(String, String)>>,
|
|
||||||
/// A connector's name as it is being typed (whose, the words): changed when done.
|
/// A connector's name as it is being typed (whose, the words): changed when done.
|
||||||
pub(super) mcp_name: Option<(String, String)>,
|
pub(super) mcp_name: Option<(String, String)>,
|
||||||
/// What a connector's page says (a login that didn't start, a name not taken).
|
/// What a connector's page says (a login that didn't start, a name not taken).
|
||||||
|
|
@ -82,7 +80,7 @@ impl Default for ChannelUi {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
let (trig_tx, trig_rx) = channel();
|
let (trig_tx, trig_rx) = channel();
|
||||||
ChannelUi { tx, rx, replies: HashMap::new(), waiting: VecDeque::new(), new_kind: Kind::Telegram, new_name: String::new(), new_token: String::new(), new_target: String::new(), new_bot: 0, note: Default::default(), started: false, trig_tx, trig_rx, trig_sig: String::new(), new_client: String::new(), new_tenant: String::new(), ms_login: Default::default(), mcp_sig: String::new(), mcp_errors: Default::default(), mcp_busy: Default::default(), mcp_tried: None, new_mcp: Default::default(), sub: 0, adding: false, skill_src: String::new(), skill_page: Page::List, skill_q: String::new(), skill_confirm: None, skill_busy: Default::default(), skill_reload: Default::default(), skill_note: Default::default(), skill_note_list: false, new_mcp_hint: String::new(), new_mcp_login: Default::default(), mcp_page: Page::List, mcp_confirm: None, tool_q: String::new(), mcp_prev: None, mcp_name: None, mcp_note: Default::default(), page_key: None, reg_q: String::new(), reg_busy: Default::default(), reg_found: Default::default() }
|
ChannelUi { tx, rx, replies: HashMap::new(), waiting: VecDeque::new(), new_kind: Kind::Telegram, new_name: String::new(), new_token: String::new(), new_target: String::new(), new_bot: 0, note: Default::default(), started: false, trig_tx, trig_rx, trig_sig: String::new(), new_client: String::new(), new_tenant: String::new(), ms_login: Default::default(), mcp_sig: String::new(), mcp_errors: Default::default(), mcp_busy: Default::default(), mcp_tried: None, new_mcp: Default::default(), sub: 0, adding: false, skill_src: String::new(), skill_page: Page::List, skill_q: String::new(), skill_confirm: None, skill_busy: Default::default(), skill_reload: Default::default(), skill_note: Default::default(), skill_note_list: false, new_mcp_hint: String::new(), new_mcp_login: Default::default(), mcp_page: Page::List, mcp_confirm: None, tool_q: String::new(), mcp_name: None, mcp_note: Default::default(), page_key: None, reg_q: String::new(), reg_busy: Default::default(), reg_found: Default::default() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -447,7 +445,6 @@ impl App {
|
||||||
Err(e) => self.notice = Some(format!("連接器「{name}」沒有登入成功:{e}")),
|
Err(e) => self.notice = Some(format!("連接器「{name}」沒有登入成功:{e}")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.follow_renames();
|
|
||||||
if self.ch.mcp_busy.load(Ordering::SeqCst) {
|
if self.ch.mcp_busy.load(Ordering::SeqCst) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -467,30 +464,6 @@ impl App {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Connectors renamed since the last look — here, from a screen of this brain, or by a bot:
|
|
||||||
/// the same address or command under a new name. Their sign-in (kept by name, here on the
|
|
||||||
/// brain) and their error follow, before they are connected again.
|
|
||||||
pub(super) fn follow_renames(&mut self) {
|
|
||||||
let endpoint = |s: &crate::mcp::Server| format!("{}\n{}\n{}", s.url.trim(), s.command.trim(), s.args.join(" "));
|
|
||||||
let now: Vec<(String, String)> = self.state.mcp_servers.iter().map(|s| (s.name.clone(), endpoint(s))).collect();
|
|
||||||
let Some(before) = self.ch.mcp_prev.replace(now.clone()) else { return };
|
|
||||||
if before == now {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let mut taken: Vec<&str> = vec![];
|
|
||||||
for (old, ep) in &before {
|
|
||||||
if ep.trim().is_empty() || now.iter().any(|(n, _)| n == old) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// (A name that is new, with the same address or command — each new one once.)
|
|
||||||
if let Some((new, _)) = now.iter().find(|(n, e)| e == ep && !before.iter().any(|(b, _)| b == n) && !taken.contains(&n.as_str())) {
|
|
||||||
taken.push(new);
|
|
||||||
crate::mcp_oauth::rename(old, new);
|
|
||||||
self.ch.mcp_errors.lock().unwrap().retain(|e| &e.0 != old);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 管理連接器 (a bot asked; the person already said yes to a change): the brain's own list
|
/// 管理連接器 (a bot asked; the person already said yes to a change): the brain's own list
|
||||||
/// changes, as 新增連接器 / 設定 / 移除 would, and the answer waits until the connector has
|
/// changes, as 新增連接器 / 設定 / 移除 would, and the answer waits until the connector has
|
||||||
/// connected or said why not (at most CONNECT_WAIT; a first `npx` may download for a while).
|
/// connected or said why not (at most CONNECT_WAIT; a first `npx` may download for a while).
|
||||||
|
|
@ -698,13 +671,28 @@ impl App {
|
||||||
*self.ch.mcp_note.lock().unwrap() = why;
|
*self.ch.mcp_note.lock().unwrap() = why;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let Some(s) = self.state.mcp_servers.iter_mut().find(|s| s.name == whose) else {
|
if !self.state.mcp_servers.iter().any(|s| s.name == whose) {
|
||||||
*self.ch.mcp_note.lock().unwrap() = t("這個連接器已經被改名或移除了,名稱沒有改。");
|
*self.ch.mcp_note.lock().unwrap() = t("這個連接器已經被改名或移除了,名稱沒有改。");
|
||||||
return;
|
return;
|
||||||
};
|
}
|
||||||
s.name = want.clone();
|
// On a screen the connector is the brain's: the brain is told to rename it — its own
|
||||||
|
// entry, with its keys, its place in the list and its sign-in — before the edit that
|
||||||
|
// carries the new name (one worker sends them in order). Not guessed from addresses.
|
||||||
|
if self.mir.on {
|
||||||
|
if !self.mir.online {
|
||||||
|
*self.ch.mcp_note.lock().unwrap() = t("連不到大腦,名稱沒有改。");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.mirror_mcp_rename(&whose, &want);
|
||||||
|
} else {
|
||||||
|
// (Its sign-in is kept under its name, here: it moves with it.)
|
||||||
|
crate::mcp_oauth::rename(&whose, &want);
|
||||||
|
self.ch.mcp_errors.lock().unwrap().retain(|e| e.0 != whose);
|
||||||
|
}
|
||||||
|
if let Some(s) = self.state.mcp_servers.iter_mut().find(|s| s.name == whose) {
|
||||||
|
s.name = want.clone();
|
||||||
|
}
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
// (Its sign-in and error follow it on the brain: follow_renames, there.)
|
|
||||||
self.ch.mcp_note.lock().unwrap().clear();
|
self.ch.mcp_note.lock().unwrap().clear();
|
||||||
if self.ch.mcp_page == Page::Item(whose.clone()) {
|
if self.ch.mcp_page == Page::Item(whose.clone()) {
|
||||||
self.ch.mcp_page = Page::Item(want.clone());
|
self.ch.mcp_page = Page::Item(want.clone());
|
||||||
|
|
@ -1518,31 +1506,6 @@ fn listing_row(ui: &mut egui::Ui, buttons: impl FnOnce(&mut egui::Ui), words: im
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
/// A connector renamed — here, from a screen, by a bot — keeps its sign-in on the brain: the
|
|
||||||
/// brain sees the same address under a new name. One that also moved elsewhere doesn't.
|
|
||||||
#[test]
|
|
||||||
fn the_brain_moves_a_renamed_connectors_sign_in() {
|
|
||||||
let ctx = egui::Context::default();
|
|
||||||
let mut app = App::new(&ctx, Some(std::env::temp_dir().join("anybot-follow-renames.png")));
|
|
||||||
let tag = crate::httpd::random_hex(4);
|
|
||||||
let (a, b) = (format!("gh-{tag}"), format!("notion-{tag}"));
|
|
||||||
let server = |n: &str, url: &str| crate::mcp::Server { name: n.into(), url: url.into(), enabled: true, ..Default::default() };
|
|
||||||
app.state.mcp_servers = vec![server(&a, "https://gh.example/mcp"), server(&b, "https://notion.example/mcp")];
|
|
||||||
for (n, url) in [(&a, "https://gh.example/mcp"), (&b, "https://notion.example/mcp")] {
|
|
||||||
crate::mcp_oauth::save_for_test(n, crate::mcp_oauth::Tokens { access: format!("tok-{n}"), url: url.into(), ..Default::default() });
|
|
||||||
}
|
|
||||||
app.follow_renames();
|
|
||||||
// As a screen's edit leaves it: one renamed, one renamed and pointed elsewhere.
|
|
||||||
app.state.mcp_servers = vec![server(&format!("{a}-work"), "https://gh.example/mcp"), server(&format!("{b}-2"), "https://other.example/mcp")];
|
|
||||||
app.follow_renames();
|
|
||||||
assert_eq!(crate::mcp_oauth::bearer(&format!("{a}-work"), "https://gh.example/mcp"), Some(format!("tok-{a}")));
|
|
||||||
assert!(crate::mcp_oauth::tokens(&a).is_none());
|
|
||||||
assert!(crate::mcp_oauth::tokens(&format!("{b}-2")).is_none(), "moved elsewhere: not its sign-in");
|
|
||||||
for n in [format!("{a}-work"), b.clone()] {
|
|
||||||
let _ = crate::mcp_oauth::logout(&n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A message from a channel never joins a turn that is running: it waits for its own.
|
/// A message from a channel never joins a turn that is running: it waits for its own.
|
||||||
#[test]
|
#[test]
|
||||||
fn a_channel_message_waits_for_a_turn_of_its_own() {
|
fn a_channel_message_waits_for_a_turn_of_its_own() {
|
||||||
|
|
|
||||||
|
|
@ -163,24 +163,10 @@ fn unredact(new: &mut Value, old: &Value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Value::Array(a) => {
|
Value::Array(a) => {
|
||||||
let key_of = |x: &Value| x.get("id").cloned().filter(|x| !x.is_null()).or_else(|| x.get("name").cloned().filter(|s| s.as_str().is_some_and(|t| !t.is_empty())));
|
|
||||||
let new_names: Vec<Value> = a.iter().filter_map(key_of).collect();
|
|
||||||
let mut used: Vec<usize> = vec![];
|
|
||||||
for (i, v) in a.iter_mut().enumerate() {
|
for (i, v) in a.iter_mut().enumerate() {
|
||||||
let key = |x: &Value| x.get("id").cloned().filter(|x| !x.is_null()).or_else(|| x.get("name").cloned().filter(|s| s.as_str().is_some_and(|t| !t.is_empty())));
|
let key = |x: &Value| x.get("id").cloned().filter(|x| !x.is_null()).or_else(|| x.get("name").cloned().filter(|s| s.as_str().is_some_and(|t| !t.is_empty())));
|
||||||
// (One renamed on a screen — a connector — is found by where it connects instead:
|
|
||||||
// the same address or command, so its secrets go nowhere new. Only an old one whose
|
|
||||||
// name is gone from the edit: it was renamed, not kept beside it.)
|
|
||||||
let endpoint = |x: &Value| ["url", "command", "args"].iter().map(|k| x.get(*k).cloned().unwrap_or(Value::Null)).collect::<Vec<_>>();
|
|
||||||
let reaches = |x: &Value| ["url", "command"].iter().any(|k| x.get(*k).and_then(Value::as_str).is_some_and(|s| !s.is_empty()));
|
|
||||||
let twin = old.as_array().and_then(|olds| match key(v) {
|
let twin = old.as_array().and_then(|olds| match key(v) {
|
||||||
Some(k) => olds.iter().find(|o| key(o).as_ref() == Some(&k)).or_else(|| {
|
Some(k) => olds.iter().find(|o| key(o).as_ref() == Some(&k)),
|
||||||
// (Each old one found this way once: two renamed copies of one address
|
|
||||||
// don't both get the first one's secrets.)
|
|
||||||
let j = olds.iter().enumerate().position(|(j, o)| !used.contains(&j) && reaches(o) && reaches(v) && endpoint(o) == endpoint(v) && key(o).is_some_and(|n| !new_names.contains(&n)))?;
|
|
||||||
used.push(j);
|
|
||||||
olds.get(j)
|
|
||||||
}),
|
|
||||||
None => olds.get(i),
|
None => olds.get(i),
|
||||||
});
|
});
|
||||||
unredact(v, twin.unwrap_or(&Value::Null));
|
unredact(v, twin.unwrap_or(&Value::Null));
|
||||||
|
|
@ -455,6 +441,8 @@ enum Out {
|
||||||
Skill { body: Value, note: SkillNote, busy: Arc<AtomicBool> },
|
Skill { body: Value, note: SkillNote, busy: Arc<AtomicBool> },
|
||||||
/// 連接器 › 重新連線 on a screen: the servers run at the brain.
|
/// 連接器 › 重新連線 on a screen: the servers run at the brain.
|
||||||
McpReconnect(String),
|
McpReconnect(String),
|
||||||
|
/// A connector renamed on a screen (old, new): the brain renames its own (see commit_mcp_name).
|
||||||
|
McpRename(String, String),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Where a skill request's answer is shown: (worked, words).
|
/// Where a skill request's answer is shown: (worked, words).
|
||||||
|
|
@ -1340,6 +1328,11 @@ impl App {
|
||||||
*err.lock().unwrap() = format!("大腦沒有重新連線:{e}");
|
*err.lock().unwrap() = format!("大腦沒有重新連線:{e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Out::McpRename(old, new) => {
|
||||||
|
if let Err(e) = remote::sync_post(&s, "mcp-rename", &json!({"name": old, "rename": new})) {
|
||||||
|
*err.lock().unwrap() = format!("大腦沒有改連接器的名稱:{e}");
|
||||||
|
}
|
||||||
|
}
|
||||||
Out::Send { bot, text, atts, memories } => {
|
Out::Send { bot, text, atts, memories } => {
|
||||||
let mut paths = vec![];
|
let mut paths = vec![];
|
||||||
for a in &atts {
|
for a in &atts {
|
||||||
|
|
@ -1399,6 +1392,10 @@ impl App {
|
||||||
|
|
||||||
/// 連接器 › 重新連線 on a screen: the brain connects it again; its line says 連線中… until
|
/// 連接器 › 重新連線 on a screen: the brain connects it again; its line says 連線中… until
|
||||||
/// the brain's next word on it.
|
/// the brain's next word on it.
|
||||||
|
pub(super) fn mirror_mcp_rename(&mut self, old: &str, new: &str) {
|
||||||
|
self.mirror_out(Out::McpRename(old.to_string(), new.to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn mirror_mcp_reconnect(&mut self, name: &str) {
|
pub(super) fn mirror_mcp_reconnect(&mut self, name: &str) {
|
||||||
if !self.mir.online {
|
if !self.mir.online {
|
||||||
*self.mir.error.lock().unwrap() = "連不到大腦,現在只能看。".into();
|
*self.mir.error.lock().unwrap() = "連不到大腦,現在只能看。".into();
|
||||||
|
|
@ -1613,22 +1610,12 @@ mod tests {
|
||||||
let mut ch = v["channels"].clone();
|
let mut ch = v["channels"].clone();
|
||||||
unredact(&mut ch, &old["channels"]);
|
unredact(&mut ch, &old["channels"]);
|
||||||
assert_eq!(ch[0]["token"], "t");
|
assert_eq!(ch[0]["token"], "t");
|
||||||
// A connector renamed on a screen keeps its secrets (found by its address) — but not a
|
// Secrets are found by name only: a renamed item (the brain wasn't told) gets none — never
|
||||||
// renamed one that also points somewhere else, nor a copy beside the one it came from.
|
// another item's that happens to have the same address.
|
||||||
let servers = json!([{"name": "gh", "url": "https://x.example/mcp", "headers": {"Authorization": "Bearer real"}, "password": "pw"}]);
|
let servers = json!([{"name": "a", "url": "https://x.example/mcp", "password": "pa"}, {"name": "b", "url": "https://x.example/mcp", "password": "pb"}]);
|
||||||
let mut renamed = json!([{"name": "gh-work", "url": "https://x.example/mcp", "headers": {"Authorization": REDACTED}, "password": REDACTED}]);
|
let mut guessed = json!([{"name": "c", "url": "https://x.example/mcp", "password": REDACTED}]);
|
||||||
unredact(&mut renamed, &servers);
|
unredact(&mut guessed, &servers);
|
||||||
assert_eq!((renamed[0]["headers"]["Authorization"].clone(), renamed[0]["password"].clone()), (json!("Bearer real"), json!("pw")));
|
assert_eq!(guessed[0]["password"], "");
|
||||||
let mut moved = json!([{"name": "gh-work", "url": "https://evil.example/mcp", "headers": {"Authorization": REDACTED}, "password": REDACTED}]);
|
|
||||||
unredact(&mut moved, &servers);
|
|
||||||
assert_eq!((moved[0]["headers"]["Authorization"].clone(), moved[0]["password"].clone()), (json!(""), json!("")));
|
|
||||||
let two = json!([{"name": "a", "url": "https://x.example/mcp", "password": "pa"}, {"name": "b", "url": "https://x.example/mcp", "password": "pb"}]);
|
|
||||||
let mut both = json!([{"name": "a2", "url": "https://x.example/mcp", "password": REDACTED}, {"name": "b2", "url": "https://x.example/mcp", "password": REDACTED}]);
|
|
||||||
unredact(&mut both, &two);
|
|
||||||
assert_eq!((both[0]["password"].clone(), both[1]["password"].clone()), (json!("pa"), json!("pb")), "each its own");
|
|
||||||
let mut copy = json!([{"name": "gh", "url": "https://x.example/mcp", "password": REDACTED}, {"name": "gh-2", "url": "https://x.example/mcp", "password": REDACTED}]);
|
|
||||||
unredact(&mut copy, &servers);
|
|
||||||
assert_eq!((copy[0]["password"].clone(), copy[1]["password"].clone()), (json!("pw"), json!("")));
|
|
||||||
// Changing base_url while keeping REDACTED must NEVER send the brain's real key to the new server.
|
// Changing base_url while keeping REDACTED must NEVER send the brain's real key to the new server.
|
||||||
let mut exfil = v["providers"].clone();
|
let mut exfil = v["providers"].clone();
|
||||||
exfil["xai"]["base_url"] = json!("https://evil.example/v1");
|
exfil["xai"]["base_url"] = json!("https://evil.example/v1");
|
||||||
|
|
|
||||||
|
|
@ -1593,6 +1593,19 @@ impl App {
|
||||||
self.mcp_reconnect(&name);
|
self.mcp_reconnect(&name);
|
||||||
return done("重新連線中…");
|
return done("重新連線中…");
|
||||||
}
|
}
|
||||||
|
// Renamed (from a screen): this entry keeps its keys, its place and its sign-in.
|
||||||
|
if let Some(new) = b["rename"].as_str().map(str::trim) {
|
||||||
|
if new.is_empty() || self.state.mcp_servers.iter().any(|m| m.name == new) {
|
||||||
|
return fail("名稱不能空白,也不能跟別的連接器一樣");
|
||||||
|
}
|
||||||
|
if let Some(m) = self.state.mcp_servers.iter_mut().find(|m| m.name == name) {
|
||||||
|
m.name = new.to_string();
|
||||||
|
}
|
||||||
|
crate::mcp_oauth::rename(&name, new);
|
||||||
|
self.ch.mcp_errors.lock().unwrap().retain(|e| e.0 != name);
|
||||||
|
self.dirty = true;
|
||||||
|
return done("好了");
|
||||||
|
}
|
||||||
// (mcp_poll connects or drops it when the list changes.)
|
// (mcp_poll connects or drops it when the list changes.)
|
||||||
if b["remove"].as_bool().unwrap_or(false) {
|
if b["remove"].as_bool().unwrap_or(false) {
|
||||||
self.state.mcp_servers.retain(|m| m.name != name);
|
self.state.mcp_servers.retain(|m| m.name != name);
|
||||||
|
|
@ -1970,6 +1983,29 @@ mod phone_act_tests {
|
||||||
assert!(app.phone_act(&ctx, "skill", &json!({"builtin": "pdf"}), "admin")["error"].is_string());
|
assert!(app.phone_act(&ctx, "skill", &json!({"builtin": "pdf"}), "admin")["error"].is_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A connector renamed on a screen: the brain renames its own entry — its keys, its place in
|
||||||
|
/// the list and its sign-in stay — and refuses an empty or taken name.
|
||||||
|
#[test]
|
||||||
|
fn the_brain_renames_a_connector_for_a_screen() {
|
||||||
|
let (ctx, mut app) = demo();
|
||||||
|
let tag = crate::httpd::random_hex(4);
|
||||||
|
let (gh, other) = (format!("gh-{tag}"), format!("x-{tag}"));
|
||||||
|
let server = |n: &str, url: &str| crate::mcp::Server { name: n.into(), url: url.into(), password: "pw".into(), enabled: true, ..Default::default() };
|
||||||
|
app.state.mcp_servers = vec![server(&gh, "https://gh.example/mcp"), server(&other, "https://x.example/mcp")];
|
||||||
|
crate::mcp_oauth::save_for_test(&gh, crate::mcp_oauth::Tokens { access: "tok".into(), url: "https://gh.example/mcp".into(), ..Default::default() });
|
||||||
|
let new = format!("{gh}-work");
|
||||||
|
assert_eq!(app.phone_act(&ctx, "mcp", &json!({"name": gh, "rename": new}), "owner")["ok"], true);
|
||||||
|
let first = &app.state.mcp_servers[0];
|
||||||
|
assert_eq!((first.name.as_str(), first.password.as_str()), (new.as_str(), "pw"), "same place, same keys");
|
||||||
|
assert_eq!(crate::mcp_oauth::bearer(&new, "https://gh.example/mcp").as_deref(), Some("tok"));
|
||||||
|
assert!(crate::mcp_oauth::tokens(&gh).is_none());
|
||||||
|
for bad in [other.as_str(), " "] {
|
||||||
|
assert!(app.phone_act(&ctx, "mcp", &json!({"name": new, "rename": bad}), "owner")["error"].is_string(), "{bad:?}");
|
||||||
|
}
|
||||||
|
assert!(app.phone_act(&ctx, "mcp", &json!({"name": new, "rename": "y"}), "admin")["error"].is_string(), "the owner's only");
|
||||||
|
let _ = crate::mcp_oauth::logout(&new);
|
||||||
|
}
|
||||||
|
|
||||||
/// The phone's 公用市集 adds a server reached by address, with its key; never one with a
|
/// The phone's 公用市集 adds a server reached by address, with its key; never one with a
|
||||||
/// 「{…}」 left in it, never twice under one name, only the owner.
|
/// 「{…}」 left in it, never twice under one name, only the owner.
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
|
|
@ -749,6 +749,7 @@ pub const ROWS: &[(&str, &str, &str)] = &[
|
||||||
("關著:不列進任何 Bot 的說明", "Off: not given to any bot", "オフ:どの Bot にも渡されません"),
|
("關著:不列進任何 Bot 的說明", "Off: not given to any bot", "オフ:どの Bot にも渡されません"),
|
||||||
("接上 Model Context Protocol 伺服器,Bot 就能用它的工具(例如 GitHub、Notion、資料庫、你公司的內部系統)。本機伺服器填指令(例如 npx -y @modelcontextprotocol/server-filesystem ~/Documents);遠端伺服器填網址(Streamable HTTP),需要時加上 Authorization 標頭。", "Connect Model Context Protocol servers and bots can use their tools (GitHub, Notion, databases, your company's own systems). A local server takes a command (e.g. npx -y @modelcontextprotocol/server-filesystem ~/Documents); a remote one an address (Streamable HTTP), with an Authorization header if needed.", "Model Context Protocol サーバーを接続すると、Bot がそのツールを使えます(GitHub、Notion、データベース、社内システムなど)。ローカルのサーバーはコマンド(例:npx -y @modelcontextprotocol/server-filesystem ~/Documents)、リモートのサーバーはアドレス(Streamable HTTP)を入力し、必要なら Authorization ヘッダーを付けます。"),
|
("接上 Model Context Protocol 伺服器,Bot 就能用它的工具(例如 GitHub、Notion、資料庫、你公司的內部系統)。本機伺服器填指令(例如 npx -y @modelcontextprotocol/server-filesystem ~/Documents);遠端伺服器填網址(Streamable HTTP),需要時加上 Authorization 標頭。", "Connect Model Context Protocol servers and bots can use their tools (GitHub, Notion, databases, your company's own systems). A local server takes a command (e.g. npx -y @modelcontextprotocol/server-filesystem ~/Documents); a remote one an address (Streamable HTTP), with an Authorization header if needed.", "Model Context Protocol サーバーを接続すると、Bot がそのツールを使えます(GitHub、Notion、データベース、社内システムなど)。ローカルのサーバーはコマンド(例:npx -y @modelcontextprotocol/server-filesystem ~/Documents)、リモートのサーバーはアドレス(Streamable HTTP)を入力し、必要なら Authorization ヘッダーを付けます。"),
|
||||||
("開著的技能會列在 Bot 的目錄裡,需要時自動載入。", "Skills that are on are listed in the bots' catalog and loaded when needed.", "オンのスキルは Bot のカタログに載り、必要なときに読み込まれます。"),
|
("開著的技能會列在 Bot 的目錄裡,需要時自動載入。", "Skills that are on are listed in the bots' catalog and loaded when needed.", "オンのスキルは Bot のカタログに載り、必要なときに読み込まれます。"),
|
||||||
|
("連不到大腦,名稱沒有改。", "Can't reach the brain; the name wasn't changed.", "ブレインに接続できないため、名前は変更していません。"),
|
||||||
("這個連接器已經被改名或移除了,名稱沒有改。", "This connector was renamed or removed meanwhile; the name wasn't changed.", "このコネクタは別の場所で名前変更または削除されたため、名前は変更していません。"),
|
("這個連接器已經被改名或移除了,名稱沒有改。", "This connector was renamed or removed meanwhile; the name wasn't changed.", "このコネクタは別の場所で名前変更または削除されたため、名前は変更していません。"),
|
||||||
("名稱不能空白,沒有改。", "A name can't be empty; it wasn't changed.", "名前は空にできません。変更していません。"),
|
("名稱不能空白,沒有改。", "A name can't be empty; it wasn't changed.", "名前は空にできません。変更していません。"),
|
||||||
("已經有叫「{n}」的連接器,名稱沒有改。", "There is already a connector called “{n}”; the name wasn't changed.", "「{n}」というコネクタがすでにあります。名前は変更していません。"),
|
("已經有叫「{n}」的連接器,名稱沒有改。", "There is already a connector called “{n}”; the name wasn't changed.", "「{n}」というコネクタがすでにあります。名前は変更していません。"),
|
||||||
|
|
|
||||||
|
|
@ -860,6 +860,8 @@ pub fn handle(req: Req, via_relay: bool) -> Resp {
|
||||||
("POST", ["api", "sync", "skill"]) => phone_act_for("skill", req.json(), "owner", 55),
|
("POST", ["api", "sync", "skill"]) => phone_act_for("skill", req.json(), "owner", 55),
|
||||||
// 連接器 › 重新連線 from a screen (the list itself changes through edits).
|
// 連接器 › 重新連線 from a screen (the list itself changes through edits).
|
||||||
("POST", ["api", "sync", "mcp"]) => phone_act_for("mcp", json!({"name": req.json()["name"], "reconnect": true}), "owner", 10),
|
("POST", ["api", "sync", "mcp"]) => phone_act_for("mcp", json!({"name": req.json()["name"], "reconnect": true}), "owner", 10),
|
||||||
|
// A connector renamed on a screen: the brain renames its own (keys, place, sign-in stay).
|
||||||
|
("POST", ["api", "sync", "mcp-rename"]) => phone_act_for("mcp", json!({"name": req.json()["name"], "rename": req.json()["rename"]}), "owner", 10),
|
||||||
("POST", ["api", "sync", "act"]) => {
|
("POST", ["api", "sync", "act"]) => {
|
||||||
let b = req.json();
|
let b = req.json();
|
||||||
let bot = b["bot"].as_u64().unwrap_or(0);
|
let bot = b["bot"].as_u64().unwrap_or(0);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue