@ainetwork/adk-provider-memory-mongodb 0.1.2 → 0.1.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.
@@ -0,0 +1,29 @@
1
+ // models/intent.model.ts
2
+ import mongoose, { Schema } from "mongoose";
3
+ var IntentObjectSchema = new Schema(
4
+ {
5
+ name: {
6
+ type: String,
7
+ required: true,
8
+ index: true
9
+ },
10
+ description: {
11
+ type: String,
12
+ required: true
13
+ },
14
+ prompt: {
15
+ type: String,
16
+ required: false
17
+ },
18
+ llm: {
19
+ type: String,
20
+ required: false
21
+ }
22
+ }
23
+ );
24
+ var IntentModel = mongoose.model("Intent", IntentObjectSchema);
25
+
26
+ export {
27
+ IntentModel
28
+ };
29
+ //# sourceMappingURL=chunk-JCE5NAY5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../models/intent.model.ts"],"sourcesContent":["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\tllm: {\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\tllm?: string;\n}\n\nexport const IntentModel = mongoose.model<IntentDocument>(\"Intent\", IntentObjectSchema);"],"mappings":";AAAA,OAAO,YAA2B,cAAc;AAEhD,IAAM,qBAAqB,IAAI;AAAA,EAC9B;AAAA,IACC,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,KAAK;AAAA,MACJ,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,EACD;AACD;AASO,IAAM,cAAc,SAAS,MAAsB,UAAU,kBAAkB;","names":[]}
@@ -1,11 +1,37 @@
1
1
  // models/chats.model.ts
2
- import mongoose, { Schema } from "mongoose";
2
+ import { Schema } from "mongoose";
3
3
  var ChatRole = /* @__PURE__ */ ((ChatRole2) => {
4
4
  ChatRole2["USER"] = "USER";
5
5
  ChatRole2["SYSTEM"] = "SYSTEM";
6
6
  ChatRole2["MODEL"] = "MODEL";
7
7
  return ChatRole2;
8
8
  })(ChatRole || {});
9
+ var SessionObjectSchema = new Schema(
10
+ {
11
+ sessionId: {
12
+ type: String,
13
+ required: true,
14
+ index: true
15
+ },
16
+ userId: {
17
+ type: String,
18
+ required: true,
19
+ index: true
20
+ },
21
+ title: {
22
+ type: String,
23
+ required: false
24
+ },
25
+ created_at: {
26
+ type: Number,
27
+ required: true
28
+ },
29
+ updated_at: {
30
+ type: Number,
31
+ required: true
32
+ }
33
+ }
34
+ );
9
35
  var ChatContentObjectSchema = new Schema(
10
36
  {
11
37
  type: { type: String, required: true },
@@ -20,6 +46,11 @@ var ChatObjectSchema = new Schema(
20
46
  required: true,
21
47
  index: true
22
48
  },
49
+ userId: {
50
+ type: String,
51
+ required: true,
52
+ index: true
53
+ },
23
54
  role: {
24
55
  type: String,
25
56
  enum: Object.values(ChatRole),
@@ -37,15 +68,13 @@ var ChatObjectSchema = new Schema(
37
68
  type: Schema.Types.Mixed,
38
69
  default: {}
39
70
  }
40
- },
41
- {
42
- timestamps: true
43
71
  }
44
72
  );
45
- var ChatModel = mongoose.model("Chat", ChatObjectSchema);
46
73
 
47
74
  export {
48
75
  ChatRole,
49
- ChatModel
76
+ SessionObjectSchema,
77
+ ChatContentObjectSchema,
78
+ ChatObjectSchema
50
79
  };
51
- //# sourceMappingURL=chunk-2SB2M62A.js.map
80
+ //# sourceMappingURL=chunk-N5FAVJ4Z.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../models/chats.model.ts"],"sourcesContent":["import { type Document, Schema } from \"mongoose\";\n\n// ChatRole enum\nexport enum ChatRole {\n\tUSER = \"USER\",\n\tSYSTEM = \"SYSTEM\",\n\tMODEL = \"MODEL\",\n}\n\nexport const SessionObjectSchema = new Schema(\n\t{\n\t\tsessionId: {\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 SessionDocument extends Document {\n\tsessionId: string;\n\tuserId: string;\n\ttitle?: string;\n\tcreated_at: number;\n\tupdated_at: number;\n}\n\n// ChatContentObject schema\nexport const ChatContentObjectSchema = 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// ChatObject schema - 개별 문서로 저장\nexport const ChatObjectSchema = new Schema(\n\t{\n\t\tsessionId: {\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(ChatRole),\n\t\t\trequired: true,\n\t\t},\n\t\tcontent: {\n\t\t\ttype: ChatContentObjectSchema,\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// Chat Document interface\nexport interface ChatDocument extends Document {\n\tsessionId: string;\n\trole: ChatRole;\n\tcontent: {\n\t\ttype: string;\n\t\tparts: any[];\n\t};\n\ttimestamp: number;\n\tmetadata?: { [key: string]: unknown };\n\tcreatedAt: Date;\n\tupdatedAt: Date;\n}\n"],"mappings":";AAAA,SAAwB,cAAc;AAG/B,IAAK,WAAL,kBAAKA,cAAL;AACN,EAAAA,UAAA,UAAO;AACP,EAAAA,UAAA,YAAS;AACT,EAAAA,UAAA,WAAQ;AAHG,SAAAA;AAAA,GAAA;AAML,IAAM,sBAAsB,IAAI;AAAA,EACtC;AAAA,IACC,WAAW;AAAA,MACV,MAAM;AAAA,MACN,UAAU;AAAA,MACV,OAAO;AAAA,IACR;AAAA,IACA,QAAQ;AAAA,MACP,MAAM;AAAA,MACN,UAAU;AAAA,MACV,OAAO;AAAA,IACR;AAAA,IACA,OAAO;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,IACA,YAAY;AAAA,MACX,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,IACA,YAAY;AAAA,MACX,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,EACD;AACD;AAWO,IAAM,0BAA0B,IAAI;AAAA,EAC1C;AAAA,IACC,MAAM,EAAE,MAAM,QAAQ,UAAU,KAAK;AAAA,IACrC,OAAO,EAAE,MAAM,CAAC,OAAO,MAAM,KAAK,GAAG,UAAU,KAAK;AAAA,EACrD;AAAA,EACA,EAAE,KAAK,MAAM;AACd;AAGO,IAAM,mBAAmB,IAAI;AAAA,EACnC;AAAA,IACC,WAAW;AAAA,MACV,MAAM;AAAA,MACN,UAAU;AAAA,MACV,OAAO;AAAA,IACR;AAAA,IACA,QAAQ;AAAA,MACP,MAAM;AAAA,MACN,UAAU;AAAA,MACV,OAAO;AAAA,IACR;AAAA,IACA,MAAM;AAAA,MACL,MAAM;AAAA,MACN,MAAM,OAAO,OAAO,QAAQ;AAAA,MAC5B,UAAU;AAAA,IACX;AAAA,IACA,SAAS;AAAA,MACR,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,IACA,WAAW;AAAA,MACV,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,IACA,UAAU;AAAA,MACT,MAAM,OAAO,MAAM;AAAA,MACnB,SAAS,CAAC;AAAA,IACX;AAAA,EACD;AACD;","names":["ChatRole"]}
package/dist/index.cjs CHANGED
@@ -30,35 +30,112 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- MongoDBMemory: () => MongoDBMemory
33
+ MongoDBIntent: () => MongoDBIntent,
34
+ MongoDBSession: () => MongoDBSession
34
35
  });
