Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

Merge remote-tracking branch 'origin/dev' into feature/8661-improve-login-ux

thinhlpgeca583c74395
diff --cc src-tauri/src/core/agent/loop.rs
index 8c4b4a375,ede8ac7d9..558e25061
--- a/src-tauri/src/core/agent/loop.rs
+++ b/src-tauri/src/core/agent/loop.rs
@@@ -18,12 -18,11 +18,13 @@@ use crate::core::agent::events::{Stream
use crate::core::agent::session::SessionBudget;
use tauri_plugin_agent_tools::tools::gate::{DenyReason, PermissionDecision};
use crate::core::agent::upstream::{
- collect_mcp_openai_tools, copy_optional_chat_params, execute_mcp_tool_calls,
- extract_choice_message, extract_tool_calls, load_assistant_config, parse_openai_messages,
- repair_dangling_tool_calls, resolve_api_type_for_model, resolve_upstream_for_model,
+ collect_mcp_openai_tools, copy_optional_chat_params, drop_malformed_tool_calls,
+ execute_mcp_tool_calls, extract_choice_message, extract_tool_calls, load_assistant_config,
- parse_openai_messages, repair_dangling_tool_calls, resolve_upstream_for_model,
++ parse_openai_messages, repair_dangling_tool_calls, resolve_api_type_for_model,
++ resolve_upstream_for_model,
set_system_prompt, stream_openai_chat_completions,
};
+use crate::core::server::converters::{converter_for, UpstreamConverter};
#[cfg(not(feature = "cli"))]
use crate::core::server::proxy::router_first_model;
#[cfg(not(feature = "cli"))]
diff --cc src-tauri/src/core/cli/tui.rs
index ff729f018,b23bdc7dc..91e95916e
--- a/src-tauri/src/core/cli/tui.rs
+++ b/src-tauri/src/core/cli/tui.rs
@@@ -7749,32 -7345,11 +7897,34 @@@ async fn handle_key
picker.selected.min(picker.items.len().saturating_sub(1));
}
}
- Err(e) => app.note(&format!("failed to write {}: {e}", toml_path.display())),
+ Err(e) => {
+ app.note(&format!("failed to write {}: {e}", setting_path(def, &toml_path)))
+ }
}
}
+ // `/login`: `x` signs out the selected provider without leaving
+ // the picker, so it doubles as a sign-out list. Only meaningful
+ // for a provider that is currently signed in.
+ KeyCode::Char('x') if picker.kind == PickerKind::LoginProvider => {
+ let name = picker.items[picker.selected].value.clone();
+ if !crate::core::cli::providers::provider_is_signed_in(
+ Some(&app.project_root),
+ &name,
+ ) {
+ app.note(&format!("{name} is not signed in"));
+ return;
+ }
+ sign_out_provider(app, &name);
+ // Refresh the status labels so the row flips to
+ // "not signed in" without reopening the picker.
+ if let Some(p) = app.picker.as_mut() {
+ for item in &mut p.items {
+ if item.value == name {
+ item.hint = Some("not signed in".to_string());
+ }
+ }
+ }
+ }
// Collection picker: Space toggles the selected plugin, Enter hands
// the checked set to the loop (see `plugin_select_request`). Rows
// already installed stay displayed but are not toggleable -- checking
@@@ -8900,28 -8458,22 +9069,31 @@@ const AGENT_SETTINGS: &[AgentSettingDef
key: "context_window",
label: "context_window",
desc: "context limit in tokens",
- kind: AgentSettingKind::Int { default: Some(128000), min: 1 },
+ kind: AgentSettingKind::Int {
+ default: Some(128000),
+ min: 1,
+ },
+ scope: SettingScope::Project,
},
AgentSettingDef {
key: "compaction_reserve_tokens",
label: "compaction_reserve_tokens",
desc: "headroom kept free before compaction",
- kind: AgentSettingKind::Int { default: Some(16384), min: 0 },
+ kind: AgentSettingKind::Int {
+ default: Some(16384),
+ min: 0,
+ },
+ scope: SettingScope::Project,
},
AgentSettingDef {
key: "max_tokens",
label: "max_tokens",
desc: "cap on tokens generated per response (omitted when unset)",
- kind: AgentSettingKind::Int { default: None, min: 1 },
+ kind: AgentSettingKind::Int {
+ default: None,
+ min: 1,
+ },
+ scope: SettingScope::Project,
},
AgentSettingDef {
key: "max_parallel_subagents",
@@@ -8944,10 -8498,8 +9118,11 @@@
key: "budget.max_tokens",
label: "budget.max_tokens",
desc: "token-spend ceiling per run; the only cap on run length",
- kind: AgentSettingKind::Int { default: Some(128000), min: 0 },
+ kind: AgentSettingKind::Int {
+ default: Some(128000),
+ min: 0,
+ },
+ scope: SettingScope::Project,
},
AgentSettingDef {
key: "tools.default",
@@@ -9571,12 -9171,18 +9827,20 @@@ fn open_provider_settings(app: &mut App
});
}
+ /// Truncate to the first `n` grapheme clusters. Slicing by byte or `char`
+ /// would split an emoji mid-sequence and leave a different glyph on screen.
+ fn grapheme_prefix(s: &str, n: usize) -> String {
+ use unicode_segmentation::UnicodeSegmentation;
+ s.graphemes(true).take(n).collect()
+ }
+
/// Keyboard for the `/settings` edit dock: chars/backspace edit the field,
- /// Enter validates and writes (empty clears the key), Esc cancels. Mirrors
+ /// Enter validates and writes (an empty field clears the key, except for a
+ /// `Glyph`, where it writes the off value), Esc cancels. Mirrors
/// `handle_login_key`, minus the secret/verify machinery.
-fn handle_settings_key(app: &mut App, key: KeyEvent, ctrl: bool) { if (key.code == KeyCode::Esc || (ctrl && key.code == KeyCode::Char('c'))) && app.settings_prompt.is_some()
+fn handle_settings_key(app: &mut App, key: KeyEvent, ctrl: bool) {
+ if (key.code == KeyCode::Esc || (ctrl && key.code == KeyCode::Char('c')))
+ && app.settings_prompt.is_some()
{
app.settings_prompt = None;
return;
@@@ -19372,94 -17892,6 +19868,94 @@@ mod tests
assert!(app.provider_prompt.is_none(), "Enter on the watermark opens no wizard");
});
}
+ /// `x` on the provider-settings picker signs out (clears the credential)
+ /// but keeps the provider entry and its config, distinct from `d` delete.
+ #[test]
+ fn provider_settings_x_logout_clears_credential_and_keeps_config() {
+ // Seeds the process-global secret store, so it has to hold the same
+ // lock (and get its own data folder) as every other credential test.
+ with_isolated_login_state(|| {
+ use crate::core::cli::auth::{Credential, CredentialStore};
+ crate::core::agent::global_config::set_provider(
+ "myprovider",
+ crate::core::agent::global_config::ProviderUpdate {
+ api_key: Some("k".into()),
+ base_url: Some("https://my.example/v1".into()),
+ clear_api_key: false,
+ models: Some(vec!["m1".into()]),
+ api_type: None,
+ },
+ )
+ .unwrap();
+ CredentialStore::store("myprovider", &Credential::ApiKey("k".into()))
+ .expect("seed a stored credential");
+
+ let mut app = test_app();
+ super::open_provider_settings(&mut app);
+ let rt = tokio::runtime::Runtime::new().unwrap();
+ rt.block_on(async {
+ press(&mut app, KeyCode::Char('x'), KeyModifiers::NONE).await;
+ });
+
+ // The provider entry (and its models) survive; the credential is gone.
+ let configs = crate::core::agent::global_config::load_global_config().unwrap();
+ assert!(configs.contains_key("myprovider"), "config kept after logout");
+ assert_eq!(configs.get("myprovider").unwrap().models, vec!["m1"]);
+ assert!(
+ CredentialStore::load("myprovider").unwrap().is_none(),
+ "credential cleared on logout"
+ );
+ assert!(transcript_text(&app).contains("signed out of myprovider"));
+ assert!(app.picker.is_some(), "logout keeps the picker open");
+ });
+ }
+
+ /// `x` on the `/login` picker signs out a signed-in provider and flips its
+ /// row hint to "not signed in" without closing the picker.
+ #[test]
+ fn login_picker_x_signs_out_signed_in_provider() {
- crate::core::agent::global_config::with_temp_home(|_| {
++ with_isolated_login_state(|| {
+ use crate::core::cli::auth::{Credential, CredentialStore};
+ // A catalog provider (tokamak) that we can sign out of.
+ CredentialStore::store("tokamak", &Credential::ApiKey("k".into()))
+ .expect("seed a stored credential");
+ crate::core::agent::global_config::set_provider(
+ "tokamak",
+ crate::core::agent::global_config::ProviderUpdate {
+ api_key: Some("k".into()),
+ base_url: Some("https://api.tokamak.sh/v1".into()),
+ clear_api_key: false,
+ models: Some(vec!["tokamak-1-preview".into()]),
+ api_type: None,
+ },
+ )
+ .unwrap();
+
+ let mut app = test_app();
+ super::open_login_picker(&mut app);
+ // Tokamak is pinned to the top of the login picker.
+ let rt = tokio::runtime::Runtime::new().unwrap();
+ rt.block_on(async {
+ press(&mut app, KeyCode::Char('x'), KeyModifiers::NONE).await;
+ });
+
+ assert!(
+ crate::core::cli::auth::CredentialStore::load("tokamak")
+ .unwrap()
+ .is_none(),
+ "x on the login picker signs out"
+ );
+ assert!(app.picker.is_some(), "login picker stays open after sign-out");
+ let picker = app.picker.as_ref().unwrap();
+ assert_eq!(picker.items[0].value, "tokamak");
+ assert_eq!(
+ picker.items[0].hint.as_deref(),
+ Some("not signed in"),
+ "row hint flips to not signed in"
+ );
+ assert!(transcript_text(&app).contains("signed out of tokamak"));
+ });
+ }
/// Editing a provider must keep its name read-only so the save writes back
/// under the original key: renaming would orphan the old entry and lose the