n8n-nodes-tembory 1.1.13 → 1.1.15
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.
|
@@ -1960,7 +1960,7 @@ const contextMemoryText = (memory, max = 700) => {
|
|
|
1960
1960
|
};
|
|
1961
1961
|
const approxTokenCount = (text) => Math.ceil(String(text || '').length / 4);
|
|
1962
1962
|
const noisyToolFields = new Set(['requested_from', 'thread', 'thread_id', 'run_id', 'dedupe_key', 'args_hash', 'result_hash', 'source']);
|
|
1963
|
-
const importantJsonFields = ['id', 'status', 'state', 'next_step', 'action', 'intent', 'tool', 'input', 'output', 'result', 'error', 'message', 'reason', 'customer_id', 'customerId', 'user_id', 'lead_id', 'ticket_id', 'charge_id', 'reservation_id', 'confirmation_id', 'selected_from_message', 'available_slots', 'availability_slots', 'disponibilidade', 'dataDisponivel', 'horarios', 'timezone', 'name', 'phone', 'segmento', 'platform', 'plataforma', 'lifecycle_stage', 'provider', 'provider_id', 'providerId', 'provider_name', 'services', 'service_id', 'serviceId', 'locationId', 'location_id', 'local', 'especialidade', 'duration', 'price', 'price_num', 'sku', 'product', 'stock', 'queue', 'priority'];
|
|
1963
|
+
const importantJsonFields = ['id', 'status', 'state', 'timestamp', 'next_step', 'action', 'intent', 'tool', 'input', 'output', 'result', 'error', 'message', 'reason', 'customer_id', 'customerId', 'user_id', 'lead_id', 'ticket_id', 'charge_id', 'reservation_id', 'confirmation_id', 'selected_from_message', 'available_slots', 'availability_slots', 'disponibilidade', 'dataDisponivel', 'horarios', 'timezone', 'name', 'phone', 'segmento', 'platform', 'plataforma', 'lifecycle_stage', 'provider', 'provider_id', 'providerId', 'provider_name', 'services', 'service_id', 'serviceId', 'locationId', 'location_id', 'local', 'especialidade', 'duration', 'price', 'price_num', 'sku', 'product', 'stock', 'queue', 'priority', 'prioridade', 'fila'];
|
|
1964
1964
|
const stripNoisyToolFields = (value, depth = 0) => {
|
|
1965
1965
|
if (depth > 8)
|
|
1966
1966
|
return undefined;
|
|
@@ -2030,8 +2030,8 @@ const compactToolHistoryForAgent = (toolHistory = [], maxItems = 6, includeResul
|
|
|
2030
2030
|
status: tool.ok === false ? 'failed' : 'ok',
|
|
2031
2031
|
at: tool.at,
|
|
2032
2032
|
reason: truncate(String(tool.reason || tool.decision || tool.why || tool.source || 'recorded tool call'), 140),
|
|
2033
|
-
input: truncate(String(tool.input || ''),
|
|
2034
|
-
result: includeResults ? compactToolResult(tool.result,
|
|
2033
|
+
input: truncate(String(tool.input || ''), 500) || undefined,
|
|
2034
|
+
result: includeResults ? compactToolResult(tool.result, 1200) : undefined,
|
|
2035
2035
|
}));
|
|
2036
2036
|
const cleanContextValue = (value) => {
|
|
2037
2037
|
if (Array.isArray(value)) {
|
|
@@ -2271,6 +2271,40 @@ const compactMemoryEventPayload = (payload = {}) => {
|
|
|
2271
2271
|
}
|
|
2272
2272
|
return compact;
|
|
2273
2273
|
};
|
|
2274
|
+
const summarizeMemoryMessagesForSideChannel = (messages = []) => {
|
|
2275
|
+
const list = Array.isArray(messages) ? messages : [];
|
|
2276
|
+
const summary = { messages: list.length };
|
|
2277
|
+
const firstSystem = list.find((message) => {
|
|
2278
|
+
const type = messageTypeOf(message);
|
|
2279
|
+
return type === 'system' || /system/i.test(String(message?.role || ''));
|
|
2280
|
+
});
|
|
2281
|
+
if (!firstSystem)
|
|
2282
|
+
return summary;
|
|
2283
|
+
try {
|
|
2284
|
+
const parsed = JSON.parse(messageContentOf(firstSystem));
|
|
2285
|
+
const conversation = parsed.conversation || {};
|
|
2286
|
+
const tools = parsed.tools || {};
|
|
2287
|
+
const toolItems = Array.isArray(tools.items) ? tools.items : [];
|
|
2288
|
+
const summaryText = parsed.summary?.slm || parsed.summary || parsed.connectedModelSummary || parsed.activeSummary || '';
|
|
2289
|
+
summary.intent = parsed.observations?.inferred_intent?.label || parsed.workingMemory?.last_user_intent || parsed.decisionState?.current_intent || undefined;
|
|
2290
|
+
summary.currentUserMessage = conversation.current_user_message ? truncate(conversation.current_user_message, 180) : undefined;
|
|
2291
|
+
summary.recentMessages = Array.isArray(conversation.conversation_history_chronological) ? conversation.conversation_history_chronological.length : undefined;
|
|
2292
|
+
summary.toolCount = toolItems.length || tools.count || parsed.operationalState?.tool_counts?.total || undefined;
|
|
2293
|
+
summary.toolNames = toolItems.map((tool) => tool.name || tool.tool_name).filter(Boolean).slice(0, 20);
|
|
2294
|
+
summary.lastTool = tools.last_successful_tool
|
|
2295
|
+
? {
|
|
2296
|
+
name: tools.last_successful_tool.name,
|
|
2297
|
+
at: tools.last_successful_tool.at,
|
|
2298
|
+
}
|
|
2299
|
+
: (toolItems.length ? { name: toolItems[toolItems.length - 1].name, at: toolItems[toolItems.length - 1].at } : undefined);
|
|
2300
|
+
summary.quality = parsed.contextHealth?.quality_score || parsed.contextQualityScore || undefined;
|
|
2301
|
+
summary.summaryChars = typeof summaryText === 'string' ? summaryText.length : safeStringify(summaryText).length;
|
|
2302
|
+
return Object.fromEntries(Object.entries(summary).filter(([, value]) => value !== undefined));
|
|
2303
|
+
}
|
|
2304
|
+
catch {
|
|
2305
|
+
return summary;
|
|
2306
|
+
}
|
|
2307
|
+
};
|
|
2274
2308
|
const contextSizeOfMessages = (messages = []) => {
|
|
2275
2309
|
const perMessage = (messages || []).map((message, index) => {
|
|
2276
2310
|
const content = String(message.content || '');
|
|
@@ -2288,12 +2322,14 @@ const wrapTemboryMemory = (memory, ctx, memoryKey) => new Proxy(memory, {
|
|
|
2288
2322
|
]);
|
|
2289
2323
|
try {
|
|
2290
2324
|
const response = await target.loadMemoryVariables(values);
|
|
2291
|
-
const
|
|
2325
|
+
const memoryMessages = response[memoryKey] || response.chatHistory || [];
|
|
2326
|
+
const messages = Array.isArray(memoryMessages) ? memoryMessages.length : 0;
|
|
2292
2327
|
ctx.addOutputData(n8n_workflow_1.NodeConnectionTypes.AiMemory, index, [
|
|
2293
2328
|
[{
|
|
2294
2329
|
json: {
|
|
2295
2330
|
action: 'loadMemoryVariables',
|
|
2296
2331
|
messages,
|
|
2332
|
+
memorySummary: summarizeMemoryMessagesForSideChannel(memoryMessages),
|
|
2297
2333
|
},
|
|
2298
2334
|
}],
|
|
2299
2335
|
]);
|
|
@@ -4060,4 +4096,5 @@ exports.__private = {
|
|
|
4060
4096
|
cleanModelSummaryText,
|
|
4061
4097
|
invokeConnectedModelSummary,
|
|
4062
4098
|
compactMemoryEventPayload,
|
|
4099
|
+
summarizeMemoryMessagesForSideChannel,
|
|
4063
4100
|
};
|
package/package.json
CHANGED