@hydranium/client-theia 1.0.0-next.22 → 1.0.0-next.220

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 (94) hide show
  1. package/README.md +49 -12
  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 +10 -7
  6. package/lib/browser/channel-logger.js.map +1 -1
  7. package/lib/browser/connection-diagnostics-contribution.d.ts +69 -0
  8. package/lib/browser/connection-diagnostics-contribution.d.ts.map +1 -0
  9. package/lib/browser/connection-diagnostics-contribution.js +153 -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 +40 -4
  31. package/lib/browser/memory-diagnostics-contribution.d.ts.map +1 -1
  32. package/lib/browser/memory-diagnostics-contribution.js +161 -31
  33. package/lib/browser/memory-diagnostics-contribution.js.map +1 -1
  34. package/lib/browser/session-aware-connection-source.d.ts +101 -0
  35. package/lib/browser/session-aware-connection-source.d.ts.map +1 -0
  36. package/lib/browser/session-aware-connection-source.js +184 -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 +12 -8
  59. package/lib/node/abstract-socket-forwarding-connection-handler.d.ts.map +1 -1
  60. package/lib/node/abstract-socket-forwarding-connection-handler.js +70 -13
  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 +118 -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 +224 -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 +31 -32
  77. package/src/browser/channel-logger.ts +10 -7
  78. package/src/browser/connection-diagnostics-contribution.ts +142 -0
  79. package/src/browser/connection-reporter.ts +121 -0
  80. package/src/browser/editor-disk-sync.ts +253 -0
  81. package/src/browser/hydranium-file-service.ts +56 -0
  82. package/src/browser/index.ts +5 -0
  83. package/src/browser/log-level-preference.ts +11 -0
  84. package/src/browser/memory-diagnostics-contribution.ts +268 -45
  85. package/src/browser/session-aware-connection-source.ts +196 -0
  86. package/src/common/clock.ts +20 -0
  87. package/src/common/connection-resilience-options.ts +30 -0
  88. package/src/common/framed-socket-write-buffer.ts +345 -0
  89. package/src/common/inbound-message-sequence.ts +102 -0
  90. package/src/common/index.ts +16 -0
  91. package/src/node/abstract-socket-forwarding-connection-handler.ts +61 -15
  92. package/src/node/index.ts +2 -0
  93. package/src/node/session-bound-frontend-connection-service.ts +260 -0
  94. package/src/node/socket-channel-forwarder.ts +101 -0
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+ /********************************************************************************
3
+ * Copyright (c) 2026 CrossBreeze, EclipseSource and others.
4
+ *
5
+ * This program and the accompanying materials are made available under the
6
+ * terms of the MIT License which is available in the project root.
7
+ *
8
+ * SPDX-License-Identifier: MIT
9
+ ********************************************************************************/
10
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
11
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
12
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
13
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
14
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.SessionAwareConnectionSource = void 0;
18
+ exports.bindConnectionResilience = bindConnectionResilience;
19
+ const ws_connection_source_1 = require("@theia/core/lib/browser/messaging/ws-connection-source");
20
+ const disposable_1 = require("@theia/core/lib/common/disposable");
21
+ const channel_1 = require("@theia/core/lib/common/message-rpc/channel");
22
+ const uint8_array_message_buffer_1 = require("@theia/core/lib/common/message-rpc/uint8-array-message-buffer");
23
+ const connection_management_1 = require("@theia/core/lib/common/messaging/connection-management");
24
+ const inversify_1 = require("@theia/core/shared/inversify");
25
+ const socket_write_buffer_1 = require("@theia/core/lib/common/messaging/socket-write-buffer");
26
+ const framed_socket_write_buffer_1 = require("../common/framed-socket-write-buffer");
27
+ const inbound_message_sequence_1 = require("../common/inbound-message-sequence");
28
+ /**
29
+ * Sends a message only once the server has confirmed the session, and only
30
+ * behind anything already queued.
31
+ *
32
+ * Theia sends straight away when `socket.connected` is true and buffers
33
+ * otherwise. The gap is that reconnecting sets that flag immediately, while the
34
+ * session is only confirmed a round trip later. A message produced in that
35
+ * window either jumps ahead of older messages still waiting in the buffer, or,
36
+ * if nothing was waiting, goes out on a socket whose channel the server has not
37
+ * attached yet and is discarded by a peer with no listener for it.
38
+ *
39
+ * Losing one or reordering them is equally unrecoverable for anything that
40
+ * applies messages by position. Theia's plugin host keeps a line-indexed copy of
41
+ * every open document, so a single late or missing edit leaves that copy wrong
42
+ * for good, and the next edit past its end fails.
43
+ *
44
+ * The server side needs no equivalent: it adopts its socket and flushes in one
45
+ * synchronous step, so it has no window of this kind.
46
+ */
47
+ let SessionAwareConnectionSource = class SessionAwareConnectionSource extends ws_connection_source_1.WebSocketConnectionSource {
48
+ /**
49
+ * Whether the server has confirmed, on the socket in use right now, that it
50
+ * still holds this frontend's session. A connected socket is not enough:
51
+ * until the handshake is answered the server has not attached its channel to
52
+ * this socket, and a message sent meanwhile reaches a peer with no listener
53
+ * for it and is discarded without a trace.
54
+ */
55
+ sessionResumed = false;
56
+ sessionListenersAttached = false;
57
+ /**
58
+ * Every connect starts a socket the server has not confirmed yet, including
59
+ * the reconnects socket.io performs on its own. Resetting here rather than on
60
+ * disconnect also covers a connect that follows no clean disconnect event.
61
+ */
62
+ handleSocketConnected() {
63
+ this.trackSessionState();
64
+ this.sessionResumed = false;
65
+ super.handleSocketConnected();
66
+ }
67
+ /**
68
+ * Watches the connection handshake for its outcome.
69
+ *
70
+ * Attached once, to the socket socket.io reuses across reconnects, and before
71
+ * the base class adds its own per-negotiation listeners — so this has already
72
+ * recorded the outcome by the time the base class reacts to it by flushing.
73
+ */
74
+ trackSessionState() {
75
+ if (this.sessionListenersAttached) {
76
+ return;
77
+ }
78
+ this.sessionListenersAttached = true;
79
+ this.socket.on(connection_management_1.ConnectionManagementMessages.INITIAL_CONNECT, () => {
80
+ this.sessionResumed = true;
81
+ });
82
+ this.socket.on(connection_management_1.ConnectionManagementMessages.RECONNECT, (hasConnection) => {
83
+ this.sessionResumed = hasConnection;
84
+ });
85
+ this.socket.on(inbound_message_sequence_1.ACKNOWLEDGEMENT_EVENT, (sequence) => {
86
+ if (typeof sequence === 'number') {
87
+ this.framedBuffer.acknowledge(sequence);
88
+ }
89
+ });
90
+ }
91
+ /** Whether a message may go out now, as opposed to waiting in the buffer. */
92
+ get canSend() {
93
+ return this.socket.connected && this.sessionResumed;
94
+ }
95
+ /**
96
+ * Copied from Theia apart from the duplicate check on receipt and the `onCommit` body, because
97
+ * the base builds both callbacks inline and exposes no narrower seam. Re-diff when the supported
98
+ * range moves.
99
+ *
100
+ * Called once per session, so the receive-side state starts afresh with the server's numbering.
101
+ */
102
+ createChannel() {
103
+ const toDispose = new disposable_1.DisposableCollection();
104
+ const inbound = new inbound_message_sequence_1.InboundMessageSequence(sequence => this.socket.emit(inbound_message_sequence_1.ACKNOWLEDGEMENT_EVENT, sequence));
105
+ toDispose.push(disposable_1.Disposable.create(() => inbound.dispose()));
106
+ const messageHandler = (data, sequence) => {
107
+ this.onIncomingMessageActivityEmitter.fire();
108
+ if (typeof sequence === 'number') {
109
+ this.framedBuffer.markPeerDeduplicates();
110
+ }
111
+ if (!inbound.accept(sequence, data.byteLength)) {
112
+ return;
113
+ }
114
+ if (this.currentChannel) {
115
+ // socket.io hands binary over as ArrayBuffer in the browser.
116
+ const buffer = data instanceof ArrayBuffer ? new Uint8Array(data) : data;
117
+ this.currentChannel.onMessageEmitter.fire(() => new uint8_array_message_buffer_1.Uint8ArrayReadBuffer(buffer));
118
+ }
119
+ };
120
+ this.socket.on('message', messageHandler);
121
+ toDispose.push(disposable_1.Disposable.create(() => this.socket.off('message', messageHandler)));
122
+ return new channel_1.ForwardingChannel('any', () => toDispose.dispose(), () => {
123
+ const result = new uint8_array_message_buffer_1.Uint8ArrayWriteBuffer();
124
+ // Says only whether the session can carry a message; the buffer decides whether it may
125
+ // go ahead of anything already waiting.
126
+ result.onCommit(buffer => this.framedBuffer.sendOrQueue(this.canSend ? this.socket : undefined, buffer));
127
+ return result;
128
+ });
129
+ }
130
+ /** Fires when the buffer runs out of room, so an adopter can say so rather than just stopping. */
131
+ get onBufferOverflow() {
132
+ return this.framedBuffer.onOverflow;
133
+ }
134
+ /**
135
+ * The write buffer Theia injected into the base class.
136
+ *
137
+ * Reached through a structural view rather than as `this.writeBuffer`,
138
+ * because that member is `private` in Theia 1.70 and only became `protected`
139
+ * in 1.71 — and this package compiles against the whole range. The view
140
+ * asserts nothing the versions disagree about: the field is there in both,
141
+ * holding whatever `SocketWriteBuffer` is bound, and the check below is what
142
+ * establishes it is ours.
143
+ */
144
+ get framedBuffer() {
145
+ const buffer = this.writeBuffer;
146
+ if (!(buffer instanceof framed_socket_write_buffer_1.FramedSocketWriteBuffer)) {
147
+ throw new Error('SessionAwareConnectionSource requires FramedSocketWriteBuffer to be bound');
148
+ }
149
+ return buffer;
150
+ }
151
+ };
152
+ exports.SessionAwareConnectionSource = SessionAwareConnectionSource;
153
+ exports.SessionAwareConnectionSource = SessionAwareConnectionSource = __decorate([
154
+ (0, inversify_1.injectable)()
155
+ ], SessionAwareConnectionSource);
156
+ /**
157
+ * Replaces the frontend pieces that decide how outgoing messages survive a
158
+ * reconnect. Every one of them rebinds something Theia's
159
+ * `messagingFrontendModule` already bound, so this belongs in a module loaded
160
+ * into the same container.
161
+ *
162
+ * It must be a `frontendPreload` module rather than a normal frontend module:
163
+ * Theia's preloader resolves `WebSocketConnectionSource` (and with it the write
164
+ * buffer) while loading i18n and OS settings, which happens before any frontend
165
+ * module is loaded. A rebind there would come too late — the instances would
166
+ * already exist. All `frontendPreload` modules, by contrast, are loaded before
167
+ * the preloader constructs anything.
168
+ *
169
+ * Does nothing but warn on a Theia too old to expose the buffer binding, so the
170
+ * package keeps one supported range rather than splitting its floor for this
171
+ * feature. Returns whether the hardening was installed, for an adopter that
172
+ * wants to branch on it.
173
+ */
174
+ function bindConnectionResilience(isBound, rebind, options = {}) {
175
+ if (!(0, framed_socket_write_buffer_1.supportsConnectionResilience)(isBound)) {
176
+ (0, framed_socket_write_buffer_1.warnConnectionResilienceUnavailable)('frontend');
177
+ return false;
178
+ }
179
+ // Scopes are kept as Theia declares them: one buffer per connection source, one shared socket owner.
180
+ rebind(socket_write_buffer_1.SocketWriteBuffer).toDynamicValue(() => (0, framed_socket_write_buffer_1.createFramedSocketWriteBuffer)(options));
181
+ rebind(ws_connection_source_1.WebSocketConnectionSource).to(SessionAwareConnectionSource).inSingletonScope();
182
+ return true;
183
+ }
184
+ //# sourceMappingURL=session-aware-connection-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-aware-connection-source.js","sourceRoot":"","sources":["../../src/browser/session-aware-connection-source.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;AAElF,iGAAmG;AACnG,kEAAqF;AAErF,wEAAqG;AACr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IACvF,MAAM,CAAC,gDAAyB,CAAC,CAAC,EAAE,CAAC,4BAA4B,CAAC,CAAC,gBAAgB,EAAE,CAAC;IACtF,OAAO,IAAI,CAAC;AACf,CAAC"}
@@ -0,0 +1,19 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2026 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
+ import type { Clock as ProtocolClock } from '@hydranium/protocol';
10
+ /**
11
+ * The protocol's `Clock`, as a Theia container binds it: type and injection
12
+ * token under one identifier, as Theia declares its own. The framework's
13
+ * frontend and backend classes that time or bound something inject it as
14
+ * optional, and use a `SystemClock` when the container binds none, so a
15
+ * container can supply another clock.
16
+ */
17
+ export type Clock = ProtocolClock;
18
+ export declare const Clock: unique symbol;
19
+ //# sourceMappingURL=clock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clock.d.ts","sourceRoot":"","sources":["../../src/common/clock.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,KAAK,EAAE,KAAK,IAAI,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAElE;;;;;;GAMG;AACH,MAAM,MAAM,KAAK,GAAG,aAAa,CAAC;AAClC,eAAO,MAAM,KAAK,eAAkB,CAAC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ /********************************************************************************
3
+ * Copyright (c) 2026 EclipseSource and others.
4
+ *
5
+ * This program and the accompanying materials are made available under the
6
+ * terms of the MIT License which is available in the project root.
7
+ *
8
+ * SPDX-License-Identifier: MIT
9
+ ********************************************************************************/
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.Clock = void 0;
12
+ exports.Clock = Symbol('Clock');
13
+ //# sourceMappingURL=clock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clock.js","sourceRoot":"","sources":["../../src/common/clock.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAYrE,QAAA,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC"}
@@ -0,0 +1,30 @@
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
+ * Options for the `bindConnectionResilience` helper each tier exports.
11
+ *
12
+ * Lives in `common` rather than beside either helper so the server entry can
13
+ * name the type without importing the browser module, and the other way round.
14
+ */
15
+ export interface ConnectionResilienceOptions {
16
+ /**
17
+ * Size of the buffer holding messages while the socket is down, in bytes.
18
+ * Defaults to Theia's own limit. It decides how long an outage can last
19
+ * before changes start being rejected, so a deployment on a poor network
20
+ * trades memory for tolerance here.
21
+ */
22
+ readonly bufferBytes?: number;
23
+ /**
24
+ * How much each side keeps of what it sent and the peer has not acknowledged
25
+ * yet, in bytes. Past it the copies are discarded and a dropped connection
26
+ * loses them, so it bounds what a peer that never acknowledges can cost.
27
+ */
28
+ readonly unacknowledgedBytes?: number;
29
+ }
30
+ //# sourceMappingURL=connection-resilience-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-resilience-options.d.ts","sourceRoot":"","sources":["../../src/common/connection-resilience-options.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF;;;;;GAKG;AACH,MAAM,WAAW,2BAA2B;IACzC;;;;;OAKG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;OAIG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC;CACxC"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ /********************************************************************************
3
+ * Copyright (c) 2026 CrossBreeze, EclipseSource and others.
4
+ *
5
+ * This program and the accompanying materials are made available under the
6
+ * terms of the MIT License which is available in the project root.
7
+ *
8
+ * SPDX-License-Identifier: MIT
9
+ ********************************************************************************/
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ //# sourceMappingURL=connection-resilience-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-resilience-options.js","sourceRoot":"","sources":["../../src/common/connection-resilience-options.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF"}
@@ -0,0 +1,173 @@
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
+ import { Emitter, type Event } from '@theia/core/lib/common/event';
10
+ import { SocketWriteBuffer } from '@theia/core/lib/common/messaging/socket-write-buffer';
11
+ import { type ConnectionResilienceOptions } from './connection-resilience-options';
12
+ /**
13
+ * Prefix on every connection log line, deliberately shared by the browser and the
14
+ * server so one pattern greps a console and a pod log at once.
15
+ */
16
+ export declare const CONNECTION_LOG_PREFIX = "[connection]";
17
+ /**
18
+ * The part of a socket this buffer uses. Narrower than the socket type Theia
19
+ * declares, which keeps the dependency honest and lets the class be tested
20
+ * without a connection.
21
+ */
22
+ export interface MessageSink {
23
+ /** `sequence` travels as a second socket.io argument, which a reader that does not expect it ignores. */
24
+ send(data: Uint8Array, sequence: number): void;
25
+ }
26
+ /**
27
+ * Reported when the buffer runs out of room. The message that did not fit is
28
+ * rejected, and so is every further one for as long as the buffer stays full.
29
+ * Reconnecting drains it and sending resumes, but whatever was rejected
30
+ * meanwhile is gone, so the two sides no longer agree about the session.
31
+ */
32
+ export interface ConnectionBufferOverflow {
33
+ /** Messages held when the limit was reached. */
34
+ readonly messages: number;
35
+ /** Bytes held when the limit was reached. */
36
+ readonly bytes: number;
37
+ /** The limit in force, so a reader can tell what to raise it to. */
38
+ readonly maxBytes: number;
39
+ }
40
+ /**
41
+ * Holds messages while the peer is away and re-sends them when it returns.
42
+ *
43
+ * Theia copies them into one growing byte array and flushes that with a single
44
+ * `send`. A websocket delivers whole messages rather than a byte stream, so
45
+ * Theia's encoding adds no length prefix and every reader assumes one delivery
46
+ * is one message. The concatenated flush breaks that assumption: the reader
47
+ * decodes the first message and throws away the bytes behind it.
48
+ *
49
+ * Changed here: one entry per message, sent one at a time, so each arrives as
50
+ * its own delivery. The buffer also decides whether a message may go out
51
+ * directly — see {@link sendOrQueue} — because a caller that decides for itself
52
+ * is how messages end up overtaking a backlog.
53
+ *
54
+ * Unchanged from Theia: exceeding the limit rejects the message rather than
55
+ * dropping something silently. The limit is settable, since the right value
56
+ * depends on how long an outage has to survive.
57
+ *
58
+ * Added here: every message sent is numbered and kept until the peer
59
+ * acknowledges it, and {@link flush} resends what is still unacknowledged ahead
60
+ * of the backlog. A socket whose far end died unnoticed still accepts writes, so
61
+ * a message is not delivered just because it was sent.
62
+ *
63
+ * Logging goes to `console` rather than through a `Logger`. On the browser side
64
+ * Theia's preloader builds this before any Output channel exists, so there is
65
+ * nothing else to write to; the {@link CONNECTION_LOG_PREFIX} keeps the lines
66
+ * findable on both sides.
67
+ */
68
+ export declare class FramedSocketWriteBuffer extends SocketWriteBuffer {
69
+ /** Theia's fixed limit, kept as the default. */
70
+ static readonly DEFAULT_MAX_BYTES: number;
71
+ /**
72
+ * Settable so a deployment can trade memory for longer outages.
73
+ *
74
+ * Consulted directly rather than through the base class's `maxBufferSize`,
75
+ * which does not exist before Theia 1.71 — an `override` of it would not
76
+ * compile against the oldest release this package supports. Nothing is lost:
77
+ * `buffer`, `flush` and `drain` are all replaced here, so the base's own
78
+ * limit is never reached.
79
+ */
80
+ maxBytes: number;
81
+ /** Kept copies past this are discarded, so a peer that never acknowledges cannot grow them without bound. */
82
+ static readonly DEFAULT_MAX_UNACKNOWLEDGED_BYTES: number;
83
+ /**
84
+ * Separate from {@link maxBytes}, which counts only what is produced while
85
+ * the peer is away: copies kept on a healthy connection must not use up the
86
+ * room an outage needs.
87
+ */
88
+ maxUnacknowledgedBytes: number;
89
+ protected pending: Uint8Array[];
90
+ protected pendingBytes: number;
91
+ protected overflowReported: boolean;
92
+ protected readonly onOverflowEmitter: Emitter<ConnectionBufferOverflow>;
93
+ protected nextSequence: number;
94
+ /** Oldest first: {@link acknowledge} stops at the first entry the peer has not accepted. */
95
+ protected unacknowledged: {
96
+ readonly sequence: number;
97
+ readonly data: Uint8Array;
98
+ }[];
99
+ protected unacknowledgedBytes: number;
100
+ protected unacknowledgedOverflowReported: boolean;
101
+ /**
102
+ * Whether the peer drops a message it already has. One without the hardening
103
+ * applies a resent message a second time, so nothing is resent until the
104
+ * peer has shown otherwise.
105
+ */
106
+ protected peerDeduplicates: boolean;
107
+ /** Fires once per outage when the limit is reached. */
108
+ get onOverflow(): Event<ConnectionBufferOverflow>;
109
+ /**
110
+ * Sends `data` now only if nothing is waiting, and queues it otherwise.
111
+ *
112
+ * Callers say whether the peer is ready for a message; the buffer decides
113
+ * whether it may go ahead of one already waiting. Splitting it this way is
114
+ * the point: a caller that answers both questions from one flag is how a
115
+ * fresh message ends up overtaking a backlog.
116
+ */
117
+ sendOrQueue(socket: MessageSink | undefined, data: Uint8Array): void;
118
+ buffer(data: Uint8Array): void;
119
+ /**
120
+ * Kept only once `send` returns: a message whose send threw stays in the
121
+ * backlog, and keeping it as well would send it again under a second number,
122
+ * which the receiver cannot recognise as a duplicate.
123
+ */
124
+ protected send(socket: MessageSink, data: Uint8Array): void;
125
+ protected keep(sequence: number, data: Uint8Array): void;
126
+ /**
127
+ * Records that the peer numbers its messages, which only a peer that also
128
+ * drops duplicates does, so resending to it is safe.
129
+ */
130
+ markPeerDeduplicates(): void;
131
+ /** Releases every kept message numbered up to `sequence`, which the peer has accepted. */
132
+ acknowledge(sequence: number): void;
133
+ /**
134
+ * Resends what the peer has not acknowledged, under the same numbers, then
135
+ * sends the backlog. Some of the resent messages may have arrived already;
136
+ * the receiver recognises them by number and drops them.
137
+ *
138
+ * Resends only to a peer known to drop duplicates, and otherwise discards the
139
+ * copies, leaving any message lost with the old socket lost.
140
+ */
141
+ flush(socket: MessageSink): void;
142
+ drain(): void;
143
+ /** Whether messages are still waiting to go out. */
144
+ get hasBacklog(): boolean;
145
+ protected reportOverflow(): void;
146
+ /** Also discards the kept copies: a drain ends the session, and resending them would replay it into the next one. */
147
+ protected reset(): void;
148
+ }
149
+ /** Named in the warning a skipped install emits, so the reader is told what to upgrade to. */
150
+ export declare const REQUIRED_THEIA_HINT = "@theia/core 1.71 or newer";
151
+ /**
152
+ * Whether this Theia exposes the seam the reconnect hardening replaces.
153
+ *
154
+ * Theia only began binding {@link SocketWriteBuffer} in 1.71; before that each
155
+ * connection built one privately, so there is no binding to rebind and no way
156
+ * in. Every other API involved has been there throughout, which makes this one
157
+ * probe the whole compatibility question — and it is a binding check rather
158
+ * than a version parse, so it answers about the container actually in front of
159
+ * us instead of a number that may have been overridden or vendored.
160
+ *
161
+ * Callers that get `false` must leave Theia's own wiring alone: rebinding half
162
+ * of it would be worse than not rebinding at all.
163
+ */
164
+ export declare function supportsConnectionResilience(isBound: (identifier: typeof SocketWriteBuffer) => boolean): boolean;
165
+ /**
166
+ * The warning a skipped install emits. Says what is lost rather than only what
167
+ * is missing: the failures this guards against are silent, so an adopter who
168
+ * never sees this line has no other way to learn the guard is absent.
169
+ */
170
+ export declare function warnConnectionResilienceUnavailable(tier: 'frontend' | 'backend'): void;
171
+ /** Builds a buffer with the configured limits, or the defaults for any not configured. */
172
+ export declare function createFramedSocketWriteBuffer(options?: ConnectionResilienceOptions): FramedSocketWriteBuffer;
173
+ //# sourceMappingURL=framed-socket-write-buffer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"framed-socket-write-buffer.d.ts","sourceRoot":"","sources":["../../src/common/framed-socket-write-buffer.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAA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