@ainetwork/adk-provider-memory-mongodb 0.1.2 → 0.1.3
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/chunk-JCE5NAY5.js +29 -0
- package/dist/chunk-JCE5NAY5.js.map +1 -0
- package/dist/{chunk-2SB2M62A.js → chunk-SS7OXU6N.js} +31 -7
- package/dist/chunk-SS7OXU6N.js.map +1 -0
- package/dist/index.cjs +218 -70
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +31 -9
- package/dist/index.d.ts +31 -9
- package/dist/index.js +139 -37
- package/dist/index.js.map +1 -1
- package/dist/models/chats.model.cjs +35 -19
- package/dist/models/chats.model.cjs.map +1 -1
- package/dist/models/chats.model.d.cts +81 -7
- package/dist/models/chats.model.d.ts +81 -7
- package/dist/models/chats.model.js +9 -5
- package/dist/models/{intentTriggeringInfos.model.cjs → intent.model.cjs} +22 -28
- package/dist/models/intent.model.cjs.map +1 -0
- package/dist/models/intent.model.d.cts +15 -0
- package/dist/models/intent.model.d.ts +15 -0
- package/dist/models/intent.model.js +7 -0
- package/dist/models/intent.model.js.map +1 -0
- package/package.json +2 -2
- package/dist/chunk-2SB2M62A.js.map +0 -1
- package/dist/models/intentTriggeringInfos.model.cjs.map +0 -1
- package/dist/models/intentTriggeringInfos.model.d.cts +0 -29
- package/dist/models/intentTriggeringInfos.model.d.ts +0 -29
- package/dist/models/intentTriggeringInfos.model.js +0 -34
- package/dist/models/intentTriggeringInfos.model.js.map +0 -1
|
@@ -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
|
|
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 },
|
|
@@ -37,15 +63,13 @@ var ChatObjectSchema = new Schema(
|
|
|
37
63
|
type: Schema.Types.Mixed,
|
|
38
64
|
default: {}
|
|
39
65
|
}
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
timestamps: true
|
|
43
66
|
}
|
|
44
67
|
);
|
|
45
|
-
var ChatModel = mongoose.model("Chat", ChatObjectSchema);
|
|
46
68
|
|
|
47
69
|
export {
|
|
48
70
|
ChatRole,
|
|
49
|
-
|
|
71
|
+
SessionObjectSchema,
|
|
72
|
+
ChatContentObjectSchema,
|
|
73
|
+
ChatObjectSchema
|
|
50
74
|
};
|
|
51
|
-
//# sourceMappingURL=chunk-
|
|
75
|
+
//# sourceMappingURL=chunk-SS7OXU6N.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\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,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,29 +30,101 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
|
|
33
|
+
MongoDBIntent: () => MongoDBIntent,
|
|
34
|
+
MongoDBSession: () => MongoDBSession
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(index_exports);
|
|
36
|
-
|
|
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
|
|
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
|
|
42
|
-
var ChatRole = /* @__PURE__ */ ((
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return
|
|
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
|
|
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: [
|
|
123
|
+
parts: { type: [import_mongoose2.Schema.Types.Mixed], required: true }
|
|
52
124
|
},
|
|
53
125
|
{ _id: false }
|
|
54
126
|
);
|
|
55
|
-
var ChatObjectSchema = new
|
|
127
|
+
var ChatObjectSchema = new import_mongoose2.Schema(
|
|
56
128
|
{
|
|
57
129
|
sessionId: {
|
|
58
130
|
type: String,
|
|
@@ -73,54 +145,28 @@ var ChatObjectSchema = new import_mongoose.Schema(
|
|
|
73
145
|
required: true
|
|
74
146
|
},
|
|
75
147
|
metadata: {
|
|
76
|
-
type:
|
|
148
|
+
type: import_mongoose2.Schema.Types.Mixed,
|
|
77
149
|
default: {}
|
|
78
150
|
}
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
timestamps: true
|
|
82
151
|
}
|
|
83
152
|
);
|
|
84
|
-
var ChatModel = import_mongoose.default.model("Chat", ChatObjectSchema);
|
|
85
153
|
|
|
86
|
-
//
|
|
87
|
-
var
|
|
88
|
-
|
|
154
|
+
// implements/session.memory.ts
|
|
155
|
+
var import_logger2 = require("@ainetwork/adk/utils/logger");
|
|
156
|
+
var MongoDBSession = class extends MongoDBMemory {
|
|
157
|
+
chatModel;
|
|
158
|
+
sessionModel;
|
|
89
159
|
constructor(uri) {
|
|
90
|
-
super();
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
}
|
|
160
|
+
super(uri);
|
|
161
|
+
const _mongoose = super.getInstance();
|
|
162
|
+
this.chatModel = _mongoose.model("Chat", ChatObjectSchema);
|
|
163
|
+
this.sessionModel = _mongoose.model("Session", SessionObjectSchema);
|
|
105
164
|
}
|
|
106
|
-
async
|
|
107
|
-
|
|
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
|
-
}
|
|
118
|
-
}
|
|
119
|
-
async getSessionHistory(sessionId) {
|
|
120
|
-
const chats = await ChatModel.find({ sessionId }).sort({
|
|
165
|
+
async getSession(sessionId, userId) {
|
|
166
|
+
const chats = await this.chatModel.find({ sessionId }).sort({
|
|
121
167
|
timestamp: 1
|
|
122
168
|
});
|
|
123
|
-
|
|
169
|
+
import_logger2.loggers.agent.debug(`Found ${chats.length} chats for session ${sessionId}`);
|
|
124
170
|
const sessionObject = { chats: {} };
|
|
125
171
|
chats.forEach((chat) => {
|
|
126
172
|
const chatId = chat._id?.toString() || chat.id;
|
|
@@ -133,35 +179,137 @@ var MongoDBMemory = class extends import_modules.BaseMemory {
|
|
|
133
179
|
});
|
|
134
180
|
return sessionObject;
|
|
135
181
|
}
|
|
136
|
-
async
|
|
137
|
-
|
|
138
|
-
import_logger.loggers.agent.info(`Chat: ${JSON.stringify(chat)}`);
|
|
139
|
-
await ChatModel.create({
|
|
182
|
+
async createSession(userId, sessionId) {
|
|
183
|
+
await this.sessionModel.create({
|
|
140
184
|
sessionId,
|
|
185
|
+
userId,
|
|
186
|
+
updated_at: Date.now(),
|
|
187
|
+
created_at: Date.now()
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
async addChatToSession(userId, sessionId, chat) {
|
|
191
|
+
const newId = (0, import_node_crypto.randomUUID)();
|
|
192
|
+
const session = await this.sessionModel.findOne({ sessionId, userId });
|
|
193
|
+
if (!session) {
|
|
194
|
+
await this.createSession(userId, sessionId);
|
|
195
|
+
} else {
|
|
196
|
+
await this.sessionModel.updateOne({ sessionId, userId }, {
|
|
197
|
+
updated_at: Date.now()
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
await this.chatModel.create({
|
|
201
|
+
sessionId,
|
|
202
|
+
chatId: newId,
|
|
203
|
+
userId,
|
|
141
204
|
role: chat.role,
|
|
142
205
|
content: chat.content,
|
|
143
206
|
timestamp: chat.timestamp,
|
|
144
207
|
metadata: chat.metadata
|
|
145
208
|
});
|
|
146
209
|
}
|
|
147
|
-
async
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
210
|
+
async deleteSession(userId, sessionId) {
|
|
211
|
+
const chats = await this.chatModel.find({ userId, sessionId }).sort({
|
|
212
|
+
timestamp: 1
|
|
213
|
+
});
|
|
214
|
+
chats?.forEach((chat) => {
|
|
215
|
+
chat.deleteOne();
|
|
216
|
+
});
|
|
217
|
+
const session = await this.sessionModel.findOne({ sessionId, userId });
|
|
218
|
+
session?.deleteOne();
|
|
219
|
+
}
|
|
220
|
+
async listSessions(userId) {
|
|
221
|
+
const sessions = await this.sessionModel.find({ userId }).sort({
|
|
222
|
+
updated_at: -1
|
|
223
|
+
});
|
|
224
|
+
const data = sessions.map((session) => {
|
|
225
|
+
return {
|
|
226
|
+
sessionId: session.sessionId,
|
|
227
|
+
title: session.title,
|
|
228
|
+
updatedAt: session.updated_at
|
|
229
|
+
};
|
|
230
|
+
});
|
|
231
|
+
return data;
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
// implements/intent.memory.ts
|
|
236
|
+
var import_node_crypto2 = require("crypto");
|
|
237
|
+
|
|
238
|
+
// models/intent.model.ts
|
|
239
|
+
var import_mongoose3 = __toESM(require("mongoose"), 1);
|
|
240
|
+
var IntentObjectSchema = new import_mongoose3.Schema(
|
|
241
|
+
{
|
|
242
|
+
name: {
|
|
243
|
+
type: String,
|
|
244
|
+
required: true,
|
|
245
|
+
index: true
|
|
246
|
+
},
|
|
247
|
+
description: {
|
|
248
|
+
type: String,
|
|
249
|
+
required: true
|
|
250
|
+
},
|
|
251
|
+
prompt: {
|
|
252
|
+
type: String,
|
|
253
|
+
required: false
|
|
254
|
+
},
|
|
255
|
+
llm: {
|
|
256
|
+
type: String,
|
|
257
|
+
required: false
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
);
|
|
261
|
+
var IntentModel = import_mongoose3.default.model("Intent", IntentObjectSchema);
|
|
262
|
+
|
|
263
|
+
// implements/intent.memory.ts
|
|
264
|
+
var MongoDBIntent = class extends MongoDBMemory {
|
|
265
|
+
async getIntent(intentId) {
|
|
266
|
+
const intent = await IntentModel.findById(intentId);
|
|
267
|
+
if (intent) {
|
|
268
|
+
return {
|
|
269
|
+
name: intent.name,
|
|
270
|
+
description: intent.description,
|
|
271
|
+
prompt: intent.prompt,
|
|
272
|
+
llm: intent.llm
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
return void 0;
|
|
276
|
+
}
|
|
277
|
+
async saveIntent(intent) {
|
|
278
|
+
const newId = (0, import_node_crypto2.randomUUID)();
|
|
279
|
+
await IntentModel.create({
|
|
280
|
+
_id: newId,
|
|
281
|
+
name: intent.name,
|
|
282
|
+
description: intent.description,
|
|
283
|
+
prompt: intent.prompt,
|
|
284
|
+
llm: intent.llm
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
async updateIntent(intentId, intent) {
|
|
288
|
+
await IntentModel.updateOne({
|
|
289
|
+
_id: intentId
|
|
290
|
+
}, {
|
|
291
|
+
name: intent.name,
|
|
292
|
+
description: intent.description,
|
|
293
|
+
prompt: intent.prompt,
|
|
294
|
+
llm: intent.llm
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
async deleteIntent(intentId) {
|
|
298
|
+
await IntentModel.deleteOne({ _id: intentId });
|
|
299
|
+
}
|
|
300
|
+
async listIntents() {
|
|
301
|
+
const intents = await IntentModel.find();
|
|
302
|
+
return intents.map((intent) => ({
|
|
303
|
+
name: intent.name,
|
|
304
|
+
description: intent.description,
|
|
305
|
+
prompt: intent.prompt,
|
|
306
|
+
llm: intent.llm
|
|
307
|
+
}));
|
|
161
308
|
}
|
|
162
309
|
};
|
|
163
310
|
// Annotate the CommonJS export names for ESM import in node:
|
|
164
311
|
0 && (module.exports = {
|
|
165
|
-
|
|
312
|
+
MongoDBIntent,
|
|
313
|
+
MongoDBSession
|
|
166
314
|
});
|
|
167
315
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -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,U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;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 }).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): Promise<void> {\n await this.sessionModel.create({\n sessionId,\n userId,\n updated_at: Date.now(),\n created_at: Date.now(),\n });\n };\n\n\tpublic async addChatToSession(userId: string, sessionId: string, chat: ChatObject): Promise<void> {\n const newId = randomUUID();\n const session = await this.sessionModel.findOne({ sessionId, userId });\n if (!session) {\n await this.createSession(userId, sessionId);\n } else {\n await this.sessionModel.updateOne({ sessionId, userId }, {\n updated_at: Date.now(),\n });\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\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,K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ACpB,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 {
|
|
2
|
-
import {
|
|
1
|
+
import { SessionObject, ChatObject, SessionMetadata, 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
|
|
5
|
-
private
|
|
6
|
+
declare class MongoDBMemory implements IMemory {
|
|
7
|
+
private _isConnected;
|
|
8
|
+
private _uri;
|
|
9
|
+
private _mongoose;
|
|
6
10
|
constructor(uri: string);
|
|
7
|
-
|
|
11
|
+
getInstance(): Mongoose;
|
|
12
|
+
connect(): Promise<void>;
|
|
8
13
|
disconnect(): Promise<void>;
|
|
9
|
-
|
|
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
|
-
|
|
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): Promise<void>;
|
|
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 {
|
|
2
|
-
import {
|
|
1
|
+
import { SessionObject, ChatObject, SessionMetadata, 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
|
|
5
|
-
private
|
|
6
|
+
declare class MongoDBMemory implements IMemory {
|
|
7
|
+
private _isConnected;
|
|
8
|
+
private _uri;
|
|
9
|
+
private _mongoose;
|
|
6
10
|
constructor(uri: string);
|
|
7
|
-
|
|
11
|
+
getInstance(): Mongoose;
|
|
12
|
+
connect(): Promise<void>;
|
|
8
13
|
disconnect(): Promise<void>;
|
|
9
|
-
|
|
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
|
-
|
|
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): Promise<void>;
|
|
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 };
|