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

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,106 @@ 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) {
55
+ const key = this.generateKey(userId, sessionId);
56
+ if (!this.userSessionIndex.has(userId)) {
57
+ this.userSessionIndex.set(userId, /* @__PURE__ */ new Set());
58
+ }
59
+ if (!this.sessions.has(key)) {
60
+ this.sessions.set(key, { chats: /* @__PURE__ */ new Map() });
61
+ const metadata = {
62
+ sessionId,
63
+ createdAt: Date.now(),
64
+ updatedAt: Date.now()
65
+ };
66
+ this.userSessionIndex.get(userId)?.add(metadata);
67
+ }
68
+ }
69
+ async addChatToSession(userId, sessionId, chat) {
70
+ const key = this.generateKey(userId, sessionId);
38
71
  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);
72
+ if (!this.sessions.has(key)) {
73
+ await this.createSession(userId, sessionId);
74
+ }
75
+ const sessions = this.sessions.get(key);
76
+ this.sessions.get(key)?.chats.set(newChatId, chat);
77
+ }
78
+ async deleteSession(userId, sessionId) {
79
+ const key = this.generateKey(userId, sessionId);
80
+ this.sessions.delete(key);
81
+ this.userSessionIndex.delete(sessionId);
82
+ }
83
+ async listSessions(userId) {
84
+ const sessions = this.userSessionIndex.get(userId);
85
+ if (sessions) {
86
+ return Array.from(sessions);
87
+ }
88
+ return [];
89
+ }
90
+ };
91
+
92
+ // implements/intent.memory.ts
93
+ var import_node_crypto2 = require("crypto");
94
+ var InMemoryIntent = class {
95
+ intents = /* @__PURE__ */ new Map();
96
+ async connect() {
97
+ }
98
+ async disconnect() {
99
+ }
100
+ isConnected() {
101
+ return true;
102
+ }
103
+ async getIntent(intentId) {
104
+ return this.intents.get(intentId);
105
+ }
106
+ async saveIntent(intent) {
107
+ const newId = (0, import_node_crypto2.randomUUID)();
108
+ this.intents.set(newId, intent);
109
+ }
110
+ async updateIntent(intentId, intent) {
111
+ this.intents.set(intentId, intent);
112
+ }
113
+ async deleteIntent(intentId) {
114
+ this.intents.delete(intentId);
42
115
  }
43
- async storeQueryAndIntent(query, intent, sessionId) {
116
+ async listIntents() {
117
+ return Array.from(this.intents.values());
44
118
  }
45
119
  };
46
120
  // Annotate the CommonJS export names for ESM import in node:
47
121
  0 && (module.exports = {
48
- InMemoryMemory
122
+ InMemoryIntent,
123
+ InMemorySession
49
124
  });
50
125
  //# 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): Promise<void> {\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: Date.now(), updatedAt: Date.now(),\n }\n this.userSessionIndex.get(userId)?.add(metadata);\n }\n };\n\n\tpublic async addChatToSession(userId: string, sessionId: string, chat: ChatObject): Promise<void> {\n const key = this.generateKey(userId, sessionId);\n const newChatId = randomUUID();\n if (!this.sessions.has(key)) {\n await this.createSession(userId, sessionId);\n }\n const sessions = this.sessions.get(key);\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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AAK,QAAQ;AAAA,IAC5B;AACA,WAAO,CAAC;AAAA,EACV;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): Promise<void>;
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): Promise<void>;
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,97 @@
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) {
28
+ const key = this.generateKey(userId, sessionId);
29
+ if (!this.userSessionIndex.has(userId)) {
30
+ this.userSessionIndex.set(userId, /* @__PURE__ */ new Set());
31
+ }
32
+ if (!this.sessions.has(key)) {
33
+ this.sessions.set(key, { chats: /* @__PURE__ */ new Map() });
34
+ const metadata = {
35
+ sessionId,
36
+ createdAt: Date.now(),
37
+ updatedAt: Date.now()
38
+ };
39
+ this.userSessionIndex.get(userId)?.add(metadata);
40
+ }
41
+ }
42
+ async addChatToSession(userId, sessionId, chat) {
43
+ const key = this.generateKey(userId, sessionId);
14
44
  const newChatId = randomUUID();
15
- const history = await this.getSessionHistory(sessionId);
16
- history.chats[newChatId] = chat;
17
- this.sessionHistory.set(sessionId, history);
45
+ if (!this.sessions.has(key)) {
46
+ await this.createSession(userId, sessionId);
47
+ }
48
+ const sessions = this.sessions.get(key);
49
+ this.sessions.get(key)?.chats.set(newChatId, chat);
50
+ }
51
+ async deleteSession(userId, sessionId) {
52
+ const key = this.generateKey(userId, sessionId);
53
+ this.sessions.delete(key);
54
+ this.userSessionIndex.delete(sessionId);
55
+ }
56
+ async listSessions(userId) {
57
+ const sessions = this.userSessionIndex.get(userId);
58
+ if (sessions) {
59
+ return Array.from(sessions);
60
+ }
61
+ return [];
62
+ }
63
+ };
64
+
65
+ // implements/intent.memory.ts
66
+ import { randomUUID as randomUUID2 } from "crypto";
67
+ var InMemoryIntent = class {
68
+ intents = /* @__PURE__ */ new Map();
69
+ async connect() {
70
+ }
71
+ async disconnect() {
72
+ }
73
+ isConnected() {
74
+ return true;
75
+ }
76
+ async getIntent(intentId) {
77
+ return this.intents.get(intentId);
78
+ }
79
+ async saveIntent(intent) {
80
+ const newId = randomUUID2();
81
+ this.intents.set(newId, intent);
82
+ }
83
+ async updateIntent(intentId, intent) {
84
+ this.intents.set(intentId, intent);
85
+ }
86
+ async deleteIntent(intentId) {
87
+ this.intents.delete(intentId);
18
88
  }
19
- async storeQueryAndIntent(query, intent, sessionId) {
89
+ async listIntents() {
90
+ return Array.from(this.intents.values());
20
91
  }
21
92
  };
22
93
  export {
23
- InMemoryMemory
94
+ InMemoryIntent,
95
+ InMemorySession
24
96
  };
25
97
  //# 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): Promise<void> {\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: Date.now(), updatedAt: Date.now(),\n }\n this.userSessionIndex.get(userId)?.add(metadata);\n }\n };\n\n\tpublic async addChatToSession(userId: string, sessionId: string, chat: ChatObject): Promise<void> {\n const key = this.generateKey(userId, sessionId);\n const newChatId = randomUUID();\n if (!this.sessions.has(key)) {\n await this.createSession(userId, sessionId);\n }\n const sessions = this.sessions.get(key);\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,E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B,WAAkC;AAC1E,UAAM,MAAM,KAAK,YAAY,QAAQ,SAAS;AAC9C,SAAK,SAAS,OAAO,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"]}
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.3",
4
4
  "author": "AI Network (https://ainetwork.ai)",
5
5
  "type": "module",
6
6
  "engines": {
@@ -30,5 +30,5 @@
30
30
  "publishConfig": {
31
31
  "access": "public"
32
32
  },
33
- "gitHead": "4098aacea7a18099aa020ef5d331cdce0d59c3f3"
33
+ "gitHead": "179c9e22bac074444e9a1ddf656eb52d6fe8d34a"
34
34
  }