nothumanallowed 12.1.2 → 12.2.0
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 +1 -1
- package/src/commands/ui.mjs +154 -2
- package/src/constants.mjs +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nothumanallowed",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.2.0",
|
|
4
4
|
"description": "NotHumanAllowed — 38 AI agents, 80 tools. Email, calendar, browser automation, screen capture, canvas, cron/heartbeat, Alexandria E2E messaging, GitHub, Notion, Slack, voice chat, free AI (Liara), 28 languages. Zero-dependency CLI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/src/commands/ui.mjs
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import http from 'http';
|
|
11
11
|
import os from 'os';
|
|
12
12
|
import crypto from 'crypto';
|
|
13
|
+
import zlib from 'zlib';
|
|
13
14
|
import { exec } from 'child_process';
|
|
14
15
|
import fs from 'fs';
|
|
15
16
|
import path from 'path';
|
|
@@ -59,6 +60,80 @@ import {
|
|
|
59
60
|
|
|
60
61
|
const DEFAULT_PORT = 3847;
|
|
61
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Extract text from PDF buffer — zero dependencies.
|
|
65
|
+
* Handles text-based PDFs (not scanned images).
|
|
66
|
+
* Extracts text from PDF stream objects using basic PDF parsing.
|
|
67
|
+
*/
|
|
68
|
+
function extractTextFromPdf(buffer) {
|
|
69
|
+
try {
|
|
70
|
+
const raw = buffer.toString('latin1');
|
|
71
|
+
const texts = [];
|
|
72
|
+
|
|
73
|
+
// Extract text from BT...ET blocks (PDF text objects)
|
|
74
|
+
const btRegex = /BT[\s\S]*?ET/g;
|
|
75
|
+
let match;
|
|
76
|
+
while ((match = btRegex.exec(raw)) !== null) {
|
|
77
|
+
const block = match[0];
|
|
78
|
+
// Extract Tj (show string) and TJ (show array) operators
|
|
79
|
+
const tjRegex = /\(([^)]*)\)\s*Tj|\[([^\]]*)\]\s*TJ/g;
|
|
80
|
+
let tj;
|
|
81
|
+
while ((tj = tjRegex.exec(block)) !== null) {
|
|
82
|
+
if (tj[1]) texts.push(tj[1]);
|
|
83
|
+
if (tj[2]) {
|
|
84
|
+
// TJ array: extract strings from parenthesized elements
|
|
85
|
+
const arr = tj[2];
|
|
86
|
+
const strRegex = /\(([^)]*)\)/g;
|
|
87
|
+
let s;
|
|
88
|
+
while ((s = strRegex.exec(arr)) !== null) {
|
|
89
|
+
texts.push(s[1]);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Also try to extract from FlateDecode streams (compressed text)
|
|
96
|
+
// This handles most modern PDFs
|
|
97
|
+
const streamRegex = /stream\r?\n([\s\S]*?)\r?\nendstream/g;
|
|
98
|
+
while ((match = streamRegex.exec(raw)) !== null) {
|
|
99
|
+
try {
|
|
100
|
+
const { inflateSync } = zlib;
|
|
101
|
+
const inflated = inflateSync(Buffer.from(match[1], 'latin1')).toString('latin1');
|
|
102
|
+
const btInner = /BT[\s\S]*?ET/g;
|
|
103
|
+
let m2;
|
|
104
|
+
while ((m2 = btInner.exec(inflated)) !== null) {
|
|
105
|
+
const block = m2[0];
|
|
106
|
+
const tjR = /\(([^)]*)\)\s*Tj|\[([^\]]*)\]\s*TJ/g;
|
|
107
|
+
let t;
|
|
108
|
+
while ((t = tjR.exec(block)) !== null) {
|
|
109
|
+
if (t[1]) texts.push(t[1]);
|
|
110
|
+
if (t[2]) {
|
|
111
|
+
const sr = /\(([^)]*)\)/g;
|
|
112
|
+
let ss;
|
|
113
|
+
while ((ss = sr.exec(t[2])) !== null) texts.push(ss[1]);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
} catch { /* not a flate stream or decompression failed */ }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Decode PDF escape sequences
|
|
121
|
+
let result = texts.join(' ')
|
|
122
|
+
.replace(/\\n/g, '\n')
|
|
123
|
+
.replace(/\\r/g, '\r')
|
|
124
|
+
.replace(/\\t/g, '\t')
|
|
125
|
+
.replace(/\\\(/g, '(')
|
|
126
|
+
.replace(/\\\)/g, ')')
|
|
127
|
+
.replace(/\\\\/g, '\\')
|
|
128
|
+
.replace(/\s+/g, ' ')
|
|
129
|
+
.trim();
|
|
130
|
+
|
|
131
|
+
return result;
|
|
132
|
+
} catch {
|
|
133
|
+
return '';
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
62
137
|
// ── Agent loader ──────────────────────────────────────────────────────────
|
|
63
138
|
|
|
64
139
|
function loadAgentCards() {
|
|
@@ -1289,7 +1364,48 @@ export async function cmdUI(args) {
|
|
|
1289
1364
|
const pdfPrompt = body.message || `Read and analyze this PDF document "${body.pdfName}". Extract all text content, summarize key information.`;
|
|
1290
1365
|
let pdfResponse = '';
|
|
1291
1366
|
|
|
1292
|
-
if (provider === '
|
|
1367
|
+
if (provider === 'nha') {
|
|
1368
|
+
// NHA Free tier: extract text from PDF, then send to Liara chat
|
|
1369
|
+
// Decode PDF base64 and extract text content
|
|
1370
|
+
const pdfBuffer = Buffer.from(body.pdfBase64, 'base64');
|
|
1371
|
+
const pdfText = extractTextFromPdf(pdfBuffer);
|
|
1372
|
+
if (!pdfText || pdfText.length < 10) {
|
|
1373
|
+
// Fallback: send first page as image to vision model
|
|
1374
|
+
const r = await fetch('https://nothumanallowed.com/api/v1/liara/vision', {
|
|
1375
|
+
method: 'POST',
|
|
1376
|
+
headers: { 'Content-Type': 'application/json' },
|
|
1377
|
+
body: JSON.stringify({ image_base64: body.pdfBase64, prompt: pdfPrompt }),
|
|
1378
|
+
});
|
|
1379
|
+
if (r.ok) {
|
|
1380
|
+
const d = await r.json();
|
|
1381
|
+
pdfResponse = d.description || d.text || 'Could not extract content from this PDF.';
|
|
1382
|
+
} else {
|
|
1383
|
+
pdfResponse = 'Could not read this PDF. Try a text-based PDF or use Claude/Gemini for scanned documents.';
|
|
1384
|
+
}
|
|
1385
|
+
} else {
|
|
1386
|
+
// Send extracted text to Liara chat
|
|
1387
|
+
const truncatedText = pdfText.slice(0, 12000);
|
|
1388
|
+
const r = await fetch('https://nothumanallowed.com/api/v1/liara/chat', {
|
|
1389
|
+
method: 'POST',
|
|
1390
|
+
headers: { 'Content-Type': 'application/json' },
|
|
1391
|
+
body: JSON.stringify({
|
|
1392
|
+
model: 'nha-v1',
|
|
1393
|
+
messages: [
|
|
1394
|
+
{ role: 'system', content: enrichedSystemPrompt },
|
|
1395
|
+
{ role: 'user', content: `[PDF: ${body.pdfName}]\n\n${truncatedText}\n\n---\n\n${pdfPrompt}` },
|
|
1396
|
+
],
|
|
1397
|
+
max_tokens: 4096,
|
|
1398
|
+
chat_template_kwargs: { enable_thinking: false },
|
|
1399
|
+
}),
|
|
1400
|
+
});
|
|
1401
|
+
if (r.ok) {
|
|
1402
|
+
const d = await r.json();
|
|
1403
|
+
pdfResponse = d.choices?.[0]?.message?.content || '';
|
|
1404
|
+
} else {
|
|
1405
|
+
pdfResponse = 'Error reading PDF via Liara.';
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
} else if (provider === 'anthropic') {
|
|
1293
1409
|
const r = await fetch('https://api.anthropic.com/v1/messages', {
|
|
1294
1410
|
method: 'POST',
|
|
1295
1411
|
headers: { 'Content-Type': 'application/json', 'x-api-key': apiKey, 'anthropic-version': '2023-06-01' },
|
|
@@ -1788,8 +1904,44 @@ export async function cmdUI(args) {
|
|
|
1788
1904
|
toolResults.push({ action, result: resultStr });
|
|
1789
1905
|
sendSSE('tool', { action, status: 'done', result: typeof resultStr === 'string' ? resultStr.slice(0, 500) : '' });
|
|
1790
1906
|
|
|
1907
|
+
// After web_search: open first result in browser + send canvas with results
|
|
1908
|
+
if (action === 'web_search' && resultStr.length > 50) {
|
|
1909
|
+
try {
|
|
1910
|
+
// Extract first URL from results
|
|
1911
|
+
const urlMatch = resultStr.match(/https?:\/\/[^\s)<]+/);
|
|
1912
|
+
if (urlMatch) {
|
|
1913
|
+
const be = await import('../services/browser-engine.mjs');
|
|
1914
|
+
sendSSE('tool', { action: 'browser_open', status: 'executing' });
|
|
1915
|
+
await be.browserOpen(urlMatch[0]);
|
|
1916
|
+
sendSSE('tool', { action: 'browser_open', status: 'done', result: 'Opened ' + urlMatch[0] });
|
|
1917
|
+
// Capture frame for monitor
|
|
1918
|
+
await new Promise(r => setTimeout(r, 1500));
|
|
1919
|
+
const frame = await be.browserScreenshot({ fullPage: false, format: 'jpeg', quality: 40 });
|
|
1920
|
+
if (!frame.error) {
|
|
1921
|
+
const info = await be.browserInfo();
|
|
1922
|
+
const thumbDir = path.join(NHA_DIR, 'screenshots');
|
|
1923
|
+
fs.mkdirSync(thumbDir, { recursive: true });
|
|
1924
|
+
const thumbFile = `thumb-${Date.now()}.jpg`;
|
|
1925
|
+
fs.writeFileSync(path.join(thumbDir, thumbFile), Buffer.from(frame.base64, 'base64'));
|
|
1926
|
+
if (!res._browserThumbs) res._browserThumbs = [];
|
|
1927
|
+
res._browserThumbs.push({ file: thumbFile, url: (info.url || '').slice(0, 80) });
|
|
1928
|
+
sendSSE('browser_frame', { file: thumbFile, format: 'jpeg', url: (info.url || '').slice(0, 80) });
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
// Send canvas with structured search results
|
|
1933
|
+
const lines = resultStr.split('\n').filter(l => l.trim());
|
|
1934
|
+
const canvasHtml = `<html><head><meta charset="utf-8"><style>body{font-family:system-ui;background:#0a0a0a;color:#ccc;padding:20px;margin:0}h2{color:#00ff41;font-size:16px;margin:0 0 16px}a{color:#00e5ff;text-decoration:none}.r{padding:12px;border:1px solid #222;border-radius:8px;margin-bottom:8px;background:#111}.r:hover{border-color:#00ff41}.t{font-size:14px;margin-bottom:4px}.s{font-size:11px;color:#666}</style></head><body><h2>🔍 Search Results</h2>${lines.slice(0, 8).map(l => {
|
|
1935
|
+
const um = l.match(/https?:\/\/[^\s)]+/);
|
|
1936
|
+
const title = l.replace(/^\d+\.\s*/, '').replace(/https?:\/\/\S+/g, '').trim();
|
|
1937
|
+
return '<div class="r">' + (um ? '<a href="' + um[0] + '" target="_blank">' : '') + '<div class="t">' + title.replace(/</g, '<') + '</div>' + (um ? '<div class="s">' + um[0] + '</div></a>' : '') + '</div>';
|
|
1938
|
+
}).join('')}</body></html>`;
|
|
1939
|
+
sendSSE('canvas', { markers: `[CANVAS_RENDER]${JSON.stringify({ html: canvasHtml, title: 'Search Results' })}[/CANVAS_RENDER]` });
|
|
1940
|
+
} catch { /* non-critical: search results still shown as text */ }
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1791
1943
|
// Send live browser frame after browser/search/fetch actions — save as thumbnail file for persistence
|
|
1792
|
-
if ((action.startsWith('browser_') && action !== 'browser_close') || action === '
|
|
1944
|
+
if ((action.startsWith('browser_') && action !== 'browser_close') || action === 'fetch_url') {
|
|
1793
1945
|
try {
|
|
1794
1946
|
const be = await import('../services/browser-engine.mjs');
|
|
1795
1947
|
if (be.isBrowserRunning()) {
|
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 = '12.
|
|
8
|
+
export const VERSION = '12.2.0';
|
|
9
9
|
export const BASE_URL = 'https://nothumanallowed.com/cli';
|
|
10
10
|
export const API_BASE = 'https://nothumanallowed.com/api/v1';
|
|
11
11
|
|