feat: complete stage 4 cleanup and code formatting

This commit completes stage 4 of the refactoring plan, focusing on cleanup
and optimization of the modernized codebase.

## Key Changes

### Code Cleanup
- Remove legacy `src/lib/styles.ts` (no longer needed)
- Remove old modal components (`ImportProgressModal.tsx`, `ProviderList.tsx`)
- Streamline `src/lib/tauri-api.ts` from 712 lines to 17 lines (-97.6%)
  - Remove global `window.api` pollution
  - Keep only event listeners (`tauriEvents.onProviderSwitched`)
  - All API calls now use modular `@/lib/api/*` layer

### Type System
- Clean up `src/vite-env.d.ts` (remove 156 lines of outdated types)
- Remove obsolete global type declarations
- All TypeScript checks pass with zero errors

### Code Formatting
- Format all source files with Prettier (82 files)
- Fix formatting issues in 15 files:
  - App.tsx and core components
  - MCP management components
  - Settings module components
  - Provider management components
  - UI components

### Documentation Updates
- Update `REFACTORING_CHECKLIST.md` with stage 4 progress
- Mark completed tasks in `REFACTORING_MASTER_PLAN.md`

## Impact

**Code Reduction:**
- Total: -1,753 lines, +384 lines (net -1,369 lines)
- tauri-api.ts: 712 → 17 lines (-97.6%)
- Removed styles.ts: -82 lines
- Removed vite-env.d.ts declarations: -156 lines

**Quality Improvements:**
-  Zero TypeScript errors
-  Zero TODO/FIXME comments
-  100% Prettier compliant
-  Zero `window.api` references
-  Fully modular API layer

## Testing
- [x] TypeScript compilation passes
- [x] Code formatting validated
- [x] No linting errors

Stage 4 completion: 100%
Ready for stage 5 (testing and bug fixes)
This commit is contained in:
Jason
2025-10-16 12:13:51 +08:00
parent 2b45af118f
commit f3e7412a14
46 changed files with 384 additions and 1753 deletions

156
src/vite-env.d.ts vendored
View File

@@ -1,159 +1,3 @@
/// <reference types="vite/client" />
import {
Provider,
Settings,
CustomEndpoint,
McpStatus,
McpConfigResponse,
McpServer,
McpServerSpec,
} from "./types";
import { AppType } from "./lib/tauri-api";
import type { UnlistenFn } from "@tauri-apps/api/event";
interface ImportResult {
success: boolean;
message?: string;
}
interface ConfigStatus {
exists: boolean;
path: string;
error?: string;
}
declare global {
interface Window {
api: {
getProviders: (app?: AppType) => Promise<Record<string, Provider>>;
getCurrentProvider: (app?: AppType) => Promise<string>;
addProvider: (provider: Provider, app?: AppType) => Promise<boolean>;
deleteProvider: (id: string, app?: AppType) => Promise<boolean>;
updateProvider: (provider: Provider, app?: AppType) => Promise<boolean>;
switchProvider: (providerId: string, app?: AppType) => Promise<boolean>;
importCurrentConfigAsDefault: (app?: AppType) => Promise<ImportResult>;
getClaudeCodeConfigPath: () => Promise<string>;
getClaudeConfigStatus: () => Promise<ConfigStatus>;
getConfigStatus: (app?: AppType) => Promise<ConfigStatus>;
getConfigDir: (app?: AppType) => Promise<string>;
saveFileDialog: (defaultName: string) => Promise<string | null>;
openFileDialog: () => Promise<string | null>;
exportConfigToFile: (filePath: string) => Promise<{
success: boolean;
message: string;
filePath: string;
}>;
importConfigFromFile: (filePath: string) => Promise<{
success: boolean;
message: string;
backupId?: string;
}>;
selectConfigDirectory: (defaultPath?: string) => Promise<string | null>;
openConfigFolder: (app?: AppType) => Promise<void>;
openExternal: (url: string) => Promise<void>;
updateTrayMenu: () => Promise<boolean>;
onProviderSwitched: (
callback: (data: { appType: string; providerId: string }) => void,
) => Promise<UnlistenFn>;
getSettings: () => Promise<Settings>;
saveSettings: (settings: Settings) => Promise<boolean>;
restartApp: () => Promise<boolean>;
checkForUpdates: () => Promise<void>;
isPortable: () => Promise<boolean>;
getAppConfigPath: () => Promise<string>;
openAppConfigFolder: () => Promise<void>;
// Claude 插件配置能力
getClaudePluginStatus: () => Promise<ConfigStatus>;
readClaudePluginConfig: () => Promise<string | null>;
applyClaudePluginConfig: (options: {
official: boolean;
}) => Promise<boolean>;
isClaudePluginApplied: () => Promise<boolean>;
// 查询供应商用量
queryProviderUsage: (
providerId: string,
app: AppType
) => Promise<import("./types").UsageResult>;
// Claude MCP
getClaudeMcpStatus: () => Promise<McpStatus>;
readClaudeMcpConfig: () => Promise<string | null>;
upsertClaudeMcpServer: (
id: string,
spec: McpServerSpec | Record<string, any>,
) => Promise<boolean>;
deleteClaudeMcpServer: (id: string) => Promise<boolean>;
validateMcpCommand: (cmd: string) => Promise<boolean>;
// 新config.json 为 SSOT 的 MCP API
getMcpConfig: (app?: AppType) => Promise<McpConfigResponse>;
upsertMcpServerInConfig: (
app: AppType | undefined,
id: string,
spec: McpServer,
options?: { syncOtherSide?: boolean },
) => Promise<boolean>;
deleteMcpServerInConfig: (
app: AppType | undefined,
id: string,
) => Promise<boolean>;
setMcpEnabled: (
app: AppType | undefined,
id: string,
enabled: boolean,
) => Promise<boolean>;
syncEnabledMcpToClaude: () => Promise<boolean>;
syncEnabledMcpToCodex: () => Promise<boolean>;
importMcpFromClaude: () => Promise<number>;
importMcpFromCodex: () => Promise<number>;
// 读取当前生效live的 provider settings根据 appType
// Codex: { auth: object, config: string }
// Claude: settings.json 内容
getLiveProviderSettings: (app?: AppType) => Promise<any>;
testApiEndpoints: (
urls: string[],
options?: { timeoutSecs?: number },
) => Promise<
Array<{
url: string;
latency: number | null;
status?: number;
error?: string;
}>
>;
// 自定义端点管理
getCustomEndpoints: (
appType: AppType,
providerId: string,
) => Promise<CustomEndpoint[]>;
addCustomEndpoint: (
appType: AppType,
providerId: string,
url: string,
) => Promise<void>;
removeCustomEndpoint: (
appType: AppType,
providerId: string,
url: string,
) => Promise<void>;
updateEndpointLastUsed: (
appType: AppType,
providerId: string,
url: string,
) => Promise<void>;
// Provider sort order management
updateProvidersSortOrder: (
updates: Array<{ id: string; sortIndex: number }>,
app?: AppType,
) => Promise<boolean>;
// app_config_dir override via Store
getAppConfigDirOverride: () => Promise<string | null>;
setAppConfigDirOverride: (path: string | null) => Promise<boolean>;
};
platform: {
isMac: boolean;
};
__TAURI__?: any;
}
}
export {};