@ainetwork/adk-provider-memory-mongodb 0.2.2 → 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.
@@ -2,6 +2,12 @@
2
2
  import mongoose, { Schema } from "mongoose";
3
3
  var IntentObjectSchema = new Schema(
4
4
  {
5
+ id: {
6
+ type: String,
7
+ required: true,
8
+ index: true,
9
+ unique: true
10
+ },
5
11
  name: {
6
12
  type: String,
7
13
  required: true,
@@ -14,6 +20,18 @@ var IntentObjectSchema = new Schema(
14
20
  prompt: {
15
21
  type: String,
16
22
  required: false
23
+ },
24
+ status: {
25
+ type: String,
26
+ required: true
27
+ },
28
+ triggeringSentences: {
29
+ type: [String],
30
+ required: false
31
+ },
32
+ tags: {
33
+ type: [String],
34
+ required: false
17
35
  }
18
36
  }
19
37
  );
@@ -22,4 +40,4 @@ var IntentModel = mongoose.model("Intent", IntentObjectSchema);
22
40
  export {
23
41
  IntentModel
24
42
  };
25
- //# sourceMappingURL=chunk-722XAZKL.js.map
43
+ //# sourceMappingURL=chunk-YFW7JXII.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../models/intent.model.ts"],"sourcesContent":["import { Intent } from \"@ainetwork/adk/types/memory\";\nimport mongoose, { type Document, Schema } from \"mongoose\";\n\nconst IntentObjectSchema = new Schema(\n\t{\n\t\tid: { \n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t\tindex: true,\n\t\t\tunique: true,\n\t\t},\n\t\tname: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t\tindex: true,\n\t\t},\n\t\tdescription: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t},\n\t\tprompt: {\n\t\t\ttype: String,\n\t\t\trequired: false,\n\t\t},\n\t\tstatus: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t},\n\t\ttriggeringSentences: {\n\t\t\ttype: [String],\n\t\t\trequired: false,\n\t\t},\n\t\ttags: {\n\t\t\ttype: [String],\n\t\t\trequired: false,\n\t\t},\n\t},\n);\n\nexport interface IntentDocument extends Omit<Document, 'id'>, Omit<Intent, 'id'> {\n\tid: string;\n}\n\nexport const IntentModel = mongoose.model<IntentDocument>(\"Intent\", IntentObjectSchema);"],"mappings":";AACA,OAAO,YAA2B,cAAc;AAEhD,IAAM,qBAAqB,IAAI;AAAA,EAC9B;AAAA,IACC,IAAI;AAAA,MACH,MAAM;AAAA,MACN,UAAU;AAAA,MACV,OAAO;AAAA,MACP,QAAQ;AAAA,IACT;AAAA,IACA,MAAM;AAAA,MACL,MAAM;AAAA,MACN,UAAU;AAAA,MACV,OAAO;AAAA,IACR;AAAA,IACA,aAAa;AAAA,MACZ,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,IACA,QAAQ;AAAA,MACP,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,IACA,QAAQ;AAAA,MACP,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,IACA,qBAAqB;AAAA,MACpB,MAAM,CAAC,MAAM;AAAA,MACb,UAAU;AAAA,IACX;AAAA,IACA,MAAM;AAAA,MACL,MAAM,CAAC,MAAM;AAAA,MACb,UAAU;AAAA,IACX;AAAA,EACD;AACD;AAMO,IAAM,cAAc,SAAS,MAAsB,UAAU,kBAAkB;","names":[]}
package/dist/index.cjs CHANGED
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  MongoDBIntent: () => MongoDBIntent,
34
+ MongoDBMemory: () => MongoDBMemory,
34
35
  MongoDBThread: () => MongoDBThread
35
36
  });
36
37
  module.exports = __toCommonJS(index_exports);
@@ -38,26 +39,108 @@ module.exports = __toCommonJS(index_exports);
38
39
  // implements/base.memory.ts
39
40
  var import_mongoose = __toESM(require("mongoose"), 1);
40
41
  var import_logger = require("@ainetwork/adk/utils/logger");
