omo-web 0.1.1 → 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/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 localRuntimeCommands = new Set([
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 && localRuntimeCommands.has(head)) {
8606
- throw new WebError(400, "runtime_command_local", "\u8BE5\u547D\u4EE4\u7531 Web \u672C\u5730\u67E5\u770B\u5165\u53E3\u5904\u7406\uFF1B\u539F\u751F\u4FEE\u6539\u8BF7\u5728\u672C\u673A OmO \u7EC8\u7AEF\u64CD\u4F5C\u3002");
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,20 @@ 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
+
11816
11856
  // packaging/npm/listen-address.js
11817
11857
  import { networkInterfaces } from "os";
11818
11858
  var loopbackAddress = "127.0.0.1";
@@ -11912,7 +11952,6 @@ class WebAccessConfigError extends Error {
11912
11952
  this.setting = setting;
11913
11953
  }
11914
11954
  }
11915
- var passwordSchema = string2().regex(/^[\x20-\x7e]{20,128}$/);
11916
11955
  var MAX_AUTH_FAILURES = 5;
11917
11956
  var MAX_TRACKED_ADDRESSES = 1024;
11918
11957
  var AUTH_COOLDOWN_MS = 30000;
@@ -12006,13 +12045,19 @@ async function loadWebAccess(env, port) {
12006
12045
  const {
12007
12046
  OMO_WEB_PASSWORD_FILE: passwordFile,
12008
12047
  OMO_WEB_ORIGIN: originSetting,
12048
+ OMO_WEB_PROXY_ORIGIN: proxySetting,
12009
12049
  OMO_WEB_TLS_CERT: certFile,
12010
12050
  OMO_WEB_TLS_KEY: keyFile
12011
12051
  } = env;
12012
12052
  const publicBinding = isRemoteAddress(host);
12013
- const unprotected = publicBinding && passwordFile === undefined;
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;
12014
12059
  if (unprotected && env.OMO_WEB_ALLOW_UNAUTHENTICATED !== "1") {
12015
- throw new WebAccessConfigError("OMO_WEB_PASSWORD_FILE", cliTr("\u975E\u672C\u673A\u76D1\u542C\u5FC5\u987B\u914D\u7F6E\u5BC6\u7801\u6587\u4EF6\uFF0C\u6216\u663E\u5F0F\u8BBE\u7F6E OMO_WEB_ALLOW_UNAUTHENTICATED=1\u3002", "Non-loopback listening requires a password file or explicit OMO_WEB_ALLOW_UNAUTHENTICATED=1."));
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."));
12016
12061
  }
12017
12062
  let origin;
12018
12063
  let tls;
@@ -12033,24 +12078,30 @@ async function loadWebAccess(env, port) {
12033
12078
  origin = url.origin;
12034
12079
  }
12035
12080
  let digest;
12081
+ let weakPassword = false;
12036
12082
  if (passwordFile !== undefined) {
12037
12083
  const bytes = await fileBytes(passwordFile, "OMO_WEB_PASSWORD_FILE");
12038
- const password = passwordSchema.safeParse(bytes.toString("latin1").replace(/(?:\r\n|\n|\r)$/, ""));
12039
- if (!password.success) {
12040
- throw new WebAccessConfigError("OMO_WEB_PASSWORD_FILE", cliTr("\u5BC6\u7801\u5FC5\u987B\u662F 20\u2013128 \u4E2A\u53EF\u6253\u5370 ASCII \u5B57\u7B26\uFF0C\u53EA\u5141\u8BB8\u5355\u4E2A\u672B\u5C3E\u6362\u884C\u3002", "The password must be 20\u2013128 printable ASCII characters with at most one trailing line ending."));
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."));
12041
12087
  }
12042
- const credentials = Buffer.from(`omo:${password.data}`).toString("base64");
12088
+ weakPassword = password.length < recommendedPasswordLength;
12089
+ const credentials = Buffer.from(`omo:${password}`).toString("base64");
12043
12090
  digest = createHash4("sha256").update(credentials).digest();
12044
12091
  }
12045
- const limiter = publicBinding && digest ? authFailureLimiter() : undefined;
12092
+ const limiter = exposed && digest ? authFailureLimiter() : undefined;
12046
12093
  return {
12047
12094
  hostname: host,
12048
12095
  origin,
12049
12096
  tls,
12050
12097
  unprotected,
12098
+ weakPassword,
12099
+ proxyOrigin,
12051
12100
  authorize(request, expected, token, address) {
12052
12101
  const requestOrigin = request.headers.get("Origin");
12053
- if (request.headers.get("Host") !== expected.host || requestOrigin !== null && requestOrigin !== expected.origin || ["cross-site", "same-site"].includes(request.headers.get("Sec-Fetch-Site") ?? "")) {
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") ?? "")) {
12054
12105
  throw new WebError(403, "origin_refused", "\u53EA\u63A5\u53D7\u540C\u6E90\u8BF7\u6C42\u3002");
12055
12106
  }
12056
12107
  if (digest) {
@@ -12061,7 +12112,7 @@ async function loadWebAccess(env, port) {
12061
12112
  if (retryAfter !== undefined) {
12062
12113
  return new Response(null, { status: 429, headers: { ...headers, "Retry-After": String(retryAfter) } });
12063
12114
  }
12064
- if (!encoded || encoded.length < 30 || encoded.length > 178 || !timingSafeEqual2(createHash4("sha256").update(encoded).digest(), digest)) {
12115
+ if (!encoded || encoded.length < 8 || encoded.length > 176 || !timingSafeEqual2(createHash4("sha256").update(encoded).digest(), digest)) {
12065
12116
  if (source)
12066
12117
  limiter?.record(source);
12067
12118
  return new Response(null, { status: 401, headers: { ...headers, "WWW-Authenticate": 'Basic realm="OmO Web"' } });
@@ -12070,7 +12121,7 @@ async function loadWebAccess(env, port) {
12070
12121
  if (request.method === "POST") {
12071
12122
  const provided = request.headers.get("X-OmO-Token") ?? "";
12072
12123
  const bytes = provided.length === token.length ? Buffer.from(provided) : undefined;
12073
- if (requestOrigin !== expected.origin || bytes?.length !== token.length || !timingSafeEqual2(bytes, token)) {
12124
+ if (requestOrigin === null || bytes?.length !== token.length || !timingSafeEqual2(bytes, token)) {
12074
12125
  throw new WebError(403, "token_refused", "\u8BF7\u5237\u65B0\u9875\u9762\u540E\u91CD\u8BD5\u3002");
12075
12126
  }
12076
12127
  } else if (request.method !== "GET") {
@@ -12460,6 +12511,8 @@ data: ${JSON.stringify(event)}
12460
12511
  return {
12461
12512
  url: new URL(url),
12462
12513
  unprotected: access.unprotected,
12514
+ weakPassword: access.weakPassword,
12515
+ proxyOrigin: access.proxyOrigin?.origin,
12463
12516
  fetch,
12464
12517
  stop() {
12465
12518
  closing ??= (async () => {
@@ -12511,8 +12564,12 @@ var app = await startApp({
12511
12564
  process.exit(1);
12512
12565
  });
12513
12566
  if (app.unprotected)
12514
- console.warn(cliTr("\u8B66\u544A\uFF1A\u975E\u672C\u673A\u76D1\u542C\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: non-loopback listening 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."));
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."));
12515
12570
  console.log(`OmO Web: ${app.url.href}`);
12571
+ if (app.proxyOrigin)
12572
+ console.log(`${cliTr("\u4EE3\u7406\u5165\u53E3", "Proxy origin")}: ${app.proxyOrigin}`);
12516
12573
  console.log(`${cliTr("\u5DE5\u4F5C\u76EE\u5F55", "Working directories")}: ${workspaces.join(", ")}`);
12517
12574
  var halt = () => {
12518
12575
  app.stop().catch((error) => {
package/package.json CHANGED
@@ -29,5 +29,5 @@
29
29
  "dist/server.js",
30
30
  "public"
31
31
  ],
32
- "version": "0.1.1"
32
+ "version": "0.1.2"
33
33
  }