n8n-nodes-tembory 1.1.16 → 1.1.18
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.
|
@@ -2262,6 +2262,35 @@ const compactToolAuditForSideChannel = (tool = {}) => cleanContextValue({
|
|
|
2262
2262
|
input: truncate(String(tool.input || tool.tool_args || tool.normalized_args || ''), 500) || undefined,
|
|
2263
2263
|
output: compactToolResult(tool.result !== undefined ? tool.result : tool.output !== undefined ? tool.output : tool.observation, 1200),
|
|
2264
2264
|
});
|
|
2265
|
+
const compactMessageForSideChannel = (message = {}) => {
|
|
2266
|
+
const type = messageTypeOf(message) || String(message.role || 'message').toLowerCase();
|
|
2267
|
+
const role = type === 'human' ? 'user' : type === 'ai' ? 'assistant' : type || 'message';
|
|
2268
|
+
const content = messageContentOf(message);
|
|
2269
|
+
return cleanContextValue({
|
|
2270
|
+
role,
|
|
2271
|
+
chars: content.length,
|
|
2272
|
+
preview: role === 'system' ? '[system context hidden]' : truncate(content, 280),
|
|
2273
|
+
});
|
|
2274
|
+
};
|
|
2275
|
+
const summarizeSaveContextForSideChannel = (input = {}, output = {}, chatHistory = []) => {
|
|
2276
|
+
const inputMessage = input?.input || input?.chatInput || input?.query || input?.question || input?.text || input?.message || '';
|
|
2277
|
+
const outputMessage = output?.output || output?.response || output?.text || output?.message || output?.answer || '';
|
|
2278
|
+
const toolEvents = extractToolCalls(output || {})
|
|
2279
|
+
.map((tool) => compactToolAuditForSideChannel(tool || {}))
|
|
2280
|
+
.filter((tool) => tool && Object.keys(tool).length)
|
|
2281
|
+
.slice(0, 20);
|
|
2282
|
+
return cleanContextValue({
|
|
2283
|
+
messagesAfterSave: Array.isArray(chatHistory) ? chatHistory.length : 0,
|
|
2284
|
+
savedMessages: Array.isArray(chatHistory)
|
|
2285
|
+
? chatHistory.slice(-6).map((message) => compactMessageForSideChannel(message))
|
|
2286
|
+
: undefined,
|
|
2287
|
+
userInput: inputMessage ? truncate(String(inputMessage), 500) : undefined,
|
|
2288
|
+
assistantOutput: outputMessage ? truncate(String(outputMessage), 700) : undefined,
|
|
2289
|
+
toolCallsCaptured: toolEvents.length || undefined,
|
|
2290
|
+
toolNames: toolEvents.map((tool) => tool.name).filter(Boolean),
|
|
2291
|
+
toolEvents,
|
|
2292
|
+
});
|
|
2293
|
+
};
|
|
2265
2294
|
const compactMemoryEventPayload = (payload = {}) => {
|
|
2266
2295
|
const compact = { ...(payload || {}) };
|
|
2267
2296
|
if (Array.isArray(compact.toolCalls)) {
|
|
@@ -2298,6 +2327,11 @@ const summarizeMemoryMessagesForSideChannel = (messages = []) => {
|
|
|
2298
2327
|
const tools = parsed.tools || {};
|
|
2299
2328
|
const toolItems = Array.isArray(tools.items) ? tools.items : [];
|
|
2300
2329
|
const summaryText = parsed.summary?.slm || parsed.summary || parsed.connectedModelSummary || parsed.activeSummary || '';
|
|
2330
|
+
summary.userId = parsed.userId;
|
|
2331
|
+
summary.project = parsed.project || undefined;
|
|
2332
|
+
summary.retrievalMode = parsed.retrievalMode;
|
|
2333
|
+
summary.payloadFormat = parsed.payloadFormat;
|
|
2334
|
+
summary.options = cleanContextValue(parsed.options || {});
|
|
2301
2335
|
summary.intent = parsed.observations?.inferred_intent?.label || parsed.workingMemory?.last_user_intent || parsed.decisionState?.current_intent || undefined;
|
|
2302
2336
|
summary.currentUserMessage = conversation.current_user_message ? truncate(conversation.current_user_message, 180) : undefined;
|
|
2303
2337
|
summary.recentMessages = Array.isArray(conversation.conversation_history_chronological) ? conversation.conversation_history_chronological.length : undefined;
|
|
@@ -2313,7 +2347,47 @@ const summarizeMemoryMessagesForSideChannel = (messages = []) => {
|
|
|
2313
2347
|
at: tools.last_successful_tool.at,
|
|
2314
2348
|
}
|
|
2315
2349
|
: (toolItems.length ? { name: toolItems[toolItems.length - 1].name, at: toolItems[toolItems.length - 1].at } : undefined);
|
|
2350
|
+
summary.counts = cleanContextValue({
|
|
2351
|
+
conversationMessages: Array.isArray(conversation.conversation_history_chronological) ? conversation.conversation_history_chronological.length : undefined,
|
|
2352
|
+
userMessages: Array.isArray(conversation.all_user_messages_chronological) ? conversation.all_user_messages_chronological.length : undefined,
|
|
2353
|
+
toolHistory: toolItems.length,
|
|
2354
|
+
actionLedger: Array.isArray(parsed.actionLedger) ? parsed.actionLedger.length : undefined,
|
|
2355
|
+
entityTimeline: Array.isArray(parsed.entityTimeline) ? parsed.entityTimeline.length : undefined,
|
|
2356
|
+
vectorMemories: Array.isArray(parsed.vectorMemories) ? parsed.vectorMemories.length : undefined,
|
|
2357
|
+
graph: Array.isArray(parsed.graph) ? parsed.graph.length : undefined,
|
|
2358
|
+
recentHighlights: Array.isArray(parsed.recentHighlights) ? parsed.recentHighlights.length : undefined,
|
|
2359
|
+
});
|
|
2360
|
+
summary.loadedSections = cleanContextValue({
|
|
2361
|
+
conversation: Boolean(parsed.conversation),
|
|
2362
|
+
summary: Boolean(parsed.summary),
|
|
2363
|
+
activeSummary: Boolean(parsed.activeSummary),
|
|
2364
|
+
connectedModelSummary: Boolean(parsed.connectedModelSummary),
|
|
2365
|
+
workingMemory: Boolean(parsed.workingMemory),
|
|
2366
|
+
decisionState: Boolean(parsed.decisionState),
|
|
2367
|
+
memoryCompression: Boolean(parsed.memoryCompression),
|
|
2368
|
+
operationalState: Boolean(parsed.operationalState),
|
|
2369
|
+
actionLedger: Array.isArray(parsed.actionLedger),
|
|
2370
|
+
entityTimeline: Array.isArray(parsed.entityTimeline),
|
|
2371
|
+
vectorMemories: Array.isArray(parsed.vectorMemories),
|
|
2372
|
+
graph: Array.isArray(parsed.graph),
|
|
2373
|
+
recentHighlights: Array.isArray(parsed.recentHighlights),
|
|
2374
|
+
contextHealth: Boolean(parsed.contextHealth),
|
|
2375
|
+
});
|
|
2376
|
+
summary.workingMemory = cleanContextValue({
|
|
2377
|
+
currentGoal: parsed.workingMemory?.current_goal,
|
|
2378
|
+
currentTask: parsed.workingMemory?.current_task,
|
|
2379
|
+
nextExpectedAction: parsed.workingMemory?.next_expected_action,
|
|
2380
|
+
lastUserIntent: parsed.workingMemory?.last_user_intent,
|
|
2381
|
+
lastUserMessage: parsed.workingMemory?.last_user_message ? truncate(parsed.workingMemory.last_user_message, 220) : undefined,
|
|
2382
|
+
});
|
|
2383
|
+
summary.decisionState = cleanContextValue({
|
|
2384
|
+
currentIntent: parsed.decisionState?.current_intent,
|
|
2385
|
+
decisionCount: parsed.decisionState?.decision_count,
|
|
2386
|
+
latestTool: parsed.decisionState?.latest_tool,
|
|
2387
|
+
doNotRepeatTools: parsed.decisionState?.do_not_repeat_tools,
|
|
2388
|
+
});
|
|
2316
2389
|
summary.quality = parsed.contextHealth?.quality_score || parsed.contextQualityScore || undefined;
|
|
2390
|
+
summary.contextSize = parsed.diagnostics?.contextSize || undefined;
|
|
2317
2391
|
summary.summaryChars = typeof summaryText === 'string' ? summaryText.length : safeStringify(summaryText).length;
|
|
2318
2392
|
return Object.fromEntries(Object.entries(summary).filter(([, value]) => value !== undefined));
|
|
2319
2393
|
}
|
|
@@ -2371,6 +2445,7 @@ const wrapTemboryMemory = (memory, ctx, memoryKey) => new Proxy(memory, {
|
|
|
2371
2445
|
try {
|
|
2372
2446
|
const response = await target.saveContext(input, output);
|
|
2373
2447
|
const chatHistory = snapshotJson(await target.chatHistory.getMessages());
|
|
2448
|
+
const savedSummary = summarizeSaveContextForSideChannel(input, output, chatHistory);
|
|
2374
2449
|
ctx.addOutputData(n8n_workflow_1.NodeConnectionTypes.AiMemory, index, [
|
|
2375
2450
|
[{
|
|
2376
2451
|
json: {
|
|
@@ -2379,14 +2454,26 @@ const wrapTemboryMemory = (memory, ctx, memoryKey) => new Proxy(memory, {
|
|
|
2379
2454
|
inputChars: JSON.stringify(input || {}).length,
|
|
2380
2455
|
outputChars: JSON.stringify(output || {}).length,
|
|
2381
2456
|
messages: Array.isArray(chatHistory) ? chatHistory.length : 0,
|
|
2457
|
+
savedSummary,
|
|
2382
2458
|
},
|
|
2383
2459
|
}],
|
|
2384
2460
|
]);
|
|
2385
2461
|
return response;
|
|
2386
2462
|
}
|
|
2387
2463
|
catch (error) {
|
|
2388
|
-
|
|
2389
|
-
|
|
2464
|
+
const message = error && error.message ? error.message : String(error);
|
|
2465
|
+
ctx.addOutputData(n8n_workflow_1.NodeConnectionTypes.AiMemory, index, [
|
|
2466
|
+
[{
|
|
2467
|
+
json: {
|
|
2468
|
+
action: 'saveContext',
|
|
2469
|
+
saved: false,
|
|
2470
|
+
inputChars: JSON.stringify(input || {}).length,
|
|
2471
|
+
outputChars: JSON.stringify(output || {}).length,
|
|
2472
|
+
error: truncate(message, 500),
|
|
2473
|
+
},
|
|
2474
|
+
}],
|
|
2475
|
+
]);
|
|
2476
|
+
return undefined;
|
|
2390
2477
|
}
|
|
2391
2478
|
};
|
|
2392
2479
|
}
|
|
@@ -4113,4 +4200,5 @@ exports.__private = {
|
|
|
4113
4200
|
invokeConnectedModelSummary,
|
|
4114
4201
|
compactMemoryEventPayload,
|
|
4115
4202
|
summarizeMemoryMessagesForSideChannel,
|
|
4203
|
+
summarizeSaveContextForSideChannel,
|
|
4116
4204
|
};
|
package/package.json
CHANGED