@hydranium/client-theia 1.0.0-next.36 → 1.0.0-next.361

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 (95) hide show
  1. package/README.md +52 -80
  2. package/lib/browser/browser-capture.js.map +1 -1
  3. package/lib/browser/channel-logger.d.ts +4 -3
  4. package/lib/browser/channel-logger.d.ts.map +1 -1
  5. package/lib/browser/channel-logger.js +11 -19
  6. package/lib/browser/channel-logger.js.map +1 -1
  7. package/lib/browser/connection-diagnostics-contribution.d.ts +73 -0
  8. package/lib/browser/connection-diagnostics-contribution.d.ts.map +1 -0
  9. package/lib/browser/connection-diagnostics-contribution.js +162 -0
  10. package/lib/browser/connection-diagnostics-contribution.js.map +1 -0
  11. package/lib/browser/connection-reporter.d.ts +57 -0
  12. package/lib/browser/connection-reporter.d.ts.map +1 -0
  13. package/lib/browser/connection-reporter.js +104 -0
  14. package/lib/browser/connection-reporter.js.map +1 -0
  15. package/lib/browser/editor-disk-sync.d.ts +142 -0
  16. package/lib/browser/editor-disk-sync.d.ts.map +1 -0
  17. package/lib/browser/editor-disk-sync.js +250 -0
  18. package/lib/browser/editor-disk-sync.js.map +1 -0
  19. package/lib/browser/hydranium-file-service.d.ts +44 -0
  20. package/lib/browser/hydranium-file-service.d.ts.map +1 -0
  21. package/lib/browser/hydranium-file-service.js +61 -0
  22. package/lib/browser/hydranium-file-service.js.map +1 -0
  23. package/lib/browser/index.d.ts +5 -0
  24. package/lib/browser/index.d.ts.map +1 -1
  25. package/lib/browser/index.js +5 -0
  26. package/lib/browser/index.js.map +1 -1
  27. package/lib/browser/log-level-preference.d.ts.map +1 -1
  28. package/lib/browser/log-level-preference.js +11 -0
  29. package/lib/browser/log-level-preference.js.map +1 -1
  30. package/lib/browser/memory-diagnostics-contribution.d.ts +1 -1
  31. package/lib/browser/memory-diagnostics-contribution.d.ts.map +1 -1
  32. package/lib/browser/memory-diagnostics-contribution.js +1 -1
  33. package/lib/browser/memory-diagnostics-contribution.js.map +1 -1
  34. package/lib/browser/session-aware-connection-source.d.ts +104 -0
  35. package/lib/browser/session-aware-connection-source.d.ts.map +1 -0
  36. package/lib/browser/session-aware-connection-source.js +193 -0
  37. package/lib/browser/session-aware-connection-source.js.map +1 -0
  38. package/lib/common/clock.d.ts +19 -0
  39. package/lib/common/clock.d.ts.map +1 -0
  40. package/lib/common/clock.js +13 -0
  41. package/lib/common/clock.js.map +1 -0
  42. package/lib/common/connection-resilience-options.d.ts +30 -0
  43. package/lib/common/connection-resilience-options.d.ts.map +1 -0
  44. package/lib/common/connection-resilience-options.js +11 -0
  45. package/lib/common/connection-resilience-options.js.map +1 -0
  46. package/lib/common/framed-socket-write-buffer.d.ts +173 -0
  47. package/lib/common/framed-socket-write-buffer.d.ts.map +1 -0
  48. package/lib/common/framed-socket-write-buffer.js +293 -0
  49. package/lib/common/framed-socket-write-buffer.js.map +1 -0
  50. package/lib/common/inbound-message-sequence.d.ts +56 -0
  51. package/lib/common/inbound-message-sequence.d.ts.map +1 -0
  52. package/lib/common/inbound-message-sequence.js +98 -0
  53. package/lib/common/inbound-message-sequence.js.map +1 -0
  54. package/lib/common/index.d.ts +13 -0
  55. package/lib/common/index.d.ts.map +1 -0
  56. package/lib/common/index.js +32 -0
  57. package/lib/common/index.js.map +1 -0
  58. package/lib/node/abstract-socket-forwarding-connection-handler.d.ts +16 -12
  59. package/lib/node/abstract-socket-forwarding-connection-handler.d.ts.map +1 -1
  60. package/lib/node/abstract-socket-forwarding-connection-handler.js +94 -31
  61. package/lib/node/abstract-socket-forwarding-connection-handler.js.map +1 -1
  62. package/lib/node/index.d.ts +2 -0
  63. package/lib/node/index.d.ts.map +1 -1
  64. package/lib/node/index.js +2 -0
  65. package/lib/node/index.js.map +1 -1
  66. package/lib/node/session-bound-frontend-connection-service.d.ts +122 -0
  67. package/lib/node/session-bound-frontend-connection-service.d.ts.map +1 -0
  68. package/lib/node/session-bound-frontend-connection-service.js +236 -0
  69. package/lib/node/session-bound-frontend-connection-service.js.map +1 -0
  70. package/lib/node/socket-channel-forwarder.d.ts +54 -0
  71. package/lib/node/socket-channel-forwarder.d.ts.map +1 -0
  72. package/lib/node/socket-channel-forwarder.js +95 -0
  73. package/lib/node/socket-channel-forwarder.js.map +1 -0
  74. package/lib/testing/stub-inversify-context.js.map +1 -1
  75. package/lib/testing/stub-output-channel.js.map +1 -1
  76. package/package.json +33 -34
  77. package/src/browser/browser-capture.ts +1 -1
  78. package/src/browser/channel-logger.ts +11 -19
  79. package/src/browser/connection-diagnostics-contribution.ts +146 -0
  80. package/src/browser/connection-reporter.ts +121 -0
  81. package/src/browser/editor-disk-sync.ts +253 -0
  82. package/src/browser/hydranium-file-service.ts +56 -0
  83. package/src/browser/index.ts +5 -0
  84. package/src/browser/log-level-preference.ts +11 -0
  85. package/src/browser/memory-diagnostics-contribution.ts +4 -3
  86. package/src/browser/session-aware-connection-source.ts +205 -0
  87. package/src/common/clock.ts +20 -0
  88. package/src/common/connection-resilience-options.ts +30 -0
  89. package/src/common/framed-socket-write-buffer.ts +345 -0
  90. package/src/common/inbound-message-sequence.ts +102 -0
  91. package/src/common/index.ts +16 -0
  92. package/src/node/abstract-socket-forwarding-connection-handler.ts +85 -36
  93. package/src/node/index.ts +2 -0
  94. package/src/node/session-bound-frontend-connection-service.ts +264 -0
  95. package/src/node/socket-channel-forwarder.ts +101 -0
