Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
251 lines
8.0 KiB
TypeScript
251 lines
8.0 KiB
TypeScript
import { useCallback, useMemo } from 'react';
|
|
import type {
|
|
DockerContainerAction,
|
|
DockerImageManageAction,
|
|
SystemdUnitAction,
|
|
SystemdUnitInfo,
|
|
TmuxManageAction,
|
|
} from '../../domain/systemManager/types';
|
|
import { netcattyBridge } from '../../infrastructure/services/netcattyBridge';
|
|
|
|
export function useSystemManagerBackend() {
|
|
const probeSystemCapabilities = useCallback(async (sessionId: string) => {
|
|
const bridge = netcattyBridge.get();
|
|
if (!bridge?.probeSystemCapabilities) {
|
|
return { success: false as const, error: 'probeSystemCapabilities unavailable' };
|
|
}
|
|
return bridge.probeSystemCapabilities(sessionId);
|
|
}, []);
|
|
|
|
const listSystemProcesses = useCallback(async (sessionId: string) => {
|
|
const bridge = netcattyBridge.get();
|
|
if (!bridge?.listSystemProcesses) {
|
|
return { success: false as const, error: 'listSystemProcesses unavailable' };
|
|
}
|
|
return bridge.listSystemProcesses(sessionId);
|
|
}, []);
|
|
|
|
const signalSystemProcess = useCallback(async (options: {
|
|
sessionId: string;
|
|
pid: number;
|
|
signal?: string;
|
|
nice?: number;
|
|
}) => {
|
|
const bridge = netcattyBridge.get();
|
|
if (!bridge?.signalSystemProcess) {
|
|
return { success: false as const, error: 'signalSystemProcess unavailable' };
|
|
}
|
|
return bridge.signalSystemProcess(options);
|
|
}, []);
|
|
|
|
const listTmuxSessions = useCallback(async (sessionId: string) => {
|
|
const bridge = netcattyBridge.get();
|
|
if (!bridge?.listTmuxSessions) {
|
|
return { success: false as const, error: 'listTmuxSessions unavailable' };
|
|
}
|
|
return bridge.listTmuxSessions(sessionId);
|
|
}, []);
|
|
|
|
const createTmuxSession = useCallback(async (options: {
|
|
sessionId: string;
|
|
name: string;
|
|
command?: string;
|
|
}) => {
|
|
const bridge = netcattyBridge.get();
|
|
if (!bridge?.createTmuxSession) {
|
|
return { success: false as const, error: 'createTmuxSession unavailable' };
|
|
}
|
|
return bridge.createTmuxSession(options);
|
|
}, []);
|
|
|
|
const listTmuxWindows = useCallback(async (options: { sessionId: string; sessionName: string }) => {
|
|
const bridge = netcattyBridge.get();
|
|
if (!bridge?.listTmuxWindows) {
|
|
return { success: false as const, error: 'listTmuxWindows unavailable' };
|
|
}
|
|
return bridge.listTmuxWindows(options);
|
|
}, []);
|
|
|
|
const listTmuxPanes = useCallback(async (options: {
|
|
sessionId: string;
|
|
sessionName: string;
|
|
windowIndex: number;
|
|
}) => {
|
|
const bridge = netcattyBridge.get();
|
|
if (!bridge?.listTmuxPanes) {
|
|
return { success: false as const, error: 'listTmuxPanes unavailable' };
|
|
}
|
|
return bridge.listTmuxPanes(options);
|
|
}, []);
|
|
|
|
const listTmuxClients = useCallback(async (options: { sessionId: string; sessionName?: string }) => {
|
|
const bridge = netcattyBridge.get();
|
|
if (!bridge?.listTmuxClients) {
|
|
return { success: false as const, error: 'listTmuxClients unavailable' };
|
|
}
|
|
return bridge.listTmuxClients(options);
|
|
}, []);
|
|
|
|
const tmuxAction = useCallback(async (options: { sessionId: string } & TmuxManageAction) => {
|
|
const bridge = netcattyBridge.get();
|
|
if (!bridge?.tmuxAction) {
|
|
return { success: false as const, error: 'tmuxAction unavailable' };
|
|
}
|
|
return bridge.tmuxAction(options);
|
|
}, []);
|
|
|
|
const listDockerContainers = useCallback(async (sessionId: string) => {
|
|
const bridge = netcattyBridge.get();
|
|
if (!bridge?.listDockerContainers) {
|
|
return { success: false as const, error: 'listDockerContainers unavailable' };
|
|
}
|
|
return bridge.listDockerContainers(sessionId);
|
|
}, []);
|
|
|
|
const listDockerImages = useCallback(async (sessionId: string) => {
|
|
const bridge = netcattyBridge.get();
|
|
if (!bridge?.listDockerImages) {
|
|
return { success: false as const, error: 'listDockerImages unavailable' };
|
|
}
|
|
return bridge.listDockerImages(sessionId);
|
|
}, []);
|
|
|
|
const getDockerStats = useCallback(async (options: { sessionId: string; ids?: string[] }) => {
|
|
const bridge = netcattyBridge.get();
|
|
if (!bridge?.getDockerStats) {
|
|
return { success: false as const, error: 'getDockerStats unavailable' };
|
|
}
|
|
return bridge.getDockerStats(options);
|
|
}, []);
|
|
|
|
const listAccelerators = useCallback(async (sessionId: string) => {
|
|
const bridge = netcattyBridge.get();
|
|
if (!bridge?.listAccelerators) {
|
|
return { success: false as const, error: 'listAccelerators unavailable' };
|
|
}
|
|
return bridge.listAccelerators(sessionId);
|
|
}, []);
|
|
|
|
const listListeningPorts = useCallback(async (sessionId: string) => {
|
|
const bridge = netcattyBridge.get();
|
|
if (!bridge?.listListeningPorts) {
|
|
return { success: false as const, error: 'listListeningPorts unavailable' };
|
|
}
|
|
return bridge.listListeningPorts(sessionId);
|
|
}, []);
|
|
|
|
const listSystemServices = useCallback(async (sessionId: string) => {
|
|
const bridge = netcattyBridge.get();
|
|
if (!bridge?.listSystemServices) {
|
|
return { success: false as const, error: 'listSystemServices unavailable' };
|
|
}
|
|
return bridge.listSystemServices(sessionId);
|
|
}, []);
|
|
|
|
const systemServiceAction = useCallback(async (options: {
|
|
sessionId: string;
|
|
unitName: string;
|
|
action: SystemdUnitAction;
|
|
scope?: SystemdUnitInfo['scope'];
|
|
}) => {
|
|
const bridge = netcattyBridge.get();
|
|
if (!bridge?.systemServiceAction) {
|
|
return { success: false as const, error: 'systemServiceAction unavailable' };
|
|
}
|
|
return bridge.systemServiceAction(options);
|
|
}, []);
|
|
|
|
const dockerInspect = useCallback(async (options: { sessionId: string; containerId: string }) => {
|
|
const bridge = netcattyBridge.get();
|
|
if (!bridge?.dockerInspect) {
|
|
return { success: false as const, error: 'dockerInspect unavailable' };
|
|
}
|
|
return bridge.dockerInspect(options);
|
|
}, []);
|
|
|
|
const dockerImageInspect = useCallback(async (options: { sessionId: string; imageId: string }) => {
|
|
const bridge = netcattyBridge.get();
|
|
if (!bridge?.dockerImageInspect) {
|
|
return { success: false as const, error: 'dockerImageInspect unavailable' };
|
|
}
|
|
return bridge.dockerImageInspect(options);
|
|
}, []);
|
|
|
|
const dockerAction = useCallback(async (options: {
|
|
sessionId: string;
|
|
containerId: string;
|
|
action: DockerContainerAction;
|
|
newName?: string;
|
|
}) => {
|
|
const bridge = netcattyBridge.get();
|
|
if (!bridge?.dockerAction) {
|
|
return { success: false as const, error: 'dockerAction unavailable' };
|
|
}
|
|
return bridge.dockerAction(options);
|
|
}, []);
|
|
|
|
const dockerImageAction = useCallback(async (options: { sessionId: string } & DockerImageManageAction) => {
|
|
const bridge = netcattyBridge.get();
|
|
if (!bridge?.dockerImageAction) {
|
|
return { success: false as const, error: 'dockerImageAction unavailable' };
|
|
}
|
|
return bridge.dockerImageAction(options);
|
|
}, []);
|
|
|
|
const openTerminalPopup = useCallback(async (
|
|
payload: Parameters<NonNullable<NetcattyBridge['openTerminalPopup']>>[0],
|
|
) => {
|
|
const bridge = netcattyBridge.get();
|
|
if (!bridge?.openTerminalPopup) {
|
|
return { success: false as const, error: 'openTerminalPopup unavailable' };
|
|
}
|
|
return bridge.openTerminalPopup(payload);
|
|
}, []);
|
|
|
|
return useMemo(() => ({
|
|
probeSystemCapabilities,
|
|
listSystemProcesses,
|
|
signalSystemProcess,
|
|
listTmuxSessions,
|
|
createTmuxSession,
|
|
listTmuxWindows,
|
|
listTmuxPanes,
|
|
listTmuxClients,
|
|
tmuxAction,
|
|
listDockerContainers,
|
|
listDockerImages,
|
|
getDockerStats,
|
|
listAccelerators,
|
|
listListeningPorts,
|
|
listSystemServices,
|
|
systemServiceAction,
|
|
dockerInspect,
|
|
dockerImageInspect,
|
|
dockerAction,
|
|
dockerImageAction,
|
|
openTerminalPopup,
|
|
}), [
|
|
probeSystemCapabilities,
|
|
listSystemProcesses,
|
|
signalSystemProcess,
|
|
listTmuxSessions,
|
|
createTmuxSession,
|
|
listTmuxWindows,
|
|
listTmuxPanes,
|
|
listTmuxClients,
|
|
tmuxAction,
|
|
listDockerContainers,
|
|
listDockerImages,
|
|
getDockerStats,
|
|
listAccelerators,
|
|
listListeningPorts,
|
|
listSystemServices,
|
|
systemServiceAction,
|
|
dockerInspect,
|
|
dockerImageInspect,
|
|
dockerAction,
|
|
dockerImageAction,
|
|
openTerminalPopup,
|
|
]);
|
|
}
|