refactor: remove unused functions and frontend declarations
- Remove four redundant Rust functions - Update tests to call the active implementations directly - Remove unused TypeScript state, parameters, and imports - Resolve unused-code compiler warnings
This commit is contained in:
1 parent
a9297b86cc
commit
0725f6ed8a
8 files changed
+25
-58
No files matched your search
@@ -3200,17 +3200,6 @@ pub(crate) fn claude_effective_context_window(
|
||||
context_window
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn claude_code_max_context_tokens(
|
||||
mappings: &ClaudeDesktopModelMappings,
|
||||
models: &[AgentModelOption],
|
||||
) -> Result<u64, String> {
|
||||
let model = mappings.sonnet.as_str();
|
||||
let context_window = claude_effective_context_window(models, model, mappings.sonnet_1m)
|
||||
.ok_or_else(|| format!("CPA 模型 API 未返回 Claude Code 主模型 {model} 的上下文窗口"))?;
|
||||
Ok(context_window)
|
||||
}
|
||||
|
||||
pub(crate) fn agent_model_display_name<'a>(
|
||||
models: &'a [AgentModelOption],
|
||||
model_name: &'a str,
|
||||
|
||||
@@ -1667,15 +1667,6 @@ pub(crate) fn sanitize_gui_config(config: &mut GuiConfigFile) -> Result<bool, St
|
||||
Ok(changed)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn write_gui_config_legacy(config: &GuiConfigFile) -> Result<(), String> {
|
||||
validate_gui_config(config)?;
|
||||
let config_path = gui_config_path()?;
|
||||
let content =
|
||||
toml::to_string_pretty(config).map_err(|err| format!("序列化 GUI 配置失败: {err}"))?;
|
||||
write_yaml_if_changed(&config_path, &content).map(|_| ())
|
||||
}
|
||||
|
||||
pub(crate) fn write_gui_config(config: &GuiConfigFile) -> Result<(), String> {
|
||||
write_gui_config_to_path(config, &gui_config_path()?)
|
||||
}
|
||||
|
||||
+6
-11
@@ -1894,14 +1894,6 @@ fn set_collector_status(
|
||||
});
|
||||
}
|
||||
|
||||
fn persist_queue_items(
|
||||
root: &Path,
|
||||
items: Vec<Value>,
|
||||
config: &GuiConfigFile,
|
||||
) -> Result<usize, String> {
|
||||
persist_queue_items_from_source(root, HTTP_USAGE_QUEUE_SOURCE, items, config)
|
||||
}
|
||||
|
||||
fn persist_queue_items_from_source(
|
||||
root: &Path,
|
||||
source: &str,
|
||||
@@ -4722,8 +4714,9 @@ mod tests {
|
||||
let root = test_root("usage-control-messages");
|
||||
initialize_usage_storage_at(&root).unwrap();
|
||||
let config = GuiConfigFile::default();
|
||||
let inserted = persist_queue_items(
|
||||
let inserted = persist_queue_items_from_source(
|
||||
&root,
|
||||
HTTP_USAGE_QUEUE_SOURCE,
|
||||
vec![
|
||||
serde_json::json!({"refresh": true}),
|
||||
serde_json::json!({"support_refresh": true}),
|
||||
@@ -4791,8 +4784,9 @@ mod tests {
|
||||
let root = test_root("queue-events-without-generation");
|
||||
initialize_usage_storage_at(&root).unwrap();
|
||||
let config = GuiConfigFile::default();
|
||||
let inserted = persist_queue_items(
|
||||
let inserted = persist_queue_items_from_source(
|
||||
&root,
|
||||
HTTP_USAGE_QUEUE_SOURCE,
|
||||
vec![
|
||||
serde_json::json!({
|
||||
"timestamp": "2026-07-29T10:00:00+08:00",
|
||||
@@ -4856,8 +4850,9 @@ mod tests {
|
||||
let root = test_root("usage-failure-details");
|
||||
initialize_usage_storage_at(&root).unwrap();
|
||||
let config = GuiConfigFile::default();
|
||||
persist_queue_items(
|
||||
persist_queue_items_from_source(
|
||||
&root,
|
||||
HTTP_USAGE_QUEUE_SOURCE,
|
||||
vec![
|
||||
serde_json::json!({
|
||||
"timestamp": "2026-07-29T10:00:00+08:00",
|
||||
|
||||
+17
-13
@@ -214,17 +214,6 @@ enum ParseResult {
|
||||
Incomplete,
|
||||
}
|
||||
|
||||
fn parse_resp_frame(input: &[u8], offset: usize, depth: usize) -> Result<ParseResult, String> {
|
||||
let mut remaining_bulk_bytes = SUBSCRIPTION_LIMITS.max_total_bulk_bytes;
|
||||
parse_resp_frame_with_limits(
|
||||
input,
|
||||
offset,
|
||||
depth,
|
||||
SUBSCRIPTION_LIMITS,
|
||||
&mut remaining_bulk_bytes,
|
||||
)
|
||||
}
|
||||
|
||||
fn parse_resp_frame_with_limits(
|
||||
input: &[u8],
|
||||
offset: usize,
|
||||
@@ -384,7 +373,15 @@ mod tests {
|
||||
#[test]
|
||||
fn parses_usage_subscription_message() {
|
||||
let input = b"*3\r\n$7\r\nmessage\r\n$5\r\nusage\r\n$16\r\n{\"request_id\":1}\r\n";
|
||||
let ParseResult::Complete(value, consumed) = parse_resp_frame(input, 0, 0).unwrap() else {
|
||||
let mut remaining_bulk_bytes = SUBSCRIPTION_LIMITS.max_total_bulk_bytes;
|
||||
let ParseResult::Complete(value, consumed) = parse_resp_frame_with_limits(
|
||||
input,
|
||||
0,
|
||||
0,
|
||||
SUBSCRIPTION_LIMITS,
|
||||
&mut remaining_bulk_bytes,
|
||||
)
|
||||
.unwrap() else {
|
||||
panic!("expected complete RESP frame");
|
||||
};
|
||||
assert_eq!(consumed, input.len());
|
||||
@@ -396,7 +393,14 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn rejects_oversized_arrays() {
|
||||
let error = match parse_resp_frame(b"*17\r\n", 0, 0) {
|
||||
let mut remaining_bulk_bytes = SUBSCRIPTION_LIMITS.max_total_bulk_bytes;
|
||||
let error = match parse_resp_frame_with_limits(
|
||||
b"*17\r\n",
|
||||
0,
|
||||
0,
|
||||
SUBSCRIPTION_LIMITS,
|
||||
&mut remaining_bulk_bytes,
|
||||
) {
|
||||
Err(error) => error,
|
||||
_ => panic!("expected oversized RESP array to fail"),
|
||||
};
|
||||
|
||||
@@ -423,7 +423,6 @@ export const exclusionsForModelSelection = (
|
||||
};
|
||||
|
||||
export const modelSelectionForDiscovery = (
|
||||
section: ProviderSection,
|
||||
configuredModels: ModelOption[],
|
||||
discoveredModels: ModelOption[],
|
||||
excludedModelsText: string,
|
||||
@@ -1773,7 +1772,7 @@ export function ApiProviderDialog({
|
||||
setSelectedModelNames((current) =>
|
||||
initialized
|
||||
? reconcileModelSelection(models, draft.models, current, 'refresh')
|
||||
: modelSelectionForDiscovery(activeSection, draft.models, models, draft.excludedModelsText ?? ''));
|
||||
: modelSelectionForDiscovery(draft.models, models, draft.excludedModelsText ?? ''));
|
||||
discoverySelectionInitializedRef.current = true;
|
||||
if (activeCategory === 'deepseek') setModelDiscoveryReady(true);
|
||||
if (!models.length) setModelError(t('apiAccess.error.noAvailableModels'));
|
||||
@@ -1792,7 +1791,7 @@ export function ApiProviderDialog({
|
||||
return;
|
||||
}
|
||||
discoverySelectionInitializedRef.current = false;
|
||||
setSelectedModelNames(modelSelectionForDiscovery(activeSection, draft.models, discoveredModels, draft.excludedModelsText ?? ''));
|
||||
setSelectedModelNames(modelSelectionForDiscovery(draft.models, discoveredModels, draft.excludedModelsText ?? ''));
|
||||
setModelDiscoveryOpen(true);
|
||||
void discoverModels();
|
||||
};
|
||||
|
||||
@@ -7,11 +7,9 @@ import {
|
||||
} from "react";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import {
|
||||
AlertCircle,
|
||||
ArrowLeft,
|
||||
ArrowRight,
|
||||
Check,
|
||||
CheckCircle2,
|
||||
ChevronDown,
|
||||
Languages,
|
||||
LoaderCircle,
|
||||
@@ -115,7 +113,6 @@ export function EasyModePage({
|
||||
const [activeStep, setActiveStep] = useState<SetupStep>(1);
|
||||
const [authMethod, setAuthMethod] = useState<AuthMethod>("oauth");
|
||||
|
||||
const [loadingSources, setLoadingSources] = useState(true);
|
||||
const [authFiles, setAuthFiles] = useState<Record<string, unknown>[]>([]);
|
||||
const [apiCounts, setApiCounts] = useState<Record<ApiSection, number>>({
|
||||
"openai-compatibility": 0,
|
||||
@@ -124,7 +121,6 @@ export function EasyModePage({
|
||||
gemini: 0,
|
||||
codex: 0,
|
||||
});
|
||||
const [availableModels, setAvailableModels] = useState<ModelOption[]>([]);
|
||||
|
||||
const [oauthLoggingIn, setOauthLoggingIn] = useState<OAuthProviderId | null>(null);
|
||||
const oauthFeedback = useAppNotice();
|
||||
@@ -168,7 +164,6 @@ export function EasyModePage({
|
||||
const [langMenuOpen, setLangMenuOpen] = useState(false);
|
||||
|
||||
const refreshSourceStatus = useCallback(async () => {
|
||||
setLoadingSources(true);
|
||||
try {
|
||||
const authFilesPayload = await managementApi.get("/auth-files");
|
||||
const files = responseList(authFilesPayload, "files");
|
||||
@@ -202,8 +197,6 @@ export function EasyModePage({
|
||||
setApiCounts(counts);
|
||||
} catch (e) {
|
||||
console.warn("Failed to refresh source status", e);
|
||||
} finally {
|
||||
setLoadingSources(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -84,7 +84,6 @@ export function VersionManagementPage() {
|
||||
|
||||
const {
|
||||
status: coreStatus,
|
||||
statusError,
|
||||
refreshStatus,
|
||||
} = useCoreRuntime();
|
||||
const {
|
||||
|
||||
@@ -357,7 +357,6 @@ describe('API 接入配置合并', () => {
|
||||
|
||||
it('普通提供商没有模型映射时按真实开放状态初始化勾选', () => {
|
||||
const selected = modelSelectionForDiscovery(
|
||||
'codex-api-key',
|
||||
[],
|
||||
[{ name: 'gpt-5.4' }, { name: 'gpt-image-1.5' }, { name: 'gpt-image-2' }],
|
||||
'gpt-image-*',
|
||||
@@ -368,7 +367,6 @@ describe('API 接入配置合并', () => {
|
||||
|
||||
it('普通提供商未限制模型时默认显示全部已开放', () => {
|
||||
const selected = modelSelectionForDiscovery(
|
||||
'codex-api-key',
|
||||
[],
|
||||
[{ name: 'gpt-5.4' }, { name: 'gpt-image-2' }],
|
||||
'',
|
||||
@@ -379,7 +377,6 @@ describe('API 接入配置合并', () => {
|
||||
|
||||
it('OpenAI 兼容接入没有已保存模型时默认全选发现的模型', () => {
|
||||
const selected = modelSelectionForDiscovery(
|
||||
'openai-compatibility',
|
||||
[],
|
||||
[{ name: 'model-a' }, { name: 'model-b' }],
|
||||
'',
|
||||
|
||||
Reference in new issue
Block a user