Skip to content

Commit 2ddb3c7

Browse files
Describing the control packet structures
1 parent aa28779 commit 2ddb3c7

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/replit_river/v2/schema.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from typing import Any, Literal, NotRequired, TypeAlias, TypedDict
2+
3+
from replit_river.rpc import ExpectedSessionState
4+
5+
6+
class ControlClose(TypedDict):
7+
type: Literal["CLOSE"]
8+
9+
10+
class ControlAck(TypedDict):
11+
type: Literal["ACK"]
12+
13+
14+
class ControlHandshakeRequest(TypedDict):
15+
type: Literal["HANDSHAKE_REQ"]
16+
protocolVersion: Literal["v2.0"]
17+
sessionId: str
18+
expectedSessionState: ExpectedSessionState
19+
metdata: NotRequired[Any]
20+
21+
22+
class HandshakeOK(TypedDict):
23+
ok: Literal[True]
24+
sessionId: str
25+
26+
27+
class HandshakeError(TypedDict):
28+
ok: Literal[False]
29+
reaason: str
30+
31+
32+
class ControlHandshakeResponse(TypedDict):
33+
type: Literal["HANDSHAKE_RESP"]
34+
status: HandshakeOK | HandshakeError
35+
36+
37+
Control: TypeAlias = (
38+
ControlClose | ControlAck | ControlHandshakeRequest | ControlHandshakeResponse
39+
)

0 commit comments

Comments
 (0)