n8n-nodes-tembory 1.0.32 → 1.0.34

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,26 @@ 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) => {
601
+ const orderedTools = sortToolHistory(tools || []);
602
+ const names = orderedTools.map((tool) => tool.name || tool.tool || tool.toolName || 'tool').filter(Boolean);
603
+ const readable = `Tool history ledger. Tools called in this thread: ${names.join(', ')}. Use this ledger to answer questions about called tools, tool inputs, tool outputs, tool status and tool order. `;
604
+ return `${readable}${TOOL_LEDGER_MARKER}${safeStringify({
605
+ thread_id: threadId,
606
+ generated_at: nowIso(),
607
+ tools: orderedTools.map((tool, index) => ({
608
+ id: tool.id || tool.callId || tool.call_id || '',
609
+ turn_id: tool.turnId || tool.turn_id || '',
610
+ sequence: tool.sequence || index + 1,
611
+ name: tool.name || tool.tool || tool.toolName || '',
612
+ input: tool.input || '',
613
+ ok: tool.ok !== false,
614
+ result: tool.result || '',
615
+ at: tool.at || nowIso(),
616
+ source: tool.source || 'n8n',
617
+ })),
618
+ })}`;
619
+ };
599
620
  const parseRecentMessageMarker = (text) => {
600
621
  if (!text || typeof text !== 'string' || !text.startsWith(RECENT_MESSAGE_MARKER))
601
622
  return null;
@@ -636,6 +657,33 @@ const parseToolHistoryMarker = (text) => {
636
657
  return null;
637
658
  }
638
659
  };
660
+ const parseToolLedgerMarker = (text) => {
661
+ if (!text || typeof text !== 'string')
662
+ return [];
663
+ const markerIndex = text.indexOf(TOOL_LEDGER_MARKER);
664
+ if (markerIndex < 0)
665
+ return [];
666
+ try {
667
+ const parsed = JSON.parse(text.slice(markerIndex + TOOL_LEDGER_MARKER.length));
668
+ const tools = Array.isArray(parsed?.tools) ? parsed.tools : [];
669
+ return tools
670
+ .filter((tool) => tool && tool.name)
671
+ .map((tool, index) => ({
672
+ id: tool.id || tool.call_id || tool.callId || '',
673
+ turnId: tool.turn_id || tool.turnId || '',
674
+ sequence: tool.sequence || index + 1,
675
+ name: String(tool.name),
676
+ input: tool.input === undefined ? '' : String(tool.input),
677
+ ok: tool.ok !== false,
678
+ result: truncate(tool.result || '', 1000),
679
+ at: tool.at || parsed.generated_at || nowIso(),
680
+ source: tool.source || 'tool_ledger_marker',
681
+ }));
682
+ }
683
+ catch {
684
+ return [];
685
+ }
686
+ };
639
687
  const recentMessageFromMemory = (item) => {
640
688
  const meta = metadataOf(item);
641
689
  const content = meta.content || item.memory || item.text || item.value || item.content || item.data;
@@ -710,6 +758,9 @@ const toolHistoryFromMemory = (item) => {
710
758
  const explicitToolHistoryItemsFromMemory = (item) => {
711
759
  const meta = metadataOf(item);
712
760
  const content = meta.content || item.memory || item.text || item.value || item.content || item.data;
761
+ const ledger = parseToolLedgerMarker(content);
762
+ if (ledger.length)
763
+ return ledger;
713
764
  const marked = parseToolHistoryMarker(content);
714
765
  if (marked)
715
766
  return [marked];
@@ -2812,6 +2863,13 @@ class Mem0Memory {
2812
2863
  thread_id: threadId,
2813
2864
  }, ids));
2814
2865
  }
2866
+ clientMemories.push(await createClientVectorMemory(connectedEmbedding, encodeToolLedger(toolHistoryForTurn, threadId), {
2867
+ kind: 'tool_ledger',
2868
+ thread_id: threadId,
2869
+ project: project || undefined,
2870
+ source: 'n8n_connected_embedding',
2871
+ generated_at: nowIso(),
2872
+ }, ids));
2815
2873
  }
2816
2874
  await saveClientVectorMemories(this, clientMemories, ids);
2817
2875
  if (adv.includeRecentMessages !== false && recentForMem0.length) {
@@ -2865,6 +2923,23 @@ class Mem0Memory {
2865
2923
  tool: tool.name,
2866
2924
  });
2867
2925
  }
2926
+ await safePersistLegacyMemory(this, {
2927
+ messages: [{ role: 'system', content: encodeToolLedger(toolHistoryForTurn, threadId) }],
2928
+ infer: false,
2929
+ user_id: body.user_id,
2930
+ agent_id: body.agent_id,
2931
+ run_id: body.run_id,
2932
+ metadata: {
2933
+ kind: 'tool_ledger',
2934
+ thread_id: threadId,
2935
+ project: project || undefined,
2936
+ source: 'tembory_transcript',
2937
+ generated_at: nowIso(),
2938
+ },
2939
+ }, {
2940
+ kind: 'tool_ledger',
2941
+ user_id: body.user_id,
2942
+ });
2868
2943
  }
2869
2944
  return;
2870
2945
  }
@@ -2912,6 +2987,20 @@ class Mem0Memory {
2912
2987
  },
2913
2988
  });
2914
2989
  }
2990
+ await GenericFunctions_1.mem0ApiRequest.call(this, 'POST', '/v1/memories/', {
2991
+ messages: [{ role: 'system', content: encodeToolLedger(toolHistoryForTurn, threadId) }],
2992
+ infer: false,
2993
+ user_id: body.user_id,
2994
+ agent_id: body.agent_id,
2995
+ run_id: body.run_id,
2996
+ metadata: {
2997
+ kind: 'tool_ledger',
2998
+ thread_id: threadId,
2999
+ project: project || undefined,
3000
+ source: 'tembory_transcript',
3001
+ generated_at: nowIso(),
3002
+ },
3003
+ });
2915
3004
  }
2916
3005
  if (adv.persistToolFactsToMem0 && toolCalls.length) {
2917
3006
  const facts = toolCalls.map((tool) => `Tool ${tool.name} input=${tool.input}${tool.result ? ` result=${tool.result}` : ''}`).join('\n');
@@ -3619,8 +3708,10 @@ exports.__private = {
3619
3708
  applyToolHistoryWindow,
3620
3709
  dedupeRecentMessages,
3621
3710
  parseToolHistoryMarker,
3711
+ parseToolLedgerMarker,
3622
3712
  parseRecentMessageMarker,
3623
3713
  encodeToolCall,
3714
+ encodeToolLedger,
3624
3715
  encodeRecentMessage,
3625
3716
  userKeyFrom,
3626
3717
  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.34",
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",