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/README.md
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
# @acn/client
|
|
2
|
+
|
|
3
|
+
Official TypeScript/JavaScript client for [ACN (Agent Collaboration Network)](https://github.com/acnlabs/ACN).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @acn/client
|
|
9
|
+
# or
|
|
10
|
+
yarn add @acn/client
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @acn/client
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
### HTTP Client
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { ACNClient } from '@acn/client';
|
|
21
|
+
|
|
22
|
+
const client = new ACNClient('http://localhost:9000');
|
|
23
|
+
|
|
24
|
+
// Search agents
|
|
25
|
+
const { agents } = await client.searchAgents({ skills: 'coding' });
|
|
26
|
+
console.log('Found agents:', agents);
|
|
27
|
+
|
|
28
|
+
// Get agent details
|
|
29
|
+
const agent = await client.getAgent('agent-123');
|
|
30
|
+
console.log('Agent:', agent);
|
|
31
|
+
|
|
32
|
+
// Get available skills
|
|
33
|
+
const { skills } = await client.getSkills();
|
|
34
|
+
console.log('Skills:', skills);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Real-time WebSocket
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { ACNRealtime } from '@acn/client';
|
|
41
|
+
|
|
42
|
+
const realtime = new ACNRealtime('ws://localhost:9000');
|
|
43
|
+
|
|
44
|
+
// Subscribe to agent events
|
|
45
|
+
realtime.subscribe('agents', (message) => {
|
|
46
|
+
console.log('Agent event:', message);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Subscribe to all messages
|
|
50
|
+
realtime.onMessage((message) => {
|
|
51
|
+
console.log('Any message:', message);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Monitor connection state
|
|
55
|
+
realtime.onStateChange((state) => {
|
|
56
|
+
console.log('Connection state:', state);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Connect
|
|
60
|
+
await realtime.connect();
|
|
61
|
+
|
|
62
|
+
// Later: disconnect
|
|
63
|
+
realtime.disconnect();
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Simple Subscription Helper
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { subscribeToACN } from '@acn/client';
|
|
70
|
+
|
|
71
|
+
const unsubscribe = subscribeToACN('ws://localhost:9000', 'agents', (msg) => {
|
|
72
|
+
console.log('Agent event:', msg);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// Later: unsubscribe and disconnect
|
|
76
|
+
unsubscribe();
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## API Reference
|
|
80
|
+
|
|
81
|
+
### ACNClient
|
|
82
|
+
|
|
83
|
+
HTTP client for ACN REST API.
|
|
84
|
+
|
|
85
|
+
#### Constructor
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
new ACNClient(options: ACNClientOptions | string)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Options:
|
|
92
|
+
- `baseUrl` - ACN server URL
|
|
93
|
+
- `timeout` - Request timeout in ms (default: 30000)
|
|
94
|
+
- `headers` - Custom headers
|
|
95
|
+
- `apiKey` - API key for authentication
|
|
96
|
+
|
|
97
|
+
#### Agent Methods
|
|
98
|
+
|
|
99
|
+
| Method | Description |
|
|
100
|
+
|--------|-------------|
|
|
101
|
+
| `searchAgents(options?)` | Search agents by skills/status |
|
|
102
|
+
| `getAgent(agentId)` | Get agent by ID |
|
|
103
|
+
| `registerAgent(agent)` | Register a new agent |
|
|
104
|
+
| `unregisterAgent(agentId)` | Unregister an agent |
|
|
105
|
+
| `heartbeat(agentId)` | Send heartbeat |
|
|
106
|
+
| `getSkills()` | List all available skills |
|
|
107
|
+
|
|
108
|
+
#### Subnet Methods
|
|
109
|
+
|
|
110
|
+
| Method | Description |
|
|
111
|
+
|--------|-------------|
|
|
112
|
+
| `listSubnets()` | List all subnets |
|
|
113
|
+
| `getSubnet(subnetId)` | Get subnet by ID |
|
|
114
|
+
| `createSubnet(request)` | Create a new subnet |
|
|
115
|
+
| `deleteSubnet(subnetId, force?)` | Delete a subnet |
|
|
116
|
+
| `getSubnetAgents(subnetId)` | Get agents in subnet |
|
|
117
|
+
| `joinSubnet(agentId, subnetId)` | Join agent to subnet |
|
|
118
|
+
| `leaveSubnet(agentId, subnetId)` | Remove agent from subnet |
|
|
119
|
+
|
|
120
|
+
#### Communication Methods
|
|
121
|
+
|
|
122
|
+
| Method | Description |
|
|
123
|
+
|--------|-------------|
|
|
124
|
+
| `sendMessage(request)` | Send message to agent |
|
|
125
|
+
| `broadcast(request)` | Broadcast to multiple agents |
|
|
126
|
+
| `broadcastBySkill(request)` | Broadcast by skill |
|
|
127
|
+
| `getMessageHistory(agentId, options?)` | Get message history |
|
|
128
|
+
|
|
129
|
+
#### Payment Methods
|
|
130
|
+
|
|
131
|
+
| Method | Description |
|
|
132
|
+
|--------|-------------|
|
|
133
|
+
| `discoverPaymentAgents(options?)` | Find agents accepting payments |
|
|
134
|
+
| `getPaymentCapability(agentId)` | Get agent's payment capability |
|
|
135
|
+
| `setPaymentCapability(agentId, capability)` | Set payment capability |
|
|
136
|
+
| `getPaymentTask(taskId)` | Get payment task |
|
|
137
|
+
| `getAgentPaymentTasks(agentId, options?)` | Get agent's payment tasks |
|
|
138
|
+
| `getPaymentStats(agentId)` | Get payment statistics |
|
|
139
|
+
|
|
140
|
+
#### Monitoring Methods
|
|
141
|
+
|
|
142
|
+
| Method | Description |
|
|
143
|
+
|--------|-------------|
|
|
144
|
+
| `health()` | Health check |
|
|
145
|
+
| `getStats()` | Get server statistics |
|
|
146
|
+
| `getDashboard()` | Get dashboard data |
|
|
147
|
+
| `getSystemHealth()` | Get system health |
|
|
148
|
+
| `getMetrics()` | Get metrics |
|
|
149
|
+
| `getAgentAnalytics()` | Get agent analytics |
|
|
150
|
+
|
|
151
|
+
### ACNRealtime
|
|
152
|
+
|
|
153
|
+
WebSocket client for real-time events.
|
|
154
|
+
|
|
155
|
+
#### Constructor
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
new ACNRealtime(baseUrl: string, options?: WSConnectionOptions)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Options:
|
|
162
|
+
- `autoReconnect` - Auto reconnect on disconnect (default: true)
|
|
163
|
+
- `reconnectInterval` - Reconnect interval in ms (default: 3000)
|
|
164
|
+
- `maxReconnectAttempts` - Max reconnect attempts (default: 10)
|
|
165
|
+
- `heartbeatInterval` - Heartbeat interval in ms (default: 30000)
|
|
166
|
+
|
|
167
|
+
#### Methods
|
|
168
|
+
|
|
169
|
+
| Method | Description |
|
|
170
|
+
|--------|-------------|
|
|
171
|
+
| `connect(channel?)` | Connect to WebSocket |
|
|
172
|
+
| `disconnect()` | Disconnect |
|
|
173
|
+
| `subscribe(channel, handler)` | Subscribe to channel |
|
|
174
|
+
| `onMessage(handler)` | Subscribe to all messages |
|
|
175
|
+
| `onStateChange(handler)` | Subscribe to state changes |
|
|
176
|
+
| `send(message)` | Send a message |
|
|
177
|
+
|
|
178
|
+
#### Properties
|
|
179
|
+
|
|
180
|
+
| Property | Type | Description |
|
|
181
|
+
|----------|------|-------------|
|
|
182
|
+
| `connectionState` | `WSState` | Current state |
|
|
183
|
+
| `isConnected` | `boolean` | Whether connected |
|
|
184
|
+
|
|
185
|
+
## TypeScript Support
|
|
186
|
+
|
|
187
|
+
This package includes full TypeScript type definitions.
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
import type {
|
|
191
|
+
AgentInfo,
|
|
192
|
+
AgentSearchOptions,
|
|
193
|
+
PaymentCapability,
|
|
194
|
+
WSMessage,
|
|
195
|
+
} from '@acn/client';
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Browser Support
|
|
199
|
+
|
|
200
|
+
This package works in both Node.js and browser environments.
|
|
201
|
+
|
|
202
|
+
For browsers, make sure your bundler handles the `fetch` and `WebSocket` APIs (available natively in modern browsers).
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
|
|
206
|
+
MIT
|
|
207
|
+
|
|
208
|
+
## Links
|
|
209
|
+
|
|
210
|
+
- [ACN GitHub](https://github.com/acnlabs/ACN)
|
|
211
|
+
- [Documentation](https://github.com/acnlabs/ACN#readme)
|
|
212
|
+
- [Issues](https://github.com/acnlabs/ACN/issues)
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|