tmex-cli 0.1.7 → 0.2.1

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.
Files changed (31) hide show
  1. package/dist/runtime/server.js +2924 -514
  2. package/package.json +2 -3
  3. package/resources/fe-dist/assets/DevicePage-6GBZ9nXN.css +32 -0
  4. package/resources/fe-dist/assets/DevicePage-DDl0kHG5.js +267 -0
  5. package/resources/fe-dist/assets/DevicePage-DDl0kHG5.js.map +1 -0
  6. package/resources/fe-dist/assets/{DevicesPage-DClS6lhB.js → DevicesPage-B4rMKhEo.js} +3 -3
  7. package/resources/fe-dist/assets/{DevicesPage-DClS6lhB.js.map → DevicesPage-B4rMKhEo.js.map} +1 -1
  8. package/resources/fe-dist/assets/SettingsPage-CNlEDOxd.js +17 -0
  9. package/resources/fe-dist/assets/SettingsPage-CNlEDOxd.js.map +1 -0
  10. package/resources/fe-dist/assets/index-35UZ83ei.js +200 -0
  11. package/resources/fe-dist/assets/index-35UZ83ei.js.map +1 -0
  12. package/resources/fe-dist/assets/index-CxzyWqMn.css +1 -0
  13. package/resources/fe-dist/assets/select-Eq1zbeJ1.js +17 -0
  14. package/resources/fe-dist/assets/select-Eq1zbeJ1.js.map +1 -0
  15. package/resources/fe-dist/assets/{switch-DbiHVHFg.js → switch-MW4hLOq6.js} +3 -3
  16. package/resources/fe-dist/assets/{switch-DbiHVHFg.js.map → switch-MW4hLOq6.js.map} +1 -1
  17. package/resources/fe-dist/assets/useValueChanged-ia5UgAxm.js +7 -0
  18. package/resources/fe-dist/assets/useValueChanged-ia5UgAxm.js.map +1 -0
  19. package/resources/fe-dist/index.html +2 -2
  20. package/resources/fe-dist/assets/DevicePage-Beg8tuEN.css +0 -32
  21. package/resources/fe-dist/assets/DevicePage-DXr7cn5f.js +0 -31
  22. package/resources/fe-dist/assets/DevicePage-DXr7cn5f.js.map +0 -1
  23. package/resources/fe-dist/assets/SettingsPage-DZPiSKLS.js +0 -17
  24. package/resources/fe-dist/assets/SettingsPage-DZPiSKLS.js.map +0 -1
  25. package/resources/fe-dist/assets/index-DLLCJhRn.css +0 -1
  26. package/resources/fe-dist/assets/index-uap7lu9-.js +0 -200
  27. package/resources/fe-dist/assets/index-uap7lu9-.js.map +0 -1
  28. package/resources/fe-dist/assets/select-DOLHUgAj.js +0 -12
  29. package/resources/fe-dist/assets/select-DOLHUgAj.js.map +0 -1
  30. package/resources/fe-dist/assets/useValueChanged-DoNZeDee.js +0 -2
  31. package/resources/fe-dist/assets/useValueChanged-DoNZeDee.js.map +0 -1
@@ -44,6 +44,751 @@ var __export = (target, all) => {
44
44
  };
45
45
  var __require = import.meta.require;
46
46
 
47
+ // ../../node_modules/.bun/@zorsh+zorsh@0.4.0/node_modules/@zorsh/zorsh/dist/src/binary-io.js
48
+ var require_binary_io = __commonJS((exports) => {
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.BinaryReader = exports.BinaryWriter = undefined;
51
+
52
+ class BinaryWriter {
53
+ buffer;
54
+ view;
55
+ offset = 0;
56
+ constructor(initialSize = 1024) {
57
+ this.buffer = new Uint8Array(initialSize);
58
+ this.view = new DataView(this.buffer.buffer);
59
+ }
60
+ ensureCapacity(additionalBytes) {
61
+ const requiredSize = this.offset + additionalBytes;
62
+ if (requiredSize <= this.buffer.length) {
63
+ return;
64
+ }
65
+ let newSize = this.buffer.length;
66
+ while (newSize < requiredSize) {
67
+ newSize *= 2;
68
+ }
69
+ const newBuffer = new Uint8Array(newSize);
70
+ newBuffer.set(this.buffer);
71
+ this.buffer = newBuffer;
72
+ this.view = new DataView(this.buffer.buffer);
73
+ }
74
+ writeUint8(value) {
75
+ this.ensureCapacity(1);
76
+ this.view.setUint8(this.offset, value);
77
+ this.offset += 1;
78
+ }
79
+ writeUint16(value) {
80
+ this.ensureCapacity(2);
81
+ this.view.setUint16(this.offset, value, true);
82
+ this.offset += 2;
83
+ }
84
+ writeUint32(value) {
85
+ this.ensureCapacity(4);
86
+ this.view.setUint32(this.offset, value, true);
87
+ this.offset += 4;
88
+ }
89
+ writeUint64(value) {
90
+ this.ensureCapacity(8);
91
+ this.view.setBigUint64(this.offset, value, true);
92
+ this.offset += 8;
93
+ }
94
+ writeUint128(value) {
95
+ this.ensureCapacity(16);
96
+ const low = value & BigInt("0xFFFFFFFFFFFFFFFF");
97
+ const high = value >> BigInt(64);
98
+ this.writeUint64(low);
99
+ this.writeUint64(high);
100
+ }
101
+ writeInt8(value) {
102
+ this.ensureCapacity(1);
103
+ this.view.setInt8(this.offset, value);
104
+ this.offset += 1;
105
+ }
106
+ writeInt16(value) {
107
+ this.ensureCapacity(2);
108
+ this.view.setInt16(this.offset, value, true);
109
+ this.offset += 2;
110
+ }
111
+ writeInt32(value) {
112
+ this.ensureCapacity(4);
113
+ this.view.setInt32(this.offset, value, true);
114
+ this.offset += 4;
115
+ }
116
+ writeInt64(value) {
117
+ this.ensureCapacity(8);
118
+ this.view.setBigInt64(this.offset, value, true);
119
+ this.offset += 8;
120
+ }
121
+ writeInt128(value) {
122
+ this.ensureCapacity(16);
123
+ const low = value & BigInt("0xFFFFFFFFFFFFFFFF");
124
+ const high = value >> BigInt(64);
125
+ this.writeInt64(low);
126
+ this.writeInt64(high);
127
+ }
128
+ writeFloat32(value) {
129
+ this.ensureCapacity(4);
130
+ this.view.setFloat32(this.offset, value, true);
131
+ this.offset += 4;
132
+ }
133
+ writeFloat64(value) {
134
+ this.ensureCapacity(8);
135
+ this.view.setFloat64(this.offset, value, true);
136
+ this.offset += 8;
137
+ }
138
+ writeBool(value) {
139
+ this.writeUint8(value ? 1 : 0);
140
+ }
141
+ writeString(value) {
142
+ const bytes = new TextEncoder().encode(value);
143
+ this.writeUint32(bytes.length);
144
+ this.ensureCapacity(bytes.length);
145
+ this.buffer.set(bytes, this.offset);
146
+ this.offset += bytes.length;
147
+ }
148
+ getBuffer() {
149
+ return this.buffer.slice(0, this.offset);
150
+ }
151
+ }
152
+ exports.BinaryWriter = BinaryWriter;
153
+
154
+ class BinaryReader {
155
+ buffer;
156
+ view;
157
+ offset = 0;
158
+ constructor(buffer) {
159
+ this.buffer = buffer;
160
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
161
+ }
162
+ readUint8() {
163
+ const value = this.view.getUint8(this.offset);
164
+ this.offset += 1;
165
+ return value;
166
+ }
167
+ readUint16() {
168
+ const value = this.view.getUint16(this.offset, true);
169
+ this.offset += 2;
170
+ return value;
171
+ }
172
+ readUint32() {
173
+ const value = this.view.getUint32(this.offset, true);
174
+ this.offset += 4;
175
+ return value;
176
+ }
177
+ readUint64() {
178
+ const value = this.view.getBigUint64(this.offset, true);
179
+ this.offset += 8;
180
+ return value;
181
+ }
182
+ readUint128() {
183
+ const low = this.readUint64();
184
+ const high = this.readUint64();
185
+ return high << BigInt(64) | low;
186
+ }
187
+ readInt8() {
188
+ const value = this.view.getInt8(this.offset);
189
+ this.offset += 1;
190
+ return value;
191
+ }
192
+ readInt16() {
193
+ const value = this.view.getInt16(this.offset, true);
194
+ this.offset += 2;
195
+ return value;
196
+ }
197
+ readInt32() {
198
+ const value = this.view.getInt32(this.offset, true);
199
+ this.offset += 4;
200
+ return value;
201
+ }
202
+ readInt64() {
203
+ const value = this.view.getBigInt64(this.offset, true);
204
+ this.offset += 8;
205
+ return value;
206
+ }
207
+ readInt128() {
208
+ const low = this.readUint64();
209
+ const high = this.readInt64();
210
+ return high << BigInt(64) | low;
211
+ }
212
+ readFloat32() {
213
+ const value = this.view.getFloat32(this.offset, true);
214
+ this.offset += 4;
215
+ return value;
216
+ }
217
+ readFloat64() {
218
+ const value = this.view.getFloat64(this.offset, true);
219
+ this.offset += 8;
220
+ return value;
221
+ }
222
+ readBool() {
223
+ return Boolean(this.readUint8());
224
+ }
225
+ readString() {
226
+ const length = this.readUint32();
227
+ const bytes = this.buffer.slice(this.offset, this.offset + length);
228
+ this.offset += length;
229
+ return new TextDecoder().decode(bytes);
230
+ }
231
+ getOffset() {
232
+ return this.offset;
233
+ }
234
+ }
235
+ exports.BinaryReader = BinaryReader;
236
+ });
237
+
238
+ // ../../node_modules/.bun/@zorsh+zorsh@0.4.0/node_modules/@zorsh/zorsh/dist/src/registry.js
239
+ var require_registry = __commonJS((exports) => {
240
+ Object.defineProperty(exports, "__esModule", { value: true });
241
+ exports.registry = exports.TypeRegistry = undefined;
242
+
243
+ class TypeRegistry {
244
+ handlers = new Map;
245
+ register(type, handler) {
246
+ this.handlers.set(type, handler);
247
+ }
248
+ getHandler(type) {
249
+ const handler = this.handlers.get(type);
250
+ if (!handler) {
251
+ throw new Error(`No handler registered for type: ${type}`);
252
+ }
253
+ return handler;
254
+ }
255
+ }
256
+ exports.TypeRegistry = TypeRegistry;
257
+ exports.registry = new TypeRegistry;
258
+ exports.registry.register("u8", {
259
+ write: (writer, value) => {
260
+ if (value < 0 || value > 255 || !Number.isInteger(value)) {
261
+ throw new Error("Value out of range for u8");
262
+ }
263
+ writer.writeUint8(value);
264
+ },
265
+ read: (reader) => reader.readUint8()
266
+ });
267
+ exports.registry.register("u16", {
268
+ write: (writer, value) => {
269
+ if (value < 0 || value > 65535 || !Number.isInteger(value)) {
270
+ throw new Error("Value out of range for u16");
271
+ }
272
+ writer.writeUint16(value);
273
+ },
274
+ read: (reader) => reader.readUint16()
275
+ });
276
+ exports.registry.register("u32", {
277
+ write: (writer, value) => {
278
+ if (value < 0 || value > 4294967295 || !Number.isInteger(value)) {
279
+ throw new Error("Value out of range for u32");
280
+ }
281
+ writer.writeUint32(value);
282
+ },
283
+ read: (reader) => reader.readUint32()
284
+ });
285
+ exports.registry.register("u64", {
286
+ write: (writer, value) => {
287
+ if (value < 0n || value > 18446744073709551615n) {
288
+ throw new Error("Value out of range for u64");
289
+ }
290
+ writer.writeUint64(value);
291
+ },
292
+ read: (reader) => reader.readUint64()
293
+ });
294
+ exports.registry.register("u128", {
295
+ write: (writer, value) => {
296
+ if (value < 0n || value > 340282366920938463463374607431768211455n) {
297
+ throw new Error("Value out of range for u128");
298
+ }
299
+ writer.writeUint128(value);
300
+ },
301
+ read: (reader) => reader.readUint128()
302
+ });
303
+ exports.registry.register("i8", {
304
+ write: (writer, value) => {
305
+ if (value < -128 || value > 127 || !Number.isInteger(value)) {
306
+ throw new Error("Value out of range for i8");
307
+ }
308
+ writer.writeInt8(value);
309
+ },
310
+ read: (reader) => reader.readInt8()
311
+ });
312
+ exports.registry.register("i16", {
313
+ write: (writer, value) => {
314
+ if (value < -32768 || value > 32767 || !Number.isInteger(value)) {
315
+ throw new Error("Value out of range for i16");
316
+ }
317
+ writer.writeInt16(value);
318
+ },
319
+ read: (reader) => reader.readInt16()
320
+ });
321
+ exports.registry.register("i32", {
322
+ write: (writer, value) => {
323
+ if (value < -2147483648 || value > 2147483647 || !Number.isInteger(value)) {
324
+ throw new Error("Value out of range for i32");
325
+ }
326
+ writer.writeInt32(value);
327
+ },
328
+ read: (reader) => reader.readInt32()
329
+ });
330
+ exports.registry.register("i64", {
331
+ write: (writer, value) => {
332
+ if (value < -9223372036854775808n || value > 9223372036854775807n) {
333
+ throw new Error("Value out of range for i64");
334
+ }
335
+ writer.writeInt64(value);
336
+ },
337
+ read: (reader) => reader.readInt64()
338
+ });
339
+ exports.registry.register("i128", {
340
+ write: (writer, value) => {
341
+ if (value < -170141183460469231731687303715884105728n || value > 170141183460469231731687303715884105727n) {
342
+ throw new Error("Value out of range for i128");
343
+ }
344
+ writer.writeInt128(value);
345
+ },
346
+ read: (reader) => reader.readInt128()
347
+ });
348
+ exports.registry.register("f32", {
349
+ write: (writer, value) => writer.writeFloat32(value),
350
+ read: (reader) => reader.readFloat32()
351
+ });
352
+ exports.registry.register("f64", {
353
+ write: (writer, value) => {
354
+ if (Number.isNaN(value)) {
355
+ throw new Error("For portability reasons we do not allow serializing NaN values.");
356
+ }
357
+ writer.writeFloat64(value);
358
+ },
359
+ read: (reader) => reader.readFloat64()
360
+ });
361
+ exports.registry.register("bool", {
362
+ write: (writer, value) => writer.writeBool(value),
363
+ read: (reader) => reader.readBool()
364
+ });
365
+ exports.registry.register("string", {
366
+ write: (writer, value) => writer.writeString(value),
367
+ read: (reader) => reader.readString()
368
+ });
369
+ exports.registry.register("unit", {
370
+ write: () => {},
371
+ read: () => ({})
372
+ });
373
+ exports.registry.register("struct", {
374
+ write: (writer, value, fields) => {
375
+ if (!fields)
376
+ return;
377
+ for (const [field, def] of Object.entries(fields)) {
378
+ const handler = exports.registry.getHandler(def.type);
379
+ handler.write(writer, value[field], def.options);
380
+ }
381
+ },
382
+ read: (reader, fields) => {
383
+ if (!fields)
384
+ return {};
385
+ const result = {};
386
+ for (const [field, def] of Object.entries(fields)) {
387
+ const handler = exports.registry.getHandler(def.type);
388
+ result[field] = handler.read(reader, def.options);
389
+ }
390
+ return result;
391
+ }
392
+ });
393
+ exports.registry.register("vec", {
394
+ write: (writer, value, options) => {
395
+ if (!options)
396
+ return;
397
+ const { elementType, elementOptions } = options;
398
+ const length = ArrayBuffer.isView(value) ? value.length : value.length;
399
+ writer.writeUint32(length);
400
+ const handler = exports.registry.getHandler(elementType);
401
+ if (ArrayBuffer.isView(value)) {
402
+ for (let i = 0;i < length; i++) {
403
+ handler.write(writer, value[i], elementOptions);
404
+ }
405
+ } else {
406
+ for (const item of value) {
407
+ handler.write(writer, item, elementOptions);
408
+ }
409
+ }
410
+ },
411
+ read: (reader, options) => {
412
+ if (!options)
413
+ return [];
414
+ const { elementType, elementOptions } = options;
415
+ const length = reader.readUint32();
416
+ const handler = exports.registry.getHandler(elementType);
417
+ const values = Array.from({ length }, () => handler.read(reader, elementOptions));
418
+ switch (elementType) {
419
+ case "u8":
420
+ return new Uint8Array(values);
421
+ case "u16":
422
+ return new Uint16Array(values);
423
+ case "u32":
424
+ return new Uint32Array(values);
425
+ case "i8":
426
+ return new Int8Array(values);
427
+ case "i16":
428
+ return new Int16Array(values);
429
+ case "i32":
430
+ return new Int32Array(values);
431
+ case "i64":
432
+ return new BigInt64Array(values);
433
+ case "f32":
434
+ return new Float32Array(values);
435
+ case "f64":
436
+ return new Float64Array(values);
437
+ default:
438
+ return values;
439
+ }
440
+ }
441
+ });
442
+ exports.registry.register("set", {
443
+ write: (writer, value, options) => {
444
+ if (!options)
445
+ return;
446
+ const { elementType, elementOptions } = options;
447
+ const array = Array.from(value).sort();
448
+ writer.writeUint32(array.length);
449
+ const handler = exports.registry.getHandler(elementType);
450
+ for (const item of array) {
451
+ handler.write(writer, item, elementOptions);
452
+ }
453
+ },
454
+ read: (reader, options) => {
455
+ if (!options)
456
+ return new Set;
457
+ const { elementType, elementOptions } = options;
458
+ const length = reader.readUint32();
459
+ const handler = exports.registry.getHandler(elementType);
460
+ const items = Array.from({ length }, () => handler.read(reader, elementOptions));
461
+ return new Set(items);
462
+ }
463
+ });
464
+ exports.registry.register("map", {
465
+ write: (writer, value, options) => {
466
+ if (!options)
467
+ return;
468
+ const { keyType, keyOptions, valueType, valueOptions } = options;
469
+ const entries = Array.from(value.entries()).sort();
470
+ writer.writeUint32(entries.length);
471
+ const keyHandler = exports.registry.getHandler(keyType);
472
+ const valueHandler = exports.registry.getHandler(valueType);
473
+ for (const [key, val] of entries) {
474
+ keyHandler.write(writer, key, keyOptions);
475
+ valueHandler.write(writer, val, valueOptions);
476
+ }
477
+ },
478
+ read: (reader, options) => {
479
+ if (!options)
480
+ return new Map;
481
+ const { keyType, keyOptions, valueType, valueOptions } = options;
482
+ const length = reader.readUint32();
483
+ const keyHandler = exports.registry.getHandler(keyType);
484
+ const valueHandler = exports.registry.getHandler(valueType);
485
+ const entries = Array.from({ length }, () => {
486
+ const key = keyHandler.read(reader, keyOptions);
487
+ const value = valueHandler.read(reader, valueOptions);
488
+ return [key, value];
489
+ });
490
+ return new Map(entries);
491
+ }
492
+ });
493
+ exports.registry.register("option", {
494
+ write: (writer, value, options) => {
495
+ if (!options)
496
+ return;
497
+ const { valueType, valueOptions } = options;
498
+ const isSome = value !== null;
499
+ writer.writeUint8(isSome ? 1 : 0);
500
+ if (isSome) {
501
+ const handler = exports.registry.getHandler(valueType);
502
+ handler.write(writer, value, valueOptions);
503
+ }
504
+ },
505
+ read: (reader, options) => {
506
+ if (!options)
507
+ return null;
508
+ const { valueType, valueOptions } = options;
509
+ const isSome = reader.readUint8() === 1;
510
+ if (isSome) {
511
+ const handler = exports.registry.getHandler(valueType);
512
+ return handler.read(reader, valueOptions);
513
+ }
514
+ return null;
515
+ }
516
+ });
517
+ exports.registry.register("enum", {
518
+ write: (writer, value, options) => {
519
+ if (!options)
520
+ return;
521
+ const variantName = Object.keys(value)[0];
522
+ const variantValue = value[variantName];
523
+ const variant = options.variants.find((v) => v.name === variantName);
524
+ if (!variant) {
525
+ throw new Error(`Unknown enum variant: ${variantName}`);
526
+ }
527
+ writer.writeUint8(variant.index);
528
+ if (variant.type !== "unit") {
529
+ const handler = exports.registry.getHandler(variant.type);
530
+ handler.write(writer, variantValue, variant.options);
531
+ }
532
+ },
533
+ read: (reader, options) => {
534
+ if (!options)
535
+ return {};
536
+ const index = reader.readUint8();
537
+ const variant = options.variants.find((v) => v.index === index);
538
+ if (!variant) {
539
+ throw new Error(`Unknown enum variant index: ${index}`);
540
+ }
541
+ if (variant.type === "unit") {
542
+ return { [variant.name]: {} };
543
+ }
544
+ const handler = exports.registry.getHandler(variant.type);
545
+ const value = handler.read(reader, variant.options);
546
+ return { [variant.name]: value };
547
+ }
548
+ });
549
+ exports.registry.register("tuple", {
550
+ write: (writer, value, types) => {
551
+ if (!types)
552
+ return;
553
+ if (value.length !== types.length) {
554
+ throw new Error(`Tuple length mismatch: expected ${types.length}, got ${value.length}`);
555
+ }
556
+ for (let i = 0;i < types.length; i++) {
557
+ const typeInfo = types[i];
558
+ if (!typeInfo) {
559
+ throw new Error(`Missing type information for tuple element at index ${i}`);
560
+ }
561
+ const handler = exports.registry.getHandler(typeInfo.type);
562
+ handler.write(writer, value[i], typeInfo.options);
563
+ }
564
+ },
565
+ read: (reader, types) => {
566
+ if (!types)
567
+ return [];
568
+ const result = [];
569
+ for (const type of types) {
570
+ const handler = exports.registry.getHandler(type.type);
571
+ result.push(handler.read(reader, type.options));
572
+ }
573
+ return result;
574
+ }
575
+ });
576
+ exports.registry.register("array", {
577
+ write: (writer, value, options) => {
578
+ if (!options)
579
+ return;
580
+ const { elementType, elementOptions, length } = options;
581
+ if (value.length !== length) {
582
+ throw new Error(`Array length mismatch: expected ${length}, got ${value.length}`);
583
+ }
584
+ const handler = exports.registry.getHandler(elementType);
585
+ for (const item of value) {
586
+ handler.write(writer, item, elementOptions);
587
+ }
588
+ },
589
+ read: (reader, options) => {
590
+ if (!options)
591
+ return [];
592
+ const { elementType, elementOptions, length } = options;
593
+ const handler = exports.registry.getHandler(elementType);
594
+ return Array.from({ length }, () => handler.read(reader, elementOptions));
595
+ }
596
+ });
597
+ exports.registry.register("bytes", {
598
+ write: (writer, value, options) => {
599
+ const length = value.length;
600
+ if (options?.length != null) {
601
+ if (length !== options.length) {
602
+ throw new Error(`Bytes length mismatch: expected ${options.length}, got ${length}`);
603
+ }
604
+ for (let i = 0;i < length; i++) {
605
+ writer.writeUint8(value[i]);
606
+ }
607
+ } else {
608
+ writer.writeUint32(length);
609
+ for (let i = 0;i < length; i++) {
610
+ writer.writeUint8(value[i]);
611
+ }
612
+ }
613
+ },
614
+ read: (reader, options) => {
615
+ const length = options?.length != null ? options.length : reader.readUint32();
616
+ const bytes = new Uint8Array(length);
617
+ for (let i = 0;i < length; i++) {
618
+ bytes[i] = reader.readUint8();
619
+ }
620
+ return bytes;
621
+ }
622
+ });
623
+ exports.registry.register("nativeEnum", {
624
+ write: (writer, value, options) => {
625
+ if (!options)
626
+ return;
627
+ const { valueToIndexMap } = options;
628
+ const enumValue = value;
629
+ const index = valueToIndexMap.get(enumValue);
630
+ if (index === undefined) {
631
+ throw new Error(`Invalid enum value: ${String(value)}`);
632
+ }
633
+ writer.writeUint8(index);
634
+ },
635
+ read: (reader, options) => {
636
+ if (!options)
637
+ return null;
638
+ const { indexToValueMap } = options;
639
+ const index = reader.readUint8();
640
+ const value = indexToValueMap.get(index);
641
+ if (value === undefined) {
642
+ throw new Error(`Invalid enum index: ${index}`);
643
+ }
644
+ return value;
645
+ }
646
+ });
647
+ });
648
+
649
+ // ../../node_modules/.bun/@zorsh+zorsh@0.4.0/node_modules/@zorsh/zorsh/dist/src/schema.js
650
+ var require_schema = __commonJS((exports) => {
651
+ Object.defineProperty(exports, "__esModule", { value: true });
652
+ exports.b = exports.Schema = undefined;
653
+ var binary_io_1 = require_binary_io();
654
+ var registry_1 = require_registry();
655
+
656
+ class Schema {
657
+ type;
658
+ options;
659
+ registry;
660
+ constructor(type, options, registry) {
661
+ this.type = type;
662
+ this.options = options;
663
+ this.registry = registry;
664
+ }
665
+ serialize(value) {
666
+ const writer = new binary_io_1.BinaryWriter;
667
+ const handler = this.registry.getHandler(this.type);
668
+ handler.write(writer, value, this.options);
669
+ return writer.getBuffer();
670
+ }
671
+ deserialize(buffer) {
672
+ const reader = new binary_io_1.BinaryReader(buffer);
673
+ const handler = this.registry.getHandler(this.type);
674
+ return handler.read(reader, this.options);
675
+ }
676
+ }
677
+ exports.Schema = Schema;
678
+ exports.b = {
679
+ u8: () => new Schema("u8", null, registry_1.registry),
680
+ u16: () => new Schema("u16", null, registry_1.registry),
681
+ u32: () => new Schema("u32", null, registry_1.registry),
682
+ u64: () => new Schema("u64", null, registry_1.registry),
683
+ u128: () => new Schema("u128", null, registry_1.registry),
684
+ i8: () => new Schema("i8", null, registry_1.registry),
685
+ i16: () => new Schema("i16", null, registry_1.registry),
686
+ i32: () => new Schema("i32", null, registry_1.registry),
687
+ i64: () => new Schema("i64", null, registry_1.registry),
688
+ i128: () => new Schema("i128", null, registry_1.registry),
689
+ f32: () => new Schema("f32", null, registry_1.registry),
690
+ f64: () => new Schema("f64", null, registry_1.registry),
691
+ bool: () => new Schema("bool", null, registry_1.registry),
692
+ string: () => new Schema("string", null, registry_1.registry),
693
+ unit: () => new Schema("unit", null, registry_1.registry),
694
+ vec: (elementSchema) => {
695
+ return new Schema("vec", {
696
+ elementType: elementSchema.type,
697
+ elementOptions: elementSchema.options
698
+ }, registry_1.registry);
699
+ },
700
+ hashSet: (elementSchema) => {
701
+ return new Schema("set", {
702
+ elementType: elementSchema.type,
703
+ elementOptions: elementSchema.options
704
+ }, registry_1.registry);
705
+ },
706
+ hashMap: (keySchema, valueSchema) => {
707
+ return new Schema("map", {
708
+ keyType: keySchema.type,
709
+ keyOptions: keySchema.options,
710
+ valueType: valueSchema.type,
711
+ valueOptions: valueSchema.options
712
+ }, registry_1.registry);
713
+ },
714
+ option: (valueSchema) => {
715
+ return new Schema("option", {
716
+ valueType: valueSchema.type,
717
+ valueOptions: valueSchema.options
718
+ }, registry_1.registry);
719
+ },
720
+ array: (elementSchema, length) => {
721
+ return new Schema("array", {
722
+ elementType: elementSchema.type,
723
+ elementOptions: elementSchema.options,
724
+ length
725
+ }, registry_1.registry);
726
+ },
727
+ bytes: (length) => {
728
+ return new Schema("bytes", length != null ? { length } : {}, registry_1.registry);
729
+ },
730
+ enum: (variants) => {
731
+ const variantArray = Object.entries(variants).map(([name, schema], index) => ({
732
+ index,
733
+ name,
734
+ type: schema.type,
735
+ options: schema.options
736
+ }));
737
+ return new Schema("enum", { variants: variantArray }, registry_1.registry);
738
+ },
739
+ struct: (fields) => {
740
+ const fieldDefs = Object.fromEntries(Object.entries(fields).map(([key, schema]) => [
741
+ key,
742
+ { type: schema.type, options: schema.options }
743
+ ]));
744
+ return new Schema("struct", fieldDefs, registry_1.registry);
745
+ },
746
+ tuple: (...elements) => {
747
+ const types = elements.map((schema) => ({
748
+ type: schema.type,
749
+ options: schema.options
750
+ }));
751
+ return new Schema("tuple", types, registry_1.registry);
752
+ },
753
+ nativeEnum: (enumObj) => {
754
+ const enumEntries = Object.entries(enumObj).filter(([key]) => typeof key === "string" && Number.isNaN(Number(key)));
755
+ const enumValues = enumEntries.map(([_, value]) => value);
756
+ const hasStringValues = enumValues.some((value) => typeof value === "string");
757
+ const hasNumericValues = enumValues.some((value) => typeof value === "number");
758
+ if (hasStringValues && hasNumericValues) {
759
+ throw new Error("Mixed string/numeric enums are not supported");
760
+ }
761
+ const valueToIndexMap = new Map;
762
+ const indexToValueMap = new Map;
763
+ enumEntries.forEach(([_key, value], index) => {
764
+ valueToIndexMap.set(value, index);
765
+ indexToValueMap.set(index, value);
766
+ });
767
+ if (enumEntries.length > 255) {
768
+ throw new Error("Borsh only supports enums with up to 255 variants");
769
+ }
770
+ return new Schema("nativeEnum", {
771
+ enumObj,
772
+ valueToIndexMap,
773
+ indexToValueMap
774
+ }, registry_1.registry);
775
+ }
776
+ };
777
+ });
778
+
779
+ // ../../node_modules/.bun/@zorsh+zorsh@0.4.0/node_modules/@zorsh/zorsh/dist/src/index.js
780
+ var require_src = __commonJS((exports) => {
781
+ Object.defineProperty(exports, "__esModule", { value: true });
782
+ exports.Schema = exports.b = undefined;
783
+ var schema_1 = require_schema();
784
+ Object.defineProperty(exports, "b", { enumerable: true, get: function() {
785
+ return schema_1.b;
786
+ } });
787
+ Object.defineProperty(exports, "Schema", { enumerable: true, get: function() {
788
+ return schema_1.Schema;
789
+ } });
790
+ });
791
+
47
792
  // ../../node_modules/.bun/@gramio+callback-data@0.0.3/node_modules/@gramio/callback-data/dist/index.js
