@2501-ai/cli
Version:
[](https://www.npmjs.com/package/@2501-ai/cli) [](https://www.2501.ai/research/full-humaneval-benchmark) [); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RemoteExecutor = void 0;
const logger_1 = __importDefault(require("../utils/logger"));
const sshExecutor_1 = require("./executors/sshExecutor");
const winrmExecutor_1 = require("./executors/winrmExecutor");
class RemoteExecutor {
constructor() {
this.config = null;
this.executor = null;
}
static get instance() {
if (!RemoteExecutor._instance) {
RemoteExecutor._instance = new RemoteExecutor();
}
return RemoteExecutor._instance;
}
get isConnected() {
var _a, _b;
return (_b = (_a = this.executor) === null || _a === void 0 ? void 0 : _a.isConnected()) !== null && _b !== void 0 ? _b : false;
}
init(config) {
if (!config || !config.enabled) {
throw new Error('Remote config is not enabled');
}
if (config.type === 'winrm') {
this.executor = winrmExecutor_1.WinRMExecutor.instance;
}
else if (config.type === 'ssh') {
this.executor = sshExecutor_1.SSHExecutor.instance;
}
else {
throw new Error(`Unsupported remote execution type: ${config.type}`);
}
this.config = config;
this.executor.init(config);
logger_1.default.debug(`Initialized ${config.type} remote executor for ${config.target}:${config.port}`);
}
isConfigured() {
return this.executor !== null && this.config !== null;
}
isEnabled() {
var _a, _b;
return (_b = (this.isConfigured() && ((_a = this.config) === null || _a === void 0 ? void 0 : _a.enabled))) !== null && _b !== void 0 ? _b : false;
}
throwIfNotInitialized() {
if (!this.isConfigured()) {
throw new Error(`Remote executor not initialized. Call init() first.`);
}
}
executeCommand(command, stdin, rawCmd) {
return __awaiter(this, void 0, void 0, function* () {
this.throwIfNotInitialized();
logger_1.default.debug(`Executing remote command: ${command}`);
return this.executor.executeCommand(command, stdin, rawCmd);
});
}
validateConnection() {
return __awaiter(this, void 0, void 0, function* () {
this.throwIfNotInitialized();
logger_1.default.debug(`Validating connection for host: ${this.config.target}`);
return (yield this.detectRemotePlatform()) !== null;
});
}
detectRemotePlatform() {
return __awaiter(this, void 0, void 0, function* () {
this.throwIfNotInitialized();
yield this.connect();
if (this.config.type === 'winrm') {
this.config.platform = 'windows';
return 'windows';
}
try {
logger_1.default.debug('Attempting FortiGate platform detection with "get system status" command');
const fortigateResult = yield this.executeCommand('get system status', undefined, true);
if (fortigateResult &&
(fortigateResult.includes('FortiGate') ||
fortigateResult.includes('FortiOS') ||
(fortigateResult.includes('Version:') &&
fortigateResult.includes('Model:')))) {
logger_1.default.debug('FortiGate system detected');
this.config.platform = 'fortigate';
return 'fortigate';
}
}
catch (error) {
logger_1.default.debug('FortiGate platform detection failed, falling back to standard detection:', error);
}
try {
const result = yield this.executeCommand('uname -s 2>&1 || ver', '', true);
logger_1.default.debug('Platform detection result:', result);
if (result.toLowerCase().includes('windows') ||
result.toLowerCase().includes('microsoft')) {
this.config.platform = 'windows';
return 'windows';
}
if (result.includes('Linux') ||
result.includes('Darwin') ||
result.includes('FreeBSD')) {
this.config.platform = 'unix';
return 'unix';
}
logger_1.default.debug('Platform detection unclear, defaulting to unix. Result:', result);
this.config.platform = 'unix';
return 'unix';
}
catch (error) {
logger_1.default.debug('Platform detection failed:', error);
return null;
}
});
}
disconnect() {
return __awaiter(this, void 0, void 0, function* () {
if (this.executor &&
'disconnect' in this.executor &&
this.executor.disconnect) {
yield this.executor.disconnect();
logger_1.default.debug('Remote executor disconnected');
}
this.executor = null;
this.config = null;
});
}
connect() {
return __awaiter(this, void 0, void 0, function* () {
this.throwIfNotInitialized();
yield this.executor.connect();
});
}
getConfig() {
this.throwIfNotInitialized();
return this.config;
}
}
exports.RemoteExecutor = RemoteExecutor;