@ainetwork/adk-provider-memory-inmemory 0.1.5 → 0.1.7
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 +46 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -17
- package/dist/index.d.ts +20 -17
- package/dist/index.js +45 -38
- package/dist/index.js.map +1 -1
- package/implements/intent.memory.ts +4 -0
- package/implements/thread.memory.ts +99 -0
- package/index.ts +1 -1
- package/package.json +3 -3
- package/implements/session.memory.ts +0 -81
package/dist/index.cjs
CHANGED
|
@@ -21,15 +21,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
InMemoryIntent: () => InMemoryIntent,
|
|
24
|
-
|
|
24
|
+
InMemoryThread: () => InMemoryThread
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(index_exports);
|
|
27
27
|
|
|
28
|
-
// implements/
|
|
28
|
+
// implements/thread.memory.ts
|
|
29
29
|
var import_node_crypto = require("crypto");
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
var InMemoryThread = class {
|
|
31
|
+
threads = /* @__PURE__ */ new Map();
|
|
32
|
+
userThreadIndex = /* @__PURE__ */ new Map();
|
|
33
33
|
async connect() {
|
|
34
34
|
}
|
|
35
35
|
async disconnect() {
|
|
@@ -37,54 +37,58 @@ var InMemorySession = class {
|
|
|
37
37
|
isConnected() {
|
|
38
38
|
return true;
|
|
39
39
|
}
|
|
40
|
-
generateKey(userId,
|
|
41
|
-
return `${userId}:${
|
|
40
|
+
generateKey(userId, threadId) {
|
|
41
|
+
return `${userId}:${threadId}`;
|
|
42
42
|
}
|
|
43
|
-
async
|
|
44
|
-
const key = this.generateKey(userId,
|
|
45
|
-
const res = this.
|
|
43
|
+
async getThread(type, userId, threadId) {
|
|
44
|
+
const key = this.generateKey(userId, threadId);
|
|
45
|
+
const res = this.threads.get(key);
|
|
46
46
|
if (res) {
|
|
47
|
-
const
|
|
47
|
+
const threadObject = {
|
|
48
|
+
type: res.type,
|
|
48
49
|
title: res.title,
|
|
49
|
-
|
|
50
|
+
messages: Object.fromEntries(res.messages)
|
|
50
51
|
};
|
|
51
|
-
return
|
|
52
|
+
return threadObject;
|
|
52
53
|
}
|
|
53
54
|
return void 0;
|
|
54
55
|
}
|
|
55
|
-
async
|
|
56
|
+
async createThread(type, userId, threadId, title) {
|
|
56
57
|
const now = Date.now();
|
|
57
|
-
const key = this.generateKey(userId,
|
|
58
|
-
if (!this.
|
|
59
|
-
this.
|
|
58
|
+
const key = this.generateKey(userId, threadId);
|
|
59
|
+
if (!this.userThreadIndex.has(userId)) {
|
|
60
|
+
this.userThreadIndex.set(userId, /* @__PURE__ */ new Set());
|
|
60
61
|
}
|
|
61
|
-
if (!this.
|
|
62
|
-
this.
|
|
62
|
+
if (!this.threads.has(key)) {
|
|
63
|
+
this.threads.set(key, { type, title, messages: /* @__PURE__ */ new Map() });
|
|
63
64
|
const metadata = {
|
|
64
|
-
|
|
65
|
+
type,
|
|
66
|
+
threadId,
|
|
65
67
|
title,
|
|
66
68
|
createdAt: now,
|
|
67
69
|
updatedAt: now
|
|
68
70
|
};
|
|
69
|
-
this.
|
|
71
|
+
this.userThreadIndex.get(userId)?.add(metadata);
|
|
70
72
|
}
|
|
71
|
-
return { title,
|
|
72
|
-
}
|
|
73
|
-
async
|
|
74
|
-
const key = this.generateKey(userId,
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
this.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
73
|
+
return { type, title, threadId, updatedAt: now };
|
|
74
|
+
}
|
|
75
|
+
async addMessagesToThread(userId, threadId, messages) {
|
|
76
|
+
const key = this.generateKey(userId, threadId);
|
|
77
|
+
const thread = this.threads.get(key);
|
|
78
|
+
for (const message of messages) {
|
|
79
|
+
const newMessageId = (0, import_node_crypto.randomUUID)();
|
|
80
|
+
thread?.messages.set(newMessageId, message);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async deleteThread(userId, threadId) {
|
|
84
|
+
const key = this.generateKey(userId, threadId);
|
|
85
|
+
this.threads.delete(key);
|
|
86
|
+
this.userThreadIndex.delete(threadId);
|
|
87
|
+
}
|
|
88
|
+
async listThreads(userId) {
|
|
89
|
+
const threads = this.userThreadIndex.get(userId);
|
|
90
|
+
if (threads) {
|
|
91
|
+
return Array.from(threads);
|
|
88
92
|
}
|
|
89
93
|
return [];
|
|
90
94
|
}
|
|
@@ -104,6 +108,9 @@ var InMemoryIntent = class {
|
|
|
104
108
|
async getIntent(intentId) {
|
|
105
109
|
return this.intents.get(intentId);
|
|
106
110
|
}
|
|
111
|
+
async getIntentByName(intentName) {
|
|
112
|
+
return Array.from(this.intents.values()).find((intent) => intent.name === intentName);
|
|
113
|
+
}
|
|
107
114
|
async saveIntent(intent) {
|
|
108
115
|
const newId = (0, import_node_crypto2.randomUUID)();
|
|
109
116
|
this.intents.set(newId, intent);
|
|
@@ -121,6 +128,6 @@ var InMemoryIntent = class {
|
|
|
121
128
|
// Annotate the CommonJS export names for ESM import in node:
|
|
122
129
|
0 && (module.exports = {
|
|
123
130
|
InMemoryIntent,
|
|
124
|
-
|
|
131
|
+
InMemoryThread
|
|
125
132
|
});
|
|
126
133
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../index.ts","../implements/
|
|
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 { randomUUID } from \"node:crypto\";\nimport 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: Map<string, 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 type: ThreadType,\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: Object.fromEntries(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: new Map() });\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 const newMessageId = randomUUID();\n thread?.messages.set(newMessageId, 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":"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","names":["import_node_crypto"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,28 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ThreadType, MessageObject, ThreadObject, ThreadMetadata, Intent } from '@ainetwork/adk/types/memory';
|
|
2
|
+
import { IThreadMemory, IIntentMemory } from '@ainetwork/adk/modules';
|
|
3
3
|
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
type InMemoryThreadObject = {
|
|
5
|
+
type: ThreadType;
|
|
6
|
+
title: string;
|
|
7
|
+
messages: Map<string, MessageObject>;
|
|
7
8
|
};
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
type InMemoryThreadMetadata = {
|
|
10
|
+
type: ThreadType;
|
|
11
|
+
threadId: string;
|
|
12
|
+
title: string;
|
|
11
13
|
updatedAt: number;
|
|
12
14
|
createdAt: number;
|
|
13
15
|
};
|
|
14
|
-
declare class
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
declare class InMemoryThread implements IThreadMemory {
|
|
17
|
+
threads: Map<string, InMemoryThreadObject>;
|
|
18
|
+
userThreadIndex: Map<string, Set<InMemoryThreadMetadata>>;
|
|
17
19
|
connect(): Promise<void>;
|
|
18
20
|
disconnect(): Promise<void>;
|
|
19
21
|
isConnected(): boolean;
|
|
20
22
|
private generateKey;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
getThread(type: ThreadType, userId: string, threadId: string): Promise<ThreadObject | undefined>;
|
|
24
|
+
createThread(type: ThreadType, userId: string, threadId: string, title: string): Promise<ThreadMetadata>;
|
|
25
|
+
addMessagesToThread(userId: string, threadId: string, messages: MessageObject[]): Promise<void>;
|
|
26
|
+
deleteThread(userId: string, threadId: string): Promise<void>;
|
|
27
|
+
listThreads(userId: string): Promise<ThreadMetadata[]>;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
declare class InMemoryIntent implements IIntentMemory {
|
|
@@ -31,10 +33,11 @@ declare class InMemoryIntent implements IIntentMemory {
|
|
|
31
33
|
disconnect(): Promise<void>;
|
|
32
34
|
isConnected(): boolean;
|
|
33
35
|
getIntent(intentId: string): Promise<Intent | undefined>;
|
|
36
|
+
getIntentByName(intentName: string): Promise<Intent | undefined>;
|
|
34
37
|
saveIntent(intent: Intent): Promise<void>;
|
|
35
38
|
updateIntent(intentId: string, intent: Intent): Promise<void>;
|
|
36
39
|
deleteIntent(intentId: string): Promise<void>;
|
|
37
40
|
listIntents(): Promise<Intent[]>;
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
export { InMemoryIntent,
|
|
43
|
+
export { InMemoryIntent, InMemoryThread };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,28 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ThreadType, MessageObject, ThreadObject, ThreadMetadata, Intent } from '@ainetwork/adk/types/memory';
|
|
2
|
+
import { IThreadMemory, IIntentMemory } from '@ainetwork/adk/modules';
|
|
3
3
|
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
type InMemoryThreadObject = {
|
|
5
|
+
type: ThreadType;
|
|
6
|
+
title: string;
|
|
7
|
+
messages: Map<string, MessageObject>;
|
|
7
8
|
};
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
type InMemoryThreadMetadata = {
|
|
10
|
+
type: ThreadType;
|
|
11
|
+
threadId: string;
|
|
12
|
+
title: string;
|
|
11
13
|
updatedAt: number;
|
|
12
14
|
createdAt: number;
|
|
13
15
|
};
|
|
14
|
-
declare class
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
declare class InMemoryThread implements IThreadMemory {
|
|
17
|
+
threads: Map<string, InMemoryThreadObject>;
|
|
18
|
+
userThreadIndex: Map<string, Set<InMemoryThreadMetadata>>;
|
|
17
19
|
connect(): Promise<void>;
|
|
18
20
|
disconnect(): Promise<void>;
|
|
19
21
|
isConnected(): boolean;
|
|
20
22
|
private generateKey;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
getThread(type: ThreadType, userId: string, threadId: string): Promise<ThreadObject | undefined>;
|
|
24
|
+
createThread(type: ThreadType, userId: string, threadId: string, title: string): Promise<ThreadMetadata>;
|
|
25
|
+
addMessagesToThread(userId: string, threadId: string, messages: MessageObject[]): Promise<void>;
|
|
26
|
+
deleteThread(userId: string, threadId: string): Promise<void>;
|
|
27
|
+
listThreads(userId: string): Promise<ThreadMetadata[]>;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
declare class InMemoryIntent implements IIntentMemory {
|
|
@@ -31,10 +33,11 @@ declare class InMemoryIntent implements IIntentMemory {
|
|
|
31
33
|
disconnect(): Promise<void>;
|
|
32
34
|
isConnected(): boolean;
|
|
33
35
|
getIntent(intentId: string): Promise<Intent | undefined>;
|
|
36
|
+
getIntentByName(intentName: string): Promise<Intent | undefined>;
|
|
34
37
|
saveIntent(intent: Intent): Promise<void>;
|
|
35
38
|
updateIntent(intentId: string, intent: Intent): Promise<void>;
|
|
36
39
|
deleteIntent(intentId: string): Promise<void>;
|
|
37
40
|
listIntents(): Promise<Intent[]>;
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
export { InMemoryIntent,
|
|
43
|
+
export { InMemoryIntent, InMemoryThread };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
// implements/
|
|
1
|
+
// implements/thread.memory.ts
|
|
2
2
|
import { randomUUID } from "crypto";
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
var InMemoryThread = class {
|
|
4
|
+
threads = /* @__PURE__ */ new Map();
|
|
5
|
+
userThreadIndex = /* @__PURE__ */ new Map();
|
|
6
6
|
async connect() {
|
|
7
7
|
}
|
|
8
8
|
async disconnect() {
|
|
@@ -10,54 +10,58 @@ var InMemorySession = class {
|
|
|
10
10
|
isConnected() {
|
|
11
11
|
return true;
|
|
12
12
|
}
|
|
13
|
-
generateKey(userId,
|
|
14
|
-
return `${userId}:${
|
|
13
|
+
generateKey(userId, threadId) {
|
|
14
|
+
return `${userId}:${threadId}`;
|
|
15
15
|
}
|
|
16
|
-
async
|
|
17
|
-
const key = this.generateKey(userId,
|
|
18
|
-
const res = this.
|
|
16
|
+
async getThread(type, userId, threadId) {
|
|
17
|
+
const key = this.generateKey(userId, threadId);
|
|
18
|
+
const res = this.threads.get(key);
|
|
19
19
|
if (res) {
|
|
20
|
-
const
|
|
20
|
+
const threadObject = {
|
|
21
|
+
type: res.type,
|
|
21
22
|
title: res.title,
|
|
22
|
-
|
|
23
|
+
messages: Object.fromEntries(res.messages)
|
|
23
24
|
};
|
|
24
|
-
return
|
|
25
|
+
return threadObject;
|
|
25
26
|
}
|
|
26
27
|
return void 0;
|
|
27
28
|
}
|
|
28
|
-
async
|
|
29
|
+
async createThread(type, userId, threadId, title) {
|
|
29
30
|
const now = Date.now();
|
|
30
|
-
const key = this.generateKey(userId,
|
|
31
|
-
if (!this.
|
|
32
|
-
this.
|
|
31
|
+
const key = this.generateKey(userId, threadId);
|
|
32
|
+
if (!this.userThreadIndex.has(userId)) {
|
|
33
|
+
this.userThreadIndex.set(userId, /* @__PURE__ */ new Set());
|
|
33
34
|
}
|
|
34
|
-
if (!this.
|
|
35
|
-
this.
|
|
35
|
+
if (!this.threads.has(key)) {
|
|
36
|
+
this.threads.set(key, { type, title, messages: /* @__PURE__ */ new Map() });
|
|
36
37
|
const metadata = {
|
|
37
|
-
|
|
38
|
+
type,
|
|
39
|
+
threadId,
|
|
38
40
|
title,
|
|
39
41
|
createdAt: now,
|
|
40
42
|
updatedAt: now
|
|
41
43
|
};
|
|
42
|
-
this.
|
|
44
|
+
this.userThreadIndex.get(userId)?.add(metadata);
|
|
43
45
|
}
|
|
44
|
-
return { title,
|
|
45
|
-
}
|
|
46
|
-
async
|
|
47
|
-
const key = this.generateKey(userId,
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
46
|
+
return { type, title, threadId, updatedAt: now };
|
|
47
|
+
}
|
|
48
|
+
async addMessagesToThread(userId, threadId, messages) {
|
|
49
|
+
const key = this.generateKey(userId, threadId);
|
|
50
|
+
const thread = this.threads.get(key);
|
|
51
|
+
for (const message of messages) {
|
|
52
|
+
const newMessageId = randomUUID();
|
|
53
|
+
thread?.messages.set(newMessageId, message);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async deleteThread(userId, threadId) {
|
|
57
|
+
const key = this.generateKey(userId, threadId);
|
|
58
|
+
this.threads.delete(key);
|
|
59
|
+
this.userThreadIndex.delete(threadId);
|
|
60
|
+
}
|
|
61
|
+
async listThreads(userId) {
|
|
62
|
+
const threads = this.userThreadIndex.get(userId);
|
|
63
|
+
if (threads) {
|
|
64
|
+
return Array.from(threads);
|
|
61
65
|
}
|
|
62
66
|
return [];
|
|
63
67
|
}
|
|
@@ -77,6 +81,9 @@ var InMemoryIntent = class {
|
|
|
77
81
|
async getIntent(intentId) {
|
|
78
82
|
return this.intents.get(intentId);
|
|
79
83
|
}
|
|
84
|
+
async getIntentByName(intentName) {
|
|
85
|
+
return Array.from(this.intents.values()).find((intent) => intent.name === intentName);
|
|
86
|
+
}
|
|
80
87
|
async saveIntent(intent) {
|
|
81
88
|
const newId = randomUUID2();
|
|
82
89
|
this.intents.set(newId, intent);
|
|
@@ -93,6 +100,6 @@ var InMemoryIntent = class {
|
|
|
93
100
|
};
|
|
94
101
|
export {
|
|
95
102
|
InMemoryIntent,
|
|
96
|
-
|
|
103
|
+
InMemoryThread
|
|
97
104
|
};
|
|
98
105
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../implements/
|
|
1
|
+
{"version":3,"sources":["../implements/thread.memory.ts","../implements/intent.memory.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport 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: Map<string, 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 type: ThreadType,\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: Object.fromEntries(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: new Map() });\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 const newMessageId = randomUUID();\n thread?.messages.set(newMessageId, 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":"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","names":["randomUUID"]}
|
|
@@ -15,6 +15,10 @@ export class InMemoryIntent implements IIntentMemory {
|
|
|
15
15
|
return this.intents.get(intentId);
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
public async getIntentByName(intentName: string): Promise<Intent | undefined> {
|
|
19
|
+
return Array.from(this.intents.values()).find(intent => intent.name === intentName);
|
|
20
|
+
};
|
|
21
|
+
|
|
18
22
|
public async saveIntent(intent: Intent): Promise<void> {
|
|
19
23
|
const newId = randomUUID();
|
|
20
24
|
this.intents.set(newId, intent);
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import type { MessageObject, ThreadObject, ThreadMetadata, ThreadType } from "@ainetwork/adk/types/memory";
|
|
3
|
+
import { IThreadMemory } from "@ainetwork/adk/modules";
|
|
4
|
+
|
|
5
|
+
type InMemoryThreadObject = {
|
|
6
|
+
type: ThreadType;
|
|
7
|
+
title: string;
|
|
8
|
+
messages: Map<string, MessageObject>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type InMemoryThreadMetadata = {
|
|
12
|
+
type: ThreadType;
|
|
13
|
+
threadId: string;
|
|
14
|
+
title: string;
|
|
15
|
+
updatedAt: number;
|
|
16
|
+
createdAt: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class InMemoryThread implements IThreadMemory {
|
|
20
|
+
public threads: Map<string, InMemoryThreadObject> = new Map();
|
|
21
|
+
public userThreadIndex: Map<string, Set<InMemoryThreadMetadata>> = new Map();
|
|
22
|
+
|
|
23
|
+
public async connect(): Promise<void> {}
|
|
24
|
+
public async disconnect(): Promise<void> {}
|
|
25
|
+
public isConnected(): boolean {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private generateKey(userId: string, threadId: string) {
|
|
30
|
+
return `${userId}:${threadId}`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public async getThread(
|
|
34
|
+
type: ThreadType,
|
|
35
|
+
userId: string,
|
|
36
|
+
threadId: string
|
|
37
|
+
): Promise<ThreadObject | undefined> {
|
|
38
|
+
const key = this.generateKey(userId, threadId);
|
|
39
|
+
const res = this.threads.get(key);
|
|
40
|
+
if (res) {
|
|
41
|
+
const threadObject: ThreadObject = {
|
|
42
|
+
type: res.type,
|
|
43
|
+
title: res.title,
|
|
44
|
+
messages: Object.fromEntries(res.messages)
|
|
45
|
+
};
|
|
46
|
+
return threadObject;
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
public async createThread(
|
|
52
|
+
type: ThreadType,
|
|
53
|
+
userId: string,
|
|
54
|
+
threadId: string,
|
|
55
|
+
title: string
|
|
56
|
+
): Promise<ThreadMetadata> {
|
|
57
|
+
const now = Date.now();
|
|
58
|
+
const key = this.generateKey(userId, threadId);
|
|
59
|
+
if (!this.userThreadIndex.has(userId)) {
|
|
60
|
+
this.userThreadIndex.set(userId, new Set());
|
|
61
|
+
}
|
|
62
|
+
if (!this.threads.has(key)) {
|
|
63
|
+
this.threads.set(key, { type, title, messages: new Map() });
|
|
64
|
+
const metadata: InMemoryThreadMetadata = {
|
|
65
|
+
type, threadId, title, createdAt: now, updatedAt: now,
|
|
66
|
+
}
|
|
67
|
+
this.userThreadIndex.get(userId)?.add(metadata);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return { type, title, threadId, updatedAt: now };
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
public async addMessagesToThread(
|
|
74
|
+
userId: string,
|
|
75
|
+
threadId: string,
|
|
76
|
+
messages: MessageObject[]
|
|
77
|
+
): Promise<void> {
|
|
78
|
+
const key = this.generateKey(userId, threadId);
|
|
79
|
+
const thread = this.threads.get(key);
|
|
80
|
+
for (const message of messages) {
|
|
81
|
+
const newMessageId = randomUUID();
|
|
82
|
+
thread?.messages.set(newMessageId, message);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
public async deleteThread(userId: string, threadId: string): Promise<void> {
|
|
87
|
+
const key = this.generateKey(userId, threadId);
|
|
88
|
+
this.threads.delete(key);
|
|
89
|
+
this.userThreadIndex.delete(threadId);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
public async listThreads(userId: string): Promise<ThreadMetadata[]> {
|
|
93
|
+
const threads = this.userThreadIndex.get(userId);
|
|
94
|
+
if (threads) {
|
|
95
|
+
return Array.from(threads);
|
|
96
|
+
}
|
|
97
|
+
return [];
|
|
98
|
+
};
|
|
99
|
+
}
|
package/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { InMemoryThread } from "./implements/thread.memory";
|
|
2
2
|
export { InMemoryIntent } from "./implements/intent.memory";
|
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.1.7",
|
|
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.
|
|
24
|
+
"@ainetwork/adk": "^0.2.0"
|
|
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": "2c60e4331a05d404f244fd59085710cb4870f599"
|
|
34
34
|
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import type { ChatObject, SessionObject, SessionMetadata } from "@ainetwork/adk/types/memory";
|
|
3
|
-
import { ISessionMemory } from "@ainetwork/adk/modules";
|
|
4
|
-
|
|
5
|
-
type InMemorySessionObject = {
|
|
6
|
-
title?: string;
|
|
7
|
-
chats: Map<string, ChatObject>
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
type InMemorySessionMetadata = {
|
|
11
|
-
sessionId: string;
|
|
12
|
-
title?: string;
|
|
13
|
-
updatedAt: number;
|
|
14
|
-
createdAt: number;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class InMemorySession implements ISessionMemory {
|
|
18
|
-
public sessions: Map<string, InMemorySessionObject> = new Map();
|
|
19
|
-
public userSessionIndex: Map<string, Set<InMemorySessionMetadata>> = new Map();
|
|
20
|
-
|
|
21
|
-
public async connect(): Promise<void> {}
|
|
22
|
-
public async disconnect(): Promise<void> {}
|
|
23
|
-
public isConnected(): boolean {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
private generateKey(userId: string, sessionId: string) {
|
|
28
|
-
return `${userId}:${sessionId}`;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public async getSession(userId: string, sessionId: string): Promise<SessionObject | undefined> {
|
|
32
|
-
const key = this.generateKey(userId, sessionId);
|
|
33
|
-
const res = this.sessions.get(key);
|
|
34
|
-
if (res) {
|
|
35
|
-
const sessionObject: SessionObject = {
|
|
36
|
-
title: res.title,
|
|
37
|
-
chats: Object.fromEntries(res.chats)
|
|
38
|
-
};
|
|
39
|
-
return sessionObject;
|
|
40
|
-
}
|
|
41
|
-
return undefined;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
public async createSession(userId: string, sessionId: string, title: string): Promise<SessionMetadata> {
|
|
45
|
-
const now = Date.now();
|
|
46
|
-
const key = this.generateKey(userId, sessionId);
|
|
47
|
-
if (!this.userSessionIndex.has(userId)) {
|
|
48
|
-
this.userSessionIndex.set(userId, new Set());
|
|
49
|
-
}
|
|
50
|
-
if (!this.sessions.has(key)) {
|
|
51
|
-
this.sessions.set(key, { title, chats: new Map() });
|
|
52
|
-
const metadata: InMemorySessionMetadata = {
|
|
53
|
-
sessionId, title, createdAt: now, updatedAt: now,
|
|
54
|
-
}
|
|
55
|
-
this.userSessionIndex.get(userId)?.add(metadata);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return { title, sessionId, updatedAt: now };
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
public async addChatToSession(userId: string, sessionId: string, chat: ChatObject): Promise<void> {
|
|
62
|
-
const key = this.generateKey(userId, sessionId);
|
|
63
|
-
await this.createSession(userId, sessionId, "New chat");
|
|
64
|
-
const newChatId = randomUUID();
|
|
65
|
-
this.sessions.get(key)?.chats.set(newChatId, chat);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
public async deleteSession(userId: string, sessionId: string): Promise<void> {
|
|
69
|
-
const key = this.generateKey(userId, sessionId);
|
|
70
|
-
this.sessions.delete(key);
|
|
71
|
-
this.userSessionIndex.delete(sessionId);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
public async listSessions(userId: string): Promise<SessionMetadata[]> {
|
|
75
|
-
const sessions = this.userSessionIndex.get(userId);
|
|
76
|
-
if (sessions) {
|
|
77
|
-
return Array.from(sessions);
|
|
78
|
-
}
|
|
79
|
-
return [];
|
|
80
|
-
};
|
|
81
|
-
}
|