41
- var MongoDBMemory = class {
42
- _isConnected = false;
43
- _uri;
44
- constructor(uri) {
45
- this._uri = uri;
42
+ var MongoDBMemory = class _MongoDBMemory {
43
+ static instance;
44
+ uri;
45
+ connected = false;
46
+ reconnectAttempts = 0;
47
+ maxReconnectAttempts;
48
+ reconnectInterval;
49
+ reconnecting = false;
50
+ connectionConfig;
51
+ eventListenersSetup = false;
52
+ operationTimeoutMS;
53
+ constructor(config) {
54
+ const cfg = typeof config === "string" ? { uri: config } : config;
55
+ this.uri = cfg.uri;
56
+ this.maxReconnectAttempts = cfg.maxReconnectAttempts ?? 5;
57
+ this.reconnectInterval = cfg.reconnectInterval ?? 5e3;
58
+ this.operationTimeoutMS = cfg.operationTimeoutMS ?? 1e4;
59
+ this.connectionConfig = {
60
+ maxPoolSize: cfg.maxPoolSize ?? 1,
61
+ serverSelectionTimeoutMS: cfg.serverSelectionTimeoutMS ?? 3e4,
62
+ socketTimeoutMS: cfg.socketTimeoutMS ?? 45e3,
63
+ connectTimeoutMS: cfg.connectTimeoutMS ?? 3e4,
64
+ bufferCommands: false
65
+ };
66
+ if (!_MongoDBMemory.instance) {
67
+ _MongoDBMemory.instance = this;
68
+ this.setupMongooseEventListeners();
69
+ } else {
70
+ this.connected = _MongoDBMemory.instance.connected;
71
+ this.operationTimeoutMS = _MongoDBMemory.instance.operationTimeoutMS;
72
+ }
73
+ }
74
+ setupMongooseEventListeners() {
75
+ if (this.eventListenersSetup) return;
76
+ this.eventListenersSetup = true;
77
+ import_mongoose.default.connection.on("connected", () => {
78
+ this.connected = true;
79
+ this.reconnectAttempts = 0;
80
+ this.reconnecting = false;
81
+ import_logger.loggers.agent.info("MongoDB connected successfully");
82
+ });
83
+ import_mongoose.default.connection.on("disconnected", () => {
84
+ this.connected = false;
85
+ import_logger.loggers.agent.warn("MongoDB disconnected");
86
+ this.handleDisconnection();
87
+ });
88
+ import_mongoose.default.connection.on("error", (error) => {
89
+ this.connected = false;
90
+ import_logger.loggers.agent.error("MongoDB connection error:", error);
91
+ this.handleDisconnection();
92
+ });
93
+ import_mongoose.default.connection.on("reconnected", () => {
94
+ this.connected = true;
95
+ this.reconnectAttempts = 0;
96
+ this.reconnecting = false;
97
+ import_logger.loggers.agent.info("MongoDB reconnected successfully");
98
+ });
99
+ }
100
+ async handleDisconnection() {
101
+ if (this.reconnecting) {
102
+ return;
103
+ }
104
+ this.reconnecting = true;
105
+ while (this.reconnectAttempts < this.maxReconnectAttempts && !this.isConnected) {
106
+ this.reconnectAttempts++;
107
+ import_logger.loggers.agent.info(
108
+ `Attempting to reconnect to MongoDB (${this.reconnectAttempts}/${this.maxReconnectAttempts})...`
109
+ );
110
+ try {
111
+ await import_mongoose.default.connect(this.uri, this.connectionConfig);
112
+ this.connected = true;
113
+ this.reconnectAttempts = 0;
114
+ this.reconnecting = false;
115
+ import_logger.loggers.agent.info("MongoDB reconnection successful");
116
+ return;
117
+ } catch (error) {
118
+ import_logger.loggers.agent.error(
119
+ `Reconnection attempt ${this.reconnectAttempts} failed:`,
120
+ error
121
+ );
122
+ if (this.reconnectAttempts < this.maxReconnectAttempts) {
123
+ await new Promise(
124
+ (resolve) => setTimeout(resolve, this.reconnectInterval)
125
+ );
126
+ }
127
+ }
128
+ }
129
+ this.reconnecting = false;
130
+ if (!this.isConnected) {
131
+ import_logger.loggers.agent.error(
132
+ `Failed to reconnect to MongoDB after ${this.maxReconnectAttempts} attempts`
133
+ );
134
+ }
46
135
  }
47
136
  async connect() {
48
- if (this._isConnected) {
137
+ if (this.connected) {
49
138
  return;
50
139
  }
51
140
  try {
52
- await import_mongoose.default.connect(this._uri, {
53
- maxPoolSize: 1,
54
- serverSelectionTimeoutMS: 3e4,
55
- socketTimeoutMS: 45e3,
56
- connectTimeoutMS: 3e4,
57
- bufferCommands: false
58
- });
59
- this._isConnected = true;
60
- import_logger.loggers.agent.info("MongoDB connected successfully");
141
+ await import_mongoose.default.connect(this.uri, this.connectionConfig);
142
+ this.connected = true;
143
+ this.reconnectAttempts = 0;
61
144
  } catch (error) {
62
145
  import_logger.loggers.agent.error("Failed to connect to MongoDB:", error);
63
146
  throw error;
@@ -69,15 +152,61 @@ var MongoDBMemory = class {
69
152
  }
70
153
  try {
71
154
  await import_mongoose.default.disconnect();
72
- this._isConnected = false;
73
- import_logger.loggers.agent.info("MongoDB disconnected successfully");
155
+ this.connected = false;
74
156
  } catch (error) {
75
157
  import_logger.loggers.agent.error("Failed to disconnect from MongoDB:", error);
76
158
  throw error;
77
159
  }
78
160
  }
79
161
  isConnected() {
80
- return this._isConnected;
162
+ return this.connected;
163
+ }
164
+ async ensureConnection() {
165
+ if (!this.isConnected && !this.reconnecting) {
166
+ await this.connect();
167
+ }
168
+ const maxWaitTime = 3e4;
169
+ const startTime = Date.now();
170
+ while (this.reconnecting && Date.now() - startTime < maxWaitTime) {
171
+ await new Promise((resolve) => setTimeout(resolve, 100));
172
+ }
173
+ if (!this.isConnected) {
174
+ throw new Error("MongoDB is not connected and reconnection failed");
175
+ }
176
+ }
177
+ /**
178
+ * Get the operation timeout in milliseconds
179
+ */
180
+ getOperationTimeout() {
181
+ return this.operationTimeoutMS;
182
+ }
183
+ /**
184
+ * Execute a database operation with automatic retry on connection errors
185
+ * Note: Use mongoose's maxTimeMS option in queries for timeout control
186
+ */
187
+ async executeWithRetry(operation, operationName = "Database operation") {
188
+ await this.ensureConnection();
189
+ try {
190
+ return await operation();
191
+ } catch (error) {
192
+ if (error.code === 50 || error.message?.includes("operation exceeded time limit")) {
193
+ import_logger.loggers.agent.error(`${operationName} exceeded time limit`);
194
+ throw error;
195
+ }
196
+ if (error.name === "MongoNetworkError" || error.name === "MongoServerError" || error.message?.includes("connection") || error.message?.includes("disconnect")) {
197
+ import_logger.loggers.agent.warn(
198
+ `${operationName} failed due to connection issue, attempting reconnection...`
199
+ );
200
+ await this.ensureConnection();
201
+ try {
202
+ return await operation();
203
+ } catch (retryError) {
204
+ import_logger.loggers.agent.error(`${operationName} failed after retry:`, retryError);
205
+ throw retryError;
206
+ }
207
+ }
208
+ throw error;
209
+ }
81
210
  }
82
211
  };
83
212
 
@@ -174,82 +303,89 @@ var MongoDBThread = class extends MongoDBMemory {
174
303
  super(uri);
175
304
  }
176
305
  async getThread(userId, threadId) {
177
- const thread = await ThreadModel.findOne({ threadId, userId });
178
- const messages = await MessageModel.find({ threadId, userId }).sort({
179
- timestamp: 1
180
- });
181
- if (!thread) return void 0;
182
- import_logger2.loggers.agent.debug(`Found ${messages.length} messages for thread ${threadId}`);
183
- const threadObject = {
184
- threadId: thread.threadId,
185
- userId: thread.userId,
186
- type: thread.type,
187
- title: thread.title || "New thread",
188
- messages: []
189
- };
190
- messages.forEach((message) => {
191
- threadObject.messages.push({
192
- messageId: message.messageId,
193
- role: message.role,
194
- content: message.content,
195
- timestamp: message.timestamp,
196
- metadata: message.metadata
306
+ return this.executeWithRetry(async () => {
307
+ const timeout = this.getOperationTimeout();
308
+ const thread = await ThreadModel.findOne({ threadId, userId }).maxTimeMS(timeout);
309
+ const messages = await MessageModel.find({ threadId, userId }).sort({ timestamp: 1 }).maxTimeMS(timeout);
310
+ if (!thread) return void 0;
311
+ import_logger2.loggers.agent.debug(`Found ${messages.length} messages for thread ${threadId}`);
312
+ const threadObject = {
313
+ threadId: thread.threadId,
314
+ userId: thread.userId,
315
+ type: thread.type,
316
+ title: thread.title || "New thread",
317
+ messages: []
318
+ };
319
+ messages.forEach((message) => {
320
+ threadObject.messages.push({
321
+ messageId: message.messageId,
322
+ role: message.role,
323
+ content: message.content,
324
+ timestamp: message.timestamp,
325
+ metadata: message.metadata
326
+ });
197
327
  });
198
- });
199
- return threadObject;
328
+ return threadObject;
329
+ }, `getThread(${userId}, ${threadId})`);
200
330
  }
201
331
  async createThread(type, userId, threadId, title) {
202
- const now = Date.now();
203
- await ThreadModel.create({
204
- type,
205
- userId,
206
- threadId,
207
- title,
208
- updated_at: now,
209
- created_at: now
210
- });
211
- return { type, userId, threadId, title, messages: [] };
332
+ return this.executeWithRetry(async () => {
333
+ const now = Date.now();
334
+ await ThreadModel.create({
335
+ type,
336
+ userId,
337
+ threadId,
338
+ title,
339
+ updated_at: now,
340
+ created_at: now
341
+ });
342
+ return { type, userId, threadId, title, messages: [] };
343
+ }, `createThread(${userId}, ${threadId})`);
212
344
  }
213
345
  async addMessagesToThread(userId, threadId, messages) {
214
- await ThreadModel.updateOne({ threadId, userId }, {
215
- updated_at: Date.now()
216
- });
217
- for (const message of messages) {
218
- await MessageModel.create({
219
- threadId,
220
- messageId: message.messageId,
221
- userId,
222
- role: message.role,
223
- content: message.content,
224
- timestamp: message.timestamp,
225
- metadata: message.metadata
346
+ return this.executeWithRetry(async () => {
347
+ await ThreadModel.updateOne({ threadId, userId }, {
348
+ updated_at: Date.now()
226
349
  });
227
- }
350
+ for (const message of messages) {
351
+ await MessageModel.create({
352
+ threadId,
353
+ messageId: message.messageId,
354
+ userId,
355
+ role: message.role,
356
+ content: message.content,
357
+ timestamp: message.timestamp,
358
+ metadata: message.metadata
359
+ });
360
+ }
361
+ }, `addMessagesToThread(${userId}, ${threadId})`);
228
362
  }
229
363
  async deleteThread(userId, threadId) {
230
- const messages = await MessageModel.find({ userId, threadId }).sort({
231
- timestamp: 1
232
- });
233
- messages?.forEach((message) => {
234
- message.deleteOne();
235
- });
236
- const thread = await ThreadModel.findOne({ userId, threadId });
237
- thread?.deleteOne();
364
+ return this.executeWithRetry(async () => {
365
+ const timeout = this.getOperationTimeout();
366
+ const messages = await MessageModel.find({ userId, threadId }).sort({ timestamp: 1 }).maxTimeMS(timeout);
367
+ messages?.forEach((message) => {
368
+ message.deleteOne();
369
+ });
370
+ const thread = await ThreadModel.findOne({ userId, threadId }).maxTimeMS(timeout);
371
+ thread?.deleteOne();
372
+ }, `deleteThread(${userId}, ${threadId})`);
238
373
  }
239
374
  async listThreads(userId) {
240
- const threads = await ThreadModel.find({ userId }).sort({
241
- updated_at: -1
242
- });
243
- const data = threads.map((thread) => {
244
- return {
245
- type: thread.type,
246
- userId,
247
- threadId: thread.threadId,
248
- title: thread.title,
249
- updatedAt: thread.updated_at
250
- };
251
- });
252
- return data;
375
+ return this.executeWithRetry(async () => {
376
+ const timeout = this.getOperationTimeout();
377
+ const threads = await ThreadModel.find({ userId }).sort({ updated_at: -1 }).maxTimeMS(timeout);
378
+ const data = threads.map((thread) => {
379
+ return {
380
+ type: thread.type,
381
+ userId,
382
+ threadId: thread.threadId,
383
+ title: thread.title,
384
+ updatedAt: thread.updated_at
385
+ };
386
+ });
387
+ return data;
388
+ }, `listThreads(${userId})`);
253
389
  }
254
390
  };
255
391
 
@@ -257,6 +393,12 @@ var MongoDBThread = class extends MongoDBMemory {
257
393
  var import_mongoose6 = __toESM(require("mongoose"), 1);
258
394
  var IntentObjectSchema = new import_mongoose6.Schema(
259
395
  {
396
+ id: {
397
+ type: String,
398
+ required: true,
399
+ index: true,
400
+ unique: true
401
+ },
260
402
  name: {
261
403
  type: String,
262
404
  required: true,
@@ -269,67 +411,70 @@ var IntentObjectSchema = new import_mongoose6.Schema(
269
411
  prompt: {
270
412
  type: String,
271
413
  required: false
414
+ },
415
+ status: {
416
+ type: String,
417
+ required: true
418
+ },
419
+ triggeringSentences: {
420
+ type: [String],
421
+ required: false
422
+ },
423
+ tags: {
424
+ type: [String],
425
+ required: false
272
426
  }
273
427
  }
274
428
  );
275
429
  var IntentModel = import_mongoose6.default.model("Intent", IntentObjectSchema);
276
430
 
277
431
  // implements/intent.memory.ts
278
- var import_mongoose7 = require("mongoose");
279
432
  var MongoDBIntent = class extends MongoDBMemory {
280
433
  async getIntent(intentId) {
281
- const intent = await IntentModel.findById(new import_mongoose7.Types.ObjectId(intentId));
282
- if (intent) {
283
- return {
284
- name: intent.name,
285
- description: intent.description,
286
- prompt: intent.prompt
287
- };
288
- }
289
- return void 0;
434
+ return this.executeWithRetry(async () => {
435
+ const timeout = this.getOperationTimeout();
436
+ const intent = await IntentModel.findOne({ id: intentId }).maxTimeMS(timeout).lean();
437
+ return intent || void 0;
438
+ }, `getIntent(${intentId})`);
290
439
  }
291
440
  async getIntentByName(intentName) {
292
- const intent = await IntentModel.findOne({ name: intentName });
293
- if (intent) {
294
- return {
295
- name: intent.name,
296
- description: intent.description,
297
- prompt: intent.prompt
298
- };
299
- }
300
- return void 0;
441
+ return this.executeWithRetry(async () => {
442
+ const timeout = this.getOperationTimeout();
443
+ const intent = await IntentModel.findOne({ name: intentName }).maxTimeMS(timeout).lean();
444
+ return intent || void 0;
445
+ }, `getIntentByName(${intentName})`);
301
446
  }
302
447
  async saveIntent(intent) {
303
- await IntentModel.create({
304
- name: intent.name,
305
- description: intent.description,
306
- prompt: intent.prompt
307
- });
448
+ return this.executeWithRetry(async () => {
449
+ await IntentModel.create(intent);
450
+ }, `saveIntent(${intent.id})`);
308
451
  }
309
452
  async updateIntent(intentId, intent) {
310
- await IntentModel.updateOne({
311
- _id: new import_mongoose7.Types.ObjectId(intentId)
312
- }, {
313
- name: intent.name,
314
- description: intent.description,
315
- prompt: intent.prompt
316
- });
453
+ return this.executeWithRetry(async () => {
454
+ const timeout = this.getOperationTimeout();
455
+ await IntentModel.updateOne({
456
+ id: intentId
457
+ }, intent).maxTimeMS(timeout);
458
+ }, `updateIntent(${intentId})`);
317
459
  }
318
460
  async deleteIntent(intentId) {
319
- await IntentModel.deleteOne({ _id: new import_mongoose7.Types.ObjectId(intentId) });
461
+ return this.executeWithRetry(async () => {
462
+ const timeout = this.getOperationTimeout();
463
+ await IntentModel.deleteOne({ id: intentId }).maxTimeMS(timeout);
464
+ }, `deleteIntent(${intentId})`);
320
465
  }
321
466
  async listIntents() {
322
- const intents = await IntentModel.find();
323
- return intents.map((intent) => ({
324
- name: intent.name,
325
- description: intent.description,
326
- prompt: intent.prompt
327
- }));
467
+ return this.executeWithRetry(async () => {
468
+ const timeout = this.getOperationTimeout();
469
+ const intents = await IntentModel.find().maxTimeMS(timeout).lean();
470
+ return intents;
471
+ }, `listIntents()`);
328
472
  }
329
473
  };
330
474
  // Annotate the CommonJS export names for ESM import in node:
331
475
  0 && (module.exports = {
332
476
  MongoDBIntent,
477
+ MongoDBMemory,
333
478
  MongoDBThread
334
479
  });
335
480
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts","../implements/base.memory.ts","../models/threads.model.ts","../models/messages.model.ts","../implements/thread.memory.ts","../models/intent.model.ts","../implements/intent.memory.ts"],"sourcesContent":["export { MongoDBThread } from \"./implements/thread.memory\";\nexport { MongoDBIntent } from \"./implements/intent.memory\";","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 { ThreadType } from \"@ainetwork/adk/types/memory\";\nimport { type Document, Schema } from \"mongoose\";\nimport mongoose from \"mongoose\";\n\nexport const ThreadObjectSchema = new Schema(\n\t{\n\t\ttype: {\n\t\t\ttype: String,\n\t\t\tenum: Object.values(ThreadType),\n\t\t\trequired: true,\n\t\t},\n\t\tthreadId: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t\tindex: true,\n\t\t},\n\t\tuserId: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t\tindex: true,\n\t\t},\n\t\ttitle: {\n\t\t\ttype: String,\n\t\t\trequired: false,\n\t\t},\n\t\tcreated_at: {\n\t\t\ttype: Number,\n\t\t\trequired: true,\n\t\t},\n\t\tupdated_at: {\n\t\t\ttype: Number,\n\t\t\trequired: true,\n\t\t}\n\t},\n);\n\nexport interface ThreadDocument extends Document {\n\ttype: ThreadType;\n\tthreadId: string;\n\tuserId: string;\n\ttitle: string;\n\tcreated_at: number;\n\tupdated_at: number;\n}\n\nexport const ThreadModel = mongoose.model<ThreadDocument>(\"Thread\", ThreadObjectSchema);\n","import { MessageRole } from \"@ainetwork/adk/types/memory\";\nimport { type Document, Schema } from \"mongoose\";\nimport mongoose from \"mongoose\";\n\n// MessageContentObject schema\nexport const MessageContentObjectSchema = new Schema(\n\t{\n\t\ttype: { type: String, required: true },\n\t\tparts: { type: [Schema.Types.Mixed], required: true },\n\t},\n\t{ _id: false },\n);\n\n// MessageObject schema - 개별 문서로 저장\nexport const MessageObjectSchema = new Schema(\n\t{\n\t\tmessageId: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t\tindex: true,\n\t\t},\n\t\tthreadId: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t\tindex: true,\n\t\t},\n\t\tuserId: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t\tindex: true,\n\t\t},\n\t\trole: {\n\t\t\ttype: String,\n\t\t\tenum: Object.values(MessageRole),\n\t\t\trequired: true,\n\t\t},\n\t\tcontent: {\n\t\t\ttype: MessageContentObjectSchema,\n\t\t\trequired: true,\n\t\t},\n\t\ttimestamp: {\n\t\t\ttype: Number,\n\t\t\trequired: true,\n\t\t},\n\t\tmetadata: {\n\t\t\ttype: Schema.Types.Mixed,\n\t\t\tdefault: {},\n\t\t},\n\t},\n);\n\n// Message Document interface\nexport interface MessageDocument extends Document {\n\tmessageId: string;\n\tthreadId: string;\n\tuserId: string;\n\trole: MessageRole;\n\tcontent: {\n\t\ttype: string;\n\t\tparts: any[];\n\t};\n\ttimestamp: number;\n\tmetadata?: { [key: string]: unknown };\n}\n\nexport const MessageModel = mongoose.model<MessageDocument>(\"Message\", MessageObjectSchema);","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 mongoose, { type Document, Schema } from \"mongoose\";\n\nconst IntentObjectSchema = new Schema(\n\t{\n\t\tname: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t\tindex: true,\n\t\t},\n\t\tdescription: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t},\n\t\tprompt: {\n\t\t\ttype: String,\n\t\t\trequired: false,\n\t\t},\n\t}\n);\n\nexport interface IntentDocument extends Document {\n\tname: string;\n\tdescription: string;\n\tprompt?: string;\n}\n\nexport const IntentModel = mongoose.model<IntentDocument>(\"Intent\", IntentObjectSchema);","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\";\nimport { Types } from \"mongoose\";\n\nexport class MongoDBIntent extends MongoDBMemory implements IIntentMemory {\n public async getIntent(intentId: string): Promise<Intent | undefined> {\n const intent = await IntentModel.findById(new Types.ObjectId(intentId));\n if (intent) {\n return {\n name: intent.name,\n description: intent.description,\n prompt: intent.prompt,\n } as Intent;\n }\n return undefined;\n };\n\n\tpublic async getIntentByName(intentName: string): Promise<Intent | undefined> {\n\t\tconst intent = await IntentModel.findOne({ name: intentName });\n\t\tif (intent) {\n\t\t\treturn {\n\t\t\t\tname: intent.name,\n\t\t\t\tdescription: intent.description,\n\t\t\t\tprompt: intent.prompt,\n\t\t\t} as Intent;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tpublic async saveIntent(intent: Intent): Promise<void> {\n // ObjectId automatically generated (MongoDB automatically generates)\n await IntentModel.create({\n name: intent.name,\n description: intent.description,\n prompt: intent.prompt,\n });\n };\n\n\tpublic async updateIntent(intentId: string, intent: Intent): Promise<void> {\n await IntentModel.updateOne({\n _id: new Types.ObjectId(intentId),\n },{\n name: intent.name,\n description: intent.description,\n prompt: intent.prompt,\n });\n };\n\n\tpublic async deleteIntent(intentId: string): Promise<void> {\n await IntentModel.deleteOne({ _id: new Types.ObjectId(intentId) });\n };\n\n\tpublic async listIntents(): Promise<Intent[]> {\n const intents = await IntentModel.find();\n return intents.map(intent => ({\n name: intent.name,\n description: intent.description,\n prompt: intent.prompt,\n } as Intent));\n };\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,sBAAqB;AACrB,oBAAwB;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,Y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AED,MAAa,gBAAgB,YAAiD;AAC7E,UAAM,SAAS,MAAM,YAAY,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC7D,QAAI,QAAQ;AACX,aAAO;AAAA,QACN,MAAM,OAAO;AAAA,QACb,aAAa,OAAO;AAAA,QACpB,QAAQ,OAAO;AAAA,MAChB;AAAA,IACD;AACA,WAAO;AAAA,EACR;AAAA,EAEA,MAAa,WAAW,QAA+B;AAEpD,UAAM,YAAY,OAAO;AAAA,MACvB,MAAM,OAAO;AAAA,MACb,aAAa,OAAO;AAAA,MACpB,QAAQ,OAAO;AAAA,IACjB,CAAC;AAAA,EACH;AAAA,EAED,MAAa,aAAa,UAAkB,QAA+B;AACxE,UAAM,YAAY,UAAU;AAAA,MAC1B,KAAK,IAAI,uBAAM,SAAS,QAAQ;AAAA,IAClC,GAAE;AAAA,MACA,MAAM,OAAO;AAAA,MACb,aAAa,OAAO;AAAA,MACpB,QAAQ,OAAO;AAAA,IACjB,CAAC;AAAA,EACH;AAAA,EAED,MAAa,aAAa,UAAiC;AACxD,UAAM,YAAY,UAAU,EAAE,KAAK,IAAI,uBAAM,SAAS,QAAQ,EAAE,CAAC;AAAA,EACnE;AAAA,EAED,MAAa,cAAiC;AAC3C,UAAM,UAAU,MAAM,YAAY,KAAK;AACvC,WAAO,QAAQ,IAAI,aAAW;AAAA,MAC5B,MAAM,OAAO;AAAA,MACb,aAAa,OAAO;AAAA,MACpB,QAAQ,OAAO;AAAA,IACjB,EAAY;AAAA,EACd;AACF;","names":["mongoose","import_mongoose","mongoose","import_memory","import_mongoose","mongoose","import_logger","import_mongoose","mongoose","import_mongoose"]}
1
+ {"version":3,"sources":["../index.ts","../implements/base.memory.ts","../models/threads.model.ts","../models/messages.model.ts","../implements/thread.memory.ts","../models/intent.model.ts","../implements/intent.memory.ts"],"sourcesContent":["export { MongoDBThread } from \"./implements/thread.memory\";\nexport { MongoDBIntent } from \"./implements/intent.memory\";\nexport { MongoDBMemory } from \"./implements/base.memory\";\nexport type { MongoDBMemoryConfig } from \"./implements/base.memory\";","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 { ThreadType } from \"@ainetwork/adk/types/memory\";\nimport { type Document, Schema } from \"mongoose\";\nimport mongoose from \"mongoose\";\n\nexport const ThreadObjectSchema = new Schema(\n\t{\n\t\ttype: {\n\t\t\ttype: String,\n\t\t\tenum: Object.values(ThreadType),\n\t\t\trequired: true,\n\t\t},\n\t\tthreadId: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t\tindex: true,\n\t\t},\n\t\tuserId: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t\tindex: true,\n\t\t},\n\t\ttitle: {\n\t\t\ttype: String,\n\t\t\trequired: false,\n\t\t},\n\t\tcreated_at: {\n\t\t\ttype: Number,\n\t\t\trequired: true,\n\t\t},\n\t\tupdated_at: {\n\t\t\ttype: Number,\n\t\t\trequired: true,\n\t\t}\n\t},\n);\n\nexport interface ThreadDocument extends Document {\n\ttype: ThreadType;\n\tthreadId: string;\n\tuserId: string;\n\ttitle: string;\n\tcreated_at: number;\n\tupdated_at: number;\n}\n\nexport const ThreadModel = mongoose.model<ThreadDocument>(\"Thread\", ThreadObjectSchema);\n","import { MessageRole } from \"@ainetwork/adk/types/memory\";\nimport { type Document, Schema } from \"mongoose\";\nimport mongoose from \"mongoose\";\n\n// MessageContentObject schema\nexport const MessageContentObjectSchema = new Schema(\n\t{\n\t\ttype: { type: String, required: true },\n\t\tparts: { type: [Schema.Types.Mixed], required: true },\n\t},\n\t{ _id: false },\n);\n\n// MessageObject schema - 개별 문서로 저장\nexport const MessageObjectSchema = new Schema(\n\t{\n\t\tmessageId: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t\tindex: true,\n\t\t},\n\t\tthreadId: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t\tindex: true,\n\t\t},\n\t\tuserId: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t\tindex: true,\n\t\t},\n\t\trole: {\n\t\t\ttype: String,\n\t\t\tenum: Object.values(MessageRole),\n\t\t\trequired: true,\n\t\t},\n\t\tcontent: {\n\t\t\ttype: MessageContentObjectSchema,\n\t\t\trequired: true,\n\t\t},\n\t\ttimestamp: {\n\t\t\ttype: Number,\n\t\t\trequired: true,\n\t\t},\n\t\tmetadata: {\n\t\t\ttype: Schema.Types.Mixed,\n\t\t\tdefault: {},\n\t\t},\n\t},\n);\n\n// Message Document interface\nexport interface MessageDocument extends Document {\n\tmessageId: string;\n\tthreadId: string;\n\tuserId: string;\n\trole: MessageRole;\n\tcontent: {\n\t\ttype: string;\n\t\tparts: any[];\n\t};\n\ttimestamp: number;\n\tmetadata?: { [key: string]: unknown };\n}\n\nexport const MessageModel = mongoose.model<MessageDocument>(\"Message\", MessageObjectSchema);","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 { Intent } from \"@ainetwork/adk/types/memory\";\nimport mongoose, { type Document, Schema } from \"mongoose\";\n\nconst IntentObjectSchema = new Schema(\n\t{\n\t\tid: { \n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t\tindex: true,\n\t\t\tunique: true,\n\t\t},\n\t\tname: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t\tindex: true,\n\t\t},\n\t\tdescription: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t},\n\t\tprompt: {\n\t\t\ttype: String,\n\t\t\trequired: false,\n\t\t},\n\t\tstatus: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t},\n\t\ttriggeringSentences: {\n\t\t\ttype: [String],\n\t\t\trequired: false,\n\t\t},\n\t\ttags: {\n\t\t\ttype: [String],\n\t\t\trequired: false,\n\t\t},\n\t},\n);\n\nexport interface IntentDocument extends Omit<Document, 'id'>, Omit<Intent, 'id'> {\n\tid: string;\n}\n\nexport const IntentModel = mongoose.model<IntentDocument>(\"Intent\", IntentObjectSchema);","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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,sBAAqB;AACrB,oBAAwB;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,oBAAAA,QAAS,WAAW,GAAG,aAAa,MAAM;AACxC,WAAK,YAAY;AACjB,WAAK,oBAAoB;AACzB,WAAK,eAAe;AACpB,4BAAQ,MAAM,KAAK,gCAAgC;AAAA,IACrD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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":["mongoose","import_mongoose","mongoose","import_memory","import_mongoose","mongoose","import_logger","import_mongoose","mongoose"]}