@stamn/stamn-plugin 0.1.0-alpha.18 → 0.1.0-alpha.19
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/dist/index.js +99 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5438,6 +5438,76 @@ var wrapper_default = import_websocket.default;
|
|
|
5438
5438
|
// src/ws-service.ts
|
|
5439
5439
|
import { hostname } from "os";
|
|
5440
5440
|
import { execFile } from "child_process";
|
|
5441
|
+
|
|
5442
|
+
// src/log-reader.ts
|
|
5443
|
+
import { openSync, readSync, closeSync, statSync } from "fs";
|
|
5444
|
+
import { join as join5 } from "path";
|
|
5445
|
+
import { tmpdir as tmpdir3 } from "os";
|
|
5446
|
+
var LOG_DIR = join5(tmpdir3(), "openclaw");
|
|
5447
|
+
var DEFAULT_MAX_BYTES = 64 * 1024;
|
|
5448
|
+
var DEFAULT_LIMIT = 200;
|
|
5449
|
+
function getLogFilePath() {
|
|
5450
|
+
const date = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
5451
|
+
return join5(LOG_DIR, `openclaw-${date}.log`);
|
|
5452
|
+
}
|
|
5453
|
+
function readLogs(opts) {
|
|
5454
|
+
const file = getLogFilePath();
|
|
5455
|
+
const limit = opts.limit ?? DEFAULT_LIMIT;
|
|
5456
|
+
const maxBytes = opts.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
5457
|
+
let cursor = opts.cursor;
|
|
5458
|
+
let stat;
|
|
5459
|
+
try {
|
|
5460
|
+
stat = statSync(file);
|
|
5461
|
+
} catch {
|
|
5462
|
+
return { lines: [], cursor: 0, size: 0, file, truncated: false, reset: false };
|
|
5463
|
+
}
|
|
5464
|
+
const size = stat.size;
|
|
5465
|
+
const reset = cursor > size;
|
|
5466
|
+
if (reset) cursor = 0;
|
|
5467
|
+
if (cursor >= size) {
|
|
5468
|
+
return { lines: [], cursor, size, file, truncated: false, reset };
|
|
5469
|
+
}
|
|
5470
|
+
const bytesToRead = Math.min(maxBytes, size - cursor);
|
|
5471
|
+
const buffer = Buffer.alloc(bytesToRead);
|
|
5472
|
+
const fd = openSync(file, "r");
|
|
5473
|
+
try {
|
|
5474
|
+
readSync(fd, buffer, 0, bytesToRead, cursor);
|
|
5475
|
+
} finally {
|
|
5476
|
+
closeSync(fd);
|
|
5477
|
+
}
|
|
5478
|
+
const raw = buffer.toString("utf-8");
|
|
5479
|
+
const rawLines = raw.split("\n");
|
|
5480
|
+
const atEof = cursor + bytesToRead >= size;
|
|
5481
|
+
let actualBytesConsumed = bytesToRead;
|
|
5482
|
+
if (!atEof && rawLines.length > 0 && !raw.endsWith("\n")) {
|
|
5483
|
+
const incomplete = rawLines.pop();
|
|
5484
|
+
actualBytesConsumed -= Buffer.byteLength(incomplete, "utf-8");
|
|
5485
|
+
}
|
|
5486
|
+
const lines = [];
|
|
5487
|
+
let truncated = false;
|
|
5488
|
+
for (const line of rawLines) {
|
|
5489
|
+
const trimmed = line.trim();
|
|
5490
|
+
if (!trimmed) continue;
|
|
5491
|
+
try {
|
|
5492
|
+
lines.push(JSON.parse(trimmed));
|
|
5493
|
+
} catch {
|
|
5494
|
+
}
|
|
5495
|
+
if (lines.length >= limit) {
|
|
5496
|
+
truncated = true;
|
|
5497
|
+
break;
|
|
5498
|
+
}
|
|
5499
|
+
}
|
|
5500
|
+
return {
|
|
5501
|
+
lines,
|
|
5502
|
+
cursor: cursor + actualBytesConsumed,
|
|
5503
|
+
size,
|
|
5504
|
+
file,
|
|
5505
|
+
truncated: truncated || !atEof,
|
|
5506
|
+
reset
|
|
5507
|
+
};
|
|
5508
|
+
}
|
|
5509
|
+
|
|
5510
|
+
// src/ws-service.ts
|
|
5441
5511
|
var MAX_EVENT_BUFFER_SIZE = 200;
|
|
5442
5512
|
var BASE_RECONNECT_DELAY_MS = 1e3;
|
|
5443
5513
|
var MAX_RECONNECT_DELAY_MS = 6e4;
|
|
@@ -5609,6 +5679,10 @@ var StamnWsService = class {
|
|
|
5609
5679
|
this.handleUpdatePlugin();
|
|
5610
5680
|
return;
|
|
5611
5681
|
}
|
|
5682
|
+
if (payload.command === "request_logs") {
|
|
5683
|
+
this.handleRequestLogs(payload.params);
|
|
5684
|
+
return;
|
|
5685
|
+
}
|
|
5612
5686
|
this.bufferEvent(ServerEvent.COMMAND, payload);
|
|
5613
5687
|
}
|
|
5614
5688
|
handleUpdatePlugin() {
|
|
@@ -5623,6 +5697,31 @@ var StamnWsService = class {
|
|
|
5623
5697
|
this.sendStatusReport("online");
|
|
5624
5698
|
});
|
|
5625
5699
|
}
|
|
5700
|
+
handleRequestLogs(params) {
|
|
5701
|
+
try {
|
|
5702
|
+
const result = readLogs({
|
|
5703
|
+
cursor: params.cursor,
|
|
5704
|
+
limit: params.limit,
|
|
5705
|
+
maxBytes: params.maxBytes
|
|
5706
|
+
});
|
|
5707
|
+
this.sendMessage("participant:log_response", {
|
|
5708
|
+
requestId: params.requestId,
|
|
5709
|
+
...result
|
|
5710
|
+
});
|
|
5711
|
+
} catch (err) {
|
|
5712
|
+
this.logger.error(`Failed to read logs: ${err}`);
|
|
5713
|
+
this.sendMessage("participant:log_response", {
|
|
5714
|
+
requestId: params.requestId,
|
|
5715
|
+
lines: [],
|
|
5716
|
+
cursor: params.cursor,
|
|
5717
|
+
size: 0,
|
|
5718
|
+
file: "",
|
|
5719
|
+
truncated: false,
|
|
5720
|
+
reset: false,
|
|
5721
|
+
error: err.message
|
|
5722
|
+
});
|
|
5723
|
+
}
|
|
5724
|
+
}
|
|
5626
5725
|
onAuthError(payload) {
|
|
5627
5726
|
this.authFailed = true;
|
|
5628
5727
|
this.logger.error(`Authentication failed: ${payload.reason}`);
|