@unicitylabs/openclaw-unicity 0.5.1 → 0.5.2

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/channel.ts +23 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unicitylabs/openclaw-unicity",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Unicity wallet identity and encrypted DMs for OpenClaw agents — powered by Sphere SDK",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/channel.ts CHANGED
@@ -242,7 +242,30 @@ export const unicityChannelPlugin = {
242
242
 
243
243
  ctx.log?.info(`[${ctx.account.accountId}] Subscribing to DMs (pubkey: ${sphere.identity?.chainPubkey?.slice(0, 16)}...)`);
244
244
 
245
+ // Track DM start time and seen IDs to skip historical replays from the relay.
246
+ // The SDK fires onDirectMessage for every cached/replayed DM on connect.
247
+ const dmStartTime = Math.floor(Date.now() / 1000);
248
+ const seenDmIds = new Set<string>();
249
+ const DM_SEEN_MAX = 1000;
250
+
251
+
245
252
  const unsub = sphere.communications.onDirectMessage((msg) => {
253
+ // Deduplicate: skip already-processed messages (relays may deliver dupes)
254
+ if (msg.id && seenDmIds.has(msg.id)) return;
255
+ if (msg.id) {
256
+ seenDmIds.add(msg.id);
257
+ if (seenDmIds.size > DM_SEEN_MAX) {
258
+ const first = seenDmIds.values().next().value!;
259
+ seenDmIds.delete(first);
260
+ }
261
+ }
262
+
263
+ // Skip historical messages replayed on connect
264
+ if (msg.timestamp && msg.timestamp < dmStartTime) {
265
+ ctx.log?.debug(`[${ctx.account.accountId}] Skipping historical DM (ts=${msg.timestamp} < start=${dmStartTime})`);
266
+ return;
267
+ }
268
+
246
269
  // Immediately signal that we're composing a reply
247
270
  sphere.communications.sendComposingIndicator(msg.senderPubkey)
248
271
  .catch((err: unknown) => ctx.log?.error(`[${ctx.account.accountId}] Composing indicator failed: ${err}`));