Files
openchamber/packages/web/src/api/terminal.ts
T
Bohdan Triapitsyn d4a8c4d2e1 feat(terminal): refactor runtime and add mobile workspace (#2280)
Replace the legacy terminal flow with a shared authenticated WebSocket
runtime used across web, desktop, relay, and mobile surfaces.

- introduce the v3 terminal protocol with scoped attachments, snapshots,
  ordered output, bounded replay history, reconnects, and explicit lifecycle
- harden PTY creation, restart, resize, close, force-kill, idle cleanup,
  shell selection, login mode, environment sanitization, and appearance sync
- add runtime-aware terminal APIs with relay authentication and Electron parity
- add a fullscreen mobile terminal workspace with touch scrolling,
  long-press selection, safe-area controls, quick keys, and Ctrl/Alt input
- add terminal selection attachments, preview detection, project actions,
  shell settings, and localized UI
- harden Ghostty rendering, resize recovery, Unicode handling, block
  characters, line height, and stale-row behavior
- remove the obsolete terminal SSE path and update reverse-proxy guidance
- expand terminal runtime, transport, input, selection, and store coverage
- avoid duplicate web builds when preparing mobile assets in root CI builds
2026-07-17 13:17:21 +03:00

78 lines
2.0 KiB
TypeScript

import {
connectTerminalStream,
createTerminalSession,
resizeTerminal,
updateTerminalAppearance,
sendTerminalInput,
closeTerminal,
restartTerminalSession,
forceKillTerminal,
listTerminalShells,
} from '@openchamber/ui/lib/terminalApi';
import type {
TerminalAPI,
TerminalHandlers,
CreateTerminalOptions,
ResizeTerminalPayload,
TerminalSession,
ForceKillOptions,
} from '@openchamber/ui/lib/api/types';
export const createWebTerminalAPI = (): TerminalAPI => ({
async listShells() {
return listTerminalShells();
},
async createSession(options: CreateTerminalOptions): Promise<TerminalSession> {
return createTerminalSession(options);
},
connect(sessionId: string, handlers: TerminalHandlers) {
const unsubscribe = connectTerminalStream(
sessionId,
handlers.onEvent,
handlers.onError
);
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);
},
async updateAppearance(sessionId, appearance): Promise<void> {
await updateTerminalAppearance(sessionId, appearance);
},
async close(sessionId: string): Promise<void> {
await closeTerminal(sessionId);
},
async restartSession(
currentSessionId: string,
options: CreateTerminalOptions
): Promise<TerminalSession> {
return restartTerminalSession(currentSessionId, {
cwd: options.cwd ?? '',
cols: options.cols,
rows: options.rows,
themeMode: options.themeMode,
terminalBackground: options.terminalBackground,
terminalForeground: options.terminalForeground,
shell: options.shell,
loginShell: options.loginShell,
});
},
async forceKill(options: ForceKillOptions): Promise<void> {
await forceKillTerminal(options);
},
});