@ainetwork/adk-provider-memory-inmemory 0.1.7 → 0.2.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 +6 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -8
- package/dist/index.js.map +1 -1
- package/implements/thread.memory.ts +4 -7
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -26,7 +26,6 @@ __export(index_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(index_exports);
|
|
27
27
|
|
|
28
28
|
// implements/thread.memory.ts
|
|
29
|
-
var import_node_crypto = require("crypto");
|
|
30
29
|
var InMemoryThread = class {
|
|
31
30
|
threads = /* @__PURE__ */ new Map();
|
|
32
31
|
userThreadIndex = /* @__PURE__ */ new Map();
|
|
@@ -40,14 +39,14 @@ var InMemoryThread = class {
|
|
|
40
39
|
generateKey(userId, threadId) {
|
|
41
40
|
return `${userId}:${threadId}`;
|
|
42
41
|
}
|
|
43
|
-
async getThread(
|
|
42
|
+
async getThread(userId, threadId) {
|
|
44
43
|
const key = this.generateKey(userId, threadId);
|
|
45
44
|
const res = this.threads.get(key);
|
|
46
45
|
if (res) {
|
|
47
46
|
const threadObject = {
|
|
48
47
|
type: res.type,
|
|
49
48
|
title: res.title,
|
|
50
|
-
messages:
|
|
49
|
+
messages: res.messages
|
|
51
50
|
};
|
|
52
51
|
return threadObject;
|
|
53
52
|
}
|
|
@@ -60,7 +59,7 @@ var InMemoryThread = class {
|
|
|
60
59
|
this.userThreadIndex.set(userId, /* @__PURE__ */ new Set());
|
|
61
60
|
}
|
|
62
61
|
if (!this.threads.has(key)) {
|
|
63
|
-
this.threads.set(key, { type, title, messages:
|
|
62
|
+
this.threads.set(key, { type, title, messages: [] });
|
|
64
63
|
const metadata = {
|
|
65
64
|
type,
|
|
66
65
|
threadId,
|
|
@@ -76,8 +75,7 @@ var InMemoryThread = class {
|
|
|
76
75
|
const key = this.generateKey(userId, threadId);
|
|
77
76
|
const thread = this.threads.get(key);
|
|
78
77
|
for (const message of messages) {
|
|
79
|
-
|
|
80
|
-
thread?.messages.set(newMessageId, message);
|
|
78
|
+
thread?.messages.push(message);
|
|
81
79
|
}
|
|
82
80
|
}
|
|
83
81
|
async deleteThread(userId, threadId) {
|
|
@@ -95,7 +93,7 @@ var InMemoryThread = class {
|
|
|
95
93
|
};
|
|
96
94
|
|
|
97
95
|
// implements/intent.memory.ts
|
|
98
|
-
var
|
|
96
|
+
var import_node_crypto = require("crypto");
|
|
99
97
|
var InMemoryIntent = class {
|
|
100
98
|
intents = /* @__PURE__ */ new Map();
|
|
101
99
|
async connect() {
|
|
@@ -112,7 +110,7 @@ var InMemoryIntent = class {
|
|
|
112
110
|
return Array.from(this.intents.values()).find((intent) => intent.name === intentName);
|
|
113
111
|
}
|
|
114
112
|
async saveIntent(intent) {
|
|
115
|
-
const newId = (0,
|
|
113
|
+
const newId = (0, import_node_crypto.randomUUID)();
|
|
116
114
|
this.intents.set(newId, intent);
|
|
117
115
|
}
|
|
118
116
|
async updateIntent(intentId, intent) {
|
package/dist/index.cjs.map
CHANGED
|
@@ -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
|
|
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;A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AA,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,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":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -4,7 +4,7 @@ import { IThreadMemory, IIntentMemory } from '@ainetwork/adk/modules';
|
|
|
4
4
|
type InMemoryThreadObject = {
|
|
5
5
|
type: ThreadType;
|
|
6
6
|
title: string;
|
|
7
|
-
messages:
|
|
7
|
+
messages: Array<MessageObject>;
|
|
8
8
|
};
|
|
9
9
|
type InMemoryThreadMetadata = {
|
|
10
10
|
type: ThreadType;
|
|
@@ -20,7 +20,7 @@ declare class InMemoryThread implements IThreadMemory {
|
|
|
20
20
|
disconnect(): Promise<void>;
|
|
21
21
|
isConnected(): boolean;
|
|
22
22
|
private generateKey;
|
|
23
|
-
getThread(
|
|
23
|
+
getThread(userId: string, threadId: string): Promise<ThreadObject | undefined>;
|
|
24
24
|
createThread(type: ThreadType, userId: string, threadId: string, title: string): Promise<ThreadMetadata>;
|
|
25
25
|
addMessagesToThread(userId: string, threadId: string, messages: MessageObject[]): Promise<void>;
|
|
26
26
|
deleteThread(userId: string, threadId: string): Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { IThreadMemory, IIntentMemory } from '@ainetwork/adk/modules';
|
|
|
4
4
|
type InMemoryThreadObject = {
|
|
5
5
|
type: ThreadType;
|
|
6
6
|
title: string;
|
|
7
|
-
messages:
|
|
7
|
+
messages: Array<MessageObject>;
|
|
8
8
|
};
|
|
9
9
|
type InMemoryThreadMetadata = {
|
|
10
10
|
type: ThreadType;
|
|
@@ -20,7 +20,7 @@ declare class InMemoryThread implements IThreadMemory {
|
|
|
20
20
|
disconnect(): Promise<void>;
|
|
21
21
|
isConnected(): boolean;
|
|
22
22
|
private generateKey;
|
|
23
|
-
getThread(
|
|
23
|
+
getThread(userId: string, threadId: string): Promise<ThreadObject | undefined>;
|
|
24
24
|
createThread(type: ThreadType, userId: string, threadId: string, title: string): Promise<ThreadMetadata>;
|
|
25
25
|
addMessagesToThread(userId: string, threadId: string, messages: MessageObject[]): Promise<void>;
|
|
26
26
|
deleteThread(userId: string, threadId: string): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// implements/thread.memory.ts
|
|
2
|
-
import { randomUUID } from "crypto";
|
|
3
2
|
var InMemoryThread = class {
|
|
4
3
|
threads = /* @__PURE__ */ new Map();
|
|
5
4
|
userThreadIndex = /* @__PURE__ */ new Map();
|
|
@@ -13,14 +12,14 @@ var InMemoryThread = class {
|
|
|
13
12
|
generateKey(userId, threadId) {
|
|
14
13
|
return `${userId}:${threadId}`;
|
|
15
14
|
}
|
|
16
|
-
async getThread(
|
|
15
|
+
async getThread(userId, threadId) {
|
|
17
16
|
const key = this.generateKey(userId, threadId);
|
|
18
17
|
const res = this.threads.get(key);
|
|
19
18
|
if (res) {
|
|
20
19
|
const threadObject = {
|
|
21
20
|
type: res.type,
|
|
22
21
|
title: res.title,
|
|
23
|
-
messages:
|
|
22
|
+
messages: res.messages
|
|
24
23
|
};
|
|
25
24
|
return threadObject;
|
|
26
25
|
}
|
|
@@ -33,7 +32,7 @@ var InMemoryThread = class {
|
|
|
33
32
|
this.userThreadIndex.set(userId, /* @__PURE__ */ new Set());
|
|
34
33
|
}
|
|
35
34
|
if (!this.threads.has(key)) {
|
|
36
|
-
this.threads.set(key, { type, title, messages:
|
|
35
|
+
this.threads.set(key, { type, title, messages: [] });
|
|
37
36
|
const metadata = {
|
|
38
37
|
type,
|
|
39
38
|
threadId,
|
|
@@ -49,8 +48,7 @@ var InMemoryThread = class {
|
|
|
49
48
|
const key = this.generateKey(userId, threadId);
|
|
50
49
|
const thread = this.threads.get(key);
|
|
51
50
|
for (const message of messages) {
|
|
52
|
-
|
|
53
|
-
thread?.messages.set(newMessageId, message);
|
|
51
|
+
thread?.messages.push(message);
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
54
|
async deleteThread(userId, threadId) {
|
|
@@ -68,7 +66,7 @@ var InMemoryThread = class {
|
|
|
68
66
|
};
|
|
69
67
|
|
|
70
68
|
// implements/intent.memory.ts
|
|
71
|
-
import { randomUUID
|
|
69
|
+
import { randomUUID } from "crypto";
|
|
72
70
|
var InMemoryIntent = class {
|
|
73
71
|
intents = /* @__PURE__ */ new Map();
|
|
74
72
|
async connect() {
|
|
@@ -85,7 +83,7 @@ var InMemoryIntent = class {
|
|
|
85
83
|
return Array.from(this.intents.values()).find((intent) => intent.name === intentName);
|
|
86
84
|
}
|
|
87
85
|
async saveIntent(intent) {
|
|
88
|
-
const newId =
|
|
86
|
+
const newId = randomUUID();
|
|
89
87
|
this.intents.set(newId, intent);
|
|
90
88
|
}
|
|
91
89
|
async updateIntent(intentId, intent) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../implements/thread.memory.ts","../implements/intent.memory.ts"],"sourcesContent":["import
|
|
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<Intent[]> {\n return Array.from(this.intents.values());\n };\n}"],"mappings":";AAiBO,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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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":[]}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
1
|
import type { MessageObject, ThreadObject, ThreadMetadata, ThreadType } from "@ainetwork/adk/types/memory";
|
|
3
2
|
import { IThreadMemory } from "@ainetwork/adk/modules";
|
|
4
3
|
|
|
5
4
|
type InMemoryThreadObject = {
|
|
6
5
|
type: ThreadType;
|
|
7
6
|
title: string;
|
|
8
|
-
messages:
|
|
7
|
+
messages: Array<MessageObject>;
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
type InMemoryThreadMetadata = {
|
|
@@ -31,7 +30,6 @@ export class InMemoryThread implements IThreadMemory {
|
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
public async getThread(
|
|
34
|
-
type: ThreadType,
|
|
35
33
|
userId: string,
|
|
36
34
|
threadId: string
|
|
37
35
|
): Promise<ThreadObject | undefined> {
|
|
@@ -41,7 +39,7 @@ export class InMemoryThread implements IThreadMemory {
|
|
|
41
39
|
const threadObject: ThreadObject = {
|
|
42
40
|
type: res.type,
|
|
43
41
|
title: res.title,
|
|
44
|
-
messages:
|
|
42
|
+
messages: res.messages,
|
|
45
43
|
};
|
|
46
44
|
return threadObject;
|
|
47
45
|
}
|
|
@@ -60,7 +58,7 @@ export class InMemoryThread implements IThreadMemory {
|
|
|
60
58
|
this.userThreadIndex.set(userId, new Set());
|
|
61
59
|
}
|
|
62
60
|
if (!this.threads.has(key)) {
|
|
63
|
-
this.threads.set(key, { type, title, messages:
|
|
61
|
+
this.threads.set(key, { type, title, messages: [] });
|
|
64
62
|
const metadata: InMemoryThreadMetadata = {
|
|
65
63
|
type, threadId, title, createdAt: now, updatedAt: now,
|
|
66
64
|
}
|
|
@@ -78,8 +76,7 @@ export class InMemoryThread implements IThreadMemory {
|
|
|
78
76
|
const key = this.generateKey(userId, threadId);
|
|
79
77
|
const thread = this.threads.get(key);
|
|
80
78
|
for (const message of messages) {
|
|
81
|
-
|
|
82
|
-
thread?.messages.set(newMessageId, message);
|
|
79
|
+
thread?.messages.push(message);
|
|
83
80
|
}
|
|
84
81
|
};
|
|
85
82
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ainetwork/adk-provider-memory-inmemory",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.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.2.
|
|
24
|
+
"@ainetwork/adk": "^0.2.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": "65f5c77dad2ba16ee695a88f9b1b3ca2a5a886a3"
|
|
34
34
|
}
|