@teneo-protocol/sdk 2.2.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/ISSUE_TEMPLATE/config.yml +1 -1
- package/CHANGELOG.md +366 -15
- package/CONCEPTS.md +182 -44
- package/README.md +524 -94
- package/dist/constants.d.ts +3 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +5 -3
- package/dist/constants.js.map +1 -1
- package/dist/core/websocket-client.d.ts.map +1 -1
- package/dist/core/websocket-client.js +9 -5
- package/dist/core/websocket-client.js.map +1 -1
- package/dist/formatters/response-formatter.d.ts +6 -6
- package/dist/handlers/message-handlers/agent-details-response-handler.d.ts +756 -756
- package/dist/handlers/message-handlers/agent-details-response-handler.js +2 -2
- package/dist/handlers/message-handlers/agent-details-response-handler.js.map +1 -1
- package/dist/handlers/message-handlers/agent-error-handler.d.ts +91 -0
- package/dist/handlers/message-handlers/agent-error-handler.d.ts.map +1 -0
- package/dist/handlers/message-handlers/agent-error-handler.js +44 -0
- package/dist/handlers/message-handlers/agent-error-handler.js.map +1 -0
- package/dist/handlers/message-handlers/agent-selected-handler.d.ts +6 -0
- package/dist/handlers/message-handlers/agent-selected-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/agent-status-update-handler.d.ts +756 -756
- package/dist/handlers/message-handlers/agent-status-update-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/agent-status-update-handler.js +2 -7
- package/dist/handlers/message-handlers/agent-status-update-handler.js.map +1 -1
- package/dist/handlers/message-handlers/all-agents-response-handler.js +2 -2
- package/dist/handlers/message-handlers/all-agents-response-handler.js.map +1 -1
- package/dist/handlers/message-handlers/auth-error-handler.d.ts +6 -0
- package/dist/handlers/message-handlers/auth-error-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/auth-message-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/auth-message-handler.js +6 -1
- package/dist/handlers/message-handlers/auth-message-handler.js.map +1 -1
- package/dist/handlers/message-handlers/auth-required-handler.d.ts +6 -0
- package/dist/handlers/message-handlers/auth-required-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/auth-success-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/auth-success-handler.js +6 -1
- package/dist/handlers/message-handlers/auth-success-handler.js.map +1 -1
- package/dist/handlers/message-handlers/base-handler.d.ts +2 -1
- package/dist/handlers/message-handlers/base-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/base-handler.js +24 -4
- package/dist/handlers/message-handlers/base-handler.js.map +1 -1
- package/dist/handlers/message-handlers/challenge-handler.d.ts +6 -0
- package/dist/handlers/message-handlers/challenge-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/error-message-handler.d.ts +6 -0
- package/dist/handlers/message-handlers/error-message-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/index.d.ts +4 -0
- package/dist/handlers/message-handlers/index.d.ts.map +1 -1
- package/dist/handlers/message-handlers/index.js +23 -1
- package/dist/handlers/message-handlers/index.js.map +1 -1
- package/dist/handlers/message-handlers/list-available-agents-handler.d.ts +792 -756
- package/dist/handlers/message-handlers/list-available-agents-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/list-available-agents-handler.js +23 -10
- package/dist/handlers/message-handlers/list-available-agents-handler.js.map +1 -1
- package/dist/handlers/message-handlers/list-room-agents-handler.d.ts +756 -756
- package/dist/handlers/message-handlers/list-room-agents-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/list-room-agents-handler.js +2 -6
- package/dist/handlers/message-handlers/list-room-agents-handler.js.map +1 -1
- package/dist/handlers/message-handlers/list-rooms-response-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/list-rooms-response-handler.js +2 -5
- package/dist/handlers/message-handlers/list-rooms-response-handler.js.map +1 -1
- package/dist/handlers/message-handlers/ping-pong-handler.d.ts +52 -4
- package/dist/handlers/message-handlers/ping-pong-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/ping-pong-handler.js +23 -4
- package/dist/handlers/message-handlers/ping-pong-handler.js.map +1 -1
- package/dist/handlers/message-handlers/rate-limit-notification-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/rate-limit-notification-handler.js +3 -2
- package/dist/handlers/message-handlers/rate-limit-notification-handler.js.map +1 -1
- package/dist/handlers/message-handlers/regular-message-handler.d.ts +6 -0
- package/dist/handlers/message-handlers/regular-message-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/subscribe-response-handler.d.ts +12 -6
- package/dist/handlers/message-handlers/subscribe-response-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/success-handler.d.ts +82 -0
- package/dist/handlers/message-handlers/success-handler.d.ts.map +1 -0
- package/dist/handlers/message-handlers/success-handler.js +24 -0
- package/dist/handlers/message-handlers/success-handler.js.map +1 -0
- package/dist/handlers/message-handlers/task-confirmed-handler.d.ts +110 -0
- package/dist/handlers/message-handlers/task-confirmed-handler.d.ts.map +1 -0
- package/dist/handlers/message-handlers/task-confirmed-handler.js +46 -0
- package/dist/handlers/message-handlers/task-confirmed-handler.js.map +1 -0
- package/dist/handlers/message-handlers/trigger-wallet-tx-handler.d.ts +244 -0
- package/dist/handlers/message-handlers/trigger-wallet-tx-handler.d.ts.map +1 -0
- package/dist/handlers/message-handlers/trigger-wallet-tx-handler.js +58 -0
- package/dist/handlers/message-handlers/trigger-wallet-tx-handler.js.map +1 -0
- package/dist/handlers/message-handlers/unsubscribe-response-handler.d.ts +12 -6
- package/dist/handlers/message-handlers/unsubscribe-response-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/user-authenticated-handler.js +2 -2
- package/dist/handlers/message-handlers/user-authenticated-handler.js.map +1 -1
- package/dist/handlers/message-handlers/user-count-handler.js +2 -2
- package/dist/handlers/message-handlers/user-count-handler.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -4
- package/dist/index.js.map +1 -1
- package/dist/managers/admin-manager.d.ts +2 -0
- package/dist/managers/admin-manager.d.ts.map +1 -1
- package/dist/managers/admin-manager.js +3 -2
- package/dist/managers/admin-manager.js.map +1 -1
- package/dist/managers/agent-room-manager.d.ts +89 -11
- package/dist/managers/agent-room-manager.d.ts.map +1 -1
- package/dist/managers/agent-room-manager.js +99 -35
- package/dist/managers/agent-room-manager.js.map +1 -1
- package/dist/managers/index.d.ts +1 -1
- package/dist/managers/index.d.ts.map +1 -1
- package/dist/managers/index.js.map +1 -1
- package/dist/managers/message-router.d.ts +45 -5
- package/dist/managers/message-router.d.ts.map +1 -1
- package/dist/managers/message-router.js +96 -24
- package/dist/managers/message-router.js.map +1 -1
- package/dist/managers/room-manager.d.ts +29 -7
- package/dist/managers/room-manager.d.ts.map +1 -1
- package/dist/managers/room-manager.js +37 -11
- package/dist/managers/room-manager.js.map +1 -1
- package/dist/payments/index.d.ts +3 -1
- package/dist/payments/index.d.ts.map +1 -1
- package/dist/payments/index.js +17 -3
- package/dist/payments/index.js.map +1 -1
- package/dist/payments/networks.d.ts +59 -0
- package/dist/payments/networks.d.ts.map +1 -0
- package/dist/payments/networks.js +192 -0
- package/dist/payments/networks.js.map +1 -0
- package/dist/payments/payment-client.d.ts +55 -10
- package/dist/payments/payment-client.d.ts.map +1 -1
- package/dist/payments/payment-client.js +172 -51
- package/dist/payments/payment-client.js.map +1 -1
- package/dist/teneo-sdk.d.ts +214 -40
- package/dist/teneo-sdk.d.ts.map +1 -1
- package/dist/teneo-sdk.js +360 -83
- package/dist/teneo-sdk.js.map +1 -1
- package/dist/types/config.d.ts +334 -25
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js +114 -22
- package/dist/types/config.js.map +1 -1
- package/dist/types/events.d.ts +60 -14
- package/dist/types/events.d.ts.map +1 -1
- package/dist/types/events.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +11 -4
- package/dist/types/index.js.map +1 -1
- package/dist/types/messages.d.ts +9801 -7222
- package/dist/types/messages.d.ts.map +1 -1
- package/dist/types/messages.js +180 -40
- package/dist/types/messages.js.map +1 -1
- package/dist/utils/pricing-resolver.d.ts +1 -1
- package/dist/utils/pricing-resolver.d.ts.map +1 -1
- package/dist/utils/pricing-resolver.js +9 -1
- package/dist/utils/pricing-resolver.js.map +1 -1
- package/examples/agent-room-management-example.ts +5 -5
- package/examples/basic-usage.ts +26 -6
- package/examples/claude-agent-x-follower/index.ts +1 -1
- package/examples/minimal-chat.ts +4 -3
- package/examples/n8n-teneo/index.ts +2 -2
- package/examples/nestjs-dashboard/README.md +1 -1
- package/examples/nestjs-dashboard/src/teneo/agents.controller.ts +3 -3
- package/examples/nestjs-dashboard/src/teneo/rooms.controller.ts +5 -5
- package/examples/nestjs-dashboard/src/teneo/teneo.service.ts +8 -8
- package/examples/openai-teneo/index.ts +1 -1
- package/examples/payment-flow.ts +143 -0
- package/examples/production-dashboard/README.md +6 -8
- package/examples/production-dashboard/server.ts +22 -10
- package/examples/room-management-example.ts +2 -2
- package/examples/usage/01-connect.ts +0 -3
- package/examples/usage/02-list-agents.ts +0 -2
- package/examples/usage/03-pick-agent.ts +3 -4
- package/examples/usage/04-find-by-capability.ts +10 -12
- package/examples/usage/05-webhook-example.ts +2 -4
- package/examples/usage/06-simple-api-server.ts +13 -9
- package/examples/usage/07-event-listener.ts +1 -13
- package/examples/usage/README.md +33 -7
- package/examples/webhook-integration.ts +9 -9
- package/examples/x-influencer-battle-server.ts +1 -1
- package/package.json +1 -1
- package/scripts/diagnose-connection.ts +86 -0
- package/scripts/investigate-payload.ts +163 -0
- package/scripts/list-agents.ts +58 -0
- package/scripts/live-multi-network-test.ts +230 -0
- package/src/constants.ts +5 -3
- package/src/core/websocket-client.ts +10 -9
- package/src/handlers/message-handlers/agent-details-response-handler.ts +2 -2
- package/src/handlers/message-handlers/agent-error-handler.ts +47 -0
- package/src/handlers/message-handlers/agent-status-update-handler.ts +2 -7
- package/src/handlers/message-handlers/all-agents-response-handler.ts +2 -2
- package/src/handlers/message-handlers/auth-message-handler.ts +7 -1
- package/src/handlers/message-handlers/auth-success-handler.ts +7 -1
- package/src/handlers/message-handlers/base-handler.ts +24 -4
- package/src/handlers/message-handlers/index.ts +24 -0
- package/src/handlers/message-handlers/list-available-agents-handler.ts +24 -11
- package/src/handlers/message-handlers/list-room-agents-handler.ts +2 -6
- package/src/handlers/message-handlers/list-rooms-response-handler.ts +2 -5
- package/src/handlers/message-handlers/ping-pong-handler.ts +29 -4
- package/src/handlers/message-handlers/rate-limit-notification-handler.ts +3 -2
- package/src/handlers/message-handlers/success-handler.ts +26 -0
- package/src/handlers/message-handlers/task-confirmed-handler.ts +49 -0
- package/src/handlers/message-handlers/trigger-wallet-tx-handler.ts +62 -0
- package/src/handlers/message-handlers/user-authenticated-handler.ts +2 -2
- package/src/handlers/message-handlers/user-count-handler.ts +2 -2
- package/src/index.ts +12 -4
- package/src/managers/admin-manager.ts +5 -2
- package/src/managers/agent-room-manager.ts +155 -26
- package/src/managers/index.ts +6 -1
- package/src/managers/message-router.ts +122 -27
- package/src/managers/room-manager.ts +39 -11
- package/src/payments/index.ts +20 -5
- package/src/payments/networks.ts +208 -0
- package/src/payments/payment-client.ts +211 -56
- package/src/teneo-sdk.ts +401 -70
- package/src/types/config.test.ts +24 -4
- package/src/types/config.ts +123 -25
- package/src/types/events.ts +36 -2
- package/src/types/index.ts +16 -3
- package/src/types/messages.ts +221 -57
- package/src/utils/pricing-resolver.ts +10 -2
- package/tests/direct-agent-test.ts +1 -1
- package/tests/integration/real-server.test.ts +1 -1
- package/tests/integration/websocket.test.ts +3 -3
- package/tests/multi-network-payment.test.ts +309 -0
- package/tests/multi-network.test.ts +296 -0
- package/tests/payment-flow-test.ts +6 -4
- package/tests/unit/handlers/agent-error-handler.test.ts +388 -0
- package/tests/unit/handlers/agent-room-operation-response-handler.test.ts +9 -6
- package/tests/unit/handlers/agent-status-update-handler.test.ts +11 -16
- package/tests/unit/handlers/list-available-agents-handler.test.ts +11 -14
- package/tests/unit/handlers/list-room-agents-handler.test.ts +11 -15
- package/tests/unit/handlers/room-operation-response-handler.test.ts +9 -6
- package/tests/unit/handlers/trigger-wallet-tx-handler.test.ts +431 -0
- package/tests/unit/managers/admin-manager.test.ts +183 -0
- package/tests/unit/managers/agent-room-manager.test.ts +189 -33
- package/tests/unit/sdk-new-methods.test.ts +221 -0
package/src/types/config.test.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, it, expect, vi } from "vitest";
|
|
2
2
|
import {
|
|
3
3
|
SDKConfigSchema,
|
|
4
|
+
PartialSDKConfigSchema,
|
|
4
5
|
SDKConfigBuilder,
|
|
5
6
|
validateConfig,
|
|
6
7
|
DEFAULT_CONFIG,
|
|
@@ -31,7 +32,7 @@ describe("SDK Configuration", () => {
|
|
|
31
32
|
messageTimeout: 15000,
|
|
32
33
|
maxMessageSize: 2 * 1024 * 1024,
|
|
33
34
|
logLevel: "debug" as LogLevel,
|
|
34
|
-
|
|
35
|
+
autoJoinPublicRooms: ["room1", "room2"],
|
|
35
36
|
responseFormat: "humanized" as const,
|
|
36
37
|
includeMetadata: true,
|
|
37
38
|
webhookRetries: 5,
|
|
@@ -168,7 +169,7 @@ describe("SDK Configuration", () => {
|
|
|
168
169
|
})
|
|
169
170
|
.withReconnection(true, 3000, 15)
|
|
170
171
|
.withLogging("debug")
|
|
171
|
-
.
|
|
172
|
+
.withAutoJoinPublicRooms(["room1", "room2"])
|
|
172
173
|
.withResponseFormat("humanized", true)
|
|
173
174
|
.withCache(true, 300000, 100)
|
|
174
175
|
.build();
|
|
@@ -183,7 +184,7 @@ describe("SDK Configuration", () => {
|
|
|
183
184
|
expect(config.reconnectDelay).toBe(3000);
|
|
184
185
|
expect(config.maxReconnectAttempts).toBe(15);
|
|
185
186
|
expect(config.logLevel).toBe("debug");
|
|
186
|
-
expect(config.
|
|
187
|
+
expect(config.autoJoinPublicRooms).toEqual(["room1", "room2"]);
|
|
187
188
|
expect(config.responseFormat).toBe("humanized");
|
|
188
189
|
expect(config.includeMetadata).toBe(true);
|
|
189
190
|
expect(config.enableCache).toBe(true);
|
|
@@ -208,6 +209,25 @@ describe("SDK Configuration", () => {
|
|
|
208
209
|
}).not.toThrow(); // Private key is not actually required if wsUrl is set in default
|
|
209
210
|
});
|
|
210
211
|
|
|
212
|
+
it("should handle backward compatibility for autoJoinRooms -> autoJoinPublicRooms", () => {
|
|
213
|
+
// Test that autoJoinRooms is mapped to autoJoinPublicRooms
|
|
214
|
+
const config = PartialSDKConfigSchema.parse({
|
|
215
|
+
wsUrl: "wss://example.com/ws",
|
|
216
|
+
autoJoinRooms: ["old-room-1", "old-room-2"]
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
expect(config.autoJoinPublicRooms).toEqual(["old-room-1", "old-room-2"]);
|
|
220
|
+
|
|
221
|
+
// Test that new property takes precedence
|
|
222
|
+
const config2 = PartialSDKConfigSchema.parse({
|
|
223
|
+
wsUrl: "wss://example.com/ws",
|
|
224
|
+
autoJoinRooms: ["old-room"],
|
|
225
|
+
autoJoinPublicRooms: ["new-room"]
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
expect(config2.autoJoinPublicRooms).toEqual(["new-room"]);
|
|
229
|
+
});
|
|
230
|
+
|
|
211
231
|
it("should merge with default config", () => {
|
|
212
232
|
const config = new SDKConfigBuilder()
|
|
213
233
|
.withWebSocketUrl("wss://example.com/ws")
|
|
@@ -309,7 +329,7 @@ describe("SDK Configuration", () => {
|
|
|
309
329
|
expect(DEFAULT_CONFIG.maxReconnectAttempts).toBe(10);
|
|
310
330
|
expect(DEFAULT_CONFIG.connectionTimeout).toBe(30000);
|
|
311
331
|
expect(DEFAULT_CONFIG.messageTimeout).toBe(30000);
|
|
312
|
-
expect(DEFAULT_CONFIG.maxMessageSize).toBe(
|
|
332
|
+
expect(DEFAULT_CONFIG.maxMessageSize).toBe(10 * 1024 * 1024);
|
|
313
333
|
expect(DEFAULT_CONFIG.logLevel).toBe("info");
|
|
314
334
|
expect(DEFAULT_CONFIG.responseFormat).toBe("humanized");
|
|
315
335
|
expect(DEFAULT_CONFIG.includeMetadata).toBe(false);
|
package/src/types/config.ts
CHANGED
|
@@ -32,13 +32,31 @@ export const ResponseFormatSchema = z.enum(["raw", "humanized", "both"]);
|
|
|
32
32
|
|
|
33
33
|
// Webhook event type schema
|
|
34
34
|
export const WebhookEventTypeSchema = z.enum([
|
|
35
|
+
// Core events
|
|
35
36
|
"message",
|
|
36
37
|
"task",
|
|
37
38
|
"task_response",
|
|
38
39
|
"agent_selected",
|
|
39
40
|
"error",
|
|
40
41
|
"connection_state",
|
|
41
|
-
"auth_state"
|
|
42
|
+
"auth_state",
|
|
43
|
+
|
|
44
|
+
// Error events
|
|
45
|
+
"agent_error",
|
|
46
|
+
"room_operation_error",
|
|
47
|
+
"agent_room_operation_error",
|
|
48
|
+
|
|
49
|
+
// Payment flow events
|
|
50
|
+
"task_quote",
|
|
51
|
+
"task_confirmed",
|
|
52
|
+
"wallet_tx_requested",
|
|
53
|
+
|
|
54
|
+
// State change events
|
|
55
|
+
"room_subscribed",
|
|
56
|
+
"room_unsubscribed",
|
|
57
|
+
"room_deleted",
|
|
58
|
+
"room_operation",
|
|
59
|
+
"agent_room_operation"
|
|
42
60
|
]);
|
|
43
61
|
|
|
44
62
|
// Custom Zod schema for SecurePrivateKey or string
|
|
@@ -55,8 +73,8 @@ const PrivateKeySchema = z.union([
|
|
|
55
73
|
)
|
|
56
74
|
]);
|
|
57
75
|
|
|
58
|
-
// SDK Configuration schema
|
|
59
|
-
|
|
76
|
+
// SDK Configuration base schema (without transform)
|
|
77
|
+
const SDKConfigBaseSchema = z.object({
|
|
60
78
|
// WebSocket configuration
|
|
61
79
|
wsUrl: z
|
|
62
80
|
.string()
|
|
@@ -74,6 +92,8 @@ export const SDKConfigSchema = z.object({
|
|
|
74
92
|
clientName: z.string().optional(),
|
|
75
93
|
|
|
76
94
|
// Room configuration
|
|
95
|
+
autoJoinPublicRooms: z.array(z.string()).optional(),
|
|
96
|
+
/** @deprecated Use autoJoinPublicRooms instead */
|
|
77
97
|
autoJoinRooms: z.array(z.string()).optional(),
|
|
78
98
|
|
|
79
99
|
// Webhook configuration
|
|
@@ -92,7 +112,7 @@ export const SDKConfigSchema = z.object({
|
|
|
92
112
|
|
|
93
113
|
// Message settings
|
|
94
114
|
messageTimeout: z.number().min(1000).max(300000).optional(),
|
|
95
|
-
maxMessageSize: z.number().min(1024).max(
|
|
115
|
+
maxMessageSize: z.number().min(1024).max(10 * 1024 * 1024).optional(), // 1KB to 10MB
|
|
96
116
|
maxMessagesPerSecond: z.number().min(1).max(1000).optional(), // Rate limiting
|
|
97
117
|
|
|
98
118
|
// Response formatting
|
|
@@ -128,14 +148,32 @@ export const SDKConfigSchema = z.object({
|
|
|
128
148
|
.string()
|
|
129
149
|
.regex(/^[a-z0-9-]+:\d+$/, "Must be valid CAIP-2 format")
|
|
130
150
|
.optional(),
|
|
131
|
-
paymentAsset: z.string().optional()
|
|
151
|
+
paymentAsset: z.string().optional(),
|
|
152
|
+
|
|
153
|
+
// Multi-network support (v2.3.0)
|
|
154
|
+
network: z.string().optional(), // Network name (peaq, base, avalanche)
|
|
155
|
+
networkChainId: z.number().optional() // Or chain ID directly
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// SDK Configuration schema with transform for backward compatibility
|
|
159
|
+
export const SDKConfigSchema = SDKConfigBaseSchema.transform((config) => {
|
|
160
|
+
// Handle backward compatibility: map autoJoinRooms to autoJoinPublicRooms
|
|
161
|
+
if (config.autoJoinRooms && !config.autoJoinPublicRooms) {
|
|
162
|
+
config.autoJoinPublicRooms = config.autoJoinRooms;
|
|
163
|
+
}
|
|
164
|
+
return config;
|
|
132
165
|
});
|
|
133
166
|
|
|
134
167
|
// Partial config for constructor
|
|
135
|
-
export const PartialSDKConfigSchema =
|
|
136
|
-
(config) => config.wsUrl !== undefined,
|
|
137
|
-
|
|
138
|
-
|
|
168
|
+
export const PartialSDKConfigSchema = SDKConfigBaseSchema.partial()
|
|
169
|
+
.refine((config) => config.wsUrl !== undefined, { message: "WebSocket URL is required" })
|
|
170
|
+
.transform((config) => {
|
|
171
|
+
// Handle backward compatibility: map autoJoinRooms to autoJoinPublicRooms
|
|
172
|
+
if (config.autoJoinRooms && !config.autoJoinPublicRooms) {
|
|
173
|
+
config.autoJoinPublicRooms = config.autoJoinRooms;
|
|
174
|
+
}
|
|
175
|
+
return config;
|
|
176
|
+
});
|
|
139
177
|
|
|
140
178
|
// Connection state schema
|
|
141
179
|
export const ConnectionStateSchema = z.object({
|
|
@@ -165,7 +203,13 @@ export const AuthenticationStateSchema = z.object({
|
|
|
165
203
|
// NEW in v2.0.0: Room categorization
|
|
166
204
|
privateRoomIds: z.array(z.string()).optional(), // IDs of rooms user owns
|
|
167
205
|
sharedRoomIds: z.array(z.string()).optional(), // IDs of rooms user is member of
|
|
168
|
-
maxPrivateRooms: z.number().optional() // Max rooms user can create
|
|
206
|
+
maxPrivateRooms: z.number().optional(), // Max rooms user can create
|
|
207
|
+
|
|
208
|
+
// Auth enhancement fields (audit #6, #7, #9)
|
|
209
|
+
jwtToken: z.string().optional(), // JWT token for KeyVault API authentication
|
|
210
|
+
sessionToken: z.string().optional(), // 64-char hex token for fast re-auth (24h validity)
|
|
211
|
+
whitelistVerified: z.union([z.boolean(), z.string()]).optional(), // Whitelist verification status
|
|
212
|
+
userCount: z.number().optional() // Total user count (admin only)
|
|
169
213
|
});
|
|
170
214
|
|
|
171
215
|
// Webhook config schema
|
|
@@ -207,7 +251,7 @@ export type WebhookPayload = z.infer<typeof WebhookPayloadSchema>;
|
|
|
207
251
|
export type { RetryStrategy };
|
|
208
252
|
|
|
209
253
|
// Default configuration with validation
|
|
210
|
-
export const DEFAULT_CONFIG: PartialSDKConfig =
|
|
254
|
+
export const DEFAULT_CONFIG: PartialSDKConfig = SDKConfigBaseSchema.partial().parse({
|
|
211
255
|
wsUrl: "ws://localhost:8080/ws",
|
|
212
256
|
clientType: "user",
|
|
213
257
|
reconnect: true,
|
|
@@ -215,7 +259,7 @@ export const DEFAULT_CONFIG: PartialSDKConfig = SDKConfigSchema.partial().parse(
|
|
|
215
259
|
maxReconnectAttempts: 10,
|
|
216
260
|
connectionTimeout: 30000,
|
|
217
261
|
messageTimeout: 30000,
|
|
218
|
-
maxMessageSize:
|
|
262
|
+
maxMessageSize: 10 * 1024 * 1024, // 10MB - sufficient for room history
|
|
219
263
|
maxMessagesPerSecond: 10, // Rate limit: 10 messages per second
|
|
220
264
|
responseFormat: "humanized",
|
|
221
265
|
includeMetadata: false,
|
|
@@ -236,9 +280,8 @@ export const DEFAULT_CONFIG: PartialSDKConfig = SDKConfigSchema.partial().parse(
|
|
|
236
280
|
|
|
237
281
|
// Quote-Approve Payment Flow (v2.2.0)
|
|
238
282
|
autoApproveQuotes: true, // Auto-approve quotes by default
|
|
239
|
-
quoteTimeout: 30000
|
|
240
|
-
paymentNetwork
|
|
241
|
-
paymentAsset: "0xbbA60da06c2c5424f03f7434542280FCAd453d10" // USDC on PEAQ
|
|
283
|
+
quoteTimeout: 30000 // 30 seconds for quote responses
|
|
284
|
+
// paymentNetwork and paymentAsset are dynamically loaded from backend via initializeNetworks()
|
|
242
285
|
});
|
|
243
286
|
|
|
244
287
|
// Configuration validation with custom refinements
|
|
@@ -297,7 +340,7 @@ export function safeParseConfig(config: unknown): {
|
|
|
297
340
|
* const config = new SDKConfigBuilder()
|
|
298
341
|
* .withWebSocketUrl('wss://teneo.example.com')
|
|
299
342
|
* .withAuthentication('0x...', '0xYourWalletAddress')
|
|
300
|
-
* .
|
|
343
|
+
* .withAutoJoinPublicRooms(['room-id-1', 'room-id-2'])
|
|
301
344
|
* .withWebhook('https://api.example.com/webhooks', {
|
|
302
345
|
* 'Authorization': 'Bearer token'
|
|
303
346
|
* })
|
|
@@ -310,11 +353,12 @@ export function safeParseConfig(config: unknown): {
|
|
|
310
353
|
* const sdk = new TeneoSDK(config);
|
|
311
354
|
*
|
|
312
355
|
* // Using via TeneoSDK.builder() (recommended)
|
|
313
|
-
* const
|
|
356
|
+
* const config = TeneoSDK.builder()
|
|
314
357
|
* .withWebSocketUrl('wss://teneo.example.com')
|
|
315
358
|
* .withAuthentication('0x...')
|
|
316
|
-
* .
|
|
359
|
+
* .withAutoJoinPublicRooms(['room-id-1'])
|
|
317
360
|
* .build();
|
|
361
|
+
* const sdk = new TeneoSDK(config);
|
|
318
362
|
* ```
|
|
319
363
|
*
|
|
320
364
|
* @see {@link TeneoSDK} for the main SDK class
|
|
@@ -416,23 +460,37 @@ export class SDKConfigBuilder {
|
|
|
416
460
|
}
|
|
417
461
|
|
|
418
462
|
/**
|
|
419
|
-
* Configures rooms to automatically subscribe to after authentication.
|
|
420
|
-
* These rooms will be subscribed to automatically when connection is established.
|
|
463
|
+
* Configures public rooms to automatically subscribe to after authentication.
|
|
464
|
+
* These PUBLIC rooms will be subscribed to automatically when connection is established.
|
|
465
|
+
* Note: Private rooms are automatically available after auth without needing subscription.
|
|
421
466
|
*
|
|
422
|
-
* @param rooms - Array of room IDs to auto-subscribe to on connection
|
|
467
|
+
* @param rooms - Array of public room IDs to auto-subscribe to on connection
|
|
423
468
|
* @returns this builder for method chaining
|
|
424
469
|
* @throws {z.ZodError} If room IDs are invalid
|
|
425
470
|
*
|
|
426
471
|
* @example
|
|
427
472
|
* ```typescript
|
|
428
|
-
* builder.
|
|
473
|
+
* builder.withAutoJoinPublicRooms(['public-room-1', 'public-room-2'])
|
|
429
474
|
* ```
|
|
430
475
|
*/
|
|
431
|
-
|
|
432
|
-
this.config.
|
|
476
|
+
withAutoJoinPublicRooms(rooms: string[]): this {
|
|
477
|
+
this.config.autoJoinPublicRooms = z.array(z.string()).parse(rooms);
|
|
433
478
|
return this;
|
|
434
479
|
}
|
|
435
480
|
|
|
481
|
+
/**
|
|
482
|
+
* @deprecated Use withAutoJoinPublicRooms() instead. This method only affects public rooms.
|
|
483
|
+
* Private rooms are automatically available after authentication without subscription.
|
|
484
|
+
*
|
|
485
|
+
* Configures public rooms to automatically subscribe to after authentication.
|
|
486
|
+
*
|
|
487
|
+
* @param rooms - Array of public room IDs to auto-subscribe to on connection
|
|
488
|
+
* @returns this builder for method chaining
|
|
489
|
+
*/
|
|
490
|
+
withAutoJoinRooms(rooms: string[]): this {
|
|
491
|
+
return this.withAutoJoinPublicRooms(rooms);
|
|
492
|
+
}
|
|
493
|
+
|
|
436
494
|
/**
|
|
437
495
|
* Configures automatic reconnection behavior for WebSocket connections.
|
|
438
496
|
* When enabled, SDK will automatically attempt to reconnect on disconnection.
|
|
@@ -850,6 +908,46 @@ export class SDKConfigBuilder {
|
|
|
850
908
|
return this;
|
|
851
909
|
}
|
|
852
910
|
|
|
911
|
+
/**
|
|
912
|
+
* Sets the default network by name for payment operations (v2.3.0).
|
|
913
|
+
*
|
|
914
|
+
* Priority order for network selection:
|
|
915
|
+
* 1. Per-request network override in sendMessage options
|
|
916
|
+
* 2. This builder setting
|
|
917
|
+
* 3. TENEO_NETWORK environment variable
|
|
918
|
+
* 4. Default: PEAQ (eip155:3338)
|
|
919
|
+
*
|
|
920
|
+
* @param network - Network name (peaq, base, avalanche)
|
|
921
|
+
* @returns this builder for method chaining
|
|
922
|
+
*
|
|
923
|
+
* @example
|
|
924
|
+
* ```typescript
|
|
925
|
+
* builder.withNetwork("base") // Use Base Mainnet for payments
|
|
926
|
+
* builder.withNetwork("avalanche") // Use Avalanche Mainnet
|
|
927
|
+
* ```
|
|
928
|
+
*/
|
|
929
|
+
withNetwork(network: string): this {
|
|
930
|
+
this.config.network = z.string().parse(network);
|
|
931
|
+
return this;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* Sets the default network by chain ID for payment operations (v2.3.0).
|
|
936
|
+
*
|
|
937
|
+
* @param chainId - Chain ID (3338 for PEAQ, 8453 for Base, 43114 for Avalanche)
|
|
938
|
+
* @returns this builder for method chaining
|
|
939
|
+
*
|
|
940
|
+
* @example
|
|
941
|
+
* ```typescript
|
|
942
|
+
* builder.withNetworkChainId(8453) // Use Base Mainnet for payments
|
|
943
|
+
* builder.withNetworkChainId(43114) // Use Avalanche Mainnet
|
|
944
|
+
* ```
|
|
945
|
+
*/
|
|
946
|
+
withNetworkChainId(chainId: number): this {
|
|
947
|
+
this.config.networkChainId = z.number().parse(chainId);
|
|
948
|
+
return this;
|
|
949
|
+
}
|
|
950
|
+
|
|
853
951
|
/**
|
|
854
952
|
* Builds and validates the final SDK configuration.
|
|
855
953
|
* Performs comprehensive validation including custom refinements (e.g., webhook security).
|
|
@@ -864,7 +962,7 @@ export class SDKConfigBuilder {
|
|
|
864
962
|
* const config = new SDKConfigBuilder()
|
|
865
963
|
* .withWebSocketUrl('wss://teneo.example.com')
|
|
866
964
|
* .withAuthentication('0x...')
|
|
867
|
-
* .
|
|
965
|
+
* .withAutoJoinPublicRooms(['room-id-1'])
|
|
868
966
|
* .build(); // Validates and returns final config
|
|
869
967
|
*
|
|
870
968
|
* const sdk = new TeneoSDK(config);
|
package/src/types/events.ts
CHANGED
|
@@ -311,12 +311,21 @@ export interface SDKEvents {
|
|
|
311
311
|
"agent:response": (response: AgentResponse) => void;
|
|
312
312
|
"agent:list": (agents: z.infer<typeof AgentSchema>[]) => void;
|
|
313
313
|
"agent:status": (agentId: string, status: "online" | "offline") => void;
|
|
314
|
+
"agent:error": (data: {
|
|
315
|
+
agentName?: string;
|
|
316
|
+
content?: string;
|
|
317
|
+
taskId?: string;
|
|
318
|
+
clientRequestId?: string;
|
|
319
|
+
room?: string;
|
|
320
|
+
}) => void;
|
|
314
321
|
|
|
315
322
|
// Room events
|
|
316
323
|
"room:subscribed": (data: { roomId: string; subscriptions: string[] }) => void;
|
|
317
324
|
"room:unsubscribed": (data: { roomId: string; subscriptions: string[] }) => void;
|
|
318
325
|
"room:message": (roomId: string, message: z.infer<typeof BaseMessageSchema>) => void;
|
|
319
|
-
|
|
326
|
+
|
|
327
|
+
// Room Ping/Pong events
|
|
328
|
+
"room:pong": (data: { roomId: string; liveCount: number; timestamp: string }) => void;
|
|
320
329
|
|
|
321
330
|
// Room Management events (v2.0.0)
|
|
322
331
|
"room:created": (room: z.infer<typeof RoomInfoSchema>) => void;
|
|
@@ -330,7 +339,15 @@ export interface SDKEvents {
|
|
|
330
339
|
"agent_room:agent_added": (roomId: string, agentId: string) => void;
|
|
331
340
|
"agent_room:agent_removed": (roomId: string, agentId: string) => void;
|
|
332
341
|
"agent_room:agents_listed": (roomId: string, agents: any[]) => void;
|
|
333
|
-
"agent_room:available_agents_listed": (
|
|
342
|
+
"agent_room:available_agents_listed": (
|
|
343
|
+
agents: any[],
|
|
344
|
+
paginationMeta?: {
|
|
345
|
+
total?: number;
|
|
346
|
+
offset?: number;
|
|
347
|
+
limit?: number;
|
|
348
|
+
hasMore?: boolean;
|
|
349
|
+
}
|
|
350
|
+
) => void;
|
|
334
351
|
"agent_room:status_update": (data: {
|
|
335
352
|
roomId: string;
|
|
336
353
|
agentId: string;
|
|
@@ -350,6 +367,12 @@ export interface SDKEvents {
|
|
|
350
367
|
// Quote-Approve Payment events (v2.2.0)
|
|
351
368
|
"quote:received": (quote: any) => void;
|
|
352
369
|
"quote:expired": (taskId: string) => void;
|
|
370
|
+
"task:confirmed": (data: {
|
|
371
|
+
taskId: string;
|
|
372
|
+
agentId?: string;
|
|
373
|
+
agentName?: string;
|
|
374
|
+
clientRequestId?: string;
|
|
375
|
+
}) => void;
|
|
353
376
|
"payment:blocked": (data: { agentId: string; agentPrice: number; maxPrice: number }) => void;
|
|
354
377
|
"payment:attached": (data: { agentId: string; amount: number; command: string }) => void;
|
|
355
378
|
"payment:error": (error: Error, agentId?: string) => void;
|
|
@@ -375,6 +398,16 @@ export interface SDKEvents {
|
|
|
375
398
|
// User Preferences events
|
|
376
399
|
"preferences:updated": (data: { maxPricePerRequest?: number | null }) => void;
|
|
377
400
|
|
|
401
|
+
// Wallet Transaction events
|
|
402
|
+
"wallet:tx_requested": (data: {
|
|
403
|
+
taskId: string;
|
|
404
|
+
agentName?: string;
|
|
405
|
+
tx: { to: string; value: string; data?: string; chainId: number };
|
|
406
|
+
description?: string;
|
|
407
|
+
optional?: boolean;
|
|
408
|
+
room?: string;
|
|
409
|
+
}) => void;
|
|
410
|
+
|
|
378
411
|
// Webhook events
|
|
379
412
|
"webhook:sent": (payload: any, url: string) => void;
|
|
380
413
|
"webhook:success": (response: any, url: string) => void;
|
|
@@ -383,6 +416,7 @@ export interface SDKEvents {
|
|
|
383
416
|
|
|
384
417
|
// Error events
|
|
385
418
|
error: (error: SDKError) => void;
|
|
419
|
+
success: (message: string) => void;
|
|
386
420
|
warning: (warning: string) => void;
|
|
387
421
|
|
|
388
422
|
// Lifecycle events
|
package/src/types/index.ts
CHANGED
|
@@ -50,6 +50,7 @@ export {
|
|
|
50
50
|
// System message schemas
|
|
51
51
|
AgentsListMessageSchema,
|
|
52
52
|
ErrorMessageSchema,
|
|
53
|
+
SuccessMessageSchema,
|
|
53
54
|
PingMessageSchema,
|
|
54
55
|
PongMessageSchema,
|
|
55
56
|
|
|
@@ -87,7 +88,6 @@ export {
|
|
|
87
88
|
|
|
88
89
|
// Room Ping schemas (v2.0.0)
|
|
89
90
|
RoomPingMessageSchema,
|
|
90
|
-
RoomPongResponseSchema,
|
|
91
91
|
|
|
92
92
|
// Union schema
|
|
93
93
|
AnyMessageSchema,
|
|
@@ -125,6 +125,7 @@ export {
|
|
|
125
125
|
type ConfirmTaskMessage,
|
|
126
126
|
type AgentsListMessage,
|
|
127
127
|
type ErrorMessage,
|
|
128
|
+
type SuccessMessage,
|
|
128
129
|
type PingMessage,
|
|
129
130
|
type PongMessage,
|
|
130
131
|
type SubscribeMessage,
|
|
@@ -160,7 +161,6 @@ export {
|
|
|
160
161
|
|
|
161
162
|
// Room Ping types (v2.0.0)
|
|
162
163
|
type RoomPingMessage,
|
|
163
|
-
type RoomPongResponse,
|
|
164
164
|
|
|
165
165
|
// Admin types
|
|
166
166
|
AdminAgentInfoSchema,
|
|
@@ -191,9 +191,22 @@ export {
|
|
|
191
191
|
type SetUserPreferencesMessage,
|
|
192
192
|
type UserPreferencesUpdatedData,
|
|
193
193
|
type UserPreferencesUpdatedMessage,
|
|
194
|
-
|
|
195
194
|
type AnyMessage,
|
|
196
195
|
|
|
196
|
+
// Task Confirmed types
|
|
197
|
+
TaskConfirmedMessageSchema,
|
|
198
|
+
type TaskConfirmedMessage,
|
|
199
|
+
|
|
200
|
+
// Agent Error types
|
|
201
|
+
AgentErrorMessageSchema,
|
|
202
|
+
type AgentErrorMessage,
|
|
203
|
+
|
|
204
|
+
// Wallet Transaction types
|
|
205
|
+
TxResultStatusSchema,
|
|
206
|
+
TriggerWalletTxMessageSchema,
|
|
207
|
+
type TxResultStatus,
|
|
208
|
+
type TriggerWalletTxMessage,
|
|
209
|
+
|
|
197
210
|
// Type guards
|
|
198
211
|
isAuthSuccess,
|
|
199
212
|
isAuthError,
|