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:
@@ -47,10 +47,8 @@ use crate::LoginStatus;
|
||||
use crate::activation_key_guard::ActivationKeyGuard;
|
||||
use crate::key_hint::KeyBinding;
|
||||
use crate::key_hint::KeyBindingListExt;
|
||||
use crate::onboarding::bedrock::BedrockState;
|
||||
use crate::onboarding::gateway::GatewayStep;
|
||||
use crate::onboarding::gateway::USE_CUSTOM_PROVIDER;
|
||||
use crate::onboarding::gcp::GcpState;
|
||||
use crate::onboarding::keys;
|
||||
use crate::onboarding::onboarding_screen::KeyboardHandler;
|
||||
use crate::onboarding::onboarding_screen::StepStateProvider;
|
||||
@@ -74,10 +72,6 @@ pub(crate) enum SignInState {
|
||||
PickMode,
|
||||
ApiKeyEntry(ApiKeyInputState),
|
||||
ApiKeyConfigured,
|
||||
Bedrock(BedrockState),
|
||||
BedrockConfigured,
|
||||
Gcp(GcpState),
|
||||
GcpConfigured,
|
||||
GatewaySelected(String),
|
||||
GatewayOAuth {
|
||||
provider_id: String,
|
||||
@@ -93,8 +87,6 @@ pub(crate) enum SignInState {
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum SignInOption {
|
||||
ApiKey,
|
||||
Bedrock,
|
||||
Gcp,
|
||||
Gateway,
|
||||
}
|
||||
|
||||
@@ -119,10 +111,7 @@ impl KeyboardHandler for AuthModeWidget {
|
||||
{
|
||||
return;
|
||||
}
|
||||
if self.handle_gcp_key_event(&key_event)
|
||||
|| self.handle_bedrock_key_event(&key_event)
|
||||
|| self.handle_gateway_key_event(key_event)
|
||||
{
|
||||
if self.handle_gateway_key_event(key_event) {
|
||||
return;
|
||||
}
|
||||
if self.handle_api_key_entry_key_event(&key_event) {
|
||||
@@ -178,22 +167,12 @@ impl KeyboardHandler for AuthModeWidget {
|
||||
}
|
||||
return;
|
||||
}
|
||||
let mut state = self.sign_in_state.write().unwrap();
|
||||
let input = match &mut *state {
|
||||
SignInState::Bedrock(state) => state.active_input_mut(),
|
||||
SignInState::Gcp(state) => state.active_input_mut(),
|
||||
SignInState::ApiKeyEntry(_) => {
|
||||
drop(state);
|
||||
let _ = self.handle_api_key_entry_paste(pasted);
|
||||
return;
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
if let Some(input) = input {
|
||||
input.paste(&pasted);
|
||||
self.set_error(/*message*/ None);
|
||||
drop(state);
|
||||
self.request_frame.schedule_frame();
|
||||
let is_api_key_entry = matches!(
|
||||
*self.sign_in_state.read().unwrap(),
|
||||
SignInState::ApiKeyEntry(_)
|
||||
);
|
||||
if is_api_key_entry {
|
||||
let _ = self.handle_api_key_entry_paste(pasted);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -209,8 +188,6 @@ pub(crate) struct AuthModeWidget {
|
||||
pub app_server_target: crate::AppServerTarget,
|
||||
pub app_server_request_handle: AppServerRequestHandle,
|
||||
pub auth_config: AuthConfig,
|
||||
pub bedrock_setup_enabled: bool,
|
||||
pub gcp_setup_enabled: bool,
|
||||
pub gateway_setup_enabled: bool,
|
||||
pub(super) gateway: Option<GatewayStep>,
|
||||
}
|
||||
@@ -231,24 +208,20 @@ impl AuthModeWidget {
|
||||
}
|
||||
self.sign_in_state.read().is_ok_and(|guard| match &*guard {
|
||||
SignInState::ApiKeyEntry(_) => true,
|
||||
SignInState::Bedrock(state) => state.is_text_entry_active(),
|
||||
SignInState::Gcp(state) => state.is_text_entry_active(),
|
||||
_ => false,
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns whether printable quit shortcuts must be treated as text input.
|
||||
///
|
||||
/// OpenAI API-key entry keeps its existing empty-field quit behavior, while
|
||||
/// Cloud setup fields accept printable input from their first character.
|
||||
/// API-key entry keeps its existing empty-field quit behavior, while
|
||||
/// provider setup fields accept printable input from their first character.
|
||||
pub(crate) fn should_suppress_printable_quit(&self) -> bool {
|
||||
if let Some(wizard) = &self.gateway {
|
||||
return wizard.is_text_entry_active();
|
||||
}
|
||||
self.sign_in_state.read().is_ok_and(|guard| match &*guard {
|
||||
SignInState::ApiKeyEntry(state) => !state.value.is_empty(),
|
||||
SignInState::Bedrock(state) => state.is_text_entry_active(),
|
||||
SignInState::Gcp(state) => state.is_text_entry_active(),
|
||||
_ => false,
|
||||
})
|
||||
}
|
||||
@@ -268,12 +241,6 @@ impl AuthModeWidget {
|
||||
|
||||
fn displayed_sign_in_options(&self) -> Vec<SignInOption> {
|
||||
let mut options = vec![SignInOption::ApiKey];
|
||||
if self.bedrock_setup_enabled {
|
||||
options.push(SignInOption::Bedrock);
|
||||
}
|
||||
if self.gcp_setup_enabled {
|
||||
options.push(SignInOption::Gcp);
|
||||
}
|
||||
if self.gateway_setup_enabled {
|
||||
options.push(SignInOption::Gateway);
|
||||
}
|
||||
@@ -333,22 +300,6 @@ impl AuthModeWidget {
|
||||
self.disallow_api_login();
|
||||
}
|
||||
}
|
||||
SignInOption::Bedrock => {
|
||||
if self.bedrock_setup_enabled && self.is_api_login_allowed() {
|
||||
self.start_bedrock_discovery();
|
||||
} else if !self.is_api_login_allowed() {
|
||||
self.disallow_api_login();
|
||||
}
|
||||
}
|
||||
SignInOption::Gcp => {
|
||||
if self.gcp_setup_enabled && self.is_api_login_allowed() {
|
||||
*self.sign_in_state.write().unwrap() = SignInState::Gcp(GcpState::default());
|
||||
self.set_error(/*message*/ None);
|
||||
self.request_frame.schedule_frame();
|
||||
} else if !self.is_api_login_allowed() {
|
||||
self.disallow_api_login();
|
||||
}
|
||||
}
|
||||
SignInOption::Gateway => {
|
||||
if self.gateway_setup_enabled && self.is_api_login_allowed() {
|
||||
self.start_gateway_picker();
|
||||
@@ -367,12 +318,11 @@ impl AuthModeWidget {
|
||||
}
|
||||
|
||||
fn render_pick_mode(&self, area: Rect, buf: &mut Buffer) {
|
||||
let mut lines: Vec<Line> =
|
||||
if self.bedrock_setup_enabled || self.gcp_setup_enabled || self.gateway_setup_enabled {
|
||||
vec![" Choose how you want to use aKode.".into(), "".into()]
|
||||
} else {
|
||||
vec![" Connect an API key to use aKode.".into(), "".into()]
|
||||
};
|
||||
let mut lines: Vec<Line> = if self.gateway_setup_enabled {
|
||||
vec![" Choose how you want to use aKode.".into(), "".into()]
|
||||
} else {
|
||||
vec![" Connect an API key to use aKode.".into(), "".into()]
|
||||
};
|
||||
|
||||
let options_start = lines.len();
|
||||
let mut compact_options = Vec::new();
|
||||
@@ -416,22 +366,6 @@ impl AuthModeWidget {
|
||||
"Pay for what you use",
|
||||
));
|
||||
}
|
||||
SignInOption::Bedrock => {
|
||||
lines.extend(create_mode_item(
|
||||
idx,
|
||||
option,
|
||||
"Use Amazon Bedrock",
|
||||
"Connect using your AWS credentials",
|
||||
));
|
||||
}
|
||||
SignInOption::Gcp => {
|
||||
lines.extend(create_mode_item(
|
||||
idx,
|
||||
option,
|
||||
"Use Google Cloud Vertex AI",
|
||||
"Connect using your Google Cloud credentials",
|
||||
));
|
||||
}
|
||||
SignInOption::Gateway => {
|
||||
lines.extend(create_mode_item(
|
||||
idx,
|
||||
@@ -697,15 +631,6 @@ impl AuthModeWidget {
|
||||
*error.write().unwrap() = None;
|
||||
*sign_in_state.write().unwrap() = SignInState::ApiKeyConfigured;
|
||||
}
|
||||
Ok(other) => {
|
||||
*error.write().unwrap() = Some(format!(
|
||||
"Unexpected account/login/start response: {other:?}"
|
||||
));
|
||||
*sign_in_state.write().unwrap() = SignInState::ApiKeyEntry(ApiKeyInputState {
|
||||
value: api_key,
|
||||
prepopulated_from_env: false,
|
||||
});
|
||||
}
|
||||
Err(err) => {
|
||||
*error.write().unwrap() = Some(format!("Failed to save API key: {err}"));
|
||||
*sign_in_state.write().unwrap() = SignInState::ApiKeyEntry(ApiKeyInputState {
|
||||
@@ -726,8 +651,6 @@ impl AuthModeWidget {
|
||||
LoginStatus::AuthMode(match auth_mode {
|
||||
ApiAuthMode::ApiKey => AuthMode::ApiKey,
|
||||
ApiAuthMode::Headers => AuthMode::Headers,
|
||||
ApiAuthMode::BedrockApiKey => AuthMode::BedrockApiKey,
|
||||
ApiAuthMode::BedrockAccessKeys => AuthMode::BedrockAccessKeys,
|
||||
})
|
||||
})
|
||||
.unwrap_or(LoginStatus::NotAuthenticated);
|
||||
@@ -740,13 +663,9 @@ impl StepStateProvider for AuthModeWidget {
|
||||
match &*sign_in_state {
|
||||
SignInState::PickMode
|
||||
| SignInState::ApiKeyEntry(_)
|
||||
| SignInState::Bedrock(_)
|
||||
| SignInState::Gcp(_)
|
||||
| SignInState::GatewayOAuth { .. }
|
||||
| SignInState::GatewayOAuthFailed { .. } => StepState::InProgress,
|
||||
SignInState::ApiKeyConfigured
|
||||
| SignInState::BedrockConfigured
|
||||
| SignInState::GcpConfigured
|
||||
| SignInState::GatewaySelected(_)
|
||||
| SignInState::GatewayConfigured => StepState::Complete,
|
||||
}
|
||||
@@ -770,12 +689,6 @@ impl WidgetRef for AuthModeWidget {
|
||||
SignInState::ApiKeyConfigured => {
|
||||
self.render_api_key_configured(area, buf);
|
||||
}
|
||||
SignInState::Bedrock(state) => {
|
||||
state.render(area, buf, self.error_message());
|
||||
}
|
||||
SignInState::Gcp(state) => {
|
||||
state.render(area, buf, self.error_message());
|
||||
}
|
||||
SignInState::GatewayOAuth { url, .. } => {
|
||||
let mut lines = vec![Line::from(
|
||||
"Finish signing in to your gateway in the browser.".bold(),
|
||||
@@ -804,16 +717,6 @@ impl WidgetRef for AuthModeWidget {
|
||||
.wrap(Wrap { trim: false })
|
||||
.render(area, buf);
|
||||
}
|
||||
SignInState::GcpConfigured => {
|
||||
Paragraph::new("✓ Google Cloud Vertex AI configured".green())
|
||||
.wrap(Wrap { trim: false })
|
||||
.render(area, buf);
|
||||
}
|
||||
SignInState::BedrockConfigured => {
|
||||
Paragraph::new("✓ Amazon Bedrock configured".green())
|
||||
.wrap(Wrap { trim: false })
|
||||
.render(area, buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -888,8 +791,6 @@ mod tests {
|
||||
app_server_target: crate::AppServerTarget::Embedded,
|
||||
app_server_request_handle: AppServerRequestHandle::InProcess(client.request_handle()),
|
||||
auth_config,
|
||||
bedrock_setup_enabled: false,
|
||||
gcp_setup_enabled: false,
|
||||
gateway_setup_enabled: false,
|
||||
gateway: None,
|
||||
};
|
||||
@@ -936,7 +837,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn bedrock_option_requires_feature_and_api_login_permission() {
|
||||
async fn gateway_option_requires_feature_and_api_login_permission() {
|
||||
let (mut widget, codex_home) = widget_api_login_forbidden().await;
|
||||
widget.auth_config.forced_login_method = None;
|
||||
assert_eq!(
|
||||
@@ -946,7 +847,7 @@ mod tests {
|
||||
|
||||
std::fs::write(
|
||||
codex_home.path().join("config.toml"),
|
||||
"model_provider = \"openai\"\n[features]\nbedrock_setup_wizard = true\n",
|
||||
"[features]\ngateway_setup_wizard = true\n",
|
||||
)
|
||||
.unwrap();
|
||||
let config = ConfigBuilder::default()
|
||||
@@ -954,16 +855,16 @@ mod tests {
|
||||
.build()
|
||||
.await
|
||||
.unwrap();
|
||||
widget.bedrock_setup_enabled = crate::should_show_provider_setup_wizard(
|
||||
widget.gateway_setup_enabled = crate::should_show_provider_setup_wizard(
|
||||
widget.login_status,
|
||||
/*requires_openai_auth*/ true,
|
||||
&config,
|
||||
&widget.app_server_target,
|
||||
Feature::BedrockSetupWizard,
|
||||
Feature::GatewaySetupWizard,
|
||||
);
|
||||
assert_eq!(
|
||||
widget.displayed_sign_in_options(),
|
||||
vec![SignInOption::ApiKey, SignInOption::Bedrock]
|
||||
vec![SignInOption::ApiKey, SignInOption::Gateway]
|
||||
);
|
||||
widget.move_highlight(/*delta*/ 1);
|
||||
|
||||
@@ -988,8 +889,8 @@ mod tests {
|
||||
1. Use an OpenAI API key
|
||||
Pay for what you use
|
||||
|
||||
> 2. Use Amazon Bedrock
|
||||
Connect using your AWS credentials
|
||||
> 2. Use a custom provider or gateway
|
||||
Choose a saved configuration or create a new one
|
||||
|
||||
Press enter to continue
|
||||
"###);
|
||||
@@ -1090,10 +991,6 @@ mod tests {
|
||||
#[cfg(test)]
|
||||
mod activation_key_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "gcp_tests.rs"]
|
||||
mod gcp_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "gateway_tests.rs"]
|
||||
mod gateway_tests;
|
||||
|
||||
Reference in New Issue
Block a user