// Bot 設定 › 個人檔案: who the bot is (its soul, what it is good at, what it leaves to others), // what it may do (能力), the skills it has and the computers it may use. The rules and the // roster that go with them are in profile.rs. use super::*; /// The editor's skill list scrolls past this height. const SKILL_LIST_MAX_H: f32 = 220.0; impl App { /// 個人檔案: soul, 擅長, 不找它做的事. pub(super) fn profile_identity_card(&mut self, ui: &mut egui::Ui, b: &mut Bot) { let p = self.pal; setting_card(ui, p, |ui| { setting_title(ui, "個人檔案", "Soul 只有這個 Bot 自己讀,放在它每次回答的最前面。「擅長」和「不找它做的事」會出現在其他 Bot 的同事名冊裡,讓它們知道什麼事該交給誰。", p); field_label(ui, "Soul(個性、價值觀、說話和做事的方式)", p); ui.add(egui::TextEdit::multiline(&mut b.soul).hint_text(t("例如:我是細心的研究員,只相信官方來源;先講結論、再給證據;不確定就說不確定,不硬猜。")).desired_rows(3).desired_width(f32::INFINITY)); field_label(ui, "擅長(什麼事找它)", p); ui.add(egui::TextEdit::singleline(&mut b.strengths).hint_text(t("例如:FSD 新聞和法規進度、維護追蹤頁")).desired_width(f32::INFINITY)); field_label(ui, "不找它做的事", p); ui.add(egui::TextEdit::singleline(&mut b.not_for).hint_text(t("例如:寫程式、操作別人的電腦")).desired_width(f32::INFINITY)); }); } /// 能力: the tool families it has. Fewer is safer and cheaper: what it lacks isn't offered /// (nor described) on any step. pub(super) fn profile_abilities_card(&mut self, ui: &mut egui::Ui, b: &mut Bot) { let p = self.pal; setting_card(ui, p, |ui| { setting_title(ui, "能力", "這個 Bot 可以用哪幾類工具。沒勾的不會提供給它,也不會寫進它的說明:每一步都比較省 token,也比較安全。記憶、技能、問你問題、傳檔案到聊天每個 Bot 都有。", p); let mut on: Vec = b.abilities.clone().unwrap_or_else(|| crate::profile::ABILITIES.iter().map(|a| a.0.to_string()).collect()); let mut changed = false; egui::Grid::new(("abilities", b.id)).num_columns(2).spacing([16.0, 4.0]).show(ui, |ui| { for (i, (key, label, what)) in crate::profile::ABILITIES.iter().enumerate() { let mut has = on.iter().any(|x| x == key); if ui.checkbox(&mut has, t(label)).on_hover_text(t(what)).changed() { changed = true; if has { on.push(key.to_string()); } else { on.retain(|x| x != key); } } if i % 2 == 1 { ui.end_row(); } } }); if changed { // All of them again: back to "everything", so families added later come too. b.abilities = if crate::profile::ABILITIES.iter().all(|a| on.iter().any(|x| x == a.0)) { None } else { Some(on) }; } let n = crate::profile::ABILITIES.iter().filter(|a| crate::profile::has(b, a.0)).count(); hint(ui, format!("{n} / {} 類", crate::profile::ABILITIES.len()), p); }); } /// 技能: the ones it has, out of the library (installed once, for all). pub(super) fn profile_skills_card(&mut self, ui: &mut egui::Ui, b: &mut Bot) { let p = self.pal; let all: Vec<(String, String)> = self.state.skills.iter().filter(|k| k.enabled).map(|k| (k.name.clone(), k.description.clone())).collect(); if all.is_empty() { return; } setting_card(ui, p, |ui| { setting_title(ui, "技能", "從技能庫勾選這個 Bot 會的技能。它的說明裡只列這些,用到時才讀完整做法。它自己學會(存成)的技能會自動加進來。", p); let mut mine: Vec = b.skills.clone().unwrap_or_else(|| all.iter().map(|k| k.0.clone()).collect()); let mut changed = false; ui.horizontal(|ui| { let n = all.iter().filter(|k| mine.contains(&k.0)).count(); ui.label(RichText::new(format!("{} {n} / {}", t("會"), all.len())).size(FONT_SM).color(p.text2)); ui.with_layout(Layout::right_to_left(Align::Center), |ui| { if ui.small_button(t("全不選")).clicked() { mine.clear(); changed = true; } if ui.small_button(t("全選")).clicked() { mine = all.iter().map(|k| k.0.clone()).collect(); changed = true; } }); }); egui::ScrollArea::vertical().id_salt(("skills", b.id)).max_height(SKILL_LIST_MAX_H).auto_shrink([false, true]).show(ui, |ui| { for (name, about) in &all { let mut has = mine.contains(name); let r = ui.checkbox(&mut has, name.as_str()); let r = if about.trim().is_empty() { r } else { r.on_hover_text(about.as_str()) }; if r.changed() { changed = true; if has { mine.push(name.clone()); } else { mine.retain(|x| x != name); } } } }); if changed { // In the library's order, so its instructions read the same every turn. let ordered: Vec = all.iter().filter(|k| mine.contains(&k.0)).map(|k| k.0.clone()).collect(); b.skills = if ordered.len() == all.len() { None } else { Some(ordered) }; } }); } /// Every computer there is for this bot (name, what it is): a screen of a brain asks the brain. fn every_computer(&self, b: &Bot) -> Vec<(String, String)> { if self.mir.on { return self.mir.computers.get(&b.id).and_then(|c| c["all"].as_array().or(c["names"].as_array()).cloned()).unwrap_or_default().iter().filter_map(|x| Some((x["name"].as_str()?.to_string(), x["kind"].as_str().unwrap_or("").to_string()))).collect(); } let t = self.all_targets_for(b); let r = self.roles_for(b, &t); t.iter().map(|x| (x.name.clone(), mirror_ui::computer_kind(x, &r).to_string())).collect() } /// 可以用的電腦: its own always; of the others, the ticked ones. pub(super) fn profile_computers(&mut self, ui: &mut egui::Ui, b: &mut Bot) { let p = self.pal; let own = crate::model::own_computer_name(&b.name); let all = self.every_computer(b); if all.len() <= 1 { return; } ui.add_space(6.0); ui.label(RichText::new(t("可以用的電腦")).size(FONT_XS).color(p.text2)); let mut on: Vec = b.computers.clone().unwrap_or_else(|| all.iter().map(|c| c.0.clone()).collect()); let mut changed = false; ui.horizontal_wrapped(|ui| { for (name, _) in &all { let is_own = *name == own || all.first().is_some_and(|f| f.0 == *name); let mut has = is_own || on.contains(name); let r = ui.add_enabled(!is_own, egui::Checkbox::new(&mut has, name.as_str())); let r = if is_own { r.on_disabled_hover_text(t("它自己的電腦一定可以用")) } else { r }; if r.changed() { changed = true; if has { on.push(name.clone()); } else { on.retain(|x| x != name); } } } }); if changed { let others: Vec = all.iter().skip(1).map(|c| c.0.clone()).collect(); let kept: Vec = others.iter().filter(|n| on.contains(n)).cloned().collect(); b.computers = if kept.len() == others.len() { None } else { Some(kept) }; // The computer it works on by default must be one of them. let chosen = b.default_computer.trim().to_string(); let allowed = chosen.is_empty() || chosen == crate::model::BOT_COMPUTER_NAME || chosen == own || b.computers.as_ref().is_none_or(|c| c.contains(&chosen)); if !allowed { b.default_computer = crate::model::BOT_COMPUTER_NAME.to_string(); } } hint(ui, "沒勾的電腦,這個 Bot 看不到也不能用;同事名冊會寫它在哪幾台做事,交辦時才知道該找誰。", p); } }