libp2p-mesh 2026.5.26 → 2026.5.27
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.
|
@@ -18,6 +18,18 @@ export async function handleIdentityMessage(msg, deps) {
|
|
|
18
18
|
// Malformed payload — skip silently
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
|
+
// sendToPeer 包装了一层 direct 外壳后,payload 里可能嵌套了 identity 消息:
|
|
22
|
+
// outer: {"type":"identity","from":"A","payload":"{\"agentId\":\"A\",\"channel\":\"feishu\",...}"}
|
|
23
|
+
// 先解析拿到外层,再检测 type 并递归解析内层 payload。
|
|
24
|
+
if (parsed.type === "identity" && typeof parsed.payload === "string") {
|
|
25
|
+
try {
|
|
26
|
+
parsed = JSON.parse(parsed.payload);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// Inner payload malformed — skip silently
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
21
33
|
const { agentId, channel, accountId, instanceId } = parsed;
|
|
22
34
|
// Only register if all required fields are present
|
|
23
35
|
if (agentId && channel && accountId) {
|
package/package.json
CHANGED
package/src/identity-exchange.ts
CHANGED
|
@@ -40,7 +40,7 @@ export async function handleIdentityMessage(
|
|
|
40
40
|
const logger = deps.logger;
|
|
41
41
|
|
|
42
42
|
// Parse remote identity payload
|
|
43
|
-
let parsed:
|
|
43
|
+
let parsed: Record<string, unknown> = {};
|
|
44
44
|
try {
|
|
45
45
|
parsed = JSON.parse(msg.payload);
|
|
46
46
|
} catch {
|
|
@@ -48,7 +48,24 @@ export async function handleIdentityMessage(
|
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
// sendToPeer 包装了一层 direct 外壳后,payload 里可能嵌套了 identity 消息:
|
|
52
|
+
// outer: {"type":"identity","from":"A","payload":"{\"agentId\":\"A\",\"channel\":\"feishu\",...}"}
|
|
53
|
+
// 先解析拿到外层,再检测 type 并递归解析内层 payload。
|
|
54
|
+
if (parsed.type === "identity" && typeof parsed.payload === "string") {
|
|
55
|
+
try {
|
|
56
|
+
parsed = JSON.parse(parsed.payload);
|
|
57
|
+
} catch {
|
|
58
|
+
// Inner payload malformed — skip silently
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const { agentId, channel, accountId, instanceId } = parsed as {
|
|
64
|
+
agentId?: string;
|
|
65
|
+
channel?: string;
|
|
66
|
+
accountId?: string;
|
|
67
|
+
instanceId?: string;
|
|
68
|
+
};
|
|
52
69
|
|
|
53
70
|
// Only register if all required fields are present
|
|
54
71
|
if (agentId && channel && accountId) {
|