@ainetwork/adk-provider-memory-inmemory 0.3.3 → 0.3.5
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 +77 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +77 -3
- package/dist/index.js.map +1 -1
- package/implements/base.memory.ts +8 -1
- package/implements/intent.memory.ts +4 -2
- package/implements/thread.memory.ts +11 -1
- package/implements/workflow.memory.ts +76 -0
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -46,8 +46,9 @@ var InMemoryIntent = class {
|
|
|
46
46
|
return Array.from(this.intents.values()).find((intent) => intent.name === intentName);
|
|
47
47
|
}
|
|
48
48
|
async saveIntent(intent) {
|
|
49
|
-
const
|
|
50
|
-
|
|
49
|
+
const intentId = intent.id || (0, import_node_crypto.randomUUID)();
|
|
50
|
+
const intentToSave = { ...intent, id: intentId };
|
|
51
|
+
this.intents.set(intentId, intentToSave);
|
|
51
52
|
}
|
|
52
53
|
async updateIntent(intentId, intent) {
|
|
53
54
|
this.intents.set(intentId, intent);
|
|
@@ -112,7 +113,15 @@ var InMemoryThread = class {
|
|
|
112
113
|
async deleteThread(userId, threadId) {
|
|
113
114
|
const key = this.generateKey(userId, threadId);
|
|
114
115
|
this.threads.delete(key);
|
|
115
|
-
this.userThreadIndex.
|
|
116
|
+
const userThreads = this.userThreadIndex.get(userId);
|
|
117
|
+
if (userThreads) {
|
|
118
|
+
const metadataToDelete = Array.from(userThreads).find(
|
|
119
|
+
(metadata) => metadata.threadId === threadId
|
|
120
|
+
);
|
|
121
|
+
if (metadataToDelete) {
|
|
122
|
+
userThreads.delete(metadataToDelete);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
116
125
|
}
|
|
117
126
|
async listThreads(userId) {
|
|
118
127
|
const threads = this.userThreadIndex.get(userId);
|
|
@@ -123,6 +132,66 @@ var InMemoryThread = class {
|
|
|
123
132
|
}
|
|
124
133
|
};
|
|
125
134
|
|
|
135
|
+
// implements/workflow.memory.ts
|
|
136
|
+
var InMemoryWorkflow = class {
|
|
137
|
+
workflows = /* @__PURE__ */ new Map();
|
|
138
|
+
userWorkflowIndex = /* @__PURE__ */ new Map();
|
|
139
|
+
async createWorkflow(workflow) {
|
|
140
|
+
this.workflows.set(workflow.workflowId, workflow);
|
|
141
|
+
if (workflow.userId) {
|
|
142
|
+
if (!this.userWorkflowIndex.has(workflow.userId)) {
|
|
143
|
+
this.userWorkflowIndex.set(workflow.userId, /* @__PURE__ */ new Set());
|
|
144
|
+
}
|
|
145
|
+
this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);
|
|
146
|
+
}
|
|
147
|
+
return workflow;
|
|
148
|
+
}
|
|
149
|
+
async getWorkflow(workflowId) {
|
|
150
|
+
return this.workflows.get(workflowId);
|
|
151
|
+
}
|
|
152
|
+
async updateWorkflow(workflowId, updates) {
|
|
153
|
+
if (!updates.userId) {
|
|
154
|
+
throw new Error("userId is required for updateWorkflow");
|
|
155
|
+
}
|
|
156
|
+
const existing = this.workflows.get(workflowId);
|
|
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");
|
|
162
|
+
}
|
|
163
|
+
const updated = { ...existing, ...updates, workflowId };
|
|
164
|
+
this.workflows.set(workflowId, updated);
|
|
165
|
+
}
|
|
166
|
+
async deleteWorkflow(workflowId, userId) {
|
|
167
|
+
const workflow = this.workflows.get(workflowId);
|
|
168
|
+
if (workflow && workflow.userId === userId) {
|
|
169
|
+
this.workflows.delete(workflowId);
|
|
170
|
+
this.userWorkflowIndex.get(userId)?.delete(workflowId);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
async listWorkflows(userId) {
|
|
174
|
+
const workflows = [];
|
|
175
|
+
for (const workflow of this.workflows.values()) {
|
|
176
|
+
if (!workflow.userId) {
|
|
177
|
+
workflows.push(workflow);
|
|
178
|
+
}
|
|
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
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return workflows;
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
126
195
|
// implements/base.memory.ts
|
|
127
196
|
var InMemoryMemory = class _InMemoryMemory {
|
|
128
197
|
static instance;
|
|
@@ -130,6 +199,7 @@ var InMemoryMemory = class _InMemoryMemory {
|
|
|
130
199
|
agentMemory;
|
|
131
200
|
intentMemory;
|
|
132
201
|
threadMemory;
|
|
202
|
+
workflowMemory;
|
|
133
203
|
constructor() {
|
|
134
204
|
if (!_InMemoryMemory.instance) {
|
|
135
205
|
_InMemoryMemory.instance = this;
|
|
@@ -137,6 +207,7 @@ var InMemoryMemory = class _InMemoryMemory {
|
|
|
137
207
|
this.agentMemory = new InMemoryAgent();
|
|
138
208
|
this.threadMemory = new InMemoryThread();
|
|
139
209
|
this.intentMemory = new InMemoryIntent();
|
|
210
|
+
this.workflowMemory = new InMemoryWorkflow();
|
|
140
211
|
}
|
|
141
212
|
async connect() {
|
|
142
213
|
this.connected = true;
|
|
@@ -156,6 +227,9 @@ var InMemoryMemory = class _InMemoryMemory {
|
|
|
156
227
|
getIntentMemory() {
|
|
157
228
|
return this.intentMemory;
|
|
158
229
|
}
|
|
230
|
+
getWorkflowMemory() {
|
|
231
|
+
return this.workflowMemory;
|
|
232
|
+
}
|
|
159
233
|
};
|
|
160
234
|
// Annotate the CommonJS export names for ESM import in node:
|
|
161
235
|
0 && (module.exports = {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../index.ts","../implements/agent.memory.ts","../implements/intent.memory.ts","../implements/thread.memory.ts","../implements/base.memory.ts"],"sourcesContent":["export { InMemoryMemory } from \"./implements/base.memory\";","import { IAgentMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryAgent implements IAgentMemory {\n private prompt: string = \"\";\n\n public async getAgentPrompt(): Promise<string> {\n return this.prompt;\n }\n\n public async updateAgentPrompt(prompt: string): Promise<void> {\n this.prompt = prompt;\n }\n}\n","import { randomUUID } from \"node:crypto\";\nimport type { Intent } from \"@ainetwork/adk/types/memory\";\nimport { IIntentMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryIntent implements IIntentMemory {\n public intents: Map<string, Intent> = new Map();\n\n public async getIntent(intentId: string): Promise<Intent | undefined> {\n return this.intents.get(intentId);\n }\n\n public async getIntentByName(intentName: string): Promise<Intent | undefined> {\n return Array.from(this.intents.values()).find(intent => intent.name === intentName);\n }\n\n public async saveIntent(intent: Intent): Promise<void> {\n const newId = randomUUID();\n this.intents.set(newId, intent);\n }\n\n public async updateIntent(intentId: string, intent: Intent): Promise<void> {\n this.intents.set(intentId, intent);\n }\n\n public async deleteIntent(intentId: string): Promise<void> {\n this.intents.delete(intentId);\n }\n\n public async listIntents(): Promise<Intent[]> {\n return Array.from(this.intents.values());\n }\n}","import type { MessageObject, ThreadObject, ThreadMetadata, ThreadType } from \"@ainetwork/adk/types/memory\";\nimport { IThreadMemory } from \"@ainetwork/adk/modules\";\n\ntype InMemoryThreadObject = {\n type: ThreadType;\n title: string;\n messages: Array<MessageObject>;\n}\n\ntype InMemoryThreadMetadata = {\n type: ThreadType;\n userId: string;\n threadId: string;\n title: string;\n updatedAt: number;\n createdAt: number;\n}\n\nexport class InMemoryThread implements IThreadMemory {\n public threads: Map<string, InMemoryThreadObject> = new Map();\n public userThreadIndex: Map<string, Set<InMemoryThreadMetadata>> = new Map();\n\n private generateKey(userId: string, threadId: string) {\n return `${userId}:${threadId}`;\n }\n\n public async getThread(\n userId: string,\n threadId: string\n ): Promise<ThreadObject | undefined> {\n const key = this.generateKey(userId, threadId);\n const res = this.threads.get(key);\n if (res) {\n const threadObject: ThreadObject = {\n threadId,\n userId,\n type: res.type,\n title: res.title,\n messages: res.messages,\n };\n return threadObject;\n }\n return undefined;\n }\n\n public async createThread(\n type: ThreadType,\n userId: string,\n threadId: string,\n title: string\n ): Promise<ThreadObject> {\n const now = Date.now();\n const key = this.generateKey(userId, threadId);\n if (!this.userThreadIndex.has(userId)) {\n this.userThreadIndex.set(userId, new Set());\n }\n if (!this.threads.has(key)) {\n this.threads.set(key, { type, title, messages: [] });\n const metadata: InMemoryThreadMetadata = {\n type, userId, threadId, title, createdAt: now, updatedAt: now,\n }\n this.userThreadIndex.get(userId)?.add(metadata);\n }\n\n return { type, title, threadId, userId, messages: [] };\n }\n\n public async addMessagesToThread(\n userId: string,\n threadId: string,\n messages: MessageObject[]\n ): Promise<void> {\n const key = this.generateKey(userId, threadId);\n const thread = this.threads.get(key);\n for (const message of messages) {\n thread?.messages.push(message);\n }\n }\n\n public async deleteThread(userId: string, threadId: string): Promise<void> {\n const key = this.generateKey(userId, threadId);\n this.threads.delete(key);\n this.userThreadIndex.delete(threadId);\n }\n\n public async listThreads(userId: string): Promise<ThreadMetadata[]> {\n const threads = this.userThreadIndex.get(userId);\n if (threads) {\n return Array.from(threads);\n }\n return [];\n }\n}","import { IAgentMemory, IIntentMemory, IMemory, IThreadMemory } from \"node_modules/@ainetwork/adk/dist/esm/modules/memory/base.memory\";\nimport { InMemoryAgent } from \"./agent.memory\";\nimport { InMemoryIntent } from \"./intent.memory\";\nimport { InMemoryThread } from \"./thread.memory\";\n\nexport class InMemoryMemory implements IMemory {\n private static instance: InMemoryMemory;\n private connected: boolean = false;\n\n private agentMemory: InMemoryAgent;\n private intentMemory: InMemoryIntent;\n private threadMemory: InMemoryThread;\n\n constructor() {\n if (!InMemoryMemory.instance) {\n InMemoryMemory.instance = this;\n }\n\n this.agentMemory = new InMemoryAgent();\n this.threadMemory = new InMemoryThread();\n this.intentMemory = new InMemoryIntent();\n }\n\n public async connect(): Promise<void> {\n this.connected = true;\n }\n\n public async disconnect(): Promise<void> {\n this.connected = false;\n }\n\n public isConnected(): boolean {\n return this.connected;\n }\n\n public getAgentMemory(): IAgentMemory {\n return this.agentMemory;\n }\n\n public getThreadMemory(): IThreadMemory {\n return this.threadMemory;\n }\n\n public getIntentMemory(): IIntentMemory {\n return this.intentMemory;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,gBAAN,MAA4C;AAAA,EACzC,SAAiB;AAAA,EAEzB,MAAa,iBAAkC;AAC7C,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,kBAAkB,QAA+B;AAC5D,SAAK,SAAS;AAAA,EAChB;AACF;;;ACZA,yBAA2B;AAIpB,IAAM,iBAAN,MAA8C;AAAA,EAC5C,UAA+B,oBAAI,IAAI;AAAA,EAE9C,MAAa,UAAU,UAA+C;AACpE,WAAO,KAAK,QAAQ,IAAI,QAAQ;AAAA,EAClC;AAAA,EAEA,MAAa,gBAAgB,YAAiD;AAC5E,WAAO,MAAM,KAAK,KAAK,QAAQ,OAAO,CAAC,EAAE,KAAK,YAAU,OAAO,SAAS,UAAU;AAAA,EACpF;AAAA,EAEA,MAAa,WAAW,QAA+B;AACrD,UAAM,YAAQ,+BAAW;AACzB,SAAK,QAAQ,IAAI,OAAO,MAAM;AAAA,EAChC;AAAA,EAEA,MAAa,aAAa,UAAkB,QAA+B;AACzE,SAAK,QAAQ,IAAI,UAAU,MAAM;AAAA,EACnC;AAAA,EAEA,MAAa,aAAa,UAAiC;AACzD,SAAK,QAAQ,OAAO,QAAQ;AAAA,EAC9B;AAAA,EAEA,MAAa,cAAiC;AAC5C,WAAO,MAAM,KAAK,KAAK,QA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,KAAK,QAAQ,IAAI,GAAG;AACnC,eAAW,WAAW,UAAU;AAC9B,cAAQ,SAAS,KAAK,OAAO;AAAA,IAC/B;AAAA,EACF;AAAA,EAEA,MAAa,aAAa,QAAgB,UAAiC;AACzE,UAAM,MAAM,KAAK,YAAY,QAAQ,QAAQ;AAC7C,SAAK,QAAQ,OAAO,GAAG;AACvB,SAAK,gBAAgB,OAAO,QAAQ;AAAA,EACtC;AAAA,EAEA,MAAa,YAAY,QAA2C;AAClE,UAAM,UAAU,KAAK,gBAAgB,IAAI,MAAM;AAC/C,QAAI,SAAS;AACX,aAAO,MAAM,KAAK,OAAO;AAAA,IAC3B;AACA,WAAO,CAAC;AAAA,EACV;AACF;;;ACvFO,IAAM,iBAAN,MAAM,gBAAkC;AAAA,EAC7C,OAAe;AAAA,EACP,YAAqB;AAAA,EAErB;AAAA,EACA;AAAA,EACA;AAAA,EAER,cAAc;AACZ,QAAI,CAAC,gBAAe,UAAU;AAC5B,sBAAe,WAAW;AAAA,IAC5B;AAEA,SAAK,cAAc,IAAI,cAAc;AACrC,SAAK,eAAe,IAAI,eAAe;AACvC,SAAK,eAAe,IAAI,eAAe;AAAA,EACzC;AAAA,EAEA,MAAa,UAAyB;AACpC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,MAAa,aAA4B;AACvC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEO,cAAuB;AAC5B,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,iBAA+B;AACpC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,kBAAiC;AACtC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,kBAAiC;AACtC,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../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,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,UAAM,+BAAW;AACzC,UAAM,eAAe,EAAE,GAAG,QAAQ,IAAI,SAAS;AAC/C,SAAK,QAAQ,IAAI,UAAU,YAAY;AAAA,EACzC;AAAA,EAEA,MAAa,aAAa,UAAkB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;AAAA,EAC7C,OAAe;AAAA,EACP,YAAqB;AAAA,EAErB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,cAAc;AACZ,QAAI,CAAC,gBAAe,UAAU;AAC5B,sBAAe,WAAW;AAAA,IAC5B;AAEA,SAAK,cAAc,IAAI,cAAc;AACrC,SAAK,eAAe,IAAI,eAAe;AACvC,SAAK,eAAe,IAAI,eAAe;AACvC,SAAK,iBAAiB,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,MAAa,UAAyB;AACpC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,MAAa,aAA4B;AACvC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEO,cAAuB;AAC5B,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,iBAA+B;AACpC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,kBAAiC;AACtC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,kBAAiC;AACtC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,oBAAqC;AAC1C,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IMemory, IAgentMemory, IThreadMemory, IIntentMemory } from '
|
|
1
|
+
import { IMemory, IAgentMemory, IThreadMemory, IIntentMemory, IWorkflowMemory } from '@ainetwork/adk/modules';
|
|
2
2
|
|
|
3
3
|
declare class InMemoryMemory implements IMemory {
|
|
4
4
|
private static instance;
|
|
@@ -6,6 +6,7 @@ declare class InMemoryMemory implements IMemory {
|
|
|
6
6
|
private agentMemory;
|
|
7
7
|
private intentMemory;
|
|
8
8
|
private threadMemory;
|
|
9
|
+
private workflowMemory;
|
|
9
10
|
constructor();
|
|
10
11
|
connect(): Promise<void>;
|
|
11
12
|
disconnect(): Promise<void>;
|
|
@@ -13,6 +14,7 @@ declare class InMemoryMemory implements IMemory {
|
|
|
13
14
|
getAgentMemory(): IAgentMemory;
|
|
14
15
|
getThreadMemory(): IThreadMemory;
|
|
15
16
|
getIntentMemory(): IIntentMemory;
|
|
17
|
+
getWorkflowMemory(): IWorkflowMemory;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
export { InMemoryMemory };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IMemory, IAgentMemory, IThreadMemory, IIntentMemory } from '
|
|
1
|
+
import { IMemory, IAgentMemory, IThreadMemory, IIntentMemory, IWorkflowMemory } from '@ainetwork/adk/modules';
|
|
2
2
|
|
|
3
3
|
declare class InMemoryMemory implements IMemory {
|
|
4
4
|
private static instance;
|
|
@@ -6,6 +6,7 @@ declare class InMemoryMemory implements IMemory {
|
|
|
6
6
|
private agentMemory;
|
|
7
7
|
private intentMemory;
|
|
8
8
|
private threadMemory;
|
|
9
|
+
private workflowMemory;
|
|
9
10
|
constructor();
|
|
10
11
|
connect(): Promise<void>;
|
|
11
12
|
disconnect(): Promise<void>;
|
|
@@ -13,6 +14,7 @@ declare class InMemoryMemory implements IMemory {
|
|
|
13
14
|
getAgentMemory(): IAgentMemory;
|
|
14
15
|
getThreadMemory(): IThreadMemory;
|
|
15
16
|
getIntentMemory(): IIntentMemory;
|
|
17
|
+
getWorkflowMemory(): IWorkflowMemory;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
export { InMemoryMemory };
|
package/dist/index.js
CHANGED
|
@@ -20,8 +20,9 @@ var InMemoryIntent = class {
|
|
|
20
20
|
return Array.from(this.intents.values()).find((intent) => intent.name === intentName);
|
|
21
21
|
}
|
|
22
22
|
async saveIntent(intent) {
|
|
23
|
-
const
|
|
24
|
-
|
|
23
|
+
const intentId = intent.id || randomUUID();
|
|
24
|
+
const intentToSave = { ...intent, id: intentId };
|
|
25
|
+
this.intents.set(intentId, intentToSave);
|
|
25
26
|
}
|
|
26
27
|
async updateIntent(intentId, intent) {
|
|
27
28
|
this.intents.set(intentId, intent);
|
|
@@ -86,7 +87,15 @@ var InMemoryThread = class {
|
|
|
86
87
|
async deleteThread(userId, threadId) {
|
|
87
88
|
const key = this.generateKey(userId, threadId);
|
|
88
89
|
this.threads.delete(key);
|
|
89
|
-
this.userThreadIndex.
|
|
90
|
+
const userThreads = this.userThreadIndex.get(userId);
|
|
91
|
+
if (userThreads) {
|
|
92
|
+
const metadataToDelete = Array.from(userThreads).find(
|
|
93
|
+
(metadata) => metadata.threadId === threadId
|
|
94
|
+
);
|
|
95
|
+
if (metadataToDelete) {
|
|
96
|
+
userThreads.delete(metadataToDelete);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
90
99
|
}
|
|
91
100
|
async listThreads(userId) {
|
|
92
101
|
const threads = this.userThreadIndex.get(userId);
|
|
@@ -97,6 +106,66 @@ var InMemoryThread = class {
|
|
|
97
106
|
}
|
|
98
107
|
};
|
|
99
108
|
|
|
109
|
+
// implements/workflow.memory.ts
|
|
110
|
+
var InMemoryWorkflow = class {
|
|
111
|
+
workflows = /* @__PURE__ */ new Map();
|
|
112
|
+
userWorkflowIndex = /* @__PURE__ */ new Map();
|
|
113
|
+
async createWorkflow(workflow) {
|
|
114
|
+
this.workflows.set(workflow.workflowId, workflow);
|
|
115
|
+
if (workflow.userId) {
|
|
116
|
+
if (!this.userWorkflowIndex.has(workflow.userId)) {
|
|
117
|
+
this.userWorkflowIndex.set(workflow.userId, /* @__PURE__ */ new Set());
|
|
118
|
+
}
|
|
119
|
+
this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);
|
|
120
|
+
}
|
|
121
|
+
return workflow;
|
|
122
|
+
}
|
|
123
|
+
async getWorkflow(workflowId) {
|
|
124
|
+
return this.workflows.get(workflowId);
|
|
125
|
+
}
|
|
126
|
+
async updateWorkflow(workflowId, updates) {
|
|
127
|
+
if (!updates.userId) {
|
|
128
|
+
throw new Error("userId is required for updateWorkflow");
|
|
129
|
+
}
|
|
130
|
+
const existing = this.workflows.get(workflowId);
|
|
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");
|
|
136
|
+
}
|
|
137
|
+
const updated = { ...existing, ...updates, workflowId };
|
|
138
|
+
this.workflows.set(workflowId, updated);
|
|
139
|
+
}
|
|
140
|
+
async deleteWorkflow(workflowId, userId) {
|
|
141
|
+
const workflow = this.workflows.get(workflowId);
|
|
142
|
+
if (workflow && workflow.userId === userId) {
|
|
143
|
+
this.workflows.delete(workflowId);
|
|
144
|
+
this.userWorkflowIndex.get(userId)?.delete(workflowId);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
async listWorkflows(userId) {
|
|
148
|
+
const workflows = [];
|
|
149
|
+
for (const workflow of this.workflows.values()) {
|
|
150
|
+
if (!workflow.userId) {
|
|
151
|
+
workflows.push(workflow);
|
|
152
|
+
}
|
|
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
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return workflows;
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
|
|
100
169
|
// implements/base.memory.ts
|
|
101
170
|
var InMemoryMemory = class _InMemoryMemory {
|
|
102
171
|
static instance;
|
|
@@ -104,6 +173,7 @@ var InMemoryMemory = class _InMemoryMemory {
|
|
|
104
173
|
agentMemory;
|
|
105
174
|
intentMemory;
|
|
106
175
|
threadMemory;
|
|
176
|
+
workflowMemory;
|
|
107
177
|
constructor() {
|
|
108
178
|
if (!_InMemoryMemory.instance) {
|
|
109
179
|
_InMemoryMemory.instance = this;
|
|
@@ -111,6 +181,7 @@ var InMemoryMemory = class _InMemoryMemory {
|
|
|
111
181
|
this.agentMemory = new InMemoryAgent();
|
|
112
182
|
this.threadMemory = new InMemoryThread();
|
|
113
183
|
this.intentMemory = new InMemoryIntent();
|
|
184
|
+
this.workflowMemory = new InMemoryWorkflow();
|
|
114
185
|
}
|
|
115
186
|
async connect() {
|
|
116
187
|
this.connected = true;
|
|
@@ -130,6 +201,9 @@ var InMemoryMemory = class _InMemoryMemory {
|
|
|
130
201
|
getIntentMemory() {
|
|
131
202
|
return this.intentMemory;
|
|
132
203
|
}
|
|
204
|
+
getWorkflowMemory() {
|
|
205
|
+
return this.workflowMemory;
|
|
206
|
+
}
|
|
133
207
|
};
|
|
134
208
|
export {
|
|
135
209
|
InMemoryMemory
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../implements/agent.memory.ts","../implements/intent.memory.ts","../implements/thread.memory.ts","../implements/base.memory.ts"],"sourcesContent":["import { IAgentMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryAgent implements IAgentMemory {\n private prompt: string = \"\";\n\n public async getAgentPrompt(): Promise<string> {\n return this.prompt;\n }\n\n public async updateAgentPrompt(prompt: string): Promise<void> {\n this.prompt = prompt;\n }\n}\n","import { randomUUID } from \"node:crypto\";\nimport type { Intent } from \"@ainetwork/adk/types/memory\";\nimport { IIntentMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryIntent implements IIntentMemory {\n public intents: Map<string, Intent> = new Map();\n\n public async getIntent(intentId: string): Promise<Intent | undefined> {\n return this.intents.get(intentId);\n }\n\n public async getIntentByName(intentName: string): Promise<Intent | undefined> {\n return Array.from(this.intents.values()).find(intent => intent.name === intentName);\n }\n\n public async saveIntent(intent: Intent): Promise<void> {\n const newId = randomUUID();\n this.intents.set(newId, intent);\n }\n\n public async updateIntent(intentId: string, intent: Intent): Promise<void> {\n this.intents.set(intentId, intent);\n }\n\n public async deleteIntent(intentId: string): Promise<void> {\n this.intents.delete(intentId);\n }\n\n public async listIntents(): Promise<Intent[]> {\n return Array.from(this.intents.values());\n }\n}","import type { MessageObject, ThreadObject, ThreadMetadata, ThreadType } from \"@ainetwork/adk/types/memory\";\nimport { IThreadMemory } from \"@ainetwork/adk/modules\";\n\ntype InMemoryThreadObject = {\n type: ThreadType;\n title: string;\n messages: Array<MessageObject>;\n}\n\ntype InMemoryThreadMetadata = {\n type: ThreadType;\n userId: string;\n threadId: string;\n title: string;\n updatedAt: number;\n createdAt: number;\n}\n\nexport class InMemoryThread implements IThreadMemory {\n public threads: Map<string, InMemoryThreadObject> = new Map();\n public userThreadIndex: Map<string, Set<InMemoryThreadMetadata>> = new Map();\n\n private generateKey(userId: string, threadId: string) {\n return `${userId}:${threadId}`;\n }\n\n public async getThread(\n userId: string,\n threadId: string\n ): Promise<ThreadObject | undefined> {\n const key = this.generateKey(userId, threadId);\n const res = this.threads.get(key);\n if (res) {\n const threadObject: ThreadObject = {\n threadId,\n userId,\n type: res.type,\n title: res.title,\n messages: res.messages,\n };\n return threadObject;\n }\n return undefined;\n }\n\n public async createThread(\n type: ThreadType,\n userId: string,\n threadId: string,\n title: string\n ): Promise<ThreadObject> {\n const now = Date.now();\n const key = this.generateKey(userId, threadId);\n if (!this.userThreadIndex.has(userId)) {\n this.userThreadIndex.set(userId, new Set());\n }\n if (!this.threads.has(key)) {\n this.threads.set(key, { type, title, messages: [] });\n const metadata: InMemoryThreadMetadata = {\n type, userId, threadId, title, createdAt: now, updatedAt: now,\n }\n this.userThreadIndex.get(userId)?.add(metadata);\n }\n\n return { type, title, threadId, userId, messages: [] };\n }\n\n public async addMessagesToThread(\n userId: string,\n threadId: string,\n messages: MessageObject[]\n ): Promise<void> {\n const key = this.generateKey(userId, threadId);\n const thread = this.threads.get(key);\n for (const message of messages) {\n thread?.messages.push(message);\n }\n }\n\n public async deleteThread(userId: string, threadId: string): Promise<void> {\n const key = this.generateKey(userId, threadId);\n this.threads.delete(key);\n this.userThreadIndex.delete(threadId);\n }\n\n public async listThreads(userId: string): Promise<ThreadMetadata[]> {\n const threads = this.userThreadIndex.get(userId);\n if (threads) {\n return Array.from(threads);\n }\n return [];\n }\n}","import { IAgentMemory, IIntentMemory, IMemory, IThreadMemory } from \"node_modules/@ainetwork/adk/dist/esm/modules/memory/base.memory\";\nimport { InMemoryAgent } from \"./agent.memory\";\nimport { InMemoryIntent } from \"./intent.memory\";\nimport { InMemoryThread } from \"./thread.memory\";\n\nexport class InMemoryMemory implements IMemory {\n private static instance: InMemoryMemory;\n private connected: boolean = false;\n\n private agentMemory: InMemoryAgent;\n private intentMemory: InMemoryIntent;\n private threadMemory: InMemoryThread;\n\n constructor() {\n if (!InMemoryMemory.instance) {\n InMemoryMemory.instance = this;\n }\n\n this.agentMemory = new InMemoryAgent();\n this.threadMemory = new InMemoryThread();\n this.intentMemory = new InMemoryIntent();\n }\n\n public async connect(): Promise<void> {\n this.connected = true;\n }\n\n public async disconnect(): Promise<void> {\n this.connected = false;\n }\n\n public isConnected(): boolean {\n return this.connected;\n }\n\n public getAgentMemory(): IAgentMemory {\n return this.agentMemory;\n }\n\n public getThreadMemory(): IThreadMemory {\n return this.threadMemory;\n }\n\n public getIntentMemory(): IIntentMemory {\n return this.intentMemory;\n }\n}\n"],"mappings":";AAEO,IAAM,gBAAN,MAA4C;AAAA,EACzC,SAAiB;AAAA,EAEzB,MAAa,iBAAkC;AAC7C,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAa,kBAAkB,QAA+B;AAC5D,SAAK,SAAS;AAAA,EAChB;AACF;;;ACZA,SAAS,kBAAkB;AAIpB,IAAM,iBAAN,MAA8C;AAAA,EAC5C,UAA+B,oBAAI,IAAI;AAAA,EAE9C,MAAa,UAAU,UAA+C;AACpE,WAAO,KAAK,QAAQ,IAAI,QAAQ;AAAA,EAClC;AAAA,EAEA,MAAa,gBAAgB,YAAiD;AAC5E,WAAO,MAAM,KAAK,KAAK,QAAQ,OAAO,CAAC,EAAE,KAAK,YAAU,OAAO,S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AAAA,EACd;AAAA,EAEO,iBAA+B;AACpC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,kBAAiC;AACtC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,kBAAiC;AACtC,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../implements/agent.memory.ts","../implements/intent.memory.ts","../implements/thread.memory.ts","../implements/workflow.memory.ts","../implements/base.memory.ts"],"sourcesContent":["import { IAgentMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryAgent implements IAgentMemory {\n private prompt: string = \"\";\n\n public async getAgentPrompt(): Promise<string> {\n return this.prompt;\n }\n\n public async updateAgentPrompt(prompt: string): Promise<void> {\n this.prompt = prompt;\n }\n}\n","import { randomUUID } from \"node:crypto\";\nimport type { Intent } from \"@ainetwork/adk/types/memory\";\nimport { IIntentMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryIntent implements IIntentMemory {\n public intents: Map<string, Intent> = new Map();\n\n public async getIntent(intentId: string): Promise<Intent | undefined> {\n return this.intents.get(intentId);\n }\n\n public async getIntentByName(intentName: string): Promise<Intent | undefined> {\n return Array.from(this.intents.values()).find(intent => intent.name === intentName);\n }\n\n public async saveIntent(intent: Intent): Promise<void> {\n // Intent에 이미 id가 있으면 그것을 사용하고, 없으면 새로 생성\n const intentId = intent.id || randomUUID();\n const intentToSave = { ...intent, id: intentId };\n this.intents.set(intentId, intentToSave);\n }\n\n public async updateIntent(intentId: string, intent: Intent): Promise<void> {\n this.intents.set(intentId, intent);\n }\n\n public async deleteIntent(intentId: string): Promise<void> {\n this.intents.delete(intentId);\n }\n\n public async listIntents(): Promise<Intent[]> {\n return Array.from(this.intents.values());\n }\n}","import type { MessageObject, ThreadObject, ThreadMetadata, ThreadType } from \"@ainetwork/adk/types/memory\";\nimport { IThreadMemory } from \"@ainetwork/adk/modules\";\n\ntype InMemoryThreadObject = {\n type: ThreadType;\n title: string;\n messages: Array<MessageObject>;\n}\n\ntype InMemoryThreadMetadata = {\n type: ThreadType;\n userId: string;\n threadId: string;\n title: string;\n updatedAt: number;\n createdAt: number;\n}\n\nexport class InMemoryThread implements IThreadMemory {\n public threads: Map<string, InMemoryThreadObject> = new Map();\n public userThreadIndex: Map<string, Set<InMemoryThreadMetadata>> = new Map();\n\n private generateKey(userId: string, threadId: string) {\n return `${userId}:${threadId}`;\n }\n\n public async getThread(\n userId: string,\n threadId: string\n ): Promise<ThreadObject | undefined> {\n const key = this.generateKey(userId, threadId);\n const res = this.threads.get(key);\n if (res) {\n const threadObject: ThreadObject = {\n threadId,\n userId,\n type: res.type,\n title: res.title,\n messages: res.messages,\n };\n return threadObject;\n }\n return undefined;\n }\n\n public async createThread(\n type: ThreadType,\n userId: string,\n threadId: string,\n title: string\n ): Promise<ThreadObject> {\n const now = Date.now();\n const key = this.generateKey(userId, threadId);\n if (!this.userThreadIndex.has(userId)) {\n this.userThreadIndex.set(userId, new Set());\n }\n if (!this.threads.has(key)) {\n this.threads.set(key, { type, title, messages: [] });\n const metadata: InMemoryThreadMetadata = {\n type, userId, threadId, title, createdAt: now, updatedAt: now,\n }\n this.userThreadIndex.get(userId)?.add(metadata);\n }\n\n return { type, title, threadId, userId, messages: [] };\n }\n\n public async addMessagesToThread(\n userId: string,\n threadId: string,\n messages: MessageObject[]\n ): Promise<void> {\n const key = this.generateKey(userId, threadId);\n const thread = this.threads.get(key);\n for (const message of messages) {\n thread?.messages.push(message);\n }\n }\n\n public async deleteThread(userId: string, threadId: string): Promise<void> {\n const key = this.generateKey(userId, threadId);\n this.threads.delete(key);\n\n // userThreadIndex에서 해당 thread metadata 제거\n const userThreads = this.userThreadIndex.get(userId);\n if (userThreads) {\n const metadataToDelete = Array.from(userThreads).find(\n metadata => metadata.threadId === threadId\n );\n if (metadataToDelete) {\n userThreads.delete(metadataToDelete);\n }\n }\n }\n\n public async listThreads(userId: string): Promise<ThreadMetadata[]> {\n const threads = this.userThreadIndex.get(userId);\n if (threads) {\n return Array.from(threads);\n }\n return [];\n }\n}","import { IWorkflowMemory } from \"@ainetwork/adk/modules\";\nimport type { Workflow } from \"@ainetwork/adk/types/memory\";\n\nexport class InMemoryWorkflow implements IWorkflowMemory {\n private workflows: Map<string, Workflow> = new Map();\n private userWorkflowIndex: Map<string, Set<string>> = new Map();\n\n public async createWorkflow(workflow: Workflow): Promise<Workflow> {\n this.workflows.set(workflow.workflowId, workflow);\n\n if (workflow.userId) {\n if (!this.userWorkflowIndex.has(workflow.userId)) {\n this.userWorkflowIndex.set(workflow.userId, new Set());\n }\n this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);\n }\n\n return workflow;\n }\n\n public async getWorkflow(workflowId: string): Promise<Workflow | undefined> {\n return this.workflows.get(workflowId);\n }\n\n public async updateWorkflow(workflowId: string, updates: Partial<Workflow>): Promise<void> {\n 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,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BAAkB,IAAI,MAAM;AACzD,UAAI,iBAAiB;AACnB,mBAAW,cAAc,iBAAiB;AACxC,gBAAM,WAAW,KAAK,UAAU,IAAI,UAAU;AAC9C,cAAI,UAAU;AACZ,sBAAU,KAAK,QAAQ;AAAA,UACzB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;;;ACrEO,IAAM,iBAAN,MAAM,gBAAkC;AAAA,EAC7C,OAAe;AAAA,EACP,YAAqB;AAAA,EAErB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,cAAc;AACZ,QAAI,CAAC,gBAAe,UAAU;AAC5B,sBAAe,WAAW;AAAA,IAC5B;AAEA,SAAK,cAAc,IAAI,cAAc;AACrC,SAAK,eAAe,IAAI,eAAe;AACvC,SAAK,eAAe,IAAI,eAAe;AACvC,SAAK,iBAAiB,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,MAAa,UAAyB;AACpC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,MAAa,aAA4B;AACvC,SAAK,YAAY;AAAA,EACnB;AAAA,EAEO,cAAuB;AAC5B,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,iBAA+B;AACpC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,kBAAiC;AACtC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,kBAAiC;AACtC,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,oBAAqC;AAC1C,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { IAgentMemory, IIntentMemory, IMemory, IThreadMemory } from "
|
|
1
|
+
import { IAgentMemory, IIntentMemory, IMemory, IThreadMemory, IWorkflowMemory } from "@ainetwork/adk/modules";
|
|
2
2
|
import { InMemoryAgent } from "./agent.memory";
|
|
3
3
|
import { InMemoryIntent } from "./intent.memory";
|
|
4
4
|
import { InMemoryThread } from "./thread.memory";
|
|
5
|
+
import { InMemoryWorkflow } from "./workflow.memory";
|
|
5
6
|
|
|
6
7
|
export class InMemoryMemory implements IMemory {
|
|
7
8
|
private static instance: InMemoryMemory;
|
|
@@ -10,6 +11,7 @@ export class InMemoryMemory implements IMemory {
|
|
|
10
11
|
private agentMemory: InMemoryAgent;
|
|
11
12
|
private intentMemory: InMemoryIntent;
|
|
12
13
|
private threadMemory: InMemoryThread;
|
|
14
|
+
private workflowMemory: InMemoryWorkflow;
|
|
13
15
|
|
|
14
16
|
constructor() {
|
|
15
17
|
if (!InMemoryMemory.instance) {
|
|
@@ -19,6 +21,7 @@ export class InMemoryMemory implements IMemory {
|
|
|
19
21
|
this.agentMemory = new InMemoryAgent();
|
|
20
22
|
this.threadMemory = new InMemoryThread();
|
|
21
23
|
this.intentMemory = new InMemoryIntent();
|
|
24
|
+
this.workflowMemory = new InMemoryWorkflow();
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
public async connect(): Promise<void> {
|
|
@@ -44,4 +47,8 @@ export class InMemoryMemory implements IMemory {
|
|
|
44
47
|
public getIntentMemory(): IIntentMemory {
|
|
45
48
|
return this.intentMemory;
|
|
46
49
|
}
|
|
50
|
+
|
|
51
|
+
public getWorkflowMemory(): IWorkflowMemory {
|
|
52
|
+
return this.workflowMemory;
|
|
53
|
+
}
|
|
47
54
|
}
|
|
@@ -14,8 +14,10 @@ export class InMemoryIntent implements IIntentMemory {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
public async saveIntent(intent: Intent): Promise<void> {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
// Intent에 이미 id가 있으면 그것을 사용하고, 없으면 새로 생성
|
|
18
|
+
const intentId = intent.id || randomUUID();
|
|
19
|
+
const intentToSave = { ...intent, id: intentId };
|
|
20
|
+
this.intents.set(intentId, intentToSave);
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
public async updateIntent(intentId: string, intent: Intent): Promise<void> {
|
|
@@ -80,7 +80,17 @@ export class InMemoryThread implements IThreadMemory {
|
|
|
80
80
|
public async deleteThread(userId: string, threadId: string): Promise<void> {
|
|
81
81
|
const key = this.generateKey(userId, threadId);
|
|
82
82
|
this.threads.delete(key);
|
|
83
|
-
|
|
83
|
+
|
|
84
|
+
// userThreadIndex에서 해당 thread metadata 제거
|
|
85
|
+
const userThreads = this.userThreadIndex.get(userId);
|
|
86
|
+
if (userThreads) {
|
|
87
|
+
const metadataToDelete = Array.from(userThreads).find(
|
|
88
|
+
metadata => metadata.threadId === threadId
|
|
89
|
+
);
|
|
90
|
+
if (metadataToDelete) {
|
|
91
|
+
userThreads.delete(metadataToDelete);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
84
94
|
}
|
|
85
95
|
|
|
86
96
|
public async listThreads(userId: string): Promise<ThreadMetadata[]> {
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { IWorkflowMemory } from "@ainetwork/adk/modules";
|
|
2
|
+
import type { Workflow } from "@ainetwork/adk/types/memory";
|
|
3
|
+
|
|
4
|
+
export class InMemoryWorkflow implements IWorkflowMemory {
|
|
5
|
+
private workflows: Map<string, Workflow> = new Map();
|
|
6
|
+
private userWorkflowIndex: Map<string, Set<string>> = new Map();
|
|
7
|
+
|
|
8
|
+
public async createWorkflow(workflow: Workflow): Promise<Workflow> {
|
|
9
|
+
this.workflows.set(workflow.workflowId, workflow);
|
|
10
|
+
|
|
11
|
+
if (workflow.userId) {
|
|
12
|
+
if (!this.userWorkflowIndex.has(workflow.userId)) {
|
|
13
|
+
this.userWorkflowIndex.set(workflow.userId, new Set());
|
|
14
|
+
}
|
|
15
|
+
this.userWorkflowIndex.get(workflow.userId)?.add(workflow.workflowId);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return workflow;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public async getWorkflow(workflowId: string): Promise<Workflow | undefined> {
|
|
22
|
+
return this.workflows.get(workflowId);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public async updateWorkflow(workflowId: string, updates: Partial<Workflow>): Promise<void> {
|
|
26
|
+
if (!updates.userId) {
|
|
27
|
+
throw new Error("userId is required for updateWorkflow");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const existing = this.workflows.get(workflowId);
|
|
31
|
+
if (!existing) {
|
|
32
|
+
throw new Error(`Workflow not found: ${workflowId}`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (existing.userId !== updates.userId) {
|
|
36
|
+
throw new Error("Unauthorized: userId does not match workflow owner");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const updated = { ...existing, ...updates, workflowId };
|
|
40
|
+
this.workflows.set(workflowId, updated);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public async deleteWorkflow(workflowId: string, userId: string): Promise<void> {
|
|
44
|
+
const workflow = this.workflows.get(workflowId);
|
|
45
|
+
if (workflow && workflow.userId === userId) {
|
|
46
|
+
this.workflows.delete(workflowId);
|
|
47
|
+
this.userWorkflowIndex.get(userId)?.delete(workflowId);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public async listWorkflows(userId?: string): Promise<Workflow[]> {
|
|
52
|
+
const workflows: Workflow[] = [];
|
|
53
|
+
|
|
54
|
+
// 템플릿 workflow (userId가 없는 것)은 항상 포함
|
|
55
|
+
for (const workflow of this.workflows.values()) {
|
|
56
|
+
if (!workflow.userId) {
|
|
57
|
+
workflows.push(workflow);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// userId가 있으면 해당 유저 소유 workflow도 포함
|
|
62
|
+
if (userId) {
|
|
63
|
+
const userWorkflowIds = this.userWorkflowIndex.get(userId);
|
|
64
|
+
if (userWorkflowIds) {
|
|
65
|
+
for (const workflowId of userWorkflowIds) {
|
|
66
|
+
const workflow = this.workflows.get(workflowId);
|
|
67
|
+
if (workflow) {
|
|
68
|
+
workflows.push(workflow);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return workflows;
|
|
75
|
+
}
|
|
76
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ainetwork/adk-provider-memory-inmemory",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
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.
|
|
24
|
+
"@ainetwork/adk": "^0.3.5"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"typescript": "^5.0.0"
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "0361ececa3c7404035d1b67c4830f52fa904d3d8"
|
|
34
34
|
}
|