openclaw-channel-dmwork 0.2.13 → 0.2.14
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/inbound.ts +18 -50
package/package.json
CHANGED
package/src/inbound.ts
CHANGED
|
@@ -6,8 +6,7 @@ import { ChannelType, MessageType } from "./types.js";
|
|
|
6
6
|
import { getDmworkRuntime } from "./runtime.js";
|
|
7
7
|
|
|
8
8
|
// Defensive imports — these may not exist in older OpenClaw versions
|
|
9
|
-
|
|
10
|
-
let buildPendingHistoryContextFromMap: any;
|
|
9
|
+
// History context managed manually for cross-SDK compatibility
|
|
11
10
|
let clearHistoryEntriesIfEnabled: any;
|
|
12
11
|
let DEFAULT_GROUP_HISTORY_LIMIT = 20;
|
|
13
12
|
let _sdkLoaded = false;
|
|
@@ -17,12 +16,8 @@ async function ensureSdkLoaded() {
|
|
|
17
16
|
_sdkLoaded = true;
|
|
18
17
|
try {
|
|
19
18
|
const sdk = await import("openclaw/plugin-sdk");
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
if (typeof sdk.buildPendingHistoryContextFromMap === "function") {
|
|
24
|
-
buildPendingHistoryContextFromMap = sdk.buildPendingHistoryContextFromMap;
|
|
25
|
-
}
|
|
19
|
+
// History context managed manually (SDK buildPendingHistoryContextFromMap
|
|
20
|
+
// has incompatible entry format expectations across versions)
|
|
26
21
|
if (typeof sdk.clearHistoryEntriesIfEnabled === "function") {
|
|
27
22
|
clearHistoryEntriesIfEnabled = sdk.clearHistoryEntriesIfEnabled;
|
|
28
23
|
}
|
|
@@ -95,33 +90,18 @@ export async function handleInboundMessage(params: {
|
|
|
95
90
|
const isMentioned = mentionAll || mentionUids.includes(botUid);
|
|
96
91
|
|
|
97
92
|
if (!isMentioned) {
|
|
98
|
-
// Record as pending history —
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
} else {
|
|
111
|
-
// Manual fallback: store history in the map directly
|
|
112
|
-
if (!groupHistories.has(sessionId)) {
|
|
113
|
-
groupHistories.set(sessionId, []);
|
|
114
|
-
}
|
|
115
|
-
const entries = groupHistories.get(sessionId)!;
|
|
116
|
-
entries.push({
|
|
117
|
-
sender: message.from_uid,
|
|
118
|
-
body: rawBody,
|
|
119
|
-
timestamp: message.timestamp ? message.timestamp * 1000 : Date.now(),
|
|
120
|
-
});
|
|
121
|
-
// Trim to limit
|
|
122
|
-
while (entries.length > DEFAULT_GROUP_HISTORY_LIMIT) {
|
|
123
|
-
entries.shift();
|
|
124
|
-
}
|
|
93
|
+
// Record as pending history context (manual — avoids SDK format incompatibility)
|
|
94
|
+
if (!groupHistories.has(sessionId)) {
|
|
95
|
+
groupHistories.set(sessionId, []);
|
|
96
|
+
}
|
|
97
|
+
const entries = groupHistories.get(sessionId)!;
|
|
98
|
+
entries.push({
|
|
99
|
+
sender: message.from_uid,
|
|
100
|
+
body: rawBody,
|
|
101
|
+
timestamp: message.timestamp ? message.timestamp * 1000 : Date.now(),
|
|
102
|
+
});
|
|
103
|
+
while (entries.length > DEFAULT_GROUP_HISTORY_LIMIT) {
|
|
104
|
+
entries.shift();
|
|
125
105
|
}
|
|
126
106
|
log?.info?.(
|
|
127
107
|
`dmwork: group message not mentioning bot, recorded as history context`,
|
|
@@ -129,26 +109,14 @@ export async function handleInboundMessage(params: {
|
|
|
129
109
|
return;
|
|
130
110
|
}
|
|
131
111
|
|
|
132
|
-
// Bot IS mentioned — prepend history context
|
|
133
|
-
|
|
134
|
-
const enrichedBody = buildPendingHistoryContextFromMap({
|
|
135
|
-
historyMap: groupHistories,
|
|
136
|
-
historyKey: sessionId,
|
|
137
|
-
currentMessage: rawBody,
|
|
138
|
-
limit: DEFAULT_GROUP_HISTORY_LIMIT,
|
|
139
|
-
});
|
|
140
|
-
if (enrichedBody !== rawBody) {
|
|
141
|
-
historyPrefix = enrichedBody.slice(0, enrichedBody.length - rawBody.length);
|
|
142
|
-
log?.info?.(`dmwork: prepending history context (${historyPrefix.length} chars)`);
|
|
143
|
-
}
|
|
144
|
-
} else {
|
|
145
|
-
// Manual fallback: build history prefix
|
|
112
|
+
// Bot IS mentioned — prepend history context (manual — avoids SDK format incompatibility)
|
|
113
|
+
{
|
|
146
114
|
const entries = groupHistories.get(sessionId) ?? [];
|
|
147
115
|
if (entries.length > 0) {
|
|
148
116
|
historyPrefix = entries
|
|
149
117
|
.map((e: any) => `[${e.sender}]: ${e.body}`)
|
|
150
118
|
.join("\n") + "\n---\n";
|
|
151
|
-
log?.info?.(`dmwork: prepending history context (${historyPrefix.length} chars
|
|
119
|
+
log?.info?.(`dmwork: prepending history context (${historyPrefix.length} chars)`);
|
|
152
120
|
}
|
|
153
121
|
}
|
|
154
122
|
|