feat(gui): pick timezone/locale/keymap and AI model from lists
The region and keyboard fields were free-text, so users had to know zone names and layout names from memory, and the AI model had to be typed. Add an 'options' bridge op (live timezones/locales/keymaps) and an 'ai_catalog' op (the OpenCode provider/model catalog, or an OpenAI-compatible /models list), and a searchable PhoebusCombo picker. Also name provider/model in OpenCode errors instead of an opaque HTTP code. Record the user-trial findings U1-U5.
This commit is contained in:
parent
359f083bc2
commit
39c69d59cf
7 changed files with 612 additions and 36 deletions
|
|
@ -51,6 +51,22 @@ and passed in the graphical VM; the remaining stages are the long package
|
||||||
installation. Two fresh-disk graphical installs and a separate physical machine
|
installation. Two fresh-disk graphical installs and a separate physical machine
|
||||||
remain unverified.
|
remain unverified.
|
||||||
|
|
||||||
|
### User trial findings (interactive VM, 2026-09-22)
|
||||||
|
|
||||||
|
Observed while a user drove the live ISO by hand (run
|
||||||
|
`/var/tmp/phoebus-vm/user-session*`):
|
||||||
|
|
||||||
|
| ID | Finding | Status |
|
||||||
|
|----|---------|--------|
|
||||||
|
| U1 | Timezone (and locale, keyboard) were **free-text**: the user was expected to know `America/New_York` etc. Only ~5 keymap presets were offered, then manual entry. | **Fixed**: searchable pickers populated from the live system (418 timezones from `zone.tab`, 513 locales, 82 keymaps), type-to-filter and click-to-choose; a custom value is still accepted. |
|
||||||
|
| U2 | The AI **provider/model** fields were free-text; the user had to know the exact model id. | **Fixed**: `ai_catalog` bridge op returns the OpenCode catalog (223 providers, real model ids) or an OpenAI-compatible `/models` list; the GUI shows selectable Provider/Model combos with a "Load list" action. |
|
||||||
|
| U3 | An invalid model produced only `OpenCode message failed: HTTP 500` — opaque. | **Fixed in source**: the error now names `provider/model` and says to check the model exists and the credentials are valid. (Needs the next ISO.) |
|
||||||
|
| U4 | At first boot the DMS app-launcher/overview overlay was open on top of the welcome window, hiding the primary action until dismissed. | **Open**: reproduced once; investigating whether it is a DMS first-run behaviour or a focus race. |
|
||||||
|
| U5 | The OpenCode model default `deepseek-chat` is not present on every server, so the first attempt failed. | **Mitigated**: the picker now lists only real models. Considering defaulting the model to unset and requiring a pick. |
|
||||||
|
|
||||||
|
None of these blocked the installer; they are usability defects. U1–U3 are
|
||||||
|
implemented; U4–U5 are tracked.
|
||||||
|
|
||||||
OpenCode protocol/transport tests: 26 executor unit tests + 7 real-HTTP
|
OpenCode protocol/transport tests: 26 executor unit tests + 7 real-HTTP
|
||||||
integration tests + 2 live tests (skipped offline, real inference when
|
integration tests + 2 live tests (skipped offline, real inference when
|
||||||
configured). Bridge gate tests: 5. Full suite: 336 Rust tests.
|
configured). Bridge gate tests: 5. Full suite: 336 Rust tests.
|
||||||
|
|
|
||||||
|
|
@ -551,13 +551,21 @@ impl<'a> OpenCodeClient<'a> {
|
||||||
|
|
||||||
fn error_for(&self, action: &str, response: &HttpResponse) -> AiError {
|
fn error_for(&self, action: &str, response: &HttpResponse) -> AiError {
|
||||||
let hint = match response.status {
|
let hint = match response.status {
|
||||||
|
400 => "the server rejected the request (check the model id)".to_string(),
|
||||||
401 => "authentication required".to_string(),
|
401 => "authentication required".to_string(),
|
||||||
403 => "authentication rejected".to_string(),
|
403 => "authentication rejected".to_string(),
|
||||||
404 => "endpoint not found (incompatible server?)".to_string(),
|
404 => "endpoint not found (incompatible server?)".to_string(),
|
||||||
429 => "rate limited".to_string(),
|
429 => "rate limited".to_string(),
|
||||||
|
500..=599 => "the server returned an internal error (check that the model \
|
||||||
|
exists and the provider credentials are valid)"
|
||||||
|
.to_string(),
|
||||||
_ => format!("HTTP {}", response.status),
|
_ => format!("HTTP {}", response.status),
|
||||||
};
|
};
|
||||||
AiError::Provider(format!("OpenCode {action} failed: {hint}"))
|
// Name the provider:model so an invalid selection is obvious.
|
||||||
|
AiError::Provider(format!(
|
||||||
|
"OpenCode {action} failed for {}/{}: {hint}",
|
||||||
|
self.provider, self.model
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch the provider/model catalog. Uses the metadata endpoint only.
|
/// Fetch the provider/model catalog. Uses the metadata endpoint only.
|
||||||
|
|
@ -997,7 +1005,7 @@ mod tests {
|
||||||
(401u16, "authentication required"),
|
(401u16, "authentication required"),
|
||||||
(403, "authentication rejected"),
|
(403, "authentication rejected"),
|
||||||
(404, "not found"),
|
(404, "not found"),
|
||||||
(500, "HTTP 500"),
|
(500, "internal error"),
|
||||||
] {
|
] {
|
||||||
let http = FakeHttp::new(vec![FakeHttp::json(status, "{}")]);
|
let http = FakeHttp::new(vec![FakeHttp::json(status, "{}")]);
|
||||||
let client = OpenCodeClient::new(&http, "http://127.0.0.1:4096", "p", "m");
|
let client = OpenCodeClient::new(&http, "http://127.0.0.1:4096", "p", "m");
|
||||||
|
|
|
||||||
|
|
@ -258,6 +258,8 @@ impl Bridge {
|
||||||
let op = request.op.clone();
|
let op = request.op.clone();
|
||||||
let result = match request.op.as_str() {
|
let result = match request.op.as_str() {
|
||||||
"handshake" => self.handshake(),
|
"handshake" => self.handshake(),
|
||||||
|
"options" => self.options(),
|
||||||
|
"ai_catalog" => self.ai_catalog(),
|
||||||
"disks" => self.disks(),
|
"disks" => self.disks(),
|
||||||
"set_config" => self.set_config(&request),
|
"set_config" => self.set_config(&request),
|
||||||
"set_secrets" => self.set_secrets(&request),
|
"set_secrets" => self.set_secrets(&request),
|
||||||
|
|
@ -312,6 +314,109 @@ impl Bridge {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Selectable options for the language/region step. Reading these from the
|
||||||
|
/// live system means the user picks from the real timezones, locales and
|
||||||
|
/// keymaps instead of typing them from memory.
|
||||||
|
fn options(&self) -> Result<Value, String> {
|
||||||
|
Ok(json!({
|
||||||
|
"timezones": system_timezones(),
|
||||||
|
"locales": system_locales(),
|
||||||
|
"keymaps": system_keymaps(),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The providers and models the configured AI connection actually offers:
|
||||||
|
/// the OpenCode catalog, or an OpenAI-compatible `/models` list. Read-only;
|
||||||
|
/// never returns provider credentials.
|
||||||
|
fn ai_catalog(&self) -> Result<Value, String> {
|
||||||
|
use phoebus_executor::opencode_client::{CurlHttpClient, HttpClient, OpenCodeClient};
|
||||||
|
use phoebus_executor::opencode_server::Endpoint;
|
||||||
|
|
||||||
|
let redact = self.installer.exec.redactor();
|
||||||
|
match self.installer.config.ai.backend {
|
||||||
|
AiBackend::OpenCode => {
|
||||||
|
// The catalog only needs the server; the model is optional.
|
||||||
|
let server = self.installer.config.ai.opencode_server.trim().to_string();
|
||||||
|
if server.is_empty() {
|
||||||
|
return Err("OpenCode requires a server URL".into());
|
||||||
|
}
|
||||||
|
let provider = self
|
||||||
|
.installer
|
||||||
|
.config
|
||||||
|
.ai
|
||||||
|
.opencode_provider
|
||||||
|
.trim()
|
||||||
|
.to_string();
|
||||||
|
let model = self.installer.config.ai.opencode_model.trim().to_string();
|
||||||
|
let endpoint = Endpoint::parse(&server)
|
||||||
|
.map_err(|e| format!("invalid OpenCode endpoint: {e}"))?;
|
||||||
|
let target = endpoint
|
||||||
|
.checked_target()
|
||||||
|
.map_err(|e| redact.redact(&e.to_string()))?;
|
||||||
|
let http = CurlHttpClient::new(&self.installer.exec);
|
||||||
|
// The provider catalog can be several MiB on a busy server.
|
||||||
|
let client = OpenCodeClient::new(&http, endpoint.base(), &provider, &model)
|
||||||
|
.with_auth(self.opencode_password.clone())
|
||||||
|
.with_max_body(16 * 1024 * 1024)
|
||||||
|
.with_resolve(Some((endpoint.host.clone(), endpoint.port, target.ip())));
|
||||||
|
match client.catalog() {
|
||||||
|
Ok(catalog) => {
|
||||||
|
let providers: Vec<Value> = catalog
|
||||||
|
.providers
|
||||||
|
.iter()
|
||||||
|
.map(
|
||||||
|
|p| json!({ "id": p.id, "name": p.name, "connected": p.connected }),
|
||||||
|
)
|
||||||
|
.collect();
|
||||||
|
let models = catalog
|
||||||
|
.providers
|
||||||
|
.iter()
|
||||||
|
.find(|p| p.id == provider)
|
||||||
|
.or_else(|| catalog.providers.iter().find(|p| !p.models.is_empty()))
|
||||||
|
.map(|p| p.models.clone())
|
||||||
|
.unwrap_or_default();
|
||||||
|
Ok(json!({
|
||||||
|
"backend": "opencode",
|
||||||
|
"providers": providers,
|
||||||
|
"models": models,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
Err(e) => Err(redact.redact(&e.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AiBackend::Direct => {
|
||||||
|
let raw = self.installer.config.ai.provider.clone();
|
||||||
|
let provider = ProviderKind::parse(&raw)
|
||||||
|
.ok_or_else(|| format!("unknown AI provider `{raw}`"))?;
|
||||||
|
if provider == ProviderKind::None {
|
||||||
|
return Err("no AI provider selected".into());
|
||||||
|
}
|
||||||
|
let endpoint = if self.installer.config.ai.endpoint.is_empty() {
|
||||||
|
provider.endpoint().to_string()
|
||||||
|
} else {
|
||||||
|
self.installer.config.ai.endpoint.clone()
|
||||||
|
};
|
||||||
|
let url = models_url(&endpoint);
|
||||||
|
let mut request = phoebus_executor::opencode_client::HttpRequest::get(url);
|
||||||
|
request.auth_user = String::new(); // OpenAI-compatible: Bearer
|
||||||
|
request.auth = self.api_key.clone();
|
||||||
|
let http = CurlHttpClient::new(&self.installer.exec);
|
||||||
|
match http.request(&request) {
|
||||||
|
Ok(response) if response.is_success() => {
|
||||||
|
let models = parse_model_ids(&response.body);
|
||||||
|
Ok(json!({
|
||||||
|
"backend": "direct",
|
||||||
|
"providers": [ { "id": provider.as_str(), "name": provider.as_str(), "connected": true } ],
|
||||||
|
"models": models,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
Ok(response) => Err(format!("model list returned HTTP {}", response.status)),
|
||||||
|
Err(e) => Err(redact.redact(&e.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn disks(&mut self) -> Result<Value, String> {
|
fn disks(&mut self) -> Result<Value, String> {
|
||||||
self.installer.disks =
|
self.installer.disks =
|
||||||
phoebus_executor::probe::probe_disks(self.installer.exec.runner.as_ref());
|
phoebus_executor::probe::probe_disks(self.installer.exec.runner.as_ref());
|
||||||
|
|
@ -881,6 +986,237 @@ fn opencode_parts(config: &InstallConfig) -> Result<(String, String, String), St
|
||||||
Ok((server, provider, model))
|
Ok((server, provider, model))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Time zones offered by the live system, from the zoneinfo database.
|
||||||
|
fn system_timezones() -> Vec<String> {
|
||||||
|
let mut zones: std::collections::BTreeSet<String> = std::collections::BTreeSet::new();
|
||||||
|
if let Ok(text) = std::fs::read_to_string("/usr/share/zoneinfo/zone.tab") {
|
||||||
|
for line in text.lines() {
|
||||||
|
let line = line.trim();
|
||||||
|
if line.is_empty() || line.starts_with('#') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if let Some(tz) = line.split_whitespace().nth(2) {
|
||||||
|
zones.insert(tz.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if zones.is_empty() {
|
||||||
|
for zone in [
|
||||||
|
"UTC",
|
||||||
|
"Europe/London",
|
||||||
|
"Europe/Berlin",
|
||||||
|
"Europe/Paris",
|
||||||
|
"America/New_York",
|
||||||
|
"America/Chicago",
|
||||||
|
"America/Denver",
|
||||||
|
"America/Los_Angeles",
|
||||||
|
"Asia/Tokyo",
|
||||||
|
"Asia/Shanghai",
|
||||||
|
"Asia/Kolkata",
|
||||||
|
"Australia/Sydney",
|
||||||
|
] {
|
||||||
|
zones.insert(zone.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
zones.into_iter().take(2000).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Locales from the system's i18n database (or a common fallback set).
|
||||||
|
fn system_locales() -> Vec<String> {
|
||||||
|
let mut locales: std::collections::BTreeSet<String> = std::collections::BTreeSet::new();
|
||||||
|
if let Ok(text) = std::fs::read_to_string("/usr/share/i18n/SUPPORTED") {
|
||||||
|
for line in text.lines() {
|
||||||
|
let line = line.trim();
|
||||||
|
if line.is_empty() || line.starts_with('#') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if let Some(locale) = line.split_whitespace().next() {
|
||||||
|
// Prefer UTF-8 variants; keep the rest too.
|
||||||
|
locales.insert(locale.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if locales.is_empty() {
|
||||||
|
for locale in [
|
||||||
|
"en_US.UTF-8",
|
||||||
|
"en_GB.UTF-8",
|
||||||
|
"de_DE.UTF-8",
|
||||||
|
"fr_FR.UTF-8",
|
||||||
|
"es_ES.UTF-8",
|
||||||
|
"it_IT.UTF-8",
|
||||||
|
"pt_BR.UTF-8",
|
||||||
|
"ja_JP.UTF-8",
|
||||||
|
"zh_CN.UTF-8",
|
||||||
|
] {
|
||||||
|
locales.insert(locale.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
locales.into_iter().take(2000).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Console keymaps from the system's keymap trees.
|
||||||
|
fn system_keymaps() -> Vec<String> {
|
||||||
|
let mut keymaps: std::collections::BTreeSet<String> = std::collections::BTreeSet::new();
|
||||||
|
for root in ["/usr/share/keymaps", "/usr/share/kbd/keymaps"] {
|
||||||
|
collect_keymaps(std::path::Path::new(root), &mut keymaps, 0);
|
||||||
|
}
|
||||||
|
if keymaps.is_empty() {
|
||||||
|
// The live medium does not always ship the kbd keymap tree, so fall
|
||||||
|
// back to the common console keymaps. The combo still accepts a
|
||||||
|
// custom value.
|
||||||
|
for name in [
|
||||||
|
"us",
|
||||||
|
"us-acentos",
|
||||||
|
"uk",
|
||||||
|
"gb",
|
||||||
|
"de",
|
||||||
|
"de-latin1",
|
||||||
|
"de-latin1-nodeadkeys",
|
||||||
|
"de-nodeadkeys",
|
||||||
|
"fr",
|
||||||
|
"fr-latin9",
|
||||||
|
"fr-latin1",
|
||||||
|
"fr-pc",
|
||||||
|
"es",
|
||||||
|
"es-cp850",
|
||||||
|
"it",
|
||||||
|
"it2",
|
||||||
|
"pt",
|
||||||
|
"pt-latin1",
|
||||||
|
"nl",
|
||||||
|
"nl2",
|
||||||
|
"be",
|
||||||
|
"dk",
|
||||||
|
"dk-latin1",
|
||||||
|
"no",
|
||||||
|
"no-latin1",
|
||||||
|
"se",
|
||||||
|
"fi",
|
||||||
|
"is",
|
||||||
|
"ie",
|
||||||
|
"ie-Gaelic",
|
||||||
|
"pl",
|
||||||
|
"pl2",
|
||||||
|
"cz",
|
||||||
|
"cz-us-qwertz",
|
||||||
|
"sk",
|
||||||
|
"hu",
|
||||||
|
"hu101",
|
||||||
|
"ro",
|
||||||
|
"bg",
|
||||||
|
"gr",
|
||||||
|
"gr-pc",
|
||||||
|
"ru",
|
||||||
|
"ruwin_alt-UTF-8",
|
||||||
|
"ua-utf",
|
||||||
|
"tr",
|
||||||
|
"trq",
|
||||||
|
"il",
|
||||||
|
"ara",
|
||||||
|
"in",
|
||||||
|
"jp106",
|
||||||
|
"kr",
|
||||||
|
"kr-utf",
|
||||||
|
"cn",
|
||||||
|
"tw",
|
||||||
|
"br-abnt2",
|
||||||
|
"latam",
|
||||||
|
"ca",
|
||||||
|
"cf",
|
||||||
|
"ch",
|
||||||
|
"ch-fr",
|
||||||
|
"at",
|
||||||
|
"si",
|
||||||
|
"hr",
|
||||||
|
"ee",
|
||||||
|
"lt",
|
||||||
|
"lv",
|
||||||
|
"mk",
|
||||||
|
"rs",
|
||||||
|
"by",
|
||||||
|
"kz",
|
||||||
|
"us-dvorak",
|
||||||
|
"dvorak",
|
||||||
|
"colemak",
|
||||||
|
"mac-us",
|
||||||
|
"sun-pl",
|
||||||
|
"sg",
|
||||||
|
"th",
|
||||||
|
"vn",
|
||||||
|
"fa",
|
||||||
|
"az",
|
||||||
|
"ge",
|
||||||
|
"am",
|
||||||
|
] {
|
||||||
|
keymaps.insert(name.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
keymaps.into_iter().take(2000).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn collect_keymaps(
|
||||||
|
dir: &std::path::Path,
|
||||||
|
out: &mut std::collections::BTreeSet<String>,
|
||||||
|
depth: usize,
|
||||||
|
) {
|
||||||
|
if depth > 6 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let Ok(entries) = std::fs::read_dir(dir) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
for entry in entries.flatten() {
|
||||||
|
let path = entry.path();
|
||||||
|
if path.is_dir() {
|
||||||
|
collect_keymaps(&path, out, depth + 1);
|
||||||
|
} else if let Some(name) = path.file_name().and_then(|n| n.to_str()) {
|
||||||
|
for suffix in [".map.gz", ".map"] {
|
||||||
|
if let Some(stem) = name.strip_suffix(suffix) {
|
||||||
|
out.insert(stem.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The OpenAI-compatible model-list URL for a chat-completions endpoint.
|
||||||
|
fn models_url(endpoint: &str) -> String {
|
||||||
|
let trimmed = endpoint.trim().trim_end_matches('/');
|
||||||
|
if let Some(base) = trimmed.strip_suffix("/chat/completions") {
|
||||||
|
format!("{base}/models")
|
||||||
|
} else {
|
||||||
|
format!("{trimmed}/models")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Extract model ids from an OpenAI-compatible `/models` response.
|
||||||
|
fn parse_model_ids(body: &str) -> Vec<String> {
|
||||||
|
let mut ids: std::collections::BTreeSet<String> = std::collections::BTreeSet::new();
|
||||||
|
if let Ok(value) = serde_json::from_str::<Value>(body) {
|
||||||
|
if let Some(data) = value.get("data").and_then(|d| d.as_array()) {
|
||||||
|
for item in data {
|
||||||
|
if let Some(id) = item.get("id").and_then(|v| v.as_str()) {
|
||||||
|
ids.insert(id.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ids.is_empty() {
|
||||||
|
if let Some(models) = value.get("models").and_then(|m| m.as_array()) {
|
||||||
|
for item in models {
|
||||||
|
if let Some(id) = item
|
||||||
|
.get("id")
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.or_else(|| item.get("name").and_then(|v| v.as_str()))
|
||||||
|
{
|
||||||
|
ids.insert(id.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ids.into_iter().collect()
|
||||||
|
}
|
||||||
|
|
||||||
fn opencode_transport<'a>(
|
fn opencode_transport<'a>(
|
||||||
exec: &'a Exec,
|
exec: &'a Exec,
|
||||||
config: &InstallConfig,
|
config: &InstallConfig,
|
||||||
|
|
@ -1616,6 +1952,42 @@ mod tests {
|
||||||
.contains("validated AI interaction"));
|
.contains("validated AI interaction"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn options_are_available_for_the_region_pickers() {
|
||||||
|
let mut bridge = test_bridge();
|
||||||
|
let lines = call(&mut bridge, r#"{"id":50,"op":"options"}"#);
|
||||||
|
let data = &response(&lines)["data"];
|
||||||
|
assert!(!data["timezones"].as_array().unwrap().is_empty());
|
||||||
|
assert!(!data["locales"].as_array().unwrap().is_empty());
|
||||||
|
assert!(!data["keymaps"].as_array().unwrap().is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn models_url_is_derived_from_the_chat_endpoint() {
|
||||||
|
assert_eq!(
|
||||||
|
models_url("https://api.deepseek.com/chat/completions"),
|
||||||
|
"https://api.deepseek.com/models"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
models_url("https://api.openai.com/v1/chat/completions"),
|
||||||
|
"https://api.openai.com/v1/models"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
models_url("http://127.0.0.1:11434/v1/chat/completions"),
|
||||||
|
"http://127.0.0.1:11434/v1/models"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_model_ids_reads_common_shapes() {
|
||||||
|
assert_eq!(
|
||||||
|
parse_model_ids(r#"{"data":[{"id":"b"},{"id":"a"},{"id":"a"}]}"#),
|
||||||
|
vec!["a", "b"]
|
||||||
|
);
|
||||||
|
assert_eq!(parse_model_ids(r#"{"models":[{"name":"m"}]}"#), vec!["m"]);
|
||||||
|
assert!(parse_model_ids("<html>").is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn ai_test_is_a_known_operation_and_fails_without_a_provider() {
|
fn ai_test_is_a_known_operation_and_fails_without_a_provider() {
|
||||||
let mut bridge = test_bridge();
|
let mut bridge = test_bridge();
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,12 @@ Singleton {
|
||||||
function listDisks(cb) {
|
function listDisks(cb) {
|
||||||
call("disks", {}, cb);
|
call("disks", {}, cb);
|
||||||
}
|
}
|
||||||
|
function options(cb) {
|
||||||
|
call("options", {}, cb);
|
||||||
|
}
|
||||||
|
function aiCatalog(cb) {
|
||||||
|
call("ai_catalog", {}, cb);
|
||||||
|
}
|
||||||
function setConfig(cfg, cb) {
|
function setConfig(cfg, cb) {
|
||||||
call("set_config", { config: cfg }, reply => {
|
call("set_config", { config: cfg }, reply => {
|
||||||
if (reply.ok)
|
if (reply.ok)
|
||||||
|
|
|
||||||
108
installer/live/desktop/common/PhoebusCombo.qml
Normal file
108
installer/live/desktop/common/PhoebusCombo.qml
Normal file
|
|
@ -0,0 +1,108 @@
|
||||||
|
import QtQuick
|
||||||
|
|
||||||
|
// A labelled input with an inline, filtered suggestion list. The user can type
|
||||||
|
// to narrow the list or click an entry to choose it, and a custom value is
|
||||||
|
// still allowed. Used for timezone, locale, keymap, provider and model so the
|
||||||
|
// user picks from what the system actually offers instead of typing from
|
||||||
|
// memory.
|
||||||
|
Column {
|
||||||
|
id: combo
|
||||||
|
|
||||||
|
property string label: ""
|
||||||
|
property string placeholder: ""
|
||||||
|
property string error: ""
|
||||||
|
property var options: []
|
||||||
|
property int maxVisible: 8
|
||||||
|
property string hint: "Type to filter, click to choose"
|
||||||
|
property alias text: field.text
|
||||||
|
property alias inputItem: field.inputItem
|
||||||
|
property var suggestions: []
|
||||||
|
|
||||||
|
signal edited(string value)
|
||||||
|
signal selected(string value)
|
||||||
|
|
||||||
|
width: parent ? parent.width : implicitWidth
|
||||||
|
spacing: 4
|
||||||
|
|
||||||
|
function refresh() {
|
||||||
|
const query = (field.text || "").toLowerCase();
|
||||||
|
const all = combo.options || [];
|
||||||
|
const out = [];
|
||||||
|
for (let i = 0; i < all.length && out.length < combo.maxVisible; i++) {
|
||||||
|
const option = "" + all[i];
|
||||||
|
if (query.length === 0 || option.toLowerCase().indexOf(query) !== -1)
|
||||||
|
out.push(option);
|
||||||
|
}
|
||||||
|
combo.suggestions = out;
|
||||||
|
}
|
||||||
|
|
||||||
|
onOptionsChanged: combo.refresh()
|
||||||
|
Component.onCompleted: combo.refresh()
|
||||||
|
|
||||||
|
PhoebusField {
|
||||||
|
id: field
|
||||||
|
width: parent.width
|
||||||
|
label: combo.label
|
||||||
|
placeholder: combo.placeholder
|
||||||
|
error: combo.error
|
||||||
|
onEdited: value => { combo.edited(value); combo.refresh(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show the first suggestions as soon as the field takes focus.
|
||||||
|
Connections {
|
||||||
|
target: field.inputItem
|
||||||
|
function onActiveFocusChanged() {
|
||||||
|
if (field.inputItem.activeFocus)
|
||||||
|
combo.refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Column {
|
||||||
|
width: parent.width
|
||||||
|
spacing: 0
|
||||||
|
visible: field.inputItem.activeFocus && combo.suggestions.length > 0
|
||||||
|
Repeater {
|
||||||
|
model: field.inputItem.activeFocus ? combo.suggestions : []
|
||||||
|
delegate: Rectangle {
|
||||||
|
required property var modelData
|
||||||
|
width: parent.width
|
||||||
|
height: 30
|
||||||
|
color: hover.containsMouse ? Theme.surfaceRaised : Theme.surface
|
||||||
|
border.width: 1
|
||||||
|
border.color: Theme.border
|
||||||
|
Text {
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.leftMargin: 12
|
||||||
|
anchors.rightMargin: 12
|
||||||
|
text: modelData
|
||||||
|
elide: Text.ElideRight
|
||||||
|
color: Theme.warmWhite
|
||||||
|
font.family: Theme.family
|
||||||
|
font.pixelSize: Theme.fontSmall
|
||||||
|
}
|
||||||
|
MouseArea {
|
||||||
|
id: hover
|
||||||
|
anchors.fill: parent
|
||||||
|
hoverEnabled: true
|
||||||
|
cursorShape: Qt.PointingHandCursor
|
||||||
|
onClicked: {
|
||||||
|
field.inputItem.text = modelData;
|
||||||
|
combo.selected(modelData);
|
||||||
|
combo.suggestions = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
width: parent.width
|
||||||
|
visible: field.inputItem.activeFocus && combo.options.length > 0
|
||||||
|
text: combo.hint
|
||||||
|
color: Theme.muted
|
||||||
|
font.family: Theme.family
|
||||||
|
font.pixelSize: Theme.fontSmall
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,4 +7,5 @@ PhoebusCard 1.0 PhoebusCard.qml
|
||||||
PhoebusField 1.0 PhoebusField.qml
|
PhoebusField 1.0 PhoebusField.qml
|
||||||
PhoebusToggle 1.0 PhoebusToggle.qml
|
PhoebusToggle 1.0 PhoebusToggle.qml
|
||||||
PhoebusChoice 1.0 PhoebusChoice.qml
|
PhoebusChoice 1.0 PhoebusChoice.qml
|
||||||
|
PhoebusCombo 1.0 PhoebusCombo.qml
|
||||||
PhoebusEmblem 1.0 PhoebusEmblem.qml
|
PhoebusEmblem 1.0 PhoebusEmblem.qml
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,11 @@ ShellRoot {
|
||||||
property string previewText: ""
|
property string previewText: ""
|
||||||
property string planDigest: ""
|
property string planDigest: ""
|
||||||
property var handshake: null
|
property var handshake: null
|
||||||
|
// Selectable system lists (timezones/locales/keymaps) and the AI catalog.
|
||||||
|
property var options: ({ timezones: [], locales: [], keymaps: [] })
|
||||||
|
property var aiCatalog: ({ providers: [], models: [] })
|
||||||
|
property string aiCatalogError: ""
|
||||||
|
readonly property var aiProviderIds: (shell.aiCatalog.providers || []).map(p => p.id)
|
||||||
|
|
||||||
// Secrets: held in memory only, sent over the bridge stdin, never in cfg.
|
// Secrets: held in memory only, sent over the bridge stdin, never in cfg.
|
||||||
property string userPw: ""
|
property string userPw: ""
|
||||||
|
|
@ -165,12 +170,34 @@ ShellRoot {
|
||||||
shell.phase = "form";
|
shell.phase = "form";
|
||||||
shell.status = "";
|
shell.status = "";
|
||||||
shell.syncFields();
|
shell.syncFields();
|
||||||
|
shell.loadOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshHandshake() {
|
function refreshHandshake() {
|
||||||
Bridge.refreshHandshake(null);
|
Bridge.refreshHandshake(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fetch the real timezones/locales/keymaps the live system offers.
|
||||||
|
function loadOptions() {
|
||||||
|
Bridge.options(reply => {
|
||||||
|
if (reply.ok)
|
||||||
|
shell.options = reply.data;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch the providers/models the configured AI connection offers.
|
||||||
|
function loadAiCatalog() {
|
||||||
|
Bridge.aiCatalog(reply => {
|
||||||
|
if (reply.ok) {
|
||||||
|
shell.aiCatalog = reply.data;
|
||||||
|
shell.aiCatalogError = "";
|
||||||
|
} else {
|
||||||
|
shell.aiCatalog = { providers: [], models: [] };
|
||||||
|
shell.aiCatalogError = reply.error;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function applyConfig(then) {
|
function applyConfig(then) {
|
||||||
if (!shell.cfg) {
|
if (!shell.cfg) {
|
||||||
shell.status = "The installer backend is not ready yet.";
|
shell.status = "The installer backend is not ready yet.";
|
||||||
|
|
@ -271,6 +298,8 @@ ShellRoot {
|
||||||
}
|
}
|
||||||
shell.syncFields();
|
shell.syncFields();
|
||||||
shell.touchConfig();
|
shell.touchConfig();
|
||||||
|
if (s === 2)
|
||||||
|
shell.loadAiCatalog();
|
||||||
if (s === 3)
|
if (s === 3)
|
||||||
refreshDisks();
|
refreshDisks();
|
||||||
if (s === 5)
|
if (s === 5)
|
||||||
|
|
@ -340,6 +369,8 @@ ShellRoot {
|
||||||
endpointField.inputItem.text = shell.cfg.ai.endpoint;
|
endpointField.inputItem.text = shell.cfg.ai.endpoint;
|
||||||
}
|
}
|
||||||
shell.touchConfig();
|
shell.touchConfig();
|
||||||
|
// Populate the provider/model choices for the newly selected backend.
|
||||||
|
shell.loadAiCatalog();
|
||||||
}
|
}
|
||||||
|
|
||||||
// A lightweight real interaction used by "Test connection": it obtains and
|
// A lightweight real interaction used by "Test connection": it obtains and
|
||||||
|
|
@ -680,46 +711,34 @@ ShellRoot {
|
||||||
PhoebusCard {
|
PhoebusCard {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
Text { width: parent.width; text: "Language and region"; color: Theme.warmWhite; font.family: Theme.family; font.pixelSize: Theme.fontHeading; font.weight: Font.DemiBold }
|
Text { width: parent.width; text: "Language and region"; color: Theme.warmWhite; font.family: Theme.family; font.pixelSize: Theme.fontHeading; font.weight: Font.DemiBold }
|
||||||
PhoebusField {
|
PhoebusCombo {
|
||||||
id: localeField
|
id: localeField
|
||||||
label: "Locale"
|
label: "Locale"
|
||||||
placeholder: "en_US.UTF-8"
|
placeholder: "en_US.UTF-8"
|
||||||
|
options: shell.options.locales
|
||||||
error: shell.issueFor("locale")
|
error: shell.issueFor("locale")
|
||||||
onEdited: value => shell.cfg.system.locale = value
|
onEdited: value => shell.cfg.system.locale = value
|
||||||
|
onSelected: value => shell.cfg.system.locale = value
|
||||||
Component.onCompleted: inputItem.text = shell.cfg ? shell.cfg.system.locale : ""
|
Component.onCompleted: inputItem.text = shell.cfg ? shell.cfg.system.locale : ""
|
||||||
}
|
}
|
||||||
PhoebusChoice {
|
PhoebusCombo {
|
||||||
id: localePresets
|
|
||||||
options: [
|
|
||||||
{ value: "en_US.UTF-8", label: "English (US)" },
|
|
||||||
{ value: "en_GB.UTF-8", label: "English (UK)" },
|
|
||||||
{ value: "de_DE.UTF-8", label: "Deutsch" },
|
|
||||||
{ value: "fr_FR.UTF-8", label: "Français" },
|
|
||||||
{ value: "es_ES.UTF-8", label: "Español" }
|
|
||||||
]
|
|
||||||
value: shell.cfg ? shell.cfg.system.locale : ""
|
|
||||||
onSelected: value => { shell.cfg.system.locale = value; localeField.inputItem.text = value; shell.touchConfig(); }
|
|
||||||
}
|
|
||||||
PhoebusField {
|
|
||||||
id: keymapField
|
id: keymapField
|
||||||
label: "Keyboard layout"
|
label: "Keyboard layout"
|
||||||
placeholder: "us"
|
placeholder: "us"
|
||||||
|
options: shell.options.keymaps
|
||||||
error: shell.issueFor("keymap")
|
error: shell.issueFor("keymap")
|
||||||
onEdited: value => shell.cfg.system.keymap = value
|
onEdited: value => shell.cfg.system.keymap = value
|
||||||
|
onSelected: value => shell.cfg.system.keymap = value
|
||||||
Component.onCompleted: inputItem.text = shell.cfg ? shell.cfg.system.keymap : ""
|
Component.onCompleted: inputItem.text = shell.cfg ? shell.cfg.system.keymap : ""
|
||||||
}
|
}
|
||||||
PhoebusChoice {
|
PhoebusCombo {
|
||||||
id: keymapPresets
|
|
||||||
options: ["us", "gb", "de", "fr", "es", "dvorak"]
|
|
||||||
value: shell.cfg ? shell.cfg.system.keymap : ""
|
|
||||||
onSelected: value => { shell.cfg.system.keymap = value; keymapField.inputItem.text = value; shell.touchConfig(); }
|
|
||||||
}
|
|
||||||
PhoebusField {
|
|
||||||
id: tzField
|
id: tzField
|
||||||
label: "Timezone"
|
label: "Timezone"
|
||||||
placeholder: "UTC"
|
placeholder: "UTC"
|
||||||
|
options: shell.options.timezones
|
||||||
error: shell.issueFor("timezone")
|
error: shell.issueFor("timezone")
|
||||||
onEdited: value => shell.cfg.system.timezone = value
|
onEdited: value => shell.cfg.system.timezone = value
|
||||||
|
onSelected: value => shell.cfg.system.timezone = value
|
||||||
Component.onCompleted: inputItem.text = shell.cfg ? shell.cfg.system.timezone : ""
|
Component.onCompleted: inputItem.text = shell.cfg ? shell.cfg.system.timezone : ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -801,15 +820,6 @@ ShellRoot {
|
||||||
visible: shell.cfg && !shell.isOpenCode && (shell.cfg.ai.provider === "deepseek" || shell.cfg.ai.provider === "openai")
|
visible: shell.cfg && !shell.isOpenCode && (shell.cfg.ai.provider === "deepseek" || shell.cfg.ai.provider === "openai")
|
||||||
onEdited: value => shell.apiKey = value
|
onEdited: value => shell.apiKey = value
|
||||||
}
|
}
|
||||||
PhoebusField {
|
|
||||||
id: modelField
|
|
||||||
label: "Model"
|
|
||||||
placeholder: "model name"
|
|
||||||
error: ""
|
|
||||||
visible: shell.cfg && !shell.isOpenCode
|
|
||||||
onEdited: value => shell.cfg.ai.model = value
|
|
||||||
Component.onCompleted: inputItem.text = shell.cfg && shell.cfg.ai.model ? shell.cfg.ai.model : ""
|
|
||||||
}
|
|
||||||
PhoebusField {
|
PhoebusField {
|
||||||
id: endpointField
|
id: endpointField
|
||||||
label: "Endpoint (local models)"
|
label: "Endpoint (local models)"
|
||||||
|
|
@ -818,6 +828,35 @@ ShellRoot {
|
||||||
onEdited: value => shell.cfg.ai.endpoint = value
|
onEdited: value => shell.cfg.ai.endpoint = value
|
||||||
Component.onCompleted: inputItem.text = shell.cfg && shell.cfg.ai.endpoint ? shell.cfg.ai.endpoint : ""
|
Component.onCompleted: inputItem.text = shell.cfg && shell.cfg.ai.endpoint ? shell.cfg.ai.endpoint : ""
|
||||||
}
|
}
|
||||||
|
PhoebusCombo {
|
||||||
|
id: modelField
|
||||||
|
label: "Model"
|
||||||
|
placeholder: "choose a model or type one"
|
||||||
|
options: shell.aiCatalog.models
|
||||||
|
visible: shell.cfg && !shell.isOpenCode
|
||||||
|
onEdited: value => shell.cfg.ai.model = value
|
||||||
|
onSelected: value => shell.cfg.ai.model = value
|
||||||
|
Component.onCompleted: inputItem.text = shell.cfg && shell.cfg.ai.model ? shell.cfg.ai.model : ""
|
||||||
|
}
|
||||||
|
Row {
|
||||||
|
spacing: 12
|
||||||
|
visible: shell.cfg && !shell.isOpenCode
|
||||||
|
PhoebusButton {
|
||||||
|
label: shell.aiChecking ? "Loading…" : "Load model list"
|
||||||
|
compact: true
|
||||||
|
onClicked: shell.loadAiCatalog()
|
||||||
|
}
|
||||||
|
Text {
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
visible: shell.aiCatalogError.length > 0
|
||||||
|
text: shell.aiCatalogError
|
||||||
|
color: Theme.danger
|
||||||
|
font.family: Theme.family
|
||||||
|
font.pixelSize: Theme.fontSmall
|
||||||
|
width: parent.width - 200
|
||||||
|
elide: Text.ElideRight
|
||||||
|
}
|
||||||
|
}
|
||||||
// -- OpenCode agent server -----------------------------
|
// -- OpenCode agent server -----------------------------
|
||||||
Text {
|
Text {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
|
|
@ -843,19 +882,45 @@ ShellRoot {
|
||||||
visible: shell.isOpenCode
|
visible: shell.isOpenCode
|
||||||
onEdited: value => shell.opencodePassword = value
|
onEdited: value => shell.opencodePassword = value
|
||||||
}
|
}
|
||||||
PhoebusField {
|
PhoebusCombo {
|
||||||
id: opencodeProviderField
|
id: opencodeProviderField
|
||||||
label: "Provider"
|
label: "Provider"
|
||||||
placeholder: "deepseek"
|
placeholder: "choose a provider"
|
||||||
|
options: shell.aiProviderIds
|
||||||
visible: shell.isOpenCode
|
visible: shell.isOpenCode
|
||||||
onEdited: value => shell.cfg.ai.opencode_provider = value
|
onEdited: value => shell.cfg.ai.opencode_provider = value
|
||||||
|
onSelected: value => {
|
||||||
|
shell.cfg.ai.opencode_provider = value;
|
||||||
|
shell.loadAiCatalog();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PhoebusField {
|
PhoebusCombo {
|
||||||
id: opencodeModelField
|
id: opencodeModelField
|
||||||
label: "Model"
|
label: "Model"
|
||||||
placeholder: "deepseek-chat"
|
placeholder: "choose a model"
|
||||||
|
options: shell.aiCatalog.models
|
||||||
visible: shell.isOpenCode
|
visible: shell.isOpenCode
|
||||||
onEdited: value => shell.cfg.ai.opencode_model = value
|
onEdited: value => shell.cfg.ai.opencode_model = value
|
||||||
|
onSelected: value => shell.cfg.ai.opencode_model = value
|
||||||
|
}
|
||||||
|
Row {
|
||||||
|
spacing: 12
|
||||||
|
visible: shell.isOpenCode
|
||||||
|
PhoebusButton {
|
||||||
|
label: "Load provider/model list"
|
||||||
|
compact: true
|
||||||
|
onClicked: shell.loadAiCatalog()
|
||||||
|
}
|
||||||
|
Text {
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
visible: shell.aiCatalogError.length > 0
|
||||||
|
text: shell.aiCatalogError
|
||||||
|
color: Theme.danger
|
||||||
|
font.family: Theme.family
|
||||||
|
font.pixelSize: Theme.fontSmall
|
||||||
|
width: parent.width - 240
|
||||||
|
elide: Text.ElideRight
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Row {
|
Row {
|
||||||
spacing: 12
|
spacing: 12
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue