macro-agent 0.0.14 → 0.0.16
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/acp/index.d.ts +1 -1
- package/dist/acp/index.d.ts.map +1 -1
- package/dist/acp/index.js.map +1 -1
- package/dist/acp/macro-agent.d.ts +21 -0
- package/dist/acp/macro-agent.d.ts.map +1 -1
- package/dist/acp/macro-agent.js +182 -0
- package/dist/acp/macro-agent.js.map +1 -1
- package/dist/acp/types.d.ts +31 -2
- package/dist/acp/types.d.ts.map +1 -1
- package/dist/acp/types.js.map +1 -1
- 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/acp-over-map.d.ts +5 -0
- package/dist/map/adapter/acp-over-map.d.ts.map +1 -1
- package/dist/map/adapter/acp-over-map.js +47 -4
- package/dist/map/adapter/acp-over-map.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/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/acp/__tests__/history.test.ts +526 -0
- package/src/acp/__tests__/integration.test.ts +2 -1
- package/src/acp/index.ts +4 -0
- package/src/acp/macro-agent.ts +329 -85
- package/src/acp/types.ts +39 -2
- 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/acp-over-map.ts +57 -2
- package/src/store/event-store.ts +10 -3
- package/src/store/types/agents.ts +2 -0
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Server Setup
|
|
3
|
+
parent: Guides
|
|
4
|
+
grand_parent: SDK
|
|
5
|
+
nav_order: 1
|
|
6
|
+
description: "Create and configure a MAP server"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Server Setup
|
|
10
|
+
{: .no_toc }
|
|
11
|
+
|
|
12
|
+
Create MAP-compliant servers with MAPServer.
|
|
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
|
+
`MAPServer` is the recommended way to create MAP-compliant servers. It wires together all building blocks with sensible defaults while providing access to everything for advanced use cases.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Basic Usage
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { MAPServer } from "@multi-agent-protocol/sdk/server";
|
|
33
|
+
|
|
34
|
+
const server = new MAPServer({
|
|
35
|
+
name: "MyServer",
|
|
36
|
+
version: "1.0.0",
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
That's it! The server now has:
|
|
41
|
+
- EventBus for event dispatching
|
|
42
|
+
- AgentRegistry for agent lifecycle
|
|
43
|
+
- SessionManager for connection tracking
|
|
44
|
+
- ScopeManager for logical groupings
|
|
45
|
+
- SubscriptionManager for event filtering
|
|
46
|
+
- MessageRouter for message delivery
|
|
47
|
+
- All standard protocol handlers
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Accepting Connections
|
|
52
|
+
|
|
53
|
+
Use `accept()` to handle incoming connections:
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { createStreamPair } from "@multi-agent-protocol/sdk/stream";
|
|
57
|
+
|
|
58
|
+
// For testing with in-memory streams
|
|
59
|
+
const [clientStream, serverStream] = createStreamPair();
|
|
60
|
+
const router = server.accept(serverStream);
|
|
61
|
+
router.start();
|
|
62
|
+
|
|
63
|
+
// For WebSocket
|
|
64
|
+
wss.on("connection", (ws) => {
|
|
65
|
+
const stream = websocketToStream(ws);
|
|
66
|
+
const router = server.accept(stream);
|
|
67
|
+
router.start();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// With options
|
|
71
|
+
server.accept(stream, {
|
|
72
|
+
role: "agent", // "client" | "agent" | "gateway"
|
|
73
|
+
name: "WorkerAgent", // Session name
|
|
74
|
+
resumeToken: token, // For reconnection
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Configuration Options
|
|
81
|
+
|
|
82
|
+
### Server Identity
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
const server = new MAPServer({
|
|
86
|
+
name: "ProductionServer", // Shown in connect response
|
|
87
|
+
version: "2.1.0", // Shown in connect response
|
|
88
|
+
capabilities: { // Advertised capabilities
|
|
89
|
+
subscriptions: { maxActive: 100 },
|
|
90
|
+
streaming: { backpressure: true },
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Custom Handlers
|
|
96
|
+
|
|
97
|
+
Add your own protocol methods:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
const server = new MAPServer({
|
|
101
|
+
additionalHandlers: {
|
|
102
|
+
"custom/echo": async (params, ctx) => {
|
|
103
|
+
return { echo: params };
|
|
104
|
+
},
|
|
105
|
+
"custom/stats": async (params, ctx) => {
|
|
106
|
+
return {
|
|
107
|
+
agents: server.agents.list().length,
|
|
108
|
+
sessions: server.sessions.list().length,
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Middleware
|
|
116
|
+
|
|
117
|
+
Add request/response middleware:
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
const server = new MAPServer({
|
|
121
|
+
middleware: [
|
|
122
|
+
// Logging middleware
|
|
123
|
+
async (method, params, ctx, next) => {
|
|
124
|
+
console.log(`[${ctx.requestId}] ${method}`);
|
|
125
|
+
const start = Date.now();
|
|
126
|
+
const result = await next();
|
|
127
|
+
console.log(`[${ctx.requestId}] ${method} took ${Date.now() - start}ms`);
|
|
128
|
+
return result;
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
// Auth middleware
|
|
132
|
+
async (method, params, ctx, next) => {
|
|
133
|
+
if (method.startsWith("admin/") && ctx.session.role !== "admin") {
|
|
134
|
+
throw new Error("Unauthorized");
|
|
135
|
+
}
|
|
136
|
+
return next();
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Event Delivery
|
|
143
|
+
|
|
144
|
+
Configure how events are delivered to subscriptions:
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
const server = new MAPServer({
|
|
148
|
+
eventDelivery: {
|
|
149
|
+
enabled: true, // Default: true
|
|
150
|
+
|
|
151
|
+
// Custom filter for event delivery
|
|
152
|
+
filter: (event, subscription) => {
|
|
153
|
+
// Don't deliver internal events to clients
|
|
154
|
+
if (event.type.startsWith("internal.")) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
return true;
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## Accessing Building Blocks
|
|
166
|
+
|
|
167
|
+
All building blocks are accessible for direct manipulation:
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
// Direct agent registration (bypassing protocol)
|
|
171
|
+
const agent = server.agents.register({
|
|
172
|
+
name: "SystemAgent",
|
|
173
|
+
sessionId: "internal",
|
|
174
|
+
role: "system",
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
// Direct scope creation
|
|
178
|
+
const scope = server.scopes.create({
|
|
179
|
+
name: "global",
|
|
180
|
+
metadata: { description: "Global announcement channel" },
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// Direct session management
|
|
184
|
+
const sessions = server.sessions.list({ status: "connected" });
|
|
185
|
+
|
|
186
|
+
// Direct event emission
|
|
187
|
+
server.emit({
|
|
188
|
+
type: "system.started",
|
|
189
|
+
data: { timestamp: Date.now() },
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// Event subscription
|
|
193
|
+
server.on("agent.registered", (event) => {
|
|
194
|
+
console.log(`New agent: ${event.data.agent.name}`);
|
|
195
|
+
});
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## Custom Storage
|
|
201
|
+
|
|
202
|
+
Use custom stores for persistence:
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
import { MAPServer } from "@multi-agent-protocol/sdk/server";
|
|
206
|
+
|
|
207
|
+
const server = new MAPServer({
|
|
208
|
+
stores: {
|
|
209
|
+
events: new RedisEventStore(redis),
|
|
210
|
+
agents: new PostgresAgentStore(db),
|
|
211
|
+
sessions: new RedisSessionStore(redis),
|
|
212
|
+
scopes: new PostgresScopeStore(db),
|
|
213
|
+
subscriptions: new InMemorySubscriptionStore(),
|
|
214
|
+
messages: new RabbitMQMessageStore(channel),
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Store Interfaces
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
interface EventStore {
|
|
223
|
+
append(event: MAPEvent): void;
|
|
224
|
+
getAfter(afterId: string, limit?: number): MAPEvent[];
|
|
225
|
+
getByType(type: string, limit?: number): MAPEvent[];
|
|
226
|
+
clear(): void;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
interface AgentStore {
|
|
230
|
+
save(agent: RegisteredAgent): void;
|
|
231
|
+
get(id: string): RegisteredAgent | undefined;
|
|
232
|
+
list(filter?: AgentFilter): RegisteredAgent[];
|
|
233
|
+
delete(id: string): boolean;
|
|
234
|
+
clear(): void;
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## Replacing Building Blocks
|
|
241
|
+
|
|
242
|
+
For full control, replace entire building blocks:
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
import {
|
|
246
|
+
MAPServer,
|
|
247
|
+
EventBusImpl,
|
|
248
|
+
AgentRegistryImpl,
|
|
249
|
+
} from "@multi-agent-protocol/sdk/server";
|
|
250
|
+
|
|
251
|
+
// Custom EventBus with special behavior
|
|
252
|
+
const customEventBus = new EventBusImpl({
|
|
253
|
+
store: new RedisEventStore(redis),
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
// Custom AgentRegistry
|
|
257
|
+
const customAgents = new AgentRegistryImpl({
|
|
258
|
+
eventBus: customEventBus,
|
|
259
|
+
store: new PostgresAgentStore(db),
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
const server = new MAPServer({
|
|
263
|
+
eventBus: customEventBus,
|
|
264
|
+
agents: customAgents,
|
|
265
|
+
// Other blocks will use the custom eventBus
|
|
266
|
+
});
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## Graceful Shutdown
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
// Graceful shutdown (default 5s timeout)
|
|
275
|
+
await server.close();
|
|
276
|
+
|
|
277
|
+
// Custom timeout
|
|
278
|
+
await server.close({ timeout: 10000 });
|
|
279
|
+
|
|
280
|
+
// Force close (no waiting)
|
|
281
|
+
await server.close({ force: true });
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## Complete Example
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
import { MAPServer } from "@multi-agent-protocol/sdk/server";
|
|
290
|
+
import { WebSocketServer } from "ws";
|
|
291
|
+
|
|
292
|
+
// Create server with common configuration
|
|
293
|
+
const server = new MAPServer({
|
|
294
|
+
name: "ProductionServer",
|
|
295
|
+
version: "1.0.0",
|
|
296
|
+
|
|
297
|
+
// Add custom methods
|
|
298
|
+
additionalHandlers: {
|
|
299
|
+
"stats/overview": async () => ({
|
|
300
|
+
agents: server.agents.list().length,
|
|
301
|
+
scopes: server.scopes.list().length,
|
|
302
|
+
connections: server.connections.size,
|
|
303
|
+
}),
|
|
304
|
+
},
|
|
305
|
+
|
|
306
|
+
// Add logging
|
|
307
|
+
middleware: [
|
|
308
|
+
async (method, params, ctx, next) => {
|
|
309
|
+
console.log(`${ctx.session.id} -> ${method}`);
|
|
310
|
+
return next();
|
|
311
|
+
},
|
|
312
|
+
],
|
|
313
|
+
|
|
314
|
+
// Configure event delivery
|
|
315
|
+
eventDelivery: {
|
|
316
|
+
filter: (event) => !event.type.startsWith("internal."),
|
|
317
|
+
},
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
// Listen for system events
|
|
321
|
+
server.on("agent.registered", (event) => {
|
|
322
|
+
console.log(`Agent registered: ${event.data.agent.name}`);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
server.on("session.connected", (event) => {
|
|
326
|
+
console.log(`Session connected: ${event.data.session.id}`);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
// WebSocket server
|
|
330
|
+
const wss = new WebSocketServer({ port: 8080 });
|
|
331
|
+
|
|
332
|
+
wss.on("connection", (ws) => {
|
|
333
|
+
const stream = websocketToStream(ws);
|
|
334
|
+
const router = server.accept(stream);
|
|
335
|
+
router.start();
|
|
336
|
+
|
|
337
|
+
ws.on("close", () => {
|
|
338
|
+
console.log("Connection closed");
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
// Graceful shutdown
|
|
343
|
+
process.on("SIGTERM", async () => {
|
|
344
|
+
console.log("Shutting down...");
|
|
345
|
+
await server.close();
|
|
346
|
+
wss.close();
|
|
347
|
+
process.exit(0);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
console.log("Server listening on ws://localhost:8080");
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
---
|
|
354
|
+
|
|
355
|
+
## Next Steps
|
|
356
|
+
|
|
357
|
+
- [Client Integration](./client.html) - Build monitoring dashboards
|
|
358
|
+
- [Agent Integration](./agent.html) - Build agents that connect
|
|
359
|
+
- [Transports](./transports.html) - Use different transports
|
|
360
|
+
- [Testing](./testing.html) - Test your server
|