fix(api): lazy-load node-pty to prevent API crash on missing native binary #525

Merged
jason.woltje merged 2 commits from fix/api-node-pty-crash into main 2026-02-26 13:46:27 +00:00
Showing only changes of commit a7fbc1ccc8 - Show all commits

View File

@@ -14,13 +14,16 @@
*/ */
import { Injectable, Logger, OnModuleInit } from "@nestjs/common"; import { Injectable, Logger, OnModuleInit } from "@nestjs/common";
import type { IPty } from "node-pty";
import type { Socket } from "socket.io"; import type { Socket } from "socket.io";
import { randomUUID } from "node:crypto"; import { randomUUID } from "node:crypto";
// Lazy-loaded in onModuleInit via dynamic import() to prevent crash // Lazy-loaded in onModuleInit via dynamic import() to prevent crash
// if the native binary is missing. node-pty requires a compiled .node // if the native binary is missing. node-pty requires a compiled .node
// binary which may not be available in all Docker environments. // binary which may not be available in all Docker environments.
type NodePtyModule = typeof import("node-pty"); interface NodePtyModule {
spawn: (file: string, args: string[], options: Record<string, unknown>) => IPty;
}
let pty: NodePtyModule | null = null; let pty: NodePtyModule | null = null;
/** Maximum concurrent PTY sessions per workspace */ /** Maximum concurrent PTY sessions per workspace */
@@ -36,7 +39,7 @@ const DEFAULT_ROWS = 24;
export interface TerminalSession { export interface TerminalSession {
sessionId: string; sessionId: string;
workspaceId: string; workspaceId: string;
pty: import("node-pty").IPty; pty: IPty;
name?: string; name?: string;
createdAt: Date; createdAt: Date;
} }