Move terminal sessions to worker process
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user