@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.WinRMExecutor = void 0;
const winrm_client_1 = require("winrm-client");
const logger_1 = __importDefault(require("../../utils/logger"));
const WINDOWS_CMD_WRAPPER = 'powershell';
const HTTPS_PORTS = [443, 5986, 8443];
const REJECT_UNAUTHORIZED_TLS = process.env.NODE_TLS_REJECT_UNAUTHORIZED !== '0';
class WinRMExecutor {
static get instance() {
if (!WinRMExecutor._instance) {
WinRMExecutor._instance = new WinRMExecutor();
}
return WinRMExecutor._instance;
}
constructor() {
this.config = null;
this.wrapper = WINDOWS_CMD_WRAPPER;
}
init(config) {
this.config = config;
}
isConnected() {
var _a;
return !!((_a = this.config) === null || _a === void 0 ? void 0 : _a.enabled);
}
connect() {
return __awaiter(this, void 0, void 0, function* () {
var _a;
if (!((_a = this.config) === null || _a === void 0 ? void 0 : _a.enabled)) {
throw new Error('Remote execution not configured');
}
const { target: host, user: username, password = '', port } = this.config;
logger_1.default.debug('Testing WinRM connection...');
try {
const isHttps = HTTPS_PORTS.includes(port);
yield (0, winrm_client_1.runPowershell)('$true', host, username, password, port, isHttps, REJECT_UNAUTHORIZED_TLS);
logger_1.default.debug('WinRM connection successful');
}
catch (error) {
logger_1.default.error('WinRM connection test failed:', error);
throw new Error(`Failed to connect to WinRM host ${host}`);
}
});
}
executeCommand(command_1, stdin_1) {
return __awaiter(this, arguments, void 0, function* (command, stdin, rawCmd = false) {
var _a;
if (!((_a = this.config) === null || _a === void 0 ? void 0 : _a.enabled)) {
throw new Error('Remote execution not configured');
}
if (stdin) {
logger_1.default.debug('WinRM does not support stdin input, ignoring stdin parameter');
}
const { target: host, port = 5985, user: username, password = '', } = this.config;
logger_1.default.debug('Executing WinRM command:', {
host,
port,
username: username || '(not provided)',
command: command.substring(0, 50) + (command.length > 50 ? '...' : ''),
});
try {
const isHttps = HTTPS_PORTS.includes(port);
const usePowershell = !rawCmd;
const result = yield (0, winrm_client_1.runCommand)(command, host, username, password, port, usePowershell, isHttps, REJECT_UNAUTHORIZED_TLS);
logger_1.default.debug('WinRM command completed');
return result || '';
}
catch (error) {
logger_1.default.error('WinRM command execution failed:', error);
throw error;
}
});
}
disconnect() {
return __awaiter(this, void 0, void 0, function* () {
this.config = null;
logger_1.default.debug('WinRM executor reset');
});
}
}
exports.WinRMExecutor = WinRMExecutor;