@ainetwork/adk-provider-memory-inmemory 0.1.2 → 0.1.4

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
@@ -20,31 +20,105 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
- InMemoryMemory: () => InMemoryMemory
23
+ InMemoryIntent: () => InMemoryIntent,
24
+ InMemorySession: () => InMemorySession
24
25
  });
25
26
  module.exports = __toCommonJS(index_exports);
27
+
28
+ // implements/session.memory.ts
26
29
  var import_node_crypto = require("crypto");
27
- var import_modules = require("@ainetwork/adk/modules");
28
- var InMemoryMemory = class extends import_modules.BaseMemory {
29
- sessionHistory;
30
- constructor() {
31
- super();
32
- this.sessionHistory = /* @__PURE__ */ new Map();
30
+ var InMemorySession = class {
31
+ sessions = /* @__PURE__ */ new Map();
32
+ userSessionIndex = /* @__PURE__ */ new Map();
33
+ async connect() {
34
+ }
35
+ async disconnect() {
36
+ }
37
+ isConnected() {
38
+ return true;
39
+ }
40
+ generateKey(userId, sessionId) {
41
+ return `${userId}:${sessionId}`;
33
42
  }
34
- async getSessionHistory(sessionId) {
35
- return this.sessionHistory.get(sessionId) || { chats: {} };
43
+ async getSession(userId, sessionId) {
44
+ const key = this.generateKey(userId, sessionId);
45
+ const res = this.sessions.get(key);
46
+ if (res) {
47
+ const sessionObject = {
48
+ chats: Object.fromEntries(res.chats)
49
+ };
50
+ return sessionObject;
51
+ }
52
+ return void 0;
36
53
  }
37
- async updateSessionHistory(sessionId, chat) {
54
+ async createSession(userId, sessionId, title) {
55
+ const now = Date.now();
56
+ const key = this.generateKey(userId, sessionId);
57
+ if (!this.userSessionIndex.has(userId)) {
58
+ this.userSessionIndex.set(userId, /* @__PURE__ */ new Set());
59
+ }
60
+ if (!this.sessions.has(key)) {
61
+ this.sessions.set(key, { chats: /* @__PURE__ */ new Map() });
62
+ const metadata = {
63
+ sessionId,
64
+ createdAt: now,
65
+ updatedAt: now
66
+ };
67
+ this.userSessionIndex.get(userId)?.add(metadata);
68
+ }
69
+ return { title, sessionId, updatedAt: now };
70
+ }
71
+ async addChatToSession(userId, sessionId, chat) {
72
+ const key = this.generateKey(userId, sessionId);
73
+ await this.createSession(userId, sessionId, "New chat");
38
74
  const newChatId = (0, import_node_crypto.randomUUID)();
39
- const history = await this.getSessionHistory(sessionId);
40
- history.chats[newChatId] = chat;
41
- this.sessionHistory.set(sessionId, history);
75
+ this.sessions.get(key)?.chats.set(newChatId, chat);
76
+ }
77
+ async deleteSession(userId, sessionId) {
78
+ const key = this.generateKey(userId, sessionId);
79
+ this.sessions.delete(key);
80
+ this.userSessionIndex.delete(sessionId);
81
+ }
82
+ async listSessions(userId) {
83
+ const sessions = this.userSessionIndex.get(userId);
84
+ if (sessions) {
85
+ return Array.from(sessions);
86
+ }
87
+ return [];
88
+ }
89
+ };
90
+
91
+ // implements/intent.memory.ts
92
+ var import_node_crypto2 = require("crypto");
93
+ var InMemoryIntent = class {
94
+ intents = /* @__PURE__ */ new Map();
95
+ async connect() {
96
+ }
97
+ async disconnect() {
98
+ }
99
+ isConnected() {
100
+ return true;
101
+ }
102
+ async getIntent(intentId) {
103
+ return this.intents.get(intentId);
104
+ }
105
+ async saveIntent(intent) {
106
+ const newId = (0, import_node_crypto2.randomUUID)();
107
+ this.intents.set(newId, intent);
108
+ }
109
+ async updateIntent(intentId, intent) {
110
+ this.intents.set(intentId, intent);
111
+ }
112
+ async deleteIntent(intentId) {
113
+ this.intents.delete(intentId);
42
114
  }
43
- async storeQueryAndIntent(query, intent, sessionId) {
115
+ async listIntents() {
116
+ return Array.from(this.intents.values());
44
117
  }
45
118
  };
46
119
  // Annotate the CommonJS export names for ESM import in node:
47
120
  0 && (module.exports = {
48
- InMemoryMemory
121
+ InMemoryIntent,
122
+ InMemorySession
49
123
  });
50
124
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { ChatObject, SessionObject } from \"@ainetwork/adk/types/memory\";\nimport { BaseMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryMemory extends BaseMemory {\n\tpublic sessionHistory: Map<string, SessionObject>;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.sessionHistory = new Map<string, SessionObject>();\n\t}\n\n\tpublic async getSessionHistory(sessionId: string): Promise<SessionObject> {\n\t\treturn this.sessionHistory.get(sessionId) || { chats: {} };\n\t}\n\n\tpublic async updateSessionHistory(\n\t\tsessionId: string,\n\t\tchat: ChatObject,\n\t): Promise<void> {\n\t\tconst newChatId = randomUUID();\n\t\tconst history = await this.getSessionHistory(sessionId);\n\t\thistory.chats[newChatId] = chat;\n\t\tthis.sessionHistory.set(sessionId, history);\n\t}\n\n\tpublic async storeQueryAndIntent(\n\t\tquery: string,\n\t\tintent: string,\n\t\tsessionId: string,\n\t) {}\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA2B;AAE3B,qBAA2B;AAEpB,IAAM,iBAAN,cAA6B,0BAAW;AAAA,EACvC;AAAA,EAEP,cAAc;AACb,UAAM;AACN,SAAK,iBAAiB,oBAAI,IAA2B;AAAA,EACtD;AAAA,EAEA,MAAa,kBAAkB,WAA2C;AACzE,WAAO,KAAK,eAAe,IAAI,SAAS,KAAK,EAAE,OAAO,CAAC,EAAE;AAAA,EAC1D;AAAA,EAEA,MAAa,qBACZ,WACA,MACgB;AAChB,UAAM,gBAAY,+BAAW;AAC7B,UAAM,UAAU,MAAM,KAAK,kBAAkB,SAAS;AACtD,YAAQ,MAAM,SAAS,IAAI;AAC3B,SAAK,eAAe,IAAI,WAAW,OAAO;AAAA,EAC3C;AAAA,EAEA,MAAa,oBACZ,OACA,QACA,WACC;AAAA,EAAC;AACJ;","names":[]}
1
+ {"version":3,"sources":["../index.ts","../implements/session.memory.ts","../implements/intent.memory.ts"],"sourcesContent":["export { InMemorySession } from \"./implements/session.memory\";\nexport { InMemoryIntent } from \"./implements/intent.memory\";","import { randomUUID } from \"node:crypto\";\nimport type { ChatObject, SessionObject, SessionMetadata } from \"@ainetwork/adk/types/memory\";\nimport { ISessionMemory } from \"@ainetwork/adk/modules\";\n\ntype InMemorySessionObject = {\n chats: Map<string, ChatObject>\n}\n\ntype InMemorySessionMetadata = {\n sessionId: string;\n title?: string;\n updatedAt: number;\n createdAt: number;\n}\n\nexport class InMemorySession implements ISessionMemory {\n\tpublic sessions: Map<string, InMemorySessionObject> = new Map();\n public userSessionIndex: Map<string, Set<InMemorySessionMetadata>> = 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, sessionId: string) {\n return `${userId}:${sessionId}`;\n }\n\n public async getSession(userId: string, sessionId: string): Promise<SessionObject | undefined> {\n const key = this.generateKey(userId, sessionId);\n const res = this.sessions.get(key);\n if (res) {\n const sessionObject: SessionObject = {\n chats: Object.fromEntries(res.chats)\n };\n return sessionObject;\n }\n return undefined;\n };\n\n\tpublic async createSession(userId: string, sessionId: string, title: string): Promise<SessionMetadata> {\n const now = Date.now();\n const key = this.generateKey(userId, sessionId);\n if (!this.userSessionIndex.has(userId)) {\n this.userSessionIndex.set(userId, new Set());\n }\n if (!this.sessions.has(key)) {\n this.sessions.set(key, { chats: new Map() });\n const metadata: InMemorySessionMetadata = {\n sessionId, createdAt: now, updatedAt: now,\n }\n this.userSessionIndex.get(userId)?.add(metadata);\n }\n\n return { title, sessionId, updatedAt: now };\n };\n\n\tpublic async addChatToSession(userId: string, sessionId: string, chat: ChatObject): Promise<void> {\n const key = this.generateKey(userId, sessionId);\n await this.createSession(userId, sessionId, \"New chat\");\n const newChatId = randomUUID();\n this.sessions.get(key)?.chats.set(newChatId, chat);\n };\n\n\tpublic async deleteSession(userId: string, sessionId: string): Promise<void> {\n const key = this.generateKey(userId, sessionId);\n this.sessions.delete(key);\n this.userSessionIndex.delete(sessionId);\n };\n\n\tpublic async listSessions(userId: string): Promise<SessionMetadata[]> {\n const sessions = this.userSessionIndex.get(userId);\n if (sessions) {\n return Array.from(sessions);\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\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;;;ACAA,yBAA2B;AAepB,IAAM,kBAAN,MAAgD;AAAA,EAC/C,WAA+C,oBAAI,IAAI;AAAA,EACtD,mBAA8D,oBAAI,IAAI;AAAA,EAE7E,MAAa,UAAyB;AAAA,EAAC;AAAA,EACvC,MAAa,aAA4B;AAAA,EAAC;AAAA,EACnC,cAAuB;AAC5B,WAAO;AAAA,EACT;AAAA,EAEQ,YAAY,QAAgB,WAAmB;AACrD,WAAO,GAAG,MAAM,IAAI,SAAS;AAAA,EAC/B;AAAA,EAEA,MAAa,WAAW,QAAgB,WAAuD;AAC7F,UAAM,MAAM,KAAK,YAAY,QAAQ,SAAS;AAC9C,UAAM,MAAM,KAAK,SAAS,IAAI,GAAG;AACjC,QAA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;AACF;;;AC9EA,IAAAA,sBAA2B;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,EAED,MAAa,WAAW,QAA+B;AACpD,UAAM,YAAQ,gCAAW;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":["import_node_crypto"]}
package/dist/index.d.cts CHANGED
@@ -1,12 +1,39 @@
1
- import { SessionObject, ChatObject } from '@ainetwork/adk/types/memory';
2
- import { BaseMemory } from '@ainetwork/adk/modules';
1
+ import { ChatObject, SessionObject, SessionMetadata, Intent } from '@ainetwork/adk/types/memory';
2
+ import { ISessionMemory, IIntentMemory } from '@ainetwork/adk/modules';
3
3
 
4
- declare class InMemoryMemory extends BaseMemory {
5
- sessionHistory: Map<string, SessionObject>;
6
- constructor();
7
- getSessionHistory(sessionId: string): Promise<SessionObject>;
8
- updateSessionHistory(sessionId: string, chat: ChatObject): Promise<void>;
9
- storeQueryAndIntent(query: string, intent: string, sessionId: string): Promise<void>;
4
+ type InMemorySessionObject = {
5
+ chats: Map<string, ChatObject>;
6
+ };
7
+ type InMemorySessionMetadata = {
8
+ sessionId: string;
9
+ title?: string;
10
+ updatedAt: number;
11
+ createdAt: number;
12
+ };
13
+ declare class InMemorySession implements ISessionMemory {
14
+ sessions: Map<string, InMemorySessionObject>;
15
+ userSessionIndex: Map<string, Set<InMemorySessionMetadata>>;
16
+ connect(): Promise<void>;
17
+ disconnect(): Promise<void>;
18
+ isConnected(): boolean;
19
+ private generateKey;
20
+ getSession(userId: string, sessionId: string): Promise<SessionObject | undefined>;
21
+ createSession(userId: string, sessionId: string, title: string): Promise<SessionMetadata>;
22
+ addChatToSession(userId: string, sessionId: string, chat: ChatObject): Promise<void>;
23
+ deleteSession(userId: string, sessionId: string): Promise<void>;
24
+ listSessions(userId: string): Promise<SessionMetadata[]>;
10
25
  }
11
26
 
12
- export { InMemoryMemory };
27
+ declare class InMemoryIntent implements IIntentMemory {
28
+ intents: Map<string, Intent>;
29
+ connect(): Promise<void>;
30
+ disconnect(): Promise<void>;
31
+ isConnected(): boolean;
32
+ getIntent(intentId: string): Promise<Intent | undefined>;
33
+ saveIntent(intent: Intent): Promise<void>;
34
+ updateIntent(intentId: string, intent: Intent): Promise<void>;
35
+ deleteIntent(intentId: string): Promise<void>;
36
+ listIntents(): Promise<Intent[]>;
37
+ }
38
+
39
+ export { InMemoryIntent, InMemorySession };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,39 @@
1
- import { SessionObject, ChatObject } from '@ainetwork/adk/types/memory';
2
- import { BaseMemory } from '@ainetwork/adk/modules';
1
+ import { ChatObject, SessionObject, SessionMetadata, Intent } from '@ainetwork/adk/types/memory';
2
+ import { ISessionMemory, IIntentMemory } from '@ainetwork/adk/modules';
3
3
 
4
- declare class InMemoryMemory extends BaseMemory {
5
- sessionHistory: Map<string, SessionObject>;
6
- constructor();
7
- getSessionHistory(sessionId: string): Promise<SessionObject>;
8
- updateSessionHistory(sessionId: string, chat: ChatObject): Promise<void>;
9
- storeQueryAndIntent(query: string, intent: string, sessionId: string): Promise<void>;
4
+ type InMemorySessionObject = {
5
+ chats: Map<string, ChatObject>;
6
+ };
7
+ type InMemorySessionMetadata = {
8
+ sessionId: string;
9
+ title?: string;
10
+ updatedAt: number;
11
+ createdAt: number;
12
+ };
13
+ declare class InMemorySession implements ISessionMemory {
14
+ sessions: Map<string, InMemorySessionObject>;
15
+ userSessionIndex: Map<string, Set<InMemorySessionMetadata>>;
16
+ connect(): Promise<void>;
17
+ disconnect(): Promise<void>;
18
+ isConnected(): boolean;
19
+ private generateKey;
20
+ getSession(userId: string, sessionId: string): Promise<SessionObject | undefined>;
21
+ createSession(userId: string, sessionId: string, title: string): Promise<SessionMetadata>;
22
+ addChatToSession(userId: string, sessionId: string, chat: ChatObject): Promise<void>;
23
+ deleteSession(userId: string, sessionId: string): Promise<void>;
24
+ listSessions(userId: string): Promise<SessionMetadata[]>;
10
25
  }
11
26
 
12
- export { InMemoryMemory };
27
+ declare class InMemoryIntent implements IIntentMemory {
28
+ intents: Map<string, Intent>;
29
+ connect(): Promise<void>;
30
+ disconnect(): Promise<void>;
31
+ isConnected(): boolean;
32
+ getIntent(intentId: string): Promise<Intent | undefined>;
33
+ saveIntent(intent: Intent): Promise<void>;
34
+ updateIntent(intentId: string, intent: Intent): Promise<void>;
35
+ deleteIntent(intentId: string): Promise<void>;
36
+ listIntents(): Promise<Intent[]>;
37
+ }
38
+
39
+ export { InMemoryIntent, InMemorySession };
package/dist/index.js CHANGED
@@ -1,25 +1,96 @@
1
- // index.ts
1
+ // implements/session.memory.ts
2
2
  import { randomUUID } from "crypto";
3
- import { BaseMemory } from "@ainetwork/adk/modules";
4
- var InMemoryMemory = class extends BaseMemory {
5
- sessionHistory;
6
- constructor() {
7
- super();
8
- this.sessionHistory = /* @__PURE__ */ new Map();
3
+ var InMemorySession = class {
4
+ sessions = /* @__PURE__ */ new Map();
5
+ userSessionIndex = /* @__PURE__ */ new Map();
6
+ async connect() {
9
7
  }
10
- async getSessionHistory(sessionId) {
11
- return this.sessionHistory.get(sessionId) || { chats: {} };
8
+ async disconnect() {
12
9
  }
13
- async updateSessionHistory(sessionId, chat) {
10
+ isConnected() {
11
+ return true;
12
+ }
13
+ generateKey(userId, sessionId) {
14
+ return `${userId}:${sessionId}`;
15
+ }
16
+ async getSession(userId, sessionId) {
17
+ const key = this.generateKey(userId, sessionId);
18
+ const res = this.sessions.get(key);
19
+ if (res) {
20
+ const sessionObject = {
21
+ chats: Object.fromEntries(res.chats)
22
+ };
23
+ return sessionObject;
24
+ }
25
+ return void 0;
26
+ }
27
+ async createSession(userId, sessionId, title) {
28
+ const now = Date.now();
29
+ const key = this.generateKey(userId, sessionId);
30
+ if (!this.userSessionIndex.has(userId)) {
31
+ this.userSessionIndex.set(userId, /* @__PURE__ */ new Set());
32
+ }
33
+ if (!this.sessions.has(key)) {
34
+ this.sessions.set(key, { chats: /* @__PURE__ */ new Map() });
35
+ const metadata = {
36
+ sessionId,
37
+ createdAt: now,
38
+ updatedAt: now
39
+ };
40
+ this.userSessionIndex.get(userId)?.add(metadata);
41
+ }
42
+ return { title, sessionId, updatedAt: now };
43
+ }
44
+ async addChatToSession(userId, sessionId, chat) {
45
+ const key = this.generateKey(userId, sessionId);
46
+ await this.createSession(userId, sessionId, "New chat");
14
47
  const newChatId = randomUUID();
15
- const history = await this.getSessionHistory(sessionId);
16
- history.chats[newChatId] = chat;
17
- this.sessionHistory.set(sessionId, history);
48
+ this.sessions.get(key)?.chats.set(newChatId, chat);
49
+ }
50
+ async deleteSession(userId, sessionId) {
51
+ const key = this.generateKey(userId, sessionId);
52
+ this.sessions.delete(key);
53
+ this.userSessionIndex.delete(sessionId);
54
+ }
55
+ async listSessions(userId) {
56
+ const sessions = this.userSessionIndex.get(userId);
57
+ if (sessions) {
58
+ return Array.from(sessions);
59
+ }
60
+ return [];
61
+ }
62
+ };
63
+
64
+ // implements/intent.memory.ts
65
+ import { randomUUID as randomUUID2 } from "crypto";
66
+ var InMemoryIntent = class {
67
+ intents = /* @__PURE__ */ new Map();
68
+ async connect() {
69
+ }
70
+ async disconnect() {
71
+ }
72
+ isConnected() {
73
+ return true;
74
+ }
75
+ async getIntent(intentId) {
76
+ return this.intents.get(intentId);
77
+ }
78
+ async saveIntent(intent) {
79
+ const newId = randomUUID2();
80
+ this.intents.set(newId, intent);
81
+ }
82
+ async updateIntent(intentId, intent) {
83
+ this.intents.set(intentId, intent);
84
+ }
85
+ async deleteIntent(intentId) {
86
+ this.intents.delete(intentId);
18
87
  }
19
- async storeQueryAndIntent(query, intent, sessionId) {
88
+ async listIntents() {
89
+ return Array.from(this.intents.values());
20
90
  }
21
91
  };
22
92
  export {
23
- InMemoryMemory
93
+ InMemoryIntent,
94
+ InMemorySession
24
95
  };
25
96
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { ChatObject, SessionObject } from \"@ainetwork/adk/types/memory\";\nimport { BaseMemory } from \"@ainetwork/adk/modules\";\n\nexport class InMemoryMemory extends BaseMemory {\n\tpublic sessionHistory: Map<string, SessionObject>;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.sessionHistory = new Map<string, SessionObject>();\n\t}\n\n\tpublic async getSessionHistory(sessionId: string): Promise<SessionObject> {\n\t\treturn this.sessionHistory.get(sessionId) || { chats: {} };\n\t}\n\n\tpublic async updateSessionHistory(\n\t\tsessionId: string,\n\t\tchat: ChatObject,\n\t): Promise<void> {\n\t\tconst newChatId = randomUUID();\n\t\tconst history = await this.getSessionHistory(sessionId);\n\t\thistory.chats[newChatId] = chat;\n\t\tthis.sessionHistory.set(sessionId, history);\n\t}\n\n\tpublic async storeQueryAndIntent(\n\t\tquery: string,\n\t\tintent: string,\n\t\tsessionId: string,\n\t) {}\n}"],"mappings":";AAAA,SAAS,kBAAkB;AAE3B,SAAS,kBAAkB;AAEpB,IAAM,iBAAN,cAA6B,WAAW;AAAA,EACvC;AAAA,EAEP,cAAc;AACb,UAAM;AACN,SAAK,iBAAiB,oBAAI,IAA2B;AAAA,EACtD;AAAA,EAEA,MAAa,kBAAkB,WAA2C;AACzE,WAAO,KAAK,eAAe,IAAI,SAAS,KAAK,EAAE,OAAO,CAAC,EAAE;AAAA,EAC1D;AAAA,EAEA,MAAa,qBACZ,WACA,MACgB;AAChB,UAAM,YAAY,WAAW;AAC7B,UAAM,UAAU,MAAM,KAAK,kBAAkB,SAAS;AACtD,YAAQ,MAAM,SAAS,IAAI;AAC3B,SAAK,eAAe,IAAI,WAAW,OAAO;AAAA,EAC3C;AAAA,EAEA,MAAa,oBACZ,OACA,QACA,WACC;AAAA,EAAC;AACJ;","names":[]}
1
+ {"version":3,"sources":["../implements/session.memory.ts","../implements/intent.memory.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { ChatObject, SessionObject, SessionMetadata } from \"@ainetwork/adk/types/memory\";\nimport { ISessionMemory } from \"@ainetwork/adk/modules\";\n\ntype InMemorySessionObject = {\n chats: Map<string, ChatObject>\n}\n\ntype InMemorySessionMetadata = {\n sessionId: string;\n title?: string;\n updatedAt: number;\n createdAt: number;\n}\n\nexport class InMemorySession implements ISessionMemory {\n\tpublic sessions: Map<string, InMemorySessionObject> = new Map();\n public userSessionIndex: Map<string, Set<InMemorySessionMetadata>> = 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, sessionId: string) {\n return `${userId}:${sessionId}`;\n }\n\n public async getSession(userId: string, sessionId: string): Promise<SessionObject | undefined> {\n const key = this.generateKey(userId, sessionId);\n const res = this.sessions.get(key);\n if (res) {\n const sessionObject: SessionObject = {\n chats: Object.fromEntries(res.chats)\n };\n return sessionObject;\n }\n return undefined;\n };\n\n\tpublic async createSession(userId: string, sessionId: string, title: string): Promise<SessionMetadata> {\n const now = Date.now();\n const key = this.generateKey(userId, sessionId);\n if (!this.userSessionIndex.has(userId)) {\n this.userSessionIndex.set(userId, new Set());\n }\n if (!this.sessions.has(key)) {\n this.sessions.set(key, { chats: new Map() });\n const metadata: InMemorySessionMetadata = {\n sessionId, createdAt: now, updatedAt: now,\n }\n this.userSessionIndex.get(userId)?.add(metadata);\n }\n\n return { title, sessionId, updatedAt: now };\n };\n\n\tpublic async addChatToSession(userId: string, sessionId: string, chat: ChatObject): Promise<void> {\n const key = this.generateKey(userId, sessionId);\n await this.createSession(userId, sessionId, \"New chat\");\n const newChatId = randomUUID();\n this.sessions.get(key)?.chats.set(newChatId, chat);\n };\n\n\tpublic async deleteSession(userId: string, sessionId: string): Promise<void> {\n const key = this.generateKey(userId, sessionId);\n this.sessions.delete(key);\n this.userSessionIndex.delete(sessionId);\n };\n\n\tpublic async listSessions(userId: string): Promise<SessionMetadata[]> {\n const sessions = this.userSessionIndex.get(userId);\n if (sessions) {\n return Array.from(sessions);\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\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,SAAS,kBAAkB;AAepB,IAAM,kBAAN,MAAgD;AAAA,EAC/C,WAA+C,oBAAI,IAAI;AAAA,EACtD,mBAA8D,oBAAI,IAAI;AAAA,EAE7E,MAAa,UAAyB;AAAA,EAAC;AAAA,EACvC,MAAa,aAA4B;AAAA,EAAC;AAAA,EACnC,cAAuB;AAC5B,WAAO;AAAA,EACT;AA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GAAG;AACxB,SAAK,iBAAiB,OAAO,SAAS;AAAA,EACxC;AAAA,EAED,MAAa,aAAa,QAA4C;AACnE,UAAM,WAAW,KAAK,iBAAiB,IAAI,MAAM;AACjD,QAAI,UAAU;AACZ,aAAO,MAAM,KAAK,QAAQ;AAAA,IAC5B;AACA,WAAO,CAAC;AAAA,EACV;AACF;;;AC9EA,SAAS,cAAAA,mBAAkB;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,EAED,MAAa,WAAW,QAA+B;AACpD,UAAM,QAAQA,YAAW;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":["randomUUID"]}
@@ -39,7 +39,8 @@ export class InMemorySession implements ISessionMemory {
39
39
  return undefined;
40
40
  };
41
41
 
42
- public async createSession(userId: string, sessionId: string): Promise<void> {
42
+ public async createSession(userId: string, sessionId: string, title: string): Promise<SessionMetadata> {
43
+ const now = Date.now();
43
44
  const key = this.generateKey(userId, sessionId);
44
45
  if (!this.userSessionIndex.has(userId)) {
45
46
  this.userSessionIndex.set(userId, new Set());
@@ -47,19 +48,18 @@ export class InMemorySession implements ISessionMemory {
47
48
  if (!this.sessions.has(key)) {
48
49
  this.sessions.set(key, { chats: new Map() });
49
50
  const metadata: InMemorySessionMetadata = {
50
- sessionId, createdAt: Date.now(), updatedAt: Date.now(),
51
+ sessionId, createdAt: now, updatedAt: now,
51
52
  }
52
53
  this.userSessionIndex.get(userId)?.add(metadata);
53
54
  }
55
+
56
+ return { title, sessionId, updatedAt: now };
54
57
  };
55
58
 
56
59
  public async addChatToSession(userId: string, sessionId: string, chat: ChatObject): Promise<void> {
57
60
  const key = this.generateKey(userId, sessionId);
61
+ await this.createSession(userId, sessionId, "New chat");
58
62
  const newChatId = randomUUID();
59
- if (!this.sessions.has(key)) {
60
- await this.createSession(userId, sessionId);
61
- }
62
- const sessions = this.sessions.get(key);
63
63
  this.sessions.get(key)?.chats.set(newChatId, chat);
64
64
  };
65
65
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ainetwork/adk-provider-memory-inmemory",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
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.1.7"
24
+ "@ainetwork/adk": "^0.1.9"
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": "4098aacea7a18099aa020ef5d331cdce0d59c3f3"
33
+ "gitHead": "66a5fbc5f9a509bd412ff8dc91b002862133fbae"
34
34
  }