Move terminal sessions to worker process

This commit is contained in:
Mohamed Boudra
2026-04-30 22:35:22 +07:00
parent 39f100b4bb
commit 4d840dafd4
10 changed files with 1126 additions and 4 deletions
@@ -0,0 +1,122 @@
import type { TerminalExitInfo, ServerMessage, ClientMessage } from "./terminal.js";
import type { TerminalState } from "../shared/messages.js";
export interface WorkerTerminalInfo {
id: string;
name: string;
cwd: string;
title?: string;
}
export interface WorkerCreateTerminalOptions {
id?: string;
cwd: string;
name?: string;
title?: string;
env?: Record<string, string>;
command?: string;
args?: string[];
}
export interface WorkerKillAndWaitOptions {
gracefulTimeoutMs?: number;
forceTimeoutMs?: number;
}
export type TerminalWorkerRequest =
| {
type: "getTerminals";
requestId: string;
cwd: string;
}
| {
type: "createTerminal";
requestId: string;
options: WorkerCreateTerminalOptions;
}
| {
type: "registerCwdEnv";
requestId: string;
cwd: string;
env: Record<string, string>;
}
| {
type: "killTerminal";
requestId: string;
terminalId: string;
}
| {
type: "killTerminalAndWait";
requestId: string;
terminalId: string;
options?: WorkerKillAndWaitOptions;
}
| {
type: "listDirectories";
requestId: string;
}
| {
type: "killAll";
requestId: string;
}
| {
type: "send";
requestId: string;
terminalId: string;
message: ClientMessage;
};
export type TerminalWorkerResponse =
| {
type: "response";
requestId: string;
ok: true;
result?: unknown;
}
| {
type: "response";
requestId: string;
ok: false;
error: string;
};
export type TerminalWorkerEvent =
| {
type: "terminalCreated";
terminal: WorkerTerminalInfo;
state: TerminalState;
}
| {
type: "terminalRemoved";
terminalId: string;
cwd: string;
}
| {
type: "terminalMessage";
terminalId: string;
message: ServerMessage;
}
| {
type: "terminalExit";
terminalId: string;
info: TerminalExitInfo;
}
| {
type: "terminalTitleChange";
terminalId: string;
title?: string;
}
| {
type: "terminalCommandFinished";
terminalId: string;
info: {
exitCode: number | null;
};
}
| {
type: "terminalsChanged";
cwd: string;
terminals: WorkerTerminalInfo[];
};
export type TerminalWorkerToParentMessage = TerminalWorkerResponse | TerminalWorkerEvent;