n8n-nodes-smart-memory 1.0.0

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.
Files changed (54) hide show
  1. package/.eslintrc.js +29 -0
  2. package/.prettierrc +10 -0
  3. package/README.md +45 -0
  4. package/dist/SmartMemory.d.ts +13 -0
  5. package/dist/SmartMemory.d.ts.map +1 -0
  6. package/dist/SmartMemory.js +163 -0
  7. package/dist/SmartMemory.js.map +1 -0
  8. package/dist/SmartMemory.node.d.ts +6 -0
  9. package/dist/SmartMemory.node.d.ts.map +1 -0
  10. package/dist/SmartMemory.node.js +136 -0
  11. package/dist/SmartMemory.node.js.map +1 -0
  12. package/dist/index.d.ts +3 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +6 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/interfaces/MemoryInterfaces.d.ts +40 -0
  17. package/dist/interfaces/MemoryInterfaces.d.ts.map +1 -0
  18. package/dist/interfaces/MemoryInterfaces.js +3 -0
  19. package/dist/interfaces/MemoryInterfaces.js.map +1 -0
  20. package/dist/storage/GoogleSheetsStorage.d.ts +8 -0
  21. package/dist/storage/GoogleSheetsStorage.d.ts.map +1 -0
  22. package/dist/storage/GoogleSheetsStorage.js +20 -0
  23. package/dist/storage/GoogleSheetsStorage.js.map +1 -0
  24. package/dist/storage/InMemoryStorage.d.ts +9 -0
  25. package/dist/storage/InMemoryStorage.d.ts.map +1 -0
  26. package/dist/storage/InMemoryStorage.js +19 -0
  27. package/dist/storage/InMemoryStorage.js.map +1 -0
  28. package/dist/storage/MemoryStorage.d.ts +7 -0
  29. package/dist/storage/MemoryStorage.d.ts.map +1 -0
  30. package/dist/storage/MemoryStorage.js +3 -0
  31. package/dist/storage/MemoryStorage.js.map +1 -0
  32. package/dist/storage/RedisStorage.d.ts +8 -0
  33. package/dist/storage/RedisStorage.d.ts.map +1 -0
  34. package/dist/storage/RedisStorage.js +20 -0
  35. package/dist/storage/RedisStorage.js.map +1 -0
  36. package/dist/utils/ExpressionEvaluator.d.ts +4 -0
  37. package/dist/utils/ExpressionEvaluator.d.ts.map +1 -0
  38. package/dist/utils/ExpressionEvaluator.js +33 -0
  39. package/dist/utils/ExpressionEvaluator.js.map +1 -0
  40. package/jest.config.js +18 -0
  41. package/package.json +51 -0
  42. package/src/SmartMemory.node.ts +153 -0
  43. package/src/SmartMemory.ts +195 -0
  44. package/src/__tests__/SmartMemory.test.ts +157 -0
  45. package/src/__tests__/setup.ts +18 -0
  46. package/src/__tests__/storage/InMemoryStorage.test.ts +70 -0
  47. package/src/index.ts +3 -0
  48. package/src/interfaces/MemoryInterfaces.ts +42 -0
  49. package/src/storage/GoogleSheetsStorage.ts +20 -0
  50. package/src/storage/InMemoryStorage.ts +18 -0
  51. package/src/storage/MemoryStorage.ts +7 -0
  52. package/src/storage/RedisStorage.ts +20 -0
  53. package/src/utils/ExpressionEvaluator.ts +27 -0
  54. package/tsconfig.json +31 -0
