@ainetwork/adk-provider-memory-inmemory 0.3.2 → 0.3.4

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
@@ -46,8 +46,9 @@ var InMemoryIntent = class {
46
46
  return Array.from(this.intents.values()).find((intent) => intent.name === intentName);
47
47
  }
48
48
  async saveIntent(intent) {
49
- const newId = (0, import_node_crypto.randomUUID)();
50
- this.intents.set(newId, intent);
49
+ const intentId = intent.id || (0, import_node_crypto.randomUUID)();
50
+ const intentToSave = { ...intent, id: intentId };
51
+ this.intents.set(intentId, intentToSave);
51
52
  }
52
53
  async updateIntent(intentId, intent) {
53
54
  this.intents.set(intentId, intent);
@@ -112,7 +113,15 @@ var InMemoryThread = class {
112
113
  async deleteThread(userId, threadId) {
113
114
  const key = this.generateKey(userId, threadId);
114
115
  this.threads.delete(key);
115
- this.userThreadIndex.delete(threadId);
116
+ const userThreads = this.userThreadIndex.get(userId);
117
+ if (userThreads) {
118
+ const metadataToDelete = Array.from(userThreads).find(
119
+ (metadata) => metadata.threadId === threadId
120
+ );
121
+ if (metadataToDelete) {
122
+ userThreads.delete(metadataToDelete);
123
+ }
124
+ }
116
125
  }
117
126
  async listThreads(userId) {
118
127
  const threads = this.userThreadIndex.get(userId);
@@ -123,6 +132,69 @@ var InMemoryThread = class {
123
132
  }
124
133
  };
125
134
 
135
+ // implements/workflow.memory.ts
136
+ var InMemoryWorkflow = class {
137
+ workflows = /* @__PURE__ */ new Map();
138
+ userWorkflowIndex = /* @__PURE__ */ new Map();
139
+ async createWorkflow(workflow) {
140
+ this.workflows.set(workflow.workflowId, workflow);
141
+ if (workflow.userId) {
142
+ if (!this.userWorkflowIndex.has(workflow.userId)) {
143
+ this.userWorkflowIndex.set(workflow.userId, /* @__PURE__ */ new Set());
144
+ }
145
+ this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);
146
+ }
147
+ return workflow;
148
+ }
149
+ async getWorkflow(workflowId) {
150
+ return this.workflows.get(workflowId);
151
+ }
152
+ async updateWorkflow(workflowId, updates) {
153
+ const existing = this.workflows.get(workflowId);
154
+ if (existing) {
155
+ const updated = { ...existing, ...updates, workflowId };
156
+ if (updates.userId !== void 0 && existing.userId !== updates.userId) {
157
+ if (existing.userId) {
158
+ this.userWorkflowIndex.get(existing.userId)?.delete(workflowId);
159
+ }
160
+ if (updates.userId) {
161
+ if (!this.userWorkflowIndex.has(updates.userId)) {
162
+ this.userWorkflowIndex.set(updates.userId, /* @__PURE__ */ new Set());
163
+ }
164
+ this.userWorkflowIndex.get(updates.userId)?.add(workflowId);
165
+ }
166
+ }
167
+ this.workflows.set(workflowId, updated);
168
+ }
169
+ }
170
+ async deleteWorkflow(workflowId) {
171
+ const workflow = this.workflows.get(workflowId);
172
+ if (workflow) {
173
+ this.workflows.delete(workflowId);
174
+ if (workflow.userId) {
175
+ this.userWorkflowIndex.get(workflow.userId)?.delete(workflowId);
176
+ }
177
+ }
178
+ }
179
+ async listWorkflows(userId) {
180
+ if (userId) {
181
+ const workflowIds = this.userWorkflowIndex.get(userId);
182
+ if (!workflowIds) {
183
+ return [];
184
+ }
185
+ const workflows = [];
186
+ for (const workflowId of workflowIds) {
187
+ const workflow = this.workflows.get(workflowId);
188
+ if (workflow) {
189
+ workflows.push(workflow);
190
+ }
191
+ }
192
+ return workflows;
193
+ }
194
+ return Array.from(this.workflows.values());
195
+ }
196
+ };
197
+
126
198
  // implements/base.memory.ts
127
199
  var InMemoryMemory = class _InMemoryMemory {
128
200
  static instance;
@@ -130,6 +202,7 @@ var InMemoryMemory = class _InMemoryMemory {
130
202
  agentMemory;
131
203
  intentMemory;
132
204
  threadMemory;
205
+ workflowMemory;
133
206
  constructor() {
134
207
  if (!_InMemoryMemory.instance) {
135
208
  _InMemoryMemory.instance = this;
@@ -137,6 +210,7 @@ var InMemoryMemory = class _InMemoryMemory {
137
210
  this.agentMemory = new InMemoryAgent();
138
211
  this.threadMemory = new InMemoryThread();
139
212
  this.intentMemory = new InMemoryIntent();
213
+ this.workflowMemory = new InMemoryWorkflow();
140
214
  }
141
215
  async connect() {
142
216
  this.connected = true;
@@ -156,6 +230,9 @@ var InMemoryMemory = class _InMemoryMemory {
156
230
  getIntentMemory() {
157
231
  return this.intentMemory;
158
232
  }
233
+ getWorkflowMemory() {
234
+ return this.workflowMemory;
235
+ }
159
236
  };
160
237
  // Annotate the CommonJS export names for ESM import in node:
161
238
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts","../implements/agent.memory.ts","../implements/intent.memory.ts","../implements/thread.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 prompt: string = \"\";\n\n public async getAgentPrompt(): Promise<string> {\n return this.prompt;\n }\n\n public async updateAgentPrompt(prompt: string): Promise<void> {\n this.prompt = prompt;\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 const newId = randomUUID();\n this.intents.set(newId, intent);\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 this.userThreadIndex.delete(threadId);\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 { IAgentMemory, IIntentMemory, IMemory, IThreadMemory } from \"node_modules/@ainetwork/adk/dist/esm/modules/memory/base.memory\";\nimport { InMemoryAgent } from \"./agent.memory\";\nimport { InMemoryIntent } from \"./intent.memory\";\nimport { InMemoryThread } from \"./thread.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\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 }\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,gBAAN,MAA4C;AAAA,EACzC,SAAiB;AAAA,EAEzB,MAAa,iBAAkC;AAC7C,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,kBAAkB,QAA+B;AAC5D,SAAK,SAAS;AAAA,EAChB;AACF;;;ACZA,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;AACrD,UAAM,YAAQ,+BAAW;AACzB,SAAK,QAAQ,IAAI,OAAO,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AAA,EAEO,kBAAiC;AACtC,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/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 prompt: string = \"\";\n\n public async getAgentPrompt(): Promise<string> {\n return this.prompt;\n }\n\n public async updateAgentPrompt(prompt: string): Promise<void> {\n this.prompt = prompt;\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 const existing = this.workflows.get(workflowId);\n if (existing) {\n const updated = { ...existing, ...updates, workflowId };\n\n // userId가 변경된 경우 인덱스 업데이트\n if (updates.userId !== undefined && existing.userId !== updates.userId) {\n // 기존 userId 인덱스에서 제거\n if (existing.userId) {\n this.userWorkflowIndex.get(existing.userId)?.delete(workflowId);\n }\n // 새 userId 인덱스에 추가\n if (updates.userId) {\n if (!this.userWorkflowIndex.has(updates.userId)) {\n this.userWorkflowIndex.set(updates.userId, new Set());\n }\n this.userWorkflowIndex.get(updates.userId)?.add(workflowId);\n }\n }\n\n this.workflows.set(workflowId, updated);\n }\n }\n\n public async deleteWorkflow(workflowId: string): Promise<void> {\n const workflow = this.workflows.get(workflowId);\n if (workflow) {\n this.workflows.delete(workflowId);\n\n // 인덱스에서도 제거\n if (workflow.userId) {\n this.userWorkflowIndex.get(workflow.userId)?.delete(workflowId);\n }\n }\n }\n\n public async listWorkflows(userId?: string): Promise<Workflow[]> {\n if (userId) {\n const workflowIds = this.userWorkflowIndex.get(userId);\n if (!workflowIds) {\n return [];\n }\n\n const workflows: Workflow[] = [];\n for (const workflowId of workflowIds) {\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","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,SAAiB;AAAA,EAEzB,MAAa,iBAAkC;AAC7C,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,kBAAkB,QAA+B;AAC5D,SAAK,SAAS;AAAA,EAChB;AACF;;;ACZA,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,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,EAEA,MAAa,cAAc,QAAsC;AAC/D,QAAI,QAAQ;AACV,YAAM,cAAc,KAAK,kBAAkB,IAAI,MAAM;AACrD,UAAI,CAAC,aAAa;AAChB,eAAO,CAAC;AAAA,MACV;AAEA,YAAM,YAAwB,CAAC;AAC/B,iBAAW,cAAc,aAAa;AACpC,cAAM,WAAW,KAAK,UAAU,IAAI,UAAU;AAC9C,YAAI,UAAU;AACZ,oBAAU,KAAK,QAAQ;AAAA,QACzB;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAEA,WAAO,MAAM,KAAK,KAAK,UAAU,OAAO,CAAC;AAAA,EAC3C;AACF;;;ACzEO,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":[]}
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { IMemory, IAgentMemory, IThreadMemory, IIntentMemory } from 'node_modules/@ainetwork/adk/dist/esm/modules/memory/base.memory';
1
+ import { IMemory, IAgentMemory, IThreadMemory, IIntentMemory, IWorkflowMemory } from '@ainetwork/adk/modules';
2
2
 
3
3
  declare class InMemoryMemory implements IMemory {
4
4
  private static instance;
@@ -6,6 +6,7 @@ declare class InMemoryMemory implements IMemory {
6
6
  private agentMemory;
7
7
  private intentMemory;
8
8
  private threadMemory;
9
+ private workflowMemory;
9
10
  constructor();
10
11
  connect(): Promise<void>;
11
12
  disconnect(): Promise<void>;
@@ -13,6 +14,7 @@ declare class InMemoryMemory implements IMemory {
13
14
  getAgentMemory(): IAgentMemory;
14
15
  getThreadMemory(): IThreadMemory;
15
16
  getIntentMemory(): IIntentMemory;
17
+ getWorkflowMemory(): IWorkflowMemory;
16
18
  }
17
19
 
18
20
  export { InMemoryMemory };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IMemory, IAgentMemory, IThreadMemory, IIntentMemory } from 'node_modules/@ainetwork/adk/dist/esm/modules/memory/base.memory';
1
+ import { IMemory, IAgentMemory, IThreadMemory, IIntentMemory, IWorkflowMemory } from '@ainetwork/adk/modules';
2
2
 
3
3
  declare class InMemoryMemory implements IMemory {
4
4
  private static instance;
@@ -6,6 +6,7 @@ declare class InMemoryMemory implements IMemory {
6
6
  private agentMemory;
7
7
  private intentMemory;
8
8
  private threadMemory;
9
+ private workflowMemory;
9
10
  constructor();
10
11
  connect(): Promise<void>;
11
12
  disconnect(): Promise<void>;
@@ -13,6 +14,7 @@ declare class InMemoryMemory implements IMemory {
13
14
  getAgentMemory(): IAgentMemory;
14
15
  getThreadMemory(): IThreadMemory;
15
16
  getIntentMemory(): IIntentMemory;
17
+ getWorkflowMemory(): IWorkflowMemory;
16
18
  }
17
19
 
18
20
  export { InMemoryMemory };
package/dist/index.js CHANGED
@@ -20,8 +20,9 @@ var InMemoryIntent = class {
20
20
  return Array.from(this.intents.values()).find((intent) => intent.name === intentName);
21
21
  }
22
22
  async saveIntent(intent) {
23
- const newId = randomUUID();
24
- this.intents.set(newId, intent);
23
+ const intentId = intent.id || randomUUID();
24
+ const intentToSave = { ...intent, id: intentId };
25
+ this.intents.set(intentId, intentToSave);
25
26
  }
26
27
  async updateIntent(intentId, intent) {
27
28
  this.intents.set(intentId, intent);
@@ -86,7 +87,15 @@ var InMemoryThread = class {
86
87
  async deleteThread(userId, threadId) {
87
88
  const key = this.generateKey(userId, threadId);
88
89
  this.threads.delete(key);
89
- this.userThreadIndex.delete(threadId);
90
+ const userThreads = this.userThreadIndex.get(userId);
91
+ if (userThreads) {
92
+ const metadataToDelete = Array.from(userThreads).find(
93
+ (metadata) => metadata.threadId === threadId
94
+ );
95
+ if (metadataToDelete) {
96
+ userThreads.delete(metadataToDelete);
97
+ }
98
+ }
90
99
  }
91
100
  async listThreads(userId) {
92
101
  const threads = this.userThreadIndex.get(userId);
@@ -97,6 +106,69 @@ var InMemoryThread = class {
97
106
  }
98
107
  };
99
108
 
109
+ // implements/workflow.memory.ts
110
+ var InMemoryWorkflow = class {
111
+ workflows = /* @__PURE__ */ new Map();
112
+ userWorkflowIndex = /* @__PURE__ */ new Map();
113
+ async createWorkflow(workflow) {
114
+ this.workflows.set(workflow.workflowId, workflow);
115
+ if (workflow.userId) {
116
+ if (!this.userWorkflowIndex.has(workflow.userId)) {
117
+ this.userWorkflowIndex.set(workflow.userId, /* @__PURE__ */ new Set());
118
+ }
119
+ this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);
120
+ }
121
+ return workflow;
122
+ }
123
+ async getWorkflow(workflowId) {
124
+ return this.workflows.get(workflowId);
125
+ }
126
+ async updateWorkflow(workflowId, updates) {
127
+ const existing = this.workflows.get(workflowId);
128
+ if (existing) {
129
+ const updated = { ...existing, ...updates, workflowId };
130
+ if (updates.userId !== void 0 && existing.userId !== updates.userId) {
131
+ if (existing.userId) {
132
+ this.userWorkflowIndex.get(existing.userId)?.delete(workflowId);
133
+ }
134
+ if (updates.userId) {
135
+ if (!this.userWorkflowIndex.has(updates.userId)) {
136
+ this.userWorkflowIndex.set(updates.userId, /* @__PURE__ */ new Set());
137
+ }
138
+ this.userWorkflowIndex.get(updates.userId)?.add(workflowId);
139
+ }
140
+ }
141
+ this.workflows.set(workflowId, updated);
142
+ }
143
+ }
144
+ async deleteWorkflow(workflowId) {
145
+ const workflow = this.workflows.get(workflowId);
146
+ if (workflow) {
147
+ this.workflows.delete(workflowId);
148
+ if (workflow.userId) {
149
+ this.userWorkflowIndex.get(workflow.userId)?.delete(workflowId);
150
+ }
151
+ }
152
+ }
153
+ async listWorkflows(userId) {
154
+ if (userId) {
155
+ const workflowIds = this.userWorkflowIndex.get(userId);
156
+ if (!workflowIds) {
157
+ return [];
158
+ }
159
+ const workflows = [];
160
+ for (const workflowId of workflowIds) {
161
+ const workflow = this.workflows.get(workflowId);
162
+ if (workflow) {
163
+ workflows.push(workflow);
164
+ }
165
+ }
166
+ return workflows;
167
+ }
168
+ return Array.from(this.workflows.values());
169
+ }
170
+ };
171
+
100
172
  // implements/base.memory.ts
101
173
  var InMemoryMemory = class _InMemoryMemory {
102
174
  static instance;
@@ -104,6 +176,7 @@ var InMemoryMemory = class _InMemoryMemory {
104
176
  agentMemory;
105
177
  intentMemory;
106
178
  threadMemory;
179
+ workflowMemory;
107
180
  constructor() {
108
181
  if (!_InMemoryMemory.instance) {
109
182
  _InMemoryMemory.instance = this;
@@ -111,6 +184,7 @@ var InMemoryMemory = class _InMemoryMemory {
111
184
  this.agentMemory = new InMemoryAgent();
112
185
  this.threadMemory = new InMemoryThread();
113
186
  this.intentMemory = new InMemoryIntent();
187
+ this.workflowMemory = new InMemoryWorkflow();
114
188
  }
115
189
  async connect() {
116
190
  this.connected = true;
@@ -130,6 +204,9 @@ var InMemoryMemory = class _InMemoryMemory {
130
204
  getIntentMemory() {
131
205
  return this.intentMemory;
132
206
  }
207
+ getWorkflowMemory() {
208
+ return this.workflowMemory;
209
+ }
133
210
  };
134
211
  export {
135
212
  InMemoryMemory
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/base.memory.ts"],"sourcesContent":["import { IAgentMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryAgent implements IAgentMemory {\n private prompt: string = \"\";\n\n public async getAgentPrompt(): Promise<string> {\n return this.prompt;\n }\n\n public async updateAgentPrompt(prompt: string): Promise<void> {\n this.prompt = prompt;\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 const newId = randomUUID();\n this.intents.set(newId, intent);\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 this.userThreadIndex.delete(threadId);\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 { IAgentMemory, IIntentMemory, IMemory, IThreadMemory } from \"node_modules/@ainetwork/adk/dist/esm/modules/memory/base.memory\";\nimport { InMemoryAgent } from \"./agent.memory\";\nimport { InMemoryIntent } from \"./intent.memory\";\nimport { InMemoryThread } from \"./thread.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\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 }\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"],"mappings":";AAEO,IAAM,gBAAN,MAA4C;AAAA,EACzC,SAAiB;AAAA,EAEzB,MAAa,iBAAkC;AAC7C,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,kBAAkB,QAA+B;AAC5D,SAAK,SAAS;AAAA,EAChB;AACF;;;ACZA,SAAS,kBAAkB;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;AACrD,UAAM,QAAQ,WAAW;AACzB,SAAK,QAAQ,IAAI,OAAO,MAAM;AAAA,EAChC;AAAA,EAEA,MAAa,aAAa,UAAkB,QAA+B;AACzE,SAAK,QAAQ,IAAI,UAAU,MAAM;AAAA,EACnC;AAAA,EAEA,MAAa,aAAa,UAAiC;AACzD,SAAK,QAAQ,OAAO,QAAQ;AAAA,EAC9B;AAAA,EAEA,MAAa,cAAiC;AAC5C,WAAO,MAAM,KAAK,KAAK,QAAQ,OAAO,CAAC;AAAA,EACzC;AACF;;;ACbO,IAAM,iBAAN,MAA8C;AAAA,EAC5C,UAA6C,oBAAI,IAAI;AAAA,EACrD,kBAA4D,oBAAI,IAAI;AAAA,EAEnE,YAAY,QAAgB,UAAkB;AACpD,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YAAY,QAAQ,QAAQ;AAC7C,SAAK,QAAQ,OAAO,GAAG;AACvB,SAAK,gBAAgB,OAAO,QAAQ;AAAA,EACtC;AAAA,EAEA,MAAa,YAAY,QAA2C;AAClE,UAAM,UAAU,KAAK,gBAAgB,IAAI,MAAM;AAC/C,QAAI,SAAS;AACX,aAAO,MAAM,KAAK,OAAO;AAAA,IAC3B;AACA,WAAO,CAAC;AAAA,EACV;AACF;;;ACvFO,IAAM,iBAAN,MAAM,gBAAkC;AAAA,EAC7C,OAAe;AAAA,EACP,YAAqB;AAAA,EAErB;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;AAAA,EACzC;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;AACF;","names":[]}
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 prompt: string = \"\";\n\n public async getAgentPrompt(): Promise<string> {\n return this.prompt;\n }\n\n public async updateAgentPrompt(prompt: string): Promise<void> {\n this.prompt = prompt;\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 const existing = this.workflows.get(workflowId);\n if (existing) {\n const updated = { ...existing, ...updates, workflowId };\n\n // userId가 변경된 경우 인덱스 업데이트\n if (updates.userId !== undefined && existing.userId !== updates.userId) {\n // 기존 userId 인덱스에서 제거\n if (existing.userId) {\n this.userWorkflowIndex.get(existing.userId)?.delete(workflowId);\n }\n // 새 userId 인덱스에 추가\n if (updates.userId) {\n if (!this.userWorkflowIndex.has(updates.userId)) {\n this.userWorkflowIndex.set(updates.userId, new Set());\n }\n this.userWorkflowIndex.get(updates.userId)?.add(workflowId);\n }\n }\n\n this.workflows.set(workflowId, updated);\n }\n }\n\n public async deleteWorkflow(workflowId: string): Promise<void> {\n const workflow = this.workflows.get(workflowId);\n if (workflow) {\n this.workflows.delete(workflowId);\n\n // 인덱스에서도 제거\n if (workflow.userId) {\n this.userWorkflowIndex.get(workflow.userId)?.delete(workflowId);\n }\n }\n }\n\n public async listWorkflows(userId?: string): Promise<Workflow[]> {\n if (userId) {\n const workflowIds = this.userWorkflowIndex.get(userId);\n if (!workflowIds) {\n return [];\n }\n\n const workflows: Workflow[] = [];\n for (const workflowId of workflowIds) {\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","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,SAAiB;AAAA,EAEzB,MAAa,iBAAkC;AAC7C,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,kBAAkB,QAA+B;AAC5D,SAAK,SAAS;AAAA,EAChB;AACF;;;ACZA,SAAS,kBAAkB;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,UAAM,WAAW,OAAO,MAAM,WAAW;AACzC,UAAM,eAAe,EAAE,GAAG,QAAQ,IAAI,SAAS;AAC/C,SAAK,QAAQ,IAAI,UAAU,YAAY;AAAA,EACzC;AAAA,EAEA,MAAa,aAAa,UAAkB,QAA+B;AACzE,SAAK,QAAQ,IAAI,UAAU,MAAM;AAAA,EACnC;AAAA,EAEA,MAAa,aAAa,UAAiC;AACzD,SAAK,QAAQ,OAAO,QAAQ;AAAA,EAC9B;AAAA,EAEA,MAAa,cAAiC;AAC5C,WAAO,MAAM,KAAK,KAAK,QAAQ,OAAO,CAAC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A;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,7 +1,8 @@
1
- import { IAgentMemory, IIntentMemory, IMemory, IThreadMemory } from "node_modules/@ainetwork/adk/dist/esm/modules/memory/base.memory";
1
+ import { IAgentMemory, IIntentMemory, IMemory, IThreadMemory, IWorkflowMemory } 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
6
 
6
7
  export class InMemoryMemory implements IMemory {
7
8
  private static instance: InMemoryMemory;
@@ -10,6 +11,7 @@ export class InMemoryMemory implements IMemory {
10
11
  private agentMemory: InMemoryAgent;
11
12
  private intentMemory: InMemoryIntent;
12
13
  private threadMemory: InMemoryThread;
14
+ private workflowMemory: InMemoryWorkflow;
13
15
 
14
16
  constructor() {
15
17
  if (!InMemoryMemory.instance) {
@@ -19,6 +21,7 @@ export class InMemoryMemory implements IMemory {
19
21
  this.agentMemory = new InMemoryAgent();
20
22
  this.threadMemory = new InMemoryThread();
21
23
  this.intentMemory = new InMemoryIntent();
24
+ this.workflowMemory = new InMemoryWorkflow();
22
25
  }
23
26
 
24
27
  public async connect(): Promise<void> {
@@ -44,4 +47,8 @@ export class InMemoryMemory implements IMemory {
44
47
  public getIntentMemory(): IIntentMemory {
45
48
  return this.intentMemory;
46
49
  }
50
+
51
+ public getWorkflowMemory(): IWorkflowMemory {
52
+ return this.workflowMemory;
53
+ }
47
54
  }
@@ -14,8 +14,10 @@ export class InMemoryIntent implements IIntentMemory {
14
14
  }
15
15
 
16
16
  public async saveIntent(intent: Intent): Promise<void> {
17
- const newId = randomUUID();
18
- this.intents.set(newId, intent);
17
+ // Intent에 이미 id가 있으면 그것을 사용하고, 없으면 새로 생성
18
+ const intentId = intent.id || randomUUID();
19
+ const intentToSave = { ...intent, id: intentId };
20
+ this.intents.set(intentId, intentToSave);
19
21
  }
20
22
 
21
23
  public async updateIntent(intentId: string, intent: Intent): Promise<void> {
@@ -80,7 +80,17 @@ export class InMemoryThread implements IThreadMemory {
80
80
  public async deleteThread(userId: string, threadId: string): Promise<void> {
81
81
  const key = this.generateKey(userId, threadId);
82
82
  this.threads.delete(key);
83
- this.userThreadIndex.delete(threadId);
83
+
84
+ // userThreadIndex에서 해당 thread metadata 제거
85
+ const userThreads = this.userThreadIndex.get(userId);
86
+ if (userThreads) {
87
+ const metadataToDelete = Array.from(userThreads).find(
88
+ metadata => metadata.threadId === threadId
89
+ );
90
+ if (metadataToDelete) {
91
+ userThreads.delete(metadataToDelete);
92
+ }
93
+ }
84
94
  }
85
95
 
86
96
  public async listThreads(userId: string): Promise<ThreadMetadata[]> {
@@ -0,0 +1,80 @@
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
+ const existing = this.workflows.get(workflowId);
27
+ if (existing) {
28
+ const updated = { ...existing, ...updates, workflowId };
29
+
30
+ // userId가 변경된 경우 인덱스 업데이트
31
+ if (updates.userId !== undefined && existing.userId !== updates.userId) {
32
+ // 기존 userId 인덱스에서 제거
33
+ if (existing.userId) {
34
+ this.userWorkflowIndex.get(existing.userId)?.delete(workflowId);
35
+ }
36
+ // 새 userId 인덱스에 추가
37
+ if (updates.userId) {
38
+ if (!this.userWorkflowIndex.has(updates.userId)) {
39
+ this.userWorkflowIndex.set(updates.userId, new Set());
40
+ }
41
+ this.userWorkflowIndex.get(updates.userId)?.add(workflowId);
42
+ }
43
+ }
44
+
45
+ this.workflows.set(workflowId, updated);
46
+ }
47
+ }
48
+
49
+ public async deleteWorkflow(workflowId: string): Promise<void> {
50
+ const workflow = this.workflows.get(workflowId);
51
+ if (workflow) {
52
+ this.workflows.delete(workflowId);
53
+
54
+ // 인덱스에서도 제거
55
+ if (workflow.userId) {
56
+ this.userWorkflowIndex.get(workflow.userId)?.delete(workflowId);
57
+ }
58
+ }
59
+ }
60
+
61
+ public async listWorkflows(userId?: string): Promise<Workflow[]> {
62
+ if (userId) {
63
+ const workflowIds = this.userWorkflowIndex.get(userId);
64
+ if (!workflowIds) {
65
+ return [];
66
+ }
67
+
68
+ const workflows: Workflow[] = [];
69
+ for (const workflowId of workflowIds) {
70
+ const workflow = this.workflows.get(workflowId);
71
+ if (workflow) {
72
+ workflows.push(workflow);
73
+ }
74
+ }
75
+ return workflows;
76
+ }
77
+
78
+ return Array.from(this.workflows.values());
79
+ }
80
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ainetwork/adk-provider-memory-inmemory",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
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.3.2"
24
+ "@ainetwork/adk": "^0.3.4"
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": "4bfa5afae29304e6cb5f106c7327f5f2092f6601"
33
+ "gitHead": "a1e19f88b1255e8b5d3fd6f60edb82139b324123"
34
34
  }