@ainetwork/adk-provider-memory-inmemory 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -105,6 +105,7 @@ var InMemoryThread = class {
105
105
  userId,
106
106
  type: res.type,
107
107
  title: res.title,
108
+ isPinned: res.isPinned,
108
109
  messages: res.messages
109
110
  };
110
111
  return threadObject;
@@ -118,12 +119,13 @@ var InMemoryThread = class {
118
119
  this.userThreadIndex.set(userId, /* @__PURE__ */ new Set());
119
120
  }
120
121
  if (!this.threads.has(key)) {
121
- this.threads.set(key, { type, title, messages: [] });
122
+ this.threads.set(key, { type, title, isPinned: false, messages: [] });
122
123
  const metadata = {
123
124
  type,
124
125
  userId,
125
126
  threadId,
126
127
  title,
128
+ isPinned: false,
127
129
  createdAt: now,
128
130
  updatedAt: now
129
131
  };
@@ -158,6 +160,22 @@ var InMemoryThread = class {
158
160
  }
159
161
  return [];
160
162
  }
163
+ async updateThreadPin(userId, threadId, isPinned) {
164
+ const key = this.generateKey(userId, threadId);
165
+ const thread = this.threads.get(key);
166
+ if (thread) {
167
+ thread.isPinned = isPinned;
168
+ }
169
+ const userThreads = this.userThreadIndex.get(userId);
170
+ if (userThreads) {
171
+ const metadata = Array.from(userThreads).find(
172
+ (m) => m.threadId === threadId
173
+ );
174
+ if (metadata) {
175
+ metadata.isPinned = isPinned;
176
+ }
177
+ }
178
+ }
161
179
  };
162
180
 
