@bun-native/protocol 0.33.1 → 0.33.2

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,789 @@
1
+ // @generated by scripts/protocol/schema.ts from packages/protocol/schema/wire.json. Do not edit: change the schema and run `bun run generate:schema`.
2
+
3
+ export const PROTOCOL_VERSION = 12
4
+ /**
5
+ * Largest command frame (Bun to host) in UTF-8 JSON bytes, excluding the newline. One transaction
6
+ * is one batch, so this bounds a full-window mount: at most `MAX_OPERATIONS` operations plus
7
+ * `MAX_TEXT_BYTES_PER_WINDOW` of text, which JSON escaping can double.
8
+ */
9
+ export const MAX_FRAME_BYTES = 16_777_216
10
+ /**
11
+ * Largest event frame (host to Bun). Events carry at most one text value or one bounded service
12
+ * result, never a tree.
13
+ */
14
+ export const MAX_EVENT_FRAME_BYTES = 65_536
15
+ export const MAX_TEXT_BYTES = 16_384
16
+ const MAX_TEXT_BYTES_PER_WINDOW = 4_194_304
17
+ export const MAX_TITLE_BYTES = 256
18
+ /**
19
+ * Operations in one batch: four per node of a full window, so a whole-window replacement (deletes,
20
+ * creates, inserts and sets) fits one batch.
21
+ */
22
+ export const MAX_OPERATIONS = 16_384
23
+ export const MAX_NODES_PER_WINDOW = 4_096
24
+ const MAX_WINDOWS = 16
25
+ /** Tree edges from a window root to its deepest node. */
26
+ const MAX_DEPTH = 64
27
+ /**
28
+ * Node identities in a routed event path: the target and each ancestor up to the window root, so
29
+ * `MAX_DEPTH + 1`.
30
+ */
31
+ export const MAX_EVENT_PATH_NODES = 65
32
+ /**
33
+ * Overlays nested inside overlays, the outermost counting as one. The host lays out each nested
34
+ * layer in its own bounded prepaint round.
35
+ */
36
+ export const MAX_OVERLAY_DEPTH = 8
37
+ /** Largest programmatic scroll offset, in logical pixels from the content start. */
38
+ export const MAX_SCROLL_OFFSET = 1_000_000
39
+ /** Main-axis thickness of the host-drawn split divider, in logical pixels. */
40
+ export const SPLIT_DIVIDER = 6
41
+ /** The largest `accessible_set_size` and `accessible_position`. */
42
+ export const MAX_ACCESSIBLE_SET_SIZE = 2_147_483_647
43
+ /** UTF-8 bytes of a key event's `key` and `key_char`. */
44
+ export const MAX_KEY_BYTES = 256
45
+ /** Largest pointer or context menu coordinate magnitude, in logical pixels. */
46
+ export const MAX_POINTER_COORDINATE = 1_048_576
47
+ /** Largest display origin magnitude and display size, in logical pixels. */
48
+ export const MAX_DISPLAY_COORDINATE = 1_048_576
49
+ /** Worst-case JSON escaping still leaves room within the event frame. */
50
+ export const MAX_CLIPBOARD_BYTES = 8_192
51
+ const MAX_SERVICE_REQUESTS = 8
52
+ export const MAX_GLOBAL_SHORTCUTS = 16
53
+ export const MAX_NOTIFICATIONS = 32
54
+ export const MAX_NOTIFICATION_TITLE_BYTES = 256
55
+ export const MAX_NOTIFICATION_BODY_BYTES = 2_048
56
+ export const MAX_FILESYSTEM_ROOTS = 8
57
+ /**
58
+ * Filesystem root and process executable identifiers: lowercase ASCII letters, digits, `-` and `_`,
59
+ * starting with a letter.
60
+ */
61
+ export const MAX_ROOT_ID_BYTES = 32
62
+ export const MAX_FILE_GRANTS = 32
63
+ export const MAX_ROOT_PATH_BYTES = 4_096
64
+ export const MAX_FILE_PATH_BYTES = 1_024
65
+ export const MAX_FILE_PATH_COMPONENTS = 32
66
+ export const MAX_FILE_NAME_BYTES = 255
67
+ export const MAX_FILE_CHUNK_BYTES = 16_384
68
+ export const MAX_DIRECTORY_ENTRIES = 64
69
+ export const MAX_PROCESS_EXECUTABLES = 8
70
+ export const MAX_PROCESSES = 8
71
+ export const MAX_PROCESS_ARGS = 64
72
+ export const MAX_PROCESS_ARG_BYTES = 4_096
73
+ export const MAX_PROCESS_ENV = 64
74
+ export const MAX_PROCESS_ENV_NAME_BYTES = 128
75
+ export const MAX_PROCESS_ENV_VALUE_BYTES = 4_096
76
+ /** Combined bytes of arguments and environment, well below the frame cap. */
77
+ export const MAX_PROCESS_LAUNCH_BYTES = 32_768
78
+ /** Output chunks a process may have delivered but not yet acknowledged. */
79
+ export const MAX_PROCESS_OUTPUT_CREDIT = 4
80
+ export const MAX_TERMINAL_DIMENSION = 1_000
81
+ /** Bounds of the optional per-executable resource limits. */
82
+ export const MAX_PROCESS_CPU_SECONDS = 604_800
83
+ export const MIN_PROCESS_MEMORY_BYTES = 1_048_576
84
+ export const MAX_PROCESS_MEMORY_BYTES = 281_474_976_710_656
85
+ export const MIN_PROCESS_OPEN_FILES = 3
86
+ export const MAX_PROCESS_OPEN_FILES = 1_048_576
87
+ /** Live file dialogs per session. Each window owns at most one at a time. */
88
+ export const MAX_FILE_DIALOGS = 16
89
+ export const MAX_DIALOG_TITLE_BYTES = 256
90
+ export const MAX_DIALOG_LABEL_BYTES = 64
91
+ export const MAX_DIALOG_PATH_BYTES = 4_096
92
+ export const MAX_DIALOG_NAME_BYTES = 255
93
+ export const MAX_DIALOG_FILTERS = 16
94
+ export const MAX_DIALOG_FILTER_PATTERNS = 16
95
+ export const MAX_DIALOG_FILTER_NAME_BYTES = 128
96
+ export const MAX_DIALOG_PATTERN_BYTES = 64
97
+ /** Selected paths in one result. The whole result must also fit one frame. */
98
+ export const MAX_DIALOG_PATHS = 256
99
+ export const MAX_MESSAGE_DIALOG_BUTTONS = 4
100
+ export const MAX_MESSAGE_DIALOG_TITLE_BYTES = 256
101
+ export const MAX_MESSAGE_DIALOG_MESSAGE_BYTES = 2_048
102
+ export const MAX_MESSAGE_DIALOG_DETAIL_BYTES = 4_096
103
+ export const MAX_MESSAGE_DIALOG_LABEL_BYTES = 64
104
+ export const MAX_MESSAGE_DIALOG_ID_BYTES = 64
105
+ /** Live drop targets across a session. */
106
+ export const MAX_DROP_TARGETS = 32
107
+ /** Items one drop may deliver. A larger drop is rejected, never truncated. */
108
+ export const MAX_DROP_ITEMS = 64
109
+ /** UTF-8 bytes of one untrusted display name. */
110
+ export const MAX_DROP_NAME_BYTES = 255
111
+ /** Top-level menus in one menu bar. */
112
+ export const MAX_APP_MENUS = 16
113
+ /** Items, separators and submenus in one menu bar, at every depth. */
114
+ export const MAX_APP_MENU_ENTRIES = 128
115
+ /** A top-level menu is depth 1; submenus nest at most two levels below it. */
116
+ export const MAX_APP_MENU_DEPTH = 3
117
+ export const MAX_APP_MENU_LABEL_BYTES = 64
118
+ /** An application menu item identifier, `[A-Za-z0-9._:-]`. */
119
+ export const MAX_APP_MENU_ITEM_ID_BYTES = 64
120
+
121
+ export interface Limits {
122
+ max_frame_bytes: number
123
+ max_operations: number
124
+ max_nodes_per_window: number
125
+ max_windows: number
126
+ max_depth: number
127
+ max_text_bytes: number
128
+ max_text_bytes_per_window: number
129
+ max_clipboard_bytes: number
130
+ max_service_requests: number
131
+ max_global_shortcuts: number
132
+ max_notifications: number
133
+ max_file_grants: number
134
+ max_file_chunk_bytes: number
135
+ max_processes: number
136
+ max_drop_targets: number
137
+ max_drop_items: number
138
+ }
139
+
140
+ export const DEFAULT_LIMITS: Readonly<Limits> = Object.freeze({
141
+ max_frame_bytes: MAX_FRAME_BYTES,
142
+ max_operations: MAX_OPERATIONS,
143
+ max_nodes_per_window: MAX_NODES_PER_WINDOW,
144
+ max_windows: MAX_WINDOWS,
145
+ max_depth: MAX_DEPTH,
146
+ max_text_bytes: MAX_TEXT_BYTES,
147
+ max_text_bytes_per_window: MAX_TEXT_BYTES_PER_WINDOW,
148
+ max_clipboard_bytes: MAX_CLIPBOARD_BYTES,
149
+ max_service_requests: MAX_SERVICE_REQUESTS,
150
+ max_global_shortcuts: MAX_GLOBAL_SHORTCUTS,
151
+ max_notifications: MAX_NOTIFICATIONS,
152
+ max_file_grants: MAX_FILE_GRANTS,
153
+ max_file_chunk_bytes: MAX_FILE_CHUNK_BYTES,
154
+ max_processes: MAX_PROCESSES,
155
+ max_drop_targets: MAX_DROP_TARGETS,
156
+ max_drop_items: MAX_DROP_ITEMS,
157
+ })
158
+
159
+ export type Direction = 'row' | 'column'
160
+
161
+ export type AlignItems = 'start' | 'center' | 'end' | 'stretch'
162
+
163
+ export type JustifyContent =
164
+ | 'start'
165
+ | 'center'
166
+ | 'end'
167
+ | 'space_between'
168
+ | 'space_around'
169
+ | 'space_evenly'
170
+
171
+ export type Overflow = 'visible' | 'hidden' | 'scroll_x' | 'scroll_y' | 'scroll'
172
+
173
+ /** Which edge a vertical scroll viewport keeps visible as its content changes. */
174
+ export type ScrollAnchor = 'start' | 'end'
175
+
176
+ /** Where an overlay's layer is placed. */
177
+ export const OVERLAY_ANCHORS = Object.freeze([
178
+ /** A layer covering the whole window viewport, blocking pointer input beneath it. */
179
+ 'window',
180
+ /** A content-sized layer below its parent's bottom-left corner, kept inside the window. */
181
+ 'parent',
182
+ ] as const)
183
+ export type OverlayAnchor = (typeof OVERLAY_ANCHORS)[number]
184
+
185
+ /** How arrow keys move focus among an overlay's own controls. */
186
+ export const OVERLAY_NAVIGATIONS = Object.freeze([
187
+ /** Only Tab and Shift-Tab move focus. */
188
+ 'tab',
189
+ /** Up/Down/Home/End move a roving focus and printable keys type ahead. */
190
+ 'menu',
191
+ ] as const)
192
+ export type OverlayNavigation = (typeof OVERLAY_NAVIGATIONS)[number]
193
+
194
+ /**
195
+ * What an overlay paints into. A `window` surface is an owned OS popup window: it may extend beyond
196
+ * its parent window and is kept on the display.
197
+ */
198
+ export const OVERLAY_SURFACES = Object.freeze([
199
+ /** A deferred GPUI layer inside the parent window. */
200
+ 'layer',
201
+ /** An owned popup window placed below its parent node in screen coordinates. */
202
+ 'window',
203
+ ] as const)
204
+ export type OverlaySurface = (typeof OVERLAY_SURFACES)[number]
205
+
206
+ /**
207
+ * `accessibility_lists_v1`: the role a box may declare. A box without one is layout only and has no
208
+ * accessible node.
209
+ */
210
+ export const ACCESSIBLE_ROLES = Object.freeze(['list', 'list_item'] as const)
211
+ export type AccessibleRole = (typeof ACCESSIBLE_ROLES)[number]
212
+
213
+ /** `accessibility_lists_v1`: how urgently a live text node is announced. */
214
+ export const LIVE_POLITENESS = Object.freeze(['polite', 'assertive'] as const)
215
+ export type Live = (typeof LIVE_POLITENESS)[number]
216
+
217
+ export const POINTER_BUTTONS = Object.freeze([
218
+ 'left',
219
+ 'right',
220
+ 'middle',
221
+ 'back',
222
+ 'forward',
223
+ ] as const)
224
+ export type PointerButton = (typeof POINTER_BUTTONS)[number]
225
+
226
+ /** Why the host asks the application to close a popup window overlay. */
227
+ export const DISMISS_REASONS = Object.freeze([
228
+ /** The popup's parent window stopped being the active window. */
229
+ 'window_blur',
230
+ ] as const)
231
+ export type DismissReason = (typeof DISMISS_REASONS)[number]
232
+
233
+ /** What moved a split divider (`split_resize_v1`). */
234
+ export const RESIZE_SOURCES = Object.freeze(['pointer', 'keyboard'] as const)
235
+ export type ResizeSource = (typeof RESIZE_SOURCES)[number]
236
+
237
+ export const ERROR_CODES = Object.freeze([
238
+ 'invalid_command',
239
+ 'version_mismatch',
240
+ 'invalid_state',
241
+ 'invalid_handle',
242
+ 'stale_revision',
243
+ 'limit_exceeded',
244
+ 'native_failure',
245
+ 'permission_denied',
246
+ 'service_unavailable',
247
+ 'cancelled',
248
+ 'operation_timed_out',
249
+ 'payload_too_large',
250
+ 'conflict',
251
+ 'not_found',
252
+ 'already_exists',
253
+ 'path_denied',
254
+ 'wrong_kind',
255
+ 'not_empty',
256
+ 'access_denied',
257
+ ] as const)
258
+ export type ErrorCode = (typeof ERROR_CODES)[number]
259
+
260
+ export const REQUIRED_CAPABILITIES = Object.freeze([
261
+ 'tree',
262
+ 'input_revisions',
263
+ 'layout_v1',
264
+ 'interactions_v1',
265
+ 'window_display_v1',
266
+ ] as const)
267
+ /** A feature the host advertises in `ready`. The required ones are mandatory. */
268
+ export const CAPABILITIES = Object.freeze([
269
+ ...REQUIRED_CAPABILITIES,
270
+ 'clipboard_text_v1',
271
+ 'global_shortcuts_v1',
272
+ 'notifications_v1',
273
+ 'filesystem_grants_v1',
274
+ 'processes_v1',
275
+ 'split_v1',
276
+ 'style_decoration_v1',
277
+ /** Snapshots carry the display's work area (macOS, Windows). */
278
+ 'display_details_v1',
279
+ /** Owned windows report `display_changed` (macOS, Windows, Linux Wayland). */
280
+ 'display_changes_v1',
281
+ 'file_dialogs_v1',
282
+ 'overlays_v1',
283
+ 'scroll_anchor_v1',
284
+ 'focus_v1',
285
+ 'scroll_control_v1',
286
+ 'overlay_keyboard_v1',
287
+ 'popup_windows_v1',
288
+ 'drag_drop_files_v1',
289
+ 'input_states_v1',
290
+ /** A native application menu bar (macOS). */
291
+ 'app_menu_v1',
292
+ /** Owned OS message dialogs (Windows task dialogs, macOS alert sheets). */
293
+ 'task_dialogs_v1',
294
+ /** OS context menus at a window point (macOS `NSMenu`, Windows popup menus). */
295
+ 'context_menus_v1',
296
+ /** The split divider is a keyboard Tab stop and reports `split_resize`. */
297
+ 'split_resize_v1',
298
+ /**
299
+ * Every element kind has an accessibility role, and overlays and splits accept an
300
+ * `accessible_label`.
301
+ */
302
+ 'accessibility_v1',
303
+ /**
304
+ * Boxes accept list and list-item roles with set size, position and selection, and text nodes
305
+ * accept `accessible_live`.
306
+ */
307
+ 'accessibility_lists_v1',
308
+ /**
309
+ * Snapshots carry the platform display UUID when the backend names the display (macOS, Windows,
310
+ * Linux Wayland).
311
+ */
312
+ 'display_identity_v1',
313
+ ] as const)
314
+ export type Capability = (typeof CAPABILITIES)[number]
315
+
316
+ export interface Style {
317
+ direction?: Direction
318
+ /** Logical pixels. 0 to 4096. */
319
+ gap?: number
320
+ /** Logical pixels. 0 to 4096. */
321
+ padding?: number
322
+ /** Logical pixels. 0 to 16384, or `fill`. */
323
+ width?: number | 'fill'
324
+ /** Logical pixels. 0 to 16384, or `fill`. */
325
+ height?: number | 'fill'
326
+ /** Logical pixels. 0 to 16384. */
327
+ min_width?: number
328
+ /** Logical pixels. 0 to 16384. */
329
+ max_width?: number
330
+ /** Logical pixels. 0 to 16384. */
331
+ min_height?: number
332
+ /** Logical pixels. 0 to 16384. */
333
+ max_height?: number
334
+ /** 0 to 1000. */
335
+ flex_grow?: number
336
+ /** 0 to 1000. */
337
+ flex_shrink?: number
338
+ align_items?: AlignItems
339
+ justify_content?: JustifyContent
340
+ overflow?: Overflow
341
+ /** Requires `scroll_y` or `scroll`. `end` keeps a viewport already at its end pinned there. */
342
+ scroll_anchor?: ScrollAnchor
343
+ /** Unsigned 24-bit RGB. */
344
+ background?: number
345
+ /** Unsigned 24-bit RGB. */
346
+ color?: number
347
+ /** Logical pixels. 1 to 512. */
348
+ font_size?: number
349
+ /** `style_decoration_v1`: one uniform border width, in logical pixels. 0 to 64. */
350
+ border_width?: number
351
+ /** `style_decoration_v1`: unsigned 24-bit RGB. */
352
+ border_color?: number
353
+ /** `style_decoration_v1`: one radius for every corner, in logical pixels. 0 to 4096. */
354
+ corner_radius?: number
355
+ /** `style_decoration_v1`: multiplies this element and its descendants. 0 to 1. */
356
+ opacity?: number
357
+ /** `style_decoration_v1`: an inherited weight. 100 to 900 in steps of 100. */
358
+ font_weight?: 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
359
+ }
360
+
361
+ /** Style fields that require `style_decoration_v1`. */
362
+ export const DECORATION_FIELDS = Object.freeze([
363
+ 'border_width',
364
+ 'border_color',
365
+ 'corner_radius',
366
+ 'opacity',
367
+ 'font_weight',
368
+ ] as const)
369
+
370
+ /** How one style field is checked: a finite range, `fill` or a range, RGB, a value list or a stepped range. */
371
+ export type StyleField =
372
+ | { readonly type: 'number' | 'dimension'; readonly min: number; readonly max: number }
373
+ | { readonly type: 'color' }
374
+ | { readonly type: 'enum'; readonly values: readonly string[] }
375
+ | { readonly type: 'weight'; readonly min: number; readonly max: number; readonly step: number }
376
+
377
+ export const STYLE_FIELDS: ReadonlyMap<string, StyleField> = new Map<string, StyleField>([
378
+ ['direction', { type: 'enum', values: ['row', 'column'] }],
379
+ ['gap', { type: 'number', min: 0, max: 4_096 }],
380
+ ['padding', { type: 'number', min: 0, max: 4_096 }],
381
+ ['width', { type: 'dimension', min: 0, max: 16_384 }],
382
+ ['height', { type: 'dimension', min: 0, max: 16_384 }],
383
+ ['min_width', { type: 'number', min: 0, max: 16_384 }],
384
+ ['max_width', { type: 'number', min: 0, max: 16_384 }],
385
+ ['min_height', { type: 'number', min: 0, max: 16_384 }],
386
+ ['max_height', { type: 'number', min: 0, max: 16_384 }],
387
+ ['flex_grow', { type: 'number', min: 0, max: 1_000 }],
388
+ ['flex_shrink', { type: 'number', min: 0, max: 1_000 }],
389
+ ['align_items', { type: 'enum', values: ['start', 'center', 'end', 'stretch'] }],
390
+ [
391
+ 'justify_content',
392
+ {
393
+ type: 'enum',
394
+ values: ['start', 'center', 'end', 'space_between', 'space_around', 'space_evenly'],
395
+ },
396
+ ],
397
+ ['overflow', { type: 'enum', values: ['visible', 'hidden', 'scroll_x', 'scroll_y', 'scroll'] }],
398
+ ['scroll_anchor', { type: 'enum', values: ['start', 'end'] }],
399
+ ['background', { type: 'color' }],
400
+ ['color', { type: 'color' }],
401
+ ['font_size', { type: 'number', min: 1, max: 512 }],
402
+ ['border_width', { type: 'number', min: 0, max: 64 }],
403
+ ['border_color', { type: 'color' }],
404
+ ['corner_radius', { type: 'number', min: 0, max: 4_096 }],
405
+ ['opacity', { type: 'number', min: 0, max: 1 }],
406
+ ['font_weight', { type: 'weight', min: 100, max: 900, step: 100 }],
407
+ ])
408
+
409
+ /** Members of each element kind, `kind` included. */
410
+ export const ELEMENT_KEYS = Object.freeze({
411
+ box: new Set([
412
+ 'kind',
413
+ 'accessible_role',
414
+ 'accessible_label',
415
+ 'accessible_set_size',
416
+ 'accessible_position',
417
+ 'accessible_selected',
418
+ 'style',
419
+ ] as const),
420
+ text: new Set(['kind', 'text', 'accessible_live', 'style'] as const),
421
+ button: new Set(['kind', 'text', 'disabled', 'style'] as const),
422
+ input: new Set(['kind', 'value', 'placeholder', 'disabled', 'read_only', 'style'] as const),
423
+ split: new Set(['kind', 'ratio', 'min_size', 'accessible_label', 'style'] as const),
424
+ overlay: new Set([
425
+ 'kind',
426
+ 'anchor',
427
+ 'modal',
428
+ 'surface',
429
+ 'autofocus',
430
+ 'navigation',
431
+ 'accessible_label',
432
+ 'style',
433
+ ] as const),
434
+ })
435
+
436
+ /** Members of each tree operation, `type` included. */
437
+ export const OPERATION_KEYS = Object.freeze({
438
+ create: new Set(['type', 'node_id', 'element'] as const),
439
+ set: new Set(['type', 'node_id', 'element', 'expected_input_revision'] as const),
440
+ insert: new Set(['type', 'parent_id', 'child_id', 'index'] as const),
441
+ delete: new Set(['type', 'node_id'] as const),
442
+ focus: new Set(['type', 'node_id'] as const),
443
+ scroll_to: new Set(['type', 'node_id', 'x', 'y'] as const),
444
+ scroll_into_view: new Set(['type', 'node_id'] as const),
445
+ })
446
+
447
+ /** Members of each command, `type` included. */
448
+ export const COMMAND_KEYS = Object.freeze({
449
+ hello: new Set(['type', 'id', 'protocol'] as const),
450
+ open: new Set(['type', 'id', 'window_id', 'root_id', 'title', 'width', 'height'] as const),
451
+ batch: new Set(['type', 'id', 'window_id', 'base_revision', 'operations'] as const),
452
+ close: new Set(['type', 'id', 'window_id'] as const),
453
+ display_snapshot: new Set(['type', 'id', 'window_id'] as const),
454
+ clipboard_read: new Set(['type', 'id', 'window_id'] as const),
455
+ clipboard_write: new Set(['type', 'id', 'window_id', 'text'] as const),
456
+ register_global_shortcut: new Set([
457
+ 'type',
458
+ 'id',
459
+ 'window_id',
460
+ 'shortcut_id',
461
+ 'key',
462
+ 'modifiers',
463
+ ] as const),
464
+ unregister_global_shortcut: new Set(['type', 'id', 'window_id', 'shortcut_id'] as const),
465
+ post_notification: new Set([
466
+ 'type',
467
+ 'id',
468
+ 'window_id',
469
+ 'notification_id',
470
+ 'title',
471
+ 'body',
472
+ ] as const),
473
+ withdraw_notification: new Set(['type', 'id', 'window_id', 'notification_id'] as const),
474
+ open_file_grant: new Set(['type', 'id', 'window_id', 'grant_id', 'root', 'access'] as const),
475
+ close_file_grant: new Set(['type', 'id', 'window_id', 'grant_id'] as const),
476
+ file_request: new Set(['type', 'id', 'window_id', 'grant_id', 'path', 'operation'] as const),
477
+ spawn_process: new Set(['type', 'id', 'window_id', 'process_id', 'launch'] as const),
478
+ write_process: new Set(['type', 'id', 'window_id', 'process_id', 'data'] as const),
479
+ close_process_input: new Set(['type', 'id', 'window_id', 'process_id'] as const),
480
+ resize_process: new Set(['type', 'id', 'window_id', 'process_id', 'size'] as const),
481
+ signal_process: new Set(['type', 'id', 'window_id', 'process_id', 'signal'] as const),
482
+ acknowledge_process_output: new Set(['type', 'id', 'window_id', 'process_id', 'chunk'] as const),
483
+ release_process: new Set(['type', 'id', 'window_id', 'process_id'] as const),
484
+ show_file_dialog: new Set(['type', 'id', 'window_id', 'dialog_id', 'options'] as const),
485
+ close_file_dialog: new Set(['type', 'id', 'window_id', 'dialog_id'] as const),
486
+ show_message_dialog: new Set(['type', 'id', 'window_id', 'dialog_id', 'options'] as const),
487
+ close_message_dialog: new Set(['type', 'id', 'window_id', 'dialog_id'] as const),
488
+ show_context_menu: new Set(['type', 'id', 'window_id', 'menu_id', 'x', 'y', 'items'] as const),
489
+ close_context_menu: new Set(['type', 'id', 'window_id', 'menu_id'] as const),
490
+ register_drop_target: new Set(['type', 'id', 'window_id', 'target_id', 'node_id'] as const),
491
+ unregister_drop_target: new Set(['type', 'id', 'window_id', 'target_id'] as const),
492
+ resolve_dropped_item: new Set([
493
+ 'type',
494
+ 'id',
495
+ 'window_id',
496
+ 'target_id',
497
+ 'drop_id',
498
+ 'item',
499
+ 'root',
500
+ ] as const),
501
+ set_app_menu: new Set(['type', 'id', 'menu_id', 'menus'] as const),
502
+ shutdown: new Set(['type', 'id'] as const),
503
+ })
504
+
505
+ /** Members of each event, `type` included. */
506
+ export const EVENT_KEYS = Object.freeze({
507
+ ready: new Set(['type', 'protocol', 'capabilities', 'limits', 'service_policy'] as const),
508
+ ack: new Set(['type', 'id'] as const),
509
+ opened: new Set(['type', 'id', 'window_id', 'root_id', 'tree_revision'] as const),
510
+ applied: new Set(['type', 'id', 'window_id', 'tree_revision'] as const),
511
+ display_snapshot: new Set(['type', 'id', 'window_id', 'snapshot'] as const),
512
+ clipboard_text: new Set(['type', 'id', 'window_id', 'result'] as const),
513
+ clipboard_written: new Set(['type', 'id', 'window_id'] as const),
514
+ global_shortcut_registered: new Set(['type', 'id', 'window_id', 'shortcut_id'] as const),
515
+ global_shortcut_unregistered: new Set(['type', 'id', 'window_id', 'shortcut_id'] as const),
516
+ display_changed: new Set(['type', 'sequence', 'window_id', 'snapshot'] as const),
517
+ global_shortcut: new Set(['type', 'sequence', 'window_id', 'shortcut_id'] as const),
518
+ notification_posted: new Set([
519
+ 'type',
520
+ 'id',
521
+ 'window_id',
522
+ 'notification_id',
523
+ 'activatable',
524
+ ] as const),
525
+ notification_withdrawn: new Set(['type', 'id', 'window_id', 'notification_id'] as const),
526
+ notification_activated: new Set(['type', 'sequence', 'window_id', 'notification_id'] as const),
527
+ notification_dismissed: new Set([
528
+ 'type',
529
+ 'sequence',
530
+ 'window_id',
531
+ 'notification_id',
532
+ 'reason',
533
+ ] as const),
534
+ file_grant_opened: new Set(['type', 'id', 'window_id', 'grant_id'] as const),
535
+ file_grant_closed: new Set(['type', 'id', 'window_id', 'grant_id'] as const),
536
+ file_result: new Set(['type', 'id', 'window_id', 'grant_id', 'result'] as const),
537
+ process_spawned: new Set(['type', 'id', 'window_id', 'process_id'] as const),
538
+ process_updated: new Set(['type', 'id', 'window_id', 'process_id'] as const),
539
+ process_released: new Set(['type', 'id', 'window_id', 'process_id'] as const),
540
+ process_output: new Set([
541
+ 'type',
542
+ 'sequence',
543
+ 'window_id',
544
+ 'process_id',
545
+ 'chunk',
546
+ 'stream',
547
+ 'data',
548
+ ] as const),
549
+ process_exited: new Set(['type', 'sequence', 'window_id', 'process_id', 'exit'] as const),
550
+ file_dialog_opened: new Set(['type', 'id', 'window_id', 'dialog_id'] as const),
551
+ file_dialog_closed: new Set(['type', 'id', 'window_id', 'dialog_id'] as const),
552
+ file_dialog_completed: new Set(['type', 'sequence', 'window_id', 'dialog_id', 'result'] as const),
553
+ message_dialog_opened: new Set(['type', 'id', 'window_id', 'dialog_id'] as const),
554
+ message_dialog_closed: new Set(['type', 'id', 'window_id', 'dialog_id'] as const),
555
+ message_dialog_completed: new Set([
556
+ 'type',
557
+ 'sequence',
558
+ 'window_id',
559
+ 'dialog_id',
560
+ 'result',
561
+ ] as const),
562
+ context_menu_opened: new Set(['type', 'id', 'window_id', 'menu_id'] as const),
563
+ context_menu_closed: new Set(['type', 'id', 'window_id', 'menu_id'] as const),
564
+ context_menu_completed: new Set(['type', 'sequence', 'window_id', 'menu_id', 'item_id'] as const),
565
+ drop_target_registered: new Set(['type', 'id', 'window_id', 'target_id'] as const),
566
+ drop_target_unregistered: new Set(['type', 'id', 'window_id', 'target_id'] as const),
567
+ dropped_item_resolved: new Set([
568
+ 'type',
569
+ 'id',
570
+ 'window_id',
571
+ 'target_id',
572
+ 'drop_id',
573
+ 'item',
574
+ 'root',
575
+ 'path',
576
+ ] as const),
577
+ drop_target_drag: new Set(['type', 'sequence', 'window_id', 'target_id', 'state'] as const),
578
+ drop_received: new Set([
579
+ 'type',
580
+ 'sequence',
581
+ 'window_id',
582
+ 'target_id',
583
+ 'drop_id',
584
+ 'items',
585
+ ] as const),
586
+ drop_rejected: new Set(['type', 'sequence', 'window_id', 'target_id', 'reason'] as const),
587
+ click: new Set(['type', 'sequence', 'window_id', 'node_id', 'tree_revision', 'path'] as const),
588
+ focus: new Set(['type', 'sequence', 'window_id', 'node_id', 'tree_revision', 'path'] as const),
589
+ blur: new Set(['type', 'sequence', 'window_id', 'node_id', 'tree_revision', 'path'] as const),
590
+ input: new Set([
591
+ 'type',
592
+ 'sequence',
593
+ 'window_id',
594
+ 'node_id',
595
+ 'tree_revision',
596
+ 'path',
597
+ 'value',
598
+ 'input_revision',
599
+ ] as const),
600
+ key_down: new Set([
601
+ 'type',
602
+ 'sequence',
603
+ 'window_id',
604
+ 'node_id',
605
+ 'tree_revision',
606
+ 'path',
607
+ 'key',
608
+ 'key_char',
609
+ 'modifiers',
610
+ ] as const),
611
+ key_up: new Set([
612
+ 'type',
613
+ 'sequence',
614
+ 'window_id',
615
+ 'node_id',
616
+ 'tree_revision',
617
+ 'path',
618
+ 'key',
619
+ 'key_char',
620
+ 'modifiers',
621
+ ] as const),
622
+ pointer_down: new Set([
623
+ 'type',
624
+ 'sequence',
625
+ 'window_id',
626
+ 'node_id',
627
+ 'tree_revision',
628
+ 'path',
629
+ 'button',
630
+ 'x',
631
+ 'y',
632
+ 'modifiers',
633
+ ] as const),
634
+ pointer_up: new Set([
635
+ 'type',
636
+ 'sequence',
637
+ 'window_id',
638
+ 'node_id',
639
+ 'tree_revision',
640
+ 'path',
641
+ 'button',
642
+ 'x',
643
+ 'y',
644
+ 'modifiers',
645
+ ] as const),
646
+ dismiss: new Set([
647
+ 'type',
648
+ 'sequence',
649
+ 'window_id',
650
+ 'node_id',
651
+ 'tree_revision',
652
+ 'path',
653
+ 'reason',
654
+ ] as const),
655
+ split_resize: new Set([
656
+ 'type',
657
+ 'sequence',
658
+ 'window_id',
659
+ 'node_id',
660
+ 'tree_revision',
661
+ 'path',
662
+ 'ratio',
663
+ 'source',
664
+ ] as const),
665
+ closed: new Set(['type', 'sequence', 'window_id'] as const),
666
+ app_menu_set: new Set(['type', 'id', 'menu_id'] as const),
667
+ app_menu_item: new Set(['type', 'sequence', 'menu_id', 'item_id'] as const),
668
+ error: new Set(['type', 'id', 'code', 'message'] as const),
669
+ })
670
+
671
+ /** Members of a key or pointer event's `modifiers`. */
672
+ export const MODIFIER_KEYS = new Set(['control', 'alt', 'shift', 'platform', 'function'] as const)
673
+
674
+ /** Named menu shortcut keys besides letters, digits and function keys. */
675
+ export const APP_MENU_NAMED_KEYS = Object.freeze([
676
+ 'enter',
677
+ 'escape',
678
+ 'tab',
679
+ 'space',
680
+ 'backspace',
681
+ 'delete',
682
+ 'up',
683
+ 'down',
684
+ 'left',
685
+ 'right',
686
+ 'home',
687
+ 'end',
688
+ 'pageup',
689
+ 'pagedown',
690
+ ] as const)
691
+ /** Punctuation menu shortcut keys. */
692
+ export const APP_MENU_PUNCTUATION_KEYS = Object.freeze([
693
+ ',',
694
+ '.',
695
+ '/',
696
+ ';',
697
+ "'",
698
+ '[',
699
+ ']',
700
+ '-',
701
+ '=',
702
+ '`',
703
+ '\\',
704
+ ] as const)
705
+
706
+ /** Members of each nested payload object; each variant of a tagged one includes the tag. */
707
+ export const PAYLOAD_KEYS = Object.freeze({
708
+ filesystem_root: new Set(['id', 'path', 'access'] as const),
709
+ file_operation: Object.freeze({
710
+ stat: new Set(['kind'] as const),
711
+ list: new Set(['kind', 'after'] as const),
712
+ read: new Set(['kind', 'offset', 'length'] as const),
713
+ write: new Set(['kind', 'mode', 'data'] as const),
714
+ create_directory: new Set(['kind'] as const),
715
+ remove: new Set(['kind'] as const),
716
+ }),
717
+ file_result: Object.freeze({
718
+ stat: new Set(['kind', 'file_kind', 'size', 'modified_ms'] as const),
719
+ list: new Set(['kind', 'entries', 'complete', 'omitted'] as const),
720
+ read: new Set(['kind', 'data', 'end_of_file'] as const),
721
+ written: new Set(['kind', 'bytes'] as const),
722
+ done: new Set(['kind'] as const),
723
+ }),
724
+ directory_entry: new Set(['name', 'kind'] as const),
725
+ process_limits: new Set(['cpu_seconds', 'memory_bytes', 'open_files'] as const),
726
+ process_executable: new Set(['id', 'executable', 'limits'] as const),
727
+ process_launch: new Set(['executable', 'args', 'env', 'cwd', 'terminal'] as const),
728
+ process_directory: new Set(['grant_id', 'path'] as const),
729
+ terminal_size: new Set(['columns', 'rows'] as const),
730
+ process_exit: new Set(['code', 'signal'] as const),
731
+ app_menu: new Set(['title', 'items'] as const),
732
+ app_menu_entry: Object.freeze({
733
+ item: new Set(['kind', 'id', 'label', 'shortcut', 'enabled', 'checked'] as const),
734
+ separator: new Set(['kind'] as const),
735
+ submenu: new Set(['kind', 'label', 'enabled', 'items'] as const),
736
+ }),
737
+ menu_shortcut: new Set(['key', 'modifiers'] as const),
738
+ menu_shortcut_modifiers: new Set(['control', 'alt', 'shift', 'platform'] as const),
739
+ file_dialog_options: new Set([
740
+ 'mode',
741
+ 'title',
742
+ 'accept_label',
743
+ 'folder',
744
+ 'name',
745
+ 'filters',
746
+ ] as const),
747
+ file_filter: new Set(['name', 'patterns'] as const),
748
+ file_dialog_result: Object.freeze({
749
+ selected: new Set(['kind', 'paths'] as const),
750
+ cancelled: new Set(['kind'] as const),
751
+ failed: new Set(['kind', 'code'] as const),
752
+ }),
753
+ message_dialog_options: new Set([
754
+ 'title',
755
+ 'message',
756
+ 'detail',
757
+ 'buttons',
758
+ 'default_button',
759
+ 'cancel_button',
760
+ 'dismissible',
761
+ ] as const),
762
+ message_dialog_button: new Set(['id', 'label'] as const),
763
+ message_dialog_result: Object.freeze({
764
+ button: new Set(['kind', 'id'] as const),
765
+ dismissed: new Set(['kind'] as const),
766
+ failed: new Set(['kind'] as const),
767
+ }),
768
+ service_policy: new Set([
769
+ 'window_display',
770
+ 'clipboard_read',
771
+ 'clipboard_write',
772
+ 'global_shortcuts',
773
+ 'notifications',
774
+ 'drag_drop',
775
+ 'filesystem_roots',
776
+ 'processes',
777
+ 'file_dialogs',
778
+ 'app_menu',
779
+ 'task_dialogs',
780
+ ] as const),
781
+ shortcut_modifiers: new Set(['control', 'alt', 'shift', 'platform'] as const),
782
+ clipboard_text: Object.freeze({
783
+ empty: new Set(['kind'] as const),
784
+ text: new Set(['kind', 'text'] as const),
785
+ }),
786
+ display_snapshot: new Set(['bounds', 'scale_factor', 'visible_bounds', 'display_uuid'] as const),
787
+ display_bounds: new Set(['x', 'y', 'width', 'height'] as const),
788
+ dropped_item: new Set(['name'] as const),
789
+ })