n8n-nodes-tembory 1.1.17 → 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 = {}) => {
|
|
@@ -2461,8 +2461,43 @@ const wrapTemboryMemory = (memory, ctx, memoryKey) => new Proxy(memory, {
|
|
|
2461
2461
|
return response;
|
|
2462
2462
|
}
|
|
2463
2463
|
catch (error) {
|
|
2464
|
-
|
|
2465
|
-
|
|
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
|
+
}
|
|
2485
|
+
ctx.addOutputData(n8n_workflow_1.NodeConnectionTypes.AiMemory, index, [
|
|
2486
|
+
[{
|
|
2487
|
+
json: {
|
|
2488
|
+
action: 'saveContext',
|
|
2489
|
+
saved: fallbackSaved,
|
|
2490
|
+
fallback: true,
|
|
2491
|
+
inputChars: JSON.stringify(input || {}).length,
|
|
2492
|
+
outputChars: JSON.stringify(output || {}).length,
|
|
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),
|
|
2497
|
+
},
|
|
2498
|
+
}],
|
|
2499
|
+
]);
|
|
2500
|
+
return undefined;
|
|
2466
2501
|
}
|
|
2467
2502
|
};
|
|
2468
2503
|
}
|
|
@@ -3072,7 +3107,7 @@ class TemboryMemory {
|
|
|
3072
3107
|
await TemboryMemory.prototype.saveContextForItem.call(this, itemIndex, inputValues, outputValues);
|
|
3073
3108
|
},
|
|
3074
3109
|
};
|
|
3075
|
-
return { response: wrapTemboryMemory(memory, this, memoryKey) };
|
|
3110
|
+
return { response: wrapTemboryMemory(memory, this, memoryKey, itemIndex) };
|
|
3076
3111
|
}
|
|
3077
3112
|
async saveMessagesForItem(itemIndex, messages = []) {
|
|
3078
3113
|
const inputValues = {};
|
package/package.json
CHANGED