@ebowwa/channel-telegram 1.12.5 → 1.13.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.
Files changed (49) hide show
  1. package/README.md +78 -44
  2. package/dist/commands/index.d.ts +1 -0
  3. package/dist/commands/index.d.ts.map +1 -1
  4. package/dist/commands/index.js +3 -0
  5. package/dist/commands/index.js.map +1 -1
  6. package/dist/commands/restart.d.ts +7 -0
  7. package/dist/commands/restart.d.ts.map +1 -0
  8. package/dist/commands/restart.js +29 -0
  9. package/dist/commands/restart.js.map +1 -0
  10. package/dist/commands/settings.d.ts +8 -0
  11. package/dist/commands/settings.d.ts.map +1 -0
  12. package/dist/commands/settings.js +16 -0
  13. package/dist/commands/settings.js.map +1 -0
  14. package/dist/index.d.ts +83 -29
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +350 -712
  17. package/dist/index.js.map +1 -1
  18. package/package.json +9 -13
  19. package/src/commands/index.ts +3 -0
  20. package/src/commands/restart.ts +41 -0
  21. package/src/commands/settings.ts +24 -0
  22. package/src/index.ts +415 -823
  23. package/dist/mcp/client.d.ts +0 -50
  24. package/dist/mcp/client.d.ts.map +0 -1
  25. package/dist/mcp/client.js +0 -150
  26. package/dist/mcp/client.js.map +0 -1
  27. package/dist/mcp/index.d.ts +0 -5
  28. package/dist/mcp/index.d.ts.map +0 -1
  29. package/dist/mcp/index.js +0 -5
  30. package/dist/mcp/index.js.map +0 -1
  31. package/src/api/fetch-retry.js +0 -96
  32. package/src/api/keys.js +0 -25
  33. package/src/commands/cancel.js +0 -120
  34. package/src/commands/clear.js +0 -59
  35. package/src/commands/doppler.js +0 -118
  36. package/src/commands/git.js +0 -126
  37. package/src/commands/help.js +0 -74
  38. package/src/commands/index.js +0 -65
  39. package/src/commands/logs.js +0 -81
  40. package/src/commands/pause.js +0 -133
  41. package/src/commands/resources.js +0 -87
  42. package/src/commands/resume.js +0 -95
  43. package/src/commands/start.js +0 -68
  44. package/src/commands/status.js +0 -62
  45. package/src/commands/tools.js +0 -67
  46. package/src/commands/toolsoutput.js +0 -85
  47. package/src/commands/types.js +0 -5
  48. package/src/mcp/client.ts +0 -188
  49. package/src/mcp/index.ts +0 -5
