aKode v0.2: pannello /endpoint e impostazioni per modello
- /endpoint: tre colonne (endpoint, modelli, impostazioni), una alla volta sotto 100 colonne con il percorso in alto. Aggiunta e modifica con il modulo dell'endpoint di /setup (chiave mascherata e mantenuta se vuota), prova della connessione, eliminazione con conferma e rimozione della chiave, «u» per usare endpoint e modello con una nuova chat. - [model_providers.<id>.models."<modello>"]: context_window, temperature, top_p, max_output_tokens, reasoning_effort, display_name. Il valore del modello vince su quello globale; temperature/top_p/max_output_tokens vanno nella richiesta Responses; il contesto entra nel calcolo di ctx % e dell'auto-compattazione. Le modifiche al modello attivo valgono dal turno successivo, senza riavvio. - Nomi dei modelli: gli id che sono percorsi mostrano solo il nome del file senza estensione; display_name ha la precedenza. L'API riceve sempre l'id completo. - /setup: se [web_search] è configurato, l'URL di SearXNG è precompilato e «Mantieni» è preselezionato. - Schema della configurazione rigenerato; test per precedenze, richiesta, snapshot a 80/120/160 colonne e assenza delle chiavi. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -72,6 +72,75 @@ impl App {
|
||||
tui.frame_requester().schedule_frame();
|
||||
}
|
||||
|
||||
/// `/endpoint`: endpoints, their models and per-model settings.
|
||||
pub(super) async fn run_endpoint_panel(
|
||||
&mut self,
|
||||
tui: &mut tui::Tui,
|
||||
app_server: &mut AppServerSession,
|
||||
) {
|
||||
self.refresh_in_memory_config_from_disk_best_effort("endpoint panel")
|
||||
.await;
|
||||
let config = self.config.clone();
|
||||
let active_provider = self.chat_widget.config_ref().model_provider_id.clone();
|
||||
let active_model = self.chat_widget.current_model().to_string();
|
||||
// Configured endpoints, plus the active one when it is built in.
|
||||
let configured: std::collections::BTreeSet<String> = config
|
||||
.config_layer_stack
|
||||
.effective_config()
|
||||
.get("model_providers")
|
||||
.and_then(|providers| providers.as_table())
|
||||
.map(|providers| providers.keys().cloned().collect())
|
||||
.unwrap_or_default();
|
||||
let mut endpoints: Vec<crate::endpoint_panel::EndpointEntry> = config
|
||||
.model_providers
|
||||
.iter()
|
||||
.filter(|(id, _)| configured.contains(*id) || **id == active_provider)
|
||||
.map(|(id, info)| crate::endpoint_panel::EndpointEntry {
|
||||
id: id.clone(),
|
||||
info: info.clone(),
|
||||
typed_key: None,
|
||||
})
|
||||
.collect();
|
||||
endpoints.sort_by(|a, b| {
|
||||
(a.id != active_provider, a.info.name.to_lowercase())
|
||||
.cmp(&(b.id != active_provider, b.info.name.to_lowercase()))
|
||||
});
|
||||
let ctx = crate::endpoint_panel::EndpointPanelContext {
|
||||
endpoints,
|
||||
active_provider,
|
||||
active_model,
|
||||
global_context_window: config.model_context_window,
|
||||
setup: crate::onboarding::onboarding_screen::setup_context(
|
||||
&config,
|
||||
Some(app_server.request_handle()),
|
||||
/*include_theme*/ false,
|
||||
),
|
||||
};
|
||||
let outcome = match crate::endpoint_panel::run_endpoint_panel(tui, ctx).await {
|
||||
Ok(outcome) => outcome,
|
||||
Err(err) => {
|
||||
self.chat_widget
|
||||
.add_error_message(format!("Pannello endpoint non disponibile: {err}"));
|
||||
return;
|
||||
}
|
||||
};
|
||||
if outcome.config_changed {
|
||||
self.refresh_in_memory_config_from_disk_best_effort("endpoint panel")
|
||||
.await;
|
||||
crate::model_display::set_display_names_from_config(&self.config);
|
||||
self.chat_widget.refresh_model_dependent_surfaces();
|
||||
}
|
||||
if let Some(effort) = outcome.active_effort.clone()
|
||||
&& outcome.activate.is_none()
|
||||
{
|
||||
self.app_event_tx.send(AppEvent::UpdateReasoningEffort(effort));
|
||||
}
|
||||
if let Some((provider_id, model)) = outcome.activate {
|
||||
self.switch_provider(app_server, provider_id, model).await;
|
||||
}
|
||||
tui.frame_requester().schedule_frame();
|
||||
}
|
||||
|
||||
/// Fetch another provider's model list directly from its server (`GET {base_url}/models`).
|
||||
pub(super) fn open_provider_models(&mut self, provider_id: String) {
|
||||
let config = self.chat_widget.config_ref();
|
||||
|
||||
@@ -218,7 +218,7 @@ impl ChatWidget {
|
||||
&self.config,
|
||||
&self.local_settings,
|
||||
&model_for_header,
|
||||
self.model_catalog.display_name(&session.model),
|
||||
&self.model_catalog.display_name(&session.model),
|
||||
&session,
|
||||
self.show_welcome_banner,
|
||||
startup_tooltip_override,
|
||||
|
||||
@@ -252,7 +252,7 @@ impl ChatWidget {
|
||||
rate_limit_snapshots.as_slice(),
|
||||
self.plan_type,
|
||||
Local::now(),
|
||||
self.model_display_name(),
|
||||
&self.model_display_name(),
|
||||
collaboration_mode,
|
||||
reasoning_effort_override,
|
||||
agents_summary,
|
||||
|
||||
1523
akode-rs/tui/src/endpoint_panel.rs
Normal file
1523
akode-rs/tui/src/endpoint_panel.rs
Normal file
File diff suppressed because it is too large
Load Diff
168
akode-rs/tui/src/endpoint_panel_tests.rs
Normal file
168
akode-rs/tui/src/endpoint_panel_tests.rs
Normal file
@@ -0,0 +1,168 @@
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
const SECRET: &str = "sk-akode-test-secret-0123456789";
|
||||
const FLINT: &str = "/Users/andrea/models/Flint.APEX-I-NanoPlus-V2.1.gguf";
|
||||
|
||||
fn provider(name: &str, url: &str) -> ModelProviderInfo {
|
||||
ModelProviderInfo {
|
||||
name: name.to_string(),
|
||||
base_url: Some(url.to_string()),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn panel() -> EndpointPanel {
|
||||
let mut macos = provider("MACOS", "http://127.0.0.1:8080/v1");
|
||||
macos.models.insert(
|
||||
FLINT.to_string(),
|
||||
ProviderModelSettings {
|
||||
context_window: Some(65536),
|
||||
temperature: Some(0.7),
|
||||
top_p: Some(0.95),
|
||||
max_output_tokens: Some(8192),
|
||||
reasoning_effort: Some(ReasoningEffort::Medium),
|
||||
display_name: None,
|
||||
},
|
||||
);
|
||||
let ctx = EndpointPanelContext {
|
||||
endpoints: vec![
|
||||
EndpointEntry {
|
||||
id: "macos".to_string(),
|
||||
info: macos,
|
||||
typed_key: None,
|
||||
},
|
||||
EndpointEntry {
|
||||
id: "giulio".to_string(),
|
||||
info: provider("Giulio", "https://mega-link.cloud/v1"),
|
||||
typed_key: Some(SECRET.to_string()),
|
||||
},
|
||||
EndpointEntry {
|
||||
id: "openrouter".to_string(),
|
||||
info: provider("OpenRouter", "https://openrouter.ai/api/v1"),
|
||||
typed_key: None,
|
||||
},
|
||||
],
|
||||
active_provider: "macos".to_string(),
|
||||
active_model: FLINT.to_string(),
|
||||
global_context_window: None,
|
||||
setup: SetupContext::default(),
|
||||
};
|
||||
let mut panel = EndpointPanel::new(FrameRequester::test_dummy(), ctx);
|
||||
panel.set_models_for_test(
|
||||
"macos",
|
||||
setup_net::ModelList {
|
||||
base_url: "http://127.0.0.1:8080/v1".to_string(),
|
||||
models: vec![FLINT.to_string()],
|
||||
..Default::default()
|
||||
},
|
||||
Some(65536),
|
||||
);
|
||||
panel
|
||||
}
|
||||
|
||||
fn key(code: KeyCode) -> KeyEvent {
|
||||
KeyEvent::new(code, KeyModifiers::NONE)
|
||||
}
|
||||
|
||||
fn render(panel: &EndpointPanel, width: u16, height: u16) -> String {
|
||||
let area = Rect::new(0, 0, width, height);
|
||||
let mut buf = Buffer::empty(area);
|
||||
panel.render_ref(area, &mut buf);
|
||||
(0..height)
|
||||
.map(|y| {
|
||||
(0..width)
|
||||
.map(|x| buf[(x, y)].symbol().to_string())
|
||||
.collect::<String>()
|
||||
.trim_end()
|
||||
.to_string()
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn endpoint_panel_snapshots() {
|
||||
let panel = panel();
|
||||
for width in [80, 120, 160] {
|
||||
insta::assert_snapshot!(format!("endpoint_panel_{width}"), render(&panel, width, 14));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn narrow_panel_shows_one_column_with_breadcrumb() {
|
||||
let mut panel = panel();
|
||||
panel.handle_key_event(key(KeyCode::Tab));
|
||||
panel.handle_key_event(key(KeyCode::Tab));
|
||||
let text = render(&panel, 80, 14);
|
||||
assert!(text.contains("Impostazioni · Flint.APEX-I-NanoPlus-V2.1"));
|
||||
assert!(text.contains("(server 65536)"));
|
||||
insta::assert_snapshot!("endpoint_panel_settings_80", text);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn path_model_ids_show_the_file_stem() {
|
||||
let text = render(&panel(), 160, 14);
|
||||
assert!(text.contains("Flint.APEX-I-NanoPlus-V2.1"));
|
||||
assert!(!text.contains(".gguf"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keys_never_appear_in_the_panel_or_the_edit_form() {
|
||||
let mut panel = panel();
|
||||
panel.handle_key_event(key(KeyCode::Down));
|
||||
for width in [80, 120, 160] {
|
||||
assert!(!render(&panel, width, 14).contains(SECRET));
|
||||
}
|
||||
panel.handle_key_event(key(KeyCode::Enter));
|
||||
assert!(panel.wizard.is_some());
|
||||
let form = render(&panel, 120, 20);
|
||||
assert!(form.contains("Modifica endpoint"));
|
||||
assert!(form.contains("lascia vuoto per mantenerla"));
|
||||
assert!(!form.contains(SECRET));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_active_endpoint_cannot_be_deleted() {
|
||||
let mut panel = panel();
|
||||
panel.handle_key_event(key(KeyCode::Char('d')));
|
||||
assert!(!panel.confirm_delete);
|
||||
assert!(render(&panel, 120, 14).contains("Non puoi eliminare l'endpoint attivo"));
|
||||
panel.handle_key_event(key(KeyCode::Down));
|
||||
panel.handle_key_event(key(KeyCode::Char('d')));
|
||||
assert!(panel.confirm_delete);
|
||||
panel.handle_key_event(key(KeyCode::Esc));
|
||||
assert!(!panel.confirm_delete);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn settings_parse_and_key_paths_quote_the_model_id() {
|
||||
assert_eq!(
|
||||
parse_setting(Setting::Temperature, "0,7"),
|
||||
Ok(Some(serde_json::json!(0.7)))
|
||||
);
|
||||
assert_eq!(parse_setting(Setting::Context, ""), Ok(None));
|
||||
assert!(parse_setting(Setting::TopP, "1.5").is_err());
|
||||
assert_eq!(
|
||||
model_setting_path("openrouter", "recursive/flint-v1.0:free", "top_p"),
|
||||
"model_providers.openrouter.models.\"recursive/flint-v1.0:free\".top_p"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn per_model_settings_serialize_without_keys() {
|
||||
let mut info = provider("Giulio", "https://mega-link.cloud/v1");
|
||||
info.models.insert(
|
||||
"flint".to_string(),
|
||||
ProviderModelSettings {
|
||||
context_window: Some(65536),
|
||||
temperature: Some(0.7),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let toml = toml::to_string(&info).expect("serialize");
|
||||
assert!(toml.contains("[models.flint]"));
|
||||
assert!(toml.contains("context_window = 65536"));
|
||||
assert!(!toml.contains(SECRET));
|
||||
assert!(!toml.contains("top_p"));
|
||||
}
|
||||
@@ -6,8 +6,8 @@ mod keys;
|
||||
pub(crate) mod onboarding_screen;
|
||||
mod provider_required;
|
||||
pub(crate) use provider_required::model_provider_missing;
|
||||
mod provider_setup;
|
||||
mod setup_net;
|
||||
pub(crate) mod provider_setup;
|
||||
pub(crate) mod setup_net;
|
||||
pub(crate) mod setup_wizard;
|
||||
pub(crate) use provider_setup::FieldDisplay;
|
||||
pub(crate) use provider_setup::ProviderInput;
|
||||
|
||||
@@ -462,3 +462,52 @@ fn endpoint_without_a_key_skips_the_storage_choice() {
|
||||
wizard.handle_key_event(key(KeyCode::Enter));
|
||||
assert_eq!(wizard.page, Page::Model);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn endpoint_mode_edits_keep_the_key_out_of_config() {
|
||||
let mut ctx = SetupContext {
|
||||
key_store_mode: AuthCredentialsStoreMode::Auto,
|
||||
keyring_available: true,
|
||||
endpoint_mode: Some(EndpointMode {
|
||||
edit: Some(EndpointEdit {
|
||||
provider_id: "giulio".to_string(),
|
||||
name: "Giulio".to_string(),
|
||||
base_url: "https://mega-link.cloud/v1".to_string(),
|
||||
stored_key: Some(SECRET.to_string()),
|
||||
}),
|
||||
}),
|
||||
..Default::default()
|
||||
};
|
||||
ctx.existing_provider_ids.insert("giulio".to_string());
|
||||
let mut wizard = SetupWizard::new(FrameRequester::test_dummy(), ctx);
|
||||
assert_eq!(wizard.page, Page::Endpoint);
|
||||
assert!(!render(&wizard, 80, 14).contains(SECRET));
|
||||
wizard.handle_key_event(key(KeyCode::Down));
|
||||
wizard.handle_key_event(key(KeyCode::Down));
|
||||
type_text(&mut wizard, SECRET);
|
||||
wizard.base_url = "https://mega-link.cloud/v1".to_string();
|
||||
let edits = wizard.endpoint_config_edits("giulio", "Giulio", true);
|
||||
let json = serde_json::to_string(&edits.iter().map(|e| (&e.key_path, &e.value)).collect::<Vec<_>>())
|
||||
.expect("serialize");
|
||||
assert!(!json.contains(SECRET));
|
||||
assert!(json.contains("model_providers.giulio.api_key"));
|
||||
assert!(!json.contains("model_providers.giulio.models"));
|
||||
assert!(!json.contains("\"model\""));
|
||||
assert!(!render(&wizard, 80, 14).contains(SECRET));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn configured_searxng_is_prefilled_and_kept() {
|
||||
let ctx = SetupContext {
|
||||
searx_url: Some("http://192.168.40.57:8080".to_string()),
|
||||
..Default::default()
|
||||
};
|
||||
let mut wizard = SetupWizard::new(FrameRequester::test_dummy(), ctx);
|
||||
wizard.page = Page::WebSearch;
|
||||
assert!(wizard.searx_keep_available());
|
||||
assert_eq!(wizard.searx_focus, 1);
|
||||
let text = render(&wizard, 80, 14);
|
||||
assert!(text.contains("http://192.168.40.57:8080"));
|
||||
assert!(text.contains("› [ Mantieni ]"));
|
||||
assert!(wizard.config_edits("p", "P", false).iter().all(|e| e.key_path != "web_search"));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
source: tui/src/endpoint_panel_tests.rs
|
||||
expression: "render(&panel, width, 14)"
|
||||
---
|
||||
Modelli ed endpoint esc chiudi
|
||||
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
Endpoint │ Modelli · MACOS │ Impostazioni · Flint.APEX-I-NanoPlus-V2.1
|
||||
› ● MACOS 127.0.0.1 │ › Flint.APEX-I-NanoPlus-V2.1 ● attivo │ › Contesto 65536 (server 65536)
|
||||
Giulio mega-link.clo… │ │ Temperatura 0.7
|
||||
OpenRouter openrouter.ai │ │ Top-p 0.95
|
||||
+ Aggiungi endpoint │ │ Max output 8192
|
||||
│ │ Ragionamento medio
|
||||
│ │ Nome Flint.APEX-I-NanoPlus-V2…
|
||||
│ │
|
||||
│ │
|
||||
|
||||
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
↑↓ scegli · tab colonna · invio modifica · u usa · t prova connessione · d elimina
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
source: tui/src/endpoint_panel_tests.rs
|
||||
expression: "render(&panel, width, 14)"
|
||||
---
|
||||
Modelli ed endpoint esc chiudi
|
||||
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
Endpoint │ Modelli · MACOS │ Impostazioni · Flint.APEX-I-NanoPlus-V2.1
|
||||
› ● MACOS 127.0.0.1 │ › Flint.APEX-I-NanoPlus-V2.1 ● attivo │ › Contesto 65536 (server 65536)
|
||||
Giulio mega-link.cloud │ │ Temperatura 0.7
|
||||
OpenRouter openrouter.ai │ │ Top-p 0.95
|
||||
+ Aggiungi endpoint │ │ Max output 8192
|
||||
│ │ Ragionamento medio
|
||||
│ │ Nome Flint.APEX-I-NanoPlus-V2.1
|
||||
│ │
|
||||
│ │
|
||||
|
||||
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
↑↓ scegli · tab colonna · invio modifica · u usa · t prova connessione · d elimina
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
source: tui/src/endpoint_panel_tests.rs
|
||||
expression: "render(&panel, width, 14)"
|
||||
---
|
||||
Modelli ed endpoint esc chiudi
|
||||
────────────────────────────────────────────────────────────────────────────
|
||||
Endpoint › Modelli › Impostazioni
|
||||
› ● MACOS 127.0.0.1
|
||||
Giulio mega-link.cloud
|
||||
OpenRouter openrouter.ai
|
||||
+ Aggiungi endpoint
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
────────────────────────────────────────────────────────────────────────────
|
||||
↑↓ scegli · tab colonna · invio modifica · u usa · t prova · d elimina
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
source: tui/src/endpoint_panel_tests.rs
|
||||
expression: text
|
||||
---
|
||||
Modelli ed endpoint esc chiudi
|
||||
────────────────────────────────────────────────────────────────────────────
|
||||
Endpoint › Modelli › Impostazioni · Flint.APEX-I-NanoPlus-V2.1
|
||||
› Contesto 65536 (server 65536)
|
||||
Temperatura 0.7
|
||||
Top-p 0.95
|
||||
Max output 8192
|
||||
Ragionamento medio
|
||||
Nome Flint.APEX-I-NanoPlus-V2.1
|
||||
|
||||
|
||||
|
||||
────────────────────────────────────────────────────────────────────────────
|
||||
↑↓ scegli · tab colonna · invio modifica · canc predefinito · u usa
|
||||
Reference in New Issue
Block a user