n8n-nodes-mem0-self 0.1.0 → 0.2.0
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.
- package/LICENSE +21 -0
- package/README.md +30 -17
- package/dist/credentials/Mem0SelfHostedApi.credentials.js +1 -1
- package/dist/credentials/Mem0SelfHostedApi.credentials.js.map +1 -1
- package/dist/nodes/Mem0/GenericFunctions.d.ts +2 -2
- package/dist/nodes/Mem0/GenericFunctions.d.ts.map +1 -1
- package/dist/nodes/Mem0/GenericFunctions.js.map +1 -1
- package/dist/nodes/Mem0/Mem0Memory.node.d.ts +7 -0
- package/dist/nodes/Mem0/Mem0Memory.node.d.ts.map +1 -0
- package/dist/nodes/Mem0/Mem0Memory.node.js +244 -0
- package/dist/nodes/Mem0/Mem0Memory.node.js.map +1 -0
- package/package.json +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Amaral Karl
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,29 +1,42 @@
|
|
|
1
|
-
# n8n-nodes-mem0-
|
|
1
|
+
# n8n-nodes-mem0-self
|
|
2
2
|
|
|
3
|
-
Community node for Mem0 Self-Hosted
|
|
3
|
+
Community node for Mem0 Self-Hosted memory in n8n.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Included Node
|
|
6
6
|
|
|
7
|
-
- `
|
|
8
|
-
- `POST /search` (search scoped by `user_id` + `agent_id`)
|
|
7
|
+
- `Mem0 Chat Memory` (`mem0Memory`)
|
|
9
8
|
|
|
10
|
-
This package
|
|
9
|
+
This package is focused on AI Agent memory usage (safe profile) and intentionally avoids admin/destructive operations.
|
|
11
10
|
|
|
12
|
-
##
|
|
11
|
+
## What It Does
|
|
13
12
|
|
|
14
|
-
- `
|
|
15
|
-
- `
|
|
16
|
-
-
|
|
13
|
+
- Stores conversation turns in Mem0 using `POST /memories`
|
|
14
|
+
- Retrieves contextual memory using `POST /search`
|
|
15
|
+
- Scopes memory by:
|
|
16
|
+
- `user_id` (required)
|
|
17
|
+
- `agent_id` (required)
|
|
18
|
+
- `run_id` (optional)
|
|
17
19
|
|
|
18
|
-
## Credential
|
|
20
|
+
## Credential Setup
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
- API Key: set in n8n credentials (no hardcoded default in production)
|
|
22
|
+
Credential type: `Mem0 Self-Hosted API`
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
- Base URL default: `http://localhost:8000`
|
|
25
|
+
- Header auth: `X-API-Key`
|
|
24
26
|
|
|
25
|
-
##
|
|
27
|
+
## Safe Profile Notes
|
|
26
28
|
|
|
29
|
+
- `clear()` is non-destructive (no-op) in this node.
|
|
30
|
+
- If `run_id` is omitted, memory context is shared across sessions for the same `user_id + agent_id`.
|
|
27
31
|
- Keep API keys only in n8n credential storage.
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
|
|
33
|
+
## Build
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install
|
|
37
|
+
npm run build
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## License
|
|
41
|
+
|
|
42
|
+
MIT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mem0SelfHostedApi.credentials.js","sourceRoot":"","sources":["../../credentials/Mem0SelfHostedApi.credentials.ts"],"names":[],"mappings":";;;AAOA,MAAa,iBAAiB;IAA9B;QACC,SAAI,GAAG,mBAAmB,CAAC;QAC3B,gBAAW,GAAG,sBAAsB,CAAC;QACrC,qBAAgB,GAAG,oDAAoD,CAAC;QAExE,eAAU,GAAsB;YAC/B;gBACC,WAAW,EAAE,UAAU;gBACvB,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"Mem0SelfHostedApi.credentials.js","sourceRoot":"","sources":["../../credentials/Mem0SelfHostedApi.credentials.ts"],"names":[],"mappings":";;;AAOA,MAAa,iBAAiB;IAA9B;QACC,SAAI,GAAG,mBAAmB,CAAC;QAC3B,gBAAW,GAAG,sBAAsB,CAAC;QACrC,qBAAgB,GAAG,oDAAoD,CAAC;QAExE,eAAU,GAAsB;YAC/B;gBACC,WAAW,EAAE,UAAU;gBACvB,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,uBAAuB;gBAChC,QAAQ,EAAE,IAAI;gBACd,WAAW,EAAE,gDAAgD;aAC7D;YACD;gBACC,WAAW,EAAE,SAAS;gBACtB,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;gBAC/B,OAAO,EAAE,EAAE;gBACX,WAAW,EAAE,kCAAkC;aAC/C;SACD,CAAC;QAEF,iBAAY,GAAyB;YACpC,IAAI,EAAE,SAAS;YACf,UAAU,EAAE;gBACX,OAAO,EAAE;oBACR,WAAW,EAAE,0BAA0B;iBACvC;aACD;SACD,CAAC;QAEF,SAAI,GAA2B;YAC9B,OAAO,EAAE;gBACR,OAAO,EAAE,2BAA2B;gBACpC,GAAG,EAAE,OAAO;gBACZ,MAAM,EAAE,KAAK;aACb;SACD,CAAC;IACH,CAAC;CAAA;AAxCD,8CAwCC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { IExecuteFunctions, IHookFunctions, ILoadOptionsFunctions } from 'n8n-workflow';
|
|
2
|
-
type Ctx = IExecuteFunctions | IHookFunctions | ILoadOptionsFunctions;
|
|
1
|
+
import type { IExecuteFunctions, IHookFunctions, ILoadOptionsFunctions, ISupplyDataFunctions } from 'n8n-workflow';
|
|
2
|
+
type Ctx = IExecuteFunctions | IHookFunctions | ILoadOptionsFunctions | ISupplyDataFunctions;
|
|
3
3
|
/**
|
|
4
4
|
* Extracts the memories array from an API response.
|
|
5
5
|
* Self-hosted usually returns arrays directly, but can also wrap results in
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenericFunctions.d.ts","sourceRoot":"","sources":["../../../nodes/Mem0/GenericFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EAErB,MAAM,cAAc,CAAC;AAGtB,KAAK,GAAG,GAAG,iBAAiB,GAAG,cAAc,GAAG,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"GenericFunctions.d.ts","sourceRoot":"","sources":["../../../nodes/Mem0/GenericFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EAErB,oBAAoB,EACpB,MAAM,cAAc,CAAC;AAGtB,KAAK,GAAG,GAAG,iBAAiB,GAAG,cAAc,GAAG,qBAAqB,GAAG,oBAAoB,CAAC;AAE7F;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,CAK9C;AAED;;;GAGG;AACH,wBAAsB,cAAc,CACnC,IAAI,EAAE,GAAG,EACT,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EAC9B,EAAE,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAC1B,OAAO,CAAC,GAAG,CAAC,CAqBd"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenericFunctions.js","sourceRoot":"","sources":["../../../nodes/Mem0/GenericFunctions.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"GenericFunctions.js","sourceRoot":"","sources":["../../../nodes/Mem0/GenericFunctions.ts"],"names":[],"mappings":";;AAgBA,wCAKC;AAMD,wCA2BC;AA/CD,+CAA4C;AAI5C;;;;GAIG;AACH,SAAgB,cAAc,CAAC,GAAQ;IACtC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC;IACnC,IAAI,GAAG,EAAE,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;QAAE,OAAO,GAAG,CAAC,OAAO,CAAC;IACnE,IAAI,GAAG;QAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IACtB,OAAO,EAAE,CAAC;AACX,CAAC;AAED;;;GAGG;AACI,KAAK,UAAU,cAAc,CAEnC,MAAc,EACd,QAAgB,EAChB,OAA4B,EAAE,EAC9B,KAA0B,EAAE;IAE5B,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC;IACnE,MAAM,OAAO,GAAI,WAAW,CAAC,OAAkB,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACnE,MAAM,gBAAgB,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE,CAAC;IAE9E,MAAM,OAAO,GAAwB;QACpC,MAAM,EAAE,MAAuC;QAC/C,IAAI;QACJ,EAAE;QACF,GAAG,EAAE,GAAG,OAAO,GAAG,gBAAgB,EAAE;KACpC,CAAC;IAEF,IAAI,WAAW,CAAC,MAAM,EAAE,CAAC;QACxB,OAAO,CAAC,OAAO,GAAG,EAAE,WAAW,EAAE,WAAW,CAAC,MAAgB,EAAE,CAAC;IACjE,CAAC;IAED,IAAI,CAAC;QACJ,OAAO,MAAO,IAA0B,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACvE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,IAAI,2BAAY,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,KAAY,CAAC,CAAC;IACtD,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription, ISupplyDataFunctions, SupplyData } from 'n8n-workflow';
|
|
2
|
+
export declare class Mem0Memory implements INodeType {
|
|
3
|
+
description: INodeTypeDescription;
|
|
4
|
+
supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData>;
|
|
5
|
+
execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=Mem0Memory.node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Mem0Memory.node.d.ts","sourceRoot":"","sources":["../../../nodes/Mem0/Mem0Memory.node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,iBAAiB,EACjB,kBAAkB,EAClB,SAAS,EACT,oBAAoB,EACpB,oBAAoB,EACpB,UAAU,EACV,MAAM,cAAc,CAAC;AA+DtB,qBAAa,UAAW,YAAW,SAAS;IAC3C,WAAW,EAAE,oBAAoB,CAyE/B;IAEI,UAAU,CAAC,IAAI,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAsH9E,OAAO,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC;CAUvE"}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Mem0Memory = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
const GenericFunctions_1 = require("./GenericFunctions");
|
|
6
|
+
let HumanMessage;
|
|
7
|
+
let AIMessage;
|
|
8
|
+
let SystemMessage;
|
|
9
|
+
(function loadLangchainMessages() {
|
|
10
|
+
const candidates = ['@langchain/core/messages', 'langchain/messages'];
|
|
11
|
+
for (const moduleName of candidates) {
|
|
12
|
+
try {
|
|
13
|
+
const loaded = require(moduleName);
|
|
14
|
+
if (loaded?.HumanMessage && loaded?.AIMessage) {
|
|
15
|
+
HumanMessage = loaded.HumanMessage;
|
|
16
|
+
AIMessage = loaded.AIMessage;
|
|
17
|
+
SystemMessage = loaded.SystemMessage || loaded.HumanMessage;
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// Continue trying other candidates
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
class BaseMessage {
|
|
26
|
+
constructor(content) {
|
|
27
|
+
this.lc_namespace = ['langchain_core', 'messages'];
|
|
28
|
+
this.lc_serializable = true;
|
|
29
|
+
this.additional_kwargs = {};
|
|
30
|
+
this.content = content;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
HumanMessage = class extends BaseMessage {
|
|
34
|
+
_getType() { return 'human'; }
|
|
35
|
+
get type() { return 'human'; }
|
|
36
|
+
};
|
|
37
|
+
AIMessage = class extends BaseMessage {
|
|
38
|
+
_getType() { return 'ai'; }
|
|
39
|
+
get type() { return 'ai'; }
|
|
40
|
+
};
|
|
41
|
+
SystemMessage = class extends BaseMessage {
|
|
42
|
+
_getType() { return 'system'; }
|
|
43
|
+
get type() { return 'system'; }
|
|
44
|
+
};
|
|
45
|
+
})();
|
|
46
|
+
function toMessageContent(memory) {
|
|
47
|
+
return memory?.memory ?? memory?.text ?? memory?.content ?? JSON.stringify(memory);
|
|
48
|
+
}
|
|
49
|
+
function toLangchainMessage(memory) {
|
|
50
|
+
const content = toMessageContent(memory);
|
|
51
|
+
const role = String(memory?.metadata?.role || memory?.role || '').toLowerCase();
|
|
52
|
+
if (role === 'user' || role === 'human')
|
|
53
|
+
return new HumanMessage(content);
|
|
54
|
+
if (role === 'assistant' || role === 'ai')
|
|
55
|
+
return new AIMessage(content);
|
|
56
|
+
return new SystemMessage(content);
|
|
57
|
+
}
|
|
58
|
+
class Mem0Memory {
|
|
59
|
+
constructor() {
|
|
60
|
+
this.description = {
|
|
61
|
+
displayName: 'Mem0 Chat Memory',
|
|
62
|
+
name: 'mem0Memory',
|
|
63
|
+
icon: 'file:mem0.svg',
|
|
64
|
+
group: ['transform'],
|
|
65
|
+
version: 1,
|
|
66
|
+
description: 'Safe chat memory for AI Agent using Mem0 Self-Hosted',
|
|
67
|
+
defaults: { name: 'Mem0 Chat Memory' },
|
|
68
|
+
inputs: [],
|
|
69
|
+
outputs: [n8n_workflow_1.NodeConnectionTypes.AiMemory],
|
|
70
|
+
outputNames: ['Memory'],
|
|
71
|
+
credentials: [{ name: 'mem0SelfHostedApi', required: true }],
|
|
72
|
+
properties: [
|
|
73
|
+
{
|
|
74
|
+
displayName: 'User ID',
|
|
75
|
+
name: 'userId',
|
|
76
|
+
type: 'string',
|
|
77
|
+
default: '',
|
|
78
|
+
required: true,
|
|
79
|
+
description: 'Required memory owner user identifier',
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
displayName: 'Agent ID',
|
|
83
|
+
name: 'agentId',
|
|
84
|
+
type: 'string',
|
|
85
|
+
default: '',
|
|
86
|
+
required: true,
|
|
87
|
+
description: 'Required memory owner agent identifier',
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
displayName: 'Run ID',
|
|
91
|
+
name: 'runId',
|
|
92
|
+
type: 'string',
|
|
93
|
+
default: '',
|
|
94
|
+
description: 'Optional conversation/session identifier',
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
displayName: 'Default Query',
|
|
98
|
+
name: 'defaultQuery',
|
|
99
|
+
type: 'string',
|
|
100
|
+
default: '',
|
|
101
|
+
description: 'Fallback search query when no dynamic input query is available',
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
displayName: 'Top K',
|
|
105
|
+
name: 'topK',
|
|
106
|
+
type: 'number',
|
|
107
|
+
default: 10,
|
|
108
|
+
typeOptions: { minValue: 1, maxValue: 50 },
|
|
109
|
+
description: 'Maximum number of memories retrieved per search',
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
displayName: 'Rerank',
|
|
113
|
+
name: 'rerank',
|
|
114
|
+
type: 'boolean',
|
|
115
|
+
default: false,
|
|
116
|
+
description: 'Enable reranking during search retrieval',
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
displayName: 'Fields (Comma Separated)',
|
|
120
|
+
name: 'fields',
|
|
121
|
+
type: 'string',
|
|
122
|
+
default: '',
|
|
123
|
+
description: 'Optional fields list for search response',
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
displayName: 'Infer on Store',
|
|
127
|
+
name: 'infer',
|
|
128
|
+
type: 'boolean',
|
|
129
|
+
default: true,
|
|
130
|
+
description: 'Enable Mem0 inference when storing memory entries',
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
async supplyData(itemIndex) {
|
|
136
|
+
const MAX_MESSAGE_LENGTH = 10000;
|
|
137
|
+
const MAX_QUERY_LENGTH = 2000;
|
|
138
|
+
const FALLBACK_QUERY = 'recent conversation context for this user and agent';
|
|
139
|
+
const self = this;
|
|
140
|
+
const userId = String(this.getNodeParameter('userId', itemIndex, '') || '').trim();
|
|
141
|
+
const agentId = String(this.getNodeParameter('agentId', itemIndex, '') || '').trim();
|
|
142
|
+
const runId = String(this.getNodeParameter('runId', itemIndex, '') || '').trim();
|
|
143
|
+
const defaultQuery = String(this.getNodeParameter('defaultQuery', itemIndex, '') || '').trim();
|
|
144
|
+
const topK = Math.min(Math.max(1, Math.floor(Number(this.getNodeParameter('topK', itemIndex, 10) || 10))), 50);
|
|
145
|
+
const rerank = Boolean(this.getNodeParameter('rerank', itemIndex, false));
|
|
146
|
+
const fieldsInput = String(this.getNodeParameter('fields', itemIndex, '') || '').trim();
|
|
147
|
+
const infer = Boolean(this.getNodeParameter('infer', itemIndex, true));
|
|
148
|
+
if (!userId || !agentId) {
|
|
149
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'User ID and Agent ID are required.');
|
|
150
|
+
}
|
|
151
|
+
function buildScope() {
|
|
152
|
+
const scope = {
|
|
153
|
+
user_id: userId,
|
|
154
|
+
agent_id: agentId,
|
|
155
|
+
};
|
|
156
|
+
if (runId)
|
|
157
|
+
scope.run_id = runId;
|
|
158
|
+
return scope;
|
|
159
|
+
}
|
|
160
|
+
async function searchMessages(query) {
|
|
161
|
+
const normalizedQuery = String(query || '').trim();
|
|
162
|
+
const effectiveQuery = normalizedQuery || FALLBACK_QUERY;
|
|
163
|
+
if (effectiveQuery.length > MAX_QUERY_LENGTH) {
|
|
164
|
+
throw new n8n_workflow_1.NodeOperationError(self.getNode(), `Search query is too long. Maximum supported length is ${MAX_QUERY_LENGTH} characters.`);
|
|
165
|
+
}
|
|
166
|
+
const body = {
|
|
167
|
+
query: effectiveQuery,
|
|
168
|
+
top_k: topK,
|
|
169
|
+
rerank,
|
|
170
|
+
...buildScope(),
|
|
171
|
+
};
|
|
172
|
+
if (fieldsInput) {
|
|
173
|
+
body.fields = fieldsInput
|
|
174
|
+
.split(',')
|
|
175
|
+
.map((field) => field.trim())
|
|
176
|
+
.filter((field) => field.length > 0);
|
|
177
|
+
}
|
|
178
|
+
const response = await GenericFunctions_1.mem0ApiRequest.call(self, 'POST', '/search', body);
|
|
179
|
+
const results = (0, GenericFunctions_1.extractResults)(response);
|
|
180
|
+
return results.map((entry) => toLangchainMessage(entry));
|
|
181
|
+
}
|
|
182
|
+
async function storeMessage(role, content) {
|
|
183
|
+
const normalized = String(content || '').trim();
|
|
184
|
+
if (!normalized)
|
|
185
|
+
return;
|
|
186
|
+
if (normalized.length > MAX_MESSAGE_LENGTH) {
|
|
187
|
+
throw new n8n_workflow_1.NodeOperationError(self.getNode(), `${role === 'user' ? 'User' : 'Assistant'} message is too long. Maximum supported length is ${MAX_MESSAGE_LENGTH} characters.`);
|
|
188
|
+
}
|
|
189
|
+
const body = {
|
|
190
|
+
messages: [{ role, content: normalized }],
|
|
191
|
+
infer,
|
|
192
|
+
metadata: { source: 'n8n_mem0_memory_safe', role },
|
|
193
|
+
...buildScope(),
|
|
194
|
+
};
|
|
195
|
+
await GenericFunctions_1.mem0ApiRequest.call(self, 'POST', '/memories', body);
|
|
196
|
+
}
|
|
197
|
+
const memoryObject = {
|
|
198
|
+
memoryKeys: ['chat_history'],
|
|
199
|
+
chatHistory: {
|
|
200
|
+
async getMessages() {
|
|
201
|
+
return searchMessages(defaultQuery);
|
|
202
|
+
},
|
|
203
|
+
async addUserMessage(message) {
|
|
204
|
+
await storeMessage('user', message);
|
|
205
|
+
},
|
|
206
|
+
async addAIChatMessage(message) {
|
|
207
|
+
await storeMessage('assistant', message);
|
|
208
|
+
},
|
|
209
|
+
// Intentionally non-destructive in safe profile.
|
|
210
|
+
async clear() {
|
|
211
|
+
return;
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
async loadMemoryVariables(values) {
|
|
215
|
+
const query = String(values?.input || values?.query || values?.human_input || defaultQuery || '').trim();
|
|
216
|
+
const messages = await searchMessages(query);
|
|
217
|
+
return { chat_history: messages };
|
|
218
|
+
},
|
|
219
|
+
async saveContext(inputValues, outputValues) {
|
|
220
|
+
const userInput = String(inputValues?.input || inputValues?.query || inputValues?.human_input || inputValues?.chatInput || '').trim();
|
|
221
|
+
const assistantOutput = String(outputValues?.output || outputValues?.response || outputValues?.text || '').trim();
|
|
222
|
+
await storeMessage('user', userInput);
|
|
223
|
+
await storeMessage('assistant', assistantOutput);
|
|
224
|
+
},
|
|
225
|
+
// Intentionally non-destructive in safe profile.
|
|
226
|
+
async clear() {
|
|
227
|
+
return;
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
return { response: memoryObject };
|
|
231
|
+
}
|
|
232
|
+
async execute() {
|
|
233
|
+
const items = this.getInputData();
|
|
234
|
+
return [
|
|
235
|
+
items.map(() => ({
|
|
236
|
+
json: {
|
|
237
|
+
message: 'Mem0 Chat Memory is ready. Connect "ai_memory" to AI Agent memory input.',
|
|
238
|
+
},
|
|
239
|
+
})),
|
|
240
|
+
];
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
exports.Mem0Memory = Mem0Memory;
|
|
244
|
+
//# sourceMappingURL=Mem0Memory.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Mem0Memory.node.js","sourceRoot":"","sources":["../../../nodes/Mem0/Mem0Memory.node.ts"],"names":[],"mappings":";;;AAQA,+CAAuE;AACvE,yDAAoE;AAIpE,IAAI,YAAiB,CAAC;AACtB,IAAI,SAAc,CAAC;AACnB,IAAI,aAAkB,CAAC;AAEvB,CAAC,SAAS,qBAAqB;IAC9B,MAAM,UAAU,GAAG,CAAC,0BAA0B,EAAE,oBAAoB,CAAC,CAAC;IACtE,KAAK,MAAM,UAAU,IAAI,UAAU,EAAE,CAAC;QACrC,IAAI,CAAC;YACJ,MAAM,MA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@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n8n-nodes-mem0-self",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "n8n community node for Mem0 Self-Hosted REST API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"dist/credentials/Mem0SelfHostedApi.credentials.js"
|
|
58
58
|
],
|
|
59
59
|
"nodes": [
|
|
60
|
-
"dist/nodes/Mem0/
|
|
60
|
+
"dist/nodes/Mem0/Mem0Memory.node.js"
|
|
61
61
|
]
|
|
62
62
|
}
|
|
63
63
|
}
|