engine7 7.1.144 → 7.1.145

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.
@@ -534,31 +534,31 @@ var init_mem7_replication = __esm({
534
534
  // src/continuity/runtime-replication.ts
535
535
  import { constants as constants4, lstatSync as lstatSync6, realpathSync as realpathSync3, mkdirSync as mkdirSync5, openSync as openSync6, closeSync as closeSync6, fstatSync as fstatSync4, readFileSync as readFileSync4, writeFileSync as writeFileSync3, fsyncSync as fsyncSync5 } from "node:fs";
536
536
  import { basename as basename2, dirname as dirname4, join as join5, resolve as resolve3 } from "node:path";
537
- function checkKey(component, key) {
538
- if (component === "topics-vectors" && typeof key === "string" && /^[a-f0-9]{64}$/.test(key)) return;
539
- if (component === "legacy-memory" && typeof key === "string" && /^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/.test(key) && !/[. ]$/.test(key) && !/^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(?:\.|$)/i.test(key)) return;
540
- if (["calendar", "proactive", "session-events"].includes(component) && key === void 0) return;
537
+ function checkKey(component, key2) {
538
+ if (component === "topics-vectors" && typeof key2 === "string" && /^[a-f0-9]{64}$/.test(key2)) return;
539
+ if (component === "legacy-memory" && typeof key2 === "string" && /^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/.test(key2) && !/[. ]$/.test(key2) && !/^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(?:\.|$)/i.test(key2)) return;
540
+ if (["calendar", "proactive", "session-events"].includes(component) && key2 === void 0) return;
541
541
  throw new Error("REPLICATION_REGISTRATION_INVALID");
542
542
  }
543
- function location2(stateDir, component, key) {
544
- checkKey(component, key);
545
- return join5(stateDir, ".continuity", component + (key === void 0 ? "" : "-" + key) + "-replication.json");
543
+ function location2(stateDir, component, key2) {
544
+ checkKey(component, key2);
545
+ return join5(stateDir, ".continuity", component + (key2 === void 0 ? "" : "-" + key2) + "-replication.json");
546
546
  }
547
- function runtimeReplicationFile(stateDir, component, key) {
548
- checkKey(component, key);
549
- if (component === "legacy-memory") return join5(stateDir, "agents", key, "memory", "memory.db");
550
- if (component === "topics-vectors") return join5(stateDir, "topics-history", key, "vectors.db");
547
+ function runtimeReplicationFile(stateDir, component, key2) {
548
+ checkKey(component, key2);
549
+ if (component === "legacy-memory") return join5(stateDir, "agents", key2, "memory", "memory.db");
550
+ if (component === "topics-vectors") return join5(stateDir, "topics-history", key2, "vectors.db");
551
551
  if (component === "session-events") return join5(stateDir, ".continuity", "session-events.db");
552
552
  return join5(stateDir, "." + component, component + ".db");
553
553
  }
554
554
  function runtimeReplicationLocation(stateDir, component, file) {
555
- const key = component === "legacy-memory" ? basename2(dirname4(dirname4(file))) : component === "topics-vectors" ? basename2(dirname4(file)) : void 0;
555
+ const key2 = component === "legacy-memory" ? basename2(dirname4(dirname4(file))) : component === "topics-vectors" ? basename2(dirname4(file)) : void 0;
556
556
  try {
557
- if (resolve3(file) !== resolve3(runtimeReplicationFile(stateDir, component, key))) throw new Error();
557
+ if (resolve3(file) !== resolve3(runtimeReplicationFile(stateDir, component, key2))) throw new Error();
558
558
  } catch (error) {
559
559
  throw new Error("REPLICATION_RUNTIME_PATH_UNSUPPORTED", { cause: error });
560
560
  }
561
- return { component, ...key === void 0 ? {} : { key } };
561
+ return { component, ...key2 === void 0 ? {} : { key: key2 } };
562
562
  }
563
563
  function normalize3(input) {
564
564
  if (!input || !/^[a-f0-9]{64}$/.test(input.schemaHash)) throw new Error("REPLICATION_REGISTRATION_INVALID");
@@ -569,8 +569,8 @@ function directory(path2) {
569
569
  if (!info.isDirectory() || info.isSymbolicLink() || realpathSync3(path2) !== resolve3(path2) || process.platform !== "win32" && (info.mode & 63 || info.uid !== process.getuid()))
570
570
  throw new Error("REPLICATION_REGISTRATION_INVALID");
571
571
  }
572
- function readRuntimeReplicationRegistration(stateDir, component, key) {
573
- const file = location2(stateDir, component, key);
572
+ function readRuntimeReplicationRegistration(stateDir, component, key2) {
573
+ const file = location2(stateDir, component, key2);
574
574
  try {
575
575
  lstatSync6(dirname4(file));
576
576
  } catch (error) {
@@ -834,10 +834,10 @@ var init_live = __esm({
834
834
  /** 安全取子段('services.voice-chat.start' → current.services.voice-chat.start) */
835
835
  get(dotPath) {
836
836
  if (!this.current) return void 0;
837
- return dotPath.split(".").reduce((acc, key) => {
837
+ return dotPath.split(".").reduce((acc, key2) => {
838
838
  if (acc == null) return void 0;
839
- if (key === "__proto__" || key === "constructor" || key === "prototype") return void 0;
840
- return acc[key];
839
+ if (key2 === "__proto__" || key2 === "constructor" || key2 === "prototype") return void 0;
840
+ return acc[key2];
841
841
  }, this.current);
842
842
  }
843
843
  /** reload 时原地更新(Object.assign 保持引用不变)
@@ -955,7 +955,7 @@ var init_scope = __esm({
955
955
  function canonicalJson(value) {
956
956
  const normalize4 = (input) => {
957
957
  if (Array.isArray(input)) return input.map(normalize4);
958
- if (input && typeof input === "object") return Object.fromEntries(Object.entries(input).filter(([, entry]) => entry !== void 0).sort(([a], [b]) => a.localeCompare(b)).map(([key, entry]) => [key, normalize4(entry)]));
958
+ if (input && typeof input === "object") return Object.fromEntries(Object.entries(input).filter(([, entry]) => entry !== void 0).sort(([a], [b]) => a.localeCompare(b)).map(([key2, entry]) => [key2, normalize4(entry)]));
959
959
  return input;
960
960
  };
961
961
  const json = JSON.stringify(normalize4(value));
@@ -1029,9 +1029,9 @@ function invalidateChildren(db, scope, pending, reason) {
1029
1029
  let referencedPlan;
1030
1030
  while (pending.length) {
1031
1031
  const child = pending.shift();
1032
- const key = JSON.stringify([child.child_kind, child.child_id]);
1033
- if (visited.has(key) && (visited.get(key) || !child.deleted)) continue;
1034
- visited.set(key, Boolean(child.deleted));
1032
+ const key2 = JSON.stringify([child.child_kind, child.child_id]);
1033
+ if (visited.has(key2) && (visited.get(key2) || !child.deleted)) continue;
1034
+ visited.set(key2, Boolean(child.deleted));
1035
1035
  if (child.child_kind === "graph_plan") {
1036
1036
  referencedPlan ??= db.prepare(`SELECT 1 WHERE EXISTS (SELECT 1 FROM memory_dependencies
1037
1037
  WHERE scope_id=? AND parent_kind='artifact' AND parent_id=?)
@@ -1192,8 +1192,8 @@ var init_change_feed = __esm({
1192
1192
  * 事件重放失败一次即回死信+skip,不重烧 5 轮预算)。先 UPDATE 后记账:中间崩溃只会
1193
1193
  * 多治一次(幂等无害),反过来会出现"记了账但没治"的永久死锁。 */
1194
1194
  reenqueueGapPrefix(sinkId, head, now2 = Date.now()) {
1195
- const key = `${sinkId}:${head.scopeId}:${head.eventSeq}`;
1196
- if (this.healedGaps.has(key)) return;
1195
+ const key2 = `${sinkId}:${head.scopeId}:${head.eventSeq}`;
1196
+ if (this.healedGaps.has(key2)) return;
1197
1197
  const ledgerPath = this.gapHealLedgerPath;
1198
1198
  let ledger = {};
1199
1199
  if (ledgerPath) {
@@ -1201,8 +1201,8 @@ var init_change_feed = __esm({
1201
1201
  ledger = JSON.parse(readFileSync6(ledgerPath, "utf8"))?.heals ?? {};
1202
1202
  } catch {
1203
1203
  }
1204
- if (Number.isFinite(ledger[key])) {
1205
- this.healedGaps.add(key);
1204
+ if (Number.isFinite(ledger[key2])) {
1205
+ this.healedGaps.add(key2);
1206
1206
  return;
1207
1207
  }
1208
1208
  }
@@ -1216,11 +1216,11 @@ var init_change_feed = __esm({
1216
1216
  const count = Number(result?.changes ?? 0);
1217
1217
  if (count > 0) console.warn(`[mem7] \u5E8F\u5217\u7F3A\u53E3\u81EA\u6108\uFF1Ahead seq=${head.eventSeq} \u524D ${count} \u6761\u5DF2 ack \u6295\u9012\u884C\u91CD\u7F6E\u5F85\u6295\uFF08\u65B0\u56FE\u5982\u5B9E\u91CD\u653E / \u65E7\u56FE\u5E42\u7B49 duplicate-ack\uFF1B\u6B7B\u4FE1\u884C\u4FDD\u7559 attempts\uFF09`);
1218
1218
  });
1219
- this.healedGaps.add(key);
1219
+ this.healedGaps.add(key2);
1220
1220
  if (!ledgerPath) return;
1221
1221
  const cutoff = now2 - _ChangeFeed.GAP_HEAL_RETENTION_MS, retained = {};
1222
1222
  for (const [entry, at] of Object.entries(ledger)) if (Number.isFinite(at) && at >= cutoff) retained[entry] = at;
1223
- retained[key] = now2;
1223
+ retained[key2] = now2;
1224
1224
  const temp = `${ledgerPath}.${randomUUID4()}.tmp`;
1225
1225
  try {
1226
1226
  writeFileSync5(temp, JSON.stringify({ version: 1, heals: retained }));
@@ -1880,6 +1880,19 @@ var init_timing = __esm({
1880
1880
  }
1881
1881
  });
1882
1882
 
1883
+ // src/mem7/core/lance-cache.ts
1884
+ var LANCE_INDEX_CACHE_BYTES, LANCE_METADATA_CACHE_BYTES, key, globals, sessions;
1885
+ var init_lance_cache = __esm({
1886
+ "src/mem7/core/lance-cache.ts"() {
1887
+ "use strict";
1888
+ LANCE_INDEX_CACHE_BYTES = 256 * 1024 * 1024;
1889
+ LANCE_METADATA_CACHE_BYTES = 64 * 1024 * 1024;
1890
+ key = Symbol.for("engine7.mem7.lanceCacheSessions");
1891
+ globals = globalThis;
1892
+ sessions = globals[key] ??= /* @__PURE__ */ new WeakMap();
1893
+ }
1894
+ });
1895
+
1883
1896
  // src/mem7/core/vector-store.ts
1884
1897
  import { DatabaseSync as DatabaseSync7 } from "node:sqlite";
1885
1898
  function lanceSpecifierFor(platform, arch) {
@@ -1897,6 +1910,7 @@ var init_vector_store = __esm({
1897
1910
  init_read_guard();
1898
1911
  init_timing();
1899
1912
  init_runtime_authority();
1913
+ init_lance_cache();
1900
1914
  isIntelMac = process.platform === "darwin" && process.arch === "x64";
1901
1915
  bootAt = Date.now();
1902
1916
  }