feat: add CLI settings export/import functionality

- Implemented exportSettings and importSettings APIs for CLI settings.
- Added hooks useExportSettings and useImportSettings for managing export/import operations in the frontend.
- Updated SettingsPage to include buttons for exporting and importing CLI settings.
- Enhanced backend to handle export and import requests, including validation and conflict resolution.
- Introduced new data structures for exported settings and import options.
- Updated localization files to support new export/import features.
- Refactored CLI tool configurations to remove hardcoded model defaults, allowing dynamic model retrieval.
This commit is contained in:
catlog22
2026-02-25 21:40:24 +08:00
parent 4c2bf31525
commit b2b8688d26
24 changed files with 1287 additions and 651 deletions

View File

@@ -16,11 +16,15 @@ import {
fetchCliToolStatus,
fetchCcwInstallations,
upgradeCcwInstallation,
exportSettings,
importSettings,
type ChineseResponseStatus,
type WindowsPlatformStatus,
type CodexCliEnhancementStatus,
type CcwInstallStatus,
type CcwInstallationManifest,
type ExportedSettings,
type ImportOptions,
} from '../lib/api';
// Query key factory
@@ -32,6 +36,7 @@ export const systemSettingsKeys = {
aggregatedStatus: () => [...systemSettingsKeys.all, 'aggregatedStatus'] as const,
cliToolStatus: () => [...systemSettingsKeys.all, 'cliToolStatus'] as const,
ccwInstallations: () => [...systemSettingsKeys.all, 'ccwInstallations'] as const,
exportSettings: () => [...systemSettingsKeys.all, 'exportSettings'] as const,
};
const STALE_TIME = 60 * 1000; // 1 minute
@@ -285,3 +290,39 @@ export function useUpgradeCcwInstallation() {
error: mutation.error,
};
}
// ========================================
// Settings Export/Import Hooks
// ========================================
export function useExportSettings() {
const mutation = useMutation({
mutationFn: exportSettings,
});
return {
exportSettings: mutation.mutateAsync,
isPending: mutation.isPending,
error: mutation.error,
};
}
export function useImportSettings() {
const queryClient = useQueryClient();
const mutation = useMutation({
mutationFn: ({ data, options }: { data: ExportedSettings; options?: ImportOptions }) =>
importSettings(data, options),
onSuccess: () => {
// Invalidate all system settings queries to refresh the UI
queryClient.invalidateQueries({ queryKey: systemSettingsKeys.all });
},
});
return {
importSettings: (data: ExportedSettings, options?: ImportOptions) =>
mutation.mutateAsync({ data, options }),
isPending: mutation.isPending,
error: mutation.error,
};
}