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

Class ZepMemoryExtended

packages/components/nodes/memory/ZepMemory/ZepMemory.ts:144–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

142}
143
144class ZepMemoryExtended extends ZepMemory implements MemoryMethods {
145 lastN?: number
146 orgId = ''
147
148 constructor(fields: ZepMemoryInput & ZepMemoryExtendedInput) {
149 super(fields)
150 this.lastN = fields.k
151 this.orgId = fields.orgId
152 }
153
154 async loadMemoryVariables(values: InputValues, overrideSessionId = ''): Promise<MemoryVariables> {
155 if (overrideSessionId) {
156 this.sessionId = overrideSessionId
157 }
158 return super.loadMemoryVariables({ ...values, lastN: this.lastN })
159 }
160
161 async saveContext(inputValues: InputValues, outputValues: OutputValues, overrideSessionId = ''): Promise<void> {
162 if (overrideSessionId) {
163 this.sessionId = overrideSessionId
164 }
165 return super.saveContext(inputValues, outputValues)
166 }
167
168 async clear(overrideSessionId = ''): Promise<void> {
169 if (overrideSessionId) {
170 this.sessionId = overrideSessionId
171 }
172 return super.clear()
173 }
174
175 async getChatMessages(
176 overrideSessionId = '',
177 returnBaseMessages = false,
178 prependMessages?: IMessage[]
179 ): Promise<IMessage[] | BaseMessage[]> {
180 const id = overrideSessionId ? overrideSessionId : this.sessionId
181 const memoryVariables = await this.loadMemoryVariables({}, id)
182 const baseMessages = memoryVariables[this.memoryKey]
183 if (prependMessages?.length) {
184 baseMessages.unshift(...(await mapChatMessageToBaseMessage(prependMessages, this.orgId)))
185 }
186 return returnBaseMessages ? baseMessages : convertBaseMessagetoIMessage(baseMessages)
187 }
188
189 async addChatMessages(msgArray: { text: string; type: MessageType }[], overrideSessionId = ''): Promise<void> {
190 const id = overrideSessionId ? overrideSessionId : this.sessionId
191 const input = msgArray.find((msg) => msg.type === 'userMessage')
192 const output = msgArray.find((msg) => msg.type === 'apiMessage')
193 const inputValues = { [this.inputKey ?? 'input']: input?.text }
194 const outputValues = { output: output?.text }
195
196 await this.saveContext(inputValues, outputValues, id)
197 }
198
199 async clearChatMessages(overrideSessionId = ''): Promise<void> {
200 const id = overrideSessionId ? overrideSessionId : this.sessionId
201 await this.clear(id)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected