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:
@@ -36,6 +36,7 @@ icu_provider = { workspace = true, features = ["sync"] }
|
||||
quick-xml = { workspace = true, features = ["serialize"] }
|
||||
schemars = { workspace = true }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
url = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
serde_with = { workspace = true, features = ["macros", "base64"] }
|
||||
strum = { workspace = true }
|
||||
|
||||
@@ -52,10 +52,6 @@ pub enum PlanType {
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ProviderAccount {
|
||||
ApiKey,
|
||||
AmazonBedrock {
|
||||
uses_codex_managed_credentials: bool,
|
||||
},
|
||||
Gcp,
|
||||
}
|
||||
|
||||
impl PlanType {
|
||||
|
||||
@@ -13,14 +13,6 @@ pub enum AuthMode {
|
||||
#[serde(rename = "headers")]
|
||||
#[strum(serialize = "headers")]
|
||||
Headers,
|
||||
/// Amazon Bedrock bearer token managed by Codex.
|
||||
#[serde(rename = "bedrockApiKey")]
|
||||
#[strum(serialize = "bedrockApiKey")]
|
||||
BedrockApiKey,
|
||||
/// Amazon Bedrock AWS access keys managed by Codex.
|
||||
#[serde(rename = "bedrockAccessKeys")]
|
||||
#[strum(serialize = "bedrockAccessKeys")]
|
||||
BedrockAccessKeys,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
|
||||
@@ -406,6 +406,104 @@ pub enum ToolExposureSurface {
|
||||
Direct,
|
||||
}
|
||||
|
||||
/// Client-side web search backends (`[web_search] backend = ...`).
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Display, JsonSchema, TS)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[strum(serialize_all = "lowercase")]
|
||||
pub enum WebSearchBackendKind {
|
||||
/// A SearXNG instance with the JSON output format enabled.
|
||||
Searxng,
|
||||
}
|
||||
|
||||
/// Default number of results returned by the client-side `web_search` tool.
|
||||
pub const DEFAULT_WEB_SEARCH_MAX_RESULTS: usize = 8;
|
||||
|
||||
/// `[web_search]` table form: a client-side backend plus the optional mode.
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
#[schemars(deny_unknown_fields)]
|
||||
pub struct WebSearchTable {
|
||||
/// Same values as the string form (`web_search = "live"`); `disabled` turns tools off.
|
||||
pub mode: Option<WebSearchMode>,
|
||||
/// Client-side backend. When unset, no web tools are exposed.
|
||||
pub backend: Option<WebSearchBackendKind>,
|
||||
/// Base URL of the backend, for example `http://192.168.40.57:8080`.
|
||||
pub url: Option<String>,
|
||||
/// Number of results returned by `web_search` (default 8).
|
||||
pub max_results: Option<usize>,
|
||||
/// Expose the `web_fetch` tool (default true).
|
||||
pub fetch: Option<bool>,
|
||||
}
|
||||
|
||||
/// `web_search` accepts either a mode string or a `[web_search]` table.
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, TS)]
|
||||
#[serde(untagged)]
|
||||
pub enum WebSearchSetting {
|
||||
Mode(WebSearchMode),
|
||||
Table(WebSearchTable),
|
||||
}
|
||||
|
||||
impl From<WebSearchMode> for WebSearchSetting {
|
||||
fn from(mode: WebSearchMode) -> Self {
|
||||
Self::Mode(mode)
|
||||
}
|
||||
}
|
||||
|
||||
impl WebSearchSetting {
|
||||
pub fn mode(&self) -> Option<WebSearchMode> {
|
||||
match self {
|
||||
Self::Mode(mode) => Some(*mode),
|
||||
Self::Table(table) => table.mode,
|
||||
}
|
||||
}
|
||||
|
||||
/// The configured client-side backend, validated, or `None` when not configured.
|
||||
pub fn backend(&self) -> Result<Option<WebSearchBackendConfig>, String> {
|
||||
let Self::Table(table) = self else {
|
||||
return Ok(None);
|
||||
};
|
||||
let Some(backend) = table.backend else {
|
||||
if table.url.is_some() {
|
||||
return Err("web_search.url requires web_search.backend".to_string());
|
||||
}
|
||||
return Ok(None);
|
||||
};
|
||||
let url = table
|
||||
.url
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.filter(|url| !url.is_empty())
|
||||
.ok_or_else(|| format!("web_search.backend = \"{backend}\" requires web_search.url"))?;
|
||||
let parsed = url::Url::parse(url)
|
||||
.map_err(|_| "web_search.url must be an absolute http(s) URL".to_string())?;
|
||||
if !matches!(parsed.scheme(), "http" | "https") || parsed.host_str().is_none() {
|
||||
return Err("web_search.url must be an absolute http(s) URL".to_string());
|
||||
}
|
||||
if !parsed.username().is_empty() || parsed.password().is_some() {
|
||||
return Err("web_search.url must not contain credentials".to_string());
|
||||
}
|
||||
let max_results = table.max_results.unwrap_or(DEFAULT_WEB_SEARCH_MAX_RESULTS);
|
||||
if !(1..=50).contains(&max_results) {
|
||||
return Err("web_search.max_results must be between 1 and 50".to_string());
|
||||
}
|
||||
Ok(Some(WebSearchBackendConfig {
|
||||
backend,
|
||||
url: url.to_string(),
|
||||
max_results,
|
||||
fetch: table.fetch.unwrap_or(true),
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
/// Validated client-side web search backend.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct WebSearchBackendConfig {
|
||||
pub backend: WebSearchBackendKind,
|
||||
pub url: String,
|
||||
pub max_results: usize,
|
||||
pub fetch: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Display, JsonSchema, TS)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[strum(serialize_all = "lowercase")]
|
||||
@@ -799,6 +897,76 @@ mod tests {
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
fn setting(value: serde_json::Value) -> WebSearchSetting {
|
||||
serde_json::from_value(value).expect("web_search setting")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn web_search_accepts_mode_string_and_backend_table() {
|
||||
assert_eq!(
|
||||
setting(serde_json::json!("live")),
|
||||
WebSearchSetting::Mode(WebSearchMode::Live)
|
||||
);
|
||||
assert_eq!(setting(serde_json::json!("live")).backend(), Ok(None));
|
||||
let table = setting(serde_json::json!({
|
||||
"backend": "searxng",
|
||||
"url": "http://192.168.40.57:8080",
|
||||
}));
|
||||
assert_eq!(table.mode(), None);
|
||||
assert_eq!(
|
||||
table.backend(),
|
||||
Ok(Some(WebSearchBackendConfig {
|
||||
backend: WebSearchBackendKind::Searxng,
|
||||
url: "http://192.168.40.57:8080".to_string(),
|
||||
max_results: DEFAULT_WEB_SEARCH_MAX_RESULTS,
|
||||
fetch: true,
|
||||
}))
|
||||
);
|
||||
let custom = setting(serde_json::json!({
|
||||
"backend": "searxng",
|
||||
"url": "https://search.example/searx",
|
||||
"max_results": 3,
|
||||
"fetch": false,
|
||||
"mode": "disabled",
|
||||
}));
|
||||
assert_eq!(custom.mode(), Some(WebSearchMode::Disabled));
|
||||
assert_eq!(custom.backend().unwrap().unwrap().max_results, 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn web_search_backend_table_is_validated() {
|
||||
for (value, error) in [
|
||||
(
|
||||
serde_json::json!({"backend": "searxng"}),
|
||||
"requires web_search.url",
|
||||
),
|
||||
(
|
||||
serde_json::json!({"backend": "searxng", "url": "ftp://x"}),
|
||||
"absolute http(s) URL",
|
||||
),
|
||||
(
|
||||
serde_json::json!({"backend": "searxng", "url": "http://u:p@host"}),
|
||||
"must not contain credentials",
|
||||
),
|
||||
(
|
||||
serde_json::json!({"backend": "searxng", "url": "http://h", "max_results": 0}),
|
||||
"between 1 and 50",
|
||||
),
|
||||
(
|
||||
serde_json::json!({"url": "http://h"}),
|
||||
"requires web_search.backend",
|
||||
),
|
||||
] {
|
||||
let message = setting(value).backend().unwrap_err();
|
||||
assert!(message.contains(error), "{message}");
|
||||
}
|
||||
assert!(
|
||||
serde_json::from_value::<WebSearchSetting>(serde_json::json!({"backend": "google"}))
|
||||
.is_err()
|
||||
);
|
||||
assert_eq!(setting(serde_json::json!({})).backend(), Ok(None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn web_search_mode_restrictions_never_expand_either_mode() {
|
||||
use WebSearchMode::Cached;
|
||||
|
||||
@@ -329,6 +329,8 @@ pub enum ConfigShellToolType {
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ApplyPatchToolType {
|
||||
Freeform,
|
||||
/// JSON function tool with a single `input` string, for servers without custom tools.
|
||||
Function,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
|
||||
Reference in New Issue
Block a user