@@ -117,14 +117,20 @@ const initalizeDynamoDB = async (nodeData: INodeData, options: ICommonObject): P
117
117
memoryKey : memoryKey ?? 'chat_history' ,
118
118
chatHistory : dynamoDb ,
119
119
sessionId,
120
- dynamodbClient : client
120
+ dynamodbClient : client ,
121
+ tableName,
122
+ partitionKey,
123
+ dynamoKey : { [ partitionKey ] : { S : sessionId } }
121
124
} )
122
125
return memory
123
126
}
124
127
125
128
interface BufferMemoryExtendedInput {
126
129
dynamodbClient : DynamoDBClient
127
130
sessionId : string
131
+ tableName : string
132
+ partitionKey : string
133
+ dynamoKey : Record < string , AttributeValue >
128
134
}
129
135
130
136
interface DynamoDBSerializedChatMessage {
@@ -142,18 +148,25 @@ interface DynamoDBSerializedChatMessage {
142
148
}
143
149
144
150
class BufferMemoryExtended extends FlowiseMemory implements MemoryMethods {
151
+ private tableName = ''
152
+ private partitionKey = ''
153
+ private dynamoKey : Record < string , AttributeValue >
154
+ private messageAttributeName : string
145
155
sessionId = ''
146
156
dynamodbClient : DynamoDBClient
147
157
148
158
constructor ( fields : BufferMemoryInput & BufferMemoryExtendedInput ) {
149
159
super ( fields )
150
160
this . sessionId = fields . sessionId
151
161
this . dynamodbClient = fields . dynamodbClient
162
+ this . tableName = fields . tableName
163
+ this . partitionKey = fields . partitionKey
164
+ this . dynamoKey = fields . dynamoKey
152
165
}
153
166
154
167
overrideDynamoKey ( overrideSessionId = '' ) {
155
- const existingDynamoKey = ( this as any ) . dynamoKey
156
- const partitionKey = ( this as any ) . partitionKey
168
+ const existingDynamoKey = this . dynamoKey
169
+ const partitionKey = this . partitionKey
157
170
158
171
let newDynamoKey : Record < string , AttributeValue > = { }
159
172
@@ -209,9 +222,9 @@ class BufferMemoryExtended extends FlowiseMemory implements MemoryMethods {
209
222
async getChatMessages ( overrideSessionId = '' , returnBaseMessages = false ) : Promise < IMessage [ ] | BaseMessage [ ] > {
210
223
if ( ! this . dynamodbClient ) return [ ]
211
224
212
- const dynamoKey = overrideSessionId ? this . overrideDynamoKey ( overrideSessionId ) : ( this as any ) . dynamoKey
213
- const tableName = ( this as any ) . tableName
214
- const messageAttributeName = ( this as any ) . messageAttributeName
225
+ const dynamoKey = overrideSessionId ? this . overrideDynamoKey ( overrideSessionId ) : this . dynamoKey
226
+ const tableName = this . tableName
227
+ const messageAttributeName = this . messageAttributeName
215
228
216
229
const params : GetItemCommandInput = {
217
230
TableName : tableName ,
@@ -236,9 +249,9 @@ class BufferMemoryExtended extends FlowiseMemory implements MemoryMethods {
236
249
async addChatMessages ( msgArray : { text : string ; type : MessageType } [ ] , overrideSessionId = '' ) : Promise < void > {
237
250
if ( ! this . dynamodbClient ) return
238
251
239
- const dynamoKey = overrideSessionId ? this . overrideDynamoKey ( overrideSessionId ) : ( this as any ) . dynamoKey
240
- const tableName = ( this as any ) . tableName
241
- const messageAttributeName = ( this as any ) . messageAttributeName
252
+ const dynamoKey = overrideSessionId ? this . overrideDynamoKey ( overrideSessionId ) : this . dynamoKey
253
+ const tableName = this . tableName
254
+ const messageAttributeName = this . messageAttributeName
242
255
243
256
const input = msgArray . find ( ( msg ) => msg . type === 'userMessage' )
244
257
const output = msgArray . find ( ( msg ) => msg . type === 'apiMessage' )
@@ -259,8 +272,8 @@ class BufferMemoryExtended extends FlowiseMemory implements MemoryMethods {
259
272
async clearChatMessages ( overrideSessionId = '' ) : Promise < void > {
260
273
if ( ! this . dynamodbClient ) return
261
274
262
- const dynamoKey = overrideSessionId ? this . overrideDynamoKey ( overrideSessionId ) : ( this as any ) . dynamoKey
263
- const tableName = ( this as any ) . tableName
275
+ const dynamoKey = overrideSessionId ? this . overrideDynamoKey ( overrideSessionId ) : this . dynamoKey
276
+ const tableName = this . tableName
264
277
265
278
const params : DeleteItemCommandInput = {
266
279
TableName : tableName ,
0 commit comments