aKode fase 5: 429 con Retry-After/X-RateLimit-Reset e messaggi in italiano, filtro modelli nel primo avvio, correzioni della rinomina
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -27,7 +27,7 @@ impl App {
|
||||
let disconnect_info = thread_id.and_then(|_| {
|
||||
let command = match &self.app_server_target {
|
||||
AppServerTarget::Embedded | AppServerTarget::Cloud => return None,
|
||||
AppServerTarget::LocalDaemon { .. } => vec!["codex".to_string()],
|
||||
AppServerTarget::LocalDaemon { .. } => vec!["akode".to_string()],
|
||||
AppServerTarget::Remote { endpoint } => {
|
||||
let address = match endpoint {
|
||||
RemoteAppServerEndpoint::WebSocket { websocket_url, .. } => {
|
||||
@@ -44,7 +44,7 @@ impl App {
|
||||
format!("unix://{}", socket_path.display())
|
||||
}
|
||||
};
|
||||
vec!["codex".to_string(), "--remote".to_string(), address]
|
||||
vec!["akode".to_string(), "--remote".to_string(), address]
|
||||
}
|
||||
};
|
||||
let stop_hint = self
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
{"run_id":"1794393105-269973000","line":406,"new":{"module_name":"akode_tui__app__tests__session_lifecycle_requests","snapshot_name":"cloud_resume_picker_reconciles_admitted_steers","metadata":{"source":"tui/src/app/tests/session_lifecycle_requests.rs","assertion_line":406,"expression":"rendered_responses(&app)"},"snapshot":" Tip: Use /copy or press ⌃o to copy the latest agent response as Markdown.\n• Commentary response\n• Partial response"},"old":{"module_name":"akode_tui__app__tests__session_lifecycle_requests","metadata":{},"snapshot":"• Commentary response\n• Partial response"}}
|
||||
{"run_id":"1794393105-269973000","line":4851,"new":null,"old":null}
|
||||
{"run_id":"1794393105-269973000","line":4947,"new":null,"old":null}
|
||||
{"run_id":"1794393105-269973000","line":4949,"new":null,"old":null}
|
||||
{"run_id":"1794393105-269973000","line":4990,"new":null,"old":null}
|
||||
{"run_id":"1794393105-269973000","line":4990,"new":null,"old":null}
|
||||
{"run_id":"1794393105-269973000","line":5285,"new":null,"old":null}
|
||||
{"run_id":"1794393105-269973000","line":4330,"new":null,"old":null}
|
||||
{"run_id":"1794393105-269973000","line":5062,"new":null,"old":null}
|
||||
{"run_id":"1794393105-269973000","line":5902,"new":null,"old":null}
|
||||
{"run_id":"1794393105-269973000","line":5948,"new":null,"old":null}
|
||||
{"run_id":"1794393105-269973000","line":3067,"new":null,"old":null}
|
||||
{"run_id":"1794393105-269973000","line":5485,"new":null,"old":null}
|
||||
{"run_id":"1794393105-269973000","line":5563,"new":null,"old":null}
|
||||
{"run_id":"1794393105-269973000","line":5948,"new":null,"old":null}
|
||||
{"run_id":"1794393105-269973000","line":5902,"new":null,"old":null}
|
||||
{"run_id":"1794393262-192799000","line":406,"new":null,"old":null}
|
||||
{"run_id":"1794393262-192799000","line":427,"new":null,"old":null}
|
||||
{"run_id":"1794393262-192799000","line":446,"new":null,"old":null}
|
||||
{"run_id":"1794393262-192799000","line":468,"new":null,"old":null}
|
||||
@@ -1677,7 +1677,7 @@ async fn external_transport_registers_dynamic_tools_and_finds_task_mentions() ->
|
||||
assert_eq!(starts.len(), 2);
|
||||
for params in starts {
|
||||
assert_eq!(params["dynamicTools"][0]["type"], "namespace");
|
||||
assert_eq!(params["dynamicTools"][0]["name"], "akode_tui");
|
||||
assert_eq!(params["dynamicTools"][0]["name"], "codex_tui");
|
||||
assert_eq!(
|
||||
params["dynamicTools"][0]["tools"].as_array().map(Vec::len),
|
||||
Some(6)
|
||||
@@ -1984,7 +1984,7 @@ async fn local_daemon_registers_approval_gated_mcp_tools_for_both_start_paths_sc
|
||||
let tools = &inventory
|
||||
.data
|
||||
.iter()
|
||||
.find(|server| server.name == "akode_tui")
|
||||
.find(|server| server.name == "codex_tui")
|
||||
.expect("local daemon must connect to the TUI MCP server")
|
||||
.tools;
|
||||
assert_eq!(tools.len(), 9);
|
||||
@@ -2383,7 +2383,7 @@ async fn embedded_server_dispatches_only_its_own_dynamic_tools() -> Result<()> {
|
||||
crate::test_support::ensure_test_config_toml(&app.config.codex_home);
|
||||
app.config.sqlite = SqliteConfig::new_for_testing(codex_home.path().abs());
|
||||
let app_server = crate::start_embedded_app_server_for_picker(&app.config).await?;
|
||||
for (id, namespace, expected_success) in [(100, "codex_app", false), (101, "akode_tui", true)] {
|
||||
for (id, namespace, expected_success) in [(100, "codex_app", false), (101, "codex_tui", true)] {
|
||||
app.handle_app_server_event(
|
||||
&app_server,
|
||||
akode_app_server_client::AppServerEvent::ServerRequest(Box::new(
|
||||
@@ -2521,7 +2521,7 @@ async fn check_dynamic_tool_requests(
|
||||
thread_id: thread_id.clone(),
|
||||
turn_id: "turn-1".to_string(),
|
||||
call_id: "call-2".to_string(),
|
||||
namespace: Some("akode_tui".to_string()),
|
||||
namespace: Some("codex_tui".to_string()),
|
||||
tool: "list_threads".to_string(),
|
||||
arguments: serde_json::json!({}),
|
||||
},
|
||||
@@ -2578,7 +2578,7 @@ async fn check_dynamic_tool_requests(
|
||||
thread_id: thread_id.clone(),
|
||||
turn_id: "turn-1".to_string(),
|
||||
call_id: "call-3".to_string(),
|
||||
namespace: Some("akode_tui".to_string()),
|
||||
namespace: Some("codex_tui".to_string()),
|
||||
tool: "set_thread_title".to_string(),
|
||||
arguments: serde_json::json!({"threadId": thread_id, "title": "Renamed"}),
|
||||
},
|
||||
@@ -2612,7 +2612,7 @@ async fn check_dynamic_tool_requests(
|
||||
thread_id: thread_id.clone(),
|
||||
turn_id: "turn-1".to_string(),
|
||||
call_id: format!("rejected-{index}"),
|
||||
namespace: Some("akode_tui".to_string()),
|
||||
namespace: Some("codex_tui".to_string()),
|
||||
tool: tool.to_string(),
|
||||
arguments: serde_json::json!({}),
|
||||
},
|
||||
@@ -2673,7 +2673,7 @@ async fn check_dynamic_tool_requests(
|
||||
request_id: AppServerRequestId::String("read-source-sandbox".to_string()),
|
||||
params: akode_app_server_protocol::ThreadResumeParams {
|
||||
thread_id: creation_source.to_string(),
|
||||
..codex_app_server_protocol::ThreadResumeParams::default()
|
||||
..akode_app_server_protocol::ThreadResumeParams::default()
|
||||
},
|
||||
})
|
||||
.await?;
|
||||
@@ -2690,7 +2690,7 @@ async fn check_dynamic_tool_requests(
|
||||
thread_id: creation_source.to_string(),
|
||||
turn_id: "turn-1".to_string(),
|
||||
call_id: "call-4".to_string(),
|
||||
namespace: Some("akode_tui".to_string()),
|
||||
namespace: Some("codex_tui".to_string()),
|
||||
tool: "create_thread".to_string(),
|
||||
arguments: serde_json::json!({
|
||||
"prompt": "Check <main> & report",
|
||||
@@ -2765,7 +2765,7 @@ async fn check_dynamic_tool_requests(
|
||||
turn["toolOutput"],
|
||||
serde_json::json!({
|
||||
"name": "create_thread",
|
||||
"namespace": "akode_tui",
|
||||
"namespace": "codex_tui",
|
||||
"output": format!(
|
||||
"<codex_delegation>\n <source_thread_id>{creation_source}</source_thread_id>\n <input>Check <main> & report</input>\n</codex_delegation>"
|
||||
)
|
||||
@@ -2795,7 +2795,7 @@ async fn check_dynamic_tool_requests(
|
||||
thread_id: thread_id.clone(),
|
||||
turn_id: "turn-1".to_string(),
|
||||
call_id: "call-5".to_string(),
|
||||
namespace: Some("akode_tui".to_string()),
|
||||
namespace: Some("codex_tui".to_string()),
|
||||
tool: "send_message_to_thread".to_string(),
|
||||
arguments: serde_json::json!({
|
||||
"threadId": created_thread_id,
|
||||
@@ -2839,7 +2839,7 @@ async fn check_dynamic_tool_requests(
|
||||
turn["toolOutput"],
|
||||
serde_json::json!({
|
||||
"name": "send_message_to_thread",
|
||||
"namespace": "akode_tui",
|
||||
"namespace": "codex_tui",
|
||||
"output": format!(
|
||||
"<codex_delegation>\n <source_thread_id>{thread_id}</source_thread_id>\n <input>Follow <up> & report</input>\n</codex_delegation>"
|
||||
)
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
---
|
||||
source: tui/src/app/tests/background_exit_tests.rs
|
||||
assertion_line: 236
|
||||
expression: output
|
||||
---
|
||||
Disconnected from this task. Any running work continues.
|
||||
To reconnect, run:
|
||||
akode resume THREAD_ID
|
||||
Stop the current turn: run codex agents, select this task, and press f10.
|
||||
Stop the current turn: run akode agents, select this task, and press f10.
|
||||
Token usage so far: total=12 input=10 output=2
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
source: tui/src/app/tests/safety_buffering.rs
|
||||
assertion_line: 284
|
||||
assertion_line: 304
|
||||
expression: "context_snapshot::format_request_history_snapshot(\"The fork excludes the blocked turn and submits the selected rewrite.\",\n&requests, &ContextSnapshotOptions::default().rewrite_known_segments(),)"
|
||||
---
|
||||
Scenario: The fork excludes the blocked turn and submits the selected rewrite.
|
||||
@@ -15,7 +15,7 @@ Scenario: The fork excludes the blocked turn and submits the selected rewrite.
|
||||
[03] <COLLABORATION_MODE>
|
||||
[04] <tools>
|
||||
Deferred tool namespaces:
|
||||
- akode_tui: Manage Codex tasks available through the connected app server.
|
||||
- codex_tui: Manage Codex tasks available through the connected app server.
|
||||
</tools>
|
||||
02:message/user:
|
||||
<ENVIRONMENT_CONTEXT>
|
||||
@@ -32,7 +32,7 @@ Scenario: The fork excludes the blocked turn and submits the selected rewrite.
|
||||
[03] <COLLABORATION_MODE>
|
||||
[04] <tools>
|
||||
Deferred tool namespaces:
|
||||
- akode_tui: Manage Codex tasks available through the connected app server.
|
||||
- codex_tui: Manage Codex tasks available through the connected app server.
|
||||
</tools>
|
||||
02:message/user:
|
||||
<ENVIRONMENT_CONTEXT>
|
||||
|
||||
@@ -4121,7 +4121,7 @@ mod tests {
|
||||
.loader_overrides(akode_config::LoaderOverrides {
|
||||
user_config_path: selected_profile.then(|| profile.clone()),
|
||||
user_config_profile: selected_profile.then(|| "work".parse().unwrap()),
|
||||
..codex_config::LoaderOverrides::without_managed_config_for_tests()
|
||||
..akode_config::LoaderOverrides::without_managed_config_for_tests()
|
||||
})
|
||||
.cli_overrides(if cli {
|
||||
vec![
|
||||
|
||||
@@ -119,7 +119,7 @@ async fn selected_profile_provider_is_explicit() -> Result<()> {
|
||||
.loader_overrides(akode_config::LoaderOverrides {
|
||||
user_config_path: Some(profile_path),
|
||||
user_config_profile: Some("selected".parse()?),
|
||||
..codex_config::LoaderOverrides::without_managed_config_for_tests()
|
||||
..akode_config::LoaderOverrides::without_managed_config_for_tests()
|
||||
})
|
||||
.build()
|
||||
.await?;
|
||||
|
||||
@@ -128,7 +128,7 @@ async fn embedded_legacy_search_honors_shared_feature_requirements() -> Result<(
|
||||
)
|
||||
.loader_overrides(akode_config::LoaderOverrides {
|
||||
system_requirements_path: Some(requirements_path.clone()),
|
||||
..codex_config::LoaderOverrides::without_managed_config_for_tests()
|
||||
..akode_config::LoaderOverrides::without_managed_config_for_tests()
|
||||
})
|
||||
.build()
|
||||
.await?;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
---
|
||||
source: tui/src/bottom_pane/experimental_features_view_tests.rs
|
||||
assertion_line: 283
|
||||
expression: buffer_text(&buffer)
|
||||
---
|
||||
|
||||
@@ -8,7 +9,7 @@ expression: buffer_text(&buffer)
|
||||
only in new tasks or after restarting the aKode server.
|
||||
|
||||
|
||||
› [ ] System proxy Use macOS or Windows system proxy settings for Codex
|
||||
› [ ] System proxy Use macOS or Windows system proxy settings for aKode
|
||||
requests.
|
||||
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ pub(crate) enum StatusSurfacePreviewItem {
|
||||
impl StatusSurfacePreviewItem {
|
||||
fn placeholder(self) -> &'static str {
|
||||
match self {
|
||||
StatusSurfacePreviewItem::AppName => "codex",
|
||||
StatusSurfacePreviewItem::AppName => "akode",
|
||||
StatusSurfacePreviewItem::ProjectName => "my-project",
|
||||
StatusSurfacePreviewItem::ProjectRoot => "my-project",
|
||||
StatusSurfacePreviewItem::CurrentDir => "~/my-project/subdir",
|
||||
|
||||
@@ -174,7 +174,7 @@ pub(super) use toml::Value as TomlValue;
|
||||
|
||||
pub(super) fn chatwidget_snapshot_dir() -> PathBuf {
|
||||
let snapshot_file = akode_utils_cargo_bin::find_resource!(
|
||||
"src/chatwidget/snapshots/codex_tui__chatwidget__tests__chatwidget_tall.snap"
|
||||
"src/chatwidget/snapshots/akode_tui__chatwidget__tests__chatwidget_tall.snap"
|
||||
)
|
||||
.expect("snapshot file");
|
||||
snapshot_file
|
||||
@@ -189,7 +189,7 @@ macro_rules! assert_chatwidget_snapshot {
|
||||
settings.set_prepend_module_to_snapshot(false);
|
||||
settings.set_snapshot_path(crate::chatwidget::tests::chatwidget_snapshot_dir());
|
||||
settings.bind(|| {
|
||||
insta::assert_snapshot!(format!("codex_tui__chatwidget__tests__{}", $name), $value);
|
||||
insta::assert_snapshot!(format!("akode_tui__chatwidget__tests__{}", $name), $value);
|
||||
});
|
||||
}};
|
||||
($name:expr, $value:expr, @$snapshot:literal $(,)?) => {{
|
||||
@@ -198,7 +198,7 @@ macro_rules! assert_chatwidget_snapshot {
|
||||
settings.set_snapshot_path(crate::chatwidget::tests::chatwidget_snapshot_dir());
|
||||
settings.bind(|| {
|
||||
insta::assert_snapshot!(
|
||||
format!("codex_tui__chatwidget__tests__{}", $name),
|
||||
format!("akode_tui__chatwidget__tests__{}", $name),
|
||||
$value,
|
||||
@$snapshot
|
||||
);
|
||||
|
||||
@@ -276,7 +276,7 @@ async fn replayed_delegated_tool_output_is_attributed_without_seeding_composer_h
|
||||
let item = AppServerThreadItemPayload::FunctionCallOutput {
|
||||
id: "delegation-1".to_string(),
|
||||
name: "send_message_to_thread".to_string(),
|
||||
namespace: Some("akode_tui".to_string()),
|
||||
namespace: Some("codex_tui".to_string()),
|
||||
output: FunctionCallOutputBody::Text(
|
||||
concat!(
|
||||
"<codex_delegation>\n <source_thread_id>source-task</source_thread_id>\n <input>",
|
||||
|
||||
@@ -4533,6 +4533,19 @@ async fn status_line_default_akode_footer_snapshot() {
|
||||
terminal
|
||||
.draw(|f| chat.render(f.area(), f.buffer_mut()))
|
||||
.expect("draw default footer");
|
||||
// The gap between the left and the right group is blank: no stray ellipsis.
|
||||
let rendered = normalized_backend_snapshot(terminal.backend());
|
||||
let footer = rendered
|
||||
.lines()
|
||||
.find(|line| line.contains("ctx 31%"))
|
||||
.expect("footer row");
|
||||
let gap_end = footer.find("ctx 31%").expect("right group");
|
||||
if let Some(gap_start) = footer.find("(main)").map(|at| at + "(main)".len()) {
|
||||
assert!(
|
||||
footer[gap_start..gap_end].chars().all(|ch| ch == ' '),
|
||||
"footer gap at {width} columns must be blank: {footer:?}"
|
||||
);
|
||||
}
|
||||
assert_chatwidget_snapshot!(
|
||||
format!("status_line_default_akode_footer_{width}"),
|
||||
normalized_backend_snapshot(terminal.backend())
|
||||
|
||||
@@ -1240,7 +1240,7 @@ interrupt_message = false
|
||||
let rendered = render_stack_to_text(&stack);
|
||||
let requirements_source = (RequirementSource::LegacyManagedConfigTomlFromMdm).to_string();
|
||||
assert!(rendered.contains(&format!(
|
||||
"network_proxy: unix_sockets={{/tmp/blocked.sock=deny, /tmp/akode.sock=allow}} (source: {requirements_source})"
|
||||
"network_proxy: unix_sockets={{/tmp/akode.sock=allow, /tmp/blocked.sock=deny}} (source: {requirements_source})"
|
||||
)));
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ use uuid::Uuid;
|
||||
#[path = "dynamic_tools_response.rs"]
|
||||
mod response;
|
||||
|
||||
pub(crate) const NAMESPACE: &str = "akode_tui";
|
||||
pub(crate) const NAMESPACE: &str = "codex_tui";
|
||||
pub(crate) const DELEGATION_TOOLS: [&str; 3] =
|
||||
["create_thread", "send_message_to_thread", "fork_thread"];
|
||||
const DEFAULT_LIST_LIMIT: u32 = 10;
|
||||
|
||||
@@ -58,7 +58,7 @@ async fn test_server(
|
||||
"item": {
|
||||
"type": "DynamicToolCall",
|
||||
"id": "persisted-tool",
|
||||
"namespace": "akode_tui",
|
||||
"namespace": "codex_tui",
|
||||
"tool": "list_threads",
|
||||
"arguments": tool_arguments,
|
||||
"status": "completed",
|
||||
@@ -284,7 +284,7 @@ stream_max_retries = 0
|
||||
#[test]
|
||||
fn delegated_prompts_match_desktop_xml_contract() {
|
||||
let output = FunctionCallOutputBody::Text(delegated_prompt("thread-1", "Check status"));
|
||||
for namespace in ["akode_tui", "codex_app"] {
|
||||
for namespace in ["codex_tui", "codex_app"] {
|
||||
assert_eq!(
|
||||
parse_delegated_tool_output("send_message_to_thread", Some(namespace), &output),
|
||||
Some(("thread-1".to_string(), "Check status".to_string()))
|
||||
@@ -333,7 +333,7 @@ fn activity_metadata_is_retained_without_including_outputs() -> color_eyre::Resu
|
||||
"revisedPrompt": "a cat", "result": "image bytes"},
|
||||
{"type": "enteredReviewMode", "id": "review-1", "review": "review changes"},
|
||||
{"type": "functionCallOutput", "id": "delegation-1", "name": "send_message_to_thread",
|
||||
"namespace": "akode_tui", "output": delegated_prompt("source-2", "Follow <up> & report")}
|
||||
"namespace": "codex_tui", "output": delegated_prompt("source-2", "Follow <up> & report")}
|
||||
]
|
||||
}))?;
|
||||
|
||||
@@ -366,7 +366,7 @@ fn activity_metadata_is_retained_without_including_outputs() -> color_eyre::Resu
|
||||
"revisedPrompt": "a cat", "savedPath": null},
|
||||
{"type": "enteredReviewMode", "id": "review-1", "review": "review changes"},
|
||||
{"type": "functionCallOutput", "id": "delegation-1", "name": "send_message_to_thread",
|
||||
"namespace": "akode_tui", "codexDelegation": {
|
||||
"namespace": "codex_tui", "codexDelegation": {
|
||||
"sourceThreadId": "source-2", "input": "Follow <up> & report"
|
||||
}}
|
||||
])
|
||||
|
||||
@@ -94,7 +94,7 @@ async fn creation_attaches_to_original_task_and_survives_service_restart_scenari
|
||||
serde_json::from_value(json!({"url":"http://127.0.0.1:1/mcp"}))?;
|
||||
let mut servers = conflicting.mcp_servers.get().clone();
|
||||
servers.insert(
|
||||
"akode_tui".to_owned(),
|
||||
"codex_tui".to_owned(),
|
||||
akode_config::McpServerConfig::try_from(raw).map_err(color_eyre::eyre::Report::msg)?,
|
||||
);
|
||||
conflicting.mcp_servers.set(servers)?;
|
||||
|
||||
@@ -83,6 +83,30 @@ pub(crate) fn parse_model_ids(body: &Value) -> Vec<String> {
|
||||
ids
|
||||
}
|
||||
|
||||
/// Ids of the models a provider offers for free: an OpenRouter-style `:free` suffix, or a
|
||||
/// `pricing` object whose prompt and completion prices are both zero.
|
||||
pub(crate) fn parse_free_model_ids(body: &Value) -> Vec<String> {
|
||||
let is_zero = |value: Option<&Value>| match value {
|
||||
Some(Value::String(text)) => text.trim().parse::<f64>().is_ok_and(|price| price == 0.0),
|
||||
Some(Value::Number(number)) => number.as_f64().is_some_and(|price| price == 0.0),
|
||||
_ => false,
|
||||
};
|
||||
let mut free = Vec::new();
|
||||
for entry in body.get("data").and_then(Value::as_array).into_iter().flatten() {
|
||||
let Some(id) = entry.get("id").and_then(Value::as_str).map(str::trim) else {
|
||||
continue;
|
||||
};
|
||||
let pricing = entry.get("pricing");
|
||||
let zero_priced = pricing.is_some_and(|pricing| {
|
||||
is_zero(pricing.get("prompt")) && is_zero(pricing.get("completion"))
|
||||
});
|
||||
if (id.ends_with(":free") || zero_priced) && !free.iter().any(|known| known == id) {
|
||||
free.push(id.to_string());
|
||||
}
|
||||
}
|
||||
free
|
||||
}
|
||||
|
||||
fn connection_error(url: &str, err: &impl std::fmt::Display, api_key: Option<&str>) -> String {
|
||||
redact(&format!("Server non raggiungibile ({url}): {err}"), api_key)
|
||||
}
|
||||
@@ -92,6 +116,8 @@ fn connection_error(url: &str, err: &impl std::fmt::Display, api_key: Option<&st
|
||||
pub(crate) struct ModelList {
|
||||
pub base_url: String,
|
||||
pub models: Vec<String>,
|
||||
/// Models that cost nothing (see [`parse_free_model_ids`]).
|
||||
pub free: Vec<String>,
|
||||
}
|
||||
|
||||
/// `GET {base}/models`; when `base` has no path, `{base}/v1/models` is tried too.
|
||||
@@ -147,9 +173,11 @@ pub(crate) async fn fetch_models(
|
||||
last_error = "Il server non ha elencato nessun modello.".to_string();
|
||||
continue;
|
||||
}
|
||||
let free = parse_free_model_ids(&body);
|
||||
return Ok(ModelList {
|
||||
base_url: candidate,
|
||||
models,
|
||||
free,
|
||||
});
|
||||
}
|
||||
Err(last_error)
|
||||
@@ -278,6 +306,27 @@ mod tests {
|
||||
assert!(parse_model_ids(&serde_json::json!({"data": []})).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn finds_free_models_by_suffix_or_zero_pricing() {
|
||||
let body = serde_json::json!({
|
||||
"data": [
|
||||
{"id": "meta-llama/llama-3.3-70b-instruct:free", "pricing": {"prompt": "0.0000001", "completion": "0"}},
|
||||
{"id": "openrouter/zero", "pricing": {"prompt": "0", "completion": "0"}},
|
||||
{"id": "local-number", "pricing": {"prompt": 0, "completion": 0.0}},
|
||||
{"id": "anthropic/paid", "pricing": {"prompt": "0.000003", "completion": "0.000015"}},
|
||||
{"id": "no-pricing"},
|
||||
],
|
||||
});
|
||||
assert_eq!(
|
||||
parse_free_model_ids(&body),
|
||||
vec![
|
||||
"meta-llama/llama-3.3-70b-instruct:free",
|
||||
"openrouter/zero",
|
||||
"local-number"
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validates_base_urls() {
|
||||
assert_eq!(
|
||||
|
||||
@@ -51,6 +51,27 @@ const THEME_SIDE_BY_SIDE_MIN_WIDTH: u16 = 70;
|
||||
const MAX_MODEL_ROWS: usize = 8;
|
||||
const MANUAL_MODEL_LABEL: &str = "Inserisci il nome a mano…";
|
||||
|
||||
/// Models shown for the current filter: case-insensitive substring match on the id, and
|
||||
/// only the free ones when `free_only` is set.
|
||||
fn visible_models<'a>(
|
||||
models: &'a [String],
|
||||
free: &[String],
|
||||
filter: &str,
|
||||
free_only: bool,
|
||||
) -> Vec<&'a String> {
|
||||
let needle = filter.trim().to_lowercase();
|
||||
models
|
||||
.iter()
|
||||
.filter(|model| !free_only || free.contains(model))
|
||||
.filter(|model| needle.is_empty() || model.to_lowercase().contains(&needle))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Long lists (e.g. OpenRouter's hundreds of models) get a search field.
|
||||
fn model_list_is_searchable(models: &[String]) -> bool {
|
||||
models.len() > MAX_MODEL_ROWS
|
||||
}
|
||||
|
||||
/// Built-in local providers offered by the setup.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum ProviderChoice {
|
||||
@@ -135,7 +156,14 @@ enum ModelsState {
|
||||
Loading,
|
||||
Loaded {
|
||||
models: Vec<String>,
|
||||
/// Models the provider offers for free (`:free` ids or zero pricing).
|
||||
free: Vec<String>,
|
||||
/// Index into the visible (filtered) list; one past its end is manual entry.
|
||||
selected: usize,
|
||||
/// Type-to-filter text, used when the list is longer than [`MAX_MODEL_ROWS`].
|
||||
filter: String,
|
||||
/// Show only the free models.
|
||||
free_only: bool,
|
||||
},
|
||||
Failed(String),
|
||||
}
|
||||
@@ -275,12 +303,18 @@ impl SetupWizard {
|
||||
pub(crate) fn is_text_entry_active(&self) -> bool {
|
||||
match self.page {
|
||||
Page::Endpoint => self.form_focus < 3,
|
||||
Page::Model => self.model_input_active(),
|
||||
Page::Model => self.model_input_active() || self.model_filter_active(),
|
||||
Page::WebSearch => self.searx_focus == 0,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// The model list takes typed text as a filter.
|
||||
fn model_filter_active(&self) -> bool {
|
||||
!self.manual_active
|
||||
&& matches!(&self.models, ModelsState::Loaded { models, .. } if model_list_is_searchable(models))
|
||||
}
|
||||
|
||||
fn model_input_active(&self) -> bool {
|
||||
self.manual_active || matches!(self.models, ModelsState::Failed(_))
|
||||
}
|
||||
@@ -308,7 +342,10 @@ impl SetupWizard {
|
||||
.unwrap_or(0);
|
||||
self.models = ModelsState::Loaded {
|
||||
models: list.models,
|
||||
free: list.free,
|
||||
selected,
|
||||
filter: String::new(),
|
||||
free_only: false,
|
||||
};
|
||||
}
|
||||
Err(error) => self.models = ModelsState::Failed(error),
|
||||
@@ -597,6 +634,17 @@ impl SetupWizard {
|
||||
}
|
||||
|
||||
fn handle_model_key(&mut self, key: KeyEvent) {
|
||||
if key.code == KeyCode::Esc
|
||||
&& !self.manual_active
|
||||
&& let ModelsState::Loaded {
|
||||
filter, selected, ..
|
||||
} = &mut self.models
|
||||
&& !filter.is_empty()
|
||||
{
|
||||
filter.clear();
|
||||
*selected = 0;
|
||||
return;
|
||||
}
|
||||
if key.code == KeyCode::Esc {
|
||||
if self.manual_active {
|
||||
self.manual_active = false;
|
||||
@@ -616,14 +664,52 @@ impl SetupWizard {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if let ModelsState::Loaded { models, selected } = &mut self.models {
|
||||
let count = models.len() + 1;
|
||||
if let ModelsState::Loaded {
|
||||
models,
|
||||
free,
|
||||
selected,
|
||||
filter,
|
||||
free_only,
|
||||
} = &mut self.models
|
||||
{
|
||||
let searchable = model_list_is_searchable(models);
|
||||
if searchable {
|
||||
let typed = !key
|
||||
.modifiers
|
||||
.intersects(KeyModifiers::CONTROL | KeyModifiers::ALT);
|
||||
let changed = match key.code {
|
||||
KeyCode::Char(ch) if typed => {
|
||||
filter.push(ch);
|
||||
true
|
||||
}
|
||||
KeyCode::Backspace => filter.pop().is_some(),
|
||||
KeyCode::Tab if !free.is_empty() => {
|
||||
*free_only = !*free_only;
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
if changed {
|
||||
*selected = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
let visible = visible_models(models, free, filter, *free_only);
|
||||
let count = visible.len() + 1;
|
||||
let moved = match key.code {
|
||||
KeyCode::Up | KeyCode::Char('k') => {
|
||||
KeyCode::Up => {
|
||||
*selected = (*selected + count - 1) % count;
|
||||
true
|
||||
}
|
||||
KeyCode::Down | KeyCode::Char('j') => {
|
||||
KeyCode::Down => {
|
||||
*selected = (*selected + 1) % count;
|
||||
true
|
||||
}
|
||||
KeyCode::Char('k') if !searchable => {
|
||||
*selected = (*selected + count - 1) % count;
|
||||
true
|
||||
}
|
||||
KeyCode::Char('j') if !searchable => {
|
||||
*selected = (*selected + 1) % count;
|
||||
true
|
||||
}
|
||||
@@ -641,9 +727,9 @@ impl SetupWizard {
|
||||
return;
|
||||
}
|
||||
if key.code == KeyCode::Enter {
|
||||
match models.get(*selected) {
|
||||
match visible.get(*selected) {
|
||||
Some(model) => {
|
||||
let model = model.clone();
|
||||
let model = (*model).clone();
|
||||
self.start_test(model);
|
||||
}
|
||||
None => self.manual_active = true,
|
||||
@@ -985,11 +1071,34 @@ impl SetupWizard {
|
||||
Page::Model if self.model_input_active() => {
|
||||
vec![("invio", "conferma"), ("esc", "indietro")]
|
||||
}
|
||||
Page::Model => vec![
|
||||
("↑/↓", "scegli"),
|
||||
("invio", "conferma"),
|
||||
("esc", "indietro"),
|
||||
],
|
||||
Page::Model => match &self.models {
|
||||
ModelsState::Loaded {
|
||||
models,
|
||||
free,
|
||||
filter,
|
||||
..
|
||||
} if model_list_is_searchable(models) => {
|
||||
let mut hints = vec![("↑/↓", "scegli")];
|
||||
if !free.is_empty() {
|
||||
hints.push(("tab", "gratuiti"));
|
||||
}
|
||||
hints.push(("invio", "conferma"));
|
||||
hints.push((
|
||||
"esc",
|
||||
if filter.is_empty() {
|
||||
"indietro"
|
||||
} else {
|
||||
"pulisci"
|
||||
},
|
||||
));
|
||||
hints
|
||||
}
|
||||
_ => vec![
|
||||
("↑/↓", "scegli"),
|
||||
("invio", "conferma"),
|
||||
("esc", "indietro"),
|
||||
],
|
||||
},
|
||||
Page::Test => match self.test {
|
||||
CheckState::Ok => vec![("invio", "continua"), ("esc", "indietro")],
|
||||
CheckState::Failed(_) => {
|
||||
@@ -1110,7 +1219,13 @@ impl SetupWizard {
|
||||
width,
|
||||
));
|
||||
}
|
||||
ModelsState::Loaded { models, selected } => {
|
||||
ModelsState::Loaded {
|
||||
models,
|
||||
free,
|
||||
selected,
|
||||
filter,
|
||||
free_only,
|
||||
} => {
|
||||
if self.manual_active {
|
||||
lines.push(field_line(
|
||||
"Modello",
|
||||
@@ -1121,14 +1236,35 @@ impl SetupWizard {
|
||||
width,
|
||||
));
|
||||
} else {
|
||||
let count = models.len() + 1;
|
||||
let visible = visible_models(models, free, filter, *free_only);
|
||||
if model_list_is_searchable(models) {
|
||||
let mut search = vec![
|
||||
"Cerca: ".dim(),
|
||||
filter.clone().into(),
|
||||
"▏".cyan(),
|
||||
];
|
||||
if !free.is_empty() {
|
||||
search.push(" ".into());
|
||||
search.push(if *free_only {
|
||||
"[x] solo gratuiti (tab)".cyan()
|
||||
} else {
|
||||
"[ ] solo gratuiti (tab)".dim()
|
||||
});
|
||||
}
|
||||
lines.push(truncate_line(Line::from(search), w));
|
||||
if visible.is_empty() {
|
||||
lines.push(Line::from("Nessun modello corrisponde.".dim()));
|
||||
}
|
||||
}
|
||||
let count = visible.len() + 1;
|
||||
let start = selected
|
||||
.saturating_sub(MAX_MODEL_ROWS - 1)
|
||||
.min(count.saturating_sub(MAX_MODEL_ROWS));
|
||||
let end = (start + MAX_MODEL_ROWS).min(count);
|
||||
for index in start..end {
|
||||
let label =
|
||||
models.get(index).map_or(MANUAL_MODEL_LABEL, String::as_str);
|
||||
let label = visible
|
||||
.get(index)
|
||||
.map_or(MANUAL_MODEL_LABEL, |model| model.as_str());
|
||||
lines.push(option_line(
|
||||
index + 1,
|
||||
label,
|
||||
@@ -1137,9 +1273,21 @@ impl SetupWizard {
|
||||
w,
|
||||
));
|
||||
}
|
||||
if count > MAX_MODEL_ROWS {
|
||||
lines
|
||||
.push(Line::from(format!("{} di {count}", selected + 1).dim()));
|
||||
if count > MAX_MODEL_ROWS || visible.len() < models.len() {
|
||||
let mut position = format!("{} di {count}", selected + 1);
|
||||
if visible.len() < models.len() {
|
||||
let noun = if visible.len() == 1 {
|
||||
"modello"
|
||||
} else {
|
||||
"modelli"
|
||||
};
|
||||
position.push_str(&format!(
|
||||
" · {} {noun} su {}",
|
||||
visible.len(),
|
||||
models.len()
|
||||
));
|
||||
}
|
||||
lines.push(truncate_line(Line::from(position.dim()), w));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,6 +156,7 @@ fn model_list_screen() {
|
||||
"qwen3-coder-30b-a3b".to_string(),
|
||||
"gemma-3-4b-it".to_string(),
|
||||
],
|
||||
free: Vec::new(),
|
||||
})));
|
||||
snapshot_all_widths("setup_model_list", &wizard, 14);
|
||||
// The last row switches to manual entry.
|
||||
@@ -308,3 +309,55 @@ fn saving_failure_can_retry() {
|
||||
insta::assert_snapshot!("setup_save_failed_80", render(&wizard, 80, 12));
|
||||
assert!(!render(&wizard, 80, 12).contains(SECRET));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn long_model_list_filters_by_text_and_free_toggle() {
|
||||
let mut wizard = endpoint_wizard();
|
||||
wizard.base_url = "https://openrouter.ai/api/v1".to_string();
|
||||
wizard.start_models();
|
||||
let mut models: Vec<String> = (0..300).map(|i| format!("vendor/model-{i:03}")).collect();
|
||||
models.push("qwen/qwen3-coder:free".to_string());
|
||||
models.push("google/gemma-3-27b-it:free".to_string());
|
||||
models.push("qwen/qwen3-coder".to_string());
|
||||
wizard.apply(Outcome::Models(Ok(setup_net::ModelList {
|
||||
base_url: "https://openrouter.ai/api/v1".to_string(),
|
||||
models,
|
||||
free: vec![
|
||||
"qwen/qwen3-coder:free".to_string(),
|
||||
"google/gemma-3-27b-it:free".to_string(),
|
||||
],
|
||||
})));
|
||||
assert!(wizard.is_text_entry_active(), "typed text goes to the filter");
|
||||
snapshot_all_widths("setup_model_search_empty", &wizard, 20);
|
||||
|
||||
// `j`/`k` are text here, not navigation.
|
||||
type_text(&mut wizard, "qwen");
|
||||
snapshot_all_widths("setup_model_search_qwen", &wizard, 20);
|
||||
wizard.handle_key_event(key(KeyCode::Tab));
|
||||
snapshot_all_widths("setup_model_search_qwen_free", &wizard, 20);
|
||||
wizard.handle_key_event(key(KeyCode::Enter));
|
||||
assert_eq!(wizard.page, Page::Test);
|
||||
assert_eq!(wizard.model, "qwen/qwen3-coder:free");
|
||||
|
||||
// Esc clears the filter before leaving the page; Backspace edits it.
|
||||
wizard.start_models();
|
||||
wizard.apply(Outcome::Models(Ok(setup_net::ModelList {
|
||||
base_url: "https://openrouter.ai/api/v1".to_string(),
|
||||
models: (0..20).map(|i| format!("m-{i}")).collect(),
|
||||
free: Vec::new(),
|
||||
})));
|
||||
type_text(&mut wizard, "zz");
|
||||
let rendered = render(&wizard, 80, 16);
|
||||
assert!(rendered.contains("Nessun modello corrisponde."), "{rendered}");
|
||||
assert!(!rendered.contains("solo gratuiti"), "no toggle without free models");
|
||||
wizard.handle_key_event(key(KeyCode::Backspace));
|
||||
wizard.handle_key_event(key(KeyCode::Esc));
|
||||
assert_eq!(wizard.page, Page::Model);
|
||||
let ModelsState::Loaded { filter, .. } = &wizard.models else {
|
||||
panic!("models stay loaded");
|
||||
};
|
||||
assert!(filter.is_empty());
|
||||
wizard.handle_key_event(key(KeyCode::Down));
|
||||
wizard.handle_key_event(key(KeyCode::Enter));
|
||||
assert_eq!(wizard.model, "m-1");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
---
|
||||
source: tui/src/onboarding/setup_wizard_tests.rs
|
||||
expression: rendered
|
||||
---
|
||||
|
||||
Modello passo 4 di 6
|
||||
|
||||
Server: https://openrouter.ai/api/v1
|
||||
|
||||
Cerca: ▏ [ ] solo gratuiti (tab)
|
||||
› 1. vendor/model-000
|
||||
2. vendor/model-001
|
||||
3. vendor/model-002
|
||||
4. vendor/model-003
|
||||
5. vendor/model-004
|
||||
6. vendor/model-005
|
||||
7. vendor/model-006
|
||||
8. vendor/model-007
|
||||
1 di 304
|
||||
|
||||
↑/↓ scegli · tab gratuiti · invio conferma · esc indietro
|
||||
@@ -0,0 +1,21 @@
|
||||
---
|
||||
source: tui/src/onboarding/setup_wizard_tests.rs
|
||||
expression: rendered
|
||||
---
|
||||
|
||||
Modello passo 4 di 6
|
||||
|
||||
Server: https://openrouter.ai/api/v1
|
||||
|
||||
Cerca: ▏ [ ] solo gratuiti (tab)
|
||||
› 1. vendor/model-000
|
||||
2. vendor/model-001
|
||||
3. vendor/model-002
|
||||
4. vendor/model-003
|
||||
5. vendor/model-004
|
||||
6. vendor/model-005
|
||||
7. vendor/model-006
|
||||
8. vendor/model-007
|
||||
1 di 304
|
||||
|
||||
↑/↓ scegli · tab gratuiti · invio conferma · esc indiet…
|
||||
@@ -0,0 +1,21 @@
|
||||
---
|
||||
source: tui/src/onboarding/setup_wizard_tests.rs
|
||||
expression: rendered
|
||||
---
|
||||
|
||||
Modello passo 4 di 6
|
||||
|
||||
Server: https://openrouter.ai/api/v1
|
||||
|
||||
Cerca: ▏ [ ] solo gratuiti (tab)
|
||||
› 1. vendor/model-000
|
||||
2. vendor/model-001
|
||||
3. vendor/model-002
|
||||
4. vendor/model-003
|
||||
5. vendor/model-004
|
||||
6. vendor/model-005
|
||||
7. vendor/model-006
|
||||
8. vendor/model-007
|
||||
1 di 304
|
||||
|
||||
↑/↓ scegli · tab gratuiti · invio conferma · esc indietro
|
||||
@@ -0,0 +1,16 @@
|
||||
---
|
||||
source: tui/src/onboarding/setup_wizard_tests.rs
|
||||
expression: rendered
|
||||
---
|
||||
|
||||
Modello passo 4 di 6
|
||||
|
||||
Server: https://openrouter.ai/api/v1
|
||||
|
||||
Cerca: qwen▏ [ ] solo gratuiti (tab)
|
||||
› 1. qwen/qwen3-coder:free
|
||||
2. qwen/qwen3-coder
|
||||
3. Inserisci il nome a mano…
|
||||
1 di 3 · 2 modelli su 303
|
||||
|
||||
↑/↓ scegli · tab gratuiti · invio conferma · esc pulisci
|
||||
@@ -0,0 +1,16 @@
|
||||
---
|
||||
source: tui/src/onboarding/setup_wizard_tests.rs
|
||||
expression: rendered
|
||||
---
|
||||
|
||||
Modello passo 4 di 6
|
||||
|
||||
Server: https://openrouter.ai/api/v1
|
||||
|
||||
Cerca: qwen▏ [ ] solo gratuiti (tab)
|
||||
› 1. qwen/qwen3-coder:free
|
||||
2. qwen/qwen3-coder
|
||||
3. Inserisci il nome a mano…
|
||||
1 di 3 · 2 modelli su 303
|
||||
|
||||
↑/↓ scegli · tab gratuiti · invio conferma · esc pulisci
|
||||
@@ -0,0 +1,16 @@
|
||||
---
|
||||
source: tui/src/onboarding/setup_wizard_tests.rs
|
||||
expression: rendered
|
||||
---
|
||||
|
||||
Modello passo 4 di 6
|
||||
|
||||
Server: https://openrouter.ai/api/v1
|
||||
|
||||
Cerca: qwen▏ [ ] solo gratuiti (tab)
|
||||
› 1. qwen/qwen3-coder:free
|
||||
2. qwen/qwen3-coder
|
||||
3. Inserisci il nome a mano…
|
||||
1 di 3 · 2 modelli su 303
|
||||
|
||||
↑/↓ scegli · tab gratuiti · invio conferma · esc pulisci
|
||||
@@ -0,0 +1,15 @@
|
||||
---
|
||||
source: tui/src/onboarding/setup_wizard_tests.rs
|
||||
expression: rendered
|
||||
---
|
||||
|
||||
Modello passo 4 di 6
|
||||
|
||||
Server: https://openrouter.ai/api/v1
|
||||
|
||||
Cerca: qwen▏ [x] solo gratuiti (tab)
|
||||
› 1. qwen/qwen3-coder:free
|
||||
2. Inserisci il nome a mano…
|
||||
1 di 2 · 1 modello su 303
|
||||
|
||||
↑/↓ scegli · tab gratuiti · invio conferma · esc pulisci
|
||||
@@ -0,0 +1,15 @@
|
||||
---
|
||||
source: tui/src/onboarding/setup_wizard_tests.rs
|
||||
expression: rendered
|
||||
---
|
||||
|
||||
Modello passo 4 di 6
|
||||
|
||||
Server: https://openrouter.ai/api/v1
|
||||
|
||||
Cerca: qwen▏ [x] solo gratuiti (tab)
|
||||
› 1. qwen/qwen3-coder:free
|
||||
2. Inserisci il nome a mano…
|
||||
1 di 2 · 1 modello su 303
|
||||
|
||||
↑/↓ scegli · tab gratuiti · invio conferma · esc pulisci
|
||||
@@ -0,0 +1,15 @@
|
||||
---
|
||||
source: tui/src/onboarding/setup_wizard_tests.rs
|
||||
expression: rendered
|
||||
---
|
||||
|
||||
Modello passo 4 di 6
|
||||
|
||||
Server: https://openrouter.ai/api/v1
|
||||
|
||||
Cerca: qwen▏ [x] solo gratuiti (tab)
|
||||
› 1. qwen/qwen3-coder:free
|
||||
2. Inserisci il nome a mano…
|
||||
1 di 2 · 1 modello su 303
|
||||
|
||||
↑/↓ scegli · tab gratuiti · invio conferma · esc pulisci
|
||||
@@ -17,7 +17,7 @@ async fn only_direct_launch_choices_override_saved_permissions() -> color_eyre::
|
||||
.loader_overrides(akode_config::LoaderOverrides {
|
||||
user_config_path: Some(AbsolutePathBuf::try_from(profile)?),
|
||||
user_config_profile: Some("work".parse()?),
|
||||
..codex_config::LoaderOverrides::without_managed_config_for_tests()
|
||||
..akode_config::LoaderOverrides::without_managed_config_for_tests()
|
||||
});
|
||||
let config = builder.clone().build().await?;
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user