163
181
  // implements/workflow.memory.ts
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts","../implements/agent.memory.ts","../implements/intent.memory.ts","../implements/thread.memory.ts","../implements/workflow.memory.ts","../implements/base.memory.ts"],"sourcesContent":["export { InMemoryMemory } from \"./implements/base.memory\";","import { IAgentMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryAgent implements IAgentMemory {\n private agentPrompt: string = \"\";\n private aggregatePrompt: string = \"\";\n private generateTitlePrompt: string = \"\";\n private singleTriggerPrompt: string = \"\";\n private multiTriggerPrompt: string = \"\";\n private toolSelectPrompt: string = \"\";\n private piiDetectPrompt: string = \"\";\n private piiFilterPrompt: string = \"\";\n\n public async getAgentPrompt(): Promise<string> {\n return this.agentPrompt;\n }\n\n public async updateAgentPrompt(prompt: string): Promise<void> {\n this.agentPrompt = prompt;\n }\n\n public async getAggregatePrompt(): Promise<string> {\n return this.aggregatePrompt;\n }\n\n public async getGenerateTitlePrompt(): Promise<string> {\n return this.generateTitlePrompt;\n }\n\n public async getSingleTriggerPrompt(): Promise<string> {\n return this.singleTriggerPrompt;\n }\n\n public async getMultiTriggerPrompt(): Promise<string> {\n return this.multiTriggerPrompt;\n }\n\n public async getToolSelectPrompt(): Promise<string> {\n return this.toolSelectPrompt;\n }\n\n public async getPIIDetectPrompt(): Promise<string> {\n return this.piiDetectPrompt;\n }\n\n public async getPIIFilterPrompt(): Promise<string> {\n return this.piiFilterPrompt;\n }\n}\n","import { randomUUID } from \"node:crypto\";\nimport type { Intent } from \"@ainetwork/adk/types/memory\";\nimport { IIntentMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryIntent implements IIntentMemory {\n public intents: Map<string, Intent> = new Map();\n\n public async getIntent(intentId: string): Promise<Intent | undefined> {\n return this.intents.get(intentId);\n }\n\n public async getIntentByName(intentName: string): Promise<Intent | undefined> {\n return Array.from(this.intents.values()).find(intent => intent.name === intentName);\n }\n\n public async saveIntent(intent: Intent): Promise<void> {\n // Intent에 이미 id가 있으면 그것을 사용하고, 없으면 새로 생성\n const intentId = intent.id || randomUUID();\n const intentToSave = { ...intent, id: intentId };\n this.intents.set(intentId, intentToSave);\n }\n\n public async updateIntent(intentId: string, intent: Intent): Promise<void> {\n this.intents.set(intentId, intent);\n }\n\n public async deleteIntent(intentId: string): Promise<void> {\n this.intents.delete(intentId);\n }\n\n public async listIntents(): Promise<Intent[]> {\n return Array.from(this.intents.values());\n }\n}","import type { MessageObject, ThreadObject, ThreadMetadata, ThreadType } from \"@ainetwork/adk/types/memory\";\nimport { IThreadMemory } from \"@ainetwork/adk/modules\";\n\ntype InMemoryThreadObject = {\n type: ThreadType;\n title: string;\n messages: Array<MessageObject>;\n}\n\ntype InMemoryThreadMetadata = {\n type: ThreadType;\n userId: string;\n threadId: string;\n title: string;\n updatedAt: number;\n createdAt: number;\n}\n\nexport class InMemoryThread implements IThreadMemory {\n public threads: Map<string, InMemoryThreadObject> = new Map();\n public userThreadIndex: Map<string, Set<InMemoryThreadMetadata>> = new Map();\n\n private generateKey(userId: string, threadId: string) {\n return `${userId}:${threadId}`;\n }\n\n public async getThread(\n userId: string,\n threadId: string\n ): Promise<ThreadObject | undefined> {\n const key = this.generateKey(userId, threadId);\n const res = this.threads.get(key);\n if (res) {\n const threadObject: ThreadObject = {\n threadId,\n userId,\n type: res.type,\n title: res.title,\n messages: res.messages,\n };\n return threadObject;\n }\n return undefined;\n }\n\n public async createThread(\n type: ThreadType,\n userId: string,\n threadId: string,\n title: string\n ): Promise<ThreadObject> {\n const now = Date.now();\n const key = this.generateKey(userId, threadId);\n if (!this.userThreadIndex.has(userId)) {\n this.userThreadIndex.set(userId, new Set());\n }\n if (!this.threads.has(key)) {\n this.threads.set(key, { type, title, messages: [] });\n const metadata: InMemoryThreadMetadata = {\n type, userId, threadId, title, createdAt: now, updatedAt: now,\n }\n this.userThreadIndex.get(userId)?.add(metadata);\n }\n\n return { type, title, threadId, userId, messages: [] };\n }\n\n public async addMessagesToThread(\n userId: string,\n threadId: string,\n messages: MessageObject[]\n ): Promise<void> {\n const key = this.generateKey(userId, threadId);\n const thread = this.threads.get(key);\n for (const message of messages) {\n thread?.messages.push(message);\n }\n }\n\n public async deleteThread(userId: string, threadId: string): Promise<void> {\n const key = this.generateKey(userId, threadId);\n this.threads.delete(key);\n\n // userThreadIndex에서 해당 thread metadata 제거\n const userThreads = this.userThreadIndex.get(userId);\n if (userThreads) {\n const metadataToDelete = Array.from(userThreads).find(\n metadata => metadata.threadId === threadId\n );\n if (metadataToDelete) {\n userThreads.delete(metadataToDelete);\n }\n }\n }\n\n public async listThreads(userId: string): Promise<ThreadMetadata[]> {\n const threads = this.userThreadIndex.get(userId);\n if (threads) {\n return Array.from(threads);\n }\n return [];\n }\n}","import { IWorkflowMemory } from \"@ainetwork/adk/modules\";\nimport type { Workflow } from \"@ainetwork/adk/types/memory\";\n\nexport class InMemoryWorkflow implements IWorkflowMemory {\n private workflows: Map<string, Workflow> = new Map();\n private userWorkflowIndex: Map<string, Set<string>> = new Map();\n\n public async createWorkflow(workflow: Workflow): Promise<Workflow> {\n this.workflows.set(workflow.workflowId, workflow);\n\n if (workflow.userId) {\n if (!this.userWorkflowIndex.has(workflow.userId)) {\n this.userWorkflowIndex.set(workflow.userId, new Set());\n }\n this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);\n }\n\n return workflow;\n }\n\n public async getWorkflow(workflowId: string): Promise<Workflow | undefined> {\n return this.workflows.get(workflowId);\n }\n\n public async updateWorkflow(workflowId: string, updates: Partial<Workflow>): Promise<void> {\n if (!updates.userId) {\n throw new Error(\"userId is required for updateWorkflow\");\n }\n\n const existing = this.workflows.get(workflowId);\n if (!existing) {\n throw new Error(`Workflow not found: ${workflowId}`);\n }\n\n if (existing.userId !== updates.userId) {\n throw new Error(\"Unauthorized: userId does not match workflow owner\");\n }\n\n const updated = { ...existing, ...updates, workflowId };\n this.workflows.set(workflowId, updated);\n }\n\n public async deleteWorkflow(workflowId: string, userId: string): Promise<void> {\n const workflow = this.workflows.get(workflowId);\n if (workflow && workflow.userId === userId) {\n this.workflows.delete(workflowId);\n this.userWorkflowIndex.get(userId)?.delete(workflowId);\n }\n }\n\n public async listWorkflows(userId?: string): Promise<Workflow[]> {\n const workflows: Workflow[] = [];\n\n // 템플릿 workflow (userId가 없는 것)은 항상 포함\n for (const workflow of this.workflows.values()) {\n if (!workflow.userId) {\n workflows.push(workflow);\n }\n }\n\n // userId가 있으면 해당 유저 소유 workflow도 포함\n if (userId) {\n const userWorkflowIds = this.userWorkflowIndex.get(userId);\n if (userWorkflowIds) {\n for (const workflowId of userWorkflowIds) {\n const workflow = this.workflows.get(workflowId);\n if (workflow) {\n workflows.push(workflow);\n }\n }\n }\n }\n\n return workflows;\n }\n}\n","import { IAgentMemory, IIntentMemory, IMemory, IThreadMemory, IWorkflowMemory } from \"@ainetwork/adk/modules\";\nimport { InMemoryAgent } from \"./agent.memory\";\nimport { InMemoryIntent } from \"./intent.memory\";\nimport { InMemoryThread } from \"./thread.memory\";\nimport { InMemoryWorkflow } from \"./workflow.memory\";\n\nexport class InMemoryMemory implements IMemory {\n private static instance: InMemoryMemory;\n private connected: boolean = false;\n\n private agentMemory: InMemoryAgent;\n private intentMemory: InMemoryIntent;\n private threadMemory: InMemoryThread;\n private workflowMemory: InMemoryWorkflow;\n\n constructor() {\n if (!InMemoryMemory.instance) {\n InMemoryMemory.instance = this;\n }\n\n this.agentMemory = new InMemoryAgent();\n this.threadMemory = new InMemoryThread();\n this.intentMemory = new InMemoryIntent();\n this.workflowMemory = new InMemoryWorkflow();\n }\n\n public async connect(): Promise<void> {\n this.connected = true;\n }\n\n public async disconnect(): Promise<void> {\n this.connected = false;\n }\n\n public isConnected(): boolean {\n return this.connected;\n }\n\n public getAgentMemory(): IAgentMemory {\n return this.agentMemory;\n }\n\n public getThreadMemory(): IThreadMemory {\n return this.threadMemory;\n }\n\n public getIntentMemory(): IIntentMemory {\n return this.intentMemory;\n }\n\n public getWorkflowMemory(): IWorkflowMemory {\n return this.workflowMemory;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,gBAAN,MAA4C;AAAA,EACzC,cAAsB;AAAA,EACtB,kBAA0B;AAAA,EAC1B,sBAA8B;AAAA,EAC9B,sBAA8B;AAAA,EAC9B,qBAA6B;AAAA,EAC7B,mBAA2B;AAAA,EAC3B,kBAA0B;AAAA,EAC1B,kBAA0B;AAAA,EAElC,MAAa,iBAA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,eAAe;AACvC,SAAK,iBAAiB,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,MAAa,UAAyB;AACpC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,MAAa,aAA4B;AACvC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEO,cAAuB;AAC5B,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,iBAA+B;AACpC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,kBAAiC;AACtC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,kBAAiC;AACtC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,oBAAqC;AAC1C,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
1
+ {"version":3,"sources":["../index.ts","../implements/agent.memory.ts","../implements/intent.memory.ts","../implements/thread.memory.ts","../implements/workflow.memory.ts","../implements/base.memory.ts"],"sourcesContent":["export { InMemoryMemory } from \"./implements/base.memory\";","import { IAgentMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryAgent implements IAgentMemory {\n private agentPrompt: string = \"\";\n private aggregatePrompt: string = \"\";\n private generateTitlePrompt: string = \"\";\n private singleTriggerPrompt: string = \"\";\n private multiTriggerPrompt: string = \"\";\n private toolSelectPrompt: string = \"\";\n private piiDetectPrompt: string = \"\";\n private piiFilterPrompt: string = \"\";\n\n public async getAgentPrompt(): Promise<string> {\n return this.agentPrompt;\n }\n\n public async updateAgentPrompt(prompt: string): Promise<void> {\n this.agentPrompt = prompt;\n }\n\n public async getAggregatePrompt(): Promise<string> {\n return this.aggregatePrompt;\n }\n\n public async getGenerateTitlePrompt(): Promise<string> {\n return this.generateTitlePrompt;\n }\n\n public async getSingleTriggerPrompt(): Promise<string> {\n return this.singleTriggerPrompt;\n }\n\n public async getMultiTriggerPrompt(): Promise<string> {\n return this.multiTriggerPrompt;\n }\n\n public async getToolSelectPrompt(): Promise<string> {\n return this.toolSelectPrompt;\n }\n\n public async getPIIDetectPrompt(): Promise<string> {\n return this.piiDetectPrompt;\n }\n\n public async getPIIFilterPrompt(): Promise<string> {\n return this.piiFilterPrompt;\n }\n}\n","import { randomUUID } from \"node:crypto\";\nimport type { Intent } from \"@ainetwork/adk/types/memory\";\nimport { IIntentMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryIntent implements IIntentMemory {\n public intents: Map<string, Intent> = new Map();\n\n public async getIntent(intentId: string): Promise<Intent | undefined> {\n return this.intents.get(intentId);\n }\n\n public async getIntentByName(intentName: string): Promise<Intent | undefined> {\n return Array.from(this.intents.values()).find(intent => intent.name === intentName);\n }\n\n public async saveIntent(intent: Intent): Promise<void> {\n // Intent에 이미 id가 있으면 그것을 사용하고, 없으면 새로 생성\n const intentId = intent.id || randomUUID();\n const intentToSave = { ...intent, id: intentId };\n this.intents.set(intentId, intentToSave);\n }\n\n public async updateIntent(intentId: string, intent: Intent): Promise<void> {\n this.intents.set(intentId, intent);\n }\n\n public async deleteIntent(intentId: string): Promise<void> {\n this.intents.delete(intentId);\n }\n\n public async listIntents(): Promise<Intent[]> {\n return Array.from(this.intents.values());\n }\n}","import type { MessageObject, ThreadObject, ThreadMetadata, ThreadType } from \"@ainetwork/adk/types/memory\";\nimport { IThreadMemory } from \"@ainetwork/adk/modules\";\n\ntype InMemoryThreadObject = {\n type: ThreadType;\n title: string;\n isPinned: boolean;\n messages: Array<MessageObject>;\n}\n\ntype InMemoryThreadMetadata = {\n type: ThreadType;\n userId: string;\n threadId: string;\n title: string;\n isPinned: boolean;\n updatedAt: number;\n createdAt: number;\n}\n\nexport class InMemoryThread implements IThreadMemory {\n public threads: Map<string, InMemoryThreadObject> = new Map();\n public userThreadIndex: Map<string, Set<InMemoryThreadMetadata>> = new Map();\n\n private generateKey(userId: string, threadId: string) {\n return `${userId}:${threadId}`;\n }\n\n public async getThread(\n userId: string,\n threadId: string\n ): Promise<ThreadObject | undefined> {\n const key = this.generateKey(userId, threadId);\n const res = this.threads.get(key);\n if (res) {\n const threadObject: ThreadObject = {\n threadId,\n userId,\n type: res.type,\n title: res.title,\n isPinned: res.isPinned,\n messages: res.messages,\n };\n return threadObject;\n }\n return undefined;\n }\n\n public async createThread(\n type: ThreadType,\n userId: string,\n threadId: string,\n title: string\n ): Promise<ThreadObject> {\n const now = Date.now();\n const key = this.generateKey(userId, threadId);\n if (!this.userThreadIndex.has(userId)) {\n this.userThreadIndex.set(userId, new Set());\n }\n if (!this.threads.has(key)) {\n this.threads.set(key, { type, title, isPinned: false, messages: [] });\n const metadata: InMemoryThreadMetadata = {\n type, userId, threadId, title, isPinned: false, createdAt: now, updatedAt: now,\n }\n this.userThreadIndex.get(userId)?.add(metadata);\n }\n\n return { type, title, threadId, userId, messages: [] };\n }\n\n public async addMessagesToThread(\n userId: string,\n threadId: string,\n messages: MessageObject[]\n ): Promise<void> {\n const key = this.generateKey(userId, threadId);\n const thread = this.threads.get(key);\n for (const message of messages) {\n thread?.messages.push(message);\n }\n }\n\n public async deleteThread(userId: string, threadId: string): Promise<void> {\n const key = this.generateKey(userId, threadId);\n this.threads.delete(key);\n\n // userThreadIndex에서 해당 thread metadata 제거\n const userThreads = this.userThreadIndex.get(userId);\n if (userThreads) {\n const metadataToDelete = Array.from(userThreads).find(\n metadata => metadata.threadId === threadId\n );\n if (metadataToDelete) {\n userThreads.delete(metadataToDelete);\n }\n }\n }\n\n public async listThreads(userId: string): Promise<ThreadMetadata[]> {\n const threads = this.userThreadIndex.get(userId);\n if (threads) {\n return Array.from(threads);\n }\n return [];\n }\n\n public async updateThreadPin(\n userId: string,\n threadId: string,\n isPinned: boolean\n ): Promise<void> {\n const key = this.generateKey(userId, threadId);\n const thread = this.threads.get(key);\n if (thread) {\n thread.isPinned = isPinned;\n }\n\n const userThreads = this.userThreadIndex.get(userId);\n if (userThreads) {\n const metadata = Array.from(userThreads).find(\n m => m.threadId === threadId\n );\n if (metadata) {\n metadata.isPinned = isPinned;\n }\n }\n }\n}","import { IWorkflowMemory } from \"@ainetwork/adk/modules\";\nimport type { Workflow } from \"@ainetwork/adk/types/memory\";\n\nexport class InMemoryWorkflow implements IWorkflowMemory {\n private workflows: Map<string, Workflow> = new Map();\n private userWorkflowIndex: Map<string, Set<string>> = new Map();\n\n public async createWorkflow(workflow: Workflow): Promise<Workflow> {\n this.workflows.set(workflow.workflowId, workflow);\n\n if (workflow.userId) {\n if (!this.userWorkflowIndex.has(workflow.userId)) {\n this.userWorkflowIndex.set(workflow.userId, new Set());\n }\n this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);\n }\n\n return workflow;\n }\n\n public async getWorkflow(workflowId: string): Promise<Workflow | undefined> {\n return this.workflows.get(workflowId);\n }\n\n public async updateWorkflow(workflowId: string, updates: Partial<Workflow>): Promise<void> {\n if (!updates.userId) {\n throw new Error(\"userId is required for updateWorkflow\");\n }\n\n const existing = this.workflows.get(workflowId);\n if (!existing) {\n throw new Error(`Workflow not found: ${workflowId}`);\n }\n\n if (existing.userId !== updates.userId) {\n throw new Error(\"Unauthorized: userId does not match workflow owner\");\n }\n\n const updated = { ...existing, ...updates, workflowId };\n this.workflows.set(workflowId, updated);\n }\n\n public async deleteWorkflow(workflowId: string, userId: string): Promise<void> {\n const workflow = this.workflows.get(workflowId);\n if (workflow && workflow.userId === userId) {\n this.workflows.delete(workflowId);\n this.userWorkflowIndex.get(userId)?.delete(workflowId);\n }\n }\n\n public async listWorkflows(userId?: string): Promise<Workflow[]> {\n const workflows: Workflow[] = [];\n\n // 템플릿 workflow (userId가 없는 것)은 항상 포함\n for (const workflow of this.workflows.values()) {\n if (!workflow.userId) {\n workflows.push(workflow);\n }\n }\n\n // userId가 있으면 해당 유저 소유 workflow도 포함\n if (userId) {\n const userWorkflowIds = this.userWorkflowIndex.get(userId);\n if (userWorkflowIds) {\n for (const workflowId of userWorkflowIds) {\n const workflow = this.workflows.get(workflowId);\n if (workflow) {\n workflows.push(workflow);\n }\n }\n }\n }\n\n return workflows;\n }\n}\n","import { IAgentMemory, IIntentMemory, IMemory, IThreadMemory, IWorkflowMemory } from \"@ainetwork/adk/modules\";\nimport { InMemoryAgent } from \"./agent.memory\";\nimport { InMemoryIntent } from \"./intent.memory\";\nimport { InMemoryThread } from \"./thread.memory\";\nimport { InMemoryWorkflow } from \"./workflow.memory\";\n\nexport class InMemoryMemory implements IMemory {\n private static instance: InMemoryMemory;\n private connected: boolean = false;\n\n private agentMemory: InMemoryAgent;\n private intentMemory: InMemoryIntent;\n private threadMemory: InMemoryThread;\n private workflowMemory: InMemoryWorkflow;\n\n constructor() {\n if (!InMemoryMemory.instance) {\n InMemoryMemory.instance = this;\n }\n\n this.agentMemory = new InMemoryAgent();\n this.threadMemory = new InMemoryThread();\n this.intentMemory = new InMemoryIntent();\n this.workflowMemory = new InMemoryWorkflow();\n }\n\n public async connect(): Promise<void> {\n this.connected = true;\n }\n\n public async disconnect(): Promise<void> {\n this.connected = false;\n }\n\n public isConnected(): boolean {\n return this.connected;\n }\n\n public getAgentMemory(): IAgentMemory {\n return this.agentMemory;\n }\n\n public getThreadMemory(): IThreadMemory {\n return this.threadMemory;\n }\n\n public getIntentMemory(): IIntentMemory {\n return this.intentMemory;\n }\n\n public getWorkflowMemory(): IWorkflowMemory {\n return this.workflowMemory;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,gBAAN,MAA4C;AAAA,EACzC,cAAsB;AAAA,EACtB,kBAA0B;AAAA,EAC1B,sBAA8B;AAAA,EAC9B,sBAA8B;AAAA,EAC9B,qBAA6B;AAAA,EAC7B,mBAA2B;AAAA,EAC3B,kBAA0B;AAAA,EAC1B,kBAA0B;AAAA,EAElC,MAAa,iBAAkC;AAC7C,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,kBAAkB,QAA+B;AAC5D,SAAK,cAAc;AAAA,EACrB;AAAA,EAEA,MAAa,qBAAsC;AACjD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,yBAA0C;AACrD,WAAO,KAAK;AAAA,EACd;AAAA,E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AAA,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
@@ -79,6 +79,7 @@ var InMemoryThread = class {
79
79
  userId,
80
80
  type: res.type,
81
81
  title: res.title,
82
+ isPinned: res.isPinned,
82
83
  messages: res.messages
83
84
  };
84
85
  return threadObject;
@@ -92,12 +93,13 @@ var InMemoryThread = class {
92
93
  this.userThreadIndex.set(userId, /* @__PURE__ */ new Set());
93
94
  }
94
95
  if (!this.threads.has(key)) {
95
- this.threads.set(key, { type, title, messages: [] });
96
+ this.threads.set(key, { type, title, isPinned: false, messages: [] });
96
97
  const metadata = {
97
98
  type,
98
99
  userId,
99
100
  threadId,
100
101
  title,
102
+ isPinned: false,
101
103
  createdAt: now,
102
104
  updatedAt: now
103
105
  };
@@ -132,6 +134,22 @@ var InMemoryThread = class {
132
134
  }
133
135
  return [];
134
136
  }
137
+ async updateThreadPin(userId, threadId, isPinned) {
138
+ const key = this.generateKey(userId, threadId);
139
+ const thread = this.threads.get(key);
140
+ if (thread) {
141
+ thread.isPinned = isPinned;
142
+ }
143
+ const userThreads = this.userThreadIndex.get(userId);
144
+ if (userThreads) {
145
+ const metadata = Array.from(userThreads).find(
146
+ (m) => m.threadId === threadId
147
+ );
148
+ if (metadata) {
149
+ metadata.isPinned = isPinned;
150
+ }
151
+ }
152
+ }
135
153
  };
136
154
 
137
155
  // implements/workflow.memory.ts
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../implements/agent.memory.ts","../implements/intent.memory.ts","../implements/thread.memory.ts","../implements/workflow.memory.ts","../implements/base.memory.ts"],"sourcesContent":["import { IAgentMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryAgent implements IAgentMemory {\n private agentPrompt: string = \"\";\n private aggregatePrompt: string = \"\";\n private generateTitlePrompt: string = \"\";\n private singleTriggerPrompt: string = \"\";\n private multiTriggerPrompt: string = \"\";\n private toolSelectPrompt: string = \"\";\n private piiDetectPrompt: string = \"\";\n private piiFilterPrompt: string = \"\";\n\n public async getAgentPrompt(): Promise<string> {\n return this.agentPrompt;\n }\n\n public async updateAgentPrompt(prompt: string): Promise<void> {\n this.agentPrompt = prompt;\n }\n\n public async getAggregatePrompt(): Promise<string> {\n return this.aggregatePrompt;\n }\n\n public async getGenerateTitlePrompt(): Promise<string> {\n return this.generateTitlePrompt;\n }\n\n public async getSingleTriggerPrompt(): Promise<string> {\n return this.singleTriggerPrompt;\n }\n\n public async getMultiTriggerPrompt(): Promise<string> {\n return this.multiTriggerPrompt;\n }\n\n public async getToolSelectPrompt(): Promise<string> {\n return this.toolSelectPrompt;\n }\n\n public async getPIIDetectPrompt(): Promise<string> {\n return this.piiDetectPrompt;\n }\n\n public async getPIIFilterPrompt(): Promise<string> {\n return this.piiFilterPrompt;\n }\n}\n","import { randomUUID } from \"node:crypto\";\nimport type { Intent } from \"@ainetwork/adk/types/memory\";\nimport { IIntentMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryIntent implements IIntentMemory {\n public intents: Map<string, Intent> = new Map();\n\n public async getIntent(intentId: string): Promise<Intent | undefined> {\n return this.intents.get(intentId);\n }\n\n public async getIntentByName(intentName: string): Promise<Intent | undefined> {\n return Array.from(this.intents.values()).find(intent => intent.name === intentName);\n }\n\n public async saveIntent(intent: Intent): Promise<void> {\n // Intent에 이미 id가 있으면 그것을 사용하고, 없으면 새로 생성\n const intentId = intent.id || randomUUID();\n const intentToSave = { ...intent, id: intentId };\n this.intents.set(intentId, intentToSave);\n }\n\n public async updateIntent(intentId: string, intent: Intent): Promise<void> {\n this.intents.set(intentId, intent);\n }\n\n public async deleteIntent(intentId: string): Promise<void> {\n this.intents.delete(intentId);\n }\n\n public async listIntents(): Promise<Intent[]> {\n return Array.from(this.intents.values());\n }\n}","import type { MessageObject, ThreadObject, ThreadMetadata, ThreadType } from \"@ainetwork/adk/types/memory\";\nimport { IThreadMemory } from \"@ainetwork/adk/modules\";\n\ntype InMemoryThreadObject = {\n type: ThreadType;\n title: string;\n messages: Array<MessageObject>;\n}\n\ntype InMemoryThreadMetadata = {\n type: ThreadType;\n userId: string;\n threadId: string;\n title: string;\n updatedAt: number;\n createdAt: number;\n}\n\nexport class InMemoryThread implements IThreadMemory {\n public threads: Map<string, InMemoryThreadObject> = new Map();\n public userThreadIndex: Map<string, Set<InMemoryThreadMetadata>> = new Map();\n\n private generateKey(userId: string, threadId: string) {\n return `${userId}:${threadId}`;\n }\n\n public async getThread(\n userId: string,\n threadId: string\n ): Promise<ThreadObject | undefined> {\n const key = this.generateKey(userId, threadId);\n const res = this.threads.get(key);\n if (res) {\n const threadObject: ThreadObject = {\n threadId,\n userId,\n type: res.type,\n title: res.title,\n messages: res.messages,\n };\n return threadObject;\n }\n return undefined;\n }\n\n public async createThread(\n type: ThreadType,\n userId: string,\n threadId: string,\n title: string\n ): Promise<ThreadObject> {\n const now = Date.now();\n const key = this.generateKey(userId, threadId);\n if (!this.userThreadIndex.has(userId)) {\n this.userThreadIndex.set(userId, new Set());\n }\n if (!this.threads.has(key)) {\n this.threads.set(key, { type, title, messages: [] });\n const metadata: InMemoryThreadMetadata = {\n type, userId, threadId, title, createdAt: now, updatedAt: now,\n }\n this.userThreadIndex.get(userId)?.add(metadata);\n }\n\n return { type, title, threadId, userId, messages: [] };\n }\n\n public async addMessagesToThread(\n userId: string,\n threadId: string,\n messages: MessageObject[]\n ): Promise<void> {\n const key = this.generateKey(userId, threadId);\n const thread = this.threads.get(key);\n for (const message of messages) {\n thread?.messages.push(message);\n }\n }\n\n public async deleteThread(userId: string, threadId: string): Promise<void> {\n const key = this.generateKey(userId, threadId);\n this.threads.delete(key);\n\n // userThreadIndex에서 해당 thread metadata 제거\n const userThreads = this.userThreadIndex.get(userId);\n if (userThreads) {\n const metadataToDelete = Array.from(userThreads).find(\n metadata => metadata.threadId === threadId\n );\n if (metadataToDelete) {\n userThreads.delete(metadataToDelete);\n }\n }\n }\n\n public async listThreads(userId: string): Promise<ThreadMetadata[]> {\n const threads = this.userThreadIndex.get(userId);\n if (threads) {\n return Array.from(threads);\n }\n return [];\n }\n}","import { IWorkflowMemory } from \"@ainetwork/adk/modules\";\nimport type { Workflow } from \"@ainetwork/adk/types/memory\";\n\nexport class InMemoryWorkflow implements IWorkflowMemory {\n private workflows: Map<string, Workflow> = new Map();\n private userWorkflowIndex: Map<string, Set<string>> = new Map();\n\n public async createWorkflow(workflow: Workflow): Promise<Workflow> {\n this.workflows.set(workflow.workflowId, workflow);\n\n if (workflow.userId) {\n if (!this.userWorkflowIndex.has(workflow.userId)) {\n this.userWorkflowIndex.set(workflow.userId, new Set());\n }\n this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);\n }\n\n return workflow;\n }\n\n public async getWorkflow(workflowId: string): Promise<Workflow | undefined> {\n return this.workflows.get(workflowId);\n }\n\n public async updateWorkflow(workflowId: string, updates: Partial<Workflow>): Promise<void> {\n if (!updates.userId) {\n throw new Error(\"userId is required for updateWorkflow\");\n }\n\n const existing = this.workflows.get(workflowId);\n if (!existing) {\n throw new Error(`Workflow not found: ${workflowId}`);\n }\n\n if (existing.userId !== updates.userId) {\n throw new Error(\"Unauthorized: userId does not match workflow owner\");\n }\n\n const updated = { ...existing, ...updates, workflowId };\n this.workflows.set(workflowId, updated);\n }\n\n public async deleteWorkflow(workflowId: string, userId: string): Promise<void> {\n const workflow = this.workflows.get(workflowId);\n if (workflow && workflow.userId === userId) {\n this.workflows.delete(workflowId);\n this.userWorkflowIndex.get(userId)?.delete(workflowId);\n }\n }\n\n public async listWorkflows(userId?: string): Promise<Workflow[]> {\n const workflows: Workflow[] = [];\n\n // 템플릿 workflow (userId가 없는 것)은 항상 포함\n for (const workflow of this.workflows.values()) {\n if (!workflow.userId) {\n workflows.push(workflow);\n }\n }\n\n // userId가 있으면 해당 유저 소유 workflow도 포함\n if (userId) {\n const userWorkflowIds = this.userWorkflowIndex.get(userId);\n if (userWorkflowIds) {\n for (const workflowId of userWorkflowIds) {\n const workflow = this.workflows.get(workflowId);\n if (workflow) {\n workflows.push(workflow);\n }\n }\n }\n }\n\n return workflows;\n }\n}\n","import { IAgentMemory, IIntentMemory, IMemory, IThreadMemory, IWorkflowMemory } from \"@ainetwork/adk/modules\";\nimport { InMemoryAgent } from \"./agent.memory\";\nimport { InMemoryIntent } from \"./intent.memory\";\nimport { InMemoryThread } from \"./thread.memory\";\nimport { InMemoryWorkflow } from \"./workflow.memory\";\n\nexport class InMemoryMemory implements IMemory {\n private static instance: InMemoryMemory;\n private connected: boolean = false;\n\n private agentMemory: InMemoryAgent;\n private intentMemory: InMemoryIntent;\n private threadMemory: InMemoryThread;\n private workflowMemory: InMemoryWorkflow;\n\n constructor() {\n if (!InMemoryMemory.instance) {\n InMemoryMemory.instance = this;\n }\n\n this.agentMemory = new InMemoryAgent();\n this.threadMemory = new InMemoryThread();\n this.intentMemory = new InMemoryIntent();\n this.workflowMemory = new InMemoryWorkflow();\n }\n\n public async connect(): Promise<void> {\n this.connected = true;\n }\n\n public async disconnect(): Promise<void> {\n this.connected = false;\n }\n\n public isConnected(): boolean {\n return this.connected;\n }\n\n public getAgentMemory(): IAgentMemory {\n return this.agentMemory;\n }\n\n public getThreadMemory(): IThreadMemory {\n return this.threadMemory;\n }\n\n public getIntentMemory(): IIntentMemory {\n return this.intentMemory;\n }\n\n public getWorkflowMemory(): IWorkflowMemory {\n return this.workflowMemory;\n }\n}\n"],"mappings":";AAEO,IAAM,gBAAN,MAA4C;AAAA,EACzC,cAAsB;AAAA,EACtB,kBAA0B;AAAA,EAC1B,sBAA8B;AAAA,EAC9B,sBAA8B;AAAA,EAC9B,qBAA6B;AAAA,EAC7B,mBAA2B;AAAA,EAC3B,kBAA0B;AAAA,EAC1B,kBAA0B;AAAA,EAElC,MAAa,iBAAkC;AAC7C,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,kBAAkB,QAA+B;AAC5D,SAAK,cAAc;AAAA,EACrB;AAAA,EAEA,MAAa,qBAAsC;AACjD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,yBAA0C;AACrD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,yBAA0C;AACrD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,wBAAyC;AACpD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,sBAAuC;AAClD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,qBAAsC;AACjD,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,qBAAsC;AACjD,WAAO,KAAK;AAAA,EACd;AACF;;;AC/CA,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;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Ac,iBAAiB;AACxC,gBAAM,WAAW,KAAK,UAAU,IAAI,UAAU;AAC9C,cAAI,UAAU;AACZ,sBAAU,KAAK,QAAQ;AAAA,UACzB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;;;ACrEO,IAAM,iBAAN,MAAM,gBAAkC;AAAA,EAC7C,OAAe;AAAA,EACP,YAAqB;AAAA,EAErB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,cAAc;AACZ,QAAI,CAAC,gBAAe,UAAU;AAC5B,sBAAe,WAAW;AAAA,IAC5B;AAEA,SAAK,cAAc,IAAI,cAAc;AACrC,SAAK,eAAe,IAAI,eAAe;AACvC,SAAK,eAAe,IAAI,eAAe;AACvC,SAAK,iBAAiB,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,MAAa,UAAyB;AACpC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,MAAa,aAA4B;AACvC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEO,cAAuB;AAC5B,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,iBAA+B;AACpC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,kBAAiC;AACtC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,kBAAiC;AACtC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,oBAAqC;AAC1C,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
1
+ {"version":3,"sources":["../implements/agent.memory.ts","../implements/intent.memory.ts","../implements/thread.memory.ts","../implements/workflow.memory.ts","../implements/base.memory.ts"],"sourcesContent":["import { IAgentMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryAgent implements IAgentMemory {\n private agentPrompt: string = \"\";\n private aggregatePrompt: string = \"\";\n private generateTitlePrompt: string = \"\";\n private singleTriggerPrompt: string = \"\";\n private multiTriggerPrompt: string = \"\";\n private toolSelectPrompt: string = \"\";\n private piiDetectPrompt: string = \"\";\n private piiFilterPrompt: string = \"\";\n\n public async getAgentPrompt(): Promise<string> {\n return this.agentPrompt;\n }\n\n public async updateAgentPrompt(prompt: string): Promise<void> {\n this.agentPrompt = prompt;\n }\n\n public async getAggregatePrompt(): Promise<string> {\n return this.aggregatePrompt;\n }\n\n public async getGenerateTitlePrompt(): Promise<string> {\n return this.generateTitlePrompt;\n }\n\n public async getSingleTriggerPrompt(): Promise<string> {\n return this.singleTriggerPrompt;\n }\n\n public async getMultiTriggerPrompt(): Promise<string> {\n return this.multiTriggerPrompt;\n }\n\n public async getToolSelectPrompt(): Promise<string> {\n return this.toolSelectPrompt;\n }\n\n public async getPIIDetectPrompt(): Promise<string> {\n return this.piiDetectPrompt;\n }\n\n public async getPIIFilterPrompt(): Promise<string> {\n return this.piiFilterPrompt;\n }\n}\n","import { randomUUID } from \"node:crypto\";\nimport type { Intent } from \"@ainetwork/adk/types/memory\";\nimport { IIntentMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryIntent implements IIntentMemory {\n public intents: Map<string, Intent> = new Map();\n\n public async getIntent(intentId: string): Promise<Intent | undefined> {\n return this.intents.get(intentId);\n }\n\n public async getIntentByName(intentName: string): Promise<Intent | undefined> {\n return Array.from(this.intents.values()).find(intent => intent.name === intentName);\n }\n\n public async saveIntent(intent: Intent): Promise<void> {\n // Intent에 이미 id가 있으면 그것을 사용하고, 없으면 새로 생성\n const intentId = intent.id || randomUUID();\n const intentToSave = { ...intent, id: intentId };\n this.intents.set(intentId, intentToSave);\n }\n\n public async updateIntent(intentId: string, intent: Intent): Promise<void> {\n this.intents.set(intentId, intent);\n }\n\n public async deleteIntent(intentId: string): Promise<void> {\n this.intents.delete(intentId);\n }\n\n public async listIntents(): Promise<Intent[]> {\n return Array.from(this.intents.values());\n }\n}","import type { MessageObject, ThreadObject, ThreadMetadata, ThreadType } from \"@ainetwork/adk/types/memory\";\nimport { IThreadMemory } from \"@ainetwork/adk/modules\";\n\ntype InMemoryThreadObject = {\n type: ThreadType;\n title: string;\n isPinned: boolean;\n messages: Array<MessageObject>;\n}\n\ntype InMemoryThreadMetadata = {\n type: ThreadType;\n userId: string;\n threadId: string;\n title: string;\n isPinned: boolean;\n updatedAt: number;\n createdAt: number;\n}\n\nexport class InMemoryThread implements IThreadMemory {\n public threads: Map<string, InMemoryThreadObject> = new Map();\n public userThreadIndex: Map<string, Set<InMemoryThreadMetadata>> = new Map();\n\n private generateKey(userId: string, threadId: string) {\n return `${userId}:${threadId}`;\n }\n\n public async getThread(\n userId: string,\n threadId: string\n ): Promise<ThreadObject | undefined> {\n const key = this.generateKey(userId, threadId);\n const res = this.threads.get(key);\n if (res) {\n const threadObject: ThreadObject = {\n threadId,\n userId,\n type: res.type,\n title: res.title,\n isPinned: res.isPinned,\n messages: res.messages,\n };\n return threadObject;\n }\n return undefined;\n }\n\n public async createThread(\n type: ThreadType,\n userId: string,\n threadId: string,\n title: string\n ): Promise<ThreadObject> {\n const now = Date.now();\n const key = this.generateKey(userId, threadId);\n if (!this.userThreadIndex.has(userId)) {\n this.userThreadIndex.set(userId, new Set());\n }\n if (!this.threads.has(key)) {\n this.threads.set(key, { type, title, isPinned: false, messages: [] });\n const metadata: InMemoryThreadMetadata = {\n type, userId, threadId, title, isPinned: false, createdAt: now, updatedAt: now,\n }\n this.userThreadIndex.get(userId)?.add(metadata);\n }\n\n return { type, title, threadId, userId, messages: [] };\n }\n\n public async addMessagesToThread(\n userId: string,\n threadId: string,\n messages: MessageObject[]\n ): Promise<void> {\n const key = this.generateKey(userId, threadId);\n const thread = this.threads.get(key);\n for (const message of messages) {\n thread?.messages.push(message);\n }\n }\n\n public async deleteThread(userId: string, threadId: string): Promise<void> {\n const key = this.generateKey(userId, threadId);\n this.threads.delete(key);\n\n // userThreadIndex에서 해당 thread metadata 제거\n const userThreads = this.userThreadIndex.get(userId);\n if (userThreads) {\n const metadataToDelete = Array.from(userThreads).find(\n metadata => metadata.threadId === threadId\n );\n if (metadataToDelete) {\n userThreads.delete(metadataToDelete);\n }\n }\n }\n\n public async listThreads(userId: string): Promise<ThreadMetadata[]> {\n const threads = this.userThreadIndex.get(userId);\n if (threads) {\n return Array.from(threads);\n }\n return [];\n }\n\n public async updateThreadPin(\n userId: string,\n threadId: string,\n isPinned: boolean\n ): Promise<void> {\n const key = this.generateKey(userId, threadId);\n const thread = this.threads.get(key);\n if (thread) {\n thread.isPinned = isPinned;\n }\n\n const userThreads = this.userThreadIndex.get(userId);\n if (userThreads) {\n const metadata = Array.from(userThreads).find(\n m => m.threadId === threadId\n );\n if (metadata) {\n metadata.isPinned = isPinned;\n }\n }\n }\n}","import { IWorkflowMemory } from \"@ainetwork/adk/modules\";\nimport type { Workflow } from \"@ainetwork/adk/types/memory\";\n\nexport class InMemoryWorkflow implements IWorkflowMemory {\n private workflows: Map<string, Workflow> = new Map();\n private userWorkflowIndex: Map<string, Set<string>> = new Map();\n\n public async createWorkflow(workflow: Workflow): Promise<Workflow> {\n this.workflows.set(workflow.workflowId, workflow);\n\n if (workflow.userId) {\n if (!this.userWorkflowIndex.has(workflow.userId)) {\n this.userWorkflowIndex.set(workflow.userId, new Set());\n }\n this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);\n }\n\n return workflow;\n }\n\n public async getWorkflow(workflowId: string): Promise<Workflow | undefined> {\n return this.workflows.get(workflowId);\n }\n\n public async updateWorkflow(workflowId: string, updates: Partial<Workflow>): Promise<void> {\n if (!updates.userId) {\n throw new Error(\"userId is required for updateWorkflow\");\n }\n\n const existing = this.workflows.get(workflowId);\n if (!existing) {\n throw new Error(`Workflow not found: ${workflowId}`);\n }\n\n if (existing.userId !== updates.userId) {\n throw new Error(\"Unauthorized: userId does not match workflow owner\");\n }\n\n const updated = { ...existing, ...updates, workflowId };\n this.workflows.set(workflowId, updated);\n }\n\n public async deleteWorkflow(workflowId: string, userId: string): Promise<void> {\n const workflow = this.workflows.get(workflowId);\n if (workflow && workflow.userId === userId) {\n this.workflows.delete(workflowId);\n this.userWorkflowIndex.get(userId)?.delete(workflowId);\n }\n }\n\n public async listWorkflows(userId?: string): Promise<Workflow[]> {\n const workflows: Workflow[] = [];\n\n // 템플릿 workflow (userId가 없는 것)은 항상 포함\n for (const workflow of this.workflows.values()) {\n if (!workflow.userId) {\n workflows.push(workflow);\n }\n }\n\n // userId가 있으면 해당 유저 소유 workflow도 포함\n if (userId) {\n const userWorkflowIds = this.userWorkflowIndex.get(userId);\n if (userWorkflowIds) {\n for (const workflowId of userWorkflowIds) {\n const workflow = this.workflows.get(workflowId);\n if (workflow) {\n workflows.push(workflow);\n }\n }\n }\n }\n\n return workflows;\n }\n}\n","import { IAgentMemory, IIntentMemory, IMemory, IThreadMemory, IWorkflowMemory } from \"@ainetwork/adk/modules\";\nimport { InMemoryAgent } from \"./agent.memory\";\nimport { InMemoryIntent } from \"./intent.memory\";\nimport { InMemoryThread } from \"./thread.memory\";\nimport { InMemoryWorkflow } from \"./workflow.memory\";\n\nexport class InMemoryMemory implements IMemory {\n private static instance: InMemoryMemory;\n private connected: boolean = false;\n\n private agentMemory: InMemoryAgent;\n private intentMemory: InMemoryIntent;\n private threadMemory: InMemoryThread;\n private workflowMemory: InMemoryWorkflow;\n\n constructor() {\n if (!InMemoryMemory.instance) {\n InMemoryMemory.instance = this;\n }\n\n this.agentMemory = new InMemoryAgent();\n this.threadMemory = new InMemoryThread();\n this.intentMemory = new InMemoryIntent();\n this.workflowMemory = new InMemoryWorkflow();\n }\n\n public async connect(): Promise<void> {\n this.connected = true;\n }\n\n public async disconnect(): Promise<void> {\n this.connected = false;\n }\n\n public isConnected(): boolean {\n return this.connected;\n }\n\n public getAgentMemory(): IAgentMemory {\n return this.agentMemory;\n }\n\n public getThreadMemory(): IThreadMemory {\n return this.threadMemory;\n }\n\n public getIntentMemory(): IIntentMemory {\n return this.intentMemory;\n }\n\n public getWorkflowMemory(): IWorkflowMemory {\n return this.workflowMemory;\n }\n}\n"],"mappings":";AAEO,IAAM,gBAAN,MAA4C;AAAA,EACzC,cAAsB;AAAA,EACtB,kBAA0B;AAAA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,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":[]}
@@ -4,6 +4,7 @@ import { IThreadMemory } from "@ainetwork/adk/modules";
4
4
  type InMemoryThreadObject = {
5
5
  type: ThreadType;
6
6
  title: string;
7
+ isPinned: boolean;
7
8
  messages: Array<MessageObject>;
8
9
  }
9
10
 
@@ -12,6 +13,7 @@ type InMemoryThreadMetadata = {
12
13
  userId: string;
13
14
  threadId: string;
14
15
  title: string;
16
+ isPinned: boolean;
15
17
  updatedAt: number;
16
18
  createdAt: number;
17
19
  }
@@ -36,6 +38,7 @@ export class InMemoryThread implements IThreadMemory {
36
38
  userId,
37
39
  type: res.type,
38
40
  title: res.title,
41
+ isPinned: res.isPinned,
39
42
  messages: res.messages,
40
43
  };
41
44
  return threadObject;
@@ -55,9 +58,9 @@ export class InMemoryThread implements IThreadMemory {
55
58
  this.userThreadIndex.set(userId, new Set());
56
59
  }
57
60
  if (!this.threads.has(key)) {
58
- this.threads.set(key, { type, title, messages: [] });
61
+ this.threads.set(key, { type, title, isPinned: false, messages: [] });
59
62
  const metadata: InMemoryThreadMetadata = {
60
- type, userId, threadId, title, createdAt: now, updatedAt: now,
63
+ type, userId, threadId, title, isPinned: false, createdAt: now, updatedAt: now,
61
64
  }
62
65
  this.userThreadIndex.get(userId)?.add(metadata);
63
66
  }
@@ -100,4 +103,26 @@ export class InMemoryThread implements IThreadMemory {
100
103
  }
101
104
  return [];
102
105
  }
106
+
107
+ public async updateThreadPin(
108
+ userId: string,
109
+ threadId: string,
110
+ isPinned: boolean
111
+ ): Promise<void> {
112
+ const key = this.generateKey(userId, threadId);
113
+ const thread = this.threads.get(key);
114
+ if (thread) {
115
+ thread.isPinned = isPinned;
116
+ }
117
+
118
+ const userThreads = this.userThreadIndex.get(userId);
119
+ if (userThreads) {
120
+ const metadata = Array.from(userThreads).find(
121
+ m => m.threadId === threadId
122
+ );
123
+ if (metadata) {
124
+ metadata.isPinned = isPinned;
125
+ }
126
+ }
127
+ }
103
128
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ainetwork/adk-provider-memory-inmemory",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
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.4.0"
24
+ "@ainetwork/adk": "^0.4.1"
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": "36d311adf911c3539166e08bc2e6b7e240e8615c"
33
+ "gitHead": "49996589506616fbfe330a0ad992301b06d55066"
34
34
  }