@@ -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
- }
@@ -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
- }
@@ -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
- }
@@ -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
- }
@@ -1,5 +0,0 @@
1
- "use strict";
2
- /**
3
- * Types for Telegram command handlers
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
package/src/mcp/client.ts DELETED
@@ -1,188 +0,0 @@
1
- /**
2
- * MCP Client - Connect to MCP servers and expose their tools
3
- *
4
- * Uses stdio transport to communicate with local MCP servers
5
- */
6
-
7
- import { Client } from '@modelcontextprotocol/sdk/client/index.js';
8
- import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
9
-
10
- export interface MCPTool {
11
- name: string;
12
- description: string;
13
- inputSchema: Record<string, unknown>;
14
- serverName: string;
15
- }
16
-
17
- export interface MCPServerConfig {
18
- name: string;
19
- command: string;
20
- args?: string[];
21
- env?: Record<string, string>;
22
- }
23
-
24
- export class MCPClient {
25
- private clients: Map<string, Client> = new Map();
26
- private transports: Map<string, StdioClientTransport> = new Map();
27
- private tools: MCPTool[] = [];
28
-
29
- /**
30
- * Default MCP servers to connect to
31
- * Uses globally installed @ebowwa/*-mcp packages
32
- */
33
- static DEFAULT_SERVERS: MCPServerConfig[] = [
34
- {
35
- name: 'hetzner',
36
- command: '/root/.bun/bin/bun',
37
- args: ['/root/.bun/install/global/node_modules/@ebowwa/hetzner-mcp/dist/index.js'],
38
- },
39
- ];
40
-
41
- constructor(private servers: MCPServerConfig[] = MCPClient.DEFAULT_SERVERS) {}
42
-
43
- /**
44
- * Connect to all configured MCP servers
45
- */
46
- async connect(): Promise<void> {
47
- console.log(`[MCP] Connecting to ${this.servers.length} servers...`);
48
-
49
- for (const server of this.servers) {
50
- try {
51
- await this.connectToServer(server);
52
- } catch (error) {
53
- console.error(`[MCP] Failed to connect to ${server.name}:`, error);
54
- }
55
- }
56
-
57
- console.log(`[MCP] Connected. Found ${this.tools.length} tools.`);
58
- }
59
-
60
- /**
61
- * Connect to a single MCP server
62
- */
63
- private async connectToServer(server: MCPServerConfig): Promise<void> {
64
- console.log(`[MCP] Connecting to ${server.name}...`);
65
-
66
- // Build env - filter out undefined values
67
- const env: Record<string, string> = {};
68
- for (const [key, value] of Object.entries(process.env)) {
69
- if (value !== undefined) {
70
- env[key] = value;
71
- }
72
- }
73
- if (server.env) {
74
- Object.assign(env, server.env);
75
- }
76
-
77
- // Create stdio transport - it handles spawning the process
78
- const transport = new StdioClientTransport({
79
- command: server.command,
80
- args: server.args,
81
- env,
82
- stderr: 'pipe',
83
- });
84
-
85
- this.transports.set(server.name, transport);
86
-
87
- // Handle stderr for debugging
88
- const stderr = transport.stderr;
89
- if (stderr) {
90
- stderr.on('data', (data: Buffer) => {
91
- console.error(`[MCP:${server.name}] ${data.toString().trim()}`);
92
- });
93
- }
94
-
95
- // Create MCP client
96
- const client = new Client(
97
- { name: `telegram-bot-mcp-${server.name}`, version: '1.0.0' },
98
- { capabilities: {} }
99
- );
100
-
101
- await client.connect(transport);
102
- this.clients.set(server.name, client);
103
-
104
- // Discover tools
105
- const toolsResult = await client.listTools();
106
-
107
- for (const tool of toolsResult.tools) {
108
- this.tools.push({
109
- name: tool.name,
110
- description: tool.description || '',
111
- inputSchema: tool.inputSchema as Record<string, unknown>,
112
- serverName: server.name,
113
- });
114
- }
115
-
116
- console.log(`[MCP] ${server.name}: Found ${toolsResult.tools.length} tools`);
117
- }
118
-
119
- /**
120
- * Get all discovered MCP tools
121
- */
122
- getTools(): MCPTool[] {
123
- return this.tools;
124
- }
125
-
126
- /**
127
- * Call an MCP tool
128
- */
129
- async callTool(name: string, args: Record<string, unknown>): Promise<string> {
130
- const tool = this.tools.find(t => t.name === name);
131
-
132
- if (!tool) {
133
- throw new Error(`Tool not found: ${name}`);
134
- }
135
-
136
- const client = this.clients.get(tool.serverName);
137
-
138
- if (!client) {
139
- throw new Error(`MCP server not connected: ${tool.serverName}`);
140
- }
141
-
142
- try {
143
- const result = await client.callTool({
144
- name,
145
- arguments: args,
146
- });
147
-
148
- // Extract text content from result
149
- if (result.content && Array.isArray(result.content)) {
150
- return result.content
151
- .map((c: { type: string; text?: string }) => c.text || '')
152
- .join('\n');
153
- }
154
-
155
- return JSON.stringify(result);
156
- } catch (error) {
157
- throw new Error(`MCP tool error: ${(error as Error).message}`);
158
- }
159
- }
160
-
161
- /**
162
- * Disconnect from all MCP servers
163
- */
164
- async disconnect(): Promise<void> {
165
- console.log('[MCP] Disconnecting...');
166
-
167
- for (const [name, client] of this.clients) {
168
- try {
169
- await client.close();
170
- console.log(`[MCP] Disconnected from ${name}`);
171
- } catch (error) {
172
- console.error(`[MCP] Error disconnecting from ${name}:`, error);
173
- }
174
- }
175
-
176
- for (const [name, transport] of this.transports) {
177
- try {
178
- await transport.close();
179
- } catch (error) {
180
- console.error(`[MCP] Error closing transport ${name}:`, error);
181
- }
182
- }
183
-
184
- this.clients.clear();
185
- this.transports.clear();
186
- this.tools = [];
187
- }
188
- }
package/src/mcp/index.ts DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * MCP Module Exports
3
- */
4
-
5
- export { MCPClient, type MCPTool, type MCPServerConfig } from './client';