@myrialabs/clopen 0.4.34 → 0.4.35
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/backend/auth/permissions.ts +7 -0
- package/backend/containers/actions.ts +316 -0
- package/backend/containers/disk-usage.test.ts +68 -0
- package/backend/containers/disk-usage.ts +170 -0
- package/backend/containers/logs.ts +335 -0
- package/backend/containers/monitor.ts +410 -0
- package/backend/containers/parse.test.ts +599 -0
- package/backend/containers/parse.ts +905 -0
- package/backend/containers/port-index.test.ts +91 -0
- package/backend/containers/port-index.ts +198 -0
- package/backend/containers/prune-job.test.ts +148 -0
- package/backend/containers/prune-job.ts +129 -0
- package/backend/containers/pty-backend.ts +337 -0
- package/backend/containers/pty.ts +114 -0
- package/backend/containers/runtime.ts +218 -0
- package/backend/containers/scan.ts +293 -0
- package/backend/files/file-watcher.test.ts +105 -0
- package/backend/files/file-watcher.ts +45 -1
- package/backend/git/git-service.test.ts +33 -0
- package/backend/git/git-service.ts +7 -3
- package/backend/git/nested-repos.test.ts +292 -1
- package/backend/git/nested-repos.ts +330 -17
- package/backend/{ports → host}/runner.ts +19 -10
- package/backend/index.ts +11 -2
- package/backend/ports/attribute.ts +1 -1
- package/backend/ports/kill.ts +1 -1
- package/backend/ports/monitor.ts +1 -1
- package/backend/ports/processes.ts +1 -1
- package/backend/ports/scan-host.ts +77 -8
- package/backend/ports/scan.test.ts +1 -1
- package/backend/ports/scan.ts +1 -1
- package/backend/ports/ssh-lineage.ts +1 -1
- package/backend/preview/browser/browser-video-capture.ts +84 -31
- package/backend/ws/containers/actions.ts +156 -0
- package/backend/ws/containers/index.ts +43 -0
- package/backend/ws/containers/list.ts +146 -0
- package/backend/ws/containers/logs.ts +43 -0
- package/backend/ws/containers/tunnel.ts +101 -0
- package/backend/ws/git/log.ts +3 -1
- package/backend/ws/git/status.ts +37 -27
- package/backend/ws/index.ts +2 -0
- package/backend/ws/message-rate-limiter.test.ts +45 -0
- package/backend/ws/message-rate-limiter.ts +34 -3
- package/backend/ws/ssh/connections.ts +8 -0
- package/backend/ws/system/device-info.ts +99 -43
- package/dist/assets/{index-vW2RpdHu.js → index-B0iIhSO9.js} +1 -1
- package/dist/assets/{index-gGTMFUa8.js → index-BRJqss6F.js} +1 -1
- package/dist/assets/main-Buko4D0t.css +1 -0
- package/dist/assets/{main-ZCojSzvW.js → main-C_iGUZyL.js} +467 -449
- package/dist/index.html +2 -2
- package/dist/manifest.json +9 -2
- package/package.json +1 -1
- package/shared/types/containers/container.ts +366 -0
- package/shared/types/containers/index.ts +5 -0
- package/shared/types/host/index.ts +18 -0
- package/shared/types/ports/port.ts +47 -9
- package/shared/utils/logger.ts +2 -0
- package/shared/utils/ws-client.ts +67 -12
- package/shared/utils/ws-server.ts +64 -13
- package/dist/assets/main-CYCMEbXB.css +0 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Containers — the shell tunnel.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors backend/ws/ssh/tunnel.ts: PtyKit's wire protocol rides Clopen's
|
|
5
|
+
* app-wide socket on `containers:pty` / `containers:pty-out`, with one embedded
|
|
6
|
+
* PtyKit connection per Clopen connection.
|
|
7
|
+
*
|
|
8
|
+
* As with the SSH tunnel, the spawn target is stamped here rather than taken
|
|
9
|
+
* from the client. The namespace is the only thing the client says about what
|
|
10
|
+
* it wants, `authorize` has already checked that it may have it, and the target
|
|
11
|
+
* is derived from that same namespace — so naming one container in the
|
|
12
|
+
* namespace and another in the payload cannot open a shell anywhere.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { t } from 'elysia';
|
|
16
|
+
import { createRouter } from '$shared/utils/ws-server';
|
|
17
|
+
import type { WSConnection } from '$shared/utils/ws-server';
|
|
18
|
+
import type { PtyKitConnection } from '@myrialabs/ptykit/server';
|
|
19
|
+
import type { WireFrame } from '@myrialabs/ptykit';
|
|
20
|
+
import { ws } from '$backend/utils/ws';
|
|
21
|
+
import { encodeContainerTarget } from '../../containers/pty-backend';
|
|
22
|
+
import { containerPtyKitServer, rememberNamespace, targetFromNamespace } from '../../containers/pty';
|
|
23
|
+
import { debug } from '$shared/utils/logger';
|
|
24
|
+
|
|
25
|
+
/** One embedded PtyKit connection per Clopen ws connection (by stable id). */
|
|
26
|
+
const containerPtyConnections = new Map<string, PtyKitConnection>();
|
|
27
|
+
|
|
28
|
+
function getContainerPtyConnection(conn: WSConnection): PtyKitConnection {
|
|
29
|
+
const connId = ws.getConnectionId(conn);
|
|
30
|
+
if (!connId) {
|
|
31
|
+
throw new Error('Connection not registered');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const existing = containerPtyConnections.get(connId);
|
|
35
|
+
if (existing) return existing;
|
|
36
|
+
|
|
37
|
+
const userId = ws.getUserId(conn);
|
|
38
|
+
const isAdmin = ws.getRole(conn) === 'admin';
|
|
39
|
+
const ptyConn = containerPtyKitServer.createConnection({
|
|
40
|
+
data: { userId, isAdmin, connId },
|
|
41
|
+
send: (frame) => {
|
|
42
|
+
ws.sendToConnectionId(connId, JSON.stringify({ action: 'containers:pty-out', payload: frame }));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
containerPtyKitServer.handleOpen(ptyConn);
|
|
46
|
+
containerPtyConnections.set(connId, ptyConn);
|
|
47
|
+
|
|
48
|
+
ws.addCleanup(conn, () => {
|
|
49
|
+
containerPtyKitServer.handleClose(ptyConn);
|
|
50
|
+
containerPtyConnections.delete(connId);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
debug.log('containers', `PtyKit connection opened for ${connId}`);
|
|
54
|
+
return ptyConn;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Replace whatever `shell` the client sent with the target derived from the
|
|
59
|
+
* frame's own namespace. Frames that are not `create-session` pass through.
|
|
60
|
+
*/
|
|
61
|
+
function stampSpawnTarget(frame: WireFrame): WireFrame {
|
|
62
|
+
if (frame.action !== 'create-session') return frame;
|
|
63
|
+
|
|
64
|
+
const payload = frame.payload as { requestId?: string; data?: Record<string, unknown> } | null;
|
|
65
|
+
const request = payload?.data;
|
|
66
|
+
if (!request || typeof request.namespace !== 'string') return frame;
|
|
67
|
+
|
|
68
|
+
const target = targetFromNamespace(request.namespace);
|
|
69
|
+
if (!target) return frame;
|
|
70
|
+
rememberNamespace(request.namespace);
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
action: frame.action,
|
|
74
|
+
payload: { ...payload, data: { ...request, shell: encodeContainerTarget(target) } }
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const containersTunnelHandler = createRouter()
|
|
79
|
+
// Client → server: one PtyKit wire frame for a container shell.
|
|
80
|
+
.on(
|
|
81
|
+
'containers:pty',
|
|
82
|
+
{
|
|
83
|
+
data: t.Object({
|
|
84
|
+
action: t.String(),
|
|
85
|
+
payload: t.Any()
|
|
86
|
+
})
|
|
87
|
+
},
|
|
88
|
+
({ conn, data }) => {
|
|
89
|
+
const ptyConn = getContainerPtyConnection(conn);
|
|
90
|
+
void containerPtyKitServer.handleFrame(ptyConn, stampSpawnTarget(data as WireFrame));
|
|
91
|
+
}
|
|
92
|
+
)
|
|
93
|
+
// Server → client: PtyKit wire frames. Declared for the typed WSAPI; actually
|
|
94
|
+
// sent via ws.sendToConnectionId above.
|
|
95
|
+
.emit(
|
|
96
|
+
'containers:pty-out',
|
|
97
|
+
t.Object({
|
|
98
|
+
action: t.String(),
|
|
99
|
+
payload: t.Any()
|
|
100
|
+
})
|
|
101
|
+
);
|
package/backend/ws/git/log.ts
CHANGED
|
@@ -32,6 +32,7 @@ export const logHandler = createRouter()
|
|
|
32
32
|
limit: t.Optional(t.Number()),
|
|
33
33
|
skip: t.Optional(t.Number()),
|
|
34
34
|
branch: t.Optional(t.String()),
|
|
35
|
+
allBranches: t.Optional(t.Boolean()),
|
|
35
36
|
repoPath: t.Optional(t.String())
|
|
36
37
|
}),
|
|
37
38
|
response: t.Object({
|
|
@@ -55,6 +56,7 @@ export const logHandler = createRouter()
|
|
|
55
56
|
cwd,
|
|
56
57
|
data.limit ?? 50,
|
|
57
58
|
data.skip ?? 0,
|
|
58
|
-
data.branch
|
|
59
|
+
data.branch,
|
|
60
|
+
data.allBranches ?? false
|
|
59
61
|
);
|
|
60
62
|
});
|
package/backend/ws/git/status.ts
CHANGED
|
@@ -55,15 +55,18 @@ export const statusHandler = createRouter()
|
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
// Fetch outer status and nested repo list in parallel — the walk does
|
|
59
|
+
// not depend on the status result, and on Windows the walk (readdir +
|
|
60
|
+
// check-ignore spawns) is the dominant cost. Sharing the walk via the
|
|
61
|
+
// findNestedRepoPaths cache + inflight dedup also keeps concurrent
|
|
62
|
+
// callers (status + branches triggered together) from walking twice.
|
|
63
|
+
const [status, nestedRepoPaths] = await Promise.all([
|
|
64
|
+
gitService.getStatus(project.path),
|
|
65
|
+
// Discovery failing must not cost the user the outer repo's status.
|
|
66
|
+
findNestedRepoPaths(project.path).catch(() => [] as string[])
|
|
67
|
+
]);
|
|
59
68
|
|
|
60
|
-
|
|
61
|
-
// project (e.g. a theme extracted into its own repo, listed in the
|
|
62
|
-
// parent's .gitignore). The outer repo's `git status` skips them
|
|
63
|
-
// entirely, so without this aggregation the Changes tab would not
|
|
64
|
-
// show edits the AI made inside the nested repo.
|
|
65
|
-
try {
|
|
66
|
-
const nestedRepoPaths = await findNestedRepoPaths(project.path);
|
|
69
|
+
if (nestedRepoPaths.length > 0) {
|
|
67
70
|
const nestedPrefixes = nestedRepoPaths.map(
|
|
68
71
|
(repoPath) => pathRelative(project.path, repoPath).replace(/\\/g, '/') + '/'
|
|
69
72
|
);
|
|
@@ -84,26 +87,33 @@ export const statusHandler = createRouter()
|
|
|
84
87
|
status.conflicted = status.conflicted.filter((f) => !underNested(f));
|
|
85
88
|
}
|
|
86
89
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
90
|
+
// Fetch all nested statuses in parallel instead of sequentially.
|
|
91
|
+
// Each `git status` is a separate spawn; on Windows Defender scans
|
|
92
|
+
// .git/index per call, so sequential loops multiplied the wait.
|
|
93
|
+
const nestedStatuses = await Promise.all(
|
|
94
|
+
nestedRepoPaths.map(async (repoPath) => {
|
|
95
|
+
try {
|
|
96
|
+
const nestedStatus = await gitService.getStatus(repoPath);
|
|
97
|
+
return { repoPath, nestedStatus };
|
|
98
|
+
} catch {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
for (const entry of nestedStatuses) {
|
|
105
|
+
if (!entry) continue;
|
|
106
|
+
const prefix = pathRelative(project.path, entry.repoPath).replace(/\\/g, '/') + '/';
|
|
107
|
+
const withPrefix = (f: typeof entry.nestedStatus.staged[number]) => ({
|
|
108
|
+
...f,
|
|
109
|
+
path: prefix + f.path,
|
|
110
|
+
oldPath: f.oldPath ? prefix + f.oldPath : undefined
|
|
111
|
+
});
|
|
112
|
+
status.staged.push(...entry.nestedStatus.staged.map(withPrefix));
|
|
113
|
+
status.unstaged.push(...entry.nestedStatus.unstaged.map(withPrefix));
|
|
114
|
+
status.untracked.push(...entry.nestedStatus.untracked.map(withPrefix));
|
|
115
|
+
status.conflicted.push(...entry.nestedStatus.conflicted.map(withPrefix));
|
|
104
116
|
}
|
|
105
|
-
} catch {
|
|
106
|
-
// If findNestedRepoPaths itself fails, just return outer status
|
|
107
117
|
}
|
|
108
118
|
|
|
109
119
|
return { isRepo: true, ...status };
|
package/backend/ws/index.ts
CHANGED
|
@@ -33,6 +33,7 @@ import { stackRouter } from './stack';
|
|
|
33
33
|
import { dbClientRouter } from './db-client';
|
|
34
34
|
import { sshRouter } from './ssh';
|
|
35
35
|
import { portsRouter } from './ports';
|
|
36
|
+
import { containersRouter } from './containers';
|
|
36
37
|
import { mcpRouter } from './mcp';
|
|
37
38
|
import { skillsRouter } from './skills';
|
|
38
39
|
import { commandsRouter } from './commands';
|
|
@@ -89,6 +90,7 @@ export const wsRouter = createRouter()
|
|
|
89
90
|
// SSH client (terminal, SFTP, port forwarding)
|
|
90
91
|
.merge(sshRouter)
|
|
91
92
|
.merge(portsRouter)
|
|
93
|
+
.merge(containersRouter)
|
|
92
94
|
|
|
93
95
|
// External MCP server management (install from the official registry)
|
|
94
96
|
.merge(mcpRouter)
|
|
@@ -56,6 +56,51 @@ describe('MessageRateLimiter', () => {
|
|
|
56
56
|
expect(closeCalls.length).toBe(0);
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
+
test('throttling never drops a request somebody is waiting on', () => {
|
|
60
|
+
const limiter = new MessageRateLimiter();
|
|
61
|
+
const { conn, closeCalls } = createMockConnection();
|
|
62
|
+
|
|
63
|
+
// Push the connection into the throttled state with event traffic — the
|
|
64
|
+
// shape of a preview stream or a terminal, which is what actually fills
|
|
65
|
+
// this window on a busy instance.
|
|
66
|
+
for (let i = 0; i < 99; i++) {
|
|
67
|
+
expect(limiter.checkRateLimit(conn, 'preview:browser-interaction')).toBe(true);
|
|
68
|
+
}
|
|
69
|
+
expect(limiter.checkRateLimit(conn, 'preview:browser-interaction')).toBe(false);
|
|
70
|
+
expect(limiter.getConnectionStats(conn)?.isThrottled).toBe(true);
|
|
71
|
+
|
|
72
|
+
// A request-response call arriving in the same window still gets through.
|
|
73
|
+
// Shedding it used to hang its caller for a full timeout, which the client
|
|
74
|
+
// then "healed" by tearing down the socket — a far bigger burst than the
|
|
75
|
+
// one being throttled, and the reason the overload sustained itself.
|
|
76
|
+
expect(limiter.checkRateLimit(conn, 'files:list-tree', true)).toBe(true);
|
|
77
|
+
expect(limiter.checkRateLimit(conn, 'git:status', true)).toBe(true);
|
|
78
|
+
|
|
79
|
+
// Only the events were counted as dropped.
|
|
80
|
+
expect(limiter.getConnectionStats(conn)?.messagesDropped).toBe(1);
|
|
81
|
+
expect(closeCalls.length).toBe(0);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('a request is still refused once the connection is closed for abuse', () => {
|
|
85
|
+
const limiter = new MessageRateLimiter({
|
|
86
|
+
warningThreshold: 50,
|
|
87
|
+
throttleThreshold: 100,
|
|
88
|
+
disconnectThreshold: 200,
|
|
89
|
+
windowMs: 1000
|
|
90
|
+
});
|
|
91
|
+
const { conn, closeCalls } = createMockConnection();
|
|
92
|
+
|
|
93
|
+
for (let i = 0; i < 199; i++) {
|
|
94
|
+
limiter.checkRateLimit(conn, 'files:list-tree', true);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Requests are exempt from THROTTLING, not from the abuse ceiling: past the
|
|
98
|
+
// disconnect threshold the socket is gone, so there is nothing to protect.
|
|
99
|
+
expect(limiter.checkRateLimit(conn, 'files:list-tree', true)).toBe(false);
|
|
100
|
+
expect(limiter.getConnectionStats(conn)?.isFlagged).toBe(true);
|
|
101
|
+
expect(closeCalls.length).toBe(1);
|
|
102
|
+
});
|
|
103
|
+
|
|
59
104
|
test('drops and closes connection at disconnect threshold', () => {
|
|
60
105
|
const limiter = new MessageRateLimiter({
|
|
61
106
|
warningThreshold: 50,
|
|
@@ -6,8 +6,29 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Thresholds:
|
|
8
8
|
* 50 messages/second → warning logged
|
|
9
|
-
* 100 messages/second → connection throttled (
|
|
10
|
-
* 200 messages/second → connection
|
|
9
|
+
* 100 messages/second → connection throttled (fire-and-forget events dropped)
|
|
10
|
+
* 200 messages/second → connection closed
|
|
11
|
+
*
|
|
12
|
+
* WHAT GETS SHED WHEN THROTTLING
|
|
13
|
+
*
|
|
14
|
+
* Throttling drops events, never request-response calls, and the asymmetry is
|
|
15
|
+
* the entire point. A busy Clopen tab is dominated by high-volume fire-and-
|
|
16
|
+
* forget traffic — preview pointer moves at ~30/s per viewer, terminal
|
|
17
|
+
* keystrokes, stream feedback — while the calls a panel actually waits on
|
|
18
|
+
* (`files:list-tree`, `git:status`, `engine:*-accounts-list`) are a trickle by
|
|
19
|
+
* comparison.
|
|
20
|
+
*
|
|
21
|
+
* Counting them in one bucket and dropping whatever arrived last meant the
|
|
22
|
+
* flood survived and the request died. That is backwards twice over: a dropped
|
|
23
|
+
* pointer move is invisible because the next one supersedes it a frame later,
|
|
24
|
+
* whereas a dropped request leaves a panel with no data and a user with no
|
|
25
|
+
* explanation. Worse, it was self-amplifying — a dropped request used to hang
|
|
26
|
+
* its caller until the client tore the socket down and every panel refetched at
|
|
27
|
+
* once, which is a bigger burst than the one that tripped the limiter.
|
|
28
|
+
*
|
|
29
|
+
* Abuse is still bounded, and by the threshold that was always the real one:
|
|
30
|
+
* a connection genuinely spamming the server crosses 200/s and gets closed
|
|
31
|
+
* regardless of what it is sending.
|
|
11
32
|
*/
|
|
12
33
|
|
|
13
34
|
import { debug } from '$shared/utils/logger';
|
|
@@ -59,7 +80,13 @@ export class MessageRateLimiter {
|
|
|
59
80
|
return state;
|
|
60
81
|
}
|
|
61
82
|
|
|
62
|
-
|
|
83
|
+
/**
|
|
84
|
+
* @param isRequest Whether `action` is a request-response route — i.e. a
|
|
85
|
+
* caller is blocked waiting for its reply. Such calls are counted like
|
|
86
|
+
* everything else but are never shed by throttling; see the note at the
|
|
87
|
+
* top of this file.
|
|
88
|
+
*/
|
|
89
|
+
checkRateLimit(conn: WSConnection, action: string, isRequest = false): boolean {
|
|
63
90
|
const state = this.getState(conn);
|
|
64
91
|
const now = Date.now();
|
|
65
92
|
const windowStart = now - this.config.windowMs;
|
|
@@ -91,6 +118,10 @@ export class MessageRateLimiter {
|
|
|
91
118
|
state.isWarning = false;
|
|
92
119
|
debug.warn('rate-limit', `Connection throttled: ${messagesPerSecond.toFixed(0)} msg/s on action ${action}`);
|
|
93
120
|
}
|
|
121
|
+
// Shed the flood, not the thing somebody is waiting on. Below the
|
|
122
|
+
// disconnect threshold a request is always answered; above it the
|
|
123
|
+
// connection is gone anyway.
|
|
124
|
+
if (isRequest) return true;
|
|
94
125
|
state.messagesDropped++;
|
|
95
126
|
return false;
|
|
96
127
|
}
|
|
@@ -11,6 +11,8 @@ import { sshForwardManager } from '../../ssh/forwards';
|
|
|
11
11
|
import { sshHealthService } from '../../ssh/health';
|
|
12
12
|
import { knownHosts } from '../../ssh/known-hosts';
|
|
13
13
|
import { killSessionsForConnection } from '../../ssh/ptykit';
|
|
14
|
+
import { killContainerSessionsForHost } from '../../containers/pty';
|
|
15
|
+
import { stopLogStreamsForHost } from '../../containers/logs';
|
|
14
16
|
import type { SshConnectionInput } from '$shared/types/ssh';
|
|
15
17
|
import { debug } from '$shared/utils/logger';
|
|
16
18
|
import { getSshPrincipal, requireSshConnection } from './access';
|
|
@@ -78,9 +80,13 @@ function isInput(value: unknown): value is SshConnectionInput {
|
|
|
78
80
|
/**
|
|
79
81
|
* Changing where or how a host is reached invalidates everything riding the old
|
|
80
82
|
* transport, so shells, forwards and the pooled client all go before the write.
|
|
83
|
+
* That includes the two things this host's containers hold open: shells running
|
|
84
|
+
* inside them, and any log stream being followed.
|
|
81
85
|
*/
|
|
82
86
|
async function tearDownConnection(connectionId: string): Promise<void> {
|
|
83
87
|
killSessionsForConnection(connectionId);
|
|
88
|
+
killContainerSessionsForHost(connectionId);
|
|
89
|
+
stopLogStreamsForHost(connectionId);
|
|
84
90
|
await sshForwardManager.stopForConnection(connectionId);
|
|
85
91
|
sshClientPool.release(connectionId);
|
|
86
92
|
// Editing or deleting is not "disconnect" — a host suspended earlier should
|
|
@@ -187,6 +193,8 @@ export const sshConnectionsHandler = createRouter()
|
|
|
187
193
|
}, async ({ data, conn }) => {
|
|
188
194
|
requireSshConnection(conn, data.id);
|
|
189
195
|
killSessionsForConnection(data.id);
|
|
196
|
+
killContainerSessionsForHost(data.id);
|
|
197
|
+
stopLogStreamsForHost(data.id);
|
|
190
198
|
await sshForwardManager.stopForConnection(data.id);
|
|
191
199
|
sshClientPool.suspend(data.id);
|
|
192
200
|
return sshHealthService.testSaved(data.id);
|
|
@@ -38,31 +38,74 @@ interface StaticInfo {
|
|
|
38
38
|
gpus: Array<{ model: string; vendor: string; vramMb: number | null }>;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
/** Timeout helper: race a promise against a deadline, return fallback on timeout. */
|
|
42
|
+
function withTimeout<T>(promise: Promise<T>, ms: number, fallback: T): Promise<T> {
|
|
43
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
44
|
+
const timeout = new Promise<T>((_, reject) => {
|
|
45
|
+
timer = setTimeout(() => reject(new Error(`timeout after ${ms}ms`)), ms);
|
|
46
|
+
});
|
|
47
|
+
return Promise.race([promise, timeout])
|
|
48
|
+
.then((v) => {
|
|
49
|
+
clearTimeout(timer);
|
|
50
|
+
return v;
|
|
51
|
+
})
|
|
52
|
+
.catch(() => {
|
|
53
|
+
clearTimeout(timer);
|
|
54
|
+
return fallback;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
41
58
|
/** Static facts don't change while the process runs — resolve them once. */
|
|
42
59
|
let staticInfoPromise: Promise<StaticInfo> | null = null;
|
|
43
60
|
|
|
61
|
+
/** Last-good caches for dynamic probes: prevents transient WMI timeouts from
|
|
62
|
+
* flickering the UI between "This Device" <-> "Server" or dropping Storage cards. */
|
|
63
|
+
let lastMemCache: Systeminformation.MemData | null = null;
|
|
64
|
+
let lastBatteryCache: Systeminformation.BatteryData | null = null;
|
|
65
|
+
let lastFsSizeCache: Systeminformation.FsSizeData[] | null = null;
|
|
66
|
+
let lastLoadCache: Systeminformation.CurrentLoadData | null = null;
|
|
67
|
+
let lastGraphicsCache: Systeminformation.GraphicsData | null = null;
|
|
68
|
+
let lastNetCache: Systeminformation.NetworkInterfacesData | null = null;
|
|
69
|
+
|
|
44
70
|
async function getStaticInfo(): Promise<StaticInfo> {
|
|
45
71
|
if (!staticInfoPromise) {
|
|
46
72
|
staticInfoPromise = (async () => {
|
|
73
|
+
const fallbackOs = {
|
|
74
|
+
hostname: os.hostname(),
|
|
75
|
+
platform: os.platform(),
|
|
76
|
+
distro: '',
|
|
77
|
+
release: os.release(),
|
|
78
|
+
kernel: os.version(),
|
|
79
|
+
arch: os.arch()
|
|
80
|
+
} as unknown as Systeminformation.OsData;
|
|
81
|
+
const fallbackCpu = {
|
|
82
|
+
brand: '',
|
|
83
|
+
manufacturer: '',
|
|
84
|
+
physicalCores: os.cpus().length,
|
|
85
|
+
cores: os.cpus().length,
|
|
86
|
+
speed: 0
|
|
87
|
+
} as unknown as Systeminformation.CpuData;
|
|
88
|
+
const fallbackSystem = { virtual: false } as unknown as Systeminformation.SystemData;
|
|
89
|
+
const fallbackGraphics = { controllers: [] } as unknown as Systeminformation.GraphicsData;
|
|
47
90
|
const [osInfo, cpu, system, graphics] = await Promise.all([
|
|
48
|
-
si.osInfo(),
|
|
49
|
-
si.cpu(),
|
|
50
|
-
si.system(),
|
|
51
|
-
si.graphics()
|
|
91
|
+
withTimeout(si.osInfo(), 4000, fallbackOs),
|
|
92
|
+
withTimeout(si.cpu(), 4000, fallbackCpu),
|
|
93
|
+
withTimeout(si.system(), 4000, fallbackSystem),
|
|
94
|
+
withTimeout(si.graphics(), 4000, fallbackGraphics)
|
|
52
95
|
]);
|
|
53
96
|
return {
|
|
54
|
-
hostname: osInfo
|
|
55
|
-
platform: osInfo.platform,
|
|
56
|
-
distro: osInfo
|
|
57
|
-
release: osInfo.release,
|
|
58
|
-
kernel: osInfo.
|
|
59
|
-
arch: osInfo
|
|
60
|
-
isVirtual: Boolean(system
|
|
61
|
-
cpuBrand: cpu
|
|
62
|
-
cpuManufacturer: cpu
|
|
63
|
-
physicalCores: cpu
|
|
64
|
-
logicalCores: cpu.
|
|
65
|
-
cpuSpeedGhz: typeof cpu
|
|
97
|
+
hostname: (osInfo?.hostname || os.hostname()) as string,
|
|
98
|
+
platform: (osInfo?.platform || os.platform()) as string,
|
|
99
|
+
distro: (osInfo?.distro || '') as string,
|
|
100
|
+
release: (osInfo?.release || os.release()) as string,
|
|
101
|
+
kernel: (osInfo?.kernel || os.version()) as string,
|
|
102
|
+
arch: (osInfo?.arch || os.arch()) as string,
|
|
103
|
+
isVirtual: Boolean(system?.virtual),
|
|
104
|
+
cpuBrand: (cpu?.brand || '') as string,
|
|
105
|
+
cpuManufacturer: (cpu?.manufacturer || '') as string,
|
|
106
|
+
physicalCores: (cpu?.physicalCores || cpu?.cores || os.cpus().length) as number,
|
|
107
|
+
logicalCores: (cpu?.cores || os.cpus().length) as number,
|
|
108
|
+
cpuSpeedGhz: typeof cpu?.speed === 'number' && cpu.speed > 0 ? cpu.speed : null,
|
|
66
109
|
gpus: graphics.controllers.map((c) => ({
|
|
67
110
|
model: c.model || 'Unknown GPU',
|
|
68
111
|
vendor: c.vendor || 'Unknown',
|
|
@@ -213,24 +256,37 @@ export const deviceInfoHandler = createRouter()
|
|
|
213
256
|
const staticInfo = await getStaticInfo();
|
|
214
257
|
|
|
215
258
|
const [load, mem, battery, graphics, fsSize, netDefault] = await Promise.all([
|
|
216
|
-
si.currentLoad(),
|
|
217
|
-
si.mem(),
|
|
218
|
-
si.battery(),
|
|
219
|
-
si.graphics(),
|
|
220
|
-
si.fsSize(),
|
|
221
|
-
si.networkInterfaces('default')
|
|
259
|
+
withTimeout(si.currentLoad(), 3500, null as unknown as Systeminformation.CurrentLoadData | null),
|
|
260
|
+
withTimeout(si.mem(), 3500, null as unknown as Systeminformation.MemData | null),
|
|
261
|
+
withTimeout(si.battery(), 3500, null as unknown as Systeminformation.BatteryData | null),
|
|
262
|
+
withTimeout(si.graphics(), 3500, null as unknown as Systeminformation.GraphicsData | null),
|
|
263
|
+
withTimeout(si.fsSize(), 3500, null as unknown as Systeminformation.FsSizeData[] | null),
|
|
264
|
+
withTimeout(si.networkInterfaces('default'), 3500, null as unknown as Systeminformation.NetworkInterfacesData | null)
|
|
222
265
|
]);
|
|
223
266
|
|
|
224
|
-
//
|
|
225
|
-
//
|
|
226
|
-
|
|
267
|
+
// Update last-good caches; reuse them when a probe times out so the UI
|
|
268
|
+
// doesn't flicker between "This Device" <-> "Server" or drop Storage cards.
|
|
269
|
+
if (mem) lastMemCache = mem as unknown as Systeminformation.MemData;
|
|
270
|
+
if (battery) lastBatteryCache = battery as unknown as Systeminformation.BatteryData;
|
|
271
|
+
if (fsSize) lastFsSizeCache = fsSize as unknown as Systeminformation.FsSizeData[];
|
|
272
|
+
if (load) lastLoadCache = load as unknown as Systeminformation.CurrentLoadData;
|
|
273
|
+
if (graphics) lastGraphicsCache = graphics as unknown as Systeminformation.GraphicsData;
|
|
274
|
+
if (netDefault) lastNetCache = (Array.isArray(netDefault) ? netDefault[0] : netDefault) as unknown as Systeminformation.NetworkInterfacesData;
|
|
275
|
+
|
|
276
|
+
const memEff = (mem as unknown as Systeminformation.MemData) ?? lastMemCache;
|
|
277
|
+
const batteryEff = (battery as unknown as Systeminformation.BatteryData) ?? lastBatteryCache;
|
|
278
|
+
const fsSizeEff = (fsSize as unknown as Systeminformation.FsSizeData[]) ?? lastFsSizeCache ?? [];
|
|
279
|
+
const loadEff = (load as unknown as Systeminformation.CurrentLoadData) ?? lastLoadCache;
|
|
280
|
+
const graphicsEff = (graphics as unknown as Systeminformation.GraphicsData) ?? lastGraphicsCache ?? { controllers: [] } as unknown as Systeminformation.GraphicsData;
|
|
281
|
+
const netRawEff = (netDefault as unknown as Systeminformation.NetworkInterfacesData | null) ?? lastNetCache;
|
|
282
|
+
const net = Array.isArray(netRawEff) ? netRawEff[0] : (netRawEff as unknown as Systeminformation.NetworkInterfacesData | null);
|
|
227
283
|
|
|
228
284
|
// avgLoad is 0/undefined on platforms without load average (e.g. Windows).
|
|
229
|
-
const loadAvg1 = typeof
|
|
285
|
+
const loadAvg1 = typeof (loadEff as unknown as { avgLoad?: number })?.avgLoad === 'number' && (loadEff as unknown as { avgLoad: number }).avgLoad > 0 ? (loadEff as unknown as { avgLoad: number }).avgLoad : null;
|
|
230
286
|
|
|
231
287
|
// Pair live GPU utilization with the cached controller identity by index.
|
|
232
288
|
const gpus = staticInfo.gpus.map((g, i) => {
|
|
233
|
-
const live =
|
|
289
|
+
const live = (graphicsEff as Systeminformation.GraphicsData)?.controllers?.[i];
|
|
234
290
|
return {
|
|
235
291
|
model: g.model,
|
|
236
292
|
vendor: g.vendor,
|
|
@@ -242,7 +298,7 @@ export const deviceInfoHandler = createRouter()
|
|
|
242
298
|
});
|
|
243
299
|
|
|
244
300
|
// Show only the primary disk(s); collapses macOS APFS synthetic volumes.
|
|
245
|
-
const disks = selectPrimaryDisks(
|
|
301
|
+
const disks = selectPrimaryDisks((fsSizeEff as Systeminformation.FsSizeData[]) || [], staticInfo.platform);
|
|
246
302
|
|
|
247
303
|
return {
|
|
248
304
|
hostname: staticInfo.hostname,
|
|
@@ -259,29 +315,29 @@ export const deviceInfoHandler = createRouter()
|
|
|
259
315
|
physicalCores: staticInfo.physicalCores,
|
|
260
316
|
logicalCores: staticInfo.logicalCores,
|
|
261
317
|
speedGhz: staticInfo.cpuSpeedGhz,
|
|
262
|
-
loadPercent: typeof
|
|
318
|
+
loadPercent: typeof (loadEff as unknown as { currentLoad?: number })?.currentLoad === 'number' ? (loadEff as unknown as { currentLoad: number }).currentLoad : 0,
|
|
263
319
|
loadAvg1
|
|
264
320
|
},
|
|
265
321
|
memory: {
|
|
266
|
-
totalBytes:
|
|
267
|
-
usedBytes:
|
|
268
|
-
freeBytes:
|
|
269
|
-
swapTotalBytes:
|
|
270
|
-
swapUsedBytes:
|
|
322
|
+
totalBytes: (memEff as unknown as Systeminformation.MemData)?.total ?? os.totalmem(),
|
|
323
|
+
usedBytes: (memEff as unknown as Systeminformation.MemData)?.active ?? os.totalmem() - os.freemem(),
|
|
324
|
+
freeBytes: (memEff as unknown as Systeminformation.MemData)?.available ?? os.freemem(),
|
|
325
|
+
swapTotalBytes: (memEff as unknown as Systeminformation.MemData)?.swaptotal ?? 0,
|
|
326
|
+
swapUsedBytes: (memEff as unknown as Systeminformation.MemData)?.swapused ?? 0
|
|
271
327
|
},
|
|
272
328
|
network: {
|
|
273
|
-
iface: net?.iface || '',
|
|
274
|
-
ip4: net?.ip4 || '',
|
|
275
|
-
mac: net?.mac || ''
|
|
329
|
+
iface: (net as unknown as { iface?: string })?.iface || '',
|
|
330
|
+
ip4: (net as unknown as { ip4?: string })?.ip4 || '',
|
|
331
|
+
mac: (net as unknown as { mac?: string })?.mac || ''
|
|
276
332
|
},
|
|
277
333
|
battery: {
|
|
278
|
-
hasBattery: Boolean(
|
|
279
|
-
percent: typeof
|
|
280
|
-
isCharging: Boolean(
|
|
281
|
-
acConnected: Boolean(
|
|
334
|
+
hasBattery: Boolean((batteryEff as unknown as Systeminformation.BatteryData)?.hasBattery),
|
|
335
|
+
percent: typeof (batteryEff as unknown as Systeminformation.BatteryData)?.percent === 'number' && (batteryEff as unknown as Systeminformation.BatteryData)?.hasBattery ? (batteryEff as unknown as Systeminformation.BatteryData).percent : null,
|
|
336
|
+
isCharging: Boolean((batteryEff as unknown as Systeminformation.BatteryData)?.isCharging),
|
|
337
|
+
acConnected: Boolean((batteryEff as unknown as Systeminformation.BatteryData)?.acConnected),
|
|
282
338
|
timeRemainingMinutes:
|
|
283
|
-
typeof
|
|
284
|
-
?
|
|
339
|
+
typeof (batteryEff as unknown as Systeminformation.BatteryData)?.timeRemaining === 'number' && (batteryEff as unknown as Systeminformation.BatteryData).timeRemaining > 0
|
|
340
|
+
? (batteryEff as unknown as Systeminformation.BatteryData).timeRemaining
|
|
285
341
|
: null
|
|
286
342
|
},
|
|
287
343
|
gpus,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{s as _,_ as d,r as s,a as u}from"./main-
|
|
1
|
+
import{s as _,_ as d,r as s,a as u}from"./main-C_iGUZyL.js";import{C as T,P as y,W as E,d as L,b as g,c as v,h as P,l as b,m as k,e as D,n as O,f as R,g as S,t as V}from"./main-C_iGUZyL.js";async function h(o,e={}){const i=e.loading===!1?void 0:_(o,e.loadingText??"Loading…"),[{Terminal:l},{FitAddon:c}]=await Promise.all([d(()=>import("./xterm-B-qIQCd3.js"),[]),d(()=>import("./addon-fit-DX4qG4td.js"),[])]).catch(r=>{throw i?.(),r}),a=new l({scrollback:e.scrollback??5e3,fontSize:e.fontSize??13,fontFamily:e.fontFamily??"ui-monospace, SFMono-Regular, Menlo, monospace",lineHeight:e.lineHeight??1,cursorBlink:e.cursorBlink??!1,cursorStyle:e.cursorStyle??"block",disableStdin:e.stdin!==!0,allowProposedApi:!0,convertEol:!0,theme:s(e.theme),...e.cols?{cols:e.cols}:{},...e.rows?{rows:e.rows}:{},...e.terminalOptions??{}}),t=e.fit===!1?void 0:new c;if(t&&a.loadAddon(t),e.clipboard)try{const{ClipboardAddon:r}=await d(()=>import("./addon-clipboard-wHJhZAA4.js"),[]);a.loadAddon(new r)}catch{}if(e.webLinks)try{const{WebLinksAddon:r}=await d(()=>import("./addon-web-links-DIbG5aQx.js"),[]);a.loadAddon(new r)}catch{}if(e.unicode11)try{const{Unicode11Addon:r}=await d(()=>import("./addon-unicode11-Bt8F3D7-.js"),[]);a.loadAddon(new r),a.unicode.activeVersion="11"}catch{}for(const r of e.addons??[])a.loadAddon(r);if(a.open(o),e.ligatures)try{const{LigaturesAddon:r}=await d(()=>import("./addon-ligatures-DpDY8N_X.js"),[]);a.loadAddon(new r)}catch{}const m=t?u({resize:async()=>{}},a,t,{debounceMs:e.fitDebounceMs??100}):void 0;e.onReady?.(a),i?.();let n=!1;return{terminal:a,fitAddon:t,write:r=>a.write(r),clear:()=>{a.clear(),a.reset()},fit:()=>t?.fit(),setTheme:r=>{a.options.theme=s(r)},dispose(){n||(n=!0,m?.(),a.dispose())}}}export{T as ClientSession,y as PtyKitClient,E as WsCore,u as attachFit,L as darkTheme,g as defaultPersistence,v as draculaTheme,P as hostSocket,b as lightTheme,k as matrixTheme,D as mountTerminal,h as mountViewer,O as nordTheme,s as resolveTheme,_ as showLoadingOverlay,R as solarizedDarkTheme,S as solarizedLightTheme,V as themes};
|