Show effective settings in bds-cli config.

This commit is contained in:
2026-07-20 09:28:26 +02:00
parent 269e4b0e4a
commit 3739da0984
8 changed files with 198 additions and 51 deletions

View File

@@ -197,30 +197,36 @@ pub fn save_endpoint(conn: &Connection, endpoint: &AiEndpointConfig) -> EngineRe
checked_at,
)?;
if endpoint.kind == AiEndpointKind::Online {
let entry = endpoint_keyring_entry(endpoint.kind)?;
if let Some(api_key) = &endpoint.api_key {
if api_key.trim().is_empty() {
entry.delete_credential().ok();
set_setting(
conn,
&endpoint_setting_key(endpoint.kind, "api_key_configured"),
"false",
checked_at,
)?;
} else {
entry.set_password(api_key.trim()).map_err(keyring_error)?;
set_setting(
conn,
&endpoint_setting_key(endpoint.kind, "api_key_configured"),
"true",
checked_at,
)?;
}
save_online_api_key_at(conn, api_key, checked_at)?;
}
}
Ok(())
}
pub fn save_online_api_key(conn: &Connection, api_key: &str) -> EngineResult<()> {
save_online_api_key_at(conn, api_key, now_unix_ms())
}
fn save_online_api_key_at(conn: &Connection, api_key: &str, updated_at: i64) -> EngineResult<()> {
let entry = endpoint_keyring_entry(AiEndpointKind::Online)?;
let configured = !api_key.trim().is_empty();
if configured {
entry.set_password(api_key.trim()).map_err(keyring_error)?;
} else {
match entry.delete_credential() {
Ok(()) | Err(keyring::Error::NoEntry) => {}
Err(error) => return Err(keyring_error(error)),
}
}
set_setting(
conn,
&endpoint_setting_key(AiEndpointKind::Online, "api_key_configured"),
if configured { "true" } else { "false" },
updated_at,
)
}
pub fn save_model_preferences(
conn: &Connection,
default_model: Option<&str>,

View File

@@ -1,9 +1,32 @@
use std::collections::BTreeMap;
use crate::db::DbConnection as Connection;
use crate::db::queries::setting;
use crate::engine::{EngineError, EngineResult, domain_events};
use crate::util::now_unix_ms;
pub const UI_LANGUAGE_KEY: &str = "ui.language";
pub const ONLINE_API_KEY: &str = "ai.endpoint.online.api_key";
const ONLINE_API_KEY_CONFIGURED: &str = "ai.endpoint.online.api_key_configured";
const DEFAULTS: &[(&str, &str)] = &[
("editor.default_mode", "markdown"),
("editor.diff_view_style", "inline"),
("editor.wrap_long_lines", "true"),
("editor.hide_unchanged_regions", "false"),
("ai.endpoint.online.url", ""),
("ai.endpoint.online.model", ""),
(ONLINE_API_KEY, ""),
("ai.endpoint.airplane.url", ""),
("ai.endpoint.airplane.model", ""),
("ai.default_model", ""),
("ai.title_model", ""),
("ai.image_model", ""),
("ai.system_prompt", ""),
("mcp.http.enabled", "false"),
("data.automatic_rebuild", "true"),
("style.theme", "system"),
("style.content_width", "72"),
];
pub fn get(conn: &Connection, key: &str) -> EngineResult<Option<String>> {
match setting::get_setting_by_key(conn, key) {
@@ -13,6 +36,49 @@ pub fn get(conn: &Connection, key: &str) -> EngineResult<Option<String>> {
}
}
pub fn get_effective(conn: &Connection, key: &str) -> EngineResult<Option<String>> {
if key == ONLINE_API_KEY {
return Ok(Some(
get(conn, ONLINE_API_KEY_CONFIGURED)?
.filter(|value| value == "true")
.map_or_else(String::new, |_| "configured".to_string()),
));
}
if let Some(value) = get(conn, key)? {
return Ok(Some(value));
}
if key == UI_LANGUAGE_KEY {
return Ok(Some(crate::i18n::detect_os_locale().code().to_string()));
}
Ok(DEFAULTS
.iter()
.find(|(candidate, _)| *candidate == key)
.map(|(_, value)| (*value).to_string()))
}
pub fn list_effective(conn: &Connection) -> EngineResult<BTreeMap<String, String>> {
let mut values = DEFAULTS
.iter()
.map(|(key, value)| ((*key).to_string(), (*value).to_string()))
.collect::<BTreeMap<_, _>>();
values.insert(
UI_LANGUAGE_KEY.to_string(),
crate::i18n::detect_os_locale().code().to_string(),
);
for value in setting::list_all_settings(conn)? {
if !value.key.starts_with("app.")
&& value.key != ONLINE_API_KEY
&& value.key != ONLINE_API_KEY_CONFIGURED
{
values.insert(value.key, value.value);
}
}
if get(conn, ONLINE_API_KEY_CONFIGURED)?.as_deref() == Some("true") {
values.insert(ONLINE_API_KEY.to_string(), "configured".to_string());
}
Ok(values)
}
pub fn set(conn: &Connection, key: &str, value: &str) -> EngineResult<()> {
set_at(conn, key, value, now_unix_ms())
}