@@ -15,6 +15,12 @@ interface BufferMemoryExtendedInput {
15
15
chatflowid : string
16
16
}
17
17
18
+ interface NodeFields extends Mem0MemoryInput , Mem0MemoryExtendedInput , BufferMemoryExtendedInput {
19
+ searchOnly : boolean
20
+ useFlowiseChatId : boolean
21
+ input : string
22
+ }
23
+
18
24
class Mem0_Memory implements INode {
19
25
label : string
20
26
name : string
@@ -143,12 +149,12 @@ class Mem0_Memory implements INode {
143
149
]
144
150
}
145
151
146
- async init ( nodeData : INodeData , _ : string , options : ICommonObject ) : Promise < any > {
147
- return await initializeMem0 ( nodeData , options )
152
+ async init ( nodeData : INodeData , input : string , options : ICommonObject ) : Promise < any > {
153
+ return await initializeMem0 ( nodeData , input , options )
148
154
}
149
155
}
150
156
151
- const initializeMem0 = async ( nodeData : INodeData , options : ICommonObject ) : Promise < BaseMem0Memory > => {
157
+ const initializeMem0 = async ( nodeData : INodeData , input : string , options : ICommonObject ) : Promise < BaseMem0Memory > => {
152
158
const initialUserId = nodeData . inputs ?. user_id as string
153
159
const useFlowiseChatId = nodeData . inputs ?. useFlowiseChatId as boolean
154
160
const orgId = options . orgId as string
@@ -184,24 +190,24 @@ const initializeMem0 = async (nodeData: INodeData, options: ICommonObject): Prom
184
190
filters : ( nodeData . inputs ?. filters as Record < string , any > ) || { }
185
191
}
186
192
187
- const obj : Mem0MemoryInput & Mem0MemoryExtendedInput & BufferMemoryExtendedInput & { searchOnly : boolean ; useFlowiseChatId : boolean } =
188
- {
189
- apiKey : apiKey ,
190
- humanPrefix : nodeData . inputs ?. humanPrefix as string ,
191
- aiPrefix : nodeData . inputs ?. aiPrefix as string ,
192
- inputKey : nodeData . inputs ?. inputKey as string ,
193
- sessionId : constructorSessionId ,
194
- mem0Options : mem0Options ,
195
- memoryOptions : memoryOptions ,
196
- separateMessages : false ,
197
- returnMessages : false ,
198
- appDataSource : options . appDataSource as DataSource ,
199
- databaseEntities : options . databaseEntities as IDatabaseEntity ,
200
- chatflowid : options . chatflowid as string ,
201
- searchOnly : ( nodeData . inputs ?. searchOnly as boolean ) || false ,
202
- useFlowiseChatId : useFlowiseChatId ,
203
- orgId : orgId
204
- }
193
+ const obj : NodeFields = {
194
+ apiKey : apiKey ,
195
+ humanPrefix : nodeData . inputs ?. humanPrefix as string ,
196
+ aiPrefix : nodeData . inputs ?. aiPrefix as string ,
197
+ inputKey : nodeData . inputs ?. inputKey as string ,
198
+ sessionId : constructorSessionId ,
199
+ mem0Options : mem0Options ,
200
+ memoryOptions : memoryOptions ,
201
+ separateMessages : false ,
202
+ returnMessages : false ,
203
+ appDataSource : options . appDataSource as DataSource ,
204
+ databaseEntities : options . databaseEntities as IDatabaseEntity ,
205
+ chatflowid : options . chatflowid as string ,
206
+ searchOnly : ( nodeData . inputs ?. searchOnly as boolean ) || false ,
207
+ useFlowiseChatId : useFlowiseChatId ,
208
+ input : input ,
209
+ orgId : orgId
210
+ }
205
211
206
212
return new Mem0MemoryExtended ( obj )
207
213
}
@@ -223,10 +229,9 @@ class Mem0MemoryExtended extends BaseMem0Memory implements MemoryMethods {
223
229
chatflowid : string
224
230
searchOnly : boolean
225
231
useFlowiseChatId : boolean
232
+ input : string
226
233
227
- constructor (
228
- fields : Mem0MemoryInput & Mem0MemoryExtendedInput & BufferMemoryExtendedInput & { searchOnly : boolean ; useFlowiseChatId : boolean }
229
- ) {
234
+ constructor ( fields : NodeFields ) {
230
235
super ( fields )
231
236
this . initialUserId = fields . memoryOptions ?. user_id ?? ''
232
237
this . userId = this . initialUserId
@@ -237,6 +242,7 @@ class Mem0MemoryExtended extends BaseMem0Memory implements MemoryMethods {
237
242
this . chatflowid = fields . chatflowid
238
243
this . searchOnly = fields . searchOnly
239
244
this . useFlowiseChatId = fields . useFlowiseChatId
245
+ this . input = fields . input
240
246
this . orgId = fields . orgId
241
247
}
242
248
@@ -323,11 +329,16 @@ class Mem0MemoryExtended extends BaseMem0Memory implements MemoryMethods {
323
329
if ( prependMessages ?. length ) {
324
330
returnIMessages . unshift ( ...prependMessages )
325
331
// Reverted to original simpler unshift
326
- chatMessage . unshift ( ...( prependMessages as any ) ) // Cast as any
332
+ chatMessage . unshift ( ...( prependMessages as any ) )
327
333
}
328
334
329
335
if ( returnBaseMessages ) {
330
- const memoryVariables = await this . loadMemoryVariables ( { } , overrideUserId )
336
+ const memoryVariables = await this . loadMemoryVariables (
337
+ {
338
+ [ this . inputKey ] : this . input ?? ''
339
+ } ,
340
+ overrideUserId
341
+ )
331
342
const mem0History = memoryVariables [ this . memoryKey ]
332
343
333
344
if ( mem0History && typeof mem0History === 'string' ) {
0 commit comments