@xdarkicex/openclaw-memory-libravdb 1.4.61 → 1.4.63

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.
@@ -312,8 +312,9 @@ function isQuestionShapedRecallCandidate(text) {
312
312
  /^\s*(?:who|what|when|where|why|how)\b/i.test(normalized));
313
313
  }
314
314
  function rankExactRecallCandidate(result, token) {
315
- if (!result.text.includes(token))
315
+ if (typeof result.text !== "string" || !result.text.includes(token)) {
316
316
  return Number.NEGATIVE_INFINITY;
317
+ }
317
318
  let rank = result.score;
318
319
  if (/\bmeans\b/i.test(result.text))
319
320
  rank += 100;
@@ -476,7 +477,7 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
476
477
  excludeByCollection: {},
477
478
  });
478
479
  const hit = (result.results ?? [])
479
- .filter((candidate) => isExactRecallFact(candidate.text, token))
480
+ .filter((candidate) => typeof candidate?.text === "string" && isExactRecallFact(candidate.text, token))
480
481
  .sort((a, b) => rankExactRecallCandidate(b, token) - rankExactRecallCandidate(a, token))[0];
481
482
  if (hit) {
482
483
  injectedFacts.push(buildExactRecallFact(hit, token));
@@ -321,22 +321,26 @@ function parseTrailingMetadata(body) {
321
321
  uniqueQueries,
322
322
  };
323
323
  }
