@mobcode/openclaw-plugin 0.1.21 → 0.1.23
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/package.json +1 -1
- package/src/plugin-definition.js +46 -4
package/package.json
CHANGED
package/src/plugin-definition.js
CHANGED
|
@@ -15,20 +15,37 @@ import { registerMobcodeRuntimeObservers } from "./runtime-events.js";
|
|
|
15
15
|
import { MobcodeStateStore } from "./state-store.js";
|
|
16
16
|
import { registerMobcodeTools } from "./plugin-tools.js";
|
|
17
17
|
|
|
18
|
+
function createSafePluginLogger(api) {
|
|
19
|
+
const pluginLogger = api?.logger;
|
|
20
|
+
return {
|
|
21
|
+
debug: pluginLogger?.debug?.bind(pluginLogger) ?? console.debug.bind(console),
|
|
22
|
+
info: pluginLogger?.info?.bind(pluginLogger) ?? console.info.bind(console),
|
|
23
|
+
warn: pluginLogger?.warn?.bind(pluginLogger) ?? console.warn.bind(console),
|
|
24
|
+
error: pluginLogger?.error?.bind(pluginLogger) ?? console.error.bind(console),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function describeLoggerShape(api) {
|
|
29
|
+
return `info=${typeof api?.logger?.info} warn=${typeof api?.logger?.warn} error=${typeof api?.logger?.error} debug=${typeof api?.logger?.debug}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
18
32
|
export function createMobcodePluginDefinition() {
|
|
19
33
|
return {
|
|
20
34
|
id: "mobcode",
|
|
21
35
|
name: "MobCode",
|
|
22
36
|
description: "MobCode mobile integration plugin for OpenClaw.",
|
|
23
37
|
register(api) {
|
|
38
|
+
const log = createSafePluginLogger(api);
|
|
24
39
|
const pluginConfig = api.pluginConfig ?? {};
|
|
25
40
|
const stateDir = api.runtime.state.resolveStateDir();
|
|
26
41
|
const pluginMetadata = readPluginMetadata();
|
|
27
42
|
const store = new MobcodeStateStore({
|
|
28
43
|
rootDir: path.join(stateDir, "plugins", "mobcode"),
|
|
29
|
-
logger:
|
|
44
|
+
logger: log,
|
|
30
45
|
});
|
|
31
46
|
|
|
47
|
+
log.warn(`[mobcode-debug] register loggerShape ${describeLoggerShape(api)}`);
|
|
48
|
+
|
|
32
49
|
const builders = {
|
|
33
50
|
configSnapshot: (options) => buildConfigSnapshot(api, options),
|
|
34
51
|
providers: async () => await tryBuildAvailableProvidersPayload(api),
|
|
@@ -40,7 +57,7 @@ export function createMobcodePluginDefinition() {
|
|
|
40
57
|
api.runtime,
|
|
41
58
|
api.runtime.config.loadConfig(),
|
|
42
59
|
sessionKey,
|
|
43
|
-
|
|
60
|
+
log,
|
|
44
61
|
),
|
|
45
62
|
);
|
|
46
63
|
},
|
|
@@ -68,14 +85,38 @@ export function createMobcodePluginDefinition() {
|
|
|
68
85
|
store,
|
|
69
86
|
});
|
|
70
87
|
api.on("after_tool_call", (event, ctx) => {
|
|
71
|
-
|
|
88
|
+
log.warn(
|
|
72
89
|
`[mobcode-debug] after_tool_call sessionKey=${String(ctx?.sessionKey ?? "").trim() || "-"} toolCallId=${String(event?.toolCallId ?? "").trim() || "-"} toolName=${String(event?.toolName ?? "").trim() || "-"} durationMs=${typeof event?.durationMs === "number" ? String(event.durationMs) : "-"}`,
|
|
73
90
|
);
|
|
74
91
|
});
|
|
75
92
|
api.on("tool_result_persist", (event, ctx) => {
|
|
76
|
-
|
|
93
|
+
console.warn(
|
|
94
|
+
"[mobcode-direct-debug] tool_result_persist enter",
|
|
95
|
+
"sessionKey=",
|
|
96
|
+
String(ctx?.sessionKey ?? "").trim() || "-",
|
|
97
|
+
"toolCallId=",
|
|
98
|
+
String(event?.toolCallId ?? "").trim() || "-",
|
|
99
|
+
"toolName=",
|
|
100
|
+
String(event?.toolName ?? "").trim() || "-",
|
|
101
|
+
"messageId=",
|
|
102
|
+
typeof event?.message?.id === "string" && event.message.id.trim()
|
|
103
|
+
? event.message.id.trim()
|
|
104
|
+
: "-",
|
|
105
|
+
"role=",
|
|
106
|
+
String(event?.message?.role ?? "").trim() || "-",
|
|
107
|
+
);
|
|
108
|
+
log.warn(
|
|
77
109
|
`[mobcode-debug] tool_result_persist sessionKey=${String(ctx?.sessionKey ?? "").trim() || "-"} toolCallId=${String(event?.toolCallId ?? "").trim() || "-"} toolName=${String(event?.toolName ?? "").trim() || "-"} messageId=${typeof event?.message?.id === "string" && event.message.id.trim() ? event.message.id.trim() : "-"}`,
|
|
78
110
|
);
|
|
111
|
+
console.warn(
|
|
112
|
+
"[mobcode-direct-debug] before appendMessageSync",
|
|
113
|
+
"sessionKey=",
|
|
114
|
+
String(ctx?.sessionKey ?? "").trim() || "-",
|
|
115
|
+
"toolCallId=",
|
|
116
|
+
String(event?.toolCallId ?? "").trim() || "-",
|
|
117
|
+
"toolName=",
|
|
118
|
+
String(event?.toolName ?? "").trim() || "-",
|
|
119
|
+
);
|
|
79
120
|
store.appendMessageSync({
|
|
80
121
|
sessionKey: ctx?.sessionKey,
|
|
81
122
|
message: event?.message,
|
|
@@ -84,6 +125,7 @@ export function createMobcodePluginDefinition() {
|
|
|
84
125
|
? event.message.id.trim()
|
|
85
126
|
: undefined,
|
|
86
127
|
});
|
|
128
|
+
console.warn("[mobcode-direct-debug] after appendMessageSync");
|
|
87
129
|
});
|
|
88
130
|
},
|
|
89
131
|
};
|