@locusai/locus-telegram 0.24.9 → 0.25.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.
- package/bin/locus-telegram.js +39 -3
- package/package.json +4 -4
package/bin/locus-telegram.js
CHANGED
|
@@ -9314,6 +9314,34 @@ import { execSync } from "node:child_process";
|
|
|
9314
9314
|
import { existsSync } from "node:fs";
|
|
9315
9315
|
import { dirname, join } from "node:path";
|
|
9316
9316
|
import { fileURLToPath } from "node:url";
|
|
9317
|
+
function startHeartbeat(options) {
|
|
9318
|
+
const { processName, logger, intervalMs = DEFAULT_INTERVAL_MS } = options;
|
|
9319
|
+
const startedAt = Date.now();
|
|
9320
|
+
const tick = () => {
|
|
9321
|
+
const uptimeSec = Math.floor((Date.now() - startedAt) / 1000);
|
|
9322
|
+
const memUsage = process.memoryUsage();
|
|
9323
|
+
const heapMB = (memUsage.heapUsed / (1024 * 1024)).toFixed(1);
|
|
9324
|
+
const rssMB = (memUsage.rss / (1024 * 1024)).toFixed(1);
|
|
9325
|
+
logger.info(`[heartbeat] ${processName} alive — uptime: ${formatUptime(uptimeSec)}, heap: ${heapMB}MB, rss: ${rssMB}MB`);
|
|
9326
|
+
};
|
|
9327
|
+
tick();
|
|
9328
|
+
const timer = setInterval(tick, intervalMs);
|
|
9329
|
+
timer.unref();
|
|
9330
|
+
return () => clearInterval(timer);
|
|
9331
|
+
}
|
|
9332
|
+
function formatUptime(seconds) {
|
|
9333
|
+
const d = Math.floor(seconds / 86400);
|
|
9334
|
+
const h = Math.floor(seconds % 86400 / 3600);
|
|
9335
|
+
const m = Math.floor(seconds % 3600 / 60);
|
|
9336
|
+
const s = seconds % 60;
|
|
9337
|
+
if (d > 0)
|
|
9338
|
+
return `${d}d ${h}h ${m}m`;
|
|
9339
|
+
if (h > 0)
|
|
9340
|
+
return `${h}h ${m}m ${s}s`;
|
|
9341
|
+
if (m > 0)
|
|
9342
|
+
return `${m}m ${s}s`;
|
|
9343
|
+
return `${s}s`;
|
|
9344
|
+
}
|
|
9317
9345
|
function getPm2Bin() {
|
|
9318
9346
|
let dir = process.cwd();
|
|
9319
9347
|
while (dir !== dirname(dir)) {
|
|
@@ -9417,7 +9445,10 @@ function resolvePackageScript(importMetaUrl, binName) {
|
|
|
9417
9445
|
const packageRoot = dirname(dirname(currentFile));
|
|
9418
9446
|
return join(packageRoot, "bin", `${binName}.js`);
|
|
9419
9447
|
}
|
|
9420
|
-
var
|
|
9448
|
+
var DEFAULT_INTERVAL_MS;
|
|
9449
|
+
var init_dist = __esm(() => {
|
|
9450
|
+
DEFAULT_INTERVAL_MS = 5 * 60 * 1000;
|
|
9451
|
+
});
|
|
9421
9452
|
|
|
9422
9453
|
// ../sdk/dist/index.js
|
|
9423
9454
|
import { existsSync as existsSync2, readFileSync } from "node:fs";
|
|
@@ -10378,7 +10409,7 @@ function prCreatedMessage(prNumber, url) {
|
|
|
10378
10409
|
`);
|
|
10379
10410
|
}
|
|
10380
10411
|
function serviceStatusMessage(status, pid, uptime, memory, restarts) {
|
|
10381
|
-
const uptimeStr = uptime ?
|
|
10412
|
+
const uptimeStr = uptime ? formatUptime2(uptime) : "N/A";
|
|
10382
10413
|
const memoryStr = memory ? formatMemory(memory) : "N/A";
|
|
10383
10414
|
return [
|
|
10384
10415
|
`\uD83E\uDD16 ${bold3("Locus Telegram Bot")}`,
|
|
@@ -10400,7 +10431,7 @@ function serviceNotRunningMessage() {
|
|
|
10400
10431
|
].join(`
|
|
10401
10432
|
`);
|
|
10402
10433
|
}
|
|
10403
|
-
function
|
|
10434
|
+
function formatUptime2(startTimeMs) {
|
|
10404
10435
|
const diff = Date.now() - startTimeMs;
|
|
10405
10436
|
const seconds = Math.floor(diff / 1000);
|
|
10406
10437
|
const minutes = Math.floor(seconds / 60);
|
|
@@ -11236,8 +11267,13 @@ async function handleBot() {
|
|
|
11236
11267
|
}
|
|
11237
11268
|
await bot.api.deleteWebhook({ drop_pending_updates: true });
|
|
11238
11269
|
const runner = import_runner.run(bot);
|
|
11270
|
+
const stopHeartbeat = startHeartbeat({
|
|
11271
|
+
processName: "locus-telegram",
|
|
11272
|
+
logger: logger3
|
|
11273
|
+
});
|
|
11239
11274
|
const shutdown = () => {
|
|
11240
11275
|
logger3.info("Shutting down bot...");
|
|
11276
|
+
stopHeartbeat();
|
|
11241
11277
|
runner.stop();
|
|
11242
11278
|
process.exit(0);
|
|
11243
11279
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@locusai/locus-telegram",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "Remote-control Locus via Telegram with full CLI mapping, git operations, and PM2 management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@grammyjs/runner": "^2.0.3",
|
|
30
|
-
"@locusai/locus-gateway": "^0.
|
|
31
|
-
"@locusai/locus-pm2": "^0.
|
|
32
|
-
"@locusai/sdk": "^0.
|
|
30
|
+
"@locusai/locus-gateway": "^0.25.0",
|
|
31
|
+
"@locusai/locus-pm2": "^0.25.0",
|
|
32
|
+
"@locusai/sdk": "^0.25.0",
|
|
33
33
|
"grammy": "^1.35.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|