aKode fase 3: provider locali, chiavi per provider, modelli dal server, SearXNG
- Provider: rimossi openai, Bedrock e GCP integrati e ogni fallback a OpenAI;
restano ollama, lmstudio e i provider personalizzati. Senza provider, exec e
TUI mostrano come configurarlo.
- Chiave per provider: api_key = "keyring", provider_api_key_store =
auto|keyring|file (fallback su file 0600 / ACL Windows); `codex login
--provider <id> --with-api-key`, `logout --provider`; login status e doctor
mostrano dove sta la chiave senza rivelarla.
- Modelli letti da GET {base_url}/models; contesto da config, poi dal server
(/props, meta.n_ctx), poi 32768; apply_patch come tool function; niente tool
ospitati; niente piu' avviso "metadata not found".
- Unione dei soli messaggi system/developer iniziali in un unico system;
quelli successivi restano al loro posto come user (cache del server
preservata: turno N prefisso esatto del turno N+1).
- Modelli ausiliari (memorie, guardian-v2) = modello di sessione se il
preferito gpt-* non e' nel catalogo.
- Ricerca web: crate web-tools, backend SearXNG con web_search e web_fetch
(protezione SSRF); senza backend nessuno strumento web.
- Skill: rimossa openai-docs; skill-installer punta a git.difonzo.net.
- apply_patch accetta gli header @@ -a,b +c,d @@ dei diff unificati.
- Rimossi resti: request_plugin_install, AppsInstructions, --cyber-access-program,
URL updater/realtime predefiniti.
- Fix: importazione sessioni con provider vuoto.
- Istruzioni di sistema invariate. Test: cancellati solo quelli del codice
rimosso, test di sicurezza adattati; restano solo fallimenti d'ambiente.
- Prova reale su imeAI + SearXNG: risposta, modifica file, web_search,
cache riusata, connessioni solo verso .25 e .57.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -110,9 +110,35 @@ impl MockResponsesConfig {
|
||||
provider_config,
|
||||
extra_config,
|
||||
} = self;
|
||||
let root_config = root_config.join("\n");
|
||||
let provider_config = provider_config.join("\n");
|
||||
let mut root_config = root_config.join("\n");
|
||||
let mut provider_config = provider_config.join("\n");
|
||||
let extra_config = extra_config.join("\n");
|
||||
// aKode providers without a catalog URL synthesize local metadata; tests keep the
|
||||
// bundled catalog the removed built-in defaults provided (unless they configure one).
|
||||
if !root_config.contains("model_catalog_json")
|
||||
&& !extra_config.contains("model_catalog_json")
|
||||
&& !provider_config.contains("model_catalog_url")
|
||||
{
|
||||
root_config.push('\n');
|
||||
root_config.push_str(&bundled_model_catalog_config(codex_home)?);
|
||||
}
|
||||
// Upstream custom providers offered hosted web search by default; aKode makes it an
|
||||
// explicit provider capability, so the mock provider opts in to keep request shapes.
|
||||
// Upstream also gave providers named "OpenAI" remote compaction V2 by name; aKode
|
||||
// requires the explicit capability.
|
||||
if !provider_config.contains("capabilities") && !extra_config.contains("capabilities") {
|
||||
if provider_name == "OpenAI" {
|
||||
provider_config.push_str(
|
||||
"\ncapabilities = { hosted_web_search = true, remote_compaction = \"v2\" }",
|
||||
);
|
||||
} else {
|
||||
provider_config.push_str("\ncapabilities = { hosted_web_search = true }");
|
||||
}
|
||||
}
|
||||
// Request-shape tests keep the upstream instruction layout; merging has its own tests.
|
||||
if !provider_config.contains("merge_system_messages") {
|
||||
provider_config.push_str("\nmerge_system_messages = false");
|
||||
}
|
||||
let feature_entries = features
|
||||
.into_iter()
|
||||
.map(|(feature, enabled)| {
|
||||
@@ -156,6 +182,23 @@ stream_max_retries = 0
|
||||
}
|
||||
}
|
||||
|
||||
/// Copy the bundled model catalog into `codex_home` and return the root-level
|
||||
/// `model_catalog_json = ...` line that selects it.
|
||||
///
|
||||
/// aKode has no default provider and no bundled catalog seed, so tests that start threads
|
||||
/// from a hand-written config (and relied on the removed defaults) opt in explicitly.
|
||||
pub fn bundled_model_catalog_config(codex_home: &Path) -> std::io::Result<String> {
|
||||
let catalog = codex_home.join(crate::models_cache::HARNESS_CATALOG_FILE);
|
||||
std::fs::write(
|
||||
&catalog,
|
||||
include_str!("../../../models-manager/models.json"),
|
||||
)?;
|
||||
Ok(format!(
|
||||
"model_catalog_json = {}\n",
|
||||
serde_json::to_string(&catalog.display().to_string())?
|
||||
))
|
||||
}
|
||||
|
||||
pub fn write_mock_responses_config_toml(
|
||||
codex_home: &Path,
|
||||
server_uri: &str,
|
||||
|
||||
@@ -12,6 +12,7 @@ mod test_app_server;
|
||||
|
||||
use codex_app_server_protocol::JSONRPCResponse;
|
||||
pub use config::MockResponsesConfig;
|
||||
pub use config::bundled_model_catalog_config;
|
||||
pub use config::write_mock_responses_config_toml;
|
||||
pub use config::write_mock_responses_config_toml_with_chatgpt_base_url;
|
||||
pub use core_test_support::PathBufExt;
|
||||
|
||||
@@ -125,12 +125,50 @@ pub async fn write_models_cache_with_models(
|
||||
let cache = codex_model_provider::test_support::models_cache_entry(
|
||||
&config.model_provider,
|
||||
auth.as_ref(),
|
||||
models,
|
||||
models.clone(),
|
||||
);
|
||||
let cache_path = codex_home.join("models_cache.json");
|
||||
std::fs::write(cache_path, serde_json::to_string_pretty(&cache)?)
|
||||
std::fs::write(cache_path, serde_json::to_string_pretty(&cache)?)?;
|
||||
// aKode: providers without `model_catalog_url` never read `models_cache.json` (they
|
||||
// use an explicit catalog or the provider's `/models` listing). Keep the cached
|
||||
// models authoritative, as they were upstream, by serving them as the explicit
|
||||
// catalog — replacing the bundled one `MockResponsesConfig` installs by default.
|
||||
if config.model_provider.model_catalog_url.is_none() {
|
||||
let config_path = codex_home.join("config.toml");
|
||||
let config_text = std::fs::read_to_string(&config_path).unwrap_or_default();
|
||||
let harness_catalog = codex_home.join(HARNESS_CATALOG_FILE);
|
||||
// Upstream merged cached models over the bundled catalog by slug.
|
||||
let mut catalog = serde_json::from_str::<codex_protocol::openai_models::ModelsResponse>(
|
||||
include_str!("../../../models-manager/models.json"),
|
||||
)?
|
||||
.models;
|
||||
for model in models {
|
||||
match catalog
|
||||
.iter()
|
||||
.position(|existing| existing.slug == model.slug)
|
||||
{
|
||||
Some(index) => catalog[index] = model,
|
||||
None => catalog.push(model),
|
||||
}
|
||||
}
|
||||
if config_text.contains(HARNESS_CATALOG_FILE) && harness_catalog.exists() {
|
||||
std::fs::write(
|
||||
harness_catalog,
|
||||
serde_json::to_string_pretty(&serde_json::json!({ "models": catalog }))?,
|
||||
)?;
|
||||
} else if !config_text.contains("model_catalog_json") {
|
||||
if !config_path.exists() {
|
||||
std::fs::write(&config_path, "")?;
|
||||
}
|
||||
write_model_catalog_json(codex_home, catalog)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Catalog file `MockResponsesConfig::write` installs unless a test configures one.
|
||||
pub(crate) const HARNESS_CATALOG_FILE: &str = "test-models.json";
|
||||
|
||||
/// Write `models` as a `model_catalog_json` catalog and point `config.toml` at it.
|
||||
///
|
||||
/// API-key sessions without a provider model catalog URL never read `models_cache.json`, so
|
||||
@@ -142,7 +180,12 @@ pub fn write_model_catalog_json(codex_home: &Path, models: Vec<ModelInfo>) -> st
|
||||
serde_json::to_string_pretty(&serde_json::json!({ "models": models }))?,
|
||||
)?;
|
||||
let config_path = codex_home.join("config.toml");
|
||||
let config = std::fs::read_to_string(&config_path)?;
|
||||
// Replace the default catalog `MockResponsesConfig::write` may have installed.
|
||||
let config = std::fs::read_to_string(&config_path)?
|
||||
.lines()
|
||||
.filter(|line| !line.trim_start().starts_with("model_catalog_json"))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
std::fs::write(
|
||||
&config_path,
|
||||
format!(
|
||||
|
||||
@@ -1401,20 +1401,6 @@ impl TestAppServer {
|
||||
self.send_login_account_request(params).await
|
||||
}
|
||||
|
||||
/// Send an `account/login/start` JSON-RPC request for managed Amazon Bedrock login.
|
||||
pub async fn send_login_account_amazon_bedrock_request(
|
||||
&mut self,
|
||||
api_key: &str,
|
||||
region: &str,
|
||||
) -> anyhow::Result<i64> {
|
||||
let params = serde_json::json!({
|
||||
"type": "amazonBedrock",
|
||||
"apiKey": api_key,
|
||||
"region": region,
|
||||
});
|
||||
self.send_request("account/login/start", Some(params)).await
|
||||
}
|
||||
|
||||
/// Send an `account/login/cancel` JSON-RPC request.
|
||||
pub async fn send_cancel_login_account_request(
|
||||
&mut self,
|
||||
|
||||
Reference in New Issue
Block a user