nothumanallowed 16.0.13 → 16.0.15
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/constants.mjs +1 -1
- package/src/services/message-responder.mjs +103 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nothumanallowed",
|
|
3
|
-
"version": "16.0.
|
|
3
|
+
"version": "16.0.15",
|
|
4
4
|
"description": "NotHumanAllowed — 38 AI agents, 80 tools, Studio (visual agentic workflows). 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/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 = '16.0.
|
|
8
|
+
export const VERSION = '16.0.15';
|
|
9
9
|
export const BASE_URL = 'https://nothumanallowed.com/cli';
|
|
10
10
|
export const API_BASE = 'https://nothumanallowed.com/api/v1';
|
|
11
11
|
|
|
@@ -1486,6 +1486,46 @@ class TelegramResponder {
|
|
|
1486
1486
|
// Parse calendar_date / calendar_find tool output. The executor returns
|
|
1487
1487
|
// a human-readable string with each event on its own line plus the
|
|
1488
1488
|
// eventId in parentheses. We extract structured records.
|
|
1489
|
+
/**
|
|
1490
|
+
* Map a list-tool invocation to the (timeMin, timeMax) range that listEvents
|
|
1491
|
+
* would query. Used as a fallback when the textual tool output doesn't
|
|
1492
|
+
* include event IDs (calendar_month, calendar_today, etc).
|
|
1493
|
+
*/
|
|
1494
|
+
_computeRangeForListTool(toolName, args) {
|
|
1495
|
+
const now = new Date();
|
|
1496
|
+
if (toolName === 'calendar_today') {
|
|
1497
|
+
const from = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
1498
|
+
return { from, to: new Date(from.getTime() + 86400000) };
|
|
1499
|
+
}
|
|
1500
|
+
if (toolName === 'calendar_tomorrow') {
|
|
1501
|
+
const from = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1);
|
|
1502
|
+
return { from, to: new Date(from.getTime() + 86400000) };
|
|
1503
|
+
}
|
|
1504
|
+
if (toolName === 'calendar_week') {
|
|
1505
|
+
const from = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
1506
|
+
return { from, to: new Date(from.getTime() + 7 * 86400000) };
|
|
1507
|
+
}
|
|
1508
|
+
if (toolName === 'calendar_month') {
|
|
1509
|
+
let y = now.getFullYear(), m = now.getMonth();
|
|
1510
|
+
if (args?.month && /^\d{4}-\d{2}$/.test(args.month)) {
|
|
1511
|
+
const [yy, mm] = args.month.split('-');
|
|
1512
|
+
y = parseInt(yy, 10);
|
|
1513
|
+
m = parseInt(mm, 10) - 1;
|
|
1514
|
+
}
|
|
1515
|
+
return { from: new Date(y, m, 1), to: new Date(y, m + 1, 1) };
|
|
1516
|
+
}
|
|
1517
|
+
if (toolName === 'calendar_date' && args?.date && /^\d{4}-\d{2}-\d{2}$/.test(args.date)) {
|
|
1518
|
+
const [yy, mm, dd] = args.date.split('-').map(n => parseInt(n, 10));
|
|
1519
|
+
const from = new Date(yy, mm - 1, dd);
|
|
1520
|
+
return { from, to: new Date(from.getTime() + 86400000) };
|
|
1521
|
+
}
|
|
1522
|
+
if (toolName === 'calendar_upcoming') {
|
|
1523
|
+
const hours = parseInt(args?.hours || '48', 10);
|
|
1524
|
+
return { from: now, to: new Date(now.getTime() + hours * 3600000) };
|
|
1525
|
+
}
|
|
1526
|
+
return null;
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1489
1529
|
_parseEventsFromToolOutput(toolResult) {
|
|
1490
1530
|
const text = typeof toolResult === 'string' ? toolResult : JSON.stringify(toolResult || '');
|
|
1491
1531
|
const lines = text.split(/\r?\n/);
|
|
@@ -2010,18 +2050,45 @@ class TelegramResponder {
|
|
|
2010
2050
|
// If the previous turn ran a LIST/LAST-SHOWN and the user now says
|
|
2011
2051
|
// "cancellalo / eliminalo / quello / si / conferma / fallo", resolve the
|
|
2012
2052
|
// referent from this._lastContextByChatId[chatId].lastCalendarEvents.
|
|
2013
|
-
|
|
2053
|
+
// Wider regex: matches "cancellalo", "cancellali", "cancellatelo!",
|
|
2054
|
+
// "eliminali tutti", with any trailing punctuation.
|
|
2055
|
+
const isAnaphoric = /(cancell|elimin|rimuov)\w*\s*[!.?]?$/i.test(userMessage.trim())
|
|
2014
2056
|
&& !this._extractCalendarProposal(userMessage).date
|
|
2015
2057
|
&& !this._extractCalendarProposal(userMessage).title;
|
|
2016
2058
|
const isYesConfirm = /^\s*(s[ìi]\b|si\s|sì\s|ok\b|okay\b|certo\b|certamente\b|d'?accordo\b|fai|fallo|procedi|esegui|conferm[oa]|yes\b|yep\b|confirm\b|do\s*it|go\s*ahead)/i.test(userMessage.trim());
|
|
2017
|
-
if (
|
|
2018
|
-
|
|
2059
|
+
if (isAnaphoric || isYesConfirm) {
|
|
2060
|
+
// Look up the event list across multiple keys, in order of preference:
|
|
2061
|
+
// 1. exact chatId (if the caller passed one)
|
|
2062
|
+
// 2. any context key whose lastCalendarListAt is the most recent
|
|
2063
|
+
// This fixes a class of bugs where the chat UI generates a fresh
|
|
2064
|
+
// conversationId between turns, breaking the strict key lookup.
|
|
2065
|
+
let ctx = chatId ? (this._lastContextByChatId[chatId] || {}) : {};
|
|
2066
|
+
if (!ctx.lastCalendarEvents || ctx.lastCalendarEvents.length === 0) {
|
|
2067
|
+
// Fallback: scan every stored context for the most recent calendar list.
|
|
2068
|
+
let bestKey = null, bestAt = 0;
|
|
2069
|
+
for (const [k, v] of Object.entries(this._lastContextByChatId)) {
|
|
2070
|
+
if (Array.isArray(v?.lastCalendarEvents) && v.lastCalendarEvents.length > 0
|
|
2071
|
+
&& (v.lastCalendarListAt || 0) > bestAt) {
|
|
2072
|
+
bestKey = k;
|
|
2073
|
+
bestAt = v.lastCalendarListAt || 0;
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
if (bestKey) {
|
|
2077
|
+
this.log(`[direct] anaphoric fallback: chatId=${chatId} empty, using bestKey=${bestKey} (${Date.now() - bestAt}ms ago)`);
|
|
2078
|
+
ctx = this._lastContextByChatId[bestKey];
|
|
2079
|
+
}
|
|
2080
|
+
} else {
|
|
2081
|
+
this.log(`[direct] anaphoric hit: chatId=${chatId} eventsCount=${ctx.lastCalendarEvents.length}`);
|
|
2082
|
+
}
|
|
2019
2083
|
const pendingEvents = ctx.lastCalendarEvents || ctx.pendingDeleteEvents || [];
|
|
2020
2084
|
// Strict: only auto-execute if the previous turn LIST/proposal had a
|
|
2021
2085
|
// single deletable event, or if pendingDelete is explicitly set.
|
|
2022
2086
|
const eligible = ctx.pendingDeleteEvents && ctx.pendingDeleteEvents.length > 0
|
|
2023
2087
|
? ctx.pendingDeleteEvents
|
|
2024
2088
|
: (pendingEvents.length === 1 ? pendingEvents : null);
|
|
2089
|
+
if (!eligible) {
|
|
2090
|
+
this.log(`[direct] anaphoric SKIP: ${isAnaphoric ? 'anaphoric' : 'yes-confirm'} matched but no eligible event. ctx keys: ${Object.keys(this._lastContextByChatId).join(',')}`);
|
|
2091
|
+
}
|
|
2025
2092
|
if (eligible && eligible.length > 0) {
|
|
2026
2093
|
let ok = 0, ko = 0;
|
|
2027
2094
|
const failed = [];
|
|
@@ -2236,17 +2303,40 @@ class TelegramResponder {
|
|
|
2236
2303
|
const runListAndRemember = async (toolName, args, actionKey) => {
|
|
2237
2304
|
try {
|
|
2238
2305
|
const out = await executeTool(toolName, args, config);
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2306
|
+
// Parse from text first (cheap, works when tools include event IDs).
|
|
2307
|
+
let events = this._parseEventsFromToolOutput(String(out));
|
|
2308
|
+
// Fallback: tools like calendar_month don't print event IDs in their
|
|
2309
|
+
// pretty-printed output, so we MUST call listEvents() directly to
|
|
2310
|
+
// get structured objects with real Google Calendar event IDs.
|
|
2311
|
+
// Without this, anaphoric "cancellalo" can never resolve.
|
|
2312
|
+
if (events.length === 0) {
|
|
2313
|
+
try {
|
|
2314
|
+
const { listEvents } = await import('./google-calendar.mjs');
|
|
2315
|
+
const range = this._computeRangeForListTool(toolName, args);
|
|
2316
|
+
if (range) {
|
|
2317
|
+
const evs = await listEvents(config, 'primary', range.from, range.to);
|
|
2318
|
+
events = (evs || []).map(e => ({
|
|
2319
|
+
eventId: e.id,
|
|
2320
|
+
summary: e.summary || '(senza titolo)',
|
|
2321
|
+
time: (e.start || '').slice(11, 16),
|
|
2322
|
+
date: (e.start || '').slice(0, 10),
|
|
2323
|
+
}));
|
|
2324
|
+
this.log(`[direct] LIST structured fallback: ${events.length} events via listEvents(${range.from.toISOString().slice(0,10)}..${range.to.toISOString().slice(0,10)})`);
|
|
2325
|
+
}
|
|
2326
|
+
} catch (e) { this.log(`[direct] LIST structured fallback failed: ${e.message}`); }
|
|
2249
2327
|
}
|
|
2328
|
+
// Even without chatId, save to a global fallback bucket so the
|
|
2329
|
+
// anaphoric resolution can still find it.
|
|
2330
|
+
const persistKey = chatId || '__last_list__';
|
|
2331
|
+
const prev = this._lastContextByChatId[persistKey] || {};
|
|
2332
|
+
this._lastContextByChatId[persistKey] = {
|
|
2333
|
+
...prev,
|
|
2334
|
+
lastCalendarEvents: events,
|
|
2335
|
+
lastCalendarListAt: Date.now(),
|
|
2336
|
+
lastCalendarSource: { tool: toolName, args },
|
|
2337
|
+
};
|
|
2338
|
+
this.log(`[direct] LIST stored: chatId=${persistKey} eventsCount=${events.length} tool=${toolName}`);
|
|
2339
|
+
try { saveTelegramContext(this._lastContextByChatId); } catch (e) { this.log(`[direct] persist FAILED: ${e.message}`); }
|
|
2250
2340
|
return { action: actionKey, success: true, message: String(out) };
|
|
2251
2341
|
} catch (e) { return { action: actionKey, success: false, message: `Errore: ${e.message}` }; }
|
|
2252
2342
|
};
|