macro-agent 0.0.13 → 0.0.15
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/settings.local.json +59 -0
- package/dist/agent/agent-manager.d.ts.map +1 -1
- package/dist/agent/agent-manager.js +10 -4
- package/dist/agent/agent-manager.js.map +1 -1
- package/dist/cli/acp.d.ts +6 -0
- package/dist/cli/acp.d.ts.map +1 -1
- package/dist/cli/acp.js +16 -2
- package/dist/cli/acp.js.map +1 -1
- package/dist/map/adapter/index.d.ts +1 -1
- package/dist/map/adapter/index.d.ts.map +1 -1
- package/dist/map/adapter/index.js +1 -1
- package/dist/map/adapter/index.js.map +1 -1
- package/dist/map/utils/address-translation.d.ts +99 -0
- package/dist/map/utils/address-translation.d.ts.map +1 -0
- package/dist/map/utils/address-translation.js +285 -0
- package/dist/map/utils/address-translation.js.map +1 -0
- package/dist/map/utils/index.d.ts +7 -0
- package/dist/map/utils/index.d.ts.map +1 -0
- package/dist/map/utils/index.js +7 -0
- package/dist/map/utils/index.js.map +1 -0
- package/dist/server/combined-server.d.ts.map +1 -1
- package/dist/server/combined-server.js +8 -1
- package/dist/server/combined-server.js.map +1 -1
- package/dist/store/event-store.js +9 -2
- package/dist/store/event-store.js.map +1 -1
- package/dist/store/types/agents.d.ts +2 -0
- package/dist/store/types/agents.d.ts.map +1 -1
- package/package.json +4 -4
- package/references/acp-factory-ref/CHANGELOG.md +33 -0
- package/references/acp-factory-ref/LICENSE +21 -0
- package/references/acp-factory-ref/README.md +341 -0
- package/references/acp-factory-ref/package-lock.json +3102 -0
- package/references/acp-factory-ref/package.json +96 -0
- package/references/acp-factory-ref/python/CHANGELOG.md +33 -0
- package/references/acp-factory-ref/python/LICENSE +21 -0
- package/references/acp-factory-ref/python/Makefile +57 -0
- package/references/acp-factory-ref/python/README.md +253 -0
- package/references/acp-factory-ref/python/pyproject.toml +73 -0
- package/references/acp-factory-ref/python/tests/__init__.py +0 -0
- package/references/acp-factory-ref/python/tests/e2e/__init__.py +1 -0
- package/references/acp-factory-ref/python/tests/e2e/test_codex_e2e.py +349 -0
- package/references/acp-factory-ref/python/tests/e2e/test_gemini_e2e.py +165 -0
- package/references/acp-factory-ref/python/tests/e2e/test_opencode_e2e.py +296 -0
- package/references/acp-factory-ref/python/tests/test_client_handler.py +543 -0
- package/references/acp-factory-ref/python/tests/test_pushable.py +199 -0
- package/references/claude-code-acp/.github/workflows/ci.yml +45 -0
- package/references/claude-code-acp/.github/workflows/publish.yml +34 -0
- package/references/claude-code-acp/.prettierrc.json +4 -0
- package/references/claude-code-acp/CHANGELOG.md +249 -0
- package/references/claude-code-acp/LICENSE +222 -0
- package/references/claude-code-acp/README.md +53 -0
- package/references/claude-code-acp/docs/RELEASES.md +24 -0
- package/references/claude-code-acp/eslint.config.js +48 -0
- package/references/claude-code-acp/package-lock.json +4570 -0
- package/references/claude-code-acp/package.json +88 -0
- package/references/claude-code-acp/scripts/release.sh +119 -0
- package/references/claude-code-acp/src/acp-agent.ts +2079 -0
- package/references/claude-code-acp/src/index.ts +26 -0
- package/references/claude-code-acp/src/lib.ts +38 -0
- package/references/claude-code-acp/src/mcp-server.ts +911 -0
- package/references/claude-code-acp/src/settings.ts +522 -0
- package/references/claude-code-acp/src/tests/.claude/commands/quick-math.md +5 -0
- package/references/claude-code-acp/src/tests/.claude/commands/say-hello.md +6 -0
- package/references/claude-code-acp/src/tests/acp-agent-fork.test.ts +479 -0
- package/references/claude-code-acp/src/tests/acp-agent.test.ts +1502 -0
- package/references/claude-code-acp/src/tests/extract-lines.test.ts +103 -0
- package/references/claude-code-acp/src/tests/fork-session.test.ts +335 -0
- package/references/claude-code-acp/src/tests/replace-and-calculate-location.test.ts +334 -0
- package/references/claude-code-acp/src/tests/settings.test.ts +617 -0
- package/references/claude-code-acp/src/tests/skills-options.test.ts +187 -0
- package/references/claude-code-acp/src/tests/tools.test.ts +318 -0
- package/references/claude-code-acp/src/tests/typescript-declarations.test.ts +558 -0
- package/references/claude-code-acp/src/tools.ts +819 -0
- package/references/claude-code-acp/src/utils.ts +171 -0
- package/references/claude-code-acp/tsconfig.json +18 -0
- package/references/claude-code-acp/vitest.config.ts +19 -0
- package/references/multi-agent-protocol/.sudocode/issues.jsonl +111 -0
- package/references/multi-agent-protocol/.sudocode/specs.jsonl +13 -0
- package/references/multi-agent-protocol/LICENSE +21 -0
- package/references/multi-agent-protocol/README.md +113 -0
- package/references/multi-agent-protocol/docs/00-design-specification.md +496 -0
- package/references/multi-agent-protocol/docs/01-open-questions.md +1050 -0
- package/references/multi-agent-protocol/docs/02-wire-protocol.md +296 -0
- package/references/multi-agent-protocol/docs/03-streaming-semantics.md +252 -0
- package/references/multi-agent-protocol/docs/04-error-handling.md +231 -0
- package/references/multi-agent-protocol/docs/05-connection-model.md +244 -0
- package/references/multi-agent-protocol/docs/06-visibility-permissions.md +243 -0
- package/references/multi-agent-protocol/docs/07-federation.md +259 -0
- package/references/multi-agent-protocol/docs/08-macro-agent-migration.md +253 -0
- package/references/multi-agent-protocol/docs/09-authentication.md +680 -0
- package/references/multi-agent-protocol/docs/10-mail-protocol.md +553 -0
- package/references/multi-agent-protocol/docs/agent-iam-integration.md +877 -0
- package/references/multi-agent-protocol/docs/agentic-mesh-integration-draft.md +459 -0
- package/references/multi-agent-protocol/docs/git-transport-draft.md +251 -0
- package/references/multi-agent-protocol/docs-site/Gemfile +22 -0
- package/references/multi-agent-protocol/docs-site/README.md +82 -0
- package/references/multi-agent-protocol/docs-site/_config.yml +91 -0
- package/references/multi-agent-protocol/docs-site/_includes/head_custom.html +20 -0
- package/references/multi-agent-protocol/docs-site/_sass/color_schemes/map.scss +42 -0
- package/references/multi-agent-protocol/docs-site/_sass/custom/custom.scss +34 -0
- package/references/multi-agent-protocol/docs-site/examples/full-integration.md +510 -0
- package/references/multi-agent-protocol/docs-site/examples/index.md +138 -0
- package/references/multi-agent-protocol/docs-site/examples/simple-chat.md +282 -0
- package/references/multi-agent-protocol/docs-site/examples/task-queue.md +399 -0
- package/references/multi-agent-protocol/docs-site/getting-started/index.md +98 -0
- package/references/multi-agent-protocol/docs-site/getting-started/installation.md +219 -0
- package/references/multi-agent-protocol/docs-site/getting-started/overview.md +172 -0
- package/references/multi-agent-protocol/docs-site/getting-started/quickstart.md +237 -0
- package/references/multi-agent-protocol/docs-site/index.md +136 -0
- package/references/multi-agent-protocol/docs-site/protocol/authentication.md +391 -0
- package/references/multi-agent-protocol/docs-site/protocol/connection-model.md +376 -0
- package/references/multi-agent-protocol/docs-site/protocol/design.md +284 -0
- package/references/multi-agent-protocol/docs-site/protocol/error-handling.md +312 -0
- package/references/multi-agent-protocol/docs-site/protocol/federation.md +449 -0
- package/references/multi-agent-protocol/docs-site/protocol/index.md +129 -0
- package/references/multi-agent-protocol/docs-site/protocol/permissions.md +398 -0
- package/references/multi-agent-protocol/docs-site/protocol/streaming.md +353 -0
- package/references/multi-agent-protocol/docs-site/protocol/wire-protocol.md +369 -0
- package/references/multi-agent-protocol/docs-site/sdk/api/agent.md +357 -0
- package/references/multi-agent-protocol/docs-site/sdk/api/client.md +380 -0
- package/references/multi-agent-protocol/docs-site/sdk/api/index.md +62 -0
- package/references/multi-agent-protocol/docs-site/sdk/api/server.md +453 -0
- package/references/multi-agent-protocol/docs-site/sdk/api/types.md +468 -0
- package/references/multi-agent-protocol/docs-site/sdk/guides/agent.md +375 -0
- package/references/multi-agent-protocol/docs-site/sdk/guides/authentication.md +405 -0
- package/references/multi-agent-protocol/docs-site/sdk/guides/client.md +352 -0
- package/references/multi-agent-protocol/docs-site/sdk/guides/index.md +89 -0
- package/references/multi-agent-protocol/docs-site/sdk/guides/server.md +360 -0
- package/references/multi-agent-protocol/docs-site/sdk/guides/testing.md +446 -0
- package/references/multi-agent-protocol/docs-site/sdk/guides/transports.md +363 -0
- package/references/multi-agent-protocol/docs-site/sdk/index.md +206 -0
- package/references/multi-agent-protocol/package-lock.json +3886 -0
- package/references/multi-agent-protocol/package.json +56 -0
- package/references/multi-agent-protocol/schema/meta.json +467 -0
- package/references/multi-agent-protocol/schema/schema.json +2558 -0
- package/src/agent/__tests__/agent-manager.test.ts +67 -1
- package/src/agent/agent-manager.ts +10 -4
- package/src/cli/__tests__/stable-instance-id.test.ts +57 -0
- package/src/cli/acp.ts +17 -2
- package/src/map/adapter/index.ts +3 -0
- package/src/server/combined-server.ts +10 -0
- package/src/store/event-store.ts +10 -3
- package/src/store/types/agents.ts +2 -0
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Transports
|
|
3
|
+
parent: Guides
|
|
4
|
+
grand_parent: SDK
|
|
5
|
+
nav_order: 4
|
|
6
|
+
description: "WebSocket, stdio, and custom transport adapters"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Transports
|
|
10
|
+
{: .no_toc }
|
|
11
|
+
|
|
12
|
+
Connect via WebSocket, stdio, or custom transports.
|
|
13
|
+
{: .fs-6 .fw-300 }
|
|
14
|
+
|
|
15
|
+
## Table of contents
|
|
16
|
+
{: .no_toc .text-delta }
|
|
17
|
+
|
|
18
|
+
1. TOC
|
|
19
|
+
{:toc}
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Overview
|
|
24
|
+
|
|
25
|
+
MAP is transport-agnostic. The SDK provides adapters for common transports and interfaces for building custom ones.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Stream Interface
|
|
30
|
+
|
|
31
|
+
All transports implement the bidirectional stream interface:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
interface Stream {
|
|
35
|
+
readable: ReadableStream<JSONRPCMessage>;
|
|
36
|
+
writable: WritableStream<JSONRPCMessage>;
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## WebSocket Transport
|
|
43
|
+
|
|
44
|
+
The most common transport for remote connections.
|
|
45
|
+
|
|
46
|
+
### Server Side
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { MAPServer } from "@multi-agent-protocol/sdk/server";
|
|
50
|
+
import { WebSocketServer } from "ws";
|
|
51
|
+
|
|
52
|
+
const server = new MAPServer({ name: "MyServer" });
|
|
53
|
+
const wss = new WebSocketServer({ port: 8080 });
|
|
54
|
+
|
|
55
|
+
wss.on("connection", (ws) => {
|
|
56
|
+
const stream = websocketToStream(ws);
|
|
57
|
+
server.accept(stream).start();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
function websocketToStream(ws: WebSocket): Stream {
|
|
61
|
+
return {
|
|
62
|
+
readable: new ReadableStream({
|
|
63
|
+
start(controller) {
|
|
64
|
+
ws.on("message", (data) => {
|
|
65
|
+
controller.enqueue(JSON.parse(data.toString()));
|
|
66
|
+
});
|
|
67
|
+
ws.on("close", () => controller.close());
|
|
68
|
+
ws.on("error", (err) => controller.error(err));
|
|
69
|
+
},
|
|
70
|
+
}),
|
|
71
|
+
writable: new WritableStream({
|
|
72
|
+
write(message) {
|
|
73
|
+
ws.send(JSON.stringify(message));
|
|
74
|
+
},
|
|
75
|
+
close() {
|
|
76
|
+
ws.close();
|
|
77
|
+
},
|
|
78
|
+
}),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Client Side
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { ClientConnection } from "@multi-agent-protocol/sdk";
|
|
87
|
+
import WebSocket from "ws";
|
|
88
|
+
|
|
89
|
+
const ws = new WebSocket("ws://localhost:8080");
|
|
90
|
+
await new Promise((resolve) => ws.on("open", resolve));
|
|
91
|
+
|
|
92
|
+
const stream = websocketToStream(ws);
|
|
93
|
+
const client = new ClientConnection(stream, { name: "Dashboard" });
|
|
94
|
+
await client.connect();
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Stdio Transport
|
|
100
|
+
|
|
101
|
+
For subprocess agents (like Claude Code's Task tool pattern).
|
|
102
|
+
|
|
103
|
+
### Parent Process (Server)
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { spawn } from "child_process";
|
|
107
|
+
import { MAPServer } from "@multi-agent-protocol/sdk/server";
|
|
108
|
+
|
|
109
|
+
const server = new MAPServer({ name: "ParentServer" });
|
|
110
|
+
|
|
111
|
+
// Spawn child agent process
|
|
112
|
+
const child = spawn("node", ["agent.js"], {
|
|
113
|
+
stdio: ["pipe", "pipe", "inherit"],
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const stream = stdioToStream(child.stdin, child.stdout);
|
|
117
|
+
server.accept(stream).start();
|
|
118
|
+
|
|
119
|
+
function stdioToStream(stdin: Writable, stdout: Readable): Stream {
|
|
120
|
+
let buffer = "";
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
readable: new ReadableStream({
|
|
124
|
+
start(controller) {
|
|
125
|
+
stdout.on("data", (chunk) => {
|
|
126
|
+
buffer += chunk.toString();
|
|
127
|
+
const lines = buffer.split("\n");
|
|
128
|
+
buffer = lines.pop() || "";
|
|
129
|
+
|
|
130
|
+
for (const line of lines) {
|
|
131
|
+
if (line.trim()) {
|
|
132
|
+
controller.enqueue(JSON.parse(line));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
stdout.on("end", () => controller.close());
|
|
137
|
+
stdout.on("error", (err) => controller.error(err));
|
|
138
|
+
},
|
|
139
|
+
}),
|
|
140
|
+
writable: new WritableStream({
|
|
141
|
+
write(message) {
|
|
142
|
+
stdin.write(JSON.stringify(message) + "\n");
|
|
143
|
+
},
|
|
144
|
+
close() {
|
|
145
|
+
stdin.end();
|
|
146
|
+
},
|
|
147
|
+
}),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Child Process (Agent)
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
// agent.js
|
|
156
|
+
import { AgentConnection } from "@multi-agent-protocol/sdk";
|
|
157
|
+
|
|
158
|
+
const stream = stdioToStream(process.stdin, process.stdout);
|
|
159
|
+
const agent = new AgentConnection(stream, {
|
|
160
|
+
name: "ChildAgent",
|
|
161
|
+
role: "worker",
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
await agent.connect();
|
|
165
|
+
|
|
166
|
+
agent.onMessage((message) => {
|
|
167
|
+
// Process messages from parent
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## In-Process Transport
|
|
174
|
+
|
|
175
|
+
For testing or co-located components.
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
import { createStreamPair } from "@multi-agent-protocol/sdk/stream";
|
|
179
|
+
import { MAPServer } from "@multi-agent-protocol/sdk/server";
|
|
180
|
+
import { ClientConnection } from "@multi-agent-protocol/sdk";
|
|
181
|
+
|
|
182
|
+
// Create a connected pair of streams
|
|
183
|
+
const [clientStream, serverStream] = createStreamPair();
|
|
184
|
+
|
|
185
|
+
// Server uses one end
|
|
186
|
+
const server = new MAPServer({ name: "TestServer" });
|
|
187
|
+
server.accept(serverStream).start();
|
|
188
|
+
|
|
189
|
+
// Client uses the other end
|
|
190
|
+
const client = new ClientConnection(clientStream, { name: "TestClient" });
|
|
191
|
+
await client.connect();
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## HTTP + SSE Transport
|
|
197
|
+
|
|
198
|
+
For stateless clients and environments that don't support WebSockets.
|
|
199
|
+
|
|
200
|
+
### Server Side
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
import express from "express";
|
|
204
|
+
import { MAPServer } from "@multi-agent-protocol/sdk/server";
|
|
205
|
+
|
|
206
|
+
const app = express();
|
|
207
|
+
const server = new MAPServer({ name: "HTTPServer" });
|
|
208
|
+
|
|
209
|
+
// Store active SSE connections
|
|
210
|
+
const sseConnections = new Map<string, Response>();
|
|
211
|
+
|
|
212
|
+
// RPC endpoint
|
|
213
|
+
app.post("/map/rpc", express.json(), async (req, res) => {
|
|
214
|
+
const sessionId = req.headers["x-session-id"] as string;
|
|
215
|
+
const result = await server.handleRequest(req.body, sessionId);
|
|
216
|
+
res.json(result);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// SSE endpoint for events
|
|
220
|
+
app.get("/map/events", (req, res) => {
|
|
221
|
+
const sessionId = req.query.sessionId as string;
|
|
222
|
+
|
|
223
|
+
res.setHeader("Content-Type", "text/event-stream");
|
|
224
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
225
|
+
res.setHeader("Connection", "keep-alive");
|
|
226
|
+
|
|
227
|
+
sseConnections.set(sessionId, res);
|
|
228
|
+
|
|
229
|
+
req.on("close", () => {
|
|
230
|
+
sseConnections.delete(sessionId);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
// Deliver events via SSE
|
|
235
|
+
server.on("*", (event) => {
|
|
236
|
+
for (const [sessionId, res] of sseConnections) {
|
|
237
|
+
res.write(`event: map.event\n`);
|
|
238
|
+
res.write(`data: ${JSON.stringify(event)}\n\n`);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
app.listen(8080);
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Client Side
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
function httpToStream(baseUrl: string, sessionId: string): Stream {
|
|
249
|
+
const eventSource = new EventSource(
|
|
250
|
+
`${baseUrl}/map/events?sessionId=${sessionId}`
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
return {
|
|
254
|
+
readable: new ReadableStream({
|
|
255
|
+
start(controller) {
|
|
256
|
+
eventSource.addEventListener("map.event", (e) => {
|
|
257
|
+
controller.enqueue(JSON.parse(e.data));
|
|
258
|
+
});
|
|
259
|
+
eventSource.onerror = () => controller.close();
|
|
260
|
+
},
|
|
261
|
+
}),
|
|
262
|
+
writable: new WritableStream({
|
|
263
|
+
async write(message) {
|
|
264
|
+
await fetch(`${baseUrl}/map/rpc`, {
|
|
265
|
+
method: "POST",
|
|
266
|
+
headers: {
|
|
267
|
+
"Content-Type": "application/json",
|
|
268
|
+
"X-Session-Id": sessionId,
|
|
269
|
+
},
|
|
270
|
+
body: JSON.stringify(message),
|
|
271
|
+
});
|
|
272
|
+
},
|
|
273
|
+
}),
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## Custom Transports
|
|
281
|
+
|
|
282
|
+
Implement any transport by providing a Stream:
|
|
283
|
+
|
|
284
|
+
```typescript
|
|
285
|
+
interface CustomTransportOptions {
|
|
286
|
+
// Your transport-specific options
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function createCustomTransport(options: CustomTransportOptions): Stream {
|
|
290
|
+
return {
|
|
291
|
+
readable: new ReadableStream({
|
|
292
|
+
start(controller) {
|
|
293
|
+
// Set up your transport's incoming message handling
|
|
294
|
+
// Call controller.enqueue(message) for each message
|
|
295
|
+
// Call controller.close() when connection ends
|
|
296
|
+
// Call controller.error(err) on errors
|
|
297
|
+
},
|
|
298
|
+
}),
|
|
299
|
+
writable: new WritableStream({
|
|
300
|
+
write(message) {
|
|
301
|
+
// Send message over your transport
|
|
302
|
+
},
|
|
303
|
+
close() {
|
|
304
|
+
// Clean up your transport
|
|
305
|
+
},
|
|
306
|
+
}),
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### Example: Redis Pub/Sub Transport
|
|
312
|
+
|
|
313
|
+
```typescript
|
|
314
|
+
import Redis from "ioredis";
|
|
315
|
+
|
|
316
|
+
function redisToStream(channelIn: string, channelOut: string): Stream {
|
|
317
|
+
const subscriber = new Redis();
|
|
318
|
+
const publisher = new Redis();
|
|
319
|
+
|
|
320
|
+
return {
|
|
321
|
+
readable: new ReadableStream({
|
|
322
|
+
async start(controller) {
|
|
323
|
+
await subscriber.subscribe(channelIn);
|
|
324
|
+
subscriber.on("message", (channel, data) => {
|
|
325
|
+
if (channel === channelIn) {
|
|
326
|
+
controller.enqueue(JSON.parse(data));
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
},
|
|
330
|
+
cancel() {
|
|
331
|
+
subscriber.unsubscribe(channelIn);
|
|
332
|
+
subscriber.quit();
|
|
333
|
+
},
|
|
334
|
+
}),
|
|
335
|
+
writable: new WritableStream({
|
|
336
|
+
write(message) {
|
|
337
|
+
publisher.publish(channelOut, JSON.stringify(message));
|
|
338
|
+
},
|
|
339
|
+
close() {
|
|
340
|
+
publisher.quit();
|
|
341
|
+
},
|
|
342
|
+
}),
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
---
|
|
348
|
+
|
|
349
|
+
## Transport Selection Guide
|
|
350
|
+
|
|
351
|
+
| Transport | Use Case | Pros | Cons |
|
|
352
|
+
|:----------|:---------|:-----|:-----|
|
|
353
|
+
| **WebSocket** | Remote clients, browsers | Bidirectional, real-time | Requires WS support |
|
|
354
|
+
| **stdio** | Subprocess agents | Simple, no network | Local only |
|
|
355
|
+
| **In-process** | Testing, co-located | Zero latency | Same process only |
|
|
356
|
+
| **HTTP + SSE** | Serverless, restricted envs | Works everywhere | Higher latency |
|
|
357
|
+
|
|
358
|
+
---
|
|
359
|
+
|
|
360
|
+
## Next Steps
|
|
361
|
+
|
|
362
|
+
- [Server Setup](./server.html) - Configure your server
|
|
363
|
+
- [Testing](./testing.html) - Use in-process transport for tests
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: SDK
|
|
3
|
+
nav_order: 4
|
|
4
|
+
has_children: true
|
|
5
|
+
description: "MAP TypeScript SDK documentation"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# TypeScript SDK
|
|
9
|
+
|
|
10
|
+
The Multi-Agent Protocol TypeScript SDK provides everything you need to build observable, coordinated multi-agent systems.
|
|
11
|
+
{: .fs-6 .fw-300 }
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Who This Is For
|
|
16
|
+
|
|
17
|
+
- **Agent Developers** - Build agents that register with MAP servers, receive messages, and collaborate with other agents
|
|
18
|
+
- **Platform Developers** - Build MAP-compliant servers that orchestrate agents and expose them to clients
|
|
19
|
+
- **Client Developers** - Build applications that observe and interact with multi-agent systems
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @multi-agent-protocol/sdk
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Quick Navigation
|
|
32
|
+
|
|
33
|
+
### Guides
|
|
34
|
+
|
|
35
|
+
| Guide | Description |
|
|
36
|
+
|:------|:------------|
|
|
37
|
+
| [Server Setup](./guides/server.html) | Set up a MAP server with MAPServer |
|
|
38
|
+
| [Client Integration](./guides/client.html) | Connect clients that observe and send messages |
|
|
39
|
+
| [Agent Integration](./guides/agent.html) | Build agents that register and process work |
|
|
40
|
+
| [Transports](./guides/transports.html) | WebSocket, stdio, and custom transports |
|
|
41
|
+
| [Authentication](./guides/authentication.html) | Configure authentication |
|
|
42
|
+
| [Testing](./guides/testing.html) | Test your MAP integrations |
|
|
43
|
+
|
|
44
|
+
### API Reference
|
|
45
|
+
|
|
46
|
+
| Reference | Description |
|
|
47
|
+
|:----------|:------------|
|
|
48
|
+
| [Server API](./api/server.html) | MAPServer and building blocks |
|
|
49
|
+
| [Client API](./api/client.html) | ClientConnection methods |
|
|
50
|
+
| [Agent API](./api/agent.html) | AgentConnection methods |
|
|
51
|
+
| [Types](./api/types.html) | TypeScript type definitions |
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Package Exports
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
// Main exports (connections)
|
|
59
|
+
import {
|
|
60
|
+
ClientConnection,
|
|
61
|
+
AgentConnection,
|
|
62
|
+
GatewayConnection
|
|
63
|
+
} from "@multi-agent-protocol/sdk";
|
|
64
|
+
|
|
65
|
+
// Server components
|
|
66
|
+
import { MAPServer } from "@multi-agent-protocol/sdk/server";
|
|
67
|
+
|
|
68
|
+
// Building blocks for custom servers
|
|
69
|
+
import {
|
|
70
|
+
EventBusImpl,
|
|
71
|
+
AgentRegistryImpl,
|
|
72
|
+
ScopeManagerImpl,
|
|
73
|
+
SubscriptionManagerImpl,
|
|
74
|
+
} from "@multi-agent-protocol/sdk/server";
|
|
75
|
+
|
|
76
|
+
// Stream utilities
|
|
77
|
+
import { createStreamPair } from "@multi-agent-protocol/sdk/stream";
|
|
78
|
+
|
|
79
|
+
// Type definitions
|
|
80
|
+
import type {
|
|
81
|
+
Agent,
|
|
82
|
+
Message,
|
|
83
|
+
Event,
|
|
84
|
+
Subscription,
|
|
85
|
+
} from "@multi-agent-protocol/sdk";
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Minimal Example
|
|
91
|
+
|
|
92
|
+
**Server:**
|
|
93
|
+
```typescript
|
|
94
|
+
import { MAPServer } from "@multi-agent-protocol/sdk/server";
|
|
95
|
+
import { WebSocketServer } from "ws";
|
|
96
|
+
|
|
97
|
+
const server = new MAPServer({ name: "MyServer" });
|
|
98
|
+
const wss = new WebSocketServer({ port: 8080 });
|
|
99
|
+
|
|
100
|
+
wss.on("connection", (ws) => {
|
|
101
|
+
const stream = websocketToStream(ws);
|
|
102
|
+
server.accept(stream).start();
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**Agent:**
|
|
107
|
+
```typescript
|
|
108
|
+
import { AgentConnection } from "@multi-agent-protocol/sdk";
|
|
109
|
+
|
|
110
|
+
const agent = new AgentConnection(stream, {
|
|
111
|
+
name: "Worker",
|
|
112
|
+
role: "processor"
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const { agent: registered } = await agent.connect();
|
|
116
|
+
console.log(`Registered: ${registered.id}`);
|
|
117
|
+
|
|
118
|
+
agent.onMessage((message) => {
|
|
119
|
+
console.log("Received:", message.payload);
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Client:**
|
|
124
|
+
```typescript
|
|
125
|
+
import { ClientConnection } from "@multi-agent-protocol/sdk";
|
|
126
|
+
|
|
127
|
+
const client = new ClientConnection(stream, { name: "Dashboard" });
|
|
128
|
+
await client.connect();
|
|
129
|
+
|
|
130
|
+
// List all agents
|
|
131
|
+
const { agents } = await client.listAgents();
|
|
132
|
+
|
|
133
|
+
// Subscribe to events
|
|
134
|
+
const subscription = await client.subscribe({
|
|
135
|
+
eventTypes: ["agent.*"]
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
for await (const event of subscription) {
|
|
139
|
+
console.log("Event:", event.type);
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## Progressive Disclosure
|
|
146
|
+
|
|
147
|
+
The SDK follows a **progressive disclosure** pattern:
|
|
148
|
+
|
|
149
|
+
### Level 1: Just Works
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
const server = new MAPServer();
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Level 2: Customize Behavior
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
const server = new MAPServer({
|
|
159
|
+
middleware: [loggingMiddleware, authMiddleware],
|
|
160
|
+
additionalHandlers: { "custom/method": myHandler },
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Level 3: Full Control
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
const eventBus = new EventBusImpl({
|
|
168
|
+
store: new RedisEventStore()
|
|
169
|
+
});
|
|
170
|
+
const agents = new AgentRegistryImpl({
|
|
171
|
+
eventBus,
|
|
172
|
+
store: new PostgresAgentStore()
|
|
173
|
+
});
|
|
174
|
+
// ... compose your own server
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Key Concepts
|
|
180
|
+
|
|
181
|
+
### Three Participant Types
|
|
182
|
+
|
|
183
|
+
| Type | Class | Purpose |
|
|
184
|
+
|:-----|:------|:--------|
|
|
185
|
+
| **Agent** | `AgentConnection` | Worker that processes tasks |
|
|
186
|
+
| **Client** | `ClientConnection` | Observer that monitors and sends messages |
|
|
187
|
+
| **Gateway** | `GatewayConnection` | Bridge between federated systems |
|
|
188
|
+
|
|
189
|
+
### Server Building Blocks
|
|
190
|
+
|
|
191
|
+
| Component | Purpose |
|
|
192
|
+
|:----------|:--------|
|
|
193
|
+
| **EventBus** | Central event dispatcher |
|
|
194
|
+
| **AgentRegistry** | Tracks registered agents |
|
|
195
|
+
| **ScopeManager** | Manages logical groupings |
|
|
196
|
+
| **SessionManager** | Handles connections |
|
|
197
|
+
| **SubscriptionManager** | Event filtering and delivery |
|
|
198
|
+
| **MessageRouter** | Routes messages |
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## Next Steps
|
|
203
|
+
|
|
204
|
+
1. **[Server Setup](./guides/server.html)** - Create your MAP server
|
|
205
|
+
2. **[Agent Integration](./guides/agent.html)** - Build your first agent
|
|
206
|
+
3. **[Client Integration](./guides/client.html)** - Build observability tools
|