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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/inbound.ts +18 -50
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-channel-dmwork",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
4
4
  "description": "DMWork channel plugin for OpenClaw via WuKongIM WebSocket",
5
5
  "main": "index.ts",
6
6
  "type": "module",
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
- let recordPendingHistoryEntryIfEnabled: any;
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
- if (typeof sdk.recordPendingHistoryEntryIfEnabled === "function") {
21
- recordPendingHistoryEntryIfEnabled = sdk.recordPendingHistoryEntryIfEnabled;
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 — with fallback for older SDK
99
- if (typeof recordPendingHistoryEntryIfEnabled === "function") {
100
- recordPendingHistoryEntryIfEnabled({
101
- historyMap: groupHistories,
102
- historyKey: sessionId,
103
- entry: {
104
- sender: message.from_uid,
105
- body: rawBody,
106
- timestamp: message.timestamp ? message.timestamp * 1000 : Date.now(),
107
- },
108
- limit: DEFAULT_GROUP_HISTORY_LIMIT,
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
- if (typeof buildPendingHistoryContextFromMap === "function") {
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, fallback)`);
119
+ log?.info?.(`dmwork: prepending history context (${historyPrefix.length} chars)`);
152
120
  }
153
121
  }
154
122