om-memory-system 3.5.0-next.32 → 3.5.0-next.33
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/cli/web-command.js
CHANGED
|
@@ -15,6 +15,8 @@ export async function runWebCommand(args, options = {}, online) {
|
|
|
15
15
|
console.error("OMMS web server is disabled (webServerEnabled is false)");
|
|
16
16
|
return 1;
|
|
17
17
|
}
|
|
18
|
+
const { webServerUrl } = await import("../services/web-api-auth.js");
|
|
19
|
+
const url = webServerUrl(config.CONFIG.webServerHost, config.CONFIG.webServerPort);
|
|
18
20
|
if (action === "install" || action === "uninstall") {
|
|
19
21
|
const { readGlobalConfigRevision, writeGlobalConfigKeys } = await import("../services/global-config-writer.js");
|
|
20
22
|
await writeGlobalConfigKeys({ webServerAutoStart: action === "install" }, readGlobalConfigRevision());
|
|
@@ -23,6 +25,8 @@ export async function runWebCommand(args, options = {}, online) {
|
|
|
23
25
|
? installWebAutostart({ ...options, start: true })
|
|
24
26
|
: removeWebAutostart({ ...options, start: true });
|
|
25
27
|
console.log(`OMMS login item: ${result.state}`);
|
|
28
|
+
if (action === "install" && result.state === "installed")
|
|
29
|
+
console.log(`OMMS web app: ${url}`);
|
|
26
30
|
return action === "install" && result.state !== "installed" ? 1 : 0;
|
|
27
31
|
}
|
|
28
32
|
if (action === "status") {
|
|
@@ -37,7 +41,7 @@ export async function runWebCommand(args, options = {}, online) {
|
|
|
37
41
|
apiToken: config.CONFIG.webServerApiToken,
|
|
38
42
|
}).checkServerAvailable();
|
|
39
43
|
});
|
|
40
|
-
console.log(JSON.stringify({ setting: config.CONFIG.webServerAutoStart, item: status, online: await check() }, null, 2));
|
|
44
|
+
console.log(JSON.stringify({ setting: config.CONFIG.webServerAutoStart, item: status, url, online: await check() }, null, 2));
|
|
41
45
|
return 0;
|
|
42
46
|
}
|
|
43
47
|
if (!config.CONFIG.webServerEnabled) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export declare function isLoopbackHost(host: string): boolean;
|
|
2
|
+
/** A URL needs brackets around an IPv6 literal such as ::1. */
|
|
3
|
+
export declare function webServerUrl(host: string, port: number): string;
|
|
2
4
|
export declare function assertWebServerNetworkAuth(host: string, apiToken?: string, basicAuthEnabled?: boolean): void;
|
|
3
5
|
export declare function authorizeApiRequest(req: Request, apiToken?: string): Response | null;
|
|
@@ -3,6 +3,11 @@ const LOOPBACK_HOSTS = new Set(["127.0.0.1", "localhost", "::1", "[::1]", "0:0:0
|
|
|
3
3
|
export function isLoopbackHost(host) {
|
|
4
4
|
return LOOPBACK_HOSTS.has(host.trim().toLowerCase());
|
|
5
5
|
}
|
|
6
|
+
/** A URL needs brackets around an IPv6 literal such as ::1. */
|
|
7
|
+
export function webServerUrl(host, port) {
|
|
8
|
+
const urlHost = host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
|
|
9
|
+
return `http://${urlHost}:${port}`;
|
|
10
|
+
}
|
|
6
11
|
export function assertWebServerNetworkAuth(host, apiToken, basicAuthEnabled = false) {
|
|
7
12
|
if (!isLoopbackHost(host) && !apiToken && !basicAuthEnabled) {
|
|
8
13
|
throw new Error(`webServerHost "${host}" exposes the API on the network. Set webServerApiToken in omms.jsonc, or bind to 127.0.0.1.`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { execFileSync } from "node:child_process";
|
|
3
|
-
import { accessSync, existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync, constants, } from "node:fs";
|
|
3
|
+
import { accessSync, existsSync, mkdirSync, readFileSync, realpathSync, renameSync, unlinkSync, writeFileSync, constants, } from "node:fs";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { basename, dirname, join, delimiter, resolve } from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
@@ -23,13 +23,34 @@ function executable(name) {
|
|
|
23
23
|
}
|
|
24
24
|
return null;
|
|
25
25
|
}
|
|
26
|
+
function sameFile(a, b) {
|
|
27
|
+
try {
|
|
28
|
+
return realpathSync(a) === realpathSync(b);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** A Homebrew upgrade deletes the versioned Cellar folder, so use a link that survives it. */
|
|
35
|
+
function stableRuntime(path) {
|
|
36
|
+
const match = /^(.*)[\\/]Cellar[\\/]([^\\/]+)[\\/][^\\/]+[\\/]bin[\\/]([^\\/]+)$/.exec(path);
|
|
37
|
+
const [, prefix, formula, name] = match ?? [];
|
|
38
|
+
if (!prefix || !formula || !name)
|
|
39
|
+
return path;
|
|
40
|
+
const linked = join(prefix, "bin", name);
|
|
41
|
+
if (sameFile(linked, path))
|
|
42
|
+
return linked;
|
|
43
|
+
const opt = join(prefix, "opt", formula, "bin", name);
|
|
44
|
+
return sameFile(opt, path) ? opt : path;
|
|
45
|
+
}
|
|
26
46
|
/** OpenCode's executable is not a JavaScript runtime. */
|
|
27
47
|
export function resolveWebRuntime(execPath = process.execPath, platform = process.platform) {
|
|
28
48
|
const name = basename(execPath).toLowerCase();
|
|
29
49
|
if (["node", "bun", "node.exe", "bun.exe"].includes(name))
|
|
30
|
-
return execPath;
|
|
50
|
+
return stableRuntime(execPath);
|
|
31
51
|
const suffix = platform === "win32" ? ".exe" : "";
|
|
32
|
-
|
|
52
|
+
const found = executable(`node${suffix}`) ?? executable(`bun${suffix}`);
|
|
53
|
+
return found && stableRuntime(found);
|
|
33
54
|
}
|
|
34
55
|
function packageRoot() {
|
|
35
56
|
let dir = dirname(fileURLToPath(import.meta.url));
|
|
@@ -5,7 +5,7 @@ import { join, dirname, extname, normalize, sep } from "node:path";
|
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { log } from "./logger.js";
|
|
7
7
|
import { corsPreflightResponse, disallowedCorsResponse, isAllowedBrowserOrigin } from "./cors.js";
|
|
8
|
-
import { assertWebServerNetworkAuth, authorizeApiRequest, isLoopbackHost } from "./web-api-auth.js";
|
|
8
|
+
import { assertWebServerNetworkAuth, authorizeApiRequest, isLoopbackHost, webServerUrl, } from "./web-api-auth.js";
|
|
9
9
|
import { getOrCreateAuthToken, isAuthorizedApiRequest } from "./auth-token.js";
|
|
10
10
|
import { WebAuth } from "./web-auth.js";
|
|
11
11
|
import { NODE_HTTP_IDLE_TIMEOUT_MS } from "./request-timeouts.js";
|
|
@@ -322,7 +322,7 @@ export class WebServer {
|
|
|
322
322
|
return this.isOwner;
|
|
323
323
|
}
|
|
324
324
|
getUrl() {
|
|
325
|
-
return
|
|
325
|
+
return webServerUrl(this.config.host, this.config.port);
|
|
326
326
|
}
|
|
327
327
|
async checkServerAvailable() {
|
|
328
328
|
try {
|