openclaw-channel-dmwork 0.2.13 → 0.2.15

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 +32 -51
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.15",
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
  }
@@ -85,6 +80,19 @@ export async function handleInboundMessage(params: {
85
80
  return;
86
81
  }
87
82
 
83
+ // Extract quoted/replied message content if present
84
+ let quotePrefix = "";
85
+ const replyData = message.payload?.reply;
86
+ if (replyData) {
87
+ const replyPayload = replyData.payload;
88
+ const replyContent = replyPayload?.content ?? resolveContent(replyPayload);
89
+ const replyFrom = replyData.from_uid ?? replyData.from_name ?? "unknown";
90
+ if (replyContent) {
91
+ quotePrefix = `[Quoted message from ${replyFrom}]: ${replyContent}\n---\n`;
92
+ log?.info?.(`dmwork: message quotes a reply (${quotePrefix.length} chars)`);
93
+ }
94
+ }
95
+
88
96
  // --- Mention gating for group messages ---
89
97
  const requireMention = account.config.requireMention !== false;
90
98
  let historyPrefix = "";
@@ -95,33 +103,18 @@ export async function handleInboundMessage(params: {
95
103
  const isMentioned = mentionAll || mentionUids.includes(botUid);
96
104
 
97
105
  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
- }
106
+ // Record as pending history context (manual avoids SDK format incompatibility)
107
+ if (!groupHistories.has(sessionId)) {
108
+ groupHistories.set(sessionId, []);
109
+ }
110
+ const entries = groupHistories.get(sessionId)!;
111
+ entries.push({
112
+ sender: message.from_uid,
113
+ body: rawBody,
114
+ timestamp: message.timestamp ? message.timestamp * 1000 : Date.now(),
115
+ });
116
+ while (entries.length > DEFAULT_GROUP_HISTORY_LIMIT) {
117
+ entries.shift();
125
118
  }
126
119
  log?.info?.(
127
120
  `dmwork: group message not mentioning bot, recorded as history context`,
@@ -129,26 +122,14 @@ export async function handleInboundMessage(params: {
129
122
  return;
130
123
  }
131
124
 
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
125
+ // Bot IS mentioned — prepend history context (manual — avoids SDK format incompatibility)
126
+ {
146
127
  const entries = groupHistories.get(sessionId) ?? [];
147
128
  if (entries.length > 0) {
148
129
  historyPrefix = entries
149
130
  .map((e: any) => `[${e.sender}]: ${e.body}`)
150
131
  .join("\n") + "\n---\n";
151
- log?.info?.(`dmwork: prepending history context (${historyPrefix.length} chars, fallback)`);
132
+ log?.info?.(`dmwork: prepending history context (${historyPrefix.length} chars)`);
152
133
  }
153
134
  }
154
135
 
@@ -206,7 +187,7 @@ export async function handleInboundMessage(params: {
206
187
  sessionKey: route.sessionKey,
207
188
  });
208
189
 
209
- const finalBody = historyPrefix ? historyPrefix + rawBody : rawBody;
190
+ const finalBody = (historyPrefix || quotePrefix) ? (historyPrefix + quotePrefix + rawBody) : rawBody;
210
191
 
211
192
  const body = core.channel.reply.formatAgentEnvelope({
212
193
  channel: "DMWork",