nothumanallowed 12.1.1 → 12.1.3
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 +139 -1
- package/src/constants.mjs +1 -1
- package/src/services/tool-executor.mjs +6 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nothumanallowed",
|
|
3
|
-
"version": "12.1.
|
|
3
|
+
"version": "12.1.3",
|
|
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' },
|
|
@@ -1683,6 +1799,28 @@ export async function cmdUI(args) {
|
|
|
1683
1799
|
}
|
|
1684
1800
|
}
|
|
1685
1801
|
|
|
1802
|
+
// Auto-correct: if LLM called web_search but query looks like a domain, switch to browser_open
|
|
1803
|
+
for (const a of actions) {
|
|
1804
|
+
if (a.action === 'web_search' && a.params.query) {
|
|
1805
|
+
const q = a.params.query.trim();
|
|
1806
|
+
// Detect domain names: corriere.it, github.com, youtube.com, etc.
|
|
1807
|
+
if (/^[a-zA-Z0-9][a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(q) || /^(https?:\/\/)/.test(q)) {
|
|
1808
|
+
a.action = 'browser_open';
|
|
1809
|
+
a.params = { url: q.startsWith('http') ? q : 'https://' + q };
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
|
|
1814
|
+
// Auto-correct: if user said "visita/vai su/apri/open" + domain but LLM used web_search
|
|
1815
|
+
const visitMatch = msg.match(/(?:visita|vai su|apri|open|go to)\s+([a-zA-Z0-9][a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/i);
|
|
1816
|
+
if (visitMatch && !actions.some(a => a.action === 'browser_open')) {
|
|
1817
|
+
const domain = visitMatch[1];
|
|
1818
|
+
// Remove any web_search that was targeting this domain
|
|
1819
|
+
const wsIdx = actions.findIndex(a => a.action === 'web_search' && a.params.query?.toLowerCase().includes(domain.toLowerCase()));
|
|
1820
|
+
if (wsIdx >= 0) actions.splice(wsIdx, 1);
|
|
1821
|
+
actions.unshift({ action: 'browser_open', params: { url: 'https://' + domain } });
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1686
1824
|
for (const { action, params } of actions) {
|
|
1687
1825
|
// Force screenshot=true on web_search if user asked for screenshot
|
|
1688
1826
|
if (action === 'web_search' && wantsScreenshot && !params.screenshot) {
|
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.1.
|
|
8
|
+
export const VERSION = '12.1.3';
|
|
9
9
|
export const BASE_URL = 'https://nothumanallowed.com/cli';
|
|
10
10
|
export const API_BASE = 'https://nothumanallowed.com/api/v1';
|
|
11
11
|
|
|
@@ -445,8 +445,12 @@ TOOLS:
|
|
|
445
445
|
|
|
446
446
|
RULES:
|
|
447
447
|
- ABSOLUTE RULE: NEVER LIE. NEVER fabricate, invent, or guess information. If you do not know, say "I don't know." If a tool fails, say it failed. If you cannot see something, say so. Honesty is MORE important than being helpful.
|
|
448
|
-
- CRITICAL
|
|
449
|
-
|
|
448
|
+
- CRITICAL ROUTING RULE — browser_open vs web_search:
|
|
449
|
+
* "visita X.com", "vai su X", "apri X.com", "open X", "go to X" → ALWAYS use browser_open("https://X.com"). The user wants to SEE a specific website.
|
|
450
|
+
* "cerca X", "search for X", "find X", "look up X" → ALWAYS use web_search. The user wants search results.
|
|
451
|
+
* If the user mentions a SPECIFIC domain name (corriere.it, github.com, youtube.com, etc.) → browser_open, NEVER web_search.
|
|
452
|
+
* NEVER open Google/Bing/DuckDuckGo in the browser — use web_search for searching.
|
|
453
|
+
* web_search is for QUERIES. browser_open is for URLS. If it looks like a website name, it's a URL.
|
|
450
454
|
- For search/read operations, execute immediately and present results conversationally.
|
|
451
455
|
- For write/send/delete operations (gmail_send, gmail_reply, gmail_delete, calendar_create, calendar_move, calendar_update, contact_delete, task_done, notify_remind, file_write), DESCRIBE what you're about to do and include the JSON block so the system can ask the user for confirmation.
|
|
452
456
|
- For schedule_meeting and schedule_draft_email, execute immediately — these are read operations that suggest slots.
|