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:
andrea.difonzo
2026-11-11 02:11:45 +01:00
parent 9e33707b8e
commit e39aae0085
545 changed files with 9742 additions and 24503 deletions

View File

@@ -93,7 +93,8 @@ async fn create_and_patch_gateway_providers_without_changing_the_default() -> Re
.find(|p| p["id"] == "team-gateway"),
Some(&expected)
);
assert_eq!(after["defaultProviderId"], "openai");
// aKode: there is no default (`openai`) provider when none is configured.
assert_eq!(after["defaultProviderId"], "");
let persisted: Value = toml::from_str(&before)?;
assert_eq!(
persisted["model_providers"]["team-gateway"],
@@ -145,11 +146,8 @@ async fn custom_provider_edits_preserve_other_fields_and_respect_policy() -> Res
json!({"name": "Changed"}),
"configLayerReadonly",
),
(
"openai",
json!({"name": "Changed"}),
"configValidationError",
),
// aKode: `openai` is no longer a built-in provider, so it is an unknown id here.
("openai", json!({"name": "Changed"}), "configPathNotFound"),
("external", json!({"envKey": null}), "configValidationError"),
(
"basic",
@@ -163,7 +161,6 @@ async fn custom_provider_edits_preserve_other_fields_and_respect_policy() -> Res
"configValidationError",
),
("ollama", json!({}), "configValidationError"),
("gcp", json!({}), "configValidationError"),
] {
patch["type"] = json!("customGateway");
patch["providerId"] = json!(id);
@@ -191,177 +188,3 @@ async fn custom_provider_edits_preserve_other_fields_and_respect_policy() -> Res
assert_eq!(persisted, expected);
Ok(())
}
#[tokio::test]
async fn custom_provider_writes_reject_builtin_auth_names_and_preserve_existing_ids() -> Result<()>
{
let home = TempDir::new()?;
let config_path = home.path().join("config.toml");
let ids = [r"team\gpu", "corp.gateway", r#"team"gpu"#];
let mut providers = json!({});
for id in ids {
providers[id] = json!({"name":"Amazon Bedrock", "base_url":"https://old.example.test"});
}
std::fs::write(
&config_path,
toml::to_string(&json!({"model_providers":providers}))?,
)?;
let mut server = TestAppServer::builder()
.with_codex_home(home.path())
.with_env_overrides(CLEARED_AUTH_ENV)
.build_initialized()
.await?;
let new_url = "https://new.example.test";
for (provider_id, mut settings) in [
(None, json!({"name": "OpenAI", "baseUrl": new_url})),
(
None,
json!({"name": " Amazon Bedrock ", "baseUrl": new_url}),
),
(Some(ids[0]), json!({"name": "Amazon Bedrock Runtime"})),
(Some(ids[0]), json!({"name": "Google Cloud Vertex AI"})),
(Some(ids[0]), json!({"baseUrl": new_url})),
(Some(ids[0]), json!({"name":"Renamed", "envKey":null})),
] {
settings["type"] = json!("customGateway");
settings["providerId"] = json!(provider_id);
let request = server
.send_request(
"modelProvider/config/write",
Some(json!({"settings":settings})),
)
.await?;
let error = server
.read_stream_until_error_message(RequestId::Integer(request))
.await?;
assert_eq!(
error.error.data,
Some(json!({"config_write_error_code":"configValidationError"}))
);
}
for id in ids {
let request = server
.send_request(
"modelProvider/config/write",
Some(json!({"settings":{"type":"customGateway","providerId":id,"name":"Amazon Bedrock Mantle","baseUrl":new_url}})),
)
.await?;
let saved: Value = server.read_response(request).await?;
assert_eq!(saved["provider"]["id"], id);
providers[id] = json!({"name": "Amazon Bedrock Mantle", "base_url": new_url});
}
let saved: Value = toml::from_str(&std::fs::read_to_string(config_path)?)?;
assert_eq!(saved["model_providers"], providers);
Ok(())
}
#[tokio::test]
async fn builtin_provider_patches_preserve_auth_and_do_not_select_or_authenticate() -> Result<()> {
let home = TempDir::new()?;
let config_path = home.path().join("config.toml");
std::fs::write(
home.path().join("requirements.toml"),
"model_provider = 'openai'\n",
)?;
let mut server = TestAppServer::builder()
.with_codex_home(home.path())
.with_env_overrides(CLEARED_AUTH_ENV)
.build_initialized()
.await?;
let credential_file = home.path().join("missing-credentials.json");
for mut settings in [
json!({"type":"bedrock", "providerId":"amazon-bedrock", "profile":"work", "region":"us-east-1"}),
json!({"type":"bedrock", "providerId":"amazon-bedrock-runtime", "profile":null, "region":"us-west-2"}),
json!({"type":"gcp", "providerId":"gcp", "projectId":"test-project", "location":"global", "credentialFile":credential_file}),
] {
let params = serde_json::from_value(json!({"settings":settings}))?;
let saved: Value = server
.request(|request_id| ClientRequest::ModelProviderConfigWrite { request_id, params })
.await?;
let id = settings
.as_object_mut()
.unwrap()
.remove("providerId")
.unwrap();
assert_eq!(saved["provider"]["id"], id);
assert_eq!(saved["provider"]["settings"], settings);
}
let refresh = json!({"command":"aws", "args":["sso", "login"]});
let export = json!({"command":"unused-credential-command", "args":["test-only"]});
let mut configured: Value = toml::from_str(&std::fs::read_to_string(&config_path)?)?;
configured["model_providers"]["amazon-bedrock"]["aws"]["auth_refresh"] = refresh.clone();
configured["model_providers"]["amazon-bedrock-runtime"]["aws"]["credential_export"] =
export.clone();
std::fs::write(&config_path, toml::to_string(&configured)?)?;
for settings in [
json!({"type":"bedrock", "providerId":"amazon-bedrock", "region":null}),
json!({"type":"bedrock", "providerId":"amazon-bedrock-runtime", "region":"eu-west-1"}),
json!({"type":"gcp", "providerId":"gcp", "location":"us-central1", "credentialFile":null}),
json!({"type":"gcp", "providerId":"gcp"}),
] {
let params = serde_json::from_value(json!({"settings":settings}))?;
let saved: Value = server
.request(|request_id| ClientRequest::ModelProviderConfigWrite { request_id, params })
.await?;
assert_eq!(saved["provider"]["id"], settings["providerId"]);
}
let list: Value = server
.request(|request_id| ClientRequest::ModelProviderList {
request_id,
params: Default::default(),
})
.await?;
assert_eq!(list["defaultProviderId"], "openai");
assert_eq!(list["canChangeDefault"], false);
let before_rejections = std::fs::read_to_string(&config_path)?;
let actual: Value = toml::from_str(&before_rejections)?;
assert_eq!(
actual,
json!({"model_providers": {
"amazon-bedrock": {"aws":{"profile":"work", "auth_refresh":refresh}},
"amazon-bedrock-runtime": {"aws":{"region":"eu-west-1", "credential_export":export}},
"gcp":{"project_id":"test-project", "location":"us-central1"}
}})
);
for settings in [
json!({"type":"bedrock", "providerId":"amazon-bedrock-runtime", "profile":"conflicts-with-command", "region":"must-not-save"}),
json!({"type":"gcp", "providerId":"gcp", "credentialFile":"relative/path", "location":"must-not-save"}),
] {
let write = server
.send_request(
"modelProvider/config/write",
Some(json!({"settings":settings})),
)
.await?;
let error = server
.read_stream_until_error_message(RequestId::Integer(write))
.await?;
assert_eq!(
error.error.data,
Some(json!({"config_write_error_code":"configValidationError"}))
);
assert_eq!(std::fs::read_to_string(&config_path)?, before_rejections);
}
for settings in [
json!({"type":"bedrock", "providerId":"gcp", "region":"must-not-save"}),
json!({"type":"gcp", "providerId":"amazon-bedrock", "location":"must-not-save"}),
json!({"type":"bedrock", "providerId":"amazon-bedrock", "envKey":"UNSUPPORTED"}),
json!({"type":"gcp", "providerId":"gcp", "profile":"wrong-provider-field"}),
json!({"type":"gcp", "location":"missing-id"}),
] {
let write = server
.send_request(
"modelProvider/config/write",
Some(json!({"settings":settings})),
)
.await?;
let error = server
.read_stream_until_error_message(RequestId::Integer(write))
.await?;
assert_eq!(error.error.code, -32600);
}
assert_eq!(std::fs::read_to_string(&config_path)?, before_rejections);
Ok(())
}