@ainetwork/adk-provider-memory-inmemory 0.4.0 → 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.
- package/dist/index.cjs +98 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +98 -40
- package/dist/index.js.map +1 -1
- package/implements/base.memory.ts +13 -6
- package/implements/thread.memory.ts +46 -11
- package/implements/user-workflow.memory.ts +75 -0
- package/implements/workflow-template.memory.ts +33 -0
- package/package.json +3 -3
- package/implements/workflow.memory.ts +0 -76
package/dist/index.cjs
CHANGED
|
@@ -105,31 +105,35 @@ var InMemoryThread = class {
|
|
|
105
105
|
userId,
|
|
106
106
|
type: res.type,
|
|
107
107
|
title: res.title,
|
|
108
|
+
isPinned: res.isPinned,
|
|
109
|
+
workflowId: res.workflowId,
|
|
108
110
|
messages: res.messages
|
|
109
111
|
};
|
|
110
112
|
return threadObject;
|
|
111
113
|
}
|
|
112
114
|
return void 0;
|
|
113
115
|
}
|
|
114
|
-
async createThread(type, userId, threadId, title) {
|
|
116
|
+
async createThread(type, userId, threadId, title, workflowId) {
|
|
115
117
|
const now = Date.now();
|
|
116
118
|
const key = this.generateKey(userId, threadId);
|
|
117
119
|
if (!this.userThreadIndex.has(userId)) {
|
|
118
120
|
this.userThreadIndex.set(userId, /* @__PURE__ */ new Set());
|
|
119
121
|
}
|
|
120
122
|
if (!this.threads.has(key)) {
|
|
121
|
-
this.threads.set(key, { type, title, messages: [] });
|
|
123
|
+
this.threads.set(key, { type, title, isPinned: false, workflowId, messages: [] });
|
|
122
124
|
const metadata = {
|
|
123
125
|
type,
|
|
124
126
|
userId,
|
|
125
127
|
threadId,
|
|
126
128
|
title,
|
|
127
|
-
|
|
128
|
-
|
|
129
|
+
isPinned: false,
|
|
130
|
+
workflowId,
|
|
131
|
+
createdAt: new Date(now).toISOString(),
|
|
132
|
+
updatedAt: new Date(now).toISOString()
|
|
129
133
|
};
|
|
130
134
|
this.userThreadIndex.get(userId)?.add(metadata);
|
|
131
135
|
}
|
|
132
|
-
return { type, title, threadId, userId, messages: [] };
|
|
136
|
+
return { type, title, threadId, userId, workflowId, messages: [] };
|
|
133
137
|
}
|
|
134
138
|
async addMessagesToThread(userId, threadId, messages) {
|
|
135
139
|
const key = this.generateKey(userId, threadId);
|
|
@@ -151,39 +155,58 @@ var InMemoryThread = class {
|
|
|
151
155
|
}
|
|
152
156
|
}
|
|
153
157
|
}
|
|
154
|
-
async listThreads(userId) {
|
|
158
|
+
async listThreads(userId, filter) {
|
|
155
159
|
const threads = this.userThreadIndex.get(userId);
|
|
156
|
-
if (threads)
|
|
157
|
-
|
|
160
|
+
if (!threads) return [];
|
|
161
|
+
let result = Array.from(threads);
|
|
162
|
+
if (filter?.workflowId) {
|
|
163
|
+
result = result.filter((t) => t.workflowId === filter.workflowId);
|
|
164
|
+
}
|
|
165
|
+
if (filter?.type) {
|
|
166
|
+
result = result.filter((t) => t.type === filter.type);
|
|
167
|
+
}
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
170
|
+
async updateThreadPin(userId, threadId, isPinned) {
|
|
171
|
+
const key = this.generateKey(userId, threadId);
|
|
172
|
+
const thread = this.threads.get(key);
|
|
173
|
+
if (thread) {
|
|
174
|
+
thread.isPinned = isPinned;
|
|
175
|
+
}
|
|
176
|
+
const userThreads = this.userThreadIndex.get(userId);
|
|
177
|
+
if (userThreads) {
|
|
178
|
+
const metadata = Array.from(userThreads).find(
|
|
179
|
+
(m) => m.threadId === threadId
|
|
180
|
+
);
|
|
181
|
+
if (metadata) {
|
|
182
|
+
metadata.isPinned = isPinned;
|
|
183
|
+
}
|
|
158
184
|
}
|
|
159
|
-
return [];
|
|
160
185
|
}
|
|
161
186
|
};
|
|
162
187
|
|
|
163
|
-
// implements/workflow.memory.ts
|
|
164
|
-
var
|
|
188
|
+
// implements/user-workflow.memory.ts
|
|
189
|
+
var InMemoryUserWorkflow = class {
|
|
165
190
|
workflows = /* @__PURE__ */ new Map();
|
|
166
191
|
userWorkflowIndex = /* @__PURE__ */ new Map();
|
|
167
|
-
async
|
|
192
|
+
async createUserWorkflow(workflow) {
|
|
168
193
|
this.workflows.set(workflow.workflowId, workflow);
|
|
169
|
-
if (workflow.userId) {
|
|
170
|
-
|
|
171
|
-
this.userWorkflowIndex.set(workflow.userId, /* @__PURE__ */ new Set());
|
|
172
|
-
}
|
|
173
|
-
this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);
|
|
194
|
+
if (!this.userWorkflowIndex.has(workflow.userId)) {
|
|
195
|
+
this.userWorkflowIndex.set(workflow.userId, /* @__PURE__ */ new Set());
|
|
174
196
|
}
|
|
197
|
+
this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);
|
|
175
198
|
return workflow;
|
|
176
199
|
}
|
|
177
|
-
async
|
|
200
|
+
async getUserWorkflow(workflowId) {
|
|
178
201
|
return this.workflows.get(workflowId);
|
|
179
202
|
}
|
|
180
|
-
async
|
|
203
|
+
async updateUserWorkflow(workflowId, updates) {
|
|
181
204
|
if (!updates.userId) {
|
|
182
|
-
throw new Error("userId is required for
|
|
205
|
+
throw new Error("userId is required for updateUserWorkflow");
|
|
183
206
|
}
|
|
184
207
|
const existing = this.workflows.get(workflowId);
|
|
185
208
|
if (!existing) {
|
|
186
|
-
throw new Error(`
|
|
209
|
+
throw new Error(`UserWorkflow not found: ${workflowId}`);
|
|
187
210
|
}
|
|
188
211
|
if (existing.userId !== updates.userId) {
|
|
189
212
|
throw new Error("Unauthorized: userId does not match workflow owner");
|
|
@@ -191,32 +214,62 @@ var InMemoryWorkflow = class {
|
|
|
191
214
|
const updated = { ...existing, ...updates, workflowId };
|
|
192
215
|
this.workflows.set(workflowId, updated);
|
|
193
216
|
}
|
|
194
|
-
async
|
|
217
|
+
async deleteUserWorkflow(workflowId, userId) {
|
|
195
218
|
const workflow = this.workflows.get(workflowId);
|
|
196
219
|
if (workflow && workflow.userId === userId) {
|
|
197
220
|
this.workflows.delete(workflowId);
|
|
198
221
|
this.userWorkflowIndex.get(userId)?.delete(workflowId);
|
|
199
222
|
}
|
|
200
223
|
}
|
|
201
|
-
async
|
|
202
|
-
const workflows = [];
|
|
203
|
-
for (const workflow of this.workflows.values()) {
|
|
204
|
-
if (!workflow.userId) {
|
|
205
|
-
workflows.push(workflow);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
224
|
+
async listUserWorkflows(userId) {
|
|
208
225
|
if (userId) {
|
|
209
226
|
const userWorkflowIds = this.userWorkflowIndex.get(userId);
|
|
210
|
-
if (userWorkflowIds)
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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);
|
|
216
233
|
}
|
|
217
234
|
}
|
|
235
|
+
return workflows;
|
|
218
236
|
}
|
|
219
|
-
return workflows;
|
|
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
|
+
}
|
|
245
|
+
}
|
|
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());
|
|
220
273
|
}
|
|
221
274
|
};
|
|
222
275
|
|
|
@@ -227,7 +280,8 @@ var InMemoryMemory = class _InMemoryMemory {
|
|
|
227
280
|
agentMemory;
|
|
228
281
|
intentMemory;
|
|
229
282
|
threadMemory;
|
|
230
|
-
|
|
283
|
+
workflowTemplateMemory;
|
|
284
|
+
userWorkflowMemory;
|
|
231
285
|
constructor() {
|
|
232
286
|
if (!_InMemoryMemory.instance) {
|
|
233
287
|
_InMemoryMemory.instance = this;
|
|
@@ -235,7 +289,8 @@ var InMemoryMemory = class _InMemoryMemory {
|
|
|
235
289
|
this.agentMemory = new InMemoryAgent();
|
|
236
290
|
this.threadMemory = new InMemoryThread();
|
|
237
291
|
this.intentMemory = new InMemoryIntent();
|
|
238
|
-
this.
|
|
292
|
+
this.workflowTemplateMemory = new InMemoryWorkflowTemplate();
|
|
293
|
+
this.userWorkflowMemory = new InMemoryUserWorkflow();
|
|
239
294
|
}
|
|
240
295
|
async connect() {
|
|
241
296
|
this.connected = true;
|
|
@@ -255,8 +310,11 @@ var InMemoryMemory = class _InMemoryMemory {
|
|
|
255
310
|
getIntentMemory() {
|
|
256
311
|
return this.intentMemory;
|
|
257
312
|
}
|
|
258
|
-
|
|
259
|
-
return this.
|
|
313
|
+
getWorkflowTemplateMemory() {
|
|
314
|
+
return this.workflowTemplateMemory;
|
|
315
|
+
}
|
|
316
|
+
getUserWorkflowMemory() {
|
|
317
|
+
return this.userWorkflowMemory;
|
|
260
318
|
}
|
|
261
319
|
};
|
|
262
320
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.cjs.map
CHANGED
|
@@ -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 messages: Array<MessageObject>;\n}\n\ntype InMemoryThreadMetadata = {\n type: ThreadType;\n userId: string;\n threadId: string;\n title: string;\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 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, messages: [] });\n const metadata: InMemoryThreadMetadata = {\n type, userId, threadId, title, 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}","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,gBAAN,MAA4C;AAAA,EACzC,cAAsB;AAAA,EACtB,kBAA0B;AAAA,EAC1B,sBAA8B;AAAA,EAC9B,sBAA8B;AAAA,EAC9B,qBAA6B;AAAA,EAC7B,mBAA2B;AAAA,EAC3B,kBAA0B;AAAA,EAC1B,kBAA0B;AAAA,EAElC,MAAa,iBAAkC;AAC7C,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,kBAAkB,QAA+B;AAC5D,SAAK,cAAc;AAAA,EACrB;AAAA,EAEA,MAAa,qBAAsC;AACjD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,yBAA0C;AACrD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,yBAA0C;AACrD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,wBAAyC;AACpD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,sBAAuC;AAClD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,qBAAsC;AACjD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,qBAAsC;AACjD,WAAO,KAAK;AAAA,EACd;AACF;;;AC/CA,yBAA2B;AAIpB,IAAM,iBAAN,MAA8C;AAAA,EAC5C,UAA+B,oBAAI,IAAI;AAAA,EAE9C,MAAa,UAAU,UAA+C;AACpE,WAAO,KAAK,QAAQ,IAAI,QAAQ;AAAA,EAClC;AAAA,EAEA,MAAa,gBAAgB,YAAiD;AAC5E,WAAO,MAAM,KAAK,KAAK,QAAQ,OAAO,CAAC,EAAE,KAAK,YAAU,OAAO,SAAS,UAAU;AAAA,EACpF;AAAA,EAEA,MAAa,WAAW,QAA+B;AAErD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I,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(): IUserWorkflowMemory {\n return this.userWorkflowMemory;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,gBAAN,MAA4C;AAAA,EACzC,cAAsB;AAAA,EACtB,kBAA0B;AAAA,EAC1B,sBAA8B;AAAA,EAC9B,sBAA8B;AAAA,EAC9B,qBAA6B;AAAA,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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":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IMemory, IAgentMemory, IThreadMemory, IIntentMemory,
|
|
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
|
|
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
|
-
|
|
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,
|
|
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
|
|
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
|
-
|
|
18
|
+
getWorkflowTemplateMemory(): IWorkflowTemplateMemory;
|
|
19
|
+
getUserWorkflowMemory(): IUserWorkflowMemory;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
export { InMemoryMemory };
|
package/dist/index.js
CHANGED
|
@@ -79,31 +79,35 @@ var InMemoryThread = class {
|
|
|
79
79
|
userId,
|
|
80
80
|
type: res.type,
|
|
81
81
|
title: res.title,
|
|
82
|
+
isPinned: res.isPinned,
|
|
83
|
+
workflowId: res.workflowId,
|
|
82
84
|
messages: res.messages
|
|
83
85
|
};
|
|
84
86
|
return threadObject;
|
|
85
87
|
}
|
|
86
88
|
return void 0;
|
|
87
89
|
}
|
|
88
|
-
async createThread(type, userId, threadId, title) {
|
|
90
|
+
async createThread(type, userId, threadId, title, workflowId) {
|
|
89
91
|
const now = Date.now();
|
|
90
92
|
const key = this.generateKey(userId, threadId);
|
|
91
93
|
if (!this.userThreadIndex.has(userId)) {
|
|
92
94
|
this.userThreadIndex.set(userId, /* @__PURE__ */ new Set());
|
|
93
95
|
}
|
|
94
96
|
if (!this.threads.has(key)) {
|
|
95
|
-
this.threads.set(key, { type, title, messages: [] });
|
|
97
|
+
this.threads.set(key, { type, title, isPinned: false, workflowId, messages: [] });
|
|
96
98
|
const metadata = {
|
|
97
99
|
type,
|
|
98
100
|
userId,
|
|
99
101
|
threadId,
|
|
100
102
|
title,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
isPinned: false,
|
|
104
|
+
workflowId,
|
|
105
|
+
createdAt: new Date(now).toISOString(),
|
|
106
|
+
updatedAt: new Date(now).toISOString()
|
|
103
107
|
};
|
|
104
108
|
this.userThreadIndex.get(userId)?.add(metadata);
|
|
105
109
|
}
|
|
106
|
-
return { type, title, threadId, userId, messages: [] };
|
|
110
|
+
return { type, title, threadId, userId, workflowId, messages: [] };
|
|
107
111
|
}
|
|
108
112
|
async addMessagesToThread(userId, threadId, messages) {
|
|
109
113
|
const key = this.generateKey(userId, threadId);
|
|
@@ -125,39 +129,58 @@ var InMemoryThread = class {
|
|
|
125
129
|
}
|
|
126
130
|
}
|
|
127
131
|
}
|
|
128
|
-
async listThreads(userId) {
|
|
132
|
+
async listThreads(userId, filter) {
|
|
129
133
|
const threads = this.userThreadIndex.get(userId);
|
|
130
|
-
if (threads)
|
|
131
|
-
|
|
134
|
+
if (!threads) return [];
|
|
135
|
+
let result = Array.from(threads);
|
|
136
|
+
if (filter?.workflowId) {
|
|
137
|
+
result = result.filter((t) => t.workflowId === filter.workflowId);
|
|
138
|
+
}
|
|
139
|
+
if (filter?.type) {
|
|
140
|
+
result = result.filter((t) => t.type === filter.type);
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
async updateThreadPin(userId, threadId, isPinned) {
|
|
145
|
+
const key = this.generateKey(userId, threadId);
|
|
146
|
+
const thread = this.threads.get(key);
|
|
147
|
+
if (thread) {
|
|
148
|
+
thread.isPinned = isPinned;
|
|
149
|
+
}
|
|
150
|
+
const userThreads = this.userThreadIndex.get(userId);
|
|
151
|
+
if (userThreads) {
|
|
152
|
+
const metadata = Array.from(userThreads).find(
|
|
153
|
+
(m) => m.threadId === threadId
|
|
154
|
+
);
|
|
155
|
+
if (metadata) {
|
|
156
|
+
metadata.isPinned = isPinned;
|
|
157
|
+
}
|
|
132
158
|
}
|
|
133
|
-
return [];
|
|
134
159
|
}
|
|
135
160
|
};
|
|
136
161
|
|
|
137
|
-
// implements/workflow.memory.ts
|
|
138
|
-
var
|
|
162
|
+
// implements/user-workflow.memory.ts
|
|
163
|
+
var InMemoryUserWorkflow = class {
|
|
139
164
|
workflows = /* @__PURE__ */ new Map();
|
|
140
165
|
userWorkflowIndex = /* @__PURE__ */ new Map();
|
|
141
|
-
async
|
|
166
|
+
async createUserWorkflow(workflow) {
|
|
142
167
|
this.workflows.set(workflow.workflowId, workflow);
|
|
143
|
-
if (workflow.userId) {
|
|
144
|
-
|
|
145
|
-
this.userWorkflowIndex.set(workflow.userId, /* @__PURE__ */ new Set());
|
|
146
|
-
}
|
|
147
|
-
this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);
|
|
168
|
+
if (!this.userWorkflowIndex.has(workflow.userId)) {
|
|
169
|
+
this.userWorkflowIndex.set(workflow.userId, /* @__PURE__ */ new Set());
|
|
148
170
|
}
|
|
171
|
+
this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);
|
|
149
172
|
return workflow;
|
|
150
173
|
}
|
|
151
|
-
async
|
|
174
|
+
async getUserWorkflow(workflowId) {
|
|
152
175
|
return this.workflows.get(workflowId);
|
|
153
176
|
}
|
|
154
|
-
async
|
|
177
|
+
async updateUserWorkflow(workflowId, updates) {
|
|
155
178
|
if (!updates.userId) {
|
|
156
|
-
throw new Error("userId is required for
|
|
179
|
+
throw new Error("userId is required for updateUserWorkflow");
|
|
157
180
|
}
|
|
158
181
|
const existing = this.workflows.get(workflowId);
|
|
159
182
|
if (!existing) {
|
|
160
|
-
throw new Error(`
|
|
183
|
+
throw new Error(`UserWorkflow not found: ${workflowId}`);
|
|
161
184
|
}
|
|
162
185
|
if (existing.userId !== updates.userId) {
|
|
163
186
|
throw new Error("Unauthorized: userId does not match workflow owner");
|
|
@@ -165,32 +188,62 @@ var InMemoryWorkflow = class {
|
|
|
165
188
|
const updated = { ...existing, ...updates, workflowId };
|
|
166
189
|
this.workflows.set(workflowId, updated);
|
|
167
190
|
}
|
|
168
|
-
async
|
|
191
|
+
async deleteUserWorkflow(workflowId, userId) {
|
|
169
192
|
const workflow = this.workflows.get(workflowId);
|
|
170
193
|
if (workflow && workflow.userId === userId) {
|
|
171
194
|
this.workflows.delete(workflowId);
|
|
172
195
|
this.userWorkflowIndex.get(userId)?.delete(workflowId);
|
|
173
196
|
}
|
|
174
197
|
}
|
|
175
|
-
async
|
|
176
|
-
const workflows = [];
|
|
177
|
-
for (const workflow of this.workflows.values()) {
|
|
178
|
-
if (!workflow.userId) {
|
|
179
|
-
workflows.push(workflow);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
198
|
+
async listUserWorkflows(userId) {
|
|
182
199
|
if (userId) {
|
|
183
200
|
const userWorkflowIds = this.userWorkflowIndex.get(userId);
|
|
184
|
-
if (userWorkflowIds)
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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);
|
|
190
207
|
}
|
|
191
208
|
}
|
|
209
|
+
return workflows;
|
|
192
210
|
}
|
|
193
|
-
return workflows;
|
|
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
|
+
}
|
|
219
|
+
}
|
|
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());
|
|
194
247
|
}
|
|
195
248
|
};
|
|
196
249
|
|
|
@@ -201,7 +254,8 @@ var InMemoryMemory = class _InMemoryMemory {
|
|
|
201
254
|
agentMemory;
|
|
202
255
|
intentMemory;
|
|
203
256
|
threadMemory;
|
|
204
|
-
|
|
257
|
+
workflowTemplateMemory;
|
|
258
|
+
userWorkflowMemory;
|
|
205
259
|
constructor() {
|
|
206
260
|
if (!_InMemoryMemory.instance) {
|
|
207
261
|
_InMemoryMemory.instance = this;
|
|
@@ -209,7 +263,8 @@ var InMemoryMemory = class _InMemoryMemory {
|
|
|
209
263
|
this.agentMemory = new InMemoryAgent();
|
|
210
264
|
this.threadMemory = new InMemoryThread();
|
|
211
265
|
this.intentMemory = new InMemoryIntent();
|
|
212
|
-
this.
|
|
266
|
+
this.workflowTemplateMemory = new InMemoryWorkflowTemplate();
|
|
267
|
+
this.userWorkflowMemory = new InMemoryUserWorkflow();
|
|
213
268
|
}
|
|
214
269
|
async connect() {
|
|
215
270
|
this.connected = true;
|
|
@@ -229,8 +284,11 @@ var InMemoryMemory = class _InMemoryMemory {
|
|
|
229
284
|
getIntentMemory() {
|
|
230
285
|
return this.intentMemory;
|
|
231
286
|
}
|
|
232
|
-
|
|
233
|
-
return this.
|
|
287
|
+
getWorkflowTemplateMemory() {
|
|
288
|
+
return this.workflowTemplateMemory;
|
|
289
|
+
}
|
|
290
|
+
getUserWorkflowMemory() {
|
|
291
|
+
return this.userWorkflowMemory;
|
|
234
292
|
}
|
|
235
293
|
};
|
|
236
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 messages: Array<MessageObject>;\n}\n\ntype InMemoryThreadMetadata = {\n type: ThreadType;\n userId: string;\n threadId: string;\n title: string;\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 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, messages: [] });\n const metadata: InMemoryThreadMetadata = {\n type, userId, threadId, title, 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}","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,qBAA6B;AAAA,EAC7B,mBAA2B;AAAA,EAC3B,kBAA0B;AAAA,EAC1B,kBAA0B;AAAA,EAElC,MAAa,iBAAkC;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I,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,sBAA8B;AAAA,EAC9B,qBAA6B;AAAA,EAC7B,mBAA2B;AAAA,EAC3B,kBAA0B;AAAA,EAC1B,kBAA0B;AAAA,EAElC,MAAa,iBAAkC;AAC7C,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,kBAAkB,QAA+B;AAC5D,SAAK,cAAc;AAAA,EACrB;AAAA,EAEA,MAAa,qBAAsC;AACjD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,yBAA0C;AACrD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,yBAA0C;AACrD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,wBAAyC;AACpD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,sBAAuC;AAClD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,qBAAsC;AACjD,WAAO,KAAK;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AAa,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,
|
|
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 {
|
|
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
|
|
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.
|
|
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
|
|
52
|
-
return this.
|
|
54
|
+
public getWorkflowTemplateMemory(): IWorkflowTemplateMemory {
|
|
55
|
+
return this.workflowTemplateMemory;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public getUserWorkflowMemory(): IUserWorkflowMemory {
|
|
59
|
+
return this.userWorkflowMemory;
|
|
53
60
|
}
|
|
54
61
|
}
|
|
@@ -1,9 +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
|
+
isPinned: boolean;
|
|
8
|
+
workflowId?: string;
|
|
7
9
|
messages: Array<MessageObject>;
|
|
8
10
|
}
|
|
9
11
|
|
|
@@ -12,8 +14,10 @@ type InMemoryThreadMetadata = {
|
|
|
12
14
|
userId: string;
|
|
13
15
|
threadId: string;
|
|
14
16
|
title: string;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
isPinned: boolean;
|
|
18
|
+
workflowId?: string;
|
|
19
|
+
updatedAt: string;
|
|
20
|
+
createdAt: string;
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
export class InMemoryThread implements IThreadMemory {
|
|
@@ -36,6 +40,8 @@ export class InMemoryThread implements IThreadMemory {
|
|
|
36
40
|
userId,
|
|
37
41
|
type: res.type,
|
|
38
42
|
title: res.title,
|
|
43
|
+
isPinned: res.isPinned,
|
|
44
|
+
workflowId: res.workflowId,
|
|
39
45
|
messages: res.messages,
|
|
40
46
|
};
|
|
41
47
|
return threadObject;
|
|
@@ -47,7 +53,8 @@ export class InMemoryThread implements IThreadMemory {
|
|
|
47
53
|
type: ThreadType,
|
|
48
54
|
userId: string,
|
|
49
55
|
threadId: string,
|
|
50
|
-
title: string
|
|
56
|
+
title: string,
|
|
57
|
+
workflowId?: string,
|
|
51
58
|
): Promise<ThreadObject> {
|
|
52
59
|
const now = Date.now();
|
|
53
60
|
const key = this.generateKey(userId, threadId);
|
|
@@ -55,14 +62,14 @@ export class InMemoryThread implements IThreadMemory {
|
|
|
55
62
|
this.userThreadIndex.set(userId, new Set());
|
|
56
63
|
}
|
|
57
64
|
if (!this.threads.has(key)) {
|
|
58
|
-
this.threads.set(key, { type, title, messages: [] });
|
|
65
|
+
this.threads.set(key, { type, title, isPinned: false, workflowId, messages: [] });
|
|
59
66
|
const metadata: InMemoryThreadMetadata = {
|
|
60
|
-
type, userId, threadId, title, createdAt: now, updatedAt: now,
|
|
67
|
+
type, userId, threadId, title, isPinned: false, workflowId, createdAt: new Date(now).toISOString(), updatedAt: new Date(now).toISOString(),
|
|
61
68
|
}
|
|
62
69
|
this.userThreadIndex.get(userId)?.add(metadata);
|
|
63
70
|
}
|
|
64
71
|
|
|
65
|
-
return { type, title, threadId, userId, messages: [] };
|
|
72
|
+
return { type, title, threadId, userId, workflowId, messages: [] };
|
|
66
73
|
}
|
|
67
74
|
|
|
68
75
|
public async addMessagesToThread(
|
|
@@ -93,11 +100,39 @@ export class InMemoryThread implements IThreadMemory {
|
|
|
93
100
|
}
|
|
94
101
|
}
|
|
95
102
|
|
|
96
|
-
public async listThreads(userId: string): Promise<ThreadMetadata[]> {
|
|
103
|
+
public async listThreads(userId: string, filter?: ThreadFilter): Promise<ThreadMetadata[]> {
|
|
97
104
|
const threads = this.userThreadIndex.get(userId);
|
|
98
|
-
if (threads)
|
|
99
|
-
|
|
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);
|
|
113
|
+
}
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public async updateThreadPin(
|
|
118
|
+
userId: string,
|
|
119
|
+
threadId: string,
|
|
120
|
+
isPinned: boolean
|
|
121
|
+
): Promise<void> {
|
|
122
|
+
const key = this.generateKey(userId, threadId);
|
|
123
|
+
const thread = this.threads.get(key);
|
|
124
|
+
if (thread) {
|
|
125
|
+
thread.isPinned = isPinned;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const userThreads = this.userThreadIndex.get(userId);
|
|
129
|
+
if (userThreads) {
|
|
130
|
+
const metadata = Array.from(userThreads).find(
|
|
131
|
+
m => m.threadId === threadId
|
|
132
|
+
);
|
|
133
|
+
if (metadata) {
|
|
134
|
+
metadata.isPinned = isPinned;
|
|
135
|
+
}
|
|
100
136
|
}
|
|
101
|
-
return [];
|
|
102
137
|
}
|
|
103
138
|
}
|
|
@@ -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.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"author": "AI Network (https://ainetwork.ai)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"clean": "rm -rf dist"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@ainetwork/adk": "^0.
|
|
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": "
|
|
33
|
+
"gitHead": "8c14fa8de70f23589cd273772db665f354f3e713"
|
|
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
|
-
}
|