openclaw-channel-dmwork 0.2.5 → 0.2.7
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/channel.ts +13 -2
- package/src/inbound.ts +22 -9
package/package.json
CHANGED
package/src/channel.ts
CHANGED
|
@@ -20,6 +20,17 @@ import { ChannelType, MessageType, type BotMessage, type MessagePayload } from "
|
|
|
20
20
|
type HistoryEntry = { sender: string; body: string; timestamp: number };
|
|
21
21
|
const DEFAULT_GROUP_HISTORY_LIMIT = 20;
|
|
22
22
|
|
|
23
|
+
// Module-level history storage — survives auto-restarts
|
|
24
|
+
const _historyMaps = new Map<string, Map<string, any[]>>();
|
|
25
|
+
function getOrCreateHistoryMap(accountId: string): Map<string, any[]> {
|
|
26
|
+
let m = _historyMaps.get(accountId);
|
|
27
|
+
if (!m) {
|
|
28
|
+
m = new Map<string, any[]>();
|
|
29
|
+
_historyMaps.set(accountId, m);
|
|
30
|
+
}
|
|
31
|
+
return m;
|
|
32
|
+
}
|
|
33
|
+
|
|
23
34
|
const meta = {
|
|
24
35
|
id: "dmwork",
|
|
25
36
|
label: "DMWork",
|
|
@@ -177,8 +188,8 @@ export const dmworkPlugin: ChannelPlugin<ResolvedDmworkAccount> = {
|
|
|
177
188
|
}, account.config.heartbeatIntervalMs);
|
|
178
189
|
};
|
|
179
190
|
|
|
180
|
-
// 4. Group history map
|
|
181
|
-
const groupHistories =
|
|
191
|
+
// 4. Group history map — persists across auto-restarts (module-level)
|
|
192
|
+
const groupHistories = getOrCreateHistoryMap(account.accountId);
|
|
182
193
|
|
|
183
194
|
// 5. Token refresh state — detect stale cached token
|
|
184
195
|
let hasRefreshedToken = false;
|
package/src/inbound.ts
CHANGED
|
@@ -10,17 +10,28 @@ let recordPendingHistoryEntryIfEnabled: any;
|
|
|
10
10
|
let buildPendingHistoryContextFromMap: any;
|
|
11
11
|
let clearHistoryEntriesIfEnabled: any;
|
|
12
12
|
let DEFAULT_GROUP_HISTORY_LIMIT = 20;
|
|
13
|
+
let _sdkLoaded = false;
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
async function ensureSdkLoaded() {
|
|
16
|
+
if (_sdkLoaded) return;
|
|
17
|
+
_sdkLoaded = true;
|
|
18
|
+
try {
|
|
19
|
+
const sdk = await import("openclaw/plugin-sdk");
|
|
20
|
+
if (typeof sdk.recordPendingHistoryEntryIfEnabled === "function") {
|
|
21
|
+
recordPendingHistoryEntryIfEnabled = sdk.recordPendingHistoryEntryIfEnabled;
|
|
22
|
+
}
|
|
23
|
+
if (typeof sdk.buildPendingHistoryContextFromMap === "function") {
|
|
24
|
+
buildPendingHistoryContextFromMap = sdk.buildPendingHistoryContextFromMap;
|
|
25
|
+
}
|
|
26
|
+
if (typeof sdk.clearHistoryEntriesIfEnabled === "function") {
|
|
27
|
+
clearHistoryEntriesIfEnabled = sdk.clearHistoryEntriesIfEnabled;
|
|
28
|
+
}
|
|
29
|
+
if (sdk.DEFAULT_GROUP_HISTORY_LIMIT) {
|
|
30
|
+
DEFAULT_GROUP_HISTORY_LIMIT = sdk.DEFAULT_GROUP_HISTORY_LIMIT;
|
|
31
|
+
}
|
|
32
|
+
} catch {
|
|
33
|
+
// Older OpenClaw versions may not export these — fallback implementations used
|
|
21
34
|
}
|
|
22
|
-
} catch {
|
|
23
|
-
// Older OpenClaw versions may not export these
|
|
24
35
|
}
|
|
25
36
|
|
|
26
37
|
|
|
@@ -55,6 +66,8 @@ export async function handleInboundMessage(params: {
|
|
|
55
66
|
}) {
|
|
56
67
|
const { account, message, botUid, groupHistories, log, statusSink } = params;
|
|
57
68
|
|
|
69
|
+
await ensureSdkLoaded();
|
|
70
|
+
|
|
58
71
|
const isGroup =
|
|
59
72
|
typeof message.channel_id === "string" &&
|
|
60
73
|
message.channel_id.length > 0 &&
|