@ainetwork/adk-provider-memory-mongodb 0.4.1 → 0.5.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.
Files changed (49) hide show
  1. package/dist/{chunk-EPJZT2YE.js → chunk-2XJ6S2W5.js} +6 -1
  2. package/dist/chunk-2XJ6S2W5.js.map +1 -0
  3. package/dist/{chunk-T5WRFXBY.js → chunk-QULDFKGZ.js} +2 -1
  4. package/dist/chunk-QULDFKGZ.js.map +1 -0
  5. package/dist/chunk-RC275GLE.js +70 -0
  6. package/dist/chunk-RC275GLE.js.map +1 -0
  7. package/dist/{chunk-ENGJ6NTO.js → chunk-SJ2FHHN6.js} +10 -10
  8. package/dist/chunk-SJ2FHHN6.js.map +1 -0
  9. package/dist/index.cjs +235 -67
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +5 -3
  12. package/dist/index.d.ts +5 -3
  13. package/dist/index.js +155 -55
  14. package/dist/index.js.map +1 -1
  15. package/dist/models/messages.model.cjs +1 -0
  16. package/dist/models/messages.model.cjs.map +1 -1
  17. package/dist/models/messages.model.js +1 -1
  18. package/dist/models/threads.model.cjs +5 -0
  19. package/dist/models/threads.model.cjs.map +1 -1
  20. package/dist/models/threads.model.d.cts +4 -0
  21. package/dist/models/threads.model.d.ts +4 -0
  22. package/dist/models/threads.model.js +1 -1
  23. package/dist/models/user-workflow.model.cjs +105 -0
  24. package/dist/models/user-workflow.model.cjs.map +1 -0
  25. package/dist/models/user-workflow.model.d.cts +92 -0
  26. package/dist/models/user-workflow.model.d.ts +92 -0
  27. package/dist/models/user-workflow.model.js +9 -0
  28. package/dist/models/{workflow.model.cjs → workflow-template.model.cjs} +15 -15
  29. package/dist/models/workflow-template.model.cjs.map +1 -0
  30. package/dist/models/{workflow.model.d.ts → workflow-template.model.d.cts} +10 -13
  31. package/dist/models/{workflow.model.d.cts → workflow-template.model.d.ts} +10 -13
  32. package/dist/models/workflow-template.model.js +9 -0
  33. package/dist/models/workflow-template.model.js.map +1 -0
  34. package/implements/base.memory.ts +49 -12
  35. package/implements/thread.memory.ts +31 -16
  36. package/implements/user-workflow.memory.ts +87 -0
  37. package/implements/workflow-template.memory.ts +69 -0
  38. package/models/messages.model.ts +2 -0
  39. package/models/threads.model.ts +6 -0
  40. package/models/user-workflow.model.ts +91 -0
  41. package/models/{workflow.model.ts → workflow-template.model.ts} +10 -10
  42. package/package.json +3 -3
  43. package/dist/chunk-ENGJ6NTO.js.map +0 -1
  44. package/dist/chunk-EPJZT2YE.js.map +0 -1
  45. package/dist/chunk-T5WRFXBY.js.map +0 -1
  46. package/dist/models/workflow.model.cjs.map +0 -1
  47. package/dist/models/workflow.model.js +0 -9
  48. package/implements/workflow.memory.ts +0 -78
  49. /package/dist/models/{workflow.model.js.map → user-workflow.model.js.map} +0 -0
@@ -1,10 +1,11 @@
1
- import { IAgentMemory, IIntentMemory, IMemory, IThreadMemory, IWorkflowMemory } from "@ainetwork/adk/modules";
1
+ import { IAgentMemory, IIntentMemory, IMemory, IUserWorkflowMemory, IThreadMemory, IWorkflowTemplateMemory } from "@ainetwork/adk/modules";
2
2
  import mongoose from "mongoose";
3
3
  import { loggers } from "@ainetwork/adk/utils/logger";
4
4
  import { MongoDBAgent } from "./agent.memory";
5
5
  import { MongoDBIntent } from "./intent.memory";
6
6
  import { MongoDBThread } from "./thread.memory";
7
- import { MongoDBWorkflow } from "./workflow.memory";
7
+ import { MongoDBUserWorkflow } from "./user-workflow.memory";
8
+ import { MongoDBWorkflowTemplate } from "./workflow-template.memory";
8
9
  import { MessageModel } from "../models/messages.model";
9
10
 
