* claim: #7009 * Assistant: connect the last-used agent and open the panel at start (#7009) Two Settings > AI options, off by default: when SolidCraft starts, connect the agent started last (once the installed agents are known; a missing one is not swapped for another) and open the Assistant panel. Not for runs started with --control. A connection that never gets ready (no agent, start error, the agent ends while starting) is a new Failed state: the header reads Connection failed and Connect reads Retry. The control channel reports it as "failed" and takes connect_at_start / open_at_start. * Assistant: keep the start-up agent when a design replaces the blank one (#7009) Opening a design over the blank design SolidCraft starts with reset its chat and stopped the agent connected at start. A chat not asked anything yet now starts over in place and keeps its agent. Turning AI features off also drops a start-up connection still waiting for discovery. * i18n: Arabic, Hebrew and Vietnamese for the start-up options (#7009) ar, he and vi are complete catalogs on main now, so every new English message needs them. --------- Co-authored-by: MateuszSychXpl <151755914+MateuszSychXpl@users.noreply.github.com>
This commit is contained in:
@@ -419,7 +419,7 @@ fn wait_for_turn(control: &mut Control, mut chat: Value, began: Instant, end: In
|
||||
let idle = !matches!(state, "busy" | "starting") && !turn && !queued;
|
||||
// A turn can start and end between two polls: then the conversation has its answer.
|
||||
let answered = chat["items"].as_array().into_iter().flatten().any(|i| i.get("user").is_none());
|
||||
if idle && (seen_busy || answered || matches!(state, "exited" | "auth" | "off") || began.elapsed() >= START_GRACE) {
|
||||
if idle && (seen_busy || answered || matches!(state, "exited" | "failed" | "auth" | "off") || began.elapsed() >= START_GRACE) {
|
||||
return Ok((chat, false));
|
||||
}
|
||||
let Some(left) = end.checked_duration_since(Instant::now()).filter(|d| !d.is_zero()) else { return Ok((chat, true)) };
|
||||
|
||||
@@ -122,6 +122,7 @@ impl eframe::App for App {
|
||||
// Automation runs (a control port was asked for) leave the user's AI apps alone.
|
||||
if !self.take_focus_unwanted {
|
||||
solidcraft_ui_egui::ai_connect::begin(&mut self.solve);
|
||||
solidcraft_ui_egui::agent_chat::begin(&mut self.solve);
|
||||
}
|
||||
if let Some(dir) = self.starting.take() {
|
||||
startup::started(&dir);
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"en": {
|
||||
"ai.prefs.connect_at_start": "Connect the last-used agent when SolidCraft starts",
|
||||
"ai.prefs.connect_at_start_note": "Starts the agent you connected last (or the default one) in the background each time SolidCraft starts, so it is ready for chatting. Not when SolidCraft is started with --control. If it cannot connect, the Assistant shows Connection failed and a Retry button.",
|
||||
"ai.prefs.open_at_start": "Open the Assistant panel when SolidCraft starts",
|
||||
"ai.prefs.open_at_start_note": "Shows the Assistant panel (or its own window) each time SolidCraft starts. Not when SolidCraft is started with --control.",
|
||||
"ui.agent_chat_last_missing": "The agent used last ({agent}) is not available any more. Pick an agent, then press Retry.",
|
||||
"ui.agent_chat_retry": "Retry",
|
||||
"ui.agent_chat_state_failed": "Connection failed"
|
||||
},
|
||||
"ar": {
|
||||
"ai.prefs.connect_at_start": "الاتصال بآخر وكيل مستخدم عند بدء SolidCraft",
|
||||
"ai.prefs.connect_at_start_note": "يبدأ في الخلفية الوكيل الذي اتصلت به آخر مرة (أو الوكيل الافتراضي) في كل مرة يبدأ فيها SolidCraft، ليكون جاهزًا للمحادثة. لا يحدث ذلك عند بدء SolidCraft مع --control. إذا تعذّر الاتصال، يعرض المساعد «فشل الاتصال» وزر «إعادة المحاولة».",
|
||||
"ai.prefs.open_at_start": "فتح لوحة المساعد عند بدء SolidCraft",
|
||||
"ai.prefs.open_at_start_note": "يعرض لوحة المساعد (أو نافذتها المستقلة) في كل مرة يبدأ فيها SolidCraft. لا يحدث ذلك عند بدء SolidCraft مع --control.",
|
||||
"ui.agent_chat_last_missing": "الوكيل المستخدم آخر مرة ({agent}) لم يعد متاحًا. اختر وكيلًا، ثم اضغط «إعادة المحاولة».",
|
||||
"ui.agent_chat_retry": "إعادة المحاولة",
|
||||
"ui.agent_chat_state_failed": "فشل الاتصال"
|
||||
},
|
||||
"he": {
|
||||
"ai.prefs.connect_at_start": "התחברות לסוכן האחרון שבו השתמשת בהפעלת SolidCraft",
|
||||
"ai.prefs.connect_at_start_note": "מפעיל ברקע את הסוכן שאליו התחברת לאחרונה (או את סוכן ברירת המחדל) בכל הפעלה של SolidCraft, כך שהוא מוכן לשיחה. לא כש-SolidCraft מופעל עם --control. אם ההתחברות נכשלת, העוזר מציג „ההתחברות נכשלה” ולחצן „ניסיון חוזר”.",
|
||||
"ai.prefs.open_at_start": "פתיחת חלונית העוזר בהפעלת SolidCraft",
|
||||
"ai.prefs.open_at_start_note": "מציג את חלונית העוזר (או את החלון הנפרד שלה) בכל הפעלה של SolidCraft. לא כש-SolidCraft מופעל עם --control.",
|
||||
"ui.agent_chat_last_missing": "הסוכן שבו השתמשת לאחרונה ({agent}) כבר אינו זמין. בחר סוכן ולחץ על „ניסיון חוזר”.",
|
||||
"ui.agent_chat_retry": "ניסיון חוזר",
|
||||
"ui.agent_chat_state_failed": "ההתחברות נכשלה"
|
||||
},
|
||||
"ja": {
|
||||
"ai.prefs.connect_at_start": "SolidCraft の起動時に前回使用したエージェントに接続",
|
||||
"ai.prefs.connect_at_start_note": "SolidCraft を起動するたびに、前回接続したエージェント (またはデフォルトのエージェント) をバックグラウンドで起動し、すぐにチャットできるようにします。--control を付けて起動した場合は行いません。接続できない場合、アシスタントに「接続に失敗しました」と「再試行」ボタンが表示されます。",
|
||||
"ai.prefs.open_at_start": "SolidCraft の起動時にアシスタントパネルを開く",
|
||||
"ai.prefs.open_at_start_note": "SolidCraft を起動するたびにアシスタントパネル (または独立したウィンドウ) を表示します。--control を付けて起動した場合は行いません。",
|
||||
"ui.agent_chat_last_missing": "前回使用したエージェント ({agent}) は利用できなくなりました。エージェントを選んでから「再試行」を押してください。",
|
||||
"ui.agent_chat_retry": "再試行",
|
||||
"ui.agent_chat_state_failed": "接続に失敗しました"
|
||||
},
|
||||
"vi": {
|
||||
"ai.prefs.connect_at_start": "Kết nối tác tử dùng gần nhất khi SolidCraft khởi động",
|
||||
"ai.prefs.connect_at_start_note": "Mỗi lần SolidCraft khởi động, chạy ngầm tác tử bạn kết nối gần nhất (hoặc tác tử mặc định) để sẵn sàng trò chuyện. Không áp dụng khi SolidCraft được khởi động với --control. Nếu không kết nối được, Trợ lý hiển thị “Kết nối thất bại” và nút “Thử lại”.",
|
||||
"ai.prefs.open_at_start": "Mở bảng Trợ lý khi SolidCraft khởi động",
|
||||
"ai.prefs.open_at_start_note": "Hiển thị bảng Trợ lý (hoặc cửa sổ riêng của nó) mỗi lần SolidCraft khởi động. Không áp dụng khi SolidCraft được khởi động với --control.",
|
||||
"ui.agent_chat_last_missing": "Tác tử dùng gần nhất ({agent}) không còn khả dụng. Hãy chọn một tác tử rồi nhấn “Thử lại”.",
|
||||
"ui.agent_chat_retry": "Thử lại",
|
||||
"ui.agent_chat_state_failed": "Kết nối thất bại"
|
||||
},
|
||||
"zh": {
|
||||
"ai.prefs.connect_at_start": "SolidCraft 启动时连接上次使用的智能体",
|
||||
"ai.prefs.connect_at_start_note": "每次启动 SolidCraft 时,在后台启动上次连接的智能体(或默认智能体),以便随时开始聊天。使用 --control 启动 SolidCraft 时不会这样做。如果无法连接,助手会显示“连接失败”和“重试”按钮。",
|
||||
"ai.prefs.open_at_start": "SolidCraft 启动时打开助手面板",
|
||||
"ai.prefs.open_at_start_note": "每次启动 SolidCraft 时显示助手面板(或其独立窗口)。使用 --control 启动 SolidCraft 时不会这样做。",
|
||||
"ui.agent_chat_last_missing": "上次使用的智能体({agent})已不可用。请选择一个智能体,然后按“重试”。",
|
||||
"ui.agent_chat_retry": "重试",
|
||||
"ui.agent_chat_state_failed": "连接失败"
|
||||
}
|
||||
}
|
||||
@@ -76,6 +76,9 @@ pub enum State {
|
||||
Busy,
|
||||
NeedsAuth,
|
||||
Exited,
|
||||
/// The agent never got ready: none to start, it could not start, or it ended while starting.
|
||||
/// Connect reads Retry.
|
||||
Failed,
|
||||
}
|
||||
|
||||
impl State {
|
||||
@@ -87,6 +90,7 @@ impl State {
|
||||
State::Busy => "busy",
|
||||
State::NeedsAuth => "auth",
|
||||
State::Exited => "exited",
|
||||
State::Failed => "failed",
|
||||
}
|
||||
}
|
||||
fn label(self) -> &'static str {
|
||||
@@ -97,6 +101,7 @@ impl State {
|
||||
State::Busy => "ui.agent_chat_state_busy",
|
||||
State::NeedsAuth => "ui.agent_chat_state_auth",
|
||||
State::Exited => "ui.agent_chat_state_exited",
|
||||
State::Failed => "ui.agent_chat_state_failed",
|
||||
})
|
||||
}
|
||||
fn running(self) -> bool {
|
||||
@@ -417,6 +422,8 @@ pub struct AgentChat {
|
||||
pub control_starter: Option<ControlStarter>,
|
||||
/// The picker is unfolded (it folds to one line once an agent is connected).
|
||||
picking: Option<bool>,
|
||||
/// This launch connects the agent started last once the installed agents are known ([`begin`]).
|
||||
connect_at_start: bool,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
detection: Option<discover::Detection>,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
@@ -438,6 +445,7 @@ impl AgentChat {
|
||||
std::mem::swap(&mut self.control_starter, &mut other.control_starter);
|
||||
std::mem::swap(&mut self.models_cache, &mut other.models_cache);
|
||||
std::mem::swap(&mut self.window_placed, &mut other.window_placed);
|
||||
std::mem::swap(&mut self.connect_at_start, &mut other.connect_at_start);
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
std::mem::swap(&mut self.detection, &mut other.detection);
|
||||
@@ -701,12 +709,14 @@ impl AgentChat {
|
||||
}
|
||||
Event::Error(e) => {
|
||||
self.notice(e, true);
|
||||
if !self.state().running() || self.state() == State::Starting {
|
||||
self.state = Some(State::Exited);
|
||||
match self.state() {
|
||||
State::Starting | State::Failed => self.state = Some(State::Failed),
|
||||
s if !s.running() => self.state = Some(State::Exited),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Event::Exited { tail } => {
|
||||
self.state = Some(State::Exited);
|
||||
self.state = Some(if matches!(self.state(), State::Starting | State::Failed) { State::Failed } else { State::Exited });
|
||||
self.steering = false;
|
||||
let last: Vec<String> = tail.into_iter().rev().take(6).collect::<Vec<_>>().into_iter().rev().collect();
|
||||
let detail = if last.is_empty() { String::new() } else { format!("\n{}", last.join("\n")) };
|
||||
@@ -755,7 +765,7 @@ fn assistant_mark_for(state: State, login: &str, configured: bool, waiting: usiz
|
||||
if state == State::NeedsAuth {
|
||||
return AssistantMark::NeedsAuth;
|
||||
}
|
||||
if state == State::Exited || stopped || failed {
|
||||
if matches!(state, State::Exited | State::Failed) || stopped || failed {
|
||||
return AssistantMark::Stopped;
|
||||
}
|
||||
match state {
|
||||
@@ -829,7 +839,11 @@ fn working_dir() -> std::path::PathBuf {
|
||||
pub fn connect(app: &mut SolveApp, ctx: &egui::Context) {
|
||||
disconnect(app);
|
||||
let Some(entry) = agents::current(app) else {
|
||||
app.agent_chat.notice(tr("ui.agent_chat_none_found"), true);
|
||||
let chat = &mut app.agent_chat;
|
||||
chat.notice(panel::no_agents_message(), true);
|
||||
chat.state = Some(State::Failed);
|
||||
// The picker lists what to install (and, in the Flatpak, the permissions to grant).
|
||||
chat.picking = Some(true);
|
||||
return;
|
||||
};
|
||||
// An API agent's key comes from the keychain for this connection only.
|
||||
@@ -838,6 +852,7 @@ pub fn connect(app: &mut SolveApp, ctx: &egui::Context) {
|
||||
Some(Ok(k)) => k,
|
||||
Some(Err(e)) => {
|
||||
app.agent_chat.notice(trf("ui.ai_keychain_error", &[("error", &e)]), true);
|
||||
app.agent_chat.state = Some(State::Failed);
|
||||
return;
|
||||
}
|
||||
None => None,
|
||||
@@ -892,6 +907,7 @@ pub fn connect(app: &mut SolveApp, ctx: &egui::Context) {
|
||||
};
|
||||
match started {
|
||||
Ok(b) => {
|
||||
app.preferences.agent_last = entry.id.clone();
|
||||
chat.backend = Some(b);
|
||||
chat.argv = entry.argv.clone();
|
||||
chat.running_id = entry.id.clone();
|
||||
@@ -912,11 +928,52 @@ pub fn connect(app: &mut SolveApp, ctx: &egui::Context) {
|
||||
}
|
||||
Err(e) => {
|
||||
chat.notice(trf("ui.agent_chat_failed_start", &[("error", &e)]), true);
|
||||
chat.state = Some(State::Exited);
|
||||
chat.state = Some(State::Failed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The launch, once the window is up (the desktop host; not for runs driven over `--control`):
|
||||
/// Settings → AI can open the panel and connect the agent started last (#7009).
|
||||
pub fn begin(app: &mut SolveApp) {
|
||||
if !shown(app) {
|
||||
return;
|
||||
}
|
||||
if app.preferences.agent_chat_open_at_start {
|
||||
app.agent_chat.open = true;
|
||||
}
|
||||
app.agent_chat.connect_at_start = app.preferences.agent_connect_at_start;
|
||||
}
|
||||
|
||||
/// Connect at start, once the installed agents are known (the one started last may be one of
|
||||
/// them). A missing agent is not swapped for another: the chat says so and shows Connection
|
||||
/// failed, whose Retry starts the agent the switcher shows. Nothing waits on it: discovery and
|
||||
/// the agent run in the background, and an agent connected by hand meanwhile stays.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn connect_at_start(app: &mut SolveApp, ctx: &egui::Context) {
|
||||
if !app.agent_chat.connect_at_start {
|
||||
return;
|
||||
}
|
||||
if app.agent_chat.detection.is_none() {
|
||||
refresh(app, ctx);
|
||||
return;
|
||||
}
|
||||
app.agent_chat.connect_at_start = false;
|
||||
if app.agent_chat.state.is_some() || !app.preferences.agent_connect_at_start {
|
||||
return;
|
||||
}
|
||||
let last = app.preferences.agent_last.clone();
|
||||
if !last.is_empty() {
|
||||
if !agents::entries(app).iter().any(|e| e.id == last) {
|
||||
app.agent_chat.notice(trf("ui.agent_chat_last_missing", &[("agent", &last)]), true);
|
||||
app.agent_chat.state = Some(State::Failed);
|
||||
return;
|
||||
}
|
||||
app.agent_chat.agent_id = Some(last);
|
||||
}
|
||||
connect(app, ctx);
|
||||
}
|
||||
|
||||
/// Stop the agent (and everything it started); the conversation stays.
|
||||
pub fn disconnect(app: &mut SolveApp) {
|
||||
app.agent_chat.disconnect_document(&mut app.session, false);
|
||||
@@ -1669,6 +1726,8 @@ pub fn poll(app: &mut SolveApp, ctx: &egui::Context) {
|
||||
}
|
||||
// AI features turned off: nothing keeps running, nothing is looked for.
|
||||
if !shown(app) {
|
||||
// Turned back on later, AI features don't connect as if SolidCraft were starting.
|
||||
app.agent_chat.connect_at_start = false;
|
||||
crate::documents::disconnect_background_chats(app, false);
|
||||
if app.agent_chat.backend.is_some() || app.agent_chat.open {
|
||||
disconnect(app);
|
||||
@@ -1701,7 +1760,10 @@ pub fn poll(app: &mut SolveApp, ctx: &egui::Context) {
|
||||
}
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
settings::poll_capabilities(app, ctx);
|
||||
{
|
||||
settings::poll_capabilities(app, ctx);
|
||||
connect_at_start(app, ctx);
|
||||
}
|
||||
pump_tools(app);
|
||||
if !app.agent_chat.held.is_empty() || app.agent_chat.state() == State::Busy {
|
||||
ctx.request_repaint_after(std::time::Duration::from_millis(250));
|
||||
@@ -1842,7 +1904,8 @@ pub fn set_mode(app: &mut SolveApp, mode: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
/// `ui.agent_chat` on the control channel (tests and screenshots): `enabled`, `command`, `open`,
|
||||
/// `ui.agent_chat` on the control channel (tests and screenshots): `enabled`, `command`,
|
||||
/// `connect_at_start` and `open_at_start` (the launch preferences), `open`,
|
||||
/// `side`, `minimized`, `width`, `refresh`, `connect`, `stop`, `attach` (a file's path, for the
|
||||
/// next message), `remove_file` (index), `send`, `attach_view`, `attach_selection`, `pick`,
|
||||
/// `permission` (an option id, or `"cancel"`), `approve` (`true`/`false`, the oldest held
|
||||
@@ -1854,6 +1917,12 @@ pub fn control(app: &mut SolveApp, ctx: &egui::Context, p: &Value) -> Result<Val
|
||||
if let Some(b) = p.get("toolbar_button").and_then(Value::as_bool) {
|
||||
app.preferences.ai_toolbar_button = b;
|
||||
}
|
||||
if let Some(b) = p.get("connect_at_start").and_then(Value::as_bool) {
|
||||
app.preferences.agent_connect_at_start = b;
|
||||
}
|
||||
if let Some(b) = p.get("open_at_start").and_then(Value::as_bool) {
|
||||
app.preferences.agent_chat_open_at_start = b;
|
||||
}
|
||||
if let Some(m) = p.get("permissions") {
|
||||
let Some(mode) = m.as_str().and_then(agents::Mode::parse) else { return Err("permissions must be ask, edits or all".into()) };
|
||||
app.preferences.ai_permissions = mode;
|
||||
@@ -2045,6 +2114,9 @@ pub fn status(app: &SolveApp) -> Value {
|
||||
json!({
|
||||
"features": app.preferences.ai_features,
|
||||
"toolbarButton": app.preferences.ai_toolbar_button,
|
||||
"connectAtStart": app.preferences.agent_connect_at_start,
|
||||
"openAtStart": app.preferences.agent_chat_open_at_start,
|
||||
"lastAgent": app.preferences.agent_last,
|
||||
"permissions": app.preferences.ai_permissions.id(),
|
||||
"agents": agents::entries(app).iter().map(|e| json!({"id": e.id, "name": e.name, "kind": e.kind.id(), "found": e.found, "version": e.version, "login": e.login, "request_timeout_s": e.kind.is_api().then_some(e.request_timeout_s)})).collect::<Vec<_>>(),
|
||||
"currentAgent": agents::current(app).map(|e| e.id),
|
||||
|
||||
@@ -634,7 +634,7 @@ fn state_color(state: State) -> Color32 {
|
||||
let t = Tokens::get();
|
||||
match state {
|
||||
State::Ready | State::Busy => t.accent,
|
||||
State::NeedsAuth | State::Exited => t.warning,
|
||||
State::NeedsAuth | State::Exited | State::Failed => t.warning,
|
||||
_ => t.text_dim,
|
||||
}
|
||||
}
|
||||
@@ -703,7 +703,7 @@ fn header(app: &mut SolveApp, ui: &mut egui::Ui, left: bool) {
|
||||
State::Ready => ui_kit::AssistantTone::Success,
|
||||
State::Busy => ui_kit::AssistantTone::Working,
|
||||
State::NeedsAuth => ui_kit::AssistantTone::Warning,
|
||||
State::Exited => ui_kit::AssistantTone::Error,
|
||||
State::Exited | State::Failed => ui_kit::AssistantTone::Error,
|
||||
_ => ui_kit::AssistantTone::Neutral,
|
||||
}
|
||||
},
|
||||
@@ -1170,7 +1170,8 @@ fn switcher(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
let b = if app.agent_chat.state().running() {
|
||||
ui_kit::button(ui, tr("ui.agent_chat_stop"), ui_kit::Button::Normal).on_hover_text(tr("ui.agent_chat_stop_tip"))
|
||||
} else {
|
||||
ui_kit::button(ui, tr("ui.agent_chat_connect"), ui_kit::Button::Normal)
|
||||
let label = if app.agent_chat.state() == State::Failed { "ui.agent_chat_retry" } else { "ui.agent_chat_connect" };
|
||||
ui_kit::button(ui, tr(label), ui_kit::Button::Normal)
|
||||
};
|
||||
crate::scenario::publish_handle("agent_chat:connect", b.rect.center());
|
||||
if b.clicked() {
|
||||
@@ -1190,7 +1191,7 @@ fn switcher(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
const FLATPAK_OVERRIDE: &str = "flatpak override --user ai.storyteller.solidcraft --filesystem=~/.nvm:ro --filesystem=~/.local/bin:ro --filesystem=~/.local/share/claude:ro --filesystem=~/.claude --filesystem=~/.claude.json --share=network";
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn no_agents_message() -> String {
|
||||
pub(super) fn no_agents_message() -> String {
|
||||
if std::env::var_os("FLATPAK_ID").is_some() { tr("ui.agent_chat_flatpak_none_found") } else { tr("ui.agent_chat_none_found") }.to_string()
|
||||
}
|
||||
|
||||
|
||||
@@ -249,6 +249,12 @@ pub fn page(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
let response = ui_kit::checkbox(ui, tr("ui.ai_toolbar_button"), &mut app.preferences.ai_toolbar_button)
|
||||
.on_hover_text(tr("ui.ai_toolbar_button_note"));
|
||||
crate::scenario::publish_handle("prefs:ai_toolbar_button", response.rect.center());
|
||||
let response = ui_kit::checkbox(ui, tr("ai.prefs.connect_at_start"), &mut app.preferences.agent_connect_at_start)
|
||||
.on_hover_text(tr("ai.prefs.connect_at_start_note"));
|
||||
crate::scenario::publish_handle("prefs:agent_connect_at_start", response.rect.center());
|
||||
let response = ui_kit::checkbox(ui, tr("ai.prefs.open_at_start"), &mut app.preferences.agent_chat_open_at_start)
|
||||
.on_hover_text(tr("ai.prefs.open_at_start_note"));
|
||||
crate::scenario::publish_handle("prefs:agent_chat_open_at_start", response.rect.center());
|
||||
}
|
||||
let response = ui_kit::checkbox(ui, tr("ai.prefs.background_commands"), &mut app.preferences.agent_off_thread)
|
||||
.on_hover_text(tr("ui.agent_off_thread_note"));
|
||||
@@ -535,6 +541,10 @@ fn agents_section(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
if app.agent_chat.agent_id.as_deref() == Some(id.as_str()) {
|
||||
app.agent_chat.agent_id = None;
|
||||
}
|
||||
// A removed agent is not missed at the next start: the default connects instead.
|
||||
if app.preferences.agent_last == id {
|
||||
app.preferences.agent_last.clear();
|
||||
}
|
||||
}
|
||||
if app.agent_chat.settings.tests.values().any(|t| matches!(t, Test::Running(_))) {
|
||||
ui.ctx().request_repaint_after(std::time::Duration::from_millis(200));
|
||||
|
||||
@@ -1973,9 +1973,14 @@ fn assistant_marks_follow_chat_login_turns_and_approvals() {
|
||||
}
|
||||
assert_eq!(mark(State::Off, "signed_out", true), NeedsAuth);
|
||||
for login in ["", "signed_out", "unknown", "signed_in"] {
|
||||
for (state, expected) in
|
||||
[(State::Ready, Ready), (State::Busy, Busy), (State::Starting, Busy), (State::NeedsAuth, NeedsAuth), (State::Exited, Stopped)]
|
||||
{
|
||||
for (state, expected) in [
|
||||
(State::Ready, Ready),
|
||||
(State::Busy, Busy),
|
||||
(State::Starting, Busy),
|
||||
(State::NeedsAuth, NeedsAuth),
|
||||
(State::Exited, Stopped),
|
||||
(State::Failed, Stopped),
|
||||
] {
|
||||
assert_eq!(mark(state, login, true), expected);
|
||||
assert_eq!(assistant_mark_for(state, login, true, 12, false, false), Waiting(12));
|
||||
}
|
||||
@@ -1984,6 +1989,105 @@ fn assistant_marks_follow_chat_login_turns_and_approvals() {
|
||||
assert_eq!(assistant_mark_for(State::Ready, "signed_in", true, 0, false, true), Stopped);
|
||||
}
|
||||
|
||||
/// An app whose endpoint agents answer at once (offline), with `api-1` and `api-2` added.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn app_with_endpoints() -> SolveApp {
|
||||
let http: backend::HttpFn = Arc::new(|_| Err("offline".into()));
|
||||
let mut app = SolveApp::new(solidcraft_engine::Session::default(), crate::Services { agent_http: Some(http), ..Default::default() });
|
||||
for id in ["api-1", "api-2"] {
|
||||
app.preferences.agents.push(agents::AgentConfig {
|
||||
id: id.into(),
|
||||
kind: agents::Kind::Api,
|
||||
base_url: "http://localhost:11434/v1".into(),
|
||||
model: "m".into(),
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
app
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn the_agent_started_last_connects_at_start_once_the_agents_are_known() {
|
||||
let ctx = crate::fonts::test_context();
|
||||
let mut app = app_with_endpoints();
|
||||
// Off by default: a launch starts nothing and leaves the panel closed.
|
||||
begin(&mut app);
|
||||
poll(&mut app, &ctx);
|
||||
assert!(!app.agent_chat.open && app.agent_chat.backend.is_none() && app.agent_chat.detecting.is_none());
|
||||
|
||||
app.preferences.agent_connect_at_start = true;
|
||||
app.preferences.agent_chat_open_at_start = true;
|
||||
app.preferences.agent_last = "api-2".into();
|
||||
begin(&mut app);
|
||||
assert!(app.agent_chat.open);
|
||||
// Nothing waits for discovery: the agent starts when it is in, in whichever tab is shown.
|
||||
let (found, detecting) = channel();
|
||||
app.agent_chat.detecting = Some(detecting);
|
||||
poll(&mut app, &ctx);
|
||||
assert!(app.agent_chat.backend.is_none());
|
||||
crate::documents::open_tab(&mut app, solidcraft_engine::Session::default()).unwrap();
|
||||
found.send(discover::Detection::default()).unwrap();
|
||||
poll(&mut app, &ctx);
|
||||
assert_eq!(app.agent_chat.agent_id.as_deref(), Some("api-2"), "the agent started last, not the default");
|
||||
assert_eq!(app.agent_chat.state(), State::Starting);
|
||||
assert!(app.agent_chat.backend.is_some());
|
||||
// A design opened over the launch's blank one keeps the agent: nothing was asked yet.
|
||||
crate::documents::adopt(&mut app, solidcraft_engine::Session::default());
|
||||
assert!(app.agent_chat.backend.is_some() && app.agent_chat.items.is_empty());
|
||||
assert_eq!(app.docs.count(), 2);
|
||||
// Once per launch.
|
||||
disconnect(&mut app);
|
||||
poll(&mut app, &ctx);
|
||||
assert!(app.agent_chat.backend.is_none());
|
||||
// Connecting another agent makes it the one started last.
|
||||
app.agent_chat.agent_id = Some("api-1".into());
|
||||
connect(&mut app, &ctx);
|
||||
assert_eq!(app.preferences.agent_last, "api-1");
|
||||
assert!(status(&app)["lastAgent"] == "api-1" && status(&app)["connectAtStart"] == true);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn a_connection_that_never_gets_ready_says_connection_failed_and_offers_retry() {
|
||||
let ctx = crate::fonts::test_context();
|
||||
// The agent started last is gone: the chat says so, and no other agent starts by itself.
|
||||
let mut app = app_with_endpoints();
|
||||
app.preferences.agent_connect_at_start = true;
|
||||
app.preferences.agent_last = "claude".into();
|
||||
app.agent_chat.detection = Some(discover::Detection::default());
|
||||
begin(&mut app);
|
||||
poll(&mut app, &ctx);
|
||||
assert_eq!(app.agent_chat.state(), State::Failed);
|
||||
assert!(app.agent_chat.backend.is_none() && app.agent_chat.agent_id.is_none());
|
||||
assert!(matches!(app.agent_chat.items.last(), Some(Item::Notice { text, error: true }) if text.contains("claude")));
|
||||
assert!(!State::Failed.running(), "the Connect button reads Retry, not Stop");
|
||||
assert_eq!(status(&app)["state"], "failed");
|
||||
|
||||
// An agent that cannot start.
|
||||
let mut app = SolveApp::new(solidcraft_engine::Session::default(), crate::Services::default());
|
||||
app.preferences.agents.push(agents::AgentConfig { id: "custom-1".into(), command: "solidcraft-no-such-agent-7009".into(), ..Default::default() });
|
||||
connect(&mut app, &ctx);
|
||||
assert_eq!(app.agent_chat.state(), State::Failed);
|
||||
assert!(app.preferences.agent_last.is_empty(), "only an agent that started is remembered");
|
||||
|
||||
// No agent at all: the picker opens on what to install.
|
||||
let mut app = SolveApp::new(solidcraft_engine::Session::default(), crate::Services::default());
|
||||
app.agent_chat.detection = Some(discover::Detection::default());
|
||||
connect(&mut app, &ctx);
|
||||
assert_eq!((app.agent_chat.state(), app.agent_chat.picking), (State::Failed, Some(true)));
|
||||
|
||||
// An agent that ends while starting failed to connect; one that ends later stopped.
|
||||
let mut c = chat();
|
||||
c.state = Some(State::Starting);
|
||||
c.on_event(Event::Error("initialize failed".into()));
|
||||
c.on_event(Event::Exited { tail: Vec::new() });
|
||||
assert_eq!(c.state(), State::Failed);
|
||||
let mut c = chat();
|
||||
c.on_event(Event::Exited { tail: Vec::new() });
|
||||
assert_eq!(c.state(), State::Exited);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn assistant_click_and_shortcut_toggle_the_same_panel_without_a_connection() {
|
||||
let mut h = crate::scenario::Harness::new();
|
||||
|
||||
@@ -403,6 +403,13 @@ pub fn close(app: &mut SolveApp, i: usize, force: bool) {
|
||||
|
||||
/// A replacement design starts a fresh conversation while retaining the window's chat services.
|
||||
pub(crate) fn reset_chat(app: &mut SolveApp) {
|
||||
// A chat not asked anything yet (an agent connected at start, say) holds nothing of the old
|
||||
// design: it starts over in place, and its agent stays connected.
|
||||
if !app.agent_chat.items.iter().any(|i| matches!(i, crate::agent_chat::Item::User { .. })) {
|
||||
crate::agent_chat::new_chat(app);
|
||||
app.agent_chat.input.clear();
|
||||
return;
|
||||
}
|
||||
crate::agent_chat::leave_document(app);
|
||||
app.agent_chat.swap_document(&mut crate::agent_chat::AgentChat::default());
|
||||
}
|
||||
|
||||
@@ -754,6 +754,13 @@ preference_settings! {
|
||||
agents: Vec<crate::agent_chat::agents::AgentConfig> = Vec::new();
|
||||
/// The agent a new conversation starts with (an agent's id; empty: the first one available).
|
||||
agent_default: String = String::new();
|
||||
/// The agent the chat last started (an agent's id; empty: none yet).
|
||||
agent_last: String = String::new();
|
||||
/// When SolidCraft starts: connect the agent started last (`agent_last`, else the one a new
|
||||
/// conversation starts with), and open the panel (#7009). Off by default: an agent starts
|
||||
/// only when a message is sent or Connect is pressed, and the panel opens when asked for.
|
||||
agent_connect_at_start: bool = false, PAGE_AI;
|
||||
agent_chat_open_at_start: bool = false, PAGE_AI;
|
||||
/// How much the agent may do without asking (`ask`, `edits`, `all`), and per agent.
|
||||
ai_permissions: crate::agent_chat::agents::Mode = crate::agent_chat::agents::Mode::Edits, PAGE_AI;
|
||||
agent_permissions: std::collections::BTreeMap<String, crate::agent_chat::agents::Mode> = Default::default(), PAGE_AI;
|
||||
|
||||
+12
-1
@@ -20,6 +20,17 @@ Everything about it is on one page: **Preferences → AI**.
|
||||
- **Show Assistant button in application bar** (on by default): the **Assistant** icon in the application bar
|
||||
row, which stays there however wide the window is. Turn it off to keep only the shortcut and
|
||||
the menu entry.
|
||||
- **Connect the last-used agent when SolidCraft starts** (off by default): each launch starts
|
||||
the agent you connected last (the default one if you never connected), in the background,
|
||||
once SolidCraft has looked for the installed agents. The panel's header shows **Starting…**,
|
||||
then **Ready**, or **Connection failed** with **Retry** in place of **Connect** (the agent is
|
||||
missing, could not start, or ended while starting); the conversation says why. A design
|
||||
opened in place of the empty one SolidCraft starts with keeps the agent connected, as long
|
||||
as nothing was asked in that empty design's chat.
|
||||
- **Open the Assistant panel when SolidCraft starts** (off by default): the panel (or its own
|
||||
window) is shown at each launch.
|
||||
|
||||
Neither applies when SolidCraft is started with `--control` for automation.
|
||||
|
||||
With AI features on, the panel opens from:
|
||||
|
||||
@@ -29,7 +40,7 @@ With AI features on, the panel opens from:
|
||||
|
||||
Nothing runs until you need it: SolidCraft looks for installed agents (a quick `--version`
|
||||
each, in the background) when the panel or the AI page first opens, and starts an agent only
|
||||
when you send a message or press **Connect**.
|
||||
when you send a message or press **Connect** (or at launch, when you turned that on above).
|
||||
|
||||
## The panel
|
||||
|
||||
|
||||
@@ -311,7 +311,7 @@ labels; `prefs:measure_axis_distances` identifies the checkbox.
|
||||
| `engine.execute` → `browser.expand_all` | `path?`: occurrence ids; `component?`: id; omit both for the whole tree | Open every Browser row under that scope, including folders that start closed (Origin, Named Views, Features). Display only: not saved in the design, not an undo step. |
|
||||
| `engine.execute` → `browser.collapse_all` | same | Close those rows. The design row stays open when the whole tree is collapsed. |
|
||||
| `engine.execute` → `view.history_layout` | `width?`, `dock?`: `bottom`, `left`, `under_browser`, `collapsed?` | Resize/dock the history without opening a dialog or changing the design. Contents respond to measured width; browser-stacked history shares its width and splits height equally. One folded header gives the expanded card the rest; two folded headers stay at the top. |
|
||||
| `ui.agent_chat` | `features?`, `toolbar_button?`, `permissions?` (`ask`, `edits`, `all`), `add_agent?` ({`name`, `kind`: `acp`, `api` or `anthropic` (`api` is OpenAI-compatible, `anthropic` Anthropic-compatible), `command` or `base_url` + `model` + `request_timeout_s?` (seconds one model request may take, 300 by default, rounded and clamped to 30 to 3600)}; no keys), `add_dialog?` (`installed`, `custom`, `api`, `anthropic`, or `false` to close), `default_agent?`, `agent?` (the conversation's agent, by id), `mode?` (the agent's own mode), `provider?` (which provider's models the model picker lists, when they come from several), `model?` (one of its models), `open?`, `side?` (`left`, `right`), `minimized?`, `popped?` (in its own window), `width?`, `picker?`, `refresh?`, `connect?`, `stop?`, `attach?`: a file's path (a picture, a text file or a CAD file, for the next message; CAD files are imported at once), `remove_file?` (index of a file on the next message), `send?`: text (files alone make a message too), `attach_view?`, `attach_selection?`, `pick?` (true: open the context picker), `permission?`: an option id or `"cancel"` (the newest question of the agent's own), `approve?`: true, false or `"always"` (the oldest request held for Allow/Deny), `cancel?` (Stop: the queue stays), `send_now?` (stop the running step, then send the queued messages), `remove_pending?` (index), `new_chat?` (clear the chat, new session), `undo?` (the last message's changes) | the chat's state: `features`, `agents` (found and added), `currentAgent`, `state` (off, starting, ready, busy, auth, exited), `popped`, `window` (its place and size), `agent`, `modes`, `mode`, `models`, `model`, `modelWarning` (the model capability warning text, or `null` when unknown or tool support is reported; checked asynchronously and never blocks sending), `turnWarning` (the latest completed turn's no-tool notice, otherwise `null`; cleared on the next turn or new chat), `providers` (`name` and `count` of each, empty with one provider), `provider` (the one listed), `authMethods`, `toolsPort`, `pid`, `waiting`, `turn`, `pending` (queued messages, with their `files`), `attachments` (the files on the next message, by name), `loading` (pictures still being read for it, by name), `stopped`, `detection` and the conversation (`items`). With `features` off only the settings apply. Desktop only; see [Agent chat](agent-chat.md) |
|
||||
| `ui.agent_chat` | `features?`, `toolbar_button?`, `connect_at_start?` and `open_at_start?` (connect the agent started last, and open the panel, when SolidCraft starts; both off by default, never with `--control`), `permissions?` (`ask`, `edits`, `all`), `add_agent?` ({`name`, `kind`: `acp`, `api` or `anthropic` (`api` is OpenAI-compatible, `anthropic` Anthropic-compatible), `command` or `base_url` + `model` + `request_timeout_s?` (seconds one model request may take, 300 by default, rounded and clamped to 30 to 3600)}; no keys), `add_dialog?` (`installed`, `custom`, `api`, `anthropic`, or `false` to close), `default_agent?`, `agent?` (the conversation's agent, by id), `mode?` (the agent's own mode), `provider?` (which provider's models the model picker lists, when they come from several), `model?` (one of its models), `open?`, `side?` (`left`, `right`), `minimized?`, `popped?` (in its own window), `width?`, `picker?`, `refresh?`, `connect?`, `stop?`, `attach?`: a file's path (a picture, a text file or a CAD file, for the next message; CAD files are imported at once), `remove_file?` (index of a file on the next message), `send?`: text (files alone make a message too), `attach_view?`, `attach_selection?`, `pick?` (true: open the context picker), `permission?`: an option id or `"cancel"` (the newest question of the agent's own), `approve?`: true, false or `"always"` (the oldest request held for Allow/Deny), `cancel?` (Stop: the queue stays), `send_now?` (stop the running step, then send the queued messages), `remove_pending?` (index), `new_chat?` (clear the chat, new session), `undo?` (the last message's changes) | the chat's state: `features`, `agents` (found and added), `currentAgent`, `state` (off, starting, ready, busy, auth, exited, failed: the agent never got ready, and Connect reads Retry), `connectAtStart`, `openAtStart`, `lastAgent` (the agent started last), `popped`, `window` (its place and size), `agent`, `modes`, `mode`, `models`, `model`, `modelWarning` (the model capability warning text, or `null` when unknown or tool support is reported; checked asynchronously and never blocks sending), `turnWarning` (the latest completed turn's no-tool notice, otherwise `null`; cleared on the next turn or new chat), `providers` (`name` and `count` of each, empty with one provider), `provider` (the one listed), `authMethods`, `toolsPort`, `pid`, `waiting`, `turn`, `pending` (queued messages, with their `files`), `attachments` (the files on the next message, by name), `loading` (pictures still being read for it, by name), `stopped`, `detection` and the conversation (`items`). With `features` off only the settings apply. Desktop only; see [Agent chat](agent-chat.md) |
|
||||
| `ui.resize` | `width`, `height` | |
|
||||
| `app.quit` | `force?` (quit without asking about unsaved designs) | `quitting` (the window closes), `asking` (a "save changes?" prompt is open) |
|
||||
|
||||
|
||||
Reference in New Issue
Block a user