@43world/llm-logger-openclaw-plugin 0.0.3
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/DESIGN.md +352 -0
- package/README.md +80 -0
- package/index.ts +46 -0
- package/openclaw.plugin.json +40 -0
- package/package.json +14 -0
- package/src/config.ts +142 -0
- package/src/jsonl-writer.ts +52 -0
- package/src/manager.ts +844 -0
- package/src/openclaw-root.ts +52 -0
- package/src/redaction.ts +57 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
function safeJsonStringify(value: unknown): string {
|
|
5
|
+
const seen = new WeakSet<object>();
|
|
6
|
+
return JSON.stringify(value, (_key, current) => {
|
|
7
|
+
if (typeof current === "bigint") {
|
|
8
|
+
return current.toString();
|
|
9
|
+
}
|
|
10
|
+
if (current instanceof Error) {
|
|
11
|
+
return {
|
|
12
|
+
name: current.name,
|
|
13
|
+
message: current.message,
|
|
14
|
+
stack: current.stack,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
if (current && typeof current === "object") {
|
|
18
|
+
if (seen.has(current)) {
|
|
19
|
+
return "[Circular]";
|
|
20
|
+
}
|
|
21
|
+
seen.add(current);
|
|
22
|
+
}
|
|
23
|
+
return current;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class JsonlWriter {
|
|
28
|
+
readonly filePath: string;
|
|
29
|
+
|
|
30
|
+
#queue: Promise<void> = Promise.resolve();
|
|
31
|
+
#dirReady = false;
|
|
32
|
+
|
|
33
|
+
constructor(filePath: string) {
|
|
34
|
+
this.filePath = filePath;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async write(record: unknown): Promise<void> {
|
|
38
|
+
const line = `${safeJsonStringify(record)}\n`;
|
|
39
|
+
this.#queue = this.#queue.then(async () => {
|
|
40
|
+
if (!this.#dirReady) {
|
|
41
|
+
await fs.mkdir(path.dirname(this.filePath), { recursive: true });
|
|
42
|
+
this.#dirReady = true;
|
|
43
|
+
}
|
|
44
|
+
await fs.appendFile(this.filePath, line, "utf8");
|
|
45
|
+
});
|
|
46
|
+
return this.#queue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async close(): Promise<void> {
|
|
50
|
+
await this.#queue;
|
|
51
|
+
}
|
|
52
|
+
}
|