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