@ainetwork/adk-provider-memory-inmemory 0.4.1 → 0.5.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/index.cjs CHANGED
@@ -106,32 +106,34 @@ var InMemoryThread = class {
106
106
  type: res.type,
107
107
  title: res.title,
108
108
  isPinned: res.isPinned,
109
+ workflowId: res.workflowId,
109
110
  messages: res.messages
110
111
  };
111
112
  return threadObject;
112
113
  }
113
114
  return void 0;
114
115
  }
115
- async createThread(type, userId, threadId, title) {
116
+ async createThread(type, userId, threadId, title, workflowId) {
116
117
  const now = Date.now();
117
118
  const key = this.generateKey(userId, threadId);
118
119
  if (!this.userThreadIndex.has(userId)) {
119
120
  this.userThreadIndex.set(userId, /* @__PURE__ */ new Set());
120
121
  }
121
122
  if (!this.threads.has(key)) {
122
- this.threads.set(key, { type, title, isPinned: false, messages: [] });
123
+ this.threads.set(key, { type, title, isPinned: false, workflowId, messages: [] });
123
124
  const metadata = {
124
125
  type,
125
126
  userId,
126
127
  threadId,
127
128
  title,
128
129
  isPinned: false,
129
- createdAt: now,
130
- updatedAt: now
130
+ workflowId,
131
+ createdAt: new Date(now).toISOString(),
132
+ updatedAt: new Date(now).toISOString()
131
133
  };
132
134
  this.userThreadIndex.get(userId)?.add(metadata);
133
135
  }
134
- return { type, title, threadId, userId, messages: [] };
136
+ return { type, title, threadId, userId, workflowId, messages: [] };
135
137
  }
136
138
  async addMessagesToThread(userId, threadId, messages) {
137
139
  const key = this.generateKey(userId, threadId);
@@ -153,12 +155,17 @@ var InMemoryThread = class {
153
155
  }
154
156
  }
155
157
  }
