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.
Files changed (154) hide show
  1. package/.claude/settings.local.json +59 -0
  2. package/dist/acp/index.d.ts +1 -1
  3. package/dist/acp/index.d.ts.map +1 -1
  4. package/dist/acp/index.js.map +1 -1
  5. package/dist/acp/macro-agent.d.ts +21 -0
  6. package/dist/acp/macro-agent.d.ts.map +1 -1
  7. package/dist/acp/macro-agent.js +182 -0
  8. package/dist/acp/macro-agent.js.map +1 -1
  9. package/dist/acp/types.d.ts +31 -2
  10. package/dist/acp/types.d.ts.map +1 -1
  11. package/dist/acp/types.js.map +1 -1
  12. package/dist/agent/agent-manager.d.ts.map +1 -1
  13. package/dist/agent/agent-manager.js +10 -4
  14. package/dist/agent/agent-manager.js.map +1 -1
  15. package/dist/cli/acp.d.ts +6 -0
  16. package/dist/cli/acp.d.ts.map +1 -1
  17. package/dist/cli/acp.js +16 -2
  18. package/dist/cli/acp.js.map +1 -1
  19. package/dist/map/adapter/acp-over-map.d.ts +5 -0
  20. package/dist/map/adapter/acp-over-map.d.ts.map +1 -1
  21. package/dist/map/adapter/acp-over-map.js +47 -4
  22. package/dist/map/adapter/acp-over-map.js.map +1 -1
  23. package/dist/map/utils/address-translation.d.ts +99 -0
  24. package/dist/map/utils/address-translation.d.ts.map +1 -0
  25. package/dist/map/utils/address-translation.js +285 -0
  26. package/dist/map/utils/address-translation.js.map +1 -0
  27. package/dist/map/utils/index.d.ts +7 -0
  28. package/dist/map/utils/index.d.ts.map +1 -0
  29. package/dist/map/utils/index.js +7 -0
  30. package/dist/map/utils/index.js.map +1 -0
  31. package/dist/store/event-store.js +9 -2
  32. package/dist/store/event-store.js.map +1 -1
  33. package/dist/store/types/agents.d.ts +2 -0
  34. package/dist/store/types/agents.d.ts.map +1 -1
  35. package/package.json +4 -4
  36. package/references/acp-factory-ref/CHANGELOG.md +33 -0
  37. package/references/acp-factory-ref/LICENSE +21 -0
  38. package/references/acp-factory-ref/README.md +341 -0
  39. package/references/acp-factory-ref/package-lock.json +3102 -0
  40. package/references/acp-factory-ref/package.json +96 -0
  41. package/references/acp-factory-ref/python/CHANGELOG.md +33 -0
  42. package/references/acp-factory-ref/python/LICENSE +21 -0
  43. package/references/acp-factory-ref/python/Makefile +57 -0
  44. package/references/acp-factory-ref/python/README.md +253 -0
  45. package/references/acp-factory-ref/python/pyproject.toml +73 -0
  46. package/references/acp-factory-ref/python/tests/__init__.py +0 -0
  47. package/references/acp-factory-ref/python/tests/e2e/__init__.py +1 -0
  48. package/references/acp-factory-ref/python/tests/e2e/test_codex_e2e.py +349 -0
  49. package/references/acp-factory-ref/python/tests/e2e/test_gemini_e2e.py +165 -0
  50. package/references/acp-factory-ref/python/tests/e2e/test_opencode_e2e.py +296 -0
  51. package/references/acp-factory-ref/python/tests/test_client_handler.py +543 -0
  52. package/references/acp-factory-ref/python/tests/test_pushable.py +199 -0
  53. package/references/claude-code-acp/.github/workflows/ci.yml +45 -0
  54. package/references/claude-code-acp/.github/workflows/publish.yml +34 -0
  55. package/references/claude-code-acp/.prettierrc.json +4 -0
  56. package/references/claude-code-acp/CHANGELOG.md +249 -0
  57. package/references/claude-code-acp/LICENSE +222 -0
  58. package/references/claude-code-acp/README.md +53 -0
  59. package/references/claude-code-acp/docs/RELEASES.md +24 -0
  60. package/references/claude-code-acp/eslint.config.js +48 -0
  61. package/references/claude-code-acp/package-lock.json +4570 -0
  62. package/references/claude-code-acp/package.json +88 -0
  63. package/references/claude-code-acp/scripts/release.sh +119 -0
  64. package/references/claude-code-acp/src/acp-agent.ts +2079 -0
  65. package/references/claude-code-acp/src/index.ts +26 -0
  66. package/references/claude-code-acp/src/lib.ts +38 -0
  67. package/references/claude-code-acp/src/mcp-server.ts +911 -0
  68. package/references/claude-code-acp/src/settings.ts +522 -0
  69. package/references/claude-code-acp/src/tests/.claude/commands/quick-math.md +5 -0
  70. package/references/claude-code-acp/src/tests/.claude/commands/say-hello.md +6 -0
  71. package/references/claude-code-acp/src/tests/acp-agent-fork.test.ts +479 -0
  72. package/references/claude-code-acp/src/tests/acp-agent.test.ts +1502 -0
  73. package/references/claude-code-acp/src/tests/extract-lines.test.ts +103 -0
  74. package/references/claude-code-acp/src/tests/fork-session.test.ts +335 -0
  75. package/references/claude-code-acp/src/tests/replace-and-calculate-location.test.ts +334 -0
  76. package/references/claude-code-acp/src/tests/settings.test.ts +617 -0
  77. package/references/claude-code-acp/src/tests/skills-options.test.ts +187 -0
  78. package/references/claude-code-acp/src/tests/tools.test.ts +318 -0
  79. package/references/claude-code-acp/src/tests/typescript-declarations.test.ts +558 -0
  80. package/references/claude-code-acp/src/tools.ts +819 -0
  81. package/references/claude-code-acp/src/utils.ts +171 -0
  82. package/references/claude-code-acp/tsconfig.json +18 -0
  83. package/references/claude-code-acp/vitest.config.ts +19 -0
  84. package/references/multi-agent-protocol/.sudocode/issues.jsonl +111 -0
  85. package/references/multi-agent-protocol/.sudocode/specs.jsonl +13 -0
  86. package/references/multi-agent-protocol/LICENSE +21 -0
  87. package/references/multi-agent-protocol/README.md +113 -0
  88. package/references/multi-agent-protocol/docs/00-design-specification.md +496 -0
  89. package/references/multi-agent-protocol/docs/01-open-questions.md +1050 -0
  90. package/references/multi-agent-protocol/docs/02-wire-protocol.md +296 -0
  91. package/references/multi-agent-protocol/docs/03-streaming-semantics.md +252 -0
  92. package/references/multi-agent-protocol/docs/04-error-handling.md +231 -0
  93. package/references/multi-agent-protocol/docs/05-connection-model.md +244 -0
  94. package/references/multi-agent-protocol/docs/06-visibility-permissions.md +243 -0
  95. package/references/multi-agent-protocol/docs/07-federation.md +259 -0
  96. package/references/multi-agent-protocol/docs/08-macro-agent-migration.md +253 -0
  97. package/references/multi-agent-protocol/docs/09-authentication.md +680 -0
  98. package/references/multi-agent-protocol/docs/10-mail-protocol.md +553 -0
  99. package/references/multi-agent-protocol/docs/agent-iam-integration.md +877 -0
  100. package/references/multi-agent-protocol/docs/agentic-mesh-integration-draft.md +459 -0
  101. package/references/multi-agent-protocol/docs/git-transport-draft.md +251 -0
  102. package/references/multi-agent-protocol/docs-site/Gemfile +22 -0
  103. package/references/multi-agent-protocol/docs-site/README.md +82 -0
  104. package/references/multi-agent-protocol/docs-site/_config.yml +91 -0
  105. package/references/multi-agent-protocol/docs-site/_includes/head_custom.html +20 -0
  106. package/references/multi-agent-protocol/docs-site/_sass/color_schemes/map.scss +42 -0
  107. package/references/multi-agent-protocol/docs-site/_sass/custom/custom.scss +34 -0
  108. package/references/multi-agent-protocol/docs-site/examples/full-integration.md +510 -0
  109. package/references/multi-agent-protocol/docs-site/examples/index.md +138 -0
  110. package/references/multi-agent-protocol/docs-site/examples/simple-chat.md +282 -0
  111. package/references/multi-agent-protocol/docs-site/examples/task-queue.md +399 -0
  112. package/references/multi-agent-protocol/docs-site/getting-started/index.md +98 -0
  113. package/references/multi-agent-protocol/docs-site/getting-started/installation.md +219 -0
  114. package/references/multi-agent-protocol/docs-site/getting-started/overview.md +172 -0
  115. package/references/multi-agent-protocol/docs-site/getting-started/quickstart.md +237 -0
  116. package/references/multi-agent-protocol/docs-site/index.md +136 -0
  117. package/references/multi-agent-protocol/docs-site/protocol/authentication.md +391 -0
  118. package/references/multi-agent-protocol/docs-site/protocol/connection-model.md +376 -0
  119. package/references/multi-agent-protocol/docs-site/protocol/design.md +284 -0
  120. package/references/multi-agent-protocol/docs-site/protocol/error-handling.md +312 -0
  121. package/references/multi-agent-protocol/docs-site/protocol/federation.md +449 -0
  122. package/references/multi-agent-protocol/docs-site/protocol/index.md +129 -0
  123. package/references/multi-agent-protocol/docs-site/protocol/permissions.md +398 -0
  124. package/references/multi-agent-protocol/docs-site/protocol/streaming.md +353 -0
  125. package/references/multi-agent-protocol/docs-site/protocol/wire-protocol.md +369 -0
  126. package/references/multi-agent-protocol/docs-site/sdk/api/agent.md +357 -0
  127. package/references/multi-agent-protocol/docs-site/sdk/api/client.md +380 -0
  128. package/references/multi-agent-protocol/docs-site/sdk/api/index.md +62 -0
  129. package/references/multi-agent-protocol/docs-site/sdk/api/server.md +453 -0
  130. package/references/multi-agent-protocol/docs-site/sdk/api/types.md +468 -0
  131. package/references/multi-agent-protocol/docs-site/sdk/guides/agent.md +375 -0
  132. package/references/multi-agent-protocol/docs-site/sdk/guides/authentication.md +405 -0
  133. package/references/multi-agent-protocol/docs-site/sdk/guides/client.md +352 -0
  134. package/references/multi-agent-protocol/docs-site/sdk/guides/index.md +89 -0
  135. package/references/multi-agent-protocol/docs-site/sdk/guides/server.md +360 -0
  136. package/references/multi-agent-protocol/docs-site/sdk/guides/testing.md +446 -0
  137. package/references/multi-agent-protocol/docs-site/sdk/guides/transports.md +363 -0
  138. package/references/multi-agent-protocol/docs-site/sdk/index.md +206 -0
  139. package/references/multi-agent-protocol/package-lock.json +3886 -0
  140. package/references/multi-agent-protocol/package.json +56 -0
  141. package/references/multi-agent-protocol/schema/meta.json +467 -0
  142. package/references/multi-agent-protocol/schema/schema.json +2558 -0
  143. package/src/acp/__tests__/history.test.ts +526 -0
  144. package/src/acp/__tests__/integration.test.ts +2 -1
  145. package/src/acp/index.ts +4 -0
  146. package/src/acp/macro-agent.ts +329 -85
  147. package/src/acp/types.ts +39 -2
  148. package/src/agent/__tests__/agent-manager.test.ts +67 -1
  149. package/src/agent/agent-manager.ts +10 -4
  150. package/src/cli/__tests__/stable-instance-id.test.ts +57 -0
  151. package/src/cli/acp.ts +17 -2
  152. package/src/map/adapter/acp-over-map.ts +57 -2
  153. package/src/store/event-store.ts +10 -3
  154. package/src/store/types/agents.ts +2 -0
