nothumanallowed 12.1.2 → 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 +117 -1
- package/src/constants.mjs +1 -1
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' },
|
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
|
|