@ainetwork/adk-provider-memory-mongodb 0.6.2 → 0.7.1
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-JMRBIQNX.js +96 -0
- package/dist/chunk-JMRBIQNX.js.map +1 -0
- package/dist/index.cjs +213 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +90 -0
- package/dist/index.js.map +1 -1
- package/dist/models/document.model.cjs +128 -0
- package/dist/models/document.model.cjs.map +1 -0
- package/dist/models/document.model.d.cts +87 -0
- package/dist/models/document.model.d.ts +87 -0
- package/dist/models/document.model.js +9 -0
- package/dist/models/document.model.js.map +1 -0
- package/dist/models/messages.model.d.cts +6 -6
- package/dist/models/messages.model.d.ts +6 -6
- package/dist/models/workflow-template.model.d.cts +3 -3
- package/dist/models/workflow-template.model.d.ts +3 -3
- package/implements/base.memory.ts +12 -1
- package/implements/document.memory.ts +125 -0
- package/models/document.model.ts +113 -0
- package/package.json +3 -3
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// models/document.model.ts
|
|
2
|
+
import {
|
|
3
|
+
DocumentFormat,
|
|
4
|
+
DocumentSource
|
|
5
|
+
} from "@ainetwork/adk/types/document";
|
|
6
|
+
import { Schema } from "mongoose";
|
|
7
|
+
import mongoose from "mongoose";
|
|
8
|
+
var DocumentObjectSchema = new Schema(
|
|
9
|
+
{
|
|
10
|
+
documentId: {
|
|
11
|
+
type: String,
|
|
12
|
+
required: true,
|
|
13
|
+
unique: true
|
|
14
|
+
},
|
|
15
|
+
userId: {
|
|
16
|
+
type: String,
|
|
17
|
+
required: true,
|
|
18
|
+
index: true
|
|
19
|
+
},
|
|
20
|
+
title: {
|
|
21
|
+
type: String,
|
|
22
|
+
required: true
|
|
23
|
+
},
|
|
24
|
+
format: {
|
|
25
|
+
type: String,
|
|
26
|
+
enum: Object.values(DocumentFormat),
|
|
27
|
+
required: true,
|
|
28
|
+
default: DocumentFormat.MARKDOWN
|
|
29
|
+
},
|
|
30
|
+
content: {
|
|
31
|
+
type: String,
|
|
32
|
+
required: true
|
|
33
|
+
},
|
|
34
|
+
blocks: {
|
|
35
|
+
type: Schema.Types.Mixed
|
|
36
|
+
},
|
|
37
|
+
slots: {
|
|
38
|
+
type: Schema.Types.Mixed
|
|
39
|
+
},
|
|
40
|
+
// Cached AI advice ({ content, generatedAt }). Free-form so the schema
|
|
41
|
+
// doesn't strip it on update (mongoose strict mode).
|
|
42
|
+
advice: {
|
|
43
|
+
type: Schema.Types.Mixed
|
|
44
|
+
},
|
|
45
|
+
// Faceted grouping (e.g. category/workplaceId/month). Stored as a free
|
|
46
|
+
// map; index specific keys (e.g. `labels.workplaceId`) if query volume
|
|
47
|
+
// warrants it.
|
|
48
|
+
labels: {
|
|
49
|
+
type: Schema.Types.Mixed
|
|
50
|
+
},
|
|
51
|
+
source: {
|
|
52
|
+
type: String,
|
|
53
|
+
enum: Object.values(DocumentSource),
|
|
54
|
+
required: true
|
|
55
|
+
},
|
|
56
|
+
workflowId: {
|
|
57
|
+
type: String,
|
|
58
|
+
index: true
|
|
59
|
+
},
|
|
60
|
+
threadId: {
|
|
61
|
+
type: String,
|
|
62
|
+
index: true
|
|
63
|
+
},
|
|
64
|
+
version: {
|
|
65
|
+
type: Number,
|
|
66
|
+
required: true,
|
|
67
|
+
default: 1
|
|
68
|
+
},
|
|
69
|
+
editedManually: {
|
|
70
|
+
type: Boolean
|
|
71
|
+
},
|
|
72
|
+
createdAt: {
|
|
73
|
+
type: String,
|
|
74
|
+
required: true
|
|
75
|
+
},
|
|
76
|
+
updatedAt: {
|
|
77
|
+
type: String,
|
|
78
|
+
required: true
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
// `createdAt`/`updatedAt` are caller-supplied ISO strings (see Document type),
|
|
82
|
+
// so mongoose's automatic Date timestamps are intentionally disabled.
|
|
83
|
+
{
|
|
84
|
+
timestamps: false
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
var DocumentModel = mongoose.model(
|
|
88
|
+
"Document",
|
|
89
|
+
DocumentObjectSchema
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
export {
|
|
93
|
+
DocumentObjectSchema,
|
|
94
|
+
DocumentModel
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=chunk-JMRBIQNX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../models/document.model.ts"],"sourcesContent":["import {\n\ttype DocumentAdvice,\n\tDocumentFormat,\n\ttype DocumentSlot,\n\tDocumentSource,\n} from \"@ainetwork/adk/types/document\";\nimport type { WorkflowRenderedBlock } from \"@ainetwork/adk/types/memory\";\nimport { type Document, Schema } from \"mongoose\";\nimport mongoose from \"mongoose\";\n\nexport const DocumentObjectSchema = new Schema(\n\t{\n\t\tdocumentId: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t\tunique: 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: true,\n\t\t},\n\t\tformat: {\n\t\t\ttype: String,\n\t\t\tenum: Object.values(DocumentFormat),\n\t\t\trequired: true,\n\t\t\tdefault: DocumentFormat.MARKDOWN,\n\t\t},\n\t\tcontent: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t},\n\t\tblocks: {\n\t\t\ttype: Schema.Types.Mixed,\n\t\t},\n\t\tslots: {\n\t\t\ttype: Schema.Types.Mixed,\n\t\t},\n\t\t// Cached AI advice ({ content, generatedAt }). Free-form so the schema\n\t\t// doesn't strip it on update (mongoose strict mode).\n\t\tadvice: {\n\t\t\ttype: Schema.Types.Mixed,\n\t\t},\n\t\t// Faceted grouping (e.g. category/workplaceId/month). Stored as a free\n\t\t// map; index specific keys (e.g. `labels.workplaceId`) if query volume\n\t\t// warrants it.\n\t\tlabels: {\n\t\t\ttype: Schema.Types.Mixed,\n\t\t},\n\t\tsource: {\n\t\t\ttype: String,\n\t\t\tenum: Object.values(DocumentSource),\n\t\t\trequired: true,\n\t\t},\n\t\tworkflowId: {\n\t\t\ttype: String,\n\t\t\tindex: true,\n\t\t},\n\t\tthreadId: {\n\t\t\ttype: String,\n\t\t\tindex: true,\n\t\t},\n\t\tversion: {\n\t\t\ttype: Number,\n\t\t\trequired: true,\n\t\t\tdefault: 1,\n\t\t},\n\t\teditedManually: {\n\t\t\ttype: Boolean,\n\t\t},\n\t\tcreatedAt: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t},\n\t\tupdatedAt: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t},\n\t},\n\t// `createdAt`/`updatedAt` are caller-supplied ISO strings (see Document type),\n\t// so mongoose's automatic Date timestamps are intentionally disabled.\n\t{\n\t\ttimestamps: false,\n\t}\n);\n\nexport interface DocumentDocument extends Document {\n\tdocumentId: string;\n\tuserId: string;\n\ttitle: string;\n\tformat: DocumentFormat;\n\tcontent: string;\n\tblocks?: WorkflowRenderedBlock[];\n\tslots?: DocumentSlot[];\n\tadvice?: DocumentAdvice;\n\tlabels?: Record<string, string>;\n\tsource: DocumentSource;\n\tworkflowId?: string;\n\tthreadId?: string;\n\tversion: number;\n\teditedManually?: boolean;\n\tcreatedAt: string;\n\tupdatedAt: string;\n}\n\nexport const DocumentModel = mongoose.model<DocumentDocument>(\n\t\"Document\",\n\tDocumentObjectSchema\n);\n"],"mappings":";AAAA;AAAA,EAEC;AAAA,EAEA;AAAA,OACM;AAEP,SAAwB,cAAc;AACtC,OAAO,cAAc;AAEd,IAAM,uBAAuB,IAAI;AAAA,EACvC;AAAA,IACC,YAAY;AAAA,MACX,MAAM;AAAA,MACN,UAAU;AAAA,MACV,QAAQ;AAAA,IACT;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,QAAQ;AAAA,MACP,MAAM;AAAA,MACN,MAAM,OAAO,OAAO,cAAc;AAAA,MAClC,UAAU;AAAA,MACV,SAAS,eAAe;AAAA,IACzB;AAAA,IACA,SAAS;AAAA,MACR,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,IACA,QAAQ;AAAA,MACP,MAAM,OAAO,MAAM;AAAA,IACpB;AAAA,IACA,OAAO;AAAA,MACN,MAAM,OAAO,MAAM;AAAA,IACpB;AAAA;AAAA;AAAA,IAGA,QAAQ;AAAA,MACP,MAAM,OAAO,MAAM;AAAA,IACpB;AAAA;AAAA;AAAA;AAAA,IAIA,QAAQ;AAAA,MACP,MAAM,OAAO,MAAM;AAAA,IACpB;AAAA,IACA,QAAQ;AAAA,MACP,MAAM;AAAA,MACN,MAAM,OAAO,OAAO,cAAc;AAAA,MAClC,UAAU;AAAA,IACX;AAAA,IACA,YAAY;AAAA,MACX,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA,UAAU;AAAA,MACT,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA,SAAS;AAAA,MACR,MAAM;AAAA,MACN,UAAU;AAAA,MACV,SAAS;AAAA,IACV;AAAA,IACA,gBAAgB;AAAA,MACf,MAAM;AAAA,IACP;AAAA,IACA,WAAW;AAAA,MACV,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,IACA,WAAW;AAAA,MACV,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,EACD;AAAA;AAAA;AAAA,EAGA;AAAA,IACC,YAAY;AAAA,EACb;AACD;AAqBO,IAAM,gBAAgB,SAAS;AAAA,EACrC;AAAA,EACA;AACD;","names":[]}
|
package/dist/index.cjs
CHANGED
|
@@ -35,7 +35,7 @@ __export(index_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(index_exports);
|
|
36
36
|
|
|
37
37
|
// implements/base.memory.ts
|
|
38
|
-
var
|
|
38
|
+
var import_mongoose14 = __toESM(require("mongoose"), 1);
|
|
39
39
|
var import_logger2 = require("@ainetwork/adk/utils/logger");
|
|
40
40
|
|
|
41
41
|
// models/agent.model.ts
|
|
@@ -145,9 +145,176 @@ var MongoDBAgent = class {
|
|
|
145
145
|
}
|
|
146
146
|
};
|
|
147
147
|
|
|
148
|
+
// models/document.model.ts
|
|
149
|
+
var import_document = require("@ainetwork/adk/types/document");
|
|
150
|
+
var import_mongoose3 = require("mongoose");
|
|
151
|
+
var import_mongoose4 = __toESM(require("mongoose"), 1);
|
|
152
|
+
var DocumentObjectSchema = new import_mongoose3.Schema(
|
|
153
|
+
{
|
|
154
|
+
documentId: {
|
|
155
|
+
type: String,
|
|
156
|
+
required: true,
|
|
157
|
+
unique: true
|
|
158
|
+
},
|
|
159
|
+
userId: {
|
|
160
|
+
type: String,
|
|
161
|
+
required: true,
|
|
162
|
+
index: true
|
|
163
|
+
},
|
|
164
|
+
title: {
|
|
165
|
+
type: String,
|
|
166
|
+
required: true
|
|
167
|
+
},
|
|
168
|
+
format: {
|
|
169
|
+
type: String,
|
|
170
|
+
enum: Object.values(import_document.DocumentFormat),
|
|
171
|
+
required: true,
|
|
172
|
+
default: import_document.DocumentFormat.MARKDOWN
|
|
173
|
+
},
|
|
174
|
+
content: {
|
|
175
|
+
type: String,
|
|
176
|
+
required: true
|
|
177
|
+
},
|
|
178
|
+
blocks: {
|
|
179
|
+
type: import_mongoose3.Schema.Types.Mixed
|
|
180
|
+
},
|
|
181
|
+
slots: {
|
|
182
|
+
type: import_mongoose3.Schema.Types.Mixed
|
|
183
|
+
},
|
|
184
|
+
// Cached AI advice ({ content, generatedAt }). Free-form so the schema
|
|
185
|
+
// doesn't strip it on update (mongoose strict mode).
|
|
186
|
+
advice: {
|
|
187
|
+
type: import_mongoose3.Schema.Types.Mixed
|
|
188
|
+
},
|
|
189
|
+
// Faceted grouping (e.g. category/workplaceId/month). Stored as a free
|
|
190
|
+
// map; index specific keys (e.g. `labels.workplaceId`) if query volume
|
|
191
|
+
// warrants it.
|
|
192
|
+
labels: {
|
|
193
|
+
type: import_mongoose3.Schema.Types.Mixed
|
|
194
|
+
},
|
|
195
|
+
source: {
|
|
196
|
+
type: String,
|
|
197
|
+
enum: Object.values(import_document.DocumentSource),
|
|
198
|
+
required: true
|
|
199
|
+
},
|
|
200
|
+
workflowId: {
|
|
201
|
+
type: String,
|
|
202
|
+
index: true
|
|
203
|
+
},
|
|
204
|
+
threadId: {
|
|
205
|
+
type: String,
|
|
206
|
+
index: true
|
|
207
|
+
},
|
|
208
|
+
version: {
|
|
209
|
+
type: Number,
|
|
210
|
+
required: true,
|
|
211
|
+
default: 1
|
|
212
|
+
},
|
|
213
|
+
editedManually: {
|
|
214
|
+
type: Boolean
|
|
215
|
+
},
|
|
216
|
+
createdAt: {
|
|
217
|
+
type: String,
|
|
218
|
+
required: true
|
|
219
|
+
},
|
|
220
|
+
updatedAt: {
|
|
221
|
+
type: String,
|
|
222
|
+
required: true
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
// `createdAt`/`updatedAt` are caller-supplied ISO strings (see Document type),
|
|
226
|
+
// so mongoose's automatic Date timestamps are intentionally disabled.
|
|
227
|
+
{
|
|
228
|
+
timestamps: false
|
|
229
|
+
}
|
|
230
|
+
);
|
|
231
|
+
var DocumentModel = import_mongoose4.default.model(
|
|
232
|
+
"Document",
|
|
233
|
+
DocumentObjectSchema
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
// implements/document.memory.ts
|
|
237
|
+
var MongoDBDocument = class {
|
|
238
|
+
executeWithRetry;
|
|
239
|
+
getOperationTimeout;
|
|
240
|
+
constructor(executeWithRetry, getOperationTimeout) {
|
|
241
|
+
this.executeWithRetry = executeWithRetry;
|
|
242
|
+
this.getOperationTimeout = getOperationTimeout;
|
|
243
|
+
}
|
|
244
|
+
async getDocument(documentId) {
|
|
245
|
+
return this.executeWithRetry(async () => {
|
|
246
|
+
const timeout = this.getOperationTimeout();
|
|
247
|
+
const document = await DocumentModel.findOne({ documentId }).maxTimeMS(timeout).lean();
|
|
248
|
+
return document || void 0;
|
|
249
|
+
}, "getDocument()");
|
|
250
|
+
}
|
|
251
|
+
async createDocument(document) {
|
|
252
|
+
return this.executeWithRetry(async () => {
|
|
253
|
+
const created = await DocumentModel.create(document);
|
|
254
|
+
return created.toObject();
|
|
255
|
+
}, "createDocument()");
|
|
256
|
+
}
|
|
257
|
+
async updateDocument(documentId, document) {
|
|
258
|
+
const { documentId: _documentId, ...mutableUpdates } = document;
|
|
259
|
+
return this.executeWithRetry(async () => {
|
|
260
|
+
const timeout = this.getOperationTimeout();
|
|
261
|
+
await DocumentModel.updateOne(
|
|
262
|
+
{ documentId },
|
|
263
|
+
{ $set: mutableUpdates }
|
|
264
|
+
).maxTimeMS(timeout);
|
|
265
|
+
}, "updateDocument()");
|
|
266
|
+
}
|
|
267
|
+
async updateDocumentSlot(documentId, slotId, patch) {
|
|
268
|
+
const { slotId: _slotId, ...fields } = patch;
|
|
269
|
+
const set = { updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
270
|
+
const unset = {};
|
|
271
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
272
|
+
if (value === void 0) {
|
|
273
|
+
unset[`slots.$.${key}`] = "";
|
|
274
|
+
} else {
|
|
275
|
+
set[`slots.$.${key}`] = value;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
const update = { $set: set, $inc: { version: 1 } };
|
|
279
|
+
if (Object.keys(unset).length > 0) {
|
|
280
|
+
update.$unset = unset;
|
|
281
|
+
}
|
|
282
|
+
return this.executeWithRetry(async () => {
|
|
283
|
+
const timeout = this.getOperationTimeout();
|
|
284
|
+
await DocumentModel.updateOne(
|
|
285
|
+
{ documentId, "slots.slotId": slotId },
|
|
286
|
+
update
|
|
287
|
+
).maxTimeMS(timeout);
|
|
288
|
+
}, "updateDocumentSlot()");
|
|
289
|
+
}
|
|
290
|
+
async deleteDocument(documentId) {
|
|
291
|
+
return this.executeWithRetry(async () => {
|
|
292
|
+
const timeout = this.getOperationTimeout();
|
|
293
|
+
await DocumentModel.deleteOne({ documentId }).maxTimeMS(timeout);
|
|
294
|
+
}, "deleteDocument()");
|
|
295
|
+
}
|
|
296
|
+
async listDocuments(userId, filter) {
|
|
297
|
+
return this.executeWithRetry(async () => {
|
|
298
|
+
const timeout = this.getOperationTimeout();
|
|
299
|
+
const query = {};
|
|
300
|
+
if (userId) query.userId = userId;
|
|
301
|
+
if (filter?.workflowId) query.workflowId = filter.workflowId;
|
|
302
|
+
if (filter?.threadId) query.threadId = filter.threadId;
|
|
303
|
+
if (filter?.source) query.source = filter.source;
|
|
304
|
+
if (filter?.labels) {
|
|
305
|
+
for (const [key, value] of Object.entries(filter.labels)) {
|
|
306
|
+
query[`labels.${key}`] = value;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
const documents = await DocumentModel.find(query).maxTimeMS(timeout).lean();
|
|
310
|
+
return documents;
|
|
311
|
+
}, "listDocuments()");
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
|
|
148
315
|
// models/intent.model.ts
|
|
149
|
-
var
|
|
150
|
-
var IntentObjectSchema = new
|
|
316
|
+
var import_mongoose5 = __toESM(require("mongoose"), 1);
|
|
317
|
+
var IntentObjectSchema = new import_mongoose5.Schema(
|
|
151
318
|
{
|
|
152
319
|
id: {
|
|
153
320
|
type: String,
|
|
@@ -187,7 +354,7 @@ var IntentObjectSchema = new import_mongoose3.Schema(
|
|
|
187
354
|
}
|
|
188
355
|
}
|
|
189
356
|
);
|
|
190
|
-
var IntentModel =
|
|
357
|
+
var IntentModel = import_mongoose5.default.model("Intent", IntentObjectSchema);
|
|
191
358
|
|
|
192
359
|
// implements/intent.memory.ts
|
|
193
360
|
var MongoDBIntent = class {
|
|
@@ -241,9 +408,9 @@ var MongoDBIntent = class {
|
|
|
241
408
|
|
|
242
409
|
// models/threads.model.ts
|
|
243
410
|
var import_memory = require("@ainetwork/adk/types/memory");
|
|
244
|
-
var
|
|
245
|
-
var
|
|
246
|
-
var ThreadObjectSchema = new
|
|
411
|
+
var import_mongoose6 = require("mongoose");
|
|
412
|
+
var import_mongoose7 = __toESM(require("mongoose"), 1);
|
|
413
|
+
var ThreadObjectSchema = new import_mongoose6.Schema(
|
|
247
414
|
{
|
|
248
415
|
type: {
|
|
249
416
|
type: String,
|
|
@@ -279,20 +446,20 @@ var ThreadObjectSchema = new import_mongoose4.Schema(
|
|
|
279
446
|
timestamps: true
|
|
280
447
|
}
|
|
281
448
|
);
|
|
282
|
-
var ThreadModel =
|
|
449
|
+
var ThreadModel = import_mongoose7.default.model("Thread", ThreadObjectSchema);
|
|
283
450
|
|
|
284
451
|
// models/messages.model.ts
|
|
285
452
|
var import_memory2 = require("@ainetwork/adk/types/memory");
|
|
286
|
-
var
|
|
287
|
-
var
|
|
288
|
-
var MessageContentObjectSchema = new
|
|
453
|
+
var import_mongoose8 = require("mongoose");
|
|
454
|
+
var import_mongoose9 = __toESM(require("mongoose"), 1);
|
|
455
|
+
var MessageContentObjectSchema = new import_mongoose8.Schema(
|
|
289
456
|
{
|
|
290
457
|
type: { type: String, required: true },
|
|
291
|
-
parts: { type: [
|
|
458
|
+
parts: { type: [import_mongoose8.Schema.Types.Mixed], required: true }
|
|
292
459
|
},
|
|
293
460
|
{ _id: false }
|
|
294
461
|
);
|
|
295
|
-
var MessageObjectSchema = new
|
|
462
|
+
var MessageObjectSchema = new import_mongoose8.Schema(
|
|
296
463
|
{
|
|
297
464
|
messageId: {
|
|
298
465
|
type: String,
|
|
@@ -323,7 +490,7 @@ var MessageObjectSchema = new import_mongoose6.Schema(
|
|
|
323
490
|
required: true
|
|
324
491
|
},
|
|
325
492
|
metadata: {
|
|
326
|
-
type:
|
|
493
|
+
type: import_mongoose8.Schema.Types.Mixed,
|
|
327
494
|
default: {}
|
|
328
495
|
}
|
|
329
496
|
},
|
|
@@ -332,7 +499,7 @@ var MessageObjectSchema = new import_mongoose6.Schema(
|
|
|
332
499
|
}
|
|
333
500
|
);
|
|
334
501
|
MessageObjectSchema.index({ threadId: 1, messageId: 1 }, { unique: true });
|
|
335
|
-
var MessageModel =
|
|
502
|
+
var MessageModel = import_mongoose9.default.model("Message", MessageObjectSchema);
|
|
336
503
|
|
|
337
504
|
// implements/thread.memory.ts
|
|
338
505
|
var import_logger = require("@ainetwork/adk/utils/logger");
|
|
@@ -447,9 +614,9 @@ var MongoDBThread = class {
|
|
|
447
614
|
};
|
|
448
615
|
|
|
449
616
|
// models/user-workflow.model.ts
|
|
450
|
-
var
|
|
451
|
-
var
|
|
452
|
-
var UserWorkflowObjectSchema = new
|
|
617
|
+
var import_mongoose10 = require("mongoose");
|
|
618
|
+
var import_mongoose11 = __toESM(require("mongoose"), 1);
|
|
619
|
+
var UserWorkflowObjectSchema = new import_mongoose10.Schema(
|
|
453
620
|
{
|
|
454
621
|
workflowId: {
|
|
455
622
|
type: String,
|
|
@@ -484,13 +651,13 @@ var UserWorkflowObjectSchema = new import_mongoose8.Schema(
|
|
|
484
651
|
required: true
|
|
485
652
|
},
|
|
486
653
|
definition: {
|
|
487
|
-
type:
|
|
654
|
+
type: import_mongoose10.Schema.Types.Mixed
|
|
488
655
|
},
|
|
489
656
|
variables: {
|
|
490
|
-
type:
|
|
657
|
+
type: import_mongoose10.Schema.Types.Mixed
|
|
491
658
|
},
|
|
492
659
|
variableValues: {
|
|
493
|
-
type:
|
|
660
|
+
type: import_mongoose10.Schema.Types.Mixed
|
|
494
661
|
},
|
|
495
662
|
schedule: {
|
|
496
663
|
type: String
|
|
@@ -512,7 +679,7 @@ var UserWorkflowObjectSchema = new import_mongoose8.Schema(
|
|
|
512
679
|
timestamps: true
|
|
513
680
|
}
|
|
514
681
|
);
|
|
515
|
-
var UserWorkflowModel =
|
|
682
|
+
var UserWorkflowModel = import_mongoose11.default.model(
|
|
516
683
|
"UserWorkflow",
|
|
517
684
|
UserWorkflowObjectSchema
|
|
518
685
|
);
|
|
@@ -578,9 +745,9 @@ var MongoDBUserWorkflow = class {
|
|
|
578
745
|
};
|
|
579
746
|
|
|
580
747
|
// models/workflow-template.model.ts
|
|
581
|
-
var
|
|
582
|
-
var
|
|
583
|
-
var WorkflowTemplateObjectSchema = new
|
|
748
|
+
var import_mongoose12 = require("mongoose");
|
|
749
|
+
var import_mongoose13 = __toESM(require("mongoose"), 1);
|
|
750
|
+
var WorkflowTemplateObjectSchema = new import_mongoose12.Schema(
|
|
584
751
|
{
|
|
585
752
|
templateId: {
|
|
586
753
|
type: String,
|
|
@@ -608,17 +775,17 @@ var WorkflowTemplateObjectSchema = new import_mongoose10.Schema(
|
|
|
608
775
|
required: true
|
|
609
776
|
},
|
|
610
777
|
definition: {
|
|
611
|
-
type:
|
|
778
|
+
type: import_mongoose12.Schema.Types.Mixed
|
|
612
779
|
},
|
|
613
780
|
variables: {
|
|
614
|
-
type:
|
|
781
|
+
type: import_mongoose12.Schema.Types.Mixed
|
|
615
782
|
}
|
|
616
783
|
},
|
|
617
784
|
{
|
|
618
785
|
timestamps: true
|
|
619
786
|
}
|
|
620
787
|
);
|
|
621
|
-
var WorkflowTemplateModel =
|
|
788
|
+
var WorkflowTemplateModel = import_mongoose13.default.model(
|
|
622
789
|
"WorkflowTemplate",
|
|
623
790
|
WorkflowTemplateObjectSchema
|
|
624
791
|
);
|
|
@@ -688,6 +855,7 @@ var MongoDBMemory = class _MongoDBMemory {
|
|
|
688
855
|
threadMemory;
|
|
689
856
|
workflowTemplateMemory;
|
|
690
857
|
userWorkflowMemory;
|
|
858
|
+
documentMemory;
|
|
691
859
|
constructor(config) {
|
|
692
860
|
const cfg = typeof config === "string" ? { uri: config } : config;
|
|
693
861
|
this.uri = cfg.uri;
|
|
@@ -733,6 +901,10 @@ var MongoDBMemory = class _MongoDBMemory {
|
|
|
733
901
|
this.executeWithRetry.bind(this),
|
|
734
902
|
this.getOperationTimeout.bind(this)
|
|
735
903
|
);
|
|
904
|
+
this.documentMemory = new MongoDBDocument(
|
|
905
|
+
this.executeWithRetry.bind(this),
|
|
906
|
+
this.getOperationTimeout.bind(this)
|
|
907
|
+
);
|
|
736
908
|
}
|
|
737
909
|
getAgentMemory() {
|
|
738
910
|
return this.agentMemory;
|
|
@@ -749,26 +921,29 @@ var MongoDBMemory = class _MongoDBMemory {
|
|
|
749
921
|
getUserWorkflowMemory() {
|
|
750
922
|
return this.userWorkflowMemory;
|
|
751
923
|
}
|
|
924
|
+
getDocumentMemory() {
|
|
925
|
+
return this.documentMemory;
|
|
926
|
+
}
|
|
752
927
|
setupMongooseEventListeners() {
|
|
753
928
|
if (this.eventListenersSetup) return;
|
|
754
929
|
this.eventListenersSetup = true;
|
|
755
|
-
|
|
930
|
+
import_mongoose14.default.connection.on("connected", () => {
|
|
756
931
|
this.connected = true;
|
|
757
932
|
this.reconnectAttempts = 0;
|
|
758
933
|
this.reconnecting = false;
|
|
759
934
|
import_logger2.loggers.agent.info("MongoDB connected successfully");
|
|
760
935
|
});
|
|
761
|
-
|
|
936
|
+
import_mongoose14.default.connection.on("disconnected", () => {
|
|
762
937
|
this.connected = false;
|
|
763
938
|
import_logger2.loggers.agent.warn("MongoDB disconnected");
|
|
764
939
|
this.handleDisconnection();
|
|
765
940
|
});
|
|
766
|
-
|
|
941
|
+
import_mongoose14.default.connection.on("error", (error) => {
|
|
767
942
|
this.connected = false;
|
|
768
943
|
import_logger2.loggers.agent.error("MongoDB connection error:", error);
|
|
769
944
|
this.handleDisconnection();
|
|
770
945
|
});
|
|
771
|
-
|
|
946
|
+
import_mongoose14.default.connection.on("reconnected", () => {
|
|
772
947
|
this.connected = true;
|
|
773
948
|
this.reconnectAttempts = 0;
|
|
774
949
|
this.reconnecting = false;
|
|
@@ -786,7 +961,7 @@ var MongoDBMemory = class _MongoDBMemory {
|
|
|
786
961
|
`Attempting to reconnect to MongoDB (${this.reconnectAttempts}/${this.maxReconnectAttempts})...`
|
|
787
962
|
);
|
|
788
963
|
try {
|
|
789
|
-
await
|
|
964
|
+
await import_mongoose14.default.connect(this.uri, this.connectionConfig);
|
|
790
965
|
this.connected = true;
|
|
791
966
|
this.reconnectAttempts = 0;
|
|
792
967
|
this.reconnecting = false;
|
|
@@ -816,7 +991,7 @@ var MongoDBMemory = class _MongoDBMemory {
|
|
|
816
991
|
return;
|
|
817
992
|
}
|
|
818
993
|
try {
|
|
819
|
-
await
|
|
994
|
+
await import_mongoose14.default.connect(this.uri, this.connectionConfig);
|
|
820
995
|
this.connected = true;
|
|
821
996
|
this.reconnectAttempts = 0;
|
|
822
997
|
await this.setupTTLIndex();
|
|
@@ -835,7 +1010,7 @@ var MongoDBMemory = class _MongoDBMemory {
|
|
|
835
1010
|
clearInterval(this.orphanCleanupTimer);
|
|
836
1011
|
this.orphanCleanupTimer = void 0;
|
|
837
1012
|
}
|
|
838
|
-
await
|
|
1013
|
+
await import_mongoose14.default.disconnect();
|
|
839
1014
|
this.connected = false;
|
|
840
1015
|
} catch (error) {
|
|
841
1016
|
import_logger2.loggers.agent.error("Failed to disconnect from MongoDB:", error);
|
|
@@ -861,7 +1036,7 @@ var MongoDBMemory = class _MongoDBMemory {
|
|
|
861
1036
|
async setupTTLIndex() {
|
|
862
1037
|
if (this.threadTTLSeconds === void 0) return;
|
|
863
1038
|
try {
|
|
864
|
-
const db =
|
|
1039
|
+
const db = import_mongoose14.default.connection.db;
|
|
865
1040
|
if (!db) return;
|
|
866
1041
|
const collection = db.collection("threads");
|
|
867
1042
|
const indexes = await collection.indexes();
|
|
@@ -901,7 +1076,7 @@ var MongoDBMemory = class _MongoDBMemory {
|
|
|
901
1076
|
async cleanupOrphanedMessages() {
|
|
902
1077
|
if (!this.connected) return;
|
|
903
1078
|
try {
|
|
904
|
-
const db =
|
|
1079
|
+
const db = import_mongoose14.default.connection.db;
|
|
905
1080
|
if (!db) return;
|
|
906
1081
|
const existingThreadIds = await db.collection("threads").distinct("threadId");
|
|
907
1082
|
const result = await MessageModel.deleteMany({
|
|
@@ -938,7 +1113,7 @@ var MongoDBMemory = class _MongoDBMemory {
|
|
|
938
1113
|
`${operationName} failed due to too many sessions, disconnecting to release sessions...`
|
|
939
1114
|
);
|
|
940
1115
|
try {
|
|
941
|
-
await
|
|
1116
|
+
await import_mongoose14.default.disconnect();
|
|
942
1117
|
this.connected = false;
|
|
943
1118
|
} catch (disconnectError) {
|
|
944
1119
|
import_logger2.loggers.agent.error("Failed to disconnect during session cleanup:", disconnectError);
|