mtmoc 0.0.18 → 0.0.20
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/commands/hello.d.ts +2 -0
- package/dist/hooks/after_tool_call.d.ts +2 -0
- package/dist/index.js +48 -17
- package/dist/tools/hello_tools.d.ts +0 -0
- package/package.json +1 -4
- package/src/commands/hello.ts +11 -0
- package/src/hooks/after_tool_call.ts +29 -0
- package/src/index.ts +10 -23
- package/src/tools/hello_tools.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1,14 +1,54 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// src/index.ts
|
|
3
|
+
import fs2 from "fs";
|
|
4
|
+
|
|
5
|
+
// src/commands/hello.ts
|
|
6
|
+
function registarHelloCommand(api) {
|
|
7
|
+
api.registerCommand({
|
|
8
|
+
name: "mtm_hello",
|
|
9
|
+
description: "Mtm Hello",
|
|
10
|
+
handler: (_ctx) => {
|
|
11
|
+
return { text: "Hello \u547D\u4EE4\u5DF2\u7ECF\u88AB\u8C03\u7528\u4E86" };
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/hooks/after_tool_call.ts
|
|
3
17
|
import fs from "fs";
|
|
18
|
+
function registarAfterToolCallHook(api) {
|
|
19
|
+
const logFile = api.pluginConfig?.logFile || "./mtmoc-events.log";
|
|
20
|
+
const log = (event, data) => {
|
|
21
|
+
const timestamp = new Date().toISOString();
|
|
22
|
+
const entry = `[${timestamp}] [${event}] ${JSON.stringify(data)}
|
|
23
|
+
`;
|
|
24
|
+
try {
|
|
25
|
+
fs.appendFileSync(logFile, entry);
|
|
26
|
+
} catch (err) {
|
|
27
|
+
api.logger.error(`Failed to write to log file: ${err}`);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
api.on("after_tool_call", (event, ctx) => {
|
|
31
|
+
log("after_tool_call", {
|
|
32
|
+
toolName: event.toolName,
|
|
33
|
+
result: event.result,
|
|
34
|
+
error: event.error,
|
|
35
|
+
durationMs: event.durationMs,
|
|
36
|
+
agentId: ctx.agentId,
|
|
37
|
+
sessionKey: ctx.sessionKey
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// src/index.ts
|
|
43
|
+
var DEFAULT_LOG_FILE = "./mtmoc-events.log";
|
|
4
44
|
var mtmocPlugin = {
|
|
5
45
|
id: "mtmoc",
|
|
6
|
-
name: "MTMOC
|
|
7
|
-
description: "
|
|
46
|
+
name: "MTMOC",
|
|
47
|
+
description: "MTMOC",
|
|
8
48
|
register(api) {
|
|
9
|
-
const logFile = api.pluginConfig?.logFile ||
|
|
49
|
+
const logFile = api.pluginConfig?.logFile || DEFAULT_LOG_FILE;
|
|
10
50
|
try {
|
|
11
|
-
|
|
51
|
+
fs2.appendFileSync(logFile, "");
|
|
12
52
|
} catch (err) {
|
|
13
53
|
api.logger.error(`Failed to initialize log file ${logFile}: ${err}`);
|
|
14
54
|
}
|
|
@@ -17,12 +57,11 @@ var mtmocPlugin = {
|
|
|
17
57
|
const entry = `[${timestamp}] [${event}] ${JSON.stringify(data)}
|
|
18
58
|
`;
|
|
19
59
|
try {
|
|
20
|
-
|
|
60
|
+
fs2.appendFileSync(logFile, entry);
|
|
21
61
|
} catch (err) {
|
|
22
62
|
api.logger.error(`Failed to write to log file: ${err}`);
|
|
23
63
|
}
|
|
24
64
|
};
|
|
25
|
-
api.logger.info(`MTMOC Plugin registering... Log file: ${logFile}`);
|
|
26
65
|
api.on("message_received", (event, ctx) => {
|
|
27
66
|
log("message_received", {
|
|
28
67
|
from: event.from,
|
|
@@ -63,16 +102,6 @@ var mtmocPlugin = {
|
|
|
63
102
|
sessionKey: ctx.sessionKey
|
|
64
103
|
});
|
|
65
104
|
});
|
|
66
|
-
api.on("after_tool_call", (event, ctx) => {
|
|
67
|
-
log("after_tool_call", {
|
|
68
|
-
toolName: event.toolName,
|
|
69
|
-
result: event.result,
|
|
70
|
-
error: event.error,
|
|
71
|
-
durationMs: event.durationMs,
|
|
72
|
-
agentId: ctx.agentId,
|
|
73
|
-
sessionKey: ctx.sessionKey
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
105
|
api.on("tool_result_persist", (event, ctx) => {
|
|
77
106
|
log("tool_result_persist", {
|
|
78
107
|
toolName: event.toolName,
|
|
@@ -81,7 +110,9 @@ var mtmocPlugin = {
|
|
|
81
110
|
isSynthetic: event.isSynthetic
|
|
82
111
|
});
|
|
83
112
|
});
|
|
84
|
-
api
|
|
113
|
+
registarAfterToolCallHook(api);
|
|
114
|
+
registarHelloCommand(api);
|
|
115
|
+
api.logger.info(`MTMOC Plugin registered successfully. Log file: ${logFile}`);
|
|
85
116
|
}
|
|
86
117
|
};
|
|
87
118
|
var src_default = mtmocPlugin;
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mtmoc",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"description": "OpenClaw plugin for event logging",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -34,9 +34,6 @@
|
|
|
34
34
|
"build": "bun build src/index.ts --outdir dist --target bun --format esm && tsc --emitDeclarationOnly",
|
|
35
35
|
"clean": "rm -rf dist",
|
|
36
36
|
"prepublishOnly": "bun run clean && bun run build",
|
|
37
|
-
"release:patch": "npm version patch && npm publish",
|
|
38
|
-
"release:minor": "npm version minor && npm publish",
|
|
39
|
-
"release:major": "npm version major && npm publish",
|
|
40
37
|
"typecheck": "tsc --noEmit"
|
|
41
38
|
},
|
|
42
39
|
"keywords": [
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { OpenClawPluginApi, ReplyPayload } from "openclaw/plugin-sdk";
|
|
2
|
+
|
|
3
|
+
export function registarHelloCommand(api: OpenClawPluginApi) {
|
|
4
|
+
api.registerCommand({
|
|
5
|
+
name: "mtm_hello",
|
|
6
|
+
description: "Mtm Hello",
|
|
7
|
+
handler: (_ctx) => {
|
|
8
|
+
return { text: "Hello 命令已经被调用了" } satisfies ReplyPayload;
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export function registarAfterToolCallHook(api: OpenClawPluginApi) {
|
|
8
|
+
|
|
9
|
+
const logFile = api.pluginConfig?.logFile as string || "./mtmoc-events.log";
|
|
10
|
+
const log = (event: string, data: any) => {
|
|
11
|
+
const timestamp = new Date().toISOString();
|
|
12
|
+
const entry = `[${timestamp}] [${event}] ${JSON.stringify(data)}\n`;
|
|
13
|
+
try {
|
|
14
|
+
fs.appendFileSync(logFile, entry);
|
|
15
|
+
} catch (err) {
|
|
16
|
+
api.logger.error(`Failed to write to log file: ${err}`);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
api.on("after_tool_call", (event, ctx) => {
|
|
20
|
+
log("after_tool_call", {
|
|
21
|
+
toolName: event.toolName,
|
|
22
|
+
result: event.result, // Note: Result might be large
|
|
23
|
+
error: event.error,
|
|
24
|
+
durationMs: event.durationMs,
|
|
25
|
+
agentId: ctx.agentId,
|
|
26
|
+
sessionKey: ctx.sessionKey,
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
3
|
+
import { registarHelloCommand } from "./commands/hello";
|
|
4
|
+
import { registarAfterToolCallHook } from "./hooks/after_tool_call";
|
|
5
|
+
|
|
6
|
+
const DEFAULT_LOG_FILE = "./mtmoc-events.log";
|
|
3
7
|
|
|
4
8
|
const mtmocPlugin = {
|
|
5
9
|
id: "mtmoc",
|
|
6
|
-
name: "MTMOC
|
|
7
|
-
description: "
|
|
10
|
+
name: "MTMOC",
|
|
11
|
+
description: "MTMOC",
|
|
8
12
|
register(api: OpenClawPluginApi) {
|
|
9
|
-
const logFile = (api.pluginConfig?.logFile as string) ||
|
|
13
|
+
const logFile = (api.pluginConfig?.logFile as string) || DEFAULT_LOG_FILE;
|
|
10
14
|
|
|
11
|
-
// Ensure log file is writable or create it
|
|
12
15
|
try {
|
|
13
16
|
fs.appendFileSync(logFile, "");
|
|
14
17
|
} catch (err) {
|
|
@@ -24,10 +27,6 @@ const mtmocPlugin = {
|
|
|
24
27
|
api.logger.error(`Failed to write to log file: ${err}`);
|
|
25
28
|
}
|
|
26
29
|
};
|
|
27
|
-
|
|
28
|
-
api.logger.info(`MTMOC Plugin registering... Log file: ${logFile}`);
|
|
29
|
-
|
|
30
|
-
// Hook: message_received
|
|
31
30
|
api.on("message_received", (event, ctx) => {
|
|
32
31
|
log("message_received", {
|
|
33
32
|
from: event.from,
|
|
@@ -37,7 +36,6 @@ const mtmocPlugin = {
|
|
|
37
36
|
});
|
|
38
37
|
});
|
|
39
38
|
|
|
40
|
-
// Hook: message_sent
|
|
41
39
|
api.on("message_sent", (event, ctx) => {
|
|
42
40
|
log("message_sent", {
|
|
43
41
|
to: event.to,
|
|
@@ -48,7 +46,6 @@ const mtmocPlugin = {
|
|
|
48
46
|
});
|
|
49
47
|
});
|
|
50
48
|
|
|
51
|
-
// Hook: session_start
|
|
52
49
|
api.on("session_start", (event, ctx) => {
|
|
53
50
|
log("session_start", {
|
|
54
51
|
sessionId: event.sessionId,
|
|
@@ -77,17 +74,6 @@ const mtmocPlugin = {
|
|
|
77
74
|
});
|
|
78
75
|
});
|
|
79
76
|
|
|
80
|
-
// Hook: after_tool_call
|
|
81
|
-
api.on("after_tool_call", (event, ctx) => {
|
|
82
|
-
log("after_tool_call", {
|
|
83
|
-
toolName: event.toolName,
|
|
84
|
-
result: event.result, // Note: Result might be large
|
|
85
|
-
error: event.error,
|
|
86
|
-
durationMs: event.durationMs,
|
|
87
|
-
agentId: ctx.agentId,
|
|
88
|
-
sessionKey: ctx.sessionKey,
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
77
|
|
|
92
78
|
// Hook: tool_result_persist (Auditing what gets saved to memory)
|
|
93
79
|
api.on("tool_result_persist", (event, ctx) => {
|
|
@@ -98,8 +84,9 @@ const mtmocPlugin = {
|
|
|
98
84
|
isSynthetic: event.isSynthetic
|
|
99
85
|
});
|
|
100
86
|
});
|
|
101
|
-
|
|
102
|
-
api
|
|
87
|
+
registarAfterToolCallHook(api);
|
|
88
|
+
registarHelloCommand(api);
|
|
89
|
+
api.logger.info(`MTMOC Plugin registered successfully. Log file: ${logFile}`);
|
|
103
90
|
},
|
|
104
91
|
};
|
|
105
92
|
|
|
File without changes
|