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

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
@@ -1,3 +1,6 @@
1
+ import {
2
+ AgentModel
3
+ } from "./chunk-OWGGE5EW.js";
1
4
  import {
2
5
  IntentModel
3
6
  } from "./chunk-YFW7JXII.js";
@@ -10,7 +13,182 @@ import {
10
13
 
11
14
  // implements/base.memory.ts
12
15
  import mongoose from "mongoose";
16
+ import { loggers as loggers2 } from "@ainetwork/adk/utils/logger";
17
+
18
+ // implements/agent.memory.ts
19
+ var MongoDBAgent = class {
20
+ executeWithRetry;
21
+ getOperationTimeout;
22
+ constructor(executeWithRetry, getOperationTimeout) {
23
+ this.executeWithRetry = executeWithRetry;
24
+ this.getOperationTimeout = getOperationTimeout;
25
+ }
26
+ async getAgentPrompt() {
27
+ return this.executeWithRetry(async () => {
28
+ const timeout = this.getOperationTimeout();
29
+ const metadata = await AgentModel.findOne({
30
+ id: "agent_metadata"
31
+ }).maxTimeMS(timeout).lean();
32
+ return metadata?.agent_prompt || "";
33
+ }, "getAgentPrompt()");
34
+ }
35
+ async updateAgentPrompt(prompt) {
36
+ return this.executeWithRetry(async () => {
37
+ const timeout = this.getOperationTimeout();
38
+ await AgentModel.updateOne({
39
+ id: "agent_metadata"
40
+ }, { "agent_prompt": prompt }).maxTimeMS(timeout);
41
+ }, "updateAgentPrompt()");
42
+ }
43
+ };
44
+
45
+ // implements/intent.memory.ts
46
+ var MongoDBIntent = class {
47
+ executeWithRetry;
48
+ getOperationTimeout;
49
+ constructor(executeWithRetry, getOperationTimeout) {
50
+ this.executeWithRetry = executeWithRetry;
51
+ this.getOperationTimeout = getOperationTimeout;
52
+ }
53
+ async getIntent(intentId) {
54
+ return this.executeWithRetry(async () => {
55
+ const timeout = this.getOperationTimeout();
56
+ const intent = await IntentModel.findOne({ id: intentId }).maxTimeMS(timeout).lean();
57
+ return intent || void 0;
58
+ }, `getIntent(${intentId})`);
59
+ }
60
+ async getIntentByName(intentName) {
61
+ return this.executeWithRetry(async () => {
62
+ const timeout = this.getOperationTimeout();
63
+ const intent = await IntentModel.findOne({ name: intentName }).maxTimeMS(timeout).lean();
64
+ return intent || void 0;
65
+ }, `getIntentByName(${intentName})`);
66
+ }
67
+ async saveIntent(intent) {
68
+ return this.executeWithRetry(async () => {
69
+ await IntentModel.create(intent);
70
+ }, `saveIntent(${intent.id})`);
71
+ }
72
+ async updateIntent(intentId, intent) {
73
+ return this.executeWithRetry(async () => {
74
+ const timeout = this.getOperationTimeout();
75
+ await IntentModel.updateOne({
76
+ id: intentId
77
+ }, intent).maxTimeMS(timeout);
78
+ }, `updateIntent(${intentId})`);
79
+ }
80
+ async deleteIntent(intentId) {
81
+ return this.executeWithRetry(async () => {
82
+ const timeout = this.getOperationTimeout();
83
+ await IntentModel.deleteOne({ id: intentId }).maxTimeMS(timeout);
84
+ }, `deleteIntent(${intentId})`);
85
+ }
86
+ async listIntents() {
87
+ return this.executeWithRetry(async () => {
88
+ const timeout = this.getOperationTimeout();
89
+ const intents = await IntentModel.find().maxTimeMS(timeout).lean();
90
+ return intents;
91
+ }, `listIntents()`);
92
+ }
93
+ };
94
+
95
+ // implements/thread.memory.ts
13
96
  import { loggers } from "@ainetwork/adk/utils/logger";
97
+ var MongoDBThread = class {
98
+ executeWithRetry;
99
+ getOperationTimeout;
100
+ constructor(executeWithRetry, getOperationTimeout) {
101
+ this.executeWithRetry = executeWithRetry;
102
+ this.getOperationTimeout = getOperationTimeout;
103
+ }
104
+ async getThread(userId, threadId) {
105
+ return this.executeWithRetry(async () => {
106
+ const timeout = this.getOperationTimeout();
107
+ const thread = await ThreadModel.findOne({ threadId, userId }).maxTimeMS(timeout);
108
+ const messages = await MessageModel.find({ threadId, userId }).sort({ timestamp: 1 }).maxTimeMS(timeout);
109
+ if (!thread) return void 0;
110
+ loggers.agent.debug(`Found ${messages.length} messages for thread ${threadId}`);
111
+ const threadObject = {
112
+ threadId: thread.threadId,
113
+ userId: thread.userId,
114
+ type: thread.type,
115
+ title: thread.title || "New thread",
116
+ messages: []
117
+ };
118
+ messages.forEach((message) => {
119
+ threadObject.messages.push({
120
+ messageId: message.messageId,
121
+ role: message.role,
122
+ content: message.content,
123
+ timestamp: message.timestamp,
124
+ metadata: message.metadata
125
+ });
126
+ });
127
+ return threadObject;
128
+ }, `getThread(${userId}, ${threadId})`);
129
+ }
130
+ async createThread(type, userId, threadId, title) {
131
+ return this.executeWithRetry(async () => {
132
+ const now = Date.now();
133
+ await ThreadModel.create({
134
+ type,
135
+ userId,
136
+ threadId,
137
+ title,
138
+ updated_at: now,
139
+ created_at: now
140
+ });
141
+ return { type, userId, threadId, title, messages: [] };
142
+ }, `createThread(${userId}, ${threadId})`);
143
+ }
144
+ async addMessagesToThread(userId, threadId, messages) {
145
+ return this.executeWithRetry(async () => {
146
+ await ThreadModel.updateOne({ threadId, userId }, {
147
+ updated_at: Date.now()
148
+ });
149
+ for (const message of messages) {
150
+ await MessageModel.create({
151
+ threadId,
152
+ messageId: message.messageId,
153
+ userId,
154
+ role: message.role,
155
+ content: message.content,
156
+ timestamp: message.timestamp,
157
+ metadata: message.metadata
158
+ });
159
+ }
160
+ }, `addMessagesToThread(${userId}, ${threadId})`);
161
+ }
162
+ async deleteThread(userId, threadId) {
163
+ return this.executeWithRetry(async () => {
164
+ const timeout = this.getOperationTimeout();
165
+ const messages = await MessageModel.find({ userId, threadId }).sort({ timestamp: 1 }).maxTimeMS(timeout);
166
+ messages?.forEach((message) => {
167
+ message.deleteOne();
168
+ });
169
+ const thread = await ThreadModel.findOne({ userId, threadId }).maxTimeMS(timeout);
170
+ thread?.deleteOne();
171
+ }, `deleteThread(${userId}, ${threadId})`);
172
+ }
173
+ async listThreads(userId) {
174
+ return this.executeWithRetry(async () => {
175
+ const timeout = this.getOperationTimeout();
176
+ const threads = await ThreadModel.find({ userId }).sort({ updated_at: -1 }).maxTimeMS(timeout);
177
+ const data = threads.map((thread) => {
178
+ return {
179
+ type: thread.type,
180
+ userId,
181
+ threadId: thread.threadId,
182
+ title: thread.title,
183
+ updatedAt: thread.updated_at
184
+ };
185
+ });
186
+ return data;
187
+ }, `listThreads(${userId})`);
188
+ }
189
+ };
190
+
191
+ // implements/base.memory.ts
14
192
  var MongoDBMemory = class _MongoDBMemory {
15
193
  static instance;
16
194
  uri;
@@ -22,6 +200,9 @@ var MongoDBMemory = class _MongoDBMemory {
22
200
  connectionConfig;
23
201
  eventListenersSetup = false;
24
202
  operationTimeoutMS;
203
+ agentMemory;
204
+ intentMemory;
205
+ threadMemory;
25
206
  constructor(config) {
26
207
  const cfg = typeof config === "string" ? { uri: config } : config;
27
208
  this.uri = cfg.uri;
@@ -42,6 +223,27 @@ var MongoDBMemory = class _MongoDBMemory {
42
223
  this.connected = _MongoDBMemory.instance.connected;
43
224
  this.operationTimeoutMS = _MongoDBMemory.instance.operationTimeoutMS;
44
225
  }
226
+ this.agentMemory = new MongoDBAgent(
227
+ this.executeWithRetry.bind(this),
228
+ this.getOperationTimeout.bind(this)
229
+ );
230
+ this.threadMemory = new MongoDBThread(
231
+ this.executeWithRetry.bind(this),
232
+ this.getOperationTimeout.bind(this)
233
+ );
234
+ this.intentMemory = new MongoDBIntent(
235
+ this.executeWithRetry.bind(this),
236
+ this.getOperationTimeout.bind(this)
237
+ );
238
+ }
239
+ getAgentMemory() {
240
+ return this.agentMemory;
241
+ }
242
+ getThreadMemory() {
243
+ return this.threadMemory;
244
+ }
245
+ getIntentMemory() {
246
+ return this.intentMemory;
45
247
  }
46
248
  setupMongooseEventListeners() {
47
249
  if (this.eventListenersSetup) return;
@@ -50,23 +252,23 @@ var MongoDBMemory = class _MongoDBMemory {
50
252
  this.connected = true;
51
253
  this.reconnectAttempts = 0;
52
254
  this.reconnecting = false;
53
- loggers.agent.info("MongoDB connected successfully");
255
+ loggers2.agent.info("MongoDB connected successfully");
54
256
  });
55
257
  mongoose.connection.on("disconnected", () => {
56
258
  this.connected = false;
57
- loggers.agent.warn("MongoDB disconnected");
259
+ loggers2.agent.warn("MongoDB disconnected");
58
260
  this.handleDisconnection();
59
261
  });
60
262
  mongoose.connection.on("error", (error) => {
61
263
  this.connected = false;
62
- loggers.agent.error("MongoDB connection error:", error);
264
+ loggers2.agent.error("MongoDB connection error:", error);
63
265
  this.handleDisconnection();
64
266
  });
65
267
  mongoose.connection.on("reconnected", () => {
66
268
  this.connected = true;
67
269
  this.reconnectAttempts = 0;
68
270
  this.reconnecting = false;
69
- loggers.agent.info("MongoDB reconnected successfully");
271
+ loggers2.agent.info("MongoDB reconnected successfully");
70
272
  });
71
273
  }
72
274
  async handleDisconnection() {
@@ -76,7 +278,7 @@ var MongoDBMemory = class _MongoDBMemory {
76
278
  this.reconnecting = true;
77
279
  while (this.reconnectAttempts < this.maxReconnectAttempts && !this.isConnected) {
78
280
  this.reconnectAttempts++;
79
- loggers.agent.info(
281
+ loggers2.agent.info(
80
282
  `Attempting to reconnect to MongoDB (${this.reconnectAttempts}/${this.maxReconnectAttempts})...`
81
283
  );
82
284
  try {
@@ -84,10 +286,10 @@ var MongoDBMemory = class _MongoDBMemory {
84
286
  this.connected = true;
85
287
  this.reconnectAttempts = 0;
86
288
  this.reconnecting = false;
87
- loggers.agent.info("MongoDB reconnection successful");
289
+ loggers2.agent.info("MongoDB reconnection successful");
88
290
  return;
89
291
  } catch (error) {
90
- loggers.agent.error(
292
+ loggers2.agent.error(
91
293
  `Reconnection attempt ${this.reconnectAttempts} failed:`,
92
294
  error
93
295
  );
@@ -100,7 +302,7 @@ var MongoDBMemory = class _MongoDBMemory {
100
302
  }
101
303
  this.reconnecting = false;
102
304
  if (!this.isConnected) {
103
- loggers.agent.error(
305
+ loggers2.agent.error(
104
306
  `Failed to reconnect to MongoDB after ${this.maxReconnectAttempts} attempts`
105
307
  );
106
308
  }
@@ -114,7 +316,7 @@ var MongoDBMemory = class _MongoDBMemory {
114
316
  this.connected = true;
115
317
  this.reconnectAttempts = 0;
116
318
  } catch (error) {
117
- loggers.agent.error("Failed to connect to MongoDB:", error);
319
+ loggers2.agent.error("Failed to connect to MongoDB:", error);
118
320
  throw error;
119
321
  }
120
322
  }
@@ -126,7 +328,7 @@ var MongoDBMemory = class _MongoDBMemory {
126
328
  await mongoose.disconnect();
127
329
  this.connected = false;
128
330
  } catch (error) {
129
- loggers.agent.error("Failed to disconnect from MongoDB:", error);
331
+ loggers2.agent.error("Failed to disconnect from MongoDB:", error);
130
332
  throw error;
131
333
  }
132
334
  }
@@ -162,18 +364,18 @@ var MongoDBMemory = class _MongoDBMemory {
162
364
  return await operation();
163
365
  } catch (error) {
164
366
  if (error.code === 50 || error.message?.includes("operation exceeded time limit")) {
165
- loggers.agent.error(`${operationName} exceeded time limit`);
367
+ loggers2.agent.error(`${operationName} exceeded time limit`);
166
368
  throw error;
167
369
  }
168
370
  if (error.name === "MongoNetworkError" || error.name === "MongoServerError" || error.message?.includes("connection") || error.message?.includes("disconnect")) {
169
- loggers.agent.warn(
371
+ loggers2.agent.warn(
170
372
  `${operationName} failed due to connection issue, attempting reconnection...`
171
373
  );
172
374
  await this.ensureConnection();
173
375
  try {
174
376
  return await operation();
175
377
  } catch (retryError) {
176
- loggers.agent.error(`${operationName} failed after retry:`, retryError);
378
+ loggers2.agent.error(`${operationName} failed after retry:`, retryError);
177
379
  throw retryError;
178
380
  }
179
381
  }
@@ -181,146 +383,7 @@ var MongoDBMemory = class _MongoDBMemory {
181
383
  }
182
384
  }
183
385
  };
184
-
185
- // implements/thread.memory.ts
186
- import { loggers as loggers2 } from "@ainetwork/adk/utils/logger";
187
- var MongoDBThread = class extends MongoDBMemory {
188
- constructor(uri) {
189
- super(uri);
190
- }
191
- async getThread(userId, threadId) {
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
- });
213
- });
214
- return threadObject;
215
- }, `getThread(${userId}, ${threadId})`);
216
- }
217
- async createThread(type, userId, threadId, title) {
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})`);
230
- }
231
- async addMessagesToThread(userId, threadId, messages) {
232
- return this.executeWithRetry(async () => {
233
- await ThreadModel.updateOne({ threadId, userId }, {
234
- updated_at: Date.now()
235
- });
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})`);
248
- }
249
- async deleteThread(userId, threadId) {
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})`);
259
- }
260
- async listThreads(userId) {
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})`);
275
- }
276
- };
277
-
278
- // implements/intent.memory.ts
279
- var MongoDBIntent = class extends MongoDBMemory {
280
- async getIntent(intentId) {
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})`);
286
- }
287
- async getIntentByName(intentName) {
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})`);
293
- }
294
- async saveIntent(intent) {
295
- return this.executeWithRetry(async () => {
296
- await IntentModel.create(intent);
297
- }, `saveIntent(${intent.id})`);
298
- }
299
- async updateIntent(intentId, 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})`);
306
- }
307
- async deleteIntent(intentId) {
308
- return this.executeWithRetry(async () => {
309
- const timeout = this.getOperationTimeout();
310
- await IntentModel.deleteOne({ id: intentId }).maxTimeMS(timeout);
311
- }, `deleteIntent(${intentId})`);
312
- }
313
- async listIntents() {
314
- return this.executeWithRetry(async () => {
315
- const timeout = this.getOperationTimeout();
316
- const intents = await IntentModel.find().maxTimeMS(timeout).lean();
317
- return intents;
318
- }, `listIntents()`);
319
- }
320
- };
321
386
  export {
322
- MongoDBIntent,
323
- MongoDBMemory,
324
- MongoDBThread
387
+ MongoDBMemory
325
388
  };
326
389
  //# 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 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,qBAAqB,eAAc,SAAS;AAAA,IACnD;AAAA,EACF;AAAA,EAEQ,8BAAoC;AAC1C,QAAI,KAAK,oBAAqB;AAE9B,SAAK,sBAAsB;AAE3B,aAAS,WAAW,GAAG,aAAa,MAAM;AACxC,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AAO,UAAU;AAAA,IACnB,GAAG,mBAAmB,UAAU,GAAG;AAAA,EACrC;AAAA,EAEA,MAAa,WAAW,QAA+B;AACrD,WAAO,KAAK,iBAAiB,YAAY;AACvC,YAAM,YAAY,OAAO,MAAM;AAAA,IACjC,GAAG,cAAc,OAAO,EAAE,GAAG;AAAA,EAC/B;AAAA,EAEA,MAAa,aAAa,UAAkB,QAA+B;AACzE,WAAO,KAAK,iBAAiB,YAAY;AACvC,YAAM,UAAU,KAAK,oBAAoB;AACzC,YAAM,YAAY,UAAU;AAAA,QAC1B,IAAI;AAAA,MACN,GAAG,MAAM,EAAE,UAAU,OAAO;AAAA,IAC9B,GAAG,gBAAgB,QAAQ,GAAG;AAAA,EAChC;AAAA,EAEA,MAAa,aAAa,UAAiC;AACzD,WAAO,KAAK,iBAAiB,YAAY;AACvC,YAAM,UAAU,KAAK,oBAAoB;AACzC,YAAM,YAAY,UAAU,EAAE,IAAI,SAAS,CAAC,EAAE,UAAU,OAAO;AAAA,IACjE,GAAG,gBAAgB,QAAQ,GAAG;AAAA,EAChC;AAAA,EAEA,MAAa,cAAiC;AAC5C,WAAO,KAAK,iBAAiB,YAAY;AACvC,YAAM,UAAU,KAAK,oBAAoB;AACzC,YAAM,UAAU,MAAM,YAAY,KAAK,EACpC,UAAU,OAAO,EACjB,KAAe;AAClB,aAAO;AAAA,IACT,GAAG,eAAe;AAAA,EACpB;AACF;","names":["loggers"]}
1
+ {"version":3,"sources":["../implements/base.memory.ts","../implements/agent.memory.ts","../implements/intent.memory.ts","../implements/thread.memory.ts"],"sourcesContent":["import { IAgentMemory, IIntentMemory, IMemory, IThreadMemory } from \"node_modules/@ainetwork/adk/dist/esm/modules/memory/base.memory\";\nimport mongoose from \"mongoose\";\nimport { loggers } from \"@ainetwork/adk/utils/logger\";\nimport { MongoDBAgent } from \"./agent.memory\";\nimport { MongoDBIntent } from \"./intent.memory\";\nimport { MongoDBThread } from \"./thread.memory\";\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 private agentMemory: MongoDBAgent;\n private intentMemory: MongoDBIntent;\n private threadMemory: MongoDBThread;\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\t\tthis.agentMemory = new MongoDBAgent(\n\t\t\tthis.executeWithRetry.bind(this),\n\t\t\tthis.getOperationTimeout.bind(this)\n\t\t);\n\n\t\tthis.threadMemory = new MongoDBThread(\n\t\t\tthis.executeWithRetry.bind(this),\n\t\t\tthis.getOperationTimeout.bind(this)\n\t\t);\n\n\t\tthis.intentMemory = new MongoDBIntent(\n\t\t\tthis.executeWithRetry.bind(this),\n\t\t\tthis.getOperationTimeout.bind(this)\n\t\t);\n }\n\n public getAgentMemory(): IAgentMemory {\n return this.agentMemory;\n }\n\n public getThreadMemory(): IThreadMemory {\n return this.threadMemory;\n }\n\n public getIntentMemory(): IIntentMemory {\n return this.intentMemory;\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 { IAgentMemory } from \"@ainetwork/adk/modules\";\nimport { AgentModel } from \"../models/agent.model\";\n\nexport type ExecuteWithRetryFn = <T>(\n operation: () => Promise<T>,\n operationName?: string\n) => Promise<T>;\n\nexport type GetOperationTimeoutFn = () => number;\n\ntype AgentMetadata = {\n agent_prompt: string;\n}\n\nexport class MongoDBAgent implements IAgentMemory {\n private executeWithRetry: ExecuteWithRetryFn;\n private getOperationTimeout: GetOperationTimeoutFn;\n\n constructor(\n executeWithRetry: ExecuteWithRetryFn,\n getOperationTimeout: GetOperationTimeoutFn\n ) {\n this.executeWithRetry = executeWithRetry;\n this.getOperationTimeout = getOperationTimeout;\n }\n\n public async getAgentPrompt(): Promise<string> {\n return this.executeWithRetry(async () => {\n const timeout = this.getOperationTimeout();\n const metadata = await AgentModel.findOne({\n id: \"agent_metadata\"\n }).maxTimeMS(timeout)\n .lean<AgentMetadata>();\n return metadata?.agent_prompt || \"\";\n }, \"getAgentPrompt()\");\n };\n \n public async updateAgentPrompt(prompt: string): Promise<void> {\n return this.executeWithRetry(async () => {\n const timeout = this.getOperationTimeout();\n await AgentModel.updateOne({\n id: \"agent_metadata\",\n }, { \"agent_prompt\": prompt }).maxTimeMS(timeout);\n }, \"updateAgentPrompt()\");\n };\n}\n","import type { Intent } from \"@ainetwork/adk/types/memory\";\nimport { IIntentMemory } from \"@ainetwork/adk/modules\";\nimport { IntentModel } from \"../models/intent.model\";\n\nexport type ExecuteWithRetryFn = <T>(\n operation: () => Promise<T>,\n operationName?: string\n) => Promise<T>;\n\nexport type GetOperationTimeoutFn = () => number;\n\nexport class MongoDBIntent implements IIntentMemory {\n private executeWithRetry: ExecuteWithRetryFn;\n private getOperationTimeout: GetOperationTimeoutFn;\n\n constructor(\n executeWithRetry: ExecuteWithRetryFn,\n getOperationTimeout: GetOperationTimeoutFn\n ) {\n this.executeWithRetry = executeWithRetry;\n this.getOperationTimeout = getOperationTimeout;\n }\n\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","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 { ThreadDocument, ThreadModel } from \"../models/threads.model\";\nimport { MessageDocument, MessageModel } from \"../models/messages.model\";\nimport { loggers } from \"@ainetwork/adk/utils/logger\";\n\nexport type ExecuteWithRetryFn = <T>(\n operation: () => Promise<T>,\n operationName?: string\n) => Promise<T>;\n\nexport type GetOperationTimeoutFn = () => number;\n\nexport class MongoDBThread implements IThreadMemory {\n private executeWithRetry: ExecuteWithRetryFn;\n private getOperationTimeout: GetOperationTimeoutFn;\n\n constructor(\n executeWithRetry: ExecuteWithRetryFn,\n getOperationTimeout: GetOperationTimeoutFn\n ) {\n this.executeWithRetry = executeWithRetry;\n this.getOperationTimeout = getOperationTimeout;\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"],"mappings":";;;;;;;;;;;;;;AACA,OAAO,cAAc;AACrB,SAAS,WAAAA,gBAAe;;;ACYjB,IAAM,eAAN,MAA2C;AAAA,EACxC;AAAA,EACA;AAAA,EAER,YACE,kBACA,qBACA;AACA,SAAK,mBAAmB;AACxB,SAAK,sBAAsB;AAAA,EAC7B;AAAA,EAEA,MAAa,iBAAkC;AAC7C,WAAO,KAAK,iBAAiB,YAAY;AACvC,YAAM,UAAU,KAAK,oBAAoB;AACzC,YAAM,WAAW,MAAM,WAAW,QAAQ;AAAA,QACxC,IAAI;AAAA,MACN,CAAC,EAAE,UAAU,OAAO,EACjB,KAAoB;AACvB,aAAO,UAAU,gBAAgB;AAAA,IACnC,GAAG,kBAAkB;AAAA,EACvB;AAAA,EAEA,MAAa,kBAAkB,QAA+B;AAC5D,WAAO,KAAK,iBAAiB,YAAY;AACvC,YAAM,UAAU,KAAK,oBAAoB;AACzC,YAAM,WAAW,UAAU;AAAA,QACzB,IAAI;AAA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AACxB,UAAAA,SAAQ,MAAM,MAAM,GAAG,aAAa,wBAAwB,UAAU;AACtE,gBAAM;AAAA,QACR;AAAA,MACF;AAGA,YAAM;AAAA,IACR;AAAA,EACF;AACF;","names":["loggers","loggers"]}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // models/agent.model.ts
31
+ var agent_model_exports = {};
32
+ __export(agent_model_exports, {
33
+ AgentModel: () => AgentModel,
34
+ AgentObjectSchema: () => AgentObjectSchema
35
+ });
36
+ module.exports = __toCommonJS(agent_model_exports);
37
+ var import_mongoose = require("mongoose");
38
+ var import_mongoose2 = __toESM(require("mongoose"), 1);
39
+ var AgentObjectSchema = new import_mongoose.Schema(
40
+ {
41
+ agent_prompt: {
42
+ type: String
43
+ }
44
+ }
45
+ );
46
+ var AgentModel = import_mongoose2.default.model("Agent", AgentObjectSchema);
47
+ // Annotate the CommonJS export names for ESM import in node:
48
+ 0 && (module.exports = {
49
+ AgentModel,
50
+ AgentObjectSchema
51
+ });
52
+ //# sourceMappingURL=agent.model.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../models/agent.model.ts"],"sourcesContent":["import { type Document, Schema } from \"mongoose\";\nimport mongoose from \"mongoose\";\n\nexport const AgentObjectSchema = new Schema(\n\t{\n\t\tagent_prompt: {\n\t\t\ttype: String,\n\t\t},\n\t},\n);\n\nexport interface AgentDocument extends Document {\n\tagent_prompt: string;\n}\n\nexport const AgentModel = mongoose.model<AgentDocument>(\"Agent\", AgentObjectSchema);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAsC;AACtC,IAAAA,mBAAqB;AAEd,IAAM,oBAAoB,IAAI;AAAA,EACpC;AAAA,IACC,cAAc;AAAA,MACb,MAAM;AAAA,IACP;AAAA,EACD;AACD;AAMO,IAAM,aAAa,iBAAAC,QAAS,MAAqB,SAAS,iBAAiB;","names":["import_mongoose","mongoose"]}
@@ -0,0 +1,23 @@
1
+ import mongoose, { Schema, Document } from 'mongoose';
2
+
3
+ declare const AgentObjectSchema: Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, mongoose.DefaultSchemaOptions, {
4
+ agent_prompt?: string | null | undefined;
5
+ }, Document<unknown, {}, mongoose.FlatRecord<{
6
+ agent_prompt?: string | null | undefined;
7
+ }>, {}> & mongoose.FlatRecord<{
8
+ agent_prompt?: string | null | undefined;
9
+ }> & {
10
+ _id: mongoose.Types.ObjectId;
11
+ } & {
12
+ __v: number;
13
+ }>;
14
+ interface AgentDocument extends Document {
15
+ agent_prompt: string;
16
+ }
17
+ declare const AgentModel: mongoose.Model<AgentDocument, {}, {}, {}, Document<unknown, {}, AgentDocument, {}> & AgentDocument & Required<{
18
+ _id: unknown;
19
+ }> & {
20
+ __v: number;
21
+ }, any>;
22
+
23
+ export { type AgentDocument, AgentModel, AgentObjectSchema };