@ebowwa/channel-telegram 1.12.6 → 1.13.1
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/README.md +78 -44
- package/dist/commands/index.d.ts +1 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +3 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/restart.d.ts +7 -0
- package/dist/commands/restart.d.ts.map +1 -0
- package/dist/commands/restart.js +29 -0
- package/dist/commands/restart.js.map +1 -0
- package/dist/commands/settings.d.ts +8 -0
- package/dist/commands/settings.d.ts.map +1 -0
- package/dist/commands/settings.js +16 -0
- package/dist/commands/settings.js.map +1 -0
- package/dist/index.d.ts +83 -29
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +352 -712
- package/dist/index.js.map +1 -1
- package/package.json +8 -12
- package/src/commands/index.ts +3 -0
- package/src/commands/restart.ts +41 -0
- package/src/commands/settings.ts +24 -0
- package/src/index.ts +418 -823
- package/dist/mcp/client.d.ts +0 -50
- package/dist/mcp/client.d.ts.map +0 -1
- package/dist/mcp/client.js +0 -150
- package/dist/mcp/client.js.map +0 -1
- package/dist/mcp/index.d.ts +0 -5
- package/dist/mcp/index.d.ts.map +0 -1
- package/dist/mcp/index.js +0 -5
- package/dist/mcp/index.js.map +0 -1
- package/src/api/fetch-retry.js +0 -96
- package/src/api/keys.js +0 -25
- package/src/commands/cancel.js +0 -120
- package/src/commands/clear.js +0 -59
- package/src/commands/doppler.js +0 -118
- package/src/commands/git.js +0 -126
- package/src/commands/help.js +0 -74
- package/src/commands/index.js +0 -65
- package/src/commands/logs.js +0 -81
- package/src/commands/pause.js +0 -133
- package/src/commands/resources.js +0 -87
- package/src/commands/resume.js +0 -95
- package/src/commands/start.js +0 -68
- package/src/commands/status.js +0 -62
- package/src/commands/tools.js +0 -67
- package/src/commands/toolsoutput.js +0 -85
- package/src/commands/types.js +0 -5
- package/src/conversation-memory.js +0 -216
- package/src/index.js +0 -736
- package/src/mcp/client.ts +0 -188
- package/src/mcp/index.ts +0 -5
- package/src/types.js +0 -5
package/src/commands/resume.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* /resume command - Resume after pause or cancel
|
|
4
|
-
*
|
|
5
|
-
* Clears pause and cancel flags, allowing execution to continue.
|
|
6
|
-
*/
|
|
7
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
17
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
18
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
19
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
20
|
-
function step(op) {
|
|
21
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
22
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
23
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
24
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
25
|
-
switch (op[0]) {
|
|
26
|
-
case 0: case 1: t = op; break;
|
|
27
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
28
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
29
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
30
|
-
default:
|
|
31
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
32
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
33
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
34
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
35
|
-
if (t[2]) _.ops.pop();
|
|
36
|
-
_.trys.pop(); continue;
|
|
37
|
-
}
|
|
38
|
-
op = body.call(thisArg, _);
|
|
39
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
40
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
-
exports.registerResumeCommand = registerResumeCommand;
|
|
45
|
-
var fs_1 = require("fs");
|
|
46
|
-
var pause_1 = require("./pause");
|
|
47
|
-
var cancel_1 = require("./cancel");
|
|
48
|
-
var STATE_DIR = '/root/seed/state';
|
|
49
|
-
var PAUSE_FLAG = "".concat(STATE_DIR, "/.pause");
|
|
50
|
-
var CANCEL_FLAG = "".concat(STATE_DIR, "/.cancel");
|
|
51
|
-
function registerResumeCommand(bot, _memory, _tools) {
|
|
52
|
-
var _this = this;
|
|
53
|
-
bot.onText(/\/resume/, function (msg) { return __awaiter(_this, void 0, void 0, function () {
|
|
54
|
-
var chatId, wasPaused, wasCancelled, status_1, error_1;
|
|
55
|
-
return __generator(this, function (_a) {
|
|
56
|
-
switch (_a.label) {
|
|
57
|
-
case 0:
|
|
58
|
-
chatId = msg.chat.id;
|
|
59
|
-
_a.label = 1;
|
|
60
|
-
case 1:
|
|
61
|
-
_a.trys.push([1, 3, , 5]);
|
|
62
|
-
wasPaused = (0, fs_1.existsSync)(PAUSE_FLAG);
|
|
63
|
-
wasCancelled = (0, fs_1.existsSync)(CANCEL_FLAG);
|
|
64
|
-
// Clear both flags
|
|
65
|
-
(0, pause_1.clearPause)();
|
|
66
|
-
(0, cancel_1.clearCancel)();
|
|
67
|
-
status_1 = '';
|
|
68
|
-
if (wasPaused && wasCancelled) {
|
|
69
|
-
status_1 = '⏯️ *RESUMED*\n\nBoth pause and cancel flags cleared.';
|
|
70
|
-
}
|
|
71
|
-
else if (wasPaused) {
|
|
72
|
-
status_1 = '▶️ *RESUMED*\n\nPause flag cleared. Continuing...';
|
|
73
|
-
}
|
|
74
|
-
else if (wasCancelled) {
|
|
75
|
-
status_1 = '▶️ *RESUMED*\n\nCancel flag cleared. Ready for new tasks.';
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
status_1 = '✅ *READY*\n\nNo pause or cancel flags were set. Ready to go.';
|
|
79
|
-
}
|
|
80
|
-
return [4 /*yield*/, bot.sendMessage(chatId, status_1 + '\n\nUse /status to check current state.', { parse_mode: 'Markdown' })];
|
|
81
|
-
case 2:
|
|
82
|
-
_a.sent();
|
|
83
|
-
console.log("[RESUME] Resume requested by chat ".concat(chatId, " at ").concat(new Date().toISOString()));
|
|
84
|
-
return [3 /*break*/, 5];
|
|
85
|
-
case 3:
|
|
86
|
-
error_1 = _a.sent();
|
|
87
|
-
return [4 /*yield*/, bot.sendMessage(chatId, "\u274C Error clearing flags: ".concat(error_1), { parse_mode: 'Markdown' })];
|
|
88
|
-
case 4:
|
|
89
|
-
_a.sent();
|
|
90
|
-
return [3 /*break*/, 5];
|
|
91
|
-
case 5: return [2 /*return*/];
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}); });
|
|
95
|
-
}
|
package/src/commands/start.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* /start command - Show welcome message
|
|
4
|
-
*/
|
|
5
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
15
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
16
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
17
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
18
|
-
function step(op) {
|
|
19
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
20
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
21
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
22
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
23
|
-
switch (op[0]) {
|
|
24
|
-
case 0: case 1: t = op; break;
|
|
25
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
26
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
27
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
28
|
-
default:
|
|
29
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
30
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
31
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
32
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
33
|
-
if (t[2]) _.ops.pop();
|
|
34
|
-
_.trys.pop(); continue;
|
|
35
|
-
}
|
|
36
|
-
op = body.call(thisArg, _);
|
|
37
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
38
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.registerStartCommand = registerStartCommand;
|
|
43
|
-
function registerStartCommand(bot, _memory, _tools) {
|
|
44
|
-
var _this = this;
|
|
45
|
-
bot.onText(/\/start/, function (msg) { return __awaiter(_this, void 0, void 0, function () {
|
|
46
|
-
var chatId;
|
|
47
|
-
return __generator(this, function (_a) {
|
|
48
|
-
switch (_a.label) {
|
|
49
|
-
case 0:
|
|
50
|
-
chatId = msg.chat.id;
|
|
51
|
-
return [4 /*yield*/, bot.sendMessage(chatId, '👋 Hello! I\'m GLM Daemon Telegram Bot.\n\n' +
|
|
52
|
-
'🧠 Powered by GLM-4.7 via Z.AI API\n\n' +
|
|
53
|
-
'Commands:\n' +
|
|
54
|
-
'/start - Show this message\n' +
|
|
55
|
-
'/status - Check API status\n' +
|
|
56
|
-
'/git - Check git status & GitHub auth\n' +
|
|
57
|
-
'/doppler - Check Doppler config\n' +
|
|
58
|
-
'/tools - Show available AI tools\n' +
|
|
59
|
-
'/clear - Clear conversation memory\n' +
|
|
60
|
-
'/help - Show help\n\n' +
|
|
61
|
-
'Or just send any message for AI assistance!')];
|
|
62
|
-
case 1:
|
|
63
|
-
_a.sent();
|
|
64
|
-
return [2 /*return*/];
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}); });
|
|
68
|
-
}
|
package/src/commands/status.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* /status command - Check API status
|
|
4
|
-
*/
|
|
5
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
15
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
16
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
17
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
18
|
-
function step(op) {
|
|
19
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
20
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
21
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
22
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
23
|
-
switch (op[0]) {
|
|
24
|
-
case 0: case 1: t = op; break;
|
|
25
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
26
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
27
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
28
|
-
default:
|
|
29
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
30
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
31
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
32
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
33
|
-
if (t[2]) _.ops.pop();
|
|
34
|
-
_.trys.pop(); continue;
|
|
35
|
-
}
|
|
36
|
-
op = body.call(thisArg, _);
|
|
37
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
38
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.registerStatusCommand = registerStatusCommand;
|
|
43
|
-
var keys_1 = require("../api/keys");
|
|
44
|
-
function registerStatusCommand(bot, _memory, _tools) {
|
|
45
|
-
var _this = this;
|
|
46
|
-
bot.onText(/\/status/, function (msg) { return __awaiter(_this, void 0, void 0, function () {
|
|
47
|
-
var chatId, apiKey;
|
|
48
|
-
return __generator(this, function (_a) {
|
|
49
|
-
switch (_a.label) {
|
|
50
|
-
case 0:
|
|
51
|
-
chatId = msg.chat.id;
|
|
52
|
-
apiKey = (0, keys_1.getZAIKey)();
|
|
53
|
-
return [4 /*yield*/, bot.sendMessage(chatId, "*Bot Status*\n\n" +
|
|
54
|
-
"*AI:* GLM-4.7 via Z.AI\n" +
|
|
55
|
-
"*API:* ".concat(apiKey ? 'Connected' : 'Disconnected'), { parse_mode: 'Markdown' })];
|
|
56
|
-
case 1:
|
|
57
|
-
_a.sent();
|
|
58
|
-
return [2 /*return*/];
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}); });
|
|
62
|
-
}
|
package/src/commands/tools.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* /tools command - Show available LLM tools
|
|
4
|
-
*/
|
|
5
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
15
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
16
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
17
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
18
|
-
function step(op) {
|
|
19
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
20
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
21
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
22
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
23
|
-
switch (op[0]) {
|
|
24
|
-
case 0: case 1: t = op; break;
|
|
25
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
26
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
27
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
28
|
-
default:
|
|
29
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
30
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
31
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
32
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
33
|
-
if (t[2]) _.ops.pop();
|
|
34
|
-
_.trys.pop(); continue;
|
|
35
|
-
}
|
|
36
|
-
op = body.call(thisArg, _);
|
|
37
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
38
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.registerToolsCommand = void 0;
|
|
43
|
-
var registerToolsCommand = function (bot, _memory, tools) {
|
|
44
|
-
bot.onText(/\/tools/, function (msg) { return __awaiter(void 0, void 0, void 0, function () {
|
|
45
|
-
var chatId, toolsMsg, _i, tools_1, tool;
|
|
46
|
-
return __generator(this, function (_a) {
|
|
47
|
-
switch (_a.label) {
|
|
48
|
-
case 0:
|
|
49
|
-
chatId = msg.chat.id;
|
|
50
|
-
toolsMsg = '*🛠️ Available Tools*\n\n';
|
|
51
|
-
toolsMsg += 'The AI can use these tools:\n\n';
|
|
52
|
-
for (_i = 0, tools_1 = tools; _i < tools_1.length; _i++) {
|
|
53
|
-
tool = tools_1[_i];
|
|
54
|
-
toolsMsg += "*".concat(tool.name, "*\n");
|
|
55
|
-
toolsMsg += "".concat(tool.description, "\n\n");
|
|
56
|
-
}
|
|
57
|
-
toolsMsg += '_Just ask the AI to use them!_';
|
|
58
|
-
toolsMsg += '\nExample: "Show me system info" or "List files in /root"';
|
|
59
|
-
return [4 /*yield*/, bot.sendMessage(chatId, toolsMsg, { parse_mode: 'Markdown' })];
|
|
60
|
-
case 1:
|
|
61
|
-
_a.sent();
|
|
62
|
-
return [2 /*return*/];
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}); });
|
|
66
|
-
};
|
|
67
|
-
exports.registerToolsCommand = registerToolsCommand;
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* /toolsoutput command - Toggle tool output messages
|
|
4
|
-
*
|
|
5
|
-
* When disabled, tools still execute but their output isn't sent to Telegram
|
|
6
|
-
*/
|
|
7
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
17
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
18
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
19
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
20
|
-
function step(op) {
|
|
21
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
22
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
23
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
24
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
25
|
-
switch (op[0]) {
|
|
26
|
-
case 0: case 1: t = op; break;
|
|
27
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
28
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
29
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
30
|
-
default:
|
|
31
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
32
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
33
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
34
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
35
|
-
if (t[2]) _.ops.pop();
|
|
36
|
-
_.trys.pop(); continue;
|
|
37
|
-
}
|
|
38
|
-
op = body.call(thisArg, _);
|
|
39
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
40
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
-
exports.isToolOutputEnabled = isToolOutputEnabled;
|
|
45
|
-
exports.registerToolsOutputCommand = registerToolsOutputCommand;
|
|
46
|
-
// Global state for tool output visibility
|
|
47
|
-
var toolOutputEnabled = true;
|
|
48
|
-
function isToolOutputEnabled() {
|
|
49
|
-
return toolOutputEnabled;
|
|
50
|
-
}
|
|
51
|
-
function registerToolsOutputCommand(bot, _memory, _tools) {
|
|
52
|
-
var _this = this;
|
|
53
|
-
bot.onText(/\/toolsoutput(?:\s+(on|off|toggle))?/, function (msg, match) { return __awaiter(_this, void 0, void 0, function () {
|
|
54
|
-
var chatId, subCommand, status, emoji;
|
|
55
|
-
var _a;
|
|
56
|
-
return __generator(this, function (_b) {
|
|
57
|
-
switch (_b.label) {
|
|
58
|
-
case 0:
|
|
59
|
-
chatId = msg.chat.id;
|
|
60
|
-
subCommand = (_a = match === null || match === void 0 ? void 0 : match[1]) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
61
|
-
if (subCommand === 'on') {
|
|
62
|
-
toolOutputEnabled = true;
|
|
63
|
-
}
|
|
64
|
-
else if (subCommand === 'off') {
|
|
65
|
-
toolOutputEnabled = false;
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
// toggle or no arg = toggle
|
|
69
|
-
toolOutputEnabled = !toolOutputEnabled;
|
|
70
|
-
}
|
|
71
|
-
status = toolOutputEnabled ? 'ON' : 'OFF';
|
|
72
|
-
emoji = toolOutputEnabled ? '🔊' : '🔇';
|
|
73
|
-
return [4 /*yield*/, bot.sendMessage(chatId, "".concat(emoji, " *Tool Output: ").concat(status, "*\n\n") +
|
|
74
|
-
"Tool execution messages are now ".concat(toolOutputEnabled ? 'visible' : 'hidden', ".\n\n") +
|
|
75
|
-
"Commands:\n" +
|
|
76
|
-
"/toolsoutput on - Enable tool messages\n" +
|
|
77
|
-
"/toolsoutput off - Disable tool messages\n" +
|
|
78
|
-
"/toolsoutput toggle - Toggle", { parse_mode: 'Markdown' })];
|
|
79
|
-
case 1:
|
|
80
|
-
_b.sent();
|
|
81
|
-
return [2 /*return*/];
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}); });
|
|
85
|
-
}
|
package/src/commands/types.js
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Conversation Memory - tracks chat history per user
|
|
4
|
-
* Uses JSONL format for efficient append operations
|
|
5
|
-
*/
|
|
6
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
16
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
17
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
18
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
19
|
-
function step(op) {
|
|
20
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
21
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
22
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
23
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
24
|
-
switch (op[0]) {
|
|
25
|
-
case 0: case 1: t = op; break;
|
|
26
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
27
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
28
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
29
|
-
default:
|
|
30
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
31
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
32
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
33
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
34
|
-
if (t[2]) _.ops.pop();
|
|
35
|
-
_.trys.pop(); continue;
|
|
36
|
-
}
|
|
37
|
-
op = body.call(thisArg, _);
|
|
38
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
39
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
43
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
44
|
-
var m = o[Symbol.asyncIterator], i;
|
|
45
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
46
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
47
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
48
|
-
};
|
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.ConversationMemory = void 0;
|
|
51
|
-
var fs_1 = require("fs");
|
|
52
|
-
var readline = require("readline");
|
|
53
|
-
var ConversationMemory = /** @class */ (function () {
|
|
54
|
-
function ConversationMemory(file) {
|
|
55
|
-
this.conversations = new Map();
|
|
56
|
-
this.maxMessages = 10; // Keep last N messages
|
|
57
|
-
// Default to .jsonl extension
|
|
58
|
-
this.file = file || '/root/conversations.jsonl';
|
|
59
|
-
// Handle migration from old .json format
|
|
60
|
-
this.migrateFromJson();
|
|
61
|
-
this.load();
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Migrate from old JSON format to JSONL if .json file exists
|
|
65
|
-
*/
|
|
66
|
-
ConversationMemory.prototype.migrateFromJson = function () {
|
|
67
|
-
var jsonFile = this.file.replace(/\.jsonl$/, '.json');
|
|
68
|
-
if (this.file.endsWith('.jsonl') && (0, fs_1.existsSync)(jsonFile) && !(0, fs_1.existsSync)(this.file)) {
|
|
69
|
-
try {
|
|
70
|
-
var data = JSON.parse((0, fs_1.readFileSync)(jsonFile, 'utf-8'));
|
|
71
|
-
// Write as JSONL
|
|
72
|
-
var lines = [];
|
|
73
|
-
for (var _i = 0, _a = Object.entries(data); _i < _a.length; _i++) {
|
|
74
|
-
var _b = _a[_i], chatId = _b[0], messages = _b[1];
|
|
75
|
-
var entry = {
|
|
76
|
-
chatId: Number(chatId),
|
|
77
|
-
messages: messages
|
|
78
|
-
};
|
|
79
|
-
lines.push(JSON.stringify(entry));
|
|
80
|
-
}
|
|
81
|
-
(0, fs_1.writeFileSync)(this.file, lines.join('\n') + '\n');
|
|
82
|
-
// Remove old JSON file after successful migration
|
|
83
|
-
(0, fs_1.unlinkSync)(jsonFile);
|
|
84
|
-
}
|
|
85
|
-
catch (_c) {
|
|
86
|
-
// If migration fails, continue with empty memory
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* Load conversations from JSONL file using readline for streaming
|
|
92
|
-
*/
|
|
93
|
-
ConversationMemory.prototype.load = function () {
|
|
94
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
95
|
-
var fileStream, rl, _a, rl_1, rl_1_1, line, entry, e_1_1, _b;
|
|
96
|
-
var _c, e_1, _d, _e;
|
|
97
|
-
return __generator(this, function (_f) {
|
|
98
|
-
switch (_f.label) {
|
|
99
|
-
case 0:
|
|
100
|
-
if (!(0, fs_1.existsSync)(this.file))
|
|
101
|
-
return [2 /*return*/];
|
|
102
|
-
_f.label = 1;
|
|
103
|
-
case 1:
|
|
104
|
-
_f.trys.push([1, 14, , 15]);
|
|
105
|
-
fileStream = (0, fs_1.createReadStream)(this.file, 'utf-8');
|
|
106
|
-
rl = readline.createInterface({
|
|
107
|
-
input: fileStream,
|
|
108
|
-
crlfDelay: Infinity
|
|
109
|
-
});
|
|
110
|
-
_f.label = 2;
|
|
111
|
-
case 2:
|
|
112
|
-
_f.trys.push([2, 7, 8, 13]);
|
|
113
|
-
_a = true, rl_1 = __asyncValues(rl);
|
|
114
|
-
_f.label = 3;
|
|
115
|
-
case 3: return [4 /*yield*/, rl_1.next()];
|
|
116
|
-
case 4:
|
|
117
|
-
if (!(rl_1_1 = _f.sent(), _c = rl_1_1.done, !_c)) return [3 /*break*/, 6];
|
|
118
|
-
_e = rl_1_1.value;
|
|
119
|
-
_a = false;
|
|
120
|
-
line = _e;
|
|
121
|
-
if (!line.trim())
|
|
122
|
-
return [3 /*break*/, 5]; // Skip empty lines
|
|
123
|
-
try {
|
|
124
|
-
entry = JSON.parse(line);
|
|
125
|
-
this.conversations.set(entry.chatId, entry.messages);
|
|
126
|
-
}
|
|
127
|
-
catch (_g) {
|
|
128
|
-
// Skip malformed lines
|
|
129
|
-
}
|
|
130
|
-
_f.label = 5;
|
|
131
|
-
case 5:
|
|
132
|
-
_a = true;
|
|
133
|
-
return [3 /*break*/, 3];
|
|
134
|
-
case 6: return [3 /*break*/, 13];
|
|
135
|
-
case 7:
|
|
136
|
-
e_1_1 = _f.sent();
|
|
137
|
-
e_1 = { error: e_1_1 };
|
|
138
|
-
return [3 /*break*/, 13];
|
|
139
|
-
case 8:
|
|
140
|
-
_f.trys.push([8, , 11, 12]);
|
|
141
|
-
if (!(!_a && !_c && (_d = rl_1.return))) return [3 /*break*/, 10];
|
|
142
|
-
return [4 /*yield*/, _d.call(rl_1)];
|
|
143
|
-
case 9:
|
|
144
|
-
_f.sent();
|
|
145
|
-
_f.label = 10;
|
|
146
|
-
case 10: return [3 /*break*/, 12];
|
|
147
|
-
case 11:
|
|
148
|
-
if (e_1) throw e_1.error;
|
|
149
|
-
return [7 /*endfinally*/];
|
|
150
|
-
case 12: return [7 /*endfinally*/];
|
|
151
|
-
case 13:
|
|
152
|
-
rl.close();
|
|
153
|
-
fileStream.destroy();
|
|
154
|
-
return [3 /*break*/, 15];
|
|
155
|
-
case 14:
|
|
156
|
-
_b = _f.sent();
|
|
157
|
-
return [3 /*break*/, 15];
|
|
158
|
-
case 15: return [2 /*return*/];
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
};
|
|
163
|
-
/**
|
|
164
|
-
* Save all conversations as JSONL (full rewrite)
|
|
165
|
-
*/
|
|
166
|
-
ConversationMemory.prototype.save = function () {
|
|
167
|
-
var lines = [];
|
|
168
|
-
for (var _i = 0, _a = this.conversations; _i < _a.length; _i++) {
|
|
169
|
-
var _b = _a[_i], chatId = _b[0], messages = _b[1];
|
|
170
|
-
var entry = { chatId: chatId, messages: messages };
|
|
171
|
-
lines.push(JSON.stringify(entry));
|
|
172
|
-
}
|
|
173
|
-
(0, fs_1.writeFileSync)(this.file, lines.join('\n') + (lines.length > 0 ? '\n' : ''));
|
|
174
|
-
};
|
|
175
|
-
/**
|
|
176
|
-
* Append a single conversation entry (efficient for new chats)
|
|
177
|
-
*/
|
|
178
|
-
ConversationMemory.prototype.append = function (chatId) {
|
|
179
|
-
var entry = {
|
|
180
|
-
chatId: chatId,
|
|
181
|
-
messages: this.conversations.get(chatId) || []
|
|
182
|
-
};
|
|
183
|
-
(0, fs_1.appendFileSync)(this.file, JSON.stringify(entry) + '\n');
|
|
184
|
-
};
|
|
185
|
-
ConversationMemory.prototype.add = function (chatId, role, content, name) {
|
|
186
|
-
var isNewChat = !this.conversations.has(chatId);
|
|
187
|
-
if (isNewChat) {
|
|
188
|
-
this.conversations.set(chatId, []);
|
|
189
|
-
}
|
|
190
|
-
var history = this.conversations.get(chatId);
|
|
191
|
-
var msg = { role: role, content: content };
|
|
192
|
-
if (name)
|
|
193
|
-
msg.name = name;
|
|
194
|
-
history.push(msg);
|
|
195
|
-
// Keep only last N messages
|
|
196
|
-
if (history.length > this.maxMessages) {
|
|
197
|
-
history.splice(0, history.length - this.maxMessages);
|
|
198
|
-
}
|
|
199
|
-
// Use append for new chats (efficient), full save for existing (handles truncation)
|
|
200
|
-
if (isNewChat) {
|
|
201
|
-
this.append(chatId);
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
this.save();
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
ConversationMemory.prototype.get = function (chatId) {
|
|
208
|
-
return this.conversations.get(chatId) || [];
|
|
209
|
-
};
|
|
210
|
-
ConversationMemory.prototype.clear = function (chatId) {
|
|
211
|
-
this.conversations.delete(chatId);
|
|
212
|
-
this.save();
|
|
213
|
-
};
|
|
214
|
-
return ConversationMemory;
|
|
215
|
-
}());
|
|
216
|
-
exports.ConversationMemory = ConversationMemory;
|