@multi-agent-protocol/sdk 0.0.2
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/README.md +248 -0
- package/dist/index-C7XPWnxS.d.cts +3052 -0
- package/dist/index-C7XPWnxS.d.ts +3052 -0
- package/dist/index.cjs +4528 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2288 -0
- package/dist/index.d.ts +2288 -0
- package/dist/index.js +4353 -0
- package/dist/index.js.map +1 -0
- package/dist/testing.cjs +4004 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +367 -0
- package/dist/testing.d.ts +367 -0
- package/dist/testing.js +4000 -0
- package/dist/testing.js.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import { P as ParticipantCapabilities, dy as SystemExposure, d as FederationRoutingConfig, S as Stream, aC as BaseConnection, f as SessionId, A as AgentId, m as Agent, l as ScopeId, n as Scope, c as Message, q as Event, j as ParticipantId, L as SubscriptionId, aI as ClientConnectionOptions, aH as ClientConnection, ae as AgentsListRequestParams, ct as ScopesListRequestParams, p as SubscriptionFilter, cR as Subscription, e as EventType, Y as AgentConnectionOptions, X as AgentConnection } from './index-C7XPWnxS.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Test MAP Server Implementation
|
|
5
|
+
*
|
|
6
|
+
* A simple in-memory MAP server for testing purposes.
|
|
7
|
+
* Implements the core MAP protocol methods.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Options for test server
|
|
12
|
+
*/
|
|
13
|
+
interface TestServerOptions {
|
|
14
|
+
name?: string;
|
|
15
|
+
version?: string;
|
|
16
|
+
capabilities?: ParticipantCapabilities;
|
|
17
|
+
/** Maximum number of events to retain for replay. Default: 10000 */
|
|
18
|
+
maxEventHistory?: number;
|
|
19
|
+
/** System exposure configuration for permission filtering */
|
|
20
|
+
exposure?: SystemExposure;
|
|
21
|
+
/** Federation routing configuration for envelope validation */
|
|
22
|
+
federationRouting?: FederationRoutingConfig;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Stored event for replay capability
|
|
26
|
+
*/
|
|
27
|
+
interface StoredEvent {
|
|
28
|
+
eventId: string;
|
|
29
|
+
timestamp: number;
|
|
30
|
+
event: Event;
|
|
31
|
+
/** Event IDs that caused this event */
|
|
32
|
+
causedBy?: string[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Test MAP Server
|
|
36
|
+
*
|
|
37
|
+
* Provides a fully functional MAP server for integration testing.
|
|
38
|
+
*/
|
|
39
|
+
declare class TestServer {
|
|
40
|
+
#private;
|
|
41
|
+
constructor(options?: TestServerOptions);
|
|
42
|
+
/**
|
|
43
|
+
* Accept a new connection
|
|
44
|
+
*/
|
|
45
|
+
acceptConnection(stream: Stream): BaseConnection;
|
|
46
|
+
/**
|
|
47
|
+
* Get current session ID
|
|
48
|
+
*/
|
|
49
|
+
get sessionId(): SessionId;
|
|
50
|
+
/**
|
|
51
|
+
* Get all registered agents
|
|
52
|
+
*/
|
|
53
|
+
get agents(): ReadonlyMap<AgentId, Agent>;
|
|
54
|
+
/**
|
|
55
|
+
* Get all scopes
|
|
56
|
+
*/
|
|
57
|
+
get scopes(): ReadonlyMap<ScopeId, Scope>;
|
|
58
|
+
/**
|
|
59
|
+
* Get all messages sent through the server
|
|
60
|
+
*/
|
|
61
|
+
get messages(): readonly Message[];
|
|
62
|
+
/**
|
|
63
|
+
* Get connected participant count
|
|
64
|
+
*/
|
|
65
|
+
get participantCount(): number;
|
|
66
|
+
/**
|
|
67
|
+
* Get event history for replay testing
|
|
68
|
+
*/
|
|
69
|
+
get eventHistory(): readonly StoredEvent[];
|
|
70
|
+
/**
|
|
71
|
+
* Emit an event to subscribers
|
|
72
|
+
* @param event - The event to emit (without id/timestamp)
|
|
73
|
+
* @param causedBy - Optional array of event IDs that caused this event
|
|
74
|
+
* @returns The generated event ID
|
|
75
|
+
*/
|
|
76
|
+
emitEvent(event: Omit<Event, 'id' | 'timestamp'>, causedBy?: string[]): string;
|
|
77
|
+
/**
|
|
78
|
+
* Deliver a message notification to a participant
|
|
79
|
+
*/
|
|
80
|
+
deliverMessage(participantId: ParticipantId, message: Message): void;
|
|
81
|
+
/**
|
|
82
|
+
* Get ack state for a subscription (for testing assertions)
|
|
83
|
+
*/
|
|
84
|
+
getSubscriptionAckState(subscriptionId: SubscriptionId): {
|
|
85
|
+
sequenceNumber: number;
|
|
86
|
+
lastAckedSequence?: number;
|
|
87
|
+
} | undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Test Client Helper
|
|
92
|
+
*
|
|
93
|
+
* Provides a convenient wrapper around ClientConnection for testing.
|
|
94
|
+
* Automatically manages stream pairs and connection lifecycle.
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Options for TestClient
|
|
99
|
+
*/
|
|
100
|
+
interface TestClientOptions extends ClientConnectionOptions {
|
|
101
|
+
/** Auto-connect on creation */
|
|
102
|
+
autoConnect?: boolean;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Test client for integration testing.
|
|
106
|
+
*
|
|
107
|
+
* Wraps ClientConnection with convenience methods and automatic
|
|
108
|
+
* stream management for easier testing.
|
|
109
|
+
*/
|
|
110
|
+
declare class TestClient {
|
|
111
|
+
#private;
|
|
112
|
+
private constructor();
|
|
113
|
+
/**
|
|
114
|
+
* Create and connect a test client
|
|
115
|
+
*/
|
|
116
|
+
static create(server: TestServer, options?: TestClientOptions): Promise<TestClient>;
|
|
117
|
+
/**
|
|
118
|
+
* Get the underlying connection
|
|
119
|
+
*/
|
|
120
|
+
get connection(): ClientConnection;
|
|
121
|
+
/**
|
|
122
|
+
* Whether the client is connected
|
|
123
|
+
*/
|
|
124
|
+
get isConnected(): boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Current session ID
|
|
127
|
+
*/
|
|
128
|
+
get sessionId(): string | null;
|
|
129
|
+
/**
|
|
130
|
+
* Connect to the server
|
|
131
|
+
*/
|
|
132
|
+
connect(): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Disconnect from the server
|
|
135
|
+
*/
|
|
136
|
+
disconnect(): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* List all agents
|
|
139
|
+
*/
|
|
140
|
+
listAgents(options?: AgentsListRequestParams): Promise<Agent[]>;
|
|
141
|
+
/**
|
|
142
|
+
* Get agent by ID with optional hierarchy expansion
|
|
143
|
+
*/
|
|
144
|
+
getAgent(agentId: string, options?: {
|
|
145
|
+
include?: {
|
|
146
|
+
children?: boolean;
|
|
147
|
+
descendants?: boolean;
|
|
148
|
+
};
|
|
149
|
+
}): Promise<{
|
|
150
|
+
agent: Agent;
|
|
151
|
+
children?: Agent[];
|
|
152
|
+
descendants?: Agent[];
|
|
153
|
+
}>;
|
|
154
|
+
/**
|
|
155
|
+
* Find agent by name
|
|
156
|
+
*/
|
|
157
|
+
findAgentByName(name: string): Promise<Agent | undefined>;
|
|
158
|
+
/**
|
|
159
|
+
* Find agents by role
|
|
160
|
+
*/
|
|
161
|
+
findAgentsByRole(role: string): Promise<Agent[]>;
|
|
162
|
+
/**
|
|
163
|
+
* List all scopes
|
|
164
|
+
*/
|
|
165
|
+
listScopes(options?: ScopesListRequestParams): Promise<Scope[]>;
|
|
166
|
+
/**
|
|
167
|
+
* Get scope by ID
|
|
168
|
+
*/
|
|
169
|
+
getScope(scopeId: string): Promise<Scope>;
|
|
170
|
+
/**
|
|
171
|
+
* Send message to agent
|
|
172
|
+
*/
|
|
173
|
+
sendTo(agentId: string, payload: unknown): Promise<string>;
|
|
174
|
+
/**
|
|
175
|
+
* Broadcast to all agents
|
|
176
|
+
*/
|
|
177
|
+
broadcast(payload: unknown): Promise<string>;
|
|
178
|
+
/**
|
|
179
|
+
* Send to all agents with a specific role
|
|
180
|
+
*/
|
|
181
|
+
sendToRole(role: string, payload: unknown): Promise<string>;
|
|
182
|
+
/**
|
|
183
|
+
* Send to all agents in a scope
|
|
184
|
+
*/
|
|
185
|
+
sendToScope(scopeId: string, payload: unknown): Promise<string>;
|
|
186
|
+
/**
|
|
187
|
+
* Subscribe to events with automatic tracking
|
|
188
|
+
*/
|
|
189
|
+
subscribe(filter?: SubscriptionFilter): Promise<Subscription>;
|
|
190
|
+
/**
|
|
191
|
+
* Collect events matching filter for a duration
|
|
192
|
+
*/
|
|
193
|
+
collectEvents(filter: SubscriptionFilter, durationMs: number): Promise<Event[]>;
|
|
194
|
+
/**
|
|
195
|
+
* Wait for a specific event type
|
|
196
|
+
*/
|
|
197
|
+
waitForEvent(eventType: EventType, timeoutMs?: number): Promise<Event>;
|
|
198
|
+
/**
|
|
199
|
+
* Stop an agent
|
|
200
|
+
*/
|
|
201
|
+
stopAgent(agentId: string, reason?: string): Promise<void>;
|
|
202
|
+
/**
|
|
203
|
+
* Inject context into an agent
|
|
204
|
+
*/
|
|
205
|
+
inject(agentId: string, content: unknown, delivery?: 'interrupt' | 'queue' | 'best-effort'): Promise<void>;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Test Agent Helper
|
|
210
|
+
*
|
|
211
|
+
* Provides a convenient wrapper around AgentConnection for testing.
|
|
212
|
+
* Automatically manages stream pairs and connection lifecycle.
|
|
213
|
+
*/
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Options for TestAgent
|
|
217
|
+
*/
|
|
218
|
+
interface TestAgentOptions extends AgentConnectionOptions {
|
|
219
|
+
/** Auto-connect on creation */
|
|
220
|
+
autoConnect?: boolean;
|
|
221
|
+
/** Pre-assigned agent ID */
|
|
222
|
+
agentId?: AgentId;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Test agent for integration testing.
|
|
226
|
+
*
|
|
227
|
+
* Wraps AgentConnection with convenience methods and automatic
|
|
228
|
+
* stream management for easier testing.
|
|
229
|
+
*/
|
|
230
|
+
declare class TestAgent {
|
|
231
|
+
#private;
|
|
232
|
+
private constructor();
|
|
233
|
+
/**
|
|
234
|
+
* Create and connect a test agent
|
|
235
|
+
*/
|
|
236
|
+
static create(server: TestServer, options?: TestAgentOptions): Promise<TestAgent>;
|
|
237
|
+
/**
|
|
238
|
+
* Get the underlying connection
|
|
239
|
+
*/
|
|
240
|
+
get connection(): AgentConnection;
|
|
241
|
+
/**
|
|
242
|
+
* Whether the agent is connected
|
|
243
|
+
*/
|
|
244
|
+
get isConnected(): boolean;
|
|
245
|
+
/**
|
|
246
|
+
* Agent ID
|
|
247
|
+
*/
|
|
248
|
+
get id(): AgentId | null;
|
|
249
|
+
/**
|
|
250
|
+
* Current state
|
|
251
|
+
*/
|
|
252
|
+
get state(): string;
|
|
253
|
+
/**
|
|
254
|
+
* Session ID
|
|
255
|
+
*/
|
|
256
|
+
get sessionId(): string | null;
|
|
257
|
+
/**
|
|
258
|
+
* All messages received by this agent
|
|
259
|
+
*/
|
|
260
|
+
get receivedMessages(): readonly Message[];
|
|
261
|
+
/**
|
|
262
|
+
* Get the last received message
|
|
263
|
+
*/
|
|
264
|
+
get lastMessage(): Message | undefined;
|
|
265
|
+
/**
|
|
266
|
+
* Clear received messages
|
|
267
|
+
*/
|
|
268
|
+
clearMessages(): void;
|
|
269
|
+
/**
|
|
270
|
+
* Connect to the server
|
|
271
|
+
*/
|
|
272
|
+
connect(agentId?: AgentId): Promise<Agent>;
|
|
273
|
+
/**
|
|
274
|
+
* Disconnect from the server
|
|
275
|
+
*/
|
|
276
|
+
disconnect(reason?: string): Promise<void>;
|
|
277
|
+
/**
|
|
278
|
+
* Update state
|
|
279
|
+
*/
|
|
280
|
+
setState(state: 'idle' | 'busy' | 'suspended' | 'stopping' | 'stopped'): Promise<Agent>;
|
|
281
|
+
/**
|
|
282
|
+
* Mark as busy
|
|
283
|
+
*/
|
|
284
|
+
busy(): Promise<Agent>;
|
|
285
|
+
/**
|
|
286
|
+
* Mark as idle
|
|
287
|
+
*/
|
|
288
|
+
idle(): Promise<Agent>;
|
|
289
|
+
/**
|
|
290
|
+
* Mark as done
|
|
291
|
+
*/
|
|
292
|
+
done(exitCode?: number, exitReason?: string): Promise<void>;
|
|
293
|
+
/**
|
|
294
|
+
* Update metadata
|
|
295
|
+
*/
|
|
296
|
+
setMetadata(metadata: Record<string, unknown>): Promise<Agent>;
|
|
297
|
+
/**
|
|
298
|
+
* Spawn a child agent
|
|
299
|
+
*/
|
|
300
|
+
spawn(options?: {
|
|
301
|
+
name?: string;
|
|
302
|
+
role?: string;
|
|
303
|
+
agentId?: AgentId;
|
|
304
|
+
}): Promise<Agent>;
|
|
305
|
+
/**
|
|
306
|
+
* Spawn and return a connected TestAgent for the child
|
|
307
|
+
*/
|
|
308
|
+
spawnTestAgent(server: TestServer, options?: TestAgentOptions): Promise<TestAgent>;
|
|
309
|
+
/**
|
|
310
|
+
* Create a scope
|
|
311
|
+
*/
|
|
312
|
+
createScope(name: string, options?: {
|
|
313
|
+
description?: string;
|
|
314
|
+
}): Promise<Scope>;
|
|
315
|
+
/**
|
|
316
|
+
* Join a scope
|
|
317
|
+
*/
|
|
318
|
+
joinScope(scopeId: ScopeId): Promise<{
|
|
319
|
+
scope: Scope;
|
|
320
|
+
agent: Agent;
|
|
321
|
+
}>;
|
|
322
|
+
/**
|
|
323
|
+
* Leave a scope
|
|
324
|
+
*/
|
|
325
|
+
leaveScope(scopeId: ScopeId): Promise<{
|
|
326
|
+
scope: Scope;
|
|
327
|
+
agent: Agent;
|
|
328
|
+
}>;
|
|
329
|
+
/**
|
|
330
|
+
* Send to another agent
|
|
331
|
+
*/
|
|
332
|
+
sendTo(agentId: AgentId, payload: unknown): Promise<string>;
|
|
333
|
+
/**
|
|
334
|
+
* Send to parent
|
|
335
|
+
*/
|
|
336
|
+
sendToParent(payload: unknown): Promise<string>;
|
|
337
|
+
/**
|
|
338
|
+
* Send to children
|
|
339
|
+
*/
|
|
340
|
+
sendToChildren(payload: unknown): Promise<string>;
|
|
341
|
+
/**
|
|
342
|
+
* Send to siblings
|
|
343
|
+
*/
|
|
344
|
+
sendToSiblings(payload: unknown): Promise<string>;
|
|
345
|
+
/**
|
|
346
|
+
* Send to scope
|
|
347
|
+
*/
|
|
348
|
+
sendToScope(scopeId: ScopeId, payload: unknown): Promise<string>;
|
|
349
|
+
/**
|
|
350
|
+
* Reply to a message
|
|
351
|
+
*/
|
|
352
|
+
reply(message: Message, payload: unknown): Promise<string>;
|
|
353
|
+
/**
|
|
354
|
+
* Wait for a message
|
|
355
|
+
*/
|
|
356
|
+
waitForMessage(timeoutMs?: number): Promise<Message>;
|
|
357
|
+
/**
|
|
358
|
+
* Subscribe to events
|
|
359
|
+
*/
|
|
360
|
+
subscribe(filter?: SubscriptionFilter): Promise<Subscription>;
|
|
361
|
+
/**
|
|
362
|
+
* Wait for a specific event
|
|
363
|
+
*/
|
|
364
|
+
waitForEvent(eventType: EventType, timeoutMs?: number): Promise<Event>;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
export { TestAgent, type TestAgentOptions, TestClient, type TestClientOptions, TestServer, type TestServerOptions };
|