n8n-nodes-tembory 1.0.44 → 1.0.45
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.
|
@@ -750,6 +750,23 @@ const parseConversationLedgerMarker = (text) => {
|
|
|
750
750
|
return [];
|
|
751
751
|
}
|
|
752
752
|
};
|
|
753
|
+
const parseTurnArchive = (text) => {
|
|
754
|
+
if (!text || typeof text !== 'string')
|
|
755
|
+
return null;
|
|
756
|
+
const marker = '"marker":"tembory_turn_archive_v1"';
|
|
757
|
+
const markerIndex = text.indexOf(marker);
|
|
758
|
+
if (markerIndex < 0)
|
|
759
|
+
return null;
|
|
760
|
+
const jsonStart = text.lastIndexOf('{', markerIndex);
|
|
761
|
+
if (jsonStart < 0)
|
|
762
|
+
return null;
|
|
763
|
+
try {
|
|
764
|
+
return JSON.parse(text.slice(jsonStart));
|
|
765
|
+
}
|
|
766
|
+
catch {
|
|
767
|
+
return null;
|
|
768
|
+
}
|
|
769
|
+
};
|
|
753
770
|
const recentMessageFromMemory = (item) => {
|
|
754
771
|
const meta = metadataOf(item);
|
|
755
772
|
const content = meta.content || item.memory || item.text || item.value || item.content || item.data;
|
|
@@ -769,6 +786,16 @@ const recentMessageFromMemory = (item) => {
|
|
|
769
786
|
const recentMessagesFromMemory = (item) => {
|
|
770
787
|
const meta = metadataOf(item);
|
|
771
788
|
const content = meta.content || item.memory || item.text || item.value || item.content || item.data;
|
|
789
|
+
const archive = parseTurnArchive(content);
|
|
790
|
+
if (archive && Array.isArray(archive.conversation)) {
|
|
791
|
+
return archive.conversation
|
|
792
|
+
.filter((msg) => msg && msg.content)
|
|
793
|
+
.map((msg) => ({
|
|
794
|
+
role: msg.role || 'user',
|
|
795
|
+
content: truncate(msg.content, 2000),
|
|
796
|
+
at: msg.at || archive.generated_at || nowIso(),
|
|
797
|
+
}));
|
|
798
|
+
}
|
|
772
799
|
const ledger = parseConversationLedgerMarker(content);
|
|
773
800
|
if (ledger.length)
|
|
774
801
|
return ledger;
|
|
@@ -833,6 +860,22 @@ const toolHistoryFromMemory = (item) => {
|
|
|
833
860
|
const explicitToolHistoryItemsFromMemory = (item) => {
|
|
834
861
|
const meta = metadataOf(item);
|
|
835
862
|
const content = meta.content || item.memory || item.text || item.value || item.content || item.data;
|
|
863
|
+
const archive = parseTurnArchive(content);
|
|
864
|
+
if (archive && Array.isArray(archive.tools)) {
|
|
865
|
+
return archive.tools
|
|
866
|
+
.filter((tool) => tool && tool.name)
|
|
867
|
+
.map((tool, index) => ({
|
|
868
|
+
id: tool.id || tool.call_id || tool.callId || '',
|
|
869
|
+
turnId: tool.turn_id || tool.turnId || '',
|
|
870
|
+
sequence: tool.sequence || index + 1,
|
|
871
|
+
name: String(tool.name),
|
|
872
|
+
input: tool.input === undefined ? '' : String(tool.input),
|
|
873
|
+
ok: tool.ok !== false,
|
|
874
|
+
result: truncate(tool.output || tool.result || '', 1000),
|
|
875
|
+
at: tool.at || archive.generated_at || nowIso(),
|
|
876
|
+
source: tool.source || 'turn_archive',
|
|
877
|
+
}));
|
|
878
|
+
}
|
|
836
879
|
const ledger = parseToolLedgerMarker(content);
|
|
837
880
|
if (ledger.length)
|
|
838
881
|
return ledger;
|
|
@@ -3284,7 +3327,7 @@ class Mem0Memory {
|
|
|
3284
3327
|
catch (error) {
|
|
3285
3328
|
connectedAi.errors.push(`languageModel: ${error.message || String(error)}`);
|
|
3286
3329
|
}
|
|
3287
|
-
if (vectorMemoryEnabled) {
|
|
3330
|
+
if (vectorMemoryEnabled || backendPersistenceEnabled) {
|
|
3288
3331
|
try {
|
|
3289
3332
|
connectedEmbedding = await this.getInputConnectionData(n8n_workflow_1.NodeConnectionTypes.AiEmbedding, itemIndex);
|
|
3290
3333
|
connectedAi.embedding = true;
|
|
@@ -3306,6 +3349,28 @@ class Mem0Memory {
|
|
|
3306
3349
|
catch { }
|
|
3307
3350
|
let payload;
|
|
3308
3351
|
let vectorMemories = [];
|
|
3352
|
+
if (!vectorMemoryEnabled && backendPersistenceEnabled && connectedEmbedding && String(query || '').trim()) {
|
|
3353
|
+
try {
|
|
3354
|
+
const archiveBody = {
|
|
3355
|
+
user_id: key,
|
|
3356
|
+
agent_id: adv.agentId ? String(adv.agentId) : undefined,
|
|
3357
|
+
run_id: adv.runId ? String(adv.runId) : undefined,
|
|
3358
|
+
top_k: Math.max(Number(adv.lastN || 0), Number(adv.maxReturn || 12), 12),
|
|
3359
|
+
filters: { kind: 'turn_archive' },
|
|
3360
|
+
};
|
|
3361
|
+
const archiveRes = await searchClientVectorMemories(this, connectedEmbedding, `latest turn archive for thread ${threadId}\n${query}`, archiveBody);
|
|
3362
|
+
vectorMemories = normalizeResults(archiveRes).map((memory) => withTemboryScore(memory, {
|
|
3363
|
+
semanticScore: scoreOf(memory),
|
|
3364
|
+
source: 'turn_archive_lookup',
|
|
3365
|
+
}));
|
|
3366
|
+
connectedAi.embedding = true;
|
|
3367
|
+
connectedAi.embeddingQuery = true;
|
|
3368
|
+
connectedAi.turnArchiveLookup = true;
|
|
3369
|
+
}
|
|
3370
|
+
catch (error) {
|
|
3371
|
+
connectedAi.errors.push(`turnArchiveLookup: ${error.message || String(error)}`);
|
|
3372
|
+
}
|
|
3373
|
+
}
|
|
3309
3374
|
if (vectorMemoryEnabled && (retrievalMode === 'semantic' || retrievalMode === 'semanticV2' || retrievalMode === 'hybrid')) {
|
|
3310
3375
|
const body = { query: String(query || '') };
|
|
3311
3376
|
// IDs
|
package/package.json
CHANGED