324
+ const DECIMAL_NUMBER_PATTERN = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
325
+ const INTEGER_PATTERN = /^[+-]?\d+$/;
324
326
  function parseNumber(value) {
325
- if (!value) {
327
+ const trimmed = value?.trim();
328
+ if (!trimmed || !DECIMAL_NUMBER_PATTERN.test(trimmed)) {
326
329
  return null;
327
330
  }
328
- const parsed = Number.parseFloat(value);
331
+ const parsed = Number(trimmed);
329
332
  if (!Number.isFinite(parsed)) {
330
333
  return null;
331
334
  }
332
335
  return parsed;
333
336
  }
334
337
  function parseInteger(value) {
335
- if (!value) {
338
+ const trimmed = value?.trim();
339
+ if (!trimmed || !INTEGER_PATTERN.test(trimmed)) {
336
340
  return null;
337
341
  }
338
- const parsed = Number.parseInt(value, 10);
339
- if (!Number.isFinite(parsed)) {
342
+ const parsed = Number(trimmed);
343
+ if (!Number.isSafeInteger(parsed)) {
340
344
  return null;
341
345
  }
342
346
  return parsed;
package/dist/index.js CHANGED
@@ -32164,14 +32164,25 @@ function registerMemoryCliMetadata(api) {
32164
32164
  // src/memory-scopes.ts
32165
32165
  var SESSION_KEY_NAMESPACE_PREFIX = "session-key:";
32166
32166
  var AGENT_ID_NAMESPACE_PREFIX = "agent-id:";
32167
+ var COLLECTION_NAME_RE = /^[a-zA-Z][a-zA-Z0-9_.:@#-]{0,127}$/;
32168
+ function validateNamespace(name) {
32169
+ if (!COLLECTION_NAME_RE.test(name)) {
32170
+ throw new Error(
32171
+ `Invalid collection namespace: "${name}". Must match ${COLLECTION_NAME_RE.source}`
32172
+ );
32173
+ }
32174
+ return name;
32175
+ }
32167
32176
  function resolveDurableNamespace(params) {
32168
32177
  const explicitUserId = firstNonEmpty(params.userId);
32169
- if (explicitUserId) return explicitUserId;
32178
+ if (explicitUserId) return validateNamespace(explicitUserId);
32170
32179
  const sessionKey = firstNonEmpty(params.sessionKey);
32171
- if (sessionKey) return `${SESSION_KEY_NAMESPACE_PREFIX}${sessionKey}`;
32180
+ if (sessionKey) return validateNamespace(`${SESSION_KEY_NAMESPACE_PREFIX}${sessionKey}`);
32172
32181
  const agentId = firstNonEmpty(params.agentId);
32173
- if (agentId) return `${AGENT_ID_NAMESPACE_PREFIX}${agentId}`;
32174
- return firstNonEmpty(params.fallback) ?? "default";
32182
+ if (agentId) return validateNamespace(`${AGENT_ID_NAMESPACE_PREFIX}${agentId}`);
32183
+ const fallback = firstNonEmpty(params.fallback);
32184
+ if (fallback) return validateNamespace(fallback);
32185
+ return "default";
32175
32186
  }
32176
32187
  function firstNonEmpty(value) {
32177
32188
  if (typeof value !== "string") return void 0;
@@ -32819,22 +32830,26 @@ function parseTrailingMetadata(body) {
32819
32830
  uniqueQueries
32820
32831
  };
32821
32832
  }
32833
+ var DECIMAL_NUMBER_PATTERN = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
32834
+ var INTEGER_PATTERN = /^[+-]?\d+$/;
32822
32835
  function parseNumber(value) {
32823
- if (!value) {
32836
+ const trimmed = value?.trim();
32837
+ if (!trimmed || !DECIMAL_NUMBER_PATTERN.test(trimmed)) {
32824
32838
  return null;
32825
32839
  }
32826
- const parsed = Number.parseFloat(value);
32840
+ const parsed = Number(trimmed);
32827
32841
  if (!Number.isFinite(parsed)) {
32828
32842
  return null;
32829
32843
  }
32830
32844
  return parsed;
32831
32845
  }
32832
32846
  function parseInteger(value) {
32833
- if (!value) {
32847
+ const trimmed = value?.trim();
32848
+ if (!trimmed || !INTEGER_PATTERN.test(trimmed)) {
32834
32849
  return null;
32835
32850
  }
32836
- const parsed = Number.parseInt(value, 10);
32837
- if (!Number.isFinite(parsed)) {
32851
+ const parsed = Number(trimmed);
32852
+ if (!Number.isSafeInteger(parsed)) {
32838
32853
  return null;
32839
32854
  }
32840
32855
  return parsed;
@@ -33076,7 +33091,16 @@ function resolveSessionSearchCollection(cfg, sessionId) {
33076
33091
  return `session:${sessionId}`;
33077
33092
  }
33078
33093
  function firstString(...values) {
33079
- return values.find((value) => typeof value === "string" && value.length > 0);
33094
+ for (const value of values) {
33095
+ if (typeof value !== "string") {
33096
+ continue;
33097
+ }
33098
+ const trimmed = value.trim();
33099
+ if (trimmed.length > 0) {
33100
+ return trimmed;
33101
+ }
33102
+ }
33103
+ return void 0;
33080
33104
  }
33081
33105
  function toMemorySearchResult(item) {
33082
33106
  const collection = typeof item.metadata.collection === "string" ? item.metadata.collection : "memory";
@@ -33929,7 +33953,9 @@ function isQuestionShapedRecallCandidate(text) {
33929
33953
  return normalized.includes("?") || /\bwhat\s+does\b/i.test(normalized) || /^\s*(?:who|what|when|where|why|how)\b/i.test(normalized);
33930
33954
  }
33931
33955
  function rankExactRecallCandidate(result, token) {
33932
- if (!result.text.includes(token)) return Number.NEGATIVE_INFINITY;
33956
+ if (typeof result.text !== "string" || !result.text.includes(token)) {
33957
+ return Number.NEGATIVE_INFINITY;
33958
+ }
33933
33959
  let rank = result.score;
33934
33960
  if (/\bmeans\b/i.test(result.text)) rank += 100;
33935
33961
  if (/\b(remember|durable|fact)\b/i.test(result.text)) rank += 10;
@@ -34076,7 +34102,7 @@ function buildContextEngineFactory(runtime, cfg, logger = console) {
34076
34102
  k: Math.max(EXACT_RECALL_SEARCH_K, cfg.topK ?? 0),
34077
34103
  excludeByCollection: {}
34078
34104
  });
34079
- const hit = (result.results ?? []).filter((candidate) => isExactRecallFact(candidate.text, token)).sort((a, b) => rankExactRecallCandidate(b, token) - rankExactRecallCandidate(a, token))[0];
34105
+ const hit = (result.results ?? []).filter((candidate) => typeof candidate?.text === "string" && isExactRecallFact(candidate.text, token)).sort((a, b) => rankExactRecallCandidate(b, token) - rankExactRecallCandidate(a, token))[0];
34080
34106
  if (hit) {
34081
34107
  injectedFacts.push(buildExactRecallFact(hit, token));
34082
34108
  }
@@ -39650,19 +39676,20 @@ function resolveConfiguredEndpoint(cfg) {
39650
39676
  if (!value || value === "auto") {
39651
39677
  return defaultEndpoint();
39652
39678
  }
39653
- if (!isConfiguredEndpoint(value)) {
39679
+ const endpoint = normalizeConfiguredEndpoint(value);
39680
+ if (!endpoint) {
39654
39681
  throw new Error(
39655
39682
  `LibraVDB sidecarPath must be a daemon endpoint like unix:/path/to/libravdb.sock or tcp:127.0.0.1:37421. Executable paths are no longer supported.`
39656
39683
  );
39657
39684
  }
39658
- return value;
39685
+ return endpoint;
39659
39686
  }
39660
39687
  function daemonProvisioningHint() {
39661
39688
  return "If you installed the npm package, install and start libravdbd separately; the package does not provision the daemon binary, ONNX Runtime, or model assets.";
39662
39689
  }
39663
39690
  function defaultEndpoint(platform = process.platform, homeDir = os2.homedir(), pathExists = fs3.existsSync) {
39664
- const envEndpoint = process.env.LIBRAVDB_RPC_ENDPOINT?.trim();
39665
- if (envEndpoint && isConfiguredEndpoint(envEndpoint)) {
39691
+ const envEndpoint = normalizeConfiguredEndpoint(process.env.LIBRAVDB_RPC_ENDPOINT);
39692
+ if (envEndpoint) {
39666
39693
  return envEndpoint;
39667
39694
  }
39668
39695
  if (platform === "win32") {
@@ -39755,6 +39782,17 @@ function isConfiguredEndpoint(value) {
39755
39782
  const port = Number(address.slice(separator + 1));
39756
39783
  return host.length > 0 && Number.isInteger(port) && port > 0 && port <= 65535;
39757
39784
  }
39785
+ function normalizeConfiguredEndpoint(value) {
39786
+ const trimmed = value?.trim();
39787
+ if (!trimmed || trimmed === "auto") {
39788
+ return null;
39789
+ }
39790
+ if (trimmed.startsWith("unix:")) {
39791
+ const socketPath = trimmed.slice("unix:".length).trim();
39792
+ return socketPath ? `unix:${socketPath}` : null;
39793
+ }
39794
+ return isConfiguredEndpoint(trimmed) ? trimmed : null;
39795
+ }
39758
39796
  function sleep2(delayMs) {
39759
39797
  return new Promise((resolve) => setTimeout(resolve, delayMs));
39760
39798
  }
@@ -161,7 +161,16 @@ function resolveSessionSearchCollection(cfg, sessionId) {
161
161
  return `session:${sessionId}`;
162
162
  }
163
163
  function firstString(...values) {
164
- return values.find((value) => typeof value === "string" && value.length > 0);
164
+ for (const value of values) {
165
+ if (typeof value !== "string") {
166
+ continue;
167
+ }
168
+ const trimmed = value.trim();
169
+ if (trimmed.length > 0) {
170
+ return trimmed;
171
+ }
172
+ }
173
+ return undefined;
165
174
  }
166
175
  function toMemorySearchResult(item) {
167
176
  const collection = typeof item.metadata.collection === "string" ? item.metadata.collection : "memory";
@@ -1,3 +1,6 @@
1
+ /** Validate and return a collection-safe namespace.
2
+ * Throws on invalid characters or length. */
3
+ export declare function validateNamespace(name: string): string;
1
4
  export type RetrievalScopes = {
2
5
  /** Always queried — fresh context bound to this session. */
3
6
  session: string;
@@ -1,16 +1,30 @@
1
1
  const SESSION_KEY_NAMESPACE_PREFIX = "session-key:";
2
2
  const AGENT_ID_NAMESPACE_PREFIX = "agent-id:";
3
+ /** Valid collection names: alphanumeric, underscores, hyphens, dots, colons, at-signs, hashes.
4
+ * Must start with a letter. Max 128 characters. */
5
+ const COLLECTION_NAME_RE = /^[a-zA-Z][a-zA-Z0-9_.:@#-]{0,127}$/;
6
+ /** Validate and return a collection-safe namespace.
7
+ * Throws on invalid characters or length. */
8
+ export function validateNamespace(name) {
9
+ if (!COLLECTION_NAME_RE.test(name)) {
10
+ throw new Error(`Invalid collection namespace: "${name}". Must match ${COLLECTION_NAME_RE.source}`);
11
+ }
12
+ return name;
13
+ }
3
14
  export function resolveDurableNamespace(params) {
4
15
  const explicitUserId = firstNonEmpty(params.userId);
5
16
  if (explicitUserId)
6
- return explicitUserId;
17
+ return validateNamespace(explicitUserId);
7
18
  const sessionKey = firstNonEmpty(params.sessionKey);
8
19
  if (sessionKey)
9
- return `${SESSION_KEY_NAMESPACE_PREFIX}${sessionKey}`;
20
+ return validateNamespace(`${SESSION_KEY_NAMESPACE_PREFIX}${sessionKey}`);
10
21
  const agentId = firstNonEmpty(params.agentId);
11
22
  if (agentId)
12
- return `${AGENT_ID_NAMESPACE_PREFIX}${agentId}`;
13
- return firstNonEmpty(params.fallback) ?? "default";
23
+ return validateNamespace(`${AGENT_ID_NAMESPACE_PREFIX}${agentId}`);
24
+ const fallback = firstNonEmpty(params.fallback);
25
+ if (fallback)
26
+ return validateNamespace(fallback);
27
+ return "default";
14
28
  }
15
29
  export function resolveScopes(params) {
16
30
  return {
package/dist/sidecar.js CHANGED
@@ -351,18 +351,19 @@ export function resolveConfiguredEndpoint(cfg) {
351
351
  if (!value || value === "auto") {
352
352
  return defaultEndpoint();
353
353
  }
354
- if (!isConfiguredEndpoint(value)) {
354
+ const endpoint = normalizeConfiguredEndpoint(value);
355
+ if (!endpoint) {
355
356
  throw new Error(`LibraVDB sidecarPath must be a daemon endpoint like unix:/path/to/libravdb.sock or tcp:127.0.0.1:37421. Executable paths are no longer supported.`);
356
357
  }
357
- return value;
358
+ return endpoint;
358
359
  }
359
360
  export function daemonProvisioningHint() {
360
361
  return "If you installed the npm package, install and start libravdbd separately; the package does not provision the daemon binary, ONNX Runtime, or model assets.";
361
362
  }
362
363
  export function defaultEndpoint(platform = process.platform, homeDir = os.homedir(), pathExists = fs.existsSync) {
363
364
  // Honour the daemon's own env var first (set by Homebrew LaunchAgent / systemd unit).
364
- const envEndpoint = process.env.LIBRAVDB_RPC_ENDPOINT?.trim();
365
- if (envEndpoint && isConfiguredEndpoint(envEndpoint)) {
365
+ const envEndpoint = normalizeConfiguredEndpoint(process.env.LIBRAVDB_RPC_ENDPOINT);
366
+ if (envEndpoint) {
366
367
  return envEndpoint;
367
368
  }
368
369
  if (platform === "win32") {
@@ -525,6 +526,17 @@ function isConfiguredEndpoint(value) {
525
526
  const port = Number(address.slice(separator + 1));
526
527
  return host.length > 0 && Number.isInteger(port) && port > 0 && port <= 65535;
527
528
  }
529
+ function normalizeConfiguredEndpoint(value) {
530
+ const trimmed = value?.trim();
531
+ if (!trimmed || trimmed === "auto") {
532
+ return null;
533
+ }
534
+ if (trimmed.startsWith("unix:")) {
535
+ const socketPath = trimmed.slice("unix:".length).trim();
536
+ return socketPath ? `unix:${socketPath}` : null;
537
+ }
538
+ return isConfiguredEndpoint(trimmed) ? trimmed : null;
539
+ }
528
540
  export { PlaceholderSocket };
529
541
  function sleep(delayMs) {
530
542
  return new Promise((resolve) => setTimeout(resolve, delayMs));
@@ -2,7 +2,7 @@
2
2
  "id": "libravdb-memory",
3
3
  "name": "LibraVDB Memory",
4
4
  "description": "Persistent vector memory with three-tier hybrid scoring",
5
- "version": "1.4.61",
5
+ "version": "1.4.63",
6
6
  "kind": [
7
7
  "memory",
8
8
  "context-engine"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xdarkicex/openclaw-memory-libravdb",
3
- "version": "1.4.61",
3
+ "version": "1.4.63",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",