@@ -0,0 +1,101 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2026 CrossBreeze, EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the MIT License which is available in the project root.
6
+ *
7
+ * SPDX-License-Identifier: MIT
8
+ ********************************************************************************/
9
+
10
+ import { type Clock, SystemClock } from '@hydranium/protocol';
11
+ import { type Channel, Disposable, DisposableCollection, type MessageProvider } from '@theia/core';
12
+ import type * as net from 'node:net';
13
+ import {
14
+ createMessageConnection,
15
+ type Message,
16
+ type MessageConnection,
17
+ SocketMessageReader,
18
+ SocketMessageWriter
19
+ } from 'vscode-jsonrpc/node';
20
+
21
+ /**
22
+ * Relays JSON-RPC messages between a Theia browser-frontend {@link Channel} and
23
+ * a server's TCP socket — the backend half of a head's transport. The server
24
+ * speaks vscode-jsonrpc (Content-Length framed) on the socket; the frontend
25
+ * speaks the same protocol over the channel. This forwarder decodes each side
26
+ * and re-emits on the other.
27
+ *
28
+ * Behaves as `@eclipse-glsp/theia-integration`'s `SocketConnectionForwarder`
29
+ * does, and both heads use it, except that when the channel closes, the writes
30
+ * still queued go out before the socket ends. A page going away sends its last
31
+ * messages and closes its channel in the same tick, and the writer takes
32
+ * several turns per message, so destroying the socket on the close loses them.
33
+ */
34
+ export class SocketChannelForwarder implements Disposable {
35
+ protected readonly toDispose = new DisposableCollection();
36
+ /** The last write to the socket; the writer runs its writes one at a time, so this settles last. */
37
+ protected lastWrite: Promise<void> = Promise.resolve();
38
+ /**
39
+ * How long {@link endSocket} waits for the queued writes before it destroys
40
+ * the socket anyway. Without a bound, a server that stops reading holds the
41
+ * socket open for good, and with it the server's end of the connection.
42
+ */
43
+ protected readonly flushTimeoutMs: number = 10_000;
44
+
45
+ constructor(
46
+ protected readonly channel: Channel,
47
+ protected readonly socket: net.Socket,
48
+ /** Times {@link flushTimeoutMs}. */
49
+ protected readonly clock: Clock = new SystemClock()
50
+ ) {
51
+ const reader = new SocketMessageReader(socket);
52
+ const writer = new SocketMessageWriter(socket);
53
+ // Never listens, so it handles no message and has nothing to log.
54
+ // ast-grep-ignore: connection-without-logger
55
+ const connection = createMessageConnection(reader, writer);
56
+ // Nothing here destroys the socket directly. `SocketMessageWriter.dispose()`
57
+ // destroys it itself, which covers both `dispose` and `endSocket`; and
58
+ // `connection.onClose` fires only from the reader's or writer's own close,
59
+ // which for a socket means the socket has already gone — so a destroy
60
+ // handler there is downstream of the effect it would be trying to cause.
61
+ this.toDispose.pushAll([
62
+ reader.listen(message => this.writeToChannel(message)),
63
+ channel.onMessage(provider => {
64
+ // A failed write means the socket is gone, which its own close reports.
65
+ this.lastWrite = writer.write(this.decodeChannelMessage(provider)).catch(() => undefined);
66
+ }),
67
+ channel.onClose(() => void this.endSocket(connection)),
68
+ connection.onClose(() => channel.close()),
69
+ Disposable.create(() => {
70
+ channel.close();
71
+ connection.dispose();
72
+ })
73
+ ]);
74
+ }
75
+
76
+ /**
77
+ * Dispose `connection`, which destroys the socket, once the writes queued
78
+ * before the channel closed are out, or {@link flushTimeoutMs} has passed. A
79
+ * write has settled once the socket handed its bytes to the OS, and
80
+ * destroying the socket then loses nothing.
81
+ */
82
+ protected async endSocket(connection: MessageConnection): Promise<void> {
83
+ await this.clock.raceTimer(this.lastWrite, this.flushTimeoutMs);
84
+ connection.dispose();
85
+ }
86
+
87
+ protected decodeChannelMessage(provider: MessageProvider): Message {
88
+ const buffer = provider().readBytes();
89
+ return JSON.parse(new TextDecoder().decode(buffer)) as Message;
90
+ }
91
+
92
+ protected writeToChannel(message: Message): void {
93
+ const writeBuffer = this.channel.getWriteBuffer();
94
+ writeBuffer.writeBytes(new TextEncoder().encode(JSON.stringify(message)));
95
+ writeBuffer.commit();
96
+ }
97
+
98
+ dispose(): void {
99
+ this.toDispose.dispose();
100
+ }
101
+ }