@amd-gaia/agent-ui 0.27.0-rc.11 → 0.27.0-rc.13
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/dist/assets/AdvancedSettings-D2hiKcb8.js +1 -0
- package/dist/assets/{AutomationsSettings-CBgmdTDU.js → AutomationsSettings-kmr5NhGJ.js} +1 -1
- package/dist/assets/ConnectorsPane-BKJzwjs_.js +1 -0
- package/dist/assets/DocumentLibrary-Cen-e75Q.js +5 -0
- package/dist/assets/FileBrowser-C1BvzIK3.js +4 -0
- package/dist/assets/MemoryDashboard-CTv0qxep.js +1 -0
- package/dist/assets/{MessagingSettings-CKylzEfe.js → MessagingSettings-Z9ZX0Hcu.js} +1 -1
- package/dist/assets/MobileAccessModal-De86l1zd.js +2 -0
- package/dist/assets/{ScheduleManager-xu8gK_Yr.js → ScheduleManager-BLUwCMl0.js} +1 -1
- package/dist/assets/folderIndexResult-kIPjvkMW.js +1 -0
- package/dist/assets/{index-DTQb951g.js → index-BFIVkgAZ.js} +55 -55
- package/dist/assets/{index-ByAKIpox.css → index-DB1-bDNU.css} +1 -1
- package/dist/assets/useFocusTrap-CzBMA4Ux.js +6 -0
- package/dist/index.html +3 -3
- package/dist/sw.js +1 -1
- package/main-safety-net.cjs +19 -0
- package/main.cjs +150 -44
- package/package.json +1 -1
- package/services/backend-crash-dialog.cjs +19 -5
- package/services/backend-health-monitor.cjs +86 -0
- package/services/backend-supervisor.cjs +11 -3
- package/services/browser-pane/dev-servers.cjs +44 -1
- package/services/browser-pane/listen-addresses.cjs +140 -0
- package/services/link-policy.cjs +48 -13
- package/services/port-manager.cjs +2 -3
- package/services/process-tree.cjs +84 -14
- package/dist/assets/AdvancedSettings-Bwkk7Urp.js +0 -1
- package/dist/assets/ConnectorsPane-C84jzSpJ.js +0 -1
- package/dist/assets/DocumentLibrary-BQsh6FlL.js +0 -5
- package/dist/assets/FileBrowser-Cd6e0KtR.js +0 -4
- package/dist/assets/MemoryDashboard-CA-SQUh6.js +0 -1
- package/dist/assets/MobileAccessModal-Dxs7Nnto.js +0 -2
- package/dist/assets/useFocusTrap-bD-rtqqm.js +0 -6
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
* A ledger file records each server's pids and command lines, so the next
|
|
15
15
|
* launch can stop servers a crash left behind. It only ever signals a pid it
|
|
16
16
|
* recorded whose command line still matches.
|
|
17
|
+
*
|
|
18
|
+
* A server must listen only on loopback. Once its port answers, the
|
|
19
|
+
* addresses it is bound to are read from the OS; one bound to every interface
|
|
20
|
+
* or to a network address is stopped with an error saying how to bind it.
|
|
17
21
|
*/
|
|
18
22
|
|
|
19
23
|
"use strict";
|
|
@@ -24,6 +28,7 @@ const net = require("net");
|
|
|
24
28
|
const path = require("path");
|
|
25
29
|
const { BridgeError } = require("./bridge-error.cjs");
|
|
26
30
|
const { descendantsFromTable, killProcessTree, listProcesses } = require("../process-tree.cjs");
|
|
31
|
+
const { isLoopback, listeningAddresses } = require("./listen-addresses.cjs");
|
|
27
32
|
|
|
28
33
|
/** @typedef {import("./contract").DevServerSpec} DevServerSpec */
|
|
29
34
|
/** @typedef {import("./contract").DevServerState} DevServerState */
|
|
@@ -49,6 +54,10 @@ const LINE_CHARS = 500;
|
|
|
49
54
|
const PROBE_EVERY_MS = 100;
|
|
50
55
|
const PROBE_TIMEOUT_MS = 400;
|
|
51
56
|
const REAP_GRACE_MS = 3000;
|
|
57
|
+
const LOOPBACK_HINT =
|
|
58
|
+
'Start it bound to 127.0.0.1: in launch.json\'s runtimeArgs add "--bind 127.0.0.1" for python -m http.server, ' +
|
|
59
|
+
'"--host 127.0.0.1" for Vite or webpack serve, "--hostname 127.0.0.1" for Next.js, "-a 127.0.0.1" for http-server, ' +
|
|
60
|
+
'or "--listen tcp://127.0.0.1:<port>" for serve; for an npm script, put the flag in package.json\'s script.';
|
|
52
61
|
const ERROR_LINE = /\berror\b|\bfailed\b|\bexception\b|\bfatal\b|\bpanic\b|ERR!/i;
|
|
53
62
|
|
|
54
63
|
function envNameAllowed(name) {
|
|
@@ -56,6 +65,7 @@ function envNameAllowed(name) {
|
|
|
56
65
|
}
|
|
57
66
|
|
|
58
67
|
/**
|
|
68
|
+
* HOST=127.0.0.1 is the loopback bind for dev servers that read it; launch.json may set another loopback HOST.
|
|
59
69
|
* @param {DevServerSpec} spec @param {NodeJS.ProcessEnv} from
|
|
60
70
|
* @param {string | null} searchPath The backend's login-shell PATH; an app opened from the Dock has only launchd's.
|
|
61
71
|
*/
|
|
@@ -63,7 +73,7 @@ function childEnv(spec, from, searchPath = null) {
|
|
|
63
73
|
const env = {};
|
|
64
74
|
for (const name of INHERITED_ENV) if (from[name] !== undefined) env[name] = from[name];
|
|
65
75
|
if (searchPath) env.PATH = searchPath;
|
|
66
|
-
return { ...env, ...spec.env };
|
|
76
|
+
return { ...env, HOST: "127.0.0.1", ...spec.env };
|
|
67
77
|
}
|
|
68
78
|
|
|
69
79
|
/** True when something accepts a TCP connection on the port, over IPv4 or IPv6 loopback. */
|
|
@@ -148,6 +158,7 @@ class DevServerSupervisor {
|
|
|
148
158
|
* spawn?: typeof childProcess.spawn,
|
|
149
159
|
* listProcesses?: typeof listProcesses,
|
|
150
160
|
* killTree?: typeof killProcessTree,
|
|
161
|
+
* listeningAddresses?: typeof listeningAddresses,
|
|
151
162
|
* reapGraceMs?: number,
|
|
152
163
|
* logger?: { log: Function, error: Function },
|
|
153
164
|
* }} deps
|
|
@@ -158,6 +169,7 @@ class DevServerSupervisor {
|
|
|
158
169
|
spawn: childProcess.spawn,
|
|
159
170
|
listProcesses,
|
|
160
171
|
killTree: killProcessTree,
|
|
172
|
+
listeningAddresses,
|
|
161
173
|
reapGraceMs: REAP_GRACE_MS,
|
|
162
174
|
logger: console,
|
|
163
175
|
...deps,
|
|
@@ -427,10 +439,41 @@ class DevServerSupervisor {
|
|
|
427
439
|
}
|
|
428
440
|
await new Promise((r) => setTimeout(r, PROBE_EVERY_MS));
|
|
429
441
|
}
|
|
442
|
+
await this.requireLoopbackOnly(entry);
|
|
430
443
|
entry.status = "ready";
|
|
431
444
|
this.deps.onChange();
|
|
432
445
|
}
|
|
433
446
|
|
|
447
|
+
/** Stop a server anything off this computer could reach, or whose binding can't be read. */
|
|
448
|
+
async requireLoopbackOnly(entry) {
|
|
449
|
+
let addresses;
|
|
450
|
+
try {
|
|
451
|
+
addresses = await this.deps.listeningAddresses(entry.spec.port);
|
|
452
|
+
} catch (err) {
|
|
453
|
+
await this.halt(entry);
|
|
454
|
+
throw this.notLoopback(entry, `answered, but GAIA could not read which network addresses it listens on (${err.message}), so it stopped it rather than risk exposing it.`, []);
|
|
455
|
+
}
|
|
456
|
+
const open = addresses.filter((a) => !isLoopback(a));
|
|
457
|
+
if (addresses.length > 0 && open.length === 0) return;
|
|
458
|
+
await this.halt(entry);
|
|
459
|
+
if (addresses.length === 0) {
|
|
460
|
+
throw this.notLoopback(entry, "answered, but GAIA could not see which address it listens on, so it stopped it rather than risk exposing it.", []);
|
|
461
|
+
}
|
|
462
|
+
const everywhere = open.some((a) => a === "*" || a === "0.0.0.0" || a === "::");
|
|
463
|
+
const where = everywhere ? "all network interfaces" : `the network address ${open.join(", ")}`;
|
|
464
|
+
throw this.notLoopback(entry, `listened on ${where}, so other computers on the network could reach it; GAIA stopped it.`, open);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
notLoopback(entry, what, addresses) {
|
|
468
|
+
const { spec } = entry;
|
|
469
|
+
this.deps.logger.error(`[dev-servers] Stopped "${spec.name}" on port ${spec.port}: not bound to loopback only (${addresses.join(", ") || "binding unknown"}).`);
|
|
470
|
+
return new BridgeError("dev_server_failed", `Dev server "${spec.name}" (${spec.argv.join(" ")}) on port ${spec.port} ${what} ${LOOPBACK_HINT}`, {
|
|
471
|
+
exitCode: null,
|
|
472
|
+
lines: [],
|
|
473
|
+
addresses,
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
|
|
434
477
|
failed(entry, what) {
|
|
435
478
|
const { spec } = entry;
|
|
436
479
|
const lines = readLines(entry.logFile).slice(-FAIL_LINES);
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Copyright(C) 2026 Advanced Micro Devices, Inc. All rights reserved.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The local addresses TCP listeners on one port are bound to, read from the
|
|
6
|
+
* OS: `lsof` on macOS and other Unixes, /proc/net/tcp{,6} on Linux, and
|
|
7
|
+
* `netstat -ano` on Windows. A dev server GAIA starts must listen only on
|
|
8
|
+
* loopback, so nothing else on the network can reach the folder it serves.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
"use strict";
|
|
12
|
+
|
|
13
|
+
const childProcess = require("child_process");
|
|
14
|
+
const fs = require("fs");
|
|
15
|
+
const os = require("os");
|
|
16
|
+
const path = require("path");
|
|
17
|
+
|
|
18
|
+
const LIST_TIMEOUT_MS = 10000;
|
|
19
|
+
const PROC_LISTEN_STATE = "0A";
|
|
20
|
+
|
|
21
|
+
/** True for 127.0.0.0/8 and ::1 (also as an IPv4-mapped address). "*", 0.0.0.0 and :: are every interface. */
|
|
22
|
+
function isLoopback(address) {
|
|
23
|
+
const a = String(address).replace(/^\[|\]$/g, "").replace(/%.*$/, "").toLowerCase();
|
|
24
|
+
if (/^127\.\d+\.\d+\.\d+$/.test(a)) return true;
|
|
25
|
+
if (/^::ffff:127\.\d+\.\d+\.\d+$/.test(a)) return true;
|
|
26
|
+
return a === "::1" || a === "0:0:0:0:0:0:0:1";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** "1.2.3.4:80" or "[::1]:80" -> { address, port }; null when there is no port. */
|
|
30
|
+
function splitHostPort(text) {
|
|
31
|
+
const cut = text.lastIndexOf(":");
|
|
32
|
+
if (cut <= 0) return null;
|
|
33
|
+
const port = Number(text.slice(cut + 1));
|
|
34
|
+
if (!Number.isInteger(port)) return null;
|
|
35
|
+
return { address: text.slice(0, cut).replace(/^\[|\]$/g, ""), port };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** `lsof -nP -iTCP:<port> -sTCP:LISTEN -Fn` output: one "n<addr>:<port>" line per socket. */
|
|
39
|
+
function parseLsof(stdout, port) {
|
|
40
|
+
const found = [];
|
|
41
|
+
for (const line of stdout.split(/\r?\n/)) {
|
|
42
|
+
if (!line.startsWith("n")) continue;
|
|
43
|
+
const hp = splitHostPort(line.slice(1));
|
|
44
|
+
if (hp && hp.port === port) found.push(hp.address);
|
|
45
|
+
}
|
|
46
|
+
return found;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A /proc/net/tcp address: 32-bit words in host byte order, hex. */
|
|
50
|
+
function decodeProcAddress(hex, endianness = os.endianness()) {
|
|
51
|
+
const bytes = [];
|
|
52
|
+
for (let w = 0; w < hex.length; w += 8) {
|
|
53
|
+
const word = hex.slice(w, w + 8).match(/../g).map((b) => parseInt(b, 16));
|
|
54
|
+
bytes.push(...(endianness === "LE" ? word.reverse() : word));
|
|
55
|
+
}
|
|
56
|
+
if (bytes.length === 4) return bytes.join(".");
|
|
57
|
+
if (bytes.every((b) => b === 0)) return "::";
|
|
58
|
+
if (bytes.slice(0, 15).every((b) => b === 0) && bytes[15] === 1) return "::1";
|
|
59
|
+
if (bytes.slice(0, 10).every((b) => b === 0) && bytes[10] === 0xff && bytes[11] === 0xff) {
|
|
60
|
+
return `::ffff:${bytes.slice(12).join(".")}`;
|
|
61
|
+
}
|
|
62
|
+
const groups = [];
|
|
63
|
+
for (let i = 0; i < 16; i += 2) groups.push(((bytes[i] << 8) | bytes[i + 1]).toString(16));
|
|
64
|
+
return groups.join(":");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The listening sockets on `port` in one /proc/net/tcp or tcp6 table. */
|
|
68
|
+
function parseProcNetTcp(text, port, endianness = os.endianness()) {
|
|
69
|
+
const found = [];
|
|
70
|
+
for (const line of text.split(/\r?\n/).slice(1)) {
|
|
71
|
+
const cols = line.trim().split(/\s+/);
|
|
72
|
+
if (cols.length < 4 || cols[3] !== PROC_LISTEN_STATE) continue;
|
|
73
|
+
const [addrHex, portHex] = cols[1].split(":");
|
|
74
|
+
if (parseInt(portHex, 16) !== port) continue;
|
|
75
|
+
found.push(decodeProcAddress(addrHex, endianness));
|
|
76
|
+
}
|
|
77
|
+
return found;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* `netstat -ano` output. The state column is translated on non-English
|
|
82
|
+
* Windows, so a listener is told by its foreign address, which is always
|
|
83
|
+
* 0.0.0.0:0 or [::]:0 for one and never for a connection.
|
|
84
|
+
*/
|
|
85
|
+
function parseNetstat(stdout, port) {
|
|
86
|
+
const found = [];
|
|
87
|
+
for (const line of stdout.split(/\r?\n/)) {
|
|
88
|
+
const cols = line.trim().split(/\s+/);
|
|
89
|
+
if (cols.length < 4 || cols[0].toUpperCase() !== "TCP") continue;
|
|
90
|
+
if (cols[2] !== "0.0.0.0:0" && cols[2] !== "[::]:0") continue;
|
|
91
|
+
const hp = splitHostPort(cols[1]);
|
|
92
|
+
if (hp && hp.port === port) found.push(hp.address);
|
|
93
|
+
}
|
|
94
|
+
return found;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function run(execFile, file, args) {
|
|
98
|
+
return new Promise((resolve, reject) => {
|
|
99
|
+
execFile(file, args, { timeout: LIST_TIMEOUT_MS, windowsHide: true, maxBuffer: 16 * 1024 * 1024 }, (err, stdout) => {
|
|
100
|
+
if (err) reject(Object.assign(err, { stdout: String(stdout || "") }));
|
|
101
|
+
else resolve(String(stdout));
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Every local address something listens on at `port`. Rejects when the OS
|
|
108
|
+
* can't be asked, never answers "none" for a list it could not read.
|
|
109
|
+
* @param {number} port
|
|
110
|
+
* @returns {Promise<string[]>}
|
|
111
|
+
*/
|
|
112
|
+
async function listeningAddresses(
|
|
113
|
+
port,
|
|
114
|
+
{ platform = process.platform, execFile = childProcess.execFile, readFile = fs.promises.readFile, env = process.env } = {}
|
|
115
|
+
) {
|
|
116
|
+
if (platform === "linux") {
|
|
117
|
+
const v4 = await readFile("/proc/net/tcp", "utf8");
|
|
118
|
+
let v6 = "";
|
|
119
|
+
try {
|
|
120
|
+
v6 = await readFile("/proc/net/tcp6", "utf8");
|
|
121
|
+
} catch (err) {
|
|
122
|
+
if (err.code !== "ENOENT") throw err;
|
|
123
|
+
}
|
|
124
|
+
return [...parseProcNetTcp(v4, port), ...parseProcNetTcp(v6, port)];
|
|
125
|
+
}
|
|
126
|
+
if (platform === "win32") {
|
|
127
|
+
const root = env.SystemRoot || env.SYSTEMROOT || "C:\\Windows";
|
|
128
|
+
return parseNetstat(await run(execFile, path.win32.join(root, "System32", "netstat.exe"), ["-ano"]), port);
|
|
129
|
+
}
|
|
130
|
+
const lsof = platform === "darwin" ? "/usr/sbin/lsof" : "lsof";
|
|
131
|
+
try {
|
|
132
|
+
return parseLsof(await run(execFile, lsof, ["-nP", `-iTCP:${port}`, "-sTCP:LISTEN", "-Fn"]), port);
|
|
133
|
+
} catch (err) {
|
|
134
|
+
// lsof exits 1 with no output when nothing matches.
|
|
135
|
+
if (err.code === 1 && !err.stdout.trim()) return [];
|
|
136
|
+
throw err;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
module.exports = { decodeProcAddress, isLoopback, listeningAddresses, parseLsof, parseNetstat, parseProcNetTcp };
|
package/services/link-policy.cjs
CHANGED
|
@@ -60,26 +60,62 @@ function isInAppNavigation(targetUrl, currentUrl) {
|
|
|
60
60
|
);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
// U+2068/U+2069 keep a URL left-to-right inside Arabic text.
|
|
64
|
+
const isolate = (text) => `${text}`;
|
|
65
|
+
|
|
66
|
+
const NOTICE_TEXT = {
|
|
67
|
+
en: {
|
|
68
|
+
blockedTitle: "Link blocked",
|
|
69
|
+
notOpenedTitle: "Link not opened",
|
|
70
|
+
ok: "OK",
|
|
71
|
+
noScheme: "no scheme",
|
|
72
|
+
blocked: (url, scheme) =>
|
|
73
|
+
`GAIA refused to open "${url}" (${scheme}). ` +
|
|
74
|
+
"Only http, https and mailto links open outside the app — a link that " +
|
|
75
|
+
"resolves to a local file or network share is never launched.",
|
|
76
|
+
openFailed: (url, reason) =>
|
|
77
|
+
`GAIA couldn't open "${url}": ${reason}. ` +
|
|
78
|
+
"Check that this PC has an app set up for that kind of link.",
|
|
79
|
+
},
|
|
80
|
+
ar: {
|
|
81
|
+
blockedTitle: "تم حظر الرابط",
|
|
82
|
+
notOpenedTitle: "لم يُفتح الرابط",
|
|
83
|
+
ok: "حسنًا",
|
|
84
|
+
noScheme: "بلا بروتوكول",
|
|
85
|
+
blocked: (url, scheme) =>
|
|
86
|
+
`رفض GAIA فتح "${isolate(url)}" (${isolate(scheme)}). ` +
|
|
87
|
+
"لا تُفتح خارج التطبيق إلا روابط http وhttps وmailto، ولا يُشغَّل أبدًا " +
|
|
88
|
+
"رابط يشير إلى ملف محلي أو مجلد مشترك على الشبكة.",
|
|
89
|
+
openFailed: (url, reason) =>
|
|
90
|
+
`تعذّر على GAIA فتح "${isolate(url)}": ${isolate(reason)}. ` +
|
|
91
|
+
"تأكد من وجود تطبيق على هذا الجهاز مُعدّ لفتح هذا النوع من الروابط.",
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/** The link-notice strings for an OS locale such as "ar-EG"; English for any language without them. */
|
|
96
|
+
function linkNoticeText(locale) {
|
|
97
|
+
const lang = String(locale || "").toLowerCase().split(/[-_]/)[0];
|
|
98
|
+
return NOTICE_TEXT[lang] || NOTICE_TEXT.en;
|
|
99
|
+
}
|
|
100
|
+
|
|
63
101
|
/**
|
|
64
102
|
* A one-line, user-facing reason a URL was refused. Never silently dropped —
|
|
65
103
|
* the caller logs this and shows it, so a blocked click is explainable.
|
|
66
104
|
*
|
|
67
105
|
* @param {string} rawUrl
|
|
106
|
+
* @param {string} [locale] The OS locale, as `app.getLocale()` gives it.
|
|
68
107
|
* @returns {string}
|
|
69
108
|
*/
|
|
70
|
-
function describeBlockedUrl(rawUrl) {
|
|
109
|
+
function describeBlockedUrl(rawUrl, locale) {
|
|
110
|
+
const text = linkNoticeText(locale);
|
|
71
111
|
const shown = typeof rawUrl === "string" && rawUrl ? rawUrl : String(rawUrl);
|
|
72
|
-
let scheme =
|
|
112
|
+
let scheme = text.noScheme;
|
|
73
113
|
try {
|
|
74
114
|
scheme = new URL(shown).protocol.replace(/:$/, "");
|
|
75
115
|
} catch {
|
|
76
|
-
/* keep "no scheme" */
|
|
116
|
+
/* keep the "no scheme" label */
|
|
77
117
|
}
|
|
78
|
-
return (
|
|
79
|
-
`GAIA refused to open "${shown.slice(0, 300)}" (${scheme}). ` +
|
|
80
|
-
"Only http, https and mailto links open outside the app — a link that " +
|
|
81
|
-
"resolves to a local file or network share is never launched."
|
|
82
|
-
);
|
|
118
|
+
return text.blocked(shown.slice(0, 300), scheme);
|
|
83
119
|
}
|
|
84
120
|
|
|
85
121
|
/**
|
|
@@ -87,17 +123,15 @@ function describeBlockedUrl(rawUrl) {
|
|
|
87
123
|
*
|
|
88
124
|
* @param {string} rawUrl
|
|
89
125
|
* @param {unknown} err
|
|
126
|
+
* @param {string} [locale] The OS locale, as `app.getLocale()` gives it.
|
|
90
127
|
* @returns {string}
|
|
91
128
|
*/
|
|
92
|
-
function describeOpenFailure(rawUrl, err) {
|
|
129
|
+
function describeOpenFailure(rawUrl, err, locale) {
|
|
93
130
|
const reason = (err && err.message ? err.message : String(err)).replace(
|
|
94
131
|
/\.+$/,
|
|
95
132
|
"",
|
|
96
133
|
);
|
|
97
|
-
return (
|
|
98
|
-
`GAIA couldn't open "${String(rawUrl).slice(0, 300)}": ${reason}. ` +
|
|
99
|
-
"Check that this PC has an app set up for that kind of link."
|
|
100
|
-
);
|
|
134
|
+
return linkNoticeText(locale).openFailed(String(rawUrl).slice(0, 300), reason);
|
|
101
135
|
}
|
|
102
136
|
|
|
103
137
|
/**
|
|
@@ -123,4 +157,5 @@ module.exports = {
|
|
|
123
157
|
describeBlockedUrl,
|
|
124
158
|
describeOpenFailure,
|
|
125
159
|
openExternalSafely,
|
|
160
|
+
linkNoticeText,
|
|
126
161
|
};
|
|
@@ -68,13 +68,12 @@ function findFreePort() {
|
|
|
68
68
|
async function killBackend(procOrPid, logger) {
|
|
69
69
|
const log = (logger && logger.log) || console.log;
|
|
70
70
|
const logError = (logger && logger.error) || console.error;
|
|
71
|
-
if (!procOrPid) return;
|
|
71
|
+
if (!procOrPid) return { killed: [], survivors: [], verified: true };
|
|
72
72
|
const proc = typeof procOrPid === "object" ? procOrPid : null;
|
|
73
73
|
if (proc && (proc.exitCode !== null || proc.signalCode !== null)) {
|
|
74
74
|
log(`[port-manager] child pid ${proc.pid} already exited (exitCode=${proc.exitCode} signal=${proc.signalCode})`);
|
|
75
|
-
return;
|
|
76
75
|
}
|
|
77
|
-
|
|
76
|
+
return killProcessTree(procOrPid, {
|
|
78
77
|
graceMs: BACKEND_KILL_GRACE_MS,
|
|
79
78
|
forceWaitMs: BACKEND_FORCE_WAIT_MS,
|
|
80
79
|
log,
|
|
@@ -22,6 +22,7 @@ const childProcess = require("child_process");
|
|
|
22
22
|
|
|
23
23
|
const DEFAULT_GRACE_MS = 3000;
|
|
24
24
|
const DEFAULT_FORCE_WAIT_MS = 1000;
|
|
25
|
+
const pendingTreeState = new WeakMap();
|
|
25
26
|
// PowerShell's CIM query takes about a second on an idle PC and several on a
|
|
26
27
|
// loaded one; timing out strands every process the agent started. `ps` is fast.
|
|
27
28
|
const WINDOWS_LIST_TIMEOUT_MS = 20000;
|
|
@@ -195,7 +196,7 @@ function rootAlive(proc, pid) {
|
|
|
195
196
|
* on Linux and macOS when the root may already have exited: its children
|
|
196
197
|
* are then re-parented and can no longer be found from it. Each is killed
|
|
197
198
|
* only while its command line still matches, so a reused pid is spared.
|
|
198
|
-
* @returns {Promise<{ killed: number[], survivors: number[] }>}
|
|
199
|
+
* @returns {Promise<{ killed: number[], survivors: number[], verified: boolean }>}
|
|
199
200
|
*/
|
|
200
201
|
async function killProcessTree(target, opts = {}) {
|
|
201
202
|
const {
|
|
@@ -209,36 +210,75 @@ async function killProcessTree(target, opts = {}) {
|
|
|
209
210
|
} = opts;
|
|
210
211
|
const proc = target && typeof target === "object" ? target : null;
|
|
211
212
|
const pid = proc ? proc.pid : target;
|
|
212
|
-
if (!pid) return { killed: [], survivors: [] };
|
|
213
|
+
if (!pid) return { killed: [], survivors: [], verified: true };
|
|
213
214
|
|
|
214
215
|
const readTable = () => (opts.listProcesses || listProcesses)(opts);
|
|
215
216
|
|
|
216
217
|
// pid -> command, for every non-root member we intend to stop.
|
|
218
|
+
const priorState = proc ? pendingTreeState.get(proc) : null;
|
|
219
|
+
const known = new Map((priorState && priorState.descendants ? priorState.descendants : []).map((d) => [d.pid, d]));
|
|
220
|
+
for (const d of knownDescendants) known.set(d.pid, d);
|
|
221
|
+
let unknownTree = Boolean(priorState && priorState.unknown);
|
|
222
|
+
if (!rootAlive(proc, pid) && known.size === 0) unknownTree = true;
|
|
217
223
|
const members = new Map();
|
|
224
|
+
const unverifiedMembers = new Map();
|
|
218
225
|
const absorb = (table) => {
|
|
219
226
|
const live = new Map(table.map((r) => [r.pid, r.command]));
|
|
227
|
+
for (const [memberPid, descendant] of [...known]) {
|
|
228
|
+
const command = live.get(memberPid);
|
|
229
|
+
if (command === descendant.command) {
|
|
230
|
+
unverifiedMembers.delete(memberPid);
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
if (command !== undefined || !pidAlive(memberPid)) {
|
|
234
|
+
known.delete(memberPid);
|
|
235
|
+
members.delete(memberPid);
|
|
236
|
+
unverifiedMembers.delete(memberPid);
|
|
237
|
+
} else {
|
|
238
|
+
unverifiedMembers.set(memberPid, descendant);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
220
241
|
// A member that exited, or whose pid now runs something else, is no
|
|
221
242
|
// longer ours to signal.
|
|
222
243
|
for (const [memberPid, command] of [...members]) {
|
|
223
|
-
if (live.get(memberPid) !== command)
|
|
244
|
+
if (live.get(memberPid) !== command) {
|
|
245
|
+
members.delete(memberPid);
|
|
246
|
+
if (live.has(memberPid) || !pidAlive(memberPid)) known.delete(memberPid);
|
|
247
|
+
}
|
|
224
248
|
}
|
|
225
|
-
for (const d of
|
|
249
|
+
for (const d of known.values()) {
|
|
226
250
|
if (live.has(d.pid) && live.get(d.pid) === d.command) members.set(d.pid, d.command);
|
|
227
251
|
}
|
|
228
252
|
if (live.has(pid) && rootAlive(proc, pid)) {
|
|
229
|
-
for (const d of descendantsFromTable(table, pid).descendants)
|
|
253
|
+
for (const d of descendantsFromTable(table, pid).descendants) {
|
|
254
|
+
members.set(d.pid, d.command);
|
|
255
|
+
known.set(d.pid, d);
|
|
256
|
+
}
|
|
230
257
|
}
|
|
231
258
|
// Children of members that outlived their parent's handle.
|
|
232
259
|
for (const memberPid of [...members.keys()]) {
|
|
233
|
-
for (const d of descendantsFromTable(table, memberPid).descendants)
|
|
260
|
+
for (const d of descendantsFromTable(table, memberPid).descendants) {
|
|
261
|
+
members.set(d.pid, d.command);
|
|
262
|
+
known.set(d.pid, d);
|
|
263
|
+
}
|
|
234
264
|
}
|
|
235
265
|
};
|
|
236
266
|
|
|
237
267
|
let tableError = null;
|
|
238
268
|
try {
|
|
239
|
-
|
|
269
|
+
const table = await readTable();
|
|
270
|
+
if (rootAlive(proc, pid) && !table.some((row) => row.pid === pid)) {
|
|
271
|
+
tableError = new Error(`the live root pid ${pid} was missing from the process table`);
|
|
272
|
+
unknownTree = true;
|
|
273
|
+
logError(`[process-tree] ${label} ${pid}: ${tableError.message}; descendants may keep running.`);
|
|
274
|
+
}
|
|
275
|
+
absorb(table);
|
|
276
|
+
if (!rootAlive(proc, pid) && known.size === 0 && unverifiedMembers.size === 0) unknownTree = false;
|
|
240
277
|
} catch (err) {
|
|
241
278
|
tableError = err;
|
|
279
|
+
unknownTree = true;
|
|
280
|
+
for (const d of known.values()) unverifiedMembers.set(d.pid, d);
|
|
281
|
+
members.clear();
|
|
242
282
|
logError(
|
|
243
283
|
`[process-tree] ${label} ${pid}: ${err.message} — only the ${label} itself will be stopped; ` +
|
|
244
284
|
"any process it started may keep running. Check them with Task Manager or `ps`."
|
|
@@ -248,7 +288,8 @@ async function killProcessTree(target, opts = {}) {
|
|
|
248
288
|
const signal = (p, sig) => {
|
|
249
289
|
try {
|
|
250
290
|
if (p === pid && proc) {
|
|
251
|
-
if (rootAlive(proc, pid))
|
|
291
|
+
if (!rootAlive(proc, pid)) return false;
|
|
292
|
+
return proc.kill(sig) !== false;
|
|
252
293
|
} else {
|
|
253
294
|
process.kill(p, sig);
|
|
254
295
|
}
|
|
@@ -271,27 +312,56 @@ async function killProcessTree(target, opts = {}) {
|
|
|
271
312
|
};
|
|
272
313
|
|
|
273
314
|
const all = () => [pid, ...members.keys()];
|
|
315
|
+
const observed = () => [...new Set([...all(), ...unverifiedMembers.keys()])];
|
|
274
316
|
const killed = [];
|
|
275
317
|
for (const p of all()) {
|
|
276
318
|
if (alive(p) && signal(p, "SIGTERM")) killed.push(p);
|
|
277
319
|
}
|
|
278
|
-
if (killed.length
|
|
279
|
-
|
|
320
|
+
if (killed.length) {
|
|
321
|
+
log(`[process-tree] SIGTERM sent to ${label} ${pid} and ${killed.length - (killed.includes(pid) ? 1 : 0)} descendant(s)`);
|
|
322
|
+
}
|
|
280
323
|
|
|
281
|
-
|
|
324
|
+
const finish = (survivors, verified) => {
|
|
325
|
+
if (!rootAlive(proc, pid)) {
|
|
326
|
+
for (const memberPid of known.keys()) {
|
|
327
|
+
if (!pidAlive(memberPid)) known.delete(memberPid);
|
|
328
|
+
}
|
|
329
|
+
for (const memberPid of unverifiedMembers.keys()) {
|
|
330
|
+
if (!pidAlive(memberPid)) unverifiedMembers.delete(memberPid);
|
|
331
|
+
}
|
|
332
|
+
if (!tableError && known.size === 0 && unverifiedMembers.size === 0) unknownTree = false;
|
|
333
|
+
verified = !unknownTree && !tableError && survivors.length === 0;
|
|
334
|
+
}
|
|
335
|
+
const result = { killed, survivors: [...new Set(survivors)], verified };
|
|
336
|
+
if (proc) {
|
|
337
|
+
if (verified) pendingTreeState.delete(proc);
|
|
338
|
+
else pendingTreeState.set(proc, { descendants: [...known.values()], unknown: unknownTree });
|
|
339
|
+
}
|
|
340
|
+
return result;
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
if (await waitAllGone(observed(), graceMs)) {
|
|
344
|
+
const survivors = [...unverifiedMembers.keys()].filter(pidAlive);
|
|
345
|
+
return finish(survivors, !unknownTree && !tableError && survivors.length === 0);
|
|
346
|
+
}
|
|
282
347
|
|
|
283
348
|
if (platform === "win32") {
|
|
284
349
|
// SIGTERM was already TerminateProcess, so a member still listed is one
|
|
285
350
|
// that could not be ended or a pid already reused: only the root, through
|
|
286
351
|
// its handle, is worth a second try. Skipping the re-read also keeps a
|
|
287
352
|
// slow PowerShell from eating the quit's time limit.
|
|
353
|
+
for (const [memberPid, command] of members) {
|
|
354
|
+
if (alive(memberPid)) unverifiedMembers.set(memberPid, { pid: memberPid, command });
|
|
355
|
+
}
|
|
288
356
|
members.clear();
|
|
289
357
|
} else if (!tableError) {
|
|
290
358
|
try {
|
|
291
359
|
absorb(await readTable());
|
|
292
360
|
} catch (err) {
|
|
293
361
|
// Without a fresh table a member's pid may already belong to a stranger.
|
|
362
|
+
for (const [memberPid, command] of members) unverifiedMembers.set(memberPid, { pid: memberPid, command });
|
|
294
363
|
members.clear();
|
|
364
|
+
unknownTree = true;
|
|
295
365
|
logError(
|
|
296
366
|
`[process-tree] ${label} ${pid}: re-reading the tree before SIGKILL failed (${err.message}); ` +
|
|
297
367
|
`only the ${label} itself gets SIGKILL — any process it started may keep running.`
|
|
@@ -304,15 +374,15 @@ async function killProcessTree(target, opts = {}) {
|
|
|
304
374
|
}
|
|
305
375
|
log(`[process-tree] SIGKILL sent to ${stubborn.length} process(es) of ${label} ${pid} that ignored SIGTERM`);
|
|
306
376
|
|
|
307
|
-
await waitAllGone(stubborn, forceWaitMs);
|
|
308
|
-
const survivors = stubborn.filter(alive);
|
|
377
|
+
await waitAllGone([...stubborn, ...unverifiedMembers.keys()], forceWaitMs);
|
|
378
|
+
const survivors = [...new Set([...stubborn.filter(alive), ...[...unverifiedMembers.keys()].filter(pidAlive)])];
|
|
309
379
|
if (survivors.length) {
|
|
310
380
|
logError(
|
|
311
381
|
`[process-tree] ${label} ${pid}: pid(s) ${survivors.join(", ")} still running ${forceWaitMs} ms after SIGKILL — ` +
|
|
312
382
|
"end them with Task Manager or `kill -9` before relaunching GAIA."
|
|
313
383
|
);
|
|
314
384
|
}
|
|
315
|
-
return
|
|
385
|
+
return finish(survivors, !unknownTree && !tableError && survivors.length === 0);
|
|
316
386
|
}
|
|
317
387
|
|
|
318
388
|
module.exports = {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{$t as t,Gt as n,Hn as r,Jt as i,Nn as a,Pn as o,U as s,Vt as c,Zt as l,c as u,hi as d,l as f,mn as p,ot as m,s as h,u as g,wi as _,x as v}from"./useFocusTrap-bD-rtqqm.js";import{Dn as y,It as b,Mt as x,Nt as S,Ot as C,Pt as w,Sn as T,at as E,c as D,d as O,g as k,l as A,m as j,n as M,nn as N,o as P,p as F,qt as I,s as ee,u as te,xn as L}from"./index-DTQb951g.js";var R=e(_(),1);function ne(){let e=h(),t=v(e=>e.runSetupAgain),n=v(e=>e.closeSettings),[r,i]=(0,R.useState)(null),[o,s]=(0,R.useState)(null),[l,d]=(0,R.useState)(``),[p,m]=(0,R.useState)(``),[_,y]=(0,R.useState)(!1),[b,x]=(0,R.useState)(null),[S,C]=(0,R.useState)(!1);(0,R.useEffect)(()=>{c().then(e=>{i(e),d(e.saved_base_url??e.base_url??``)}).catch(e=>s(e instanceof Error?e.message:String(e)))},[]);let w=(0,R.useCallback)(async e=>{y(!0),x(null);try{let r=await a(e);i(r),m(``),C(!1),r.mode===`gaia`&&!r.gaia_installed&&(n(),t(!0))}catch(e){C(F(e)),x(e instanceof Error?e.message:String(e))}finally{y(!1)}},[n,t]),T=()=>void w({mode:`external`,base_url:l.trim(),api_key:p.trim()||void 0});if(o)return g(`section`,{className:`settings-section`,children:[f(`h4`,{children:e(`settings.advanced.modelServer`)}),g(`div`,{className:`model-warning`,role:`alert`,children:[f(L,{size:14}),g(`div`,{className:`model-warning-content`,children:[f(`strong`,{children:e(`settings.server.readFailed`)}),f(`p`,{children:o})]})]})]});if(!r)return null;let E=r.mode===`external`,D=r.source===`env`;return g(`section`,{className:`settings-section`,"aria-label":e(`settings.advanced.modelServer`),children:[f(`h4`,{children:e(`settings.advanced.modelServer`)}),f(`p`,{className:`model-override-desc`,role:`status`,children:D?e(`settings.server.usesEnv`,{url:r.base_url??``}):E?e(`settings.server.usesYours`,{url:r.base_url??``}):e(`settings.server.usesOwn`)}),!D&&r.env_url_ignored&&f(`p`,{className:`model-status-hint`,children:e(`settings.server.envIgnored`,{url:r.env_url_ignored})}),D?f(`p`,{className:`model-status-hint`,children:e(`settings.server.envUseOwn`)}):g(u.Fragment,{children:[g(`p`,{className:`model-status-hint`,children:[e(`settings.server.useYours`),` `,f(`bdi`,{children:r.what_gaia_does})]}),g(`form`,{className:`model-input-row`,onSubmit:e=>{e.preventDefault(),T()},children:[f(`input`,{type:`text`,className:`model-input`,placeholder:`http://localhost:13305`,value:l,onChange:e=>{d(e.target.value),x(null)},disabled:_,spellCheck:!1,autoCapitalize:`off`,autoCorrect:`off`,"aria-label":e(`settings.server.address`)}),f(`input`,{type:`password`,className:`model-input`,autoComplete:`off`,placeholder:r.api_key_stored?e.bare(`settings.server.keySaved`):e.bare(`settings.server.keyOptional`),value:p,onChange:e=>m(e.target.value),disabled:_,"aria-label":e(`settings.server.key`)}),f(`div`,{className:`model-btn-group`,children:f(`button`,{type:`submit`,className:`btn-primary`,disabled:_||!l.trim(),children:_?g(u.Fragment,{children:[f(N,{size:13,className:`btn-spinner`}),` `,e(`settings.server.checking`)]}):e(`settings.server.use`)})})]})]}),E&&f(`div`,{className:`setting-actions`,children:f(`button`,{type:`button`,className:`btn-secondary`,disabled:_,onClick:()=>void w({mode:`gaia`}),children:e(`settings.server.useOwn`)})}),b&&g(`div`,{className:`model-warning`,role:`alert`,children:[f(L,{size:14}),g(`div`,{className:`model-warning-content`,children:[f(`strong`,{children:e(S?`settings.server.needsKey`:`settings.server.notSwitched`)}),f(`p`,{children:b})]})]})]})}var re={vulkan:`Vulkan`,rocm:`ROCm`,metal:`Metal`,cpu:`CPU`,npu:`NPU`,remote:`Remote (cloud)`},z={gaia:`settings.server.ownerGaia`,user:`settings.server.ownerUser`,remote:`settings.server.ownerRemote`};function B(e){return e?re[e]??e:`unknown`}function V(e){if(!e)return`unknown`;let t=B(e.backend);return e.backend_source===`lemonade_default`?`${t} (Lemonade's default)`:t}function H(e){return e?`${Math.round(e/1024)}K tokens`:`unknown`}var U={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 W(e,t){if(!e.model_type)return t(`settings.server.loadedModel`);let n=e.model_type.toLowerCase(),r=U[n];return r?t(r):t(`settings.server.kindOther`,{kind:`${n.charAt(0).toUpperCase()}${n.slice(1)}`})}function G(e,t){let n=[e.name?x(e.name):t.bare(`settings.server.unknownModel`),V(e)];return e.backend!==`remote`&&e.ctx_size&&n.push(H(e.ctx_size)),n.join(` · `)}function K({label:e,value:t,title:n}){return g(`div`,{className:`status-row`,children:[f(`span`,{className:`status-label`,children:e}),f(`span`,{className:`status-value model-server-value`,dir:`auto`,title:n??t,children:t})]})}function ie(){let e=h(),t=v(e=>e.openSettings),n=b(e=>e.show),[r,a]=(0,R.useState)(null),[s,c]=(0,R.useState)(null),[l,d]=(0,R.useState)(null),[m,_]=(0,R.useState)(null),[y,S]=(0,R.useState)(!1);(0,R.useEffect)(()=>{i().then(a).catch(e=>c(e instanceof Error?e.message:String(e)))},[]);let C=(0,R.useCallback)(async t=>{d(t),_(null);try{let n=await o(t);a(n),_({ok:!0,text:e(`settings.server.savedBackend`)})}catch(e){_({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{d(null)}},[e]),w=r?.chat_model??null,T=(0,R.useCallback)(async()=>{if(w?.name){S(!0);try{if(!await p(w.name,w.ctx_size??void 0))return;_({ok:!0,text:e(`settings.server.reloading`,{name:w.name})})}catch(e){_({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{S(!1)}}},[w,e]),D=f(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>t(`model`),children:e(`settings.server.changeModel`)}),O=g(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>n(`model_server`),children:[f(I,{size:13,"aria-hidden":`true`}),` `,e(`logs.serverLog`)]});if(s)return g(`section`,{className:`settings-section`,"aria-label":e(`settings.advanced.modelServer`),children:[f(`h4`,{children:e(`settings.advanced.modelServer`)}),f(P,{message:s})]});if(!r)return g(`section`,{className:`settings-section`,"aria-label":e(`settings.advanced.modelServer`),children:[f(`h4`,{children:e(`settings.advanced.modelServer`)}),f(`p`,{className:`loading-text`,children:e(`settings.server.checkingServer`)})]});if(!r.reachable)return g(`section`,{className:`settings-section`,"aria-label":e(`settings.advanced.modelServer`),children:[f(`h4`,{children:e(`settings.advanced.modelServer`)}),f(P,{message:r.error??e(`settings.errors.serverDownTitle`)}),g(`div`,{className:`settings-row`,children:[D,O]})]});let k=r.available_backends??[],A=r.preferred_backend??null,j=k.map(e=>e.name);A&&!j.includes(A)&&j.push(A);let M=A??r.default_backend??null,F=k.filter(e=>e.state===`installable`).map(e=>B(e.name)),ee=!!w?.name&&w.recipe===`llamacpp`;return g(`section`,{className:`settings-section`,"aria-label":e(`settings.advanced.modelServer`),children:[f(`h4`,{children:e(`settings.advanced.modelServer`)}),g(`div`,{className:`status-grid`,children:[f(K,{label:e(`settings.server.server`),value:`${z[r.owner]?e(z[r.owner]):r.owner}${r.version?` v${r.version}`:``}`}),f(K,{label:e(`settings.server.addressShort`),value:r.base_url}),f(K,{label:e(`settings.server.chatModel`),value:w?.name?x(w.name):e(`settings.advanced.noneLoaded`),title:w?.name??void 0}),w&&f(K,{label:e(`settings.server.runsOn`),value:V(w)}),w&&w.backend!==`remote`&&f(K,{label:e(`settings.advanced.context`),value:H(w.ctx_size)}),f(K,{label:e(`settings.advanced.embedding`),value:r.embedding_model?.name?`${r.embedding_model.name} · ${V(r.embedding_model)}`:e(`settings.advanced.noneLoaded`)}),(r.loaded_models??[]).map((t,n)=>f(K,{label:W(t,e),value:G(t,e),title:t.name??void 0},`${t.name??`unknown`}-${n}`))]}),r.embedding_note&&f(`p`,{className:`settings-hint`,children:f(`bdi`,{children:r.embedding_note})}),r.system_info_error&&f(`p`,{className:`settings-hint`,children:f(`bdi`,{children:r.system_info_error})}),g(`div`,{className:`settings-field model-server-backend`,children:[f(`span`,{className:`settings-label`,children:e(`settings.server.backend`)}),k.length===0&&!A?f(`span`,{className:`settings-hint`,children:e(`settings.server.noBackends`)}):g(u.Fragment,{children:[f(E,{className:`segmented`,"aria-label":e(`settings.server.backendShort`),children:j.map(e=>g(`button`,{type:`button`,role:`radio`,"aria-checked":M===e,className:M===e?`is-active`:``,disabled:l!==null,onClick:()=>{e!==M&&C(e)},children:[l===e?f(N,{size:12,className:`spin`}):null,B(e)]},e))}),g(`span`,{className:`settings-hint`,children:[e(`settings.server.backendHint`),F.length>0&&` ${e(`settings.server.installable`,{names:F.join(`, `)})}`]})]}),m?.ok&&f(`p`,{className:`settings-ok`,role:`status`,children:m.text}),m&&!m.ok&&f(P,{message:m.text})]}),g(`div`,{className:`settings-row`,children:[D,O,ee&&g(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void T(),disabled:y,children:[y?f(N,{size:13,className:`spin`}):null,e(`settings.server.reload`)]})]})]})}function ae(e,t){return!e||!t||t.found?null:{kind:t.checked?`unlisted`:`unchecked`,id:e}}function q(){let e=h(),[i,a]=(0,R.useState)(null),[o,c]=(0,R.useState)(!0),[p,_]=(0,R.useState)([]),[v,b]=(0,R.useState)(``),[x,E]=(0,R.useState)(``),[j,F]=(0,R.useState)(!1),[I,re]=(0,R.useState)(!1),[z,B]=(0,R.useState)(null),[V,H]=(0,R.useState)(null),[U,W]=(0,R.useState)(!1),G=(0,R.useRef)(null),[K,q]=(0,R.useState)(!1),[J,le]=(0,R.useState)(!1),[ue,de]=(0,R.useState)(!1),[fe,pe]=(0,R.useState)(null);(0,R.useEffect)(()=>{d.system.info(`Checking system status...`);let e=d.system.time();t().then(t=>{a(t),d.system.timed(`System status received`,e,{lemonade:t.lemonade_running?`running`:`stopped`,model:t.model_loaded||`none`,embedding:t.embedding_model_loaded?`yes`:`no`,disk:`${t.disk_space_gb}GB free`,memory:t.memory_available_gb==null?`unknown`:`${t.memory_available_gb}GB available`}),t.lemonade_running||d.system.warn(`Lemonade Server is NOT running.`)}).catch(e=>{d.system.error(`Failed to get system status`,e),a(null)}).finally(()=>c(!1)),n().then(e=>_(e.servers)).catch(()=>{}),l().then(e=>{let t=e.custom_model??``;b(t),E(t),H(ae(t,e.model_status)),q(e.dynamic_tools),le(e.dynamic_tools_locked)}).catch(e=>{d.system.error(`Failed to load settings`,e)}).finally(()=>F(!0))},[]),(0,R.useEffect)(()=>()=>{G.current&&clearTimeout(G.current)},[]);let me=(0,R.useCallback)(async()=>{let n=v.trim(),i=n.length>0?n:``,o=w.getState().active?.model;re(!0),B(null),H(null),W(!1);try{d.system.info(`Saving custom_model override`,{custom_model:i});let e=await r({custom_model:i}),n=e.custom_model??``;b(n),E(n),S(o),t().then(a).catch(e=>d.system.error(`Failed to get system status`,e)),H(ae(n,e.model_status)),W(!0),G.current&&clearTimeout(G.current),G.current=setTimeout(()=>W(!1),2200)}catch(t){d.system.error(`Failed to save custom_model`,t);let n=t instanceof m&&t.httpStatus===422&&t.fields.includes(`custom_model`);B(n?e(`settings.advanced.customModelInvalid`):t instanceof Error?t.message:String(t))}finally{re(!1)}},[v,e]),he=(0,R.useCallback)(async()=>{if(J||ue)return;let e=K,t=!e;q(t),de(!0),pe(null);try{d.system.info(`Saving dynamic_tools setting`,{dynamic_tools:t});let e=await r({dynamic_tools:t});q(e.dynamic_tools),le(e.dynamic_tools_locked)}catch(t){let n=t instanceof Error?t.message:String(t);d.system.error(`Failed to save dynamic_tools`,t),q(e),pe(n)}finally{de(!1)}},[K,J,ue]),ge=v.trim()!==x.trim(),X=i?i.default_model_name:C,{isLoadingModel:_e,isDownloadingModel:Z,downloadError:Q,loadModel:ve,downloadModel:ye}=M(X??void 0),$=!!i?.default_model_is_cloud,be=!$&&!!(i?.lemonade_running&&i.model_loaded&&i.expected_model_loaded===!1&&i.model_downloaded!==!1),xe=!$&&!!(i?.lemonade_running&&i.model_loaded&&i.context_size_sufficient===!1),Se=!$&&!(!i?.lemonade_running||i.model_loaded||i.model_downloaded!==!1),Ce=(be||xe)&&X!==null,we=p.some(e=>!e.connected);return g(`div`,{className:`settings-pane`,children:[f(`h2`,{className:`settings-pane-title`,children:e(`settings.section.advanced`)}),f(`section`,{className:`settings-card`,"aria-label":e(`settings.advanced.status`),children:o?f(`p`,{className:`loading-text`,children:e(`settings.advanced.checking`)}):i?g(u.Fragment,{children:[g(`div`,{className:`status-grid`,children:[f(Y,{label:e(`settings.advanced.modelServer`),value:i.lemonade_running?i.lemonade_version?e(`settings.advanced.runningAt`,{version:i.lemonade_version}):e(`settings.advanced.running`):A(i)?e(`settings.advanced.notInstalled`):i.lemonade_error?e(`settings.advanced.unavailable`):e(`settings.advanced.notRunning`),ok:i.lemonade_running,hint:i.lemonade_running?void 0:A(i)?e(`settings.advanced.notInstalledHint`):i.lemonade_error?e(`settings.advanced.queryFailed`,{reason:i.lemonade_error}):i.start_instruction&&!D(i.start_instruction)?te(e,i.start_instruction)??void 0:e(`settings.advanced.notRunningHint`)}),A(i)&&f(ee,{className:`btn-primary`}),f(Y,{label:e(`settings.section.model`),value:i.model_loaded||e(`settings.advanced.noneLoaded`),ok:!!i.model_loaded&&($||i.expected_model_loaded!==!1),hint:i.model_loaded?!$&&i.expected_model_loaded===!1?e(`settings.advanced.expected`,{name:X??``}):void 0:e(i.lemonade_running?`settings.advanced.loadsFirst`:`settings.advanced.loadsWhenBack`)}),f(Y,{label:e(`settings.advanced.disk`),value:g(`bdi`,{dir:`ltr`,children:[i.disk_space_gb,` GB`]}),ok:i.disk_space_gb>5,hint:!i.model_loaded&&i.disk_space_gb<30?e(`settings.advanced.diskLow`,{need:`6 GB`,size:`${i.disk_space_gb} GB`}):void 0})]}),Se&&g(`div`,{className:`model-action-row model-action-row--download`,children:[g(`div`,{className:`model-action-info`,children:[f(`span`,{className:`model-action-label`,children:e(`settings.advanced.notDownloaded`)}),f(`span`,{className:`model-action-desc`,children:e(`settings.advanced.notDownloadedHint`,{name:X??``,need:`6 GB`})})]}),f(`button`,{className:`btn-primary`,onClick:()=>ye(!1,void 0,!i.model_loaded),disabled:Z,children:Z?g(u.Fragment,{children:[f(N,{size:13,className:`btn-spinner`}),` `,e(`settings.advanced.downloading`)]}):e(`settings.model.download`)})]}),Se&&Q&&f(P,{message:Q}),Ce&&g(`div`,{className:`model-action-row model-action-row--load`,children:[g(`div`,{className:`model-action-info`,children:[f(`span`,{className:`model-action-label`,children:e(be?`settings.advanced.wrongModel`:`settings.advanced.smallContext`)}),f(`span`,{className:`model-action-desc`,children:e(`settings.advanced.loadHint`,{name:X??``})})]}),f(`button`,{className:`btn-primary`,onClick:()=>ve(),disabled:_e,children:_e?g(u.Fragment,{children:[f(N,{size:13,className:`btn-spinner`}),` `,e(`settings.advanced.loading`)]}):e(`settings.advanced.load`)})]}),g(`details`,{className:`settings-more`,children:[g(`summary`,{children:[f(y,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,e(`settings.advanced.details`)]}),g(`div`,{className:`status-grid`,children:[i.model_size_gb!=null&&f(Y,{label:e(`settings.advanced.modelSize`),value:g(`bdi`,{dir:`ltr`,children:[i.model_size_gb,` GB`]}),ok:!0}),i.model_device&&!$&&f(Y,{label:e(`settings.advanced.device`),value:i.model_device.toUpperCase(),ok:i.model_device!==`cpu`}),i.model_context_size!=null&&f(Y,{label:e(`settings.advanced.context`),value:e(`settings.ctx.tokens`,{size:`${(i.model_context_size/1024).toFixed(0)}K`}),ok:i.context_size_sufficient}),i.model_labels&&i.model_labels.length>0&&f(Y,{label:e(`settings.advanced.capabilities`),value:ce(e,i.model_labels),ok:!0}),f(Y,{label:e(`settings.advanced.embedding`),value:i.embedding_model_loaded?e(`settings.advanced.available`):e(`settings.advanced.notLoaded`),ok:i.embedding_model_loaded}),i.gpu_name&&f(Y,{label:`GPU`,value:f(`bdi`,{children:`${i.gpu_name}${i.gpu_vram_gb?` (${k(i.gpu_vram_gb)})`:``}`}),ok:!0}),f(Y,{label:e(`settings.advanced.memory`),value:i.memory_available_gb==null?e(`settings.advanced.unknown`):g(`bdi`,{dir:`ltr`,children:[i.memory_available_gb,` GB`]}),ok:i.memory_available_gb!=null&&i.memory_available_gb>2}),i.processor_name&&f(Y,{label:e(`settings.advanced.processor`),value:f(`bdi`,{children:i.processor_name}),ok:!0})]}),i.lemonade_running&&X!==null&&!$&&g(`div`,{className:`force-redownload-row`,children:[f(`span`,{className:`force-redownload-label`,children:e(`settings.advanced.corrupted`)}),f(`button`,{className:`btn-secondary`,onClick:()=>ye(!0,void 0,!i.model_loaded),disabled:Z,children:Z?g(u.Fragment,{children:[f(N,{size:12,className:`btn-spinner`}),` `,e(`settings.advanced.downloading`)]}):e(`settings.advanced.redownload`)})]}),!Se&&Q&&f(P,{message:Q})]})]}):f(`div`,{className:`status-error`,children:f(`p`,{children:e(`settings.advanced.unreachable`)})})}),f(oe,{}),g(O,{title:e(`settings.advanced.serverTitle`),hint:e(`settings.advanced.serverHint`),targetId:`model-server`,children:[f(ie,{}),f(ne,{})]}),g(O,{title:e(`settings.advanced.customTitle`),hint:x?s(x,`ltr`):e(`settings.advanced.customHint`),targetId:`custom-model`,children:[f(`p`,{className:`model-override-desc`,children:e(`settings.advanced.customDesc`)}),g(`div`,{className:`model-input-row`,children:[f(`input`,{type:`text`,className:`model-input${x?` has-override`:``}`,placeholder:e.bare(`settings.advanced.customPlaceholder`),value:v,dir:v?`ltr`:void 0,onChange:e=>{b(e.target.value),B(null),H(null),W(!1)},onKeyDown:e=>{e.key===`Enter`&&!I&&ge&&j&&(e.preventDefault(),me())},disabled:!j||I,spellCheck:!1,autoCapitalize:`off`,autoCorrect:`off`,"aria-label":e(`settings.advanced.customAria`)}),f(`div`,{className:`model-btn-group`,children:f(`button`,{className:`btn-primary`,onClick:()=>{me()},disabled:!j||I||!ge&&!U,"aria-label":e(`settings.advanced.customSave`),children:I?g(u.Fragment,{children:[f(N,{size:13,className:`btn-spinner`}),` `,e(`settings.models.applying`)]}):U?g(u.Fragment,{children:[f(T,{size:13}),` `,e(`settings.advanced.saved`)]}):e(`settings.advanced.save`)})})]}),f(`p`,{className:`model-status-hint`,children:e(`settings.advanced.customIds`)}),z&&f(se,{message:z}),V&&g(`div`,{className:`model-warning`,role:`status`,children:[f(L,{size:14}),f(`div`,{className:`model-warning-content`,children:f(`p`,{children:V.kind===`unlisted`?e(`settings.advanced.customNotListed`,{id:V.id}):e(`settings.advanced.customNotChecked`)})})]})]}),g(O,{title:e(`settings.advanced.dynamicTitle`),children:[f(`p`,{className:`model-override-desc`,children:e(`settings.advanced.dynamicDesc`)}),g(`label`,{className:`setting-row`,children:[f(`span`,{children:e(`settings.advanced.dynamicEnable`)}),g(`span`,{className:`toggle-switch`,children:[f(`input`,{type:`checkbox`,checked:K,onChange:()=>void he(),disabled:!j||ue||J,"aria-label":e(K?`settings.advanced.dynamicOff`:`settings.advanced.dynamicOn`)}),f(`span`,{className:`toggle-track`})]})]}),J&&f(`p`,{className:`model-status-hint`,children:e(`settings.advanced.dynamicLocked`)}),fe&&f(se,{message:fe})]}),p.length>0&&f(O,{title:e(`settings.advanced.mcp`),count:p.length,defaultOpen:we,children:f(`div`,{className:`status-grid`,children:p.map(t=>g(`div`,{className:`status-row`,children:[f(`bdi`,{className:`status-label`,children:t.name}),f(`div`,{className:`status-value-wrap`,children:t.connected?g(`span`,{className:`status-value ok mcp-status-connected`,children:[f(T,{size:12}),e.plural(`settings.advanced.tools`,t.tool_count)]}):g(`span`,{className:`status-value warn mcp-status-failed`,title:t.error??void 0,children:[f(L,{size:12}),e(`settings.custom.failed`)]})})]},t.name))})})]})}function oe(){let e=h(),t=b(e=>e.show);return g(`section`,{className:`settings-card`,"aria-labelledby":`settings-logs-title`,children:[f(`h3`,{className:`settings-label`,id:`settings-logs-title`,children:e(`logs.title`)}),f(`p`,{className:`settings-hint`,children:e(`logs.settingsHint`)}),f(`div`,{className:`settings-row`,children:g(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>t(`gaia`),children:[f(I,{size:13,"aria-hidden":`true`}),` `,e(`logs.view`)]})}),f(j,{})]})}function se({message:e}){let t=h();return g(`div`,{className:`model-warning`,role:`alert`,children:[f(L,{size:14}),g(`div`,{className:`model-warning-content`,children:[f(`strong`,{children:t(`settings.advanced.saveFailed`)}),f(`p`,{children:e})]})]})}var J={cloud:`settings.advanced.capability.cloud`,chat:`settings.advanced.capability.chat`,vision:`settings.advanced.capability.vision`,"tool-calling":`settings.advanced.capability.toolCalling`,reasoning:`settings.advanced.capability.reasoning`,embeddings:`settings.advanced.capability.embeddings`,reranking:`settings.advanced.capability.reranking`,coding:`settings.advanced.capability.coding`,audio:`settings.advanced.capability.audio`,image:`settings.advanced.capability.image`,tts:`settings.advanced.capability.tts`,stt:`settings.advanced.capability.stt`,transcription:`settings.advanced.capability.transcription`};function ce(e,t){return e.compose(e=>t.map(t=>J[t]?e(J[t]):t).join(e(`mem.listSeparator`)))}function Y({label:e,value:t,ok:n,hint:r}){return g(`div`,{className:`status-row${r?` status-row--has-hint`:``}`,children:[f(`span`,{className:`status-label`,children:e}),g(`div`,{className:`status-value-wrap`,children:[f(`span`,{className:`status-value ${n?`ok`:`warn`}`,children:t}),r&&f(`span`,{className:`status-hint`,children:r})]})]})}export{q as AdvancedSettings};
|