@ainetwork/adk-provider-memory-inmemory 0.2.1 → 0.2.2

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
@@ -44,6 +44,8 @@ var InMemoryThread = class {
44
44
  const res = this.threads.get(key);
45
45
  if (res) {
46
46
  const threadObject = {
47
+ threadId,
48
+ userId,
47
49
  type: res.type,
48
50
  title: res.title,
49
51
  messages: res.messages
@@ -62,6 +64,7 @@ var InMemoryThread = class {
62
64
  this.threads.set(key, { type, title, messages: [] });
63
65
  const metadata = {
64
66
  type,
67
+ userId,
65
68
  threadId,
66
69
  title,
67
70
  createdAt: now,
@@ -69,7 +72,7 @@ var InMemoryThread = class {
69
72
  };
70
73
  this.userThreadIndex.get(userId)?.add(metadata);
71
74
  }
72
- return { type, title, threadId, updatedAt: now };
75
+ return { type, title, threadId, userId, messages: [] };
73
76
  }
74
77
  async addMessagesToThread(userId, threadId, messages) {
75
78
  const key = this.generateKey(userId, threadId);
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts","../implements/thread.memory.ts","../implements/intent.memory.ts"],"sourcesContent":["export { InMemoryThread } from \"./implements/thread.memory\";\nexport { InMemoryIntent } from \"./implements/intent.memory\";","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 threadId: string;\n title: string;\n updatedAt: number;\n createdAt: number;\n}\n\nexport class InMemoryThread implements IThreadMemory {\n\tpublic threads: Map<string, InMemoryThreadObject> = new Map();\n public userThreadIndex: Map<string, Set<InMemoryThreadMetadata>> = new Map();\n\n public async connect(): Promise<void> {}\n public async disconnect(): Promise<void> {}\n public isConnected(): boolean {\n return true;\n }\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 type: res.type,\n title: res.title,\n messages: res.messages,\n };\n return threadObject;\n }\n return undefined;\n };\n\n\tpublic async createThread(\n type: ThreadType,\n userId: string,\n threadId: string,\n title: string\n ): Promise<ThreadMetadata> {\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, threadId, title, createdAt: now, updatedAt: now,\n }\n this.userThreadIndex.get(userId)?.add(metadata);\n }\n\n return { type, title, threadId, updatedAt: now };\n };\n\n\tpublic 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\tpublic 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\tpublic 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 { 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\tpublic intents: Map<string, Intent> = new Map();\n\n public async connect(): Promise<void> {}\n public async disconnect(): Promise<void> {}\n public isConnected(): boolean {\n return true;\n }\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\tpublic async saveIntent(intent: Intent): Promise<void> {\n const newId = randomUUID();\n this.intents.set(newId, intent);\n };\n\n\tpublic async updateIntent(intentId: string, intent: Intent): Promise<void> {\n this.intents.set(intentId, intent);\n };\n\n\tpublic async deleteIntent(intentId: string): Promise<void> {\n this.intents.delete(intentId);\n };\n\n\tpublic async listIntents(): Promise<Intent[]> {\n return Array.from(this.intents.values());\n };\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiBO,IAAM,iBAAN,MAA8C;AAAA,EAC7C,UAA6C,oBAAI,IAAI;AAAA,EACpD,kBAA4D,oBAAI,IAAI;AAAA,EAE3E,MAAa,UAAyB;AAAA,EAAC;AAAA,EACvC,MAAa,aAA4B;AAAA,EAAC;AAAA,EACnC,cAAuB;AAC5B,WAAO;AAAA,EACT;AAAA,EAEQ,YAAY,QAAgB,UAAkB;AACpD,WAAO,GAAG,MAAM,IAAI,QAAQ;AAAA,EAC9B;AAAA,EAEA,MAAa,UACX,QACA,UACmC;AACnC,UAAM,MAAM,KAAK,YAAY,QAAQ,QAAQ;AAC7C,UAAM,MAAM,KAAK,QAAQ,IAAI,GAAG;AAChC,QAAI,KAAK;AACP,YAAM,eAA6B;AAAA,QACjC,MAAM,IAAI;AAAA,QACV,OAAO,IAAI;AAAA,QACX,UAAU,IAAI;AAAA,MAChB;AACA,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT;AAAA,EAED,MAAa,aACV,MACA,QACA,UACA,OACyB;AACzB,UAAM,MAAM,KAAK,IAAI;AACrB,UAAM,MAAM,KAAK,YAAY,QAAQ,QAAQ;AAC7C,QAAI,CAAC,KAAK,gBAAgB,IAAI,MAAM,GAAG;AACrC,WAAK,gBAAgB,IAAI,QAAQ,oBAAI,IAAI,CAAC;AAAA,IAC5C;AACA,QAAI,CAAC,KAAK,QAAQ,IAAI,GAAG,GAAG;AAC1B,WAAK,QAAQ,IAAI,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MAAa,WAAW,QAA+B;AACpD,UAAM,YAAQ,+BAAW;AACzB,SAAK,QAAQ,IAAI,OAAO,MAAM;AAAA,EAChC;AAAA,EAED,MAAa,aAAa,UAAkB,QAA+B;AACxE,SAAK,QAAQ,IAAI,UAAU,MAAM;AAAA,EACnC;AAAA,EAED,MAAa,aAAa,UAAiC;AACxD,SAAK,QAAQ,OAAO,QAAQ;AAAA,EAC9B;AAAA,EAED,MAAa,cAAiC;AAC3C,WAAO,MAAM,KAAK,KAAK,QAAQ,OAAO,CAAC;AAAA,EACzC;AACF;","names":[]}
1
+ {"version":3,"sources":["../index.ts","../implements/thread.memory.ts","../implements/intent.memory.ts"],"sourcesContent":["export { InMemoryThread } from \"./implements/thread.memory\";\nexport { InMemoryIntent } from \"./implements/intent.memory\";","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\tpublic threads: Map<string, InMemoryThreadObject> = new Map();\n public userThreadIndex: Map<string, Set<InMemoryThreadMetadata>> = new Map();\n\n public async connect(): Promise<void> {}\n public async disconnect(): Promise<void> {}\n public isConnected(): boolean {\n return true;\n }\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\tpublic 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\tpublic 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\tpublic 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\tpublic 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 { 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\tpublic intents: Map<string, Intent> = new Map();\n\n public async connect(): Promise<void> {}\n public async disconnect(): Promise<void> {}\n public isConnected(): boolean {\n return true;\n }\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\tpublic async saveIntent(intent: Intent): Promise<void> {\n const newId = randomUUID();\n this.intents.set(newId, intent);\n };\n\n\tpublic async updateIntent(intentId: string, intent: Intent): Promise<void> {\n this.intents.set(intentId, intent);\n };\n\n\tpublic async deleteIntent(intentId: string): Promise<void> {\n this.intents.delete(intentId);\n };\n\n\tpublic async listIntents(): Promise<Intent[]> {\n return Array.from(this.intents.values());\n };\n}"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,QAAQ,OAAO,QAAQ;AAAA,EAC9B;AAAA,EAED,MAAa,cAAiC;AAC3C,WAAO,MAAM,KAAK,KAAK,QAAQ,OAAO,CAAC;AAAA,EACzC;AACF;","names":[]}
package/dist/index.d.cts CHANGED
@@ -8,6 +8,7 @@ type InMemoryThreadObject = {
8
8
  };
9
9
  type InMemoryThreadMetadata = {
10
10
  type: ThreadType;
11
+ userId: string;
11
12
  threadId: string;
12
13
  title: string;
13
14
  updatedAt: number;
@@ -21,7 +22,7 @@ declare class InMemoryThread implements IThreadMemory {
21
22
  isConnected(): boolean;
22
23
  private generateKey;
23
24
  getThread(userId: string, threadId: string): Promise<ThreadObject | undefined>;
24
- createThread(type: ThreadType, userId: string, threadId: string, title: string): Promise<ThreadMetadata>;
25
+ createThread(type: ThreadType, userId: string, threadId: string, title: string): Promise<ThreadObject>;
25
26
  addMessagesToThread(userId: string, threadId: string, messages: MessageObject[]): Promise<void>;
26
27
  deleteThread(userId: string, threadId: string): Promise<void>;
27
28
  listThreads(userId: string): Promise<ThreadMetadata[]>;
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ type InMemoryThreadObject = {
8
8
  };
9
9
  type InMemoryThreadMetadata = {
10
10
  type: ThreadType;
11
+ userId: string;
11
12
  threadId: string;
12
13
  title: string;
13
14
  updatedAt: number;
@@ -21,7 +22,7 @@ declare class InMemoryThread implements IThreadMemory {
21
22
  isConnected(): boolean;
22
23
  private generateKey;
23
24
  getThread(userId: string, threadId: string): Promise<ThreadObject | undefined>;
24
- createThread(type: ThreadType, userId: string, threadId: string, title: string): Promise<ThreadMetadata>;
25
+ createThread(type: ThreadType, userId: string, threadId: string, title: string): Promise<ThreadObject>;
25
26
  addMessagesToThread(userId: string, threadId: string, messages: MessageObject[]): Promise<void>;
26
27
  deleteThread(userId: string, threadId: string): Promise<void>;
27
28
  listThreads(userId: string): Promise<ThreadMetadata[]>;
package/dist/index.js CHANGED
@@ -17,6 +17,8 @@ var InMemoryThread = class {
17
17
  const res = this.threads.get(key);
18
18
  if (res) {
19
19
  const threadObject = {
20
+ threadId,
21
+ userId,
20
22
  type: res.type,
21
23
  title: res.title,
22
24
  messages: res.messages
@@ -35,6 +37,7 @@ var InMemoryThread = class {
35
37
  this.threads.set(key, { type, title, messages: [] });
36
38
  const metadata = {
37
39
  type,
40
+ userId,
38
41
  threadId,
39
42
  title,
40
43
  createdAt: now,
@@ -42,7 +45,7 @@ var InMemoryThread = class {
42
45
  };
43
46
  this.userThreadIndex.get(userId)?.add(metadata);
44
47
  }
45
- return { type, title, threadId, updatedAt: now };
48
+ return { type, title, threadId, userId, messages: [] };
46
49
  }
47
50
  async addMessagesToThread(userId, threadId, messages) {
48
51
  const key = this.generateKey(userId, threadId);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../implements/thread.memory.ts","../implements/intent.memory.ts"],"sourcesContent":["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 threadId: string;\n title: string;\n updatedAt: number;\n createdAt: number;\n}\n\nexport class InMemoryThread implements IThreadMemory {\n\tpublic threads: Map<string, InMemoryThreadObject> = new Map();\n public userThreadIndex: Map<string, Set<InMemoryThreadMetadata>> = new Map();\n\n public async connect(): Promise<void> {}\n public async disconnect(): Promise<void> {}\n public isConnected(): boolean {\n return true;\n }\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 type: res.type,\n title: res.title,\n messages: res.messages,\n };\n return threadObject;\n }\n return undefined;\n };\n\n\tpublic async createThread(\n type: ThreadType,\n userId: string,\n threadId: string,\n title: string\n ): Promise<ThreadMetadata> {\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, threadId, title, createdAt: now, updatedAt: now,\n }\n this.userThreadIndex.get(userId)?.add(metadata);\n }\n\n return { type, title, threadId, updatedAt: now };\n };\n\n\tpublic 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\tpublic 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\tpublic 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 { 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\tpublic intents: Map<string, Intent> = new Map();\n\n public async connect(): Promise<void> {}\n public async disconnect(): Promise<void> {}\n public isConnected(): boolean {\n return true;\n }\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\tpublic async saveIntent(intent: Intent): Promise<void> {\n const newId = randomUUID();\n this.intents.set(newId, intent);\n };\n\n\tpublic async updateIntent(intentId: string, intent: Intent): Promise<void> {\n this.intents.set(intentId, intent);\n };\n\n\tpublic async deleteIntent(intentId: string): Promise<void> {\n this.intents.delete(intentId);\n };\n\n\tpublic async listIntents(): Promise<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,MAAM,KAAK,KAAK,QAAQ,OAAO,CAAC;AAAA,EACzC;AACF;","names":[]}
1
+ {"version":3,"sources":["../implements/thread.memory.ts","../implements/intent.memory.ts"],"sourcesContent":["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\tpublic threads: Map<string, InMemoryThreadObject> = new Map();\n public userThreadIndex: Map<string, Set<InMemoryThreadMetadata>> = new Map();\n\n public async connect(): Promise<void> {}\n public async disconnect(): Promise<void> {}\n public isConnected(): boolean {\n return true;\n }\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\tpublic 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\tpublic 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\tpublic 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\tpublic 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 { 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\tpublic intents: Map<string, Intent> = new Map();\n\n public async connect(): Promise<void> {}\n public async disconnect(): Promise<void> {}\n public isConnected(): boolean {\n return true;\n }\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\tpublic async saveIntent(intent: Intent): Promise<void> {\n const newId = randomUUID();\n this.intents.set(newId, intent);\n };\n\n\tpublic async updateIntent(intentId: string, intent: Intent): Promise<void> {\n this.intents.set(intentId, intent);\n };\n\n\tpublic async deleteIntent(intentId: string): Promise<void> {\n this.intents.delete(intentId);\n };\n\n\tpublic async listIntents(): Promise<Intent[]> {\n return Array.from(this.intents.values());\n };\n}"],"mappings":";AAkBO,IAAM,iBAAN,MAA8C;AAAA,EAC7C,UAA6C,oBAAI,IAAI;AAAA,EACpD,kBAA4D,oBAAI,IAAI;AAAA,EAE3E,MAAa,UAAyB;AAAA,EAAC;AAAA,EACvC,MAAa,aAA4B;AAAA,EAAC;AAAA,EACnC,cAAuB;AAC5B,WAAO;AAAA,EACT;AAAA,EAEQ,YAAY,QAAgB,UAAkB;AACpD,WAAO,GAAG,MAAM,IAAI,QAAQ;AAAA,EAC9B;AAAA,EAEA,MAAa,UACX,QACA,UACmC;AACnC,UAAM,MAAM,KAAK,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AED,MAAa,YAAY,QAA2C;AACjE,UAAM,UAAU,KAAK,gBAAgB,IAAI,MAAM;AAC/C,QAAI,SAAS;AACX,aAAO,MAAM,KAAK,OAAO;AAAA,IAC3B;AACA,WAAO,CAAC;AAAA,EACV;AACF;;;AClGA,SAAS,kBAAkB;AAIpB,IAAM,iBAAN,MAA8C;AAAA,EAC7C,UAA+B,oBAAI,IAAI;AAAA,EAE7C,MAAa,UAAyB;AAAA,EAAC;AAAA,EACvC,MAAa,aAA4B;AAAA,EAAC;AAAA,EACnC,cAAuB;AAC5B,WAAO;AAAA,EACT;AAAA,EAEA,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,EAED,MAAa,WAAW,QAA+B;AACpD,UAAM,QAAQ,WAAW;AACzB,SAAK,QAAQ,IAAI,OAAO,MAAM;AAAA,EAChC;AAAA,EAED,MAAa,aAAa,UAAkB,QAA+B;AACxE,SAAK,QAAQ,IAAI,UAAU,MAAM;AAAA,EACnC;AAAA,EAED,MAAa,aAAa,UAAiC;AACxD,SAAK,QAAQ,OAAO,QAAQ;AAAA,EAC9B;AAAA,EAED,MAAa,cAAiC;AAC3C,WAAO,MAAM,KAAK,KAAK,QAAQ,OAAO,CAAC;AAAA,EACzC;AACF;","names":[]}
@@ -9,6 +9,7 @@ type InMemoryThreadObject = {
9
9
 
10
10
  type InMemoryThreadMetadata = {
11
11
  type: ThreadType;
12
+ userId: string;
12
13
  threadId: string;
13
14
  title: string;
14
15
  updatedAt: number;
@@ -37,6 +38,8 @@ export class InMemoryThread implements IThreadMemory {
37
38
  const res = this.threads.get(key);
38
39
  if (res) {
39
40
  const threadObject: ThreadObject = {
41
+ threadId,
42
+ userId,
40
43
  type: res.type,
41
44
  title: res.title,
42
45
  messages: res.messages,
@@ -51,7 +54,7 @@ export class InMemoryThread implements IThreadMemory {
51
54
  userId: string,
52
55
  threadId: string,
53
56
  title: string
54
- ): Promise<ThreadMetadata> {
57
+ ): Promise<ThreadObject> {
55
58
  const now = Date.now();
56
59
  const key = this.generateKey(userId, threadId);
57
60
  if (!this.userThreadIndex.has(userId)) {
@@ -60,12 +63,12 @@ export class InMemoryThread implements IThreadMemory {
60
63
  if (!this.threads.has(key)) {
61
64
  this.threads.set(key, { type, title, messages: [] });
62
65
  const metadata: InMemoryThreadMetadata = {
63
- type, threadId, title, createdAt: now, updatedAt: now,
66
+ type, userId, threadId, title, createdAt: now, updatedAt: now,
64
67
  }
65
68
  this.userThreadIndex.get(userId)?.add(metadata);
66
69
  }
67
70
 
68
- return { type, title, threadId, updatedAt: now };
71
+ return { type, title, threadId, userId, messages: [] };
69
72
  };
70
73
 
71
74
  public async addMessagesToThread(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ainetwork/adk-provider-memory-inmemory",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
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.2.5"
24
+ "@ainetwork/adk": "^0.2.7"
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": "65f5c77dad2ba16ee695a88f9b1b3ca2a5a886a3"
33
+ "gitHead": "e0021453227b0c9c0cd1d21efa0395e8e1f6740e"
34
34
  }