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:
@@ -327,6 +327,36 @@ pub type ModelsManagerFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a
|
||||
/// Shared model manager handle used across runtime services.
|
||||
pub type SharedModelsManager = Arc<dyn ModelsManager>;
|
||||
|
||||
/// Picks the model for an auxiliary call (memories, background classifiers).
|
||||
///
|
||||
/// aKode never sends a hard-coded model name to a provider that does not serve it: the
|
||||
/// provider-preferred model is used only when the provider's catalog (or an explicit
|
||||
/// `model_catalog_json`) advertises it; otherwise the session's current model is used.
|
||||
pub async fn auxiliary_model(
|
||||
manager: &dyn ModelsManager,
|
||||
preferred: &str,
|
||||
session_model: &str,
|
||||
http_client_factory: HttpClientFactory,
|
||||
) -> String {
|
||||
let advertised = manager
|
||||
// Loads the catalog once if needed (from the configured provider or explicit catalog).
|
||||
.model_catalog_with_origins(RefreshStrategy::OnlineIfUncached, http_client_factory)
|
||||
.await
|
||||
.iter()
|
||||
.any(|entry| {
|
||||
entry.slug == preferred
|
||||
&& matches!(
|
||||
entry.origin,
|
||||
ModelOrigin::Provider | ModelOrigin::ExplicitConfig
|
||||
)
|
||||
});
|
||||
if advertised {
|
||||
preferred.to_string()
|
||||
} else {
|
||||
session_model.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
/// Only explicit catalogs serialize refresh and suppress bundled fallback. Auth and discovery
|
||||
/// settings are still evaluated when models are requested.
|
||||
#[derive(Debug)]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use codex_protocol::config_types::Personality;
|
||||
use codex_protocol::config_types::ReasoningSummary;
|
||||
use codex_protocol::openai_models::ApplyPatchToolType;
|
||||
use codex_protocol::openai_models::ConfigShellToolType;
|
||||
use codex_protocol::openai_models::ModelInfo;
|
||||
use codex_protocol::openai_models::ModelMessages;
|
||||
@@ -94,9 +95,42 @@ fn is_h1_heading(line: &str) -> bool {
|
||||
rest.is_empty() || rest.starts_with(' ') || rest.starts_with('\t')
|
||||
}
|
||||
|
||||
/// Context window assumed for a local model when neither config nor server reports one.
|
||||
pub const DEFAULT_LOCAL_CONTEXT_WINDOW: i64 = 32_768;
|
||||
/// Percent of the context window at which auto-compaction triggers for local models.
|
||||
const LOCAL_AUTO_COMPACT_PERCENT: i64 = 85;
|
||||
|
||||
/// Metadata for a model served by a local or self-hosted OpenAI-compatible server.
|
||||
///
|
||||
/// `context_window` is what the server reported, if anything; config
|
||||
/// (`model_context_window`) still takes precedence through [`with_config_overrides`].
|
||||
/// Tools: shell plus `apply_patch` as a JSON function tool (local servers do not support
|
||||
/// custom grammar tools); no hosted tools; reasoning summaries off.
|
||||
pub fn local_model_info(slug: &str, context_window: Option<i64>) -> ModelInfo {
|
||||
let reported = context_window.filter(|window| *window > 0);
|
||||
let window = reported.unwrap_or(DEFAULT_LOCAL_CONTEXT_WINDOW);
|
||||
ModelInfo {
|
||||
visibility: ModelVisibility::List,
|
||||
priority: 0,
|
||||
supports_reasoning_summary_parameter: false,
|
||||
default_reasoning_summary: ReasoningSummary::None,
|
||||
apply_patch_tool_type: Some(ApplyPatchToolType::Function),
|
||||
web_search_provider: None,
|
||||
context_window: Some(window),
|
||||
// Only a server-reported window caps a configured `model_context_window`.
|
||||
max_context_window: reported,
|
||||
auto_compact_token_limit: Some(window * LOCAL_AUTO_COMPACT_PERCENT / 100),
|
||||
..base_model_info(slug)
|
||||
}
|
||||
}
|
||||
|
||||
/// Build a minimal fallback model descriptor for missing/unknown slugs.
|
||||
pub fn model_info_from_slug(slug: &str) -> ModelInfo {
|
||||
warn!("Unknown model {slug} is used. This will use fallback model metadata.");
|
||||
base_model_info(slug)
|
||||
}
|
||||
|
||||
fn base_model_info(slug: &str) -> ModelInfo {
|
||||
ModelInfo {
|
||||
slug: slug.to_string(),
|
||||
display_name: slug.to_string(),
|
||||
|
||||
@@ -278,3 +278,45 @@ fn model_context_window_uses_model_value_without_override() {
|
||||
|
||||
assert_eq!(updated, model);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_model_info_uses_server_context_and_function_apply_patch() {
|
||||
let model = local_model_info("qwen3.6-35b-a3b", Some(131_072));
|
||||
assert_eq!(model.slug, "qwen3.6-35b-a3b");
|
||||
assert_eq!(model.context_window, Some(131_072));
|
||||
assert_eq!(model.max_context_window, Some(131_072));
|
||||
assert_eq!(model.auto_compact_token_limit, Some(111_411));
|
||||
assert_eq!(
|
||||
model.apply_patch_tool_type,
|
||||
Some(codex_protocol::openai_models::ApplyPatchToolType::Function)
|
||||
);
|
||||
assert!(!model.supports_reasoning_summary_parameter);
|
||||
assert_eq!(
|
||||
model.default_reasoning_summary,
|
||||
codex_protocol::config_types::ReasoningSummary::None
|
||||
);
|
||||
assert_eq!(model.web_search_provider, None);
|
||||
assert_eq!(
|
||||
model.shell_type,
|
||||
codex_protocol::openai_models::ConfigShellToolType::UnifiedExec
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_model_info_defaults_conservatively_and_lets_config_win() {
|
||||
let model = local_model_info("unknown-local", None);
|
||||
assert_eq!(model.context_window, Some(DEFAULT_LOCAL_CONTEXT_WINDOW));
|
||||
assert_eq!(model.max_context_window, None);
|
||||
|
||||
// A configured window is not clamped by the conservative default.
|
||||
let config = ModelsManagerConfig {
|
||||
model_context_window: Some(200_000),
|
||||
..Default::default()
|
||||
};
|
||||
let model = with_config_overrides(model, &config);
|
||||
assert_eq!(model.context_window, Some(200_000));
|
||||
|
||||
// A server-reported maximum still caps a larger configured window.
|
||||
let capped = with_config_overrides(local_model_info("m", Some(65_536)), &config);
|
||||
assert_eq!(capped.context_window, Some(65_536));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user