48
793
  var require_dist = __commonJS((exports) => {
49
794
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -707,7 +1452,7 @@ var require_node = __commonJS((exports, module) => {
707
1452
  });
708
1453
 
709
1454
  // ../../node_modules/.bun/debug@4.4.3/node_modules/debug/src/index.js
710
- var require_src = __commonJS((exports, module) => {
1455
+ var require_src2 = __commonJS((exports, module) => {
711
1456
  if (typeof process === "undefined" || process.type === "renderer" || false || process.__nwjs) {
712
1457
  module.exports = require_browser();
713
1458
  } else {
@@ -872,10 +1617,10 @@ var require_reader = __commonJS((exports, module) => {
872
1617
  Reader.prototype.readByte = function(peek) {
873
1618
  if (this._size - this._offset < 1)
874
1619
  return null;
875
- var b = this._buf[this._offset] & 255;
1620
+ var b3 = this._buf[this._offset] & 255;
876
1621
  if (!peek)
877
1622
  this._offset += 1;
878
- return b;
1623
+ return b3;
879
1624
  };
880
1625
  Reader.prototype.peek = function() {
881
1626
  return this.readByte(true);
@@ -928,11 +1673,11 @@ var require_reader = __commonJS((exports, module) => {
928
1673
  Reader.prototype.readString = function(tag, retbuf) {
929
1674
  if (!tag)
930
1675
  tag = ASN1.OctetString;
931
- var b = this.peek();
932
- if (b === null)
1676
+ var b3 = this.peek();
1677
+ if (b3 === null)
933
1678
  return null;
934
- if (b !== tag)
935
- throw newInvalidAsn1Error("Expected 0x" + tag.toString(16) + ": got 0x" + b.toString(16));
1679
+ if (b3 !== tag)
1680
+ throw newInvalidAsn1Error("Expected 0x" + tag.toString(16) + ": got 0x" + b3.toString(16));
936
1681
  var o = this.readLength(this._offset + 1);
937
1682
  if (o === null)
938
1683
  return null;
@@ -948,13 +1693,13 @@ var require_reader = __commonJS((exports, module) => {
948
1693
  Reader.prototype.readOID = function(tag) {
949
1694
  if (!tag)
950
1695
  tag = ASN1.OID;
951
- var b = this.readString(tag, true);
952
- if (b === null)
1696
+ var b3 = this.readString(tag, true);
1697
+ if (b3 === null)
953
1698
  return null;
954
1699
  var values = [];
955
1700
  var value = 0;
956
- for (var i = 0;i < b.length; i++) {
957
- var byte = b[i] & 255;
1701
+ for (var i = 0;i < b3.length; i++) {
1702
+ var byte = b3[i] & 255;
958
1703
  value <<= 7;
959
1704
  value += byte & 127;
960
1705
  if ((byte & 128) === 0) {
@@ -969,11 +1714,11 @@ var require_reader = __commonJS((exports, module) => {
969
1714
  };
970
1715
  Reader.prototype._readTag = function(tag) {
971
1716
  assert.ok(tag !== undefined);
972
- var b = this.peek();
973
- if (b === null)
1717
+ var b3 = this.peek();
1718
+ if (b3 === null)
974
1719
  return null;
975
- if (b !== tag)
976
- throw newInvalidAsn1Error("Expected 0x" + tag.toString(16) + ": got 0x" + b.toString(16));
1720
+ if (b3 !== tag)
1721
+ throw newInvalidAsn1Error("Expected 0x" + tag.toString(16) + ": got 0x" + b3.toString(16));
977
1722
  var o = this.readLength(this._offset + 1);
978
1723
  if (o === null)
979
1724
  return null;
@@ -1035,11 +1780,11 @@ var require_writer = __commonJS((exports, module) => {
1035
1780
  return this._buf.slice(0, this._offset);
1036
1781
  }
1037
1782
  });
1038
- Writer.prototype.writeByte = function(b) {
1039
- if (typeof b !== "number")
1783
+ Writer.prototype.writeByte = function(b3) {
1784
+ if (typeof b3 !== "number")
1040
1785
  throw new TypeError("argument must be a Number");
1041
1786
  this._ensure(1);
1042
- this._buf[this._offset++] = b;
1787
+ this._buf[this._offset++] = b3;
1043
1788
  };
1044
1789
  Writer.prototype.writeInt = function(i, tag) {
1045
1790
  if (typeof i !== "number")
@@ -1072,15 +1817,15 @@ var require_writer = __commonJS((exports, module) => {
1072
1817
  tag = ASN1.Enumeration;
1073
1818
  return this.writeInt(i, tag);
1074
1819
  };
1075
- Writer.prototype.writeBoolean = function(b, tag) {
1076
- if (typeof b !== "boolean")
1820
+ Writer.prototype.writeBoolean = function(b3, tag) {
1821
+ if (typeof b3 !== "boolean")
1077
1822
  throw new TypeError("argument must be a Boolean");
1078
1823
  if (typeof tag !== "number")
1079
1824
  tag = ASN1.Boolean;
1080
1825
  this._ensure(3);
1081
1826
  this._buf[this._offset++] = tag;
1082
1827
  this._buf[this._offset++] = 1;
1083
- this._buf[this._offset++] = b ? 255 : 0;
1828
+ this._buf[this._offset++] = b3 ? 255 : 0;
1084
1829
  };
1085
1830
  Writer.prototype.writeString = function(s, tag) {
1086
1831
  if (typeof s !== "string")
@@ -1148,15 +1893,15 @@ var require_writer = __commonJS((exports, module) => {
1148
1893
  var tmp = s.split(".");
1149
1894
  var bytes = [];
1150
1895
  bytes.push(parseInt(tmp[0], 10) * 40 + parseInt(tmp[1], 10));
1151
- tmp.slice(2).forEach(function(b) {
1152
- encodeOctet(bytes, parseInt(b, 10));
1896
+ tmp.slice(2).forEach(function(b3) {
1897
+ encodeOctet(bytes, parseInt(b3, 10));
1153
1898
  });
1154
1899
  var self2 = this;
1155
1900
  this._ensure(2 + bytes.length);
1156
1901
  this.writeByte(tag);
1157
1902
  this.writeLength(bytes.length);
1158
- bytes.forEach(function(b) {
1159
- self2.writeByte(b);
1903
+ bytes.forEach(function(b3) {
1904
+ self2.writeByte(b3);
1160
1905
  });
1161
1906
  };
1162
1907
  Writer.prototype.writeLength = function(len) {
@@ -1566,14 +2311,14 @@ var require_nacl_fast = __commonJS((exports, module) => {
1566
2311
  core_hsalsa20(out, inp, k, c);
1567
2312
  }
1568
2313
  var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);
1569
- function crypto_stream_salsa20_xor(c, cpos, m, mpos, b, n, k) {
2314
+ function crypto_stream_salsa20_xor(c, cpos, m, mpos, b3, n, k) {
1570
2315
  var z = new Uint8Array(16), x = new Uint8Array(64);
1571
2316
  var u, i;
1572
2317
  for (i = 0;i < 16; i++)
1573
2318
  z[i] = 0;
1574
2319
  for (i = 0;i < 8; i++)
1575
2320
  z[i] = n[i];
1576
- while (b >= 64) {
2321
+ while (b3 >= 64) {
1577
2322
  crypto_core_salsa20(x, z, k, sigma);
1578
2323
  for (i = 0;i < 64; i++)
1579
2324
  c[cpos + i] = m[mpos + i] ^ x[i];
@@ -1583,25 +2328,25 @@ var require_nacl_fast = __commonJS((exports, module) => {
1583
2328
  z[i] = u & 255;
1584
2329
  u >>>= 8;
1585
2330
  }
1586
- b -= 64;
2331
+ b3 -= 64;
1587
2332
  cpos += 64;
1588
2333
  mpos += 64;
1589
2334
  }
1590
- if (b > 0) {
2335
+ if (b3 > 0) {
1591
2336
  crypto_core_salsa20(x, z, k, sigma);
1592
- for (i = 0;i < b; i++)
2337
+ for (i = 0;i < b3; i++)
1593
2338
  c[cpos + i] = m[mpos + i] ^ x[i];
1594
2339
  }
1595
2340
  return 0;
1596
2341
  }
1597
- function crypto_stream_salsa20(c, cpos, b, n, k) {
2342
+ function crypto_stream_salsa20(c, cpos, b3, n, k) {
1598
2343
  var z = new Uint8Array(16), x = new Uint8Array(64);
1599
2344
  var u, i;
1600
2345
  for (i = 0;i < 16; i++)
1601
2346
  z[i] = 0;
1602
2347
  for (i = 0;i < 8; i++)
1603
2348
  z[i] = n[i];
1604
- while (b >= 64) {
2349
+ while (b3 >= 64) {
1605
2350
  crypto_core_salsa20(x, z, k, sigma);
1606
2351
  for (i = 0;i < 64; i++)
1607
2352
  c[cpos + i] = x[i];
@@ -1611,12 +2356,12 @@ var require_nacl_fast = __commonJS((exports, module) => {
1611
2356
  z[i] = u & 255;
1612
2357
  u >>>= 8;
1613
2358
  }
1614
- b -= 64;
2359
+ b3 -= 64;
1615
2360
  cpos += 64;
1616
2361
  }
1617
- if (b > 0) {
2362
+ if (b3 > 0) {
1618
2363
  crypto_core_salsa20(x, z, k, sigma);
1619
- for (i = 0;i < b; i++)
2364
+ for (i = 0;i < b3; i++)
1620
2365
  c[cpos + i] = x[i];
1621
2366
  }
1622
2367
  return 0;
@@ -2024,8 +2769,8 @@ var require_nacl_fast = __commonJS((exports, module) => {
2024
2769
  }
2025
2770
  o[0] += c - 1 + 37 * (c - 1);
2026
2771
  }
2027
- function sel25519(p, q, b) {
2028
- var t3, c = ~(b - 1);
2772
+ function sel25519(p, q, b3) {
2773
+ var t3, c = ~(b3 - 1);
2029
2774
  for (var i = 0;i < 16; i++) {
2030
2775
  t3 = c & (p[i] ^ q[i]);
2031
2776
  p[i] ^= t3;
@@ -2033,7 +2778,7 @@ var require_nacl_fast = __commonJS((exports, module) => {
2033
2778
  }
2034
2779
  }
2035
2780
  function pack25519(o, n) {
2036
- var i, j, b;
2781
+ var i, j, b3;
2037
2782
  var m = gf(), t3 = gf();
2038
2783
  for (i = 0;i < 16; i++)
2039
2784
  t3[i] = n[i];
@@ -2047,19 +2792,19 @@ var require_nacl_fast = __commonJS((exports, module) => {
2047
2792
  m[i - 1] &= 65535;
2048
2793
  }
2049
2794
  m[15] = t3[15] - 32767 - (m[14] >> 16 & 1);
2050
- b = m[15] >> 16 & 1;
2795
+ b3 = m[15] >> 16 & 1;
2051
2796
  m[14] &= 65535;
2052
- sel25519(t3, m, 1 - b);
2797
+ sel25519(t3, m, 1 - b3);
2053
2798
  }
2054
2799
  for (i = 0;i < 16; i++) {
2055
2800
  o[2 * i] = t3[i] & 255;
2056
2801
  o[2 * i + 1] = t3[i] >> 8;
2057
2802
  }
2058
2803
  }
2059
- function neq25519(a, b) {
2804
+ function neq25519(a, b3) {
2060
2805
  var c = new Uint8Array(32), d = new Uint8Array(32);
2061
2806
  pack25519(c, a);
2062
- pack25519(d, b);
2807
+ pack25519(d, b3);
2063
2808
  return crypto_verify_32(c, 0, d, 0);
2064
2809
  }
2065
2810
  function par25519(a) {
@@ -2073,21 +2818,21 @@ var require_nacl_fast = __commonJS((exports, module) => {
2073
2818
  o[i] = n[2 * i] + (n[2 * i + 1] << 8);
2074
2819
  o[15] &= 32767;
2075
2820
  }
2076
- function A(o, a, b) {
2821
+ function A(o, a, b3) {
2077
2822
  for (var i = 0;i < 16; i++)
2078
- o[i] = a[i] + b[i];
2823
+ o[i] = a[i] + b3[i];
2079
2824
  }
2080
- function Z(o, a, b) {
2825
+ function Z(o, a, b3) {
2081
2826
  for (var i = 0;i < 16; i++)
2082
- o[i] = a[i] - b[i];
2827
+ o[i] = a[i] - b3[i];
2083
2828
  }
2084
- function M(o, a, b) {
2085
- var v, c, t0 = 0, t1 = 0, t22 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0, t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t222 = 0, t23 = 0, t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0, b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5], b6 = b[6], b7 = b[7], b8 = b[8], b9 = b[9], b10 = b[10], b11 = b[11], b12 = b[12], b13 = b[13], b14 = b[14], b15 = b[15];
2829
+ function M(o, a, b3) {
2830
+ var v, c, t0 = 0, t1 = 0, t22 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0, t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t222 = 0, t23 = 0, t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0, b0 = b3[0], b1 = b3[1], b22 = b3[2], b32 = b3[3], b4 = b3[4], b5 = b3[5], b6 = b3[6], b7 = b3[7], b8 = b3[8], b9 = b3[9], b10 = b3[10], b11 = b3[11], b12 = b3[12], b13 = b3[13], b14 = b3[14], b15 = b3[15];
2086
2831
  v = a[0];
2087
2832
  t0 += v * b0;
2088
2833
  t1 += v * b1;
2089
- t22 += v * b2;
2090
- t3 += v * b3;
2834
+ t22 += v * b22;
2835
+ t3 += v * b32;
2091
2836
  t4 += v * b4;
2092
2837
  t5 += v * b5;
2093
2838
  t6 += v * b6;
@@ -2103,8 +2848,8 @@ var require_nacl_fast = __commonJS((exports, module) => {
2103
2848
  v = a[1];
2104
2849
  t1 += v * b0;
2105
2850
  t22 += v * b1;
2106
- t3 += v * b2;
2107
- t4 += v * b3;
2851
+ t3 += v * b22;
2852
+ t4 += v * b32;
2108
2853
  t5 += v * b4;
2109
2854
  t6 += v * b5;
2110
2855
  t7 += v * b6;
@@ -2120,8 +2865,8 @@ var require_nacl_fast = __commonJS((exports, module) => {
2120
2865
  v = a[2];
2121
2866
  t22 += v * b0;
2122
2867
  t3 += v * b1;
2123
- t4 += v * b2;
2124
- t5 += v * b3;
2868
+ t4 += v * b22;
2869
+ t5 += v * b32;
2125
2870
  t6 += v * b4;
2126
2871
  t7 += v * b5;
2127
2872
  t8 += v * b6;
@@ -2137,8 +2882,8 @@ var require_nacl_fast = __commonJS((exports, module) => {
2137
2882
  v = a[3];
2138
2883
  t3 += v * b0;
2139
2884
  t4 += v * b1;
2140
- t5 += v * b2;
2141
- t6 += v * b3;
2885
+ t5 += v * b22;
2886
+ t6 += v * b32;
2142
2887
  t7 += v * b4;
2143
2888
  t8 += v * b5;
2144
2889
  t9 += v * b6;
@@ -2154,8 +2899,8 @@ var require_nacl_fast = __commonJS((exports, module) => {
2154
2899
  v = a[4];
2155
2900
  t4 += v * b0;
2156
2901
  t5 += v * b1;
2157
- t6 += v * b2;
2158
- t7 += v * b3;
2902
+ t6 += v * b22;
2903
+ t7 += v * b32;
2159
2904
  t8 += v * b4;
2160
2905
  t9 += v * b5;
2161
2906
  t10 += v * b6;
@@ -2171,8 +2916,8 @@ var require_nacl_fast = __commonJS((exports, module) => {
2171
2916
  v = a[5];
2172
2917
  t5 += v * b0;
2173
2918
  t6 += v * b1;
2174
- t7 += v * b2;
2175
- t8 += v * b3;
2919
+ t7 += v * b22;
2920
+ t8 += v * b32;
2176
2921
  t9 += v * b4;
2177
2922
  t10 += v * b5;
2178
2923
  t11 += v * b6;
@@ -2188,8 +2933,8 @@ var require_nacl_fast = __commonJS((exports, module) => {
2188
2933
  v = a[6];
2189
2934
  t6 += v * b0;
2190
2935
  t7 += v * b1;
2191
- t8 += v * b2;
2192
- t9 += v * b3;
2936
+ t8 += v * b22;
2937
+ t9 += v * b32;
2193
2938
  t10 += v * b4;
2194
2939
  t11 += v * b5;
2195
2940
  t12 += v * b6;
@@ -2205,8 +2950,8 @@ var require_nacl_fast = __commonJS((exports, module) => {
2205
2950
  v = a[7];
2206
2951
  t7 += v * b0;
2207
2952
  t8 += v * b1;
2208
- t9 += v * b2;
2209
- t10 += v * b3;
2953
+ t9 += v * b22;
2954
+ t10 += v * b32;
2210
2955
  t11 += v * b4;
2211
2956
  t12 += v * b5;
2212
2957
  t13 += v * b6;
@@ -2222,8 +2967,8 @@ var require_nacl_fast = __commonJS((exports, module) => {
2222
2967
  v = a[8];
2223
2968
  t8 += v * b0;
2224
2969
  t9 += v * b1;
2225
- t10 += v * b2;
2226
- t11 += v * b3;
2970
+ t10 += v * b22;
2971
+ t11 += v * b32;
2227
2972
  t12 += v * b4;
2228
2973
  t13 += v * b5;
2229
2974
  t14 += v * b6;
@@ -2239,8 +2984,8 @@ var require_nacl_fast = __commonJS((exports, module) => {
2239
2984
  v = a[9];
2240
2985
  t9 += v * b0;
2241
2986
  t10 += v * b1;
2242
- t11 += v * b2;
2243
- t12 += v * b3;
2987
+ t11 += v * b22;
2988
+ t12 += v * b32;
2244
2989
  t13 += v * b4;
2245
2990
  t14 += v * b5;
2246
2991
  t15 += v * b6;
@@ -2256,8 +3001,8 @@ var require_nacl_fast = __commonJS((exports, module) => {
2256
3001
  v = a[10];
2257
3002
  t10 += v * b0;
2258
3003
  t11 += v * b1;
2259
- t12 += v * b2;
2260
- t13 += v * b3;
3004
+ t12 += v * b22;
3005
+ t13 += v * b32;
2261
3006
  t14 += v * b4;
2262
3007
  t15 += v * b5;
2263
3008
  t16 += v * b6;
@@ -2273,8 +3018,8 @@ var require_nacl_fast = __commonJS((exports, module) => {
2273
3018
  v = a[11];
2274
3019
  t11 += v * b0;
2275
3020
  t12 += v * b1;
2276
- t13 += v * b2;
2277
- t14 += v * b3;
3021
+ t13 += v * b22;
3022
+ t14 += v * b32;
2278
3023
  t15 += v * b4;
2279
3024
  t16 += v * b5;
2280
3025
  t17 += v * b6;
@@ -2290,8 +3035,8 @@ var require_nacl_fast = __commonJS((exports, module) => {
2290
3035
  v = a[12];
2291
3036
  t12 += v * b0;
2292
3037
  t13 += v * b1;
2293
- t14 += v * b2;
2294
- t15 += v * b3;
3038
+ t14 += v * b22;
3039
+ t15 += v * b32;
2295
3040
  t16 += v * b4;
2296
3041
  t17 += v * b5;
2297
3042
  t18 += v * b6;
@@ -2307,8 +3052,8 @@ var require_nacl_fast = __commonJS((exports, module) => {
2307
3052
  v = a[13];
2308
3053
  t13 += v * b0;
2309
3054
  t14 += v * b1;
2310
- t15 += v * b2;
2311
- t16 += v * b3;
3055
+ t15 += v * b22;
3056
+ t16 += v * b32;
2312
3057
  t17 += v * b4;
2313
3058
  t18 += v * b5;
2314
3059
  t19 += v * b6;
@@ -2324,8 +3069,8 @@ var require_nacl_fast = __commonJS((exports, module) => {
2324
3069
  v = a[14];
2325
3070
  t14 += v * b0;
2326
3071
  t15 += v * b1;
2327
- t16 += v * b2;
2328
- t17 += v * b3;
3072
+ t16 += v * b22;
3073
+ t17 += v * b32;
2329
3074
  t18 += v * b4;
2330
3075
  t19 += v * b5;
2331
3076
  t20 += v * b6;
@@ -2341,8 +3086,8 @@ var require_nacl_fast = __commonJS((exports, module) => {
2341
3086
  v = a[15];
2342
3087
  t15 += v * b0;
2343
3088
  t16 += v * b1;
2344
- t17 += v * b2;
2345
- t18 += v * b3;
3089
+ t17 += v * b22;
3090
+ t18 += v * b32;
2346
3091
  t19 += v * b4;
2347
3092
  t20 += v * b5;
2348
3093
  t21 += v * b6;
@@ -2519,46 +3264,46 @@ var require_nacl_fast = __commonJS((exports, module) => {
2519
3264
  function crypto_scalarmult(q, n, p) {
2520
3265
  var z = new Uint8Array(32);
2521
3266
  var x = new Float64Array(80), r, i;
2522
- var a = gf(), b = gf(), c = gf(), d = gf(), e = gf(), f = gf();
3267
+ var a = gf(), b3 = gf(), c = gf(), d = gf(), e = gf(), f = gf();
2523
3268
  for (i = 0;i < 31; i++)
2524
3269
  z[i] = n[i];
2525
3270
  z[31] = n[31] & 127 | 64;
2526
3271
  z[0] &= 248;
2527
3272
  unpack25519(x, p);
2528
3273
  for (i = 0;i < 16; i++) {
2529
- b[i] = x[i];
3274
+ b3[i] = x[i];
2530
3275
  d[i] = a[i] = c[i] = 0;
2531
3276
  }
2532
3277
  a[0] = d[0] = 1;
2533
3278
  for (i = 254;i >= 0; --i) {
2534
3279
  r = z[i >>> 3] >>> (i & 7) & 1;
2535
- sel25519(a, b, r);
3280
+ sel25519(a, b3, r);
2536
3281
  sel25519(c, d, r);
2537
3282
  A(e, a, c);
2538
3283
  Z(a, a, c);
2539
- A(c, b, d);
2540
- Z(b, b, d);
3284
+ A(c, b3, d);
3285
+ Z(b3, b3, d);
2541
3286
  S(d, e);
2542
3287
  S(f, a);
2543
3288
  M(a, c, a);
2544
- M(c, b, e);
3289
+ M(c, b3, e);
2545
3290
  A(e, a, c);
2546
3291
  Z(a, a, c);
2547
- S(b, a);
3292
+ S(b3, a);
2548
3293
  Z(c, d, f);
2549
3294
  M(a, c, _121665);
2550
3295
  A(a, a, d);
2551
3296
  M(c, c, a);
2552
3297
  M(a, d, f);
2553
- M(d, b, x);
2554
- S(b, e);
2555
- sel25519(a, b, r);
3298
+ M(d, b3, x);
3299
+ S(b3, e);
3300
+ sel25519(a, b3, r);
2556
3301
  sel25519(c, d, r);
2557
3302
  }
2558
3303
  for (i = 0;i < 16; i++) {
2559
3304
  x[i + 16] = a[i];
2560
3305
  x[i + 32] = c[i];
2561
- x[i + 48] = b[i];
3306
+ x[i + 48] = b3[i];
2562
3307
  x[i + 64] = d[i];
2563
3308
  }
2564
3309
  var x32 = x.subarray(32);
@@ -2755,7 +3500,7 @@ var require_nacl_fast = __commonJS((exports, module) => {
2755
3500
  1246189591
2756
3501
  ];
2757
3502
  function crypto_hashblocks_hl(hh, hl, m, n) {
2758
- var wh = new Int32Array(16), wl = new Int32Array(16), bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7, bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7, th, tl, i, j, h, l, a, b, c, d;
3503
+ var wh = new Int32Array(16), wl = new Int32Array(16), bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7, bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7, th, tl, i, j, h, l, a, b3, c, d;
2759
3504
  var ah0 = hh[0], ah1 = hh[1], ah2 = hh[2], ah3 = hh[3], ah4 = hh[4], ah5 = hh[5], ah6 = hh[6], ah7 = hh[7], al0 = hl[0], al1 = hl[1], al2 = hl[2], al3 = hl[3], al4 = hl[4], al5 = hl[5], al6 = hl[6], al7 = hl[7];
2760
3505
  var pos = 0;
2761
3506
  while (n >= 128) {
@@ -2784,78 +3529,78 @@ var require_nacl_fast = __commonJS((exports, module) => {
2784
3529
  h = ah7;
2785
3530
  l = al7;
2786
3531
  a = l & 65535;
2787
- b = l >>> 16;
3532
+ b3 = l >>> 16;
2788
3533
  c = h & 65535;
2789
3534
  d = h >>> 16;
2790
3535
  h = (ah4 >>> 14 | al4 << 32 - 14) ^ (ah4 >>> 18 | al4 << 32 - 18) ^ (al4 >>> 41 - 32 | ah4 << 32 - (41 - 32));
2791
3536
  l = (al4 >>> 14 | ah4 << 32 - 14) ^ (al4 >>> 18 | ah4 << 32 - 18) ^ (ah4 >>> 41 - 32 | al4 << 32 - (41 - 32));
2792
3537
  a += l & 65535;
2793
- b += l >>> 16;
3538
+ b3 += l >>> 16;
2794
3539
  c += h & 65535;
2795
3540
  d += h >>> 16;
2796
3541
  h = ah4 & ah5 ^ ~ah4 & ah6;
2797
3542
  l = al4 & al5 ^ ~al4 & al6;
2798
3543
  a += l & 65535;
2799
- b += l >>> 16;
3544
+ b3 += l >>> 16;
2800
3545
  c += h & 65535;
2801
3546
  d += h >>> 16;
2802
3547
  h = K[i * 2];
2803
3548
  l = K[i * 2 + 1];
2804
3549
  a += l & 65535;
2805
- b += l >>> 16;
3550
+ b3 += l >>> 16;
2806
3551
  c += h & 65535;
2807
3552
  d += h >>> 16;
2808
3553
  h = wh[i % 16];
2809
3554
  l = wl[i % 16];
2810
3555
  a += l & 65535;
2811
- b += l >>> 16;
3556
+ b3 += l >>> 16;
2812
3557
  c += h & 65535;
2813
3558
  d += h >>> 16;
2814
- b += a >>> 16;
2815
- c += b >>> 16;
3559
+ b3 += a >>> 16;
3560
+ c += b3 >>> 16;
2816
3561
  d += c >>> 16;
2817
3562
  th = c & 65535 | d << 16;
2818
- tl = a & 65535 | b << 16;
3563
+ tl = a & 65535 | b3 << 16;
2819
3564
  h = th;
2820
3565
  l = tl;
2821
3566
  a = l & 65535;
2822
- b = l >>> 16;
3567
+ b3 = l >>> 16;
2823
3568
  c = h & 65535;
2824
3569
  d = h >>> 16;
2825
3570
  h = (ah0 >>> 28 | al0 << 32 - 28) ^ (al0 >>> 34 - 32 | ah0 << 32 - (34 - 32)) ^ (al0 >>> 39 - 32 | ah0 << 32 - (39 - 32));
2826
3571
  l = (al0 >>> 28 | ah0 << 32 - 28) ^ (ah0 >>> 34 - 32 | al0 << 32 - (34 - 32)) ^ (ah0 >>> 39 - 32 | al0 << 32 - (39 - 32));
2827
3572
  a += l & 65535;
2828
- b += l >>> 16;
3573
+ b3 += l >>> 16;
2829
3574
  c += h & 65535;
2830
3575
  d += h >>> 16;
2831
3576
  h = ah0 & ah1 ^ ah0 & ah2 ^ ah1 & ah2;
2832
3577
  l = al0 & al1 ^ al0 & al2 ^ al1 & al2;
2833
3578
  a += l & 65535;
2834
- b += l >>> 16;
3579
+ b3 += l >>> 16;
2835
3580
  c += h & 65535;
2836
3581
  d += h >>> 16;
2837
- b += a >>> 16;
2838
- c += b >>> 16;
3582
+ b3 += a >>> 16;
3583
+ c += b3 >>> 16;
2839
3584
  d += c >>> 16;
2840
3585
  bh7 = c & 65535 | d << 16;
2841
- bl7 = a & 65535 | b << 16;
3586
+ bl7 = a & 65535 | b3 << 16;
2842
3587
  h = bh3;
2843
3588
  l = bl3;
2844
3589
  a = l & 65535;
2845
- b = l >>> 16;
3590
+ b3 = l >>> 16;
2846
3591
  c = h & 65535;
2847
3592
  d = h >>> 16;
2848
3593
  h = th;
2849
3594
  l = tl;
2850
3595
  a += l & 65535;
2851
- b += l >>> 16;
3596
+ b3 += l >>> 16;
2852
3597
  c += h & 65535;
2853
3598
  d += h >>> 16;
2854
- b += a >>> 16;
2855
- c += b >>> 16;
3599
+ b3 += a >>> 16;
3600
+ c += b3 >>> 16;
2856
3601
  d += c >>> 16;
2857
3602
  bh3 = c & 65535 | d << 16;
2858
- bl3 = a & 65535 | b << 16;
3603
+ bl3 = a & 65535 | b3 << 16;
2859
3604
  ah1 = bh0;
2860
3605
  ah2 = bh1;
2861
3606
  ah3 = bh2;
@@ -2877,13 +3622,13 @@ var require_nacl_fast = __commonJS((exports, module) => {
2877
3622
  h = wh[j];
2878
3623
  l = wl[j];
2879
3624
  a = l & 65535;
2880
- b = l >>> 16;
3625
+ b3 = l >>> 16;
2881
3626
  c = h & 65535;
2882
3627
  d = h >>> 16;
2883
3628
  h = wh[(j + 9) % 16];
2884
3629
  l = wl[(j + 9) % 16];
2885
3630
  a += l & 65535;
2886
- b += l >>> 16;
3631
+ b3 += l >>> 16;
2887
3632
  c += h & 65535;
2888
3633
  d += h >>> 16;
2889
3634
  th = wh[(j + 1) % 16];
@@ -2891,7 +3636,7 @@ var require_nacl_fast = __commonJS((exports, module) => {
2891
3636
  h = (th >>> 1 | tl << 32 - 1) ^ (th >>> 8 | tl << 32 - 8) ^ th >>> 7;
2892
3637
  l = (tl >>> 1 | th << 32 - 1) ^ (tl >>> 8 | th << 32 - 8) ^ (tl >>> 7 | th << 32 - 7);
2893
3638
  a += l & 65535;
2894
- b += l >>> 16;
3639
+ b3 += l >>> 16;
2895
3640
  c += h & 65535;
2896
3641
  d += h >>> 16;
2897
3642
  th = wh[(j + 14) % 16];
@@ -2899,160 +3644,160 @@ var require_nacl_fast = __commonJS((exports, module) => {
2899
3644
  h = (th >>> 19 | tl << 32 - 19) ^ (tl >>> 61 - 32 | th << 32 - (61 - 32)) ^ th >>> 6;
2900
3645
  l = (tl >>> 19 | th << 32 - 19) ^ (th >>> 61 - 32 | tl << 32 - (61 - 32)) ^ (tl >>> 6 | th << 32 - 6);
2901
3646
  a += l & 65535;
2902
- b += l >>> 16;
3647
+ b3 += l >>> 16;
2903
3648
  c += h & 65535;
2904
3649
  d += h >>> 16;
2905
- b += a >>> 16;
2906
- c += b >>> 16;
3650
+ b3 += a >>> 16;
3651
+ c += b3 >>> 16;
2907
3652
  d += c >>> 16;
2908
3653
  wh[j] = c & 65535 | d << 16;
2909
- wl[j] = a & 65535 | b << 16;
3654
+ wl[j] = a & 65535 | b3 << 16;
2910
3655
  }
2911
3656
  }
2912
3657
  }
2913
3658
  h = ah0;
2914
3659
  l = al0;
2915
3660
  a = l & 65535;
2916
- b = l >>> 16;
3661
+ b3 = l >>> 16;
2917
3662
  c = h & 65535;
2918
3663
  d = h >>> 16;
2919
3664
  h = hh[0];
2920
3665
  l = hl[0];
2921
3666
  a += l & 65535;
2922
- b += l >>> 16;
3667
+ b3 += l >>> 16;
2923
3668
  c += h & 65535;
2924
3669
  d += h >>> 16;
2925
- b += a >>> 16;
2926
- c += b >>> 16;
3670
+ b3 += a >>> 16;
3671
+ c += b3 >>> 16;
2927
3672
  d += c >>> 16;
2928
3673
  hh[0] = ah0 = c & 65535 | d << 16;
2929
- hl[0] = al0 = a & 65535 | b << 16;
3674
+ hl[0] = al0 = a & 65535 | b3 << 16;
2930
3675
  h = ah1;
2931
3676
  l = al1;
2932
3677
  a = l & 65535;
2933
- b = l >>> 16;
3678
+ b3 = l >>> 16;
2934
3679
  c = h & 65535;
2935
3680
  d = h >>> 16;
2936
3681
  h = hh[1];
2937
3682
  l = hl[1];
2938
3683
  a += l & 65535;
2939
- b += l >>> 16;
3684
+ b3 += l >>> 16;
2940
3685
  c += h & 65535;
2941
3686
  d += h >>> 16;
2942
- b += a >>> 16;
2943
- c += b >>> 16;
3687
+ b3 += a >>> 16;
3688
+ c += b3 >>> 16;
2944
3689
  d += c >>> 16;
2945
3690
  hh[1] = ah1 = c & 65535 | d << 16;
2946
- hl[1] = al1 = a & 65535 | b << 16;
3691
+ hl[1] = al1 = a & 65535 | b3 << 16;
2947
3692
  h = ah2;
2948
3693
  l = al2;
2949
3694
  a = l & 65535;
2950
- b = l >>> 16;
3695
+ b3 = l >>> 16;
2951
3696
  c = h & 65535;
2952
3697
  d = h >>> 16;
2953
3698
  h = hh[2];
2954
3699
  l = hl[2];
2955
3700
  a += l & 65535;
2956
- b += l >>> 16;
3701
+ b3 += l >>> 16;
2957
3702
  c += h & 65535;
2958
3703
  d += h >>> 16;
2959
- b += a >>> 16;
2960
- c += b >>> 16;
3704
+ b3 += a >>> 16;
3705
+ c += b3 >>> 16;
2961
3706
  d += c >>> 16;
2962
3707
  hh[2] = ah2 = c & 65535 | d << 16;
2963
- hl[2] = al2 = a & 65535 | b << 16;
3708
+ hl[2] = al2 = a & 65535 | b3 << 16;
2964
3709
  h = ah3;
2965
3710
  l = al3;
2966
3711
  a = l & 65535;
2967
- b = l >>> 16;
3712
+ b3 = l >>> 16;
2968
3713
  c = h & 65535;
2969
3714
  d = h >>> 16;
2970
3715
  h = hh[3];
2971
3716
  l = hl[3];
2972
3717
  a += l & 65535;
2973
- b += l >>> 16;
3718
+ b3 += l >>> 16;
2974
3719
  c += h & 65535;
2975
3720
  d += h >>> 16;
2976
- b += a >>> 16;
2977
- c += b >>> 16;
3721
+ b3 += a >>> 16;
3722
+ c += b3 >>> 16;
2978
3723
  d += c >>> 16;
2979
3724
  hh[3] = ah3 = c & 65535 | d << 16;
2980
- hl[3] = al3 = a & 65535 | b << 16;
3725
+ hl[3] = al3 = a & 65535 | b3 << 16;
2981
3726
  h = ah4;
2982
3727
  l = al4;
2983
3728
  a = l & 65535;
2984
- b = l >>> 16;
3729
+ b3 = l >>> 16;
2985
3730
  c = h & 65535;
2986
3731
  d = h >>> 16;
2987
3732
  h = hh[4];
2988
3733
  l = hl[4];
2989
3734
  a += l & 65535;
2990
- b += l >>> 16;
3735
+ b3 += l >>> 16;
2991
3736
  c += h & 65535;
2992
3737
  d += h >>> 16;
2993
- b += a >>> 16;
2994
- c += b >>> 16;
3738
+ b3 += a >>> 16;
3739
+ c += b3 >>> 16;
2995
3740
  d += c >>> 16;
2996
3741
  hh[4] = ah4 = c & 65535 | d << 16;
2997
- hl[4] = al4 = a & 65535 | b << 16;
3742
+ hl[4] = al4 = a & 65535 | b3 << 16;
2998
3743
  h = ah5;
2999
3744
  l = al5;
3000
3745
  a = l & 65535;
3001
- b = l >>> 16;
3746
+ b3 = l >>> 16;
3002
3747
  c = h & 65535;
3003
3748
  d = h >>> 16;
3004
3749
  h = hh[5];
3005
3750
  l = hl[5];
3006
3751
  a += l & 65535;
3007
- b += l >>> 16;
3752
+ b3 += l >>> 16;
3008
3753
  c += h & 65535;
3009
3754
  d += h >>> 16;
3010
- b += a >>> 16;
3011
- c += b >>> 16;
3755
+ b3 += a >>> 16;
3756
+ c += b3 >>> 16;
3012
3757
  d += c >>> 16;
3013
3758
  hh[5] = ah5 = c & 65535 | d << 16;
3014
- hl[5] = al5 = a & 65535 | b << 16;
3759
+ hl[5] = al5 = a & 65535 | b3 << 16;
3015
3760
  h = ah6;
3016
3761
  l = al6;
3017
3762
  a = l & 65535;
3018
- b = l >>> 16;
3763
+ b3 = l >>> 16;
3019
3764
  c = h & 65535;
3020
3765
  d = h >>> 16;
3021
3766
  h = hh[6];
3022
3767
  l = hl[6];
3023
3768
  a += l & 65535;
3024
- b += l >>> 16;
3769
+ b3 += l >>> 16;
3025
3770
  c += h & 65535;
3026
3771
  d += h >>> 16;
3027
- b += a >>> 16;
3028
- c += b >>> 16;
3772
+ b3 += a >>> 16;
3773
+ c += b3 >>> 16;
3029
3774
  d += c >>> 16;
3030
3775
  hh[6] = ah6 = c & 65535 | d << 16;
3031
- hl[6] = al6 = a & 65535 | b << 16;
3776
+ hl[6] = al6 = a & 65535 | b3 << 16;
3032
3777
  h = ah7;
3033
3778
  l = al7;
3034
3779
  a = l & 65535;
3035
- b = l >>> 16;
3780
+ b3 = l >>> 16;
3036
3781
  c = h & 65535;
3037
3782
  d = h >>> 16;
3038
3783
  h = hh[7];
3039
3784
  l = hl[7];
3040
3785
  a += l & 65535;
3041
- b += l >>> 16;
3786
+ b3 += l >>> 16;
3042
3787
  c += h & 65535;
3043
3788
  d += h >>> 16;
3044
- b += a >>> 16;
3045
- c += b >>> 16;
3789
+ b3 += a >>> 16;
3790
+ c += b3 >>> 16;
3046
3791
  d += c >>> 16;
3047
3792
  hh[7] = ah7 = c & 65535 | d << 16;
3048
- hl[7] = al7 = a & 65535 | b << 16;
3793
+ hl[7] = al7 = a & 65535 | b3 << 16;
3049
3794
  pos += 128;
3050
3795
  n -= 128;
3051
3796
  }
3052
3797
  return n;
3053
3798
  }
3054
3799
  function crypto_hash(out, m, n) {
3055
- var hh = new Int32Array(8), hl = new Int32Array(8), x = new Uint8Array(256), i, b = n;
3800
+ var hh = new Int32Array(8), hl = new Int32Array(8), x = new Uint8Array(256), i, b3 = n;
3056
3801
  hh[0] = 1779033703;
3057
3802
  hh[1] = 3144134277;
3058
3803
  hh[2] = 1013904242;
@@ -3072,41 +3817,41 @@ var require_nacl_fast = __commonJS((exports, module) => {
3072
3817
  crypto_hashblocks_hl(hh, hl, m, n);
3073
3818
  n %= 128;
3074
3819
  for (i = 0;i < n; i++)
3075
- x[i] = m[b - n + i];
3820
+ x[i] = m[b3 - n + i];
3076
3821
  x[n] = 128;
3077
3822
  n = 256 - 128 * (n < 112 ? 1 : 0);
3078
3823
  x[n - 9] = 0;
3079
- ts64(x, n - 8, b / 536870912 | 0, b << 3);
3824
+ ts64(x, n - 8, b3 / 536870912 | 0, b3 << 3);
3080
3825
  crypto_hashblocks_hl(hh, hl, x, n);
3081
3826
  for (i = 0;i < 8; i++)
3082
3827
  ts64(out, 8 * i, hh[i], hl[i]);
3083
3828
  return 0;
3084
3829
  }
3085
3830
  function add(p, q) {
3086
- var a = gf(), b = gf(), c = gf(), d = gf(), e = gf(), f = gf(), g = gf(), h = gf(), t3 = gf();
3831
+ var a = gf(), b3 = gf(), c = gf(), d = gf(), e = gf(), f = gf(), g = gf(), h = gf(), t3 = gf();
3087
3832
  Z(a, p[1], p[0]);
3088
3833
  Z(t3, q[1], q[0]);
3089
3834
  M(a, a, t3);
3090
- A(b, p[0], p[1]);
3835
+ A(b3, p[0], p[1]);
3091
3836
  A(t3, q[0], q[1]);
3092
- M(b, b, t3);
3837
+ M(b3, b3, t3);
3093
3838
  M(c, p[3], q[3]);
3094
3839
  M(c, c, D2);
3095
3840
  M(d, p[2], q[2]);
3096
3841
  A(d, d, d);
3097
- Z(e, b, a);
3842
+ Z(e, b3, a);
3098
3843
  Z(f, d, c);
3099
3844
  A(g, d, c);
3100
- A(h, b, a);
3845
+ A(h, b3, a);
3101
3846
  M(p[0], e, f);
3102
3847
  M(p[1], h, g);
3103
3848
  M(p[2], g, f);
3104
3849
  M(p[3], e, h);
3105
3850
  }
3106
- function cswap(p, q, b) {
3851
+ function cswap(p, q, b3) {
3107
3852
  var i;
3108
3853
  for (i = 0;i < 4; i++) {
3109
- sel25519(p[i], q[i], b);
3854
+ sel25519(p[i], q[i], b3);
3110
3855
  }
3111
3856
  }
3112
3857
  function pack(r, p) {
@@ -3118,17 +3863,17 @@ var require_nacl_fast = __commonJS((exports, module) => {
3118
3863
  r[31] ^= par25519(tx) << 7;
3119
3864
  }
3120
3865
  function scalarmult(p, q, s) {
3121
- var b, i;
3866
+ var b3, i;
3122
3867
  set25519(p[0], gf0);
3123
3868
  set25519(p[1], gf1);
3124
3869
  set25519(p[2], gf1);
3125
3870
  set25519(p[3], gf0);
3126
3871
  for (i = 255;i >= 0; --i) {
3127
- b = s[i / 8 | 0] >> (i & 7) & 1;
3128
- cswap(p, q, b);
3872
+ b3 = s[i / 8 | 0] >> (i & 7) & 1;
3873
+ cswap(p, q, b3);
3129
3874
  add(q, p);
3130
3875
  add(p, p);
3131
- cswap(p, q, b);
3876
+ cswap(p, q, b3);
3132
3877
  }
3133
3878
  }
3134
3879
  function scalarbase(p, s) {
@@ -3355,9 +4100,9 @@ var require_nacl_fast = __commonJS((exports, module) => {
3355
4100
  };
3356
4101
  }
3357
4102
  nacl.randomBytes = function(n) {
3358
- var b = new Uint8Array(n);
3359
- randombytes(b, n);
3360
- return b;
4103
+ var b3 = new Uint8Array(n);
4104
+ randombytes(b3, n);
4105
+ return b3;
3361
4106
  };
3362
4107
  nacl.secretbox = function(msg, nonce, key) {
3363
4108
  checkArrayTypes(msg, nonce, key);
@@ -5440,16 +6185,16 @@ var require_poly1305 = __commonJS((exports, module) => {
5440
6185
  _scriptDir = _scriptDir || __filename;
5441
6186
  return function(createPoly13052) {
5442
6187
  createPoly13052 = createPoly13052 || {};
5443
- var b;
5444
- b || (b = typeof createPoly13052 !== "undefined" ? createPoly13052 : {});
6188
+ var b3;
6189
+ b3 || (b3 = typeof createPoly13052 !== "undefined" ? createPoly13052 : {});
5445
6190
  var q, r;
5446
- b.ready = new Promise(function(a, c) {
6191
+ b3.ready = new Promise(function(a, c) {
5447
6192
  q = a;
5448
6193
  r = c;
5449
6194
  });
5450
6195
  var u = {}, w;
5451
- for (w in b)
5452
- b.hasOwnProperty(w) && (u[w] = b[w]);
6196
+ for (w in b3)
6197
+ b3.hasOwnProperty(w) && (u[w] = b3[w]);
5453
6198
  var x = typeof window === "object", y = typeof importScripts === "function", z = typeof process === "object" && typeof process.versions === "object" && typeof process.versions.node === "string", B = "", C, D, E, F, G;
5454
6199
  if (z)
5455
6200
  B = y ? __require("path").dirname(B) + "/" : __dirname + "/", C = function(a, c) {
@@ -5474,7 +6219,7 @@ var require_poly1305 = __commonJS((exports, module) => {
5474
6219
  F.readFile(a, function(f, l) {
5475
6220
  f ? d(f) : c(l.buffer);
5476
6221
  });
5477
- }, 1 < process.argv.length && process.argv[1].replace(/\\/g, "/"), process.argv.slice(2), b.inspect = function() {
6222
+ }, 1 < process.argv.length && process.argv[1].replace(/\\/g, "/"), process.argv.slice(2), b3.inspect = function() {
5478
6223
  return "[Emscripten Module object]";
5479
6224
  };
5480
6225
  else if (x || y)
@@ -5523,21 +6268,21 @@ var require_poly1305 = __commonJS((exports, module) => {
5523
6268
  e.onerror = d;
5524
6269
  e.send(null);
5525
6270
  };
5526
- b.print || console.log.bind(console);
5527
- var I = b.printErr || console.warn.bind(console);
6271
+ b3.print || console.log.bind(console);
6272
+ var I = b3.printErr || console.warn.bind(console);
5528
6273
  for (w in u)
5529
- u.hasOwnProperty(w) && (b[w] = u[w]);
6274
+ u.hasOwnProperty(w) && (b3[w] = u[w]);
5530
6275
  u = null;
5531
6276
  var J;
5532
- b.wasmBinary && (J = b.wasmBinary);
5533
- var noExitRuntime = b.noExitRuntime || true;
6277
+ b3.wasmBinary && (J = b3.wasmBinary);
6278
+ var noExitRuntime = b3.noExitRuntime || true;
5534
6279
  typeof WebAssembly !== "object" && K("no native wasm support detected");
5535
6280
  var L, M = false;
5536
6281
  function assert(a, c) {
5537
6282
  a || K("Assertion failed: " + c);
5538
6283
  }
5539
6284
  function N(a) {
5540
- var c = b["_" + a];
6285
+ var c = b3["_" + a];
5541
6286
  assert(c, "Cannot call unknown function " + a + ", make sure it is exported");
5542
6287
  return c;
5543
6288
  }
@@ -5634,26 +6379,26 @@ var require_poly1305 = __commonJS((exports, module) => {
5634
6379
  function ia() {
5635
6380
  var a = L.buffer;
5636
6381
  ha = a;
5637
- b.HEAP8 = Q = new Int8Array(a);
5638
- b.HEAP16 = new Int16Array(a);
5639
- b.HEAP32 = new Int32Array(a);
5640
- b.HEAPU8 = P = new Uint8Array(a);
5641
- b.HEAPU16 = new Uint16Array(a);
5642
- b.HEAPU32 = new Uint32Array(a);
5643
- b.HEAPF32 = new Float32Array(a);
5644
- b.HEAPF64 = new Float64Array(a);
6382
+ b3.HEAP8 = Q = new Int8Array(a);
6383
+ b3.HEAP16 = new Int16Array(a);
6384
+ b3.HEAP32 = new Int32Array(a);
6385
+ b3.HEAPU8 = P = new Uint8Array(a);
6386
+ b3.HEAPU16 = new Uint16Array(a);
6387
+ b3.HEAPU32 = new Uint32Array(a);
6388
+ b3.HEAPF32 = new Float32Array(a);
6389
+ b3.HEAPF64 = new Float64Array(a);
5645
6390
  }
5646
6391
  var R, ja = [], ka = [], la = [];
5647
6392
  function ma() {
5648
- var a = b.preRun.shift();
6393
+ var a = b3.preRun.shift();
5649
6394
  ja.unshift(a);
5650
6395
  }
5651
6396
  var S = 0, T = null, U = null;
5652
- b.preloadedImages = {};
5653
- b.preloadedAudios = {};
6397
+ b3.preloadedImages = {};
6398
+ b3.preloadedAudios = {};
5654
6399
  function K(a) {
5655
- if (b.onAbort)
5656
- b.onAbort(a);
6400
+ if (b3.onAbort)
6401
+ b3.onAbort(a);
5657
6402
  I(a);
5658
6403
  M = true;
5659
6404
  a = new WebAssembly.RuntimeError("abort(" + a + "). Build with -s ASSERTIONS=1 for more info.");
@@ -5664,7 +6409,7 @@ var require_poly1305 = __commonJS((exports, module) => {
5664
6409
  W = "data:application/octet-stream;base64,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";
5665
6410
  if (!W.startsWith(V)) {
5666
6411
  var na = W;
5667
- W = b.locateFile ? b.locateFile(na, B) : B + na;
6412
+ W = b3.locateFile ? b3.locateFile(na, B) : B + na;
5668
6413
  }
5669
6414
  function pa() {
5670
6415
  var a = W;
@@ -5706,7 +6451,7 @@ var require_poly1305 = __commonJS((exports, module) => {
5706
6451
  for (;0 < a.length; ) {
5707
6452
  var c = a.shift();
5708
6453
  if (typeof c == "function")
5709
- c(b);
6454
+ c(b3);
5710
6455
  else {
5711
6456
  var d = c.m;
5712
6457
  typeof d === "number" ? c.l === undefined ? R.get(d)() : R.get(d)(c.l) : d(c.l === undefined ? null : c.l);
@@ -5774,13 +6519,13 @@ var require_poly1305 = __commonJS((exports, module) => {
5774
6519
  } };
5775
6520
  (function() {
5776
6521
  function a(f) {
5777
- b.asm = f.exports;
5778
- L = b.asm.b;
6522
+ b3.asm = f.exports;
6523
+ L = b3.asm.b;
5779
6524
  ia();
5780
- R = b.asm.j;
5781
- ka.unshift(b.asm.c);
6525
+ R = b3.asm.j;
6526
+ ka.unshift(b3.asm.c);
5782
6527
  S--;
5783
- b.monitorRunDependencies && b.monitorRunDependencies(S);
6528
+ b3.monitorRunDependencies && b3.monitorRunDependencies(S);
5784
6529
  S == 0 && (T !== null && (clearInterval(T), T = null), U && (f = U, U = null, f()));
5785
6530
  }
5786
6531
  function c(f) {
@@ -5796,10 +6541,10 @@ var require_poly1305 = __commonJS((exports, module) => {
5796
6541
  }
5797
6542
  var e = { a: sa };
5798
6543
  S++;
5799
- b.monitorRunDependencies && b.monitorRunDependencies(S);
5800
- if (b.instantiateWasm)
6544
+ b3.monitorRunDependencies && b3.monitorRunDependencies(S);
6545
+ if (b3.instantiateWasm)
5801
6546
  try {
5802
- return b.instantiateWasm(e, a);
6547
+ return b3.instantiateWasm(e, a);
5803
6548
  } catch (f) {
5804
6549
  return I("Module.instantiateWasm callback failed with error: " + f), false;
5805
6550
  }
@@ -5814,26 +6559,26 @@ var require_poly1305 = __commonJS((exports, module) => {
5814
6559
  })().catch(r);
5815
6560
  return {};
5816
6561
  })();
5817
- b.___wasm_call_ctors = function() {
5818
- return (b.___wasm_call_ctors = b.asm.c).apply(null, arguments);
6562
+ b3.___wasm_call_ctors = function() {
6563
+ return (b3.___wasm_call_ctors = b3.asm.c).apply(null, arguments);
5819
6564
  };
5820
- b._poly1305_auth = function() {
5821
- return (b._poly1305_auth = b.asm.d).apply(null, arguments);
6565
+ b3._poly1305_auth = function() {
6566
+ return (b3._poly1305_auth = b3.asm.d).apply(null, arguments);
5822
6567
  };
5823
- var da = b.stackSave = function() {
5824
- return (da = b.stackSave = b.asm.e).apply(null, arguments);
5825
- }, fa = b.stackRestore = function() {
5826
- return (fa = b.stackRestore = b.asm.f).apply(null, arguments);
5827
- }, O = b.stackAlloc = function() {
5828
- return (O = b.stackAlloc = b.asm.g).apply(null, arguments);
6568
+ var da = b3.stackSave = function() {
6569
+ return (da = b3.stackSave = b3.asm.e).apply(null, arguments);
6570
+ }, fa = b3.stackRestore = function() {
6571
+ return (fa = b3.stackRestore = b3.asm.f).apply(null, arguments);
6572
+ }, O = b3.stackAlloc = function() {
6573
+ return (O = b3.stackAlloc = b3.asm.g).apply(null, arguments);
5829
6574
  };
5830
- b._malloc = function() {
5831
- return (b._malloc = b.asm.h).apply(null, arguments);
6575
+ b3._malloc = function() {
6576
+ return (b3._malloc = b3.asm.h).apply(null, arguments);
5832
6577
  };
5833
- b._free = function() {
5834
- return (b._free = b.asm.i).apply(null, arguments);
6578
+ b3._free = function() {
6579
+ return (b3._free = b3.asm.i).apply(null, arguments);
5835
6580
  };
5836
- b.cwrap = function(a, c, d, e) {
6581
+ b3.cwrap = function(a, c, d, e) {
5837
6582
  d = d || [];
5838
6583
  var f = d.every(function(l) {
5839
6584
  return l === "number";
@@ -5849,36 +6594,36 @@ var require_poly1305 = __commonJS((exports, module) => {
5849
6594
  };
5850
6595
  function Z() {
5851
6596
  function a() {
5852
- if (!Y && (Y = true, b.calledRun = true, !M)) {
6597
+ if (!Y && (Y = true, b3.calledRun = true, !M)) {
5853
6598
  X(ka);
5854
- q(b);
5855
- if (b.onRuntimeInitialized)
5856
- b.onRuntimeInitialized();
5857
- if (b.postRun)
5858
- for (typeof b.postRun == "function" && (b.postRun = [b.postRun]);b.postRun.length; ) {
5859
- var c = b.postRun.shift();
6599
+ q(b3);
6600
+ if (b3.onRuntimeInitialized)
6601
+ b3.onRuntimeInitialized();
6602
+ if (b3.postRun)
6603
+ for (typeof b3.postRun == "function" && (b3.postRun = [b3.postRun]);b3.postRun.length; ) {
6604
+ var c = b3.postRun.shift();
5860
6605
  la.unshift(c);
5861
6606
  }
5862
6607
  X(la);
5863
6608
  }
5864
6609
  }
5865
6610
  if (!(0 < S)) {
5866
- if (b.preRun)
5867
- for (typeof b.preRun == "function" && (b.preRun = [b.preRun]);b.preRun.length; )
6611
+ if (b3.preRun)
6612
+ for (typeof b3.preRun == "function" && (b3.preRun = [b3.preRun]);b3.preRun.length; )
5868
6613
  ma();
5869
6614
  X(ja);
5870
- 0 < S || (b.setStatus ? (b.setStatus("Running..."), setTimeout(function() {
6615
+ 0 < S || (b3.setStatus ? (b3.setStatus("Running..."), setTimeout(function() {
5871
6616
  setTimeout(function() {
5872
- b.setStatus("");
6617
+ b3.setStatus("");
5873
6618
  }, 1);
5874
6619
  a();
5875
6620
  }, 1)) : a());
5876
6621
  }
5877
6622
  }
5878
- b.run = Z;
5879
- if (b.preInit)
5880
- for (typeof b.preInit == "function" && (b.preInit = [b.preInit]);0 < b.preInit.length; )
5881
- b.preInit.pop()();
6623
+ b3.run = Z;
6624
+ if (b3.preInit)
6625
+ for (typeof b3.preInit == "function" && (b3.preInit = [b3.preInit]);0 < b3.preInit.length; )
6626
+ b3.preInit.pop()();
5882
6627
  Z();
5883
6628
  return createPoly13052.ready;
5884
6629
  };
@@ -6944,12 +7689,12 @@ var require_crypto = __commonJS((exports, module) => {
6944
7689
  return ret;
6945
7690
  };
6946
7691
  })();
6947
- function timingSafeEquals(a, b) {
6948
- if (a.length !== b.length) {
7692
+ function timingSafeEquals(a, b3) {
7693
+ if (a.length !== b3.length) {
6949
7694
  timingSafeEqual(a, a);
6950
7695
  return false;
6951
7696
  }
6952
- return timingSafeEqual(a, b);
7697
+ return timingSafeEqual(a, b3);
6953
7698
  }
6954
7699
  function createCipher(config2) {
6955
7700
  if (typeof config2 !== "object" || config2 === null)
@@ -12722,7 +13467,7 @@ var require_Protocol = __commonJS((exports, module) => {
12722
13467
  function modesToBytes(modes) {
12723
13468
  const keys = Object.keys(modes);
12724
13469
  const bytes = Buffer.allocUnsafe(5 * keys.length + 1);
12725
- let b = 0;
13470
+ let b3 = 0;
12726
13471
  for (let i = 0;i < keys.length; ++i) {
12727
13472
  const key = keys[i];
12728
13473
  if (key === "TTY_OP_END")
@@ -12732,16 +13477,16 @@ var require_Protocol = __commonJS((exports, module) => {
12732
13477
  continue;
12733
13478
  const val = modes[key];
12734
13479
  if (typeof val === "number" && isFinite(val)) {
12735
- bytes[b++] = opcode;
12736
- bytes[b++] = val >>> 24;
12737
- bytes[b++] = val >>> 16;
12738
- bytes[b++] = val >>> 8;
12739
- bytes[b++] = val;
13480
+ bytes[b3++] = opcode;
13481
+ bytes[b3++] = val >>> 24;
13482
+ bytes[b3++] = val >>> 16;
13483
+ bytes[b3++] = val >>> 8;
13484
+ bytes[b3++] = val;
12740
13485
  }
12741
13486
  }
12742
- bytes[b++] = TERMINAL_MODE.TTY_OP_END;
12743
- if (b < bytes.length)
12744
- return bufferSlice(bytes, 0, b);
13487
+ bytes[b3++] = TERMINAL_MODE.TTY_OP_END;
13488
+ if (b3 < bytes.length)
13489
+ return bufferSlice(bytes, 0, b3);
12745
13490
  return bytes;
12746
13491
  }
12747
13492
  function sendExtInfo(proto) {
@@ -15549,7 +16294,7 @@ var require_SFTP = __commonJS((exports, module) => {
15549
16294
  this.destroy();
15550
16295
  return;
15551
16296
  }
15552
- let b = null;
16297
+ let b3 = null;
15553
16298
  if (start + toRead === thisPool.used && thisPool === pool) {
15554
16299
  thisPool.used = roundUpToMultipleOf8(thisPool.used + bytesRead - toRead);
15555
16300
  } else {
@@ -15560,10 +16305,10 @@ var require_SFTP = __commonJS((exports, module) => {
15560
16305
  }
15561
16306
  if (bytesRead > 0) {
15562
16307
  this.bytesRead += bytesRead;
15563
- b = thisPool.slice(start, start + bytesRead);
16308
+ b3 = thisPool.slice(start, start + bytesRead);
15564
16309
  }
15565
16310
  this.pos += bytesRead;
15566
- this.push(b);
16311
+ this.push(b3);
15567
16312
  });
15568
16313
  pool.used = roundUpToMultipleOf8(pool.used + toRead);
15569
16314
  };
@@ -19072,8 +19817,8 @@ var require_server = __commonJS((exports, module) => {
19072
19817
  throw new Error(`Unsupported channel type: ${type}`);
19073
19818
  }
19074
19819
  }
19075
- function compareNumbers(a, b) {
19076
- return a - b;
19820
+ function compareNumbers(a, b3) {
19821
+ return a - b3;
19077
19822
  }
19078
19823
  module.exports = Server;
19079
19824
  module.exports.IncomingClient = Client;
@@ -19629,6 +20374,7 @@ var I18N_RESOURCES = {
19629
20374
  passphrase: "Passphrase",
19630
20375
  connect: "Connect",
19631
20376
  connected: "Connected",
20377
+ disconnect: "Disconnect",
19632
20378
  disconnected: "Disconnected",
19633
20379
  connecting: "Connecting...",
19634
20380
  deleteConfirm: "Delete this device?",
@@ -19861,6 +20607,10 @@ Time: {{time}}`,
19861
20607
  closePane: "Close Pane",
19862
20608
  addDevice: "Add Device"
19863
20609
  },
20610
+ window: {
20611
+ noWindows: "No windows",
20612
+ new: "New Window"
20613
+ },
19864
20614
  validation: {
19865
20615
  deviceNameRequired: "Device name is required",
19866
20616
  hostRequired: "Host is required for SSH devices"
@@ -19951,6 +20701,7 @@ Time: {{time}}`,
19951
20701
  passphrase: "\u79C1\u94A5\u5BC6\u7801\uFF08\u53EF\u9009\uFF09",
19952
20702
  connect: "\u8FDE\u63A5",
19953
20703
  connected: "\u5DF2\u8FDE\u63A5",
20704
+ disconnect: "\u65AD\u5F00",
19954
20705
  disconnected: "\u5DF2\u65AD\u5F00",
19955
20706
  connecting: "\u8FDE\u63A5\u4E2D...",
19956
20707
  deleteConfirm: "\u5220\u9664\u6B64\u8BBE\u5907\uFF1F",
@@ -20183,6 +20934,10 @@ Bot\uFF1A{{botName}}
20183
20934
  closePane: "\u5173\u95ED pane",
20184
20935
  addDevice: "\u6DFB\u52A0\u8BBE\u5907"
20185
20936
  },
20937
+ window: {
20938
+ noWindows: "\u6682\u65E0\u7A97\u53E3",
20939
+ new: "\u65B0\u5EFA\u7A97\u53E3"
20940
+ },
20186
20941
  validation: {
20187
20942
  deviceNameRequired: "\u8BBE\u5907\u540D\u79F0\u4E3A\u5FC5\u586B\u9879",
20188
20943
  hostRequired: "SSH \u8BBE\u5907\u9700\u8981\u586B\u5199\u4E3B\u673A\u5730\u5740"
@@ -20273,6 +21028,7 @@ Bot\uFF1A{{botName}}
20273
21028
  passphrase: "\u30D1\u30B9\u30D5\u30EC\u30FC\u30BA",
20274
21029
  connect: "\u63A5\u7D9A",
20275
21030
  connected: "\u63A5\u7D9A\u6E08\u307F",
21031
+ disconnect: "\u5207\u65AD",
20276
21032
  disconnected: "\u5207\u65AD\u6E08\u307F",
20277
21033
  connecting: "\u63A5\u7D9A\u4E2D...",
20278
21034
  deleteConfirm: "\u3053\u306E\u30C7\u30D0\u30A4\u30B9\u3092\u524A\u9664\u3057\u307E\u3059\u304B\uFF1F",
@@ -20505,6 +21261,10 @@ Bot\uFF1A{{botName}}
20505
21261
  closePane: "\u30DA\u30A4\u30F3\u3092\u9589\u3058\u308B",
20506
21262
  addDevice: "\u30C7\u30D0\u30A4\u30B9\u3092\u8FFD\u52A0"
20507
21263
  },
21264
+ window: {
21265
+ noWindows: "\u30A6\u30A3\u30F3\u30C9\u30A6\u304C\u3042\u308A\u307E\u305B\u3093",
21266
+ new: "\u65B0\u898F\u30A6\u30A3\u30F3\u30C9\u30A6"
21267
+ },
20508
21268
  validation: {
20509
21269
  deviceNameRequired: "\u30C7\u30D0\u30A4\u30B9\u540D\u306F\u5FC5\u9808\u3067\u3059",
20510
21270
  hostRequired: "SSH \u30C7\u30D0\u30A4\u30B9\u306B\u306F\u30DB\u30B9\u30C8\u30A2\u30C9\u30EC\u30B9\u304C\u5FC5\u8981\u3067\u3059"
@@ -20517,6 +21277,939 @@ function toBCP47(locale) {
20517
21277
  return locale.replace("_", "-");
20518
21278
  }
20519
21279
  var AVAILABLE_LOCALES = ["en_US", "zh_CN", "ja_JP"];
21280
+ // ../shared/src/ws-borsh/index.ts
21281
+ var exports_ws_borsh = {};
21282
+ __export(exports_ws_borsh, {
21283
+ splitPayloadIntoChunks: () => splitPayloadIntoChunks,
21284
+ setFlag: () => setFlag,
21285
+ schema: () => exports_schema,
21286
+ resetChunkStreamId: () => resetChunkStreamId,
21287
+ kindToString: () => kindToString,
21288
+ isValidKind: () => isValidKind,
21289
+ hasFlag: () => hasFlag,
21290
+ getErrorMessage: () => getErrorMessage,
21291
+ generateChunkStreamId: () => generateChunkStreamId,
21292
+ encodeTmuxEventPayload: () => encodeTmuxEventPayload,
21293
+ encodeStateSnapshot: () => encodeStateSnapshot,
21294
+ encodePayload: () => encodePayload,
21295
+ encodeEnvelope: () => encodeEnvelope,
21296
+ encodeDeviceEventPayload: () => encodeDeviceEventPayload,
21297
+ encodeChunk: () => encodeChunk,
21298
+ decodeTmuxEventPayload: () => decodeTmuxEventPayload,
21299
+ decodeStateSnapshot: () => decodeStateSnapshot,
21300
+ decodePayload: () => decodePayload,
21301
+ decodeEnvelopeAndPayload: () => decodeEnvelopeAndPayload,
21302
+ decodeEnvelope: () => decodeEnvelope,
21303
+ decodeDeviceEventPayload: () => decodeDeviceEventPayload,
21304
+ decodeChunk: () => decodeChunk,
21305
+ createSeqGenerator: () => createSeqGenerator,
21306
+ checkMagic: () => checkMagic,
21307
+ b: () => import_zorsh2.b,
21308
+ WsBorshError: () => WsBorshError,
21309
+ MAX_CHUNK_STREAMS: () => MAX_CHUNK_STREAMS,
21310
+ MAX_CHUNKS_PER_MESSAGE: () => MAX_CHUNKS_PER_MESSAGE,
21311
+ MAGIC: () => MAGIC,
21312
+ KIND_TMUX_SELECT_WINDOW: () => KIND_TMUX_SELECT_WINDOW,
21313
+ KIND_TMUX_SELECT: () => KIND_TMUX_SELECT,
21314
+ KIND_TMUX_RENAME_WINDOW: () => KIND_TMUX_RENAME_WINDOW,
21315
+ KIND_TMUX_EVENT: () => KIND_TMUX_EVENT,
21316
+ KIND_TMUX_CREATE_WINDOW: () => KIND_TMUX_CREATE_WINDOW,
21317
+ KIND_TMUX_CLOSE_WINDOW: () => KIND_TMUX_CLOSE_WINDOW,
21318
+ KIND_TMUX_CLOSE_PANE: () => KIND_TMUX_CLOSE_PANE,
21319
+ KIND_TERM_SYNC_SIZE: () => KIND_TERM_SYNC_SIZE,
21320
+ KIND_TERM_RESIZE: () => KIND_TERM_RESIZE,
21321
+ KIND_TERM_PASTE: () => KIND_TERM_PASTE,
21322
+ KIND_TERM_OUTPUT: () => KIND_TERM_OUTPUT,
21323
+ KIND_TERM_INPUT: () => KIND_TERM_INPUT,
21324
+ KIND_TERM_HISTORY: () => KIND_TERM_HISTORY,
21325
+ KIND_SWITCH_ACK: () => KIND_SWITCH_ACK,
21326
+ KIND_STATE_SNAPSHOT_DIFF: () => KIND_STATE_SNAPSHOT_DIFF,
21327
+ KIND_STATE_SNAPSHOT: () => KIND_STATE_SNAPSHOT,
21328
+ KIND_PONG: () => KIND_PONG,
21329
+ KIND_PING: () => KIND_PING,
21330
+ KIND_LIVE_RESUME: () => KIND_LIVE_RESUME,
21331
+ KIND_HELLO_S2C: () => KIND_HELLO_S2C,
21332
+ KIND_HELLO_C2S: () => KIND_HELLO_C2S,
21333
+ KIND_ERROR: () => KIND_ERROR,
21334
+ KIND_DEVICE_EVENT: () => KIND_DEVICE_EVENT,
21335
+ KIND_DEVICE_DISCONNECTED: () => KIND_DEVICE_DISCONNECTED,
21336
+ KIND_DEVICE_DISCONNECT: () => KIND_DEVICE_DISCONNECT,
21337
+ KIND_DEVICE_CONNECTED: () => KIND_DEVICE_CONNECTED,
21338
+ KIND_DEVICE_CONNECT: () => KIND_DEVICE_CONNECT,
21339
+ KIND_CHUNK: () => KIND_CHUNK,
21340
+ FLAG_IS_ERROR: () => FLAG_IS_ERROR,
21341
+ FLAG_IS_COMPRESSED: () => FLAG_IS_COMPRESSED,
21342
+ FLAG_IS_CHUNK: () => FLAG_IS_CHUNK,
21343
+ FLAG_IS_ACK: () => FLAG_IS_ACK,
21344
+ FLAG_ACK_REQUIRED: () => FLAG_ACK_REQUIRED,
21345
+ ERROR_UNSUPPORTED_PROTOCOL: () => ERROR_UNSUPPORTED_PROTOCOL,
21346
+ ERROR_UNKNOWN_KIND: () => ERROR_UNKNOWN_KIND,
21347
+ ERROR_TMUX_TARGET_NOT_FOUND: () => ERROR_TMUX_TARGET_NOT_FOUND,
21348
+ ERROR_TMUX_NOT_READY: () => ERROR_TMUX_NOT_READY,
21349
+ ERROR_SELECT_TOKEN_MISMATCH: () => ERROR_SELECT_TOKEN_MISMATCH,
21350
+ ERROR_SELECT_CONFLICT: () => ERROR_SELECT_CONFLICT,
21351
+ ERROR_PAYLOAD_DECODE_FAILED: () => ERROR_PAYLOAD_DECODE_FAILED,
21352
+ ERROR_MESSAGES: () => ERROR_MESSAGES,
21353
+ ERROR_INVALID_FRAME: () => ERROR_INVALID_FRAME,
21354
+ ERROR_INTERNAL_ERROR: () => ERROR_INTERNAL_ERROR,
21355
+ ERROR_FRAME_TOO_LARGE: () => ERROR_FRAME_TOO_LARGE,
21356
+ ERROR_DEVICE_NOT_FOUND: () => ERROR_DEVICE_NOT_FOUND,
21357
+ ERROR_DEVICE_CONNECT_FAILED: () => ERROR_DEVICE_CONNECT_FAILED,
21358
+ DEFAULT_MAX_FRAME_BYTES: () => DEFAULT_MAX_FRAME_BYTES,
21359
+ ChunkReassembler: () => ChunkReassembler,
21360
+ CURRENT_VERSION: () => CURRENT_VERSION,
21361
+ CHUNK_TIMEOUT_MS: () => CHUNK_TIMEOUT_MS
21362
+ });
21363
+ var import_zorsh2 = __toESM(require_src(), 1);
21364
+
21365
+ // ../shared/src/ws-borsh/kind.ts
21366
+ var KIND_HELLO_C2S = 1;
21367
+ var KIND_HELLO_S2C = 2;
21368
+ var KIND_PING = 3;
21369
+ var KIND_PONG = 4;
21370
+ var KIND_ERROR = 5;
21371
+ var KIND_DEVICE_CONNECT = 257;
21372
+ var KIND_DEVICE_CONNECTED = 258;
21373
+ var KIND_DEVICE_DISCONNECT = 259;
21374
+ var KIND_DEVICE_DISCONNECTED = 260;
21375
+ var KIND_DEVICE_EVENT = 261;
21376
+ var KIND_TMUX_SELECT = 513;
21377
+ var KIND_TMUX_SELECT_WINDOW = 514;
21378
+ var KIND_TMUX_CREATE_WINDOW = 515;
21379
+ var KIND_TMUX_CLOSE_WINDOW = 516;
21380
+ var KIND_TMUX_CLOSE_PANE = 517;
21381
+ var KIND_TMUX_RENAME_WINDOW = 518;
21382
+ var KIND_TMUX_EVENT = 519;
21383
+ var KIND_STATE_SNAPSHOT = 520;
21384
+ var KIND_STATE_SNAPSHOT_DIFF = 521;
21385
+ var KIND_TERM_INPUT = 769;
21386
+ var KIND_TERM_PASTE = 770;
21387
+ var KIND_TERM_RESIZE = 771;
21388
+ var KIND_TERM_SYNC_SIZE = 772;
21389
+ var KIND_TERM_OUTPUT = 773;
21390
+ var KIND_TERM_HISTORY = 774;
21391
+ var KIND_SWITCH_ACK = 1025;
21392
+ var KIND_LIVE_RESUME = 1026;
21393
+ var KIND_CHUNK = 1281;
21394
+ var VALID_KINDS = new Set([
21395
+ KIND_HELLO_C2S,
21396
+ KIND_HELLO_S2C,
21397
+ KIND_PING,
21398
+ KIND_PONG,
21399
+ KIND_ERROR,
21400
+ KIND_DEVICE_CONNECT,
21401
+ KIND_DEVICE_CONNECTED,
21402
+ KIND_DEVICE_DISCONNECT,
21403
+ KIND_DEVICE_DISCONNECTED,
21404
+ KIND_DEVICE_EVENT,
21405
+ KIND_TMUX_SELECT,
21406
+ KIND_TMUX_SELECT_WINDOW,
21407
+ KIND_TMUX_CREATE_WINDOW,
21408
+ KIND_TMUX_CLOSE_WINDOW,
21409
+ KIND_TMUX_CLOSE_PANE,
21410
+ KIND_TMUX_RENAME_WINDOW,
21411
+ KIND_TMUX_EVENT,
21412
+ KIND_STATE_SNAPSHOT,
21413
+ KIND_STATE_SNAPSHOT_DIFF,
21414
+ KIND_TERM_INPUT,
21415
+ KIND_TERM_PASTE,
21416
+ KIND_TERM_RESIZE,
21417
+ KIND_TERM_SYNC_SIZE,
21418
+ KIND_TERM_OUTPUT,
21419
+ KIND_TERM_HISTORY,
21420
+ KIND_SWITCH_ACK,
21421
+ KIND_LIVE_RESUME,
21422
+ KIND_CHUNK
21423
+ ]);
21424
+ function isValidKind(kind) {
21425
+ return VALID_KINDS.has(kind);
21426
+ }
21427
+ function kindToString(kind) {
21428
+ const kindMap = {
21429
+ [KIND_HELLO_C2S]: "HELLO_C2S",
21430
+ [KIND_HELLO_S2C]: "HELLO_S2C",
21431
+ [KIND_PING]: "PING",
21432
+ [KIND_PONG]: "PONG",
21433
+ [KIND_ERROR]: "ERROR",
21434
+ [KIND_DEVICE_CONNECT]: "DEVICE_CONNECT",
21435
+ [KIND_DEVICE_CONNECTED]: "DEVICE_CONNECTED",
21436
+ [KIND_DEVICE_DISCONNECT]: "DEVICE_DISCONNECT",
21437
+ [KIND_DEVICE_DISCONNECTED]: "DEVICE_DISCONNECTED",
21438
+ [KIND_DEVICE_EVENT]: "DEVICE_EVENT",
21439
+ [KIND_TMUX_SELECT]: "TMUX_SELECT",
21440
+ [KIND_TMUX_SELECT_WINDOW]: "TMUX_SELECT_WINDOW",
21441
+ [KIND_TMUX_CREATE_WINDOW]: "TMUX_CREATE_WINDOW",
21442
+ [KIND_TMUX_CLOSE_WINDOW]: "TMUX_CLOSE_WINDOW",
21443
+ [KIND_TMUX_CLOSE_PANE]: "TMUX_CLOSE_PANE",
21444
+ [KIND_TMUX_RENAME_WINDOW]: "TMUX_RENAME_WINDOW",
21445
+ [KIND_TMUX_EVENT]: "TMUX_EVENT",
21446
+ [KIND_STATE_SNAPSHOT]: "STATE_SNAPSHOT",
21447
+ [KIND_STATE_SNAPSHOT_DIFF]: "STATE_SNAPSHOT_DIFF",
21448
+ [KIND_TERM_INPUT]: "TERM_INPUT",
21449
+ [KIND_TERM_PASTE]: "TERM_PASTE",
21450
+ [KIND_TERM_RESIZE]: "TERM_RESIZE",
21451
+ [KIND_TERM_SYNC_SIZE]: "TERM_SYNC_SIZE",
21452
+ [KIND_TERM_OUTPUT]: "TERM_OUTPUT",
21453
+ [KIND_TERM_HISTORY]: "TERM_HISTORY",
21454
+ [KIND_SWITCH_ACK]: "SWITCH_ACK",
21455
+ [KIND_LIVE_RESUME]: "LIVE_RESUME",
21456
+ [KIND_CHUNK]: "CHUNK"
21457
+ };
21458
+ return kindMap[kind] ?? `UNKNOWN(0x${kind.toString(16).padStart(4, "0")})`;
21459
+ }
21460
+ // ../shared/src/ws-borsh/errors.ts
21461
+ var ERROR_UNSUPPORTED_PROTOCOL = 1001;
21462
+ var ERROR_INVALID_FRAME = 1002;
21463
+ var ERROR_UNKNOWN_KIND = 1003;
21464
+ var ERROR_PAYLOAD_DECODE_FAILED = 1004;
21465
+ var ERROR_FRAME_TOO_LARGE = 1005;
21466
+ var ERROR_DEVICE_NOT_FOUND = 1101;
21467
+ var ERROR_DEVICE_CONNECT_FAILED = 1102;
21468
+ var ERROR_TMUX_TARGET_NOT_FOUND = 1201;
21469
+ var ERROR_TMUX_NOT_READY = 1202;
21470
+ var ERROR_SELECT_CONFLICT = 1301;
21471
+ var ERROR_SELECT_TOKEN_MISMATCH = 1302;
21472
+ var ERROR_INTERNAL_ERROR = 1401;
21473
+ var ERROR_MESSAGES = {
21474
+ [ERROR_UNSUPPORTED_PROTOCOL]: "Unsupported protocol version",
21475
+ [ERROR_INVALID_FRAME]: "Invalid frame format",
21476
+ [ERROR_UNKNOWN_KIND]: "Unknown message kind",
21477
+ [ERROR_PAYLOAD_DECODE_FAILED]: "Failed to decode payload",
21478
+ [ERROR_FRAME_TOO_LARGE]: "Frame exceeds maximum size",
21479
+ [ERROR_DEVICE_NOT_FOUND]: "Device not found",
21480
+ [ERROR_DEVICE_CONNECT_FAILED]: "Failed to connect device",
21481
+ [ERROR_TMUX_TARGET_NOT_FOUND]: "Tmux target not found",
21482
+ [ERROR_TMUX_NOT_READY]: "Tmux not ready",
21483
+ [ERROR_SELECT_CONFLICT]: "Select conflict",
21484
+ [ERROR_SELECT_TOKEN_MISMATCH]: "Select token mismatch",
21485
+ [ERROR_INTERNAL_ERROR]: "Internal server error"
21486
+ };
21487
+ function getErrorMessage(code) {
21488
+ return ERROR_MESSAGES[code] ?? `Unknown error code: ${code}`;
21489
+ }
21490
+
21491
+ class WsBorshError extends Error {
21492
+ code;
21493
+ retryable;
21494
+ constructor(code, retryable = false, message) {
21495
+ super(message ?? getErrorMessage(code));
21496
+ this.code = code;
21497
+ this.retryable = retryable;
21498
+ this.name = "WsBorshError";
21499
+ }
21500
+ }
21501
+ // ../shared/src/ws-borsh/schema.ts
21502
+ var exports_schema = {};
21503
+ __export(exports_schema, {
21504
+ WindowWireSchema: () => WindowWireSchema,
21505
+ WindowRenamedEventSchema: () => WindowRenamedEventSchema,
21506
+ WindowCloseEventSchema: () => WindowCloseEventSchema,
21507
+ WindowAddEventSchema: () => WindowAddEventSchema,
21508
+ WindowActiveEventSchema: () => WindowActiveEventSchema,
21509
+ TmuxSelectWindowSchema: () => TmuxSelectWindowSchema,
21510
+ TmuxSelectSchema: () => TmuxSelectSchema,
21511
+ TmuxRenameWindowSchema: () => TmuxRenameWindowSchema,
21512
+ TmuxEventSchema: () => TmuxEventSchema,
21513
+ TmuxCreateWindowSchema: () => TmuxCreateWindowSchema,
21514
+ TmuxCloseWindowSchema: () => TmuxCloseWindowSchema,
21515
+ TmuxClosePaneSchema: () => TmuxClosePaneSchema,
21516
+ TermSyncSizeSchema: () => TermSyncSizeSchema,
21517
+ TermResizeSchema: () => TermResizeSchema,
21518
+ TermPasteSchema: () => TermPasteSchema,
21519
+ TermOutputSchema: () => TermOutputSchema,
21520
+ TermInputSchema: () => TermInputSchema,
21521
+ TermHistorySchema: () => TermHistorySchema,
21522
+ SwitchAckSchema: () => SwitchAckSchema,
21523
+ StateSnapshotSchema: () => StateSnapshotSchema,
21524
+ StateSnapshotDiffSchema: () => StateSnapshotDiffSchema,
21525
+ SessionWireSchema: () => SessionWireSchema,
21526
+ PingPongSchema: () => PingPongSchema,
21527
+ PaneWireSchema: () => PaneWireSchema,
21528
+ PaneCloseEventSchema: () => PaneCloseEventSchema,
21529
+ PaneAddEventSchema: () => PaneAddEventSchema,
21530
+ PaneActiveEventSchema: () => PaneActiveEventSchema,
21531
+ OptionU32Schema: () => OptionU32Schema,
21532
+ OptionU16Schema: () => OptionU16Schema,
21533
+ OptionStringSchema: () => OptionStringSchema,
21534
+ LiveResumeSchema: () => LiveResumeSchema,
21535
+ LayoutChangeEventSchema: () => LayoutChangeEventSchema,
21536
+ HelloS2CSchema: () => HelloS2CSchema,
21537
+ HelloC2SSchema: () => HelloC2SSchema,
21538
+ ErrorSchema: () => ErrorSchema,
21539
+ EnvelopeSchema: () => EnvelopeSchema,
21540
+ DeviceEventSchema: () => DeviceEventSchema,
21541
+ DeviceDisconnectedSchema: () => DeviceDisconnectedSchema,
21542
+ DeviceDisconnectSchema: () => DeviceDisconnectSchema,
21543
+ DeviceConnectedSchema: () => DeviceConnectedSchema,
21544
+ DeviceConnectSchema: () => DeviceConnectSchema,
21545
+ ChunkSchema: () => ChunkSchema,
21546
+ BellEventSchema: () => BellEventSchema
21547
+ });
21548
+ var import_zorsh = __toESM(require_src(), 1);
21549
+ var EnvelopeSchema = import_zorsh.b.struct({
21550
+ magic: import_zorsh.b.bytes(2),
21551
+ version: import_zorsh.b.u16(),
21552
+ kind: import_zorsh.b.u16(),
21553
+ flags: import_zorsh.b.u16(),
21554
+ seq: import_zorsh.b.u32(),
21555
+ payload: import_zorsh.b.bytes()
21556
+ });
21557
+ var OptionU32Schema = import_zorsh.b.option(import_zorsh.b.u32());
21558
+ var OptionU16Schema = import_zorsh.b.option(import_zorsh.b.u16());
21559
+ var OptionStringSchema = import_zorsh.b.option(import_zorsh.b.string());
21560
+ var HelloC2SSchema = import_zorsh.b.struct({
21561
+ clientImpl: import_zorsh.b.string(),
21562
+ clientVersion: import_zorsh.b.string(),
21563
+ maxFrameBytes: import_zorsh.b.u32(),
21564
+ supportsCompression: import_zorsh.b.bool(),
21565
+ supportsDiffSnapshot: import_zorsh.b.bool()
21566
+ });
21567
+ var HelloS2CSchema = import_zorsh.b.struct({
21568
+ serverImpl: import_zorsh.b.string(),
21569
+ serverVersion: import_zorsh.b.string(),
21570
+ selectedVersion: import_zorsh.b.u16(),
21571
+ maxFrameBytes: import_zorsh.b.u32(),
21572
+ heartbeatIntervalMs: import_zorsh.b.u32(),
21573
+ capabilities: import_zorsh.b.vec(import_zorsh.b.string())
21574
+ });
21575
+ var PingPongSchema = import_zorsh.b.struct({
21576
+ nonce: import_zorsh.b.u32(),
21577
+ timeMs: import_zorsh.b.u64()
21578
+ });
21579
+ var ErrorSchema = import_zorsh.b.struct({
21580
+ refSeq: OptionU32Schema,
21581
+ code: import_zorsh.b.u16(),
21582
+ message: import_zorsh.b.string(),
21583
+ retryable: import_zorsh.b.bool()
21584
+ });
21585
+ var DeviceConnectSchema = import_zorsh.b.struct({
21586
+ deviceId: import_zorsh.b.string()
21587
+ });
21588
+ var DeviceConnectedSchema = import_zorsh.b.struct({
21589
+ deviceId: import_zorsh.b.string()
21590
+ });
21591
+ var DeviceDisconnectSchema = import_zorsh.b.struct({
21592
+ deviceId: import_zorsh.b.string()
21593
+ });
21594
+ var DeviceDisconnectedSchema = import_zorsh.b.struct({
21595
+ deviceId: import_zorsh.b.string()
21596
+ });
21597
+ var DeviceEventSchema = import_zorsh.b.struct({
21598
+ deviceId: import_zorsh.b.string(),
21599
+ eventType: import_zorsh.b.u8(),
21600
+ errorType: OptionStringSchema,
21601
+ message: OptionStringSchema,
21602
+ rawMessage: OptionStringSchema
21603
+ });
21604
+ var TmuxSelectSchema = import_zorsh.b.struct({
21605
+ deviceId: import_zorsh.b.string(),
21606
+ windowId: OptionStringSchema,
21607
+ paneId: OptionStringSchema,
21608
+ selectToken: import_zorsh.b.bytes(16),
21609
+ wantHistory: import_zorsh.b.bool(),
21610
+ cols: OptionU16Schema,
21611
+ rows: OptionU16Schema
21612
+ });
21613
+ var TmuxSelectWindowSchema = import_zorsh.b.struct({
21614
+ deviceId: import_zorsh.b.string(),
21615
+ windowId: import_zorsh.b.string()
21616
+ });
21617
+ var TmuxCreateWindowSchema = import_zorsh.b.struct({
21618
+ deviceId: import_zorsh.b.string(),
21619
+ name: OptionStringSchema
21620
+ });
21621
+ var TmuxCloseWindowSchema = import_zorsh.b.struct({
21622
+ deviceId: import_zorsh.b.string(),
21623
+ windowId: import_zorsh.b.string()
21624
+ });
21625
+ var TmuxClosePaneSchema = import_zorsh.b.struct({
21626
+ deviceId: import_zorsh.b.string(),
21627
+ paneId: import_zorsh.b.string()
21628
+ });
21629
+ var TmuxRenameWindowSchema = import_zorsh.b.struct({
21630
+ deviceId: import_zorsh.b.string(),
21631
+ windowId: import_zorsh.b.string(),
21632
+ name: import_zorsh.b.string()
21633
+ });
21634
+ var TmuxEventSchema = import_zorsh.b.struct({
21635
+ deviceId: import_zorsh.b.string(),
21636
+ eventType: import_zorsh.b.u8(),
21637
+ eventData: import_zorsh.b.bytes()
21638
+ });
21639
+ var TermInputSchema = import_zorsh.b.struct({
21640
+ deviceId: import_zorsh.b.string(),
21641
+ paneId: import_zorsh.b.string(),
21642
+ encoding: import_zorsh.b.u8(),
21643
+ data: import_zorsh.b.bytes(),
21644
+ isComposing: import_zorsh.b.bool()
21645
+ });
21646
+ var TermPasteSchema = import_zorsh.b.struct({
21647
+ deviceId: import_zorsh.b.string(),
21648
+ paneId: import_zorsh.b.string(),
21649
+ encoding: import_zorsh.b.u8(),
21650
+ data: import_zorsh.b.bytes(),
21651
+ isComposing: import_zorsh.b.bool()
21652
+ });
21653
+ var TermResizeSchema = import_zorsh.b.struct({
21654
+ deviceId: import_zorsh.b.string(),
21655
+ paneId: import_zorsh.b.string(),
21656
+ cols: import_zorsh.b.u16(),
21657
+ rows: import_zorsh.b.u16()
21658
+ });
21659
+ var TermSyncSizeSchema = TermResizeSchema;
21660
+ var TermOutputSchema = import_zorsh.b.struct({
21661
+ deviceId: import_zorsh.b.string(),
21662
+ paneId: import_zorsh.b.string(),
21663
+ encoding: import_zorsh.b.u8(),
21664
+ data: import_zorsh.b.bytes()
21665
+ });
21666
+ var TermHistorySchema = import_zorsh.b.struct({
21667
+ deviceId: import_zorsh.b.string(),
21668
+ paneId: import_zorsh.b.string(),
21669
+ selectToken: import_zorsh.b.bytes(16),
21670
+ encoding: import_zorsh.b.u8(),
21671
+ data: import_zorsh.b.bytes()
21672
+ });
21673
+ var SwitchAckSchema = import_zorsh.b.struct({
21674
+ deviceId: import_zorsh.b.string(),
21675
+ windowId: import_zorsh.b.string(),
21676
+ paneId: import_zorsh.b.string(),
21677
+ selectToken: import_zorsh.b.bytes(16)
21678
+ });
21679
+ var LiveResumeSchema = import_zorsh.b.struct({
21680
+ deviceId: import_zorsh.b.string(),
21681
+ paneId: import_zorsh.b.string(),
21682
+ selectToken: import_zorsh.b.bytes(16)
21683
+ });
21684
+ var ChunkSchema = import_zorsh.b.struct({
21685
+ chunkStreamId: import_zorsh.b.u32(),
21686
+ originalKind: import_zorsh.b.u16(),
21687
+ originalSeq: import_zorsh.b.u32(),
21688
+ totalChunks: import_zorsh.b.u16(),
21689
+ chunkIndex: import_zorsh.b.u16(),
21690
+ data: import_zorsh.b.bytes()
21691
+ });
21692
+ var PaneWireSchema = import_zorsh.b.struct({
21693
+ id: import_zorsh.b.string(),
21694
+ windowId: import_zorsh.b.string(),
21695
+ index: import_zorsh.b.u16(),
21696
+ title: OptionStringSchema,
21697
+ active: import_zorsh.b.bool(),
21698
+ width: import_zorsh.b.u16(),
21699
+ height: import_zorsh.b.u16()
21700
+ });
21701
+ var WindowWireSchema = import_zorsh.b.struct({
21702
+ id: import_zorsh.b.string(),
21703
+ name: import_zorsh.b.string(),
21704
+ index: import_zorsh.b.u16(),
21705
+ active: import_zorsh.b.bool(),
21706
+ panes: import_zorsh.b.vec(PaneWireSchema)
21707
+ });
21708
+ var SessionWireSchema = import_zorsh.b.struct({
21709
+ id: import_zorsh.b.string(),
21710
+ name: import_zorsh.b.string(),
21711
+ windows: import_zorsh.b.vec(WindowWireSchema)
21712
+ });
21713
+ var StateSnapshotSchema = import_zorsh.b.struct({
21714
+ deviceId: import_zorsh.b.string(),
21715
+ session: import_zorsh.b.option(SessionWireSchema)
21716
+ });
21717
+ var StateSnapshotDiffSchema = import_zorsh.b.struct({
21718
+ deviceId: import_zorsh.b.string(),
21719
+ baseRevision: import_zorsh.b.u32(),
21720
+ revision: import_zorsh.b.u32(),
21721
+ diffFormat: import_zorsh.b.u8(),
21722
+ diffBytes: import_zorsh.b.bytes()
21723
+ });
21724
+ var WindowAddEventSchema = import_zorsh.b.struct({
21725
+ windowId: import_zorsh.b.string()
21726
+ });
21727
+ var WindowCloseEventSchema = import_zorsh.b.struct({
21728
+ windowId: import_zorsh.b.string()
21729
+ });
21730
+ var WindowRenamedEventSchema = import_zorsh.b.struct({
21731
+ windowId: import_zorsh.b.string(),
21732
+ name: import_zorsh.b.string()
21733
+ });
21734
+ var WindowActiveEventSchema = import_zorsh.b.struct({
21735
+ windowId: import_zorsh.b.string()
21736
+ });
21737
+ var PaneAddEventSchema = import_zorsh.b.struct({
21738
+ paneId: import_zorsh.b.string(),
21739
+ windowId: import_zorsh.b.string()
21740
+ });
21741
+ var PaneCloseEventSchema = import_zorsh.b.struct({
21742
+ paneId: import_zorsh.b.string()
21743
+ });
21744
+ var PaneActiveEventSchema = import_zorsh.b.struct({
21745
+ windowId: import_zorsh.b.string(),
21746
+ paneId: import_zorsh.b.string()
21747
+ });
21748
+ var LayoutChangeEventSchema = import_zorsh.b.struct({
21749
+ windowId: import_zorsh.b.string(),
21750
+ layout: import_zorsh.b.string()
21751
+ });
21752
+ var BellEventSchema = import_zorsh.b.struct({
21753
+ windowId: OptionStringSchema,
21754
+ paneId: OptionStringSchema,
21755
+ windowIndex: OptionU16Schema,
21756
+ paneIndex: OptionU16Schema,
21757
+ paneUrl: OptionStringSchema
21758
+ });
21759
+ // ../shared/src/ws-borsh/codec.ts
21760
+ var MAGIC = new Uint8Array([84, 88]);
21761
+ var CURRENT_VERSION = 1;
21762
+ var DEFAULT_MAX_FRAME_BYTES = 1048576;
21763
+ var FLAG_ACK_REQUIRED = 1 << 0;
21764
+ var FLAG_IS_ACK = 1 << 1;
21765
+ var FLAG_IS_ERROR = 1 << 2;
21766
+ var FLAG_IS_CHUNK = 1 << 3;
21767
+ var FLAG_IS_COMPRESSED = 1 << 4;
21768
+ function encodeEnvelope(kind, payload, seq, flags = 0, version = CURRENT_VERSION) {
21769
+ const envelope = {
21770
+ magic: MAGIC,
21771
+ version,
21772
+ kind,
21773
+ flags,
21774
+ seq,
21775
+ payload
21776
+ };
21777
+ return EnvelopeSchema.serialize(envelope);
21778
+ }
21779
+ function encodePayload(schema, data) {
21780
+ return schema.serialize(data);
21781
+ }
21782
+ function decodeEnvelope(data) {
21783
+ if (data.length < 12) {
21784
+ throw new WsBorshError(ERROR_INVALID_FRAME, false, "Envelope too small");
21785
+ }
21786
+ if (data[0] !== MAGIC[0] || data[1] !== MAGIC[1]) {
21787
+ throw new WsBorshError(ERROR_INVALID_FRAME, false, "Invalid magic bytes");
21788
+ }
21789
+ try {
21790
+ return EnvelopeSchema.deserialize(data);
21791
+ } catch (err) {
21792
+ throw new WsBorshError(ERROR_INVALID_FRAME, false, err instanceof Error ? err.message : "Failed to decode envelope");
21793
+ }
21794
+ }
21795
+ function decodePayload(schema, data) {
21796
+ try {
21797
+ return schema.deserialize(data);
21798
+ } catch (err) {
21799
+ throw new WsBorshError(ERROR_PAYLOAD_DECODE_FAILED, false, err instanceof Error ? err.message : "Failed to decode payload");
21800
+ }
21801
+ }
21802
+ function decodeEnvelopeAndPayload(envelopeData, payloadSchema) {
21803
+ const envelope = decodeEnvelope(envelopeData);
21804
+ const payload = decodePayload(payloadSchema, envelope.payload);
21805
+ return {
21806
+ version: envelope.version,
21807
+ kind: envelope.kind,
21808
+ flags: envelope.flags,
21809
+ seq: envelope.seq,
21810
+ payload
21811
+ };
21812
+ }
21813
+ function encodeChunk(chunk, seq) {
21814
+ const payloadBytes = ChunkSchema.serialize(chunk);
21815
+ return encodeEnvelope(1281, payloadBytes, seq);
21816
+ }
21817
+ function decodeChunk(data) {
21818
+ return ChunkSchema.deserialize(data);
21819
+ }
21820
+ function hasFlag(flags, flag) {
21821
+ return (flags & flag) !== 0;
21822
+ }
21823
+ function setFlag(flags, flag, value) {
21824
+ return value ? flags | flag : flags & ~flag;
21825
+ }
21826
+ function checkMagic(data) {
21827
+ return data.length >= 2 && data[0] === MAGIC[0] && data[1] === MAGIC[1];
21828
+ }
21829
+ function createSeqGenerator() {
21830
+ let seq = 1;
21831
+ return () => seq++;
21832
+ }
21833
+ // ../shared/src/ws-borsh/chunk.ts
21834
+ var CHUNK_TIMEOUT_MS = 5000;
21835
+ var MAX_CHUNK_STREAMS = 100;
21836
+ var MAX_CHUNKS_PER_MESSAGE = 1000;
21837
+
21838
+ class ChunkReassembler {
21839
+ streams = new Map;
21840
+ lastCleanup = Date.now();
21841
+ addChunk(chunk) {
21842
+ this.cleanup();
21843
+ if (chunk.totalChunks > MAX_CHUNKS_PER_MESSAGE) {
21844
+ throw new WsBorshError(ERROR_INVALID_FRAME, false, `Too many chunks: ${chunk.totalChunks} > ${MAX_CHUNKS_PER_MESSAGE}`);
21845
+ }
21846
+ if (chunk.chunkIndex >= chunk.totalChunks) {
21847
+ throw new WsBorshError(ERROR_INVALID_FRAME, false, `Chunk index out of bounds: ${chunk.chunkIndex} >= ${chunk.totalChunks}`);
21848
+ }
21849
+ let stream = this.streams.get(chunk.chunkStreamId);
21850
+ if (!stream) {
21851
+ if (this.streams.size >= MAX_CHUNK_STREAMS) {
21852
+ this.cleanup(true);
21853
+ if (this.streams.size >= MAX_CHUNK_STREAMS) {
21854
+ throw new WsBorshError(ERROR_INVALID_FRAME, false, "Too many concurrent chunk streams");
21855
+ }
21856
+ }
21857
+ stream = {
21858
+ chunks: new Map,
21859
+ totalChunks: chunk.totalChunks,
21860
+ createdAt: Date.now(),
21861
+ originalKind: chunk.originalKind,
21862
+ originalSeq: chunk.originalSeq
21863
+ };
21864
+ this.streams.set(chunk.chunkStreamId, stream);
21865
+ }
21866
+ if (stream.totalChunks !== chunk.totalChunks) {
21867
+ this.streams.delete(chunk.chunkStreamId);
21868
+ throw new WsBorshError(ERROR_INVALID_FRAME, false, "Chunk total count mismatch");
21869
+ }
21870
+ if (stream.chunks.has(chunk.chunkIndex)) {
21871
+ throw new WsBorshError(ERROR_INVALID_FRAME, false, `Duplicate chunk index: ${chunk.chunkIndex}`);
21872
+ }
21873
+ stream.chunks.set(chunk.chunkIndex, chunk);
21874
+ if (stream.chunks.size === stream.totalChunks) {
21875
+ return this.reassemble(chunk.chunkStreamId, stream);
21876
+ }
21877
+ return null;
21878
+ }
21879
+ reassemble(streamId, stream) {
21880
+ const chunks = [];
21881
+ let totalLength = 0;
21882
+ for (let i = 0;i < stream.totalChunks; i++) {
21883
+ const chunk = stream.chunks.get(i);
21884
+ if (!chunk) {
21885
+ this.streams.delete(streamId);
21886
+ throw new WsBorshError(ERROR_INVALID_FRAME, false, `Missing chunk index: ${i}`);
21887
+ }
21888
+ chunks.push(chunk.data);
21889
+ totalLength += chunk.data.length;
21890
+ }
21891
+ const payload = new Uint8Array(totalLength);
21892
+ let offset = 0;
21893
+ for (const chunk of chunks) {
21894
+ payload.set(chunk, offset);
21895
+ offset += chunk.length;
21896
+ }
21897
+ this.streams.delete(streamId);
21898
+ return {
21899
+ kind: stream.originalKind,
21900
+ seq: stream.originalSeq,
21901
+ payload
21902
+ };
21903
+ }
21904
+ cleanup(force = false) {
21905
+ const now = Date.now();
21906
+ if (!force && now - this.lastCleanup < 5000) {
21907
+ return;
21908
+ }
21909
+ this.lastCleanup = now;
21910
+ const cutoff = now - CHUNK_TIMEOUT_MS;
21911
+ for (const [streamId, stream] of this.streams) {
21912
+ if (stream.createdAt < cutoff) {
21913
+ this.streams.delete(streamId);
21914
+ }
21915
+ }
21916
+ }
21917
+ getActiveStreamCount() {
21918
+ return this.streams.size;
21919
+ }
21920
+ clear() {
21921
+ this.streams.clear();
21922
+ }
21923
+ }
21924
+ function splitPayloadIntoChunks(payload, kind, seq, options) {
21925
+ const { maxFrameBytes, chunkStreamId } = options;
21926
+ const envelopeOverhead = 16;
21927
+ const chunkOverhead = 18;
21928
+ const maxUnchunkedPayloadBytes = maxFrameBytes - envelopeOverhead;
21929
+ if (maxUnchunkedPayloadBytes <= 0) {
21930
+ throw new WsBorshError(ERROR_FRAME_TOO_LARGE, false, `maxFrameBytes too small: ${maxFrameBytes}`);
21931
+ }
21932
+ if (payload.length <= maxUnchunkedPayloadBytes) {
21933
+ return { chunks: [], totalChunks: 0 };
21934
+ }
21935
+ const maxChunkDataSize = maxFrameBytes - envelopeOverhead - chunkOverhead;
21936
+ if (maxChunkDataSize <= 0) {
21937
+ throw new WsBorshError(ERROR_FRAME_TOO_LARGE, false, `maxFrameBytes too small for chunking: ${maxFrameBytes}`);
21938
+ }
21939
+ const totalChunks = Math.ceil(payload.length / maxChunkDataSize);
21940
+ if (totalChunks > MAX_CHUNKS_PER_MESSAGE) {
21941
+ throw new WsBorshError(ERROR_FRAME_TOO_LARGE, false, `Too many chunks: ${totalChunks}`);
21942
+ }
21943
+ const chunks = [];
21944
+ for (let i = 0;i < totalChunks; i++) {
21945
+ const start = i * maxChunkDataSize;
21946
+ const end = Math.min(start + maxChunkDataSize, payload.length);
21947
+ chunks.push({
21948
+ chunkStreamId,
21949
+ originalKind: kind,
21950
+ originalSeq: seq,
21951
+ totalChunks,
21952
+ chunkIndex: i,
21953
+ data: payload.slice(start, end)
21954
+ });
21955
+ }
21956
+ return {
21957
+ chunks,
21958
+ totalChunks
21959
+ };
21960
+ }
21961
+ var nextChunkStreamId = 1;
21962
+ function generateChunkStreamId() {
21963
+ const id = nextChunkStreamId;
21964
+ nextChunkStreamId = nextChunkStreamId % 4294967295 + 1;
21965
+ return id;
21966
+ }
21967
+ function resetChunkStreamId() {
21968
+ nextChunkStreamId = 1;
21969
+ }
21970
+ // ../shared/src/ws-borsh/convert.ts
21971
+ function encodeDeviceEventPayload(payload) {
21972
+ const eventTypeMap = {
21973
+ "tmux-missing": 1,
21974
+ disconnected: 2,
21975
+ error: 3,
21976
+ reconnected: 4
21977
+ };
21978
+ const wireData = {
21979
+ deviceId: payload.deviceId,
21980
+ eventType: eventTypeMap[payload.type],
21981
+ errorType: payload.errorType ?? null,
21982
+ message: payload.message ?? null,
21983
+ rawMessage: payload.rawMessage ?? null
21984
+ };
21985
+ return DeviceEventSchema.serialize(wireData);
21986
+ }
21987
+ function encodeTmuxEventPayload(payload) {
21988
+ const eventTypeMap = {
21989
+ "window-add": 1,
21990
+ "window-close": 2,
21991
+ "window-renamed": 3,
21992
+ "window-active": 4,
21993
+ "pane-add": 5,
21994
+ "pane-close": 6,
21995
+ "pane-active": 7,
21996
+ "layout-change": 8,
21997
+ bell: 9,
21998
+ output: 10
21999
+ };
22000
+ const eventData = encodeEventData(payload.type, payload.data);
22001
+ const wireData = {
22002
+ deviceId: payload.deviceId,
22003
+ eventType: eventTypeMap[payload.type],
22004
+ eventData
22005
+ };
22006
+ return TmuxEventSchema.serialize(wireData);
22007
+ }
22008
+ function encodeEventData(type, data) {
22009
+ switch (type) {
22010
+ case "window-add": {
22011
+ const d = data;
22012
+ return WindowAddEventSchema.serialize({ windowId: d.windowId });
22013
+ }
22014
+ case "window-close": {
22015
+ const d = data;
22016
+ return WindowCloseEventSchema.serialize({ windowId: d.windowId });
22017
+ }
22018
+ case "window-renamed": {
22019
+ const d = data;
22020
+ return WindowRenamedEventSchema.serialize({
22021
+ windowId: d.windowId,
22022
+ name: d.name
22023
+ });
22024
+ }
22025
+ case "window-active": {
22026
+ const d = data;
22027
+ return WindowActiveEventSchema.serialize({ windowId: d.windowId });
22028
+ }
22029
+ case "pane-add": {
22030
+ const d = data;
22031
+ return PaneAddEventSchema.serialize({
22032
+ paneId: d.paneId,
22033
+ windowId: d.windowId
22034
+ });
22035
+ }
22036
+ case "pane-close": {
22037
+ const d = data;
22038
+ return PaneCloseEventSchema.serialize({ paneId: d.paneId });
22039
+ }
22040
+ case "pane-active": {
22041
+ const d = data;
22042
+ return PaneActiveEventSchema.serialize({
22043
+ windowId: d.windowId,
22044
+ paneId: d.paneId
22045
+ });
22046
+ }
22047
+ case "layout-change": {
22048
+ const d = data;
22049
+ return LayoutChangeEventSchema.serialize({
22050
+ windowId: d.windowId,
22051
+ layout: d.layout
22052
+ });
22053
+ }
22054
+ case "bell": {
22055
+ const d = data;
22056
+ return BellEventSchema.serialize({
22057
+ windowId: d.windowId ?? null,
22058
+ paneId: d.paneId ?? null,
22059
+ windowIndex: d.windowIndex ?? null,
22060
+ paneIndex: d.paneIndex ?? null,
22061
+ paneUrl: d.paneUrl ?? null
22062
+ });
22063
+ }
22064
+ case "output":
22065
+ return new Uint8Array;
22066
+ default:
22067
+ return new Uint8Array;
22068
+ }
22069
+ }
22070
+ function encodeStateSnapshot(payload) {
22071
+ const wireData = {
22072
+ deviceId: payload.deviceId,
22073
+ session: payload.session ? encodeSessionWire(payload.session) : null
22074
+ };
22075
+ return StateSnapshotSchema.serialize(wireData);
22076
+ }
22077
+ function encodeSessionWire(session) {
22078
+ return {
22079
+ id: session.id,
22080
+ name: session.name,
22081
+ windows: session.windows.map(encodeWindowWire)
22082
+ };
22083
+ }
22084
+ function encodeWindowWire(window2) {
22085
+ return {
22086
+ id: window2.id,
22087
+ name: window2.name,
22088
+ index: window2.index,
22089
+ active: window2.active,
22090
+ panes: window2.panes.map(encodePaneWire)
22091
+ };
22092
+ }
22093
+ function encodePaneWire(pane) {
22094
+ return {
22095
+ id: pane.id,
22096
+ windowId: pane.windowId,
22097
+ index: pane.index,
22098
+ title: pane.title ?? null,
22099
+ active: pane.active,
22100
+ width: pane.width,
22101
+ height: pane.height
22102
+ };
22103
+ }
22104
+ function decodeDeviceEventPayload(data) {
22105
+ const wire = DeviceEventSchema.deserialize(data);
22106
+ const eventTypeMap = {
22107
+ 1: "tmux-missing",
22108
+ 2: "disconnected",
22109
+ 3: "error",
22110
+ 4: "reconnected"
22111
+ };
22112
+ return {
22113
+ deviceId: wire.deviceId,
22114
+ type: eventTypeMap[wire.eventType] ?? "error",
22115
+ errorType: wire.errorType ?? undefined,
22116
+ message: wire.message ?? undefined,
22117
+ rawMessage: wire.rawMessage ?? undefined
22118
+ };
22119
+ }
22120
+ function decodeTmuxEventPayload(data) {
22121
+ const wire = TmuxEventSchema.deserialize(data);
22122
+ const eventTypeMap = {
22123
+ 1: "window-add",
22124
+ 2: "window-close",
22125
+ 3: "window-renamed",
22126
+ 4: "window-active",
22127
+ 5: "pane-add",
22128
+ 6: "pane-close",
22129
+ 7: "pane-active",
22130
+ 8: "layout-change",
22131
+ 9: "bell",
22132
+ 10: "output"
22133
+ };
22134
+ const type = eventTypeMap[wire.eventType] ?? "output";
22135
+ return {
22136
+ deviceId: wire.deviceId,
22137
+ type,
22138
+ data: decodeEventData(type, wire.eventData)
22139
+ };
22140
+ }
22141
+ function decodeEventData(type, data) {
22142
+ if (data.length === 0)
22143
+ return {};
22144
+ try {
22145
+ switch (type) {
22146
+ case "window-add":
22147
+ return WindowAddEventSchema.deserialize(data);
22148
+ case "window-close":
22149
+ return WindowCloseEventSchema.deserialize(data);
22150
+ case "window-renamed":
22151
+ return WindowRenamedEventSchema.deserialize(data);
22152
+ case "window-active":
22153
+ return WindowActiveEventSchema.deserialize(data);
22154
+ case "pane-add":
22155
+ return PaneAddEventSchema.deserialize(data);
22156
+ case "pane-close":
22157
+ return PaneCloseEventSchema.deserialize(data);
22158
+ case "pane-active":
22159
+ return PaneActiveEventSchema.deserialize(data);
22160
+ case "layout-change":
22161
+ return LayoutChangeEventSchema.deserialize(data);
22162
+ case "bell": {
22163
+ const bell = BellEventSchema.deserialize(data);
22164
+ return {
22165
+ windowId: bell.windowId ?? undefined,
22166
+ paneId: bell.paneId ?? undefined,
22167
+ windowIndex: bell.windowIndex ?? undefined,
22168
+ paneIndex: bell.paneIndex ?? undefined,
22169
+ paneUrl: bell.paneUrl ?? undefined
22170
+ };
22171
+ }
22172
+ default:
22173
+ return {};
22174
+ }
22175
+ } catch {
22176
+ return {};
22177
+ }
22178
+ }
22179
+ function decodeStateSnapshot(data) {
22180
+ const wire = StateSnapshotSchema.deserialize(data);
22181
+ return {
22182
+ deviceId: wire.deviceId,
22183
+ session: wire.session ? decodeSessionWire(wire.session) : null
22184
+ };
22185
+ }
22186
+ function decodeSessionWire(wire) {
22187
+ return {
22188
+ id: wire.id,
22189
+ name: wire.name,
22190
+ windows: wire.windows.map(decodeWindowWire)
22191
+ };
22192
+ }
22193
+ function decodeWindowWire(wire) {
22194
+ return {
22195
+ id: wire.id,
22196
+ name: wire.name,
22197
+ index: wire.index,
22198
+ active: wire.active,
22199
+ panes: wire.panes.map(decodePaneWire)
22200
+ };
22201
+ }
22202
+ function decodePaneWire(wire) {
22203
+ return {
22204
+ id: wire.id,
22205
+ windowId: wire.windowId,
22206
+ index: wire.index,
22207
+ title: wire.title ?? undefined,
22208
+ active: wire.active,
22209
+ width: wire.width,
22210
+ height: wire.height
22211
+ };
22212
+ }
20520
22213
  // ../../node_modules/.bun/uuid@11.1.0/node_modules/uuid/dist/esm/stringify.js
20521
22214
  var byteToHex = [];
20522
22215
  for (let i = 0;i < 256; ++i) {
@@ -20598,9 +22291,9 @@ function getEnv(key, defaultValue) {
20598
22291
  var config = {
20599
22292
  masterKey: process.env.TMEX_MASTER_KEY,
20600
22293
  port: Number.parseInt(getEnv("GATEWAY_PORT", "9663"), 10),
20601
- baseUrl: getEnv("TMEX_BASE_URL", "http://localhost:9663"),
22294
+ baseUrl: getEnv("TMEX_BASE_URL", "http://127.0.0.1:8085"),
20602
22295
  siteNameDefault: getEnv("TMEX_SITE_NAME", "tmex"),
20603
- databaseUrl: getEnv("DATABASE_URL", "/data/tmex.db"),
22296
+ databaseUrl: getEnv("DATABASE_URL", "./tmex.db"),
20604
22297
  bellThrottleSecondsDefault: Number.parseInt(getEnv("TMEX_BELL_THROTTLE_SECONDS", "6"), 10),
20605
22298
  sshReconnectMaxRetriesDefault: Number.parseInt(getEnv("TMEX_SSH_RECONNECT_MAX_RETRIES", "2"), 10),
20606
22299
  sshReconnectDelaySecondsDefault: Number.parseInt(getEnv("TMEX_SSH_RECONNECT_DELAY_SECONDS", "10"), 10),
@@ -21618,10 +23311,10 @@ function getTableColumns(table) {
21618
23311
  function getTableLikeName(table) {
21619
23312
  return is(table, Subquery) ? table._.alias : is(table, View) ? table[ViewBaseConfig].name : is(table, SQL) ? undefined : table[Table.Symbol.IsAlias] ? table[Table.Symbol.Name] : table[Table.Symbol.BaseName];
21620
23313
  }
21621
- function getColumnNameAndConfig(a, b) {
23314
+ function getColumnNameAndConfig(a, b3) {
21622
23315
  return {
21623
23316
  name: typeof a === "string" && a.length > 0 ? a : "",
21624
- config: typeof a === "object" ? a : b
23317
+ config: typeof a === "object" ? a : b3
21625
23318
  };
21626
23319
  }
21627
23320
  function isConfig(data) {
@@ -23881,7 +25574,7 @@ var usesLocize = (inst) => {
23881
25574
  if (inst?.modules?.backend?.constructor?.name?.indexOf("Locize") > 0)
23882
25575
  return true;
23883
25576
  if (inst?.options?.backend?.backends) {
23884
- if (inst.options.backend.backends.some((b) => b?.name?.indexOf("Locize") > 0 || b?.constructor?.name?.indexOf("Locize") > 0))
25577
+ if (inst.options.backend.backends.some((b3) => b3?.name?.indexOf("Locize") > 0 || b3?.constructor?.name?.indexOf("Locize") > 0))
23885
25578
  return true;
23886
25579
  }
23887
25580
  return false;
@@ -24753,8 +26446,8 @@ class SQLiteBlobBuffer extends SQLiteColumn {
24753
26446
  return "blob";
24754
26447
  }
24755
26448
  }
24756
- function blob(a, b) {
24757
- const { name, config: config2 } = getColumnNameAndConfig(a, b);
26449
+ function blob(a, b3) {
26450
+ const { name, config: config2 } = getColumnNameAndConfig(a, b3);
24758
26451
  if (config2?.mode === "json") {
24759
26452
  return new SQLiteBlobJsonBuilder(name);
24760
26453
  }
@@ -24799,8 +26492,8 @@ class SQLiteCustomColumn extends SQLiteColumn {
24799
26492
  }
24800
26493
  }
24801
26494
  function customType(customTypeParams) {
24802
- return (a, b) => {
24803
- const { name, config: config2 } = getColumnNameAndConfig(a, b);
26495
+ return (a, b3) => {
26496
+ const { name, config: config2 } = getColumnNameAndConfig(a, b3);
24804
26497
  return new SQLiteCustomColumnBuilder(name, config2, customTypeParams);
24805
26498
  };
24806
26499
  }
@@ -24896,8 +26589,8 @@ class SQLiteBoolean extends SQLiteBaseInteger {
24896
26589
  return value ? 1 : 0;
24897
26590
  }
24898
26591
  }
24899
- function integer(a, b) {
24900
- const { name, config: config2 } = getColumnNameAndConfig(a, b);
26592
+ function integer(a, b3) {
26593
+ const { name, config: config2 } = getColumnNameAndConfig(a, b3);
24901
26594
  if (config2?.mode === "timestamp" || config2?.mode === "timestamp_ms") {
24902
26595
  return new SQLiteTimestampBuilder(name, config2.mode);
24903
26596
  }
@@ -24971,8 +26664,8 @@ class SQLiteNumericBigInt extends SQLiteColumn {
24971
26664
  return "numeric";
24972
26665
  }
24973
26666
  }
24974
- function numeric(a, b) {
24975
- const { name, config: config2 } = getColumnNameAndConfig(a, b);
26667
+ function numeric(a, b3) {
26668
+ const { name, config: config2 } = getColumnNameAndConfig(a, b3);
24976
26669
  const mode = config2?.mode;
24977
26670
  return mode === "number" ? new SQLiteNumericNumberBuilder(name) : mode === "bigint" ? new SQLiteNumericBigIntBuilder(name) : new SQLiteNumericBuilder(name);
24978
26671
  }
@@ -25045,8 +26738,8 @@ class SQLiteTextJson extends SQLiteColumn {
25045
26738
  return JSON.stringify(value);
25046
26739
  }
25047
26740
  }
25048
- function text(a, b = {}) {
25049
- const { name, config: config2 } = getColumnNameAndConfig(a, b);
26741
+ function text(a, b3 = {}) {
26742
+ const { name, config: config2 } = getColumnNameAndConfig(a, b3);
25050
26743
  if (config2.mode === "json") {
25051
26744
  return new SQLiteTextJsonBuilder(name);
25052
26745
  }
@@ -26696,7 +28389,7 @@ async function hashQuery(sql2, params) {
26696
28389
  const data = encoder.encode(dataToHash);
26697
28390
  const hashBuffer = await crypto.subtle.digest("SHA-256", data);
26698
28391
  const hashArray = [...new Uint8Array(hashBuffer)];
26699
- const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
28392
+ const hashHex = hashArray.map((b3) => b3.toString(16).padStart(2, "0")).join("");
26700
28393
  return hashHex;
26701
28394
  }
26702
28395
 
@@ -27026,8 +28719,8 @@ function drizzle(...params) {
27026
28719
  })(drizzle || (drizzle = {}));
27027
28720
 
27028
28721
  // ../../apps/gateway/src/db/schema.ts
27029
- var exports_schema = {};
27030
- __export(exports_schema, {
28722
+ var exports_schema2 = {};
28723
+ __export(exports_schema2, {
27031
28724
  webhookEndpoints: () => webhookEndpoints,
27032
28725
  telegramBots: () => telegramBots,
27033
28726
  telegramBotChats: () => telegramBotChats,
@@ -27121,7 +28814,7 @@ function ensureSqliteClient() {
27121
28814
  }
27122
28815
  function getDb() {
27123
28816
  if (!db) {
27124
- db = drizzle(ensureSqliteClient(), { schema: exports_schema });
28817
+ db = drizzle(ensureSqliteClient(), { schema: exports_schema2 });
27125
28818
  }
27126
28819
  return db;
27127
28820
  }
@@ -47940,7 +49633,7 @@ function formatSaveIndents(stringParts, ...strings) {
47940
49633
  }
47941
49634
 
47942
49635
  // ../../node_modules/.bun/gramio@0.4.12+cb432ad7c9c526f6/node_modules/gramio/dist/index.js
47943
- var import_debug2 = __toESM(require_src(), 1);
49636
+ var import_debug2 = __toESM(require_src2(), 1);
47944
49637
 
47945
49638
  // ../../node_modules/.bun/gramio@0.4.12+cb432ad7c9c526f6/node_modules/gramio/dist/utils-CJfJNxc_.js
47946
49639
  var exports_utils_CJfJNxc_ = {};
@@ -47954,7 +49647,7 @@ __export(exports_utils_CJfJNxc_, {
47954
49647
  I: () => IS_BUN,
47955
49648
  E: () => ErrorKind
47956
49649
  });
47957
- var import_debug = __toESM(require_src(), 1);
49650
+ var import_debug = __toESM(require_src2(), 1);
47958
49651
  var ErrorKind = Symbol("ErrorKind");
47959
49652
 
47960
49653
  class TelegramError extends Error {
@@ -49985,8 +51678,8 @@ function buildPaneUrl(event) {
49985
51678
  }
49986
51679
  const base = trimTrailingSlash(event.site.url);
49987
51680
  const deviceId = encodeURIComponent(event.device.id);
49988
- const windowId = event.tmux.windowId;
49989
- const paneId = event.tmux.paneId;
51681
+ const windowId = encodeURIComponent(event.tmux.windowId);
51682
+ const paneId = encodeURIComponent(event.tmux.paneId);
49990
51683
  return `${base}/devices/${deviceId}/windows/${windowId}/panes/${paneId}`;
49991
51684
  }
49992
51685
  function normalizeHttpUrl(input) {
@@ -50238,6 +51931,7 @@ class TmuxControlParser {
50238
51931
  onEvent;
50239
51932
  onTerminalOutput;
50240
51933
  onPaneTitle;
51934
+ onOutputBlockBegin;
50241
51935
  onOutputBlock;
50242
51936
  onNonControlOutput;
50243
51937
  onExit;
@@ -50253,6 +51947,7 @@ class TmuxControlParser {
50253
51947
  this.onEvent = options.onEvent;
50254
51948
  this.onTerminalOutput = options.onTerminalOutput;
50255
51949
  this.onPaneTitle = options.onPaneTitle;
51950
+ this.onOutputBlockBegin = options.onOutputBlockBegin;
50256
51951
  this.onOutputBlock = options.onOutputBlock;
50257
51952
  this.onNonControlOutput = options.onNonControlOutput;
50258
51953
  this.onExit = options.onExit;
@@ -50317,6 +52012,7 @@ class TmuxControlParser {
50317
52012
  this.inOutputBlock = true;
50318
52013
  this.outputBlockMeta = meta;
50319
52014
  this.outputBlockLines = [];
52015
+ this.onOutputBlockBegin?.(meta);
50320
52016
  }
50321
52017
  finishOutputBlock(line) {
50322
52018
  const meta = this.parseOutputBlockMeta(line);
@@ -50569,6 +52265,17 @@ class TmuxControlParser {
50569
52265
  this.onExit?.(args.trim() ? args : null);
50570
52266
  break;
50571
52267
  case "%bell":
52268
+ {
52269
+ const parts = this.parseArgs(args);
52270
+ const windowId = parts[0] ?? args;
52271
+ const paneId = parts[1];
52272
+ const data = {};
52273
+ if (windowId)
52274
+ data.windowId = windowId;
52275
+ if (paneId)
52276
+ data.paneId = paneId;
52277
+ this.onEvent({ type: "bell", data });
52278
+ }
50572
52279
  break;
50573
52280
  case "%pause":
50574
52281
  case "%resume":
@@ -50613,6 +52320,8 @@ class TmuxControlParser {
50613
52320
  }
50614
52321
 
50615
52322
  // ../../apps/gateway/src/tmux/connection.ts
52323
+ var BELL_DEDUP_WINDOW_MS = 200;
52324
+
50616
52325
  class TmuxConnection {
50617
52326
  deviceId;
50618
52327
  device = null;
@@ -50639,6 +52348,7 @@ class TmuxConnection {
50639
52348
  startupNonControlOutput = [];
50640
52349
  lastExitReason = null;
50641
52350
  pendingCommandKinds = [];
52351
+ commandKindsByNo = new Map;
50642
52352
  pendingCapturePaneRequests = [];
50643
52353
  pendingCapturePaneModeRequests = [];
50644
52354
  snapshotSession = null;
@@ -50647,6 +52357,8 @@ class TmuxConnection {
50647
52357
  snapshotPanesReady = false;
50648
52358
  historyCaptureStates = new Map;
50649
52359
  resizeSnapshotTimer = null;
52360
+ bellControlEventSeen = false;
52361
+ bellDedup = new Map;
50650
52362
  constructor(options) {
50651
52363
  this.deviceId = options.deviceId;
50652
52364
  this.onEvent = options.onEvent;
@@ -50663,6 +52375,7 @@ class TmuxConnection {
50663
52375
  onEvent: (event) => this.handleTmuxEvent(event),
50664
52376
  onTerminalOutput: (paneId, data) => this.emitTerminalOutput(paneId, data),
50665
52377
  onPaneTitle: (paneId, title) => this.handlePaneTitleUpdate(paneId, title),
52378
+ onOutputBlockBegin: (meta) => this.handleOutputBlockBegin(meta),
50666
52379
  onOutputBlock: (block) => this.handleOutputBlock(block),
50667
52380
  onNonControlOutput: (line) => this.handleNonControlOutput(line),
50668
52381
  onReady: () => this.markReady(),
@@ -50969,14 +52682,58 @@ ssh stderr: ${stderrText}`) : err2;
50969
52682
  conn.connect(authConfig);
50970
52683
  });
50971
52684
  }
52685
+ shouldPassBellDedup(key) {
52686
+ const now = Date.now();
52687
+ const previous = this.bellDedup.get(key) ?? 0;
52688
+ if (now - previous < BELL_DEDUP_WINDOW_MS) {
52689
+ return false;
52690
+ }
52691
+ this.bellDedup.set(key, now);
52692
+ return true;
52693
+ }
50972
52694
  handleTmuxEvent(event) {
52695
+ if (event.type === "pane-active") {
52696
+ const data = event.data ?? {};
52697
+ const windowId = typeof data.windowId === "string" && data.windowId ? data.windowId : null;
52698
+ const paneId = typeof data.paneId === "string" && data.paneId ? data.paneId : null;
52699
+ if (windowId)
52700
+ this.activeWindowId = windowId;
52701
+ if (paneId)
52702
+ this.activePaneId = paneId;
52703
+ }
52704
+ if (event.type === "bell") {
52705
+ this.bellControlEventSeen = true;
52706
+ const data = event.data ?? {};
52707
+ const resolvedPaneId = (typeof data.paneId === "string" && data.paneId ? data.paneId : null) ?? this.activePaneId ?? undefined;
52708
+ const windowId = typeof data.windowId === "string" && data.windowId ? data.windowId : undefined;
52709
+ const key = resolvedPaneId ?? windowId ?? "-";
52710
+ if (!this.shouldPassBellDedup(key)) {
52711
+ return;
52712
+ }
52713
+ if (resolvedPaneId && !data.paneId) {
52714
+ this.onEvent({
52715
+ ...event,
52716
+ data: {
52717
+ ...data,
52718
+ paneId: resolvedPaneId
52719
+ }
52720
+ });
52721
+ return;
52722
+ }
52723
+ }
50973
52724
  this.onEvent(event);
50974
52725
  }
50975
52726
  emitBellEventIfNeeded(paneId, data) {
52727
+ if (this.bellControlEventSeen) {
52728
+ return;
52729
+ }
50976
52730
  for (const byte of data) {
50977
52731
  if (byte !== 7) {
50978
52732
  continue;
50979
52733
  }
52734
+ if (!this.shouldPassBellDedup(paneId)) {
52735
+ break;
52736
+ }
50980
52737
  this.onEvent({
50981
52738
  type: "bell",
50982
52739
  data: {
@@ -51169,10 +52926,15 @@ ssh stderr: ${stderrText}`) : err2;
51169
52926
  this.sendCommand(`list-panes -F "#{pane_id} #{window_id} #{pane_index} #{pane_title} #{pane_active} #{pane_width} #{pane_height}"
51170
52927
  `, "snapshot-panes");
51171
52928
  }
52929
+ handleOutputBlockBegin(meta) {
52930
+ const kind = this.pendingCommandKinds.shift() ?? "noop";
52931
+ this.commandKindsByNo.set(meta.commandNo, kind);
52932
+ }
51172
52933
  handleOutputBlock(block) {
51173
52934
  this.markReady();
51174
- const kind = this.pendingCommandKinds.shift();
51175
- console.log("[tmux] handleOutputBlock kind:", kind, "lines:", block.lines.length);
52935
+ const kind = this.commandKindsByNo.get(block.commandNo);
52936
+ this.commandKindsByNo.delete(block.commandNo);
52937
+ console.log("[tmux] handleOutputBlock commandNo:", block.commandNo, "kind:", kind, "lines:", block.lines.length);
51176
52938
  const resolvedKind = kind ?? "noop";
51177
52939
  if (block.isError) {
51178
52940
  const message = block.lines.join(`
@@ -51292,7 +53054,7 @@ ssh stderr: ${stderrText}`) : err2;
51292
53054
  this.pendingPaneTitles.delete(paneId);
51293
53055
  }
51294
53056
  for (const win of this.snapshotWindows.values()) {
51295
- win.panes.sort((a, b) => a.index - b.index);
53057
+ win.panes.sort((a, b3) => a.index - b3.index);
51296
53058
  }
51297
53059
  this.snapshotPanesReady = true;
51298
53060
  }
@@ -51303,7 +53065,7 @@ ssh stderr: ${stderrText}`) : err2;
51303
53065
  return;
51304
53066
  if (!this.snapshotPanesReady)
51305
53067
  return;
51306
- const windows = Array.from(this.snapshotWindows.values()).sort((a, b) => a.index - b.index);
53068
+ const windows = Array.from(this.snapshotWindows.values()).sort((a, b3) => a.index - b3.index);
51307
53069
  const session = {
51308
53070
  id: this.snapshotSession.id,
51309
53071
  name: this.snapshotSession.name,
@@ -51413,6 +53175,7 @@ ssh stderr: ${stderrText}`) : err2;
51413
53175
  this.connected = false;
51414
53176
  this.parser.flush();
51415
53177
  this.pendingCommandKinds = [];
53178
+ this.commandKindsByNo.clear();
51416
53179
  this.pendingCapturePaneRequests = [];
51417
53180
  this.pendingCapturePaneModeRequests = [];
51418
53181
  for (const state of this.historyCaptureStates.values()) {
@@ -51428,6 +53191,8 @@ ssh stderr: ${stderrText}`) : err2;
51428
53191
  this.lastExitReason = null;
51429
53192
  this.activePaneId = null;
51430
53193
  this.activeWindowId = null;
53194
+ this.bellControlEventSeen = false;
53195
+ this.bellDedup.clear();
51431
53196
  if (this.resizeSnapshotTimer) {
51432
53197
  clearTimeout(this.resizeSnapshotTimer);
51433
53198
  this.resizeSnapshotTimer = null;
@@ -52319,6 +54084,544 @@ function classifySshError(error) {
52319
54084
  };
52320
54085
  }
52321
54086
 
54087
+ // ../../apps/gateway/src/ws/borsh/codec-borsh.ts
54088
+ function createBorshClientState() {
54089
+ return {
54090
+ seqGen: exports_ws_borsh.createSeqGenerator(),
54091
+ negotiated: false,
54092
+ maxFrameBytes: exports_ws_borsh.DEFAULT_MAX_FRAME_BYTES,
54093
+ chunkReassembler: new exports_ws_borsh.ChunkReassembler,
54094
+ selectedPanes: {}
54095
+ };
54096
+ }
54097
+ function encodeTermOutput(params, seq) {
54098
+ const payload = exports_ws_borsh.encodePayload(exports_ws_borsh.schema.TermOutputSchema, params);
54099
+ return exports_ws_borsh.encodeEnvelope(exports_ws_borsh.KIND_TERM_OUTPUT, payload, seq);
54100
+ }
54101
+ function encodeTermHistory(params, seqGen, maxFrameBytes) {
54102
+ const payload = exports_ws_borsh.encodePayload(exports_ws_borsh.schema.TermHistorySchema, params);
54103
+ return encodeWithChunking(exports_ws_borsh.KIND_TERM_HISTORY, payload, seqGen, maxFrameBytes);
54104
+ }
54105
+ function encodeSwitchAck(params, seq) {
54106
+ const payload = exports_ws_borsh.encodePayload(exports_ws_borsh.schema.SwitchAckSchema, params);
54107
+ return exports_ws_borsh.encodeEnvelope(exports_ws_borsh.KIND_SWITCH_ACK, payload, seq);
54108
+ }
54109
+ function encodeLiveResume(params, seq) {
54110
+ const payload = exports_ws_borsh.encodePayload(exports_ws_borsh.schema.LiveResumeSchema, params);
54111
+ return exports_ws_borsh.encodeEnvelope(exports_ws_borsh.KIND_LIVE_RESUME, payload, seq);
54112
+ }
54113
+ function encodeWithChunking(kind, payload, seqGen, maxFrameBytes) {
54114
+ const messages = [];
54115
+ const originalSeq = seqGen();
54116
+ const chunkResult = exports_ws_borsh.splitPayloadIntoChunks(payload, kind, originalSeq, {
54117
+ maxFrameBytes,
54118
+ chunkStreamId: exports_ws_borsh.generateChunkStreamId()
54119
+ });
54120
+ if (chunkResult.totalChunks === 0) {
54121
+ messages.push(exports_ws_borsh.encodeEnvelope(kind, payload, originalSeq));
54122
+ } else {
54123
+ for (const chunk2 of chunkResult.chunks) {
54124
+ messages.push(exports_ws_borsh.encodeChunk(chunk2, seqGen()));
54125
+ }
54126
+ }
54127
+ return messages;
54128
+ }
54129
+ function sendToClient(ws, data) {
54130
+ if (Array.isArray(data)) {
54131
+ for (const chunk2 of data) {
54132
+ ws.send(chunk2);
54133
+ }
54134
+ } else {
54135
+ ws.send(data);
54136
+ }
54137
+ }
54138
+
54139
+ // ../../apps/gateway/src/ws/borsh/session-state.ts
54140
+ class SessionStateStore {
54141
+ states = new Map;
54142
+ create(ws) {
54143
+ const now = Date.now();
54144
+ const state = {
54145
+ wsConnection: {
54146
+ state: "IDLE",
54147
+ connectedAt: null,
54148
+ lastActivityAt: now,
54149
+ seq: 0
54150
+ },
54151
+ deviceConnections: new Map,
54152
+ selectTransactions: new Map,
54153
+ outputGates: new Map,
54154
+ bellThrottles: new Map
54155
+ };
54156
+ this.states.set(ws, state);
54157
+ return state;
54158
+ }
54159
+ get(ws) {
54160
+ return this.states.get(ws);
54161
+ }
54162
+ delete(ws) {
54163
+ this.states.delete(ws);
54164
+ }
54165
+ transitionWsState(ws, newState) {
54166
+ const state = this.states.get(ws);
54167
+ if (!state)
54168
+ return false;
54169
+ const oldState = state.wsConnection.state;
54170
+ const validTransitions = {
54171
+ IDLE: ["WS_CONNECTING", "CLOSED"],
54172
+ WS_CONNECTING: ["HELLO_NEGOTIATING", "RECONNECT_BACKOFF", "CLOSED"],
54173
+ HELLO_NEGOTIATING: ["READY", "RECONNECT_BACKOFF", "CLOSED"],
54174
+ READY: ["RECONNECT_BACKOFF", "CLOSED"],
54175
+ RECONNECT_BACKOFF: ["WS_CONNECTING", "CLOSED"],
54176
+ CLOSED: []
54177
+ };
54178
+ if (!validTransitions[oldState].includes(newState)) {
54179
+ console.warn(`[session-state] Invalid WS state transition: ${oldState} -> ${newState}`);
54180
+ return false;
54181
+ }
54182
+ state.wsConnection.state = newState;
54183
+ if (newState === "READY") {
54184
+ state.wsConnection.connectedAt = Date.now();
54185
+ }
54186
+ return true;
54187
+ }
54188
+ updateLastActivity(ws) {
54189
+ const state = this.states.get(ws);
54190
+ if (state) {
54191
+ state.wsConnection.lastActivityAt = Date.now();
54192
+ }
54193
+ }
54194
+ incrementSeq(ws) {
54195
+ const state = this.states.get(ws);
54196
+ if (!state)
54197
+ return 0;
54198
+ state.wsConnection.seq += 1;
54199
+ return state.wsConnection.seq;
54200
+ }
54201
+ getOrCreateDeviceConnection(ws, deviceId) {
54202
+ const state = this.states.get(ws);
54203
+ if (!state)
54204
+ return;
54205
+ let ctx = state.deviceConnections.get(deviceId);
54206
+ if (!ctx) {
54207
+ ctx = {
54208
+ state: "DETACHED",
54209
+ deviceId,
54210
+ connectedAt: null,
54211
+ lastError: null,
54212
+ reconnectAttempts: 0
54213
+ };
54214
+ state.deviceConnections.set(deviceId, ctx);
54215
+ }
54216
+ return ctx;
54217
+ }
54218
+ transitionDeviceState(ws, deviceId, newState) {
54219
+ const ctx = this.getOrCreateDeviceConnection(ws, deviceId);
54220
+ if (!ctx)
54221
+ return false;
54222
+ const oldState = ctx.state;
54223
+ const validTransitions = {
54224
+ DETACHED: ["CONNECTING"],
54225
+ CONNECTING: ["CONNECTED", "FAILED"],
54226
+ CONNECTED: ["DISCONNECTING", "RECONNECTING"],
54227
+ FAILED: ["CONNECTING"],
54228
+ DISCONNECTING: ["DETACHED"],
54229
+ RECONNECTING: ["CONNECTED", "FAILED"]
54230
+ };
54231
+ if (!validTransitions[oldState].includes(newState)) {
54232
+ console.warn(`[session-state] Invalid device state transition: ${oldState} -> ${newState} for ${deviceId}`);
54233
+ return false;
54234
+ }
54235
+ ctx.state = newState;
54236
+ if (newState === "CONNECTED") {
54237
+ ctx.connectedAt = Date.now();
54238
+ ctx.reconnectAttempts = 0;
54239
+ ctx.lastError = null;
54240
+ } else if (newState === "FAILED") {
54241
+ ctx.reconnectAttempts += 1;
54242
+ }
54243
+ return true;
54244
+ }
54245
+ getOrCreateSelectTransaction(ws, deviceId) {
54246
+ const state = this.states.get(ws);
54247
+ if (!state)
54248
+ return;
54249
+ let ctx = state.selectTransactions.get(deviceId);
54250
+ if (!ctx) {
54251
+ ctx = {
54252
+ state: "STABLE",
54253
+ deviceId,
54254
+ windowId: null,
54255
+ paneId: null,
54256
+ selectToken: null,
54257
+ startedAt: 0,
54258
+ ackedAt: null,
54259
+ historyAppliedAt: null,
54260
+ liveResumedAt: null
54261
+ };
54262
+ state.selectTransactions.set(deviceId, ctx);
54263
+ }
54264
+ return ctx;
54265
+ }
54266
+ startSelectTransaction(ws, deviceId, windowId, paneId, selectToken) {
54267
+ const ctx = this.getOrCreateSelectTransaction(ws, deviceId);
54268
+ if (!ctx)
54269
+ return false;
54270
+ ctx.state = "SELECTING";
54271
+ ctx.windowId = windowId;
54272
+ ctx.paneId = paneId;
54273
+ ctx.selectToken = selectToken;
54274
+ ctx.startedAt = Date.now();
54275
+ ctx.ackedAt = null;
54276
+ ctx.historyAppliedAt = null;
54277
+ ctx.liveResumedAt = null;
54278
+ this.startOutputBuffering(ws, deviceId);
54279
+ return true;
54280
+ }
54281
+ transitionSelectState(ws, deviceId, newState) {
54282
+ const ctx = this.getOrCreateSelectTransaction(ws, deviceId);
54283
+ if (!ctx)
54284
+ return false;
54285
+ const oldState = ctx.state;
54286
+ const validTransitions = {
54287
+ STABLE: ["SELECTING"],
54288
+ SELECTING: ["ACKED", "SELECT_FAILED"],
54289
+ ACKED: ["HISTORY_APPLIED", "LIVE", "SELECT_FAILED"],
54290
+ HISTORY_APPLIED: ["LIVE", "SELECT_FAILED"],
54291
+ LIVE: ["STABLE", "SELECTING"],
54292
+ SELECT_FAILED: ["STABLE", "SELECTING"]
54293
+ };
54294
+ if (!validTransitions[oldState].includes(newState)) {
54295
+ console.warn(`[session-state] Invalid select state transition: ${oldState} -> ${newState} for ${deviceId}`);
54296
+ return false;
54297
+ }
54298
+ ctx.state = newState;
54299
+ const now = Date.now();
54300
+ switch (newState) {
54301
+ case "ACKED":
54302
+ ctx.ackedAt = now;
54303
+ break;
54304
+ case "HISTORY_APPLIED":
54305
+ ctx.historyAppliedAt = now;
54306
+ break;
54307
+ case "LIVE":
54308
+ ctx.liveResumedAt = now;
54309
+ break;
54310
+ case "STABLE":
54311
+ ctx.selectToken = null;
54312
+ break;
54313
+ }
54314
+ return true;
54315
+ }
54316
+ getOrCreateOutputGate(ws, deviceId) {
54317
+ const state = this.states.get(ws);
54318
+ if (!state)
54319
+ return;
54320
+ let ctx = state.outputGates.get(deviceId);
54321
+ if (!ctx) {
54322
+ ctx = {
54323
+ state: "FLOWING",
54324
+ buffer: [],
54325
+ maxBufferSize: 1000
54326
+ };
54327
+ state.outputGates.set(deviceId, ctx);
54328
+ }
54329
+ return ctx;
54330
+ }
54331
+ startOutputBuffering(ws, deviceId) {
54332
+ const ctx = this.getOrCreateOutputGate(ws, deviceId);
54333
+ if (!ctx)
54334
+ return;
54335
+ ctx.state = "BUFFERING";
54336
+ ctx.buffer = [];
54337
+ }
54338
+ stopOutputBuffering(ws, deviceId) {
54339
+ const ctx = this.getOrCreateOutputGate(ws, deviceId);
54340
+ if (!ctx)
54341
+ return [];
54342
+ ctx.state = "FLOWING";
54343
+ const buffered = [...ctx.buffer];
54344
+ ctx.buffer = [];
54345
+ return buffered;
54346
+ }
54347
+ bufferOutput(ws, deviceId, data) {
54348
+ const ctx = this.getOrCreateOutputGate(ws, deviceId);
54349
+ if (!ctx || ctx.state !== "BUFFERING")
54350
+ return false;
54351
+ if (ctx.buffer.length >= ctx.maxBufferSize) {
54352
+ console.warn(`[session-state] Output buffer overflow for ${deviceId}`);
54353
+ ctx.buffer.shift();
54354
+ }
54355
+ ctx.buffer.push(data);
54356
+ return true;
54357
+ }
54358
+ isBuffering(ws, deviceId) {
54359
+ const ctx = this.getOrCreateOutputGate(ws, deviceId);
54360
+ return ctx?.state === "BUFFERING";
54361
+ }
54362
+ shouldAllowBell(ws, deviceId, paneId, throttleSeconds) {
54363
+ const state = this.states.get(ws);
54364
+ if (!state)
54365
+ return false;
54366
+ const key = `${deviceId}:${paneId}`;
54367
+ const now = Date.now();
54368
+ let ctx = state.bellThrottles.get(key);
54369
+ if (!ctx) {
54370
+ ctx = {
54371
+ lastBellAt: 0,
54372
+ throttleSeconds
54373
+ };
54374
+ state.bellThrottles.set(key, ctx);
54375
+ }
54376
+ const throttleMs = throttleSeconds * 1000;
54377
+ if (now - ctx.lastBellAt < throttleMs) {
54378
+ return false;
54379
+ }
54380
+ ctx.lastBellAt = now;
54381
+ ctx.throttleSeconds = throttleSeconds;
54382
+ return true;
54383
+ }
54384
+ cleanupDevice(ws, deviceId) {
54385
+ const state = this.states.get(ws);
54386
+ if (!state)
54387
+ return;
54388
+ state.deviceConnections.delete(deviceId);
54389
+ state.selectTransactions.delete(deviceId);
54390
+ state.outputGates.delete(deviceId);
54391
+ for (const key of state.bellThrottles.keys()) {
54392
+ if (key.startsWith(`${deviceId}:`)) {
54393
+ state.bellThrottles.delete(key);
54394
+ }
54395
+ }
54396
+ }
54397
+ cleanup(ws) {
54398
+ this.states.delete(ws);
54399
+ }
54400
+ }
54401
+ var sessionStateStore = new SessionStateStore;
54402
+
54403
+ // ../../apps/gateway/src/ws/borsh/switch-barrier.ts
54404
+ var SWITCH_ACK_TIMEOUT_MS = 1500;
54405
+ var HISTORY_TIMEOUT_MS = 1500;
54406
+ var LIVE_RESUME_DELAY_MS = 450;
54407
+
54408
+ class SwitchBarrier {
54409
+ pendingTransactions = new Map;
54410
+ tokensEqual(a, b3) {
54411
+ if (a.length !== b3.length)
54412
+ return false;
54413
+ for (let i = 0;i < a.length; i++) {
54414
+ if (a[i] !== b3[i])
54415
+ return false;
54416
+ }
54417
+ return true;
54418
+ }
54419
+ getOrCreateDeviceMap(ws) {
54420
+ const existing = this.pendingTransactions.get(ws);
54421
+ if (existing)
54422
+ return existing;
54423
+ const created = new Map;
54424
+ this.pendingTransactions.set(ws, created);
54425
+ return created;
54426
+ }
54427
+ getPending(ws, deviceId) {
54428
+ return this.pendingTransactions.get(ws)?.get(deviceId);
54429
+ }
54430
+ setPending(ws, deviceId, value) {
54431
+ this.getOrCreateDeviceMap(ws).set(deviceId, value);
54432
+ }
54433
+ deletePending(ws, deviceId) {
54434
+ const map = this.pendingTransactions.get(ws);
54435
+ if (!map)
54436
+ return;
54437
+ map.delete(deviceId);
54438
+ if (map.size === 0) {
54439
+ this.pendingTransactions.delete(ws);
54440
+ }
54441
+ }
54442
+ startTransaction(ws, context, callbacks = {}) {
54443
+ this.cancelTransaction(ws, context.deviceId);
54444
+ const started = sessionStateStore.startSelectTransaction(ws, context.deviceId, context.windowId, context.paneId, context.selectToken);
54445
+ if (!started) {
54446
+ console.error(`[switch-barrier] Failed to start transaction for ${context.deviceId}`);
54447
+ return false;
54448
+ }
54449
+ const timers = [];
54450
+ timers.push(setTimeout(() => {
54451
+ this.handleTimeout(ws, context.deviceId, "ack", context.selectToken);
54452
+ }, SWITCH_ACK_TIMEOUT_MS));
54453
+ this.setPending(ws, context.deviceId, {
54454
+ context,
54455
+ callbacks,
54456
+ timers
54457
+ });
54458
+ return true;
54459
+ }
54460
+ sendSwitchAck(ws, deviceId) {
54461
+ const pending = this.getPending(ws, deviceId);
54462
+ if (!pending)
54463
+ return;
54464
+ const { context } = pending;
54465
+ const borshState = ws.data?.borshState;
54466
+ if (!borshState)
54467
+ return;
54468
+ const ackTimer = pending.timers.shift();
54469
+ if (ackTimer)
54470
+ clearTimeout(ackTimer);
54471
+ sessionStateStore.transitionSelectState(ws, deviceId, "ACKED");
54472
+ const seq = borshState.seqGen();
54473
+ const ackData = encodeSwitchAck({
54474
+ deviceId,
54475
+ windowId: context.windowId,
54476
+ paneId: context.paneId,
54477
+ selectToken: context.selectToken
54478
+ }, seq);
54479
+ sendToClient(ws, ackData);
54480
+ if (context.wantHistory) {
54481
+ pending.timers.push(setTimeout(() => {
54482
+ this.handleTimeout(ws, deviceId, "history", context.selectToken);
54483
+ }, HISTORY_TIMEOUT_MS));
54484
+ } else {
54485
+ const expectedToken = context.selectToken;
54486
+ pending.timers.push(setTimeout(() => {
54487
+ this.sendLiveResume(ws, deviceId, expectedToken);
54488
+ }, LIVE_RESUME_DELAY_MS));
54489
+ }
54490
+ pending.callbacks.onAckSent?.();
54491
+ }
54492
+ sendTermHistory(ws, deviceId, paneId, historyData) {
54493
+ const pending = this.getPending(ws, deviceId);
54494
+ if (!pending)
54495
+ return;
54496
+ const { context } = pending;
54497
+ if (context.paneId !== paneId) {
54498
+ return;
54499
+ }
54500
+ const borshState = ws.data?.borshState;
54501
+ if (!borshState)
54502
+ return;
54503
+ const historyTimer = pending.timers.shift();
54504
+ if (historyTimer)
54505
+ clearTimeout(historyTimer);
54506
+ sessionStateStore.transitionSelectState(ws, deviceId, "HISTORY_APPLIED");
54507
+ const historyMessages = encodeTermHistory({
54508
+ deviceId,
54509
+ paneId: context.paneId,
54510
+ selectToken: context.selectToken,
54511
+ encoding: 2,
54512
+ data: historyData
54513
+ }, borshState.seqGen, borshState.maxFrameBytes);
54514
+ sendToClient(ws, historyMessages);
54515
+ pending.callbacks.onHistorySent?.();
54516
+ const expectedToken = context.selectToken;
54517
+ pending.timers.push(setTimeout(() => {
54518
+ this.sendLiveResume(ws, deviceId, expectedToken);
54519
+ }, LIVE_RESUME_DELAY_MS));
54520
+ }
54521
+ sendLiveResume(ws, deviceId, expectedToken) {
54522
+ const pending = this.getPending(ws, deviceId);
54523
+ if (!pending)
54524
+ return;
54525
+ const { context } = pending;
54526
+ if (expectedToken && !this.tokensEqual(context.selectToken, expectedToken)) {
54527
+ return;
54528
+ }
54529
+ const borshState = ws.data?.borshState;
54530
+ if (!borshState)
54531
+ return;
54532
+ for (const timer of pending.timers) {
54533
+ clearTimeout(timer);
54534
+ }
54535
+ pending.timers = [];
54536
+ sessionStateStore.transitionSelectState(ws, deviceId, "LIVE");
54537
+ const bufferedOutput = sessionStateStore.stopOutputBuffering(ws, deviceId);
54538
+ const seq = borshState.seqGen();
54539
+ const liveResumeData = encodeLiveResume({
54540
+ deviceId,
54541
+ paneId: context.paneId,
54542
+ selectToken: context.selectToken
54543
+ }, seq);
54544
+ sendToClient(ws, liveResumeData);
54545
+ for (const data of bufferedOutput) {
54546
+ const outputSeq = borshState.seqGen();
54547
+ const outputData = encodeTermOutput({
54548
+ deviceId,
54549
+ paneId: context.paneId,
54550
+ encoding: 1,
54551
+ data
54552
+ }, outputSeq);
54553
+ sendToClient(ws, outputData);
54554
+ }
54555
+ this.completeTransaction(ws, deviceId);
54556
+ pending.callbacks.onLiveResumed?.();
54557
+ }
54558
+ getSelectToken(ws, deviceId) {
54559
+ return this.getPending(ws, deviceId)?.context.selectToken ?? null;
54560
+ }
54561
+ validateToken(ws, deviceId, token) {
54562
+ const currentToken = this.getSelectToken(ws, deviceId);
54563
+ if (!currentToken)
54564
+ return false;
54565
+ if (currentToken.length !== token.length)
54566
+ return false;
54567
+ for (let i = 0;i < currentToken.length; i++) {
54568
+ if (currentToken[i] !== token[i])
54569
+ return false;
54570
+ }
54571
+ return true;
54572
+ }
54573
+ shouldBufferOutput(ws, deviceId) {
54574
+ return sessionStateStore.isBuffering(ws, deviceId);
54575
+ }
54576
+ bufferOutput(ws, deviceId, data) {
54577
+ return sessionStateStore.bufferOutput(ws, deviceId, data);
54578
+ }
54579
+ handleTimeout(ws, deviceId, stage, expectedToken) {
54580
+ const pending = this.getPending(ws, deviceId);
54581
+ if (!pending)
54582
+ return;
54583
+ if (expectedToken && !this.tokensEqual(pending.context.selectToken, expectedToken)) {
54584
+ return;
54585
+ }
54586
+ console.warn(`[switch-barrier] Transaction timeout at stage: ${stage} for ${deviceId}`);
54587
+ if (stage === "history") {
54588
+ this.sendLiveResume(ws, deviceId, expectedToken);
54589
+ pending.callbacks.onTimeout?.(stage);
54590
+ return;
54591
+ }
54592
+ sessionStateStore.transitionSelectState(ws, deviceId, "SELECT_FAILED");
54593
+ sessionStateStore.stopOutputBuffering(ws, deviceId);
54594
+ pending.callbacks.onTimeout?.(stage);
54595
+ this.cleanupTransaction(ws, deviceId);
54596
+ }
54597
+ cancelTransaction(ws, deviceId) {
54598
+ const pending = this.getPending(ws, deviceId);
54599
+ if (!pending)
54600
+ return;
54601
+ for (const timer of pending.timers) {
54602
+ clearTimeout(timer);
54603
+ }
54604
+ sessionStateStore.stopOutputBuffering(ws, deviceId);
54605
+ this.cleanupTransaction(ws, deviceId);
54606
+ }
54607
+ completeTransaction(ws, deviceId) {
54608
+ sessionStateStore.transitionSelectState(ws, deviceId, "STABLE");
54609
+ this.cleanupTransaction(ws, deviceId);
54610
+ }
54611
+ cleanupTransaction(ws, deviceId) {
54612
+ this.deletePending(ws, deviceId);
54613
+ }
54614
+ cleanupClient(ws) {
54615
+ const deviceMap = this.pendingTransactions.get(ws);
54616
+ if (!deviceMap)
54617
+ return;
54618
+ for (const deviceId of Array.from(deviceMap.keys())) {
54619
+ this.cancelTransaction(ws, deviceId);
54620
+ }
54621
+ }
54622
+ }
54623
+ var switchBarrier = new SwitchBarrier;
54624
+
52322
54625
  // ../../apps/gateway/src/ws/index.ts
52323
54626
  class WebSocketServer {
52324
54627
  connections = new Map;
@@ -52345,7 +54648,7 @@ class WebSocketServer {
52345
54648
  const entry = this.connections.get(deviceId);
52346
54649
  if (!entry)
52347
54650
  return;
52348
- const hasSelectedPaneClient = Array.from(entry.clients).some((client) => Boolean(client.data.selectedPanes[deviceId]));
54651
+ const hasSelectedPaneClient = Array.from(entry.clients).some((client) => Boolean(client.data.borshState.selectedPanes[deviceId]));
52349
54652
  if (!hasSelectedPaneClient) {
52350
54653
  this.clearSnapshotPollTimer(entry);
52351
54654
  return;
@@ -52389,32 +54692,60 @@ class WebSocketServer {
52389
54692
  }
52390
54693
  const success = server.upgrade(req, {
52391
54694
  data: {
52392
- selectedPanes: {}
54695
+ borshState: createBorshClientState()
52393
54696
  }
52394
54697
  });
52395
54698
  return success ? undefined : new Response("Upgrade failed", { status: 500 });
52396
54699
  }
52397
54700
  handleOpen(ws) {
52398
54701
  console.log("[ws] client connected");
52399
- ws.send(JSON.stringify({ type: "connected", payload: {} }));
54702
+ sessionStateStore.create(ws);
52400
54703
  }
52401
54704
  handleMessage(ws, message) {
54705
+ if (typeof message === "string") {
54706
+ return;
54707
+ }
54708
+ const data = new Uint8Array(message);
54709
+ if (!exports_ws_borsh.checkMagic(data)) {
54710
+ this.sendError(ws, null, exports_ws_borsh.ERROR_INVALID_FRAME, "Missing magic bytes", false);
54711
+ return;
54712
+ }
54713
+ let envelope;
52402
54714
  try {
52403
- const data = JSON.parse(message.toString());
52404
- this.handleWsMessage(ws, data);
54715
+ envelope = exports_ws_borsh.decodeEnvelope(data);
52405
54716
  } catch (err) {
52406
- console.error("[ws] failed to parse message:", err);
52407
- ws.send(JSON.stringify({ type: "error", payload: { message: "Invalid message format" } }));
54717
+ const e = err instanceof exports_ws_borsh.WsBorshError ? err : null;
54718
+ this.sendError(ws, null, e?.code ?? exports_ws_borsh.ERROR_INVALID_FRAME, e?.message ?? "Invalid envelope", e?.retryable ?? false);
54719
+ return;
54720
+ }
54721
+ const clientState = ws.data.borshState;
54722
+ if (envelope.kind === exports_ws_borsh.KIND_CHUNK) {
54723
+ try {
54724
+ const chunk2 = exports_ws_borsh.decodeChunk(envelope.payload);
54725
+ const reassembled = clientState.chunkReassembler.addChunk(chunk2);
54726
+ if (!reassembled) {
54727
+ return;
54728
+ }
54729
+ this.handleBorshMessage(ws, reassembled.kind, reassembled.seq, reassembled.payload);
54730
+ return;
54731
+ } catch (err) {
54732
+ const e = err instanceof exports_ws_borsh.WsBorshError ? err : null;
54733
+ this.sendError(ws, null, e?.code ?? exports_ws_borsh.ERROR_INVALID_FRAME, e?.message ?? "Invalid chunk", e?.retryable ?? false);
54734
+ return;
54735
+ }
52408
54736
  }
54737
+ this.handleBorshMessage(ws, envelope.kind, envelope.seq, envelope.payload);
52409
54738
  }
52410
54739
  handleClose(ws) {
52411
54740
  console.log("[ws] client disconnected");
54741
+ switchBarrier.cleanupClient(ws);
54742
+ sessionStateStore.cleanup(ws);
52412
54743
  const toDelete = [];
52413
54744
  for (const [deviceId, entry] of this.connections) {
52414
54745
  if (!entry.clients.has(ws))
52415
54746
  continue;
52416
54747
  entry.clients.delete(ws);
52417
- delete ws.data.selectedPanes[deviceId];
54748
+ delete ws.data.borshState.selectedPanes[deviceId];
52418
54749
  if (entry.clients.size === 0) {
52419
54750
  console.log(`[ws] no more clients for device ${deviceId}, disconnecting`);
52420
54751
  this.clearSnapshotTimer(entry);
@@ -52440,6 +54771,155 @@ class WebSocketServer {
52440
54771
  }
52441
54772
  this.pendingConnectionEntries.clear();
52442
54773
  }
54774
+ async handleBorshMessage(ws, kind, refSeq, payload) {
54775
+ const state = ws.data.borshState;
54776
+ if (kind !== exports_ws_borsh.KIND_HELLO_C2S && !state.negotiated) {
54777
+ this.sendError(ws, refSeq, exports_ws_borsh.ERROR_INVALID_FRAME, "HELLO required", false);
54778
+ return;
54779
+ }
54780
+ if (kind === exports_ws_borsh.KIND_HELLO_C2S) {
54781
+ this.handleHello(ws, refSeq, payload);
54782
+ return;
54783
+ }
54784
+ if (kind === exports_ws_borsh.KIND_PING) {
54785
+ this.handlePing(ws, refSeq, payload);
54786
+ return;
54787
+ }
54788
+ switch (kind) {
54789
+ case exports_ws_borsh.KIND_DEVICE_CONNECT: {
54790
+ const decoded = exports_ws_borsh.decodePayload(exports_ws_borsh.schema.DeviceConnectSchema, payload);
54791
+ await this.handleDeviceConnect(ws, decoded.deviceId);
54792
+ return;
54793
+ }
54794
+ case exports_ws_borsh.KIND_DEVICE_DISCONNECT: {
54795
+ const decoded = exports_ws_borsh.decodePayload(exports_ws_borsh.schema.DeviceDisconnectSchema, payload);
54796
+ this.handleDeviceDisconnect(ws, decoded.deviceId);
54797
+ return;
54798
+ }
54799
+ case exports_ws_borsh.KIND_TMUX_SELECT: {
54800
+ const decoded = exports_ws_borsh.decodePayload(exports_ws_borsh.schema.TmuxSelectSchema, payload);
54801
+ this.handleTmuxSelect(ws, decoded);
54802
+ return;
54803
+ }
54804
+ case exports_ws_borsh.KIND_TMUX_SELECT_WINDOW: {
54805
+ const decoded = exports_ws_borsh.decodePayload(exports_ws_borsh.schema.TmuxSelectWindowSchema, payload);
54806
+ this.handleTmuxSelectWindow(decoded.deviceId, decoded.windowId);
54807
+ return;
54808
+ }
54809
+ case exports_ws_borsh.KIND_TMUX_CREATE_WINDOW: {
54810
+ const decoded = exports_ws_borsh.decodePayload(exports_ws_borsh.schema.TmuxCreateWindowSchema, payload);
54811
+ this.handleCreateWindow(decoded.deviceId, decoded.name ?? undefined);
54812
+ return;
54813
+ }
54814
+ case exports_ws_borsh.KIND_TMUX_CLOSE_WINDOW: {
54815
+ const decoded = exports_ws_borsh.decodePayload(exports_ws_borsh.schema.TmuxCloseWindowSchema, payload);
54816
+ this.handleCloseWindow(decoded.deviceId, decoded.windowId);
54817
+ return;
54818
+ }
54819
+ case exports_ws_borsh.KIND_TMUX_CLOSE_PANE: {
54820
+ const decoded = exports_ws_borsh.decodePayload(exports_ws_borsh.schema.TmuxClosePaneSchema, payload);
54821
+ this.handleClosePane(decoded.deviceId, decoded.paneId);
54822
+ return;
54823
+ }
54824
+ case exports_ws_borsh.KIND_TMUX_RENAME_WINDOW: {
54825
+ const decoded = exports_ws_borsh.decodePayload(exports_ws_borsh.schema.TmuxRenameWindowSchema, payload);
54826
+ this.handleRenameWindow(decoded.deviceId, decoded.windowId, decoded.name);
54827
+ return;
54828
+ }
54829
+ case exports_ws_borsh.KIND_TERM_INPUT: {
54830
+ const decoded = exports_ws_borsh.decodePayload(exports_ws_borsh.schema.TermInputSchema, payload);
54831
+ if (decoded.isComposing)
54832
+ return;
54833
+ const text2 = new TextDecoder().decode(decoded.data);
54834
+ this.handleTermInput(decoded.deviceId, decoded.paneId, text2);
54835
+ return;
54836
+ }
54837
+ case exports_ws_borsh.KIND_TERM_PASTE: {
54838
+ const decoded = exports_ws_borsh.decodePayload(exports_ws_borsh.schema.TermPasteSchema, payload);
54839
+ const text2 = new TextDecoder().decode(decoded.data);
54840
+ this.handleTermPaste(decoded.deviceId, decoded.paneId, text2);
54841
+ return;
54842
+ }
54843
+ case exports_ws_borsh.KIND_TERM_RESIZE: {
54844
+ const decoded = exports_ws_borsh.decodePayload(exports_ws_borsh.schema.TermResizeSchema, payload);
54845
+ this.handleTermResize(decoded.deviceId, decoded.paneId, decoded.cols, decoded.rows);
54846
+ return;
54847
+ }
54848
+ case exports_ws_borsh.KIND_TERM_SYNC_SIZE: {
54849
+ const decoded = exports_ws_borsh.decodePayload(exports_ws_borsh.schema.TermSyncSizeSchema, payload);
54850
+ this.handleTermResize(decoded.deviceId, decoded.paneId, decoded.cols, decoded.rows);
54851
+ return;
54852
+ }
54853
+ default:
54854
+ this.sendError(ws, refSeq, exports_ws_borsh.ERROR_UNKNOWN_KIND, `Unknown kind: ${kind}`, false);
54855
+ }
54856
+ }
54857
+ handleHello(ws, refSeq, payload) {
54858
+ let hello;
54859
+ try {
54860
+ hello = exports_ws_borsh.decodePayload(exports_ws_borsh.schema.HelloC2SSchema, payload);
54861
+ } catch (err) {
54862
+ const e = err instanceof exports_ws_borsh.WsBorshError ? err : null;
54863
+ this.sendError(ws, refSeq, e?.code ?? exports_ws_borsh.ERROR_PAYLOAD_DECODE_FAILED, e?.message ?? "HELLO payload decode failed", e?.retryable ?? false);
54864
+ return;
54865
+ }
54866
+ const serverMaxFrameBytes = exports_ws_borsh.DEFAULT_MAX_FRAME_BYTES;
54867
+ const effectiveMaxFrameBytes = Math.min(hello.maxFrameBytes, serverMaxFrameBytes);
54868
+ ws.data.borshState.negotiated = true;
54869
+ ws.data.borshState.maxFrameBytes = effectiveMaxFrameBytes;
54870
+ const helloS2C = {
54871
+ serverImpl: "tmex-gateway",
54872
+ serverVersion: "0.1.0",
54873
+ selectedVersion: exports_ws_borsh.CURRENT_VERSION,
54874
+ maxFrameBytes: serverMaxFrameBytes,
54875
+ heartbeatIntervalMs: 15000,
54876
+ capabilities: ["tmex-ws-borsh-v1"]
54877
+ };
54878
+ const payloadBytes = exports_ws_borsh.encodePayload(exports_ws_borsh.schema.HelloS2CSchema, helloS2C);
54879
+ this.sendEnvelope(ws, exports_ws_borsh.KIND_HELLO_S2C, payloadBytes);
54880
+ }
54881
+ handlePing(ws, refSeq, payload) {
54882
+ try {
54883
+ const ping = exports_ws_borsh.decodePayload(exports_ws_borsh.schema.PingPongSchema, payload);
54884
+ const pongPayload = exports_ws_borsh.encodePayload(exports_ws_borsh.schema.PingPongSchema, {
54885
+ nonce: ping.nonce,
54886
+ timeMs: ping.timeMs
54887
+ });
54888
+ this.sendEnvelope(ws, exports_ws_borsh.KIND_PONG, pongPayload);
54889
+ } catch (err) {
54890
+ const e = err instanceof exports_ws_borsh.WsBorshError ? err : null;
54891
+ this.sendError(ws, refSeq, e?.code ?? exports_ws_borsh.ERROR_PAYLOAD_DECODE_FAILED, e?.message ?? "PING payload decode failed", e?.retryable ?? false);
54892
+ }
54893
+ }
54894
+ sendEnvelope(ws, kind, payload) {
54895
+ const seq = ws.data.borshState.seqGen();
54896
+ const data = exports_ws_borsh.encodeEnvelope(kind, payload, seq);
54897
+ ws.send(data);
54898
+ }
54899
+ sendChunked(ws, kind, payload) {
54900
+ const state = ws.data.borshState;
54901
+ const originalSeq = state.seqGen();
54902
+ const chunked = exports_ws_borsh.splitPayloadIntoChunks(payload, kind, originalSeq, {
54903
+ maxFrameBytes: state.maxFrameBytes,
54904
+ chunkStreamId: exports_ws_borsh.generateChunkStreamId()
54905
+ });
54906
+ if (chunked.totalChunks === 0) {
54907
+ ws.send(exports_ws_borsh.encodeEnvelope(kind, payload, originalSeq));
54908
+ return;
54909
+ }
54910
+ for (const chunk2 of chunked.chunks) {
54911
+ ws.send(exports_ws_borsh.encodeChunk(chunk2, state.seqGen()));
54912
+ }
54913
+ }
54914
+ sendError(ws, refSeq, code2, message, retryable) {
54915
+ const payload = exports_ws_borsh.encodePayload(exports_ws_borsh.schema.ErrorSchema, {
54916
+ refSeq,
54917
+ code: code2,
54918
+ message,
54919
+ retryable
54920
+ });
54921
+ this.sendEnvelope(ws, exports_ws_borsh.KIND_ERROR, payload);
54922
+ }
52443
54923
  async getOrCreateConnectionEntry(deviceId, ws) {
52444
54924
  const existing = this.connections.get(deviceId);
52445
54925
  if (existing) {
@@ -52463,129 +54943,21 @@ class WebSocketServer {
52463
54943
  this.pendingConnectionEntries.set(deviceId, creationPromise);
52464
54944
  return creationPromise;
52465
54945
  }
52466
- async handleWsMessage(ws, msg) {
52467
- const { type, payload } = msg;
52468
- switch (type) {
52469
- case "device/connect": {
52470
- const { deviceId } = payload;
52471
- await this.handleDeviceConnect(ws, deviceId);
52472
- break;
52473
- }
52474
- case "device/disconnect": {
52475
- const { deviceId } = payload;
52476
- this.handleDeviceDisconnect(ws, deviceId);
52477
- break;
52478
- }
52479
- case "tmux/select": {
52480
- const data = payload;
52481
- this.handleTmuxSelect(ws, data);
52482
- break;
52483
- }
52484
- case "tmux/select-window": {
52485
- const data = payload;
52486
- this.handleTmuxSelectWindow(data);
52487
- break;
52488
- }
52489
- case "term/input": {
52490
- const data = payload;
52491
- this.handleTermInput(data);
52492
- break;
52493
- }
52494
- case "term/resize": {
52495
- const data = payload;
52496
- this.handleTermResize(data);
52497
- break;
52498
- }
52499
- case "term/sync-size": {
52500
- const data = payload;
52501
- this.handleTermSyncSize(data);
52502
- break;
52503
- }
52504
- case "term/paste": {
52505
- const data = payload;
52506
- this.handleTermPaste(data);
52507
- break;
52508
- }
52509
- case "tmux/create-window": {
52510
- const data = payload;
52511
- this.handleCreateWindow(data);
52512
- break;
52513
- }
52514
- case "tmux/close-window": {
52515
- const data = payload;
52516
- this.handleCloseWindow(data);
52517
- break;
52518
- }
52519
- case "tmux/close-pane": {
52520
- const data = payload;
52521
- this.handleClosePane(data);
52522
- break;
52523
- }
52524
- default:
52525
- console.log("[ws] unknown message type:", type);
52526
- }
52527
- }
52528
54946
  async handleDeviceConnect(ws, deviceId) {
52529
54947
  const entry = await this.getOrCreateConnectionEntry(deviceId, ws);
52530
- if (!entry) {
54948
+ if (!entry)
52531
54949
  return;
52532
- }
52533
54950
  entry.clients.add(ws);
52534
- ws.data.selectedPanes[deviceId] ??= null;
52535
- ws.send(JSON.stringify({
52536
- type: "device/connected",
52537
- payload: { deviceId }
52538
- }));
54951
+ ws.data.borshState.selectedPanes[deviceId] ??= null;
54952
+ const connectedPayload = exports_ws_borsh.encodePayload(exports_ws_borsh.schema.DeviceConnectedSchema, { deviceId });
54953
+ this.sendEnvelope(ws, exports_ws_borsh.KIND_DEVICE_CONNECTED, connectedPayload);
52539
54954
  if (entry.lastSnapshot) {
52540
- ws.send(JSON.stringify({
52541
- type: "state/snapshot",
52542
- payload: entry.lastSnapshot
52543
- }));
54955
+ const snapshotBytes = exports_ws_borsh.encodeStateSnapshot(entry.lastSnapshot);
54956
+ this.sendChunked(ws, exports_ws_borsh.KIND_STATE_SNAPSHOT, snapshotBytes);
52544
54957
  } else {
52545
54958
  entry.connection.requestSnapshot();
52546
54959
  }
52547
54960
  }
52548
- async createDeviceConnectionEntry(deviceId, ws) {
52549
- const connection = new TmuxConnection({
52550
- deviceId,
52551
- onEvent: (event) => {
52552
- this.broadcastTmuxEvent(deviceId, event);
52553
- },
52554
- onTerminalOutput: (paneId, data) => this.broadcastTerminalOutput(deviceId, paneId, data),
52555
- onTerminalHistory: (paneId, data) => this.broadcastTerminalHistory(deviceId, paneId, data),
52556
- onSnapshot: (payload) => this.broadcastStateSnapshot(deviceId, payload),
52557
- onError: (err) => this.broadcastError(deviceId, err),
52558
- onClose: () => {
52559
- this.handleConnectionClose(deviceId);
52560
- }
52561
- });
52562
- try {
52563
- await connection.connect();
52564
- return {
52565
- connection,
52566
- clients: new Set,
52567
- lastSnapshot: null,
52568
- snapshotTimer: null,
52569
- snapshotPollTimer: null,
52570
- reconnectAttempts: 0,
52571
- reconnectTimer: null
52572
- };
52573
- } catch (err) {
52574
- const errorInfo = classifySshError(err instanceof Error ? err : new Error(String(err)));
52575
- const settings = getSiteSettings();
52576
- ws.send(JSON.stringify({
52577
- type: "event/device",
52578
- payload: {
52579
- deviceId,
52580
- type: "error",
52581
- errorType: errorInfo.type,
52582
- message: t2(errorInfo.messageKey, { ...errorInfo.messageParams }),
52583
- rawMessage: err instanceof Error ? err.message : String(err)
52584
- }
52585
- }));
52586
- return null;
52587
- }
52588
- }
52589
54961
  handleDeviceDisconnect(ws, deviceId) {
52590
54962
  const entry = this.connections.get(deviceId);
52591
54963
  if (entry) {
@@ -52599,80 +54971,132 @@ class WebSocketServer {
52599
54971
  this.connections.delete(deviceId);
52600
54972
  }
52601
54973
  }
52602
- delete ws.data.selectedPanes[deviceId];
52603
- ws.send(JSON.stringify({
52604
- type: "device/disconnected",
52605
- payload: { deviceId }
52606
- }));
52607
- }
52608
- handleTmuxSelectWindow(data) {
52609
- const entry = this.connections.get(data.deviceId);
52610
- if (!entry)
52611
- return;
52612
- entry.connection.selectWindow(data.windowId);
54974
+ delete ws.data.borshState.selectedPanes[deviceId];
54975
+ const disconnectedPayload = exports_ws_borsh.encodePayload(exports_ws_borsh.schema.DeviceDisconnectedSchema, { deviceId });
54976
+ this.sendEnvelope(ws, exports_ws_borsh.KIND_DEVICE_DISCONNECTED, disconnectedPayload);
52613
54977
  }
52614
54978
  handleTmuxSelect(ws, data) {
52615
- if (data.paneId !== undefined) {
52616
- ws.data.selectedPanes[data.deviceId] = data.paneId;
52617
- this.refreshSnapshotPolling(data.deviceId);
54979
+ const deviceId = data.deviceId;
54980
+ const paneId = data.paneId ?? undefined;
54981
+ if (paneId) {
54982
+ ws.data.borshState.selectedPanes[deviceId] = paneId;
54983
+ this.refreshSnapshotPolling(deviceId);
52618
54984
  }
52619
- const entry = this.connections.get(data.deviceId);
52620
- if (!entry) {
54985
+ const entry = this.connections.get(deviceId);
54986
+ if (!entry)
54987
+ return;
54988
+ const windowId = data.windowId ?? undefined;
54989
+ if (!windowId || !paneId)
54990
+ return;
54991
+ const started = switchBarrier.startTransaction(ws, {
54992
+ deviceId,
54993
+ windowId,
54994
+ paneId,
54995
+ selectToken: data.selectToken,
54996
+ wantHistory: data.wantHistory,
54997
+ cols: data.cols ?? null,
54998
+ rows: data.rows ?? null
54999
+ });
55000
+ if (!started) {
55001
+ this.sendError(ws, null, exports_ws_borsh.ERROR_SELECT_CONFLICT, "Failed to start select transaction", false);
52621
55002
  return;
52622
55003
  }
52623
- if (data.windowId && data.paneId) {
52624
- entry.connection.selectPane(data.windowId, data.paneId);
55004
+ switchBarrier.sendSwitchAck(ws, deviceId);
55005
+ entry.connection.selectPane(windowId, paneId);
55006
+ const cols = data.cols ?? null;
55007
+ const rows = data.rows ?? null;
55008
+ if (cols !== null && rows !== null) {
55009
+ entry.connection.resizePane(paneId, cols, rows);
52625
55010
  }
52626
55011
  }
52627
- handleTermInput(data) {
52628
- const entry = this.connections.get(data.deviceId);
55012
+ handleTmuxSelectWindow(deviceId, windowId) {
55013
+ const entry = this.connections.get(deviceId);
52629
55014
  if (!entry)
52630
55015
  return;
52631
- if (data.isComposing) {
52632
- return;
52633
- }
52634
- entry.connection.sendInput(data.paneId, data.data);
55016
+ entry.connection.selectWindow(windowId);
52635
55017
  }
52636
- handleTermResize(data) {
52637
- const entry = this.connections.get(data.deviceId);
55018
+ handleTermInput(deviceId, paneId, data) {
55019
+ const entry = this.connections.get(deviceId);
52638
55020
  if (!entry)
52639
55021
  return;
52640
- entry.connection.resizePane(data.paneId, data.cols, data.rows);
55022
+ entry.connection.sendInput(paneId, data);
52641
55023
  }
52642
- handleTermSyncSize(data) {
52643
- const entry = this.connections.get(data.deviceId);
55024
+ handleTermResize(deviceId, paneId, cols, rows) {
55025
+ const entry = this.connections.get(deviceId);
52644
55026
  if (!entry)
52645
55027
  return;
52646
- entry.connection.resizePane(data.paneId, data.cols, data.rows);
55028
+ entry.connection.resizePane(paneId, cols, rows);
52647
55029
  }
52648
- handleTermPaste(data) {
52649
- const entry = this.connections.get(data.deviceId);
55030
+ handleTermPaste(deviceId, paneId, data) {
55031
+ const entry = this.connections.get(deviceId);
52650
55032
  if (!entry)
52651
55033
  return;
52652
55034
  const chunkSize = 1024;
52653
- const text2 = data.data;
52654
- for (let i = 0;i < text2.length; i += chunkSize) {
52655
- const chunk2 = text2.slice(i, i + chunkSize);
52656
- entry.connection.sendInput(data.paneId, chunk2);
55035
+ for (let i = 0;i < data.length; i += chunkSize) {
55036
+ const chunk2 = data.slice(i, i + chunkSize);
55037
+ entry.connection.sendInput(paneId, chunk2);
52657
55038
  }
52658
55039
  }
52659
- handleCreateWindow(data) {
52660
- const entry = this.connections.get(data.deviceId);
55040
+ handleCreateWindow(deviceId, name) {
55041
+ const entry = this.connections.get(deviceId);
52661
55042
  if (!entry)
52662
55043
  return;
52663
- entry.connection.createWindow(data.name);
55044
+ entry.connection.createWindow(name);
52664
55045
  }
52665
- handleCloseWindow(data) {
52666
- const entry = this.connections.get(data.deviceId);
55046
+ handleCloseWindow(deviceId, windowId) {
55047
+ const entry = this.connections.get(deviceId);
52667
55048
  if (!entry)
52668
55049
  return;
52669
- entry.connection.closeWindow(data.windowId);
55050
+ entry.connection.closeWindow(windowId);
52670
55051
  }
52671
- handleClosePane(data) {
52672
- const entry = this.connections.get(data.deviceId);
55052
+ handleClosePane(deviceId, paneId) {
55053
+ const entry = this.connections.get(deviceId);
52673
55054
  if (!entry)
52674
55055
  return;
52675
- entry.connection.closePane(data.paneId);
55056
+ entry.connection.closePane(paneId);
55057
+ }
55058
+ handleRenameWindow(deviceId, windowId, name) {
55059
+ const entry = this.connections.get(deviceId);
55060
+ if (!entry)
55061
+ return;
55062
+ entry.connection.renameWindow(windowId, name);
55063
+ }
55064
+ async createDeviceConnectionEntry(deviceId, ws) {
55065
+ const connection = new TmuxConnection({
55066
+ deviceId,
55067
+ onEvent: (event) => {
55068
+ this.broadcastTmuxEvent(deviceId, event);
55069
+ },
55070
+ onTerminalOutput: (paneId, data) => this.broadcastTerminalOutput(deviceId, paneId, data),
55071
+ onTerminalHistory: (paneId, data) => this.broadcastTerminalHistory(deviceId, paneId, data),
55072
+ onSnapshot: (payload) => this.broadcastStateSnapshot(deviceId, payload),
55073
+ onError: (err) => this.broadcastError(deviceId, err),
55074
+ onClose: () => {
55075
+ this.handleConnectionClose(deviceId);
55076
+ }
55077
+ });
55078
+ try {
55079
+ await connection.connect();
55080
+ return {
55081
+ connection,
55082
+ clients: new Set,
55083
+ lastSnapshot: null,
55084
+ snapshotTimer: null,
55085
+ snapshotPollTimer: null,
55086
+ reconnectAttempts: 0,
55087
+ reconnectTimer: null
55088
+ };
55089
+ } catch (err) {
55090
+ const errorInfo = classifySshError(err instanceof Error ? err : new Error(String(err)));
55091
+ ws.send(exports_ws_borsh.encodeEnvelope(exports_ws_borsh.KIND_DEVICE_EVENT, exports_ws_borsh.encodeDeviceEventPayload({
55092
+ deviceId,
55093
+ type: "error",
55094
+ errorType: errorInfo.type,
55095
+ message: t2(errorInfo.messageKey, { ...errorInfo.messageParams }),
55096
+ rawMessage: err instanceof Error ? err.message : String(err)
55097
+ }), ws.data.borshState.seqGen()));
55098
+ return null;
55099
+ }
52676
55100
  }
52677
55101
  async broadcastTmuxEvent(deviceId, event) {
52678
55102
  const entry = this.connections.get(deviceId);
@@ -52680,16 +55104,25 @@ class WebSocketServer {
52680
55104
  return;
52681
55105
  this.scheduleSnapshot(deviceId);
52682
55106
  const extendedEvent = await this.extendTmuxEvent(deviceId, event);
52683
- const message = JSON.stringify({
52684
- type: "event/tmux",
52685
- payload: {
52686
- deviceId,
52687
- type: extendedEvent.type,
52688
- data: extendedEvent.data
52689
- }
55107
+ const payloadBytes = exports_ws_borsh.encodeTmuxEventPayload({
55108
+ deviceId,
55109
+ type: extendedEvent.type,
55110
+ data: extendedEvent.data
52690
55111
  });
55112
+ if (extendedEvent.type === "bell") {
55113
+ const settings = getSiteSettings();
55114
+ const data = extendedEvent.data ?? {};
55115
+ const paneId = typeof data.paneId === "string" && data.paneId ? data.paneId : "-";
55116
+ for (const client of entry.clients) {
55117
+ if (!sessionStateStore.shouldAllowBell(client, deviceId, paneId, settings.bellThrottleSeconds)) {
55118
+ continue;
55119
+ }
55120
+ this.sendEnvelope(client, exports_ws_borsh.KIND_TMUX_EVENT, payloadBytes);
55121
+ }
55122
+ return;
55123
+ }
52691
55124
  for (const client of entry.clients) {
52692
- client.send(message);
55125
+ this.sendEnvelope(client, exports_ws_borsh.KIND_TMUX_EVENT, payloadBytes);
52693
55126
  }
52694
55127
  }
52695
55128
  async extendTmuxEvent(deviceId, event) {
@@ -52714,57 +55147,42 @@ class WebSocketServer {
52714
55147
  if (!entry)
52715
55148
  return;
52716
55149
  entry.lastSnapshot = payload;
52717
- const message = JSON.stringify({
52718
- type: "state/snapshot",
52719
- payload
52720
- });
55150
+ const payloadBytes = exports_ws_borsh.encodeStateSnapshot(payload);
52721
55151
  for (const client of entry.clients) {
52722
- client.send(message);
55152
+ this.sendChunked(client, exports_ws_borsh.KIND_STATE_SNAPSHOT, payloadBytes);
52723
55153
  }
52724
55154
  }
52725
55155
  broadcastTerminalOutput(deviceId, paneId, data) {
52726
55156
  const entry = this.connections.get(deviceId);
52727
55157
  if (!entry)
52728
55158
  return;
52729
- const deviceIdBytes = new TextEncoder().encode(deviceId);
52730
- const paneIdBytes = new TextEncoder().encode(paneId);
52731
- const headerSize = 1 + 2 + deviceIdBytes.length + 2 + paneIdBytes.length;
52732
- const message = new Uint8Array(headerSize + data.length);
52733
- message[0] = 1;
52734
- message[1] = deviceIdBytes.length >> 8 & 255;
52735
- message[2] = deviceIdBytes.length & 255;
52736
- message.set(deviceIdBytes, 3);
52737
- const paneLenOffset = 3 + deviceIdBytes.length;
52738
- message[paneLenOffset] = paneIdBytes.length >> 8 & 255;
52739
- message[paneLenOffset + 1] = paneIdBytes.length & 255;
52740
- const paneOffset = paneLenOffset + 2;
52741
- message.set(paneIdBytes, paneOffset);
52742
- message.set(data, paneOffset + paneIdBytes.length);
52743
55159
  for (const client of entry.clients) {
52744
- if (client.data.selectedPanes[deviceId] !== paneId) {
55160
+ if (client.data.borshState.selectedPanes[deviceId] !== paneId) {
55161
+ continue;
55162
+ }
55163
+ if (switchBarrier.shouldBufferOutput(client, deviceId)) {
55164
+ switchBarrier.bufferOutput(client, deviceId, data);
52745
55165
  continue;
52746
55166
  }
52747
- client.send(message);
55167
+ const payloadBytes = exports_ws_borsh.encodePayload(exports_ws_borsh.schema.TermOutputSchema, {
55168
+ deviceId,
55169
+ paneId,
55170
+ encoding: 1,
55171
+ data
55172
+ });
55173
+ this.sendChunked(client, exports_ws_borsh.KIND_TERM_OUTPUT, payloadBytes);
52748
55174
  }
52749
55175
  }
52750
55176
  broadcastTerminalHistory(deviceId, paneId, data) {
52751
55177
  const entry = this.connections.get(deviceId);
52752
- if (!entry) {
55178
+ if (!entry)
52753
55179
  return;
52754
- }
52755
- const message = JSON.stringify({
52756
- type: "term/history",
52757
- payload: {
52758
- deviceId,
52759
- paneId,
52760
- data
52761
- }
52762
- });
55180
+ const historyBytes = new TextEncoder().encode(data);
52763
55181
  for (const client of entry.clients) {
52764
- if (client.data.selectedPanes[deviceId] !== paneId) {
55182
+ if (client.data.borshState.selectedPanes[deviceId] !== paneId) {
52765
55183
  continue;
52766
55184
  }
52767
- client.send(message);
55185
+ switchBarrier.sendTermHistory(client, deviceId, paneId, historyBytes);
52768
55186
  }
52769
55187
  }
52770
55188
  broadcastError(deviceId, err) {
@@ -52772,19 +55190,21 @@ class WebSocketServer {
52772
55190
  if (!entry)
52773
55191
  return;
52774
55192
  const errorInfo = classifySshError(err);
52775
- const settings = getSiteSettings();
52776
- const message = JSON.stringify({
52777
- type: "event/device",
52778
- payload: {
52779
- deviceId,
52780
- type: "error",
52781
- errorType: errorInfo.type,
52782
- message: t2(errorInfo.messageKey, { ...errorInfo.messageParams }),
52783
- rawMessage: err.message
52784
- }
55193
+ const payloadBytes = exports_ws_borsh.encodeDeviceEventPayload({
55194
+ deviceId,
55195
+ type: "error",
55196
+ errorType: errorInfo.type,
55197
+ message: t2(errorInfo.messageKey, { ...errorInfo.messageParams }),
55198
+ rawMessage: err.message
52785
55199
  });
52786
55200
  for (const client of entry.clients) {
52787
- client.send(message);
55201
+ this.sendEnvelope(client, exports_ws_borsh.KIND_DEVICE_EVENT, payloadBytes);
55202
+ }
55203
+ }
55204
+ broadcastDeviceEvent(entry, payload) {
55205
+ const payloadBytes = exports_ws_borsh.encodeDeviceEventPayload(payload);
55206
+ for (const client of entry.clients) {
55207
+ this.sendEnvelope(client, exports_ws_borsh.KIND_DEVICE_EVENT, payloadBytes);
52788
55208
  }
52789
55209
  }
52790
55210
  async handleConnectionClose(deviceId) {
@@ -52798,7 +55218,6 @@ class WebSocketServer {
52798
55218
  if (entry.clients.size > 0 && entry.reconnectAttempts < sshReconnectMaxRetries) {
52799
55219
  entry.reconnectAttempts += 1;
52800
55220
  const delay = Math.max(1, sshReconnectDelaySeconds) * 1000;
52801
- const settings = getSiteSettings();
52802
55221
  const notifying = {
52803
55222
  deviceId,
52804
55223
  type: "error",
@@ -52851,20 +55270,11 @@ class WebSocketServer {
52851
55270
  };
52852
55271
  this.broadcastDeviceEvent(entry, disconnected);
52853
55272
  for (const client of entry.clients) {
52854
- delete client.data.selectedPanes[deviceId];
55273
+ delete client.data.borshState.selectedPanes[deviceId];
52855
55274
  }
52856
55275
  this.clearReconnectTimer(entry);
52857
55276
  this.connections.delete(deviceId);
52858
55277
  }
52859
- broadcastDeviceEvent(entry, payload) {
52860
- const message = JSON.stringify({
52861
- type: "event/device",
52862
- payload
52863
- });
52864
- for (const client of entry.clients) {
52865
- client.send(message);
52866
- }
52867
- }
52868
55278
  }
52869
55279
 
52870
55280
  // ../../apps/gateway/src/runtime.ts