@@ -0,0 +1,357 @@
1
+ ---
2
+ title: Agent API
3
+ parent: API Reference
4
+ grand_parent: SDK
5
+ nav_order: 3
6
+ description: "AgentConnection methods and properties"
7
+ ---
8
+
9
+ # Agent API
10
+ {: .no_toc }
11
+
12
+ AgentConnection class for building MAP agents.
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
+ ## AgentConnection
24
+
25
+ ### Constructor
26
+
27
+ ```typescript
28
+ const agent = new AgentConnection(stream: Stream, options: AgentOptions);
29
+
30
+ interface AgentOptions {
31
+ name: string;
32
+ role?: string;
33
+ metadata?: Record<string, unknown>;
34
+ auth?: AuthCredentials;
35
+ reconnect?: ReconnectOptions;
36
+ }
37
+ ```
38
+
39
+ ---
40
+
41
+ ## Properties
42
+
43
+ | Property | Type | Description |
44
+ |:---------|:-----|:------------|
45
+ | `state` | `ConnectionState` | Current connection state |
46
+ | `id` | `string \| undefined` | Registered agent ID |
47
+ | `sessionId` | `string \| undefined` | Current session ID |
48
+ | `resumeToken` | `string \| undefined` | Token for session resume |
49
+
50
+ ---
51
+
52
+ ## Connection Methods
53
+
54
+ ### connect()
55
+
56
+ Connect and register the agent:
57
+
58
+ ```typescript
59
+ const result = await agent.connect(options?: ConnectOptions): Promise<AgentConnectResult>;
60
+
61
+ interface ConnectOptions {
62
+ resumeToken?: string;
63
+ }
64
+
65
+ interface AgentConnectResult {
66
+ agent: RegisteredAgent;
67
+ connection: {
68
+ sessionId: string;
69
+ resumed: boolean;
70
+ };
71
+ }
72
+ ```
73
+
74
+ ### disconnect()
75
+
76
+ Gracefully disconnect and unregister:
77
+
78
+ ```typescript
79
+ await agent.disconnect(): Promise<void>;
80
+ ```
81
+
82
+ ---
83
+
84
+ ## Message Handling
85
+
86
+ ### onMessage()
87
+
88
+ Register a message handler:
89
+
90
+ ```typescript
91
+ agent.onMessage(handler: MessageHandler): void;
92
+
93
+ type MessageHandler = (message: IncomingMessage) => void | Promise<void>;
94
+
95
+ interface IncomingMessage {
96
+ id: string;
97
+ from: string;
98
+ payload: unknown;
99
+ meta?: MessageMeta;
100
+ timestamp: number;
101
+ }
102
+ ```
103
+
104
+ Multiple handlers can be registered and are called in order:
105
+
106
+ ```typescript
107
+ agent.onMessage((message) => {
108
+ console.log(`Received: ${message.id}`);
109
+ });
110
+
111
+ agent.onMessage(async (message) => {
112
+ if (message.payload.type === "task") {
113
+ await processTask(message.payload);
114
+ }
115
+ });
116
+ ```
117
+
118
+ ---
119
+
120
+ ## Messaging Methods
121
+
122
+ ### send()
123
+
124
+ Send a message to another agent or scope:
125
+
126
+ ```typescript
127
+ const result = await agent.send(params: SendParams): Promise<SendResult>;
128
+
129
+ interface SendParams {
130
+ to: Address;
131
+ payload: unknown;
132
+ meta?: {
133
+ priority?: "low" | "normal" | "high" | "urgent";
134
+ ttl?: number;
135
+ requireAck?: boolean;
136
+ };
137
+ }
138
+
139
+ type Address =
140
+ | { agentId: string }
141
+ | { scopeId: string }
142
+ | { role: string }
143
+ | { parent: true }
144
+ | { children: true };
145
+
146
+ interface SendResult {
147
+ messageId: string;
148
+ delivered: number;
149
+ }
150
+ ```
151
+
152
+ ---
153
+
154
+ ## Agent State Methods
155
+
156
+ ### update()
157
+
158
+ Update agent state or metadata:
159
+
160
+ ```typescript
161
+ await agent.update(updates: AgentUpdates): Promise<RegisteredAgent>;
162
+
163
+ interface AgentUpdates {
164
+ state?: "running" | "busy" | "suspended";
165
+ metadata?: Record<string, unknown>;
166
+ }
167
+ ```
168
+
169
+ ---
170
+
171
+ ## Scope Methods
172
+
173
+ ### createScope()
174
+
175
+ Create a new scope:
176
+
177
+ ```typescript
178
+ const scope = await agent.createScope(params: CreateScopeParams): Promise<Scope>;
179
+
180
+ interface CreateScopeParams {
181
+ name: string;
182
+ parentId?: string;
183
+ metadata?: Record<string, unknown>;
184
+ }
185
+ ```
186
+
187
+ ### joinScope()
188
+
189
+ Join an existing scope:
190
+
191
+ ```typescript
192
+ await agent.joinScope(scopeId: string): Promise<void>;
193
+ ```
194
+
195
+ ### leaveScope()
196
+
197
+ Leave a scope:
198
+
199
+ ```typescript
200
+ await agent.leaveScope(scopeId: string): Promise<void>;
201
+ ```
202
+
203
+ ### listScopes()
204
+
205
+ List available scopes:
206
+
207
+ ```typescript
208
+ const { scopes } = await agent.listScopes(): Promise<ListScopesResult>;
209
+ ```
210
+
211
+ ---
212
+
213
+ ## Query Methods
214
+
215
+ ### listAgents()
216
+
217
+ List other agents:
218
+
219
+ ```typescript
220
+ const { agents } = await agent.listAgents(filter?: AgentFilter): Promise<ListAgentsResult>;
221
+
222
+ interface AgentFilter {
223
+ role?: string;
224
+ state?: string;
225
+ scopeId?: string;
226
+ }
227
+ ```
228
+
229
+ ### getAgent()
230
+
231
+ Get details for a specific agent:
232
+
233
+ ```typescript
234
+ const { agent: otherAgent } = await agent.getAgent(agentId: string): Promise<GetAgentResult>;
235
+ ```
236
+
237
+ ---
238
+
239
+ ## Subscription Methods
240
+
241
+ ### subscribe()
242
+
243
+ Subscribe to system events:
244
+
245
+ ```typescript
246
+ const subscription = await agent.subscribe(params: SubscribeParams): Promise<Subscription>;
247
+
248
+ interface SubscribeParams {
249
+ eventTypes: string[];
250
+ scopeIds?: string[];
251
+ }
252
+ ```
253
+
254
+ ---
255
+
256
+ ## State Management
257
+
258
+ ### onStateChange()
259
+
260
+ Listen for connection state changes:
261
+
262
+ ```typescript
263
+ agent.onStateChange(handler: (state: ConnectionState) => void): void;
264
+ ```
265
+
266
+ ---
267
+
268
+ ## Event Handlers
269
+
270
+ ### onError()
271
+
272
+ Handle errors:
273
+
274
+ ```typescript
275
+ agent.onError(handler: (error: Error) => void): void;
276
+ ```
277
+
278
+ ### onReconnecting()
279
+
280
+ Handle reconnection attempts:
281
+
282
+ ```typescript
283
+ agent.onReconnecting(handler: (attempt: number) => void): void;
284
+ ```
285
+
286
+ ### onReconnected()
287
+
288
+ Handle successful reconnection:
289
+
290
+ ```typescript
291
+ agent.onReconnected(handler: () => void): void;
292
+ ```
293
+
294
+ ---
295
+
296
+ ## Types
297
+
298
+ ### RegisteredAgent
299
+
300
+ ```typescript
301
+ interface RegisteredAgent {
302
+ id: string;
303
+ name: string;
304
+ role?: string;
305
+ state: AgentState;
306
+ parentId?: string;
307
+ scopeIds: string[];
308
+ metadata?: Record<string, unknown>;
309
+ registeredAt: number;
310
+ }
311
+
312
+ type AgentState = "registered" | "running" | "busy" | "suspended" | "stopped";
313
+ ```
314
+
315
+ ---
316
+
317
+ ## Example
318
+
319
+ ```typescript
320
+ import { AgentConnection } from "@multi-agent-protocol/sdk";
321
+
322
+ const agent = new AgentConnection(stream, {
323
+ name: "TaskProcessor",
324
+ role: "worker",
325
+ metadata: {
326
+ capabilities: ["text-analysis"],
327
+ },
328
+ reconnect: { enabled: true },
329
+ });
330
+
331
+ // Connect and register
332
+ const { agent: registered } = await agent.connect();
333
+ console.log(`Registered as ${registered.id}`);
334
+
335
+ // Join a scope
336
+ await agent.joinScope("task-queue");
337
+
338
+ // Handle messages
339
+ agent.onMessage(async (message) => {
340
+ console.log(`Received task from ${message.from}`);
341
+
342
+ await agent.update({ state: "busy" });
343
+
344
+ try {
345
+ const result = await processTask(message.payload);
346
+
347
+ await agent.send({
348
+ to: { agentId: message.from },
349
+ payload: { type: "result", data: result },
350
+ });
351
+ } finally {
352
+ await agent.update({ state: "running" });
353
+ }
354
+ });
355
+
356
+ console.log("Ready to process tasks");
357
+ ```
@@ -0,0 +1,380 @@
1
+ ---
2
+ title: Client API
3
+ parent: API Reference
4
+ grand_parent: SDK
5
+ nav_order: 2
6
+ description: "ClientConnection methods and properties"
7
+ ---
8
+
9
+ # Client API
10
+ {: .no_toc }
11
+
12
+ ClientConnection class for observing MAP systems.
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
+ ## ClientConnection
24
+
25
+ ### Constructor
26
+
27
+ ```typescript
28
+ const client = new ClientConnection(stream: Stream, options: ClientOptions);
29
+
30
+ interface ClientOptions {
31
+ name: string;
32
+ auth?: AuthCredentials;
33
+ reconnect?: ReconnectOptions;
34
+ }
35
+
36
+ interface AuthCredentials {
37
+ method: "bearer" | "api-key" | "none";
38
+ credential?: string;
39
+ }
40
+
41
+ interface ReconnectOptions {
42
+ enabled: boolean;
43
+ maxAttempts?: number; // Default: 5
44
+ baseDelayMs?: number; // Default: 1000
45
+ maxDelayMs?: number; // Default: 30000
46
+ }
47
+ ```
48
+
49
+ ---
50
+
51
+ ## Properties
52
+
53
+ | Property | Type | Description |
54
+ |:---------|:-----|:------------|
55
+ | `state` | `ConnectionState` | Current connection state |
56
+ | `sessionId` | `string \| undefined` | Current session ID |
57
+ | `resumeToken` | `string \| undefined` | Token for session resume |
58
+
59
+ ```typescript
60
+ type ConnectionState = "initial" | "connecting" | "connected" | "reconnecting" | "closed";
61
+ ```
62
+
63
+ ---
64
+
65
+ ## Connection Methods
66
+
67
+ ### connect()
68
+
69
+ Establish connection to the server:
70
+
71
+ ```typescript
72
+ const result = await client.connect(options?: ConnectOptions): Promise<ConnectResult>;
73
+
74
+ interface ConnectOptions {
75
+ resumeToken?: string; // Resume previous session
76
+ }
77
+
78
+ interface ConnectResult {
79
+ sessionId: string;
80
+ participantId: string;
81
+ systemInfo?: {
82
+ name: string;
83
+ version: string;
84
+ };
85
+ serverCapabilities: ServerCapabilities;
86
+ principal?: Principal;
87
+ resumed?: boolean;
88
+ }
89
+ ```
90
+
91
+ ### disconnect()
92
+
93
+ Gracefully disconnect:
94
+
95
+ ```typescript
96
+ await client.disconnect(): Promise<void>;
97
+ ```
98
+
99
+ ### updateAuth()
100
+
101
+ Update authentication credentials:
102
+
103
+ ```typescript
104
+ client.updateAuth(credentials: AuthCredentials): void;
105
+ ```
106
+
107
+ ---
108
+
109
+ ## Query Methods
110
+
111
+ ### listAgents()
112
+
113
+ List registered agents:
114
+
115
+ ```typescript
116
+ const { agents } = await client.listAgents(filter?: AgentFilter): Promise<ListAgentsResult>;
117
+
118
+ interface AgentFilter {
119
+ role?: string;
120
+ state?: string;
121
+ scopeId?: string;
122
+ }
123
+
124
+ interface ListAgentsResult {
125
+ agents: Agent[];
126
+ }
127
+ ```
128
+
129
+ ### getAgent()
130
+
131
+ Get a specific agent:
132
+
133
+ ```typescript
134
+ const { agent } = await client.getAgent(agentId: string): Promise<GetAgentResult>;
135
+
136
+ interface GetAgentResult {
137
+ agent: Agent | null;
138
+ }
139
+ ```
140
+
141
+ ### listScopes()
142
+
143
+ List available scopes:
144
+
145
+ ```typescript
146
+ const { scopes } = await client.listScopes(filter?: ScopeFilter): Promise<ListScopesResult>;
147
+
148
+ interface ListScopesResult {
149
+ scopes: Scope[];
150
+ }
151
+ ```
152
+
153
+ ### getScope()
154
+
155
+ Get a specific scope:
156
+
157
+ ```typescript
158
+ const { scope } = await client.getScope(scopeId: string): Promise<GetScopeResult>;
159
+
160
+ interface GetScopeResult {
161
+ scope: Scope | null;
162
+ }
163
+ ```
164
+
165
+ ---
166
+
167
+ ## Subscription Methods
168
+
169
+ ### subscribe()
170
+
171
+ Subscribe to events:
172
+
173
+ ```typescript
174
+ const subscription = await client.subscribe(params: SubscribeParams): Promise<Subscription>;
175
+
176
+ interface SubscribeParams {
177
+ eventTypes: string[]; // e.g., ["agent.*", "message.sent"]
178
+ scopeIds?: string[]; // Filter by scopes
179
+ options?: {
180
+ bufferSize?: number;
181
+ overflowStrategy?: "drop" | "error" | "block";
182
+ };
183
+ }
184
+ ```
185
+
186
+ ### Subscription Object
187
+
188
+ ```typescript
189
+ interface Subscription {
190
+ id: string;
191
+
192
+ // Async iterator for events
193
+ [Symbol.asyncIterator](): AsyncIterator<Event>;
194
+
195
+ // Control methods
196
+ pause(): Promise<void>;
197
+ resume(): Promise<void>;
198
+ unsubscribe(): Promise<void>;
199
+
200
+ // Backpressure
201
+ ack(eventId: string): Promise<void>;
202
+ }
203
+
204
+ // Usage
205
+ for await (const event of subscription) {
206
+ console.log(event.type, event.data);
207
+ }
208
+ ```
209
+
210
+ ---
211
+
212
+ ## Messaging Methods
213
+
214
+ ### send()
215
+
216
+ Send a message:
217
+
218
+ ```typescript
219
+ const result = await client.send(params: SendParams): Promise<SendResult>;
220
+
221
+ interface SendParams {
222
+ to: Address;
223
+ payload: unknown;
224
+ meta?: {
225
+ priority?: "low" | "normal" | "high" | "urgent";
226
+ ttl?: number;
227
+ requireAck?: boolean;
228
+ };
229
+ }
230
+
231
+ type Address =
232
+ | { agentId: string }
233
+ | { scopeId: string }
234
+ | { role: string };
235
+
236
+ interface SendResult {
237
+ messageId: string;
238
+ delivered: number;
239
+ }
240
+ ```
241
+
242
+ ---
243
+
244
+ ## Replay Methods
245
+
246
+ ### replay()
247
+
248
+ Replay missed events:
249
+
250
+ ```typescript
251
+ const events = await client.replay(params: ReplayParams): Promise<Event[]>;
252
+
253
+ interface ReplayParams {
254
+ afterEventId?: string;
255
+ fromTimestamp?: number;
256
+ toTimestamp?: number;
257
+ eventTypes?: string[];
258
+ limit?: number;
259
+ }
260
+ ```
261
+
262
+ ---
263
+
264
+ ## State Management
265
+
266
+ ### onStateChange()
267
+
268
+ Listen for connection state changes:
269
+
270
+ ```typescript
271
+ client.onStateChange(handler: (state: ConnectionState) => void): void;
272
+ ```
273
+
274
+ ### Current State
275
+
276
+ ```typescript
277
+ if (client.state === "connected") {
278
+ // Safe to make requests
279
+ }
280
+ ```
281
+
282
+ ---
283
+
284
+ ## Event Handlers
285
+
286
+ ### onError()
287
+
288
+ Handle connection errors:
289
+
290
+ ```typescript
291
+ client.onError(handler: (error: Error) => void): void;
292
+ ```
293
+
294
+ ### onReconnecting()
295
+
296
+ Handle reconnection attempts:
297
+
298
+ ```typescript
299
+ client.onReconnecting(handler: (attempt: number) => void): void;
300
+ ```
301
+
302
+ ### onReconnected()
303
+
304
+ Handle successful reconnection:
305
+
306
+ ```typescript
307
+ client.onReconnected(handler: () => void): void;
308
+ ```
309
+
310
+ ---
311
+
312
+ ## Types
313
+
314
+ ### Agent
315
+
316
+ ```typescript
317
+ interface Agent {
318
+ id: string;
319
+ name: string;
320
+ role?: string;
321
+ state: string;
322
+ parentId?: string;
323
+ scopeIds: string[];
324
+ metadata?: Record<string, unknown>;
325
+ }
326
+ ```
327
+
328
+ ### Scope
329
+
330
+ ```typescript
331
+ interface Scope {
332
+ id: string;
333
+ name: string;
334
+ parentId?: string;
335
+ metadata?: Record<string, unknown>;
336
+ }
337
+ ```
338
+
339
+ ### Event
340
+
341
+ ```typescript
342
+ interface Event {
343
+ id: string;
344
+ type: string;
345
+ data: unknown;
346
+ timestamp: number;
347
+ agentId?: string;
348
+ scopeId?: string;
349
+ }
350
+ ```
351
+
352
+ ---
353
+
354
+ ## Example
355
+
356
+ ```typescript
357
+ import { ClientConnection } from "@multi-agent-protocol/sdk";
358
+
359
+ const client = new ClientConnection(stream, {
360
+ name: "Dashboard",
361
+ reconnect: { enabled: true },
362
+ });
363
+
364
+ // Connect
365
+ const { sessionId, systemInfo } = await client.connect();
366
+ console.log(`Connected to ${systemInfo?.name}`);
367
+
368
+ // Query agents
369
+ const { agents } = await client.listAgents({ role: "worker" });
370
+ console.log(`Found ${agents.length} workers`);
371
+
372
+ // Subscribe to events
373
+ const subscription = await client.subscribe({
374
+ eventTypes: ["agent.*"],
375
+ });
376
+
377
+ for await (const event of subscription) {
378
+ console.log(`${event.type}: ${JSON.stringify(event.data)}`);
379
+ }
380
+ ```