-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathprotocol.ts
More file actions
229 lines (205 loc) · 6.29 KB
/
protocol.ts
File metadata and controls
229 lines (205 loc) · 6.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
// ---- Shared types ----
/**
* Serializable description of a command argument, used in protocol messages.
*/
export type CommandArgInfo = {
/** The name of the argument. */
name: string;
/** A human-readable description of the argument. */
description: string;
/** Whether this argument is required. */
required?: boolean;
/** The type of the argument. Defaults to "string". When "file", the CLI reads the file and sends its contents. */
type?: "string" | "file";
};
/**
* Serializable description of a command, used in protocol messages.
*/
export type CommandInfo = {
/** A unique identifier for the command. */
id: string;
/** A human-readable description of the command. */
description: string;
/** The arguments this command accepts. */
args?: CommandArgInfo[];
};
/**
* Serializable description of a session, used in protocol messages.
*/
export type SessionInfo = {
/** The numeric session identifier. */
id: number;
/** The display name of the session. */
name: string;
/** ISO 8601 timestamp of when the session connected. */
connectedAt: string;
};
// ---- CLI ↔ Bridge (CLI port) ----
/**
* CLI → Bridge: Request the list of active browser sessions.
*/
export type SessionsRequest = {
/** The message type discriminator. */
type: "sessions";
};
/**
* CLI → Bridge: Request the list of commands available from a session.
*/
export type CommandsRequest = {
/** The message type discriminator. */
type: "commands";
/** The session to query for commands. */
sessionId: number;
};
/**
* CLI → Bridge: Execute a command on a session.
*/
export type ExecRequest = {
/** The message type discriminator. */
type: "exec";
/** The session to execute the command on. */
sessionId: number;
/** The identifier of the command to execute. */
commandId: string;
/** Key-value pairs of arguments for the command. */
args: Record<string, string>;
};
/**
* CLI → Bridge: Stop the bridge process.
*/
export type StopRequest = {
/** The message type discriminator. */
type: "stop";
};
/**
* All messages that the CLI sends to the bridge.
*/
export type CliRequest = SessionsRequest | CommandsRequest | ExecRequest | StopRequest;
/**
* Bridge → CLI: Response with the list of active sessions.
*/
export type SessionsResponse = {
/** The message type discriminator. */
type: "sessionsResponse";
/** The list of active sessions. */
sessions: SessionInfo[];
};
/**
* Bridge → CLI: Response with the list of commands from a session.
*/
export type CommandsResponse = {
/** The message type discriminator. */
type: "commandsResponse";
/** The list of available commands, if successful. */
commands?: CommandInfo[];
/** An error message, if the request failed. */
error?: string;
};
/**
* Bridge → CLI: Response with the result of a command execution.
*/
export type ExecResponse = {
/** The message type discriminator. */
type: "execResponse";
/** The result of the command execution, if successful. */
result?: string;
/** An error message, if the execution failed. */
error?: string;
};
/**
* Bridge → CLI: Acknowledgement that the bridge is stopping.
*/
export type StopResponse = {
/** The message type discriminator. */
type: "stopResponse";
/** Whether the bridge stopped successfully. */
success: boolean;
};
/**
* All messages that the bridge sends to the CLI.
*/
export type CliResponse = SessionsResponse | CommandsResponse | ExecResponse | StopResponse;
// ---- Bridge ↔ Browser (browser port) ----
/**
* Browser → Bridge: Register a new session.
*/
export type RegisterRequest = {
/** The message type discriminator. */
type: "register";
/** The display name for this session. */
name: string;
};
/**
* Browser → Bridge: Response to a listCommands request from the bridge.
*/
export type CommandListResponse = {
/** The message type discriminator. */
type: "commandListResponse";
/** The identifier of the original request. */
requestId: string;
/** The list of registered commands. */
commands: CommandInfo[];
};
/**
* Browser → Bridge: Response to an execCommand request from the bridge.
*/
export type CommandResponse = {
/** The message type discriminator. */
type: "commandResponse";
/** The identifier of the original request. */
requestId: string;
/** The result of the command execution, if successful. */
result?: string;
/** An error message, if the execution failed. */
error?: string;
};
/**
* Browser → Bridge: Response to a getInfo request from the bridge.
*/
export type InfoResponse = {
/** The message type discriminator. */
type: "infoResponse";
/** The identifier of the original request. */
requestId: string;
/** The current display name of the session. */
name: string;
};
/**
* All messages that the browser sends to the bridge.
*/
export type BrowserRequest = RegisterRequest | CommandListResponse | CommandResponse | InfoResponse;
/**
* Bridge → Browser: Request the list of registered commands.
*/
export type ListCommandsRequest = {
/** The message type discriminator. */
type: "listCommands";
/** A unique identifier for this request. */
requestId: string;
};
/**
* Bridge → Browser: Request execution of a command.
*/
export type ExecCommandRequest = {
/** The message type discriminator. */
type: "execCommand";
/** A unique identifier for this request. */
requestId: string;
/** The identifier of the command to execute. */
commandId: string;
/** Key-value pairs of arguments for the command. */
args: Record<string, string>;
};
/**
* Bridge → Browser: Request current session information.
*/
export type GetInfoRequest = {
/** The message type discriminator. */
type: "getInfo";
/** A unique identifier for this request. */
requestId: string;
};
/**
* All messages that the bridge sends to the browser.
*/
export type BrowserResponse = ListCommandsRequest | ExecCommandRequest | GetInfoRequest;