libp2p-mesh 2026.6.22 → 2026.6.23
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/dist/src/instance-router.js +11 -1
- package/dist/src/plugin.js +26 -0
- package/dist/src/prompt-config.js +1 -1
- package/dist/src/types.d.ts +3 -0
- package/dist/src/user-md-openclaw-extractor.js +2 -2
- package/package.json +1 -1
- package/src/instance-router.ts +12 -1
- package/src/plugin.ts +30 -0
- package/src/prompt-config.ts +1 -1
- package/src/types.ts +3 -0
- package/src/user-md-openclaw-extractor.ts +2 -2
|
@@ -121,6 +121,7 @@ export function createInstanceRouter(options) {
|
|
|
121
121
|
const deliveryCache = new Map();
|
|
122
122
|
const unsubs = [];
|
|
123
123
|
const pendingAttributePeers = new Set();
|
|
124
|
+
let publicAttributeRefreshEnabled = options.publicAttributeRefreshInitiallyEnabled !== false;
|
|
124
125
|
let attributeRefreshPromise;
|
|
125
126
|
function localInstanceId() {
|
|
126
127
|
const identity = mesh.getInstanceIdentity();
|
|
@@ -215,7 +216,9 @@ export function createInstanceRouter(options) {
|
|
|
215
216
|
if (pendingAttributePeers.size === 0 && !attributeRefreshPromise) {
|
|
216
217
|
return;
|
|
217
218
|
}
|
|
218
|
-
|
|
219
|
+
if (publicAttributeRefreshEnabled) {
|
|
220
|
+
drainAttributeRefresh();
|
|
221
|
+
}
|
|
219
222
|
}
|
|
220
223
|
function drainAttributeRefresh() {
|
|
221
224
|
if (!attributeRefreshPromise) {
|
|
@@ -233,6 +236,12 @@ export function createInstanceRouter(options) {
|
|
|
233
236
|
}
|
|
234
237
|
return attributeRefreshPromise;
|
|
235
238
|
}
|
|
239
|
+
function enablePublicAttributeRefresh() {
|
|
240
|
+
publicAttributeRefreshEnabled = true;
|
|
241
|
+
if (pendingAttributePeers.size > 0) {
|
|
242
|
+
drainAttributeRefresh();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
236
245
|
async function announceToPeer(peerId) {
|
|
237
246
|
if (!isNonEmptyString(peerId) || peerId === mesh.getLocalPeerId()) {
|
|
238
247
|
return;
|
|
@@ -667,6 +676,7 @@ export function createInstanceRouter(options) {
|
|
|
667
676
|
stop,
|
|
668
677
|
handleMessage,
|
|
669
678
|
announceToPeer,
|
|
679
|
+
enablePublicAttributeRefresh,
|
|
670
680
|
refreshPublicAttributes,
|
|
671
681
|
listInstances,
|
|
672
682
|
resolveInstance,
|
package/dist/src/plugin.js
CHANGED
|
@@ -10,6 +10,7 @@ import { createOpenClawUserMdAttributeExtractor } from "./user-md-openclaw-extra
|
|
|
10
10
|
import { createUserProfileStore } from "./user-profile-store.js";
|
|
11
11
|
import { buildP2PTools } from "./agent-tools.js";
|
|
12
12
|
import { registerLibp2pMeshCli } from "./profile-cli.js";
|
|
13
|
+
const DEFAULT_PUBLIC_ATTRIBUTE_REFRESH_STARTUP_DELAY_MS = 10000;
|
|
13
14
|
export function registerLibp2pMesh(api) {
|
|
14
15
|
registerLibp2pMeshWithDeps(api);
|
|
15
16
|
}
|
|
@@ -18,6 +19,7 @@ export function registerLibp2pMeshWithDeps(api, deps = {}) {
|
|
|
18
19
|
let unsubscribeInbound;
|
|
19
20
|
let serviceStarted = false;
|
|
20
21
|
let startPromise;
|
|
22
|
+
let publicAttributeRefreshTimer;
|
|
21
23
|
const mesh = (deps.createMeshNetwork ?? createMeshNetwork)({
|
|
22
24
|
config,
|
|
23
25
|
logger: api.logger,
|
|
@@ -50,6 +52,7 @@ export function registerLibp2pMeshWithDeps(api, deps = {}) {
|
|
|
50
52
|
userAttributeSource,
|
|
51
53
|
userProfileStore,
|
|
52
54
|
peerLabelStore,
|
|
55
|
+
publicAttributeRefreshInitiallyEnabled: false,
|
|
53
56
|
});
|
|
54
57
|
registerLibp2pMeshCli(api, {
|
|
55
58
|
profile: {
|
|
@@ -91,7 +94,28 @@ export function registerLibp2pMeshWithDeps(api, deps = {}) {
|
|
|
91
94
|
}
|
|
92
95
|
});
|
|
93
96
|
}
|
|
97
|
+
function publicAttributeRefreshStartupDelayMs() {
|
|
98
|
+
const configured = config?.publicAttributeRefreshStartupDelayMs;
|
|
99
|
+
if (typeof configured === "number" && Number.isFinite(configured) && configured >= 0) {
|
|
100
|
+
return configured;
|
|
101
|
+
}
|
|
102
|
+
return DEFAULT_PUBLIC_ATTRIBUTE_REFRESH_STARTUP_DELAY_MS;
|
|
103
|
+
}
|
|
104
|
+
function clearPublicAttributeRefreshTimer() {
|
|
105
|
+
if (publicAttributeRefreshTimer) {
|
|
106
|
+
clearTimeout(publicAttributeRefreshTimer);
|
|
107
|
+
publicAttributeRefreshTimer = undefined;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function schedulePublicAttributeRefreshEnable() {
|
|
111
|
+
clearPublicAttributeRefreshTimer();
|
|
112
|
+
publicAttributeRefreshTimer = setTimeout(() => {
|
|
113
|
+
publicAttributeRefreshTimer = undefined;
|
|
114
|
+
router.enablePublicAttributeRefresh();
|
|
115
|
+
}, publicAttributeRefreshStartupDelayMs());
|
|
116
|
+
}
|
|
94
117
|
async function cleanupStartupFailure() {
|
|
118
|
+
clearPublicAttributeRefreshTimer();
|
|
95
119
|
try {
|
|
96
120
|
unsubscribeInbound?.();
|
|
97
121
|
}
|
|
@@ -149,6 +173,7 @@ export function registerLibp2pMeshWithDeps(api, deps = {}) {
|
|
|
149
173
|
api.logger.info?.(`[libp2p-mesh] Active relay reservations: ${nat.reservedRelays.join(", ")}`);
|
|
150
174
|
}
|
|
151
175
|
serviceStarted = true;
|
|
176
|
+
schedulePublicAttributeRefreshEnable();
|
|
152
177
|
}
|
|
153
178
|
catch (error) {
|
|
154
179
|
await cleanupStartupFailure();
|
|
@@ -162,6 +187,7 @@ export function registerLibp2pMeshWithDeps(api, deps = {}) {
|
|
|
162
187
|
},
|
|
163
188
|
stop: async () => {
|
|
164
189
|
await startPromise?.catch(() => undefined);
|
|
190
|
+
clearPublicAttributeRefreshTimer();
|
|
165
191
|
unsubscribeInbound?.();
|
|
166
192
|
unsubscribeInbound = undefined;
|
|
167
193
|
await router.stop();
|
|
@@ -40,7 +40,7 @@ export const LIBP2P_MESH_AGENT_PROMPT = `
|
|
|
40
40
|
|
|
41
41
|
- \`source="USER.md"\` 表示 gateway 使用 OpenClaw 已配置的 agent/API 模型,从 USER.md 异步提取并公开广播的 tag。
|
|
42
42
|
- \`source="profile"\` 表示用户通过 \`openclaw libp2p-mesh profile\` 手动配置的公开结构化属性。
|
|
43
|
-
- gateway 的基础 \`instance-announce\` 可能省略 \`userPublicAttributes\`;这表示本次 announce
|
|
43
|
+
- gateway 的基础 \`instance-announce\` 可能省略 \`userPublicAttributes\`;这表示本次 announce 没有携带属性,不一定表示该用户没有公开属性。启动后 USER.md 属性刷新可能会延迟数秒完成。按公开属性发送前先用 \`p2p_list_instances\` 查看当前实例记录。
|
|
44
44
|
- 普通对话 agent 不应自己读取 USER.md 来决定公开属性。USER.md 属性提取是 gateway 后台职责。
|
|
45
45
|
|
|
46
46
|
3. \`openclaw libp2p-mesh labels\` manages local labels for remote instances. These labels are stored in the local \`peer-labels.json\`, stay on this machine, and are used only when the send tool uses \`scope="local"\` or \`scope="all"\`.
|
package/dist/src/types.d.ts
CHANGED
|
@@ -216,6 +216,7 @@ export type InstanceRouterOptions = {
|
|
|
216
216
|
peerLabelStore?: {
|
|
217
217
|
listLabels(instanceId: string): Promise<LocalPeerLabelAttribute[]>;
|
|
218
218
|
};
|
|
219
|
+
publicAttributeRefreshInitiallyEnabled?: boolean;
|
|
219
220
|
};
|
|
220
221
|
export interface InstanceRouter {
|
|
221
222
|
attachHandlers(): void;
|
|
@@ -224,6 +225,7 @@ export interface InstanceRouter {
|
|
|
224
225
|
stop(): Promise<void>;
|
|
225
226
|
handleMessage(msg: P2PMessage): Promise<void>;
|
|
226
227
|
announceToPeer(peerId: string): Promise<void>;
|
|
228
|
+
enablePublicAttributeRefresh(): void;
|
|
227
229
|
refreshPublicAttributes(): Promise<void>;
|
|
228
230
|
listInstances(): Promise<InstancePeerRecord[]>;
|
|
229
231
|
resolveInstance(instanceId: string): Promise<InstancePeerRecord | undefined>;
|
|
@@ -246,6 +248,7 @@ export interface MeshConfig {
|
|
|
246
248
|
bootstrapList?: string[];
|
|
247
249
|
meshTopic?: string;
|
|
248
250
|
announceLogDetail?: AnnounceLogDetail;
|
|
251
|
+
publicAttributeRefreshStartupDelayMs?: number;
|
|
249
252
|
enableAgentSync?: boolean;
|
|
250
253
|
enableWebSocket?: boolean;
|
|
251
254
|
peerIdPath?: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import { validateExtractedUserMdTags } from "./user-md-agent-attributes.js";
|
|
3
3
|
const EXTRACTION_TIMEOUT_MS = 30000;
|
|
4
4
|
const SESSION_HASH_LENGTH = 16;
|
|
@@ -100,7 +100,7 @@ export function createOpenClawUserMdAttributeExtractor(api, options) {
|
|
|
100
100
|
if (!subagent?.run || !subagent.waitForRun || !subagent.getSessionMessages) {
|
|
101
101
|
return unavailable("OpenClaw subagent runtime is unavailable");
|
|
102
102
|
}
|
|
103
|
-
const sessionKey = `libp2p-mesh:user-md-attributes:${hashForSessionKey(sourcePath)}`;
|
|
103
|
+
const sessionKey = `libp2p-mesh:user-md-attributes:${hashForSessionKey(sourcePath)}:${randomUUID()}`;
|
|
104
104
|
try {
|
|
105
105
|
await subagent.deleteSession?.({ sessionKey, deleteTranscript: true }).catch(() => undefined);
|
|
106
106
|
const { runId } = await subagent.run({
|
package/package.json
CHANGED
package/src/instance-router.ts
CHANGED
|
@@ -218,6 +218,7 @@ export function createInstanceRouter(options: InstanceRouterOptions): InstanceRo
|
|
|
218
218
|
const deliveryCache = new Map<string, DeliveryCacheEntry>();
|
|
219
219
|
const unsubs: Array<() => void> = [];
|
|
220
220
|
const pendingAttributePeers = new Set<string>();
|
|
221
|
+
let publicAttributeRefreshEnabled = options.publicAttributeRefreshInitiallyEnabled !== false;
|
|
221
222
|
let attributeRefreshPromise: Promise<void> | undefined;
|
|
222
223
|
|
|
223
224
|
function localInstanceId(): string {
|
|
@@ -335,7 +336,9 @@ export function createInstanceRouter(options: InstanceRouterOptions): InstanceRo
|
|
|
335
336
|
return;
|
|
336
337
|
}
|
|
337
338
|
|
|
338
|
-
|
|
339
|
+
if (publicAttributeRefreshEnabled) {
|
|
340
|
+
drainAttributeRefresh();
|
|
341
|
+
}
|
|
339
342
|
}
|
|
340
343
|
|
|
341
344
|
function drainAttributeRefresh(): Promise<void> {
|
|
@@ -358,6 +361,13 @@ export function createInstanceRouter(options: InstanceRouterOptions): InstanceRo
|
|
|
358
361
|
return attributeRefreshPromise;
|
|
359
362
|
}
|
|
360
363
|
|
|
364
|
+
function enablePublicAttributeRefresh(): void {
|
|
365
|
+
publicAttributeRefreshEnabled = true;
|
|
366
|
+
if (pendingAttributePeers.size > 0) {
|
|
367
|
+
drainAttributeRefresh();
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
361
371
|
async function announceToPeer(peerId: string): Promise<void> {
|
|
362
372
|
if (!isNonEmptyString(peerId) || peerId === mesh.getLocalPeerId()) {
|
|
363
373
|
return;
|
|
@@ -896,6 +906,7 @@ export function createInstanceRouter(options: InstanceRouterOptions): InstanceRo
|
|
|
896
906
|
stop,
|
|
897
907
|
handleMessage,
|
|
898
908
|
announceToPeer,
|
|
909
|
+
enablePublicAttributeRefresh,
|
|
899
910
|
refreshPublicAttributes,
|
|
900
911
|
listInstances,
|
|
901
912
|
resolveInstance,
|
package/src/plugin.ts
CHANGED
|
@@ -14,6 +14,8 @@ import { registerLibp2pMeshCli } from "./profile-cli.js";
|
|
|
14
14
|
import type { ChannelPlugin } from "openclaw/plugin-sdk/core";
|
|
15
15
|
import type { MeshConfig } from "./types.js";
|
|
16
16
|
|
|
17
|
+
const DEFAULT_PUBLIC_ATTRIBUTE_REFRESH_STARTUP_DELAY_MS = 10000;
|
|
18
|
+
|
|
17
19
|
export type Libp2pMeshPluginDeps = {
|
|
18
20
|
createMeshNetwork?: typeof createMeshNetwork;
|
|
19
21
|
createInstanceRouter?: typeof createInstanceRouter;
|
|
@@ -31,6 +33,7 @@ export function registerLibp2pMeshWithDeps(
|
|
|
31
33
|
let unsubscribeInbound: (() => void) | undefined;
|
|
32
34
|
let serviceStarted = false;
|
|
33
35
|
let startPromise: Promise<void> | undefined;
|
|
36
|
+
let publicAttributeRefreshTimer: ReturnType<typeof setTimeout> | undefined;
|
|
34
37
|
const mesh = (deps.createMeshNetwork ?? createMeshNetwork)({
|
|
35
38
|
config,
|
|
36
39
|
logger: api.logger,
|
|
@@ -65,6 +68,7 @@ export function registerLibp2pMeshWithDeps(
|
|
|
65
68
|
userAttributeSource,
|
|
66
69
|
userProfileStore,
|
|
67
70
|
peerLabelStore,
|
|
71
|
+
publicAttributeRefreshInitiallyEnabled: false,
|
|
68
72
|
});
|
|
69
73
|
|
|
70
74
|
registerLibp2pMeshCli(api, {
|
|
@@ -114,7 +118,31 @@ export function registerLibp2pMeshWithDeps(
|
|
|
114
118
|
});
|
|
115
119
|
}
|
|
116
120
|
|
|
121
|
+
function publicAttributeRefreshStartupDelayMs(): number {
|
|
122
|
+
const configured = config?.publicAttributeRefreshStartupDelayMs;
|
|
123
|
+
if (typeof configured === "number" && Number.isFinite(configured) && configured >= 0) {
|
|
124
|
+
return configured;
|
|
125
|
+
}
|
|
126
|
+
return DEFAULT_PUBLIC_ATTRIBUTE_REFRESH_STARTUP_DELAY_MS;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function clearPublicAttributeRefreshTimer(): void {
|
|
130
|
+
if (publicAttributeRefreshTimer) {
|
|
131
|
+
clearTimeout(publicAttributeRefreshTimer);
|
|
132
|
+
publicAttributeRefreshTimer = undefined;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function schedulePublicAttributeRefreshEnable(): void {
|
|
137
|
+
clearPublicAttributeRefreshTimer();
|
|
138
|
+
publicAttributeRefreshTimer = setTimeout(() => {
|
|
139
|
+
publicAttributeRefreshTimer = undefined;
|
|
140
|
+
router.enablePublicAttributeRefresh();
|
|
141
|
+
}, publicAttributeRefreshStartupDelayMs());
|
|
142
|
+
}
|
|
143
|
+
|
|
117
144
|
async function cleanupStartupFailure(): Promise<void> {
|
|
145
|
+
clearPublicAttributeRefreshTimer();
|
|
118
146
|
try {
|
|
119
147
|
unsubscribeInbound?.();
|
|
120
148
|
} catch (error) {
|
|
@@ -186,6 +214,7 @@ export function registerLibp2pMeshWithDeps(
|
|
|
186
214
|
);
|
|
187
215
|
}
|
|
188
216
|
serviceStarted = true;
|
|
217
|
+
schedulePublicAttributeRefreshEnable();
|
|
189
218
|
} catch (error) {
|
|
190
219
|
await cleanupStartupFailure();
|
|
191
220
|
throw error;
|
|
@@ -198,6 +227,7 @@ export function registerLibp2pMeshWithDeps(
|
|
|
198
227
|
},
|
|
199
228
|
stop: async () => {
|
|
200
229
|
await startPromise?.catch(() => undefined);
|
|
230
|
+
clearPublicAttributeRefreshTimer();
|
|
201
231
|
unsubscribeInbound?.();
|
|
202
232
|
unsubscribeInbound = undefined;
|
|
203
233
|
await router.stop();
|
package/src/prompt-config.ts
CHANGED
|
@@ -42,7 +42,7 @@ export const LIBP2P_MESH_AGENT_PROMPT = `
|
|
|
42
42
|
|
|
43
43
|
- \`source="USER.md"\` 表示 gateway 使用 OpenClaw 已配置的 agent/API 模型,从 USER.md 异步提取并公开广播的 tag。
|
|
44
44
|
- \`source="profile"\` 表示用户通过 \`openclaw libp2p-mesh profile\` 手动配置的公开结构化属性。
|
|
45
|
-
- gateway 的基础 \`instance-announce\` 可能省略 \`userPublicAttributes\`;这表示本次 announce
|
|
45
|
+
- gateway 的基础 \`instance-announce\` 可能省略 \`userPublicAttributes\`;这表示本次 announce 没有携带属性,不一定表示该用户没有公开属性。启动后 USER.md 属性刷新可能会延迟数秒完成。按公开属性发送前先用 \`p2p_list_instances\` 查看当前实例记录。
|
|
46
46
|
- 普通对话 agent 不应自己读取 USER.md 来决定公开属性。USER.md 属性提取是 gateway 后台职责。
|
|
47
47
|
|
|
48
48
|
3. \`openclaw libp2p-mesh labels\` manages local labels for remote instances. These labels are stored in the local \`peer-labels.json\`, stay on this machine, and are used only when the send tool uses \`scope="local"\` or \`scope="all"\`.
|
package/src/types.ts
CHANGED
|
@@ -244,6 +244,7 @@ export type InstanceRouterOptions = {
|
|
|
244
244
|
peerLabelStore?: {
|
|
245
245
|
listLabels(instanceId: string): Promise<LocalPeerLabelAttribute[]>;
|
|
246
246
|
};
|
|
247
|
+
publicAttributeRefreshInitiallyEnabled?: boolean;
|
|
247
248
|
};
|
|
248
249
|
|
|
249
250
|
export interface InstanceRouter {
|
|
@@ -253,6 +254,7 @@ export interface InstanceRouter {
|
|
|
253
254
|
stop(): Promise<void>;
|
|
254
255
|
handleMessage(msg: P2PMessage): Promise<void>;
|
|
255
256
|
announceToPeer(peerId: string): Promise<void>;
|
|
257
|
+
enablePublicAttributeRefresh(): void;
|
|
256
258
|
refreshPublicAttributes(): Promise<void>;
|
|
257
259
|
listInstances(): Promise<InstancePeerRecord[]>;
|
|
258
260
|
resolveInstance(instanceId: string): Promise<InstancePeerRecord | undefined>;
|
|
@@ -280,6 +282,7 @@ export interface MeshConfig {
|
|
|
280
282
|
bootstrapList?: string[];
|
|
281
283
|
meshTopic?: string;
|
|
282
284
|
announceLogDetail?: AnnounceLogDetail;
|
|
285
|
+
publicAttributeRefreshStartupDelayMs?: number;
|
|
283
286
|
enableAgentSync?: boolean;
|
|
284
287
|
enableWebSocket?: boolean;
|
|
285
288
|
peerIdPath?: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import type { OpenClawPluginApi } from "openclaw/plugin-sdk/core";
|
|
3
3
|
import type { UserPublicAttribute } from "./types.js";
|
|
4
4
|
import type {
|
|
@@ -134,7 +134,7 @@ export function createOpenClawUserMdAttributeExtractor(
|
|
|
134
134
|
return unavailable("OpenClaw subagent runtime is unavailable");
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
const sessionKey = `libp2p-mesh:user-md-attributes:${hashForSessionKey(sourcePath)}`;
|
|
137
|
+
const sessionKey = `libp2p-mesh:user-md-attributes:${hashForSessionKey(sourcePath)}:${randomUUID()}`;
|
|
138
138
|
|
|
139
139
|
try {
|
|
140
140
|
await subagent.deleteSession?.({ sessionKey, deleteTranscript: true }).catch(() => undefined);
|