@amd-gaia/agent-ui 0.26.0-rc.8 → 0.26.0
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 +2 -2
- package/app.config.json +1 -1
- package/assets/launcher-icon.png +0 -0
- package/assets/notification-icon.png +0 -0
- package/assets/tray-iconTemplate.png +0 -0
- package/assets/tray-iconTemplate@2x.png +0 -0
- package/dist/assets/AdvancedSettings-D8X93EJ5.js +1 -0
- package/dist/assets/AutomationsSettings-CPbZmniK.js +1 -0
- package/dist/assets/ConnectorsPane-sL0g5pbJ.js +1 -0
- package/dist/assets/ConnectorsPane-w-HLcq3n.css +1 -0
- package/dist/assets/DocumentLibrary-BKZdx6rJ.css +1 -0
- package/dist/assets/DocumentLibrary-CtdN1pvI.js +5 -0
- package/dist/assets/FileBrowser-B3ItGNDY.js +4 -0
- package/dist/assets/FileBrowser-CrRQXiPo.css +1 -0
- package/dist/assets/MemoryDashboard-B1ySnt3d.js +1 -0
- package/dist/assets/MemoryDashboard-B4AO_CU8.css +1 -0
- package/dist/assets/MessagingSettings-C-JCKvTA.js +1 -0
- package/dist/assets/MobileAccessModal-B4cWE8kn.js +2 -0
- package/dist/assets/MobileAccessModal-CX4NZmr4.css +1 -0
- package/dist/assets/ScheduleManager-CqhM09ge.js +1 -0
- package/dist/assets/ScheduleManager-DQBnf_IN.css +1 -0
- package/dist/assets/{browser-KnDALPx_.js → browser-DfYHeeW3.js} +1 -1
- package/dist/assets/index-B8x4YAsZ.js +116 -0
- package/dist/assets/index-D6KUNvpp.css +1 -0
- package/dist/assets/useT-CGVxPqT2.js +6 -0
- package/dist/assets/zap-BX0_8UeI.js +1 -0
- package/dist/index.html +17 -4
- package/dist/sw.js +1 -1
- package/main-safety-net.cjs +30 -3
- package/main.cjs +57 -220
- package/package.json +4 -3
- package/preload.cjs +0 -30
- package/services/agent-process-manager.cjs +3 -411
- package/services/app-icon.cjs +14 -4
- package/services/appimage-launcher.cjs +183 -0
- package/services/auto-updater.cjs +46 -3
- package/services/backend-installer.cjs +7 -1
- package/services/renderer-gone-dialog.cjs +57 -0
- package/services/tray-manager.cjs +7 -14
- package/services/window-reveal.cjs +42 -0
- package/assets/tray-icon-active.png +0 -0
- package/assets/tray-icon-active@2x.png +0 -0
- package/dist/assets/AdvancedSettings-Do0WzL_Y.js +0 -1
- package/dist/assets/ConnectorsPane-DZBTGEqt.js +0 -1
- package/dist/assets/ConnectorsPane-Dq8E0HKa.css +0 -1
- package/dist/assets/DocumentLibrary-CM6o8j2T.css +0 -1
- package/dist/assets/DocumentLibrary-DNy5hN3I.js +0 -4
- package/dist/assets/FileBrowser-Cna3BsT7.css +0 -1
- package/dist/assets/FileBrowser-_C82gXxd.js +0 -4
- package/dist/assets/MemoryDashboard-DwrWAXi6.css +0 -1
- package/dist/assets/MemoryDashboard-tBktv-if.js +0 -1
- package/dist/assets/MobileAccessModal-BkVDm3YG.css +0 -1
- package/dist/assets/MobileAccessModal-DaeCnIdA.js +0 -2
- package/dist/assets/ScheduleManager-4HgyUXy7.js +0 -1
- package/dist/assets/ScheduleManager-CjHJ4NbD.css +0 -1
- package/dist/assets/api-c2Hja8UA.js +0 -4
- package/dist/assets/index-CxE9Oq-q.js +0 -83
- package/dist/assets/index-LIIGp54f.css +0 -1
- package/dist/assets/useT-9bLwAbF7.js +0 -3
- package/dist/assets/zap-gjTc4oQN.js +0 -1
- package/services/deep-link-queue.cjs +0 -77
- package/services/deep-link.cjs +0 -230
- package/services/system-metrics.cjs +0 -154
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{q as e}from"./useT-9bLwAbF7.js";var t={name:`message-square`,size:24,node:[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}]]};t.node;var n=e(t),r={name:`zap`,size:24,node:[[`path`,{d:`M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z`,key:`1v7up4`}]]};r.node;var i=e(r);export{n,i as t};
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
// Copyright(C) 2025-2026 Advanced Micro Devices, Inc. All rights reserved.
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* deep-link-queue.cjs — hold gaia:// links until the backend can verify them.
|
|
6
|
-
*
|
|
7
|
-
* A cold-start "Open in GAIA" link reaches the app long before the backend
|
|
8
|
-
* listens, and the install gate resolves the agent through the backend's
|
|
9
|
-
* catalog API (failing closed). This queue holds every link that arrives
|
|
10
|
-
* before startup has waited for the backend, then dispatches each exactly
|
|
11
|
-
* once. Electron-free so the ordering can be unit-tested.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
"use strict";
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @param {object} deps
|
|
18
|
-
* @param {(rawUrl: string) => void} deps.dispatch Act on one validated link.
|
|
19
|
-
* @param {(rawUrls: string[]) => void} deps.reportNotReady Tell the user the
|
|
20
|
-
* queued links could not be opened because the backend never came up.
|
|
21
|
-
* @param {{log: Function}} [deps.logger]
|
|
22
|
-
*/
|
|
23
|
-
function createStartupDeepLinkQueue({ dispatch, reportNotReady, logger = console }) {
|
|
24
|
-
if (typeof dispatch !== "function" || typeof reportNotReady !== "function") {
|
|
25
|
-
throw new Error("createStartupDeepLinkQueue requires dispatch and reportNotReady functions");
|
|
26
|
-
}
|
|
27
|
-
const pending = [];
|
|
28
|
-
let drained = false;
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
/**
|
|
32
|
-
* Accept a validated link: queue it until drain(), dispatch it after.
|
|
33
|
-
* @returns {"queued" | "duplicate" | "dispatched"}
|
|
34
|
-
*/
|
|
35
|
-
accept(rawUrl) {
|
|
36
|
-
if (drained) {
|
|
37
|
-
dispatch(rawUrl);
|
|
38
|
-
return "dispatched";
|
|
39
|
-
}
|
|
40
|
-
if (pending.includes(rawUrl)) return "duplicate";
|
|
41
|
-
pending.push(rawUrl);
|
|
42
|
-
logger.log(`[deep-link] Queued until the backend is ready: ${rawUrl}`);
|
|
43
|
-
return "queued";
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Release the queue once, after startup has waited for the backend.
|
|
48
|
-
* Later calls are no-ops, so nothing is dispatched twice.
|
|
49
|
-
*
|
|
50
|
-
* @param {{backendReady: boolean, argvUrl?: string|null}} opts
|
|
51
|
-
* @returns {string[]} The links dispatched by this call.
|
|
52
|
-
*/
|
|
53
|
-
drain({ backendReady, argvUrl = null }) {
|
|
54
|
-
if (drained) return [];
|
|
55
|
-
drained = true;
|
|
56
|
-
const urls = pending.splice(0);
|
|
57
|
-
if (argvUrl && !urls.includes(argvUrl)) urls.push(argvUrl);
|
|
58
|
-
if (urls.length === 0) return [];
|
|
59
|
-
if (!backendReady) {
|
|
60
|
-
reportNotReady(urls);
|
|
61
|
-
return [];
|
|
62
|
-
}
|
|
63
|
-
for (const url of urls) dispatch(url);
|
|
64
|
-
return urls;
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
get isDrained() {
|
|
68
|
-
return drained;
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
get pendingCount() {
|
|
72
|
-
return pending.length;
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
module.exports = { createStartupDeepLinkQueue };
|
package/services/deep-link.cjs
DELETED
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
// Copyright(C) 2025-2026 Advanced Micro Devices, Inc. All rights reserved.
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* deep-link.cjs — parse `gaia://` deep links (issue #1725).
|
|
6
|
-
*
|
|
7
|
-
* The website's "Open in GAIA" button hands the running app a
|
|
8
|
-
* `gaia://hub/install/<id>` URL. This module is the pure, Electron-free
|
|
9
|
-
* parser so it can be unit-tested without a running app; main.cjs owns the
|
|
10
|
-
* OS protocol registration and dispatch to the install runtime.
|
|
11
|
-
*
|
|
12
|
-
* Design: parse errors are THROWN with an actionable message (no silent
|
|
13
|
-
* fallback). main.cjs surfaces the message to the user instead of dropping a
|
|
14
|
-
* malformed link on the floor.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
"use strict";
|
|
18
|
-
|
|
19
|
-
const SCHEME = "gaia:";
|
|
20
|
-
|
|
21
|
-
// Agent ids as published on the hub: start alphanumeric, then letters, digits,
|
|
22
|
-
// dot, dash, underscore. Bounded length keeps a hostile link from ballooning.
|
|
23
|
-
const AGENT_ID_RE = /^[a-z0-9][a-z0-9._-]{0,63}$/i;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Parse a `gaia://` deep link into a structured command.
|
|
27
|
-
*
|
|
28
|
-
* Supported form:
|
|
29
|
-
* gaia://hub/install/<id> → { action: "install", agentId }
|
|
30
|
-
*
|
|
31
|
-
* @param {string} rawUrl
|
|
32
|
-
* @returns {{ action: "install", agentId: string }}
|
|
33
|
-
* @throws {Error} with an actionable message on anything malformed/unsupported
|
|
34
|
-
*/
|
|
35
|
-
function parseDeepLink(rawUrl) {
|
|
36
|
-
if (typeof rawUrl !== "string" || !rawUrl.trim()) {
|
|
37
|
-
throw new Error(
|
|
38
|
-
'Not a GAIA deep link — expected a "gaia://…" URL but got ' +
|
|
39
|
-
(rawUrl === "" ? "an empty string" : JSON.stringify(rawUrl)) +
|
|
40
|
-
"."
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const trimmed = rawUrl.trim();
|
|
45
|
-
let parsed;
|
|
46
|
-
try {
|
|
47
|
-
parsed = new URL(trimmed);
|
|
48
|
-
} catch {
|
|
49
|
-
throw new Error(`Malformed GAIA deep link "${trimmed}" — not a valid URL.`);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (parsed.protocol !== SCHEME) {
|
|
53
|
-
throw new Error(
|
|
54
|
-
`Unsupported URL scheme "${parsed.protocol}" — GAIA deep links must start with "gaia://".`
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const host = parsed.hostname;
|
|
59
|
-
const segments = parsed.pathname.split("/").filter(Boolean);
|
|
60
|
-
|
|
61
|
-
if (host === "hub" && segments[0] === "install") {
|
|
62
|
-
const agentId = segments[1] ? decodeURIComponent(segments[1]) : "";
|
|
63
|
-
if (!agentId) {
|
|
64
|
-
throw new Error(
|
|
65
|
-
`GAIA install link "${trimmed}" is missing an agent id — expected gaia://hub/install/<id>.`
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
if (!AGENT_ID_RE.test(agentId)) {
|
|
69
|
-
throw new Error(
|
|
70
|
-
`GAIA install link has an invalid agent id "${agentId}" — ids may contain letters, digits, dot, dash and underscore.`
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
if (segments.length > 2) {
|
|
74
|
-
throw new Error(
|
|
75
|
-
`GAIA install link "${trimmed}" has unexpected extra path segments — expected gaia://hub/install/<id>.`
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
return { action: "install", agentId };
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
throw new Error(
|
|
82
|
-
`Unrecognized GAIA deep link "${trimmed}" — only gaia://hub/install/<id> is supported.`
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Find the first `gaia://` argument in an argv array (Windows/Linux hand the
|
|
88
|
-
* deep link to the app as a command-line argument). Returns null if absent.
|
|
89
|
-
*
|
|
90
|
-
* @param {string[]} argv
|
|
91
|
-
* @returns {string | null}
|
|
92
|
-
*/
|
|
93
|
-
function extractDeepLinkFromArgv(argv) {
|
|
94
|
-
if (!Array.isArray(argv)) return null;
|
|
95
|
-
for (const arg of argv) {
|
|
96
|
-
if (typeof arg === "string" && arg.startsWith("gaia://")) return arg;
|
|
97
|
-
}
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Act on a parsed deep-link command, with every Electron/runtime effect
|
|
103
|
-
* injected so the security-critical control flow is unit-testable.
|
|
104
|
-
*
|
|
105
|
-
* SECURITY (issue #2196 review): a `gaia://hub/install/<id>` link comes from an
|
|
106
|
-
* untrusted web page, so the install MUST be gated behind an explicit per-agent
|
|
107
|
-
* confirmation — the same trust bar the in-app install enforces (#2201). A bare
|
|
108
|
-
* OS "Open GAIA?" prompt is NOT consent to download and run a specific agent.
|
|
109
|
-
* If `confirm` does not return true, no install is attempted. `confirm` is
|
|
110
|
-
* expected to have shown the agent's real catalog tier and permissions first
|
|
111
|
-
* (see `buildInstallPrompt`), not just its bare id, before resolving true.
|
|
112
|
-
*
|
|
113
|
-
* Once confirmed, the install is sent with the trust override set — the
|
|
114
|
-
* backend's non-verified gate now covers every non-verified agent, not just
|
|
115
|
-
* native ones, and this out-of-band flow already required its own explicit
|
|
116
|
-
* per-agent confirmation regardless of tier.
|
|
117
|
-
*
|
|
118
|
-
* @param {{ action: string, agentId: string }} command
|
|
119
|
-
* @param {{
|
|
120
|
-
* confirm: (command: {action: string, agentId: string}) => Promise<boolean>,
|
|
121
|
-
* installAgent: (agentId: string, opts?: { trustNative?: boolean }) => Promise<any>,
|
|
122
|
-
* focusWindow?: () => void,
|
|
123
|
-
* logger?: { log?: (...a: any[]) => void, error?: (...a: any[]) => void },
|
|
124
|
-
* }} deps
|
|
125
|
-
* @returns {Promise<{ installed: boolean, reason?: string }>}
|
|
126
|
-
*/
|
|
127
|
-
async function dispatchDeepLink(command, deps) {
|
|
128
|
-
const { confirm, installAgent, focusWindow, logger } = deps || {};
|
|
129
|
-
const log = (logger && logger.log) || (() => {});
|
|
130
|
-
|
|
131
|
-
if (!command || command.action !== "install") {
|
|
132
|
-
throw new Error(
|
|
133
|
-
`Unsupported deep-link action "${command && command.action}".`
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
if (typeof confirm !== "function" || typeof installAgent !== "function") {
|
|
137
|
-
throw new Error(
|
|
138
|
-
"dispatchDeepLink requires confirm() and installAgent() dependencies"
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Surface the app first so the confirmation dialog is clearly GAIA's.
|
|
143
|
-
if (typeof focusWindow === "function") focusWindow();
|
|
144
|
-
|
|
145
|
-
const approved = await confirm(command);
|
|
146
|
-
if (approved !== true) {
|
|
147
|
-
log(`[deep-link] User declined install of "${command.agentId}"`);
|
|
148
|
-
return { installed: false, reason: "declined" };
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
log(`[deep-link] Confirmed — installing "${command.agentId}"`);
|
|
152
|
-
await installAgent(command.agentId, { trustNative: true });
|
|
153
|
-
return { installed: true };
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// ── Informed trust prompt (security fix: gate ALL non-verified agents) ─────
|
|
157
|
-
//
|
|
158
|
-
// The bare confirm dialog above only ever showed the raw agent id — no tier,
|
|
159
|
-
// no permissions, no AMD-verified indicator. That's per-agent confirmation,
|
|
160
|
-
// but it isn't INFORMED consent. buildInstallPrompt renders the same facts
|
|
161
|
-
// the in-app trust gate (hubLanes.trustGateFor) shows, from a catalog entry,
|
|
162
|
-
// so the caller (main.cjs) can put them in front of the user before they
|
|
163
|
-
// confirm.
|
|
164
|
-
|
|
165
|
-
const TIER_LABEL = {
|
|
166
|
-
verified: "AMD Verified",
|
|
167
|
-
community: "Community",
|
|
168
|
-
experimental: "Experimental",
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
/** Normalize a possibly-missing/unknown tier the same way the in-app gate does. */
|
|
172
|
-
function normalizeTier(entry) {
|
|
173
|
-
const t = entry && entry.security_tier;
|
|
174
|
-
return t === "verified" || t === "community" ? t : "experimental";
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Build the confirmation prompt for a deep-link install from its catalog
|
|
179
|
-
* entry. Pure — no Electron dependency — so the trust posture is
|
|
180
|
-
* unit-testable without a running dialog.
|
|
181
|
-
*
|
|
182
|
-
* @param {{
|
|
183
|
-
* id: string,
|
|
184
|
-
* name?: string,
|
|
185
|
-
* security_tier?: "verified" | "community" | "experimental",
|
|
186
|
-
* permissions?: string[],
|
|
187
|
-
* } | null | undefined} entry — the agent's catalog entry.
|
|
188
|
-
* @returns {{ title: string, message: string, detail: string, requiresTrust: boolean }}
|
|
189
|
-
* @throws {Error} if no entry is given — never build a prompt for an agent
|
|
190
|
-
* that couldn't be looked up; the caller must fail closed instead.
|
|
191
|
-
*/
|
|
192
|
-
function buildInstallPrompt(entry) {
|
|
193
|
-
if (!entry || typeof entry !== "object") {
|
|
194
|
-
throw new Error(
|
|
195
|
-
"buildInstallPrompt requires a catalog entry — refuse rather than prompting blind."
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const tier = normalizeTier(entry);
|
|
200
|
-
const requiresTrust = tier !== "verified";
|
|
201
|
-
const name = entry.name || entry.id;
|
|
202
|
-
const permissions = Array.isArray(entry.permissions) ? entry.permissions : [];
|
|
203
|
-
|
|
204
|
-
const detail = [
|
|
205
|
-
`Tier: ${TIER_LABEL[tier]}${requiresTrust ? " — NOT AMD-verified" : ""}`,
|
|
206
|
-
permissions.length
|
|
207
|
-
? `Permissions: ${permissions.join(", ")}`
|
|
208
|
-
: "Permissions: none declared",
|
|
209
|
-
requiresTrust
|
|
210
|
-
? "This agent has not been audited by AMD. Only continue if you trust the " +
|
|
211
|
-
"publisher — installing downloads and runs third-party code on your machine."
|
|
212
|
-
: "This agent has been reviewed and verified by AMD.",
|
|
213
|
-
].join("\n\n");
|
|
214
|
-
|
|
215
|
-
return {
|
|
216
|
-
title: requiresTrust
|
|
217
|
-
? "Install untrusted agent from the web?"
|
|
218
|
-
: "Install agent from the web?",
|
|
219
|
-
message: `A website asked GAIA to install "${name}" (${entry.id}).`,
|
|
220
|
-
detail,
|
|
221
|
-
requiresTrust,
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
module.exports = {
|
|
226
|
-
parseDeepLink,
|
|
227
|
-
extractDeepLinkFromArgv,
|
|
228
|
-
dispatchDeepLink,
|
|
229
|
-
buildInstallPrompt,
|
|
230
|
-
};
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
// Copyright(C) 2025-2026 Advanced Micro Devices, Inc. All rights reserved.
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* GAIA Agent UI — System metrics collection (issue #2007)
|
|
6
|
-
*
|
|
7
|
-
* Collects real host metrics (CPU, memory, disk, network, per-process
|
|
8
|
-
* usage) for the observability dashboard and exposes them to the
|
|
9
|
-
* renderer over the `system:get-metrics` IPC channel. The shape matches
|
|
10
|
-
* the renderer's `SystemMetrics` type (src/types/agent.ts).
|
|
11
|
-
*
|
|
12
|
-
* GPU/NPU utilization is intentionally omitted (left `undefined`): there
|
|
13
|
-
* is no dependency-free cross-platform source for it, and the renderer
|
|
14
|
-
* type marks those fields optional — `undefined` renders as
|
|
15
|
-
* "unavailable", never as a fake zero.
|
|
16
|
-
*
|
|
17
|
-
* Errors propagate: a failing source rejects the IPC invoke so the
|
|
18
|
-
* renderer can surface it. No silent nulls.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
"use strict";
|
|
22
|
-
|
|
23
|
-
const fs = require("fs");
|
|
24
|
-
const os = require("os");
|
|
25
|
-
const { app, ipcMain } = require("electron");
|
|
26
|
-
|
|
27
|
-
const SYSTEM_GET_METRICS_CHANNEL = "system:get-metrics";
|
|
28
|
-
|
|
29
|
-
const BYTES_PER_GB = 1024 * 1024 * 1024;
|
|
30
|
-
|
|
31
|
-
/** Minimum sampling window for the very first CPU reading (ms). */
|
|
32
|
-
const FIRST_CPU_SAMPLE_MS = 120;
|
|
33
|
-
|
|
34
|
-
// Previous aggregate CPU times — CPU% is a delta between two samples.
|
|
35
|
-
let prevCpuTimes = null;
|
|
36
|
-
|
|
37
|
-
function readCpuTimes() {
|
|
38
|
-
let idle = 0;
|
|
39
|
-
let total = 0;
|
|
40
|
-
for (const cpu of os.cpus()) {
|
|
41
|
-
for (const [kind, ms] of Object.entries(cpu.times)) {
|
|
42
|
-
total += ms;
|
|
43
|
-
if (kind === "idle") idle += ms;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return { idle, total };
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function cpuPercentBetween(prev, curr) {
|
|
50
|
-
const totalDelta = curr.total - prev.total;
|
|
51
|
-
const idleDelta = curr.idle - prev.idle;
|
|
52
|
-
if (totalDelta <= 0) return 0;
|
|
53
|
-
const pct = (1 - idleDelta / totalDelta) * 100;
|
|
54
|
-
return Math.min(100, Math.max(0, pct));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async function sampleCpuPercent() {
|
|
58
|
-
if (prevCpuTimes === null) {
|
|
59
|
-
// First call: take a short two-point sample so the reading is real,
|
|
60
|
-
// not a since-boot average.
|
|
61
|
-
prevCpuTimes = readCpuTimes();
|
|
62
|
-
await new Promise((r) => setTimeout(r, FIRST_CPU_SAMPLE_MS));
|
|
63
|
-
}
|
|
64
|
-
const curr = readCpuTimes();
|
|
65
|
-
const pct = cpuPercentBetween(prevCpuTimes, curr);
|
|
66
|
-
prevCpuTimes = curr;
|
|
67
|
-
return pct;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async function readDiskUsage(diskPath) {
|
|
71
|
-
let stat;
|
|
72
|
-
try {
|
|
73
|
-
stat = await fs.promises.statfs(diskPath);
|
|
74
|
-
} catch (err) {
|
|
75
|
-
throw new Error(
|
|
76
|
-
`Failed to read disk usage for ${diskPath}: ${err.message}. ` +
|
|
77
|
-
"The observability dashboard needs a readable filesystem path — " +
|
|
78
|
-
"check that the path exists and is accessible."
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
const totalBytes = stat.blocks * stat.bsize;
|
|
82
|
-
const freeBytes = stat.bfree * stat.bsize;
|
|
83
|
-
return {
|
|
84
|
-
diskUsedGB: (totalBytes - freeBytes) / BYTES_PER_GB,
|
|
85
|
-
diskTotalGB: totalBytes / BYTES_PER_GB,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function readProcesses(now) {
|
|
90
|
-
// Electron's own process tree (main, renderer, GPU, utility) — the
|
|
91
|
-
// processes this app can meaningfully report on without a system-wide
|
|
92
|
-
// process scanner dependency.
|
|
93
|
-
return app.getAppMetrics().map((p) => ({
|
|
94
|
-
pid: p.pid,
|
|
95
|
-
name: p.name || p.serviceName || p.type,
|
|
96
|
-
cpuPercent: p.cpu.percentCPUUsage,
|
|
97
|
-
memoryMB: p.memory.workingSetSize / 1024, // workingSetSize is in KB
|
|
98
|
-
uptime: p.creationTime ? Math.max(0, (now - p.creationTime) / 1000) : 0,
|
|
99
|
-
}));
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function readNetworkUp() {
|
|
103
|
-
return Object.values(os.networkInterfaces()).some((addrs) =>
|
|
104
|
-
(addrs || []).some((a) => !a.internal)
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Collect a full SystemMetrics snapshot from the real host.
|
|
110
|
-
*
|
|
111
|
-
* @param {object} [options]
|
|
112
|
-
* @param {string} [options.diskPath] Filesystem path to report disk usage
|
|
113
|
-
* for (defaults to the user's home directory).
|
|
114
|
-
* @returns {Promise<object>} SystemMetrics-shaped snapshot.
|
|
115
|
-
*/
|
|
116
|
-
async function collectSystemMetrics(options = {}) {
|
|
117
|
-
const diskPath = options.diskPath || os.homedir();
|
|
118
|
-
|
|
119
|
-
const [cpuPercent, disk] = await Promise.all([
|
|
120
|
-
sampleCpuPercent(),
|
|
121
|
-
readDiskUsage(diskPath),
|
|
122
|
-
]);
|
|
123
|
-
|
|
124
|
-
const totalMem = os.totalmem();
|
|
125
|
-
const freeMem = os.freemem();
|
|
126
|
-
const now = Date.now();
|
|
127
|
-
|
|
128
|
-
return {
|
|
129
|
-
cpuPercent,
|
|
130
|
-
memoryUsedGB: (totalMem - freeMem) / BYTES_PER_GB,
|
|
131
|
-
memoryTotalGB: totalMem / BYTES_PER_GB,
|
|
132
|
-
diskUsedGB: disk.diskUsedGB,
|
|
133
|
-
diskTotalGB: disk.diskTotalGB,
|
|
134
|
-
networkUp: readNetworkUp(),
|
|
135
|
-
processes: readProcesses(now),
|
|
136
|
-
timestamp: now,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Register the `system:get-metrics` IPC handler. Collection errors reject
|
|
142
|
-
* the renderer's invoke() so the store can surface them.
|
|
143
|
-
*/
|
|
144
|
-
function registerIpcHandlers() {
|
|
145
|
-
ipcMain.handle(SYSTEM_GET_METRICS_CHANNEL, async () => {
|
|
146
|
-
return collectSystemMetrics();
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
module.exports = {
|
|
151
|
-
collectSystemMetrics,
|
|
152
|
-
registerIpcHandlers,
|
|
153
|
-
SYSTEM_GET_METRICS_CHANNEL,
|
|
154
|
-
};
|