@teneo-protocol/sdk 2.2.2 → 3.0.0
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/.github/ISSUE_TEMPLATE/config.yml +1 -1
- package/CHANGELOG.md +366 -15
- package/CONCEPTS.md +182 -44
- package/README.md +524 -94
- package/dist/constants.d.ts +3 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +5 -3
- package/dist/constants.js.map +1 -1
- package/dist/core/websocket-client.d.ts.map +1 -1
- package/dist/core/websocket-client.js +9 -5
- package/dist/core/websocket-client.js.map +1 -1
- package/dist/formatters/response-formatter.d.ts +6 -6
- package/dist/handlers/message-handlers/agent-details-response-handler.d.ts +756 -756
- package/dist/handlers/message-handlers/agent-details-response-handler.js +2 -2
- package/dist/handlers/message-handlers/agent-details-response-handler.js.map +1 -1
- package/dist/handlers/message-handlers/agent-error-handler.d.ts +91 -0
- package/dist/handlers/message-handlers/agent-error-handler.d.ts.map +1 -0
- package/dist/handlers/message-handlers/agent-error-handler.js +44 -0
- package/dist/handlers/message-handlers/agent-error-handler.js.map +1 -0
- package/dist/handlers/message-handlers/agent-selected-handler.d.ts +6 -0
- package/dist/handlers/message-handlers/agent-selected-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/agent-status-update-handler.d.ts +756 -756
- package/dist/handlers/message-handlers/agent-status-update-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/agent-status-update-handler.js +2 -7
- package/dist/handlers/message-handlers/agent-status-update-handler.js.map +1 -1
- package/dist/handlers/message-handlers/all-agents-response-handler.js +2 -2
- package/dist/handlers/message-handlers/all-agents-response-handler.js.map +1 -1
- package/dist/handlers/message-handlers/auth-error-handler.d.ts +6 -0
- package/dist/handlers/message-handlers/auth-error-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/auth-message-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/auth-message-handler.js +6 -1
- package/dist/handlers/message-handlers/auth-message-handler.js.map +1 -1
- package/dist/handlers/message-handlers/auth-required-handler.d.ts +6 -0
- package/dist/handlers/message-handlers/auth-required-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/auth-success-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/auth-success-handler.js +6 -1
- package/dist/handlers/message-handlers/auth-success-handler.js.map +1 -1
- package/dist/handlers/message-handlers/base-handler.d.ts +2 -1
- package/dist/handlers/message-handlers/base-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/base-handler.js +24 -4
- package/dist/handlers/message-handlers/base-handler.js.map +1 -1
- package/dist/handlers/message-handlers/challenge-handler.d.ts +6 -0
- package/dist/handlers/message-handlers/challenge-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/error-message-handler.d.ts +6 -0
- package/dist/handlers/message-handlers/error-message-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/index.d.ts +4 -0
- package/dist/handlers/message-handlers/index.d.ts.map +1 -1
- package/dist/handlers/message-handlers/index.js +23 -1
- package/dist/handlers/message-handlers/index.js.map +1 -1
- package/dist/handlers/message-handlers/list-available-agents-handler.d.ts +792 -756
- package/dist/handlers/message-handlers/list-available-agents-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/list-available-agents-handler.js +23 -10
- package/dist/handlers/message-handlers/list-available-agents-handler.js.map +1 -1
- package/dist/handlers/message-handlers/list-room-agents-handler.d.ts +756 -756
- package/dist/handlers/message-handlers/list-room-agents-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/list-room-agents-handler.js +2 -6
- package/dist/handlers/message-handlers/list-room-agents-handler.js.map +1 -1
- package/dist/handlers/message-handlers/list-rooms-response-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/list-rooms-response-handler.js +2 -5
- package/dist/handlers/message-handlers/list-rooms-response-handler.js.map +1 -1
- package/dist/handlers/message-handlers/ping-pong-handler.d.ts +52 -4
- package/dist/handlers/message-handlers/ping-pong-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/ping-pong-handler.js +23 -4
- package/dist/handlers/message-handlers/ping-pong-handler.js.map +1 -1
- package/dist/handlers/message-handlers/rate-limit-notification-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/rate-limit-notification-handler.js +3 -2
- package/dist/handlers/message-handlers/rate-limit-notification-handler.js.map +1 -1
- package/dist/handlers/message-handlers/regular-message-handler.d.ts +6 -0
- package/dist/handlers/message-handlers/regular-message-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/subscribe-response-handler.d.ts +12 -6
- package/dist/handlers/message-handlers/subscribe-response-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/success-handler.d.ts +82 -0
- package/dist/handlers/message-handlers/success-handler.d.ts.map +1 -0
- package/dist/handlers/message-handlers/success-handler.js +24 -0
- package/dist/handlers/message-handlers/success-handler.js.map +1 -0
- package/dist/handlers/message-handlers/task-confirmed-handler.d.ts +110 -0
- package/dist/handlers/message-handlers/task-confirmed-handler.d.ts.map +1 -0
- package/dist/handlers/message-handlers/task-confirmed-handler.js +46 -0
- package/dist/handlers/message-handlers/task-confirmed-handler.js.map +1 -0
- package/dist/handlers/message-handlers/trigger-wallet-tx-handler.d.ts +244 -0
- package/dist/handlers/message-handlers/trigger-wallet-tx-handler.d.ts.map +1 -0
- package/dist/handlers/message-handlers/trigger-wallet-tx-handler.js +58 -0
- package/dist/handlers/message-handlers/trigger-wallet-tx-handler.js.map +1 -0
- package/dist/handlers/message-handlers/unsubscribe-response-handler.d.ts +12 -6
- package/dist/handlers/message-handlers/unsubscribe-response-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/user-authenticated-handler.js +2 -2
- package/dist/handlers/message-handlers/user-authenticated-handler.js.map +1 -1
- package/dist/handlers/message-handlers/user-count-handler.js +2 -2
- package/dist/handlers/message-handlers/user-count-handler.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -4
- package/dist/index.js.map +1 -1
- package/dist/managers/admin-manager.d.ts +2 -0
- package/dist/managers/admin-manager.d.ts.map +1 -1
- package/dist/managers/admin-manager.js +3 -2
- package/dist/managers/admin-manager.js.map +1 -1
- package/dist/managers/agent-room-manager.d.ts +89 -11
- package/dist/managers/agent-room-manager.d.ts.map +1 -1
- package/dist/managers/agent-room-manager.js +99 -35
- package/dist/managers/agent-room-manager.js.map +1 -1
- package/dist/managers/index.d.ts +1 -1
- package/dist/managers/index.d.ts.map +1 -1
- package/dist/managers/index.js.map +1 -1
- package/dist/managers/message-router.d.ts +45 -5
- package/dist/managers/message-router.d.ts.map +1 -1
- package/dist/managers/message-router.js +96 -24
- package/dist/managers/message-router.js.map +1 -1
- package/dist/managers/room-manager.d.ts +29 -7
- package/dist/managers/room-manager.d.ts.map +1 -1
- package/dist/managers/room-manager.js +37 -11
- package/dist/managers/room-manager.js.map +1 -1
- package/dist/payments/index.d.ts +3 -1
- package/dist/payments/index.d.ts.map +1 -1
- package/dist/payments/index.js +17 -3
- package/dist/payments/index.js.map +1 -1
- package/dist/payments/networks.d.ts +59 -0
- package/dist/payments/networks.d.ts.map +1 -0
- package/dist/payments/networks.js +192 -0
- package/dist/payments/networks.js.map +1 -0
- package/dist/payments/payment-client.d.ts +55 -10
- package/dist/payments/payment-client.d.ts.map +1 -1
- package/dist/payments/payment-client.js +172 -51
- package/dist/payments/payment-client.js.map +1 -1
- package/dist/teneo-sdk.d.ts +214 -40
- package/dist/teneo-sdk.d.ts.map +1 -1
- package/dist/teneo-sdk.js +360 -83
- package/dist/teneo-sdk.js.map +1 -1
- package/dist/types/config.d.ts +334 -25
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js +114 -22
- package/dist/types/config.js.map +1 -1
- package/dist/types/events.d.ts +60 -14
- package/dist/types/events.d.ts.map +1 -1
- package/dist/types/events.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +11 -4
- package/dist/types/index.js.map +1 -1
- package/dist/types/messages.d.ts +9801 -7222
- package/dist/types/messages.d.ts.map +1 -1
- package/dist/types/messages.js +180 -40
- package/dist/types/messages.js.map +1 -1
- package/dist/utils/pricing-resolver.d.ts +1 -1
- package/dist/utils/pricing-resolver.d.ts.map +1 -1
- package/dist/utils/pricing-resolver.js +9 -1
- package/dist/utils/pricing-resolver.js.map +1 -1
- package/examples/agent-room-management-example.ts +5 -5
- package/examples/basic-usage.ts +26 -6
- package/examples/claude-agent-x-follower/index.ts +1 -1
- package/examples/minimal-chat.ts +4 -3
- package/examples/n8n-teneo/index.ts +2 -2
- package/examples/nestjs-dashboard/README.md +1 -1
- package/examples/nestjs-dashboard/src/teneo/agents.controller.ts +3 -3
- package/examples/nestjs-dashboard/src/teneo/rooms.controller.ts +5 -5
- package/examples/nestjs-dashboard/src/teneo/teneo.service.ts +8 -8
- package/examples/openai-teneo/index.ts +1 -1
- package/examples/payment-flow.ts +143 -0
- package/examples/production-dashboard/README.md +6 -8
- package/examples/production-dashboard/server.ts +22 -10
- package/examples/room-management-example.ts +2 -2
- package/examples/usage/01-connect.ts +0 -3
- package/examples/usage/02-list-agents.ts +0 -2
- package/examples/usage/03-pick-agent.ts +3 -4
- package/examples/usage/04-find-by-capability.ts +10 -12
- package/examples/usage/05-webhook-example.ts +2 -4
- package/examples/usage/06-simple-api-server.ts +13 -9
- package/examples/usage/07-event-listener.ts +1 -13
- package/examples/usage/README.md +33 -7
- package/examples/webhook-integration.ts +9 -9
- package/examples/x-influencer-battle-server.ts +1 -1
- package/package.json +1 -1
- package/scripts/diagnose-connection.ts +86 -0
- package/scripts/investigate-payload.ts +163 -0
- package/scripts/list-agents.ts +58 -0
- package/scripts/live-multi-network-test.ts +230 -0
- package/src/constants.ts +5 -3
- package/src/core/websocket-client.ts +10 -9
- package/src/handlers/message-handlers/agent-details-response-handler.ts +2 -2
- package/src/handlers/message-handlers/agent-error-handler.ts +47 -0
- package/src/handlers/message-handlers/agent-status-update-handler.ts +2 -7
- package/src/handlers/message-handlers/all-agents-response-handler.ts +2 -2
- package/src/handlers/message-handlers/auth-message-handler.ts +7 -1
- package/src/handlers/message-handlers/auth-success-handler.ts +7 -1
- package/src/handlers/message-handlers/base-handler.ts +24 -4
- package/src/handlers/message-handlers/index.ts +24 -0
- package/src/handlers/message-handlers/list-available-agents-handler.ts +24 -11
- package/src/handlers/message-handlers/list-room-agents-handler.ts +2 -6
- package/src/handlers/message-handlers/list-rooms-response-handler.ts +2 -5
- package/src/handlers/message-handlers/ping-pong-handler.ts +29 -4
- package/src/handlers/message-handlers/rate-limit-notification-handler.ts +3 -2
- package/src/handlers/message-handlers/success-handler.ts +26 -0
- package/src/handlers/message-handlers/task-confirmed-handler.ts +49 -0
- package/src/handlers/message-handlers/trigger-wallet-tx-handler.ts +62 -0
- package/src/handlers/message-handlers/user-authenticated-handler.ts +2 -2
- package/src/handlers/message-handlers/user-count-handler.ts +2 -2
- package/src/index.ts +12 -4
- package/src/managers/admin-manager.ts +5 -2
- package/src/managers/agent-room-manager.ts +155 -26
- package/src/managers/index.ts +6 -1
- package/src/managers/message-router.ts +122 -27
- package/src/managers/room-manager.ts +39 -11
- package/src/payments/index.ts +20 -5
- package/src/payments/networks.ts +208 -0
- package/src/payments/payment-client.ts +211 -56
- package/src/teneo-sdk.ts +401 -70
- package/src/types/config.test.ts +24 -4
- package/src/types/config.ts +123 -25
- package/src/types/events.ts +36 -2
- package/src/types/index.ts +16 -3
- package/src/types/messages.ts +221 -57
- package/src/utils/pricing-resolver.ts +10 -2
- package/tests/direct-agent-test.ts +1 -1
- package/tests/integration/real-server.test.ts +1 -1
- package/tests/integration/websocket.test.ts +3 -3
- package/tests/multi-network-payment.test.ts +309 -0
- package/tests/multi-network.test.ts +296 -0
- package/tests/payment-flow-test.ts +6 -4
- package/tests/unit/handlers/agent-error-handler.test.ts +388 -0
- package/tests/unit/handlers/agent-room-operation-response-handler.test.ts +9 -6
- package/tests/unit/handlers/agent-status-update-handler.test.ts +11 -16
- package/tests/unit/handlers/list-available-agents-handler.test.ts +11 -14
- package/tests/unit/handlers/list-room-agents-handler.test.ts +11 -15
- package/tests/unit/handlers/room-operation-response-handler.test.ts +9 -6
- package/tests/unit/handlers/trigger-wallet-tx-handler.test.ts +431 -0
- package/tests/unit/managers/admin-manager.test.ts +183 -0
- package/tests/unit/managers/agent-room-manager.test.ts +189 -33
- package/tests/unit/sdk-new-methods.test.ts +221 -0
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**Connect your app to the Teneo AI Agent Network**
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.com/package/@teneo-protocol/sdk)
|
|
6
6
|
[](https://www.typescriptlang.org/)
|
|
7
7
|
[](https://nodejs.org/)
|
|
8
8
|
[](/)
|
|
@@ -15,6 +15,30 @@ The Teneo Protocol SDK lets you connect your application to a **decentralized ne
|
|
|
15
15
|
|
|
16
16
|
---
|
|
17
17
|
|
|
18
|
+
## 🎉 What's New in v3.0
|
|
19
|
+
|
|
20
|
+
Version 3.0 introduces **API Naming Improvements** for better clarity and consistency:
|
|
21
|
+
|
|
22
|
+
### 📝 Clearer Method Names
|
|
23
|
+
|
|
24
|
+
All method names have been improved to be more explicit and intuitive:
|
|
25
|
+
|
|
26
|
+
- **Room subscriptions** - `subscribeToPublicRoom()` makes it clear these only work for public rooms
|
|
27
|
+
- **Cache-only methods** - `getCached*()` prefix makes sync vs async operations obvious
|
|
28
|
+
- **Boolean semantics** - `checkAgentInRoom()` clearly indicates it may return `undefined`
|
|
29
|
+
- **Search scope** - `findAvailableAgentsBy*()` clarifies network-wide search
|
|
30
|
+
|
|
31
|
+
### 🔄 Fully Backward Compatible
|
|
32
|
+
|
|
33
|
+
**All old method names still work!** They're deprecated with helpful aliases:
|
|
34
|
+
- Old names forward to new implementations
|
|
35
|
+
- TypeScript shows deprecation warnings
|
|
36
|
+
- Migrate at your convenience
|
|
37
|
+
|
|
38
|
+
[Jump to Migration Guide](#v300-migration-guide) | [See Full CHANGELOG](CHANGELOG.md#300---2026-01-28)
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
18
42
|
## 🚀 Quickstart
|
|
19
43
|
|
|
20
44
|
### Installation
|
|
@@ -47,63 +71,54 @@ const rooms = sdk.getRooms();
|
|
|
47
71
|
const roomId = rooms[0].id;
|
|
48
72
|
|
|
49
73
|
// 5. Send a message to a room
|
|
74
|
+
|
|
75
|
+
// WITH COORDINATOR (when available):
|
|
50
76
|
await sdk.sendMessage("Give me the last 5 tweets from @elonmusk", {
|
|
51
77
|
room: roomId
|
|
52
78
|
});
|
|
79
|
+
// → Coordinator selects best agent automatically
|
|
53
80
|
|
|
54
|
-
//
|
|
81
|
+
// WITHOUT COORDINATOR (direct command required):
|
|
82
|
+
await sdk.sendMessage("@X Platform Agent search bitcoin 5", {
|
|
83
|
+
room: roomId
|
|
84
|
+
});
|
|
85
|
+
// → Direct command to specific agent by name
|
|
55
86
|
```
|
|
56
87
|
|
|
57
88
|
**That's it!** After authentication:
|
|
58
89
|
|
|
59
90
|
1. Your private rooms are automatically available
|
|
60
91
|
2. Send messages to any room by ID
|
|
61
|
-
3.
|
|
62
|
-
4.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
[
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
- **Create multiple rooms** for different contexts (crypto, gaming, research, etc.)
|
|
88
|
-
- **Update and delete** your owned rooms
|
|
89
|
-
- **Track room limits** based on your subscription tier
|
|
90
|
-
- **Invite members** to your rooms (coming soon)
|
|
91
|
-
|
|
92
|
-
### 🤖 Agent Room Management
|
|
93
|
-
|
|
94
|
-
- **Customize which agents** are available in each room
|
|
95
|
-
- **Add/remove agents** from your owned rooms
|
|
96
|
-
- **List room agents** with caching for performance
|
|
97
|
-
- **Real-time agent status updates** for room availability
|
|
98
|
-
|
|
99
|
-
### 📊 Enhanced APIs
|
|
100
|
-
|
|
101
|
-
- 8 new room management methods
|
|
102
|
-
- 8 new agent-room management methods
|
|
103
|
-
- 14 new events for room and agent operations
|
|
104
|
-
- Intelligent caching with 5-minute TTL
|
|
92
|
+
3. **With coordinator**: Use natural language - coordinator routes to best agent
|
|
93
|
+
4. **Without coordinator**: Use `@Agent Name command params` syntax to target specific agents
|
|
94
|
+
5. Responses arrive via the event listener
|
|
95
|
+
|
|
96
|
+
### Message Routing Flow
|
|
97
|
+
|
|
98
|
+
The SDK supports two routing approaches depending on your environment:
|
|
99
|
+
|
|
100
|
+
```mermaid
|
|
101
|
+
graph TB
|
|
102
|
+
UserMessage[User Message]
|
|
103
|
+
CheckEnv{Environment Has<br/>Coordinator?}
|
|
104
|
+
CoordPath[Coordinator Routing]
|
|
105
|
+
DirectPath[Direct Routing]
|
|
106
|
+
CoordSelect[Coordinator Selects<br/>Best Agent]
|
|
107
|
+
DirectTarget[Direct to<br/>Named Agent]
|
|
108
|
+
Agent[Agent Processes<br/>Request]
|
|
109
|
+
|
|
110
|
+
UserMessage --> CheckEnv
|
|
111
|
+
CheckEnv -->|Yes| CoordPath
|
|
112
|
+
CheckEnv -->|No| DirectPath
|
|
113
|
+
CoordPath -->|"Natural language<br/>supported"| CoordSelect
|
|
114
|
+
DirectPath -->|"@Agent Name required"| DirectTarget
|
|
115
|
+
CoordSelect --> Agent
|
|
116
|
+
DirectTarget --> Agent
|
|
117
|
+
```
|
|
105
118
|
|
|
106
|
-
|
|
119
|
+
**Key Differences:**
|
|
120
|
+
- **Coordinator environments**: Both natural language and direct commands work
|
|
121
|
+
- **Non-coordinator environments**: Must use `@Agent Name command params` syntax
|
|
107
122
|
|
|
108
123
|
---
|
|
109
124
|
|
|
@@ -229,23 +244,33 @@ Organize agents by context using rooms:
|
|
|
229
244
|
const sdk = new TeneoSDK({
|
|
230
245
|
wsUrl: process.env.TENEO_WS_URL!,
|
|
231
246
|
privateKey: process.env.PRIVATE_KEY!,
|
|
232
|
-
|
|
247
|
+
autoJoinPublicRooms: ["crawler-room-id", "kol-tracker-room-id"] // public rooms only
|
|
233
248
|
});
|
|
234
249
|
|
|
235
250
|
// Each room may have different agents available
|
|
251
|
+
// Note: Private rooms are automatically available after auth
|
|
236
252
|
await sdk.connect();
|
|
237
253
|
|
|
238
254
|
// Send to specific room contexts
|
|
239
|
-
await sdk.sendMessage("Get latest tweets from @elonmusk", { room: "KOL tracker" });
|
|
240
|
-
// → Routed to X Agent in KOL tracker room
|
|
241
255
|
|
|
242
|
-
|
|
243
|
-
|
|
256
|
+
// WITH COORDINATOR:
|
|
257
|
+
await sdk.sendMessage("Get latest tweets from @elonmusk", { room: "kol-tracker-room-id" });
|
|
258
|
+
// → Coordinator routes to best agent in room
|
|
259
|
+
|
|
260
|
+
await sdk.sendMessage("Crawl this website for data", { room: "crawler-room-id" });
|
|
261
|
+
// → Coordinator routes to best agent in room
|
|
262
|
+
|
|
263
|
+
// WITHOUT COORDINATOR (direct commands required):
|
|
264
|
+
await sdk.sendMessage("@X Platform Agent timeline @elonmusk 5", { room: "kol-tracker-room-id" });
|
|
265
|
+
// → Direct to X Platform Agent in room
|
|
266
|
+
|
|
267
|
+
await sdk.sendMessage("@Web Crawler Agent crawl https://example.com", { room: "crawler-room-id" });
|
|
268
|
+
// → Direct to Web Crawler Agent in room
|
|
244
269
|
|
|
245
270
|
// Manage rooms dynamically
|
|
246
271
|
const rooms = sdk.getSubscribedRooms();
|
|
247
272
|
console.log("Active rooms:", rooms);
|
|
248
|
-
// Output: Active rooms: ['
|
|
273
|
+
// Output: Active rooms: ['crawler-room-id', 'kol-tracker-room-id']
|
|
249
274
|
```
|
|
250
275
|
|
|
251
276
|
### Example 3: Webhook Integration
|
|
@@ -300,8 +325,8 @@ await sdk.connect();
|
|
|
300
325
|
|
|
301
326
|
// Check webhook health
|
|
302
327
|
const status = sdk.getWebhookStatus();
|
|
303
|
-
console.log("
|
|
304
|
-
console.log("Circuit state:", status.circuitState); // OPEN/CLOSED/HALF_OPEN
|
|
328
|
+
console.log("Pending:", status.queue.pending);
|
|
329
|
+
console.log("Circuit state:", status.queue.circuitState); // OPEN/CLOSED/HALF_OPEN
|
|
305
330
|
```
|
|
306
331
|
|
|
307
332
|
---
|
|
@@ -327,7 +352,7 @@ TENEO_WS_URL=wss://backend.developer.chatroom.teneo-protocol.ai/ws
|
|
|
327
352
|
- **URL**: `wss://backend.chatroom.teneo-protocol.ai/ws`
|
|
328
353
|
- **Whitelist**: **Required** - you must be whitelisted to use this endpoint
|
|
329
354
|
- **Use case**: Production applications and B2B integrations
|
|
330
|
-
- **Get access**: Request whitelist access at [https://teneo-protocol.ai/
|
|
355
|
+
- **Get access**: Request whitelist access at [https://teneo-protocol.ai/data-access](https://teneo-protocol.ai/data-access)
|
|
331
356
|
|
|
332
357
|
**Configuration:**
|
|
333
358
|
```bash
|
|
@@ -380,7 +405,7 @@ const allRooms = sdk.getAllRooms();
|
|
|
380
405
|
console.log(`Total rooms accessible: ${allRooms.length}`);
|
|
381
406
|
|
|
382
407
|
// Get specific room by ID
|
|
383
|
-
const room = sdk.
|
|
408
|
+
const room = sdk.getRoom("room-123");
|
|
384
409
|
if (room) {
|
|
385
410
|
console.log(`Room: ${room.name}`);
|
|
386
411
|
console.log(`Created by: ${room.created_by}`);
|
|
@@ -513,23 +538,23 @@ available.forEach((agent) => {
|
|
|
513
538
|
|
|
514
539
|
```typescript
|
|
515
540
|
// Check if specific agent is in room (instant, no network call)
|
|
516
|
-
const
|
|
517
|
-
if (
|
|
541
|
+
const inRoom = sdk.checkAgentInRoom("room-123", "agent-456");
|
|
542
|
+
if (inRoom === true) {
|
|
518
543
|
console.log("Agent is in the room");
|
|
519
|
-
} else if (
|
|
544
|
+
} else if (inRoom === false) {
|
|
520
545
|
console.log("Agent is NOT in the room");
|
|
521
546
|
} else {
|
|
522
547
|
console.log("Cache not available - call listRoomAgents() first");
|
|
523
548
|
}
|
|
524
549
|
|
|
525
550
|
// Get room agent count (instant)
|
|
526
|
-
const count = sdk.
|
|
551
|
+
const count = sdk.getCachedRoomAgentCount("room-123");
|
|
527
552
|
if (count !== undefined) {
|
|
528
553
|
console.log(`Room has ${count} agents`);
|
|
529
554
|
}
|
|
530
555
|
|
|
531
556
|
// Get cached room agents (instant)
|
|
532
|
-
const cached = sdk.
|
|
557
|
+
const cached = sdk.getCachedRoomAgents("room-123");
|
|
533
558
|
if (cached) {
|
|
534
559
|
console.log("Agents:", cached.map((a) => a.agent_name).join(", "));
|
|
535
560
|
} else {
|
|
@@ -537,7 +562,7 @@ if (cached) {
|
|
|
537
562
|
}
|
|
538
563
|
|
|
539
564
|
// Get cached available agents (instant)
|
|
540
|
-
const cachedAvailable = sdk.
|
|
565
|
+
const cachedAvailable = sdk.getCachedAvailableAgents("room-123");
|
|
541
566
|
```
|
|
542
567
|
|
|
543
568
|
### Cache Management
|
|
@@ -593,8 +618,8 @@ sdk.on("agent_room:list_error", (error, roomId) => {
|
|
|
593
618
|
console.error(`Failed to list agents in ${roomId}: ${error.message}`);
|
|
594
619
|
});
|
|
595
620
|
|
|
596
|
-
sdk.on("agent_room:list_available_error", (error
|
|
597
|
-
console.error(`Failed to list available agents
|
|
621
|
+
sdk.on("agent_room:list_available_error", (error) => {
|
|
622
|
+
console.error(`Failed to list available agents: ${error.message}`);
|
|
598
623
|
});
|
|
599
624
|
```
|
|
600
625
|
|
|
@@ -655,7 +680,7 @@ import { TeneoSDK } from "@teneo-protocol/sdk";
|
|
|
655
680
|
// Enable payments with auto-approve
|
|
656
681
|
const sdk = new TeneoSDK(
|
|
657
682
|
TeneoSDK.builder()
|
|
658
|
-
.withWebSocketUrl(
|
|
683
|
+
.withWebSocketUrl(process.env.TENEO_WS_URL!)
|
|
659
684
|
.withAuthentication(process.env.PRIVATE_KEY!)
|
|
660
685
|
.withPayments({
|
|
661
686
|
autoApprove: true, // Automatically approve quotes
|
|
@@ -667,7 +692,7 @@ const sdk = new TeneoSDK(
|
|
|
667
692
|
await sdk.connect();
|
|
668
693
|
|
|
669
694
|
// Send message - payment handled automatically
|
|
670
|
-
const response = await sdk.sendMessage("@
|
|
695
|
+
const response = await sdk.sendMessage("@X Platform Agent user @elonmusk", {
|
|
671
696
|
room: roomId,
|
|
672
697
|
waitForResponse: true
|
|
673
698
|
});
|
|
@@ -676,20 +701,367 @@ console.log(response.humanized);
|
|
|
676
701
|
// Output: User profile for @elonmusk...
|
|
677
702
|
```
|
|
678
703
|
|
|
704
|
+
> **Note:** The builder uses `withPayments({ autoApprove: true })` while the plain config object uses `autoApproveQuotes: true`. Both control the same behavior. The builder also accepts `maxPricePerRequest` and `quoteTimeout`.
|
|
705
|
+
|
|
706
|
+
### Multi-Network Support (v2.3)
|
|
707
|
+
|
|
708
|
+
The SDK supports USDC payments across multiple EVM networks with **dynamic configuration**. Network configurations are automatically fetched from the backend during `connect()`, enabling the protocol to add new networks without requiring SDK updates.
|
|
709
|
+
|
|
710
|
+
#### Dynamic Network Configuration
|
|
711
|
+
|
|
712
|
+
Networks are initialized automatically when you connect:
|
|
713
|
+
|
|
714
|
+
```typescript
|
|
715
|
+
import { TeneoSDK, NETWORKS, getSupportedNetworks } from "@teneo-protocol/sdk";
|
|
716
|
+
|
|
717
|
+
const sdk = new TeneoSDK({
|
|
718
|
+
wsUrl: "wss://teneo.network/ws",
|
|
719
|
+
privateKey: "0x..."
|
|
720
|
+
});
|
|
721
|
+
|
|
722
|
+
// Before connect: NETWORKS is empty
|
|
723
|
+
console.log(NETWORKS); // {}
|
|
724
|
+
|
|
725
|
+
// Networks fetched during connect from backend /api/networks
|
|
726
|
+
await sdk.connect();
|
|
727
|
+
|
|
728
|
+
// After connect: NETWORKS populated with backend configuration
|
|
729
|
+
console.log(NETWORKS); // { peaq: {...}, base: {...}, avalanche: {...} }
|
|
730
|
+
const networks = getSupportedNetworks(); // ["peaq", "base", "avalanche"]
|
|
731
|
+
```
|
|
732
|
+
|
|
733
|
+
**Key Features:**
|
|
734
|
+
- 🔄 **Automatic fetch** from backend `/api/networks` endpoint during `connect()`
|
|
735
|
+
- ⚡ **60-minute cache** with automatic refresh
|
|
736
|
+
- 🛡️ **Offline resilience** - falls back to cached configs if backend temporarily unavailable
|
|
737
|
+
- 🚀 **Future-proof** - new networks can be added server-side without SDK updates
|
|
738
|
+
|
|
739
|
+
#### Querying Network Information
|
|
740
|
+
|
|
741
|
+
```typescript
|
|
742
|
+
import {
|
|
743
|
+
NETWORKS,
|
|
744
|
+
getNetwork,
|
|
745
|
+
getDefaultNetwork,
|
|
746
|
+
getSupportedNetworks,
|
|
747
|
+
isNetworkSupported,
|
|
748
|
+
createChainDefinition
|
|
749
|
+
} from "@teneo-protocol/sdk";
|
|
750
|
+
|
|
751
|
+
// Must be called after connect()
|
|
752
|
+
await sdk.connect();
|
|
753
|
+
|
|
754
|
+
// Get all supported networks (dynamically loaded from backend)
|
|
755
|
+
const networks = getSupportedNetworks();
|
|
756
|
+
console.log(networks); // e.g., ["peaq", "base", "avalanche"]
|
|
757
|
+
|
|
758
|
+
// Get network by name
|
|
759
|
+
const baseNetwork = getNetwork("base");
|
|
760
|
+
|
|
761
|
+
// Get network by chain ID
|
|
762
|
+
const peaqNetwork = getNetwork(3338);
|
|
763
|
+
|
|
764
|
+
// Get network by CAIP-2 identifier
|
|
765
|
+
const avaxNetwork = getNetwork("eip155:43114");
|
|
766
|
+
|
|
767
|
+
console.log(baseNetwork);
|
|
768
|
+
// {
|
|
769
|
+
// chainId: 8453,
|
|
770
|
+
// name: "Base Mainnet",
|
|
771
|
+
// caip2: "eip155:8453",
|
|
772
|
+
// rpcUrl: "https://mainnet.base.org",
|
|
773
|
+
// usdcContract: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
774
|
+
// settlementRouter: "0x73fc659Cd5494E69852bE8D9D23FE05Aab14b29B",
|
|
775
|
+
// transferHook: "0x081258287F692D61575387ee2a4075f34dd7Aef7",
|
|
776
|
+
// eip712: { name: "USD Coin", version: "2" }
|
|
777
|
+
// }
|
|
778
|
+
|
|
779
|
+
// Check if a network is supported
|
|
780
|
+
if (isNetworkSupported("base")) {
|
|
781
|
+
// Create a viem chain definition
|
|
782
|
+
const baseChain = createChainDefinition(baseNetwork);
|
|
783
|
+
// Use with PaymentClient or other viem-based operations
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
// Get default network (prefers PEAQ, falls back to first available)
|
|
787
|
+
const defaultNetwork = getDefaultNetwork();
|
|
788
|
+
```
|
|
789
|
+
|
|
790
|
+
#### Current Networks
|
|
791
|
+
|
|
792
|
+
These networks are currently supported (fetched dynamically from backend):
|
|
793
|
+
|
|
794
|
+
**PEAQ Mainnet (chainId: 3338)**
|
|
795
|
+
- Original Teneo network
|
|
796
|
+
- USDC contract, settlement router, transfer hook configured via backend
|
|
797
|
+
|
|
798
|
+
**Base Mainnet (chainId: 8453)**
|
|
799
|
+
- Layer 2 scaling solution
|
|
800
|
+
- Lower gas fees, faster transactions
|
|
801
|
+
|
|
802
|
+
**Avalanche Mainnet (chainId: 43114)**
|
|
803
|
+
- High-throughput blockchain
|
|
804
|
+
- Sub-second finality
|
|
805
|
+
|
|
806
|
+
> **Note:** Network configurations are fetched from the backend and may change. Use `getSupportedNetworks()` to get the current list. The SDK automatically handles network selection based on agent requirements.
|
|
807
|
+
|
|
808
|
+
#### Settlement Router Integration (x402 v2.5)
|
|
809
|
+
|
|
810
|
+
Payment quotes now include settlement router information for enhanced payment routing:
|
|
811
|
+
|
|
812
|
+
```typescript
|
|
813
|
+
// Request a quote
|
|
814
|
+
const quote = await sdk.requestQuote("Analyze this data", "room-id");
|
|
815
|
+
|
|
816
|
+
// Quote includes settlement router fields (x402 v2.5)
|
|
817
|
+
console.log(quote.data.settlement_router); // Router contract address
|
|
818
|
+
console.log(quote.data.salt); // Unique transaction salt
|
|
819
|
+
console.log(quote.data.facilitator_fee); // Facilitator fee amount
|
|
820
|
+
console.log(quote.data.hook); // Transfer hook address
|
|
821
|
+
console.log(quote.data.hook_data); // Optional hook data (default: "0x")
|
|
822
|
+
```
|
|
823
|
+
|
|
824
|
+
> **Note:** The SDK automatically handles network selection. The payment server determines which network to use based on the agent's configuration. You don't need to manually configure networks unless you're using the `PaymentClient` directly for custom payment operations.
|
|
825
|
+
|
|
826
|
+
#### Configuring Default Payment Network
|
|
827
|
+
|
|
828
|
+
You can configure which network to use for all payments in three ways:
|
|
829
|
+
|
|
830
|
+
**Option 1: Using Environment Variable (Global Default)**
|
|
831
|
+
|
|
832
|
+
```bash
|
|
833
|
+
# Set default network for all payments
|
|
834
|
+
export TENEO_NETWORK=base
|
|
835
|
+
|
|
836
|
+
# Or use chain ID
|
|
837
|
+
export TENEO_NETWORK=8453
|
|
838
|
+
|
|
839
|
+
# Or use CAIP-2 format
|
|
840
|
+
export TENEO_NETWORK=eip155:8453
|
|
841
|
+
```
|
|
842
|
+
|
|
843
|
+
```typescript
|
|
844
|
+
import { TeneoSDK } from "@teneo-protocol/sdk";
|
|
845
|
+
|
|
846
|
+
// SDK automatically uses TENEO_NETWORK env var
|
|
847
|
+
const sdk = new TeneoSDK(
|
|
848
|
+
TeneoSDK.builder()
|
|
849
|
+
.withWebSocketUrl(process.env.TENEO_WS_URL!)
|
|
850
|
+
.withAuthentication(process.env.PRIVATE_KEY!)
|
|
851
|
+
.withPayments({ autoApprove: true })
|
|
852
|
+
.build()
|
|
853
|
+
);
|
|
854
|
+
|
|
855
|
+
// All payments will use Base network (from TENEO_NETWORK)
|
|
856
|
+
```
|
|
857
|
+
|
|
858
|
+
**Option 2: Using Config Builder (Per-SDK Instance)**
|
|
859
|
+
|
|
860
|
+
```typescript
|
|
861
|
+
import { TeneoSDK } from "@teneo-protocol/sdk";
|
|
862
|
+
|
|
863
|
+
// Configure Base network for this SDK instance
|
|
864
|
+
const sdk = new TeneoSDK(
|
|
865
|
+
TeneoSDK.builder()
|
|
866
|
+
.withWebSocketUrl(process.env.TENEO_WS_URL!)
|
|
867
|
+
.withAuthentication(process.env.PRIVATE_KEY!)
|
|
868
|
+
.withPayments({ autoApprove: true })
|
|
869
|
+
.withNetwork("base") // Use Base Mainnet
|
|
870
|
+
.build()
|
|
871
|
+
);
|
|
872
|
+
|
|
873
|
+
// All payments from this SDK will use Base network
|
|
874
|
+
```
|
|
875
|
+
|
|
876
|
+
Or using chain ID:
|
|
877
|
+
|
|
878
|
+
```typescript
|
|
879
|
+
const sdk = new TeneoSDK(
|
|
880
|
+
TeneoSDK.builder()
|
|
881
|
+
.withWebSocketUrl(process.env.TENEO_WS_URL!)
|
|
882
|
+
.withAuthentication(process.env.PRIVATE_KEY!)
|
|
883
|
+
.withPayments({ autoApprove: true })
|
|
884
|
+
.withNetworkChainId(43114) // Use Avalanche (chain ID 43114)
|
|
885
|
+
.build()
|
|
886
|
+
);
|
|
887
|
+
```
|
|
888
|
+
|
|
889
|
+
**Network Selection Priority:**
|
|
890
|
+
|
|
891
|
+
The SDK uses this priority order for network selection:
|
|
892
|
+
1. **Per-request network override** via `sendDirectCommand({ network: "base" })` or `sendMessage({ network: "base" })`
|
|
893
|
+
2. Builder `.withNetwork()` or `.withNetworkChainId()` setting
|
|
894
|
+
3. `TENEO_NETWORK` environment variable
|
|
895
|
+
4. Default: PEAQ network (eip155:3338)
|
|
896
|
+
|
|
897
|
+
**Example: Per-Request Network Override (Recommended)**
|
|
898
|
+
|
|
899
|
+
Send commands to different chains from a single SDK instance:
|
|
900
|
+
|
|
901
|
+
```typescript
|
|
902
|
+
const sdk = new TeneoSDK(
|
|
903
|
+
TeneoSDK.builder()
|
|
904
|
+
.withWebSocketUrl(process.env.TENEO_WS_URL!)
|
|
905
|
+
.withAuthentication(process.env.PRIVATE_KEY!)
|
|
906
|
+
.withPayments({ autoApprove: true, maxPricePerRequest: 1000000 })
|
|
907
|
+
.build()
|
|
908
|
+
);
|
|
909
|
+
|
|
910
|
+
await sdk.connect();
|
|
911
|
+
const roomId = sdk.getRooms()[0].id;
|
|
912
|
+
|
|
913
|
+
// Pay on PEAQ
|
|
914
|
+
await sdk.sendDirectCommand({
|
|
915
|
+
agent: "x-agent-enterprise-v2",
|
|
916
|
+
command: "user @elonmusk",
|
|
917
|
+
room: roomId,
|
|
918
|
+
network: "peaq", // Per-request network override
|
|
919
|
+
}, true);
|
|
920
|
+
|
|
921
|
+
// Pay on Base
|
|
922
|
+
await sdk.sendDirectCommand({
|
|
923
|
+
agent: "x-agent-enterprise-v2",
|
|
924
|
+
command: "user @elonmusk",
|
|
925
|
+
room: roomId,
|
|
926
|
+
network: "base", // Per-request network override
|
|
927
|
+
}, true);
|
|
928
|
+
|
|
929
|
+
// Pay on Avalanche
|
|
930
|
+
await sdk.sendDirectCommand({
|
|
931
|
+
agent: "x-agent-enterprise-v2",
|
|
932
|
+
command: "user @elonmusk",
|
|
933
|
+
room: roomId,
|
|
934
|
+
network: "avalanche", // Per-request network override
|
|
935
|
+
}, true);
|
|
936
|
+
```
|
|
937
|
+
|
|
938
|
+
You can also pass a chain ID instead of a name:
|
|
939
|
+
|
|
940
|
+
```typescript
|
|
941
|
+
await sdk.sendDirectCommand({
|
|
942
|
+
agent: "x-agent-enterprise-v2",
|
|
943
|
+
command: "user @elonmusk",
|
|
944
|
+
room: roomId,
|
|
945
|
+
network: 8453, // Base by chain ID
|
|
946
|
+
}, true);
|
|
947
|
+
```
|
|
948
|
+
|
|
949
|
+
The same works with `sendMessage`:
|
|
950
|
+
|
|
951
|
+
```typescript
|
|
952
|
+
await sdk.sendMessage("@X Platform Agent user @elonmusk", {
|
|
953
|
+
room: roomId,
|
|
954
|
+
waitForResponse: true,
|
|
955
|
+
network: "avalanche", // Per-request network override
|
|
956
|
+
});
|
|
957
|
+
```
|
|
958
|
+
|
|
959
|
+
**Example: Multiple SDK Instances with Different Networks**
|
|
960
|
+
|
|
961
|
+
For cases where you want a fixed default per SDK instance:
|
|
962
|
+
|
|
963
|
+
```typescript
|
|
964
|
+
// Production bot uses PEAQ
|
|
965
|
+
const peaqBot = new TeneoSDK(
|
|
966
|
+
TeneoSDK.builder()
|
|
967
|
+
.withWebSocketUrl(process.env.TENEO_WS_URL!)
|
|
968
|
+
.withAuthentication(process.env.PEAQ_PRIVATE_KEY!)
|
|
969
|
+
.withPayments({ autoApprove: true })
|
|
970
|
+
.withNetwork("peaq")
|
|
971
|
+
.build()
|
|
972
|
+
);
|
|
973
|
+
|
|
974
|
+
// Experimental bot uses Base
|
|
975
|
+
const baseBot = new TeneoSDK(
|
|
976
|
+
TeneoSDK.builder()
|
|
977
|
+
.withWebSocketUrl(process.env.TENEO_WS_URL!)
|
|
978
|
+
.withAuthentication(process.env.BASE_PRIVATE_KEY!)
|
|
979
|
+
.withPayments({ autoApprove: true })
|
|
980
|
+
.withNetwork("base")
|
|
981
|
+
.build()
|
|
982
|
+
);
|
|
983
|
+
|
|
984
|
+
// High-throughput bot uses Avalanche
|
|
985
|
+
const avalancheBot = new TeneoSDK(
|
|
986
|
+
TeneoSDK.builder()
|
|
987
|
+
.withWebSocketUrl(process.env.TENEO_WS_URL!)
|
|
988
|
+
.withAuthentication(process.env.AVALANCHE_PRIVATE_KEY!)
|
|
989
|
+
.withPayments({ autoApprove: true })
|
|
990
|
+
.withNetwork("avalanche")
|
|
991
|
+
.build()
|
|
992
|
+
);
|
|
993
|
+
```
|
|
994
|
+
|
|
679
995
|
### Direct Agent Commands
|
|
680
996
|
|
|
997
|
+
#### When to Use Direct Commands
|
|
998
|
+
|
|
999
|
+
Direct agent commands allow you to target a specific agent by name using the `@Agent Name command params` syntax:
|
|
1000
|
+
|
|
1001
|
+
- **Required** in non-coordinator environments (direct commands are the only way to communicate)
|
|
1002
|
+
- **Optional** in coordinator environments (gives you explicit control over which agent handles the request)
|
|
1003
|
+
|
|
1004
|
+
#### Syntax Options
|
|
1005
|
+
|
|
681
1006
|
```typescript
|
|
682
|
-
//
|
|
683
|
-
await sdk.sendMessage("@
|
|
1007
|
+
// Option 1: Use @mention syntax via sendMessage (recommended)
|
|
1008
|
+
await sdk.sendMessage("@X Platform Agent search bitcoin 5", {
|
|
684
1009
|
room: roomId,
|
|
685
1010
|
waitForResponse: true
|
|
686
1011
|
});
|
|
687
1012
|
|
|
688
|
-
//
|
|
1013
|
+
// Option 2: Use sendDirectCommand for programmatic control
|
|
1014
|
+
const response = await sdk.sendDirectCommand({
|
|
1015
|
+
agent: "X Platform Agent",
|
|
1016
|
+
command: "timeline @elonmusk 5",
|
|
1017
|
+
room: roomId
|
|
1018
|
+
}, true); // waitForResponse
|
|
1019
|
+
|
|
1020
|
+
console.log(response.humanized);
|
|
1021
|
+
|
|
1022
|
+
// Option 3: With per-request network override
|
|
1023
|
+
const response = await sdk.sendDirectCommand({
|
|
1024
|
+
agent: "X Platform Agent",
|
|
1025
|
+
command: "user @elonmusk",
|
|
1026
|
+
room: roomId,
|
|
1027
|
+
network: "base", // Per-request network override (peaq, base, avalanche, or chain ID)
|
|
1028
|
+
}, true);
|
|
1029
|
+
|
|
1030
|
+
// Option 4: Fire-and-forget (no wait for response)
|
|
1031
|
+
await sdk.sendDirectCommand({
|
|
1032
|
+
agent: "X Platform Agent",
|
|
1033
|
+
command: "user @elonmusk",
|
|
1034
|
+
room: roomId
|
|
1035
|
+
});
|
|
1036
|
+
```
|
|
1037
|
+
|
|
1038
|
+
#### Environment-Specific Examples
|
|
1039
|
+
|
|
1040
|
+
```typescript
|
|
1041
|
+
// IN COORDINATOR ENVIRONMENTS (both work):
|
|
1042
|
+
|
|
1043
|
+
// Natural language - coordinator selects best agent
|
|
689
1044
|
await sdk.sendMessage("Get me the latest tweets from @elonmusk", {
|
|
690
1045
|
room: roomId,
|
|
691
1046
|
waitForResponse: true
|
|
692
1047
|
});
|
|
1048
|
+
|
|
1049
|
+
// Direct command - explicit agent selection
|
|
1050
|
+
await sdk.sendMessage("@X Platform Agent timeline @elonmusk 5", {
|
|
1051
|
+
room: roomId,
|
|
1052
|
+
waitForResponse: true
|
|
1053
|
+
});
|
|
1054
|
+
|
|
1055
|
+
// IN NON-COORDINATOR ENVIRONMENTS (direct commands required):
|
|
1056
|
+
|
|
1057
|
+
// Direct command - MUST specify agent name
|
|
1058
|
+
await sdk.sendMessage("@X Platform Agent search bitcoin 5", {
|
|
1059
|
+
room: roomId,
|
|
1060
|
+
waitForResponse: true
|
|
1061
|
+
});
|
|
1062
|
+
|
|
1063
|
+
// This will NOT work without coordinator:
|
|
1064
|
+
// ❌ await sdk.sendMessage("Get bitcoin info", { room: roomId });
|
|
693
1065
|
```
|
|
694
1066
|
|
|
695
1067
|
### Payment Events
|
|
@@ -707,6 +1079,11 @@ sdk.on("payment:attached", (data) => {
|
|
|
707
1079
|
console.log(`Paid ${data.amount / 1_000_000} USDC to ${data.agentId}`);
|
|
708
1080
|
});
|
|
709
1081
|
|
|
1082
|
+
// Payment blocked (price exceeds maxPricePerRequest)
|
|
1083
|
+
sdk.on("payment:blocked", (data) => {
|
|
1084
|
+
console.warn(`Payment blocked: agent ${data.agentId} charges ${data.agentPrice} but max is ${data.maxPrice}`);
|
|
1085
|
+
});
|
|
1086
|
+
|
|
710
1087
|
// Payment errors
|
|
711
1088
|
sdk.on("payment:error", (error) => {
|
|
712
1089
|
console.error(`Payment failed: ${error.message}`);
|
|
@@ -740,7 +1117,7 @@ sdk.on("quote:received", async (quote) => {
|
|
|
740
1117
|
});
|
|
741
1118
|
|
|
742
1119
|
// Request triggers quote
|
|
743
|
-
await sdk.sendMessage("@
|
|
1120
|
+
await sdk.sendMessage("@X Platform Agent user @elonmusk", { room: roomId });
|
|
744
1121
|
```
|
|
745
1122
|
|
|
746
1123
|
### Payment Flow Diagram
|
|
@@ -783,7 +1160,7 @@ sdk.on("auth:success", (state) => {
|
|
|
783
1160
|
console.log(`✅ Authenticated as ${state.walletAddress}`);
|
|
784
1161
|
console.log(`Whitelisted: ${state.isWhitelisted}`);
|
|
785
1162
|
});
|
|
786
|
-
sdk.on("auth:error", (error) => console.error("❌ Auth failed:", error
|
|
1163
|
+
sdk.on("auth:error", (error) => console.error("❌ Auth failed:", error));
|
|
787
1164
|
```
|
|
788
1165
|
|
|
789
1166
|
### Agent Events
|
|
@@ -792,7 +1169,6 @@ sdk.on("auth:error", (error) => console.error("❌ Auth failed:", error.message)
|
|
|
792
1169
|
sdk.on("agent:selected", (selection) => {
|
|
793
1170
|
console.log(`🤖 ${selection.agentName} was selected by coordinator`);
|
|
794
1171
|
console.log(`Reasoning: ${selection.reasoning}`);
|
|
795
|
-
console.log(`Confidence: ${selection.confidence}`);
|
|
796
1172
|
});
|
|
797
1173
|
|
|
798
1174
|
sdk.on("agent:response", (response) => {
|
|
@@ -802,7 +1178,7 @@ sdk.on("agent:response", (response) => {
|
|
|
802
1178
|
sdk.on("agent:list", (agents) => {
|
|
803
1179
|
console.log(`📋 Agent list updated: ${agents.length} agents available`);
|
|
804
1180
|
agents.forEach((agent) => {
|
|
805
|
-
console.log(` - ${agent.name}: ${agent.capabilities?.join(", ")}`);
|
|
1181
|
+
console.log(` - ${agent.name}: ${agent.capabilities?.map(c => c.name).join(", ")}`);
|
|
806
1182
|
});
|
|
807
1183
|
});
|
|
808
1184
|
```
|
|
@@ -830,7 +1206,7 @@ sdk.on("room:unsubscribed", (data) => {
|
|
|
830
1206
|
const sdk = new TeneoSDK({
|
|
831
1207
|
wsUrl: "wss://backend.developer.chatroom.teneo-protocol.ai/ws",
|
|
832
1208
|
privateKey: "0x...", // Your private key
|
|
833
|
-
|
|
1209
|
+
autoJoinPublicRooms: ["room-id-1"],
|
|
834
1210
|
reconnect: true,
|
|
835
1211
|
logLevel: "info"
|
|
836
1212
|
});
|
|
@@ -846,11 +1222,11 @@ const secureKey = new SecurePrivateKey(process.env.PRIVATE_KEY!);
|
|
|
846
1222
|
|
|
847
1223
|
const config = new SDKConfigBuilder()
|
|
848
1224
|
// Required
|
|
849
|
-
.withWebSocketUrl(
|
|
1225
|
+
.withWebSocketUrl(process.env.TENEO_WS_URL!)
|
|
850
1226
|
.withAuthentication(secureKey) // Encrypted key
|
|
851
1227
|
|
|
852
|
-
// Rooms
|
|
853
|
-
.
|
|
1228
|
+
// Rooms - auto-join these public rooms on connect
|
|
1229
|
+
.withAutoJoinPublicRooms(["room-id-1", "room-id-2"]) // Public rooms only (private rooms auto-available)
|
|
854
1230
|
|
|
855
1231
|
// Reconnection strategy
|
|
856
1232
|
.withReconnectionStrategy({
|
|
@@ -886,7 +1262,6 @@ const config = new SDKConfigBuilder()
|
|
|
886
1262
|
})
|
|
887
1263
|
|
|
888
1264
|
// Performance
|
|
889
|
-
.withRateLimit(10, 20) // 10 msg/sec, burst 20
|
|
890
1265
|
.withMessageDeduplication(true, 60000, 10000)
|
|
891
1266
|
.withLogging("debug")
|
|
892
1267
|
|
|
@@ -900,11 +1275,17 @@ const sdk = new TeneoSDK(config);
|
|
|
900
1275
|
Create `.env`:
|
|
901
1276
|
|
|
902
1277
|
```bash
|
|
1278
|
+
# Required
|
|
903
1279
|
TENEO_WS_URL=wss://backend.developer.chatroom.teneo-protocol.ai/ws
|
|
904
1280
|
PRIVATE_KEY=0xYourPrivateKey
|
|
905
|
-
|
|
906
|
-
|
|
1281
|
+
|
|
1282
|
+
# Optional
|
|
907
1283
|
LOG_LEVEL=info
|
|
1284
|
+
|
|
1285
|
+
# Payment network (v2.3.0) - Optional, defaults to PEAQ
|
|
1286
|
+
TENEO_NETWORK=base # By name: peaq, base, avalanche
|
|
1287
|
+
# Or by chain ID: TENEO_NETWORK=8453
|
|
1288
|
+
# Or CAIP-2: TENEO_NETWORK=eip155:8453
|
|
908
1289
|
```
|
|
909
1290
|
|
|
910
1291
|
Load them:
|
|
@@ -916,14 +1297,64 @@ dotenv.config();
|
|
|
916
1297
|
const sdk = new TeneoSDK({
|
|
917
1298
|
wsUrl: process.env.TENEO_WS_URL!,
|
|
918
1299
|
privateKey: process.env.PRIVATE_KEY!,
|
|
919
|
-
walletAddress: process.env.WALLET_ADDRESS,
|
|
920
|
-
defaultRoom: process.env.DEFAULT_ROOM,
|
|
921
1300
|
logLevel: (process.env.LOG_LEVEL as any) || "info"
|
|
1301
|
+
// TENEO_NETWORK is automatically used by SDK for payment network
|
|
922
1302
|
});
|
|
923
1303
|
```
|
|
924
1304
|
|
|
925
1305
|
---
|
|
926
1306
|
|
|
1307
|
+
## 🔄 v3.0.0 Migration Guide
|
|
1308
|
+
|
|
1309
|
+
All v3.0.0 changes are **backward compatible**. Old method names still work via deprecated aliases.
|
|
1310
|
+
|
|
1311
|
+
### Quick Migration (Optional)
|
|
1312
|
+
|
|
1313
|
+
Search and replace across your codebase to use the new, clearer names:
|
|
1314
|
+
|
|
1315
|
+
```bash
|
|
1316
|
+
# Config property
|
|
1317
|
+
autoJoinRooms: → autoJoinPublicRooms:
|
|
1318
|
+
|
|
1319
|
+
# Room subscription methods
|
|
1320
|
+
.subscribeToRoom( → .subscribeToPublicRoom(
|
|
1321
|
+
.unsubscribeFromRoom( → .unsubscribeFromPublicRoom(
|
|
1322
|
+
|
|
1323
|
+
# Cache-only methods (sync)
|
|
1324
|
+
.getRoomAgents( → .getCachedRoomAgents(
|
|
1325
|
+
.getAvailableAgents( → .getCachedAvailableAgents(
|
|
1326
|
+
.getRoomAgentCount( → .getCachedRoomAgentCount(
|
|
1327
|
+
|
|
1328
|
+
# Boolean check methods
|
|
1329
|
+
.isAgentInRoom( → .checkAgentInRoom(
|
|
1330
|
+
|
|
1331
|
+
# Network-wide search methods
|
|
1332
|
+
.findAgentsByCapability( → .findAvailableAgentsByCapability(
|
|
1333
|
+
.findAgentsByName( → .findAvailableAgentsByName(
|
|
1334
|
+
.findAgentsByStatus( → .findAvailableAgentsByStatus(
|
|
1335
|
+
```
|
|
1336
|
+
|
|
1337
|
+
### Why These Changes?
|
|
1338
|
+
|
|
1339
|
+
**Room Subscriptions**: `subscribeToPublicRoom()` clarifies that only public rooms need subscription. Private rooms are automatically available after authentication.
|
|
1340
|
+
|
|
1341
|
+
**Cache Methods**: The `getCached*` prefix makes it obvious these are synchronous, cache-only operations. Async methods like `listRoomAgents()` still fetch from server.
|
|
1342
|
+
|
|
1343
|
+
**Boolean Checks**: `checkAgentInRoom()` returns `boolean | undefined`, not just boolean. The name clarifies this uncertainty.
|
|
1344
|
+
|
|
1345
|
+
**Search Scope**: `findAvailableAgentsBy*()` methods search ALL available agents network-wide, not just room-specific agents.
|
|
1346
|
+
|
|
1347
|
+
### No Rush!
|
|
1348
|
+
|
|
1349
|
+
- ✅ Old names work indefinitely
|
|
1350
|
+
- ✅ TypeScript/JSDoc shows deprecation hints
|
|
1351
|
+
- ✅ Migrate on your schedule
|
|
1352
|
+
- ✅ Zero functional changes
|
|
1353
|
+
|
|
1354
|
+
See [CHANGELOG.md](CHANGELOG.md#300---2026-01-28) for detailed explanations and examples.
|
|
1355
|
+
|
|
1356
|
+
---
|
|
1357
|
+
|
|
927
1358
|
## 🛡️ Production Features
|
|
928
1359
|
|
|
929
1360
|
### 1. Secure Private Key Management
|
|
@@ -955,7 +1386,7 @@ Prevents cascading failures in webhook delivery:
|
|
|
955
1386
|
```typescript
|
|
956
1387
|
const status = sdk.getWebhookStatus();
|
|
957
1388
|
|
|
958
|
-
console.log("Circuit state:", status.circuitState);
|
|
1389
|
+
console.log("Circuit state:", status.queue.circuitState);
|
|
959
1390
|
// CLOSED = Normal operation, webhooks being delivered
|
|
960
1391
|
// OPEN = Too many failures, failing fast (60s timeout)
|
|
961
1392
|
// HALF_OPEN = Testing recovery (2 successes → CLOSED)
|
|
@@ -1041,12 +1472,11 @@ sdk.on("signature:failed", (type, reason) => {
|
|
|
1041
1472
|
const health = sdk.getHealth();
|
|
1042
1473
|
|
|
1043
1474
|
console.log("Status:", health.status); // 'healthy' | 'degraded' | 'unhealthy'
|
|
1044
|
-
console.log("Connected:", health.connection.
|
|
1475
|
+
console.log("Connected:", health.connection.status);
|
|
1045
1476
|
console.log("Authenticated:", health.connection.authenticated);
|
|
1046
|
-
console.log("Uptime:", health.uptime);
|
|
1047
1477
|
|
|
1048
1478
|
if (health.webhook) {
|
|
1049
|
-
console.log("Webhook
|
|
1479
|
+
console.log("Webhook pending:", health.webhook.pending);
|
|
1050
1480
|
console.log("Circuit state:", health.webhook.circuitState);
|
|
1051
1481
|
}
|
|
1052
1482
|
|
|
@@ -1069,12 +1499,12 @@ console.log("Reconnect attempts:", state.reconnectAttempts);
|
|
|
1069
1499
|
### Performance Metrics
|
|
1070
1500
|
|
|
1071
1501
|
```typescript
|
|
1072
|
-
// Rate limiter status
|
|
1073
|
-
const
|
|
1074
|
-
if (rateLimit) {
|
|
1075
|
-
console.log("Available:", rateLimit.availableTokens);
|
|
1076
|
-
console.log("Rate:", rateLimit.tokensPerSecond, "/sec");
|
|
1077
|
-
console.log("Burst capacity:", rateLimit.maxBurst);
|
|
1502
|
+
// Rate limiter status (via health check)
|
|
1503
|
+
const health = sdk.getHealth();
|
|
1504
|
+
if (health.rateLimit) {
|
|
1505
|
+
console.log("Available:", health.rateLimit.availableTokens);
|
|
1506
|
+
console.log("Rate:", health.rateLimit.tokensPerSecond, "/sec");
|
|
1507
|
+
console.log("Burst capacity:", health.rateLimit.maxBurst);
|
|
1078
1508
|
}
|
|
1079
1509
|
|
|
1080
1510
|
// Deduplication cache
|
|
@@ -1190,7 +1620,7 @@ RateLimitError: Rate limit exceeded
|
|
|
1190
1620
|
3. **Check circuit breaker:**
|
|
1191
1621
|
```typescript
|
|
1192
1622
|
const status = sdk.getWebhookStatus();
|
|
1193
|
-
if (status.circuitState === "OPEN") {
|
|
1623
|
+
if (status.queue.circuitState === "OPEN") {
|
|
1194
1624
|
console.log("Circuit open, will retry in 60s");
|
|
1195
1625
|
}
|
|
1196
1626
|
```
|