@amd-gaia/agent-ui 0.26.0-rc.2 → 0.26.0-rc.20
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/tray-iconTemplate.png +0 -0
- package/assets/tray-iconTemplate@2x.png +0 -0
- package/bin/gaia-ui.cjs +19 -16
- package/dist/assets/AdvancedSettings-CkNjaXeq.js +1 -0
- package/dist/assets/ConnectorsPane-hmunRyL2.css +1 -0
- package/dist/assets/ConnectorsPane-j0I-yE2y.js +1 -0
- package/dist/assets/DocumentLibrary-AavruIEt.js +4 -0
- package/dist/assets/{DocumentLibrary-CM6o8j2T.css → DocumentLibrary-DM09xPsW.css} +1 -1
- package/dist/assets/FileBrowser-BAWmtQqm.js +4 -0
- package/dist/assets/MemoryDashboard-BYQDFko-.css +1 -0
- package/dist/assets/MemoryDashboard-DXHAcjo5.js +1 -0
- package/dist/assets/MobileAccessModal-g7HdSxZe.js +2 -0
- package/dist/assets/ScheduleManager-D9rKlnaQ.js +1 -0
- package/dist/assets/{browser-KnDALPx_.js → browser-DfYHeeW3.js} +1 -1
- package/dist/assets/index-DvwJqseR.css +1 -0
- package/dist/assets/index-ZvSEroLw.js +90 -0
- package/dist/assets/useT-C_wp97pe.js +6 -0
- package/dist/assets/zap-DKK5PCxy.js +1 -0
- package/dist/index.html +3 -4
- package/dist/sw.js +1 -1
- package/main-safety-net.cjs +30 -3
- package/main.cjs +77 -220
- package/package.json +3 -3
- package/preload.cjs +0 -30
- package/services/agent-process-manager.cjs +3 -411
- package/services/appimage-launcher.cjs +183 -0
- package/services/auto-updater.cjs +10 -0
- package/services/backend-installer.cjs +230 -512
- 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-DhQOkz13.js +0 -1
- package/dist/assets/ConnectorsPane-CzLYXGMl.css +0 -1
- package/dist/assets/ConnectorsPane-DZSS3unX.js +0 -1
- package/dist/assets/DocumentLibrary-Bxi2x5Ry.js +0 -4
- package/dist/assets/FileBrowser-lOETG5oo.js +0 -4
- package/dist/assets/MemoryDashboard-DwrWAXi6.css +0 -1
- package/dist/assets/MemoryDashboard-Evh8x9AG.js +0 -1
- package/dist/assets/MobileAccessModal-jZP8OcFv.js +0 -2
- package/dist/assets/ScheduleManager-CoagpVqW.js +0 -1
- package/dist/assets/api-9RdlUJAP.js +0 -4
- package/dist/assets/index-D8wu2yy4.js +0 -83
- package/dist/assets/index-LLooEbjq.css +0 -1
- package/dist/assets/useT-C0ow1Kps.js +0 -3
- package/dist/assets/zap-D2mvP3-6.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
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Manages OS agent subprocesses (C++ MCP servers, .NET agents, Python agents).
|
|
8
8
|
* Each agent communicates via JSON-RPC 2.0 over stdio:
|
|
9
9
|
* - stdout → JSON-RPC messages (MCP protocol + GAIA extensions)
|
|
10
|
-
* - stderr → Structured log lines →
|
|
10
|
+
* - stderr → Structured log lines → kept in a per-agent buffer
|
|
11
11
|
* - stdin → JSON-RPC requests from the tray app
|
|
12
12
|
*
|
|
13
13
|
* Cross-platform shutdown protocol (C3 fix):
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
23
|
const { spawn } = require("child_process");
|
|
24
|
-
const { ipcMain } = require("electron");
|
|
25
24
|
const path = require("path");
|
|
26
25
|
const fs = require("fs");
|
|
27
26
|
const os = require("os");
|
|
@@ -68,43 +67,16 @@ const STDERR_BUFFER_MAX = 10000;
|
|
|
68
67
|
/** Max bytes kept in stdout buffer per agent (protects against malformed output without newlines) */
|
|
69
68
|
const STDOUT_BUFFER_MAX = 1024 * 1024; // 1 MB
|
|
70
69
|
|
|
71
|
-
/** Poll interval while waiting on the backend install-status endpoint (ms) */
|
|
72
|
-
const INSTALL_POLL_INTERVAL = 750;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Hard ceiling on a single install poll loop (ms). A `uv pip install` of a
|
|
76
|
-
* large wheel over a slow link can legitimately take minutes; we cap at 15 to
|
|
77
|
-
* turn a wedged backend into a loud timeout instead of an infinite spinner.
|
|
78
|
-
*/
|
|
79
|
-
const INSTALL_TIMEOUT = 15 * 60 * 1000;
|
|
80
|
-
|
|
81
|
-
/** Header the UI backend requires on every mutating route (see gaia/ui/security.py). */
|
|
82
|
-
const UI_HEADER = { "X-Gaia-UI": "1" };
|
|
83
|
-
|
|
84
70
|
// ── AgentProcessManager ──────────────────────────────────────────────────
|
|
85
71
|
|
|
86
72
|
class AgentProcessManager extends EventEmitter {
|
|
87
73
|
/**
|
|
88
|
-
* @param {
|
|
89
|
-
* @param {{ getBackendPort?: () => (number | null) }} [options]
|
|
90
|
-
* getBackendPort resolves the live Python-backend port. The install/uninstall
|
|
91
|
-
* handlers proxy to that backend's `/api/agents/*` routes (the real install
|
|
92
|
-
* runtime), so without a resolver those handlers fail loudly rather than
|
|
93
|
-
* duplicating download/verify/uv logic in the main process (issue #1721).
|
|
74
|
+
* @param {{ killTree?: Function, listDescendants?: Function }} [options]
|
|
94
75
|
* killTree / listDescendants replace the process-tree helpers (tests).
|
|
95
76
|
*/
|
|
96
|
-
constructor(
|
|
77
|
+
constructor(options = {}) {
|
|
97
78
|
super();
|
|
98
79
|
|
|
99
|
-
/** @type {Electron.BrowserWindow} */
|
|
100
|
-
this.mainWindow = mainWindow;
|
|
101
|
-
|
|
102
|
-
/** @type {(() => (number | null)) | null} */
|
|
103
|
-
this._getBackendPort =
|
|
104
|
-
typeof options.getBackendPort === "function"
|
|
105
|
-
? options.getBackendPort
|
|
106
|
-
: null;
|
|
107
|
-
|
|
108
80
|
/**
|
|
109
81
|
* Running processes keyed by agentId.
|
|
110
82
|
* @type {Record<string, {
|
|
@@ -134,8 +106,6 @@ class AgentProcessManager extends EventEmitter {
|
|
|
134
106
|
|
|
135
107
|
/** Tray config (for auto-start and crash-restart settings) */
|
|
136
108
|
this.config = this._loadConfig();
|
|
137
|
-
|
|
138
|
-
this._registerIpcHandlers();
|
|
139
109
|
}
|
|
140
110
|
|
|
141
111
|
// ── Public API: Lifecycle ────────────────────────────────────────────
|
|
@@ -313,274 +283,6 @@ class AgentProcessManager extends EventEmitter {
|
|
|
313
283
|
console.log(`[agent-mgr] Agent ${agentId} stopped`);
|
|
314
284
|
}
|
|
315
285
|
|
|
316
|
-
/**
|
|
317
|
-
* Restart an agent (stop + start).
|
|
318
|
-
* @param {string} agentId
|
|
319
|
-
*/
|
|
320
|
-
async restartAgent(agentId) {
|
|
321
|
-
await this.stopAgent(agentId);
|
|
322
|
-
return this.startAgent(agentId);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// ── Public API: Install / Uninstall (issue #1721) ────────────────────
|
|
326
|
-
//
|
|
327
|
-
// The install RUNTIME lives in the Python backend (src/gaia/hub/installer.py,
|
|
328
|
-
// exposed by src/gaia/ui/routers/hub.py): R2 download, SHA-256 verify,
|
|
329
|
-
// `uv pip install` into ~/.gaia/agents/<id>/, hot-register, backup/rollback,
|
|
330
|
-
// and the native-trust gate. Rather than reimplement that in the main
|
|
331
|
-
// process, these handlers proxy to those routes so there is exactly one
|
|
332
|
-
// tested install path. Progress streams to the renderer over the existing
|
|
333
|
-
// `agent:install-progress` channel.
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Resolve the live backend base URL, or throw an actionable error.
|
|
337
|
-
* @returns {string}
|
|
338
|
-
*/
|
|
339
|
-
_backendBaseUrl() {
|
|
340
|
-
const port = this._getBackendPort ? this._getBackendPort() : null;
|
|
341
|
-
if (!port) {
|
|
342
|
-
throw new Error(
|
|
343
|
-
"GAIA backend is not running — cannot install or uninstall agents. " +
|
|
344
|
-
"The Python backend exposes the install runtime at /api/agents/install; " +
|
|
345
|
-
"wait for it to finish starting, or restart GAIA if this persists."
|
|
346
|
-
);
|
|
347
|
-
}
|
|
348
|
-
// 127.0.0.1 (not localhost) matches the backend's _require_localhost allowlist
|
|
349
|
-
// and avoids a DNS/IPv6 hop on Windows.
|
|
350
|
-
return `http://127.0.0.1:${port}`;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* Fetch a single agent's catalog entry (tier, permissions, verified status)
|
|
355
|
-
* from the live backend. Used by the gaia:// deep-link install gate
|
|
356
|
-
* (main.cjs) to build an informed trust prompt — the confirmation must show
|
|
357
|
-
* the agent's real tier/permissions, not just its bare id.
|
|
358
|
-
*
|
|
359
|
-
* Throws with an actionable message when the backend is unreachable or the
|
|
360
|
-
* agent id isn't in the catalog. Callers MUST treat that as a refusal —
|
|
361
|
-
* never install without having shown the user what they're installing.
|
|
362
|
-
*
|
|
363
|
-
* @param {string} agentId
|
|
364
|
-
* @returns {Promise<object>} the matching catalog entry
|
|
365
|
-
*/
|
|
366
|
-
async fetchCatalogEntry(agentId) {
|
|
367
|
-
if (typeof agentId !== "string" || !agentId.trim()) {
|
|
368
|
-
throw new Error("fetchCatalogEntry requires a non-empty agent id");
|
|
369
|
-
}
|
|
370
|
-
const base = this._backendBaseUrl();
|
|
371
|
-
|
|
372
|
-
let resp;
|
|
373
|
-
try {
|
|
374
|
-
resp = await fetch(`${base}/api/agents/catalog`, {
|
|
375
|
-
headers: { ...UI_HEADER },
|
|
376
|
-
});
|
|
377
|
-
} catch (err) {
|
|
378
|
-
throw new Error(
|
|
379
|
-
`Could not reach the GAIA backend to look up "${agentId}" in the agent catalog: ${err.message}`
|
|
380
|
-
);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
if (!resp.ok) {
|
|
384
|
-
const detail = await this._readErrorDetail(resp);
|
|
385
|
-
throw new Error(
|
|
386
|
-
`Agent catalog request failed (HTTP ${resp.status}): ${detail}`
|
|
387
|
-
);
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
const body = await resp.json();
|
|
391
|
-
const agents = Array.isArray(body && body.agents) ? body.agents : [];
|
|
392
|
-
const entry = agents.find((a) => a && a.id === agentId);
|
|
393
|
-
if (!entry) {
|
|
394
|
-
throw new Error(`"${agentId}" was not found in the agent catalog.`);
|
|
395
|
-
}
|
|
396
|
-
return entry;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* Install a published agent via the backend runtime, streaming progress.
|
|
401
|
-
*
|
|
402
|
-
* @param {string} agentId
|
|
403
|
-
* @param {{ trustNative?: boolean, version?: string | null }} [opts]
|
|
404
|
-
* @returns {Promise<{ id: string, status: string, version: string | null }>}
|
|
405
|
-
*/
|
|
406
|
-
async installAgent(agentId, opts = {}) {
|
|
407
|
-
if (typeof agentId !== "string" || !agentId.trim()) {
|
|
408
|
-
throw new Error("installAgent requires a non-empty agent id");
|
|
409
|
-
}
|
|
410
|
-
const base = this._backendBaseUrl();
|
|
411
|
-
const trustNative = opts.trustNative === true;
|
|
412
|
-
const version =
|
|
413
|
-
typeof opts.version === "string" && opts.version ? opts.version : null;
|
|
414
|
-
|
|
415
|
-
this._emitInstallProgress(agentId, {
|
|
416
|
-
status: "queued",
|
|
417
|
-
phase: "queued",
|
|
418
|
-
percent: 0,
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
// ── Kick off the background install (202) ──
|
|
422
|
-
let resp;
|
|
423
|
-
try {
|
|
424
|
-
resp = await fetch(`${base}/api/agents/install`, {
|
|
425
|
-
method: "POST",
|
|
426
|
-
headers: { "Content-Type": "application/json", ...UI_HEADER },
|
|
427
|
-
body: JSON.stringify({ id: agentId, trust_native: trustNative, version }),
|
|
428
|
-
});
|
|
429
|
-
} catch (err) {
|
|
430
|
-
throw new Error(
|
|
431
|
-
`Could not reach the GAIA backend to install "${agentId}": ${err.message}`
|
|
432
|
-
);
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
if (!resp.ok) {
|
|
436
|
-
const detail = await this._readErrorDetail(resp);
|
|
437
|
-
if (resp.status === 409) {
|
|
438
|
-
throw new Error(`An install for "${agentId}" is already in progress.`);
|
|
439
|
-
}
|
|
440
|
-
if (resp.status === 403) {
|
|
441
|
-
// Native agents require explicit trust — surface the backend's reason.
|
|
442
|
-
throw new Error(
|
|
443
|
-
`Install of "${agentId}" was refused: ${detail} ` +
|
|
444
|
-
`(pass trustNative once the user accepts the trust prompt).`
|
|
445
|
-
);
|
|
446
|
-
}
|
|
447
|
-
throw new Error(
|
|
448
|
-
`Install request for "${agentId}" failed (HTTP ${resp.status}): ${detail}`
|
|
449
|
-
);
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
// ── Poll install-status until terminal ──
|
|
453
|
-
const deadline = Date.now() + INSTALL_TIMEOUT;
|
|
454
|
-
let lastState = null;
|
|
455
|
-
while (Date.now() < deadline) {
|
|
456
|
-
await this._sleep(INSTALL_POLL_INTERVAL);
|
|
457
|
-
|
|
458
|
-
let statusResp;
|
|
459
|
-
try {
|
|
460
|
-
statusResp = await fetch(
|
|
461
|
-
`${base}/api/agents/${encodeURIComponent(agentId)}/install-status`,
|
|
462
|
-
{ headers: { ...UI_HEADER } }
|
|
463
|
-
);
|
|
464
|
-
} catch (err) {
|
|
465
|
-
throw new Error(
|
|
466
|
-
`Lost contact with the GAIA backend while installing "${agentId}": ${err.message}`
|
|
467
|
-
);
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
// A brief 404 window is possible between the 202 and the worker seeding
|
|
471
|
-
// progress; keep polling until the deadline rather than failing early.
|
|
472
|
-
if (statusResp.status === 404) continue;
|
|
473
|
-
if (!statusResp.ok) {
|
|
474
|
-
const detail = await this._readErrorDetail(statusResp);
|
|
475
|
-
throw new Error(
|
|
476
|
-
`Install-status poll for "${agentId}" failed (HTTP ${statusResp.status}): ${detail}`
|
|
477
|
-
);
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
lastState = await statusResp.json();
|
|
481
|
-
this._emitInstallProgress(agentId, {
|
|
482
|
-
status: lastState.status,
|
|
483
|
-
phase: lastState.phase,
|
|
484
|
-
percent: lastState.percent,
|
|
485
|
-
version: lastState.version,
|
|
486
|
-
error: lastState.error,
|
|
487
|
-
});
|
|
488
|
-
|
|
489
|
-
if (lastState.status === "completed") {
|
|
490
|
-
// Hot-register already happened backend-side; refresh our manifest so
|
|
491
|
-
// getAgentStatus / startAgent see the new binary paths.
|
|
492
|
-
this.reloadManifest();
|
|
493
|
-
return {
|
|
494
|
-
id: agentId,
|
|
495
|
-
status: "completed",
|
|
496
|
-
version: lastState.version || null,
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
if (lastState.status === "failed") {
|
|
500
|
-
throw new Error(
|
|
501
|
-
`Install of "${agentId}" failed: ${lastState.error || "unknown error"}`
|
|
502
|
-
);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
throw new Error(
|
|
507
|
-
`Install of "${agentId}" timed out after ${Math.round(
|
|
508
|
-
INSTALL_TIMEOUT / 1000
|
|
509
|
-
)}s (last phase: ${lastState ? lastState.phase : "unknown"}).`
|
|
510
|
-
);
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
/**
|
|
514
|
-
* Uninstall a hub-installed agent: stop any running sidecar, then delegate
|
|
515
|
-
* removal + de-registration to the backend runtime.
|
|
516
|
-
*
|
|
517
|
-
* @param {string} agentId
|
|
518
|
-
* @returns {Promise<{ id: string, status: string }>}
|
|
519
|
-
*/
|
|
520
|
-
async uninstallAgent(agentId) {
|
|
521
|
-
if (typeof agentId !== "string" || !agentId.trim()) {
|
|
522
|
-
throw new Error("uninstallAgent requires a non-empty agent id");
|
|
523
|
-
}
|
|
524
|
-
const base = this._backendBaseUrl();
|
|
525
|
-
|
|
526
|
-
// Stop a running sidecar first so its dir/executable isn't held open.
|
|
527
|
-
if (this.processes[agentId]) {
|
|
528
|
-
await this.stopAgent(agentId);
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
let resp;
|
|
532
|
-
try {
|
|
533
|
-
resp = await fetch(`${base}/api/agents/${encodeURIComponent(agentId)}`, {
|
|
534
|
-
method: "DELETE",
|
|
535
|
-
headers: { ...UI_HEADER },
|
|
536
|
-
});
|
|
537
|
-
} catch (err) {
|
|
538
|
-
throw new Error(
|
|
539
|
-
`Could not reach the GAIA backend to uninstall "${agentId}": ${err.message}`
|
|
540
|
-
);
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
if (!resp.ok) {
|
|
544
|
-
const detail = await this._readErrorDetail(resp);
|
|
545
|
-
if (resp.status === 404) {
|
|
546
|
-
throw new Error(`"${agentId}" is not installed.`);
|
|
547
|
-
}
|
|
548
|
-
if (resp.status === 400) {
|
|
549
|
-
// e.g. refusing to remove a builtin — surface the backend's reason.
|
|
550
|
-
throw new Error(`Cannot uninstall "${agentId}": ${detail}`);
|
|
551
|
-
}
|
|
552
|
-
throw new Error(
|
|
553
|
-
`Uninstall of "${agentId}" failed (HTTP ${resp.status}): ${detail}`
|
|
554
|
-
);
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
this.reloadManifest();
|
|
558
|
-
return { id: agentId, status: "uninstalled" };
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
/** Read a FastAPI-style `{detail}` error body without throwing. */
|
|
562
|
-
async _readErrorDetail(resp) {
|
|
563
|
-
try {
|
|
564
|
-
const body = await resp.json();
|
|
565
|
-
if (body && typeof body.detail === "string") return body.detail;
|
|
566
|
-
return JSON.stringify(body);
|
|
567
|
-
} catch {
|
|
568
|
-
return resp.statusText || `HTTP ${resp.status}`;
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
_emitInstallProgress(agentId, progress) {
|
|
573
|
-
this._sendToRenderer("agent:install-progress", {
|
|
574
|
-
agentId,
|
|
575
|
-
...progress,
|
|
576
|
-
timestamp: Date.now(),
|
|
577
|
-
});
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
_sleep(ms) {
|
|
581
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
582
|
-
}
|
|
583
|
-
|
|
584
286
|
// ── Public API: Monitoring ───────────────────────────────────────────
|
|
585
287
|
|
|
586
288
|
/**
|
|
@@ -622,30 +324,6 @@ class AgentProcessManager extends EventEmitter {
|
|
|
622
324
|
};
|
|
623
325
|
}
|
|
624
326
|
|
|
625
|
-
/**
|
|
626
|
-
* Get statuses for all known agents.
|
|
627
|
-
* @returns {Record<string, object>}
|
|
628
|
-
*/
|
|
629
|
-
getAllAgentStatuses() {
|
|
630
|
-
const result = {};
|
|
631
|
-
|
|
632
|
-
// Include agents from manifest
|
|
633
|
-
if (this.manifest && this.manifest.agents) {
|
|
634
|
-
for (const agent of this.manifest.agents) {
|
|
635
|
-
result[agent.id] = this.getAgentStatus(agent.id);
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
// Include any running agents not in manifest (shouldn't happen, but safety)
|
|
640
|
-
for (const agentId of Object.keys(this.processes)) {
|
|
641
|
-
if (!result[agentId]) {
|
|
642
|
-
result[agentId] = this.getAgentStatus(agentId);
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
return result;
|
|
647
|
-
}
|
|
648
|
-
|
|
649
327
|
// ── Public API: I/O ──────────────────────────────────────────────────
|
|
650
328
|
|
|
651
329
|
/**
|
|
@@ -723,19 +401,6 @@ class AgentProcessManager extends EventEmitter {
|
|
|
723
401
|
await Promise.all(agentIds.map((id) => this.stopAgent(id)));
|
|
724
402
|
}
|
|
725
403
|
|
|
726
|
-
// ── Public API: Manifest ─────────────────────────────────────────────
|
|
727
|
-
|
|
728
|
-
/** @returns {object | null} The agent manifest */
|
|
729
|
-
getManifest() {
|
|
730
|
-
return this.manifest;
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
/** Reload the manifest from disk. */
|
|
734
|
-
reloadManifest() {
|
|
735
|
-
this.manifest = this._loadManifest();
|
|
736
|
-
return this.manifest;
|
|
737
|
-
}
|
|
738
|
-
|
|
739
404
|
// ── Private: stdout handling (JSON-RPC) ──────────────────────────────
|
|
740
405
|
|
|
741
406
|
_handleStdout(agentId, data) {
|
|
@@ -790,13 +455,6 @@ class AgentProcessManager extends EventEmitter {
|
|
|
790
455
|
}
|
|
791
456
|
}
|
|
792
457
|
|
|
793
|
-
// It's a notification or unsolicited message — forward to renderer
|
|
794
|
-
this._sendToRenderer("agent:stdout", {
|
|
795
|
-
agentId,
|
|
796
|
-
message: msg,
|
|
797
|
-
timestamp: Date.now(),
|
|
798
|
-
});
|
|
799
|
-
|
|
800
458
|
// Handle specific notification methods
|
|
801
459
|
if (msg.method === "notification/send") {
|
|
802
460
|
this.emit("agent-notification", agentId, msg.params);
|
|
@@ -819,13 +477,6 @@ class AgentProcessManager extends EventEmitter {
|
|
|
819
477
|
if (entry.stderrBuffer.length > STDERR_BUFFER_MAX) {
|
|
820
478
|
entry.stderrBuffer.shift();
|
|
821
479
|
}
|
|
822
|
-
|
|
823
|
-
// Forward to renderer
|
|
824
|
-
this._sendToRenderer("agent:stderr", {
|
|
825
|
-
agentId,
|
|
826
|
-
line,
|
|
827
|
-
timestamp: Date.now(),
|
|
828
|
-
});
|
|
829
480
|
}
|
|
830
481
|
}
|
|
831
482
|
|
|
@@ -846,14 +497,6 @@ class AgentProcessManager extends EventEmitter {
|
|
|
846
497
|
this._logCrash(agentId, code, signal);
|
|
847
498
|
}
|
|
848
499
|
|
|
849
|
-
// Notify renderer of unexpected exit
|
|
850
|
-
this._sendToRenderer("agent:crashed", {
|
|
851
|
-
agentId,
|
|
852
|
-
exitCode: code,
|
|
853
|
-
signal,
|
|
854
|
-
timestamp: Date.now(),
|
|
855
|
-
});
|
|
856
|
-
|
|
857
500
|
this._cleanupProcess(agentId);
|
|
858
501
|
this._emitStatusChange(agentId, "stopped");
|
|
859
502
|
|
|
@@ -1045,21 +688,9 @@ class AgentProcessManager extends EventEmitter {
|
|
|
1045
688
|
timestamp: Date.now(),
|
|
1046
689
|
};
|
|
1047
690
|
|
|
1048
|
-
this._sendToRenderer("agent:status-change", payload);
|
|
1049
691
|
this.emit("status-change", payload);
|
|
1050
692
|
}
|
|
1051
693
|
|
|
1052
|
-
_sendToRenderer(channel, data) {
|
|
1053
|
-
try {
|
|
1054
|
-
if (this.mainWindow && !this.mainWindow.isDestroyed()) {
|
|
1055
|
-
this.mainWindow.webContents.send(channel, data);
|
|
1056
|
-
}
|
|
1057
|
-
} catch (err) {
|
|
1058
|
-
// Window may be closing
|
|
1059
|
-
console.warn(`[agent-mgr] Could not send to renderer:`, err.message);
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
694
|
// ── Private: Manifest & config ───────────────────────────────────────
|
|
1064
695
|
|
|
1065
696
|
_loadManifest() {
|
|
@@ -1148,45 +779,6 @@ class AgentProcessManager extends EventEmitter {
|
|
|
1148
779
|
}
|
|
1149
780
|
}
|
|
1150
781
|
|
|
1151
|
-
// ── Private: IPC handlers ────────────────────────────────────────────
|
|
1152
|
-
|
|
1153
|
-
_registerIpcHandlers() {
|
|
1154
|
-
ipcMain.handle("agent:start", async (_event, agentId) => {
|
|
1155
|
-
return this.startAgent(agentId);
|
|
1156
|
-
});
|
|
1157
|
-
|
|
1158
|
-
ipcMain.handle("agent:stop", async (_event, agentId) => {
|
|
1159
|
-
return this.stopAgent(agentId);
|
|
1160
|
-
});
|
|
1161
|
-
|
|
1162
|
-
ipcMain.handle("agent:restart", async (_event, agentId) => {
|
|
1163
|
-
return this.restartAgent(agentId);
|
|
1164
|
-
});
|
|
1165
|
-
|
|
1166
|
-
ipcMain.handle("agent:status", (_event, agentId) => {
|
|
1167
|
-
return this.getAgentStatus(agentId);
|
|
1168
|
-
});
|
|
1169
|
-
|
|
1170
|
-
ipcMain.handle("agent:status-all", () => {
|
|
1171
|
-
return this.getAllAgentStatuses();
|
|
1172
|
-
});
|
|
1173
|
-
|
|
1174
|
-
ipcMain.handle("agent:send-rpc", async (_event, agentId, method, params) => {
|
|
1175
|
-
return this.sendJsonRpc(agentId, method, params);
|
|
1176
|
-
});
|
|
1177
|
-
|
|
1178
|
-
ipcMain.handle("agent:get-manifest", () => {
|
|
1179
|
-
return this.getManifest();
|
|
1180
|
-
});
|
|
1181
|
-
|
|
1182
|
-
ipcMain.handle("agent:install", async (_event, agentId, opts) => {
|
|
1183
|
-
return this.installAgent(agentId, opts || {});
|
|
1184
|
-
});
|
|
1185
|
-
|
|
1186
|
-
ipcMain.handle("agent:uninstall", async (_event, agentId) => {
|
|
1187
|
-
return this.uninstallAgent(agentId);
|
|
1188
|
-
});
|
|
1189
|
-
}
|
|
1190
782
|
}
|
|
1191
783
|
|
|
1192
784
|
/**
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// Copyright(C) 2026 Advanced Micro Devices, Inc. All rights reserved.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A launcher for GAIA run as an AppImage.
|
|
6
|
+
*
|
|
7
|
+
* An AppImage installs nothing, so the desktop has no `.desktop` file to tie
|
|
8
|
+
* GAIA's window to: GNOME lists it without a name or icon, and the app grid
|
|
9
|
+
* has nothing to reopen it from. The `.deb` installs that file; here GAIA
|
|
10
|
+
* writes its own into the user's applications folder on launch.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const fs = require("fs");
|
|
14
|
+
const os = require("os");
|
|
15
|
+
const path = require("path");
|
|
16
|
+
const { notificationIconPath } = require("./app-icon.cjs");
|
|
17
|
+
|
|
18
|
+
// The window's app_id / WM_CLASS comes from the same package.json field.
|
|
19
|
+
const DESKTOP_FILE = require("../package.json").desktopName;
|
|
20
|
+
const APP_ID = DESKTOP_FILE.replace(/\.desktop$/, "");
|
|
21
|
+
/** Marks an entry as GAIA's own, so one the user or a tool wrote is never replaced. */
|
|
22
|
+
const OWNED = "X-GAIA-AppImage=true";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A path as one quoted Exec= argument: the Desktop Entry spec escapes " ` $ \
|
|
26
|
+
* inside the quotes, then escapes every backslash again as a string value.
|
|
27
|
+
*/
|
|
28
|
+
function desktopExecArg(file) {
|
|
29
|
+
// "%" starts a field code (%f, %u…) anywhere in Exec=, so it is doubled.
|
|
30
|
+
const quoted = `"${file.replace(/%/g, "%%").replace(/["`$\\]/g, (c) => `\\${c}`)}"`;
|
|
31
|
+
return quoted.replace(/\\/g, "\\\\").replace(/\n/g, "\\n");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** A path as a plain string value (Icon=, TryExec=): "\" and a newline are escaped. */
|
|
35
|
+
function desktopString(file) {
|
|
36
|
+
return file.replace(/\\/g, "\\\\").replace(/\n/g, "\\n");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Whether `dir` is `root` or inside it. */
|
|
40
|
+
function isInside(dir, root) {
|
|
41
|
+
const rel = path.relative(path.resolve(root), path.resolve(dir));
|
|
42
|
+
return rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** A Desktop Entry string value with its escapes (\s \n \t \r \\) undone. */
|
|
46
|
+
function unescapeString(value) {
|
|
47
|
+
const map = { s: " ", n: "\n", t: "\t", r: "\r", "\\": "\\" };
|
|
48
|
+
return value.replace(/\\([sntr\\])/g, (_m, c) => map[c]);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The program an Exec= value runs: its first argument, unquoted. */
|
|
52
|
+
function execProgram(value) {
|
|
53
|
+
const exec = unescapeString(value).trim();
|
|
54
|
+
if (!exec.startsWith('"')) return exec.split(/\s+/)[0].replace(/%%/g, "%");
|
|
55
|
+
let out = "";
|
|
56
|
+
for (let i = 1; i < exec.length; i += 1) {
|
|
57
|
+
if (exec[i] === "\\" && i + 1 < exec.length) out += exec[(i += 1)];
|
|
58
|
+
else if (exec[i] === '"') break;
|
|
59
|
+
else out += exec[i];
|
|
60
|
+
}
|
|
61
|
+
return out.replace(/%%/g, "%");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Errors that mean a path can't be followed or read, not that GAIA can't write. */
|
|
65
|
+
const UNREADABLE = new Set(["EACCES", "EPERM", "ELOOP"]);
|
|
66
|
+
|
|
67
|
+
function samePath(a, b) {
|
|
68
|
+
if (path.resolve(a) === path.resolve(b)) return true;
|
|
69
|
+
try {
|
|
70
|
+
return fs.realpathSync(a) === fs.realpathSync(b);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
if (err.code === "ENOENT" || err.code === "ENOTDIR" || UNREADABLE.has(err.code)) return false;
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Another entry in `dir` that launches this AppImage, written by an AppImage
|
|
79
|
+
* integration tool or by hand. GAIA's own `DESKTOP_FILE` is not counted.
|
|
80
|
+
*/
|
|
81
|
+
function otherLauncherFor(dir, appImage) {
|
|
82
|
+
if (!fs.existsSync(dir)) return null;
|
|
83
|
+
for (const name of fs.readdirSync(dir).sort()) {
|
|
84
|
+
if (!name.endsWith(".desktop") || name === DESKTOP_FILE) continue;
|
|
85
|
+
const file = path.join(dir, name);
|
|
86
|
+
let lines;
|
|
87
|
+
try {
|
|
88
|
+
if (!fs.statSync(file, { throwIfNoEntry: false })?.isFile()) continue;
|
|
89
|
+
lines = fs.readFileSync(file, "utf8").split("\n");
|
|
90
|
+
} catch (err) {
|
|
91
|
+
// Another app's entry GAIA can't read can't be a launcher for this AppImage.
|
|
92
|
+
if (UNREADABLE.has(err.code)) continue;
|
|
93
|
+
throw err;
|
|
94
|
+
}
|
|
95
|
+
if (lines.includes(OWNED)) continue;
|
|
96
|
+
const targets = [];
|
|
97
|
+
for (const line of lines) {
|
|
98
|
+
if (line.startsWith("Exec=")) targets.push(execProgram(line.slice(5)));
|
|
99
|
+
else if (line.startsWith("TryExec=")) targets.push(unescapeString(line.slice(8)).trim());
|
|
100
|
+
}
|
|
101
|
+
if (targets.some((target) => target && samePath(target, appImage))) return file;
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function launcherPaths(env, home) {
|
|
107
|
+
const dataHome = env.XDG_DATA_HOME || path.join(home, ".local", "share");
|
|
108
|
+
return {
|
|
109
|
+
entry: path.join(dataHome, "applications", DESKTOP_FILE),
|
|
110
|
+
icon: path.join(dataHome, "icons", "hicolor", "256x256", "apps", `${APP_ID}.png`),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function entryText(appImage, icon) {
|
|
115
|
+
return [
|
|
116
|
+
"[Desktop Entry]",
|
|
117
|
+
"Type=Application",
|
|
118
|
+
"Name=GAIA",
|
|
119
|
+
"Comment=Privacy-first agentic AI interface for AMD Ryzen AI",
|
|
120
|
+
`Exec=${desktopExecArg(appImage)}`,
|
|
121
|
+
// Hides the entry once the AppImage is deleted or moved.
|
|
122
|
+
`TryExec=${desktopString(appImage)}`,
|
|
123
|
+
`Icon=${desktopString(icon)}`,
|
|
124
|
+
"Terminal=false",
|
|
125
|
+
"Categories=Development;Utility;",
|
|
126
|
+
`StartupWMClass=${APP_ID}`,
|
|
127
|
+
OWNED,
|
|
128
|
+
"",
|
|
129
|
+
].join("\n");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Write or refresh the launcher for this AppImage.
|
|
134
|
+
*
|
|
135
|
+
* @param {{platform?: string, env?: NodeJS.ProcessEnv, home?: string, iconSource?: string}} [deps]
|
|
136
|
+
* @returns {{status: "not-appimage" | "package-installed" | "kept-existing" | "current" | "written", entry?: string}}
|
|
137
|
+
* @throws {Error} When the launcher or its icon can't be written.
|
|
138
|
+
*/
|
|
139
|
+
function installAppImageLauncher({
|
|
140
|
+
platform = process.platform,
|
|
141
|
+
env = process.env,
|
|
142
|
+
home = os.homedir(),
|
|
143
|
+
iconSource = notificationIconPath(),
|
|
144
|
+
} = {}) {
|
|
145
|
+
const appImage = env.APPIMAGE;
|
|
146
|
+
if (platform !== "linux" || !appImage) return { status: "not-appimage" };
|
|
147
|
+
|
|
148
|
+
// An AppImage's own mount can be on XDG_DATA_DIRS; its bundled entry isn't an install.
|
|
149
|
+
const systemDirs = (env.XDG_DATA_DIRS || "/usr/local/share:/usr/share")
|
|
150
|
+
.split(":")
|
|
151
|
+
.filter((dir) => dir && !(env.APPDIR && isInside(dir, env.APPDIR)));
|
|
152
|
+
const packaged = systemDirs.find((dir) => fs.existsSync(path.join(dir, "applications", DESKTOP_FILE)));
|
|
153
|
+
if (packaged) return { status: "package-installed", entry: path.join(packaged, "applications", DESKTOP_FILE) };
|
|
154
|
+
|
|
155
|
+
const { entry, icon } = launcherPaths(env, home);
|
|
156
|
+
const wanted = entryText(appImage, icon);
|
|
157
|
+
try {
|
|
158
|
+
const current = fs.existsSync(entry) ? fs.readFileSync(entry, "utf8") : null;
|
|
159
|
+
if (current !== null && !current.split("\n").includes(OWNED)) return { status: "kept-existing", entry };
|
|
160
|
+
// A second entry for the same AppImage shows GAIA twice in the app grid.
|
|
161
|
+
const other = otherLauncherFor(path.dirname(entry), appImage);
|
|
162
|
+
if (other) {
|
|
163
|
+
if (current !== null) fs.rmSync(entry);
|
|
164
|
+
return { status: "kept-existing", entry: other };
|
|
165
|
+
}
|
|
166
|
+
const image = fs.readFileSync(iconSource);
|
|
167
|
+
const iconCurrent = fs.existsSync(icon) && fs.readFileSync(icon).equals(image);
|
|
168
|
+
if (current === wanted && iconCurrent) return { status: "current", entry };
|
|
169
|
+
fs.mkdirSync(path.dirname(icon), { recursive: true });
|
|
170
|
+
fs.writeFileSync(icon, image);
|
|
171
|
+
fs.mkdirSync(path.dirname(entry), { recursive: true });
|
|
172
|
+
fs.writeFileSync(entry, wanted, "utf8");
|
|
173
|
+
} catch (err) {
|
|
174
|
+
throw new Error(
|
|
175
|
+
`Could not write GAIA's launcher ${entry}: ${err.message}. ` +
|
|
176
|
+
"GAIA still runs, but the desktop shows its window without a name or icon. " +
|
|
177
|
+
"Check that the folder is writable."
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
return { status: "written", entry };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
module.exports = { installAppImageLauncher, desktopExecArg, launcherPaths, APP_ID, DESKTOP_FILE, OWNED };
|