@teneo-protocol/sdk 1.0.1 → 2.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/workflows/publish-npm.yml +8 -6
- package/CHANGELOG.md +265 -0
- package/README.md +406 -53
- package/dist/core/websocket-client.d.ts +12 -0
- package/dist/core/websocket-client.d.ts.map +1 -1
- package/dist/core/websocket-client.js +22 -2
- package/dist/core/websocket-client.js.map +1 -1
- package/dist/handlers/message-handlers/agent-room-operation-response-handler.d.ts +76 -0
- package/dist/handlers/message-handlers/agent-room-operation-response-handler.d.ts.map +1 -0
- package/dist/handlers/message-handlers/agent-room-operation-response-handler.js +70 -0
- package/dist/handlers/message-handlers/agent-room-operation-response-handler.js.map +1 -0
- package/dist/handlers/message-handlers/agent-selected-handler.d.ts +92 -38
- package/dist/handlers/message-handlers/agent-selected-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/agent-status-update-handler.d.ts +904 -0
- package/dist/handlers/message-handlers/agent-status-update-handler.d.ts.map +1 -0
- package/dist/handlers/message-handlers/agent-status-update-handler.js +51 -0
- package/dist/handlers/message-handlers/agent-status-update-handler.js.map +1 -0
- package/dist/handlers/message-handlers/auth-error-handler.d.ts +45 -31
- package/dist/handlers/message-handlers/auth-error-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/auth-message-handler.d.ts +6 -0
- package/dist/handlers/message-handlers/auth-message-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/auth-message-handler.js +65 -5
- package/dist/handlers/message-handlers/auth-message-handler.js.map +1 -1
- package/dist/handlers/message-handlers/auth-required-handler.d.ts +49 -31
- package/dist/handlers/message-handlers/auth-required-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/auth-success-handler.d.ts +6 -0
- package/dist/handlers/message-handlers/auth-success-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/auth-success-handler.js +46 -4
- package/dist/handlers/message-handlers/auth-success-handler.js.map +1 -1
- package/dist/handlers/message-handlers/challenge-handler.d.ts +45 -31
- package/dist/handlers/message-handlers/challenge-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/error-message-handler.d.ts +49 -31
- package/dist/handlers/message-handlers/error-message-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/index.d.ts +5 -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 +877 -0
- package/dist/handlers/message-handlers/list-available-agents-handler.d.ts.map +1 -0
- package/dist/handlers/message-handlers/list-available-agents-handler.js +38 -0
- package/dist/handlers/message-handlers/list-available-agents-handler.js.map +1 -0
- package/dist/handlers/message-handlers/list-room-agents-handler.d.ts +886 -0
- package/dist/handlers/message-handlers/list-room-agents-handler.d.ts.map +1 -0
- package/dist/handlers/message-handlers/list-room-agents-handler.js +51 -0
- package/dist/handlers/message-handlers/list-room-agents-handler.js.map +1 -0
- package/dist/handlers/message-handlers/list-rooms-response-handler.d.ts +178 -89
- package/dist/handlers/message-handlers/list-rooms-response-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/ping-pong-handler.d.ts +62 -58
- package/dist/handlers/message-handlers/ping-pong-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/regular-message-handler.d.ts +31 -29
- package/dist/handlers/message-handlers/regular-message-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/room-operation-response-handler.d.ts +328 -0
- package/dist/handlers/message-handlers/room-operation-response-handler.d.ts.map +1 -0
- package/dist/handlers/message-handlers/room-operation-response-handler.js +92 -0
- package/dist/handlers/message-handlers/room-operation-response-handler.js.map +1 -0
- package/dist/handlers/message-handlers/subscribe-response-handler.d.ts +53 -31
- package/dist/handlers/message-handlers/subscribe-response-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/types.d.ts +2 -0
- package/dist/handlers/message-handlers/types.d.ts.map +1 -1
- package/dist/handlers/message-handlers/unsubscribe-response-handler.d.ts +53 -31
- package/dist/handlers/message-handlers/unsubscribe-response-handler.d.ts.map +1 -1
- package/dist/managers/agent-room-manager.d.ts +222 -0
- package/dist/managers/agent-room-manager.d.ts.map +1 -0
- package/dist/managers/agent-room-manager.js +508 -0
- package/dist/managers/agent-room-manager.js.map +1 -0
- package/dist/managers/index.d.ts +2 -0
- package/dist/managers/index.d.ts.map +1 -1
- package/dist/managers/index.js +5 -1
- package/dist/managers/index.js.map +1 -1
- package/dist/managers/room-management-manager.d.ts +213 -0
- package/dist/managers/room-management-manager.d.ts.map +1 -0
- package/dist/managers/room-management-manager.js +440 -0
- package/dist/managers/room-management-manager.js.map +1 -0
- package/dist/managers/room-manager.d.ts +4 -4
- package/dist/managers/room-manager.d.ts.map +1 -1
- package/dist/managers/room-manager.js.map +1 -1
- package/dist/teneo-sdk.d.ts +333 -13
- package/dist/teneo-sdk.d.ts.map +1 -1
- package/dist/teneo-sdk.js +468 -1
- package/dist/teneo-sdk.js.map +1 -1
- package/dist/types/config.d.ts +63 -54
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js +8 -4
- package/dist/types/config.js.map +1 -1
- package/dist/types/error-codes.d.ts +2 -0
- package/dist/types/error-codes.d.ts.map +1 -1
- package/dist/types/error-codes.js +3 -0
- package/dist/types/error-codes.js.map +1 -1
- package/dist/types/events.d.ts +132 -68
- 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 +27 -2
- package/dist/types/index.js.map +1 -1
- package/dist/types/messages.d.ts +11396 -2559
- package/dist/types/messages.d.ts.map +1 -1
- package/dist/types/messages.js +294 -27
- package/dist/types/messages.js.map +1 -1
- package/examples/.env.example +1 -1
- package/examples/agent-room-management-example.ts +334 -0
- package/examples/claude-agent-x-follower/.env.example +2 -2
- package/examples/claude-agent-x-follower/QUICKSTART.md +1 -1
- package/examples/claude-agent-x-follower/README.md +1 -1
- package/examples/n8n-teneo/.env.example +2 -2
- package/examples/n8n-teneo/README.md +1 -1
- package/examples/openai-teneo/.env.example +2 -2
- package/examples/openai-teneo/README.md +1 -1
- package/examples/production-dashboard/.env.example +2 -2
- package/examples/production-dashboard/README.md +89 -12
- package/examples/production-dashboard/public/dashboard.html +1173 -601
- package/examples/production-dashboard/server.ts +347 -5
- package/examples/room-management-example.ts +285 -0
- package/examples/usage/.env.example +1 -1
- package/examples/usage/01-connect.ts +1 -1
- package/examples/usage/02-list-agents.ts +1 -1
- package/examples/usage/03-pick-agent.ts +1 -1
- package/examples/usage/04-find-by-capability.ts +1 -1
- package/examples/usage/05-webhook-example.ts +1 -1
- package/examples/usage/06-simple-api-server.ts +1 -1
- package/examples/usage/07-event-listener.ts +1 -1
- package/examples/usage/README.md +1 -1
- package/package.json +9 -1
- package/src/core/websocket-client.ts +26 -2
- package/src/handlers/message-handlers/agent-room-operation-response-handler.ts +83 -0
- package/src/handlers/message-handlers/agent-status-update-handler.ts +58 -0
- package/src/handlers/message-handlers/auth-message-handler.ts +73 -5
- package/src/handlers/message-handlers/auth-success-handler.ts +58 -6
- package/src/handlers/message-handlers/index.ts +19 -0
- package/src/handlers/message-handlers/list-available-agents-handler.ts +41 -0
- package/src/handlers/message-handlers/list-room-agents-handler.ts +61 -0
- package/src/handlers/message-handlers/room-operation-response-handler.ts +105 -0
- package/src/handlers/message-handlers/types.ts +6 -0
- package/src/managers/agent-room-manager.ts +609 -0
- package/src/managers/index.ts +2 -0
- package/src/managers/room-management-manager.ts +523 -0
- package/src/managers/room-manager.ts +4 -5
- package/src/teneo-sdk.ts +505 -4
- package/src/types/config.ts +10 -5
- package/src/types/error-codes.ts +4 -0
- package/src/types/events.ts +24 -0
- package/src/types/index.ts +55 -0
- package/src/types/messages.ts +374 -41
- package/tests/integration/room-management.test.ts +514 -0
- package/tests/integration/websocket.test.ts +1 -1
- package/tests/unit/handlers/agent-room-operation-response-handler.test.ts +394 -0
- package/tests/unit/handlers/agent-status-update-handler.test.ts +407 -0
- package/tests/unit/handlers/auth-success-handler-rooms.test.ts +699 -0
- package/tests/unit/handlers/list-available-agents-handler.test.ts +256 -0
- package/tests/unit/handlers/list-room-agents-handler.test.ts +294 -0
- package/tests/unit/handlers/room-operation-response-handler.test.ts +527 -0
- package/tests/unit/managers/agent-room-manager.test.ts +534 -0
- package/tests/unit/managers/room-management-manager.test.ts +438 -0
package/src/types/index.ts
CHANGED
|
@@ -55,6 +55,33 @@ export {
|
|
|
55
55
|
RoomInfoSchema,
|
|
56
56
|
ListRoomsResponseSchema,
|
|
57
57
|
|
|
58
|
+
// Room Management schemas (v2.0.0)
|
|
59
|
+
CreateRoomMessageSchema,
|
|
60
|
+
UpdateRoomMessageSchema,
|
|
61
|
+
DeleteRoomMessageSchema,
|
|
62
|
+
RoomOperationResponseSchema,
|
|
63
|
+
RoomMemberInfoSchema,
|
|
64
|
+
AddRoomMemberMessageSchema,
|
|
65
|
+
RemoveRoomMemberMessageSchema,
|
|
66
|
+
ListRoomMembersMessageSchema,
|
|
67
|
+
RoomMembersResponseSchema,
|
|
68
|
+
RoomMemberOperationResponseSchema,
|
|
69
|
+
|
|
70
|
+
// Agent Room Management schemas (v2.0.0)
|
|
71
|
+
AgentRoomInfoSchema,
|
|
72
|
+
AddAgentToRoomMessageSchema,
|
|
73
|
+
RemoveAgentFromRoomMessageSchema,
|
|
74
|
+
ListRoomAgentsMessageSchema,
|
|
75
|
+
ListAvailableAgentsMessageSchema,
|
|
76
|
+
AgentStatusUpdateMessageSchema,
|
|
77
|
+
RoomAgentsResponseSchema,
|
|
78
|
+
AvailableAgentsResponseSchema,
|
|
79
|
+
AgentRoomOperationResponseSchema,
|
|
80
|
+
|
|
81
|
+
// Room Ping schemas (v2.0.0)
|
|
82
|
+
RoomPingMessageSchema,
|
|
83
|
+
RoomPongResponseSchema,
|
|
84
|
+
|
|
58
85
|
// Union schema
|
|
59
86
|
AnyMessageSchema,
|
|
60
87
|
|
|
@@ -93,6 +120,34 @@ export {
|
|
|
93
120
|
type UnsubscribeResponse,
|
|
94
121
|
type RoomInfo,
|
|
95
122
|
type ListRoomsResponse,
|
|
123
|
+
|
|
124
|
+
// Room Management types (v2.0.0)
|
|
125
|
+
type CreateRoomMessage,
|
|
126
|
+
type UpdateRoomMessage,
|
|
127
|
+
type DeleteRoomMessage,
|
|
128
|
+
type RoomOperationResponse,
|
|
129
|
+
type RoomMemberInfo,
|
|
130
|
+
type AddRoomMemberMessage,
|
|
131
|
+
type RemoveRoomMemberMessage,
|
|
132
|
+
type ListRoomMembersMessage,
|
|
133
|
+
type RoomMembersResponse,
|
|
134
|
+
type RoomMemberOperationResponse,
|
|
135
|
+
|
|
136
|
+
// Agent Room Management types (v2.0.0)
|
|
137
|
+
type AgentRoomInfo,
|
|
138
|
+
type AddAgentToRoomMessage,
|
|
139
|
+
type RemoveAgentFromRoomMessage,
|
|
140
|
+
type ListRoomAgentsMessage,
|
|
141
|
+
type ListAvailableAgentsMessage,
|
|
142
|
+
type AgentStatusUpdateMessage,
|
|
143
|
+
type RoomAgentsResponse,
|
|
144
|
+
type AvailableAgentsResponse,
|
|
145
|
+
type AgentRoomOperationResponse,
|
|
146
|
+
|
|
147
|
+
// Room Ping types (v2.0.0)
|
|
148
|
+
type RoomPingMessage,
|
|
149
|
+
type RoomPongResponse,
|
|
150
|
+
|
|
96
151
|
type AnyMessage,
|
|
97
152
|
|
|
98
153
|
// Type guards
|
package/src/types/messages.ts
CHANGED
|
@@ -46,6 +46,7 @@ const stringToBoolean = z
|
|
|
46
46
|
|
|
47
47
|
// Enum schemas
|
|
48
48
|
export const MessageTypeSchema = z.enum([
|
|
49
|
+
// Authentication
|
|
49
50
|
"request_challenge",
|
|
50
51
|
"challenge",
|
|
51
52
|
"check_cached_auth",
|
|
@@ -55,18 +56,55 @@ export const MessageTypeSchema = z.enum([
|
|
|
55
56
|
"auth_error",
|
|
56
57
|
"register",
|
|
57
58
|
"registration_success",
|
|
59
|
+
|
|
60
|
+
// Communication
|
|
58
61
|
"message",
|
|
59
62
|
"task",
|
|
60
63
|
"task_response",
|
|
61
64
|
"agent_selected",
|
|
65
|
+
|
|
66
|
+
// System
|
|
62
67
|
"agents",
|
|
63
68
|
"error",
|
|
64
69
|
"ping",
|
|
65
70
|
"pong",
|
|
66
71
|
"capabilities",
|
|
72
|
+
|
|
73
|
+
// Room Subscription (Basic)
|
|
67
74
|
"subscribe",
|
|
68
75
|
"unsubscribe",
|
|
69
|
-
"list_rooms"
|
|
76
|
+
"list_rooms",
|
|
77
|
+
|
|
78
|
+
// === NEW IN v2.0.0 ===
|
|
79
|
+
|
|
80
|
+
// Room Management (6 types)
|
|
81
|
+
"create_room",
|
|
82
|
+
"update_room",
|
|
83
|
+
"delete_room",
|
|
84
|
+
"add_room_member",
|
|
85
|
+
"remove_room_member",
|
|
86
|
+
"list_room_members",
|
|
87
|
+
|
|
88
|
+
// Room Management Responses (3 types)
|
|
89
|
+
"room_operation_response",
|
|
90
|
+
"room_member_operation_response",
|
|
91
|
+
"room_members_response",
|
|
92
|
+
|
|
93
|
+
// Agent Room Management (5 types)
|
|
94
|
+
"add_agent_to_room",
|
|
95
|
+
"remove_agent_from_room",
|
|
96
|
+
"list_room_agents",
|
|
97
|
+
"list_available_agents",
|
|
98
|
+
"agent_status_update",
|
|
99
|
+
|
|
100
|
+
// Agent Room Management Responses (3 types)
|
|
101
|
+
"agent_room_operation_response",
|
|
102
|
+
"room_agents_response",
|
|
103
|
+
"available_agents_response",
|
|
104
|
+
|
|
105
|
+
// Room Ping System (2 types)
|
|
106
|
+
"room_ping",
|
|
107
|
+
"room_pong"
|
|
70
108
|
]);
|
|
71
109
|
|
|
72
110
|
export const ContentTypeSchema = z.enum([
|
|
@@ -90,26 +128,41 @@ export const AgentStatusSchema = z.enum(["online", "offline"]);
|
|
|
90
128
|
// Supporting schemas
|
|
91
129
|
export const CapabilitySchema = z.object({
|
|
92
130
|
name: z.string(),
|
|
93
|
-
description: z.string()
|
|
131
|
+
description: z.string().optional()
|
|
94
132
|
});
|
|
95
133
|
|
|
96
134
|
export const CommandSchema = z.object({
|
|
97
135
|
trigger: z.string(),
|
|
98
136
|
argument: z.string().optional(),
|
|
99
|
-
description: z.string()
|
|
137
|
+
description: z.string().optional()
|
|
100
138
|
});
|
|
101
139
|
|
|
102
140
|
export const RoomSchema = z.object({
|
|
103
141
|
id: z.string(),
|
|
104
|
-
name: z.string(),
|
|
142
|
+
name: z.string().optional(),
|
|
105
143
|
description: z.string().optional(),
|
|
106
|
-
is_public: stringToBoolean,
|
|
107
|
-
is_active: stringToBoolean,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
144
|
+
is_public: stringToBoolean.optional(),
|
|
145
|
+
is_active: stringToBoolean.optional(),
|
|
146
|
+
is_owner: stringToBoolean.optional(),
|
|
147
|
+
created_by: z.string().optional(),
|
|
148
|
+
created_at: z.string().optional(),
|
|
149
|
+
updated_at: z.string().optional()
|
|
111
150
|
});
|
|
112
151
|
|
|
152
|
+
// RoomInfo schema for v2.0.0 - used in auth responses and room management
|
|
153
|
+
export const RoomInfoSchema = z
|
|
154
|
+
.object({
|
|
155
|
+
id: z.string(),
|
|
156
|
+
name: z.string().optional(), // Optional for permissive parsing
|
|
157
|
+
description: z.string().optional().nullable(),
|
|
158
|
+
is_public: z.boolean().optional(), // Optional - defaults to false on backend
|
|
159
|
+
created_by: z.string().optional(), // Optional in case backend doesn't send it yet
|
|
160
|
+
created_at: z.string().optional(),
|
|
161
|
+
updated_at: z.string().optional(),
|
|
162
|
+
is_owner: z.boolean().optional() // Client-side enrichment, may not always be present
|
|
163
|
+
})
|
|
164
|
+
.passthrough(); // Allow extra fields backend might add
|
|
165
|
+
|
|
113
166
|
export const AgentSchema = z.object({
|
|
114
167
|
id: z.string(),
|
|
115
168
|
name: z.string(),
|
|
@@ -125,21 +178,23 @@ export const AgentSchema = z.object({
|
|
|
125
178
|
});
|
|
126
179
|
|
|
127
180
|
// Base message schema
|
|
128
|
-
export const BaseMessageSchema = z
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
181
|
+
export const BaseMessageSchema = z
|
|
182
|
+
.object({
|
|
183
|
+
type: MessageTypeSchema,
|
|
184
|
+
content: z.any().optional(),
|
|
185
|
+
content_type: ContentTypeSchema.optional(),
|
|
186
|
+
from: z.string().optional(),
|
|
187
|
+
to: z.string().optional(),
|
|
188
|
+
room: z.string().optional(),
|
|
189
|
+
timestamp: z.string().optional(),
|
|
190
|
+
data: z.record(z.any()).optional(),
|
|
191
|
+
signature: z.string().optional(),
|
|
192
|
+
publicKey: z.string().optional(),
|
|
193
|
+
reasoning: z.string().optional(),
|
|
194
|
+
task_id: z.string().optional(),
|
|
195
|
+
id: z.string().optional() // Added for message tracking
|
|
196
|
+
})
|
|
197
|
+
.passthrough(); // Allow message-specific fields to pass through
|
|
143
198
|
|
|
144
199
|
// Authentication message schemas
|
|
145
200
|
export const RequestChallengeMessageSchema = BaseMessageSchema.extend({
|
|
@@ -193,8 +248,10 @@ export const AuthMessageSchema = BaseMessageSchema.extend({
|
|
|
193
248
|
is_whitelisted: stringToBoolean.optional(),
|
|
194
249
|
is_admin_whitelisted: stringToBoolean.optional(),
|
|
195
250
|
rooms: z.array(RoomSchema).optional(),
|
|
251
|
+
private_rooms: z.array(RoomSchema).optional(),
|
|
196
252
|
private_room_id: z.string().optional(),
|
|
197
|
-
cached_auth: stringToBoolean.optional()
|
|
253
|
+
cached_auth: stringToBoolean.optional(),
|
|
254
|
+
max_private_rooms: z.number().optional()
|
|
198
255
|
})
|
|
199
256
|
.optional()
|
|
200
257
|
});
|
|
@@ -208,9 +265,10 @@ export const AuthSuccessMessageSchema = BaseMessageSchema.extend({
|
|
|
208
265
|
nft_verified: stringToBoolean.optional(),
|
|
209
266
|
is_whitelisted: stringToBoolean.optional(),
|
|
210
267
|
is_admin_whitelisted: stringToBoolean.optional(),
|
|
211
|
-
rooms: z.array(
|
|
212
|
-
private_room_id: z.string().optional(),
|
|
213
|
-
cached_auth: stringToBoolean.optional()
|
|
268
|
+
rooms: z.array(RoomInfoSchema).optional().nullable(), // v2.0.0: Uses RoomInfo with is_owner field
|
|
269
|
+
private_room_id: z.string().optional(), // DEPRECATED: Use rooms array instead
|
|
270
|
+
cached_auth: stringToBoolean.optional(), // Admin field, optional
|
|
271
|
+
max_private_rooms: z.number().optional() // NEW in v2.0.0: Max rooms user can create
|
|
214
272
|
})
|
|
215
273
|
});
|
|
216
274
|
|
|
@@ -361,16 +419,6 @@ export const UnsubscribeResponseSchema = BaseMessageSchema.extend({
|
|
|
361
419
|
})
|
|
362
420
|
});
|
|
363
421
|
|
|
364
|
-
export const RoomInfoSchema = z.object({
|
|
365
|
-
id: z.string(),
|
|
366
|
-
name: z.string(),
|
|
367
|
-
description: z.string().optional().nullable(),
|
|
368
|
-
is_public: z.boolean(),
|
|
369
|
-
created_at: z.string(),
|
|
370
|
-
updated_at: z.string(),
|
|
371
|
-
is_owner: z.boolean()
|
|
372
|
-
});
|
|
373
|
-
|
|
374
422
|
export const ListRoomsResponseSchema = BaseMessageSchema.extend({
|
|
375
423
|
type: z.literal("list_rooms"),
|
|
376
424
|
data: z.object({
|
|
@@ -378,10 +426,240 @@ export const ListRoomsResponseSchema = BaseMessageSchema.extend({
|
|
|
378
426
|
})
|
|
379
427
|
});
|
|
380
428
|
|
|
429
|
+
// ============================================================================
|
|
430
|
+
// ROOM MANAGEMENT SCHEMAS (v2.0.0)
|
|
431
|
+
// Note: Permissive schemas to handle backend changes gracefully
|
|
432
|
+
// ============================================================================
|
|
433
|
+
|
|
434
|
+
// Room CRUD Operations
|
|
435
|
+
export const CreateRoomMessageSchema = z
|
|
436
|
+
.object({
|
|
437
|
+
type: z.literal("create_room"),
|
|
438
|
+
name: z.string(),
|
|
439
|
+
description: z.string().optional(),
|
|
440
|
+
is_public: z.boolean().optional()
|
|
441
|
+
})
|
|
442
|
+
.passthrough(); // Allow extra fields
|
|
443
|
+
|
|
444
|
+
export const UpdateRoomMessageSchema = z
|
|
445
|
+
.object({
|
|
446
|
+
type: z.literal("update_room"),
|
|
447
|
+
room_id: z.string(),
|
|
448
|
+
name: z.string().optional(),
|
|
449
|
+
description: z.string().optional()
|
|
450
|
+
})
|
|
451
|
+
.passthrough();
|
|
452
|
+
|
|
453
|
+
export const DeleteRoomMessageSchema = z
|
|
454
|
+
.object({
|
|
455
|
+
type: z.literal("delete_room"),
|
|
456
|
+
room_id: z.string()
|
|
457
|
+
})
|
|
458
|
+
.passthrough();
|
|
459
|
+
|
|
460
|
+
export const RoomOperationResponseSchema = z
|
|
461
|
+
.object({
|
|
462
|
+
type: z.literal("room_operation_response"),
|
|
463
|
+
data: z
|
|
464
|
+
.object({
|
|
465
|
+
success: z.boolean().optional(), // Optional - consuming code should handle missing as false
|
|
466
|
+
message: z.string().optional(),
|
|
467
|
+
room_id: z.string().optional(),
|
|
468
|
+
room: RoomInfoSchema.optional(),
|
|
469
|
+
max_rooms: z.number().optional(),
|
|
470
|
+
current_count: z.number().optional()
|
|
471
|
+
})
|
|
472
|
+
.passthrough() // Allow extra fields backend might add
|
|
473
|
+
})
|
|
474
|
+
.passthrough();
|
|
475
|
+
|
|
476
|
+
// Room Member Management
|
|
477
|
+
export const RoomMemberInfoSchema = z
|
|
478
|
+
.object({
|
|
479
|
+
user_id: z.string(),
|
|
480
|
+
added_by: z.string().optional(), // May not always be present
|
|
481
|
+
added_at: z.string().optional(),
|
|
482
|
+
role: z.string().optional()
|
|
483
|
+
})
|
|
484
|
+
.passthrough();
|
|
485
|
+
|
|
486
|
+
export const AddRoomMemberMessageSchema = z
|
|
487
|
+
.object({
|
|
488
|
+
type: z.literal("add_room_member"),
|
|
489
|
+
room_id: z.string(),
|
|
490
|
+
user_id: z.string()
|
|
491
|
+
})
|
|
492
|
+
.passthrough();
|
|
493
|
+
|
|
494
|
+
export const RemoveRoomMemberMessageSchema = z
|
|
495
|
+
.object({
|
|
496
|
+
type: z.literal("remove_room_member"),
|
|
497
|
+
room_id: z.string(),
|
|
498
|
+
user_id: z.string()
|
|
499
|
+
})
|
|
500
|
+
.passthrough();
|
|
501
|
+
|
|
502
|
+
export const ListRoomMembersMessageSchema = z
|
|
503
|
+
.object({
|
|
504
|
+
type: z.literal("list_room_members"),
|
|
505
|
+
room_id: z.string()
|
|
506
|
+
})
|
|
507
|
+
.passthrough();
|
|
508
|
+
|
|
509
|
+
export const RoomMembersResponseSchema = z
|
|
510
|
+
.object({
|
|
511
|
+
type: z.literal("room_members_response"),
|
|
512
|
+
data: z
|
|
513
|
+
.object({
|
|
514
|
+
room_id: z.string(),
|
|
515
|
+
members: z.array(RoomMemberInfoSchema).optional() // Optional - consuming code should handle missing as []
|
|
516
|
+
})
|
|
517
|
+
.passthrough()
|
|
518
|
+
})
|
|
519
|
+
.passthrough();
|
|
520
|
+
|
|
521
|
+
export const RoomMemberOperationResponseSchema = z
|
|
522
|
+
.object({
|
|
523
|
+
type: z.literal("room_member_operation_response"),
|
|
524
|
+
data: z
|
|
525
|
+
.object({
|
|
526
|
+
success: z.boolean().optional(),
|
|
527
|
+
message: z.string().optional(),
|
|
528
|
+
room_id: z.string().optional(),
|
|
529
|
+
user_id: z.string().optional(),
|
|
530
|
+
member_count: z.number().optional()
|
|
531
|
+
})
|
|
532
|
+
.passthrough()
|
|
533
|
+
})
|
|
534
|
+
.passthrough();
|
|
535
|
+
|
|
536
|
+
// ============================================================================
|
|
537
|
+
// AGENT ROOM MANAGEMENT SCHEMAS (v2.0.0)
|
|
538
|
+
// Note: Permissive schemas to handle backend changes gracefully
|
|
539
|
+
// ============================================================================
|
|
540
|
+
|
|
541
|
+
export const AgentRoomInfoSchema = z
|
|
542
|
+
.object({
|
|
543
|
+
agent_id: z.string(),
|
|
544
|
+
agent_name: z.string().optional(),
|
|
545
|
+
description: z.string().optional(),
|
|
546
|
+
capabilities: z.array(CapabilitySchema).optional(),
|
|
547
|
+
commands: z.array(CommandSchema).optional(),
|
|
548
|
+
image: z.string().optional(),
|
|
549
|
+
status: z.string().optional(),
|
|
550
|
+
added_by: z.string().optional(),
|
|
551
|
+
added_at: z.string().optional()
|
|
552
|
+
})
|
|
553
|
+
.passthrough();
|
|
554
|
+
|
|
555
|
+
export const AddAgentToRoomMessageSchema = z
|
|
556
|
+
.object({
|
|
557
|
+
type: z.literal("add_agent_to_room"),
|
|
558
|
+
room_id: z.string(),
|
|
559
|
+
agent_id: z.string()
|
|
560
|
+
})
|
|
561
|
+
.passthrough();
|
|
562
|
+
|
|
563
|
+
export const RemoveAgentFromRoomMessageSchema = z
|
|
564
|
+
.object({
|
|
565
|
+
type: z.literal("remove_agent_from_room"),
|
|
566
|
+
room_id: z.string(),
|
|
567
|
+
agent_id: z.string()
|
|
568
|
+
})
|
|
569
|
+
.passthrough();
|
|
570
|
+
|
|
571
|
+
export const ListRoomAgentsMessageSchema = z
|
|
572
|
+
.object({
|
|
573
|
+
type: z.literal("list_room_agents"),
|
|
574
|
+
room_id: z.string()
|
|
575
|
+
})
|
|
576
|
+
.passthrough();
|
|
577
|
+
|
|
578
|
+
export const ListAvailableAgentsMessageSchema = z
|
|
579
|
+
.object({
|
|
580
|
+
type: z.literal("list_available_agents"),
|
|
581
|
+
room_id: z.string()
|
|
582
|
+
})
|
|
583
|
+
.passthrough();
|
|
584
|
+
|
|
585
|
+
export const RoomAgentsResponseSchema = z
|
|
586
|
+
.object({
|
|
587
|
+
type: z.literal("room_agents_response"),
|
|
588
|
+
data: z
|
|
589
|
+
.object({
|
|
590
|
+
room_id: z.string(),
|
|
591
|
+
agents: z.array(AgentRoomInfoSchema).optional() // Optional - consuming code should handle missing as []
|
|
592
|
+
})
|
|
593
|
+
.passthrough()
|
|
594
|
+
})
|
|
595
|
+
.passthrough();
|
|
596
|
+
|
|
597
|
+
export const AvailableAgentsResponseSchema = z
|
|
598
|
+
.object({
|
|
599
|
+
type: z.literal("available_agents_response"),
|
|
600
|
+
data: z
|
|
601
|
+
.object({
|
|
602
|
+
agents: z.array(AgentRoomInfoSchema).optional()
|
|
603
|
+
})
|
|
604
|
+
.passthrough()
|
|
605
|
+
})
|
|
606
|
+
.passthrough();
|
|
607
|
+
|
|
608
|
+
export const AgentRoomOperationResponseSchema = z
|
|
609
|
+
.object({
|
|
610
|
+
type: z.literal("agent_room_operation_response"),
|
|
611
|
+
data: z
|
|
612
|
+
.object({
|
|
613
|
+
success: z.boolean().optional(),
|
|
614
|
+
message: z.string().optional(),
|
|
615
|
+
room_id: z.string().optional(),
|
|
616
|
+
agent_id: z.string().optional(),
|
|
617
|
+
agent_count: z.number().optional()
|
|
618
|
+
})
|
|
619
|
+
.passthrough()
|
|
620
|
+
})
|
|
621
|
+
.passthrough();
|
|
622
|
+
|
|
623
|
+
export const AgentStatusUpdateMessageSchema = z
|
|
624
|
+
.object({
|
|
625
|
+
type: z.literal("agent_status_update"),
|
|
626
|
+
data: z
|
|
627
|
+
.object({
|
|
628
|
+
room_id: z.string(),
|
|
629
|
+
agent_id: z.string(),
|
|
630
|
+
status: z.string(),
|
|
631
|
+
agent: AgentRoomInfoSchema.optional()
|
|
632
|
+
})
|
|
633
|
+
.passthrough()
|
|
634
|
+
})
|
|
635
|
+
.passthrough();
|
|
636
|
+
|
|
637
|
+
// Room Ping System
|
|
638
|
+
export const RoomPingMessageSchema = z
|
|
639
|
+
.object({
|
|
640
|
+
type: z.literal("room_ping"),
|
|
641
|
+
room_id: z.string()
|
|
642
|
+
})
|
|
643
|
+
.passthrough();
|
|
644
|
+
|
|
645
|
+
export const RoomPongResponseSchema = z
|
|
646
|
+
.object({
|
|
647
|
+
type: z.literal("room_pong"),
|
|
648
|
+
data: z
|
|
649
|
+
.object({
|
|
650
|
+
room_id: z.string(),
|
|
651
|
+
live_count: z.number().optional(), // Optional - consuming code should handle missing as 0
|
|
652
|
+
timestamp: z.string()
|
|
653
|
+
})
|
|
654
|
+
.passthrough()
|
|
655
|
+
})
|
|
656
|
+
.passthrough();
|
|
657
|
+
|
|
381
658
|
// Union of all INCOMING message schemas for validation
|
|
382
659
|
// Note: Outgoing message schemas (Subscribe, Unsubscribe, ListRooms) are excluded
|
|
383
660
|
// as they share the same type values with their response counterparts
|
|
384
661
|
export const AnyMessageSchema = z.discriminatedUnion("type", [
|
|
662
|
+
// Authentication & Registration
|
|
385
663
|
RequestChallengeMessageSchema,
|
|
386
664
|
ChallengeMessageSchema,
|
|
387
665
|
CheckCachedAuthMessageSchema,
|
|
@@ -391,18 +669,37 @@ export const AnyMessageSchema = z.discriminatedUnion("type", [
|
|
|
391
669
|
AuthErrorMessageSchema,
|
|
392
670
|
RegisterMessageSchema,
|
|
393
671
|
RegistrationSuccessMessageSchema,
|
|
672
|
+
|
|
673
|
+
// Communication
|
|
394
674
|
UserMessageSchema,
|
|
395
675
|
TaskMessageSchema,
|
|
396
676
|
TaskResponseMessageSchema,
|
|
397
677
|
AgentSelectedMessageSchema,
|
|
398
678
|
AgentsListMessageSchema,
|
|
679
|
+
|
|
680
|
+
// System
|
|
399
681
|
ErrorMessageSchema,
|
|
400
682
|
PingMessageSchema,
|
|
401
683
|
PongMessageSchema,
|
|
402
|
-
|
|
684
|
+
|
|
685
|
+
// Room Subscription (Basic)
|
|
403
686
|
SubscribeResponseSchema,
|
|
404
687
|
UnsubscribeResponseSchema,
|
|
405
|
-
ListRoomsResponseSchema
|
|
688
|
+
ListRoomsResponseSchema,
|
|
689
|
+
|
|
690
|
+
// Room Management Responses (v2.0.0)
|
|
691
|
+
RoomOperationResponseSchema,
|
|
692
|
+
RoomMemberOperationResponseSchema,
|
|
693
|
+
RoomMembersResponseSchema,
|
|
694
|
+
|
|
695
|
+
// Agent Room Management Responses (v2.0.0)
|
|
696
|
+
AgentRoomOperationResponseSchema,
|
|
697
|
+
RoomAgentsResponseSchema,
|
|
698
|
+
AvailableAgentsResponseSchema,
|
|
699
|
+
AgentStatusUpdateMessageSchema,
|
|
700
|
+
|
|
701
|
+
// Room Ping System (v2.0.0)
|
|
702
|
+
RoomPongResponseSchema
|
|
406
703
|
]);
|
|
407
704
|
|
|
408
705
|
// Type inference from schemas
|
|
@@ -443,6 +740,33 @@ export type UnsubscribeResponse = z.infer<typeof UnsubscribeResponseSchema>;
|
|
|
443
740
|
export type RoomInfo = z.infer<typeof RoomInfoSchema>;
|
|
444
741
|
export type ListRoomsResponse = z.infer<typeof ListRoomsResponseSchema>;
|
|
445
742
|
|
|
743
|
+
// Room Management Types (v2.0.0)
|
|
744
|
+
export type CreateRoomMessage = z.infer<typeof CreateRoomMessageSchema>;
|
|
745
|
+
export type UpdateRoomMessage = z.infer<typeof UpdateRoomMessageSchema>;
|
|
746
|
+
export type DeleteRoomMessage = z.infer<typeof DeleteRoomMessageSchema>;
|
|
747
|
+
export type RoomOperationResponse = z.infer<typeof RoomOperationResponseSchema>;
|
|
748
|
+
export type RoomMemberInfo = z.infer<typeof RoomMemberInfoSchema>;
|
|
749
|
+
export type AddRoomMemberMessage = z.infer<typeof AddRoomMemberMessageSchema>;
|
|
750
|
+
export type RemoveRoomMemberMessage = z.infer<typeof RemoveRoomMemberMessageSchema>;
|
|
751
|
+
export type ListRoomMembersMessage = z.infer<typeof ListRoomMembersMessageSchema>;
|
|
752
|
+
export type RoomMembersResponse = z.infer<typeof RoomMembersResponseSchema>;
|
|
753
|
+
export type RoomMemberOperationResponse = z.infer<typeof RoomMemberOperationResponseSchema>;
|
|
754
|
+
|
|
755
|
+
// Agent Room Management Types (v2.0.0)
|
|
756
|
+
export type AgentRoomInfo = z.infer<typeof AgentRoomInfoSchema>;
|
|
757
|
+
export type AddAgentToRoomMessage = z.infer<typeof AddAgentToRoomMessageSchema>;
|
|
758
|
+
export type RemoveAgentFromRoomMessage = z.infer<typeof RemoveAgentFromRoomMessageSchema>;
|
|
759
|
+
export type ListRoomAgentsMessage = z.infer<typeof ListRoomAgentsMessageSchema>;
|
|
760
|
+
export type ListAvailableAgentsMessage = z.infer<typeof ListAvailableAgentsMessageSchema>;
|
|
761
|
+
export type RoomAgentsResponse = z.infer<typeof RoomAgentsResponseSchema>;
|
|
762
|
+
export type AvailableAgentsResponse = z.infer<typeof AvailableAgentsResponseSchema>;
|
|
763
|
+
export type AgentRoomOperationResponse = z.infer<typeof AgentRoomOperationResponseSchema>;
|
|
764
|
+
export type AgentStatusUpdateMessage = z.infer<typeof AgentStatusUpdateMessageSchema>;
|
|
765
|
+
|
|
766
|
+
// Room Ping Types (v2.0.0)
|
|
767
|
+
export type RoomPingMessage = z.infer<typeof RoomPingMessageSchema>;
|
|
768
|
+
export type RoomPongResponse = z.infer<typeof RoomPongResponseSchema>;
|
|
769
|
+
|
|
446
770
|
export type AnyMessage = z.infer<typeof AnyMessageSchema>;
|
|
447
771
|
|
|
448
772
|
// Type guards using Zod parse
|
|
@@ -559,12 +883,21 @@ export function validateMessage(message: unknown): AnyMessage {
|
|
|
559
883
|
// Safe parse helper
|
|
560
884
|
export function safeParseMessage(message: unknown): {
|
|
561
885
|
success: boolean;
|
|
562
|
-
data?: AnyMessage;
|
|
886
|
+
data?: AnyMessage | BaseMessage;
|
|
563
887
|
error?: z.ZodError;
|
|
564
888
|
} {
|
|
889
|
+
// Try specific message schemas first
|
|
565
890
|
const result = AnyMessageSchema.safeParse(message);
|
|
566
891
|
if (result.success) {
|
|
567
892
|
return { success: true, data: result.data };
|
|
568
893
|
}
|
|
894
|
+
|
|
895
|
+
// Fall back to basic BaseMessage schema for unknown message types
|
|
896
|
+
// This allows the SDK to be more resilient to backend changes
|
|
897
|
+
const fallbackResult = BaseMessageSchema.safeParse(message);
|
|
898
|
+
if (fallbackResult.success) {
|
|
899
|
+
return { success: true, data: fallbackResult.data as BaseMessage };
|
|
900
|
+
}
|
|
901
|
+
|
|
569
902
|
return { success: false, error: result.error };
|
|
570
903
|
}
|