omo-web 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/bin/access-policy.js +12 -0
- package/bin/launcher-settings.js +116 -0
- package/bin/launcher-tls.js +67 -0
- package/bin/listen-address.js +20 -0
- package/bin/omo-web.js +6 -2
- package/bin/tui.js +229 -42
- package/bin/windows-password.js +8 -4
- package/dist/app.js +6 -6
- package/dist/server.js +107 -31
- package/package.json +2 -5
package/dist/server.js
CHANGED
|
@@ -8586,24 +8586,45 @@ class SessionBranches {
|
|
|
8586
8586
|
import { link, lstat as lstat6, mkdir, readFile as readFile2, readdir as readdir3, realpath as realpath6, rename, unlink as unlink2, writeFile as writeFile2 } from "fs/promises";
|
|
8587
8587
|
import { dirname as dirname4, join as join6, resolve as resolve5 } from "path";
|
|
8588
8588
|
|
|
8589
|
+
// src/command-ownership.ts
|
|
8590
|
+
var terminalOnlyCommands = [
|
|
8591
|
+
"scoped-models",
|
|
8592
|
+
"favorite-models",
|
|
8593
|
+
"task-kill",
|
|
8594
|
+
"login",
|
|
8595
|
+
"logout",
|
|
8596
|
+
"trust",
|
|
8597
|
+
"export",
|
|
8598
|
+
"import",
|
|
8599
|
+
"share",
|
|
8600
|
+
"reload",
|
|
8601
|
+
"keybindings",
|
|
8602
|
+
"changelog",
|
|
8603
|
+
"quit",
|
|
8604
|
+
"exit",
|
|
8605
|
+
"bug",
|
|
8606
|
+
"debug"
|
|
8607
|
+
];
|
|
8608
|
+
var dedicatedCommands = [
|
|
8609
|
+
"dag",
|
|
8610
|
+
"tasks",
|
|
8611
|
+
"todo",
|
|
8612
|
+
"reasoning",
|
|
8613
|
+
"efforts",
|
|
8614
|
+
"compact",
|
|
8615
|
+
"settings",
|
|
8616
|
+
"setting"
|
|
8617
|
+
];
|
|
8618
|
+
|
|
8589
8619
|
// src/commands.ts
|
|
8590
8620
|
var str = (value) => typeof value === "string" ? value : "";
|
|
8591
8621
|
var SHORT_NAME = /^[A-Za-z0-9_-]{1,64}$/;
|
|
8592
8622
|
var SKILL_NAME = /^skill:[A-Za-z0-9-]{1,64}$/;
|
|
8593
|
-
var
|
|
8594
|
-
"/dag",
|
|
8595
|
-
"/tasks",
|
|
8596
|
-
"/task-kill",
|
|
8597
|
-
"/todo",
|
|
8598
|
-
"/reasoning",
|
|
8599
|
-
"/efforts",
|
|
8600
|
-
"/scoped-models",
|
|
8601
|
-
"/favorite-models"
|
|
8602
|
-
]);
|
|
8623
|
+
var reservedCommands = new Set([...dedicatedCommands, ...terminalOnlyCommands].map((name) => `/${name}`));
|
|
8603
8624
|
function refuseRuntimeCommandRelay(text) {
|
|
8604
8625
|
const head = text.split(/\s/u, 1)[0];
|
|
8605
|
-
if (head &&
|
|
8606
|
-
throw new WebError(400, "runtime_command_local", "\
|
|
8626
|
+
if (head && reservedCommands.has(head)) {
|
|
8627
|
+
throw new WebError(400, "runtime_command_local", "\u8BF7\u5728 Web \u4F7F\u7528\u8BE5\u547D\u4EE4\u7684\u4E13\u7528\u5165\u53E3\uFF0C\u6216\u5728\u672C\u673A OmO \u7EC8\u7AEF\u6267\u884C\u7EC8\u7AEF\u4E13\u7528\u547D\u4EE4\u3002");
|
|
8607
8628
|
}
|
|
8608
8629
|
}
|
|
8609
8630
|
function isCommandSource(value) {
|
|
@@ -10665,9 +10686,14 @@ ${source.nativeSessionId}`;
|
|
|
10665
10686
|
case "autoCompaction":
|
|
10666
10687
|
await request("set_auto_compaction", { enabled: action.enabled });
|
|
10667
10688
|
break;
|
|
10668
|
-
case "compact":
|
|
10689
|
+
case "compact": {
|
|
10690
|
+
const current = state(await request("get_state"));
|
|
10691
|
+
if (row.archived || current.isStreaming === true || current.isCompacting === true || typeof current.pendingMessageCount === "number" && current.pendingMessageCount > 0 || this.#live.get(id)?.running) {
|
|
10692
|
+
throw new WebError(409, "session_busy", "\u8BF7\u7B49\u4F1A\u8BDD\u7A7A\u95F2\u4E14\u961F\u5217\u6E05\u7A7A\u540E\u518D\u538B\u7F29\uFF0C\u6216\u5148\u53D6\u6D88\u5F52\u6863\u3002");
|
|
10693
|
+
}
|
|
10669
10694
|
await request("compact", { customInstructions: action.instructions }, 180000);
|
|
10670
10695
|
break;
|
|
10696
|
+
}
|
|
10671
10697
|
case "clearQueue":
|
|
10672
10698
|
await request("clear_queue");
|
|
10673
10699
|
break;
|
|
@@ -11813,6 +11839,39 @@ import { open as open8 } from "fs/promises";
|
|
|
11813
11839
|
import { isIP } from "net";
|
|
11814
11840
|
import { createSecureContext } from "tls";
|
|
11815
11841
|
|
|
11842
|
+
// packaging/npm/access-policy.js
|
|
11843
|
+
var passwordPattern = /^[\x20-\x7e]{1,128}$/;
|
|
11844
|
+
var recommendedPasswordLength = 20;
|
|
11845
|
+
function parseProxyOrigin(value) {
|
|
11846
|
+
try {
|
|
11847
|
+
const url = new URL(value);
|
|
11848
|
+
return url.protocol === "https:" && url.origin === value ? url : undefined;
|
|
11849
|
+
} catch (error) {
|
|
11850
|
+
if (!(error instanceof TypeError))
|
|
11851
|
+
throw error;
|
|
11852
|
+
return;
|
|
11853
|
+
}
|
|
11854
|
+
}
|
|
11855
|
+
|
|
11856
|
+
// packaging/npm/listen-address.js
|
|
11857
|
+
import { networkInterfaces } from "os";
|
|
11858
|
+
var loopbackAddress = "127.0.0.1";
|
|
11859
|
+
var wildcardAddress = "0.0.0.0";
|
|
11860
|
+
function interfaceAddresses() {
|
|
11861
|
+
const entries = new Map;
|
|
11862
|
+
for (const [name, addresses] of Object.entries(networkInterfaces())) {
|
|
11863
|
+
for (const item of addresses ?? []) {
|
|
11864
|
+
if (item.family === "IPv4" && !item.internal && !entries.has(item.address)) {
|
|
11865
|
+
entries.set(item.address, { name, address: item.address, cidr: item.cidr });
|
|
11866
|
+
}
|
|
11867
|
+
}
|
|
11868
|
+
}
|
|
11869
|
+
return [...entries.values()];
|
|
11870
|
+
}
|
|
11871
|
+
function isRemoteAddress(host) {
|
|
11872
|
+
return host !== undefined && host !== loopbackAddress;
|
|
11873
|
+
}
|
|
11874
|
+
|
|
11816
11875
|
// packaging/npm/windows-password.js
|
|
11817
11876
|
import { execFile } from "child_process";
|
|
11818
11877
|
import { join as join8, resolve as resolve7 } from "path";
|
|
@@ -11893,8 +11952,6 @@ class WebAccessConfigError extends Error {
|
|
|
11893
11952
|
this.setting = setting;
|
|
11894
11953
|
}
|
|
11895
11954
|
}
|
|
11896
|
-
var hostSchema = _enum(["127.0.0.1", "0.0.0.0"]);
|
|
11897
|
-
var passwordSchema = string2().regex(/^[\x20-\x7e]{20,128}$/);
|
|
11898
11955
|
var MAX_AUTH_FAILURES = 5;
|
|
11899
11956
|
var MAX_TRACKED_ADDRESSES = 1024;
|
|
11900
11957
|
var AUTH_COOLDOWN_MS = 30000;
|
|
@@ -11981,19 +12038,26 @@ function validateCertificate(cert, key, origin) {
|
|
|
11981
12038
|
}
|
|
11982
12039
|
}
|
|
11983
12040
|
async function loadWebAccess(env, port) {
|
|
11984
|
-
const host =
|
|
11985
|
-
if (!
|
|
11986
|
-
throw new WebAccessConfigError("OMO_WEB_HOST", cliTr("\
|
|
12041
|
+
const host = env.OMO_WEB_HOST ?? loopbackAddress;
|
|
12042
|
+
if (host !== loopbackAddress && host !== wildcardAddress && !interfaceAddresses().some((entry) => entry.address === host)) {
|
|
12043
|
+
throw new WebAccessConfigError("OMO_WEB_HOST", cliTr("\u8BF7\u9009\u62E9 127.0.0.1\u30010.0.0.0 \u6216\u672C\u673A\u7F51\u5361\u5DF2\u5206\u914D\u7684 IPv4 \u5730\u5740\u3002", "Use 127.0.0.1, 0.0.0.0, or an IPv4 address assigned to a local interface."));
|
|
12044
|
+
}
|
|
11987
12045
|
const {
|
|
11988
12046
|
OMO_WEB_PASSWORD_FILE: passwordFile,
|
|
11989
12047
|
OMO_WEB_ORIGIN: originSetting,
|
|
12048
|
+
OMO_WEB_PROXY_ORIGIN: proxySetting,
|
|
11990
12049
|
OMO_WEB_TLS_CERT: certFile,
|
|
11991
12050
|
OMO_WEB_TLS_KEY: keyFile
|
|
11992
12051
|
} = env;
|
|
11993
|
-
const publicBinding = host
|
|
11994
|
-
const
|
|
12052
|
+
const publicBinding = isRemoteAddress(host);
|
|
12053
|
+
const proxyOrigin = proxySetting === undefined ? undefined : parseProxyOrigin(proxySetting);
|
|
12054
|
+
if (proxySetting !== undefined && !proxyOrigin) {
|
|
12055
|
+
throw new WebAccessConfigError("OMO_WEB_PROXY_ORIGIN", cliTr("\u586B\u5199\u4EE3\u7406\u5BF9\u5916\u7684\u5B8C\u6574 HTTPS origin\uFF0C\u4E0D\u80FD\u542B\u8DEF\u5F84\u3001\u5C3E\u90E8\u659C\u6760\u6216\u51ED\u636E\u3002", "Use the proxy's canonical HTTPS origin, without a path, trailing slash, or credentials."));
|
|
12056
|
+
}
|
|
12057
|
+
const exposed = publicBinding || proxyOrigin !== undefined;
|
|
12058
|
+
const unprotected = exposed && passwordFile === undefined;
|
|
11995
12059
|
if (unprotected && env.OMO_WEB_ALLOW_UNAUTHENTICATED !== "1") {
|
|
11996
|
-
throw new WebAccessConfigError("OMO_WEB_PASSWORD_FILE", cliTr("\
|
|
12060
|
+
throw new WebAccessConfigError("OMO_WEB_PASSWORD_FILE", cliTr("\u975E\u672C\u673A\u76D1\u542C\u6216\u4EE3\u7406\u5165\u53E3\u5FC5\u987B\u914D\u7F6E\u5BC6\u7801\u6587\u4EF6\uFF0C\u6216\u663E\u5F0F\u8BBE\u7F6E OMO_WEB_ALLOW_UNAUTHENTICATED=1\u3002", "Non-loopback listening or a proxy origin requires a password file or explicit OMO_WEB_ALLOW_UNAUTHENTICATED=1."));
|
|
11997
12061
|
}
|
|
11998
12062
|
let origin;
|
|
11999
12063
|
let tls;
|
|
@@ -12014,24 +12078,30 @@ async function loadWebAccess(env, port) {
|
|
|
12014
12078
|
origin = url.origin;
|
|
12015
12079
|
}
|
|
12016
12080
|
let digest;
|
|
12081
|
+
let weakPassword = false;
|
|
12017
12082
|
if (passwordFile !== undefined) {
|
|
12018
12083
|
const bytes = await fileBytes(passwordFile, "OMO_WEB_PASSWORD_FILE");
|
|
12019
|
-
const password =
|
|
12020
|
-
if (!password
|
|
12021
|
-
throw new WebAccessConfigError("OMO_WEB_PASSWORD_FILE", cliTr("\u5BC6\u7801\u5FC5\u987B\u662F
|
|
12084
|
+
const password = bytes.toString("latin1").replace(/(?:\r\n|\n|\r)$/, "");
|
|
12085
|
+
if (!passwordPattern.test(password)) {
|
|
12086
|
+
throw new WebAccessConfigError("OMO_WEB_PASSWORD_FILE", cliTr("\u5BC6\u7801\u5FC5\u987B\u662F 1\u2013128 \u4E2A\u53EF\u6253\u5370 ASCII \u5B57\u7B26\uFF0C\u53EA\u5141\u8BB8\u5355\u4E2A\u672B\u5C3E\u6362\u884C\u3002", "The password must be 1\u2013128 printable ASCII characters with at most one trailing line ending."));
|
|
12022
12087
|
}
|
|
12023
|
-
|
|
12088
|
+
weakPassword = password.length < recommendedPasswordLength;
|
|
12089
|
+
const credentials = Buffer.from(`omo:${password}`).toString("base64");
|
|
12024
12090
|
digest = createHash4("sha256").update(credentials).digest();
|
|
12025
12091
|
}
|
|
12026
|
-
const limiter =
|
|
12092
|
+
const limiter = exposed && digest ? authFailureLimiter() : undefined;
|
|
12027
12093
|
return {
|
|
12028
|
-
hostname: host
|
|
12094
|
+
hostname: host,
|
|
12029
12095
|
origin,
|
|
12030
12096
|
tls,
|
|
12031
12097
|
unprotected,
|
|
12098
|
+
weakPassword,
|
|
12099
|
+
proxyOrigin,
|
|
12032
12100
|
authorize(request, expected, token, address) {
|
|
12033
12101
|
const requestOrigin = request.headers.get("Origin");
|
|
12034
|
-
|
|
12102
|
+
const authority = request.headers.get("Host");
|
|
12103
|
+
const matches = (url) => authority === url.host && (requestOrigin === null || requestOrigin === url.origin);
|
|
12104
|
+
if (!matches(expected) && !(proxyOrigin && matches(proxyOrigin)) || ["cross-site", "same-site"].includes(request.headers.get("Sec-Fetch-Site") ?? "")) {
|
|
12035
12105
|
throw new WebError(403, "origin_refused", "\u53EA\u63A5\u53D7\u540C\u6E90\u8BF7\u6C42\u3002");
|
|
12036
12106
|
}
|
|
12037
12107
|
if (digest) {
|
|
@@ -12042,7 +12112,7 @@ async function loadWebAccess(env, port) {
|
|
|
12042
12112
|
if (retryAfter !== undefined) {
|
|
12043
12113
|
return new Response(null, { status: 429, headers: { ...headers, "Retry-After": String(retryAfter) } });
|
|
12044
12114
|
}
|
|
12045
|
-
if (!encoded || encoded.length <
|
|
12115
|
+
if (!encoded || encoded.length < 8 || encoded.length > 176 || !timingSafeEqual2(createHash4("sha256").update(encoded).digest(), digest)) {
|
|
12046
12116
|
if (source)
|
|
12047
12117
|
limiter?.record(source);
|
|
12048
12118
|
return new Response(null, { status: 401, headers: { ...headers, "WWW-Authenticate": 'Basic realm="OmO Web"' } });
|
|
@@ -12051,7 +12121,7 @@ async function loadWebAccess(env, port) {
|
|
|
12051
12121
|
if (request.method === "POST") {
|
|
12052
12122
|
const provided = request.headers.get("X-OmO-Token") ?? "";
|
|
12053
12123
|
const bytes = provided.length === token.length ? Buffer.from(provided) : undefined;
|
|
12054
|
-
if (requestOrigin
|
|
12124
|
+
if (requestOrigin === null || bytes?.length !== token.length || !timingSafeEqual2(bytes, token)) {
|
|
12055
12125
|
throw new WebError(403, "token_refused", "\u8BF7\u5237\u65B0\u9875\u9762\u540E\u91CD\u8BD5\u3002");
|
|
12056
12126
|
}
|
|
12057
12127
|
} else if (request.method !== "GET") {
|
|
@@ -12441,6 +12511,8 @@ data: ${JSON.stringify(event)}
|
|
|
12441
12511
|
return {
|
|
12442
12512
|
url: new URL(url),
|
|
12443
12513
|
unprotected: access.unprotected,
|
|
12514
|
+
weakPassword: access.weakPassword,
|
|
12515
|
+
proxyOrigin: access.proxyOrigin?.origin,
|
|
12444
12516
|
fetch,
|
|
12445
12517
|
stop() {
|
|
12446
12518
|
closing ??= (async () => {
|
|
@@ -12492,8 +12564,12 @@ var app = await startApp({
|
|
|
12492
12564
|
process.exit(1);
|
|
12493
12565
|
});
|
|
12494
12566
|
if (app.unprotected)
|
|
12495
|
-
console.warn(cliTr("\u8B66\u544A\uFF1A\
|
|
12567
|
+
console.warn(cliTr("\u8B66\u544A\uFF1A\u975E\u672C\u673A\u5165\u53E3\u672A\u8BBE\u5BC6\u7801\u3002\u80FD\u8BBF\u95EE\u6B64\u5730\u5740\u7684\u4EBA\u90FD\u80FD\u8BFB\u53D6\u4F1A\u8BDD\u5E76\u901A\u8FC7 OmO \u64CD\u4F5C\u672C\u673A\u3002\u4EC5\u5728\u53D7\u9650\u79C1\u7F51\u6216 VPN \u5185\u4F7F\u7528\u3002", "Warning: remote access without a password. Anyone who can reach this address can read sessions and run tools through OmO. Use only on a restricted private network or VPN."));
|
|
12568
|
+
if (app.weakPassword)
|
|
12569
|
+
console.warn(cliTr("OmO Web warning: \u5BC6\u7801\u8F83\u77ED\uFF0C\u5EFA\u8BAE\u4F7F\u7528\u81F3\u5C11 20 \u4E2A\u5B57\u7B26\u3002", "OmO Web warning: short password. Use at least 20 characters for better protection."));
|
|
12496
12570
|
console.log(`OmO Web: ${app.url.href}`);
|
|
12571
|
+
if (app.proxyOrigin)
|
|
12572
|
+
console.log(`${cliTr("\u4EE3\u7406\u5165\u53E3", "Proxy origin")}: ${app.proxyOrigin}`);
|
|
12497
12573
|
console.log(`${cliTr("\u5DE5\u4F5C\u76EE\u5F55", "Working directories")}: ${workspaces.join(", ")}`);
|
|
12498
12574
|
var halt = () => {
|
|
12499
12575
|
app.stop().catch((error) => {
|
package/package.json
CHANGED
|
@@ -24,13 +24,10 @@
|
|
|
24
24
|
"workbench"
|
|
25
25
|
],
|
|
26
26
|
"files": [
|
|
27
|
-
"bin
|
|
28
|
-
"bin/tui.js",
|
|
29
|
-
"bin/locale.js",
|
|
30
|
-
"bin/windows-password.js",
|
|
27
|
+
"bin/*.js",
|
|
31
28
|
"dist/app.js",
|
|
32
29
|
"dist/server.js",
|
|
33
30
|
"public"
|
|
34
31
|
],
|
|
35
|
-
"version": "0.1.
|
|
32
|
+
"version": "0.1.2"
|
|
36
33
|
}
|