@ai-matrx/desktop-protocol 0.1.0

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.
@@ -0,0 +1,924 @@
1
+ import { ReactNode } from 'react';
2
+ import { z } from 'zod';
3
+
4
+ /**
5
+ * Zod-free type twins of the wire error shapes, for the zod-free entries (`./frame`, error.ts).
6
+ * schema/errors.ts asserts at compile time that these equal the zod-inferred types, so they can
7
+ * never drift (see the `_assert*` lines there).
8
+ */
9
+ type ErrorCodeName = "AUTH_REQUIRED" | "AUTH_INVALID" | "AUTH_EXPIRED" | "AUTH_FORBIDDEN" | "AUTH_DEVICE_REVOKED" | "PERMISSION_DENIED_OS" | "NOT_FOUND" | "CONFLICT" | "INVALID_PARAMS" | "RESOURCE_BUSY" | "RESOURCE_GONE" | "CANCELLED" | "TIMEOUT" | "PLATFORM_UNSUPPORTED" | "RATE_LIMITED" | "INTERNAL" | "PROTOCOL_VERSION_UNSUPPORTED" | "PROTOCOL_ERROR" | "UNKNOWN_OPERATION" | "DEVICE_OFFLINE" | "PAYLOAD_TOO_LARGE";
10
+ type ErrorReasonName = "not_a_directory" | "is_a_directory" | "directory_not_empty" | "already_exists" | "stale_write" | "binary_content" | "not_utf8_boundary" | "patch_no_match" | "patch_ambiguous" | "resource_exited" | "resource_expired" | "control_taken" | "window_exhausted";
11
+ interface ErrorData {
12
+ reason?: ErrorReasonName | undefined;
13
+ cap?: string | undefined;
14
+ op?: string | undefined;
15
+ path?: string | undefined;
16
+ settings_url?: string | undefined;
17
+ retry_after_ms?: number | undefined;
18
+ limit_bytes?: number | undefined;
19
+ upgrade?: {
20
+ min_version: string;
21
+ max_version: string;
22
+ download_url?: string | undefined;
23
+ } | undefined;
24
+ }
25
+
26
+ /**
27
+ * The one error type every package entry throws. It carries the wire ErrorCode (SPEC §5), so a
28
+ * caller branches on `code`/`retryable`/`data.reason` and never parses a message. Zod-free on
29
+ * purpose: `./frame` (the relay hot path) throws it without pulling the schema graph.
30
+ */
31
+
32
+ declare class DesktopProtocolError extends Error {
33
+ readonly code: ErrorCodeName;
34
+ readonly retryable: boolean;
35
+ readonly data: ErrorData | undefined;
36
+ constructor(code: ErrorCodeName, message: string, options?: {
37
+ retryable?: boolean;
38
+ data?: ErrorData;
39
+ cause?: unknown;
40
+ });
41
+ /** The wire body (ProtocolErrorBody) — what a core or relay sends for this error. */
42
+ toBody(): {
43
+ code: ErrorCodeName;
44
+ message: string;
45
+ retryable: boolean;
46
+ data?: ErrorData;
47
+ };
48
+ }
49
+
50
+ declare const FRAME_VERSION: 1;
51
+ declare const FrameChannel: {
52
+ /** core→client: pty output, fs.read_stream bytes */
53
+ readonly DATA: 0;
54
+ /** core→client: stderr of a non-pty process (reserved for exec.spawn in v1.1) */
55
+ readonly STDERR: 1;
56
+ /** client→core: keystrokes / stdin to sid */
57
+ readonly STDIN: 2;
58
+ /** core→client: serialized terminal screen (attach when since_seq is outside the ring) */
59
+ readonly SNAPSHOT: 3;
60
+ /** relay↔device hop only: a JSON envelope carried inside a binary frame so the relay can route
61
+ * by cid without parsing JSON. Never seen by clients. */
62
+ readonly ENVELOPE: 255;
63
+ };
64
+ type FrameChannelValue = (typeof FrameChannel)[keyof typeof FrameChannel];
65
+ interface FrameHeader {
66
+ version: typeof FRAME_VERSION;
67
+ /** 0..3 — FrameFlag bits. */
68
+ flags: number;
69
+ channel: FrameChannelValue;
70
+ cid: number;
71
+ sid: number;
72
+ seq: number;
73
+ }
74
+
75
+ /** @ai-matrx/desktop-protocol — the JSON envelope (SPEC §4). Schema source: lint-enforced rules in scripts/check-schema-source.mjs. */
76
+
77
+ declare const Welcome: z.ZodObject<{
78
+ protocol_version: z.ZodString;
79
+ session_id: z.ZodString;
80
+ client_id: z.ZodString;
81
+ device_id: z.ZodString;
82
+ device_name: z.ZodString;
83
+ app_version: z.ZodString;
84
+ platform: z.ZodEnum<{
85
+ darwin: "darwin";
86
+ win32: "win32";
87
+ linux: "linux";
88
+ }>;
89
+ ops: z.ZodArray<z.ZodObject<{
90
+ cap: z.ZodString;
91
+ op: z.ZodString;
92
+ since: z.ZodString;
93
+ }, z.core.$strict>>;
94
+ limits: z.ZodObject<{
95
+ max_message_bytes: z.ZodInt;
96
+ max_frame_payload_bytes: z.ZodInt;
97
+ default_window_bytes: z.ZodInt;
98
+ max_streams_per_client: z.ZodInt;
99
+ max_resources_per_user: z.ZodInt;
100
+ }, z.core.$strict>;
101
+ server_time_ms: z.ZodInt;
102
+ }, z.core.$strict>;
103
+ type Welcome = z.output<typeof Welcome>;
104
+ declare const StreamMeta: z.ZodDiscriminatedUnion<[z.ZodObject<{
105
+ kind: z.ZodLiteral<"open">;
106
+ sid: z.ZodInt;
107
+ window_bytes: z.ZodInt;
108
+ resource_id: z.ZodOptional<z.ZodString>;
109
+ }, z.core.$strict>, z.ZodObject<{
110
+ kind: z.ZodLiteral<"snapshot">;
111
+ cols: z.ZodInt;
112
+ rows: z.ZodInt;
113
+ }, z.core.$strict>, z.ZodObject<{
114
+ kind: z.ZodLiteral<"gap">;
115
+ from_seq: z.ZodInt;
116
+ to_seq: z.ZodInt;
117
+ }, z.core.$strict>], "kind">;
118
+ type StreamMeta = z.output<typeof StreamMeta>;
119
+ declare const EndReason: z.ZodEnum<{
120
+ error: "error";
121
+ resource_exited: "resource_exited";
122
+ completed: "completed";
123
+ cancelled: "cancelled";
124
+ detached: "detached";
125
+ }>;
126
+ type EndReason = z.output<typeof EndReason>;
127
+
128
+ /** @ai-matrx/desktop-protocol — the op and event registries (Router, client and Python are generated from these). */
129
+
130
+ declare const OPS: {
131
+ readonly "sysinfo.get": {
132
+ readonly params: z.ZodObject<{}, z.core.$strict>;
133
+ readonly result: z.ZodObject<{
134
+ device_id: z.ZodString;
135
+ device_name: z.ZodString;
136
+ hostname: z.ZodString;
137
+ platform: z.ZodEnum<{
138
+ darwin: "darwin";
139
+ win32: "win32";
140
+ linux: "linux";
141
+ }>;
142
+ os_version: z.ZodString;
143
+ arch: z.ZodEnum<{
144
+ arm64: "arm64";
145
+ x64: "x64";
146
+ }>;
147
+ app_version: z.ZodString;
148
+ protocol_version: z.ZodString;
149
+ user: z.ZodObject<{
150
+ username: z.ZodString;
151
+ shell: z.ZodString;
152
+ }, z.core.$strict>;
153
+ paths: z.ZodObject<{
154
+ home: z.ZodString;
155
+ desktop: z.ZodString;
156
+ documents: z.ZodString;
157
+ downloads: z.ZodString;
158
+ app_data: z.ZodString;
159
+ temp: z.ZodString;
160
+ }, z.core.$strict>;
161
+ cpu: z.ZodObject<{
162
+ model: z.ZodString;
163
+ cores: z.ZodInt;
164
+ }, z.core.$strict>;
165
+ memory: z.ZodObject<{
166
+ total_bytes: z.ZodInt;
167
+ free_bytes: z.ZodInt;
168
+ }, z.core.$strict>;
169
+ uptime_seconds: z.ZodInt;
170
+ on_battery: z.ZodNullable<z.ZodBoolean>;
171
+ sleep_prevented: z.ZodBoolean;
172
+ permissions: z.ZodArray<z.ZodObject<{
173
+ name: z.ZodEnum<{
174
+ full_disk_access: "full_disk_access";
175
+ accessibility: "accessibility";
176
+ screen_recording: "screen_recording";
177
+ microphone: "microphone";
178
+ camera: "camera";
179
+ automation: "automation";
180
+ contacts: "contacts";
181
+ calendars: "calendars";
182
+ photos: "photos";
183
+ location: "location";
184
+ local_network: "local_network";
185
+ bluetooth: "bluetooth";
186
+ notifications: "notifications";
187
+ }>;
188
+ state: z.ZodEnum<{
189
+ granted: "granted";
190
+ denied: "denied";
191
+ not_determined: "not_determined";
192
+ not_applicable: "not_applicable";
193
+ }>;
194
+ settings_url: z.ZodNullable<z.ZodString>;
195
+ }, z.core.$strict>>;
196
+ }, z.core.$strict>;
197
+ readonly kind: "unary";
198
+ readonly since: "1.0";
199
+ readonly errors: readonly ["INTERNAL"];
200
+ };
201
+ readonly "fs.list": {
202
+ readonly params: z.ZodObject<{
203
+ path: z.ZodString;
204
+ recursive: z.ZodDefault<z.ZodBoolean>;
205
+ depth: z.ZodDefault<z.ZodInt>;
206
+ pattern: z.ZodOptional<z.ZodString>;
207
+ limit: z.ZodDefault<z.ZodInt>;
208
+ page_token: z.ZodOptional<z.ZodString>;
209
+ show_hidden: z.ZodDefault<z.ZodBoolean>;
210
+ sort: z.ZodDefault<z.ZodEnum<{
211
+ name: "name";
212
+ mtime: "mtime";
213
+ size: "size";
214
+ kind: "kind";
215
+ }>>;
216
+ }, z.core.$strict>;
217
+ readonly result: z.ZodObject<{
218
+ entries: z.ZodArray<z.ZodObject<{
219
+ name: z.ZodString;
220
+ path: z.ZodString;
221
+ kind: z.ZodEnum<{
222
+ file: "file";
223
+ dir: "dir";
224
+ symlink: "symlink";
225
+ }>;
226
+ size: z.ZodInt;
227
+ mtime: z.ZodNumber;
228
+ mtime_ms: z.ZodInt;
229
+ mode: z.ZodInt;
230
+ target: z.ZodNullable<z.ZodString>;
231
+ hidden: z.ZodBoolean;
232
+ }, z.core.$strict>>;
233
+ truncated: z.ZodBoolean;
234
+ next_page_token: z.ZodNullable<z.ZodString>;
235
+ scanned: z.ZodInt;
236
+ }, z.core.$strict>;
237
+ readonly kind: "unary";
238
+ readonly since: "1.0";
239
+ readonly errors: readonly ["NOT_FOUND", "PERMISSION_DENIED_OS", "INVALID_PARAMS", "RESOURCE_BUSY", "INTERNAL"];
240
+ };
241
+ readonly "fs.stat": {
242
+ readonly params: z.ZodObject<{
243
+ path: z.ZodString;
244
+ }, z.core.$strict>;
245
+ readonly result: z.ZodObject<{
246
+ name: z.ZodString;
247
+ path: z.ZodString;
248
+ kind: z.ZodEnum<{
249
+ file: "file";
250
+ dir: "dir";
251
+ symlink: "symlink";
252
+ }>;
253
+ size: z.ZodInt;
254
+ mtime: z.ZodNumber;
255
+ mtime_ms: z.ZodInt;
256
+ mode: z.ZodInt;
257
+ target: z.ZodNullable<z.ZodString>;
258
+ hidden: z.ZodBoolean;
259
+ }, z.core.$strict>;
260
+ readonly kind: "unary";
261
+ readonly since: "1.0";
262
+ readonly errors: readonly ["NOT_FOUND", "PERMISSION_DENIED_OS", "INVALID_PARAMS", "RESOURCE_BUSY", "INTERNAL"];
263
+ };
264
+ readonly "fs.read": {
265
+ readonly params: z.ZodObject<{
266
+ path: z.ZodString;
267
+ encoding: z.ZodDefault<z.ZodEnum<{
268
+ utf8: "utf8";
269
+ base64: "base64";
270
+ }>>;
271
+ offset: z.ZodDefault<z.ZodInt>;
272
+ limit: z.ZodDefault<z.ZodInt>;
273
+ }, z.core.$strict>;
274
+ readonly result: z.ZodObject<{
275
+ content: z.ZodString;
276
+ encoding: z.ZodEnum<{
277
+ utf8: "utf8";
278
+ base64: "base64";
279
+ }>;
280
+ size: z.ZodInt;
281
+ offset: z.ZodInt;
282
+ next_offset: z.ZodInt;
283
+ truncated: z.ZodBoolean;
284
+ mime: z.ZodNullable<z.ZodString>;
285
+ mtime_ms: z.ZodInt;
286
+ }, z.core.$strict>;
287
+ readonly kind: "unary";
288
+ readonly since: "1.0";
289
+ readonly errors: readonly ["NOT_FOUND", "PERMISSION_DENIED_OS", "INVALID_PARAMS", "RESOURCE_BUSY", "INTERNAL", "PAYLOAD_TOO_LARGE"];
290
+ };
291
+ readonly "fs.read_stream": {
292
+ readonly params: z.ZodObject<{
293
+ path: z.ZodString;
294
+ offset: z.ZodDefault<z.ZodInt>;
295
+ length: z.ZodOptional<z.ZodInt>;
296
+ window_bytes: z.ZodOptional<z.ZodInt>;
297
+ }, z.core.$strict>;
298
+ readonly result: z.ZodObject<{
299
+ size: z.ZodInt;
300
+ mime: z.ZodNullable<z.ZodString>;
301
+ mtime_ms: z.ZodInt;
302
+ }, z.core.$strict>;
303
+ readonly kind: "stream";
304
+ readonly since: "1.0";
305
+ readonly errors: readonly ["NOT_FOUND", "PERMISSION_DENIED_OS", "INVALID_PARAMS", "RESOURCE_BUSY", "INTERNAL", "CANCELLED"];
306
+ };
307
+ readonly "fs.write": {
308
+ readonly params: z.ZodObject<{
309
+ path: z.ZodString;
310
+ content: z.ZodString;
311
+ encoding: z.ZodDefault<z.ZodEnum<{
312
+ utf8: "utf8";
313
+ base64: "base64";
314
+ }>>;
315
+ mode: z.ZodOptional<z.ZodInt>;
316
+ create_parents: z.ZodDefault<z.ZodBoolean>;
317
+ if_match_mtime_ms: z.ZodOptional<z.ZodInt>;
318
+ exclusive: z.ZodDefault<z.ZodBoolean>;
319
+ }, z.core.$strict>;
320
+ readonly result: z.ZodObject<{
321
+ path: z.ZodString;
322
+ size: z.ZodInt;
323
+ mtime_ms: z.ZodInt;
324
+ created: z.ZodBoolean;
325
+ }, z.core.$strict>;
326
+ readonly kind: "unary";
327
+ readonly since: "1.0";
328
+ readonly errors: readonly ["NOT_FOUND", "PERMISSION_DENIED_OS", "INVALID_PARAMS", "RESOURCE_BUSY", "INTERNAL", "CONFLICT", "PAYLOAD_TOO_LARGE"];
329
+ };
330
+ readonly "fs.mkdir": {
331
+ readonly params: z.ZodObject<{
332
+ path: z.ZodString;
333
+ parents: z.ZodDefault<z.ZodBoolean>;
334
+ }, z.core.$strict>;
335
+ readonly result: z.ZodObject<{
336
+ path: z.ZodString;
337
+ created: z.ZodBoolean;
338
+ }, z.core.$strict>;
339
+ readonly kind: "unary";
340
+ readonly since: "1.0";
341
+ readonly errors: readonly ["NOT_FOUND", "PERMISSION_DENIED_OS", "INVALID_PARAMS", "RESOURCE_BUSY", "INTERNAL", "CONFLICT"];
342
+ };
343
+ readonly "fs.move": {
344
+ readonly params: z.ZodObject<{
345
+ from_path: z.ZodString;
346
+ to_path: z.ZodString;
347
+ overwrite: z.ZodDefault<z.ZodBoolean>;
348
+ }, z.core.$strict>;
349
+ readonly result: z.ZodObject<{
350
+ from_path: z.ZodString;
351
+ to_path: z.ZodString;
352
+ }, z.core.$strict>;
353
+ readonly kind: "unary";
354
+ readonly since: "1.0";
355
+ readonly errors: readonly ["NOT_FOUND", "PERMISSION_DENIED_OS", "INVALID_PARAMS", "RESOURCE_BUSY", "INTERNAL", "CONFLICT"];
356
+ };
357
+ readonly "fs.delete": {
358
+ readonly params: z.ZodObject<{
359
+ path: z.ZodString;
360
+ recursive: z.ZodDefault<z.ZodBoolean>;
361
+ to_trash: z.ZodDefault<z.ZodBoolean>;
362
+ }, z.core.$strict>;
363
+ readonly result: z.ZodObject<{
364
+ deleted: z.ZodLiteral<true>;
365
+ trashed_to: z.ZodNullable<z.ZodString>;
366
+ }, z.core.$strict>;
367
+ readonly kind: "unary";
368
+ readonly since: "1.0";
369
+ readonly errors: readonly ["NOT_FOUND", "PERMISSION_DENIED_OS", "INVALID_PARAMS", "RESOURCE_BUSY", "INTERNAL"];
370
+ };
371
+ readonly "fs.watch": {
372
+ readonly params: z.ZodObject<{
373
+ path: z.ZodString;
374
+ recursive: z.ZodDefault<z.ZodBoolean>;
375
+ ignore: z.ZodDefault<z.ZodArray<z.ZodString>>;
376
+ debounce_ms: z.ZodDefault<z.ZodInt>;
377
+ }, z.core.$strict>;
378
+ readonly result: z.ZodObject<{
379
+ resource_id: z.ZodString;
380
+ path: z.ZodString;
381
+ }, z.core.$strict>;
382
+ readonly kind: "resource";
383
+ readonly since: "1.0";
384
+ readonly errors: readonly ["NOT_FOUND", "PERMISSION_DENIED_OS", "INVALID_PARAMS", "RESOURCE_BUSY", "INTERNAL", "RATE_LIMITED"];
385
+ };
386
+ readonly "fs.patch": {
387
+ readonly params: z.ZodObject<{
388
+ path: z.ZodString;
389
+ edits: z.ZodArray<z.ZodObject<{
390
+ old_text: z.ZodString;
391
+ new_text: z.ZodString;
392
+ replace_all: z.ZodDefault<z.ZodBoolean>;
393
+ }, z.core.$strict>>;
394
+ create_if_missing: z.ZodDefault<z.ZodBoolean>;
395
+ }, z.core.$strict>;
396
+ readonly result: z.ZodObject<{
397
+ path: z.ZodString;
398
+ applied: z.ZodInt;
399
+ size: z.ZodInt;
400
+ mtime_ms: z.ZodInt;
401
+ }, z.core.$strict>;
402
+ readonly kind: "unary";
403
+ readonly since: "1.0";
404
+ readonly errors: readonly ["NOT_FOUND", "PERMISSION_DENIED_OS", "INVALID_PARAMS", "RESOURCE_BUSY", "INTERNAL", "CONFLICT"];
405
+ };
406
+ readonly "fs.search_paths": {
407
+ readonly params: z.ZodObject<{
408
+ pattern: z.ZodString;
409
+ cwd: z.ZodString;
410
+ hidden: z.ZodDefault<z.ZodBoolean>;
411
+ max_results: z.ZodDefault<z.ZodInt>;
412
+ }, z.core.$strict>;
413
+ readonly result: z.ZodObject<{
414
+ paths: z.ZodArray<z.ZodString>;
415
+ truncated: z.ZodBoolean;
416
+ }, z.core.$strict>;
417
+ readonly kind: "unary";
418
+ readonly since: "1.0";
419
+ readonly errors: readonly ["NOT_FOUND", "PERMISSION_DENIED_OS", "INVALID_PARAMS", "RESOURCE_BUSY", "INTERNAL", "TIMEOUT"];
420
+ };
421
+ readonly "fs.search_content": {
422
+ readonly params: z.ZodObject<{
423
+ query: z.ZodString;
424
+ cwd: z.ZodString;
425
+ regex: z.ZodDefault<z.ZodBoolean>;
426
+ case_sensitive: z.ZodDefault<z.ZodBoolean>;
427
+ include: z.ZodOptional<z.ZodArray<z.ZodString>>;
428
+ exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
429
+ max_results: z.ZodDefault<z.ZodInt>;
430
+ }, z.core.$strict>;
431
+ readonly result: z.ZodObject<{
432
+ results: z.ZodArray<z.ZodObject<{
433
+ path: z.ZodString;
434
+ lines: z.ZodString;
435
+ line_number: z.ZodInt;
436
+ submatches: z.ZodArray<z.ZodObject<{
437
+ match: z.ZodString;
438
+ start: z.ZodInt;
439
+ end: z.ZodInt;
440
+ }, z.core.$strict>>;
441
+ }, z.core.$strict>>;
442
+ truncated: z.ZodBoolean;
443
+ }, z.core.$strict>;
444
+ readonly kind: "unary";
445
+ readonly since: "1.0";
446
+ readonly errors: readonly ["NOT_FOUND", "PERMISSION_DENIED_OS", "INVALID_PARAMS", "RESOURCE_BUSY", "INTERNAL", "TIMEOUT"];
447
+ };
448
+ readonly "exec.pty.start": {
449
+ readonly params: z.ZodObject<{
450
+ cols: z.ZodInt;
451
+ rows: z.ZodInt;
452
+ cwd: z.ZodOptional<z.ZodString>;
453
+ shell: z.ZodOptional<z.ZodString>;
454
+ args: z.ZodOptional<z.ZodArray<z.ZodString>>;
455
+ env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
456
+ name: z.ZodOptional<z.ZodString>;
457
+ window_bytes: z.ZodOptional<z.ZodInt>;
458
+ }, z.core.$strict>;
459
+ readonly result: z.ZodObject<{
460
+ resource_id: z.ZodString;
461
+ pid: z.ZodInt;
462
+ shell: z.ZodString;
463
+ cwd: z.ZodString;
464
+ title: z.ZodString;
465
+ name: z.ZodNullable<z.ZodString>;
466
+ cols: z.ZodInt;
467
+ rows: z.ZodInt;
468
+ state: z.ZodEnum<{
469
+ running: "running";
470
+ exited: "exited";
471
+ }>;
472
+ exit_code: z.ZodNullable<z.ZodInt>;
473
+ exit_signal: z.ZodNullable<z.ZodEnum<{
474
+ SIGINT: "SIGINT";
475
+ SIGTERM: "SIGTERM";
476
+ SIGKILL: "SIGKILL";
477
+ SIGHUP: "SIGHUP";
478
+ SIGQUIT: "SIGQUIT";
479
+ SIGTSTP: "SIGTSTP";
480
+ SIGCONT: "SIGCONT";
481
+ SIGUSR1: "SIGUSR1";
482
+ SIGUSR2: "SIGUSR2";
483
+ }>>;
484
+ last_seq: z.ZodInt;
485
+ created_at_ms: z.ZodInt;
486
+ controller_client_id: z.ZodNullable<z.ZodString>;
487
+ attached_clients: z.ZodInt;
488
+ orphan_expires_at_ms: z.ZodNullable<z.ZodInt>;
489
+ }, z.core.$strict>;
490
+ readonly kind: "resource";
491
+ readonly since: "1.0";
492
+ readonly errors: readonly ["INVALID_PARAMS", "NOT_FOUND", "RATE_LIMITED", "PLATFORM_UNSUPPORTED", "INTERNAL"];
493
+ };
494
+ readonly "exec.pty.write": {
495
+ readonly params: z.ZodObject<{
496
+ resource_id: z.ZodString;
497
+ data: z.ZodString;
498
+ }, z.core.$strict>;
499
+ readonly result: z.ZodObject<{
500
+ written: z.ZodInt;
501
+ }, z.core.$strict>;
502
+ readonly kind: "unary";
503
+ readonly since: "1.0";
504
+ readonly errors: readonly ["RESOURCE_GONE", "AUTH_FORBIDDEN", "INVALID_PARAMS"];
505
+ };
506
+ readonly "exec.pty.resize": {
507
+ readonly params: z.ZodObject<{
508
+ resource_id: z.ZodString;
509
+ cols: z.ZodInt;
510
+ rows: z.ZodInt;
511
+ }, z.core.$strict>;
512
+ readonly result: z.ZodObject<{
513
+ cols: z.ZodInt;
514
+ rows: z.ZodInt;
515
+ }, z.core.$strict>;
516
+ readonly kind: "unary";
517
+ readonly since: "1.0";
518
+ readonly errors: readonly ["RESOURCE_GONE", "AUTH_FORBIDDEN"];
519
+ };
520
+ readonly "exec.pty.signal": {
521
+ readonly params: z.ZodObject<{
522
+ resource_id: z.ZodString;
523
+ signal: z.ZodEnum<{
524
+ SIGINT: "SIGINT";
525
+ SIGTERM: "SIGTERM";
526
+ SIGKILL: "SIGKILL";
527
+ SIGHUP: "SIGHUP";
528
+ SIGQUIT: "SIGQUIT";
529
+ SIGTSTP: "SIGTSTP";
530
+ SIGCONT: "SIGCONT";
531
+ SIGUSR1: "SIGUSR1";
532
+ SIGUSR2: "SIGUSR2";
533
+ }>;
534
+ }, z.core.$strict>;
535
+ readonly result: z.ZodObject<{
536
+ delivered: z.ZodBoolean;
537
+ }, z.core.$strict>;
538
+ readonly kind: "unary";
539
+ readonly since: "1.0";
540
+ readonly errors: readonly ["RESOURCE_GONE", "AUTH_FORBIDDEN", "PLATFORM_UNSUPPORTED"];
541
+ };
542
+ readonly "exec.pty.kill": {
543
+ readonly params: z.ZodObject<{
544
+ resource_id: z.ZodString;
545
+ grace_ms: z.ZodDefault<z.ZodInt>;
546
+ }, z.core.$strict>;
547
+ readonly result: z.ZodObject<{
548
+ exit_code: z.ZodNullable<z.ZodInt>;
549
+ exit_signal: z.ZodNullable<z.ZodEnum<{
550
+ SIGINT: "SIGINT";
551
+ SIGTERM: "SIGTERM";
552
+ SIGKILL: "SIGKILL";
553
+ SIGHUP: "SIGHUP";
554
+ SIGQUIT: "SIGQUIT";
555
+ SIGTSTP: "SIGTSTP";
556
+ SIGCONT: "SIGCONT";
557
+ SIGUSR1: "SIGUSR1";
558
+ SIGUSR2: "SIGUSR2";
559
+ }>>;
560
+ }, z.core.$strict>;
561
+ readonly kind: "unary";
562
+ readonly since: "1.0";
563
+ readonly errors: readonly ["RESOURCE_GONE", "AUTH_FORBIDDEN"];
564
+ };
565
+ readonly "exec.list": {
566
+ readonly params: z.ZodObject<{}, z.core.$strict>;
567
+ readonly result: z.ZodObject<{
568
+ sessions: z.ZodArray<z.ZodObject<{
569
+ resource_id: z.ZodString;
570
+ pid: z.ZodInt;
571
+ shell: z.ZodString;
572
+ cwd: z.ZodString;
573
+ title: z.ZodString;
574
+ name: z.ZodNullable<z.ZodString>;
575
+ cols: z.ZodInt;
576
+ rows: z.ZodInt;
577
+ state: z.ZodEnum<{
578
+ running: "running";
579
+ exited: "exited";
580
+ }>;
581
+ exit_code: z.ZodNullable<z.ZodInt>;
582
+ exit_signal: z.ZodNullable<z.ZodEnum<{
583
+ SIGINT: "SIGINT";
584
+ SIGTERM: "SIGTERM";
585
+ SIGKILL: "SIGKILL";
586
+ SIGHUP: "SIGHUP";
587
+ SIGQUIT: "SIGQUIT";
588
+ SIGTSTP: "SIGTSTP";
589
+ SIGCONT: "SIGCONT";
590
+ SIGUSR1: "SIGUSR1";
591
+ SIGUSR2: "SIGUSR2";
592
+ }>>;
593
+ last_seq: z.ZodInt;
594
+ created_at_ms: z.ZodInt;
595
+ controller_client_id: z.ZodNullable<z.ZodString>;
596
+ attached_clients: z.ZodInt;
597
+ orphan_expires_at_ms: z.ZodNullable<z.ZodInt>;
598
+ }, z.core.$strict>>;
599
+ }, z.core.$strict>;
600
+ readonly kind: "unary";
601
+ readonly since: "1.0";
602
+ readonly errors: readonly ["INTERNAL"];
603
+ };
604
+ readonly "exec.run": {
605
+ readonly params: z.ZodObject<{
606
+ command: z.ZodString;
607
+ cwd: z.ZodOptional<z.ZodString>;
608
+ cwd_key: z.ZodOptional<z.ZodString>;
609
+ env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
610
+ stdin: z.ZodOptional<z.ZodString>;
611
+ timeout: z.ZodDefault<z.ZodInt>;
612
+ max_output_bytes: z.ZodDefault<z.ZodInt>;
613
+ }, z.core.$strict>;
614
+ readonly result: z.ZodObject<{
615
+ exit_code: z.ZodInt;
616
+ stdout: z.ZodString;
617
+ stderr: z.ZodString;
618
+ cwd: z.ZodString;
619
+ duration_ms: z.ZodInt;
620
+ timed_out: z.ZodBoolean;
621
+ output_truncated: z.ZodBoolean;
622
+ }, z.core.$strict>;
623
+ readonly kind: "unary";
624
+ readonly since: "1.0";
625
+ readonly errors: readonly ["INVALID_PARAMS", "NOT_FOUND", "TIMEOUT", "CANCELLED", "INTERNAL"];
626
+ };
627
+ readonly "session.attach": {
628
+ readonly params: z.ZodObject<{
629
+ resource_id: z.ZodString;
630
+ mode: z.ZodDefault<z.ZodEnum<{
631
+ control: "control";
632
+ read_only: "read_only";
633
+ }>>;
634
+ since_seq: z.ZodOptional<z.ZodInt>;
635
+ window_bytes: z.ZodOptional<z.ZodInt>;
636
+ }, z.core.$strict>;
637
+ readonly result: z.ZodDiscriminatedUnion<[z.ZodObject<{
638
+ kind: z.ZodLiteral<"pty">;
639
+ pty: z.ZodObject<{
640
+ resource_id: z.ZodString;
641
+ pid: z.ZodInt;
642
+ shell: z.ZodString;
643
+ cwd: z.ZodString;
644
+ title: z.ZodString;
645
+ name: z.ZodNullable<z.ZodString>;
646
+ cols: z.ZodInt;
647
+ rows: z.ZodInt;
648
+ state: z.ZodEnum<{
649
+ running: "running";
650
+ exited: "exited";
651
+ }>;
652
+ exit_code: z.ZodNullable<z.ZodInt>;
653
+ exit_signal: z.ZodNullable<z.ZodEnum<{
654
+ SIGINT: "SIGINT";
655
+ SIGTERM: "SIGTERM";
656
+ SIGKILL: "SIGKILL";
657
+ SIGHUP: "SIGHUP";
658
+ SIGQUIT: "SIGQUIT";
659
+ SIGTSTP: "SIGTSTP";
660
+ SIGCONT: "SIGCONT";
661
+ SIGUSR1: "SIGUSR1";
662
+ SIGUSR2: "SIGUSR2";
663
+ }>>;
664
+ last_seq: z.ZodInt;
665
+ created_at_ms: z.ZodInt;
666
+ controller_client_id: z.ZodNullable<z.ZodString>;
667
+ attached_clients: z.ZodInt;
668
+ orphan_expires_at_ms: z.ZodNullable<z.ZodInt>;
669
+ }, z.core.$strict>;
670
+ }, z.core.$strict>, z.ZodObject<{
671
+ kind: z.ZodLiteral<"watch">;
672
+ resource_id: z.ZodString;
673
+ path: z.ZodString;
674
+ orphan_expires_at_ms: z.ZodNullable<z.ZodInt>;
675
+ }, z.core.$strict>], "kind">;
676
+ readonly kind: "stream";
677
+ readonly since: "1.0";
678
+ readonly errors: readonly ["RESOURCE_GONE", "AUTH_FORBIDDEN", "RESOURCE_BUSY"];
679
+ };
680
+ readonly "session.detach": {
681
+ readonly params: z.ZodObject<{
682
+ resource_id: z.ZodString;
683
+ }, z.core.$strict>;
684
+ readonly result: z.ZodObject<{
685
+ orphan_expires_at_ms: z.ZodNullable<z.ZodInt>;
686
+ }, z.core.$strict>;
687
+ readonly kind: "unary";
688
+ readonly since: "1.0";
689
+ readonly errors: readonly ["RESOURCE_GONE"];
690
+ };
691
+ readonly "session.release": {
692
+ readonly params: z.ZodObject<{
693
+ resource_id: z.ZodString;
694
+ }, z.core.$strict>;
695
+ readonly result: z.ZodObject<{
696
+ released: z.ZodLiteral<true>;
697
+ }, z.core.$strict>;
698
+ readonly kind: "unary";
699
+ readonly since: "1.0";
700
+ readonly errors: readonly ["RESOURCE_GONE", "AUTH_FORBIDDEN"];
701
+ };
702
+ readonly "session.list": {
703
+ readonly params: z.ZodObject<{}, z.core.$strict>;
704
+ readonly result: z.ZodObject<{
705
+ resources: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
706
+ kind: z.ZodLiteral<"pty">;
707
+ pty: z.ZodObject<{
708
+ resource_id: z.ZodString;
709
+ pid: z.ZodInt;
710
+ shell: z.ZodString;
711
+ cwd: z.ZodString;
712
+ title: z.ZodString;
713
+ name: z.ZodNullable<z.ZodString>;
714
+ cols: z.ZodInt;
715
+ rows: z.ZodInt;
716
+ state: z.ZodEnum<{
717
+ running: "running";
718
+ exited: "exited";
719
+ }>;
720
+ exit_code: z.ZodNullable<z.ZodInt>;
721
+ exit_signal: z.ZodNullable<z.ZodEnum<{
722
+ SIGINT: "SIGINT";
723
+ SIGTERM: "SIGTERM";
724
+ SIGKILL: "SIGKILL";
725
+ SIGHUP: "SIGHUP";
726
+ SIGQUIT: "SIGQUIT";
727
+ SIGTSTP: "SIGTSTP";
728
+ SIGCONT: "SIGCONT";
729
+ SIGUSR1: "SIGUSR1";
730
+ SIGUSR2: "SIGUSR2";
731
+ }>>;
732
+ last_seq: z.ZodInt;
733
+ created_at_ms: z.ZodInt;
734
+ controller_client_id: z.ZodNullable<z.ZodString>;
735
+ attached_clients: z.ZodInt;
736
+ orphan_expires_at_ms: z.ZodNullable<z.ZodInt>;
737
+ }, z.core.$strict>;
738
+ }, z.core.$strict>, z.ZodObject<{
739
+ kind: z.ZodLiteral<"watch">;
740
+ resource_id: z.ZodString;
741
+ path: z.ZodString;
742
+ orphan_expires_at_ms: z.ZodNullable<z.ZodInt>;
743
+ }, z.core.$strict>], "kind">>;
744
+ }, z.core.$strict>;
745
+ readonly kind: "unary";
746
+ readonly since: "1.0";
747
+ readonly errors: readonly ["INTERNAL"];
748
+ };
749
+ };
750
+ type OpName = keyof typeof OPS;
751
+ type OpParams<N extends OpName> = z.input<(typeof OPS)[N]["params"]>;
752
+ type OpResult<N extends OpName> = z.output<(typeof OPS)[N]["result"]>;
753
+ declare const EVENTS: {
754
+ readonly "fs.changed": z.ZodObject<{
755
+ changes: z.ZodArray<z.ZodObject<{
756
+ type: z.ZodEnum<{
757
+ created: "created";
758
+ deleted: "deleted";
759
+ modified: "modified";
760
+ moved: "moved";
761
+ }>;
762
+ path: z.ZodString;
763
+ to_path: z.ZodOptional<z.ZodString>;
764
+ kind: z.ZodEnum<{
765
+ unknown: "unknown";
766
+ file: "file";
767
+ dir: "dir";
768
+ symlink: "symlink";
769
+ }>;
770
+ }, z.core.$strict>>;
771
+ overflow: z.ZodBoolean;
772
+ }, z.core.$strict>;
773
+ readonly "exec.exited": z.ZodObject<{
774
+ exit_code: z.ZodNullable<z.ZodInt>;
775
+ exit_signal: z.ZodNullable<z.ZodEnum<{
776
+ SIGINT: "SIGINT";
777
+ SIGTERM: "SIGTERM";
778
+ SIGKILL: "SIGKILL";
779
+ SIGHUP: "SIGHUP";
780
+ SIGQUIT: "SIGQUIT";
781
+ SIGTSTP: "SIGTSTP";
782
+ SIGCONT: "SIGCONT";
783
+ SIGUSR1: "SIGUSR1";
784
+ SIGUSR2: "SIGUSR2";
785
+ }>>;
786
+ }, z.core.$strict>;
787
+ readonly "exec.title": z.ZodObject<{
788
+ title: z.ZodString;
789
+ }, z.core.$strict>;
790
+ readonly "exec.cwd": z.ZodObject<{
791
+ cwd: z.ZodString;
792
+ }, z.core.$strict>;
793
+ readonly "session.control_changed": z.ZodObject<{
794
+ controller_client_id: z.ZodNullable<z.ZodString>;
795
+ your_mode: z.ZodEnum<{
796
+ control: "control";
797
+ read_only: "read_only";
798
+ }>;
799
+ }, z.core.$strict>;
800
+ readonly "relay.device_status": z.ZodObject<{
801
+ online: z.ZodBoolean;
802
+ since_ms: z.ZodInt;
803
+ app_version: z.ZodNullable<z.ZodString>;
804
+ protocol_version: z.ZodNullable<z.ZodString>;
805
+ }, z.core.$strict>;
806
+ readonly "relay.auth_expiring": z.ZodObject<{
807
+ expires_at_ms: z.ZodInt;
808
+ }, z.core.$strict>;
809
+ };
810
+
811
+ type DesktopClientStatus =
812
+ /** Constructed, connect() not called yet. */
813
+ "idle"
814
+ /** Socket opening. */
815
+ | "connecting"
816
+ /** Socket open, hello sent, waiting for Welcome. */
817
+ | "handshaking"
818
+ /** Welcome received — requests flow. */
819
+ | "open"
820
+ /** Dropped; a reconnect is scheduled (see `retryInMs`). */
821
+ | "reconnecting"
822
+ /** Closed for good: close() was called, or the device/server refused us (see `lastError`). */
823
+ | "closed";
824
+ interface DesktopClientState {
825
+ status: DesktopClientStatus;
826
+ welcome: Welcome | null;
827
+ /** Consecutive failed connection attempts since the last stable connection. */
828
+ attempts: number;
829
+ /** Delay before the scheduled reconnect, while `status === "reconnecting"`. */
830
+ retryInMs: number | null;
831
+ lastError: DesktopProtocolError | null;
832
+ lastCloseCode: number | null;
833
+ }
834
+ interface RequestOptions {
835
+ signal?: AbortSignal;
836
+ timeoutMs?: number;
837
+ }
838
+ type StreamOpName = {
839
+ [N in OpName]: (typeof OPS)[N]["kind"] extends "unary" ? never : N;
840
+ }[OpName];
841
+ type EventName = keyof typeof EVENTS;
842
+ type EventPayload<E extends EventName> = z.output<(typeof EVENTS)[E]>;
843
+ type EventHandler<E extends EventName> = (payload: EventPayload<E>, resourceId: string | undefined) => void;
844
+ interface StreamHandlers {
845
+ /** DATA / STDERR bytes. Credit is granted only after this returns (or its promise settles) — backpressure. */
846
+ onData?: (payload: Uint8Array, header: FrameHeader) => void | Promise<void>;
847
+ /** SNAPSHOT bytes (a serialized screen after a gap). */
848
+ onSnapshot?: (payload: Uint8Array, header: FrameHeader) => void | Promise<void>;
849
+ /** open / gap / snapshot announcements, including the ones after a reattach. */
850
+ onMeta?: (meta: StreamMeta) => void;
851
+ /** Called after a transparent reattach (the stream is live again on a new sid). */
852
+ onReattached?: () => void;
853
+ }
854
+ interface StreamOptions extends RequestOptions {
855
+ /** Receive window in payload bytes (default: the core's limits.default_window_bytes). */
856
+ windowBytes?: number;
857
+ /** Reattach mode for resource streams. Default "control". */
858
+ mode?: "control" | "read_only";
859
+ }
860
+ interface DesktopStream<N extends StreamOpName> {
861
+ /** The CURRENT request id carrying this stream (changes on reattach). */
862
+ readonly id: string;
863
+ /** The unary result that precedes the stream (PtyInfo, FsReadStreamResult, ResourceInfo…). */
864
+ readonly result: Promise<OpResult<N>>;
865
+ /** Settles when the stream ends for good: resolves with the end reason, rejects on error. */
866
+ readonly done: Promise<EndReason>;
867
+ /** The resource this stream belongs to (pty_…/watch_…), once known. Resource streams survive reconnects. */
868
+ readonly resourceId: string | null;
869
+ /** Seq of the last DATA frame delivered to onData — sent as since_seq on reattach. */
870
+ readonly lastSeq: number;
871
+ /** Send STDIN bytes (UTF-8 for strings), chunked and credit-gated. */
872
+ write(data: Uint8Array | string): void;
873
+ /** Cancel the request (core ends the stream with reason "cancelled"). */
874
+ cancel(): void;
875
+ /** Leave the resource running on the device and stop following it (session.detach). */
876
+ detach(): Promise<void>;
877
+ }
878
+ interface DesktopClient {
879
+ connect(): void;
880
+ /** Close for good (no reconnect). Pending work rejects with CANCELLED. */
881
+ close(): void;
882
+ getState(): DesktopClientState;
883
+ /** useSyncExternalStore-shaped. */
884
+ subscribe(listener: () => void): () => void;
885
+ /** Resolves with the Welcome once open (immediately if already open). */
886
+ ready(options?: RequestOptions): Promise<Welcome>;
887
+ request<N extends OpName>(op: N, params: OpParams<N>, options?: RequestOptions): Promise<OpResult<N>>;
888
+ stream<N extends StreamOpName>(op: N, params: OpParams<N>, handlers?: StreamHandlers, options?: StreamOptions): DesktopStream<N>;
889
+ on<E extends EventName>(name: E, handler: EventHandler<E>): () => void;
890
+ /** Hand the relay a fresh token without dropping the socket. */
891
+ reauth(token: string): void;
892
+ }
893
+
894
+ declare function DesktopClientProvider(props: {
895
+ client: DesktopClient;
896
+ children?: ReactNode;
897
+ }): ReactNode;
898
+ /** The client from the nearest provider (or the one passed in). Throws when there is neither. */
899
+ declare function useDesktopClient(client?: DesktopClient): DesktopClient;
900
+ /** Live connection state (status, welcome, attempts, retryInMs, lastError). Connects on mount when idle. */
901
+ declare function useDesktopConnection(client?: DesktopClient): DesktopClientState;
902
+ interface DesktopRequestState<N extends OpName> {
903
+ data: OpResult<N> | undefined;
904
+ error: DesktopProtocolError | undefined;
905
+ loading: boolean;
906
+ /** Re-run now; resolves with the fresh result. */
907
+ refetch: () => Promise<OpResult<N> | undefined>;
908
+ }
909
+ interface UseDesktopRequestOptions extends Omit<RequestOptions, "signal"> {
910
+ /** Default true. False = do not run until refetch() or enabled flips true. */
911
+ enabled?: boolean;
912
+ client?: DesktopClient;
913
+ }
914
+ /**
915
+ * Run a unary op and keep its latest result. Re-runs when `op` or the params' JSON changes, and
916
+ * after a reconnect if the last attempt failed with a retryable error. Aborts on unmount.
917
+ */
918
+ declare function useDesktopRequest<N extends OpName>(op: N, params: OpParams<N>, options?: UseDesktopRequestOptions): DesktopRequestState<N>;
919
+ /** Subscribe to one protocol event (fs.changed, exec.exited, relay.device_status, …) for the component's life. */
920
+ declare function useDesktopEvent<E extends EventName>(name: E, handler: EventHandler<E>, options?: {
921
+ client?: DesktopClient;
922
+ }): void;
923
+
924
+ export { DesktopClientProvider, type DesktopRequestState, type UseDesktopRequestOptions, useDesktopClient, useDesktopConnection, useDesktopEvent, useDesktopRequest };