Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src-tauri/src/cli/commands/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ fn prompt_api_format(
.map(|api_format| value_label(api_format).to_string())
.collect::<Vec<_>>();

let selected = Select::new(texts::tui_label_claude_api_format(), labels.clone())
let selected = Select::new(texts::tui_label_api_format(), labels.clone())
.with_starting_cursor(default_index)
.prompt()
.map_err(|e| AppError::Message(texts::input_failed_error(&e.to_string())))?;
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/cli/commands/provider_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4092,7 +4092,7 @@ pub fn display_provider_summary(provider: &Provider, app_type: &AppType) {
let api_format = crate::proxy::providers::get_claude_api_format(provider);
println!(
" {}: {}",
texts::tui_label_claude_api_format(),
texts::tui_label_api_format(),
texts::tui_claude_api_format_value(api_format)
);
}
Expand Down Expand Up @@ -4148,7 +4148,7 @@ pub fn display_provider_summary(provider: &Provider, app_type: &AppType) {
};
println!(
" {}: {}",
texts::tui_label_claude_api_format(),
texts::tui_label_api_format(),
texts::tui_codex_api_format_value(api_format)
);
}
Expand Down
6 changes: 3 additions & 3 deletions src-tauri/src/cli/i18n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,7 @@ pub mod texts {
}
}

pub fn tui_label_claude_api_format() -> &'static str {
pub fn tui_label_api_format() -> &'static str {
if is_chinese() {
"API 格式"
} else {
Expand Down Expand Up @@ -1638,7 +1638,7 @@ pub mod texts {
}
}

pub fn tui_claude_api_format_requires_proxy_title() -> &'static str {
pub fn tui_api_format_requires_proxy_title() -> &'static str {
if is_chinese() {
"需开启代理"
} else {
Expand Down Expand Up @@ -1793,7 +1793,7 @@ pub mod texts {
}
}

pub fn tui_claude_api_format_popup_title() -> &'static str {
pub fn tui_api_format_popup_title() -> &'static str {
if is_chinese() {
"API 格式"
} else {
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/cli/i18n/texts/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ pub fn tui_codex_api_format_value(api_format: &str) -> &'static str {
}
}

