openclaw-channel-dmwork 0.2.12 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-channel-dmwork",
3
- "version": "0.2.12",
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/channel.ts CHANGED
@@ -217,7 +217,7 @@ export const dmworkPlugin: ChannelPlugin<ResolvedDmworkAccount> = {
217
217
  log,
218
218
  statusSink,
219
219
  }).catch((err) => {
220
- log?.error?.(`dmwork: inbound handler failed: ${String(err)}`);
220
+ log?.error?.(`dmwork: inbound handler failed: ${err instanceof Error ? err.stack ?? String(err) : String(err)}`);
221
221
  });
222
222
  },
223
223
 
@@ -262,32 +262,29 @@ export const dmworkPlugin: ChannelPlugin<ResolvedDmworkAccount> = {
262
262
 
263
263
  socket.connect();
264
264
 
265
- // Handle abort signal
266
- const onAbort = () => {
267
- stopped = true;
268
- socket.disconnect();
269
- if (heartbeatTimer) { clearInterval(heartbeatTimer); heartbeatTimer = null; }
270
- };
271
-
272
- if (ctx.abortSignal.aborted) {
273
- onAbort();
274
- } else {
275
- ctx.abortSignal.addEventListener("abort", onAbort, { once: true });
276
- }
277
-
278
- return {
279
- stop: () => {
265
+ // Keep Promise pending until stopped — gateway treats resolve as "account stopped"
266
+ return new Promise((resolve) => {
267
+ const cleanup = () => {
268
+ if (stopped) return;
280
269
  stopped = true;
281
270
  socket.disconnect();
282
271
  if (heartbeatTimer) { clearInterval(heartbeatTimer); heartbeatTimer = null; }
283
- ctx.abortSignal.removeEventListener("abort", onAbort);
284
272
  ctx.setStatus({
285
273
  accountId: account.accountId,
286
274
  running: false,
287
275
  lastStopAt: Date.now(),
288
276
  });
289
- },
290
- };
277
+ resolve({
278
+ stop: () => { /* already cleaned up */ },
279
+ });
280
+ };
281
+
282
+ if (ctx.abortSignal.aborted) {
283
+ cleanup();
284
+ } else {
285
+ ctx.abortSignal.addEventListener("abort", cleanup, { once: true });
286
+ }
287
+ });
291
288
  },
292
289
  },
293
290
  };
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