@myagentroam/protocol 0.13.11 → 0.13.13
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/dist/index.d.ts +986 -797
- package/dist/index.js +5 -0
- package/dist/remote-desktop.d.ts +789 -0
- package/dist/remote-desktop.js +341 -0
- package/package.json +1 -1
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const id = z
|
|
3
|
+
.string()
|
|
4
|
+
.min(8)
|
|
5
|
+
.max(128)
|
|
6
|
+
.regex(/^[A-Za-z0-9_-]+$/u);
|
|
7
|
+
const nodeId = z.string().min(1).max(512);
|
|
8
|
+
const revision = z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
|
|
9
|
+
const timestamp = z.number().int().positive().max(Number.MAX_SAFE_INTEGER);
|
|
10
|
+
const code = z.string().regex(/^[A-Z][A-Z0-9_]{0,127}$/u);
|
|
11
|
+
const grant = z.string().min(32).max(4096);
|
|
12
|
+
const fingerprint = z.string().regex(/^sha-256(?: [A-F0-9]{2}(?::[A-F0-9]{2}){31})$/u);
|
|
13
|
+
export const remoteDesktopModeSchema = z.enum(['VIEW', 'CONTROL']);
|
|
14
|
+
const nativeCoordinate = z.number().finite().min(-0x80000000).max(0x7fffffff);
|
|
15
|
+
const dimension = z.number().int().positive().max(65535);
|
|
16
|
+
const nativeRectangle = z
|
|
17
|
+
.object({
|
|
18
|
+
x: nativeCoordinate,
|
|
19
|
+
y: nativeCoordinate,
|
|
20
|
+
width: z.number().finite().positive().max(65535),
|
|
21
|
+
height: z.number().finite().positive().max(65535)
|
|
22
|
+
})
|
|
23
|
+
.strict();
|
|
24
|
+
const framebufferRectangle = z
|
|
25
|
+
.object({
|
|
26
|
+
x: z.number().int().nonnegative().max(65535),
|
|
27
|
+
y: z.number().int().nonnegative().max(65535),
|
|
28
|
+
width: dimension,
|
|
29
|
+
height: dimension
|
|
30
|
+
})
|
|
31
|
+
.strict();
|
|
32
|
+
const coefficient = z.number().finite().min(-1_000_000).max(1_000_000);
|
|
33
|
+
/**
|
|
34
|
+
* The adapter supplies [a,b,c,d,tx,ty], mapping x'=a*x+c*y+tx and
|
|
35
|
+
* y'=b*x+d*y+ty; the browser must not infer it from devicePixelRatio.
|
|
36
|
+
*/
|
|
37
|
+
export const remoteDesktopDescriptionSchema = z
|
|
38
|
+
.object({
|
|
39
|
+
desktopGeneration: id,
|
|
40
|
+
topologyRevision: revision,
|
|
41
|
+
framebuffer: z.object({ width: dimension, height: dimension }).strict(),
|
|
42
|
+
displays: z
|
|
43
|
+
.array(z
|
|
44
|
+
.object({
|
|
45
|
+
displayId: id,
|
|
46
|
+
name: z.string().min(1).max(256),
|
|
47
|
+
primary: z.boolean(),
|
|
48
|
+
nativeBounds: nativeRectangle,
|
|
49
|
+
framebufferBounds: framebufferRectangle,
|
|
50
|
+
nativeToFramebuffer: z.tuple([
|
|
51
|
+
coefficient,
|
|
52
|
+
coefficient,
|
|
53
|
+
coefficient,
|
|
54
|
+
coefficient,
|
|
55
|
+
coefficient,
|
|
56
|
+
coefficient
|
|
57
|
+
])
|
|
58
|
+
})
|
|
59
|
+
.strict())
|
|
60
|
+
.min(1)
|
|
61
|
+
.max(64)
|
|
62
|
+
})
|
|
63
|
+
.strict()
|
|
64
|
+
.superRefine((description, context) => {
|
|
65
|
+
const seen = new Set();
|
|
66
|
+
let primaryCount = 0;
|
|
67
|
+
description.displays.forEach((display, index) => {
|
|
68
|
+
const bounds = display.framebufferBounds;
|
|
69
|
+
if (seen.has(display.displayId))
|
|
70
|
+
context.addIssue({
|
|
71
|
+
code: z.ZodIssueCode.custom,
|
|
72
|
+
path: ['displays', index, 'displayId'],
|
|
73
|
+
message: 'Duplicate display ID'
|
|
74
|
+
});
|
|
75
|
+
seen.add(display.displayId);
|
|
76
|
+
if (display.primary)
|
|
77
|
+
primaryCount++;
|
|
78
|
+
if (bounds.x < 0 ||
|
|
79
|
+
bounds.y < 0 ||
|
|
80
|
+
bounds.x + bounds.width > description.framebuffer.width ||
|
|
81
|
+
bounds.y + bounds.height > description.framebuffer.height)
|
|
82
|
+
context.addIssue({
|
|
83
|
+
code: z.ZodIssueCode.custom,
|
|
84
|
+
path: ['displays', index, 'framebufferBounds'],
|
|
85
|
+
message: 'Display is outside the framebuffer'
|
|
86
|
+
});
|
|
87
|
+
const [a, b, c, d, tx, ty] = display.nativeToFramebuffer;
|
|
88
|
+
const native = display.nativeBounds;
|
|
89
|
+
const corners = [
|
|
90
|
+
[native.x, native.y],
|
|
91
|
+
[native.x + native.width, native.y],
|
|
92
|
+
[native.x, native.y + native.height],
|
|
93
|
+
[native.x + native.width, native.y + native.height]
|
|
94
|
+
].map(([x, y]) => [a * x + c * y + tx, b * x + d * y + ty]);
|
|
95
|
+
const xs = corners.map((corner) => corner[0]);
|
|
96
|
+
const ys = corners.map((corner) => corner[1]);
|
|
97
|
+
if (Math.abs(a * d - b * c) < 1e-12 ||
|
|
98
|
+
Math.abs(Math.min(...xs) - bounds.x) > 1 ||
|
|
99
|
+
Math.abs(Math.min(...ys) - bounds.y) > 1 ||
|
|
100
|
+
Math.abs(Math.max(...xs) - bounds.x - bounds.width) > 1 ||
|
|
101
|
+
Math.abs(Math.max(...ys) - bounds.y - bounds.height) > 1)
|
|
102
|
+
context.addIssue({
|
|
103
|
+
code: z.ZodIssueCode.custom,
|
|
104
|
+
path: ['displays', index, 'nativeToFramebuffer'],
|
|
105
|
+
message: 'Display mapping does not match its bounds'
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
if (primaryCount !== 1)
|
|
109
|
+
context.addIssue({
|
|
110
|
+
code: z.ZodIssueCode.custom,
|
|
111
|
+
path: ['displays'],
|
|
112
|
+
message: 'Exactly one primary display is required'
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
export const remoteDesktopCapabilitySchema = z.discriminatedUnion('available', [
|
|
116
|
+
z
|
|
117
|
+
.object({
|
|
118
|
+
apiVersion: z.literal(1),
|
|
119
|
+
available: z.literal(false),
|
|
120
|
+
nodeGeneration: id,
|
|
121
|
+
reasonCode: code
|
|
122
|
+
})
|
|
123
|
+
.strict(),
|
|
124
|
+
z
|
|
125
|
+
.object({
|
|
126
|
+
apiVersion: z.literal(1),
|
|
127
|
+
available: z.literal(true),
|
|
128
|
+
nodeGeneration: id,
|
|
129
|
+
backend: z.enum(['TIGERVNC_X0', 'ULTRAVNC', 'MACVNC']),
|
|
130
|
+
supportsView: z.literal(true),
|
|
131
|
+
supportsControl: z.boolean(),
|
|
132
|
+
supportsMultiDisplay: z.boolean(),
|
|
133
|
+
supportsUnicodePaste: z.boolean(),
|
|
134
|
+
transports: z
|
|
135
|
+
.array(z.enum(['DIRECT', 'RELAY']))
|
|
136
|
+
.min(1)
|
|
137
|
+
.max(2)
|
|
138
|
+
.refine((items) => new Set(items).size === items.length),
|
|
139
|
+
})
|
|
140
|
+
.strict()
|
|
141
|
+
]);
|
|
142
|
+
/** Authenticated page control messages, never an RFB data or input protocol. */
|
|
143
|
+
export const remoteDesktopDirectBrowserMessageSchema = z.discriminatedUnion('type', [
|
|
144
|
+
z
|
|
145
|
+
.object({
|
|
146
|
+
type: z.literal('desktop.direct.prepare'),
|
|
147
|
+
requestId: id,
|
|
148
|
+
nodeId,
|
|
149
|
+
nodeGeneration: id,
|
|
150
|
+
transportSessionId: id,
|
|
151
|
+
desktopGeneration: id,
|
|
152
|
+
topologyRevision: revision,
|
|
153
|
+
mode: remoteDesktopModeSchema
|
|
154
|
+
})
|
|
155
|
+
.strict(),
|
|
156
|
+
z.object({ type: z.literal('desktop.direct.heartbeat'), attachmentId: id }).strict(),
|
|
157
|
+
z.object({ type: z.literal('desktop.direct.cancel'), attachmentId: id }).strict(),
|
|
158
|
+
z.object({ type: z.literal('desktop.ready'), attachmentId: id }).strict()
|
|
159
|
+
]);
|
|
160
|
+
export const remoteDesktopDirectServerMessageSchema = z.discriminatedUnion('type', [
|
|
161
|
+
z
|
|
162
|
+
.object({
|
|
163
|
+
type: z.literal('desktop.direct.prepared'),
|
|
164
|
+
requestId: id,
|
|
165
|
+
attachmentId: id,
|
|
166
|
+
grant,
|
|
167
|
+
openExpiresAt: timestamp,
|
|
168
|
+
expiresAt: timestamp
|
|
169
|
+
})
|
|
170
|
+
.strict(),
|
|
171
|
+
z
|
|
172
|
+
.object({ type: z.literal('desktop.direct.heartbeat'), attachmentId: id, expiresAt: timestamp })
|
|
173
|
+
.strict(),
|
|
174
|
+
z.object({ type: z.literal('desktop.direct.closed'), attachmentId: id, code }).strict(),
|
|
175
|
+
z.object({ type: z.literal('desktop.direct.settled'), attachmentId: id, code }).strict(),
|
|
176
|
+
z
|
|
177
|
+
.object({
|
|
178
|
+
type: z.literal('desktop.direct.error'),
|
|
179
|
+
requestId: id.optional(),
|
|
180
|
+
attachmentId: id.optional(),
|
|
181
|
+
settled: z.literal(true).optional(),
|
|
182
|
+
code,
|
|
183
|
+
message: z.string().min(1).max(1000)
|
|
184
|
+
})
|
|
185
|
+
.strict()
|
|
186
|
+
]);
|
|
187
|
+
export const remoteDesktopDirectNodeCommandSchema = z.discriminatedUnion('type', [
|
|
188
|
+
z
|
|
189
|
+
.object({
|
|
190
|
+
type: z.literal('desktop.direct.prepare'),
|
|
191
|
+
attachmentId: id,
|
|
192
|
+
transportSessionId: id,
|
|
193
|
+
workbenchConnectionId: id,
|
|
194
|
+
nodeGeneration: id,
|
|
195
|
+
desktopGeneration: id,
|
|
196
|
+
topologyRevision: revision,
|
|
197
|
+
mode: remoteDesktopModeSchema,
|
|
198
|
+
grant,
|
|
199
|
+
browserFingerprint: fingerprint,
|
|
200
|
+
nodeFingerprint: fingerprint,
|
|
201
|
+
openExpiresAt: timestamp,
|
|
202
|
+
expiresAt: timestamp
|
|
203
|
+
})
|
|
204
|
+
.strict(),
|
|
205
|
+
z
|
|
206
|
+
.object({ type: z.literal('desktop.direct.heartbeat'), attachmentId: id, expiresAt: timestamp })
|
|
207
|
+
.strict(),
|
|
208
|
+
z.object({ type: z.literal('desktop.direct.cancel'), attachmentId: id, code }).strict(),
|
|
209
|
+
z.object({ type: z.literal('desktop.ready'), attachmentId: id }).strict()
|
|
210
|
+
]);
|
|
211
|
+
export const remoteDesktopDirectNodeEventSchema = z.discriminatedUnion('type', [
|
|
212
|
+
z
|
|
213
|
+
.object({
|
|
214
|
+
type: z.literal('desktop.direct.ready'),
|
|
215
|
+
attachmentId: id,
|
|
216
|
+
nodeGeneration: id,
|
|
217
|
+
phase: z.enum(['PREPARED', 'OPEN', 'ATTACHED', 'ACTIVE'])
|
|
218
|
+
})
|
|
219
|
+
.strict(),
|
|
220
|
+
z
|
|
221
|
+
.object({
|
|
222
|
+
type: z.literal('desktop.direct.closed'),
|
|
223
|
+
attachmentId: id,
|
|
224
|
+
nodeGeneration: id,
|
|
225
|
+
code
|
|
226
|
+
})
|
|
227
|
+
.strict()
|
|
228
|
+
]);
|
|
229
|
+
/** Relay uses the same admission phases and RFB OPEN; its one-time data sockets are distinct. */
|
|
230
|
+
export const remoteDesktopRelayBrowserMessageSchema = z.discriminatedUnion('type', [
|
|
231
|
+
z
|
|
232
|
+
.object({
|
|
233
|
+
type: z.literal('desktop.relay.prepare'),
|
|
234
|
+
requestId: id,
|
|
235
|
+
nodeId,
|
|
236
|
+
nodeGeneration: id,
|
|
237
|
+
desktopGeneration: id,
|
|
238
|
+
topologyRevision: revision,
|
|
239
|
+
mode: remoteDesktopModeSchema
|
|
240
|
+
})
|
|
241
|
+
.strict(),
|
|
242
|
+
z.object({ type: z.literal('desktop.relay.heartbeat'), attachmentId: id }).strict(),
|
|
243
|
+
z.object({ type: z.literal('desktop.relay.cancel'), attachmentId: id }).strict(),
|
|
244
|
+
z.object({ type: z.literal('desktop.ready'), attachmentId: id }).strict()
|
|
245
|
+
]);
|
|
246
|
+
export const remoteDesktopRelayServerMessageSchema = z.discriminatedUnion('type', [
|
|
247
|
+
z
|
|
248
|
+
.object({
|
|
249
|
+
type: z.literal('desktop.relay.prepared'),
|
|
250
|
+
requestId: id,
|
|
251
|
+
attachmentId: id,
|
|
252
|
+
grant,
|
|
253
|
+
ticket: grant,
|
|
254
|
+
openExpiresAt: timestamp,
|
|
255
|
+
expiresAt: timestamp
|
|
256
|
+
})
|
|
257
|
+
.strict(),
|
|
258
|
+
z
|
|
259
|
+
.object({ type: z.literal('desktop.relay.heartbeat'), attachmentId: id, expiresAt: timestamp })
|
|
260
|
+
.strict(),
|
|
261
|
+
z.object({ type: z.literal('desktop.relay.closed'), attachmentId: id, code }).strict(),
|
|
262
|
+
z.object({ type: z.literal('desktop.relay.settled'), attachmentId: id, code }).strict(),
|
|
263
|
+
z
|
|
264
|
+
.object({
|
|
265
|
+
type: z.literal('desktop.relay.error'),
|
|
266
|
+
requestId: id.optional(),
|
|
267
|
+
attachmentId: id.optional(),
|
|
268
|
+
settled: z.literal(true).optional(),
|
|
269
|
+
code,
|
|
270
|
+
message: z.string().min(1).max(1000)
|
|
271
|
+
})
|
|
272
|
+
.strict()
|
|
273
|
+
]);
|
|
274
|
+
export const remoteDesktopRelayNodeCommandSchema = z.discriminatedUnion('type', [
|
|
275
|
+
z
|
|
276
|
+
.object({
|
|
277
|
+
type: z.literal('desktop.relay.prepare'),
|
|
278
|
+
attachmentId: id,
|
|
279
|
+
workbenchConnectionId: id,
|
|
280
|
+
nodeGeneration: id,
|
|
281
|
+
desktopGeneration: id,
|
|
282
|
+
topologyRevision: revision,
|
|
283
|
+
mode: remoteDesktopModeSchema,
|
|
284
|
+
grant,
|
|
285
|
+
ticket: grant,
|
|
286
|
+
openExpiresAt: timestamp,
|
|
287
|
+
expiresAt: timestamp
|
|
288
|
+
})
|
|
289
|
+
.strict(),
|
|
290
|
+
z
|
|
291
|
+
.object({ type: z.literal('desktop.relay.heartbeat'), attachmentId: id, expiresAt: timestamp })
|
|
292
|
+
.strict(),
|
|
293
|
+
z.object({ type: z.literal('desktop.relay.cancel'), attachmentId: id, code }).strict(),
|
|
294
|
+
z.object({ type: z.literal('desktop.ready'), attachmentId: id }).strict()
|
|
295
|
+
]);
|
|
296
|
+
export const remoteDesktopRelayNodeEventSchema = z.discriminatedUnion('type', [
|
|
297
|
+
z
|
|
298
|
+
.object({
|
|
299
|
+
type: z.literal('desktop.relay.ready'),
|
|
300
|
+
attachmentId: id,
|
|
301
|
+
nodeGeneration: id,
|
|
302
|
+
phase: z.enum(['PREPARED', 'OPEN', 'ATTACHED', 'ACTIVE'])
|
|
303
|
+
})
|
|
304
|
+
.strict(),
|
|
305
|
+
z
|
|
306
|
+
.object({ type: z.literal('desktop.relay.closed'), attachmentId: id, nodeGeneration: id, code })
|
|
307
|
+
.strict()
|
|
308
|
+
]);
|
|
309
|
+
/** Sent only as the first WebSocket message, never in a URL. */
|
|
310
|
+
export const remoteDesktopRelayBrowserAttachSchema = z
|
|
311
|
+
.object({
|
|
312
|
+
type: z.literal('desktop.relay.browser'),
|
|
313
|
+
attachmentId: id,
|
|
314
|
+
workbenchConnectionId: id,
|
|
315
|
+
ticket: grant
|
|
316
|
+
})
|
|
317
|
+
.strict();
|
|
318
|
+
export const remoteDesktopRelayNodeAttachSchema = z
|
|
319
|
+
.object({
|
|
320
|
+
type: z.literal('desktop.relay.node'),
|
|
321
|
+
nodeId,
|
|
322
|
+
nodeGeneration: id,
|
|
323
|
+
attachmentId: id,
|
|
324
|
+
ticket: grant,
|
|
325
|
+
credential: z.string().min(1).max(4096)
|
|
326
|
+
})
|
|
327
|
+
.strict();
|
|
328
|
+
/** Only this one-time authorization envelope precedes standard RFB bytes. */
|
|
329
|
+
export const remoteDesktopDirectOpenFrameSchema = z
|
|
330
|
+
.object({
|
|
331
|
+
type: z.literal('OPEN'),
|
|
332
|
+
attachmentId: id,
|
|
333
|
+
grant
|
|
334
|
+
})
|
|
335
|
+
.strict();
|
|
336
|
+
export const remoteDesktopAttachedFrameSchema = z
|
|
337
|
+
.object({
|
|
338
|
+
type: z.literal('ATTACHED'),
|
|
339
|
+
attachmentId: id
|
|
340
|
+
})
|
|
341
|
+
.strict();
|