35
36
  module.exports = __toCommonJS(index_exports);
36
- var import_modules = require("@ainetwork/adk/modules");
37
+
38
+ // implements/session.memory.ts
39
+ var import_node_crypto = require("crypto");
40
+
41
+ // implements/base.memory.ts
42
+ var import_mongoose = require("mongoose");
37
43
  var import_logger = require("@ainetwork/adk/utils/logger");
38
- var import_mongoose2 = __toESM(require("mongoose"), 1);
44
+ var MongoDBMemory = class {
45
+ _isConnected = false;
46
+ _uri;
47
+ _mongoose;
48
+ constructor(uri) {
49
+ this._uri = uri;
50
+ this._mongoose = new import_mongoose.Mongoose();
51
+ }
52
+ getInstance() {
53
+ return this._mongoose;
54
+ }
55
+ async connect() {
56
+ if (this._isConnected) {
57
+ return;
58
+ }
59
+ try {
60
+ await this._mongoose.connect(this._uri);
61
+ this._isConnected = true;
62
+ import_logger.loggers.agent.info("MongoDB connected successfully");
63
+ } catch (error) {
64
+ import_logger.loggers.agent.error("Failed to connect to MongoDB:", error);
65
+ throw error;
66
+ }
67
+ }
68
+ async disconnect() {
69
+ if (!this.isConnected) {
70
+ return;
71
+ }
72
+ try {
73
+ await this._mongoose?.disconnect();
74
+ this._isConnected = false;
75
+ import_logger.loggers.agent.info("MongoDB disconnected successfully");
76
+ } catch (error) {
77
+ import_logger.loggers.agent.error("Failed to disconnect from MongoDB:", error);
78
+ throw error;
79
+ }
80
+ }
81
+ isConnected() {
82
+ return this._isConnected;
83
+ }
84
+ };
39
85
 
40
86
  // models/chats.model.ts
