contree-client 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.
package/lib/models.js ADDED
@@ -0,0 +1,2173 @@
1
+ // Generated by codegen from the OpenAPI spec - do not edit.
2
+
3
+ import {
4
+ base64ToBytes,
5
+ bytesToBase64,
6
+ bytesToText,
7
+ parseDatetime,
8
+ textToBytes,
9
+ } from "./runtime.js";
10
+
11
+ export const OPERATION_EVENT_TYPES = Object.freeze([
12
+ "init",
13
+ "spawn",
14
+ "stdin",
15
+ "stdout",
16
+ "stderr",
17
+ "exit",
18
+ "truncated",
19
+ "size_cap",
20
+ "network",
21
+ "shutdown",
22
+ "completion",
23
+ ]);
24
+
25
+ /** Operation lifecycle state. */
26
+ export const OperationStatus = Object.freeze({
27
+ PENDING: "PENDING",
28
+ ASSIGNED: "ASSIGNED",
29
+ EXECUTING: "EXECUTING",
30
+ SUCCESS: "SUCCESS",
31
+ FAILED: "FAILED",
32
+ CANCELLED: "CANCELLED",
33
+ });
34
+
35
+ export const TERMINAL_STATUSES = new Set(["SUCCESS", "FAILED", "CANCELLED"]);
36
+
37
+ export const ACTIVE_STATUSES = new Set(["PENDING", "ASSIGNED", "EXECUTING"]);
38
+
39
+ /** True for statuses that will never change again. */
40
+ export function isTerminalStatus(status) {
41
+ return TERMINAL_STATUSES.has(status);
42
+ }
43
+
44
+ export class FileItem {
45
+ constructor(fields = {}) {
46
+ this.size = fields.size;
47
+ this.path = fields.path;
48
+ this.owner = fields.owner;
49
+ this.group = fields.group;
50
+ this.uid = fields.uid;
51
+ this.gid = fields.gid;
52
+ this.mode = fields.mode;
53
+ this.mtime = fields.mtime;
54
+ this.nlink = fields.nlink;
55
+ this.is_dir = fields.is_dir;
56
+ this.is_regular = fields.is_regular;
57
+ this.is_symlink = fields.is_symlink;
58
+ this.is_socket = fields.is_socket;
59
+ this.is_fifo = fields.is_fifo;
60
+ this.symlink_to = fields.symlink_to;
61
+ }
62
+
63
+ static fromWire(data) {
64
+ return new FileItem({
65
+ size: data["size"],
66
+ path: data["path"],
67
+ owner: data["owner"],
68
+ group: data["group"],
69
+ uid: data["uid"],
70
+ gid: data["gid"],
71
+ mode: data["mode"],
72
+ mtime: data["mtime"],
73
+ nlink: data["nlink"],
74
+ is_dir: data["is_dir"],
75
+ is_regular: data["is_regular"],
76
+ is_symlink: data["is_symlink"],
77
+ is_socket: data["is_socket"],
78
+ is_fifo: data["is_fifo"],
79
+ symlink_to: data["symlink_to"],
80
+ });
81
+ }
82
+
83
+ toWire() {
84
+ const data = {};
85
+ if (this.size !== undefined) {
86
+ data["size"] = this.size;
87
+ }
88
+ if (this.path !== undefined) {
89
+ data["path"] = this.path;
90
+ }
91
+ if (this.owner !== undefined) {
92
+ data["owner"] = this.owner;
93
+ }
94
+ if (this.group !== undefined) {
95
+ data["group"] = this.group;
96
+ }
97
+ if (this.uid !== undefined) {
98
+ data["uid"] = this.uid;
99
+ }
100
+ if (this.gid !== undefined) {
101
+ data["gid"] = this.gid;
102
+ }
103
+ if (this.mode !== undefined) {
104
+ data["mode"] = this.mode;
105
+ }
106
+ if (this.mtime !== undefined) {
107
+ data["mtime"] = this.mtime;
108
+ }
109
+ if (this.nlink !== undefined) {
110
+ data["nlink"] = this.nlink;
111
+ }
112
+ if (this.is_dir !== undefined) {
113
+ data["is_dir"] = this.is_dir;
114
+ }
115
+ if (this.is_regular !== undefined) {
116
+ data["is_regular"] = this.is_regular;
117
+ }
118
+ if (this.is_symlink !== undefined) {
119
+ data["is_symlink"] = this.is_symlink;
120
+ }
121
+ if (this.is_socket !== undefined) {
122
+ data["is_socket"] = this.is_socket;
123
+ }
124
+ if (this.is_fifo !== undefined) {
125
+ data["is_fifo"] = this.is_fifo;
126
+ }
127
+ if (this.symlink_to !== undefined) {
128
+ data["symlink_to"] = this.symlink_to;
129
+ }
130
+ return data;
131
+ }
132
+ }
133
+
134
+ export class DirectoryList {
135
+ constructor(fields = {}) {
136
+ this.path = fields.path;
137
+ this.files = fields.files;
138
+ }
139
+
140
+ static fromWire(data) {
141
+ return new DirectoryList({
142
+ path: data["path"],
143
+ files: data["files"].map((item) => FileItem.fromWire(item)),
144
+ });
145
+ }
146
+
147
+ toWire() {
148
+ const data = {};
149
+ if (this.path !== undefined) {
150
+ data["path"] = this.path;
151
+ }
152
+ if (this.files !== undefined) {
153
+ data["files"] =
154
+ this.files === null ? null : this.files.map((item) => item.toWire());
155
+ }
156
+ return data;
157
+ }
158
+ }
159
+
160
+ export class ImageImportRegistryCredentials {
161
+ constructor(fields = {}) {
162
+ this.username = fields.username;
163
+ this.password = fields.password;
164
+ }
165
+
166
+ static fromWire(data) {
167
+ return new ImageImportRegistryCredentials({
168
+ username: data["username"],
169
+ password: data["password"],
170
+ });
171
+ }
172
+
173
+ toWire() {
174
+ const data = {};
175
+ if (this.username !== undefined) {
176
+ data["username"] = this.username;
177
+ }
178
+ if (this.password !== undefined) {
179
+ data["password"] = this.password;
180
+ }
181
+ return data;
182
+ }
183
+ }
184
+
185
+ export class ImageImportRegistry {
186
+ constructor(fields = {}) {
187
+ this.url = fields.url;
188
+ this.credentials = fields.credentials;
189
+ }
190
+
191
+ static fromWire(data) {
192
+ return new ImageImportRegistry({
193
+ url: data["url"],
194
+ credentials:
195
+ data["credentials"] == null
196
+ ? data["credentials"]
197
+ : ImageImportRegistryCredentials.fromWire(data["credentials"]),
198
+ });
199
+ }
200
+
201
+ toWire() {
202
+ const data = {};
203
+ if (this.url !== undefined) {
204
+ data["url"] = this.url;
205
+ }
206
+ if (this.credentials !== undefined) {
207
+ data["credentials"] =
208
+ this.credentials === null ? null : this.credentials.toWire();
209
+ }
210
+ return data;
211
+ }
212
+ }
213
+
214
+ export class ImageImportRequest {
215
+ constructor(fields = {}) {
216
+ this.registry = fields.registry;
217
+ this.tag = fields.tag;
218
+ this.timeout = fields.timeout;
219
+ }
220
+
221
+ static fromWire(data) {
222
+ return new ImageImportRequest({
223
+ registry: ImageImportRegistry.fromWire(data["registry"]),
224
+ tag: data["tag"],
225
+ timeout: data["timeout"],
226
+ });
227
+ }
228
+
229
+ toWire() {
230
+ const data = {};
231
+ if (this.registry !== undefined) {
232
+ data["registry"] = this.registry === null ? null : this.registry.toWire();
233
+ }
234
+ if (this.tag !== undefined) {
235
+ data["tag"] = this.tag;
236
+ }
237
+ if (this.timeout !== undefined) {
238
+ data["timeout"] = this.timeout;
239
+ }
240
+ return data;
241
+ }
242
+ }
243
+
244
+ export class Image {
245
+ constructor(fields = {}) {
246
+ this.uuid = fields.uuid;
247
+ this.tag = fields.tag;
248
+ this.created_at = fields.created_at;
249
+ this.operation_uuid = fields.operation_uuid;
250
+ }
251
+
252
+ static fromWire(data) {
253
+ return new Image({
254
+ uuid: data["uuid"],
255
+ tag: data["tag"],
256
+ created_at: data["created_at"],
257
+ operation_uuid: data["operation_uuid"],
258
+ });
259
+ }
260
+
261
+ toWire() {
262
+ const data = {};
263
+ if (this.uuid !== undefined) {
264
+ data["uuid"] = this.uuid;
265
+ }
266
+ if (this.tag !== undefined) {
267
+ data["tag"] = this.tag;
268
+ }
269
+ if (this.created_at !== undefined) {
270
+ data["created_at"] = this.created_at;
271
+ }
272
+ if (this.operation_uuid !== undefined) {
273
+ data["operation_uuid"] = this.operation_uuid;
274
+ }
275
+ return data;
276
+ }
277
+ }
278
+
279
+ export class ImageListResponse {
280
+ constructor(fields = {}) {
281
+ this.images = fields.images;
282
+ }
283
+
284
+ static fromWire(data) {
285
+ return new ImageListResponse({
286
+ images:
287
+ data["images"] == null
288
+ ? data["images"]
289
+ : data["images"].map((item) => Image.fromWire(item)),
290
+ });
291
+ }
292
+
293
+ toWire() {
294
+ const data = {};
295
+ if (this.images !== undefined) {
296
+ data["images"] =
297
+ this.images === null ? null : this.images.map((item) => item.toWire());
298
+ }
299
+ return data;
300
+ }
301
+ }
302
+
303
+ export class ImageImportMetadataRegistryCredentials {
304
+ constructor(fields = {}) {
305
+ this.username = fields.username;
306
+ this.password = fields.password;
307
+ }
308
+
309
+ static fromWire(data) {
310
+ return new ImageImportMetadataRegistryCredentials({
311
+ username: data["username"],
312
+ password: data["password"],
313
+ });
314
+ }
315
+
316
+ toWire() {
317
+ const data = {};
318
+ if (this.username !== undefined) {
319
+ data["username"] = this.username;
320
+ }
321
+ if (this.password !== undefined) {
322
+ data["password"] = this.password;
323
+ }
324
+ return data;
325
+ }
326
+ }
327
+
328
+ export class ImageImportMetadataRegistry {
329
+ constructor(fields = {}) {
330
+ this.url = fields.url;
331
+ this.credentials = fields.credentials;
332
+ }
333
+
334
+ static fromWire(data) {
335
+ return new ImageImportMetadataRegistry({
336
+ url: data["url"],
337
+ credentials:
338
+ data["credentials"] == null
339
+ ? data["credentials"]
340
+ : ImageImportMetadataRegistryCredentials.fromWire(
341
+ data["credentials"],
342
+ ),
343
+ });
344
+ }
345
+
346
+ toWire() {
347
+ const data = {};
348
+ if (this.url !== undefined) {
349
+ data["url"] = this.url;
350
+ }
351
+ if (this.credentials !== undefined) {
352
+ data["credentials"] =
353
+ this.credentials === null ? null : this.credentials.toWire();
354
+ }
355
+ return data;
356
+ }
357
+ }
358
+
359
+ export class ImageImportMetadata {
360
+ constructor(fields = {}) {
361
+ this.registry = fields.registry;
362
+ this.tag = fields.tag;
363
+ this.timeout = fields.timeout;
364
+ }
365
+
366
+ static fromWire(data) {
367
+ return new ImageImportMetadata({
368
+ registry:
369
+ data["registry"] == null
370
+ ? data["registry"]
371
+ : ImageImportMetadataRegistry.fromWire(data["registry"]),
372
+ tag: data["tag"],
373
+ timeout: data["timeout"],
374
+ });
375
+ }
376
+
377
+ toWire() {
378
+ const data = {};
379
+ if (this.registry !== undefined) {
380
+ data["registry"] = this.registry === null ? null : this.registry.toWire();
381
+ }
382
+ if (this.tag !== undefined) {
383
+ data["tag"] = this.tag;
384
+ }
385
+ if (this.timeout !== undefined) {
386
+ data["timeout"] = this.timeout;
387
+ }
388
+ return data;
389
+ }
390
+ }
391
+
392
+ export class StreamRepr {
393
+ constructor(fields = {}) {
394
+ this.value = fields.value;
395
+ this.encoding = fields.encoding;
396
+ this.truncated = fields.truncated;
397
+ }
398
+
399
+ static fromWire(data) {
400
+ return new StreamRepr({
401
+ value: data["value"],
402
+ encoding: data["encoding"],
403
+ truncated: data["truncated"],
404
+ });
405
+ }
406
+
407
+ toWire() {
408
+ const data = {};
409
+ if (this.value !== undefined) {
410
+ data["value"] = this.value;
411
+ }
412
+ if (this.encoding !== undefined) {
413
+ data["encoding"] = this.encoding;
414
+ }
415
+ if (this.truncated !== undefined) {
416
+ data["truncated"] = this.truncated;
417
+ }
418
+ return data;
419
+ }
420
+
421
+ /** The payload decoded to raw bytes; undecodable base64 becomes
422
+ * empty bytes instead of failing a live stream. */
423
+ asBytes() {
424
+ if (!this.value) {
425
+ return new Uint8Array();
426
+ }
427
+ if (this.encoding === "base64") {
428
+ try {
429
+ return base64ToBytes(this.value);
430
+ } catch {
431
+ return new Uint8Array();
432
+ }
433
+ }
434
+ return textToBytes(this.value);
435
+ }
436
+
437
+ /** The payload decoded to text. */
438
+ asText() {
439
+ if (this.encoding === "base64") {
440
+ return bytesToText(this.asBytes());
441
+ }
442
+ return this.value;
443
+ }
444
+
445
+ /** Build a payload from raw bytes: printable ASCII stays `ascii`,
446
+ * anything else is base64-encoded - the server-side rule. */
447
+ static fromBytes(value) {
448
+ const printable = value.every(
449
+ (byte) =>
450
+ (byte >= 32 && byte < 127) || byte === 9 || byte === 10 || byte === 13,
451
+ );
452
+ if (printable) {
453
+ return new this({
454
+ value: new TextDecoder("ascii").decode(value),
455
+ encoding: "ascii",
456
+ });
457
+ }
458
+ return new this({ value: bytesToBase64(value), encoding: "base64" });
459
+ }
460
+
461
+ /** Build a payload from text (UTF-8 encoded unless ASCII). */
462
+ static fromText(value) {
463
+ return this.fromBytes(textToBytes(value));
464
+ }
465
+ }
466
+
467
+ export class InstanceResourcesLimits {
468
+ constructor(fields = {}) {
469
+ this.max_layer_bytes = fields.max_layer_bytes;
470
+ }
471
+
472
+ static fromWire(data) {
473
+ return new InstanceResourcesLimits({
474
+ max_layer_bytes: data["max_layer_bytes"],
475
+ });
476
+ }
477
+
478
+ toWire() {
479
+ const data = {};
480
+ if (this.max_layer_bytes !== undefined) {
481
+ data["max_layer_bytes"] = this.max_layer_bytes;
482
+ }
483
+ return data;
484
+ }
485
+ }
486
+
487
+ export class FileSpec {
488
+ constructor(fields = {}) {
489
+ this.uuid = fields.uuid;
490
+ this.uid = fields.uid;
491
+ this.gid = fields.gid;
492
+ this.mode = fields.mode;
493
+
494
+ // the wire format is an octal string; accept a plain int too
495
+ if (typeof this.mode === "number") {
496
+ this.mode = this.mode.toString(8).padStart(4, "0");
497
+ }
498
+ }
499
+
500
+ static fromWire(data) {
501
+ return new FileSpec({
502
+ uuid: data["uuid"],
503
+ uid: data["uid"],
504
+ gid: data["gid"],
505
+ mode: data["mode"],
506
+ });
507
+ }
508
+
509
+ toWire() {
510
+ const data = {};
511
+ if (this.uuid !== undefined) {
512
+ data["uuid"] = this.uuid;
513
+ }
514
+ if (this.uid !== undefined) {
515
+ data["uid"] = this.uid;
516
+ }
517
+ if (this.gid !== undefined) {
518
+ data["gid"] = this.gid;
519
+ }
520
+ if (this.mode !== undefined) {
521
+ data["mode"] = this.mode;
522
+ }
523
+ return data;
524
+ }
525
+ }
526
+
527
+ export class InstanceSpawnRequest {
528
+ constructor(fields = {}) {
529
+ this.command = fields.command;
530
+ this.image = fields.image;
531
+ this.disposable = fields.disposable;
532
+ this.hostname = fields.hostname;
533
+ this.args = fields.args;
534
+ this.shell = fields.shell;
535
+ this.env = fields.env;
536
+ this.preserve_env = fields.preserve_env;
537
+ this.cwd = fields.cwd;
538
+ this.uid = fields.uid;
539
+ this.gid = fields.gid;
540
+ this.resources_limits = fields.resources_limits;
541
+ this.stdin = fields.stdin;
542
+ this.timeout = fields.timeout;
543
+ this.truncate_output_at = fields.truncate_output_at;
544
+ this.files = fields.files;
545
+ }
546
+
547
+ static fromWire(data) {
548
+ return new InstanceSpawnRequest({
549
+ command: data["command"],
550
+ image: data["image"],
551
+ disposable: data["disposable"],
552
+ hostname: data["hostname"],
553
+ args: data["args"],
554
+ shell: data["shell"],
555
+ env: data["env"],
556
+ preserve_env: data["preserve_env"],
557
+ cwd: data["cwd"],
558
+ uid: data["uid"],
559
+ gid: data["gid"],
560
+ resources_limits:
561
+ data["resources_limits"] == null
562
+ ? data["resources_limits"]
563
+ : InstanceResourcesLimits.fromWire(data["resources_limits"]),
564
+ stdin:
565
+ data["stdin"] == null
566
+ ? data["stdin"]
567
+ : StreamRepr.fromWire(data["stdin"]),
568
+ timeout: data["timeout"],
569
+ truncate_output_at: data["truncate_output_at"],
570
+ files:
571
+ data["files"] == null
572
+ ? data["files"]
573
+ : Object.fromEntries(
574
+ Object.entries(data["files"]).map(([key, value]) => [
575
+ key,
576
+ FileSpec.fromWire(value),
577
+ ]),
578
+ ),
579
+ });
580
+ }
581
+
582
+ toWire() {
583
+ const data = {};
584
+ if (this.command !== undefined) {
585
+ data["command"] = this.command;
586
+ }
587
+ if (this.image !== undefined) {
588
+ data["image"] = this.image;
589
+ }
590
+ if (this.disposable !== undefined) {
591
+ data["disposable"] = this.disposable;
592
+ }
593
+ if (this.hostname !== undefined) {
594
+ data["hostname"] = this.hostname;
595
+ }
596
+ if (this.args !== undefined) {
597
+ data["args"] = this.args;
598
+ }
599
+ if (this.shell !== undefined) {
600
+ data["shell"] = this.shell;
601
+ }
602
+ if (this.env !== undefined) {
603
+ data["env"] = this.env;
604
+ }
605
+ if (this.preserve_env !== undefined) {
606
+ data["preserve_env"] = this.preserve_env;
607
+ }
608
+ if (this.cwd !== undefined) {
609
+ data["cwd"] = this.cwd;
610
+ }
611
+ if (this.uid !== undefined) {
612
+ data["uid"] = this.uid;
613
+ }
614
+ if (this.gid !== undefined) {
615
+ data["gid"] = this.gid;
616
+ }
617
+ if (this.resources_limits !== undefined) {
618
+ data["resources_limits"] =
619
+ this.resources_limits === null ? null : this.resources_limits.toWire();
620
+ }
621
+ if (this.stdin !== undefined) {
622
+ data["stdin"] = this.stdin === null ? null : this.stdin.toWire();
623
+ }
624
+ if (this.timeout !== undefined) {
625
+ data["timeout"] = this.timeout;
626
+ }
627
+ if (this.truncate_output_at !== undefined) {
628
+ data["truncate_output_at"] = this.truncate_output_at;
629
+ }
630
+ if (this.files !== undefined) {
631
+ data["files"] =
632
+ this.files === null
633
+ ? null
634
+ : Object.fromEntries(
635
+ Object.entries(this.files).map(([key, value]) => [
636
+ key,
637
+ value.toWire(),
638
+ ]),
639
+ );
640
+ }
641
+ return data;
642
+ }
643
+ }
644
+
645
+ export class InstanceResultResources {
646
+ constructor(fields = {}) {
647
+ this.block_input = fields.block_input;
648
+ this.block_output = fields.block_output;
649
+ this.cost = fields.cost;
650
+ this.elapsed_time = fields.elapsed_time;
651
+ this.involuntary_switches = fields.involuntary_switches;
652
+ this.max_rss = fields.max_rss;
653
+ this.monotonic_time = fields.monotonic_time;
654
+ this.page_faults = fields.page_faults;
655
+ this.page_faults_io = fields.page_faults_io;
656
+ this.shared_memory = fields.shared_memory;
657
+ this.signals = fields.signals;
658
+ this.swaps = fields.swaps;
659
+ this.system_cpu_time = fields.system_cpu_time;
660
+ this.unshared_memory = fields.unshared_memory;
661
+ this.user_cpu_time = fields.user_cpu_time;
662
+ this.voluntary_switches = fields.voluntary_switches;
663
+ }
664
+
665
+ static fromWire(data) {
666
+ return new InstanceResultResources({
667
+ block_input: data["block_input"],
668
+ block_output: data["block_output"],
669
+ cost: data["cost"],
670
+ elapsed_time: data["elapsed_time"],
671
+ involuntary_switches: data["involuntary_switches"],
672
+ max_rss: data["max_rss"],
673
+ monotonic_time: data["monotonic_time"],
674
+ page_faults: data["page_faults"],
675
+ page_faults_io: data["page_faults_io"],
676
+ shared_memory: data["shared_memory"],
677
+ signals: data["signals"],
678
+ swaps: data["swaps"],
679
+ system_cpu_time: data["system_cpu_time"],
680
+ unshared_memory: data["unshared_memory"],
681
+ user_cpu_time: data["user_cpu_time"],
682
+ voluntary_switches: data["voluntary_switches"],
683
+ });
684
+ }
685
+
686
+ toWire() {
687
+ const data = {};
688
+ if (this.block_input !== undefined) {
689
+ data["block_input"] = this.block_input;
690
+ }
691
+ if (this.block_output !== undefined) {
692
+ data["block_output"] = this.block_output;
693
+ }
694
+ if (this.cost !== undefined) {
695
+ data["cost"] = this.cost;
696
+ }
697
+ if (this.elapsed_time !== undefined) {
698
+ data["elapsed_time"] = this.elapsed_time;
699
+ }
700
+ if (this.involuntary_switches !== undefined) {
701
+ data["involuntary_switches"] = this.involuntary_switches;
702
+ }
703
+ if (this.max_rss !== undefined) {
704
+ data["max_rss"] = this.max_rss;
705
+ }
706
+ if (this.monotonic_time !== undefined) {
707
+ data["monotonic_time"] = this.monotonic_time;
708
+ }
709
+ if (this.page_faults !== undefined) {
710
+ data["page_faults"] = this.page_faults;
711
+ }
712
+ if (this.page_faults_io !== undefined) {
713
+ data["page_faults_io"] = this.page_faults_io;
714
+ }
715
+ if (this.shared_memory !== undefined) {
716
+ data["shared_memory"] = this.shared_memory;
717
+ }
718
+ if (this.signals !== undefined) {
719
+ data["signals"] = this.signals;
720
+ }
721
+ if (this.swaps !== undefined) {
722
+ data["swaps"] = this.swaps;
723
+ }
724
+ if (this.system_cpu_time !== undefined) {
725
+ data["system_cpu_time"] = this.system_cpu_time;
726
+ }
727
+ if (this.unshared_memory !== undefined) {
728
+ data["unshared_memory"] = this.unshared_memory;
729
+ }
730
+ if (this.user_cpu_time !== undefined) {
731
+ data["user_cpu_time"] = this.user_cpu_time;
732
+ }
733
+ if (this.voluntary_switches !== undefined) {
734
+ data["voluntary_switches"] = this.voluntary_switches;
735
+ }
736
+ return data;
737
+ }
738
+ }
739
+
740
+ export class InstanceResultState {
741
+ constructor(fields = {}) {
742
+ this.continued = fields.continued;
743
+ this.core_dump = fields.core_dump;
744
+ this.exit_code = fields.exit_code;
745
+ this.pid = fields.pid;
746
+ this.signal = fields.signal;
747
+ this.stopped = fields.stopped;
748
+ this.timed_out = fields.timed_out;
749
+ }
750
+
751
+ static fromWire(data) {
752
+ return new InstanceResultState({
753
+ continued: data["continued"],
754
+ core_dump: data["core_dump"],
755
+ exit_code: data["exit_code"],
756
+ pid: data["pid"],
757
+ signal: data["signal"],
758
+ stopped: data["stopped"],
759
+ timed_out: data["timed_out"],
760
+ });
761
+ }
762
+
763
+ toWire() {
764
+ const data = {};
765
+ if (this.continued !== undefined) {
766
+ data["continued"] = this.continued;
767
+ }
768
+ if (this.core_dump !== undefined) {
769
+ data["core_dump"] = this.core_dump;
770
+ }
771
+ if (this.exit_code !== undefined) {
772
+ data["exit_code"] = this.exit_code;
773
+ }
774
+ if (this.pid !== undefined) {
775
+ data["pid"] = this.pid;
776
+ }
777
+ if (this.signal !== undefined) {
778
+ data["signal"] = this.signal;
779
+ }
780
+ if (this.stopped !== undefined) {
781
+ data["stopped"] = this.stopped;
782
+ }
783
+ if (this.timed_out !== undefined) {
784
+ data["timed_out"] = this.timed_out;
785
+ }
786
+ return data;
787
+ }
788
+ }
789
+
790
+ /** Result of an instance execution */
791
+ export class InstanceResult {
792
+ constructor(fields = {}) {
793
+ this.resources = fields.resources;
794
+ this.state = fields.state;
795
+ this.stdout = fields.stdout;
796
+ this.stderr = fields.stderr;
797
+ }
798
+
799
+ static fromWire(data) {
800
+ return new InstanceResult({
801
+ resources:
802
+ data["resources"] == null
803
+ ? data["resources"]
804
+ : InstanceResultResources.fromWire(data["resources"]),
805
+ state:
806
+ data["state"] == null
807
+ ? data["state"]
808
+ : InstanceResultState.fromWire(data["state"]),
809
+ stdout:
810
+ data["stdout"] == null
811
+ ? data["stdout"]
812
+ : StreamRepr.fromWire(data["stdout"]),
813
+ stderr:
814
+ data["stderr"] == null
815
+ ? data["stderr"]
816
+ : StreamRepr.fromWire(data["stderr"]),
817
+ });
818
+ }
819
+
820
+ toWire() {
821
+ const data = {};
822
+ if (this.resources !== undefined) {
823
+ data["resources"] =
824
+ this.resources === null ? null : this.resources.toWire();
825
+ }
826
+ if (this.state !== undefined) {
827
+ data["state"] = this.state === null ? null : this.state.toWire();
828
+ }
829
+ if (this.stdout !== undefined) {
830
+ data["stdout"] = this.stdout === null ? null : this.stdout.toWire();
831
+ }
832
+ if (this.stderr !== undefined) {
833
+ data["stderr"] = this.stderr === null ? null : this.stderr.toWire();
834
+ }
835
+ return data;
836
+ }
837
+ }
838
+
839
+ export class InstanceSpawnResponse {
840
+ constructor(fields = {}) {
841
+ this.uuid = fields.uuid;
842
+ this.command = fields.command;
843
+ this.image = fields.image;
844
+ this.hostname = fields.hostname;
845
+ this.args = fields.args;
846
+ this.shell = fields.shell;
847
+ this.env = fields.env;
848
+ this.preserve_env = fields.preserve_env;
849
+ this.cwd = fields.cwd;
850
+ this.uid = fields.uid;
851
+ this.gid = fields.gid;
852
+ this.resources_limits = fields.resources_limits;
853
+ this.stdin = fields.stdin;
854
+ this.timeout = fields.timeout;
855
+ this.truncate_output_at = fields.truncate_output_at;
856
+ this.disposable = fields.disposable;
857
+ this.files = fields.files;
858
+ this.result = fields.result;
859
+ }
860
+
861
+ static fromWire(data) {
862
+ return new InstanceSpawnResponse({
863
+ uuid: data["uuid"],
864
+ command: data["command"],
865
+ image: data["image"],
866
+ hostname: data["hostname"],
867
+ args: data["args"],
868
+ shell: data["shell"],
869
+ env: data["env"],
870
+ preserve_env: data["preserve_env"],
871
+ cwd: data["cwd"],
872
+ uid: data["uid"],
873
+ gid: data["gid"],
874
+ resources_limits:
875
+ data["resources_limits"] == null
876
+ ? data["resources_limits"]
877
+ : InstanceResourcesLimits.fromWire(data["resources_limits"]),
878
+ stdin:
879
+ data["stdin"] == null
880
+ ? data["stdin"]
881
+ : StreamRepr.fromWire(data["stdin"]),
882
+ timeout: data["timeout"],
883
+ truncate_output_at: data["truncate_output_at"],
884
+ disposable: data["disposable"],
885
+ files:
886
+ data["files"] == null
887
+ ? data["files"]
888
+ : Object.fromEntries(
889
+ Object.entries(data["files"]).map(([key, value]) => [
890
+ key,
891
+ FileSpec.fromWire(value),
892
+ ]),
893
+ ),
894
+ result:
895
+ data["result"] == null
896
+ ? data["result"]
897
+ : InstanceResult.fromWire(data["result"]),
898
+ });
899
+ }
900
+
901
+ toWire() {
902
+ const data = {};
903
+ if (this.uuid !== undefined) {
904
+ data["uuid"] = this.uuid;
905
+ }
906
+ if (this.command !== undefined) {
907
+ data["command"] = this.command;
908
+ }
909
+ if (this.image !== undefined) {
910
+ data["image"] = this.image;
911
+ }
912
+ if (this.hostname !== undefined) {
913
+ data["hostname"] = this.hostname;
914
+ }
915
+ if (this.args !== undefined) {
916
+ data["args"] = this.args;
917
+ }
918
+ if (this.shell !== undefined) {
919
+ data["shell"] = this.shell;
920
+ }
921
+ if (this.env !== undefined) {
922
+ data["env"] = this.env;
923
+ }
924
+ if (this.preserve_env !== undefined) {
925
+ data["preserve_env"] = this.preserve_env;
926
+ }
927
+ if (this.cwd !== undefined) {
928
+ data["cwd"] = this.cwd;
929
+ }
930
+ if (this.uid !== undefined) {
931
+ data["uid"] = this.uid;
932
+ }
933
+ if (this.gid !== undefined) {
934
+ data["gid"] = this.gid;
935
+ }
936
+ if (this.resources_limits !== undefined) {
937
+ data["resources_limits"] =
938
+ this.resources_limits === null ? null : this.resources_limits.toWire();
939
+ }
940
+ if (this.stdin !== undefined) {
941
+ data["stdin"] = this.stdin === null ? null : this.stdin.toWire();
942
+ }
943
+ if (this.timeout !== undefined) {
944
+ data["timeout"] = this.timeout;
945
+ }
946
+ if (this.truncate_output_at !== undefined) {
947
+ data["truncate_output_at"] = this.truncate_output_at;
948
+ }
949
+ if (this.disposable !== undefined) {
950
+ data["disposable"] = this.disposable;
951
+ }
952
+ if (this.files !== undefined) {
953
+ data["files"] =
954
+ this.files === null
955
+ ? null
956
+ : Object.fromEntries(
957
+ Object.entries(this.files).map(([key, value]) => [
958
+ key,
959
+ value.toWire(),
960
+ ]),
961
+ );
962
+ }
963
+ if (this.result !== undefined) {
964
+ data["result"] = this.result === null ? null : this.result.toWire();
965
+ }
966
+ return data;
967
+ }
968
+ }
969
+
970
+ export class OperationSummary {
971
+ constructor(fields = {}) {
972
+ this.uuid = fields.uuid;
973
+ this.kind = fields.kind;
974
+ this.status = fields.status;
975
+ this.error = fields.error;
976
+ this.created_at = fields.created_at;
977
+ this.duration = fields.duration;
978
+ this.image_size = fields.image_size;
979
+ this.consumed_cpu = fields.consumed_cpu;
980
+ this.consumed_memory = fields.consumed_memory;
981
+ this.image_uuid = fields.image_uuid;
982
+ this.result_image_uuid = fields.result_image_uuid;
983
+ }
984
+
985
+ static fromWire(data) {
986
+ return new OperationSummary({
987
+ uuid: data["uuid"],
988
+ kind: data["kind"],
989
+ status: data["status"],
990
+ error: data["error"],
991
+ created_at: data["created_at"],
992
+ duration: data["duration"],
993
+ image_size: data["image_size"],
994
+ consumed_cpu: data["consumed_cpu"],
995
+ consumed_memory: data["consumed_memory"],
996
+ image_uuid: data["image_uuid"],
997
+ result_image_uuid: data["result_image_uuid"],
998
+ });
999
+ }
1000
+
1001
+ toWire() {
1002
+ const data = {};
1003
+ if (this.uuid !== undefined) {
1004
+ data["uuid"] = this.uuid;
1005
+ }
1006
+ if (this.kind !== undefined) {
1007
+ data["kind"] = this.kind;
1008
+ }
1009
+ if (this.status !== undefined) {
1010
+ data["status"] = this.status;
1011
+ }
1012
+ if (this.error !== undefined) {
1013
+ data["error"] = this.error;
1014
+ }
1015
+ if (this.created_at !== undefined) {
1016
+ data["created_at"] = this.created_at;
1017
+ }
1018
+ if (this.duration !== undefined) {
1019
+ data["duration"] = this.duration;
1020
+ }
1021
+ if (this.image_size !== undefined) {
1022
+ data["image_size"] = this.image_size;
1023
+ }
1024
+ if (this.consumed_cpu !== undefined) {
1025
+ data["consumed_cpu"] = this.consumed_cpu;
1026
+ }
1027
+ if (this.consumed_memory !== undefined) {
1028
+ data["consumed_memory"] = this.consumed_memory;
1029
+ }
1030
+ if (this.image_uuid !== undefined) {
1031
+ data["image_uuid"] = this.image_uuid;
1032
+ }
1033
+ if (this.result_image_uuid !== undefined) {
1034
+ data["result_image_uuid"] = this.result_image_uuid;
1035
+ }
1036
+ return data;
1037
+ }
1038
+ }
1039
+
1040
+ export class OperationInstanceMetadata {
1041
+ constructor(fields = {}) {
1042
+ this.command = fields.command;
1043
+ this.image = fields.image;
1044
+ this.disposable = fields.disposable;
1045
+ this.hostname = fields.hostname;
1046
+ this.args = fields.args;
1047
+ this.shell = fields.shell;
1048
+ this.env = fields.env;
1049
+ this.preserve_env = fields.preserve_env;
1050
+ this.cwd = fields.cwd;
1051
+ this.uid = fields.uid;
1052
+ this.gid = fields.gid;
1053
+ this.resources_limits = fields.resources_limits;
1054
+ this.stdin = fields.stdin;
1055
+ this.timeout = fields.timeout;
1056
+ this.truncate_output_at = fields.truncate_output_at;
1057
+ this.files = fields.files;
1058
+ this.result = fields.result;
1059
+ }
1060
+
1061
+ static fromWire(data) {
1062
+ return new OperationInstanceMetadata({
1063
+ command: data["command"],
1064
+ image: data["image"],
1065
+ disposable: data["disposable"],
1066
+ hostname: data["hostname"],
1067
+ args: data["args"],
1068
+ shell: data["shell"],
1069
+ env: data["env"],
1070
+ preserve_env: data["preserve_env"],
1071
+ cwd: data["cwd"],
1072
+ uid: data["uid"],
1073
+ gid: data["gid"],
1074
+ resources_limits:
1075
+ data["resources_limits"] == null
1076
+ ? data["resources_limits"]
1077
+ : InstanceResourcesLimits.fromWire(data["resources_limits"]),
1078
+ stdin:
1079
+ data["stdin"] == null
1080
+ ? data["stdin"]
1081
+ : StreamRepr.fromWire(data["stdin"]),
1082
+ timeout: data["timeout"],
1083
+ truncate_output_at: data["truncate_output_at"],
1084
+ files:
1085
+ data["files"] == null
1086
+ ? data["files"]
1087
+ : Object.fromEntries(
1088
+ Object.entries(data["files"]).map(([key, value]) => [
1089
+ key,
1090
+ FileSpec.fromWire(value),
1091
+ ]),
1092
+ ),
1093
+ result:
1094
+ data["result"] == null
1095
+ ? data["result"]
1096
+ : InstanceResult.fromWire(data["result"]),
1097
+ });
1098
+ }
1099
+
1100
+ toWire() {
1101
+ const data = {};
1102
+ if (this.command !== undefined) {
1103
+ data["command"] = this.command;
1104
+ }
1105
+ if (this.image !== undefined) {
1106
+ data["image"] = this.image;
1107
+ }
1108
+ if (this.disposable !== undefined) {
1109
+ data["disposable"] = this.disposable;
1110
+ }
1111
+ if (this.hostname !== undefined) {
1112
+ data["hostname"] = this.hostname;
1113
+ }
1114
+ if (this.args !== undefined) {
1115
+ data["args"] = this.args;
1116
+ }
1117
+ if (this.shell !== undefined) {
1118
+ data["shell"] = this.shell;
1119
+ }
1120
+ if (this.env !== undefined) {
1121
+ data["env"] = this.env;
1122
+ }
1123
+ if (this.preserve_env !== undefined) {
1124
+ data["preserve_env"] = this.preserve_env;
1125
+ }
1126
+ if (this.cwd !== undefined) {
1127
+ data["cwd"] = this.cwd;
1128
+ }
1129
+ if (this.uid !== undefined) {
1130
+ data["uid"] = this.uid;
1131
+ }
1132
+ if (this.gid !== undefined) {
1133
+ data["gid"] = this.gid;
1134
+ }
1135
+ if (this.resources_limits !== undefined) {
1136
+ data["resources_limits"] =
1137
+ this.resources_limits === null ? null : this.resources_limits.toWire();
1138
+ }
1139
+ if (this.stdin !== undefined) {
1140
+ data["stdin"] = this.stdin === null ? null : this.stdin.toWire();
1141
+ }
1142
+ if (this.timeout !== undefined) {
1143
+ data["timeout"] = this.timeout;
1144
+ }
1145
+ if (this.truncate_output_at !== undefined) {
1146
+ data["truncate_output_at"] = this.truncate_output_at;
1147
+ }
1148
+ if (this.files !== undefined) {
1149
+ data["files"] =
1150
+ this.files === null
1151
+ ? null
1152
+ : Object.fromEntries(
1153
+ Object.entries(this.files).map(([key, value]) => [
1154
+ key,
1155
+ value.toWire(),
1156
+ ]),
1157
+ );
1158
+ }
1159
+ if (this.result !== undefined) {
1160
+ data["result"] = this.result === null ? null : this.result.toWire();
1161
+ }
1162
+ return data;
1163
+ }
1164
+ }
1165
+
1166
+ /** Result of the operation, if any */
1167
+ export class OperationResult {
1168
+ constructor(fields = {}) {
1169
+ this.image = fields.image;
1170
+ this.tag = fields.tag;
1171
+ }
1172
+
1173
+ static fromWire(data) {
1174
+ return new OperationResult({
1175
+ image: data["image"],
1176
+ tag: data["tag"],
1177
+ });
1178
+ }
1179
+
1180
+ toWire() {
1181
+ const data = {};
1182
+ if (this.image !== undefined) {
1183
+ data["image"] = this.image;
1184
+ }
1185
+ if (this.tag !== undefined) {
1186
+ data["tag"] = this.tag;
1187
+ }
1188
+ return data;
1189
+ }
1190
+ }
1191
+
1192
+ export class OperationResponse {
1193
+ constructor(fields = {}) {
1194
+ this.uuid = fields.uuid;
1195
+ this.kind = fields.kind;
1196
+ this.status = fields.status;
1197
+ this.error = fields.error;
1198
+ this.created_at = fields.created_at;
1199
+ this.duration = fields.duration;
1200
+ this.image_size = fields.image_size;
1201
+ this.consumed_cpu = fields.consumed_cpu;
1202
+ this.consumed_memory = fields.consumed_memory;
1203
+ this.image_uuid = fields.image_uuid;
1204
+ this.result_image_uuid = fields.result_image_uuid;
1205
+ this.metadata = fields.metadata;
1206
+ this.result = fields.result;
1207
+ }
1208
+
1209
+ static fromWire(data) {
1210
+ return new OperationResponse({
1211
+ uuid: data["uuid"],
1212
+ kind: data["kind"],
1213
+ status: data["status"],
1214
+ error: data["error"],
1215
+ created_at: data["created_at"],
1216
+ duration: data["duration"],
1217
+ image_size: data["image_size"],
1218
+ consumed_cpu: data["consumed_cpu"],
1219
+ consumed_memory: data["consumed_memory"],
1220
+ image_uuid: data["image_uuid"],
1221
+ result_image_uuid: data["result_image_uuid"],
1222
+ metadata:
1223
+ data["metadata"] == null
1224
+ ? data["metadata"]
1225
+ : data["kind"] === "instance"
1226
+ ? OperationInstanceMetadata.fromWire(data["metadata"])
1227
+ : ImageImportMetadata.fromWire(data["metadata"]),
1228
+ result:
1229
+ data["result"] == null
1230
+ ? data["result"]
1231
+ : OperationResult.fromWire(data["result"]),
1232
+ });
1233
+ }
1234
+
1235
+ toWire() {
1236
+ const data = {};
1237
+ if (this.uuid !== undefined) {
1238
+ data["uuid"] = this.uuid;
1239
+ }
1240
+ if (this.kind !== undefined) {
1241
+ data["kind"] = this.kind;
1242
+ }
1243
+ if (this.status !== undefined) {
1244
+ data["status"] = this.status;
1245
+ }
1246
+ if (this.error !== undefined) {
1247
+ data["error"] = this.error;
1248
+ }
1249
+ if (this.created_at !== undefined) {
1250
+ data["created_at"] = this.created_at;
1251
+ }
1252
+ if (this.duration !== undefined) {
1253
+ data["duration"] = this.duration;
1254
+ }
1255
+ if (this.image_size !== undefined) {
1256
+ data["image_size"] = this.image_size;
1257
+ }
1258
+ if (this.consumed_cpu !== undefined) {
1259
+ data["consumed_cpu"] = this.consumed_cpu;
1260
+ }
1261
+ if (this.consumed_memory !== undefined) {
1262
+ data["consumed_memory"] = this.consumed_memory;
1263
+ }
1264
+ if (this.image_uuid !== undefined) {
1265
+ data["image_uuid"] = this.image_uuid;
1266
+ }
1267
+ if (this.result_image_uuid !== undefined) {
1268
+ data["result_image_uuid"] = this.result_image_uuid;
1269
+ }
1270
+ if (this.metadata !== undefined) {
1271
+ data["metadata"] = this.metadata === null ? null : this.metadata.toWire();
1272
+ }
1273
+ if (this.result !== undefined) {
1274
+ data["result"] = this.result === null ? null : this.result.toWire();
1275
+ }
1276
+ return data;
1277
+ }
1278
+ }
1279
+
1280
+ export class Error {
1281
+ constructor(fields = {}) {
1282
+ this.error = fields.error;
1283
+ this.status = fields.status;
1284
+ this.traceback = fields.traceback;
1285
+ }
1286
+
1287
+ static fromWire(data) {
1288
+ return new Error({
1289
+ error: data["error"],
1290
+ status: data["status"],
1291
+ traceback: data["traceback"],
1292
+ });
1293
+ }
1294
+
1295
+ toWire() {
1296
+ const data = {};
1297
+ if (this.error !== undefined) {
1298
+ data["error"] = this.error;
1299
+ }
1300
+ if (this.status !== undefined) {
1301
+ data["status"] = this.status;
1302
+ }
1303
+ if (this.traceback !== undefined) {
1304
+ data["traceback"] = this.traceback;
1305
+ }
1306
+ return data;
1307
+ }
1308
+ }
1309
+
1310
+ export class FileResponse {
1311
+ constructor(fields = {}) {
1312
+ this.uuid = fields.uuid;
1313
+ this.sha256 = fields.sha256;
1314
+ this.size = fields.size;
1315
+ }
1316
+
1317
+ static fromWire(data) {
1318
+ return new FileResponse({
1319
+ uuid: data["uuid"],
1320
+ sha256: data["sha256"],
1321
+ size: data["size"],
1322
+ });
1323
+ }
1324
+
1325
+ toWire() {
1326
+ const data = {};
1327
+ if (this.uuid !== undefined) {
1328
+ data["uuid"] = this.uuid;
1329
+ }
1330
+ if (this.sha256 !== undefined) {
1331
+ data["sha256"] = this.sha256;
1332
+ }
1333
+ if (this.size !== undefined) {
1334
+ data["size"] = this.size;
1335
+ }
1336
+ return data;
1337
+ }
1338
+ }
1339
+
1340
+ export class File {
1341
+ constructor(fields = {}) {
1342
+ this.uuid = fields.uuid;
1343
+ this.sha256 = fields.sha256;
1344
+ this.size = fields.size;
1345
+ this.created_at = fields.created_at;
1346
+ this.updated_at = fields.updated_at;
1347
+ }
1348
+
1349
+ static fromWire(data) {
1350
+ return new File({
1351
+ uuid: data["uuid"],
1352
+ sha256: data["sha256"],
1353
+ size: data["size"],
1354
+ created_at: parseDatetime(data["created_at"]),
1355
+ updated_at: parseDatetime(data["updated_at"]),
1356
+ });
1357
+ }
1358
+
1359
+ toWire() {
1360
+ const data = {};
1361
+ if (this.uuid !== undefined) {
1362
+ data["uuid"] = this.uuid;
1363
+ }
1364
+ if (this.sha256 !== undefined) {
1365
+ data["sha256"] = this.sha256;
1366
+ }
1367
+ if (this.size !== undefined) {
1368
+ data["size"] = this.size;
1369
+ }
1370
+ if (this.created_at !== undefined) {
1371
+ data["created_at"] =
1372
+ this.created_at === null ? null : this.created_at.toISOString();
1373
+ }
1374
+ if (this.updated_at !== undefined) {
1375
+ data["updated_at"] =
1376
+ this.updated_at === null ? null : this.updated_at.toISOString();
1377
+ }
1378
+ return data;
1379
+ }
1380
+ }
1381
+
1382
+ export class FilesListResponse {
1383
+ constructor(fields = {}) {
1384
+ this.files = fields.files;
1385
+ }
1386
+
1387
+ static fromWire(data) {
1388
+ return new FilesListResponse({
1389
+ files:
1390
+ data["files"] == null
1391
+ ? data["files"]
1392
+ : data["files"].map((item) => File.fromWire(item)),
1393
+ });
1394
+ }
1395
+
1396
+ toWire() {
1397
+ const data = {};
1398
+ if (this.files !== undefined) {
1399
+ data["files"] =
1400
+ this.files === null ? null : this.files.map((item) => item.toWire());
1401
+ }
1402
+ return data;
1403
+ }
1404
+ }
1405
+
1406
+ export class WhoAmIResponse {
1407
+ constructor(fields = {}) {
1408
+ this.token_uuid = fields.token_uuid;
1409
+ this.token_expiration = fields.token_expiration;
1410
+ this.permissions = fields.permissions;
1411
+ this.operations_stat = fields.operations_stat;
1412
+ this.limits = fields.limits;
1413
+ }
1414
+
1415
+ static fromWire(data) {
1416
+ return new WhoAmIResponse({
1417
+ token_uuid: data["token_uuid"],
1418
+ token_expiration: data["token_expiration"],
1419
+ permissions: data["permissions"],
1420
+ operations_stat: data["operations_stat"],
1421
+ limits: data["limits"],
1422
+ });
1423
+ }
1424
+
1425
+ toWire() {
1426
+ const data = {};
1427
+ if (this.token_uuid !== undefined) {
1428
+ data["token_uuid"] = this.token_uuid;
1429
+ }
1430
+ if (this.token_expiration !== undefined) {
1431
+ data["token_expiration"] = this.token_expiration;
1432
+ }
1433
+ if (this.permissions !== undefined) {
1434
+ data["permissions"] = this.permissions;
1435
+ }
1436
+ if (this.operations_stat !== undefined) {
1437
+ data["operations_stat"] = this.operations_stat;
1438
+ }
1439
+ if (this.limits !== undefined) {
1440
+ data["limits"] = this.limits;
1441
+ }
1442
+ return data;
1443
+ }
1444
+ }
1445
+
1446
+ /** One event in the operation's event log. */
1447
+ export class OperationEvent {
1448
+ constructor(fields = {}) {
1449
+ this.id = fields.id;
1450
+ this.ts = fields.ts;
1451
+ this.type = fields.type;
1452
+ this.data = fields.data;
1453
+ this.spid = fields.spid;
1454
+ }
1455
+
1456
+ static fromWire(data) {
1457
+ return new OperationEvent({
1458
+ id: data["id"],
1459
+ ts: parseDatetime(data["ts"]),
1460
+ type: data["type"],
1461
+ data: parseEventData(data["type"], data["data"]),
1462
+ spid: data["spid"],
1463
+ });
1464
+ }
1465
+
1466
+ toWire() {
1467
+ const data = {};
1468
+ if (this.id !== undefined) {
1469
+ data["id"] = this.id;
1470
+ }
1471
+ if (this.ts !== undefined) {
1472
+ data["ts"] = this.ts === null ? null : this.ts.toISOString();
1473
+ }
1474
+ if (this.type !== undefined) {
1475
+ data["type"] = this.type;
1476
+ }
1477
+ if (this.data !== undefined) {
1478
+ data["data"] =
1479
+ this.data === null
1480
+ ? null
1481
+ : typeof this.data.toWire === "function"
1482
+ ? this.data.toWire()
1483
+ : this.data;
1484
+ }
1485
+ if (this.spid !== undefined) {
1486
+ data["spid"] = this.spid;
1487
+ }
1488
+ return data;
1489
+ }
1490
+ }
1491
+
1492
+ /** Operation-level startup snapshot. `hostname`, `kernel`, */
1493
+ export class EventDataInit {
1494
+ constructor(fields = {}) {
1495
+ this.started_at = fields.started_at;
1496
+ this.runtime_path = fields.runtime_path;
1497
+ this.verbose = fields.verbose;
1498
+ this.init_pid = fields.init_pid;
1499
+ this.hostname = fields.hostname;
1500
+ this.kernel = fields.kernel;
1501
+ this.machine = fields.machine;
1502
+ this.boot_id = fields.boot_id;
1503
+ }
1504
+
1505
+ static fromWire(data) {
1506
+ return new EventDataInit({
1507
+ started_at: parseDatetime(data["started_at"]),
1508
+ runtime_path: data["runtime_path"],
1509
+ verbose: data["verbose"],
1510
+ init_pid: data["init_pid"],
1511
+ hostname: data["hostname"],
1512
+ kernel: data["kernel"],
1513
+ machine: data["machine"],
1514
+ boot_id: data["boot_id"],
1515
+ });
1516
+ }
1517
+
1518
+ toWire() {
1519
+ const data = {};
1520
+ if (this.started_at !== undefined) {
1521
+ data["started_at"] =
1522
+ this.started_at === null ? null : this.started_at.toISOString();
1523
+ }
1524
+ if (this.runtime_path !== undefined) {
1525
+ data["runtime_path"] = this.runtime_path;
1526
+ }
1527
+ if (this.verbose !== undefined) {
1528
+ data["verbose"] = this.verbose;
1529
+ }
1530
+ if (this.init_pid !== undefined) {
1531
+ data["init_pid"] = this.init_pid;
1532
+ }
1533
+ if (this.hostname !== undefined) {
1534
+ data["hostname"] = this.hostname;
1535
+ }
1536
+ if (this.kernel !== undefined) {
1537
+ data["kernel"] = this.kernel;
1538
+ }
1539
+ if (this.machine !== undefined) {
1540
+ data["machine"] = this.machine;
1541
+ }
1542
+ if (this.boot_id !== undefined) {
1543
+ data["boot_id"] = this.boot_id;
1544
+ }
1545
+ return data;
1546
+ }
1547
+ }
1548
+
1549
+ /** Process spawn parameters. `env` values for keys ending in */
1550
+ export class EventDataSpawn {
1551
+ constructor(fields = {}) {
1552
+ this.pid = fields.pid;
1553
+ this.command = fields.command;
1554
+ this.args = fields.args;
1555
+ this.shell = fields.shell;
1556
+ this.cwd = fields.cwd;
1557
+ this.uid = fields.uid;
1558
+ this.gid = fields.gid;
1559
+ this.timeout = fields.timeout;
1560
+ this.truncate_at = fields.truncate_at;
1561
+ this.env = fields.env;
1562
+ }
1563
+
1564
+ static fromWire(data) {
1565
+ return new EventDataSpawn({
1566
+ pid: data["pid"],
1567
+ command: data["command"],
1568
+ args: data["args"],
1569
+ shell: data["shell"],
1570
+ cwd: data["cwd"],
1571
+ uid: data["uid"],
1572
+ gid: data["gid"],
1573
+ timeout: data["timeout"],
1574
+ truncate_at: data["truncate_at"],
1575
+ env: data["env"],
1576
+ });
1577
+ }
1578
+
1579
+ toWire() {
1580
+ const data = {};
1581
+ if (this.pid !== undefined) {
1582
+ data["pid"] = this.pid;
1583
+ }
1584
+ if (this.command !== undefined) {
1585
+ data["command"] = this.command;
1586
+ }
1587
+ if (this.args !== undefined) {
1588
+ data["args"] = this.args;
1589
+ }
1590
+ if (this.shell !== undefined) {
1591
+ data["shell"] = this.shell;
1592
+ }
1593
+ if (this.cwd !== undefined) {
1594
+ data["cwd"] = this.cwd;
1595
+ }
1596
+ if (this.uid !== undefined) {
1597
+ data["uid"] = this.uid;
1598
+ }
1599
+ if (this.gid !== undefined) {
1600
+ data["gid"] = this.gid;
1601
+ }
1602
+ if (this.timeout !== undefined) {
1603
+ data["timeout"] = this.timeout;
1604
+ }
1605
+ if (this.truncate_at !== undefined) {
1606
+ data["truncate_at"] = this.truncate_at;
1607
+ }
1608
+ if (this.env !== undefined) {
1609
+ data["env"] = this.env;
1610
+ }
1611
+ return data;
1612
+ }
1613
+ }
1614
+
1615
+ /** Payload for `stdin` / `stdout` / `stderr` events. Encoding */
1616
+ export class EventDataStream {
1617
+ constructor(fields = {}) {
1618
+ this.value = fields.value;
1619
+ this.encoding = fields.encoding;
1620
+ this.truncated = fields.truncated;
1621
+ }
1622
+
1623
+ static fromWire(data) {
1624
+ return new EventDataStream({
1625
+ value: data["value"],
1626
+ encoding: data["encoding"],
1627
+ truncated: data["truncated"],
1628
+ });
1629
+ }
1630
+
1631
+ toWire() {
1632
+ const data = {};
1633
+ if (this.value !== undefined) {
1634
+ data["value"] = this.value;
1635
+ }
1636
+ if (this.encoding !== undefined) {
1637
+ data["encoding"] = this.encoding;
1638
+ }
1639
+ if (this.truncated !== undefined) {
1640
+ data["truncated"] = this.truncated;
1641
+ }
1642
+ return data;
1643
+ }
1644
+
1645
+ /** The payload decoded to raw bytes; undecodable base64 becomes
1646
+ * empty bytes instead of failing a live stream. */
1647
+ asBytes() {
1648
+ if (!this.value) {
1649
+ return new Uint8Array();
1650
+ }
1651
+ if (this.encoding === "base64") {
1652
+ try {
1653
+ return base64ToBytes(this.value);
1654
+ } catch {
1655
+ return new Uint8Array();
1656
+ }
1657
+ }
1658
+ return textToBytes(this.value);
1659
+ }
1660
+
1661
+ /** The payload decoded to text. */
1662
+ asText() {
1663
+ if (this.encoding === "base64") {
1664
+ return bytesToText(this.asBytes());
1665
+ }
1666
+ return this.value;
1667
+ }
1668
+
1669
+ /** Build a payload from raw bytes: printable ASCII stays `ascii`,
1670
+ * anything else is base64-encoded - the server-side rule. */
1671
+ static fromBytes(value) {
1672
+ const printable = value.every(
1673
+ (byte) =>
1674
+ (byte >= 32 && byte < 127) || byte === 9 || byte === 10 || byte === 13,
1675
+ );
1676
+ if (printable) {
1677
+ return new this({
1678
+ value: new TextDecoder("ascii").decode(value),
1679
+ encoding: "ascii",
1680
+ });
1681
+ }
1682
+ return new this({ value: bytesToBase64(value), encoding: "base64" });
1683
+ }
1684
+
1685
+ /** Build a payload from text (UTF-8 encoded unless ASCII). */
1686
+ static fromText(value) {
1687
+ return this.fromBytes(textToBytes(value));
1688
+ }
1689
+ }
1690
+
1691
+ /** Resource usage snapshot for the process. Time fields are */
1692
+ export class EventResources {
1693
+ constructor(fields = {}) {
1694
+ this.user_time_us = fields.user_time_us;
1695
+ this.sys_time_us = fields.sys_time_us;
1696
+ this.max_rss_kb = fields.max_rss_kb;
1697
+ this.shared_memory = fields.shared_memory;
1698
+ this.unshared_memory = fields.unshared_memory;
1699
+ this.swaps = fields.swaps;
1700
+ this.minor_faults = fields.minor_faults;
1701
+ this.major_faults = fields.major_faults;
1702
+ this.voluntary_ctx_switches = fields.voluntary_ctx_switches;
1703
+ this.involuntary_ctx_switches = fields.involuntary_ctx_switches;
1704
+ this.block_input_ops = fields.block_input_ops;
1705
+ this.block_output_ops = fields.block_output_ops;
1706
+ this.ipc_msgs_sent = fields.ipc_msgs_sent;
1707
+ this.ipc_msgs_received = fields.ipc_msgs_received;
1708
+ this.signals_received = fields.signals_received;
1709
+ }
1710
+
1711
+ static fromWire(data) {
1712
+ return new EventResources({
1713
+ user_time_us: data["user_time_us"],
1714
+ sys_time_us: data["sys_time_us"],
1715
+ max_rss_kb: data["max_rss_kb"],
1716
+ shared_memory: data["shared_memory"],
1717
+ unshared_memory: data["unshared_memory"],
1718
+ swaps: data["swaps"],
1719
+ minor_faults: data["minor_faults"],
1720
+ major_faults: data["major_faults"],
1721
+ voluntary_ctx_switches: data["voluntary_ctx_switches"],
1722
+ involuntary_ctx_switches: data["involuntary_ctx_switches"],
1723
+ block_input_ops: data["block_input_ops"],
1724
+ block_output_ops: data["block_output_ops"],
1725
+ ipc_msgs_sent: data["ipc_msgs_sent"],
1726
+ ipc_msgs_received: data["ipc_msgs_received"],
1727
+ signals_received: data["signals_received"],
1728
+ });
1729
+ }
1730
+
1731
+ toWire() {
1732
+ const data = {};
1733
+ if (this.user_time_us !== undefined) {
1734
+ data["user_time_us"] = this.user_time_us;
1735
+ }
1736
+ if (this.sys_time_us !== undefined) {
1737
+ data["sys_time_us"] = this.sys_time_us;
1738
+ }
1739
+ if (this.max_rss_kb !== undefined) {
1740
+ data["max_rss_kb"] = this.max_rss_kb;
1741
+ }
1742
+ if (this.shared_memory !== undefined) {
1743
+ data["shared_memory"] = this.shared_memory;
1744
+ }
1745
+ if (this.unshared_memory !== undefined) {
1746
+ data["unshared_memory"] = this.unshared_memory;
1747
+ }
1748
+ if (this.swaps !== undefined) {
1749
+ data["swaps"] = this.swaps;
1750
+ }
1751
+ if (this.minor_faults !== undefined) {
1752
+ data["minor_faults"] = this.minor_faults;
1753
+ }
1754
+ if (this.major_faults !== undefined) {
1755
+ data["major_faults"] = this.major_faults;
1756
+ }
1757
+ if (this.voluntary_ctx_switches !== undefined) {
1758
+ data["voluntary_ctx_switches"] = this.voluntary_ctx_switches;
1759
+ }
1760
+ if (this.involuntary_ctx_switches !== undefined) {
1761
+ data["involuntary_ctx_switches"] = this.involuntary_ctx_switches;
1762
+ }
1763
+ if (this.block_input_ops !== undefined) {
1764
+ data["block_input_ops"] = this.block_input_ops;
1765
+ }
1766
+ if (this.block_output_ops !== undefined) {
1767
+ data["block_output_ops"] = this.block_output_ops;
1768
+ }
1769
+ if (this.ipc_msgs_sent !== undefined) {
1770
+ data["ipc_msgs_sent"] = this.ipc_msgs_sent;
1771
+ }
1772
+ if (this.ipc_msgs_received !== undefined) {
1773
+ data["ipc_msgs_received"] = this.ipc_msgs_received;
1774
+ }
1775
+ if (this.signals_received !== undefined) {
1776
+ data["signals_received"] = this.signals_received;
1777
+ }
1778
+ return data;
1779
+ }
1780
+ }
1781
+
1782
+ /** Process lifecycle close-out. Carries the exit code OR the */
1783
+ export class EventDataExit {
1784
+ constructor(fields = {}) {
1785
+ this.pid = fields.pid;
1786
+ this.code = fields.code;
1787
+ this.signal = fields.signal;
1788
+ this.timed_out = fields.timed_out;
1789
+ this.duration_ms = fields.duration_ms;
1790
+ this.resources = fields.resources;
1791
+ }
1792
+
1793
+ static fromWire(data) {
1794
+ return new EventDataExit({
1795
+ pid: data["pid"],
1796
+ code: data["code"],
1797
+ signal: data["signal"],
1798
+ timed_out: data["timed_out"],
1799
+ duration_ms: data["duration_ms"],
1800
+ resources: EventResources.fromWire(data["resources"]),
1801
+ });
1802
+ }
1803
+
1804
+ toWire() {
1805
+ const data = {};
1806
+ if (this.pid !== undefined) {
1807
+ data["pid"] = this.pid;
1808
+ }
1809
+ if (this.code !== undefined) {
1810
+ data["code"] = this.code;
1811
+ }
1812
+ if (this.signal !== undefined) {
1813
+ data["signal"] = this.signal;
1814
+ }
1815
+ if (this.timed_out !== undefined) {
1816
+ data["timed_out"] = this.timed_out;
1817
+ }
1818
+ if (this.duration_ms !== undefined) {
1819
+ data["duration_ms"] = this.duration_ms;
1820
+ }
1821
+ if (this.resources !== undefined) {
1822
+ data["resources"] =
1823
+ this.resources === null ? null : this.resources.toWire();
1824
+ }
1825
+ return data;
1826
+ }
1827
+ }
1828
+
1829
+ /** Per-stream summary emitted once on stream EOF when the */
1830
+ export class EventDataTruncated {
1831
+ constructor(fields = {}) {
1832
+ this.stream = fields.stream;
1833
+ this.bytes_emitted = fields.bytes_emitted;
1834
+ this.bytes_dropped = fields.bytes_dropped;
1835
+ }
1836
+
1837
+ static fromWire(data) {
1838
+ return new EventDataTruncated({
1839
+ stream: data["stream"],
1840
+ bytes_emitted: data["bytes_emitted"],
1841
+ bytes_dropped: data["bytes_dropped"],
1842
+ });
1843
+ }
1844
+
1845
+ toWire() {
1846
+ const data = {};
1847
+ if (this.stream !== undefined) {
1848
+ data["stream"] = this.stream;
1849
+ }
1850
+ if (this.bytes_emitted !== undefined) {
1851
+ data["bytes_emitted"] = this.bytes_emitted;
1852
+ }
1853
+ if (this.bytes_dropped !== undefined) {
1854
+ data["bytes_dropped"] = this.bytes_dropped;
1855
+ }
1856
+ return data;
1857
+ }
1858
+ }
1859
+
1860
+ /** Emitted at most once per operation when the cumulative */
1861
+ export class EventDataSizeCap {
1862
+ constructor(fields = {}) {
1863
+ this.limit_bytes = fields.limit_bytes;
1864
+ this.file_size = fields.file_size;
1865
+ }
1866
+
1867
+ static fromWire(data) {
1868
+ return new EventDataSizeCap({
1869
+ limit_bytes: data["limit_bytes"],
1870
+ file_size: data["file_size"],
1871
+ });
1872
+ }
1873
+
1874
+ toWire() {
1875
+ const data = {};
1876
+ if (this.limit_bytes !== undefined) {
1877
+ data["limit_bytes"] = this.limit_bytes;
1878
+ }
1879
+ if (this.file_size !== undefined) {
1880
+ data["file_size"] = this.file_size;
1881
+ }
1882
+ return data;
1883
+ }
1884
+ }
1885
+
1886
+ export class NetworkInterface {
1887
+ constructor(fields = {}) {
1888
+ this.name = fields.name;
1889
+ this.rx_bytes = fields.rx_bytes;
1890
+ this.rx_packets = fields.rx_packets;
1891
+ this.rx_errs = fields.rx_errs;
1892
+ this.rx_drop = fields.rx_drop;
1893
+ this.tx_bytes = fields.tx_bytes;
1894
+ this.tx_packets = fields.tx_packets;
1895
+ this.tx_errs = fields.tx_errs;
1896
+ this.tx_drop = fields.tx_drop;
1897
+ }
1898
+
1899
+ static fromWire(data) {
1900
+ return new NetworkInterface({
1901
+ name: data["name"],
1902
+ rx_bytes: data["rx_bytes"],
1903
+ rx_packets: data["rx_packets"],
1904
+ rx_errs: data["rx_errs"],
1905
+ rx_drop: data["rx_drop"],
1906
+ tx_bytes: data["tx_bytes"],
1907
+ tx_packets: data["tx_packets"],
1908
+ tx_errs: data["tx_errs"],
1909
+ tx_drop: data["tx_drop"],
1910
+ });
1911
+ }
1912
+
1913
+ toWire() {
1914
+ const data = {};
1915
+ if (this.name !== undefined) {
1916
+ data["name"] = this.name;
1917
+ }
1918
+ if (this.rx_bytes !== undefined) {
1919
+ data["rx_bytes"] = this.rx_bytes;
1920
+ }
1921
+ if (this.rx_packets !== undefined) {
1922
+ data["rx_packets"] = this.rx_packets;
1923
+ }
1924
+ if (this.rx_errs !== undefined) {
1925
+ data["rx_errs"] = this.rx_errs;
1926
+ }
1927
+ if (this.rx_drop !== undefined) {
1928
+ data["rx_drop"] = this.rx_drop;
1929
+ }
1930
+ if (this.tx_bytes !== undefined) {
1931
+ data["tx_bytes"] = this.tx_bytes;
1932
+ }
1933
+ if (this.tx_packets !== undefined) {
1934
+ data["tx_packets"] = this.tx_packets;
1935
+ }
1936
+ if (this.tx_errs !== undefined) {
1937
+ data["tx_errs"] = this.tx_errs;
1938
+ }
1939
+ if (this.tx_drop !== undefined) {
1940
+ data["tx_drop"] = this.tx_drop;
1941
+ }
1942
+ return data;
1943
+ }
1944
+ }
1945
+
1946
+ /** Subset of network params that were applied — empty keys */
1947
+ export class EventDataNetworkConfigured {
1948
+ constructor(fields = {}) {
1949
+ this.ip4 = fields.ip4;
1950
+ this.ip4_gw = fields.ip4_gw;
1951
+ this.ip6 = fields.ip6;
1952
+ this.ip6_gw = fields.ip6_gw;
1953
+ this.gw_mac = fields.gw_mac;
1954
+ this.nameserver = fields.nameserver;
1955
+ }
1956
+
1957
+ static fromWire(data) {
1958
+ return new EventDataNetworkConfigured({
1959
+ ip4: data["ip4"],
1960
+ ip4_gw: data["ip4_gw"],
1961
+ ip6: data["ip6"],
1962
+ ip6_gw: data["ip6_gw"],
1963
+ gw_mac: data["gw_mac"],
1964
+ nameserver: data["nameserver"],
1965
+ });
1966
+ }
1967
+
1968
+ toWire() {
1969
+ const data = {};
1970
+ if (this.ip4 !== undefined) {
1971
+ data["ip4"] = this.ip4;
1972
+ }
1973
+ if (this.ip4_gw !== undefined) {
1974
+ data["ip4_gw"] = this.ip4_gw;
1975
+ }
1976
+ if (this.ip6 !== undefined) {
1977
+ data["ip6"] = this.ip6;
1978
+ }
1979
+ if (this.ip6_gw !== undefined) {
1980
+ data["ip6_gw"] = this.ip6_gw;
1981
+ }
1982
+ if (this.gw_mac !== undefined) {
1983
+ data["gw_mac"] = this.gw_mac;
1984
+ }
1985
+ if (this.nameserver !== undefined) {
1986
+ data["nameserver"] = this.nameserver;
1987
+ }
1988
+ return data;
1989
+ }
1990
+ }
1991
+
1992
+ /** Per-interface counters plus the configured network state. */
1993
+ export class EventDataNetwork {
1994
+ constructor(fields = {}) {
1995
+ this.interfaces = fields.interfaces;
1996
+ this.configured = fields.configured;
1997
+ this.error = fields.error;
1998
+ }
1999
+
2000
+ static fromWire(data) {
2001
+ return new EventDataNetwork({
2002
+ interfaces: data["interfaces"].map((item) =>
2003
+ NetworkInterface.fromWire(item),
2004
+ ),
2005
+ configured:
2006
+ data["configured"] == null
2007
+ ? data["configured"]
2008
+ : EventDataNetworkConfigured.fromWire(data["configured"]),
2009
+ error: data["error"],
2010
+ });
2011
+ }
2012
+
2013
+ toWire() {
2014
+ const data = {};
2015
+ if (this.interfaces !== undefined) {
2016
+ data["interfaces"] =
2017
+ this.interfaces === null
2018
+ ? null
2019
+ : this.interfaces.map((item) => item.toWire());
2020
+ }
2021
+ if (this.configured !== undefined) {
2022
+ data["configured"] =
2023
+ this.configured === null ? null : this.configured.toWire();
2024
+ }
2025
+ if (this.error !== undefined) {
2026
+ data["error"] = this.error;
2027
+ }
2028
+ return data;
2029
+ }
2030
+ }
2031
+
2032
+ /** Stream-terminating marker emitted right before the operation */
2033
+ export class EventDataShutdown {
2034
+ constructor(fields = {}) {
2035
+ this.stopped_at = fields.stopped_at;
2036
+ this.reason = fields.reason;
2037
+ }
2038
+
2039
+ static fromWire(data) {
2040
+ return new EventDataShutdown({
2041
+ stopped_at: parseDatetime(data["stopped_at"]),
2042
+ reason: data["reason"],
2043
+ });
2044
+ }
2045
+
2046
+ toWire() {
2047
+ const data = {};
2048
+ if (this.stopped_at !== undefined) {
2049
+ data["stopped_at"] =
2050
+ this.stopped_at === null ? null : this.stopped_at.toISOString();
2051
+ }
2052
+ if (this.reason !== undefined) {
2053
+ data["reason"] = this.reason;
2054
+ }
2055
+ return data;
2056
+ }
2057
+ }
2058
+
2059
+ /** Terminal system-event payload, emitted once when the */
2060
+ export class EventDataCompletion {
2061
+ constructor(fields = {}) {
2062
+ this.status = fields.status;
2063
+ this.duration_ms = fields.duration_ms;
2064
+ this.result_image_uuid = fields.result_image_uuid;
2065
+ this.error = fields.error;
2066
+ this.image_size_bytes = fields.image_size_bytes;
2067
+ }
2068
+
2069
+ static fromWire(data) {
2070
+ return new EventDataCompletion({
2071
+ status: data["status"],
2072
+ duration_ms: data["duration_ms"],
2073
+ result_image_uuid: data["result_image_uuid"],
2074
+ error: data["error"],
2075
+ image_size_bytes: data["image_size_bytes"],
2076
+ });
2077
+ }
2078
+
2079
+ toWire() {
2080
+ const data = {};
2081
+ if (this.status !== undefined) {
2082
+ data["status"] = this.status;
2083
+ }
2084
+ if (this.duration_ms !== undefined) {
2085
+ data["duration_ms"] = this.duration_ms;
2086
+ }
2087
+ if (this.result_image_uuid !== undefined) {
2088
+ data["result_image_uuid"] = this.result_image_uuid;
2089
+ }
2090
+ if (this.error !== undefined) {
2091
+ data["error"] = this.error;
2092
+ }
2093
+ if (this.image_size_bytes !== undefined) {
2094
+ data["image_size_bytes"] = this.image_size_bytes;
2095
+ }
2096
+ return data;
2097
+ }
2098
+ }
2099
+
2100
+ export const EVENT_DATA_PARSERS = {
2101
+ init: EventDataInit,
2102
+ spawn: EventDataSpawn,
2103
+ stdin: EventDataStream,
2104
+ stdout: EventDataStream,
2105
+ stderr: EventDataStream,
2106
+ exit: EventDataExit,
2107
+ truncated: EventDataTruncated,
2108
+ size_cap: EventDataSizeCap,
2109
+ network: EventDataNetwork,
2110
+ shutdown: EventDataShutdown,
2111
+ completion: EventDataCompletion,
2112
+ };
2113
+
2114
+ /** Decode a per-type event payload.
2115
+ *
2116
+ * Unknown event types and payloads that do not match the documented
2117
+ * schema - a non-object body included - are returned as-is instead
2118
+ * of failing the stream.
2119
+ */
2120
+ export function parseEventData(eventType, data) {
2121
+ if (data === null || typeof data !== "object" || Array.isArray(data)) {
2122
+ return data;
2123
+ }
2124
+ const cls = EVENT_DATA_PARSERS[eventType];
2125
+ if (cls === undefined) {
2126
+ return data;
2127
+ }
2128
+ try {
2129
+ return cls.fromWire(data);
2130
+ } catch {
2131
+ return data;
2132
+ }
2133
+ }
2134
+
2135
+ /** Decode a stdout/stderr event payload to raw bytes. */
2136
+ export function decodeChunk(data) {
2137
+ if (data instanceof EventDataStream || data instanceof StreamRepr) {
2138
+ return data.asBytes();
2139
+ }
2140
+ if (data === null || typeof data !== "object" || Array.isArray(data)) {
2141
+ return new Uint8Array();
2142
+ }
2143
+ const value = data.value ?? "";
2144
+ if (typeof value !== "string" || !value) {
2145
+ return new Uint8Array();
2146
+ }
2147
+ if (String(data.encoding ?? "ascii") === "base64") {
2148
+ try {
2149
+ return base64ToBytes(value);
2150
+ } catch {
2151
+ return new Uint8Array();
2152
+ }
2153
+ }
2154
+ return textToBytes(value);
2155
+ }
2156
+
2157
+ /** Decode a StreamRepr payload (model or raw object) to a string. */
2158
+ export function decodeStream(stream) {
2159
+ if (stream instanceof EventDataStream || stream instanceof StreamRepr) {
2160
+ return stream.asText();
2161
+ }
2162
+ if (stream === null || typeof stream !== "object" || Array.isArray(stream)) {
2163
+ return "";
2164
+ }
2165
+ const value = stream.value ?? "";
2166
+ if (typeof value !== "string" || !value) {
2167
+ return "";
2168
+ }
2169
+ if (stream.encoding === "base64") {
2170
+ return bytesToText(decodeChunk(stream));
2171
+ }
2172
+ return value;
2173
+ }