n8n-nodes-tembory 1.1.18 → 1.1.19

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.
@@ -2403,7 +2403,7 @@ const contextSizeOfMessages = (messages = []) => {
2403
2403
  const chars = perMessage.reduce((sum, item) => sum + item.chars, 0);
2404
2404
  return { chars, approx_tokens: approxTokenCount((messages || []).map((m) => m.content || '').join('\n')), messages: perMessage };
2405
2405
  };
2406
- const wrapTemboryMemory = (memory, ctx, memoryKey) => new Proxy(memory, {
2406
+ const wrapTemboryMemory = (memory, ctx, memoryKey, itemIndex = 0) => new Proxy(memory, {
2407
2407
  get(target, prop) {
2408
2408
  if (prop === 'loadMemoryVariables') {
2409
2409
  return async (values = {}) => {
@@ -2462,14 +2462,38 @@ const wrapTemboryMemory = (memory, ctx, memoryKey) => new Proxy(memory, {
2462
2462
  }
2463
2463
  catch (error) {
2464
2464
  const message = error && error.message ? error.message : String(error);
2465
+ const safeInput = stripThreadTestPrefix(pickText(input, ['input', 'chatInput', 'text', 'query', 'question']));
2466
+ const safeOutput = cleanAssistantTranscriptText(pickText(output, ['output', 'response', 'text', 'answer']));
2467
+ let fallbackSaved = false;
2468
+ let fallbackError;
2469
+ let chatHistory = [];
2470
+ if (safeInput || safeOutput) {
2471
+ try {
2472
+ await TemboryMemory.prototype.saveContextForItem.call(ctx, itemIndex, safeInput ? { input: safeInput } : {}, safeOutput ? { output: safeOutput } : {});
2473
+ fallbackSaved = true;
2474
+ try {
2475
+ chatHistory = snapshotJson(await target.chatHistory.getMessages());
2476
+ }
2477
+ catch {
2478
+ chatHistory = [];
2479
+ }
2480
+ }
2481
+ catch (fallback) {
2482
+ fallbackError = fallback && fallback.message ? fallback.message : String(fallback);
2483
+ }
2484
+ }
2465
2485
  ctx.addOutputData(n8n_workflow_1.NodeConnectionTypes.AiMemory, index, [
2466
2486
  [{
2467
2487
  json: {
2468
2488
  action: 'saveContext',
2469
- saved: false,
2489
+ saved: fallbackSaved,
2490
+ fallback: true,
2470
2491
  inputChars: JSON.stringify(input || {}).length,
2471
2492
  outputChars: JSON.stringify(output || {}).length,
2472
- error: truncate(message, 500),
2493
+ messages: Array.isArray(chatHistory) ? chatHistory.length : 0,
2494
+ savedSummary: fallbackSaved ? summarizeSaveContextForSideChannel({ input: safeInput }, { output: safeOutput }, chatHistory) : undefined,
2495
+ originalError: truncate(message, 500),
2496
+ error: fallbackSaved ? undefined : truncate(fallbackError || message, 500),
2473
2497
  },
2474
2498
  }],
2475
2499
  ]);
@@ -3083,7 +3107,7 @@ class TemboryMemory {
3083
3107
  await TemboryMemory.prototype.saveContextForItem.call(this, itemIndex, inputValues, outputValues);
3084
3108
  },
3085
3109
  };
3086
- return { response: wrapTemboryMemory(memory, this, memoryKey) };
3110
+ return { response: wrapTemboryMemory(memory, this, memoryKey, itemIndex) };
3087
3111
  }
3088
3112
  async saveMessagesForItem(itemIndex, messages = []) {
3089
3113
  const inputValues = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-tembory",
3
- "version": "1.1.18",
3
+ "version": "1.1.19",
4
4
  "description": "Tembory node for n8n AI Agents with operational memory, tool history and decision state",
5
5
  "license": "MIT",
6
6
  "homepage": "https://tembory.com",