acn-client 0.2.1
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 +244 -0
- package/dist/index.d.mts +579 -0
- package/dist/index.d.ts +579 -0
- package/dist/index.js +627 -0
- package/dist/index.mjs +587 -0
- package/package.json +68 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACN Client Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions synced with ACN API models.
|
|
5
|
+
* @see https://github.com/ACNet-AI/ACN
|
|
6
|
+
*/
|
|
7
|
+
/** Agent status */
|
|
8
|
+
type AgentStatus = 'online' | 'offline' | 'busy';
|
|
9
|
+
/** Agent list filter status (includes "all" for discovery) */
|
|
10
|
+
type AgentSearchStatus = AgentStatus | 'all';
|
|
11
|
+
/** Agent information */
|
|
12
|
+
interface AgentInfo {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
skills: string[];
|
|
17
|
+
status: AgentStatus;
|
|
18
|
+
endpoint?: string;
|
|
19
|
+
metadata?: Record<string, unknown>;
|
|
20
|
+
subnets?: string[];
|
|
21
|
+
created_at?: string;
|
|
22
|
+
last_seen?: string;
|
|
23
|
+
wallet_address?: string;
|
|
24
|
+
accepts_payment?: boolean;
|
|
25
|
+
payment_methods?: string[];
|
|
26
|
+
supported_networks?: string[];
|
|
27
|
+
}
|
|
28
|
+
/** Agent registration request */
|
|
29
|
+
interface AgentRegisterRequest {
|
|
30
|
+
id: string;
|
|
31
|
+
name: string;
|
|
32
|
+
description?: string;
|
|
33
|
+
skills: string[];
|
|
34
|
+
endpoint?: string;
|
|
35
|
+
metadata?: Record<string, unknown>;
|
|
36
|
+
wallet_address?: string;
|
|
37
|
+
payment_capability?: PaymentCapability;
|
|
38
|
+
}
|
|
39
|
+
/** Agent registration response */
|
|
40
|
+
interface AgentRegisterResponse {
|
|
41
|
+
success: boolean;
|
|
42
|
+
agent_id: string;
|
|
43
|
+
message: string;
|
|
44
|
+
}
|
|
45
|
+
/** Agent search response */
|
|
46
|
+
interface AgentSearchResponse {
|
|
47
|
+
agents: AgentInfo[];
|
|
48
|
+
total: number;
|
|
49
|
+
}
|
|
50
|
+
/** Agent search options */
|
|
51
|
+
interface AgentSearchOptions {
|
|
52
|
+
skills?: string;
|
|
53
|
+
/** online (default) | offline | all. Public list does not include verification_code. */
|
|
54
|
+
status?: AgentSearchStatus;
|
|
55
|
+
subnet_id?: string;
|
|
56
|
+
}
|
|
57
|
+
/** Subnet information */
|
|
58
|
+
interface SubnetInfo {
|
|
59
|
+
id: string;
|
|
60
|
+
name: string;
|
|
61
|
+
description?: string;
|
|
62
|
+
created_at: string;
|
|
63
|
+
agent_count: number;
|
|
64
|
+
metadata?: Record<string, unknown>;
|
|
65
|
+
}
|
|
66
|
+
/** Subnet creation request */
|
|
67
|
+
interface SubnetCreateRequest {
|
|
68
|
+
name: string;
|
|
69
|
+
description?: string;
|
|
70
|
+
metadata?: Record<string, unknown>;
|
|
71
|
+
}
|
|
72
|
+
/** Subnet creation response */
|
|
73
|
+
interface SubnetCreateResponse {
|
|
74
|
+
success: boolean;
|
|
75
|
+
subnet_id: string;
|
|
76
|
+
message: string;
|
|
77
|
+
}
|
|
78
|
+
/** Message types */
|
|
79
|
+
type MessageType = 'text' | 'data' | 'notification' | 'task' | 'result';
|
|
80
|
+
/** A2A Message */
|
|
81
|
+
interface Message {
|
|
82
|
+
id: string;
|
|
83
|
+
type: MessageType;
|
|
84
|
+
from_agent: string;
|
|
85
|
+
to_agent?: string;
|
|
86
|
+
content: unknown;
|
|
87
|
+
timestamp: string;
|
|
88
|
+
metadata?: Record<string, unknown>;
|
|
89
|
+
}
|
|
90
|
+
/** Send message request */
|
|
91
|
+
interface SendMessageRequest {
|
|
92
|
+
from_agent: string;
|
|
93
|
+
to_agent: string;
|
|
94
|
+
message_type: MessageType;
|
|
95
|
+
content: unknown;
|
|
96
|
+
metadata?: Record<string, unknown>;
|
|
97
|
+
}
|
|
98
|
+
/** Broadcast strategy */
|
|
99
|
+
type BroadcastStrategy = 'all' | 'random' | 'round_robin' | 'load_balanced';
|
|
100
|
+
/** Broadcast request */
|
|
101
|
+
interface BroadcastRequest {
|
|
102
|
+
from_agent: string;
|
|
103
|
+
message_type: MessageType;
|
|
104
|
+
content: unknown;
|
|
105
|
+
strategy?: BroadcastStrategy;
|
|
106
|
+
target_agents?: string[];
|
|
107
|
+
metadata?: Record<string, unknown>;
|
|
108
|
+
}
|
|
109
|
+
/** Broadcast by skill request */
|
|
110
|
+
interface BroadcastBySkillRequest {
|
|
111
|
+
from_agent: string;
|
|
112
|
+
skill: string;
|
|
113
|
+
message_type: MessageType;
|
|
114
|
+
content: unknown;
|
|
115
|
+
strategy?: BroadcastStrategy;
|
|
116
|
+
metadata?: Record<string, unknown>;
|
|
117
|
+
}
|
|
118
|
+
/** Supported payment methods */
|
|
119
|
+
type PaymentMethod = 'USDC' | 'USDT' | 'ETH' | 'DAI' | 'CREDIT_CARD' | 'BANK_TRANSFER' | 'PLATFORM_CREDITS';
|
|
120
|
+
/** Supported networks */
|
|
121
|
+
type PaymentNetwork = 'ETHEREUM' | 'POLYGON' | 'BASE' | 'ARBITRUM' | 'OPTIMISM' | 'SOLANA';
|
|
122
|
+
/** Payment capability */
|
|
123
|
+
interface PaymentCapability {
|
|
124
|
+
accepts_payment: boolean;
|
|
125
|
+
wallet_address?: string;
|
|
126
|
+
supported_methods: PaymentMethod[];
|
|
127
|
+
supported_networks: PaymentNetwork[];
|
|
128
|
+
min_amount?: number;
|
|
129
|
+
max_amount?: number;
|
|
130
|
+
currency?: string;
|
|
131
|
+
}
|
|
132
|
+
/** Payment task status */
|
|
133
|
+
type PaymentTaskStatus = 'pending' | 'in_progress' | 'completed' | 'failed' | 'cancelled';
|
|
134
|
+
/** Payment task */
|
|
135
|
+
interface PaymentTask {
|
|
136
|
+
id: string;
|
|
137
|
+
payer_agent_id: string;
|
|
138
|
+
payee_agent_id: string;
|
|
139
|
+
amount: number;
|
|
140
|
+
currency: string;
|
|
141
|
+
method: PaymentMethod;
|
|
142
|
+
network?: PaymentNetwork;
|
|
143
|
+
status: PaymentTaskStatus;
|
|
144
|
+
created_at: string;
|
|
145
|
+
updated_at: string;
|
|
146
|
+
transaction_hash?: string;
|
|
147
|
+
metadata?: Record<string, unknown>;
|
|
148
|
+
}
|
|
149
|
+
/** Payment discovery options */
|
|
150
|
+
interface PaymentDiscoveryOptions {
|
|
151
|
+
method?: PaymentMethod;
|
|
152
|
+
network?: PaymentNetwork;
|
|
153
|
+
min_amount?: number;
|
|
154
|
+
max_amount?: number;
|
|
155
|
+
}
|
|
156
|
+
/** Payment statistics */
|
|
157
|
+
interface PaymentStats {
|
|
158
|
+
total_received: number;
|
|
159
|
+
total_sent: number;
|
|
160
|
+
transaction_count: number;
|
|
161
|
+
avg_amount: number;
|
|
162
|
+
}
|
|
163
|
+
/** System health */
|
|
164
|
+
interface SystemHealth {
|
|
165
|
+
status: 'healthy' | 'degraded' | 'unhealthy';
|
|
166
|
+
uptime: number;
|
|
167
|
+
version: string;
|
|
168
|
+
components: Record<string, ComponentHealth>;
|
|
169
|
+
}
|
|
170
|
+
/** Component health */
|
|
171
|
+
interface ComponentHealth {
|
|
172
|
+
status: 'healthy' | 'degraded' | 'unhealthy';
|
|
173
|
+
latency_ms?: number;
|
|
174
|
+
message?: string;
|
|
175
|
+
}
|
|
176
|
+
/** Dashboard data */
|
|
177
|
+
interface DashboardData {
|
|
178
|
+
agents: {
|
|
179
|
+
total: number;
|
|
180
|
+
online: number;
|
|
181
|
+
offline: number;
|
|
182
|
+
};
|
|
183
|
+
messages: {
|
|
184
|
+
total: number;
|
|
185
|
+
last_hour: number;
|
|
186
|
+
last_24h: number;
|
|
187
|
+
};
|
|
188
|
+
subnets: {
|
|
189
|
+
total: number;
|
|
190
|
+
active: number;
|
|
191
|
+
};
|
|
192
|
+
system: SystemHealth;
|
|
193
|
+
}
|
|
194
|
+
/** Metrics data */
|
|
195
|
+
interface MetricsData {
|
|
196
|
+
timestamp: string;
|
|
197
|
+
metrics: Record<string, number>;
|
|
198
|
+
}
|
|
199
|
+
/** Agent analytics */
|
|
200
|
+
interface AgentAnalytics {
|
|
201
|
+
agent_id: string;
|
|
202
|
+
messages_sent: number;
|
|
203
|
+
messages_received: number;
|
|
204
|
+
tasks_completed: number;
|
|
205
|
+
avg_response_time_ms: number;
|
|
206
|
+
uptime_percentage: number;
|
|
207
|
+
}
|
|
208
|
+
/** Agent activity */
|
|
209
|
+
interface AgentActivity {
|
|
210
|
+
agent_id: string;
|
|
211
|
+
activities: ActivityEntry[];
|
|
212
|
+
}
|
|
213
|
+
/** Activity entry */
|
|
214
|
+
interface ActivityEntry {
|
|
215
|
+
timestamp: string;
|
|
216
|
+
type: string;
|
|
217
|
+
description: string;
|
|
218
|
+
metadata?: Record<string, unknown>;
|
|
219
|
+
}
|
|
220
|
+
/** Audit event */
|
|
221
|
+
interface AuditEvent {
|
|
222
|
+
id: string;
|
|
223
|
+
timestamp: string;
|
|
224
|
+
event_type: string;
|
|
225
|
+
actor_id?: string;
|
|
226
|
+
target_id?: string;
|
|
227
|
+
action: string;
|
|
228
|
+
details?: Record<string, unknown>;
|
|
229
|
+
ip_address?: string;
|
|
230
|
+
}
|
|
231
|
+
/** Audit query options */
|
|
232
|
+
interface AuditQueryOptions {
|
|
233
|
+
event_type?: string;
|
|
234
|
+
actor_id?: string;
|
|
235
|
+
start_time?: string;
|
|
236
|
+
end_time?: string;
|
|
237
|
+
limit?: number;
|
|
238
|
+
offset?: number;
|
|
239
|
+
}
|
|
240
|
+
/** WebSocket message */
|
|
241
|
+
interface WSMessage<T = unknown> {
|
|
242
|
+
type: string;
|
|
243
|
+
channel: string;
|
|
244
|
+
data: T;
|
|
245
|
+
timestamp: string;
|
|
246
|
+
}
|
|
247
|
+
/** WebSocket event types */
|
|
248
|
+
type WSEventType = 'agent_online' | 'agent_offline' | 'message' | 'broadcast' | 'task_update' | 'payment_update' | 'error';
|
|
249
|
+
/** WebSocket connection options */
|
|
250
|
+
interface WSConnectionOptions {
|
|
251
|
+
/** Reconnect automatically on disconnect */
|
|
252
|
+
autoReconnect?: boolean;
|
|
253
|
+
/** Reconnect interval in ms */
|
|
254
|
+
reconnectInterval?: number;
|
|
255
|
+
/** Max reconnect attempts */
|
|
256
|
+
maxReconnectAttempts?: number;
|
|
257
|
+
/** Heartbeat interval in ms */
|
|
258
|
+
heartbeatInterval?: number;
|
|
259
|
+
}
|
|
260
|
+
/** ACN Client configuration */
|
|
261
|
+
interface ACNClientOptions {
|
|
262
|
+
/** ACN server base URL */
|
|
263
|
+
baseUrl: string;
|
|
264
|
+
/** Request timeout in ms */
|
|
265
|
+
timeout?: number;
|
|
266
|
+
/** Custom headers */
|
|
267
|
+
headers?: Record<string, string>;
|
|
268
|
+
/** API key for authentication (optional) */
|
|
269
|
+
apiKey?: string;
|
|
270
|
+
}
|
|
271
|
+
/** API response wrapper */
|
|
272
|
+
interface ApiResponse<T> {
|
|
273
|
+
success: boolean;
|
|
274
|
+
data?: T;
|
|
275
|
+
error?: string;
|
|
276
|
+
message?: string;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* ACN HTTP Client
|
|
281
|
+
*
|
|
282
|
+
* Official TypeScript client for ACN REST API.
|
|
283
|
+
*/
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* ACN Client - HTTP API
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```typescript
|
|
290
|
+
* import { ACNClient } from '@acn/client';
|
|
291
|
+
*
|
|
292
|
+
* const client = new ACNClient({ baseUrl: 'http://localhost:9000' });
|
|
293
|
+
*
|
|
294
|
+
* // Search agents
|
|
295
|
+
* const { agents } = await client.searchAgents({ skills: 'coding' });
|
|
296
|
+
*
|
|
297
|
+
* // Get agent details
|
|
298
|
+
* const agent = await client.getAgent('agent-123');
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
declare class ACNClient {
|
|
302
|
+
private baseUrl;
|
|
303
|
+
private timeout;
|
|
304
|
+
private headers;
|
|
305
|
+
constructor(options: ACNClientOptions | string);
|
|
306
|
+
private request;
|
|
307
|
+
private get;
|
|
308
|
+
private post;
|
|
309
|
+
private delete;
|
|
310
|
+
/** Check if ACN server is healthy */
|
|
311
|
+
health(): Promise<{
|
|
312
|
+
status: string;
|
|
313
|
+
}>;
|
|
314
|
+
/** Get server statistics */
|
|
315
|
+
getStats(): Promise<{
|
|
316
|
+
total_agents: number;
|
|
317
|
+
online_agents: number;
|
|
318
|
+
total_messages: number;
|
|
319
|
+
}>;
|
|
320
|
+
/** Register a new agent */
|
|
321
|
+
registerAgent(agent: AgentRegisterRequest): Promise<AgentRegisterResponse>;
|
|
322
|
+
/** Get agent by ID */
|
|
323
|
+
getAgent(agentId: string): Promise<AgentInfo>;
|
|
324
|
+
/** Search agents (status: online | offline | all; public list does not include verification_code) */
|
|
325
|
+
searchAgents(options?: AgentSearchOptions): Promise<AgentSearchResponse>;
|
|
326
|
+
/** Unregister an agent */
|
|
327
|
+
unregisterAgent(agentId: string): Promise<{
|
|
328
|
+
success: boolean;
|
|
329
|
+
message: string;
|
|
330
|
+
}>;
|
|
331
|
+
/** Send agent heartbeat */
|
|
332
|
+
heartbeat(agentId: string): Promise<{
|
|
333
|
+
success: boolean;
|
|
334
|
+
}>;
|
|
335
|
+
/** Get agent endpoint */
|
|
336
|
+
getAgentEndpoint(agentId: string): Promise<{
|
|
337
|
+
endpoint: string;
|
|
338
|
+
}>;
|
|
339
|
+
/** List all available skills */
|
|
340
|
+
getSkills(): Promise<{
|
|
341
|
+
skills: string[];
|
|
342
|
+
counts: Record<string, number>;
|
|
343
|
+
}>;
|
|
344
|
+
/** Create a new subnet */
|
|
345
|
+
createSubnet(request: SubnetCreateRequest): Promise<SubnetCreateResponse>;
|
|
346
|
+
/** List all subnets */
|
|
347
|
+
listSubnets(): Promise<{
|
|
348
|
+
subnets: SubnetInfo[];
|
|
349
|
+
}>;
|
|
350
|
+
/** Get subnet by ID */
|
|
351
|
+
getSubnet(subnetId: string): Promise<SubnetInfo>;
|
|
352
|
+
/** Delete a subnet */
|
|
353
|
+
deleteSubnet(subnetId: string, force?: boolean): Promise<{
|
|
354
|
+
success: boolean;
|
|
355
|
+
}>;
|
|
356
|
+
/** Get agents in a subnet */
|
|
357
|
+
getSubnetAgents(subnetId: string): Promise<{
|
|
358
|
+
agents: AgentInfo[];
|
|
359
|
+
}>;
|
|
360
|
+
/** Join agent to subnet */
|
|
361
|
+
joinSubnet(agentId: string, subnetId: string): Promise<{
|
|
362
|
+
success: boolean;
|
|
363
|
+
}>;
|
|
364
|
+
/** Remove agent from subnet */
|
|
365
|
+
leaveSubnet(agentId: string, subnetId: string): Promise<{
|
|
366
|
+
success: boolean;
|
|
367
|
+
}>;
|
|
368
|
+
/** Get agent's subnets */
|
|
369
|
+
getAgentSubnets(agentId: string): Promise<{
|
|
370
|
+
subnets: string[];
|
|
371
|
+
}>;
|
|
372
|
+
/** Send message to an agent */
|
|
373
|
+
sendMessage(request: SendMessageRequest): Promise<{
|
|
374
|
+
success: boolean;
|
|
375
|
+
message_id: string;
|
|
376
|
+
}>;
|
|
377
|
+
/** Broadcast message to multiple agents */
|
|
378
|
+
broadcast(request: BroadcastRequest): Promise<{
|
|
379
|
+
success: boolean;
|
|
380
|
+
delivered_count: number;
|
|
381
|
+
}>;
|
|
382
|
+
/** Broadcast message to agents with specific skill */
|
|
383
|
+
broadcastBySkill(request: BroadcastBySkillRequest): Promise<{
|
|
384
|
+
success: boolean;
|
|
385
|
+
delivered_count: number;
|
|
386
|
+
}>;
|
|
387
|
+
/** Get message history for an agent */
|
|
388
|
+
getMessageHistory(agentId: string, options?: {
|
|
389
|
+
limit?: number;
|
|
390
|
+
offset?: number;
|
|
391
|
+
}): Promise<{
|
|
392
|
+
messages: Message[];
|
|
393
|
+
}>;
|
|
394
|
+
/** Set agent's payment capability */
|
|
395
|
+
setPaymentCapability(agentId: string, capability: PaymentCapability): Promise<{
|
|
396
|
+
success: boolean;
|
|
397
|
+
}>;
|
|
398
|
+
/** Get agent's payment capability */
|
|
399
|
+
getPaymentCapability(agentId: string): Promise<PaymentCapability | null>;
|
|
400
|
+
/** Discover agents that accept payments */
|
|
401
|
+
discoverPaymentAgents(options?: PaymentDiscoveryOptions): Promise<{
|
|
402
|
+
agents: AgentInfo[];
|
|
403
|
+
}>;
|
|
404
|
+
/** Get payment task by ID */
|
|
405
|
+
getPaymentTask(taskId: string): Promise<PaymentTask>;
|
|
406
|
+
/** Get agent's payment tasks */
|
|
407
|
+
getAgentPaymentTasks(agentId: string, options?: {
|
|
408
|
+
role?: 'payer' | 'payee';
|
|
409
|
+
status?: string;
|
|
410
|
+
limit?: number;
|
|
411
|
+
}): Promise<{
|
|
412
|
+
tasks: PaymentTask[];
|
|
413
|
+
}>;
|
|
414
|
+
/** Get agent's payment statistics */
|
|
415
|
+
getPaymentStats(agentId: string): Promise<PaymentStats>;
|
|
416
|
+
/** Get Prometheus metrics (text format) */
|
|
417
|
+
getPrometheusMetrics(): Promise<string>;
|
|
418
|
+
/** Get all metrics */
|
|
419
|
+
getMetrics(): Promise<MetricsData>;
|
|
420
|
+
/** Get system health */
|
|
421
|
+
getSystemHealth(): Promise<SystemHealth>;
|
|
422
|
+
/** Get dashboard data */
|
|
423
|
+
getDashboard(): Promise<DashboardData>;
|
|
424
|
+
/** Get agent analytics */
|
|
425
|
+
getAgentAnalytics(): Promise<{
|
|
426
|
+
analytics: AgentAnalytics[];
|
|
427
|
+
}>;
|
|
428
|
+
/** Get specific agent's activity */
|
|
429
|
+
getAgentActivity(agentId: string, options?: {
|
|
430
|
+
start_time?: string;
|
|
431
|
+
end_time?: string;
|
|
432
|
+
}): Promise<AgentActivity>;
|
|
433
|
+
/** Get message analytics */
|
|
434
|
+
getMessageAnalytics(): Promise<Record<string, unknown>>;
|
|
435
|
+
/** Get latency analytics */
|
|
436
|
+
getLatencyAnalytics(): Promise<Record<string, unknown>>;
|
|
437
|
+
/** Get subnet analytics */
|
|
438
|
+
getSubnetAnalytics(): Promise<Record<string, unknown>>;
|
|
439
|
+
/** Get audit events */
|
|
440
|
+
getAuditEvents(options?: AuditQueryOptions): Promise<{
|
|
441
|
+
events: AuditEvent[];
|
|
442
|
+
}>;
|
|
443
|
+
/** Get recent audit events */
|
|
444
|
+
getRecentAuditEvents(limit?: number): Promise<{
|
|
445
|
+
events: AuditEvent[];
|
|
446
|
+
}>;
|
|
447
|
+
/**
|
|
448
|
+
* Register the agent on ERC-8004 Identity Registry and bind to ACN.
|
|
449
|
+
*
|
|
450
|
+
* Full flow:
|
|
451
|
+
* 1. Generate wallet if privateKey is undefined (saved to saveWalletPath).
|
|
452
|
+
* 2. Construct agentURI → agent-registration.json endpoint.
|
|
453
|
+
* 3. Sign and broadcast register(agentURI) transaction via viem.
|
|
454
|
+
* 4. Extract token ID from Registered event.
|
|
455
|
+
* 5. POST /api/v1/onchain/agents/{agentId}/bind to inform ACN.
|
|
456
|
+
*
|
|
457
|
+
* @param agentId - ACN agent ID (from join response).
|
|
458
|
+
* @param options - Chain, RPC, private key, wallet save path.
|
|
459
|
+
*/
|
|
460
|
+
registerOnchain(agentId: string, options?: {
|
|
461
|
+
privateKey?: `0x${string}`;
|
|
462
|
+
chain?: 'base' | 'base-sepolia';
|
|
463
|
+
rpcUrl?: string;
|
|
464
|
+
saveWalletPath?: string;
|
|
465
|
+
}): Promise<{
|
|
466
|
+
tokenId: bigint;
|
|
467
|
+
txHash: string;
|
|
468
|
+
chain: string;
|
|
469
|
+
agentRegistrationUrl: string;
|
|
470
|
+
walletAddress: string;
|
|
471
|
+
walletGenerated: boolean;
|
|
472
|
+
}>;
|
|
473
|
+
/** @internal Save generated wallet credentials to a .env file. */
|
|
474
|
+
private _saveWalletToEnv;
|
|
475
|
+
/** Get audit statistics */
|
|
476
|
+
getAuditStats(options?: {
|
|
477
|
+
start_time?: string;
|
|
478
|
+
end_time?: string;
|
|
479
|
+
}): Promise<Record<string, unknown>>;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* ACN API Error
|
|
483
|
+
*/
|
|
484
|
+
declare class ACNError extends Error {
|
|
485
|
+
status: number;
|
|
486
|
+
constructor(status: number, message: string);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* ACN WebSocket Client
|
|
491
|
+
*
|
|
492
|
+
* Real-time communication with ACN server.
|
|
493
|
+
*/
|
|
494
|
+
|
|
495
|
+
/** WebSocket event handler */
|
|
496
|
+
type WSEventHandler<T = unknown> = (message: WSMessage<T>) => void;
|
|
497
|
+
/** WebSocket state */
|
|
498
|
+
type WSState = 'connecting' | 'connected' | 'disconnected' | 'reconnecting';
|
|
499
|
+
/**
|
|
500
|
+
* ACN Real-time Client
|
|
501
|
+
*
|
|
502
|
+
* @example
|
|
503
|
+
* ```typescript
|
|
504
|
+
* import { ACNRealtime } from '@acn/client';
|
|
505
|
+
*
|
|
506
|
+
* const realtime = new ACNRealtime('ws://localhost:9000');
|
|
507
|
+
*
|
|
508
|
+
* // Subscribe to a channel
|
|
509
|
+
* realtime.subscribe('agents', (message) => {
|
|
510
|
+
* console.log('Agent event:', message);
|
|
511
|
+
* });
|
|
512
|
+
*
|
|
513
|
+
* // Connect
|
|
514
|
+
* await realtime.connect();
|
|
515
|
+
* ```
|
|
516
|
+
*/
|
|
517
|
+
declare class ACNRealtime {
|
|
518
|
+
private baseUrl;
|
|
519
|
+
private options;
|
|
520
|
+
private ws;
|
|
521
|
+
private state;
|
|
522
|
+
private reconnectAttempts;
|
|
523
|
+
private heartbeatTimer;
|
|
524
|
+
private reconnectTimer;
|
|
525
|
+
private channels;
|
|
526
|
+
private globalHandlers;
|
|
527
|
+
private stateHandlers;
|
|
528
|
+
constructor(baseUrl: string, options?: WSConnectionOptions);
|
|
529
|
+
/** Current connection state */
|
|
530
|
+
get connectionState(): WSState;
|
|
531
|
+
/** Whether currently connected */
|
|
532
|
+
get isConnected(): boolean;
|
|
533
|
+
/**
|
|
534
|
+
* Connect to a channel
|
|
535
|
+
*/
|
|
536
|
+
connect(channel?: string): Promise<void>;
|
|
537
|
+
/**
|
|
538
|
+
* Disconnect from server
|
|
539
|
+
*/
|
|
540
|
+
disconnect(): void;
|
|
541
|
+
/**
|
|
542
|
+
* Subscribe to a channel
|
|
543
|
+
*/
|
|
544
|
+
subscribe<T = unknown>(channel: string, handler: WSEventHandler<T>): () => void;
|
|
545
|
+
/**
|
|
546
|
+
* Subscribe to all messages
|
|
547
|
+
*/
|
|
548
|
+
onMessage<T = unknown>(handler: WSEventHandler<T>): () => void;
|
|
549
|
+
/**
|
|
550
|
+
* Subscribe to state changes
|
|
551
|
+
*/
|
|
552
|
+
onStateChange(handler: (state: WSState) => void): () => void;
|
|
553
|
+
/**
|
|
554
|
+
* Send a message
|
|
555
|
+
*/
|
|
556
|
+
send(message: unknown): void;
|
|
557
|
+
private setState;
|
|
558
|
+
private handleMessage;
|
|
559
|
+
private handleError;
|
|
560
|
+
private startHeartbeat;
|
|
561
|
+
private stopHeartbeat;
|
|
562
|
+
private scheduleReconnect;
|
|
563
|
+
private clearReconnectTimer;
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Create a simple subscription to ACN events
|
|
567
|
+
*
|
|
568
|
+
* @example
|
|
569
|
+
* ```typescript
|
|
570
|
+
* const unsubscribe = subscribeToACN('ws://localhost:9000', 'agents', (msg) => {
|
|
571
|
+
* console.log('Agent event:', msg);
|
|
572
|
+
* });
|
|
573
|
+
*
|
|
574
|
+
* // Later: unsubscribe();
|
|
575
|
+
* ```
|
|
576
|
+
*/
|
|
577
|
+
declare function subscribeToACN<T = unknown>(baseUrl: string, channel: string, handler: WSEventHandler<T>): () => void;
|
|
578
|
+
|
|
579
|
+
export { ACNClient, type ACNClientOptions, ACNError, ACNRealtime, type ActivityEntry, type AgentActivity, type AgentAnalytics, type AgentInfo, type AgentRegisterRequest, type AgentRegisterResponse, type AgentSearchOptions, type AgentSearchResponse, type AgentStatus, type ApiResponse, type AuditEvent, type AuditQueryOptions, type BroadcastBySkillRequest, type BroadcastRequest, type BroadcastStrategy, type ComponentHealth, type DashboardData, type Message, type MessageType, type MetricsData, type PaymentCapability, type PaymentDiscoveryOptions, type PaymentMethod, type PaymentNetwork, type PaymentStats, type PaymentTask, type PaymentTaskStatus, type SendMessageRequest, type SubnetCreateRequest, type SubnetCreateResponse, type SubnetInfo, type SystemHealth, type WSConnectionOptions, type WSEventHandler, type WSEventType, type WSMessage, type WSState, subscribeToACN };
|