package/.eslintrc.js ADDED
@@ -0,0 +1,29 @@
1
+ module.exports = {
2
+ parser: '@typescript-eslint/parser',
3
+ parserOptions: {
4
+ ecmaVersion: 2020,
5
+ sourceType: 'module',
6
+ project: './tsconfig.json',
7
+ },
8
+ plugins: ['@typescript-eslint', 'prettier'],
9
+ extends: [
10
+ 'eslint:recommended',
11
+ '@typescript-eslint/recommended',
12
+ 'prettier',
13
+ ],
14
+ rules: {
15
+ 'prettier/prettier': 'error',
16
+ '@typescript-eslint/no-unused-vars': 'error',
17
+ '@typescript-eslint/no-explicit-any': 'warn',
18
+ '@typescript-eslint/explicit-function-return-type': 'off',
19
+ '@typescript-eslint/explicit-module-boundary-types': 'off',
20
+ '@typescript-eslint/no-empty-interface': 'off',
21
+ 'prefer-const': 'error',
22
+ 'no-var': 'error',
23
+ },
24
+ env: {
25
+ node: true,
26
+ es6: true,
27
+ jest: true,
28
+ },
29
+ };
package/.prettierrc ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "semi": true,
3
+ "trailingComma": "es5",
4
+ "singleQuote": true,
5
+ "printWidth": 100,
6
+ "tabWidth": 2,
7
+ "useTabs": false,
8
+ "bracketSpacing": true,
9
+ "arrowParens": "avoid"
10
+ }
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Smart Memory for n8n
2
+
3
+ A flexible, configuration-driven memory management node for n8n that supports multiple storage backends and chat types.
4
+
5
+ ## Features
6
+
7
+ - **Chat-Type Aware**: Different handling for private chats vs group chats
8
+ - **Smart User Mapping**: Configure how user names are displayed
9
+ - **Multiple Storage Backends**: In-memory, Google Sheets, Redis
10
+ - **Configurable Assistant Identity**: Customize how the assistant is identified
11
+ - **Optional Features**: Reply context, semantic/episodic memory extraction
12
+ - **Token Efficient**: Only stores essential information
13
+
14
+ ## Installation
15
+
16
+ 1. Clone this repository
17
+ 2. Install dependencies: `npm install`
18
+ 3. Build the node: `npm run build`
19
+ 4. Start n8n with the node: `n8n start --nodes ./dist`
20
+
21
+ ## Usage
22
+
23
+ ### Basic Setup
24
+
25
+ 1. Add the "Smart Memory" node to your workflow
26
+ 2. Configure the basic settings:
27
+ - Memory Window Size: Number of messages to keep in memory
28
+ - Assistant Role: How the assistant should be identified (e.g., "Assistant", "Bot")
29
+ - User Display Name Expression: Expression to combine user name fields
30
+ - Storage Backend: Choose where to store memory data
31
+
32
+ ### Advanced Configuration
33
+
34
+ #### User Field Mapping
35
+
36
+ The node allows flexible mapping of user fields:
37
+
38
+ ```javascript
39
+ // Default display name expression
40
+ ={{ $json.message.from.first_name + " " + $json.message.from.last_name }}
41
+
42
+ // Alternative expressions
43
+ ={{ $json.message.from.username }}
44
+ ={{ $json.customFields.displayName }}
45
+ ={{ "User" + $json.message.from.id }}
@@ -0,0 +1,13 @@
1
+ import { CleanMemoryStructure, MemoryManagerConfig } from './interfaces/MemoryInterfaces';
2
+ export declare class PureMemoryManager {
3
+ private config;
4
+ private storage;
5
+ constructor(config: MemoryManagerConfig);
6
+ processMessage(inputData: any): Promise<CleanMemoryStructure>;
7
+ private getMemory;
8
+ private createNewMemory;
9
+ private updateExistingMemory;
10
+ private addMessageToMemory;
11
+ private evaluateExpression;
12
+ }
13
+ //# sourceMappingURL=SmartMemory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SmartMemory.d.ts","sourceRoot":"","sources":["../src/SmartMemory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AA+B1F,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,OAAO,CAAM;gBAET,MAAM,EAAE,mBAAmB;IAiBjC,cAAc,CAAC,SAAS,EAAE,GAAG,GAAG,OAAO,CAAC,oBAAoB,CAAC;YAiBrD,SAAS;YAIT,eAAe;YAsCf,oBAAoB;YAOpB,kBAAkB;IAmDhC,OAAO,CAAC,kBAAkB;CAyB3B"}
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PureMemoryManager = void 0;
4
+ const InMemoryStorage_1 = require("./storage/InMemoryStorage");
5
+ // Import placeholder implementations for now
6
+ // import { GoogleSheetsStorage } from './storage/GoogleSheetsStorage';
7
+ // import { RedisStorage } from './storage/RedisStorage';
8
+ // Placeholder implementations
9
+ class GoogleSheetsStorage {
10
+ async getMemory(_chatId) {
11
+ throw new Error('Google Sheets storage not implemented yet');
12
+ }
13
+ async saveMemory(_chatId, _memory) {
14
+ throw new Error('Google Sheets storage not implemented yet');
15
+ }
16
+ async clearMemory(_chatId) {
17
+ throw new Error('Google Sheets storage not implemented yet');
18
+ }
19
+ }
20
+ class RedisStorage {
21
+ async getMemory(_chatId) {
22
+ throw new Error('Redis storage not implemented yet');
23
+ }
24
+ async saveMemory(_chatId, _memory) {
25
+ throw new Error('Redis storage not implemented yet');
26
+ }
27
+ async clearMemory(_chatId) {
28
+ throw new Error('Redis storage not implemented yet');
29
+ }
30
+ }
31
+ class PureMemoryManager {
32
+ constructor(config) {
33
+ this.config = config;
34
+ // Initialize storage backend
35
+ switch (config.storageBackend) {
36
+ case 'memory':
37
+ this.storage = new InMemoryStorage_1.InMemoryStorage();
38
+ break;
39
+ case 'googleSheets':
40
+ this.storage = new GoogleSheetsStorage();
41
+ break;
42
+ case 'redis':
43
+ this.storage = new RedisStorage();
44
+ break;
45
+ }
46
+ }
47
+ async processMessage(inputData) {
48
+ const chatId = inputData.message?.chat?.id;
49
+ const existingMemory = await this.getMemory(chatId);
50
+ if (!existingMemory) {
51
+ const newMemory = await this.createNewMemory(inputData);
52
+ // Save the new memory
53
+ await this.storage.saveMemory(chatId, newMemory);
54
+ return newMemory;
55
+ }
56
+ const updatedMemory = await this.updateExistingMemory(existingMemory, inputData);
57
+ // Save the updated memory
58
+ await this.storage.saveMemory(chatId, updatedMemory);
59
+ return updatedMemory;
60
+ }
61
+ async getMemory(chatId) {
62
+ return await this.storage.getMemory(chatId);
63
+ }
64
+ async createNewMemory(inputData) {
65
+ const chat = inputData.message?.chat;
66
+ const user = inputData.message?.from;
67
+ const isBotResponse = !!inputData.bot_response;
68
+ const memory = {
69
+ chatInfo: {
70
+ chatId: chat.id,
71
+ chatType: chat.type,
72
+ chatName: chat.title || chat.username || 'Private Chat',
73
+ },
74
+ messages: []
75
+ };
76
+ // Only add private user info for private chats
77
+ if (chat.type === 'private' && !isBotResponse && user) {
78
+ const displayName = this.evaluateExpression(inputData, this.config.userFieldMapping.displayName);
79
+ const username = this.config.userFieldMapping.username ?
80
+ this.evaluateExpression(inputData, this.config.userFieldMapping.username) :
81
+ undefined;
82
+ // Create the object conditionally to avoid exactOptionalPropertyTypes issue
83
+ const privateUserInfo = {
84
+ userId: user.id,
85
+ displayName,
86
+ };
87
+ if (username !== undefined) {
88
+ privateUserInfo.username = username;
89
+ }
90
+ memory.privateUserInfo = privateUserInfo;
91
+ }
92
+ // Add the first message
93
+ return await this.addMessageToMemory(memory, inputData);
94
+ }
95
+ async updateExistingMemory(memory, inputData) {
96
+ return await this.addMessageToMemory(memory, inputData);
97
+ }
98
+ async addMessageToMemory(memory, inputData) {
99
+ const message = inputData.message;
100
+ const isBotResponse = !!inputData.bot_response;
101
+ const newMessage = {
102
+ role: isBotResponse ? this.config.assistantRole : 'user',
103
+ content: message.text || message.caption || inputData.bot_response || '',
104
+ timestamp: new Date().toISOString(),
105
+ };
106
+ // Add user info for user messages in groups
107
+ if (!isBotResponse && memory.chatInfo.chatType !== 'private' && message.from) {
108
+ newMessage.userInfo = {
109
+ displayName: this.evaluateExpression(inputData, this.config.userFieldMapping.displayName),
110
+ username: this.config.userFieldMapping.username ?
111
+ this.evaluateExpression(inputData, this.config.userFieldMapping.username) :
112
+ undefined,
113
+ };
114
+ }
115
+ // Add reply information if enabled and present
116
+ if (this.config.includeReplyContext && message.reply_to_message) {
117
+ const replyUser = message.reply_to_message.from;
118
+ if (replyUser) {
119
+ newMessage.replyInfo = {
120
+ replyToDisplayName: this.evaluateExpression({ message: { from: replyUser } }, this.config.userFieldMapping.displayName),
121
+ replyToUsername: this.config.userFieldMapping.username ?
122
+ this.evaluateExpression({ message: { from: replyUser } }, this.config.userFieldMapping.username) :
123
+ undefined,
124
+ replyToMessage: message.reply_to_message.text ||
125
+ message.reply_to_message.caption ||
126
+ '[Media/Other content]',
127
+ };
128
+ }
129
+ }
130
+ return {
131
+ ...memory,
132
+ messages: [...memory.messages, newMessage],
133
+ };
134
+ }
135
+ evaluateExpression(data, expression) {
136
+ // Simple expression evaluator - in real implementation, use n8n's expression system
137
+ // Examples: "={{ $json.message.from.first_name + ' ' + $json.message.from.last_name }}"
138
+ // "={{ $json.message.from.username }}"
139
+ try {
140
+ // This would integrate with n8n's expression system
141
+ if (expression.startsWith('={{ ') && expression.endsWith(' }}')) {
142
+ // Extract the expression part
143
+ const expr = expression.slice(3, -2);
144
+ // Simple evaluation for common cases
145
+ if (expr.includes('$json.message.from.first_name') && expr.includes('$json.message.from.last_name')) {
146
+ const firstName = data.message?.from?.first_name || '';
147
+ const lastName = data.message?.from?.last_name || '';
148
+ return `${firstName} ${lastName}`.trim();
149
+ }
150
+ if (expr.includes('$json.message.from.username')) {
151
+ return data.message?.from?.username || '';
152
+ }
153
+ return expr;
154
+ }
155
+ return expression;
156
+ }
157
+ catch {
158
+ return '';
159
+ }
160
+ }
161
+ }
162
+ exports.PureMemoryManager = PureMemoryManager;
163
+ //# sourceMappingURL=SmartMemory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SmartMemory.js","sourceRoot":"","sources":["../src/SmartMemory.ts"],"names":[],"mappings":";;;AACA,+DAA4D;AAC5D,6CAA6C;AAC7C,uEAAuE;AACvE,yDAAyD;AAEzD,8BAA8B;AAC9B,MAAM,mBAAmB;IACvB,KAAK,CAAC,SAAS,CAAC,OAAe;QAC7B,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;IACD,KAAK,CAAC,UAAU,CAAC,OAAe,EAAE,OAA6B;QAC7D,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;IACD,KAAK,CAAC,WAAW,CAAC,OAAe;QAC/B,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;CACF;AAED,MAAM,YAAY;IAChB,KAAK,CAAC,SAAS,CAAC,OAAe;QAC7B,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,KAAK,CAAC,UAAU,CAAC,OAAe,EAAE,OAA6B;QAC7D,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,KAAK,CAAC,WAAW,CAAC,OAAe;QAC/B,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;CACF;AAED,MAAa,iBAAiB;IAI5B,YAAY,MAA2B;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,6BAA6B;QAC7B,QAAQ,MAAM,CAAC,c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,EAAE,CAAC,IAAI,EAAE,CAAC;gBAC3C,CAAC;gBACD,IAAI,IAAI,CAAC,QAAQ,CAAC,6BAA6B,CAAC,EAAE,CAAC;oBACjD,OAAO,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,IAAI,EAAE,CAAC;gBAC5C,CAAC;gBACD,OAAO,IAAI,CAAC;YACd,CAAC;YACD,OAAO,UAAU,CAAC;QACpB,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;CACF;AAnKD,8CAmKC"}
@@ -0,0 +1,6 @@
1
+ import { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
2
+ export declare class SmartMemory implements INodeType {
3
+ description: INodeTypeDescription;
4
+ execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
5
+ }
6
+ //# sourceMappingURL=SmartMemory.node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SmartMemory.node.d.ts","sourceRoot":"","sources":["../src/SmartMemory.node.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,SAAS,EACT,oBAAoB,EACrB,MAAM,cAAc,CAAC;AAWtB,qBAAa,WAAY,YAAW,SAAS;IAC3C,WAAW,EAAE,oBAAoB,CAqE/B;IAEI,OAAO,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC;CAgExE"}
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SmartMemory = void 0;
4
+ const SmartMemory_1 = require("./SmartMemory");
5
+ // Helper function outside the class
6
+ function estimateTokenCount(memory) {
7
+ // Estimate tokens for the entire memory structure
8
+ const text = JSON.stringify(memory);
9
+ return Math.ceil(text.length / 4);
10
+ }
11
+ class SmartMemory {
12
+ constructor() {
13
+ this.description = {
14
+ displayName: 'Smart Memory',
15
+ name: 'smartMemory',
16
+ icon: 'fa:memory',
17
+ group: ['transform'],
18
+ version: 1.0,
19
+ description: 'Configuration-driven memory management without prompt manipulation',
20
+ defaults: {
21
+ name: 'Smart Memory',
22
+ },
23
+ inputs: ['main'],
24
+ outputs: ['main'],
25
+ properties: [
26
+ {
27
+ displayName: 'Memory Window Size',
28
+ name: 'memoryWindowSize',
29
+ type: 'number',
30
+ typeOptions: {
31
+ minValue: 5,
32
+ maxValue: 50,
33
+ },
34
+ default: 15,
35
+ description: 'Number of messages to keep in memory',
36
+ },
37
+ {
38
+ displayName: 'Assistant Role',
39
+ name: 'assistantRole',
40
+ type: 'string',
41
+ default: 'Assistant',
42
+ description: 'How the assistant should be identified in memory',
43
+ },
44
+ {
45
+ displayName: 'User Display Name Expression',
46
+ name: 'userDisplayNameExpression',
47
+ type: 'string',
48
+ default: '={{ $json.message.from.first_name + " " + $json.message.from.last_name }}',
49
+ description: 'Expression to combine user name fields',
50
+ },
51
+ {
52
+ displayName: 'User Username Expression',
53
+ name: 'userUsernameExpression',
54
+ type: 'string',
55
+ default: '={{ $json.message.from.username }}',
56
+ description: 'Expression to get username (leave empty to disable)',
57
+ },
58
+ {
59
+ displayName: 'Include Reply Context',
60
+ name: 'includeReplyContext',
61
+ type: 'boolean',
62
+ default: true,
63
+ description: 'Include information about replied-to messages',
64
+ },
65
+ {
66
+ displayName: 'Storage Backend',
67
+ name: 'storageBackend',
68
+ type: 'options',
69
+ options: [
70
+ { name: 'In-Memory', value: 'memory' },
71
+ { name: 'Google Sheets', value: 'googleSheets' },
72
+ { name: 'Redis', value: 'redis' },
73
+ ],
74
+ default: 'memory',
75
+ },
76
+ ],
77
+ };
78
+ }
79
+ async execute() {
80
+ const items = this.getInputData();
81
+ const returnData = [];
82
+ // Build configuration from node parameters
83
+ const config = {
84
+ memoryWindowSize: this.getNodeParameter('memoryWindowSize', 0),
85
+ storageBackend: this.getNodeParameter('storageBackend', 0),
86
+ assistantRole: this.getNodeParameter('assistantRole', 0),
87
+ userFieldMapping: {
88
+ displayName: this.getNodeParameter('userDisplayNameExpression', 0),
89
+ username: this.getNodeParameter('userUsernameExpression', 0),
90
+ },
91
+ includeReplyContext: this.getNodeParameter('includeReplyContext', 0),
92
+ enableSemanticMemory: false,
93
+ enableEpisodicMemory: false,
94
+ };
95
+ // Initialize memory manager
96
+ const memoryManager = new SmartMemory_1.PureMemoryManager(config);
97
+ for (let i = 0; i < items.length; i++) {
98
+ try {
99
+ // Process the message
100
+ if (!items[i]?.json) {
101
+ throw new Error('Invalid input data: missing json property');
102
+ }
103
+ const jsonData = items[i].json;
104
+ if (!jsonData || !jsonData.message || !jsonData.message.chat) {
105
+ throw new Error('Invalid message format: missing message or chat data');
106
+ }
107
+ const chatId = jsonData.message.chat.id;
108
+ let memory = await memoryManager.processMessage(jsonData);
109
+ // Apply memory window size
110
+ memory.messages = memory.messages.slice(-config.memoryWindowSize);
111
+ // Build output - just the memory data, no prompt manipulation
112
+ const output = {
113
+ chatId,
114
+ chatType: memory.chatInfo.chatType,
115
+ memory: memory,
116
+ messageCount: memory.messages.length,
117
+ tokenEstimate: estimateTokenCount(memory),
118
+ };
119
+ returnData.push({
120
+ json: output,
121
+ });
122
+ }
123
+ catch (error) {
124
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
125
+ returnData.push({
126
+ json: {
127
+ error: errorMessage,
128
+ },
129
+ });
130
+ }
131
+ }
132
+ return [returnData];
133
+ }
134
+ }
135
+ exports.SmartMemory = SmartMemory;
136
+ //# sourceMappingURL=SmartMemory.node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SmartMemory.node.js","sourceRoot":"","sources":["../src/SmartMemory.node.ts"],"names":[],"mappings":";;;AAMA,+CAAkD;AAGlD,oCAAoC;AACpC,SAAS,kBAAkB,CAAC,MAAW;IACrC,kDAAkD;IAClD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACpC,OAAO,IAAI,CAAC,IAAI,CAAC,IA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,CAAC;QAED,OAAO,CAAC,UAAU,CAAC,CAAC;IACtB,CAAC;CACF;AAxID,kCAwIC"}
@@ -0,0 +1,3 @@
1
+ import { SmartMemory } from './SmartMemory.node';
2
+ export { SmartMemory };
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SmartMemory = void 0;
4
+ const SmartMemory_node_1 = require("./SmartMemory.node");
5
+ Object.defineProperty(exports, "SmartMemory", { enumerable: true, get: function () { return SmartMemory_node_1.SmartMemory; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yDAAiD;AAExC,4FAFA,8BAAW,OAEA"}
@@ -0,0 +1,40 @@
1
+ export interface CleanMemoryStructure {
2
+ chatInfo: {
3
+ chatId: string;
4
+ chatType: 'private' | 'group' | 'supergroup' | 'channel';
5
+ chatName: string;
6
+ };
7
+ privateUserInfo?: {
8
+ userId: string;
9
+ displayName: string;
10
+ username?: string;
11
+ };
12
+ messages: Array<{
13
+ role: 'user' | 'assistant' | string;
14
+ content: string;
15
+ timestamp: string;
16
+ userInfo?: {
17
+ displayName: string;
18
+ username?: string;
19
+ };
20
+ replyInfo?: {
21
+ replyToDisplayName?: string;
22
+ replyToUsername?: string;
23
+ replyToMessage?: string;
24
+ };
25
+ }>;
26
+ }
27
+ export interface MemoryManagerConfig {
28
+ memoryWindowSize: number;
29
+ storageBackend: 'memory' | 'googleSheets' | 'redis';
30
+ userFieldMapping: {
31
+ displayName: string;
32
+ username?: string;
33
+ };
34
+ assistantRole: string;
35
+ assistantName?: string;
36
+ includeReplyContext: boolean;
37
+ enableSemanticMemory: boolean;
38
+ enableEpisodicMemory: boolean;
39
+ }
40
+ //# sourceMappingURL=MemoryInterfaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MemoryInterfaces.d.ts","sourceRoot":"","sources":["../../src/interfaces/MemoryInterfaces.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE;QACR,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,SAAS,GAAG,OAAO,GAAG,YAAY,GAAG,SAAS,CAAC;QACzD,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IAEF,eAAe,CAAC,EAAE;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;IAEF,QAAQ,EAAE,KAAK,CAAC;QACd,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;QACpC,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,CAAC,EAAE;YACT,WAAW,EAAE,MAAM,CAAC;YACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;SACnB,CAAC;QACF,SAAS,CAAC,EAAE;YACV,kBAAkB,CAAC,EAAE,MAAM,CAAC;YAC5B,eAAe,CAAC,EAAE,MAAM,CAAC;YACzB,cAAc,CAAC,EAAE,MAAM,CAAC;SACzB,CAAC;KACH,CAAC,CAAC;CACJ;AAED,MAAM,WAAW,mBAAmB;IAClC,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,QAAQ,GAAG,cAAc,GAAG,OAAO,CAAC;IACpD,gBAAgB,EAAE;QAChB,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mBAAmB,EAAE,OAAO,CAAC;IAC7B,oBAAoB,EAAE,OAAO,CAAC;IAC9B,oBAAoB,EAAE,OAAO,CAAC;CAC/B"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=MemoryInterfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MemoryInterfaces.js","sourceRoot":"","sources":["../../src/interfaces/MemoryInterfaces.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import { CleanMemoryStructure } from '../interfaces/MemoryInterfaces';
2
+ import { MemoryStorage } from './MemoryStorage';
3
+ export declare class GoogleSheetsStorage implements MemoryStorage {
4
+ getMemory(_chatId: string): Promise<CleanMemoryStructure | null>;
5
+ saveMemory(_chatId: string, _memory: CleanMemoryStructure): Promise<void>;
6
+ clearMemory(_chatId: string): Promise<void>;
7
+ }
8
+ //# sourceMappingURL=GoogleSheetsStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GoogleSheetsStorage.d.ts","sourceRoot":"","sources":["../../src/storage/GoogleSheetsStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,qBAAa,mBAAoB,YAAW,aAAa;IACjD,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAMhE,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAKzE,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAIlD"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GoogleSheetsStorage = void 0;
4
+ class GoogleSheetsStorage {
5
+ async getMemory(_chatId) {
6
+ // TODO: Implement Google Sheets storage
7
+ console.log('Google Sheets storage not implemented yet');
8
+ return null;
9
+ }
10
+ async saveMemory(_chatId, _memory) {
11
+ // TODO: Implement Google Sheets storage
12
+ console.log('Google Sheets storage not implemented yet');
13
+ }
14
+ async clearMemory(_chatId) {
15
+ // TODO: Implement Google Sheets storage
16
+ console.log('Google Sheets storage not implemented yet');
17
+ }
18
+ }
19
+ exports.GoogleSheetsStorage = GoogleSheetsStorage;
20
+ //# sourceMappingURL=GoogleSheetsStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GoogleSheetsStorage.js","sourceRoot":"","sources":["../../src/storage/GoogleSheetsStorage.ts"],"names":[],"mappings":";;;AAGA,MAAa,mBAAmB;IAC9B,KAAK,CAAC,SAAS,CAAC,OAAe;QAC7B,wCAAwC;QACxC,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;QACzD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,OAAe,EAAE,OAA6B;QAC7D,wCAAwC;QACxC,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;IAC3D,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,OAAe;QAC/B,wCAAwC;QACxC,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;IAC3D,CAAC;CACF;AAhBD,kDAgBC"}
@@ -0,0 +1,9 @@
1
+ import { MemoryStorage } from './MemoryStorage';
2
+ import { CleanMemoryStructure } from '../interfaces/MemoryInterfaces';
3
+ export declare class InMemoryStorage implements MemoryStorage {
4
+ private storage;
5
+ getMemory(chatId: string): Promise<CleanMemoryStructure | null>;
6
+ saveMemory(chatId: string, memory: CleanMemoryStructure): Promise<void>;
7
+ clearMemory(chatId: string): Promise<void>;
8
+ }
9
+ //# sourceMappingURL=InMemoryStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InMemoryStorage.d.ts","sourceRoot":"","sources":["../../src/storage/InMemoryStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAEtE,qBAAa,eAAgB,YAAW,aAAa;IACnD,OAAO,CAAC,OAAO,CAA2C;IAEpD,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAI/D,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvE,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGjD"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InMemoryStorage = void 0;
4
+ class InMemoryStorage {
5
+ constructor() {
6
+ this.storage = new Map();
7
+ }
8
+ async getMemory(chatId) {
9
+ return this.storage.get(chatId) || null;
10
+ }
11
+ async saveMemory(chatId, memory) {
12
+ this.storage.set(chatId, memory);
13
+ }
14
+ async clearMemory(chatId) {
15
+ this.storage.delete(chatId);
16
+ }
17
+ }
18
+ exports.InMemoryStorage = InMemoryStorage;
19
+ //# sourceMappingURL=InMemoryStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InMemoryStorage.js","sourceRoot":"","sources":["../../src/storage/InMemoryStorage.ts"],"names":[],"mappings":";;;AAGA,MAAa,eAAe;IAA5B;QACU,YAAO,GAAG,IAAI,GAAG,EAAgC,CAAC;IAa5D,CAAC;IAXC,KAAK,CAAC,SAAS,CAAC,MAAc;QAC5B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,MAAc,EAAE,MAA4B;QAC3D,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,MAAc;QAC9B,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;CACF;AAdD,0CAcC"}
@@ -0,0 +1,7 @@
1
+ import { CleanMemoryStructure } from '../interfaces/MemoryInterfaces';
2
+ export interface MemoryStorage {
3
+ getMemory(chatId: string): Promise<CleanMemoryStructure | null>;
4
+ saveMemory(chatId: string, memory: CleanMemoryStructure): Promise<void>;
5
+ clearMemory(chatId: string): Promise<void>;
6
+ }
7
+ //# sourceMappingURL=MemoryStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MemoryStorage.d.ts","sourceRoot":"","sources":["../../src/storage/MemoryStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAEtE,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAAC;IAChE,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxE,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5C"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=MemoryStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MemoryStorage.js","sourceRoot":"","sources":["../../src/storage/MemoryStorage.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import { CleanMemoryStructure } from '../interfaces/MemoryInterfaces';
2
+ import { MemoryStorage } from './MemoryStorage';
3
+ export declare class RedisStorage implements MemoryStorage {
4
+ getMemory(_chatId: string): Promise<CleanMemoryStructure | null>;
5
+ saveMemory(_chatId: string, _memory: CleanMemoryStructure): Promise<void>;
6
+ clearMemory(_chatId: string): Promise<void>;
7
+ }
8
+ //# sourceMappingURL=RedisStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RedisStorage.d.ts","sourceRoot":"","sources":["../../src/storage/RedisStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,qBAAa,YAAa,YAAW,aAAa;IAC1C,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAMhE,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAKzE,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAIlD"}