n8n-nodes-tembory 1.0.32 → 1.0.33

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.
@@ -578,6 +578,7 @@ const deriveEntityTimeline = (profileFacts = {}, graph = [], recentMessages = []
578
578
  };
579
579
  const RECENT_MESSAGE_MARKER = '__tembory_recent_message_v1__';
580
580
  const TOOL_HISTORY_MARKER = '__tembory_tool_history_v1__';
581
+ const TOOL_LEDGER_MARKER = '__tembory_tool_ledger_v1__';
581
582
  const encodeRecentMessage = (recent, threadId) => `${RECENT_MESSAGE_MARKER}${safeStringify({
582
583
  role: recent.role || 'user',
583
584
  content: recent.content || '',
@@ -596,6 +597,21 @@ const encodeToolCall = (tool, threadId) => `${TOOL_HISTORY_MARKER}${safeStringif
596
597
  source: tool.source || 'n8n',
597
598
  thread_id: threadId,
598
599
  })}`;
600
+ const encodeToolLedger = (tools = [], threadId) => `${TOOL_LEDGER_MARKER}${safeStringify({
601
+ thread_id: threadId,
602
+ generated_at: nowIso(),
603
+ tools: sortToolHistory(tools || []).map((tool, index) => ({
604
+ id: tool.id || tool.callId || tool.call_id || '',
605
+ turn_id: tool.turnId || tool.turn_id || '',
606
+ sequence: tool.sequence || index + 1,
607
+ name: tool.name || tool.tool || tool.toolName || '',
608
+ input: tool.input || '',
609
+ ok: tool.ok !== false,
610
+ result: tool.result || '',
611
+ at: tool.at || nowIso(),
612
+ source: tool.source || 'n8n',
613
+ })),
614
+ })}`;
599
615
  const parseRecentMessageMarker = (text) => {
600
616
  if (!text || typeof text !== 'string' || !text.startsWith(RECENT_MESSAGE_MARKER))
601
617
  return null;
@@ -636,6 +652,30 @@ const parseToolHistoryMarker = (text) => {
636
652
  return null;
637
653
  }
638
654
  };
655
+ const parseToolLedgerMarker = (text) => {
656
+ if (!text || typeof text !== 'string' || !text.startsWith(TOOL_LEDGER_MARKER))
657
+ return [];
658
+ try {
659
+ const parsed = JSON.parse(text.slice(TOOL_LEDGER_MARKER.length));
660
+ const tools = Array.isArray(parsed?.tools) ? parsed.tools : [];
661
+ return tools
662
+ .filter((tool) => tool && tool.name)
663
+ .map((tool, index) => ({
664
+ id: tool.id || tool.call_id || tool.callId || '',
665
+ turnId: tool.turn_id || tool.turnId || '',
666
+ sequence: tool.sequence || index + 1,
667
+ name: String(tool.name),
668
+ input: tool.input === undefined ? '' : String(tool.input),
669
+ ok: tool.ok !== false,
670
+ result: truncate(tool.result || '', 1000),
671
+ at: tool.at || parsed.generated_at || nowIso(),
672
+ source: tool.source || 'tool_ledger_marker',
673
+ }));
674
+ }
675
+ catch {
676
+ return [];
677
+ }
678
+ };
639
679
  const recentMessageFromMemory = (item) => {
640
680
  const meta = metadataOf(item);
641
681
  const content = meta.content || item.memory || item.text || item.value || item.content || item.data;
@@ -710,6 +750,9 @@ const toolHistoryFromMemory = (item) => {
710
750
  const explicitToolHistoryItemsFromMemory = (item) => {
711
751
  const meta = metadataOf(item);
712
752
  const content = meta.content || item.memory || item.text || item.value || item.content || item.data;
753
+ const ledger = parseToolLedgerMarker(content);
754
+ if (ledger.length)
755
+ return ledger;
713
756
  const marked = parseToolHistoryMarker(content);
714
757
  if (marked)
715
758
  return [marked];
@@ -2812,6 +2855,13 @@ class Mem0Memory {
2812
2855
  thread_id: threadId,
2813
2856
  }, ids));
2814
2857
  }
2858
+ clientMemories.push(await createClientVectorMemory(connectedEmbedding, encodeToolLedger(toolHistoryForTurn, threadId), {
2859
+ kind: 'tool_ledger',
2860
+ thread_id: threadId,
2861
+ project: project || undefined,
2862
+ source: 'n8n_connected_embedding',
2863
+ generated_at: nowIso(),
2864
+ }, ids));
2815
2865
  }
2816
2866
  await saveClientVectorMemories(this, clientMemories, ids);
2817
2867
  if (adv.includeRecentMessages !== false && recentForMem0.length) {
@@ -2865,6 +2915,23 @@ class Mem0Memory {
2865
2915
  tool: tool.name,
2866
2916
  });
2867
2917
  }
2918
+ await safePersistLegacyMemory(this, {
2919
+ messages: [{ role: 'system', content: encodeToolLedger(toolHistoryForTurn, threadId) }],
2920
+ infer: false,
2921
+ user_id: body.user_id,
2922
+ agent_id: body.agent_id,
2923
+ run_id: body.run_id,
2924
+ metadata: {
2925
+ kind: 'tool_ledger',
2926
+ thread_id: threadId,
2927
+ project: project || undefined,
2928
+ source: 'tembory_transcript',
2929
+ generated_at: nowIso(),
2930
+ },
2931
+ }, {
2932
+ kind: 'tool_ledger',
2933
+ user_id: body.user_id,
2934
+ });
2868
2935
  }
2869
2936
  return;
2870
2937
  }
@@ -2912,6 +2979,20 @@ class Mem0Memory {
2912
2979
  },
2913
2980
  });
2914
2981
  }
2982
+ await GenericFunctions_1.mem0ApiRequest.call(this, 'POST', '/v1/memories/', {
2983
+ messages: [{ role: 'system', content: encodeToolLedger(toolHistoryForTurn, threadId) }],
2984
+ infer: false,
2985
+ user_id: body.user_id,
2986
+ agent_id: body.agent_id,
2987
+ run_id: body.run_id,
2988
+ metadata: {
2989
+ kind: 'tool_ledger',
2990
+ thread_id: threadId,
2991
+ project: project || undefined,
2992
+ source: 'tembory_transcript',
2993
+ generated_at: nowIso(),
2994
+ },
2995
+ });
2915
2996
  }
2916
2997
  if (adv.persistToolFactsToMem0 && toolCalls.length) {
2917
2998
  const facts = toolCalls.map((tool) => `Tool ${tool.name} input=${tool.input}${tool.result ? ` result=${tool.result}` : ''}`).join('\n');
@@ -3619,8 +3700,10 @@ exports.__private = {
3619
3700
  applyToolHistoryWindow,
3620
3701
  dedupeRecentMessages,
3621
3702
  parseToolHistoryMarker,
3703
+ parseToolLedgerMarker,
3622
3704
  parseRecentMessageMarker,
3623
3705
  encodeToolCall,
3706
+ encodeToolLedger,
3624
3707
  encodeRecentMessage,
3625
3708
  userKeyFrom,
3626
3709
  applyOperationalPreset,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-tembory",
3
- "version": "1.0.32",
3
+ "version": "1.0.33",
4
4
  "description": "Tembory node for n8n AI Agents with profile, tools, timeline, graph and semantic memory",
5
5
  "license": "MIT",
6
6
  "homepage": "https://tembory.com",