@ainetwork/adk-provider-memory-mongodb 0.6.2 → 0.7.0
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 +190 -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 +67 -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 +9 -9
- package/dist/models/messages.model.d.ts +9 -9
- package/dist/models/threads.model.d.cts +6 -6
- package/dist/models/threads.model.d.ts +6 -6
- package/dist/models/user-workflow.model.d.cts +3 -3
- package/dist/models/user-workflow.model.d.ts +3 -3
- package/implements/base.memory.ts +12 -1
- package/implements/document.memory.ts +88 -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,153 @@ 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 deleteDocument(documentId) {
|
|
268
|
+
return this.executeWithRetry(async () => {
|
|
269
|
+
const timeout = this.getOperationTimeout();
|
|
270
|
+
await DocumentModel.deleteOne({ documentId }).maxTimeMS(timeout);
|
|
271
|
+
}, "deleteDocument()");
|
|
272
|
+
}
|
|
273
|
+
async listDocuments(userId, filter) {
|
|
274
|
+
return this.executeWithRetry(async () => {
|
|
275
|
+
const timeout = this.getOperationTimeout();
|
|
276
|
+
const query = {};
|
|
277
|
+
if (userId) query.userId = userId;
|
|
278
|
+
if (filter?.workflowId) query.workflowId = filter.workflowId;
|
|
279
|
+
if (filter?.threadId) query.threadId = filter.threadId;
|
|
280
|
+
if (filter?.source) query.source = filter.source;
|
|
281
|
+
if (filter?.labels) {
|
|
282
|
+
for (const [key, value] of Object.entries(filter.labels)) {
|
|
283
|
+
query[`labels.${key}`] = value;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
const documents = await DocumentModel.find(query).maxTimeMS(timeout).lean();
|
|
287
|
+
return documents;
|
|
288
|
+
}, "listDocuments()");
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
|
|
148
292
|
// models/intent.model.ts
|
|
149
|
-
var
|
|
150
|
-
var IntentObjectSchema = new
|
|
293
|
+
var import_mongoose5 = __toESM(require("mongoose"), 1);
|
|
294
|
+
var IntentObjectSchema = new import_mongoose5.Schema(
|
|
151
295
|
{
|
|
152
296
|
id: {
|
|
153
297
|
type: String,
|
|
@@ -187,7 +331,7 @@ var IntentObjectSchema = new import_mongoose3.Schema(
|
|
|
187
331
|
}
|
|
188
332
|
}
|
|
189
333
|
);
|
|
190
|
-
var IntentModel =
|
|
334
|
+
var IntentModel = import_mongoose5.default.model("Intent", IntentObjectSchema);
|
|
191
335
|
|
|
192
336
|
// implements/intent.memory.ts
|
|
193
337
|
var MongoDBIntent = class {
|
|
@@ -241,9 +385,9 @@ var MongoDBIntent = class {
|
|
|
241
385
|
|
|
242
386
|
// models/threads.model.ts
|
|
243
387
|
var import_memory = require("@ainetwork/adk/types/memory");
|
|
244
|
-
var
|
|
245
|
-
var
|
|
246
|
-
var ThreadObjectSchema = new
|
|
388
|
+
var import_mongoose6 = require("mongoose");
|
|
389
|
+
var import_mongoose7 = __toESM(require("mongoose"), 1);
|
|
390
|
+
var ThreadObjectSchema = new import_mongoose6.Schema(
|
|
247
391
|
{
|
|
248
392
|
type: {
|
|
249
393
|
type: String,
|
|
@@ -279,20 +423,20 @@ var ThreadObjectSchema = new import_mongoose4.Schema(
|
|
|
279
423
|
timestamps: true
|
|
280
424
|
}
|
|
281
425
|
);
|
|
282
|
-
var ThreadModel =
|
|
426
|
+
var ThreadModel = import_mongoose7.default.model("Thread", ThreadObjectSchema);
|
|
283
427
|
|
|
284
428
|
// models/messages.model.ts
|
|
285
429
|
var import_memory2 = require("@ainetwork/adk/types/memory");
|
|
286
|
-
var
|
|
287
|
-
var
|
|
288
|
-
var MessageContentObjectSchema = new
|
|
430
|
+
var import_mongoose8 = require("mongoose");
|
|
431
|
+
var import_mongoose9 = __toESM(require("mongoose"), 1);
|
|
432
|
+
var MessageContentObjectSchema = new import_mongoose8.Schema(
|
|
289
433
|
{
|
|
290
434
|
type: { type: String, required: true },
|
|
291
|
-
parts: { type: [
|
|
435
|
+
parts: { type: [import_mongoose8.Schema.Types.Mixed], required: true }
|
|
292
436
|
},
|
|
293
437
|
{ _id: false }
|
|
294
438
|
);
|
|
295
|
-
var MessageObjectSchema = new
|
|
439
|
+
var MessageObjectSchema = new import_mongoose8.Schema(
|
|
296
440
|
{
|
|
297
441
|
messageId: {
|
|
298
442
|
type: String,
|
|
@@ -323,7 +467,7 @@ var MessageObjectSchema = new import_mongoose6.Schema(
|
|
|
323
467
|
required: true
|
|
324
468
|
},
|
|
325
469
|
metadata: {
|
|
326
|
-
type:
|
|
470
|
+
type: import_mongoose8.Schema.Types.Mixed,
|
|
327
471
|
default: {}
|
|
328
472
|
}
|
|
329
473
|
},
|
|
@@ -332,7 +476,7 @@ var MessageObjectSchema = new import_mongoose6.Schema(
|
|
|
332
476
|
}
|
|
333
477
|
);
|
|
334
478
|
MessageObjectSchema.index({ threadId: 1, messageId: 1 }, { unique: true });
|
|
335
|
-
var MessageModel =
|
|
479
|
+
var MessageModel = import_mongoose9.default.model("Message", MessageObjectSchema);
|
|
336
480
|
|
|
337
481
|
// implements/thread.memory.ts
|
|
338
482
|
var import_logger = require("@ainetwork/adk/utils/logger");
|
|
@@ -447,9 +591,9 @@ var MongoDBThread = class {
|
|
|
447
591
|
};
|
|
448
592
|
|
|
449
593
|
// models/user-workflow.model.ts
|
|
450
|
-
var
|
|
451
|
-
var
|
|
452
|
-
var UserWorkflowObjectSchema = new
|
|
594
|
+
var import_mongoose10 = require("mongoose");
|
|
595
|
+
var import_mongoose11 = __toESM(require("mongoose"), 1);
|
|
596
|
+
var UserWorkflowObjectSchema = new import_mongoose10.Schema(
|
|
453
597
|
{
|
|
454
598
|
workflowId: {
|
|
455
599
|
type: String,
|
|
@@ -484,13 +628,13 @@ var UserWorkflowObjectSchema = new import_mongoose8.Schema(
|
|
|
484
628
|
required: true
|
|
485
629
|
},
|
|
486
630
|
definition: {
|
|
487
|
-
type:
|
|
631
|
+
type: import_mongoose10.Schema.Types.Mixed
|
|
488
632
|
},
|
|
489
633
|
variables: {
|
|
490
|
-
type:
|
|
634
|
+
type: import_mongoose10.Schema.Types.Mixed
|
|
491
635
|
},
|
|
492
636
|
variableValues: {
|
|
493
|
-
type:
|
|
637
|
+
type: import_mongoose10.Schema.Types.Mixed
|
|
494
638
|
},
|
|
495
639
|
schedule: {
|
|
496
640
|
type: String
|
|
@@ -512,7 +656,7 @@ var UserWorkflowObjectSchema = new import_mongoose8.Schema(
|
|
|
512
656
|
timestamps: true
|
|
513
657
|
}
|
|
514
658
|
);
|
|
515
|
-
var UserWorkflowModel =
|
|
659
|
+
var UserWorkflowModel = import_mongoose11.default.model(
|
|
516
660
|
"UserWorkflow",
|
|
517
661
|
UserWorkflowObjectSchema
|
|
518
662
|
);
|
|
@@ -578,9 +722,9 @@ var MongoDBUserWorkflow = class {
|
|
|
578
722
|
};
|
|
579
723
|
|
|
580
724
|
// models/workflow-template.model.ts
|
|
581
|
-
var
|
|
582
|
-
var
|
|
583
|
-
var WorkflowTemplateObjectSchema = new
|
|
725
|
+
var import_mongoose12 = require("mongoose");
|
|
726
|
+
var import_mongoose13 = __toESM(require("mongoose"), 1);
|
|
727
|
+
var WorkflowTemplateObjectSchema = new import_mongoose12.Schema(
|
|
584
728
|
{
|
|
585
729
|
templateId: {
|
|
586
730
|
type: String,
|
|
@@ -608,17 +752,17 @@ var WorkflowTemplateObjectSchema = new import_mongoose10.Schema(
|
|
|
608
752
|
required: true
|
|
609
753
|
},
|
|
610
754
|
definition: {
|
|
611
|
-
type:
|
|
755
|
+
type: import_mongoose12.Schema.Types.Mixed
|
|
612
756
|
},
|
|
613
757
|
variables: {
|
|
614
|
-
type:
|
|
758
|
+
type: import_mongoose12.Schema.Types.Mixed
|
|
615
759
|
}
|
|
616
760
|
},
|
|
617
761
|
{
|
|
618
762
|
timestamps: true
|
|
619
763
|
}
|
|
620
764
|
);
|
|
621
|
-
var WorkflowTemplateModel =
|
|
765
|
+
var WorkflowTemplateModel = import_mongoose13.default.model(
|
|
622
766
|
"WorkflowTemplate",
|
|
623
767
|
WorkflowTemplateObjectSchema
|
|
624
768
|
);
|
|
@@ -688,6 +832,7 @@ var MongoDBMemory = class _MongoDBMemory {
|
|
|
688
832
|
threadMemory;
|
|
689
833
|
workflowTemplateMemory;
|
|
690
834
|
userWorkflowMemory;
|
|
835
|
+
documentMemory;
|
|
691
836
|
constructor(config) {
|
|
692
837
|
const cfg = typeof config === "string" ? { uri: config } : config;
|
|
693
838
|
this.uri = cfg.uri;
|
|
@@ -733,6 +878,10 @@ var MongoDBMemory = class _MongoDBMemory {
|
|
|
733
878
|
this.executeWithRetry.bind(this),
|
|
734
879
|
this.getOperationTimeout.bind(this)
|
|
735
880
|
);
|
|
881
|
+
this.documentMemory = new MongoDBDocument(
|
|
882
|
+
this.executeWithRetry.bind(this),
|
|
883
|
+
this.getOperationTimeout.bind(this)
|
|
884
|
+
);
|
|
736
885
|
}
|
|
737
886
|
getAgentMemory() {
|
|
738
887
|
return this.agentMemory;
|
|
@@ -749,26 +898,29 @@ var MongoDBMemory = class _MongoDBMemory {
|
|
|
749
898
|
getUserWorkflowMemory() {
|
|
750
899
|
return this.userWorkflowMemory;
|
|
751
900
|
}
|
|
901
|
+
getDocumentMemory() {
|
|
902
|
+
return this.documentMemory;
|
|
903
|
+
}
|
|
752
904
|
setupMongooseEventListeners() {
|
|
753
905
|
if (this.eventListenersSetup) return;
|
|
754
906
|
this.eventListenersSetup = true;
|
|
755
|
-
|
|
907
|
+
import_mongoose14.default.connection.on("connected", () => {
|
|
756
908
|
this.connected = true;
|
|
757
909
|
this.reconnectAttempts = 0;
|
|
758
910
|
this.reconnecting = false;
|
|
759
911
|
import_logger2.loggers.agent.info("MongoDB connected successfully");
|
|
760
912
|
});
|
|
761
|
-
|
|
913
|
+
import_mongoose14.default.connection.on("disconnected", () => {
|
|
762
914
|
this.connected = false;
|
|
763
915
|
import_logger2.loggers.agent.warn("MongoDB disconnected");
|
|
764
916
|
this.handleDisconnection();
|
|
765
917
|
});
|
|
766
|
-
|
|
918
|
+
import_mongoose14.default.connection.on("error", (error) => {
|
|
767
919
|
this.connected = false;
|
|
768
920
|
import_logger2.loggers.agent.error("MongoDB connection error:", error);
|
|
769
921
|
this.handleDisconnection();
|
|
770
922
|
});
|
|
771
|
-
|
|
923
|
+
import_mongoose14.default.connection.on("reconnected", () => {
|
|
772
924
|
this.connected = true;
|
|
773
925
|
this.reconnectAttempts = 0;
|
|
774
926
|
this.reconnecting = false;
|
|
@@ -786,7 +938,7 @@ var MongoDBMemory = class _MongoDBMemory {
|
|
|
786
938
|
`Attempting to reconnect to MongoDB (${this.reconnectAttempts}/${this.maxReconnectAttempts})...`
|
|
787
939
|
);
|
|
788
940
|
try {
|
|
789
|
-
await
|
|
941
|
+
await import_mongoose14.default.connect(this.uri, this.connectionConfig);
|
|
790
942
|
this.connected = true;
|
|
791
943
|
this.reconnectAttempts = 0;
|
|
792
944
|
this.reconnecting = false;
|
|
@@ -816,7 +968,7 @@ var MongoDBMemory = class _MongoDBMemory {
|
|
|
816
968
|
return;
|
|
817
969
|
}
|
|
818
970
|
try {
|
|
819
|
-
await
|
|
971
|
+
await import_mongoose14.default.connect(this.uri, this.connectionConfig);
|
|
820
972
|
this.connected = true;
|
|
821
973
|
this.reconnectAttempts = 0;
|
|
822
974
|
await this.setupTTLIndex();
|
|
@@ -835,7 +987,7 @@ var MongoDBMemory = class _MongoDBMemory {
|
|
|
835
987
|
clearInterval(this.orphanCleanupTimer);
|
|
836
988
|
this.orphanCleanupTimer = void 0;
|
|
837
989
|
}
|
|
838
|
-
await
|
|
990
|
+
await import_mongoose14.default.disconnect();
|
|
839
991
|
this.connected = false;
|
|
840
992
|
} catch (error) {
|
|
841
993
|
import_logger2.loggers.agent.error("Failed to disconnect from MongoDB:", error);
|
|
@@ -861,7 +1013,7 @@ var MongoDBMemory = class _MongoDBMemory {
|
|
|
861
1013
|
async setupTTLIndex() {
|
|
862
1014
|
if (this.threadTTLSeconds === void 0) return;
|
|
863
1015
|
try {
|
|
864
|
-
const db =
|
|
1016
|
+
const db = import_mongoose14.default.connection.db;
|
|
865
1017
|
if (!db) return;
|
|
866
1018
|
const collection = db.collection("threads");
|
|
867
1019
|
const indexes = await collection.indexes();
|
|
@@ -901,7 +1053,7 @@ var MongoDBMemory = class _MongoDBMemory {
|
|
|
901
1053
|
async cleanupOrphanedMessages() {
|
|
902
1054
|
if (!this.connected) return;
|
|
903
1055
|
try {
|
|
904
|
-
const db =
|
|
1056
|
+
const db = import_mongoose14.default.connection.db;
|
|
905
1057
|
if (!db) return;
|
|
906
1058
|
const existingThreadIds = await db.collection("threads").distinct("threadId");
|
|
907
1059
|
const result = await MessageModel.deleteMany({
|
|
@@ -938,7 +1090,7 @@ var MongoDBMemory = class _MongoDBMemory {
|
|
|
938
1090
|
`${operationName} failed due to too many sessions, disconnecting to release sessions...`
|
|
939
1091
|
);
|
|
940
1092
|
try {
|
|
941
|
-
await
|
|
1093
|
+
await import_mongoose14.default.disconnect();
|
|
942
1094
|
this.connected = false;
|
|
943
1095
|
} catch (disconnectError) {
|
|
944
1096
|
import_logger2.loggers.agent.error("Failed to disconnect during session cleanup:", disconnectError);
|