agent-ecosystem/src/renderer/store/slices/cliInstallerSlice.ts
iliya a30727d3b0 feat: enhance team file handling and logging improvements
- Added support for a new worker in the team file system to list teams, improving performance and reliability in team management.
- Introduced event loop lag monitoring in various IPC handlers to track and log slow operations, enhancing observability.
- Implemented caching for CLI installation status to reduce redundant calls and improve responsiveness.
- Updated project and team data services to include total session counts, optimizing data handling and performance.
- Enhanced error handling and logging across multiple services to provide clearer insights into performance issues and failures.

Made-with: Cursor
2026-03-03 22:00:11 +02:00

109 lines
3 KiB
TypeScript

/**
* CLI Installer slice — manages CLI installation status and install/update progress.
*/
import { api } from '@renderer/api';
import { createLogger } from '@shared/utils/logger';
import type { AppState } from '../types';
import type { CliInstallationStatus } from '@shared/types';
import type { StateCreator } from 'zustand';
const logger = createLogger('Store:cliInstaller');
/** Max log lines to keep in UI (reserved for future use) */
const _MAX_LOG_LINES = 50;
// =============================================================================
// Slice Interface
// =============================================================================
export interface CliInstallerSlice {
// State
cliStatus: CliInstallationStatus | null;
cliStatusLoading: boolean;
cliStatusError: string | null;
cliInstallerState:
| 'idle'
| 'checking'
| 'downloading'
| 'verifying'
| 'installing'
| 'completed'
| 'error';
cliDownloadProgress: number;
cliDownloadTransferred: number;
cliDownloadTotal: number;
cliInstallerError: string | null;
cliInstallerDetail: string | null;
cliInstallerLogs: string[];
cliInstallerRawChunks: string[];
cliCompletedVersion: string | null;
// Actions
fetchCliStatus: () => Promise<void>;
installCli: () => void;
}
let cliStatusInFlight: Promise<void> | null = null;
// =============================================================================
// Slice Creator
// =============================================================================
export const createCliInstallerSlice: StateCreator<AppState, [], [], CliInstallerSlice> = (
set
) => ({
// Initial state
cliStatus: null,
cliStatusLoading: false,
cliStatusError: null,
cliInstallerState: 'idle',
cliDownloadProgress: 0,
cliDownloadTransferred: 0,
cliDownloadTotal: 0,
cliInstallerError: null,
cliInstallerDetail: null,
cliInstallerLogs: [],
cliInstallerRawChunks: [],
cliCompletedVersion: null,
fetchCliStatus: async () => {
if (!api.cliInstaller) return;
if (cliStatusInFlight) return cliStatusInFlight;
cliStatusInFlight = (async () => {
set({ cliStatusLoading: true, cliStatusError: null });
try {
const status = await api.cliInstaller.getStatus();
set({ cliStatus: status });
} catch (error) {
const message = error instanceof Error ? error.message : 'Failed to check CLI status';
logger.error('Failed to fetch CLI status:', error);
set({ cliStatusError: message });
} finally {
set({ cliStatusLoading: false });
cliStatusInFlight = null;
}
})();
return cliStatusInFlight;
},
installCli: () => {
set({
cliInstallerState: 'checking',
cliInstallerError: null,
cliInstallerDetail: null,
cliInstallerLogs: [],
cliInstallerRawChunks: [],
cliDownloadProgress: 0,
cliDownloadTransferred: 0,
cliDownloadTotal: 0,
cliCompletedVersion: null,
});
api.cliInstaller.install().catch((error) => {
logger.error('Failed to install CLI:', error);
});
},
});