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

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
@@ -150,48 +150,45 @@ var InMemoryWorkflow = class {
150
150
  return this.workflows.get(workflowId);
151
151
  }
152
152
  async updateWorkflow(workflowId, updates) {
153
+ if (!updates.userId) {
154
+ throw new Error("userId is required for updateWorkflow");
155
+ }
153
156
  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);
157
+ if (!existing) {
158
+ throw new Error(`Workflow not found: ${workflowId}`);
159
+ }
160
+ if (existing.userId !== updates.userId) {
161
+ throw new Error("Unauthorized: userId does not match workflow owner");
168
162
  }
163
+ const updated = { ...existing, ...updates, workflowId };
164
+ this.workflows.set(workflowId, updated);
169
165
  }
170
- async deleteWorkflow(workflowId) {
166
+ async deleteWorkflow(workflowId, userId) {
171
167
  const workflow = this.workflows.get(workflowId);
172
- if (workflow) {
168
+ if (workflow && workflow.userId === userId) {
173
169
  this.workflows.delete(workflowId);
174
- if (workflow.userId) {
175
- this.userWorkflowIndex.get(workflow.userId)?.delete(workflowId);
176
- }
170
+ this.userWorkflowIndex.get(userId)?.delete(workflowId);
177
171
  }
178
172
  }
179
173
  async listWorkflows(userId) {
180
- if (userId) {
181
- const workflowIds = this.userWorkflowIndex.get(userId);
182
- if (!workflowIds) {
183
- return [];
174
+ const workflows = [];
175
+ for (const workflow of this.workflows.values()) {
176
+ if (!workflow.userId) {
177
+ workflows.push(workflow);
184
178
  }
185
- const workflows = [];
186
- for (const workflowId of workflowIds) {
187
- const workflow = this.workflows.get(workflowId);
188
- if (workflow) {
189
- workflows.push(workflow);
179
+ }
180
+ if (userId) {
181
+ const userWorkflowIds = this.userWorkflowIndex.get(userId);
182
+ if (userWorkflowIds) {
183
+ for (const workflowId of userWorkflowIds) {
184
+ const workflow = this.workflows.get(workflowId);
185
+ if (workflow) {
186
+ workflows.push(workflow);
187
+ }
190
188
  }
191
189
  }
192
- return workflows;
193
190
  }
194
- return Array.from(this.workflows.values());
191
+ return workflows;
195
192
  }
196
193
  };
197
194
 
@@ -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 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,gBA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AO,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/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 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,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,EA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,OAAO,GAAG;AAC9C,UAAI,CAAC,SAAS,QAAQ;AACpB,kBAAU,KAAK,QAAQ;AAAA,MACzB;AAAA,IACF;AAGA,QAAI,QAAQ;AACV,YAAM,kBAAkB,KAAK,kBAAkB,IAAI,MAAM;AACzD,UAAI,iBAAiB;AACnB,mBAAW,cAAc,iBAAiB;AACxC,gBAAM,WAAW,KAAK,UAAU,IAAI,UAAU;AAC9C,cAAI,UAAU;AACZ,sBAAU,KAAK,QAAQ;AAAA,UACzB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;;;ACrEO,IAAM,iBAAN,MAAM,gBAAkC;AAAA,EAC7C,OAAe;AAAA,EACP,YAAqB;AAAA,EAErB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,cAAc;AACZ,QAAI,CAAC,gBAAe,UAAU;AAC5B,sBAAe,WAAW;AAAA,IAC5B;AAEA,SAAK,cAAc,IAAI,cAAc;AACrC,SAAK,eAAe,IAAI,eAAe;AACvC,SAAK,eAAe,IAAI,eAAe;AACvC,SAAK,iBAAiB,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,MAAa,UAAyB;AACpC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,MAAa,aAA4B;AACvC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEO,cAAuB;AAC5B,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,iBAA+B;AACpC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,kBAAiC;AACtC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,kBAAiC;AACtC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,oBAAqC;AAC1C,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
package/dist/index.js CHANGED
@@ -124,48 +124,45 @@ var InMemoryWorkflow = class {
124
124
  return this.workflows.get(workflowId);
125
125
  }
126
126
  async updateWorkflow(workflowId, updates) {
127
+ if (!updates.userId) {
128
+ throw new Error("userId is required for updateWorkflow");
129
+ }
127
130
  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);
131
+ if (!existing) {
132
+ throw new Error(`Workflow not found: ${workflowId}`);
133
+ }
134
+ if (existing.userId !== updates.userId) {
135
+ throw new Error("Unauthorized: userId does not match workflow owner");
142
136
  }
137
+ const updated = { ...existing, ...updates, workflowId };
138
+ this.workflows.set(workflowId, updated);
143
139
  }
144
- async deleteWorkflow(workflowId) {
140
+ async deleteWorkflow(workflowId, userId) {
145
141
  const workflow = this.workflows.get(workflowId);
146
- if (workflow) {
142
+ if (workflow && workflow.userId === userId) {
147
143
  this.workflows.delete(workflowId);
148
- if (workflow.userId) {
149
- this.userWorkflowIndex.get(workflow.userId)?.delete(workflowId);
150
- }
144
+ this.userWorkflowIndex.get(userId)?.delete(workflowId);
151
145
  }
152
146
  }
153
147
  async listWorkflows(userId) {
154
- if (userId) {
155
- const workflowIds = this.userWorkflowIndex.get(userId);
156
- if (!workflowIds) {
157
- return [];
148
+ const workflows = [];
149
+ for (const workflow of this.workflows.values()) {
150
+ if (!workflow.userId) {
151
+ workflows.push(workflow);
158
152
  }
159
- const workflows = [];
160
- for (const workflowId of workflowIds) {
161
- const workflow = this.workflows.get(workflowId);
162
- if (workflow) {
163
- workflows.push(workflow);
153
+ }
154
+ if (userId) {
155
+ const userWorkflowIds = this.userWorkflowIndex.get(userId);
156
+ if (userWorkflowIds) {
157
+ for (const workflowId of userWorkflowIds) {
158
+ const workflow = this.workflows.get(workflowId);
159
+ if (workflow) {
160
+ workflows.push(workflow);
161
+ }
164
162
  }
165
163
  }
166
- return workflows;
167
164
  }
168
- return Array.from(this.workflows.values());
165
+ return workflows;
169
166
  }
170
167
  };
171
168
 
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 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,Y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A,EACF;AAAA,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":[]}
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 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,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,IA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,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":[]}
@@ -23,58 +23,54 @@ export class InMemoryWorkflow implements IWorkflowMemory {
23
23
  }
24
24
 
25
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 };
26
+ if (!updates.userId) {
27
+ throw new Error("userId is required for updateWorkflow");
28
+ }
29
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
- }
30
+ const existing = this.workflows.get(workflowId);
31
+ if (!existing) {
32
+ throw new Error(`Workflow not found: ${workflowId}`);
33
+ }
44
34
 
45
- this.workflows.set(workflowId, updated);
35
+ if (existing.userId !== updates.userId) {
36
+ throw new Error("Unauthorized: userId does not match workflow owner");
46
37
  }
38
+
39
+ const updated = { ...existing, ...updates, workflowId };
40
+ this.workflows.set(workflowId, updated);
47
41
  }
48
42
 
49
- public async deleteWorkflow(workflowId: string): Promise<void> {
43
+ public async deleteWorkflow(workflowId: string, userId: string): Promise<void> {
50
44
  const workflow = this.workflows.get(workflowId);
51
- if (workflow) {
45
+ if (workflow && workflow.userId === userId) {
52
46
  this.workflows.delete(workflowId);
53
-
54
- // 인덱스에서도 제거
55
- if (workflow.userId) {
56
- this.userWorkflowIndex.get(workflow.userId)?.delete(workflowId);
57
- }
47
+ this.userWorkflowIndex.get(userId)?.delete(workflowId);
58
48
  }
59
49
  }
60
50
 
61
51
  public async listWorkflows(userId?: string): Promise<Workflow[]> {
62
- if (userId) {
63
- const workflowIds = this.userWorkflowIndex.get(userId);
64
- if (!workflowIds) {
65
- return [];
52
+ const workflows: Workflow[] = [];
53
+
54
+ // 템플릿 workflow (userId가 없는 것) 항상 포함
55
+ for (const workflow of this.workflows.values()) {
56
+ if (!workflow.userId) {
57
+ workflows.push(workflow);
66
58
  }
59
+ }
67
60
 
68
- const workflows: Workflow[] = [];
69
- for (const workflowId of workflowIds) {
70
- const workflow = this.workflows.get(workflowId);
71
- if (workflow) {
72
- workflows.push(workflow);
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
+ }
73
70
  }
74
71
  }
75
- return workflows;
76
72
  }
77
73
 
78
- return Array.from(this.workflows.values());
74
+ return workflows;
79
75
  }
80
76
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ainetwork/adk-provider-memory-inmemory",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
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.4"
24
+ "@ainetwork/adk": "^0.3.6"
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": "a1e19f88b1255e8b5d3fd6f60edb82139b324123"
33
+ "gitHead": "519c7ef43ddb78ec85255cfe45b62b40c7f3e37b"
34
34
  }