@cosmicstack/mercury-agent 1.2.3 → 1.2.4

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 CHANGED
@@ -21,7 +21,7 @@
21
21
  </p>
22
22
 
23
23
  <p align="center">
24
- <strong>🔖 Current Stable: v1.1.13</strong>
24
+ <strong>🔖 Current Stable: v1.2.3</strong>
25
25
  </p>
26
26
 
27
27
  <p align="center">
package/README.zh-CN.md CHANGED
@@ -23,7 +23,7 @@
23
23
  </p>
24
24
 
25
25
  <p align="center">
26
- <strong>🔖 当前稳定版:v1.1.6</strong>
26
+ <strong>🔖 当前稳定版:v1.2.3</strong>
27
27
  </p>
28
28
 
29
29
  <p align="center">
package/dist/index.js CHANGED
@@ -32374,6 +32374,15 @@ init_config();
32374
32374
  init_logger();
32375
32375
  import { existsSync as existsSync21, readFileSync as readFileSync16, writeFileSync as writeFileSync15 } from "fs";
32376
32376
  import { join as join19 } from "path";
32377
+
32378
+ // src/utils/format.ts
32379
+ function formatNumber(value) {
32380
+ const n = Number(value);
32381
+ if (!Number.isFinite(n)) return "0";
32382
+ return n.toLocaleString("en-US", { useGrouping: true });
32383
+ }
32384
+
32385
+ // src/utils/tokens.ts
32377
32386
  var TOKEN_FILE = "token-usage.json";
32378
32387
  function safeNumber(value) {
32379
32388
  if (value === null || value === void 0) return 0;
@@ -32499,7 +32508,7 @@ var TokenBudget = class {
32499
32508
  const used = this.sanitizeCount(this.dailyUsed);
32500
32509
  const pct = Math.round(this.getUsagePercentage());
32501
32510
  const remaining = this.getRemaining();
32502
- return `Token budget: ${used.toLocaleString()} / ${this.dailyBudget.toLocaleString()} used (${pct}%), ${remaining.toLocaleString()} remaining`;
32511
+ return `Token budget: ${formatNumber(used)} / ${formatNumber(this.dailyBudget)} used (${pct}%), ${formatNumber(remaining)} remaining`;
32503
32512
  }
32504
32513
  /**
32505
32514
  * Record an estimated savings from Token Saver Mode. Updates both the
@@ -35870,6 +35879,18 @@ function getWebPort() {
35870
35879
  }
35871
35880
  return 6174;
35872
35881
  }
35882
+ var ATTACH_TOKEN_FILE = "attach-token";
35883
+ function getAttachTokenPath() {
35884
+ return join26(getMercuryHome(), ATTACH_TOKEN_FILE);
35885
+ }
35886
+ function readAttachToken() {
35887
+ try {
35888
+ const token = readFileSync24(getAttachTokenPath(), "utf-8").trim();
35889
+ return token.length > 0 ? token : null;
35890
+ } catch {
35891
+ return null;
35892
+ }
35893
+ }
35873
35894
  function loadWebAuth() {
35874
35895
  const path9 = getWebConfigPath();
35875
35896
  if (!existsSync35(path9)) return null;
@@ -36009,6 +36030,14 @@ function getSessionMaxAge() {
36009
36030
 
36010
36031
  // src/web/middleware.ts
36011
36032
  var PUBLIC_PATHS = /* @__PURE__ */ new Set(["/login", "/api/auth/login", "/api/auth/logout"]);
36033
+ function isLoopbackRequest(c) {
36034
+ try {
36035
+ const address = c.env?.incoming?.socket?.remoteAddress || "";
36036
+ return ["127.0.0.1", "::1", "::ffff:127.0.0.1"].includes(address);
36037
+ } catch {
36038
+ return false;
36039
+ }
36040
+ }
36012
36041
  async function authGuard(c, next) {
36013
36042
  const path9 = new URL(c.req.url).pathname;
36014
36043
  if (path9.startsWith("/vendor/") || path9.startsWith("/static/") || path9.startsWith("/assets/") || path9.startsWith("/icons/") || path9.endsWith(".css") || path9.endsWith(".js") || path9.endsWith(".png") || path9.endsWith(".ico") || path9.endsWith(".svg") || path9.endsWith(".woff2") || path9.endsWith(".webmanifest")) {
@@ -36019,10 +36048,13 @@ async function authGuard(c, next) {
36019
36048
  }
36020
36049
  if (path9.startsWith("/api/")) {
36021
36050
  const token2 = getCookie(c, getSessionCookieName()) || c.req.header("Authorization")?.replace("Bearer ", "");
36022
- if (!token2 || !validateSession(token2)) {
36023
- return c.json({ error: "Unauthorized" }, 401);
36051
+ if (token2 && validateSession(token2)) {
36052
+ return next();
36024
36053
  }
36025
- return next();
36054
+ if (token2 && isLoopbackRequest(c) && token2 === readAttachToken()) {
36055
+ return next();
36056
+ }
36057
+ return c.json({ error: "Unauthorized" }, 401);
36026
36058
  }
36027
36059
  const token = getCookie(c, getSessionCookieName());
36028
36060
  if (!token || !validateSession(token)) {
@@ -37922,7 +37954,7 @@ var pkgVersion;
37922
37954
  try {
37923
37955
  pkgVersion = JSON.parse(readFileSync31(join33(__dirname2, "..", "package.json"), "utf8")).version;
37924
37956
  } catch {
37925
- pkgVersion = "1.2.3";
37957
+ pkgVersion = "1.2.4";
37926
37958
  }
37927
37959
  function hr() {
37928
37960
  console.log(chalk10.dim("\u2500".repeat(50)));