@ainetwork/adk-provider-memory-inmemory 0.2.0 → 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 +9 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +9 -11
- package/dist/index.js.map +1 -1
- package/implements/thread.memory.ts +11 -13
- 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();
|
|
@@ -45,9 +44,11 @@ var InMemoryThread = class {
|
|
|
45
44
|
const res = this.threads.get(key);
|
|
46
45
|
if (res) {
|
|
47
46
|
const threadObject = {
|
|
47
|
+
threadId,
|
|
48
|
+
userId,
|
|
48
49
|
type: res.type,
|
|
49
50
|
title: res.title,
|
|
50
|
-
messages:
|
|
51
|
+
messages: res.messages
|
|
51
52
|
};
|
|
52
53
|
return threadObject;
|
|
53
54
|
}
|
|
@@ -60,9 +61,10 @@ var InMemoryThread = class {
|
|
|
60
61
|
this.userThreadIndex.set(userId, /* @__PURE__ */ new Set());
|
|
61
62
|
}
|
|
62
63
|
if (!this.threads.has(key)) {
|
|
63
|
-
this.threads.set(key, { type, title, messages:
|
|
64
|
+
this.threads.set(key, { type, title, messages: [] });
|
|
64
65
|
const metadata = {
|
|
65
66
|
type,
|
|
67
|
+
userId,
|
|
66
68
|
threadId,
|
|
67
69
|
title,
|
|
68
70
|
createdAt: now,
|
|
@@ -70,18 +72,14 @@ var InMemoryThread = class {
|
|
|
70
72
|
};
|
|
71
73
|
this.userThreadIndex.get(userId)?.add(metadata);
|
|
72
74
|
}
|
|
73
|
-
return { type, title, threadId,
|
|
75
|
+
return { type, title, threadId, userId, messages: [] };
|
|
74
76
|
}
|
|
75
77
|
async addMessagesToThread(userId, threadId, messages) {
|
|
76
78
|
const key = this.generateKey(userId, threadId);
|
|
77
79
|
const thread = this.threads.get(key);
|
|
78
|
-
const messageIds = [];
|
|
79
80
|
for (const message of messages) {
|
|
80
|
-
|
|
81
|
-
thread?.messages.set(newMessageId, message);
|
|
82
|
-
messageIds.push(newMessageId);
|
|
81
|
+
thread?.messages.push(message);
|
|
83
82
|
}
|
|
84
|
-
return messageIds;
|
|
85
83
|
}
|
|
86
84
|
async deleteThread(userId, threadId) {
|
|
87
85
|
const key = this.generateKey(userId, threadId);
|
|
@@ -98,7 +96,7 @@ var InMemoryThread = class {
|
|
|
98
96
|
};
|
|
99
97
|
|
|
100
98
|
// implements/intent.memory.ts
|
|
101
|
-
var
|
|
99
|
+
var import_node_crypto = require("crypto");
|
|
102
100
|
var InMemoryIntent = class {
|
|
103
101
|
intents = /* @__PURE__ */ new Map();
|
|
104
102
|
async connect() {
|
|
@@ -115,7 +113,7 @@ var InMemoryIntent = class {
|
|
|
115
113
|
return Array.from(this.intents.values()).find((intent) => intent.name === intentName);
|
|
116
114
|
}
|
|
117
115
|
async saveIntent(intent) {
|
|
118
|
-
const newId = (0,
|
|
116
|
+
const newId = (0, import_node_crypto.randomUUID)();
|
|
119
117
|
this.intents.set(newId, intent);
|
|
120
118
|
}
|
|
121
119
|
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 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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACkBO,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;A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;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,yBAA2B;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,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,10 +4,11 @@ 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;
|
|
11
|
+
userId: string;
|
|
11
12
|
threadId: string;
|
|
12
13
|
title: string;
|
|
13
14
|
updatedAt: number;
|
|
@@ -21,8 +22,8 @@ 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<
|
|
25
|
-
addMessagesToThread(userId: string, threadId: string, messages: MessageObject[]): Promise<
|
|
25
|
+
createThread(type: ThreadType, userId: string, threadId: string, title: string): Promise<ThreadObject>;
|
|
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[]>;
|
|
28
29
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,10 +4,11 @@ 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;
|
|
11
|
+
userId: string;
|
|
11
12
|
threadId: string;
|
|
12
13
|
title: string;
|
|
13
14
|
updatedAt: number;
|
|
@@ -21,8 +22,8 @@ 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<
|
|
25
|
-
addMessagesToThread(userId: string, threadId: string, messages: MessageObject[]): Promise<
|
|
25
|
+
createThread(type: ThreadType, userId: string, threadId: string, title: string): Promise<ThreadObject>;
|
|
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[]>;
|
|
28
29
|
}
|
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();
|
|
@@ -18,9 +17,11 @@ var InMemoryThread = class {
|
|
|
18
17
|
const res = this.threads.get(key);
|
|
19
18
|
if (res) {
|
|
20
19
|
const threadObject = {
|
|
20
|
+
threadId,
|
|
21
|
+
userId,
|
|
21
22
|
type: res.type,
|
|
22
23
|
title: res.title,
|
|
23
|
-
messages:
|
|
24
|
+
messages: res.messages
|
|
24
25
|
};
|
|
25
26
|
return threadObject;
|
|
26
27
|
}
|
|
@@ -33,9 +34,10 @@ var InMemoryThread = class {
|
|
|
33
34
|
this.userThreadIndex.set(userId, /* @__PURE__ */ new Set());
|
|
34
35
|
}
|
|
35
36
|
if (!this.threads.has(key)) {
|
|
36
|
-
this.threads.set(key, { type, title, messages:
|
|
37
|
+
this.threads.set(key, { type, title, messages: [] });
|
|
37
38
|
const metadata = {
|
|
38
39
|
type,
|
|
40
|
+
userId,
|
|
39
41
|
threadId,
|
|
40
42
|
title,
|
|
41
43
|
createdAt: now,
|
|
@@ -43,18 +45,14 @@ var InMemoryThread = class {
|
|
|
43
45
|
};
|
|
44
46
|
this.userThreadIndex.get(userId)?.add(metadata);
|
|
45
47
|
}
|
|
46
|
-
return { type, title, threadId,
|
|
48
|
+
return { type, title, threadId, userId, messages: [] };
|
|
47
49
|
}
|
|
48
50
|
async addMessagesToThread(userId, threadId, messages) {
|
|
49
51
|
const key = this.generateKey(userId, threadId);
|
|
50
52
|
const thread = this.threads.get(key);
|
|
51
|
-
const messageIds = [];
|
|
52
53
|
for (const message of messages) {
|
|
53
|
-
|
|
54
|
-
thread?.messages.set(newMessageId, message);
|
|
55
|
-
messageIds.push(newMessageId);
|
|
54
|
+
thread?.messages.push(message);
|
|
56
55
|
}
|
|
57
|
-
return messageIds;
|
|
58
56
|
}
|
|
59
57
|
async deleteThread(userId, threadId) {
|
|
60
58
|
const key = this.generateKey(userId, threadId);
|
|
@@ -71,7 +69,7 @@ var InMemoryThread = class {
|
|
|
71
69
|
};
|
|
72
70
|
|
|
73
71
|
// implements/intent.memory.ts
|
|
74
|
-
import { randomUUID
|
|
72
|
+
import { randomUUID } from "crypto";
|
|
75
73
|
var InMemoryIntent = class {
|
|
76
74
|
intents = /* @__PURE__ */ new Map();
|
|
77
75
|
async connect() {
|
|
@@ -88,7 +86,7 @@ var InMemoryIntent = class {
|
|
|
88
86
|
return Array.from(this.intents.values()).find((intent) => intent.name === intentName);
|
|
89
87
|
}
|
|
90
88
|
async saveIntent(intent) {
|
|
91
|
-
const newId =
|
|
89
|
+
const newId = randomUUID();
|
|
92
90
|
this.intents.set(newId, intent);
|
|
93
91
|
}
|
|
94
92
|
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 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,YAAY,QAAQ,QAAQ;AAC7C,UAAM,MAAM,KAAK,QAAQ,IAAI,GAAG;AAChC,QAAI,KAAK;AACP,YAAM,eAA6B;AAAA,QACjC;AAAA,QACA;AAAA,QACA,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,OACuB;AACvB,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,IA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D;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,15 +1,15 @@
|
|
|
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 = {
|
|
12
11
|
type: ThreadType;
|
|
12
|
+
userId: string;
|
|
13
13
|
threadId: string;
|
|
14
14
|
title: string;
|
|
15
15
|
updatedAt: number;
|
|
@@ -38,9 +38,11 @@ export class InMemoryThread implements IThreadMemory {
|
|
|
38
38
|
const res = this.threads.get(key);
|
|
39
39
|
if (res) {
|
|
40
40
|
const threadObject: ThreadObject = {
|
|
41
|
+
threadId,
|
|
42
|
+
userId,
|
|
41
43
|
type: res.type,
|
|
42
44
|
title: res.title,
|
|
43
|
-
messages:
|
|
45
|
+
messages: res.messages,
|
|
44
46
|
};
|
|
45
47
|
return threadObject;
|
|
46
48
|
}
|
|
@@ -52,37 +54,33 @@ export class InMemoryThread implements IThreadMemory {
|
|
|
52
54
|
userId: string,
|
|
53
55
|
threadId: string,
|
|
54
56
|
title: string
|
|
55
|
-
): Promise<
|
|
57
|
+
): Promise<ThreadObject> {
|
|
56
58
|
const now = Date.now();
|
|
57
59
|
const key = this.generateKey(userId, threadId);
|
|
58
60
|
if (!this.userThreadIndex.has(userId)) {
|
|
59
61
|
this.userThreadIndex.set(userId, new Set());
|
|
60
62
|
}
|
|
61
63
|
if (!this.threads.has(key)) {
|
|
62
|
-
this.threads.set(key, { type, title, messages:
|
|
64
|
+
this.threads.set(key, { type, title, messages: [] });
|
|
63
65
|
const metadata: InMemoryThreadMetadata = {
|
|
64
|
-
type, threadId, title, createdAt: now, updatedAt: now,
|
|
66
|
+
type, userId, threadId, title, createdAt: now, updatedAt: now,
|
|
65
67
|
}
|
|
66
68
|
this.userThreadIndex.get(userId)?.add(metadata);
|
|
67
69
|
}
|
|
68
70
|
|
|
69
|
-
return { type, title, threadId,
|
|
71
|
+
return { type, title, threadId, userId, messages: [] };
|
|
70
72
|
};
|
|
71
73
|
|
|
72
74
|
public async addMessagesToThread(
|
|
73
75
|
userId: string,
|
|
74
76
|
threadId: string,
|
|
75
77
|
messages: MessageObject[]
|
|
76
|
-
): Promise<
|
|
78
|
+
): Promise<void> {
|
|
77
79
|
const key = this.generateKey(userId, threadId);
|
|
78
80
|
const thread = this.threads.get(key);
|
|
79
|
-
const messageIds: string[] = [];
|
|
80
81
|
for (const message of messages) {
|
|
81
|
-
|
|
82
|
-
thread?.messages.set(newMessageId, message);
|
|
83
|
-
messageIds.push(newMessageId);
|
|
82
|
+
thread?.messages.push(message);
|
|
84
83
|
}
|
|
85
|
-
return messageIds;
|
|
86
84
|
};
|
|
87
85
|
|
|
88
86
|
public async deleteThread(userId: string, threadId: string): Promise<void> {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ainetwork/adk-provider-memory-inmemory",
|
|
3
|
-
"version": "0.2.
|
|
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.
|
|
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": "
|
|
33
|
+
"gitHead": "e0021453227b0c9c0cd1d21efa0395e8e1f6740e"
|
|
34
34
|
}
|