nothumanallowed 9.9.4 → 9.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nothumanallowed",
3
- "version": "9.9.4",
3
+ "version": "9.9.5",
4
4
  "description": "NotHumanAllowed — 38 AI agents, 53 tools. Email, calendar, browser automation, screen capture, canvas, cron/heartbeat, GitHub, Notion, Slack, voice chat, 28 languages. Zero-dependency CLI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1869,17 +1869,56 @@ export async function cmdUI(args) {
1869
1869
 
1870
1870
  const server = http.createServer(handleRequest);
1871
1871
 
1872
- // ── WebSocket via ws package (compatible with Node.js 20-24+) ──────
1873
- let wss = null;
1874
- try {
1875
- const { WebSocketServer } = await import('ws');
1876
- wss = new WebSocketServer({ server });
1877
- wss.on('connection', (ws) => {
1878
- ws.on('error', () => {});
1872
+ // ── WebSocket handler accept browser WS and relay daemon events ──
1873
+ server.on('upgrade', (req, socket) => {
1874
+ const key = req.headers['sec-websocket-key'];
1875
+ if (!key) { socket.destroy(); return; }
1876
+
1877
+ const acceptKey = crypto
1878
+ .createHash('sha1')
1879
+ .update(key + '258EAFA5-E914-47DA-95CA-5AB5DC86C11B')
1880
+ .digest('base64');
1881
+
1882
+ socket.write(
1883
+ 'HTTP/1.1 101 Switching Protocols\r\n' +
1884
+ 'Upgrade: websocket\r\n' +
1885
+ 'Connection: Upgrade\r\n' +
1886
+ 'Sec-WebSocket-Accept: ' + acceptKey + '\r\n' +
1887
+ '\r\n'
1888
+ );
1889
+
1890
+ // Connect to daemon WS on port 3848 and relay messages
1891
+ let daemonWs = null;
1892
+ try {
1893
+ const daemonReq = http.request({
1894
+ hostname: '127.0.0.1', port: 3848, path: '/',
1895
+ headers: { 'Upgrade': 'websocket', 'Connection': 'Upgrade', 'Sec-WebSocket-Key': crypto.randomBytes(16).toString('base64'), 'Sec-WebSocket-Version': '13' },
1896
+ });
1897
+ daemonReq.on('upgrade', (res, daemonSocket) => {
1898
+ daemonWs = daemonSocket;
1899
+ // Relay daemon → browser
1900
+ daemonSocket.on('data', (buf) => { try { socket.write(buf); } catch {} });
1901
+ daemonSocket.on('close', () => {});
1902
+ daemonSocket.on('error', () => {});
1903
+ });
1904
+ daemonReq.on('error', () => {}); // daemon not running — WS works without it
1905
+ daemonReq.end();
1906
+ } catch {}
1907
+
1908
+ // Handle browser → daemon (ping/pong)
1909
+ socket.on('data', (buf) => {
1910
+ if (buf.length < 2) return;
1911
+ const opcode = buf[0] & 0x0f;
1912
+ if (opcode === 0x08) { socket.end(); if (daemonWs) daemonWs.end(); return; }
1913
+ if (opcode === 0x09) { // ping → pong
1914
+ const pong = Buffer.alloc(2);
1915
+ pong[0] = 0x8a; pong[1] = 0;
1916
+ socket.write(pong);
1917
+ }
1879
1918
  });
1880
- } catch {
1881
- // ws package not available WS disabled, everything else works
1882
- }
1919
+ socket.on('close', () => { if (daemonWs) try { daemonWs.end(); } catch {} });
1920
+ socket.on('error', () => { if (daemonWs) try { daemonWs.end(); } catch {} });
1921
+ });
1883
1922
 
1884
1923
  server.on('error', (err) => {
1885
1924
  if (err.code === 'EADDRINUSE') {
package/src/constants.mjs CHANGED
@@ -5,7 +5,7 @@ import { fileURLToPath } from 'url';
5
5
  const __filename = fileURLToPath(import.meta.url);
6
6
  const __dirname = path.dirname(__filename);
7
7
 
8
- export const VERSION = '9.9.4';
8
+ export const VERSION = '9.9.5';
9
9
  export const BASE_URL = 'https://nothumanallowed.com/cli';
10
10
  export const API_BASE = 'https://nothumanallowed.com/api/v1';
11
11
 
@@ -1928,7 +1928,7 @@ var wsMaxRetries = 3;
1928
1928
  function connectWebSocket() {
1929
1929
  if (wsRetryCount >= wsMaxRetries) return; // Stop trying after 3 failures
1930
1930
  try {
1931
- ws = new WebSocket('ws://' + window.location.hostname + ':3848');
1931
+ ws = new WebSocket('ws://' + window.location.host + '/ws');
1932
1932
  } catch(e) { return; }
1933
1933
 
1934
1934
  ws.onopen = function() {