@43world/llm-logger-openclaw-plugin 0.0.3 → 0.0.4
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 +9 -3
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/src/manager.ts +11 -10
package/README.md
CHANGED
|
@@ -13,6 +13,12 @@ OpenClaw 插件。
|
|
|
13
13
|
|
|
14
14
|
## 安装
|
|
15
15
|
|
|
16
|
+
直接走npm包安装
|
|
17
|
+
```bash
|
|
18
|
+
openclaw plugins install @43world/llm-logger-openclaw-plugin
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
源码目录安装
|
|
16
22
|
```bash
|
|
17
23
|
openclaw plugins install -l /root/projects/llm-logger-openclaw-plugin
|
|
18
24
|
openclaw plugins enable llm-logger-openclaw-plugin
|
|
@@ -45,18 +51,18 @@ openclaw plugins enable llm-logger-openclaw-plugin
|
|
|
45
51
|
如果不指定 `logFile`,默认按会话和日期写到:
|
|
46
52
|
|
|
47
53
|
```text
|
|
48
|
-
<OPENCLAW_STATE_DIR>/logs/<
|
|
54
|
+
<OPENCLAW_STATE_DIR>/logs/<session_key>/llm-logger-openclaw-plugin-YYYY-MM-DD.jsonl
|
|
49
55
|
```
|
|
50
56
|
|
|
51
57
|
其中:
|
|
52
58
|
|
|
53
|
-
- `<
|
|
59
|
+
- `<session_key>` 来自 OpenClaw 会话;若缺失会写到 `_unknown_session_key` 目录
|
|
54
60
|
- `YYYY-MM-DD` 为当天日期后缀,用于每日滚动记录
|
|
55
61
|
|
|
56
62
|
如果指定了 `logFile`(例如 `/tmp/openclaw-llm.jsonl`),会将其作为基准路径与基准文件名,最终写入:
|
|
57
63
|
|
|
58
64
|
```text
|
|
59
|
-
/tmp/<
|
|
65
|
+
/tmp/<session_key>/openclaw-llm-YYYY-MM-DD.jsonl
|
|
60
66
|
```
|
|
61
67
|
|
|
62
68
|
## 日志格式
|
package/openclaw.plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "llm-logger-openclaw-plugin",
|
|
3
3
|
"name": "LLM Logger OpenClaw Plugin",
|
|
4
4
|
"description": "Logs OpenClaw LLM request payloads and responses to a JSONL file.",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.4",
|
|
6
6
|
"configSchema": {
|
|
7
7
|
"type": "object",
|
|
8
8
|
"additionalProperties": false,
|
package/package.json
CHANGED
package/src/manager.ts
CHANGED
|
@@ -91,7 +91,7 @@ const GLOBAL_KEY = Symbol.for("llm-logger-openclaw-plugin.manager");
|
|
|
91
91
|
const WEBSOCKET_CALL_CONTEXT = Symbol.for("llm-logger-openclaw-plugin.wsCallContext");
|
|
92
92
|
const OBSERVED_WS_PATHS = ["/v1/responses"];
|
|
93
93
|
const TURN_METADATA_TTL_MS = 5 * 60 * 1000;
|
|
94
|
-
const UNKNOWN_SESSION_DIR = "
|
|
94
|
+
const UNKNOWN_SESSION_DIR = "_unknown_session_key";
|
|
95
95
|
|
|
96
96
|
type PatchHandles = {
|
|
97
97
|
restore: () => void;
|
|
@@ -479,21 +479,22 @@ class PluginManager {
|
|
|
479
479
|
ts: new Date().toISOString(),
|
|
480
480
|
plugin: state.pluginId,
|
|
481
481
|
sessionId: this.#currentCallContext()?.sessionId,
|
|
482
|
+
sessionKey: this.#currentCallContext()?.sessionKey,
|
|
482
483
|
...record,
|
|
483
484
|
};
|
|
484
|
-
const
|
|
485
|
-
typeof event.
|
|
486
|
-
? event.
|
|
485
|
+
const sessionKey =
|
|
486
|
+
typeof event.sessionKey === "string" && event.sessionKey.trim().length > 0
|
|
487
|
+
? event.sessionKey
|
|
487
488
|
: undefined;
|
|
488
|
-
const writer = this.#getWriterForEvent(state,
|
|
489
|
+
const writer = this.#getWriterForEvent(state, sessionKey, new Date());
|
|
489
490
|
|
|
490
491
|
void writer.write(event).catch((error) => {
|
|
491
492
|
this.#logger().warn(`[${state.pluginId}] failed to write log entry: ${this.#formatError(error)}`);
|
|
492
493
|
});
|
|
493
494
|
}
|
|
494
495
|
|
|
495
|
-
#getWriterForEvent(state: ActiveState,
|
|
496
|
-
const sessionDir = this.#sanitizeSessionDirName(
|
|
496
|
+
#getWriterForEvent(state: ActiveState, sessionKey: string | undefined, now: Date): JsonlWriter {
|
|
497
|
+
const sessionDir = this.#sanitizeSessionDirName(sessionKey);
|
|
497
498
|
const dateSuffix = this.#formatDateSuffix(now);
|
|
498
499
|
const key = `${sessionDir}|${dateSuffix}`;
|
|
499
500
|
const cachedWriter = state.writers.get(key);
|
|
@@ -515,11 +516,11 @@ class PluginManager {
|
|
|
515
516
|
return path.join(parsed.dir, sessionDir, filename);
|
|
516
517
|
}
|
|
517
518
|
|
|
518
|
-
#sanitizeSessionDirName(
|
|
519
|
-
if (!
|
|
519
|
+
#sanitizeSessionDirName(sessionKey: string | undefined): string {
|
|
520
|
+
if (!sessionKey) {
|
|
520
521
|
return UNKNOWN_SESSION_DIR;
|
|
521
522
|
}
|
|
522
|
-
const normalized =
|
|
523
|
+
const normalized = sessionKey.trim();
|
|
523
524
|
if (!normalized) {
|
|
524
525
|
return UNKNOWN_SESSION_DIR;
|
|
525
526
|
}
|