@hydranium/client-theia 1.0.0-next.39 → 1.0.0-next.390
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -81
- package/lib/browser/browser-capture.js.map +1 -1
- package/lib/browser/channel-logger.d.ts +4 -3
- package/lib/browser/channel-logger.d.ts.map +1 -1
- package/lib/browser/channel-logger.js +11 -19
- package/lib/browser/channel-logger.js.map +1 -1
- package/lib/browser/connection-diagnostics-contribution.d.ts +73 -0
- package/lib/browser/connection-diagnostics-contribution.d.ts.map +1 -0
- package/lib/browser/connection-diagnostics-contribution.js +162 -0
- package/lib/browser/connection-diagnostics-contribution.js.map +1 -0
- package/lib/browser/connection-reporter.d.ts +57 -0
- package/lib/browser/connection-reporter.d.ts.map +1 -0
- package/lib/browser/connection-reporter.js +104 -0
- package/lib/browser/connection-reporter.js.map +1 -0
- package/lib/browser/editor-disk-sync.d.ts +142 -0
- package/lib/browser/editor-disk-sync.d.ts.map +1 -0
- package/lib/browser/editor-disk-sync.js +250 -0
- package/lib/browser/editor-disk-sync.js.map +1 -0
- package/lib/browser/hydranium-file-service.d.ts +44 -0
- package/lib/browser/hydranium-file-service.d.ts.map +1 -0
- package/lib/browser/hydranium-file-service.js +61 -0
- package/lib/browser/hydranium-file-service.js.map +1 -0
- package/lib/browser/index.d.ts +5 -0
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +5 -0
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/log-level-preference.d.ts.map +1 -1
- package/lib/browser/log-level-preference.js +11 -0
- package/lib/browser/log-level-preference.js.map +1 -1
- package/lib/browser/memory-diagnostics-contribution.d.ts +1 -1
- package/lib/browser/memory-diagnostics-contribution.d.ts.map +1 -1
- package/lib/browser/memory-diagnostics-contribution.js +1 -1
- package/lib/browser/memory-diagnostics-contribution.js.map +1 -1
- package/lib/browser/session-aware-connection-source.d.ts +104 -0
- package/lib/browser/session-aware-connection-source.d.ts.map +1 -0
- package/lib/browser/session-aware-connection-source.js +193 -0
- package/lib/browser/session-aware-connection-source.js.map +1 -0
- package/lib/common/clock.d.ts +19 -0
- package/lib/common/clock.d.ts.map +1 -0
- package/lib/common/clock.js +13 -0
- package/lib/common/clock.js.map +1 -0
- package/lib/common/connection-resilience-options.d.ts +30 -0
- package/lib/common/connection-resilience-options.d.ts.map +1 -0
- package/lib/common/connection-resilience-options.js +11 -0
- package/lib/common/connection-resilience-options.js.map +1 -0
- package/lib/common/framed-socket-write-buffer.d.ts +173 -0
- package/lib/common/framed-socket-write-buffer.d.ts.map +1 -0
- package/lib/common/framed-socket-write-buffer.js +293 -0
- package/lib/common/framed-socket-write-buffer.js.map +1 -0
- package/lib/common/inbound-message-sequence.d.ts +56 -0
- package/lib/common/inbound-message-sequence.d.ts.map +1 -0
- package/lib/common/inbound-message-sequence.js +98 -0
- package/lib/common/inbound-message-sequence.js.map +1 -0
- package/lib/common/index.d.ts +13 -0
- package/lib/common/index.d.ts.map +1 -0
- package/lib/common/index.js +32 -0
- package/lib/common/index.js.map +1 -0
- package/lib/node/abstract-socket-forwarding-connection-handler.d.ts +16 -12
- package/lib/node/abstract-socket-forwarding-connection-handler.d.ts.map +1 -1
- package/lib/node/abstract-socket-forwarding-connection-handler.js +94 -31
- package/lib/node/abstract-socket-forwarding-connection-handler.js.map +1 -1
- package/lib/node/index.d.ts +2 -0
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +2 -0
- package/lib/node/index.js.map +1 -1
- package/lib/node/session-bound-frontend-connection-service.d.ts +122 -0
- package/lib/node/session-bound-frontend-connection-service.d.ts.map +1 -0
- package/lib/node/session-bound-frontend-connection-service.js +236 -0
- package/lib/node/session-bound-frontend-connection-service.js.map +1 -0
- package/lib/node/socket-channel-forwarder.d.ts +54 -0
- package/lib/node/socket-channel-forwarder.d.ts.map +1 -0
- package/lib/node/socket-channel-forwarder.js +95 -0
- package/lib/node/socket-channel-forwarder.js.map +1 -0
- package/lib/testing/stub-inversify-context.js.map +1 -1
- package/lib/testing/stub-output-channel.js.map +1 -1
- package/package.json +33 -34
- package/src/browser/browser-capture.ts +1 -1
- package/src/browser/channel-logger.ts +11 -19
- package/src/browser/connection-diagnostics-contribution.ts +146 -0
- package/src/browser/connection-reporter.ts +121 -0
- package/src/browser/editor-disk-sync.ts +253 -0
- package/src/browser/hydranium-file-service.ts +56 -0
- package/src/browser/index.ts +5 -0
- package/src/browser/log-level-preference.ts +11 -0
- package/src/browser/memory-diagnostics-contribution.ts +4 -3
- package/src/browser/session-aware-connection-source.ts +205 -0
- package/src/common/clock.ts +20 -0
- package/src/common/connection-resilience-options.ts +30 -0
- package/src/common/framed-socket-write-buffer.ts +345 -0
- package/src/common/inbound-message-sequence.ts +102 -0
- package/src/common/index.ts +16 -0
- package/src/node/abstract-socket-forwarding-connection-handler.ts +85 -36
- package/src/node/index.ts +2 -0
- package/src/node/session-bound-frontend-connection-service.ts +264 -0
- 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
|
+
}
|