@xdarkicex/openclaw-memory-libravdb 1.4.39 → 1.4.40

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.
@@ -8,8 +8,9 @@ type KernelCompatibleMessage = {
8
8
  };
9
9
  type OpenClawCompatibleMessage = {
10
10
  role: string;
11
- content: string;
11
+ content: string | unknown[];
12
12
  id?: string;
13
+ [key: string]: unknown;
13
14
  };
14
15
  type OpenClawCompatibleAssembleResult = {
15
16
  messages: OpenClawCompatibleMessage[];
@@ -76,11 +77,7 @@ export declare function buildContextEngineFactory(runtime: PluginRuntime, cfg: P
76
77
  sessionId: string;
77
78
  sessionKey?: string;
78
79
  userId?: string;
79
- messages: Array<{
80
- role: string;
81
- content: unknown;
82
- id?: string;
83
- }>;
80
+ messages: OpenClawCompatibleMessage[];
84
81
  tokenBudget: number;
85
82
  prompt?: string;
86
83
  currentTokenCount?: number;
@@ -96,11 +93,7 @@ export declare function buildContextEngineFactory(runtime: PluginRuntime, cfg: P
96
93
  sessionId: string;
97
94
  sessionKey?: string;
98
95
  userId?: string;
99
- messages: Array<{
100
- role: string;
101
- content: unknown;
102
- id?: string;
103
- }>;
96
+ messages: OpenClawCompatibleMessage[];
104
97
  prePromptMessageCount?: number;
105
98
  isHeartbeat?: boolean;
106
99
  tokenBudget?: number;
@@ -85,9 +85,13 @@ function normalizeKernelContent(content) {
85
85
  return content.map(stringifyKernelBlock).filter((part) => part.length > 0).join("\n");
86
86
  }
87
87
  function approximateTokenCount(text) {
88
- if (!text)
88
+ if (typeof text === "string") {
89
+ return Math.ceil(text.length / APPROX_CHARS_PER_TOKEN);
90
+ }
91
+ if (!Array.isArray(text)) {
89
92
  return 0;
90
- return Math.ceil(text.length / APPROX_CHARS_PER_TOKEN);
93
+ }
94
+ return Math.ceil(normalizeKernelContent(text).length / APPROX_CHARS_PER_TOKEN);
91
95
  }
92
96
  function approximateMessageTokens(message) {
93
97
  // Approximate per-message wrapper overhead so trimming is conservative.
@@ -162,10 +166,11 @@ function truncateContentToTokenBudget(content, tokenBudget) {
162
166
  if (tokenBudget <= 0)
163
167
  return "";
164
168
  const maxChars = Math.max(1, tokenBudget * APPROX_CHARS_PER_TOKEN);
165
- if (content.length <= maxChars)
166
- return content;
169
+ const normalized = normalizeKernelContent(content);
170
+ if (normalized.length <= maxChars)
171
+ return normalized;
167
172
  // Keep the tail so recent tool output / latest answer content is preserved.
168
- return content.slice(content.length - maxChars);
173
+ return normalized.slice(normalized.length - maxChars);
169
174
  }
170
175
  function trimMessagesToBudget(messages, tokenBudget) {
171
176
  if (tokenBudget <= 0 || messages.length === 0) {
@@ -399,7 +404,7 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
399
404
  return assembled;
400
405
  const existingBlocks = [
401
406
  assembled.systemPromptAddition,
402
- ...assembled.messages.map((message) => message.content),
407
+ ...assembled.messages.map((message) => normalizeKernelContent(message.content)),
403
408
  ]
404
409
  .flatMap((block) => block.split(/\n+/))
405
410
  .map((block) => block.trim())
@@ -657,7 +662,7 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
657
662
  if (!compactionResult.ok) {
658
663
  logger.warn?.(`LibraVDB predictive compaction blocked assemble path at ${currentContextTokens} tokens ` +
659
664
  `(threshold=${dynamicCompactThreshold}): ${compactionResult.reason ?? "compaction failed"}`);
660
- return buildBudgetFallbackContext(messages, args.tokenBudget);
665
+ return buildBudgetFallbackContext(args.messages, args.tokenBudget);
661
666
  }
662
667
  }
663
668
  const kernel = await getKernelOrNull("assemble");
@@ -682,7 +687,7 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
682
687
  }
683
688
  catch (error) {
684
689
  logger.warn?.(`LibraVDB assemble kernel failed, using budget-clamped fallback context: ${error instanceof Error ? error.message : String(error)}`);
685
- return buildBudgetFallbackContext(messages, args.tokenBudget);
690
+ return buildBudgetFallbackContext(args.messages, args.tokenBudget);
686
691
  }
687
692
  }
688
693
  const rpc = await runtime.getRpc();
@@ -707,7 +712,7 @@ export function buildContextEngineFactory(runtime, cfg, logger = console) {
707
712
  }
708
713
  catch (error) {
709
714
  logger.warn?.(`LibraVDB assemble sidecar failed, using budget-clamped fallback context: ${error instanceof Error ? error.message : String(error)}`);
710
- return buildBudgetFallbackContext(messages, args.tokenBudget);
715
+ return buildBudgetFallbackContext(args.messages, args.tokenBudget);
711
716
  }
712
717
  },
713
718
  async compact(args) {
package/dist/index.js CHANGED
@@ -33664,8 +33664,13 @@ function normalizeKernelContent(content) {
33664
33664
  return content.map(stringifyKernelBlock).filter((part) => part.length > 0).join("\n");
33665
33665
  }
33666
33666
  function approximateTokenCount(text) {
33667
- if (!text) return 0;
33668
- return Math.ceil(text.length / APPROX_CHARS_PER_TOKEN);
33667
+ if (typeof text === "string") {
33668
+ return Math.ceil(text.length / APPROX_CHARS_PER_TOKEN);
33669
+ }
33670
+ if (!Array.isArray(text)) {
33671
+ return 0;
33672
+ }
33673
+ return Math.ceil(normalizeKernelContent(text).length / APPROX_CHARS_PER_TOKEN);
33669
33674
  }
33670
33675
  function approximateMessageTokens(message) {
33671
33676
  return approximateTokenCount(message.content) + 8;
@@ -33731,8 +33736,9 @@ function logPredictiveCompactionOutcome(params) {
33731
33736
  function truncateContentToTokenBudget(content, tokenBudget) {
33732
33737
  if (tokenBudget <= 0) return "";
33733
33738
  const maxChars = Math.max(1, tokenBudget * APPROX_CHARS_PER_TOKEN);
33734
- if (content.length <= maxChars) return content;
33735
- return content.slice(content.length - maxChars);
33739
+ const normalized = normalizeKernelContent(content);
33740
+ if (normalized.length <= maxChars) return normalized;
33741
+ return normalized.slice(normalized.length - maxChars);
33736
33742
  }
33737
33743
  function trimMessagesToBudget(messages, tokenBudget) {
33738
33744
  if (tokenBudget <= 0 || messages.length === 0) {
@@ -33952,7 +33958,7 @@ function buildContextEngineFactory(runtime, cfg, logger = console) {
33952
33958
  if (tokens.length === 0) return assembled;
33953
33959
  const existingBlocks = [
33954
33960
  assembled.systemPromptAddition,
33955
- ...assembled.messages.map((message) => message.content)
33961
+ ...assembled.messages.map((message) => normalizeKernelContent(message.content))
33956
33962
  ].flatMap((block) => block.split(/\n+/)).map((block) => block.trim()).filter((block) => block.length > 0);
33957
33963
  const missingTokens = tokens.filter(
33958
33964
  (token) => !existingBlocks.some((block) => isExactRecallFact(block, token))
@@ -34194,7 +34200,7 @@ function buildContextEngineFactory(runtime, cfg, logger = console) {
34194
34200
  logger.warn?.(
34195
34201
  `LibraVDB predictive compaction blocked assemble path at ${currentContextTokens} tokens (threshold=${dynamicCompactThreshold}): ${compactionResult.reason ?? "compaction failed"}`
34196
34202
  );
34197
- return buildBudgetFallbackContext(messages, args.tokenBudget);
34203
+ return buildBudgetFallbackContext(args.messages, args.tokenBudget);
34198
34204
  }
34199
34205
  }
34200
34206
  const kernel = await getKernelOrNull("assemble");
@@ -34223,7 +34229,7 @@ function buildContextEngineFactory(runtime, cfg, logger = console) {
34223
34229
  logger.warn?.(
34224
34230
  `LibraVDB assemble kernel failed, using budget-clamped fallback context: ${error instanceof Error ? error.message : String(error)}`
34225
34231
  );
34226
- return buildBudgetFallbackContext(messages, args.tokenBudget);
34232
+ return buildBudgetFallbackContext(args.messages, args.tokenBudget);
34227
34233
  }
34228
34234
  }
34229
34235
  const rpc = await runtime.getRpc();
@@ -34252,7 +34258,7 @@ function buildContextEngineFactory(runtime, cfg, logger = console) {
34252
34258
  logger.warn?.(
34253
34259
  `LibraVDB assemble sidecar failed, using budget-clamped fallback context: ${error instanceof Error ? error.message : String(error)}`
34254
34260
  );
34255
- return buildBudgetFallbackContext(messages, args.tokenBudget);
34261
+ return buildBudgetFallbackContext(args.messages, args.tokenBudget);
34256
34262
  }
34257
34263
  },
34258
34264
  async compact(args) {
@@ -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.39",
5
+ "version": "1.4.40",
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.39",
3
+ "version": "1.4.40",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",