156
- async listThreads(userId) {
158
+ async listThreads(userId, filter) {
157
159
  const threads = this.userThreadIndex.get(userId);
158
- if (threads) {
159
- return Array.from(threads);
160
+ if (!threads) return [];
161
+ let result = Array.from(threads);
162
+ if (filter?.workflowId) {
163
+ result = result.filter((t) => t.workflowId === filter.workflowId);
160
164
  }
161
- return [];
165
+ if (filter?.type) {
166
+ result = result.filter((t) => t.type === filter.type);
167
+ }
168
+ return result;
162
169
  }
163
170
  async updateThreadPin(userId, threadId, isPinned) {
164
171
  const key = this.generateKey(userId, threadId);
@@ -178,30 +185,28 @@ var InMemoryThread = class {
178
185
  }
179
186
  };
180
187
 
181
- // implements/workflow.memory.ts
182
- var InMemoryWorkflow = class {
188
+ // implements/user-workflow.memory.ts
189
+ var InMemoryUserWorkflow = class {
183
190
  workflows = /* @__PURE__ */ new Map();
184
191
  userWorkflowIndex = /* @__PURE__ */ new Map();
185
- async createWorkflow(workflow) {
192
+ async createUserWorkflow(workflow) {
186
193
  this.workflows.set(workflow.workflowId, workflow);
187
- if (workflow.userId) {
188
- if (!this.userWorkflowIndex.has(workflow.userId)) {
189
- this.userWorkflowIndex.set(workflow.userId, /* @__PURE__ */ new Set());
190
- }
191
- this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);
194
+ if (!this.userWorkflowIndex.has(workflow.userId)) {
195
+ this.userWorkflowIndex.set(workflow.userId, /* @__PURE__ */ new Set());
192
196
  }
197
+ this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);
193
198
  return workflow;
194
199
  }
195
- async getWorkflow(workflowId) {
200
+ async getUserWorkflow(workflowId) {
196
201
  return this.workflows.get(workflowId);
197
202
  }
198
- async updateWorkflow(workflowId, updates) {
203
+ async updateUserWorkflow(workflowId, updates) {
199
204
  if (!updates.userId) {
200
- throw new Error("userId is required for updateWorkflow");
205
+ throw new Error("userId is required for updateUserWorkflow");
201
206
  }
202
207
  const existing = this.workflows.get(workflowId);
203
208
  if (!existing) {
204
- throw new Error(`Workflow not found: ${workflowId}`);
209
+ throw new Error(`UserWorkflow not found: ${workflowId}`);
205
210
  }
206
211
  if (existing.userId !== updates.userId) {
207
212
  throw new Error("Unauthorized: userId does not match workflow owner");
@@ -209,32 +214,62 @@ var InMemoryWorkflow = class {
209
214
  const updated = { ...existing, ...updates, workflowId };
210
215
  this.workflows.set(workflowId, updated);
211
216
  }
212
- async deleteWorkflow(workflowId, userId) {
217
+ async deleteUserWorkflow(workflowId, userId) {
213
218
  const workflow = this.workflows.get(workflowId);
214
219
  if (workflow && workflow.userId === userId) {
215
220
  this.workflows.delete(workflowId);
216
221
  this.userWorkflowIndex.get(userId)?.delete(workflowId);
217
222
  }
218
223
  }
219
- async listWorkflows(userId) {
220
- const workflows = [];
221
- for (const workflow of this.workflows.values()) {
222
- if (!workflow.userId) {
223
- workflows.push(workflow);
224
- }
225
- }
224
+ async listUserWorkflows(userId) {
226
225
  if (userId) {
227
226
  const userWorkflowIds = this.userWorkflowIndex.get(userId);
228
- if (userWorkflowIds) {
229
- for (const workflowId of userWorkflowIds) {
230
- const workflow = this.workflows.get(workflowId);
231
- if (workflow) {
232
- workflows.push(workflow);
233
- }
227
+ if (!userWorkflowIds) return [];
228
+ const workflows = [];
229
+ for (const workflowId of userWorkflowIds) {
230
+ const workflow = this.workflows.get(workflowId);
231
+ if (workflow) {
232
+ workflows.push(workflow);
234
233
  }
235
234
  }
235
+ return workflows;
236
+ }
237
+ return Array.from(this.workflows.values());
238
+ }
239
+ async listActiveScheduledWorkflows() {
240
+ const result = [];
241
+ for (const workflow of this.workflows.values()) {
242
+ if (workflow.active && workflow.schedule) {
243
+ result.push(workflow);
244
+ }
236
245
  }
237
- return workflows;
246
+ return result;
247
+ }
248
+ };
249
+
250
+ // implements/workflow-template.memory.ts
251
+ var InMemoryWorkflowTemplate = class {
252
+ templates = /* @__PURE__ */ new Map();
253
+ async createTemplate(template) {
254
+ this.templates.set(template.templateId, template);
255
+ return template;
256
+ }
257
+ async getTemplate(templateId) {
258
+ return this.templates.get(templateId);
259
+ }
260
+ async updateTemplate(templateId, updates) {
261
+ const existing = this.templates.get(templateId);
262
+ if (!existing) {
263
+ throw new Error(`WorkflowTemplate not found: ${templateId}`);
264
+ }
265
+ const updated = { ...existing, ...updates, templateId };
266
+ this.templates.set(templateId, updated);
267
+ }
268
+ async deleteTemplate(templateId) {
269
+ this.templates.delete(templateId);
270
+ }
271
+ async listTemplates() {
272
+ return Array.from(this.templates.values());
238
273
  }
239
274
  };
240
275
 
@@ -245,7 +280,8 @@ var InMemoryMemory = class _InMemoryMemory {
245
280
  agentMemory;
246
281
  intentMemory;
247
282
  threadMemory;
248
- workflowMemory;
283
+ workflowTemplateMemory;
284
+ userWorkflowMemory;
249
285
  constructor() {
250
286
  if (!_InMemoryMemory.instance) {
251
287
  _InMemoryMemory.instance = this;
@@ -253,7 +289,8 @@ var InMemoryMemory = class _InMemoryMemory {
253
289
  this.agentMemory = new InMemoryAgent();
254
290
  this.threadMemory = new InMemoryThread();
255
291
  this.intentMemory = new InMemoryIntent();
256
- this.workflowMemory = new InMemoryWorkflow();
292
+ this.workflowTemplateMemory = new InMemoryWorkflowTemplate();
293
+ this.userWorkflowMemory = new InMemoryUserWorkflow();
257
294
  }
258
295
  async connect() {
259
296
  this.connected = true;
@@ -273,8 +310,11 @@ var InMemoryMemory = class _InMemoryMemory {
273
310
  getIntentMemory() {
274
311
  return this.intentMemory;
275
312
  }
276
- getWorkflowMemory() {
277
- return this.workflowMemory;
313
+ getWorkflowTemplateMemory() {
314
+ return this.workflowTemplateMemory;
315
+ }
316
+ getUserWorkflowMemory() {
317
+ return this.userWorkflowMemory;
278
318
  }
279
319
  };
280
320
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts","../implements/agent.memory.ts","../implements/intent.memory.ts","../implements/thread.memory.ts","../implements/workflow.memory.ts","../implements/base.memory.ts"],"sourcesContent":["export { InMemoryMemory } from \"./implements/base.memory\";","import { IAgentMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryAgent implements IAgentMemory {\n private agentPrompt: string = \"\";\n private aggregatePrompt: string = \"\";\n private generateTitlePrompt: string = \"\";\n private singleTriggerPrompt: string = \"\";\n private multiTriggerPrompt: string = \"\";\n private toolSelectPrompt: string = \"\";\n private piiDetectPrompt: string = \"\";\n private piiFilterPrompt: string = \"\";\n\n public async getAgentPrompt(): Promise<string> {\n return this.agentPrompt;\n }\n\n public async updateAgentPrompt(prompt: string): Promise<void> {\n this.agentPrompt = prompt;\n }\n\n public async getAggregatePrompt(): Promise<string> {\n return this.aggregatePrompt;\n }\n\n public async getGenerateTitlePrompt(): Promise<string> {\n return this.generateTitlePrompt;\n }\n\n public async getSingleTriggerPrompt(): Promise<string> {\n return this.singleTriggerPrompt;\n }\n\n public async getMultiTriggerPrompt(): Promise<string> {\n return this.multiTriggerPrompt;\n }\n\n public async getToolSelectPrompt(): Promise<string> {\n return this.toolSelectPrompt;\n }\n\n public async getPIIDetectPrompt(): Promise<string> {\n return this.piiDetectPrompt;\n }\n\n public async getPIIFilterPrompt(): Promise<string> {\n return this.piiFilterPrompt;\n }\n}\n","import { randomUUID } from \"node:crypto\";\nimport type { Intent } from \"@ainetwork/adk/types/memory\";\nimport { IIntentMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryIntent implements IIntentMemory {\n public intents: Map<string, Intent> = new Map();\n\n public async getIntent(intentId: string): Promise<Intent | undefined> {\n return this.intents.get(intentId);\n }\n\n public async getIntentByName(intentName: string): Promise<Intent | undefined> {\n return Array.from(this.intents.values()).find(intent => intent.name === intentName);\n }\n\n public async saveIntent(intent: Intent): Promise<void> {\n // Intent에 이미 id가 있으면 그것을 사용하고, 없으면 새로 생성\n const intentId = intent.id || randomUUID();\n const intentToSave = { ...intent, id: intentId };\n this.intents.set(intentId, intentToSave);\n }\n\n public async updateIntent(intentId: string, intent: Intent): Promise<void> {\n this.intents.set(intentId, intent);\n }\n\n public async deleteIntent(intentId: string): Promise<void> {\n this.intents.delete(intentId);\n }\n\n public async listIntents(): Promise<Intent[]> {\n return Array.from(this.intents.values());\n }\n}","import type { MessageObject, ThreadObject, ThreadMetadata, ThreadType } from \"@ainetwork/adk/types/memory\";\nimport { IThreadMemory } from \"@ainetwork/adk/modules\";\n\ntype InMemoryThreadObject = {\n type: ThreadType;\n title: string;\n isPinned: boolean;\n messages: Array<MessageObject>;\n}\n\ntype InMemoryThreadMetadata = {\n type: ThreadType;\n userId: string;\n threadId: string;\n title: string;\n isPinned: boolean;\n updatedAt: number;\n createdAt: number;\n}\n\nexport class InMemoryThread implements IThreadMemory {\n public threads: Map<string, InMemoryThreadObject> = new Map();\n public userThreadIndex: Map<string, Set<InMemoryThreadMetadata>> = new Map();\n\n private generateKey(userId: string, threadId: string) {\n return `${userId}:${threadId}`;\n }\n\n public async getThread(\n userId: string,\n threadId: string\n ): Promise<ThreadObject | undefined> {\n const key = this.generateKey(userId, threadId);\n const res = this.threads.get(key);\n if (res) {\n const threadObject: ThreadObject = {\n threadId,\n userId,\n type: res.type,\n title: res.title,\n isPinned: res.isPinned,\n messages: res.messages,\n };\n return threadObject;\n }\n return undefined;\n }\n\n public async createThread(\n type: ThreadType,\n userId: string,\n threadId: string,\n title: string\n ): Promise<ThreadObject> {\n const now = Date.now();\n const key = this.generateKey(userId, threadId);\n if (!this.userThreadIndex.has(userId)) {\n this.userThreadIndex.set(userId, new Set());\n }\n if (!this.threads.has(key)) {\n this.threads.set(key, { type, title, isPinned: false, messages: [] });\n const metadata: InMemoryThreadMetadata = {\n type, userId, threadId, title, isPinned: false, createdAt: now, updatedAt: now,\n }\n this.userThreadIndex.get(userId)?.add(metadata);\n }\n\n return { type, title, threadId, userId, messages: [] };\n }\n\n public async addMessagesToThread(\n userId: string,\n threadId: string,\n messages: MessageObject[]\n ): Promise<void> {\n const key = this.generateKey(userId, threadId);\n const thread = this.threads.get(key);\n for (const message of messages) {\n thread?.messages.push(message);\n }\n }\n\n public async deleteThread(userId: string, threadId: string): Promise<void> {\n const key = this.generateKey(userId, threadId);\n this.threads.delete(key);\n\n // userThreadIndex에서 해당 thread metadata 제거\n const userThreads = this.userThreadIndex.get(userId);\n if (userThreads) {\n const metadataToDelete = Array.from(userThreads).find(\n metadata => metadata.threadId === threadId\n );\n if (metadataToDelete) {\n userThreads.delete(metadataToDelete);\n }\n }\n }\n\n public async listThreads(userId: string): Promise<ThreadMetadata[]> {\n const threads = this.userThreadIndex.get(userId);\n if (threads) {\n return Array.from(threads);\n }\n return [];\n }\n\n public async updateThreadPin(\n userId: string,\n threadId: string,\n isPinned: boolean\n ): Promise<void> {\n const key = this.generateKey(userId, threadId);\n const thread = this.threads.get(key);\n if (thread) {\n thread.isPinned = isPinned;\n }\n\n const userThreads = this.userThreadIndex.get(userId);\n if (userThreads) {\n const metadata = Array.from(userThreads).find(\n m => m.threadId === threadId\n );\n if (metadata) {\n metadata.isPinned = isPinned;\n }\n }\n }\n}","import { IWorkflowMemory } from \"@ainetwork/adk/modules\";\nimport type { Workflow } from \"@ainetwork/adk/types/memory\";\n\nexport class InMemoryWorkflow implements IWorkflowMemory {\n private workflows: Map<string, Workflow> = new Map();\n private userWorkflowIndex: Map<string, Set<string>> = new Map();\n\n public async createWorkflow(workflow: Workflow): Promise<Workflow> {\n this.workflows.set(workflow.workflowId, workflow);\n\n if (workflow.userId) {\n if (!this.userWorkflowIndex.has(workflow.userId)) {\n this.userWorkflowIndex.set(workflow.userId, new Set());\n }\n this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);\n }\n\n return workflow;\n }\n\n public async getWorkflow(workflowId: string): Promise<Workflow | undefined> {\n return this.workflows.get(workflowId);\n }\n\n public async updateWorkflow(workflowId: string, updates: Partial<Workflow>): Promise<void> {\n if (!updates.userId) {\n throw new Error(\"userId is required for updateWorkflow\");\n }\n\n const existing = this.workflows.get(workflowId);\n if (!existing) {\n throw new Error(`Workflow not found: ${workflowId}`);\n }\n\n if (existing.userId !== updates.userId) {\n throw new Error(\"Unauthorized: userId does not match workflow owner\");\n }\n\n const updated = { ...existing, ...updates, workflowId };\n this.workflows.set(workflowId, updated);\n }\n\n public async deleteWorkflow(workflowId: string, userId: string): Promise<void> {\n const workflow = this.workflows.get(workflowId);\n if (workflow && workflow.userId === userId) {\n this.workflows.delete(workflowId);\n this.userWorkflowIndex.get(userId)?.delete(workflowId);\n }\n }\n\n public async listWorkflows(userId?: string): Promise<Workflow[]> {\n const workflows: Workflow[] = [];\n\n // 템플릿 workflow (userId가 없는 것)은 항상 포함\n for (const workflow of this.workflows.values()) {\n if (!workflow.userId) {\n workflows.push(workflow);\n }\n }\n\n // userId가 있으면 해당 유저 소유 workflow도 포함\n if (userId) {\n const userWorkflowIds = this.userWorkflowIndex.get(userId);\n if (userWorkflowIds) {\n for (const workflowId of userWorkflowIds) {\n const workflow = this.workflows.get(workflowId);\n if (workflow) {\n workflows.push(workflow);\n }\n }\n }\n }\n\n return workflows;\n }\n}\n","import { IAgentMemory, IIntentMemory, IMemory, IThreadMemory, IWorkflowMemory } from \"@ainetwork/adk/modules\";\nimport { InMemoryAgent } from \"./agent.memory\";\nimport { InMemoryIntent } from \"./intent.memory\";\nimport { InMemoryThread } from \"./thread.memory\";\nimport { InMemoryWorkflow } from \"./workflow.memory\";\n\nexport class InMemoryMemory implements IMemory {\n private static instance: InMemoryMemory;\n private connected: boolean = false;\n\n private agentMemory: InMemoryAgent;\n private intentMemory: InMemoryIntent;\n private threadMemory: InMemoryThread;\n private workflowMemory: InMemoryWorkflow;\n\n constructor() {\n if (!InMemoryMemory.instance) {\n InMemoryMemory.instance = this;\n }\n\n this.agentMemory = new InMemoryAgent();\n this.threadMemory = new InMemoryThread();\n this.intentMemory = new InMemoryIntent();\n this.workflowMemory = new InMemoryWorkflow();\n }\n\n public async connect(): Promise<void> {\n this.connected = true;\n }\n\n public async disconnect(): Promise<void> {\n this.connected = false;\n }\n\n public isConnected(): boolean {\n return this.connected;\n }\n\n public getAgentMemory(): IAgentMemory {\n return this.agentMemory;\n }\n\n public getThreadMemory(): IThreadMemory {\n return this.threadMemory;\n }\n\n public getIntentMemory(): IIntentMemory {\n return this.intentMemory;\n }\n\n public getWorkflowMemory(): IWorkflowMemory {\n return this.workflowMemory;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,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AO,GAAG;AAC9C,UAAI,CAAC,SAAS,QAAQ;AACpB,kBAAU,KAAK,QAAQ;AAAA,MACzB;AAAA,IACF;AAGA,QAAI,QAAQ;AACV,YAAM,kBAAkB,KAAK,kBAAkB,IAAI,MAAM;AACzD,UAAI,iBAAiB;AACnB,mBAAW,cAAc,iBAAiB;AACxC,gBAAM,WAAW,KAAK,UAAU,IAAI,UAAU;AAC9C,cAAI,UAAU;AACZ,sBAAU,KAAK,QAAQ;AAAA,UACzB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;;;ACrEO,IAAM,iBAAN,MAAM,gBAAkC;AAAA,EAC7C,OAAe;AAAA,EACP,YAAqB;AAAA,EAErB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,cAAc;AACZ,QAAI,CAAC,gBAAe,UAAU;AAC5B,sBAAe,WAAW;AAAA,IAC5B;AAEA,SAAK,cAAc,IAAI,cAAc;AACrC,SAAK,eAAe,IAAI,eAAe;AACvC,SAAK,eAAe,IAAI,eAAe;AACvC,SAAK,iBAAiB,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,MAAa,UAAyB;AACpC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,MAAa,aAA4B;AACvC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEO,cAAuB;AAC5B,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,iBAA+B;AACpC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,kBAAiC;AACtC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,kBAAiC;AACtC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,oBAAqC;AAC1C,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
1
+ {"version":3,"sources":["../index.ts","../implements/agent.memory.ts","../implements/intent.memory.ts","../implements/thread.memory.ts","../implements/user-workflow.memory.ts","../implements/workflow-template.memory.ts","../implements/base.memory.ts"],"sourcesContent":["export { InMemoryMemory } from \"./implements/base.memory\";","import { IAgentMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryAgent implements IAgentMemory {\n private agentPrompt: string = \"\";\n private aggregatePrompt: string = \"\";\n private generateTitlePrompt: string = \"\";\n private singleTriggerPrompt: string = \"\";\n private multiTriggerPrompt: string = \"\";\n private toolSelectPrompt: string = \"\";\n private piiDetectPrompt: string = \"\";\n private piiFilterPrompt: string = \"\";\n\n public async getAgentPrompt(): Promise<string> {\n return this.agentPrompt;\n }\n\n public async updateAgentPrompt(prompt: string): Promise<void> {\n this.agentPrompt = prompt;\n }\n\n public async getAggregatePrompt(): Promise<string> {\n return this.aggregatePrompt;\n }\n\n public async getGenerateTitlePrompt(): Promise<string> {\n return this.generateTitlePrompt;\n }\n\n public async getSingleTriggerPrompt(): Promise<string> {\n return this.singleTriggerPrompt;\n }\n\n public async getMultiTriggerPrompt(): Promise<string> {\n return this.multiTriggerPrompt;\n }\n\n public async getToolSelectPrompt(): Promise<string> {\n return this.toolSelectPrompt;\n }\n\n public async getPIIDetectPrompt(): Promise<string> {\n return this.piiDetectPrompt;\n }\n\n public async getPIIFilterPrompt(): Promise<string> {\n return this.piiFilterPrompt;\n }\n}\n","import { randomUUID } from \"node:crypto\";\nimport type { Intent } from \"@ainetwork/adk/types/memory\";\nimport { IIntentMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryIntent implements IIntentMemory {\n public intents: Map<string, Intent> = new Map();\n\n public async getIntent(intentId: string): Promise<Intent | undefined> {\n return this.intents.get(intentId);\n }\n\n public async getIntentByName(intentName: string): Promise<Intent | undefined> {\n return Array.from(this.intents.values()).find(intent => intent.name === intentName);\n }\n\n public async saveIntent(intent: Intent): Promise<void> {\n // Intent에 이미 id가 있으면 그것을 사용하고, 없으면 새로 생성\n const intentId = intent.id || randomUUID();\n const intentToSave = { ...intent, id: intentId };\n this.intents.set(intentId, intentToSave);\n }\n\n public async updateIntent(intentId: string, intent: Intent): Promise<void> {\n this.intents.set(intentId, intent);\n }\n\n public async deleteIntent(intentId: string): Promise<void> {\n this.intents.delete(intentId);\n }\n\n public async listIntents(): Promise<Intent[]> {\n return Array.from(this.intents.values());\n }\n}","import type { MessageObject, ThreadObject, ThreadMetadata, ThreadType, ThreadFilter } from \"@ainetwork/adk/types/memory\";\nimport { IThreadMemory } from \"@ainetwork/adk/modules\";\n\ntype InMemoryThreadObject = {\n type: ThreadType;\n title: string;\n isPinned: boolean;\n workflowId?: string;\n messages: Array<MessageObject>;\n}\n\ntype InMemoryThreadMetadata = {\n type: ThreadType;\n userId: string;\n threadId: string;\n title: string;\n isPinned: boolean;\n workflowId?: string;\n updatedAt: string;\n createdAt: string;\n}\n\nexport class InMemoryThread implements IThreadMemory {\n public threads: Map<string, InMemoryThreadObject> = new Map();\n public userThreadIndex: Map<string, Set<InMemoryThreadMetadata>> = new Map();\n\n private generateKey(userId: string, threadId: string) {\n return `${userId}:${threadId}`;\n }\n\n public async getThread(\n userId: string,\n threadId: string\n ): Promise<ThreadObject | undefined> {\n const key = this.generateKey(userId, threadId);\n const res = this.threads.get(key);\n if (res) {\n const threadObject: ThreadObject = {\n threadId,\n userId,\n type: res.type,\n title: res.title,\n isPinned: res.isPinned,\n workflowId: res.workflowId,\n messages: res.messages,\n };\n return threadObject;\n }\n return undefined;\n }\n\n public async createThread(\n type: ThreadType,\n userId: string,\n threadId: string,\n title: string,\n workflowId?: string,\n ): Promise<ThreadObject> {\n const now = Date.now();\n const key = this.generateKey(userId, threadId);\n if (!this.userThreadIndex.has(userId)) {\n this.userThreadIndex.set(userId, new Set());\n }\n if (!this.threads.has(key)) {\n this.threads.set(key, { type, title, isPinned: false, workflowId, messages: [] });\n const metadata: InMemoryThreadMetadata = {\n type, userId, threadId, title, isPinned: false, workflowId, createdAt: new Date(now).toISOString(), updatedAt: new Date(now).toISOString(),\n }\n this.userThreadIndex.get(userId)?.add(metadata);\n }\n\n return { type, title, threadId, userId, workflowId, messages: [] };\n }\n\n public async addMessagesToThread(\n userId: string,\n threadId: string,\n messages: MessageObject[]\n ): Promise<void> {\n const key = this.generateKey(userId, threadId);\n const thread = this.threads.get(key);\n for (const message of messages) {\n thread?.messages.push(message);\n }\n }\n\n public async deleteThread(userId: string, threadId: string): Promise<void> {\n const key = this.generateKey(userId, threadId);\n this.threads.delete(key);\n\n // userThreadIndex에서 해당 thread metadata 제거\n const userThreads = this.userThreadIndex.get(userId);\n if (userThreads) {\n const metadataToDelete = Array.from(userThreads).find(\n metadata => metadata.threadId === threadId\n );\n if (metadataToDelete) {\n userThreads.delete(metadataToDelete);\n }\n }\n }\n\n public async listThreads(userId: string, filter?: ThreadFilter): Promise<ThreadMetadata[]> {\n const threads = this.userThreadIndex.get(userId);\n if (!threads) return [];\n\n let result = Array.from(threads);\n if (filter?.workflowId) {\n result = result.filter(t => t.workflowId === filter.workflowId);\n }\n if (filter?.type) {\n result = result.filter(t => t.type === filter.type);\n }\n return result;\n }\n\n public async updateThreadPin(\n userId: string,\n threadId: string,\n isPinned: boolean\n ): Promise<void> {\n const key = this.generateKey(userId, threadId);\n const thread = this.threads.get(key);\n if (thread) {\n thread.isPinned = isPinned;\n }\n\n const userThreads = this.userThreadIndex.get(userId);\n if (userThreads) {\n const metadata = Array.from(userThreads).find(\n m => m.threadId === threadId\n );\n if (metadata) {\n metadata.isPinned = isPinned;\n }\n }\n }\n}","import { IUserWorkflowMemory } from \"@ainetwork/adk/modules\";\nimport type { UserWorkflow } from \"@ainetwork/adk/types/memory\";\n\nexport class InMemoryUserWorkflow implements IUserWorkflowMemory {\n private workflows: Map<string, UserWorkflow> = new Map();\n private userWorkflowIndex: Map<string, Set<string>> = new Map();\n\n public async createUserWorkflow(workflow: UserWorkflow): Promise<UserWorkflow> {\n this.workflows.set(workflow.workflowId, workflow);\n\n if (!this.userWorkflowIndex.has(workflow.userId)) {\n this.userWorkflowIndex.set(workflow.userId, new Set());\n }\n this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);\n\n return workflow;\n }\n\n public async getUserWorkflow(workflowId: string): Promise<UserWorkflow | undefined> {\n return this.workflows.get(workflowId);\n }\n\n public async updateUserWorkflow(workflowId: string, updates: Partial<UserWorkflow>): Promise<void> {\n if (!updates.userId) {\n throw new Error(\"userId is required for updateUserWorkflow\");\n }\n\n const existing = this.workflows.get(workflowId);\n if (!existing) {\n throw new Error(`UserWorkflow not found: ${workflowId}`);\n }\n\n if (existing.userId !== updates.userId) {\n throw new Error(\"Unauthorized: userId does not match workflow owner\");\n }\n\n const updated = { ...existing, ...updates, workflowId };\n this.workflows.set(workflowId, updated);\n }\n\n public async deleteUserWorkflow(workflowId: string, userId: string): Promise<void> {\n const workflow = this.workflows.get(workflowId);\n if (workflow && workflow.userId === userId) {\n this.workflows.delete(workflowId);\n this.userWorkflowIndex.get(userId)?.delete(workflowId);\n }\n }\n\n public async listUserWorkflows(userId?: string): Promise<UserWorkflow[]> {\n if (userId) {\n const userWorkflowIds = this.userWorkflowIndex.get(userId);\n if (!userWorkflowIds) return [];\n const workflows: UserWorkflow[] = [];\n for (const workflowId of userWorkflowIds) {\n const workflow = this.workflows.get(workflowId);\n if (workflow) {\n workflows.push(workflow);\n }\n }\n return workflows;\n }\n\n return Array.from(this.workflows.values());\n }\n\n public async listActiveScheduledWorkflows(): Promise<UserWorkflow[]> {\n const result: UserWorkflow[] = [];\n for (const workflow of this.workflows.values()) {\n if (workflow.active && workflow.schedule) {\n result.push(workflow);\n }\n }\n return result;\n }\n}\n","import { IWorkflowTemplateMemory } from \"@ainetwork/adk/modules\";\nimport type { WorkflowTemplate } from \"@ainetwork/adk/types/memory\";\n\nexport class InMemoryWorkflowTemplate implements IWorkflowTemplateMemory {\n private templates: Map<string, WorkflowTemplate> = new Map();\n\n public async createTemplate(template: WorkflowTemplate): Promise<WorkflowTemplate> {\n this.templates.set(template.templateId, template);\n return template;\n }\n\n public async getTemplate(templateId: string): Promise<WorkflowTemplate | undefined> {\n return this.templates.get(templateId);\n }\n\n public async updateTemplate(templateId: string, updates: Partial<WorkflowTemplate>): Promise<void> {\n const existing = this.templates.get(templateId);\n if (!existing) {\n throw new Error(`WorkflowTemplate not found: ${templateId}`);\n }\n\n const updated = { ...existing, ...updates, templateId };\n this.templates.set(templateId, updated);\n }\n\n public async deleteTemplate(templateId: string): Promise<void> {\n this.templates.delete(templateId);\n }\n\n public async listTemplates(): Promise<WorkflowTemplate[]> {\n return Array.from(this.templates.values());\n }\n}\n","import { IAgentMemory, IIntentMemory, IMemory, IUserWorkflowMemory, IThreadMemory, IWorkflowTemplateMemory } from \"@ainetwork/adk/modules\";\nimport { InMemoryAgent } from \"./agent.memory\";\nimport { InMemoryIntent } from \"./intent.memory\";\nimport { InMemoryThread } from \"./thread.memory\";\nimport { InMemoryUserWorkflow } from \"./user-workflow.memory\";\nimport { InMemoryWorkflowTemplate } from \"./workflow-template.memory\";\n\nexport class InMemoryMemory implements IMemory {\n private static instance: InMemoryMemory;\n private connected: boolean = false;\n\n private agentMemory: InMemoryAgent;\n private intentMemory: InMemoryIntent;\n private threadMemory: InMemoryThread;\n private workflowTemplateMemory: InMemoryWorkflowTemplate;\n private userWorkflowMemory: InMemoryUserWorkflow;\n\n constructor() {\n if (!InMemoryMemory.instance) {\n InMemoryMemory.instance = this;\n }\n\n this.agentMemory = new InMemoryAgent();\n this.threadMemory = new InMemoryThread();\n this.intentMemory = new InMemoryIntent();\n this.workflowTemplateMemory = new InMemoryWorkflowTemplate();\n this.userWorkflowMemory = new InMemoryUserWorkflow();\n }\n\n public async connect(): Promise<void> {\n this.connected = true;\n }\n\n public async disconnect(): Promise<void> {\n this.connected = false;\n }\n\n public isConnected(): boolean {\n return this.connected;\n }\n\n public getAgentMemory(): IAgentMemory {\n return this.agentMemory;\n }\n\n public getThreadMemory(): IThreadMemory {\n return this.threadMemory;\n }\n\n public getIntentMemory(): IIntentMemory {\n return this.intentMemory;\n }\n\n public getWorkflowTemplateMemory(): IWorkflowTemplateMemory {\n return this.workflowTemplateMemory;\n }\n\n public getUserWorkflowMemory(): IUserWorkflowMem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@ainetwork/adk/modules';
1
+ import { IMemory, IAgentMemory, IThreadMemory, IIntentMemory, IWorkflowTemplateMemory, IUserWorkflowMemory } from '@ainetwork/adk/modules';
2
2
 
3
3
  declare class InMemoryMemory implements IMemory {
4
4
  private static instance;
@@ -6,7 +6,8 @@ declare class InMemoryMemory implements IMemory {
6
6
  private agentMemory;
7
7
  private intentMemory;
8
8
  private threadMemory;
9
- private workflowMemory;
9
+ private workflowTemplateMemory;
10
+ private userWorkflowMemory;
10
11
  constructor();
11
12
  connect(): Promise<void>;
12
13
  disconnect(): Promise<void>;
@@ -14,7 +15,8 @@ declare class InMemoryMemory implements IMemory {
14
15
  getAgentMemory(): IAgentMemory;
15
16
  getThreadMemory(): IThreadMemory;
16
17
  getIntentMemory(): IIntentMemory;
17
- getWorkflowMemory(): IWorkflowMemory;
18
+ getWorkflowTemplateMemory(): IWorkflowTemplateMemory;
19
+ getUserWorkflowMemory(): IUserWorkflowMemory;
18
20
  }
19
21
 
20
22
  export { InMemoryMemory };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IMemory, IAgentMemory, IThreadMemory, IIntentMemory, IWorkflowMemory } from '@ainetwork/adk/modules';
1
+ import { IMemory, IAgentMemory, IThreadMemory, IIntentMemory, IWorkflowTemplateMemory, IUserWorkflowMemory } from '@ainetwork/adk/modules';
2
2
 
3
3
  declare class InMemoryMemory implements IMemory {
4
4
  private static instance;
@@ -6,7 +6,8 @@ declare class InMemoryMemory implements IMemory {
6
6
  private agentMemory;
7
7
  private intentMemory;
8
8
  private threadMemory;
9
- private workflowMemory;
9
+ private workflowTemplateMemory;
10
+ private userWorkflowMemory;
10
11
  constructor();
11
12
  connect(): Promise<void>;
12
13
  disconnect(): Promise<void>;
@@ -14,7 +15,8 @@ declare class InMemoryMemory implements IMemory {
14
15
  getAgentMemory(): IAgentMemory;
15
16
  getThreadMemory(): IThreadMemory;
16
17
  getIntentMemory(): IIntentMemory;
17
- getWorkflowMemory(): IWorkflowMemory;
18
+ getWorkflowTemplateMemory(): IWorkflowTemplateMemory;
19
+ getUserWorkflowMemory(): IUserWorkflowMemory;
18
20
  }
19
21
 
20
22
  export { InMemoryMemory };
package/dist/index.js CHANGED
@@ -80,32 +80,34 @@ var InMemoryThread = class {
80
80
  type: res.type,
81
81
  title: res.title,
82
82
  isPinned: res.isPinned,
83
+ workflowId: res.workflowId,
83
84
  messages: res.messages
84
85
  };
85
86
  return threadObject;
86
87
  }
87
88
  return void 0;
88
89
  }
89
- async createThread(type, userId, threadId, title) {
90
+ async createThread(type, userId, threadId, title, workflowId) {
90
91
  const now = Date.now();
91
92
  const key = this.generateKey(userId, threadId);
92
93
  if (!this.userThreadIndex.has(userId)) {
93
94
  this.userThreadIndex.set(userId, /* @__PURE__ */ new Set());
94
95
  }
95
96
  if (!this.threads.has(key)) {
96
- this.threads.set(key, { type, title, isPinned: false, messages: [] });
97
+ this.threads.set(key, { type, title, isPinned: false, workflowId, messages: [] });
97
98
  const metadata = {
98
99
  type,
99
100
  userId,
100
101
  threadId,
101
102
  title,
102
103
  isPinned: false,
103
- createdAt: now,
104
- updatedAt: now
104
+ workflowId,
105
+ createdAt: new Date(now).toISOString(),
106
+ updatedAt: new Date(now).toISOString()
105
107
  };
106
108
  this.userThreadIndex.get(userId)?.add(metadata);
107
109
  }
108
- return { type, title, threadId, userId, messages: [] };
110
+ return { type, title, threadId, userId, workflowId, messages: [] };
109
111
  }
110
112
  async addMessagesToThread(userId, threadId, messages) {
111
113
  const key = this.generateKey(userId, threadId);
@@ -127,12 +129,17 @@ var InMemoryThread = class {
127
129
  }
128
130
  }
129
131
  }
130
- async listThreads(userId) {
132
+ async listThreads(userId, filter) {
131
133
  const threads = this.userThreadIndex.get(userId);
132
- if (threads) {
133
- return Array.from(threads);
134
+ if (!threads) return [];
135
+ let result = Array.from(threads);
136
+ if (filter?.workflowId) {
137
+ result = result.filter((t) => t.workflowId === filter.workflowId);
134
138
  }
135
- return [];
139
+ if (filter?.type) {
140
+ result = result.filter((t) => t.type === filter.type);
141
+ }
142
+ return result;
136
143
  }
137
144
  async updateThreadPin(userId, threadId, isPinned) {
138
145
  const key = this.generateKey(userId, threadId);
@@ -152,30 +159,28 @@ var InMemoryThread = class {
152
159
  }
153
160
  };
154
161
 
155
- // implements/workflow.memory.ts
156
- var InMemoryWorkflow = class {
162
+ // implements/user-workflow.memory.ts
163
+ var InMemoryUserWorkflow = class {
157
164
  workflows = /* @__PURE__ */ new Map();
158
165
  userWorkflowIndex = /* @__PURE__ */ new Map();
159
- async createWorkflow(workflow) {
166
+ async createUserWorkflow(workflow) {
160
167
  this.workflows.set(workflow.workflowId, workflow);
161
- if (workflow.userId) {
162
- if (!this.userWorkflowIndex.has(workflow.userId)) {
163
- this.userWorkflowIndex.set(workflow.userId, /* @__PURE__ */ new Set());
164
- }
165
- this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);
168
+ if (!this.userWorkflowIndex.has(workflow.userId)) {
169
+ this.userWorkflowIndex.set(workflow.userId, /* @__PURE__ */ new Set());
166
170
  }
171
+ this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);
167
172
  return workflow;
168
173
  }
169
- async getWorkflow(workflowId) {
174
+ async getUserWorkflow(workflowId) {
170
175
  return this.workflows.get(workflowId);
171
176
  }
172
- async updateWorkflow(workflowId, updates) {
177
+ async updateUserWorkflow(workflowId, updates) {
173
178
  if (!updates.userId) {
174
- throw new Error("userId is required for updateWorkflow");
179
+ throw new Error("userId is required for updateUserWorkflow");
175
180
  }
176
181
  const existing = this.workflows.get(workflowId);
177
182
  if (!existing) {
178
- throw new Error(`Workflow not found: ${workflowId}`);
183
+ throw new Error(`UserWorkflow not found: ${workflowId}`);
179
184
  }
180
185
  if (existing.userId !== updates.userId) {
181
186
  throw new Error("Unauthorized: userId does not match workflow owner");
@@ -183,32 +188,62 @@ var InMemoryWorkflow = class {
183
188
  const updated = { ...existing, ...updates, workflowId };
184
189
  this.workflows.set(workflowId, updated);
185
190
  }
186
- async deleteWorkflow(workflowId, userId) {
191
+ async deleteUserWorkflow(workflowId, userId) {
187
192
  const workflow = this.workflows.get(workflowId);
188
193
  if (workflow && workflow.userId === userId) {
189
194
  this.workflows.delete(workflowId);
190
195
  this.userWorkflowIndex.get(userId)?.delete(workflowId);
191
196
  }
192
197
  }
193
- async listWorkflows(userId) {
194
- const workflows = [];
195
- for (const workflow of this.workflows.values()) {
196
- if (!workflow.userId) {
197
- workflows.push(workflow);
198
- }
199
- }
198
+ async listUserWorkflows(userId) {
200
199
  if (userId) {
201
200
  const userWorkflowIds = this.userWorkflowIndex.get(userId);
202
- if (userWorkflowIds) {
203
- for (const workflowId of userWorkflowIds) {
204
- const workflow = this.workflows.get(workflowId);
205
- if (workflow) {
206
- workflows.push(workflow);
207
- }
201
+ if (!userWorkflowIds) return [];
202
+ const workflows = [];
203
+ for (const workflowId of userWorkflowIds) {
204
+ const workflow = this.workflows.get(workflowId);
205
+ if (workflow) {
206
+ workflows.push(workflow);
208
207
  }
209
208
  }
209
+ return workflows;
210
+ }
211
+ return Array.from(this.workflows.values());
212
+ }
213
+ async listActiveScheduledWorkflows() {
214
+ const result = [];
215
+ for (const workflow of this.workflows.values()) {
216
+ if (workflow.active && workflow.schedule) {
217
+ result.push(workflow);
218
+ }
210
219
  }
211
- return workflows;
220
+ return result;
221
+ }
222
+ };
223
+
224
+ // implements/workflow-template.memory.ts
225
+ var InMemoryWorkflowTemplate = class {
226
+ templates = /* @__PURE__ */ new Map();
227
+ async createTemplate(template) {
228
+ this.templates.set(template.templateId, template);
229
+ return template;
230
+ }
231
+ async getTemplate(templateId) {
232
+ return this.templates.get(templateId);
233
+ }
234
+ async updateTemplate(templateId, updates) {
235
+ const existing = this.templates.get(templateId);
236
+ if (!existing) {
237
+ throw new Error(`WorkflowTemplate not found: ${templateId}`);
238
+ }
239
+ const updated = { ...existing, ...updates, templateId };
240
+ this.templates.set(templateId, updated);
241
+ }
242
+ async deleteTemplate(templateId) {
243
+ this.templates.delete(templateId);
244
+ }
245
+ async listTemplates() {
246
+ return Array.from(this.templates.values());
212
247
  }
213
248
  };
214
249
 
@@ -219,7 +254,8 @@ var InMemoryMemory = class _InMemoryMemory {
219
254
  agentMemory;
220
255
  intentMemory;
221
256
  threadMemory;
222
- workflowMemory;
257
+ workflowTemplateMemory;
258
+ userWorkflowMemory;
223
259
  constructor() {
224
260
  if (!_InMemoryMemory.instance) {
225
261
  _InMemoryMemory.instance = this;
@@ -227,7 +263,8 @@ var InMemoryMemory = class _InMemoryMemory {
227
263
  this.agentMemory = new InMemoryAgent();
228
264
  this.threadMemory = new InMemoryThread();
229
265
  this.intentMemory = new InMemoryIntent();
230
- this.workflowMemory = new InMemoryWorkflow();
266
+ this.workflowTemplateMemory = new InMemoryWorkflowTemplate();
267
+ this.userWorkflowMemory = new InMemoryUserWorkflow();
231
268
  }
232
269
  async connect() {
233
270
  this.connected = true;
@@ -247,8 +284,11 @@ var InMemoryMemory = class _InMemoryMemory {
247
284
  getIntentMemory() {
248
285
  return this.intentMemory;
249
286
  }
250
- getWorkflowMemory() {
251
- return this.workflowMemory;
287
+ getWorkflowTemplateMemory() {
288
+ return this.workflowTemplateMemory;
289
+ }
290
+ getUserWorkflowMemory() {
291
+ return this.userWorkflowMemory;
252
292
  }
253
293
  };
254
294
  export {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../implements/agent.memory.ts","../implements/intent.memory.ts","../implements/thread.memory.ts","../implements/workflow.memory.ts","../implements/base.memory.ts"],"sourcesContent":["import { IAgentMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryAgent implements IAgentMemory {\n private agentPrompt: string = \"\";\n private aggregatePrompt: string = \"\";\n private generateTitlePrompt: string = \"\";\n private singleTriggerPrompt: string = \"\";\n private multiTriggerPrompt: string = \"\";\n private toolSelectPrompt: string = \"\";\n private piiDetectPrompt: string = \"\";\n private piiFilterPrompt: string = \"\";\n\n public async getAgentPrompt(): Promise<string> {\n return this.agentPrompt;\n }\n\n public async updateAgentPrompt(prompt: string): Promise<void> {\n this.agentPrompt = prompt;\n }\n\n public async getAggregatePrompt(): Promise<string> {\n return this.aggregatePrompt;\n }\n\n public async getGenerateTitlePrompt(): Promise<string> {\n return this.generateTitlePrompt;\n }\n\n public async getSingleTriggerPrompt(): Promise<string> {\n return this.singleTriggerPrompt;\n }\n\n public async getMultiTriggerPrompt(): Promise<string> {\n return this.multiTriggerPrompt;\n }\n\n public async getToolSelectPrompt(): Promise<string> {\n return this.toolSelectPrompt;\n }\n\n public async getPIIDetectPrompt(): Promise<string> {\n return this.piiDetectPrompt;\n }\n\n public async getPIIFilterPrompt(): Promise<string> {\n return this.piiFilterPrompt;\n }\n}\n","import { randomUUID } from \"node:crypto\";\nimport type { Intent } from \"@ainetwork/adk/types/memory\";\nimport { IIntentMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryIntent implements IIntentMemory {\n public intents: Map<string, Intent> = new Map();\n\n public async getIntent(intentId: string): Promise<Intent | undefined> {\n return this.intents.get(intentId);\n }\n\n public async getIntentByName(intentName: string): Promise<Intent | undefined> {\n return Array.from(this.intents.values()).find(intent => intent.name === intentName);\n }\n\n public async saveIntent(intent: Intent): Promise<void> {\n // Intent에 이미 id가 있으면 그것을 사용하고, 없으면 새로 생성\n const intentId = intent.id || randomUUID();\n const intentToSave = { ...intent, id: intentId };\n this.intents.set(intentId, intentToSave);\n }\n\n public async updateIntent(intentId: string, intent: Intent): Promise<void> {\n this.intents.set(intentId, intent);\n }\n\n public async deleteIntent(intentId: string): Promise<void> {\n this.intents.delete(intentId);\n }\n\n public async listIntents(): Promise<Intent[]> {\n return Array.from(this.intents.values());\n }\n}","import type { MessageObject, ThreadObject, ThreadMetadata, ThreadType } from \"@ainetwork/adk/types/memory\";\nimport { IThreadMemory } from \"@ainetwork/adk/modules\";\n\ntype InMemoryThreadObject = {\n type: ThreadType;\n title: string;\n isPinned: boolean;\n messages: Array<MessageObject>;\n}\n\ntype InMemoryThreadMetadata = {\n type: ThreadType;\n userId: string;\n threadId: string;\n title: string;\n isPinned: boolean;\n updatedAt: number;\n createdAt: number;\n}\n\nexport class InMemoryThread implements IThreadMemory {\n public threads: Map<string, InMemoryThreadObject> = new Map();\n public userThreadIndex: Map<string, Set<InMemoryThreadMetadata>> = new Map();\n\n private generateKey(userId: string, threadId: string) {\n return `${userId}:${threadId}`;\n }\n\n public async getThread(\n userId: string,\n threadId: string\n ): Promise<ThreadObject | undefined> {\n const key = this.generateKey(userId, threadId);\n const res = this.threads.get(key);\n if (res) {\n const threadObject: ThreadObject = {\n threadId,\n userId,\n type: res.type,\n title: res.title,\n isPinned: res.isPinned,\n messages: res.messages,\n };\n return threadObject;\n }\n return undefined;\n }\n\n public async createThread(\n type: ThreadType,\n userId: string,\n threadId: string,\n title: string\n ): Promise<ThreadObject> {\n const now = Date.now();\n const key = this.generateKey(userId, threadId);\n if (!this.userThreadIndex.has(userId)) {\n this.userThreadIndex.set(userId, new Set());\n }\n if (!this.threads.has(key)) {\n this.threads.set(key, { type, title, isPinned: false, messages: [] });\n const metadata: InMemoryThreadMetadata = {\n type, userId, threadId, title, isPinned: false, createdAt: now, updatedAt: now,\n }\n this.userThreadIndex.get(userId)?.add(metadata);\n }\n\n return { type, title, threadId, userId, messages: [] };\n }\n\n public async addMessagesToThread(\n userId: string,\n threadId: string,\n messages: MessageObject[]\n ): Promise<void> {\n const key = this.generateKey(userId, threadId);\n const thread = this.threads.get(key);\n for (const message of messages) {\n thread?.messages.push(message);\n }\n }\n\n public async deleteThread(userId: string, threadId: string): Promise<void> {\n const key = this.generateKey(userId, threadId);\n this.threads.delete(key);\n\n // userThreadIndex에서 해당 thread metadata 제거\n const userThreads = this.userThreadIndex.get(userId);\n if (userThreads) {\n const metadataToDelete = Array.from(userThreads).find(\n metadata => metadata.threadId === threadId\n );\n if (metadataToDelete) {\n userThreads.delete(metadataToDelete);\n }\n }\n }\n\n public async listThreads(userId: string): Promise<ThreadMetadata[]> {\n const threads = this.userThreadIndex.get(userId);\n if (threads) {\n return Array.from(threads);\n }\n return [];\n }\n\n public async updateThreadPin(\n userId: string,\n threadId: string,\n isPinned: boolean\n ): Promise<void> {\n const key = this.generateKey(userId, threadId);\n const thread = this.threads.get(key);\n if (thread) {\n thread.isPinned = isPinned;\n }\n\n const userThreads = this.userThreadIndex.get(userId);\n if (userThreads) {\n const metadata = Array.from(userThreads).find(\n m => m.threadId === threadId\n );\n if (metadata) {\n metadata.isPinned = isPinned;\n }\n }\n }\n}","import { IWorkflowMemory } from \"@ainetwork/adk/modules\";\nimport type { Workflow } from \"@ainetwork/adk/types/memory\";\n\nexport class InMemoryWorkflow implements IWorkflowMemory {\n private workflows: Map<string, Workflow> = new Map();\n private userWorkflowIndex: Map<string, Set<string>> = new Map();\n\n public async createWorkflow(workflow: Workflow): Promise<Workflow> {\n this.workflows.set(workflow.workflowId, workflow);\n\n if (workflow.userId) {\n if (!this.userWorkflowIndex.has(workflow.userId)) {\n this.userWorkflowIndex.set(workflow.userId, new Set());\n }\n this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);\n }\n\n return workflow;\n }\n\n public async getWorkflow(workflowId: string): Promise<Workflow | undefined> {\n return this.workflows.get(workflowId);\n }\n\n public async updateWorkflow(workflowId: string, updates: Partial<Workflow>): Promise<void> {\n if (!updates.userId) {\n throw new Error(\"userId is required for updateWorkflow\");\n }\n\n const existing = this.workflows.get(workflowId);\n if (!existing) {\n throw new Error(`Workflow not found: ${workflowId}`);\n }\n\n if (existing.userId !== updates.userId) {\n throw new Error(\"Unauthorized: userId does not match workflow owner\");\n }\n\n const updated = { ...existing, ...updates, workflowId };\n this.workflows.set(workflowId, updated);\n }\n\n public async deleteWorkflow(workflowId: string, userId: string): Promise<void> {\n const workflow = this.workflows.get(workflowId);\n if (workflow && workflow.userId === userId) {\n this.workflows.delete(workflowId);\n this.userWorkflowIndex.get(userId)?.delete(workflowId);\n }\n }\n\n public async listWorkflows(userId?: string): Promise<Workflow[]> {\n const workflows: Workflow[] = [];\n\n // 템플릿 workflow (userId가 없는 것)은 항상 포함\n for (const workflow of this.workflows.values()) {\n if (!workflow.userId) {\n workflows.push(workflow);\n }\n }\n\n // userId가 있으면 해당 유저 소유 workflow도 포함\n if (userId) {\n const userWorkflowIds = this.userWorkflowIndex.get(userId);\n if (userWorkflowIds) {\n for (const workflowId of userWorkflowIds) {\n const workflow = this.workflows.get(workflowId);\n if (workflow) {\n workflows.push(workflow);\n }\n }\n }\n }\n\n return workflows;\n }\n}\n","import { IAgentMemory, IIntentMemory, IMemory, IThreadMemory, IWorkflowMemory } from \"@ainetwork/adk/modules\";\nimport { InMemoryAgent } from \"./agent.memory\";\nimport { InMemoryIntent } from \"./intent.memory\";\nimport { InMemoryThread } from \"./thread.memory\";\nimport { InMemoryWorkflow } from \"./workflow.memory\";\n\nexport class InMemoryMemory implements IMemory {\n private static instance: InMemoryMemory;\n private connected: boolean = false;\n\n private agentMemory: InMemoryAgent;\n private intentMemory: InMemoryIntent;\n private threadMemory: InMemoryThread;\n private workflowMemory: InMemoryWorkflow;\n\n constructor() {\n if (!InMemoryMemory.instance) {\n InMemoryMemory.instance = this;\n }\n\n this.agentMemory = new InMemoryAgent();\n this.threadMemory = new InMemoryThread();\n this.intentMemory = new InMemoryIntent();\n this.workflowMemory = new InMemoryWorkflow();\n }\n\n public async connect(): Promise<void> {\n this.connected = true;\n }\n\n public async disconnect(): Promise<void> {\n this.connected = false;\n }\n\n public isConnected(): boolean {\n return this.connected;\n }\n\n public getAgentMemory(): IAgentMemory {\n return this.agentMemory;\n }\n\n public getThreadMemory(): IThreadMemory {\n return this.threadMemory;\n }\n\n public getIntentMemory(): IIntentMemory {\n return this.intentMemory;\n }\n\n public getWorkflowMemory(): IWorkflowMemory {\n return this.workflowMemory;\n }\n}\n"],"mappings":";AAEO,IAAM,gBAAN,MAA4C;AAAA,EACzC,cAAsB;AAAA,EACtB,kBAA0B;AAAA,EAC1B,sBAA8B;AAAA,EAC9B,sBAA8B;AAAA,EAC9B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AAQ;AACV,YAAM,kBAAkB,KAAK,kBAAkB,IAAI,MAAM;AACzD,UAAI,iBAAiB;AACnB,mBAAW,cAAc,iBAAiB;AACxC,gBAAM,WAAW,KAAK,UAAU,IAAI,UAAU;AAC9C,cAAI,UAAU;AACZ,sBAAU,KAAK,QAAQ;AAAA,UACzB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;;;ACrEO,IAAM,iBAAN,MAAM,gBAAkC;AAAA,EAC7C,OAAe;AAAA,EACP,YAAqB;AAAA,EAErB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,cAAc;AACZ,QAAI,CAAC,gBAAe,UAAU;AAC5B,sBAAe,WAAW;AAAA,IAC5B;AAEA,SAAK,cAAc,IAAI,cAAc;AACrC,SAAK,eAAe,IAAI,eAAe;AACvC,SAAK,eAAe,IAAI,eAAe;AACvC,SAAK,iBAAiB,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,MAAa,UAAyB;AACpC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,MAAa,aAA4B;AACvC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEO,cAAuB;AAC5B,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,iBAA+B;AACpC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,kBAAiC;AACtC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,kBAAiC;AACtC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,oBAAqC;AAC1C,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
1
+ {"version":3,"sources":["../implements/agent.memory.ts","../implements/intent.memory.ts","../implements/thread.memory.ts","../implements/user-workflow.memory.ts","../implements/workflow-template.memory.ts","../implements/base.memory.ts"],"sourcesContent":["import { IAgentMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryAgent implements IAgentMemory {\n private agentPrompt: string = \"\";\n private aggregatePrompt: string = \"\";\n private generateTitlePrompt: string = \"\";\n private singleTriggerPrompt: string = \"\";\n private multiTriggerPrompt: string = \"\";\n private toolSelectPrompt: string = \"\";\n private piiDetectPrompt: string = \"\";\n private piiFilterPrompt: string = \"\";\n\n public async getAgentPrompt(): Promise<string> {\n return this.agentPrompt;\n }\n\n public async updateAgentPrompt(prompt: string): Promise<void> {\n this.agentPrompt = prompt;\n }\n\n public async getAggregatePrompt(): Promise<string> {\n return this.aggregatePrompt;\n }\n\n public async getGenerateTitlePrompt(): Promise<string> {\n return this.generateTitlePrompt;\n }\n\n public async getSingleTriggerPrompt(): Promise<string> {\n return this.singleTriggerPrompt;\n }\n\n public async getMultiTriggerPrompt(): Promise<string> {\n return this.multiTriggerPrompt;\n }\n\n public async getToolSelectPrompt(): Promise<string> {\n return this.toolSelectPrompt;\n }\n\n public async getPIIDetectPrompt(): Promise<string> {\n return this.piiDetectPrompt;\n }\n\n public async getPIIFilterPrompt(): Promise<string> {\n return this.piiFilterPrompt;\n }\n}\n","import { randomUUID } from \"node:crypto\";\nimport type { Intent } from \"@ainetwork/adk/types/memory\";\nimport { IIntentMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryIntent implements IIntentMemory {\n public intents: Map<string, Intent> = new Map();\n\n public async getIntent(intentId: string): Promise<Intent | undefined> {\n return this.intents.get(intentId);\n }\n\n public async getIntentByName(intentName: string): Promise<Intent | undefined> {\n return Array.from(this.intents.values()).find(intent => intent.name === intentName);\n }\n\n public async saveIntent(intent: Intent): Promise<void> {\n // Intent에 이미 id가 있으면 그것을 사용하고, 없으면 새로 생성\n const intentId = intent.id || randomUUID();\n const intentToSave = { ...intent, id: intentId };\n this.intents.set(intentId, intentToSave);\n }\n\n public async updateIntent(intentId: string, intent: Intent): Promise<void> {\n this.intents.set(intentId, intent);\n }\n\n public async deleteIntent(intentId: string): Promise<void> {\n this.intents.delete(intentId);\n }\n\n public async listIntents(): Promise<Intent[]> {\n return Array.from(this.intents.values());\n }\n}","import type { MessageObject, ThreadObject, ThreadMetadata, ThreadType, ThreadFilter } from \"@ainetwork/adk/types/memory\";\nimport { IThreadMemory } from \"@ainetwork/adk/modules\";\n\ntype InMemoryThreadObject = {\n type: ThreadType;\n title: string;\n isPinned: boolean;\n workflowId?: string;\n messages: Array<MessageObject>;\n}\n\ntype InMemoryThreadMetadata = {\n type: ThreadType;\n userId: string;\n threadId: string;\n title: string;\n isPinned: boolean;\n workflowId?: string;\n updatedAt: string;\n createdAt: string;\n}\n\nexport class InMemoryThread implements IThreadMemory {\n public threads: Map<string, InMemoryThreadObject> = new Map();\n public userThreadIndex: Map<string, Set<InMemoryThreadMetadata>> = new Map();\n\n private generateKey(userId: string, threadId: string) {\n return `${userId}:${threadId}`;\n }\n\n public async getThread(\n userId: string,\n threadId: string\n ): Promise<ThreadObject | undefined> {\n const key = this.generateKey(userId, threadId);\n const res = this.threads.get(key);\n if (res) {\n const threadObject: ThreadObject = {\n threadId,\n userId,\n type: res.type,\n title: res.title,\n isPinned: res.isPinned,\n workflowId: res.workflowId,\n messages: res.messages,\n };\n return threadObject;\n }\n return undefined;\n }\n\n public async createThread(\n type: ThreadType,\n userId: string,\n threadId: string,\n title: string,\n workflowId?: string,\n ): Promise<ThreadObject> {\n const now = Date.now();\n const key = this.generateKey(userId, threadId);\n if (!this.userThreadIndex.has(userId)) {\n this.userThreadIndex.set(userId, new Set());\n }\n if (!this.threads.has(key)) {\n this.threads.set(key, { type, title, isPinned: false, workflowId, messages: [] });\n const metadata: InMemoryThreadMetadata = {\n type, userId, threadId, title, isPinned: false, workflowId, createdAt: new Date(now).toISOString(), updatedAt: new Date(now).toISOString(),\n }\n this.userThreadIndex.get(userId)?.add(metadata);\n }\n\n return { type, title, threadId, userId, workflowId, messages: [] };\n }\n\n public async addMessagesToThread(\n userId: string,\n threadId: string,\n messages: MessageObject[]\n ): Promise<void> {\n const key = this.generateKey(userId, threadId);\n const thread = this.threads.get(key);\n for (const message of messages) {\n thread?.messages.push(message);\n }\n }\n\n public async deleteThread(userId: string, threadId: string): Promise<void> {\n const key = this.generateKey(userId, threadId);\n this.threads.delete(key);\n\n // userThreadIndex에서 해당 thread metadata 제거\n const userThreads = this.userThreadIndex.get(userId);\n if (userThreads) {\n const metadataToDelete = Array.from(userThreads).find(\n metadata => metadata.threadId === threadId\n );\n if (metadataToDelete) {\n userThreads.delete(metadataToDelete);\n }\n }\n }\n\n public async listThreads(userId: string, filter?: ThreadFilter): Promise<ThreadMetadata[]> {\n const threads = this.userThreadIndex.get(userId);\n if (!threads) return [];\n\n let result = Array.from(threads);\n if (filter?.workflowId) {\n result = result.filter(t => t.workflowId === filter.workflowId);\n }\n if (filter?.type) {\n result = result.filter(t => t.type === filter.type);\n }\n return result;\n }\n\n public async updateThreadPin(\n userId: string,\n threadId: string,\n isPinned: boolean\n ): Promise<void> {\n const key = this.generateKey(userId, threadId);\n const thread = this.threads.get(key);\n if (thread) {\n thread.isPinned = isPinned;\n }\n\n const userThreads = this.userThreadIndex.get(userId);\n if (userThreads) {\n const metadata = Array.from(userThreads).find(\n m => m.threadId === threadId\n );\n if (metadata) {\n metadata.isPinned = isPinned;\n }\n }\n }\n}","import { IUserWorkflowMemory } from \"@ainetwork/adk/modules\";\nimport type { UserWorkflow } from \"@ainetwork/adk/types/memory\";\n\nexport class InMemoryUserWorkflow implements IUserWorkflowMemory {\n private workflows: Map<string, UserWorkflow> = new Map();\n private userWorkflowIndex: Map<string, Set<string>> = new Map();\n\n public async createUserWorkflow(workflow: UserWorkflow): Promise<UserWorkflow> {\n this.workflows.set(workflow.workflowId, workflow);\n\n if (!this.userWorkflowIndex.has(workflow.userId)) {\n this.userWorkflowIndex.set(workflow.userId, new Set());\n }\n this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);\n\n return workflow;\n }\n\n public async getUserWorkflow(workflowId: string): Promise<UserWorkflow | undefined> {\n return this.workflows.get(workflowId);\n }\n\n public async updateUserWorkflow(workflowId: string, updates: Partial<UserWorkflow>): Promise<void> {\n if (!updates.userId) {\n throw new Error(\"userId is required for updateUserWorkflow\");\n }\n\n const existing = this.workflows.get(workflowId);\n if (!existing) {\n throw new Error(`UserWorkflow not found: ${workflowId}`);\n }\n\n if (existing.userId !== updates.userId) {\n throw new Error(\"Unauthorized: userId does not match workflow owner\");\n }\n\n const updated = { ...existing, ...updates, workflowId };\n this.workflows.set(workflowId, updated);\n }\n\n public async deleteUserWorkflow(workflowId: string, userId: string): Promise<void> {\n const workflow = this.workflows.get(workflowId);\n if (workflow && workflow.userId === userId) {\n this.workflows.delete(workflowId);\n this.userWorkflowIndex.get(userId)?.delete(workflowId);\n }\n }\n\n public async listUserWorkflows(userId?: string): Promise<UserWorkflow[]> {\n if (userId) {\n const userWorkflowIds = this.userWorkflowIndex.get(userId);\n if (!userWorkflowIds) return [];\n const workflows: UserWorkflow[] = [];\n for (const workflowId of userWorkflowIds) {\n const workflow = this.workflows.get(workflowId);\n if (workflow) {\n workflows.push(workflow);\n }\n }\n return workflows;\n }\n\n return Array.from(this.workflows.values());\n }\n\n public async listActiveScheduledWorkflows(): Promise<UserWorkflow[]> {\n const result: UserWorkflow[] = [];\n for (const workflow of this.workflows.values()) {\n if (workflow.active && workflow.schedule) {\n result.push(workflow);\n }\n }\n return result;\n }\n}\n","import { IWorkflowTemplateMemory } from \"@ainetwork/adk/modules\";\nimport type { WorkflowTemplate } from \"@ainetwork/adk/types/memory\";\n\nexport class InMemoryWorkflowTemplate implements IWorkflowTemplateMemory {\n private templates: Map<string, WorkflowTemplate> = new Map();\n\n public async createTemplate(template: WorkflowTemplate): Promise<WorkflowTemplate> {\n this.templates.set(template.templateId, template);\n return template;\n }\n\n public async getTemplate(templateId: string): Promise<WorkflowTemplate | undefined> {\n return this.templates.get(templateId);\n }\n\n public async updateTemplate(templateId: string, updates: Partial<WorkflowTemplate>): Promise<void> {\n const existing = this.templates.get(templateId);\n if (!existing) {\n throw new Error(`WorkflowTemplate not found: ${templateId}`);\n }\n\n const updated = { ...existing, ...updates, templateId };\n this.templates.set(templateId, updated);\n }\n\n public async deleteTemplate(templateId: string): Promise<void> {\n this.templates.delete(templateId);\n }\n\n public async listTemplates(): Promise<WorkflowTemplate[]> {\n return Array.from(this.templates.values());\n }\n}\n","import { IAgentMemory, IIntentMemory, IMemory, IUserWorkflowMemory, IThreadMemory, IWorkflowTemplateMemory } from \"@ainetwork/adk/modules\";\nimport { InMemoryAgent } from \"./agent.memory\";\nimport { InMemoryIntent } from \"./intent.memory\";\nimport { InMemoryThread } from \"./thread.memory\";\nimport { InMemoryUserWorkflow } from \"./user-workflow.memory\";\nimport { InMemoryWorkflowTemplate } from \"./workflow-template.memory\";\n\nexport class InMemoryMemory implements IMemory {\n private static instance: InMemoryMemory;\n private connected: boolean = false;\n\n private agentMemory: InMemoryAgent;\n private intentMemory: InMemoryIntent;\n private threadMemory: InMemoryThread;\n private workflowTemplateMemory: InMemoryWorkflowTemplate;\n private userWorkflowMemory: InMemoryUserWorkflow;\n\n constructor() {\n if (!InMemoryMemory.instance) {\n InMemoryMemory.instance = this;\n }\n\n this.agentMemory = new InMemoryAgent();\n this.threadMemory = new InMemoryThread();\n this.intentMemory = new InMemoryIntent();\n this.workflowTemplateMemory = new InMemoryWorkflowTemplate();\n this.userWorkflowMemory = new InMemoryUserWorkflow();\n }\n\n public async connect(): Promise<void> {\n this.connected = true;\n }\n\n public async disconnect(): Promise<void> {\n this.connected = false;\n }\n\n public isConnected(): boolean {\n return this.connected;\n }\n\n public getAgentMemory(): IAgentMemory {\n return this.agentMemory;\n }\n\n public getThreadMemory(): IThreadMemory {\n return this.threadMemory;\n }\n\n public getIntentMemory(): IIntentMemory {\n return this.intentMemory;\n }\n\n public getWorkflowTemplateMemory(): IWorkflowTemplateMemory {\n return this.workflowTemplateMemory;\n }\n\n public getUserWorkflowMemory(): IUserWorkflowMemory {\n return this.userWorkflowMemory;\n }\n}\n"],"mappings":";AAEO,IAAM,gBAAN,MAA4C;AAAA,EACzC,cAAsB;AAAA,EACtB,kBAA0B;AAAA,EAC1B,sBAA8B;AAAA,EAC9B,s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C;AAC7D,SAAK,UAAU,OAAO,UAAU;AAAA,EAClC;AAAA,EAEA,MAAa,gBAA6C;AACxD,WAAO,MAAM,KAAK,KAAK,UAAU,OAAO,CAAC;AAAA,EAC3C;AACF;;;ACzBO,IAAM,iBAAN,MAAM,gBAAkC;AAAA,EAC7C,OAAe;AAAA,EACP,YAAqB;AAAA,EAErB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,cAAc;AACZ,QAAI,CAAC,gBAAe,UAAU;AAC5B,sBAAe,WAAW;AAAA,IAC5B;AAEA,SAAK,cAAc,IAAI,cAAc;AACrC,SAAK,eAAe,IAAI,eAAe;AACvC,SAAK,eAAe,IAAI,eAAe;AACvC,SAAK,yBAAyB,IAAI,yBAAyB;AAC3D,SAAK,qBAAqB,IAAI,qBAAqB;AAAA,EACrD;AAAA,EAEA,MAAa,UAAyB;AACpC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,MAAa,aAA4B;AACvC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEO,cAAuB;AAC5B,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,iBAA+B;AACpC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,kBAAiC;AACtC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,kBAAiC;AACtC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,4BAAqD;AAC1D,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,wBAA6C;AAClD,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
@@ -1,8 +1,9 @@
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 { InMemoryAgent } from "./agent.memory";
3
3
  import { InMemoryIntent } from "./intent.memory";
4
4
  import { InMemoryThread } from "./thread.memory";
5
- import { InMemoryWorkflow } from "./workflow.memory";
5
+ import { InMemoryUserWorkflow } from "./user-workflow.memory";
6
+ import { InMemoryWorkflowTemplate } from "./workflow-template.memory";
6
7
 
7
8
  export class InMemoryMemory implements IMemory {
8
9
  private static instance: InMemoryMemory;
@@ -11,7 +12,8 @@ export class InMemoryMemory implements IMemory {
11
12
  private agentMemory: InMemoryAgent;
12
13
  private intentMemory: InMemoryIntent;
13
14
  private threadMemory: InMemoryThread;
14
- private workflowMemory: InMemoryWorkflow;
15
+ private workflowTemplateMemory: InMemoryWorkflowTemplate;
16
+ private userWorkflowMemory: InMemoryUserWorkflow;
15
17
 
16
18
  constructor() {
17
19
  if (!InMemoryMemory.instance) {
@@ -21,7 +23,8 @@ export class InMemoryMemory implements IMemory {
21
23
  this.agentMemory = new InMemoryAgent();
22
24
  this.threadMemory = new InMemoryThread();
23
25
  this.intentMemory = new InMemoryIntent();
24
- this.workflowMemory = new InMemoryWorkflow();
26
+ this.workflowTemplateMemory = new InMemoryWorkflowTemplate();
27
+ this.userWorkflowMemory = new InMemoryUserWorkflow();
25
28
  }
26
29
 
27
30
  public async connect(): Promise<void> {
@@ -48,7 +51,11 @@ export class InMemoryMemory implements IMemory {
48
51
  return this.intentMemory;
49
52
  }
50
53
 
51
- public getWorkflowMemory(): IWorkflowMemory {
52
- return this.workflowMemory;
54
+ public getWorkflowTemplateMemory(): IWorkflowTemplateMemory {
55
+ return this.workflowTemplateMemory;
56
+ }
57
+
58
+ public getUserWorkflowMemory(): IUserWorkflowMemory {
59
+ return this.userWorkflowMemory;
53
60
  }
54
61
  }
@@ -1,10 +1,11 @@
1
- import type { MessageObject, ThreadObject, ThreadMetadata, ThreadType } from "@ainetwork/adk/types/memory";
1
+ import type { MessageObject, ThreadObject, ThreadMetadata, ThreadType, ThreadFilter } from "@ainetwork/adk/types/memory";
2
2
  import { IThreadMemory } from "@ainetwork/adk/modules";
3
3
 
4
4
  type InMemoryThreadObject = {
5
5
  type: ThreadType;
6
6
  title: string;
7
7
  isPinned: boolean;
8
+ workflowId?: string;
8
9
  messages: Array<MessageObject>;
9
10
  }
10
11
 
@@ -14,8 +15,9 @@ type InMemoryThreadMetadata = {
14
15
  threadId: string;
15
16
  title: string;
16
17
  isPinned: boolean;
17
- updatedAt: number;
18
- createdAt: number;
18
+ workflowId?: string;
19
+ updatedAt: string;
20
+ createdAt: string;
19
21
  }
20
22
 
21
23
  export class InMemoryThread implements IThreadMemory {
@@ -39,6 +41,7 @@ export class InMemoryThread implements IThreadMemory {
39
41
  type: res.type,
40
42
  title: res.title,
41
43
  isPinned: res.isPinned,
44
+ workflowId: res.workflowId,
42
45
  messages: res.messages,
43
46
  };
44
47
  return threadObject;
@@ -50,7 +53,8 @@ export class InMemoryThread implements IThreadMemory {
50
53
  type: ThreadType,
51
54
  userId: string,
52
55
  threadId: string,
53
- title: string
56
+ title: string,
57
+ workflowId?: string,
54
58
  ): Promise<ThreadObject> {
55
59
  const now = Date.now();
56
60
  const key = this.generateKey(userId, threadId);
@@ -58,14 +62,14 @@ export class InMemoryThread implements IThreadMemory {
58
62
  this.userThreadIndex.set(userId, new Set());
59
63
  }
60
64
  if (!this.threads.has(key)) {
61
- this.threads.set(key, { type, title, isPinned: false, messages: [] });
65
+ this.threads.set(key, { type, title, isPinned: false, workflowId, messages: [] });
62
66
  const metadata: InMemoryThreadMetadata = {
63
- type, userId, threadId, title, isPinned: false, createdAt: now, updatedAt: now,
67
+ type, userId, threadId, title, isPinned: false, workflowId, createdAt: new Date(now).toISOString(), updatedAt: new Date(now).toISOString(),
64
68
  }
65
69
  this.userThreadIndex.get(userId)?.add(metadata);
66
70
  }
67
71
 
68
- return { type, title, threadId, userId, messages: [] };
72
+ return { type, title, threadId, userId, workflowId, messages: [] };
69
73
  }
70
74
 
71
75
  public async addMessagesToThread(
@@ -96,12 +100,18 @@ export class InMemoryThread implements IThreadMemory {
96
100
  }
97
101
  }
98
102
 
99
- public async listThreads(userId: string): Promise<ThreadMetadata[]> {
103
+ public async listThreads(userId: string, filter?: ThreadFilter): Promise<ThreadMetadata[]> {
100
104
  const threads = this.userThreadIndex.get(userId);
101
- if (threads) {
102
- return Array.from(threads);
105
+ if (!threads) return [];
106
+
107
+ let result = Array.from(threads);
108
+ if (filter?.workflowId) {
109
+ result = result.filter(t => t.workflowId === filter.workflowId);
110
+ }
111
+ if (filter?.type) {
112
+ result = result.filter(t => t.type === filter.type);
103
113
  }
104
- return [];
114
+ return result;
105
115
  }
106
116
 
107
117
  public async updateThreadPin(
@@ -0,0 +1,75 @@
1
+ import { IUserWorkflowMemory } from "@ainetwork/adk/modules";
2
+ import type { UserWorkflow } from "@ainetwork/adk/types/memory";
3
+
4
+ export class InMemoryUserWorkflow implements IUserWorkflowMemory {
5
+ private workflows: Map<string, UserWorkflow> = new Map();
6
+ private userWorkflowIndex: Map<string, Set<string>> = new Map();
7
+
8
+ public async createUserWorkflow(workflow: UserWorkflow): Promise<UserWorkflow> {
9
+ this.workflows.set(workflow.workflowId, workflow);
10
+
11
+ if (!this.userWorkflowIndex.has(workflow.userId)) {
12
+ this.userWorkflowIndex.set(workflow.userId, new Set());
13
+ }
14
+ this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);
15
+
16
+ return workflow;
17
+ }
18
+
19
+ public async getUserWorkflow(workflowId: string): Promise<UserWorkflow | undefined> {
20
+ return this.workflows.get(workflowId);
21
+ }
22
+
23
+ public async updateUserWorkflow(workflowId: string, updates: Partial<UserWorkflow>): Promise<void> {
24
+ if (!updates.userId) {
25
+ throw new Error("userId is required for updateUserWorkflow");
26
+ }
27
+
28
+ const existing = this.workflows.get(workflowId);
29
+ if (!existing) {
30
+ throw new Error(`UserWorkflow not found: ${workflowId}`);
31
+ }
32
+
33
+ if (existing.userId !== updates.userId) {
34
+ throw new Error("Unauthorized: userId does not match workflow owner");
35
+ }
36
+
37
+ const updated = { ...existing, ...updates, workflowId };
38
+ this.workflows.set(workflowId, updated);
39
+ }
40
+
41
+ public async deleteUserWorkflow(workflowId: string, userId: string): Promise<void> {
42
+ const workflow = this.workflows.get(workflowId);
43
+ if (workflow && workflow.userId === userId) {
44
+ this.workflows.delete(workflowId);
45
+ this.userWorkflowIndex.get(userId)?.delete(workflowId);
46
+ }
47
+ }
48
+
49
+ public async listUserWorkflows(userId?: string): Promise<UserWorkflow[]> {
50
+ if (userId) {
51
+ const userWorkflowIds = this.userWorkflowIndex.get(userId);
52
+ if (!userWorkflowIds) return [];
53
+ const workflows: UserWorkflow[] = [];
54
+ for (const workflowId of userWorkflowIds) {
55
+ const workflow = this.workflows.get(workflowId);
56
+ if (workflow) {
57
+ workflows.push(workflow);
58
+ }
59
+ }
60
+ return workflows;
61
+ }
62
+
63
+ return Array.from(this.workflows.values());
64
+ }
65
+
66
+ public async listActiveScheduledWorkflows(): Promise<UserWorkflow[]> {
67
+ const result: UserWorkflow[] = [];
68
+ for (const workflow of this.workflows.values()) {
69
+ if (workflow.active && workflow.schedule) {
70
+ result.push(workflow);
71
+ }
72
+ }
73
+ return result;
74
+ }
75
+ }
@@ -0,0 +1,33 @@
1
+ import { IWorkflowTemplateMemory } from "@ainetwork/adk/modules";
2
+ import type { WorkflowTemplate } from "@ainetwork/adk/types/memory";
3
+
4
+ export class InMemoryWorkflowTemplate implements IWorkflowTemplateMemory {
5
+ private templates: Map<string, WorkflowTemplate> = new Map();
6
+
7
+ public async createTemplate(template: WorkflowTemplate): Promise<WorkflowTemplate> {
8
+ this.templates.set(template.templateId, template);
9
+ return template;
10
+ }
11
+
12
+ public async getTemplate(templateId: string): Promise<WorkflowTemplate | undefined> {
13
+ return this.templates.get(templateId);
14
+ }
15
+
16
+ public async updateTemplate(templateId: string, updates: Partial<WorkflowTemplate>): Promise<void> {
17
+ const existing = this.templates.get(templateId);
18
+ if (!existing) {
19
+ throw new Error(`WorkflowTemplate not found: ${templateId}`);
20
+ }
21
+
22
+ const updated = { ...existing, ...updates, templateId };
23
+ this.templates.set(templateId, updated);
24
+ }
25
+
26
+ public async deleteTemplate(templateId: string): Promise<void> {
27
+ this.templates.delete(templateId);
28
+ }
29
+
30
+ public async listTemplates(): Promise<WorkflowTemplate[]> {
31
+ return Array.from(this.templates.values());
32
+ }
33
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ainetwork/adk-provider-memory-inmemory",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "author": "AI Network (https://ainetwork.ai)",
5
5
  "type": "module",
6
6
  "engines": {
@@ -20,8 +20,8 @@
20
20
  "build": "tsup",
21
21
  "clean": "rm -rf dist"
22
22
  },
23
- "dependencies": {
24
- "@ainetwork/adk": "^0.4.1"
23
+ "peerDependencies": {
24
+ "@ainetwork/adk": "^0.5.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "typescript": "^5.0.0"
@@ -30,5 +30,5 @@
30
30
  "publishConfig": {
31
31
  "access": "public"
32
32
  },
33
- "gitHead": "49996589506616fbfe330a0ad992301b06d55066"
33
+ "gitHead": "195536a123f1471afc0974adf1671eb63296f469"
34
34
  }
@@ -1,76 +0,0 @@
1
- import { IWorkflowMemory } from "@ainetwork/adk/modules";
2
- import type { Workflow } from "@ainetwork/adk/types/memory";
3
-
4
- export class InMemoryWorkflow implements IWorkflowMemory {
5
- private workflows: Map<string, Workflow> = new Map();
6
- private userWorkflowIndex: Map<string, Set<string>> = new Map();
7
-
8
- public async createWorkflow(workflow: Workflow): Promise<Workflow> {
9
- this.workflows.set(workflow.workflowId, workflow);
10
-
11
- if (workflow.userId) {
12
- if (!this.userWorkflowIndex.has(workflow.userId)) {
13
- this.userWorkflowIndex.set(workflow.userId, new Set());
14
- }
15
- this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);
16
- }
17
-
18
- return workflow;
19
- }
20
-
21
- public async getWorkflow(workflowId: string): Promise<Workflow | undefined> {
22
- return this.workflows.get(workflowId);
23
- }
24
-
25
- public async updateWorkflow(workflowId: string, updates: Partial<Workflow>): Promise<void> {
26
- if (!updates.userId) {
27
- throw new Error("userId is required for updateWorkflow");
28
- }
29
-
30
- const existing = this.workflows.get(workflowId);
31
- if (!existing) {
32
- throw new Error(`Workflow not found: ${workflowId}`);
33
- }
34
-
35
- if (existing.userId !== updates.userId) {
36
- throw new Error("Unauthorized: userId does not match workflow owner");
37
- }
38
-
39
- const updated = { ...existing, ...updates, workflowId };
40
- this.workflows.set(workflowId, updated);
41
- }
42
-
43
- public async deleteWorkflow(workflowId: string, userId: string): Promise<void> {
44
- const workflow = this.workflows.get(workflowId);
45
- if (workflow && workflow.userId === userId) {
46
- this.workflows.delete(workflowId);
47
- this.userWorkflowIndex.get(userId)?.delete(workflowId);
48
- }
49
- }
50
-
51
- public async listWorkflows(userId?: string): Promise<Workflow[]> {
52
- const workflows: Workflow[] = [];
53
-
54
- // 템플릿 workflow (userId가 없는 것)은 항상 포함
55
- for (const workflow of this.workflows.values()) {
56
- if (!workflow.userId) {
57
- workflows.push(workflow);
58
- }
59
- }
60
-
61
- // userId가 있으면 해당 유저 소유 workflow도 포함
62
- if (userId) {
63
- const userWorkflowIds = this.userWorkflowIndex.get(userId);
64
- if (userWorkflowIds) {
65
- for (const workflowId of userWorkflowIds) {
66
- const workflow = this.workflows.get(workflowId);
67
- if (workflow) {
68
- workflows.push(workflow);
69
- }
70
- }
71
- }
72
- }
73
-
74
- return workflows;
75
- }
76
- }