Skip to content

Commit 6d0ed85

Browse files
committed
remove zod schema for server message
1 parent 4a427a1 commit 6d0ed85

File tree

2 files changed

+36
-38
lines changed

2 files changed

+36
-38
lines changed

common/src/actions.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,9 @@ type ClientActionAny =
8888
| ClientActionToolCallResponse
8989
| ClientActionCancelUserInput
9090
| ClientActionMcpToolData
91-
export type ClientAction<
92-
T extends ClientActionAny['type'] = ClientActionAny['type'],
93-
> = {
94-
[K in T]: Extract<
91+
type ClientActionType = ClientActionAny['type']
92+
export type ClientAction<T extends ClientActionType = ClientActionType> = {
93+
[K in ClientActionType]: Extract<
9594
ClientActionAny,
9695
{
9796
type: K
Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import { z } from 'zod/v4'
2-
3-
import { SERVER_ACTION_SCHEMA } from '../actions'
4-
5-
import type { ClientAction } from '../actions'
1+
import type { ClientAction, ServerAction } from '../actions'
62

73
type ClientMessageIdentify = {
84
type: 'identify'
@@ -29,38 +25,41 @@ type ClientMessageAction = {
2925
data: ClientAction
3026
}
3127

32-
export type ClientMessageType =
33-
| 'identify'
34-
| 'subscribe'
35-
| 'unsubscribe'
36-
| 'ping'
37-
| 'action'
28+
type ClientMessageAny =
29+
| ClientMessageIdentify
30+
| ClientMessageSubscribe
31+
| ClientMessageUnsubscribe
32+
| ClientMessagePing
33+
| ClientMessageAction
34+
export type ClientMessageType = ClientMessageAny['type']
3835
export type ClientMessage<T extends ClientMessageType = ClientMessageType> = {
39-
identify: ClientMessageIdentify
40-
subscribe: ClientMessageSubscribe
41-
unsubscribe: ClientMessageUnsubscribe
42-
ping: ClientMessagePing
43-
action: ClientMessageAction
36+
[K in ClientMessageType]: Extract<
37+
ClientMessageAny,
38+
{
39+
type: K
40+
}
41+
>
4442
}[T]
4543

46-
export const SERVER_MESSAGE_SCHEMAS = {
47-
ack: z.object({
48-
type: z.literal('ack'),
49-
txid: z.number().optional(),
50-
success: z.boolean(),
51-
error: z.string().optional(),
52-
}),
53-
action: z.object({
54-
type: z.literal('action'),
55-
data: SERVER_ACTION_SCHEMA,
56-
}),
44+
type ServerMessageAck = {
45+
type: 'ack'
46+
txid?: number
47+
success: boolean
48+
error?: string
5749
}
5850

59-
export const SERVER_MESSAGE_SCHEMA = z.union([
60-
SERVER_MESSAGE_SCHEMAS.ack,
61-
SERVER_MESSAGE_SCHEMAS.action,
62-
])
51+
type ServerMessageAction = {
52+
type: 'action'
53+
data: ServerAction
54+
}
6355

64-
export type ServerMessageType = keyof typeof SERVER_MESSAGE_SCHEMAS
65-
export type ServerMessage<T extends ServerMessageType = ServerMessageType> =
66-
z.infer<(typeof SERVER_MESSAGE_SCHEMAS)[T]>
56+
type ServerMessageAny = ServerMessageAck | ServerMessageAction
57+
export type ServerMessageType = ServerMessageAny['type']
58+
export type ServerMessage<T extends ServerMessageType = ServerMessageType> = {
59+
[K in ServerMessageType]: Extract<
60+
ServerMessageAny,
61+
{
62+
type: K
63+
}
64+
>
65+
}[T]

0 commit comments

Comments
 (0)