agent-comms 2.20.1 → 2.21.0
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +1 -1
- package/dist/core/agent-registry.d.ts +38 -0
- package/dist/core/agent-registry.d.ts.map +1 -0
- package/dist/core/agent-registry.js +117 -0
- package/dist/core/agent-registry.js.map +1 -0
- package/dist/core/connection-approval.d.ts +48 -0
- package/dist/core/connection-approval.d.ts.map +1 -0
- package/dist/core/connection-approval.js +89 -0
- package/dist/core/connection-approval.js.map +1 -0
- package/dist/core/delivery-engine.d.ts +82 -0
- package/dist/core/delivery-engine.d.ts.map +1 -0
- package/dist/core/delivery-engine.js +464 -0
- package/dist/core/delivery-engine.js.map +1 -0
- package/dist/core/federation-bridge.d.ts +32 -0
- package/dist/core/federation-bridge.d.ts.map +1 -0
- package/dist/core/federation-bridge.js +113 -0
- package/dist/core/federation-bridge.js.map +1 -0
- package/dist/core/mesh-store-shared.d.ts +39 -0
- package/dist/core/mesh-store-shared.d.ts.map +1 -0
- package/dist/core/mesh-store-shared.js +32 -0
- package/dist/core/mesh-store-shared.js.map +1 -0
- package/dist/core/mesh-store.d.ts +65 -256
- package/dist/core/mesh-store.d.ts.map +1 -1
- package/dist/core/mesh-store.js +211 -1917
- package/dist/core/mesh-store.js.map +1 -1
- package/dist/core/peer-lifecycle.d.ts +36 -0
- package/dist/core/peer-lifecycle.d.ts.map +1 -0
- package/dist/core/peer-lifecycle.js +85 -0
- package/dist/core/peer-lifecycle.js.map +1 -0
- package/dist/core/room-lifecycle.d.ts +82 -0
- package/dist/core/room-lifecycle.d.ts.map +1 -0
- package/dist/core/room-lifecycle.js +459 -0
- package/dist/core/room-lifecycle.js.map +1 -0
- package/dist/core/room-messaging.d.ts +31 -0
- package/dist/core/room-messaging.d.ts.map +1 -0
- package/dist/core/room-messaging.js +120 -0
- package/dist/core/room-messaging.js.map +1 -0
- package/dist/core/room-protocol.d.ts +85 -0
- package/dist/core/room-protocol.d.ts.map +1 -0
- package/dist/core/room-protocol.js +479 -0
- package/dist/core/room-protocol.js.map +1 -0
- package/dist/core/room-wire-extensions.d.ts +36 -0
- package/dist/core/room-wire-extensions.d.ts.map +1 -0
- package/dist/core/room-wire-extensions.js +52 -0
- package/dist/core/room-wire-extensions.js.map +1 -0
- package/dist/core/stale-agent-checker.d.ts +28 -0
- package/dist/core/stale-agent-checker.d.ts.map +1 -0
- package/dist/core/stale-agent-checker.js +77 -0
- package/dist/core/stale-agent-checker.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StaleAgentChecker — coordinator-only periodic liveness probe over every registered agent's own PID, marking a dead process's agent offline and, separately, purging agent records that have sat offline past a fixed threshold. Split out of MeshStore purely to keep mesh-store.ts under the repo's max-lines cap; owns its own probe-interval timer exclusively (nothing outside this class ever reads or writes it).
|
|
3
|
+
*/
|
|
4
|
+
import type { AgentIdentity, AgentStatus, DeliveryEvent } from "./types.js";
|
|
5
|
+
import type { MeshStatePatch, PeerInfo } from "./wire-protocol.js";
|
|
6
|
+
/** The state and collaborators StaleAgentChecker needs from MeshStore -- the core agent/delivery/peer/identity Maps it reads and mutates directly (shared references into MeshStore's own fields), plus the two DeliveryEngine operations a status change and an offline patch need to broadcast. */
|
|
7
|
+
export interface StaleAgentCheckerDeps {
|
|
8
|
+
agents: Map<string, AgentIdentity>;
|
|
9
|
+
deliveryQueues: Map<string, DeliveryEvent[]>;
|
|
10
|
+
identityCache: Map<string, {
|
|
11
|
+
id: string;
|
|
12
|
+
}>;
|
|
13
|
+
peerInfo: Map<string, PeerInfo>;
|
|
14
|
+
notifyRoomsOfStatus: (agentId: string, status: AgentStatus) => Promise<void>;
|
|
15
|
+
broadcastPatch: (patch: MeshStatePatch) => Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export declare class StaleAgentChecker {
|
|
18
|
+
private readonly deps;
|
|
19
|
+
private timer;
|
|
20
|
+
constructor(deps: StaleAgentCheckerDeps);
|
|
21
|
+
/** Starts the periodic probe (coordinator-only). No-op if already running. */
|
|
22
|
+
start(): void;
|
|
23
|
+
/** Stops the periodic probe, if running. */
|
|
24
|
+
stop(): void;
|
|
25
|
+
private probeStaleAgents;
|
|
26
|
+
private isProcessAlive;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=stale-agent-checker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stale-agent-checker.d.ts","sourceRoot":"","sources":["../../src/core/stale-agent-checker.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC5E,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnE,qSAAqS;AACrS,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACnC,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;IAC7C,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC3C,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAChC,mBAAmB,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7E,cAAc,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1D;AAQD,qBAAa,iBAAiB;IAGhB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,OAAO,CAAC,KAAK,CAA6C;gBAE7B,IAAI,EAAE,qBAAqB;IAExD,8EAA8E;IAC9E,KAAK,IAAI,IAAI;IAOb,4CAA4C;IAC5C,IAAI,IAAI,IAAI;YAOE,gBAAgB;IA+C9B,OAAO,CAAC,cAAc;CAQvB"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StaleAgentChecker — coordinator-only periodic liveness probe over every registered agent's own PID, marking a dead process's agent offline and, separately, purging agent records that have sat offline past a fixed threshold. Split out of MeshStore purely to keep mesh-store.ts under the repo's max-lines cap; owns its own probe-interval timer exclusively (nothing outside this class ever reads or writes it).
|
|
3
|
+
*/
|
|
4
|
+
/** How often the coordinator probes registered agent PIDs for liveness. */
|
|
5
|
+
const PROBE_INTERVAL_MS = 5000;
|
|
6
|
+
/** How long an agent may sit "offline" before its record is purged entirely, to prevent indefinite accumulation. */
|
|
7
|
+
const OFFLINE_PURGE_THRESHOLD_MS = 30 * 60 * 1000;
|
|
8
|
+
export class StaleAgentChecker {
|
|
9
|
+
deps;
|
|
10
|
+
timer;
|
|
11
|
+
constructor(deps) {
|
|
12
|
+
this.deps = deps;
|
|
13
|
+
}
|
|
14
|
+
/** Starts the periodic probe (coordinator-only). No-op if already running. */
|
|
15
|
+
start() {
|
|
16
|
+
if (this.timer)
|
|
17
|
+
return;
|
|
18
|
+
this.timer = setInterval(() => {
|
|
19
|
+
void this.probeStaleAgents();
|
|
20
|
+
}, PROBE_INTERVAL_MS);
|
|
21
|
+
}
|
|
22
|
+
/** Stops the periodic probe, if running. */
|
|
23
|
+
stop() {
|
|
24
|
+
if (this.timer) {
|
|
25
|
+
clearInterval(this.timer);
|
|
26
|
+
this.timer = undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async probeStaleAgents() {
|
|
30
|
+
const { agents, deliveryQueues, identityCache, peerInfo, notifyRoomsOfStatus, broadcastPatch, } = this.deps;
|
|
31
|
+
const deadIds = [];
|
|
32
|
+
for (const [id, agent] of agents) {
|
|
33
|
+
if (agent.status !== "active")
|
|
34
|
+
continue;
|
|
35
|
+
if (!this.isProcessAlive(agent.pid)) {
|
|
36
|
+
deadIds.push(id);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (const id of deadIds) {
|
|
40
|
+
const agent = agents.get(id);
|
|
41
|
+
if (agent) {
|
|
42
|
+
agent.status = "offline";
|
|
43
|
+
agents.set(id, agent);
|
|
44
|
+
await notifyRoomsOfStatus(id, "offline");
|
|
45
|
+
}
|
|
46
|
+
await broadcastPatch({ type: "agent_offline", agentId: id });
|
|
47
|
+
peerInfo.delete(id);
|
|
48
|
+
}
|
|
49
|
+
// Also purge long-offline agents to prevent indefinite accumulation.
|
|
50
|
+
const offlineThreshold = Date.now() - OFFLINE_PURGE_THRESHOLD_MS;
|
|
51
|
+
const purgeIds = [];
|
|
52
|
+
for (const [id, agent] of agents) {
|
|
53
|
+
if (agent.status !== "offline")
|
|
54
|
+
continue;
|
|
55
|
+
const startedAt = new Date(agent.startedAt).getTime();
|
|
56
|
+
if (startedAt < offlineThreshold) {
|
|
57
|
+
purgeIds.push(id);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
for (const id of purgeIds) {
|
|
61
|
+
agents.delete(id);
|
|
62
|
+
peerInfo.delete(id);
|
|
63
|
+
identityCache.delete(id);
|
|
64
|
+
deliveryQueues.delete(id);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
isProcessAlive(pid) {
|
|
68
|
+
try {
|
|
69
|
+
process.kill(pid, 0);
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=stale-agent-checker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stale-agent-checker.js","sourceRoot":"","sources":["../../src/core/stale-agent-checker.ts"],"names":[],"mappings":"AAAA;;GAEG;AAeH,2EAA2E;AAC3E,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAE/B,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