2025-12-07 19:32:53 +02:00
|
|
|
import {
|
|
|
|
|
connectTerminalStream,
|
|
|
|
|
createTerminalSession,
|
|
|
|
|
resizeTerminal,
|
2026-07-17 13:17:21 +03:00
|
|
|
updateTerminalAppearance,
|
2025-12-07 19:32:53 +02:00
|
|
|
sendTerminalInput,
|
|
|
|
|
closeTerminal,
|
2025-12-10 00:25:02 +02:00
|
|
|
restartTerminalSession,
|
|
|
|
|
forceKillTerminal,
|
2026-07-17 13:17:21 +03:00
|
|
|
listTerminalShells,
|
2026-08-24 14:28:45 +03:00
|
|
|
listTerminalSessions,
|
|
|
|
|
touchTerminalSessions,
|
2025-12-07 19:32:53 +02:00
|
|
|
} from '@openchamber/ui/lib/terminalApi';
|
|
|
|
|
import type {
|
|
|
|
|
TerminalAPI,
|
|
|
|
|
TerminalHandlers,
|
|
|
|
|
CreateTerminalOptions,
|
|
|
|
|
ResizeTerminalPayload,
|
|
|
|
|
TerminalSession,
|
2025-12-10 00:25:02 +02:00
|
|
|
ForceKillOptions,
|
2025-12-07 19:32:53 +02:00
|
|
|
} from '@openchamber/ui/lib/api/types';
|
|
|
|
|
|
|
|
|
|
export const createWebTerminalAPI = (): TerminalAPI => ({
|
2026-07-17 13:17:21 +03:00
|
|
|
async listShells() {
|
|
|
|
|
return listTerminalShells();
|
|
|
|
|
},
|
|
|
|
|
|
2026-08-24 14:28:45 +03:00
|
|
|
async listSessions(cwd: string) {
|
|
|
|
|
return listTerminalSessions(cwd);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async touchSessions(sessionIds: string[]) {
|
|
|
|
|
await touchTerminalSessions(sessionIds);
|
|
|
|
|
},
|
|
|
|
|
|
2025-12-07 19:32:53 +02:00
|
|
|
async createSession(options: CreateTerminalOptions): Promise<TerminalSession> {
|
|
|
|
|
return createTerminalSession(options);
|
|
|
|
|
},
|
|
|
|
|
|
2026-07-17 13:17:21 +03:00
|
|
|
connect(sessionId: string, handlers: TerminalHandlers) {
|
2025-12-07 19:32:53 +02:00
|
|
|
const unsubscribe = connectTerminalStream(
|
|
|
|
|
sessionId,
|
|
|
|
|
handlers.onEvent,
|
2026-07-17 13:17:21 +03:00
|
|
|
handlers.onError
|
2025-12-07 19:32:53 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
close: () => unsubscribe(),
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async sendInput(sessionId: string, input: string): Promise<void> {
|
|
|
|
|
await sendTerminalInput(sessionId, input);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async resize(payload: ResizeTerminalPayload): Promise<void> {
|
|
|
|
|
await resizeTerminal(payload.sessionId, payload.cols, payload.rows);
|
|
|
|
|
},
|
|
|
|
|
|
2026-07-17 13:17:21 +03:00
|
|
|
async updateAppearance(sessionId, appearance): Promise<void> {
|
|
|
|
|
await updateTerminalAppearance(sessionId, appearance);
|
|
|
|
|
},
|
|
|
|
|
|
2025-12-07 19:32:53 +02:00
|
|
|
async close(sessionId: string): Promise<void> {
|
|
|
|
|
await closeTerminal(sessionId);
|
|
|
|
|
},
|
2025-12-10 00:25:02 +02:00
|
|
|
|
|
|
|
|
async restartSession(
|
|
|
|
|
currentSessionId: string,
|
|
|
|
|
options: CreateTerminalOptions
|
|
|
|
|
): Promise<TerminalSession> {
|
|
|
|
|
return restartTerminalSession(currentSessionId, {
|
|
|
|
|
cwd: options.cwd ?? '',
|
|
|
|
|
cols: options.cols,
|
|
|
|
|
rows: options.rows,
|
2026-07-17 13:17:21 +03:00
|
|
|
themeMode: options.themeMode,
|
|
|
|
|
terminalBackground: options.terminalBackground,
|
|
|
|
|
terminalForeground: options.terminalForeground,
|
|
|
|
|
shell: options.shell,
|
|
|
|
|
loginShell: options.loginShell,
|
2025-12-10 00:25:02 +02:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async forceKill(options: ForceKillOptions): Promise<void> {
|
|
|
|
|
await forceKillTerminal(options);
|
|
|
|
|
},
|
2025-12-07 19:32:53 +02:00
|
|
|
});
|