metame-cli 1.3.20 → 1.3.23
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 +115 -646
- package/index.js +11 -31
- package/package.json +1 -1
- package/scripts/daemon.js +1192 -236
- package/scripts/distill.js +63 -42
- package/scripts/feishu-adapter.js +65 -15
- package/scripts/skill-evolution.js +792 -0
- package/scripts/telegram-adapter.js +12 -4
- package/scripts/test_daemon.js +3818 -0
|
@@ -15,7 +15,7 @@ const API_BASE = 'https://api.telegram.org';
|
|
|
15
15
|
/**
|
|
16
16
|
* Make an HTTPS request to Telegram Bot API
|
|
17
17
|
*/
|
|
18
|
-
function apiRequest(token, method, params = {}, timeout = 10000) {
|
|
18
|
+
function apiRequest(token, method, params = {}, timeout = 10000, signal = null) {
|
|
19
19
|
return new Promise((resolve, reject) => {
|
|
20
20
|
const url = `${API_BASE}/bot${token}/${method}`;
|
|
21
21
|
const body = JSON.stringify(params);
|
|
@@ -49,7 +49,14 @@ function apiRequest(token, method, params = {}, timeout = 10000) {
|
|
|
49
49
|
});
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
// AbortController support: destroy the in-flight request immediately on abort
|
|
53
|
+
if (signal) {
|
|
54
|
+
const onAbort = () => { req.destroy(); reject(new Error('aborted')); };
|
|
55
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
56
|
+
req.on('close', () => signal.removeEventListener('abort', onAbort));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
req.on('error', (e) => { if (e.message !== 'aborted') reject(e); });
|
|
53
60
|
req.on('timeout', () => {
|
|
54
61
|
req.destroy();
|
|
55
62
|
reject(new Error('Telegram API request timed out'));
|
|
@@ -75,15 +82,16 @@ function createBot(token) {
|
|
|
75
82
|
* @param {number} timeout - Long-poll timeout in seconds (default 30)
|
|
76
83
|
* @returns {Promise<Array>} Array of update objects
|
|
77
84
|
*/
|
|
78
|
-
async getUpdates(offset = 0, timeout = 30) {
|
|
85
|
+
async getUpdates(offset = 0, timeout = 30, signal = null) {
|
|
79
86
|
try {
|
|
80
87
|
const result = await apiRequest(token, 'getUpdates', {
|
|
81
88
|
offset,
|
|
82
89
|
timeout,
|
|
83
90
|
allowed_updates: ['message', 'callback_query'],
|
|
84
|
-
}, (timeout + 5) * 1000); // HTTP timeout > long-poll timeout
|
|
91
|
+
}, (timeout + 5) * 1000, signal); // HTTP timeout > long-poll timeout
|
|
85
92
|
return result || [];
|
|
86
93
|
} catch (e) {
|
|
94
|
+
if (e.message === 'aborted') throw e; // propagate abort, don't swallow
|
|
87
95
|
// On timeout or network error, return empty — caller retries
|
|
88
96
|
if (e.message.includes('timed out')) return [];
|
|
89
97
|
throw e;
|