server: add ws hello/welcome message schemas

This commit is contained in:
Mohamed Boudra
2026-02-21 11:48:18 +07:00
parent c123c98f5f
commit e906bffbb9
+40
View File
@@ -197,6 +197,19 @@ const ToolCallDetailPayloadSchema: z.ZodType<ToolCallDetail> = z.discriminatedUn
),
truncated: z.boolean().optional(),
}),
z.object({
type: z.literal('sub_agent'),
subAgentType: z.string().optional(),
description: z.string().optional(),
log: z.string(),
actions: z.array(
z.object({
index: z.number().int().positive(),
toolName: z.string(),
summary: z.string().optional(),
})
),
}),
z.object({
type: z.literal('unknown'),
input: UnknownValueSchema,
@@ -2201,6 +2214,29 @@ export const WSPongMessageSchema = z.object({
type: z.literal('pong'),
})
export const WSHelloMessageSchema = z.object({
type: z.literal('hello'),
clientId: z.string().min(1),
clientType: z.enum(['mobile', 'browser', 'cli', 'mcp']),
protocolVersion: z.number().int(),
capabilities: z
.object({
voice: z.boolean().optional(),
pushNotifications: z.boolean().optional(),
})
.passthrough()
.optional(),
})
export const WSWelcomeMessageSchema = z.object({
type: z.literal('welcome'),
serverId: z.string(),
hostname: z.string().nullable(),
version: z.string().nullable(),
resumed: z.boolean(),
capabilities: ServerCapabilitiesSchema.optional(),
})
export const WSRecordingStateMessageSchema = z.object({
type: z.literal('recording_state'),
isRecording: z.boolean(),
@@ -2220,17 +2256,21 @@ export const WSSessionOutboundSchema = z.object({
// Complete WebSocket message schemas
export const WSInboundMessageSchema = z.discriminatedUnion('type', [
WSPingMessageSchema,
WSHelloMessageSchema,
WSRecordingStateMessageSchema,
WSSessionInboundSchema,
])
export const WSOutboundMessageSchema = z.discriminatedUnion('type', [
WSPongMessageSchema,
WSWelcomeMessageSchema,
WSSessionOutboundSchema,
])
export type WSInboundMessage = z.infer<typeof WSInboundMessageSchema>
export type WSOutboundMessage = z.infer<typeof WSOutboundMessageSchema>
export type WSHelloMessage = z.infer<typeof WSHelloMessageSchema>
export type WSWelcomeMessage = z.infer<typeof WSWelcomeMessageSchema>
// ============================================================================
// Helper functions for message conversion