@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/src/teneo-sdk.ts
CHANGED
|
@@ -42,11 +42,14 @@ import {
|
|
|
42
42
|
QuoteResult,
|
|
43
43
|
AdminManager,
|
|
44
44
|
ListAllAgentsOptions,
|
|
45
|
-
AllAgentsResult
|
|
45
|
+
AllAgentsResult,
|
|
46
|
+
ListAvailableAgentsOptions,
|
|
47
|
+
PaginatedAgentsResult
|
|
46
48
|
} from "./managers";
|
|
47
49
|
import { createPinoLogger } from "./utils/logger";
|
|
48
50
|
import { RoomIdSchema, AgentIdSchema, AgentCommandContentSchema } from "./types/validation";
|
|
49
51
|
import { SecurePrivateKey } from "./utils/secure-private-key";
|
|
52
|
+
import { setNetworkConfigUrl, initializeNetworks } from "./payments";
|
|
50
53
|
|
|
51
54
|
// Re-export types for external use
|
|
52
55
|
export type {
|
|
@@ -54,7 +57,9 @@ export type {
|
|
|
54
57
|
AgentCommand,
|
|
55
58
|
QuoteResult,
|
|
56
59
|
ListAllAgentsOptions,
|
|
57
|
-
AllAgentsResult
|
|
60
|
+
AllAgentsResult,
|
|
61
|
+
ListAvailableAgentsOptions,
|
|
62
|
+
PaginatedAgentsResult
|
|
58
63
|
};
|
|
59
64
|
|
|
60
65
|
// Zod schemas for SDK-specific interfaces
|
|
@@ -101,7 +106,7 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
101
106
|
* @param config.wsUrl - WebSocket URL to connect to (e.g., 'wss://teneo.example.com')
|
|
102
107
|
* @param config.privateKey - Optional Ethereum private key for wallet-based authentication
|
|
103
108
|
* @param config.walletAddress - Optional wallet address (derived from privateKey if not provided)
|
|
104
|
-
* @param config.
|
|
109
|
+
* @param config.autoJoinPublicRooms - Optional array of public room IDs to subscribe to automatically on connection (private rooms are auto-available)
|
|
105
110
|
* @param config.webhookUrl - Optional webhook URL for receiving event notifications
|
|
106
111
|
* @param config.reconnect - Enable automatic reconnection (default: true)
|
|
107
112
|
* @param config.logLevel - Logging level: 'debug', 'info', 'warn', 'error', 'silent' (default: 'info')
|
|
@@ -121,7 +126,7 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
121
126
|
* const sdk = new TeneoSDK({
|
|
122
127
|
* wsUrl: 'wss://teneo.example.com',
|
|
123
128
|
* privateKey: '0x...',
|
|
124
|
-
*
|
|
129
|
+
* autoJoinPublicRooms: ['public-room-1', 'public-room-2'], // Public rooms only
|
|
125
130
|
* webhookUrl: 'https://api.example.com/webhooks',
|
|
126
131
|
* logLevel: 'debug',
|
|
127
132
|
* responseFormat: 'both',
|
|
@@ -130,11 +135,12 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
130
135
|
* });
|
|
131
136
|
*
|
|
132
137
|
* // Using builder pattern (recommended for complex configs)
|
|
133
|
-
* const
|
|
134
|
-
* .
|
|
135
|
-
* .
|
|
136
|
-
* .
|
|
138
|
+
* const config = TeneoSDK.builder()
|
|
139
|
+
* .withWebSocketUrl('wss://teneo.example.com')
|
|
140
|
+
* .withAuthentication('0x...')
|
|
141
|
+
* .withAutoJoinPublicRooms(['public-room-1', 'public-room-2'])
|
|
137
142
|
* .build();
|
|
143
|
+
* const sdk = new TeneoSDK(config);
|
|
138
144
|
* ```
|
|
139
145
|
*
|
|
140
146
|
* @see {@link SDKConfigBuilder} for fluent configuration API
|
|
@@ -199,20 +205,12 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
199
205
|
quoteTimeout: this.config.quoteTimeout,
|
|
200
206
|
wsUrl: this.config.wsUrl,
|
|
201
207
|
paymentNetwork: this.config.paymentNetwork,
|
|
202
|
-
paymentAsset: this.config.paymentAsset
|
|
208
|
+
paymentAsset: this.config.paymentAsset,
|
|
209
|
+
network: this.config.network // Network name from withNetwork()
|
|
203
210
|
}
|
|
204
211
|
);
|
|
205
212
|
|
|
206
|
-
//
|
|
207
|
-
if (this.config.privateKey) {
|
|
208
|
-
const secureKey =
|
|
209
|
-
this.config.privateKey instanceof SecurePrivateKey
|
|
210
|
-
? this.config.privateKey
|
|
211
|
-
: new SecurePrivateKey(this.config.privateKey);
|
|
212
|
-
const walletAddress =
|
|
213
|
-
this.config.walletAddress || this.deriveWalletAddress(this.config.privateKey);
|
|
214
|
-
this.messages.setPaymentClient(secureKey, walletAddress);
|
|
215
|
-
}
|
|
213
|
+
// NOTE: Payment client is set up in connect() after networks are initialized
|
|
216
214
|
|
|
217
215
|
// Set up event forwarding
|
|
218
216
|
this.setupEventForwarding();
|
|
@@ -250,12 +248,39 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
250
248
|
|
|
251
249
|
try {
|
|
252
250
|
this.logger.info("Connecting to Teneo Protocol");
|
|
251
|
+
|
|
252
|
+
// Initialize network configurations from backend before connecting
|
|
253
|
+
setNetworkConfigUrl(this.config.wsUrl);
|
|
254
|
+
await initializeNetworks();
|
|
255
|
+
|
|
256
|
+
// Verify networks are fully loaded before payment setup
|
|
257
|
+
const { NETWORKS } = await import("./payments/networks");
|
|
258
|
+
if (Object.keys(NETWORKS).length === 0) {
|
|
259
|
+
throw new SDKError(
|
|
260
|
+
"Failed to initialize networks from backend",
|
|
261
|
+
ErrorCode.CONFIG_ERROR,
|
|
262
|
+
null,
|
|
263
|
+
true
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// Set up payment client now that networks are initialized (v2.2.0)
|
|
268
|
+
if (this.config.privateKey) {
|
|
269
|
+
const secureKey =
|
|
270
|
+
this.config.privateKey instanceof SecurePrivateKey
|
|
271
|
+
? this.config.privateKey
|
|
272
|
+
: new SecurePrivateKey(this.config.privateKey);
|
|
273
|
+
const walletAddress =
|
|
274
|
+
this.config.walletAddress || this.deriveWalletAddress(this.config.privateKey);
|
|
275
|
+
this.messages.setPaymentClient(secureKey, walletAddress);
|
|
276
|
+
}
|
|
277
|
+
|
|
253
278
|
await this.connection.connect();
|
|
254
279
|
|
|
255
|
-
// Auto-join rooms if configured
|
|
256
|
-
if (this.config.
|
|
257
|
-
for (const room of this.config.
|
|
258
|
-
await this.rooms.
|
|
280
|
+
// Auto-join public rooms if configured
|
|
281
|
+
if (this.config.autoJoinPublicRooms && this.config.autoJoinPublicRooms.length > 0) {
|
|
282
|
+
for (const room of this.config.autoJoinPublicRooms) {
|
|
283
|
+
await this.rooms.subscribeToPublicRoom(room);
|
|
259
284
|
}
|
|
260
285
|
}
|
|
261
286
|
|
|
@@ -328,7 +353,9 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
328
353
|
* @param command.agent - The agent ID or name to send the command to
|
|
329
354
|
* @param command.command - The command text to send to the agent
|
|
330
355
|
* @param command.room - Room to send command to (defaults to configured default room)
|
|
331
|
-
* @
|
|
356
|
+
* @param command.network - Optional per-request network override (e.g., "base", "avalanche", or chain ID 8453)
|
|
357
|
+
* @param waitForResponse - Whether to wait for the agent's response (default: false)
|
|
358
|
+
* @returns Promise resolving to FormattedResponse if waitForResponse is true, void otherwise
|
|
332
359
|
* @throws {SDKError} If not connected to the network (ErrorCode.NOT_CONNECTED)
|
|
333
360
|
* @throws {ValidationError} If agent or command are empty, or room is not configured
|
|
334
361
|
*
|
|
@@ -338,8 +365,16 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
338
365
|
* await sdk.sendDirectCommand({
|
|
339
366
|
* agent: 'weather-agent',
|
|
340
367
|
* command: 'Get forecast for New York',
|
|
341
|
-
* room: '
|
|
368
|
+
* room: 'room-id'
|
|
342
369
|
* });
|
|
370
|
+
*
|
|
371
|
+
* // With per-request network override
|
|
372
|
+
* const response = await sdk.sendDirectCommand({
|
|
373
|
+
* agent: 'x-agent-enterprise-v2',
|
|
374
|
+
* command: 'user @elonmusk',
|
|
375
|
+
* room: 'room-id',
|
|
376
|
+
* network: 'base' // Pay on Base for this request
|
|
377
|
+
* }, true);
|
|
343
378
|
* ```
|
|
344
379
|
*/
|
|
345
380
|
public async sendDirectCommand(
|
|
@@ -354,8 +389,8 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
354
389
|
* The quote includes agent selection, pricing, and expiration.
|
|
355
390
|
* Does NOT auto-approve - use confirmQuote() to execute.
|
|
356
391
|
*/
|
|
357
|
-
public async requestQuote(content: string, room: string): Promise<QuoteResult> {
|
|
358
|
-
return this.messages.requestQuote(content, room);
|
|
392
|
+
public async requestQuote(content: string, room: string, networkOverride?: string | number): Promise<QuoteResult> {
|
|
393
|
+
return this.messages.requestQuote(content, room, networkOverride);
|
|
359
394
|
}
|
|
360
395
|
|
|
361
396
|
/**
|
|
@@ -389,14 +424,27 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
389
424
|
* @example
|
|
390
425
|
* ```typescript
|
|
391
426
|
* // Subscribe to a public room
|
|
392
|
-
* await sdk.
|
|
427
|
+
* await sdk.subscribeToPublicRoom('public-room-id');
|
|
393
428
|
* console.log('Subscribed to public room');
|
|
394
429
|
*
|
|
395
430
|
* // Note: Private rooms don't need subscription - you're always subscribed
|
|
396
431
|
* ```
|
|
397
432
|
*/
|
|
433
|
+
public async subscribeToPublicRoom(roomId: string): Promise<void> {
|
|
434
|
+
return this.rooms.subscribeToPublicRoom(roomId);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* @deprecated Use subscribeToPublicRoom() instead. This method only affects public rooms.
|
|
439
|
+
* Private rooms are automatically available after authentication without subscription.
|
|
440
|
+
*
|
|
441
|
+
* Subscribes to a public room in the Teneo Protocol.
|
|
442
|
+
*
|
|
443
|
+
* @param roomId - The ID of the public room to subscribe to
|
|
444
|
+
* @returns Promise that resolves when the room has been subscribed
|
|
445
|
+
*/
|
|
398
446
|
public async subscribeToRoom(roomId: string): Promise<void> {
|
|
399
|
-
return this.
|
|
447
|
+
return this.subscribeToPublicRoom(roomId);
|
|
400
448
|
}
|
|
401
449
|
|
|
402
450
|
/**
|
|
@@ -413,12 +461,25 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
413
461
|
*
|
|
414
462
|
* @example
|
|
415
463
|
* ```typescript
|
|
416
|
-
* await sdk.
|
|
464
|
+
* await sdk.unsubscribeFromPublicRoom('public-room-id');
|
|
417
465
|
* console.log('Unsubscribed from public room');
|
|
418
466
|
* ```
|
|
419
467
|
*/
|
|
468
|
+
public async unsubscribeFromPublicRoom(roomId: string): Promise<void> {
|
|
469
|
+
return this.rooms.unsubscribeFromPublicRoom(roomId);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* @deprecated Use unsubscribeFromPublicRoom() instead. This method only affects public rooms.
|
|
474
|
+
* Private rooms cannot be unsubscribed from.
|
|
475
|
+
*
|
|
476
|
+
* Unsubscribes from a public room in the Teneo Protocol.
|
|
477
|
+
*
|
|
478
|
+
* @param roomId - The ID of the public room to unsubscribe from
|
|
479
|
+
* @returns Promise that resolves when the room has been unsubscribed
|
|
480
|
+
*/
|
|
420
481
|
public async unsubscribeFromRoom(roomId: string): Promise<void> {
|
|
421
|
-
return this.
|
|
482
|
+
return this.unsubscribeFromPublicRoom(roomId);
|
|
422
483
|
}
|
|
423
484
|
|
|
424
485
|
/**
|
|
@@ -452,7 +513,7 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
452
513
|
* ```typescript
|
|
453
514
|
* const rooms = sdk.getSubscribedRooms();
|
|
454
515
|
* console.log(`Subscribed to ${rooms.length} rooms:`, rooms);
|
|
455
|
-
* // Example output: Subscribed to 3 rooms: ['
|
|
516
|
+
* // Example output: Subscribed to 3 rooms: ['room-id-1', 'room-id-2', 'room-id-3']
|
|
456
517
|
* ```
|
|
457
518
|
*/
|
|
458
519
|
public getSubscribedRooms(): string[] {
|
|
@@ -502,18 +563,18 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
502
563
|
}
|
|
503
564
|
|
|
504
565
|
/**
|
|
505
|
-
* Finds all agents that have a specific capability using O(1) indexed lookup (PERF-3).
|
|
566
|
+
* Finds all available agents (network-wide) that have a specific capability using O(1) indexed lookup (PERF-3).
|
|
506
567
|
* Much faster than filtering through all agents manually.
|
|
507
568
|
* Uses capability index for constant-time lookups regardless of agent count.
|
|
508
569
|
*
|
|
509
570
|
* @param capability - The capability name to search for (case-insensitive)
|
|
510
|
-
* @returns Read-only array of agents with the specified capability
|
|
571
|
+
* @returns Read-only array of available agents with the specified capability
|
|
511
572
|
* @throws {ValidationError} If capability name is invalid
|
|
512
573
|
*
|
|
513
574
|
* @example
|
|
514
575
|
* ```typescript
|
|
515
|
-
* // Find all weather-capable agents
|
|
516
|
-
* const weatherAgents = sdk.
|
|
576
|
+
* // Find all weather-capable agents available on the network
|
|
577
|
+
* const weatherAgents = sdk.findAvailableAgentsByCapability('weather-forecast');
|
|
517
578
|
* console.log(`Found ${weatherAgents.length} weather agents`);
|
|
518
579
|
*
|
|
519
580
|
* weatherAgents.forEach(agent => {
|
|
@@ -521,54 +582,90 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
521
582
|
* });
|
|
522
583
|
* ```
|
|
523
584
|
*/
|
|
524
|
-
public
|
|
585
|
+
public findAvailableAgentsByCapability(capability: string): ReadonlyArray<Agent> {
|
|
525
586
|
return this.agents.findByCapability(capability);
|
|
526
587
|
}
|
|
527
588
|
|
|
528
589
|
/**
|
|
529
|
-
*
|
|
590
|
+
* @deprecated Use findAvailableAgentsByCapability() instead. This searches all available agents network-wide.
|
|
591
|
+
*
|
|
592
|
+
* Finds all agents that have a specific capability.
|
|
593
|
+
*
|
|
594
|
+
* @param capability - The capability name to search for
|
|
595
|
+
* @returns Read-only array of agents with the specified capability
|
|
596
|
+
*/
|
|
597
|
+
public findAgentsByCapability(capability: string): ReadonlyArray<Agent> {
|
|
598
|
+
return this.findAvailableAgentsByCapability(capability);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Finds available agents (network-wide) by name using O(k) token-based search (PERF-3).
|
|
530
603
|
* Supports partial matching - searches for tokens within agent names.
|
|
531
604
|
* Tokenizes both the search query and agent names for flexible matching.
|
|
532
605
|
*
|
|
533
606
|
* @param name - Name or partial name to search for (case-insensitive)
|
|
534
|
-
* @returns Read-only array of agents matching the search
|
|
607
|
+
* @returns Read-only array of available agents matching the search
|
|
535
608
|
* @throws {ValidationError} If name is invalid
|
|
536
609
|
*
|
|
537
610
|
* @example
|
|
538
611
|
* ```typescript
|
|
539
|
-
* // Find all agents with "weather" in their name
|
|
540
|
-
* const agents = sdk.
|
|
612
|
+
* // Find all available agents with "weather" in their name
|
|
613
|
+
* const agents = sdk.findAvailableAgentsByName('weather');
|
|
541
614
|
* // Matches: "Weather Agent", "Weather Forecast Bot", "Advanced Weather API", etc.
|
|
542
615
|
*
|
|
543
616
|
* console.log(`Found ${agents.length} agents matching 'weather'`);
|
|
544
617
|
* ```
|
|
545
618
|
*/
|
|
546
|
-
public
|
|
619
|
+
public findAvailableAgentsByName(name: string): ReadonlyArray<Agent> {
|
|
547
620
|
return this.agents.findByName(name);
|
|
548
621
|
}
|
|
549
622
|
|
|
550
623
|
/**
|
|
551
|
-
*
|
|
624
|
+
* @deprecated Use findAvailableAgentsByName() instead. This searches all available agents network-wide.
|
|
625
|
+
*
|
|
626
|
+
* Finds agents by name.
|
|
627
|
+
*
|
|
628
|
+
* @param name - Name or partial name to search for
|
|
629
|
+
* @returns Read-only array of agents matching the search
|
|
630
|
+
*/
|
|
631
|
+
public findAgentsByName(name: string): ReadonlyArray<Agent> {
|
|
632
|
+
return this.findAvailableAgentsByName(name);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Finds all available agents (network-wide) with a specific status using O(1) indexed lookup (PERF-3).
|
|
552
637
|
* Uses status index for constant-time lookups regardless of agent count.
|
|
553
638
|
*
|
|
554
639
|
* @param status - Agent status: 'online' or 'offline' (case-insensitive)
|
|
555
|
-
* @returns Read-only array of agents with the specified status
|
|
640
|
+
* @returns Read-only array of available agents with the specified status
|
|
556
641
|
* @throws {ValidationError} If status is invalid
|
|
557
642
|
*
|
|
558
643
|
* @example
|
|
559
644
|
* ```typescript
|
|
560
|
-
* // Get all online agents
|
|
561
|
-
* const onlineAgents = sdk.
|
|
645
|
+
* // Get all online agents available on the network
|
|
646
|
+
* const onlineAgents = sdk.findAvailableAgentsByStatus('online');
|
|
562
647
|
* console.log(`${onlineAgents.length} agents are currently online`);
|
|
563
648
|
*
|
|
564
649
|
* // Get offline agents
|
|
565
|
-
* const offlineAgents = sdk.
|
|
650
|
+
* const offlineAgents = sdk.findAvailableAgentsByStatus('offline');
|
|
566
651
|
* ```
|
|
567
652
|
*/
|
|
568
|
-
public
|
|
653
|
+
public findAvailableAgentsByStatus(status: string): ReadonlyArray<Agent> {
|
|
569
654
|
return this.agents.findByStatus(status);
|
|
570
655
|
}
|
|
571
656
|
|
|
657
|
+
/**
|
|
658
|
+
* @deprecated Use findAvailableAgentsByStatus() instead. This searches all available agents network-wide.
|
|
659
|
+
*
|
|
660
|
+
* Finds all agents with a specific status.
|
|
661
|
+
*
|
|
662
|
+
* @param status - Agent status: 'online' or 'offline'
|
|
663
|
+
* @returns Read-only array of agents with the specified status
|
|
664
|
+
*/
|
|
665
|
+
public findAgentsByStatus(status: string): ReadonlyArray<Agent> {
|
|
666
|
+
return this.findAvailableAgentsByStatus(status);
|
|
667
|
+
}
|
|
668
|
+
|
|
572
669
|
/**
|
|
573
670
|
* Fetches detailed information about a specific agent from the server.
|
|
574
671
|
* Makes a request to the server for full agent details including capabilities,
|
|
@@ -610,7 +707,7 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
610
707
|
* console.log(`Found ${result.total} agents`);
|
|
611
708
|
*
|
|
612
709
|
* result.agents.forEach(agent => {
|
|
613
|
-
* console.log(`${agent.agent_name}:
|
|
710
|
+
* console.log(`${agent.agent_name}: status=${agent.review_status}, banned=${agent.is_banned}`);
|
|
614
711
|
* });
|
|
615
712
|
*
|
|
616
713
|
* // Get user count
|
|
@@ -683,7 +780,7 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
683
780
|
*
|
|
684
781
|
* @example
|
|
685
782
|
* ```typescript
|
|
686
|
-
* const room = sdk.getRoom('
|
|
783
|
+
* const room = sdk.getRoom('room-id');
|
|
687
784
|
* if (room) {
|
|
688
785
|
* console.log(`Found room: ${room.name}`);
|
|
689
786
|
* console.log(`Members: ${room.members?.length ?? 0}`);
|
|
@@ -970,13 +1067,31 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
970
1067
|
*
|
|
971
1068
|
* @example
|
|
972
1069
|
* ```typescript
|
|
1070
|
+
* // Simple usage (cached)
|
|
973
1071
|
* const available = await sdk.listAvailableAgents('room-123');
|
|
974
1072
|
* console.log(`${available.length} agents available to add`);
|
|
1073
|
+
*
|
|
1074
|
+
* // With pagination options
|
|
1075
|
+
* const result = await sdk.listAvailableAgents('room-123', {
|
|
1076
|
+
* limit: 20,
|
|
1077
|
+
* offset: 0,
|
|
1078
|
+
* sortBy: 'a-z'
|
|
1079
|
+
* });
|
|
1080
|
+
* console.log(`${result.total} total agents, showing ${result.agents.length}`);
|
|
975
1081
|
* ```
|
|
976
1082
|
*/
|
|
977
1083
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
978
|
-
public async listAvailableAgents(roomId: string, useCache
|
|
979
|
-
|
|
1084
|
+
public async listAvailableAgents(roomId: string, useCache?: boolean): Promise<any[]>;
|
|
1085
|
+
public async listAvailableAgents(
|
|
1086
|
+
roomId: string,
|
|
1087
|
+
options: ListAvailableAgentsOptions
|
|
1088
|
+
): Promise<PaginatedAgentsResult>;
|
|
1089
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1090
|
+
public async listAvailableAgents(
|
|
1091
|
+
roomId: string,
|
|
1092
|
+
useCacheOrOptions?: boolean | ListAvailableAgentsOptions
|
|
1093
|
+
): Promise<any[] | PaginatedAgentsResult> {
|
|
1094
|
+
return this.agentRoom.listAvailableAgents(roomId, useCacheOrOptions as any);
|
|
980
1095
|
}
|
|
981
1096
|
|
|
982
1097
|
/**
|
|
@@ -988,7 +1103,7 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
988
1103
|
*
|
|
989
1104
|
* @example
|
|
990
1105
|
* ```typescript
|
|
991
|
-
* const agents = sdk.
|
|
1106
|
+
* const agents = sdk.getCachedRoomAgents('room-123');
|
|
992
1107
|
* if (agents) {
|
|
993
1108
|
* console.log(`${agents.length} agents (cached)`);
|
|
994
1109
|
* } else {
|
|
@@ -997,8 +1112,22 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
997
1112
|
* ```
|
|
998
1113
|
*/
|
|
999
1114
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1115
|
+
public getCachedRoomAgents(roomId: string): any[] | undefined {
|
|
1116
|
+
return this.agentRoom.getCachedRoomAgents(roomId);
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
/**
|
|
1120
|
+
* @deprecated Use getCachedRoomAgents() instead. This method returns cached data only.
|
|
1121
|
+
* Use listRoomAgents() to fetch fresh data from server.
|
|
1122
|
+
*
|
|
1123
|
+
* Gets agents in a room from cache (synchronous).
|
|
1124
|
+
*
|
|
1125
|
+
* @param roomId - ID of the room
|
|
1126
|
+
* @returns Array of agents if cached, undefined otherwise
|
|
1127
|
+
*/
|
|
1128
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1000
1129
|
public getRoomAgents(roomId: string): any[] | undefined {
|
|
1001
|
-
return this.
|
|
1130
|
+
return this.getCachedRoomAgents(roomId);
|
|
1002
1131
|
}
|
|
1003
1132
|
|
|
1004
1133
|
/**
|
|
@@ -1010,15 +1139,29 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
1010
1139
|
*
|
|
1011
1140
|
* @example
|
|
1012
1141
|
* ```typescript
|
|
1013
|
-
* const available = sdk.
|
|
1142
|
+
* const available = sdk.getCachedAvailableAgents('room-123');
|
|
1014
1143
|
* if (available) {
|
|
1015
1144
|
* console.log(`${available.length} agents available (cached)`);
|
|
1016
1145
|
* }
|
|
1017
1146
|
* ```
|
|
1018
1147
|
*/
|
|
1019
1148
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1149
|
+
public getCachedAvailableAgents(roomId: string): any[] | undefined {
|
|
1150
|
+
return this.agentRoom.getCachedAvailableAgents(roomId);
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
/**
|
|
1154
|
+
* @deprecated Use getCachedAvailableAgents() instead. This method returns cached data only.
|
|
1155
|
+
* Use listAvailableAgents() to fetch fresh data from server.
|
|
1156
|
+
*
|
|
1157
|
+
* Gets available agents for a room from cache (synchronous).
|
|
1158
|
+
*
|
|
1159
|
+
* @param roomId - ID of the room
|
|
1160
|
+
* @returns Array of available agents if cached, undefined otherwise
|
|
1161
|
+
*/
|
|
1162
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1020
1163
|
public getAvailableAgents(roomId: string): any[] | undefined {
|
|
1021
|
-
return this.
|
|
1164
|
+
return this.getCachedAvailableAgents(roomId);
|
|
1022
1165
|
}
|
|
1023
1166
|
|
|
1024
1167
|
/**
|
|
@@ -1031,18 +1174,32 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
1031
1174
|
*
|
|
1032
1175
|
* @example
|
|
1033
1176
|
* ```typescript
|
|
1034
|
-
* const inRoom = sdk.
|
|
1177
|
+
* const inRoom = sdk.checkAgentInRoom('room-123', 'weather-agent');
|
|
1035
1178
|
* if (inRoom === true) {
|
|
1036
1179
|
* console.log('Agent is in room');
|
|
1037
1180
|
* } else if (inRoom === false) {
|
|
1038
1181
|
* console.log('Agent is not in room');
|
|
1039
1182
|
* } else {
|
|
1040
|
-
* console.log('Room data not cached');
|
|
1183
|
+
* console.log('Room data not cached - need to fetch');
|
|
1041
1184
|
* }
|
|
1042
1185
|
* ```
|
|
1043
1186
|
*/
|
|
1187
|
+
public checkAgentInRoom(roomId: string, agentId: string): boolean | undefined {
|
|
1188
|
+
return this.agentRoom.checkAgentInRoom(roomId, agentId);
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
/**
|
|
1192
|
+
* @deprecated Use checkAgentInRoom() instead. The 'is*' naming convention implies boolean-only,
|
|
1193
|
+
* but this method returns boolean | undefined to indicate cache validity.
|
|
1194
|
+
*
|
|
1195
|
+
* Checks if an agent is in a room (synchronous, from cache).
|
|
1196
|
+
*
|
|
1197
|
+
* @param roomId - ID of the room
|
|
1198
|
+
* @param agentId - ID of the agent
|
|
1199
|
+
* @returns True if agent is in room, false if not, undefined if not cached
|
|
1200
|
+
*/
|
|
1044
1201
|
public isAgentInRoom(roomId: string, agentId: string): boolean | undefined {
|
|
1045
|
-
return this.
|
|
1202
|
+
return this.checkAgentInRoom(roomId, agentId);
|
|
1046
1203
|
}
|
|
1047
1204
|
|
|
1048
1205
|
/**
|
|
@@ -1054,14 +1211,27 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
1054
1211
|
*
|
|
1055
1212
|
* @example
|
|
1056
1213
|
* ```typescript
|
|
1057
|
-
* const count = sdk.
|
|
1214
|
+
* const count = sdk.getCachedRoomAgentCount('room-123');
|
|
1058
1215
|
* if (count !== undefined) {
|
|
1059
1216
|
* console.log(`Room has ${count} agents`);
|
|
1060
1217
|
* }
|
|
1061
1218
|
* ```
|
|
1062
1219
|
*/
|
|
1220
|
+
public getCachedRoomAgentCount(roomId: string): number | undefined {
|
|
1221
|
+
return this.agentRoom.getCachedRoomAgentCount(roomId);
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
/**
|
|
1225
|
+
* @deprecated Use getCachedRoomAgentCount() instead. This method returns cached data only.
|
|
1226
|
+
* Use listRoomAgents() to fetch fresh data from server.
|
|
1227
|
+
*
|
|
1228
|
+
* Gets the count of agents in a room (synchronous, from cache).
|
|
1229
|
+
*
|
|
1230
|
+
* @param roomId - ID of the room
|
|
1231
|
+
* @returns Number of agents in room, or undefined if not cached
|
|
1232
|
+
*/
|
|
1063
1233
|
public getRoomAgentCount(roomId: string): number | undefined {
|
|
1064
|
-
return this.
|
|
1234
|
+
return this.getCachedRoomAgentCount(roomId);
|
|
1065
1235
|
}
|
|
1066
1236
|
|
|
1067
1237
|
/**
|
|
@@ -1156,6 +1326,126 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
1156
1326
|
});
|
|
1157
1327
|
}
|
|
1158
1328
|
|
|
1329
|
+
/**
|
|
1330
|
+
* Sends the result of an on-chain transaction back to the server.
|
|
1331
|
+
* Used in response to a "wallet:tx_requested" event after the user
|
|
1332
|
+
* has confirmed, rejected, or encountered a failure with the transaction.
|
|
1333
|
+
*
|
|
1334
|
+
* @param taskId - The task ID from the wallet:tx_requested event
|
|
1335
|
+
* @param status - Transaction result: "confirmed", "rejected", or "failed"
|
|
1336
|
+
* @param txHash - The on-chain transaction hash (required for "confirmed" status)
|
|
1337
|
+
* @param error - Error message (optional, for "failed" status)
|
|
1338
|
+
* @throws {SDKError} If the SDK has been destroyed or not connected
|
|
1339
|
+
*
|
|
1340
|
+
* @example
|
|
1341
|
+
* ```typescript
|
|
1342
|
+
* sdk.on("wallet:tx_requested", async (data) => {
|
|
1343
|
+
* try {
|
|
1344
|
+
* const txHash = await wallet.sendTransaction(data.tx);
|
|
1345
|
+
* await sdk.sendTxResult(data.taskId, "confirmed", txHash);
|
|
1346
|
+
* } catch (err) {
|
|
1347
|
+
* await sdk.sendTxResult(data.taskId, "failed", undefined, err.message);
|
|
1348
|
+
* }
|
|
1349
|
+
* });
|
|
1350
|
+
* ```
|
|
1351
|
+
*/
|
|
1352
|
+
public async sendTxResult(
|
|
1353
|
+
taskId: string,
|
|
1354
|
+
status: "confirmed" | "rejected" | "failed",
|
|
1355
|
+
txHash?: string,
|
|
1356
|
+
error?: string
|
|
1357
|
+
): Promise<void> {
|
|
1358
|
+
if (this.isDestroyed) {
|
|
1359
|
+
throw new SDKError("SDK has been destroyed", ErrorCode.SDK_DESTROYED, null, false);
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
if (!this.wsClient.isConnected) {
|
|
1363
|
+
throw new SDKError("Not connected to Teneo Protocol", ErrorCode.NOT_CONNECTED);
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
const message = {
|
|
1367
|
+
type: "tx_result" as const,
|
|
1368
|
+
data: {
|
|
1369
|
+
task_id: taskId,
|
|
1370
|
+
status,
|
|
1371
|
+
...(txHash && { tx_hash: txHash }),
|
|
1372
|
+
...(error && { error })
|
|
1373
|
+
}
|
|
1374
|
+
};
|
|
1375
|
+
|
|
1376
|
+
await this.wsClient.sendMessage(message);
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
/**
|
|
1380
|
+
* Sets the API key preference for the current user.
|
|
1381
|
+
* Controls whether custom API keys are used for agent interactions.
|
|
1382
|
+
*
|
|
1383
|
+
* @param useCustomKeys - Whether to use custom API keys
|
|
1384
|
+
* @throws {SDKError} If the SDK has been destroyed or not connected
|
|
1385
|
+
*
|
|
1386
|
+
* @example
|
|
1387
|
+
* ```typescript
|
|
1388
|
+
* // Enable custom API keys
|
|
1389
|
+
* await sdk.setApiKeyPreference(true);
|
|
1390
|
+
*
|
|
1391
|
+
* // Disable custom API keys
|
|
1392
|
+
* await sdk.setApiKeyPreference(false);
|
|
1393
|
+
* ```
|
|
1394
|
+
*/
|
|
1395
|
+
public async setApiKeyPreference(useCustomKeys: boolean): Promise<void> {
|
|
1396
|
+
if (this.isDestroyed) {
|
|
1397
|
+
throw new SDKError("SDK has been destroyed", ErrorCode.SDK_DESTROYED, null, false);
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
if (!this.wsClient.isConnected) {
|
|
1401
|
+
throw new SDKError("Not connected to Teneo Protocol", ErrorCode.NOT_CONNECTED);
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
const message = {
|
|
1405
|
+
type: "set_api_key_preference" as const,
|
|
1406
|
+
data: {
|
|
1407
|
+
use_custom_keys: useCustomKeys
|
|
1408
|
+
}
|
|
1409
|
+
};
|
|
1410
|
+
|
|
1411
|
+
await this.wsClient.sendMessage(message);
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
/**
|
|
1415
|
+
* Send a room ping to get live user count
|
|
1416
|
+
* Server responds with room_pong message containing current live user count
|
|
1417
|
+
*
|
|
1418
|
+
* @param roomId - The room ID to ping
|
|
1419
|
+
* @throws {SDKError} If not connected or SDK is destroyed
|
|
1420
|
+
*
|
|
1421
|
+
* @example
|
|
1422
|
+
* ```typescript
|
|
1423
|
+
* // Ping a room to get live user count
|
|
1424
|
+
* await sdk.sendRoomPing("my-room");
|
|
1425
|
+
*
|
|
1426
|
+
* // Listen for the response
|
|
1427
|
+
* sdk.on("room:pong", (data) => {
|
|
1428
|
+
* console.log(`Room ${data.roomId} has ${data.liveCount} live users`);
|
|
1429
|
+
* });
|
|
1430
|
+
* ```
|
|
1431
|
+
*/
|
|
1432
|
+
public async sendRoomPing(roomId: string): Promise<void> {
|
|
1433
|
+
if (this.isDestroyed) {
|
|
1434
|
+
throw new SDKError("SDK has been destroyed", ErrorCode.SDK_DESTROYED, null, false);
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
if (!this.wsClient.isConnected) {
|
|
1438
|
+
throw new SDKError("Not connected to Teneo Protocol", ErrorCode.NOT_CONNECTED);
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
const message = {
|
|
1442
|
+
type: "room_ping" as const,
|
|
1443
|
+
room_id: roomId
|
|
1444
|
+
};
|
|
1445
|
+
|
|
1446
|
+
await this.wsClient.sendMessage(message);
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1159
1449
|
/**
|
|
1160
1450
|
* Configures webhook URL and headers for receiving real-time event notifications.
|
|
1161
1451
|
* Webhooks allow you to receive events at your server endpoint via HTTP POST requests.
|
|
@@ -1555,9 +1845,9 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
1555
1845
|
|
|
1556
1846
|
// Destroy other components
|
|
1557
1847
|
this.webhookHandler.destroy();
|
|
1558
|
-
this.removeAllListeners();
|
|
1559
1848
|
|
|
1560
1849
|
this.emit("destroy");
|
|
1850
|
+
this.removeAllListeners();
|
|
1561
1851
|
}
|
|
1562
1852
|
|
|
1563
1853
|
/**
|
|
@@ -1642,8 +1932,48 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
1642
1932
|
// Handle agent list updates from WebSocketClient
|
|
1643
1933
|
this.wsClient.on("agent:list", (agents) => {
|
|
1644
1934
|
this.agents.updateAgents(agents);
|
|
1935
|
+
this.emit("agent:list", agents);
|
|
1936
|
+
});
|
|
1937
|
+
|
|
1938
|
+
// Forward task confirmed events from WebSocketClient (emitted by handlers)
|
|
1939
|
+
this.wsClient.on("task:confirmed", (data) => {
|
|
1940
|
+
this.emit("task:confirmed", data);
|
|
1941
|
+
});
|
|
1942
|
+
|
|
1943
|
+
// Forward agent error events from WebSocketClient (emitted by handlers)
|
|
1944
|
+
this.wsClient.on("agent:error", (data) => {
|
|
1945
|
+
this.emit("agent:error", data);
|
|
1946
|
+
});
|
|
1947
|
+
|
|
1948
|
+
// Forward wallet transaction events from WebSocketClient (emitted by handlers)
|
|
1949
|
+
this.wsClient.on("wallet:tx_requested", (data) => {
|
|
1950
|
+
this.emit("wallet:tx_requested", data);
|
|
1951
|
+
});
|
|
1952
|
+
|
|
1953
|
+
// Forward room pong events from WebSocketClient (emitted by pong handler)
|
|
1954
|
+
this.wsClient.on("room:pong", (data) => {
|
|
1955
|
+
this.emit("room:pong", data);
|
|
1956
|
+
});
|
|
1957
|
+
|
|
1958
|
+
// Forward success events from WebSocketClient (emitted by handlers)
|
|
1959
|
+
this.wsClient.on("success", (message) => {
|
|
1960
|
+
this.emit("success", message);
|
|
1645
1961
|
});
|
|
1646
1962
|
|
|
1963
|
+
// Forward message deduplication events from WebSocketClient
|
|
1964
|
+
this.wsClient.on("message:duplicate", (message) => this.emit("message:duplicate", message));
|
|
1965
|
+
|
|
1966
|
+
// Forward signature verification events from WebSocketClient
|
|
1967
|
+
this.wsClient.on("signature:verified", (messageType, address) =>
|
|
1968
|
+
this.emit("signature:verified", messageType, address)
|
|
1969
|
+
);
|
|
1970
|
+
this.wsClient.on("signature:failed", (messageType, reason, address) =>
|
|
1971
|
+
this.emit("signature:failed", messageType, reason, address)
|
|
1972
|
+
);
|
|
1973
|
+
this.wsClient.on("signature:missing", (messageType, required) =>
|
|
1974
|
+
this.emit("signature:missing", messageType, required)
|
|
1975
|
+
);
|
|
1976
|
+
|
|
1647
1977
|
// Forward room events from WebSocketClient (emitted by room subscription handlers)
|
|
1648
1978
|
this.wsClient.on("room:subscribed", (data) => this.emit("room:subscribed", data));
|
|
1649
1979
|
this.wsClient.on("room:unsubscribed", (data) => this.emit("room:unsubscribed", data));
|
|
@@ -1715,11 +2045,11 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
1715
2045
|
// Emit on SDK for external listeners
|
|
1716
2046
|
this.emit("agent_room:agents_listed", roomId, agents);
|
|
1717
2047
|
});
|
|
1718
|
-
this.wsClient.on("agent_room:available_agents_listed", (agents) => {
|
|
2048
|
+
this.wsClient.on("agent_room:available_agents_listed", (agents, paginationMeta) => {
|
|
1719
2049
|
// Emit on AgentRoomManager for promise resolution
|
|
1720
|
-
this.agentRoom.emit("agent_room:available_agents_listed", agents);
|
|
2050
|
+
this.agentRoom.emit("agent_room:available_agents_listed", agents, paginationMeta);
|
|
1721
2051
|
// Emit on SDK for external listeners
|
|
1722
|
-
this.emit("agent_room:available_agents_listed", agents);
|
|
2052
|
+
this.emit("agent_room:available_agents_listed", agents, paginationMeta);
|
|
1723
2053
|
});
|
|
1724
2054
|
this.wsClient.on("agent_room:status_update", (data) => {
|
|
1725
2055
|
// Emit on SDK for external listeners
|
|
@@ -1827,13 +2157,14 @@ export class TeneoSDK extends EventEmitter<SDKEvents> {
|
|
|
1827
2157
|
*
|
|
1828
2158
|
* @example
|
|
1829
2159
|
* ```typescript
|
|
1830
|
-
* const
|
|
1831
|
-
* .
|
|
1832
|
-
* .
|
|
1833
|
-
* .
|
|
1834
|
-
* .
|
|
1835
|
-
* .
|
|
2160
|
+
* const config = TeneoSDK.builder()
|
|
2161
|
+
* .withWebSocketUrl('wss://teneo.example.com')
|
|
2162
|
+
* .withAuthentication('0x...')
|
|
2163
|
+
* .withAutoJoinPublicRooms(['public-room-1', 'public-room-2'])
|
|
2164
|
+
* .withLogging('debug')
|
|
2165
|
+
* .withWebhook('https://api.example.com/webhooks')
|
|
1836
2166
|
* .build();
|
|
2167
|
+
* const sdk = new TeneoSDK(config);
|
|
1837
2168
|
*
|
|
1838
2169
|
* await sdk.connect();
|
|
1839
2170
|
* ```
|