MCPcopy Index your code
hub / github.com/FlowiseAI/Flowise / Mem0MemoryExtended

Class Mem0MemoryExtended

packages/components/nodes/memory/Mem0/Mem0.ts:221–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

219}
220
221class Mem0MemoryExtended extends BaseMem0Memory implements MemoryMethods {
222 initialUserId: string
223 userId: string
224 orgId: string
225 memoryKey: string
226 inputKey: string
227 appDataSource: DataSource
228 databaseEntities: IDatabaseEntity
229 chatflowid: string
230 searchOnly: boolean
231 useFlowiseChatId: boolean
232 input: string
233
234 constructor(fields: NodeFields) {
235 super(fields)
236 this.initialUserId = fields.memoryOptions?.user_id ?? ''
237 this.userId = this.initialUserId
238 this.memoryKey = 'history'
239 this.inputKey = fields.inputKey ?? 'input'
240 this.appDataSource = fields.appDataSource
241 this.databaseEntities = fields.databaseEntities
242 this.chatflowid = fields.chatflowid
243 this.searchOnly = fields.searchOnly
244 this.useFlowiseChatId = fields.useFlowiseChatId
245 this.input = fields.input
246 this.orgId = fields.orgId
247 }
248
249 // Selects Mem0 user_id based on toggle state (Flowise chat ID or input field)
250 private getEffectiveUserId(overrideUserId?: string): string {
251 let effectiveUserId: string | undefined
252
253 if (this.useFlowiseChatId) {
254 if (overrideUserId) {
255 effectiveUserId = overrideUserId
256 } else {
257 throw new Error('Mem0: "Use Flowise Chat ID" is ON, but no runtime chat ID (overrideUserId) was provided.')
258 }
259 } else {
260 // If toggle is OFF, ALWAYS use the ID from the input field.
261 effectiveUserId = this.initialUserId
262 }
263
264 // This check is now primarily for the case where the toggle is OFF and the initialUserId was somehow empty (should be caught by init validation).
265 if (!effectiveUserId) {
266 throw new Error('Mem0: Could not determine a valid User ID for the operation. Check User ID input field.')
267 }
268 return effectiveUserId
269 }
270
271 async loadMemoryVariables(values: InputValues, overrideUserId = ''): Promise<MemoryVariables> {
272 const effectiveUserId = this.getEffectiveUserId(overrideUserId)
273 this.userId = effectiveUserId
274 if (this.memoryOptions) {
275 this.memoryOptions.user_id = effectiveUserId
276 }
277 return super.loadMemoryVariables(values)
278 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected