@unicitylabs/openclaw-unicity 0.5.6 → 0.5.8
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 +1 -1
- package/src/channel.ts +21 -9
- package/src/sphere.ts +4 -1
package/package.json
CHANGED
package/src/channel.ts
CHANGED
|
@@ -103,6 +103,8 @@ let activeSphere: Sphere | null = null;
|
|
|
103
103
|
let pluginRuntime: PluginRuntime | null = null;
|
|
104
104
|
let ownerIdentity: string | null = null;
|
|
105
105
|
let pluginConfig: UnicityConfig = {};
|
|
106
|
+
/** Cleanup function from the previous gateway start — called before re-subscribing. */
|
|
107
|
+
let previousGatewayCleanup: (() => void) | null = null;
|
|
106
108
|
|
|
107
109
|
export function setUnicityRuntime(rt: PluginRuntime): void {
|
|
108
110
|
pluginRuntime = rt;
|
|
@@ -223,6 +225,14 @@ export const unicityChannelPlugin = {
|
|
|
223
225
|
log?: { info: (m: string) => void; warn: (m: string) => void; error: (m: string) => void; debug: (m: string) => void };
|
|
224
226
|
setStatus: (s: Record<string, unknown>) => void;
|
|
225
227
|
}) => {
|
|
228
|
+
// Clean up handlers from any previous gateway start (auto-restart scenario).
|
|
229
|
+
// Without this, each restart stacks duplicate onDirectMessage handlers on the
|
|
230
|
+
// shared Sphere singleton, causing messages to be processed N times.
|
|
231
|
+
if (previousGatewayCleanup) {
|
|
232
|
+
previousGatewayCleanup();
|
|
233
|
+
previousGatewayCleanup = null;
|
|
234
|
+
}
|
|
235
|
+
|
|
226
236
|
const sphere = activeSphere ?? await waitForSphere();
|
|
227
237
|
if (!sphere) throw new Error("Unicity Sphere not initialized — run `openclaw unicity init`");
|
|
228
238
|
|
|
@@ -692,7 +702,7 @@ export const unicityChannelPlugin = {
|
|
|
692
702
|
groupBackfillStates.clear();
|
|
693
703
|
}
|
|
694
704
|
|
|
695
|
-
|
|
705
|
+
function cleanupSubscriptions(): void {
|
|
696
706
|
clearBackfillTimers();
|
|
697
707
|
unsub();
|
|
698
708
|
unsubTransfer();
|
|
@@ -701,18 +711,20 @@ export const unicityChannelPlugin = {
|
|
|
701
711
|
unsubGroupJoined();
|
|
702
712
|
unsubGroupLeft();
|
|
703
713
|
unsubGroupKicked();
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
// Store cleanup so auto-restart can tear down stale handlers
|
|
717
|
+
previousGatewayCleanup = cleanupSubscriptions;
|
|
718
|
+
|
|
719
|
+
ctx.abortSignal.addEventListener("abort", () => {
|
|
720
|
+
cleanupSubscriptions();
|
|
721
|
+
previousGatewayCleanup = null;
|
|
704
722
|
}, { once: true });
|
|
705
723
|
|
|
706
724
|
return {
|
|
707
725
|
stop: () => {
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
unsubTransfer();
|
|
711
|
-
unsubPaymentRequest();
|
|
712
|
-
unsubGroupMessage();
|
|
713
|
-
unsubGroupJoined();
|
|
714
|
-
unsubGroupLeft();
|
|
715
|
-
unsubGroupKicked();
|
|
726
|
+
cleanupSubscriptions();
|
|
727
|
+
previousGatewayCleanup = null;
|
|
716
728
|
ctx.log?.info(`[${ctx.account.accountId}] Unicity channel stopped`);
|
|
717
729
|
},
|
|
718
730
|
};
|
package/src/sphere.ts
CHANGED
|
@@ -14,6 +14,9 @@ export { DATA_DIR, MNEMONIC_PATH, walletExists };
|
|
|
14
14
|
/** Default testnet API key (from Sphere app) */
|
|
15
15
|
const DEFAULT_API_KEY = "sk_06365a9c44654841a366068bcfc68986";
|
|
16
16
|
|
|
17
|
+
/** How far back to fetch DMs on first connect (seconds). */
|
|
18
|
+
export const DM_LOOKBACK_SECONDS = 86_400;
|
|
19
|
+
|
|
17
20
|
let sphereInstance: Sphere | null = null;
|
|
18
21
|
let initPromise: Promise<InitSphereResult> | null = null;
|
|
19
22
|
|
|
@@ -116,7 +119,7 @@ async function doInitSphere(
|
|
|
116
119
|
...(existingMnemonic ? { mnemonic: existingMnemonic } : { autoGenerate: true }),
|
|
117
120
|
...(cfg.nametag ? { nametag: cfg.nametag } : {}),
|
|
118
121
|
...(groupChat ? { groupChat: groupChatRelays ? { relays: groupChatRelays } : true } : {}),
|
|
119
|
-
dmSince: Math.floor(Date.now() / 1000) -
|
|
122
|
+
dmSince: Math.floor(Date.now() / 1000) - DM_LOOKBACK_SECONDS,
|
|
120
123
|
});
|
|
121
124
|
|
|
122
125
|
sphereInstance = result.sphere;
|