pub fn tui_claude_api_format_requires_proxy_title() -> &'static str {
pub fn tui_api_format_requires_proxy_title() -> &'static str {
if is_chinese() {
"需开启代理"
} else {
Expand Down
10 changes: 4 additions & 6 deletions src-tauri/src/cli/tui/app/form_handlers/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,12 @@ impl App {
data: &UiData,
) -> Action {
match selected {
ProviderAddField::ClaudeApiFormat => {
ProviderAddField::ApiFormat => {
let Some(FormState::ProviderAdd(provider)) = self.form.as_ref() else {
return Action::None;
};
self.overlay = Overlay::ClaudeApiFormatPicker {
selected: provider
.claude_api_format
.picker_index_for_app(&provider.app_type),
self.overlay = Overlay::ApiFormatPicker {
selected: provider.api_format.picker_index_for_app(&provider.app_type),
};
Action::None
}
Expand Down Expand Up @@ -481,7 +479,7 @@ impl App {
.unwrap_or(false)
{
self.overlay = Overlay::Confirm(ConfirmOverlay {
title: texts::tui_claude_api_format_requires_proxy_title().to_string(),
title: texts::tui_api_format_requires_proxy_title().to_string(),
message: texts::tui_codex_api_format_requires_proxy_message("openai_chat"),
action: ConfirmAction::ProviderApiFormatProxyNotice,
});
Expand Down
28 changes: 13 additions & 15 deletions src-tauri/src/cli/tui/app/overlay_handlers/pickers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl App {
if let Some(action) = self.handle_sync_method_picker_key(key, data) {
return Some(action);
}
if let Some(action) = self.handle_claude_api_format_picker_key(key, data) {
if let Some(action) = self.handle_api_format_picker_key(key, data) {
return Some(action);
}
if let Some(action) = self.handle_usage_query_template_picker_key(key) {
Expand Down Expand Up @@ -194,11 +194,7 @@ impl App {
})
}

fn handle_claude_api_format_picker_key(
&mut self,
key: KeyEvent,
data: &UiData,
) -> Option<Action> {
fn handle_api_format_picker_key(&mut self, key: KeyEvent, data: &UiData) -> Option<Action> {
let app_type = self
.form
.as_ref()
Expand All @@ -207,7 +203,7 @@ impl App {
_ => None,
})
.unwrap_or_else(|| self.app_type.clone());
let Overlay::ClaudeApiFormatPicker { selected } = &mut self.overlay else {
let Overlay::ApiFormatPicker { selected } = &mut self.overlay else {
return None;
};

Expand All @@ -222,39 +218,41 @@ impl App {
}
KeyCode::Down => {
*selected = (*selected + 1).min(
crate::cli::tui::form::ClaudeApiFormat::choices_for_app(&app_type)
crate::cli::tui::form::ApiFormat::choices_for_app(&app_type)
.len()
.saturating_sub(1),
);
Action::None
}
KeyCode::Enter => {
let next_format = crate::cli::tui::form::ClaudeApiFormat::from_picker_index_for_app(
let picker_format = crate::cli::tui::form::ApiFormat::from_picker_index_for_app(
*selected, &app_type,
);
let Some(FormState::ProviderAdd(provider)) = self.form.as_mut() else {
self.overlay = Overlay::None;
return Some(Action::None);
};

let changed = provider.claude_api_format != next_format;
provider.claude_api_format = next_format;
let changed = provider.api_format != picker_format;
provider.api_format = picker_format;
self.overlay = Overlay::None;

let proxy_ready = data
.proxy
.routes_current_app_through_proxy(&provider.app_type)
.unwrap_or(false);
if changed && next_format.requires_proxy_for_app(&provider.app_type) && !proxy_ready
if changed
&& picker_format.requires_proxy_for_app(&provider.app_type)
&& !proxy_ready
{
let message = if matches!(provider.app_type, crate::app_config::AppType::Codex)
{
texts::tui_codex_api_format_requires_proxy_message(next_format.as_str())
texts::tui_codex_api_format_requires_proxy_message(picker_format.as_str())
} else {
texts::tui_claude_api_format_requires_proxy_message(next_format.as_str())
texts::tui_claude_api_format_requires_proxy_message(picker_format.as_str())
};
self.overlay = Overlay::Confirm(ConfirmOverlay {
title: texts::tui_claude_api_format_requires_proxy_title().to_string(),
title: texts::tui_api_format_requires_proxy_title().to_string(),
message,
action: ConfirmAction::ProviderApiFormatProxyNotice,
});
Expand Down
44 changes: 22 additions & 22 deletions src-tauri/src/cli/tui/app/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12073,8 +12073,8 @@ mod tests {
form.field_idx = form
.fields()
.iter()
.position(|field| *field == ProviderAddField::ClaudeApiFormat)
.expect("ClaudeApiFormat field should exist");
.position(|field| *field == ProviderAddField::ApiFormat)
.expect("ApiFormat field should exist");
} else {
panic!("expected ProviderAdd form");
}
Expand All @@ -12083,33 +12083,33 @@ mod tests {
assert!(matches!(action, Action::None));
assert!(matches!(
app.overlay,
Overlay::ClaudeApiFormatPicker { selected: 0 }
Overlay::ApiFormatPicker { selected: 0 }
));

let format = match app.form.as_ref() {
Some(super::super::form::FormState::ProviderAdd(form)) => form.claude_api_format,
Some(super::super::form::FormState::ProviderAdd(form)) => form.api_format,
other => panic!("expected ProviderAdd form, got: {other:?}"),
};
assert_eq!(format, super::super::form::ClaudeApiFormat::Anthropic);
assert_eq!(format, super::super::form::ApiFormat::Anthropic);
}

#[test]
fn provider_claude_api_format_overlay_jk_navigates_options() {
let mut app = App::new(Some(AppType::Claude));
app.overlay = Overlay::ClaudeApiFormatPicker { selected: 0 };
app.overlay = Overlay::ApiFormatPicker { selected: 0 };

let action = app.on_key(key(KeyCode::Char('j')), &data());
assert!(matches!(action, Action::None));
assert!(matches!(
app.overlay,
Overlay::ClaudeApiFormatPicker { selected: 1 }
Overlay::ApiFormatPicker { selected: 1 }
));

let action = app.on_key(key(KeyCode::Char('k')), &data());
assert!(matches!(action, Action::None));
assert!(matches!(
app.overlay,
Overlay::ClaudeApiFormatPicker { selected: 0 }
Overlay::ApiFormatPicker { selected: 0 }
));
}

Expand Down Expand Up @@ -12184,10 +12184,10 @@ mod tests {
})
));
let format = match app.form.as_ref() {
Some(super::super::form::FormState::ProviderAdd(form)) => form.claude_api_format,
Some(super::super::form::FormState::ProviderAdd(form)) => form.api_format,
other => panic!("expected ProviderAdd form, got: {other:?}"),
};
assert_eq!(format, super::super::form::ClaudeApiFormat::OpenAiChat);
assert_eq!(format, super::super::form::ApiFormat::OpenAiChat);
}

#[test]
Expand Down Expand Up @@ -12222,10 +12222,10 @@ mod tests {
assert!(matches!(action, Action::None));
assert!(matches!(app.overlay, Overlay::None));
let format = match app.form.as_ref() {
Some(super::super::form::FormState::ProviderAdd(form)) => form.claude_api_format,
Some(super::super::form::FormState::ProviderAdd(form)) => form.api_format,
other => panic!("expected ProviderAdd form, got: {other:?}"),
};
assert_eq!(format, super::super::form::ClaudeApiFormat::OpenAiChat);
assert_eq!(format, super::super::form::ApiFormat::OpenAiChat);
}

#[test]
Expand Down Expand Up @@ -12540,8 +12540,8 @@ mod tests {
form.field_idx = form
.fields()
.iter()
.position(|field| *field == ProviderAddField::ClaudeApiFormat)
.expect("ClaudeApiFormat field should exist");
.position(|field| *field == ProviderAddField::ApiFormat)
.expect("ApiFormat field should exist");
} else {
panic!("expected ProviderAdd form");
}
Expand All @@ -12560,10 +12560,10 @@ mod tests {
));

let format = match app.form.as_ref() {
Some(super::super::form::FormState::ProviderAdd(form)) => form.claude_api_format,
Some(super::super::form::FormState::ProviderAdd(form)) => form.api_format,
other => panic!("expected ProviderAdd form, got: {other:?}"),
};
assert_eq!(format, super::super::form::ClaudeApiFormat::OpenAiChat);
assert_eq!(format, super::super::form::ApiFormat::OpenAiChat);
}

#[test]
Expand All @@ -12582,8 +12582,8 @@ mod tests {
form.field_idx = form
.fields()
.iter()
.position(|field| *field == ProviderAddField::ClaudeApiFormat)
.expect("ClaudeApiFormat field should exist");
.position(|field| *field == ProviderAddField::ApiFormat)
.expect("ApiFormat field should exist");
} else {
panic!("expected ProviderAdd form");
}
Expand Down Expand Up @@ -12615,8 +12615,8 @@ mod tests {
form.field_idx = form
.fields()
.iter()
.position(|field| *field == ProviderAddField::ClaudeApiFormat)
.expect("ClaudeApiFormat field should exist");
.position(|field| *field == ProviderAddField::ApiFormat)
.expect("ApiFormat field should exist");
} else {
panic!("expected ProviderAdd form");
}
Expand All @@ -12628,10 +12628,10 @@ mod tests {
assert!(matches!(app.overlay, Overlay::None));

let format = match app.form.as_ref() {
Some(super::super::form::FormState::ProviderAdd(form)) => form.claude_api_format,
Some(super::super::form::FormState::ProviderAdd(form)) => form.api_format,
other => panic!("expected ProviderAdd form, got: {other:?}"),
};
assert_eq!(format, super::super::form::ClaudeApiFormat::OpenAiChat);
assert_eq!(format, super::super::form::ApiFormat::OpenAiChat);
}

fn failover_provider_row(
Expand Down
6 changes: 3 additions & 3 deletions src-tauri/src/cli/tui/app/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ pub enum Overlay {
selected: usize,
editing: bool,
},
ClaudeApiFormatPicker {
ApiFormatPicker {
selected: usize,
},
UsageQueryTemplatePicker {
Expand Down Expand Up @@ -737,7 +737,7 @@ impl Overlay {
| Overlay::CommonSnippetPicker { .. }
| Overlay::ProviderTestMenu { .. }
| Overlay::FailoverQueueManager { .. }
| Overlay::ClaudeApiFormatPicker { .. }
| Overlay::ApiFormatPicker { .. }
| Overlay::UsageQueryTemplatePicker { .. }
| Overlay::ManagedAccountPicker { .. }
| Overlay::ManagedAccountActionPicker { .. }
Expand Down Expand Up @@ -776,7 +776,7 @@ impl Overlay {
| Overlay::CommonSnippetPicker { .. }
| Overlay::ProviderTestMenu { .. }
| Overlay::FailoverQueueManager { .. }
| Overlay::ClaudeApiFormatPicker { .. }
| Overlay::ApiFormatPicker { .. }
| Overlay::UsageQueryTemplatePicker { .. }
| Overlay::ManagedAccountPicker { .. }
| Overlay::ManagedAccountActionPicker { .. }
Expand Down
Loading