41
- var import_mongoose = __toESM(require("mongoose"), 1);
42
- var ChatRole = /* @__PURE__ */ ((ChatRole2) => {
43
- ChatRole2["USER"] = "USER";
44
- ChatRole2["SYSTEM"] = "SYSTEM";
45
- ChatRole2["MODEL"] = "MODEL";
46
- return ChatRole2;
87
+ var import_mongoose2 = require("mongoose");
88
+ var ChatRole = /* @__PURE__ */ ((ChatRole3) => {
89
+ ChatRole3["USER"] = "USER";
90
+ ChatRole3["SYSTEM"] = "SYSTEM";
91
+ ChatRole3["MODEL"] = "MODEL";
92
+ return ChatRole3;
47
93
  })(ChatRole || {});
48
- var ChatContentObjectSchema = new import_mongoose.Schema(
94
+ var SessionObjectSchema = new import_mongoose2.Schema(
95
+ {
96
+ sessionId: {
97
+ type: String,
98
+ required: true,
99
+ index: true
100
+ },
101
+ userId: {
102
+ type: String,
103
+ required: true,
104
+ index: true
105
+ },
106
+ title: {
107
+ type: String,
108
+ required: false
109
+ },
110
+ created_at: {
111
+ type: Number,
112
+ required: true
113
+ },
114
+ updated_at: {
115
+ type: Number,
116
+ required: true
117
+ }
118
+ }
119
+ );
120
+ var ChatContentObjectSchema = new import_mongoose2.Schema(
49
121
  {
50
122
  type: { type: String, required: true },
51
- parts: { type: [import_mongoose.Schema.Types.Mixed], required: true }
123
+ parts: { type: [import_mongoose2.Schema.Types.Mixed], required: true }
52
124
  },
53
125
  { _id: false }
54
126
  );
55
- var ChatObjectSchema = new import_mongoose.Schema(
127
+ var ChatObjectSchema = new import_mongoose2.Schema(
56
128
  {
57
129
  sessionId: {
58
130
  type: String,
59
131
  required: true,
60
132
  index: true
61
133
  },
134
+ userId: {
135
+ type: String,
136
+ required: true,
137
+ index: true
138
+ },
62
139
  role: {
63
140
  type: String,
64
141
  enum: Object.values(ChatRole),
@@ -73,54 +150,28 @@ var ChatObjectSchema = new import_mongoose.Schema(
73
150
  required: true
74
151
  },
75
152
  metadata: {
76
- type: import_mongoose.Schema.Types.Mixed,
153
+ type: import_mongoose2.Schema.Types.Mixed,
77
154
  default: {}
78
155
  }
79
- },
80
- {
81
- timestamps: true
82
156
  }
83
157
  );
84
- var ChatModel = import_mongoose.default.model("Chat", ChatObjectSchema);
85
158
 
86
- // index.ts
87
- var MongoDBMemory = class extends import_modules.BaseMemory {
88
- isConnected = false;
159
+ // implements/session.memory.ts
160
+ var import_logger2 = require("@ainetwork/adk/utils/logger");
161
+ var MongoDBSession = class extends MongoDBMemory {
162
+ chatModel;
163
+ sessionModel;
89
164
  constructor(uri) {
90
- super();
91
- this.connect(uri);
92
- }
93
- async connect(uri) {
94
- if (this.isConnected) {
95
- return;
96
- }
97
- try {
98
- await import_mongoose2.default.connect(uri);
99
- this.isConnected = true;
100
- import_logger.loggers.agent.info("MongoDB connected successfully");
101
- } catch (error) {
102
- import_logger.loggers.agent.error("Failed to connect to MongoDB:", error);
103
- throw error;
104
- }
105
- }
106
- async disconnect() {
107
- if (!this.isConnected) {
108
- return;
109
- }
110
- try {
111
- await import_mongoose2.default.disconnect();
112
- this.isConnected = false;
113
- import_logger.loggers.agent.info("MongoDB disconnected successfully");
114
- } catch (error) {
115
- import_logger.loggers.agent.error("Failed to disconnect from MongoDB:", error);
116
- throw error;
117
- }
165
+ super(uri);
166
+ const _mongoose = super.getInstance();
167
+ this.chatModel = _mongoose.model("Chat", ChatObjectSchema);
168
+ this.sessionModel = _mongoose.model("Session", SessionObjectSchema);
118
169
  }
119
- async getSessionHistory(sessionId) {
120
- const chats = await ChatModel.find({ sessionId }).sort({
170
+ async getSession(sessionId, userId) {
171
+ const chats = await this.chatModel.find({ sessionId, userId }).sort({
121
172
  timestamp: 1
122
173
  });
123
- import_logger.loggers.agent.info(`Found ${chats.length} chats for session ${sessionId}`);
174
+ import_logger2.loggers.agent.debug(`Found ${chats.length} chats for session ${sessionId}`);
124
175
  const sessionObject = { chats: {} };
125
176
  chats.forEach((chat) => {
126
177
  const chatId = chat._id?.toString() || chat.id;
@@ -133,35 +184,134 @@ var MongoDBMemory = class extends import_modules.BaseMemory {
133
184
  });
134
185
  return sessionObject;
135
186
  }
136
- async updateSessionHistory(sessionId, chat) {
137
- import_logger.loggers.agent.info(`Updating session history for session ${sessionId}`);
138
- import_logger.loggers.agent.info(`Chat: ${JSON.stringify(chat)}`);
139
- await ChatModel.create({
187
+ async createSession(userId, sessionId, title) {
188
+ const now = Date.now();
189
+ await this.sessionModel.create({
190
+ sessionId,
191
+ userId,
192
+ updated_at: now,
193
+ created_at: now
194
+ });
195
+ return { title, sessionId, updatedAt: now };
196
+ }
197
+ async addChatToSession(userId, sessionId, chat) {
198
+ const newId = (0, import_node_crypto.randomUUID)();
199
+ await this.sessionModel.updateOne({ sessionId, userId }, {
200
+ updated_at: Date.now()
201
+ });
202
+ await this.chatModel.create({
140
203
  sessionId,
204
+ chatId: newId,
205
+ userId,
141
206
  role: chat.role,
142
207
  content: chat.content,
143
208
  timestamp: chat.timestamp,
144
209
  metadata: chat.metadata
145
210
  });
146
211
  }
147
- async storeQueryAndIntent(query, intent, sessionId) {
148
- const chat = {
149
- role: "USER" /* USER */,
150
- content: {
151
- type: "text",
152
- parts: [query]
153
- },
154
- timestamp: Date.now(),
155
- metadata: {
156
- intent,
157
- query
158
- }
159
- };
160
- await this.updateSessionHistory(sessionId, chat);
212
+ async deleteSession(userId, sessionId) {
213
+ const chats = await this.chatModel.find({ userId, sessionId }).sort({
214
+ timestamp: 1
215
+ });
216
+ chats?.forEach((chat) => {
217
+ chat.deleteOne();
218
+ });
219
+ const session = await this.sessionModel.findOne({ sessionId, userId });
220
+ session?.deleteOne();
221
+ }
222
+ async listSessions(userId) {
223
+ const sessions = await this.sessionModel.find({ userId }).sort({
224
+ updated_at: -1
225
+ });
226
+ const data = sessions.map((session) => {
227
+ return {
228
+ sessionId: session.sessionId,
229
+ title: session.title,
230
+ updatedAt: session.updated_at
231
+ };
232
+ });
233
+ return data;
234
+ }
235
+ };
236
+
237
+ // implements/intent.memory.ts
238
+ var import_node_crypto2 = require("crypto");
239
+
240
+ // models/intent.model.ts
241
+ var import_mongoose3 = __toESM(require("mongoose"), 1);
242
+ var IntentObjectSchema = new import_mongoose3.Schema(
243
+ {
244
+ name: {
245
+ type: String,
246
+ required: true,
247
+ index: true
248
+ },
249
+ description: {
250
+ type: String,
251
+ required: true
252
+ },
253
+ prompt: {
254
+ type: String,
255
+ required: false
256
+ },
257
+ llm: {
258
+ type: String,
259
+ required: false
260
+ }
261
+ }
262
+ );
263
+ var IntentModel = import_mongoose3.default.model("Intent", IntentObjectSchema);
264
+
265
+ // implements/intent.memory.ts
266
+ var MongoDBIntent = class extends MongoDBMemory {
267
+ async getIntent(intentId) {
268
+ const intent = await IntentModel.findById(intentId);
269
+ if (intent) {
270
+ return {
271
+ name: intent.name,
272
+ description: intent.description,
273
+ prompt: intent.prompt,
274
+ llm: intent.llm
275
+ };
276
+ }
277
+ return void 0;
278
+ }
279
+ async saveIntent(intent) {
280
+ const newId = (0, import_node_crypto2.randomUUID)();
281
+ await IntentModel.create({
282
+ _id: newId,
283
+ name: intent.name,
284
+ description: intent.description,
285
+ prompt: intent.prompt,
286
+ llm: intent.llm
287
+ });
288
+ }
289
+ async updateIntent(intentId, intent) {
290
+ await IntentModel.updateOne({
291
+ _id: intentId
292
+ }, {
293
+ name: intent.name,
294
+ description: intent.description,
295
+ prompt: intent.prompt,
296
+ llm: intent.llm
297
+ });
298
+ }
299
+ async deleteIntent(intentId) {
300
+ await IntentModel.deleteOne({ _id: intentId });
301
+ }
302
+ async listIntents() {
303
+ const intents = await IntentModel.find();
304
+ return intents.map((intent) => ({
305
+ name: intent.name,
306
+ description: intent.description,
307
+ prompt: intent.prompt,
308
+ llm: intent.llm
309
+ }));
161
310
  }
162
311
  };
163
312
  // Annotate the CommonJS export names for ESM import in node:
164
313
  0 && (module.exports = {
165
- MongoDBMemory
314
+ MongoDBIntent,
315
+ MongoDBSession
166
316
  });
167
317
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts","../models/chats.model.ts"],"sourcesContent":["import { BaseMemory } from \"@ainetwork/adk/modules\";\nimport type { ChatObject, SessionObject } from \"@ainetwork/adk/types/memory\";\nimport { loggers } from \"@ainetwork/adk/utils/logger\";\nimport mongoose from \"mongoose\";\nimport {\n\ttype ChatDocument,\n\tChatModel,\n\tChatRole,\n} from \"./models/chats.model\";\n\nexport class MongoDBMemory extends BaseMemory {\n\tprivate isConnected = false;\n\n\tconstructor(uri: string) {\n\t\tsuper();\n\t\tthis.connect(uri);\n\t}\n\n\tpublic async connect(uri: string): Promise<void> {\n\t\tif (this.isConnected) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tawait mongoose.connect(uri);\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\t}\n\n\tpublic 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\t}\n\n\tpublic async getSessionHistory(sessionId: string): Promise<SessionObject> {\n\t\tconst chats = await ChatModel.find({ sessionId }).sort({\n\t\t\ttimestamp: 1,\n\t\t});\n\n\t\tloggers.agent.info(`Found ${chats.length} chats for session ${sessionId}`);\n\n\t\tconst sessionObject: SessionObject = { chats: {} };\n\t\tchats.forEach((chat: ChatDocument) => {\n\t\t\tconst chatId = chat._id?.toString() || chat.id;\n\t\t\tsessionObject.chats[chatId] = {\n\t\t\t\trole: chat.role as ChatRole,\n\t\t\t\tcontent: chat.content,\n\t\t\t\ttimestamp: chat.timestamp,\n\t\t\t\tmetadata: chat.metadata,\n\t\t\t};\n\t\t});\n\n\t\treturn sessionObject;\n\t}\n\n\tpublic async updateSessionHistory(\n\t\tsessionId: string,\n\t\tchat: ChatObject,\n\t): Promise<void> {\n\t\tloggers.agent.info(`Updating session history for session ${sessionId}`);\n\t\tloggers.agent.info(`Chat: ${JSON.stringify(chat)}`);\n\n\t\tawait ChatModel.create({\n\t\t\tsessionId,\n\t\t\trole: chat.role,\n\t\t\tcontent: chat.content,\n\t\t\ttimestamp: chat.timestamp,\n\t\t\tmetadata: chat.metadata,\n\t\t});\n\t}\n\n\tpublic async storeQueryAndIntent(\n\t\tquery: string,\n\t\tintent: string,\n\t\tsessionId: string,\n\t): Promise<void> {\n\t\t// Intent 정보를 metadata에 저장\n\t\tconst chat: ChatObject = {\n\t\t\trole: ChatRole.USER,\n\t\t\tcontent: {\n\t\t\t\ttype: \"text\",\n\t\t\t\tparts: [query],\n\t\t\t},\n\t\t\ttimestamp: Date.now(),\n\t\t\tmetadata: {\n\t\t\t\tintent,\n\t\t\t\tquery,\n\t\t\t},\n\t\t};\n\n\t\tawait this.updateSessionHistory(sessionId, chat);\n\t}\n}\n","import mongoose, { type Document, Schema } from \"mongoose\";\n\n// ChatRole enum\nexport enum ChatRole {\n\tUSER = \"USER\",\n\tSYSTEM = \"SYSTEM\",\n\tMODEL = \"MODEL\",\n}\n\n// ChatContentObject schema\nconst ChatContentObjectSchema = 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// ChatObject schema - 개별 문서로 저장\nconst ChatObjectSchema = new Schema(\n\t{\n\t\tsessionId: {\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(ChatRole),\n\t\t\trequired: true,\n\t\t},\n\t\tcontent: {\n\t\t\ttype: ChatContentObjectSchema,\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\t{\n\t\ttimestamps: true,\n\t},\n);\n\n// Chat Document interface\nexport interface ChatDocument extends Document {\n\tsessionId: string;\n\trole: ChatRole;\n\tcontent: {\n\t\ttype: string;\n\t\tparts: any[];\n\t};\n\ttimestamp: number;\n\tmetadata?: { [key: string]: unknown };\n\tcreatedAt: Date;\n\tupdatedAt: Date;\n}\n\n// Export the model\nexport const ChatModel = mongoose.model<ChatDocument>(\"Chat\", ChatObjectSchema);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA2B;AAE3B,oBAAwB;AACxB,IAAAA,mBAAqB;;;ACHrB,sBAAgD;AAGzC,IAAK,WAAL,kBAAKC,cAAL;AACN,EAAAA,UAAA,UAAO;AACP,EAAAA,UAAA,YAAS;AACT,EAAAA,UAAA,WAAQ;AAHG,SAAAA;AAAA,GAAA;AAOZ,IAAM,0BAA0B,IAAI;AAAA,EACnC;AAAA,IACC,MAAM,EAAE,MAAM,QAAQ,UAAU,KAAK;AAAA,IACrC,OAAO,EAAE,MAAM,CAAC,uBAAO,MAAM,KAAK,GAAG,UAAU,KAAK;AAAA,EACrD;AAAA,EACA,EAAE,KAAK,MAAM;AACd;AAGA,IAAM,mBAAmB,IAAI;AAAA,EAC5B;AAAA,IACC,WAAW;AAAA,MACV,MAAM;AAAA,MACN,UAAU;AAAA,MACV,OAAO;AAAA,IACR;AAAA,IACA,MAAM;AAAA,MACL,MAAM;AAAA,MACN,MAAM,OAAO,OAAO,QAAQ;AAAA,MAC5B,UAAU;AAAA,IAC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,EAAE;AACjD,UAAM,QAAQ,CAAC,SAAuB;AACrC,YAAM,SAAS,KAAK,KAAK,SAAS,KAAK,KAAK;AAC5C,oBAAc,MAAM,MAAM,IAAI;AAAA,QAC7B,MAAM,KAAK;AAAA,QACX,SAAS,KAAK;AAAA,QACd,WAAW,KAAK;AAAA,QAChB,UAAU,KAAK;AAAA,MAChB;AAAA,IACD,CAAC;AAED,WAAO;AAAA,EACR;AAAA,EAEA,MAAa,qBACZ,WACA,MACgB;AAChB,0BAAQ,MAAM,KAAK,wCAAwC,SAAS,EAAE;AACtE,0BAAQ,MAAM,KAAK,SAAS,KAAK,UAAU,IAAI,CAAC,EAAE;AAElD,UAAM,UAAU,OAAO;AAAA,MACtB;AAAA,MACA,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,WAAW,KAAK;AAAA,MAChB,UAAU,KAAK;AAAA,IAChB,CAAC;AAAA,EACF;AAAA,EAEA,MAAa,oBACZ,OACA,QACA,WACgB;AAEhB,UAAM,OAAmB;AAAA,MACxB;AAAA,MACA,SAAS;AAAA,QACR,MAAM;AAAA,QACN,OAAO,CAAC,KAAK;AAAA,MACd;AAAA,MACA,WAAW,KAAK,IAAI;AAAA,MACpB,UAAU;AAAA,QACT;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAEA,UAAM,KAAK,qBAAqB,WAAW,IAAI;AAAA,EAChD;AACD;","names":["import_mongoose","ChatRole","mongoose","mongoose"]}
1
+ {"version":3,"sources":["../index.ts","../implements/session.memory.ts","../implements/base.memory.ts","../models/chats.model.ts","../implements/intent.memory.ts","../models/intent.model.ts"],"sourcesContent":["export { MongoDBSession } from \"./implements/session.memory\";\nexport { MongoDBIntent } from \"./implements/intent.memory\";","import { randomUUID } from \"node:crypto\";\nimport type { ChatObject, SessionMetadata, SessionObject } from \"@ainetwork/adk/types/memory\";\nimport { ISessionMemory } from \"@ainetwork/adk/modules\";\nimport { MongoDBMemory } from \"./base.memory\";\nimport {\n\tChatDocument,\n\tChatRole,\n ChatObjectSchema,\n SessionObjectSchema,\n SessionDocument\n} from \"../models/chats.model\";\nimport { loggers } from \"@ainetwork/adk/utils/logger\";\nimport { Model } from \"mongoose\";\n\nexport class MongoDBSession extends MongoDBMemory implements ISessionMemory {\n private chatModel: Model<ChatDocument>;\n private sessionModel: Model<SessionDocument>;\n\n constructor(uri: string) {\n super(uri);\n const _mongoose = super.getInstance();\n this.chatModel = _mongoose.model<ChatDocument>(\"Chat\", ChatObjectSchema);\n this.sessionModel = _mongoose.model<SessionDocument>(\"Session\", SessionObjectSchema);\n }\n\n public async getSession(sessionId: string, userId?: string): Promise<SessionObject | undefined> {\n\t\tconst chats = await this.chatModel.find({ sessionId, userId }).sort({\n\t\t\ttimestamp: 1,\n\t\t});\n\n\t\tloggers.agent.debug(`Found ${chats.length} chats for session ${sessionId}`);\n\n\t\tconst sessionObject: SessionObject = { chats: {} };\n\t\tchats.forEach((chat: ChatDocument) => {\n\t\t\tconst chatId = chat._id?.toString() || chat.id;\n\t\t\tsessionObject.chats[chatId] = {\n\t\t\t\trole: chat.role as ChatRole,\n\t\t\t\tcontent: chat.content,\n\t\t\t\ttimestamp: chat.timestamp,\n\t\t\t\tmetadata: chat.metadata,\n\t\t\t};\n\t\t});\n\n\t\treturn sessionObject;\n };\n\n\tpublic async createSession(userId: string, sessionId: string, title: string): Promise<SessionMetadata> {\n const now = Date.now();\n await this.sessionModel.create({\n sessionId,\n userId,\n updated_at: now,\n created_at: now,\n });\n\n return { title, sessionId, updatedAt: now };\n };\n\n\tpublic async addChatToSession(userId: string, sessionId: string, chat: ChatObject): Promise<void> {\n const newId = randomUUID();\n await this.sessionModel.updateOne({ sessionId, userId }, {\n updated_at: Date.now(),\n });\n\t\tawait this.chatModel.create({\n\t\t\tsessionId,\n chatId: newId,\n userId,\n\t\t\trole: chat.role,\n\t\t\tcontent: chat.content,\n\t\t\ttimestamp: chat.timestamp,\n\t\t\tmetadata: chat.metadata,\n\t\t});\n };\n\n\tpublic async deleteSession(userId: string, sessionId: string): Promise<void> {\n\t\tconst chats = await this.chatModel.find({ userId, sessionId }).sort({\n\t\t\ttimestamp: 1,\n\t\t});\n\n\t\tchats?.forEach((chat: ChatDocument) => {\n chat.deleteOne();\n\t\t});\n \n const session = await this.sessionModel.findOne({ sessionId, userId });\n session?.deleteOne();\n };\n\n\tpublic async listSessions(userId: string): Promise<SessionMetadata[]> {\n const sessions = await this.sessionModel.find({ userId }).sort({\n updated_at: -1,\n });\n const data: SessionMetadata[] = sessions.map((session: SessionDocument) => {\n return {\n sessionId: session.sessionId,\n title: session.title,\n updatedAt: session.updated_at\n } as SessionMetadata;\n })\n return data;\n };\n}","import { IMemory } from \"node_modules/@ainetwork/adk/dist/esm/modules/memory/base.memory\";\nimport mongoose, { 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 private _mongoose: Mongoose;\n\n constructor(uri: string) {\n this._uri = uri;\n this._mongoose = new Mongoose();\n }\n\n public getInstance(): Mongoose {\n return this._mongoose;\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 this._mongoose.connect(this._uri);\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 this._mongoose?.disconnect();\n\t\t\tthis._isConnected = false;\n\t\t\tloggers.agent.info(\"MongoDB disconnected successfully\");\n\t\t} catch (error) {\n\t\t\tloggers.agent.error(\"Failed to disconnect from MongoDB:\", error);\n\t\t\tthrow error;\n\t\t}\n }\n\n public isConnected(): boolean {\n return this._isConnected;\n }\n}","import { type Document, Schema } from \"mongoose\";\n\n// ChatRole enum\nexport enum ChatRole {\n\tUSER = \"USER\",\n\tSYSTEM = \"SYSTEM\",\n\tMODEL = \"MODEL\",\n}\n\nexport const SessionObjectSchema = new Schema(\n\t{\n\t\tsessionId: {\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 SessionDocument extends Document {\n\tsessionId: string;\n\tuserId: string;\n\ttitle?: string;\n\tcreated_at: number;\n\tupdated_at: number;\n}\n\n// ChatContentObject schema\nexport const ChatContentObjectSchema = 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// ChatObject schema - 개별 문서로 저장\nexport const ChatObjectSchema = new Schema(\n\t{\n\t\tsessionId: {\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(ChatRole),\n\t\t\trequired: true,\n\t\t},\n\t\tcontent: {\n\t\t\ttype: ChatContentObjectSchema,\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// Chat Document interface\nexport interface ChatDocument extends Document {\n\tsessionId: string;\n\trole: ChatRole;\n\tcontent: {\n\t\ttype: string;\n\t\tparts: any[];\n\t};\n\ttimestamp: number;\n\tmetadata?: { [key: string]: unknown };\n\tcreatedAt: Date;\n\tupdatedAt: Date;\n}\n","import { randomUUID } from \"node:crypto\";\nimport type { Intent } from \"@ainetwork/adk/types/memory\";\nimport { IIntentMemory } from \"@ainetwork/adk/modules\";\nimport { MongoDBMemory } from \"./base.memory\";\nimport { IntentModel } from \"../models/intent.model\";\n\nexport class MongoDBIntent extends MongoDBMemory implements IIntentMemory {\n public async getIntent(intentId: string): Promise<Intent | undefined> {\n const intent = await IntentModel.findById(intentId);\n if (intent) {\n return {\n name: intent.name,\n description: intent.description,\n prompt: intent.prompt,\n llm: intent.llm,\n } as Intent;\n }\n return undefined;\n };\n\n\tpublic async saveIntent(intent: Intent): Promise<void> {\n const newId = randomUUID();\n await IntentModel.create({\n _id: newId,\n name: intent.name,\n description: intent.description,\n prompt: intent.prompt,\n llm: intent.llm,\n });\n };\n\n\tpublic async updateIntent(intentId: string, intent: Intent): Promise<void> {\n await IntentModel.updateOne({\n _id: intentId,\n },{\n name: intent.name,\n description: intent.description,\n prompt: intent.prompt,\n llm: intent.llm,\n });\n };\n\n\tpublic async deleteIntent(intentId: string): Promise<void> {\n await IntentModel.deleteOne({ _id: intentId });\n };\n\n\tpublic async listIntents(): Promise<Intent[]> {\n const intents = await IntentModel.find();\n return intents.map(intent => ({\n name: intent.name,\n description: intent.description,\n prompt: intent.prompt,\n llm: intent.llm,\n } as Intent));\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\tllm: {\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\tllm?: string;\n}\n\nexport const IntentModel = mongoose.model<IntentDocument>(\"Intent\", IntentObjectSchema);"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,yBAA2B;;;ACC3B,sBAAmC;AACnC,oBAAwB;AAEjB,IAAM,gBAAN,MAAuC;AAAA,EACpC,eAAwB;AAAA,EACxB;AAAA,EACA;AAAA,EAER,YAAY,KAAa;AACvB,SAAK,OAAO;AACZ,SAAK,YAAY,IAAI,yBAAS;AAAA,EAChC;AAAA,EAEO,cAAwB;AAC7B,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,UAAyB;AACtC,QAAI,KAAK,cAAc;AACtB;AAAA,IACD;AAEA,QAAI;AACA,YAAM,KAAK,UAAU,QAAQ,KAAK,IAAI;AACzC,WAAK,eAAe;AACpB,4BAAQ,MAAM,KAAK,gCAAgC;AAAA,IACpD,SAAS,OAAO;AACf,4BAAQ,MAAM,MAAM,iCAAiC,KAAK;AAC1D,YAAM;AAAA,IACP;AAAA,EACA;AAAA,EAEA,MAAa,aAA4B;AACzC,QAAI,CAAC,KAAK,aAAa;AACtB;AAAA,IACD;AAEA,QAAI;AACH,YAAM,KAAK,WAAW,WAAW;AACjC,WAAK,eAAe;AACpB,4BAAQ,MAAM,KAAK,mCAAmC;AAAA,IACvD,SAAS,OAAO;AACf,4BAAQ,MAAM,MAAM,sCAAsC,KAAK;AAC/D,YAAM;AAAA,IACP;AAAA,EACA;AAAA,EAEO,cAAuB;AAC5B,WAAO,KAAK;AAAA,EACd;AACF;;;ACnDA,IAAAA,mBAAsC;AAG/B,IAAK,WAAL,kBAAKC,cAAL;AACN,EAAAA,UAAA,UAAO;AACP,EAAAA,UAAA,YAAS;AACT,EAAAA,UAAA,WAAQ;AAHG,SAAAA;AAAA,GAAA;AAML,IAAM,sBAAsB,IAAI;AAAA,EACtC;AAAA,IACC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ACb,aAAa,OAAO;AAAA,QACpB,QAAQ,OAAO;AAAA,QACf,KAAK,OAAO;AAAA,MACd;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAED,MAAa,WAAW,QAA+B;AACpD,UAAM,YAAQ,gCAAW;AACzB,UAAM,YAAY,OAAO;AAAA,MACvB,KAAK;AAAA,MACL,MAAM,OAAO;AAAA,MACb,aAAa,OAAO;AAAA,MACpB,QAAQ,OAAO;AAAA,MACf,KAAK,OAAO;AAAA,IACd,CAAC;AAAA,EACH;AAAA,EAED,MAAa,aAAa,UAAkB,QAA+B;AACxE,UAAM,YAAY,UAAU;AAAA,MAC1B,KAAK;AAAA,IACP,GAAE;AAAA,MACA,MAAM,OAAO;AAAA,MACb,aAAa,OAAO;AAAA,MACpB,QAAQ,OAAO;AAAA,MACf,KAAK,OAAO;AAAA,IACd,CAAC;AAAA,EACH;AAAA,EAED,MAAa,aAAa,UAAiC;AACxD,UAAM,YAAY,UAAU,EAAE,KAAK,SAAS,CAAC;AAAA,EAC/C;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,MACf,KAAK,OAAO;AAAA,IACd,EAAY;AAAA,EACd;AACF;","names":["import_mongoose","ChatRole","import_logger","import_node_crypto","import_mongoose","mongoose"]}
package/dist/index.d.cts CHANGED
@@ -1,14 +1,36 @@
1
- import { BaseMemory } from '@ainetwork/adk/modules';
2
- import { SessionObject, ChatObject } from '@ainetwork/adk/types/memory';
1
+ import { SessionObject, SessionMetadata, ChatObject, Intent } from '@ainetwork/adk/types/memory';
2
+ import { ISessionMemory, IIntentMemory } from '@ainetwork/adk/modules';
3
+ import { IMemory } from 'node_modules/@ainetwork/adk/dist/esm/modules/memory/base.memory';
4
+ import { Mongoose } from 'mongoose';
3
5
 
4
- declare class MongoDBMemory extends BaseMemory {
5
- private isConnected;
6
+ declare class MongoDBMemory implements IMemory {
7
+ private _isConnected;
8
+ private _uri;
9
+ private _mongoose;
6
10
  constructor(uri: string);
7
- connect(uri: string): Promise<void>;
11
+ getInstance(): Mongoose;
12
+ connect(): Promise<void>;
8
13
  disconnect(): Promise<void>;
9
- getSessionHistory(sessionId: string): Promise<SessionObject>;
10
- updateSessionHistory(sessionId: string, chat: ChatObject): Promise<void>;
11
- storeQueryAndIntent(query: string, intent: string, sessionId: string): Promise<void>;
14
+ isConnected(): boolean;
12
15
  }
13
16
 
14
- export { MongoDBMemory };
17
+ declare class MongoDBSession extends MongoDBMemory implements ISessionMemory {
18
+ private chatModel;
19
+ private sessionModel;
20
+ constructor(uri: string);
21
+ getSession(sessionId: string, userId?: string): Promise<SessionObject | undefined>;
22
+ createSession(userId: string, sessionId: string, title: string): Promise<SessionMetadata>;
23
+ addChatToSession(userId: string, sessionId: string, chat: ChatObject): Promise<void>;
24
+ deleteSession(userId: string, sessionId: string): Promise<void>;
25
+ listSessions(userId: string): Promise<SessionMetadata[]>;
26
+ }
27
+
28
+ declare class MongoDBIntent extends MongoDBMemory implements IIntentMemory {
29
+ getIntent(intentId: string): Promise<Intent | undefined>;
30
+ saveIntent(intent: Intent): Promise<void>;
31
+ updateIntent(intentId: string, intent: Intent): Promise<void>;
32
+ deleteIntent(intentId: string): Promise<void>;
33
+ listIntents(): Promise<Intent[]>;
34
+ }
35
+
36
+ export { MongoDBIntent, MongoDBSession };
package/dist/index.d.ts CHANGED
@@ -1,14 +1,36 @@
1
- import { BaseMemory } from '@ainetwork/adk/modules';
2
- import { SessionObject, ChatObject } from '@ainetwork/adk/types/memory';
1
+ import { SessionObject, SessionMetadata, ChatObject, Intent } from '@ainetwork/adk/types/memory';
2
+ import { ISessionMemory, IIntentMemory } from '@ainetwork/adk/modules';
3
+ import { IMemory } from 'node_modules/@ainetwork/adk/dist/esm/modules/memory/base.memory';
4
+ import { Mongoose } from 'mongoose';
3
5
 
4
- declare class MongoDBMemory extends BaseMemory {
5
- private isConnected;
6
+ declare class MongoDBMemory implements IMemory {
7
+ private _isConnected;
8
+ private _uri;
9
+ private _mongoose;
6
10
  constructor(uri: string);
7
- connect(uri: string): Promise<void>;
11
+ getInstance(): Mongoose;
12
+ connect(): Promise<void>;
8
13
  disconnect(): Promise<void>;
9
- getSessionHistory(sessionId: string): Promise<SessionObject>;
10
- updateSessionHistory(sessionId: string, chat: ChatObject): Promise<void>;
11
- storeQueryAndIntent(query: string, intent: string, sessionId: string): Promise<void>;
14
+ isConnected(): boolean;
12
15
  }
13
16
 
14
- export { MongoDBMemory };
17
+ declare class MongoDBSession extends MongoDBMemory implements ISessionMemory {
18
+ private chatModel;
19
+ private sessionModel;
20
+ constructor(uri: string);
21
+ getSession(sessionId: string, userId?: string): Promise<SessionObject | undefined>;
22
+ createSession(userId: string, sessionId: string, title: string): Promise<SessionMetadata>;
23
+ addChatToSession(userId: string, sessionId: string, chat: ChatObject): Promise<void>;
24
+ deleteSession(userId: string, sessionId: string): Promise<void>;
25
+ listSessions(userId: string): Promise<SessionMetadata[]>;
26
+ }
27
+
28
+ declare class MongoDBIntent extends MongoDBMemory implements IIntentMemory {
29
+ getIntent(intentId: string): Promise<Intent | undefined>;
30
+ saveIntent(intent: Intent): Promise<void>;
31
+ updateIntent(intentId: string, intent: Intent): Promise<void>;
32
+ deleteIntent(intentId: string): Promise<void>;
33
+ listIntents(): Promise<Intent[]>;
34
+ }
35
+
36
+ export { MongoDBIntent, MongoDBSession };