10
11
  export interface MongoDBMemoryConfig {
@@ -36,7 +37,8 @@ export class MongoDBMemory implements IMemory {
36
37
  private agentMemory: MongoDBAgent;
37
38
  private intentMemory: MongoDBIntent;
38
39
  private threadMemory: MongoDBThread;
39
- private workflowMemory: MongoDBWorkflow;
40
+ private workflowTemplateMemory: MongoDBWorkflowTemplate;
41
+ private userWorkflowMemory: MongoDBUserWorkflow;
40
42
 
41
43
  constructor(config: string | MongoDBMemoryConfig) {
42
44
  const cfg = typeof config === 'string' ? { uri: config } : config;
@@ -49,7 +51,9 @@ export class MongoDBMemory implements IMemory {
49
51
  this.threadTTLSeconds = cfg.threadTTLSeconds;
50
52
  }
51
53
  this.connectionConfig = {
52
- maxPoolSize: cfg.maxPoolSize ?? 1,
54
+ maxPoolSize: cfg.maxPoolSize ?? 10,
55
+ minPoolSize: 0,
56
+ maxIdleTimeMS: 30000,
53
57
  serverSelectionTimeoutMS: cfg.serverSelectionTimeoutMS ?? 30000,
54
58
  socketTimeoutMS: cfg.socketTimeoutMS ?? 45000,
55
59
  connectTimeoutMS: cfg.connectTimeoutMS ?? 30000,
@@ -80,7 +84,12 @@ export class MongoDBMemory implements IMemory {
80
84
  this.getOperationTimeout.bind(this)
81
85
  );
82
86
 
83
- this.workflowMemory = new MongoDBWorkflow(
87
+ this.workflowTemplateMemory = new MongoDBWorkflowTemplate(
88
+ this.executeWithRetry.bind(this),
89
+ this.getOperationTimeout.bind(this)
90
+ );
91
+
92
+ this.userWorkflowMemory = new MongoDBUserWorkflow(
84
93
  this.executeWithRetry.bind(this),
85
94
  this.getOperationTimeout.bind(this)
86
95
  );
@@ -98,8 +107,12 @@ export class MongoDBMemory implements IMemory {
98
107
  return this.intentMemory;
99
108
  }
100
109
 
101
- public getWorkflowMemory(): IWorkflowMemory {
102
- return this.workflowMemory;
110
+ public getWorkflowTemplateMemory(): IWorkflowTemplateMemory {
111
+ return this.workflowTemplateMemory;
112
+ }
113
+
114
+ public getUserWorkflowMemory(): IUserWorkflowMemory {
115
+ return this.userWorkflowMemory;
103
116
  }
104
117
 
105
118
  private setupMongooseEventListeners(): void {
@@ -141,7 +154,7 @@ export class MongoDBMemory implements IMemory {
141
154
 
142
155
  this.reconnecting = true;
143
156
 
144
- while (this.reconnectAttempts < this.maxReconnectAttempts && !this.isConnected) {
157
+ while (this.reconnectAttempts < this.maxReconnectAttempts && !this.connected) {
145
158
  this.reconnectAttempts++;
146
159
  loggers.agent.info(
147
160
  `Attempting to reconnect to MongoDB (${this.reconnectAttempts}/${this.maxReconnectAttempts})...`
@@ -170,7 +183,7 @@ export class MongoDBMemory implements IMemory {
170
183
 
171
184
  this.reconnecting = false;
172
185
 
173
- if (!this.isConnected) {
186
+ if (!this.connected) {
174
187
  loggers.agent.error(
175
188
  `Failed to reconnect to MongoDB after ${this.maxReconnectAttempts} attempts`
176
189
  );
@@ -195,7 +208,7 @@ export class MongoDBMemory implements IMemory {
195
208
  }
196
209
 
197
210
  public async disconnect(): Promise<void> {
198
- if (!this.isConnected) {
211
+ if (!this.connected) {
199
212
  return;
200
213
  }
201
214
 
@@ -217,7 +230,7 @@ export class MongoDBMemory implements IMemory {
217
230
  }
218
231
 
219
232
  private async ensureConnection(): Promise<void> {
220
- if (!this.isConnected && !this.reconnecting) {
233
+ if (!this.connected && !this.reconnecting) {
221
234
  await this.connect();
222
235
  }
223
236
 
@@ -228,7 +241,7 @@ export class MongoDBMemory implements IMemory {
228
241
  await new Promise((resolve) => setTimeout(resolve, 100));
229
242
  }
230
243
 
231
- if (!this.isConnected) {
244
+ if (!this.connected) {
232
245
  throw new Error("MongoDB is not connected and reconnection failed");
233
246
  }
234
247
  }
@@ -327,6 +340,30 @@ export class MongoDBMemory implements IMemory {
327
340
  throw error;
328
341
  }
329
342
 
343
+ // Check if it's a TooManyLogicalSessions error
344
+ if (error.code === 261 || error.codeName === "TooManyLogicalSessions") {
345
+ loggers.agent.warn(
346
+ `${operationName} failed due to too many sessions, disconnecting to release sessions...`
347
+ );
348
+
349
+ try {
350
+ await mongoose.disconnect();
351
+ this.connected = false;
352
+ } catch (disconnectError) {
353
+ loggers.agent.error("Failed to disconnect during session cleanup:", disconnectError);
354
+ }
355
+
356
+ await new Promise((resolve) => setTimeout(resolve, 5000));
357
+ await this.ensureConnection();
358
+
359
+ try {
360
+ return await operation();
361
+ } catch (retryError: any) {
362
+ loggers.agent.error(`${operationName} failed after session cleanup retry:`, retryError);
363
+ throw retryError;
364
+ }
365
+ }
366
+
330
367
  // Check if it's a connection-related error
331
368
  if (
332
369
  error.name === "MongoNetworkError" ||
@@ -1,4 +1,4 @@
1
- import type { MessageObject, ThreadMetadata, ThreadObject, ThreadType } from "@ainetwork/adk/types/memory";
1
+ import type { MessageObject, ThreadMetadata, ThreadObject, ThreadType, ThreadFilter } from "@ainetwork/adk/types/memory";
2
2
  import { MessageRole } from "@ainetwork/adk/types/memory";
3
3
  import { IThreadMemory } from "@ainetwork/adk/modules";
4
4
  import { ThreadDocument, ThreadModel } from "../models/threads.model";
@@ -45,6 +45,7 @@ export class MongoDBThread implements IThreadMemory {
45
45
  type: thread.type as ThreadType,
46
46
  title: thread.title || "New thread",
47
47
  isPinned: thread.isPinned ?? false,
48
+ workflowId: thread.workflowId,
48
49
  messages: []
49
50
  };
50
51
  messages.forEach((message: MessageDocument) => {
@@ -66,6 +67,7 @@ export class MongoDBThread implements IThreadMemory {
66
67
  userId: string,
67
68
  threadId: string,
68
69
  title: string,
70
+ workflowId?: string,
69
71
  ): Promise<ThreadObject> {
70
72
  return this.executeWithRetry(async () => {
71
73
  await ThreadModel.create({
@@ -73,9 +75,10 @@ export class MongoDBThread implements IThreadMemory {
73
75
  userId,
74
76
  threadId,
75
77
  title,
78
+ workflowId,
76
79
  });
77
80
 
78
- return { type, userId, threadId, title, messages: []};
81
+ return { type, userId, threadId, title, workflowId, messages: []};
79
82
  }, `createThread(${userId}, ${threadId})`);
80
83
  };
81
84
 
@@ -85,18 +88,25 @@ export class MongoDBThread implements IThreadMemory {
85
88
  messages: MessageObject[]
86
89
  ): Promise<void> {
87
90
  return this.executeWithRetry(async () => {
88
- await ThreadModel.updateOne({ threadId, userId }, { $set: {} });
89
- for (const message of messages) {
90
- await MessageModel.create({
91
- threadId,
92
- messageId: message.messageId,
93
- userId,
94
- role: message.role,
95
- content: message.content,
96
- timestamp: message.timestamp,
97
- metadata: message.metadata,
98
- });
91
+ if (messages.length > 0) {
92
+ const messageIds = messages.map((m) => m.messageId);
93
+ await MessageModel.deleteMany({ threadId, userId, messageId: { $in: messageIds } });
94
+ await MessageModel.insertMany(
95
+ messages.map((message) => ({
96
+ threadId,
97
+ messageId: message.messageId,
98
+ userId,
99
+ role: message.role,
100
+ content: message.content,
101
+ timestamp: message.timestamp,
102
+ metadata: message.metadata,
103
+ }))
104
+ );
99
105
  }
106
+ await ThreadModel.updateOne(
107
+ { threadId, userId },
108
+ { $set: { updatedAt: new Date() } }
109
+ );
100
110
  }, `addMessagesToThread(${userId}, ${threadId})`);
101
111
  };
102
112
 
@@ -112,10 +122,13 @@ export class MongoDBThread implements IThreadMemory {
112
122
  }, `deleteThread(${userId}, ${threadId})`);
113
123
  };
114
124
 
115
- public async listThreads(userId: string): Promise<ThreadMetadata[]> {
125
+ public async listThreads(userId: string, filter?: ThreadFilter): Promise<ThreadMetadata[]> {
116
126
  return this.executeWithRetry(async () => {
117
127
  const timeout = this.getOperationTimeout();
118
- const threads = await ThreadModel.find({ userId })
128
+ const query: Record<string, any> = { userId };
129
+ if (filter?.workflowId) query.workflowId = filter.workflowId;
130
+ if (filter?.type) query.type = filter.type;
131
+ const threads = await ThreadModel.find(query)
119
132
  .sort({ updatedAt: -1 })
120
133
  .maxTimeMS(timeout);
121
134
  const data: ThreadMetadata[] = threads.map((thread: ThreadDocument) => {
@@ -125,7 +138,9 @@ export class MongoDBThread implements IThreadMemory {
125
138
  threadId: thread.threadId,
126
139
  title: thread.title,
127
140
  isPinned: thread.isPinned ?? false,
128
- updatedAt: thread.updatedAt,
141
+ workflowId: thread.workflowId,
142
+ createdAt: thread.createdAt?.toISOString(),
143
+ updatedAt: thread.updatedAt?.toISOString(),
129
144
  } as ThreadMetadata;
130
145
  })
131
146
  return data;
@@ -0,0 +1,87 @@
1
+ import type { IUserWorkflowMemory } from "@ainetwork/adk/modules";
2
+ import type { UserWorkflow } from "@ainetwork/adk/types/memory";
3
+ import { UserWorkflowModel } from "../models/user-workflow.model";
4
+
5
+ export type ExecuteWithRetryFn = <T>(
6
+ operation: () => Promise<T>,
7
+ operationName?: string
8
+ ) => Promise<T>;
9
+
10
+ export type GetOperationTimeoutFn = () => number;
11
+
12
+ export class MongoDBUserWorkflow implements IUserWorkflowMemory {
13
+ private executeWithRetry: ExecuteWithRetryFn;
14
+ private getOperationTimeout: GetOperationTimeoutFn;
15
+
16
+ constructor(
17
+ executeWithRetry: ExecuteWithRetryFn,
18
+ getOperationTimeout: GetOperationTimeoutFn
19
+ ) {
20
+ this.executeWithRetry = executeWithRetry;
21
+ this.getOperationTimeout = getOperationTimeout;
22
+ }
23
+
24
+ public async createUserWorkflow(workflow: UserWorkflow): Promise<UserWorkflow> {
25
+ return this.executeWithRetry(async () => {
26
+ const created = await UserWorkflowModel.create(workflow);
27
+ return created.toObject() as UserWorkflow;
28
+ }, "createUserWorkflow()");
29
+ }
30
+
31
+ public async getUserWorkflow(workflowId: string): Promise<UserWorkflow | undefined> {
32
+ return this.executeWithRetry(async () => {
33
+ const timeout = this.getOperationTimeout();
34
+ const workflow = await UserWorkflowModel.findOne({ workflowId })
35
+ .maxTimeMS(timeout)
36
+ .lean<UserWorkflow>();
37
+ return workflow || undefined;
38
+ }, "getUserWorkflow()");
39
+ }
40
+
41
+ public async updateUserWorkflow(workflowId: string, updates: Partial<UserWorkflow>): Promise<void> {
42
+ if (!updates.userId) {
43
+ throw new Error("userId is required for updateUserWorkflow");
44
+ }
45
+
46
+ const { userId, workflowId: _workflowId, ...mutableUpdates } = updates;
47
+
48
+ return this.executeWithRetry(async () => {
49
+ const timeout = this.getOperationTimeout();
50
+ await UserWorkflowModel.updateOne(
51
+ { workflowId, userId },
52
+ { $set: mutableUpdates }
53
+ ).maxTimeMS(timeout);
54
+ }, "updateUserWorkflow()");
55
+ }
56
+
57
+ public async deleteUserWorkflow(workflowId: string, userId: string): Promise<void> {
58
+ return this.executeWithRetry(async () => {
59
+ const timeout = this.getOperationTimeout();
60
+ await UserWorkflowModel.deleteOne({ workflowId, userId }).maxTimeMS(timeout);
61
+ }, "deleteUserWorkflow()");
62
+ }
63
+
64
+ public async listUserWorkflows(userId?: string): Promise<UserWorkflow[]> {
65
+ return this.executeWithRetry(async () => {
66
+ const timeout = this.getOperationTimeout();
67
+ const query = userId ? { userId } : {};
68
+ const workflows = await UserWorkflowModel.find(query)
69
+ .maxTimeMS(timeout)
70
+ .lean<UserWorkflow[]>();
71
+ return workflows;
72
+ }, "listUserWorkflows()");
73
+ }
74
+
75
+ public async listActiveScheduledWorkflows(): Promise<UserWorkflow[]> {
76
+ return this.executeWithRetry(async () => {
77
+ const timeout = this.getOperationTimeout();
78
+ const workflows = await UserWorkflowModel.find({
79
+ active: true,
80
+ schedule: { $exists: true, $ne: null },
81
+ })
82
+ .maxTimeMS(timeout)
83
+ .lean<UserWorkflow[]>();
84
+ return workflows;
85
+ }, "listActiveScheduledWorkflows()");
86
+ }
87
+ }
@@ -0,0 +1,69 @@
1
+ import type { IWorkflowTemplateMemory } from "@ainetwork/adk/modules";
2
+ import type { WorkflowTemplate } from "@ainetwork/adk/types/memory";
3
+ import { WorkflowTemplateModel } from "../models/workflow-template.model";
4
+
5
+ export type ExecuteWithRetryFn = <T>(
6
+ operation: () => Promise<T>,
7
+ operationName?: string
8
+ ) => Promise<T>;
9
+
10
+ export type GetOperationTimeoutFn = () => number;
11
+
12
+ export class MongoDBWorkflowTemplate implements IWorkflowTemplateMemory {
13
+ private executeWithRetry: ExecuteWithRetryFn;
14
+ private getOperationTimeout: GetOperationTimeoutFn;
15
+
16
+ constructor(
17
+ executeWithRetry: ExecuteWithRetryFn,
18
+ getOperationTimeout: GetOperationTimeoutFn
19
+ ) {
20
+ this.executeWithRetry = executeWithRetry;
21
+ this.getOperationTimeout = getOperationTimeout;
22
+ }
23
+
24
+ public async createTemplate(template: WorkflowTemplate): Promise<WorkflowTemplate> {
25
+ return this.executeWithRetry(async () => {
26
+ const created = await WorkflowTemplateModel.create(template);
27
+ return created.toObject() as WorkflowTemplate;
28
+ }, "createTemplate()");
29
+ }
30
+
31
+ public async getTemplate(templateId: string): Promise<WorkflowTemplate | undefined> {
32
+ return this.executeWithRetry(async () => {
33
+ const timeout = this.getOperationTimeout();
34
+ const template = await WorkflowTemplateModel.findOne({ templateId })
35
+ .maxTimeMS(timeout)
36
+ .lean<WorkflowTemplate>();
37
+ return template || undefined;
38
+ }, "getTemplate()");
39
+ }
40
+
41
+ public async updateTemplate(templateId: string, updates: Partial<WorkflowTemplate>): Promise<void> {
42
+ const { templateId: _templateId, ...mutableUpdates } = updates;
43
+
44
+ return this.executeWithRetry(async () => {
45
+ const timeout = this.getOperationTimeout();
46
+ await WorkflowTemplateModel.updateOne(
47
+ { templateId },
48
+ { $set: mutableUpdates }
49
+ ).maxTimeMS(timeout);
50
+ }, "updateTemplate()");
51
+ }
52
+
53
+ public async deleteTemplate(templateId: string): Promise<void> {
54
+ return this.executeWithRetry(async () => {
55
+ const timeout = this.getOperationTimeout();
56
+ await WorkflowTemplateModel.deleteOne({ templateId }).maxTimeMS(timeout);
57
+ }, "deleteTemplate()");
58
+ }
59
+
60
+ public async listTemplates(): Promise<WorkflowTemplate[]> {
61
+ return this.executeWithRetry(async () => {
62
+ const timeout = this.getOperationTimeout();
63
+ const templates = await WorkflowTemplateModel.find()
64
+ .maxTimeMS(timeout)
65
+ .lean<WorkflowTemplate[]>();
66
+ return templates;
67
+ }, "listTemplates()");
68
+ }
69
+ }
@@ -52,6 +52,8 @@ export const MessageObjectSchema = new Schema(
52
52
  },
53
53
  );
54
54
 
55
+ MessageObjectSchema.index({ threadId: 1, messageId: 1 }, { unique: true });
56
+
55
57
  // Message Document interface
56
58
  export interface MessageDocument extends Document {
57
59
  messageId: string;
@@ -28,6 +28,11 @@ export const ThreadObjectSchema = new Schema(
28
28
  required: false,
29
29
  default: false,
30
30
  },
31
+ workflowId: {
32
+ type: String,
33
+ required: false,
34
+ index: true,
35
+ },
31
36
  },
32
37
  {
33
38
  timestamps: true,
@@ -40,6 +45,7 @@ export interface ThreadDocument extends Document {
40
45
  userId: string;
41
46
  title: string;
42
47
  isPinned: boolean;
48
+ workflowId?: string;
43
49
  createdAt: Date;
44
50
  updatedAt: Date;
45
51
  }
@@ -0,0 +1,91 @@
1
+ import { type Document, Schema } from "mongoose";
2
+ import mongoose from "mongoose";
3
+
4
+ export const UserWorkflowObjectSchema = new Schema(
5
+ {
6
+ workflowId: {
7
+ type: String,
8
+ required: true,
9
+ unique: true,
10
+ },
11
+ userId: {
12
+ type: String,
13
+ required: true,
14
+ index: true,
15
+ },
16
+ title: {
17
+ type: String,
18
+ required: true,
19
+ },
20
+ description: {
21
+ type: String,
22
+ },
23
+ active: {
24
+ type: Boolean,
25
+ required: true,
26
+ default: false,
27
+ },
28
+ templateId: {
29
+ type: String,
30
+ },
31
+ content: {
32
+ type: String,
33
+ required: true,
34
+ },
35
+ variables: {
36
+ type: Schema.Types.Mixed,
37
+ },
38
+ variableValues: {
39
+ type: Schema.Types.Mixed,
40
+ },
41
+ schedule: {
42
+ type: String,
43
+ },
44
+ timezone: {
45
+ type: String,
46
+ },
47
+ lastRunAt: {
48
+ type: Number,
49
+ },
50
+ nextRunAt: {
51
+ type: Number,
52
+ },
53
+ lastThreadId: {
54
+ type: String,
55
+ },
56
+ },
57
+ {
58
+ timestamps: true,
59
+ }
60
+ );
61
+
62
+ export interface UserWorkflowDocument extends Document {
63
+ workflowId: string;
64
+ userId: string;
65
+ title: string;
66
+ description?: string;
67
+ active: boolean;
68
+ templateId?: string;
69
+ content: string;
70
+ variables?: Record<
71
+ string,
72
+ {
73
+ id: string;
74
+ label: string;
75
+ type: "select" | "date_range" | "date_parts" | "text" | "number";
76
+ options?: Array<string>;
77
+ resolveAt?: "creation" | "execution";
78
+ }
79
+ >;
80
+ variableValues?: Record<string, string>;
81
+ schedule?: string;
82
+ timezone?: string;
83
+ lastRunAt?: number;
84
+ nextRunAt?: number;
85
+ lastThreadId?: string;
86
+ }
87
+
88
+ export const UserWorkflowModel = mongoose.model<UserWorkflowDocument>(
89
+ "UserWorkflow",
90
+ UserWorkflowObjectSchema
91
+ );
@@ -1,16 +1,13 @@
1
1
  import { type Document, Schema } from "mongoose";
2
2
  import mongoose from "mongoose";
3
3
 
4
- export const WorkflowObjectSchema = new Schema(
4
+ export const WorkflowTemplateObjectSchema = new Schema(
5
5
  {
6
- workflowId: {
6
+ templateId: {
7
7
  type: String,
8
8
  required: true,
9
9
  unique: true,
10
10
  },
11
- userId: {
12
- type: String,
13
- },
14
11
  title: {
15
12
  type: String,
16
13
  required: true,
@@ -37,9 +34,8 @@ export const WorkflowObjectSchema = new Schema(
37
34
  }
38
35
  );
39
36
 
40
- export interface WorkflowDocument extends Document {
41
- workflowId: string;
42
- userId?: string;
37
+ export interface WorkflowTemplateDocument extends Document {
38
+ templateId: string;
43
39
  title: string;
44
40
  description: string;
45
41
  active: boolean;
@@ -49,10 +45,14 @@ export interface WorkflowDocument extends Document {
49
45
  {
50
46
  id: string;
51
47
  label: string;
52
- type: "select" | "date_range" | "text" | "number";
48
+ type: "select" | "date_range" | "date_parts" | "text" | "number";
53
49
  options?: Array<string>;
50
+ resolveAt?: "creation" | "execution";
54
51
  }
55
52
  >;
56
53
  }
57
54
 
58
- export const WorkflowModel = mongoose.model<WorkflowDocument>("Workflow", WorkflowObjectSchema);
55
+ export const WorkflowTemplateModel = mongoose.model<WorkflowTemplateDocument>(
56
+ "WorkflowTemplate",
57
+ WorkflowTemplateObjectSchema
58
+ );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ainetwork/adk-provider-memory-mongodb",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "author": "AI Network (https://ainetwork.ai)",
5
5
  "type": "module",
6
6
  "engines": {
@@ -28,7 +28,7 @@
28
28
  "clean": "rm -rf dist"
29
29
  },
30
30
  "dependencies": {
31
- "@ainetwork/adk": "^0.4.1",
31
+ "@ainetwork/adk": "^0.5.0",
32
32
  "mongoose": "^8.16.5"
33
33
  },
34
34
  "devDependencies": {
@@ -38,5 +38,5 @@
38
38
  "publishConfig": {
39
39
  "access": "public"
40
40
  },
41
- "gitHead": "49996589506616fbfe330a0ad992301b06d55066"
41
+ "gitHead": "8c14fa8de70f23589cd273772db665f354f3e713"
42
42
  }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../models/workflow.model.ts"],"sourcesContent":["import { type Document, Schema } from \"mongoose\";\nimport mongoose from \"mongoose\";\n\nexport const WorkflowObjectSchema = new Schema(\n\t{\n\t\tworkflowId: {\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},\n\t\ttitle: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t},\n\t\tdescription: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t},\n\t\tactive: {\n\t\t\ttype: Boolean,\n\t\t\trequired: true,\n\t\t\tdefault: false,\n\t\t},\n\t\tcontent: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t},\n\t\tvariables: {\n\t\t\ttype: Schema.Types.Mixed,\n\t\t},\n\t},\n\t{\n\t\ttimestamps: true,\n\t}\n);\n\nexport interface WorkflowDocument extends Document {\n\tworkflowId: string;\n\tuserId?: string;\n\ttitle: string;\n\tdescription: string;\n\tactive: boolean;\n\tcontent: string;\n\tvariables?: Record<\n\t\tstring,\n\t\t{\n\t\t\tid: string;\n\t\t\tlabel: string;\n\t\t\ttype: \"select\" | \"date_range\" | \"text\" | \"number\";\n\t\t\toptions?: Array<string>;\n\t\t}\n\t>;\n}\n\nexport const WorkflowModel = mongoose.model<WorkflowDocument>(\"Workflow\", WorkflowObjectSchema);\n"],"mappings":";AAAA,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,IACP;AAAA,IACA,OAAO;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,IACA,aAAa;AAAA,MACZ,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,IACA,QAAQ;AAAA,MACP,MAAM;AAAA,MACN,UAAU;AAAA,MACV,SAAS;AAAA,IACV;AAAA,IACA,SAAS;AAAA,MACR,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,IACA,WAAW;AAAA,MACV,MAAM,OAAO,MAAM;AAAA,IACpB;AAAA,EACD;AAAA,EACA;AAAA,IACC,YAAY;AAAA,EACb;AACD;AAoBO,IAAM,gBAAgB,SAAS,MAAwB,YAAY,oBAAoB;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../models/threads.model.ts"],"sourcesContent":["import { ThreadType } from \"@ainetwork/adk/types/memory\";\nimport { type Document, Schema } from \"mongoose\";\nimport mongoose from \"mongoose\";\n\nexport const ThreadObjectSchema = new Schema(\n\t{\n\t\ttype: {\n\t\t\ttype: String,\n\t\t\tenum: Object.values(ThreadType),\n\t\t\trequired: true,\n\t\t},\n\t\tthreadId: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t\tindex: true,\n\t\t},\n\t\tuserId: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t\tindex: true,\n\t\t},\n\t\ttitle: {\n\t\t\ttype: String,\n\t\t\trequired: false,\n\t\t},\n\t\tisPinned: {\n\t\t\ttype: Boolean,\n\t\t\trequired: false,\n\t\t\tdefault: false,\n\t\t},\n\t},\n\t{\n\t\ttimestamps: true,\n\t},\n);\n\nexport interface ThreadDocument extends Document {\n\ttype: ThreadType;\n\tthreadId: string;\n\tuserId: string;\n\ttitle: string;\n\tisPinned: boolean;\n\tcreatedAt: Date;\n\tupdatedAt: Date;\n}\n\nexport const ThreadModel = mongoose.model<ThreadDocument>(\"Thread\", ThreadObjectSchema);\n"],"mappings":";AAAA,SAAS,kBAAkB;AAC3B,SAAwB,cAAc;AACtC,OAAO,cAAc;AAEd,IAAM,qBAAqB,IAAI;AAAA,EACrC;AAAA,IACC,MAAM;AAAA,MACL,MAAM;AAAA,MACN,MAAM,OAAO,OAAO,UAAU;AAAA,MAC9B,UAAU;AAAA,IACX;AAAA,IACA,UAAU;AAAA,MACT,MAAM;AAAA,MACN,UAAU;AAAA,MACV,OAAO;AAAA,IACR;AAAA,IACA,QAAQ;AAAA,MACP,MAAM;AAAA,MACN,UAAU;AAAA,MACV,OAAO;AAAA,IACR;AAAA,IACA,OAAO;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,IACA,UAAU;AAAA,MACT,MAAM;AAAA,MACN,UAAU;AAAA,MACV,SAAS;AAAA,IACV;AAAA,EACD;AAAA,EACA;AAAA,IACC,YAAY;AAAA,EACb;AACD;AAYO,IAAM,cAAc,SAAS,MAAsB,UAAU,kBAAkB;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../models/messages.model.ts"],"sourcesContent":["import { MessageRole } from \"@ainetwork/adk/types/memory\";\nimport { type Document, Schema } from \"mongoose\";\nimport mongoose from \"mongoose\";\n\n// MessageContentObject schema\nexport const MessageContentObjectSchema = new Schema(\n\t{\n\t\ttype: { type: String, required: true },\n\t\tparts: { type: [Schema.Types.Mixed], required: true },\n\t},\n\t{ _id: false },\n);\n\n// MessageObject schema - 개별 문서로 저장\nexport const MessageObjectSchema = new Schema(\n\t{\n\t\tmessageId: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t\tindex: true,\n\t\t},\n\t\tthreadId: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t\tindex: true,\n\t\t},\n\t\tuserId: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t\tindex: true,\n\t\t},\n\t\trole: {\n\t\t\ttype: String,\n\t\t\tenum: Object.values(MessageRole),\n\t\t\trequired: true,\n\t\t},\n\t\tcontent: {\n\t\t\ttype: MessageContentObjectSchema,\n\t\t\trequired: true,\n\t\t},\n\t\ttimestamp: {\n\t\t\ttype: Number,\n\t\t\trequired: true,\n\t\t},\n\t\tmetadata: {\n\t\t\ttype: Schema.Types.Mixed,\n\t\t\tdefault: {},\n\t\t},\n\t},\n\t{\n\t\ttimestamps: true,\n\t},\n);\n\n// Message Document interface\nexport interface MessageDocument extends Document {\n\tmessageId: string;\n\tthreadId: string;\n\tuserId: string;\n\trole: MessageRole;\n\tcontent: {\n\t\ttype: string;\n\t\tparts: any[];\n\t};\n\ttimestamp: number;\n\tcreatedAt: Date;\n\tupdatedAt: Date;\n\tmetadata?: { [key: string]: unknown };\n}\n\nexport const MessageModel = mongoose.model<MessageDocument>(\"Message\", MessageObjectSchema);"],"mappings":";AAAA,SAAS,mBAAmB;AAC5B,SAAwB,cAAc;AACtC,OAAO,cAAc;AAGd,IAAM,6BAA6B,IAAI;AAAA,EAC7C;AAAA,IACC,MAAM,EAAE,MAAM,QAAQ,UAAU,KAAK;AAAA,IACrC,OAAO,EAAE,MAAM,CAAC,OAAO,MAAM,KAAK,GAAG,UAAU,KAAK;AAAA,EACrD;AAAA,EACA,EAAE,KAAK,MAAM;AACd;AAGO,IAAM,sBAAsB,IAAI;AAAA,EACtC;AAAA,IACC,WAAW;AAAA,MACV,MAAM;AAAA,MACN,UAAU;AAAA,MACV,OAAO;AAAA,IACR;AAAA,IACA,UAAU;AAAA,MACT,MAAM;AAAA,MACN,UAAU;AAAA,MACV,OAAO;AAAA,IACR;AAAA,IACA,QAAQ;AAAA,MACP,MAAM;AAAA,MACN,UAAU;AAAA,MACV,OAAO;AAAA,IACR;AAAA,IACA,MAAM;AAAA,MACL,MAAM;AAAA,MACN,MAAM,OAAO,OAAO,WAAW;AAAA,MAC/B,UAAU;AAAA,IACX;AAAA,IACA,SAAS;AAAA,MACR,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,IACA,WAAW;AAAA,MACV,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,IACA,UAAU;AAAA,MACT,MAAM,OAAO,MAAM;AAAA,MACnB,SAAS,CAAC;AAAA,IACX;AAAA,EACD;AAAA,EACA;AAAA,IACC,YAAY;AAAA,EACb;AACD;AAkBO,IAAM,eAAe,SAAS,MAAuB,WAAW,mBAAmB;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../models/workflow.model.ts"],"sourcesContent":["import { type Document, Schema } from \"mongoose\";\nimport mongoose from \"mongoose\";\n\nexport const WorkflowObjectSchema = new Schema(\n\t{\n\t\tworkflowId: {\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},\n\t\ttitle: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t},\n\t\tdescription: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t},\n\t\tactive: {\n\t\t\ttype: Boolean,\n\t\t\trequired: true,\n\t\t\tdefault: false,\n\t\t},\n\t\tcontent: {\n\t\t\ttype: String,\n\t\t\trequired: true,\n\t\t},\n\t\tvariables: {\n\t\t\ttype: Schema.Types.Mixed,\n\t\t},\n\t},\n\t{\n\t\ttimestamps: true,\n\t}\n);\n\nexport interface WorkflowDocument extends Document {\n\tworkflowId: string;\n\tuserId?: string;\n\ttitle: string;\n\tdescription: string;\n\tactive: boolean;\n\tcontent: string;\n\tvariables?: Record<\n\t\tstring,\n\t\t{\n\t\t\tid: string;\n\t\t\tlabel: string;\n\t\t\ttype: \"select\" | \"date_range\" | \"text\" | \"number\";\n\t\t\toptions?: Array<string>;\n\t\t}\n\t>;\n}\n\nexport const WorkflowModel = mongoose.model<WorkflowDocument>(\"Workflow\", WorkflowObjectSchema);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAsC;AACtC,IAAAA,mBAAqB;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,IACP;AAAA,IACA,OAAO;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,IACA,aAAa;AAAA,MACZ,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,IACA,QAAQ;AAAA,MACP,MAAM;AAAA,MACN,UAAU;AAAA,MACV,SAAS;AAAA,IACV;AAAA,IACA,SAAS;AAAA,MACR,MAAM;AAAA,MACN,UAAU;AAAA,IACX;AAAA,IACA,WAAW;AAAA,MACV,MAAM,uBAAO,MAAM;AAAA,IACpB;AAAA,EACD;AAAA,EACA;AAAA,IACC,YAAY;AAAA,EACb;AACD;AAoBO,IAAM,gBAAgB,iBAAAC,QAAS,MAAwB,YAAY,oBAAoB;","names":["import_mongoose","mongoose"]}
@@ -1,9 +0,0 @@
1
- import {
2
- WorkflowModel,
3
- WorkflowObjectSchema
4
- } from "../chunk-ENGJ6NTO.js";
5
- export {
6
- WorkflowModel,
7
- WorkflowObjectSchema
8
- };
9
- //# sourceMappingURL=workflow.model.js.map