mirror of
https://github.com/tale/headplane.git
synced 2026-08-09 21:49:23 +00:00
feat: initial webssh tooling
This commit is contained in:
+13
-1
@@ -10,10 +10,12 @@ import {
|
||||
} from 'node:fs/promises';
|
||||
import { exit } from 'node:process';
|
||||
import { createInterface } from 'node:readline';
|
||||
import { Readable, Writable } from 'node:stream';
|
||||
import { setTimeout } from 'node:timers/promises';
|
||||
import { type } from 'arktype';
|
||||
import { HostInfo } from '~/types';
|
||||
import log from '~/utils/log';
|
||||
import { SSHMultiplexer, createSSHMultiplexer } from '../agent/ssh';
|
||||
import type { HeadplaneConfig } from '../config/schema';
|
||||
|
||||
interface LogResponse {
|
||||
@@ -113,6 +115,7 @@ class AgentManager {
|
||||
>;
|
||||
|
||||
private spawnProcess: ChildProcess | null;
|
||||
multiplexer: SSHMultiplexer | null;
|
||||
private agentId: string | null;
|
||||
|
||||
constructor(
|
||||
@@ -124,6 +127,7 @@ class AgentManager {
|
||||
this.config = config;
|
||||
this.headscaleUrl = headscaleUrl;
|
||||
this.spawnProcess = null;
|
||||
this.multiplexer = null;
|
||||
this.agentId = null;
|
||||
this.startAgent();
|
||||
|
||||
@@ -184,7 +188,7 @@ class AgentManager {
|
||||
);
|
||||
this.spawnProcess = spawn(this.config.executable_path, [], {
|
||||
detached: false,
|
||||
stdio: ['pipe', 'pipe', 'pipe'],
|
||||
stdio: ['pipe', 'pipe', 'pipe', 'pipe', 'pipe'],
|
||||
env: {
|
||||
HOME: process.env.HOME,
|
||||
HEADPLANE_EMBEDDED: 'true',
|
||||
@@ -210,6 +214,14 @@ class AgentManager {
|
||||
return;
|
||||
}
|
||||
|
||||
const sshInput = this.spawnProcess.stdio[3];
|
||||
const sshOutput = this.spawnProcess.stdio[4];
|
||||
|
||||
if (sshInput && sshOutput) {
|
||||
log.info('agent', 'Using SSH multiplexer manager');
|
||||
this.multiplexer = createSSHMultiplexer(this.spawnProcess);
|
||||
}
|
||||
|
||||
const rlStdout = createInterface({
|
||||
input: this.spawnProcess.stdout,
|
||||
crlfDelay: Number.POSITIVE_INFINITY,
|
||||
|
||||
Reference in New Issue
Block a user