agent-inbox 0.1.8 → 0.2.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.md +44 -7
- package/README.md +67 -24
- package/dist/cli.d.ts +20 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +89 -0
- package/dist/cli.js.map +1 -0
- package/dist/federation/connection-manager.d.ts +13 -2
- package/dist/federation/connection-manager.d.ts.map +1 -1
- package/dist/federation/connection-manager.js +109 -10
- package/dist/federation/connection-manager.js.map +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +58 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -0
- package/dist/ipc/ipc-server.d.ts +2 -0
- package/dist/ipc/ipc-server.d.ts.map +1 -1
- package/dist/ipc/ipc-server.js +48 -0
- package/dist/ipc/ipc-server.js.map +1 -1
- package/dist/map/map-client.d.ts +100 -0
- package/dist/map/map-client.d.ts.map +1 -1
- package/dist/map/map-client.js +61 -0
- package/dist/map/map-client.js.map +1 -1
- package/dist/mcp/mcp-proxy.d.ts +28 -0
- package/dist/mcp/mcp-proxy.d.ts.map +1 -0
- package/dist/mcp/mcp-proxy.js +280 -0
- package/dist/mcp/mcp-proxy.js.map +1 -0
- package/dist/mesh/delivery-bridge.d.ts +47 -0
- package/dist/mesh/delivery-bridge.d.ts.map +1 -0
- package/dist/mesh/delivery-bridge.js +73 -0
- package/dist/mesh/delivery-bridge.js.map +1 -0
- package/dist/mesh/mesh-connector.d.ts +29 -0
- package/dist/mesh/mesh-connector.d.ts.map +1 -0
- package/dist/mesh/mesh-connector.js +36 -0
- package/dist/mesh/mesh-connector.js.map +1 -0
- package/dist/mesh/mesh-transport.d.ts +70 -0
- package/dist/mesh/mesh-transport.d.ts.map +1 -0
- package/dist/mesh/mesh-transport.js +92 -0
- package/dist/mesh/mesh-transport.js.map +1 -0
- package/dist/mesh/type-mapper.d.ts +67 -0
- package/dist/mesh/type-mapper.d.ts.map +1 -0
- package/dist/mesh/type-mapper.js +165 -0
- package/dist/mesh/type-mapper.js.map +1 -0
- package/dist/types.d.ts +29 -2
- package/dist/types.d.ts.map +1 -1
- package/docs/CLAUDE-CODE-SWARM-PROPOSAL.md +137 -0
- package/package.json +10 -2
- package/src/cli.ts +94 -0
- package/src/federation/connection-manager.ts +125 -10
- package/src/index.ts +96 -5
- package/src/ipc/ipc-server.ts +58 -0
- package/src/map/map-client.ts +152 -0
- package/src/mcp/mcp-proxy.ts +326 -0
- package/src/mesh/delivery-bridge.ts +110 -0
- package/src/mesh/mesh-connector.ts +41 -0
- package/src/mesh/mesh-transport.ts +157 -0
- package/src/mesh/type-mapper.ts +239 -0
- package/src/types.ts +33 -1
- package/test/federation/integration.test.ts +37 -3
- package/test/federation/sdk-integration.test.ts +4 -8
- package/test/ipc-new-commands.test.ts +200 -0
- package/test/mcp-proxy.test.ts +191 -0
- package/test/mesh/delivery-bridge.test.ts +178 -0
- package/test/mesh/e2e-mesh.test.ts +527 -0
- package/test/mesh/e2e-real-meshpeer.test.ts +629 -0
- package/test/mesh/federation-mesh.test.ts +269 -0
- package/test/mesh/mesh-connector.test.ts +66 -0
- package/test/mesh/mesh-transport.test.ts +191 -0
- package/test/mesh/meshpeer-integration.test.ts +442 -0
- package/test/mesh/mock-mesh.ts +125 -0
- package/test/mesh/mock-meshpeer.ts +266 -0
- package/test/mesh/type-mapper.test.ts +226 -0
- package/docs/PLAN.md +0 -545
package/dist/map/map-client.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { normalizeContent } from "../router/message-router.js";
|
|
2
2
|
import { ulid } from "ulid";
|
|
3
|
+
import { mapMessageToInbox } from "../mesh/type-mapper.js";
|
|
3
4
|
/**
|
|
4
5
|
* Wrapper around @multi-agent-protocol/sdk for Agent Inbox's MAP connection.
|
|
5
6
|
*
|
|
@@ -13,6 +14,9 @@ export class MapClient {
|
|
|
13
14
|
conn = null;
|
|
14
15
|
agentConnectionClass = null;
|
|
15
16
|
externalConn = false;
|
|
17
|
+
meshPeer = null;
|
|
18
|
+
meshAgentConn = null;
|
|
19
|
+
meshMessageHandler = null;
|
|
16
20
|
constructor(storage, router, events) {
|
|
17
21
|
this.storage = storage;
|
|
18
22
|
this.router = router;
|
|
@@ -71,7 +75,55 @@ export class MapClient {
|
|
|
71
75
|
this.handleIncoming(msg);
|
|
72
76
|
});
|
|
73
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Connect to an agentic-mesh MeshPeer as a local agent.
|
|
80
|
+
*
|
|
81
|
+
* Registers agent-inbox as an agent on the MeshPeer's MapServer,
|
|
82
|
+
* receives messages via the MapServer's message handler mechanism.
|
|
83
|
+
* This is the Phase 2 integration path — full MAP protocol over mesh.
|
|
84
|
+
*
|
|
85
|
+
* Returns the MapServer's systemId for federation system ID resolution.
|
|
86
|
+
*/
|
|
87
|
+
async connectViaMesh(meshPeer) {
|
|
88
|
+
this.meshPeer = meshPeer;
|
|
89
|
+
// Register agent-inbox as an agent on the MeshPeer's MapServer
|
|
90
|
+
this.meshAgentConn = await meshPeer.createAgent({
|
|
91
|
+
agentId: "agent-inbox",
|
|
92
|
+
name: "Agent Inbox",
|
|
93
|
+
role: "inbox",
|
|
94
|
+
scopes: ["default"],
|
|
95
|
+
capabilities: { trajectory: { canReport: false } },
|
|
96
|
+
metadata: { type: "agent-inbox" },
|
|
97
|
+
});
|
|
98
|
+
// Set up message handler on the MapServer for this agent
|
|
99
|
+
this.meshMessageHandler = (_agentId, message) => {
|
|
100
|
+
this.handleMeshMessage(message);
|
|
101
|
+
};
|
|
102
|
+
meshPeer.server.setMessageHandler("agent-inbox", this.meshMessageHandler);
|
|
103
|
+
return meshPeer.server.systemId;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get the MeshPeer this client is connected to, if any.
|
|
107
|
+
*/
|
|
108
|
+
getMeshPeer() {
|
|
109
|
+
return this.meshPeer;
|
|
110
|
+
}
|
|
74
111
|
async disconnect() {
|
|
112
|
+
// Disconnect mesh agent connection
|
|
113
|
+
if (this.meshAgentConn) {
|
|
114
|
+
if (this.meshPeer && this.meshMessageHandler) {
|
|
115
|
+
this.meshPeer.server.removeMessageHandler("agent-inbox");
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
await this.meshAgentConn.unregister();
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
// Best-effort
|
|
122
|
+
}
|
|
123
|
+
this.meshAgentConn = null;
|
|
124
|
+
this.meshPeer = null;
|
|
125
|
+
this.meshMessageHandler = null;
|
|
126
|
+
}
|
|
75
127
|
if (this.conn) {
|
|
76
128
|
if (!this.externalConn) {
|
|
77
129
|
await this.conn.disconnect();
|
|
@@ -155,6 +207,15 @@ export class MapClient {
|
|
|
155
207
|
const candidates = this.storage.searchMessages(msg.from);
|
|
156
208
|
return candidates.some((m) => m.sender_id === msg.from && m.created_at === msg.timestamp);
|
|
157
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* Handle an incoming MAP message from the MeshPeer's MapServer.
|
|
212
|
+
* Uses the type-mapper for full MAP Message → Inbox Message translation.
|
|
213
|
+
*/
|
|
214
|
+
handleMeshMessage(msg) {
|
|
215
|
+
const inboxMsg = mapMessageToInbox(msg);
|
|
216
|
+
this.storage.putMessage(inboxMsg);
|
|
217
|
+
this.events.emit("message.created", inboxMsg);
|
|
218
|
+
}
|
|
158
219
|
handleIncoming(msg) {
|
|
159
220
|
const now = new Date().toISOString();
|
|
160
221
|
const content = normalizeContent(msg.payload);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-client.js","sourceRoot":"","sources":["../../src/map/map-client.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file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ating its own storage/router, this connects to a running
|
|
5
|
+
* agent-inbox IPC server (e.g., the sidecar's inbox instance) and translates
|
|
6
|
+
* MCP tool calls into IPC commands.
|
|
7
|
+
*
|
|
8
|
+
* This ensures a single source of truth for messages, agents, and routing.
|
|
9
|
+
*/
|
|
10
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
11
|
+
export declare class InboxMcpProxy {
|
|
12
|
+
private socketPath;
|
|
13
|
+
private defaultAgentId;
|
|
14
|
+
private defaultScope;
|
|
15
|
+
private mcp;
|
|
16
|
+
constructor(socketPath: string, defaultAgentId?: string, defaultScope?: string);
|
|
17
|
+
/**
|
|
18
|
+
* Send an IPC command to the inbox socket and return the response.
|
|
19
|
+
* Retries connection if socket is not yet available.
|
|
20
|
+
*/
|
|
21
|
+
private sendIpc;
|
|
22
|
+
private sendIpcOnce;
|
|
23
|
+
private registerTools;
|
|
24
|
+
start(): Promise<void>;
|
|
25
|
+
/** Expose for testing */
|
|
26
|
+
get server(): McpServer;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=mcp-proxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-proxy.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AASpE,qBAAa,aAAa;IAItB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,YAAY;IALtB,OAAO,CAAC,GAAG,CAAY;gBAGb,UAAU,EAAE,MAAM,EAClB,cAAc,GAAE,MAAoB,EACpC,YAAY,GAAE,MAAkB;IAU1C;;;OAGG;YACW,OAAO;IAsBrB,OAAO,CAAC,WAAW;IA4CnB,OAAO,CAAC,aAAa;IAkNf,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAK5B,yBAAyB;IACzB,IAAI,MAAM,IAAI,SAAS,CAEtB;CACF"}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mcp-proxy.ts — MCP server that proxies all tools to an existing inbox IPC socket.
|
|
3
|
+
*
|
|
4
|
+
* Instead of creating its own storage/router, this connects to a running
|
|
5
|
+
* agent-inbox IPC server (e.g., the sidecar's inbox instance) and translates
|
|
6
|
+
* MCP tool calls into IPC commands.
|
|
7
|
+
*
|
|
8
|
+
* This ensures a single source of truth for messages, agents, and routing.
|
|
9
|
+
*/
|
|
10
|
+
import * as net from "node:net";
|
|
11
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
12
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
const IPC_TIMEOUT_MS = 5000;
|
|
15
|
+
const CONNECT_RETRY_MS = 500;
|
|
16
|
+
const CONNECT_MAX_RETRIES = 10;
|
|
17
|
+
export class InboxMcpProxy {
|
|
18
|
+
socketPath;
|
|
19
|
+
defaultAgentId;
|
|
20
|
+
defaultScope;
|
|
21
|
+
mcp;
|
|
22
|
+
constructor(socketPath, defaultAgentId = "anonymous", defaultScope = "default") {
|
|
23
|
+
this.socketPath = socketPath;
|
|
24
|
+
this.defaultAgentId = defaultAgentId;
|
|
25
|
+
this.defaultScope = defaultScope;
|
|
26
|
+
this.mcp = new McpServer({
|
|
27
|
+
name: "agent-inbox",
|
|
28
|
+
version: "0.1.0",
|
|
29
|
+
});
|
|
30
|
+
this.registerTools();
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Send an IPC command to the inbox socket and return the response.
|
|
34
|
+
* Retries connection if socket is not yet available.
|
|
35
|
+
*/
|
|
36
|
+
async sendIpc(command) {
|
|
37
|
+
let lastError = null;
|
|
38
|
+
for (let attempt = 0; attempt < CONNECT_MAX_RETRIES; attempt++) {
|
|
39
|
+
try {
|
|
40
|
+
return await this.sendIpcOnce(command);
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
44
|
+
// Only retry on connection errors (socket not ready yet)
|
|
45
|
+
if (lastError.message.includes("ENOENT") || lastError.message.includes("ECONNREFUSED")) {
|
|
46
|
+
if (attempt < CONNECT_MAX_RETRIES - 1) {
|
|
47
|
+
await new Promise((r) => setTimeout(r, CONNECT_RETRY_MS));
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return { ok: false, error: `Inbox unavailable: ${lastError?.message ?? "unknown error"}` };
|
|
55
|
+
}
|
|
56
|
+
sendIpcOnce(command) {
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
const client = net.createConnection(this.socketPath);
|
|
59
|
+
let buffer = "";
|
|
60
|
+
let settled = false;
|
|
61
|
+
const timer = setTimeout(() => {
|
|
62
|
+
if (!settled) {
|
|
63
|
+
settled = true;
|
|
64
|
+
client.destroy();
|
|
65
|
+
reject(new Error("IPC timeout"));
|
|
66
|
+
}
|
|
67
|
+
}, IPC_TIMEOUT_MS);
|
|
68
|
+
client.on("connect", () => {
|
|
69
|
+
client.write(JSON.stringify(command) + "\n");
|
|
70
|
+
});
|
|
71
|
+
client.on("data", (data) => {
|
|
72
|
+
buffer += data.toString();
|
|
73
|
+
const newlineIdx = buffer.indexOf("\n");
|
|
74
|
+
if (newlineIdx !== -1) {
|
|
75
|
+
clearTimeout(timer);
|
|
76
|
+
settled = true;
|
|
77
|
+
const line = buffer.slice(0, newlineIdx).trim();
|
|
78
|
+
client.destroy();
|
|
79
|
+
try {
|
|
80
|
+
resolve(JSON.parse(line));
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
reject(new Error("Invalid IPC response"));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
client.on("error", (err) => {
|
|
88
|
+
if (!settled) {
|
|
89
|
+
clearTimeout(timer);
|
|
90
|
+
settled = true;
|
|
91
|
+
reject(err);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
registerTools() {
|
|
97
|
+
this.mcp.tool("send_message", "Send a message to one or more agents. Supports replies (inReplyTo), threading (threadTag), and federated addressing (agent@system).", {
|
|
98
|
+
to: z
|
|
99
|
+
.union([z.string(), z.array(z.string())])
|
|
100
|
+
.describe("Recipient agent ID(s). Use 'agent@system' for federated addressing."),
|
|
101
|
+
body: z
|
|
102
|
+
.string()
|
|
103
|
+
.optional()
|
|
104
|
+
.describe("Plain text message body (shorthand for content)"),
|
|
105
|
+
content: z
|
|
106
|
+
.object({ type: z.string() })
|
|
107
|
+
.passthrough()
|
|
108
|
+
.optional()
|
|
109
|
+
.describe("Structured message content"),
|
|
110
|
+
from: z
|
|
111
|
+
.string()
|
|
112
|
+
.optional()
|
|
113
|
+
.describe("Sender agent ID (defaults to caller)"),
|
|
114
|
+
threadTag: z
|
|
115
|
+
.string()
|
|
116
|
+
.optional()
|
|
117
|
+
.describe("Thread tag for grouping related messages"),
|
|
118
|
+
inReplyTo: z
|
|
119
|
+
.string()
|
|
120
|
+
.optional()
|
|
121
|
+
.describe("Message ID this is a reply to"),
|
|
122
|
+
importance: z
|
|
123
|
+
.enum(["low", "normal", "high", "urgent"])
|
|
124
|
+
.optional()
|
|
125
|
+
.describe("Message importance level"),
|
|
126
|
+
subject: z.string().optional().describe("Message subject"),
|
|
127
|
+
}, async ({ to, body, content, from, threadTag, inReplyTo, importance, subject }) => {
|
|
128
|
+
const payload = content ?? body ?? "";
|
|
129
|
+
const senderId = from ?? this.defaultAgentId;
|
|
130
|
+
const resp = await this.sendIpc({
|
|
131
|
+
action: "send",
|
|
132
|
+
from: senderId,
|
|
133
|
+
to,
|
|
134
|
+
payload,
|
|
135
|
+
threadTag,
|
|
136
|
+
inReplyTo,
|
|
137
|
+
importance,
|
|
138
|
+
subject,
|
|
139
|
+
});
|
|
140
|
+
return {
|
|
141
|
+
content: [
|
|
142
|
+
{
|
|
143
|
+
type: "text",
|
|
144
|
+
text: JSON.stringify(resp.ok
|
|
145
|
+
? { ok: true, messageId: resp.messageId }
|
|
146
|
+
: { ok: false, error: resp.error }),
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
this.mcp.tool("check_inbox", "Check inbox for messages addressed to an agent. Auto-registers the agent if not already registered.", {
|
|
152
|
+
agentId: z.string().describe("Agent ID to check inbox for"),
|
|
153
|
+
unreadOnly: z
|
|
154
|
+
.boolean()
|
|
155
|
+
.optional()
|
|
156
|
+
.describe("Only return unread messages (default true)"),
|
|
157
|
+
limit: z
|
|
158
|
+
.number()
|
|
159
|
+
.optional()
|
|
160
|
+
.describe("Max messages to return"),
|
|
161
|
+
}, async ({ agentId, unreadOnly, limit }) => {
|
|
162
|
+
const resp = await this.sendIpc({
|
|
163
|
+
action: "check_inbox",
|
|
164
|
+
agentId,
|
|
165
|
+
unreadOnly: unreadOnly ?? true,
|
|
166
|
+
clear: true, // Mark as read after retrieval
|
|
167
|
+
});
|
|
168
|
+
if (!resp.ok) {
|
|
169
|
+
return {
|
|
170
|
+
content: [
|
|
171
|
+
{ type: "text", text: JSON.stringify({ ok: false, error: resp.error }) },
|
|
172
|
+
],
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
let messages = resp.messages ?? [];
|
|
176
|
+
if (limit && messages.length > limit) {
|
|
177
|
+
messages = messages.slice(0, limit);
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
content: [
|
|
181
|
+
{
|
|
182
|
+
type: "text",
|
|
183
|
+
text: JSON.stringify({
|
|
184
|
+
count: messages.length,
|
|
185
|
+
messages: messages.map((m) => ({
|
|
186
|
+
id: m.id,
|
|
187
|
+
from: m.sender_id,
|
|
188
|
+
subject: m.subject,
|
|
189
|
+
content: m.content,
|
|
190
|
+
threadTag: m.thread_tag,
|
|
191
|
+
importance: m.importance,
|
|
192
|
+
createdAt: m.created_at,
|
|
193
|
+
inReplyTo: m.in_reply_to,
|
|
194
|
+
})),
|
|
195
|
+
}),
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
};
|
|
199
|
+
});
|
|
200
|
+
this.mcp.tool("read_thread", "Read all messages in a thread (by thread_tag)", {
|
|
201
|
+
threadTag: z.string().describe("Thread tag to read"),
|
|
202
|
+
scope: z
|
|
203
|
+
.string()
|
|
204
|
+
.optional()
|
|
205
|
+
.describe("Scope (defaults to 'default')"),
|
|
206
|
+
}, async ({ threadTag, scope }) => {
|
|
207
|
+
const resp = await this.sendIpc({
|
|
208
|
+
action: "read_thread",
|
|
209
|
+
threadTag,
|
|
210
|
+
scope: scope ?? this.defaultScope,
|
|
211
|
+
});
|
|
212
|
+
if (!resp.ok) {
|
|
213
|
+
return {
|
|
214
|
+
content: [
|
|
215
|
+
{ type: "text", text: JSON.stringify({ ok: false, error: resp.error }) },
|
|
216
|
+
],
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
const messages = resp.messages ?? [];
|
|
220
|
+
return {
|
|
221
|
+
content: [
|
|
222
|
+
{
|
|
223
|
+
type: "text",
|
|
224
|
+
text: JSON.stringify({
|
|
225
|
+
threadTag,
|
|
226
|
+
count: messages.length,
|
|
227
|
+
messages: messages.map((m) => ({
|
|
228
|
+
id: m.id,
|
|
229
|
+
from: m.sender_id,
|
|
230
|
+
content: m.content,
|
|
231
|
+
createdAt: m.created_at,
|
|
232
|
+
inReplyTo: m.in_reply_to,
|
|
233
|
+
})),
|
|
234
|
+
}),
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
};
|
|
238
|
+
});
|
|
239
|
+
this.mcp.tool("list_agents", "List agents registered in the inbox (local and optionally federated)", {
|
|
240
|
+
scope: z.string().optional().describe("Filter by scope"),
|
|
241
|
+
includeFederated: z
|
|
242
|
+
.boolean()
|
|
243
|
+
.optional()
|
|
244
|
+
.describe("Include agents known from federation routing table"),
|
|
245
|
+
}, async ({ scope, includeFederated }) => {
|
|
246
|
+
const resp = await this.sendIpc({
|
|
247
|
+
action: "list_agents",
|
|
248
|
+
scope,
|
|
249
|
+
includeFederated,
|
|
250
|
+
});
|
|
251
|
+
if (!resp.ok) {
|
|
252
|
+
return {
|
|
253
|
+
content: [
|
|
254
|
+
{ type: "text", text: JSON.stringify({ ok: false, error: resp.error }) },
|
|
255
|
+
],
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
return {
|
|
259
|
+
content: [
|
|
260
|
+
{
|
|
261
|
+
type: "text",
|
|
262
|
+
text: JSON.stringify({
|
|
263
|
+
count: resp.count ?? resp.agents?.length ?? 0,
|
|
264
|
+
agents: resp.agents ?? [],
|
|
265
|
+
}),
|
|
266
|
+
},
|
|
267
|
+
],
|
|
268
|
+
};
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
async start() {
|
|
272
|
+
const transport = new StdioServerTransport();
|
|
273
|
+
await this.mcp.connect(transport);
|
|
274
|
+
}
|
|
275
|
+
/** Expose for testing */
|
|
276
|
+
get server() {
|
|
277
|
+
return this.mcp;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
//# sourceMappingURL=mcp-proxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-proxy.js","sourceRoot":"","sources":["../../src/mcp/mcp-proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B,MAAM,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,MAAM,EAAE,MAAM,IAAI,CAAC;4BAC7C,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,EAAE;yBAC1B,CAAC;qBACH;iBACF;aACF,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;QAC7C,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;IAED,yBAAyB;IACzB,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;CACF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DeliveryHandler bridge: connects agentic-mesh's MapServer message routing
|
|
3
|
+
* to agent-inbox's storage layer.
|
|
4
|
+
*
|
|
5
|
+
* When MapServer's MessageRouter resolves a message to a local agent,
|
|
6
|
+
* it calls `deliverToAgent()`. This bridge translates the MAP Message
|
|
7
|
+
* into an agent-inbox Message and stores it, triggering the full inbox
|
|
8
|
+
* pipeline (traceability, push notifications, etc.).
|
|
9
|
+
*
|
|
10
|
+
* For `forwardToPeer()` and `routeToFederation()`, we delegate back to
|
|
11
|
+
* the previous (default) handler so MeshPeer's own transport handles it.
|
|
12
|
+
*/
|
|
13
|
+
import { EventEmitter } from "node:events";
|
|
14
|
+
import type { Storage } from "../storage/interface.js";
|
|
15
|
+
import type { MapMessage } from "./type-mapper.js";
|
|
16
|
+
/**
|
|
17
|
+
* Subset of agentic-mesh's DeliveryHandler interface.
|
|
18
|
+
* We define it here to avoid importing the full package at compile time.
|
|
19
|
+
*/
|
|
20
|
+
export interface MeshDeliveryHandler {
|
|
21
|
+
deliverToAgent(agentId: string, message: MapMessage): Promise<boolean>;
|
|
22
|
+
forwardToPeer(peerId: string, agentIds: string[], message: MapMessage): Promise<boolean>;
|
|
23
|
+
routeToFederation?(systemId: string, agentIds: string[], message: MapMessage): Promise<boolean>;
|
|
24
|
+
}
|
|
25
|
+
export declare class DeliveryBridge implements MeshDeliveryHandler {
|
|
26
|
+
private storage;
|
|
27
|
+
private events;
|
|
28
|
+
private scope;
|
|
29
|
+
private previousHandler?;
|
|
30
|
+
constructor(storage: Storage, events: EventEmitter, scope?: string, previousHandler?: MeshDeliveryHandler | undefined);
|
|
31
|
+
/**
|
|
32
|
+
* Called by MapServer's MessageRouter when a message is resolved
|
|
33
|
+
* to a local agent. Translates and stores in agent-inbox.
|
|
34
|
+
*/
|
|
35
|
+
deliverToAgent(agentId: string, message: MapMessage): Promise<boolean>;
|
|
36
|
+
/**
|
|
37
|
+
* Forward to a connected peer. Delegates to the previous handler
|
|
38
|
+
* (MeshPeer's default transport handles actual peer forwarding).
|
|
39
|
+
*/
|
|
40
|
+
forwardToPeer(peerId: string, agentIds: string[], message: MapMessage): Promise<boolean>;
|
|
41
|
+
/**
|
|
42
|
+
* Route to a federated system. Delegates to the previous handler
|
|
43
|
+
* (FederationGateway handles cross-mesh routing).
|
|
44
|
+
*/
|
|
45
|
+
routeToFederation(systemId: string, agentIds: string[], message: MapMessage): Promise<boolean>;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=delivery-bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delivery-bridge.d.ts","sourceRoot":"","sources":["../../src/mesh/delivery-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAMnD;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACvE,aAAa,CACX,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAAE,EAClB,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,OAAO,CAAC,CAAC;IACpB,iBAAiB,CAAC,CAChB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAAE,EAClB,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,OAAO,CAAC,CAAC;CACrB;AAMD,qBAAa,cAAe,YAAW,mBAAmB;IAEtD,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,eAAe,CAAC;gBAHhB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,YAAY,EACpB,KAAK,GAAE,MAAkB,EACzB,eAAe,CAAC,EAAE,mBAAmB,YAAA;IAG/C;;;OAGG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;IAwB5E;;;OAGG;IACG,aAAa,CACjB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAAE,EAClB,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,OAAO,CAAC;IAOnB;;;OAGG;IACG,iBAAiB,CACrB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAAE,EAClB,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,OAAO,CAAC;CAMpB"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DeliveryHandler bridge: connects agentic-mesh's MapServer message routing
|
|
3
|
+
* to agent-inbox's storage layer.
|
|
4
|
+
*
|
|
5
|
+
* When MapServer's MessageRouter resolves a message to a local agent,
|
|
6
|
+
* it calls `deliverToAgent()`. This bridge translates the MAP Message
|
|
7
|
+
* into an agent-inbox Message and stores it, triggering the full inbox
|
|
8
|
+
* pipeline (traceability, push notifications, etc.).
|
|
9
|
+
*
|
|
10
|
+
* For `forwardToPeer()` and `routeToFederation()`, we delegate back to
|
|
11
|
+
* the previous (default) handler so MeshPeer's own transport handles it.
|
|
12
|
+
*/
|
|
13
|
+
import { mapMessageToInbox } from "./type-mapper.js";
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// DeliveryBridge
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
export class DeliveryBridge {
|
|
18
|
+
storage;
|
|
19
|
+
events;
|
|
20
|
+
scope;
|
|
21
|
+
previousHandler;
|
|
22
|
+
constructor(storage, events, scope = "default", previousHandler) {
|
|
23
|
+
this.storage = storage;
|
|
24
|
+
this.events = events;
|
|
25
|
+
this.scope = scope;
|
|
26
|
+
this.previousHandler = previousHandler;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Called by MapServer's MessageRouter when a message is resolved
|
|
30
|
+
* to a local agent. Translates and stores in agent-inbox.
|
|
31
|
+
*/
|
|
32
|
+
async deliverToAgent(agentId, message) {
|
|
33
|
+
try {
|
|
34
|
+
const inboxMsg = mapMessageToInbox(message, this.scope);
|
|
35
|
+
// Ensure the target agent is in the recipients list
|
|
36
|
+
const hasAgent = inboxMsg.recipients.some((r) => r.agent_id === agentId);
|
|
37
|
+
if (!hasAgent) {
|
|
38
|
+
inboxMsg.recipients.push({
|
|
39
|
+
agent_id: agentId,
|
|
40
|
+
kind: "to",
|
|
41
|
+
delivered_at: new Date().toISOString(),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
this.storage.putMessage(inboxMsg);
|
|
45
|
+
this.events.emit("message.created", inboxMsg);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Forward to a connected peer. Delegates to the previous handler
|
|
54
|
+
* (MeshPeer's default transport handles actual peer forwarding).
|
|
55
|
+
*/
|
|
56
|
+
async forwardToPeer(peerId, agentIds, message) {
|
|
57
|
+
if (this.previousHandler) {
|
|
58
|
+
return this.previousHandler.forwardToPeer(peerId, agentIds, message);
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Route to a federated system. Delegates to the previous handler
|
|
64
|
+
* (FederationGateway handles cross-mesh routing).
|
|
65
|
+
*/
|
|
66
|
+
async routeToFederation(systemId, agentIds, message) {
|
|
67
|
+
if (this.previousHandler?.routeToFederation) {
|
|
68
|
+
return this.previousHandler.routeToFederation(systemId, agentIds, message);
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=delivery-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delivery-bridge.js","sourceRoot":"","sources":["../../src/mesh/delivery-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAyBrD,8EAA8E;AAC9E,iBAAiB;AACjB,8EAA8E;AAE9E,MAAM,OAAO,cAAc;IAEf;IACA;IACA;IACA;IAJV,YACU,OAAgB,EAChB,MAAoB,EACpB,QAAgB,SAAS,EACzB,eAAqC;QAHrC,YAAO,GAAP,OAAO,CAAS;QAChB,WAAM,GAAN,MAAM,CAAc;QACpB,UAAK,GAAL,KAAK,CAAoB;QACzB,oBAAe,GAAf,eAAe,CAAsB;IAC5C,CAAC;IAEJ;;;OAGG;IACH,KAAK,CAAC,cAAc,CAAC,OAAe,EAAE,OAAmB;QACvD,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,iBAAiB,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;YAExD,oDAAoD;YACpD,MAAM,QAAQ,GAAG,QAAQ,CAAC,UAAU,CAAC,IAAI,CACvC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,CAC9B,CAAC;YACF,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC;oBACvB,QAAQ,EAAE,OAAO;oBACjB,IAAI,EAAE,IAAI;oBACV,YAAY,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;iBACvC,CAAC,CAAC;YACL,CAAC;YAED,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;YAClC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;YAC9C,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,aAAa,CACjB,MAAc,EACd,QAAkB,EAClB,OAAmB;QAEnB,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QACvE,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,iBAAiB,CACrB,QAAgB,EAChB,QAAkB,EAClB,OAAmB;QAEnB,IAAI,IAAI,CAAC,eAAe,EAAE,iBAAiB,EAAE,CAAC;YAC5C,OAAO,IAAI,CAAC,eAAe,CAAC,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC7E,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { MapAgentConnectionClass, MapConnection } from "../map/map-client.js";
|
|
2
|
+
import type { MeshContextLike } from "./mesh-transport.js";
|
|
3
|
+
/**
|
|
4
|
+
* Factory for creating MeshTransport connections to remote peers.
|
|
5
|
+
*
|
|
6
|
+
* Implements MapAgentConnectionClass so it can be injected into
|
|
7
|
+
* ConnectionManager alongside (or instead of) the MAP SDK class.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* ```ts
|
|
11
|
+
* const connector = new MeshConnector(mesh, "my-peer-id");
|
|
12
|
+
* const conn = await connector.connect("remote-peer-id");
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare class MeshConnector implements MapAgentConnectionClass {
|
|
16
|
+
private mesh;
|
|
17
|
+
private localPeerId;
|
|
18
|
+
private channelName;
|
|
19
|
+
constructor(mesh: MeshContextLike, localPeerId: string, channelName?: string);
|
|
20
|
+
/**
|
|
21
|
+
* Create a MeshTransport connection to a remote peer.
|
|
22
|
+
*
|
|
23
|
+
* The `server` parameter is the remote peer ID (not a URL).
|
|
24
|
+
* The `opts` parameter is ignored — mesh peers don't need
|
|
25
|
+
* MAP handshake parameters.
|
|
26
|
+
*/
|
|
27
|
+
connect(server: string, _opts?: unknown): Promise<MapConnection>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=mesh-connector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mesh-connector.d.ts","sourceRoot":"","sources":["../../src/mesh/mesh-connector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG3D;;;;;;;;;;;GAWG;AACH,qBAAa,aAAc,YAAW,uBAAuB;IAEzD,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,WAAW;gBAFX,IAAI,EAAE,eAAe,EACrB,WAAW,EAAE,MAAM,EACnB,WAAW,GAAE,MAA6B;IAGpD;;;;;;OAMG;IACG,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC;CAUvE"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { MeshTransport, DEFAULT_CHANNEL_NAME } from "./mesh-transport.js";
|
|
2
|
+
/**
|
|
3
|
+
* Factory for creating MeshTransport connections to remote peers.
|
|
4
|
+
*
|
|
5
|
+
* Implements MapAgentConnectionClass so it can be injected into
|
|
6
|
+
* ConnectionManager alongside (or instead of) the MAP SDK class.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* ```ts
|
|
10
|
+
* const connector = new MeshConnector(mesh, "my-peer-id");
|
|
11
|
+
* const conn = await connector.connect("remote-peer-id");
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export class MeshConnector {
|
|
15
|
+
mesh;
|
|
16
|
+
localPeerId;
|
|
17
|
+
channelName;
|
|
18
|
+
constructor(mesh, localPeerId, channelName = DEFAULT_CHANNEL_NAME) {
|
|
19
|
+
this.mesh = mesh;
|
|
20
|
+
this.localPeerId = localPeerId;
|
|
21
|
+
this.channelName = channelName;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create a MeshTransport connection to a remote peer.
|
|
25
|
+
*
|
|
26
|
+
* The `server` parameter is the remote peer ID (not a URL).
|
|
27
|
+
* The `opts` parameter is ignored — mesh peers don't need
|
|
28
|
+
* MAP handshake parameters.
|
|
29
|
+
*/
|
|
30
|
+
async connect(server, _opts) {
|
|
31
|
+
const transport = new MeshTransport(this.mesh, this.localPeerId, server, this.channelName);
|
|
32
|
+
await transport.open();
|
|
33
|
+
return transport;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=mesh-connector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mesh-connector.js","sourceRoot":"","sources":["../../src/mesh/mesh-connector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE1E;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,aAAa;IAEd;IACA;IACA;IAHV,YACU,IAAqB,EACrB,WAAmB,EACnB,cAAsB,oBAAoB;QAF1C,SAAI,GAAJ,IAAI,CAAiB;QACrB,gBAAW,GAAX,WAAW,CAAQ;QACnB,gBAAW,GAAX,WAAW,CAA+B;IACjD,CAAC;IAEJ;;;;;;OAMG;IACH,KAAK,CAAC,OAAO,CAAC,MAAc,EAAE,KAAe;QAC3C,MAAM,SAAS,GAAG,IAAI,aAAa,CACjC,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,WAAW,EAChB,MAAM,EACN,IAAI,CAAC,WAAW,CACjB,CAAC;QACF,MAAM,SAAS,CAAC,IAAI,EAAE,CAAC;QACvB,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
|