@clwnt/clawnet 0.7.9 → 0.7.11

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/service.ts +21 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clwnt/clawnet",
3
- "version": "0.7.9",
3
+ "version": "0.7.11",
4
4
  "type": "module",
5
5
  "description": "ClawNet integration for OpenClaw — poll inbox, route messages to hooks",
6
6
  "files": [
package/src/service.ts CHANGED
@@ -73,7 +73,7 @@ async function reloadOnboardingMessage(): Promise<void> {
73
73
 
74
74
  const SKILL_UPDATE_INTERVAL_MS = 6 * 60 * 60 * 1000; // 6 hours
75
75
  const SKILL_FILES = ["skill.json", "api-reference.md", "inbox-handler.md", "capabilities.json", "hook-template.txt", "tool-descriptions.json", "onboarding-message.txt", "inbox-protocol.md"];
76
- export const PLUGIN_VERSION = "0.7.8"; // Reported to server via PATCH /me every 6h
76
+ export const PLUGIN_VERSION = "0.7.11"; // Reported to server via PATCH /me every 6h
77
77
 
78
78
  function loadFreshConfig(api: any): ClawnetConfig {
79
79
  const raw = api.runtime?.config?.loadConfig?.()?.plugins?.entries?.clawnet?.config ?? {};
@@ -145,7 +145,9 @@ export function createClawnetService(params: { api: any; cfg: ClawnetConfig }) {
145
145
  if (accountBusy.has(accountId)) {
146
146
  api.logger.info(`[clawnet] ${accountId}: LLM run in progress, requeueing ${messages.length} message(s)`);
147
147
  const existing = pendingMessages.get(accountId) ?? [];
148
- pendingMessages.set(accountId, [...existing, ...messages]);
148
+ const existingIds = new Set(existing.map((m) => m.id));
149
+ const fresh = messages.filter((m) => !existingIds.has(m.id));
150
+ pendingMessages.set(accountId, [...existing, ...fresh]);
149
151
  return;
150
152
  }
151
153
 
@@ -163,7 +165,6 @@ export function createClawnetService(params: { api: any; cfg: ClawnetConfig }) {
163
165
 
164
166
  state.counters.batchesSent++;
165
167
  state.counters.delivered += messages.length;
166
- deliveryLock.set(accountId, new Date(Date.now() + DELIVERY_LOCK_TTL_MS));
167
168
  api.logger.info(
168
169
  `[clawnet] ${accountId}: delivered ${messages.length} message(s) to ${agentId} via ${freshCfg.deliveryMethod}`,
169
170
  );
@@ -203,7 +204,14 @@ export function createClawnetService(params: { api: any; cfg: ClawnetConfig }) {
203
204
  state.counters.errors++;
204
205
  api.logger.error(`[clawnet] ${accountId}: batch delivery failed: ${err.message}`);
205
206
  } finally {
207
+ // Always set delivery lock — even on error, rate-limit retries
208
+ deliveryLock.set(accountId, new Date(Date.now() + DELIVERY_LOCK_TTL_MS));
206
209
  accountBusy.delete(accountId);
210
+ // Flush any messages that accumulated while we were busy (overflow/requeue)
211
+ const remaining = pendingMessages.get(accountId);
212
+ if (remaining && remaining.length > 0) {
213
+ scheduleFlush(accountId, agentId);
214
+ }
207
215
  }
208
216
  }
209
217
 
@@ -436,9 +444,11 @@ export function createClawnetService(params: { api: any; cfg: ClawnetConfig }) {
436
444
 
437
445
  state.counters.messagesSeen += normalized.length;
438
446
 
439
- // Add to pending and schedule debounced flush
447
+ // Add to pending (dedup by ID) and schedule debounced flush
440
448
  const existing = pendingMessages.get(account.id) ?? [];
441
- pendingMessages.set(account.id, [...existing, ...normalized]);
449
+ const existingIds = new Set(existing.map((m) => m.id));
450
+ const fresh = normalized.filter((m) => !existingIds.has(m.id));
451
+ pendingMessages.set(account.id, [...existing, ...fresh]);
442
452
  scheduleFlush(account.id, account.agentId);
443
453
 
444
454
  return { a2aDmCount, sentTaskUpdates, notifyCount };
@@ -501,7 +511,9 @@ export function createClawnetService(params: { api: any; cfg: ClawnetConfig }) {
501
511
 
502
512
  state.counters.messagesSeen += messages.length;
503
513
  const existing = pendingMessages.get(account.id) ?? [];
504
- pendingMessages.set(account.id, [...existing, ...messages]);
514
+ const existingIds = new Set(existing.map((m) => m.id));
515
+ const freshTasks = messages.filter((m) => !existingIds.has(m.id));
516
+ pendingMessages.set(account.id, [...existing, ...freshTasks]);
505
517
  scheduleFlush(account.id, account.agentId);
506
518
  }
507
519
 
@@ -554,7 +566,9 @@ export function createClawnetService(params: { api: any; cfg: ClawnetConfig }) {
554
566
 
555
567
  state.counters.messagesSeen += messages.length;
556
568
  const existing = pendingMessages.get(account.id) ?? [];
557
- pendingMessages.set(account.id, [...existing, ...messages]);
569
+ const existingIds = new Set(existing.map((m) => m.id));
570
+ const freshUpdates = messages.filter((m) => !existingIds.has(m.id));
571
+ pendingMessages.set(account.id, [...existing, ...freshUpdates]);
558
572
  scheduleFlush(account.id, account.agentId);
559
573
  }
560
574