@teneo-protocol/sdk 2.2.2 → 3.0.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/.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 +1080 -756
- package/dist/handlers/message-handlers/agent-details-response-handler.d.ts.map +1 -1
- 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 +1080 -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.d.ts +135 -54
- package/dist/handlers/message-handlers/all-agents-response-handler.d.ts.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 +1116 -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 +1080 -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 +3 -1
- package/dist/managers/admin-manager.d.ts.map +1 -1
- package/dist/managers/admin-manager.js +4 -3
- 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 +215 -41
- package/dist/teneo-sdk.d.ts.map +1 -1
- package/dist/teneo-sdk.js +361 -84
- 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 +13110 -7451
- package/dist/types/messages.d.ts.map +1 -1
- package/dist/types/messages.js +195 -44
- 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 +6 -3
- 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 +402 -71
- 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 +235 -60
- 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/dist/teneo-sdk.js
CHANGED
|
@@ -4,6 +4,39 @@
|
|
|
4
4
|
* Provides a unified interface for external platforms to interact with Teneo agents
|
|
5
5
|
* Uses manager classes to follow Single Responsibility Principle
|
|
6
6
|
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
7
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
41
|
exports.TeneoSDK = exports.AgentCommandSchema = exports.SendMessageOptionsSchema = void 0;
|
|
9
42
|
const eventemitter3_1 = require("eventemitter3");
|
|
@@ -19,6 +52,7 @@ const managers_1 = require("./managers");
|
|
|
19
52
|
const logger_1 = require("./utils/logger");
|
|
20
53
|
const validation_1 = require("./types/validation");
|
|
21
54
|
const secure_private_key_1 = require("./utils/secure-private-key");
|
|
55
|
+
const payments_1 = require("./payments");
|
|
22
56
|
// Zod schemas for SDK-specific interfaces
|
|
23
57
|
exports.SendMessageOptionsSchema = zod_1.z.object({
|
|
24
58
|
room: validation_1.RoomIdSchema.optional(),
|
|
@@ -58,7 +92,7 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
58
92
|
* @param config.wsUrl - WebSocket URL to connect to (e.g., 'wss://teneo.example.com')
|
|
59
93
|
* @param config.privateKey - Optional Ethereum private key for wallet-based authentication
|
|
60
94
|
* @param config.walletAddress - Optional wallet address (derived from privateKey if not provided)
|
|
61
|
-
* @param config.
|
|
95
|
+
* @param config.autoJoinPublicRooms - Optional array of public room IDs to subscribe to automatically on connection (private rooms are auto-available)
|
|
62
96
|
* @param config.webhookUrl - Optional webhook URL for receiving event notifications
|
|
63
97
|
* @param config.reconnect - Enable automatic reconnection (default: true)
|
|
64
98
|
* @param config.logLevel - Logging level: 'debug', 'info', 'warn', 'error', 'silent' (default: 'info')
|
|
@@ -78,7 +112,7 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
78
112
|
* const sdk = new TeneoSDK({
|
|
79
113
|
* wsUrl: 'wss://teneo.example.com',
|
|
80
114
|
* privateKey: '0x...',
|
|
81
|
-
*
|
|
115
|
+
* autoJoinPublicRooms: ['public-room-1', 'public-room-2'], // Public rooms only
|
|
82
116
|
* webhookUrl: 'https://api.example.com/webhooks',
|
|
83
117
|
* logLevel: 'debug',
|
|
84
118
|
* responseFormat: 'both',
|
|
@@ -87,11 +121,12 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
87
121
|
* });
|
|
88
122
|
*
|
|
89
123
|
* // Using builder pattern (recommended for complex configs)
|
|
90
|
-
* const
|
|
91
|
-
* .
|
|
92
|
-
* .
|
|
93
|
-
* .
|
|
124
|
+
* const config = TeneoSDK.builder()
|
|
125
|
+
* .withWebSocketUrl('wss://teneo.example.com')
|
|
126
|
+
* .withAuthentication('0x...')
|
|
127
|
+
* .withAutoJoinPublicRooms(['public-room-1', 'public-room-2'])
|
|
94
128
|
* .build();
|
|
129
|
+
* const sdk = new TeneoSDK(config);
|
|
95
130
|
* ```
|
|
96
131
|
*
|
|
97
132
|
* @see {@link SDKConfigBuilder} for fluent configuration API
|
|
@@ -145,16 +180,10 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
145
180
|
quoteTimeout: this.config.quoteTimeout,
|
|
146
181
|
wsUrl: this.config.wsUrl,
|
|
147
182
|
paymentNetwork: this.config.paymentNetwork,
|
|
148
|
-
paymentAsset: this.config.paymentAsset
|
|
183
|
+
paymentAsset: this.config.paymentAsset,
|
|
184
|
+
network: this.config.network // Network name from withNetwork()
|
|
149
185
|
});
|
|
150
|
-
//
|
|
151
|
-
if (this.config.privateKey) {
|
|
152
|
-
const secureKey = this.config.privateKey instanceof secure_private_key_1.SecurePrivateKey
|
|
153
|
-
? this.config.privateKey
|
|
154
|
-
: new secure_private_key_1.SecurePrivateKey(this.config.privateKey);
|
|
155
|
-
const walletAddress = this.config.walletAddress || this.deriveWalletAddress(this.config.privateKey);
|
|
156
|
-
this.messages.setPaymentClient(secureKey, walletAddress);
|
|
157
|
-
}
|
|
186
|
+
// NOTE: Payment client is set up in connect() after networks are initialized
|
|
158
187
|
// Set up event forwarding
|
|
159
188
|
this.setupEventForwarding();
|
|
160
189
|
this.logger.info("TeneoSDK initialized", { wsUrl: this.config.wsUrl });
|
|
@@ -189,11 +218,27 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
189
218
|
}
|
|
190
219
|
try {
|
|
191
220
|
this.logger.info("Connecting to Teneo Protocol");
|
|
221
|
+
// Initialize network configurations from backend before connecting
|
|
222
|
+
(0, payments_1.setNetworkConfigUrl)(this.config.wsUrl);
|
|
223
|
+
await (0, payments_1.initializeNetworks)();
|
|
224
|
+
// Verify networks are fully loaded before payment setup
|
|
225
|
+
const { NETWORKS } = await Promise.resolve().then(() => __importStar(require("./payments/networks")));
|
|
226
|
+
if (Object.keys(NETWORKS).length === 0) {
|
|
227
|
+
throw new events_1.SDKError("Failed to initialize networks from backend", error_codes_1.ErrorCode.CONFIG_ERROR, null, true);
|
|
228
|
+
}
|
|
229
|
+
// Set up payment client now that networks are initialized (v2.2.0)
|
|
230
|
+
if (this.config.privateKey) {
|
|
231
|
+
const secureKey = this.config.privateKey instanceof secure_private_key_1.SecurePrivateKey
|
|
232
|
+
? this.config.privateKey
|
|
233
|
+
: new secure_private_key_1.SecurePrivateKey(this.config.privateKey);
|
|
234
|
+
const walletAddress = this.config.walletAddress || this.deriveWalletAddress(this.config.privateKey);
|
|
235
|
+
this.messages.setPaymentClient(secureKey, walletAddress);
|
|
236
|
+
}
|
|
192
237
|
await this.connection.connect();
|
|
193
|
-
// Auto-join rooms if configured
|
|
194
|
-
if (this.config.
|
|
195
|
-
for (const room of this.config.
|
|
196
|
-
await this.rooms.
|
|
238
|
+
// Auto-join public rooms if configured
|
|
239
|
+
if (this.config.autoJoinPublicRooms && this.config.autoJoinPublicRooms.length > 0) {
|
|
240
|
+
for (const room of this.config.autoJoinPublicRooms) {
|
|
241
|
+
await this.rooms.subscribeToPublicRoom(room);
|
|
197
242
|
}
|
|
198
243
|
}
|
|
199
244
|
this.logger.info("Successfully connected to Teneo Protocol");
|
|
@@ -260,7 +305,9 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
260
305
|
* @param command.agent - The agent ID or name to send the command to
|
|
261
306
|
* @param command.command - The command text to send to the agent
|
|
262
307
|
* @param command.room - Room to send command to (defaults to configured default room)
|
|
263
|
-
* @
|
|
308
|
+
* @param command.network - Optional per-request network override (e.g., "base", "avalanche", or chain ID 8453)
|
|
309
|
+
* @param waitForResponse - Whether to wait for the agent's response (default: false)
|
|
310
|
+
* @returns Promise resolving to FormattedResponse if waitForResponse is true, void otherwise
|
|
264
311
|
* @throws {SDKError} If not connected to the network (ErrorCode.NOT_CONNECTED)
|
|
265
312
|
* @throws {ValidationError} If agent or command are empty, or room is not configured
|
|
266
313
|
*
|
|
@@ -270,8 +317,16 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
270
317
|
* await sdk.sendDirectCommand({
|
|
271
318
|
* agent: 'weather-agent',
|
|
272
319
|
* command: 'Get forecast for New York',
|
|
273
|
-
* room: '
|
|
320
|
+
* room: 'room-id'
|
|
274
321
|
* });
|
|
322
|
+
*
|
|
323
|
+
* // With per-request network override
|
|
324
|
+
* const response = await sdk.sendDirectCommand({
|
|
325
|
+
* agent: 'x-agent-enterprise-v2',
|
|
326
|
+
* command: 'user @elonmusk',
|
|
327
|
+
* room: 'room-id',
|
|
328
|
+
* network: 'base' // Pay on Base for this request
|
|
329
|
+
* }, true);
|
|
275
330
|
* ```
|
|
276
331
|
*/
|
|
277
332
|
async sendDirectCommand(command, waitForResponse = false) {
|
|
@@ -282,8 +337,8 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
282
337
|
* The quote includes agent selection, pricing, and expiration.
|
|
283
338
|
* Does NOT auto-approve - use confirmQuote() to execute.
|
|
284
339
|
*/
|
|
285
|
-
async requestQuote(content, room) {
|
|
286
|
-
return this.messages.requestQuote(content, room);
|
|
340
|
+
async requestQuote(content, room, networkOverride) {
|
|
341
|
+
return this.messages.requestQuote(content, room, networkOverride);
|
|
287
342
|
}
|
|
288
343
|
/**
|
|
289
344
|
* Confirms a pending quote and executes the task with payment.
|
|
@@ -311,14 +366,26 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
311
366
|
* @example
|
|
312
367
|
* ```typescript
|
|
313
368
|
* // Subscribe to a public room
|
|
314
|
-
* await sdk.
|
|
369
|
+
* await sdk.subscribeToPublicRoom('public-room-id');
|
|
315
370
|
* console.log('Subscribed to public room');
|
|
316
371
|
*
|
|
317
372
|
* // Note: Private rooms don't need subscription - you're always subscribed
|
|
318
373
|
* ```
|
|
319
374
|
*/
|
|
375
|
+
async subscribeToPublicRoom(roomId) {
|
|
376
|
+
return this.rooms.subscribeToPublicRoom(roomId);
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* @deprecated Use subscribeToPublicRoom() instead. This method only affects public rooms.
|
|
380
|
+
* Private rooms are automatically available after authentication without subscription.
|
|
381
|
+
*
|
|
382
|
+
* Subscribes to a public room in the Teneo Protocol.
|
|
383
|
+
*
|
|
384
|
+
* @param roomId - The ID of the public room to subscribe to
|
|
385
|
+
* @returns Promise that resolves when the room has been subscribed
|
|
386
|
+
*/
|
|
320
387
|
async subscribeToRoom(roomId) {
|
|
321
|
-
return this.
|
|
388
|
+
return this.subscribeToPublicRoom(roomId);
|
|
322
389
|
}
|
|
323
390
|
/**
|
|
324
391
|
* Unsubscribes from a public room in the Teneo Protocol.
|
|
@@ -334,12 +401,24 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
334
401
|
*
|
|
335
402
|
* @example
|
|
336
403
|
* ```typescript
|
|
337
|
-
* await sdk.
|
|
404
|
+
* await sdk.unsubscribeFromPublicRoom('public-room-id');
|
|
338
405
|
* console.log('Unsubscribed from public room');
|
|
339
406
|
* ```
|
|
340
407
|
*/
|
|
408
|
+
async unsubscribeFromPublicRoom(roomId) {
|
|
409
|
+
return this.rooms.unsubscribeFromPublicRoom(roomId);
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* @deprecated Use unsubscribeFromPublicRoom() instead. This method only affects public rooms.
|
|
413
|
+
* Private rooms cannot be unsubscribed from.
|
|
414
|
+
*
|
|
415
|
+
* Unsubscribes from a public room in the Teneo Protocol.
|
|
416
|
+
*
|
|
417
|
+
* @param roomId - The ID of the public room to unsubscribe from
|
|
418
|
+
* @returns Promise that resolves when the room has been unsubscribed
|
|
419
|
+
*/
|
|
341
420
|
async unsubscribeFromRoom(roomId) {
|
|
342
|
-
return this.
|
|
421
|
+
return this.unsubscribeFromPublicRoom(roomId);
|
|
343
422
|
}
|
|
344
423
|
/**
|
|
345
424
|
* Lists all rooms available to the user.
|
|
@@ -371,7 +450,7 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
371
450
|
* ```typescript
|
|
372
451
|
* const rooms = sdk.getSubscribedRooms();
|
|
373
452
|
* console.log(`Subscribed to ${rooms.length} rooms:`, rooms);
|
|
374
|
-
* // Example output: Subscribed to 3 rooms: ['
|
|
453
|
+
* // Example output: Subscribed to 3 rooms: ['room-id-1', 'room-id-2', 'room-id-3']
|
|
375
454
|
* ```
|
|
376
455
|
*/
|
|
377
456
|
getSubscribedRooms() {
|
|
@@ -418,18 +497,18 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
418
497
|
return this.agents.getAgent(agentId);
|
|
419
498
|
}
|
|
420
499
|
/**
|
|
421
|
-
* Finds all agents that have a specific capability using O(1) indexed lookup (PERF-3).
|
|
500
|
+
* Finds all available agents (network-wide) that have a specific capability using O(1) indexed lookup (PERF-3).
|
|
422
501
|
* Much faster than filtering through all agents manually.
|
|
423
502
|
* Uses capability index for constant-time lookups regardless of agent count.
|
|
424
503
|
*
|
|
425
504
|
* @param capability - The capability name to search for (case-insensitive)
|
|
426
|
-
* @returns Read-only array of agents with the specified capability
|
|
505
|
+
* @returns Read-only array of available agents with the specified capability
|
|
427
506
|
* @throws {ValidationError} If capability name is invalid
|
|
428
507
|
*
|
|
429
508
|
* @example
|
|
430
509
|
* ```typescript
|
|
431
|
-
* // Find all weather-capable agents
|
|
432
|
-
* const weatherAgents = sdk.
|
|
510
|
+
* // Find all weather-capable agents available on the network
|
|
511
|
+
* const weatherAgents = sdk.findAvailableAgentsByCapability('weather-forecast');
|
|
433
512
|
* console.log(`Found ${weatherAgents.length} weather agents`);
|
|
434
513
|
*
|
|
435
514
|
* weatherAgents.forEach(agent => {
|
|
@@ -437,51 +516,84 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
437
516
|
* });
|
|
438
517
|
* ```
|
|
439
518
|
*/
|
|
440
|
-
|
|
519
|
+
findAvailableAgentsByCapability(capability) {
|
|
441
520
|
return this.agents.findByCapability(capability);
|
|
442
521
|
}
|
|
443
522
|
/**
|
|
444
|
-
*
|
|
523
|
+
* @deprecated Use findAvailableAgentsByCapability() instead. This searches all available agents network-wide.
|
|
524
|
+
*
|
|
525
|
+
* Finds all agents that have a specific capability.
|
|
526
|
+
*
|
|
527
|
+
* @param capability - The capability name to search for
|
|
528
|
+
* @returns Read-only array of agents with the specified capability
|
|
529
|
+
*/
|
|
530
|
+
findAgentsByCapability(capability) {
|
|
531
|
+
return this.findAvailableAgentsByCapability(capability);
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Finds available agents (network-wide) by name using O(k) token-based search (PERF-3).
|
|
445
535
|
* Supports partial matching - searches for tokens within agent names.
|
|
446
536
|
* Tokenizes both the search query and agent names for flexible matching.
|
|
447
537
|
*
|
|
448
538
|
* @param name - Name or partial name to search for (case-insensitive)
|
|
449
|
-
* @returns Read-only array of agents matching the search
|
|
539
|
+
* @returns Read-only array of available agents matching the search
|
|
450
540
|
* @throws {ValidationError} If name is invalid
|
|
451
541
|
*
|
|
452
542
|
* @example
|
|
453
543
|
* ```typescript
|
|
454
|
-
* // Find all agents with "weather" in their name
|
|
455
|
-
* const agents = sdk.
|
|
544
|
+
* // Find all available agents with "weather" in their name
|
|
545
|
+
* const agents = sdk.findAvailableAgentsByName('weather');
|
|
456
546
|
* // Matches: "Weather Agent", "Weather Forecast Bot", "Advanced Weather API", etc.
|
|
457
547
|
*
|
|
458
548
|
* console.log(`Found ${agents.length} agents matching 'weather'`);
|
|
459
549
|
* ```
|
|
460
550
|
*/
|
|
461
|
-
|
|
551
|
+
findAvailableAgentsByName(name) {
|
|
462
552
|
return this.agents.findByName(name);
|
|
463
553
|
}
|
|
464
554
|
/**
|
|
465
|
-
*
|
|
555
|
+
* @deprecated Use findAvailableAgentsByName() instead. This searches all available agents network-wide.
|
|
556
|
+
*
|
|
557
|
+
* Finds agents by name.
|
|
558
|
+
*
|
|
559
|
+
* @param name - Name or partial name to search for
|
|
560
|
+
* @returns Read-only array of agents matching the search
|
|
561
|
+
*/
|
|
562
|
+
findAgentsByName(name) {
|
|
563
|
+
return this.findAvailableAgentsByName(name);
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Finds all available agents (network-wide) with a specific status using O(1) indexed lookup (PERF-3).
|
|
466
567
|
* Uses status index for constant-time lookups regardless of agent count.
|
|
467
568
|
*
|
|
468
569
|
* @param status - Agent status: 'online' or 'offline' (case-insensitive)
|
|
469
|
-
* @returns Read-only array of agents with the specified status
|
|
570
|
+
* @returns Read-only array of available agents with the specified status
|
|
470
571
|
* @throws {ValidationError} If status is invalid
|
|
471
572
|
*
|
|
472
573
|
* @example
|
|
473
574
|
* ```typescript
|
|
474
|
-
* // Get all online agents
|
|
475
|
-
* const onlineAgents = sdk.
|
|
575
|
+
* // Get all online agents available on the network
|
|
576
|
+
* const onlineAgents = sdk.findAvailableAgentsByStatus('online');
|
|
476
577
|
* console.log(`${onlineAgents.length} agents are currently online`);
|
|
477
578
|
*
|
|
478
579
|
* // Get offline agents
|
|
479
|
-
* const offlineAgents = sdk.
|
|
580
|
+
* const offlineAgents = sdk.findAvailableAgentsByStatus('offline');
|
|
480
581
|
* ```
|
|
481
582
|
*/
|
|
482
|
-
|
|
583
|
+
findAvailableAgentsByStatus(status) {
|
|
483
584
|
return this.agents.findByStatus(status);
|
|
484
585
|
}
|
|
586
|
+
/**
|
|
587
|
+
* @deprecated Use findAvailableAgentsByStatus() instead. This searches all available agents network-wide.
|
|
588
|
+
*
|
|
589
|
+
* Finds all agents with a specific status.
|
|
590
|
+
*
|
|
591
|
+
* @param status - Agent status: 'online' or 'offline'
|
|
592
|
+
* @returns Read-only array of agents with the specified status
|
|
593
|
+
*/
|
|
594
|
+
findAgentsByStatus(status) {
|
|
595
|
+
return this.findAvailableAgentsByStatus(status);
|
|
596
|
+
}
|
|
485
597
|
/**
|
|
486
598
|
* Fetches detailed information about a specific agent from the server.
|
|
487
599
|
* Makes a request to the server for full agent details including capabilities,
|
|
@@ -521,7 +633,7 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
521
633
|
* console.log(`Found ${result.total} agents`);
|
|
522
634
|
*
|
|
523
635
|
* result.agents.forEach(agent => {
|
|
524
|
-
* console.log(`${agent.agent_name}:
|
|
636
|
+
* console.log(`${agent.agent_name}: status=${agent.review_status}, banned=${agent.is_banned}`);
|
|
525
637
|
* });
|
|
526
638
|
*
|
|
527
639
|
* // Get user count
|
|
@@ -591,7 +703,7 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
591
703
|
*
|
|
592
704
|
* @example
|
|
593
705
|
* ```typescript
|
|
594
|
-
* const room = sdk.getRoom('
|
|
706
|
+
* const room = sdk.getRoom('room-id');
|
|
595
707
|
* if (room) {
|
|
596
708
|
* console.log(`Found room: ${room.name}`);
|
|
597
709
|
* console.log(`Members: ${room.members?.length ?? 0}`);
|
|
@@ -843,26 +955,9 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
843
955
|
async listRoomAgents(roomId, useCache = true) {
|
|
844
956
|
return this.agentRoom.listRoomAgents(roomId, useCache);
|
|
845
957
|
}
|
|
846
|
-
/**
|
|
847
|
-
* Lists all agents available to be added to a room.
|
|
848
|
-
* Shows agents not currently in the room.
|
|
849
|
-
* Results are cached for 5 minutes for performance.
|
|
850
|
-
* Emits 'agent_room:available_agents_listed' when list is received.
|
|
851
|
-
*
|
|
852
|
-
* @param roomId - ID of the room to check available agents for
|
|
853
|
-
* @param useCache - Whether to use cached data if available (default: true)
|
|
854
|
-
* @returns Promise that resolves to array of available agents
|
|
855
|
-
* @throws {SDKError} If not connected
|
|
856
|
-
*
|
|
857
|
-
* @example
|
|
858
|
-
* ```typescript
|
|
859
|
-
* const available = await sdk.listAvailableAgents('room-123');
|
|
860
|
-
* console.log(`${available.length} agents available to add`);
|
|
861
|
-
* ```
|
|
862
|
-
*/
|
|
863
958
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
864
|
-
async listAvailableAgents(roomId,
|
|
865
|
-
return this.agentRoom.listAvailableAgents(roomId,
|
|
959
|
+
async listAvailableAgents(roomId, useCacheOrOptions) {
|
|
960
|
+
return this.agentRoom.listAvailableAgents(roomId, useCacheOrOptions);
|
|
866
961
|
}
|
|
867
962
|
/**
|
|
868
963
|
* Gets agents in a room from cache (synchronous).
|
|
@@ -873,7 +968,7 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
873
968
|
*
|
|
874
969
|
* @example
|
|
875
970
|
* ```typescript
|
|
876
|
-
* const agents = sdk.
|
|
971
|
+
* const agents = sdk.getCachedRoomAgents('room-123');
|
|
877
972
|
* if (agents) {
|
|
878
973
|
* console.log(`${agents.length} agents (cached)`);
|
|
879
974
|
* } else {
|
|
@@ -882,8 +977,21 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
882
977
|
* ```
|
|
883
978
|
*/
|
|
884
979
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
980
|
+
getCachedRoomAgents(roomId) {
|
|
981
|
+
return this.agentRoom.getCachedRoomAgents(roomId);
|
|
982
|
+
}
|
|
983
|
+
/**
|
|
984
|
+
* @deprecated Use getCachedRoomAgents() instead. This method returns cached data only.
|
|
985
|
+
* Use listRoomAgents() to fetch fresh data from server.
|
|
986
|
+
*
|
|
987
|
+
* Gets agents in a room from cache (synchronous).
|
|
988
|
+
*
|
|
989
|
+
* @param roomId - ID of the room
|
|
990
|
+
* @returns Array of agents if cached, undefined otherwise
|
|
991
|
+
*/
|
|
992
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
885
993
|
getRoomAgents(roomId) {
|
|
886
|
-
return this.
|
|
994
|
+
return this.getCachedRoomAgents(roomId);
|
|
887
995
|
}
|
|
888
996
|
/**
|
|
889
997
|
* Gets available agents for a room from cache (synchronous).
|
|
@@ -894,15 +1002,28 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
894
1002
|
*
|
|
895
1003
|
* @example
|
|
896
1004
|
* ```typescript
|
|
897
|
-
* const available = sdk.
|
|
1005
|
+
* const available = sdk.getCachedAvailableAgents('room-123');
|
|
898
1006
|
* if (available) {
|
|
899
1007
|
* console.log(`${available.length} agents available (cached)`);
|
|
900
1008
|
* }
|
|
901
1009
|
* ```
|
|
902
1010
|
*/
|
|
903
1011
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1012
|
+
getCachedAvailableAgents(roomId) {
|
|
1013
|
+
return this.agentRoom.getCachedAvailableAgents(roomId);
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* @deprecated Use getCachedAvailableAgents() instead. This method returns cached data only.
|
|
1017
|
+
* Use listAvailableAgents() to fetch fresh data from server.
|
|
1018
|
+
*
|
|
1019
|
+
* Gets available agents for a room from cache (synchronous).
|
|
1020
|
+
*
|
|
1021
|
+
* @param roomId - ID of the room
|
|
1022
|
+
* @returns Array of available agents if cached, undefined otherwise
|
|
1023
|
+
*/
|
|
1024
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
904
1025
|
getAvailableAgents(roomId) {
|
|
905
|
-
return this.
|
|
1026
|
+
return this.getCachedAvailableAgents(roomId);
|
|
906
1027
|
}
|
|
907
1028
|
/**
|
|
908
1029
|
* Checks if an agent is in a room (synchronous, from cache).
|
|
@@ -914,18 +1035,31 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
914
1035
|
*
|
|
915
1036
|
* @example
|
|
916
1037
|
* ```typescript
|
|
917
|
-
* const inRoom = sdk.
|
|
1038
|
+
* const inRoom = sdk.checkAgentInRoom('room-123', 'weather-agent');
|
|
918
1039
|
* if (inRoom === true) {
|
|
919
1040
|
* console.log('Agent is in room');
|
|
920
1041
|
* } else if (inRoom === false) {
|
|
921
1042
|
* console.log('Agent is not in room');
|
|
922
1043
|
* } else {
|
|
923
|
-
* console.log('Room data not cached');
|
|
1044
|
+
* console.log('Room data not cached - need to fetch');
|
|
924
1045
|
* }
|
|
925
1046
|
* ```
|
|
926
1047
|
*/
|
|
1048
|
+
checkAgentInRoom(roomId, agentId) {
|
|
1049
|
+
return this.agentRoom.checkAgentInRoom(roomId, agentId);
|
|
1050
|
+
}
|
|
1051
|
+
/**
|
|
1052
|
+
* @deprecated Use checkAgentInRoom() instead. The 'is*' naming convention implies boolean-only,
|
|
1053
|
+
* but this method returns boolean | undefined to indicate cache validity.
|
|
1054
|
+
*
|
|
1055
|
+
* Checks if an agent is in a room (synchronous, from cache).
|
|
1056
|
+
*
|
|
1057
|
+
* @param roomId - ID of the room
|
|
1058
|
+
* @param agentId - ID of the agent
|
|
1059
|
+
* @returns True if agent is in room, false if not, undefined if not cached
|
|
1060
|
+
*/
|
|
927
1061
|
isAgentInRoom(roomId, agentId) {
|
|
928
|
-
return this.
|
|
1062
|
+
return this.checkAgentInRoom(roomId, agentId);
|
|
929
1063
|
}
|
|
930
1064
|
/**
|
|
931
1065
|
* Gets the count of agents in a room (synchronous, from cache).
|
|
@@ -936,14 +1070,26 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
936
1070
|
*
|
|
937
1071
|
* @example
|
|
938
1072
|
* ```typescript
|
|
939
|
-
* const count = sdk.
|
|
1073
|
+
* const count = sdk.getCachedRoomAgentCount('room-123');
|
|
940
1074
|
* if (count !== undefined) {
|
|
941
1075
|
* console.log(`Room has ${count} agents`);
|
|
942
1076
|
* }
|
|
943
1077
|
* ```
|
|
944
1078
|
*/
|
|
1079
|
+
getCachedRoomAgentCount(roomId) {
|
|
1080
|
+
return this.agentRoom.getCachedRoomAgentCount(roomId);
|
|
1081
|
+
}
|
|
1082
|
+
/**
|
|
1083
|
+
* @deprecated Use getCachedRoomAgentCount() instead. This method returns cached data only.
|
|
1084
|
+
* Use listRoomAgents() to fetch fresh data from server.
|
|
1085
|
+
*
|
|
1086
|
+
* Gets the count of agents in a room (synchronous, from cache).
|
|
1087
|
+
*
|
|
1088
|
+
* @param roomId - ID of the room
|
|
1089
|
+
* @returns Number of agents in room, or undefined if not cached
|
|
1090
|
+
*/
|
|
945
1091
|
getRoomAgentCount(roomId) {
|
|
946
|
-
return this.
|
|
1092
|
+
return this.getCachedRoomAgentCount(roomId);
|
|
947
1093
|
}
|
|
948
1094
|
/**
|
|
949
1095
|
* Invalidates the agent-room cache for a specific room.
|
|
@@ -1021,6 +1167,109 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
1021
1167
|
});
|
|
1022
1168
|
});
|
|
1023
1169
|
}
|
|
1170
|
+
/**
|
|
1171
|
+
* Sends the result of an on-chain transaction back to the server.
|
|
1172
|
+
* Used in response to a "wallet:tx_requested" event after the user
|
|
1173
|
+
* has confirmed, rejected, or encountered a failure with the transaction.
|
|
1174
|
+
*
|
|
1175
|
+
* @param taskId - The task ID from the wallet:tx_requested event
|
|
1176
|
+
* @param status - Transaction result: "confirmed", "rejected", or "failed"
|
|
1177
|
+
* @param txHash - The on-chain transaction hash (required for "confirmed" status)
|
|
1178
|
+
* @param error - Error message (optional, for "failed" status)
|
|
1179
|
+
* @throws {SDKError} If the SDK has been destroyed or not connected
|
|
1180
|
+
*
|
|
1181
|
+
* @example
|
|
1182
|
+
* ```typescript
|
|
1183
|
+
* sdk.on("wallet:tx_requested", async (data) => {
|
|
1184
|
+
* try {
|
|
1185
|
+
* const txHash = await wallet.sendTransaction(data.tx);
|
|
1186
|
+
* await sdk.sendTxResult(data.taskId, "confirmed", txHash);
|
|
1187
|
+
* } catch (err) {
|
|
1188
|
+
* await sdk.sendTxResult(data.taskId, "failed", undefined, err.message);
|
|
1189
|
+
* }
|
|
1190
|
+
* });
|
|
1191
|
+
* ```
|
|
1192
|
+
*/
|
|
1193
|
+
async sendTxResult(taskId, status, txHash, error) {
|
|
1194
|
+
if (this.isDestroyed) {
|
|
1195
|
+
throw new events_1.SDKError("SDK has been destroyed", error_codes_1.ErrorCode.SDK_DESTROYED, null, false);
|
|
1196
|
+
}
|
|
1197
|
+
if (!this.wsClient.isConnected) {
|
|
1198
|
+
throw new events_1.SDKError("Not connected to Teneo Protocol", error_codes_1.ErrorCode.NOT_CONNECTED);
|
|
1199
|
+
}
|
|
1200
|
+
const message = {
|
|
1201
|
+
type: "tx_result",
|
|
1202
|
+
data: {
|
|
1203
|
+
task_id: taskId,
|
|
1204
|
+
status,
|
|
1205
|
+
...(txHash && { tx_hash: txHash }),
|
|
1206
|
+
...(error && { error })
|
|
1207
|
+
}
|
|
1208
|
+
};
|
|
1209
|
+
await this.wsClient.sendMessage(message);
|
|
1210
|
+
}
|
|
1211
|
+
/**
|
|
1212
|
+
* Sets the API key preference for the current user.
|
|
1213
|
+
* Controls whether custom API keys are used for agent interactions.
|
|
1214
|
+
*
|
|
1215
|
+
* @param useCustomKeys - Whether to use custom API keys
|
|
1216
|
+
* @throws {SDKError} If the SDK has been destroyed or not connected
|
|
1217
|
+
*
|
|
1218
|
+
* @example
|
|
1219
|
+
* ```typescript
|
|
1220
|
+
* // Enable custom API keys
|
|
1221
|
+
* await sdk.setApiKeyPreference(true);
|
|
1222
|
+
*
|
|
1223
|
+
* // Disable custom API keys
|
|
1224
|
+
* await sdk.setApiKeyPreference(false);
|
|
1225
|
+
* ```
|
|
1226
|
+
*/
|
|
1227
|
+
async setApiKeyPreference(useCustomKeys) {
|
|
1228
|
+
if (this.isDestroyed) {
|
|
1229
|
+
throw new events_1.SDKError("SDK has been destroyed", error_codes_1.ErrorCode.SDK_DESTROYED, null, false);
|
|
1230
|
+
}
|
|
1231
|
+
if (!this.wsClient.isConnected) {
|
|
1232
|
+
throw new events_1.SDKError("Not connected to Teneo Protocol", error_codes_1.ErrorCode.NOT_CONNECTED);
|
|
1233
|
+
}
|
|
1234
|
+
const message = {
|
|
1235
|
+
type: "set_api_key_preference",
|
|
1236
|
+
data: {
|
|
1237
|
+
use_custom_keys: useCustomKeys
|
|
1238
|
+
}
|
|
1239
|
+
};
|
|
1240
|
+
await this.wsClient.sendMessage(message);
|
|
1241
|
+
}
|
|
1242
|
+
/**
|
|
1243
|
+
* Send a room ping to get live user count
|
|
1244
|
+
* Server responds with room_pong message containing current live user count
|
|
1245
|
+
*
|
|
1246
|
+
* @param roomId - The room ID to ping
|
|
1247
|
+
* @throws {SDKError} If not connected or SDK is destroyed
|
|
1248
|
+
*
|
|
1249
|
+
* @example
|
|
1250
|
+
* ```typescript
|
|
1251
|
+
* // Ping a room to get live user count
|
|
1252
|
+
* await sdk.sendRoomPing("my-room");
|
|
1253
|
+
*
|
|
1254
|
+
* // Listen for the response
|
|
1255
|
+
* sdk.on("room:pong", (data) => {
|
|
1256
|
+
* console.log(`Room ${data.roomId} has ${data.liveCount} live users`);
|
|
1257
|
+
* });
|
|
1258
|
+
* ```
|
|
1259
|
+
*/
|
|
1260
|
+
async sendRoomPing(roomId) {
|
|
1261
|
+
if (this.isDestroyed) {
|
|
1262
|
+
throw new events_1.SDKError("SDK has been destroyed", error_codes_1.ErrorCode.SDK_DESTROYED, null, false);
|
|
1263
|
+
}
|
|
1264
|
+
if (!this.wsClient.isConnected) {
|
|
1265
|
+
throw new events_1.SDKError("Not connected to Teneo Protocol", error_codes_1.ErrorCode.NOT_CONNECTED);
|
|
1266
|
+
}
|
|
1267
|
+
const message = {
|
|
1268
|
+
type: "room_ping",
|
|
1269
|
+
room_id: roomId
|
|
1270
|
+
};
|
|
1271
|
+
await this.wsClient.sendMessage(message);
|
|
1272
|
+
}
|
|
1024
1273
|
/**
|
|
1025
1274
|
* Configures webhook URL and headers for receiving real-time event notifications.
|
|
1026
1275
|
* Webhooks allow you to receive events at your server endpoint via HTTP POST requests.
|
|
@@ -1404,8 +1653,8 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
1404
1653
|
this._admin.destroy();
|
|
1405
1654
|
// Destroy other components
|
|
1406
1655
|
this.webhookHandler.destroy();
|
|
1407
|
-
this.removeAllListeners();
|
|
1408
1656
|
this.emit("destroy");
|
|
1657
|
+
this.removeAllListeners();
|
|
1409
1658
|
}
|
|
1410
1659
|
/**
|
|
1411
1660
|
* Set up event forwarding from managers
|
|
@@ -1468,7 +1717,34 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
1468
1717
|
// Handle agent list updates from WebSocketClient
|
|
1469
1718
|
this.wsClient.on("agent:list", (agents) => {
|
|
1470
1719
|
this.agents.updateAgents(agents);
|
|
1720
|
+
this.emit("agent:list", agents);
|
|
1721
|
+
});
|
|
1722
|
+
// Forward task confirmed events from WebSocketClient (emitted by handlers)
|
|
1723
|
+
this.wsClient.on("task:confirmed", (data) => {
|
|
1724
|
+
this.emit("task:confirmed", data);
|
|
1725
|
+
});
|
|
1726
|
+
// Forward agent error events from WebSocketClient (emitted by handlers)
|
|
1727
|
+
this.wsClient.on("agent:error", (data) => {
|
|
1728
|
+
this.emit("agent:error", data);
|
|
1729
|
+
});
|
|
1730
|
+
// Forward wallet transaction events from WebSocketClient (emitted by handlers)
|
|
1731
|
+
this.wsClient.on("wallet:tx_requested", (data) => {
|
|
1732
|
+
this.emit("wallet:tx_requested", data);
|
|
1733
|
+
});
|
|
1734
|
+
// Forward room pong events from WebSocketClient (emitted by pong handler)
|
|
1735
|
+
this.wsClient.on("room:pong", (data) => {
|
|
1736
|
+
this.emit("room:pong", data);
|
|
1737
|
+
});
|
|
1738
|
+
// Forward success events from WebSocketClient (emitted by handlers)
|
|
1739
|
+
this.wsClient.on("success", (message) => {
|
|
1740
|
+
this.emit("success", message);
|
|
1471
1741
|
});
|
|
1742
|
+
// Forward message deduplication events from WebSocketClient
|
|
1743
|
+
this.wsClient.on("message:duplicate", (message) => this.emit("message:duplicate", message));
|
|
1744
|
+
// Forward signature verification events from WebSocketClient
|
|
1745
|
+
this.wsClient.on("signature:verified", (messageType, address) => this.emit("signature:verified", messageType, address));
|
|
1746
|
+
this.wsClient.on("signature:failed", (messageType, reason, address) => this.emit("signature:failed", messageType, reason, address));
|
|
1747
|
+
this.wsClient.on("signature:missing", (messageType, required) => this.emit("signature:missing", messageType, required));
|
|
1472
1748
|
// Forward room events from WebSocketClient (emitted by room subscription handlers)
|
|
1473
1749
|
this.wsClient.on("room:subscribed", (data) => this.emit("room:subscribed", data));
|
|
1474
1750
|
this.wsClient.on("room:unsubscribed", (data) => this.emit("room:unsubscribed", data));
|
|
@@ -1538,11 +1814,11 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
1538
1814
|
// Emit on SDK for external listeners
|
|
1539
1815
|
this.emit("agent_room:agents_listed", roomId, agents);
|
|
1540
1816
|
});
|
|
1541
|
-
this.wsClient.on("agent_room:available_agents_listed", (agents) => {
|
|
1817
|
+
this.wsClient.on("agent_room:available_agents_listed", (agents, paginationMeta) => {
|
|
1542
1818
|
// Emit on AgentRoomManager for promise resolution
|
|
1543
|
-
this.agentRoom.emit("agent_room:available_agents_listed", agents);
|
|
1819
|
+
this.agentRoom.emit("agent_room:available_agents_listed", agents, paginationMeta);
|
|
1544
1820
|
// Emit on SDK for external listeners
|
|
1545
|
-
this.emit("agent_room:available_agents_listed", agents);
|
|
1821
|
+
this.emit("agent_room:available_agents_listed", agents, paginationMeta);
|
|
1546
1822
|
});
|
|
1547
1823
|
this.wsClient.on("agent_room:status_update", (data) => {
|
|
1548
1824
|
// Emit on SDK for external listeners
|
|
@@ -1634,13 +1910,14 @@ class TeneoSDK extends eventemitter3_1.EventEmitter {
|
|
|
1634
1910
|
*
|
|
1635
1911
|
* @example
|
|
1636
1912
|
* ```typescript
|
|
1637
|
-
* const
|
|
1638
|
-
* .
|
|
1639
|
-
* .
|
|
1640
|
-
* .
|
|
1641
|
-
* .
|
|
1642
|
-
* .
|
|
1913
|
+
* const config = TeneoSDK.builder()
|
|
1914
|
+
* .withWebSocketUrl('wss://teneo.example.com')
|
|
1915
|
+
* .withAuthentication('0x...')
|
|
1916
|
+
* .withAutoJoinPublicRooms(['public-room-1', 'public-room-2'])
|
|
1917
|
+
* .withLogging('debug')
|
|
1918
|
+
* .withWebhook('https://api.example.com/webhooks')
|
|
1643
1919
|
* .build();
|
|
1920
|
+
* const sdk = new TeneoSDK(config);
|
|
1644
1921
|
*
|
|
1645
1922
|
* await sdk.connect();
|
|
1646
1923
|
* ```
|