@amd-gaia/agent-ui 0.26.0-rc.16 → 0.26.0-rc.18

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.
Files changed (40) hide show
  1. package/dist/assets/AdvancedSettings-Bz3-vkHg.js +1 -0
  2. package/dist/assets/ConnectorsPane-BZAN-4in.js +1 -0
  3. package/dist/assets/ConnectorsPane-hmunRyL2.css +1 -0
  4. package/dist/assets/DocumentLibrary-XhxSDgy3.js +4 -0
  5. package/dist/assets/FileBrowser-aGXn6FT_.js +4 -0
  6. package/dist/assets/MemoryDashboard-BDPX8_Oe.js +1 -0
  7. package/dist/assets/MemoryDashboard-k38iG5mj.css +1 -0
  8. package/dist/assets/MobileAccessModal-Dl13qVaH.js +2 -0
  9. package/dist/assets/ScheduleManager-B2uNcCLm.js +1 -0
  10. package/dist/assets/{browser-KnDALPx_.js → browser-DfYHeeW3.js} +1 -1
  11. package/dist/assets/index-Bo9WOu4c.css +1 -0
  12. package/dist/assets/index-_q5MnYHx.js +93 -0
  13. package/dist/assets/useT-BEuJOsBI.js +3 -0
  14. package/dist/assets/{zap-CJilF8mK.js → zap-BxzGBs8H.js} +1 -1
  15. package/dist/index.html +3 -4
  16. package/dist/sw.js +1 -1
  17. package/main-safety-net.cjs +8 -1
  18. package/main.cjs +16 -221
  19. package/package.json +3 -3
  20. package/preload.cjs +0 -30
  21. package/services/agent-process-manager.cjs +3 -411
  22. package/services/appimage-launcher.cjs +67 -0
  23. package/services/tray-manager.cjs +3 -1
  24. package/services/window-reveal.cjs +42 -0
  25. package/dist/assets/AdvancedSettings-BZPGfDkZ.js +0 -1
  26. package/dist/assets/ConnectorsPane-B1lwOGL5.css +0 -1
  27. package/dist/assets/ConnectorsPane-CSUwrUUn.js +0 -1
  28. package/dist/assets/DocumentLibrary-RRR0ncgw.js +0 -4
  29. package/dist/assets/FileBrowser-4LFc4BCp.js +0 -4
  30. package/dist/assets/MemoryDashboard-CP4tyFxT.js +0 -1
  31. package/dist/assets/MemoryDashboard-DwrWAXi6.css +0 -1
  32. package/dist/assets/MobileAccessModal-D6Ua5qjG.js +0 -2
  33. package/dist/assets/ScheduleManager-DtB0nj5U.js +0 -1
  34. package/dist/assets/api--I_306zc.js +0 -4
  35. package/dist/assets/index-C9wJG-Eh.js +0 -88
  36. package/dist/assets/index-CvE1q_in.css +0 -1
  37. package/dist/assets/useT-C5NQKA1s.js +0 -3
  38. package/services/deep-link-queue.cjs +0 -77
  39. package/services/deep-link.cjs +0 -230
  40. 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 → piped to terminal view
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 {Electron.BrowserWindow} mainWindow — for sending IPC events to renderer
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(mainWindow, options = {}) {
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
  /**
@@ -42,6 +42,67 @@ function isInside(dir, root) {
42
42
  return rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel));
43
43
  }
44
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
+
45
106
  function launcherPaths(env, home) {
46
107
  const dataHome = env.XDG_DATA_HOME || path.join(home, ".local", "share");
47
108
  return {
@@ -96,6 +157,12 @@ function installAppImageLauncher({
96
157
  try {
97
158
  const current = fs.existsSync(entry) ? fs.readFileSync(entry, "utf8") : null;
98
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
+ }
99
166
  const image = fs.readFileSync(iconSource);
100
167
  const iconCurrent = fs.existsSync(icon) && fs.readFileSync(icon).equals(image);
101
168
  if (current === wanted && iconCurrent) return { status: "current", entry };
@@ -355,7 +355,9 @@ class TrayManager {
355
355
  throw new TypeError("TrayManager.setHost expects {available: boolean, reason}");
356
356
  }
357
357
  this._host = { available: host.available, reason: host.available ? null : host.reason };
358
- if (!host.available) {
358
+ if (host.available) {
359
+ console.log("[tray] Tray icon host available; closing the window follows the minimize-to-tray setting");
360
+ } else {
359
361
  console.log(
360
362
  `[tray] No tray icon host (${host.reason}: ${host.detail || "no detail"}); closing the window minimizes GAIA`
361
363
  );
@@ -0,0 +1,42 @@
1
+ // Copyright(C) 2026 Advanced Micro Devices, Inc. All rights reserved.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ /**
5
+ * When to first show a window created with `show: false`.
6
+ *
7
+ * Electron's "ready-to-show" waits for the first painted frame. A Wayland
8
+ * compositor asks for no frames from a window that isn't on screen, so there
9
+ * the event never comes and the window would stay hidden for good.
10
+ */
11
+
12
+ /** How long after the page loads to stop waiting for "ready-to-show". */
13
+ const PAINT_WAIT_MS = 1000;
14
+
15
+ /**
16
+ * Call `reveal` once: on "ready-to-show", or `waitMs` after the page finished
17
+ * loading when that event hasn't come.
18
+ *
19
+ * @param {Electron.BrowserWindow} win
20
+ * @param {(via: "ready-to-show" | "page-loaded") => void} reveal
21
+ * @param {{waitMs?: number, setTimer?: typeof setTimeout, clearTimer?: typeof clearTimeout}} [deps]
22
+ */
23
+ function revealWhenReady(
24
+ win,
25
+ reveal,
26
+ { waitMs = PAINT_WAIT_MS, setTimer = setTimeout, clearTimer = clearTimeout } = {}
27
+ ) {
28
+ let done = false;
29
+ let timer = null;
30
+ const run = (via) => {
31
+ if (done) return;
32
+ done = true;
33
+ if (timer !== null) clearTimer(timer);
34
+ reveal(via);
35
+ };
36
+ win.once("ready-to-show", () => run("ready-to-show"));
37
+ win.webContents.once("did-finish-load", () => {
38
+ if (!done) timer = setTimer(() => run("page-loaded"), waitMs);
39
+ });
40
+ }
41
+
42
+ module.exports = { revealWhenReady, PAINT_WAIT_MS };
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{I as t,J as n,a as r,c as i,f as a,l as o,u as s}from"./useT-C5NQKA1s.js";import{B as c,G as l,H as u,It as d,Kt as f,Lt as p,Q as m,et as h,ht as g}from"./api--I_306zc.js";import{Gt as _,St as v,Vt as y,a as b,c as x,d as S,f as C,l as w,o as T,r as E,rt as D,s as O,tt as k,zt as A}from"./index-C9wJG-Eh.js";var j=e(n(),1);function M(){let e=r(),t=a(e=>e.runSetupAgain),n=a(e=>e.closeSettings),[l,u]=(0,j.useState)(null),[f,p]=(0,j.useState)(null),[m,h]=(0,j.useState)(``),[g,_]=(0,j.useState)(``),[b,x]=(0,j.useState)(!1),[C,w]=(0,j.useState)(null),[T,E]=(0,j.useState)(!1);(0,j.useEffect)(()=>{c().then(e=>{u(e),h(e.saved_base_url??e.base_url??``)}).catch(e=>p(e instanceof Error?e.message:String(e)))},[]);let D=(0,j.useCallback)(async e=>{x(!0),w(null);try{let r=await d(e);u(r),_(``),E(!1),r.mode===`gaia`&&!r.gaia_installed&&(n(),t(!0))}catch(e){E(S(e)),w(e instanceof Error?e.message:String(e))}finally{x(!1)}},[n,t]),O=()=>void D({mode:`external`,base_url:m.trim(),api_key:g.trim()||void 0});if(f)return s(`section`,{className:`settings-section`,children:[o(`h4`,{children:e(`settings.advanced.modelServer`)}),s(`div`,{className:`model-warning`,role:`alert`,children:[o(y,{size:14}),s(`div`,{className:`model-warning-content`,children:[o(`strong`,{children:e(`settings.server.readFailed`)}),o(`p`,{children:f})]})]})]});if(!l)return null;let k=l.mode===`external`,A=l.source===`env`;return s(`section`,{className:`settings-section`,"aria-label":e(`settings.advanced.modelServer`),children:[o(`h4`,{children:e(`settings.advanced.modelServer`)}),o(`p`,{className:`model-override-desc`,role:`status`,children:A?e(`settings.server.usesEnv`,{url:l.base_url??``}):k?e(`settings.server.usesYours`,{url:l.base_url??``}):e(`settings.server.usesOwn`)}),!A&&l.env_url_ignored&&o(`p`,{className:`model-status-hint`,children:e(`settings.server.envIgnored`,{url:l.env_url_ignored})}),A?o(`p`,{className:`model-status-hint`,children:e(`settings.server.envUseOwn`)}):s(i.Fragment,{children:[s(`p`,{className:`model-status-hint`,children:[e(`settings.server.useYours`),` `,o(`bdi`,{children:l.what_gaia_does})]}),s(`form`,{className:`model-input-row`,onSubmit:e=>{e.preventDefault(),O()},children:[o(`input`,{type:`text`,className:`model-input`,placeholder:`http://localhost:13305`,value:m,onChange:e=>{h(e.target.value),w(null)},disabled:b,spellCheck:!1,autoCapitalize:`off`,autoCorrect:`off`,"aria-label":e(`settings.server.address`)}),o(`input`,{type:`password`,className:`model-input`,autoComplete:`off`,placeholder:l.api_key_stored?e.bare(`settings.server.keySaved`):e.bare(`settings.server.keyOptional`),value:g,onChange:e=>_(e.target.value),disabled:b,"aria-label":e(`settings.server.key`)}),o(`div`,{className:`model-btn-group`,children:o(`button`,{type:`submit`,className:`btn-model-save`,disabled:b||!m.trim(),children:b?s(i.Fragment,{children:[o(v,{size:13,className:`btn-spinner`}),` `,e(`settings.server.checking`)]}):e(`settings.server.use`)})})]})]}),k&&o(`div`,{className:`setting-actions`,children:o(`button`,{type:`button`,className:`btn-secondary`,disabled:b,onClick:()=>void D({mode:`gaia`}),children:e(`settings.server.useOwn`)})}),C&&s(`div`,{className:`model-warning`,role:`alert`,children:[o(y,{size:14}),s(`div`,{className:`model-warning-content`,children:[o(`strong`,{children:e(T?`settings.server.needsKey`:`settings.server.notSwitched`)}),o(`p`,{children:C})]})]})]})}var N={vulkan:`Vulkan`,rocm:`ROCm`,metal:`Metal`,cpu:`CPU`,npu:`NPU`,remote:`Remote (cloud)`},P={gaia:`settings.server.ownerGaia`,user:`settings.server.ownerUser`,remote:`settings.server.ownerRemote`};function F(e){return e?N[e]??e:`unknown`}function I(e){if(!e)return`unknown`;let t=F(e.backend);return e.backend_source===`lemonade_default`?`${t} (Lemonade's default)`:t}function L(e){return e?`${Math.round(e/1024)}K tokens`:`unknown`}var R={asr:`settings.server.kind.speechRecognition`,embedding:`settings.server.kind.embedding`,image:`settings.server.kind.image`,llm:`settings.server.kind.language`,rerank:`settings.server.kind.reranker`,reranking:`settings.server.kind.reranker`,stt:`settings.server.kind.speechRecognition`,transcription:`settings.server.kind.speechRecognition`,tts:`settings.server.kind.speech`,vision:`settings.server.kind.vision`,"3d":`settings.server.kind.threeD`};function z(e,t){if(!e.model_type)return t(`settings.server.loadedModel`);let n=e.model_type.toLowerCase(),r=R[n];return r?t(r):t(`settings.server.kindOther`,{kind:`${n.charAt(0).toUpperCase()}${n.slice(1)}`})}function B(e,t){let n=[e.name?D(e.name):t.bare(`settings.server.unknownModel`),I(e)];return e.backend!==`remote`&&e.ctx_size&&n.push(L(e.ctx_size)),n.join(` · `)}function V({label:e,value:t,title:n}){return s(`div`,{className:`status-row`,children:[o(`span`,{className:`status-label`,children:e}),o(`span`,{className:`status-value model-server-value`,dir:`auto`,title:n??t,children:t})]})}function ee(){let e=r(),t=a(e=>e.openSettings),[n,c]=(0,j.useState)(null),[u,d]=(0,j.useState)(null),[f,m]=(0,j.useState)(null),[h,_]=(0,j.useState)(null),[y,x]=(0,j.useState)(!1);(0,j.useEffect)(()=>{l().then(c).catch(e=>d(e instanceof Error?e.message:String(e)))},[]);let S=(0,j.useCallback)(async t=>{m(t),_(null);try{let n=await p(t);c(n),_({ok:!0,text:e(`settings.server.savedBackend`)})}catch(e){_({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{m(null)}},[e]),C=n?.chat_model??null,w=(0,j.useCallback)(async()=>{if(C?.name){x(!0);try{if(!await g(C.name,C.ctx_size??void 0))return;_({ok:!0,text:e(`settings.server.reloading`,{name:C.name})})}catch(e){_({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{x(!1)}}},[C,e]),T=o(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>t(`model`),children:e(`settings.server.changeModel`)});if(u)return s(`section`,{className:`settings-section`,"aria-label":e(`settings.advanced.modelServer`),children:[o(`h4`,{children:e(`settings.advanced.modelServer`)}),o(b,{message:u})]});if(!n)return s(`section`,{className:`settings-section`,"aria-label":e(`settings.advanced.modelServer`),children:[o(`h4`,{children:e(`settings.advanced.modelServer`)}),o(`p`,{className:`loading-text`,children:e(`settings.server.checkingServer`)})]});if(!n.reachable)return s(`section`,{className:`settings-section`,"aria-label":e(`settings.advanced.modelServer`),children:[o(`h4`,{children:e(`settings.advanced.modelServer`)}),o(b,{message:n.error??e(`settings.errors.serverDownTitle`)}),T]});let E=n.available_backends??[],O=n.preferred_backend??null,k=E.map(e=>e.name);O&&!k.includes(O)&&k.push(O);let A=O??n.default_backend??null,M=E.filter(e=>e.state===`installable`).map(e=>F(e.name)),N=!!C?.name&&C.recipe===`llamacpp`;return s(`section`,{className:`settings-section`,"aria-label":e(`settings.advanced.modelServer`),children:[o(`h4`,{children:e(`settings.advanced.modelServer`)}),s(`div`,{className:`status-grid`,children:[o(V,{label:e(`settings.server.server`),value:`${P[n.owner]?e(P[n.owner]):n.owner}${n.version?` v${n.version}`:``}`}),o(V,{label:e(`settings.server.addressShort`),value:n.base_url}),o(V,{label:e(`settings.server.chatModel`),value:C?.name?D(C.name):e(`settings.advanced.noneLoaded`),title:C?.name??void 0}),C&&o(V,{label:e(`settings.server.runsOn`),value:I(C)}),C&&C.backend!==`remote`&&o(V,{label:e(`settings.advanced.context`),value:L(C.ctx_size)}),o(V,{label:e(`settings.advanced.embedding`),value:n.embedding_model?.name?`${n.embedding_model.name} · ${I(n.embedding_model)}`:e(`settings.advanced.noneLoaded`)}),(n.loaded_models??[]).map((t,n)=>o(V,{label:z(t,e),value:B(t,e),title:t.name??void 0},`${t.name??`unknown`}-${n}`))]}),n.embedding_note&&o(`p`,{className:`settings-hint`,children:o(`bdi`,{children:n.embedding_note})}),n.system_info_error&&o(`p`,{className:`settings-hint`,children:o(`bdi`,{children:n.system_info_error})}),s(`div`,{className:`settings-field model-server-backend`,children:[o(`span`,{className:`settings-label`,children:e(`settings.server.backend`)}),E.length===0&&!O?o(`span`,{className:`settings-hint`,children:e(`settings.server.noBackends`)}):s(i.Fragment,{children:[o(`div`,{className:`segmented`,role:`radiogroup`,"aria-label":e(`settings.server.backendShort`),children:k.map(e=>s(`button`,{type:`button`,role:`radio`,"aria-checked":A===e,className:A===e?`is-active`:``,disabled:f!==null,onClick:()=>{e!==A&&S(e)},children:[f===e?o(v,{size:12,className:`spin`}):null,F(e)]},e))}),s(`span`,{className:`settings-hint`,children:[e(`settings.server.backendHint`),M.length>0&&` ${e(`settings.server.installable`,{names:M.join(`, `)})}`]})]}),h?.ok&&o(`p`,{className:`settings-ok`,role:`status`,children:h.text}),h&&!h.ok&&o(b,{message:h.text})]}),s(`div`,{className:`settings-row`,children:[T,N&&s(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void w(),disabled:y,children:[y?o(v,{size:13,className:`spin`}):null,e(`settings.server.reload`)]})]})]})}function H(){let e=r(),[n,a]=(0,j.useState)(null),[c,l]=(0,j.useState)(!0),[d,p]=(0,j.useState)([]),[g,S]=(0,j.useState)(``),[D,N]=(0,j.useState)(``),[P,F]=(0,j.useState)(!1),[I,L]=(0,j.useState)(!1),[R,z]=(0,j.useState)(null),[B,V]=(0,j.useState)(!1),H=(0,j.useRef)(null),[G,K]=(0,j.useState)(!1),[q,te]=(0,j.useState)(!1),[J,ne]=(0,j.useState)(!1),[re,ie]=(0,j.useState)(null);(0,j.useEffect)(()=>{t.system.info(`Checking system status...`);let e=t.system.time();h().then(n=>{a(n),t.system.timed(`System status received`,e,{lemonade:n.lemonade_running?`running`:`stopped`,model:n.model_loaded||`none`,embedding:n.embedding_model_loaded?`yes`:`no`,disk:`${n.disk_space_gb}GB free`,memory:n.memory_available_gb==null?`unknown`:`${n.memory_available_gb}GB available`}),n.lemonade_running||t.system.warn(`Lemonade Server is NOT running.`)}).catch(e=>{t.system.error(`Failed to get system status`,e),a(null)}).finally(()=>l(!1)),u().then(e=>p(e.servers)).catch(()=>{}),m().then(e=>{let t=e.custom_model??``;S(t),N(t),K(e.dynamic_tools),te(e.dynamic_tools_locked)}).catch(e=>{t.system.error(`Failed to load settings`,e)}).finally(()=>F(!0))},[]),(0,j.useEffect)(()=>()=>{H.current&&clearTimeout(H.current)},[]);let ae=(0,j.useCallback)(async()=>{let e=g.trim(),n=e.length>0?e:``;L(!0),z(null),V(!1);try{t.system.info(`Saving custom_model override`,{custom_model:n});let e=(await f({custom_model:n})).custom_model??``;S(e),N(e),V(!0),H.current&&clearTimeout(H.current),H.current=setTimeout(()=>V(!1),2200)}catch(e){let n=e instanceof Error?e.message:String(e);t.system.error(`Failed to save custom_model`,e),z(n)}finally{L(!1)}},[g]),oe=(0,j.useCallback)(async()=>{if(q||J)return;let e=G,n=!e;K(n),ne(!0),ie(null);try{t.system.info(`Saving dynamic_tools setting`,{dynamic_tools:n});let e=await f({dynamic_tools:n});K(e.dynamic_tools),te(e.dynamic_tools_locked)}catch(n){let r=n instanceof Error?n.message:String(n);t.system.error(`Failed to save dynamic_tools`,n),K(e),ie(r)}finally{ne(!1)}},[G,q,J]),se=g.trim()!==D.trim(),Y=n?n.default_model_name:k,{isLoadingModel:ce,isDownloadingModel:X,downloadError:Z,loadModel:le,downloadModel:ue}=E(Y??void 0),Q=!!n?.default_model_is_cloud,de=!Q&&!!(n?.lemonade_running&&n.model_loaded&&n.expected_model_loaded===!1),fe=!Q&&!!(n?.lemonade_running&&n.model_loaded&&n.context_size_sufficient===!1),$=!Q&&!(!n?.lemonade_running||n.model_loaded||n.model_downloaded!==!1),pe=(de||fe)&&Y!==null,me=d.some(e=>!e.connected);return s(`div`,{className:`settings-pane`,children:[o(`h2`,{className:`settings-pane-title`,children:e(`settings.section.advanced`)}),o(`section`,{className:`settings-card`,"aria-label":e(`settings.advanced.status`),children:c?o(`p`,{className:`loading-text`,children:e(`settings.advanced.checking`)}):n?s(i.Fragment,{children:[s(`div`,{className:`status-grid`,children:[o(W,{label:e(`settings.advanced.modelServer`),value:n.lemonade_running?n.lemonade_version?e(`settings.advanced.runningAt`,{version:n.lemonade_version}):e(`settings.advanced.running`):x(n)?e(`settings.advanced.notInstalled`):n.lemonade_error?e(`settings.advanced.unavailable`):e(`settings.advanced.notRunning`),ok:n.lemonade_running,hint:n.lemonade_running?void 0:x(n)?e(`settings.advanced.notInstalledHint`):n.lemonade_error?e(`settings.advanced.queryFailed`,{reason:n.lemonade_error}):n.start_instruction&&!O(n.start_instruction)?n.start_instruction:e(`settings.advanced.notRunningHint`)}),x(n)&&o(T,{className:`btn-primary`}),o(W,{label:e(`settings.section.model`),value:n.model_loaded||e(`settings.advanced.noneLoaded`),ok:!!n.model_loaded&&(Q||n.expected_model_loaded!==!1),hint:n.model_loaded?!Q&&n.expected_model_loaded===!1?e(`settings.advanced.expected`,{name:Y??``}):void 0:e(`settings.advanced.loadsFirst`)}),o(W,{label:e(`settings.advanced.disk`),value:s(`bdi`,{dir:`ltr`,children:[n.disk_space_gb,` GB`]}),ok:n.disk_space_gb>5,hint:!n.model_loaded&&n.disk_space_gb<30?e(`settings.advanced.diskLow`,{need:`6 GB`,size:`${n.disk_space_gb} GB`}):void 0})]}),$&&s(`div`,{className:`model-action-row model-action-row--download`,children:[s(`div`,{className:`model-action-info`,children:[o(`span`,{className:`model-action-label`,children:e(`settings.advanced.notDownloaded`)}),o(`span`,{className:`model-action-desc`,children:e(`settings.advanced.notDownloadedHint`,{name:Y??``,need:`6 GB`})})]}),o(`button`,{className:`btn-model-action btn-model-action--download`,onClick:()=>ue(!1,void 0,!n.model_loaded),disabled:X,children:X?s(i.Fragment,{children:[o(v,{size:13,className:`btn-spinner`}),` `,e(`settings.advanced.downloading`)]}):e(`settings.model.download`)})]}),$&&Z&&o(b,{message:Z}),pe&&s(`div`,{className:`model-action-row model-action-row--load`,children:[s(`div`,{className:`model-action-info`,children:[o(`span`,{className:`model-action-label`,children:e(de?`settings.advanced.wrongModel`:`settings.advanced.smallContext`)}),o(`span`,{className:`model-action-desc`,children:e(`settings.advanced.loadHint`,{name:Y??``})})]}),o(`button`,{className:`btn-model-action btn-model-action--load`,onClick:()=>le(),disabled:ce,children:ce?s(i.Fragment,{children:[o(v,{size:13,className:`btn-spinner`}),` `,e(`settings.advanced.loading`)]}):e(`settings.advanced.load`)})]}),s(`details`,{className:`settings-more`,children:[s(`summary`,{children:[o(_,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,e(`settings.advanced.details`)]}),s(`div`,{className:`status-grid`,children:[n.model_size_gb!=null&&o(W,{label:e(`settings.advanced.modelSize`),value:s(`bdi`,{dir:`ltr`,children:[n.model_size_gb,` GB`]}),ok:!0}),n.model_device&&!Q&&o(W,{label:e(`settings.advanced.device`),value:n.model_device.toUpperCase(),ok:n.model_device!==`cpu`}),n.model_context_size!=null&&o(W,{label:e(`settings.advanced.context`),value:e(`settings.ctx.tokens`,{size:`${(n.model_context_size/1024).toFixed(0)}K`}),ok:n.context_size_sufficient}),n.model_labels&&n.model_labels.length>0&&o(W,{label:e(`settings.advanced.capabilities`),value:n.model_labels.join(`, `),ok:!0}),o(W,{label:e(`settings.advanced.embedding`),value:n.embedding_model_loaded?e(`settings.advanced.available`):e(`settings.advanced.notLoaded`),ok:n.embedding_model_loaded}),n.gpu_name&&o(W,{label:`GPU`,value:o(`bdi`,{children:`${n.gpu_name}${n.gpu_vram_gb?` (${C(n.gpu_vram_gb)})`:``}`}),ok:!0}),o(W,{label:e(`settings.advanced.memory`),value:n.memory_available_gb==null?e(`settings.advanced.unknown`):s(`bdi`,{dir:`ltr`,children:[n.memory_available_gb,` GB`]}),ok:n.memory_available_gb!=null&&n.memory_available_gb>2}),n.processor_name&&o(W,{label:e(`settings.advanced.processor`),value:o(`bdi`,{children:n.processor_name}),ok:!0})]}),n.lemonade_running&&Y!==null&&!Q&&s(`div`,{className:`force-redownload-row`,children:[o(`span`,{className:`force-redownload-label`,children:e(`settings.advanced.corrupted`)}),o(`button`,{className:`btn-force-redownload`,onClick:()=>ue(!0,void 0,!n.model_loaded),disabled:X,children:X?s(i.Fragment,{children:[o(v,{size:12,className:`btn-spinner`}),` `,e(`settings.advanced.downloading`)]}):e(`settings.advanced.redownload`)})]}),!$&&Z&&o(b,{message:Z})]})]}):o(`div`,{className:`status-error`,children:o(`p`,{children:e(`settings.advanced.unreachable`)})})}),s(w,{title:e(`settings.advanced.serverTitle`),hint:e(`settings.advanced.serverHint`),children:[o(ee,{}),o(M,{})]}),s(w,{title:e(`settings.advanced.customTitle`),hint:D||e(`settings.advanced.customHint`),children:[o(`p`,{className:`model-override-desc`,children:e(`settings.advanced.customDesc`)}),s(`div`,{className:`model-input-row`,children:[o(`input`,{type:`text`,className:`model-input${D?` has-override`:``}`,placeholder:e.bare(`settings.advanced.customPlaceholder`),value:g,onChange:e=>{S(e.target.value),z(null),V(!1)},onKeyDown:e=>{e.key===`Enter`&&!I&&se&&P&&(e.preventDefault(),ae())},disabled:!P||I,spellCheck:!1,autoCapitalize:`off`,autoCorrect:`off`,"aria-label":e(`settings.advanced.customAria`)}),o(`div`,{className:`model-btn-group`,children:o(`button`,{className:`btn-model-save${B?` saved`:``}`,onClick:()=>{ae()},disabled:!P||I||!se&&!B,"aria-label":e(`settings.advanced.customSave`),children:I?s(i.Fragment,{children:[o(v,{size:13,className:`btn-spinner`}),` `,e(`settings.models.applying`)]}):B?s(i.Fragment,{children:[o(A,{size:13}),` `,e(`settings.advanced.saved`)]}):e(`settings.advanced.save`)})})]}),o(`p`,{className:`model-status-hint`,children:e(`settings.advanced.customIds`)}),R&&o(U,{message:R})]}),s(w,{title:e(`settings.advanced.dynamicTitle`),children:[o(`p`,{className:`model-override-desc`,children:e(`settings.advanced.dynamicDesc`)}),s(`label`,{className:`setting-row`,children:[o(`span`,{children:e(`settings.advanced.dynamicEnable`)}),s(`span`,{className:`toggle-switch`,children:[o(`input`,{type:`checkbox`,checked:G,onChange:()=>void oe(),disabled:!P||J||q,"aria-label":e(G?`settings.advanced.dynamicOff`:`settings.advanced.dynamicOn`)}),o(`span`,{className:`toggle-track`})]})]}),q&&o(`p`,{className:`model-status-hint`,children:e(`settings.advanced.dynamicLocked`)}),re&&o(U,{message:re})]}),d.length>0&&o(w,{title:e(`settings.advanced.mcp`),count:d.length,defaultOpen:me,children:o(`div`,{className:`status-grid`,children:d.map(t=>s(`div`,{className:`status-row`,children:[o(`bdi`,{className:`status-label`,children:t.name}),o(`div`,{className:`status-value-wrap`,children:t.connected?s(`span`,{className:`status-value ok mcp-status-connected`,children:[o(A,{size:12}),e.plural(`settings.advanced.tools`,t.tool_count)]}):s(`span`,{className:`status-value warn mcp-status-failed`,title:t.error??void 0,children:[o(y,{size:12}),e(`settings.custom.failed`)]})})]},t.name))})}),s(`div`,{className:`about-info`,children:[s(`p`,{children:[s(`bdi`,{dir:`ltr`,children:[`GAIA v`,`0.26.0rc16`]}),` `,o(`span`,{className:`beta-badge`,children:`BETA`})]}),o(`p`,{className:`about-sub`,children:e(`settings.advanced.about`)})]})]})}function U({message:e}){let t=r();return s(`div`,{className:`model-warning`,role:`alert`,children:[o(y,{size:14}),s(`div`,{className:`model-warning-content`,children:[o(`strong`,{children:t(`settings.advanced.saveFailed`)}),o(`p`,{children:e})]})]})}function W({label:e,value:t,ok:n,hint:r}){return s(`div`,{className:`status-row${r?` status-row--has-hint`:``}`,children:[o(`span`,{className:`status-label`,children:e}),s(`div`,{className:`status-value-wrap`,children:[o(`span`,{className:`status-value ${n?`ok`:`warn`}`,children:t}),r&&o(`span`,{className:`status-hint`,children:r})]})]})}export{H as AdvancedSettings};