@ainetwork/adk-provider-memory-mongodb 0.2.3 → 0.2.4

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/dist/index.js CHANGED
@@ -11,26 +11,108 @@ import {
11
11
  // implements/base.memory.ts
12
12
  import mongoose from "mongoose";
13
13
  import { loggers } from "@ainetwork/adk/utils/logger";
14
- var MongoDBMemory = class {
15
- _isConnected = false;
16
- _uri;
17
- constructor(uri) {
18
- this._uri = uri;
14
+ var MongoDBMemory = class _MongoDBMemory {
15
+ static instance;
16
+ uri;
17
+ connected = false;
18
+ reconnectAttempts = 0;
19
+ maxReconnectAttempts;
20
+ reconnectInterval;
21
+ reconnecting = false;
22
+ connectionConfig;
23
+ eventListenersSetup = false;
24
+ operationTimeoutMS;
25
+ constructor(config) {
26
+ const cfg = typeof config === "string" ? { uri: config } : config;
27
+ this.uri = cfg.uri;
28
+ this.maxReconnectAttempts = cfg.maxReconnectAttempts ?? 5;
29
+ this.reconnectInterval = cfg.reconnectInterval ?? 5e3;
30
+ this.operationTimeoutMS = cfg.operationTimeoutMS ?? 1e4;
31
+ this.connectionConfig = {
32
+ maxPoolSize: cfg.maxPoolSize ?? 1,
33
+ serverSelectionTimeoutMS: cfg.serverSelectionTimeoutMS ?? 3e4,
34
+ socketTimeoutMS: cfg.socketTimeoutMS ?? 45e3,
35
+ connectTimeoutMS: cfg.connectTimeoutMS ?? 3e4,
36
+ bufferCommands: false
37
+ };
38
+ if (!_MongoDBMemory.instance) {
39
+ _MongoDBMemory.instance = this;
40
+ this.setupMongooseEventListeners();
41
+ } else {
42
+ this.connected = _MongoDBMemory.instance.connected;
43
+ this.operationTimeoutMS = _MongoDBMemory.instance.operationTimeoutMS;
44
+ }
45
+ }
46
+ setupMongooseEventListeners() {
47
+ if (this.eventListenersSetup) return;
48
+ this.eventListenersSetup = true;
49
+ mongoose.connection.on("connected", () => {
50
+ this.connected = true;
51
+ this.reconnectAttempts = 0;
52
+ this.reconnecting = false;
53
+ loggers.agent.info("MongoDB connected successfully");
54
+ });
55
+ mongoose.connection.on("disconnected", () => {
56
+ this.connected = false;
57
+ loggers.agent.warn("MongoDB disconnected");
58
+ this.handleDisconnection();
59
+ });
60
+ mongoose.connection.on("error", (error) => {
61
+ this.connected = false;
62
+ loggers.agent.error("MongoDB connection error:", error);
63
+ this.handleDisconnection();
64
+ });
65
+ mongoose.connection.on("reconnected", () => {
66
+ this.connected = true;
67
+ this.reconnectAttempts = 0;
68
+ this.reconnecting = false;
69
+ loggers.agent.info("MongoDB reconnected successfully");
70
+ });
71
+ }
72
+ async handleDisconnection() {
73
+ if (this.reconnecting) {
74
+ return;
75
+ }
76
+ this.reconnecting = true;
77
+ while (this.reconnectAttempts < this.maxReconnectAttempts && !this.isConnected) {
78
+ this.reconnectAttempts++;
79
+ loggers.agent.info(
80
+ `Attempting to reconnect to MongoDB (${this.reconnectAttempts}/${this.maxReconnectAttempts})...`
81
+ );
82
+ try {
83
+ await mongoose.connect(this.uri, this.connectionConfig);
84
+ this.connected = true;
85
+ this.reconnectAttempts = 0;
86
+ this.reconnecting = false;
87
+ loggers.agent.info("MongoDB reconnection successful");
88
+ return;
89
+ } catch (error) {
90
+ loggers.agent.error(
91
+ `Reconnection attempt ${this.reconnectAttempts} failed:`,
92
+ error
93
+ );
94
+ if (this.reconnectAttempts < this.maxReconnectAttempts) {
95
+ await new Promise(
96
+ (resolve) => setTimeout(resolve, this.reconnectInterval)
97
+ );
98
+ }
99
+ }
100
+ }
101
+ this.reconnecting = false;
102
+ if (!this.isConnected) {
103
+ loggers.agent.error(
104
+ `Failed to reconnect to MongoDB after ${this.maxReconnectAttempts} attempts`
105
+ );
106
+ }
19
107
  }
20
108
  async connect() {
21
- if (this._isConnected) {
109
+ if (this.connected) {
22
110
  return;
23
111
  }
24
112
  try {
25
- await mongoose.connect(this._uri, {
26
- maxPoolSize: 1,
27
- serverSelectionTimeoutMS: 3e4,
28
- socketTimeoutMS: 45e3,
29
- connectTimeoutMS: 3e4,
30
- bufferCommands: false
31
- });
32
- this._isConnected = true;
33
- loggers.agent.info("MongoDB connected successfully");
113
+ await mongoose.connect(this.uri, this.connectionConfig);
114
+ this.connected = true;
115
+ this.reconnectAttempts = 0;
34
116
  } catch (error) {
35
117
  loggers.agent.error("Failed to connect to MongoDB:", error);
36
118
  throw error;
@@ -42,15 +124,61 @@ var MongoDBMemory = class {
42
124
  }
43
125
  try {
44
126
  await mongoose.disconnect();
45
- this._isConnected = false;
46
- loggers.agent.info("MongoDB disconnected successfully");
127
+ this.connected = false;
47
128
  } catch (error) {
48
129
  loggers.agent.error("Failed to disconnect from MongoDB:", error);
49
130
  throw error;
50
131
  }
51
132
  }
52
133
  isConnected() {
53
- return this._isConnected;
134
+ return this.connected;
135
+ }
136
+ async ensureConnection() {
137
+ if (!this.isConnected && !this.reconnecting) {
138
+ await this.connect();
139
+ }
140
+ const maxWaitTime = 3e4;
141
+ const startTime = Date.now();
142
+ while (this.reconnecting && Date.now() - startTime < maxWaitTime) {
143
+ await new Promise((resolve) => setTimeout(resolve, 100));
144
+ }
145
+ if (!this.isConnected) {
146
+ throw new Error("MongoDB is not connected and reconnection failed");
147
+ }
148
+ }
149
+ /**
150
+ * Get the operation timeout in milliseconds
151
+ */
152
+ getOperationTimeout() {
153
+ return this.operationTimeoutMS;
154
+ }
155
+ /**
156
+ * Execute a database operation with automatic retry on connection errors
157
+ * Note: Use mongoose's maxTimeMS option in queries for timeout control
158
+ */
159
+ async executeWithRetry(operation, operationName = "Database operation") {
160
+ await this.ensureConnection();
161
+ try {
162
+ return await operation();
163
+ } catch (error) {
164
+ if (error.code === 50 || error.message?.includes("operation exceeded time limit")) {
165
+ loggers.agent.error(`${operationName} exceeded time limit`);
166
+ throw error;
167
+ }
168
+ if (error.name === "MongoNetworkError" || error.name === "MongoServerError" || error.message?.includes("connection") || error.message?.includes("disconnect")) {
169
+ loggers.agent.warn(
170
+ `${operationName} failed due to connection issue, attempting reconnection...`
171
+ );
172
+ await this.ensureConnection();
173
+ try {
174
+ return await operation();
175
+ } catch (retryError) {
176
+ loggers.agent.error(`${operationName} failed after retry:`, retryError);
177
+ throw retryError;
178
+ }
179
+ }
180
+ throw error;
181
+ }
54
182
  }
55
183
  };
56
184
 
@@ -61,113 +189,138 @@ var MongoDBThread = class extends MongoDBMemory {
61
189
  super(uri);
62
190
  }
63
191
  async getThread(userId, threadId) {
64
- const thread = await ThreadModel.findOne({ threadId, userId });
65
- const messages = await MessageModel.find({ threadId, userId }).sort({
66
- timestamp: 1
67
- });
68
- if (!thread) return void 0;
69
- loggers2.agent.debug(`Found ${messages.length} messages for thread ${threadId}`);
70
- const threadObject = {
71
- threadId: thread.threadId,
72
- userId: thread.userId,
73
- type: thread.type,
74
- title: thread.title || "New thread",
75
- messages: []
76
- };
77
- messages.forEach((message) => {
78
- threadObject.messages.push({
79
- messageId: message.messageId,
80
- role: message.role,
81
- content: message.content,
82
- timestamp: message.timestamp,
83
- metadata: message.metadata
192
+ return this.executeWithRetry(async () => {
193
+ const timeout = this.getOperationTimeout();
194
+ const thread = await ThreadModel.findOne({ threadId, userId }).maxTimeMS(timeout);
195
+ const messages = await MessageModel.find({ threadId, userId }).sort({ timestamp: 1 }).maxTimeMS(timeout);
196
+ if (!thread) return void 0;
197
+ loggers2.agent.debug(`Found ${messages.length} messages for thread ${threadId}`);
198
+ const threadObject = {
199
+ threadId: thread.threadId,
200
+ userId: thread.userId,
201
+ type: thread.type,
202
+ title: thread.title || "New thread",
203
+ messages: []
204
+ };
205
+ messages.forEach((message) => {
206
+ threadObject.messages.push({
207
+ messageId: message.messageId,
208
+ role: message.role,
209
+ content: message.content,
210
+ timestamp: message.timestamp,
211
+ metadata: message.metadata
212
+ });
84
213
  });
85
- });
86
- return threadObject;
214
+ return threadObject;
215
+ }, `getThread(${userId}, ${threadId})`);
87
216
  }
88
217
  async createThread(type, userId, threadId, title) {
89
- const now = Date.now();
90
- await ThreadModel.create({
91
- type,
92
- userId,
93
- threadId,
94
- title,
95
- updated_at: now,
96
- created_at: now
97
- });
98
- return { type, userId, threadId, title, messages: [] };
218
+ return this.executeWithRetry(async () => {
219
+ const now = Date.now();
220
+ await ThreadModel.create({
221
+ type,
222
+ userId,
223
+ threadId,
224
+ title,
225
+ updated_at: now,
226
+ created_at: now
227
+ });
228
+ return { type, userId, threadId, title, messages: [] };
229
+ }, `createThread(${userId}, ${threadId})`);
99
230
  }
100
231
  async addMessagesToThread(userId, threadId, messages) {
101
- await ThreadModel.updateOne({ threadId, userId }, {
102
- updated_at: Date.now()
103
- });
104
- for (const message of messages) {
105
- await MessageModel.create({
106
- threadId,
107
- messageId: message.messageId,
108
- userId,
109
- role: message.role,
110
- content: message.content,
111
- timestamp: message.timestamp,
112
- metadata: message.metadata
232
+ return this.executeWithRetry(async () => {
233
+ await ThreadModel.updateOne({ threadId, userId }, {
234
+ updated_at: Date.now()
113
235
  });
114
- }
236
+ for (const message of messages) {
237
+ await MessageModel.create({
238
+ threadId,
239
+ messageId: message.messageId,
240
+ userId,
241
+ role: message.role,
242
+ content: message.content,
243
+ timestamp: message.timestamp,
244
+ metadata: message.metadata
245
+ });
246
+ }
247
+ }, `addMessagesToThread(${userId}, ${threadId})`);
115
248
  }
116
249
  async deleteThread(userId, threadId) {
117
- const messages = await MessageModel.find({ userId, threadId }).sort({
118
- timestamp: 1
119
- });
120
- messages?.forEach((message) => {
121
- message.deleteOne();
122
- });
123
- const thread = await ThreadModel.findOne({ userId, threadId });
124
- thread?.deleteOne();
250
+ return this.executeWithRetry(async () => {
251
+ const timeout = this.getOperationTimeout();
252
+ const messages = await MessageModel.find({ userId, threadId }).sort({ timestamp: 1 }).maxTimeMS(timeout);
253
+ messages?.forEach((message) => {
254
+ message.deleteOne();
255
+ });
256
+ const thread = await ThreadModel.findOne({ userId, threadId }).maxTimeMS(timeout);
257
+ thread?.deleteOne();
258
+ }, `deleteThread(${userId}, ${threadId})`);
125
259
  }
126
260
  async listThreads(userId) {
127
- const threads = await ThreadModel.find({ userId }).sort({
128
- updated_at: -1
129
- });
130
- const data = threads.map((thread) => {
131
- return {
132
- type: thread.type,
133
- userId,
134
- threadId: thread.threadId,
135
- title: thread.title,
136
- updatedAt: thread.updated_at
137
- };
138
- });
139
- return data;
261
+ return this.executeWithRetry(async () => {
262
+ const timeout = this.getOperationTimeout();
263
+ const threads = await ThreadModel.find({ userId }).sort({ updated_at: -1 }).maxTimeMS(timeout);
264
+ const data = threads.map((thread) => {
265
+ return {
266
+ type: thread.type,
267
+ userId,
268
+ threadId: thread.threadId,
269
+ title: thread.title,
270
+ updatedAt: thread.updated_at
271
+ };
272
+ });
273
+ return data;
274
+ }, `listThreads(${userId})`);
140
275
  }
141
276
  };
142
277
 
143
278
  // implements/intent.memory.ts
144
279
  var MongoDBIntent = class extends MongoDBMemory {
145
280
  async getIntent(intentId) {
146
- const intent = await IntentModel.findOne({ id: intentId }).lean();
147
- return intent || void 0;
281
+ return this.executeWithRetry(async () => {
282
+ const timeout = this.getOperationTimeout();
283
+ const intent = await IntentModel.findOne({ id: intentId }).maxTimeMS(timeout).lean();
284
+ return intent || void 0;
285
+ }, `getIntent(${intentId})`);
148
286
  }
149
287
  async getIntentByName(intentName) {
150
- const intent = await IntentModel.findOne({ name: intentName }).lean();
151
- return intent || void 0;
288
+ return this.executeWithRetry(async () => {
289
+ const timeout = this.getOperationTimeout();
290
+ const intent = await IntentModel.findOne({ name: intentName }).maxTimeMS(timeout).lean();
291
+ return intent || void 0;
292
+ }, `getIntentByName(${intentName})`);
152
293
  }
153
294
  async saveIntent(intent) {
154
- await IntentModel.create(intent);
295
+ return this.executeWithRetry(async () => {
296
+ await IntentModel.create(intent);
297
+ }, `saveIntent(${intent.id})`);
155
298
  }
156
299
  async updateIntent(intentId, intent) {
157
- await IntentModel.updateOne({
158
- id: intentId
159
- }, intent);
300
+ return this.executeWithRetry(async () => {
301
+ const timeout = this.getOperationTimeout();
302
+ await IntentModel.updateOne({
303
+ id: intentId
304
+ }, intent).maxTimeMS(timeout);
305
+ }, `updateIntent(${intentId})`);
160
306
  }
161
307
  async deleteIntent(intentId) {
162
- await IntentModel.deleteOne({ id: intentId });
308
+ return this.executeWithRetry(async () => {
309
+ const timeout = this.getOperationTimeout();
310
+ await IntentModel.deleteOne({ id: intentId }).maxTimeMS(timeout);
311
+ }, `deleteIntent(${intentId})`);
163
312
  }
164
313
  async listIntents() {
165
- const intents = await IntentModel.find().lean();
166
- return intents;
314
+ return this.executeWithRetry(async () => {
315
+ const timeout = this.getOperationTimeout();
316
+ const intents = await IntentModel.find().maxTimeMS(timeout).lean();
317
+ return intents;
318
+ }, `listIntents()`);
167
319
  }
168
320
  };
169
321
  export {
170
322
  MongoDBIntent,
323
+ MongoDBMemory,
171
324
  MongoDBThread
172
325
  };
173
326
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../implements/base.memory.ts","../implements/thread.memory.ts","../implements/intent.memory.ts"],"sourcesContent":["import { IMemory } from \"node_modules/@ainetwork/adk/dist/esm/modules/memory/base.memory\";\nimport mongoose from \"mongoose\";\nimport { loggers } from \"@ainetwork/adk/utils/logger\";\n\nexport class MongoDBMemory implements IMemory {\n private _isConnected: boolean = false;\n private _uri: string;\n\n constructor(uri: string) {\n this._uri = uri;\n }\n\n public async connect(): Promise<void> {\n\t\tif (this._isConnected) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n await mongoose.connect(this._uri, {\n maxPoolSize: 1,\n serverSelectionTimeoutMS: 30000,\n socketTimeoutMS: 45000,\n connectTimeoutMS: 30000,\n bufferCommands: false,\n });\n\t\t\tthis._isConnected = true;\n\t\t\tloggers.agent.info(\"MongoDB connected successfully\");\n\t\t} catch (error) {\n\t\t\tloggers.agent.error(\"Failed to connect to MongoDB:\", error);\n\t\t\tthrow error;\n\t\t}\n }\n\n public async disconnect(): Promise<void> {\n\t\tif (!this.isConnected) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tawait mongoose.disconnect();\n\t\t\tthis._isConnected = false;\n\t\t\tloggers.agent.info(\"MongoDB disconnected successfully\");\n\t\t} catch (error) {\n\t\t\tloggers.agent.error(\"Failed to disconnect from MongoDB:\", error);\n\t\t\tthrow error;\n\t\t}\n }\n\n public isConnected(): boolean {\n return this._isConnected;\n }\n}","import type { MessageObject, ThreadMetadata, ThreadObject, ThreadType } from \"@ainetwork/adk/types/memory\";\nimport { MessageRole } from \"@ainetwork/adk/types/memory\";\nimport { IThreadMemory } from \"@ainetwork/adk/modules\";\nimport { MongoDBMemory } from \"./base.memory\";\nimport { ThreadDocument, ThreadModel } from \"../models/threads.model\";\nimport { MessageDocument, MessageModel } from \"../models/messages.model\";\nimport { loggers } from \"@ainetwork/adk/utils/logger\";\n\nexport class MongoDBThread extends MongoDBMemory implements IThreadMemory {\n constructor(uri: string) {\n super(uri);\n }\n\n public async getThread(\n userId: string,\n threadId: string\n ): Promise<ThreadObject | undefined> {\n const thread = await ThreadModel.findOne({ threadId, userId });\n\t\tconst messages = await MessageModel.find({ threadId, userId }).sort({\n\t\t\ttimestamp: 1,\n\t\t});\n\n if (!thread) return undefined;\n\n\t\tloggers.agent.debug(`Found ${messages.length} messages for thread ${threadId}`);\n\n\t\tconst threadObject: ThreadObject = { \n threadId: thread.threadId, \n userId: thread.userId,\n type: thread.type as ThreadType,\n title: thread.title || \"New thread\",\n messages: []\n };\n\t\tmessages.forEach((message: MessageDocument) => {\n\t\t\tthreadObject.messages.push({\n messageId: message.messageId,\n\t\t\t\trole: message.role as MessageRole,\n\t\t\t\tcontent: message.content,\n\t\t\t\ttimestamp: message.timestamp,\n\t\t\t\tmetadata: message.metadata,\n\t\t\t});\n\t\t});\n\n\t\treturn threadObject;\n };\n\n\tpublic async createThread(\n\t\ttype: ThreadType,\n\t\tuserId: string,\n\t\tthreadId: string,\n\t\ttitle: string,\n ): Promise<ThreadObject> {\n const now = Date.now();\n await ThreadModel.create({\n type,\n userId,\n threadId,\n title,\n updated_at: now,\n created_at: now,\n });\n\n return { type, userId, threadId, title, messages: []};\n };\n\n\tpublic async addMessagesToThread(\n userId: string,\n threadId: string,\n messages: MessageObject[]\n ): Promise<void> {\n await ThreadModel.updateOne({ threadId, userId }, {\n updated_at: Date.now(),\n });\n for (const message of messages) {\n await MessageModel.create({\n threadId,\n messageId: message.messageId,\n userId,\n role: message.role,\n content: message.content,\n timestamp: message.timestamp,\n metadata: message.metadata,\n });\n }\n };\n\n\tpublic async deleteThread(userId: string, threadId: string): Promise<void> {\n\t\tconst messages = await MessageModel.find({ userId, threadId }).sort({\n\t\t\ttimestamp: 1,\n\t\t});\n\n\t\tmessages?.forEach((message: MessageDocument) => {\n message.deleteOne();\n\t\t});\n \n const thread = await ThreadModel.findOne({ userId, threadId });\n thread?.deleteOne();\n };\n\n\tpublic async listThreads(userId: string): Promise<ThreadMetadata[]> {\n const threads = await ThreadModel.find({ userId }).sort({\n updated_at: -1,\n });\n const data: ThreadMetadata[] = threads.map((thread: ThreadDocument) => {\n return {\n type: thread.type,\n userId,\n threadId: thread.threadId,\n title: thread.title,\n updatedAt: thread.updated_at\n } as ThreadMetadata;\n })\n return data;\n };\n}","import type { Intent } from \"@ainetwork/adk/types/memory\";\nimport { IIntentMemory } from \"@ainetwork/adk/modules\";\nimport { MongoDBMemory } from \"./base.memory\";\nimport { IntentModel } from \"../models/intent.model\";\n\nexport class MongoDBIntent extends MongoDBMemory implements IIntentMemory {\n public async getIntent(intentId: string): Promise<Intent | undefined> {\n const intent = await IntentModel.findOne({ id: intentId }).lean<Intent>();\n return intent || undefined;\n };\n\n\tpublic async getIntentByName(intentName: string): Promise<Intent | undefined> {\n\t\tconst intent = await IntentModel.findOne({ name: intentName }).lean<Intent>();\n return intent || undefined;\n\t}\n\n\tpublic async saveIntent(intent: Intent): Promise<void> {\n await IntentModel.create(intent);\n };\n\n\tpublic async updateIntent(intentId: string, intent: Intent): Promise<void> {\n await IntentModel.updateOne({\n id: intentId,\n }, intent);\n };\n\n\tpublic async deleteIntent(intentId: string): Promise<void> {\n await IntentModel.deleteOne({ id: intentId });\n };\n\n\tpublic async listIntents(): Promise<Intent[]> {\n const intents = await IntentModel.find().lean<Intent[]>();\n return intents;\n };\n}"],"mappings":";;;;;;;;;;;AACA,OAAO,cAAc;AACrB,SAAS,eAAe;AAEjB,IAAM,gBAAN,MAAuC;AAAA,EACpC,eAAwB;AAAA,EACxB;AAAA,EAER,YAAY,KAAa;AACvB,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,MAAa,UAAyB;AACtC,QAAI,KAAK,cAAc;AACtB;AAAA,IACD;AAEA,QAAI;AACA,YAAM,SAAS,QAAQ,KAAK,MAAM;AAAA,QAChC,aAAa;AAAA,QACb,0BAA0B;AAAA,QAC1B,iBAAiB;AAAA,QACjB,kBAAkB;AAAA,QAClB,gBAAgB;AAAA,MAClB,CAAC;AACJ,WAAK,eAAe;AACpB,cAAQ,MAAM,KAAK,gCAAgC;AAAA,IACpD,SAAS,OAAO;AACf,cAAQ,MAAM,MAAM,iCAAiC,KAAK;AAC1D,YAAM;AAAA,IACP;AAAA,EACA;AAAA,EAEA,MAAa,aAA4B;AACzC,QAAI,CAAC,KAAK,aAAa;AACtB;AAAA,IACD;AAEA,QAAI;AACH,YAAM,SAAS,WAAW;AAC1B,WAAK,eAAe;AACpB,cAAQ,MAAM,KAAK,mCAAmC;AAAA,IACvD,SAAS,OAAO;AACf,cAAQ,MAAM,MAAM,sCAAsC,KAAK;AAC/D,YAAM;AAAA,IACP;AAAA,EACA;AAAA,EAEO,cAAuB;AAC5B,WAAO,KAAK;AAAA,EACd;AACF;;;AC7CA,SAAS,WAAAA,gBAAe;AAEjB,IAAM,gBAAN,cAA4B,cAAuC;AAAA,EACxE,YAAY,KAAa;AACvB,UAAM,GAAG;AAAA,EACX;AAAA,EAEA,MAAa,UACX,QACA,UACmC;AACnC,UAAM,SAAS,MAAM,YAAY,QAAQ,EAAE,UAAU,OAAO,CAAC;AAC/D,UAAM,WAAW,MAAM,aA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;AAAA,EAED,MAAa,cAAiC;AAC3C,UAAM,UAAU,MAAM,YAAY,KAAK,EAAE,KAAe;AACxD,WAAO;AAAA,EACT;AACF;","names":["loggers"]}
1
+ {"version":3,"sources":["../implements/base.memory.ts","../implements/thread.memory.ts","../implements/intent.memory.ts"],"sourcesContent":["import { IMemory } from \"node_modules/@ainetwork/adk/dist/esm/modules/memory/base.memory\";\nimport mongoose from \"mongoose\";\nimport { loggers } from \"@ainetwork/adk/utils/logger\";\n\nexport interface MongoDBMemoryConfig {\n uri: string;\n maxReconnectAttempts?: number;\n reconnectInterval?: number;\n maxPoolSize?: number;\n serverSelectionTimeoutMS?: number;\n socketTimeoutMS?: number;\n connectTimeoutMS?: number;\n operationTimeoutMS?: number; // Timeout for database operations\n}\n\nexport class MongoDBMemory implements IMemory {\n private static instance: MongoDBMemory;\n private uri: string;\n private connected: boolean = false;\n private reconnectAttempts: number = 0;\n private maxReconnectAttempts: number;\n private reconnectInterval: number;\n private reconnecting: boolean = false;\n private connectionConfig: mongoose.ConnectOptions;\n private eventListenersSetup: boolean = false;\n private operationTimeoutMS: number;\n\n constructor(config: string | MongoDBMemoryConfig) {\n const cfg = typeof config === 'string' ? { uri: config } : config;\n\n this.uri = cfg.uri;\n this.maxReconnectAttempts = cfg.maxReconnectAttempts ?? 5;\n this.reconnectInterval = cfg.reconnectInterval ?? 5000;\n this.operationTimeoutMS = cfg.operationTimeoutMS ?? 10000; // Default 10 seconds\n this.connectionConfig = {\n maxPoolSize: cfg.maxPoolSize ?? 1,\n serverSelectionTimeoutMS: cfg.serverSelectionTimeoutMS ?? 30000,\n socketTimeoutMS: cfg.socketTimeoutMS ?? 45000,\n connectTimeoutMS: cfg.connectTimeoutMS ?? 30000,\n bufferCommands: false,\n };\n\n if (!MongoDBMemory.instance) {\n MongoDBMemory.instance = this;\n this.setupMongooseEventListeners();\n } else {\n // Use existing instance's connection state\n this.connected = MongoDBMemory.instance.connected;\n this.operationTimeoutMS = MongoDBMemory.instance.operationTimeoutMS;\n }\n }\n\n private setupMongooseEventListeners(): void {\n if (this.eventListenersSetup) return;\n\n this.eventListenersSetup = true;\n\n mongoose.connection.on(\"connected\", () => {\n this.connected = true;\n this.reconnectAttempts = 0;\n this.reconnecting = false;\n loggers.agent.info(\"MongoDB connected successfully\");\n });\n\n mongoose.connection.on(\"disconnected\", () => {\n this.connected = false;\n loggers.agent.warn(\"MongoDB disconnected\");\n this.handleDisconnection();\n });\n\n mongoose.connection.on(\"error\", (error) => {\n this.connected = false;\n loggers.agent.error(\"MongoDB connection error:\", error);\n this.handleDisconnection();\n });\n\n mongoose.connection.on(\"reconnected\", () => {\n this.connected = true;\n this.reconnectAttempts = 0;\n this.reconnecting = false;\n loggers.agent.info(\"MongoDB reconnected successfully\");\n });\n }\n\n private async handleDisconnection(): Promise<void> {\n if (this.reconnecting) {\n return;\n }\n\n this.reconnecting = true;\n\n while (this.reconnectAttempts < this.maxReconnectAttempts && !this.isConnected) {\n this.reconnectAttempts++;\n loggers.agent.info(\n `Attempting to reconnect to MongoDB (${this.reconnectAttempts}/${this.maxReconnectAttempts})...`\n );\n\n try {\n await mongoose.connect(this.uri, this.connectionConfig);\n this.connected = true;\n this.reconnectAttempts = 0;\n this.reconnecting = false;\n loggers.agent.info(\"MongoDB reconnection successful\");\n return;\n } catch (error) {\n loggers.agent.error(\n `Reconnection attempt ${this.reconnectAttempts} failed:`,\n error\n );\n\n if (this.reconnectAttempts < this.maxReconnectAttempts) {\n await new Promise((resolve) =>\n setTimeout(resolve, this.reconnectInterval)\n );\n }\n }\n }\n\n this.reconnecting = false;\n\n if (!this.isConnected) {\n loggers.agent.error(\n `Failed to reconnect to MongoDB after ${this.maxReconnectAttempts} attempts`\n );\n }\n }\n\n public async connect(): Promise<void> {\n if (this.connected) {\n return;\n }\n\n try {\n await mongoose.connect(this.uri, this.connectionConfig);\n this.connected = true;\n this.reconnectAttempts = 0;\n } catch (error) {\n loggers.agent.error(\"Failed to connect to MongoDB:\", error);\n throw error;\n }\n }\n\n public async disconnect(): Promise<void> {\n if (!this.isConnected) {\n return;\n }\n\n try {\n await mongoose.disconnect();\n this.connected = false;\n } catch (error) {\n loggers.agent.error(\"Failed to disconnect from MongoDB:\", error);\n throw error;\n }\n }\n\n public isConnected(): boolean {\n return this.connected;\n }\n\n private async ensureConnection(): Promise<void> {\n if (!this.isConnected && !this.reconnecting) {\n await this.connect();\n }\n\n // Wait for reconnection if in progress\n const maxWaitTime = 30000; // 30 seconds\n const startTime = Date.now();\n while (this.reconnecting && Date.now() - startTime < maxWaitTime) {\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n\n if (!this.isConnected) {\n throw new Error(\"MongoDB is not connected and reconnection failed\");\n }\n }\n\n /**\n * Get the operation timeout in milliseconds\n */\n protected getOperationTimeout(): number {\n return this.operationTimeoutMS;\n }\n\n /**\n * Execute a database operation with automatic retry on connection errors\n * Note: Use mongoose's maxTimeMS option in queries for timeout control\n */\n protected async executeWithRetry<T>(\n operation: () => Promise<T>,\n operationName: string = \"Database operation\"\n ): Promise<T> {\n await this.ensureConnection();\n\n try {\n return await operation();\n } catch (error: any) {\n // Check if it's a timeout error from MongoDB\n if (error.code === 50 || error.message?.includes(\"operation exceeded time limit\")) {\n loggers.agent.error(`${operationName} exceeded time limit`);\n throw error;\n }\n\n // Check if it's a connection-related error\n if (\n error.name === \"MongoNetworkError\" ||\n error.name === \"MongoServerError\" ||\n error.message?.includes(\"connection\") ||\n error.message?.includes(\"disconnect\")\n ) {\n loggers.agent.warn(\n `${operationName} failed due to connection issue, attempting reconnection...`\n );\n\n await this.ensureConnection();\n\n // Retry the operation once after reconnection\n try {\n return await operation();\n } catch (retryError: any) {\n loggers.agent.error(`${operationName} failed after retry:`, retryError);\n throw retryError;\n }\n }\n\n // If it's not a connection error, just throw it\n throw error;\n }\n }\n}\n","import type { MessageObject, ThreadMetadata, ThreadObject, ThreadType } from \"@ainetwork/adk/types/memory\";\nimport { MessageRole } from \"@ainetwork/adk/types/memory\";\nimport { IThreadMemory } from \"@ainetwork/adk/modules\";\nimport { MongoDBMemory } from \"./base.memory\";\nimport { ThreadDocument, ThreadModel } from \"../models/threads.model\";\nimport { MessageDocument, MessageModel } from \"../models/messages.model\";\nimport { loggers } from \"@ainetwork/adk/utils/logger\";\n\nexport class MongoDBThread extends MongoDBMemory implements IThreadMemory {\n constructor(uri: string) {\n super(uri);\n }\n\n public async getThread(\n userId: string,\n threadId: string\n ): Promise<ThreadObject | undefined> {\n return this.executeWithRetry(async () => {\n const timeout = this.getOperationTimeout();\n const thread = await ThreadModel.findOne({ threadId, userId }).maxTimeMS(timeout);\n const messages = await MessageModel.find({ threadId, userId })\n .sort({ timestamp: 1 })\n .maxTimeMS(timeout);\n\n if (!thread) return undefined;\n\n loggers.agent.debug(`Found ${messages.length} messages for thread ${threadId}`);\n\n const threadObject: ThreadObject = {\n threadId: thread.threadId,\n userId: thread.userId,\n type: thread.type as ThreadType,\n title: thread.title || \"New thread\",\n messages: []\n };\n messages.forEach((message: MessageDocument) => {\n threadObject.messages.push({\n messageId: message.messageId,\n role: message.role as MessageRole,\n content: message.content,\n timestamp: message.timestamp,\n metadata: message.metadata,\n });\n });\n\n return threadObject;\n }, `getThread(${userId}, ${threadId})`);\n };\n\n public async createThread(\n type: ThreadType,\n userId: string,\n threadId: string,\n title: string,\n ): Promise<ThreadObject> {\n return this.executeWithRetry(async () => {\n const now = Date.now();\n await ThreadModel.create({\n type,\n userId,\n threadId,\n title,\n updated_at: now,\n created_at: now,\n });\n\n return { type, userId, threadId, title, messages: []};\n }, `createThread(${userId}, ${threadId})`);\n };\n\n public async addMessagesToThread(\n userId: string,\n threadId: string,\n messages: MessageObject[]\n ): Promise<void> {\n return this.executeWithRetry(async () => {\n await ThreadModel.updateOne({ threadId, userId }, {\n updated_at: Date.now(),\n });\n for (const message of messages) {\n await MessageModel.create({\n threadId,\n messageId: message.messageId,\n userId,\n role: message.role,\n content: message.content,\n timestamp: message.timestamp,\n metadata: message.metadata,\n });\n }\n }, `addMessagesToThread(${userId}, ${threadId})`);\n };\n\n public async deleteThread(userId: string, threadId: string): Promise<void> {\n return this.executeWithRetry(async () => {\n const timeout = this.getOperationTimeout();\n const messages = await MessageModel.find({ userId, threadId })\n .sort({ timestamp: 1 })\n .maxTimeMS(timeout);\n\n messages?.forEach((message: MessageDocument) => {\n message.deleteOne();\n });\n\n const thread = await ThreadModel.findOne({ userId, threadId }).maxTimeMS(timeout);\n thread?.deleteOne();\n }, `deleteThread(${userId}, ${threadId})`);\n };\n\n public async listThreads(userId: string): Promise<ThreadMetadata[]> {\n return this.executeWithRetry(async () => {\n const timeout = this.getOperationTimeout();\n const threads = await ThreadModel.find({ userId })\n .sort({ updated_at: -1 })\n .maxTimeMS(timeout);\n const data: ThreadMetadata[] = threads.map((thread: ThreadDocument) => {\n return {\n type: thread.type,\n userId,\n threadId: thread.threadId,\n title: thread.title,\n updatedAt: thread.updated_at\n } as ThreadMetadata;\n })\n return data;\n }, `listThreads(${userId})`);\n };\n}\n","import type { Intent } from \"@ainetwork/adk/types/memory\";\nimport { IIntentMemory } from \"@ainetwork/adk/modules\";\nimport { MongoDBMemory } from \"./base.memory\";\nimport { IntentModel } from \"../models/intent.model\";\n\nexport class MongoDBIntent extends MongoDBMemory implements IIntentMemory {\n public async getIntent(intentId: string): Promise<Intent | undefined> {\n return this.executeWithRetry(async () => {\n const timeout = this.getOperationTimeout();\n const intent = await IntentModel.findOne({ id: intentId })\n .maxTimeMS(timeout)\n .lean<Intent>();\n return intent || undefined;\n }, `getIntent(${intentId})`);\n };\n\n public async getIntentByName(intentName: string): Promise<Intent | undefined> {\n return this.executeWithRetry(async () => {\n const timeout = this.getOperationTimeout();\n const intent = await IntentModel.findOne({ name: intentName })\n .maxTimeMS(timeout)\n .lean<Intent>();\n return intent || undefined;\n }, `getIntentByName(${intentName})`);\n }\n\n public async saveIntent(intent: Intent): Promise<void> {\n return this.executeWithRetry(async () => {\n await IntentModel.create(intent);\n }, `saveIntent(${intent.id})`);\n };\n\n public async updateIntent(intentId: string, intent: Intent): Promise<void> {\n return this.executeWithRetry(async () => {\n const timeout = this.getOperationTimeout();\n await IntentModel.updateOne({\n id: intentId,\n }, intent).maxTimeMS(timeout);\n }, `updateIntent(${intentId})`);\n };\n\n public async deleteIntent(intentId: string): Promise<void> {\n return this.executeWithRetry(async () => {\n const timeout = this.getOperationTimeout();\n await IntentModel.deleteOne({ id: intentId }).maxTimeMS(timeout);\n }, `deleteIntent(${intentId})`);\n };\n\n public async listIntents(): Promise<Intent[]> {\n return this.executeWithRetry(async () => {\n const timeout = this.getOperationTimeout();\n const intents = await IntentModel.find()\n .maxTimeMS(timeout)\n .lean<Intent[]>();\n return intents;\n }, `listIntents()`);\n };\n}\n"],"mappings":";;;;;;;;;;;AACA,OAAO,cAAc;AACrB,SAAS,eAAe;AAajB,IAAM,gBAAN,MAAM,eAAiC;AAAA,EAC5C,OAAe;AAAA,EACP;AAAA,EACA,YAAqB;AAAA,EACrB,oBAA4B;AAAA,EAC5B;AAAA,EACA;AAAA,EACA,eAAwB;AAAA,EACxB;AAAA,EACA,sBAA+B;AAAA,EAC/B;AAAA,EAER,YAAY,QAAsC;AAChD,UAAM,MAAM,OAAO,WAAW,WAAW,EAAE,KAAK,OAAO,IAAI;AAE3D,SAAK,MAAM,IAAI;AACf,SAAK,uBAAuB,IAAI,wBAAwB;AACxD,SAAK,oBAAoB,IAAI,qBAAqB;AAClD,SAAK,qBAAqB,IAAI,sBAAsB;AACpD,SAAK,mBAAmB;AAAA,MACtB,aAAa,IAAI,eAAe;AAAA,MAChC,0BAA0B,IAAI,4BAA4B;AAAA,MAC1D,iBAAiB,IAAI,mBAAmB;AAAA,MACxC,kBAAkB,IAAI,oBAAoB;AAAA,MAC1C,gBAAgB;AAAA,IAClB;AAEA,QAAI,CAAC,eAAc,UAAU;AAC3B,qBAAc,WAAW;AACzB,WAAK,4BAA4B;AAAA,IACnC,OAAO;AAEL,WAAK,YAAY,eAAc,SAAS;AACxC,WAAK,qBA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