@amd-gaia/agent-ui 0.27.0-rc.8 → 0.27.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/bin/gaia-ui.cjs +57 -3
- package/dist/assets/AdvancedSettings-R8_C2uBe.js +1 -0
- package/dist/assets/AutomationsSettings-B3zbjgZt.js +1 -0
- package/dist/assets/ConnectorsPane-BxG6qzLb.css +1 -0
- package/dist/assets/ConnectorsPane-BzcyOZRr.js +1 -0
- package/dist/assets/{DocumentLibrary-fEMoY7lH.css → DocumentLibrary-Ctwq2m2t.css} +1 -1
- package/dist/assets/DocumentLibrary-o3Fy8URO.js +5 -0
- package/dist/assets/FileBrowser-DxS29ShT.css +1 -0
- package/dist/assets/FileBrowser-_6Dx8AKt.js +4 -0
- package/dist/assets/MemoryDashboard-Bfy9g6TS.css +1 -0
- package/dist/assets/MemoryDashboard-ao_en1zm.js +1 -0
- package/dist/assets/MessagingSettings-DJq0F5BO.js +1 -0
- package/dist/assets/{MobileAccessModal-BrZMaERi.css → MobileAccessModal-DSFjH6di.css} +1 -1
- package/dist/assets/MobileAccessModal-ld0MPTgk.js +2 -0
- package/dist/assets/ScheduleManager-CEBoBLPV.css +1 -0
- package/dist/assets/ScheduleManager-px6Ly00O.js +1 -0
- package/dist/assets/folderIndexResult-BIoxqF5I.js +1 -0
- package/dist/assets/index-DXyVxzzC.css +1 -0
- package/dist/assets/index-Qh2EUbOw.js +226 -0
- package/dist/assets/useFocusTrap-Cy_PGcml.js +6 -0
- package/dist/index.html +3 -3
- package/dist/sw.js +1 -1
- package/main-safety-net.cjs +26 -2
- package/main.cjs +196 -58
- package/package.json +2 -2
- package/services/backend-crash-dialog.cjs +19 -5
- package/services/backend-health-monitor.cjs +86 -0
- package/services/backend-installer.cjs +1 -0
- package/services/backend-supervisor.cjs +35 -9
- package/services/browser-pane/dev-servers.cjs +44 -1
- package/services/browser-pane/listen-addresses.cjs +140 -0
- package/services/context-menu.cjs +79 -0
- package/services/link-policy.cjs +78 -7
- package/services/port-manager.cjs +2 -3
- package/services/process-tree.cjs +84 -14
- package/services/quit-guard.cjs +8 -4
- package/services/ui-token.cjs +156 -0
- package/dist/assets/AdvancedSettings-DPIu61Ug.js +0 -1
- package/dist/assets/AutomationsSettings-B-JefRcu.js +0 -1
- package/dist/assets/ConnectorsPane-BGI8nBUb.css +0 -1
- package/dist/assets/ConnectorsPane-DR1BXwSE.js +0 -1
- package/dist/assets/DocumentLibrary-je0OG0yL.js +0 -5
- package/dist/assets/FileBrowser-1goNp4CP.css +0 -1
- package/dist/assets/FileBrowser-CsVRdbcE.js +0 -4
- package/dist/assets/MemoryDashboard-CeioRY3q.js +0 -1
- package/dist/assets/MemoryDashboard-RpfLag-v.css +0 -1
- package/dist/assets/MessagingSettings-naPht5_K.js +0 -1
- package/dist/assets/MobileAccessModal-Bi6c7ior.js +0 -2
- package/dist/assets/ScheduleManager-BZzEH2-W.css +0 -1
- package/dist/assets/ScheduleManager-Dod2vW7s.js +0 -1
- package/dist/assets/index-B5hpAuDg.css +0 -1
- package/dist/assets/index-BLw-Jjdx.js +0 -222
- package/dist/assets/useFocusTrap-ChaVFhZD.js +0 -6
package/dist/index.html
CHANGED
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
// main.tsx applies the theme again and reports why it could not read the saved one.
|
|
27
27
|
}
|
|
28
28
|
</script>
|
|
29
|
-
<script type="module" crossorigin src="./assets/index-
|
|
29
|
+
<script type="module" crossorigin src="./assets/index-Qh2EUbOw.js"></script>
|
|
30
30
|
<link rel="modulepreload" crossorigin href="./assets/rolldown-runtime-XKyaHtl9.js">
|
|
31
|
-
<link rel="modulepreload" crossorigin href="./assets/useFocusTrap-
|
|
32
|
-
<link rel="stylesheet" crossorigin href="./assets/index-
|
|
31
|
+
<link rel="modulepreload" crossorigin href="./assets/useFocusTrap-Cy_PGcml.js">
|
|
32
|
+
<link rel="stylesheet" crossorigin href="./assets/index-DXyVxzzC.css">
|
|
33
33
|
</head>
|
|
34
34
|
<body>
|
|
35
35
|
<div id="root"></div>
|
package/dist/sw.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// never sees a stale UI or stale data.
|
|
10
10
|
|
|
11
11
|
const CACHE_PREFIX = 'gaia-assets-';
|
|
12
|
-
const CACHE_NAME = CACHE_PREFIX + '0.27.
|
|
12
|
+
const CACHE_NAME = CACHE_PREFIX + '0.27.0-5fdd5c532967f1ef';
|
|
13
13
|
const ASSETS_PATH = new URL('assets/', self.registration.scope).pathname;
|
|
14
14
|
|
|
15
15
|
self.addEventListener('install', () => {
|
package/main-safety-net.cjs
CHANGED
|
@@ -87,6 +87,9 @@ function appendLog(logPath, msg) {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
// Chats live in the backend's database, written as each message is sent.
|
|
91
|
+
const FATAL_MESSAGE = "GAIA ran into a problem and needs to restart. Your chats are saved.";
|
|
92
|
+
|
|
90
93
|
/** How long a fatal error's quit may take before the process is ended outright (ms). */
|
|
91
94
|
const FATAL_EXIT_GRACE_MS = 25000;
|
|
92
95
|
|
|
@@ -107,6 +110,9 @@ const FATAL_EXIT_GRACE_MS = 25000;
|
|
|
107
110
|
* when a window's page dies while GAIA runs on, e.g. to offer a reload.
|
|
108
111
|
* Without it, or if it throws synchronously, the crash is fatal; an async
|
|
109
112
|
* handler must handle its own failures.
|
|
113
|
+
* @param {Function} [opts.isPanePage] - Called with a webContents whose page
|
|
114
|
+
* died; true means it is a browser-pane tab, which shows its own notice, so
|
|
115
|
+
* the crash is logged only: no dialog, no quit, no crash count.
|
|
110
116
|
*/
|
|
111
117
|
function installSafetyNet({
|
|
112
118
|
logPath,
|
|
@@ -117,6 +123,7 @@ function installSafetyNet({
|
|
|
117
123
|
exitGraceMs = FATAL_EXIT_GRACE_MS,
|
|
118
124
|
holdCrashCount = () => false,
|
|
119
125
|
onRendererGone,
|
|
126
|
+
isPanePage,
|
|
120
127
|
}) {
|
|
121
128
|
const homedir = homedirFn || (() => os.homedir());
|
|
122
129
|
|
|
@@ -179,11 +186,12 @@ function installSafetyNet({
|
|
|
179
186
|
dialogModule.showMessageBoxSync({
|
|
180
187
|
type: "error",
|
|
181
188
|
title: "GAIA crashed",
|
|
182
|
-
message:
|
|
189
|
+
message: FATAL_MESSAGE,
|
|
190
|
+
detail: stack,
|
|
183
191
|
buttons: ["OK"],
|
|
184
192
|
});
|
|
185
193
|
} else {
|
|
186
|
-
dialogModule.showErrorBox("GAIA failed to start", stack);
|
|
194
|
+
dialogModule.showErrorBox("GAIA failed to start", `${FATAL_MESSAGE}\n\n${stack}`);
|
|
187
195
|
}
|
|
188
196
|
} catch { } // intentional: fatal path, no upstream
|
|
189
197
|
|
|
@@ -214,6 +222,21 @@ function installSafetyNet({
|
|
|
214
222
|
appendLog(logPath, `[${new Date().toISOString()}] RENDER_PROCESS_EXITED reason=${reason}`);
|
|
215
223
|
return;
|
|
216
224
|
}
|
|
225
|
+
if (typeof isPanePage === "function") {
|
|
226
|
+
let panePage = false;
|
|
227
|
+
try {
|
|
228
|
+
panePage = isPanePage(webContents) === true;
|
|
229
|
+
} catch (err) {
|
|
230
|
+
appendLog(logPath, `[${new Date().toISOString()}] RENDER_PROCESS_GONE pane check failed: ${err.stack || err}`);
|
|
231
|
+
}
|
|
232
|
+
if (panePage) {
|
|
233
|
+
appendLog(
|
|
234
|
+
logPath,
|
|
235
|
+
`[${new Date().toISOString()}] PANE_PAGE_GONE reason=${reason} exitCode=${details && details.exitCode}`
|
|
236
|
+
);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
217
240
|
if (typeof onRendererGone === "function") {
|
|
218
241
|
// Only the page died: the backend and agents still run, so the window can come back.
|
|
219
242
|
appendLog(
|
|
@@ -348,6 +371,7 @@ module.exports = {
|
|
|
348
371
|
installSafetyNet,
|
|
349
372
|
installLogTee,
|
|
350
373
|
FATAL_EXIT_GRACE_MS,
|
|
374
|
+
FATAL_MESSAGE,
|
|
351
375
|
readCount,
|
|
352
376
|
runSafeModePrompt,
|
|
353
377
|
SAFE_MODE_THRESHOLD,
|
package/main.cjs
CHANGED
|
@@ -17,6 +17,7 @@ const {
|
|
|
17
17
|
app,
|
|
18
18
|
autoUpdater: electronAutoUpdater,
|
|
19
19
|
BrowserWindow,
|
|
20
|
+
clipboard,
|
|
20
21
|
Menu,
|
|
21
22
|
dialog,
|
|
22
23
|
ipcMain,
|
|
@@ -71,6 +72,8 @@ try {
|
|
|
71
72
|
onRendererGone: (contents, details) => {
|
|
72
73
|
void handleRendererGone(contents, details);
|
|
73
74
|
},
|
|
75
|
+
// A pane tab's crash is the pane's to report ("Reload to try again"), not GAIA's.
|
|
76
|
+
isPanePage: (contents) => contents.session === session.fromPartition(PANE_PARTITION),
|
|
74
77
|
}));
|
|
75
78
|
} catch (err) {
|
|
76
79
|
try { process.stderr.write(`[main] safety-net load failed: ${err.message}\n`); } catch { }
|
|
@@ -113,6 +116,7 @@ const {
|
|
|
113
116
|
const { showBackendCrashDialog } = require("./services/backend-crash-dialog.cjs");
|
|
114
117
|
const { showRendererGoneDialog } = require("./services/renderer-gone-dialog.cjs");
|
|
115
118
|
const { createBackendSupervisor } = require("./services/backend-supervisor.cjs");
|
|
119
|
+
const { createBackendHealthMonitor } = require("./services/backend-health-monitor.cjs");
|
|
116
120
|
const { buildIndexQuery, INSTALL_SCREEN_QUERY } = require("./services/index-query.cjs");
|
|
117
121
|
const backendInstaller = require("./services/backend-installer.cjs");
|
|
118
122
|
const { createEngineInstall } = require("./services/engine-install.cjs");
|
|
@@ -123,11 +127,16 @@ const {
|
|
|
123
127
|
isAllowedExternalUrl,
|
|
124
128
|
isInAppNavigation,
|
|
125
129
|
describeBlockedUrl,
|
|
130
|
+
describeOpenFailure,
|
|
131
|
+
openExternalSafely,
|
|
132
|
+
linkNoticeText,
|
|
126
133
|
} = require("./services/link-policy.cjs");
|
|
127
134
|
const { installWindowKeys } = require("./services/window-keys.cjs");
|
|
135
|
+
const { installContextMenu } = require("./services/context-menu.cjs");
|
|
128
136
|
const { installQuitCleanup } = require("./services/quit-cleanup.cjs");
|
|
129
137
|
const { chromiumSwitches } = require("./services/chromium-switches.cjs");
|
|
130
138
|
const { titleBarKind, titleBarOptions } = require("./services/window-frame.cjs");
|
|
139
|
+
const { installBackendAuth } = require("./services/ui-token.cjs");
|
|
131
140
|
const { resolveDevQaMode } = require("./services/dev-qa-mode.cjs");
|
|
132
141
|
const { createBrowserPaneService, PANE_PARTITION } = require("./services/browser-pane/ipc.cjs");
|
|
133
142
|
const { DevServerSupervisor } = require("./services/browser-pane/dev-servers.cjs");
|
|
@@ -227,6 +236,7 @@ const APP_NAME = "GAIA";
|
|
|
227
236
|
// from prior aborted sessions (issue #782 / T5).
|
|
228
237
|
const DEFAULT_BACKEND_PORT = 4200;
|
|
229
238
|
const STARTUP_TIMEOUT = 30000;
|
|
239
|
+
const BACKEND_HEALTH_CHECK_TIMEOUT = 2000;
|
|
230
240
|
// A restart must answer within this, or it counts as a failed try.
|
|
231
241
|
const RESTART_TIMEOUT = 90000;
|
|
232
242
|
|
|
@@ -258,6 +268,9 @@ const windowConfig = appConfig.window || {
|
|
|
258
268
|
// ── State ──────────────────────────────────────────────────────────────────
|
|
259
269
|
|
|
260
270
|
let backendProcess = null;
|
|
271
|
+
let backendCleanupPending = null;
|
|
272
|
+
let backendHealthMonitoringEnabled = false;
|
|
273
|
+
let backendHealthMonitor = null;
|
|
261
274
|
// The in-flight startBackend(), so a quit during startup can wait for the
|
|
262
275
|
// spawn and stop it instead of leaving it behind.
|
|
263
276
|
let backendStarting = null;
|
|
@@ -266,6 +279,8 @@ let shutdownStarted = false;
|
|
|
266
279
|
// Set once an update install starts quitting the app.
|
|
267
280
|
let updateQuitStarted = false;
|
|
268
281
|
let backendPort = DEFAULT_BACKEND_PORT;
|
|
282
|
+
// The port of the backend this app spawned; only it is sent the API token.
|
|
283
|
+
let spawnedBackendPort = null;
|
|
269
284
|
let healthCheckUrl = `http://localhost:${backendPort}/api/health`;
|
|
270
285
|
let backendStderrTail = [];
|
|
271
286
|
let isIntentionalKill = false;
|
|
@@ -345,6 +360,15 @@ async function cleanupOrphanedBackend() {
|
|
|
345
360
|
});
|
|
346
361
|
}
|
|
347
362
|
|
|
363
|
+
/** What the user reads when GAIA's backend program can't be found: what to do, and where it looked. */
|
|
364
|
+
function missingBackendMessage() {
|
|
365
|
+
const looked = [backendInstaller.BUNDLED_GAIA_BIN, backendInstaller.GAIA_BIN].filter(Boolean).join(", ");
|
|
366
|
+
return (
|
|
367
|
+
"GAIA's backend program is missing, so GAIA can't start: the app's files are incomplete. " +
|
|
368
|
+
`Reinstall GAIA from https://amd-gaia.ai/#install. Looked for ${looked} and for gaia on PATH.`
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
|
|
348
372
|
/**
|
|
349
373
|
* Start the GAIA Python backend. Expects the backend installer to have
|
|
350
374
|
* already ensured the venv is populated — callers should await
|
|
@@ -382,6 +406,8 @@ async function startBackend() {
|
|
|
382
406
|
if (!devQa) await cleanupOrphanedBackend();
|
|
383
407
|
|
|
384
408
|
console.log(`Starting backend: ${gaiaCmd} chat --ui --ui-port ${backendPort}`);
|
|
409
|
+
spawnedBackendPort = backendPort;
|
|
410
|
+
const childPort = backendPort;
|
|
385
411
|
|
|
386
412
|
// Reset per-spawn state so a fresh crash dialog doesn't mix tails.
|
|
387
413
|
backendStderrTail = [];
|
|
@@ -457,6 +483,8 @@ async function startBackend() {
|
|
|
457
483
|
console.error(`Backend exited with code ${code} (signal=${signal}, pid=${child.pid})`);
|
|
458
484
|
}
|
|
459
485
|
if (backendProcess === child) backendProcess = null;
|
|
486
|
+
// Whatever binds the port next is not ours, so it gets no token.
|
|
487
|
+
if (spawnedBackendPort === childPort) spawnedBackendPort = null;
|
|
460
488
|
if (trayManager && !isQuitting) trayManager.setBackendAlive(false);
|
|
461
489
|
|
|
462
490
|
// Once restarts run out, the supervisor's onStopped shows the crash dialog.
|
|
@@ -482,19 +510,47 @@ async function startBackend() {
|
|
|
482
510
|
return child;
|
|
483
511
|
}
|
|
484
512
|
|
|
513
|
+
/** Stop a backend tree and keep its handle pending until termination is verified. */
|
|
514
|
+
async function stopBackendTree(proc) {
|
|
515
|
+
backendCleanupPending = proc;
|
|
516
|
+
isIntentionalKill = true;
|
|
517
|
+
try {
|
|
518
|
+
const result = await portManager.killBackend(proc);
|
|
519
|
+
if (!result || !Array.isArray(result.survivors)) {
|
|
520
|
+
throw new Error("The backend stop did not confirm that its process tree exited.");
|
|
521
|
+
}
|
|
522
|
+
if (result.survivors.length) {
|
|
523
|
+
throw new Error(`The backend process tree is still running (pid ${result.survivors.join(", ")}).`);
|
|
524
|
+
}
|
|
525
|
+
if (result.verified !== true) {
|
|
526
|
+
throw new Error(
|
|
527
|
+
"The backend process tree could not be verified as stopped. " +
|
|
528
|
+
"Quit GAIA, end any leftover GAIA or Python processes in Task Manager, then reopen GAIA."
|
|
529
|
+
);
|
|
530
|
+
}
|
|
531
|
+
} catch (err) {
|
|
532
|
+
isIntentionalKill = false;
|
|
533
|
+
throw err;
|
|
534
|
+
}
|
|
535
|
+
if (backendCleanupPending === proc) backendCleanupPending = null;
|
|
536
|
+
if (backendProcess === proc) backendProcess = null;
|
|
537
|
+
}
|
|
538
|
+
|
|
485
539
|
/**
|
|
486
540
|
* Start a new backend for the supervisor and resolve once it answers.
|
|
487
541
|
* Rejects when it exits first or never answers, so the supervisor retries.
|
|
542
|
+
* A backend still alive here is a hung one Restart GAIA was pressed for:
|
|
543
|
+
* stop it first, or the new backend would run beside it on a new port.
|
|
488
544
|
*/
|
|
489
545
|
async function restartBackend() {
|
|
546
|
+
const previousBackend = backendCleanupPending || backendProcess;
|
|
547
|
+
if (previousBackend) await stopBackendTree(previousBackend);
|
|
548
|
+
|
|
490
549
|
backendStarting = startBackend();
|
|
491
550
|
const child = await backendStarting;
|
|
492
|
-
if (!child) {
|
|
493
|
-
throw new Error("GAIA's backend program is missing, so it can't restart. Reinstall GAIA.");
|
|
494
|
-
}
|
|
551
|
+
if (!child) throw Object.assign(new Error(missingBackendMessage()), { terminal: true });
|
|
495
552
|
if (quitStarted()) {
|
|
496
|
-
|
|
497
|
-
await portManager.killBackend(child);
|
|
553
|
+
await stopBackendTree(child);
|
|
498
554
|
throw new Error("GAIA is quitting, so the restarted backend was stopped.");
|
|
499
555
|
}
|
|
500
556
|
backendProcess = child;
|
|
@@ -504,10 +560,10 @@ async function restartBackend() {
|
|
|
504
560
|
if (!alive()) {
|
|
505
561
|
throw new Error(`The backend exited (code ${child.exitCode}, signal ${child.signalCode}) before it answered.`);
|
|
506
562
|
}
|
|
507
|
-
|
|
508
|
-
await portManager.killBackend(child);
|
|
563
|
+
await stopBackendTree(child);
|
|
509
564
|
throw new Error(`The backend did not answer within ${RESTART_TIMEOUT / 1000} s.`);
|
|
510
565
|
}
|
|
566
|
+
enableBackendHealthMonitoring();
|
|
511
567
|
console.log(`[main] Backend restarted on port ${backendPort} (pid=${child.pid})`);
|
|
512
568
|
if (trayManager) {
|
|
513
569
|
trayManager.setBackendPort(backendPort);
|
|
@@ -524,21 +580,42 @@ function backendStateForRenderer(state) {
|
|
|
524
580
|
const backendSupervisor = createBackendSupervisor({
|
|
525
581
|
start: restartBackend,
|
|
526
582
|
onStopped: (state) => {
|
|
527
|
-
|
|
528
|
-
void handleBackendCrash(code, signal);
|
|
583
|
+
void handleBackendCrash(state);
|
|
529
584
|
},
|
|
530
585
|
onState: (state) => {
|
|
586
|
+
if (backendHealthMonitor) {
|
|
587
|
+
if (backendHealthMonitoringEnabled && state.status === "running") backendHealthMonitor.start();
|
|
588
|
+
else backendHealthMonitor.stop();
|
|
589
|
+
}
|
|
531
590
|
console.log(
|
|
532
591
|
`[main] Backend ${state.status}` +
|
|
533
592
|
(state.status === "restarting" ? ` (try ${state.attempt} of ${state.maxRestarts})` : "") +
|
|
534
593
|
(state.lastError ? `: ${state.lastError}` : "")
|
|
535
594
|
);
|
|
595
|
+
// A backend up again after a failed start leaves nothing to roll back from.
|
|
596
|
+
if (state.status === "running") autoUpdater.clearStartFailure();
|
|
536
597
|
if (mainWindow && !mainWindow.isDestroyed()) {
|
|
537
598
|
mainWindow.webContents.send("backend:state", backendStateForRenderer(state));
|
|
538
599
|
}
|
|
539
600
|
},
|
|
540
601
|
});
|
|
541
602
|
|
|
603
|
+
backendHealthMonitor = createBackendHealthMonitor({
|
|
604
|
+
check: checkBackendHealth,
|
|
605
|
+
onUnhealthy: (error, failures) => {
|
|
606
|
+
const message = error && error.message ? error.message : String(error);
|
|
607
|
+
const reason = new Error(`Health check failed ${failures} consecutive times: ${message}`);
|
|
608
|
+
console.warn(`[main] ${reason.message}`);
|
|
609
|
+
backendSupervisor.healthFailed(reason);
|
|
610
|
+
},
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
function enableBackendHealthMonitoring() {
|
|
614
|
+
if (quitStarted()) return;
|
|
615
|
+
backendHealthMonitoringEnabled = true;
|
|
616
|
+
if (backendSupervisor.getState().status === "running") backendHealthMonitor.start();
|
|
617
|
+
}
|
|
618
|
+
|
|
542
619
|
ipcMain.handle("backend:get-state", () => backendStateForRenderer(backendSupervisor.getState()));
|
|
543
620
|
ipcMain.handle("backend:restart", () => {
|
|
544
621
|
backendSupervisor.restartNow();
|
|
@@ -549,7 +626,8 @@ ipcMain.handle("backend:restart", () => {
|
|
|
549
626
|
* Tell the user the backend stopped and offer Restart / Save diagnostics /
|
|
550
627
|
* Quit. Invoked by the supervisor's onStopped once automatic restarts run out.
|
|
551
628
|
*/
|
|
552
|
-
async function handleBackendCrash(
|
|
629
|
+
async function handleBackendCrash(state) {
|
|
630
|
+
const { code = null, signal = null } = state.lastExit || {};
|
|
553
631
|
autoUpdater.reportStartFailure();
|
|
554
632
|
try {
|
|
555
633
|
const choice = await showBackendCrashDialog({
|
|
@@ -557,6 +635,7 @@ async function handleBackendCrash(code, signal) {
|
|
|
557
635
|
app,
|
|
558
636
|
code,
|
|
559
637
|
signal,
|
|
638
|
+
reason: state.lastError,
|
|
560
639
|
tailLines: backendStderrTail.slice(-8),
|
|
561
640
|
writeDiagnostics: () => portManager.writeDiagnosticsBundle(),
|
|
562
641
|
// The backend is gone, so there is no running work to ask about.
|
|
@@ -599,24 +678,10 @@ async function handleRendererGone(contents, { reason }) {
|
|
|
599
678
|
|
|
600
679
|
async function waitForBackend(timeoutMs, isAlive = () => true) {
|
|
601
680
|
const start = Date.now();
|
|
602
|
-
const http = require("http");
|
|
603
681
|
|
|
604
682
|
while (Date.now() - start < timeoutMs && isAlive()) {
|
|
605
683
|
try {
|
|
606
|
-
await
|
|
607
|
-
const req = http.get(healthCheckUrl, (res) => {
|
|
608
|
-
if (res.statusCode === 200) {
|
|
609
|
-
resolve();
|
|
610
|
-
} else {
|
|
611
|
-
reject(new Error(`Status ${res.statusCode}`));
|
|
612
|
-
}
|
|
613
|
-
});
|
|
614
|
-
req.on("error", reject);
|
|
615
|
-
req.setTimeout(2000, () => {
|
|
616
|
-
req.destroy();
|
|
617
|
-
reject(new Error("timeout"));
|
|
618
|
-
});
|
|
619
|
-
});
|
|
684
|
+
await checkBackendHealth();
|
|
620
685
|
return true;
|
|
621
686
|
} catch {
|
|
622
687
|
await new Promise((r) => setTimeout(r, 500));
|
|
@@ -625,6 +690,51 @@ async function waitForBackend(timeoutMs, isAlive = () => true) {
|
|
|
625
690
|
return false;
|
|
626
691
|
}
|
|
627
692
|
|
|
693
|
+
function checkBackendHealth(signal) {
|
|
694
|
+
const http = require("http");
|
|
695
|
+
return new Promise((resolve, reject) => {
|
|
696
|
+
let settled = false;
|
|
697
|
+
let deadline = null;
|
|
698
|
+
let req = null;
|
|
699
|
+
const onAbort = () => {
|
|
700
|
+
const error = new Error("Health check was cancelled.");
|
|
701
|
+
finish(reject, error);
|
|
702
|
+
req.destroy(error);
|
|
703
|
+
};
|
|
704
|
+
const finish = (handler, value) => {
|
|
705
|
+
if (settled) return;
|
|
706
|
+
settled = true;
|
|
707
|
+
if (deadline) clearTimeout(deadline);
|
|
708
|
+
if (signal) signal.removeEventListener("abort", onAbort);
|
|
709
|
+
handler(value);
|
|
710
|
+
};
|
|
711
|
+
req = http.get(healthCheckUrl, (res) => {
|
|
712
|
+
if (res.statusCode !== 200) {
|
|
713
|
+
finish(reject, new Error(`Health endpoint returned status ${res.statusCode}.`));
|
|
714
|
+
res.destroy();
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
res.once("end", () => finish(resolve));
|
|
718
|
+
res.once("aborted", () => finish(reject, new Error("Health endpoint response was aborted.")));
|
|
719
|
+
res.once("close", () => {
|
|
720
|
+
if (!res.complete) finish(reject, new Error("Health endpoint response closed before completion."));
|
|
721
|
+
});
|
|
722
|
+
res.once("error", (error) => finish(reject, error));
|
|
723
|
+
res.resume();
|
|
724
|
+
});
|
|
725
|
+
deadline = setTimeout(() => {
|
|
726
|
+
const error = new Error("Health endpoint did not answer within 2 s.");
|
|
727
|
+
finish(reject, error);
|
|
728
|
+
req.destroy(error);
|
|
729
|
+
}, BACKEND_HEALTH_CHECK_TIMEOUT);
|
|
730
|
+
req.once("error", (error) => finish(reject, error));
|
|
731
|
+
if (signal) {
|
|
732
|
+
if (signal.aborted) onAbort();
|
|
733
|
+
else signal.addEventListener("abort", onAbort, { once: true });
|
|
734
|
+
}
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
|
|
628
738
|
// ── Window ─────────────────────────────────────────────────────────────────
|
|
629
739
|
|
|
630
740
|
function findDistPath() {
|
|
@@ -645,21 +755,41 @@ function findDistPath() {
|
|
|
645
755
|
|
|
646
756
|
/** Refuse a link loudly — the user clicked it, so they get told why nothing happened. */
|
|
647
757
|
function reportBlockedLink(url) {
|
|
648
|
-
const
|
|
649
|
-
|
|
758
|
+
const locale = app.getLocale();
|
|
759
|
+
warnAboutLink(
|
|
760
|
+
linkNoticeText(locale).blockedTitle,
|
|
761
|
+
describeBlockedUrl(url, locale),
|
|
762
|
+
describeBlockedUrl(url),
|
|
763
|
+
locale,
|
|
764
|
+
);
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
function reportLinkNotOpened(url, err) {
|
|
768
|
+
const locale = app.getLocale();
|
|
769
|
+
warnAboutLink(
|
|
770
|
+
linkNoticeText(locale).notOpenedTitle,
|
|
771
|
+
describeOpenFailure(url, err, locale),
|
|
772
|
+
describeOpenFailure(url, err),
|
|
773
|
+
locale,
|
|
774
|
+
);
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
// The log line stays English so bug reports stay readable.
|
|
778
|
+
function warnAboutLink(title, message, logMessage, locale) {
|
|
779
|
+
console.error(`[main] ${logMessage}`);
|
|
650
780
|
// Non-blocking and parented: showErrorBox would freeze the main process.
|
|
651
781
|
dialog
|
|
652
782
|
.showMessageBox(mainWindow && !mainWindow.isDestroyed() ? mainWindow : null, {
|
|
653
783
|
type: "warning",
|
|
654
|
-
title
|
|
655
|
-
message:
|
|
784
|
+
title,
|
|
785
|
+
message: title,
|
|
656
786
|
detail: message,
|
|
657
|
-
buttons: [
|
|
787
|
+
buttons: [linkNoticeText(locale).ok],
|
|
658
788
|
noLink: true,
|
|
659
789
|
})
|
|
660
790
|
.catch((err) =>
|
|
661
791
|
console.error(
|
|
662
|
-
`[main] Could not show the
|
|
792
|
+
`[main] Could not show the "${title}" dialog: ${err && err.message ? err.message : err}`
|
|
663
793
|
)
|
|
664
794
|
);
|
|
665
795
|
}
|
|
@@ -726,13 +856,14 @@ function createWindow() {
|
|
|
726
856
|
installWindowKeys(mainWindow.webContents, { devTools: !app.isPackaged });
|
|
727
857
|
}
|
|
728
858
|
mainWindow.setMenuBarVisibility(false);
|
|
859
|
+
installContextMenu(mainWindow, { Menu, clipboard, locale: app.getLocale() });
|
|
729
860
|
|
|
730
861
|
// Open external links in the default browser. The URL here is already
|
|
731
862
|
// RESOLVED against the file:// document, so a scheme-less markdown link
|
|
732
863
|
// arrives as file:///C:/… — check the scheme before handing it to the OS.
|
|
733
864
|
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
|
|
734
865
|
if (isAllowedExternalUrl(url)) {
|
|
735
|
-
shell
|
|
866
|
+
openExternalSafely(shell, url, (err) => reportLinkNotOpened(url, err));
|
|
736
867
|
} else {
|
|
737
868
|
reportBlockedLink(url);
|
|
738
869
|
}
|
|
@@ -746,7 +877,7 @@ function createWindow() {
|
|
|
746
877
|
if (isInAppNavigation(url, currentUrl)) return;
|
|
747
878
|
event.preventDefault();
|
|
748
879
|
if (isAllowedExternalUrl(url)) {
|
|
749
|
-
shell
|
|
880
|
+
openExternalSafely(shell, url, (err) => reportLinkNotOpened(url, err));
|
|
750
881
|
return;
|
|
751
882
|
}
|
|
752
883
|
reportBlockedLink(url);
|
|
@@ -854,9 +985,11 @@ async function loadApp() {
|
|
|
854
985
|
</div>
|
|
855
986
|
</body>
|
|
856
987
|
</html>`;
|
|
857
|
-
mainWindow
|
|
858
|
-
"data:text/html;charset=utf-8," + encodeURIComponent(waitingHtml)
|
|
859
|
-
|
|
988
|
+
mainWindow
|
|
989
|
+
.loadURL("data:text/html;charset=utf-8," + encodeURIComponent(waitingHtml))
|
|
990
|
+
.catch((err) =>
|
|
991
|
+
console.error(`[main] Could not show the waiting page: ${err && err.message ? err.message : err}`)
|
|
992
|
+
);
|
|
860
993
|
}
|
|
861
994
|
}
|
|
862
995
|
|
|
@@ -973,22 +1106,13 @@ function setupJumpList() {
|
|
|
973
1106
|
items: [
|
|
974
1107
|
{
|
|
975
1108
|
type: "task",
|
|
976
|
-
title: "
|
|
977
|
-
description: "
|
|
1109
|
+
title: "Open GAIA",
|
|
1110
|
+
description: "Show the GAIA window",
|
|
978
1111
|
program: process.execPath,
|
|
979
1112
|
args: "",
|
|
980
1113
|
iconPath: process.execPath,
|
|
981
1114
|
iconIndex: 0,
|
|
982
1115
|
},
|
|
983
|
-
{
|
|
984
|
-
type: "task",
|
|
985
|
-
title: "Agent Manager",
|
|
986
|
-
description: "View and manage OS agents",
|
|
987
|
-
program: process.execPath,
|
|
988
|
-
args: "--show-agents",
|
|
989
|
-
iconPath: process.execPath,
|
|
990
|
-
iconIndex: 0,
|
|
991
|
-
},
|
|
992
1116
|
],
|
|
993
1117
|
},
|
|
994
1118
|
]);
|
|
@@ -1098,6 +1222,7 @@ app.whenReady().then(async () => {
|
|
|
1098
1222
|
// The window, and the tray that keeps a closed one reachable, come before
|
|
1099
1223
|
// anything that can take time, so an install runs in plain sight.
|
|
1100
1224
|
titleDownloadSaveDialogs();
|
|
1225
|
+
installBackendAuth(session.defaultSession, { getPort: () => spawnedBackendPort });
|
|
1101
1226
|
// Before the window: the desktop ties a window to its launcher when it appears.
|
|
1102
1227
|
if (app.isPackaged) {
|
|
1103
1228
|
try {
|
|
@@ -1180,7 +1305,9 @@ app.whenReady().then(async () => {
|
|
|
1180
1305
|
if (shutdownStarted) return;
|
|
1181
1306
|
backendStarting = startBackend();
|
|
1182
1307
|
backendProcess = await backendStarting;
|
|
1308
|
+
// The window reads this state and shows the failure instead of waiting for a backend.
|
|
1183
1309
|
if (backendProcess) backendSupervisor.running(backendPort);
|
|
1310
|
+
else backendSupervisor.failedToStart(missingBackendMessage());
|
|
1184
1311
|
if (shutdownStarted) {
|
|
1185
1312
|
console.log("[main] Quit during startup — not opening the window");
|
|
1186
1313
|
return;
|
|
@@ -1216,9 +1343,10 @@ app.whenReady().then(async () => {
|
|
|
1216
1343
|
let backendReady = false;
|
|
1217
1344
|
if (backendProcess) {
|
|
1218
1345
|
console.log("Waiting for backend to start...");
|
|
1219
|
-
backendReady = await waitForBackend(STARTUP_TIMEOUT);
|
|
1346
|
+
backendReady = await waitForBackend(STARTUP_TIMEOUT, () => !quitStarted());
|
|
1220
1347
|
if (backendReady) {
|
|
1221
1348
|
console.log("Backend API is ready on port", backendPort);
|
|
1349
|
+
enableBackendHealthMonitoring();
|
|
1222
1350
|
} else {
|
|
1223
1351
|
console.warn("Backend did not respond within timeout.");
|
|
1224
1352
|
}
|
|
@@ -1226,8 +1354,16 @@ app.whenReady().then(async () => {
|
|
|
1226
1354
|
if (!backendReady) {
|
|
1227
1355
|
autoUpdater.reportStartFailure();
|
|
1228
1356
|
if (backendProcess) {
|
|
1229
|
-
waitForBackend(STARTUP_TIMEOUT * 10).then((ready) => {
|
|
1230
|
-
if (ready)
|
|
1357
|
+
waitForBackend(STARTUP_TIMEOUT * 10, () => !quitStarted()).then((ready) => {
|
|
1358
|
+
if (ready) {
|
|
1359
|
+
autoUpdater.clearStartFailure();
|
|
1360
|
+
enableBackendHealthMonitoring();
|
|
1361
|
+
} else if (backendProcess && !quitStarted() && backendSupervisor.getState().status === "running") {
|
|
1362
|
+
backendHealthMonitoringEnabled = true;
|
|
1363
|
+
backendSupervisor.healthFailed(
|
|
1364
|
+
new Error("The backend health endpoint did not respond during the startup grace period.")
|
|
1365
|
+
);
|
|
1366
|
+
}
|
|
1231
1367
|
});
|
|
1232
1368
|
}
|
|
1233
1369
|
}
|
|
@@ -1313,6 +1449,7 @@ const quitGuard = installQuitGuard({
|
|
|
1313
1449
|
// Mark any subsequent backend exit as intentional so we don't pop the
|
|
1314
1450
|
// crash dialog during normal shutdown.
|
|
1315
1451
|
isIntentionalKill = true;
|
|
1452
|
+
backendHealthMonitor.stop();
|
|
1316
1453
|
backendSupervisor.stop();
|
|
1317
1454
|
},
|
|
1318
1455
|
onError: (err) => {
|
|
@@ -1328,6 +1465,7 @@ const quitGuard = installQuitGuard({
|
|
|
1328
1465
|
// The installer is already running: a restart now would hold its files open.
|
|
1329
1466
|
electronAutoUpdater.on("before-quit-for-update", () => {
|
|
1330
1467
|
updateQuitStarted = true;
|
|
1468
|
+
backendHealthMonitor.stop();
|
|
1331
1469
|
backendSupervisor.stop();
|
|
1332
1470
|
});
|
|
1333
1471
|
|
|
@@ -1337,6 +1475,7 @@ installQuitCleanup({ app, cleanup });
|
|
|
1337
1475
|
|
|
1338
1476
|
async function cleanup() {
|
|
1339
1477
|
shutdownStarted = true;
|
|
1478
|
+
backendHealthMonitor.stop();
|
|
1340
1479
|
backendSupervisor.stop();
|
|
1341
1480
|
const installStopped = engineInstall ? engineInstall.stop() : null;
|
|
1342
1481
|
const updating = app.isPackaged && autoUpdater.installsOnQuit();
|
|
@@ -1419,7 +1558,7 @@ async function stopBackendForQuit() {
|
|
|
1419
1558
|
if (backendStarting) {
|
|
1420
1559
|
try {
|
|
1421
1560
|
const started = await backendStarting;
|
|
1422
|
-
if (started && !backendProcess && started.exitCode === null && started.signalCode === null) {
|
|
1561
|
+
if (started && !backendProcess && !backendCleanupPending && started.exitCode === null && started.signalCode === null) {
|
|
1423
1562
|
backendProcess = started;
|
|
1424
1563
|
}
|
|
1425
1564
|
} catch (err) {
|
|
@@ -1431,17 +1570,16 @@ async function stopBackendForQuit() {
|
|
|
1431
1570
|
// (SIGTERM → wait 3 s → SIGKILL).
|
|
1432
1571
|
// F5: previously we did this inline; extracted so main.cjs stays lean and
|
|
1433
1572
|
// to prevent orphan leaks across runs (issue #782).
|
|
1434
|
-
|
|
1573
|
+
const processToStop = backendCleanupPending || backendProcess;
|
|
1574
|
+
if (processToStop) {
|
|
1435
1575
|
console.log("Stopping backend process...");
|
|
1436
|
-
const proc =
|
|
1576
|
+
const proc = processToStop;
|
|
1437
1577
|
backendProcess = null;
|
|
1438
|
-
isIntentionalKill = true;
|
|
1439
1578
|
|
|
1440
1579
|
try {
|
|
1441
|
-
// Pass the ChildProcess handle
|
|
1442
|
-
//
|
|
1443
|
-
|
|
1444
|
-
await portManager.killBackend(proc);
|
|
1580
|
+
// Pass the ChildProcess handle so the process-tree tracker can safely
|
|
1581
|
+
// retry descendants if the launcher exits during termination.
|
|
1582
|
+
await stopBackendTree(proc);
|
|
1445
1583
|
} catch (err) {
|
|
1446
1584
|
console.error("Error stopping backend:", err.message);
|
|
1447
1585
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amd-gaia/agent-ui",
|
|
3
|
-
"version": "0.27.0
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"productName": "GAIA Agent UI",
|
|
6
6
|
"desktopName": "gaia-desktop.desktop",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@playwright/test": "1.65.1",
|
|
74
|
-
"@testing-library/jest-dom": "^
|
|
74
|
+
"@testing-library/jest-dom": "^8.0.0",
|
|
75
75
|
"@testing-library/react": "^16.1.0",
|
|
76
76
|
"@testing-library/user-event": "^14.5.2",
|
|
77
77
|
"@types/react": "^19.2.17",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* The dialog shown when GAIA's backend
|
|
5
|
+
* The dialog shown when GAIA's backend cannot recover after an exit or outage. Every choice ends
|
|
6
6
|
* somewhere: Restart relaunches the app, Quit quits it, and Save diagnostics
|
|
7
7
|
* writes the bundle and comes back to the same choice.
|
|
8
8
|
*/
|
|
@@ -19,8 +19,11 @@ function stripAnsi(text) {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/** The dialog's detail text: what happened, what to do, then the log tail. */
|
|
22
|
-
function crashDetail(code, signal, tailLines) {
|
|
23
|
-
|
|
22
|
+
function crashDetail(code, signal, tailLines, reason) {
|
|
23
|
+
let how;
|
|
24
|
+
if (signal) how = `signal ${signal}`;
|
|
25
|
+
else if (code !== null && code !== undefined) how = `exit code ${code}`;
|
|
26
|
+
else how = `last error: ${reason || "unknown cause"}`;
|
|
24
27
|
const tail = (tailLines || []).map(stripAnsi).join("\n") || "(nothing was logged)";
|
|
25
28
|
return (
|
|
26
29
|
`GAIA's background service stopped unexpectedly (${how}). Your chats are saved.\n` +
|
|
@@ -50,8 +53,19 @@ function relaunchOptions(env = process.env, argv = process.argv) {
|
|
|
50
53
|
* @param {object} [deps.parent] window the dialog is modal to, e.g. mainWindow
|
|
51
54
|
* @returns {Promise<"restart"|"quit">}
|
|
52
55
|
*/
|
|
53
|
-
async function showBackendCrashDialog({
|
|
54
|
-
|
|
56
|
+
async function showBackendCrashDialog({
|
|
57
|
+
dialog,
|
|
58
|
+
app,
|
|
59
|
+
code,
|
|
60
|
+
signal,
|
|
61
|
+
reason,
|
|
62
|
+
tailLines,
|
|
63
|
+
writeDiagnostics,
|
|
64
|
+
beforeQuit,
|
|
65
|
+
env = process.env,
|
|
66
|
+
parent,
|
|
67
|
+
}) {
|
|
68
|
+
const detail = crashDetail(code, signal, tailLines, reason);
|
|
55
69
|
// Modal to GAIA's window and in front: unparented, it can open behind other apps.
|
|
56
70
|
const owner = parent && !parent.isDestroyed() ? parent : null;
|
|
57
71
|
if (owner) {
|